Mercurial > hg > xemacs-beta
annotate lwlib/xlwcheckbox.c @ 5537:2df2d9171f20
Suppress a "shadowed local" warning.
author | Stephen J. Turnbull <stephen@xemacs.org> |
---|---|
date | Mon, 08 Aug 2011 13:57:18 +0900 |
parents | 308d34e9f07d |
children |
rev | line source |
---|---|
424 | 1 /* Checkbox Widget for XEmacs. |
2 Copyright (C) 1999 Edward A. Falk | |
3 | |
4 This file is part of XEmacs. | |
5 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4769
diff
changeset
|
6 XEmacs is free software: you can redistribute it and/or modify it |
424 | 7 under the terms of the GNU General Public License as published by the |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4769
diff
changeset
|
8 Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4769
diff
changeset
|
9 option) any later version. |
424 | 10 |
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4769
diff
changeset
|
17 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
424 | 18 |
19 /* Synched up with: Checkbox.c 1.1 */ | |
20 | |
21 /* | |
22 * Checkbox.c - Checkbox button widget | |
23 * | |
24 * Author: Edward A. Falk | |
25 * falk@falconer.vip.best.com | |
442 | 26 * |
424 | 27 * Date: June 30, 1997 |
28 * | |
29 * Overview: This widget is identical to the Radio widget in behavior, | |
30 * except that the button is square and has a check mark. | |
31 */ | |
32 | |
33 | |
34 #include <config.h> | |
35 #include <stdio.h> | |
36 | |
37 #include <X11/IntrinsicP.h> | |
38 #include <X11/StringDefs.h> | |
442 | 39 #include ATHENA_XawInit_h_ |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
40 #include "xt-wrappers.h" |
424 | 41 #include "xlwcheckboxP.h" |
42 | |
43 | |
44 /* by using the same size for the checkbox as for the diamond box, | |
45 * we can let the Radio widget do the vast majority of the work. | |
46 */ | |
47 | |
48 #define BOX_SIZE 8 | |
49 #define DRAW_CHECK 0 /* don't draw the check mark */ | |
50 | |
51 #define cclass(w) ((CheckboxWidgetClass)((w)->core.widget_class)) | |
52 | |
53 #ifdef _ThreeDP_h | |
54 #define swid(cw) ((cw)->threeD.shadow_width) | |
55 #else | |
56 #define swid(cw) ((cw)->core.border_width) | |
57 #endif | |
58 | |
59 #define bsize(cw) (cclass(cw)->radio_class.dsize) | |
60 #define bs(cw) (bsize(cw) + 2*swid(cw)) | |
61 | |
62 | |
63 #if DRAW_CHECK | |
64 #define check_width 14 | |
65 #define check_height 14 | |
458 | 66 static unsigned char check_bits[] = { |
424 | 67 0x00, 0x00, 0x00, 0x20, 0x00, 0x18, 0x00, 0x0c, 0x00, 0x06, 0x00, 0x03, |
68 0x8c, 0x03, 0xde, 0x01, 0xff, 0x01, 0xfe, 0x00, 0xfc, 0x00, 0x78, 0x00, | |
69 0x70, 0x00, 0x20, 0x00}; | |
70 #endif | |
71 | |
72 | |
73 /**************************************************************** | |
74 * | |
75 * Full class record constant | |
76 * | |
77 ****************************************************************/ | |
78 | |
79 | |
80 #if DRAW_CHECK | |
81 static char defaultTranslations[] = | |
82 "<EnterWindow>: highlight()\n\ | |
83 <LeaveWindow>: unpress(draw) unhighlight()\n\ | |
84 <Btn1Down>: press()\n\ | |
85 <Btn1Down>,<Btn1Up>: unpress(nodraw) toggle() notify()"; | |
86 #endif | |
87 | |
88 | |
89 | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
90 #define offset(field) XtOffsetOf(CheckboxRec, checkbox.field) |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
91 #define res(name,_class,intrepr,type,member,extrepr,value) \ |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
92 Xt_RESOURCE (name, _class, intrepr, type, offset(member), extrepr, value) |
424 | 93 static XtResource resources[] = { |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
94 res (XtNtristate, XtCTristate, XtRBoolean, Boolean, tristate, |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
95 XtRImmediate, FALSE), |
424 | 96 } ; |
97 #undef offset | |
98 | |
99 /* Member functions */ | |
100 | |
101 static void CheckboxClassInit (void); | |
102 static void CheckboxInit (Widget, Widget, ArgList, Cardinal *); | |
103 #if DRAW_CHECK | |
104 static void CheckboxRealize (Widget, Mask *, XSetWindowAttributes *); | |
105 #endif | |
106 static void DrawCheck (Widget); | |
107 | |
108 | |
109 /* Action procs */ | |
110 #if DRAW_CHECK | |
111 static void CheckboxPress (Widget, XEvent *, String *, Cardinal *); | |
112 static void CheckboxUnpress (Widget, XEvent *, String *, Cardinal *); | |
113 #endif | |
114 | |
115 /* internal privates */ | |
116 | |
117 #if DRAW_CHECK | |
118 static XtActionsRec actionsList[] = | |
119 { | |
120 {"press", CheckboxPress}, | |
121 {"unpress", CheckboxUnpress}, | |
122 } ; | |
123 #endif | |
124 | |
125 #define SuperClass ((RadioWidgetClass)&radioClassRec) | |
126 | |
127 CheckboxClassRec checkboxClassRec = { | |
128 { | |
442 | 129 (WidgetClass) SuperClass, /* superclass */ |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
130 (String) "Checkbox", /* class_name */ |
424 | 131 sizeof(CheckboxRec), /* size */ |
132 CheckboxClassInit, /* class_initialize */ | |
133 NULL, /* class_part_initialize */ | |
134 FALSE, /* class_inited */ | |
135 CheckboxInit, /* initialize */ | |
136 NULL, /* initialize_hook */ | |
137 #if DRAW_CHECK | |
138 CheckboxRealize, /* realize */ | |
139 actionsList, /* actions */ | |
140 XtNumber(actionsList), /* num_actions */ | |
141 #else | |
142 XtInheritRealize, /* realize */ | |
143 NULL, /* actions */ | |
144 0, /* num_actions */ | |
145 #endif | |
146 resources, /* resources */ | |
147 XtNumber(resources), /* resource_count */ | |
148 NULLQUARK, /* xrm_class */ | |
149 TRUE, /* compress_motion */ | |
150 TRUE, /* compress_exposure */ | |
151 TRUE, /* compress_enterleave */ | |
152 FALSE, /* visible_interest */ | |
153 NULL, /* destroy */ | |
154 XtInheritResize, /* resize */ | |
155 XtInheritExpose, /* expose */ | |
156 NULL, /* set_values */ | |
157 NULL, /* set_values_hook */ | |
158 XtInheritSetValuesAlmost, /* set_values_almost */ | |
159 NULL, /* get_values_hook */ | |
160 NULL, /* accept_focus */ | |
161 XtVersion, /* version */ | |
162 NULL, /* callback_private */ | |
163 #if DRAW_CHECK | |
164 defaultTranslations, /* tm_table */ | |
165 #else | |
166 XtInheritTranslations, /* tm_table */ | |
167 #endif | |
168 XtInheritQueryGeometry, /* query_geometry */ | |
169 XtInheritDisplayAccelerator, /* display_accelerator */ | |
170 NULL /* extension */ | |
171 }, /* CoreClass fields initialization */ | |
172 { | |
442 | 173 XtInheritChangeSensitive /* change_sensitive */ |
424 | 174 }, /* SimpleClass fields initialization */ |
175 #ifdef _ThreeDP_h | |
176 { | |
177 XtInheritXaw3dShadowDraw /* field not used */ | |
178 }, /* ThreeDClass fields initialization */ | |
179 #endif | |
180 { | |
181 0 /* field not used */ | |
182 }, /* LabelClass fields initialization */ | |
183 { | |
184 0 /* field not used */ | |
185 }, /* CommandClass fields initialization */ | |
186 { | |
187 RadioSet, /* Set Procedure. */ | |
188 RadioUnset, /* Unset Procedure. */ | |
189 NULL /* extension. */ | |
190 }, /* ToggleClass fields initialization */ | |
191 { | |
192 BOX_SIZE, | |
193 DrawCheck, /* draw procedure */ | |
194 NULL /* extension. */ | |
195 }, /* RadioClass fields initialization */ | |
196 { | |
197 NULL /* extension. */ | |
198 }, /* CheckboxClass fields initialization */ | |
199 }; | |
200 | |
201 /* for public consumption */ | |
202 WidgetClass checkboxWidgetClass = (WidgetClass) &checkboxClassRec; | |
203 | |
204 | |
205 | |
206 | |
207 | |
208 | |
209 /**************************************************************** | |
210 * | |
211 * Class Methods | |
212 * | |
213 ****************************************************************/ | |
214 | |
215 static void | |
216 CheckboxClassInit (void) | |
217 { | |
218 XawInitializeWidgetSet(); | |
219 } | |
220 | |
221 | |
222 /*ARGSUSED*/ | |
223 static void | |
2286 | 224 CheckboxInit (Widget UNUSED (request), |
225 #if DRAW_CHECK | |
424 | 226 Widget new, |
2286 | 227 #else |
3072 | 228 Widget UNUSED (new_), |
2286 | 229 #endif |
230 ArgList UNUSED (args), | |
231 Cardinal *UNUSED (num_args)) | |
424 | 232 { |
233 #if DRAW_CHECK | |
3072 | 234 CheckboxWidget cw = (CheckboxWidget) new_; |
424 | 235 cw->checkbox.checkmark = None ; |
236 cw->checkbox.checkmark_GC = None ; | |
237 #endif | |
238 } | |
239 | |
240 | |
241 #if DRAW_CHECK | |
242 static void | |
243 CheckboxRealize(Widget w, | |
244 Mask *valueMask, | |
245 XSetWindowAttributes *attributes) | |
246 { | |
247 CheckboxWidget cw = (CheckboxWidget) w; | |
248 XtGCMask value_mask, dynamic_mask, dontcare_mask ; | |
249 XGCValues values ; | |
250 | |
251 /* first, call superclass realize */ | |
252 (*checkboxWidgetClass->core_class.superclass->core_class.realize) | |
253 (w, valueMask, attributes); | |
254 | |
255 /* TODO: cache this via xmu */ | |
256 if( cw->checkbox.checkmark == None ) | |
257 cw->checkbox.checkmark = | |
258 XCreateBitmapFromData( XtDisplay(w), XtWindow(w), | |
259 check_bits,check_width,check_height); | |
260 | |
261 values.fill_style = FillStippled ; | |
262 values.stipple = cw->checkbox.checkmark ; | |
263 values.foreground = cw->label.foreground ; | |
264 value_mask = GCFillStyle | GCStipple | GCForeground ; | |
265 dynamic_mask = GCTileStipXOrigin | GCTileStipYOrigin ; | |
266 dontcare_mask = GCLineWidth | GCLineStyle | GCCapStyle | GCJoinStyle | | |
267 GCFont | GCSubwindowMode | GCGraphicsExposures | | |
268 GCDashOffset | GCDashList | GCArcMode ; | |
269 cw->checkbox.checkmark_GC = | |
270 XtAllocateGC(w, 0, value_mask, &values, dynamic_mask, dontcare_mask) ; | |
271 } | |
272 #endif | |
273 | |
274 | |
275 /* Function Name: CheckboxDestroy | |
276 * Description: Destroy Callback for checkbox widget. | |
277 * Arguments: w - the checkbox widget that is being destroyed. | |
442 | 278 * junk, garbage - not used. |
424 | 279 * Returns: none. |
280 */ | |
281 | |
282 /* ARGSUSED */ | |
3072 | 283 #if DRAW_CHECK |
424 | 284 static void |
2286 | 285 CheckboxDestroy ( |
286 Widget w, | |
287 XtPointer UNUSED (junk), | |
288 XtPointer UNUSED (garbage)) | |
424 | 289 { |
290 CheckboxWidget cw = (CheckboxWidget) w; | |
291 | |
292 /* TODO: cache this via xmu */ | |
293 if( cw->checkbox.checkmark != None ) | |
294 XFreePixmap( XtDisplay(w), cw->checkbox.checkmark ) ; | |
295 if( cw->checkbox.checkmark_GC != None ) | |
296 XtReleaseGC(w, cw->checkbox.checkmark_GC) ; | |
297 } | |
3072 | 298 #endif /* DRAW_CHECK */ |
424 | 299 |
300 | |
301 | |
302 #if DRAW_CHECK | |
303 /************************************************************ | |
304 * | |
305 * Actions Procedures | |
306 * | |
307 ************************************************************/ | |
308 | |
309 /* ARGSUSED */ | |
310 static void | |
311 CheckboxPress (Widget w, | |
312 XEvent *event, | |
313 String *params, /* unused */ | |
314 Cardinal *num_params) /* unused */ | |
315 { | |
316 CheckboxWidget cw = (CheckboxWidget) w ; | |
317 if( !cw->checkbox.pressed ) { | |
318 cw->checkbox.pressed = TRUE ; | |
319 ((CheckboxWidgetClass)(w->core.widget_class))->radio_class.drawDiamond(w) ; | |
320 } | |
321 } | |
322 | |
323 static void | |
324 CheckboxUnpress (Widget w, | |
325 XEvent *event, | |
326 String *params, /* unused */ | |
327 Cardinal *num_params) /* unused */ | |
328 { | |
329 CheckboxWidget cw = (CheckboxWidget) w ; | |
330 int i ; | |
331 | |
332 if( cw->checkbox.pressed ) { | |
333 cw->checkbox.pressed = FALSE ; | |
334 if( *num_params > 0 && **params == 'd' ) | |
335 ((CheckboxWidgetClass)(w->core.widget_class))->radio_class.drawDiamond(w); | |
336 } | |
337 } | |
338 #endif | |
339 | |
340 | |
341 | |
342 | |
343 | |
344 /************************************************************ | |
345 * | |
346 * Internal Procedures | |
347 * | |
348 ************************************************************/ | |
349 | |
350 static void | |
351 DrawCheck (Widget w) | |
352 { | |
353 CheckboxWidget cw = (CheckboxWidget) w ; | |
354 Display *dpy = XtDisplay(w) ; | |
355 Window win = XtWindow(w) ; | |
356 GC gc ; | |
357 | |
358 #ifdef _ThreeDP_h | |
359 XPoint pts[6] ; | |
360 #endif | |
361 Dimension s = swid(cw); | |
362 Dimension bsz = bsize(cw); | |
363 Position bx,by ; /* Check upper-left */ | |
2286 | 364 Dimension bh ; |
424 | 365 #ifdef _ThreeDP_h |
2286 | 366 Dimension bw; |
424 | 367 GC top, bot; |
368 #endif | |
369 GC ctr ; | |
370 | |
371 /* foreground GC */ | |
372 gc = XtIsSensitive(w) ? cw->command.normal_GC : cw->label.gray_GC ; | |
373 | |
2286 | 374 bh = bs(cw) ; |
424 | 375 bx = cw->label.internal_width ; |
376 by = cw->core.height/2 - bh/2 ; | |
377 | |
378 #ifdef _ThreeDP_h | |
2286 | 379 bw = bh ; |
380 | |
424 | 381 if( !cw->command.set ) { |
382 top = cw->threeD.top_shadow_GC ; | |
383 bot = cw->threeD.bot_shadow_GC ; | |
384 } else { | |
385 top = cw->threeD.bot_shadow_GC ; | |
386 bot = cw->threeD.top_shadow_GC ; | |
387 } | |
388 ctr = cw->command.inverse_GC ; | |
389 #else | |
390 ctr = cw->command.set ? cw->command.normal_GC : cw->command.inverse_GC ; | |
391 #endif | |
392 | |
393 XFillRectangle(dpy,win,ctr, bx+s,by+s, bsz,bsz) ; | |
394 | |
395 #ifdef _ThreeDP_h | |
396 /* top-left shadow */ | |
397 pts[0].x = bx ; pts[0].y = by ; | |
398 pts[1].x = bw ; pts[1].y = 0 ; | |
399 pts[2].x = -s ; pts[2].y = s ; | |
400 pts[3].x = -bsz ; pts[3].y = 0 ; | |
401 pts[4].x = 0 ; pts[4].y = bsz ; | |
402 pts[5].x = -s ; pts[5].y = s ; | |
403 XFillPolygon(dpy,win,top, pts,6, Nonconvex,CoordModePrevious) ; | |
404 /* bottom-right shadow */ | |
405 pts[0].x = bx+bw ; pts[0].y = by+bh ; | |
406 pts[1].x = -bw ; pts[1].y = 0 ; | |
407 pts[2].x = s ; pts[2].y = -s ; | |
408 pts[3].x = bsz ; pts[3].y = 0 ; | |
409 pts[4].x = 0 ; pts[4].y = -bsz ; | |
410 pts[5].x = s ; pts[5].y = -s ; | |
411 XFillPolygon(dpy,win,bot, pts,6, Nonconvex,CoordModePrevious) ; | |
412 #else | |
413 XDrawRectangle(dpy,win,gc, bx+s,by+s, bsz,bsz) ; | |
414 #endif | |
415 | |
416 #if DRAW_CHECK | |
417 if( cw->command.set && cw->checkbox.checkmark_GC != None ) { | |
418 XSetTSOrigin(dpy,cw->checkbox.checkmark_GC, bx+s, by+s) ; | |
419 XFillRectangle(dpy,win,cw->checkbox.checkmark_GC, | |
420 bx+s, by+s, check_width,check_height) ; | |
421 } | |
422 #endif | |
423 } |