Project

General

Profile

_osprint.p

Hynek Cihlar, 10/24/2017 04:32 PM

Download (8.5 KB)

 
1
/*********************************************************************
2
* Copyright (C) 2000 by Progress Software Corporation ("PSC"),       *
3
* 14 Oak Park, Bedford, MA 01730, and other contributors as listed   *
4
* below.  All Rights Reserved.                                       *
5
*                                                                    *
6
* The Initial Developer of the Original Code is PSC.  The Original   *
7
* Code is Progress IDE code released to open source December 1, 2000.*
8
*                                                                    *
9
* The contents of this file are subject to the Possenet Public       *
10
* License Version 1.0 (the "License"); you may not use this file     *
11
* except in compliance with the License.  A copy of the License is   *
12
* available as of the date of this notice at                         *
13
* http://www.possenet.org/license.html                               *
14
*                                                                    *
15
* Software distributed under the License is distributed on an "AS IS"*
16
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. You*
17
* should refer to the License for the specific language governing    *
18
* rights and limitations under the License.                          *
19
*                                                                    *
20
* Contributors:                                                      *
21
*                                                                    *
22
*********************************************************************/
23

    
24
/****************************************************************************
25
    File       _osprint.p
26
    
27
    Syntax     
28
               RUN adecomm/_osprint.p ( INPUT  p_Window,
29
                                        INPUT  p_PrintFile,
30
                                        INPUT  p_FontNumber,
31
                                        INPUT  p_PrintFlags,
32
                                        INPUT  p_PageSize,
33
                                        INPUT  p_PageCount,
34
                                        OUTPUT p_Printed ).
35
   
36
    Purpose    Send a specified operating system text file to the default
37
               printer.
38

    
39
    Remarks    Output is sent to printer as PAGED output, with a default
40
               page size of zero. This lets the printer handle the paging.
41
               The page size can be specified using p_PageSize.
42

    
43
               Max characters per line: 255.
44
               
45
               Under MS-Windows, the MSW Print Setup dialog box
46
               is called via a PROGRESS DLL (PROPRINT.DLL) and the
47
               SESSION:PRINTER-CONTROL-HANDLE is always cleared.
48

    
49
    Author     J. Palazzo
50
    Created    Mar  1994
51
    Updated    Mar  1999  Removed 16-bit proprint.dll entry and call.
52
****************************************************************************/
53

    
54
DEFINE INPUT  PARAMETER p_Window      AS WIDGET    NO-UNDO.
55
    /* Parent window for Dialogs and Message boxes. Default
56
       to CURRENT-WINDOW if p_Window is not valid. */
57
    
58
DEFINE INPUT  PARAMETER p_PrintFile   AS CHAR      NO-UNDO.
59
    /* Text file to print. Can be specified relative to PROPATH. */
60
    
61
DEFINE INPUT  PARAMETER p_FontNumber  AS INTEGER   NO-UNDO.
62
    /* PROGRESS Font Number to use when printing file.  MSW Only.
63
       This may not match screen font exactly and the printer
64
       driver will make the ultimate choice, not PROGRESS. */
65

    
66
DEFINE INPUT  PARAMETER p_PrintFlags  AS INTEGER   NO-UNDO.
67
    /*  Integer expression that specifies various print options.
68
        The table below lists the flag values that correspond to
69
        each print option. If a zero (0) value is passed, option
70
        defaults are used.
71

    
72
        Print Option        Flag Value  Meaning
73

    
74
        useDialog               1       Display the MSW Print Setup Dialog.
75
                                        Default is to not display the Print
76
                                        dialog.
77
                                        
78
        useLandscape            2       Set print orientation to Landscape.
79
                                        Default orientation is set in the
80
                                        printer properties in the Control
81
                                        Panel.
82

    
83
        You can specify any combination of these flags. For
84
        example, you can pass three (1 + 2) as an input parameter to
85
        specify that the Print Setup Dialog be displayed and that
86
        the print orientation be landscape. */
87

    
88
DEFINE INPUT  PARAMETER p_PageSize    AS INTEGER  NO-UNDO.
89
    /* Page length - number of lines per page. */
90
    
91
DEFINE INPUT  PARAMETER p_PageCount   AS INTEGER  NO-UNDO.
92
    /* If non-zero, then enable the page range selection controls
93
       in the printer setup dialog. If zero, the entire text file
94
       is printed. */
95
    
96
DEFINE OUTPUT PARAMETER p_Printed     AS LOGICAL INIT TRUE NO-UNDO .
97
    /* Returns TRUE if able to complete the OUTPUT TO PRINTER. */
98

    
99
DEFINE STREAM In_Stream.
100
DEFINE STREAM Out_Stream.
101

    
102
DEFINE VAR Text_Line      AS CHARACTER FORMAT "x(255)" NO-UNDO .
103
DEFINE VAR PrintResult    AS INTEGER   INITIAL 0       NO-UNDO .
104
DEFINE VAR PrintStatus    AS LOGICAL   INITIAL TRUE    NO-UNDO .
105

    
106

    
107
DO ON STOP  UNDO, RETRY ON ERROR UNDO, RETRY:
108
  IF NOT RETRY THEN
