2001-03-27 10:43:10 +00:00
|
|
|
/*
|
2002-03-11 22:47:41 +00:00
|
|
|
* \file xforms/FormPrint.C
|
2001-03-27 10:43:10 +00:00
|
|
|
* Copyright 2000-2001 The LyX Team.
|
|
|
|
* See the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Allan Rae, rae@lyx.org
|
2002-08-15 16:02:22 +00:00
|
|
|
* \author Angus Leeming <leeming@lyx.org>
|
2000-06-12 11:55:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2000-07-27 10:26:38 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-03-27 10:43:10 +00:00
|
|
|
#include "xformsBC.h"
|
|
|
|
#include "ControlPrint.h"
|
2000-06-12 11:55:12 +00:00
|
|
|
#include "FormPrint.h"
|
2002-06-13 13:43:51 +00:00
|
|
|
#include "forms/form_print.h"
|
2001-03-27 10:43:10 +00:00
|
|
|
|
2000-06-12 11:55:12 +00:00
|
|
|
#include "PrinterParams.h"
|
2001-03-27 10:43:10 +00:00
|
|
|
|
2002-03-22 15:24:32 +00:00
|
|
|
#include "input_validators.h"
|
|
|
|
#include "xforms_helpers.h"
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
2002-06-13 13:43:51 +00:00
|
|
|
#include FORMS_H_LOCATION
|
2001-03-27 10:43:10 +00:00
|
|
|
|
2001-01-19 15:31:40 +00:00
|
|
|
using std::make_pair;
|
2000-06-12 11:55:12 +00:00
|
|
|
|
2002-06-13 13:43:51 +00:00
|
|
|
typedef FormCB<ControlPrint, FormDB<FD_print> > base_class;
|
2001-03-27 10:43:10 +00:00
|
|
|
|
2002-08-12 14:28:43 +00:00
|
|
|
FormPrint::FormPrint()
|
|
|
|
: base_class(_("Print")),
|
2001-03-15 13:37:04 +00:00
|
|
|
target_(2), order_(2), which_(3)
|
2001-03-27 10:43:10 +00:00
|
|
|
{}
|
2000-06-12 11:55:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
void FormPrint::build()
|
|
|
|
{
|
2002-06-13 13:43:51 +00:00
|
|
|
dialog_.reset(build_print(this));
|
2000-08-14 05:24:35 +00:00
|
|
|
|
2000-11-28 06:46:06 +00:00
|
|
|
// Manage the ok, apply and cancel/close buttons
|
2001-03-15 13:37:04 +00:00
|
|
|
bc().setOK(dialog_->button_ok);
|
|
|
|
bc().setApply(dialog_->button_apply);
|
2002-03-12 14:11:15 +00:00
|
|
|
bc().setCancel(dialog_->button_close);
|
2000-10-02 00:10:25 +00:00
|
|
|
|
2000-08-14 05:24:35 +00:00
|
|
|
// allow controlling of input and ok/apply (de)activation
|
|
|
|
fl_set_input_return(dialog_->input_printer,
|
|
|
|
FL_RETURN_CHANGED);
|
|
|
|
fl_set_input_return(dialog_->input_file,
|
|
|
|
FL_RETURN_CHANGED);
|
|
|
|
fl_set_input_return(dialog_->input_from_page,
|
|
|
|
FL_RETURN_CHANGED);
|
|
|
|
fl_set_input_return(dialog_->input_to_page,
|
|
|
|
FL_RETURN_CHANGED);
|
|
|
|
fl_set_input_return(dialog_->input_count,
|
|
|
|
FL_RETURN_CHANGED);
|
|
|
|
|
|
|
|
// limit these inputs to unsigned integers
|
|
|
|
fl_set_input_filter(dialog_->input_from_page,
|
|
|
|
fl_unsigned_int_filter);
|
|
|
|
fl_set_input_filter(dialog_->input_to_page,
|
|
|
|
fl_unsigned_int_filter);
|
|
|
|
fl_set_input_filter(dialog_->input_count,
|
|
|
|
fl_unsigned_int_filter);
|
|
|
|
|
2002-03-11 18:24:31 +00:00
|
|
|
setPrehandler(dialog_->input_printer);
|
|
|
|
setPrehandler(dialog_->input_file);
|
|
|
|
setPrehandler(dialog_->input_from_page);
|
|
|
|
setPrehandler(dialog_->input_to_page);
|
|
|
|
setPrehandler(dialog_->input_count);
|
|
|
|
|
2000-08-14 05:24:35 +00:00
|
|
|
// what limits (if any) make sense for these?
|
|
|
|
fl_set_input_maxchars(dialog_->input_printer, 255);
|
|
|
|
fl_set_input_maxchars(dialog_->input_file, 255);
|
|
|
|
fl_set_input_maxchars(dialog_->input_from_page, 4); // 9999
|
|
|
|
fl_set_input_maxchars(dialog_->input_to_page, 4); // 9999
|
|
|
|
fl_set_input_maxchars(dialog_->input_count, 4); // 9999
|
|
|
|
|
2000-10-02 00:10:25 +00:00
|
|
|
target_.reset();
|
2002-03-25 11:16:15 +00:00
|
|
|
target_.init(dialog_->radio_printer, PrinterParams::PRINTER);
|
|
|
|
target_.init(dialog_->radio_file, PrinterParams::FILE);
|
2000-10-02 00:10:25 +00:00
|
|
|
order_.reset();
|
2002-03-25 11:16:15 +00:00
|
|
|
order_.init(dialog_->radio_order_reverse, true);
|
|
|
|
order_.init(dialog_->radio_order_normal, false);
|
2000-10-02 00:10:25 +00:00
|
|
|
which_.reset();
|
2002-03-25 11:16:15 +00:00
|
|
|
which_.init(dialog_->radio_odd_pages, PrinterParams::ODD);
|
|
|
|
which_.init(dialog_->radio_even_pages, PrinterParams::EVEN);
|
|
|
|
which_.init(dialog_->radio_all_pages, PrinterParams::ALL);
|
2000-06-12 11:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormPrint::apply()
|
|
|
|
{
|
2000-10-02 00:10:25 +00:00
|
|
|
PrinterParams::WhichPages
|
2002-03-25 11:16:15 +00:00
|
|
|
wp(static_cast<PrinterParams::WhichPages>(which_.get()));
|
2000-06-12 11:55:12 +00:00
|
|
|
|
|
|
|
string from;
|
|
|
|
int to(0);
|
|
|
|
if (strlen(fl_get_input(dialog_->input_from_page)) > 0) {
|
|
|
|
// we have at least one page requested
|
|
|
|
from = fl_get_input(dialog_->input_from_page);
|
|
|
|
if (strlen(fl_get_input(dialog_->input_to_page)) > 0) {
|
|
|
|
// okay we have a range
|
|
|
|
to = strToInt(fl_get_input(dialog_->input_to_page));
|
|
|
|
} // else we only print one page.
|
|
|
|
}
|
|
|
|
|
2000-10-02 00:10:25 +00:00
|
|
|
PrinterParams::Target
|
2002-03-25 11:16:15 +00:00
|
|
|
t(static_cast<PrinterParams::Target>(target_.get()));
|
2000-06-12 11:55:12 +00:00
|
|
|
|
2001-03-27 10:43:10 +00:00
|
|
|
PrinterParams const pp(t,
|
|
|
|
string(fl_get_input(dialog_->input_printer)),
|
|
|
|
string(fl_get_input(dialog_->input_file)),
|
|
|
|
wp, from, to,
|
2002-03-25 11:16:15 +00:00
|
|
|
static_cast<bool>(order_.get()),
|
2002-03-12 14:11:15 +00:00
|
|
|
!static_cast<bool>(fl_get_button(dialog_->check_collated)),
|
2001-03-27 10:43:10 +00:00
|
|
|
strToInt(fl_get_input(dialog_->input_count)));
|
|
|
|
|
|
|
|
controller().params() = pp;
|
2000-06-12 11:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-24 13:13:59 +00:00
|
|
|
void FormPrint::update()
|
2000-06-12 11:55:12 +00:00
|
|
|
{
|
2001-03-27 10:43:10 +00:00
|
|
|
PrinterParams & pp = controller().params();
|
|
|
|
|
|
|
|
fl_set_input(dialog_->input_printer, pp.printer_name.c_str());
|
|
|
|
fl_set_input(dialog_->input_file, pp.file_name.c_str());
|
|
|
|
|
2002-03-25 11:16:15 +00:00
|
|
|
target_.set(pp.target);
|
|
|
|
order_.set(pp.reverse_order);
|
|
|
|
which_.set(pp.which_pages);
|
2001-03-27 10:43:10 +00:00
|
|
|
|
|
|
|
// hmmm... maybe a bit weird but maybe not
|
|
|
|
// we might just be remembering the last
|
|
|
|
// time this was printed.
|
|
|
|
if (!pp.from_page.empty()) {
|
|
|
|
fl_set_input(dialog_->input_from_page, pp.from_page.c_str());
|
|
|
|
|
|
|
|
// we only set the "to" page of a range
|
|
|
|
// if there's a corresponding "from"
|
|
|
|
fl_activate_object(dialog_->input_to_page);
|
|
|
|
if (pp.to_page) {
|
|
|
|
fl_set_input(dialog_->input_to_page,
|
|
|
|
tostr(pp.to_page).c_str());
|
2000-06-12 11:55:12 +00:00
|
|
|
} else {
|
|
|
|
fl_set_input(dialog_->input_to_page,"");
|
|
|
|
}
|
|
|
|
|
2001-03-27 10:43:10 +00:00
|
|
|
} else {
|
|
|
|
fl_deactivate_object(dialog_->input_to_page);
|
|
|
|
fl_set_input(dialog_->input_to_page,"");
|
|
|
|
fl_set_input(dialog_->input_from_page,"");
|
2000-06-12 11:55:12 +00:00
|
|
|
}
|
2001-03-27 10:43:10 +00:00
|
|
|
|
|
|
|
fl_set_input(dialog_->input_count, tostr(pp.count_copies).c_str());
|
2000-06-12 11:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// It would be nice if we checked for cases like:
|
|
|
|
// Print only-odd-pages and from_page == an even number
|
|
|
|
//
|
2001-03-27 10:43:10 +00:00
|
|
|
ButtonPolicy::SMInput FormPrint::input(FL_OBJECT * ob, long)
|
2000-06-12 11:55:12 +00:00
|
|
|
{
|
2001-03-27 10:43:10 +00:00
|
|
|
ButtonPolicy::SMInput activate = ButtonPolicy::SMI_VALID;
|
2000-06-12 11:55:12 +00:00
|
|
|
|
|
|
|
// using a fl_input_filter that only permits numbers no '-' or '+'
|
|
|
|
// and the user cannot enter a negative number even if they try.
|
|
|
|
if (strlen(fl_get_input(dialog_->input_from_page))) {
|
|
|
|
// using a page range so activate the "to" field
|
|
|
|
fl_activate_object(dialog_->input_to_page);
|
|
|
|
if (strlen(fl_get_input(dialog_->input_to_page))
|
|
|
|
&& (strToInt(fl_get_input(dialog_->input_from_page))
|
|
|
|
> strToInt(fl_get_input(dialog_->input_to_page)))) {
|
|
|
|
// both from and to have values but from > to
|
|
|
|
// We could have code to silently swap these
|
|
|
|
// values but I'll disable the ok/apply until
|
|
|
|
// the user fixes it since they may be editting
|
|
|
|
// one of the fields.
|
2001-03-27 10:43:10 +00:00
|
|
|
activate = ButtonPolicy::SMI_INVALID;
|
2000-06-12 11:55:12 +00:00
|
|
|
// set both backgrounds to red?
|
|
|
|
}
|
|
|
|
} else if (strlen(fl_get_input(dialog_->input_to_page))) {
|
|
|
|
// from is empty but to exists so probably editting from
|
|
|
|
// therefore deactivate ok and apply until form is valid again
|
2001-03-27 10:43:10 +00:00
|
|
|
activate = ButtonPolicy::SMI_INVALID;
|
2000-06-12 11:55:12 +00:00
|
|
|
} else {
|
|
|
|
// both from and to are empty. This is valid so activate
|
|
|
|
// ok and apply but deactivate to
|
|
|
|
fl_deactivate_object(dialog_->input_to_page);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fl_get_button(dialog_->radio_file)
|
|
|
|
&& !strlen(fl_get_input(dialog_->input_file))) {
|
2001-03-27 10:43:10 +00:00
|
|
|
activate = ButtonPolicy::SMI_INVALID;
|
2000-06-12 11:55:12 +00:00
|
|
|
}
|
|
|
|
|
2001-01-19 15:31:40 +00:00
|
|
|
if (ob == dialog_->button_browse) {
|
2001-03-30 09:51:46 +00:00
|
|
|
// Get the filename from the dialog
|
|
|
|
string const in_name = fl_get_input(dialog_->input_file);
|
|
|
|
string const out_name = controller().Browse(in_name);
|
|
|
|
|
|
|
|
// Save the filename to the dialog
|
|
|
|
if (out_name != in_name && !out_name.empty()) {
|
|
|
|
fl_set_input(dialog_->input_file, out_name.c_str());
|
|
|
|
input(0, 0);
|
|
|
|
}
|
2001-06-28 13:02:03 +00:00
|
|
|
|
|
|
|
// select the file radio
|
|
|
|
if (!out_name.empty()) {
|
|
|
|
fl_set_button(dialog_->radio_file, 1);
|
|
|
|
fl_set_button(dialog_->radio_printer, 0);
|
|
|
|
}
|
2001-01-19 15:31:40 +00:00
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-06-28 13:02:03 +00:00
|
|
|
// if we type into file, select that as a target
|
2002-03-21 21:21:28 +00:00
|
|
|
if (ob == dialog_->input_file && fl_get_button(dialog_->radio_printer)
|
2002-03-21 16:59:12 +00:00
|
|
|
&& strlen(fl_get_input(dialog_->input_file))) {
|
2001-06-28 13:02:03 +00:00
|
|
|
fl_set_button(dialog_->radio_file, 1);
|
|
|
|
fl_set_button(dialog_->radio_printer, 0);
|
|
|
|
} else if (ob == dialog_->input_printer) {
|
|
|
|
fl_set_button(dialog_->radio_file, 0);
|
|
|
|
fl_set_button(dialog_->radio_printer, 1);
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2000-10-02 00:10:25 +00:00
|
|
|
return activate;
|
2000-06-12 11:55:12 +00:00
|
|
|
}
|