1444c061aSmrg/***********************************************************
2fdf6a26fSmrgCopyright (c) 1993, Oracle and/or its affiliates.
31477040fSmrg
41477040fSmrgPermission is hereby granted, free of charge, to any person obtaining a
51477040fSmrgcopy of this software and associated documentation files (the "Software"),
61477040fSmrgto deal in the Software without restriction, including without limitation
71477040fSmrgthe rights to use, copy, modify, merge, publish, distribute, sublicense,
81477040fSmrgand/or sell copies of the Software, and to permit persons to whom the
91477040fSmrgSoftware is furnished to do so, subject to the following conditions:
101477040fSmrg
111477040fSmrgThe above copyright notice and this permission notice (including the next
121477040fSmrgparagraph) shall be included in all copies or substantial portions of the
131477040fSmrgSoftware.
141477040fSmrg
151477040fSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
161477040fSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
171477040fSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
181477040fSmrgTHE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
191477040fSmrgLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
201477040fSmrgFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
211477040fSmrgDEALINGS IN THE SOFTWARE.
221477040fSmrg
231477040fSmrgCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
24444c061aSmrg
25444c061aSmrg                        All Rights Reserved
26444c061aSmrg
27444c061aSmrgPermission to use, copy, modify, and distribute this software and its
28444c061aSmrgdocumentation for any purpose and without fee is hereby granted,
29444c061aSmrgprovided that the above copyright notice appear in all copies and that
30444c061aSmrgboth that copyright notice and this permission notice appear in
311477040fSmrgsupporting documentation, and that the name of Digital not be
32444c061aSmrgused in advertising or publicity pertaining to distribution of the
33444c061aSmrgsoftware without specific, written prior permission.
34444c061aSmrg
35444c061aSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
36444c061aSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
37444c061aSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
38444c061aSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
39444c061aSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
40444c061aSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
41444c061aSmrgSOFTWARE.
42444c061aSmrg
43444c061aSmrg******************************************************************/
44444c061aSmrg
45444c061aSmrg/*
46444c061aSmrg
47444c061aSmrgCopyright 1987, 1988, 1998  The Open Group
48444c061aSmrg
49444c061aSmrgPermission to use, copy, modify, distribute, and sell this software and its
50444c061aSmrgdocumentation for any purpose is hereby granted without fee, provided that
51444c061aSmrgthe above copyright notice appear in all copies and that both that
52444c061aSmrgcopyright notice and this permission notice appear in supporting
53444c061aSmrgdocumentation.
54444c061aSmrg
55444c061aSmrgThe above copyright notice and this permission notice shall be included in
56444c061aSmrgall copies or substantial portions of the Software.
57444c061aSmrg
58444c061aSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59444c061aSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60444c061aSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
61444c061aSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
62444c061aSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
63444c061aSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
64444c061aSmrg
65444c061aSmrgExcept as contained in this notice, the name of The Open Group shall not be
66444c061aSmrgused in advertising or otherwise to promote the sale, use or other dealings
67444c061aSmrgin this Software without prior written authorization from The Open Group.
68444c061aSmrg
69444c061aSmrg*/
70444c061aSmrg
71444c061aSmrg#ifdef HAVE_CONFIG_H
72444c061aSmrg#include <config.h>
73444c061aSmrg#endif
74444c061aSmrg#include "IntrinsicI.h"
75444c061aSmrg#include "StringDefs.h"
76444c061aSmrg
77a3bd7f05Smrgstatic int
78fdf6a26fSmrgGetValues(char *const base,             /* Base address to fetch values from */
79fdf6a26fSmrg          XrmResourceList *res,         /* The current resource values.      */
80a3bd7f05Smrg          register Cardinal num_resources, /* number of items in resources   */
81a3bd7f05Smrg          ArgList args,                 /* The resource values requested     */
82a3bd7f05Smrg          Cardinal num_args)            /* number of items in arg list       */
83a3bd7f05Smrg{
84a3bd7f05Smrg    register ArgList arg;
85a3bd7f05Smrg    register Cardinal i;
86a3bd7f05Smrg    register XrmName argName;
87a3bd7f05Smrg    register XrmResourceList *xrmres;
88a3bd7f05Smrg    int translation_arg_num = -1;
89444c061aSmrg    static XrmQuark QCallback = NULLQUARK;
90444c061aSmrg    static XrmQuark QTranslationTable = NULLQUARK;
91444c061aSmrg
92444c061aSmrg    LOCK_PROCESS;
93444c061aSmrg    if (QCallback == NULLQUARK) {
94a3bd7f05Smrg        QCallback = XrmPermStringToQuark(XtRCallback);
95a3bd7f05Smrg        QTranslationTable = XrmPermStringToQuark(XtRTranslationTable);
96444c061aSmrg    }
97444c061aSmrg    UNLOCK_PROCESS;
98444c061aSmrg
99444c061aSmrg    /* Resource lists should be in compiled form already  */
100444c061aSmrg
101a3bd7f05Smrg    for (arg = args; num_args != 0; num_args--, arg++) {
102a3bd7f05Smrg        argName = StringToName(arg->name);
103a3bd7f05Smrg        for (xrmres = res, i = 0; i < num_resources; i++, xrmres++) {
104a3bd7f05Smrg            if (argName == (*xrmres)->xrm_name) {
105a3bd7f05Smrg                /* hack; do special cases here instead of a get_values_hook
106a3bd7f05Smrg                 * because get_values_hook looses info as to
107a3bd7f05Smrg                 * whether arg->value == NULL for ancient compatibility
108a3bd7f05Smrg                 * mode in _XtCopyToArg.  It helps performance, too...
109a3bd7f05Smrg                 */
110a3bd7f05Smrg                if ((*xrmres)->xrm_type == QCallback) {
111a3bd7f05Smrg                    XtCallbackList callback =
112a3bd7f05Smrg                        _XtGetCallbackList((InternalCallbackList *)
113a3bd7f05Smrg                                           (base - (*xrmres)->xrm_offset - 1));
114a3bd7f05Smrg
115a3bd7f05Smrg                    _XtCopyToArg((char *) &callback, &arg->value,
116a3bd7f05Smrg                                 (*xrmres)->xrm_size);
117a3bd7f05Smrg                }
118a3bd7f05Smrg                else if ((*xrmres)->xrm_type == QTranslationTable)
119a3bd7f05Smrg                    translation_arg_num = (int) (arg - args);
120a3bd7f05Smrg                else {
121a3bd7f05Smrg                    _XtCopyToArg(base - (*xrmres)->xrm_offset - 1,
122a3bd7f05Smrg                                 &arg->value, (*xrmres)->xrm_size);
123a3bd7f05Smrg                }
124a3bd7f05Smrg                break;
125a3bd7f05Smrg            }
126a3bd7f05Smrg        }
127444c061aSmrg    }
128444c061aSmrg    return translation_arg_num;
129a3bd7f05Smrg}                               /* GetValues */
130444c061aSmrg
131a3bd7f05Smrgstatic void
132a3bd7f05SmrgCallGetValuesHook(WidgetClass widget_class,
133a3bd7f05Smrg                  Widget w,
134a3bd7f05Smrg                  ArgList args,
135a3bd7f05Smrg                  Cardinal num_args)
136444c061aSmrg{
137444c061aSmrg    WidgetClass superclass;
138444c061aSmrg    XtArgsProc get_values_hook;
139444c061aSmrg
140444c061aSmrg    LOCK_PROCESS;
141444c061aSmrg    superclass = widget_class->core_class.superclass;
142444c061aSmrg    UNLOCK_PROCESS;
143444c061aSmrg    if (superclass != NULL)
144a3bd7f05Smrg        CallGetValuesHook(superclass, w, args, num_args);
145444c061aSmrg
146444c061aSmrg    LOCK_PROCESS;
147444c061aSmrg    get_values_hook = widget_class->core_class.get_values_hook;
148444c061aSmrg    UNLOCK_PROCESS;
149444c061aSmrg    if (get_values_hook != NULL)
150a3bd7f05Smrg        (*get_values_hook) (w, args, &num_args);
151444c061aSmrg}
152444c061aSmrg
153a3bd7f05Smrgstatic void
154a3bd7f05SmrgCallConstraintGetValuesHook(WidgetClass widget_class,
155a3bd7f05Smrg                            Widget w,
156a3bd7f05Smrg                            ArgList args,
157a3bd7f05Smrg                            Cardinal num_args)
158444c061aSmrg{
159444c061aSmrg    ConstraintClassExtension ext;
160444c061aSmrg
161444c061aSmrg    LOCK_PROCESS;
162a3bd7f05Smrg    if (widget_class->core_class.superclass->core_class.
163a3bd7f05Smrg        class_inited & ConstraintClassFlag) {
164a3bd7f05Smrg        CallConstraintGetValuesHook(widget_class->core_class.superclass, w,
165a3bd7f05Smrg                                    args, num_args);
166444c061aSmrg    }
167444c061aSmrg
168a3bd7f05Smrg    for (ext = (ConstraintClassExtension) ((ConstraintWidgetClass) widget_class)
169a3bd7f05Smrg         ->constraint_class.extension;
170a3bd7f05Smrg         ext != NULL && ext->record_type != NULLQUARK;
171a3bd7f05Smrg         ext = (ConstraintClassExtension) ext->next_extension);
172444c061aSmrg
173444c061aSmrg    if (ext != NULL) {
174a3bd7f05Smrg        if (ext->version == XtConstraintExtensionVersion
175a3bd7f05Smrg            && ext->record_size == sizeof(ConstraintClassExtensionRec)) {
176a3bd7f05Smrg            if (ext->get_values_hook != NULL)
177a3bd7f05Smrg                (*(ext->get_values_hook)) (w, args, &num_args);
178a3bd7f05Smrg        }
179a3bd7f05Smrg        else {
180a3bd7f05Smrg            String params[1];
181a3bd7f05Smrg            Cardinal num_params = 1;
182a3bd7f05Smrg
183a3bd7f05Smrg            params[0] = widget_class->core_class.class_name;
184a3bd7f05Smrg            XtAppWarningMsg(XtWidgetToApplicationContext(w),
185a3bd7f05Smrg                            "invalidExtension", "xtCreateWidget",
186a3bd7f05Smrg                            XtCXtToolkitError,
187a3bd7f05Smrg                            "widget class %s has invalid ConstraintClassExtension record",
188a3bd7f05Smrg                            params, &num_params);
189a3bd7f05Smrg        }
190444c061aSmrg    }
191444c061aSmrg    UNLOCK_PROCESS;
192444c061aSmrg}
193444c061aSmrg
194a3bd7f05Smrgvoid
195a3bd7f05SmrgXtGetValues(register Widget w,
196a3bd7f05Smrg            register ArgList args,
197a3bd7f05Smrg            register Cardinal num_args)
198444c061aSmrg{
199444c061aSmrg    WidgetClass wc;
200444c061aSmrg    int targ;
201444c061aSmrg    XtAppContext app = XtWidgetToApplicationContext(w);
202444c061aSmrg
203fdf6a26fSmrg    if (num_args == 0) {
204a3bd7f05Smrg        return;
205fdf6a26fSmrg    } else if (args == NULL) {
206a3bd7f05Smrg        XtAppErrorMsg(app,
207a3bd7f05Smrg                      "invalidArgCount", "xtGetValues", XtCXtToolkitError,
208a3bd7f05Smrg                      "Argument count > 0 on NULL argument list in XtGetValues",
209a3bd7f05Smrg                      NULL, NULL);
210444c061aSmrg    }
211444c061aSmrg
212444c061aSmrg    LOCK_APP(app);
213444c061aSmrg    wc = XtClass(w);
214444c061aSmrg    LOCK_PROCESS;
215444c061aSmrg    /* Get widget values */
216a3bd7f05Smrg    targ = GetValues((char *) w, (XrmResourceList *) wc->core_class.resources,
217a3bd7f05Smrg                     wc->core_class.num_resources, args, num_args);
218444c061aSmrg    UNLOCK_PROCESS;
219444c061aSmrg    if (targ != -1 && XtIsWidget(w)) {
220a3bd7f05Smrg        XtTranslations translations = _XtGetTranslationValue(w);
221a3bd7f05Smrg
222a3bd7f05Smrg        _XtCopyToArg((char *) &translations, &args[targ].value,
223a3bd7f05Smrg                     sizeof(XtTranslations));
224444c061aSmrg    }
225444c061aSmrg
226444c061aSmrg    /* Get constraint values if necessary */
227444c061aSmrg    /* constraints may be NULL if constraint_size==0 */
228444c061aSmrg    if (XtParent(w) != NULL && !XtIsShell(w) && XtIsConstraint(XtParent(w)) &&
229a3bd7f05Smrg        w->core.constraints) {
230a3bd7f05Smrg        ConstraintWidgetClass cwc
231a3bd7f05Smrg            = (ConstraintWidgetClass) XtClass(XtParent(w));
232a3bd7f05Smrg        LOCK_PROCESS;
233a3bd7f05Smrg        GetValues((char *) w->core.constraints,
234a3bd7f05Smrg                  (XrmResourceList *) (cwc->constraint_class.resources),
235a3bd7f05Smrg                  cwc->constraint_class.num_resources, args, num_args);
236a3bd7f05Smrg        UNLOCK_PROCESS;
237444c061aSmrg    }
238444c061aSmrg    /* Notify any class procedures that we have performed get_values */
239444c061aSmrg    CallGetValuesHook(wc, w, args, num_args);
240444c061aSmrg
241444c061aSmrg    /* Notify constraint get_values if necessary */
242444c061aSmrg    if (XtParent(w) != NULL && !XtIsShell(w) && XtIsConstraint(XtParent(w)))
243a3bd7f05Smrg        CallConstraintGetValuesHook(XtClass(XtParent(w)), w, args, num_args);
244444c061aSmrg    UNLOCK_APP(app);
245a3bd7f05Smrg}                               /* XtGetValues */
246a3bd7f05Smrg
247a3bd7f05Smrgvoid
248a3bd7f05SmrgXtGetSubvalues(XtPointer base,          /* Base address to fetch values from */
249a3bd7f05Smrg               XtResourceList resources,/* The current resource values.      */
250a3bd7f05Smrg               Cardinal num_resources,  /* number of items in resources      */
251a3bd7f05Smrg               ArgList args,            /* The resource values requested */
252a3bd7f05Smrg               Cardinal num_args)       /* number of items in arg list       */
253444c061aSmrg{
254a3bd7f05Smrg    XrmResourceList *xrmres;
255a3bd7f05Smrg
256444c061aSmrg    xrmres = _XtCreateIndirectionTable(resources, num_resources);
257a3bd7f05Smrg    GetValues((char *) base, xrmres, num_resources, args, num_args);
258a3bd7f05Smrg    XtFree((char *) xrmres);
259444c061aSmrg}
260