-
Notifications
You must be signed in to change notification settings - Fork 45
/
wndproc.go
110 lines (95 loc) · 3.4 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
package gform
import (
"github.com/AllenDang/w32"
"unsafe"
)
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 uint, wparam, lparam uintptr) uintptr {
if msg == w32.WM_INITDIALOG && gDialogWaiting != nil {
gDialogWaiting.hwnd = hwnd
RegMsgHandler(gDialogWaiting)
}
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(NewEventArg(controller, nil))
case w32.WM_KILLFOCUS:
controller.OnKillFocus().Fire(NewEventArg(controller, nil))
case w32.WM_SETFOCUS:
controller.OnSetFocus().Fire(NewEventArg(controller, nil))
case w32.WM_DROPFILES:
controller.OnDropFiles().Fire(NewEventArg(controller, genDropFilesEventArg(wparam)))
case w32.WM_LBUTTONDOWN:
controller.OnLBDown().Fire(NewEventArg(controller, genMouseEventArg(wparam, lparam)))
case w32.WM_LBUTTONUP:
controller.OnLBUp().Fire(NewEventArg(controller, genMouseEventArg(wparam, lparam)))
case w32.WM_MBUTTONDOWN:
controller.OnMBDown().Fire(NewEventArg(controller, genMouseEventArg(wparam, lparam)))
case w32.WM_MBUTTONUP:
controller.OnMBUp().Fire(NewEventArg(controller, genMouseEventArg(wparam, lparam)))
case w32.WM_RBUTTONDOWN:
controller.OnRBDown().Fire(NewEventArg(controller, genMouseEventArg(wparam, lparam)))
case w32.WM_RBUTTONUP:
controller.OnRBUp().Fire(NewEventArg(controller, genMouseEventArg(wparam, lparam)))
case w32.WM_PAINT:
canvas := NewCanvasFromHwnd(hwnd)
defer canvas.Dispose()
controller.OnPaint().Fire(NewEventArg(controller, &PaintEventData{Canvas: canvas}))
case w32.WM_KEYUP:
controller.OnKeyUp().Fire(NewEventArg(controller, &KeyUpEventData{int(wparam), int(lparam)}))
case w32.WM_SIZE:
x, y := genPoint(lparam)
controller.OnSize().Fire(NewEventArg(controller, &SizeEventData{uint(wparam), x, y}))
}
//Trigger msg handler registered via "Bind".
if handler, ok := controller.BindedHandler(msg); ok {
handler(NewEventArg(controller, &RawMsg{hwnd, msg, wparam, lparam}))
}
return ret
}
return w32.DefWindowProc(hwnd, uint32(msg), wparam, lparam)
}