Difference between revisions of "Carbon interface internals"

From Lazarus wiki
(What needs to be done next?)
(What needs to be done next?)
Line 39: Line 39:
|TControl.Cursor||SetThemeCursor|| || [[User:Paul Ishenin|Paul Ishenin]]
|TWinControl.TabOrder + TabStop||kEventControlGetNextFocusCandidate|| ||[[User:Tombo|Tombo]]
|TWinControl.TabOrder + TabStop||kEventControlGetNextFocusCandidate|| ||[[User:Tombo|Tombo]]

Revision as of 08:02, 23 March 2007

Deutsch (de) English (en)


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)
  • Use object approach

What is already working ?

Working components in the Carbon interface

What needs to be done next?

Item Note Dependencies Responsible
TWinControl.TabOrder + TabStop kEventControlGetNextFocusCandidate Tombo
LM_SETFOCUS, LM_KILLFOCUS kEventControlSetFocus Tombo
TListBox + TCheckListBox CreateListBoxControl does not function in compositing mode! We must create our own Carbon list box control.
TBitBtn default glyphs CreatePixmapIndirect
TBrush Patterns CGPatternCreate
TCustomControl Tombo
TPanel Frame3D Tombo
TGraphicControl MoveWindowOrgEx, IntersectClipRect, ExcludeClipRect, SaveDC, RestoreDC, RectVisible Tombo
ScreenDC CGDisplayCapture, CGDisplayGetDrawingContext, CGDisplayRegisterReconfigurationCallback TCarbonScreenContext
StretchMaskBlt Implement: source coordinates, ROP, stretch mode
Hints CreateNewWindow with kHelpWindowClass WindowFromPoint Tombo
TOpenDialog NavCreateGetFileDialog Phil
TSaveDialog NavCreatePutFileDialog Phil
TCalendar no counterpart
TFontDialog FPShowHideFontPanel
TListView CreateDataBrowserControl
TMainMenu + TPopupMenu CreateNewMenu Tombo
TNoteBook + TPage CreateTabsControl Tombo
TScrollBox HIScrollViewCreate
TStatusBar maybe CreatePlacardControl Tombo
TClipboard PasteboardCreate


Item Note Dependencies Responsible
ShowWindow Maximize <-> Restore is breaked
TCustomEdit.CharCase Is ignored when typing text
TMemo.WordWrap persistent bug, when word wrap is disabled the memo doesn't scroll to caret
TForm.ShowModal Problem with repeated calling
TCanvas.Rectangle Pixel accuracy Tombo
TMaskEdit Every typed char is doubled

Compatibility issues


  • 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

Note that Quickdraw is deprecated as of Mac OS X 10.5, so in the long term this needs another solution.


  • 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)
   class function  CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;

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 helper class called TCarbonButton in carbonprivate.pp, which really creates the button control in the Carbon and installs event handlers.