GetResList.c revision 249c3046
1444c061aSmrg/*********************************************************** 2249c3046SmrgCopyright (c) 1993, Oracle and/or its affiliates. All rights reserved. 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 "Intrinsic.h" 76444c061aSmrg 77444c061aSmrg/* 78444c061aSmrg * XtGetResourceList(), XtGetConstraintResourceList() 79444c061aSmrg */ 80444c061aSmrg 81444c061aSmrg#define TOXRMQUARK(p) ((XrmQuark)(long)(p)) /* avoid LP64 warnings */ 82444c061aSmrg 83444c061aSmrgvoid XtGetResourceList( 84444c061aSmrg WidgetClass widget_class, 85444c061aSmrg XtResourceList *resources, 86444c061aSmrg Cardinal *num_resources) 87444c061aSmrg{ 88444c061aSmrg int size; 89444c061aSmrg register Cardinal i, dest = 0; 90444c061aSmrg register XtResourceList *list, dlist; 91444c061aSmrg 92444c061aSmrg LOCK_PROCESS; 93444c061aSmrg size = widget_class->core_class.num_resources * sizeof(XtResource); 94444c061aSmrg *resources = (XtResourceList) __XtMalloc((unsigned) size); 95444c061aSmrg 96444c061aSmrg if (!widget_class->core_class.class_inited) { 97444c061aSmrg /* Easy case */ 98444c061aSmrg 99444c061aSmrg (void) memmove((char *) *resources, 100444c061aSmrg (char *)widget_class->core_class.resources, size); 101444c061aSmrg *num_resources = widget_class->core_class.num_resources; 102444c061aSmrg UNLOCK_PROCESS; 103444c061aSmrg return; 104444c061aSmrg } 105444c061aSmrg 106444c061aSmrg /* Nope, it's the hard case */ 107444c061aSmrg 108444c061aSmrg list = (XtResourceList *) widget_class->core_class.resources; 109444c061aSmrg dlist = *resources; 110444c061aSmrg for (i = 0; i < widget_class->core_class.num_resources; i++) { 111444c061aSmrg if (list[i] != NULL) { 112444c061aSmrg dlist[dest].resource_name = (String) 113444c061aSmrg XrmQuarkToString(TOXRMQUARK(list[i]->resource_name)); 114444c061aSmrg dlist[dest].resource_class = (String) 115444c061aSmrg XrmQuarkToString(TOXRMQUARK(list[i]->resource_class)); 116444c061aSmrg dlist[dest].resource_type = (String) 117444c061aSmrg XrmQuarkToString(TOXRMQUARK(list[i]->resource_type)); 118444c061aSmrg dlist[dest].resource_size = list[i]->resource_size; 119444c061aSmrg /* trust that resource_offset isn't that big */ 120444c061aSmrg dlist[dest].resource_offset = (Cardinal) 121444c061aSmrg -((int)(list[i]->resource_offset + 1)); 122444c061aSmrg dlist[dest].default_type = (String) 123444c061aSmrg XrmQuarkToString(TOXRMQUARK(list[i]->default_type)); 124444c061aSmrg dlist[dest].default_addr = list[i]->default_addr; 125444c061aSmrg dest++; 126444c061aSmrg } 127444c061aSmrg } 128444c061aSmrg *num_resources = dest; 129444c061aSmrg UNLOCK_PROCESS; 130444c061aSmrg} 131444c061aSmrg 132444c061aSmrg 133444c061aSmrgstatic Boolean ClassIsSubclassOf(WidgetClass class, WidgetClass superclass) 134444c061aSmrg{ 135444c061aSmrg for (; class != NULL; class = class->core_class.superclass) { 136444c061aSmrg if (class == superclass) return True; 137444c061aSmrg } 138444c061aSmrg return False; 139444c061aSmrg} 140444c061aSmrg 141444c061aSmrgvoid XtGetConstraintResourceList( 142444c061aSmrg WidgetClass widget_class, 143444c061aSmrg XtResourceList *resources, 144444c061aSmrg Cardinal *num_resources) 145444c061aSmrg{ 146444c061aSmrg int size; 147444c061aSmrg register Cardinal i, dest = 0; 148444c061aSmrg register XtResourceList *list, dlist; 149444c061aSmrg ConstraintWidgetClass class = (ConstraintWidgetClass)widget_class; 150444c061aSmrg 151444c061aSmrg LOCK_PROCESS; 152444c061aSmrg if ( (class->core_class.class_inited && 153444c061aSmrg !(class->core_class.class_inited & ConstraintClassFlag)) 154444c061aSmrg || (!class->core_class.class_inited && 155444c061aSmrg !ClassIsSubclassOf(widget_class, constraintWidgetClass)) 156444c061aSmrg || class->constraint_class.num_resources == 0) { 157444c061aSmrg 158444c061aSmrg *resources = NULL; 159444c061aSmrg *num_resources = 0; 160444c061aSmrg UNLOCK_PROCESS; 161444c061aSmrg return; 162444c061aSmrg } 163444c061aSmrg 164444c061aSmrg size = class->constraint_class.num_resources * sizeof(XtResource); 165444c061aSmrg *resources = (XtResourceList) __XtMalloc((unsigned) size); 166444c061aSmrg 167444c061aSmrg if (!class->core_class.class_inited) { 168444c061aSmrg /* Easy case */ 169444c061aSmrg 170444c061aSmrg (void) memmove((char *) *resources, 171444c061aSmrg (char *)class->constraint_class.resources, size); 172444c061aSmrg *num_resources = class->constraint_class.num_resources; 173444c061aSmrg UNLOCK_PROCESS; 174444c061aSmrg return; 175444c061aSmrg } 176444c061aSmrg 177444c061aSmrg /* Nope, it's the hard case */ 178444c061aSmrg 179444c061aSmrg list = (XtResourceList *) class->constraint_class.resources; 180444c061aSmrg dlist = *resources; 181444c061aSmrg for (i = 0; i < class->constraint_class.num_resources; i++) { 182444c061aSmrg if (list[i] != NULL) { 183444c061aSmrg dlist[dest].resource_name = (String) 184444c061aSmrg XrmQuarkToString(TOXRMQUARK(list[i]->resource_name)); 185444c061aSmrg dlist[dest].resource_class = (String) 186444c061aSmrg XrmQuarkToString(TOXRMQUARK(list[i]->resource_class)); 187444c061aSmrg dlist[dest].resource_type = (String) 188444c061aSmrg XrmQuarkToString(TOXRMQUARK(list[i]->resource_type)); 189444c061aSmrg dlist[dest].resource_size = list[i]->resource_size; 190444c061aSmrg /* trust that resource_offset isn't that big */ 191444c061aSmrg dlist[dest].resource_offset = (Cardinal) 192444c061aSmrg -((int)(list[i]->resource_offset + 1)); 193444c061aSmrg dlist[dest].default_type = (String) 194444c061aSmrg XrmQuarkToString(TOXRMQUARK(list[i]->default_type)); 195444c061aSmrg dlist[dest].default_addr = list[i]->default_addr; 196444c061aSmrg dest++; 197444c061aSmrg } 198444c061aSmrg } 199444c061aSmrg *num_resources = dest; 200444c061aSmrg UNLOCK_PROCESS; 201444c061aSmrg} 202