Sign in Join
Wiki copytemporary

Accessing the Interfaces directly: what changed

Revision 2 to 3. 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.
2-
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
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.
182
193## Overview
204
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:
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:
226
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.
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.
2711
2812## Per-Widgetset Details
2913
3014### Qt
3115
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.
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.
3317
34-Most of those objects are descendents from TQtWidget as declared below:
35-```
18+Most of those objects are descendents from TQtWidget as declared below:
19+
20+``` pascal
3621{ TQtWidget }
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;
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;
4833```
4934
50-Notice the two variables they all contain:
35+Notice the two variables they all contain:
5136
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.
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.
5439
55-And also this method:
40+And also this method:
5641
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.
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.
5843
5944### Carbon
6045
61-Handles on [[Carbon Interface|Carbon]] are very similar to Qt ones. The helper classes are descended from abstract class TCarbonWidget.
62-```
46+Handles on [[Carbon Interface|Carbon]] are very similar to Qt ones. The helper classes are descended from abstract class TCarbonWidget.
47+
48+``` pascal
6349{ TCarbonWidget }
64-
65- TCarbonWidget = class(TObject)
66- private
67- public
68- Widget: Pointer;
69- LCLObject: TWinControl;
70- end;
50+
51+TCarbonWidget = class(TObject)
52+private
53+public
54+ Widget: Pointer;
55+ LCLObject: TWinControl;
56+end;
7157```
7258
73-Notice the two variables they all contain:
59+Notice the two variables they all contain:
7460
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.
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.
7763
7864### Windows
7965
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.
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.
8167
8268## List of Handles on various LCL classes
8369
8470### TFont
8571
86- * Win32, WinCE: HFONT
87- * Qt: A TQtFont object from qtprivate.pas
88- * Carbon: A TCarbonFont object from carbongdiobjects.pp
72+- Win32, WinCE: HFONT
73+- Qt: A TQtFont object from qtprivate.pas
74+- Carbon: A TCarbonFont object from carbongdiobjects.pp
8975
9076### TCanvas
9177
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
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
9884
9985### TBrush
10086
101- * Win32, WinCE: HBRUSH
102- * Qt: A TQtBrush object from qtprivate.pas
103- * Carbon: A TCarbonBrush object from carbongdiobjects.pp
87+- Win32, WinCE: HBRUSH
88+- Qt: A TQtBrush object from qtprivate.pas
89+- Carbon: A TCarbonBrush object from carbongdiobjects.pp
10490
10591### TBitmap
10692
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
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
11197
112-You can access this on Gtk using:
113-```
98+You can access this on Gtk using:
99+
100+``` pascal
114101var
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;
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;
130117```
131118
132119### TCustomForm
133120
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
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
140127
141128### TMenu, TMainMenu, TMenuItem and TPopUpMenu
142129
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
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
146133
147134## See also
148135
149- * [[Interfaces]]
150- * [[How To Use Interfaces]]
151- * [[Understanding Interfaces]]
136+- [[Interfaces]]
137+- [[How To Use Interfaces]]
138+- [[Understanding Interfaces]]
152139
153140---
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).*
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).*

Back to history