160) Can I specify a widget in a resource file?

Answer: This answer, which uses the Xmu library, is due to David Elliott.  If
the converter is added, then the name of a widget (a string) can be used in
resource files, and will be converted to the appropriate widget.

This code, which was basically stolen from the Athena Form widget, adds a
String to Widget converter.  I wrote it as a general routine that I call at
the beginning of all of my programs, and made it so I could add other
converters as needed (like String to Unit Type ;-).

        #include <X11/Intrinsic.h>
        #include <X11/StringDefs.h>
        #include <Xm/Xm.h>
        #include <X11/Xmu/Converters.h>
        #include <X11/IntrinsicP.h>
        #include <X11/CoreP.h>

        void
        setupConverters()
        {
                static XtConvertArgRec parentCvtArgs[] = {
                        {XtBaseOffset, (caddr_t)XtOffset(Widget, core.parent),
                                sizeof(Widget)}
                };

                XtAddConverter(XmRString, XmRWindow, XmuCvtStringToWidget,
                        parentCvtArgs, XtNumber(parentCvtArgs));
        }
Go Back Up

Go To Previous

Go To Next