2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: DmxPrintOutput.C /main/6 1997/07/07 13:57:21 mgreess $ */
30 * RESTRICTED CONFIDENTIAL INFORMATION:
32 * The information in this document is subject to special
33 * restrictions in a confidential disclosure agreement between
34 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
35 * document outside HP, IBM, Sun, USL, SCO, or Univel without
36 * Sun's specific written approval. This document and all copies
37 * and derivative works thereof must be returned or destroyed at
40 * Copyright 1994 Sun Microsystems, Inc. All rights reserved.
45 * Common Desktop Environment
47 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
48 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
49 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
50 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
51 * (c) Copyright 1995 Digital Equipment Corp.
52 * (c) Copyright 1995 Fujitsu Limited
53 * (c) Copyright 1995 Hitachi, Ltd.
56 * RESTRICTED RIGHTS LEGEND
58 *Use, duplication, or disclosure by the U.S. Government is subject to
59 *restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
60 *Technical Data and Computer Software clause in DFARS 252.227-7013. Rights
61 *for non-DOD U.S. Government Departments and Agencies are as set forth in
62 *FAR 52.227-19(c)(1,2).
64 *Hewlett-Packard Company, 3000 Hanover Street, Palo Alto, CA 94304 U.S.A.
65 *International Business Machines Corp., Route 100, Somers, NY 10589 U.S.A.
66 *Sun Microsystems, Inc., 2550 Garcia Avenue, Mountain View, CA 94043 U.S.A.
67 *Novell, Inc., 190 River Road, Summit, NJ 07901 U.S.A.
68 *Digital Equipment Corp., 111 Powdermill Road, Maynard, MA 01754, U.S.A.
69 *Fujitsu Limited, 1015, Kamikodanaka Nakahara-Ku, Kawasaki 211, Japan
70 *Hitachi, Ltd., 6, Kanda Surugadai 4-Chome, Chiyoda-ku, Tokyo 101, Japan
75 #include <X11/Intrinsic.h>
77 #include <Xm/DialogS.h>
82 #include <Dt/Editor.h>
85 #include "DmxPrintOutput.h"
86 #include "RoamMenuWindow.h"
89 // Used to initialize the top, right, bottom, and left margins
90 // between the outside edge of the page (_form) and the inner
91 // page that is written on.
93 const char *const DmxPrintOutput::_default_margin = ".5in";
95 DmxPrintOutput::DmxPrintOutput (
97 ) : UIComponent( "PrintOutput" )
100 DtMailBoolean parse_error;
105 w = XtVaCreateWidget("Page",
108 XmNresizePolicy, XmRESIZE_NONE,
113 w = XtVaCreateWidget("InnerPage",
116 XmNresizePolicy, XmRESIZE_NONE,
120 w = XtVaCreateManagedWidget("HeaderLeft",
123 XmNalignment, XmALIGNMENT_BEGINNING,
124 XmNleftAttachment, XmATTACH_FORM,
125 XmNtopAttachment, XmATTACH_FORM,
129 w = XtVaCreateManagedWidget("HeaderRight",
132 XmNalignment, XmALIGNMENT_END,
133 XmNrightAttachment, XmATTACH_FORM,
134 XmNleftAttachment, XmATTACH_WIDGET,
135 XmNleftWidget, _header_left,
136 XmNtopAttachment, XmATTACH_FORM,
140 w = XtVaCreateManagedWidget("Editor",
147 DtNscrollVertical, FALSE,
148 DtNscrollHorizontal, FALSE,
149 DtNshowStatusLine, FALSE,
151 XmNeditMode, XmMULTI_LINE_EDIT,
152 XmNleftAttachment, XmATTACH_FORM,
153 XmNrightAttachment, XmATTACH_FORM,
154 XmNtopAttachment, XmATTACH_WIDGET,
155 XmNtopWidget, _header_left,
159 w = XtVaCreateManagedWidget("FooterLeft",
162 XmNalignment, XmALIGNMENT_BEGINNING,
163 XmNleftAttachment, XmATTACH_FORM,
164 XmNbottomAttachment, XmATTACH_FORM,
168 w = XtVaCreateManagedWidget("FooterRight",
171 XmNalignment, XmALIGNMENT_END,
172 XmNleftAttachment, XmATTACH_WIDGET,
173 XmNleftWidget, _footer_left,
174 XmNrightAttachment, XmATTACH_FORM,
175 XmNbottomAttachment, XmATTACH_FORM,
181 XmNbottomAttachment, XmATTACH_WIDGET,
182 XmNbottomWidget, _footer_left,
185 installDestroyHandler();
186 XtManageChild(_inner_form);
187 XtManageChild(_form);
195 assert(!parse_error);
198 DmxPrintOutput::~DmxPrintOutput (void)
201 // Don't destroy anything here.
202 // The BasicComponent class takes care of destroying
207 void DmxPrintOutput::hideFooters (void)
209 XtUnmanageChild(_footer_left);
210 XtUnmanageChild(_footer_right);
211 XtVaSetValues(_editor, XmNbottomAttachment, XmATTACH_FORM, NULL);
214 void DmxPrintOutput::showFooters (void)
216 XtManageChild(_footer_left);
217 XtManageChild(_footer_right);
220 XmNbottomAttachment, XmATTACH_WIDGET,
221 XmNbottomWidget, _footer_left,
225 void DmxPrintOutput::hideHeaders (void)
227 XtUnmanageChild(_header_left);
228 XtUnmanageChild(_header_right);
229 XtVaSetValues(_editor, XmNtopAttachment, XmATTACH_FORM, NULL);
232 void DmxPrintOutput::showHeaders (void)
234 XtManageChild(_header_left);
235 XtManageChild(_header_right);
238 XmNtopAttachment, XmATTACH_WIDGET,
239 XmNtopWidget, _header_left,
245 DmxPrintOutput::setHdrFtrString (_DtPrintHdrFtrEnum which, char *label)
250 if (label == (char *) NULL)
255 case DTPRINT_OPTION_HEADER_LEFT:
258 case DTPRINT_OPTION_HEADER_RIGHT:
261 case DTPRINT_OPTION_FOOTER_LEFT:
264 case DTPRINT_OPTION_FOOTER_RIGHT:
268 // TBD: Need to log an error.
272 xms = XmStringCreateLocalized(label);
273 XtVaSetValues(w, XmNlabelString, xms, NULL);
278 DmxPrintOutput::setHdrFtrStrings (
289 xms = XmStringCreateLocalized(hdr_left);
290 XtVaSetValues(_header_left, XmNlabelString, xms, NULL);
296 xms = XmStringCreateLocalized(hdr_right);
297 XtVaSetValues(_header_right, XmNlabelString, xms, NULL);
303 xms = XmStringCreateLocalized(ftr_left);
304 XtVaSetValues(_footer_left, XmNlabelString, xms, NULL);
310 xms = XmStringCreateLocalized(ftr_right);
311 XtVaSetValues(_footer_right, XmNlabelString, xms, NULL);
317 DmxPrintOutput::setPageMargin (
318 _DtPrintMarginEnum which,
320 DtMailBoolean *parse_error
324 XtEnum xt_parse_error = FALSE;
325 char *marginstring = strdup(margin);
328 *parse_error = DTM_FALSE;
332 case DTPRINT_OPTION_MARGIN_TOP:
333 pixels = XmConvertStringToUnits(
334 XtScreenOfObject(_pshell),
339 if (!xt_parse_error && pixels > 0)
340 _margin_top = pixels;
342 case DTPRINT_OPTION_MARGIN_RIGHT:
343 pixels = XmConvertStringToUnits(
344 XtScreenOfObject(_pshell),
349 if (!xt_parse_error && pixels > 0)
350 _margin_right = pixels;
352 case DTPRINT_OPTION_MARGIN_BOTTOM:
353 _margin_bottom = pixels;
354 pixels = XmConvertStringToUnits(
355 XtScreenOfObject(_pshell),
360 if (!xt_parse_error && pixels > 0)
361 _margin_bottom = pixels;
363 case DTPRINT_OPTION_MARGIN_LEFT:
364 pixels = XmConvertStringToUnits(
365 XtScreenOfObject(_pshell),
370 if (!xt_parse_error && pixels > 0)
371 _margin_left = pixels;
374 // TBD: Need to log an error.
379 setInnerPageDimensions(
385 *parse_error = DTM_TRUE;
391 DmxPrintOutput::setPageMargin (_DtPrintMarginEnum which, int margin)
393 Dimension pixels = (Dimension) margin;
397 case DTPRINT_OPTION_MARGIN_TOP:
398 _margin_top = pixels;
400 case DTPRINT_OPTION_MARGIN_RIGHT:
401 _margin_right = pixels;
403 case DTPRINT_OPTION_MARGIN_BOTTOM:
404 _margin_bottom = pixels;
406 case DTPRINT_OPTION_MARGIN_LEFT:
407 _margin_left = pixels;
410 // TBD: Need to log an error.
414 setInnerPageDimensions(
422 DmxPrintOutput::setPageMargins (
427 DtMailBoolean *parse_error
431 XtEnum xt_parse_error = FALSE;
434 *parse_error = DTM_FALSE;
436 margin = strdup(top);
437 pixels = XmConvertStringToUnits(
438 XtScreenOfObject(_pshell),
444 if (!xt_parse_error && pixels > 0)
446 _margin_top = pixels;
450 *parse_error = DTM_TRUE;
454 margin = strdup(right);
455 pixels = XmConvertStringToUnits(
456 XtScreenOfObject(_pshell),
462 if (!xt_parse_error && pixels > 0)
464 _margin_right = pixels;
468 *parse_error = DTM_TRUE;
472 margin = strdup(bottom);
473 pixels = XmConvertStringToUnits(
474 XtScreenOfObject(_pshell),
480 if (!xt_parse_error && pixels > 0)
482 _margin_bottom = pixels;
486 *parse_error = DTM_TRUE;
490 margin = strdup(left);
491 pixels = XmConvertStringToUnits(
492 XtScreenOfObject(_pshell),
498 if (!xt_parse_error && pixels > 0)
500 _margin_left = pixels;
504 *parse_error = DTM_TRUE;
508 setInnerPageDimensions(
516 DmxPrintOutput::setPageMargins (
523 _margin_top = (top > 0) ? (Dimension) top : _margin_top;
524 _margin_right = (right > 0) ? (Dimension) right : _margin_right;
525 _margin_bottom = (bottom > 0) ? (Dimension) bottom : _margin_bottom;
526 _margin_left = (left > 0) ? (Dimension) left : _margin_left;
528 setInnerPageDimensions(
536 DmxPrintOutput::setWrapToFit (DtMailBoolean onoff)
539 XtVaSetValues(_editor, DtNwordWrap, onoff, NULL);
541 XtVaSetValues(_editor, XmNwordWrap, onoff, NULL);
547 int DmxPrintOutput::getCharactersPerLine ()
552 XtVaGetValues(_editor, DtNcolumns, &columns, NULL);
554 XtVaGetValues(_editor, XmNcolumns, &columns, NULL);
556 return((int) columns);
561 int DmxPrintOutput::getNumLines ()
567 XtVaGetValues(_editor, XmNtotalLines, &total, NULL);
569 // Correct for off by one error.
577 int DmxPrintOutput::getLastPosition ()
582 last = DtEditorGetLastPosition(_editor);
584 last = XmTextGetLastPosition(_editor);
589 int DmxPrintOutput::getTopPosition ()
594 XtVaGetValues(_editor, DtNtopCharacter, &top, NULL);
596 top = XmTextGetTopCharacter(_editor);
601 DtMailBoolean DmxPrintOutput::pageUp ()
603 XmTextPosition top_before, top_after;
608 top_before = XmTextGetTopCharacter(_editor);
609 XmTextScroll(_editor, -1 * _lines_per_page);
610 top_after = XmTextGetTopCharacter(_editor);
612 return (top_before > top_after) ? DTM_TRUE : DTM_FALSE;
616 DtMailBoolean DmxPrintOutput::pageDown ()
618 XmTextPosition top_before, top_after;
623 top_before = XmTextGetTopCharacter(_editor);
624 XmTextScroll(_editor, _lines_per_page);
625 top_after = XmTextGetTopCharacter(_editor);
627 return (top_before < top_after) ? DTM_TRUE : DTM_FALSE;
631 void DmxPrintOutput::setTopPosition ( int pos )
633 XmTextPosition top = (XmTextPosition) pos;
636 XtVaSetValues(_editor, DtNtopCharacter, top, NULL);
638 XmTextSetTopCharacter(_editor, top);
642 void DmxPrintOutput::appendContents (void* stream, char *contents)
644 DmxPrintOutput *thisOutput = (DmxPrintOutput *) stream;
647 DtEditorContentRec rec;
649 rec.type = DtEDITOR_TEXT;
650 rec.value.string = contents;
651 DtEditorInsert(thisOutput->_editor, &rec);
655 pos = XmTextGetLastPosition(thisOutput->_editor);
656 XmTextInsert(thisOutput->_editor, pos, contents);
660 void DmxPrintOutput::appendNewLine ()
662 #ifdef PRINT_TO_VIDEO
663 char *contents = "=========== NewLine ==========\n";
665 char *contents = "\n";
667 appendContents((XtPointer) this, contents);
670 void DmxPrintOutput::appendPageBreak ()
673 char *contents = "\n";
676 nlines = getNumLines();
677 missing = ((nlines % _lines_per_page) > 0) ?
678 (_lines_per_page - (nlines % _lines_per_page)) :
684 #ifdef PRINT_TO_VIDEO
685 for (int i=0; i<missing; i++)
689 sprintf(buffer, "Page Break Line: %d\n", i);
690 appendContents((XtPointer) this, buffer);
694 "Total Lines: %d; Lines Per Page: %d; Missing Lines: %d\n",
699 buf = (char *) malloc((missing * 2) + 1);
700 for (int i=0; i<missing; i++)
701 strcat(buf, contents);
703 appendContents(this, contents);
709 void DmxPrintOutput::clearContents (void)
712 DtEditorContentRec content;
714 content.type = DtEDITOR_TEXT;
715 rec.value.string = NULL;
716 status = DtEditorSetContents(my_text, &content);
718 XmTextSetString(_editor, "");
724 * Private class methods
727 DmxPrintOutput::doGetLinesPerPage ()
731 XtVaGetValues(_editor, XmNrows, &lpp, NULL);
737 DmxPrintOutput::setInnerPageDimensions (
744 Dimension inner_height, inner_width, inner_x, inner_y,
745 outer_height, outer_width,
746 editor_height, footer_height, header_height;
749 XmNheight, &outer_height,
750 XmNwidth, &outer_width,
753 XtVaGetValues(_header_left,
754 XmNheight, &header_height,
757 XtVaGetValues(_footer_left,
758 XmNheight, &footer_height,
763 inner_height = ((int) outer_height > (top + bottom)) ?
764 (outer_height - (top + bottom)) :
766 inner_width = ((int) outer_width > (left + right)) ?
767 (outer_width - (left + right)) :
769 editor_height = ((int) inner_height > (header_height + footer_height)) ?
770 (inner_height - (header_height + footer_height)) :
773 XtVaSetValues(_editor, XmNheight, editor_height, NULL);
775 XtVaSetValues(_inner_form,
776 XmNleftAttachment, XmATTACH_NONE,
777 XmNtopAttachment, XmATTACH_NONE,
780 XmNheight, inner_height,
781 XmNwidth, inner_width,
784 _lines_per_page = doGetLinesPerPage();