Sign in Join
Wiki copytemporary

LCL Interface Redesign Idea: what changed

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

Title: LCL Interface Redesign Idea

OldNewLine
1+## Why would we want this ?
2+
3+In the present situation, the handle returned by TWSWinControl.CreateHandle is in case of win32 the winapi handle of the widget and in case of gtk a PGtkWidget. For the QT and Carbon widgetset a private internal object is returned. Using an internal object has some advantages. One of them is that we can use a true object hierarchy, with clear inheritence inside the widgetset. However, many code using the LCL expects the handle being castable. Returning an object would break this.
4+
5+> **Note:** In case of gtk, we don't have to return the internal object, we still can use the existing way of retrieving the widgetinfo
6+
7+> **Note:** We also can start to use LCLHandle only, so that a later transition will be easier
8+
9+## This is current Idea for the structure of the interface and how it relates to handles
10+
11+Overview:
12+
13+- Fork a branch of lazarus/
14+- Replace TWinControl.Handle with TWinControl.LCLHandle (there should exist no Handle yet)
15+- Try to get the LCL compiled and maybe the IDE so it doesn't use the (inefficient) .Handle anymore
16+- Introduce .Handle again, now as WSclass call
17+- Merge the branches
18+
19+**The change to .Handle will not break existing code.**
20+
21+``` pascal
22+TWSxxWinControl.CreateHandle Returns a ILCLHandle
23+
24+ILCLHandle = IInterface; // interfaces as com objects
25+
26+TxxPrivate = class(TPrivate, ILCLHandle);
27+
28+TGtkPrivateButton = class(TGtkBin, ILCLHandle);
29+```
30+
31+All TWSxx. methods should be moved to the private class. for instance:
32+
33+``` pascal
34+class procedure TWSGtkWinControl.SetText(const AWinControl; const AText: String);
35+var
36+ PrivWinControl: TGtkPrivateWinControl;
37+begin
38+ PrivWinControl := TGtkPrivateWinControl(AWinControl.LCLHandle);
39+ PrivWinControl.SetText(AText);
40+end;
41+```
42+
43+> **Note:** I'm not to sure if we should expose the ILCLHandle as Interface. This will cause an overhead of adding exception frames, addref and releaseref calls. We can do it internally and use TLCLHandle = PtrUInt (MWE).
44+
45+## Other possibilities
46+
47+For accessing widgetset native handles or IDs from the LCL, in the current situation, ppl have to cast the handle. In the case of gtk, to retrieve the XID, one needs the following cast:
48+
49+``` pascal
50+PGdkPrivateWindow(PGtkWidget(Handle)^.window)^.XID
51+```
52+
53+When interfaces are used, one can imagine the following code
54+
55+``` pascal
56+{$IFDEF GtkHasX}
57+TGtkPrivateWidget = class(TGtkPrivate, ILCLHandle, IX11Handle);
58+
59+(AWinControl.LCLHandle as IX11Handle).XID
60+```
61+
62+or maybe better:
63+
64+``` pascal
65+if Supports(AWinControl.LCLHandle, IX11Handle, X11Handle) then
66+ ... DoSomething with X11Handle
67+```
68+
69+Which leads to cleaner constructs, without the need of internal knowledge of the handle and can be the same in all widgetsets that use X11.
70+
71+Note that for this we need COM interfaces and not CORBA, however we **don't need reference counting**, so AddRef and ReleseRef can be implemented by just returning -1
72+
73+
74+A problem with interfaces is that Qt for example runs in several operating systems. How do you know what is supported where? We will need to fill the class definition with ifdefs.
75+
76+---
77+*From the Free Pascal wiki, page "LCL Interface Redesign Idea", as it stood on 2021-04-08 after a change by Skalogryz, 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).*
78+Category: LCL
79+Category: Lazarus Proposals
80+Category: Proposals

Back to history