Project

General

Profile

Buttons explanations » History » Version 5

iri, 02/22/2011 04:36 PM

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 5 iri
	- the flag. For a mnemonic button, use SCOL_GTK_BUTTON_MNEMONIC
59 3 iri
	- no supplemental parameter needed, so, nil it's ok */
60
	set button = _gtkButtonNew _channel win "My button" SCOL_GTK_BUTTON_MNEMONIC nil;
61
	/* Define the callback 
62
	- the flag. To get the "clicked" signal, use SCOL_GTK_BUTTON_CB_CLICKED */
63
	_gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_CLICKED;
64
	...
65
	;;
66
</code></pre>
67 4 iri
68
* A button with a stock item :
69
It is a same code than alabel. The name is the item. That's all.
70
To create the button, use the flag SCOL_GTK_BUTTON_STOCKITEM.
71
72
* A button with a link (uri)
73
74
<pre><code class="php">
75
typeof win = ObjGtkWidget;;
76
typeof button = ObjGtkWidget;;
77
78
fun CBbutton (obj, uparam, url)=
79
	_fooS url;
80
	_fooS strcat "user param is : " uparam;
81
	0;;
82
	
83
fun main ()=
84
	_showconsole;
85
	
86
	/* Create a window ...*/
87
	set win = ...
88
	/* Create the button : 
89 5 iri
	- the flag. For a link button, use SCOL_GTK_BUTTON_LINK
90
	- set the url to the 4e argument : type S */
91
	set button = _gtkButtonNew _channel win "Scolring" SCOL_GTK_BUTTON_LINK "http://www.scolring.org/";
92 4 iri
	/* Define the callback 
93
	- the flag. To get the activate signal, use SCOL_GTK_BUTTON_CB_LINKED 
94 5 iri
	- the callback take one supplemental parameter : the url (type S) 
95
        Note : this callback works only with GTK+ 3.x. With GTK+ 2.x, you should use SCOL_GTK_BUTTON_CB_CLICKED */
96 1 iri
	_gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_LINKED;
97
	...
98
	;;
99
</code></pre>
100 5 iri
101
* A button with a check box
102
103
<pre><code class="php">
104
typeof win = ObjGtkWidget;;
105
typeof button = ObjGtkWidget;;
106
107
fun CBbutton (obj, uparam, state)=
108
	_fooS strcat "The state of the check box is " itoa state;
109
	_fooS strcat "user param is : " uparam;
110
	0;;
111
	
112
fun main ()=
113
	_showconsole;
114
	
115
	/* Create a window ...*/
116
	set win = ...
117
	/* Create the button : 
118
	- the flag. For a check box button, use SCOL_GTK_BUTTON_CHECK
119
	- the 4e arg is the initial state of the check box : 1 (checked) or 0 (unchecked) type I */
120
	set button = _gtkButtonNew _channel win "Check it !" SCOL_GTK_BUTTON_CHECK 0;
121
	/* Define the callback 
122
	- the flag. To get the toggled signal, use SCOL_GTK_BUTTON_CB_TOGGLED 
123
	- the callback take one supplemental parameter : the new state (type I) */
124
	_gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_TOGGLED;
125
	...
126
	;;
127
</code></pre>
128
129
* A switch button
130
131
<pre><code class="php">
132
typeof win = ObjGtkWidget;;
133
typeof button = ObjGtkWidget;;
134
135
fun CBbutton (obj, uparam, state)=
136
	_fooS strcat "The state of the switch is " itoa state;
137
	_fooS strcat "user param is : " uparam;
138
	0;;
139
	
140
fun main ()=
141
	_showconsole;
142
	
143
	/* Create a window ...*/
144
	set win = ...
145
	/* Create the button : 
146
	- the flag. For a switch button, use SCOL_GTK_BUTTON_SWITCH
147
	- the 4e arg is the initial state of the switch : 1 (activate) or 0 (deactivate) (type I) */
148
	set button = _gtkButtonNew _channel win "Check it !" SCOL_GTK_BUTTON_SWITCH 0;
149
	/* Define the callback 
150
	- the flag. To get the toggled signal, use SCOL_GTK_BUTTON_CB_TOGGLED 
151
	- the callback take one supplemental parameter : the new state (type I) */
152
	_gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_TOGGLED;
153
	...
154
	;;
155
</code></pre>
156
157
* Three radios buttons
158
159
<pre><code class="php">