Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Simplify events

  • Loading branch information...
commit 5731dafd012efe19b7cd036973a2f72b6b3b79bd 1 parent 7ce1e4d
@lxn authored
View
15 src/cmd/examples/filebrowser/filebrowser.go
@@ -154,7 +154,7 @@ func main() {
exitAction := gui.NewAction()
panicIfErr(exitAction.SetText("Exit"))
- exitAction.Triggered().Subscribe(func(args *gui.EventArgs) { gui.App().Exit(0) })
+ exitAction.Triggered().Attach(func() { gui.App().Exit(0) })
panicIfErr(fileMenu.Actions().Add(exitAction))
helpMenu, err := gui.NewMenu()
@@ -165,7 +165,7 @@ func main() {
aboutAction := gui.NewAction()
panicIfErr(aboutAction.SetText("About"))
- aboutAction.Triggered().Subscribe(func(args *gui.EventArgs) {
+ aboutAction.Triggered().Attach(func() {
gui.MsgBox(mw, "About", "Walk File Browser Example", gui.MsgBoxOK|gui.MsgBoxIconInformation)
})
panicIfErr(helpMenu.Actions().Add(aboutAction))
@@ -177,17 +177,16 @@ func main() {
panicIfErr(err)
panicIfErr(mw.treeView.SetMaxSize(drawing.Size{200, 0}))
- mw.treeView.ItemExpanded().Subscribe(func(args *gui.TreeViewItemEventArgs) {
- item := args.Item()
+ mw.treeView.ItemExpanded().Attach(func(item *gui.TreeViewItem) {
children := item.Children()
if children.Len() == 1 && children.At(0).Text() == "" {
mw.populateTreeViewItem(item)
}
})
- mw.treeView.SelectionChanged().Subscribe(func(args *gui.TreeViewItemSelectionEventArgs) {
- mw.selTvwItem = args.New()
- mw.populateListView(pathForTreeViewItem(mw.selTvwItem))
+ mw.treeView.SelectionChanged().Attach(func(old, new *gui.TreeViewItem) {
+ mw.selTvwItem = new
+ mw.populateListView(pathForTreeViewItem(new))
})
drives, err := wpath.DriveNames()
@@ -204,7 +203,7 @@ func main() {
panicIfErr(err)
panicIfErr(mw.listView.SetMaxSize(drawing.Size{422, 0}))
- mw.listView.SelectedIndexChanged().Subscribe(func(args *gui.EventArgs) {
+ mw.listView.SelectedIndexChanged().Attach(func() {
index := mw.listView.SelectedIndex()
var url string
if index > -1 {
View
6 src/cmd/examples/imageviewer/imageviewer.go
@@ -109,13 +109,13 @@ func main() {
openAction := gui.NewAction()
openAction.SetImage(openBmp)
panicIfErr(openAction.SetText("Open"))
- openAction.Triggered().Subscribe(func(args *gui.EventArgs) { mw.openImage() })
+ openAction.Triggered().Attach(func() { mw.openImage() })
panicIfErr(fileMenu.Actions().Add(openAction))
panicIfErr(mw.ToolBar().Actions().Add(openAction))
exitAction := gui.NewAction()
panicIfErr(exitAction.SetText("Exit"))
- exitAction.Triggered().Subscribe(func(args *gui.EventArgs) { gui.App().Exit(0) })
+ exitAction.Triggered().Attach(func() { gui.App().Exit(0) })
panicIfErr(fileMenu.Actions().Add(exitAction))
helpMenu, err := gui.NewMenu()
@@ -126,7 +126,7 @@ func main() {
aboutAction := gui.NewAction()
panicIfErr(aboutAction.SetText("About"))
- aboutAction.Triggered().Subscribe(func(args *gui.EventArgs) {
+ aboutAction.Triggered().Attach(func() {
gui.MsgBox(mw, "About", "Walk Image Viewer Example", gui.MsgBoxOK|gui.MsgBoxIconInformation)
})
panicIfErr(helpMenu.Actions().Add(aboutAction))
View
8 src/cmd/examples/webbrowser/webbrowser.go
@@ -48,7 +48,7 @@ func main() {
exitAction := gui.NewAction()
panicIfErr(exitAction.SetText("Exit"))
- exitAction.Triggered().Subscribe(func(args *gui.EventArgs) { gui.App().Exit(0) })
+ exitAction.Triggered().Attach(func() { gui.App().Exit(0) })
panicIfErr(fileMenu.Actions().Add(exitAction))
helpMenu, err := gui.NewMenu()
@@ -59,15 +59,15 @@ func main() {
aboutAction := gui.NewAction()
panicIfErr(aboutAction.SetText("About"))
- aboutAction.Triggered().Subscribe(func(args *gui.EventArgs) {
+ aboutAction.Triggered().Attach(func() {
gui.MsgBox(mw, "About", "Walk Web Browser Example", gui.MsgBoxOK|gui.MsgBoxIconInformation)
})
panicIfErr(helpMenu.Actions().Add(aboutAction))
mw.urlLineEdit, err = gui.NewLineEdit(mw.ClientArea())
panicIfErr(err)
- mw.urlLineEdit.KeyDown().Subscribe(func(args *gui.KeyEventArgs) {
- if args.Key() == user32.VK_RETURN {
+ mw.urlLineEdit.KeyDown().Attach(func(key int) {
+ if key == user32.VK_RETURN {
panicIfErr(mw.webView.SetURL(mw.urlLineEdit.Text()))
}
})
View
2  src/pkg/walk/gui/action.go
@@ -218,7 +218,7 @@ func (a *Action) Triggered() *Event {
}
func (a *Action) raiseTriggered() {
- a.triggeredPublisher.Publish(NewEventArgs(a))
+ a.triggeredPublisher.Publish()
}
func (a *Action) addChangedHandler(handler actionChangedHandler) {
View
2  src/pkg/walk/gui/button.go
@@ -38,5 +38,5 @@ func (b *Button) Clicked() *Event {
}
func (b *Button) raiseClicked() {
- b.clickedPublisher.Publish(NewEventArgs(b))
+ b.clickedPublisher.Publish()
}
View
31 src/pkg/walk/gui/cancelevent.go
@@ -4,38 +4,17 @@
package gui
-type CancelEventArgs struct {
- EventArgs
- canceled bool
-}
-
-func NewCancelEventArgs(sender interface{}) *CancelEventArgs {
- return &CancelEventArgs{
- EventArgs: EventArgs{
- sender: sender,
- },
- }
-}
-
-func (a *CancelEventArgs) Canceled() bool {
- return a.canceled
-}
-
-func (a *CancelEventArgs) SetCanceled(value bool) {
- a.canceled = value
-}
-
-type CancelEventHandler func(args *CancelEventArgs)
+type CancelEventHandler func(canceled *bool)
type CancelEvent struct {
handlers []CancelEventHandler
}
-func (e *CancelEvent) Subscribe(handler CancelEventHandler) {
+func (e *CancelEvent) Attach(handler CancelEventHandler) {
e.handlers = append(e.handlers, handler)
}
-func (e *CancelEvent) Unsubscribe(handler CancelEventHandler) {
+func (e *CancelEvent) Detach(handler CancelEventHandler) {
for i, h := range e.handlers {
if h == handler {
e.handlers = append(e.handlers[:i], e.handlers[i+1:]...)
@@ -52,8 +31,8 @@ func (p *CancelEventPublisher) Event() *CancelEvent {
return &p.event
}
-func (p *CancelEventPublisher) Publish(args *CancelEventArgs) {
+func (p *CancelEventPublisher) Publish(canceled *bool) {
for _, handler := range p.event.handlers {
- handler(args)
+ handler(canceled)
}
}
View
30 src/pkg/walk/gui/closeevent.go
@@ -4,37 +4,17 @@
package gui
-type CloseEventArgs struct {
- CancelEventArgs
- reason CloseReason
-}
-
-func NewCloseEventArgs(sender interface{}, reason CloseReason) *CloseEventArgs {
- return &CloseEventArgs{
- CancelEventArgs: CancelEventArgs{
- EventArgs: EventArgs{
- sender: sender,
- },
- },
- reason: reason,
- }
-}
-
-func (a *CloseEventArgs) Reason() CloseReason {
- return a.reason
-}
-
-type CloseEventHandler func(args *CloseEventArgs)
+type CloseEventHandler func(canceled *bool, reason CloseReason)
type CloseEvent struct {
handlers []CloseEventHandler
}
-func (e *CloseEvent) Subscribe(handler CloseEventHandler) {
+func (e *CloseEvent) Attach(handler CloseEventHandler) {
e.handlers = append(e.handlers, handler)
}
-func (e *CloseEvent) Unsubscribe(handler CloseEventHandler) {
+func (e *CloseEvent) Detach(handler CloseEventHandler) {
for i, h := range e.handlers {
if h == handler {
e.handlers = append(e.handlers[:i], e.handlers[i+1:]...)
@@ -51,8 +31,8 @@ func (p *CloseEventPublisher) Event() *CloseEvent {
return &p.event
}
-func (p *CloseEventPublisher) Publish(args *CloseEventArgs) {
+func (p *CloseEventPublisher) Publish(canceled *bool, reason CloseReason) {
for _, handler := range p.event.handlers {
- handler(args)
+ handler(canceled, reason)
}
}
View
2  src/pkg/walk/gui/combobox.go
@@ -95,7 +95,7 @@ func (cb *ComboBox) wndProc(hwnd HWND, msg uint, wParam, lParam uintptr, origWnd
switch HIWORD(uint(wParam)) {
case CBN_SELENDOK:
if selIndex := cb.SelectedIndex(); selIndex != cb.prevSelIndex {
- cb.selectedIndexChangedPublisher.Publish(NewEventArgs(cb))
+ cb.selectedIndexChangedPublisher.Publish()
cb.prevSelIndex = selIndex
return 0
}
View
24 src/pkg/walk/gui/event.go
@@ -4,31 +4,17 @@
package gui
-type EventArgs struct {
- sender interface{}
-}
-
-func NewEventArgs(sender interface{}) *EventArgs {
- return &EventArgs{
- sender: sender,
- }
-}
-
-func (a *EventArgs) Sender() interface{} {
- return a.sender
-}
-
-type EventHandler func(args *EventArgs)
+type EventHandler func()
type Event struct {
handlers []EventHandler
}
-func (e *Event) Subscribe(handler EventHandler) {
+func (e *Event) Attach(handler EventHandler) {
e.handlers = append(e.handlers, handler)
}
-func (e *Event) Unsubscribe(handler EventHandler) {
+func (e *Event) Detach(handler EventHandler) {
for i, h := range e.handlers {
if h == handler {
e.handlers = append(e.handlers[:i], e.handlers[i+1:]...)
@@ -45,8 +31,8 @@ func (p *EventPublisher) Event() *Event {
return &p.event
}
-func (p *EventPublisher) Publish(args *EventArgs) {
+func (p *EventPublisher) Publish() {
for _, handler := range p.event.handlers {
- handler(args)
+ handler()
}
}
View
28 src/pkg/walk/gui/keyevent.go
@@ -4,35 +4,17 @@
package gui
-type KeyEventArgs struct {
- EventArgs
- key int
-}
-
-func NewKeyEventArgs(sender interface{}, key int) *KeyEventArgs {
- return &KeyEventArgs{
- EventArgs: EventArgs{
- sender: sender,
- },
- key: key,
- }
-}
-
-func (a *KeyEventArgs) Key() int {
- return a.key
-}
-
-type KeyEventHandler func(args *KeyEventArgs)
+type KeyEventHandler func(key int)
type KeyEvent struct {
handlers []KeyEventHandler
}
-func (e *KeyEvent) Subscribe(handler KeyEventHandler) {
+func (e *KeyEvent) Attach(handler KeyEventHandler) {
e.handlers = append(e.handlers, handler)
}
-func (e *KeyEvent) Unsubscribe(handler KeyEventHandler) {
+func (e *KeyEvent) Detach(handler KeyEventHandler) {
for i, h := range e.handlers {
if h == handler {
e.handlers = append(e.handlers[:i], e.handlers[i+1:]...)
@@ -49,8 +31,8 @@ func (p *KeyEventPublisher) Event() *KeyEvent {
return &p.event
}
-func (p *KeyEventPublisher) Publish(args *KeyEventArgs) {
+func (p *KeyEventPublisher) Publish(key int) {
for _, handler := range p.event.handlers {
- handler(args)
+ handler(key)
}
}
View
8 src/pkg/walk/gui/listview.go
@@ -142,7 +142,7 @@ func (lv *ListView) SetSelectedIndex(value int) os.Error {
lv.selectedIndex = value
if value == -1 {
- lv.selectedIndexChangedPublisher.Publish(NewEventArgs(lv))
+ lv.selectedIndexChangedPublisher.Publish()
}
return nil
@@ -253,7 +253,7 @@ func (lv *ListView) wndProc(hwnd HWND, msg uint, wParam, lParam uintptr, origWnd
case WM_KEYDOWN:
if wParam == VK_RETURN && lv.SelectedIndex() > -1 {
- lv.itemActivatedPublisher.Publish(NewEventArgs(lv))
+ lv.itemActivatedPublisher.Publish()
}
case WM_NOTIFY:
@@ -264,11 +264,11 @@ func (lv *ListView) wndProc(hwnd HWND, msg uint, wParam, lParam uintptr, origWnd
selectedBefore := nmlv.UOldState&LVIS_SELECTED > 0
if selectedNow && !selectedBefore {
lv.selectedIndex = nmlv.IItem
- lv.selectedIndexChangedPublisher.Publish(NewEventArgs(lv))
+ lv.selectedIndexChangedPublisher.Publish()
}
case LVN_ITEMACTIVATE:
- lv.itemActivatedPublisher.Publish(NewEventArgs(lv))
+ lv.itemActivatedPublisher.Publish()
}
}
View
40 src/pkg/walk/gui/mouseevent.go
@@ -12,47 +12,17 @@ const (
MiddleButton
)
-type MouseEventArgs struct {
- EventArgs
- x int
- y int
- button MouseButton
-}
-
-func NewMouseEventArgs(sender interface{}, x, y int, button MouseButton) *MouseEventArgs {
- return &MouseEventArgs{
- EventArgs: EventArgs{
- sender: sender,
- },
- x: x,
- y: y,
- button: button,
- }
-}
-
-func (a *MouseEventArgs) X() int {
- return a.x
-}
-
-func (a *MouseEventArgs) Y() int {
- return a.y
-}
-
-func (a *MouseEventArgs) Button() MouseButton {
- return a.button
-}
-
-type MouseEventHandler func(args *MouseEventArgs)
+type MouseEventHandler func(x, y int, button MouseButton)
type MouseEvent struct {
handlers []MouseEventHandler
}
-func (e *MouseEvent) Subscribe(handler MouseEventHandler) {
+func (e *MouseEvent) Attach(handler MouseEventHandler) {
e.handlers = append(e.handlers, handler)
}
-func (e *MouseEvent) Unsubscribe(handler MouseEventHandler) {
+func (e *MouseEvent) Detach(handler MouseEventHandler) {
for i, h := range e.handlers {
if h == handler {
e.handlers = append(e.handlers[:i], e.handlers[i+1:]...)
@@ -69,8 +39,8 @@ func (p *MouseEventPublisher) Event() *MouseEvent {
return &p.event
}
-func (p *MouseEventPublisher) Publish(args *MouseEventArgs) {
+func (p *MouseEventPublisher) Publish(x, y int, button MouseButton) {
for _, handler := range p.event.handlers {
- handler(args)
+ handler(x, y, button)
}
}
View
16 src/pkg/walk/gui/splitter.go
@@ -163,12 +163,12 @@ func (s *Splitter) onInsertedWidget(index int, widget IWidget) (err os.Error) {
err = s.children.Insert(handleIndex, handle)
if err == nil {
// FIXME: These handlers will be leaked, if widgets get removed.
- handle.MouseDown().Subscribe(func(args *MouseEventArgs) {
+ handle.MouseDown().Attach(func(x, y int, button MouseButton) {
s.draggedHandle = handle
- s.mouseDownPos = drawing.Point{args.X(), args.Y()}
+ s.mouseDownPos = drawing.Point{x, y}
})
- handle.MouseMove().Subscribe(func(args *MouseEventArgs) {
+ handle.MouseMove().Attach(func(x, y int, button MouseButton) {
if s.draggedHandle == nil {
return
}
@@ -190,15 +190,13 @@ func (s *Splitter) onInsertedWidget(index int, widget IWidget) (err os.Error) {
}
if s.Orientation() == Horizontal {
- xm := args.X()
-
xh, e := s.draggedHandle.X()
if e != nil {
log.Println(e)
return
}
- xnew := xh + xm - s.mouseDownPos.X
+ xnew := xh + x - s.mouseDownPos.X
if xnew < bp.X {
xnew = bp.X
} else if xnew >= bn.X+bn.Width-s.handleWidth {
@@ -210,15 +208,13 @@ func (s *Splitter) onInsertedWidget(index int, widget IWidget) (err os.Error) {
return
}
} else {
- ym := args.Y()
-
yh, e := s.draggedHandle.Y()
if e != nil {
log.Println(e)
return
}
- ynew := yh + ym - s.mouseDownPos.Y
+ ynew := yh + y - s.mouseDownPos.Y
if ynew < bp.Y {
ynew = bp.Y
} else if ynew >= bn.Y+bn.Height-s.handleWidth {
@@ -232,7 +228,7 @@ func (s *Splitter) onInsertedWidget(index int, widget IWidget) (err os.Error) {
}
})
- handle.MouseUp().Subscribe(func(args *MouseEventArgs) {
+ handle.MouseUp().Attach(func(x, y int, button MouseButton) {
if s.draggedHandle != nil {
dragHandle := s.draggedHandle
s.draggedHandle = nil
View
2  src/pkg/walk/gui/tabwidget.go
@@ -244,7 +244,7 @@ func (tw *TabWidget) onSelChange() {
tw.curPage.Invalidate()
}
- tw.currentPageChangedPublisher.Publish(NewEventArgs(tw))
+ tw.currentPageChangedPublisher.Publish()
}
func (tw *TabWidget) wndProc(hwnd HWND, msg uint, wParam, lParam uintptr, origWndProcPtr uintptr) uintptr {
View
6 src/pkg/walk/gui/toplevelwindow.go
@@ -174,10 +174,10 @@ func (tlw *TopLevelWindow) wndProc(hwnd HWND, msg uint, wParam, lParam uintptr,
return 0
case WM_CLOSE:
- args := NewCloseEventArgs(widgetsByHWnd[tlw.hWnd], tlw.closeReason)
tlw.closeReason = CloseReasonUnknown
- tlw.closingPublisher.Publish(args)
- if !args.Canceled() {
+ var canceled bool
+ tlw.closingPublisher.Publish(&canceled, tlw.closeReason)
+ if !canceled {
if tlw.owner != nil {
tlw.owner.SetEnabled(true)
}
View
12 src/pkg/walk/gui/treeview.go
@@ -104,12 +104,12 @@ func (tv *TreeView) wndProc(hwnd HWND, msg uint, wParam, lParam uintptr, origWnd
switch nmtv.Action {
case TVE_COLLAPSE:
- tv.itemCollapsedPublisher.Publish(NewTreeViewItemEventArgs(tv, item))
+ tv.itemCollapsedPublisher.Publish(item)
case TVE_COLLAPSERESET:
case TVE_EXPAND:
- tv.itemExpandedPublisher.Publish(NewTreeViewItemEventArgs(tv, item))
+ tv.itemExpandedPublisher.Publish(item)
case TVE_EXPANDPARTIAL:
@@ -121,12 +121,12 @@ func (tv *TreeView) wndProc(hwnd HWND, msg uint, wParam, lParam uintptr, origWnd
switch nmtv.Action {
case TVE_COLLAPSE:
- tv.itemCollapsingPublisher.Publish(NewTreeViewItemEventArgs(tv, item))
+ tv.itemCollapsingPublisher.Publish(item)
case TVE_COLLAPSERESET:
case TVE_EXPAND:
- tv.itemExpandingPublisher.Publish(NewTreeViewItemEventArgs(tv, item))
+ tv.itemExpandingPublisher.Publish(item)
case TVE_EXPANDPARTIAL:
@@ -136,12 +136,12 @@ func (tv *TreeView) wndProc(hwnd HWND, msg uint, wParam, lParam uintptr, origWnd
case TVN_SELCHANGED:
old := (*TreeViewItem)(unsafe.Pointer(nmtv.ItemOld.LParam))
new := (*TreeViewItem)(unsafe.Pointer(nmtv.ItemNew.LParam))
- tv.selectionChangedPublisher.Publish(NewTreeViewItemSelectionEventArgs(tv, old, new))
+ tv.selectionChangedPublisher.Publish(old, new)
case TVN_SELCHANGING:
old := (*TreeViewItem)(unsafe.Pointer(nmtv.ItemOld.LParam))
new := (*TreeViewItem)(unsafe.Pointer(nmtv.ItemNew.LParam))
- tv.selectionChangingPublisher.Publish(NewTreeViewItemSelectionEventArgs(tv, old, new))
+ tv.selectionChangingPublisher.Publish(old, new)
}
}
View
28 src/pkg/walk/gui/treeviewitemevent.go
@@ -4,35 +4,17 @@
package gui
-type TreeViewItemEventArgs struct {
- EventArgs
- item *TreeViewItem
-}
-
-func NewTreeViewItemEventArgs(sender interface{}, item *TreeViewItem) *TreeViewItemEventArgs {
- return &TreeViewItemEventArgs{
- EventArgs: EventArgs{
- sender: sender,
- },
- item: item,
- }
-}
-
-func (a *TreeViewItemEventArgs) Item() *TreeViewItem {
- return a.item
-}
-
-type TreeViewItemEventHandler func(args *TreeViewItemEventArgs)
+type TreeViewItemEventHandler func(item *TreeViewItem)
type TreeViewItemEvent struct {
handlers []TreeViewItemEventHandler
}
-func (e *TreeViewItemEvent) Subscribe(handler TreeViewItemEventHandler) {
+func (e *TreeViewItemEvent) Attach(handler TreeViewItemEventHandler) {
e.handlers = append(e.handlers, handler)
}
-func (e *TreeViewItemEvent) Unsubscribe(handler TreeViewItemEventHandler) {
+func (e *TreeViewItemEvent) Detach(handler TreeViewItemEventHandler) {
for i, h := range e.handlers {
if h == handler {
e.handlers = append(e.handlers[:i], e.handlers[i+1:]...)
@@ -49,8 +31,8 @@ func (p *TreeViewItemEventPublisher) Event() *TreeViewItemEvent {
return &p.event
}
-func (p *TreeViewItemEventPublisher) Publish(args *TreeViewItemEventArgs) {
+func (p *TreeViewItemEventPublisher) Publish(item *TreeViewItem) {
for _, handler := range p.event.handlers {
- handler(args)
+ handler(item)
}
}
View
34 src/pkg/walk/gui/treeviewitemselectionevent.go
@@ -4,41 +4,17 @@
package gui
-type TreeViewItemSelectionEventArgs struct {
- EventArgs
- old *TreeViewItem
- new *TreeViewItem
-}
-
-func NewTreeViewItemSelectionEventArgs(sender interface{}, old, new *TreeViewItem) *TreeViewItemSelectionEventArgs {
- return &TreeViewItemSelectionEventArgs{
- EventArgs: EventArgs{
- sender: sender,
- },
- old: old,
- new: new,
- }
-}
-
-func (a *TreeViewItemSelectionEventArgs) Old() *TreeViewItem {
- return a.old
-}
-
-func (a *TreeViewItemSelectionEventArgs) New() *TreeViewItem {
- return a.new
-}
-
-type TreeViewItemSelectionEventHandler func(args *TreeViewItemSelectionEventArgs)
+type TreeViewItemSelectionEventHandler func(old, new *TreeViewItem)
type TreeViewItemSelectionEvent struct {
handlers []TreeViewItemSelectionEventHandler
}
-func (e *TreeViewItemSelectionEvent) Subscribe(handler TreeViewItemSelectionEventHandler) {
+func (e *TreeViewItemSelectionEvent) Attach(handler TreeViewItemSelectionEventHandler) {
e.handlers = append(e.handlers, handler)
}
-func (e *TreeViewItemSelectionEvent) Unsubscribe(handler TreeViewItemSelectionEventHandler) {
+func (e *TreeViewItemSelectionEvent) Detach(handler TreeViewItemSelectionEventHandler) {
for i, h := range e.handlers {
if h == handler {
e.handlers = append(e.handlers[:i], e.handlers[i+1:]...)
@@ -55,8 +31,8 @@ func (p *TreeViewItemSelectionEventPublisher) Event() *TreeViewItemSelectionEven
return &p.event
}
-func (p *TreeViewItemSelectionEventPublisher) Publish(args *TreeViewItemSelectionEventArgs) {
+func (p *TreeViewItemSelectionEventPublisher) Publish(old, new *TreeViewItem) {
for _, handler := range p.event.handlers {
- handler(args)
+ handler(old, new)
}
}
View
14 src/pkg/walk/gui/widget.go
@@ -675,11 +675,11 @@ func (w *Widget) MouseUp() *MouseEvent {
return w.mouseUpPublisher.Event()
}
-func (w *Widget) mouseEventArgsFromMSG(wParam, lParam uintptr) *MouseEventArgs {
+func (w *Widget) publishMouseEvent(publisher *MouseEventPublisher, wParam, lParam uintptr) {
x := int(GET_X_LPARAM(lParam))
y := int(GET_Y_LPARAM(lParam))
- return NewMouseEventArgs(widgetsByHWnd[w.hWnd], x, y, 0)
+ publisher.Publish(x, y, 0)
}
func (w *Widget) SizeChanged() *Event {
@@ -728,16 +728,16 @@ func (w *Widget) wndProc(hwnd HWND, msg uint, wParam, lParam uintptr, origWndPro
switch msg {
case WM_LBUTTONDOWN:
SetCapture(w.hWnd)
- w.mouseDownPublisher.Publish(w.mouseEventArgsFromMSG(wParam, lParam))
+ w.publishMouseEvent(&w.mouseDownPublisher, wParam, lParam)
case WM_LBUTTONUP:
if !ReleaseCapture() {
log.Println(lastError("ReleaseCapture"))
}
- w.mouseUpPublisher.Publish(w.mouseEventArgsFromMSG(wParam, lParam))
+ w.publishMouseEvent(&w.mouseUpPublisher, wParam, lParam)
case WM_MOUSEMOVE:
- w.mouseMovePublisher.Publish(w.mouseEventArgsFromMSG(wParam, lParam))
+ w.publishMouseEvent(&w.mouseUpPublisher, wParam, lParam)
case WM_SETCURSOR:
if w.cursor != nil {
@@ -762,10 +762,10 @@ func (w *Widget) wndProc(hwnd HWND, msg uint, wParam, lParam uintptr, origWndPro
return 0
case WM_KEYDOWN:
- w.keyDownPublisher.Publish(NewKeyEventArgs(widgetsByHWnd[w.hWnd], int(wParam)))
+ w.keyDownPublisher.Publish(int(wParam))
case WM_SIZE, WM_SIZING:
- w.sizeChangedPublisher.Publish(NewEventArgs(widgetsByHWnd[w.hWnd]))
+ w.sizeChangedPublisher.Publish()
case WM_GETMINMAXINFO:
mmi := (*MINMAXINFO)(unsafe.Pointer(lParam))
Please sign in to comment.
Something went wrong with that request. Please try again.