]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GPrint.C
some tabular fixes for the problems reported by Helge
[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 std::string;
33 using namespace lyx::support;
34
35 namespace lyx {
36 namespace frontend {
37
38 GPrint::GPrint(Dialog & parent, string const & title)
39         : GViewCB<ControlPrint, GViewGladeB>(parent, title, false)
40 {
41 }
42
43
44 void GPrint::apply()
45 {
46         PrinterParams pp;
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());
56         }
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;
63 }
64
65
66 void GPrint::update()
67 {
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);
73
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);
86 }
87
88
89 void GPrint::updateUI()
90 {
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;
101         }
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);
107 }
108
109
110 void GPrint::onBrowse()
111 {
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);
118         updateUI();
119 }
120
121
122 void GPrint::onTargetEdit(Gtk::Entry const * who)
123 {
124         if (who == fileEntry_)
125                 file_->set_active(true);
126         else if (who == printerEntry_)
127                 printer_->set_active(true);
128         updateUI();
129 }
130
131
132 void GPrint::onFromToEdit()
133 {
134         fromTo_->set_active(true);
135         updateUI();
136 }
137
138
139 void GPrint::doBuild()
140 {
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_);
156
157         Gtk::Button * ok;
158         Gtk::Button * cancel;
159         xml_->get_widget("PrintButton", ok);
160         xml_->get_widget("CancelButton", cancel);
161
162         setOK(ok);
163         setCancel(cancel);
164
165         Gtk::Button * browse;
166         xml_->get_widget("Browse", browse);
167         browse->signal_clicked().connect(sigc::mem_fun(*this, &GPrint::onBrowse));
168
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));
178
179         controller().initialiseParams("");
180         update();
181         updateUI();
182 }
183
184 } // namespace frontend
185 } // namespace lyx