; Module/File: ComboBox_CursorposSetGet.pb ; Function: Set & get cursorpos from editable Combobox - Linux ; Author: Omi ; Date: Jun. 09, 2016 ; Version: 0.1 ; Target Compiler: PureBasic 5.22/5.31/5.4/5.5/5.6 ; Target OS: Linux: (X/K/L)ubuntu, Mint, 32/64, Ascii/Uni ;-------------------------------------------------------------- EnableExplicit #Win_Main= 0 #BtG1 = 0 #BtG2 = 1 #BtG3 = 2 #CbG1 = 3 Global.i gEvent, gQuit, gI Procedure.i Gtk_ComboBoxGetCurpos(Gadget) Protected *editable.GtkWidget= gtk_bin_get_child_(GadgetID(Gadget)) Protected.i Pos If *editable Pos= gtk_editable_get_position_(*editable) EndIf ProcedureReturn Pos EndProcedure Procedure Gtk_ComboBoxSetCurpos(Gadget, Pos) Protected *editable.GtkWidget= gtk_bin_get_child_(GadgetID(Gadget)) If *editable gtk_editable_set_position_(*editable, Pos) EndIf EndProcedure If OpenWindow(#Win_Main, #PB_Ignore, #PB_Ignore, 400, 250, "ComboBox get/set cursorpos", #PB_Window_ScreenCentered) ButtonGadget (#BtG1, 5, 5, 110, 26, "Cursor to start") ButtonGadget (#BtG2, 120, 5, 110, 26, "Cursor centered") ButtonGadget (#BtG3, 235, 5, 110, 26, "Cursor to end") ComboBoxGadget(#CbG1, 5, 35, 150, 30, #PB_ComboBox_Editable) AddGadgetItem(#CbG1, -1, "ComboBox text") For gI= 1 To 5 AddGadgetItem(#CbG1, -1, "item #"+ Str(gI)) Next gI SetGadgetState(#CbG1, 0) SetActiveGadget(#CbG1) Gtk_ComboBoxSetCurpos(#CbG1, -1); set to end Debug "Cursorpos: " + Str(Gtk_ComboBoxGetCurpos(#CbG1)); query Cursorpos ;no button-focus on click ... gtk_button_set_focus_on_click_(GadgetID(#BtG1), #False) gtk_button_set_focus_on_click_(GadgetID(#BtG2), #False) gtk_button_set_focus_on_click_(GadgetID(#BtG3), #False) EndIf Repeat gEvent = WaitWindowEvent() If EventWindow()= #Win_Main Select gEvent Case #PB_Event_CloseWindow gQuit= #True Case #PB_Event_Gadget Select EventGadget() Case #BtG1 Debug "Cursorpos: " + Str(Gtk_ComboBoxGetCurpos(#CbG1)); query Cursorpos SetActiveGadget(#CbG1) Gtk_ComboBoxSetCurpos(#CbG1, 0); set to start Case #BtG2 Debug "Cursorpos: " + Str(Gtk_ComboBoxGetCurpos(#CbG1)); query Cursorpos SetActiveGadget(#CbG1) Gtk_ComboBoxSetCurpos(#CbG1, Len(GetGadgetText(#CbG1)) / 2); centered Case #BtG3 Debug "Cursorpos: " + Str(Gtk_ComboBoxGetCurpos(#CbG1)); query Cursorpos SetActiveGadget(#CbG1) Gtk_ComboBoxSetCurpos(#CbG1, -1); set to end EndSelect EndSelect EndIf Until gQuit ; IDE Options = PureBasic 5.60 (Linux - x86) ; CursorPosition = 45 ; FirstLine = 37 ; Folding = - ; EnableXP ; EnableUnicode