summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2006-01-10 00:41:03 +0000
committerIan C <ianc@noddybox.co.uk>2006-01-10 00:41:03 +0000
commit2b568c741b63f912c25d37dd1171fc667b71b36c (patch)
treed7136c37ef24e4ca7505ba473edecd2985e9d87b
parent9bac73ab4b86a500a5dbe16676cc411cf5f7fbb1 (diff)
Development checkin
-rw-r--r--mwidget.mod/mwidget.bmx856
1 files changed, 802 insertions, 54 deletions
diff --git a/mwidget.mod/mwidget.bmx b/mwidget.mod/mwidget.bmx
index 139de6d..11ff5ae 100644
--- a/mwidget.mod/mwidget.bmx
+++ b/mwidget.mod/mwidget.bmx
@@ -1,7 +1,7 @@
Rem
bbdoc: noddybox.mwidget
-about: Provides a simply class based interface to the MaxGUI. Note that all widgets have create type methods. For thes to work correctly with
-sub-classes they must be called through a new operation, e.g.
+about: <p>Provides a simply class based interface to the MaxGUI. Note that all widgets have create type methods. For these to work correctly with
+sub-classes they must be called through a new operation, e.g.</p>
<pre>
Type MyApp Extends TMWindow
&nbsp;&nbsp;&nbsp;&nbsp;Method OnClose(e:TEvent)
@@ -10,7 +10,26 @@ Type MyApp Extends TMWindow
End Type
Local window:TMWindow=New MyApp.Create("Test",100,100,640,400)
+MWidgetMainLoop(window)
</pre>
+<p>
+There are two methods of getting events. One is to subclass and override the events, as with the @OnClose() above. The other is to set
+function pointers in the matching event lists, @OnCloseEvent in this instance. For instance:
+</p>
+<pre>
+Function OnClose(o:TMWidget)
+&nbsp;&nbsp;&nbsp;&nbsp;Local w:TMWindow=TMWindow(o)
+&nbsp;&nbsp;&nbsp;&nbsp;w.closed=Confirm("Really quit?")
+End Function
+
+Local window:TMWindow=New TMWindow.Create("Test",100,100,640,400)
+window.OnCloseEvent.Add(OnClose)
+MWidgetMainLoop(window)
+</pre>
+<p>
+When using the function callback method of capturing events, the parameters to the function are the same as the overridable method with the addition
+of the managed widget which is passed in as the first argument.
+</p>
EndRem
Module noddybox.mwidget
@@ -26,6 +45,252 @@ Import brl.maxgui
Import brl.linkedlist
Import brl.event
Import brl.timer
+Import brl.map
+Import brl.filesystem
+
+Type TMWEventListBase Abstract
+ Field list:TList
+ Method New()
+ list=CreateList()
+ End Method
+End Type
+
+Type TMWFuncVoid
+ Field func(w:TMWidget)
+ Function Create:TMWFuncVoid(func(w:TMWidget))
+ Local o:TMWFuncVoid=New TMWFuncVoid
+ o.func=func
+ Return o
+ End Function
+End Type
+
+Type TMWFuncInt
+ Field func(w:TMWidget, a:Int)
+ Function Create:TMWFuncInt(func(w:TMWidget, a:Int))
+ Local o:TMWFuncInt=New TMWFuncInt
+ o.func=func
+ Return o
+ End Function
+End Type
+
+Type TMWFuncIntInt
+ Field func(w:TMWidget, a:Int, b:Int)
+ Function Create:TMWFuncIntInt(func(w:TMWidget, a:Int, b:Int))
+ Local o:TMWFuncIntInt=New TMWFuncIntInt
+ o.func=func
+ Return o
+ End Function
+End Type
+
+Type TMWFuncString
+ Field func(w:TMWidget, a:String)
+ Function Create:TMWFuncString(func(w:TMWidget, a:String))
+ Local o:TMWFuncString=New TMWFuncString
+ o.func=func
+ Return o
+ End Function
+End Type
+
+
+Type TMWFuncStringObject
+ Field func(w:TMWidget, a:String, b:Object)
+ Function Create:TMWFuncStringObject(func(w:TMWidget, a:String, b:Object))
+ Local o:TMWFuncStringObject=New TMWFuncStringObject
+ o.func=func
+ Return o
+ End Function
+End Type
+
+
+Rem
+bbdoc: Defines an event list for functions that take the parameters (w:TMWidget)
+EndRem
+Type TMWEventListVoid Extends TMWEventListBase Final
+ Rem
+ bbdoc: Adds a callback function.
+ EndRem
+ Method Add(func(w:TMWidget))
+ list.AddLast(TMWFuncVoid.Create(func))
+ End Method
+
+ Rem
+ bbdoc: Clears all callback functions.
+ EndRem
+ Method Clear()
+ list.Clear()
+ End Method
+
+ Rem
+ bbdoc: Removes a callback function.
+ EndRem
+ Method Remove(func(w:TMWidget))
+ For Local fp:TMWFuncVoid=EachIn list
+ If fp.func=func
+ list.Remove(fp)
+ Return
+ EndIf
+ Next
+ End Method
+
+ Method Fire(w:TMWidget)
+ For Local fp:TMWFuncVoid=EachIn list
+ fp.func(w)
+ Next
+ End Method
+End Type
+
+
+Rem
+bbdoc: Defines an event list for functions that take the parameters (w:TMWidget, a:Int)
+EndRem
+Type TMWEventListInt Extends TMWEventListBase Final
+ Rem
+ bbdoc: Adds a callback function.
+ EndRem
+ Method Add(func(w:TMWidget, a:Int))
+ list.AddLast(TMWFuncInt.Create(func))
+ End Method
+
+ Rem
+ bbdoc: Clears all callback functions.
+ EndRem
+ Method Clear()
+ list.Clear()
+ End Method
+
+ Rem
+ bbdoc: Removes a callback function.
+ EndRem
+ Method Remove(func(w:TMWidget, a:Int))
+ For Local fp:TMWFuncInt=EachIn list
+ If fp.func=func
+ list.Remove(fp)
+ Return
+ EndIf
+ Next
+ End Method
+
+ Method Fire(w:TMWidget, a:Int)
+ For Local fp:TMWFuncInt=EachIn list
+ fp.func(w,a)
+ Next
+ End Method
+End Type
+
+
+Rem
+bbdoc: Defines an event list for functions that take the parameters (w:TMWidget, a:String)
+EndRem
+Type TMWEventListString Extends TMWEventListBase Final
+ Rem
+ bbdoc: Adds a callback function.
+ EndRem
+ Method Add(func(w:TMWidget, a:String))
+ list.AddLast(TMWFuncString.Create(func))
+ End Method
+
+ Rem
+ bbdoc: Clears all callback functions.
+ EndRem
+ Method Clear()
+ list.Clear()
+ End Method
+
+ Rem
+ bbdoc: Removes a callback function.
+ EndRem
+ Method Remove(func(w:TMWidget, a:String))
+ For Local fp:TMWFuncString=EachIn list
+ If fp.func=func
+ list.Remove(fp)
+ Return
+ EndIf
+ Next
+ End Method
+
+ Method Fire(w:TMWidget, a:String)
+ For Local fp:TMWFuncString=EachIn list
+ fp.func(w,a)
+ Next
+ End Method
+End Type
+
+
+Rem
+bbdoc: Defines an event list for functions that take the parameters (w:TMWidget, a:Int, b:Int)
+EndRem
+Type TMWEventListIntInt Extends TMWEventListBase Final
+ Rem
+ bbdoc: Adds a callback function.
+ EndRem
+ Method Add(func(w:TMWidget, a:Int, b:Int))
+ list.AddLast(TMWFuncIntInt.Create(func))
+ End Method
+
+ Rem
+ bbdoc: Clears all callback functions.
+ EndRem
+ Method Clear()
+ list.Clear()
+ End Method
+
+ Rem
+ bbdoc: Removes a callback function.
+ EndRem
+ Method Remove(func(w:TMWidget, a:Int, b:Int))
+ For Local fp:TMWFuncIntInt=EachIn list
+ If fp.func=func
+ list.Remove(fp)
+ Return
+ EndIf
+ Next
+ End Method
+
+ Method Fire(w:TMWidget, a:Int, b:Int)
+ For Local fp:TMWFuncIntInt=EachIn list
+ fp.func(w,a,b)
+ Next
+ End Method
+End Type
+
+
+Rem
+bbdoc: Defines an event list for functions that take the parameters (w:TMWidget, a:String, b:Object)
+EndRem
+Type TMWEventListStringObject Extends TMWEventListBase Final
+ Rem
+ bbdoc: Adds a callback function.
+ EndRem
+ Method Add(func(w:TMWidget, a:String, b:Object))
+ list.AddLast(TMWFuncStringObject.Create(func))
+ End Method
+
+ Rem
+ bbdoc: Clears all callback functions.
+ EndRem
+ Method Clear()
+ list.Clear()
+ End Method
+
+ Rem
+ bbdoc: Removes a callback function.
+ EndRem
+ Method Remove(func(w:TMWidget, a:String, b:Object))
+ For Local fp:TMWFuncStringObject=EachIn list
+ If fp.func=func
+ list.Remove(fp)
+ Return
+ EndIf
+ Next
+ End Method
+
+ Method Fire(w:TMWidget, a:String, b:Object)
+ For Local fp:TMWFuncStringObject=EachIn list
+ fp.func(w,a,b)
+ Next
+ End Method
+End Type
+
Rem
bbdoc: Defines a base managed widget type.
@@ -62,11 +327,14 @@ Type TMWidget Abstract
Method Handle(e:TEvent)
Select e.id
Case EVENT_MOUSEENTER
- OnMouseEnter(e)
+ OnMouseEnter()
+ OnMouseEnterEvent.Fire(Self)
Case EVENT_MOUSELEAVE
- OnMouseEnter(e)
+ OnMouseLeave()
+ OnMouseLeaveEvent.Fire(Self)
Case EVENT_TIMERTICK
OnTimer()
+ OnTimerEvent.Fire(Self)
End Select
End Method
@@ -260,32 +528,57 @@ Type TMWidget Abstract
End Method
Rem
+ bbdoc: Called when the widget's timer fires.
+ EndRem
+ Field OnTimerEvent:TMWEventListVoid
+
+ Rem
bbdoc: Called when the widget is managed.
EndRem
Method OnManage()
End Method
Rem
+ bbdoc: Called when the widget is managed.
+ EndRem
+ Field OnManageEvent:TMWEventListVoid
+
+ Rem
bbdoc: Called when the widget is unmanaged.
EndRem
Method OnUnmanage()
End Method
Rem
+ bbdoc: Called when the widget is unmanaged.
+ EndRem
+ Field OnUnmanageEvent:TMWEventListVoid
+
+ Rem
bbdoc: Called when the mouse enters.
EndRem
- Method OnMouseEnter(e:TEvent)
+ Method OnMouseEnter()
End Method
Rem
+ bbdoc: Called when the mouse enters.
+ EndRem
+ Field OnMouseEnterEvent:TMWEventListVoid
+
+ Rem
bbdoc: Called when the mouse leaves.
EndRem
- Method OnMouseLeave(e:TEvent)
+ Method OnMouseLeave()
End Method
Rem
+ bbdoc: Called when the mouse leaves.
+ EndRem
+ Field OnMouseLeaveEvent:TMWEventListVoid
+
+ Rem
bbdoc: Fires an event at this managed widget.
- about: The arguments are the same as @CreateEvent(), but not source is passed in.
+ about: The arguments are the same as @CreateEvent(), but no source is passed in.
EndRem
Method Emit(id:Int, data:Int=0, mods:Int=0, x:Int=0, y:Int=0,extra:Object=Null)
EmitEvent(CreateEvent(id,gadget,data,mods,x,y,extra))
@@ -301,6 +594,12 @@ Type TMWidget Abstract
self.gadget=gadget
self.parent=parent
+ OnTimerEvent=New TMWEventListVoid
+ OnManageEvent=New TMWEventListVoid
+ OnUnmanageEvent=New TMWEventListVoid
+ OnMouseEnterEvent=New TMWEventListVoid
+ OnMouseLeaveEvent=New TMWEventListVoid
+
If self.parent
self.parent.children.AddLast(Self)
EndIf
@@ -335,6 +634,10 @@ Type TMWindow Extends TMWidget
Method Create:TMWindow(name:String, x:Int,y:Int, w:Int, h:Int, group:TMWidget=Null, flags:Int=15)
closed=False
+ OnMoveEvent=New TMWEventListIntInt
+ OnResizeEvent=New TMWEventListIntInt
+ OnCloseEvent=New TMWEventListVoid
+
Local g:TGadget
If group
@@ -422,32 +725,55 @@ Type TMWindow Extends TMWidget
Rem
bbdoc: Called when the window is moved.
+ about:@x and @y are the new position.
EndRem
- Method OnMove(e:TEvent)
+ Method OnMove(x:Int, y:Int)
End Method
Rem
+ bbdoc: Called when the window is moved.
+ EndRem
+ Field OnMoveEvent:TMWEventListIntInt
+
+ Rem
bbdoc: Called when the window is resized.
+ about:@width and @height are the new size.
EndRem
- Method OnResize(e:TEvent)
+ Method OnResize(width:Int, height:Int)
End Method
Rem
+ bbdoc: Called when the window is resized.
+ EndRem
+ Field OnResizeEvent:TMWEventListIntInt
+
+ Rem
bbdoc: Called when the window's close gadget is pressed.
+ about: This default implementation sets @closed to TRUE and hide the window if no events are defined in @OnCloseEvent.
EndRem
- Method OnClose(e:TEvent)
- closed=True
- Hidden(True)
+ Method OnClose()
+ If Not OnCloseEvent.list.Count()
+ closed=True
+ Hidden(True)
+ EndIf
End Method
+ Rem
+ bbdoc: Called when the window's close gadget is pressed.
+ EndRem
+ Field OnCloseEvent:TMWEventListVoid
+
Method Handle(e:TEvent)
Select e.id
Case EVENT_WINDOWMOVE
- OnMove(e)
+ OnMove(e.x,e.y)
+ OnMoveEvent.Fire(Self,e.x,e.y)
Case EVENT_WINDOWSIZE
- OnResize(e)
+ OnResize(e.x,e.y)
+ OnResizeEvent.Fire(Self,e.x,e.y)
Case EVENT_WINDOWCLOSE
- OnClose(e)
+ OnClose()
+ OnCloseEvent.Fire(Self)
Default
super.Handle(e)
End Select
@@ -475,16 +801,8 @@ Type TMMenu Extends TMWidget
FreeMenu(gadget)
End Method
- Rem
- bbdoc: Called when the button is pressed.
- EndRem
- Method OnPress(e:TEvent)
- End Method
-
Method Handle(e:TEvent)
Select e.id
- Case EVENT_GADGETACTION
- OnPress(e)
Default
super.Handle(e)
End Select
@@ -503,6 +821,7 @@ Type TMButton Extends TMWidget
about: @label, @x, @y, @w, @h, and @group act the same as the MaxGUI arguments to @CreateButton(), except that @group is a TMWidget.
EndRem
Method Create:TMButton(label:String, x:Int,y:Int, w:Int, h:Int, group:TMWidget)
+ OnPressEvent=New TMWEventListVoid
BaseInitialise(CreateButton(label,x,y,w,h,group.gadget,BUTTON_PUSH),group)
typename="TMButton"
Return Self
@@ -514,6 +833,7 @@ Type TMButton Extends TMWidget
about: @label, @x, @y, @w, @h, and @group act the same as the MaxGUI arguments to @CreateButton(), except that @group is a TMWidget.
EndRem
Method CreateOK:TMButton(label:String, x:Int,y:Int, w:Int, h:Int, group:TMWidget)
+ OnPressEvent=New TMWEventListVoid
BaseInitialise(CreateButton(label,x,y,w,h,group.gadget,BUTTON_OK),group)
typename="TMButton"
Return Self
@@ -524,7 +844,8 @@ Type TMButton Extends TMWidget
returns: The created button.
about: @label, @x, @y, @w, @h, and @group act the same as the MaxGUI arguments to @CreateButton(), except that @group is a TMWidget.
EndRem
- Method CreateCancel:TMButton(label:String, x:Int,y:Int, w:Int, h:Int, group:TMWidget)
+ Method CreateCancel:TMButton(label:String, x:Int,y:Int, w:Int, h:Int, group:TMWidget)
+ OnPressEvent=New TMWEventListVoid
BaseInitialise(CreateButton(label,x,y,w,h,group.gadget,BUTTON_OK),group)
typename="TMButton"
Return Self
@@ -533,13 +854,19 @@ Type TMButton Extends TMWidget
Rem
bbdoc: Called when the button is pressed.
EndRem
- Method OnPress(e:TEvent)
+ Method OnPress()
End Method
+ Rem
+ bbdoc: Called when the button is pressed.
+ EndRem
+ Field OnPressEvent:TMWEventListVoid
+
Method Handle(e:TEvent)
Select e.id
Case EVENT_GADGETACTION
- OnPress(e)
+ OnPress()
+ OnPressEvent.Fire(Self)
Default
super.Handle(e)
End Select
@@ -557,6 +884,7 @@ Type TMCheckbox Extends TMWidget
about: @label, @x, @y, @w, @h, and @group act the same as the MaxGUI arguments to @CreateButton(), except that @group is a TMWidget.
EndRem
Method Create:TMCheckbox(label:String, x:Int,y:Int, w:Int, h:Int, group:TMWidget)
+ OnPressEvent=New TMWEventListInt
BaseInitialise(CreateButton(label,x,y,w,h,group.gadget,BUTTON_CHECKBOX),group)
typename="TMCheckbox"
Return Self
@@ -579,14 +907,21 @@ Type TMCheckbox Extends TMWidget
Rem
bbdoc: Called when the checkbox is pressed.
+ about: @checked is the current state.
EndRem
- Method OnPress(e:TEvent)
+ Method OnPress(checked:Int)
End Method
+ Rem
+ bbdoc: Called when the checkbox is pressed.
+ EndRem
+ Field OnPressEvent:TMWEventListInt
+
Method Handle(e:TEvent)
Select e.id
Case EVENT_GADGETACTION
- OnPress(e)
+ OnPress(e.data)
+ OnPressEvent.Fire(Self,e.data)
Default
super.Handle(e)
End Select
@@ -598,16 +933,30 @@ Rem
bbdoc: Defines a managed radio button.
EndRem
Type TMRadioButton Extends TMCheckbox
+ Field set:TMRadioButtonSet
+
Rem
bbdoc: Creates a managed radio button.
returns: The created radio button.
about: @label, @x, @y, @w, @h, and @group act the same as the MaxGUI arguments to @CreateButton(), except that @group is a TMWidget.
EndRem
Method Create:TMRadioButton(label:String, x:Int,y:Int, w:Int, h:Int, group:TMWidget)
+ OnPressEvent=New TMWEventListInt
BaseInitialise(CreateButton(label,x,y,w,h,group.gadget,BUTTON_RADIO),group)
typename="TMRadioButton"
Return Self
End Method
+
+ Rem
+ bbdoc: Called when the checkbox is pressed.
+ about: @checked is the current state. In this default implementation the @TMRadioButtonSet which this button belongs too will fire
+ its @OnSelected() member.
+ EndRem
+ Method OnPress(checked:Int)
+ If set
+ set.ButtonFired(Self)
+ EndIf
+ End Method
End Type
@@ -623,7 +972,11 @@ Type TMRadioButtonSet
about: The radio buttons must have been created prior to calling this.
EndRem
Method Create:TMRadioButtonSet(buttons:TMRadioButton[])
+ OnSelectedEvent=New TMWEventListInt
but=buttons
+ For Local b:TMRadioButton=EachIn but
+ b.set=Self
+ Next
Return Self
End Method
@@ -634,6 +987,19 @@ Type TMRadioButtonSet
Method Set(index:Int)
but[index].Checked(True)
End Method
+
+ Rem
+ bbdoc: If using the base TMRadioButton implmentation this will be called when the buttons change.
+ about: @index is the selected button.
+ EndRem
+ Method OnSelected(index:Int)
+ End Method
+
+ Rem
+ bbdoc: If using the base TMRadioButton implmentation this will be called when the buttons change.
+ about: The radio button that fired will be passed into the event.
+ EndRem
+ Field OnSelectedEvent:TMWEventListInt
Rem
bbdoc: Get the active radio button.
@@ -647,6 +1013,16 @@ Type TMRadioButtonSet
Next
Return -1
End Method
+
+ Method ButtonFired(b:TMRadioButton)
+ For Local f:Int=0 Until but.length
+ If but[f]=b
+ OnSelected(f)
+ OnSelectedEvent.Fire(b,f)
+ Return
+ EndIf
+ Next
+ End Method
End Type
@@ -678,6 +1054,7 @@ Type TMTextField Extends TMWidget
about: @x, @y, @w, @h, and @group act the same as the MaxGUI arguments to @CreateTextField(), except that @group is a TMWidget.
EndRem
Method Create:TMTextField(x:Int,y:Int, w:Int, h:Int, group:TMWidget)
+ OnTextChangedEvent=New TMWEventListString
BaseInitialise(CreateTextField(x,y,w,h,group.gadget),group)
typename="TMTextField"
Return Self
@@ -703,15 +1080,23 @@ Type TMTextField Extends TMWidget
End Method
Rem
- bbdoc: Called when a character is entered into the field.
+ bbdoc: Called when the text changes.
+ about: @txt is the content of the field
EndRem
- Method OnKey(e:TEvent)
+ Method OnTextChanged(txt:String)
End Method
+ Rem
+ bbdoc: Called when the text changes.
+ EndRem
+ Field OnTextChangedEvent:TMWEventListString
+
Method Handle(e:TEvent)
Select e.id
Case EVENT_GADGETACTION
- OnKey(e)
+ Local s:String=TextFieldText(gadget)
+ OnTextChanged(s)
+ OnTextChangedEvent.Fire(Self,s)
Default
super.Handle(e)
End Select
@@ -729,6 +1114,9 @@ Type TMTextArea Extends TMWidget
about: @x, @y, @w, @h,, @group and @style act the same as the MaxGUI arguments to @CreateTextArea(), except that @group is a TMWidget.
EndRem
Method Create:TMTextArea(x:Int, y:Int, w:Int, h:Int, group:TMWidget, style:Int=0)
+ OnTextChangedEvent=New TMWEventListVoid
+ OnSelectionEvent=New TMWEventListVoid
+ OnMenuEvent=New TMWEventListVoid
BaseInitialise(CreateTextArea(x,y,w,h,group.gadget,style),group)
typename="TMTextArea"
Return Self
@@ -848,31 +1236,49 @@ Type TMTextArea Extends TMWidget
End Method
Rem
- bbdoc: Called when a character is entered into the text.
+ bbdoc: Called when the text changes.
EndRem
- Method OnKey(e:TEvent)
+ Method OnTextChanged()
End Method
Rem
+ bbdoc: Called when the text changes.
+ EndRem
+ Field OnTextChangedEvent:TMWEventListVoid
+
+ Rem
bbdoc: Called when the selection or cursor changes.
EndRem
- Method OnSelection(e:TEvent)
+ Method OnSelection()
End Method
Rem
+ bbdoc: Called when the selection or cursor changes.
+ EndRem
+ Field OnSelectionEvent:TMWEventListVoid
+
+ Rem
bbdoc: Called when the context menu is requested.
EndRem
- Method OnMenu(e:TEvent)
+ Method OnMenu()
End Method
+ Rem
+ bbdoc: Called when the context menu is requested.
+ EndRem
+ Field OnMenuEvent:TMWEventListVoid
+
Method Handle(e:TEvent)
Select e.id
Case EVENT_GADGETACTION
- OnKey(e)
+ OnTextChanged()
+ OnTextChangedEvent.Fire(Self)
Case EVENT_GADGETSELECT
- OnSelection(e)
+ OnSelection()
+ OnSelectionEvent.Fire(Self)
Case EVENT_GADGETMENU
- OnMenu(e)
+ OnMenu()
+ OnMenuEvent.Fire(Self)
Default
super.Handle(e)
End Select
@@ -890,6 +1296,7 @@ Type TMSlider Extends TMWidget
about: @x, @y, @w, @h, @group and @style act the same as the MaxGUI arguments to @CreateSlider(), except that @group is a TMWidget.
EndRem
Method Create:TMSlider(x:Int, y:Int, w:Int, h:Int, group:TMWidget, style:Int=0)
+ OnValueChangedEvent=New TMWEventListInt
BaseInitialise(CreateSlider(x,y,w,h,group.gadget,style),group)
typename="TMSlider"
Return Self
@@ -920,14 +1327,21 @@ Type TMSlider Extends TMWidget
Rem
bbdoc: Called when the slider moves.
+ about: @val is the new slider value.
EndRem
- Method OnValueChanged(e:TEvent)
+ Method OnValueChanged(val:Int)
End Method
+ Rem
+ bbdoc: Called when the slider moves.
+ EndRem
+ Field OnValueChangedEvent:TMWEventListInt
+
Method Handle(e:TEvent)
Select e.id
Case EVENT_GADGETACTION
- OnValueChanged(e)
+ OnValueChanged(e.data)
+ OnValueChangedEvent.Fire(Self,e.data)
Default
super.Handle(e)
End Select
@@ -1098,14 +1512,21 @@ Type TMListWidget Extends TMWidget Abstract
Rem
bbdoc: Called when the selection changes.
+ about: @index is the selected index. This can be -1 for no selection.
EndRem
- Method OnIndexChanged(e:TEvent)
+ Method OnIndexChanged(index:Int)
End Method
+ Rem
+ bbdoc: Called when the selection changes.
+ EndRem
+ Field OnIndexChangedEvent:TMWEventListInt
+
Method Handle(e:TEvent)
Select e.id
Case EVENT_GADGETACTION
- OnIndexChanged(e)
+ OnIndexChanged(e.data)
+ OnIndexChangedEvent.Fire(Self,e.data)
Default
super.Handle(e)
End Select
@@ -1126,6 +1547,7 @@ Type TMComboBox Extends TMListWidget
There seems to be no easy way to remedy this.
EndRem
Method Create:TMComboBox(x:Int,y:Int, w:Int, h:Int, group:TMWidget, style:Int=0, values:TMListEntry[]=Null)
+ OnIndexChangedEvent=New TMWEventListInt
BaseInitialise(CreateComboBox(x,y,w,h,group.gadget,style),group)
typename="TMComboBox"
If values
@@ -1147,6 +1569,7 @@ Type TMListBox Extends TMListWidget
If @values is not NULL it is used to load up the initial options.
EndRem
Method Create:TMListBox(x:Int,y:Int, w:Int, h:Int, group:TMWidget, values:TMListEntry[]=Null)
+ OnIndexChangedEvent=New TMWEventListInt
BaseInitialise(CreateListBox(x,y,w,h,group.gadget),group)
typename="TMListBox"
If values
@@ -1170,6 +1593,7 @@ Type TMTabber Extends TMListWidget
If @values is not NULL it is used to load up the initial options.
EndRem
Method Create:TMTabber(x:Int,y:Int, w:Int, h:Int, group:TMWidget, values:TMListEntry[]=Null)
+ OnIndexChangedEvent=New TMWEventListInt
BaseInitialise(CreateTabber(x,y,w,h,group.gadget),group)
typename="TMTabber"
If values
@@ -1203,15 +1627,13 @@ Type TMTabber Extends TMListWidget
End Method
Rem
- bbdoc: This default information will switch the widgets as defined by @DefinePages()
+ bbdoc: This default implementation will switch the widgets as defined by @DefinePages()
EndRem
- Method OnIndexChanged(e:TEvent)
- Local sel:Int=SelectedIndex()
-
- If sel>-1 And pages
+ Method OnIndexChanged(index:Int)
+ If index>-1 And pages
For Local f:Int=0 Until pages.length
For Local w:TMWidget=EachIn pages[f]
- w.Hidden(f<>sel)
+ w.Hidden(f<>index)
Next
Next
EndIf
@@ -1230,6 +1652,8 @@ Type TMHTMLView Extends TMWidget
about: @x, @y, @w, @h, @group and @style act the same as the MaxGUI arguments to @CreateHMTLView(), except that @group is a TMWidget.
EndRem
Method Create:TMHTMLView(x:Int, y:Int, w:Int, h:Int, group:TMWidget, style:Int=0)
+ OnPageLoadedEvent=New TMWEventListString
+ OnSelectURLEvent=New TMWEventListString
BaseInitialise(CreateHTMLView(x,y,w,h,group.gadget,style),group)
typename="TMHTMLView"
Return Self
@@ -1238,7 +1662,7 @@ Type TMHTMLView Extends TMWidget
Rem
bbdoc: The current URL.
EndRem
- Method URL:String()
+ Method CurrentURL:String()
Return HtmlViewCurrentURL(gadget)
End Method
@@ -1272,22 +1696,336 @@ Type TMHTMLView Extends TMWidget
Rem
bbdoc: If HTMLVIEW_NONAVIGATE is set in the styles, then this is called when a link is clicked.
+ about: @url is the selected URL.
EndRem
- Method OnSelectURL(e:TEvent)
+ Method OnSelectURL(url:String)
End Method
Rem
- bbdoc: Called when the page finishes loading moves.
+ bbdoc: If HTMLVIEW_NONAVIGATE is set in the styles, then this is called when a link is clicked.
+ EndRem
+ Field OnSelectURLEvent:TMWEventListString
+
+ Rem
+ bbdoc: Called when the page finishes loading.
+ about: @url is the loaded URL.
EndRem
- Method OnPageLoaded(e:TEvent)
+ Method OnPageLoaded(url:String)
End Method
+ Rem
+ bbdoc: Called when the page finishes loading.
+ EndRem
+ Field OnPageLoadedEvent:TMWEventListString
+
Method Handle(e:TEvent)
Select e.id
Case EVENT_GADGETACTION
- OnSelectURL(e)
+ OnSelectURL(e.extra.ToString())
+ OnSelectURLEvent.Fire(Self,e.extra.ToString())
Case EVENT_GADGETDONE
- OnPageLoaded(e)
+ OnPageLoaded(CurrentURL())
+ OnPageLoadedEvent.Fire(Self,CurrentURL())
+ Default
+ super.Handle(e)
+ End Select
+ End Method
+End Type
+
+
+Type TMTreeNode
+ Field path:String
+ Field node:TGadget
+ Field tag:Object
+ Field icon:Int
+ Function Create:TMTreeNode(path:String, node:TGadget, tag:Object, icon:Int)
+ Local o:TMTreeNode=New TMTreeNode
+ o.path=path
+ o.node=node
+ o.tag=tag
+ o.icon=icon
+ Return o
+ End Function
+End Type
+
+Rem
+bbdoc: Defines a managed tree view.
+about: The tree view works by treating its entries as if in a simple file system.
+EndRem
+Type TMTreeView Extends TMWidget
+ Field map:TMap
+ Field gmap:TMap
+ Field update:Int
+
+ Rem
+ bbdoc: Creates a managed tree view.
+ returns: The created tree view.
+ about: @x, @y, @w, @h, @group and @style act the same as the MaxGUI arguments to @CreateTreeView(), except that @group is a TMWidget.
+ EndRem
+ Method Create:TMTreeView(x:Int, y:Int, w:Int, h:Int, group:TMWidget, style:Int=0)
+ update=False
+ map=New TMap
+ gmap=New TMap
+ OnSelectedEvent=New TMWEventListStringObject
+ OnClickedEvent=New TMWEventListStringObject
+ OnMenuEvent=New TMWEventListStringObject
+ OnExpandedEvent=New TMWEventListStringObject
+ OnCollapsedEvent=New TMWEventListStringObject
+ BaseInitialise(CreateTreeView(x,y,w,h,group.gadget,style),group)
+ typename="TMNodeView"
+ map.Insert("/",TMTreeNode.Create("/",TreeViewRoot(gadget),"/",-1))
+ Return Self
+ End Method
+
+ Method ResolvePath:TMTreeNode(path:String)
+ Return TMTreeNode(map.ValueForKey(path))
+ End Method
+
+ Method ResolveGadget:TMTreeNode(g:TGadget)
+ Return ResolvePath(gmap.ValueForKey(g).ToString())
+ End Method
+
+ Method Prune(path:String)
+ Local l:TList=CreateList()
+
+ ' Not sure if this is overly ineffecient -- just being safe as in most languages deleting whilst iterating
+ ' is not recommended...
+ '
+ For Local k:String=EachIn map.Keys()
+ If k=path Or k.Find(path+"/")=0
+ l.AddLast(k)
+ EndIf
+ Next
+
+ For Local k:String=EachIn l
+ Local n:TMTreeNode=ResolvePath(k)
+ map.Remove(k)
+ gmap.Remove(n.node)
+ Next
+ End Method
+
+ Rem
+ bbdoc: Set an icon strip.
+ EndRem
+ Method SetIconStrip(icons:TIconStrip)
+ SetGadgetIconStrip(gadget,icons)
+ End Method
+
+ Rem
+ bbdoc: The number of nodes in the view.
+ returns: The number of nodes.
+ about: @path is the path to count from. / is the root node.
+ EndRem
+ Method CountChildren:Int(path:String)
+ Local node:TMTreeNode=ResolvePath(path)
+
+ If node
+ Return CountTreeViewNodes(node.node)
+ Else
+ Return 0
+ EndIf
+ End Method
+
+ Rem
+ bbdoc: Remove nodes from the tree.
+ about: Attempting to remove the root node (/) will fail.
+ EndRem
+ Method Remove(path:String)
+ If path<>"/"
+ Local node:TMTreeNode=ResolvePath(path)
+
+ If node
+ FreeTreeViewNode(node.node)
+ Prune(path)
+ EndIf
+ EndIf
+ End Method
+
+ Rem
+ bbdoc: Don't redraw gadget when adding nodes.
+ EndRem
+ Method BeginUpdate()
+ update=True
+ End Method
+
+
+ Rem
+ bbdoc: Allow redraw of gadget when adding nodes.
+ EndRem
+ Method EndUpdate()
+ update=False
+ End Method
+
+
+ Rem
+ bbdoc: Add/modify nodes in the tree.
+ about: @path is the path to the node. This silently fails if the parent nodes don't exist. @tag is an Object that the entry is tagged with.
+ ToString() is called on this to create the text for the entry (so passing a String works fine).
+ @icon is the icon to use.
+ EndRem
+ Method Set(path:String, tag:Object, icon:Int=-1)
+ Local parent:TMTreeNode=ResolvePath(FixedExtractDir(path))
+
+ If parent
+ Local node:TMTreeNode=ResolvePath(path)
+
+ If node
+ ModifyTreeViewNode(node.node,tag.ToString(),icon)
+ Else
+ node=TMTreeNode.Create(path,AddTreeViewNode(tag.ToString(),parent.node,icon),tag,icon)
+ map.Insert(path,node)
+ gmap.Insert(node.node,path)
+ EndIf
+
+ node.tag=tag
+ node.icon=icon
+
+ If Not update
+ RedrawGadget(gadget)
+ EndIf
+ EndIf
+ End Method
+
+ Rem
+ bbdoc: Get the tag at a node.
+ returns: The tag, or NULL for unknown node.
+ EndRem
+ Method GetNodeTag:Object(path:String)
+ Local node:TMTreeNode=ResolvePath(path)
+ If node
+ Return node.tag
+ Else
+ Return Null
+ EndIf
+ End Method
+
+ Rem
+ bbdoc: Get the icon at a node.
+ returns: The icon, or -1 for none or unknown node.
+ EndRem
+ Method GetNodeIcon:Int(path:String)
+ Local node:TMTreeNode=ResolvePath(path)
+ If node
+ Return node.icon
+ Else
+ Return -1
+ EndIf
+ End Method
+
+ Rem
+ bbdoc: Expand a node on the tree.
+ EndRem
+ Method ExpandNode(path:String)
+ Local node:TMTreeNode=ResolvePath(path)
+
+ If node
+ ExpandTreeViewNode(node.node)
+ EndIf
+ End Method
+
+ Rem
+ bbdoc: Collapse a node on the tree.
+ EndRem
+ Method CollapseNode(path:String)
+ Local node:TMTreeNode=ResolvePath(path)
+
+ If node
+ CollapseTreeViewNode(node.node)
+ EndIf
+ End Method
+
+ Rem
+ bbdoc: Called when the an item is selected.
+ about: @path is the path to the selected item, @tag is the tag for that item.
+ EndRem
+ Method OnSelected(path:String, tag:Object)
+ End Method
+
+ Rem
+ bbdoc: Called when the an item is selected.
+ EndRem
+ Field OnSelectedEvent:TMWEventListStringObject
+
+ Rem
+ bbdoc: Called when the an item is double clicked.
+ about: @path is the path to the selected item, @tag is the tag for that item.
+ EndRem
+ Method OnClicked(path:String, tag:Object)
+ End Method
+
+ Rem
+ bbdoc: Called when the an item is double clicked.
+ EndRem
+ Field OnClickedEvent:TMWEventListStringObject
+
+ Rem
+ bbdoc: Called when the a context menu is requested.
+ about: @path is the path to the selected item, @tag is the tag for that item.
+ EndRem
+ Method OnMenu(path:String, tag:Object)
+ End Method
+
+ Rem
+ bbdoc: Called when the an item is selected.
+ EndRem
+ Field OnMenuEvent:TMWEventListStringObject
+
+ Rem
+ bbdoc: Called when a node is expanded.
+ about: @path is the path to the selected item, @tag is the tag for that item.
+ EndRem
+ Method OnExpanded(path:String, tag:Object)
+ End Method
+
+ Rem
+ bbdoc: Called when a node is expanded.
+ EndRem
+ Field OnExpandedEvent:TMWEventListStringObject
+
+ Rem
+ bbdoc: Called when a node is collapsed.
+ about: @path is the path to the selected item, @tag is the tag for that item.
+ EndRem
+ Method OnCollapsed(path:String, tag:Object)
+ End Method
+
+ Rem
+ bbdoc: Called when a node is collapsed.
+ EndRem
+ Field OnCollapsedEvent:TMWEventListStringObject
+
+ Method Handle(e:TEvent)
+ Select e.id
+ Case EVENT_GADGETSELECT
+ Local n:TMTreeNode=ResolveGadget(TGadget(e.extra))
+ If n
+ OnSelected(n.path,n.tag)
+ OnSelectedEvent.Fire(Self,n.path,n.tag)
+ EndIf
+ Case EVENT_GADGETACTION
+ Local n:TMTreeNode=ResolveGadget(TGadget(e.extra))
+ If n
+ OnClicked(n.path,n.tag)
+ OnClickedEvent.Fire(Self,n.path,n.tag)
+ EndIf
+ Case EVENT_GADGETOPEN
+ Local n:TMTreeNode=ResolveGadget(TGadget(e.extra))
+ If n
+ OnExpanded(n.path,n.tag)
+ OnExpandedEvent.Fire(Self,n.path,n.tag)
+ EndIf
+ Case EVENT_GADGETCLOSE
+ Local n:TMTreeNode=ResolveGadget(TGadget(e.extra))
+ If n
+ OnCollapsed(n.path,n.tag)
+ OnCollapsedEvent.Fire(Self,n.path,n.tag)
+ EndIf
+ Case EVENT_GADGETMENU
+ Local n:TMTreeNode=ResolveGadget(TGadget(e.extra))
+ If n
+ OnMenu(n.path,n.tag)
+ OnMenuEvent.Fire(Self,n.path,n.tag)
+ EndIf
Default
super.Handle(e)
End Select
@@ -1310,6 +2048,14 @@ End Function
Private
+Function FixedExtractDir:String(p:String)
+ p=ExtractDir(p)
+ If p.length=0
+ p="/"
+ EndIf
+ Return p
+End Function
+
Type Static
Global list:TList
@@ -1338,6 +2084,7 @@ Type Static
Function Register(w:TMWidget)
list.AddLast(w)
w.OnManage()
+ w.OnManageEvent.Fire(w)
End Function
Function Deregister(w:TMWidget)
@@ -1350,6 +2097,7 @@ Type Static
EndIf
w.OnUnmanage()
+ w.OnUnmanageEvent.Fire(w)
list.Remove(w)
End Function
End Type