Sign in Join
Wiki copytemporary

GTK2 Interface: what changed

Revision 3 to 4. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11*(GTK+ only)*
22
33## Introduction
44
55The gtk2 widgetset is stable and all components work. And it needs optimizations.
66
77The documentation can be found [here](http://www.gtk.org/).
88
99The minimum Gtk 2 version supported is Gtk 2.8
1010
1111## Road map for the gtk2 interface
1212
1313Here: [[Roadmap|Roadmap#Widgetset_dependent_components]]
1414
1515## Quick start guide for Linux, FreeBSD, etc
1616
1717The first thing to do is to install the gtk2 libraries including the development packages. For example: linux/debian systems call them libgtk2.0-dev. There are complete installers for Windows [here](http://www.gtk.org/).
1818
1919The gtk2 is the default widgetset, so it should work out of the box.
2020
2121You can compile the LCL for gtk2. First open your normal compiled Lazarus. Then go on the menu "Tools" --\> "Configure Build Lazarus". Set LCL to "clean+build" and everything else to "None". Now select "gtk2" and click on the "Ok" button. Next go to the menu "Tools" --\> "Build Lazarus". Now the LCL is compiled for gtk2 too.
2222
2323To compile a project for gtk2 just select it as the target widgetset on the Compiler Options dialog.
2424
2525### Ubuntu Unity liboverlay
2626
2727The Ubuntu's Unity LIBOVERLAY override breaks the gtk_grab_add function, so mouse capturing does not work in synedit, treeview and many more LCL controls that descend from TCustomControl. That means dragging or selecting text with the mouse does not work.
2828
2929This is true for many applications, which is why liboverlay has an internal list to disable itself for many famous applications (e.g. gimp).
3030
3131That's why the gtk2 interface of the LCL disables liboverlay by default. You can enable it by compiling the LCL with -dEnableLibOverlay.
3232
3333If it is enabled: The LCL will write a warning with [[DebugLn]] if it spots liboverlay.
3434
3535To disable liboverlay for a single application set the environment variable LIBOVERLAY_SCROLLBAR to '0' *before* starting the application. There is no way to disable liboverlay when the application is already running. For example:
3636
37-`LIBOVERLAY_SCROLLBAR=0 ./lazarus`
37+```text
38+LIBOVERLAY_SCROLLBAR=0 ./lazarus
39+```
3840
3941You can disable it on a whole machine by uninstalling the package "liboverlay-scrollbar-0.2-0".
4042
4143The IDE starter "startlazarus" sets this variable before starting the IDE (since 1.0). startlazarus is called for example when you use the desktop menu item.
4244
4345### Ubuntu Unity Menuproxy
4446
4547In more recent Ubuntu versions, Ubuntu tries to create a "one menubar" look like macOS has, but this fails miserably with multi window programs like Lazarus. The main problem is not being able to access the menu without first selecting the main lazarus window. (the window that would hold the menubar).
4648
4749Turning off seems to be impossible without massive changes (probably that is because then everybody would turn such features off immediately).
4850
4951Turning off manually is possible through setting environment variable UBUNTU_MENUPROXY equal to 0 before starting.
5052
5153UBUNTU_MENUPROXY=0 ./lazarus
5254
5355or put it in a script like:
5456
55-`#!/bin/sh`\
56-`export UBUNTU_MENUPROXY=0`\
57-`./startlazarus`
57+```text
58+#!/bin/sh
59+export UBUNTU_MENUPROXY=0
60+./startlazarus
61+```
5862
5963### Raspberry Pi OS
6064
6165Note: the following advice is proably not necessary if you have installed libgtk2.0-dev as mentioned further up this page
6266
6367Lazarus GTK2 cannot be compiled by default, because of missing symlinks for libraries. These symlinks are missed:
6468
6569- libgdk-x11-2.0.so
6670- libgtk-x11-2.0.so
6771- libX11.so
6872- libgdk_pixbuf-2.0.so
6973- libglib-2.0
7074- libgthread-2.0.so
7175- libgmodule-2.0.so
7276- libpango-1.0.so
7377- libcairo.so
7478- libatk-1.0.so
7579
7680The existing .so files are located in the "/usr/lib/aarch64-linux-gnu". For all mentioned files, you need to make symlinks like this:
7781
78-`cd /usr/lib/aarch64-linux-gnu`\
79-`sudo ln -s libatk-1.0.so.0 libatk-1.0.so`
82+```text
83+cd /usr/lib/aarch64-linux-gnu
84+sudo ln -s libatk-1.0.so.0 libatk-1.0.so
85+```
8086
8187## Using the GTK2 interface under macOS
8288
8389### Installing X11
8490
8591If you want to use the gtk widgetset instead of the default Carbon widgetset, then make sure **X11** is installed. X11 is no longer included with Mac, but X11 server and client libraries are available from the [XQuartz project](https://www.xquartz.org/). The last XQuartz release was version 2.7.11 on 2016-10-29 for Snow Leopard 10.6.3 or later.
8692
8793How do you know whether X11 is installed? Look in the /Applications/Utilities folder for an application named XQuartz.app. All further details are in /opt/X11/ (soft linked from /usr/X11).
8894
8995**Tip** - Drag and drop X11 onto the dock so you'll have a one-click way of opening an X11 window.
9096
9197### Installing GTK2-Lazarus with fink
9298
9399Install [Fink](http://www.finkproject.org/), the package manager for macOS. Install the GTK2 version of Lazarus with the following command:
94100
95-` fink install lazarus-gtk2`
101+```text
102+ fink install lazarus-gtk2
103+```
96104
97105You will be asked to install a number of other packages. Simply answer yes. The installation takes quite a while. After it has finished, the GTK2 application can be started with a double click on /Applications/Fink/lazarus.
98106
99107Note: Projects using GTK2 can equally be created using the Aqua version of Lazarus, which is installed with "fink install lazarus-aqua".
100108
101109### Installing gtk using MacPorts
102110
103111Follow these steps to install the libraries using MacPorts. Install MacPorts from [**www.macports.org**](http://www.macports.org/). When MacPorts is set up, you need to install two library sets using the following commands:
104112
105-`sudo /opt/local/bin/port install gtk1`\
106-`sudo /opt/local/bin/port install gdk-pixbuf`
113+```text
114+sudo /opt/local/bin/port install gtk1
115+sudo /opt/local/bin/port install gdk-pixbuf
116+```
107117
108118Then make sure that Lazarus can find the library by using the command below before running Lazarus. Alternatively you can add this command to your bash startup script (`/etc/profile` or `~/.bash_profile`) before you start the shell to run Lazarus:
109119
110-`export DYLD_FALLBACK_LIBRARY_PATH="/opt/local/lib:$DYLD_FALLBACK_LIBRARY_PATH"`
120+```text
121+export DYLD_FALLBACK_LIBRARY_PATH="/opt/local/lib:$DYLD_FALLBACK_LIBRARY_PATH"
122+```
111123
112124If this doesn't work, simply do
113125
114-`sudo ln -s /opt/local /sw`
126+```text
127+sudo ln -s /opt/local /sw
128+```
115129
116130### Using the GTK2 libraries included with Gimp
117131
118132Now that the Cocoa widgetset is the default for Lazarus on macOS, there probably isn't much need for developing or distributing GTK2-based apps on macOS. However, you might want to test your apps with the GTK2 widgetset to see how well the graphical portion will work under Linux, where GTK2 is likely to be the default. You can also compile Lazarus itself against the GTK2 widgetset if you're curious about how Lazarus looks with GTK2.
119133
120134An easy way to obtain recent GTK2 libraries is to download and install Gimp from <http://www.gimp.org/macintosh/>. Gimp is not only a useful image editor in its own right, but it also installs GTK2 version **2.16.6** libraries that you can link your apps against.
121135
122136Copy and paste the files given below into a text editor and save them as **gimplib.cfg** and **glaunch.sh**. File gimplib.cfg tells FPC how to link against the GTK2 libraries; file glaunch.sh initializes GTK2 and starts a GTK2-compiled executable specified on the command line.
123137
124138To compile an app against the GTK2 widgetset and link it with the Gimp GTK2 libraries, do the following:
125139
126140- In the Lazarus Compiler Options dialog, on the Other tab, check Use Additional Compiler Config File and enter the path to gimplib.cfg in the text box (for example, ~/tools/scripts/gimplib.cfg).
127141- In the Lazarus Compiler Options dialog, on the Paths tab, select GTK2 as the LCL Widget Type.
128142- Choose Run \| Build.
129143
130144To run a GTK2-compiled executable, open an X11 window, change to your app's folder, and enter the following (which assumes glaunch.sh is in ~/tools/scripts):
131145
132146- ~/tools/scripts/glaunch.sh myexec
133147
134148To compile Lazarus itself, do the following:
135149
136150- Open an X11 window and change to your Lazarus source folder.
137151- Make a copy of your Carbon-based Lazarus, in case something goes wrong (cp -p lazarus lazarus-carb).
138152- make clean all LCL_PLATFORM=gtk2 FPC=fpc OPT="@~/tools/scripts/gimplib.cfg -dHasX"
139153
140154This will rebuild lazarus, lazbuild and startlazarus. You'll probably want to rename your lazarus executables:
141155
142156- mv lazarus lazarus-gtk2
143157- mv lazarus-carb lazarus
144158
145159To run the GTK2-compiled Lazarus:
146160
147161- ~/tools/scripts/glaunch.sh lazarus-gtk2
148162
149163Here is the gimplib.cfg config file. Note that this assumes you installed Gimp in your Applications folder.
150164
151165 -k'-headerpad_max_install_names'
152166 -k'-L/usr/lib'
153167 -k'-L/usr/X11R6/lib'
154168 -k'-L/Applications/Gimp.app/Contents/Resources/lib'
155169 -k'-lgthread-2.0'
156170
157171 -k'-dylib_file'
158172 -k'/tmp/skl/Gimp.app/Contents/Resources/lib/libpangoft2-1.0.0.dylib:/Applications/Gimp.app/Contents/Resources/lib/libpangoft2-1.0.0.dylib'
159173 -k'-dylib_file'
160174 -k'/tmp/skl/Gimp.app/Contents/Resources/lib/libz.1.dylib:/Applications/Gimp.app/Contents/Resources/lib/libz.1.dylib'
161175 -k'-dylib_file'
162176 -k'/tmp/skl/Gimp.app/Contents/Resources/lib/libpangocairo-1.0.0.dylib:/Applications/Gimp.app/Contents/Resources/lib/libpangocairo-1.0.0.dylib'
163177 -k'-dylib_file'
164178 -k'/tmp/skl/Gimp.app/Contents/Resources/lib/libgmodule-2.0.0.dylib:/Applications/Gimp.app/Contents/Resources/lib/libgmodule-2.0.0.dylib'
165179 -k'-dylib_file'
166180 -k'/tmp/skl/Gimp.app/Contents/Resources/lib/libintl.8.dylib:/Applications/Gimp.app/Contents/Resources/lib/libintl.8.dylib'
167181 -k'-dylib_file'
168182 -k'/tmp/skl/Gimp.app/Contents/Resources/lib/libiconv.2.dylib:/Applications/Gimp.app/Contents/Resources/lib/libiconv.2.dylib'
169183 -k'-dylib_file'
170184 -k'/tmp/skl/Gimp.app/Contents/Resources/lib/libcairo.2.dylib:/Applications/Gimp.app/Contents/Resources/lib/libcairo.2.dylib'
171185 -k'-dylib_file'
172186 -k'/tmp/skl/Gimp.app/Contents/Resources/lib/libfreetype.6.dylib:/Applications/Gimp.app/Contents/Resources/lib/libfreetype.6.dylib'
173187 -k'-dylib_file'
174188 -k'/tmp/skl/Gimp.app/Contents/Resources/lib/libfontconfig.1.dylib:/Applications/Gimp.app/Contents/Resources/lib/libfontconfig.1.dylib'
175189 -k'-dylib_file'
176190 -k'/tmp/skl/Gimp.app/Contents/Resources/lib/libexpat.1.dylib:/Applications/Gimp.app/Contents/Resources/lib/libexpat.1.dylib'
177191 -k'-dylib_file'
178192 -k'/tmp/skl/Gimp.app/Contents/Resources/lib/libXrender.1.dylib:/Applications/Gimp.app/Contents/Resources/lib/libXrender.1.dylib'
179193 -k'-dylib_file'
180194 -k'/tmp/skl/Gimp.app/Contents/Resources/lib/libtiff.3.dylib:/Applications/Gimp.app/Contents/Resources/lib/libtiff.3.dylib'
181195 -k'-dylib_file'
182196 -k'/tmp/skl/Gimp.app/Contents/Resources/lib/libjpeg.62.dylib:/Applications/Gimp.app/Contents/Resources/lib/libjpeg.62.dylib'
183197 -k'-dylib_file'
184198 -k'/tmp/skl/Gimp.app/Contents/Resources/lib/libpng12.0.dylib:/Applications/Gimp.app/Contents/Resources/lib/libpng12.0.dylib'
185199 -k'-dylib_file'
186200 -k'/tmp/skl/Gimp.app/Contents/Resources/lib/libXinerama.1.dylib:/Applications/Gimp.app/Contents/Resources/lib/libXinerama.1.dylib'
187201 -k'-dylib_file'
188202 -k'/tmp/skl/Gimp.app/Contents/Resources/lib/libpixman-1.0.dylib:/Applications/Gimp.app/Contents/Resources/lib/libpixman-1.0.dylib'
189203 -k'-dylib_file'
190204 -k'/tmp/skl/Gimp.app/Contents/Resources/lib/libgio-2.0.0.dylib:/Applications/Gimp.app/Contents/Resources/lib/libgio-2.0.0.dylib'
191205 -k'-dylib_file'
192206 -k'/tmp/skl/Gimp.app/Contents/Resources/lib/libjasper.1.dylib:/Applications/Gimp.app/Contents/Resources/lib/libjasper.1.dylib'
193207
194208Here is the glaunch.sh script file:
195209
196210 #!/bin/sh
197211
198212 TMP="/tmp/$UID/TemporaryItems"
199213 GRES="Gimp.app/Contents/Resources"
200214 GIMP="/Applications/$GRES"
201215 if ! [ -e "$GIMP" ]
202216 then
203217 GIMP="~/Desktop/$GRES"
204218 if ! [ -e "$GIMP" ]
205219 then
206220 GIMP="~/$GRES"
207221 if ! [ -e "$GIMP" ]
208222 then
209223 GIMP="~/Applications/$GRES"
210224 if ! [ -e "$GIMP" ]
211225 then
212226 GIMP=""
213227 fi
214228 fi
215229 fi
216230 fi
217231
218232 if [ "$GIMP" = "" ]
219233 then
220234 echo "Can't locate Gimp"
221235 else
222236 export "DYLD_FORCE_FLAT_NAMESPACE=1"
223237 export "DYLD_INSERT_LIBRARIES=/usr/lib/libiconv.dylib"
224238 export "DYLD_LIBRARY_PATH=/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/Resources:$GIMP/lib"
225239 export "PANGO_RC_FILE=$TMP/pangorc"
226240 export "FONTCONFIG_PATH=$GIMP/etc/fonts"
227241 export "GTK_IM_MODULE_FILE=$TMP/gtk.immodules"
228242 export "GDK_PIXBUF_MODULE_FILE=$TMP/gdk-pixbuf.loaders"
229243 export "GTK_DATA_PREFIX=$GIMP"
230244 export "GTK_EXE_PREFIX=$GIMP"
231245
232246 mkdir -p "$TMP"
233247 sed 's|/tmp/skl/Gimp.app/Contents/Resources/etc/pango|'"$TMP|g" "$GIMP/etc/pango/pangorc" > "$TMP/pangorc"
234248 sed 's|/tmp/skl/Gimp.app/Contents/Resources|'"$GIMP|g" "$GIMP/etc/pango/pango.modules" > "$TMP/pango.modules"
235249 cp -f "$GIMP/etc/pango/pangox.aliases" "$TMP"
236250 sed 's|/tmp/skl/Gimp.app/Contents/Resources|'"$GIMP|g" "$GIMP/etc/gtk-2.0/gtk.immodules" > "$TMP/gtk.immodules"
237251 sed 's|/tmp/skl/Gimp.app/Contents/Resources|'"$GIMP|g" "$GIMP/etc/gtk-2.0/gdk-pixbuf.loaders" > "$TMP/gdk-pixbuf.loaders"
238252
239253 ./$1
240254 fi
241255
242256## Using the Gtk2 interface under Microsoft Windows
243257
244258### Getting the needed Gtk2 libraries
245259
246260Using the Gtk2 libraries from gtk.org:
247261
248262- <http://www.gtk.org/download>
249263
250264or using the GTK-Runtime project:
251265
252266- <https://gtk-win.sourceforge.io>
253267
254268or using the Gtk2 libraries provided by Gimp:
255269
256270- <http://gimp-win.sourceforge.net/stable.html>
257271
258272### Standalone Application under Windows
259273
260274You may prefer a standalone application to avoid versions conflicts. All needed libraries are in the packages mentioned above. They should be placed in the same folder of your executable. You will need all these libraries:
261275
262276- libcairo-2.dll
263277- libglib-2.0-0.dll
264278- libpangocairo-1.0-0.dll
265279- libpng12.dll
266280- libgdk-win32-2.0-0.dll
267281- libgmodule-2.0-0.dll
268282- libgtk-win32-2.0-0.dll
269283- libatk-1.0-0.dll
270284- libgdk_pixbuf-2.0-0.dll
271285- libgobject-2.0-0.dll
272286- libpango-1.0-0.dll
273287- libpangowin32-1.0-0.dll
274288- libgio-2.0-0.dll
275289- zlib1.dll
276290
277291### Themes
278292
279293The default GTK2 interface is quite ugly and not very integrated with the Windows Desktop. Your GTK2 application may use the Windows Theme if you use the [gtk-wimp project](http://gtk-wimp.sourceforge.net/). Into your application's folder you should add the following files ([Available here](http://sourceforge.net/project/showfiles.php?group_id=76416)):
280294
281295- .\lib\gtk-2.0\engines\libwimp.dll
282296- .\share\themes\Raleigh\gtk-2.0\gtkrc
283297
284298### A sample project
285299
286300A complete and working "Hello world" project (with sources) is available [here](http://www.lazarusforum.de/lazwiki/winGTK2_Demo.zip).
287301
288302![](/wiki-images/b/b1/WinGTK2.png)
289303
290304## Current issues
291305
292306Here are some notes about some of the current issues. It is not a complete list, but mainly a collection of the information about some of the most annoying problems, that can not be solved simply.
293307
294308### Editor Options allows to select incompatible fonts
295309
296310TFontDialog must be extended to show only monospace fonts by default and only if the users insists show all fonts.
297311
298312### Moving with keys in the OI sometimes does not move the edit field
299313
300314ToDo
301315
302316### Destroying handle during OnKeyDown gives AV
303317
304318This is a more general problem, not only KeyDown. There are two solutions:
305319
306320- Increase reference counters of all used widgets during events. Difficult to maintain and we will never be sure to ref count every used widget.
307321- Instead of destroying widgets immediately, hide them, untie them and put them into a queue. The widgets will then be destroyed in the message loop and on gtk intf shut down.
308322
309323### Z-Order of controls
310324
311325In Gtk2 many controls don't have a window, so they are just painted on their parent. This makes they be painted before controls with a window, so we get a wrong Z-Order.
312326
313327Here is a list of gtk widgets that don't have windows: <https://developer.gnome.org/gtk-tutorial/stable/x481.html>
314328
315329The solution is adding a GtkEventBox under each of these widgets: <https://developer.gnome.org/gtk-tutorial/stable/c1226.html#SEC-EVENTBOX>
316330
317331**Bug reports**
318332
319333- <http://bugs.freepascal.org/view.php?id=964>
320334- <http://bugs.freepascal.org/view.php?id=8346>
321335
322336### Open Dialog Options
323337
324338TOpenDialog has several options to control the dialog. When implementing these options in Gtk2, however, one needs to watch out because of the vast amount of bugs in Gtk 2, which may prevent the options from working. For example, ofForceShowHidden doesn't work because of Gtk 2 bugs, althougth it is implemented correctly.
325339
326340**Bug reports**
327341
328342- ofForceShowHidden - <http://bugs.freepascal.org/view.php?id=8473>
329343
330344### TScrollBox and Scrolling problems
331345
332346TScrollBox and Scrolling seems deeply broken in Gtk 2.
333347
334348**Bug reports**
335349
336350- <http://bugs.freepascal.org/view.php?id=10779>
337351- <http://bugs.freepascal.org/view.php?id=10952>
338352- <http://bugs.freepascal.org/view.php?id=9049>
339353- <http://bugs.freepascal.org/view.php?id=11010>
340354
341355### Shortcut keys
342356
343357**Bug reports**
344358
345359- <http://bugs.freepascal.org/view.php?id=1946>
346360- <http://bugs.freepascal.org/view.php?id=7249>
347361- <http://bugs.freepascal.org/view.php?id=10282>
348362
349363### Up/Down key navigation between TEdits
350364
351365A standard Gtk 2 feature allows the use of up/down key to navigate between GtkEntry widgets (like TEdits), but this is undesirable if the user implements a dropdrow list to be attached to the TEdit. As we cannot know what code the user has written, the best option is to disable this feature. Possible ways to do that are:
352366
353367- Listen to key press events of GtkEntry and for Up/Down events shift the focus to implemented widget.
354368- Don't propagate Up/Down key press events to GtkEntry.
355369
356370**As of lazarus 0.9.31 r31562 GtkEntry behaviour is same as under other widgetsets - NO FOCUS CHANGING BY VK_UP or VK_DOWN.**
357371
358372**Bug reports**
359373
360374- <http://bugs.freepascal.org/view.php?id=11115>
361375
362376## Done issues
363377
364378### Done: ~~Synedit is very slow~~
365379
366380Actually this is not a bug of the gtk2 intf, but a problem of gtk2 and some video drivers. On some systems SynEdit is as fast as any other text editor. Some bugs were fixed with gtk 2.12. SynEdit already paints every token with the ExtTextOut function. It does not use a TCanvas text function, which would be even slower.
367381
368382Bug Tracker item: <http://www.freepascal.org/mantis/view.php?id=7717>
369383
370384For people using the Nvidia drivers, setting GlyphCache=1 may speed up SynEdit. You will need the beta-drivers: <http://www.nvnews.net/vbulletin/showthread.php?s=399832e3761a522d34db6faaf8423ad9&t=118088>
371385
372386### Done: ~~Small TButton does not center text~~
373387
374388Actually the text is centered, but some themes (like the default under ubuntu) define a big minimum space above and below the label. The gtk2 default is not that big. So, it is a user setting.
375389
376390- a\) It might be possible to override this setting and set the space to 0.
377391 - Pro: Most small autosize buttons would look better.
378392 - Cons: the AutoSize would be incorrect. And the bug is still there for themes with big text.
379393- b\) set the interface constraint to the gtk_button normal height.
380394 - Pro: there are no small buttons.
381395 - Con: Enlarging a button requires autosizing all surrounding controls too. And you need a nice auto shrink feature, which does not exist yet.
382396- c\) Set the space to 0 and when calculating the preferred size, restore temporarily the space size.
383397 - Pro: Most small buttons will look better, autosize will still work.
384398 - Con: Most difficult solution to implement. Maybe not possible without a hack.
385399
386400**Bug Reports**
387401
388402- <http://bugs.freepascal.org/view.php?id=11120>
389403- <http://bugs.freepascal.org/view.php?id=8765>
390404
391405### Done: ~~TOpenPictureDialog does not update the preview~~
392406
393407### Done: ~~Only the main form appears in the window list~~
394408
395409Probably a bug in the window hints parameters.
396410
397411### Done: ~~Slow and visible resizing when creating/resizing a dialog~~
398412
399413This has several reasons, which fall into 3 categories:
400414
4014151\. Too many resizes. Status: Acceptable.
402416
4034172\. Slow painting. Status: It seems other gtk2 apps are as slow, so maybe it is a gtk2 issue.
404418
4054193\. Some resizes happen after painting. Status: Acceptable.
406420
407421- The application does not resize the controls in one step, but in many small steps. For example: It resizes a control in several small steps SetBounds, AnchorParallel, ... . Or first the the Form is resized, then the a TPageControl, then a TButton, ... . Solution: The LCL sets BeginAlign/EndAlign during loading/creation.
408422- If there are anchored or autosized controls, every resize triggers the resize system of the the LCL. The LCL tries to combine many resizes during csLoading and Begin/EndAlign. During creation the LCL still sends several times the bounds to the interface. ToDo Solution: Send bounds not during BeginAlign (including parents), but send them all in EndAlign.
409423- The hen-egg problem. In order to autosize, the LCL needs the current gtk theme sizes. The current gtk theme sizes can only be calculated by creating a handle. When you create a handle you need the size. Solution: Create some hidden widgets to test the current gtk sizes. This already works for TCustomGroupBox and descendants. ToDo: the other controls.
410424- The gtk does not resize immediately, but puts resizes on a queue and resizes later. These values are stored in private, hidden variables. Especially if you resize a TGroupBox, the inner borders are updated later by the gtk. That means the GetClientRect function is not reliable during resizing. That's why the LCL first works with the wrong ClientRect. Solution: The LCL anticipates the new ClientRect based on the old. And there is now a GetDefaultClientRect function to ask the interface for an estimation of the ClientRect.
411425- The gtk1 intf caches LCL resize requests. This accelerates many typical overhead, but it only works with delayed painting and creates flicker during creation and resizing a form never works smooth. The delayed painting breaks the gtk2 double buffering and special paint contexts (opengl), so this trick is disabled under gtk2 and therefore the delayed resize does not work under gtk2.
412426- Top level controls, like TForm can not move/resize freely. The window manager decides, what is possible. Often they take only the first position/size request and ignores the later changes. And even worse: first the window is created, realized, then resized, then mapped and 'shown' and finally moved to the final position. So, if the gtk intf asks the gtk where a form is during creation, it will most of the time get 0,0, even though it told the gtk to move the window long ago. Because this is a more general problem (not gtk specific, but X), the LCL tries avoids asking the interface for coords and only asks on rare occasions like LM_SIZE, LM_MOVE messages coming from the interface or if told to do so.
413427- The LCL expects a LM_SIZE message on resize, including window state changes like iconify/maximize. But the gtk first notifies about the change and then resizes. ToDo: 1. Maybe: Omit the message, if the state does not change (is this Delphi compatible?). 2. Send the current window state with the normal resizes (Should work for maximize and restore from maximize). 3. Find a solution for iconify and restore from iconify.
414428
415429Things done to handle the above issues:
416430
417431- The gtk2 intf now calls gtk_widget_size_allocate when resizing widgets. This initializes the Widget^.allocation, so that further reads by the LCL no longer give old values.
418432- Resizes of child widgets (not gtkwindow or not top level) are now given to the gtk immediately. This does not resize immediately, but together with other changes this resizes earlier, reducing the total number of resizes.
419433- gtk resize events are now given almost always directly to the LCL. The only exception is gtkwindow and the client areas (gtk_fixed). The gtk resize events come bottom up, so the client areas are always triggered before the widget itself is resized.
420434- The gtk intf now checks the mapped attribute for gtkwindow, which seems finally to work reliable under gtk2. This means the gtk intf no longer send window positions to the LCL, before the window is really moved.
421435- In order to let the LCL resize during component/handle creation, the new function GetDefaultClientRect allows every widget class to provide a nice clientrect even before the handle is created. This is done by using the hidden style widgets of the gtk intf.
422436
423437### Done: ~~Selecting a TPage in the designer gives the wrong bounds rectangle~~
424438
425439GetClientOrigin needed extra code for TNotebook, which does not have a normal client area.
426440
427441### Done: ~~Sometimes the hint window of the component palette is not resized~~
428442
429443Sometimes the gtk does not resize the gdkwindow. This is now forced and it seems to fix this problem.
430444
431445### Done: ~~gtk criticals in IDE codetools options dialog~~
432446
433447Empty comboboxes do not have all private structures, so you can not set callbacks.
434448
435449### Done: System Colors
436450
437451The system colors depend on the theme, but many themes don't give adequate colors and many controls use system colors, so we need them to have a correct value. To solve this, a list of ignored system colors was constructed, and in case the user sets any of these colors, it is ignored and the default theme color is used instead.
438452
439453List of colors which were tested and need to be ignored for the correct functioning of programs:
440454
441455- clBtnFace - Otherwise Notebooks and Buttons look bad
442456
443457**Bug reports**
444458
445459- <http://bugs.freepascal.org/view.php?id=8684>
446460
447461## Gtk1/Gtk2 separation roadmap
448462
449463List of already separated elements:
450464
451465- gtk2wscomctrls --- gtkwscomctrls
452466- gtk2wsdialogs --- gtkwsdialogs
453467- gtk2wsspin --- gtkwsspin
454468- gtk2wscalendar --- gtkwscalendar
455469
456470Next tasks:
457471
458472- Rework of the events system
459473- Rework of private classes
460474
461475## Profiling
462476
463477There are various compiler switches:
464478
465479- VerboseSizeMsg - This will show you all changes and messages, with coords and reasons. Even for simple forms this gives a lot of output.
466480- DisableLoadedClientSize - This will ignore the ClientWidth/Height stored in the .lfm/.lrs files. This way you can somehow simulate, what happens, if you start an application under a different theme.
467481
468482---
469483*From the Free Pascal wiki, page "GTK2 Interface", as it stood on 2022-11-25 after a change by Dbannon, 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