00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #include <stdio.h>
00052 #include <X11/IntrinsicP.h>
00053 #include <X11/StringDefs.h>
00054 #include <X11/Xaw3d/XawInit.h>
00055 #include <X11/Xaw3d/SimpleP.h>
00056 #include <X11/Xmu/Drawing.h>
00057
00058 #define offset(field) XtOffsetOf(SimpleRec, simple.field)
00059
00060 static XtResource resources[] = {
00061 {XtNcursor, XtCCursor, XtRCursor, sizeof(Cursor),
00062 offset(cursor), XtRImmediate, (XtPointer) None},
00063 {XtNinsensitiveBorder, XtCInsensitive, XtRPixmap, sizeof(Pixmap),
00064 offset(insensitive_border), XtRImmediate, (XtPointer) NULL},
00065 {XtNpointerColor, XtCForeground, XtRPixel, sizeof(Pixel),
00066 offset(pointer_fg), XtRString, XtDefaultForeground},
00067 {XtNpointerColorBackground, XtCBackground, XtRPixel, sizeof(Pixel),
00068 offset(pointer_bg), XtRString, XtDefaultBackground},
00069 {XtNcursorName, XtCCursor, XtRString, sizeof(String),
00070 offset(cursor_name), XtRString, NULL},
00071 {XtNinternational, XtCInternational, XtRBoolean, sizeof(Boolean),
00072 offset(international), XtRImmediate, (XtPointer) FALSE},
00073 #undef offset
00074 };
00075
00076 static void ClassPartInitialize(), ClassInitialize(),Realize(),ConvertCursor();
00077 static Boolean SetValues(), ChangeSensitive();
00078
00079 SimpleClassRec simpleClassRec = {
00080 {
00081 (WidgetClass) &widgetClassRec,
00082 "Simple",
00083 sizeof(SimpleRec),
00084 ClassInitialize,
00085 ClassPartInitialize,
00086 FALSE,
00087 NULL,
00088 NULL,
00089 Realize,
00090 NULL,
00091 0,
00092 resources,
00093 XtNumber(resources),
00094 NULLQUARK,
00095 TRUE,
00096 TRUE,
00097 TRUE,
00098 FALSE,
00099 NULL,
00100 NULL,
00101 NULL,
00102 SetValues,
00103 NULL,
00104 XtInheritSetValuesAlmost,
00105 NULL,
00106 NULL,
00107 XtVersion,
00108 NULL,
00109 NULL,
00110 XtInheritQueryGeometry,
00111 XtInheritDisplayAccelerator,
00112 NULL
00113 },
00114 {
00115 ChangeSensitive
00116 }
00117 };
00118
00119 WidgetClass simpleWidgetClass = (WidgetClass)&simpleClassRec;
00120
00121 static void ClassInitialize()
00122 {
00123 static XtConvertArgRec convertArg[] = {
00124 {XtWidgetBaseOffset, (XtPointer) XtOffsetOf(WidgetRec, core.screen),
00125 sizeof(Screen *)},
00126 {XtResourceString, (XtPointer) XtNpointerColor, sizeof(Pixel)},
00127 {XtResourceString, (XtPointer) XtNpointerColorBackground,
00128 sizeof(Pixel)},
00129 {XtWidgetBaseOffset, (XtPointer) XtOffsetOf(WidgetRec, core.colormap),
00130 sizeof(Colormap)}
00131 };
00132
00133 XawInitializeWidgetSet();
00134 XtSetTypeConverter( XtRString, XtRColorCursor, XmuCvtStringToColorCursor,
00135 convertArg, XtNumber(convertArg),
00136 XtCacheByDisplay, (XtDestructor)NULL);
00137 }
00138
00139 static void ClassPartInitialize(class)
00140 WidgetClass class;
00141 {
00142 SimpleWidgetClass c = (SimpleWidgetClass) class;
00143 SimpleWidgetClass super = (SimpleWidgetClass)
00144 c->core_class.superclass;
00145
00146 if (c->simple_class.change_sensitive == NULL) {
00147 char buf[BUFSIZ];
00148
00149 (void) sprintf(buf,
00150 "%s Widget: The Simple Widget class method 'change_sensitive' is undefined.\nA function must be defined or inherited.",
00151 c->core_class.class_name);
00152 XtWarning(buf);
00153 c->simple_class.change_sensitive = ChangeSensitive;
00154 }
00155
00156 if (c->simple_class.change_sensitive == XtInheritChangeSensitive)
00157 c->simple_class.change_sensitive = super->simple_class.change_sensitive;
00158 }
00159
00160 static void Realize(w, valueMask, attributes)
00161 Widget w;
00162 Mask *valueMask;
00163 XSetWindowAttributes *attributes;
00164 {
00165 Pixmap border_pixmap = 0;
00166 if (!XtIsSensitive(w)) {
00167
00168
00169 if (((SimpleWidget)w)->simple.insensitive_border == None)
00170 ((SimpleWidget)w)->simple.insensitive_border =
00171 XmuCreateStippledPixmap(XtScreen(w),
00172 w->core.border_pixel,
00173 w->core.background_pixel,
00174 w->core.depth);
00175 border_pixmap = w->core.border_pixmap;
00176 attributes->border_pixmap =
00177 w->core.border_pixmap = ((SimpleWidget)w)->simple.insensitive_border;
00178
00179 *valueMask |= CWBorderPixmap;
00180 *valueMask &= ~CWBorderPixel;
00181 }
00182
00183 ConvertCursor(w);
00184
00185 if ((attributes->cursor = ((SimpleWidget)w)->simple.cursor) != None)
00186 *valueMask |= CWCursor;
00187
00188 XtCreateWindow( w, (unsigned int)InputOutput, (Visual *)CopyFromParent,
00189 *valueMask, attributes );
00190
00191 if (!XtIsSensitive(w))
00192 w->core.border_pixmap = border_pixmap;
00193 }
00194
00195
00196
00197
00198
00199
00200
00201 static void
00202 ConvertCursor(w)
00203 Widget w;
00204 {
00205 SimpleWidget simple = (SimpleWidget) w;
00206 XrmValue from, to;
00207 Cursor cursor;
00208
00209 if (simple->simple.cursor_name == NULL)
00210 return;
00211
00212 from.addr = (XPointer) simple->simple.cursor_name;
00213 from.size = strlen((char *) from.addr) + 1;
00214
00215 to.size = sizeof(Cursor);
00216 to.addr = (XPointer) &cursor;
00217
00218 if (XtConvertAndStore(w, XtRString, &from, XtRColorCursor, &to)) {
00219 if ( cursor != None)
00220 simple->simple.cursor = cursor;
00221 }
00222 else {
00223 XtAppErrorMsg(XtWidgetToApplicationContext(w),
00224 "convertFailed","ConvertCursor","XawError",
00225 "Simple: ConvertCursor failed.",
00226 (String *)NULL, (Cardinal *)NULL);
00227 }
00228 }
00229
00230
00231
00232 static Boolean SetValues(current, request, new, args, num_args)
00233 Widget current, request, new;
00234 ArgList args;
00235 Cardinal *num_args;
00236 {
00237 SimpleWidget s_old = (SimpleWidget) current;
00238 SimpleWidget s_new = (SimpleWidget) new;
00239 Boolean new_cursor = FALSE;
00240
00241
00242 s_new->simple.international = s_old->simple.international;
00243
00244 if ( XtIsSensitive(current) != XtIsSensitive(new) )
00245 (*((SimpleWidgetClass)XtClass(new))->
00246 simple_class.change_sensitive) ( new );
00247
00248 if (s_old->simple.cursor != s_new->simple.cursor) {
00249 new_cursor = TRUE;
00250 }
00251
00252
00253
00254
00255
00256 if ( (s_old->simple.pointer_fg != s_new->simple.pointer_fg) ||
00257 (s_old->simple.pointer_bg != s_new->simple.pointer_bg) ||
00258 (s_old->simple.cursor_name != s_new->simple.cursor_name) ) {
00259 ConvertCursor(new);
00260 new_cursor = TRUE;
00261 }
00262
00263 if (new_cursor && XtIsRealized(new))
00264 XDefineCursor(XtDisplay(new), XtWindow(new), s_new->simple.cursor);
00265
00266 return False;
00267 }
00268
00269
00270 static Boolean ChangeSensitive(w)
00271 Widget w;
00272 {
00273 if (XtIsRealized(w)) {
00274 if (XtIsSensitive(w))
00275 if (w->core.border_pixmap != XtUnspecifiedPixmap)
00276 XSetWindowBorderPixmap( XtDisplay(w), XtWindow(w),
00277 w->core.border_pixmap );
00278 else
00279 XSetWindowBorder( XtDisplay(w), XtWindow(w),
00280 w->core.border_pixel );
00281 else {
00282 if (((SimpleWidget)w)->simple.insensitive_border == None)
00283 ((SimpleWidget)w)->simple.insensitive_border =
00284 XmuCreateStippledPixmap(XtScreen(w),
00285 w->core.border_pixel,
00286 w->core.background_pixel,
00287 w->core.depth);
00288 XSetWindowBorderPixmap( XtDisplay(w), XtWindow(w),
00289 ((SimpleWidget)w)->
00290 simple.insensitive_border );
00291 }
00292 }
00293 return False;
00294 }