|
|
1.1 ! root 1: #ifndef lint ! 2: static char rcsid[] = "$Header: Intrinsic.c,v 1.34 87/09/14 00:39:44 newman Exp $"; ! 3: #endif lint ! 4: ! 5: /* ! 6: * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. ! 7: * ! 8: * All Rights Reserved ! 9: * ! 10: * Permission to use, copy, modify, and distribute this software and its ! 11: * documentation for any purpose and without fee is hereby granted, ! 12: * provided that the above copyright notice appear in all copies and that ! 13: * both that copyright notice and this permission notice appear in ! 14: * supporting documentation, and that the name of Digital Equipment ! 15: * Corporation not be used in advertising or publicity pertaining to ! 16: * distribution of the software without specific, written prior permission. ! 17: * ! 18: * ! 19: * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ! 20: * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL ! 21: * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ! 22: * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, ! 23: * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ! 24: * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS ! 25: * SOFTWARE. ! 26: */ ! 27: #include "Intrinsic.h" ! 28: #include "TM.h" ! 29: #include "Atoms.h" ! 30: ! 31: extern char *strcpy(); ! 32: extern void RegisterWindow(); /* from event, should be in .h ||| */ ! 33: extern void UnregisterWindow(); /* from event, should be in .h ||| */ ! 34: /****************************************************************** ! 35: * ! 36: * Core Resources ! 37: * ! 38: ******************************************************************/ ! 39: ! 40: static XtResource resources[] = { ! 41: {XtNx, XtCPosition, XrmRInt, sizeof(int), ! 42: XtOffset(Widget,core.x), XtRString, "0"}, ! 43: {XtNy, XtCPosition, XrmRInt, sizeof(int), ! 44: XtOffset(Widget,core.y), XtRString, "0"}, ! 45: {XtNwidth, XtCWidth, XrmRInt, sizeof(int), ! 46: XtOffset(Widget,core.width), XtRString, "0"}, ! 47: {XtNheight, XtCHeight, XrmRInt, sizeof(int), ! 48: XtOffset(Widget,core.height), XtRString, "0"}, ! 49: /* default depth should be "InheritFromParent", and we should have a */ ! 50: /* string to depth type converter, but it needs the widget to be able */ ! 51: /* to find the parent's depth... right now, we kludge it and check for */ ! 52: /* a depth of 0 in XtCreateWidget. Gross. */ ! 53: {XtNdepth, XtCDepth,XrmRInt,sizeof(int), ! 54: XtOffset(Widget,core.depth), XtRString, "0"}, ! 55: {XtNbackground,XtCBackground,XrmRPixel,sizeof(Pixel), ! 56: XtOffset(Widget,core.background_pixel), XtRString, "White"}, ! 57: {XtNborderWidth, XtCBorderWidth,XrmRInt, sizeof(int), ! 58: XtOffset(Widget,core.border_width),XtRString, "1"}, ! 59: {XtNborder,XtCBorderColor,XrmRPixel,sizeof(Pixel), ! 60: XtOffset(Widget,core.border_pixel),XtRString, "Black"}, ! 61: {XtNsensitive,XtCSensitive,XrmRBoolean, sizeof(Boolean), ! 62: XtOffset(Widget,core.sensitive),XtRString,"TRUE"}, ! 63: {XtNmappedWhenManaged,XtCMappedWhenManaged,XrmRBoolean, sizeof(Boolean), ! 64: XtOffset(Widget,core.mapped_when_managed),XtRString,"TRUE"} ! 65: }; ! 66: static void CoreDestroy(); ! 67: static Boolean CoreSetValues (); ! 68: ! 69: CompositeWidgetClass compositeWidgetClass = &compositeClassRec; ! 70: ConstraintWidgetClass constraintWidgetClass = &constraintClassRec; ! 71: ! 72: /* ||| Should have defaults for Inherit from superclass to work */ ! 73: ! 74: WidgetClassRec widgetClassRec = { ! 75: (WidgetClass)NULL, /*superclass pointer*/ ! 76: "Core", /*class_name*/ ! 77: sizeof(WidgetRec), /*size of core data record*/ ! 78: (XtWidgetProc)NULL, /* class initializer routine */ ! 79: FALSE, /* not init'ed */ ! 80: (XtWidgetProc)NULL, /* Instance Initializer routine*/ ! 81: (XtWidgetProc)NULL, /*Realize*/ ! 82: NULL, /*actions*/ ! 83: 0, /*number of actions in translation table*/ ! 84: resources, /*resource list*/ ! 85: XtNumber(resources), /*resource_count*/ ! 86: NULLQUARK, /*xrm_class*/ ! 87: FALSE, /*compress motion*/ ! 88: TRUE, /*compress exposure*/ ! 89: FALSE, /*visible_interest*/ ! 90: CoreDestroy, /*destroy proc*/ ! 91: (XtWidgetProc) NULL, /*resize*/ ! 92: (XtExposeProc)NULL, /*expose*/ ! 93: CoreSetValues, /*set_values*/ ! 94: (XtWidgetProc)NULL /*accept_focus*/ ! 95: }; ! 96: ! 97: static void CompositeInsertChild(); ! 98: static void CompositeDeleteChild(); ! 99: static void CompositeDestroy(); ! 100: ! 101: ConstraintClassRec constraintClassRec = { ! 102: { ! 103: (WidgetClass)&widgetClassRec, /*superclass pointer*/ ! 104: "Composite", /*class_name*/ ! 105: sizeof(CompositeRec), /*size of core data record*/ ! 106: (XtWidgetProc)NULL, /* class initializer routine */ ! 107: FALSE, /* not init'ed */ ! 108: (XtWidgetProc)NULL, /* Instance Initializer routine*/ ! 109: (XtWidgetProc)NULL, /*Realize*/ ! 110: NULL, /*actions*/ ! 111: 0, /*number of actions*/ ! 112: NULL, /*resource list*/ ! 113: 0, /*resource_count*/ ! 114: NULLQUARK, /*xrm_class*/ ! 115: FALSE, /*compress motion*/ ! 116: TRUE, /*compress expose*/ ! 117: FALSE, /*visible_interest*/ ! 118: (XtWidgetProc) CompositeDestroy, /*destroy proc*/ ! 119: (XtWidgetProc) NULL, /*resize*/ ! 120: (XtExposeProc)NULL, /*expose*/ ! 121: NULL, /*set_values*/ ! 122: (XtWidgetProc)NULL, /*accept_focus*/ ! 123: },{ ! 124: (XtGeometryHandler) NULL, /* geometry_manager */ ! 125: (XtWidgetProc) NULL, ! 126: CompositeInsertChild, ! 127: CompositeDeleteChild, ! 128: (XtWidgetProc) NULL, ! 129: (XtWidgetProc) NULL, ! 130: },{ ! 131: NULL, ! 132: 0 ! 133: } ! 134: }; ! 135: ! 136: CompositeClassRec compositeClassRec = { ! 137: { ! 138: (WidgetClass)&widgetClassRec, /*superclass pointer*/ ! 139: "Composite", /*class_name*/ ! 140: sizeof(CompositeRec), /*size of core data record*/ ! 141: (XtWidgetProc)NULL, /* class initializer routine */ ! 142: FALSE, /* not init'ed */ ! 143: (XtWidgetProc)NULL, /* Instance Initializer routine*/ ! 144: (XtWidgetProc)NULL, /*Realize*/ ! 145: NULL, /*actions*/ ! 146: 0, /*number of actions*/ ! 147: NULL, /*resource list*/ ! 148: 0, /*resource_count*/ ! 149: NULLQUARK, /*xrm_class*/ ! 150: FALSE, /*compress motion*/ ! 151: TRUE, /*compress expose*/ ! 152: FALSE, /*visible_interest*/ ! 153: (XtWidgetProc) CompositeDestroy, /*destroy proc*/ ! 154: (XtWidgetProc) NULL, /*resize*/ ! 155: (XtExposeProc)NULL, /*expose*/ ! 156: NULL, /*set_values*/ ! 157: (XtWidgetProc)NULL, /*accept_focus*/ ! 158: },{ ! 159: (XtGeometryHandler) NULL, /* geometry_manager */ ! 160: (XtWidgetProc) NULL, ! 161: CompositeInsertChild, ! 162: CompositeDeleteChild, ! 163: (XtWidgetProc) NULL, ! 164: (XtWidgetProc) NULL, ! 165: } ! 166: }; ! 167: ! 168: void ClassInit(widgetClass) ! 169: WidgetClass widgetClass; ! 170: { ! 171: if ((widgetClass->core_class.superclass != NULL) ! 172: && (!(widgetClass->core_class.superclass-> core_class.class_inited))) ! 173: ClassInit(widgetClass->core_class.superclass); ! 174: if (widgetClass->core_class.class_initialize != NULL) ! 175: widgetClass->core_class.class_initialize(); ! 176: widgetClass->core_class.class_inited = TRUE; ! 177: return; ! 178: } ! 179: ! 180: static void RecurseInitialize (reqWidget, newWidget, args, num_args, class) ! 181: Widget reqWidget; ! 182: Widget newWidget; ! 183: ArgList args; ! 184: Cardinal num_args; ! 185: WidgetClass class; ! 186: { ! 187: if (class->core_class.superclass) ! 188: RecurseInitialize (reqWidget, newWidget, args, num_args, ! 189: class->core_class.superclass); ! 190: if (class->core_class.initialize) ! 191: (*class->core_class.initialize) (reqWidget, newWidget, args, num_args); ! 192: } ! 193: ! 194: Widget TopLevelCreate(name,widgetClass,screen,args,num_args) ! 195: char *name; ! 196: WidgetClass widgetClass; ! 197: Screen* screen; ! 198: ArgList args; ! 199: Cardinal num_args; ! 200: { ! 201: Widget widget, reqWidget; ! 202: unsigned widget_size; ! 203: if(!(widgetClass->core_class.class_inited)) ! 204: ClassInit(widgetClass); ! 205: widget_size = widgetClass->core_class.widget_size; ! 206: widget = (Widget)XtMalloc(widget_size); ! 207: widget->core.window = (Window) NULL; ! 208: widget->core.name = strcpy(XtMalloc((unsigned) strlen(name)+1), name); ! 209: widget->core.widget_class = widgetClass; ! 210: widget->core.parent = NULL; ! 211: widget->core.screen = screen; ! 212: widget->core.managed = FALSE; ! 213: widget->core.visible = TRUE; ! 214: widget->core.background_pixmap = (Pixmap) NULL; ! 215: widget->core.border_pixmap = (Pixmap) NULL; ! 216: widget->core.event_table = NULL; ! 217: widget->core.sensitive = TRUE; ! 218: widget->core.ancestor_sensitive = TRUE; ! 219: widget->core.translations = NULL; ! 220: widget->core.destroy_callbacks = NULL; ! 221: widget->core.being_destroyed = FALSE; ! 222: ! 223: if (XtIsComposite(widget)) { ! 224: ((CompositeWidget)widget)->composite.num_children = 0; ! 225: ((CompositeWidget)widget)->composite.num_mapped_children = 0; ! 226: ((CompositeWidget)widget)->composite.children = NULL; ! 227: } ! 228: XtGetResources(widget,args,num_args); ! 229: if (widget->core.depth == 0) ! 230: /* ||| gross kludge! fix this!!! */ ! 231: widget->core.depth = XtScreen(widget)->root_depth; ! 232: reqWidget = (Widget)XtMalloc(widget_size); ! 233: bcopy ((char *) widget, (char *) reqWidget, widget_size); ! 234: RecurseInitialize (reqWidget, widget, args, num_args, widgetClass); ! 235: XtFree ((char *) reqWidget); ! 236: ! 237: return (widget); ! 238: } ! 239: ! 240: static void CompositeDestroy(w) ! 241: CompositeWidget w; ! 242: { ! 243: XtFree((char *) w->composite.children); ! 244: } ! 245: ! 246: /* ARGSUSED */ ! 247: static void CompositeInsertChild(w, args, num_args) ! 248: Widget w; ! 249: ArgList args; ! 250: Cardinal num_args; ! 251: { ! 252: Cardinal position; ! 253: Cardinal i; ! 254: CompositeWidget cw; ! 255: ! 256: cw = (CompositeWidget) w->core.parent; ! 257: ! 258: /* ||| Get position from "insert_position" procedure */ ! 259: position = cw->composite.num_children; ! 260: ! 261: /* ||| Some better allocation, don't realloc every time ! */ ! 262: cw->composite.children = ! 263: (WidgetList) XtRealloc((caddr_t) cw->composite.children, ! 264: (unsigned) (cw->composite.num_children + 1) * sizeof(Widget)); ! 265: /* Ripple children up one space from "position" */ ! 266: for (i = cw->composite.num_children; i > position; i--) { ! 267: cw->composite.children[i] = cw->composite.children[i-1]; ! 268: } ! 269: cw->composite.children[position] = w; ! 270: cw->composite.num_children++; ! 271: } ! 272: ! 273: static void CompositeDeleteChild(w) ! 274: Widget w; ! 275: { ! 276: Cardinal position; ! 277: Cardinal i; ! 278: CompositeWidget cw; ! 279: ! 280: cw = (CompositeWidget) w->core.parent; ! 281: ! 282: for (position = 0; position < cw->composite.num_children; position++) { ! 283: if (cw->composite.children[position] == w) { ! 284: break; ! 285: } ! 286: } ! 287: ! 288: /* Ripple children down one space from "position" */ ! 289: cw->composite.num_children--; ! 290: for (i = position; i < cw->composite.num_children; i++) { ! 291: cw->composite.children[i] = cw->composite.children[i+1]; ! 292: } ! 293: } ! 294: ! 295: Widget XtCreateWidget(name,widgetClass,parent,args,num_args) ! 296: char *name; ! 297: WidgetClass widgetClass; ! 298: Widget parent; ! 299: ArgList args; ! 300: Cardinal num_args; ! 301: ! 302: { ! 303: Widget widget, reqWidget; ! 304: unsigned widget_size; ! 305: if (widgetClass == NULL || parent == NULL || ! XtIsComposite(parent)) { ! 306: XtError("invalid parameters to XtCreateWidget"); ! 307: return NULL; ! 308: } ! 309: if (! (widgetClass->core_class.class_inited)) ! 310: ClassInit(widgetClass); ! 311: ! 312: widget_size = widgetClass->core_class.widget_size; ! 313: widget = (Widget)XtMalloc(widget_size); ! 314: widget->core.window = (Window) NULL; ! 315: widget->core.name = strcpy(XtMalloc((unsigned)strlen(name)+1), name); ! 316: widget->core.widget_class = widgetClass; ! 317: widget->core.parent = parent; ! 318: widget->core.screen = parent->core.screen; ! 319: widget->core.managed = FALSE; ! 320: widget->core.visible = TRUE; ! 321: widget->core.background_pixmap = (Pixmap) NULL; ! 322: widget->core.border_pixmap = (Pixmap) NULL; ! 323: widget->core.event_table = NULL; ! 324: widget->core.sensitive = TRUE; ! 325: widget->core.ancestor_sensitive = TRUE; ! 326: widget->core.translations = NULL; ! 327: widget->core.destroy_callbacks = NULL; ! 328: widget->core.being_destroyed = parent -> core.being_destroyed; ! 329: /* ||| Should be in CompositeInitialize */ ! 330: if (XtIsComposite (widget)) { ! 331: ((CompositeWidget)widget)->composite.num_children = 0; ! 332: ((CompositeWidget)widget)->composite.num_mapped_children = 0; ! 333: ((CompositeWidget)widget)->composite.children = NULL; ! 334: ((CompositeWidget)widget)->composite.num_slots = 0; ! 335: } ! 336: XtGetResources(widget,args,num_args); ! 337: if (widget->core.depth == 0) ! 338: /* ||| gross kludge! fix this!!! */ ! 339: widget->core.depth = widget->core.parent->core.depth; ! 340: DefineTranslation(widget); ! 341: reqWidget = (Widget)XtMalloc(widget_size); ! 342: bcopy ((char *) widget, (char *) reqWidget, widget_size); ! 343: RecurseInitialize (reqWidget, widget, args, num_args, widgetClass); ! 344: XtFree ((char *) reqWidget); ! 345: ((CompositeWidgetClass)(widget->core.parent->core.widget_class)) ! 346: ->composite_class.insert_child(widget, args, num_args); ! 347: return (widget); ! 348: } ! 349: ! 350: void FillInParameters(widget,valuemask,values) ! 351: Widget widget; ! 352: XtValueMask *valuemask; ! 353: XSetWindowAttributes *values; ! 354: { ! 355: *valuemask = (CWBackPixel | CWBorderPixel | CWEventMask); ! 356: (*values).event_mask = _XtBuildEventMask(widget); ! 357: (*values).background_pixel = widget->core.background_pixel; ! 358: (*values).border_pixel = widget->core.border_pixel; ! 359: return; ! 360: } ! 361: ! 362: Boolean XtIsRealized (widget) ! 363: Widget widget; ! 364: { ! 365: return (widget->core.window != NULL); ! 366: } ! 367: ! 368: Boolean XtIsSubclass(widget, widgetClass) ! 369: Widget widget; ! 370: WidgetClass widgetClass; ! 371: { ! 372: WidgetClass w; ! 373: for(w=widget->core.widget_class; w != NULL; w = w->core_class.superclass) ! 374: if (w == widgetClass) return (TRUE); ! 375: return (FALSE); ! 376: } ! 377: ! 378: void XtRealizeWidget (widget) ! 379: ! 380: Widget widget; ! 381: { ! 382: CompositeWidget cwidget; ! 383: XtValueMask valuemask; ! 384: XSetWindowAttributes values; ! 385: Cardinal i; ! 386: if (XtIsRealized(widget)) return; ! 387: FillInParameters (widget,&valuemask,&values); ! 388: widget->core.widget_class->core_class.realize(widget,valuemask,&values); ! 389: RegisterWindow(widget->core.window, widget); ! 390: if (XtIsComposite (widget)) { ! 391: cwidget = (CompositeWidget)widget; ! 392: for (i= cwidget->composite.num_children;i!=0;--i) ! 393: XtRealizeWidget(cwidget->composite.children[i-1]); ! 394: if (cwidget->composite.num_children == cwidget->composite.num_mapped_children) ! 395: XMapSubwindows(XtDisplay(widget), XtWindow(widget)); ! 396: else while (i = cwidget->composite.num_mapped_children != 0) { ! 397: if (cwidget->composite.children[i-1]->core.managed) { ! 398: XtMapWidget(cwidget->composite.children[i-1]); ! 399: i--; ! 400: } } ! 401: } ! 402: if (widget->core.parent == NULL) XtMapWidget(widget); ! 403: return; ! 404: } ! 405: ! 406: void XtCreateWindow(widget, windowClass, visual, valueMask, attributes) ! 407: Widget widget; ! 408: unsigned int windowClass; ! 409: Visual *visual; ! 410: Mask valueMask; ! 411: XSetWindowAttributes *attributes; ! 412: { ! 413: if (widget->core.window == None) { ! 414: widget->core.window = ! 415: XCreateWindow(XtDisplay(widget), (widget->core.parent ? ! 416: widget->core.parent->core.window: ! 417: widget->core.screen->root), ! 418: widget->core.x, widget->core.y, ! 419: widget->core.width, widget->core.height, ! 420: widget->core.border_width, (int)widget->core.depth, ! 421: windowClass, visual, valueMask, attributes); ! 422: } ! 423: } ! 424: ! 425: ! 426: void XtUnmanageChildren(children, num_children) ! 427: WidgetList children; ! 428: Cardinal num_children; ! 429: { ! 430: CompositeWidget parent; ! 431: register Widget child; ! 432: Cardinal newCount, oldCount; ! 433: ! 434: if (num_children == 0) return; ! 435: parent = (CompositeWidget) children[0]->core.parent; ! 436: if (parent->core.being_destroyed) return; ! 437: ! 438: newCount = 0; ! 439: for (oldCount = 0; oldCount < num_children; oldCount++) { ! 440: child = children[oldCount]; ! 441: if ((CompositeWidget) child->core.parent != parent) { ! 442: XtWarning("Not all children have same parent in XtRemoveChildren"); ! 443: } else if ((! child->core.managed) || (child->core.being_destroyed)) { ! 444: /* Do nothing */ ! 445: } else { ! 446: if (XtIsRealized(child)) { ! 447: XtUnmapWidget(child); ! 448: } ! 449: child->core.managed = FALSE; ! 450: newCount++; ! 451: } ! 452: } ! 453: parent->composite.num_mapped_children = ! 454: parent->composite.num_mapped_children - newCount; ! 455: ! 456: ((CompositeWidgetClass)parent->core.widget_class) ! 457: ->composite_class.change_managed(parent); ! 458: } ! 459: ! 460: void XtUnmanageChild(child) ! 461: Widget child; ! 462: { ! 463: XtUnmanageChildren(&child, 1); ! 464: } ! 465: ! 466: void XtManageChildren(children, num_children) ! 467: WidgetList children; ! 468: Cardinal num_children; ! 469: { ! 470: CompositeWidget parent; ! 471: register Widget child; ! 472: Cardinal newCount, oldCount; ! 473: ! 474: if (num_children == 0) return; ! 475: parent = (CompositeWidget) children[0]->core.parent; ! 476: if (parent->core.being_destroyed) return; ! 477: ! 478: newCount = 0; ! 479: for (oldCount = 0; oldCount < num_children; oldCount++) { ! 480: child = children[oldCount]; ! 481: if ((CompositeWidget) child->core.parent != parent) { ! 482: XtWarning("Not all children have same parent in XtAddChildren"); ! 483: } else if ((child->core.managed) || (child->core.being_destroyed)) { ! 484: /* Do nothing */ ! 485: } else { ! 486: if (XtIsRealized(child)) { ! 487: /* ||| Do mapping after change_managed */ ! 488: XtMapWidget(child); ! 489: } ! 490: child->core.managed = TRUE; ! 491: newCount++; ! 492: } ! 493: } ! 494: parent->composite.num_mapped_children = ! 495: parent->composite.num_mapped_children + newCount; ! 496: ! 497: ((CompositeWidgetClass)parent->core.widget_class) ! 498: ->composite_class.change_managed(parent); ! 499: } ! 500: ! 501: void XtManageChild(child) ! 502: Widget child; ! 503: { ! 504: XtManageChildren(&child, (Cardinal) 1); ! 505: } ! 506: ! 507: void XtSetMappedWhenManaged(widget, mappedWhenManaged) ! 508: Widget widget; ! 509: Boolean mappedWhenManaged; ! 510: { ! 511: if (widget->core.mapped_when_managed == mappedWhenManaged) return; ! 512: XtWarning("Mapped when managed not implemented."); /* ||| */ ! 513: if (mappedWhenManaged) { ! 514: /* we didn't used to be mapped when managed. If we are realized and */ ! 515: /* managed then map us, increment parent's count of mapped children */ ! 516: } else { ! 517: /* we used to be mapped when managed. If we were realized and */ ! 518: /* managed then unmap us, decrement parent's mapped children count */ ! 519: } ! 520: } ! 521: ! 522: void XtSetSensitive(widget,sensitive) ! 523: Widget widget; ! 524: Boolean sensitive; ! 525: { ! 526: int i; ! 527: widget->core.sensitive = sensitive; ! 528: if ((widget->core.sensitive == widget->core.ancestor_sensitive) ! 529: && XtIsComposite (widget)) ! 530: for (i= ((CompositeWidget)widget)->composite.num_children;i != 0; --i) ! 531: XtSetSensitive (((CompositeWidget)widget)->composite.children[i-1],sensitive); ! 532: ! 533: } ! 534: ! 535: #define TABLESIZE 20 ! 536: typedef struct { ! 537: int offset; ! 538: WidgetClass widgetClass; ! 539: } CallbackTableRec,*CallbackTable; ! 540: typedef void (*fooProc)(); ! 541: static CallbackTable callbackTable = NULL; ! 542: static XtCallbackKind currentIndex = 1; ! 543: static XtCallbackKind maxIndex; ! 544: InitializeCallbackTable () ! 545: { ! 546: callbackTable = (CallbackTable) XtMalloc( ! 547: (unsigned)TABLESIZE*sizeof(CallbackTableRec)); ! 548: maxIndex = TABLESIZE; ! 549: } ! 550: ! 551: static void ExpandTable() ! 552: { ! 553: ! 554: callbackTable = (CallbackTable)XtRealloc( ! 555: (char *)callbackTable, ! 556: (unsigned)(currentIndex+TABLESIZE)*sizeof(CallbackTableRec)); ! 557: maxIndex = currentIndex + TABLESIZE; ! 558: } ! 559: ! 560: ! 561: XtCallbackKind XtNewCallbackKind(widgetClass,offset) ! 562: WidgetClass widgetClass; ! 563: Cardinal offset; ! 564: { ! 565: if (currentIndex == maxIndex) ExpandTable(); ! 566: callbackTable[currentIndex].offset = offset; ! 567: callbackTable[currentIndex].widgetClass = widgetClass; ! 568: return(currentIndex++); ! 569: } ! 570: ! 571: ! 572: ! 573: XtCallbackList *FetchXtCallbackList (widget,callbackKind) ! 574: Widget widget; ! 575: XtCallbackKind callbackKind; ! 576: { ! 577: if ( callbackKind >= maxIndex || ! 578: !XtIsSubclass(widget,callbackTable[callbackKind].widgetClass) ) ! 579: return(NULL); ! 580: ! 581: return ((XtCallbackList*)((int)widget + callbackTable[callbackKind].offset)); ! 582: } ! 583: ! 584: ! 585: void AddCallback (widget,callbackList,callback,closure) ! 586: Widget widget; ! 587: XtCallbackList *callbackList; ! 588: XtCallbackProc callback; ! 589: Opaque closure; ! 590: { ! 591: ! 592: XtCallbackRec *c,*cl; ! 593: c = (XtCallbackRec*) XtMalloc((unsigned)sizeof(XtCallbackRec)); ! 594: c -> next = NULL; ! 595: c -> widget = widget; ! 596: c -> closure = closure; ! 597: c -> callback = callback; ! 598: if (*callbackList == NULL){ ! 599: (*callbackList) = c; ! 600: return; ! 601: } ! 602: for (cl = (*callbackList); cl->next != NULL; cl = cl->next) {} ! 603: cl->next = c; ! 604: return; ! 605: } ! 606: ! 607: void XtAddCallback(widget, callbackKind,callback,closure) ! 608: Widget widget; ! 609: XtCallbackKind callbackKind; ! 610: XtCallbackProc callback; ! 611: Opaque closure; ! 612: { ! 613: XtCallbackList *callbackList; ! 614: callbackList = FetchXtCallbackList(widget,callbackKind); ! 615: if (callbackList == NULL) { ! 616: XtError("invalid parameters to XtAddCallback"); ! 617: return; ! 618: } ! 619: AddCallback(widget,callbackList,callback,closure); ! 620: return; ! 621: } ! 622: ! 623: void RemoveCallback (widget,callbackList, callback, closure) ! 624: Widget widget; ! 625: XtCallbackList *callbackList; ! 626: XtCallbackProc callback; ! 627: Opaque closure; ! 628: ! 629: { ! 630: XtCallbackList cl; ! 631: ! 632: for ( ! 633: cl = *callbackList; ! 634: cl != NULL; ! 635: (cl = *(callbackList = &cl->next))) ! 636: if (( cl->widget == widget) && (cl->closure == closure) ! 637: && (cl->callback == callback) ) { ! 638: *callbackList = cl->next; ! 639: XtFree ((char *)cl); ! 640: } ! 641: return; ! 642: } ! 643: ! 644: void XtRemoveCallback (widget, callbackKind, callback, closure) ! 645: Widget widget; ! 646: XtCallbackKind callbackKind; ! 647: XtCallbackProc callback; ! 648: Opaque closure; ! 649: { ! 650: XtCallbackList *callbackList; ! 651: callbackList = FetchXtCallbackList(widget,callbackKind); ! 652: if (callbackList == NULL) { ! 653: XtError("invalid parameters to XtRemoveCallback"); ! 654: return; ! 655: } ! 656: RemoveCallback(widget,callbackList,callback,closure); ! 657: return; ! 658: } ! 659: ! 660: ! 661: void RemoveAllCallbacks (callbackList) ! 662: XtCallbackList *callbackList; ! 663: ! 664: { ! 665: XtCallbackList cl, tcl; ! 666: ! 667: cl = *callbackList; ! 668: while (cl != NULL) { ! 669: tcl = cl; ! 670: cl = cl->next; ! 671: XtFree((char *) tcl); ! 672: } ! 673: ! 674: (*callbackList) = NULL; ! 675: } ! 676: ! 677: void XtRemoveAllCallbacks(widget, callbackKind) ! 678: Widget widget; ! 679: XtCallbackKind callbackKind; ! 680: { ! 681: XtCallbackList *callbackList; ! 682: callbackList = FetchXtCallbackList(widget,callbackKind); ! 683: if (callbackList == NULL) { ! 684: XtError("invalid parameters to XtRemoveAllCallbacks"); ! 685: return; ! 686: } ! 687: RemoveAllCallbacks(callbackList); ! 688: return; ! 689: } ! 690: ! 691: ! 692: void CallCallbacks (callbackList,callData) ! 693: XtCallbackList *callbackList; ! 694: Opaque callData; ! 695: { ! 696: XtCallbackRec *cl; ! 697: if ((*callbackList) == NULL )return; ! 698: for (cl = (*callbackList); cl != NULL; cl = cl->next) ! 699: (*(cl->callback))(cl->widget,cl->closure,callData); ! 700: } ! 701: ! 702: void XtCallCallbacks (widget, callbackKind, callData) ! 703: Widget widget; ! 704: XtCallbackKind callbackKind; ! 705: Opaque callData; ! 706: { ! 707: XtCallbackList *callbackList; ! 708: callbackList = FetchXtCallbackList(widget,callbackKind); ! 709: if (callbackList == NULL) { ! 710: XtError("invalid parameters to XtCallCallbacks"); ! 711: return; ! 712: } ! 713: CallCallbacks(callbackList,callData); ! 714: return; ! 715: } ! 716: ! 717: ! 718: void Phase1Destroy (widget) ! 719: Widget widget; ! 720: { ! 721: int i; ! 722: if (widget->core.being_destroyed) return; ! 723: widget-> core.being_destroyed = TRUE; ! 724: if (XtIsComposite (widget)) ! 725: for (i= ((CompositeWidget)widget)->composite.num_children; i != 0; --i) ! 726: Phase1Destroy (((CompositeWidget)widget)->composite.children[i-1]); ! 727: return; ! 728: } ! 729: void Recursive(widget,proc) ! 730: Widget widget; ! 731: fooProc proc; ! 732: { ! 733: CompositeWidget cwidget; ! 734: int i; ! 735: if (XtIsComposite(widget)) { ! 736: cwidget=(CompositeWidget)widget; ! 737: for (i=cwidget->composite.num_children; ! 738: i != 0; --i) { ! 739: Recursive(cwidget->composite.children[i-1],proc); ! 740: } ! 741: } ! 742: (*proc)(widget); ! 743: return; ! 744: } ! 745: ! 746: void Phase2Callbacks(widget) ! 747: Widget widget; ! 748: { ! 749: CallCallbacks(&(widget->core.destroy_callbacks), ! 750: (Opaque) NULL); ! 751: return; ! 752: } ! 753: ! 754: /* ARGSUSED */ ! 755: void Phase2Destroy(widget, closure, callData) ! 756: Widget widget; ! 757: Opaque closure; ! 758: Opaque callData; ! 759: { ! 760: WidgetClass widgetClass; ! 761: for(widgetClass = widget->core.widget_class; ! 762: widgetClass != NULL; ! 763: widgetClass = widgetClass ->core_class.superclass) ! 764: if ((widgetClass->core_class.destroy) != NULL) ! 765: (*(widgetClass->core_class.destroy))(widget); ! 766: } ! 767: ! 768: void XtPhase2Destroy (widget, closure, callData) ! 769: Widget widget; ! 770: { ! 771: Display *display; ! 772: Window window; ! 773: if (widget->core.parent != NULL) { ! 774: XtUnmanageChild(widget); ! 775: ((CompositeWidgetClass) widget->core.parent->core.widget_class) ! 776: ->composite_class.delete_child(widget); ! 777: } ! 778: display = XtDisplay(widget); /* Phase2Destroy removes Widget*/ ! 779: window = widget->core.window; ! 780: Recursive(widget,Phase2Callbacks); ! 781: Recursive(widget,Phase2Destroy); ! 782: if (window != NULL) XDestroyWindow(display,window); ! 783: return; ! 784: } ! 785: ! 786: ! 787: void XtDestroyWidget (widget) ! 788: Widget widget; ! 789: ! 790: { ! 791: if (widget->core.being_destroyed) return; ! 792: ! 793: Phase1Destroy(widget); ! 794: AddCallback(widget, &DestroyList, XtPhase2Destroy, (Opaque)NULL); ! 795: ! 796: } ! 797: ! 798: static void CoreDestroy (widget) ! 799: Widget widget; ! 800: { ! 801: register XtEventRec *p1,*p2; ! 802: XtFree((char*)(widget->core.name)); ! 803: if (widget->core.background_pixmap != NULL) ! 804: XFreePixmap(XtDisplay(widget),widget->core.background_pixmap); ! 805: if (widget->core.border_pixmap != NULL) ! 806: XFreePixmap(XtDisplay(widget),widget->core.border_pixmap); ! 807: p1 = widget->core.event_table; ! 808: while(p1 != NULL){ ! 809: p2 = p1; ! 810: p1 = p1->next; ! 811: XtFree((char*)p2); ! 812: } ! 813: if (widget->core.translations != NULL) ! 814: TranslateTableFree(widget->core.translations); ! 815: UnregisterWindow(widget->core.window,widget); ! 816: /* if (onGrabList(widget))RemoveGrab(widget); */ ! 817: XtFree((char*)widget); ! 818: return; ! 819: ! 820: } ! 821: ! 822: static Boolean CoreSetValues() ! 823: { ! 824: /* ||| */ ! 825: return (FALSE); ! 826: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.