[comp.windows.x.motif] Setting Widget Resources

bonnett@seismo.CSS.GOV (H. David Bonnett) (04/22/91)

In article <1991Apr18.003956.6310@latcs2.lat.oz.au>, arthur@latcs2.lat.oz.au (Arthur Proestakis) writes:
|> Can all the resources of a widget be set in a resource file?
|> 
|> I am trying to do the following in a resource file:
|> 
|>         app*widget.bottomAttachment: ATTACH_WIDGET
|>         app*widget.bottomWidget: bottom_widget
|> 
|> and the error I get is:
|> 
|>         X Toolkit Warning: Cannot convert string "bottom_widget" to type Widget
|> 
|> "bottom_widget" does exist in the program, therefore should I assume
|> this can't be done?

The problem with this is that the attachment argument for BottomWidget
expects to get a Widget Pointer, not the Name of the widget. It would be nice
if there were and conversion routine to allow for this, but there is not one at
present (and I am not sure that it that the process is meant to handle conversion
to values not resolvable at program startup. Any ideas?)  Doug Young mentions
this problem in his book.

I end up setting these in the code through XtSetArgs.

Hope this helps,

--
-dave bonnett-   Center for Seismic Studies;  Arlington, VA 
      bonnett@seismo.css.gov :  All standard disclaimers apply.

aw@BAE.BELLCORE.COM (Andrew Wason) (04/22/91)

csus.edu!wuarchive!uwm.edu!spool.mu.edu!munnari.oz.au!mel.dit.csiro.au!latcs1!a
rthur@ucdavis.ucdavis.edu (Arthur Proestakis) writes:
> Can all the resources of a widget be set in a resource file?

Only those resources for which a String to 'resource type' converter
has been registered.

> I am trying to do the following in a resource file:
> 
>         app*widget.bottomAttachment: ATTACH_WIDGET
>         app*widget.bottomWidget: bottom_widget

In this case the resource type is XtRWidget and no String to Widget
converter has been registered.

Wcl (available on export) provides the converter you need.

Andrew

_______________________________________________________________________________

Andrew Wason                                       Bell Communications Research
aw@bae.bellcore.com                                Piscataway, NJ
bellcore!bae!aw

dbrooks@osf.osf.org (David Brooks) (04/22/91)

aw@BAE.BELLCORE.COM (Andrew Wason) writes:
>> I am trying to do the following in a resource file:
>> 
>>         app*widget.bottomAttachment: ATTACH_WIDGET
>>         app*widget.bottomWidget: bottom_widget
>
>In this case the resource type is XtRWidget and no String to Widget
>converter has been registered.
>
>Wcl (available on export) provides the converter you need.

You can also do this with UIL.

UIL (and presumably Wcl) can convert a widget name to a widget because the
interface is created in one swell foop.  They have enough information
sitting around to (almost) guarantee a successful conversion.

However, a more general mechanism like a resource specification can't make
these guarantees.  At the time the resource is converted, bottom_widget
will probably not exist.  If it does exist, there may be two widgets of the
same name in the app-context.  Given a conversion that's likely to fail
most of the time, I think the choice was not to provide it at all.

A clear case of advantage to using UIL :-)
-- 
David Brooks				dbrooks@osf.org
Systems Engineering, OSF		uunet!osf.org!dbrooks
Donnie Wahlberg is brought to you by three billion years of evolution.

dce@smsc.sony.com (David Elliott) (04/22/91)

In article <1991Apr18.003956.6310@latcs2.lat.oz.au>, arthur@latcs2.lat.oz.au (Arthur Proestakis) writes:
|> Can all the resources of a widget be set in a resource file?
|> 
|> I am trying to do the following in a resource file:
|> 
|>         app*widget.bottomAttachment: ATTACH_WIDGET
|>         app*widget.bottomWidget: bottom_widget
|> 

From all the replies to this, maybe my code should become part of
the FAQ (or better yet, part of Motif 1.2!).

This code, which was basically stolen from the Athena Form widget, adds
a String to Window 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));
}

-- 
...David Elliott
...dce@smsc.sony.com | ...!{uunet,mips}!sonyusa!dce
...(408)944-4073
..."Once a head-crusher, always a head-crusher" - Mark M.

david@ap542.uucp (04/29/91)

bonnett@seismo.CSS.GOV (H. David Bonnett) writes:
>arthur@latcs2.lat.oz.au (Arthur Proestakis) writes:
>|> Can all the resources of a widget be set in a resource file?
>|> 
>|> I am trying to do the following in a resource file:
>|> 
>|>         app*widget.bottomAttachment: ATTACH_WIDGET
>|>         app*widget.bottomWidget: bottom_widget
>|> 
>|> and the error I get is:
>|> 
>|>  X Toolkit Warning: Cannot convert string "bottom_widget" to type Widget
>
>The problem with this is that the attachment argument for BottomWidget
>expects to get a Widget Pointer, not the Name of the widget. 

Sounds like you should get the Widget Creation Library.  It provides
a CvtStringToWidget converter so you can do this type of stuff in
resource files.  It also provides a CvtStringToCallback converter
so you can bind callbacks in resource files.  And of course it also
provides CvtStringToClass and CvtStringToConstructor converters
which allow you to delete every line in your source which looks like
this:
	XtCreateWidget( ... )
	XtManageWidget(... )
	XmCreate....(...)
	XtManageChildren(...)

All that sort of thing then gets put into your resource file(s) and
your C code ends up being nothing but very simple initialization
code and your callbacks and action procedures which actually implement
the application.

Get Wcl via ftp from most any achive server, including export.lcs.mit.edu
in contrib/Wcl1.05 and devvax.jpl.nasa.gov in pub/Wcl1.05


David E. Smyth
david@ap542.uucp