[comp.windows.x] A question on Form widgets ... on motif.

veerabad@buster.cps.msu.edu (Vibhu Veerabadrappa) (02/02/91)

I had a problem using the form widget class:

I created a form widget as a child of the root widget. Under this 
form widget, I created some pushbutton widgets as children, and I
tried to space them using the resource file. Specifically, I tried 
to position some pushbuttons with respect to the form's right or
top edge, and it works fine.

I say:
*quit_button.topAttachment: attach_form

But if I try to specify the position wrt a widget, like:

*sep1.topAttachment: attach_widget <--- to attach to a widget
*sep1.topWidget: quit_button <--- name of the already created widget,

I get an error message when I run the application program. The error 
message is something like:

 ... no type converter specified for String to Window convertion 
					      ^^^^^^^^

Note that it says String to Window ... which is the first surprise.

1. So I tried to write a String to Window type converter based on the 
   example in Young's book ... (pg 61) but I do not know what the type 
   of Window is. I tried %d, but it would not work.

2. Another surprise is that if I burn the same information in the program 
   using XtSetValues, it works fine.

3. The problem is only if I try to position wrt a widget. I do not seem to
   have any problems with others, like attach_form, attach_position etc.

Can any of you please let me know if it is a legitimate problem, or am I
doing something wrong. I would appreciate it if you can send me mail, as
I do not read this group often. My address is 
	  veerabad@frith.egr.msu.edu

	  Thanks a lot.

gstiehl@pixel.convex.com (Greg Stiehl) (02/03/91)

In article <1991Feb1.235040.14018@msuinfo.cl.msu.edu>, veerabad@buster.cps.msu.edu (Vibhu Veerabadrappa) writes:
> 
> I had a problem using the form widget class:
> 
> I created a form widget as a child of the root widget. Under this 
> form widget, I created some pushbutton widgets as children, and I
> tried to space them using the resource file. Specifically, I tried 
> to position some pushbuttons with respect to the form's right or
> top edge, and it works fine.
> 
> I say:
> *quit_button.topAttachment: attach_form
> 
> But if I try to specify the position wrt a widget, like:
> 
> *sep1.topAttachment: attach_widget <--- to attach to a widget
> *sep1.topWidget: quit_button <--- name of the already created widget,

the topWidget resource is expecting a widget ID.  So, if you wanted to
set it in a resource file, you would have to convert the string
"quit_button" to a widget ID.  You could do this in a converter
routine, provided you have created the "quit_button" widget before
you created the "sep1" widget.  And you have kept track all possible widgets
names and IDs. It is unfortunate (but understandable) that the form widget
doesn't attach to widgets by name.

> I get an error message when I run the application program. The error 
> message is something like:
> 
>  ... no type converter specified for String to Window convertion 
>					        ^^^^^^^^
> 
> Note that it says String to Window ... which is the first surprise.

Yes, that is a surprise.  From the resource definition in Form.c, I would
expect it to complain about no "String to Immediate".

> 1. So I tried to write a String to Window type converter based on the 
>    example in Young's book ... (pg 61) but I do not know what the type 
>    of Window is. I tried %d, but it would not work.

You might try String to Immediate, since that is the default type (even
though the error message indicates otherwise).  Like I said about, type
that it is expecting is a widget, so your converstion routine should
set the to.addr to the correct widget ID.  Provided, of course, that you
can figure out what the widget ID of the string is.

> 
> 2. Another surprise is that if I burn the same information in the program 
>    using XtSetValues, it works fine.

I'll bet that you are using the widget ID and not the name of the widget.

> 3. The problem is only if I try to position wrt a widget. I do not seem to
>    have any problems with others, like attach_form, attach_position etc.

That is because  attach_form, attach_position...  are constants that can
be converted by the Xt resource manager.  Whereas widget is dymamic.

> Can any of you please let me know if it is a legitimate problem, or am I
> doing something wrong.

