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