1444c061aSmrg/*********************************************************** 2fdf6a26fSmrgCopyright (c) 1993, Oracle and/or its affiliates. 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 81a3bd7f05Smrg#define TOXRMQUARK(p) ((XrmQuark)(long)(p)) /* avoid LP64 warnings */ 82444c061aSmrg 83a3bd7f05Smrgvoid 84a3bd7f05SmrgXtGetResourceList(WidgetClass widget_class, 85a3bd7f05Smrg XtResourceList *resources, 86a3bd7f05Smrg Cardinal *num_resources) 87444c061aSmrg{ 88a3bd7f05Smrg int size; 89a3bd7f05Smrg register Cardinal i, dest = 0; 90a3bd7f05Smrg register XtResourceList *list, dlist; 91a3bd7f05Smrg 92a3bd7f05Smrg LOCK_PROCESS; 93fdf6a26fSmrg *resources = XtMallocArray(widget_class->core_class.num_resources, 94fdf6a26fSmrg (Cardinal) sizeof(XtResource)); 95a3bd7f05Smrg size = (int) (widget_class->core_class.num_resources * sizeof(XtResource)); 96a3bd7f05Smrg 97a3bd7f05Smrg if (!widget_class->core_class.class_inited) { 98a3bd7f05Smrg /* Easy case */ 99a3bd7f05Smrg 100fdf6a26fSmrg (void) memcpy(*resources, widget_class->core_class.resources, 101fdf6a26fSmrg (size_t) size); 102a3bd7f05Smrg *num_resources = widget_class->core_class.num_resources; 103a3bd7f05Smrg UNLOCK_PROCESS; 104a3bd7f05Smrg return; 105a3bd7f05Smrg } 106444c061aSmrg 107a3bd7f05Smrg /* Nope, it's the hard case */ 108a3bd7f05Smrg 109a3bd7f05Smrg list = (XtResourceList *) widget_class->core_class.resources; 110a3bd7f05Smrg dlist = *resources; 111a3bd7f05Smrg for (i = 0; i < widget_class->core_class.num_resources; i++) { 112a3bd7f05Smrg if (list[i] != NULL) { 113a3bd7f05Smrg dlist[dest].resource_name = (String) 114a3bd7f05Smrg XrmQuarkToString(TOXRMQUARK(list[i]->resource_name)); 115a3bd7f05Smrg dlist[dest].resource_class = (String) 116a3bd7f05Smrg XrmQuarkToString(TOXRMQUARK(list[i]->resource_class)); 117a3bd7f05Smrg dlist[dest].resource_type = (String) 118a3bd7f05Smrg XrmQuarkToString(TOXRMQUARK(list[i]->resource_type)); 119a3bd7f05Smrg dlist[dest].resource_size = list[i]->resource_size; 120a3bd7f05Smrg /* trust that resource_offset isn't that big */ 121a3bd7f05Smrg dlist[dest].resource_offset = (Cardinal) 122a3bd7f05Smrg -((int) (list[i]->resource_offset + 1)); 123a3bd7f05Smrg dlist[dest].default_type = (String) 124a3bd7f05Smrg XrmQuarkToString(TOXRMQUARK(list[i]->default_type)); 125a3bd7f05Smrg dlist[dest].default_addr = list[i]->default_addr; 126a3bd7f05Smrg dest++; 127a3bd7f05Smrg } 128a3bd7f05Smrg } 129a3bd7f05Smrg *num_resources = dest; 130a3bd7f05Smrg UNLOCK_PROCESS; 131a3bd7f05Smrg} 132444c061aSmrg 133a3bd7f05Smrgstatic Boolean 134fdf6a26fSmrgClassIsSubclassOf(WidgetClass class, const WidgetClass superclass) 135444c061aSmrg{ 136444c061aSmrg for (; class != NULL; class = class->core_class.superclass) { 137a3bd7f05Smrg if (class == superclass) 138a3bd7f05Smrg return True; 139444c061aSmrg } 140444c061aSmrg return False; 141444c061aSmrg} 142444c061aSmrg 143a3bd7f05Smrgvoid 144a3bd7f05SmrgXtGetConstraintResourceList(WidgetClass widget_class, 145a3bd7f05Smrg XtResourceList *resources, 146a3bd7f05Smrg Cardinal *num_resources) 147444c061aSmrg{ 148a3bd7f05Smrg int size; 149a3bd7f05Smrg register Cardinal i, dest = 0; 150a3bd7f05Smrg register XtResourceList *list, dlist; 151a3bd7f05Smrg ConstraintWidgetClass class = (ConstraintWidgetClass) widget_class; 152a3bd7f05Smrg 153a3bd7f05Smrg LOCK_PROCESS; 154a3bd7f05Smrg if ((class->core_class.class_inited && 155a3bd7f05Smrg !(class->core_class.class_inited & ConstraintClassFlag)) 156a3bd7f05Smrg || (!class->core_class.class_inited && 157a3bd7f05Smrg !ClassIsSubclassOf(widget_class, constraintWidgetClass)) 158a3bd7f05Smrg || class->constraint_class.num_resources == 0) { 159a3bd7f05Smrg 160a3bd7f05Smrg *resources = NULL; 161a3bd7f05Smrg *num_resources = 0; 162a3bd7f05Smrg UNLOCK_PROCESS; 163a3bd7f05Smrg return; 164a3bd7f05Smrg } 165a3bd7f05Smrg 166fdf6a26fSmrg *resources = XtMallocArray(class->constraint_class.num_resources, 167fdf6a26fSmrg (Cardinal) sizeof(XtResource)); 168a3bd7f05Smrg size = (int) (class->constraint_class.num_resources * sizeof(XtResource)); 169a3bd7f05Smrg 170a3bd7f05Smrg if (!class->core_class.class_inited) { 171a3bd7f05Smrg /* Easy case */ 172a3bd7f05Smrg 173fdf6a26fSmrg (void) memcpy(*resources, class->constraint_class.resources, 174fdf6a26fSmrg (size_t) size); 175a3bd7f05Smrg *num_resources = class->constraint_class.num_resources; 176a3bd7f05Smrg UNLOCK_PROCESS; 177a3bd7f05Smrg return; 178a3bd7f05Smrg } 179a3bd7f05Smrg 180a3bd7f05Smrg /* Nope, it's the hard case */ 181a3bd7f05Smrg 182a3bd7f05Smrg list = (XtResourceList *) class->constraint_class.resources; 183a3bd7f05Smrg dlist = *resources; 184a3bd7f05Smrg for (i = 0; i < class->constraint_class.num_resources; i++) { 185a3bd7f05Smrg if (list[i] != NULL) { 186a3bd7f05Smrg dlist[dest].resource_name = (String) 187a3bd7f05Smrg XrmQuarkToString(TOXRMQUARK(list[i]->resource_name)); 188a3bd7f05Smrg dlist[dest].resource_class = (String) 189a3bd7f05Smrg XrmQuarkToString(TOXRMQUARK(list[i]->resource_class)); 190a3bd7f05Smrg dlist[dest].resource_type = (String) 191a3bd7f05Smrg XrmQuarkToString(TOXRMQUARK(list[i]->resource_type)); 192a3bd7f05Smrg dlist[dest].resource_size = list[i]->resource_size; 193a3bd7f05Smrg /* trust that resource_offset isn't that big */ 194a3bd7f05Smrg dlist[dest].resource_offset = (Cardinal) 195a3bd7f05Smrg -((int) (list[i]->resource_offset + 1)); 196a3bd7f05Smrg dlist[dest].default_type = (String) 197a3bd7f05Smrg XrmQuarkToString(TOXRMQUARK(list[i]->default_type)); 198a3bd7f05Smrg dlist[dest].default_addr = list[i]->default_addr; 199a3bd7f05Smrg dest++; 200a3bd7f05Smrg } 201a3bd7f05Smrg } 202a3bd7f05Smrg *num_resources = dest; 203a3bd7f05Smrg UNLOCK_PROCESS; 204444c061aSmrg} 205