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  * Different label alignments
23  *
24  *  This file is part of xforms package
25  *  T.C. Zhao and M. Overmars
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 /**** Forms and Objects ****/
36 
37 #undef TEST_PIXMAP_ALIGN
38 
39 
40 typedef struct {
41     FL_FORM   * form0;
42     void      * vdata;
43     long        ldata;
44     FL_OBJECT * box;
45     FL_OBJECT * inside;
46     FL_OBJECT * center;
47 } FD_form0;
48 
49 static FD_form0 * create_form_form0( void );
50 
51 FD_form0 *fd_form0;
52 
53 
54 /***************************************
55  ***************************************/
56 
57 int
main(int argc,char * argv[])58 main( int    argc,
59       char * argv[ ] )
60 {
61     int align;
62 
63     fl_initialize( &argc, argv, "FormDemo", 0, 0 );
64     fd_form0 = create_form_form0( );
65 
66     /* Fill-in form initialization code */
67 
68     fl_set_form_dblbuffer( fd_form0->form0, 1 );
69     align = fd_form0->box->align | FL_ALIGN_INSIDE;
70     if ( align != fd_form0->box->align )
71         fl_set_button( fd_form0->inside, 1 );
72 
73     /* Show the first form */
74 
75     fl_show_form( fd_form0->form0, FL_PLACE_FREE, FL_FULLBORDER,"form0" );
76 
77     fl_do_forms( );
78     return 0;
79 }
80 
81 
82 /***************************************
83  ***************************************/
84 
85 static void
align_cb(FL_OBJECT * ob FL_UNUSED_ARG,long n)86 align_cb( FL_OBJECT * ob  FL_UNUSED_ARG,
87           long        n )
88 {
89     if ( fl_get_button( fd_form0->inside ) )
90         n = fl_to_inside_lalign( n );
91 
92     if ( n == FL_ALIGN_CENTER )
93         fl_set_button( fd_form0->inside, 1 );
94 
95 #ifndef TEST_PIXMAP_ALIGN
96     fl_set_object_lalign( fd_form0->box, n );
97 #else
98     fl_set_pixmap_align( fd_form0->box, n, 3, 3 );
99 #endif
100 }
101 
102 
103 /***************************************
104  ***************************************/
105 
106 static void
inside_cb(FL_OBJECT * ob,long data FL_UNUSED_ARG)107 inside_cb( FL_OBJECT * ob,
108            long        data  FL_UNUSED_ARG )
109 {
110     int align = fl_get_object_lalign( fd_form0->box );
111 
112     if ( fl_get_button( ob ) )
113         fl_set_object_lalign( fd_form0->box, fl_to_inside_lalign( align ) );
114     else
115         fl_set_object_lalign( fd_form0->box, fl_to_outside_lalign( align ) );
116 
117 #ifdef TEST_PIXMAP_ALIGN
118     fl_set_pixmap_align( fd_form0->box, fd_form0->box->align, 3, 3 );
119 #else
120     fl_redraw_form( fd_form0->form0 );
121 #endif
122 }
123 
124 
125 /***************************************
126  ***************************************/
127 
128 static FD_form0 *
create_form_form0(void)129 create_form_form0( void )
130 {
131     FL_OBJECT *obj;
132     FD_form0 *fdui = fl_calloc( 1, sizeof *fdui );
133 
134     fdui->form0 = fl_bgn_form( FL_NO_BOX, 351, 180 );
135 
136     fl_add_box( FL_UP_BOX, 0, 0, 351, 180, "" );
137 
138 #ifndef TEST_PIXMAP_ALIGN
139     fdui->box = obj = fl_add_box( FL_UP_BOX, 190, 40, 90, 55,
140                                   "This is\na label" );
141 #else
142     fdui->box = obj = fl_add_pixmap( FL_NORMAL_PIXMAP, 190, 35, 90, 60, "" );
143     fl_set_pixmap_file( obj, "crab.xpm" );
144     fl_set_object_boxtype( obj,FL_UP_BOX );
145 #endif
146 
147     fdui->inside = obj = fl_add_lightbutton( FL_PUSH_BUTTON, 20, 125, 90, 30,
148                                              "Inside" );
149     fl_set_button( obj, 1 );
150     fl_set_object_callback( obj, inside_cb, 0 );
151 
152     fl_bgn_group();
153 
154     obj = fl_add_button( FL_RADIO_BUTTON, 20, 20, 30, 30, "@#7->" );
155     fl_set_object_lcolor( obj, FL_BLUE );
156     fl_set_object_callback( obj, align_cb, FL_ALIGN_LEFT_TOP );
157 
158     obj = fl_add_button( FL_RADIO_BUTTON, 50, 20, 30, 30, "@#8->" );
159     fl_set_object_lcolor( obj, FL_BLUE );
160     fl_set_object_callback( obj, align_cb, FL_ALIGN_TOP );
161 
162     obj = fl_add_button( FL_RADIO_BUTTON, 80, 20, 30, 30, "@#9->" );
163     fl_set_object_lcolor( obj, FL_BLUE );
164     fl_set_object_callback( obj, align_cb, FL_ALIGN_RIGHT_TOP );
165 
166     obj = fl_add_button( FL_RADIO_BUTTON, 80, 50, 30, 30, "@#->" );
167     fl_set_object_lcolor( obj, FL_BLUE );
168     fl_set_object_callback( obj, align_cb, FL_ALIGN_RIGHT );
169 
170     fdui->center = obj = fl_add_button( FL_RADIO_BUTTON, 50, 50, 30, 30,
171                                         "@circle" );
172     fl_set_object_lcolor( obj, FL_RED );
173     fl_set_object_callback( obj, align_cb, FL_ALIGN_CENTER );
174 
175     obj = fl_add_button( FL_RADIO_BUTTON, 20, 50, 30, 30, "@#<-" );
176     fl_set_object_lcolor( obj, FL_BLUE );
177     fl_set_object_callback( obj, align_cb, FL_ALIGN_LEFT );
178 
179     obj = fl_add_button( FL_RADIO_BUTTON, 20, 80, 30, 30, "@#1->" );
180     fl_set_object_lcolor( obj, FL_BLUE );
181     fl_set_object_callback( obj, align_cb, FL_ALIGN_LEFT_BOTTOM );
182 
183     obj = fl_add_button( FL_RADIO_BUTTON, 50, 80, 30, 30, "@#2->" );
184     fl_set_object_lcolor( obj, FL_BLUE );
185     fl_set_object_callback( obj, align_cb, FL_ALIGN_BOTTOM );
186 
187     obj = fl_add_button( FL_RADIO_BUTTON, 80, 80, 30, 30, "@#3->" );
188     fl_set_object_lcolor( obj, FL_BLUE );
189     fl_set_object_callback( obj, align_cb, FL_ALIGN_RIGHT_BOTTOM );
190 
191     fl_end_group( );
192 
193     fl_add_button( FL_NORMAL_BUTTON, 200, 135, 70, 30, "Done" );
194 
195     fl_end_form( );
196 
197     return fdui;
198 }
199 
200 
201 /*
202  * Local variables:
203  * tab-width: 4
204  * indent-tabs-mode: nil
205  * End:
206  */
207