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 * Input return setting and raw callback. Terrible hack.
23 */
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include "include/forms.h"
29 #include <stdlib.h>
30
31 extern void howreturn_callback( FL_OBJECT *, long );
32 extern void input_callback( FL_OBJECT *, long );
33
34 /**** Forms and Objects ****/
35
36 typedef struct {
37 FL_FORM * inputform;
38 void * vdata;
39 long ldata;
40 FL_OBJECT * input1;
41 FL_OBJECT * howreturn;
42 FL_OBJECT * status;
43 FL_OBJECT * input2;
44 } FD_inputform;
45
46 extern FD_inputform *create_form_inputform( void );
47
48 /* end of minput.h */
49
50 FD_inputform *ui;
51
52
53 /***************************************
54 ***************************************/
55
56 int
peek_event(FL_FORM * form FL_UNUSED_ARG,void * xev)57 peek_event( FL_FORM * form FL_UNUSED_ARG,
58 void * xev )
59 {
60 if ( ( ( XEvent * )xev )->type == KeyPress )
61 {
62 fl_set_object_label( ui->status, "keyboard input" );
63 fl_XFlush( ); /* necessary to show the label? */
64 fl_msleep( 50 );
65 }
66
67 return 0;
68 }
69
70
71 /***************************************
72 ***************************************/
73
74 int
main(int argc,char * argv[])75 main( int argc,
76 char * argv[ ] )
77 {
78 fl_initialize( &argc, argv, "FormDemo", 0, 0 );
79 ui = create_form_inputform( );
80 fl_register_raw_callback( ui->inputform, KeyPressMask, peek_event );
81
82 fl_show_form( ui->inputform, FL_PLACE_CENTER, FL_TRANSIENT, "Input" );
83
84 fl_do_forms( );
85 fl_finish( );
86
87 return 0;
88 }
89
90
91 /***************************************
92 ***************************************/
93
94 void
input_callback(FL_OBJECT * ob FL_UNUSED_ARG,long data)95 input_callback( FL_OBJECT * ob FL_UNUSED_ARG,
96 long data )
97 {
98 char buf[ 32 ];
99
100 sprintf( buf, "Input%ld returned", data );
101 fl_set_object_label( ui->status, buf );
102 fl_XFlush( );
103 fl_msleep( 50 );
104 }
105
106
107 /***************************************
108 ***************************************/
109
110 void
howreturn_callback(FL_OBJECT * ob,long data FL_UNUSED_ARG)111 howreturn_callback( FL_OBJECT * ob,
112 long data FL_UNUSED_ARG )
113 {
114 fl_set_input_return( ui->input1, fl_get_button( ob ) );
115 fl_set_input_return( ui->input2, fl_get_button( ob ) );
116 }
117
118
119 /***************************************
120 ***************************************/
121
122 FD_inputform *
create_form_inputform(void)123 create_form_inputform( void )
124 {
125 FL_OBJECT *obj;
126 FD_inputform *fdui = fl_calloc( 1, sizeof *fdui );
127
128 fdui->inputform = fl_bgn_form( FL_NO_BOX, 475, 485 );
129
130 fl_add_box( FL_UP_BOX, 0, 0, 475, 485, "" );
131
132 fdui->input1 = obj = fl_add_input( FL_MULTILINE_INPUT, 15, 275, 350, 180,
133 "" );
134 fl_set_object_lalign( obj, FL_ALIGN_TOP );
135 fl_set_object_callback( obj, input_callback, 1 );
136
137 fdui->howreturn = obj = fl_add_checkbutton( FL_PUSH_BUTTON,
138 375, 435, 80, 35,
139 "always\nreturn" );
140 fl_set_object_color( obj, FL_COL1, FL_BLUE );
141 fl_set_object_callback( obj, howreturn_callback, 0 );
142
143 fdui->status = obj = fl_add_text( FL_NORMAL_TEXT, 20, 15, 270, 30, "" );
144 fl_set_object_boxtype( obj, FL_FRAME_BOX );
145
146 fl_add_button( FL_NORMAL_BUTTON, 375, 15, 80, 35, "Done" );
147
148 fdui->input2 = obj = fl_add_input( FL_MULTILINE_INPUT, 15, 60, 349, 185,
149 "" );
150 fl_set_object_lalign( obj, FL_ALIGN_TOP );
151 fl_set_object_callback( obj, input_callback, 2 );
152
153 fl_end_form( );
154
155 return fdui;
156 }
157
158
159 /*
160 * Local variables:
161 * tab-width: 4
162 * indent-tabs-mode: nil
163 * End:
164 */
165