Page 1 of 1

[solved]Can't compile Unicode using g_signal_connect_()?

Posted: Wed Jan 11, 2012 8:23 pm
by idle
I can't find a work around to compile in unicode mode using g_signal_connect
it's a macro and should accept UTF8 encoding but how to do it?

compile in unicode it doesn't work!

Code: Select all

ImportC "-gtk"
EndImport

ProcedureC onSize(*widget.GtkWidget,*event.GtkAllocation)
  Debug *event\x
  Debug *event\y
  ProcedureReturn 1
EndProcedure  

OpenWindow(1,0,0,200,100,"g_signalConnect")
ButtonGadget(0,5,5,60,20,"OK")
g_signal_connect_(GadgetID(0),"size-allocate",@onSize(),0)

Repeat 
Until WaitWindowEvent() = #PB_Event_CloseWindow 
Edit this works
Scroll the mouse wheel over the button!

Code: Select all

ImportC "-gtk"
  g_signal_connect(instance,signal.p-ascii,*fn,*vdata,destroy=0,flags=0) As "g_signal_connect_data"
EndImport

ProcedureC onScroll(*widget.GtkWidget,*event.GdkEventScroll,pbID)
  Debug *event\direction 
  Debug pbid 
  ProcedureReturn 1
EndProcedure 

OpenWindow(1,0,0,200,100,"g_signalConnect")
ButtonGadget(2,5,5,60,20,"OK")
ButtonGadget(3,5,30,60,20,"OK TOO")
g_signal_connect(GadgetID(2),"scroll-event",@onScroll(),2)
g_signal_connect(GadgetID(3),"scroll-event",@onScroll(),3)

Repeat
  Ev = WaitWindowEvent()
  evg = EventGadget()
  If Ev
    If  evg = 2 
      Debug EventType()
    EndIf
  EndIf
Until Ev = #PB_Event_CloseWindow 

Re: Can't compile Unicode using g_signal_connect_()?

Posted: Wed Jan 11, 2012 8:38 pm
by Guimauve
Hello,

I'm just about to suggest this workaround :

Code: Select all

ImportC "-gtk"
EndImport

ProcedureC onSize(*widget.GtkWidget,*event.GtkAllocation)
	Debug *event\x
	Debug *event\y
	ProcedureReturn 1
EndProcedure  

Procedure GLIB_signal_connect(instance, detailed_signal.s, c_handler, Data_)
  
  *Source.Character = @detailed_signal
  g_signal_connect_(instance, PeekS(*Source, Len(detailed_signal), #PB_UTF8), c_handler, Data_)
  
EndProcedure

OpenWindow(1,0,0,200,100,"g_signalConnect")
ButtonGadget(0,5,5,100,30,"OK")

GLIB_signal_connect(GadgetID(0), "size-allocate",@onSize(),0)

; g_signal_connect_(GadgetID(0),"size-allocate",@onSize(),0)

Repeat 
Until WaitWindowEvent() = #PB_Event_CloseWindow
But the code still generate this warning message :
GLib-GObject (Warning): /build/buildd/glib2.0-2.30.0/./gobject/gsignal.c:2295: signal 's' is invalid for instance '0xd8d830'
Best regards.
Guimauve

Re: Can't compile Unicode using g_signal_connect_()?

Posted: Wed Jan 11, 2012 9:29 pm
by idle
The macro maps to g_signal_connect_data
this appears to work but it's not right!

Code: Select all

ImportC "-gtk"
  g_signal_connect_data(instance,*signal,*fn,*vdata,destroy,flags)
EndImport

Prototype gsignal_connect(*widget,signal.p-utf8,*fn,*vdata,destroy=0)
Global gsignal_connect.gsignal_connect = @g_signal_connect_data()

ProcedureC onScroll(*widget.GtkWidget,*event.GdkEventScroll)
  Debug *event\direction
   ProcedureReturn 1
EndProcedure  

OpenWindow(1,0,0,200,100,"g_signalConnect")
ButtonGadget(2,5,5,60,20,"OK")

gsignal_connect(GadgetID(2),"scroll-event",@onScroll(),0)

Repeat 
  Ev = WaitWindowEvent() 
  evg = EventGadget()
  If Ev 
    If  evg = 2  
      Debug EventType()
    EndIf
  EndIf 
Until Ev = #PB_Event_CloseWindow 



Re: Can't compile Unicode using g_signal_connect_()?

Posted: Wed Jan 11, 2012 10:23 pm
by Guimauve
It's probably because some signal should be added to the gadget. Also, special PB EventType are for specific gadget only and this can be an issue.

Best regards.
Guimauve

Re: Can't compile Unicode using g_signal_connect_()?

Posted: Wed Jan 11, 2012 10:43 pm
by idle
Got it a fix

Code: Select all

ImportC "-gtk"
  g_signal_connect(instance,signal.p-ascii,*fn,*vdata,destroy=0,flags=0) As "g_signal_connect_data"
EndImport

ProcedureC onScroll(*widget.GtkWidget,*event.GdkEventScroll,pbID)
  Debug *event\direction 
  Debug pbid 
  ProcedureReturn 1
EndProcedure 

OpenWindow(1,0,0,200,100,"g_signalConnect")
ButtonGadget(2,5,5,60,20,"OK")
ButtonGadget(3,5,30,60,20,"OK TOO")
g_signal_connect(GadgetID(2),"scroll-event",@onScroll(),2)
g_signal_connect(GadgetID(3),"scroll-event",@onScroll(),3)

Repeat
  Ev = WaitWindowEvent()
  evg = EventGadget()
  If Ev
    If  evg = 2 
      Debug EventType()
    EndIf
  EndIf
Until Ev = #PB_Event_CloseWindow  
you can add any signal to a gadget you want since they're inherited from gtkwidget
http://developer.gnome.org/gtk/2.24/Gtk ... et.signals

Re: Can't compile Unicode using g_signal_connect_()?

Posted: Wed Jan 11, 2012 11:49 pm
by Guimauve
idle wrote:you can add any signal to a gadget you want since they're inherited from gtkwidget
http://developer.gnome.org/gtk/2.24/Gtk ... et.signals
Possible but what happen when we add signals and function to a Gadget when this gadget already have the added signals with different function attached ? They will be all executed or they will interfere each other ?
Thanks for the link.

Best regards.
Guimauve

Re: [solved]Can't compile Unicode using g_signal_connect_()?

Posted: Thu Jan 12, 2012 5:34 pm
by idle
I don't know but I expect It'll just add it to the hook chain.