home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / Xt / Object.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-10  |  6.6 KB  |  215 lines

  1. /* $XConsortium: Object.c,v 1.19 91/06/10 15:08:05 converse Exp $ */
  2.  
  3. /***********************************************************
  4. Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  5. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  6.  
  7.                         All Rights Reserved
  8.  
  9. Permission to use, copy, modify, and distribute this software and its 
  10. documentation for any purpose and without fee is hereby granted, 
  11. provided that the above copyright notice appear in all copies and that
  12. both that copyright notice and this permission notice appear in 
  13. supporting documentation, and that the names of Digital or MIT not be
  14. used in advertising or publicity pertaining to distribution of the
  15. software without specific, written prior permission.  
  16.  
  17. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  19. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  20. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23. SOFTWARE.
  24.  
  25. ******************************************************************/
  26.  
  27. #define OBJECT
  28. #include "IntrinsicI.h"
  29. #include "StringDefs.h"
  30.  
  31. static XtResource resources[] = {
  32.         {XtNdestroyCallback, XtCCallback, XtRCallback,sizeof(XtPointer),
  33.          XtOffsetOf(ObjectRec,object.destroy_callbacks),
  34.      XtRCallback, (XtPointer)NULL}
  35.     };
  36.  
  37. static void ObjectClassPartInitialize();
  38. static Boolean ObjectSetValues();
  39. static void ObjectDestroy();
  40.  
  41. externaldef(objectclassrec) ObjectClassRec objectClassRec = {
  42.   {
  43.     /* superclass      */    NULL,
  44.     /* class_name      */    "Object",
  45.     /* widget_size      */    sizeof(ObjectRec),
  46.     /* class_initialize   */    NULL,
  47.     /* class_part_initialize*/    ObjectClassPartInitialize,
  48.     /* class_inited       */    FALSE,
  49.     /* initialize      */    NULL,
  50.     /* initialize_hook    */    NULL,        
  51.     /* pad                */    NULL,
  52.     /* pad          */    NULL,
  53.     /* pad             */    0,
  54.     /* resources      */    resources,
  55.     /* num_resources      */    XtNumber(resources),
  56.     /* xrm_class      */    NULLQUARK,
  57.     /* pad                */    FALSE,
  58.     /* pad                */    FALSE,
  59.     /* pad                */    FALSE,
  60.     /* pad                */    FALSE,
  61.     /* destroy          */    ObjectDestroy,
  62.     /* pad          */    NULL,
  63.     /* pad          */    NULL,
  64.     /* set_values      */    ObjectSetValues,
  65.     /* set_values_hook    */    NULL,            
  66.     /* pad                */    NULL,
  67.     /* get_values_hook    */    NULL,            
  68.     /* pad                */    NULL,
  69.     /* version          */    XtVersion,
  70.     /* callback_offsets   */    NULL,
  71.     /* pad                */    NULL,
  72.     /* pad                */    NULL,
  73.     /* pad                */    NULL,
  74.     /* extension        */  NULL
  75. }
  76. };
  77.  
  78. externaldef(objectClass) WidgetClass objectClass
  79.                           = (WidgetClass)&objectClassRec;
  80.  
  81. /*
  82.  * Start of object routines.
  83.  */
  84.  
  85.  
  86. static void ConstructCallbackOffsets(widgetClass)
  87.     WidgetClass widgetClass;
  88. {
  89.     static XrmQuark QCallback = NULLQUARK;
  90.     register int i;
  91.     register int tableSize;
  92.     register CallbackTable newTable;
  93.     register CallbackTable superTable;
  94.     register XrmResourceList resourceList;
  95.     ObjectClass objectClass = (ObjectClass)widgetClass;
  96.  
  97.     /*
  98.       This function builds an array of pointers to the resource
  99.       structures which describe the callbacks for this widget class.
  100.       This array is special in that the 0th entry is the number of
  101.       callback pointers.
  102.      */
  103.  
  104.     if (QCallback == NULLQUARK)
  105.     QCallback = XrmPermStringToQuark(XtRCallback);
  106.  
  107.     if (objectClass->object_class.superclass != NULL) {
  108.     superTable = (CallbackTable)
  109.         ((ObjectClass) objectClass->object_class.superclass)->
  110.         object_class.callback_private;
  111.     tableSize = (int) superTable[0];
  112.     } else { 
  113.     superTable = (CallbackTable) NULL;
  114.     tableSize = 0;
  115.     }
  116.  
  117.     /* Count the number of callbacks */
  118.     resourceList = (XrmResourceList) objectClass->object_class.resources;
  119.     for (i = objectClass->object_class.num_resources; --i >= 0; resourceList++)
  120.     if (resourceList->xrm_type == QCallback)
  121.         tableSize++;
  122.     
  123.     /*
  124.      * Allocate and load the table.  Make sure that the new callback
  125.      * offsets occur in the table ahead of the superclass callback
  126.      * offsets so that resource overrides work.
  127.      */
  128.     newTable = (CallbackTable)
  129.     XtMalloc(sizeof(XrmResource *) * (tableSize + 1));
  130.     
  131.     newTable[0] = (XrmResource *) tableSize;
  132.  
  133.     if (superTable)
  134.     tableSize -= (int) superTable[0];
  135.     resourceList = (XrmResourceList) objectClass->object_class.resources;
  136.     for (i=1; tableSize > 0; resourceList++)
  137.     if (resourceList->xrm_type == QCallback) {
  138.         newTable[i++] = resourceList;
  139.         tableSize--;
  140.     }
  141.  
  142.     if (superTable)
  143.     for (tableSize = (int) *superTable++; --tableSize >= 0; superTable++)
  144.         newTable[i++] = *superTable;
  145.     
  146.     objectClass->object_class.callback_private = (XtPointer) newTable;
  147. }
  148.  
  149. static void ObjectClassPartInitialize(wc)
  150.     register WidgetClass wc;
  151. {
  152.    ObjectClass oc = (ObjectClass)wc;
  153.  
  154.     oc->object_class.xrm_class = XrmPermStringToQuark(oc->object_class.class_name);
  155.  
  156.     if (oc->object_class.resources)
  157.     _XtCompileResourceList(oc->object_class.resources,
  158.                    oc->object_class.num_resources);
  159.  
  160.     ConstructCallbackOffsets(wc);
  161.     _XtResourceDependencies(wc);
  162. }
  163.  
  164.  
  165. /*ARGSUSED*/
  166. static Boolean ObjectSetValues(old, request, widget, args, num_args)
  167.     Widget    old, request, widget;
  168.     ArgList args;
  169.     Cardinal *num_args;
  170. {
  171.     register CallbackTable offsets;
  172.     register int i;
  173.     register InternalCallbackList *ol, *nl;
  174.  
  175.     /* Compile any callback lists into internal form */
  176.     offsets = (CallbackTable) XtClass(widget)->core_class.callback_private;
  177.  
  178.     for (i= (int) *(offsets++); --i >= 0; offsets++) {
  179.     ol = (InternalCallbackList *)
  180.         ((char *) old - (*offsets)->xrm_offset - 1);
  181.     nl = (InternalCallbackList *)
  182.         ((char *) widget - (*offsets)->xrm_offset - 1);
  183.     if (*ol != *nl) {
  184.         if (*ol != NULL)
  185.         XtFree((char *) *ol);
  186.         if (*nl != NULL)
  187.         *nl = _XtCompileCallbackList((XtCallbackList) *nl);
  188.     }
  189.     }
  190.     return False;
  191. }
  192.  
  193.  
  194. static void ObjectDestroy (widget)
  195.     register Widget    widget;
  196. {
  197.     register CallbackTable offsets;
  198.     register int i;
  199.     register InternalCallbackList cl;
  200.  
  201.     /* Remove all callbacks associated with widget */
  202.     offsets = (CallbackTable)
  203.     widget->core.widget_class->core_class.callback_private;
  204.  
  205.     for (i = (int) *(offsets++); --i >= 0; offsets++) {
  206.     cl = *(InternalCallbackList *)
  207.         ((char *) widget - (*offsets)->xrm_offset - 1);
  208.     if (cl) XtFree((char *) cl);
  209.     }
  210.  
  211.     XtFree((char *) widget);
  212. } /* ObjectDestroy */
  213.  
  214.  
  215.