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