Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!elroy.jpl.nasa.gov!ames!ncar!ico!attc!marbru From: marbru@attc.UUCP (Martin Brunecky) Newsgroups: comp.windows.x.motif Subject: Re: XmString type converter Message-ID: <1034@attc.UUCP> Date: 2 Feb 91 15:12:35 GMT References: <1991Jan31.143450.24173@slhisc.uucp> Reply-To: marbru@auto-trol.UUCP (Martin Brunecky) Organization: Auto-trol Technology, Denver Lines: 52 In article <1991Jan31.143450.24173@slhisc.uucp> paul@slhisc.uucp (Paul Tam) writes: >This is a common problem with motif labelString. Resource manager >can't handle multiple line label string specified in resource file > >Someone mentioned using a self-defined type converter. So I started >out testing the converter concept. So far I have been able to define >a converter, add the converter, and the converter is called when >widgets are created. In the converter function, I convert the label >... >However, the application blows up after returning from the converter. > Are you sure you are returning the "right" stuff back from the converter ? The result of your converter must be a *static* XmString foo (which in fact is some kind of a pointer), so you return toVal->size = sizeof(XmString); toVal->addr = &foo; The "foo" must be *static*, as it must exist *after* your converter exited, so that the calling code can make a copy of "foo" into the conversion cache (kinda klugy, but there are reasons for it). Next, you should NOT free the XmString created by the conversion, as you are returning a *pointer* to it - so the result of the conversion must "live for ever". You can and will reuse the "foo", but everytime you are called (with a new string), you will eat memory for the new XmString itself. > >Another question is does motif 1.0.3 with X11 R3 fully support self-defined >type converter. The reason I ask this question is that when I put the >XtAddConverter function call right after XtInitialize, the converter >was never invoked. If I move it down a little bit then It get called. >Strange!! Motif has a "block" of converters, ALL installed (in Motif 1.0) on the first call to XmRegisterConverters, typically called by the Motif widget's ClassInitialize, i.e when the first Xm widget is created. To overload Motif converters, just call XmRegisterConverters, and then add/load/overload your own converters. (note XmRegisterConverters uses a static flag "registered" to avoid reloading converters after the very first call). The best joke of the season: Write Motif application without access to Motif sources. -- =*= 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