1 /***********************************************************
3 Copyright 1987, 1988, 1994, 1998 The Open Group
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
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
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.
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.
26 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
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.
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
46 ******************************************************************/
52 #include <X11/IntrinsicP.h>
53 #include <X11/StringDefs.h>
54 #include <X11/Xmu/Drawing.h>
55 #include <X11/Xmu/SysUtil.h>
56 #include <X11/Xaw/SimpleP.h>
57 #include <X11/Xaw/XawInit.h>
60 #include <X11/Xaw/Tip.h>
66 static Bool ChangeSensitive(Widget);
67 static void XawSimpleClassInitialize(void);
68 static void XawSimpleClassPartInitialize(WidgetClass);
70 static void XawSimpleInitialize(Widget, Widget, ArgList, Cardinal*);
71 static void XawSimpleDestroy(Widget);
72 static void XawSimpleExpose(Widget, XEvent*, Region);
74 static void XawSimpleRealize(Widget, Mask*, XSetWindowAttributes*);
75 static Boolean XawSimpleSetValues(Widget, Widget, Widget, ArgList, Cardinal*);
80 static void ConvertCursor(Widget);
86 static XtActionsRec actions[] = {
87 {"set-values", XawSetValuesAction},
88 {"get-values", XawGetValuesAction},
89 {"declare", XawDeclareAction},
90 {"call-proc", XawCallProcAction},
94 #define offset(field) XtOffsetOf(SimpleRec, simple.field)
95 static XtResource resources[] = {
106 XtNinsensitiveBorder,
110 offset(insensitive_border),
124 XtNpointerColorBackground,
146 offset(international),
155 sizeof(XawDisplayList*),
156 offset(display_list),
173 SimpleClassRec simpleClassRec = {
176 (WidgetClass)&widgetClassRec, /* superclass */
177 "Simple", /* class_name */
178 sizeof(SimpleRec), /* widget_size */
179 XawSimpleClassInitialize, /* class_initialize */
180 XawSimpleClassPartInitialize, /* class_part_initialize */
181 False, /* class_inited */
183 XawSimpleInitialize, /* initialize */
185 NULL, /* initialize */
187 NULL, /* initialize_hook */
188 XawSimpleRealize, /* realize */
190 actions, /* actions */
191 XtNumber(actions), /* num_actions */
196 resources, /* resources */
197 XtNumber(resources), /* num_resources */
198 NULLQUARK, /* xrm_class */
199 True, /* compress_motion */
200 True, /* compress_exposure */
201 True, /* compress_enterleave */
202 False, /* visible_interest */
204 XawSimpleDestroy, /* destroy */
210 XawSimpleExpose, /* expose */
214 XawSimpleSetValues, /* set_values */
215 NULL, /* set_values_hook */
216 XtInheritSetValuesAlmost, /* set_values_almost */
217 NULL, /* get_values_hook */
218 NULL, /* accept_focus */
219 XtVersion, /* version */
220 NULL, /* callback_private */
222 XtInheritQueryGeometry, /* query_geometry */
223 XtInheritDisplayAccelerator, /* display_accelerator */
224 NULL, /* extension */
228 ChangeSensitive, /* change_sensitive */
232 WidgetClass simpleWidgetClass = (WidgetClass)&simpleClassRec;
235 XawSimpleClassInitialize(void)
237 static XtConvertArgRec convertArg[] = {
240 (XtPointer)XtOffsetOf(WidgetRec, core.screen),
245 (XtPointer)XtNpointerColor,
250 (XtPointer)XtNpointerColorBackground,
255 (XtPointer)XtOffsetOf(WidgetRec, core.colormap),
260 XawInitializeWidgetSet();
261 XtSetTypeConverter(XtRString, XtRColorCursor, XmuCvtStringToColorCursor,
262 convertArg, XtNumber(convertArg), XtCacheByDisplay, NULL);
266 XawSimpleClassPartInitialize(WidgetClass cclass)
268 SimpleWidgetClass c = (SimpleWidgetClass)cclass;
269 SimpleWidgetClass super = (SimpleWidgetClass)c->core_class.superclass;
271 if (c->simple_class.change_sensitive == NULL) {
274 (void)XmuSnprintf(buf, sizeof(buf),
275 "%s Widget: The Simple Widget class method "
276 "'change_sensitive' is undefined.\nA function "
277 "must be defined or inherited.",
278 c->core_class.class_name);
280 c->simple_class.change_sensitive = ChangeSensitive;
283 if (c->simple_class.change_sensitive == XtInheritChangeSensitive)
284 c->simple_class.change_sensitive = super->simple_class.change_sensitive;
290 XawSimpleInitialize(Widget request, Widget cnew,
291 ArgList args, Cardinal *num_args)
293 SimpleWidget simple = (SimpleWidget)cnew;
295 if (simple->simple.tip)
296 simple->simple.tip = XtNewString(simple->simple.tip);
300 XawSimpleDestroy(Widget w)
302 SimpleWidget simple = (SimpleWidget)w;
304 if (simple->simple.tip)
305 XtFree((XtPointer)simple->simple.tip);
310 XawSimpleRealize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
315 Pixmap border_pixmap = CopyFromParent;
317 if (!XtIsSensitive(w))
319 /* change border to gray; have to remember the old one,
320 * so XtDestroyWidget deletes the proper one */
321 if (((SimpleWidget)w)->simple.insensitive_border == None)
322 ((SimpleWidget)w)->simple.insensitive_border =
323 XmuCreateStippledPixmap(XtScreen(w),
324 w->core.border_pixel,
325 w->core.background_pixel,
327 border_pixmap = w->core.border_pixmap;
328 attributes->border_pixmap =
329 w->core.border_pixmap = ((SimpleWidget)w)->simple.insensitive_border;
331 *valueMask |= CWBorderPixmap;
332 *valueMask &= ~CWBorderPixel;
337 if ((attributes->cursor = ((SimpleWidget)w)->simple.cursor) != None)
338 *valueMask |= CWCursor;
340 XtCreateWindow(w, InputOutput, (Visual *)CopyFromParent,
341 *valueMask, attributes);
343 if (!XtIsSensitive(w))
344 w->core.border_pixmap = border_pixmap;
347 if (w->core.background_pixmap > XtUnspecifiedPixmap) {
348 pixmap = XawPixmapFromXPixmap(w->core.background_pixmap, XtScreen(w),
349 w->core.colormap, w->core.depth);
350 if (pixmap && pixmap->mask)
351 XawReshapeWidget(w, pixmap);
354 if (((SimpleWidget)w)->simple.tip)
367 * Converts a name to a new cursor.
370 ConvertCursor(Widget w)
372 SimpleWidget simple = (SimpleWidget) w;
374 Cursor cursor = None;
376 if (simple->simple.cursor_name == NULL)
379 from.addr = (XPointer)simple->simple.cursor_name;
380 from.size = strlen((char *)from.addr) + 1;
382 to.size = sizeof(Cursor);
383 to.addr = (XPointer)&cursor;
385 if (XtConvertAndStore(w, XtRString, &from, XtRColorCursor, &to))
386 simple->simple.cursor = cursor;
388 XtAppErrorMsg(XtWidgetToApplicationContext(w),
389 "convertFailed","ConvertCursor","XawError",
390 "Simple: ConvertCursor failed.",
397 XawSimpleSetValues(Widget current, Widget request, Widget cnew,
398 ArgList args, Cardinal *num_args)
400 SimpleWidget s_old = (SimpleWidget)current;
401 SimpleWidget s_new = (SimpleWidget)cnew;
402 Bool new_cursor = False;
404 /* this disables user changes after creation */
405 s_new->simple.international = s_old->simple.international;
407 if (XtIsSensitive(current) != XtIsSensitive(cnew))
408 (*((SimpleWidgetClass)XtClass(cnew))->simple_class.change_sensitive)
411 if (s_old->simple.cursor != s_new->simple.cursor)
415 * We are not handling the string cursor_name correctly here
418 if (s_old->simple.pointer_fg != s_new->simple.pointer_fg ||
419 s_old->simple.pointer_bg != s_new->simple.pointer_bg ||
420 s_old->simple.cursor_name != s_new->simple.cursor_name) {
425 if (new_cursor && XtIsRealized(cnew)) {
426 if (s_new->simple.cursor != None)
427 XDefineCursor(XtDisplay(cnew), XtWindow(cnew), s_new->simple.cursor);
429 XUndefineCursor(XtDisplay(cnew), XtWindow(cnew));
433 if (s_old->core.background_pixmap != s_new->core.background_pixmap) {
434 XawPixmap *opix, *npix;
436 opix = XawPixmapFromXPixmap(s_old->core.background_pixmap,
437 XtScreen(s_old), s_old->core.colormap,
439 npix = XawPixmapFromXPixmap(s_new->core.background_pixmap,
440 XtScreen(s_new), s_new->core.colormap,
442 if ((npix && npix->mask) || (opix && opix->mask))
443 XawReshapeWidget(cnew, npix);
446 if (s_old->simple.tip != s_new->simple.tip) {
447 if (s_old->simple.tip)
448 XtFree((XtPointer)s_old->simple.tip);
449 if (s_new->simple.tip)
450 s_new->simple.tip = XtNewString(s_new->simple.tip);
453 if (s_old->simple.tip && !s_new->simple.tip)
455 else if (!s_old->simple.tip && s_new->simple.tip)
458 if (s_old->simple.display_list != s_new->simple.display_list)
467 XawSimpleExpose(Widget w, XEvent *event, Region region)
469 SimpleWidget xaw = (SimpleWidget)w;
471 if (xaw->simple.display_list)
472 XawRunDisplayList(w, xaw->simple.display_list, event, region);
477 ChangeSensitive(Widget w)
479 if (XtIsRealized(w)) {
480 if (XtIsSensitive(w))
481 if (w->core.border_pixmap != XtUnspecifiedPixmap)
482 XSetWindowBorderPixmap(XtDisplay(w), XtWindow(w),
483 w->core.border_pixmap);
485 XSetWindowBorder(XtDisplay(w), XtWindow(w),
486 w->core.border_pixel);
488 if (((SimpleWidget)w)->simple.insensitive_border == None)
489 ((SimpleWidget)w)->simple.insensitive_border =
490 XmuCreateStippledPixmap(XtScreen(w),
491 w->core.border_pixel,
492 w->core.background_pixel,
494 XSetWindowBorderPixmap(XtDisplay(w), XtWindow(w),
495 ((SimpleWidget)w)->simple.insensitive_border);