]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GDocument.C
some tabular fixes for the problems reported by Helge
[lyx.git] / src / frontends / gtk / GDocument.C
1 /**
2  * \file GDocument.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Spray
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 "GDocument.h"
22 #include "ghelpers.h"
23
24 #include "ControlDocument.h"
25 #include "controllers/helper_funcs.h"
26
27 #include "support/lstrings.h"
28
29 #include "lyxtextclasslist.h"
30 #include "bufferparams.h"
31 #include "tex-strings.h"
32
33 using std::string;
34
35 namespace lyx {
36
37 using support::bformat;
38
39 namespace frontend {
40
41 GDocument::GDocument(Dialog & parent)
42         : GViewCB<ControlDocument, GViewGladeB>(parent, _("Document Settings"), false)
43 {}
44
45 void GDocument::doBuild()
46 {
47         string const gladeName = findGladeFile("document");
48         xml_ = Gnome::Glade::Xml::create(gladeName);
49
50         // Manage the action area buttons
51         Gtk::Button * button;
52         xml_->get_widget("Cancel", button);
53         setCancel(button);
54         xml_->get_widget("OK", button);
55         setOK(button);
56         xml_->get_widget("Apply", button);
57         setApply(button);
58         xml_->get_widget("Revert", button);
59         setRestore(button);
60
61         xml_->get_widget("UseClassDefaults", button);
62         button->signal_clicked().connect(
63                 sigc::mem_fun(*this, &GDocument::resetToDefaults));
64         xml_->get_widget("SaveAsDocumentDefaults", button);
65         button->signal_clicked().connect(
66                 sigc::mem_fun(*this, &GDocument::saveAsDefaults));
67
68
69         // *** Start "Document" Page ***
70         Gtk::Box * box = NULL;
71         xml_->get_widget("DocumentClass", box);
72         // Prevent combo making dialog super-wide due to long class names
73         classcombo_.set_size_request(1, -1);
74         box->pack_start(classcombo_, true, true, 0);
75         box->show_all();
76
77         // Populate Document Class combo
78         for (LyXTextClassList::const_iterator cit = textclasslist.begin();
79              cit != textclasslist.end(); ++cit) {
80                 if (cit->isTeXClassAvailable()) {
81                         classcombo_.append_text(cit->description());
82                 } else {
83                         string item =
84                                 bformat(_("Unavailable: %1$s"), cit->description());
85                         classcombo_.append_text(item);
86                 }
87         }
88
89         xml_->get_widget("ExtraOptions", extraoptionsentry_);
90
91         xml_->get_widget("PostscriptDriver", box);
92         box->pack_start(psdrivercombo_, true, true, 0);
93         box->show_all();
94
95         // Populate Postscript driver combo
96         for (int i = 0; tex_graphics[i][0]; ++i) {
97                 psdrivercombo_.append_text(tex_graphics[i]);
98         }
99
100         xml_->get_widget("Font", box);
101         box->pack_start(fontcombo_, true, true, 0);
102         box->show_all();
103
104         // Populate font combo
105         for (int i = 0; tex_fonts[i][0]; ++i) {
106                 fontcombo_.append_text(tex_fonts[i]);
107         }
108
109         xml_->get_widget("FontSize", box);
110         box->pack_start(fontsizecombo_, true, true, 0);
111         box->show_all();
112         fontsizecombo_.append_text(_("Default"));
113         fontsizecombo_.append_text(_("10"));
114         fontsizecombo_.append_text(_("11"));
115         fontsizecombo_.append_text(_("12"));
116         // These are the corresponding strings to be passed to the backend
117         fontsizemap_[0] = "default";
118         fontsizemap_[1] = "10";
119         fontsizemap_[2] = "11";
120         fontsizemap_[3] = "12";
121
122         Gtk::SpinButton * spin;
123         xml_->get_widget("LineSpacing", spin);
124         linespacingadj_ = spin->get_adjustment();
125
126         xml_->get_widget("Indentation", indentradio_);
127         xml_->get_widget("VerticalSpace", vspaceradio_);
128         vspaceradio_->signal_toggled().connect(
129                 sigc::mem_fun(*this, &GDocument::updateParagraphSeparationSensitivity));
130
131         xml_->get_widget("VerticalSpaceSize", box);
132         box->pack_start(vspacesizecombo_, true, true, 0);
133         box->show_all();
134         // The order of these items is magic
135         vspacesizecombo_.append_text(_("Small Skip"));
136         vspacesizecombo_.append_text(_("Medium Skip"));
137         vspacesizecombo_.append_text(_("Big Skip"));
138         vspacesizecombo_.append_text(_("Custom"));
139         vspacesizemap_[0] = VSpace::SMALLSKIP;
140         vspacesizemap_[1] = VSpace::MEDSKIP;
141         vspacesizemap_[2] = VSpace::BIGSKIP;
142         vspacesizemap_[3] = VSpace::LENGTH;
143
144         vspacesizecombo_.signal_changed().connect(
145                 sigc::mem_fun(*this,
146                 &GDocument::updateParagraphSeparationSensitivity));
147
148         xml_->get_widget("VerticalSpaceLength", vspacelengthspin_);
149         vspacelengthadj_ = vspacelengthspin_->get_adjustment();
150
151         xml_->get_widget("VerticalSpaceUnit", box);
152         box->pack_start(vspaceunitcombo_, true, true, 0);
153         box->show_all();
154
155         populateUnitCombo(vspaceunitcombo_, false);
156
157         updateParagraphSeparationSensitivity();
158
159         // *** End "Document" Page ***
160 }
161
162
163 void GDocument::update()
164 {
165         BufferParams & params = controller().params();
166
167         // *** Start "Document" Page ***
168
169         // Document Class
170         classcombo_.set_active(params.textclass);
171
172         // Extra Options
173         extraoptionsentry_->set_text(params.options);
174
175         // Postscript driver
176         comboBoxTextSet(psdrivercombo_, params.graphicsDriver);
177
178         // Font & Size
179         comboBoxTextSet(fontcombo_, params.fonts);
180         for (int i = 0; i <= 3; ++i) {
181                 if (fontsizemap_[i] == params.fontsize)
182                         fontsizecombo_.set_active(i);
183         }
184
185         // Line Spacing
186         linespacingadj_->set_value(params.spacing().getValue());
187
188         // Paragraph Separation
189         if (params.paragraph_separation == BufferParams::PARSEP_INDENT) {
190                 indentradio_->set_active(true);
191         } else {
192                 vspaceradio_->set_active(true);
193         }
194
195         // Paragraph Separation Vertical Space Size
196         VSpace::vspace_kind const skipkind = params.getDefSkip().kind();
197         for (int i = 0; i <= 3; ++i) {
198                 if (vspacesizemap_[i] == skipkind)
199                         vspacesizecombo_.set_active(i);
200         }
201
202         LyXLength vspacelen = params.getDefSkip().length().len();
203         setWidgetsFromLength(*vspacelengthadj_, vspaceunitcombo_, vspacelen);
204
205         // *** End "Document" Page ***
206
207         // Be a cheesy bastard, for the moment
208         bc().valid();
209 }
210
211
212 void GDocument::apply()
213 {
214         BufferParams & params = controller().params();
215
216         // *** Start "Document" Page ***
217
218         // Document Class
219         params.textclass = classcombo_.get_active_row_number();
220
221         // Extra Options
222         params.options = extraoptionsentry_->get_text();
223
224         // Postscript Driver
225         params.graphicsDriver = psdrivercombo_.get_active_text();
226
227         // Font & Size
228         params.fonts = fontcombo_.get_active_text();
229         params.fontsize =
230                 fontsizemap_[fontsizecombo_.get_active_row_number()];
231
232         // Line Spacing
233         params.spacing().set(Spacing::Other, linespacingadj_->get_value());
234
235         // Paragraph Separation
236         if (indentradio_->get_active()) {
237                 params.paragraph_separation = BufferParams::PARSEP_INDENT;
238         } else {
239                 params.paragraph_separation = BufferParams::PARSEP_SKIP;
240         }
241
242         // Paragraph Separation Vertical Space Size
243         VSpace::vspace_kind const selection =
244                 vspacesizemap_[vspacesizecombo_.get_active_row_number()];
245         params.setDefSkip(VSpace(selection));
246         if (selection == VSpace::LENGTH) {
247                 string const length =
248                 getLengthFromWidgets(*vspacelengthadj_,
249                                      vspaceunitcombo_);
250
251                 params.setDefSkip(VSpace(LyXGlueLength(length)));
252         }
253
254         // *** End "Document" Page ***
255 }
256
257
258 void GDocument::saveAsDefaults()
259 {
260         apply();
261         controller().saveAsDefault();
262 }
263
264
265 void GDocument::resetToDefaults()
266 {
267         BufferParams & params = controller().params();
268         params.textclass = classcombo_.get_active_row_number();
269         params.useClassDefaults();
270         update();
271 }
272
273
274 void GDocument::updateParagraphSeparationSensitivity()
275 {
276         bool const vspacesensitive = vspaceradio_->get_active();
277
278         vspacesizecombo_.set_sensitive(vspacesensitive);
279
280         bool const lengthsensitive = vspacesensitive &&
281                 (vspacesizecombo_.get_active_row_number() == 3);
282
283         vspacelengthspin_->set_sensitive(lengthsensitive);
284         vspaceunitcombo_.set_sensitive(lengthsensitive);
285 }
286
287
288 } // namespace frontend
289 } // namespace lyx