GetValues.c revision 1477040f
1444c061aSmrg/* $Xorg: GetValues.c,v 1.4 2001/02/09 02:03:55 xorgcvs Exp $ */
2444c061aSmrg/*LINTLIBRARY*/
3444c061aSmrg
4444c061aSmrg/***********************************************************
51477040fSmrgCopyright 1993 Sun Microsystems, Inc.  All rights reserved.
61477040fSmrg
71477040fSmrgPermission is hereby granted, free of charge, to any person obtaining a
81477040fSmrgcopy of this software and associated documentation files (the "Software"),
91477040fSmrgto deal in the Software without restriction, including without limitation
101477040fSmrgthe rights to use, copy, modify, merge, publish, distribute, sublicense,
111477040fSmrgand/or sell copies of the Software, and to permit persons to whom the
121477040fSmrgSoftware is furnished to do so, subject to the following conditions:
131477040fSmrg
141477040fSmrgThe above copyright notice and this permission notice (including the next
151477040fSmrgparagraph) shall be included in all copies or substantial portions of the
161477040fSmrgSoftware.
171477040fSmrg
181477040fSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
191477040fSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
201477040fSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
211477040fSmrgTHE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
221477040fSmrgLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
231477040fSmrgFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
241477040fSmrgDEALINGS IN THE SOFTWARE.
251477040fSmrg
261477040fSmrgCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
27444c061aSmrg
28444c061aSmrg                        All Rights Reserved
29444c061aSmrg
30444c061aSmrgPermission to use, copy, modify, and distribute this software and its
31444c061aSmrgdocumentation for any purpose and without fee is hereby granted,
32444c061aSmrgprovided that the above copyright notice appear in all copies and that
33444c061aSmrgboth that copyright notice and this permission notice appear in
341477040fSmrgsupporting documentation, and that the name of Digital not be
35444c061aSmrgused in advertising or publicity pertaining to distribution of the
36444c061aSmrgsoftware without specific, written prior permission.
37444c061aSmrg
38444c061aSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39444c061aSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40444c061aSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41444c061aSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42444c061aSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43444c061aSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
44444c061aSmrgSOFTWARE.
45444c061aSmrg
46444c061aSmrg******************************************************************/
47444c061aSmrg
48444c061aSmrg/*
49444c061aSmrg
50444c061aSmrgCopyright 1987, 1988, 1998  The Open Group
51444c061aSmrg
52444c061aSmrgPermission to use, copy, modify, distribute, and sell this software and its
53444c061aSmrgdocumentation for any purpose is hereby granted without fee, provided that
54444c061aSmrgthe above copyright notice appear in all copies and that both that
55444c061aSmrgcopyright notice and this permission notice appear in supporting
56444c061aSmrgdocumentation.
57444c061aSmrg
58444c061aSmrgThe above copyright notice and this permission notice shall be included in
59444c061aSmrgall copies or substantial portions of the Software.
60444c061aSmrg
61444c061aSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
62444c061aSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
63444c061aSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
64444c061aSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
65444c061aSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
66444c061aSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
67444c061aSmrg
68444c061aSmrgExcept as contained in this notice, the name of The Open Group shall not be
69444c061aSmrgused in advertising or otherwise to promote the sale, use or other dealings
70444c061aSmrgin this Software without prior written authorization from The Open Group.
71444c061aSmrg
72444c061aSmrg*/
73444c061aSmrg/* $XFree86: xc/lib/Xt/GetValues.c,v 1.2 2001/08/22 22:52:18 dawes Exp $ */
74444c061aSmrg
75444c061aSmrg#ifdef HAVE_CONFIG_H
76444c061aSmrg#include <config.h>
77444c061aSmrg#endif
78444c061aSmrg#include "IntrinsicI.h"
79444c061aSmrg#include "StringDefs.h"
80444c061aSmrg
81444c061aSmrgstatic int GetValues(
82444c061aSmrg  char*			base,		/* Base address to fetch values from */
83444c061aSmrg  XrmResourceList*      res,		/* The current resource values.      */
84444c061aSmrg  register Cardinal	num_resources,	/* number of items in resources      */
85444c061aSmrg  ArgList 		args,		/* The resource values requested     */
86444c061aSmrg  Cardinal		num_args)	/* number of items in arg list       */
87444c061aSmrg{
88444c061aSmrg    register ArgList		arg;
89444c061aSmrg    register Cardinal 		i;
90444c061aSmrg    register XrmName		argName;
91444c061aSmrg    register XrmResourceList*   xrmres;
92444c061aSmrg    int				translation_arg_num = -1;
93444c061aSmrg    static XrmQuark QCallback = NULLQUARK;
94444c061aSmrg    static XrmQuark QTranslationTable = NULLQUARK;
95444c061aSmrg
96444c061aSmrg    LOCK_PROCESS;
97444c061aSmrg    if (QCallback == NULLQUARK) {
98444c061aSmrg	QCallback = XrmPermStringToQuark(XtRCallback);
99444c061aSmrg	QTranslationTable = XrmPermStringToQuark(XtRTranslationTable);
100444c061aSmrg    }
101444c061aSmrg    UNLOCK_PROCESS;
102444c061aSmrg
103444c061aSmrg    /* Resource lists should be in compiled form already  */
104444c061aSmrg
105444c061aSmrg    for (arg = args ; num_args != 0; num_args--, arg++) {
106444c061aSmrg	argName = StringToName(arg->name);
107444c061aSmrg	for (xrmres = res, i = 0; i < num_resources; i++, xrmres++) {
108444c061aSmrg	    if (argName == (*xrmres)->xrm_name) {
109444c061aSmrg		/* hack; do special cases here instead of a get_values_hook
110444c061aSmrg		 * because get_values_hook looses info as to
111444c061aSmrg		 * whether arg->value == NULL for ancient compatibility
112444c061aSmrg		 * mode in _XtCopyToArg.  It helps performance, too...
113444c061aSmrg		 */
114444c061aSmrg		if ((*xrmres)->xrm_type == QCallback) {
115444c061aSmrg		    XtCallbackList callback = _XtGetCallbackList(
116444c061aSmrg			      (InternalCallbackList *)
117444c061aSmrg			      (base - (*xrmres)->xrm_offset - 1));
118444c061aSmrg		    _XtCopyToArg(
119444c061aSmrg			      (char*)&callback, &arg->value,
120444c061aSmrg			      (*xrmres)->xrm_size);
121444c061aSmrg		}
122444c061aSmrg		else if ((*xrmres)->xrm_type == QTranslationTable)
123444c061aSmrg		    translation_arg_num = (int) (arg - args);
124444c061aSmrg		else {
125444c061aSmrg		    _XtCopyToArg(
126444c061aSmrg			      base - (*xrmres)->xrm_offset - 1,
127444c061aSmrg			      &arg->value,
128444c061aSmrg			      (*xrmres)->xrm_size);
129444c061aSmrg		}
130444c061aSmrg		break;
131444c061aSmrg	    }
132444c061aSmrg	}
133444c061aSmrg    }
134444c061aSmrg    return translation_arg_num;
135444c061aSmrg} /* GetValues */
136444c061aSmrg
137444c061aSmrgstatic void CallGetValuesHook(
138444c061aSmrg    WidgetClass	  widget_class,
139444c061aSmrg    Widget	  w,
140444c061aSmrg    ArgList	  args,
141444c061aSmrg    Cardinal	  num_args)
142444c061aSmrg{
143444c061aSmrg    WidgetClass superclass;
144444c061aSmrg    XtArgsProc get_values_hook;
145444c061aSmrg
146444c061aSmrg    LOCK_PROCESS;
147444c061aSmrg    superclass = widget_class->core_class.superclass;
148444c061aSmrg    UNLOCK_PROCESS;
149444c061aSmrg    if (superclass != NULL)
150444c061aSmrg	CallGetValuesHook (superclass, w, args, num_args);
151444c061aSmrg
152444c061aSmrg    LOCK_PROCESS;
153444c061aSmrg    get_values_hook = widget_class->core_class.get_values_hook;
154444c061aSmrg    UNLOCK_PROCESS;
155444c061aSmrg    if (get_values_hook != NULL)
156444c061aSmrg	(*get_values_hook) (w, args, &num_args);
157444c061aSmrg}
158444c061aSmrg
159444c061aSmrg
160444c061aSmrg
161444c061aSmrgstatic void CallConstraintGetValuesHook(
162444c061aSmrg    WidgetClass	  widget_class,
163444c061aSmrg    Widget	  w,
164444c061aSmrg    ArgList	  args,
165444c061aSmrg    Cardinal	  num_args)
166444c061aSmrg{
167444c061aSmrg    ConstraintClassExtension ext;
168444c061aSmrg
169444c061aSmrg    LOCK_PROCESS;
170444c061aSmrg    if (widget_class->core_class.superclass
171444c061aSmrg	->core_class.class_inited & ConstraintClassFlag) {
172444c061aSmrg	CallConstraintGetValuesHook
173444c061aSmrg	    (widget_class->core_class.superclass, w, args, num_args);
174444c061aSmrg    }
175444c061aSmrg
176444c061aSmrg    for (ext = (ConstraintClassExtension)((ConstraintWidgetClass)widget_class)
177444c061aSmrg		 ->constraint_class.extension;
178444c061aSmrg	 ext != NULL && ext->record_type != NULLQUARK;
179444c061aSmrg	 ext = (ConstraintClassExtension)ext->next_extension);
180444c061aSmrg
181444c061aSmrg    if (ext != NULL) {
182444c061aSmrg	if (  ext->version == XtConstraintExtensionVersion
183444c061aSmrg	      && ext->record_size == sizeof(ConstraintClassExtensionRec)) {
184444c061aSmrg	    if (ext->get_values_hook != NULL)
185444c061aSmrg		(*(ext->get_values_hook)) (w, args, &num_args);
186444c061aSmrg	} else {
187444c061aSmrg	    String params[1];
188444c061aSmrg	    Cardinal num_params = 1;
189444c061aSmrg	    params[0] = widget_class->core_class.class_name;
190444c061aSmrg	    XtAppWarningMsg(XtWidgetToApplicationContext(w),
191444c061aSmrg		 "invalidExtension", "xtCreateWidget", XtCXtToolkitError,
192444c061aSmrg		 "widget class %s has invalid ConstraintClassExtension record",
193444c061aSmrg		 params, &num_params);
194444c061aSmrg	}
195444c061aSmrg    }
196444c061aSmrg    UNLOCK_PROCESS;
197444c061aSmrg}
198444c061aSmrg
199444c061aSmrg
200444c061aSmrgvoid XtGetValues(
201444c061aSmrg    register Widget   w,
202444c061aSmrg    register ArgList  args,
203444c061aSmrg    register Cardinal num_args)
204444c061aSmrg{
205444c061aSmrg    WidgetClass wc;
206444c061aSmrg    int targ;
207444c061aSmrg    XtAppContext app = XtWidgetToApplicationContext(w);
208444c061aSmrg
209444c061aSmrg    if (num_args == 0) return;
210444c061aSmrg    if ((args == NULL) && (num_args != 0)) {
211444c061aSmrg	XtAppErrorMsg(app,
212444c061aSmrg		"invalidArgCount","xtGetValues",XtCXtToolkitError,
213444c061aSmrg            "Argument count > 0 on NULL argument list in XtGetValues",
214444c061aSmrg              (String *)NULL, (Cardinal *)NULL);
215444c061aSmrg    }
216444c061aSmrg
217444c061aSmrg    LOCK_APP(app);
218444c061aSmrg    wc = XtClass(w);
219444c061aSmrg    LOCK_PROCESS;
220444c061aSmrg    /* Get widget values */
221444c061aSmrg    targ = GetValues((char*)w, (XrmResourceList *) wc->core_class.resources,
222444c061aSmrg	wc->core_class.num_resources, args, num_args);
223444c061aSmrg    UNLOCK_PROCESS;
224444c061aSmrg    if (targ != -1 && XtIsWidget(w)) {
225444c061aSmrg	XtTranslations translations = _XtGetTranslationValue(w);
226444c061aSmrg	_XtCopyToArg((char*)&translations, &args[targ].value,
227444c061aSmrg		     sizeof(XtTranslations));
228444c061aSmrg    }
229444c061aSmrg
230444c061aSmrg    /* Get constraint values if necessary */
231444c061aSmrg    /* constraints may be NULL if constraint_size==0 */
232444c061aSmrg    if (XtParent(w) != NULL && !XtIsShell(w) && XtIsConstraint(XtParent(w)) &&
233444c061aSmrg	w->core.constraints) {
234444c061aSmrg	ConstraintWidgetClass cwc
235444c061aSmrg	    = (ConstraintWidgetClass) XtClass(XtParent(w));
236444c061aSmrg	LOCK_PROCESS;
237444c061aSmrg	GetValues((char*)w->core.constraints,
238444c061aSmrg		  (XrmResourceList *)(cwc->constraint_class.resources),
239444c061aSmrg		  cwc->constraint_class.num_resources, args, num_args);
240444c061aSmrg	UNLOCK_PROCESS;
241444c061aSmrg    }
242444c061aSmrg    /* Notify any class procedures that we have performed get_values */
243444c061aSmrg    CallGetValuesHook(wc, w, args, num_args);
244444c061aSmrg
245444c061aSmrg    /* Notify constraint get_values if necessary */
246444c061aSmrg    if (XtParent(w) != NULL && !XtIsShell(w) && XtIsConstraint(XtParent(w)))
247444c061aSmrg	CallConstraintGetValuesHook(XtClass(XtParent(w)), w, args,num_args);
248444c061aSmrg    UNLOCK_APP(app);
249444c061aSmrg} /* XtGetValues */
250444c061aSmrg
251444c061aSmrgvoid XtGetSubvalues(
252444c061aSmrg  XtPointer	    base,           /* Base address to fetch values from */
253444c061aSmrg  XtResourceList    resources,      /* The current resource values.      */
254444c061aSmrg  Cardinal	    num_resources,  /* number of items in resources      */
255444c061aSmrg  ArgList	    args,           /* The resource values requested     */
256444c061aSmrg  Cardinal	    num_args)       /* number of items in arg list       */
257444c061aSmrg{
258444c061aSmrg    XrmResourceList* xrmres;
259444c061aSmrg    xrmres = _XtCreateIndirectionTable(resources, num_resources);
260444c061aSmrg    GetValues((char*)base, xrmres, num_resources, args, num_args);
261444c061aSmrg    XtFree((char *)xrmres);
262444c061aSmrg}
263