-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathany_variants.go
234 lines (205 loc) · 5.78 KB
/
any_variants.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package wingo
import (
"unsafe"
"github.com/rogeecn/wingo/co"
)
type (
// An interface which accepts a string or a nil value.
//
// Example:
//
// func Foo(s win.StrOrNil) {}
//
// Foo(win.StrVal("some text"))
// Foo(nil)
StrOrNil interface{ isStrOrNil() }
StrVal string // A string value for StrOrNil interface.
)
func (StrVal) isStrOrNil() {}
func variantStrOrNil(v StrOrNil) unsafe.Pointer {
if v != nil {
s := v.(StrVal)
return unsafe.Pointer(Str.ToNativePtr(string(s)))
}
return nil
}
//------------------------------------------------------------------------------
type (
// A window class name identifier.
//
// Example:
//
// func Foo(cn win.ClassName) {}
//
// Foo(ClassNameAtom(ATOM(100)))
// Foo(ClassNameStr("MY_CLASS_NAME"))
// Foo(nil)
ClassName interface{ isClassName() }
ClassNameAtom ATOM // An atom window class name identifier for ClassName interface.
ClassNameStr string // A string window class name identifier for ClassName interface.
)
func (ClassNameAtom) isClassName() {}
func (ClassNameStr) isClassName() {}
func variantClassName(v ClassName) (uintptr, *uint16) { // pointer must be kept alive
var buf *uint16
switch v := v.(type) {
case ClassNameAtom:
return uintptr(v), nil
case ClassNameStr:
buf = Str.ToNativePtr(string(v))
return uintptr(unsafe.Pointer(buf)), buf
default:
return 0, nil
}
}
//------------------------------------------------------------------------------
type (
// A cursor resource identifier.
//
// Example:
//
// func Foo(c win.CursorRes) {}
//
// Foo(win.CursorResIdc(co.IDC_ARROW))
// Foo(win.CursorResInt(301))
// Foo(win.CursorResStr("MY_CURSOR"))
CursorRes interface{ isCursorRes() }
CursorResIdc co.IDC // A co.IDC cursor resource identifier for CursorResId interface.
CursorResInt uint16 // A number cursor resource identifier for CursorResId interface.
CursorResStr string // A string cursor resource identifier for CursorResId interface.
)
func (CursorResIdc) isCursorRes() {}
func (CursorResInt) isCursorRes() {}
func (CursorResStr) isCursorRes() {}
func variantCursorResId(v CursorRes) (uintptr, *uint16) { // pointer must be kept alive
var buf *uint16
switch v := v.(type) {
case CursorResIdc:
return uintptr(v), nil
case CursorResInt:
return uintptr(v), nil
case CursorResStr:
buf = Str.ToNativePtr(string(v))
return uintptr(unsafe.Pointer(buf)), buf
default:
panic("CursorResId does not accept a nil value.")
}
}
//------------------------------------------------------------------------------
type (
// An icon resource identifier.
//
// Example:
//
// func Foo(i win.IconRes) {}
//
// Foo(win.IconResIdc(co.IDI_ERROR))
// Foo(win.IconResInt(201))
// Foo(win.IconResStr("MY_ICON"))
IconRes interface{ isIconRes() }
IconResIdc co.IDI // A co.IDI icon resource identifier for IconResId interface.
IconResInt uint16 // A number icon resource identifier for IconResId interface.
IconResStr string // A string icon resource identifier for IconResId interface.
)
func (IconResIdc) isIconRes() {}
func (IconResInt) isIconRes() {}
func (IconResStr) isIconRes() {}
func variantIconResId(v IconRes) (uintptr, *uint16) { // pointer must be kept alive
var buf *uint16
switch v := v.(type) {
case IconResIdc:
return uintptr(v), nil
case IconResInt:
return uintptr(v), nil
case IconResStr:
buf = Str.ToNativePtr(string(v))
return uintptr(unsafe.Pointer(buf)), buf
default:
panic("CursorResId does not accept a nil value.")
}
}
//------------------------------------------------------------------------------
type (
// A menu item identifier.
//
// Example:
//
// func Foo(i win.MenuItem) {}
//
// Foo(win.MenuItemCmd(4001))
// Foo(win.MenuItemPos(2))
MenuItem interface{ isIdPos() }
MenuItemCmd uint16 // A command ID for MenuItem interface.
MenuItemPos uint16 // A zero-based index for MenuItem interface.
)
func (MenuItemCmd) isIdPos() {}
func (MenuItemPos) isIdPos() {}
func variantMenuItem(v MenuItem) (uintptr, co.MF) {
switch v := v.(type) {
case MenuItemCmd:
return uintptr(v), co.MF_BYCOMMAND
case MenuItemPos:
return uintptr(v), co.MF_BYPOSITION
default:
panic("MenuItem does not accept a nil value.")
}
}
//------------------------------------------------------------------------------
type (
// A resource identifier.
//
// Example:
//
// func Foo(r win.ResId) {}
//
// Foo(win.ResIdInt(101))
// Foo(win.ResIdStr("MY_RESOURCE"))
ResId interface{ isResId() }
ResIdInt uint16 // A number resource identifier for ResId interface.
ResIdStr string // A string resource identifier for ResId interface.
)
func (ResIdInt) isResId() {}
func (ResIdStr) isResId() {}
func variantResId(v ResId) (uintptr, *uint16) { // pointer must be kept alive
var buf *uint16
switch v := v.(type) {
case ResIdInt:
return uintptr(v), nil
case ResIdStr:
buf = Str.ToNativePtr(string(v))
return uintptr(unsafe.Pointer(buf)), buf
default:
panic("ResId does not accept a nil value.")
}
}
//------------------------------------------------------------------------------
type (
// Icon identifier for TASKDIALOGCONFIG.
//
// Example:
//
// func Foo(i win.TdcIcon) {}
//
// Foo(win.TdcIconHicon(win.HICON(0)))
// Foo(win.TdcIconInt(301))
// Foo(win.TdcIconTdi(co.TD_ICON_ERROR))
TdcIcon interface{ isTdcIcon() }
TdcIconHicon HICON // An HICON identifier for TdcIcon interface.
TdcIconInt uint16 // A number identifier for TdcIcon interface.
TdcIconTdi co.TD_ICON // A co.TD_ICON identifier for TdcIcon interface.
)
func (TdcIconHicon) isTdcIcon() {}
func (TdcIconInt) isTdcIcon() {}
func (TdcIconTdi) isTdcIcon() {}
func variantTdcIcon(v TdcIcon) uintptr {
switch v := v.(type) {
case TdcIconHicon:
return uintptr(v)
case TdcIconInt:
return uintptr(v)
case TdcIconTdi:
return uintptr(v)
default:
return 0
}
}