Project

General

Profile

Buttons explanations » History » Version 10

iri, 02/23/2011 11:26 AM

1 1 iri
h1. Buttons explanations
2
3
To create any button, you should use [[Create|_gtkButtonNew]]
4
5
How to create them ?
6
7
* A simple button with a label :
8
9 2 iri
<pre><code class="php">
10 1 iri
typeof win = ObjGtkWidget;;
11
typeof button = ObjGtkWidget;;
12
13
fun CBbutton (obj, uparam)=
14
	_fooS "The button has been clicked";
15
	_fooS strcat "user param is : " uparam;
16
	0;;
17
	
18
fun main ()=
19
	_showconsole;
20
	
21
	/* Create a window ...*/
22
	set win = ...
23
	/* Create the button : 
24
	use _gtkButtonNew function with :
25
	- the channel
26
	- the parent (here a window)
27
	- the label
28
	- the flag. For a simple button, use SCOL_GTK_BUTTON_LABEL
29
	- no supplemental parameter needed, so, nil it's ok */
30
	set button = _gtkButtonNew _channel win "My button" SCOL_GTK_BUTTON_LABEL nil;
31
	/* Define the callback 
32
	use _gtkButtonCB with :
33
	- the Scol object
34
	- the reflex
35
	- any parameter at your convenience
36
	- the flag. To get the "clicked" signal, use SCOL_GTK_BUTTON_CB_CLICKED
37
	It's all*/
38
	_gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_CLICKED;
39
	...
40
	;;
41
</code></pre>
42 3 iri
43
* A button with a mnemonic :
44
A mnemonic is, by example, a keyboard shortcut
45
46
<pre><code class="php">
47
fun CBbutton (obj, uparam)=
48
	_fooS "The button has been clicked";
49
	_fooS strcat "user param is : " uparam;
50
	0;;
51
	
52
fun main ()=
53
	_showconsole;
54
	
55
	/* Create a window ...*/
56
	set win = ...
57
	/* Create the button : 
58 10 iri
	- the flag. For a mnemonic button, use SCOL_GTK_BUTTON_MNEMONIC.
59
          Here, with "My _button" the button will be accessible with ALT + b.
60 3 iri
	- no supplemental parameter needed, so, nil it's ok */
61 9 iri
	set button = _gtkButtonNew _channel win "My _button" SCOL_GTK_BUTTON_MNEMONIC nil;
62 3 iri
	/* Define the callback 
63
	- the flag. To get the "clicked" signal, use SCOL_GTK_BUTTON_CB_CLICKED */
64
	_gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_CLICKED;
65
	...
66
	;;
67
</code></pre>
68 4 iri
69
* A button with a stock item :
70
It is a same code than alabel. The name is the item. That's all.
71
To create the button, use the flag SCOL_GTK_BUTTON_STOCKITEM.
72
73
* A button with a link (uri)
74
75
<pre><code class="php">
76
typeof win = ObjGtkWidget;;
77
typeof button = ObjGtkWidget;;
78
79
fun CBbutton (obj, uparam, url)=
80
	_fooS url;
81
	_fooS strcat "user param is : " uparam;
82
	0;;
83
	
84
fun main ()=
85
	_showconsole;
86
	
87
	/* Create a window ...*/
88
	set win = ...
89
	/* Create the button : 
90 5 iri
	- the flag. For a link button, use SCOL_GTK_BUTTON_LINK
91
	- set the url to the 4e argument : type S */
92
	set button = _gtkButtonNew _channel win "Scolring" SCOL_GTK_BUTTON_LINK "http://www.scolring.org/";
93 4 iri
	/* Define the callback 
94
	- the flag. To get the activate signal, use SCOL_GTK_BUTTON_CB_LINKED 
95 5 iri
	- the callback take one supplemental parameter : the url (type S) 
96
        Note : this callback works only with GTK+ 3.x. With GTK+ 2.x, you should use SCOL_GTK_BUTTON_CB_CLICKED */
97 1 iri
	_gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_LINKED;
98
	...
99
	;;
100
</code></pre>
101 5 iri
102
* A button with a check box
103
104
<pre><code class="php">
105
typeof win = ObjGtkWidget;;
106
typeof button = ObjGtkWidget;;
107
108
fun CBbutton (obj, uparam, state)=
109
	_fooS strcat "The state of the check box is " itoa state;
110
	_fooS strcat "user param is : " uparam;
111
	0;;
112
	
113
fun main ()=
114
	_showconsole;
115
	
116
	/* Create a window ...*/
117
	set win = ...
118
	/* Create the button : 
119
	- the flag. For a check box button, use SCOL_GTK_BUTTON_CHECK
120
	- the 4e arg is the initial state of the check box : 1 (checked) or 0 (unchecked) type I */
