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_freeobj.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 free object class specific attributes, in this
27 * case, the handler name. We store this piece of into in
28 * ob->c_vdata.
29 */
30
31 #ifdef HAVE_CONFIG_H
32 #include "config.h"
33 #endif
34
35 #include <ctype.h>
36
37 #include "fd_main.h"
38 #include "fd_spec.h"
39 #include "sp_freeobj.h"
40 #include "spec/freeobj_spec.h"
41
42 static char *get_free_handle( FL_OBJECT * ob,
43 const char * name );
44
45 static char ori_handle_name[ 128 ];
46
47 static FD_freeobjattrib *fo_attrib;
48 static FL_OBJECT *curobj;
49
50
51 /***************************************
52 ***************************************/
53
54 FL_FORM *
freeobj_create_spec_form(void)55 freeobj_create_spec_form( void )
56 {
57 if ( ! fo_attrib )
58 fo_attrib = create_form_freeobjattrib( );
59
60 return fo_attrib->freeobjattrib;
61 }
62
63
64 /***************************************
65 ***************************************/
66
67 void
freeobj_adjust_spec_form(FL_OBJECT * obj)68 freeobj_adjust_spec_form( FL_OBJECT * obj )
69 {
70 curobj = obj;
71
72 *ori_handle_name = '\0';
73 if ( obj->c_vdata )
74 strcpy( ori_handle_name, obj->c_vdata );
75 }
76
77
78 /***************************************
79 ***************************************/
80
81 void
freeobj_fill_in_spec_form(FL_OBJECT * obj)82 freeobj_fill_in_spec_form( FL_OBJECT * obj )
83 {
84 fl_set_input( fo_attrib->hname, get_free_handle( obj, 0 ) );
85 }
86
87
88 /***************************************
89 ***************************************/
90
91 void
freeobj_reread_spec_form(FL_OBJECT * obj FL_UNUSED_ARG)92 freeobj_reread_spec_form( FL_OBJECT * obj FL_UNUSED_ARG )
93 {
94 if ( curobj )
95 handler_name_change_cb( fo_attrib->hname, 0 );
96 }
97
98
99 /***************************************
100 ***************************************/
101
102 void
freeobj_restore_spec(FL_OBJECT * obj)103 freeobj_restore_spec( FL_OBJECT * obj )
104 {
105 fli_safe_free( obj->c_vdata );
106 obj->c_vdata = fl_strdup( ori_handle_name );
107 }
108
109
110 /***************************************
111 ***************************************/
112
113 void
freeobj_emit_spec_fd_code(FILE * fp,FL_OBJECT * obj)114 freeobj_emit_spec_fd_code( FILE * fp,
115 FL_OBJECT * obj )
116 {
117 if ( obj->c_vdata )
118 fprintf( fp, " handler: %s\n", ( char * ) obj->c_vdata );
119 }
120
121
122 /***************************************
123 ***************************************/
124
125 int
noop_handle(FL_OBJECT * obj,int e,FL_Coord mx FL_UNUSED_ARG,FL_Coord my FL_UNUSED_ARG,int k FL_UNUSED_ARG,void * xev FL_UNUSED_ARG)126 noop_handle( FL_OBJECT * obj,
127 int e,
128 FL_Coord mx FL_UNUSED_ARG,
129 FL_Coord my FL_UNUSED_ARG,
130 int k FL_UNUSED_ARG,
131 void * xev FL_UNUSED_ARG )
132 {
133 if ( e == FL_DRAW )
134 {
135 fl_draw_box( obj->boxtype, obj->x, obj->y, obj->w, obj->h,
136 obj->col1, obj->bw );
137 return 0;
138 }
139
140 if ( obj->type == FL_INACTIVE_FREE )
141 return 0;
142 else if ( obj->type == FL_INPUT_FREE )
143 return e == FL_KEYPRESS;
144
145 return 1;
146 }
147
148
149 /***************************************
150 ***************************************/
151
152 void
handler_name_change_cb(FL_OBJECT * obj,long data FL_UNUSED_ARG)153 handler_name_change_cb( FL_OBJECT * obj,
154 long data FL_UNUSED_ARG )
155 {
156 fli_safe_free( curobj->c_vdata );
157 curobj->c_vdata = fl_strdup( fl_get_input( obj ) );
158 }
159
160
161 /* default free object handler name */
162
163 #define MAXFREEOBJ 16
164
165 /***************************************
166 ***************************************/
167
168 static char *
get_free_handle(FL_OBJECT * obj,const char * name)169 get_free_handle( FL_OBJECT * obj,
170 const char * name )
171 {
172 static int n;
173 static char buf[ 1024 ];
174 static FL_OBJECT *freeobj[ MAXFREEOBJ ];
175
176 if ( obj->c_vdata )
177 strcpy( buf, obj->c_vdata );
178 else if ( name && *name )
179 sprintf( buf, "freeobj_%s_handle", name );
180 else if ( *obj->label )
181 sprintf( buf, "freeobj_%s_handle", obj->label );
182 else
183 {
184 int i, k;
185
186 for ( k = -1, i = 0; i < MAXFREEOBJ && k < 0; i++ )
187 if ( freeobj[ i ] == obj )
188 k = i;
189
190 if ( k < 0 )
191 {
192 k = ++n;
193 freeobj[ k ] = obj;
194 }
195
196 sprintf( buf, "freeobj%d_handle", k );
197 }
198
199 return buf;
200 }
201
202
203 #include "spec/freeobj_spec.c"
204
205
206 /*
207 * Local variables:
208 * tab-width: 4
209 * indent-tabs-mode: nil
210 * End:
211 */
212