1 /* $XConsortium: Simple.c,v 1.36 94/04/17 20:12:43 kaleb Exp $ */
3 /***********************************************************
5 Copyright (c) 1987, 1988, 1994 X Consortium
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 Except as contained in this notice, the name of the X Consortium shall not be
25 used in advertising or otherwise to promote the sale, use or other dealings
26 in this Software without prior written authorization from the X Consortium.
29 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
33 Permission to use, copy, modify, and distribute this software and its
34 documentation for any purpose and without fee is hereby granted,
35 provided that the above copyright notice appear in all copies and that
36 both that copyright notice and this permission notice appear in
37 supporting documentation, and that the name of Digital not be
38 used in advertising or publicity pertaining to distribution of the
39 software without specific, written prior permission.
41 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
42 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
43 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
44 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
45 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
46 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
49 ******************************************************************/
52 #include <X11/IntrinsicP.h>
53 #include <X11/StringDefs.h>
54 #include <X11/Xaw/XawInit.h>
55 #include <X11/Xaw/SimpleP.h>
56 #include <X11/Xmu/Drawing.h>
58 #define offset(field) XtOffsetOf(SimpleRec, simple.field)
60 static XtResource resources
[] = {
61 {XtNcursor
, XtCCursor
, XtRCursor
, sizeof(Cursor
),
62 offset(cursor
), XtRImmediate
, (XtPointer
) None
},
63 {XtNinsensitiveBorder
, XtCInsensitive
, XtRPixmap
, sizeof(Pixmap
),
64 offset(insensitive_border
), XtRImmediate
, (XtPointer
) NULL
},
65 {XtNpointerColor
, XtCForeground
, XtRPixel
, sizeof(Pixel
),
66 offset(pointer_fg
), XtRString
, XtDefaultForeground
},
67 {XtNpointerColorBackground
, XtCBackground
, XtRPixel
, sizeof(Pixel
),
68 offset(pointer_bg
), XtRString
, XtDefaultBackground
},
69 {XtNcursorName
, XtCCursor
, XtRString
, sizeof(String
),
70 offset(cursor_name
), XtRString
, NULL
},
71 {XtNinternational
, XtCInternational
, XtRBoolean
, sizeof(Boolean
),
72 offset(international
), XtRImmediate
, (XtPointer
) FALSE
},
76 static void ClassPartInitialize(), ClassInitialize(),Realize(),ConvertCursor();
77 static Boolean
SetValues(), ChangeSensitive();
79 SimpleClassRec simpleClassRec
= {
81 /* superclass */ (WidgetClass
) &widgetClassRec
,
82 /* class_name */ "Simple",
83 /* widget_size */ sizeof(SimpleRec
),
84 /* class_initialize */ ClassInitialize
,
85 /* class_part_initialize */ ClassPartInitialize
,
86 /* class_inited */ FALSE
,
87 /* initialize */ NULL
,
88 /* initialize_hook */ NULL
,
89 /* realize */ Realize
,
92 /* resources */ resources
,
93 /* num_resources */ XtNumber(resources
),
94 /* xrm_class */ NULLQUARK
,
95 /* compress_motion */ TRUE
,
96 /* compress_exposure */ TRUE
,
97 /* compress_enterleave */ TRUE
,
98 /* visible_interest */ FALSE
,
102 /* set_values */ SetValues
,
103 /* set_values_hook */ NULL
,
104 /* set_values_almost */ XtInheritSetValuesAlmost
,
105 /* get_values_hook */ NULL
,
106 /* accept_focus */ NULL
,
107 /* version */ XtVersion
,
108 /* callback_private */ NULL
,
110 /* query_geometry */ XtInheritQueryGeometry
,
111 /* display_accelerator */ XtInheritDisplayAccelerator
,
114 { /* simple fields */
115 /* change_sensitive */ ChangeSensitive
119 WidgetClass simpleWidgetClass
= (WidgetClass
)&simpleClassRec
;
121 static void ClassInitialize()
123 static XtConvertArgRec convertArg
[] = {
124 {XtWidgetBaseOffset
, (XtPointer
) XtOffsetOf(WidgetRec
, core
.screen
),
126 {XtResourceString
, (XtPointer
) XtNpointerColor
, sizeof(Pixel
)},
127 {XtResourceString
, (XtPointer
) XtNpointerColorBackground
,
129 {XtWidgetBaseOffset
, (XtPointer
) XtOffsetOf(WidgetRec
, core
.colormap
),
133 XawInitializeWidgetSet();
134 XtSetTypeConverter( XtRString
, XtRColorCursor
, XmuCvtStringToColorCursor
,
135 convertArg
, XtNumber(convertArg
),
136 XtCacheByDisplay
, (XtDestructor
)NULL
);
139 static void ClassPartInitialize(class)
142 SimpleWidgetClass c
= (SimpleWidgetClass
) class;
143 SimpleWidgetClass super
= (SimpleWidgetClass
) c
->core_class
.superclass
;
145 if (c
->simple_class
.change_sensitive
== NULL
) {
149 char* fmt
= "%s Widget: The Simple Widget class method 'change_sensitive' is undefined.\nA function must be defined or inherited.";
151 if ((len
= strlen (fmt
) + strlen (c
->core_class
.class_name
)) < sizeof buf
)
154 bufp
= XtMalloc (len
+ 1);
157 strcpy (bufp
, "The Simple Widget class method 'change_sensitive' is undefined.\nA function must be defined or inherited.");
159 (void) sprintf(bufp
, fmt
, c
->core_class
.class_name
);
161 if (bufp
!= buf
) XtFree (bufp
);
162 c
->simple_class
.change_sensitive
= ChangeSensitive
;
165 if (c
->simple_class
.change_sensitive
== XtInheritChangeSensitive
)
166 c
->simple_class
.change_sensitive
= super
->simple_class
.change_sensitive
;
169 static void Realize(w
, valueMask
, attributes
)
172 XSetWindowAttributes
*attributes
;
174 Pixmap border_pixmap
;
175 if (!XtIsSensitive(w
)) {
176 /* change border to gray; have to remember the old one,
177 * so XtDestroyWidget deletes the proper one */
178 if (((SimpleWidget
)w
)->simple
.insensitive_border
== None
)
179 ((SimpleWidget
)w
)->simple
.insensitive_border
=
180 XmuCreateStippledPixmap(XtScreen(w
),
181 w
->core
.border_pixel
,
182 w
->core
.background_pixel
,
184 border_pixmap
= w
->core
.border_pixmap
;
185 attributes
->border_pixmap
=
186 w
->core
.border_pixmap
= ((SimpleWidget
)w
)->simple
.insensitive_border
;
188 *valueMask
|= CWBorderPixmap
;
189 *valueMask
&= ~CWBorderPixel
;
194 if ((attributes
->cursor
= ((SimpleWidget
)w
)->simple
.cursor
) != None
)
195 *valueMask
|= CWCursor
;
197 XtCreateWindow( w
, (unsigned int)InputOutput
, (Visual
*)CopyFromParent
,
198 *valueMask
, attributes
);
200 if (!XtIsSensitive(w
))
201 w
->core
.border_pixmap
= border_pixmap
;
204 /* Function Name: ConvertCursor
205 * Description: Converts a name to a new cursor.
206 * Arguments: w - the simple widget.
214 SimpleWidget simple
= (SimpleWidget
) w
;
218 if (simple
->simple
.cursor_name
== NULL
)
221 from
.addr
= (XPointer
) simple
->simple
.cursor_name
;
222 from
.size
= strlen((char *) from
.addr
) + 1;
224 to
.size
= sizeof(Cursor
);
225 to
.addr
= (XPointer
) &cursor
;
227 if (XtConvertAndStore(w
, XtRString
, &from
, XtRColorCursor
, &to
)) {
229 simple
->simple
.cursor
= cursor
;
232 XtAppErrorMsg(XtWidgetToApplicationContext(w
),
233 "convertFailed","ConvertCursor","XawError",
234 "Simple: ConvertCursor failed.",
235 (String
*)NULL
, (Cardinal
*)NULL
);
241 static Boolean
SetValues(current
, request
, new, args
, num_args
)
242 Widget current
, request
, new;
246 SimpleWidget s_old
= (SimpleWidget
) current
;
247 SimpleWidget s_new
= (SimpleWidget
) new;
248 Boolean new_cursor
= FALSE
;
250 /* this disables user changes after creation*/
251 s_new
->simple
.international
= s_old
->simple
.international
;
253 if ( XtIsSensitive(current
) != XtIsSensitive(new) )
254 (*((SimpleWidgetClass
)XtClass(new))->
255 simple_class
.change_sensitive
) ( new );
257 if (s_old
->simple
.cursor
!= s_new
->simple
.cursor
) {
262 * We are not handling the string cursor_name correctly here.
265 if ( (s_old
->simple
.pointer_fg
!= s_new
->simple
.pointer_fg
) ||
266 (s_old
->simple
.pointer_bg
!= s_new
->simple
.pointer_bg
) ||
267 (s_old
->simple
.cursor_name
!= s_new
->simple
.cursor_name
) ) {
272 if (new_cursor
&& XtIsRealized(new))
273 XDefineCursor(XtDisplay(new), XtWindow(new), s_new
->simple
.cursor
);
279 static Boolean
ChangeSensitive(w
)
282 if (XtIsRealized(w
)) {
283 if (XtIsSensitive(w
))
284 if (w
->core
.border_pixmap
!= XtUnspecifiedPixmap
)
285 XSetWindowBorderPixmap( XtDisplay(w
), XtWindow(w
),
286 w
->core
.border_pixmap
);
288 XSetWindowBorder( XtDisplay(w
), XtWindow(w
),
289 w
->core
.border_pixel
);
291 if (((SimpleWidget
)w
)->simple
.insensitive_border
== None
)
292 ((SimpleWidget
)w
)->simple
.insensitive_border
=
293 XmuCreateStippledPixmap(XtScreen(w
),
294 w
->core
.border_pixel
,
295 w
->core
.background_pixel
,
297 XSetWindowBorderPixmap( XtDisplay(w
), XtWindow(w
),
299 simple
.insensitive_border
);