1/*********************************************************** 2Copyright (c) 1993, Oracle and/or its affiliates. 3 4Permission is hereby granted, free of charge, to any person obtaining a 5copy of this software and associated documentation files (the "Software"), 6to deal in the Software without restriction, including without limitation 7the rights to use, copy, modify, merge, publish, distribute, sublicense, 8and/or sell copies of the Software, and to permit persons to whom the 9Software is furnished to do so, subject to the following conditions: 10 11The above copyright notice and this permission notice (including the next 12paragraph) shall be included in all copies or substantial portions of the 13Software. 14 15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21DEALINGS IN THE SOFTWARE. 22 23Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts. 24 25 All Rights Reserved 26 27Permission to use, copy, modify, and distribute this software and its 28documentation for any purpose and without fee is hereby granted, 29provided that the above copyright notice appear in all copies and that 30both that copyright notice and this permission notice appear in 31supporting documentation, and that the name of Digital not be 32used in advertising or publicity pertaining to distribution of the 33software without specific, written prior permission. 34 35DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 36ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 37DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 38ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 39WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 40ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 41SOFTWARE. 42 43******************************************************************/ 44 45/* 46 47Copyright 1987, 1988, 1998 The Open Group 48 49Permission to use, copy, modify, distribute, and sell this software and its 50documentation for any purpose is hereby granted without fee, provided that 51the above copyright notice appear in all copies and that both that 52copyright notice and this permission notice appear in supporting 53documentation. 54 55The above copyright notice and this permission notice shall be included in 56all copies or substantial portions of the Software. 57 58THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 59IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 60FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 61OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 62AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 63CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 64 65Except as contained in this notice, the name of The Open Group shall not be 66used in advertising or otherwise to promote the sale, use or other dealings 67in this Software without prior written authorization from The Open Group. 68 69*/ 70 71#ifdef HAVE_CONFIG_H 72#include <config.h> 73#endif 74#include "IntrinsicP.h" 75#include "EventI.h" 76#include "ConvertI.h" 77#include "TranslateI.h" 78#include "ResourceI.h" 79#include "RectObj.h" 80#include "RectObjP.h" 81#include "ThreadsI.h" 82#include "StringDefs.h" 83 84/****************************************************************** 85 * 86 * CoreWidget Resources 87 * 88 ******************************************************************/ 89 90externaldef(xtinherittranslations) 91int _XtInheritTranslations = 0; 92extern String XtCXtToolkitError; /* from IntrinsicI.h */ 93static void 94XtCopyScreen(Widget, int, XrmValue *); 95 96static XtResource resources[] = { 97 {XtNscreen, XtCScreen, XtRScreen, sizeof(Screen *), 98 XtOffsetOf(CoreRec, core.screen), XtRCallProc, (XtPointer) XtCopyScreen}, 99/*_XtCopyFromParent does not work for screen because the Display 100parameter is not passed through to the XtRCallProc routines */ 101 {XtNdepth, XtCDepth, XtRInt, sizeof(int), 102 XtOffsetOf(CoreRec, core.depth), 103 XtRCallProc, (XtPointer) _XtCopyFromParent}, 104 {XtNcolormap, XtCColormap, XtRColormap, sizeof(Colormap), 105 XtOffsetOf(CoreRec, core.colormap), 106 XtRCallProc, (XtPointer) _XtCopyFromParent}, 107 {XtNbackground, XtCBackground, XtRPixel, sizeof(Pixel), 108 XtOffsetOf(CoreRec, core.background_pixel), 109 XtRString, (XtPointer) "XtDefaultBackground"}, 110 {XtNbackgroundPixmap, XtCPixmap, XtRPixmap, sizeof(Pixmap), 111 XtOffsetOf(CoreRec, core.background_pixmap), 112 XtRImmediate, (XtPointer) XtUnspecifiedPixmap}, 113 {XtNborderColor, XtCBorderColor, XtRPixel, sizeof(Pixel), 114 XtOffsetOf(CoreRec, core.border_pixel), 115 XtRString, (XtPointer) "XtDefaultForeground"}, 116 {XtNborderPixmap, XtCPixmap, XtRPixmap, sizeof(Pixmap), 117 XtOffsetOf(CoreRec, core.border_pixmap), 118 XtRImmediate, (XtPointer) XtUnspecifiedPixmap}, 119 {XtNmappedWhenManaged, XtCMappedWhenManaged, XtRBoolean, sizeof(Boolean), 120 XtOffsetOf(CoreRec, core.mapped_when_managed), 121 XtRImmediate, (XtPointer) True}, 122 {XtNtranslations, XtCTranslations, XtRTranslationTable, 123 sizeof(XtTranslations), XtOffsetOf(CoreRec, core.tm.translations), 124 XtRTranslationTable, (XtPointer) NULL}, 125 {XtNaccelerators, XtCAccelerators, XtRAcceleratorTable, 126 sizeof(XtTranslations), XtOffsetOf(CoreRec, core.accelerators), 127 XtRTranslationTable, (XtPointer) NULL} 128}; 129 130static void CoreInitialize(Widget, Widget, ArgList, Cardinal *); 131static void CoreClassPartInitialize(WidgetClass); 132static void CoreDestroy(Widget); 133static void CoreRealize(Widget, XtValueMask *, XSetWindowAttributes *); 134static Boolean CoreSetValues(Widget, Widget, Widget, ArgList, Cardinal *); 135static void CoreSetValuesAlmost(Widget, Widget, XtWidgetGeometry *, 136 XtWidgetGeometry *); 137 138static RectObjClassRec unNamedObjClassRec = { 139 { 140 /* superclass */ (WidgetClass) &rectObjClassRec, 141 /* class_name */ "UnNamedObj", 142 /* widget_size */ 0, 143 /* class_initialize */ NULL, 144 /* class_part_initialize */ NULL, 145 /* class_inited */ FALSE, 146 /* initialize */ NULL, 147 /* initialize_hook */ NULL, 148 /* realize */ (XtProc) XtInheritRealize, 149 /* actions */ NULL, 150 /* num_actions */ 0, 151 /* resources */ NULL, 152 /* num_resources */ 0, 153 /* xrm_class */ NULLQUARK, 154 /* compress_motion */ FALSE, 155 /* compress_exposure */ FALSE, 156 /* compress_enterleave */ FALSE, 157 /* visible_interest */ FALSE, 158 /* destroy */ NULL, 159 /* resize */ NULL, 160 /* expose */ NULL, 161 /* set_values */ NULL, 162 /* set_values_hook */ NULL, 163 /* set_values_almost */ XtInheritSetValuesAlmost, 164 /* get_values_hook */ NULL, 165 /* accept_focus */ NULL, 166 /* version */ XtVersion, 167 /* callback_offsets */ NULL, 168 /* tm_table */ NULL, 169 /* query_geometry */ NULL, 170 /* display_accelerator */ NULL, 171 /* extension */ NULL 172 } 173}; 174 175externaldef(widgetclassrec) 176WidgetClassRec widgetClassRec = { 177 { 178 /* superclass */ (WidgetClass) &unNamedObjClassRec, 179 /* class_name */ "Core", 180 /* widget_size */ sizeof(WidgetRec), 181 /* class_initialize */ NULL, 182 /* class_part_initialize */ CoreClassPartInitialize, 183 /* class_inited */ FALSE, 184 /* initialize */ CoreInitialize, 185 /* initialize_hook */ NULL, 186 /* realize */ CoreRealize, 187 /* actions */ NULL, 188 /* num_actions */ 0, 189 /* resources */ resources, 190 /* num_resources */ XtNumber(resources), 191 /* xrm_class */ NULLQUARK, 192 /* compress_motion */ FALSE, 193 /* compress_exposure */ TRUE, 194 /* compress_enterleave */ FALSE, 195 /* visible_interest */ FALSE, 196 /* destroy */ CoreDestroy, 197 /* resize */ NULL, 198 /* expose */ NULL, 199 /* set_values */ CoreSetValues, 200 /* set_values_hook */ NULL, 201 /* set_values_almost */ CoreSetValuesAlmost, 202 /* get_values_hook */ NULL, 203 /* accept_focus */ NULL, 204 /* version */ XtVersion, 205 /* callback_offsets */ NULL, 206 /* tm_table */ NULL, 207 /* query_geometry */ NULL, 208 /* display_accelerator */ NULL, 209 /* extension */ NULL 210 } 211}; 212 213externaldef(WidgetClass) 214WidgetClass widgetClass = &widgetClassRec; 215 216externaldef(WidgetClass) 217WidgetClass coreWidgetClass = &widgetClassRec; 218 219static void 220XtCopyScreen(Widget widget, int offset _X_UNUSED, XrmValue *value) 221{ 222 value->addr = (XPointer) (&widget->core.screen); 223} 224 225/* 226 * Start of Core methods 227 */ 228 229static void 230CoreClassPartInitialize(register WidgetClass wc) 231{ 232 /* We don't need to check for null super since we'll get to object 233 eventually, and it had better define them! */ 234 235 register WidgetClass super = wc->core_class.superclass; 236 237 LOCK_PROCESS; 238 if (wc->core_class.realize == XtInheritRealize) { 239 wc->core_class.realize = super->core_class.realize; 240 } 241 242 if (wc->core_class.accept_focus == XtInheritAcceptFocus) { 243 wc->core_class.accept_focus = super->core_class.accept_focus; 244 } 245 246 if (wc->core_class.display_accelerator == XtInheritDisplayAccelerator) { 247 wc->core_class.display_accelerator = 248 super->core_class.display_accelerator; 249 } 250 251 if (wc->core_class.tm_table == XtInheritTranslations) { 252 wc->core_class.tm_table = 253 wc->core_class.superclass->core_class.tm_table; 254 } 255 else if (wc->core_class.tm_table != NULL) { 256 wc->core_class.tm_table = 257 (String) XtParseTranslationTable(wc->core_class.tm_table); 258 } 259 260 if (wc->core_class.actions != NULL) { 261 Boolean inPlace; 262 263 if (wc->core_class.version == XtVersionDontCheck) 264 inPlace = True; 265 else 266 inPlace = (wc->core_class.version < XtVersion) ? False : True; 267 268 /* Compile the action table into a more efficient form */ 269 wc->core_class.actions = 270 (XtActionList) _XtInitializeActionData(wc->core_class.actions, 271 wc->core_class.num_actions, 272 inPlace); 273 } 274 UNLOCK_PROCESS; 275} 276 277static void 278CoreInitialize(Widget requested_widget _X_UNUSED, 279 register Widget new_widget, 280 ArgList args _X_UNUSED, 281 Cardinal *num_args _X_UNUSED) 282{ 283 XtTranslations save1, save2; 284 285 new_widget->core.event_table = NULL; 286 new_widget->core.tm.proc_table = NULL; 287 new_widget->core.tm.lastEventTime = 0; 288 /* magic semi-resource fetched by GetResources */ 289 save1 = (XtTranslations) new_widget->core.tm.current_state; 290 new_widget->core.tm.current_state = NULL; 291 save2 = new_widget->core.tm.translations; 292 LOCK_PROCESS; 293 new_widget->core.tm.translations = 294 (XtTranslations) new_widget->core.widget_class->core_class.tm_table; 295 UNLOCK_PROCESS; 296 if (save1) 297 _XtMergeTranslations(new_widget, save1, save1->operation); 298 if (save2) 299 _XtMergeTranslations(new_widget, save2, save2->operation); 300} 301 302static void 303CoreRealize(Widget widget, 304 XtValueMask *value_mask, 305 XSetWindowAttributes *attributes) 306{ 307 XtCreateWindow(widget, (unsigned int) InputOutput, 308 (Visual *) CopyFromParent, *value_mask, attributes); 309} /* CoreRealize */ 310 311static void 312CoreDestroy(Widget widget) 313{ 314 _XtFreeEventTable(&widget->core.event_table); 315 _XtDestroyTMData(widget); 316 XtUnregisterDrawable(XtDisplay(widget), widget->core.window); 317 318 if (widget->core.popup_list != NULL) 319 XtFree((char *) widget->core.popup_list); 320 321} /* CoreDestroy */ 322 323static Boolean 324CoreSetValues(Widget old, 325 Widget reference _X_UNUSED, 326 Widget new, 327 ArgList args _X_UNUSED, 328 Cardinal *num_args _X_UNUSED) 329{ 330 Boolean redisplay; 331 Mask window_mask; 332 XSetWindowAttributes attributes; 333 334 redisplay = FALSE; 335 if (old->core.tm.translations != new->core.tm.translations) { 336 XtTranslations save = new->core.tm.translations; 337 338 new->core.tm.translations = old->core.tm.translations; 339 _XtMergeTranslations(new, save, XtTableReplace); 340 } 341 342 /* Check everything that depends upon window being realized */ 343 if (XtIsRealized(old)) { 344 window_mask = 0; 345 /* Check window attributes */ 346 if (old->core.background_pixel != new->core.background_pixel 347 && new->core.background_pixmap == XtUnspecifiedPixmap) { 348 attributes.background_pixel = new->core.background_pixel; 349 window_mask |= CWBackPixel; 350 redisplay = TRUE; 351 } 352 if (old->core.background_pixmap != new->core.background_pixmap) { 353 if (new->core.background_pixmap == XtUnspecifiedPixmap) { 354 window_mask |= CWBackPixel; 355 attributes.background_pixel = new->core.background_pixel; 356 } 357 else { 358 attributes.background_pixmap = new->core.background_pixmap; 359 window_mask &= (unsigned long) (~CWBackPixel); 360 window_mask |= CWBackPixmap; 361 } 362 redisplay = TRUE; 363 } 364 if (old->core.border_pixel != new->core.border_pixel 365 && new->core.border_pixmap == XtUnspecifiedPixmap) { 366 attributes.border_pixel = new->core.border_pixel; 367 window_mask |= CWBorderPixel; 368 } 369 if (old->core.border_pixmap != new->core.border_pixmap) { 370 if (new->core.border_pixmap == XtUnspecifiedPixmap) { 371 window_mask |= CWBorderPixel; 372 attributes.border_pixel = new->core.border_pixel; 373 } 374 else { 375 attributes.border_pixmap = new->core.border_pixmap; 376 window_mask &= (unsigned long) (~CWBorderPixel); 377 window_mask |= CWBorderPixmap; 378 } 379 } 380 if (old->core.depth != new->core.depth) { 381 XtAppWarningMsg(XtWidgetToApplicationContext(old), 382 "invalidDepth", "setValues", XtCXtToolkitError, 383 "Can't change widget depth", NULL, NULL); 384 new->core.depth = old->core.depth; 385 } 386 if (old->core.colormap != new->core.colormap) { 387 window_mask |= CWColormap; 388 attributes.colormap = new->core.colormap; 389 } 390 if (window_mask != 0) { 391 /* Actually change X window attributes */ 392 XChangeWindowAttributes(XtDisplay(new), XtWindow(new), window_mask, 393 &attributes); 394 } 395 396 if (old->core.mapped_when_managed != new->core.mapped_when_managed) { 397 Boolean mapped_when_managed = new->core.mapped_when_managed; 398 399 new->core.mapped_when_managed = !mapped_when_managed; 400 XtSetMappedWhenManaged(new, mapped_when_managed); 401 } 402 } /* if realized */ 403 404 return redisplay; 405} /* CoreSetValues */ 406 407static void 408CoreSetValuesAlmost(Widget old _X_UNUSED, 409 Widget new _X_UNUSED, 410 XtWidgetGeometry *request, 411 XtWidgetGeometry *reply) 412{ 413 *request = *reply; 414} 415