Problem with compound string with tabs in a dialog

Problem with compound string with tabs in a dialog

Post by Jim Gra » Tue, 29 Jun 2004 02:17:42


I want to have tabbed output in the message part of a dialog. I am
trying to do this in the simplest way, but I can't get it to work. I
cobbled the included example from the "Motif Programming Manual, VOLUME
SIX A". If anybody can see where I'm going wrong, I would appreciate a
response. My alternative is to go to a custom dialog, using a table or
something like that. Maybe even a fixed font with spaces to line things
up. I can get tabs to work in a label, but not the dialog as below.


---cut here---cut here---cut here---cut here---cut here---cut here
(sun SUNWspro, Motif Version 2.1.0) cc junk.c -lXm -lXt
(linux Motif Version 2.2.2) gcc junk.c -L/usr/X11R6/lib -lXm -lXt

#include <Xm/Label.h>
#include <Xm/MessageB.h>

Widget PostDialog (Widget parent, int dialog_type, char *msg){
Widget dialog;
XmString text;

// tabs
const int MAX_COLUMNS = 5;
XmTab tabs[MAX_COLUMNS];
XmTabList tablist;
XmRendition rendition;
XmRenderTable rtable;
int n,i;
Arg args[5];

/* Create tab stops */
for (i = 0; i < MAX_COLUMNS; i++) {
tabs[i] = XmTabCreate((float)1.5, XmINCHES,
((i == 0) ? XmABSOLUTE : XmRELATIVE),
/* Create the XmTabList from the XmTab objects */
tablist = XmTabListInsertTabs(NULL, tabs, XtNumber(tabs), 0);

dialog = XmCreateMessageDialog (parent, "dialog", NULL, 0);
text = XmStringGenerate(msg,NULL, XmCHARSET_TEXT, NULL);
XtVaSetValues (dialog,
XmNdialogType, dialog_type,
XmNmessageString, text,
/* Create an XmRendition that uses the XmTabList */
n = 0;
XtSetArg(args[n], XmNtabList, tablist); n++;
rendition = XmRenditionCreate(dialog, XmFONTLIST_DEFAULT_TAG,args, n);
rtable = XmRenderTableAddRenditions(NULL,&rendition,1,XmMERGE_NEW);
XtVaSetValues (dialog, XmNrenderTable, rtable, NULL);
XmStringFree (text);
XtManageChild (dialog);
return dialog;

int main(int argc, char **argv){
Widget shell, label;
XtAppContext app;

/* Create a shell. */

shell = XtAppInitialize(&app, "Rendition", NULL, 0,
&argc, argv, NULL, NULL, 0);

PostDialog(shell, XmDIALOG_MESSAGE, "message\nmessage2\tmessage3");

return 1;

---cut here---cut here---cut here---cut here---cut here---cut here

Problem with compound string with tabs in a dialog

Post by Fred L. Kl » Sat, 10 Jul 2004 00:12:49

Try setting the XmNrendertable resource of the label child of the
dialog, not the dialog itself:

XtVaSetValues( XmMessageBoxGetChild(dialog,
XmNrenderTable, rtable, NULL);

Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94 (206)544-5225