]> git.lyx.org Git - lyx.git/blob - src/PrinterParams.h
48718c7926dfb3382f2136073d7f2a6e512d7634
[lyx.git] / src / PrinterParams.h
1 // -*- C++ -*-
2 /**
3  * \file PrinterParams.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Allan Rae
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef PRINTERPARAMS_H
13 #define PRINTERPARAMS_H
14
15 #include "lyxrc.h"
16
17 #ifdef ENABLE_ASSERTIONS
18 #include "support/lstrings.h"
19 #include "support/LAssert.h"
20 #endif
21
22
23 /**
24   This struct contains (or should contain) all the parameters required for
25   printing a buffer.  Some work still needs to be done on this struct and
26   printing handling in general to make it nice and full-featured.
27   The main things I'd like to add now is the ability to print a read-only
28   document with different orientation, papersize or single/duplex state
29   than the document's settings. ARRae 20000423
30 */
31 struct PrinterParams {
32         ///
33         enum Target {
34                 ///
35                 PRINTER,
36                 ///
37                 FILE
38         };
39         ///
40         Target target;
41         ///
42         string printer_name;
43         ///
44         string file_name;
45         ///
46         bool all_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         unsigned int from_page;
55         ///
56         unsigned int to_page;
57         ///
58         bool odd_pages;
59         ///
60         bool even_pages;
61         ///
62         unsigned int count_copies;
63         ///
64         bool sorted_copies;
65         ///
66         bool reverse_order;
67         // The settings below should allow us to print any read-only doc in
68         // whatever size/orientation we want it -- overriding the documents
69         // settings.
70         // Override the documents orientation
71         // bool orientation;
72         // Print n pages per physical sheet
73         // unsigned int nup;
74         // Override document settings for duplex.
75         // bool duplex;
76
77         /** Test that all the fields contain valid entries.  It's unlikely
78             that the internal code will get this wrong (at least for the
79             xforms code anyway) however new ports and external scripts
80             might drive the wrong values in.
81          */
82         void testInvariant() const
83                 {
84 #ifdef ENABLE_ASSERTIONS
85                         switch (target) {
86                         case PRINTER:
87                                 //lyx::support::Assert(!printer_name.empty());
88                                 break;
89                         case FILE:
90                                 lyx::support::Assert(!file_name.empty());
91                                 break;
92                         default:
93                                 lyx::support::Assert(false);
94                                 break;
95                         }
96 #endif
97                 }
98
99         ///
100         PrinterParams(Target const & t = PRINTER,
101                       string const & pname = lyxrc.printer,
102                       string const & fname = string(),
103                       bool const all = true,
104                       unsigned int const & from = 1,
105                       unsigned int const & to = 0,
106                       bool const odd = true,
107                       bool const even = true,
108                       unsigned int const & copies = 1,
109                       bool const sorted = false,
110                       bool const reverse = false)
111                 : target(t),
112                   printer_name(pname),
113                   file_name(fname),
114                   all_pages(all),
115                   from_page(from),
116                   to_page(to),
117                   odd_pages(odd),
118                   even_pages(even),
119                   count_copies(copies),
120                   sorted_copies(sorted),
121                   reverse_order(reverse)
122                 {
123                         testInvariant();
124                 }
125         ///
126         PrinterParams(PrinterParams const & pp)
127                 : target(pp.target),
128                   printer_name(pp.printer_name),
129                   file_name(pp.file_name),
130                   all_pages(pp.all_pages),
131                   from_page(pp.from_page),
132                   to_page(pp.to_page),
133                   odd_pages(pp.odd_pages),
134                   even_pages(pp.even_pages),
135                   count_copies(pp.count_copies),
136                   sorted_copies(pp.sorted_copies),
137                   reverse_order(pp.reverse_order)
138                 {
139                         testInvariant();
140                 }
141 };
142
143 #endif