|
Packit Service |
2b1f13 |
/*
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
Copyright 1989, 1998 The Open Group
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
Permission to use, copy, modify, distribute, and sell this software and its
|
|
Packit Service |
2b1f13 |
documentation for any purpose is hereby granted without fee, provided that
|
|
Packit Service |
2b1f13 |
the above copyright notice appear in all copies and that both that
|
|
Packit Service |
2b1f13 |
copyright notice and this permission notice appear in supporting
|
|
Packit Service |
2b1f13 |
documentation.
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
The above copyright notice and this permission notice shall be included in
|
|
Packit Service |
2b1f13 |
all copies or substantial portions of the Software.
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
Packit Service |
2b1f13 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
Packit Service |
2b1f13 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
Packit Service |
2b1f13 |
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
Packit Service |
2b1f13 |
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
Packit Service |
2b1f13 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
Except as contained in this notice, the name of The Open Group shall not be
|
|
Packit Service |
2b1f13 |
used in advertising or otherwise to promote the sale, use or other dealings
|
|
Packit Service |
2b1f13 |
in this Software without prior written authorization from The Open Group.
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
*/
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
/*
|
|
Packit Service |
2b1f13 |
* Author: Jim Fulton, MIT X Consortium
|
|
Packit Service |
2b1f13 |
*/
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
#ifdef HAVE_CONFIG_H
|
|
Packit Service |
2b1f13 |
#include <config.h>
|
|
Packit Service |
2b1f13 |
#endif
|
|
Packit Service |
2b1f13 |
#include <stdio.h>
|
|
Packit Service |
2b1f13 |
#include <stdlib.h>
|
|
Packit Service |
2b1f13 |
#include <X11/Xos.h>
|
|
Packit Service |
2b1f13 |
#include <X11/IntrinsicP.h>
|
|
Packit Service |
2b1f13 |
#include <X11/Xmu/CharSet.h>
|
|
Packit Service |
2b1f13 |
#include <X11/Xmu/WidgetNode.h>
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
/*
|
|
Packit Service |
2b1f13 |
* Prototypes
|
|
Packit Service |
2b1f13 |
*/
|
|
Packit Service |
2b1f13 |
static char *binsearch(char*, char*, int, int,
|
|
Packit Service |
2b1f13 |
int (*__compar)(_Xconst void*, _Xconst void*));
|
|
Packit Service |
2b1f13 |
static int compare_resource_entries(_Xconst void *a, _Xconst void *b);
|
|
Packit Service |
2b1f13 |
static XmuWidgetNode *find_resource(XmuWidgetNode*, char*, Bool);
|
|
Packit Service |
2b1f13 |
static void mark_resource_owner(XmuWidgetNode*);
|
|
Packit Service |
2b1f13 |
/*
|
|
Packit Service |
2b1f13 |
* Implementation
|
|
Packit Service |
2b1f13 |
*/
|
|
Packit Service |
2b1f13 |
static char *
|
|
Packit Service |
2b1f13 |
binsearch(char *key, char *base, int nelems, int elemsize,
|
|
Packit Service |
2b1f13 |
int compar(_Xconst void*, _Xconst void*))
|
|
Packit Service |
2b1f13 |
/*
|
|
Packit Service |
2b1f13 |
* key - template of object to find
|
|
Packit Service |
2b1f13 |
* base - beginning of array
|
|
Packit Service |
2b1f13 |
* nelems - number of elements in array
|
|
Packit Service |
2b1f13 |
* elemsize - sizeof an element
|
|
Packit Service |
2b1f13 |
* compar - qsort-style compare function
|
|
Packit Service |
2b1f13 |
*/
|
|
Packit Service |
2b1f13 |
{
|
|
Packit Service |
2b1f13 |
int lower = 0, upper = nelems - 1;
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
while (lower <= upper) {
|
|
Packit Service |
2b1f13 |
int middle = (lower + upper) / 2;
|
|
Packit Service |
2b1f13 |
char *p = base + middle * elemsize;
|
|
Packit Service |
2b1f13 |
int res = (*compar) (p, key);
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
if (res < 0) {
|
|
Packit Service |
2b1f13 |
lower = middle + 1;
|
|
Packit Service |
2b1f13 |
} else if (res == 0) {
|
|
Packit Service |
2b1f13 |
return p;
|
|
Packit Service |
2b1f13 |
} else {
|
|
Packit Service |
2b1f13 |
upper = middle - 1;
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
return NULL;
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
static int
|
|
Packit Service |
2b1f13 |
compare_resource_entries(register _Xconst void *a,
|
|
Packit Service |
2b1f13 |
register _Xconst void *b)
|
|
Packit Service |
2b1f13 |
{
|
|
Packit Service |
2b1f13 |
return strcmp (((_Xconst XtResource *)a)->resource_name,
|
|
Packit Service |
2b1f13 |
((_Xconst XtResource *)b)->resource_name);
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
static XmuWidgetNode *
|
|
Packit Service |
2b1f13 |
find_resource(XmuWidgetNode *node, char *name, Bool cons)
|
|
Packit Service |
2b1f13 |
{
|
|
Packit Service |
2b1f13 |
register XmuWidgetNode *sup;
|
|
Packit Service |
2b1f13 |
XtResource res;
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
#define reslist ((char *) (cons ? sup->constraints : sup->resources))
|
|
Packit Service |
2b1f13 |
#define nreslist (int) (cons ? sup->nconstraints : sup->nresources)
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
res.resource_name = name;
|
|
Packit Service |
2b1f13 |
for (sup = node->superclass;
|
|
Packit Service |
2b1f13 |
sup && (XtResourceList) binsearch ((char *) &res,
|
|
Packit Service |
2b1f13 |
reslist, nreslist,
|
|
Packit Service |
2b1f13 |
sizeof(XtResource),
|
|
Packit Service |
2b1f13 |
compare_resource_entries);
|
|
Packit Service |
2b1f13 |
node = sup, sup = sup->superclass) ;
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
#undef reslist
|
|
Packit Service |
2b1f13 |
#undef nreslist
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
return node;
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
static void
|
|
Packit Service |
2b1f13 |
mark_resource_owner(register XmuWidgetNode *node)
|
|
Packit Service |
2b1f13 |
{
|
|
Packit Service |
2b1f13 |
register Cardinal i;
|
|
Packit Service |
2b1f13 |
XtResourceList childres;
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
childres = node->resources;
|
|
Packit Service |
2b1f13 |
for (i = 0; i < node->nresources; i++, childres++) {
|
|
Packit Service |
2b1f13 |
node->resourcewn[i] = find_resource (node, childres->resource_name,
|
|
Packit Service |
2b1f13 |
False);
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
childres = node->constraints;
|
|
Packit Service |
2b1f13 |
for (i = 0; i < node->nconstraints; i++, childres++) {
|
|
Packit Service |
2b1f13 |
node->constraintwn[i] = find_resource (node, childres->resource_name,
|
|
Packit Service |
2b1f13 |
True);
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
/*
|
|
Packit Service |
2b1f13 |
* Public Interfaces
|
|
Packit Service |
2b1f13 |
*/
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
void
|
|
Packit Service |
2b1f13 |
XmuWnInitializeNodes(XmuWidgetNode *nodearray, int nnodes)
|
|
Packit Service |
2b1f13 |
{
|
|
Packit Service |
2b1f13 |
int i;
|
|
Packit Service |
2b1f13 |
XmuWidgetNode *wn;
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
/*
|
|
Packit Service |
2b1f13 |
* Assume that the node array is in alphabetic order, so we need to
|
|
Packit Service |
2b1f13 |
* search backwards to make sure that the children are listed forward.
|
|
Packit Service |
2b1f13 |
*/
|
|
Packit Service |
2b1f13 |
for (i = nnodes - 1, wn = nodearray + (nnodes - 1); i >= 0; i--, wn--) {
|
|
Packit Service |
2b1f13 |
WidgetClass superclass = XmuWnSuperclass(wn);
|
|
Packit Service |
2b1f13 |
int j;
|
|
Packit Service |
2b1f13 |
XmuWidgetNode *swn;
|
|
Packit Service |
2b1f13 |
int lablen = strlen (wn->label);
|
|
Packit Service |
2b1f13 |
int namelen = strlen (XmuWnClassname(wn));
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
wn->lowered_label = XtMalloc (lablen + namelen + 2);
|
|
Packit Service |
2b1f13 |
#if 0
|
|
Packit Service |
2b1f13 |
/* XtMalloc exits if failed */
|
|
Packit Service |
2b1f13 |
if (!wn->lowered_label) {
|
|
Packit Service |
2b1f13 |
fprintf (stderr,
|
|
Packit Service |
2b1f13 |
"%s: unable to allocate %d bytes for widget name\n",
|
|
Packit Service |
2b1f13 |
"XmuWnInitializeNodes", lablen + namelen + 2);
|
|
Packit Service |
2b1f13 |
exit (1);
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
#endif
|
|
Packit Service |
2b1f13 |
wn->lowered_classname = wn->lowered_label + (lablen + 1);
|
|
Packit Service |
2b1f13 |
XmuCopyISOLatin1Lowered (wn->lowered_label, wn->label);
|
|
Packit Service |
2b1f13 |
XmuCopyISOLatin1Lowered (wn->lowered_classname, XmuWnClassname(wn));
|
|
Packit Service |
2b1f13 |
wn->superclass = NULL;
|
|
Packit Service |
2b1f13 |
wn->have_resources = False;
|
|
Packit Service |
2b1f13 |
wn->resources = NULL;
|
|
Packit Service |
2b1f13 |
wn->resourcewn = NULL;
|
|
Packit Service |
2b1f13 |
wn->nresources = 0;
|
|
Packit Service |
2b1f13 |
wn->constraints = NULL;
|
|
Packit Service |
2b1f13 |
wn->constraintwn = NULL;
|
|
Packit Service |
2b1f13 |
wn->nconstraints = 0;
|
|
Packit Service |
2b1f13 |
wn->data = (XtPointer) NULL;
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
/*
|
|
Packit Service |
2b1f13 |
* walk up the superclass chain
|
|
Packit Service |
2b1f13 |
*/
|
|
Packit Service |
2b1f13 |
while (superclass) {
|
|
Packit Service |
2b1f13 |
for (j = 0, swn = nodearray; j < nnodes; j++, swn++) {
|
|
Packit Service |
2b1f13 |
if (superclass == XmuWnClass(swn)) {
|
|
Packit Service |
2b1f13 |
wn->superclass = swn;
|
|
Packit Service |
2b1f13 |
goto done; /* stupid C language */
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
/*
|
|
Packit Service |
2b1f13 |
* Hmm, we have a hidden superclass (such as in core in R4); just
|
|
Packit Service |
2b1f13 |
* ignore it and keep on walking
|
|
Packit Service |
2b1f13 |
*/
|
|
Packit Service |
2b1f13 |
superclass = superclass->core_class.superclass;
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
done:
|
|
Packit Service |
2b1f13 |
if (wn->superclass) {
|
|
Packit Service |
2b1f13 |
wn->siblings = wn->superclass->children;
|
|
Packit Service |
2b1f13 |
wn->superclass->children = wn;
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
return;
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
void
|
|
Packit Service |
2b1f13 |
XmuWnFetchResources(XmuWidgetNode *node, Widget toplevel,
|
|
Packit Service |
2b1f13 |
XmuWidgetNode *topnode)
|
|
Packit Service |
2b1f13 |
{
|
|
Packit Service |
2b1f13 |
Widget dummy;
|
|
Packit Service |
2b1f13 |
XmuWidgetNode *wn;
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
if (node->have_resources) return;
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
dummy = XtCreateWidget (node->label, XmuWnClass(node), toplevel,
|
|
Packit Service |
2b1f13 |
NULL, 0);
|
|
Packit Service |
2b1f13 |
if (dummy) XtDestroyWidget (dummy);
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
/*
|
|
Packit Service |
2b1f13 |
* walk up tree geting resources; since we've instantiated the widget,
|
|
Packit Service |
2b1f13 |
* we know that all of our superclasses have been initialized
|
|
Packit Service |
2b1f13 |
*/
|
|
Packit Service |
2b1f13 |
for (wn = node; wn && !wn->have_resources; wn = wn->superclass) {
|
|
Packit Service |
2b1f13 |
XtGetResourceList (XmuWnClass(wn), &wn->resources, &wn->nresources);
|
|
Packit Service |
2b1f13 |
if (wn->resources) {
|
|
Packit Service |
2b1f13 |
qsort ((char *) wn->resources, wn->nresources,
|
|
Packit Service |
2b1f13 |
sizeof(XtResource), compare_resource_entries);
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
wn->resourcewn = (XmuWidgetNode **) XtCalloc (wn->nresources,
|
|
Packit Service |
2b1f13 |
sizeof (XmuWidgetNode *));
|
|
Packit Service |
2b1f13 |
if (!wn->resourcewn) {
|
|
Packit Service |
2b1f13 |
fprintf (stderr,
|
|
Packit Service |
2b1f13 |
"%s: unable to calloc %d %ld byte widget node ptrs\n",
|
|
Packit Service |
2b1f13 |
"XmuWnFetchResources", wn->nresources,
|
|
Packit Service |
2b1f13 |
(unsigned long)sizeof (XmuWidgetNode *));
|
|
Packit Service |
2b1f13 |
exit (1);
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
XtGetConstraintResourceList (XmuWnClass(wn), &wn->constraints,
|
|
Packit Service |
2b1f13 |
&wn->nconstraints);
|
|
Packit Service |
2b1f13 |
if (wn->constraints) {
|
|
Packit Service |
2b1f13 |
qsort ((char *) wn->constraints, wn->nconstraints,
|
|
Packit Service |
2b1f13 |
sizeof(XtResource), compare_resource_entries);
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
wn->constraintwn = (XmuWidgetNode **)
|
|
Packit Service |
2b1f13 |
XtCalloc (wn->nconstraints, sizeof (XmuWidgetNode *));
|
|
Packit Service |
2b1f13 |
if (!wn->constraintwn) {
|
|
Packit Service |
2b1f13 |
fprintf (stderr,
|
|
Packit Service |
2b1f13 |
"%s: unable to calloc %d %ld byte widget node ptrs\n",
|
|
Packit Service |
2b1f13 |
"XmuWnFetchResources", wn->nconstraints,
|
|
Packit Service |
2b1f13 |
(unsigned long)sizeof (XmuWidgetNode *));
|
|
Packit Service |
2b1f13 |
exit (1);
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
wn->have_resources = True;
|
|
Packit Service |
2b1f13 |
if (wn == topnode) break;
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
/*
|
|
Packit Service |
2b1f13 |
* Walk up tree removing all resources that appear in superclass; we can
|
|
Packit Service |
2b1f13 |
* mash the resource list in place since it was copied out of widget.
|
|
Packit Service |
2b1f13 |
*/
|
|
Packit Service |
2b1f13 |
for (wn = node; wn; wn = wn->superclass) {
|
|
Packit Service |
2b1f13 |
mark_resource_owner (wn);
|
|
Packit Service |
2b1f13 |
if (wn == topnode) break;
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
return;
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
int
|
|
Packit Service |
2b1f13 |
XmuWnCountOwnedResources(XmuWidgetNode *node, XmuWidgetNode *ownernode,
|
|
Packit Service |
2b1f13 |
Bool cons)
|
|
Packit Service |
2b1f13 |
{
|
|
Packit Service |
2b1f13 |
register int i;
|
|
Packit Service |
2b1f13 |
XmuWidgetNode **wn = (cons ? node->constraintwn : node->resourcewn);
|
|
Packit Service |
2b1f13 |
int nmatches = 0;
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
for (i = (cons ? node->nconstraints : node->nresources); i > 0; i--, wn++)
|
|
Packit Service |
2b1f13 |
if (*wn == ownernode) nmatches++;
|
|
Packit Service |
2b1f13 |
return nmatches;
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
XmuWidgetNode *
|
|
Packit Service |
2b1f13 |
XmuWnNameToNode(XmuWidgetNode *nodelist, int nnodes, _Xconst char *name)
|
|
Packit Service |
2b1f13 |
{
|
|
Packit Service |
2b1f13 |
int i;
|
|
Packit Service |
2b1f13 |
XmuWidgetNode *wn;
|
|
Packit Service |
2b1f13 |
char tmp[1024];
|
|
Packit Service |
2b1f13 |
|
|
Packit Service |
2b1f13 |
XmuNCopyISOLatin1Lowered(tmp, name, sizeof(tmp));
|
|
Packit Service |
2b1f13 |
for (i = 0, wn = nodelist; i < nnodes; i++, wn++) {
|
|
Packit Service |
2b1f13 |
if (strcmp (tmp, wn->lowered_label) == 0 ||
|
|
Packit Service |
2b1f13 |
strcmp (tmp, wn->lowered_classname) == 0) {
|
|
Packit Service |
2b1f13 |
return wn;
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
}
|
|
Packit Service |
2b1f13 |
return NULL;
|
|
Packit Service |
2b1f13 |
}
|