1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
19 #include "BufferView.h"
22 #include "PrinterParams.h"
23 #include "lyx_gui_misc.h"
24 #include "support/lstrings.h"
25 #include "support/filetools.h"
26 #include "support/path.h"
28 #include "minibuffer.h"
31 extern bool RunScript(Buffer * buffer, bool wait, string const & command,
32 string const & orgname = string(), bool need_shell=true);
35 #ifdef CXX_WORKING_NAMESPACES
40 PrinterParams getPrinterParams(Buffer * buffer)
42 return PrinterParams(PrinterParams::PRINTER,
44 ChangeExtension(buffer->fileName(),
45 lyxrc.print_file_extension));
49 bool printBuffer(Buffer * buffer, PrinterParams const & pp)
52 string command(lyxrc.print_command + ' ');
54 if (pp.target == PrinterParams::PRINTER
55 && lyxrc.print_adapt_output // dvips wants a printer name
56 && !pp.printer_name.empty()) {// printer name given
57 command += lyxrc.print_to_printer
62 switch (pp.which_pages) {
63 case PrinterParams::EVEN:
64 command += lyxrc.print_evenpage_flag + ' ';
67 case PrinterParams::ODD:
68 command += lyxrc.print_oddpage_flag + ' ';
72 // only option left is print all of them
76 if (!pp.from_page.empty()) {
77 command += lyxrc.print_pagerange_flag + ' ';
78 command += pp.from_page;
80 // we have a range "from-to"
82 command += tostr(pp.to_page);
87 if (pp.reverse_order) {
88 command += lyxrc.print_reverse_flag + ' ';
91 BufferParams params(buffer->params);
92 if (params.orientation
93 == BufferParams::ORIENTATION_LANDSCAPE) {
94 command += lyxrc.print_landscape_flag + ' ';
97 if (1 < pp.count_copies) {
98 if (pp.unsorted_copies) {
99 command += lyxrc.print_copies_flag;
101 command += lyxrc.print_collcopies_flag;
104 command += tostr(pp.count_copies);
108 if (!lyxrc.print_extra_options.empty()) {
109 command += lyxrc.print_extra_options + ' ';
112 char real_papersize = params.papersize;
113 if (real_papersize == BufferParams::PAPER_DEFAULT) {
114 real_papersize = lyxrc.default_papersize;
117 if (params.use_geometry
118 && params.papersize2 == BufferParams::VM_PAPER_CUSTOM
119 && !lyxrc.print_paper_dimension_flag.empty()
120 && !params.paperwidth.empty()
121 && !params.paperheight.empty()) {
122 // using a custom papersize
123 command += lyxrc.print_paper_dimension_flag + ' ';
124 command += params.paperwidth + ',';
125 command += params.paperheight + ' ';
126 } else if (!lyxrc.print_paper_flag.empty()
127 && (real_papersize != BufferParams::PAPER_USLETTER
128 || params.orientation
129 == BufferParams::ORIENTATION_PORTRAIT)) {
130 // There's a problem with US Letter + landscape
132 switch (real_papersize) {
133 case BufferParams::PAPER_USLETTER:
136 case BufferParams::PAPER_A3PAPER:
139 case BufferParams::PAPER_A4PAPER:
142 case BufferParams::PAPER_A5PAPER:
145 case BufferParams::PAPER_B5PAPER:
148 case BufferParams::PAPER_EXECUTIVEPAPER:
151 case BufferParams::PAPER_LEGALPAPER:
154 default: /* If nothing else fits, keep empty value */
157 if (!paper.empty()) {
158 command += lyxrc.print_paper_flag + ' ';
159 command += paper + ' ';
163 // Push directory path if necessary.
164 // PS file should go where the source file is unless it's a
165 // read-only directory in which case we write it to tmpdir.
166 // All temporary files go in tmpdir (like spool files).
167 string path = OnlyPath(buffer->fileName());
168 if ((pp.target != PrinterParams::FILE
169 && lyxrc.use_tempdir)
170 || (IsDirWriteable(path) < 1)) {
171 path = buffer->tmppath;
176 // there are three cases here:
177 // 1. we print to a file
178 // 2. we print direct to a printer
179 // 3. we print using a spool command (print to file first)
181 case PrinterParams::PRINTER:
182 if (!lyxrc.print_spool_command.empty()) {
184 command += lyxrc.print_to_file
185 + QuoteName(pp.file_name);
186 string command2 = lyxrc.print_spool_command
188 if (!pp.printer_name.empty()) {
189 command2 += lyxrc.print_spool_printerprefix
193 // If successful, then spool command
194 if (result = RunScript(buffer, true, command)) {
195 result = RunScript(buffer, false,
197 QuoteName(pp.file_name));
201 result = RunScript(buffer, false, command);
205 case PrinterParams::FILE:
207 command += lyxrc.print_to_file
208 + QuoteName(MakeAbsPath(pp.file_name, path));
209 result = RunScript(buffer, false, command);
216 void setMinibuffer(LyXView * lv, char const * msg)
218 lv->getMiniBuffer()->Set(msg);
221 #ifdef CXX_WORKING_NAMESPACES