1(*
2    Copyright (c) 2001, 2015
3        David C.J. Matthews
4
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License version 2.1 as published by the Free Software Foundation.
8
9    This library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13
14    You should have received a copy of the GNU Lesser General Public
15    License along with this library; if not, write to the Free Software
16    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17*)
18
19structure Printing :
20  sig
21    type HDC
22    type DOCINFO = { docName: string, output: string option, dType: string option}
23
24    val StartDoc : HDC * DOCINFO -> int
25    val StartPage : HDC -> unit
26    val AbortDoc : HDC -> unit
27    val EndDoc : HDC -> unit
28    val EndPage : HDC -> unit
29
30    datatype WMPrintOption =
31        PRF_CHECKVISIBLE | PRF_NONCLIENT | PRF_CLIENT | PRF_ERASEBKGND |
32        PRF_CHILDREN | PRF_OWNED
33  end =
34struct
35    local
36        open Foreign Base
37    in
38        type HDC = HDC
39        type DOCINFO = { docName: string, output: string option, dType: string option}
40
41        (* PRINTING AND SPOOLING. *)
42        local
43            val DOCINFO = cStruct5(cInt, cString, STRINGOPT, STRINGOPT, cDWORDw)
44            val {ctype={size=sizeDI, ...}, ...} = breakConversion DOCINFO
45            val startdoc = winCall2(gdi "StartDocA")(cHDC, DOCINFO) cInt
46        in
47
48            fun StartDoc(hdc: HDC, {docName, output, dType}): int =
49            let
50                val res = startdoc(hdc, (Word.toInt sizeDI, docName, output, dType, 0w0))
51            in
52                checkResult(res > 0);
53                res
54            end
55        end
56
57        local
58            fun checkSuccess res = checkResult(res > 0)
59        in
60            val EndDoc      = checkSuccess o winCall1(gdi "EndDoc") cHDC cInt
61            val StartPage   = checkSuccess o winCall1(gdi "StartPage") cHDC cInt
62            val EndPage     = checkSuccess o winCall1(gdi "EndPage") cHDC cInt
63            val AbortDoc    = checkSuccess o winCall1(gdi "AbortDoc") cHDC cInt
64        end
65
66        datatype WMPrintOption = datatype Message.WMPrintOption
67
68        (*
69        Other printing functions:
70            DeviceCapabilities
71            Escape
72            ExtEscape
73            SetAbortProc
74        *)
75
76    end
77end;
78