]> git.lyx.org Git - lyx.git/blob - src/PrinterParams.h
Dekel's patch -- I didn't fix the xforms-0.88 keysyms stuff so it still doesn't finis...
[lyx.git] / src / PrinterParams.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  * 
5  *          LyX, The Document Processor
6  *       
7  *          Copyright 1995 Matthias Ettrich
8  *          Copyright 1995-2000 The LyX Team
9  *
10  *          This file Copyright 1999-2000
11  *          Allan Rae
12  *======================================================
13  */
14
15 #ifndef PRINTERPARAMS_H
16 #define PRINTERPARAMS_H
17
18 #ifndef LYXRC_H
19 #error You must include lyxrc.h before PrinterParams.h
20 #endif
21
22 #ifdef ENABLE_ASSERTIONS
23 #include "support/LAssert.h"
24 #endif
25
26 /**
27   This struct contains (or should contain) all the parameters required for
28   printing a buffer.  Some work still needs to be done on this struct and
29   printing handling in general to make it nice and full-featured.
30   The main things I'd like to add now is the ability to print a read-only
31   document with different orientation, papersize or single/duplex state
32   than the document's settings. ARRae 20000423
33 */
34 struct PrinterParams {
35         ///
36         enum Target{
37                 ///
38                 PRINTER,
39                 ///
40                 FILE
41         };
42         ///
43         Target target;
44         ///
45         string printer_name;
46         ///
47         string file_name;
48         /// We allow printing of even pages in a range and so on.
49         enum WhichPages{
50                 ///
51                 ALL,
52                 ///
53                 ODD,
54                 ///
55                 EVEN
56         };
57         ///
58         WhichPages which_pages;
59         /** Print a page range. Both from_page and to_page used to be strings
60             because they're actually easier to work with that way.  I've
61             switched to_page to be an int.  However, from_page will remain a
62             string because I want the from_page field to be able to be used as
63             a page range "1,3-5" and so on.
64             I've modified the invariant test to match. ARRae 20000518
65          */
66         string from_page;
67         ///
68         int to_page;
69         ///
70         bool reverse_order;
71         ///
72         bool unsorted_copies;
73         ///
74         int count_copies;
75         // The settings below should allow us to print any read-only doc in
76         // whatever size/orientation we want it -- overriding the documents
77         // settings.
78         // Override the documents orientation
79         // bool orientation;
80         // Print n pages per physical sheet
81         // unsigned int nup;
82         // Override document settings for duplex.
83         // bool duplex;
84
85         ///
86         PrinterParams(Target const & t = PRINTER,
87                       string const & pname = lyxrc.printer,
88                       string const & fname = string(),
89                       WhichPages const wp = ALL,
90                       string const & from = string(),
91                       int const & to = 0,
92                       bool const reversed = false,
93                       bool const unsorted = false,
94                       int const & num_copies = 1)
95                 : target(t),
96                   printer_name(pname),
97                   file_name(fname),
98                   which_pages(wp),
99                   from_page(from),
100                   to_page(to),
101                   reverse_order(reversed),
102                   unsorted_copies(unsorted),
103                   count_copies(num_copies)
104                 {
105                         testInvariant();
106                 }
107         ///
108         PrinterParams(PrinterParams const & pp)
109                 : target(pp.target),
110                   printer_name(pp.printer_name),
111                   file_name(pp.file_name),
112                   which_pages(pp.which_pages),
113                   from_page(pp.from_page),
114                   to_page(pp.to_page),
115                   reverse_order(pp.reverse_order),
116                   unsorted_copies(pp.unsorted_copies),
117                   count_copies(pp.count_copies)
118                 {
119                         testInvariant();
120                 }
121
122 // do we need these?
123 //      friend bool operator==(PrinterParams const &, PrinterParams const &);
124 //      friend bool operator<(PrinterParams const &, PrinterParams const &);
125
126         /** Test that all the fields contain valid entries.  It's unlikely
127             that the internal code will get this wrong (at least for the
128             xforms code anyway) however new ports and external scripts
129             might drive the wrong values in.
130          */
131         void testInvariant() const
132                 {
133 #ifdef ENABLE_ASSERTIONS
134                         extern bool containsOnly(string const &, char const *);
135                         if (!from_page.empty()) {
136                                 // Assert(from_page == number or empty)
137                                 Assert(containsOnly(from_page, "1234567890"));
138                         }
139                         if (to_page) {
140                                 // Assert(to_page == empty
141                                 //        or number iff from_page set)
142                                 Assert(!from_page.empty());
143                         }
144                         switch (target) {
145                         case PRINTER:
146 //                              Assert(!printer_name.empty());
147                                 break;
148                         case FILE:
149                                 Assert(!file_name.empty());
150                                 break;
151                         default:
152                                 Assert(false);
153                                 break;
154                         }
155                         switch (which_pages) {
156                         case ALL:
157                         case ODD:
158                         case EVEN:
159                                 break;
160                         default:
161                                 Assert(false);
162                                 break;
163                         }
164 #endif
165                 }
166 };
167
168 #endif
169
170
171