~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/3rdparty/qmon/Xmt310/Xmt/NameToWidget.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Motif Tools Library, Version 3.1
 
3
 * $Id$
 
4
 * 
 
5
 * Written by David Flanagan.
 
6
 * Copyright (c) 1992-2001 by David Flanagan.
 
7
 * All Rights Reserved.  See the file COPYRIGHT for details.
 
8
 * This is open source software.  See the file LICENSE for details.
 
9
 * There is no warranty for this software.  See NO_WARRANTY for details.
 
10
 *
 
11
 * $Log$
 
12
 * Revision 1.1.1.1  2001/07/18 11:06:02  root
 
13
 * Initial checkin.
 
14
 *
 
15
 * Revision 1.2  2001/06/12 16:25:28  andre
 
16
 * *** empty log message ***
 
17
 *
 
18
 *
 
19
 */
 
20
 
 
21
/*
 
22
 * Portions of this file are derived from the Xt source code.
 
23
 * See the file COPYRIGHT for the MIT and Digital copyrights.
 
24
 */
 
25
 
 
26
#include <Xmt/Xmt.h>
 
27
#include <Xmt/Util.h>    
 
28
#include <Xmt/AppRes.h>
 
29
#include <X11/IntrinsicP.h>
 
30
 
 
31
static XrmQuark selfq = NULLQUARK;
 
32
static XrmQuark questionq = NULLQUARK;
 
33
    
 
34
#if NeedFunctionPrototypes
 
35
static Widget GetParent(Widget w)
 
36
#else
 
37
static Widget GetParent(w)
 
38
Widget w;
 
39
#endif
 
40
{
 
41
    if (w == NULL) return NULL;
 
42
    if (XtParent(w) != NULL) return XtParent(w);
 
43
    else return w;
 
44
}
 
45
 
 
46
#if NeedFunctionPrototypes
 
47
static Widget GetNamedAncestor(Widget ref, char *name)
 
48
#else
 
49
static Widget GetNamedAncestor(ref, name)
 
50
Widget ref;
 
51
char *name;
 
52
#endif
 
53
{
 
54
    Widget w;
 
55
    WidgetClass c;
 
56
    XrmQuark q = XrmStringToQuark(name);
 
57
 
 
58
    if (ref == NULL) return NULL;
 
59
 
 
60
    /* see if the supplied name matches any ancestor's names */
 
61
    for(w = XtParent(ref); w != NULL; w = XtParent(w))
 
62
        if (w->core.xrm_name == q) return w;
 
63
 
 
64
    /*
 
65
     * if not, start checking classes.  Check the class name, and
 
66
     * all the superclass names of each ancestor widget.
 
67
     * This is done with WidgetClass, but should work for objects too.
 
68
     */
 
69
    for(w = XtParent(ref); w != NULL; w = XtParent(w)) 
 
70
        for(c = XtClass(w); c != NULL; c = c->core_class.superclass)
 
71
            if (c->core_class.xrm_class == q) return w;
 
72
 
 
73
    /* if no name or class matches, return NULL */
 
74
    return NULL;
 
75
}
 
76
 
 
77
#if NeedFunctionPrototypes
 
78
static Widget GetChild(Widget w, XrmName q)
 
79
#else
 
80
static Widget GetChild(w, q)
 
81
Widget w;
 
82
XrmName q;
 
83
#endif
 
