It is currently Thu Dec 03, 2020 3:11 pm

All times are UTC + 1 hour

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Linux-PureBasic-ComboBox tweak f. gtk3 width issue
PostPosted: Tue Oct 24, 2017 8:10 pm 

Joined: Thu Jun 26, 2014 9:17 am
Posts: 312
Location: Germany
Under gtk3, non-editable ComboBoxGadgets have the big problem that their width is spread up to the widest popup item text.
Editable ComboBoxGadgets don't seem to have this problem.

I may have found a solution that can work around this problem. Tested with gtk3 on Xubuntu x32 14.04 + 17.04 and Mint KDE 18.3.
The editable ComboBoxGadget is converted to' not editable'.

Requirement: The ComboBox must be created with the flag '#PB_ComboBox_Editable', and for each ComboBoxGadget 'ComboBoxGadgetGadgetGtk3Tweak(#Gadget)' must be called.
Try it sometime. Maybe it will bypass a major gtk3 problem.
ImportC ""
   gtk_widget_set_can_focus(*widget.GtkWidget, can_focus)


; Object constants
#Win_Main  = 0

#CBox1     = 0
#CBox2     = 1

#Img1      = 0
#Img2      = 1

Global.i gEvent, gQuit

Procedure ComboBoxGadget_Gtk3Tweak(Gadget)
   CompilerIf #PB_Compiler_OS = #PB_OS_Linux
      If GadgetType(Gadget) = #PB_GadgetType_ComboBox
         Protected *entry.GtkEntry = gtk_bin_get_child_(GadgetID(Gadget))
         If *entry
            If PeekS(gtk_widget_get_name_(*entry), -1, #PB_UTF8) = "GtkEntry"
               gtk_editable_set_editable_(*entry, #False)
               gtk_widget_set_can_focus(*entry, #False)

Procedure Create_WinMain()
   If OpenWindow(#Win_Main, 0, 0, 500, 180, "ComboBoxGadget gtk3 width fix", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
      TextGadget    (#PB_Any,  5,   5, 490,  40, "Tweaked ComboBoxGadget 'editable' as 'non editable'." + #LF$ + "Watch the width-behaviour! It's similar to gtk2.")
      ComboBoxGadget(#CBox1,   5,  50, 100,  21, #PB_ComboBox_Editable | #PB_ComboBox_Image)
      If LoadImage(#Img1, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Open.png")
         AddGadgetItem  (#CBox1, -1, "Tweaked 'ComboBox editable' as", ImageID(#Img1))
      AddGadgetItem (#CBox1,  -1, "replacement for a non editable")
      AddGadgetItem (#CBox1,  -1, "Gtk3-ComboBoxGadget.")
      SetGadgetState(#CBox1,   0)
      TextGadget    (#PB_Any,  5,  90, 490,  40, "The same ComboBoxGadget as PB-Standard 'non editable'." + #LF$ + "The width corresponds to the widest item text in the popup.")
      ComboBoxGadget(#CBox2,   5, 130, 100,  21, #PB_ComboBox_Image)
      If LoadImage(#Img2, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Open.png")
         AddGadgetItem  (#CBox2, -1, "PureBasic gtk3-ComboBox, which", ImageID(#Img2))
      AddGadgetItem (#CBox2,  -1, "has always the width of the widest")
      AddGadgetItem (#CBox2,  -1, "item text.")
      SetGadgetState(#CBox2,   0)


   gEvent= WaitWindowEvent()
   Select gEvent
      Case #PB_Event_CloseWindow
         gQuit= #True
Until gQuit
Regards, Charly

PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer:

Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour

Who is online

Users browsing this forum: No registered users and 4 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye