Repository navigation
Expand file tree
/
Copy pathattributes.go
More file actions
230 lines (171 loc) · 6.04 KB
/
Copy pathattributes.go
File metadata and controls
230 lines (171 loc) · 6.04 KB
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
/*
Copyright (C) 2011 by Jeremy Cowgar <jeremy@cowgar.com>
This file is part of go-iup.
go-iup is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
go-iup is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with go-iup. If not, see <http://www.gnu.org/licenses/>.
*/
package iup
/*
#include <stdlib.h>
#include <iup.h>
void _IupSetfAttributeId2(Ihandle *ih, const char *name, int lin, int col, const char *value) {
IupSetfAttributeId2(ih, name, lin, col, value);
}
*/
import "C"
import (
"unsafe"
"fmt"
"bytes"
)
func cstring(gostr string) *C.char {
cstr := C.CString(gostr)
cstrings = append(cstrings, unsafe.Pointer(cstr))
return cstr
}
func StoreAttribute(ih *Ihandle, name, value string) {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
C.IupStoreAttribute((*C.Ihandle)(ih), cName, cstring(value))
}
func StoreAttributeId(ih *Ihandle, name string, id int, value string) {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
C.IupStoreAttributeId((*C.Ihandle)(ih), cName, C.int(id), cstring(value))
}
func SetAttribute(ih *Ihandle, name, value string) {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
// value can't be freed here or IUP will have an invalid char pointer
C.IupSetAttribute(ih.C(), cName, cstring(value))
}
func SetAttributeId(ih *Ihandle, name string, id int, value string) {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
C.IupSetAttributeId((*C.Ihandle)(ih), cName, C.int(id), cstring(value))
}
func SetfAttribute(ih *Ihandle, name, format string, args ...interface{}) {
StoreAttribute(ih, name, fmt.Sprintf(format, args...))
}
func SetfAttributeId(ih *Ihandle, name string, id int, format string, args ...interface{}) {
StoreAttributeId(ih, name, id, fmt.Sprintf(format, args...))
}
func SetfAttributeId2(ih *Ihandle, name string, lin int, col int, format string, args ...interface{}) {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
cValue := cstring(fmt.Sprintf(format, args...))
C._IupSetfAttributeId2((*C.Ihandle)(ih), cName, C.int(lin), C.int(col), cValue)
}
func SetAttributes(ih *Ihandle, values string) {
C.IupSetAttributes((*C.Ihandle)(ih), cstring(values))
}
func ResetAttribute(ih *Ihandle, name string) {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
C.IupResetAttribute((*C.Ihandle)(ih), cName)
}
// Warning: handle_name is ignored
func SetAtt(ih *Ihandle, handle_name string, args ...string) *Ihandle {
attrs := bytes.NewBufferString("")
for i := 0; i < len(args); i += 2 {
if i > 0 {
attrs.WriteString(",")
}
attrs.WriteString(fmt.Sprintf("%s=\"%s\"", args[i], args[i+1]))
}
SetAttributes(ih, attrs.String())
return ih
}
// This method does not exist in C Iup. It has been provided as a convience function to allow
// code such as:
//
// box := iup.Hbox(button1, button2).SetAttrs("GAP", "5", "MARGIN", "8x8")
//
// C Iup provides SetAtt for this purpose but in Go Iup SetAttrs is an easier method to
// accomplish this task due to no necessity of handle_name.
func SetAttrs(ih *Ihandle, args ...string) *Ihandle {
return SetAtt(ih, "", args...)
}
func SetAttributeHandle(ih *Ihandle, name string, ihNamed *Ihandle) {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
C.IupSetAttributeHandle((*C.Ihandle)(ih), cName, (*C.Ihandle)(ihNamed))
}
func GetAttributeHandle(ih *Ihandle, name string) *Ihandle {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return (*Ihandle)(C.IupGetAttributeHandle((*C.Ihandle)(ih), cName))
}
func GetAttribute(ih *Ihandle, name string) string {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return C.GoString(C.IupGetAttribute((*C.Ihandle)(ih), cName))
}
func GetAttributeId(ih *Ihandle, name string, id int) string {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return C.GoString(C.IupGetAttributeId((*C.Ihandle)(ih), cName, C.int(id)))
}
func GetIntId(ih *Ihandle, name string, id int) int {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return int(C.IupGetIntId((*C.Ihandle)(ih), cName, C.int(id)))
}
func GetFloatId(ih *Ihandle, name string, id int) float64 {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return float64(C.IupGetFloatId((*C.Ihandle)(ih), cName, C.int(id)))
}
func GetAttributes(ih *Ihandle) string {
return C.GoString(C.IupGetAttributes((*C.Ihandle)(ih)))
}
func SetFloat(ih *Ihandle, name string, value float32) {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
C.IupSetFloat(ih.C(), cName, C.float(value))
}
func SetInt(ih *Ihandle, name string, value int32) {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
C.IupSetInt(ih.C(), cName, C.int(value))
}
func GetFloat(ih *Ihandle, name string) float64 {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return float64(C.IupGetFloat((*C.Ihandle)(ih), cName))
}
func GetInt(ih *Ihandle, name string) int64 {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return int64(C.IupGetInt((*C.Ihandle)(ih), cName))
}
func StoreGlobal(name, value string) {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
C.IupStoreGlobal(cName, cstring(value))
}
func SetGlobal(name string, value string) {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
cValue := C.CString(value)
defer C.free(unsafe.Pointer(cValue))
C.IupSetGlobal(cName, cValue)
}
func GetGlobal(name string) string {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return C.GoString(C.IupGetGlobal(cName))
}
func GetHandle(name string) *Ihandle {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return (*Ihandle)(C.IupGetHandle(cName))
}