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