From: bobhays@spss.com (Bob Hays)
Newsgroups: comp.windows.x.motif
Subject: Re: Use of constant strings in UIL description
Keywords: Uil, XmNuserData, Storage allocation
Date: 15 Oct 92 14:32:25 GMT
Organization: SPSS, Inc.

In article <3650@creatures.cs.vt.edu>, ramakris@csgrad.cs.vt.edu (S.Ramakrishnan) writes:
> 
>   [
>     * Motif vers 1.2
>     * Motif Uil Compiler V2.0-000
>     * SPARCstation, SunOS Release 4.1.1 (GENERIC) #1
>   ]
>   
> (1)
> In a Uil description of a UI layout, I need to 
> attach a constant string (that is, a constant within the 
> uil file) as user data to a primitive widget. The following
> fragment produces empty XmNuserData at runtime :
> 
>    module Bajji ;
> 
>     [...]
>     my_text : exported XmText {
>       arguments {
>        XmNuserData = "SilkSmitha" ;
>       };
>     };
>     [...]
> 
> At runtime however, the userdata of "my_text" turns out to be an 
> empty string instead of "SilkSmitha" :-(.
> 
>    ...MrmInitialize...
>    ...MrmRegisterNames...
>    ...MrmFetchWidget (top widget)...
>    [...]
>    Widget my_text = XtNameToWidget(top, "*my_text");
>    caddr_t opaque ;
>    XtVaGetValues(my_text, XmNuserData, &opqaue, NULL);
> 
>    { (String)opaque turns out to be "" }
>    [...]
> 
> Were there a restriction that only identifiers may be bound this way
> and not constants, the Uil compiler'd (*) have pointed it out ?

You can bind whatever you want to user data, but see (2) below for
more (important and undocumented [I think]) information.

> (2)
> As an aside, when is storage allocated to the constant strings declared
> within Uil ? Is it done when the hierarchy is opened or when the
> hierarchy is "fetched" (realized) ? Are such strings stored in the code 
> segment ? If that's the case, would muliple instantiations of the Ui
> template "Bajji" share a common space allocated to the string 
> "SilkSmitha" ?

This is all "to the best of my knowledge" - perhaps one of our
listeners from OSF could shed more light here.

I did this before (so I could write a UIL driven dialog system for
interfacing to DCL command files on VMS for OSF/Motif-izing our system
command files (if you were running X, of course:-).

The gotcha here is that:

1) the data may well be a compound string when you get it (the
Programmer's Guide mentions that strings are represented in whatever
way the usage indicates - so what does that mean in this case?) - it
was on DEC stuff back on V. 5.1 of VMS (Motif V 1.1.2 I think).

2) The memory allocated for the data area is deallocated after the
creation callback.  Therefore, you must copy the user data to your own
internal area and then put that pointer back onto the XmNuserData to
keep it around.  Don't even ask me why Mrm works this way....

> (3)
> Is there any "Tricks of the UIL Masters" kind of a book (a la Dan
> Heller's "Motif Programming Manual") ? Apart form the manuals, the 
> only book that seems to dwell on the subject bit more than cursorily 
> seems to be Thomas Berlage's book on Motif. Yet, this treatment is
> quite brief. Further, there are typos in crucial places (such as 
> "XmNcreateCallback" for "MrmNcreateCallback").

Berlage's book provides some UIL stuff (I don't have it [yet] so I
cannot comment on the personal value).

> I really need the answers to or any suggestions about question (1),
> (2) and (3) being secondary queries. I'd really be obliged
> if some Uil expert could suggest a solution to (1) that would
> not necessitate the use of identifiers.
> 
> Thanx.
> 
> 
> (*): Talking of the Uil compiler, it really taught me the meaning of
>      snowballing error messages.

And they roll downscreen. :-) :-)

Have fun! - Bob

-- 
===============================================================================
The opinions expressed above are those of Bob Hays and not SPSS, Inc.
 bobhays@spss.com  Phone: (312) 329-3529 | "I'm hovering like a fly, waiting
                   Fax:   (312) 329-3657 |  for a windshield on a freeway" -PG
Newsgroups: comp.windows.x.motif