[comp.windows.x] Getting ID for widget loaded from .uid?

gaf@uucs1.UUCP (gaf) (01/10/90)

I can't believe there isn't a simple, approved way to do this, but can't
see one for the life of me.

I fetch a tree of widgets from my .uid file, and need the widget ID of
some of them so I can twiddle their resources on the fly.  Trouble is,
I can't see a way of finding the widget ID.

My situation is pretty simple: I have a toggle button on a menu, the callback
for which tries to open a file.  If the open fails, I don't want to leave
the toggle "on" since it would fool the user.  It's easy enough to turn it
"off" with XtSetValues, but I need the widget ID for that.

This seems like the sort of thing that would come up fairly often.
Has anyone else faced and solved this, or am I missing something obvious
(not uncommon).
-- 
Guy Finney					It's that feeling of deja-vu
UUCS inc.   Phoenix, Az				all over again.
ncar!noao!asuvax!hrc!uucs1!gaf	sun!sunburn!gtx!uucs1!gaf

schoeller@4gl.enet.dec.com (Dick Schoeller) (01/10/90)

> 
> I can't believe there isn't a simple, approved way to do this, but can't
> see one for the life of me.
> 
> I fetch a tree of widgets from my .uid file, and need the widget ID of
> some of them so I can twiddle their resources on the fly.  Trouble is,
> I can't see a way of finding the widget ID.
> 

Try making setting up a create callback for each of the widgets whose IDs
you want to record.  The create callback is a only available through uil since
it is really called by mrm not the widget itself.

Dick Schoeller                  | schoeller@4gl.enet.dec.com
Digital Equipment Corporation   | 603-881-2965
110 Spit Brook Rd., ZKO2-3/R56  | "Either Judaism has something to say to the
Nashua, NH 03062-2642           | world or it has nothing to say to Jews."
                                |                             - Dennis Prager

swick@ATHENA.MIT.EDU (Ralph R. Swick) (01/11/90)

> I fetch a tree of widgets from my .uid file, and need the widget ID of
> some of them so I can twiddle their resources on the fly.  Trouble is,
> I can't see a way of finding the widget ID.

How about XtNameToWidget()?

bjaspan@athena.mit.edu (Barr3y Jaspan) (01/11/90)

In article <223@uucs1.UUCP>, gaf@uucs1.UUCP (gaf) writes:
> 
> I can't believe there isn't a simple, approved way to do this, but can't
> see one for the life of me.
> 
> I fetch a tree of widgets from my .uid file, and need the widget ID of
> some of them so I can twiddle their resources on the fly.  Trouble is,
> I can't see a way of finding the widget ID.

Yes, you are missing something obvious.  In fact, there are two
perfectly good ways to do what you want.  1) XtNameToWidget() 2) callbacks.

1) XtNameToWidget takes a widget and a list of names of children and
returns the widget ID of the last child in the list.  For example,
suppose you have the widget tree 

             foo
           bar  baz
         quux

Then XtNameToWidget(foo, "bar.quux") would return the ID of "quux." 
Presumably the ID of "foo" comes from MrmFetchHierarchy().  I seem to
recall there being a problem with using this with popup windows or menus
or something, but I don't recall the exact details -- I think you just
have to be very careful to get all the intermediate children widget
names correct.

2) callbacks.  All motif widgets have a "create" callback, and all
callbacks are passed the widget ID of the widget that caused them to
happen.  Thus, you can specify a create callback and have each widget
pass it a unique client_data parameter, and save away the widget ID.

Barry Jaspan, MIT-Project Athena
bjaspan@athena.mit.edu

asente@decwrl.dec.com (Paul Asente) (01/11/90)

In article <1990Jan10.172318.20172@athena.mit.edu> bjaspan@athena.mit.edu (Barr3y Jaspan) writes:
>1) XtNameToWidget takes a widget and a list of names of children and
>returns the widget ID of the last child in the list.  For example,
>suppose you have the widget tree 
>
>             foo
>           bar  baz
>         quux
>
>Then XtNameToWidget(foo, "bar.quux") would return the ID of "quux." 
>Presumably the ID of "foo" comes from MrmFetchHierarchy().

When Motif goes R4 you can also use wildcarding, a la
XtNameToWidget(foo, "*quux")
This is a useful thing to keep in mind even though you can't do it yet
since it frees the application from having to know as much about the
widget tree (one of the main reasons for using UIL in the first place).

	-paul asente
	    asente@decwrl.dec.com	decwrl!asente

ron@xwind.UUCP (Ronald P. Hughes) (01/12/90)

In article <223@uucs1.UUCP> gaf@uucs1.UUCP () writes:
>I fetch a tree of widgets from my .uid file, and need the widget ID of
>some of them so I can twiddle their resources on the fly.  Trouble is,
>I can't see a way of finding the widget ID.

Use a create callback, and stash the widget (actually its address)
somewhere handy for later reference.

Ronald P. Hughes		ron@xwind.com (or ...!uunet!xwind!ron)
CrossWind Technologies, Inc.	(408)335-4988

gaf@uucs1.UUCP (gaf) (01/12/90)

In article <1990Jan10.172318.20172@athena.mit.edu> bjaspan@athena.mit.edu (Barr3y Jaspan) writes:

>1) XtNameToWidget takes a widget and a list of names of children and
>returns the widget ID of the last child in the list.  For example,
>suppose you have the widget tree 
>
>             foo
>           bar  baz
>         quux
>
>Then XtNameToWidget(foo, "bar.quux") would return the ID of "quux." 

Ralph Swick also suggested this, and I've made it work in my program,
but have a nit to pick with it.  Doing this ties the code to a specific
widget hierarchy, so that if the button moves to a different menu the
code must change, too.  This would be a shame, as preventing this is
the main benefit of UIL.

>Presumably the ID of "foo" comes from MrmFetchHierarchy().  I seem to
>recall there being a problem with using this with popup windows or menus

I discovered the following, which may or may not be unique to Motif.
Starting with the menu bar widget as reference, the toggle button on
the pulldown is named "popup_File_pulldown.File_pulldown.Logging".
I would never have guessed the "popup_File_pulldown" part of it, since
the hierarchy I created was "File_pulldown.Logging".  Good thing we bought
the source!

>2) callbacks.

Boy, talk about missing something obvious!  The callback is provided with
the widget ID as its first argument.  I've even used it before.  Good grief.
This is sort of like asking if anyone has seen your glasses, only to be told
they're on top of your head.  Must be time for a vacation.

Thanks to all.
-- 
Guy Finney					It's that feeling of deja-vu
UUCS inc.   Phoenix, Az				all over again.
ncar!noao!asuvax!hrc!uucs1!gaf	sun!sunburn!gtx!uucs1!gaf