Difference between revisions of "Accessing the Interfaces directly"

From Free Pascal wiki
(List of Handles on various LCL classes)
Line 10: Line 10:
 
* under gtk a Handle is often a PGtkWidget
 
* under gtk a Handle is often a PGtkWidget
 
* under windows a Handle is often a HWnd.
 
* under windows a Handle is often a HWnd.
* under carbon a Handle is often a ControlRef
+
* under carbon a Handle is often a object descendant of TCarbonWidget.
 
* under Qt, a Handle is often a pointer to a object descendent of TQtWidget.
 
* under Qt, a Handle is often a pointer to a object descendent of TQtWidget.
  
Line 37: Line 37:
  
 
* Widget - This is a connect to the Qt object for this Widget
 
* Widget - This is a connect to the Qt object for this Widget
 +
* LCLObject - Is a bridge with the LCL object it is linked to.
 +
 +
=== Carbon ===
 +
 +
Handles on Carbon are very similar to Qt ones. The helper classes are descended from abstract class TCarbonWidget.
 +
 +
<pre>
 +
{ TCarbonWidget }
 +
 +
TCarbonWidget = class(TObject)
 +
private
 +
public
 +
  Widget: Pointer;
 +
  LCLObject: TWinControl;
 +
end;
 +
</pre>
 +
 +
Notice the two variables they all contain:
 +
 +
* Widget - This is a connect to the Carbon object for this Widget: ControlRef (TCarbonControl descendants) or WindowRef (TCarbonWindow descendants).
 
* LCLObject - Is a bridge with the LCL object it is linked to.
 
* LCLObject - Is a bridge with the LCL object it is linked to.
  
Line 49: Line 69:
 
* Win32, WinCE: HFONT
 
* Win32, WinCE: HFONT
 
* Qt: A TQtFont object from qtprivate.pas
 
* Qt: A TQtFont object from qtprivate.pas
* Carbon: A TCarbonFont object from carbondef.pp
+
* Carbon: A TCarbonFont object from carbongdiobjects.pp
  
 
=== TCanvas ===
 
=== TCanvas ===
Line 55: Line 75:
 
* Win32, WinCE: HDC
 
* Win32, WinCE: HDC
 
* Qt: A TQtDeviceContext object from qtprivate.pas
 
* Qt: A TQtDeviceContext object from qtprivate.pas
* Carbon: A TCarbonDeviceContext object from carbondef.pp
+
* Carbon: A TCarbonDeviceContext object from carboncanvas.pp
  
 
=== TBrush ===
 
=== TBrush ===
Line 61: Line 81:
 
* Win32, WinCE: HBRUSH
 
* Win32, WinCE: HBRUSH
 
* Qt: A TQtBrush object from qtprivate.pas
 
* Qt: A TQtBrush object from qtprivate.pas
* Carbon: A TCarbonBrush object from carbondef.pp
+
* Carbon: A TCarbonBrush object from carbongdiobjects.pp
  
 
=== TBitmap ===
 
=== TBitmap ===
Line 68: Line 88:
 
* Gtk: PGDIObject (defined on unit GtkDef)
 
* Gtk: PGDIObject (defined on unit GtkDef)
 
* Qt: A TQtImage object from qtobjects.pas unit
 
* Qt: A TQtImage object from qtobjects.pas unit
* Carbon: A TCarbonBitmap object from carbondef.pp
+
* Carbon: A TCarbonBitmap object from carbongdiobjects.pp
  
 
You can access this on Gtk using:
 
You can access this on Gtk using:
Line 96: Line 116:
 
* Gtk: It´s a pointer to a structure.
 
* Gtk: It´s a pointer to a structure.
 
* Qt: The Handle is a pointer to a object from the TQtMainWindow class declared at qtprivate.pas. To have access to the QMainWindow Qt object it represents do: TQtMainWindow(Handle).Widget
 
* Qt: The Handle is a pointer to a object from the TQtMainWindow class declared at qtprivate.pas. To have access to the QMainWindow Qt object it represents do: TQtMainWindow(Handle).Widget
* Carbon: WindowRef, Carbon native window handle
+
* Carbon: TCarbonWindow from carbonprivate.pp
  
 
=== TMenu, TMainMenu, TMenuItem and TPopUpMenu ===
 
=== TMenu, TMainMenu, TMenuItem and TPopUpMenu ===

