-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathiup.go
2149 lines (1816 loc) · 81.2 KB
/
iup.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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package iup
import (
"bytes"
"fmt"
"reflect"
"strings"
"syscall"
"unsafe"
)
/*
#cgo CFLAGS: -I./include
#cgo LDFLAGS: -L${SRCDIR}/lib
#cgo LDFLAGS: -liup -liupcd -liupim -liupimglib -lgdi32 -lcomdlg32 -lcomctl32 -luuid -loleaut32 -lole32
#include <stdlib.h>
#include <string.h>
#include <iup.h>
Icallback __IupSetCallback(Ihandle* ih, const char *name, void* func) {
return IupSetCallback(ih, name, (Icallback)func);
}
Icallback __IupSetFunction(const char *name, void* func) {
return IupSetFunction(name, (Icallback)func);
}
*/
import "C"
// constants
const (
NAME = C.IUP_NAME
DESCRIPTION = C.IUP_DESCRIPTION
COPYRIGHT = C.IUP_COPYRIGHT
VERSION = C.IUP_VERSION /* bug fixes are reported only by IupVersion functions */
VERSION_NUMBER = C.IUP_VERSION_NUMBER
VERSION_DATE = C.IUP_VERSION_DATE /* does not include bug fix releases */
)
//Ihandle type.
type Ihandle uintptr
// callbacks are different, so functions that accept callbacks take it as interface{}
//type Icallback func(Ihandle) int
func (ih Ihandle) ptr() *C.Ihandle {
return (*C.Ihandle)(unsafe.Pointer(ih))
}
func mkih(p *C.Ihandle) Ihandle {
return Ihandle(unsafe.Pointer(p))
}
/* ---------------------------------------------------------------------------------------------- */
/* Main API */
/* ---------------------------------------------------------------------------------------------- */
//Open initializes the IUP toolkit.
//Must be called before any other IUP function.
func Open() int {
//int IupOpen (int *argc, char ***argv);
//TODO implement custom args passing
return int(C.IupOpen(nil, nil /*&C._argc, &C._argv*/)) // from stdlib.h
}
//Close ends the IUP toolkit and releases internal memory.
//It will also automatically destroy all dialogs and all elements that have names.
func Close() {
//void IupClose (void);
C.IupClose()
}
//ImageLibOpen register the names but do not load the images.
//The images will be loaded only if they are used in a control.
//The loaded images will be automatically released at IupClose.
func ImageLibOpen() {
//void IupImageLibOpen (void);
C.IupImageLibOpen()
}
//MainLoop executes the user interaction until a callback returns IUP_CLOSE, IupExitLoop is called, or hiding the last visible dialog.
func MainLoop() int {
//int IupMainLoop (void);
return int(C.IupMainLoop())
}
//LoopStep runs one iteration of the message loop.
func LoopStep() int {
//int IupLoopStep (void);
return int(C.IupLoopStep())
}
//LoopStepWait runs one iteration of the message loop.
func LoopStepWait() int {
//int IupLoopStepWait (void);
return int(C.IupLoopStepWait())
}
//MainLoopLevel returns the current cascade level of IupMainLoop. When no calls were done, return value is 0.
func MainLoopLevel() int {
//int IupMainLoopLevel (void);
return int(C.IupMainLoopLevel())
}
//Flush processes all pending messages in the message queue.
func Flush() {
//void IupFlush (void);
C.IupFlush()
}
//ExitLoop terminates the current message loop. It has the same effect of a callback returning IUP_CLOSE.
func ExitLoop() {
//void IupExitLoop (void);
C.IupExitLoop()
}
//RecordInput records all mouse and keyboard input in a file for later reproduction.
func RecordInput(fileName string, mode int) int {
c_fileName := C.CString(fileName)
defer C.free(unsafe.Pointer(c_fileName))
//int IupRecordInput(const char* filename, int mode);
return int(C.IupRecordInput(c_fileName, C.int(mode)))
}
//PlayInput reproduces all mouse and keyboard input from a given file.
func PlayInput(fileName string) int {
c_fileName := C.CString(fileName)
defer C.free(unsafe.Pointer(c_fileName))
//int IupPlayInput(const char* filename);
return int(C.IupPlayInput(c_fileName))
}
//Update mark the element or its children to be redraw when the control returns to the system.
func Update(ih Ihandle) {
//void IupUpdate (Ihandle* ih);
C.IupUpdate(ih.ptr())
}
//UpdateChildren mark the element or its children to be redraw when the control returns to the system.
func UpdateChildren(ih Ihandle) {
//void IupUpdateChildren(Ihandle* ih);
C.IupUpdateChildren(ih.ptr())
}
//Redraw force the element and its children to be redraw immediately.
func Redraw(ih Ihandle, children int) {
//void IupRedraw (Ihandle* ih, int children);
C.IupRedraw(ih.ptr(), C.int(children))
}
//Refresh updates the size and layout of all controls in the same dialog.
//To be used after changing size attributes, or attributes that affect the size of the control.
//Can be used for any element inside a dialog, but the layout of the dialog and all controls will be updated.
//It can change the layout of all the controls inside the dialog because of the dynamic layout positioning.
func Refresh(ih Ihandle) {
//void IupRefresh (Ihandle* ih);
C.IupRefresh(ih.ptr())
}
//RefreshChildren updates the size and layout of controls after changing size attributes,
//or attributes that affect the size of the control. Can be used for any element inside a dialog,
//only its children will be updated. It can change the layout of all the controls inside
//the given element because of the dynamic layout positioning.
func RefreshChildren(ih Ihandle) {
//void IupRefreshChildren(Ihandle* ih);
C.IupRefreshChildren(ih.ptr())
}
//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.
//Used by the IupHelp function.
func Execute(fileName, parameters string) int {
c_fileName := C.CString(fileName)
defer C.free(unsafe.Pointer(c_fileName))
//int IupExecute(const char *filename, const char* parameters);
return int(C.IupExecute(c_fileName, 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 IupExecute function.
func Help(url string) int {
c_url := C.CString(url)
defer C.free(unsafe.Pointer(c_url))
//int IupHelp(const char* url);
return int(C.IupHelp(c_url))
}
//Load compiles a LED specification
func Load(fileName string) error {
c_fileName := C.CString(fileName)
defer C.free(unsafe.Pointer(c_fileName))
//char* IupLoad (const char *filename);
ret := C.IupLoad(c_fileName)
if ret == nil {
return nil
} else {
return fmt.Errorf(C.GoString(ret))
}
}
//LoadBuffer compiles a LED specification
func LoadBuffer(buffer string) error {
c_buffer := C.CString(buffer)
defer C.free(unsafe.Pointer(c_buffer))
//char* IupLoadBuffer (const char *buffer);
ret := C.IupLoadBuffer(c_buffer)
if ret == nil {
return nil
} else {
return fmt.Errorf(C.GoString(ret))
}
}
//Version returns a string with the IUP version number
func Version() string {
//char* IupVersion (void);
return C.GoString(C.IupVersion())
}
func VersionDate() string {
//char* IupVersionDate (void);
return C.GoString(C.IupVersionDate())
}
//VersionNumber returns a string with the IUP version number
func VersionNumber() int {
//int IupVersionNumber (void);
return int(C.IupVersionNumber())
}
//SetLanguage sets the language name used by some pre-defined dialogs.
//Can also be changed using the global attribute LANGUAGE.
func SetLanguage(lng string) {
c_lng := C.CString(lng)
defer C.free(unsafe.Pointer(c_lng))
//void IupSetLanguage (const char *lng);
C.IupSetLanguage(c_lng)
}
//GetLanguage returns the language used by some pre-defined dialogs.
//Returns the same value as the LANGUAGE global attribute.
func GetLanguage() string {
//char* IupGetLanguage (void);
return C.GoString(C.IupGetLanguage())
}
//SetLanguageString associates a name with a string as an auxiliary method for Internationalization of applications.
func SetLanguageString(name, str string) {
c_name, c_str := C.CString(name), C.CString(str)
defer C.free(unsafe.Pointer(c_name))
defer C.free(unsafe.Pointer(c_str))
//void IupSetLanguageString(const char* name, const char* str);
//void IupStoreLanguageString(const char* name, const char* str);
C.IupStoreLanguageString(c_name, c_str) //NOTE string always duplicated
}
//GetLanguageString returns a language dependent string.
//The string must have been associated with the name using the IupSetLanguageString or IupSetLanguagePack functions.
func GetLanguageString(name string) string {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//char* IupGetLanguageString(const char* name);
return C.GoString(C.IupGetLanguageString(c_name))
}
//SetLanguagePack sets a pack of associations between names and string values.
//It is simply a IupUser element with several attributes set.
//Internally will call IupSetLanguageString for each name in the pack.
func SetLanguagePack(ih Ihandle) {
//void IupSetLanguagePack(Ihandle* ih);
C.IupSetLanguagePack(ih.ptr())
}
//Destroy destroys an interface element and all its children.
//Only dialogs, timers, popup menus and images should be normally destroyed, but detached controls can also be destroyed.
func Destroy(ih Ihandle) {
//void IupDestroy (Ihandle* ih);
C.IupDestroy(ih.ptr())
}
//Detach detaches an interface element from its parent.
func Detach(child Ihandle) {
//void IupDetach (Ihandle* child);
C.IupDetach(child.ptr())
}
//Append inserts an interface element at the end of the container, after the last element of the container.
//Valid for any element that contains other elements like dialog, frame, hbox, vbox, zbox or menu.
func Append(ih, child Ihandle) Ihandle {
//Ihandle* IupAppend (Ihandle* ih, Ihandle* child);
return mkih(C.IupAppend(ih.ptr(), child.ptr()))
}
//Insert Inserts an interface element before another child of the container.
//Valid for any element that contains other elements like dialog, frame, hbox, vbox, zbox, menu, etc.
func Insert(ih, refChild, child Ihandle) Ihandle {
//Ihandle* IupInsert (Ihandle* ih, Ihandle* ref_child, Ihandle* child);
return mkih(C.IupInsert(ih.ptr(), refChild.ptr(), child.ptr()))
}
//GetChild returns the a child of the control given its position.
func GetChild(ih Ihandle, pos int) Ihandle {
//Ihandle* IupGetChild (Ihandle* ih, int pos);
return mkih(C.IupGetChild(ih.ptr(), C.int(pos)))
}
//GetChildPos returns the position of a child of the given control.
func GetChildPos(ih, child Ihandle) int {
//int IupGetChildPos (Ihandle* ih, Ihandle* child);
return int(C.IupGetChildPos(ih.ptr(), child.ptr()))
}
//GetChildCount returns the number of children of the given control.
func GetChildCount(ih Ihandle) int {
//int IupGetChildCount(Ihandle* ih);
return int(C.IupGetChildCount(ih.ptr()))
}
//GetNextChild returns the a child of the given control given its brother.
func GetNextChild(ih, child Ihandle) Ihandle {
//Ihandle* IupGetNextChild (Ihandle* ih, Ihandle* child);
return mkih(C.IupGetNextChild(ih.ptr(), child.ptr()))
}
//GetBrother returns the brother of an element.
func GetBrother(ih Ihandle) Ihandle {
//Ihandle* IupGetBrother (Ihandle* ih);
return mkih(C.IupGetBrother(ih.ptr()))
}
//GetParent returns the parent of a control.
func GetParent(ih Ihandle) Ihandle {
//Ihandle* IupGetParent (Ihandle* ih);
return mkih(C.IupGetParent(ih.ptr()))
}
//GetDialog returns the handle of the dialog that contains that interface element.
//Works also for children of a menu that is associated with a dialog.
func GetDialog(ih Ihandle) Ihandle {
//Ihandle* IupGetDialog (Ihandle* ih);
return mkih(C.IupGetDialog(ih.ptr()))
}
//GetDialogChild returns the identifier of the child element that has the NAME attribute
//equals to the given value on the same dialog hierarchy.
//Works also for children of a menu that is associated with a dialog.
func GetDialogChild(ih Ihandle, name string) Ihandle {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//Ihandle* IupGetDialogChild(Ihandle* ih, const char* name);
return mkih(C.IupGetDialogChild(ih.ptr(), c_name))
}
//Reparent moves an interface element from one position in the hierarchy tree to another.
//Both new_parent and child must be mapped or unmapped at the same time.
//If ref_child is NULL, then it will append the child to the new_parent.
//If ref_child is NOT NULL then it will insert child before ref_child inside the new_parent.
func Reparent(ih, newParent, refChild Ihandle) int {
//int IupReparent (Ihandle* ih, Ihandle* new_parent, Ihandle* ref_child);
return int(C.IupReparent(ih.ptr(), newParent.ptr(), refChild.ptr()))
}
//Popup shows a dialog or menu and restricts user interaction only to the specified element.
//It is equivalent of creating a Modal dialog is some toolkits.
//
//If another dialog is shown after IupPopup using IupShow, then its interaction will not be inhibited.
//Every IupPopup call creates a new popup level that inhibits all previous dialogs interactions, but does not disable new ones
//(even if they were disabled by the Popup, calling IupShow will re-enable the dialog because it will change its popup level).
//IMPORTANT: The popup levels must be closed in the reverse order they were created or unpredictable results will occur.
//
//For a dialog this function will only return the control to the application
//after a callback returns IUP_CLOSE, IupExitLoop is called, or when the popup dialog is hidden, for example using IupHide.
//For a menu it returns automatically after a menu item is selected.
//IMPORTANT: If a menu item callback returns IUP_CLOSE, it will also ends the current popup level dialog.
func Popup(ih Ihandle, x, y int) int {
//int IupPopup (Ihandle* ih, int x, int y);
return int(C.IupPopup(ih.ptr(), C.int(x), C.int(y)))
}
//Show displays a dialog in the current position, or changes a control VISIBLE attribute.
func Show(ih Ihandle) int {
//int IupShow (Ihandle* ih);
return int(C.IupShow(ih.ptr()))
}
//ShowXY displays a dialog in a given position on the screen.
func ShowXY(ih Ihandle, x, y int) int {
//int IupShowXY (Ihandle* ih, int x, int y);
return int(C.IupShowXY(ih.ptr(), C.int(x), C.int(y)))
}
//Hide hides an interface element.
//This function has the same effect as attributing value "NO" to the interface element’s VISIBLE attribute.
func Hide(ih Ihandle) int {
//int IupHide (Ihandle* ih);
return int(C.IupHide(ih.ptr()))
}
//Map creates (maps) the native interface objects corresponding to the given IUP interface elements.
//
//It will also called recursively to create the native element of all the children in the element's tree.
//
//The element must be already attached to a mapped container, except the dialog.
//A child can only be mapped if its parent is already mapped.
//
//This function is automatically called before the dialog is shown in IupShow, IupShowXY or IupPopup.
func Map(ih Ihandle) int {
//int IupMap (Ihandle* ih);
return int(C.IupMap(ih.ptr()))
}
//Unmap unmap the element from the native system. It will also unmap all its children.
//It will NOT detach the element from its parent, and it will NOT destroy the IUP element.
func Unmap(ih Ihandle) {
//void IupUnmap (Ihandle *ih);
C.IupUnmap(ih.ptr())
}
//ResetAttributes removes an attribute from the hash table of the element, and its children if the attribute is inheritable.
//It is useful to reset the state of inheritable attributes in a tree of elements.
func ResetAttribute(ih Ihandle, name string) {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//void IupResetAttribute(Ihandle *ih, const char* name);
C.IupResetAttribute(ih.ptr(), c_name)
}
//GetAllAttributes returns the names of all attributes of an element that are set in its internal hash table only.
func GetAllAttributes(ih Ihandle) (ret []string) {
n := int(C.IupGetAllAttributes(ih.ptr(), nil, 0))
if n > 0 {
ret = make([]string, n)
pRets := make([]*C.char, n)
//int IupGetAllAttributes(Ihandle* ih, char** names, int n);
C.IupGetAllAttributes(ih.ptr(), (**C.char)(unsafe.Pointer(&pRets[0])), C.int(n))
for i := 0; i < n; i++ {
ret[i] = C.GoString(pRets[i])
}
}
return
}
//Ihandle* IupSetAtt(const char* handle_name, Ihandle* ih, const char* name, ...);
//SetAttributes sets several attributes of an interface element.
func SetAttributes(ih Ihandle, str string) Ihandle {
c_str := C.CString(str)
defer C.free(unsafe.Pointer(c_str))
//Ihandle* IupSetAttributes (Ihandle* ih, const char *str);
return mkih(C.IupSetAttributes(ih.ptr(), c_str))
}
//GetAttributes returns all attributes of a given element that are set in the internal hash table.
//The known attributes that are pointers (not strings) are returned as integers.
//
//The internal attributes are not returned (attributes prefixed with "_IUP").
//
//Before calling this function the application must ensure that there is no pointer attributes
//set for that element, although all known pointers attributes are handled.
//
//This function should be avoided. Use iup.GetAllAttributes instead.
func GetAttributes(ih Ihandle) string {
//char* IupGetAttributes (Ihandle* ih);
return C.GoString(C.IupGetAttributes(ih.ptr()))
}
//SetAttribute sets an interface element attribute.
func SetAttribute(ih Ihandle, name string, value interface{}) { //NOTE string attribute is always copied
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//void IupSetAttribute (Ihandle* ih, const char* name, const char* value);
//void IupSetStrAttribute(Ihandle* ih, const char* name, const char* value);
//void IupSetStrf (Ihandle* ih, const char* name, const char* format, ...);
//void IupSetInt (Ihandle* ih, const char* name, int value);
//void IupSetFloat (Ihandle* ih, const char* name, float value);
//void IupSetDouble (Ihandle* ih, const char* name, double value);
switch value.(type) {
case nil:
C.IupSetAttribute(ih.ptr(), c_name, nil) // default value
case Ihandle:
C.IupSetAttribute(ih.ptr(), c_name, (*C.char)(unsafe.Pointer(value.(Ihandle)))) // store pointer
case uintptr:
C.IupSetAttribute(ih.ptr(), c_name, (*C.char)(unsafe.Pointer(value.(uintptr)))) // store pointer
case string:
c_value := C.CString(value.(string))
defer C.free(unsafe.Pointer(c_value))
C.IupSetStrAttribute(ih.ptr(), c_name, c_value) // always copy string
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
C.IupSetInt(ih.ptr(), c_name, C.int(reflect.ValueOf(value).Int()))
case float32:
C.IupSetFloat(ih.ptr(), c_name, C.float(value.(float32)))
case float64:
C.IupSetDouble(ih.ptr(), c_name, C.double(value.(float64)))
case [3]uint8:
C.IupSetRGB(ih.ptr(), c_name, C.uchar(value.([3]uint8)[0]), C.uchar(value.([3]uint8)[1]), C.uchar(value.([3]uint8)[2]))
default:
panic(fmt.Errorf("bad argument passed to iup.SetAttribute"))
}
}
//SetRGB sets an interface element attribute.
func SetRGB(ih Ihandle, name string, r, g, b uint8) {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//void IupSetRGB (Ihandle *ih, const char* name, unsigned char r, unsigned char g, unsigned char b);
C.IupSetRGB(ih.ptr(), c_name, C.uchar(r), C.uchar(g), C.uchar(b))
}
//GetAttribute returns the name of an interface element attribute.
func GetAttribute(ih Ihandle, name string) string {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//char* IupGetAttribute(Ihandle* ih, const char* name);
return C.GoString(C.IupGetAttribute(ih.ptr(), c_name))
}
//GetInt returns the name of an interface element attribute.
func GetInt(ih Ihandle, name string) int {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//int IupGetInt (Ihandle* ih, const char* name);
return int(C.IupGetInt(ih.ptr(), c_name))
}
//GetInt2 returns the name of an interface element attribute.
func GetInt2(ih Ihandle, name string) (count, i1, i2 int) { // count = 0, 1 or 2
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//int IupGetInt2 (Ihandle* ih, const char* name);
//int IupGetIntInt (Ihandle *ih, const char* name, int *i1, int *i2);
count = int(C.IupGetIntInt(ih.ptr(), c_name, (*C.int)(unsafe.Pointer(&i1)), (*C.int)(unsafe.Pointer(&i2))))
return
}
//GetFloat returns the name of an interface element attribute.
func GetFloat(ih Ihandle, name string) float32 {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//float IupGetFloat (Ihandle* ih, const char* name);
return float32(C.IupGetFloat(ih.ptr(), c_name))
}
//GetDouble returns the name of an interface element attribute.
func GetDouble(ih Ihandle, name string) float64 {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//double IupGetDouble (Ihandle* ih, const char* name);
return float64(C.IupGetDouble(ih.ptr(), c_name))
}
//GetRGB returns the name of an interface element attribute.
func GetRGB(ih Ihandle, name string) (r, g, b uint8) {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//void IupGetRGB (Ihandle *ih, const char* name, unsigned char *r, unsigned char *g, unsigned char *b);
C.IupGetRGB(ih.ptr(), c_name, (*C.uchar)(unsafe.Pointer(&r)), (*C.uchar)(unsafe.Pointer(&g)), (*C.uchar)(unsafe.Pointer(&b)))
return
}
//SetAttributeId sets an interface element attribute.
func SetAttributeId(ih Ihandle, name string, id int, value interface{}) { //NOTE string attribute is always copied
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//void IupSetAttributeId(Ihandle *ih, const char* name, int id, const char *value);
//void IupSetStrAttributeId(Ihandle *ih, const char* name, int id, const char *value);
//void IupSetStrfId(Ihandle *ih, const char* name, int id, const char* format, ...);
//void IupSetIntId(Ihandle* ih, const char* name, int id, int value);
//void IupSetFloatId(Ihandle* ih, const char* name, int id, float value);
//void IupSetDoubleId(Ihandle* ih, const char* name, int id, double value);
switch value.(type) {
case nil:
C.IupSetAttributeId(ih.ptr(), c_name, C.int(id), nil) // default value
case Ihandle:
C.IupSetAttributeId(ih.ptr(), c_name, C.int(id), (*C.char)(unsafe.Pointer(value.(Ihandle)))) // store pointer
case uintptr:
C.IupSetAttributeId(ih.ptr(), c_name, C.int(id), (*C.char)(unsafe.Pointer(value.(uintptr)))) // store pointer
case string:
c_value := C.CString(value.(string))
defer C.free(unsafe.Pointer(c_value))
C.IupSetStrAttributeId(ih.ptr(), c_name, C.int(id), c_value) // always copy string
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
C.IupSetIntId(ih.ptr(), c_name, C.int(id), C.int(reflect.ValueOf(value).Int()))
case float32:
C.IupSetFloatId(ih.ptr(), c_name, C.int(id), C.float(value.(float32)))
case float64:
C.IupSetDoubleId(ih.ptr(), c_name, C.int(id), C.double(value.(float64)))
case [3]uint8:
C.IupSetRGBId(ih.ptr(), c_name, C.int(id), C.uchar(value.([3]uint8)[0]), C.uchar(value.([3]uint8)[1]), C.uchar(value.([3]uint8)[2]))
default:
panic(fmt.Errorf("bad argument passed to iup.SetAttributeId"))
}
}
//SetRGBId sets an interface element attribute.
func SetRGBId(ih Ihandle, name string, id int, r, g, b uint8) {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//void IupSetRGBId(Ihandle *ih, const char* name, int id, unsigned char r, unsigned char g, unsigned char b);
C.IupSetRGBId(ih.ptr(), c_name, C.int(id), C.uchar(r), C.uchar(g), C.uchar(b))
}
//GetAttributeId returns the name of an interface element attribute.
func GetAttributeId(ih Ihandle, name string, id int) string {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//char* IupGetAttributeId(Ihandle *ih, const char* name, int id);
return C.GoString(C.IupGetAttributeId(ih.ptr(), c_name, C.int(id)))
}
//GetIntId returns the name of an interface element attribute.
func GetIntId(ih Ihandle, name string, id int) int {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//int IupGetIntId(Ihandle *ih, const char* name, int id);
return int(C.IupGetIntId(ih.ptr(), c_name, C.int(id)))
}
//GetFloatId returns the name of an interface element attribute.
func GetFloatId(ih Ihandle, name string, id int) float32 {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//float IupGetFloatId(Ihandle *ih, const char* name, int id);
return float32(C.IupGetFloatId(ih.ptr(), c_name, C.int(id)))
}
//GetDoubleId returns the name of an interface element attribute.
func GetDoubleId(ih Ihandle, name string, id int) float64 {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//double IupGetDoubleId(Ihandle *ih, const char* name, int id);
return float64(C.IupGetDoubleId(ih.ptr(), c_name, C.int(id)))
}
//GetRGBId returns the name of an interface element attribute.
func GetRGBId(ih Ihandle, name string, id int) (r, g, b uint8) {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//void IupGetRGBId(Ihandle *ih, const char* name, int id, unsigned char *r, unsigned char *g, unsigned char *b);
C.IupGetRGBId(ih.ptr(), c_name, C.int(id), (*C.uchar)(unsafe.Pointer(&r)), (*C.uchar)(unsafe.Pointer(&g)), (*C.uchar)(unsafe.Pointer(&b)))
return
}
//SetAttributeId2 sets an interface element attribute.
func SetAttributeId2(ih Ihandle, name string, lin, col int, value interface{}) { //NOTE string attribute is always copied
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//void IupSetAttributeId2(Ihandle* ih, const char* name, int lin, int col, const char* value);
//void IupSetStrAttributeId2(Ihandle* ih, const char* name, int lin, int col, const char* value);
//void IupSetStrfId2(Ihandle* ih, const char* name, int lin, int col, const char* format, ...);
//void IupSetIntId2(Ihandle* ih, const char* name, int lin, int col, int value);
//void IupSetFloatId2(Ihandle* ih, const char* name, int lin, int col, float value);
//void IupSetDoubleId2(Ihandle* ih, const char* name, int lin, int col, double value);
switch value.(type) {
case nil:
C.IupSetAttributeId2(ih.ptr(), c_name, C.int(lin), C.int(col), nil) // default value
case Ihandle:
C.IupSetAttributeId2(ih.ptr(), c_name, C.int(lin), C.int(col), (*C.char)(unsafe.Pointer(value.(Ihandle)))) // store pointer
case uintptr:
C.IupSetAttributeId2(ih.ptr(), c_name, C.int(lin), C.int(col), (*C.char)(unsafe.Pointer(value.(uintptr)))) // store pointer
case string:
c_value := C.CString(value.(string))
defer C.free(unsafe.Pointer(c_value))
C.IupSetStrAttributeId2(ih.ptr(), c_name, C.int(lin), C.int(col), c_value) // always copy string
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
C.IupSetIntId2(ih.ptr(), c_name, C.int(lin), C.int(col), C.int(reflect.ValueOf(value).Int()))
case float32:
C.IupSetFloatId2(ih.ptr(), c_name, C.int(lin), C.int(col), C.float(value.(float32)))
case float64:
C.IupSetDoubleId2(ih.ptr(), c_name, C.int(lin), C.int(col), C.double(value.(float64)))
case [3]uint8:
C.IupSetRGBId2(ih.ptr(), c_name, C.int(lin), C.int(col), C.uchar(value.([3]uint8)[0]), C.uchar(value.([3]uint8)[1]), C.uchar(value.([3]uint8)[2]))
default:
panic(fmt.Errorf("bad argument passed to iup.SetAttributeId2"))
}
}
//SetRGBId2 sets an interface element attribute.
func SetRGBId2(ih Ihandle, name string, lin, col int, r, g, b uint8) {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//void IupSetRGBId2(Ihandle *ih, const char* name, int lin, int col, unsigned char r, unsigned char g, unsigned char b);
C.IupSetRGBId2(ih.ptr(), c_name, C.int(lin), C.int(col), C.uchar(r), C.uchar(g), C.uchar(b))
}
//GetAttributeId2 returns the name of an interface element attribute.
func GetAttributeId2(ih Ihandle, name string, lin, col int) string {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//char* IupGetAttributeId2(Ihandle* ih, const char* name, int lin, int col);
return C.GoString(C.IupGetAttributeId2(ih.ptr(), c_name, C.int(lin), C.int(col)))
}
//GetIntId2 returns the name of an interface element attribute.
func GetIntId2(ih Ihandle, name string, lin, col int) int {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//int IupGetIntId2(Ihandle* ih, const char* name, int lin, int col);
return int(C.IupGetIntId2(ih.ptr(), c_name, C.int(lin), C.int(col)))
}
//GetRGBId returns the name of an interface element attribute.
func GetFloatId2(ih Ihandle, name string, lin, col int) float32 {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//float IupGetFloatId2(Ihandle* ih, const char* name, int lin, int col);
return float32(C.IupGetFloatId2(ih.ptr(), c_name, C.int(lin), C.int(col)))
}
//GetDoubleId2 returns the name of an interface element attribute.
func GetDoubleId2(ih Ihandle, name string, lin, col int) float64 {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//double IupGetDoubleId2(Ihandle* ih, const char* name, int lin, int col);
return float64(C.IupGetDoubleId2(ih.ptr(), c_name, C.int(lin), C.int(col)))
}
//GetRGBId2 returns the name of an interface element attribute.
func GetRGBId2(ih Ihandle, name string, lin, col int) (r, g, b uint8) {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//void IupGetRGBId2(Ihandle *ih, const char* name, int lin, int col, unsigned char *r, unsigned char *g, unsigned char *b);
C.IupGetRGBId2(ih.ptr(), c_name, C.int(lin), C.int(col), (*C.uchar)(unsafe.Pointer(&r)), (*C.uchar)(unsafe.Pointer(&g)), (*C.uchar)(unsafe.Pointer(&b)))
return
}
//SetGlobal sets an attribute in the global environment.
//If the driver process the attribute then it will not be stored internally.
func SetGlobal(name string, value interface{}) {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//void IupSetGlobal (const char* name, const char* value);
//void IupSetStrGlobal(const char* name, const char* value);
switch value.(type) { //TODO handle number values?
case string:
c_value := C.CString(value.(string))
defer C.free(unsafe.Pointer(c_value))
C.IupSetStrGlobal(c_name, c_value) // always copy value
case uintptr:
C.IupSetGlobal(c_name, (*C.char)(unsafe.Pointer(value.(uintptr))))
case Ihandle:
C.IupSetGlobal(c_name, (*C.char)(unsafe.Pointer(value.(Ihandle))))
default:
panic(fmt.Errorf("bad argument passed to iup.SetGlobal"))
}
}
//GetGlobal returns an attribute value from the global environment.
//The value can be returned from the driver or from the internal storage.
func GetGlobal(name string) string {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//char* IupGetGlobal (const char* name);
return C.GoString(C.IupGetGlobal(c_name))
}
//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 con
func SetFocus(ih Ihandle) Ihandle {
//Ihandle* IupSetFocus (Ihandle* ih);
return mkih(C.IupSetFocus(ih.ptr()))
}
//GetFocus returns the identifier of the interface element that has the keyboard focus, i.e. the element that will receive keyboard events.
func GetFocus() Ihandle {
//Ihandle* IupGetFocus (void);
return mkih(C.IupGetFocus())
}
//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.
func PreviousField(ih Ihandle) Ihandle {
//Ihandle* IupPreviousField(Ihandle* ih);
return mkih(C.IupPreviousField(ih.ptr()))
}
//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.
func NextField(ih Ihandle) Ihandle {
//Ihandle* IupNextField (Ihandle* ih);
return mkih(C.IupNextField(ih.ptr()))
}
//GetCallback returns the callback associated to an event.
//
//Go specific note: The value returned is not a Go function, it is a pointer to a C function.
func GetCallback(ih Ihandle, name string) uintptr {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//Icallback IupGetCallback (Ihandle* ih, const char *name);
return uintptr(unsafe.Pointer(C.IupGetCallback(ih.ptr(), c_name)))
}
//SetCallback associates a callback to an event.
//
//Go specific note: You can pass a Go function or a pointer to a C function (as returned by iup.GetCallback for example)
func SetCallback(ih Ihandle, name string, fn interface{}) uintptr {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//Icallback IupSetCallback (Ihandle* ih, const char *name, Icallback func);
//Ihandle* IupSetCallbacks(Ihandle* ih, const char *name, Icallback func, ...);
switch fn.(type) {
case uintptr:
return uintptr(unsafe.Pointer(C.__IupSetCallback(ih.ptr(), c_name, unsafe.Pointer(fn.(uintptr)))))
default:
return uintptr(unsafe.Pointer(C.__IupSetCallback(ih.ptr(), c_name, unsafe.Pointer(syscall.NewCallbackCDecl(fn)))))
}
}
//GetFunction returns the function associated to an action only when they were set by IupSetFunction.
//It will not work if IupSetCallback were used.
//
//Go specific note: The value returned is not a Go function, it is a pointer to a C function.
func GetFunction(name string) uintptr {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//Icallback IupGetFunction(const char *name);
return uintptr(unsafe.Pointer(C.IupGetFunction(c_name)))
}
//SetFunction associates a function to an action as a global callback.
//
//This function should not be used by new applications, use it only for global callbacks.
//For regular elements use IupSetCallback instead.
//
//Notice that the application or libraries may set the same name for two different functions by mistake.
//IupSetCallback does not depends on global names.
//
//Go specific note: You can pass a Go function or a pointer to a C function (as returned by iup.GetCallback for example)
func SetFunction(name string, fn interface{}) uintptr {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//Icallback IupSetFunction(const char *name, Icallback func);
switch fn.(type) {
case nil:
return uintptr(unsafe.Pointer(C.__IupSetFunction(c_name, unsafe.Pointer(uintptr(0)))))
case uintptr:
return uintptr(unsafe.Pointer(C.__IupSetFunction(c_name, unsafe.Pointer(fn.(uintptr)))))
default:
return uintptr(unsafe.Pointer(C.__IupSetFunction(c_name, unsafe.Pointer(syscall.NewCallbackCDecl(fn)))))
}
}
//GetHandle returns the identifier of an interface element that has an associated name using IupSetHandle or using LED.
func GetHandle(name string) Ihandle {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//Ihandle* IupGetHandle (const char *name);
return mkih(C.IupGetHandle(c_name))
}
//SetHandle associates a name with an interface element.
func SetHandle(name string, ih Ihandle) Ihandle {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//Ihandle* IupSetHandle (const char *name, Ihandle* ih);
return mkih(C.IupSetHandle(c_name, ih.ptr()))
}
//GetAllNames returns the names of all interface elements that have an associated name using IupSetHandle or using LED.
func GetAllNames() (names []string) {
//int IupGetAllNames (char** names, int n);
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 IupSetHandle or using LED.
//Other dialogs will not be returned.
func GetAllDialogs() (names []string) {
//int IupGetAllDialogs(char** names, int n);
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
}
//GetName Returns a name of an interface element, if the element has an associated name using IupSetHandle or using LED (which calls IupSetHandle when parsed).
//
//Notice that a handle can have many names. IupGetName will return the last name set.
func GetName(ih Ihandle) string {
//char* IupGetName (Ihandle* ih);
return C.GoString(C.IupGetName(ih.ptr()))
}
//SetAttributeHandle instead of using IupSetHandle and IupSetAttribute with a new creative name,
//this function automatically creates a non conflict name and associates the name with the attribute.
//
//It is very useful for associating images and menus.
func SetAttributeHandle(ih Ihandle, name string, ihNamed Ihandle) {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//void IupSetAttributeHandle(Ihandle* ih, const char* name, Ihandle* ih_named);
C.IupSetAttributeHandle(ih.ptr(), c_name, ihNamed.ptr())
}
//GetAttributeHandle instead of using IupGetAttribute and IupGetHandle, this function directly returns the associated handle.
func GetAttributeHandle(ih Ihandle, name string) Ihandle {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
//Ihandle* IupGetAttributeHandle(Ihandle* ih, const char* name);
return mkih(C.IupGetAttributeHandle(ih.ptr(), c_name))
}
//GetClassName returns the name of the class of an interface element.
func GetClassName(ih Ihandle) string {
//char* IupGetClassName(Ihandle* ih);
return C.GoString(C.IupGetClassName(ih.ptr()))
}
//GetClassType returns the name of the native type of an interface element.
func GetClassType(ih Ihandle) string {
//char* IupGetClassType(Ihandle* ih);
return C.GoString(C.IupGetClassType(ih.ptr()))
}
//GetAllClasses returns the names of all registered classes.
func GetAllClasses() (names []string) {
//int IupGetAllClasses(char** names, int n);
n := int(C.IupGetAllClasses(nil, 0))
if n > 0 {
names = make([]string, n)
pNames := make([]*C.char, n)