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 the effect of different border widths
23  *
24  * This file is part of xforms packge
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 
36 /**** Forms and Objects ****/
37 
38 typedef struct {
39     FL_FORM   * bwform;
40     void      * vdata;
41     char      * cdata;
42     long        ldata;
43     FL_OBJECT * done;
44     FL_OBJECT * bw_select;
45     FL_OBJECT * bwgroup;
46     FL_OBJECT * pmobj;
47 } FD_bwform;
48 
49 static FD_bwform * fd_bwform;
50 
51 static FD_bwform * create_form_bwform( void );
52 static void done_callback( FL_OBJECT *, long );
53 static void bw_callback( FL_OBJECT *, long );
54 
55 
56 /* Callbacks for form bwform */
57 
58 /***************************************
59  ***************************************/
60 
61 static void
done_callback(FL_OBJECT * ob FL_UNUSED_ARG,long data FL_UNUSED_ARG)62 done_callback( FL_OBJECT * ob    FL_UNUSED_ARG,
63                long        data  FL_UNUSED_ARG )
64 {
65     fl_finish( );
66     fl_free( fd_bwform );
67     exit( 0 );
68 }
69 
70 
71 /***************************************
72  ***************************************/
73 
74 static void
bw_callback(FL_OBJECT * ob,long data FL_UNUSED_ARG)75 bw_callback( FL_OBJECT * ob,
76              long        data  FL_UNUSED_ARG )
77 {
78     static int bws[ ] = { -5, -4, -3, -2, -1, 1, 2, 3, 4, 5 };
79     FL_POPUP_RETURN *r =  fl_get_select_item( ob );
80     int bw = bws[ r->val ];
81 
82     fl_set_object_bw( fd_bwform->bwgroup, bw );
83     fl_set_object_bw( fd_bwform->done, bw );
84     fl_popup_set_bw( ( FL_POPUP * ) r->popup, bw );
85 }
86 
87 
88 /***************************************
89  ***************************************/
90 
91 int
main(int argc,char * argv[])92 main( int    argc,
93       char * argv[ ] )
94 {
95     int bw;
96     char txt[ 9 ];
97 
98     /* Application default. Can be overriden by the command line options */
99 
100     fl_set_border_width( 1 );
101 
102     fl_initialize( &argc, argv, "FormDemo", 0, 0 );
103     fd_bwform = create_form_bwform( );
104 
105     /* Form initialization code */
106 
107     fl_set_pixmapbutton_file( fd_bwform->pmobj, "crab.xpm" );
108 
109     fl_add_select_items( fd_bwform->bw_select,
110                          "-5 Pixel|-4 Pixel|-3 Pixel|-2 Pixel|-1 Pixel|"
111                          " 1 Pixel| 2 Pixel| 3 Pixel| 4 Pixel| 5 Pixel" );
112 
113     bw = fl_get_border_width( );
114     if ( bw < -5 || bw == 0 || bw > 5 )
115         fl_set_border_width( bw = -2 );
116 
117     sprintf( txt, "%2d Pixel", bw );
118     fl_set_select_item( fd_bwform->bw_select,
119                         fl_get_select_item_by_label( fd_bwform->bw_select,
120                                                      txt ) );
121 
122     /* show the form */
123 
124     fl_show_form( fd_bwform->bwform, FL_PLACE_CENTER, FL_TRANSIENT, "bwform" );
125 
126     while ( fl_do_forms( ) )
127         /* empty */ ;
128 
129     return 0;
130 }
131 
132 
133 /***************************************
134  * Form definition file generated with fdesign.
135  ***************************************/
136 
137 static FD_bwform *
create_form_bwform(void)138 create_form_bwform( void )
139 {
140     FL_OBJECT *obj;
141     FD_bwform *fdui = fl_calloc( 1, sizeof *fdui );
142 
143     fdui->bwform = fl_bgn_form( FL_NO_BOX, 380, 340 );
144 
145     fdui->bwgroup = fl_bgn_group();
146 
147     fl_add_box( FL_UP_BOX, 0, 0, 380, 340, "" );
148 
149     fl_add_frame( FL_EMBOSSED_FRAME, 220, 60, 135, 145, "" );
150 
151     fl_add_frame( FL_ENGRAVED_FRAME, 15, 60, 185, 145, "" );
152 
153     fl_add_slider( FL_HOR_SLIDER, 25, 70, 160, 20, "" );
154 
155     fl_add_valslider( FL_HOR_BROWSER_SLIDER, 25, 105, 160, 20, "" );
156 
157     obj = fl_add_scrollbar( FL_HOR_THIN_SCROLLBAR, 25, 140, 160, 20, "" );
158     fl_set_scrollbar_size( obj, 0.2 );
159 
160     fl_add_counter( FL_NORMAL_COUNTER, 25, 175, 160, 20, "" );
161 
162     fdui->pmobj = fl_add_pixmapbutton( FL_NORMAL_BUTTON, 305, 145, 40, 35, "" );
163 
164     fl_add_positioner( FL_NORMAL_POSITIONER, 30, 225, 100, 80, "" );
165 
166     fl_add_button( FL_NORMAL_BUTTON, 230, 65, 100, 28, "Button" );
167 
168     fl_add_lightbutton( FL_PUSH_BUTTON, 230, 98, 100, 28, "LightButton" );
169 
170     fl_add_roundbutton( FL_PUSH_BUTTON, 230, 128, 80, 32, "Button" );
171 
172     obj = fl_add_round3dbutton( FL_PUSH_BUTTON, 230, 152, 80, 32, "Button" );
173     fl_set_object_color( obj, FL_COL1, FL_BLUE );
174 
175     fl_add_checkbutton( FL_PUSH_BUTTON, 230, 175, 80, 32, "Button" );
176 
177     fl_add_input( FL_NORMAL_INPUT, 195, 240, 160, 28, "Input" );
178 
179     fdui->bw_select = obj = fl_add_select( FL_MENU_SELECT, 105, 20, 100, 28,
180                                            "Border Width" );
181     fl_set_object_callback( obj, bw_callback, 0 );
182 
183     fl_end_group( );
184 
185     fdui->done = obj = fl_add_button( FL_NORMAL_BUTTON, 270, 290, 75, 30,
186                                       "Done" );
187     fl_set_object_callback( obj, done_callback, 0 );
188 
189     fl_end_form( );
190 
191     fdui->bwform->fdui  = fdui;
192 
193     return fdui;
194 }
195 
196 
197 /*
198  * Local variables:
199  * tab-width: 4
200  * indent-tabs-mode: nil
201  * End:
202  */
203