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 License
15 * along with XForms. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18
19 /**
20 * \file sp_browser.c
21 *
22 * This file is part of XForms package
23 * Copyright (c) 1996-2002 T.C. Zhao and Mark Overmars
24 * All rights reserved.
25 *.
26 * Settting browser class specific attributes.
27 */
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include "fd_main.h"
34 #include "fd_spec.h"
35 #include "sp_browser.h"
36 #include "private/pbrowser.h"
37 #include "spec/browser_spec.h"
38
39 static FD_browserattrib *br_attrib;
40 static FL_OBJECT * curobj;
41
42
43 /***************************************
44 ***************************************/
45
46 FL_FORM *
browser_create_spec_form(void)47 browser_create_spec_form( void )
48 {
49 if ( br_attrib )
50 return br_attrib->browserattrib;
51
52 br_attrib = create_form_browserattrib( );
53
54 fl_addto_choice( br_attrib->hscb_pref, get_scrollbar_pref_string( ) );
55 fl_addto_choice( br_attrib->vscb_pref, get_scrollbar_pref_string( ) );
56 setup_how_return_menu( br_attrib->returnsetting );
57
58 return br_attrib->browserattrib;
59 }
60
61
62 /***************************************
63 ***************************************/
64
65 void
browser_fill_in_spec_form(FL_OBJECT * obj)66 browser_fill_in_spec_form( FL_OBJECT * obj )
67 {
68 FLI_BROWSER_SPEC *sp = obj->spec;
69 int i;
70 int nlines = fl_get_browser_maxline( obj );
71
72 curobj = obj;
73
74 fl_set_choice( br_attrib->hscb_pref, sp->h_pref + 1 );
75 fl_set_choice( br_attrib->vscb_pref, sp->v_pref + 1 );
76
77 fl_freeze_form( br_attrib->content_br->form );
78
79 fl_clear_browser( br_attrib->content_br );
80
81 for ( i = 1; i <= nlines; i++ )
82 fl_add_browser_line( br_attrib->content_br,
83 fl_get_browser_line( obj, i ) );
84
85 fl_unfreeze_form( br_attrib->content_br->form );
86
87 reset_how_return_menu( br_attrib->returnsetting, obj->how_return );
88 }
89
90
91 /***************************************
92 ***************************************/
93
94 void
browser_emit_spec_fd_code(FILE * fp,FL_OBJECT * obj)95 browser_emit_spec_fd_code( FILE * fp,
96 FL_OBJECT * obj )
97 {
98 FL_OBJECT *defobj = fl_create_browser( obj->type, 0, 0, 0, 0, "" );
99 FLI_BROWSER_SPEC *sp = obj->spec,
100 *defsp = defobj->spec;
101 int i;
102 int nlines = fl_get_browser_maxline( obj );
103
104 if ( sp->h_pref != defsp->h_pref )
105 fprintf( fp, "h_pref: %s\n",
106 get_scrollbar_pref_name( sp->h_pref ) );
107
108 if ( sp->v_pref != defsp->v_pref )
109 fprintf( fp, "v_pref: %s\n",
110 get_scrollbar_pref_name( sp->v_pref ) );
111
112 for ( i = 1; i <= nlines; i++ )
113 fprintf( fp, "content: %s\n", fl_get_browser_line( obj, i ) );
114 }
115
116
117 /***************************************
118 ***************************************/
119
120 void
browser_emit_spec_c_code(FILE * fp,FL_OBJECT * obj)121 browser_emit_spec_c_code( FILE * fp,
122 FL_OBJECT * obj )
123 {
124 FL_OBJECT *defobj = fl_create_browser( obj->type, 0, 0, 0, 0, "" );
125 FLI_BROWSER_SPEC *sp = obj->spec,
126 *defsp = defobj->spec;
127 int i;
128 int nlines = fl_get_browser_maxline( obj );
129
130 if ( sp->h_pref != defsp->h_pref )
131 fprintf( fp, " fl_set_browser_hscrollbar( obj, %s );\n",
132 get_scrollbar_pref_name( sp->h_pref ) );
133
134 if ( sp->v_pref != defsp->v_pref )
135 fprintf( fp, " fl_set_browser_vscrollbar( obj, %s );\n",
136 get_scrollbar_pref_name( sp->v_pref ) );
137
138 for ( i = 1; i <= nlines; i++ )
139 fprintf( fp, " fl_add_browser_line( obj, \"%s\" );\n",
140 fl_get_browser_line( obj, i ) );
141 }
142
143
144 /***************************************
145 * Callbacks and freeobj handles for form browserattrib
146 ***************************************/
147
148 void
add_item_cb(FL_OBJECT * obj,long data FL_UNUSED_ARG)149 add_item_cb( FL_OBJECT * obj,
150 long data FL_UNUSED_ARG )
151 {
152 FD_browserattrib *ui = obj->form->fdui;
153 const char *s = fl_get_input( ui->input );
154
155 if ( ! s )
156 s = "";
157
158 fl_addto_browser( ui->content_br, s );
159 fl_addto_browser( curobj, s );
160
161 if ( fl_get_button( ui->auto_clear ) )
162 fl_set_input( ui->input, "" );
163
164 redraw_the_form( 0 );
165 }
166
167
168 /***************************************
169 ***************************************/
170
171 void
replace_item_cb(FL_OBJECT * obj,long data FL_UNUSED_ARG)172 replace_item_cb( FL_OBJECT * obj,
173 long data FL_UNUSED_ARG )
174 {
175 FD_browserattrib *ui = obj->form->fdui;
176 int i = fl_get_browser( ui->content_br );
177 const char *s = fl_get_input( ui->input );
178
179 if ( i > 0 )
180 {
181 if ( ! s )
182 s = "";
183
184 fl_replace_browser_line( ui->content_br, i, s );
185 fl_replace_browser_line( curobj, i, s );
186
187 if ( fl_get_button( ui->auto_clear ) )
188 fl_set_input( ui->input, "" );
189 }
190
191 redraw_the_form( 0 );
192 }
193
194
195 /***************************************
196 ***************************************/
197
198 void
insert_cb(FL_OBJECT * obj,long data FL_UNUSED_ARG)199 insert_cb( FL_OBJECT * obj,
200 long data FL_UNUSED_ARG )
201 {
202 FD_browserattrib *ui = obj->form->fdui;
203 int i = fl_get_browser( ui->content_br );
204 const char *s = fl_get_input( ui->input );
205
206 if ( i > 0 )
207 {
208 if ( ! s )
209 s = "";
210
211 fl_insert_browser_line( ui->content_br, i, s );
212 fl_insert_browser_line( curobj, i, s );
213
214 if ( fl_get_button( ui->auto_clear ) )
215 fl_set_input( ui->input, "" );
216 }
217
218 redraw_the_form( 0 );
219 }
220
221
222 /***************************************
223 ***************************************/
224
225 void
delete_item_cb(FL_OBJECT * obj,long data FL_UNUSED_ARG)226 delete_item_cb( FL_OBJECT * obj,
227 long data FL_UNUSED_ARG )
228 {
229 FD_browserattrib *ui = obj->form->fdui;
230 int i = fl_get_browser( ui->content_br );
231
232 if ( i <= 0 )
233 return;
234
235 fl_delete_browser_line( ui->content_br, i );
236 fl_delete_browser_line( curobj, i );
237 redraw_the_form( 0 );
238 }
239
240
241 /***************************************
242 ***************************************/
243
244 void
hscb_pref_cb(FL_OBJECT * obj,long data FL_UNUSED_ARG)245 hscb_pref_cb( FL_OBJECT * obj,
246 long data FL_UNUSED_ARG )
247 {
248 fl_set_browser_hscrollbar( curobj, fl_get_choice( obj ) - 1 );
249 redraw_the_form( 0 );
250 }
251
252
253 /***************************************
254 ***************************************/
255
256 void
vscb_pref_cb(FL_OBJECT * obj,long data FL_UNUSED_ARG)257 vscb_pref_cb( FL_OBJECT * obj,
258 long data FL_UNUSED_ARG )
259 {
260 fl_set_browser_vscrollbar( curobj, fl_get_choice( obj ) - 1 );
261 redraw_the_form( 0 );
262 }
263
264
265 /***************************************
266 ***************************************/
267
268 void
br_returnsetting_change(FL_OBJECT * obj,long data FL_UNUSED_ARG)269 br_returnsetting_change( FL_OBJECT * obj,
270 long data FL_UNUSED_ARG )
271 {
272 handle_how_return_changes( obj, curobj );
273 }
274
275
276 /***************************************
277 ***************************************/
278
279 void
clear_field_cb(FL_OBJECT * ob,long data FL_UNUSED_ARG)280 clear_field_cb( FL_OBJECT * ob,
281 long data FL_UNUSED_ARG )
282 {
283 FD_browserattrib *ui = ob->form->fdui;
284
285 fl_set_input( ui->input, "" );
286 }
287
288
289 #include "spec/browser_spec.c"
290
291
292 /*
293 * Local variables:
294 * tab-width: 4
295 * indent-tabs-mode: nil
296 * End:
297 */
298