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 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include "include/forms.h"
26 #include <stdlib.h>
27 
28 
29 typedef struct {
30     FL_FORM   * form0;
31     void      * vdata;
32     long        ldata;
33     FL_OBJECT * text;
34 } FD_form0;
35 
36 
37 static FD_form0 * fd_form0;
38 
39 
40 /***************************************
41  ***************************************/
42 
43 static void
exit_cb(FL_OBJECT * ob FL_UNUSED_ARG,long data FL_UNUSED_ARG)44 exit_cb( FL_OBJECT * ob    FL_UNUSED_ARG,
45          long        data  FL_UNUSED_ARG )
46 {
47     fl_finish( );
48     exit( 0 );
49 }
50 
51 
52 /***************************************
53  ***************************************/
54 
55 static void
input_cb(FL_OBJECT * ob,long data FL_UNUSED_ARG)56 input_cb( FL_OBJECT * ob,
57           long        data  FL_UNUSED_ARG )
58 {
59     const char * s = fl_get_input( ob );
60     int w = fl_get_string_width( ob->lstyle, ob->lsize, s, strlen( s ) );
61     int h = fl_get_string_height( ob->lstyle, ob->lsize, s, strlen( s ), 0, 0 );
62     char buf[ 50 ];
63 
64     sprintf( buf, "w = %d, h = %d", w, h );
65     fl_set_object_label( fd_form0->text, buf );
66 }
67 
68 
69 /***************************************
70  ***************************************/
71 
72 static FD_form0 *
create_form_form0(void)73 create_form_form0( void )
74 {
75     FL_OBJECT * obj;
76     FD_form0 * fdui = fl_calloc( 1, sizeof *fdui );
77 
78     fdui->form0 = fl_bgn_form( FL_FLAT_BOX, 311, 181 );
79 
80     obj = fl_add_input( FL_NORMAL_INPUT, 20, 30, 280, 30, "" );
81     fl_set_object_callback( obj, input_cb, 0 );
82     fl_set_object_return( obj, FL_RETURN_ALWAYS );
83 
84     fdui->text = obj = fl_add_text( FL_NORMAL_TEXT, 60, 90, 130, 30, "Text" );
85     fl_set_object_lalign( obj, fl_to_inside_lalign( FL_ALIGN_LEFT ) );
86 
87     obj = fl_add_button( FL_NORMAL_BUTTON, 220, 130, 80, 30, "Done" );
88     fl_set_object_callback( obj, exit_cb, 0 );
89 
90     fl_end_form( );
91 
92     return fdui;
93 }
94 
95 
96 /***************************************
97  ***************************************/
98 
99 int
main(int argc,char * argv[])100 main( int    argc,
101       char * argv[ ] )
102 {
103     fl_initialize( &argc, argv, 0, 0, 0 );
104 
105     fd_form0 = create_form_form0( );
106 
107     fl_show_form( fd_form0->form0, FL_PLACE_CENTER, FL_FULLBORDER, "form0" );
108 
109     fl_do_forms( );
110 
111     return 0;
112 }
113 
114 
115 /*
116  * Local variables:
117  * tab-width: 4
118  * indent-tabs-mode: nil
119  * End:
120  */
121