1 /*
2  *  This file is part of the XForms library package.
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 License
15  *  along with XForms.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 
19 /**
20  * \file goodie_sinput.c
21  *
22  *  This file is part of the XForms library package.
23  *  Copyright (c) 1996-2002  T.C. Zhao and Mark Overmars
24  *  All rights reserved.
25  */
26 
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30 
31 #include "include/forms.h"
32 #include "flinternal.h"
33 
34 
35 /***********    Simple input    ********************{*******/
36 
37 typedef struct
38 {
39     FL_FORM   * form;
40     FL_OBJECT * str1;
41     FL_OBJECT * input;
42     FL_OBJECT * but;
43 } FD_input;
44 
45 
46 /***************************************
47  ***************************************/
48 
49 static FD_input *
create_input(const char * str1,const char * defstr)50 create_input( const char * str1,
51               const char * defstr )
52 {
53     FD_input *fdui = fl_calloc( 1, sizeof *fdui );
54     int oldy = fli_inverted_y;
55     int oldu = fl_get_coordunit( );
56 
57     fli_inverted_y = 0;
58     fl_set_coordunit( FL_COORD_PIXEL );
59 
60     fdui->form = fl_bgn_form( FL_FLAT_BOX, 460, 130 );
61 
62     fdui->input = fl_add_input( FL_NORMAL_INPUT, 30, 50, 400, 30, str1 );
63     fl_set_input( fdui->input, defstr );
64 
65     fdui->but = fl_add_button( FL_RETURN_BUTTON, 185, 94, 90, 27, "OK" );
66     fli_parse_goodies_label( fdui->but, FLOKLabel );
67 
68     fl_set_form_hotobject( fdui->form, fdui->but );
69 
70     fl_end_form( );
71 
72     fli_handle_goodie_font( fdui->but, fdui->input );
73 
74     fl_register_raw_callback( fdui->form, FL_ALL_EVENT,
75                               fli_goodies_preemptive );
76     fl_set_form_atclose( fdui->form, fl_goodies_atclose, fdui->but );
77 
78     fli_inverted_y = oldy;
79     fl_set_coordunit( oldu );
80 
81     return fdui;
82 }
83 
84 static FD_input *fd_input = NULL;
85 static char *ret_str = NULL;
86 
87 
88 /***************************************
89  * Asks the user for textual input
90  ***************************************/
91 
92 const char *
fl_show_simple_input(const char * str1,const char * defstr)93 fl_show_simple_input( const char * str1,
94                       const char * defstr )
95 {
96     if ( fd_input )
97     {
98         fl_hide_form( fd_input->form );
99         fl_free_form( fd_input->form );
100         fli_safe_free( fd_input );
101     }
102     else
103         fl_deactivate_all_forms( );
104 
105     fli_safe_free( ret_str );
106 
107     fd_input = create_input( str1, defstr );
108 
109     fl_show_form( fd_input->form, FL_PLACE_HOTSPOT, FL_TRANSIENT, "Input" );
110     fl_update_display( 0 );
111 
112     while ( fl_do_only_forms( ) != fd_input->but )
113         /* empty */ ;
114 
115     ret_str = fl_strdup( fl_get_input( fd_input->input ) );
116 
117     fl_hide_form( fd_input->form );
118     fl_free_form( fd_input->form );
119     fli_safe_free( fd_input );
120 
121     fl_activate_all_forms( );
122 
123     return ret_str;
124 }
125 
126 
127 /***************************************
128  ***************************************/
129 
130 void
fli_sinput_cleanup(void)131 fli_sinput_cleanup( void )
132 {
133     fli_safe_free( fd_input );
134     fli_safe_free( ret_str );
135 }
136 
137 
138 /*
139  * Local variables:
140  * tab-width: 4
141  * indent-tabs-mode: nil
142  * End:
143  */
144