84
{
 
85
    CompositeWidget parent = (CompositeWidget) w;
 
86
    int i;
 
87
 
 
88
    /*
 
89
     * Check the names of all normal children.
 
90
     * Check the names of all popup children.
 
91
     * Check the class names of all normal children.
 
92
     * Check the class names of all popup children.
 
93
     * Note that we don't check superclass names.
 
94
     */
 
95
 
 
96
    if (w == NULL) return NULL;
 
97
 
 
98
    /* normal children names */
 
99
    if (XtIsComposite(w)) {
 
100
        for(i = 0; i < parent->composite.num_children; i++)
 
101
            if (parent->composite.children[i]->core.xrm_name == q)
 
102
                return parent->composite.children[i];
 
103
    }
 
104
 
 
105
    /* popup children names */
 
106
    for(i = 0; i < w->core.num_popups; i++)
 
107
        if (w->core.popup_list[i]->core.xrm_name == q)
 
108
            return w->core.popup_list[i];
 
109
 
 
110
    /* normal children classes */
 
111
    if (XtIsComposite(w)) {
 
112
        for(i = 0; i < parent->composite.num_children; i++)
 
113
            if (XtClass(parent->composite.children[i])->core_class.xrm_class
 
114
                == q)
 
115
                return parent->composite.children[i];
 
116
    }
 
117
 
 
118
    /* popup children classes */
 
119
    for(i = 0; i < w->core.num_popups; i++)
 
120
        if (XtClass(w->core.popup_list[i])->core_class.xrm_class == q)
 
121
            return w->core.popup_list[i];
 
122
 
 
123
    /* no child matches */
 
124
    return NULL;
 
125
}
 
126
 
 
127
 
 
128
#if NeedFunctionPrototypes
 
129
static Widget ParseWidgetModifiers(Widget w, StringConst *name)
 
130
#else
 
131
static Widget ParseWidgetModifiers(w, name)
 
132
Widget w;
 
133
StringConst *name;
 
134
#endif
 
135
{
 
136
    if (*name == NULL || **name == '\0')
 
137
        return w;  /* no recursion */
 
138
    else if (**name == '.') {
 
139
        /*
 
140
         * ignore '.' if there are following modifiers, or
 
141
         * return w if no modifiers follow it.
 
142
         */
 
143
        *name += 1;
 
144
        return ParseWidgetModifiers(w, name);
 
145
    }
 
146
    else if (**name == '~') {
 
147
        *name += 1;
 
148
        return XmtGetShell(ParseWidgetModifiers(w, name));
 
149
    }
 
150
    else if (**name == '^') {
 
151
        if (*(*name+1) != '{') {
 
152
            *name += 1;
 
153
            return GetParent(ParseWidgetModifiers(w, name));
 
154
        }
 
155
        else {
 
156
            char ancestor[100];
 
157
            int i = 0;
 
158
            *name += 2;
 
159
            while (**name && **name != '}') {
 
160
                ancestor[i++] = **name;
 
161
                *name += 1;
 
162
            }
 
163
            ancestor[i] = '\0';
 
164
            if (**name == '}') *name += 1;
 
165
            return GetNamedAncestor(ParseWidgetModifiers(w, name),
 
166
                                    ancestor);
 
167
        }
 
168
    }
 
169
    else /* there are no more modifiers, so don't recurse */
 
170
        return w;
 
171
}
 
172
 
 
173
 
 
174
/*
 
175
 * The following 5 procedures are code modified from the internals
 
176
 * of the function XtNameToWidget.  This code appears in the file
 
177
 * Intrinsic.c in the MIT Xt distribution, with the following RCS info:
 
178
 * $XConsortium: Intrinsic.c,v 1.171 91/07/16 18:30:20 converse Exp $
 
179
 */
 
180
#if NeedFunctionPrototypes
 
181
static Widget NameListToWidget(register Widget root,
 
182
                               XrmNameList names, XrmBindingList bindings,
 
183
                               int num_quarks, int in_depth, int *out_depth,
 
184
                               int *found_depth);
 
185
#else
 
186
static Widget NameListToWidget();
 
187
#endif
 
188
 
 
189
typedef Widget (*NameMatchProc)();
 
190
 
 
191
#if NeedFunctionPrototypes
 
192
static Widget MatchExactChildren(XrmNameList names, XrmBindingList bindings,
 
193
                                 int num_quarks, register WidgetList children,
 
194
                                 register int num, int in_depth,
 
195
                                 int *out_depth, int *found_depth)
 
