GTKMaxGUI - ActiveGadget() is asynchronous?

BlitzMax Forums/Brucey's Modules/GTKMaxGUI - ActiveGadget() is asynchronous?

JoshK(Posted 2013) [#1]
It appears that ActiveGadget:TGadget() does not return the same gadget that is activated when ActivateGadget(gadget:TGadget) is called. In this case, ActivateGadget() appears to have no effect.

However, if we wait for all events to be processed, then the window will be recognized as being active:
SuperStrict 

Framework bah.gtkmaxgui
Import brl.eventqueue

Extern "C"
	Function gtk_window_is_active:Int(window:Byte Ptr)
EndExtern

Global window:TGadget = CreateWindow("MaxGUI Buttons",40,40,400,330,Null,WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS)
Local bt:TGadget=CreateButton("Std. Button",10,10,120,30,window,BUTTON_OK)

ActivateGadget window

Rem
'Uncomment this block and it will print '1'
While PeekEvent()
	WaitEvent()
Wend
EndRem

Print gtk_window_is_active(TGTKWindow(window).handle)
End


Is there some way to process the activation immediately?


JoshK(Posted 2013) [#2]
I'm digging into the source, and there seems to be very little correlation between what gtk_window_get_focus() returns and what is actually set to be the current widget. It seems to return the last created gadget of that type. This leads me to believe there may be some class function that is erroneously activating each gadget of that type.


JoshK(Posted 2013) [#3]
Now I'm getting somewhere!!! If you create three buttons, they all have the same handle:
SuperStrict 

Framework maxgui.maxgui
Import brl.eventqueue
Import "Source/GTKMaxGUI/gtkmaxgui.bmx"

Global window:TGadget = CreateWindow("MaxGUI Buttons",200,200,400,330,Null,WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS)
Local bt1:TGadget=CreateButton("Button 1",10,10,120,30,window)
Local bt2:TGadget=CreateButton("Button 2",10,100,120,30,window)
Local bt3:TGadget=CreateButton("Button 3",10,200,120,30,window)

Local widget:Byte Ptr
Local handle:Int

widget=TGTKGadget(bt1).handle
handle = Int Ptr(widget)[0]
Print handle

widget=TGTKGadget(bt2).handle
handle = Int Ptr(widget)[0]
Print handle

widget=TGTKGadget(bt3).handle
handle = Int Ptr(widget)[0]
Print handle

End



JoshK(Posted 2013) [#4]
Okay, I am pretty sure you should be doing this:
GadgetMap.Insert(TGTKInteger.Set(Int(handle)),gadget)

Instead of this:
GadgetMap.Insert(TGTKInteger.Set(Int Ptr(gadget.handle)[0]),gadget)

The first member of that structure is probably an ID for the type of widget it is.