home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / Xt / Composite.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-08  |  6.7 KB  |  206 lines

  1. /* $XConsortium: Composite.c,v 1.18 91/04/04 20:52:53 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 COMPOSITE
  28. #include "IntrinsicI.h"
  29. #include "StringDefs.h"
  30.  
  31. static XtResource resources[] = {
  32.     {XtNchildren, XtCReadOnly, XtRWidgetList, sizeof(WidgetList),
  33.      XtOffsetOf(CompositeRec, composite.children), XtRImmediate, NULL},
  34.     {XtNnumChildren, XtCReadOnly, XtRCardinal, sizeof(Cardinal),
  35.      XtOffsetOf(CompositeRec, composite.num_children), XtRImmediate, 0},
  36.     {XtNinsertPosition, XtCInsertPosition, XtRFunction, sizeof(XtOrderProc),
  37.      XtOffsetOf(CompositeRec, composite.insert_position), XtRImmediate, NULL},
  38. };
  39.  
  40. static void CompositeClassPartInitialize();
  41. static void CompositeInitialize();
  42. static void CompositeInsertChild();
  43. static void CompositeDeleteChild();
  44. static void CompositeDestroy();
  45.  
  46. externaldef(compositeclassrec) CompositeClassRec compositeClassRec = {
  47.   { /******* CorePart *******/
  48.     /* superclass        */    &widgetClassRec,
  49.     /* class_name        */    "Composite",
  50.     /* widget_size        */    sizeof(CompositeRec),
  51.     /* class_initialize     */  NULL,
  52.     /* class_part_initialize*/    CompositeClassPartInitialize,
  53.     /* class_inited        */    FALSE,
  54.     /* initialize        */    CompositeInitialize,
  55.     /* initialize_hook      */    NULL,        
  56.     /* realize            */    XtInheritRealize,
  57.     /* actions            */    NULL,
  58.     /* num_actions        */    0,
  59.     /* resources        */    resources,
  60.     /* num_resources        */    XtNumber(resources),
  61.     /* xrm_class        */    NULLQUARK,
  62.     /* compress_motion      */    FALSE,
  63.     /* compress_exposure    */    TRUE,
  64.     /* compress_enterleave  */  FALSE,
  65.     /* visible_interest     */    FALSE,
  66.     /* destroy            */    CompositeDestroy,
  67.     /* resize            */    NULL,
  68.     /* expose            */    NULL,
  69.     /* set_values        */    NULL,
  70.     /* set_values_hook      */    NULL,            
  71.     /* set_values_almost    */    XtInheritSetValuesAlmost,  
  72.     /* get_values_hook      */    NULL,            
  73.     /* accept_focus        */    NULL,
  74.     /* version            */    XtVersion,
  75.     /* callback_offsets     */  NULL,
  76.     /* tm_table            */  NULL,
  77.     /* query_geometry        */  NULL,
  78.     /* display_accelerator  */    NULL,
  79.     /* extension        */  NULL
  80.   },
  81.   { /**** CompositePart *****/
  82.     /* geometry_handler     */  NULL,
  83.     /* change_managed       */  NULL,
  84.     /* insert_child        */  CompositeInsertChild,
  85.     /* delete_child        */  CompositeDeleteChild,
  86.     /* extension        */  NULL
  87.     }
  88. };
  89.  
  90. externaldef(compositewidgetclass) WidgetClass compositeWidgetClass = (WidgetClass) &compositeClassRec;
  91.  
  92. static void CompositeClassPartInitialize(widgetClass)
  93.     WidgetClass widgetClass;
  94. {
  95.     register CompositePartPtr wcPtr;
  96.     register CompositePartPtr superPtr;
  97.  
  98.     wcPtr = (CompositePartPtr)
  99.     &(((CompositeWidgetClass)widgetClass)->composite_class);
  100.  
  101.     if (widgetClass != compositeWidgetClass)
  102.     /* don't compute possible bogus pointer */
  103.     superPtr = (CompositePartPtr)&(((CompositeWidgetClass)widgetClass
  104.             ->core_class.superclass)->composite_class);
  105. #ifdef lint
  106.     else
  107.     superPtr = NULL;
  108. #endif
  109.  
  110.     /* We don't need to check for null super since we'll get to composite
  111.        eventually, and it had better define them!  */
  112.  
  113.     if (wcPtr->geometry_manager == XtInheritGeometryManager) {
  114.     wcPtr->geometry_manager =
  115.         superPtr->geometry_manager;
  116.     }
  117.  
  118.     if (wcPtr->change_managed == XtInheritChangeManaged) {
  119.     wcPtr->change_managed =
  120.         superPtr->change_managed;
  121.     }
  122.  
  123.     if (wcPtr->insert_child == XtInheritInsertChild) {
  124.     wcPtr->insert_child = superPtr->insert_child;
  125.     }
  126.  
  127.     if (wcPtr->delete_child == XtInheritDeleteChild) {
  128.     wcPtr->delete_child = superPtr->delete_child;
  129.     }
  130.  
  131. }
  132.  
  133. static void CompositeDestroy(w)
  134.     CompositeWidget    w;
  135. {
  136.     XtFree((char *) w->composite.children);
  137. }
  138.  
  139. static void CompositeInsertChild(w)
  140.     Widget    w;
  141. {
  142.     register Cardinal         position;
  143.     register Cardinal        i;
  144.     register CompositeWidget cw;
  145.     register WidgetList      children;
  146.  
  147.     cw = (CompositeWidget) w->core.parent;
  148.     children = cw->composite.children;
  149.  
  150.     if (cw->composite.insert_position != NULL)
  151.     position = (*(cw->composite.insert_position))(w);
  152.     else
  153.     position = cw->composite.num_children;
  154.  
  155.     if (cw->composite.num_children == cw->composite.num_slots) {
  156.     /* Allocate more space */
  157.     cw->composite.num_slots +=  (cw->composite.num_slots / 2) + 2;
  158.     cw->composite.children = children = 
  159.         (WidgetList) XtRealloc((XtPointer) children,
  160.         (unsigned) (cw->composite.num_slots) * sizeof(Widget));
  161.     }
  162.     /* Ripple children up one space from "position" */
  163.     for (i = cw->composite.num_children; i > position; i--) {
  164.     children[i] = children[i-1];
  165.     }
  166.     children[position] = w;
  167.     cw->composite.num_children++;
  168. }
  169.  
  170. static void CompositeDeleteChild(w)
  171.     Widget    w;
  172. {
  173.     register Cardinal         position;
  174.     register Cardinal         i;
  175.     register CompositeWidget cw;
  176.  
  177.     cw = (CompositeWidget) w->core.parent;
  178.  
  179.     for (position = 0; position < cw->composite.num_children; position++) {
  180.         if (cw->composite.children[position] == w) {
  181.         break;
  182.     }
  183.     }
  184.     if (position == cw->composite.num_children) return;
  185.  
  186.     /* Ripple children down one space from "position" */
  187.     cw->composite.num_children--;
  188.     for (i = position; i < cw->composite.num_children; i++) {
  189.         cw->composite.children[i] = cw->composite.children[i+1];
  190.     }
  191. }
  192.  
  193. /* ARGSUSED */
  194. static void CompositeInitialize(requested_widget, new_widget, args, num_args)
  195.     Widget   new_widget, requested_widget;
  196.     ArgList args;
  197.     Cardinal *num_args;
  198. {
  199.     register CompositeWidget cw;
  200.  
  201.     cw = (CompositeWidget) new_widget;
  202.     cw->composite.num_children = 0;
  203.     cw->composite.children = NULL;
  204.     cw->composite.num_slots = 0;
  205. }
  206.