196
#else
 
197
static Widget MatchExactChildren(names, bindings, num_quarks, children, num,
 
198
                                 in_depth, out_depth, found_depth)
 
199
XrmNameList names;
 
200
XrmBindingList bindings;
 
201
int num_quarks;
 
202
register WidgetList children;
 
203
register int num;
 
204
int in_depth;
 
205
int *out_depth;
 
206
int *found_depth;
 
207
#endif
 
208
{
 
209
    register Cardinal   i;
 
210
    register XrmName    name = *names;
 
211
    Widget w, result = NULL;
 
212
    int d, min = 10000;
 
213
 
 
214
    /* check the names of children.  '?' always matches -- djf */
 
215
    for (i = 0; i < num; i++) {
 
216
        if ((name == children[i]->core.xrm_name) ||
 
217
            (name == questionq)) /* djf */ {
 
218
            w = NameListToWidget(children[i], &names[1], &bindings[1],
 
219
                                 num_quarks-1,
 
220
                                 in_depth+1, &d, found_depth);
 
221
            if (w != NULL && d < min) {result = w; min = d;}
 
222
        }
 
223
    }
 
224
 
 
225
    *out_depth = min;
 
226
    return result;
 
227
}
 
228
 
 
229
#if NeedFunctionPrototypes
 
230
static Widget MatchExactClass(XrmNameList names, XrmBindingList bindings,
 
231
                              int num_quarks, register WidgetList children,
 
232
                              register int num, int in_depth, int *out_depth,
 
233
                              int *found_depth)
 
234
#else
 
235
static Widget MatchExactClass(names, bindings, num_quarks, children, num,
 
236
                              in_depth, out_depth, found_depth)
 
237
XrmNameList names;
 
238
XrmBindingList bindings;
 
239
int num_quarks;
 
240
register WidgetList children;
 
241
register int num;
 
242
int in_depth;
 
243
int *out_depth;
 
244
int *found_depth;
 
245
#endif
 
246
{
 
247
    register Cardinal   i;
 
248
    register XrmName    name = *names;
 
249
    Widget w, result = NULL;
 
250
    int d, min = 10000;
 
251
 
 
252
    /* like the above, but check classes  -- djf */
 
253
    for (i = 0; i < num; i++) {
 
254
        if (name == XtClass(children[i])->core_class.xrm_class) {
 
255
            w = NameListToWidget(children[i], &names[1], &bindings[1],
 
256
                                 num_quarks-1,
 
257
                                 in_depth+1, &d, found_depth);
 
258
            if (w != NULL && d < min) {result = w; min = d;}
 
259
        }
 
260
    }
 
261
        
 
262
    *out_depth = min;
 
263
    return result;
 
264
}
 
265
 
 
266
 
 
267
#if NeedFunctionPrototypes
 
268
static Widget MatchWildChildren(XrmNameList names, XrmBindingList bindings,
 
269
                                int num_quarks, register WidgetList children,
 
270
                                register int num, int in_depth,
 
271
                                int *out_depth, int *found_depth)
 
272
#else
 
273
static Widget MatchWildChildren(names, bindings, num_quarks, children, num,
 
274
                                in_depth, out_depth, found_depth) 
 
275
XrmNameList names;
 
276
XrmBindingList bindings;
 
277
int num_quarks;
 
278
register WidgetList children;
 
279
register int num;
 
280
int in_depth;
 
281
int *out_depth;
 
282
int *found_depth;
 
283
#endif
 
284
{
 
285
    register Cardinal   i;
 
286
    Widget w, result = NULL;
 
287
    int d, min = 10000;
 
288
 
 
289
    for (i = 0; i < num; i++) {
 
290
        w = NameListToWidget(children[i], names, bindings, num_quarks,
 
291
                in_depth+1, &d, found_depth);
 
292
        if (w != NULL && d < min) {result = w; min = d;}
 
293
    }
 
294
    *out_depth = min;
 
295
    return result;
 
296
}
 
