As suggested I have objectified it.
this is the new creation code
Global gmain:_gmain = _gmain.create()
Type _gmain
Field window:gwindow
Field tabber:gtabber
Const networktoolbar:Int = 0
Function hookupdate_networktab:Int()
'this function is hooked by the update function
Select EventSource()
Case gmain.i.tabber
Select EventID()
Case EVENT_ACTION
gmain.tabber.changetab(EventData())
End Select
Case gmain.tabber.tabs[0].gadgets[0]
'toolbar event
Select EventID()
Case EVENT_ACTION
'user has requested network information
'disable refresh button
gmain.tabber.tabs[0].gadgets[0].disablebutton(0)
'clear the tree nodes
tnetworktree.instance.clear()
'request list of servers from the master
tcpc_master.sendcommand(_command_adminrequestservers)
End Select
Case gmain.i.tabber.tabs[0].gadgets[1]
'tree view event
Select EventID()
Case EVENT_ACTION
'check if server / peer info window
Local temp_peer:tnetworktree_peer = tnetworktree.instance.findpeerfromgadget(tgadget(EventExtra()))
If temp_peer
CreatePeerWindow(nip,nport)
End If
End Select
End Select
End Function
Function create:_gmain()
Local window:_gmain = New _gmain
window.window = gwindow.create("Master admin",[10,10,500,500])
window.tabber = gtabber.create(window.insiderect(),window)
'network tab
window.tabber.addtab("Network","Browse the network")
window.tabber.tabs[0].addgadget(gtoolbar.create([0,0,window.tabber.tabs[0].insidewidth(),24],window.tabber.tabs[0],imagepath_networktoolbar,"Refresh the network"))
window.tabber.tabs[0].addgadget(gtreeview.create([0,window.tabber.tabs[0].gadgets[0].outerheight(),window.tabber.tabs[0].innerwidth,window.tabber.tabs[0].innerheight()-window.tabber.tabs[0].gadgets[0].outerheight()],window.tabber.tabs[0],iconstrip_networktreeview))
window.tabber.tabs[0].gadget[1].addnode("master",0)
'window.tabber.tabs[0].setupdatehook(
'log tab
window.tabber.addtab("Logs","View traffic logs")
window.tabber.tabs[1].addgadget(gtextarea.create(window.tabber.tabs[0].innerrect(),window.tabber.tabs[1],True))
Return window
End Function
End Type
this is the code that does the work
Import BRL.Win32MaxGUI
Import BRL.EventQueue
Type ggadget Abstract
Global list:TList = CreateList()
Field gadgets:ggadget[]
Field gadget:tgadget
Field _hookupdate:Int()
Method update:Int()
'this function should return true if it wants to halt gui updates
If _hookupdate <> Null Return _hookupdate()
'scan through all gadgets until a return was matched
If gadgets.length > 0
Local temp_i:Int
For temp_i = 0 Until gadgets.length
If gadgets[temp_i].update() Return True
Next
End If
End Method
Method setupdatehook:Int(nhook:Int())
_hookupdate = nhook
End Method
Method show:Int()
ShowGadget(Gadget)
End Method
Method hide:Int()
HideGadget(gadget)
End Method
Method enable:Int()
EnableGadget(gadget)
End Method
Method disable:Int()
DisableGadget(gadget)
End Method
Method insidex:Int()
Return 0
End Method
Method insidey:Int()
Return 0
End Method
Method insidewidth:Int()
Return ClientWidth(gadget)
End Method
Method insideheight:Int()
Return ClientHeight(gadget)
End Method
Method outsidex:Int()
Return GadgetX(gadget)
End Method
Method outsidey:Int()
Return GadgetY(gadget)
End Method
Method outsidewidth:Int()
Return GadgetWidth(gadget)
End Method
Method outsideheight:Int()
Return GadgetHeight(gadget)
End Method
Method insiderect:Int[](noffsetx:Int=0,noffsety:Int=0,noffsetw:Int=0,noffseth:Int=0)
Return [0+noffsetx,0+noffsety,ClientWidth(gadget)+noffsetw,ClientHeight(gadget)+noffseth]
End Method
Method outsiderect:Int[](noffsetx:Int=0,noffsety:Int=0,noffsetw:Int=0,noffseth:Int=0)
Return [GadgetX(gadget)+noffsetx,GadgetY(gadget)+noffsety,ClientWidth(gadget)+noffsetw,ClientHeight(gadget)+noffseth]
End Method
Method addgadget:Int(ngadget:ggadget)
Local temp_slot:Int = gadgets.length
gadgets = gadgets[..temp_slot+1]
gadgets[temp_slot] = ngadget
Return temp_slot
End Method
End Type
Type gwindow Extends ggadget
Field window:tgadget
Function create:gwindow(ntitle:String,nrect:Int[],nparent:ggadget=Null,nstyle:Int=WINDOW_TITLEBAR)
Local window:gwindow = New gwindow
Local temp_parent:tgadget = Null
If nparent <> Null temp_parent = nparent.gadget
window.window = CreateWindow(ntitle,nrect[0],nrect[1],nrect[2],nrect[3],temp_gadget,nstyle)
window.gadget = CreatePanel(nrect[0],nrect[1],nrect[2],nrect[3],window.window)
SetGadgetLayout(window.gadget,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED)
Return window
End Function
End Type
Type gtoolwindow Extends ggadget
Field window:tgadget
Function create:gtoolwindow(ntitle:String,nrect:Int[],nparent:ggadget=Null,nstyle:Int=WINDOW_TITLEBAR)
Local window:gtoolwindow = New gtoolwindow
Local temp_parent:tgadget = Null
If nparent <> Null temp_parent = nparent.gadget
window.window = CreateWindow(ntitle,nrect[0],nrect[1],nrect[2],nrect[3],temp_gadget,nstyle | WINDOW_TOOL)
window.gadget = CreatePanel(nrect[0],nrect[1],nrect[2],nrect[3],window.window)
SetGadgetLayout(window.gadget,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED)
Return window
End Function
End Type
Type gtabber Extends ggadget
Field selected:Int = -1
Field icons:ticonstrip
Field tabs:gtab[]
Method addtab:gtab(ntitle:String,ntip:String="",nicon:Int=-1)
'create a new tab ggadget
Local tab:gtab = New gtab
'setup the tab
tab.slot = tabs.length
tab.gadget = CreatePanel(0,0,ClientWidth(gadget),ClientHeight(gadget),gadget)
SetGadgetLayout(tab.gadget,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED)
'resize tabs array for this new tab
tabs = tabs[..tab.slot+1]
tabs[tab.slot] = tab
'add tab to tabber
AddGadgetItem(gadget,ntitle,0,nicon,ntip)
'hide the tab unless it is only current active tab in tabber
If tabs.length > 1
tab.hide()
Else
selected = 0
End If
Return tab
End Method
Method changetab:Int(ntab:Int)
If ntab > tabs.length Or ntab = selected Return False
Local temp_i:Int
tabs[selected].hide()
tabs[ntab].show()
End Method
Function create:gtabber(nrect[],nparent:ggadget=Null,nicons:Object=Null)
Local tabber:gtabber = New gtabber
Local temp_parent:tgadget = Null
If nparent <> Null temp_parent = nparent.gadget
tabber.gadget = CreateTabber(nrect[0],nrect[1],nrect[2],nrect[3],temp_parent,nstyle)
Local iconstrip:ticonstrip = ticonstrip(nicons)
If iconstrip = Null
tabber.icons = LoadIconStrip(String(nicons))
Else
tabber.icons = ticonstrip(nicons)
End If
If tabber.icons SetGadgetIconStrip(tabber.gadget,tabber.icons)
SetGadgetLayout(tabber.gadget,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED)
Return tabber
End Function
End Type
Type gtab Extends ggadget
Field slot:Int
End Type
Type glistbox Extends ggadget
Field icons:ticonstrip
Function create:glistbox(nrect[],nparent:ggadget=Null,nicons:Object=Null)
Local listbox:glistbox = New glistbox
Local temp_parent:tgadget = Null
If nparent <> Null temp_parent = nparent.gadget
Local iconstrip:ticonstrip = ticonstrip(nicons)
If iconstrip = Null
listbox.icons = LoadIconStrip(String(nicons))
Else
listbox.icons = ticonstrip(nicons)
End If
listbox.gadget = CreateListBox(nrect[0],nrect[1],nrect[2],nrect[3],temp_parent)
If listbox.icons SetGadgetIconStrip(listbox.gadget,listbox.icons)
Return listbox
End Function
End Type
Type gtoolbar Extends ggadget
Field toolbar:tgadget
Function enablebutton:Int(nbutton:Int)
EnableGadgetItem(toolbar,nbutton)
End Function
Function disablebutton:Int(nbutton:Int)
DisableGadgetItem(toolbar,nbutton)
End Function
Function create:gtoolbar(nrect[],nparent:ggadget=Null,nicons:String="",ntips:String[]=Null)
Local toolbar:gtoolbar = New gtoolbar
Local temp_parent:tgadget = Null
If nparent <> Null temp_parent = nparent.gadget
toolbar.gadget = CreatePanel(nrect[0],nrect[1],nrect[2],nrect[3],nparent.gadget)
SetGadgetLayout(toolbar.toolbar,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED)
If ntips SetToolBarTips(toolbar.toolbar,ntips)
Return toolbar
End Function
End Type
Type gtreeview Extends ggadget
Field icons:ticonstrip
Field nodes:gtreeviewnode[]
Method addnode:Int(ntitle:String,nicon:Int=-1)
Local node:gtreeviewnode = New gtreeviewnode
node.parent = TreeViewRoot(gadget)
node.gadget = AddTreeViewNode(ntitle,node.parent,nicon)
Local temp_slot:Int = nodes.length
nodes = nodes[..temp_slot+1]
nodes[temp_slot] = node
Return temp_slot
End Method
Function create:gtreeview(nrect[],nparent:ggadget=Null,nicons:Object=Null)
Local treeview:gtreeview = New gtreeview
Local temp_parent:tgadget = Null
If nparent <> Null temp_parent = nparent.gadget
treeview.gadget = CreateTreeView(nrect[0],nrect[1],nrect[2],nrect[3],temp_parent)
Local iconstrip:ticonstrip = ticonstrip(nicons)
If iconstrip = Null
treeview.icons = LoadIconStrip(String(nicons))
Else
treeview.icons = ticonstrip(nicons)
End If
If treeview.icons SetGadgetIconStrip(treeview.gadget,treeview.icons)
Return treeview
End Function
End Type
Type gtreeviewnode
Field parent:tgadget
Field gadget:tgadget
Field nodes:gtreeviewnode[]
Method addnode:Int(ntitle:String,nicon:Int=-1)
Local node:gtreeviewnode = New gtreeviewnode
node.parent = gadget
node.gadget = AddTreeViewNode(ntitle,node.parent,nicon)
Local temp_slot:Int = nodes.length
nodes = nodes[..temp_slot+1]
nodes[temp_slot] = node
Return temp_slot
End Method
End Type
Type gtextarea Extends ggadget
Function create:gtextarea(nrect[],nparent:ggadget=Null,nreadonly:Int=False)
Local textarea:gtextarea = New gtextarea
Local temp_parent:tgadget = Null
If nparent <> Null temp_parent = nparent.gadget
If nreadonly = False
textarea.gadget = CreateTextArea(nrect[0],nrect[1],nrect[2],nrect[3],temp_parent)
Else
textarea.gadget = CreateTextArea(nrect[0],nrect[1],nrect[2],nrect[3],temp_parent,TEXTAREA_READONLY)
End If
Return textarea
End Function
End Type
better ?
|