-
Notifications
You must be signed in to change notification settings - Fork 30
/
wndproc.go
145 lines (125 loc) · 4.28 KB
/
wndproc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* Copyright (C) 2019 The Winc Authors. All Rights Reserved.
* Copyright (C) 2010-2013 Allen Dang. All Rights Reserved.
*/
package winc
import (
"unsafe"
"github.com/tadvi/winc/w32"
)
func genPoint(p uintptr) (x, y int) {
x = int(w32.LOWORD(uint32(p)))
y = int(w32.HIWORD(uint32(p)))
return
}
func genMouseEventArg(wparam, lparam uintptr) *MouseEventData {
var data MouseEventData
data.Button = int(wparam)
data.X, data.Y = genPoint(lparam)
return &data
}
func genDropFilesEventArg(wparam uintptr) *DropFilesEventData {
hDrop := w32.HDROP(wparam)
var data DropFilesEventData
_, fileCount := w32.DragQueryFile(hDrop, 0xFFFFFFFF)
data.Files = make([]string, fileCount)
var i uint
for i = 0; i < fileCount; i++ {
data.Files[i], _ = w32.DragQueryFile(hDrop, i)
}
data.X, data.Y, _ = w32.DragQueryPoint(hDrop)
w32.DragFinish(hDrop)
return &data
}
func generalWndProc(hwnd w32.HWND, msg uint32, wparam, lparam uintptr) uintptr {
switch msg {
case w32.WM_HSCROLL:
//println("case w32.WM_HSCROLL")
case w32.WM_VSCROLL:
//println("case w32.WM_VSCROLL")
}
if controller := GetMsgHandler(hwnd); controller != nil {
ret := controller.WndProc(msg, wparam, lparam)
switch msg {
case w32.WM_NOTIFY: //Reflect notification to control
nm := (*w32.NMHDR)(unsafe.Pointer(lparam))
if controller := GetMsgHandler(nm.HwndFrom); controller != nil {
ret := controller.WndProc(msg, wparam, lparam)
if ret != 0 {
w32.SetWindowLong(hwnd, w32.DWL_MSGRESULT, uint32(ret))
return w32.TRUE
}
}
case w32.WM_COMMAND:
if lparam != 0 { //Reflect message to control
h := w32.HWND(lparam)
if controller := GetMsgHandler(h); controller != nil {
ret := controller.WndProc(msg, wparam, lparam)
if ret != 0 {
w32.SetWindowLong(hwnd, w32.DWL_MSGRESULT, uint32(ret))
return w32.TRUE
}
}
}
case w32.WM_CLOSE:
controller.OnClose().Fire(NewEvent(controller, nil))
case w32.WM_KILLFOCUS:
controller.OnKillFocus().Fire(NewEvent(controller, nil))
case w32.WM_SETFOCUS:
controller.OnSetFocus().Fire(NewEvent(controller, nil))
case w32.WM_DROPFILES:
controller.OnDropFiles().Fire(NewEvent(controller, genDropFilesEventArg(wparam)))
case w32.WM_CONTEXTMENU:
if wparam != 0 { //Reflect message to control
h := w32.HWND(wparam)
if controller := GetMsgHandler(h); controller != nil {
contextMenu := controller.ContextMenu()
x, y := genPoint(lparam)
if contextMenu != nil {
id := w32.TrackPopupMenuEx(
contextMenu.hMenu,
w32.TPM_NOANIMATION|w32.TPM_RETURNCMD,
int32(x),
int32(y),
controller.Handle(),
nil)
item := findMenuItemByID(int(id))
if item != nil {
item.OnClick().Fire(NewEvent(controller, genMouseEventArg(wparam, lparam)))
}
return 0
}
}
}
case w32.WM_LBUTTONDOWN:
controller.OnLBDown().Fire(NewEvent(controller, genMouseEventArg(wparam, lparam)))
case w32.WM_LBUTTONUP:
controller.OnLBUp().Fire(NewEvent(controller, genMouseEventArg(wparam, lparam)))
case w32.WM_LBUTTONDBLCLK:
controller.OnLBDbl().Fire(NewEvent(controller, genMouseEventArg(wparam, lparam)))
case w32.WM_MBUTTONDOWN:
controller.OnMBDown().Fire(NewEvent(controller, genMouseEventArg(wparam, lparam)))
case w32.WM_MBUTTONUP:
controller.OnMBUp().Fire(NewEvent(controller, genMouseEventArg(wparam, lparam)))
case w32.WM_RBUTTONDOWN:
controller.OnRBDown().Fire(NewEvent(controller, genMouseEventArg(wparam, lparam)))
case w32.WM_RBUTTONUP:
controller.OnRBUp().Fire(NewEvent(controller, genMouseEventArg(wparam, lparam)))
case w32.WM_RBUTTONDBLCLK:
controller.OnRBDbl().Fire(NewEvent(controller, genMouseEventArg(wparam, lparam)))
case w32.WM_MOUSEMOVE:
controller.OnMouseMove().Fire(NewEvent(controller, genMouseEventArg(wparam, lparam)))
case w32.WM_PAINT:
canvas := NewCanvasFromHwnd(hwnd)
defer canvas.Dispose()
controller.OnPaint().Fire(NewEvent(controller, &PaintEventData{Canvas: canvas}))
case w32.WM_KEYUP:
controller.OnKeyUp().Fire(NewEvent(controller, &KeyUpEventData{int(wparam), int(lparam)}))
case w32.WM_SIZE:
x, y := genPoint(lparam)
controller.OnSize().Fire(NewEvent(controller, &SizeEventData{uint(wparam), x, y}))
}
return ret
}
return w32.DefWindowProc(hwnd, uint32(msg), wparam, lparam)
}