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"
27 #include "minibuffer.h"
30 extern bool RunScript(Buffer * buffer, bool wait, string const & command,
31 string const & orgname = string(), bool need_shell=true);
34 #ifdef CXX_WORKING_NAMESPACES
39 PrinterParams getPrinterParams(Buffer * buffer)
41 return PrinterParams(PrinterParams::PRINTER,
43 ChangeExtension(buffer->fileName(),
44 lyxrc.print_file_extension));
48 bool printBuffer(Buffer * buffer, PrinterParams const & pp)
51 string command(lyxrc.print_command + ' ');
53 if (pp.target == PrinterParams::PRINTER
54 && lyxrc.print_adapt_output // dvips wants a printer name
55 && !pp.printer_name.empty()) {// printer name given
56 command += lyxrc.print_to_printer
61 switch (pp.which_pages) {
62 case PrinterParams::EVEN:
63 command += lyxrc.print_evenpage_flag + ' ';
66 case PrinterParams::ODD:
67 command += lyxrc.print_oddpage_flag + ' ';
71 // only option left is print all of them
75 if (!pp.from_page.empty()) {
76 command += lyxrc.print_pagerange_flag + ' ';
77 command += pp.from_page;
79 // we have a range "from-to"
81 command += tostr(pp.to_page);
86 if (pp.reverse_order) {
87 command += lyxrc.print_reverse_flag + ' ';
90 BufferParams params(buffer->params);
91 if (params.orientation
92 == BufferParams::ORIENTATION_LANDSCAPE) {
93 command += lyxrc.print_landscape_flag + ' ';
96 if (1 < pp.count_copies) {
97 if (pp.unsorted_copies) {
98 command += lyxrc.print_copies_flag;
100 command += lyxrc.print_collcopies_flag;
103 command += tostr(pp.count_copies);
107 if (!lyxrc.print_extra_options.empty()) {
108 command += lyxrc.print_extra_options + ' ';
111 char real_papersize = params.papersize;
112 if (real_papersize == BufferParams::PAPER_DEFAULT) {
113 real_papersize = lyxrc.default_papersize;
116 if (params.use_geometry
117 && params.papersize2 == BufferParams::VM_PAPER_CUSTOM
118 && !lyxrc.print_paper_dimension_flag.empty()
119 && !params.paperwidth.empty()
120 && !params.paperheight.empty()) {
121 // using a custom papersize
122 command += lyxrc.print_paper_dimension_flag + ' ';
123 command += params.paperwidth + ',';
124 command += params.paperheight + ' ';
125 } else if (!lyxrc.print_paper_flag.empty()
126 && (real_papersize != BufferParams::PAPER_USLETTER
127 || params.orientation
128 == BufferParams::ORIENTATION_PORTRAIT)) {
129 // There's a problem with US Letter + landscape
131 switch (real_papersize) {
132 case BufferParams::PAPER_USLETTER:
135 case BufferParams::PAPER_A3PAPER:
138 case BufferParams::PAPER_A4PAPER:
141 case BufferParams::PAPER_A5PAPER:
144 case BufferParams::PAPER_B5PAPER:
147 case BufferParams::PAPER_EXECUTIVEPAPER:
150 case BufferParams::PAPER_LEGALPAPER:
153 default: /* If nothing else fits, keep empty value */
156 if (!paper.empty()) {
157 command += lyxrc.print_paper_flag + ' ';
158 command += paper + ' ';
162 // Push directory path if necessary.
163 // PS file should go where the source file is unless it's a
164 // read-only directory in which case we write it to tmpdir.
165 // All temporary files go in tmpdir (like spool files).
166 string path = OnlyPath(buffer->fileName());
167 if ((pp.target != PrinterParams::FILE
168 && lyxrc.use_tempdir)
169 || (IsDirWriteable(path) < 1)) {
170 path = buffer->tmppath;
174 // there are three cases here:
175 // 1. we print to a file
176 // 2. we print direct to a printer
177 // 3. we print using a spool command (print to file first)
179 case PrinterParams::PRINTER:
180 if (!lyxrc.print_spool_command.empty()) {
182 command += lyxrc.print_to_file
183 + QuoteName(pp.file_name);
184 string command2 = lyxrc.print_spool_command
186 if (!pp.printer_name.empty()) {
187 command2 += lyxrc.print_spool_printerprefix
191 // If successful, then spool command
192 if (result = RunScript(buffer, true, command)) {
193 result = RunScript(buffer, false,
195 QuoteName(pp.file_name));
199 result = RunScript(buffer, false, command);
203 case PrinterParams::FILE:
205 command += lyxrc.print_to_file
206 + QuoteName(MakeAbsPath(pp.file_name, path));
207 result = RunScript(buffer, false, command);
213 void setMinibuffer(LyXView * lv, char const * msg)
215 lv->getMiniBuffer()->Set(msg);
218 #ifdef CXX_WORKING_NAMESPACES