Revision as of 19:02, 16 March 2007

English (en) português (pt)

This page describes, how to write a new LCL control, using the various LCL interfaces for the platform dependent implementations.

OpenGL is a platform independent language for 3D graphics. The platform dependent part is to get a OpenGL context. Under linux/freebsd/X you use glx for that, under windows you use WGL and under MacOSX you can use AGL.

Every TWinControl has a Handle, and the LCL does not need to know, what a Handle is. The meaning of the Handle is totally up to the LCL interface:

  • under gtk a Handle is often a PGtkWidget
  • under windows a Handle is often a HWnd.
  • under carbon a Handle is often a object descendant of TCarbonWidget.
  • under Qt, a Handle is often a pointer to a object descendent of TQtWidget.

Be aware that you should avoid relying on any widgetset specials. This page is for people improving the widgetsets and for people writing components that need to access the widgets directly.

Per-Widgetset Details

Qt

Handles on Qt are mostly pointers to objects. Every time a control is created, a helper object is also created and both are connected. The helper object is necessary to receive events from Qt. After receiving a event it will send it to the LCL.

Most of those objects are descendents from TQtWidget as declared below:

 { TQtWidget }

 TQtWidget = class(TObject)
 private
 public
   Widget: QWidgetH;
   LCLObject: TWinControl;
 end;

Notice the two variables they all contain:

  • Widget - This is a connect to the Qt object for this Widget
  • LCLObject - Is a bridge with the LCL object it is linked to.

Carbon

Handles on Carbon are very similar to Qt ones. The helper classes are descended from abstract class TCarbonWidget.

 { TCarbonWidget }

 TCarbonWidget = class(TObject)
 private
 public
   Widget: Pointer;
   LCLObject: TWinControl;
 end;

Notice the two variables they all contain:

  • Widget - This is a connect to the Carbon object for this Widget: ControlRef (TCarbonControl descendants) or WindowRef (TCarbonWindow descendants).
  • LCLObject - Is a bridge with the LCL object it is linked to.

Windows

Handles on Win32 or WinCE are almost always the same as their relative win api handles,For example handle of tmenu is HMENU,handle of TBrush is HBRUSH,so you can easily use them and pass them to windows apis.

List of Handles on various LCL classes

TFont

  • Win32, WinCE: HFONT
  • Qt: A TQtFont object from qtprivate.pas
  • Carbon: A TCarbonFont object from carbongdiobjects.pp

TCanvas

  • Win32, WinCE: HDC
  • Qt: A TQtDeviceContext object from qtprivate.pas
  • Carbon: A TCarbonDeviceContext object from carboncanvas.pp

TBrush

  • Win32, WinCE: HBRUSH
  • Qt: A TQtBrush object from qtprivate.pas
  • Carbon: A TCarbonBrush object from carbongdiobjects.pp

TBitmap

  • Win32, WinCE: HBITMAP
  • Gtk: PGDIObject (defined on unit GtkDef)
  • Qt: A TQtImage object from qtobjects.pas unit
  • Carbon: A TCarbonBitmap object from carbongdiobjects.pp

You can access this on Gtk using:

var
  GDIObject: PGDIObject;
  Bitmap: TBitmap;
  AImage: PGtkWidget;
begin
  ...

  GDIObject := PgdiObject(Bitmap.Handle);

  AImage := gtk_image_new_from_pixmap(GDIObject^.GDIPixmapObject,
   GDIObject^.GDIBitmapMaskObject);

  gtk_widget_show(AImage);

  gtk_container_add(GTK_CONTAINER(MyForm.Handle), AImage);
end;

TCustomForm

  • Win32, WinCE: it´s a HWND, a native window handle
  • Gtk: It´s a pointer to a structure.
  • Qt: The Handle is a pointer to a object from the TQtMainWindow class declared at qtprivate.pas. To have access to the QMainWindow Qt object it represents do: TQtMainWindow(Handle).Widget
  • Carbon: TCarbonWindow from carbonprivate.pp

TMenu, TMainMenu, TMenuItem and TPopUpMenu

  • Win32, WinCE : HMENU
  • Qt: TMainMenu is a pointer to a TQtMenuBar object. TPopUpMenu is a TQtMenu object. TMenuItem can either be a TQtAction if it represents a clickable item or a separator or a TQtMenu if it is an item that has submenus.