[ Usenet FAQs | Web FAQs | Documents | RFC Index ]
    Search the FAQ Archives

Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Part7 - Part8 - Part9 - Single Page

Top Document: Motif FAQ (Part 5 of 9)
Previous Document: 150) Why doesn't label alignment work in a XmRowColumn?
Next Document: 152) How can I have a vertical label?


151) How can I set a multi-line label?


[Last modified: Mar 96]

Answer: In .Xdefaults

*XmLabel*labelString:              Here\nis\nthe\nLabel

This method does not seem to work in some of the older Motif 1.0 versions.

In code,

char buf[128];
XmString msg;
strcpy(buf, "Here\nis\nthe\nLabel");
msg = XmStringCreateLtoR(buf, XmSTRING_DEFAULT_CHARSET);
XtSetArg (args[n], XmNlabelString, msg);

Gives a four line label, using the escape sequence \n for a newline.  Here's
another approach from Jean-Philippe Martin-Flatin <syj@ecmwf.int>

#include <Xm/Xm.h>
#include <string.h>

/*-----------------------------------------------------
Create a new XmString from a char*

This function can deal with embedded 'newline' and
is equivalent to XmStringCreateLtoR,
except it does not use non AES compliant charset
XmSTRING_DEFAULT_CHARSET
----------------------------------------------------*/
XmString xec_NewString(char *s)
{
XmString xms1;
XmString xms2;
XmString line;
XmString separator;
char     *p;
char     *t = XtNewString(s);   /* Make a copy for strtok not to */
                            /* damage the original string    */

separator = XmStringSeparatorCreate();
p         = strtok(t,"\n");
xms1      = XmStringCreateLocalized(p);

while (p = strtok(NULL,"\n"))
{
line = XmStringCreateLocalized(p);
xms2 = XmStringConcat(xms1,separator);
XmStringFree(xms1);
xms1 = XmStringConcat(xms2,line);
XmStringFree(xms2);
XmStringFree(line);
}

XmStringFree(separator);
XtFree(t);
return xms1;
}


Do not use XmStringCreateLocalized() - it does not process the newline
character in the way you want.   In Motif 1.x, XmStringCreateLocalized() does
NOT process newlines, but XmStringCreateLtoR() does.

Thanks to Paul Tomblin (ptomblin@xcski.com) for the newline clarification.



Top Document: Motif FAQ (Part 5 of 9)
Previous Document: 150) Why doesn't label alignment work in a XmRowColumn?
Next Document: 152) How can I have a vertical label?

Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Part7 - Part8 - Part9 - Single Page


[ Usenet FAQs | Web FAQs | Documents | RFC Index ]

Send corrections/additions to the FAQ Maintainer:
kenton@rahul.net (Ken Lee)

Last Update October 22 2009 @ 05:27 AM

Some parts © 2009 Advameg, Inc.