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
21 #include "GDocument.h"
24 #include "ControlDocument.h"
25 #include "controllers/helper_funcs.h"
27 #include "support/lstrings.h"
29 #include "lyxtextclasslist.h"
30 #include "bufferparams.h"
31 #include "tex-strings.h"
37 using support::bformat;
41 GDocument::GDocument(Dialog & parent)
42 : GViewCB<ControlDocument, GViewGladeB>(parent, _("Document Settings"), false)
45 void GDocument::doBuild()
47 string const gladeName = findGladeFile("document");
48 xml_ = Gnome::Glade::Xml::create(gladeName);
50 // Manage the action area buttons
52 xml_->get_widget("Cancel", button);
54 xml_->get_widget("OK", button);
56 xml_->get_widget("Apply", button);
58 xml_->get_widget("Revert", button);
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));
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);
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());
84 bformat(_("Unavailable: %1$s"), cit->description());
85 classcombo_.append_text(item);
89 xml_->get_widget("ExtraOptions", extraoptionsentry_);
91 xml_->get_widget("PostscriptDriver", box);
92 box->pack_start(psdrivercombo_, true, true, 0);
95 // Populate Postscript driver combo
96 for (int i = 0; tex_graphics[i][0]; ++i) {
97 psdrivercombo_.append_text(tex_graphics[i]);
100 xml_->get_widget("Font", box);
101 box->pack_start(fontcombo_, true, true, 0);
104 // Populate font combo
105 for (int i = 0; tex_fonts[i][0]; ++i) {
106 fontcombo_.append_text(tex_fonts[i]);
109 xml_->get_widget("FontSize", box);
110 box->pack_start(fontsizecombo_, true, true, 0);
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";
122 Gtk::SpinButton * spin;
123 xml_->get_widget("LineSpacing", spin);
124 linespacingadj_ = spin->get_adjustment();
126 xml_->get_widget("Indentation", indentradio_);
127 xml_->get_widget("VerticalSpace", vspaceradio_);
128 vspaceradio_->signal_toggled().connect(
129 sigc::mem_fun(*this, &GDocument::updateParagraphSeparationSensitivity));
131 xml_->get_widget("VerticalSpaceSize", box);
132 box->pack_start(vspacesizecombo_, true, true, 0);
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;
144 vspacesizecombo_.signal_changed().connect(
146 &GDocument::updateParagraphSeparationSensitivity));
148 xml_->get_widget("VerticalSpaceLength", vspacelengthspin_);
149 vspacelengthadj_ = vspacelengthspin_->get_adjustment();
151 xml_->get_widget("VerticalSpaceUnit", box);
152 box->pack_start(vspaceunitcombo_, true, true, 0);
155 populateUnitCombo(vspaceunitcombo_, false);
157 updateParagraphSeparationSensitivity();
159 // *** End "Document" Page ***
163 void GDocument::update()
165 BufferParams & params = controller().params();
167 // *** Start "Document" Page ***
170 classcombo_.set_active(params.textclass);
173 extraoptionsentry_->set_text(params.options);
176 comboBoxTextSet(psdrivercombo_, params.graphicsDriver);
179 comboBoxTextSet(fontcombo_, params.fonts);
180 for (int i = 0; i <= 3; ++i) {
181 if (fontsizemap_[i] == params.fontsize)
182 fontsizecombo_.set_active(i);
186 linespacingadj_->set_value(params.spacing().getValue());
188 // Paragraph Separation
189 if (params.paragraph_separation == BufferParams::PARSEP_INDENT) {
190 indentradio_->set_active(true);
192 vspaceradio_->set_active(true);
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);
202 LyXLength vspacelen = params.getDefSkip().length().len();
203 setWidgetsFromLength(*vspacelengthadj_, vspaceunitcombo_, vspacelen);
205 // *** End "Document" Page ***
207 // Be a cheesy bastard, for the moment
212 void GDocument::apply()
214 BufferParams & params = controller().params();
216 // *** Start "Document" Page ***
219 params.textclass = classcombo_.get_active_row_number();
222 params.options = extraoptionsentry_->get_text();
225 params.graphicsDriver = psdrivercombo_.get_active_text();
228 params.fonts = fontcombo_.get_active_text();
230 fontsizemap_[fontsizecombo_.get_active_row_number()];
233 params.spacing().set(Spacing::Other, linespacingadj_->get_value());
235 // Paragraph Separation
236 if (indentradio_->get_active()) {
237 params.paragraph_separation = BufferParams::PARSEP_INDENT;
239 params.paragraph_separation = BufferParams::PARSEP_SKIP;
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_,
251 params.setDefSkip(VSpace(LyXGlueLength(length)));
254 // *** End "Document" Page ***
258 void GDocument::saveAsDefaults()
261 controller().saveAsDefault();
265 void GDocument::resetToDefaults()
267 BufferParams & params = controller().params();
268 params.textclass = classcombo_.get_active_row_number();
269 params.useClassDefaults();
274 void GDocument::updateParagraphSeparationSensitivity()
276 bool const vspacesensitive = vspaceradio_->get_active();
278 vspacesizecombo_.set_sensitive(vspacesensitive);
280 bool const lengthsensitive = vspacesensitive &&
281 (vspacesizecombo_.get_active_row_number() == 3);
283 vspacelengthspin_->set_sensitive(lengthsensitive);
284 vspaceunitcombo_.set_sensitive(lengthsensitive);
288 } // namespace frontend