-/* callbacks for form form_print */
-
-extern "C" void PrintCancelCB(FL_OBJECT *, long)
-{
- fl_hide_form(fd_form_print->form_print);
-}
-
-
-static
-bool stringOnlyContains (string const & LStr, char const * cset)
-{
- return LStr.find_first_not_of(cset) == string::npos;
-}
-
-
-extern "C" void PrintApplyCB(FL_OBJECT *, long)
-{
- if (!current_view->available())
- return;
- Buffer * buffer = current_view->buffer();
- string path = OnlyPath(buffer->fileName());
-
- string pageflag;
- if (fl_get_button(fd_form_print->radio_even_pages))
- pageflag = lyxrc.print_evenpage_flag + ' ';
- else if (fl_get_button(fd_form_print->radio_odd_pages))
- pageflag = lyxrc.print_oddpage_flag + ' ';
-
-// Changes by Stephan Witt (stephan.witt@beusen.de), 19-Jan-99
-// User may give a page (range) list
-// User may print multiple (unsorted) copies
- string pages = subst(fl_get_input(fd_form_print->input_pages), ';',',');
- pages = subst(pages, '+',',');
- pages = frontStrip(strip(pages)) ;
- while (!pages.empty()) { // a page range was given
- string piece ;
- pages = split (pages, piece, ',') ;
- piece = strip(piece) ;
- piece = frontStrip(piece) ;
- if ( !stringOnlyContains (piece, "0123456789-") ) {
- WriteAlert(_("ERROR! Unable to print!"),
- _("Check 'range of pages'!"));
- return;
- }
- if (piece.find('-') == string::npos) { // not found
- pageflag += lyxrc.print_pagerange_flag + piece + '-' + piece + ' ' ;
- } else if (suffixIs(piece, "-") ) { // missing last page
- pageflag += lyxrc.print_pagerange_flag + piece + "1000 ";
- } else if (prefixIs(piece, "-") ) { // missing first page
- pageflag += lyxrc.print_pagerange_flag + '1' + piece + ' ' ;
- } else {
- pageflag += lyxrc.print_pagerange_flag + piece + ' ' ;
- }
- }
-
- string copies = frontStrip(strip(fl_get_input(fd_form_print->input_copies)));
- if (!copies.empty()) { // a number of copies was given
- if ( !stringOnlyContains (copies, "0123456789") ) {
- WriteAlert(_("ERROR! Unable to print!"),
- _("Check 'number of copies'!"));
- return;
- }
- if (fl_get_button(fd_form_print->do_unsorted))
- pageflag += lyxrc.print_copies_flag;
- else
- pageflag += lyxrc.print_collcopies_flag;
- pageflag += " " + copies + ' ' ;
- }
-
- string reverseflag;
- if (fl_get_button(fd_form_print->radio_order_reverse))
- reverseflag = lyxrc.print_reverse_flag + ' ';
-
- string orientationflag;
- if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
- orientationflag = lyxrc.print_landscape_flag + ' ';
-
- string ps_file = fl_get_input(fd_form_print->input_file);
- string printer = strip(fl_get_input(fd_form_print->input_printer));
-
- string printerflag;
- if (lyxrc.print_adapt_output // printer name should be passed to dvips
- && ! printer.empty()) // a printer name has been given
- printerflag = lyxrc.print_to_printer + printer + ' ';
-
- string extraflags;
- if (!lyxrc.print_extra_options.empty())
- extraflags = lyxrc.print_extra_options + ' ';
-
- string command = lyxrc.print_command + ' '
- + printerflag + pageflag + reverseflag
- + orientationflag + extraflags;
-
- char real_papersize = buffer->params.papersize;
- if (real_papersize == BufferParams::PAPER_DEFAULT)
- real_papersize = lyxrc.default_papersize;
-
- string paper;
- switch (real_papersize) {
- case BufferParams::PAPER_USLETTER:
- paper = "letter";
- break;
- case BufferParams::PAPER_A3PAPER:
- paper = "a3";
- break;
- case BufferParams::PAPER_A4PAPER:
- paper = "a4";
- break;
- case BufferParams::PAPER_A5PAPER:
- paper = "a5";
- break;
- case BufferParams::PAPER_B5PAPER:
- paper = "b5";
- break;
- case BufferParams::PAPER_EXECUTIVEPAPER:
- paper = "foolscap";
- break;
- case BufferParams::PAPER_LEGALPAPER:
- paper = "legal";
- break;
- default: /* If nothing else fits, keep an empty value... */
- break;
- }
-
- if (buffer->params.use_geometry
- && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
- && !lyxrc.print_paper_dimension_flag.empty()
- && !buffer->params.paperwidth.empty()
- && !buffer->params.paperheight.empty()) {
- // using a custom papersize
- command += ' ';
- command += lyxrc.print_paper_dimension_flag + ' ';
- command += buffer->params.paperwidth + ',';
- command += buffer->params.paperheight + ' ';
- } else if (!lyxrc.print_paper_flag.empty()
- && !paper.empty()
- && (real_papersize != BufferParams::PAPER_USLETTER ||
- buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
- command += " " + lyxrc.print_paper_flag + " " + paper + " ";
- }
- if (fl_get_button(fd_form_print->radio_file))
- command += lyxrc.print_to_file
- + QuoteName(MakeAbsPath(ps_file, path));
- else if (!lyxrc.print_spool_command.empty())
- command += lyxrc.print_to_file
- + QuoteName(ps_file);
-
- // push directorypath, if necessary
- if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
- path = buffer->tmppath;
- }
- Path p(path);
-
- bool result;
- if (!lyxrc.print_spool_command.empty() &&
- !fl_get_button(fd_form_print->radio_file)) {
- string command2 = lyxrc.print_spool_command + ' ';
- if (!printer.empty())
- command2 += lyxrc.print_spool_printerprefix
- + printer;
- // First run dvips and, if succesful, then spool command
- if ((result = RunScript(buffer, true, command))) {
- result = RunScript(buffer, false, command2, ps_file);
- }
- } else
- result = RunScript(buffer, false, command);
-
- if (!result)
- WriteAlert(_("Error:"),
- _("Unable to print"),
- _("Check that your parameters are correct"));
-}
-
-
-extern "C" void PrintOKCB(FL_OBJECT * ob, long data)
-{
- PrintCancelCB(ob, data);
- PrintApplyCB(ob, data);
-}
-
-