121
	set button = _gtkButtonNew _channel win "Check it !" SCOL_GTK_BUTTON_CHECK 0;
122
	/* Define the callback 
123
	- the flag. To get the toggled signal, use SCOL_GTK_BUTTON_CB_TOGGLED 
124
	- the callback take one supplemental parameter : the new state (type I) */
125
	_gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_TOGGLED;
126
	...
127
	;;
128
</code></pre>
129
130
* A switch button
131
132
<pre><code class="php">
133
typeof win = ObjGtkWidget;;
134
typeof button = ObjGtkWidget;;
135
136
fun CBbutton (obj, uparam, state)=
137
	_fooS strcat "The state of the switch is " itoa state;
138
	_fooS strcat "user param is : " uparam;
139
	0;;
140
	
141
fun main ()=
142
	_showconsole;
143
	
144
	/* Create a window ...*/
145
	set win = ...
146
	/* Create the button : 
147
	- the flag. For a switch button, use SCOL_GTK_BUTTON_SWITCH
148
	- the 4e arg is the initial state of the switch : 1 (activate) or 0 (deactivate) (type I) */
149
	set button = _gtkButtonNew _channel win "Check it !" SCOL_GTK_BUTTON_SWITCH 0;
150
	/* Define the callback 
151
	- the flag. To get the toggled signal, use SCOL_GTK_BUTTON_CB_TOGGLED 
152
	- the callback take one supplemental parameter : the new state (type I) */
153
	_gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_TOGGLED;
154
	...
155
	;;
156
</code></pre>
157
158
* Three radios buttons
159
160
<pre><code class="php">
161 6 iri
typeof win = ObjGtkWidget;;
162
typeof button = ObjGtkWidget;;
163
typeof button2 = ObjGtkWidget;;
164
typeof button3 = ObjGtkWidget;;
165
166
fun CBbutton (obj, uparam, state)=
167
	_fooS strcat "The state of the switch is " itoa state;
168
	_fooS strcat "user param is : " uparam;
169
	0;;
170
	
171
fun main ()=
172
	_showconsole;
173
	
174
	/* Create a window ...*/
175
	set win = ...
176
	/* Create the button : 
177 7 iri
	- the flag. For a radio button, use SCOL_GTK_BUTTON_RADIO
178 6 iri
	- the 4e arg is a tuple (type [ObjGtkWidget I]) :
179
		- this Scol object is the group object. At first radio button, it's nil. Next,
180
		others radio buttons belong to the same group have this first object.
181
		- the initial state (1 : checked, 0, unchecked)*/
182
	set button1 = _gtkButtonNew _channel "One" SCOL_GTK_BUTTON_RADIO [nil 1];
183
	set button2 = _gtkButtonNew _channel "Two" SCOL_GTK_BUTTON_RADIO [button1 0];
184
	set button3 = _gtkButtonNew _channel "Three" SCOL_GTK_BUTTON_RADIO [button1 0];
185
	/* Define the callback 
186
	- the flag. To get the toggled signal, use SCOL_GTK_BUTTON_CB_TOGGLED 
187
	- the callback take one supplemental parameter : the new state (type I) 
188
	Note : you can set the flag to SCOL_GTK_BUTTON_CB_RADIO_CHANGED : in this case,
189
	the callback will be called when the radio button will change group */
190 1 iri
	_gtkButtonCB button1 @CBbutton "yes !" SCOL_GTK_BUTTON_CB_TOGGLED;
191 7 iri
	...
192
	;;
193
</code></pre>
194
195
* A toggled button : two states : normal, pressed.
196
197
<pre><code class="php">
198
typeof win = ObjGtkWidget;;
199
typeof button = ObjGtkWidget;;
200
201
fun CBbutton (obj, uparam, state)=
202
	_fooS strcat "The state of the state is " itoa state;
203
	_fooS strcat "user param is : " uparam;
204
	0;;
205
	
206
fun main ()=
207
	_showconsole;
208
	
209
	/* Create a window ...*/
210
	set win = ...
211
	/* Create the button : 
212
	- the flag. For a toggled button, use SCOL_GTK_BUTTON_TOGGLE
213
	- the 4e arg is the initial state of the button : 1 (activate) or 0 (deactivate) (type I) */
214
	set button = _gtkButtonNew _channel win "Click !" SCOL_GTK_BUTTON_TOGGLE 0;
215
	/* Define the callback 
216
	- the flag. To get the toggled signal, use SCOL_GTK_BUTTON_CB_TOGGLED 
217
	- the callback take one supplemental parameter : the new state (type I) */
218
	_gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_TOGGLED;
219 6 iri
	...
220
	;;
221
</code></pre>
222 8 iri
223
Return [[Examples]]