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