2003-09-02 17:02:32 +00:00
|
|
|
/**
|
|
|
|
* \file GPrint.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Huang Ying
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
2003-09-02 10:29:05 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2004-11-16 23:18:46 +00:00
|
|
|
// Too hard to make concept checks work with this file
|
2005-01-29 15:09:14 +00:00
|
|
|
#ifdef _GLIBCXX_CONCEPT_CHECKS
|
|
|
|
#undef _GLIBCXX_CONCEPT_CHECKS
|
|
|
|
#endif
|
2004-11-16 23:18:46 +00:00
|
|
|
#ifdef _GLIBCPP_CONCEPT_CHECKS
|
|
|
|
#undef _GLIBCPP_CONCEPT_CHECKS
|
|
|
|
#endif
|
|
|
|
|
2003-09-02 10:29:05 +00:00
|
|
|
#include "GPrint.h"
|
|
|
|
#include "ControlPrint.h"
|
2004-04-27 12:48:45 +00:00
|
|
|
#include "ghelpers.h"
|
|
|
|
|
2003-09-02 10:29:05 +00:00
|
|
|
#include "PrinterParams.h"
|
2004-09-26 18:36:07 +00:00
|
|
|
|
2005-01-06 16:44:04 +00:00
|
|
|
#include "support/convert.h"
|
2005-01-27 21:05:44 +00:00
|
|
|
#include "support/lstrings.h"
|
2004-09-26 08:05:05 +00:00
|
|
|
|
2004-09-26 18:36:07 +00:00
|
|
|
#include <libglademm.h>
|
|
|
|
|
2004-09-26 08:05:05 +00:00
|
|
|
using std::string;
|
|
|
|
using namespace lyx::support;
|
2003-09-02 10:29:05 +00:00
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
2003-09-02 10:29:05 +00:00
|
|
|
|
2004-09-26 13:18:29 +00:00
|
|
|
GPrint::GPrint(Dialog & parent, string const & title)
|
2003-09-02 10:29:05 +00:00
|
|
|
: GViewCB<ControlPrint, GViewGladeB>(parent, title, false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GPrint::apply()
|
|
|
|
{
|
|
|
|
PrinterParams pp;
|
|
|
|
pp.target = printer_->get_active() ? PrinterParams::PRINTER : PrinterParams::FILE;
|
|
|
|
pp.printer_name = printerEntry_->get_text();
|
2004-09-26 08:05:05 +00:00
|
|
|
pp.file_name = fileEntry_->get_text();
|
2003-09-02 10:29:05 +00:00
|
|
|
pp.all_pages = all_->get_active();
|
|
|
|
pp.from_page = pp.to_page = 0;
|
|
|
|
if (!fromEntry_->get_text().empty()) {
|
2005-01-27 21:05:44 +00:00
|
|
|
pp.from_page = convert<int>(fromEntry_->get_text());
|
2003-09-02 10:29:05 +00:00
|
|
|
if (!toEntry_->get_text().empty())
|
2005-01-27 21:05:44 +00:00
|
|
|
pp.to_page = convert<int>(toEntry_->get_text());
|
2003-09-02 10:29:05 +00:00
|
|
|
}
|
|
|
|
pp.odd_pages = odd_->get_active();
|
|
|
|
pp.even_pages = even_->get_active();
|
|
|
|
pp.count_copies = number_->get_value_as_int();
|
|
|
|
pp.sorted_copies = sorted_->get_active();
|
|
|
|
pp.reverse_order = reverse_->get_active();
|
|
|
|
controller().params() = pp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GPrint::update()
|
|
|
|
{
|
|
|
|
PrinterParams & pp = controller().params();
|
|
|
|
printer_->set_active(pp.target == PrinterParams::PRINTER);
|
|
|
|
printerEntry_->set_text(pp.printer_name);
|
|
|
|
fileEntry_->set_text(pp.file_name);
|
|
|
|
all_->set_active(pp.all_pages);
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
string const from = ( pp.from_page ? convert<string>(pp.from_page) : string() );
|
|
|
|
string const to = ( pp.to_page ? convert<string>(pp.to_page) : string() );
|
2003-09-02 10:29:05 +00:00
|
|
|
fromEntry_->set_text(from);
|
|
|
|
toEntry_->set_text(to);
|
|
|
|
odd_->set_active(pp.odd_pages);
|
|
|
|
even_->set_active(pp.even_pages);
|
|
|
|
reverse_->set_active(pp.reverse_order);
|
|
|
|
sorted_->set_active(pp.sorted_copies);
|
|
|
|
number_->set_value(pp.count_copies);
|
|
|
|
bool const enable_counter = pp.target == PrinterParams::PRINTER;
|
|
|
|
number_->set_sensitive(enable_counter);
|
|
|
|
sorted_->set_sensitive(enable_counter && pp.count_copies > 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GPrint::updateUI()
|
|
|
|
{
|
|
|
|
ButtonPolicy::SMInput activate = ButtonPolicy::SMI_VALID;
|
|
|
|
// disable OK/Apply buttons when file output is selected, but no file name entered
|
|
|
|
if (file_->get_active() && fileEntry_->get_text().empty())
|
|
|
|
activate = ButtonPolicy::SMI_INVALID;
|
|
|
|
// check 'from' and 'to' fields only when 'from/to' radio button is selected
|
|
|
|
if (fromTo_->get_active()) {
|
|
|
|
string from = fromEntry_->get_text();
|
|
|
|
string to = toEntry_->get_text();
|
2005-01-27 21:05:44 +00:00
|
|
|
if (from.empty() || (!to.empty() && convert<int>(from) > convert<int>(to)))
|
2003-09-02 10:29:05 +00:00
|
|
|
activate = ButtonPolicy::SMI_INVALID;
|
|
|
|
}
|
|
|
|
bool const enableCounter = printer_->get_active();
|
|
|
|
number_->set_sensitive(enableCounter);
|
|
|
|
bool const enableSorted = enableCounter && number_->get_value_as_int() > 1;
|
|
|
|
sorted_->set_sensitive(enableSorted);
|
|
|
|
bc().input(activate);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GPrint::onBrowse()
|
|
|
|
{
|
|
|
|
string const inName = fileEntry_->get_text();
|
2004-09-26 08:05:05 +00:00
|
|
|
string const outName = Glib::locale_to_utf8(controller().browse(Glib::locale_from_utf8(inName)));
|
2003-09-02 10:29:05 +00:00
|
|
|
if (outName != inName && !outName.empty())
|
|
|
|
fileEntry_->set_text(outName);
|
|
|
|
if (!outName.empty())
|
|
|
|
file_->set_active(true);
|
|
|
|
updateUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GPrint::onTargetEdit(Gtk::Entry const * who)
|
|
|
|
{
|
|
|
|
if (who == fileEntry_)
|
|
|
|
file_->set_active(true);
|
|
|
|
else if (who == printerEntry_)
|
|
|
|
printer_->set_active(true);
|
|
|
|
updateUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GPrint::onFromToEdit()
|
|
|
|
{
|
|
|
|
fromTo_->set_active(true);
|
|
|
|
updateUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GPrint::doBuild()
|
|
|
|
{
|
2004-04-27 12:48:45 +00:00
|
|
|
string const gladeName = findGladeFile("print");
|
2003-09-02 10:29:05 +00:00
|
|
|
xml_ = Gnome::Glade::Xml::create(gladeName);
|
|
|
|
xml_->get_widget("Printer", printer_);
|
|
|
|
xml_->get_widget("File", file_);
|
|
|
|
xml_->get_widget("All", all_);
|
|
|
|
xml_->get_widget("FromTo", fromTo_);
|
|
|
|
xml_->get_widget("Odd", odd_);
|
|
|
|
xml_->get_widget("Even", even_);
|
|
|
|
xml_->get_widget("Reverse", reverse_);
|
|
|
|
xml_->get_widget("Number", number_);
|
2004-09-26 08:05:05 +00:00
|
|
|
xml_->get_widget("Collate", sorted_);
|
2003-09-02 10:29:05 +00:00
|
|
|
xml_->get_widget("FromEntry", fromEntry_);
|
|
|
|
xml_->get_widget("ToEntry", toEntry_);
|
|
|
|
xml_->get_widget("PrinterEntry", printerEntry_);
|
|
|
|
xml_->get_widget("FileEntry", fileEntry_);
|
2004-09-26 13:18:29 +00:00
|
|
|
|
2003-09-02 10:29:05 +00:00
|
|
|
Gtk::Button * ok;
|
|
|
|
Gtk::Button * cancel;
|
2004-09-26 08:05:05 +00:00
|
|
|
xml_->get_widget("PrintButton", ok);
|
2003-09-02 10:29:05 +00:00
|
|
|
xml_->get_widget("CancelButton", cancel);
|
2004-09-26 16:48:30 +00:00
|
|
|
|
2004-09-26 08:05:05 +00:00
|
|
|
setOK(ok);
|
|
|
|
setCancel(cancel);
|
2004-09-26 13:18:29 +00:00
|
|
|
|
2003-09-02 10:29:05 +00:00
|
|
|
Gtk::Button * browse;
|
|
|
|
xml_->get_widget("Browse", browse);
|
2004-09-26 16:48:30 +00:00
|
|
|
browse->signal_clicked().connect(sigc::mem_fun(*this, &GPrint::onBrowse));
|
|
|
|
|
|
|
|
fileEntry_->signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &GPrint::onTargetEdit), fileEntry_));
|
|
|
|
printerEntry_->signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &GPrint::onTargetEdit), printerEntry_));
|
|
|
|
fromEntry_->signal_changed().connect(sigc::mem_fun(*this, &GPrint::onFromToEdit));
|
|
|
|
toEntry_->signal_changed().connect(sigc::mem_fun(*this, &GPrint::onFromToEdit));
|
|
|
|
printer_->signal_toggled().connect(sigc::mem_fun(*this, &GPrint::updateUI));
|
|
|
|
file_->signal_toggled().connect(sigc::mem_fun(*this, &GPrint::updateUI));
|
|
|
|
all_->signal_toggled().connect(sigc::mem_fun(*this, &GPrint::updateUI));
|
|
|
|
fromTo_->signal_toggled().connect(sigc::mem_fun(*this, &GPrint::updateUI));
|
|
|
|
number_->signal_changed().connect(sigc::mem_fun(*this, &GPrint::updateUI));
|
2004-09-26 13:18:29 +00:00
|
|
|
|
2004-09-26 08:05:05 +00:00
|
|
|
controller().initialiseParams("");
|
|
|
|
update();
|
|
|
|
updateUI();
|
2003-09-02 10:29:05 +00:00
|
|
|
}
|
2004-05-19 15:11:37 +00:00
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|