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>
80 #if 0 && defined(PRINTING_SUPPORTED)
82 #endif /* PRINTING_SUPPORTED */
84 #include <Dt/Editor.h>
87 #include "DmxPrintOutput.h"
88 #include "RoamMenuWindow.h"
91 // Used to initialize the top, right, bottom, and left margins
92 // between the outside edge of the page (_form) and the inner
93 // page that is written on.
95 const char *const DmxPrintOutput::_default_margin = ".5in";
97 DmxPrintOutput::DmxPrintOutput (
99 ) : UIComponent( "PrintOutput" )
102 DtMailBoolean parse_error;
107 w = XtVaCreateWidget("Page",
110 XmNresizePolicy, XmRESIZE_NONE,
115 w = XtVaCreateWidget("InnerPage",
118 XmNresizePolicy, XmRESIZE_NONE,
122 w = XtVaCreateManagedWidget("HeaderLeft",
125 XmNalignment, XmALIGNMENT_BEGINNING,
126 XmNleftAttachment, XmATTACH_FORM,
127 XmNtopAttachment, XmATTACH_FORM,
131 w = XtVaCreateManagedWidget("HeaderRight",
134 XmNalignment, XmALIGNMENT_END,
135 XmNrightAttachment, XmATTACH_FORM,
136 XmNleftAttachment, XmATTACH_WIDGET,
137 XmNleftWidget, _header_left,
138 XmNtopAttachment, XmATTACH_FORM,
142 w = XtVaCreateManagedWidget("Editor",
149 DtNscrollVertical, FALSE,
150 DtNscrollHorizontal, FALSE,
151 DtNshowStatusLine, FALSE,
153 XmNeditMode, XmMULTI_LINE_EDIT,
154 XmNleftAttachment, XmATTACH_FORM,
155 XmNrightAttachment, XmATTACH_FORM,
156 XmNtopAttachment, XmATTACH_WIDGET,
157 XmNtopWidget, _header_left,
161 w = XtVaCreateManagedWidget("FooterLeft",
164 XmNalignment, XmALIGNMENT_BEGINNING,
165 XmNleftAttachment, XmATTACH_FORM,
166 XmNbottomAttachment, XmATTACH_FORM,
170 w = XtVaCreateManagedWidget("FooterRight",
173 XmNalignment, XmALIGNMENT_END,
174 XmNleftAttachment, XmATTACH_WIDGET,
175 XmNleftWidget, _footer_left,
176 XmNrightAttachment, XmATTACH_FORM,
177 XmNbottomAttachment, XmATTACH_FORM,
183 XmNbottomAttachment, XmATTACH_WIDGET,
184 XmNbottomWidget, _footer_left,
187 installDestroyHandler();
188 XtManageChild(_inner_form);
189 XtManageChild(_form);
197 assert(!parse_error);
200 DmxPrintOutput::~DmxPrintOutput (void)
203 // Don't destroy anything here.
204 // The BasicComponent class takes care of destroying
209 void DmxPrintOutput::hideFooters (void)
211 XtUnmanageChild(_footer_left);
212 XtUnmanageChild(_footer_right);
213 XtVaSetValues(_editor, XmNbottomAttachment, XmATTACH_FORM, NULL);
216 void DmxPrintOutput::showFooters (void)
218 XtManageChild(_footer_left);
219 XtManageChild(_footer_right);
222 XmNbottomAttachment, XmATTACH_WIDGET,
223 XmNbottomWidget, _footer_left,
227 void DmxPrintOutput::hideHeaders (void)
229 XtUnmanageChild(_header_left);
230 XtUnmanageChild(_header_right);
231 XtVaSetValues(_editor, XmNtopAttachment, XmATTACH_FORM, NULL);
234 void DmxPrintOutput::showHeaders (void)
236 XtManageChild(_header_left);
237 XtManageChild(_header_right);
240 XmNtopAttachment, XmATTACH_WIDGET,
241 XmNtopWidget, _header_left,
247 DmxPrintOutput::setHdrFtrString (_DtPrintHdrFtrEnum which, char *label)
252 if (label == (char *) NULL)
257 case DTPRINT_OPTION_HEADER_LEFT:
260 case DTPRINT_OPTION_HEADER_RIGHT:
263 case DTPRINT_OPTION_FOOTER_LEFT:
266 case DTPRINT_OPTION_FOOTER_RIGHT:
270 // TBD: Need to log an error.
274 xms = XmStringCreateLocalized(label);
275 XtVaSetValues(w, XmNlabelString, xms, NULL);
280 DmxPrintOutput::setHdrFtrStrings (
291 xms = XmStringCreateLocalized(hdr_left);
292 XtVaSetValues(_header_left, XmNlabelString, xms, NULL);
298 xms = XmStringCreateLocalized(hdr_right);
299 XtVaSetValues(_header_right, XmNlabelString, xms, NULL);
305 xms = XmStringCreateLocalized(ftr_left);
306 XtVaSetValues(_footer_left, XmNlabelString, xms, NULL);
312 xms = XmStringCreateLocalized(ftr_right);
313 XtVaSetValues(_footer_right, XmNlabelString, xms, NULL);
319 DmxPrintOutput::setPageMargin (
320 _DtPrintMarginEnum which,
322 DtMailBoolean *parse_error
326 XtEnum xt_parse_error = FALSE;
327 char *marginstring = strdup(margin);
330 *parse_error = DTM_FALSE;
334 case DTPRINT_OPTION_MARGIN_TOP:
335 pixels = XmConvertStringToUnits(
336 XtScreenOfObject(_pshell),
341 if (!xt_parse_error && pixels > 0)
342 _margin_top = pixels;
344 case DTPRINT_OPTION_MARGIN_RIGHT:
345 pixels = XmConvertStringToUnits(
346 XtScreenOfObject(_pshell),
351 if (!xt_parse_error && pixels > 0)
352 _margin_right = pixels;
354 case DTPRINT_OPTION_MARGIN_BOTTOM:
355 _margin_bottom = pixels;
356 pixels = XmConvertStringToUnits(
357 XtScreenOfObject(_pshell),
362 if (!xt_parse_error && pixels > 0)
363 _margin_bottom = pixels;
365 case DTPRINT_OPTION_MARGIN_LEFT:
366 pixels = XmConvertStringToUnits(
367 XtScreenOfObject(_pshell),
372 if (!xt_parse_error && pixels > 0)
373 _margin_left = pixels;
376 // TBD: Need to log an error.
381 setInnerPageDimensions(
387 *parse_error = DTM_TRUE;
393 DmxPrintOutput::setPageMargin (_DtPrintMarginEnum which, int margin)
395 Dimension pixels = (Dimension) margin;
399 case DTPRINT_OPTION_MARGIN_TOP:
400 _margin_top = pixels;
402 case DTPRINT_OPTION_MARGIN_RIGHT:
403 _margin_right = pixels;
405 case DTPRINT_OPTION_MARGIN_BOTTOM:
406 _margin_bottom = pixels;
408 case DTPRINT_OPTION_MARGIN_LEFT:
409 _margin_left = pixels;
412 // TBD: Need to log an error.
416 setInnerPageDimensions(
424 DmxPrintOutput::setPageMargins (
429 DtMailBoolean *parse_error
433 XtEnum xt_parse_error = FALSE;
436 *parse_error = DTM_FALSE;
438 margin = strdup(top);
439 pixels = XmConvertStringToUnits(
440 XtScreenOfObject(_pshell),
446 if (!xt_parse_error && pixels > 0)
448 _margin_top = pixels;
452 *parse_error = DTM_TRUE;
456 margin = strdup(right);
457 pixels = XmConvertStringToUnits(
458 XtScreenOfObject(_pshell),
464 if (!xt_parse_error && pixels > 0)
466 _margin_right = pixels;
470 *parse_error = DTM_TRUE;
474 margin = strdup(bottom);
475 pixels = XmConvertStringToUnits(
476 XtScreenOfObject(_pshell),
482 if (!xt_parse_error && pixels > 0)
484 _margin_bottom = pixels;
488 *parse_error = DTM_TRUE;
492 margin = strdup(left);
493 pixels = XmConvertStringToUnits(
494 XtScreenOfObject(_pshell),
500 if (!xt_parse_error && pixels > 0)
502 _margin_left = pixels;
506 *parse_error = DTM_TRUE;
510 setInnerPageDimensions(
518 DmxPrintOutput::setPageMargins (
525 _margin_top = (top > 0) ? (Dimension) top : _margin_top;
526 _margin_right = (right > 0) ? (Dimension) right : _margin_right;
527 _margin_bottom = (bottom > 0) ? (Dimension) bottom : _margin_bottom;
528 _margin_left = (left > 0) ? (Dimension) left : _margin_left;
530 setInnerPageDimensions(
538 DmxPrintOutput::setWrapToFit (DtMailBoolean onoff)
541 XtVaSetValues(_editor, DtNwordWrap, onoff, NULL);
543 XtVaSetValues(_editor, XmNwordWrap, onoff, NULL);
549 int DmxPrintOutput::getCharactersPerLine ()
551 XtArgVal columns = 0;
554 XtVaGetValues(_editor, DtNcolumns, &columns, NULL);
556 XtVaGetValues(_editor, XmNcolumns, &columns, NULL);
558 return((int) columns);
563 int DmxPrintOutput::getNumLines ()
569 XtVaGetValues(_editor, XmNtotalLines, &total, NULL);
571 // Correct for off by one error.
579 int DmxPrintOutput::getLastPosition ()
584 last = DtEditorGetLastPosition(_editor);
586 last = XmTextGetLastPosition(_editor);
591 int DmxPrintOutput::getTopPosition ()
596 XtVaGetValues(_editor, DtNtopCharacter, &top, NULL);
598 top = XmTextGetTopCharacter(_editor);
603 DtMailBoolean DmxPrintOutput::pageUp ()
605 XmTextPosition top_before, top_after;
610 top_before = XmTextGetTopCharacter(_editor);
611 XmTextScroll(_editor, -1 * _lines_per_page);
612 top_after = XmTextGetTopCharacter(_editor);
614 return (top_before > top_after) ? DTM_TRUE : DTM_FALSE;
618 DtMailBoolean DmxPrintOutput::pageDown ()
620 XmTextPosition top_before, top_after;
625 top_before = XmTextGetTopCharacter(_editor);
626 XmTextScroll(_editor, _lines_per_page);
627 top_after = XmTextGetTopCharacter(_editor);
629 return (top_before < top_after) ? DTM_TRUE : DTM_FALSE;
633 void DmxPrintOutput::setTopPosition ( int pos )
635 XmTextPosition top = (XmTextPosition) pos;
638 XtVaSetValues(_editor, DtNtopCharacter, top, NULL);
640 XmTextSetTopCharacter(_editor, top);
644 void DmxPrintOutput::appendContents (void* stream, char *contents)
646 DmxPrintOutput *thisOutput = (DmxPrintOutput *) stream;
649 DtEditorContentRec rec;
651 rec.type = DtEDITOR_TEXT;
652 rec.value.string = contents;
653 DtEditorInsert(thisOutput->_editor, &rec);
657 pos = XmTextGetLastPosition(thisOutput->_editor);
658 XmTextInsert(thisOutput->_editor, pos, contents);
662 void DmxPrintOutput::appendNewLine ()
664 #ifdef PRINT_TO_VIDEO
665 char *contents = "=========== NewLine ==========\n";
667 char *contents = "\n";
669 appendContents((XtPointer) this, contents);
672 void DmxPrintOutput::appendPageBreak ()
675 char *contents = "\n";
678 nlines = getNumLines();
679 missing = ((nlines % _lines_per_page) > 0) ?
680 (_lines_per_page - (nlines % _lines_per_page)) :
686 #ifdef PRINT_TO_VIDEO
687 for (int i=0; i<missing; i++)
691 sprintf(buffer, "Page Break Line: %d\n", i);
692 appendContents((XtPointer) this, buffer);
696 "Total Lines: %d; Lines Per Page: %d; Missing Lines: %d\n",
701 buf = (char *) malloc((missing * 2) + 1);
702 for (int i=0; i<missing; i++)
703 strcat(buf, contents);
705 appendContents(this, contents);
711 void DmxPrintOutput::clearContents (void)
714 DtEditorContentRec content;
716 content.type = DtEDITOR_TEXT;
717 rec.value.string = NULL;
718 status = DtEditorSetContents(my_text, &content);
720 XmTextSetString(_editor, "");
726 * Private class methods
729 DmxPrintOutput::doGetLinesPerPage ()
731 XtArgVal /* Dimension */ lpp;
733 XtVaGetValues(_editor, XmNrows, &lpp, NULL);
739 DmxPrintOutput::setInnerPageDimensions (
746 XtArgVal height0, width0;
747 Dimension inner_height, inner_width, inner_x, inner_y,
748 outer_height, outer_width,
749 editor_height, footer_height, header_height;
755 outer_height = (Dimension)height0;
756 outer_width = (Dimension)width0;
758 XtVaGetValues(_header_left,
761 header_height = (Dimension)height0;
763 XtVaGetValues(_footer_left,
766 footer_height = (Dimension)height0;
770 inner_height = ((int) outer_height > (top + bottom)) ?
771 (outer_height - (top + bottom)) :
773 inner_width = ((int) outer_width > (left + right)) ?
774 (outer_width - (left + right)) :
776 editor_height = ((int) inner_height > (header_height + footer_height)) ?
777 (inner_height - (header_height + footer_height)) :
780 XtVaSetValues(_editor, XmNheight, editor_height, NULL);
782 XtVaSetValues(_inner_form,
783 XmNleftAttachment, XmATTACH_NONE,
784 XmNtopAttachment, XmATTACH_NONE,
787 XmNheight, inner_height,
788 XmNwidth, inner_width,
791 _lines_per_page = doGetLinesPerPage();