├── .gitignore
├── COPYRIGHT
├── LINSTALL
├── README
├── examples
├── demo
│ ├── doc.go
│ ├── main.go
│ ├── make.bat
│ └── rc
│ │ ├── goiup.ico
│ │ ├── goiup.manifest
│ │ └── goiup.rc
├── hello
│ ├── doc.go
│ ├── main.go
│ ├── make.bat
│ └── rc
│ │ ├── goiup.ico
│ │ ├── goiup.manifest
│ │ └── goiup.rc
└── notepad
│ ├── doc.go
│ ├── main.go
│ ├── make.bat
│ └── rc
│ ├── goiup.ico
│ ├── goiup.manifest
│ └── goiup.rc
├── iup
├── _cgo_export.h
├── csutil_linux.go
├── csutil_windows.go
├── dialog.go
├── doc.go
├── errors.go
├── gencb.lua
├── handle.go
├── iupobject.go
├── system.go
└── types.go
├── iupctls
├── doc.go
└── iupctls.go
├── iupim
├── doc.go
└── iupim.go
├── iupimglib
├── doc.go
└── iupimglib.go
├── iupole
├── doc.go
└── iupole.go
├── iuppplot
├── doc.go
└── iuppplot.go
├── iuptuio
├── doc.go
└── iuptuio.go
└── iupweb
├── Makefile
├── doc.go
├── iupweb_linux.go
└── iupweb_windows.go
/.gitignore:
--------------------------------------------------------------------------------
1 | *.8
2 | *.6
3 | *.o
4 | *.exe
--------------------------------------------------------------------------------
/COPYRIGHT:
--------------------------------------------------------------------------------
1 | GO-IUP License
2 | -----------
3 |
4 | GO-IUP is licensed under the terms of the MIT license reproduced below.
5 | This means that GOIUP is free software and can be used for both academic
6 | and commercial purposes at absolutely no cost.
7 |
8 | ===============================================================================
9 |
10 | Copyright (C) 2011-2012 visualfc.
11 |
12 | ===============================================================================
13 |
14 | (end of GOIUP)
15 |
16 |
17 | ===============================================================================
18 | ===============================================================================
19 |
20 |
21 | IUP License
22 | -----------
23 |
24 | IUP is licensed under the terms of the MIT license reproduced below.
25 | This means that IUP is free software and can be used for both academic
26 | and commercial purposes at absolutely no cost.
27 |
28 | ===============================================================================
29 |
30 | Copyright (C) 1994-2011 Tecgraf, PUC-Rio.
31 |
32 | Permission is hereby granted, free of charge, to any person obtaining a copy
33 | of this software and associated documentation files (the "Software"), to deal
34 | in the Software without restriction, including without lIUPitation the rights
35 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
36 | copies of the Software, and to permit persons to whom the Software is
37 | furnished to do so, subject to the following conditions:
38 |
39 | The above copyright notice and this permission notice shall be included in
40 | all copies or substantial portions of the Software.
41 |
42 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
43 | IUPPLIED, INCLUDING BUT NOT LIUPITED TO THE WARRANTIES OF MERCHANTABILITY,
44 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
45 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIUP, DAMAGES OR OTHER
46 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
47 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
48 | THE SOFTWARE.
49 |
50 | ===============================================================================
51 |
52 | (end of COPYRIGHT)
53 |
54 |
--------------------------------------------------------------------------------
/LINSTALL:
--------------------------------------------------------------------------------
1 | INSTALL GO-IUP
2 |
3 | 1. DOWNLOAD GO-IUP
4 | go get github.com/visualfc/go-iup
5 |
6 | 2. DOWNLOAD IUP CD IM
7 | All the libraries were build using Tecmake. Please use it if you intend to recompile the sources. Tecmake can be found at http://www.tecgraf.puc-rio.br/tecmake.
8 |
9 | The IM files can be downloaded at http://sourceforge.net/projects/imtoolkit/files/.
10 | The CD files can be downloaded at http://sourceforge.net/projects/canvasdraw/files/.
11 | The IUP files can be downloaded at http://sourceforge.net/projects/iup/files/.
12 | The Lua files can be downloaded at http://sourceforge.net/projects/luabinaries/files/.
13 |
14 | 3. SETUP GO-IUP libs
15 |
16 | Windows:
17 | github.com/
18 | visualfc/
19 | go-iup/ -- go-iup
20 | libs/
21 | iup/ -- iup libs
22 | include/
23 | Linux:
24 | github.com/
25 | visualfc/
26 | go-iup/ -- go-iup
27 | libs/
28 | iup/ -- iup libs
29 | include/
30 | cd/ -- cd libs
31 | include/
32 | im/ -- im libs
33 | include/
34 |
35 | 4. INSTALL GO-IUP
36 | go install github.com/visualfc/go-iup/iup
37 | go install github.com/visualfc/go-iup/iupctls
38 | go install github.com/visualfc/go-iup/iupim
39 | go install github.com/visualfc/go-iup/iupimglib
40 | go install github.com/visualfc/go-iup/iupole
41 | go install github.com/visualfc/go-iup/iuppplot
42 | go install github.com/visualfc/go-iup/iuptuio
43 | go install github.com/visualfc/go-iup/iupweb
44 |
45 |
46 | (end of INSTALL)
47 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | README for GO-IUP
2 | GO-IUP is a IUP golang binding
3 | https://github.com/visualfc/go-iup
4 |
5 |
6 | README for IUP
7 | http://www.tecgraf.puc-rio.br/iup
8 | IUP is a portable toolkit for building graphical user interfaces. It offers a configuration API in three basic languages: C, Lua and LED. IUP's purpose is to allow a program to be executed in different systems without any modification, therefore it is highly portable. Its main advantages are:
9 | * high performance, due to the fact that it uses native interface elements.
10 | * fast learning by the user, due to the simplicity of its API.
11 |
12 | Build instructions and usage are available in the IUP documentation.
13 |
14 | For complete information, visit IUP's web site at http://www.tecgraf.puc-rio.br/iup
15 | or access its documentation in the HTML folder.
16 |
17 | (end of README)
18 |
--------------------------------------------------------------------------------
/examples/demo/doc.go:
--------------------------------------------------------------------------------
1 | // demo project doc.go
2 |
3 | /*
4 | demo document
5 | */
6 | package documentation
7 |
--------------------------------------------------------------------------------
/examples/demo/main.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011-2012 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | package main
6 |
7 | import (
8 | "fmt"
9 | "github.com/visualfc/go-iup/iup"
10 | "github.com/visualfc/go-iup/iupctls"
11 | "github.com/visualfc/go-iup/iupim"
12 | "github.com/visualfc/go-iup/iupimglib"
13 | "github.com/visualfc/go-iup/iuppplot"
14 | )
15 |
16 | func main() {
17 | e := iup.Open()
18 | if e != nil {
19 | fmt.Println(e)
20 | return
21 | }
22 | defer iup.Close()
23 |
24 | iupctls.Open()
25 | iuppplot.Open()
26 | iupimglib.Open()
27 |
28 | ui()
29 | }
30 |
31 | func ui() {
32 | var img *iup.Handle
33 | tree := iup.Tree(
34 | "EXPANDALL=YES",
35 | )
36 | tree.SetName("tree")
37 | vbox1 := iup.Vbox(
38 | "TABTITLE=Standard,MARGIN=0x0,GAP=5",
39 | iup.Frame("TITLE=Frame,EXPAND=YES",
40 | iup.Vbox(
41 | iup.Label("TITLE=\"List Label\""),
42 | iup.List("EXPAND=YES,1=list1", "2=list2", "3=list3"),
43 | ),
44 | ),
45 | iup.Hbox(
46 | iup.List("DROPDOWN=YES,EDITBOX=YES", "1=list1", "2=list2"),
47 | iup.SpinBox(
48 | iup.Text("VALUE=100"),
49 | ),
50 | iup.Toggle("TITLE=Toggle,EXPAND=VERTICAL"),
51 | // iup.Val("MIN=1,MAX=100"),
52 | ),
53 | iup.Frame(
54 | iup.Radio(
55 | iup.Hbox(
56 | iup.Toggle("TITLE=1"),
57 | iup.Toggle("TITLE=2"),
58 | iup.Toggle("TITLE=3"),
59 | iup.Toggle("TITLE=4"),
60 | ),
61 | ),
62 | ),
63 | iup.Text("EXPAND=HORIZONTAL"),
64 | iup.ProgressBar("MIN=0,MAX=100,VALUE=50,EXPAND=HORIZONTAL"),
65 | tree,
66 | )
67 | vbox2 := iup.Vbox(
68 | "TABTITLE=Text",
69 | iup.Text("EXPAND=YES,MULTILINE=YES"),
70 | )
71 | vbox3 := iup.Vbox(
72 | "TABTITLE=Colorbar",
73 | iup.Colorbar(
74 | "ORIENTATION=HORIZONTAL",
75 | "NUM_PARTS=2",
76 | "SHOW_SECONDARY=YES",
77 | func(arg *iup.ColorbarSelect) {
78 | fmt.Println(arg)
79 | },
80 | ),
81 | )
82 | vbox4 := iup.Vbox(
83 | "TABTITLE=ColorBrowser",
84 | iup.ColorBrowser(
85 | "EXPAND=YES",
86 | func(arg *iup.ColorBrowserDrag) {
87 | fmt.Printf("R=%d,G=%d,B=%d\n", arg.R, arg.G, arg.B)
88 | },
89 | ),
90 | )
91 | vbox5 := iup.Vbox(
92 | "TABTITLE=Dial",
93 | iup.Fill(),
94 | iup.Dial(),
95 | iup.Dial("ORIENTATION=VERTICAL"),
96 | iup.Fill(),
97 | )
98 | pplot := iuppplot.PPlot(
99 | iup.Attr("TITLE", "A simple XY Plot"),
100 | iup.Attrs(
101 | "MARGINBOTTOM", "35",
102 | "MARGINLEFT", "35",
103 | "AXS_XLABEL", "X",
104 | "AXS_YLABEL", "Y",
105 | ),
106 | )
107 | pplot.Begin(0)
108 | pplot.Add(0, 0)
109 | pplot.Add(5, 5)
110 | pplot.Add(10, 7)
111 | pplot.End()
112 | vbox6 := iup.Vbox(
113 | "TABTITLE=PPlot",
114 | pplot,
115 | )
116 | vbox7 := iup.Vbox(
117 | "TABTITLE=Matrix",
118 | iup.Matrix(
119 | "NUMCOL=5,NUMLIN=10,NUMCOL_VISIBLE=5,NUMLIN_VISIBLE=3,WIDTHDEF=34",
120 | "RESIZEMATRIX=YES",
121 | ),
122 | )
123 | vbox8 := iup.Vbox(
124 | "TABTITLE=Image",
125 | iup.Hbox(
126 | "GAP=10",
127 | iup.Button("IMAGE=IUP_FileNew"),
128 | iup.Button("IMAGE=IUP_FileOpen"),
129 | iup.Button(
130 | "TITLE=SelectImg",
131 | func(arg *iup.ButtonAction) {
132 | file, ok := iup.GetOpenFile("", "*.png;*.jpg;*.bmp;*.jpeg")
133 | if ok {
134 | label := arg.Sender.GetDialogChild("img_label")
135 | if img != nil {
136 | img.Destroy()
137 | }
138 | img = iupim.LoadImage(file)
139 | if img != nil {
140 | img.SetName("img_label_image")
141 | label.(*iup.Handle).SetAttribute("IMAGE", "img_label_image")
142 | label.(*iup.Handle).Refresh()
143 | }
144 | }
145 | },
146 | ),
147 | ),
148 | iup.Label("IMAGE=img_label_image", "NAME=img_label"),
149 | )
150 | dlg := iup.Dialog(
151 | iup.Attr("TITLE", "GO-IUP Demo 1.0"),
152 | "SIZE=350x200",
153 | "SHRINK=YES",
154 | "MARGIN=10x10",
155 | iup.Tabs(
156 | vbox1,
157 | vbox2,
158 | vbox3,
159 | vbox4,
160 | vbox5,
161 | vbox6,
162 | vbox7,
163 | vbox8,
164 | ),
165 | )
166 | dlg.Show()
167 |
168 | tree.SetAttribute("ADDBRANCH", "Item2")
169 | tree.SetAttribute("ADDLEAF1", "leaf3")
170 | tree.SetAttribute("ADDLEAF2", "leaf4")
171 | tree.SetAttribute("ADDBRANCH", "Item1")
172 | tree.SetAttribute("ADDLEAF1", "leaf1")
173 | tree.SetAttribute("ADDLEAF2", "leaf2")
174 |
175 | defer dlg.Destroy()
176 | iup.MainLoop()
177 | }
178 |
--------------------------------------------------------------------------------
/examples/demo/make.bat:
--------------------------------------------------------------------------------
1 | windres rc/goiup.rc -o temp-rc.o
2 |
3 | set GOIUPPKG=../../../../../../pkg/windows_386
4 | set SRC=main.go
5 | set OUT=demo
6 |
7 | go tool 8g -I%GOIUPPKG% %SRC%
8 |
9 | go tool pack grc _go_.8 main.8 temp-rc.o
10 |
11 | go tool 8l -L%GOIUPPKG% -s -Hwindowsgui -o %OUT%.exe _go_.8
12 |
13 | rm *.8 *.o
--------------------------------------------------------------------------------
/examples/demo/rc/goiup.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/visualfc/go-iup/e6afc2277af81f0c4f7189db74321ba766af085c/examples/demo/rc/goiup.ico
--------------------------------------------------------------------------------
/examples/demo/rc/goiup.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
11 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/examples/demo/rc/goiup.rc:
--------------------------------------------------------------------------------
1 | IDI_ICON ICON "goiup.ico"
2 | 1 24 "goiup.manifest"
3 |
--------------------------------------------------------------------------------
/examples/hello/doc.go:
--------------------------------------------------------------------------------
1 | // hello project doc.go
2 |
3 | /*
4 | hello document
5 | */
6 | package documentation
7 |
--------------------------------------------------------------------------------
/examples/hello/main.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011-2012 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | package main
6 |
7 | import (
8 | "fmt"
9 | "github.com/visualfc/go-iup/iup"
10 | )
11 |
12 | func main() {
13 | e := iup.Open()
14 | if e != nil {
15 | fmt.Println(e)
16 | return
17 | }
18 | defer iup.Close()
19 | fmt.Println("Hello go-iup!")
20 | mainui()
21 | }
22 |
23 | func mainui() {
24 | dlg := iup.Dialog(
25 | iup.Attr("TITLE", "Iup Hello World"),
26 | "RASTERSIZE=400x300",
27 | iup.Hbox(
28 | "MARGIN=5x5,GAP=5",
29 | iup.Vbox(
30 | iup.Label(
31 | "EXPAND=HORIZONTAL,ALIGNMENT=ACENTER,FONTSIZE=12",
32 | iup.Attr("TITLE", "Welcome to GO-IUP"),
33 | ),
34 | iup.Label(
35 | "EXPAND=YES,ALIGNMENT=ACENTER:ACENTER,WORDWRAP=YES",
36 | iup.Attr("TITLE",
37 | fmt.Sprintf("%s\nVersion: %s\n\n%s\nVersion: %s",
38 | iup.IupName, iup.IupVersion, iup.Name, iup.Version)),
39 | ),
40 | ),
41 | iup.Vbox(
42 | iup.Button(
43 | "TITLE=OK",
44 | "SIZE=50x",
45 | func(arg *iup.ButtonAction) {
46 | arg.Return = iup.CLOSE
47 | },
48 | ),
49 | iup.Button(
50 | "TITLE=About",
51 | "SIZE=50x",
52 | func(arg *iup.ButtonAction) {
53 | iup.Message("About", "GO-IUP\nvisualfc@gmail.com 2011-2012")
54 | },
55 | ),
56 | ),
57 | ),
58 | )
59 | defer dlg.Destroy()
60 | dlg.Show()
61 | iup.MainLoop()
62 | }
63 |
--------------------------------------------------------------------------------
/examples/hello/make.bat:
--------------------------------------------------------------------------------
1 | windres rc/goiup.rc -o temp-rc.o
2 |
3 | set GOIUPPKG=../../../../../../pkg/windows_386
4 | set SRC=main.go
5 | set OUT=hello
6 |
7 | go tool 8g -I%GOIUPPKG% %SRC%
8 |
9 | go tool pack grc _go_.8 main.8 temp-rc.o
10 |
11 | go tool 8l -L%GOIUPPKG% -s -Hwindowsgui -o %OUT%.exe _go_.8
12 |
13 | rm *.8 *.o
--------------------------------------------------------------------------------
/examples/hello/rc/goiup.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/visualfc/go-iup/e6afc2277af81f0c4f7189db74321ba766af085c/examples/hello/rc/goiup.ico
--------------------------------------------------------------------------------
/examples/hello/rc/goiup.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
11 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/examples/hello/rc/goiup.rc:
--------------------------------------------------------------------------------
1 | IDI_ICON ICON "goiup.ico"
2 | 1 24 "goiup.manifest"
3 |
--------------------------------------------------------------------------------
/examples/notepad/doc.go:
--------------------------------------------------------------------------------
1 | // notepad project doc.go
2 |
3 | /*
4 | notepad document
5 | */
6 | package documentation
7 |
--------------------------------------------------------------------------------
/examples/notepad/main.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011-2012 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | package main
6 |
7 | import (
8 | "fmt"
9 | "github.com/visualfc/go-iup/iup"
10 | "io/ioutil"
11 | "runtime"
12 | "sync"
13 | "time"
14 | )
15 |
16 | type Notepad struct {
17 | fileName string
18 | modify bool
19 | dlg *iup.Handle
20 | edit *iup.Handle
21 | sts1 *iup.Handle
22 | sts2 *iup.Handle
23 | timer *time.Timer
24 | }
25 |
26 | var m sync.Mutex
27 |
28 | func (pad *Notepad) ShowStatus(h *iup.Handle) {
29 | if pad.timer != nil {
30 | pad.timer.Stop()
31 | }
32 | tip := h.GetAttribute("TIP")
33 | pad.sts1.SetAttribute("TITLE", tip)
34 | pad.timer = time.AfterFunc(1e9, func() {
35 | pad.sts1.SetAttribute("TITLE", "Ready")
36 | })
37 | }
38 |
39 | func (pad *Notepad) init() *Notepad {
40 | iup.Menu(
41 | iup.SubMenu("TITLE=File",
42 | iup.Menu(
43 | iup.Item(
44 | iup.Attr("TITLE", "New\tCtrl+N"),
45 | iup.Attr("TIP", "New File"),
46 | func(arg *iup.ItemAction) {
47 | pad.NewFile()
48 | },
49 | func(arg *iup.ItemHighlight) {
50 | pad.ShowStatus(arg.Sender)
51 | },
52 | ),
53 | iup.Item(
54 | iup.Attr("TITLE", "Open\tCtrl+O"),
55 | iup.Attr("TIP", "Open File"),
56 | func(arg *iup.ItemAction) {
57 | runtime.GC()
58 | pad.Open()
59 | },
60 | func(arg *iup.ItemHighlight) {
61 | pad.ShowStatus(arg.Sender)
62 | },
63 | ),
64 | iup.Item(
65 | iup.Attr("TITLE", "Save\tCtrl+S"),
66 | iup.Attr("TIP", "Save File"),
67 | func(arg *iup.ItemAction) {
68 | pad.Save()
69 | },
70 | func(arg *iup.ItemHighlight) {
71 | pad.ShowStatus(arg.Sender)
72 | },
73 | ),
74 | iup.Item(
75 | iup.Attr("TITLE", "SaveAs"),
76 | iup.Attr("TIP", "Save File As..."),
77 | func(arg *iup.ItemAction) {
78 | pad.SaveAS()
79 | },
80 | func(arg *iup.ItemHighlight) {
81 | pad.ShowStatus(arg.Sender)
82 | },
83 | ),
84 | iup.Separator(),
85 | iup.Item(
86 | iup.Attr("TITLE", "Quit"),
87 | iup.Attr("TIP", "Exit Application"),
88 | func(arg *iup.ItemAction) {
89 | pad.CheckModify()
90 | arg.Return = iup.CLOSE
91 | },
92 | func(arg *iup.ItemHighlight) {
93 | pad.ShowStatus(arg.Sender)
94 | },
95 | ),
96 | ),
97 | ),
98 | iup.SubMenu("TITLE=Help",
99 | iup.Menu(
100 | iup.Item(
101 | iup.Attr("TITLE", "About"),
102 | iup.Attr("TIP", "About Notepad"),
103 | func(arg *iup.ItemAction) {
104 | iup.Message("About", "\tNotepad 1.0\n\n\tvisualfc@gmail.com 2012\t")
105 | },
106 | func(arg *iup.ItemHighlight) {
107 | pad.ShowStatus(arg.Sender)
108 | },
109 | ),
110 | ),
111 | ),
112 | ).SetName("main_menu")
113 | pad.edit = iup.Text(
114 | "EXPAND=YES",
115 | "MULTILINE=YES",
116 | "WORDWRAP=YES",
117 | "TABSIZE=4",
118 | "NAME=text",
119 | func(arg *iup.ValueChanged) {
120 | pad.SetModify()
121 | },
122 | func(arg *iup.TextCaret) {
123 | pad.sts2.SetAttribute("TITLE", fmt.Sprintf("Lin:%d Col:%d ", arg.Lin, arg.Col))
124 | },
125 | func(arg *iup.CommonKeyAny) {
126 | key := iup.KeyState(arg.Key)
127 | if !key.IsCtrl() {
128 | return
129 | }
130 | switch key.Key() {
131 | case 'N':
132 | pad.NewFile()
133 | case 'O':
134 | pad.Open()
135 | case 'S':
136 | pad.Save()
137 | default:
138 | return
139 | }
140 | },
141 | )
142 | pad.sts1 = iup.Label(
143 | "TITLE=Ready",
144 | "EXPAND=HORIZONTAL",
145 | "SIZE=50x",
146 | )
147 | pad.sts2 = iup.Label(
148 | "TITLE=\"Lin:1 Col:1\"",
149 | "EXPAND=NO",
150 | "SIZE=60x",
151 | )
152 | pad.dlg = iup.Dialog(
153 | iup.Attrs(
154 | "MENU", "main_menu",
155 | "TITLE", "Notepad",
156 | "SHRINK", "YES",
157 | "SIZE", "300x200",
158 | ),
159 | iup.Vbox(
160 | pad.edit,
161 | iup.Hbox(
162 | pad.sts1,
163 | iup.Fill(),
164 | pad.sts2,
165 | ),
166 | ),
167 | func(arg *iup.DialogClose) {
168 | pad.CheckModify()
169 | arg.Return = iup.CLOSE
170 | },
171 | )
172 | return pad
173 | }
174 |
175 | func (pad *Notepad) CheckModify() {
176 | if pad.modify == false {
177 | return
178 | }
179 | msg := iup.MessageDlg(
180 | iup.Attrs(
181 | "DIALOGTYPE", "WARNING",
182 | "TITLE", "Notepad",
183 | "BUTTONS", "YESNO",
184 | "VALUE", "File is Modify, Save File",
185 | ),
186 | )
187 | msg.Popup(iup.CENTERPARENT, iup.CENTERPARENT)
188 | defer msg.Destroy()
189 | if msg.GetAttribute("BUTTONRESPONSE") == "2" {
190 | return
191 | }
192 | pad.Save()
193 | }
194 |
195 | func (pad *Notepad) Save() {
196 | fileName := pad.fileName
197 | if fileName == "" {
198 | pad.SaveAS()
199 | } else {
200 | pad.SaveFile(fileName)
201 | }
202 | }
203 |
204 | func (pad *Notepad) SaveAS() {
205 | if name, ok := iup.GetSaveFile("", "*.*"); ok {
206 | pad.SaveFile(name)
207 | }
208 | }
209 |
210 | func (pad *Notepad) NewFile() {
211 | pad.CheckModify()
212 |
213 | pad.edit.SetAttribute("VALUE", "")
214 | pad.sts1.SetAttribute("TITLE", "Ready")
215 | pad.sts2.SetAttribute("TITLE", "Lin:1 Col:1 ")
216 | pad.SetFileName("")
217 | }
218 |
219 | func (pad *Notepad) Open() {
220 | pad.CheckModify()
221 | if name, ok := iup.GetOpenFile("", "*.*"); ok {
222 | pad.OpenFile(name)
223 | }
224 | }
225 |
226 | func (pad *Notepad) OpenFile(fileName string) bool {
227 | data, e := ioutil.ReadFile(fileName)
228 | if e != nil {
229 | return false
230 | }
231 | pad.edit.SetAttribute("VALUE", string(data))
232 | pad.SetFileName(fileName)
233 | return true
234 | }
235 |
236 | func (pad *Notepad) SaveFile(fileName string) bool {
237 | data := pad.edit.GetAttribute("VALUE")
238 | e := ioutil.WriteFile(fileName, []byte(data), 0666)
239 | if e != nil {
240 | return false
241 | }
242 | pad.SetFileName(fileName)
243 | return true
244 | }
245 |
246 | func (pad *Notepad) SetFileName(fileName string) {
247 | pad.modify = false
248 | pad.fileName = fileName
249 | if fileName == "" {
250 | pad.dlg.SetAttribute("TITLE", "[noname] - Notepad")
251 | } else {
252 | pad.dlg.SetAttribute("TITLE", "["+fileName+"] - Notepad")
253 | }
254 | }
255 |
256 | func (pad *Notepad) SetModify() {
257 | pad.modify = true
258 | if pad.fileName == "" {
259 | pad.dlg.SetAttribute("TITLE", "[noname*] - Notepad")
260 | } else {
261 | pad.dlg.SetAttribute("TITLE", "["+pad.fileName+"*] - Notepad")
262 | }
263 | }
264 |
265 | func main() {
266 | e := iup.Open()
267 | if e != nil {
268 | fmt.Println(e)
269 | return
270 | }
271 | defer iup.Close()
272 |
273 | pad := new(Notepad).init()
274 | pad.NewFile()
275 | pad.dlg.Show()
276 | iup.MainLoop()
277 | }
278 |
--------------------------------------------------------------------------------
/examples/notepad/make.bat:
--------------------------------------------------------------------------------
1 | windres rc/goiup.rc -o temp-rc.o
2 |
3 | set GOIUPPKG=../../../../../../pkg/windows_386
4 | set SRC=main.go
5 | set OUT=notepad
6 |
7 | go tool 8g -I%GOIUPPKG% %SRC%
8 |
9 | go tool pack grc _go_.8 main.8 temp-rc.o
10 |
11 | go tool 8l -L%GOIUPPKG% -s -Hwindowsgui -o %OUT%.exe _go_.8
12 |
13 | rm *.8 *.o
--------------------------------------------------------------------------------
/examples/notepad/rc/goiup.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/visualfc/go-iup/e6afc2277af81f0c4f7189db74321ba766af085c/examples/notepad/rc/goiup.ico
--------------------------------------------------------------------------------
/examples/notepad/rc/goiup.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
11 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/examples/notepad/rc/goiup.rc:
--------------------------------------------------------------------------------
1 | IDI_ICON ICON "goiup.ico"
2 | 1 24 "goiup.manifest"
3 |
--------------------------------------------------------------------------------
/iup/_cgo_export.h:
--------------------------------------------------------------------------------
1 | /* Created by cgo - DO NOT EDIT. */
2 |
3 | typedef unsigned int uint;
4 | typedef signed char schar;
5 | typedef unsigned char uchar;
6 | typedef unsigned short ushort;
7 | typedef long long int64;
8 | typedef unsigned long long uint64;
9 | typedef __SIZE_TYPE__ uintptr;
10 |
11 | typedef struct { char *p; int n; } GoString;
12 | typedef void *GoMap;
13 | typedef void *GoChan;
14 | typedef struct { void *t; void *v; } GoInterface;
15 |
16 |
--------------------------------------------------------------------------------
/iup/csutil_linux.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011-2012 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | package iup
6 |
7 | /*
8 | #include
9 | #include
10 | char *CStringN(char *buf, int len, int max)
11 | {
12 | char *ansi = malloc(max);
13 | memcpy(ansi,buf,len);
14 | ansi[len] = '\0';
15 | return ansi;
16 | }
17 | */
18 | import "C"
19 | import "unsafe"
20 | import "reflect"
21 |
22 | func NewCSN(s string, max int) *C.char {
23 | head := (*reflect.StringHeader)(unsafe.Pointer(&s))
24 | return C.CStringN((*C.char)(unsafe.Pointer(head.Data)), C.int(len(s)), C.int(max))
25 | }
26 |
27 | func NewCS(s string) *C.char {
28 | return C.CString(s)
29 | }
30 |
31 | func FreeCS(cs *C.char) {
32 | C.free(unsafe.Pointer(cs))
33 | }
34 |
35 | func NewCSA(sa []string) []*C.char {
36 | max := len(sa)
37 | csa := make([]*C.char, max+1)
38 | for i := 0; i < max; i++ {
39 | csa[i] = NewCS(sa[i])
40 | }
41 | csa[max] = nil
42 | return csa
43 | }
44 |
45 | func FreeCSA(csa []*C.char) {
46 | max := len(csa)
47 | for i := 0; i < max; i++ {
48 | if csa[i] != nil {
49 | C.free(unsafe.Pointer(csa[i]))
50 | }
51 | }
52 | }
53 |
54 | func FromCS(cs *C.char) string {
55 | return C.GoString(cs)
56 | }
57 |
58 | func FromCSA(csa []*C.char) []string {
59 | size := len(csa)
60 | if size == 0 {
61 | return nil
62 | }
63 | array := make([]string, size)
64 | for i := 0; i < size; i++ {
65 | array[i] = FromCS(csa[i])
66 | }
67 | return array
68 | }
69 |
--------------------------------------------------------------------------------
/iup/csutil_windows.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011-2012 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | package iup
6 |
7 | /*
8 | #include
9 | #include
10 | char *Utf8toAnsi(char *buf, int len)
11 | {
12 | int ulen = MultiByteToWideChar(CP_UTF8,0,buf,len,0,0);
13 | unsigned short *utf = malloc(ulen*2);
14 | ulen = MultiByteToWideChar(CP_UTF8,0,buf,len,utf,ulen*2);
15 | int clen = WideCharToMultiByte(CP_ACP,0,utf,ulen,0,0,0,0);
16 | char *ansi = malloc(clen+1);
17 | clen = WideCharToMultiByte(CP_ACP,0,utf,ulen,ansi,clen,0,0);
18 | ansi[clen] = '\0';
19 | free(utf);
20 | return ansi;
21 | }
22 |
23 | char *Utf8toAnsiN(char *buf, int len, int max)
24 | {
25 | int ulen = MultiByteToWideChar(CP_UTF8,0,buf,len,0,0);
26 | unsigned short *utf = malloc(ulen*2);
27 | ulen = MultiByteToWideChar(CP_UTF8,0,buf,len,utf,ulen*2);
28 | int clen = WideCharToMultiByte(CP_ACP,0,utf,ulen,0,0,0,0);
29 | char *ansi = malloc(max);
30 | memset(ansi,max,0);
31 | clen = WideCharToMultiByte(CP_ACP,0,utf,ulen,ansi,clen,0,0);
32 | ansi[clen] = '\0';
33 | free(utf);
34 | return ansi;
35 | }
36 |
37 | char *AnsiToUtf8(char *buf, int *size)
38 | {
39 | int len = strlen(buf);
40 | int ulen = MultiByteToWideChar(CP_ACP,0,buf,len,0,0);
41 | unsigned short *utf = malloc(ulen*2);
42 | ulen = MultiByteToWideChar(CP_ACP,0,buf,len,utf,ulen*2);
43 | len = WideCharToMultiByte(CP_UTF8,0,utf,ulen,0,0,0,0);
44 | char *utf8 = malloc(len+1);
45 | len = WideCharToMultiByte(CP_UTF8,0,utf,ulen,utf8,len,0,0);
46 | utf8[len] = '\0';
47 | free(utf);
48 | *size = len;
49 | return utf8;
50 | }
51 | */
52 | import "C"
53 | import "unsafe"
54 | import "reflect"
55 |
56 | func NewCS(s string) *C.char {
57 | if len(s) == 0 {
58 | return C.CString(s)
59 | }
60 | head := (*reflect.StringHeader)(unsafe.Pointer(&s))
61 | return C.Utf8toAnsi((*C.char)(unsafe.Pointer(head.Data)), C.int(len(s)))
62 | }
63 |
64 | func NewCSN(s string, max int) *C.char {
65 | head := (*reflect.StringHeader)(unsafe.Pointer(&s))
66 | return C.Utf8toAnsiN((*C.char)(unsafe.Pointer(head.Data)), C.int(len(s)), C.int(max))
67 | }
68 |
69 | func FreeCS(cs *C.char) {
70 | C.free(unsafe.Pointer(cs))
71 | }
72 |
73 | func NewCSA(sa []string) []*C.char {
74 | max := len(sa)
75 | csa := make([]*C.char, max+1)
76 | for i := 0; i < max; i++ {
77 | csa[i] = NewCS(sa[i])
78 | }
79 | csa[max] = nil
80 | return csa
81 | }
82 |
83 | func FreeCSA(csa []*C.char) {
84 | max := len(csa)
85 | for i := 0; i < max; i++ {
86 | if csa[i] != nil {
87 | C.free(unsafe.Pointer(csa[i]))
88 | }
89 | }
90 | }
91 |
92 | func FromCS(cs *C.char) string {
93 | if cs == nil {
94 | return ""
95 | }
96 | var size C.int
97 | buf := C.AnsiToUtf8(cs, &size)
98 | defer C.free(unsafe.Pointer(buf))
99 | return string((*[1 << 30]byte)(unsafe.Pointer(buf))[0:size])
100 | }
101 |
102 | func FromCSA(csa []*C.char) []string {
103 | size := len(csa)
104 | if size == 0 {
105 | return nil
106 | }
107 | array := make([]string, size)
108 | for i := 0; i < size; i++ {
109 | array[i] = FromCS(csa[i])
110 | }
111 | return array
112 | }
113 |
--------------------------------------------------------------------------------
/iup/dialog.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011-2012 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | package iup
6 |
7 | /*
8 | #include
9 | #include
10 | */
11 | import "C"
12 | import (
13 | "strings"
14 | "unsafe"
15 | )
16 |
17 | func Alarm(title, message string, btns ...string) int {
18 | var b1 *C.char = nil
19 | var b2 *C.char = nil
20 | var b3 *C.char = nil
21 | t := NewCS(title)
22 | defer FreeCS(t)
23 | m := NewCS(message)
24 | defer FreeCS(m)
25 | l := len(btns)
26 | if l >= 3 {
27 | b3 = NewCS(btns[2])
28 | defer FreeCS(b3)
29 | }
30 | if l >= 2 {
31 | b2 = NewCS(btns[1])
32 | defer FreeCS(b2)
33 | }
34 | if l >= 1 {
35 | b1 = NewCS(btns[0])
36 | defer FreeCS(b1)
37 | }
38 | return int(C.IupAlarm(t, m, b1, b2, b3))
39 | }
40 |
41 | func GetOpenFile(dir string, filter string) (string, bool) {
42 | dlg := FileDlg(
43 | Attrs(
44 | "DIALOGTYPE", "Open",
45 | "FILTER", filter,
46 | "DIRECTORY", dir,
47 | "NOCHANGEDIR", "YES",
48 | "PARENTDIALOG", GetGlobal("PARENTDIALOG"),
49 | "ICON", GetGlobal("ICON"),
50 | ),
51 | )
52 | dlg.Popup(CENTERPARENT, CENTERPARENT)
53 | defer dlg.Destroy()
54 | return dlg.GetAttribute("VALUE"), dlg.GetInt("STATUS") == 0
55 | }
56 |
57 | func GetSaveFile(dir string, filter string) (string, bool) {
58 | dlg := FileDlg(
59 | Attrs(
60 | "DIALOGTYPE", "Save",
61 | "FILTER", filter,
62 | "DIRECTORY", dir,
63 | "ALLOWNEW", "YES",
64 | "NOCHANGEDIR", "YES",
65 | "PARENTDIALOG", GetGlobal("PARENTDIALOG"),
66 | "ICON", GetGlobal("ICON"),
67 | ),
68 | )
69 | dlg.Popup(CENTERPARENT, CENTERPARENT)
70 | defer dlg.Destroy()
71 | return dlg.GetAttribute("VALUE"), dlg.GetInt("STATUS") != -1
72 | }
73 |
74 | func GetColor(x, y int, r, g, b *byte) int {
75 | return int(C.IupGetColor(C.int(x), C.int(y), (*C.uchar)(r), (*C.uchar)(b), (*C.uchar)(b)))
76 | }
77 |
78 | /*
79 | The format string must have the following format, notice the "\n" at the end
80 |
81 | "text%x[extra]{tip}\n", where:
82 |
83 | text is a descriptive text, to be placed to the left of the entry field in a label.
84 |
85 | x is the type of the parameter. The valid options are:
86 |
87 | b = boolean (shows a True/False toggle, use "int" in C)
88 | i = integer (shows a integer number filtered text box, use "int" in C)
89 | r = real (shows a real number filtered text box, use "float" in C)
90 | a = angle in degrees (shows a real number filtered text box and a dial [if IupControlsOpen is called], use "float" in C)
91 | s = string (shows a text box, use "char*" in C, it must have room enough for your string)
92 | m = multiline string (shows a multiline text box, use "char*" in C, it must have room enough for your string)
93 | l = list (shows a dropdown list box, use "int" in C for the zero based item index selected)
94 | o = list (shows a list of toggles inside a radio, use "int" in C for the zero based item index selected) (since 3.3)
95 | t = separator (shows a horizontal line separator label, in this case text can be an empty string, not included in parameter count)
96 | f = string (same as s, but also show a button to open a file selection dialog box)
97 | c = string (same as s, but also show a color button to open a color selection dialog box)
98 | n = string (same as s, but also show a font button to open a font selection dialog box) (since 3.3)
99 | u = buttons names (allow to redefine the OK and Cancel button names, and to add a Help button, use [ok,cancel,help] as extra data, can omit one of them, it will use the default name, not included in parameter count) (since 3.1)
100 |
101 | bool int float32 float64 string
102 | */
103 |
104 | func GetParam(title string, format string, out ...interface{}) bool {
105 | extra := strings.Count(format, "%t") + strings.Count(format, "%u")
106 | count := strings.Count(format, "\n") - extra
107 | t := NewCS(title)
108 | defer FreeCS(t)
109 | f := NewCS(format)
110 | defer FreeCS(f)
111 | args := make([]unsafe.Pointer, count+1)
112 | for i := 0; i < count; i++ {
113 | args[i] = nil
114 | switch v := out[i].(type) {
115 | case *bool:
116 | p := new(C.int)
117 | if *v {
118 | *p = 1
119 | } else {
120 | *p = 0
121 | }
122 | args[i] = unsafe.Pointer(p)
123 | case *int:
124 | args[i] = unsafe.Pointer(v)
125 | case *uint:
126 | args[i] = unsafe.Pointer(v)
127 | case *float32:
128 | args[i] = unsafe.Pointer(v)
129 | case *float64:
130 | args[i] = unsafe.Pointer(v)
131 | case *string:
132 | buf := NewCSN(*v, 4096)
133 | args[i] = unsafe.Pointer(buf)
134 | default:
135 | return false
136 | }
137 | }
138 | args[count] = nil
139 | r := C.IupGetParamv(t, nil, nil, f, C.int(count), C.int(extra), (*unsafe.Pointer)(&args[0]))
140 | if r == 0 {
141 | return false
142 | }
143 | for i := 0; i < count; i++ {
144 | switch v := out[i].(type) {
145 | case *bool:
146 | *v = *(*int)(args[i]) != 0
147 | case *string:
148 | *v = FromCS((*C.char)(args[i]))
149 | }
150 | }
151 | return true
152 | }
153 |
154 | func ListDialog(typ int, title string, list []string, opt, max_col, max_lin int, marks []int) int {
155 | t := NewCS(title)
156 | defer FreeCS(t)
157 |
158 | clist := NewCSA(list)
159 | defer FreeCSA(clist)
160 |
161 | r := C.IupListDialog(C.int(typ), t, C.int(len(list)), &clist[0], C.int(opt), C.int(max_col), C.int(max_lin), (*C.int)(unsafe.Pointer(&marks[0])))
162 | return int(r)
163 | }
164 |
165 | func Message(title string, message string) {
166 | t := NewCS(title)
167 | defer FreeCS(t)
168 | m := NewCS(message)
169 | defer FreeCS(m)
170 | C.IupMessage(t, m)
171 | }
172 |
173 | func LayoutDialog(h IHandle) IHandle {
174 | return toHandle(C.IupLayoutDialog(toNative(h)))
175 | }
176 |
177 | func ElementPropertiesDialog(h IHandle) IHandle {
178 | return toHandle(C.IupElementPropertiesDialog(toNative(h)))
179 | }
180 |
181 | func Image(width, height int, pixels []byte) IHandle {
182 | return toHandle(C.IupImage(C.int(width), C.int(height), (*C.uchar)(&pixels[0])))
183 | }
184 |
185 | func ImageRGB(width, height int, pixels []byte) IHandle {
186 | return toHandle(C.IupImageRGB(C.int(width), C.int(height), (*C.uchar)(&pixels[0])))
187 | }
188 |
189 | func ImageRGBA(width, height int, pixels []byte) IHandle {
190 | return toHandle(C.IupImageRGBA(C.int(width), C.int(height), (*C.uchar)(&pixels[0])))
191 | }
192 |
193 | func GetText(title string, data string) (string, bool) {
194 | t := NewCS(title)
195 | defer FreeCS(t)
196 | d := NewCSN(data, 4096)
197 | defer FreeCS(d)
198 | r := C.IupGetText(t, d)
199 | return FromCS(d), r != 0
200 | }
201 |
202 | /*
203 |
204 | func GetText(title, value string) (bool, string) {
205 | return GetTextParam(title, value, "OK", "Cancel")
206 | }
207 | func GetTextParam(title, value, title_ok, title_cancel string) (bool, string) {
208 | text := Text(
209 | Attrs("MULTILINE", "YES",
210 | "EXPAND", "YES",
211 | "VALUE", value,
212 | "FONT", "Courier,12",
213 | "VISIBLELINES", "10",
214 | "VISIBLECOLUMNS", "50",
215 | ),
216 | )
217 |
218 | ok := Button(
219 | Attr("PADDING", "20x5"),
220 | Attr("TITLE", title_ok),
221 | func(arg *ButtonAction) {
222 | arg.Sender.GetDialog().SetAttribute("STATUS", "1")
223 | arg.Return = CLOSE
224 | },
225 | )
226 |
227 | cancel := Button(
228 | Attr("PADDING", "20x5"),
229 | Attr("TITLE", title_cancel),
230 | func(arg *ButtonAction) {
231 | arg.Sender.GetDialog().SetAttribute("STATUS", "-1")
232 | arg.Return = CLOSE
233 | },
234 | )
235 |
236 | dlg := Dialog(
237 | "MINBOX=NO,MAXBOX=NO,SIZE=200x150",
238 | Attr("TITLE", title),
239 | Attr("ICON", GetGlobal("ICON")),
240 | Attr("PARENTDIALOG", GetGlobal("PARENTDIALOG")),
241 | Vbox(
242 | "MARGIN=10x10",
243 | "GAP=10",
244 | text,
245 | Hbox(
246 | "MARGIN=0x0",
247 | "NORMALIZESIZE=HORZONTAL",
248 | Fill(),
249 | ok,
250 | cancel,
251 | ),
252 | ),
253 | )
254 | defer dlg.Destroy()
255 | dlg.SetAttributeHandle("DEFAULTENTER", ok)
256 | dlg.SetAttributeHandle("DEFAULTESC", cancel)
257 |
258 | dlg.Map()
259 |
260 | text.SetAttribute("VISIBLELINES", "")
261 | text.SetAttribute("VISIBLECOLUMNS", "")
262 |
263 | dlg.Popup(CENTERPARENT, CENTERPARENT)
264 | if dlg.GetAttribute("STATUS") == "-1" {
265 | return false, ""
266 | }
267 | return true, text.GetAttribute("VALUE")
268 | }
269 |
270 | */
271 |
272 | func Help(url string) {
273 | curl := NewCS(url)
274 | defer FreeCS(curl)
275 | C.IupHelp(curl)
276 | }
277 |
--------------------------------------------------------------------------------
/iup/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011-2012 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | /*
6 | goiup document
7 | */
8 | package documentation
9 |
--------------------------------------------------------------------------------
/iup/errors.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011-2012 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | package iup
6 |
7 | import (
8 | "fmt"
9 | )
10 |
11 | type Error struct {
12 | Name string
13 | }
14 |
15 | func (e *Error) Error() string {
16 | return fmt.Sprintf("Error %s", e.Name)
17 | }
18 |
--------------------------------------------------------------------------------
/iup/gencb.lua:
--------------------------------------------------------------------------------
1 | code_head = [[
2 | // Copyright (C) 2011-2012 visualfc. All rights reserved.
3 | // Use of this source code is governed by a MIT license
4 | // that can be found in the COPYRIGHT file.
5 |
6 | // gencb.lua
7 | // MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
8 |
9 | package iup
10 |
11 | /*
12 | #include
13 | #include
14 | #define GOIUP "_GOIUP_"
15 | ]]
16 |
17 | code_head_d = [[
18 | // IUP definitions not defined
19 | #define IUP_UNMAP_CB "UNMAP_CB"
20 | #define IUP_DESTROY_CB "DESTROY_CB"
21 | #define IUP_CARET_CB "CARET_CB"
22 | #define IUP_DBLCLICK_CB "DBLCLICK_CB"
23 | #define IUP_EDIT_CB "EDIT_CB"
24 | #define IUP_MULTISELECT_CB "MULTISELECT_CB"
25 | #define IUP_VALUECHANGED_CB "VALUECHANGED_CB"
26 | #define IUP_TABCHANGE_CB "TABCHANGE_CB"
27 | #define IUP_TABCHANGEPOS_CB "TABCHANGEPOS_CB"
28 | #define IUP_SPIN_CB "SPIN_CB"
29 | #define IUP_FILE_CB "FILE_CB"
30 | #define IUP_FOCUS_CB "FOCUS_CB"
31 | #define IUP_TOUCH_CB "TOUCH_CB"
32 | #define IUP_MULTITOUCH_CB "MULTITOUCH_CB"
33 | #define IUP_DROPDOWN_CB "DROPDOWN_CB"
34 | #define IUP_MULTISELECTION_CB "MULTISELECTION_CB"
35 | #define IUP_SHOWRENAME_CB "SHOWRENAME_CB"
36 | #define IUP_RENAME_CB "RENAME_CB"
37 | #define IUP_DRAGDROP_CB "DRAGDROP_CB"
38 | #define IUP_NODEREMOVED_CB "NODEREMOVED_CB"
39 | #define IUP_BUTTON_PRESS_CB "BUTTON_PRESS_CB"
40 | #define IUP_BUTTON_RELEASE_CB "BUTTON_RELEASE_CB"
41 | #define IUP_ACTION_CB "ACTION_CB"
42 | #define IUP_RELEASE_CB "RELEASE_CB"
43 | #define IUP_SCROLLTOP_CB "SCROLLTOP_CB"
44 | #define IUP_BGCOLOR_CB "BGCOLOR_CB"
45 | #define IUP_FGCOLOR_CB "FGCOLOR_CB"
46 | #define IUP_FONT_CB "FONT_CB"
47 | #define IUP_MARK_CB "MARK_CB"
48 | #define IUP_MARKEDIT_CB "MARKEDIT_CB"
49 | #define IUP_DELETE_CB "DELETE_CB"
50 | #define IUP_DELETEBEGIN_CB "DELETEBEGIN_CB"
51 | #define IUP_DELETEEND_CB "DELETEEND_CB"
52 | #define IUP_SELECTBEGIN_CB "SELECTBEGIN_CB"
53 | #define IUP_SELECTEND_CB "SELECTEND_CB"
54 | #define IUP_EDITBEGIN_CB "EDITBEGIN_CB"
55 | #define IUP_EDITEND_CB "EDITEND_CB"
56 | #define IUP_PREDRAW_CB "PREDRAW_CB"
57 | #define IUP_POSTDRAW_CB "POSTDRAW_CB"
58 | #define IUP_COMPLETED_CB "COMPLETED_CB"
59 | #define IUP_ERROR_CB "ERROR_CB"
60 | #define IUP_NAVIGATE_CB "NAVIGATE_CB"
61 | #define IUP_NEWWINDOW_CB "NEWWINDOW_CB"
62 | ]]
63 |
64 | code_import = [[
65 | */
66 | import "C"
67 | import (
68 | "unsafe"
69 | )
70 | ]]
71 |
72 | code_n_case_head = [[
73 | func (h *Handle) SetCallback(fn interface{}) {
74 | switch v := fn.(type) {
75 | ]]
76 |
77 | code_n_case_end = [[
78 | }
79 | }
80 | ]]
81 |
82 | code_id_head = [[
83 | const (
84 | ]]
85 | code_id_end = [[
86 | )
87 | ]]
88 |
89 | code_reg_head = [[
90 | func RegisterAllClass() {
91 | ]]
92 | code_reg_head_ctls = [[
93 | func RegisterCtlsClass() {
94 | ]]
95 | code_reg_end = [[
96 | }
97 | ]]
98 |
99 | -- global table
100 |
101 | t_cb = {}
102 |
103 | t_cmn_call = {}
104 | t_id_call = {}
105 |
106 | t_id_tag = {}
107 | t_id_reg = {}
108 | t_id_new = {}
109 | t_id_callback = {}
110 | t_id_case = {}
111 |
112 | t_c_tmpl = {}
113 | t_go_type = {}
114 | t_go_tmpl = {}
115 |
116 | item_name = nil
117 |
118 | function begin_common()
119 | t_id_case = {}
120 | t_id_call = {}
121 | end
122 |
123 |
124 | function end_common()
125 | local head = [[
126 | func common_SetCallback(h *Handle, fn interface{}) bool {
127 | switch fn.(type) {
128 | ]]
129 | local _end = [[
130 | default:
131 | return false
132 | }
133 | return true
134 | }
135 | ]]
136 | t_cmn_call = t_id_call
137 | t_id_call = {}
138 | t_id_callback[#t_id_callback+1] = head .. table.concat(t_id_case) .. _end
139 | t_id_case = {}
140 | end
141 |
142 | function begin_item(name)
143 | t_id_case = {}
144 | t_id_call = {}
145 | assert(item_name == nil,"error call end_item")
146 | item_name = name
147 | end
148 |
149 | function end_item(use_common)
150 | local Name = item_name
151 | item_name = nil
152 | if Name == "_" then
153 | return
154 | end
155 | use_common = use_common or false
156 | local _head0 = [[
157 | func name_SetCallback(h *Handle, fn interface{}) bool {
158 | ]]
159 | local _end0 = [[
160 | return false
161 | }
162 | ]]
163 | local _head = [[
164 | func name_SetCallback(h *Handle, fn interface{}) bool {
165 | switch fn.(type) {
166 | ]]
167 | local _end1 = [[
168 | default:
169 | return false
170 | }
171 | return true
172 | }
173 | ]]
174 | local _end2 = [[
175 | default:
176 | return common_SetCallback(h,fn)
177 | }
178 | return true
179 | }
180 | ]]
181 | local _reg = [[
182 | RegisterClass("CLS",NewClassInfo("CLS",name_SetCallback))
183 | ]]
184 | local _id = [[
185 | TAG = "CLS"
186 | ]]
187 | local _new = [[
188 | // Iup control NAME
189 | //
190 | // CALLBACKS
191 | func NAME(a ...interface{}) *Handle {
192 | return New(TAG, a...)
193 | }
194 | ]]
195 | local tag = string.upper(Name)
196 | local cls = string.lower(Name)
197 | if use_common == true then
198 | for k, v in ipairs(t_cmn_call) do
199 | t_id_call[#t_id_call+1] = v
200 | end
201 | end
202 | local callback_doc = table.concat(t_id_call,"\n//\n// ")
203 |
204 | local head = _head
205 | if #t_id_case == 0 then
206 | head = _head0--string.gsub(head,"V","_")
207 | else
208 | head = string.gsub(head,"V","v")
209 | end
210 | head = string.gsub(head,"name",string.lower(Name))
211 | local reg = string.gsub(_reg,"CLS",cls)
212 | reg = string.gsub(reg,"name",string.lower(Name))
213 | local id = string.gsub(_id,"TAG",tag)
214 | id = string.gsub(id,"CLS",cls)
215 | local new = string.gsub(_new,"NAME",Name)
216 | new = string.gsub(new,"TAG",tag)
217 | new = string.gsub(new,"CALLBACKS",callback_doc)
218 | t_id_tag[#t_id_tag+1] = id
219 | t_id_reg[#t_id_reg+1] = reg
220 | t_id_new[#t_id_new+1] = new
221 | local _end = _end1
222 | if #t_id_case == 0 then
223 | _end = _end0
224 | end
225 | if use_common == true then
226 | _end = _end2
227 | end
228 | t_id_callback[#t_id_callback+1] = head .. table.concat(t_id_case) .. _end
229 | t_id_case = {}
230 | end
231 |
232 | b_change_s = false
233 | -- funcion in
234 | function gen_in(ACT,ActCB,fmt,...)
235 | local fmt = fmt or ""
236 | t_id_call[#t_id_call+1] = "Callback ".. ACT .. " : func(arg *"..ActCB..")"
237 | local c_tmpl_i = [[
238 | extern int goActionCb(PARAMS_C);
239 | static void iupSetActionCb(Ihandle* ih)
240 | {
241 | IupSetCallback(ih,IUP_ACTION,(Icallback)&goActionCb);
242 | }
243 | ]]
244 | local c_tmpl_s = [[
245 | extern char* goActionCb(PARAMS_C);
246 | static void iupSetActionCb(Ihandle* ih)
247 | {
248 | IupSetCallback(ih,IUP_ACTION,(Icallback)&goActionCb);
249 | }
250 | ]]
251 |
252 | local go_type = [[
253 | // Iup callback IUP_ACTION
254 | type ActionCb struct {
255 | PARAM_TYPE
256 | }
257 | ]]
258 |
259 | local go_case = [[
260 | case func(*ActionCb):
261 | C.iupSetActionCb(h.p)
262 | h.funcs["ActionCb"] = fn
263 | ]]
264 |
265 | local go_tmpl_i = [[
266 | //export goActionCb
267 | func goActionCb(PARAMS_GO) int {
268 | ih := ptoHandle(p)
269 | if ih == nil {
270 | return DEFAULT
271 | }
272 | if h,ok := ih.(*Handle); ok {
273 | if f,ok := h.funcs["ActionCb"]; ok {
274 | if fn, ok := f.(func(*ActionCb)); ok {
275 | arg := &ActionCb{PARAMS_ACT}
276 | fn(arg)
277 | return arg.Return
278 | }
279 | }
280 | }
281 | return DEFAULT
282 | }
283 | ]]
284 | local go_tmpl_s = [[
285 | //export goActionCb
286 | func goActionCb(PARAMS_GO) *C.char {
287 | ih := ptoHandle(p)
288 | if ih == nil {
289 | return nil
290 | }
291 | if h,ok := ih.(*Handle); ok {
292 | if f,ok := h.funcs["ActionCb"]; ok {
293 | if fn, ok := f.(func(*ActionCb)); ok {
294 | arg := &ActionCb{PARAMS_ACT}
295 | fn(arg)
296 | size := len(arg.Return)
297 | ch := make([]byte,size+1)
298 | copy(ch,arg.Return)
299 | ch[size] = 0
300 | return (*C.char)(unsafe.Pointer(&ch[0]))
301 | }
302 | }
303 | }
304 | return nil
305 | }
306 | ]]
307 |
308 | local arg = {...}
309 | local tb_c = {n="void*",i="int",I="int*",s="char*",f="float",F="float*",c="unsigned char",C="void*",d="double",U="unsigned int*"}
310 | local tb_go = {n="unsafe.Pointer",i="int",I="*int",s="*C.char",f="float32",F="*float32",c="C.uchar",C="unsafe.Pointer",d="float64",U="*C.uint"}
311 | local tb_type = {n="*Handle",i="int",I="*int",s="string",f="float32",F="*float32",c="byte",C="unsafe.Pointer",d="float64",U="*uint"}
312 | local p_type ={}
313 | local p_go = {}
314 | local p_c = {}
315 | local p_act = {}
316 | p_c[#p_c+1] = "void*"
317 | p_type[#p_type+1] = "Sender *Handle"
318 | if b_change_s == true then
319 | p_type[#p_type+1] = "Return string"
320 | else
321 | p_type[#p_type+1] = "Return int"
322 | end
323 | p_go[#p_go+1] = "p unsafe.Pointer"
324 | p_act[#p_act+1] = "h"
325 | if b_change_s == true then
326 | p_act[#p_act+1] = "\"\""
327 | else
328 | p_act[#p_act+1] = "DEFAULT"
329 | end
330 | if fmt ~= "" then
331 | assert(#fmt == #arg,"conv error fmt ".. ACT)
332 | for i=1,#fmt do
333 | local f = string.sub(fmt,i,i)
334 | local a = arg[i]
335 | local n = "N" .. i
336 | p_c[#p_c+1] = tb_c[f]
337 | p_type[#p_type+1] = a .. " " .. tb_type[f]
338 | p_go[#p_go+1] = n .. " " .. tb_go[f]
339 | if f == "s" then
340 | p_act[#p_act+1] = "C.GoString(" .. n .. ")"
341 | elseif f == "n" then
342 | p_act[#p_act+1] = "(*Handle)(" .. n .. ")"
343 | elseif f == "c" then
344 | p_act[#p_act+1] = "byte(".. n ..")"
345 | elseif f == "U" then
346 | p_act[#p_act+1] = "(*uint)(unsafe.Pointer(".. n .. "))"
347 | else
348 | p_act[#p_act+1] = n
349 | end
350 | end
351 | end
352 |
353 |
354 | local c_tmpl = c_tmpl_i
355 | local go_tmpl = go_tmpl_i
356 | if b_change_s == true then
357 | c_tmpl = c_tmpl_s
358 | go_tmpl = go_tmpl_s
359 | end
360 | c_tmpl = string.gsub(c_tmpl,"ACTION",ACT)
361 | c_tmpl = string.gsub(c_tmpl,"ActionCb",ActCB)
362 | c_tmpl = string.gsub(c_tmpl,"PARAMS_C",table.concat(p_c,","))
363 | go_type = string.gsub(go_type,"ACTION",ACT)
364 | go_type = string.gsub(go_type,"ActionCb",ActCB)
365 | go_type = string.gsub(go_type,"PARAM_TYPE",table.concat(p_type,"\n\t"))
366 | go_case = string.gsub(go_case,"ActionCb",ActCB)
367 | go_tmpl = string.gsub(go_tmpl,"ActionCb",ActCB)
368 | go_tmpl = string.gsub(go_tmpl,"PARAMS_GO",table.concat(p_go,","))
369 | go_tmpl = string.gsub(go_tmpl,"PARAMS_ACT",table.concat(p_act,","))
370 |
371 | if t_cb[ActCB] ~= nil then
372 | assert(t_cb[ActCB] == fmt,ActCB .. " unequal format ".. t_cb[ActCB] .. "<>".. fmt)
373 | t_id_case[#t_id_case+1] = go_case
374 | return
375 | end
376 | t_cb[ActCB] = fmt
377 |
378 | t_c_tmpl[#t_c_tmpl+1] = c_tmpl
379 | t_go_type[#t_go_type+1] = go_type
380 | t_id_case[#t_id_case+1] = go_case
381 | t_go_tmpl[#t_go_tmpl+1] = go_tmpl
382 | end
383 |
384 | function gen_sn(ACT,ActCB,fmt,...)
385 | b_change_s = true
386 | gen_in(ACT,ActCB,fmt,...)
387 | b_change_s = false
388 | end
389 |
390 | function clear()
391 | t_cb = {}
392 |
393 | t_id_tag = {}
394 | t_id_reg = {}
395 | t_id_new = {}
396 | t_id_callback = {}
397 | t_id_case = {}
398 |
399 | t_c_tmpl = {}
400 | t_go_type = {}
401 | t_go_tmpl = {}
402 |
403 | item_name = nil
404 | all = {}
405 | end
406 |
407 | function gen_iup()
408 | begin_common()
409 | gen_in("DEFAULT_ACTION","CommonDefaultAction")
410 | gen_in("MAP_CB","CommonMap")
411 | gen_in("UNMAP_CB","CommonUnmap")
412 | gen_in("DESTROY_CB","CommonDestroy")
413 | gen_in("GETFOCUS_CB","CommonGetFocus")
414 | gen_in("KILLFOCUS_CB","CommonKillFocus")
415 | gen_in("ENTERWINDOW_CB","CommonEnterWindow")
416 | gen_in("LEAVEWINDOW_CB","CommonLeaveWindow")
417 | gen_in("HELP_CB","CommonHelp")
418 | gen_in("K_ANY","CommonKeyAny","i","Key")
419 | end_common()
420 |
421 | begin_item("Dialog")
422 | gen_in("CLOSE_CB","DialogClose")
423 | gen_in("RESIZE_CB","DialogResize","ii","Width","Height")
424 | gen_in("DROPFILES_CB","DialogDropFiles","siii","FileName","Num","X","Y")
425 | gen_in("SHOW_CB","DialogShow","i","State")
426 | end_item(true)
427 |
428 | begin_item("FileDlg")
429 | gen_in("FILE_CB","FileDlgFile","ss","FileName","Status")
430 | gen_in("HELP_CB","CommonHelp")
431 | end_item()
432 |
433 | begin_item("MessageDlg")
434 | gen_in("HELP_CB","CommonHelp")
435 | end_item()
436 |
437 | begin_item("ColorDlg")
438 | gen_in("HELP_CB","CommonHelp")
439 | end_item()
440 |
441 | begin_item("FontDlg")
442 | gen_in("HELP_CB","CommonHelp")
443 | end_item()
444 |
445 | begin_item("Fill")
446 | end_item()
447 |
448 | begin_item("Hbox")
449 | end_item()
450 |
451 | begin_item("Vbox")
452 | end_item()
453 |
454 | begin_item("Zbox")
455 | end_item()
456 |
457 | begin_item("Radio")
458 | end_item()
459 |
460 | begin_item("Normalizer")
461 | end_item()
462 |
463 | begin_item("Cbox")
464 | end_item()
465 |
466 | begin_item("Sbox")
467 | end_item()
468 |
469 | begin_item("Split")
470 | end_item()
471 |
472 | begin_item("Item")
473 | gen_in("ACTION","ItemAction")
474 | gen_in("HIGHLIGHT_CB","ItemHighlight")
475 | gen_in("MAP_CB","CommonMap")
476 | gen_in("UNMAP_CB","CommonUnmap")
477 | gen_in("HELP_CB","CommonHelp")
478 | end_item()
479 |
480 | begin_item("Menu")
481 | gen_in("OPEN_CB","MenuOpen")
482 | gen_in("MENUCLOSE_CB","MenuClose")
483 | gen_in("MAP_CB","CommonMap")
484 | gen_in("UNMAP_CB","CommonUnmap")
485 | end_item()
486 |
487 | begin_item("Separator")
488 | end_item()
489 |
490 | begin_item("SubMenu")
491 | gen_in("HIGHLIGHT_CB","SubMenuHighlight")
492 | gen_in("MAP_CB","CommonMap")
493 | gen_in("UNMAP_CB","CommonUnmap")
494 | end_item()
495 |
496 | begin_item("Clipboard")
497 | end_item()
498 |
499 | begin_item("Timer")
500 | gen_in("ACTION","TimerAction")
501 | end_item()
502 |
503 | begin_item("User")
504 | end_item()
505 |
506 | begin_item("Button")
507 | gen_in("ACTION","ButtonAction")
508 | gen_in("BUTTON_CB","MouseButton","iiiis","Button","Pressed","X","Y","Status")
509 | end_item(true)
510 |
511 | begin_item("Canvas")
512 | gen_in("ACTION","CanvasAction")
513 | gen_in("BUTTON_CB","MouseButton","iiiis","Button","Pressed","X","Y","Status")
514 | gen_in("DROPFILES_CB","CanvasDropFiles","siii","FileName","Num","X","Y")
515 | gen_in("FOCUS_CB","CanvasFocus","i","Focus")
516 | gen_in("MOTION_CB","MouseMotion","iis","X","Y","Status")
517 | gen_in("KEYPRESS_CB","CanvasKeyPress","ii","C","Press")
518 | gen_in("RESIZE_CB","CanvasResize","ii","Width","Height")
519 | gen_in("SCROLL_CB","CanvasScroll","iff","Op","PosX","PosY")
520 | gen_in("TOUCH_CB","TouchEvent","iis","X","Y","State")
521 | gen_in("MULTITOUCH_CB","MultiTouchEvent","iIIII","Count","Pid","Px","Py","PState")
522 | gen_in("WHEEL_CB","CanvasWheel","fiis","Delta","X","Y","Status")
523 | gen_in("WOM_CB","CanvasWom","i","State")
524 | end_item(true)
525 |
526 | begin_item("Frame")
527 | gen_in("MAP_CB","CommonMap")
528 | gen_in("UNMAP_CB","CommonUnmap")
529 | end_item()
530 |
531 | begin_item("Label")
532 | gen_in("BUTTON_CB","MouseButton","iiiis","Button","Pressed","X","Y","Status")
533 | gen_in("DROPFILES_CB","LabelDropFiles","siii","FileName","Num","X","Y")
534 | gen_in("MAP_CB","CommonMap")
535 | gen_in("UNMAP_CB","CommonUnmap")
536 | gen_in("ENTERWINDOW_CB","CommonEnterWindow")
537 | gen_in("LEAVEWINDOW_CB","CommonLeaveWindow")
538 | end_item()
539 |
540 | begin_item("List")
541 | gen_in("ACTION","ListAction","sii","Text","Item","State")
542 | gen_in("BUTTON_CB","MouseButton","iiiis","Button","Pressed","X","Y","Status")
543 | gen_in("CARET_CB","ListCaret","iii","Lin","Col","Pos")
544 | gen_in("DBLCLICK_CB","ListDblclick","is","Item","Text")
545 | gen_in("DROPDOWN_CB","ListDropDown","i","State")
546 | gen_in("DROPFILES_CB","ListDropFiles","siii","FileName","Num","X","Y")
547 | gen_in("EDIT_CB","ListEdit","is","C","NewValue")
548 | gen_in("MOTION_CB","MouseMotion","iis","X","Y","Status")
549 | gen_in("MULTISELECT_CB","ListMultiSelect","s","Value")
550 | gen_in("VALUECHANGED_CB","ValueChanged")
551 | end_item(true)
552 |
553 | begin_item("ProgressBar")
554 | gen_in("MAP_CB","CommonMap")
555 | gen_in("UNMAP_CB","CommonUnmap")
556 | end_item()
557 |
558 | begin_item("Spin")
559 | gen_in("SPIN_CB","SpinInc","i","Inc")
560 | end_item()
561 |
562 | begin_item("SpinBox")
563 | gen_in("SPIN_CB","SpinBoxInc","i","Inc")
564 | end_item()
565 |
566 | begin_item("Tabs")
567 | gen_in("TABCHANGE_CB","TabsChange","nn","NewTab","OldTab")
568 | gen_in("TABCHANGEPOS_CB","TabsChangePos","ii","NewPos","OldPos")
569 | end_item(true)
570 |
571 | begin_item("Text")
572 | gen_in("ACTION","TextAction","is","C","NewValue")
573 | gen_in("BUTTON_CB","MouseButton","iiiis","Button","Pressed","X","Y","Status")
574 | gen_in("CARET_CB","TextCaret","iii","Lin","Col","Pos")
575 | gen_in("DROPFILES_CB","TextDropFiles","siii","FileName","Num","X","Y")
576 | gen_in("MOTION_CB","MouseMotion","iis","X","Y","Status")
577 | gen_in("SPIN_CB","TextSpin","i","Inc")
578 | gen_in("VALUECHANGED_CB","ValueChanged")
579 | end_item(true)
580 |
581 | begin_item("Toggle")
582 | gen_in("ACTION","ToggleAction","i","State")
583 | gen_in("VALUECHANGED_CB","ValueChanged")
584 | end_item(true)
585 |
586 | begin_item("Tree")
587 | gen_in("SELECTION_CB","TreeSelection","ii","Id","Status")
588 | gen_in("MULTISELECTION_CB","TreeMultiSelection","Ii","Ids","N")
589 | gen_in("BRANCHOPEN_CB","TreeBranchOpen","i","Id")
590 | gen_in("BRANCHCLOSE_CB","TreeBranchClose","i","Id")
591 | gen_in("EXECUTELEAF_CB","TreeExecuteLeaf","i","Id")
592 | gen_in("SHOWRENAME_CB","TreeShowRename","i","Id")
593 | gen_in("RENAME_CB","TreeRename","is","Id","Title")
594 | gen_in("DRAGDROP_CB","TreeDragDrop","iiii","DragId","DropId","IsShift","IsControl")
595 | gen_in("NODEREMOVED_CB","TreeNodeRemoved","C","UserData")
596 | gen_in("RIGHTCLICK_CB","TreeRightClick","i","Id")
597 | gen_in("BUTTON_CB","MouseButton","iiiis","Button","Pressed","X","Y","Status")
598 | gen_in("DROPFILES_CB","TreeDropFiles","siii","FileName","Num","X","Y")
599 | gen_in("MOTION_CB","MouseMotion","iis","X","Y","Status")
600 | end_item(true)
601 |
602 | begin_item("Val")
603 | gen_in("VALUECHANGED_CB","ValueChanged")
604 | end_item(true)
605 | end
606 |
607 | function gen_ctls()
608 |
609 | begin_item("Cells")
610 | gen_in("DRAW_CB","CellsDraw","iiiiiiC","Line","Column","Xmin","Xmax","Ymin","Ymax","Cnv")
611 | gen_in("HEIGHT_CB","CellsHeight","i","Line")
612 | gen_in("HSPAN_CB","CellsHspan","ii","Line","Column")
613 | gen_in("MOUSECLICK_CB","CellsMouseClick","iiiiiis","Button","Pressed","Line","Column","X","Y","Status")
614 | gen_in("MOUSEMOTION_CB","CellsMouseMotion","iiiis","Line","Column","X","Y","R")
615 | gen_in("NCOLS_CB","CellsNcols")
616 | gen_in("NLINES_CB","CellsNlines")
617 | gen_in("SCROLLING_CB","CellsScrolling","ii","Line","Column")
618 | gen_in("VSPAN_CB","CellsVspan","ii","Line","Column")
619 | gen_in("WIDTH_CB","CellsWidth","i","Column")
620 | end_item(true)
621 |
622 | begin_item("Colorbar")
623 | gen_sn("CELL_CB","ColorbarCell","i","Cell")
624 | gen_in("EXTENDED_CB","ColorbarExtended","i","Cell")
625 | gen_in("SELECT_CB","ColorbarSelect","ii","Cell","Type")
626 | gen_in("SWITCH_CB","ColorbarSwitch","ii","PrimCell","SecCell")
627 | end_item(true)
628 |
629 | begin_item("ColorBrowser")
630 | gen_in("CHANGE_CB","ColorBrowserChange","ccc","R","G","B")
631 | gen_in("DRAG_CB","ColorBrowserDrag","ccc","R","G","B")
632 | gen_in("VALUECHANGED_CB","ValueChanged")
633 | end_item(true)
634 |
635 | begin_item("Dial")
636 | gen_in("BUTTON_PRESS_CB","DialButtonPress","d","Angle")
637 | gen_in("BUTTON_RELEASE_CB","DialButtonRelease","d","Angle")
638 | gen_in("MOUSEMOVE_CB","DialMouseMove","d","Angle")
639 | gen_in("VALUECHANGED_CB","ValueChanged")
640 | end_item(true)
641 |
642 | begin_item("Matrix")
643 | gen_in("ACTION_CB","MatrixAction","iiiis","Key","Lin","Col","Edition","Value")
644 | gen_in("CLICK_CB","MatrixClick","iis","Lin","Col","Status")
645 | gen_in("RELEASE_CB","MatrixRelease","iis","Lin","Col","Status")
646 | gen_in("MOUSEMOVE_CB","MatrixMouseMove","ii","Lin","Col")
647 | gen_in("ENTERITEM_CB","MatrixEnterItem","ii","Lin","Col")
648 | gen_in("LEAVEITEM_CB","MatrixLeaveItem","ii","Lin","Col")
649 | gen_in("SCROLLTOP_CB","MatrixScrollTop","ii","Lin","Col")
650 | gen_in("BGCOLOR_CB","MatrixBgcolor","iiUUU","Lin","Col","Red","Green","Blue")
651 | gen_in("FGCOLOR_CB","MatrixFgcolor","iiUUU","Lin","Col","Red","Green","Blue")
652 | gen_in("FONT_CB","MatrixFont","ii","Lin","Col")
653 | gen_in("DRAW_CB","MatrixDraw","iiiiiiC","Lin","Col","X1","X2","Y1","Y2","Cnv")
654 | gen_in("DROPCHECK_CB","MatrixDropCheck","ii","Lin","Col")
655 | gen_in("DROP_CB","MatrixDrop","ii","Lin","Col")
656 | gen_in("DROPSELECT_CB","MatrixDropSelect","iinsii","Lin","Col","Drop","T","I","V")
657 | gen_in("EDITION_CB","MatrixEdition","iiii","Lin","Col","Mode","Update")
658 | gen_in("VALUE_CB","MatrixValue","ii","Lin","Col")
659 | gen_in("VALUE_EDIT_CB","MatrixValueEdit","iis","Lin","Col","NewValue")
660 | gen_in("MARK_CB","MatrixMark","ii","Lin","Col")
661 | gen_in("MARKEDIT_CB","MatrixMarkEdit","iii","Lin","Col","Marked")
662 |
663 | gen_in("ACTION","CanvasAction")
664 | gen_in("SCROLL_CB","CanvasScroll","iff","Op","PosX","PosY")
665 | gen_in("KEYPRESS_CB","CanvasKeyPress","ii","C","Press")
666 | gen_in("MOTION_CB","MouseMotion","iis","X","Y","Status")
667 | gen_in("RESIZE_CB","CanvasResize","ii","Width","Height")
668 | gen_in("BUTTON_CB","MouseButton","iiiis","Button","Pressed","X","Y","Status")
669 | gen_in("MAP_CB","CommonMap")
670 | end_item()
671 |
672 | begin_item("OleControl")
673 | gen_in("MAP_CB","CommonMap")
674 | gen_in("UNMAP_CB","CommonUnmap")
675 | gen_in("GETFOCUS_CB","CommonGetFocus")
676 | gen_in("KILLFOCUS_CB","CommonKillFocus")
677 | gen_in("ENTERWINDOW_CB","CommonEnterWindow")
678 | gen_in("LEAVEWINDOW_CB","CommonLeaveWindow")
679 | end_item()
680 |
681 | begin_item("PPlot")
682 | gen_in("DELETE_CB","PPlotDelete","iiff","Index","SampleIndex","X","Y")
683 | gen_in("DELETEBEGIN_CB","PPlotDeleteBegin")
684 | gen_in("DELETEEND_CB","PPlotDeleteEnd")
685 | gen_in("SELECT_CB","PPlotSelect","iiffi","Index","SampleIndex","X","Y","Select")
686 | gen_in("SELECTBEGIN_CB","PPlotSelectBegin")
687 | gen_in("SELECTEND_CB","PPlotSelectEnd")
688 | gen_in("EDIT_CB","PPlotEdit","iiffFF","Index","SampleIndex","X","Y","NewX","NewY")
689 | gen_in("EDITBEGIN_CB","PPlotEditBegin")
690 | gen_in("EDITEND_CB","PPlotEditEnd")
691 | gen_in("PREDRAW_CB","PPlotPreDraw","C","Canvas")
692 | gen_in("POSTDRAW_CB","PPlotPostDraw","C","Canvas")
693 | end_item(true)
694 |
695 | begin_item("WebBrowser")
696 | gen_in("COMPLETED_CB","WebBrowserCompleted","s","Url")
697 | gen_in("ERROR_CB","WebBrowserError","s","Url")
698 | gen_in("NAVIGATE_CB","WebBrowserNavigate","s","Url")
699 | gen_in("NEWWINDOW_CB","WebBrowserNewWindow","s","Url")
700 | end_item(true)
701 |
702 | begin_item("TuioClient")
703 | gen_in("TOUCH_CB","TouchEvent","iis","X","Y","State")
704 | gen_in("MULTITOUCH_CB","MultiTouchEvent","iIIII","Count","Pid","Px","Py","PState")
705 | end_item(true)
706 | end
707 |
708 | all = {}
709 | function make_iup()
710 | all[#all+1] = code_head
711 | all[#all+1] = code_head_d
712 | all[#all+1] = table.concat(t_c_tmpl,"\n")
713 | all[#all+1] = code_import
714 | all[#all+1] = code_id_head .. table.concat(t_id_tag) ..code_id_end
715 | all[#all+1] = code_reg_head .. table.concat(t_id_reg) ..code_reg_end
716 | all[#all+1] = table.concat(t_id_new,"\n")
717 | all[#all+1] = table.concat(t_go_type,"\n")
718 | all[#all+1] = table.concat(t_id_callback,"\n")
719 | all[#all+1] = table.concat(t_go_tmpl,"\n")
720 | end
721 |
722 | function make_file(filename)
723 | local f = io.open(filename,"w")
724 | f:write(table.concat(all,"\n"))
725 | f:close()
726 | end
727 |
728 | function show_all()
729 | print(table.concat(all,"\n"))
730 | end
731 |
732 | function main()
733 | -- clear
734 | clear()
735 | -- gen iup
736 | gen_iup()
737 | -- gen ctls
738 | gen_ctls()
739 | -- make all
740 | make_iup()
741 | -- print all
742 | show_all()
743 | -- make file
744 | make_file("iupobject.go")
745 | end
746 |
747 | main()
748 |
--------------------------------------------------------------------------------
/iup/handle.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011-2012 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | package iup
6 |
7 | /*
8 | #include
9 |
10 | #define LDESTROY_CB "LDESTROY_CB"
11 | extern void goLDestroyCb(void*);
12 | static void iupSetLDestroyCb(Ihandle* ih)
13 | {
14 | IupSetCallback(ih,LDESTROY_CB,(Icallback)&goLDestroyCb);
15 | }
16 | */
17 | import "C"
18 |
19 | import (
20 | "fmt"
21 | "unsafe"
22 | )
23 |
24 | type IAttribute interface {
25 | Name() string
26 | Value() string
27 | }
28 |
29 | type Attribute struct {
30 | name string
31 | value string
32 | }
33 |
34 | func (a *Attribute) Name() string {
35 | return a.name
36 | }
37 |
38 | func (a *Attribute) Value() string {
39 | return a.value
40 | }
41 |
42 | func Attr(name string, value string) IAttribute {
43 | return &Attribute{name, value}
44 | }
45 |
46 | func Attrs(a ...string) (attrs []IAttribute) {
47 | count := len(a)
48 | if count == 0 || count%2 != 0 {
49 | return nil
50 | }
51 | for i := 0; i < count; i += 2 {
52 | attrs = append(attrs, &Attribute{a[i], a[i+1]})
53 | }
54 | return
55 | }
56 |
57 | func parser(a []interface{}) (children []IHandle, attrs []IAttribute, sattrs []string, funcs []interface{}) {
58 | for i := 0; i < len(a); i++ {
59 | switch v := a[i].(type) {
60 | case IHandle:
61 | children = append(children, v)
62 | case IAttribute:
63 | attrs = append(attrs, v)
64 | case []IAttribute:
65 | attrs = append(attrs, v[:]...)
66 | case string:
67 | sattrs = append(sattrs, v)
68 | default:
69 | funcs = append(funcs, v)
70 | }
71 | }
72 | return
73 | }
74 |
75 | func _ParserAttrs(a string) (attrs []IAttribute) {
76 | var n1, n2 int
77 | var s1, s2 string
78 | b1, b2 := true, false
79 | for n, v := range a {
80 | if b1 && v == '=' {
81 | s1 = a[n1:n]
82 | b2 = true
83 | n2 = n + 1
84 | } else if b2 && v == ',' {
85 | s2 = a[n2:n]
86 | b1 = true
87 | n1 = n + 1
88 | attrs = append(attrs, &Attribute{s1, s2})
89 | }
90 | }
91 | if b1 && b2 {
92 | attrs = append(attrs, &Attribute{s1, s2})
93 | }
94 | return
95 | }
96 |
97 | func NewClassInfo(classname string, fn func(*Handle, interface{}) bool) *ClassInfo {
98 | return &ClassInfo{classname, fn}
99 | }
100 |
101 | func (i ClassInfo) ClassName() string {
102 | return i.className
103 | }
104 |
105 | func (i *ClassInfo) SetCallback(h *Handle, fn interface{}) bool {
106 | return i.setCallback(h, fn)
107 | }
108 |
109 | func (i *ClassInfo) GetClassAttributes() []string {
110 | return GetClassAttributes(i.className)
111 | }
112 |
113 | func (i *ClassInfo) GetClassCallbacks() []string {
114 | return GetClassCallbacks(i.className)
115 | }
116 |
117 | func (i *ClassInfo) SetClassDefaultAttribute(name, value string) {
118 | SetClassDefaultAttribute(i.className, name, value)
119 | }
120 |
121 | func GetClassAttributes(classname string) []string {
122 | c := NewCS(classname)
123 | defer FreeCS(c)
124 | total_count := C.IupGetClassAttributes(c, nil, 0)
125 | if total_count == 0 {
126 | return nil
127 | }
128 | parray := make([]*C.char, total_count)
129 | count := C.IupGetClassAttributes(c, &parray[0], total_count)
130 | return FromCSA(parray[0:count])
131 | }
132 |
133 | func GetClassCallbacks(classname string) []string {
134 | c := NewCS(classname)
135 | defer FreeCS(c)
136 | total_count := C.IupGetClassCallbacks(c, nil, 0)
137 | if total_count == 0 {
138 | return nil
139 | }
140 | parray := make([]*C.char, total_count)
141 | count := C.IupGetClassCallbacks(c, &parray[0], total_count)
142 | return FromCSA(parray[0:count])
143 | }
144 |
145 | func SetClassDefaultAttribute(classname, name, value string) {
146 | c := NewCS(classname)
147 | defer FreeCS(c)
148 | n := NewCS(name)
149 | defer FreeCS(n)
150 | v := NewCS(value)
151 | defer FreeCS(v)
152 | C.IupSetClassDefaultAttribute(c, n, v)
153 | }
154 |
155 | var classMap = make(map[string]*ClassInfo)
156 |
157 | func RegisterClass(name string, info *ClassInfo) {
158 | classMap[name] = info
159 | }
160 |
161 | type IHandle interface {
162 | Native() uintptr
163 | }
164 |
165 | var handleMap = make(map[uintptr]IHandle)
166 |
167 | func toHandle(native *C.Ihandle) IHandle {
168 | return handleMap[uintptr(unsafe.Pointer(native))]
169 | }
170 |
171 | func ptoHandle(native unsafe.Pointer) IHandle {
172 | return handleMap[uintptr(native)]
173 | }
174 |
175 | func toNative(h IHandle) *C.Ihandle {
176 | return (*C.Ihandle)(unsafe.Pointer(h.Native()))
177 | }
178 |
179 | //export goLDestroyCb
180 | func goLDestroyCb(p unsafe.Pointer) {
181 | delete(handleMap, uintptr(p))
182 | }
183 |
184 | // iup.Attr(key,value), iup.Attrs(k1,v1,v2,v2,...) ,
185 | // string , IHandle , func(arg *Action)
186 | func New(classname string, a ...interface{}) *Handle {
187 | cname := NewCS(classname)
188 | defer FreeCS(cname)
189 | ptr := C.IupCreate(cname)
190 | if ptr == nil {
191 | return nil
192 | }
193 | h := NewHandle(ptr)
194 | if len(a) == 0 {
195 | return h
196 | }
197 | children, attrs, sattrs, funcs := parser(a)
198 | for i := 0; i < len(children); i++ {
199 | h.Append(children[i])
200 | }
201 | for i := 0; i < len(attrs); i++ {
202 | h.SetAttribute(attrs[i].Name(), attrs[i].Value())
203 | }
204 | for i := 0; i < len(sattrs); i++ {
205 | h.SetAttributes(sattrs[i])
206 | }
207 | for i := 0; i < len(funcs); i++ {
208 | h.SetCallback(funcs[i])
209 | }
210 | return h
211 | }
212 |
213 | type ClassInfo struct {
214 | className string
215 | setCallback func(*Handle, interface{}) bool
216 | }
217 |
218 | func SetHandle(name string, h IHandle) {
219 | cname := NewCS(name)
220 | defer FreeCS(cname)
221 | C.IupSetHandle(cname, toNative(h))
222 | }
223 |
224 | func GetHandle(name string) IHandle {
225 | cname := NewCS(name)
226 | defer FreeCS(cname)
227 | return toHandle(C.IupGetHandle(cname))
228 | }
229 |
230 | func GetName(h IHandle) string {
231 | return FromCS(C.IupGetName(toNative(h)))
232 | }
233 |
234 | func GetAllNames() []string {
235 | total_count := C.IupGetAllNames(nil, 0)
236 | if total_count == 0 {
237 | return nil
238 | }
239 | parray := make([]*C.char, total_count)
240 | count := C.IupGetAllNames(&parray[0], total_count)
241 | return FromCSA(parray[0:count])
242 | }
243 |
244 | func GetAllDialogs() []string {
245 | total_count := C.IupGetAllDialogs(nil, 0)
246 | if total_count == 0 {
247 | return nil
248 | }
249 | parray := make([]*C.char, total_count)
250 | count := C.IupGetAllDialogs(&parray[0], total_count)
251 | return FromCSA(parray[0:count])
252 | }
253 |
254 | type Handle struct {
255 | p *C.Ihandle
256 | funcs map[string]interface{}
257 | }
258 |
259 | func NewHandle(p *C.Ihandle) *Handle {
260 | h := new(Handle)
261 | h.p = p
262 | h.funcs = make(map[string]interface{})
263 | handleMap[uintptr(unsafe.Pointer(p))] = h
264 | C.iupSetLDestroyCb(p)
265 | return h
266 | }
267 |
268 | func (h *Handle) Native() uintptr {
269 | return (uintptr)(unsafe.Pointer(h.p))
270 | }
271 |
272 | func (h *Handle) GetClassType() string {
273 | return FromCS(C.IupGetClassType(h.p))
274 | }
275 |
276 | func (h *Handle) GetClassName() string {
277 | return FromCS(C.IupGetClassName(h.p))
278 | }
279 |
280 | func (h *Handle) GetClassInfo() *ClassInfo {
281 | classname := h.GetClassName()
282 | if info, ok := classMap[classname]; ok {
283 | return info
284 | }
285 | return nil
286 | }
287 |
288 | func (h *Handle) SetName(name string) {
289 | SetHandle(name, h)
290 | }
291 |
292 | func (h *Handle) GetName() string {
293 | return FromCS(C.IupGetName(h.p))
294 | }
295 |
296 | func (h *Handle) SetCallback(fn interface{}) error {
297 | classname := h.GetClassName()
298 | if info, ok := classMap[classname]; ok {
299 | if info.SetCallback(h, fn) {
300 | return nil
301 | }
302 | }
303 | return &Error{fmt.Sprintf("ClassName %s Unsupport %v", classname, fn)}
304 | }
305 |
306 | func (h *Handle) Detach() {
307 | C.IupDetach(h.p)
308 | }
309 |
310 | func (h *Handle) Update() {
311 | C.IupUpdate(h.p)
312 | }
313 |
314 | func (h *Handle) UpdateChildren() {
315 | C.IupUpdateChildren(h.p)
316 | }
317 |
318 | func (h *Handle) Redraw(children int) {
319 | C.IupRedraw(h.p, C.int(children))
320 | }
321 |
322 | func (h *Handle) Refresh() {
323 | C.IupRefresh(h.p)
324 | }
325 |
326 | func (h *Handle) RefreshChildren() {
327 | C.IupRefreshChildren(h.p)
328 | }
329 |
330 | func (h *Handle) ConvertXYToPos(x, y int) int {
331 | return int(C.IupConvertXYToPos(h.p, C.int(x), C.int(y)))
332 | }
333 |
334 | func (h *Handle) Destroy() {
335 | C.IupDestroy(h.p)
336 | }
337 |
338 | func (h *Handle) Append(child IHandle) error {
339 | if C.IupAppend(h.p, toNative(child)) == nil {
340 | return &Error{"IupAppend"}
341 | }
342 | return nil
343 | }
344 |
345 | func (h *Handle) Insert(ref_child, child IHandle) error {
346 | if C.IupInsert(h.p, toNative(ref_child), toNative(child)) == nil {
347 | return &Error{"IupInsert"}
348 | }
349 | return nil
350 | }
351 |
352 | func (h *Handle) GetChild(pos int) IHandle {
353 | return toHandle(C.IupGetChild(h.p, C.int(pos)))
354 | }
355 |
356 | func (h *Handle) GetChildPos(child IHandle) int {
357 | return int(C.IupGetChildPos(h.p, toNative(child)))
358 | }
359 |
360 | func (h *Handle) GetChildCount() int {
361 | return int(C.IupGetChildCount(h.p))
362 | }
363 |
364 | func (h *Handle) GetNextChild(child IHandle) IHandle {
365 | return toHandle(C.IupGetNextChild(h.p, toNative(child)))
366 | }
367 |
368 | func (h *Handle) GetBrother() IHandle {
369 | return toHandle(C.IupGetBrother(h.p))
370 | }
371 |
372 | func (h *Handle) GetParent() IHandle {
373 | return toHandle(C.IupGetParent(h.p))
374 | }
375 |
376 | func (h *Handle) GetDialog() IHandle {
377 | return toHandle(C.IupGetDialog(h.p))
378 | }
379 |
380 | func (h *Handle) GetDialogChild(name string) IHandle {
381 | cname := NewCS(name)
382 | defer FreeCS(cname)
383 | return toHandle(C.IupGetDialogChild(h.p, cname))
384 | }
385 |
386 | func (h *Handle) Reparent(new_parent, ref_child IHandle) int {
387 | return int(C.IupReparent(h.p, toNative(new_parent), toNative(ref_child)))
388 | }
389 |
390 | func (h *Handle) Popup(x, y int) int {
391 | return int(C.IupPopup(h.p, C.int(x), C.int(y)))
392 | }
393 |
394 | func (h *Handle) PopupA() int {
395 | return int(C.IupPopup(h.p, C.IUP_CURRENT, C.IUP_CURRENT))
396 | }
397 |
398 | func (h *Handle) PopupC() int {
399 | return int(C.IupPopup(h.p, C.IUP_CENTER, C.IUP_CENTER))
400 | }
401 |
402 | func (h *Handle) Show() int {
403 | return int(C.IupShow(h.p))
404 | }
405 |
406 | func (h *Handle) ShowXY(x, y int) int {
407 | return int(C.IupShowXY(h.p, C.int(x), C.int(y)))
408 | }
409 |
410 | func (h *Handle) Hide() int {
411 | return int(C.IupHide(h.p))
412 | }
413 |
414 | func (h *Handle) Map() int {
415 | return int(C.IupMap(h.p))
416 | }
417 |
418 | func (h *Handle) Unmap() {
419 | C.IupUnmap(h.p)
420 | }
421 |
422 | func (h *Handle) SetAttrs(a ...string) error {
423 | count := len(a)
424 | if count%2 != 0 {
425 | return &Error{"key number != value number"}
426 | }
427 | for i := 0; i < count; i += 2 {
428 | h.SetAttribute(a[i], a[i+1])
429 | }
430 | return nil
431 | }
432 |
433 | func (h *Handle) SetAttribute(name string, value string) {
434 | cname := NewCS(name)
435 | defer FreeCS(cname)
436 | cvalue := NewCS(value)
437 | defer FreeCS(cvalue)
438 | C.IupStoreAttribute(h.p, cname, cvalue)
439 | }
440 |
441 | func (h *Handle) GetAttribute(name string) string {
442 | cname := NewCS(name)
443 | defer FreeCS(cname)
444 | return FromCS(C.IupGetAttribute(h.p, cname))
445 | }
446 |
447 | func (h *Handle) SetAttributeId(name string, id int, value string) {
448 | cname := NewCS(name)
449 | defer FreeCS(cname)
450 | cvalue := NewCS(value)
451 | defer FreeCS(cvalue)
452 | C.IupStoreAttributeId(h.p, cname, C.int(id), cvalue)
453 | }
454 |
455 | func (h *Handle) GetAttributeId(name string, id int) string {
456 | cname := NewCS(name)
457 | defer FreeCS(cname)
458 | return FromCS(C.IupGetAttributeId(h.p, cname, C.int(id)))
459 | }
460 |
461 | func (h *Handle) SetAttributes(values string) {
462 | cvalues := NewCS(values)
463 | defer FreeCS(cvalues)
464 | C.IupSetAttributes(h.p, cvalues)
465 | }
466 |
467 | func (h *Handle) GetAttributes() string {
468 | return FromCS(C.IupGetAttributes(h.p))
469 | }
470 |
471 | func (h *Handle) SetAttributeData(name string, value uintptr) {
472 | cname := NewCS(name)
473 | defer FreeCS(cname)
474 | C.IupSetAttribute(h.p, cname, (*C.char)(unsafe.Pointer(value)))
475 | }
476 |
477 | func (h *Handle) GetAttributeData(name string) uintptr {
478 | cname := NewCS(name)
479 | defer FreeCS(cname)
480 | return uintptr(unsafe.Pointer(C.IupGetAttribute(h.p, cname)))
481 | }
482 |
483 | func (h *Handle) SetAttributeDataId(name string, id int, value uintptr) {
484 | cname := NewCS(name)
485 | defer FreeCS(cname)
486 | C.IupSetAttributeId(h.p, cname, C.int(id), (*C.char)(unsafe.Pointer(value)))
487 | }
488 |
489 | func (h *Handle) GetAttributeDataId(name string, id int) uintptr {
490 | cname := NewCS(name)
491 | defer FreeCS(cname)
492 | return uintptr(unsafe.Pointer(C.IupGetAttributeId(h.p, cname, C.int(id))))
493 | }
494 |
495 | func (h *Handle) SetAttributeHandle(name string, h_named IHandle) {
496 | cname := NewCS(name)
497 | defer FreeCS(cname)
498 | C.IupSetAttributeHandle(h.p, cname, toNative(h_named))
499 | }
500 |
501 | func (h *Handle) GetAttributeHandle(name string) IHandle {
502 | cname := NewCS(name)
503 | defer FreeCS(cname)
504 | return toHandle(C.IupGetAttributeHandle(h.p, cname))
505 | }
506 |
507 | func (h *Handle) ResetAttribute(name string) {
508 | cname := NewCS(name)
509 | defer FreeCS(cname)
510 | C.IupResetAttribute(h.p, cname)
511 | }
512 |
513 | func (h *Handle) GetInt(name string) int {
514 | cname := NewCS(name)
515 | defer FreeCS(cname)
516 | return int(C.IupGetInt(h.p, cname))
517 | }
518 |
519 | func (h *Handle) GetIntId(name string, id int) int {
520 | cname := NewCS(name)
521 | defer FreeCS(cname)
522 | return int(C.IupGetIntId(h.p, cname, C.int(id)))
523 | }
524 |
525 | func (h *Handle) GetIntInt(name string) (count int, n1 int, n2 int) {
526 | cname := NewCS(name)
527 | defer FreeCS(cname)
528 | var v1, v2 C.int
529 | r := C.IupGetIntInt(h.p, cname, &v1, &v2)
530 | return int(r), int(v1), int(v2)
531 | }
532 |
533 | func (h *Handle) GetFloat(name string) float32 {
534 | cname := NewCS(name)
535 | defer FreeCS(cname)
536 | return float32(C.IupGetFloat(h.p, cname))
537 | }
538 |
539 | func (h *Handle) GetFloatId(name string, id int) float32 {
540 | cname := NewCS(name)
541 | defer FreeCS(cname)
542 | return float32(C.IupGetFloatId(h.p, cname, C.int(id)))
543 | }
544 |
545 | func (h *Handle) NextField() IHandle {
546 | return toHandle(C.IupNextField(h.p))
547 | }
548 |
549 | func (h *Handle) PreviousField() IHandle {
550 | return toHandle(C.IupPreviousField(h.p))
551 | }
552 |
553 | func GetFocus() IHandle {
554 | return toHandle(C.IupGetFocus())
555 | }
556 |
557 | func SetFocus(h IHandle) IHandle {
558 | return toHandle(C.IupSetFocus(toNative(h)))
559 | }
560 |
561 | func (h *Handle) SaveClassAttributes() {
562 | C.IupSaveClassAttributes(h.p)
563 | }
564 |
565 | func (h *Handle) CopyClassAttributes(src IHandle) {
566 | C.IupCopyClassAttributes(h.p, toNative(src))
567 | }
568 |
569 | func (h *Handle) SetCallbackProc(name string, proc uintptr) {
570 | cname := NewCS(name)
571 | defer FreeCS(cname)
572 | C.IupSetCallback(h.p, cname, (C.Icallback)(unsafe.Pointer(proc)))
573 | }
574 |
575 | //func GetAttribute(h IHandle, name string) string {
576 | // return h.GetHandle().GetAttribute(name)
577 | //}
578 |
579 | //func GetAttributeData(h IHandle, name string) uintptr {
580 | // return h.GetHandle().GetAttributeData(name)
581 | //}
582 |
583 | //func SetAttribute(h IHandle, name string, value string) {
584 | // h.GetHandle().SetAttribute(name, value)
585 | //}
586 |
587 | //func SetAttributeData(h IHandle, name string, value uintptr) {
588 | // h.GetHandle().SetAttributeData(name, value)
589 | //}
590 |
591 | func init() {
592 | RegisterAllClass()
593 | }
594 |
--------------------------------------------------------------------------------
/iup/system.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011-2012 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | package iup
6 |
7 | /*
8 | #cgo CFLAGS : -I../../libs/iup/include
9 | #cgo LDFLAGS: -L../../libs/iup -liup
10 | #include
11 | */
12 | import "C"
13 | import "unsafe"
14 |
15 | func Open() *Error {
16 | r := C.IupOpen(nil, nil)
17 | if r == C.IUP_ERROR {
18 | return &Error{"IupOpen false"}
19 | }
20 | return nil
21 | }
22 |
23 | func Close() {
24 | C.IupClose()
25 | }
26 |
27 | func MainLoop() int {
28 | return int(C.IupMainLoop())
29 | }
30 |
31 | func LoopStep() int {
32 | return int(C.IupLoopStep())
33 | }
34 |
35 | func LoopStepWait() int {
36 | return int(C.IupLoopStepWait())
37 | }
38 |
39 | func MainLoopLevel() int {
40 | return int(C.IupMainLoopLevel())
41 | }
42 |
43 | func Flush() {
44 | C.IupFlush()
45 | }
46 |
47 | func ExitLoop() {
48 | C.IupExitLoop()
49 | }
50 |
51 | func RecordInput(filename string, mode int) int {
52 | cname := NewCS(filename)
53 | defer FreeCS(cname)
54 | return int(C.IupRecordInput(cname, C.int(mode)))
55 | }
56 |
57 | func PlayInput(filename string) int {
58 | cname := NewCS(filename)
59 | defer FreeCS(cname)
60 | return int(C.IupPlayInput(cname))
61 | }
62 |
63 | func SetGlobal(name string, value string) {
64 | cname := NewCS(name)
65 | defer FreeCS(cname)
66 | cvalue := NewCS(value)
67 | defer FreeCS(cvalue)
68 | C.IupStoreGlobal(cname, cvalue)
69 | }
70 |
71 | func GetGlobal(name string) string {
72 | cname := NewCS(name)
73 | defer FreeCS(cname)
74 | return FromCS(C.IupGetGlobal(cname))
75 | }
76 |
77 | func SetGlobalPtr(name string, value uintptr) {
78 | cname := NewCS(name)
79 | defer FreeCS(cname)
80 | C.IupSetGlobal(cname, (*C.char)(unsafe.Pointer(value)))
81 | }
82 |
83 | func GetGlobalPtr(name string) uintptr {
84 | cname := NewCS(name)
85 | defer FreeCS(cname)
86 | return uintptr(unsafe.Pointer(C.IupGetGlobal(cname)))
87 | }
88 |
89 | func ResetGlobal(name string) {
90 | cname := NewCS(name)
91 | defer FreeCS(cname)
92 | C.IupResetAttribute(nil, cname)
93 | }
94 |
95 | func LoadLEDFile(file string) error {
96 | cfile := NewCS(file)
97 | defer FreeCS(cfile)
98 | err := C.IupLoad(cfile)
99 | if err != nil {
100 | return &Error{"IupLoad"}
101 | }
102 | return nil
103 | }
104 |
105 | func LoadLEDData(data string) error {
106 | cdata := NewCS(data)
107 | defer FreeCS(cdata)
108 | err := C.IupLoadBuffer(cdata)
109 | if err != nil {
110 | return &Error{"IupLoadBuffer"}
111 | }
112 | return nil
113 | }
114 |
--------------------------------------------------------------------------------
/iup/types.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011-2012 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | package iup
6 |
7 | /*
8 | #include
9 | */
10 | import "C"
11 |
12 | /************************************************************************/
13 | /* GO-IUP Version */
14 | /************************************************************************/
15 | const (
16 | Name = "GO-IUP - Iup Golang Binding"
17 | CopyRight = "Copyright (C) 2011-2012 visualfc"
18 | Version = "1.1"
19 | VersionDate = "2012.9.26"
20 | )
21 |
22 | /************************************************************************/
23 | /* IUP Version */
24 | /************************************************************************/
25 | const (
26 | IupName = C.IUP_NAME
27 | IupCopyRight = C.IUP_COPYRIGHT
28 | IupDescription = C.IUP_DESCRIPTION
29 | IupVersion = C.IUP_VERSION
30 | IupVersionNumber = C.IUP_VERSION_NUMBER
31 | IupVersionDate = C.IUP_VERSION_DATE
32 | )
33 |
34 | /************************************************************************/
35 | /* Common Return Values */
36 | /************************************************************************/
37 | const (
38 | ERROR int = C.IUP_ERROR
39 | NOERROR = C.IUP_NOERROR
40 | OPENDE = C.IUP_OPENED
41 | INVALID = C.IUP_INVALID
42 | )
43 |
44 | /************************************************************************/
45 | /* Callback Return Values */
46 | /************************************************************************/
47 | const (
48 | IGNORE int = C.IUP_IGNORE
49 | DEFAULT = C.IUP_DEFAULT
50 | CLOSE = C.IUP_CLOSE
51 | CONTINUE = C.IUP_CONTINUE
52 | )
53 |
54 | /************************************************************************/
55 | /* IupPopup and IupShowXY Parameter Values */
56 | /************************************************************************/
57 | const (
58 | CENTER int = C.IUP_CENTER //0xFFFF /* 65535 */
59 | LEFT = C.IUP_LEFT // 0xFFFE /* 65534 */
60 | RIGHT = C.IUP_RIGHT // 0xFFFD /* 65533 */
61 | MOUSEPOS = C.IUP_MOUSEPOS // 0xFFFC /* 65532 */
62 | CURIUP = C.IUP_CURRENT // 0xFFFB /* 65531 */
63 | CENTERPARENT = C.IUP_CENTERPARENT // 0xFFFA /* 65530 */
64 | )
65 |
66 | /************************************************************************/
67 | /* SHOW_CB Callback Values */
68 | /************************************************************************/
69 | const (
70 | SHOW = C.IUP_SHOW
71 | RESTORE = C.IUP_RESTORE
72 | MINIMIZE = C.IUP_MINIMIZE
73 | MAXIMIZE = C.IUP_MAXIMIZE
74 | HIDE = C.IUP_HIDE
75 | )
76 |
77 | /************************************************************************/
78 | /* SCROLL_CB Callback Values */
79 | /************************************************************************/
80 | const (
81 | SBUP = C.IUP_SBUP
82 | SBDN = C.IUP_SBUP
83 | SBPGUP = C.IUP_SBPGUP
84 | SBPGDN = C.IUP_SBPGDN
85 | SBPOSV = C.IUP_SBPOSV
86 | SBDRAGV = C.IUP_SBDRAGV
87 | SBLEFT = C.IUP_SBLEFT
88 | SBRIGHT = C.IUP_SBRIGHT
89 | SBPGLEFT = C.IUP_SBPGLEFT
90 | SBPGRIGHT = C.IUP_SBPGRIGHT
91 | SBPOSH = C.IUP_SBPOSH
92 | SBDRAGH = C.IUP_SBDRAGH
93 | )
94 |
95 | type KeyState int
96 |
97 | func (k KeyState) Key() int {
98 | return int(k % 256)
99 | }
100 |
101 | func (k KeyState) Xkey() int {
102 | return int(k % 128)
103 | }
104 |
105 | func (k KeyState) IsShift() bool {
106 | return k > 256 && k < 512
107 | }
108 |
109 | func (k KeyState) IsCtrl() bool {
110 | return k > 512 && k < 768
111 | }
112 |
113 | func (k KeyState) IsAlt() bool {
114 | return k > 768 && k < 1024
115 | }
116 |
117 | func (k KeyState) IsSys() bool {
118 | return k > 1024 && k < 1280
119 | }
120 |
121 | /************************************************************************/
122 | /* Mouse Button Values and State */
123 | /************************************************************************/
124 | const (
125 | BUTTON1 = '1'
126 | BUTTON2 = '2'
127 | BUTTON3 = '3'
128 | BUTTON4 = '4'
129 | BUTTON5 = '5'
130 | )
131 |
132 | type MouseState struct {
133 | S string
134 | }
135 |
136 | func (s *MouseState) IsShift() bool {
137 | return s.S[0] == 'S'
138 | }
139 |
140 | func (s *MouseState) IsControl() bool {
141 | return s.S[1] == 'C'
142 | }
143 |
144 | func (s *MouseState) IsButton1() bool {
145 | return s.S[2] == '1'
146 | }
147 |
148 | func (s *MouseState) IsButton2() bool {
149 | return s.S[3] == '2'
150 | }
151 |
152 | func (s *MouseState) IsButton3() bool {
153 | return s.S[4] == '3'
154 | }
155 |
156 | func (s *MouseState) IsDouble() bool {
157 | return s.S[5] == 'D'
158 | }
159 |
160 | func (s *MouseState) IsAlt() bool {
161 | return s.S[6] == 'A'
162 | }
163 |
164 | func (s *MouseState) IsSys() bool {
165 | return s.S[7] == 'Y'
166 | }
167 |
168 | func (s *MouseState) IsButton4() bool {
169 | return s.S[8] == '4'
170 | }
171 |
172 | func (s *MouseState) IsButton5() bool {
173 | return s.S[9] == '5'
174 | }
175 |
176 | /************************************************************************/
177 | /* Pre-Defined Masks */
178 | /************************************************************************/
179 | const (
180 | MASK_FLOAT = "[+/-]?(/d+/.?/d*|/./d+)"
181 | MASK_UFLOAT = "(/d+/.?/d*|/./d+)"
182 | MASK_EFLOAT = "[+/-]?(/d+/.?/d*|/./d+)([eE][+/-]?/d+)?"
183 | MASK_INT = "[+/-]?/d+"
184 | MASK_UINT = "/d+"
185 | )
186 |
187 | /************************************************************************/
188 | /* Record Input Modes */
189 | /************************************************************************/
190 | const (
191 | RECBINARY = C.IUP_RECBINARY
192 | IUP_RECTEXT = C.IUP_RECTEXT
193 | )
194 |
--------------------------------------------------------------------------------
/iupctls/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | package documentation
6 |
--------------------------------------------------------------------------------
/iupctls/iupctls.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011-2012 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | package iupctls
6 |
7 | /*
8 | #cgo CFLAGS : -I../../libs/iup/include
9 | #cgo LDFLAGS: -L../../libs/iup -liupcontrols
10 | #cgo linux CFLAGS : -I../../libs/cd/include
11 | #cgo linux LDFLAGS : -L../../libs/cd -liupcd -lcd
12 | #include
13 | #include
14 | #include
15 | */
16 | import "C"
17 | import "unsafe"
18 | import "github.com/visualfc/go-iup/iup"
19 |
20 | func Open() *iup.Error {
21 | r := C.IupControlsOpen()
22 | if r == C.IUP_ERROR {
23 | return &iup.Error{"IupControlsOpen"}
24 | }
25 | return nil
26 | }
27 |
28 | func NewCS(s string) *C.char {
29 | return C.CString(s)
30 | cs := make([]byte, len(s)+1)
31 | copy(cs, s)
32 | return (*C.char)(unsafe.Pointer(&cs[0]))
33 | }
34 |
35 | func FreeCS(cs *C.char) {
36 | C.free(unsafe.Pointer(cs))
37 | }
38 |
39 | type IupMatrix struct {
40 | *iup.Handle
41 | }
42 |
43 | func Matrix(a ...interface{}) *IupMatrix {
44 | return &IupMatrix{iup.Matrix(a...)}
45 | }
46 |
47 | func AttachMatrix(h *iup.Handle) *IupMatrix {
48 | return &IupMatrix{h}
49 | }
50 |
51 | func toNative(h iup.IHandle) *C.Ihandle {
52 | return (*C.Ihandle)(unsafe.Pointer(h.Native()))
53 | }
54 |
55 | func (m *IupMatrix) MatSetAttribute(name string, lin, col int, value string) {
56 | cname := NewCS(name)
57 | defer FreeCS(cname)
58 | cvalue := NewCS(value)
59 | defer FreeCS(cvalue)
60 | C.IupMatStoreAttribute(toNative(m), cname, C.int(lin), C.int(col), cvalue)
61 | }
62 |
63 | func (m *IupMatrix) MatGetAttribute(name string, lin, col int) string {
64 | cname := NewCS(name)
65 | defer FreeCS(cname)
66 | return C.GoString(C.IupMatGetAttribute(toNative(m), cname, C.int(lin), C.int(col)))
67 | }
68 |
69 | func (m *IupMatrix) MatSetAttributeData(name string, lin, col int, ptr uintptr) {
70 | cname := NewCS(name)
71 | defer FreeCS(cname)
72 | C.IupMatSetAttribute(toNative(m), cname, C.int(lin), C.int(col), (*C.char)(unsafe.Pointer(ptr)))
73 | }
74 |
75 | func (m *IupMatrix) MatGetAttributeData(name string, lin, col int) uintptr {
76 | cname := NewCS(name)
77 | defer FreeCS(cname)
78 | return (uintptr)(unsafe.Pointer(C.IupMatGetAttribute(toNative(m), cname, C.int(lin), C.int(col))))
79 | }
80 |
81 | func (m *IupMatrix) MatGetInt(name string, lin, col int) int {
82 | cname := NewCS(name)
83 | defer FreeCS(cname)
84 | return int(C.IupMatGetInt(toNative(m), cname, C.int(lin), C.int(col)))
85 | }
86 |
87 | func (m *IupMatrix) MatGetFloat(name string, lin, col int) float32 {
88 | cname := NewCS(name)
89 | defer FreeCS(cname)
90 | return float32(C.IupMatGetFloat(toNative(m), cname, C.int(lin), C.int(col)))
91 | }
92 |
--------------------------------------------------------------------------------
/iupim/doc.go:
--------------------------------------------------------------------------------
1 | // iupim project doc.go
2 |
3 | /*
4 | iupim document
5 | */
6 | package documentation
7 |
--------------------------------------------------------------------------------
/iupim/iupim.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011-2012 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | package iupim
6 |
7 | /*
8 | #cgo CFLAGS : -I../../libs/iup/include
9 | #cgo LDFLAGS : -L../../libs/iup -liup -liupim
10 | #cgo linux CFLAGS : -I../../libs/im/include
11 | #cgo linux LDFLAGS : -L../../libs/im -lim
12 | #include
13 | #include
14 | */
15 | import "C"
16 | import "github.com/visualfc/go-iup/iup"
17 |
18 | func LoadImage(filename string) *iup.Handle {
19 | cname := iup.NewCS(filename)
20 | defer iup.FreeCS(cname)
21 | return iup.NewHandle(C.IupLoadImage((*C.char)(cname)))
22 | }
23 |
--------------------------------------------------------------------------------
/iupimglib/doc.go:
--------------------------------------------------------------------------------
1 | // iupimglib project doc.go
2 |
3 | /*
4 | iupimglib document
5 | */
6 | package documentation
7 |
--------------------------------------------------------------------------------
/iupimglib/iupimglib.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011-2012 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | package iupimglib
6 |
7 | /*
8 | #cgo CFLAGS : -I../../libs/iup/include
9 | #cgo LDFLAGS: -L../../libs/iup -liup -liupimglib
10 |
11 | #include
12 | #include
13 | */
14 | import "C"
15 | import "github.com/visualfc/go-iup/iup"
16 |
17 | func Open() *iup.Error {
18 | C.IupImageLibOpen()
19 | return nil
20 | }
21 |
--------------------------------------------------------------------------------
/iupole/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | package documentation
6 |
--------------------------------------------------------------------------------
/iupole/iupole.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011-2012 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | package iupole
6 |
7 | /*
8 | #cgo CFLAGS : -I../../libs/iup/include
9 | #cgo LDFLAGS: -L../../libs/iup -liup -liupole
10 |
11 | #include
12 | #include
13 | #include
14 | */
15 | import "C"
16 | import "github.com/visualfc/go-iup/iup"
17 |
18 | func Open() *iup.Error {
19 | r := C.IupOleControlOpen()
20 | if r == C.IUP_ERROR {
21 | return &iup.Error{"IupOleControlOpen"}
22 | }
23 | return nil
24 | }
25 |
26 | func OleControl(progid string) *iup.Handle {
27 | id := iup.NewCS(progid)
28 | defer iup.FreeCS(id)
29 | return iup.NewHandle(C.IupOleControl((*C.char)(id)))
30 | }
31 |
--------------------------------------------------------------------------------
/iuppplot/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | package documentation
6 |
--------------------------------------------------------------------------------
/iuppplot/iuppplot.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011-2012 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | package iuppplot
6 |
7 | /*
8 | #cgo CFLAGS : -I../../libs/iup/include
9 | #cgo LDFLAGS: -L../../libs/iup -liup -liup_pplot
10 | #cgo linux CFLAGS : -I../../libs/cd/include
11 | #cgo linux LDFLAGS: -L../../libs/cd -liupcd -lcd
12 | #include
13 | #include
14 | #include
15 | */
16 | import "C"
17 | import "unsafe"
18 | import "github.com/visualfc/go-iup/iup"
19 |
20 | func toNative(h iup.IHandle) *C.Ihandle {
21 | return (*C.Ihandle)(unsafe.Pointer(h.Native()))
22 | }
23 |
24 | func Open() *iup.Error {
25 | C.IupPPlotOpen()
26 | return nil
27 | }
28 |
29 | type IupPPlot struct {
30 | *iup.Handle
31 | }
32 |
33 | func PPlot(a ...interface{}) *IupPPlot {
34 | return &IupPPlot{iup.PPlot(a...)}
35 | }
36 |
37 | func AttachPPloat(h *iup.Handle) *IupPPlot {
38 | return &IupPPlot{h}
39 | }
40 |
41 | func (h *IupPPlot) Begin(strXdata int) {
42 | C.IupPPlotBegin(toNative(h), C.int(strXdata))
43 | }
44 |
45 | func (h *IupPPlot) End() {
46 | C.IupPPlotEnd(toNative(h))
47 | }
48 |
49 | func (h *IupPPlot) Add(x, y float32) {
50 | C.IupPPlotAdd(toNative(h), C.float(x), C.float(y))
51 | }
52 |
53 | func (h *IupPPlot) AddStr(x string, y float32) {
54 | cx := iup.NewCS(x)
55 | iup.FreeCS(cx)
56 | C.IupPPlotAddStr(toNative(h), (*C.char)(cx), C.float(y))
57 | }
58 |
59 | func (h *IupPPlot) Insert(index, sample_index int, x, y float32) {
60 | C.IupPPlotInsert(toNative(h), C.int(index), C.int(sample_index), C.float(x), C.float(y))
61 | }
62 |
63 | func (h *IupPPlot) InsertStr(index, sample_index int, x string, y float32) {
64 | cx := iup.NewCS(x)
65 | iup.FreeCS(cx)
66 | C.IupPPlotInsertStr(toNative(h), C.int(index), C.int(sample_index), (*C.char)(cx), C.float(y))
67 | }
68 |
69 | func (h *IupPPlot) InsertPoints(index, sample_index int, x, y []float32) {
70 | count := len(x)
71 | if len(x) > len(y) {
72 | count = len(y)
73 | }
74 | C.IupPPlotInsertPoints(toNative(h), C.int(index), C.int(sample_index), (*C.float)(unsafe.Pointer(&x[0])), (*C.float)(unsafe.Pointer(&y[0])), C.int(count))
75 | }
76 |
77 | func (h *IupPPlot) InsertStrPoints(index, sample_index int, x []string, y []float32) {
78 | count := len(x)
79 | if len(x) > len(y) {
80 | count = len(y)
81 | }
82 | cx := iup.NewCSA(x)
83 | defer iup.FreeCSA(cx)
84 | C.IupPPlotInsertStrPoints(toNative(h), C.int(index), C.int(sample_index), (**C.char)(unsafe.Pointer(&cx[0])), (*C.float)(unsafe.Pointer(&y[0])), C.int(count))
85 | }
86 |
87 | func (h *IupPPlot) InsertAddPoints(index int, x, y []float32) {
88 | count := len(x)
89 | if len(x) > len(y) {
90 | count = len(y)
91 | }
92 | C.IupPPlotAddPoints(toNative(h), C.int(index), (*C.float)(unsafe.Pointer(&x[0])), (*C.float)(unsafe.Pointer(&y[0])), C.int(count))
93 | }
94 |
95 | func (h *IupPPlot) AddStrPoints(index int, x []string, y []float32) {
96 | count := len(x)
97 | if len(x) > len(y) {
98 | count = len(y)
99 | }
100 | cx := iup.NewCSA(x)
101 | defer iup.FreeCSA(cx)
102 | C.IupPPlotAddStrPoints(toNative(h), C.int(index), (**C.char)(unsafe.Pointer(&cx[0])), (*C.float)(unsafe.Pointer(&y[0])), C.int(count))
103 | }
104 |
105 | func (h *IupPPlot) Transform(x, y float32, ix, iy *int) {
106 | C.IupPPlotTransform(toNative(h), C.float(x), C.float(y), (*C.int)(unsafe.Pointer(ix)), (*C.int)(unsafe.Pointer(iy)))
107 | }
108 |
109 | func (h *IupPPlot) PaintTo(cnv uintptr) {
110 | C.IupPPlotPaintTo(toNative(h), unsafe.Pointer(cnv))
111 | }
112 |
--------------------------------------------------------------------------------
/iuptuio/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | package documentation
6 |
--------------------------------------------------------------------------------
/iuptuio/iuptuio.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | package iuptuio
6 |
7 | /*
8 | #cgo CFLAGS : -I../../libs/iup/include
9 | #cgo LDFLAGS: -L../../libs/iup -liup -liuptuio
10 | #include
11 | #include
12 | #include
13 | */
14 | import "C"
15 | import "github.com/visualfc/go-iup/iup"
16 |
17 | func Open() *iup.Error {
18 | r := C.IupTuioOpen()
19 | if r == C.IUP_ERROR {
20 | return &iup.Error{"IupTuiopen"}
21 | }
22 | return nil
23 | }
24 |
25 | func TuioClient(port int) *iup.Handle {
26 | return iup.NewHandle(C.IupTuioClient(C.int(port)))
27 | }
28 |
--------------------------------------------------------------------------------
/iupweb/Makefile:
--------------------------------------------------------------------------------
1 | include $(GOROOT)/src/Make.inc
2 |
3 | TARG=vfc/iupweb
4 |
5 | ifeq ($(GOOS),windows)
6 | GOFILES += iupweb_windows.go
7 | else
8 | CGOFILES += iupweb_linux.go
9 | CGO_CFLAGS = -I../../libs/iup/include
10 | CGO_LDFLAGS+= -L../../libs/iup -liup -liupweb
11 | endif
12 |
13 | #CLEANFILES+=
14 |
15 | include $(GOROOT)/src/Make.pkg
16 |
--------------------------------------------------------------------------------
/iupweb/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | package documentation
6 |
--------------------------------------------------------------------------------
/iupweb/iupweb_linux.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011-2012 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | package iupweb
6 |
7 | /*
8 | #cgo linux CFLAGS: -I../../libs/iup/include
9 | #cgo linux LDFLAGS: -L../../libs/iup -liup -liupweb
10 |
11 | #include
12 | #include
13 | #include
14 | */
15 | import "C"
16 | import "github.com/visualfc/go-iup/iup"
17 |
18 | func Open() *iup.Error {
19 | r := C.IupWebBrowserOpen()
20 | if r == C.IUP_ERROR {
21 | return &iup.Error{"IupWebBrowserOpen"}
22 | }
23 | return nil
24 | }
25 |
--------------------------------------------------------------------------------
/iupweb/iupweb_windows.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2011-2012 visualfc. All rights reserved.
2 | // Use of this source code is governed by a MIT license
3 | // that can be found in the COPYRIGHT file.
4 |
5 | package iupweb
6 |
7 | import (
8 | "github.com/visualfc/go-iup/iup"
9 | "syscall"
10 | )
11 |
12 | func Open() *iup.Error {
13 | h, err := syscall.LoadLibrary("iupweb.dll")
14 | if err != nil {
15 | return &iup.Error{"LoadLibrary iupweb.dll false"}
16 | }
17 | proc, err := syscall.GetProcAddress(h, "IupWebBrowserOpen")
18 | if err != nil {
19 | return &iup.Error{"GetProcAddress IupWebBrowserOpen false"}
20 | }
21 | syscall.Syscall(uintptr(proc), 0, 0, 0, 0)
22 | return nil
23 | }
24 |
--------------------------------------------------------------------------------