home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / Xt / GetValues.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-11  |  7.0 KB  |  197 lines

  1. /* $XConsortium: GetValues.c,v 1.10 91/05/11 20:54:55 converse Exp $ */
  2. /*LINTLIBRARY*/
  3.  
  4. /***********************************************************
  5. Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  6. and the Massachusetts Institute of Technology, Cambridge, 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 names of Digital or MIT not be
  15. used in advertising or publicity pertaining to distribution of the
  16. software without specific, written prior permission.  
  17.  
  18. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  20. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  21. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  22. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  23. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  24. SOFTWARE.
  25.  
  26. ******************************************************************/
  27.  
  28. #include "IntrinsicI.h"
  29. #include "StringDefs.h"
  30.  
  31. extern void _XtCopyToArg();
  32. extern XrmResourceList* _XtCreateIndirectionTable();
  33.  
  34. static int GetValues(base, res, num_resources, args, num_args)
  35.   char*            base;        /* Base address to fetch values from */
  36.   XrmResourceList*      res;        /* The current resource values.      */
  37.   register Cardinal    num_resources;    /* number of items in resources      */
  38.   ArgList         args;        /* The resource values requested     */
  39.   Cardinal        num_args;    /* number of items in arg list       */
  40. {
  41.     register ArgList        arg;
  42.     register int         i;
  43.     register XrmName        argName;
  44.     register XrmResourceList*   xrmres;
  45.     int                translation_arg_num = -1;
  46.     static XrmQuark QCallback = NULLQUARK;
  47.     static XrmQuark QTranslationTable = NULLQUARK;
  48.  
  49.     if (QCallback == NULLQUARK) {
  50.     QCallback = XrmPermStringToQuark(XtRCallback);
  51.     QTranslationTable = XrmPermStringToQuark(XtRTranslationTable);
  52.     }
  53.  
  54.     /* Resource lists should be in compiled form already  */
  55.  
  56.     for (arg = args ; num_args != 0; num_args--, arg++) {
  57.     argName = StringToName(arg->name);
  58.     for (xrmres = res, i = 0; i < num_resources; i++, xrmres++) {
  59.         if (argName == (*xrmres)->xrm_name) {
  60.         /* hack; do special cases here instead of a get_values_hook
  61.          * because get_values_hook looses info as to
  62.          * whether arg->value == NULL for ancient compatibility
  63.          * mode in _XtCopyToArg.  It helps performance, too...
  64.          */
  65.         if ((*xrmres)->xrm_type == QCallback) {
  66.             XtCallbackList callback = _XtGetCallbackList(
  67.                   (InternalCallbackList *)
  68.                   (base - (*xrmres)->xrm_offset - 1));
  69.             _XtCopyToArg(
  70.                   (char*)&callback, &arg->value,
  71.                   (*xrmres)->xrm_size);
  72.         }
  73.         else if ((*xrmres)->xrm_type == QTranslationTable)
  74.             translation_arg_num = (int) (arg - args);
  75.         else {
  76.             _XtCopyToArg(
  77.                   base - (*xrmres)->xrm_offset - 1,
  78.                   &arg->value,
  79.                   (*xrmres)->xrm_size);
  80.         }
  81.         break;
  82.         }
  83.     }
  84.     }
  85.     return translation_arg_num;
  86. } /* GetValues */
  87.  
  88. static void CallGetValuesHook(widget_class, w, args, num_args)
  89.     WidgetClass      widget_class;
  90.     Widget      w;
  91.     ArgList      args;
  92.     Cardinal      num_args;
  93. {
  94.     if (widget_class->core_class.superclass != NULL) {
  95.     CallGetValuesHook
  96.         (widget_class->core_class.superclass, w, args, num_args);
  97.     }
  98.     if (widget_class->core_class.get_values_hook != NULL) {
  99.     (*(widget_class->core_class.get_values_hook)) (w, args, &num_args);
  100.     }
  101. }
  102.  
  103.  
  104.  
  105. static void CallConstraintGetValuesHook(widget_class, w, args, num_args)
  106.     WidgetClass      widget_class;
  107.     Widget      w;
  108.     ArgList      args;
  109.     Cardinal      num_args;
  110. {
  111.     ConstraintClassExtension ext;
  112.  
  113.     if (widget_class->core_class.superclass
  114.     ->core_class.class_inited & ConstraintClassFlag) {
  115.     CallConstraintGetValuesHook
  116.         (widget_class->core_class.superclass, w, args, num_args);
  117.     }
  118.  
  119.     for (ext = (ConstraintClassExtension)((ConstraintWidgetClass)widget_class)
  120.          ->constraint_class.extension;
  121.      ext != NULL && ext->record_type != NULLQUARK;
  122.      ext = (ConstraintClassExtension)ext->next_extension);
  123.  
  124.     if (ext != NULL) {
  125.     if (  ext->version == XtConstraintExtensionVersion
  126.           && ext->record_size == sizeof(ConstraintClassExtensionRec)) {
  127.         if (ext->get_values_hook != NULL)
  128.         (*(ext->get_values_hook)) (w, args, &num_args);
  129.     } else {
  130.         String params[1];
  131.         Cardinal num_params = 1;
  132.         params[0] = widget_class->core_class.class_name;
  133.         XtAppWarningMsg(XtWidgetToApplicationContext(w),
  134.          "invalidExtension", "xtCreateWidget", XtCXtToolkitError,
  135.          "widget class %s has invalid ConstraintClassExtension record",
  136.          params, &num_params);
  137.     }
  138.     }
  139. }
  140.  
  141.  
  142. void XtGetValues(w, args, num_args)
  143.     register Widget   w;
  144.     register ArgList  args;
  145.     register Cardinal num_args;
  146. {
  147.     WidgetClass wc = XtClass(w);
  148.     int targ;
  149.  
  150.     if (num_args == 0) return;
  151.     if ((args == NULL) && (num_args != 0)) {
  152.     XtAppErrorMsg(XtWidgetToApplicationContext(w),
  153.         "invalidArgCount","xtGetValues",XtCXtToolkitError,
  154.             "Argument count > 0 on NULL argument list in XtGetValues",
  155.               (String *)NULL, (Cardinal *)NULL);
  156.     }
  157.  
  158.     /* Get widget values */
  159.     targ = GetValues((char*)w, (XrmResourceList *) wc->core_class.resources,
  160.     wc->core_class.num_resources, args, num_args);
  161.     if (targ != -1 && XtIsWidget(w)) {
  162.     XtTranslations translations = _XtGetTranslationValue(w);
  163.     _XtCopyToArg((char*)&translations, &args[targ].value,
  164.              sizeof(XtTranslations));
  165.     }
  166.  
  167.     /* Get constraint values if necessary */
  168.     /* assert: !XtIsShell(w) => (XtParent(w) != NULL) */
  169.     /* constraints may be NULL if constraint_size==0 */
  170.     if (!XtIsShell(w) && XtIsConstraint(XtParent(w)) && w->core.constraints) {
  171.     ConstraintWidgetClass cwc
  172.         = (ConstraintWidgetClass) XtClass(XtParent(w));
  173.     GetValues((char*)w->core.constraints, 
  174.           (XrmResourceList *)(cwc->constraint_class.resources),
  175.           cwc->constraint_class.num_resources, args, num_args);
  176.     }
  177.     /* Notify any class procedures that we have performed get_values */
  178.     CallGetValuesHook(wc, w, args, num_args);
  179.  
  180.     /* Notify constraint get_values if necessary */
  181.     if (!XtIsShell(w) && XtIsConstraint(XtParent(w)))
  182.     CallConstraintGetValuesHook(XtClass(XtParent(w)), w, args,num_args);
  183. } /* XtGetValues */
  184.  
  185. void XtGetSubvalues(base, resources, num_resources, args, num_args)
  186.   XtPointer        base;           /* Base address to fetch values from */
  187.   XtResourceList    resources;      /* The current resource values.      */
  188.   Cardinal        num_resources;  /* number of items in resources      */
  189.   ArgList        args;           /* The resource values requested     */
  190.   Cardinal        num_args;       /* number of items in arg list       */
  191. {
  192.     XrmResourceList* xrmres;
  193.     xrmres = _XtCreateIndirectionTable(resources, num_resources);
  194.     GetValues((char*)base, xrmres, num_resources, args, num_args);
  195.     XtFree((char *)xrmres);
  196. }
  197.