collectordave wrote:After loading, a combogadget has extra whitespace at the top obvious only on first use.
This is not a PureBasic bug but a "feature" of GTK+ 2 and 3. Please take a look into
this bugzilla thread which has even 32 duplicates where users consider this behaviour as a bug. Even in the Ubuntu bug tracker
this bug entry was opened and a dev developed a fix which was not accepted upstream because the white spaces are considered a feature instead of a bug...
The reasoning of the GTK+ devs in not changing this seemingly bug is that the presence of a large empty area at the top or bottom of the pop-up menus is intentional: it allows the menu to pop up with the default option under the mouse, while still allowing some room for scrolling the other entries.
However in the above bugzilla thread Sven Neumann posted a hint how to suppress the white spaces at the top and bottom of the ComboBox popup by using the option "appears-as-list". I have therefore programmed a code example which demonstrates how to toggle between showing and suppressing the white spaces in both GTK+ 2 and 3. I have tested my example successfully with PB 5.61 on Linux Mint 18.1 x64 Serena with Cinnamon.
Unfortunately the workaround with "appears-as-list" has been removed from the GTK master branch in November 2016 (in GTK+ 3.22 it is still contained):
Code: Select all
EnableExplicit
CompilerIf Subsystem("gtk2") = #False
ImportC ""
gtk_css_provider_load_from_data(*CSSProvider, CSSData.P-UTF8, Length.I,
*Error.GError)
gtk_css_provider_new()
gtk_style_context_add_provider(*StyleContext, *StyleProvider, Priority.I)
gtk_style_context_add_provider_for_screen(*Screen.GdkScreen,
*StyleProvider, Priority.I)
gtk_widget_get_style_context(*Widget.GtkWidget)
EndImport
#GTK_STYLE_PROVIDER_PRIORITY_APPLICATION = 600
CompilerEndIf
#DQ$ = #DQUOTE$
Procedure CreateComboBox(AppearsAsList.I = 0)
Protected i.I
CompilerIf Subsystem("gtk2") = #False
Protected CSSProvider.I
Protected ComboBoxCSS.S
Protected Screen.I
ComboBoxCSS.S = "GtkComboBox { " +
"-GtkComboBox-appears-as-list: " + Str(AppearsAsList) + "; }"
CSSProvider= gtk_css_provider_new()
gtk_css_provider_load_from_data(CSSProvider, ComboBoxCSS, -1, 0)
Screen = gdk_display_get_default_screen_(gdk_display_get_default_())
gtk_style_context_add_provider_for_screen(Screen, CSSProvider,
#GTK_STYLE_PROVIDER_PRIORITY_APPLICATION)
g_object_unref_(CSSProvider)
CompilerElse
Protected RCString.S
RCString = "" +
"style " + #DQ$ + "default-style" + #DQ$ + #LF$ +
"{" + #LF$ +
" GtkComboBox::appears-as-list = " + Str(AppearsAsList) + #LF$ +
"}" + #LF$ +
#LF$ +
"class " + #DQ$ + "GtkWidget" + #DQ$ + " style " + #DQ$ +
"default-style" + #DQ$ + #LF$
gtk_rc_parse_string_(RCString)
CompilerEndIf
ComboBoxGadget(0, 20, 20, 90, 30)
For i = 1 To 6
AddGadgetItem(0, -1, "Item " + Str(i))
Next i
SetGadgetState(0, 5)
gtk_widget_show_(GadgetID(0))
EndProcedure
Define AppearsAsList.I
OpenWindow(0, 100, 10, 330, 70, "Change ComboBox style")
CreateComboBox(#False)
ButtonGadget(1, 130, 20, 180, 30, "Toggle ComboBox list style")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = 1
AppearsAsList ! 1
CreateComboBox(AppearsAsList)
EndIf
EndSelect
ForEver