3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS.
13 #include "ControlPrint.h"
15 #include "ButtonController.h"
16 #include "helper_funcs.h"
19 #include "bufferparams.h"
20 #include "funcrequest.h"
22 #include "PrinterParams.h"
24 #include "support/tostr.h"
25 #include "support/filetools.h"
26 #include "support/globbing.h"
28 using lyx::support::ChangeExtension;
29 using lyx::support::FileFilterList;
33 ControlPrint::ControlPrint(Dialog & parent)
34 : Dialog::Controller(parent),
39 bool ControlPrint::initialiseParams(std::string const &)
41 /// get global printer parameters
42 string const name = ChangeExtension(kernel().buffer().fileName(),
43 lyxrc.print_file_extension);
44 params_.reset(new PrinterParams (PrinterParams::PRINTER,
45 lyxrc.printer, name));
47 dialog().bc().valid(); // so that the user can press Ok
52 void ControlPrint::clearParams()
58 PrinterParams & ControlPrint::params() const
60 BOOST_ASSERT(params_.get());
65 string const ControlPrint::browse(string const & in_name) const
67 return browseRelFile(in_name, kernel().buffer().filePath(),
69 FileFilterList("PostScript files (*.ps)"),
74 /// print the current buffer
75 void ControlPrint::dispatchParams()
77 PrinterParams const pp = params();
78 string command(lyxrc.print_command + ' ');
80 if (pp.target == PrinterParams::PRINTER
81 && lyxrc.print_adapt_output // dvips wants a printer name
82 && !pp.printer_name.empty()) {// printer name given
83 command += lyxrc.print_to_printer
88 if (!pp.all_pages && pp.from_page) {
89 command += lyxrc.print_pagerange_flag + ' ';
90 command += tostr(pp.from_page);
92 // we have a range "from-to"
99 // If both are, or both are not selected, then skip the odd/even printing
100 if (pp.odd_pages != pp.even_pages) {
102 command += lyxrc.print_oddpage_flag + ' ';
103 } else if (pp.even_pages) {
104 command += lyxrc.print_evenpage_flag + ' ';
108 if (pp.count_copies > 1) {
109 if (pp.sorted_copies) {
110 command += lyxrc.print_collcopies_flag;
112 command += lyxrc.print_copies_flag;
115 + tostr(pp.count_copies)
119 if (pp.reverse_order) {
120 command += lyxrc.print_reverse_flag + ' ';
123 if (!lyxrc.print_extra_options.empty()) {
124 command += lyxrc.print_extra_options + ' ';
127 command += kernel().buffer().params().dvips_options() + ' ';
129 string const target = (pp.target == PrinterParams::PRINTER) ?
132 string const target_name = (pp.target == PrinterParams::PRINTER) ?
133 (pp.printer_name.empty() ? "default" : pp.printer_name) :
136 string const data = target + " " + target_name + " " + command;
137 kernel().dispatch(FuncRequest(LFUN_PRINT, data));