3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
22 #include "ControlPrint.h"
25 #include "PrinterParams.h"
27 #include "support/convert.h"
28 #include "support/lstrings.h"
30 #include <libglademm.h>
33 using namespace lyx::support;
38 GPrint::GPrint(Dialog & parent, string const & title)
39 : GViewCB<ControlPrint, GViewGladeB>(parent, title, false)
47 pp.target = printer_->get_active() ? PrinterParams::PRINTER : PrinterParams::FILE;
48 pp.printer_name = printerEntry_->get_text();
49 pp.file_name = fileEntry_->get_text();
50 pp.all_pages = all_->get_active();
51 pp.from_page = pp.to_page = 0;
52 if (!fromEntry_->get_text().empty()) {
53 pp.from_page = convert<int, string>(fromEntry_->get_text());
54 if (!toEntry_->get_text().empty())
55 pp.to_page = convert<int, string>(toEntry_->get_text());
57 pp.odd_pages = odd_->get_active();
58 pp.even_pages = even_->get_active();
59 pp.count_copies = number_->get_value_as_int();
60 pp.sorted_copies = sorted_->get_active();
61 pp.reverse_order = reverse_->get_active();
62 controller().params() = pp;
68 PrinterParams & pp = controller().params();
69 printer_->set_active(pp.target == PrinterParams::PRINTER);
70 printerEntry_->set_text(pp.printer_name);
71 fileEntry_->set_text(pp.file_name);
72 all_->set_active(pp.all_pages);
74 string const from = ( pp.from_page ? convert<string>(pp.from_page) : string() );
75 string const to = ( pp.to_page ? convert<string>(pp.to_page) : string() );
76 fromEntry_->set_text(from);
77 toEntry_->set_text(to);
78 odd_->set_active(pp.odd_pages);
79 even_->set_active(pp.even_pages);
80 reverse_->set_active(pp.reverse_order);
81 sorted_->set_active(pp.sorted_copies);
82 number_->set_value(pp.count_copies);
83 bool const enable_counter = pp.target == PrinterParams::PRINTER;
84 number_->set_sensitive(enable_counter);
85 sorted_->set_sensitive(enable_counter && pp.count_copies > 1);
89 void GPrint::updateUI()
91 ButtonPolicy::SMInput activate = ButtonPolicy::SMI_VALID;
92 // disable OK/Apply buttons when file output is selected, but no file name entered
93 if (file_->get_active() && fileEntry_->get_text().empty())
94 activate = ButtonPolicy::SMI_INVALID;
95 // check 'from' and 'to' fields only when 'from/to' radio button is selected
96 if (fromTo_->get_active()) {
97 string from = fromEntry_->get_text();
98 string to = toEntry_->get_text();
99 if (from.empty() || (!to.empty() && convert<int>(from) > convert<int>(to)))
100 activate = ButtonPolicy::SMI_INVALID;
102 bool const enableCounter = printer_->get_active();
103 number_->set_sensitive(enableCounter);
104 bool const enableSorted = enableCounter && number_->get_value_as_int() > 1;
105 sorted_->set_sensitive(enableSorted);
106 bc().input(activate);
110 void GPrint::onBrowse()
112 string const inName = fileEntry_->get_text();
113 string const outName = Glib::locale_to_utf8(controller().browse(Glib::locale_from_utf8(inName)));
114 if (outName != inName && !outName.empty())
115 fileEntry_->set_text(outName);
116 if (!outName.empty())
117 file_->set_active(true);
122 void GPrint::onTargetEdit(Gtk::Entry const * who)
124 if (who == fileEntry_)
125 file_->set_active(true);
126 else if (who == printerEntry_)
127 printer_->set_active(true);
132 void GPrint::onFromToEdit()
134 fromTo_->set_active(true);
139 void GPrint::doBuild()
141 string const gladeName = findGladeFile("print");
142 xml_ = Gnome::Glade::Xml::create(gladeName);
143 xml_->get_widget("Printer", printer_);
144 xml_->get_widget("File", file_);
145 xml_->get_widget("All", all_);
146 xml_->get_widget("FromTo", fromTo_);
147 xml_->get_widget("Odd", odd_);
148 xml_->get_widget("Even", even_);
149 xml_->get_widget("Reverse", reverse_);
150 xml_->get_widget("Number", number_);
151 xml_->get_widget("Collate", sorted_);
152 xml_->get_widget("FromEntry", fromEntry_);
153 xml_->get_widget("ToEntry", toEntry_);
154 xml_->get_widget("PrinterEntry", printerEntry_);
155 xml_->get_widget("FileEntry", fileEntry_);
158 Gtk::Button * cancel;
159 xml_->get_widget("PrintButton", ok);
160 xml_->get_widget("CancelButton", cancel);
165 Gtk::Button * browse;
166 xml_->get_widget("Browse", browse);
167 browse->signal_clicked().connect(sigc::mem_fun(*this, &GPrint::onBrowse));
169 fileEntry_->signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &GPrint::onTargetEdit), fileEntry_));
170 printerEntry_->signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &GPrint::onTargetEdit), printerEntry_));
171 fromEntry_->signal_changed().connect(sigc::mem_fun(*this, &GPrint::onFromToEdit));
172 toEntry_->signal_changed().connect(sigc::mem_fun(*this, &GPrint::onFromToEdit));
173 printer_->signal_toggled().connect(sigc::mem_fun(*this, &GPrint::updateUI));
174 file_->signal_toggled().connect(sigc::mem_fun(*this, &GPrint::updateUI));
175 all_->signal_toggled().connect(sigc::mem_fun(*this, &GPrint::updateUI));
176 fromTo_->signal_toggled().connect(sigc::mem_fun(*this, &GPrint::updateUI));
177 number_->signal_changed().connect(sigc::mem_fun(*this, &GPrint::updateUI));
179 controller().initialiseParams("");
184 } // namespace frontend