Search the FAQ Archives

3 - A - B - C - D - E - F - G - H - I - J - K - L - M
N - O - P - Q - R - S - T - U - V - W - X - Y - Z
faqs.org - Internet FAQ Archives

Motif FAQ (Part 5 of 9)
Section - 151) How can I set a multi-line label?

( Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Part7 - Part8 - Part9 - Single Page )
[ Usenet FAQs | Web FAQs | Documents | RFC Index | Zip codes ]


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?
See reader questions & answers on this topic! - Help others by sharing your knowledge
[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.

User Contributions:

Comment about this article, ask questions, or add new information about this topic:

CAPTCHA




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 March 27 2014 @ 02:11 PM