]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GPrint.C
more compile fixes
[lyx.git] / src / frontends / gtk / GPrint.C
1 /**
2  * \file GPrint.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Huang Ying
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
16 #endif
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
19 #endif
20
21 #include "GPrint.h"
22 #include "ControlPrint.h"
23 #include "ghelpers.h"
24
25 #include "PrinterParams.h"
26
27 #include "support/convert.h"
28 #include "support/lstrings.h"
29
30 #include <libglademm.h>
31
32 using lyx::docstring;
33
34 using std::string;
35 using namespace lyx::support;
36
37 namespace lyx {
38 namespace frontend {
39
40 GPrint::GPrint(Dialog & parent, docstring const & title)
41         : GViewCB<ControlPrint, GViewGladeB>(parent, title, false)
42 {
43 }
44
45
46 void GPrint::apply()
47 {
48         PrinterParams pp;
49         pp.target = printer_->get_active() ? PrinterParams::PRINTER : PrinterParams::FILE;
50         pp.printer_name = printerEntry_->get_text();
51         pp.file_name = fileEntry_->get_text();
52         pp.all_pages = all_->get_active();
53         pp.from_page = pp.to_page = 0;
54         if (!fromEntry_->get_text().empty()) {
55                 pp.from_page = convert<int, string>(fromEntry_->get_text());
56                 if (!toEntry_->get_text().empty())
57                         pp.to_page = convert<int, string>(toEntry_->get_text());
58         }
59         pp.odd_pages = odd_->get_active();
60         pp.even_pages = even_->get_active();
61         pp.count_copies = number_->get_value_as_int();
62         pp.sorted_copies = sorted_->get_active();
63         pp.reverse_order = reverse_->get_active();
64         controller().params() = pp;
65 }
66
67
68 void GPrint::update()
69 {
70         PrinterParams & pp = controller().params();
71         printer_->set_active(pp.target == PrinterParams::PRINTER);
72         printerEntry_->set_text(pp.printer_name);
73         fileEntry_->set_text(pp.file_name);
74         all_->set_active(pp.all_pages);
75
76         string const from = ( pp.from_page ? convert<string>(pp.from_page) : string() );
77         string const to   = ( pp.to_page   ? convert<string>(pp.to_page)   : string() );
78         fromEntry_->set_text(from);
79         toEntry_->set_text(to);
80         odd_->set_active(pp.odd_pages);
81         even_->set_active(pp.even_pages);
82         reverse_->set_active(pp.reverse_order);
83         sorted_->set_active(pp.sorted_copies);
84         number_->set_value(pp.count_copies);
85         bool const enable_counter = pp.target == PrinterParams::PRINTER;
86         number_->set_sensitive(enable_counter);
87         sorted_->set_sensitive(enable_counter && pp.count_copies > 1);
88 }
89
90
91 void GPrint::updateUI()
92 {
93         ButtonPolicy::SMInput activate = ButtonPolicy::SMI_VALID;
94         // disable OK/Apply buttons when file output is selected, but no file name entered
95         if (file_->get_active() && fileEntry_->get_text().empty())
96                 activate = ButtonPolicy::SMI_INVALID;
97         // check 'from' and 'to' fields only when 'from/to' radio button is selected
98         if (fromTo_->get_active()) {
99                 string from = fromEntry_->get_text();
100                 string to = toEntry_->get_text();
101                 if (from.empty() || (!to.empty() && convert<int>(from) > convert<int>(to)))
102                         activate = ButtonPolicy::SMI_INVALID;
103         }
104         bool const enableCounter = printer_->get_active();
105         number_->set_sensitive(enableCounter);
106         bool const enableSorted = enableCounter && number_->get_value_as_int() > 1;
107         sorted_->set_sensitive(enableSorted);
108         bc().input(activate);
109 }
110
111
112 void GPrint::onBrowse()
113 {
114         string const inName = fileEntry_->get_text();
115         string const outName = lyx::to_utf8(controller().browse(lyx::from_utf8(inName)));
116         if (outName != inName && !outName.empty())
117                 fileEntry_->set_text(outName);
118         if (!outName.empty())
119                 file_->set_active(true);
120         updateUI();
121 }
122
123
124 void GPrint::onTargetEdit(Gtk::Entry const * who)
125 {
126         if (who == fileEntry_)
127                 file_->set_active(true);
128         else if (who == printerEntry_)
129                 printer_->set_active(true);
130         updateUI();
131 }
132
133
134 void GPrint::onFromToEdit()
135 {
136         fromTo_->set_active(true);
137         updateUI();
138 }
139
140
141 void GPrint::doBuild()
142 {
143         string const gladeName = findGladeFile("print");
144         xml_ = Gnome::Glade::Xml::create(gladeName);
145         xml_->get_widget("Printer", printer_);
146         xml_->get_widget("File", file_);
147         xml_->get_widget("All", all_);
148         xml_->get_widget("FromTo", fromTo_);
149         xml_->get_widget("Odd", odd_);
150         xml_->get_widget("Even", even_);
151         xml_->get_widget("Reverse", reverse_);
152         xml_->get_widget("Number", number_);
153         xml_->get_widget("Collate", sorted_);
154         xml_->get_widget("FromEntry", fromEntry_);
155         xml_->get_widget("ToEntry", toEntry_);
156         xml_->get_widget("PrinterEntry", printerEntry_);
157         xml_->get_widget("FileEntry", fileEntry_);
158
159         Gtk::Button * ok;
160         Gtk::Button * cancel;
161         xml_->get_widget("PrintButton", ok);
162         xml_->get_widget("CancelButton", cancel);
163
164         setOK(ok);
165         setCancel(cancel);
166
167         Gtk::Button * browse;
168         xml_->get_widget("Browse", browse);
169         browse->signal_clicked().connect(sigc::mem_fun(*this, &GPrint::onBrowse));
170
171         fileEntry_->signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &GPrint::onTargetEdit), fileEntry_));
172         printerEntry_->signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &GPrint::onTargetEdit), printerEntry_));
173         fromEntry_->signal_changed().connect(sigc::mem_fun(*this, &GPrint::onFromToEdit));
174         toEntry_->signal_changed().connect(sigc::mem_fun(*this, &GPrint::onFromToEdit));
175         printer_->signal_toggled().connect(sigc::mem_fun(*this, &GPrint::updateUI));
176         file_->signal_toggled().connect(sigc::mem_fun(*this, &GPrint::updateUI));
177         all_->signal_toggled().connect(sigc::mem_fun(*this, &GPrint::updateUI));
178         fromTo_->signal_toggled().connect(sigc::mem_fun(*this, &GPrint::updateUI));
179         number_->signal_changed().connect(sigc::mem_fun(*this, &GPrint::updateUI));
180
181         controller().initialiseParams("");
182         update();
183         updateUI();
184 }
185
186 } // namespace frontend
187 } // namespace lyx