StrToWidg.c

Go to the documentation of this file.
00001 /* $Xorg: StrToWidg.c,v 1.4 2001/02/09 02:03:53 xorgcvs Exp $ */
00002 
00003 /*
00004 
00005 Copyright 1994, 1998  The Open Group
00006 
00007 Permission to use, copy, modify, distribute, and sell this software and its
00008 documentation for any purpose is hereby granted without fee, provided that
00009 the above copyright notice appear in all copies and that both that
00010 copyright notice and this permission notice appear in supporting
00011 documentation.
00012 
00013 The above copyright notice and this permission notice shall be included in
00014 all copies or substantial portions of the Software.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00019 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00020 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00021 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00022 
00023 Except as contained in this notice, the name of The Open Group shall not be
00024 used in advertising or otherwise to promote the sale, use or other dealings
00025 in this Software without prior written authorization from The Open Group.
00026 
00027 */
00028 /* $XFree86: xc/lib/Xmu/StrToWidg.c,v 1.6 2001/01/17 19:42:57 dawes Exp $ */
00029 
00030 /*
00031  * XmuCvtStringToWidget
00032  *
00033  * static XtConvertArgRec parentCvtArgs[] = {
00034  *   {XtBaseOffset, (XtPointer)XtOffset(Widget, core.parent), sizeof(Widget)},
00035  * };
00036  *
00037  * matches the string against the name of the immediate children (normal
00038  * or popup) of the parent.  If none match, compares string to classname
00039  * & returns first match.  Case is significant.
00040  */
00041 #include <X11/IntrinsicP.h>
00042 #include <X11/StringDefs.h>
00043 #include <X11/ObjectP.h>
00044 #include <X11/Xmu/Converters.h>
00045 
00046 #define done(address, type) \
00047 {                                               \
00048   toVal->size = sizeof(type);                   \
00049   toVal->addr = (XPointer)address;              \
00050           return; \
00051 }
00052 
00053 /*ARGSUSED*/
00054 void
00055 XmuCvtStringToWidget(XrmValuePtr args, Cardinal *num_args,
00056                      XrmValuePtr fromVal, XrmValuePtr toVal)
00057 {
00058     static Widget widget, *widgetP, parent;
00059     XrmName name = XrmStringToName(fromVal->addr);
00060     int i;
00061 
00062     if (*num_args != 1)
00063         XtErrorMsg("wrongParameters", "cvtStringToWidget", "xtToolkitError",
00064                    "StringToWidget conversion needs parent arg", NULL, 0);
00065 
00066     parent = *(Widget*)args[0].addr;
00067     /* try to match names of normal children */
00068   if (XtIsComposite(parent))
00069     {
00070         i = ((CompositeWidget)parent)->composite.num_children;
00071         for (widgetP = ((CompositeWidget)parent)->composite.children;
00072            i; i--, widgetP++)
00073         if ((*widgetP)->core.xrm_name == name)
00074           {
00075                 widget = *widgetP;
00076                 done(&widget, Widget);
00077             }
00078         }
00079 
00080     /* try to match names of popup children */
00081     i = parent->core.num_popups;
00082   for (widgetP = parent->core.popup_list; i; i--, widgetP++)
00083     if ((*widgetP)->core.xrm_name == name)
00084       {
00085             widget = *widgetP;
00086             done(&widget, Widget);
00087         }
00088 
00089     /* try to match classes of normal children */
00090   if (XtIsComposite(parent))
00091     {
00092         i = ((CompositeWidget)parent)->composite.num_children;
00093         for (widgetP = ((CompositeWidget)parent)->composite.children;
00094            i; i--, widgetP++)
00095         if ((*widgetP)->core.widget_class->core_class.xrm_class == name)
00096           {
00097                 widget = *widgetP;
00098                 done(&widget, Widget);
00099             }
00100         }
00101 
00102     /* try to match classes of popup children */
00103     i = parent->core.num_popups;
00104   for (widgetP = parent->core.popup_list; i; i--, widgetP++)
00105     if ((*widgetP)->core.widget_class->core_class.xrm_class == name)
00106       {
00107             widget = *widgetP;
00108             done(&widget, Widget);
00109         }
00110 
00111     XtStringConversionWarning(fromVal->addr, XtRWidget);
00112     toVal->addr = NULL;
00113     toVal->size = 0;
00114 }
00115 
00116 #undef done
00117 
00118 #define newDone(type, value) \
00119         {                                                       \
00120             if (toVal->addr != NULL) {                          \
00121                 if (toVal->size < sizeof(type)) {               \
00122                     toVal->size = sizeof(type);                 \
00123                     return False;                               \
00124                 }                                               \
00125                 *(type*)(toVal->addr) = (value);                \
00126             }                                                   \
00127             else {                                              \
00128                 static type static_val;                         \
00129                 static_val = (value);                           \
00130                 toVal->addr = (XtPointer)&static_val;           \
00131             }                                                   \
00132             toVal->size = sizeof(type);                         \
00133             return True;                                        \
00134         }
00135 
00136 
00137 /*ARGSUSED*/
00138 Boolean
00139 XmuNewCvtStringToWidget(Display *dpy, XrmValue *args, Cardinal *num_args,
00140                         XrmValue *fromVal, XrmValue *toVal,
00141                         XtPointer *converter_data)
00142 {
00143     Widget *widgetP, parent;
00144     XrmName name = XrmStringToName(fromVal->addr);
00145     int i;
00146 
00147     if (*num_args != 1)
00148         XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
00149                         "wrongParameters","cvtStringToWidget","xtToolkitError",
00150                         "String To Widget conversion needs parent argument",
00151                         (String *)NULL, (Cardinal *)NULL);
00152 
00153     parent = *(Widget*)args[0].addr;
00154     /* try to match names of normal children */
00155   if (XtIsComposite(parent))
00156     {
00157         i = ((CompositeWidget)parent)->composite.num_children;
00158         for (widgetP = ((CompositeWidget)parent)->composite.children;
00159            i; i--, widgetP++)
00160             if ((*widgetP)->core.xrm_name == name)
00161                 newDone(Widget, *widgetP);
00162         }
00163 
00164     /* try to match names of popup children */
00165     i = parent->core.num_popups;
00166   for (widgetP = parent->core.popup_list; i; i--, widgetP++)
00167         if ((*widgetP)->core.xrm_name == name)
00168             newDone(Widget, *widgetP);
00169 
00170     /* try to match classes of normal children */
00171   if (XtIsComposite(parent))
00172     {
00173         i = ((CompositeWidget)parent)->composite.num_children;
00174         for (widgetP = ((CompositeWidget)parent)->composite.children;
00175            i; i--, widgetP++)
00176             if ((*widgetP)->core.widget_class->core_class.xrm_class == name)
00177                 newDone(Widget, *widgetP);
00178         }
00179 
00180     /* try to match classes of popup children */
00181     i = parent->core.num_popups;
00182   for (widgetP = parent->core.popup_list; i; i--, widgetP++)
00183         if ((*widgetP)->core.widget_class->core_class.xrm_class == name)
00184             newDone(Widget, *widgetP);
00185 
00186     XtDisplayStringConversionWarning(dpy, (String)fromVal->addr, XtRWidget);
00187   return (False);
00188 }
00189 
00190 /*ARGSUSED*/
00191 Boolean
00192 XmuCvtWidgetToString(Display *dpy, XrmValuePtr args, Cardinal *num_args,
00193                      XrmValuePtr fromVal, XrmValuePtr toVal,
00194                      XtPointer *data)
00195 {
00196   static String buffer;
00197   Cardinal size;
00198   Widget widget;
00199 
00200   widget = *(Widget *)fromVal->addr;
00201 
00202   if (widget)
00203     buffer = XrmQuarkToString(widget->core.xrm_name);
00204   else
00205     buffer = "(null)";
00206 
00207   size = strlen(buffer) + 1;
00208   if (toVal->addr != NULL)
00209     {
00210       if (toVal->size < size)
00211         {
00212           toVal->size = size;
00213           return (False);
00214         }
00215       strcpy((char *)toVal->addr, buffer);
00216     }
00217   else
00218     toVal->addr = (XPointer)buffer;
00219   toVal->size = sizeof(String);
00220 
00221   return (True);
00222 }

Generated on Sun Mar 4 15:03:56 2007 for Scilab [trunk] by  doxygen 1.5.1