]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GDocument.C
c9c253b786003c8515c7b140a4fe5274095f2c4f
[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 #include "controllers/frnt_lang.h"
27
28 #include "support/lstrings.h"
29 #include "lyxrc.h"
30
31 #include "lyxtextclasslist.h"
32 #include "bufferparams.h"
33 #include "tex-strings.h"
34 #include "language.h"
35
36 using std::string;
37 using std::vector;
38
39 namespace lyx {
40
41 using support::bformat;
42 using support::token;
43 using support::contains;
44
45 namespace frontend {
46
47 namespace {
48
49 char const * const encodings[] = { "Language Default", "LaTeX default",
50         "latin1", "latin2", "latin3", "latin4", "latin5", "latin9",
51         "koi8-r", "koi8-u", "cp866", "cp1251", "iso88595", "pt154", 0
52 };
53
54 }
55
56
57 GDocument::GDocument(Dialog & parent)
58         : GViewCB<ControlDocument, GViewGladeB>(parent, _("Document Settings"), false),
59         lang_(getSecond(getLanguageData(false)))
60 {}
61
62 void GDocument::doBuild()
63 {
64         string const gladeName = findGladeFile("document");
65         xml_ = Gnome::Glade::Xml::create(gladeName);
66
67         // Manage the action area buttons
68         Gtk::Button * button;
69         xml_->get_widget("Cancel", button);
70         setCancel(button);
71         xml_->get_widget("OK", button);
72         setOK(button);
73         xml_->get_widget("Apply", button);
74         setApply(button);
75         xml_->get_widget("Revert", button);
76         setRestore(button);
77
78         xml_->get_widget("UseClassDefaults", button);
79         button->signal_clicked().connect(
80                 sigc::mem_fun(*this, &GDocument::resetToDefaults));
81         xml_->get_widget("SaveAsDocumentDefaults", button);
82         button->signal_clicked().connect(
83                 sigc::mem_fun(*this, &GDocument::saveAsDefaults));
84
85
86         // *** Start "Document" Page ***
87         Gtk::Box * box = NULL;
88         xml_->get_widget("DocumentClass", box);
89         // Prevent combo making dialog super-wide due to long class names
90         classcombo_.set_size_request(1, -1);
91         box->pack_start(classcombo_, true, true, 0);
92         box->show_all();
93
94         classcombo_.signal_changed().connect(
95                 sigc::mem_fun(*this, &GDocument::classChanged));
96
97         // Populate Document Class combo
98         for (LyXTextClassList::const_iterator cit = textclasslist.begin();
99              cit != textclasslist.end(); ++cit) {
100                 if (cit->isTeXClassAvailable()) {
101                         classcombo_.append_text(cit->description());
102                 } else {
103                         string item =
104                                 bformat(_("Unavailable: %1$s"), cit->description());
105                         classcombo_.append_text(item);
106                 }
107         }
108
109         xml_->get_widget("ExtraOptions", extraoptionsentry_);
110
111         xml_->get_widget("PostscriptDriver", box);
112         box->pack_start(psdrivercombo_, true, true, 0);
113         box->show_all();
114
115         // Populate Postscript driver combo
116         for (int i = 0; tex_graphics[i][0]; ++i) {
117                 psdrivercombo_.append_text(tex_graphics[i]);
118         }
119
120         xml_->get_widget("Font", box);
121         box->pack_start(fontcombo_, true, true, 0);
122         box->show_all();
123
124         // Populate font combo
125         for (int i = 0; tex_fonts[i][0]; ++i) {
126                 fontcombo_.append_text(tex_fonts[i]);
127         }
128
129         xml_->get_widget("FontSize", box);
130         box->pack_start(fontsizecombo_, true, true, 0);
131         box->show_all();
132
133         Gtk::SpinButton * spin;
134         xml_->get_widget("LineSpacing", spin);
135         linespacingadj_ = spin->get_adjustment();
136
137         xml_->get_widget("Indentation", indentradio_);
138         xml_->get_widget("VerticalSpace", vspaceradio_);
139         vspaceradio_->signal_toggled().connect(
140                 sigc::mem_fun(*this, &GDocument::updateParagraphSeparationSensitivity));
141
142
143         xml_->get_widget("VerticalSpaceSize", box);
144         box->pack_start(vspacesizecombo_, true, true, 0);
145         box->show_all();
146         // The order of these items is magic
147         vspacesizecombo_.append_text(_("Small Skip"));
148         vspacesizecombo_.append_text(_("Medium Skip"));
149         vspacesizecombo_.append_text(_("Big Skip"));
150         vspacesizecombo_.append_text(_("Custom"));
151         vspacesizemap_[0] = VSpace::SMALLSKIP;
152         vspacesizemap_[1] = VSpace::MEDSKIP;
153         vspacesizemap_[2] = VSpace::BIGSKIP;
154         vspacesizemap_[3] = VSpace::LENGTH;
155
156         vspacesizecombo_.signal_changed().connect(
157                 sigc::mem_fun(*this,
158                 &GDocument::updateParagraphSeparationSensitivity));
159
160         xml_->get_widget_derived("VerticalSpaceLength", vspacelengthentry_);
161         vspacelengthentry_->set_relative(false);
162
163         updateParagraphSeparationSensitivity();
164         // *** End "Document" Page ***
165
166         // *** Begin "Page" Page ***
167         xml_->get_widget("PageSize", box);
168         box->pack_start(pagesizecombo_, true, true, 0);
169         box->show_all();
170         pagesizecombo_.append_text(_("Default"));
171         pagesizecombo_.append_text(_("Custom"));
172         pagesizecombo_.append_text(_("US letter"));
173         pagesizecombo_.append_text(_("US legal"));
174         pagesizecombo_.append_text(_("US executive"));
175         pagesizecombo_.append_text(_("A3"));
176         pagesizecombo_.append_text(_("A4"));
177         pagesizecombo_.append_text(_("A5"));
178         pagesizecombo_.append_text(_("B3"));
179         pagesizecombo_.append_text(_("B4"));
180         pagesizecombo_.append_text(_("B5"));
181         pagesizecombo_.signal_changed().connect(
182                 sigc::mem_fun(*this, &GDocument::pageSizeChanged));
183
184         xml_->get_widget_derived("PageWidth", pagewidthlengthentry_);
185         xml_->get_widget_derived("PageHeight", pageheightlengthentry_);
186         pagewidthlengthentry_->set_relative(false);
187         pageheightlengthentry_->set_relative(false);
188
189         xml_->get_widget("Portrait", portraitradio_);
190         xml_->get_widget("Landscape", landscaperadio_);
191
192         xml_->get_widget("PageStyle", box);
193         box->pack_start(pagestylecombo_, true, true, 0);
194         box->show_all();
195         xml_->get_widget("DoubleSided", doublesidedtoggle_);
196         xml_->get_widget("TwoColumns", twocolumnstoggle_);
197         // *** End "Page" Page ***
198
199         // *** Begin "Margins" Page ***
200         xml_->get_widget("DefaultMargins", defaultmargins_);
201         defaultmargins_->signal_toggled().connect(
202                 sigc::mem_fun(*this, &GDocument::marginsChanged));
203
204         xml_->get_widget_derived("MarginsTop", mtoplengthentry_);
205         xml_->get_widget_derived("MarginsBottom", mbottomlengthentry_);
206         xml_->get_widget_derived("MarginsInner", minnerlengthentry_);
207         xml_->get_widget_derived("MarginsOuter", mouterlengthentry_);
208         xml_->get_widget_derived("MarginsHeadSep", mheadseplengthentry_);
209         xml_->get_widget_derived("MarginsHeadHeight", mheadheightlengthentry_);
210         xml_->get_widget_derived("MarginsFootSkip", mfootskiplengthentry_);
211         // *** End "Margins" Page ***
212
213         // *** Start "Language" Page ***
214         xml_->get_widget("Language", box);
215         box->pack_start(languagecombo_, true, true, 0);
216         box->show_all();
217
218         vector<LanguagePair> const langs = getLanguageData(false);
219         vector<LanguagePair>::const_iterator lit  = langs.begin();
220         vector<LanguagePair>::const_iterator lend = langs.end();
221         for (; lit != lend; ++lit) {
222                 languagecombo_.append_text(lit->first);
223         }
224
225         xml_->get_widget("TextEncoding", box);
226         box->pack_start(encodingcombo_, true, true, 0);
227         box->show_all();
228
229         int i = 0;
230         while (encodings[i])
231                 encodingcombo_.append_text(encodings[i++]);
232
233         xml_->get_widget("EnglishQuote", qenglishradio_);
234         xml_->get_widget("SwedishQuote", qswedishradio_);
235         xml_->get_widget("GermanQuote", qgermanradio_);
236         xml_->get_widget("PolishQuote", qpolishradio_);
237         xml_->get_widget("FrenchQuote", qfrenchradio_);
238         xml_->get_widget("DanishQuote", qdanishradio_);
239         // *** End "Language" Page ***
240
241         // *** Start "Numbering" Page ***
242         Gtk::HScale * scale;
243         xml_->get_widget("Numbering", scale);
244         numberingadj_ = scale->get_adjustment();
245         numberingadj_->signal_value_changed().connect(
246                 sigc::mem_fun(*this, &GDocument::numberingChanged));
247         xml_->get_widget("NumberingLabel", numberinglabel_);
248
249         xml_->get_widget("TOC", scale);
250         TOCadj_ = scale->get_adjustment();
251         TOCadj_->signal_value_changed().connect(
252                 sigc::mem_fun(*this, &GDocument::TOCChanged));
253         xml_->get_widget("TOCLabel", TOClabel_);
254         // *** End "Numbering" Page ***
255
256         // *** Start "Bibliography" Page ***
257         xml_->get_widget("BasicNumerical", basicnumericalradio_);
258         xml_->get_widget("NatbibNumerical", natbibnumericalradio_);
259         xml_->get_widget("NatbibAuthorYear", natbibauthoryearradio_);
260         xml_->get_widget("Jurabib", jurabibradio_);
261         xml_->get_widget("SectionedBibliography", sectionedbibliographytoggle_);
262         // *** End "Bibliography" Page ***
263
264         // *** Start "Math" Page ***
265         xml_->get_widget("AMSAutomatically", AMSautomaticallyradio_);
266         xml_->get_widget("AMSAlways", AMSalwaysradio_);
267         xml_->get_widget("AMSNever", AMSneverradio_);
268         // *** End "Math" Page ***
269
270         // *** Start "Floats" Page ***
271         xml_->get_widget("DocumentDefault", defaultradio_);
272         xml_->get_widget("HereDefinitely", heredefinitelyradio_);
273         xml_->get_widget("Alternative", alternativeradio_);
274         alternativeradio_->signal_toggled().connect(
275                 sigc::mem_fun(*this, &GDocument::alternativeChanged));
276         xml_->get_widget("TopOfPage", topcheck_);
277         xml_->get_widget("BottomOfPage", bottomcheck_);
278         xml_->get_widget("PageOfFloats", pageoffloatscheck_);
279         xml_->get_widget("HereIfPossible", hereifpossiblecheck_);
280         xml_->get_widget("IgnoreRules", ignorerulescheck_);
281         // Initial sensitivity
282         GDocument::alternativeChanged();
283
284         // *** End "Floats" Page ***
285
286         // *** Start "Bullets" Page ***
287         // *** End "Bullets" Page ***
288
289         // *** Start "Branches" Page ***
290         xml_->get_widget("Branches", branchesview_);
291         xml_->get_widget("AddBranch", addbranchbutton_);
292         addbranchbutton_->signal_clicked().connect(
293                 sigc::mem_fun(*this, &GDocument::addBranch));
294         xml_->get_widget("RemoveBranch", removebranchbutton_);
295         removebranchbutton_->signal_clicked().connect(
296                 sigc::mem_fun(*this, &GDocument::removeBranch));
297         branchCols_.add(branchColName_);
298         branchCols_.add(branchColActivated_);
299         branchCols_.add(branchColColor_);
300
301         branchliststore_ = Gtk::ListStore::create(branchCols_);
302         branchesview_->set_model(branchliststore_);
303         branchesview_->append_column_editable(_("Name"), branchColName_);
304         branchesview_->append_column_editable(_("Activated"), branchColActivated_);
305         branchesview_->append_column_editable(_("Color"), branchColColor_);
306         branchsel_ = branchesview_->get_selection();
307
308         branchsel_->signal_changed().connect(
309                 sigc::mem_fun(*this, &GDocument::branchSelChanged));
310
311         /*
312         ErrorList::const_iterator cit = errors.begin();
313         ErrorList::const_iterator end = errors.end();
314         for (int rowindex = 0; cit != end; ++cit, ++rowindex) {
315                 Gtk::ListStore::Row row = *errliststore_->append();
316                 if (rowindex == 0)
317                         errlistsel_->select(*row);
318
319                 (*row)[listCol_] = cit->error;
320                 (*row)[listColIndex_] = rowindex;
321         }
322         */
323         Gtk::ListStore::Row row = *branchliststore_->append();
324         (*row)[branchColName_] = "Munch";
325         (*row)[branchColActivated_] = false;
326         row = *branchliststore_->append();
327         (*row)[branchColName_] = "Hunch";
328         (*row)[branchColActivated_] = true;
329         // *** End "Branches" Page ***
330
331         // *** Begin "Preamble" Page ***
332         Gtk::TextView *view;
333         xml_->get_widget ("Preamble", view);
334         preamblebuffer_ = view->get_buffer();
335         // *** End "Preamble" Page ***
336 }
337
338
339 void GDocument::update()
340 {
341         BufferParams & params = controller().params();
342
343         // *** Start "Document" Page ***
344
345         // Document Class
346         classcombo_.set_active(params.textclass);
347
348         // Extra Options
349         extraoptionsentry_->set_text(params.options);
350
351         // Postscript driver
352         comboBoxTextSet(psdrivercombo_, params.graphicsDriver);
353
354         // Font & Size
355         comboBoxTextSet(fontcombo_, params.fonts);
356         comboBoxTextSet(fontsizecombo_, params.fontsize);
357
358         // Line Spacing
359         linespacingadj_->set_value(params.spacing().getValue());
360
361         // Paragraph Separation
362         if (params.paragraph_separation == BufferParams::PARSEP_INDENT) {
363                 indentradio_->set_active(true);
364         } else {
365                 vspaceradio_->set_active(true);
366         }
367
368         // Paragraph Separation Vertical Space Size
369         VSpace::vspace_kind const skipkind = params.getDefSkip().kind();
370         for (int i = 0; i <= 3; ++i) {
371                 if (vspacesizemap_[i] == skipkind)
372                         vspacesizecombo_.set_active(i);
373         }
374
375         LyXLength vspacelen = params.getDefSkip().length().len();
376         vspacelengthentry_->set_length (vspacelen);
377
378         // *** End "Document" Page ***
379
380         // *** Begin "Page" Page ***
381         int const psize = params.papersize;
382         pagesizecombo_.set_active(psize);
383
384         pagewidthlengthentry_->set_length(LyXLength(params.paperwidth));
385         pageheightlengthentry_->set_length(LyXLength(params.paperheight));
386
387         if (params.orientation == ORIENTATION_PORTRAIT)
388                 portraitradio_->set_active();
389         else
390                 landscaperadio_->set_active();
391
392         if (params.columns == 2)
393                 twocolumnstoggle_->set_active(true);
394         else
395                 twocolumnstoggle_->set_active(false);
396
397         doublesidedtoggle_->set_active(params.sides == LyXTextClass::TwoSides);
398
399         comboBoxTextSet(pagestylecombo_, params.pagestyle);
400         // *** End "Page" Page ***
401
402         defaultmargins_->set_active(!params.use_geometry);
403
404         mtoplengthentry_->set_length(params.topmargin);
405         mbottomlengthentry_->set_length(params.bottommargin);
406         minnerlengthentry_->set_length(params.leftmargin);
407         mouterlengthentry_->set_length(params.rightmargin);
408         mheadseplengthentry_->set_length(params.headsep);
409         mheadheightlengthentry_->set_length(params.headheight);
410         mfootskiplengthentry_->set_length(params.footskip);
411
412         marginsChanged();
413         // *** End "Margins" Page ***
414
415         // *** Start "Language" Page ***
416         int const langpos = findPos(lang_,
417                 params.language->lang());
418         languagecombo_.set_active(langpos);
419
420         // Default to "auto"
421         encodingcombo_.set_active(0);
422         if (params.inputenc == "default") {
423                 encodingcombo_.set_active(1);
424         } else {
425                 int i = 0;
426                 while (encodings[i]) {
427                         if (encodings[i] == params.inputenc)
428                                 encodingcombo_.set_active(i);
429                         ++i;
430                 }
431         }
432
433         switch (params.quotes_language) {
434         case InsetQuotes::EnglishQ:
435                 qenglishradio_->set_active();
436                 break;
437         case InsetQuotes::SwedishQ:
438                 qswedishradio_->set_active();
439                 break;
440         case InsetQuotes::GermanQ:
441                 qgermanradio_->set_active();
442                 break;
443         case InsetQuotes::PolishQ:
444                 qpolishradio_->set_active();
445                 break;
446         case InsetQuotes::FrenchQ:
447                 qfrenchradio_->set_active();
448                 break;
449         case InsetQuotes::DanishQ:
450                 qdanishradio_->set_active();
451                 break;
452         }
453
454         // *** End "Language" Page ***
455
456         // *** Start "Numbering" Page ***
457         numberingadj_->set_value(params.secnumdepth + 2);
458         TOCadj_->set_value(params.tocdepth + 1);
459         // *** End "Numbering" Page ***
460
461         // *** Start "Bibliography" Page ***
462         switch (params.cite_engine) {
463         case biblio::ENGINE_BASIC:
464                 basicnumericalradio_->set_active();
465                 break;
466         case biblio::ENGINE_NATBIB_NUMERICAL:
467                 natbibnumericalradio_->set_active();
468                 break;
469         case biblio::ENGINE_NATBIB_AUTHORYEAR:
470                 natbibauthoryearradio_->set_active();
471                 break;
472         case biblio::ENGINE_JURABIB:
473                 jurabibradio_->set_active();
474                 break;
475         }
476
477         sectionedbibliographytoggle_->set_active(params.use_bibtopic);
478         // *** End "Bibliography" Page ***
479
480         // *** Start "Math" Page ***
481         switch (params.use_amsmath) {
482         case BufferParams::AMS_AUTO:
483                 AMSautomaticallyradio_->set_active();
484                 break;
485         case BufferParams::AMS_ON:
486                 AMSalwaysradio_->set_active();
487                 break;
488         case BufferParams::AMS_OFF:
489                 AMSneverradio_->set_active();
490                 break;
491         }
492         // *** End "Math" Page ***
493
494         // *** Start "Floats" Page ***
495         string const placement = params.float_placement;
496         bool const here_definitely = contains(placement, 'H');
497         bool const top    = contains(placement, 't');
498         bool const bottom = contains(placement, 'b');
499         bool const page   = contains(placement, 'p');
500         bool const here   = contains(placement, 'h');
501         bool const force  = contains(placement, '!');
502         bool const alternatives = top || bottom || page || here;
503
504         if (alternatives) {
505                 alternativeradio_->set_active(true);
506         } else if (here_definitely) {
507                 heredefinitelyradio_->set_active(true);
508         } else {
509                 defaultradio_->set_active(true);
510         }
511         ignorerulescheck_->set_active(force);
512         topcheck_->set_active(top);
513         bottomcheck_->set_active(bottom);
514         pageoffloatscheck_->set_active(page);
515         hereifpossiblecheck_->set_active(here);
516
517         // *** End "Floats" Page ***
518
519         // *** Start "Bullets" Page ***
520         // *** End "Bullets" Page ***
521
522         // *** Start "Branches" Page ***
523         branchliststore_->clear();
524
525         BranchList::const_iterator it = params.branchlist().begin();
526         BranchList::const_iterator const end = params.branchlist().end();
527         for (; it != end; ++it) {
528                 Gtk::ListStore::Row row = *branchliststore_->append();
529                 (*row)[branchColName_] = (*it).getBranch();
530                 std::cerr << "update: loading '" << (*it).getBranch() << "'\n";
531                 (*row)[branchColActivated_] = (*it).getSelected();
532                 (*row)[branchColColor_] = (*it).getColor();
533         }
534         // *** End "Branches" Page ***
535
536         // *** Begin "Preamble" Page ***
537         preamblebuffer_->set_text(params.preamble);
538         // *** End "Preamble" Page ***
539
540         // Be a cheesy bastard, for the moment
541         bc().valid();
542 }
543
544
545 void GDocument::apply()
546 {
547         BufferParams & params = controller().params();
548
549         // *** Start "Document" Page ***
550
551         // Document Class
552         params.textclass = classcombo_.get_active_row_number();
553
554         // Extra Options
555         params.options = extraoptionsentry_->get_text();
556
557         // Postscript Driver
558         params.graphicsDriver = psdrivercombo_.get_active_text();
559
560         // Font & Size
561         params.fonts = fontcombo_.get_active_text();
562         params.fontsize = fontsizecombo_.get_active_text();
563
564         // Line Spacing
565         params.spacing().set(Spacing::Other, linespacingadj_->get_value());
566
567         // Paragraph Separation
568         if (indentradio_->get_active()) {
569                 params.paragraph_separation = BufferParams::PARSEP_INDENT;
570         } else {
571                 params.paragraph_separation = BufferParams::PARSEP_SKIP;
572         }
573
574         // Paragraph Separation Vertical Space Size
575         VSpace::vspace_kind const selection =
576                 vspacesizemap_[vspacesizecombo_.get_active_row_number()];
577         params.setDefSkip(VSpace(selection));
578         if (selection == VSpace::LENGTH) {
579                 LyXLength length = vspacelengthentry_->get_length();
580                 params.setDefSkip(VSpace(LyXGlueLength(length)));
581         }
582
583         // *** End "Document" Page ***
584
585         // *** Begin "Page" Page ***
586         params.papersize = PAPER_SIZE(
587                 pagesizecombo_.get_active_row_number());
588
589         params.paperwidth = pagewidthlengthentry_->get_length_string();
590         params.paperheight = pageheightlengthentry_->get_length_string();
591
592         if (portraitradio_->get_active())
593                 params.orientation = ORIENTATION_PORTRAIT;
594         else
595                 params.orientation = ORIENTATION_LANDSCAPE;
596
597         if (twocolumnstoggle_->get_active())
598                 params.columns = 2;
599         else
600                 params.columns = 1;
601
602         if (doublesidedtoggle_->get_active())
603                 params.sides = LyXTextClass::TwoSides;
604         else
605                 params.sides = LyXTextClass::OneSide;
606
607         params.pagestyle = pagestylecombo_.get_active_text();
608         // *** End "Page" Page ***
609
610         // *** Begin "Margins" Page ***
611         params.use_geometry = !defaultmargins_->get_active();
612
613         params.topmargin = mtoplengthentry_->get_length_string();
614         params.bottommargin = mbottomlengthentry_->get_length_string();
615         params.leftmargin = minnerlengthentry_->get_length_string();
616         params.rightmargin = mouterlengthentry_->get_length_string();
617         params.headsep = mheadseplengthentry_->get_length_string();
618         params.headheight = mheadheightlengthentry_->get_length_string();
619         params.footskip = mfootskiplengthentry_->get_length_string();
620         // *** End "Margins" Page ***
621
622         // *** Start "Language" Page ***
623         int const encodingsel = encodingcombo_.get_active_row_number();
624         if (encodingsel == 0)
625                 params.inputenc = "auto";
626         else if (encodingsel == 1)
627                 params.inputenc = "default";
628         else
629                 params.inputenc = encodings[encodingsel];
630
631         int const langsel = languagecombo_.get_active_row_number();
632         params.language = languages.getLanguage(lang_[langsel]);
633
634         if (qenglishradio_->get_active())
635                 params.quotes_language = InsetQuotes::EnglishQ;
636         else if (qswedishradio_->get_active())
637                 params.quotes_language = InsetQuotes::SwedishQ;
638         else if (qgermanradio_->get_active())
639                 params.quotes_language = InsetQuotes::GermanQ;
640         else if (qpolishradio_->get_active())
641                 params.quotes_language = InsetQuotes::PolishQ;
642         else if (qfrenchradio_->get_active())
643                 params.quotes_language = InsetQuotes::FrenchQ;
644         else if (qdanishradio_->get_active())
645                 params.quotes_language = InsetQuotes::DanishQ;
646         // *** End "Language" Page ***
647
648         // *** Start "Numbering" Page ***
649         params.secnumdepth = (int)(numberingadj_->get_value()) - 2;
650         params.tocdepth = (int)(TOCadj_->get_value()) - 1;
651         // *** End "Numbering" Page ***
652
653         // *** Start "Bibliography" Page ***
654         if (basicnumericalradio_->get_active())
655                 params.cite_engine = biblio::ENGINE_BASIC;
656         else if (natbibnumericalradio_->get_active())
657                 params.cite_engine = biblio::ENGINE_NATBIB_NUMERICAL;
658         else if (natbibauthoryearradio_->get_active())
659                 params.cite_engine = biblio::ENGINE_NATBIB_AUTHORYEAR;
660         else if (jurabibradio_->get_active())
661                 params.cite_engine = biblio::ENGINE_JURABIB;
662
663         params.use_bibtopic = sectionedbibliographytoggle_->get_active();
664         // *** End "Bibliography" Page ***
665
666         // *** Start "Math" Page ***
667         if (AMSautomaticallyradio_->get_active())
668                 params.use_amsmath = BufferParams::AMS_AUTO;
669         else if (AMSalwaysradio_->get_active())
670                 params.use_amsmath = BufferParams::AMS_ON;
671         else if (AMSneverradio_->get_active())
672                 params.use_amsmath = BufferParams::AMS_OFF;
673         // *** End "Math" Page ***
674
675         // *** Start "Floats" Page ***
676         string placement;
677         if (alternativeradio_->get_active()) {
678                 if (ignorerulescheck_->get_active())
679                         placement += '!';
680                 if (topcheck_->get_active())
681                         placement += 't';
682                 if (bottomcheck_->get_active())
683                         placement += 'b';
684                 if (pageoffloatscheck_->get_active())
685                         placement += 'p';
686                 if (hereifpossiblecheck_->get_active())
687                         placement += 'h';
688                 if (placement == "!")
689                         placement.erase();
690         } else if (heredefinitelyradio_->get_active())
691                 placement = "H";
692
693         params.float_placement = placement;
694         // *** End "Floats" Page ***
695
696         // *** Start "Bullets" Page ***
697         // *** End "Bullets" Page ***
698
699         // *** Start "Branches" Page ***
700         /*branchliststore_->clear();
701
702         BranchList::const_iterator it = params.branchlist().begin();
703         BranchList::const_iterator const end = params.branchlist().end();
704         for (; it != end; ++it) {
705                 Gtk::ListStore::Row row = *branchliststore_->append();
706                 (*row)[branchColName_] = (*it).getBranch();
707                 (*row)[branchColActivated_] = (*it).getSelected();
708                 (*row)[branchColColor_] = (*it).getColor();
709         }*/
710
711         BranchList branchlist;
712
713         Gtk::ListStore::iterator it = branchliststore_->children().begin();
714         Gtk::ListStore::iterator const end = branchliststore_->children().end();
715         for (; it != end; ++it) {
716                 Gtk::ListStore::Row row = *it;
717                 Glib::ustring const name = (*row)[branchColName_];
718                 if (branchlist.add(name)) {
719                         std::cerr << "apply: adding '" << name << "'\n";
720                         Branch * newbranch = branchlist.find(name);
721                         newbranch->setSelected((*row)[branchColActivated_]);
722                         Glib::ustring const color = (*row)[branchColColor_];
723                         newbranch->setColor(color);
724                 }
725         }
726
727         params.branchlist() = branchlist;
728
729         // *** End "Branches" Page ***
730
731         // *** Begin "Preamble" Page ***
732         params.preamble = preamblebuffer_->get_text();
733         // *** End "Preamble" Page ***
734 }
735
736
737 void GDocument::saveAsDefaults()
738 {
739         apply();
740         controller().saveAsDefault();
741 }
742
743
744 void GDocument::resetToDefaults()
745 {
746         BufferParams & params = controller().params();
747         params.textclass = classcombo_.get_active_row_number();
748         params.useClassDefaults();
749         update();
750 }
751
752
753 void GDocument::updateParagraphSeparationSensitivity()
754 {
755         bool const vspacesensitive = vspaceradio_->get_active();
756
757         vspacesizecombo_.set_sensitive(vspacesensitive);
758
759         bool const lengthsensitive = vspacesensitive &&
760                 (vspacesizecombo_.get_active_row_number() == 3);
761
762         vspacelengthentry_->set_sensitive(lengthsensitive);
763 }
764
765
766 void GDocument::classChanged()
767 {
768         ControlDocument & ctrl = controller();
769         BufferParams & params = ctrl.params();
770
771         lyx::textclass_type const tc = classcombo_.get_active_row_number();
772
773         if (ctrl.loadTextclass(tc)) {
774                 params.textclass = tc;
775
776                 if (lyxrc.auto_reset_options) {
777                         params.useClassDefaults();
778                         update();
779                 } else {
780                         fontsizecombo_.clear();
781                         fontsizecombo_.append_text("default");
782
783                         string const fontsizeitems = ctrl.textClass().opt_fontsize();
784                         for (int n = 0; !token(fontsizeitems, '|', n).empty(); ++n)
785                                 fontsizecombo_.append_text(token(fontsizeitems, '|', n));
786
787                         comboBoxTextSet(fontsizecombo_, params.fontsize);
788
789                         pagestylecombo_.clear();
790                         pagestylecombo_.append_text("default");
791
792                         string const pagestyleitems = ctrl.textClass().opt_pagestyle();
793                         for (int n=0; !token(pagestyleitems,'|',n).empty(); ++n)
794                                 pagestylecombo_.append_text(token(pagestyleitems,'|',n));
795
796                         comboBoxTextSet(pagestylecombo_, params.pagestyle);
797                 }
798         } else {
799                 classcombo_.set_active(params.textclass);
800         }
801 }
802
803
804 void GDocument::pageSizeChanged()
805 {
806         bool const customsize = pagesizecombo_.get_active_row_number() == 1;
807         pagewidthlengthentry_->set_sensitive(customsize);
808         pageheightlengthentry_->set_sensitive(customsize);
809
810         if (customsize)
811                 portraitradio_->set_active();
812 }
813
814
815 void GDocument::marginsChanged()
816 {
817         bool const custom = !defaultmargins_->get_active();
818
819         mtoplengthentry_->set_sensitive(custom);
820         mbottomlengthentry_->set_sensitive(custom);
821         minnerlengthentry_->set_sensitive(custom);
822         mouterlengthentry_->set_sensitive(custom);
823         mheadseplengthentry_->set_sensitive(custom);
824         mheadheightlengthentry_->set_sensitive(custom);
825         mfootskiplengthentry_->set_sensitive(custom);
826 }
827
828
829 void GDocument::numberingChanged()
830 {
831         string const numberinglabels[] = {
832                 _("No headings numbered"),
833                 _("Only parts numbered"),
834                 _("Chapters and above numbered"),
835                 _("Sections and above numbered"),
836                 _("Subsections and above numbered"),
837                 _("Subsubsections and above numbered"),
838                 _("Paragraphs and above numbered"),
839                 _("All headings numbered")
840         };
841
842         int const value = (int)(numberingadj_->get_value());
843         numberinglabel_->set_label("<i>" + numberinglabels[value] + "</i>");
844 }
845
846
847 void GDocument::TOCChanged()
848 {
849         string const TOClabels[] = {
850                 _("Only Parts appear in TOC"),
851                 _("Chapters and above appear in TOC"),
852                 _("Sections and above appear in TOC"),
853                 _("Subsections and above appear in TOC"),
854                 _("Subsubsections and above appear in TOC"),
855                 _("Paragraphs and above appear in TOC"),
856                 _("TOC contains all headings")
857         };
858
859         int const value = (int)(TOCadj_->get_value());
860         TOClabel_->set_label("<i>" + TOClabels[value] + "</i>");
861 }
862
863
864 void GDocument::alternativeChanged()
865 {
866         bool const sens = alternativeradio_->get_active();
867         topcheck_->set_sensitive(sens);
868         bottomcheck_->set_sensitive(sens);
869         pageoffloatscheck_->set_sensitive(sens);
870         hereifpossiblecheck_->set_sensitive(sens);
871         ignorerulescheck_->set_sensitive(sens);
872 }
873
874
875 void GDocument::addBranch()
876 {
877         Gtk::ListStore::Row row = *branchliststore_->append();
878         (*row)[branchColName_] = "New Branch";
879         (*row)[branchColActivated_] = false;
880         (*row)[branchColColor_] = "#000000";
881 }
882
883
884 void GDocument::removeBranch()
885 {
886         Gtk::TreeModel::iterator const selected = branchsel_->get_selected();
887         if (!branchliststore_->iter_is_valid(selected))
888                 return;
889
890         branchliststore_->erase (selected);
891 }
892
893
894 void GDocument::branchSelChanged()
895 {
896         if (branchsel_->get_selected() == branchliststore_->children().end())
897                 removebranchbutton_->set_sensitive(false);
898         else
899                 removebranchbutton_->set_sensitive(true);
900 }
901
902 } // namespace frontend
903 } // namespace lyx