Attaching objects to tabbers and updating.

BlitzMax Forums/BlitzMax GUI Programming/Attaching objects to tabbers and updating.

using degac sample and an eventhook, I think this is more or less what you want.
SuperStrict' createtabber.bmx
'Import MaxGui.Drivers
 
Local window:TGadget
Global tabber:TGadget
Global document:TGadget[3],pa:tgadget[3]
Global currentdocument:TGadget

' CreateDocument creates a hidden panel that fills entire tabber client area 

Function CreateDocument:TGadget(tabber:TGadget)
	Local	panel:TGadget
	panel=CreatePanel(0,0,ClientWidth(tabber),ClientHeight(tabber),tabber)
	SetGadgetLayout panel,1,1,1,1
	HideGadget panel
	Return panel
End Function

' create a default window with a tabber gadget that fills entire client area

window=CreateWindow("My Window",30,20,400,300)

tabber=CreateTabber(0,0,ClientWidth(window),ClientHeight(window),window)
SetGadgetLayout tabber,1,1,1,1 

' add three items and corresponding document panels to the tabber

AddGadgetItem tabber,"Red Curve",False,-1,""
AddGadgetItem tabber,"Green Curve",False,-1,"Tabber Tip 1"
AddGadgetItem tabber,"Blue Curve",False,-1,"tips 4 2"

document[0]=CreateDocument(tabber)
document[1]=CreateDocument(tabber)
document[2]=CreateDocument(tabber)

SetPanelColor document[0],255,200,200
SetPanelColor document[1],200,255,200
SetPanelColor document[2],200,200,255

'to keep track of the canvases associated each to one tab (document[])


pa[0]=CreateCanvas(10 , 10 , 100 , 100 , document[0])
pa[1]=CreateCanvas(10 , 10 , 200 , 100 , document[1])
pa[2]=CreateCanvas(10 , 10 , 100 , 200 , document[2])

AddHook EmitEventHook, MyHook
' our documents start off hidden so make first one current and show

currentdocument=document[0]
ShowGadget currentdocument


Global grfx:tgraphics = CanvasGraphics(pa[0])
SetGraphics grfx 

' standard message loop with special tabber GADGET_ACTION handling
SetColor 255,0,0
Global text$ = "Red Canvas"
Global what_canvas:Int=0
'CreateTimer 60
Global index% = 0
While WaitEvent()
	Select EventID() 
	
			
		Case EVENT_GADGETPAINT
			updateCanvas()
			
			
		Case EVENT_WINDOWCLOSE
			End
	End Select
Wend

Function MyHook:Object(iId:Int,tData:Object,tContext:Object)
	Local Event:TEvent=TEvent(tData)
	
	If Event.source=tabber 
		index = event.data
		UpdateCanvas()
		Return Null
  	EndIf

	Return tData
End Function

Function UpdateCanvas:Int()
	Select  index
		Case 0
			SetColor 255,0,0
			text = "Red Canvas"
		Case 1
			SetColor 0,255,0
			text = "Green Canvas"
		Case 2
			text = "Blue Canvas"
			SetColor 0,0,255
	End Select
	grfx:tgraphics = CanvasGraphics(pa[index])
	SetGraphics grfx
	If currentdocument <> document[index]
		HideGadget currentdocument
		currentdocument = document[index]
	EndIf
	ShowGadget currentdocument 
    Cls
	DrawText text,0,0 
    Flip
End Function