You are not doing anything wrong, what you are doing just isn't supported.
At a glance it seems like adding a converter is the correct thing to do.
If you are creative enough, you might even be able to forward reference
widgets.  Of course you will have to keep track of all the widget names
and IDs, so that your conversion routine can figure things out.

Greg Stiehl (gstiehl@convex.com)
Convex -- Graphics Software Group.

marbru@attc.UUCP (Martin Brunecky) (02/04/91)

In article <1991Feb02.183100.8367@convex.com> gstiehl@convex.com writes:
>In article <1991Feb1.235040.14018@msuinfo.cl.msu.edu>, veerabad@buster.cps.msu.edu (Vibhu Veerabadrappa) writes:
>> 
>> I had a problem using the form widget class:
>> 
>> I created a form widget as a child of the root widget. Under this 
>> form widget, I created some pushbutton widgets as children, and I
>> tried to space them using the resource file. Specifically, I tried...
>> 
>> But if I try to specify the position wrt a widget, like:
>> 
>> *sep1.topAttachment: attach_widget <--- to attach to a widget
>> *sep1.topWidget: quit_button <--- name of the already created widget,
>
>the topWidget resource is expecting a widget ID.  So, if you wanted to
>set it in a resource file, you would have to convert the string
>"quit_button" to a widget ID.  You could do this in a converter
>routine, provided you have created the "quit_button" widget before
>you created the "sep1" widget.  And you have kept track all possible widgets
>names and IDs. It is unfortunate (but understandable) that the form widget
>doesn't attach to widgets by name.

    Understandable ??? - just a design flaw to be corrected during
    widget evolution ....

    The Wcl library included a StringToWidget resource converter, designed
    exactly for what you want to do, with the Only limitation that
    the widget must exist (i.e. be created before).

    There are some situations where you seem to need to reference a widget 
    BEFORE it has been created. You can't do it.
    The ONLY solution in situations like that is to
    postpone initialization of such a resource UNTIL a particular widget
    is created.

    Using Wcl (again), uou can attach (a set of) callbacks to the creation
    callback, and let those callbacks set the widget ID into appropriate
    resources of OTHER widgets.


-- 
=*= Opinions presented here are solely of my own and not those of Auto-trol =*=
Martin Brunecky                           {...}sunpeaks!auto-trol!marbru
(303) 252-2499                        (sometimes also:  marbru@auto-trol.COM )
Auto-trol Technology Corp. 12500 North Washington St., Denver, CO 80241-2404 

ben@hpcvlx.cv.hp.com (Benjamin Ellsworth) (02/05/91)

> ... From the resource definition in Form.c, I would expect it to
> complain about no "String to Immediate".
> ...
> You might try String to Immediate, since that is the default type
> (even though the error message indicates otherwise).

No No No.  There are TWO resource type qualifiers in a resource
specification.  The first is the type of the resource and the second is
the type of the default provided.  XtRImmediate only occurs in the
second position.  It means that the default provided is of the
appropriate type [history of Xt deleted].

The first specifier for attachment widgets is XtRWindow.  This is the
type expected.  The resource conversion stuff in Xt will look for a
converter to convert the type gotten from the database (usually string)
to the type specified (in this case window).  Since there is no such
converter registered, a warning message is generated.

> You are not doing anything wrong, what you are doing just isn't
> supported.

Yup.

> At a glance it seems like adding a converter is the correct thing to
> do.

Yes, but be sure to add the right one ;-)

> If you are creative enough, you might even be able to forward
> reference widgets. ...

Boy I doubt that!  Unless you can guarantee that a certain widget will
get a certain id, you can't do forward references without modifying the
Form widget itself.

-----------------------------------------------------------------------
Benjamin Ellsworth      | ben@cv.hp.com                | INTERNET
Hewlett-Packard Company | {backbone}!hplabs!hp-pcd!ben | UUCP
1000 N.E. Circle        | (USA) (503) 750-4980         | FAX
Corvallis, OR 97330     | (USA) (503) 757-2000         | VOICE
-----------------------------------------------------------------------
                     All relevant disclaimers apply.
-----------------------------------------------------------------------