Difference between revisions of "Carbon interface internals"

From Free Pascal wiki
Jump to navigationJump to search
m
Line 29: Line 29:
 
* Keyboard events
 
* Keyboard events
  
== Screenshot ==
+
[[Image:Carbon interface show case.png|thumb|300px|Working components in the Carbon interface]]
 
 
[[Image:Carbon interface show case.png]]
 
  
 
== What needs to be done next? ==
 
== What needs to be done next? ==

Revision as of 15:06, 15 March 2007

Deutsch (de) English (en)

macOSlogo.png

This article applies to macOS only.

See also: Multiplatform Programming Guide

Apple iOS new.svg

This article applies to iOS only.

See also: Multiplatform Programming Guide


This page gives an overview of the LCL Carbon interface for Mac OS X and will help new developers.

For installation and creating a first Carbon application refer to Carbon Interface.

Documentation about Carbon

Apple Carbon docs

Carbon Book for download

Carbon Dev

"Learning Carbon" sample book chapter

Free Pascal's Carbon API unit is FPCMacOSAll.pas in /usr/local/share/fpcsrc/packages/extra/univint.

Carbon interface development basics

  • Target Mac OS X version is 10.4
  • Avoid using obsolete or deprecated APIs and functions (e. g. QuickDraw vs. Quartz 2D)

What is already working ?

Working components in the Carbon interface

What needs to be done next?

Item Note Dependencies Responsible
TControl.Cursor SetThemeCursor
TWinControl.TabOrder + TabStop kEventControlGetNextFocusCandidate
TComboBox HIComboBox(Create) Tombo
TListBox + TCheckListBox CreateListBoxControl does not function in compositing mode! We must create our own Carbon list box control. Tombo
TCanvas Quartz 2D, CGContext Tombo
TPen Quartz 2D Tombo
TBrush Quartz 2D Tombo
SaveDC, RestoreDC Quartz 2D, CGContextSaveGState, CGContextRestoreGState Tombo
TBitmap.LoadFromFile Quartz 2D, CGImage GetDeviceRawImageDescription, CreateBitmapFromRawImage, GetObject Tombo
TBitBtn CreateBevelButtonControl Tombo
TBitBtn default glyphs CreatePixmapIndirect
TCustomControl Tombo
TGraphicControl MoveWindowOrgEx, IntersectClipRect, SaveDC, RestoreDC Tombo
ScreenDC CGDisplayCapture, CGDisplayGetDrawingContext, CGDisplayRegisterReconfigurationCallback TCarbonScreenContext
Hints CreateNewWindow with kHelpWindowClass WindowFromPoint
TOpenDialog NavCreateGetFileDialog Phil
TSaveDialog NavCreatePutFileDialog Phil
TCalendar CreateClockControl
TFontDialog FPShowHideFontPanel
TListView CreateDataBrowserControl
TMainMenu + TPopupMenu CreateNewMenu
TNoteBook + TPage CreateTabsControl
TScrollBox HIScrollViewCreate
TStatusBar maybe CreatePlacardControl

Bugs

Item Note Dependencies Responsible
Mouse events fired on structure part of TForm
ShowWindow Maximize <-> Restore is breaked
TScrollBar and TTrackBar live tracking kEventControlIndicatorMoved Tombo
TScrollBar arrow clicking Tombo
TCustomGroupBox client area Tombo
TCustomEdit.MaxLength The caret pos is not preserved when typed text is longer than maxlength Tombo
TCustomEdit.CharCase Is ignored when typing text
TMemo.ReadOnly Tombo
TMemo.WordWrap Tombo
TMemo is not scrolling to caret Tombo
TMemo.ScrollBars Embed in HIScrollView -> solve event handling Tombo
EnumFontFamiliesEx, FindCarbonFontID Get UTF-8 font names UTF16ToUTF8 Tombo
TCustomCheckBox.OnClick Called before state is changed -> call on hit event before mouse up Tombo
TForm.ShowModal Problem with repeated calling
TMaskEdit Every typed char is doubled

Compatibility issues

Keyboard

  • Apple Command key is mapped to ssCtrl per Apple Guidelines
  • Apple control key is mapped to ssMeta
  • Apple option key is mapped to its inscription, i.e. ssAlt
  • Virtual key codes mapping (depends on keyboard language layout!)
  • Shortcuts indication (ampersand)

Drawing on canvas outside OnPaint event

  • paints into QuickDraw window port, maybe QDBeginCGContext, QDEndCGContext would help

TControl.Color

  • background of Carbon controls is transparent

How to add a new control

For example TButton.

TButton is defined in lcl/buttons.pp. This is the platform independent part of the LCL, which is used by the normal LCL programmer.

Its widgetset class is in lcl/widgetset/wsbuttons.pp. This is the platform independent base for all widgetsets (carbon, gtk, win32, ...).

Its Carbon interface class is in lcl/interfaces/carbon/carbonwsbuttons.pp:

 TCarbonWSButton = class(TWSButton)
 private
 protected
 public
   class function  CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
 end;

Every WS class that actually implements something must be registered. See the initialization section at the end of the carbonwsXXX.pp unit:

 RegisterWSComponent(TCustomButton, TCarbonWSButton);

TCarbonWSButton overrides CreateHandle to create a Carbon button. The code is short and should be easily adaptable for other controls like TCheckBox.