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 goodies.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 * Common routines for the goodies
27 */
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include "include/forms.h"
34 #include "flinternal.h"
35 #include "bitmaps/q.xbm" /* in directory bitmaps */
36 #include "bitmaps/warn.xbm" /* in directory bitmaps */
37
38
39 /***************************************
40 ***************************************/
41
42 void
fl_update_display(int block)43 fl_update_display( int block )
44 {
45 if ( block )
46 XSync( flx->display, 0 );
47 else
48 XFlush( flx->display );
49 }
50
51
52 /***************************************
53 * Preemptive handler to work around a bug in some window managers
54 * where iconification causes a window to close. For normal closing,
55 * we don't see any unmap events as winclose eats it
56 ***************************************/
57
58 int
fli_goodies_preemptive(FL_FORM * form,void * ev)59 fli_goodies_preemptive( FL_FORM * form,
60 void * ev )
61 {
62 if ( ( ( XEvent * ) ev )->type == UnmapNotify )
63 {
64 fl_trigger_object( form->u_vdata );
65 return FL_PREEMPT;
66 }
67
68 return 0;
69 }
70
71
72 /***************************************
73 ***************************************/
74
75 int
fl_goodies_atclose(FL_FORM * form,void * data)76 fl_goodies_atclose( FL_FORM * form,
77 void * data )
78 {
79 fl_trigger_object( data ? data : form->u_vdata );
80 if ( form->sort_of_modal )
81 form->sort_of_modal = 0;
82
83 return FL_IGNORE;
84 }
85
86
87 /***************************************
88 ***************************************/
89
90 void
fli_parse_goodies_label(FL_OBJECT * ob,const char * name)91 fli_parse_goodies_label( FL_OBJECT * ob,
92 const char * name )
93 {
94 char s[ 256 ];
95
96 if ( fl_get_resource( name, NULL, FL_STRING, NULL, s, 256 ) )
97 {
98 fl_set_object_label( ob, s );
99 fl_fit_object_label( ob, 5, 2 );
100 }
101 }
102
103
104 /***************************************
105 ***************************************/
106
107 void
fli_get_goodie_title(FL_FORM * form,const char * res)108 fli_get_goodie_title( FL_FORM * form,
109 const char * res )
110 {
111 char s[ 256 ];
112
113 if ( fl_get_resource( res, NULL, FL_STRING, NULL, s, 256 ) )
114 fl_set_form_title( form, s );
115 }
116
117
118
119 static int goodie_style = FL_NORMAL_STYLE,
120 goodie_size = FL_DEFAULT_SIZE;
121
122
123 /***************************************
124 ***************************************/
125
126 void
fl_set_goodies_font(int style,int size)127 fl_set_goodies_font( int style,
128 int size )
129 {
130 goodie_style = style;
131 goodie_size = size;
132 }
133
134
135 /***************************************
136 ***************************************/
137
138 void
fli_get_goodies_font(int * style,int * size)139 fli_get_goodies_font( int * style,
140 int * size )
141 {
142 *style = goodie_style;
143 *size = goodie_size;
144 }
145
146
147 /***************************************
148 ***************************************/
149
150 void
fli_handle_goodie_font(FL_OBJECT * ob1,FL_OBJECT * ob2)151 fli_handle_goodie_font( FL_OBJECT * ob1,
152 FL_OBJECT * ob2 )
153 {
154 if ( goodie_style < 0 )
155 return;
156
157 if ( ob1 )
158 {
159 fl_set_object_lstyle( ob1, goodie_style );
160 fl_set_object_lsize( ob1, goodie_size );
161 fl_fit_object_label( ob1, 1, 1 );
162 }
163
164 if ( ob2 )
165 {
166 fl_set_object_lstyle( ob2, goodie_style );
167 fl_set_object_lsize( ob2, goodie_size );
168 }
169 }
170
171
172 /***************************************
173 ***************************************/
174
175 static void
fli_box_vert(FL_Coord x,FL_Coord y,FL_Coord w,FL_Coord h)176 fli_box_vert( FL_Coord x,
177 FL_Coord y,
178 FL_Coord w,
179 FL_Coord h )
180 {
181 int halfh = 0.5 * h,
182 halfw = 0.5 * w;
183
184 fli_add_vertex( x, y + halfh );
185 fli_add_vertex( x + halfw, y );
186 fli_add_vertex( x + 2 * halfw, y + halfh );
187 fli_add_vertex( x + halfw, y + 2 * halfh );
188 }
189
190
191 /***************************************
192 ***************************************/
193
194 static int
draw_box(FL_OBJECT * ob,int ev,FL_Coord x FL_UNUSED_ARG,FL_Coord y FL_UNUSED_ARG,int k FL_UNUSED_ARG,void * sp FL_UNUSED_ARG)195 draw_box( FL_OBJECT * ob,
196 int ev,
197 FL_Coord x FL_UNUSED_ARG,
198 FL_Coord y FL_UNUSED_ARG,
199 int k FL_UNUSED_ARG,
200 void * sp FL_UNUSED_ARG )
201 {
202 int p = ( FL_max( ob->w, ob->h ) / 2 ) * 2 + 1;
203
204 if ( ev != FL_DRAW )
205 return 0;
206
207 fl_winset( FL_ObjWin( ob ) );
208
209 if ( ! fli_dithered( fl_vmode ) )
210 {
211 fl_color( FL_YELLOW );
212 fli_reset_vertex( );
213 fli_box_vert( ob->x, ob->y, p, p );
214 fli_endpolygon( );
215 }
216 fl_linewidth( 2 );
217 fl_color( FL_BLACK );
218 fli_reset_vertex( );
219 fli_box_vert( ob->x, ob->y, ob->w, ob->h );
220 fli_endclosedline( );
221 fl_linewidth( 0 );
222
223 return 0;
224 }
225
226
227 /***************************************
228 ***************************************/
229
230 void
fli_add_q_icon(FL_Coord x,FL_Coord y,FL_Coord w,FL_Coord h)231 fli_add_q_icon( FL_Coord x,
232 FL_Coord y,
233 FL_Coord w,
234 FL_Coord h )
235 {
236 FL_OBJECT *obj;
237
238 fl_add_free( FL_INACTIVE_FREE, x, y, w, h, "", draw_box );
239 obj = fl_add_bitmap( FL_NORMAL_BITMAP, x, y, w, h, "" );
240 fl_set_bitmap_data( obj, q_width, q_height, q_bits );
241 fl_set_object_color( obj, FL_YELLOW, FL_YELLOW );
242 fl_set_object_lcolor( obj, FL_BLACK );
243 }
244
245
246 /***************************************
247 ***************************************/
248
249 void
fli_add_warn_icon(FL_Coord x,FL_Coord y,FL_Coord w,FL_Coord h)250 fli_add_warn_icon( FL_Coord x,
251 FL_Coord y,
252 FL_Coord w,
253 FL_Coord h )
254 {
255 FL_OBJECT *obj;
256
257 fl_add_free( FL_INACTIVE_FREE, x, y, w, h, "", draw_box );
258 obj = fl_add_bitmap( FL_NORMAL_BITMAP, x, y, w, h, "" );
259 fl_set_bitmap_data( obj, warn_width, warn_height, warn_bits );
260 fl_set_object_color( obj, FL_YELLOW, FL_YELLOW );
261 fl_set_object_lcolor( obj, FL_BLACK );
262 }
263
264
265 /***************************************
266 ***************************************/
267
268 void
fli_goodies_cleanup(void)269 fli_goodies_cleanup( void )
270 {
271 fli_msg_cleanup( );
272 fli_alert_cleanup( );
273 fli_choice_cleanup( );
274 fli_question_cleanup( );
275 fli_input_cleanup( );
276 fli_sinput_cleanup( );
277 }
278
279
280 /*
281 * Local variables:
282 * tab-width: 4
283 * indent-tabs-mode: nil
284 * End:
285 */
286