297
 
 
298
#if NeedFunctionPrototypes
 
299
static Widget SearchChildren(Widget root,
 
300
                             XrmNameList names, XrmBindingList bindings,
 
301
                             int num_quarks, NameMatchProc matchproc,
 
302
                             int in_depth, int *out_depth, int *found_depth)
 
303
#else
 
304
static Widget SearchChildren(root, names, bindings, num_quarks, matchproc,
 
305
                             in_depth, out_depth, found_depth)
 
306
Widget root;
 
307
XrmNameList names;
 
308
XrmBindingList bindings;
 
309
int num_quarks;
 
310
NameMatchProc matchproc;
 
311
int in_depth;
 
312
int *out_depth;
 
313
int *found_depth;
 
314
#endif
 
315
{
 
316
    Widget w1, w2;
 
317
    int d1, d2;
 
318
 
 
319
    if (XtIsComposite(root)) {
 
320
        w1 = (*matchproc)(names, bindings, num_quarks,
 
321
                ((CompositeWidget) root)->composite.children,
 
322
                ((CompositeWidget) root)->composite.num_children,
 
323
                in_depth, &d1, found_depth); 
 
324
    }
 
325
    else {
 
326
        d1 = 10000;
 
327
        w1 = NULL;
 
328
    }
 
329
    w2 = (*matchproc)(names, bindings, num_quarks, root->core.popup_list,
 
330
            root->core.num_popups, in_depth, &d2, found_depth);
 
331
    *out_depth = (d1 < d2 ? d1 : d2);
 
332
    return (d1 < d2 ? w1 : w2);
 
333
}
 
334
 
 
335
#if NeedFunctionPrototypes
 
336
static Widget NameListToWidget(register Widget root,
 
337
                               XrmNameList names, XrmBindingList bindings,
 
338
                               int num_quarks, int in_depth,
 
339
                               int *out_depth, int *found_depth)
 
340
#else
 
341
static Widget NameListToWidget(root, names, bindings, num_quarks, in_depth,
 
342
                               out_depth, found_depth) 
 
343
register Widget root;
 
344
XrmNameList names;
 
345
XrmBindingList bindings;
 
346
int num_quarks;
 
347
int in_depth;
 
348
int *out_depth;
 
349
int *found_depth;
 
350
#endif
 
351
{
 
352
    Widget w1, w2;
 
353
    int d1, d2;
 
354
 
 
355
    if (in_depth >= *found_depth) {
 
356
        *out_depth = 10000;
 
357
        return NULL;
 
358
    }
 
359
 
 
360
    if (num_quarks == 0) {
 
361
        *out_depth = *found_depth = in_depth;
 
362
        return root;
 
363
    }
 
364
 
 
365
    if (! XtIsWidget(root)) {
 
366
        *out_depth = 10000;
 
367
        return NULL;
 
368
    }
 
369
 
 
370
    if (*bindings == XrmBindTightly) {
 
371
        w1 =  SearchChildren(root, names, bindings, num_quarks,
 
372
                             MatchExactChildren,
 
373
                             in_depth, out_depth, found_depth);
 
374
        /* if no names match, look for a class name that matches -- djf */
 
375
        if (w1 == NULL) {
 
376
            w1 = SearchChildren(root, names, bindings, num_quarks,
 
377
                                MatchExactClass,
 
378
                                in_depth, out_depth, found_depth);
 
379
        }
 
380
        
 
381
        if (w1 != NULL)
 
382
            return w1;
 
383
    }
 
384
    else {  /* XrmBindLoosely */
 
385
        w1 = SearchChildren(root, names, bindings, num_quarks,
 
386
                            MatchExactChildren,
 
387
                            in_depth, &d1, found_depth);
 
388
        if (w1 == NULL) { /* if no names match exactly, check classes -- djf */
 
389
            w1 = SearchChildren(root, names, bindings, num_quarks,
 
390
                                MatchExactClass,
 
391
                                in_depth, &d1, found_depth);
 
392
        }
 
393
        w2 = SearchChildren(root, names, bindings, num_quarks,
 
394
                            MatchWildChildren,
 
395
                            in_depth, &d2, found_depth);
 
396
        *out_depth = (d1 < d2 ? d1 : d2);
 
397
        return (d1 < d2 ? w1 : w2);
 
398
    }
 
399
    /* NOTREACHED */
 
400
    return NULL;  /* but return something anyway to keep gcc -Wall quiet */
 
401
} /* NameListToWidget */
 
