Home | History | Annotate | Line # | Download | only in src
      1 /***********************************************************
      2 Copyright (c) 1993, Oracle and/or its affiliates.
      3 
      4 Permission is hereby granted, free of charge, to any person obtaining a
      5 copy of this software and associated documentation files (the "Software"),
      6 to deal in the Software without restriction, including without limitation
      7 the rights to use, copy, modify, merge, publish, distribute, sublicense,
      8 and/or sell copies of the Software, and to permit persons to whom the
      9 Software is furnished to do so, subject to the following conditions:
     10 
     11 The above copyright notice and this permission notice (including the next
     12 paragraph) shall be included in all copies or substantial portions of the
     13 Software.
     14 
     15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     18 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     20 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     21 DEALINGS IN THE SOFTWARE.
     22 
     23 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
     24 
     25                         All Rights Reserved
     26 
     27 Permission to use, copy, modify, and distribute this software and its
     28 documentation for any purpose and without fee is hereby granted,
     29 provided that the above copyright notice appear in all copies and that
     30 both that copyright notice and this permission notice appear in
     31 supporting documentation, and that the name of Digital not be
     32 used in advertising or publicity pertaining to distribution of the
     33 software without specific, written prior permission.
     34 
     35 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
     36 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
     37 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
     38 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
     39 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
     40 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
     41 SOFTWARE.
     42 
     43 ******************************************************************/
     44 
     45 /*
     46 
     47 Copyright 1987, 1988, 1998  The Open Group
     48 
     49 Permission to use, copy, modify, distribute, and sell this software and its
     50 documentation for any purpose is hereby granted without fee, provided that
     51 the above copyright notice appear in all copies and that both that
     52 copyright notice and this permission notice appear in supporting
     53 documentation.
     54 
     55 The above copyright notice and this permission notice shall be included in
     56 all copies or substantial portions of the Software.
     57 
     58 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     59 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     60 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
     61 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
     62 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
     63 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     64 
     65 Except as contained in this notice, the name of The Open Group shall not be
     66 used in advertising or otherwise to promote the sale, use or other dealings
     67 in this Software without prior written authorization from The Open Group.
     68 
     69 */
     70 
     71 #ifdef HAVE_CONFIG_H
     72 #include <config.h>
     73 #endif
     74 #include "IntrinsicI.h"
     75 #include "Intrinsic.h"
     76 
     77 /*
     78  * XtGetResourceList(), XtGetConstraintResourceList()
     79  */
     80 
     81 #define TOXRMQUARK(p) ((XrmQuark)(long)(p))     /* avoid LP64 warnings */
     82 
     83 void
     84 XtGetResourceList(WidgetClass widget_class,
     85                   XtResourceList *resources,
     86                   Cardinal *num_resources)
     87 {
     88     int size;
     89     register Cardinal i, dest = 0;
     90     register XtResourceList *list, dlist;
     91 
     92     LOCK_PROCESS;
     93     *resources = XtMallocArray(widget_class->core_class.num_resources,
     94                                (Cardinal) sizeof(XtResource));
     95     size = (int) (widget_class->core_class.num_resources * sizeof(XtResource));
     96 
     97     if (!widget_class->core_class.class_inited) {
     98         /* Easy case */
     99 
    100         (void) memcpy(*resources, widget_class->core_class.resources,
    101                       (size_t) size);
    102         *num_resources = widget_class->core_class.num_resources;
    103         UNLOCK_PROCESS;
    104         return;
    105     }
    106 
    107     /* Nope, it's the hard case */
    108 
    109     list = (XtResourceList *) widget_class->core_class.resources;
    110     dlist = *resources;
    111     for (i = 0; i < widget_class->core_class.num_resources; i++) {
    112         if (list[i] != NULL) {
    113             dlist[dest].resource_name = (String)
    114                 XrmQuarkToString(TOXRMQUARK(list[i]->resource_name));
    115             dlist[dest].resource_class = (String)
    116                 XrmQuarkToString(TOXRMQUARK(list[i]->resource_class));
    117             dlist[dest].resource_type = (String)
    118                 XrmQuarkToString(TOXRMQUARK(list[i]->resource_type));
    119             dlist[dest].resource_size = list[i]->resource_size;
    120             /* trust that resource_offset isn't that big */
    121             dlist[dest].resource_offset = (Cardinal)
    122                 -((int) (list[i]->resource_offset + 1));
    123             dlist[dest].default_type = (String)
    124                 XrmQuarkToString(TOXRMQUARK(list[i]->default_type));
    125             dlist[dest].default_addr = list[i]->default_addr;
    126             dest++;
    127         }
    128     }
    129     *num_resources = dest;
    130     UNLOCK_PROCESS;
    131 }
    132 
    133 static Boolean
    134 ClassIsSubclassOf(WidgetClass class, const WidgetClass superclass)
    135 {
    136     for (; class != NULL; class = class->core_class.superclass) {
    137         if (class == superclass)
    138             return True;
    139     }
    140     return False;
    141 }
    142 
    143 void
    144 XtGetConstraintResourceList(WidgetClass widget_class,
    145                             XtResourceList *resources,
    146                             Cardinal *num_resources)
    147 {
    148     int size;
    149     register Cardinal i, dest = 0;
    150     register XtResourceList *list, dlist;
    151     ConstraintWidgetClass class = (ConstraintWidgetClass) widget_class;
    152 
    153     LOCK_PROCESS;
    154     if ((class->core_class.class_inited &&
    155          !(class->core_class.class_inited & ConstraintClassFlag))
    156         || (!class->core_class.class_inited &&
    157             !ClassIsSubclassOf(widget_class, constraintWidgetClass))
    158         || class->constraint_class.num_resources == 0) {
    159 
    160         *resources = NULL;
    161         *num_resources = 0;
    162         UNLOCK_PROCESS;
    163         return;
    164     }
    165 
    166     *resources = XtMallocArray(class->constraint_class.num_resources,
    167                                (Cardinal) sizeof(XtResource));
    168     size = (int) (class->constraint_class.num_resources * sizeof(XtResource));
    169 
    170     if (!class->core_class.class_inited) {
    171         /* Easy case */
    172 
    173         (void) memcpy(*resources, class->constraint_class.resources,
    174                       (size_t) size);
    175         *num_resources = class->constraint_class.num_resources;
    176         UNLOCK_PROCESS;
    177         return;
    178     }
    179 
    180     /* Nope, it's the hard case */
    181 
    182     list = (XtResourceList *) class->constraint_class.resources;
    183     dlist = *resources;
    184     for (i = 0; i < class->constraint_class.num_resources; i++) {
    185         if (list[i] != NULL) {
    186             dlist[dest].resource_name = (String)
    187                 XrmQuarkToString(TOXRMQUARK(list[i]->resource_name));
    188             dlist[dest].resource_class = (String)
    189                 XrmQuarkToString(TOXRMQUARK(list[i]->resource_class));
    190             dlist[dest].resource_type = (String)
    191                 XrmQuarkToString(TOXRMQUARK(list[i]->resource_type));
    192             dlist[dest].resource_size = list[i]->resource_size;
    193             /* trust that resource_offset isn't that big */
    194             dlist[dest].resource_offset = (Cardinal)
    195                 -((int) (list[i]->resource_offset + 1));
    196             dlist[dest].default_type = (String)
    197                 XrmQuarkToString(TOXRMQUARK(list[i]->default_type));
    198             dlist[dest].default_addr = list[i]->default_addr;
    199             dest++;
    200         }
    201     }
    202     *num_resources = dest;
    203     UNLOCK_PROCESS;
    204 }
    205