[ Previous | Next | Contents | Glossary | Home | Search ]
Motif 2.1 Programmer's Guide

Motif Widget Printing

In this section, we examine the Motif widgets (mainly, XmText and XmLabel) and give hints about which widget resources need to be turned on or off in the printing case. This section also gives examples of sample code that copies data from a video widget to a corresponding print widget.

The assumption we make in this discussion is that we want to print the content of the widgets, rather than the visual representation of the widgets; in other words, our goal is not to print high-resolution screen dumps. Although it's impossible to define what constitutes the content of an arbitrary widget class (that is a sufficiently difficult task for the widgets we know), we can start by pointing out the resources that are important visually in Xt/Motif, in order to help the programmer set or unset them appropriately for printing.

Purely Visual Resources

At the Core class level, there are XmNbackground, which the application will probably want to set to white for paper output, and XmNborderWidth, which should be 0 (its default value).

For XmPrimitive, the XmNshadowThickness and XmNhighlightThickness resources are probably good candidates for 0 value as well, unless some three-dimensional effect is intended on the paper. XmNforeground should probably be black.

For the XmText and XmTextField widgets, one obvious setting is to turn off the blinking of the I-beam cursor. This happens automatically (refer to default dynamic and XmNcursorPositionVisible == False) if the widget is rooted to a XmPrintShell.

The print case almost certainly shouldn't print the scrollbars in a ScrolledText instance. The XmNscrollHorizontal and XmNscrollVertical resources can be set to False to suppress the printing of scrollbars. Note that, as a rule, it is better to avoid ScrolledText altogether in the case of printing.

For the Text widget, XmMwordWrap is a resource that deserves some attention; it's up to the programmer to decide what the application should do with it. If a wordwrap-on video text buffer is transferred to a print text buffer using (as is likely to be the case) a different character size, font, resolution, and so on (with wordwrap on as well), the number of pages will be different in the print and video cases. That's probably be fine since the number of pages on the video side should not be treated as content to be printed out: they are virtual pages, after all. If the video text has wordwrap off, the sequence of lines on the print side will be the same, and it's up to the application or its user to guarantee that this layout is appropriate for the print font, paper size, and so on, because no new formatting is done. The application can decide to take a wordwrap-on video text buffer and generate explicit newlines before passing it to the print text, so that the same layout is preserved. However, the application does so at the risk of allowing the content to run off the edge of the paper).

Finally, the Text widget also carries internal margins (XmNmarginWidth and XmNmarginHeight) that the print code might want to reset before printing.

For the XmLabel widget, the important visual resources are margins and alignment, since shadows and highlights are covered by XmPrimitive. XmLabel carries six margins resources (XmNmarginWidth, XmNmarginHeight, XmNmarginTop, XmNmarginBottom, XmNmarginRight, XmNmarginLeft) and the XmNaligment resource. These resources are mostly useful when the widget holds a border, highlight, or shadow of some kind. If borders are not to be transferred, there is no real need to transfer a margin either.

Content Resources

In connection with defining the content for XmText and XmLabel, the resource settings that the programmer would probably want to transfer to the print widget are the following: XmNvalue and XmNvalueWcs for the text widgets (or by using XmTextGetString/XmTextSetString). The XmText resource XmNtopCharacter may be relevant if the current page only is to be printed. XmTextSetHighlight can be used to highlight some text in a text widget.

For XmLabel, XmNlabelType ( PIXMAP or STRING), and XmNlabelString or XmNlabelPixmap are important resources.

In both the label and text cases, the setting of XmNstringDirection is probably inherited from the environment, so it's probably best to leave it alone.


In the following examples, a simple widget initialize method wants to know whether it is creating a widget for printing or video.

Widget CopyText(print_parent, video_text...)
    /* get the content out of the video text */
    buffer = XmTextGetString (video_text);
	    /* now create the print instance */
    ptext = XtVaCreateWidget(print_parent, ...,
	                             XmNvalue, buffer, NULL);
    return ptext;
Widget CopyLabel(print_parent, video_label...)
    /* get the string content out of the video label */
    XtVaGetValues(video_label, XmNlabelString, &buffer, NULL);
	    /* now create the print instance */
    plabel = XtVaCreateWidget(print_parent, ...,
	                              XmNlabelString, buffer, NULL);
    return plabel;

[ Previous | Next | Contents | Glossary | Home | Search ]