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 /* demo showing the choices when to return object. Note this program,
22 * strictly speaking, is illegal in the usage of user data parameter
23 * in the callback function.
24 *
25 * T.C. Zhao and M. Overmars
26 */
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31 #include "include/forms.h"
32 #include <stdlib.h>
33
34
35 /**** Forms and Objects ****/
36
37 typedef struct
38 {
39 FL_FORM * form0;
40 void * vdata;
41 long ldata;
42 FL_OBJECT * obj[ 4 ];
43 FL_OBJECT * br;
44 FL_OBJECT * when;
45 } FD_form0;
46
47
48 extern FD_form0 *create_form_form0( void );
49 static FD_form0 *fd_form0;
50
51
52 /* callbacks for form form0 */
53
54 /***************************************
55 ***************************************/
56
57 const char *mess[ ] = { "slider returned",
58 "counter returned",
59 "input 1 returned",
60 "input 2 returned" };
61
62
63 void
return_cb(FL_OBJECT * ob FL_UNUSED_ARG,long data)64 return_cb( FL_OBJECT * ob FL_UNUSED_ARG,
65 long data )
66 {
67 fl_addto_browser( fd_form0->br, mess[ data ] );
68 }
69
70
71 /***************************************
72 ***************************************/
73
74 void
set_when(int n)75 set_when( int n )
76 {
77 fl_set_object_return( fd_form0->obj[ 0 ], n );
78 fl_set_object_return( fd_form0->obj[ 1 ], n );
79 fl_set_object_return( fd_form0->obj[ 2 ], n );
80 fl_set_object_return( fd_form0->obj[ 3 ], n );
81 }
82
83
84 /***************************************
85 ***************************************/
86
87 void
when_cb(FL_OBJECT * ob,long data FL_UNUSED_ARG)88 when_cb( FL_OBJECT * ob,
89 long data FL_UNUSED_ARG )
90 {
91 set_when( fl_get_select_item( ob )->val );
92 }
93
94
95 /***************************************
96 ***************************************/
97
98 void
resetlog_cb(FL_OBJECT * ob FL_UNUSED_ARG,long data FL_UNUSED_ARG)99 resetlog_cb( FL_OBJECT * ob FL_UNUSED_ARG,
100 long data FL_UNUSED_ARG )
101 {
102 fl_clear_browser( fd_form0->br );
103 }
104
105
106 /***************************************
107 ***************************************/
108
109 int
main(int argc,char * argv[])110 main( int argc,
111 char * argv[ ] )
112 {
113 fl_set_border_width( -2 );
114
115 fl_initialize( &argc, argv, "FormDemo", 0, 0 );
116 fd_form0 = create_form_form0( );
117
118 /* fill-in form initialization code */
119
120 set_when( 0 );
121 fl_set_object_dblbuffer( fd_form0->br, 1);
122 fl_add_select_items( fd_form0->when,
123 "RETURN_NONE%x|RETURN_CHANGED%x|"
124 "RETURN_END%x|RETURN_END_CHANGED%x|RETURN_ALWAYS%x",
125 FL_RETURN_NONE, FL_RETURN_CHANGED, FL_RETURN_END,
126 FL_RETURN_END_CHANGED, FL_RETURN_ALWAYS );
127
128 /* show the first form */
129
130 fl_show_form( fd_form0->form0, FL_PLACE_CENTER, FL_FULLBORDER, "form0" );
131
132 fl_do_forms( );
133
134 return 0;
135 }
136
137
138 /***************************************
139 ***************************************/
140
141 FD_form0 *
create_form_form0(void)142 create_form_form0( void )
143 {
144 FL_OBJECT *obj;
145 FD_form0 *fdui = fl_calloc( 1, sizeof *fdui );
146
147 fdui->form0 = fl_bgn_form( FL_NO_BOX, 321, 276 );
148
149 fl_add_box( FL_UP_BOX, 0, 0, 321, 276, "" );
150
151 fdui->obj[ 0 ] = obj = fl_add_valslider( FL_HOR_SLIDER, 12, 55, 138, 22,
152 "" );
153 fl_set_object_lalign( obj, fl_to_inside_lalign( FL_ALIGN_BOTTOM ) );
154 fl_set_object_callback( obj, return_cb, 0 );
155 fl_set_slider_return( obj, FL_RETURN_CHANGED );
156
157 fdui->obj[ 1 ] = obj = fl_add_counter( FL_NORMAL_COUNTER, 12, 85, 138, 22,
158 "" );
159 fl_set_object_lalign( obj, fl_to_inside_lalign( FL_ALIGN_BOTTOM ) );
160 fl_set_object_callback( obj, return_cb, 1 );
161
162 fdui->obj[ 2 ] = obj = fl_add_input( FL_NORMAL_INPUT, 12, 150, 138, 25,
163 "" );
164 fl_set_object_callback( obj, return_cb, 2 );
165
166 fdui->br = obj = fl_add_browser( FL_NORMAL_BROWSER, 170, 55, 140, 160, "" );
167
168 fdui->obj[ 3 ] = obj = fl_add_input( FL_INT_INPUT, 12, 187, 138, 25,
169 "" );
170 fl_set_object_lalign( obj, fl_to_inside_lalign( FL_ALIGN_LEFT ) );
171 fl_set_object_callback( obj, return_cb, 3 );
172
173 fdui->when = obj = fl_add_select( FL_NORMAL_SELECT, 40, 12, 240, 27, "" );
174 fl_set_object_callback( obj, when_cb, 0 );
175
176 fl_add_button( FL_NORMAL_BUTTON, 170, 239, 80, 25, "Done" );
177
178 obj = fl_add_button( FL_NORMAL_BUTTON, 70, 239, 80, 25, "ResetLog" );
179 fl_set_object_callback( obj, resetlog_cb, 0 );
180
181 fl_end_form( );
182
183 return fdui;
184 }
185 /*---------------------------------------*/
186
187
188 /*
189 * Local variables:
190 * tab-width: 4
191 * indent-tabs-mode: nil
192 * End:
193 */
194