109
  DO:
110
    /* Point to a valid window handle. */
111
    ASSIGN p_Window = IF VALID-HANDLE( p_Window ) THEN
112
                        p_Window
113
                      ELSE IF VALID-HANDLE( CURRENT-WINDOW ) THEN
114
                        CURRENT-WINDOW
115
                      ELSE
116
                         DEFAULT-WINDOW.
117
                              
118
    /* Get file info on file to print. */
119
    ASSIGN FILE-INFO:FILE-NAME = p_PrintFile NO-ERROR .
120
    IF ( FILE-INFO:FULL-PATHNAME = ? ) THEN
121
    DO:
122
      MESSAGE "Unable to find file to print."
123
        VIEW-AS ALERT-BOX ERROR BUTTONS OK IN WINDOW p_Window.
124
      STOP.
125
    END.
126
    ASSIGN p_PrintFile = FILE-INFO:FULL-PATHNAME.
127

    
128
    /* Run Proprint DLL for Windows and 32bit Windows Char Console. */        
129
    IF (SESSION:WINDOW-SYSTEM BEGINS "MS-WIN") OR
130
       (OPSYS = "WIN32" AND SESSION:WINDOW-SYSTEM = "TTY") THEN
131
    DO:
132
      /* Clear the current print handle. */
133
      ASSIGN SESSION:PRINTER-CONTROL-HANDLE = ?.
134

    
135
      /* Print dialog with PORTRAIT option */
136
      IF (p_PrintFlags = 1) THEN DO:
137
        SYSTEM-DIALOG PRINTER-SETUP PORTRAIT IN WINDOW p_Window UPDATE PrintStatus.
138
      END.
139

    
140
      /* Print dialog with LANDSCAPE option */
141
      ELSE IF (p_PrintFlags = 3) THEN DO:
142
        SYSTEM-DIALOG PRINTER-SETUP LANDSCAPE IN WINDOW p_Window UPDATE PrintStatus.
143
      END.
144

    
145
      IF (PrintStatus) THEN DO:
146
        RUN PrintFile.
147
      END.
148

    
149
      ASSIGN p_Printed = PrintStatus.
150
    END.
151
    ELSE
152
    DO:
153
        /* All other operating environments/windowing systems.
154
           Break out into a CASE statement to customize.  */
155
        RUN PrintFile.
156
    END.
157
  END. /* NOT RETRY */
158
  ELSE 
159
    ASSIGN p_Printed = FALSE.
160
        
161
  INPUT  STREAM In_Stream  CLOSE.
162
  OUTPUT STREAM Out_Stream CLOSE.
163
END.
164

    
165
/* -----------------------------------------------------------------------*/ 
166
PROCEDURE ProPrintFile EXTERNAL "PROPRINT.DLL":
167
  /* Internal Procedure call to MS-Windows DLL to Print Setup dialog.  */
168
  
169
  DEFINE INPUT  PARAMETER hControl        AS LONG.
170
  DEFINE INPUT  PARAMETER fPrintFlags     AS LONG.
171
  DEFINE INPUT  PARAMETER hWndParent      AS LONG.
172
  DEFINE INPUT  PARAMETER nFontNo         AS LONG.
173
  DEFINE INPUT  PARAMETER lpszFile        AS CHARACTER.
174
  DEFINE INPUT  PARAMETER nPages          AS LONG.
175
  DEFINE RETURN PARAMETER Print_Result    AS LONG.
176
END.
177

    
178
/* -----------------------------------------------------------------------*/ 
179
PROCEDURE PrintFile: 
180
  /* Print an operating system file via simple OUTPUT TO PRINTER. */
181

    
182
  INPUT  STREAM In_Stream  FROM VALUE(p_PrintFile) NO-ECHO NO-MAP.
183

    
184
  IF (p_PrintFlags = 2) THEN DO:
185
    OUTPUT STREAM Out_Stream TO   PRINTER LANDSCAPE PAGE-SIZE VALUE( p_PageSize ) FONT VALUE(p_FontNumber).
186
  END.
187
  ELSE IF (p_PrintFlags = 1 OR p_PrintFlags = 3) THEN DO:
188
    /* page orientation will be taken from print dialog */
189
    OUTPUT STREAM Out_Stream TO   PRINTER PAGE-SIZE VALUE( p_PageSize ) FONT VALUE(p_FontNumber).
190
  END.
191
  ELSE DO:
192
    OUTPUT STREAM Out_Stream TO   PRINTER PORTRAIT  PAGE-SIZE VALUE( p_PageSize ) FONT VALUE(p_FontNumber).
193
  END.
194

    
195
  /* Frame must be down frame, so scope to REPEAT. */
196
  REPEAT ON STOP UNDO, LEAVE WITH FRAME f_Print:
197
    IMPORT STREAM In_Stream UNFORMATTED Text_Line.
198
    DISPLAY STREAM Out_Stream Text_Line 
199
      WITH FRAME f_Print NO-LABELS STREAM-IO
200
      NO-BOX USE-TEXT WIDTH 255.
201
  END.
202
END PROCEDURE.
203

    
204
/* _osprint.p - end of file */