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