402
 
 
403
 
 
404
/* modified X Consortium code ends here. */
 
405
 
 
406
#if NeedFunctionPrototypes
 
407
Widget XmtNameToWidget(Widget ref, StringConst name)
 
408
#else
 
409
Widget XmtNameToWidget(ref, name)
 
410
Widget ref;
 
411
StringConst name;
 
412
#endif
 
413
{
 
414
    StringConst newname;
 
415
    Boolean modifiers = False;
 
416
    XrmQuark quark_array[50];
 
417
    XrmBinding binding_array[50];
 
418
    XrmQuarkList quarks;
 
419
    XrmBindingList bindings;
 
420
    int numquarks;
 
421
    Widget w;
 
422
    int depth = 0;
 
423
    int found = 10000;
 
424
    
 
425
    /* initialize quarks used by lots of functions */
 
426
    if (selfq == NULLQUARK) selfq = XrmStringToQuark("self");
 
427
    if (questionq == NULLQUARK) questionq = XrmStringToQuark("?");
 
428
    
 
429
    newname = name;
 
430
    /* if the name begins with a modifier, go parse them */
 
431
    if ((name[0] == '.') || (name[0] == '^') || (name[0] == '~')) {
 
432
        modifiers = True;
 
433
        ref = ParseWidgetModifiers(ref, &newname);
 
434
    }
 
435
 
 
436
    /*
 
437
     * if no name, or nothing following the modifiers,
 
438
     * then just return the reference widget.  This is
 
439
     * so names like "^^" work.
 
440
     */
 
441
    if (!newname || !*newname) return ref;
 
442
 
 
443
    /* quarkify the name and count the quarks */
 
444
    quarks = quark_array;
 
445
    bindings = binding_array;
 
446
    XrmStringToBindingQuarkList(newname, bindings, quarks);
 
447
    for(numquarks = 0; quarks[numquarks] != NULLQUARK; numquarks++);
 
448
    
 
449
    if (!modifiers) {
 
450
        /* if the name begins with '*', it is relative to the root. */
 
451
        if (name[0]== '*')
 
452
            ref = XmtGetApplicationShell(ref);
 
453
        else {
 
454
            /*
 
455
             * if first quark is 'self', skip it.
 
456
             * if first quark is a sibling of ref, ref = parent
 
457
             * otherwise if first quark doesn't name a child, maybe it
 
458
             * names a root widget.  If it doesn't name any known root,
 
459
             * it is an error.
 
460
             */
 
461
            if (quarks[0] == selfq) {
 
462
                quarks++;
 
463
                bindings++;
 
464
                numquarks--;
 
465
            }
 
466
            else if (GetChild(XtParent(ref), quarks[0]))
 
467
                ref = XtParent(ref);
 
468
            else if (!GetChild(ref, quarks[0])) {
 
469
                ref = XmtLookupApplicationShell(quarks[0]);
 
470
                if (!ref) return NULL;
 
471
                quarks++;
 
472
                bindings++;
 
473
                numquarks--;
 
474
            }
 
475
        }
 
476
    }
 
477
 
 
478
    w =  NameListToWidget(ref, quarks, bindings, numquarks,
 
479
                          0, &depth, &found);
 
480
    return w;
 
481
}
 
482