1 | #include <X11/Wc/COPY_X> |
---|
2 | |
---|
3 | /* |
---|
4 | * SCCS_data: @(#) XtName.c 1.4 92/03/18 11:02:30 |
---|
5 | * |
---|
6 | * NOTE: Some old versions of Xt (including X11R4 before several patches) |
---|
7 | * do not handle Gadgets, and many do not find names with wildcards. |
---|
8 | * |
---|
9 | * Below is the code extracted from the X11R5 distribution, with very |
---|
10 | * minor changes to make it independent from the rest of the R5 Intrinsics. |
---|
11 | * |
---|
12 | * differences: changed name from XtNameToWidget to WcChildNameToWidget |
---|
13 | * Deleted gratuitous double function decl |
---|
14 | */ |
---|
15 | |
---|
16 | #include <X11/IntrinsicP.h> |
---|
17 | #include <X11/ObjectP.h> /* some machines need this */ |
---|
18 | #include <X11/StringDefs.h> |
---|
19 | |
---|
20 | #include <X11/Wc/WcCreateP.h> |
---|
21 | |
---|
22 | /*************** Begin source from X11R5 Xtos.h ***************/ |
---|
23 | |
---|
24 | #ifndef ALLOCATE_LOCAL |
---|
25 | #define ALLOCATE_LOCAL(size) XtMalloc((unsigned long)(size)) |
---|
26 | #define DEALLOCATE_LOCAL(ptr) XtFree((caddr_t)(ptr)) |
---|
27 | #endif /* ALLOCATE_LOCAL */ |
---|
28 | |
---|
29 | /*************** End source from X11R5 Xtos.h ***************/ |
---|
30 | |
---|
31 | #define _XtAllocError XtError |
---|
32 | |
---|
33 | /*************** Begin source from X11R5 lib/Xt/Intrinsics.c ***************/ |
---|
34 | /* ---------------- XtNameToWidget ----------------- */ |
---|
35 | |
---|
36 | static Widget NameListToWidget(); |
---|
37 | |
---|
38 | typedef Widget (*NameMatchProc)(); |
---|
39 | |
---|
40 | static Widget MatchExactChildren(names, bindings, children, num, |
---|
41 | in_depth, out_depth, found_depth) |
---|
42 | XrmNameList names; |
---|
43 | XrmBindingList bindings; |
---|
44 | register WidgetList children; |
---|
45 | register int num; |
---|
46 | int in_depth, *out_depth, *found_depth; |
---|
47 | { |
---|
48 | register Cardinal i; |
---|
49 | register XrmName name = *names; |
---|
50 | Widget w, result = NULL; |
---|
51 | int d, min = 10000; |
---|
52 | |
---|
53 | for (i = 0; i < num; i++) { |
---|
54 | if (name == children[i]->core.xrm_name) { |
---|
55 | w = NameListToWidget(children[i], &names[1], &bindings[1], |
---|
56 | in_depth+1, &d, found_depth); |
---|
57 | if (w != NULL && d < min) {result = w; min = d;} |
---|
58 | } |
---|
59 | } |
---|
60 | *out_depth = min; |
---|
61 | return result; |
---|
62 | } |
---|
63 | |
---|
64 | static Widget MatchWildChildren(names, bindings, children, num, |
---|
65 | in_depth, out_depth, found_depth) |
---|
66 | XrmNameList names; |
---|
67 | XrmBindingList bindings; |
---|
68 | register WidgetList children; |
---|
69 | register int num; |
---|
70 | int in_depth, *out_depth, *found_depth; |
---|
71 | { |
---|
72 | register Cardinal i; |
---|
73 | Widget w, result = NULL; |
---|
74 | int d, min = 10000; |
---|
75 | |
---|
76 | for (i = 0; i < num; i++) { |
---|
77 | w = NameListToWidget(children[i], names, bindings, |
---|
78 | in_depth+1, &d, found_depth); |
---|
79 | if (w != NULL && d < min) {result = w; min = d;} |
---|
80 | } |
---|
81 | *out_depth = min; |
---|
82 | return result; |
---|
83 | } |
---|
84 | |
---|
85 | static Widget SearchChildren(root, names, bindings, matchproc, |
---|
86 | in_depth, out_depth, found_depth) |
---|
87 | Widget root; |
---|
88 | XrmNameList names; |
---|
89 | XrmBindingList bindings; |
---|
90 | NameMatchProc matchproc; |
---|
91 | int in_depth, *out_depth, *found_depth; |
---|
92 | { |
---|
93 | Widget w1, w2; |
---|
94 | int d1, d2; |
---|
95 | |
---|
96 | if (XtIsComposite(root)) { |
---|
97 | w1 = (*matchproc)(names, bindings, |
---|
98 | ((CompositeWidget) root)->composite.children, |
---|
99 | ((CompositeWidget) root)->composite.num_children, |
---|
100 | in_depth, &d1, found_depth); |
---|
101 | } else d1 = 10000; |
---|
102 | w2 = (*matchproc)(names, bindings, root->core.popup_list, |
---|
103 | root->core.num_popups, in_depth, &d2, found_depth); |
---|
104 | *out_depth = (d1 < d2 ? d1 : d2); |
---|
105 | return (d1 < d2 ? w1 : w2); |
---|
106 | } |
---|
107 | |
---|
108 | static Widget NameListToWidget(root, names, bindings, |
---|
109 | in_depth, out_depth, found_depth) |
---|
110 | register Widget root; |
---|
111 | XrmNameList names; |
---|
112 | XrmBindingList bindings; |
---|
113 | int in_depth, *out_depth, *found_depth; |
---|
114 | { |
---|
115 | Widget w1, w2; |
---|
116 | int d1, d2; |
---|
117 | |
---|
118 | if (in_depth >= *found_depth) { |
---|
119 | *out_depth = 10000; |
---|
120 | return NULL; |
---|
121 | } |
---|
122 | |
---|
123 | if (names[0] == NULLQUARK) { |
---|
124 | *out_depth = *found_depth = in_depth; |
---|
125 | return root; |
---|
126 | } |
---|
127 | |
---|
128 | if (! XtIsWidget(root)) { |
---|
129 | *out_depth = 10000; |
---|
130 | return NULL; |
---|
131 | } |
---|
132 | |
---|
133 | if (*bindings == XrmBindTightly) { |
---|
134 | return SearchChildren(root, names, bindings, MatchExactChildren, |
---|
135 | in_depth, out_depth, found_depth); |
---|
136 | |
---|
137 | } else { /* XrmBindLoosely */ |
---|
138 | w1 = SearchChildren(root, names, bindings, MatchExactChildren, |
---|
139 | in_depth, &d1, found_depth); |
---|
140 | w2 = SearchChildren(root, names, bindings, MatchWildChildren, |
---|
141 | in_depth, &d2, found_depth); |
---|
142 | *out_depth = (d1 < d2 ? d1 : d2); |
---|
143 | return (d1 < d2 ? w1 : w2); |
---|
144 | } |
---|
145 | } /* NameListToWidget */ |
---|
146 | |
---|
147 | Widget WcChildNameToWidget(root, name) |
---|
148 | Widget root; |
---|
149 | String name; |
---|
150 | { |
---|
151 | XrmName *names; |
---|
152 | XrmBinding *bindings; |
---|
153 | int len, depth, found = 10000; |
---|
154 | Widget result; |
---|
155 | |
---|
156 | len = strlen(name); |
---|
157 | if (len == 0) return NULL; |
---|
158 | |
---|
159 | names = (XrmName *) ALLOCATE_LOCAL((unsigned) (len+1) * sizeof(XrmName)); |
---|
160 | bindings = (XrmBinding *) |
---|
161 | ALLOCATE_LOCAL((unsigned) (len+1) * sizeof(XrmBinding)); |
---|
162 | if (names == NULL || bindings == NULL) _XtAllocError(NULL); |
---|
163 | |
---|
164 | XrmStringToBindingQuarkList(name, bindings, names); |
---|
165 | if (names[0] == NULLQUARK) { |
---|
166 | DEALLOCATE_LOCAL((char *) bindings); |
---|
167 | DEALLOCATE_LOCAL((char *) names); |
---|
168 | return NULL; |
---|
169 | } |
---|
170 | |
---|
171 | result = NameListToWidget(root, names, bindings, 0, &depth, &found); |
---|
172 | |
---|
173 | DEALLOCATE_LOCAL((char *) bindings); |
---|
174 | DEALLOCATE_LOCAL((char *) names); |
---|
175 | return result; |
---|
176 | } /* XtNameToWidget */ |
---|
177 | |
---|