pds@quintus.UUCP (Peter Schachte) (07/15/89)
The (R3) doc for XtConvert() says it takes a widget argument which "specifies the widget to use for additional arguments (if any are needed)." What does this mean? What extra arguments? I'm trying to convert strings to the appropriate argument types to be put into the ArgList to be passed to XtCreateWidget() or XtAppCreateShell(), so I don't have a widget yet to pass to XtConvert(). Can I pass it a NULL? Or is there some way I can find the appropriate resource converter myself so I can call XtDirectConvert()? Thanks in advance for any advice, -- -Peter Schachte pds@quintus.uucp ...!sun!quintus!pds
pds@quintus.UUCP (Peter Schachte) (07/21/89)
I asked a similar question before, but I didn't get any replies, so I'm trying again: what should one pass for the widget argument to XtConvert() when one doesn't have a widget yet (I need to convert arguments in order to create a widget)? I see two basic possibilities: 1. Pass the parent widget. In intrinsic converters and all the widget sets I have source for, the converters that need extra arguments only need to look at the core part of the widget. Is that guaranteed? The problem with this approach comes in converting arguments for the shell widget. In this case, I don't have a parent widget to pass. The only thing I can think of to do here is create a shell widget as a dummy, use it to do my conversions, and destroy it when I'm done. 2. Create the widget first, use it to convert the arguments, and use XtSetValues() to install them. But am I guaranteed that creating a widget with an emtpy argument list and calling XtSetValues() to specify the initial arguments is equivalent to specifying the the arguments when creating the widget? This certainly seems like the simplest and most obvious solution to the problem, if the two are equivalent. But I seem to recall somewhere seeing resources that could not be set by XtSetValues(), but only at the time of widget creation. I've read TFM, and can't find either guarantee. Anyone have any answers? Has anyone already faced this question? Any words of wisdom would be greatly appreciated. TIA, -- -Peter Schachte pds@quintus.uucp ...!sun!quintus!pds
asente@decwrl.dec.com (Paul Asente) (07/21/89)
In article <1208@quintus.UUCP> pds@quintus.UUCP (Peter Schachte) writes: >The (R3) doc for XtConvert() says it takes a widget argument which >"specifies the widget to use for additional arguments (if any are >needed)." What does this mean? What extra arguments? Some conversions need more information than just the source value. String to font, for example, needs the display connection to fetch the font from and string to pixel needs a display and a colormap. These extra convert arguments are extracted from the widget you pass to XtConvert. >I'm trying to convert strings to the appropriate argument types to be >put into the ArgList to be passed to XtCreateWidget() or >XtAppCreateShell(), so I don't have a widget yet to pass to XtConvert(). >Can I pass it a NULL? No. When creating a widget the right thing is usually to pass in some other widget on the same display, usually the new widget's parent. If you're creating the very first widget in the application you can't do conversions; create the widget then use XtSetValues. >Or is there some way I can find the appropriate >resource converter myself so I can call XtDirectConvert()? Nope. -paul asente asente@decwrl.dec.com decwrl!asente
net@tub.UUCP (Oliver Laumann) (09/24/89)
Another question about the usage of XtConvert(). I don't quite understand how the result of a call to XtConvert() (a caddr_t) can be placed into an argument to e.g. XtSetValues(). Something like XtSetArg (args[n], XtNsomething, *(XtArgVal *)result.addr); (where result is an XrmValue the address of which has been passed to XtConvert() as the to_return argument) or simply XtSetArg (args[n], XtNsomething, *result.addr); doesn't work in all cases, e.g. when result.addr == 1 (when the result of the conversion is an unsigned char, for instance). Do I really have to write a switch statement with one case for each possible destination type (like the ugly switch in CopyFromArg() in lib/Xt/Resources.c)? Regards, -- Oliver Laumann net@TUB.BITNET net@tub.UUCP
swick@ATHENA.MIT.EDU (Ralph R. Swick) (09/25/89)
> I don't quite understand > how the result of a call to XtConvert() (a caddr_t) can be placed into > an argument to e.g. XtSetValues(). In general, it can't; you have to hard-code some knowledge about the C datatype of the result of the conversion; i.e. the specific type of object pointed to by result.addr. E.g. if you "know" the result of the conversion is an int, you can say XtSetArg (args[n], XtNsomething, *(int *)result.addr); In the special case of ArgLists, you can get away with just looking at the size of the returned conversion result, since that determines how it is "widened" to an XtArgVal. > Do I really have to > write a switch statement with one case for each possible destination type > (like the ugly switch in CopyFromArg() in lib/Xt/Resources.c)? For a higher-level generic interface, unfortunately yes.