16c321187Smrg/* 26c321187Smrg 36c321187SmrgCopyright 1994, 1998 The Open Group 46c321187Smrg 56c321187SmrgPermission to use, copy, modify, distribute, and sell this software and its 66c321187Smrgdocumentation for any purpose is hereby granted without fee, provided that 76c321187Smrgthe above copyright notice appear in all copies and that both that 86c321187Smrgcopyright notice and this permission notice appear in supporting 96c321187Smrgdocumentation. 106c321187Smrg 116c321187SmrgThe above copyright notice and this permission notice shall be included in 126c321187Smrgall copies or substantial portions of the Software. 136c321187Smrg 146c321187SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 156c321187SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 166c321187SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 176c321187SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 186c321187SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 196c321187SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 206c321187Smrg 216c321187SmrgExcept as contained in this notice, the name of The Open Group shall not be 226c321187Smrgused in advertising or otherwise to promote the sale, use or other dealings 236c321187Smrgin this Software without prior written authorization from The Open Group. 246c321187Smrg 256c321187Smrg*/ 266c321187Smrg 276c321187Smrg/* 286c321187Smrg * XmuCvtStringToWidget 296c321187Smrg * 306c321187Smrg * static XtConvertArgRec parentCvtArgs[] = { 316c321187Smrg * {XtBaseOffset, (XtPointer)XtOffset(Widget, core.parent), sizeof(Widget)}, 326c321187Smrg * }; 336c321187Smrg * 346c321187Smrg * matches the string against the name of the immediate children (normal 356c321187Smrg * or popup) of the parent. If none match, compares string to classname 366c321187Smrg * & returns first match. Case is significant. 376c321187Smrg */ 386c321187Smrg#ifdef HAVE_CONFIG_H 396c321187Smrg#include <config.h> 406c321187Smrg#endif 416c321187Smrg#include <X11/IntrinsicP.h> 426c321187Smrg#include <X11/StringDefs.h> 436c321187Smrg#include <X11/ObjectP.h> 446c321187Smrg#include <X11/Xmu/Converters.h> 456c321187Smrg 466c321187Smrg#define done(address, type) \ 476c321187Smrg{ \ 486c321187Smrg toVal->size = sizeof(type); \ 496c321187Smrg toVal->addr = (XPointer)address; \ 506c321187Smrg return; \ 516c321187Smrg} 526c321187Smrg 536c321187Smrg/*ARGSUSED*/ 546c321187Smrgvoid 556c321187SmrgXmuCvtStringToWidget(XrmValuePtr args, Cardinal *num_args, 56198e4c3cSmrg XrmValuePtr fromVal, XrmValuePtr toVal) 576c321187Smrg{ 586c321187Smrg static Widget widget, *widgetP, parent; 596c321187Smrg XrmName name = XrmStringToName(fromVal->addr); 6093493779Smrg Cardinal i; 616c321187Smrg 62198e4c3cSmrg if (*num_args != 1) { 63198e4c3cSmrg i = 0; 64198e4c3cSmrg XtErrorMsg("wrongParameters", "cvtStringToWidget", "xtToolkitError", 65198e4c3cSmrg "StringToWidget conversion needs parent arg", NULL, &i); 666c321187Smrg } 676c321187Smrg 68198e4c3cSmrg parent = *(Widget *) args[0].addr; 696c321187Smrg /* try to match names of normal children */ 70198e4c3cSmrg if (XtIsComposite(parent)) { 71198e4c3cSmrg i = ((CompositeWidget) parent)->composite.num_children; 72198e4c3cSmrg for (widgetP = ((CompositeWidget) parent)->composite.children; 73198e4c3cSmrg i; i--, widgetP++) { 74198e4c3cSmrg if ((*widgetP)->core.xrm_name == name) { 75198e4c3cSmrg widget = *widgetP; 76198e4c3cSmrg done(&widget, Widget); 77198e4c3cSmrg } 78198e4c3cSmrg } 79198e4c3cSmrg } 806c321187Smrg 816c321187Smrg /* try to match names of popup children */ 826c321187Smrg i = parent->core.num_popups; 83198e4c3cSmrg for (widgetP = parent->core.popup_list; i; i--, widgetP++) { 84198e4c3cSmrg if ((*widgetP)->core.xrm_name == name) { 85198e4c3cSmrg widget = *widgetP; 86198e4c3cSmrg done(&widget, Widget); 87198e4c3cSmrg } 88198e4c3cSmrg } 896c321187Smrg 906c321187Smrg /* try to match classes of normal children */ 91198e4c3cSmrg if (XtIsComposite(parent)) { 92198e4c3cSmrg i = ((CompositeWidget) parent)->composite.num_children; 93198e4c3cSmrg for (widgetP = ((CompositeWidget) parent)->composite.children; 94198e4c3cSmrg i; i--, widgetP++) { 95198e4c3cSmrg if ((*widgetP)->core.widget_class->core_class.xrm_class == name) { 96198e4c3cSmrg widget = *widgetP; 97198e4c3cSmrg done(&widget, Widget); 98198e4c3cSmrg } 99198e4c3cSmrg } 100198e4c3cSmrg } 1016c321187Smrg 1026c321187Smrg /* try to match classes of popup children */ 1036c321187Smrg i = parent->core.num_popups; 104198e4c3cSmrg for (widgetP = parent->core.popup_list; i; i--, widgetP++) { 105198e4c3cSmrg if ((*widgetP)->core.widget_class->core_class.xrm_class == name) { 106198e4c3cSmrg widget = *widgetP; 107198e4c3cSmrg done(&widget, Widget); 108198e4c3cSmrg } 109198e4c3cSmrg } 1106c321187Smrg 1116c321187Smrg XtStringConversionWarning(fromVal->addr, XtRWidget); 1126c321187Smrg toVal->addr = NULL; 1136c321187Smrg toVal->size = 0; 1146c321187Smrg} 1156c321187Smrg 1166c321187Smrg#undef done 1176c321187Smrg 118198e4c3cSmrg#define newDone(type, value) \ 119198e4c3cSmrg { \ 120198e4c3cSmrg if (toVal->addr != NULL) { \ 121198e4c3cSmrg if (toVal->size < sizeof(type)) { \ 122198e4c3cSmrg toVal->size = sizeof(type); \ 123198e4c3cSmrg return False; \ 124198e4c3cSmrg } \ 125198e4c3cSmrg *(type*)(toVal->addr) = (value); \ 126198e4c3cSmrg } \ 127198e4c3cSmrg else { \ 128198e4c3cSmrg static type static_val; \ 129198e4c3cSmrg static_val = (value); \ 130198e4c3cSmrg toVal->addr = (XtPointer)&static_val; \ 131198e4c3cSmrg } \ 132198e4c3cSmrg toVal->size = sizeof(type); \ 133198e4c3cSmrg return True; \ 134198e4c3cSmrg } 1356c321187Smrg 1366c321187Smrg 1376c321187Smrg/*ARGSUSED*/ 1386c321187SmrgBoolean 1396c321187SmrgXmuNewCvtStringToWidget(Display *dpy, XrmValue *args, Cardinal *num_args, 140198e4c3cSmrg XrmValue *fromVal, XrmValue *toVal, 141198e4c3cSmrg XtPointer *converter_data) 1426c321187Smrg{ 1436c321187Smrg Widget *widgetP, parent; 1446c321187Smrg XrmName name = XrmStringToName(fromVal->addr); 1456c321187Smrg int i; 1466c321187Smrg 1476c321187Smrg if (*num_args != 1) 148198e4c3cSmrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 149198e4c3cSmrg "wrongParameters", "cvtStringToWidget", 150198e4c3cSmrg "xtToolkitError", 151198e4c3cSmrg "String To Widget conversion needs parent argument", 152198e4c3cSmrg (String *) NULL, (Cardinal *) NULL); 1536c321187Smrg 154198e4c3cSmrg parent = *(Widget *) args[0].addr; 1556c321187Smrg /* try to match names of normal children */ 156198e4c3cSmrg if (XtIsComposite(parent)) { 157198e4c3cSmrg i = ((CompositeWidget) parent)->composite.num_children; 158198e4c3cSmrg for (widgetP = ((CompositeWidget) parent)->composite.children; 159198e4c3cSmrg i; i--, widgetP++) { 160198e4c3cSmrg if ((*widgetP)->core.xrm_name == name) 161198e4c3cSmrg newDone(Widget, *widgetP); 162198e4c3cSmrg } 163198e4c3cSmrg } 1646c321187Smrg 1656c321187Smrg /* try to match names of popup children */ 1666c321187Smrg i = parent->core.num_popups; 167198e4c3cSmrg for (widgetP = parent->core.popup_list; i; i--, widgetP++) { 168198e4c3cSmrg if ((*widgetP)->core.xrm_name == name) 169198e4c3cSmrg newDone(Widget, *widgetP); 170198e4c3cSmrg } 1716c321187Smrg 1726c321187Smrg /* try to match classes of normal children */ 173198e4c3cSmrg if (XtIsComposite(parent)) { 174198e4c3cSmrg i = ((CompositeWidget) parent)->composite.num_children; 175198e4c3cSmrg for (widgetP = ((CompositeWidget) parent)->composite.children; 176198e4c3cSmrg i; i--, widgetP++) { 177198e4c3cSmrg if ((*widgetP)->core.widget_class->core_class.xrm_class == name) 178198e4c3cSmrg newDone(Widget, *widgetP); 179198e4c3cSmrg } 180198e4c3cSmrg } 1816c321187Smrg 1826c321187Smrg /* try to match classes of popup children */ 1836c321187Smrg i = parent->core.num_popups; 184198e4c3cSmrg for (widgetP = parent->core.popup_list; i; i--, widgetP++) { 185198e4c3cSmrg if ((*widgetP)->core.widget_class->core_class.xrm_class == name) 186198e4c3cSmrg newDone(Widget, *widgetP); 187198e4c3cSmrg } 1886c321187Smrg 189198e4c3cSmrg XtDisplayStringConversionWarning(dpy, (String) fromVal->addr, XtRWidget); 190198e4c3cSmrg return (False); 1916c321187Smrg} 1926c321187Smrg 1936c321187Smrg/*ARGSUSED*/ 1946c321187SmrgBoolean 1956c321187SmrgXmuCvtWidgetToString(Display *dpy, XrmValuePtr args, Cardinal *num_args, 196198e4c3cSmrg XrmValuePtr fromVal, XrmValuePtr toVal, XtPointer *data) 1976c321187Smrg{ 198198e4c3cSmrg static String buffer; 199198e4c3cSmrg Cardinal size; 200198e4c3cSmrg Widget widget; 201198e4c3cSmrg 202198e4c3cSmrg widget = *(Widget *) fromVal->addr; 203198e4c3cSmrg 204198e4c3cSmrg if (widget) 205198e4c3cSmrg buffer = XrmQuarkToString(widget->core.xrm_name); 206198e4c3cSmrg else 207198e4c3cSmrg buffer = "(null)"; 208198e4c3cSmrg 209198e4c3cSmrg size = strlen(buffer) + 1; 210198e4c3cSmrg if (toVal->addr != NULL) { 211198e4c3cSmrg if (toVal->size < size) { 212198e4c3cSmrg toVal->size = size; 213198e4c3cSmrg return (False); 214198e4c3cSmrg } 215198e4c3cSmrg strcpy((char *) toVal->addr, buffer); 216198e4c3cSmrg } 217198e4c3cSmrg else { 218198e4c3cSmrg toVal->addr = (XPointer) buffer; 2196c321187Smrg } 220198e4c3cSmrg toVal->size = sizeof(String); 2216c321187Smrg 222198e4c3cSmrg return (True); 2236c321187Smrg} 224