forked from tadvi/winc
/
resizer.go
214 lines (169 loc) · 4.12 KB
/
resizer.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
* Copyright (C) 2019 The Winc Authors. All Rights Reserved.
*/
package winc
import (
"github.com/leaanthony/winc/w32"
)
type VResizer struct {
ControlBase
control1 Dockable
control2 Dockable
dir Direction
mouseLeft bool
drag bool
}
func NewVResizer(parent Controller) *VResizer {
sp := new(VResizer)
RegClassOnlyOnce("winc_VResizer")
sp.hwnd = CreateWindow("winc_VResizer", parent, w32.WS_EX_CONTROLPARENT, w32.WS_CHILD|w32.WS_VISIBLE)
sp.parent = parent
sp.mouseLeft = true
RegMsgHandler(sp)
sp.SetFont(DefaultFont)
sp.SetText("")
sp.SetSize(20, 100)
return sp
}
func (sp *VResizer) SetControl(control1, control2 Dockable, dir Direction, minSize int) {
sp.control1 = control1
sp.control2 = control2
if dir != Left && dir != Right {
panic("invalid direction")
}
sp.dir = dir
// TODO(vi): ADDED
/*internalTrackMouseEvent(control1.Handle())
internalTrackMouseEvent(control2.Handle())
control1.OnMouseMove().Bind(func(e *Event) {
if sp.drag {
x := e.Data.(*MouseEventData).X
sp.update(x)
w32.SetCursor(w32.LoadCursor(0, w32.MakeIntResource(w32.IDC_SIZEWE)))
}
fmt.Println("control1.OnMouseMove")
})
control2.OnMouseMove().Bind(func(e *Event) {
if sp.drag {
x := e.Data.(*MouseEventData).X
sp.update(x)
w32.SetCursor(w32.LoadCursor(0, w32.MakeIntResource(w32.IDC_SIZEWE)))
}
fmt.Println("control2.OnMouseMove")
})
control1.OnLBUp().Bind(func(e *Event) {
sp.drag = false
sp.mouseLeft = true
fmt.Println("control1.OnLBUp")
})
control2.OnLBUp().Bind(func(e *Event) {
sp.drag = false
sp.mouseLeft = true
fmt.Println("control2.OnLBUp")
})*/
// ---- finish ADDED
}
func (sp *VResizer) update(x int) {
pos := x - 10
w1, h1 := sp.control1.Width(), sp.control1.Height()
if sp.dir == Left {
w1 += pos
} else {
w1 -= pos
}
sp.control1.SetSize(w1, h1)
fm := sp.parent.(*Form)
fm.UpdateLayout()
w32.SetCursor(w32.LoadCursor(0, w32.MakeIntResource(w32.IDC_ARROW)))
}
func (sp *VResizer) WndProc(msg uint32, wparam, lparam uintptr) uintptr {
switch msg {
case w32.WM_CREATE:
internalTrackMouseEvent(sp.hwnd)
case w32.WM_MOUSEMOVE:
if sp.drag {
x, _ := genPoint(lparam)
sp.update(x)
} else {
w32.SetCursor(w32.LoadCursor(0, w32.MakeIntResource(w32.IDC_SIZEWE)))
}
if sp.mouseLeft {
internalTrackMouseEvent(sp.hwnd)
sp.mouseLeft = false
}
case w32.WM_MOUSELEAVE:
sp.drag = false
sp.mouseLeft = true
case w32.WM_LBUTTONUP:
sp.drag = false
case w32.WM_LBUTTONDOWN:
sp.drag = true
}
return w32.DefWindowProc(sp.hwnd, msg, wparam, lparam)
}
type HResizer struct {
ControlBase
control1 Dockable
control2 Dockable
dir Direction
mouseLeft bool
drag bool
}
func NewHResizer(parent Controller) *HResizer {
sp := new(HResizer)
RegClassOnlyOnce("winc_HResizer")
sp.hwnd = CreateWindow("winc_HResizer", parent, w32.WS_EX_CONTROLPARENT, w32.WS_CHILD|w32.WS_VISIBLE)
sp.parent = parent
sp.mouseLeft = true
RegMsgHandler(sp)
sp.SetFont(DefaultFont)
sp.SetText("")
sp.SetSize(100, 20)
return sp
}
func (sp *HResizer) SetControl(control1, control2 Dockable, dir Direction, minSize int) {
sp.control1 = control1
sp.control2 = control2
if dir != Top && dir != Bottom {
panic("invalid direction")
}
sp.dir = dir
}
func (sp *HResizer) update(y int) {
pos := y - 10
w1, h1 := sp.control1.Width(), sp.control1.Height()
if sp.dir == Top {
h1 += pos
} else {
h1 -= pos
}
sp.control1.SetSize(w1, h1)
fm := sp.parent.(*Form)
fm.UpdateLayout()
w32.SetCursor(w32.LoadCursor(0, w32.MakeIntResource(w32.IDC_ARROW)))
}
func (sp *HResizer) WndProc(msg uint32, wparam, lparam uintptr) uintptr {
switch msg {
case w32.WM_CREATE:
internalTrackMouseEvent(sp.hwnd)
case w32.WM_MOUSEMOVE:
if sp.drag {
_, y := genPoint(lparam)
sp.update(y)
} else {
w32.SetCursor(w32.LoadCursor(0, w32.MakeIntResource(w32.IDC_SIZENS)))
}
if sp.mouseLeft {
internalTrackMouseEvent(sp.hwnd)
sp.mouseLeft = false
}
case w32.WM_MOUSELEAVE:
sp.drag = false
sp.mouseLeft = true
case w32.WM_LBUTTONUP:
sp.drag = false
case w32.WM_LBUTTONDOWN:
sp.drag = true
}
return w32.DefWindowProc(sp.hwnd, msg, wparam, lparam)
}