Debian Codegraph @

src/Simple.c

raw
1 /***********************************************************
2
3 Copyright 1987, 1988, 1994, 1998 The Open Group
4
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
24
25
26 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
27
28 All Rights Reserved
29
30 Permission to use, copy, modify, and distribute this software and its
31 documentation for any purpose and without fee is hereby granted,
32 provided that the above copyright notice appear in all copies and that
33 both that copyright notice and this permission notice appear in
34 supporting documentation, and that the name of Digital not be
35 used in advertising or publicity pertaining to distribution of the
36 software without specific, written prior permission.
37
38 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
44 SOFTWARE.
45
46 ******************************************************************/
47
48 #ifdef HAVE_CONFIG_H
49 #include <config.h>
50 #endif
51 #include <stdio.h>
52 #include <X11/IntrinsicP.h>
53 #include <X11/StringDefs.h>
54 #include <X11/Xmu/Drawing.h>
55 #include <X11/Xaw/SimpleP.h>
56 #include <X11/Xaw/XawInit.h>
57 #include "Private.h"
58 #ifndef OLDXAW
59 #include <X11/Xaw/Tip.h>
60 #endif
61
62 /*
63 * Class Methods
64 */
65 static Bool ChangeSensitive(Widget);
66 static void XawSimpleClassInitialize(void);
67 static void XawSimpleClassPartInitialize(WidgetClass);
68 #ifndef OLDXAW
69 static void XawSimpleInitialize(Widget, Widget, ArgList, Cardinal*);
70 static void XawSimpleDestroy(Widget);
71 static void XawSimpleExpose(Widget, XEvent*, Region);
72 #endif
73 static void XawSimpleRealize(Widget, Mask*, XSetWindowAttributes*);
74 static Boolean XawSimpleSetValues(Widget, Widget, Widget, ArgList, Cardinal*);
75
76 /*
77 * Prototypes
78 */
79 static void ConvertCursor(Widget);
80
81 /*
82 * Initialization
83 */
84 #ifndef OLDXAW
85 static XtActionsRec actions[] = {
86 {"set-values", XawSetValuesAction},
87 {"get-values", XawGetValuesAction},
88 {"declare", XawDeclareAction},
89 {"call-proc", XawCallProcAction},
90 };
91 #endif
92
93 #define offset(field) XtOffsetOf(SimpleRec, simple.field)
94 static XtResource resources[] = {
95 {
96 XtNcursor,
97 XtCCursor,
98 XtRCursor,
99 sizeof(Cursor),
100 offset(cursor),
101 XtRImmediate,
102 (XtPointer)None
103 },
104 {
105 XtNinsensitiveBorder,
106 XtCInsensitive,
107 XtRPixmap,
108 sizeof(Pixmap),
109 offset(insensitive_border),
110 XtRImmediate,
111 NULL
112 },
113 {
114 XtNpointerColor,
115 XtCForeground,
116 XtRPixel,
117 sizeof(Pixel),
118 offset(pointer_fg),
119 XtRString,
120 (XtPointer)XtDefaultForeground
121 },
122 {
123 XtNpointerColorBackground,
124 XtCBackground,
125 XtRPixel,
126 sizeof(Pixel),
127 offset(pointer_bg),
128 XtRString,
129 (XtPointer)XtDefaultBackground
130 },
131 {
132 XtNcursorName,
133 XtCCursor,
134 XtRString,
135 sizeof(String),
136 offset(cursor_name),
137 XtRString,
138 NULL
139 },
140 {
141 XtNinternational,
142 XtCInternational,
143 XtRBoolean,
144 sizeof(Boolean),
145 offset(international),
146 XtRImmediate,
147 (XtPointer)False
148 },
149 #ifndef OLDXAW
150 {
151 XawNdisplayList,
152 XawCDisplayList,
153 XawRDisplayList,
154 sizeof(XawDisplayList*),
155 offset(display_list),
156 XtRImmediate,
157 NULL
158 },
159 {
160 XtNtip,
161 XtCTip,
162 XtRString,
163 sizeof(String),
164 offset(tip),
165 XtRImmediate,
166 NULL
167 },
168 #endif
169 #undef offset
170 };
171
172 SimpleClassRec simpleClassRec = {
173 /* core */
174 {
175 (WidgetClass)&widgetClassRec, /* superclass */
176 "Simple", /* class_name */
177 sizeof(SimpleRec), /* widget_size */
178 XawSimpleClassInitialize, /* class_initialize */
179 XawSimpleClassPartInitialize, /* class_part_initialize */
180 False, /* class_inited */
181 #ifndef OLDXAW
182 XawSimpleInitialize, /* initialize */
183 #else
184 NULL, /* initialize */
185 #endif
186 NULL, /* initialize_hook */
187 XawSimpleRealize, /* realize */
188 #ifndef OLDXAW
189 actions, /* actions */
190 XtNumber(actions), /* num_actions */
191 #else
192 NULL, /* actions */
193 0, /* num_actions */
194 #endif
195 resources, /* resources */
196 XtNumber(resources), /* num_resources */
197 NULLQUARK, /* xrm_class */
198 True, /* compress_motion */
199 True, /* compress_exposure */
200 True, /* compress_enterleave */
201 False, /* visible_interest */
202 #ifndef OLDXAW
203 XawSimpleDestroy, /* destroy */
204 #else
205 NULL, /* destroy */
206 #endif
207 NULL, /* resize */
208 #ifndef OLDXAW
209 XawSimpleExpose, /* expose */
210 #else
211 NULL, /* expose */
212 #endif
213 XawSimpleSetValues, /* set_values */
214 NULL, /* set_values_hook */
215 XtInheritSetValuesAlmost, /* set_values_almost */
216 NULL, /* get_values_hook */
217 NULL, /* accept_focus */
218 XtVersion, /* version */
219 NULL, /* callback_private */
220 NULL, /* tm_table */
221 XtInheritQueryGeometry, /* query_geometry */
222 XtInheritDisplayAccelerator, /* display_accelerator */
223 NULL, /* extension */
224 },
225 /* simple */
226 {
227 ChangeSensitive, /* change_sensitive */
228 #ifndef OLDXAW
229 NULL,
230 #endif
231 },
232 };
233
234 WidgetClass simpleWidgetClass = (WidgetClass)&simpleClassRec;
235
236 static void
237 XawSimpleClassInitialize(void)
238 {
239 static XtConvertArgRec convertArg[] = {
240 {
241 XtWidgetBaseOffset,
242 (XtPointer)XtOffsetOf(WidgetRec, core.screen),
243 sizeof(Screen *)
244 },
245 {
246 XtResourceString,
247 (XtPointer)XtNpointerColor,
248 sizeof(Pixel)
249 },
250 {
251 XtResourceString,
252 (XtPointer)XtNpointerColorBackground,
253 sizeof(Pixel)
254 },
255 {
256 XtWidgetBaseOffset,
257 (XtPointer)XtOffsetOf(WidgetRec, core.colormap),
258 sizeof(Colormap)
259 },
260 };
261
262 XawInitializeWidgetSet();
263 XtSetTypeConverter(XtRString, XtRColorCursor, XmuCvtStringToColorCursor,
264 convertArg, XtNumber(convertArg), XtCacheByDisplay, NULL);
265 }
266
267 static void
268 XawSimpleClassPartInitialize(WidgetClass cclass)
269 {
270 SimpleWidgetClass c = (SimpleWidgetClass)cclass;
271 SimpleWidgetClass super = (SimpleWidgetClass)c->core_class.superclass;
272
273 if (c->simple_class.change_sensitive == NULL) {
274 char buf[BUFSIZ];
275
276 snprintf(buf, sizeof(buf),
277 "%s Widget: The Simple Widget class method "
278 "'change_sensitive' is undefined.\n"
279 "A function must be defined or inherited.",
280 c->core_class.class_name);
281 XtWarning(buf);
282 c->simple_class.change_sensitive = ChangeSensitive;
283 }
284
285 if (c->simple_class.change_sensitive == XtInheritChangeSensitive)
286 c->simple_class.change_sensitive = super->simple_class.change_sensitive;
287 }
288
289 #ifndef OLDXAW
290 /*ARGSUSED*/
291 static void
292 XawSimpleInitialize(Widget request _X_UNUSED, Widget cnew,
293 ArgList args _X_UNUSED, Cardinal *num_args _X_UNUSED)
294 {
295 SimpleWidget simple = (SimpleWidget)cnew;
296
297 if (simple->simple.tip)
298 simple->simple.tip = XtNewString(simple->simple.tip);
299 }
300
301 static void
302 XawSimpleDestroy(Widget w)
303 {
304 SimpleWidget simple = (SimpleWidget)w;
305
306 if (simple->simple.tip)
307 XtFree((XtPointer)simple->simple.tip);
308 }
309 #endif
310
311 static void
312 XawSimpleRealize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
313 {
314 #ifndef OLDXAW
315 XawPixmap *pixmap;
316 #endif
317 Pixmap border_pixmap = CopyFromParent;
318
319 if (!XtIsSensitive(w))
320 {
321 /* change border to gray; have to remember the old one,
322 * so XtDestroyWidget deletes the proper one */
323 if (((SimpleWidget)w)->simple.insensitive_border == None)
324 ((SimpleWidget)w)->simple.insensitive_border =
325 XmuCreateStippledPixmap(XtScreen(w),
326 w->core.border_pixel,
327 w->core.background_pixel,
328 w->core.depth);
329 border_pixmap = w->core.border_pixmap;
330 attributes->border_pixmap =
331 w->core.border_pixmap = ((SimpleWidget)w)->simple.insensitive_border;
332
333 *valueMask |= CWBorderPixmap;
334 *valueMask &= (Mask)(~CWBorderPixel);
335 }
336
337 ConvertCursor(w);
338
339 if ((attributes->cursor = ((SimpleWidget)w)->simple.cursor) != None)
340 *valueMask |= CWCursor;
341
342 XtCreateWindow(w, InputOutput, (Visual *)CopyFromParent,
343 *valueMask, attributes);
344
345 if (!XtIsSensitive(w))
346 w->core.border_pixmap = border_pixmap;
347
348 #ifndef OLDXAW
349 if (w->core.background_pixmap > XtUnspecifiedPixmap) {
350 pixmap = XawPixmapFromXPixmap(w->core.background_pixmap, XtScreen(w),
351 w->core.colormap, (int)w->core.depth);
352 if (pixmap && pixmap->mask)
353 XawReshapeWidget(w, pixmap);
354 }
355
356 if (((SimpleWidget)w)->simple.tip)
357 XawTipEnable(w);
358 #endif
359 }
360
361 /*
362 * Function:
363 * ConvertCursor
364 *
365 * Parameters:
366 * w - simple widget
367 *
368 * Description:
369 * Converts a name to a new cursor.
370 */
371 static void
372 ConvertCursor(Widget w)
373 {
374 SimpleWidget simple = (SimpleWidget) w;
375 XrmValue from, to;
376 Cursor cursor = None;
377
378 if (simple->simple.cursor_name == NULL)
379 return;
380
381 from.addr = (XPointer)simple->simple.cursor_name;
382 from.size = (unsigned)strlen((char *)from.addr) + 1;
383
384 to.size = sizeof(Cursor);
385 to.addr = (XPointer)&cursor;
386
387 if (XtConvertAndStore(w, XtRString, &from, XtRColorCursor, &to))
388 simple->simple.cursor = cursor;
389 else
390 XtAppErrorMsg(XtWidgetToApplicationContext(w),
391 "convertFailed","ConvertCursor","XawError",
392 "Simple: ConvertCursor failed.",
393 NULL, NULL);
394 }
395
396
397 /*ARGSUSED*/
398 static Boolean
399 XawSimpleSetValues(Widget current, Widget request _X_UNUSED, Widget cnew,
400 ArgList args _X_UNUSED, Cardinal *num_args _X_UNUSED)
401 {
402 SimpleWidget s_old = (SimpleWidget)current;
403 SimpleWidget s_new = (SimpleWidget)cnew;
404 Bool new_cursor = False;
405
406 /* this disables user changes after creation */
407 s_new->simple.international = s_old->simple.international;
408
409 if (XtIsSensitive(current) != XtIsSensitive(cnew))
410 (*((SimpleWidgetClass)XtClass(cnew))->simple_class.change_sensitive)
411 (cnew);
412
413 if (s_old->simple.cursor != s_new->simple.cursor)
414 new_cursor = True;
415
416 /*
417 * We are not handling the string cursor_name correctly here
418 */
419
420 if (s_old->simple.pointer_fg != s_new->simple.pointer_fg ||
421 s_old->simple.pointer_bg != s_new->simple.pointer_bg ||
422 s_old->simple.cursor_name != s_new->simple.cursor_name) {
423 ConvertCursor(cnew);
424 new_cursor = True;
425 }
426
427 if (new_cursor && XtIsRealized(cnew)) {
428 if (s_new->simple.cursor != None)
429 XDefineCursor(XtDisplay(cnew), XtWindow(cnew), s_new->simple.cursor);
430 else
431 XUndefineCursor(XtDisplay(cnew), XtWindow(cnew));
432 }
433
434 #ifndef OLDXAW
435 if (s_old->core.background_pixmap != s_new->core.background_pixmap) {
436 XawPixmap *opix, *npix;
437
438 opix = XawPixmapFromXPixmap(s_old->core.background_pixmap,
439 XtScreen(s_old), s_old->core.colormap,
440 (int)s_old->core.depth);
441 npix = XawPixmapFromXPixmap(s_new->core.background_pixmap,
442 XtScreen(s_new), s_new->core.colormap,
443 (int)s_new->core.depth);
444 if ((npix && npix->mask) || (opix && opix->mask))
445 XawReshapeWidget(cnew, npix);
446 }
447
448 if (s_old->simple.tip != s_new->simple.tip) {
449 if (s_old->simple.tip)
450 XtFree((XtPointer)s_old->simple.tip);
451 if (s_new->simple.tip)
452 s_new->simple.tip = XtNewString(s_new->simple.tip);
453 }
454
455 if (s_old->simple.tip && !s_new->simple.tip)
456 XawTipDisable(cnew);
457 else if (!s_old->simple.tip && s_new->simple.tip)
458 XawTipEnable(cnew);
459
460 if (s_old->simple.display_list != s_new->simple.display_list)
461 return (True);
462 #endif /* OLDXAW */
463
464 return (False);
465 }
466
467 #ifndef OLDXAW
468 static void
469 XawSimpleExpose(Widget w, XEvent *event, Region region)
470 {
471 SimpleWidget xaw = (SimpleWidget)w;
472
473 if (xaw->simple.display_list)
474 XawRunDisplayList(w, xaw->simple.display_list, event, region);
475 }
476 #endif
477
478 static Bool
479 ChangeSensitive(Widget w)
480 {
481 if (XtIsRealized(w)) {
482 if (XtIsSensitive(w))
483 if (w->core.border_pixmap != XtUnspecifiedPixmap)
484 XSetWindowBorderPixmap(XtDisplay(w), XtWindow(w),
485 w->core.border_pixmap);
486 else
487 XSetWindowBorder(XtDisplay(w), XtWindow(w),
488 w->core.border_pixel);
489 else {
490 if (((SimpleWidget)w)->simple.insensitive_border == None)
491 ((SimpleWidget)w)->simple.insensitive_border =
492 XmuCreateStippledPixmap(XtScreen(w),
493 w->core.border_pixel,
494 w->core.background_pixel,
495 w->core.depth);
496 XSetWindowBorderPixmap(XtDisplay(w), XtWindow(w),
497 ((SimpleWidget)w)->simple.insensitive_border);
498 }
499 }
500
501 return (False);
502 }