Sign in Join
Wiki copytemporary

Accessing the Interfaces directly: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-This page describes how to write access the underlying [[Widgetset|widgetset]] used by lazarus directly (for example: The Windows API, or Gtk, or Qt, etc). One should always try to avoid relying on widgetset specials. This document is here for both people improving the widgetsets and for people writing components that really need to access the widgets directly.
1+This page describes how to write access the underlying [[Widgetset|widgetset]] used by lazarus directly (for example: The Windows API, or Gtk, or Qt, etc). One should always try to avoid relying on widgetset specials. This document is here for both people improving the widgetsets and for people writing components that really need to access the widgets directly.
22
3+## Contents
4+
5+ * 1 Overview
6+ * 2 Per-Widgetset Details
7+ * 2.1 Qt
8+ * 2.2 Carbon
9+ * 2.3 Windows
10+ * 3 List of Handles on various LCL classes
11+ * 3.1 TFont
12+ * 3.2 TCanvas
13+ * 3.3 TBrush
14+ * 3.4 TBitmap
15+ * 3.5 TCustomForm
16+ * 3.6 TMenu, TMainMenu, TMenuItem and TPopUpMenu
17+ * 4 See also
18+
319## Overview
420
5-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 interface:
21+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 interface:
622
7-- under [GTK](/wiki-category/GTK%20Widgetsets) a handle is often a PGtkWidget
8-- under Windows a handle is often a HWnd.
9-- under Carbon a handle is often a object descendant of TCarbonWidget.
10-- under Qt, a handle is often a pointer to a object descendent of TQtWidget.
23+ * under [GTK](</Category:GTK_Widgetsets> "Category:GTK Widgetsets") a handle is often a PGtkWidget
24+ * under Windows a handle is often a HWnd.
25+ * under Carbon a handle is often a object descendant of TCarbonWidget.
26+ * under Qt, a handle is often a pointer to a object descendent of TQtWidget.
1127
1228## Per-Widgetset Details
1329
1430### Qt
1531
16-Handles on [[Qt Interface|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 an event it will send it to the LCL.
17-
18-Most of those objects are descendents from TQtWidget as declared below:
32+Handles on [[Qt Interface|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 an event it will send it to the LCL.
1933
20-``` pascal
34+Most of those objects are descendents from TQtWidget as declared below:
35+```
2136{ TQtWidget }
22-
23-TQtWidget = class(TObject)
24-private
25- ...
26-public
27- Widget: QWidgetH;
28- LCLObject: TWinControl;
29-public
30- function GetContainerWidget: QWidgetH; virtual;
31- ...
32-end;
37+
38+ TQtWidget = class(TObject)
39+ private
40+ ...
41+ public
42+ Widget: QWidgetH;
43+ LCLObject: TWinControl;
44+ public
45+ function GetContainerWidget: QWidgetH; virtual;
46+ ...
47+ end;
3348```
3449
35-Notice the two variables they all contain:
50+Notice the two variables they all contain:
3651
37-- Widget - This is a connect to the Qt object for this Widget
38-- LCLObject - Is a bridge with the LCL object it is linked to.
52+ * Widget - This is a connect to the Qt object for this Widget
53+ * LCLObject - Is a bridge with the LCL object it is linked to.
3954
40-And also this method:
55+And also this method:
4156
42-- GetContrainerWidget() - When you wish to create a new widget and set it's parent, don't set it to Widget. Set it to GetContrainerWidget() instead. This happens because forms have 2 widgets. The main form widget, and also a container widget, where all child controls should be put to ensure that the size of the menu is handled automatically. Most other controls will have just one widget, but by using this function you avoid surprises in case the implementation of a control changes.
57+ * GetContrainerWidget() - When you wish to create a new widget and set it's parent, don't set it to Widget. Set it to GetContrainerWidget() instead. This happens because forms have 2 widgets. The main form widget, and also a container widget, where all child controls should be put to ensure that the size of the menu is handled automatically. Most other controls will have just one widget, but by using this function you avoid surprises in case the implementation of a control changes.
4358
4459### Carbon
4560
46-Handles on [[Carbon Interface|Carbon]] are very similar to Qt ones. The helper classes are descended from abstract class TCarbonWidget.
47-
48-``` pascal
61+Handles on [[Carbon Interface|Carbon]] are very similar to Qt ones. The helper classes are descended from abstract class TCarbonWidget.
62+```
4963{ TCarbonWidget }
50-
51-TCarbonWidget = class(TObject)
52-private
53-public
54- Widget: Pointer;
55- LCLObject: TWinControl;
56-end;
64+
65+ TCarbonWidget = class(TObject)
66+ private
67+ public
68+ Widget: Pointer;
69+ LCLObject: TWinControl;
70+ end;
5771```
5872
59-Notice the two variables they all contain:
73+Notice the two variables they all contain:
6074
61-- Widget - This is a connect to the Carbon object for this Widget: ControlRef (TCarbonControl descendants) or WindowRef (TCarbonWindow descendants).
62-- LCLObject - Is a bridge with the LCL object it is linked to.
75+ * Widget - This is a connect to the Carbon object for this Widget: ControlRef (TCarbonControl descendants) or WindowRef (TCarbonWindow descendants).
76+ * LCLObject - Is a bridge with the LCL object it is linked to.
6377
6478### Windows
6579
66-Handles on [[Win32/64 Interface|Win32]] or [[Windows CE Interface|WinCE]] are almost always the same as their corresponding Win api handles. For example the handle for a TMenu is an HMENU, the handle for a TBrush is an HBRUSH. You simply pass one such handle as a parameter in a Windows api call.
80+Handles on [[Win32/64 Interface|Win32]] or [[Windows CE Interface|WinCE]] are almost always the same as their corresponding Win api handles. For example the handle for a TMenu is an HMENU, the handle for a TBrush is an HBRUSH. You simply pass one such handle as a parameter in a Windows api call.
6781
6882## List of Handles on various LCL classes
6983
7084### TFont
7185
72-- Win32, WinCE: HFONT
73-- Qt: A TQtFont object from qtprivate.pas
74-- Carbon: A TCarbonFont object from carbongdiobjects.pp
86+ * Win32, WinCE: HFONT
87+ * Qt: A TQtFont object from qtprivate.pas
88+ * Carbon: A TCarbonFont object from carbongdiobjects.pp
7589
7690### TCanvas
7791
78-- Win32, WinCE: HDC
79-- Gtk: A TDeviceContext object from gtkdef.pp
80- - You can get a drawable, for example with: TDeviceContext(MyCanvas.Handle).Drawable
81-- Qt: A TQtDeviceContext object from qtprivate.pas
82-- Carbon: A TCarbonDeviceContext object from carboncanvas.pp
83- - The native handle can be accessed with TCarbonDeviceContext(MyCanvas.Handle).CGContext of type CGContextRef
92+ * Win32, WinCE: HDC
93+ * Gtk: A TDeviceContext object from gtkdef.pp
94+ * You can get a drawable, for example with: TDeviceContext(MyCanvas.Handle).Drawable
95+ * Qt: A TQtDeviceContext object from qtprivate.pas
96+ * Carbon: A TCarbonDeviceContext object from carboncanvas.pp
97+ * The native handle can be accessed with TCarbonDeviceContext(MyCanvas.Handle).CGContext of type CGContextRef
8498
8599### TBrush
86100
87-- Win32, WinCE: HBRUSH
88-- Qt: A TQtBrush object from qtprivate.pas
89-- Carbon: A TCarbonBrush object from carbongdiobjects.pp
101+ * Win32, WinCE: HBRUSH
102+ * Qt: A TQtBrush object from qtprivate.pas
103+ * Carbon: A TCarbonBrush object from carbongdiobjects.pp
90104
91105### TBitmap
92106
93-- Win32, WinCE: HBITMAP
94-- Gtk: PGDIObject (defined on unit GtkDef)
95-- Qt: A TQtImage object from qtobjects.pas unit
96-- Carbon: A TCarbonBitmap object from carbongdiobjects.pp
97-
98-You can access this on Gtk using:
107+ * Win32, WinCE: HBITMAP
108+ * Gtk: PGDIObject (defined on unit GtkDef)
109+ * Qt: A TQtImage object from qtobjects.pas unit
110+ * Carbon: A TCarbonBitmap object from carbongdiobjects.pp
99111
100-``` pascal
112+You can access this on Gtk using:
113+```
101114var
102- GDIObject: PGDIObject;
103- Bitmap: TBitmap;
104- AImage: PGtkWidget;
105-begin
106- ...
107-
108- GDIObject := PgdiObject(Bitmap.Handle);
109-
110- AImage := gtk_image_new_from_pixmap(GDIObject^.GDIPixmapObject,
111- GDIObject^.GDIBitmapMaskObject);
112-
113- gtk_widget_show(AImage);
114-
115- gtk_container_add(GTK_CONTAINER(MyForm.Handle), AImage);
116-end;
115+ GDIObject: PGDIObject;
116+ Bitmap: TBitmap;
117+ AImage: PGtkWidget;
118+ begin
119+ ...
120+
121+ GDIObject := PgdiObject(Bitmap.Handle);
122+
123+ AImage := gtk_image_new_from_pixmap(GDIObject^.GDIPixmapObject,
124+ GDIObject^.GDIBitmapMaskObject);
125+
126+ gtk_widget_show(AImage);
127+
128+ gtk_container_add(GTK_CONTAINER(MyForm.Handle), AImage);
129+ end;
117130```
118131
119132### TCustomForm
120133
121-- Win32, WinCE: it´s a HWND, a native window handle
122-- Gtk: It´s a pointer to a structure.
123-- Qt: The Handle is a pointer to a object from the TQtMainWindow class declared at qtwidgets.pas.
124- - To have access to the QMainWindow Qt object it represents do: TQtMainWindow(Handle).Widget
125- - To have access to the container widget of the form, do: TQtMainWindow(Handle).GetContrainerWidget
126-- Carbon: TCarbonWindow from carbonprivate.pp
134+ * Win32, WinCE: it´s a HWND, a native window handle
135+ * Gtk: It´s a pointer to a structure.
136+ * Qt: The Handle is a pointer to a object from the TQtMainWindow class declared at qtwidgets.pas.
137+ * To have access to the QMainWindow Qt object it represents do: TQtMainWindow(Handle).Widget
138+ * To have access to the container widget of the form, do: TQtMainWindow(Handle).GetContrainerWidget
139+ * Carbon: TCarbonWindow from carbonprivate.pp
127140
128141### TMenu, TMainMenu, TMenuItem and TPopUpMenu
129142
130-- Win32, WinCE : HMENU
131-- 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.
132-- Carbon: TMenuItem is a TCarbonMenu object, TMenu (TMainMenu and TPopupMenu) is represented by its root menu item
143+ * Win32, WinCE : HMENU
144+ * 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.
145+ * Carbon: TMenuItem is a TCarbonMenu object, TMenu (TMainMenu and TPopupMenu) is represented by its root menu item
133146
134147## See also
135148
136-- [[Interfaces]]
137-- [[How To Use Interfaces]]
138-- [[Understanding Interfaces]]
149+ * [[Interfaces]]
150+ * [[How To Use Interfaces]]
151+ * [[Understanding Interfaces]]
139152
140153---
141-*From the Free Pascal wiki, page "Accessing the Interfaces directly", as it stood on 2020-03-09 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
154+*From the Free Pascal wiki, page "Accessing the Interfaces directly", as the Internet Archive kept it on 2022-12-31. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history