2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * $Id: Simple.c,v 1.1 1992/03/20 13:52:41 jbm Exp $
26 * Copyright (c) 1991 HaL Computer Systems, Inc. All rights reserved.
27 * UNPUBLISHED -- rights reserved under the Copyright Laws of the United
28 * States. Use of a copyright notice is precautionary only and does not
29 * imply publication or disclosure.
31 * This software contains confidential information and trade secrets of HaL
32 * Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
33 * without the prior express written permission of HaL Computer Systems, Inc.
35 * RESTRICTED RIGHTS LEGEND
36 * Use, duplication, or disclosure by the Government is subject to
37 * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
38 * Technical Data and Computer Software clause at DFARS 252.227-7013.
39 * HaL Computer Systems, Inc.
40 * 1315 Dell Avenue, Campbell, CA 95008
44 /* $XConsortium: Simple.c,v 1.33 91/07/21 13:55:23 converse Exp $ */
46 /***********************************************************
47 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
48 and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
52 Permission to use, copy, modify, and distribute this software and its
53 documentation for any purpose and without fee is hereby granted,
54 provided that the above copyright notice appear in all copies and that
55 both that copyright notice and this permission notice appear in
56 supporting documentation, and that the names of Digital or MIT not be
57 used in advertising or publicity pertaining to distribution of the
58 software without specific, written prior permission.
60 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
61 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
62 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
63 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
64 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
65 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
68 ******************************************************************/
71 #include <X11/IntrinsicP.h>
72 #include <X11/StringDefs.h>
73 #include <X11/Xaw/XawInit.h>
74 #include <X11/Xaw/SimpleP.h>
75 #include <X11/Xmu/Drawing.h>
77 #define offset(field) XtOffsetOf(SimpleRec, simple.field)
79 static XtResource resources[] = {
80 {XtNcursor, XtCCursor, XtRCursor, sizeof(Cursor),
81 offset(cursor), XtRImmediate, (XtPointer) None},
82 {XtNinsensitiveBorder, XtCInsensitive, XtRPixmap, sizeof(Pixmap),
83 offset(insensitive_border), XtRImmediate, (XtPointer) NULL},
84 {XtNpointerColor, XtCForeground, XtRPixel, sizeof(Pixel),
85 offset(pointer_fg), XtRString, XtDefaultForeground},
86 {XtNpointerColorBackground, XtCBackground, XtRPixel, sizeof(Pixel),
87 offset(pointer_bg), XtRString, XtDefaultBackground},
88 {XtNcursorName, XtCCursor, XtRString, sizeof(String),
89 offset(cursor_name), XtRString, NULL},
93 static void ClassPartInitialize(), ClassInitialize(),Realize(),ConvertCursor();
94 static Boolean SetValues(), ChangeSensitive();
96 SimpleClassRec simpleClassRec = {
98 /* superclass */ (WidgetClass) &widgetClassRec,
99 /* class_name */ "Simple",
100 /* widget_size */ sizeof(SimpleRec),
101 /* class_initialize */ ClassInitialize,
102 /* class_part_initialize */ ClassPartInitialize,
103 /* class_inited */ FALSE,
104 /* initialize */ NULL,
105 /* initialize_hook */ NULL,
106 /* realize */ Realize,
109 /* resources */ resources,
110 /* num_resources */ XtNumber(resources),
111 /* xrm_class */ NULLQUARK,
112 /* compress_motion */ TRUE,
113 /* compress_exposure */ TRUE,
114 /* compress_enterleave */ TRUE,
115 /* visible_interest */ FALSE,
119 /* set_values */ SetValues,
120 /* set_values_hook */ NULL,
121 /* set_values_almost */ XtInheritSetValuesAlmost,
122 /* get_values_hook */ NULL,
123 /* accept_focus */ NULL,
124 /* version */ XtVersion,
125 /* callback_private */ NULL,
127 /* query_geometry */ XtInheritQueryGeometry,
128 /* display_accelerator */ XtInheritDisplayAccelerator,
131 { /* simple fields */
132 /* change_sensitive */ (Bool (*)(Widget))ChangeSensitive
136 WidgetClass simpleWidgetClass = (WidgetClass)&simpleClassRec;
138 static void ClassInitialize()
140 static XtConvertArgRec convertArg[] = {
141 {XtWidgetBaseOffset, (XtPointer) XtOffsetOf(WidgetRec, core.screen),
143 {XtResourceString, (XtPointer) XtNpointerColor, sizeof(Pixel)},
144 {XtResourceString, (XtPointer) XtNpointerColorBackground,
146 {XtWidgetBaseOffset, (XtPointer) XtOffsetOf(WidgetRec, core.colormap),
150 XawInitializeWidgetSet();
151 XtSetTypeConverter( XtRString, XtRColorCursor, XmuCvtStringToColorCursor,
152 convertArg, XtNumber(convertArg),
153 XtCacheByDisplay, NULL);
156 static void ClassPartInitialize(class)
159 register SimpleWidgetClass c = (SimpleWidgetClass)class;
160 register SimpleWidgetClass super = (SimpleWidgetClass)
161 c->core_class.superclass;
163 if (c->simple_class.change_sensitive == NULL) {
167 "%s Widget: The Simple Widget class method 'change_sensitive' is undefined.\nA function must be defined or inherited.",
168 c->core_class.class_name);
170 c->simple_class.change_sensitive = (Bool (*)(Widget))ChangeSensitive;
173 if (c->simple_class.change_sensitive == XtInheritChangeSensitive)
174 c->simple_class.change_sensitive = super->simple_class.change_sensitive;
177 static void Realize(w, valueMask, attributes)
180 XSetWindowAttributes *attributes;
182 Pixmap border_pixmap;
184 if (!XtIsSensitive(w)) {
185 /* change border to gray; have to remember the old one,
186 * so XtDestroyWidget deletes the proper one */
187 if (((SimpleWidget)w)->simple.insensitive_border == None)
188 ((SimpleWidget)w)->simple.insensitive_border =
189 XmuCreateStippledPixmap(XtScreen(w),
190 w->core.border_pixel,
191 w->core.background_pixel,
193 border_pixmap = w->core.border_pixmap;
194 attributes->border_pixmap =
195 w->core.border_pixmap = ((SimpleWidget)w)->simple.insensitive_border;
197 *valueMask |= CWBorderPixmap;
198 *valueMask &= ~CWBorderPixel;
203 if ((attributes->cursor = ((SimpleWidget)w)->simple.cursor) != None)
204 *valueMask |= CWCursor;
206 XtCreateWindow( w, (unsigned int)InputOutput, (Visual *)CopyFromParent,
207 *valueMask, attributes );
209 if (!XtIsSensitive(w))
210 w->core.border_pixmap = border_pixmap;
213 /* Function Name: ConvertCursor
214 * Description: Converts a name to a new cursor.
215 * Arguments: w - the simple widget.
223 SimpleWidget simple = (SimpleWidget) w;
227 if (simple->simple.cursor_name == NULL)
230 from.addr = (XPointer) simple->simple.cursor_name;
231 from.size = strlen((char *) from.addr) + 1;
233 to.size = sizeof(Cursor);
234 to.addr = (XPointer) &cursor;
236 if (XtConvertAndStore(w, XtRString, &from, XtRColorCursor, &to)) {
238 simple->simple.cursor = cursor;
241 XtAppErrorMsg(XtWidgetToApplicationContext(w),
242 "convertFailed","ConvertCursor","XawError",
243 "Simple: ConvertCursor failed.",
244 (String *)NULL, (Cardinal *)NULL);
250 static Boolean SetValues(current, request, new)
251 Widget current, request, new;
253 SimpleWidget s_old = (SimpleWidget) current;
254 SimpleWidget s_new = (SimpleWidget) new;
255 Boolean new_cursor = FALSE;
257 if ( XtIsSensitive(current) != XtIsSensitive(new) )
258 (*((SimpleWidgetClass)XtClass(new))->
259 simple_class.change_sensitive) ( new );
261 if (s_old->simple.cursor != s_new->simple.cursor) {
266 * We are not handling the string cursor_name correctly here.
269 if ( (s_old->simple.pointer_fg != s_new->simple.pointer_fg) ||
270 (s_old->simple.pointer_bg != s_new->simple.pointer_bg) ||
271 (s_old->simple.cursor_name != s_new->simple.cursor_name) ) {
276 if (new_cursor && XtIsRealized(new))
277 XDefineCursor(XtDisplay(new), XtWindow(new), s_new->simple.cursor);
283 static Boolean ChangeSensitive(w)
286 if (XtIsRealized(w)) {
287 if (XtIsSensitive(w))
288 if (w->core.border_pixmap != XtUnspecifiedPixmap)
289 XSetWindowBorderPixmap( XtDisplay(w), XtWindow(w),
290 w->core.border_pixmap );
292 XSetWindowBorder( XtDisplay(w), XtWindow(w),
293 w->core.border_pixel );
295 if (((SimpleWidget)w)->simple.insensitive_border == None)
296 ((SimpleWidget)w)->simple.insensitive_border =
297 XmuCreateStippledPixmap(XtScreen(w),
298 w->core.border_pixel,
299 w->core.background_pixel,
301 XSetWindowBorderPixmap( XtDisplay(w), XtWindow(w),
303 simple.insensitive_border );