Another combogadget bug

Linux specific forum
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Another combogadget bug

Post by collectordave »

ubuntu 16.04LTS PB 5.61

After loading, a combogadget has extra whitespace at the top obvious only on first use. Clicking in this whitespace selects the first item and all works fine. After selection reclicking the combo gadget does not display this whitespace.

On first use when the list is displayed scrolling through the list until the whitespace disappears, the white space no longer esxists and all is normal. The code below shows this. All works fine on windows(64bit)

Code: Select all

Global Window_0

Global Combo_0

  Window_0 = OpenWindow(#PB_Any, 0, 0, 600, 400, "", #PB_Window_SystemMenu)
  Combo_0 = ComboBoxGadget(#PB_Any, 200, 70, 80, 20)
  
  For iLoop = 0 To 40
    AddGadgetItem(Combo_0,-1,"Item Number " + Str(iLoop))
  Next iLoop

  Repeat
      
      Event = WaitWindowEvent()
      Select Event

        Case #PB_Event_CloseWindow
          End

     EndSelect
    
  ForEver
cd
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Another combogadget bug

Post by Shardik »

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... :wink:

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):
[color=#0040FF][u]Emmanuele Bassi[/u][/color] wrote:Timm also removed the appears-as-list custom style property from GtkComboBox

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
Post Reply