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"
32 using support::ChangeExtension;
33 using support::FileFilterList;
38 ControlPrint::ControlPrint(Dialog & parent)
39 : Dialog::Controller(parent),
44 bool ControlPrint::initialiseParams(std::string const &)
46 /// get global printer parameters
47 string const name = ChangeExtension(kernel().buffer().fileName(),
48 lyxrc.print_file_extension);
49 params_.reset(new PrinterParams (PrinterParams::PRINTER,
50 lyxrc.printer, name));
52 dialog().bc().valid(); // so that the user can press Ok
57 void ControlPrint::clearParams()
63 PrinterParams & ControlPrint::params() const
65 BOOST_ASSERT(params_.get());
70 string const ControlPrint::browse(string const & in_name) const
72 return browseRelFile(in_name, kernel().buffer().filePath(),
74 FileFilterList("PostScript files (*.ps)"),
79 /// print the current buffer
80 void ControlPrint::dispatchParams()
82 PrinterParams const pp = params();
83 string command(lyxrc.print_command + ' ');
85 if (pp.target == PrinterParams::PRINTER
86 && lyxrc.print_adapt_output // dvips wants a printer name
87 && !pp.printer_name.empty()) {// printer name given
88 command += lyxrc.print_to_printer
93 if (!pp.all_pages && pp.from_page) {
94 command += lyxrc.print_pagerange_flag + ' ';
95 command += tostr(pp.from_page);
97 // we have a range "from-to"
104 // If both are, or both are not selected, then skip the odd/even printing
105 if (pp.odd_pages != pp.even_pages) {
107 command += lyxrc.print_oddpage_flag + ' ';
108 } else if (pp.even_pages) {
109 command += lyxrc.print_evenpage_flag + ' ';
113 if (pp.count_copies > 1) {
114 if (pp.sorted_copies) {
115 command += lyxrc.print_collcopies_flag;
117 command += lyxrc.print_copies_flag;
120 + tostr(pp.count_copies)
124 if (pp.reverse_order) {
125 command += lyxrc.print_reverse_flag + ' ';
128 if (!lyxrc.print_extra_options.empty()) {
129 command += lyxrc.print_extra_options + ' ';
132 command += kernel().buffer().params().dvips_options() + ' ';
134 string const target = (pp.target == PrinterParams::PRINTER) ?
137 string const target_name = (pp.target == PrinterParams::PRINTER) ?
138 (pp.printer_name.empty() ? "default" : pp.printer_name) :
141 string const data = target + " " + target_name + " " + command;
142 kernel().dispatch(FuncRequest(LFUN_PRINT, data));
145 } // namespace frontend