1 /*
2 * This file is part of XForms.
3 *
4 * XForms is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation; either version 2.1, or
7 * (at your option) any later version.
8 *
9 * XForms is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with XForms; see the file COPYING. If not, write to
16 * the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
17 * MA 02111-1307, USA.
18 */
19
20
21
22 /* Demo showing activating and deactivating objects
23 */
24
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include "include/forms.h"
32
33
34 FL_FORM *form;
35
36 FL_OBJECT *button1,
37 *button2,
38 *button3,
39 *button4,
40 *group,
41 *firstbut;
42
43
44 /***************************************
45 ***************************************/
46
47 void
exit_cb(FL_OBJECT * obj FL_UNUSED_ARG,long arg FL_UNUSED_ARG)48 exit_cb( FL_OBJECT * obj FL_UNUSED_ARG,
49 long arg FL_UNUSED_ARG )
50 {
51 fl_finish( );
52 exit( 0 );
53 }
54
55
56 /***************************************
57 ***************************************/
58
59 void
setit(FL_OBJECT * obj,int val)60 setit( FL_OBJECT * obj,
61 int val )
62 {
63 if ( val )
64 {
65 fl_set_object_lcolor( obj, FL_BLACK );
66 fl_activate_object( obj );
67 }
68 else
69 {
70 fl_set_object_lcolor( obj, FL_INACTIVE );
71 fl_deactivate_object( obj );
72 }
73 }
74
75
76 /***************************************
77 ***************************************/
78
79 void
doit(int b1,int b2,int b3,int b4)80 doit( int b1,
81 int b2,
82 int b3,
83 int b4 )
84 {
85 setit( button1, b1 );
86 setit( button2, b2 );
87 setit( button3, b3 );
88 setit( button4, b4 );
89 }
90
91
92 /***************************************
93 ***************************************/
94
95 void
set_active(FL_OBJECT * obj FL_UNUSED_ARG,long arg)96 set_active( FL_OBJECT * obj FL_UNUSED_ARG,
97 long arg)
98 {
99 switch ( arg )
100 {
101 case 0 :
102 doit( 1, 1, 1, 1 );
103 break;
104
105 case 1 :
106 doit( 0, 0, 0, 0 );
107 break;
108
109 case 2 :
110 doit( 0, 1, 0, 1 );
111 break;
112
113 case 3 :
114 doit( 1, 0, 1, 0 );
115 break;
116 }
117 }
118
119
120 /***************************************
121 ***************************************/
122
123 void
create_form(void)124 create_form( void )
125 {
126 FL_OBJECT *obj;
127
128 form = fl_bgn_form( FL_NO_BOX, 420, 230 );
129
130 obj = fl_add_box( FL_UP_BOX, 0, 0, 420, 230, "" );
131 fl_set_object_color( obj, FL_SLATEBLUE, FL_COL1 );
132
133 button1 = obj = fl_add_button( FL_NORMAL_BUTTON, 20, 170, 150, 40,
134 "Button 1" );
135 fl_set_object_lsize( obj ,FL_LARGE_SIZE );
136 fl_set_button_shortcut( obj, "1", 1 );
137
138 button2 = obj = fl_add_button( FL_NORMAL_BUTTON, 20, 120, 150, 40,
139 "Button 2" );
140 fl_set_object_lsize( obj, FL_LARGE_SIZE );
141 fl_set_button_shortcut( obj, "2", 1 );
142
143 button3 = obj = fl_add_button( FL_NORMAL_BUTTON, 20, 70, 150, 40,
144 "Button 3" );
145 fl_set_object_lsize( obj, FL_LARGE_SIZE );
146 fl_set_button_shortcut( obj, "3", 1 );
147
148 button4 = obj = fl_add_button( FL_NORMAL_BUTTON, 20, 20, 150, 40,
149 "Button 4" );
150 fl_set_button_shortcut( obj, "4", 1 );
151 fl_set_object_lsize( obj,FL_LARGE_SIZE );
152
153 group = fl_bgn_group( );
154
155 firstbut = obj = fl_add_lightbutton( FL_RADIO_BUTTON, 260, 180, 140, 30,
156 "All active" );
157 fl_set_object_callback( obj, set_active, 0 );
158
159 obj = fl_add_lightbutton( FL_RADIO_BUTTON, 260, 150, 140, 30,
160 "Non active" );
161 fl_set_object_callback( obj, set_active, 1 );
162
163 obj = fl_add_lightbutton( FL_RADIO_BUTTON, 260, 120, 140 ,30,
164 "Even active" );
165 fl_set_object_callback(obj, set_active, 2 );
166
167 obj = fl_add_lightbutton( FL_RADIO_BUTTON, 260, 90, 140, 30, "Odd active" );
168 fl_set_object_callback( obj, set_active, 3 );
169
170 fl_end_group( );
171
172 obj = fl_add_button( FL_NORMAL_BUTTON, 270, 20, 130, 30, "Quit" );
173 fl_set_object_callback( obj, exit_cb, 0 );
174
175 fl_end_form( );
176 }
177
178
179 /***************************************
180 ***************************************/
181
182 int
main(int argc,char * argv[])183 main( int argc,
184 char * argv[ ] )
185 {
186 fl_initialize( &argc, argv, "FormDemo", 0, 0 );
187 create_form( );
188
189 fl_set_button( firstbut, 1 );
190
191 fl_show_form( form, FL_PLACE_CENTER, FL_NOBORDER, NULL );
192
193 while ( fl_do_forms( ) )
194 /* empty */ ;
195
196 return 0;
197 }
198
199
200 /*
201 * Local variables:
202 * tab-width: 4
203 * indent-tabs-mode: nil
204 * End:
205 */
206