The implementation of the numeric SpinGadget on Linux is a PureBasic-own construct to maintain the compatibility. Unfortunately the functionality is very simplified against the API or Windows. This makes the handling a cumbersome matter.
see:
http://www.purebasic.fr/english/viewtop ... =3&t=63627
http://www.purebasic.fr/english/viewtop ... 13&t=60658
No value change with mousewheel or keyboard up/down-keys ist possible, and the mouseclick-repeat on up/down-arrows in the Gadget does not work either.
A simple tweak to a up/down-arrow-repeat on a permanent click (w/o singleclicks) has not yet succeeded to me!
But for the rest i've found a workaround for the PureBasic-SpinGadget on gtk2/gtk3.
1. Include the marked part in the code example,
2. and finally you only have to make an additional call of SpinGadget_Tweak(Window, Gadget) for each SpinGadget ...
I hope the team could be inspired thereof and implement something similar in the standard SpinGadget .
Code: Select all
EnableExplicit
; Object constants
#Win_Main = 0
Enumeration
#But1
#SpBG1
#SpBG2
#But2
EndEnumeration
Global.i gEvent, gEventType, gQuit
;- Part for tweaked SpinGadgets ...
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
ImportC ""
g_signal_connect(*instance, detailed_signal.p-utf8, *c_handler, *data, destroy= 0, flags= 0) As "g_signal_connect_data"
EndImport
;see https://git.gnome.org/browse/gtk+/plain/gdk/gdkkeysyms.h
#GDK_KEY_Up = $FF52
#GDK_KEY_Down= $FF54
Structure CALLBACKDATA
GadgetNo.i
WindowNo.i
EndStructure
Global NewList GadgetData.CALLBACKDATA()
ProcedureC Callback_SpinGadgetScroll(*widget.GtkWidget, *Event.GdkEventAny, *user_data.CALLBACKDATA); match callback name with the call in SpinGadget_Tweak
Protected *ev_scroll.GdkEventScroll
Protected *ev_keypress.GdkEventKey
Protected Ret= #False
If *Event\type = #GDK_SCROLL
*ev_scroll= *Event
ElseIf *Event\type = #GDK_KEY_PRESS
*ev_keypress= *Event
EndIf
If (*ev_scroll And *ev_scroll\direction = #GDK_SCROLL_UP) Or (*ev_keypress And *ev_keypress\keyval = #GDK_KEY_Up)
SetGadgetText(*user_data\GadgetNo, Str(Val(GetGadgetText(*user_data\GadgetNo))+ 1))
PostEvent(#PB_Event_Gadget, *user_data\WindowNo, *user_data\GadgetNo, #PB_EventType_Up)
PostEvent(#PB_Event_Gadget, *user_data\WindowNo, *user_data\GadgetNo, #PB_EventType_Change)
Ret= #True; avoids focus change on up/down key
ElseIf (*ev_scroll And *ev_scroll\direction = #GDK_SCROLL_DOWN) Or (*ev_keypress And *ev_keypress\keyval = #GDK_KEY_Down)
SetGadgetText(*user_data\GadgetNo, Str(Val(GetGadgetText(*user_data\GadgetNo))- 1))
PostEvent(#PB_Event_Gadget, *user_data\WindowNo, *user_data\GadgetNo, #PB_EventType_Down)
PostEvent(#PB_Event_Gadget, *user_data\WindowNo, *user_data\GadgetNo, #PB_EventType_Change)
Ret= #True; avoids focus change on up/down key
EndIf
ProcedureReturn Ret
EndProcedure
CompilerEndIf
Procedure SpinGadget_Tweak(Window, Gadget)
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
If GadgetType(Gadget) = #PB_GadgetType_Spin
Protected *entry.GtkEntry = g_list_nth_data_(gtk_container_get_children_(GadgetID(Gadget)), 0)
AddElement(GadgetData())
GadgetData()\GadgetNo= Gadget
GadgetData()\WindowNo= Window
gtk_widget_add_events_(*entry, #GDK_SCROLL_MASK | #GDK_KEY_PRESS_MASK)
g_signal_connect_(*entry, "scroll-event", @Callback_SpinGadgetScroll(), @GadgetData()); event on wheelscrolling over entry
g_signal_connect_(*entry, "key-press-event", @Callback_SpinGadgetScroll(), @GadgetData()); event on key up/down on focussed entry
EndIf
CompilerEndIf
EndProcedure
;- ... End of part
Procedure Create_WinMain()
If OpenWindow(#Win_Main, 300, 200, 600, 200, "PB-SpinGadget w. scrollwheel + up/down-key support", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget (#But1, 5, 5, 100, 26, "Gadget in front")
TextGadget (#PB_Any, 5, 45, 190, 22, "Tweaked PB-StringGadget")
SpinGadget (#SpBG1, 200, 40, 100, 26, 0, 10, #PB_Spin_Numeric)
TextGadget (#PB_Any, 5, 80, 190, 22, "Standard PB-StringGadget")
SpinGadget (#SpBG2, 200, 75, 100, 26, 0, 10, #PB_Spin_Numeric)
ButtonGadget (#But2, 5, 110, 100, 26, "Gadget rear")
SetGadgetState(#SpBG1, 5)
SetGadgetState(#SpBG2, 5)
SpinGadget_Tweak(#Win_Main, #SpBG1); add this call for each SpinGadget you wanna tweak
GadgetToolTip(#SpBG1, "Use mousewheel on hover or up/down-keys on focused SpinGadget")
EndIf
EndProcedure
Create_WinMain()
Repeat
gEvent= WaitWindowEvent()
Select gEvent
Case #PB_Event_CloseWindow
gQuit= #True
Case #PB_Event_Gadget
If EventGadget() = #SpBG1
gEventType= EventType()
If gEventType = #PB_EventType_Up
Debug "SpinGadget up"
ElseIf gEventType = #PB_EventType_Down
Debug "SpinGadget down"
ElseIf gEventType = #PB_EventType_Change
Debug "SpinGadget change"
Debug " ---"
EndIf
EndIf
EndSelect
Until gQuit
ps: 28-01-2018:
Fixed a bug with a LinkedList instead of the static structure, which caused the workaround to only work on the last SpinGadget!