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 * timer routine tester
23 *
24 * This file is part of xforms package
25 * T.C. Zhao and M. Overmars (1997)
26 */
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include "include/forms.h"
33 #include <stdlib.h>
34
35 /**** Callback routines ****/
36
37 extern void expired( FL_OBJECT *,
38 long );
39 extern void suspend_resume( FL_OBJECT *,
40 long );
41 extern void reset( FL_OBJECT *,
42 long );
43 extern void timer_direction( FL_OBJECT *,
44 long );
45
46
47 /**** Forms and Objects ****/
48
49 typedef struct {
50 FL_FORM * timerform;
51 void * vdata;
52 long ldata;
53 FL_OBJECT * timer;
54 FL_OBJECT * down;
55 } FD_timerform;
56
57 extern FD_timerform * create_form_timerform( void );
58
59
60 #define T 20
61
62 FD_timerform *fd_timerform;
63
64
65 /***************************************
66 * callbacks for form timer form
67 ***************************************/
68
69 void
suspend_resume(FL_OBJECT * ob FL_UNUSED_ARG,long data)70 suspend_resume( FL_OBJECT * ob FL_UNUSED_ARG,
71 long data )
72 {
73 if ( data )
74 fl_resume_timer( fd_timerform->timer );
75 else
76 fl_suspend_timer( fd_timerform->timer );
77 }
78
79
80 /***************************************
81 ***************************************/
82
83 void
reset(FL_OBJECT * ob FL_UNUSED_ARG,long data FL_UNUSED_ARG)84 reset( FL_OBJECT * ob FL_UNUSED_ARG,
85 long data FL_UNUSED_ARG )
86 {
87 fl_set_timer( fd_timerform->timer, T );
88 }
89
90
91 /***************************************
92 ***************************************/
93
94 void
timer_direction(FL_OBJECT * ob FL_UNUSED_ARG,long data)95 timer_direction( FL_OBJECT * ob FL_UNUSED_ARG,
96 long data )
97 {
98 fl_set_timer_countup( fd_timerform->timer, data );
99 }
100
101
102 /***************************************
103 ***************************************/
104
105 void
expired(FL_OBJECT * ob FL_UNUSED_ARG,long data FL_UNUSED_ARG)106 expired( FL_OBJECT * ob FL_UNUSED_ARG,
107 long data FL_UNUSED_ARG )
108 {
109 if ( fl_show_question( "Expired!\n\nQuit?", 0 ) == 1 )
110 {
111 fl_finish( );
112 exit( 0 );
113 }
114 else
115 fl_set_timer( fd_timerform->timer, T );
116 }
117
118
119 /***************************************
120 ***************************************/
121
122 int
main(int argc,char * argv[])123 main( int argc,
124 char * argv[ ] )
125 {
126
127 fl_set_border_width( -2 );
128
129 fl_initialize( &argc, argv, 0, 0, 0 );
130 fd_timerform = create_form_timerform( );
131
132 /* fill-in form initialization code */
133
134 fl_set_timer( fd_timerform->timer, T );
135 fl_set_button( fd_timerform->down, 1 );
136
137 /* show the first form */
138
139 fl_show_form( fd_timerform->timerform, FL_PLACE_CENTER,
140 FL_FULLBORDER, "timerform" );
141
142 fl_do_forms( );
143
144 return 0;
145 }
146
147
148 /***************************************
149 * Form definition file generated with fdesign
150 ***************************************/
151
152 FD_timerform *
create_form_timerform(void)153 create_form_timerform( void )
154 {
155 FL_OBJECT *obj;
156 FD_timerform *fdui = fl_calloc(1, sizeof *fdui );
157
158 fdui->timerform = fl_bgn_form( FL_NO_BOX, 290, 210 );
159 fl_add_box( FL_UP_BOX, 0, 0, 290, 210, "" );
160 fl_add_frame( FL_UP_FRAME, 0, 0, 290, 94, "" );
161 fl_add_frame( FL_UP_FRAME, 0, 100, 330, 190, "" );
162 fl_add_button( FL_NORMAL_BUTTON, 100, 170, 80, 30, "Done" );
163
164 fdui->timer = obj = fl_add_timer( FL_VALUE_TIMER, 20, 30, 180, 40,
165 "Timer" );
166 fl_set_object_boxtype( obj, FL_UP_BOX );
167 fl_set_object_lsize( obj, FL_MEDIUM_SIZE );
168 fl_set_object_lalign( obj, FL_ALIGN_TOP );
169 fl_set_object_lstyle( obj, FL_TIMES_STYLE );
170 fl_set_object_callback( obj, expired, 0 );
171
172 obj = fl_add_button( FL_NORMAL_BUTTON, 20, 120, 80, 30, "Suspend" );
173 fl_set_object_callback( obj, suspend_resume, 0);
174
175 obj = fl_add_button( FL_NORMAL_BUTTON, 100, 120, 80, 30, "Resume" );
176 fl_set_object_callback( obj, suspend_resume, 1 );
177
178 obj = fl_add_button( FL_NORMAL_BUTTON, 180, 120, 80, 30, "Reset" );
179 fl_set_object_callback( obj, reset, 0 );
180
181 obj = fdui->down = fl_add_checkbutton( FL_RADIO_BUTTON, 210, 20, 70, 30,
182 "Down" );
183 fl_set_object_shortcut( obj, "D#D", 1 );
184 fl_set_object_callback( obj, timer_direction, 0 );
185
186 obj = fl_add_checkbutton( FL_RADIO_BUTTON, 210, 50, 70, 30, "Up" );
187 fl_set_object_shortcut( obj, "U#U", 1 );
188 fl_set_object_callback( obj, timer_direction, 1 );
189
190 fl_end_form( );
191
192 return fdui;
193 }
194
195
196 /*
197 * Local variables:
198 * tab-width: 4
199 * indent-tabs-mode: nil
200 * End:
201 */
202