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 * This demo shows the use of a browser and a file selector.
23 * Good browser/scrollbar test
24 *
25 * This file is part of xforms package
26 * T.C. Zhao and M. Overmars
27 *
28 */
29
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include "include/forms.h"
37
38 typedef struct {
39 FL_FORM * form;
40 void * vdata;
41 char * cdata;
42 long ldata;
43 FL_OBJECT * br;
44 } FD_form;
45
46
47 /***************************************
48 ***************************************/
49
50 void
load_file(FL_OBJECT * ob,long arg FL_UNUSED_ARG)51 load_file( FL_OBJECT * ob,
52 long arg FL_UNUSED_ARG )
53 {
54 const char *fname;
55 FD_form *fdui = ob->form->fdui;
56
57 if ( ( fname = fl_show_file_selector( "File To Load", "", "*", "" ) ) )
58 {
59 if ( ! fl_load_browser( fdui->br, fname ) )
60 fl_add_browser_line( fdui->br,"NO SUCH FILE!" );
61 }
62 }
63
64
65 /***************************************
66 ***************************************/
67
68 void
set_size(FL_OBJECT * ob,long arg)69 set_size( FL_OBJECT * ob,
70 long arg)
71 {
72 FD_form *fdui = ob->form->fdui;
73
74 fl_set_browser_fontsize( fdui->br, arg );
75 }
76
77
78 /***************************************
79 ***************************************/
80
81 void
exit_program(FL_OBJECT * ob FL_UNUSED_ARG,long data FL_UNUSED_ARG)82 exit_program( FL_OBJECT * ob FL_UNUSED_ARG,
83 long data FL_UNUSED_ARG )
84 {
85 fl_finish( );
86 exit( 0 );
87 }
88
89
90 /***************************************
91 ***************************************/
92
93 void
hide_show(FL_OBJECT * ob,long data FL_UNUSED_ARG)94 hide_show( FL_OBJECT * ob,
95 long data FL_UNUSED_ARG )
96 {
97 FD_form *fdui = ob->form->fdui;
98
99 if ( fl_object_is_visible( fdui->br ) )
100 fl_hide_object( fdui->br );
101 else
102 fl_show_object( fdui->br );
103 }
104
105
106 /***************************************
107 ***************************************/
108
109 FD_form *
create_form(void)110 create_form( void )
111 {
112 FL_OBJECT *obj;
113 FL_Coord x = 20,
114 dx = 80,
115 dy = 28;
116 FD_form *fdui = fl_calloc( 1, sizeof *fdui );
117
118 fdui->form = fl_bgn_form( FL_NO_BOX, 590, 610 );
119
120 fl_add_box( FL_UP_BOX, 0, 0, 590, 610, "" );
121
122 fdui->br = obj = fl_add_browser( FL_NORMAL_BROWSER, 20, 20, 550, 530, "" );
123
124 obj = fl_add_button( FL_NORMAL_BUTTON, x, 565, dx-5, dy, "Load" );
125 fl_set_object_callback( obj, load_file, 0 );
126 x += dx ;
127
128 obj = fl_add_lightbutton( FL_RADIO_BUTTON, x, 565, dx, dy, "Tiny" );
129 fl_set_object_callback( obj, set_size, FL_TINY_SIZE );
130 x += dx;
131
132 obj = fl_add_lightbutton( FL_RADIO_BUTTON, x , 565, dx, dy, "Small" );
133 fl_set_object_callback( obj, set_size, FL_SMALL_SIZE );
134 fl_set_button( obj, FL_SMALL_SIZE == FL_BROWSER_FONTSIZE );
135 x += dx;
136
137 obj = fl_add_lightbutton( FL_RADIO_BUTTON, x , 565, dx, dy, "Normal" );
138 fl_set_object_callback( obj, set_size, FL_NORMAL_SIZE );
139 fl_set_button( obj, FL_NORMAL_SIZE == FL_BROWSER_FONTSIZE );
140 x += dx;
141
142 obj = fl_add_lightbutton( FL_RADIO_BUTTON, x , 565, dx, dy, "Large" );
143 fl_set_object_callback( obj, set_size, FL_LARGE_SIZE );
144 x += dx + 4;
145
146 obj = fl_add_button( FL_NORMAL_BUTTON, x, 565, dx, dy, "Hide/Show" );
147 fl_set_object_callback( obj, hide_show, 0 );
148 x += dx + 5;
149
150 obj = fl_add_button( FL_NORMAL_BUTTON, x, 565, 60, dy, "Exit" );
151 fl_set_object_callback( obj, exit_program, 0 );
152
153 fl_end_form();
154
155 fl_adjust_form_size( fdui->form );
156 fdui->form->fdui = fdui;
157
158 return fdui;
159 }
160
161
162 /***************************************
163 ***************************************/
164
165 int
main(int argc,char * argv[])166 main( int argc,
167 char * argv[ ] )
168 {
169 FD_form *fdui;
170 FL_OBJECT *o;
171
172 fl_initialize( &argc, argv, "FormDemo", 0, 0 );
173
174 fdui = create_form( );
175
176 fl_clear_browser( fdui->br );
177 fl_add_browser_line( fdui->br, "LOAD A FILE." );
178 fl_set_browser_fontstyle( fdui->br,FL_FIXED_STYLE );
179
180 fl_show_form( fdui->form, FL_PLACE_FREE, FL_FULLBORDER, "Browser" );
181
182 o = fl_do_forms( );
183 fprintf( stderr, "%p %d %s\n", o, o->objclass, o->label ? o->label: "" );
184
185 fl_hide_form( fdui->form );
186
187 fl_finish( );
188 return 0;
189 }
190
191
192 /*
193 * Local variables:
194 * tab-width: 4
195 * indent-tabs-mode: nil
196 * End:
197 */
198