diff --git a/action.go b/action.go index 57449571..ed643c92 100644 --- a/action.go +++ b/action.go @@ -5,7 +5,8 @@ package walk type actionChangedHandler interface { - onActionChanged(action *Action) (err error) + onActionChanged(action *Action) error + onActionVisibleChanged(action *Action) error } var ( @@ -17,18 +18,22 @@ var ( ) type Action struct { - menu *Menu - triggeredPublisher EventPublisher - changedHandlers []actionChangedHandler - text string - toolTip string - image *Bitmap - enabled bool - visible bool - checkable bool - checked bool - exclusive bool - id uint16 + menu *Menu + triggeredPublisher EventPublisher + changedHandlers []actionChangedHandler + text string + toolTip string + image *Bitmap + enabledCondition Condition + enabledConditionChangedHandle int + visibleCondition Condition + visibleConditionChangedHandle int + enabled bool + visible bool + checkable bool + checked bool + exclusive bool + id uint16 } func NewAction() *Action { @@ -84,10 +89,18 @@ func (a *Action) SetChecked(value bool) (err error) { } func (a *Action) Enabled() bool { + if a.enabledCondition != nil { + return a.enabledCondition.Satisfied() + } + return a.enabled } func (a *Action) SetEnabled(value bool) (err error) { + if a.enabledCondition != nil { + return newError("EnabledCondition != nil") + } + if value != a.enabled { old := a.enabled @@ -102,6 +115,24 @@ func (a *Action) SetEnabled(value bool) (err error) { return } +func (a *Action) EnabledCondition() Condition { + return a.enabledCondition +} + +func (a *Action) SetEnabledCondition(c Condition) { + if a.enabledCondition != nil { + a.enabledCondition.Changed().Detach(a.enabledConditionChangedHandle) + } + + a.enabledCondition = c + + if c != nil { + a.enabledConditionChangedHandle = c.Changed().Attach(func() { + a.raiseChanged() + }) + } +} + func (a *Action) Exclusive() bool { return a.exclusive } @@ -179,24 +210,50 @@ func (a *Action) SetToolTip(value string) (err error) { } func (a *Action) Visible() bool { + if a.visibleCondition != nil { + return a.visibleCondition.Satisfied() + } + return a.visible } func (a *Action) SetVisible(value bool) (err error) { + if a.visibleCondition != nil { + return newError("VisibleCondition != nil") + } + if value != a.visible { old := a.visible a.visible = value - if err = a.raiseChanged(); err != nil { + if err = a.raiseVisibleChanged(); err != nil { a.visible = old - a.raiseChanged() + a.raiseVisibleChanged() } } return } +func (a *Action) VisibleCondition() Condition { + return a.visibleCondition +} + +func (a *Action) SetVisibleCondition(c Condition) { + if a.visibleCondition != nil { + a.visibleCondition.Changed().Detach(a.visibleConditionChangedHandle) + } + + a.visibleCondition = c + + if c != nil { + a.visibleConditionChangedHandle = c.Changed().Attach(func() { + a.raiseVisibleChanged() + }) + } +} + func (a *Action) Triggered() *Event { return a.triggeredPublisher.Event() } @@ -218,12 +275,22 @@ func (a *Action) removeChangedHandler(handler actionChangedHandler) { } } -func (a *Action) raiseChanged() (err error) { +func (a *Action) raiseChanged() error { for _, handler := range a.changedHandlers { - if err = handler.onActionChanged(a); err != nil { - return + if err := handler.onActionChanged(a); err != nil { + return err } } - return + return nil +} + +func (a *Action) raiseVisibleChanged() error { + for _, handler := range a.changedHandlers { + if err := handler.onActionVisibleChanged(a); err != nil { + return err + } + } + + return nil } diff --git a/actionlist.go b/actionlist.go index 22b9f014..80efaa63 100644 --- a/actionlist.go +++ b/actionlist.go @@ -5,8 +5,8 @@ package walk type actionListObserver interface { - onInsertingAction(index int, action *Action) error - onRemovingAction(index int, action *Action) error + onInsertedAction(action *Action) error + onRemovingAction(action *Action) error onClearingActions() error } @@ -58,18 +58,35 @@ func (l *ActionList) Index(action *Action) int { return -1 } -func (l *ActionList) Insert(index int, action *Action) error { - observer := l.observer - if observer != nil { - if err := observer.onInsertingAction(index, action); err != nil { - return err +func (l *ActionList) indexInObserver(action *Action) int { + var idx int + + for _, a := range l.actions { + if a == action { + return idx + } + if a.Visible() { + idx++ } } + return -1 +} + +func (l *ActionList) Insert(index int, action *Action) error { l.actions = append(l.actions, nil) copy(l.actions[index+1:], l.actions[index:]) l.actions[index] = action + observer := l.observer + if observer != nil { + if err := observer.onInsertedAction(action); err != nil { + l.actions = append(l.actions[:index], l.actions[index+1:]...) + + return err + } + } + return nil } @@ -101,8 +118,10 @@ func (l *ActionList) RemoveAt(index int) error { observer := l.observer if observer != nil { action := l.actions[index] - if err := observer.onRemovingAction(index, action); err != nil { - return err + if action.Visible() { + if err := observer.onRemovingAction(action); err != nil { + return err + } } } diff --git a/declarative/action.go b/declarative/action.go index 6fc53e78..bdaf17b9 100644 --- a/declarative/action.go +++ b/declarative/action.go @@ -6,6 +6,7 @@ package declarative import ( "errors" + "fmt" ) import ( @@ -16,10 +17,12 @@ type Action struct { AssignTo **walk.Action Text string Image interface{} + Enabled Property + Visible Property OnTriggered walk.EventHandler } -func (a Action) createAction(menu *walk.Menu) (*walk.Action, error) { +func (a Action) createAction(builder *Builder, menu *walk.Menu) (*walk.Action, error) { action := walk.NewAction() if err := action.SetText(a.Text); err != nil { @@ -29,6 +32,33 @@ func (a Action) createAction(menu *walk.Menu) (*walk.Action, error) { return nil, err } + if a.Enabled != nil { + if b, ok := a.Enabled.(bool); ok { + if err := action.SetEnabled(b); err != nil { + return nil, err + } + } else if s := builder.conditionOrProperty(a.Enabled); s != nil { + if c, ok := s.(walk.Condition); ok { + action.SetEnabledCondition(c) + } else { + return nil, fmt.Errorf("value of invalid type bound to Action.Enabled: %T", s) + } + } + } + if a.Visible != nil { + if b, ok := a.Visible.(bool); ok { + if err := action.SetVisible(b); err != nil { + return nil, err + } + } else if s := builder.conditionOrProperty(a.Visible); s != nil { + if c, ok := s.(walk.Condition); ok { + action.SetVisibleCondition(c) + } else { + return nil, fmt.Errorf("value of invalid type bound to Action.Visible: %T", s) + } + } + } + if a.OnTriggered != nil { action.Triggered().Attach(a.OnTriggered) } @@ -47,17 +77,17 @@ func (a Action) createAction(menu *walk.Menu) (*walk.Action, error) { } type ActionRef struct { - Action *walk.Action + Action **walk.Action } -func (ar ActionRef) createAction(menu *walk.Menu) (*walk.Action, error) { +func (ar ActionRef) createAction(builder *Builder, menu *walk.Menu) (*walk.Action, error) { if menu != nil { - if err := menu.Actions().Add(ar.Action); err != nil { + if err := menu.Actions().Add(*ar.Action); err != nil { return nil, err } } - return ar.Action, nil + return *ar.Action, nil } type Menu struct { @@ -68,7 +98,7 @@ type Menu struct { Items []MenuItem } -func (m Menu) createAction(menu *walk.Menu) (*walk.Action, error) { +func (m Menu) createAction(builder *Builder, menu *walk.Menu) (*walk.Action, error) { if menu == nil { var err error if menu, err = walk.NewMenu(); err != nil { @@ -94,7 +124,7 @@ func (m Menu) createAction(menu *walk.Menu) (*walk.Action, error) { } for _, item := range m.Items { - if _, err := item.createAction(subMenu); err != nil { + if _, err := item.createAction(builder, subMenu); err != nil { return nil, err } } @@ -112,7 +142,7 @@ func (m Menu) createAction(menu *walk.Menu) (*walk.Action, error) { type Separator struct { } -func (s Separator) createAction(menu *walk.Menu) (*walk.Action, error) { +func (s Separator) createAction(builder *Builder, menu *walk.Menu) (*walk.Action, error) { action := walk.NewAction() if err := action.SetText("-"); err != nil { @@ -161,10 +191,14 @@ func setActionImage(action *walk.Action, image interface{}) (err error) { } func CreateActions(items ...MenuItem) ([]*walk.Action, error) { + return createActions(NewBuilder(nil), items...) +} + +func createActions(builder *Builder, items ...MenuItem) ([]*walk.Action, error) { var actions []*walk.Action for _, item := range items { - action, err := item.createAction(nil) + action, err := item.createAction(builder, nil) if err != nil { return nil, err } diff --git a/declarative/builder.go b/declarative/builder.go index ec7f5bdc..473dad71 100644 --- a/declarative/builder.go +++ b/declarative/builder.go @@ -60,6 +60,22 @@ func (b *Builder) Defer(f func() error) { b.deferredFuncs = append(b.deferredFuncs, f) } +func (b *Builder) deferBuildActions(actionList *walk.ActionList, items []MenuItem) { + if len(items) > 0 { + b.Defer(func() error { + actions, err := createActions(b, items...) + if err != nil { + return err + } + if err := addToActionList(actionList, actions); err != nil { + return err + } + + return nil + }) + } +} + func (b *Builder) InitWidget(d Widget, w walk.Widget, customInit func() error) error { b.level++ defer func() { @@ -76,7 +92,7 @@ func (b *Builder) InitWidget(d Widget, w walk.Widget, customInit func() error) e b.declWidgets = append(b.declWidgets, declWidget{d, w}) // Widget - name, _, _, font, toolTipText, minSize, maxSize, stretchFactor, row, rowSpan, column, columnSpan, contextMenuActions, onKeyDown, onMouseDown, onMouseMove, onMouseUp, onSizeChanged := d.WidgetInfo() + name, _, _, font, toolTipText, minSize, maxSize, stretchFactor, row, rowSpan, column, columnSpan, contextMenuItems, onKeyDown, onMouseDown, onMouseMove, onMouseUp, onSizeChanged := d.WidgetInfo() w.SetName(name) @@ -94,14 +110,13 @@ func (b *Builder) InitWidget(d Widget, w walk.Widget, customInit func() error) e return err } - if len(contextMenuActions) > 0 { + if len(contextMenuItems) > 0 { cm, err := walk.NewMenu() if err != nil { return err } - if err := addToActionList(cm.Actions(), contextMenuActions); err != nil { - return err - } + + b.deferBuildActions(cm.Actions(), contextMenuItems) w.SetContextMenu(cm) } diff --git a/declarative/checkbox.go b/declarative/checkbox.go index d1d9a861..731b0b13 100644 --- a/declarative/checkbox.go +++ b/declarative/checkbox.go @@ -9,28 +9,28 @@ import ( ) type CheckBox struct { - AssignTo **walk.CheckBox - Name string - Enabled Property - Visible Property - Font Font - ToolTipText Property - MinSize Size - MaxSize Size - StretchFactor int - Row int - RowSpan int - Column int - ColumnSpan int - ContextMenuActions []*walk.Action - OnKeyDown walk.KeyEventHandler - OnMouseDown walk.MouseEventHandler - OnMouseMove walk.MouseEventHandler - OnMouseUp walk.MouseEventHandler - OnSizeChanged walk.EventHandler - Text Property - Checked Property - OnClicked walk.EventHandler + AssignTo **walk.CheckBox + Name string + Enabled Property + Visible Property + Font Font + ToolTipText Property + MinSize Size + MaxSize Size + StretchFactor int + Row int + RowSpan int + Column int + ColumnSpan int + ContextMenuItems []MenuItem + OnKeyDown walk.KeyEventHandler + OnMouseDown walk.MouseEventHandler + OnMouseMove walk.MouseEventHandler + OnMouseUp walk.MouseEventHandler + OnSizeChanged walk.EventHandler + Text Property + Checked Property + OnClicked walk.EventHandler } func (cb CheckBox) Create(builder *Builder) error { @@ -52,6 +52,6 @@ func (cb CheckBox) Create(builder *Builder) error { }) } -func (w CheckBox) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w CheckBox) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } diff --git a/declarative/combobox.go b/declarative/combobox.go index 0f20f578..b3791ab3 100644 --- a/declarative/combobox.go +++ b/declarative/combobox.go @@ -22,7 +22,7 @@ type ComboBox struct { RowSpan int Column int ColumnSpan int - ContextMenuActions []*walk.Action + ContextMenuItems []MenuItem OnKeyDown walk.KeyEventHandler OnMouseDown walk.MouseEventHandler OnMouseMove walk.MouseEventHandler @@ -67,6 +67,6 @@ func (cb ComboBox) Create(builder *Builder) error { }) } -func (w ComboBox) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w ComboBox) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } diff --git a/declarative/composite.go b/declarative/composite.go index 5509f3cc..ddd78b65 100644 --- a/declarative/composite.go +++ b/declarative/composite.go @@ -9,28 +9,28 @@ import ( ) type Composite struct { - AssignTo **walk.Composite - Name string - Enabled Property - Visible Property - Font Font - ToolTipText Property - MinSize Size - MaxSize Size - StretchFactor int - Row int - RowSpan int - Column int - ColumnSpan int - ContextMenuActions []*walk.Action - OnKeyDown walk.KeyEventHandler - OnMouseDown walk.MouseEventHandler - OnMouseMove walk.MouseEventHandler - OnMouseUp walk.MouseEventHandler - OnSizeChanged walk.EventHandler - DataBinder DataBinder - Layout Layout - Children []Widget + AssignTo **walk.Composite + Name string + Enabled Property + Visible Property + Font Font + ToolTipText Property + MinSize Size + MaxSize Size + StretchFactor int + Row int + RowSpan int + Column int + ColumnSpan int + ContextMenuItems []MenuItem + OnKeyDown walk.KeyEventHandler + OnMouseDown walk.MouseEventHandler + OnMouseMove walk.MouseEventHandler + OnMouseUp walk.MouseEventHandler + OnSizeChanged walk.EventHandler + DataBinder DataBinder + Layout Layout + Children []Widget } func (c Composite) Create(builder *Builder) error { @@ -54,8 +54,8 @@ func (c Composite) Create(builder *Builder) error { }) } -func (w Composite) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w Composite) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } func (c Composite) ContainerInfo() (DataBinder, Layout, []Widget) { diff --git a/declarative/customwidget.go b/declarative/customwidget.go index c44ab59a..9c0cd801 100644 --- a/declarative/customwidget.go +++ b/declarative/customwidget.go @@ -22,7 +22,7 @@ type CustomWidget struct { RowSpan int Column int ColumnSpan int - ContextMenuActions []*walk.Action + ContextMenuItems []MenuItem OnKeyDown walk.KeyEventHandler OnMouseDown walk.MouseEventHandler OnMouseMove walk.MouseEventHandler @@ -52,6 +52,6 @@ func (cw CustomWidget) Create(builder *Builder) error { }) } -func (w CustomWidget) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w CustomWidget) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } diff --git a/declarative/dateedit.go b/declarative/dateedit.go index dd7d9f53..9e15bbe8 100644 --- a/declarative/dateedit.go +++ b/declarative/dateedit.go @@ -13,30 +13,30 @@ import ( ) type DateEdit struct { - AssignTo **walk.DateEdit - Name string - Enabled Property - Visible Property - Font Font - ToolTipText Property - MinSize Size - MaxSize Size - StretchFactor int - Row int - RowSpan int - Column int - ColumnSpan int - ContextMenuActions []*walk.Action - OnKeyDown walk.KeyEventHandler - OnMouseDown walk.MouseEventHandler - OnMouseMove walk.MouseEventHandler - OnMouseUp walk.MouseEventHandler - OnSizeChanged walk.EventHandler - NoneOption bool - MinDate time.Time - MaxDate time.Time - Date Property - OnDateChanged walk.EventHandler + AssignTo **walk.DateEdit + Name string + Enabled Property + Visible Property + Font Font + ToolTipText Property + MinSize Size + MaxSize Size + StretchFactor int + Row int + RowSpan int + Column int + ColumnSpan int + ContextMenuItems []MenuItem + OnKeyDown walk.KeyEventHandler + OnMouseDown walk.MouseEventHandler + OnMouseMove walk.MouseEventHandler + OnMouseUp walk.MouseEventHandler + OnSizeChanged walk.EventHandler + NoneOption bool + MinDate time.Time + MaxDate time.Time + Date Property + OnDateChanged walk.EventHandler } func (de DateEdit) Create(builder *Builder) error { @@ -69,6 +69,6 @@ func (de DateEdit) Create(builder *Builder) error { }) } -func (w DateEdit) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w DateEdit) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } diff --git a/declarative/dialog.go b/declarative/dialog.go index be01bb76..f41a7e5f 100644 --- a/declarative/dialog.go +++ b/declarative/dialog.go @@ -9,26 +9,26 @@ import ( ) type Dialog struct { - AssignTo **walk.Dialog - Name string - Enabled Property - Visible Property - Font Font - MinSize Size - MaxSize Size - ContextMenuActions []*walk.Action - OnKeyDown walk.KeyEventHandler - OnMouseDown walk.MouseEventHandler - OnMouseMove walk.MouseEventHandler - OnMouseUp walk.MouseEventHandler - OnSizeChanged walk.EventHandler - Title string - Size Size - DataBinder DataBinder - Layout Layout - Children []Widget - DefaultButton **walk.PushButton - CancelButton **walk.PushButton + AssignTo **walk.Dialog + Name string + Enabled Property + Visible Property + Font Font + MinSize Size + MaxSize Size + ContextMenuItems []MenuItem + OnKeyDown walk.KeyEventHandler + OnMouseDown walk.MouseEventHandler + OnMouseMove walk.MouseEventHandler + OnMouseUp walk.MouseEventHandler + OnSizeChanged walk.EventHandler + Title string + Size Size + DataBinder DataBinder + Layout Layout + Children []Widget + DefaultButton **walk.PushButton + CancelButton **walk.PushButton } func (d Dialog) Create(owner walk.RootWidget) error { @@ -38,20 +38,20 @@ func (d Dialog) Create(owner walk.RootWidget) error { } tlwi := topLevelWindowInfo{ - Name: d.Name, - Font: d.Font, - ToolTipText: "", - MinSize: d.MinSize, - MaxSize: d.MaxSize, - ContextMenuActions: d.ContextMenuActions, - DataBinder: d.DataBinder, - Layout: d.Layout, - Children: d.Children, - OnKeyDown: d.OnKeyDown, - OnMouseDown: d.OnMouseDown, - OnMouseMove: d.OnMouseMove, - OnMouseUp: d.OnMouseUp, - OnSizeChanged: d.OnSizeChanged, + Name: d.Name, + Font: d.Font, + ToolTipText: "", + MinSize: d.MinSize, + MaxSize: d.MaxSize, + ContextMenuItems: d.ContextMenuItems, + DataBinder: d.DataBinder, + Layout: d.Layout, + Children: d.Children, + OnKeyDown: d.OnKeyDown, + OnMouseDown: d.OnMouseDown, + OnMouseMove: d.OnMouseMove, + OnMouseUp: d.OnMouseUp, + OnSizeChanged: d.OnSizeChanged, } var db *walk.DataBinder diff --git a/declarative/groupbox.go b/declarative/groupbox.go index aa23d6be..654dcb27 100644 --- a/declarative/groupbox.go +++ b/declarative/groupbox.go @@ -9,29 +9,29 @@ import ( ) type GroupBox struct { - AssignTo **walk.GroupBox - Name string - Enabled Property - Visible Property - Font Font - ToolTipText Property - MinSize Size - MaxSize Size - StretchFactor int - Row int - RowSpan int - Column int - ColumnSpan int - ContextMenuActions []*walk.Action - OnKeyDown walk.KeyEventHandler - OnMouseDown walk.MouseEventHandler - OnMouseMove walk.MouseEventHandler - OnMouseUp walk.MouseEventHandler - OnSizeChanged walk.EventHandler - Title string - DataBinder DataBinder - Layout Layout - Children []Widget + AssignTo **walk.GroupBox + Name string + Enabled Property + Visible Property + Font Font + ToolTipText Property + MinSize Size + MaxSize Size + StretchFactor int + Row int + RowSpan int + Column int + ColumnSpan int + ContextMenuItems []MenuItem + OnKeyDown walk.KeyEventHandler + OnMouseDown walk.MouseEventHandler + OnMouseMove walk.MouseEventHandler + OnMouseUp walk.MouseEventHandler + OnSizeChanged walk.EventHandler + Title string + DataBinder DataBinder + Layout Layout + Children []Widget } func (gb GroupBox) Create(builder *Builder) error { @@ -59,8 +59,8 @@ func (gb GroupBox) Create(builder *Builder) error { }) } -func (w GroupBox) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w GroupBox) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } func (gb GroupBox) ContainerInfo() (DataBinder, Layout, []Widget) { diff --git a/declarative/imageview.go b/declarative/imageview.go index 22ac70eb..0d5dbf99 100644 --- a/declarative/imageview.go +++ b/declarative/imageview.go @@ -9,26 +9,26 @@ import ( ) type ImageView struct { - AssignTo **walk.ImageView - Name string - Enabled Property - Visible Property - Font Font - ToolTipText Property - MinSize Size - MaxSize Size - StretchFactor int - Row int - RowSpan int - Column int - ColumnSpan int - ContextMenuActions []*walk.Action - OnKeyDown walk.KeyEventHandler - OnMouseDown walk.MouseEventHandler - OnMouseMove walk.MouseEventHandler - OnMouseUp walk.MouseEventHandler - OnSizeChanged walk.EventHandler - Image walk.Image + AssignTo **walk.ImageView + Name string + Enabled Property + Visible Property + Font Font + ToolTipText Property + MinSize Size + MaxSize Size + StretchFactor int + Row int + RowSpan int + Column int + ColumnSpan int + ContextMenuItems []MenuItem + OnKeyDown walk.KeyEventHandler + OnMouseDown walk.MouseEventHandler + OnMouseMove walk.MouseEventHandler + OnMouseUp walk.MouseEventHandler + OnSizeChanged walk.EventHandler + Image walk.Image } func (iv ImageView) Create(builder *Builder) error { @@ -50,6 +50,6 @@ func (iv ImageView) Create(builder *Builder) error { }) } -func (w ImageView) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w ImageView) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } diff --git a/declarative/interfaces.go b/declarative/interfaces.go index cbbf8311..acd24e7a 100644 --- a/declarative/interfaces.go +++ b/declarative/interfaces.go @@ -11,12 +11,12 @@ import ( type Property interface{} type bindData struct { - path string - validator Validator + expression string + validator Validator } -func Bind(path string, validators ...Validator) Property { - bd := bindData{path: path} +func Bind(expression string, validators ...Validator) Property { + bd := bindData{expression: expression} switch len(validators) { case 0: // nop @@ -37,7 +37,7 @@ type Layout interface { type Widget interface { Create(builder *Builder) error - WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) + WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) } type Container interface { @@ -45,7 +45,7 @@ type Container interface { } type MenuItem interface { - createAction(menu *walk.Menu) (*walk.Action, error) + createAction(builder *Builder, menu *walk.Menu) (*walk.Action, error) } type Validator interface { @@ -69,30 +69,30 @@ func (epr ErrorPresenterRef) Create() (walk.ErrorPresenter, error) { } type topLevelWindowInfo struct { - Name string - Disabled bool - Hidden bool - Font Font - ToolTipText string - MinSize Size - MaxSize Size - ContextMenuActions []*walk.Action - OnKeyDown walk.KeyEventHandler - OnMouseDown walk.MouseEventHandler - OnMouseMove walk.MouseEventHandler - OnMouseUp walk.MouseEventHandler - OnSizeChanged walk.EventHandler - DataBinder DataBinder - Layout Layout - Children []Widget + Name string + Disabled bool + Hidden bool + Font Font + ToolTipText string + MinSize Size + MaxSize Size + ContextMenuItems []MenuItem + OnKeyDown walk.KeyEventHandler + OnMouseDown walk.MouseEventHandler + OnMouseMove walk.MouseEventHandler + OnMouseUp walk.MouseEventHandler + OnSizeChanged walk.EventHandler + DataBinder DataBinder + Layout Layout + Children []Widget } func (topLevelWindowInfo) Create(builder *Builder) error { return nil } -func (i topLevelWindowInfo) WidgetInfo() (name string, disabled, hidden bool, font *Font, ToolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return i.Name, i.Disabled, i.Hidden, &i.Font, i.ToolTipText, i.MinSize, i.MaxSize, 0, 0, 0, 0, 0, i.ContextMenuActions, i.OnKeyDown, i.OnMouseDown, i.OnMouseMove, i.OnMouseUp, i.OnSizeChanged +func (i topLevelWindowInfo) WidgetInfo() (name string, disabled, hidden bool, font *Font, ToolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return i.Name, i.Disabled, i.Hidden, &i.Font, i.ToolTipText, i.MinSize, i.MaxSize, 0, 0, 0, 0, 0, i.ContextMenuItems, i.OnKeyDown, i.OnMouseDown, i.OnMouseMove, i.OnMouseUp, i.OnSizeChanged } func (i topLevelWindowInfo) ContainerInfo() (DataBinder, Layout, []Widget) { diff --git a/declarative/label.go b/declarative/label.go index cfecad87..05e37f78 100644 --- a/declarative/label.go +++ b/declarative/label.go @@ -9,26 +9,26 @@ import ( ) type Label struct { - AssignTo **walk.Label - Name string - Enabled Property - Visible Property - Font Font - ToolTipText Property - MinSize Size - MaxSize Size - StretchFactor int - Row int - RowSpan int - Column int - ColumnSpan int - ContextMenuActions []*walk.Action - OnKeyDown walk.KeyEventHandler - OnMouseDown walk.MouseEventHandler - OnMouseMove walk.MouseEventHandler - OnMouseUp walk.MouseEventHandler - OnSizeChanged walk.EventHandler - Text Property + AssignTo **walk.Label + Name string + Enabled Property + Visible Property + Font Font + ToolTipText Property + MinSize Size + MaxSize Size + StretchFactor int + Row int + RowSpan int + Column int + ColumnSpan int + ContextMenuItems []MenuItem + OnKeyDown walk.KeyEventHandler + OnMouseDown walk.MouseEventHandler + OnMouseMove walk.MouseEventHandler + OnMouseUp walk.MouseEventHandler + OnSizeChanged walk.EventHandler + Text Property } func (l Label) Create(builder *Builder) error { @@ -46,6 +46,6 @@ func (l Label) Create(builder *Builder) error { }) } -func (w Label) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w Label) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } diff --git a/declarative/lineedit.go b/declarative/lineedit.go index a42f27f3..3401df8a 100644 --- a/declarative/lineedit.go +++ b/declarative/lineedit.go @@ -9,33 +9,33 @@ import ( ) type LineEdit struct { - AssignTo **walk.LineEdit - Name string - Enabled Property - Visible Property - Font Font - ToolTipText Property - MinSize Size - MaxSize Size - StretchFactor int - Row int - RowSpan int - Column int - ColumnSpan int - ContextMenuActions []*walk.Action - OnKeyDown walk.KeyEventHandler - OnMouseDown walk.MouseEventHandler - OnMouseMove walk.MouseEventHandler - OnMouseUp walk.MouseEventHandler - OnSizeChanged walk.EventHandler - Text Property - ReadOnly Property - CueBanner string - MaxLength int - PasswordMode bool - OnEditingFinished walk.EventHandler - OnReturnPressed walk.EventHandler - OnTextChanged walk.EventHandler + AssignTo **walk.LineEdit + Name string + Enabled Property + Visible Property + Font Font + ToolTipText Property + MinSize Size + MaxSize Size + StretchFactor int + Row int + RowSpan int + Column int + ColumnSpan int + ContextMenuItems []MenuItem + OnKeyDown walk.KeyEventHandler + OnMouseDown walk.MouseEventHandler + OnMouseMove walk.MouseEventHandler + OnMouseUp walk.MouseEventHandler + OnSizeChanged walk.EventHandler + Text Property + ReadOnly Property + CueBanner string + MaxLength int + PasswordMode bool + OnEditingFinished walk.EventHandler + OnReturnPressed walk.EventHandler + OnTextChanged walk.EventHandler } func (le LineEdit) Create(builder *Builder) error { @@ -69,6 +69,6 @@ func (le LineEdit) Create(builder *Builder) error { }) } -func (w LineEdit) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w LineEdit) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } diff --git a/declarative/lineerrorpresenter.go b/declarative/lineerrorpresenter.go index dcc55c60..22d394a8 100644 --- a/declarative/lineerrorpresenter.go +++ b/declarative/lineerrorpresenter.go @@ -9,25 +9,25 @@ import ( ) type LineErrorPresenter struct { - AssignTo *walk.ErrorPresenter - Name string - Enabled Property - Visible Property - Font Font - ToolTipText Property - MinSize Size - MaxSize Size - StretchFactor int - Row int - RowSpan int - Column int - ColumnSpan int - ContextMenuActions []*walk.Action - OnKeyDown walk.KeyEventHandler - OnMouseDown walk.MouseEventHandler - OnMouseMove walk.MouseEventHandler - OnMouseUp walk.MouseEventHandler - OnSizeChanged walk.EventHandler + AssignTo *walk.ErrorPresenter + Name string + Enabled Property + Visible Property + Font Font + ToolTipText Property + MinSize Size + MaxSize Size + StretchFactor int + Row int + RowSpan int + Column int + ColumnSpan int + ContextMenuItems []MenuItem + OnKeyDown walk.KeyEventHandler + OnMouseDown walk.MouseEventHandler + OnMouseMove walk.MouseEventHandler + OnMouseUp walk.MouseEventHandler + OnSizeChanged walk.EventHandler } func (lep LineErrorPresenter) Create(builder *Builder) error { @@ -45,6 +45,6 @@ func (lep LineErrorPresenter) Create(builder *Builder) error { }) } -func (w LineErrorPresenter) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w LineErrorPresenter) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } diff --git a/declarative/listbox.go b/declarative/listbox.go index 64816fff..911d6a66 100644 --- a/declarative/listbox.go +++ b/declarative/listbox.go @@ -22,7 +22,7 @@ type ListBox struct { RowSpan int Column int ColumnSpan int - ContextMenuActions []*walk.Action + ContextMenuItems []MenuItem OnKeyDown walk.KeyEventHandler OnMouseDown walk.MouseEventHandler OnMouseMove walk.MouseEventHandler @@ -67,6 +67,6 @@ func (lb ListBox) Create(builder *Builder) error { }) } -func (w ListBox) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w ListBox) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } diff --git a/declarative/mainwindow.go b/declarative/mainwindow.go index 227748f9..98d9e2c6 100644 --- a/declarative/mainwindow.go +++ b/declarative/mainwindow.go @@ -9,26 +9,26 @@ import ( ) type MainWindow struct { - AssignTo **walk.MainWindow - Name string - Enabled Property - Visible Property - Font Font - MinSize Size - MaxSize Size - ContextMenuActions []*walk.Action - OnKeyDown walk.KeyEventHandler - OnMouseDown walk.MouseEventHandler - OnMouseMove walk.MouseEventHandler - OnMouseUp walk.MouseEventHandler - OnSizeChanged walk.EventHandler - Title string - Size Size - DataBinder DataBinder - Layout Layout - Children []Widget - MenuActions []*walk.Action - ToolBarActions []*walk.Action + AssignTo **walk.MainWindow + Name string + Enabled Property + Visible Property + Font Font + MinSize Size + MaxSize Size + ContextMenuItems []MenuItem + OnKeyDown walk.KeyEventHandler + OnMouseDown walk.MouseEventHandler + OnMouseMove walk.MouseEventHandler + OnMouseUp walk.MouseEventHandler + OnSizeChanged walk.EventHandler + Title string + Size Size + DataBinder DataBinder + Layout Layout + Children []Widget + MenuItems []MenuItem + ToolBarItems []MenuItem } func (mw MainWindow) Create() error { @@ -38,20 +38,20 @@ func (mw MainWindow) Create() error { } tlwi := topLevelWindowInfo{ - Name: mw.Name, - Font: mw.Font, - ToolTipText: "", - MinSize: mw.MinSize, - MaxSize: mw.MaxSize, - ContextMenuActions: mw.ContextMenuActions, - OnKeyDown: mw.OnKeyDown, - OnMouseDown: mw.OnMouseDown, - OnMouseMove: mw.OnMouseMove, - OnMouseUp: mw.OnMouseUp, - OnSizeChanged: mw.OnSizeChanged, - DataBinder: mw.DataBinder, - Layout: mw.Layout, - Children: mw.Children, + Name: mw.Name, + Font: mw.Font, + ToolTipText: "", + MinSize: mw.MinSize, + MaxSize: mw.MaxSize, + ContextMenuItems: mw.ContextMenuItems, + OnKeyDown: mw.OnKeyDown, + OnMouseDown: mw.OnMouseDown, + OnMouseMove: mw.OnMouseMove, + OnMouseUp: mw.OnMouseUp, + OnSizeChanged: mw.OnSizeChanged, + DataBinder: mw.DataBinder, + Layout: mw.Layout, + Children: mw.Children, } builder := NewBuilder(nil) @@ -65,26 +65,25 @@ func (mw MainWindow) Create() error { return err } - if err := addToActionList(w.Menu().Actions(), mw.MenuActions); err != nil { - return err - } - imageList, err := walk.NewImageList(walk.Size{16, 16}, 0) if err != nil { return err } w.ToolBar().SetImageList(imageList) - if err := addToActionList(w.ToolBar().Actions(), mw.ToolBarActions); err != nil { - return err - } - - w.Show() - if mw.AssignTo != nil { *mw.AssignTo = w } + builder.deferBuildActions(w.Menu().Actions(), mw.MenuItems) + builder.deferBuildActions(w.ToolBar().Actions(), mw.ToolBarItems) + + builder.Defer(func() error { + w.Show() + + return nil + }) + return nil }) } diff --git a/declarative/numberedit.go b/declarative/numberedit.go index 3ff0ef0c..3cc1e0c0 100644 --- a/declarative/numberedit.go +++ b/declarative/numberedit.go @@ -9,31 +9,31 @@ import ( ) type NumberEdit struct { - AssignTo **walk.NumberEdit - Name string - Enabled Property - Visible Property - Font Font - ToolTipText Property - MinSize Size - MaxSize Size - StretchFactor int - Row int - RowSpan int - Column int - ColumnSpan int - ContextMenuActions []*walk.Action - OnKeyDown walk.KeyEventHandler - OnMouseDown walk.MouseEventHandler - OnMouseMove walk.MouseEventHandler - OnMouseUp walk.MouseEventHandler - OnSizeChanged walk.EventHandler - Decimals int - Increment float64 - MinValue float64 - MaxValue float64 - Value Property - OnValueChanged walk.EventHandler + AssignTo **walk.NumberEdit + Name string + Enabled Property + Visible Property + Font Font + ToolTipText Property + MinSize Size + MaxSize Size + StretchFactor int + Row int + RowSpan int + Column int + ColumnSpan int + ContextMenuItems []MenuItem + OnKeyDown walk.KeyEventHandler + OnMouseDown walk.MouseEventHandler + OnMouseMove walk.MouseEventHandler + OnMouseUp walk.MouseEventHandler + OnSizeChanged walk.EventHandler + Decimals int + Increment float64 + MinValue float64 + MaxValue float64 + Value Property + OnValueChanged walk.EventHandler } func (ne NumberEdit) Create(builder *Builder) error { @@ -74,6 +74,6 @@ func (ne NumberEdit) Create(builder *Builder) error { }) } -func (w NumberEdit) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w NumberEdit) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } diff --git a/declarative/progressbar.go b/declarative/progressbar.go index ba3fcc7b..ad2e9c92 100644 --- a/declarative/progressbar.go +++ b/declarative/progressbar.go @@ -9,28 +9,28 @@ import ( ) type ProgressBar struct { - AssignTo **walk.ProgressBar - Name string - Enabled Property - Visible Property - Font Font - ToolTipText Property - MinSize Size - MaxSize Size - StretchFactor int - Row int - RowSpan int - Column int - ColumnSpan int - ContextMenuActions []*walk.Action - OnKeyDown walk.KeyEventHandler - OnMouseDown walk.MouseEventHandler - OnMouseMove walk.MouseEventHandler - OnMouseUp walk.MouseEventHandler - OnSizeChanged walk.EventHandler - MinValue int - MaxValue int - Value int + AssignTo **walk.ProgressBar + Name string + Enabled Property + Visible Property + Font Font + ToolTipText Property + MinSize Size + MaxSize Size + StretchFactor int + Row int + RowSpan int + Column int + ColumnSpan int + ContextMenuItems []MenuItem + OnKeyDown walk.KeyEventHandler + OnMouseDown walk.MouseEventHandler + OnMouseMove walk.MouseEventHandler + OnMouseUp walk.MouseEventHandler + OnSizeChanged walk.EventHandler + MinValue int + MaxValue int + Value int } func (pb ProgressBar) Create(builder *Builder) error { @@ -51,6 +51,6 @@ func (pb ProgressBar) Create(builder *Builder) error { }) } -func (w ProgressBar) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w ProgressBar) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } diff --git a/declarative/pushbutton.go b/declarative/pushbutton.go index 232e08ee..842b6c26 100644 --- a/declarative/pushbutton.go +++ b/declarative/pushbutton.go @@ -9,27 +9,27 @@ import ( ) type PushButton struct { - AssignTo **walk.PushButton - Name string - Enabled Property - Visible Property - Font Font - ToolTipText Property - MinSize Size - MaxSize Size - StretchFactor int - Row int - RowSpan int - Column int - ColumnSpan int - ContextMenuActions []*walk.Action - OnKeyDown walk.KeyEventHandler - OnMouseDown walk.MouseEventHandler - OnMouseMove walk.MouseEventHandler - OnMouseUp walk.MouseEventHandler - OnSizeChanged walk.EventHandler - Text Property - OnClicked walk.EventHandler + AssignTo **walk.PushButton + Name string + Enabled Property + Visible Property + Font Font + ToolTipText Property + MinSize Size + MaxSize Size + StretchFactor int + Row int + RowSpan int + Column int + ColumnSpan int + ContextMenuItems []MenuItem + OnKeyDown walk.KeyEventHandler + OnMouseDown walk.MouseEventHandler + OnMouseMove walk.MouseEventHandler + OnMouseUp walk.MouseEventHandler + OnSizeChanged walk.EventHandler + Text Property + OnClicked walk.EventHandler } func (pb PushButton) Create(builder *Builder) error { @@ -51,6 +51,6 @@ func (pb PushButton) Create(builder *Builder) error { }) } -func (w PushButton) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w PushButton) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } diff --git a/declarative/radiobutton.go b/declarative/radiobutton.go index 3886fd3d..460e2c8f 100644 --- a/declarative/radiobutton.go +++ b/declarative/radiobutton.go @@ -9,27 +9,27 @@ import ( ) type RadioButton struct { - AssignTo **walk.RadioButton - Name string - Enabled Property - Visible Property - Font Font - ToolTipText Property - MinSize Size - MaxSize Size - StretchFactor int - Row int - RowSpan int - Column int - ColumnSpan int - ContextMenuActions []*walk.Action - OnKeyDown walk.KeyEventHandler - OnMouseDown walk.MouseEventHandler - OnMouseMove walk.MouseEventHandler - OnMouseUp walk.MouseEventHandler - OnSizeChanged walk.EventHandler - Text Property - OnClicked walk.EventHandler + AssignTo **walk.RadioButton + Name string + Enabled Property + Visible Property + Font Font + ToolTipText Property + MinSize Size + MaxSize Size + StretchFactor int + Row int + RowSpan int + Column int + ColumnSpan int + ContextMenuItems []MenuItem + OnKeyDown walk.KeyEventHandler + OnMouseDown walk.MouseEventHandler + OnMouseMove walk.MouseEventHandler + OnMouseUp walk.MouseEventHandler + OnSizeChanged walk.EventHandler + Text Property + OnClicked walk.EventHandler } func (rb RadioButton) Create(builder *Builder) error { @@ -51,6 +51,6 @@ func (rb RadioButton) Create(builder *Builder) error { }) } -func (w RadioButton) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w RadioButton) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } diff --git a/declarative/spacer.go b/declarative/spacer.go index 0a553fa0..dd502b58 100644 --- a/declarative/spacer.go +++ b/declarative/spacer.go @@ -35,7 +35,7 @@ func (hs HSpacer) Create(builder *Builder) (err error) { return builder.InitWidget(hs, w, nil) } -func (hs HSpacer) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { +func (hs HSpacer) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { return hs.Name, false, false, nil, "", hs.MinSize, hs.MaxSize, hs.StretchFactor, hs.Row, hs.RowSpan, hs.Column, hs.ColumnSpan, nil, nil, nil, nil, nil, nil } @@ -66,6 +66,6 @@ func (vs VSpacer) Create(builder *Builder) (err error) { return builder.InitWidget(vs, w, nil) } -func (vs VSpacer) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { +func (vs VSpacer) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { return vs.Name, false, false, nil, "", vs.MinSize, vs.MaxSize, vs.StretchFactor, vs.Row, vs.RowSpan, vs.Column, vs.ColumnSpan, nil, nil, nil, nil, nil, nil } diff --git a/declarative/splitter.go b/declarative/splitter.go index 0cd4165d..70aabe67 100644 --- a/declarative/splitter.go +++ b/declarative/splitter.go @@ -9,29 +9,29 @@ import ( ) type Splitter struct { - AssignTo **walk.Splitter - Name string - Enabled Property - Visible Property - Font Font - ToolTipText Property - MinSize Size - MaxSize Size - StretchFactor int - Row int - RowSpan int - Column int - ColumnSpan int - ContextMenuActions []*walk.Action - OnKeyDown walk.KeyEventHandler - OnMouseDown walk.MouseEventHandler - OnMouseMove walk.MouseEventHandler - OnMouseUp walk.MouseEventHandler - OnSizeChanged walk.EventHandler - DataBinder DataBinder - Children []Widget - HandleWidth int - Orientation Orientation + AssignTo **walk.Splitter + Name string + Enabled Property + Visible Property + Font Font + ToolTipText Property + MinSize Size + MaxSize Size + StretchFactor int + Row int + RowSpan int + Column int + ColumnSpan int + ContextMenuItems []MenuItem + OnKeyDown walk.KeyEventHandler + OnMouseDown walk.MouseEventHandler + OnMouseMove walk.MouseEventHandler + OnMouseUp walk.MouseEventHandler + OnSizeChanged walk.EventHandler + DataBinder DataBinder + Children []Widget + HandleWidth int + Orientation Orientation } func (s Splitter) Create(builder *Builder) error { @@ -58,8 +58,8 @@ func (s Splitter) Create(builder *Builder) error { }) } -func (w Splitter) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w Splitter) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } func (s Splitter) ContainerInfo() (DataBinder, Layout, []Widget) { diff --git a/declarative/tableview.go b/declarative/tableview.go index 9a58199c..5a7436b4 100644 --- a/declarative/tableview.go +++ b/declarative/tableview.go @@ -22,7 +22,7 @@ type TableView struct { RowSpan int Column int ColumnSpan int - ContextMenuActions []*walk.Action + ContextMenuItems []MenuItem OnKeyDown walk.KeyEventHandler OnMouseDown walk.MouseEventHandler OnMouseMove walk.MouseEventHandler @@ -89,6 +89,6 @@ func (tv TableView) Create(builder *Builder) error { }) } -func (w TableView) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w TableView) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } diff --git a/declarative/tabpage.go b/declarative/tabpage.go index e8c282ef..b290ae87 100644 --- a/declarative/tabpage.go +++ b/declarative/tabpage.go @@ -9,25 +9,25 @@ import ( ) type TabPage struct { - AssignTo **walk.TabPage - Name string - Enabled Property - Visible Property - Font Font - ToolTipText Property - MinSize Size - MaxSize Size - ContextMenuActions []*walk.Action - OnKeyDown walk.KeyEventHandler - OnMouseDown walk.MouseEventHandler - OnMouseMove walk.MouseEventHandler - OnMouseUp walk.MouseEventHandler - OnSizeChanged walk.EventHandler - DataBinder DataBinder - Layout Layout - Children []Widget - Title Property - Content Widget + AssignTo **walk.TabPage + Name string + Enabled Property + Visible Property + Font Font + ToolTipText Property + MinSize Size + MaxSize Size + ContextMenuItems []MenuItem + OnKeyDown walk.KeyEventHandler + OnMouseDown walk.MouseEventHandler + OnMouseMove walk.MouseEventHandler + OnMouseUp walk.MouseEventHandler + OnSizeChanged walk.EventHandler + DataBinder DataBinder + Layout Layout + Children []Widget + Title Property + Content Widget } func (tp TabPage) Create(builder *Builder) error { @@ -51,8 +51,8 @@ func (tp TabPage) Create(builder *Builder) error { }) } -func (w TabPage) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, 0, 0, 0, 0, 0, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w TabPage) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, 0, 0, 0, 0, 0, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } func (tp TabPage) ContainerInfo() (DataBinder, Layout, []Widget) { diff --git a/declarative/tabwidget.go b/declarative/tabwidget.go index f8e3b388..feb423a4 100644 --- a/declarative/tabwidget.go +++ b/declarative/tabwidget.go @@ -22,7 +22,7 @@ type TabWidget struct { RowSpan int Column int ColumnSpan int - ContextMenuActions []*walk.Action + ContextMenuItems []MenuItem OnKeyDown walk.KeyEventHandler OnMouseDown walk.MouseEventHandler OnMouseMove walk.MouseEventHandler @@ -72,6 +72,6 @@ func (tw TabWidget) Create(builder *Builder) error { }) } -func (w TabWidget) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w TabWidget) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } diff --git a/declarative/textedit.go b/declarative/textedit.go index 30147abf..9ed80cc6 100644 --- a/declarative/textedit.go +++ b/declarative/textedit.go @@ -9,27 +9,27 @@ import ( ) type TextEdit struct { - AssignTo **walk.TextEdit - Name string - Enabled Property - Visible Property - Font Font - ToolTipText Property - MinSize Size - MaxSize Size - StretchFactor int - Row int - RowSpan int - Column int - ColumnSpan int - ContextMenuActions []*walk.Action - OnKeyDown walk.KeyEventHandler - OnMouseDown walk.MouseEventHandler - OnMouseMove walk.MouseEventHandler - OnMouseUp walk.MouseEventHandler - OnSizeChanged walk.EventHandler - Text Property - ReadOnly Property + AssignTo **walk.TextEdit + Name string + Enabled Property + Visible Property + Font Font + ToolTipText Property + MinSize Size + MaxSize Size + StretchFactor int + Row int + RowSpan int + Column int + ColumnSpan int + ContextMenuItems []MenuItem + OnKeyDown walk.KeyEventHandler + OnMouseDown walk.MouseEventHandler + OnMouseMove walk.MouseEventHandler + OnMouseUp walk.MouseEventHandler + OnSizeChanged walk.EventHandler + Text Property + ReadOnly Property } func (te TextEdit) Create(builder *Builder) error { @@ -47,6 +47,6 @@ func (te TextEdit) Create(builder *Builder) error { }) } -func (w TextEdit) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w TextEdit) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } diff --git a/declarative/toolbar.go b/declarative/toolbar.go index 89607e6c..6410cbdb 100644 --- a/declarative/toolbar.go +++ b/declarative/toolbar.go @@ -9,28 +9,28 @@ import ( ) type ToolBar struct { - AssignTo **walk.ToolBar - Name string - Enabled Property - Visible Property - Font Font - ToolTipText Property - MinSize Size - MaxSize Size - StretchFactor int - Row int - RowSpan int - Column int - ColumnSpan int - ContextMenuActions []*walk.Action - OnKeyDown walk.KeyEventHandler - OnMouseDown walk.MouseEventHandler - OnMouseMove walk.MouseEventHandler - OnMouseUp walk.MouseEventHandler - OnSizeChanged walk.EventHandler - Actions []*walk.Action - MaxTextRows int - Orientation Orientation + AssignTo **walk.ToolBar + Name string + Enabled Property + Visible Property + Font Font + ToolTipText Property + MinSize Size + MaxSize Size + StretchFactor int + Row int + RowSpan int + Column int + ColumnSpan int + ContextMenuItems []MenuItem + OnKeyDown walk.KeyEventHandler + OnMouseDown walk.MouseEventHandler + OnMouseMove walk.MouseEventHandler + OnMouseUp walk.MouseEventHandler + OnSizeChanged walk.EventHandler + Actions []*walk.Action + MaxTextRows int + Orientation Orientation } func (tb ToolBar) Create(builder *Builder) (err error) { @@ -71,6 +71,6 @@ func (tb ToolBar) Create(builder *Builder) (err error) { }) } -func (w ToolBar) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w ToolBar) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } diff --git a/declarative/toolbutton.go b/declarative/toolbutton.go index fead4716..04a8c89f 100644 --- a/declarative/toolbutton.go +++ b/declarative/toolbutton.go @@ -9,27 +9,27 @@ import ( ) type ToolButton struct { - AssignTo **walk.ToolButton - Name string - Enabled Property - Visible Property - Font Font - ToolTipText Property - MinSize Size - MaxSize Size - StretchFactor int - Row int - RowSpan int - Column int - ColumnSpan int - ContextMenuActions []*walk.Action - OnKeyDown walk.KeyEventHandler - OnMouseDown walk.MouseEventHandler - OnMouseMove walk.MouseEventHandler - OnMouseUp walk.MouseEventHandler - OnSizeChanged walk.EventHandler - Text Property - OnClicked walk.EventHandler + AssignTo **walk.ToolButton + Name string + Enabled Property + Visible Property + Font Font + ToolTipText Property + MinSize Size + MaxSize Size + StretchFactor int + Row int + RowSpan int + Column int + ColumnSpan int + ContextMenuItems []MenuItem + OnKeyDown walk.KeyEventHandler + OnMouseDown walk.MouseEventHandler + OnMouseMove walk.MouseEventHandler + OnMouseUp walk.MouseEventHandler + OnSizeChanged walk.EventHandler + Text Property + OnClicked walk.EventHandler } func (tb ToolButton) Create(builder *Builder) error { @@ -51,6 +51,6 @@ func (tb ToolButton) Create(builder *Builder) error { }) } -func (w ToolButton) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w ToolButton) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } diff --git a/declarative/treeview.go b/declarative/treeview.go index 79ee4d4a..2f438283 100644 --- a/declarative/treeview.go +++ b/declarative/treeview.go @@ -22,7 +22,7 @@ type TreeView struct { RowSpan int Column int ColumnSpan int - ContextMenuActions []*walk.Action + ContextMenuItems []MenuItem OnKeyDown walk.KeyEventHandler OnMouseDown walk.MouseEventHandler OnMouseMove walk.MouseEventHandler @@ -65,6 +65,6 @@ func (tv TreeView) Create(builder *Builder) error { }) } -func (w TreeView) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w TreeView) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } diff --git a/declarative/webview.go b/declarative/webview.go index 0377851a..25984835 100644 --- a/declarative/webview.go +++ b/declarative/webview.go @@ -9,27 +9,27 @@ import ( ) type WebView struct { - AssignTo **walk.WebView - Name string - Enabled Property - Visible Property - Font Font - ToolTipText Property - MinSize Size - MaxSize Size - StretchFactor int - Row int - RowSpan int - Column int - ColumnSpan int - ContextMenuActions []*walk.Action - OnKeyDown walk.KeyEventHandler - OnMouseDown walk.MouseEventHandler - OnMouseMove walk.MouseEventHandler - OnMouseUp walk.MouseEventHandler - OnSizeChanged walk.EventHandler - URL Property - OnURLChanged walk.EventHandler + AssignTo **walk.WebView + Name string + Enabled Property + Visible Property + Font Font + ToolTipText Property + MinSize Size + MaxSize Size + StretchFactor int + Row int + RowSpan int + Column int + ColumnSpan int + ContextMenuItems []MenuItem + OnKeyDown walk.KeyEventHandler + OnMouseDown walk.MouseEventHandler + OnMouseMove walk.MouseEventHandler + OnMouseUp walk.MouseEventHandler + OnSizeChanged walk.EventHandler + URL Property + OnURLChanged walk.EventHandler } func (wv WebView) Create(builder *Builder) error { @@ -51,6 +51,6 @@ func (wv WebView) Create(builder *Builder) error { }) } -func (w WebView) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuActions []*walk.Action, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { - return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuActions, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged +func (w WebView) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) { + return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.ContextMenuItems, w.OnKeyDown, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged } diff --git a/menu.go b/menu.go index 74e62127..fdb99dcf 100644 --- a/menu.go +++ b/menu.go @@ -100,18 +100,43 @@ func (m *Menu) initMenuItemInfoFromAction(mii *MENUITEMINFO, action *Action) { } func (m *Menu) onActionChanged(action *Action) error { + if !action.Visible() { + return nil + } + var mii MENUITEMINFO m.initMenuItemInfoFromAction(&mii, action) - if !SetMenuItemInfo(m.hMenu, uint32(m.actions.Index(action)), true, &mii) { + if !SetMenuItemInfo(m.hMenu, uint32(m.actions.indexInObserver(action)), true, &mii) { return newError("SetMenuItemInfo failed") } return nil } -func (m *Menu) onInsertingAction(index int, action *Action) error { +func (m *Menu) onActionVisibleChanged(action *Action) error { + if action.Visible() { + return m.onInsertedAction(action) + } + + return m.onRemovingAction(action) +} + +func (m *Menu) onInsertedAction(action *Action) (err error) { + action.addChangedHandler(m) + defer func() { + if err != nil { + action.removeChangedHandler(m) + } + }() + + if !action.Visible() { + return + } + + index := m.actions.indexInObserver(action) + var mii MENUITEMINFO m.initMenuItemInfoFromAction(&mii, action) @@ -120,8 +145,6 @@ func (m *Menu) onInsertingAction(index int, action *Action) error { return newError("InsertMenuItem failed") } - action.addChangedHandler(m) - menu := action.menu if menu != nil { menu.hWnd = m.hWnd @@ -131,10 +154,12 @@ func (m *Menu) onInsertingAction(index int, action *Action) error { DrawMenuBar(m.hWnd) } - return nil + return } -func (m *Menu) onRemovingAction(index int, action *Action) error { +func (m *Menu) onRemovingAction(action *Action) error { + index := m.actions.indexInObserver(action) + if !RemoveMenu(m.hMenu, uint32(index), MF_BYPOSITION) { return lastError("RemoveMenu") } @@ -150,15 +175,11 @@ func (m *Menu) onRemovingAction(index int, action *Action) error { func (m *Menu) onClearingActions() error { for i := m.actions.Len() - 1; i >= 0; i-- { - if !RemoveMenu(m.hMenu, uint32(i), MF_BYPOSITION) { - return lastError("RemoveMenu") + if action := m.actions.At(i); action.Visible() { + if err := m.onRemovingAction(action); err != nil { + return err + } } - - m.actions.At(i).removeChangedHandler(m) - } - - if m.hWnd != 0 { - DrawMenuBar(m.hWnd) } return nil diff --git a/toolbar.go b/toolbar.go index c77b94ae..665cb31f 100644 --- a/toolbar.go +++ b/toolbar.go @@ -58,7 +58,7 @@ func (tb *ToolBar) LayoutFlags() LayoutFlags { } // FIXME: Since reimplementation of BoxLayout we must return 0 here, - // otherwise the ToolBar contained in MainWindow will eat half the space. + // otherwise the ToolBar contained in MainWindow will eat half the space. return 0 //ShrinkableHorz | GrowableHorz } @@ -108,15 +108,15 @@ func (tb *ToolBar) applyDefaultButtonWidth() error { // DefaultButtonWidth returns the default button width of the ToolBar. // // The default value for a horizontal ToolBar is 0, resulting in automatic -// sizing behavior. For a vertical ToolBar, the default is 100 pixels. +// sizing behavior. For a vertical ToolBar, the default is 100 pixels. func (tb *ToolBar) DefaultButtonWidth() int { return tb.defaultButtonWidth } // SetDefaultButtonWidth sets the default button width of the ToolBar. // -// Calling this method affects all buttons in the ToolBar, no matter if they are -// added before or after the call. A width of 0 results in automatic sizing +// Calling this method affects all buttons in the ToolBar, no matter if they are +// added before or after the call. A width of 0 results in automatic sizing // behavior. Negative values are not allowed. func (tb *ToolBar) SetDefaultButtonWidth(width int) error { if width == tb.defaultButtonWidth { @@ -269,42 +269,62 @@ func (tb *ToolBar) onActionChanged(action *Action) error { return nil } -func (tb *ToolBar) onInsertingAction(index int, action *Action) error { +func (tb *ToolBar) onActionVisibleChanged(action *Action) error { + if action.Visible() { + return tb.onInsertedAction(action) + } + + return tb.onRemovingAction(action) +} + +func (tb *ToolBar) onInsertedAction(action *Action) (err error) { + action.addChangedHandler(tb) + defer func() { + if err != nil { + action.removeChangedHandler(tb) + } + }() + + if !action.Visible() { + return + } + + index := tb.actions.indexInObserver(action) + tbb := TBBUTTON{ IdCommand: int32(action.id), } - if err := tb.initButtonForAction( + if err = tb.initButtonForAction( action, &tbb.FsState, &tbb.FsStyle, &tbb.IBitmap, &tbb.IString); err != nil { - return err + return } tb.SetVisible(true) tb.SendMessage(TB_BUTTONSTRUCTSIZE, uintptr(unsafe.Sizeof(tbb)), 0) - if FALSE == tb.SendMessage(TB_ADDBUTTONS, 1, uintptr(unsafe.Pointer(&tbb))) { + if FALSE == tb.SendMessage(TB_INSERTBUTTON, uintptr(index), uintptr(unsafe.Pointer(&tbb))) { return newError("SendMessage(TB_ADDBUTTONS)") } - if err := tb.applyDefaultButtonWidth(); err != nil { - return err + if err = tb.applyDefaultButtonWidth(); err != nil { + return } tb.SendMessage(TB_AUTOSIZE, 0, 0) - action.addChangedHandler(tb) - - return nil + return } -func (tb *ToolBar) removeAt(index int) error { - action := tb.actions.At(index) +func (tb *ToolBar) onRemovingAction(action *Action) error { + index := tb.actions.indexInObserver(action) + action.removeChangedHandler(tb) if 0 == tb.SendMessage(TB_DELETEBUTTON, uintptr(index), 0) { @@ -314,14 +334,12 @@ func (tb *ToolBar) removeAt(index int) error { return nil } -func (tb *ToolBar) onRemovingAction(index int, action *Action) error { - return tb.removeAt(index) -} - func (tb *ToolBar) onClearingActions() error { for i := tb.actions.Len() - 1; i >= 0; i-- { - if err := tb.removeAt(i); err != nil { - return err + if action := tb.actions.At(i); action.Visible() { + if err := tb.onRemovingAction(action); err != nil { + return err + } } } diff --git a/widget.go b/widget.go index 07478cd9..93ee041b 100644 --- a/widget.go +++ b/widget.go @@ -665,6 +665,26 @@ func (wb *WidgetBase) Dispose() { wb.hWnd = 0 DestroyWindow(hWnd) + + var disposeMenuActions func(menu *Menu) + disposeMenuActions = func(menu *Menu) { + if menu == nil { + return + } + + for _, action := range menu.actions.actions { + if action.enabledCondition != nil { + action.enabledCondition.Changed().Detach(action.enabledConditionChangedHandle) + } + if action.visibleCondition != nil { + action.visibleCondition.Changed().Detach(action.visibleConditionChangedHandle) + } + + disposeMenuActions(action.menu) + } + } + + disposeMenuActions(wb.contextMenu) } }