Page 1 of 1

GTK-EventCallback and Unicode

Posted: Sun Jan 20, 2013 5:31 pm
by gerd
Hope somebody can help. The following code works fine in ascii mode, but not with unicode.
What do I have to do, to make it work in unicode?

Code: Select all

; Wrapper to call the correct function for Gtk.

Procedure GTKSignalConnect(*Widget, Signal$, Function, user_data)
    g_signal_connect_data_(*Widget, @Signal$, Function, user_data, 0, 0)
EndProcedure

; This is a signal callback. Note the CDLL declaration. that is important.
; the user_data field helps to pass additional data.
;
ProcedureCDLL EventCallback(*Widget, *Event.GdkEventCrossing, user_data)
  If user_data = 1
    Debug "Enter Event"
  Else
    Debug "Leave Event"
  EndIf
EndProcedure

If OpenWindow(0,0,0,345,105,"Event Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  myButton = ButtonGadget(#PB_Any, 200, 10, 100, 30, "Test")

; connect the signals...
GTKSignalConnect(GadgetID(myButton), "enter-notify-event", @EventCallback(), 1)
GTKSignalConnect(GadgetID(myButton), "leave-notify-event", @EventCallback(), 2)

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow : EndIf 
Thanks
gerd

Re: GTK-EventCallback and Unicode

Posted: Sun Jan 20, 2013 5:46 pm
by ts-soft
You can import the api with prototypes or use this:

Code: Select all

; Wrapper to call the correct function for Gtk.

Procedure GTKSignalConnect(*Widget, Signal$, Function, user_data)
  Protected *buffer = AllocateMemory(StringByteLength(Signal$, #PB_Ascii) + 1)
  If *buffer
    PokeS(*buffer, Signal$, -1, #PB_Ascii)
    g_signal_connect_data_(*Widget, *buffer, Function, user_data, 0, 0)
    FreeMemory(*buffer)
  EndIf
EndProcedure

; This is a signal callback. Note the CDLL declaration. that is important.
; the user_data field helps to pass additional data.
;
ProcedureCDLL EventCallback(*Widget, *Event.GdkEventCrossing, user_data)
  If user_data = 1
    Debug "Enter Event"
  Else
    Debug "Leave Event"
  EndIf
EndProcedure

If OpenWindow(0,0,0,345,105,"Event Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  myButton = ButtonGadget(#PB_Any, 200, 10, 100, 30, "Test")

; connect the signals...
GTKSignalConnect(GadgetID(myButton), "enter-notify-event", @EventCallback(), 1)
GTKSignalConnect(GadgetID(myButton), "leave-notify-event", @EventCallback(), 2)

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow : EndIf 
Greetings - Thomas

Re: GTK-EventCallback and Unicode

Posted: Sun Jan 20, 2013 6:06 pm
by gerd
Thank you Thomas

Re: GTK-EventCallback and Unicode

Posted: Wed Jan 30, 2013 7:49 pm
by uwekel
Hi Gerd,

you do not need a wrapper routine and you must not convert the event name string. Just use the pseudo-type ".p-utf8" as in the code below. This sample works in Ascii and Unicode mode :-)

Code: Select all

; Wrapper to call the correct function for Gtk.

ImportC ""
  g_signal_connect_data.i(*instance, detailed_signal.p-utf8, *c_handler, *data_=0, *destroy_data=0, *connect_flags=0)
EndImport

ProcedureC EventCallback(*Widget, *Event.GdkEventCrossing, user_data)
  If user_data = 1
    Debug "Enter Event"
  Else
    Debug "Leave Event"
  EndIf
EndProcedure

OpenWindow(0, 0, 0, 345, 105, "Event Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
*b = GadgetID(ButtonGadget(#PB_Any, 200, 10, 100, 30, "Test"))
g_signal_connect_data(*b, "enter-notify-event", @EventCallback(), 1)
g_signal_connect_data(*b, "leave-notify-event", @EventCallback(), 2)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Best Regards
Uwe

Re: GTK-EventCallback and Unicode

Posted: Sun Feb 03, 2013 3:21 pm
by gerd
Hi Uwe,

thanks for your reply. Your code works fine too.

Thanks
gerd

Re: GTK-EventCallback and Unicode

Posted: Wed Feb 20, 2013 9:19 am
by Poshu
Out of sheer curiosity, where could I find a list of available signal? The Gnome Dev Center isn't of much help here...

Re: GTK-EventCallback and Unicode

Posted: Wed Feb 20, 2013 10:00 am
by uwekel
For the PB gadgets you have to lookup the events fro the GTK widgets.
A good entry point is this: http://developer.gnome.org/gtk2/stable/