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