3 Copyright 1994, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
28 * XmuCvtStringToWidget
30 * static XtConvertArgRec parentCvtArgs[] = {
31 * {XtBaseOffset, (XtPointer)XtOffset(Widget, core.parent), sizeof(Widget)},
34 * matches the string against the name of the immediate children (normal
35 * or popup) of the parent. If none match, compares string to classname
36 * & returns first match. Case is significant.
41 #include <X11/IntrinsicP.h>
42 #include <X11/StringDefs.h>
43 #include <X11/ObjectP.h>
44 #include <X11/Xmu/Converters.h>
46 #define done(address, type) \
48 toVal->size = sizeof(type); \
49 toVal->addr = (XPointer)address; \
55 XmuCvtStringToWidget(XrmValuePtr args, Cardinal *num_args,
56 XrmValuePtr fromVal, XrmValuePtr toVal)
58 static Widget widget, *widgetP, parent;
59 XrmName name = XrmStringToName(fromVal->addr);
65 XtErrorMsg("wrongParameters", "cvtStringToWidget", "xtToolkitError",
66 "StringToWidget conversion needs parent arg", NULL, &i);
69 parent = *(Widget*)args[0].addr;
70 /* try to match names of normal children */
71 if (XtIsComposite(parent))
73 i = ((CompositeWidget)parent)->composite.num_children;
74 for (widgetP = ((CompositeWidget)parent)->composite.children;
76 if ((*widgetP)->core.xrm_name == name)
79 done(&widget, Widget);
83 /* try to match names of popup children */
84 i = parent->core.num_popups;
85 for (widgetP = parent->core.popup_list; i; i--, widgetP++)
86 if ((*widgetP)->core.xrm_name == name)
89 done(&widget, Widget);
92 /* try to match classes of normal children */
93 if (XtIsComposite(parent))
95 i = ((CompositeWidget)parent)->composite.num_children;
96 for (widgetP = ((CompositeWidget)parent)->composite.children;
98 if ((*widgetP)->core.widget_class->core_class.xrm_class == name)
101 done(&widget, Widget);
105 /* try to match classes of popup children */
106 i = parent->core.num_popups;
107 for (widgetP = parent->core.popup_list; i; i--, widgetP++)
108 if ((*widgetP)->core.widget_class->core_class.xrm_class == name)
111 done(&widget, Widget);
114 XtStringConversionWarning(fromVal->addr, XtRWidget);
121 #define newDone(type, value) \
123 if (toVal->addr != NULL) { \
124 if (toVal->size < sizeof(type)) { \
125 toVal->size = sizeof(type); \
128 *(type*)(toVal->addr) = (value); \
131 static type static_val; \
132 static_val = (value); \
133 toVal->addr = (XtPointer)&static_val; \
135 toVal->size = sizeof(type); \
142 XmuNewCvtStringToWidget(Display *dpy, XrmValue *args, Cardinal *num_args,
143 XrmValue *fromVal, XrmValue *toVal,
144 XtPointer *converter_data)
146 Widget *widgetP, parent;
147 XrmName name = XrmStringToName(fromVal->addr);
151 XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
152 "wrongParameters","cvtStringToWidget","xtToolkitError",
153 "String To Widget conversion needs parent argument",
154 (String *)NULL, (Cardinal *)NULL);
156 parent = *(Widget*)args[0].addr;
157 /* try to match names of normal children */
158 if (XtIsComposite(parent))
160 i = ((CompositeWidget)parent)->composite.num_children;
161 for (widgetP = ((CompositeWidget)parent)->composite.children;
163 if ((*widgetP)->core.xrm_name == name)
164 newDone(Widget, *widgetP);
167 /* try to match names of popup children */
168 i = parent->core.num_popups;
169 for (widgetP = parent->core.popup_list; i; i--, widgetP++)
170 if ((*widgetP)->core.xrm_name == name)
171 newDone(Widget, *widgetP);
173 /* try to match classes of normal children */
174 if (XtIsComposite(parent))
176 i = ((CompositeWidget)parent)->composite.num_children;
177 for (widgetP = ((CompositeWidget)parent)->composite.children;
179 if ((*widgetP)->core.widget_class->core_class.xrm_class == name)
180 newDone(Widget, *widgetP);
183 /* try to match classes of popup children */
184 i = parent->core.num_popups;
185 for (widgetP = parent->core.popup_list; i; i--, widgetP++)
186 if ((*widgetP)->core.widget_class->core_class.xrm_class == name)
187 newDone(Widget, *widgetP);
189 XtDisplayStringConversionWarning(dpy, (String)fromVal->addr, XtRWidget);
195 XmuCvtWidgetToString(Display *dpy, XrmValuePtr args, Cardinal *num_args,
196 XrmValuePtr fromVal, XrmValuePtr toVal,
199 static String buffer;
203 widget = *(Widget *)fromVal->addr;
206 buffer = XrmQuarkToString(widget->core.xrm_name);
210 size = strlen(buffer) + 1;
211 if (toVal->addr != NULL)
213 if (toVal->size < size)
218 strcpy((char *)toVal->addr, buffer);
221 toVal->addr = (XPointer)buffer;
222 toVal->size = sizeof(String);