/
bind_resources.go
350 lines (302 loc) · 12 KB
/
bind_resources.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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
package iup
import (
"image"
"image/draw"
"unsafe"
"github.com/google/uuid"
)
/*
#include <stdlib.h>
#include "iup.h"
static void Log(const char* type, const char* str) {
IupLog(type, "%s", str);
}
*/
import "C"
// Image creates an image to be shown on a label, button, toggle, or as a cursor.
//
// https://www.tecgraf.puc-rio.br/iup/en/elem/iupimage.html
func Image(width, height int, pixMap []byte) Ihandle {
h := mkih(C.IupImage(C.int(width), C.int(height), (*C.uchar)(unsafe.Pointer(&pixMap[0]))))
h.SetAttribute("UUID", uuid.NewString())
return h
}
// ImageRGB creates an image to be shown on a label, button, toggle, or as a cursor.
//
// https://www.tecgraf.puc-rio.br/iup/en/elem/iupimage.html
func ImageRGB(width, height int, pixMap []byte) Ihandle {
h := mkih(C.IupImageRGB(C.int(width), C.int(height), (*C.uchar)(unsafe.Pointer(&pixMap[0]))))
h.SetAttribute("UUID", uuid.NewString())
return h
}
// ImageRGBA creates an image to be shown on a label, button, toggle, or as a cursor.
//
// https://www.tecgraf.puc-rio.br/iup/en/elem/iupimage.html
func ImageRGBA(width, height int, pixMap []byte) Ihandle {
h := mkih(C.IupImageRGBA(C.int(width), C.int(height), (*C.uchar)(unsafe.Pointer(&pixMap[0]))))
h.SetAttribute("UUID", uuid.NewString())
return h
}
// ImageFromImage creates an image from image.Image.
func ImageFromImage(i image.Image) Ihandle {
if img, ok := i.(*image.RGBA); ok {
h := mkih(C.IupImageRGBA(C.int(img.Bounds().Dx()), C.int(img.Bounds().Dy()), (*C.uchar)(unsafe.Pointer(&img.Pix[0]))))
h.SetAttribute("UUID", uuid.NewString())
return h
}
b := i.Bounds()
dst := image.NewRGBA(image.Rect(0, 0, b.Dx(), b.Dy()))
draw.Draw(dst, dst.Bounds(), i, b.Min, draw.Src)
h := mkih(C.IupImageRGBA(C.int(dst.Bounds().Dx()), C.int(dst.Bounds().Dy()), (*C.uchar)(unsafe.Pointer(&dst.Pix[0]))))
h.SetAttribute("UUID", uuid.NewString())
return h
}
// NextField shifts the focus to the next element that can have the focus.
// It is relative to the given element and does not depend on the element currently with the focus.
//
// It will search for the next element first in the children, then in the brothers,
// then in the uncles and their children, and so on.
//
// This sequence is not the same sequence used by the Tab key, which is dependent on the native system.
//
// https://www.tecgraf.puc-rio.br/iup/en/func/iupnextfield.html
func NextField(ih Ihandle) Ihandle {
return mkih(C.IupNextField(ih.ptr()))
}
// PreviousField shifts the focus to the previous element that can have the focus.
// It is relative to the given element and does not depend on the element currently with the focus.
//
// https://www.tecgraf.puc-rio.br/iup/en/func/iuppreviousfield.html
func PreviousField(ih Ihandle) Ihandle {
return mkih(C.IupPreviousField(ih.ptr()))
}
// GetFocus returns the identifier of the interface element that has the keyboard focus, i.e. the element that will receive keyboard events.
//
// https://www.tecgraf.puc-rio.br/iup/en/func/iupgetfocus.html
func GetFocus() Ihandle {
return mkih(C.IupGetFocus())
}
// SetFocus sets the interface element that will receive the keyboard focus, i.e., the element that will receive keyboard events.
// But this will be processed only after the control actually receive the focus.
//
// https://www.tecgraf.puc-rio.br/iup/en/func/iupsetfocus.html
func SetFocus(ih Ihandle) Ihandle {
return mkih(C.IupSetFocus(ih.ptr()))
}
// Item creates an item of the menu interface element. When selected, it generates an action.
//
// https://www.tecgraf.puc-rio.br/iup/en/elem/iupitem.html
func Item(title string) Ihandle {
cTitle := C.CString(title)
defer C.free(unsafe.Pointer(cTitle))
h := mkih(C.IupItem(cTitle, nil))
h.SetAttribute("UUID", uuid.NewString())
return h
}
// Menu Creates a menu element, which groups 3 types of interface elements: item, submenu and separator.
// Any other interface element defined inside a menu will be an error.
//
// https://www.tecgraf.puc-rio.br/iup/en/elem/iupmenu.html
func Menu(children ...Ihandle) Ihandle {
children = append(children, Ihandle(0))
h := mkih(C.IupMenuv((**C.Ihandle)(unsafe.Pointer(&(children[0])))))
h.SetAttribute("UUID", uuid.NewString())
return h
}
// Separator creates the separator interface element. It shows a line between two menu items.
//
// https://www.tecgraf.puc-rio.br/iup/en/elem/iupseparator.html
func Separator() Ihandle {
h := mkih(C.IupSeparator())
h.SetAttribute("UUID", uuid.NewString())
return h
}
// Submenu creates a menu item that, when selected, opens another menu.
//
// https://www.tecgraf.puc-rio.br/iup/en/elem/iupsubmenu.html
func Submenu(title string, child Ihandle) Ihandle {
cTitle := C.CString(title)
defer C.free(unsafe.Pointer(cTitle))
h := mkih(C.IupSubmenu(cTitle, child.ptr()))
h.SetAttribute("UUID", uuid.NewString())
return h
}
// SetHandle associates a name with an interface element.
//
// https://www.tecgraf.puc-rio.br/iup/en/func/iupsethandle.html
func SetHandle(name string, ih Ihandle) Ihandle {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return mkih(C.IupSetHandle(cName, ih.ptr()))
}
// GetHandle returns the identifier of an interface element that has an associated name using SetHandle.
//
// https://www.tecgraf.puc-rio.br/iup/en/func/iupgethandle.html
func GetHandle(name string) Ihandle {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return mkih(C.IupGetHandle(cName))
}
// GetName Returns a name of an interface element, if the element has an associated name using SetHandle.
// Notice that a handle can have many names. GetName will return the last name set.
//
// https://www.tecgraf.puc-rio.br/iup/en/func/iupgetname.html
func GetName(ih Ihandle) string {
return C.GoString(C.IupGetName(ih.ptr()))
}
// GetAllNames returns the names of all interface elements that have an associated name using SetHandle.
//
// https://www.tecgraf.puc-rio.br/iup/en/func/iupgetallnames.html
func GetAllNames() (names []string) {
n := int(C.IupGetAllNames(nil, 0))
if n > 0 {
names = make([]string, n)
pNames := make([]*C.char, n)
C.IupGetAllNames((**C.char)(unsafe.Pointer(&pNames[0])), C.int(n))
for i := 0; i < n; i++ {
names[i] = C.GoString(pNames[i])
}
}
return
}
// GetAllDialogs returns the names of all dialogs that have an associated name using SetHandle.
// Other dialogs will not be returned.
//
// https://www.tecgraf.puc-rio.br/iup/en/func/iupgetalldialogs.html
func GetAllDialogs() (names []string) {
n := int(C.IupGetAllDialogs(nil, 0))
if n > 0 {
names = make([]string, n)
pNames := make([]*C.char, n)
C.IupGetAllDialogs((**C.char)(unsafe.Pointer(&pNames[0])), C.int(n))
for i := 0; i < n; i++ {
names[i] = C.GoString(pNames[i])
}
}
return
}
// SetLanguage sets the language name used by some pre-defined dialogs.
// Can also be changed using the global attribute LANGUAGE.
//
// https://www.tecgraf.puc-rio.br/iup/en/func/iupsetlanguage.html
func SetLanguage(lng string) {
cLng := C.CString(lng)
defer C.free(unsafe.Pointer(cLng))
C.IupSetLanguage(cLng)
}
// GetLanguage returns the language used by some pre-defined dialogs.
// Returns the same value as the LANGUAGE global attribute.
//
// https://www.tecgraf.puc-rio.br/iup/en/func/iupgetlanguage.html
func GetLanguage() string {
return C.GoString(C.IupGetLanguage())
}
// SetLanguageString associates a name with a string as an auxiliary method for Internationalization of applications.
//
// https://www.tecgraf.puc-rio.br/iup/en/func/iupsetlanguagestring.html
func SetLanguageString(name, str string) {
cName, cStr := C.CString(name), C.CString(str)
defer C.free(unsafe.Pointer(cName))
defer C.free(unsafe.Pointer(cStr))
C.IupStoreLanguageString(cName, cStr) //NOTE string always duplicated
}
// GetLanguageString returns a language dependent string.
// The string must have been associated with the name using the SetLanguageString or SetLanguagePack functions.
//
// https://www.tecgraf.puc-rio.br/iup/en/func/iupgetlanguagestring.html
func GetLanguageString(name string) string {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return C.GoString(C.IupGetLanguageString(cName))
}
// SetLanguagePack sets a pack of associations between names and string values.
// It is simply a User element with several attributes set.
// Internally will call SetLanguageString for each name in the pack.
//
// https://www.tecgraf.puc-rio.br/iup/en/func/iupsetlanguagepack.html
func SetLanguagePack(ih Ihandle) {
C.IupSetLanguagePack(ih.ptr())
}
// Clipboard creates an element that allows access to the clipboard.
// Each clipboard should be destroyed using Destroy,
// but you can use only one for the entire application because it does not store any data inside.
// Or you can simply create and destroy every time you need to copy or paste.
//
// https://www.tecgraf.puc-rio.br/iup/en/elem/iupclipboard.html
func Clipboard() Ihandle {
h := mkih(C.IupClipboard())
h.SetAttribute("UUID", uuid.NewString())
return h
}
// Timer creates a timer which periodically invokes a callback when the time is up.
// Each timer should be destroyed using Destroy.
//
// https://www.tecgraf.puc-rio.br/iup/en/elem/iuptimer.html
func Timer() Ihandle {
h := mkih(C.IupTimer())
h.SetAttribute("UUID", uuid.NewString())
return h
}
// Thread creates a thread element in IUP, which is not associated to any interface element.
// It is a very simple support to create and manage threads in a multithreading environment.
//
// https://www.tecgraf.puc-rio.br/iup/en/elem/iupthread.html
func Thread() Ihandle {
h := mkih(C.IupThread())
h.SetAttribute("UUID", uuid.NewString())
return h
}
// User creates a user element in IUP, which is not associated to any interface element.
// It is used to map an external element to a IUP element.
// Its use is usually for additional elements, but you can use it to create an Ihandle to store private attributes.
//
// It is also a void container. Its children can be dynamically added using Append or Insert.
//
// https://www.tecgraf.puc-rio.br/iup/en/elem/iupuser.html
func User() Ihandle {
h := mkih(C.IupUser())
h.SetAttribute("UUID", uuid.NewString())
return h
}
// Execute runs the executable with the given parameters.
// It is a non synchronous operation, i.e. the function will return just after execute the command and it will not wait for its result.
// In Windows, there is no need to add the ".exe" file extension.
//
// https://www.tecgraf.puc-rio.br/iup/en/func/iupexecute.html
func Execute(fileName, parameters string) int {
cFileName := C.CString(fileName)
defer C.free(unsafe.Pointer(cFileName))
return int(C.IupExecute(cFileName, C.CString(parameters)))
}
// ExecuteWait runs the executable with the given parameters.
// It is a synchronous operation, i.e. the function will wait the command to terminate before it returns.
// In Windows, there is no need to add the ".exe" file extension.
//
// https://www.tecgraf.puc-rio.br/iup/en/func/iupexecutewait.html
func ExecuteWait(fileName, parameters string) int {
cFileName := C.CString(fileName)
defer C.free(unsafe.Pointer(cFileName))
return int(C.IupExecuteWait(cFileName, C.CString(parameters)))
}
// Help opens the given URL. In UNIX executes Netscape, Safari (MacOS) or Firefox (in Linux) passing the desired URL as a parameter.
// In Windows executes the shell "open" operation on the given URL.
// In UNIX you can change the used browser setting the environment variable IUP_HELPAPP or using the global attribute "HELPAPP".
// It is a non synchronous operation, i.e. the function will return just after execute the command and it will not wait for its result.
// Since IUP 3.17, it will use the Execute function.
//
// https://www.tecgraf.puc-rio.br/iup/en/func/iuphelp.html
func Help(url string) int {
cUrl := C.CString(url)
defer C.free(unsafe.Pointer(cUrl))
return int(C.IupHelp(cUrl))
}
// Log writes a message to the system log.
// In Windows, writes to the Application event log. In Linux, writes to the Syslog.
//
// https://www.tecgraf.puc-rio.br/iup/en/func/iuplog.html
func Log(_type, str string) {
cType, cStr := C.CString(_type), C.CString(str)
defer C.free(unsafe.Pointer(cType))
defer C.free(unsafe.Pointer(cStr))
C.Log(cType, cStr)
}