Home | History | Annotate | Line # | Download | only in src
      1 /***********************************************************
      2 Copyright (c) 1993, Oracle and/or its affiliates.
      3 
      4 Permission is hereby granted, free of charge, to any person obtaining a
      5 copy of this software and associated documentation files (the "Software"),
      6 to deal in the Software without restriction, including without limitation
      7 the rights to use, copy, modify, merge, publish, distribute, sublicense,
      8 and/or sell copies of the Software, and to permit persons to whom the
      9 Software is furnished to do so, subject to the following conditions:
     10 
     11 The above copyright notice and this permission notice (including the next
     12 paragraph) shall be included in all copies or substantial portions of the
     13 Software.
     14 
     15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     18 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     20 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     21 DEALINGS IN THE SOFTWARE.
     22 
     23 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
     24 
     25                         All Rights Reserved
     26 
     27 Permission to use, copy, modify, and distribute this software and its
     28 documentation for any purpose and without fee is hereby granted,
     29 provided that the above copyright notice appear in all copies and that
     30 both that copyright notice and this permission notice appear in
     31 supporting documentation, and that the name of Digital not be
     32 used in advertising or publicity pertaining to distribution of the
     33 software without specific, written prior permission.
     34 
     35 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
     36 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
     37 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
     38 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
     39 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
     40 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
     41 SOFTWARE.
     42 
     43 ******************************************************************/
     44 
     45 /*
     46 
     47 Copyright 1987, 1988, 1998  The Open Group
     48 
     49 Permission to use, copy, modify, distribute, and sell this software and its
     50 documentation for any purpose is hereby granted without fee, provided that
     51 the above copyright notice appear in all copies and that both that
     52 copyright notice and this permission notice appear in supporting
     53 documentation.
     54 
     55 The above copyright notice and this permission notice shall be included in
     56 all copies or substantial portions of the Software.
     57 
     58 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     59 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     60 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
     61 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
     62 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
     63 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     64 
     65 Except as contained in this notice, the name of The Open Group shall not be
     66 used in advertising or otherwise to promote the sale, use or other dealings
     67 in this Software without prior written authorization from The Open Group.
     68 
     69 */
     70 
     71 #ifdef HAVE_CONFIG_H
     72 #include <config.h>
     73 #endif
     74 #include "IntrinsicI.h"
     75 #include "StringDefs.h"
     76 
     77 static int
     78 GetValues(char *const base,             /* Base address to fetch values from */
     79           XrmResourceList *res,         /* The current resource values.      */
     80           register Cardinal num_resources, /* number of items in resources   */
     81           ArgList args,                 /* The resource values requested     */
     82           Cardinal num_args)            /* number of items in arg list       */
     83 {
     84     register ArgList arg;
     85     register Cardinal i;
     86     register XrmName argName;
     87     register XrmResourceList *xrmres;
     88     int translation_arg_num = -1;
     89     static XrmQuark QCallback = NULLQUARK;
     90     static XrmQuark QTranslationTable = NULLQUARK;
     91 
     92     LOCK_PROCESS;
     93     if (QCallback == NULLQUARK) {
     94         QCallback = XrmPermStringToQuark(XtRCallback);
     95         QTranslationTable = XrmPermStringToQuark(XtRTranslationTable);
     96     }
     97     UNLOCK_PROCESS;
     98 
     99     /* Resource lists should be in compiled form already  */
    100 
    101     for (arg = args; num_args != 0; num_args--, arg++) {
    102         argName = StringToName(arg->name);
    103         for (xrmres = res, i = 0; i < num_resources; i++, xrmres++) {
    104             if (argName == (*xrmres)->xrm_name) {
    105                 /* hack; do special cases here instead of a get_values_hook
    106                  * because get_values_hook looses info as to
    107                  * whether arg->value == NULL for ancient compatibility
    108                  * mode in _XtCopyToArg.  It helps performance, too...
    109                  */
    110                 if ((*xrmres)->xrm_type == QCallback) {
    111                     XtCallbackList callback =
    112                         _XtGetCallbackList((InternalCallbackList *)
    113                                            (base - (*xrmres)->xrm_offset - 1));
    114 
    115                     _XtCopyToArg((char *) &callback, &arg->value,
    116                                  (*xrmres)->xrm_size);
    117                 }
    118                 else if ((*xrmres)->xrm_type == QTranslationTable)
    119                     translation_arg_num = (int) (arg - args);
    120                 else {
    121                     _XtCopyToArg(base - (*xrmres)->xrm_offset - 1,
    122                                  &arg->value, (*xrmres)->xrm_size);
    123                 }
    124                 break;
    125             }
    126         }
    127     }
    128     return translation_arg_num;
    129 }                               /* GetValues */
    130 
    131 static void
    132 CallGetValuesHook(WidgetClass widget_class,
    133                   Widget w,
    134                   ArgList args,
    135                   Cardinal num_args)
    136 {
    137     WidgetClass superclass;
    138     XtArgsProc get_values_hook;
    139 
    140     LOCK_PROCESS;
    141     superclass = widget_class->core_class.superclass;
    142     UNLOCK_PROCESS;
    143     if (superclass != NULL)
    144         CallGetValuesHook(superclass, w, args, num_args);
    145 
    146     LOCK_PROCESS;
    147     get_values_hook = widget_class->core_class.get_values_hook;
    148     UNLOCK_PROCESS;
    149     if (get_values_hook != NULL)
    150         (*get_values_hook) (w, args, &num_args);
    151 }
    152 
    153 static void
    154 CallConstraintGetValuesHook(WidgetClass widget_class,
    155                             Widget w,
    156                             ArgList args,
    157                             Cardinal num_args)
    158 {
    159     ConstraintClassExtension ext;
    160 
    161     LOCK_PROCESS;
    162     if (widget_class->core_class.superclass->core_class.
    163         class_inited & ConstraintClassFlag) {
    164         CallConstraintGetValuesHook(widget_class->core_class.superclass, w,
    165                                     args, num_args);
    166     }
    167 
    168     for (ext = (ConstraintClassExtension) ((ConstraintWidgetClass) widget_class)
    169          ->constraint_class.extension;
    170          ext != NULL && ext->record_type != NULLQUARK;
    171          ext = (ConstraintClassExtension) ext->next_extension);
    172 
    173     if (ext != NULL) {
    174         if (ext->version == XtConstraintExtensionVersion
    175             && ext->record_size == sizeof(ConstraintClassExtensionRec)) {
    176             if (ext->get_values_hook != NULL)
    177                 (*(ext->get_values_hook)) (w, args, &num_args);
    178         }
    179         else {
    180             String params[1];
    181             Cardinal num_params = 1;
    182 
    183             params[0] = widget_class->core_class.class_name;
    184             XtAppWarningMsg(XtWidgetToApplicationContext(w),
    185                             "invalidExtension", "xtCreateWidget",
    186                             XtCXtToolkitError,
    187                             "widget class %s has invalid ConstraintClassExtension record",
    188                             params, &num_params);
    189         }
    190     }
    191     UNLOCK_PROCESS;
    192 }
    193 
    194 void
    195 XtGetValues(register Widget w,
    196             register ArgList args,
    197             register Cardinal num_args)
    198 {
    199     WidgetClass wc;
    200     int targ;
    201     XtAppContext app = XtWidgetToApplicationContext(w);
    202 
    203     if (num_args == 0) {
    204         return;
    205     } else if (args == NULL) {
    206         XtAppErrorMsg(app,
    207                       "invalidArgCount", "xtGetValues", XtCXtToolkitError,
    208                       "Argument count > 0 on NULL argument list in XtGetValues",
    209                       NULL, NULL);
    210     }
    211 
    212     LOCK_APP(app);
    213     wc = XtClass(w);
    214     LOCK_PROCESS;
    215     /* Get widget values */
    216     targ = GetValues((char *) w, (XrmResourceList *) wc->core_class.resources,
    217                      wc->core_class.num_resources, args, num_args);
    218     UNLOCK_PROCESS;
    219     if (targ != -1 && XtIsWidget(w)) {
    220         XtTranslations translations = _XtGetTranslationValue(w);
    221 
    222         _XtCopyToArg((char *) &translations, &args[targ].value,
    223                      sizeof(XtTranslations));
    224     }
    225 
    226     /* Get constraint values if necessary */
    227     /* constraints may be NULL if constraint_size==0 */
    228     if (XtParent(w) != NULL && !XtIsShell(w) && XtIsConstraint(XtParent(w)) &&
    229         w->core.constraints) {
    230         ConstraintWidgetClass cwc
    231             = (ConstraintWidgetClass) XtClass(XtParent(w));
    232         LOCK_PROCESS;
    233         GetValues((char *) w->core.constraints,
    234                   (XrmResourceList *) (cwc->constraint_class.resources),
    235                   cwc->constraint_class.num_resources, args, num_args);
    236         UNLOCK_PROCESS;
    237     }
    238     /* Notify any class procedures that we have performed get_values */
    239     CallGetValuesHook(wc, w, args, num_args);
    240 
    241     /* Notify constraint get_values if necessary */
    242     if (XtParent(w) != NULL && !XtIsShell(w) && XtIsConstraint(XtParent(w)))
    243         CallConstraintGetValuesHook(XtClass(XtParent(w)), w, args, num_args);
    244     UNLOCK_APP(app);
    245 }                               /* XtGetValues */
    246 
    247 void
    248 XtGetSubvalues(XtPointer base,          /* Base address to fetch values from */
    249                XtResourceList resources,/* The current resource values.      */
    250                Cardinal num_resources,  /* number of items in resources      */
    251                ArgList args,            /* The resource values requested */
    252                Cardinal num_args)       /* number of items in arg list       */
    253 {
    254     XrmResourceList *xrmres;
    255 
    256     xrmres = _XtCreateIndirectionTable(resources, num_resources);
    257     GetValues((char *) base, xrmres, num_resources, args, num_args);
    258     XtFree((char *) xrmres);
    259 }
    260