[comp.windows.x] XmString Question

jerry@polygen.uucp (Jerry Sheckel) (12/04/90)

Hello.  I'm developing my first Motif application, and I have a question
about XmString things.  This is the situation:  I need to obtain the
labelString resource from a pushbutton and use it to set the string
resource of another widget:

	Widget		w1, w2;
	XmString	str;
        Arg		arg;

	XtSetArg(arg, XmNlabelString, &str);
	XtGetValues(w1, &arg, 1);
	XtSetArg(arg, XmNmessageString /* or whatever */, str);
	XtSetValues(w2, &arg, 1);

This seems to work.  My question: does 'str' have to be deallocated at this
point?  That is, did XtGetValues() create an entire new instance of the
XmString?  Does XtSetValues() create an internal instance of the XmString,
or does it just set up pointers to 'str'?  Please help if you can.
--
+-------------------+----------------------+---------------------------------+
| JERRY J. SHEKHEL  | POLYGEN CORPORATION  | When I was young, I had to walk |
| Drummers do it... | Waltham, MA USA      | to school and back every day -- |
|    ... In rhythm! | (617) 890-2175       | 20 miles, uphill both ways.     |
+-------------------+----------------------+---------------------------------+
|           ...! [ princeton mit-eddie bu sunne ] !polygen!jerry             |
|                            jerry@polygen.com                               |
+----------------------------------------------------------------------------+

kaleb@thyme.jpl.nasa.gov (Kaleb Keithley ) (12/05/90)

In article <917@stewart.UUCP> jerry@stewart.UUCP (Jerry Shekhel) writes:
>
>	XtSetArg(arg, XmNlabelString, &str);
>	XtGetValues(w1, &arg, 1);
>	XtSetArg(arg, XmNmessageString /* or whatever */, str);
>	XtSetValues(w2, &arg, 1);
>
>This seems to work.  My question: does 'str' have to be deallocated at this
>point?  That is, did XtGetValues() create an entire new instance of the
>XmString?  Does XtSetValues() create an internal instance of the XmString,
>or does it just set up pointers to 'str'?  Please help if you can.

Yes, yes, and yes.  XmStringFree(str) after the XtSetValues().

-- 
Kaleb Keithley                      Jet Propulsion Labs
kaleb@thyme.jpl.nasa.gov

Good girls get to go to heaven, but bad girls get to go everywhere!

nazgul@alphalpha.com (Kee Hinckley) (12/05/90)

In article <917@stewart.UUCP> jerry@stewart.UUCP (Jerry Shekhel) writes:
>This seems to work.  My question: does 'str' have to be deallocated at this
>point?  That is, did XtGetValues() create an entire new instance of the
>XmString?  Does XtSetValues() create an internal instance of the XmString,
>or does it just set up pointers to 'str'?  Please help if you can.

If you do a SetValues you definitely should deallocate the string
afterwards.  The GetValues is a little less consistant.  The release
notes for 1.1 state that everything is copied except XmNdialogTitle,
XmNdirectory, XmNnoMatchString, XmNlabelString (RowColumn only) and
XmNtitleString (in Scale).  Presumbably those will be fixed at some
later date.  Also in XmList XmNitems and XmNselectedItems, which are
arrays of XmStrings are not copied (and you wouldn't want them to be).

I'm pretty convinced that the only right way to do this is to
reference count XmStrings.  Then you always copy what is handed
to you if you want it, but all copy does is increment the reference
count.  Then nothing is copied in the GetValues, you just get a
pointer to the real thing.  But in the meantime the above stands.

If you're stuck with 1.0 I think the situation is a bit more
mixed up.  You still want to do a free after setting values, but
I'm not sure about getting values.
						-kee
-- 
Alphalpha Software, Inc.	|	motif-request@alphalpha.com
nazgul@alphalpha.com		|-----------------------------------
617/646-7703 (voice/fax)	|	Proline BBS: 617/641-3722

I'm not sure which upsets me more; that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.

dbrooks@penge.osf.org (David Brooks) (12/07/90)

In article <1990Dec5.020710.12550@alphalpha.com> nazgul@alphalpha.com (Kee Hinckley) writes:
>
>If you do a SetValues you definitely should deallocate the string
>afterwards.  The GetValues is a little less consistant.  The release
>notes for 1.1 state that everything is copied except XmNdialogTitle,
>XmNdirectory, XmNnoMatchString, XmNlabelString (RowColumn only) and
>XmNtitleString (in Scale).

Add XmNpattern in XmFileSelectionBox.

> Presumbably those will be fixed at some
>later date.

I believe they will be, in 1.1.1 (as usual, no commitment to content
or schedule).

>  Also in XmList XmNitems and XmNselectedItems, which are
>arrays of XmStrings are not copied (and you wouldn't want them to be).

Right.

-- 
David Brooks				dbrooks@osf.org
Systems Engineering, OSF		uunet!osf.org!dbrooks
"No, I didn't say I wanted a Bud light!!!" -- Oedipus