StrToWidg.c revision 6c321187
16c321187Smrg/* $Xorg: StrToWidg.c,v 1.4 2001/02/09 02:03:53 xorgcvs Exp $ */ 26c321187Smrg 36c321187Smrg/* 46c321187Smrg 56c321187SmrgCopyright 1994, 1998 The Open Group 66c321187Smrg 76c321187SmrgPermission to use, copy, modify, distribute, and sell this software and its 86c321187Smrgdocumentation for any purpose is hereby granted without fee, provided that 96c321187Smrgthe above copyright notice appear in all copies and that both that 106c321187Smrgcopyright notice and this permission notice appear in supporting 116c321187Smrgdocumentation. 126c321187Smrg 136c321187SmrgThe above copyright notice and this permission notice shall be included in 146c321187Smrgall copies or substantial portions of the Software. 156c321187Smrg 166c321187SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 176c321187SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 186c321187SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 196c321187SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 206c321187SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 216c321187SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 226c321187Smrg 236c321187SmrgExcept as contained in this notice, the name of The Open Group shall not be 246c321187Smrgused in advertising or otherwise to promote the sale, use or other dealings 256c321187Smrgin this Software without prior written authorization from The Open Group. 266c321187Smrg 276c321187Smrg*/ 286c321187Smrg/* $XFree86: xc/lib/Xmu/StrToWidg.c,v 1.6 2001/01/17 19:42:57 dawes Exp $ */ 296c321187Smrg 306c321187Smrg/* 316c321187Smrg * XmuCvtStringToWidget 326c321187Smrg * 336c321187Smrg * static XtConvertArgRec parentCvtArgs[] = { 346c321187Smrg * {XtBaseOffset, (XtPointer)XtOffset(Widget, core.parent), sizeof(Widget)}, 356c321187Smrg * }; 366c321187Smrg * 376c321187Smrg * matches the string against the name of the immediate children (normal 386c321187Smrg * or popup) of the parent. If none match, compares string to classname 396c321187Smrg * & returns first match. Case is significant. 406c321187Smrg */ 416c321187Smrg#ifdef HAVE_CONFIG_H 426c321187Smrg#include <config.h> 436c321187Smrg#endif 446c321187Smrg#include <X11/IntrinsicP.h> 456c321187Smrg#include <X11/StringDefs.h> 466c321187Smrg#include <X11/ObjectP.h> 476c321187Smrg#include <X11/Xmu/Converters.h> 486c321187Smrg 496c321187Smrg#define done(address, type) \ 506c321187Smrg{ \ 516c321187Smrg toVal->size = sizeof(type); \ 526c321187Smrg toVal->addr = (XPointer)address; \ 536c321187Smrg return; \ 546c321187Smrg} 556c321187Smrg 566c321187Smrg/*ARGSUSED*/ 576c321187Smrgvoid 586c321187SmrgXmuCvtStringToWidget(XrmValuePtr args, Cardinal *num_args, 596c321187Smrg XrmValuePtr fromVal, XrmValuePtr toVal) 606c321187Smrg{ 616c321187Smrg static Widget widget, *widgetP, parent; 626c321187Smrg XrmName name = XrmStringToName(fromVal->addr); 636c321187Smrg int i; 646c321187Smrg 656c321187Smrg if (*num_args != 1) 666c321187Smrg { 676c321187Smrg i = 0; 686c321187Smrg XtErrorMsg("wrongParameters", "cvtStringToWidget", "xtToolkitError", 696c321187Smrg "StringToWidget conversion needs parent arg", NULL, &i); 706c321187Smrg } 716c321187Smrg 726c321187Smrg parent = *(Widget*)args[0].addr; 736c321187Smrg /* try to match names of normal children */ 746c321187Smrg if (XtIsComposite(parent)) 756c321187Smrg { 766c321187Smrg i = ((CompositeWidget)parent)->composite.num_children; 776c321187Smrg for (widgetP = ((CompositeWidget)parent)->composite.children; 786c321187Smrg i; i--, widgetP++) 796c321187Smrg if ((*widgetP)->core.xrm_name == name) 806c321187Smrg { 816c321187Smrg widget = *widgetP; 826c321187Smrg done(&widget, Widget); 836c321187Smrg } 846c321187Smrg } 856c321187Smrg 866c321187Smrg /* try to match names of popup children */ 876c321187Smrg i = parent->core.num_popups; 886c321187Smrg for (widgetP = parent->core.popup_list; i; i--, widgetP++) 896c321187Smrg if ((*widgetP)->core.xrm_name == name) 906c321187Smrg { 916c321187Smrg widget = *widgetP; 926c321187Smrg done(&widget, Widget); 936c321187Smrg } 946c321187Smrg 956c321187Smrg /* try to match classes of normal children */ 966c321187Smrg if (XtIsComposite(parent)) 976c321187Smrg { 986c321187Smrg i = ((CompositeWidget)parent)->composite.num_children; 996c321187Smrg for (widgetP = ((CompositeWidget)parent)->composite.children; 1006c321187Smrg i; i--, widgetP++) 1016c321187Smrg if ((*widgetP)->core.widget_class->core_class.xrm_class == name) 1026c321187Smrg { 1036c321187Smrg widget = *widgetP; 1046c321187Smrg done(&widget, Widget); 1056c321187Smrg } 1066c321187Smrg } 1076c321187Smrg 1086c321187Smrg /* try to match classes of popup children */ 1096c321187Smrg i = parent->core.num_popups; 1106c321187Smrg for (widgetP = parent->core.popup_list; i; i--, widgetP++) 1116c321187Smrg if ((*widgetP)->core.widget_class->core_class.xrm_class == name) 1126c321187Smrg { 1136c321187Smrg widget = *widgetP; 1146c321187Smrg done(&widget, Widget); 1156c321187Smrg } 1166c321187Smrg 1176c321187Smrg XtStringConversionWarning(fromVal->addr, XtRWidget); 1186c321187Smrg toVal->addr = NULL; 1196c321187Smrg toVal->size = 0; 1206c321187Smrg} 1216c321187Smrg 1226c321187Smrg#undef done 1236c321187Smrg 1246c321187Smrg#define newDone(type, value) \ 1256c321187Smrg { \ 1266c321187Smrg if (toVal->addr != NULL) { \ 1276c321187Smrg if (toVal->size < sizeof(type)) { \ 1286c321187Smrg toVal->size = sizeof(type); \ 1296c321187Smrg return False; \ 1306c321187Smrg } \ 1316c321187Smrg *(type*)(toVal->addr) = (value); \ 1326c321187Smrg } \ 1336c321187Smrg else { \ 1346c321187Smrg static type static_val; \ 1356c321187Smrg static_val = (value); \ 1366c321187Smrg toVal->addr = (XtPointer)&static_val; \ 1376c321187Smrg } \ 1386c321187Smrg toVal->size = sizeof(type); \ 1396c321187Smrg return True; \ 1406c321187Smrg } 1416c321187Smrg 1426c321187Smrg 1436c321187Smrg/*ARGSUSED*/ 1446c321187SmrgBoolean 1456c321187SmrgXmuNewCvtStringToWidget(Display *dpy, XrmValue *args, Cardinal *num_args, 1466c321187Smrg XrmValue *fromVal, XrmValue *toVal, 1476c321187Smrg XtPointer *converter_data) 1486c321187Smrg{ 1496c321187Smrg Widget *widgetP, parent; 1506c321187Smrg XrmName name = XrmStringToName(fromVal->addr); 1516c321187Smrg int i; 1526c321187Smrg 1536c321187Smrg if (*num_args != 1) 1546c321187Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 1556c321187Smrg "wrongParameters","cvtStringToWidget","xtToolkitError", 1566c321187Smrg "String To Widget conversion needs parent argument", 1576c321187Smrg (String *)NULL, (Cardinal *)NULL); 1586c321187Smrg 1596c321187Smrg parent = *(Widget*)args[0].addr; 1606c321187Smrg /* try to match names of normal children */ 1616c321187Smrg if (XtIsComposite(parent)) 1626c321187Smrg { 1636c321187Smrg i = ((CompositeWidget)parent)->composite.num_children; 1646c321187Smrg for (widgetP = ((CompositeWidget)parent)->composite.children; 1656c321187Smrg i; i--, widgetP++) 1666c321187Smrg if ((*widgetP)->core.xrm_name == name) 1676c321187Smrg newDone(Widget, *widgetP); 1686c321187Smrg } 1696c321187Smrg 1706c321187Smrg /* try to match names of popup children */ 1716c321187Smrg i = parent->core.num_popups; 1726c321187Smrg for (widgetP = parent->core.popup_list; i; i--, widgetP++) 1736c321187Smrg if ((*widgetP)->core.xrm_name == name) 1746c321187Smrg newDone(Widget, *widgetP); 1756c321187Smrg 1766c321187Smrg /* try to match classes of normal children */ 1776c321187Smrg if (XtIsComposite(parent)) 1786c321187Smrg { 1796c321187Smrg i = ((CompositeWidget)parent)->composite.num_children; 1806c321187Smrg for (widgetP = ((CompositeWidget)parent)->composite.children; 1816c321187Smrg i; i--, widgetP++) 1826c321187Smrg if ((*widgetP)->core.widget_class->core_class.xrm_class == name) 1836c321187Smrg newDone(Widget, *widgetP); 1846c321187Smrg } 1856c321187Smrg 1866c321187Smrg /* try to match classes of popup children */ 1876c321187Smrg i = parent->core.num_popups; 1886c321187Smrg for (widgetP = parent->core.popup_list; i; i--, widgetP++) 1896c321187Smrg if ((*widgetP)->core.widget_class->core_class.xrm_class == name) 1906c321187Smrg newDone(Widget, *widgetP); 1916c321187Smrg 1926c321187Smrg XtDisplayStringConversionWarning(dpy, (String)fromVal->addr, XtRWidget); 1936c321187Smrg return (False); 1946c321187Smrg} 1956c321187Smrg 1966c321187Smrg/*ARGSUSED*/ 1976c321187SmrgBoolean 1986c321187SmrgXmuCvtWidgetToString(Display *dpy, XrmValuePtr args, Cardinal *num_args, 1996c321187Smrg XrmValuePtr fromVal, XrmValuePtr toVal, 2006c321187Smrg XtPointer *data) 2016c321187Smrg{ 2026c321187Smrg static String buffer; 2036c321187Smrg Cardinal size; 2046c321187Smrg Widget widget; 2056c321187Smrg 2066c321187Smrg widget = *(Widget *)fromVal->addr; 2076c321187Smrg 2086c321187Smrg if (widget) 2096c321187Smrg buffer = XrmQuarkToString(widget->core.xrm_name); 2106c321187Smrg else 2116c321187Smrg buffer = "(null)"; 2126c321187Smrg 2136c321187Smrg size = strlen(buffer) + 1; 2146c321187Smrg if (toVal->addr != NULL) 2156c321187Smrg { 2166c321187Smrg if (toVal->size < size) 2176c321187Smrg { 2186c321187Smrg toVal->size = size; 2196c321187Smrg return (False); 2206c321187Smrg } 2216c321187Smrg strcpy((char *)toVal->addr, buffer); 2226c321187Smrg } 2236c321187Smrg else 2246c321187Smrg toVal->addr = (XPointer)buffer; 2256c321187Smrg toVal->size = sizeof(String); 2266c321187Smrg 2276c321187Smrg return (True); 2286c321187Smrg} 229