; Module/File: ComboBox_WidthIssueWorkaround_Gtk3.pb ; Function: (Temp.) Workaround for the variable width problem on gtk3-ComboBoxes - Linux gtk3 ; Author: Omi ; Date: Sep. 24, 2017 ; Version: 0.1 ; Target Compiler: PureBasic 5.4/5.5/5.6 ; Target OS: Linux: (X/K/L)ubuntu, Mint, 32/64, Ascii/Uni ;-------------------------------------------------------------- ImportC "" gtk_widget_set_can_focus(*widget.GtkWidget, can_focus) EndImport UsePNGImageDecoder() ; 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) EndIf EndIf EndIf CompilerEndIf EndProcedure 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)) EndIf 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)) EndIf AddGadgetItem (#CBox2, -1, "has always the width of the widest") AddGadgetItem (#CBox2, -1, "item text.") SetGadgetState(#CBox2, 0) ComboBoxGadget_Gtk3Tweak(#CBox1) EndIf EndProcedure Create_WinMain() Repeat gEvent= WaitWindowEvent() Select gEvent Case #PB_Event_CloseWindow gQuit= #True EndSelect Until gQuit ; IDE Options = PureBasic 5.46 LTS Beta 1 (Linux - x86) ; CursorPosition = 1 ; Folding = - ; EnableUnicode ; EnableXP