home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / l / libxtgeo.zip / libgeo17 / Xt / Manage.c < prev    next >
C/C++ Source or Header  |  1992-10-06  |  8KB  |  246 lines

  1. /* $XConsortium: Manage.c,v 1.25 90/12/12 14:52:32 rws 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. #include "IntrinsicI.h"
  28.  
  29. static String XtNinvalidChild = "invalidChild";
  30. static String XtNxtUnmanageChildren = "xtUnmanageChildren";
  31. static String XtNxtManageChildren = "xtManageChildren";
  32.  
  33. void XtUnmanageChildren(children, num_children)
  34.     WidgetList children;
  35.     Cardinal num_children;
  36. {
  37.     register CompositeWidget    parent;
  38.     register Widget        child;
  39.     register Cardinal        num_unique_children, i;
  40.          XtWidgetProc    change_managed;
  41.          Bool        parent_realized;
  42.  
  43.     if (num_children == 0) return;
  44.     if (children[0] == NULL) {
  45.     XtWarningMsg(XtNinvalidChild,XtNxtUnmanageChildren,XtCXtToolkitError,
  46.                   "Null child passed to XtUnmanageChildren",
  47.           (String *)NULL, (Cardinal *)NULL);
  48.     return;
  49.     }
  50.     parent = (CompositeWidget) children[0]->core.parent;
  51.     if (parent->core.being_destroyed) return;
  52.  
  53.     if (XtIsComposite((Widget) parent)) {
  54.         change_managed = ((CompositeWidgetClass) parent->core.widget_class)
  55.             ->composite_class.change_managed;
  56.     parent_realized = XtIsRealized((Widget)parent);
  57.     }
  58.  
  59.     num_unique_children = 0;
  60.     for (i = 0; i < num_children; i++) {
  61.     child = children[i];
  62.     if (child == NULL) {
  63.         XtAppWarningMsg(XtWidgetToApplicationContext((Widget)parent),
  64.           XtNinvalidChild,XtNxtUnmanageChildren,XtCXtToolkitError,
  65.                   "Null child passed to XtUnmanageChildren",
  66.           (String *)NULL, (Cardinal *)NULL);
  67.         return;
  68.     }
  69.         if ((CompositeWidget) child->core.parent != parent) {
  70.        XtAppWarningMsg(XtWidgetToApplicationContext((Widget)parent),
  71.            "ambiguousParent",XtNxtUnmanageChildren,XtCXtToolkitError,
  72.            "Not all children have same parent in XtUnmanageChildren",
  73.              (String *)NULL, (Cardinal *)NULL);
  74.     } else
  75.         if (child->core.managed) {
  76.             num_unique_children++;
  77.         child->core.managed = FALSE;
  78.             if (XtIsWidget(child)
  79.         && XtIsRealized(child)
  80.         && child->core.mapped_when_managed)
  81.                     XtUnmapWidget(child);
  82.             else
  83.         { /* RectObj child */
  84.         Widget pw = child->core.parent;
  85.         RectObj r = (RectObj) child;
  86.         while ((pw!=NULL) && (!XtIsWidget(pw))) pw = pw->core.parent;
  87.         if ((pw!=NULL) && XtIsRealized (pw))
  88.             XClearArea (XtDisplay (pw), XtWindow (pw),
  89.             r->rectangle.x, r->rectangle.y,
  90.             r->rectangle.width + (r->rectangle.border_width << 1),
  91.             r->rectangle.height + (r->rectangle.border_width << 1),
  92.             TRUE);
  93.         }
  94.  
  95.         }
  96.     }
  97.     if (num_unique_children != 0 && change_managed != NULL && parent_realized) {
  98.     (*change_managed) ((Widget)parent);
  99.     }
  100. } /* XtUnmanageChildren */
  101.  
  102.  
  103. void XtUnmanageChild(child)
  104.     Widget child;
  105. {
  106.     XtUnmanageChildren(&child, (Cardinal)1);
  107. } /* XtUnmanageChild */
  108.  
  109.  
  110. void XtManageChildren(children, num_children)
  111.     WidgetList  children;
  112.     Cardinal    num_children;
  113. {
  114. #define MAXCHILDREN 100
  115.     register CompositeWidget    parent;
  116.     register Widget        child;
  117.     register Cardinal        num_unique_children, i;
  118.          XtWidgetProc    change_managed;
  119.     register WidgetList        unique_children;
  120.          Widget        cache[MAXCHILDREN];
  121.          Bool        parent_realized;
  122.  
  123.     if (num_children == 0) return;
  124.     if (children[0] == NULL) {
  125.     XtWarningMsg(XtNinvalidChild,XtNxtManageChildren,XtCXtToolkitError,
  126.          "null child passed to XtManageChildren",
  127.      (String *)NULL, (Cardinal *)NULL);
  128.     return;
  129.     } 
  130.     parent = (CompositeWidget) children[0]->core.parent;
  131.     if (XtIsComposite((Widget) parent)) {
  132.         change_managed = ((CompositeWidgetClass) parent->core.widget_class)
  133.             ->composite_class.change_managed;
  134.     parent_realized = XtIsRealized((Widget)parent);
  135.  
  136.     } else {
  137.     XtAppErrorMsg(XtWidgetToApplicationContext((Widget)parent),
  138.         "invalidParent",XtNxtManageChildren, XtCXtToolkitError,
  139.         "Attempt to manage a child when parent is not Composite",
  140.         (String *) NULL, (Cardinal *) NULL);
  141.     }
  142.     if (parent->core.being_destroyed) return;
  143.  
  144.     /* Construct new list of children that really need to be operated upon. */
  145.     if (num_children <= MAXCHILDREN) {
  146.     unique_children = cache;
  147.     } else {
  148.     unique_children = (WidgetList) XtMalloc(num_children * sizeof(Widget));
  149.     }
  150.     num_unique_children = 0;
  151.     for (i = 0; i < num_children; i++) {
  152.     child = children[i];
  153.     if (child == NULL) {
  154.         XtAppWarningMsg(XtWidgetToApplicationContext((Widget)parent),
  155.         XtNinvalidChild,XtNxtManageChildren,XtCXtToolkitError,
  156.         "null child passed to XtManageChildren",
  157.         (String *)NULL, (Cardinal *)NULL);
  158.         if (unique_children != cache) XtFree((char *) unique_children);
  159.         return;
  160.     }
  161. #ifdef DEBUG
  162.     if (!XtIsRectObj(child)) {
  163.         String params[2];
  164.         Cardinal num_params = 2;
  165.         params[0] = XtName(child);
  166.         params[1] = child->core.widget_class->core_class.class_name;
  167.         XtAppWarningMsg(XtWidgetToApplicationContext((Widget)parent),
  168.                 "notRectObj",XtNxtManageChildren,XtCXtToolkitError,
  169.                 "child \"%s\", class %s is not a RectObj",
  170.                 params, &num_params);
  171.         continue;
  172.     }
  173. #endif /*DEBUG*/
  174.         if ((CompositeWidget) child->core.parent != parent) {
  175.         XtAppWarningMsg(XtWidgetToApplicationContext((Widget)parent),
  176.             "ambiguousParent",XtNxtManageChildren,XtCXtToolkitError,
  177.         "Not all children have same parent in XtManageChildren",
  178.         (String *)NULL, (Cardinal *)NULL);
  179.     } else if (! child->core.managed && !child->core.being_destroyed) {
  180.         unique_children[num_unique_children++] = child;
  181.         child->core.managed = TRUE;
  182.     }
  183.     }
  184.  
  185.     if (num_unique_children != 0 && parent_realized) {
  186.     /* Compute geometry of new managed set of children. */
  187.     if (change_managed != NULL) (*change_managed) ((Widget)parent);
  188.  
  189.     /* Realize each child if necessary, then map if necessary */
  190.     for (i = 0; i < num_unique_children; i++) {
  191.         child = unique_children[i];
  192.         if (XtIsWidget(child)) {
  193.         if (! XtIsRealized(child)) XtRealizeWidget(child);
  194.         if (child->core.mapped_when_managed) XtMapWidget(child);
  195.         } else { /* RectObj child */
  196.         Widget pw = child->core.parent;
  197.         RectObj r = (RectObj) child;
  198.         while ((pw!=NULL) && (!XtIsWidget(pw)))
  199.             pw = pw->core.parent;
  200.         if (pw != NULL)
  201.             XClearArea (XtDisplay (pw), XtWindow (pw),
  202.             r->rectangle.x, r->rectangle.y,
  203.             r->rectangle.width + (r->rectangle.border_width << 1),
  204.             r->rectangle.height + (r->rectangle.border_width << 1),
  205.             TRUE);
  206.             }
  207.         }
  208.     }
  209.  
  210.     if (unique_children != cache) XtFree((char *) unique_children);
  211. } /* XtManageChildren */
  212.  
  213.  
  214. void XtManageChild(child)
  215.     Widget child;
  216. {
  217.     XtManageChildren(&child, (Cardinal) 1);
  218. } /* XtManageChild */
  219.  
  220.  
  221. #if NeedFunctionPrototypes
  222. void XtSetMappedWhenManaged(
  223.     register Widget widget,
  224.     _XtBoolean        mapped_when_managed
  225.     )
  226. #else
  227. void XtSetMappedWhenManaged(widget, mapped_when_managed)
  228.     register Widget widget;
  229.     Boolean        mapped_when_managed;
  230. #endif
  231. {
  232.     if (widget->core.mapped_when_managed == mapped_when_managed) return;
  233.     widget->core.mapped_when_managed = mapped_when_managed;
  234.     if (! XtIsManaged(widget)) return;
  235.  
  236.     if (mapped_when_managed) {
  237.     /* Didn't used to be mapped when managed.        */
  238.     if (XtIsRealized(widget)) XtMapWidget(widget);
  239.     } else {
  240.     /* Used to be mapped when managed.            */
  241.     if (XtIsRealized(widget)) XtUnmapWidget(widget);
  242.     }
  243. } /* XtSetMappedWhenManaged */
  244.  
  245.  
  246.