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 / SetValues.c < prev    next >
C/C++ Source or Header  |  1992-10-06  |  12KB  |  314 lines

  1. /* $XConsortium: SetValues.c,v 1.15 92/05/22 09:50:27 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. #include "StringDefs.h"
  29.  
  30. /*
  31.  *    XtSetValues(), XtSetSubvalues()
  32.  */
  33.  
  34.  
  35. extern void _XtCopyFromArg();
  36. extern XrmResourceList* _XtCreateIndirectionTable();
  37.  
  38. static void SetValues(base, res, num_resources, args, num_args)
  39.   char*            base;        /* Base address to write values to   */
  40.   XrmResourceList*    res;        /* The current resource values.      */
  41.   register Cardinal    num_resources;    /* number of items in resources      */
  42.   ArgList         args;        /* The resource values to set        */
  43.   Cardinal        num_args;    /* number of items in arg list       */
  44. {
  45.     register ArgList        arg;
  46.     register int             i;
  47.     register XrmName        argName;
  48.     register XrmResourceList*   xrmres;
  49.  
  50.     /* Resource lists are assumed to be in compiled form already via the
  51.        initial XtGetResources, XtGetSubresources calls */
  52.  
  53.     for (arg = args ; num_args != 0; num_args--, arg++) {
  54.     argName = StringToName(arg->name);
  55.     for (xrmres = res, i = 0; i < num_resources; i++, xrmres++) {
  56.         if (argName == (*xrmres)->xrm_name) {
  57.         _XtCopyFromArg(arg->value,
  58.             base - (*xrmres)->xrm_offset - 1,
  59.             (*xrmres)->xrm_size);
  60.         break;
  61.         }
  62.     }
  63.     }
  64. } /* SetValues */
  65.  
  66. static Boolean CallSetValues (class, current, request, new, args, num_args)
  67.     WidgetClass class;
  68.     Widget      current, request, new;
  69.     ArgList     args;
  70.     Cardinal    num_args;
  71. {
  72.     Boolean redisplay = FALSE;
  73.  
  74.     if (class->core_class.superclass != NULL)
  75.         redisplay = CallSetValues(
  76.       class->core_class.superclass, current, request, new, args, num_args);
  77.     if (class->core_class.set_values != NULL)
  78.         redisplay |= (*class->core_class.
  79.               set_values) (current, request, new, args, &num_args);
  80.     if (class->core_class.set_values_hook != NULL)
  81.     redisplay |=
  82.         (*class->core_class.set_values_hook) (new, args, &num_args);
  83.     return (redisplay);
  84. }
  85.  
  86. static Boolean
  87. CallConstraintSetValues (class, current, request, new, args, num_args)
  88.     ConstraintWidgetClass class;
  89.     Widget      current, request, new;
  90.     ArgList     args;
  91.     Cardinal    num_args;
  92. {
  93.     Boolean redisplay = FALSE;
  94.  
  95.     if ((WidgetClass)class != constraintWidgetClass) {
  96.     if (class == NULL)
  97.         XtAppErrorMsg(XtWidgetToApplicationContext(current),
  98.             "invalidClass","constraintSetValue",XtCXtToolkitError,
  99.                  "Subclass of Constraint required in CallConstraintSetValues",
  100.                   (String *)NULL, (Cardinal *)NULL);
  101.     redisplay = CallConstraintSetValues(
  102.         (ConstraintWidgetClass) (class->core_class.superclass),
  103.         current, request, new, args, num_args);
  104.     }
  105.     if (class->constraint_class.set_values != NULL)
  106.         redisplay |= (*class->constraint_class.
  107.               set_values) (current, request, new, args, &num_args);
  108.     return (redisplay);
  109. }
  110.  
  111. void XtSetSubvalues(base, resources, num_resources, args, num_args)
  112.   XtPointer             base;           /* Base address to write values to   */
  113.   register XtResourceList resources;    /* The current resource values.      */
  114.   register Cardinal     num_resources;  /* number of items in resources      */
  115.   ArgList               args;           /* The resource values to set        */
  116.   Cardinal              num_args;       /* number of items in arg list       */
  117. {
  118.       register XrmResourceList*   xrmres;
  119.       xrmres = _XtCreateIndirectionTable (resources, num_resources);
  120.       SetValues((char*)base,xrmres,num_resources, args, num_args);
  121.       XtFree((char *)xrmres);
  122. }
  123.  
  124.  
  125. void XtSetValues(w, args, num_args)
  126.     register Widget   w;
  127.          ArgList  args;
  128.          Cardinal num_args;
  129. {
  130.     register Widget oldw, reqw;
  131.     /* need to use strictest alignment rules possible in next two decls. */
  132.     double        oldwCache[100], reqwCache[100];
  133.     double        oldcCache[20], reqcCache[20];
  134.     Cardinal        widgetSize, constraintSize;
  135.     Boolean        redisplay, cleared_rect_obj = False;
  136.     XtGeometryResult result;
  137.     XtWidgetGeometry geoReq, geoReply;
  138.     WidgetClass     wc = XtClass(w);
  139.     ConstraintWidgetClass cwc;
  140.     Boolean        hasConstraints;
  141.  
  142.     if ((args == NULL) && (num_args != 0)) {
  143.         XtAppErrorMsg(XtWidgetToApplicationContext(w),
  144.         "invalidArgCount","xtSetValues",XtCXtToolkitError,
  145.                 "Argument count > 0 on NULL argument list in XtSetValues",
  146.                  (String *)NULL, (Cardinal *)NULL);
  147.     }
  148.  
  149.     /* Allocate and copy current widget into old widget */
  150.  
  151.     widgetSize = wc->core_class.widget_size;
  152.     oldw = (Widget) XtStackAlloc(widgetSize, oldwCache);
  153.     reqw = (Widget) XtStackAlloc (widgetSize, reqwCache);
  154.     bcopy((char *) w, (char *) oldw, (int) widgetSize);
  155.  
  156.     /* Set resource values */
  157.  
  158.     SetValues((char*)w, (XrmResourceList *) wc->core_class.resources,
  159.     wc->core_class.num_resources, args, num_args);
  160.  
  161.     bcopy ((char *) w, (char *) reqw, (int) widgetSize);
  162.  
  163.     /* assert: !XtIsShell(w) => (XtParent(w) != NULL) */
  164.     hasConstraints = (!XtIsShell(w) && XtIsConstraint(XtParent(w)));
  165.  
  166.     /* Some widget sets apparently do ugly things by freeing the
  167.      * constraints on some children, thus the extra test here */
  168.     if (hasConstraints) {
  169.     cwc = (ConstraintWidgetClass) XtClass(w->core.parent);
  170.     if (w->core.constraints)
  171.         constraintSize = cwc->constraint_class.constraint_size;
  172.     else constraintSize = 0;
  173.     } else constraintSize = 0;
  174.     
  175.     if (constraintSize) {
  176.     /* Allocate and copy current constraints into oldw */
  177.     oldw->core.constraints = XtStackAlloc(constraintSize, oldcCache);
  178.     reqw->core.constraints = XtStackAlloc(constraintSize, reqcCache);
  179.     bcopy((char *) w->core.constraints, 
  180.         (char *) oldw->core.constraints, (int) constraintSize);
  181.  
  182.     /* Set constraint values */
  183.     SetValues((char*)w->core.constraints,
  184.         (XrmResourceList *)(cwc->constraint_class.resources),
  185.         cwc->constraint_class.num_resources, args, num_args);
  186.     bcopy((char *) w->core.constraints,
  187.           (char *) reqw->core.constraints, (int) constraintSize);
  188.     }
  189.  
  190.     /* Inform widget of changes, then inform parent of changes */
  191.     redisplay = CallSetValues (wc, oldw, reqw, w, args, num_args);
  192.     if (hasConstraints) {
  193.     redisplay |= CallConstraintSetValues(cwc, oldw, reqw, w, args, num_args);
  194.     }
  195.  
  196.     if (XtIsRectObj(w)) {
  197.     /* Now perform geometry request if needed */
  198.     geoReq.request_mode = 0;
  199.     if (oldw->core.x    != w->core.x) {
  200.         geoReq.x        = w->core.x;
  201.         w->core.x        = oldw->core.x;
  202.         geoReq.request_mode |= CWX;
  203.     }
  204.     if (oldw->core.y    != w->core.y) {
  205.         geoReq.y        = w->core.y;
  206.         w->core.y        = oldw->core.y;
  207.         geoReq.request_mode |= CWY;
  208.     }
  209.     if (oldw->core.width    != w->core.width) {
  210.         geoReq.width    = w->core.width;
  211.         w->core.width    = oldw->core.width;
  212.         geoReq.request_mode |= CWWidth;
  213.     }
  214.     if (oldw->core.height    != w->core.height) {
  215.         geoReq.height    = w->core.height;
  216.         w->core.height    = oldw->core.height;
  217.         geoReq.request_mode |= CWHeight;
  218.     }
  219.     if (oldw->core.border_width != w->core.border_width) {
  220.         geoReq.border_width        = w->core.border_width;
  221.         w->core.border_width    = oldw->core.border_width;
  222.         geoReq.request_mode        |= CWBorderWidth;
  223.     }
  224.     
  225.     if (geoReq.request_mode != 0) {
  226.         /* Pass on any requests for unchanged geometry values */
  227.         if (geoReq.request_mode !=
  228.         (CWX | CWY | CWWidth | CWHeight | CWBorderWidth)) {
  229.         for ( ; num_args != 0; num_args--, args++) {
  230.             if (! (geoReq.request_mode & CWX) &&
  231.             strcmp(XtNx, args->name) == 0) {
  232.             geoReq.x = w->core.x;
  233.             geoReq.request_mode |= CWX;
  234.             } else if (! (geoReq.request_mode & CWY) &&
  235.                    strcmp(XtNy, args->name) == 0) {
  236.             geoReq.y = w->core.y;
  237.             geoReq.request_mode |= CWY;
  238.             } else if (! (geoReq.request_mode & CWWidth) &&
  239.                    strcmp(XtNwidth, args->name) == 0) {
  240.             geoReq.width = w->core.width;
  241.             geoReq.request_mode |= CWWidth;
  242.             } else if (! (geoReq.request_mode & CWHeight) &&
  243.                    strcmp(XtNheight, args->name) == 0) {
  244.             geoReq.height = w->core.height;
  245.             geoReq.request_mode |= CWHeight;
  246.             } else if (! (geoReq.request_mode & CWBorderWidth) &&
  247.                    strcmp(XtNborderWidth, args->name) == 0) {
  248.             geoReq.border_width = w->core.border_width;
  249.             geoReq.request_mode |= CWBorderWidth;
  250.             }
  251.         }
  252.         }
  253.         do {
  254.         result = _XtMakeGeometryRequest(w, &geoReq, &geoReply, 
  255.                         &cleared_rect_obj);
  256.         if (result == XtGeometryYes || result == XtGeometryDone)
  257.             break;
  258.  
  259.         /* An Almost or No reply.  Call widget and let it munge
  260.            request, reply */
  261.         if (wc->core_class.set_values_almost == NULL) {
  262.             XtAppWarningMsg(XtWidgetToApplicationContext(w),
  263.                 "invalidProcedure","set_values_almost",
  264.               XtCXtToolkitError,
  265.               "set_values_almost procedure shouldn't be NULL",
  266.               (String *)NULL, (Cardinal *)NULL);
  267.             break;
  268.         }
  269.         if (result == XtGeometryNo) geoReply.request_mode = 0;
  270.         (*(wc->core_class.set_values_almost))
  271.             (oldw, w, &geoReq, &geoReply);
  272.         } while (geoReq.request_mode != 0);
  273.         /* call resize proc if we changed size and parent
  274.          * didn't already invoke resize */
  275.         if ((w->core.width != oldw->core.width ||
  276.          w->core.height != oldw->core.height)
  277.         && result != XtGeometryDone
  278.         && wc->core_class.resize != (XtWidgetProc) NULL) {
  279.         (*(wc->core_class.resize))(w);
  280.         }
  281.     }
  282.     /* Redisplay if needed.  No point in clearing if the window is
  283.      * about to disappear, as the Expose event will just go straight
  284.      * to the bit bucket. */
  285.         if (XtIsWidget(w)) {
  286.             /* widgets can distinguish between redisplay and resize, since
  287.              the server will cause an expose on resize */
  288.             if (redisplay && XtIsRealized(w) && !w->core.being_destroyed)
  289.                 XClearArea (XtDisplay(w), XtWindow(w), 0, 0, 0, 0, TRUE);
  290.         } else { /*non-window object */
  291.       if (redisplay && ! cleared_rect_obj ) {
  292.           Widget pw = _XtWindowedAncestor(w);
  293.           if (XtIsRealized(pw) && !pw->core.being_destroyed) {
  294.           RectObj r = (RectObj)w;
  295.           int bw2 = r->rectangle.border_width << 1;
  296.           XClearArea (XtDisplay (pw), XtWindow (pw),
  297.               r->rectangle.x, r->rectangle.y,
  298.               r->rectangle.width + bw2,r->rectangle.height + bw2,TRUE);
  299.           }
  300.       }
  301.         }
  302.     }
  303.  
  304.  
  305.     /* Free dynamic storage */
  306.     if (constraintSize) {
  307.         XtStackFree(oldw->core.constraints, oldcCache);
  308.         XtStackFree(reqw->core.constraints, reqcCache);
  309.     }
  310.     XtStackFree((XtPointer)oldw, oldwCache);
  311.     XtStackFree((XtPointer)reqw, reqwCache);
  312.  
  313. } /* XtSetValues */
  314.