Carbon interface internals

From Free Pascal wiki
Jump to navigationJump to search

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 read first Carbon Interface.

Documentation about Carbon

Carbon Book for download

Carbon Dev

What is already working ?

  • Creating a TForm
  • Creating and clicking on a TButton
  • Creating TOpenGLControl with AGL context (see components/opengl/)
  • Mouse events
  • Keyboard events (VK_ mapping for foreign keyboards needs testing)

What needs to be done next?

  • Create more controls (TEdit, TCheckBox, TRadioButton, TGroupBox)
  • Resize events (when form has been resized by user)
  • InvalidateRect
  • ShowModal (for dialogs)

More difficult tasks

  • TLabel is custom drawn in the LCL. That means TCanvas needs to be implemented first.
  • TCanvas needs GetDC/ReleaseDC, fonts, brush, pen, clipping and paint messages
  • TMenu is quite different than the gtk and win32 menus.

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.

Keyboard

  • Apple Command key is mapped to ssCtrl due to Apple Guidelines
  • Apple control key is mapped to ssMeta
  • Apple option key is mapped to its inscription, i.e. ssAlt