[Lazarus] More Gtk3 Status

Kostas Michalopoulos badsector at runtimeterror.com
Fri Jul 15 18:45:02 CEST 2022


On 7/15/22 14:47, Anthony Walter via lazarus wrote:
> Denis,
> 
> I will attempt the big design flaws [...]
> Now here is the first big problem with the Gtk3 widgetset 
> as implemented. Somehow someone decided it would be a neat idea to add a 
> 4th piece just for Gtk3. [...]

This isn't a flaw, the approach the Gtk3 backend has makes sense if you 
consider that it is trying to avoid all the special case functionality 
for what essentially mimicing the Win32 API in an increasingly (in every 
major version) weird and "non-Win32-like" API.

In a way the Gtk1 and Gtk2 widgetsets do it too but if anything they do 
it in a messier way because for anything non-trivial they allocate a 
separate TWidgetInfo object (a record) that they map between the 
Gtk1/Gtk base widget and the LCL functionality/data that needs to 
emulate the Win32 behavior all the time when that data is needed with 
the source code being littered with calls like 
"GetOrCreateWidgetInfo(handle)".

The Gtk3 widgetset instead of doing that uses the OOP functionality that 
Free Pascal had for decades now :-P to avoid doing that runtime mapping 
and put widget-specific functionality in its own class. Otherwise that 
functionality would need to be spread all over the place - especially 
for calls that assume that a call with HWND would apply to all widgets 
the same way.

Also about that "just for Gtk3", in fact it isn't just the Gtk3 backend 
that takes the OOP approach with a custom class per control - from a 
quick look, the Qt, Qt5, FPGUI, Carbon and MUI widgetsets take that 
approach too.

> Just make the control handle an actual reference to 
> the underlying system toolkit handle, and please DO NOT attempt to 
> recreate another object hierarchy
While it can be a minor surprise, in practice you are already dealing 
with widgetset-specific functionality anyway and you should always keep 
the widgetset itself "in the loop" - meaning that even if you try to 
bypass it, you still need to know what the widgetset does. And again, if 
anything, the Gtk3 approach still seems better because control has its 
own class for the underlying widgets which makes it easier to find what 
is going on.

Kostas


More information about the lazarus mailing list