]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDocument.cpp
8ed57911933c87db545e7cb9d4b170b2cc65613c
[lyx.git] / src / frontends / qt4 / GuiDocument.cpp
1 /**
2  * \file GuiDocument.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  * \author Richard Heck (modules)
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiDocument.h"
15
16 #include "BranchList.h"
17 #include "buffer_funcs.h"
18 #include "Buffer.h"
19 #include "BufferParams.h"
20 #include "BufferView.h"
21 #include "Encoding.h"
22 #include "FloatPlacement.h"
23 #include "frontend_helpers.h"
24 #include "FuncRequest.h"
25 #include "gettext.h"
26 #include "GuiBranches.h"
27 #include "Language.h"
28 #include "LaTeXFeatures.h"
29 #include "LaTeXHighlighter.h"
30 #include "Layout.h"
31 #include "LengthCombo.h"
32 #include "LyXRC.h" // defaultUnit
33 #include "ModuleList.h"
34 #include "OutputParams.h"
35 #include "PanelStack.h"
36 #include "PDFOptions.h"
37 #include "qt_helpers.h"
38 #include "Spacing.h"
39 #include "TextClassList.h"
40 #include "Validator.h"
41
42
43 // FIXME: those two headers are needed because of the
44 // WorkArea::redraw() call below.
45 #include "frontends/LyXView.h"
46 #include "frontends/WorkArea.h"
47
48 #include "insets/InsetListingsParams.h"
49
50 #include "support/lstrings.h"
51
52 #include <boost/bind.hpp>
53
54 #include <QCloseEvent>
55 #include <QScrollBar>
56 #include <QTextCursor>
57
58 #include <algorithm>
59 #include <sstream>
60
61 using std::distance;
62 using std::make_pair;
63 using std::pair;
64 using std::vector;
65 using std::string;
66 using std::ostringstream;
67 using std::sort;
68
69 ///
70 template<class Pair>
71 std::vector<typename Pair::second_type> const
72 getSecond(std::vector<Pair> const & pr)
73 {
74          std::vector<typename Pair::second_type> tmp(pr.size());
75          std::transform(pr.begin(), pr.end(), tmp.begin(),
76                                          boost::bind(&Pair::second, _1));
77          return tmp;
78 }
79
80 char const * const tex_graphics[] =
81 {
82         "default", "dvips", "dvitops", "emtex",
83         "ln", "oztex", "textures", "none", ""
84 };
85
86
87 char const * const tex_graphics_gui[] =
88 {
89         N_("Default"), "Dvips", "DVItoPS", "EmTeX",
90         "LN", "OzTeX", "Textures", N_("None"), ""
91 };
92
93
94 char const * const tex_fonts_roman[] =
95 {
96         "default", "cmr", "lmodern", "ae", "times", "palatino",
97         "charter", "newcent", "bookman", "utopia", "beraserif",
98         "ccfonts", "chancery", ""
99 };
100
101
102 char const * tex_fonts_roman_gui[] =
103 {
104         N_("Default"), N_("Computer Modern Roman"), N_("Latin Modern Roman"),
105         N_("AE (Almost European)"), N_("Times Roman"), N_("Palatino"),
106         N_("Bitstream Charter"), N_("New Century Schoolbook"), N_("Bookman"),
107         N_("Utopia"),  N_("Bera Serif"), N_("Concrete Roman"), N_("Zapf Chancery"),
108         ""
109 };
110
111
112 char const * const tex_fonts_sans[] =
113 {
114         "default", "cmss", "lmss", "helvet", "avant", "berasans", "cmbr", ""
115 };
116
117
118 char const * tex_fonts_sans_gui[] =
119 {
120         N_("Default"), N_("Computer Modern Sans"), N_("Latin Modern Sans"),
121         N_("Helvetica"), N_("Avant Garde"), N_("Bera Sans"), N_("CM Bright"), ""
122 };
123
124
125 char const * const tex_fonts_monospaced[] =
126 {
127         "default", "cmtt", "lmtt", "courier", "beramono", "luximono", "cmtl", ""
128 };
129
130
131 char const * tex_fonts_monospaced_gui[] =
132 {
133         N_("Default"), N_("Computer Modern Typewriter"),
134         N_("Latin Modern Typewriter"), N_("Courier"), N_("Bera Mono"),
135         N_("LuxiMono"), N_("CM Typewriter Light"), ""
136 };
137
138
139 vector<pair<string, lyx::docstring> > pagestyles;
140
141
142 namespace lyx {
143 namespace frontend {
144
145 using support::token;
146 using support::bformat;
147 using support::findToken;
148 using support::getVectorFromString;
149
150 /////////////////////////////////////////////////////////////////////
151 //
152 // PreambleModule
153 //
154 /////////////////////////////////////////////////////////////////////
155
156 PreambleModule::PreambleModule(): current_id_(0)
157 {
158         // This is not a memory leak. The object will be destroyed
159         // with this.
160         (void) new LaTeXHighlighter(preambleTE->document());
161         setFocusProxy(preambleTE);
162         connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
163 }
164
165
166 void PreambleModule::update(BufferParams const & params, BufferId id)
167 {
168         QString preamble = toqstr(params.preamble);
169         // Nothing to do if the params and preamble are unchanged.
170         if (id == current_id_
171                 && preamble == preambleTE->document()->toPlainText())
172                 return;
173
174         QTextCursor cur = preambleTE->textCursor();
175         // Save the coords before switching to the new one.
176         preamble_coords_[current_id_] =
177                 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
178
179         // Save the params address for further use.
180         current_id_ = id;
181         preambleTE->document()->setPlainText(preamble);
182         Coords::const_iterator it = preamble_coords_.find(current_id_);
183         if (it == preamble_coords_.end())
184                 // First time we open this one.
185                 preamble_coords_[current_id_] = make_pair(0,0);
186         else {
187                 // Restore saved coords.
188                 QTextCursor cur = preambleTE->textCursor();
189                 cur.setPosition(it->second.first);
190                 preambleTE->setTextCursor(cur);
191                 preambleTE->verticalScrollBar()->setValue(it->second.second);
192         }
193 }
194
195
196 void PreambleModule::apply(BufferParams & params)
197 {
198         params.preamble = fromqstr(preambleTE->document()->toPlainText());
199 }
200
201
202 void PreambleModule::closeEvent(QCloseEvent * e)
203 {
204         // Save the coords before closing.
205         QTextCursor cur = preambleTE->textCursor();
206         preamble_coords_[current_id_] =
207                 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
208         e->accept();
209 }
210
211
212 /////////////////////////////////////////////////////////////////////
213 //
214 // DocumentDialog
215 //
216 /////////////////////////////////////////////////////////////////////
217
218
219
220 GuiDocument::GuiDocument(LyXView & lv)
221         : GuiDialog(lv, "document")
222 {
223         setupUi(this);
224         setViewTitle(_("Document Settings"));
225
226         lang_ = getSecond(getLanguageData(false));
227
228         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
229         connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
230         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
231         connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
232
233         connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
234         connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
235
236         // Manage the restore, ok, apply, restore and cancel/close buttons
237         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
238         bc().setOK(okPB);
239         bc().setApply(applyPB);
240         bc().setCancel(closePB);
241         bc().setRestore(restorePB);
242
243         textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
244         // text layout
245         connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
246                 this, SLOT(change_adaptor()));
247         connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
248                 this, SLOT(setLSpacing(int)));
249         connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)),
250                 this, SLOT(change_adaptor()));
251         connect(textLayoutModule->skipRB, SIGNAL(clicked()),
252                 this, SLOT(change_adaptor()));
253         connect(textLayoutModule->indentRB, SIGNAL(clicked()),
254                 this, SLOT(change_adaptor()));
255         connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
256                 this, SLOT(change_adaptor()));
257         connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
258                 this, SLOT(change_adaptor()));
259         connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
260                 this, SLOT(change_adaptor()));
261         connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
262                 this, SLOT(setSkip(int)));
263         connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
264                 this, SLOT(enableSkip(bool)));
265         connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
266                 this, SLOT(change_adaptor()));
267         connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
268                 this, SLOT(change_adaptor()));
269         connect(textLayoutModule->bypassCB, SIGNAL(clicked()), 
270                 this, SLOT(change_adaptor()));
271         connect(textLayoutModule->bypassCB, SIGNAL(clicked()), 
272                 this, SLOT(set_listings_msg()));
273         connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
274                 this, SLOT(set_listings_msg()));
275         textLayoutModule->listingsTB->setPlainText(
276                 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
277         textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
278                 textLayoutModule->lspacingLE));
279         textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
280                 textLayoutModule->skipLE));
281
282         textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
283         textLayoutModule->skipCO->addItem(qt_("MedSkip"));
284         textLayoutModule->skipCO->addItem(qt_("BigSkip"));
285         textLayoutModule->skipCO->addItem(qt_("Length"));
286         // remove the %-items from the unit choice
287         textLayoutModule->skipLengthCO->noPercents();
288         textLayoutModule->lspacingCO->insertItem(
289                 Spacing::Single, qt_("Single"));
290         textLayoutModule->lspacingCO->insertItem(
291                 Spacing::Onehalf, qt_("OneHalf"));
292         textLayoutModule->lspacingCO->insertItem(
293                 Spacing::Double, qt_("Double"));
294         textLayoutModule->lspacingCO->insertItem(
295                 Spacing::Other, qt_("Custom"));
296
297         // initialize the length validator
298         bc().addCheckedLineEdit(textLayoutModule->skipLE);
299
300         fontModule = new UiWidget<Ui::FontUi>;
301         // fonts
302         connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
303                 this, SLOT(change_adaptor()));
304         connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
305                 this, SLOT(romanChanged(int)));
306         connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
307                 this, SLOT(change_adaptor()));
308         connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
309                 this, SLOT(sansChanged(int)));
310         connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
311                 this, SLOT(change_adaptor()));
312         connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
313                 this, SLOT(ttChanged(int)));
314         connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
315                 this, SLOT(change_adaptor()));
316         connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
317                 this, SLOT(change_adaptor()));
318         connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
319                 this, SLOT(change_adaptor()));
320         connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
321                 this, SLOT(change_adaptor()));
322         connect(fontModule->fontScCB, SIGNAL(clicked()),
323                 this, SLOT(change_adaptor()));
324         connect(fontModule->fontOsfCB, SIGNAL(clicked()),
325                 this, SLOT(change_adaptor()));
326
327         for (int n = 0; tex_fonts_roman[n][0]; ++n) {
328                 QString font = qt_(tex_fonts_roman_gui[n]);
329                 if (!isFontAvailable(tex_fonts_roman[n]))
330                         font += qt_(" (not installed)");
331                 fontModule->fontsRomanCO->addItem(font);
332         }
333         for (int n = 0; tex_fonts_sans[n][0]; ++n) {
334                 QString font = qt_(tex_fonts_sans_gui[n]);
335                 if (!isFontAvailable(tex_fonts_sans[n]))
336                         font += qt_(" (not installed)");
337                 fontModule->fontsSansCO->addItem(font);
338         }
339         for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
340                 QString font = qt_(tex_fonts_monospaced_gui[n]);
341                 if (!isFontAvailable(tex_fonts_monospaced[n]))
342                         font += qt_(" (not installed)");
343                 fontModule->fontsTypewriterCO->addItem(font);
344         }
345
346         fontModule->fontsizeCO->addItem(qt_("Default"));
347         fontModule->fontsizeCO->addItem(qt_("10"));
348         fontModule->fontsizeCO->addItem(qt_("11"));
349         fontModule->fontsizeCO->addItem(qt_("12"));
350
351         for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
352                 fontModule->fontsDefaultCO->addItem(
353                         qt_(GuiDocument::fontfamilies_gui[n]));
354
355
356         pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
357         // page layout
358         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
359                 this, SLOT(setCustomPapersize(int)));
360         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
361                 this, SLOT(setCustomPapersize(int)));
362         connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
363                 this, SLOT(portraitChanged()));
364         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
365                 this, SLOT(change_adaptor()));
366         connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
367                 this, SLOT(change_adaptor()));
368         connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
369                 this, SLOT(change_adaptor()));
370         connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
371                 this, SLOT(change_adaptor()));
372         connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
373                 this, SLOT(change_adaptor()));
374         connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
375                 this, SLOT(change_adaptor()));
376         connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
377                 this, SLOT(change_adaptor()));
378         connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
379                 this, SLOT(change_adaptor()));
380         connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
381                 this, SLOT(change_adaptor()));
382
383         pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
384         pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
385         pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
386         pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
387         pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
388         bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
389                 pageLayoutModule->paperheightL);
390         bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
391                 pageLayoutModule->paperwidthL);
392
393         // paper
394         QComboBox * cb = pageLayoutModule->papersizeCO;
395         cb->addItem(qt_("Default"));
396         cb->addItem(qt_("Custom"));
397         cb->addItem(qt_("US letter"));
398         cb->addItem(qt_("US legal"));
399         cb->addItem(qt_("US executive"));
400         cb->addItem(qt_("A3"));
401         cb->addItem(qt_("A4"));
402         cb->addItem(qt_("A5"));
403         cb->addItem(qt_("B3"));
404         cb->addItem(qt_("B4"));
405         cb->addItem(qt_("B5"));
406         // remove the %-items from the unit choice
407         pageLayoutModule->paperwidthUnitCO->noPercents();
408         pageLayoutModule->paperheightUnitCO->noPercents();
409         pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
410                 pageLayoutModule->paperheightLE));
411         pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
412                 pageLayoutModule->paperwidthLE));
413
414
415         marginsModule = new UiWidget<Ui::MarginsUi>;
416         // margins
417         connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
418                 this, SLOT(setCustomMargins(bool)));
419         connect(marginsModule->marginCB, SIGNAL(clicked()),
420                 this, SLOT(change_adaptor()));
421         connect(marginsModule->topLE, SIGNAL(textChanged(const QString &)),
422                 this, SLOT(change_adaptor()));
423         connect(marginsModule->topUnit, SIGNAL(activated(int)),
424                 this, SLOT(change_adaptor()));
425         connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString &)),
426                 this, SLOT(change_adaptor()));
427         connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
428                 this, SLOT(change_adaptor()));
429         connect(marginsModule->innerLE, SIGNAL(textChanged(const QString &)),
430                 this, SLOT(change_adaptor()));
431         connect(marginsModule->innerUnit, SIGNAL(activated(int)),
432                 this, SLOT(change_adaptor()));
433         connect(marginsModule->outerLE, SIGNAL(textChanged(const QString &)),
434                 this, SLOT(change_adaptor()));
435         connect(marginsModule->outerUnit, SIGNAL(activated(int)),
436                 this, SLOT(change_adaptor()));
437         connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString &)),
438                 this, SLOT(change_adaptor()));
439         connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
440                 this, SLOT(change_adaptor()));
441         connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString &)),
442                 this, SLOT(change_adaptor()));
443         connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
444                 this, SLOT(change_adaptor()));
445         connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)),
446                 this, SLOT(change_adaptor()));
447         connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
448                 this, SLOT(change_adaptor()));
449         marginsModule->topLE->setValidator(unsignedLengthValidator(
450                 marginsModule->topLE));
451         marginsModule->bottomLE->setValidator(unsignedLengthValidator(
452                 marginsModule->bottomLE));
453         marginsModule->innerLE->setValidator(unsignedLengthValidator(
454                 marginsModule->innerLE));
455         marginsModule->outerLE->setValidator(unsignedLengthValidator(
456                 marginsModule->outerLE));
457         marginsModule->headsepLE->setValidator(unsignedLengthValidator(
458                 marginsModule->headsepLE));
459         marginsModule->headheightLE->setValidator(unsignedLengthValidator(
460                 marginsModule->headheightLE));
461         marginsModule->footskipLE->setValidator(unsignedLengthValidator(
462                 marginsModule->footskipLE));
463
464         bc().addCheckedLineEdit(marginsModule->topLE,
465                 marginsModule->topL);
466         bc().addCheckedLineEdit(marginsModule->bottomLE,
467                 marginsModule->bottomL);
468         bc().addCheckedLineEdit(marginsModule->innerLE,
469                 marginsModule->innerL);
470         bc().addCheckedLineEdit(marginsModule->outerLE,
471                 marginsModule->outerL);
472         bc().addCheckedLineEdit(marginsModule->headsepLE,
473                 marginsModule->headsepL);
474         bc().addCheckedLineEdit(marginsModule->headheightLE,
475                 marginsModule->headheightL);
476         bc().addCheckedLineEdit(marginsModule->footskipLE,
477                 marginsModule->footskipL);
478
479
480         langModule = new UiWidget<Ui::LanguageUi>;
481         // language & quote
482         connect(langModule->languageCO, SIGNAL(activated(int)),
483                 this, SLOT(change_adaptor()));
484         connect(langModule->defaultencodingRB, SIGNAL(clicked()),
485                 this, SLOT(change_adaptor()));
486         connect(langModule->otherencodingRB, SIGNAL(clicked()),
487                 this, SLOT(change_adaptor()));
488         connect(langModule->encodingCO, SIGNAL(activated(int)),
489                 this, SLOT(change_adaptor()));
490         connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
491                 this, SLOT(change_adaptor()));
492         // language & quotes
493         vector<LanguagePair> const langs = getLanguageData(false);
494         vector<LanguagePair>::const_iterator lit  = langs.begin();
495         vector<LanguagePair>::const_iterator lend = langs.end();
496         for (; lit != lend; ++lit) {
497                 langModule->languageCO->addItem(toqstr(lit->first));
498         }
499
500         // Always put the default encoding in the first position.
501         // It is special because the displayed text is translated.
502         langModule->encodingCO->addItem(qt_("LaTeX default"));
503         Encodings::const_iterator it = encodings.begin();
504         Encodings::const_iterator const end = encodings.end();
505         for (; it != end; ++it)
506                 langModule->encodingCO->addItem(toqstr(it->latexName()));
507
508         langModule->quoteStyleCO->addItem(qt_("``text''"));
509         langModule->quoteStyleCO->addItem(qt_("''text''"));
510         langModule->quoteStyleCO->addItem(qt_(",,text``"));
511         langModule->quoteStyleCO->addItem(qt_(",,text''"));
512         langModule->quoteStyleCO->addItem(qt_("<<text>>"));
513         langModule->quoteStyleCO->addItem(qt_(">>text<<"));
514
515
516
517         numberingModule = new UiWidget<Ui::NumberingUi>;
518         // numbering
519         connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
520                 this, SLOT(change_adaptor()));
521         connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
522                 this, SLOT(change_adaptor()));
523         connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
524                 this, SLOT(updateNumbering()));
525         connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
526                 this, SLOT(updateNumbering()));
527         numberingModule->tocTW->setColumnCount(3);
528         numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
529         numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
530         numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
531
532
533         biblioModule = new UiWidget<Ui::BiblioUi>;
534         connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
535                 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
536         connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
537                 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
538         // biblio
539         connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
540                 this, SLOT(change_adaptor()));
541         connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
542                 this, SLOT(change_adaptor()));
543         connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
544                 this, SLOT(change_adaptor()));
545         connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
546                 this, SLOT(change_adaptor()));
547         connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
548                 this, SLOT(change_adaptor()));
549         // biblio
550         biblioModule->citeStyleCO->addItem(qt_("Author-year"));
551         biblioModule->citeStyleCO->addItem(qt_("Numerical"));
552         biblioModule->citeStyleCO->setCurrentIndex(0);
553
554
555         mathsModule = new UiWidget<Ui::MathsUi>;
556         connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
557                 mathsModule->amsCB, SLOT(setDisabled(bool)));
558         connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
559                 mathsModule->esintCB, SLOT(setDisabled(bool)));
560         // maths
561         connect(mathsModule->amsCB, SIGNAL(clicked()),
562                 this, SLOT(change_adaptor()));
563         connect(mathsModule->amsautoCB, SIGNAL(clicked()),
564                 this, SLOT(change_adaptor()));
565         connect(mathsModule->esintCB, SIGNAL(clicked()),
566                 this, SLOT(change_adaptor()));
567         connect(mathsModule->esintautoCB, SIGNAL(clicked()),
568                 this, SLOT(change_adaptor()));
569
570         latexModule = new UiWidget<Ui::LaTeXUi>;
571         // latex class
572         connect(latexModule->classCO, SIGNAL(activated(int)),
573                 this, SLOT(change_adaptor()));
574         connect(latexModule->optionsLE, SIGNAL(textChanged(const QString &)),
575                 this, SLOT(change_adaptor()));
576         connect(latexModule->psdriverCO, SIGNAL(activated(int)),
577                 this, SLOT(change_adaptor()));
578         connect(latexModule->classCO, SIGNAL(activated(int)),
579                 this, SLOT(classChanged()));
580         
581         selectionManager = 
582                 new GuiSelectionManager(latexModule->availableLV, latexModule->selectedLV, 
583                         latexModule->addPB, latexModule->deletePB, 
584                         latexModule->upPB, latexModule->downPB, 
585                         availableModel(), selectedModel());
586         connect(selectionManager, SIGNAL(updateHook()),
587                 this, SLOT(updateModuleInfo()));
588         connect(selectionManager, SIGNAL(updateHook()),
589                 this, SLOT(change_adaptor()));
590         
591         // postscript drivers
592         for (int n = 0; tex_graphics[n][0]; ++n) {
593                 QString enc = qt_(tex_graphics_gui[n]);
594                 latexModule->psdriverCO->addItem(enc);
595         }
596         // latex classes
597         //FIXME This seems too involved with the kernel. Some of this
598         //should be moved to the kernel---which should perhaps just
599         //give us a list of entries or something of the sort.
600         for (TextClassList::const_iterator cit = textclasslist.begin();
601              cit != textclasslist.end(); ++cit) {
602                 if (cit->isTeXClassAvailable()) {
603                         latexModule->classCO->addItem(toqstr(cit->description()));
604                 } else {
605                         docstring item =
606                                 bformat(_("Unavailable: %1$s"), from_utf8(cit->description()));
607                         latexModule->classCO->addItem(toqstr(item));
608                 }
609         }
610
611         // branches
612         branchesModule = new GuiBranches;
613         connect(branchesModule, SIGNAL(changed()),
614                 this, SLOT(change_adaptor()));
615
616         // preamble
617         preambleModule = new PreambleModule;
618         connect(preambleModule, SIGNAL(changed()),
619                 this, SLOT(change_adaptor()));
620
621         // bullets
622         bulletsModule = new BulletsModule;
623         connect(bulletsModule, SIGNAL(changed()),
624                 this, SLOT(change_adaptor()));
625
626         // embedded files
627         embeddedFilesModule = new UiWidget<Ui::EmbeddedFilesUi>;
628         connect(embeddedFilesModule, SIGNAL(changed()),
629                 this, SLOT(change_adaptor()));
630         
631         connect(embeddedFilesModule->bundleCB, SIGNAL(toggled(bool)),
632                 this, SLOT(change_adaptor()));
633         connect(embeddedFilesModule->addPB, SIGNAL(clicked()),
634                 this, SLOT(change_adaptor()));
635         connect(embeddedFilesModule->removePB, SIGNAL(clicked()),
636                 this, SLOT(change_adaptor()));
637
638         // PDF support
639         pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
640
641         connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
642                 this, SLOT(change_adaptor()));
643         connect(pdfSupportModule->titleLE, SIGNAL(textChanged(const QString &)),
644                 this, SLOT(change_adaptor()));
645         connect(pdfSupportModule->authorLE, SIGNAL(textChanged(const QString &)),
646                 this, SLOT(change_adaptor()));
647         connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(const QString &)),
648                 this, SLOT(change_adaptor()));
649         connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(const QString &)),
650                 this, SLOT(change_adaptor()));
651         connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
652                 this, SLOT(change_adaptor()));
653         connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
654                 this, SLOT(change_adaptor()));
655         connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
656                 this, SLOT(change_adaptor()));
657         connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
658                 this, SLOT(change_adaptor()));
659         connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
660                 this, SLOT(change_adaptor()));
661         connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
662                 this, SLOT(change_adaptor()));
663         connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
664                 this, SLOT(change_adaptor()));
665         connect(pdfSupportModule->backrefCB, SIGNAL(toggled(bool)),
666                 this, SLOT(change_adaptor()));
667         connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
668                 this, SLOT(change_adaptor()));
669         connect(pdfSupportModule->pagebackrefCB, SIGNAL(toggled(bool)),
670                 this, SLOT(change_adaptor()));
671         connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
672                 this, SLOT(change_adaptor()));
673         connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(const QString &)),
674                 this, SLOT(change_adaptor()));
675
676         // float
677         floatModule = new FloatPlacement;
678         connect(floatModule, SIGNAL(changed()),
679                 this, SLOT(change_adaptor()));
680
681         docPS->addPanel(latexModule, _("Document Class"));
682         docPS->addPanel(fontModule, _("Fonts"));
683         docPS->addPanel(textLayoutModule, _("Text Layout"));
684         docPS->addPanel(pageLayoutModule, _("Page Layout"));
685         docPS->addPanel(marginsModule, _("Page Margins"));
686         docPS->addPanel(langModule, _("Language"));
687         docPS->addPanel(numberingModule, _("Numbering & TOC"));
688         docPS->addPanel(biblioModule, _("Bibliography"));
689         docPS->addPanel(pdfSupportModule, _("PDF Properties"));
690         docPS->addPanel(mathsModule, _("Math Options"));
691         docPS->addPanel(floatModule, _("Float Placement"));
692         docPS->addPanel(bulletsModule, _("Bullets"));
693         docPS->addPanel(branchesModule, _("Branches"));
694         docPS->addPanel(embeddedFilesModule, _("Embedded Files"));
695         docPS->addPanel(preambleModule, _("LaTeX Preamble"));
696         docPS->setCurrentPanel(_("Document Class"));
697 // FIXME: hack to work around resizing bug in Qt >= 4.2
698 // bug verified with Qt 4.2.{0-3} (JSpitzm)
699 #if QT_VERSION >= 0x040200
700         docPS->updateGeometry();
701 #endif
702 }
703
704
705 void GuiDocument::showPreamble()
706 {
707         docPS->setCurrentPanel(_("LaTeX Preamble"));
708 }
709
710
711 void GuiDocument::saveDefaultClicked()
712 {
713         saveDocDefault();
714 }
715
716
717 void GuiDocument::useDefaultsClicked()
718 {
719         useClassDefaults();
720 }
721
722
723 void GuiDocument::change_adaptor()
724 {
725         changed();
726 }
727
728
729 docstring GuiDocument::validate_listings_params()
730 {
731         // use a cache here to avoid repeated validation
732         // of the same parameters
733         static string param_cache = string();
734         static docstring msg_cache = docstring();
735         
736         if (textLayoutModule->bypassCB->isChecked())
737                 return docstring();
738
739         string params = fromqstr(textLayoutModule->listingsED->toPlainText());
740         if (params != param_cache) {
741                 param_cache = params;
742                 msg_cache = InsetListingsParams(params).validate();
743         }
744         return msg_cache;
745 }
746
747
748 void GuiDocument::set_listings_msg()
749 {
750         static bool isOK = true;
751         docstring msg = validate_listings_params();
752         if (msg.empty()) {
753                 if (isOK)
754                         return;
755                 isOK = true;
756                 // listingsTB->setTextColor("black");
757                 textLayoutModule->listingsTB->setPlainText(
758                         qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
759         } else {
760                 isOK = false;
761                 // listingsTB->setTextColor("red");
762                 textLayoutModule->listingsTB->setPlainText(toqstr(msg));
763         }
764 }
765
766
767 void GuiDocument::closeEvent(QCloseEvent * e)
768 {
769         slotClose();
770         e->accept();
771 }
772
773
774 void GuiDocument::setLSpacing(int item)
775 {
776         textLayoutModule->lspacingLE->setEnabled(item == 3);
777 }
778
779
780 void GuiDocument::setSkip(int item)
781 {
782         bool const enable = (item == 3);
783         textLayoutModule->skipLE->setEnabled(enable);
784         textLayoutModule->skipLengthCO->setEnabled(enable);
785 }
786
787
788 void GuiDocument::enableSkip(bool skip)
789 {
790         textLayoutModule->skipCO->setEnabled(skip);
791         textLayoutModule->skipLE->setEnabled(skip);
792         textLayoutModule->skipLengthCO->setEnabled(skip);
793         if (skip)
794                 setSkip(textLayoutModule->skipCO->currentIndex());
795 }
796
797 void GuiDocument::portraitChanged()
798 {
799         setMargins(pageLayoutModule->papersizeCO->currentIndex());
800 }
801
802 void GuiDocument::setMargins(bool custom)
803 {
804         marginsModule->marginCB->setChecked(custom);
805         setCustomMargins(custom);
806 }
807
808
809 void GuiDocument::setCustomPapersize(int papersize)
810 {
811         bool const custom = (papersize == 1);
812
813         pageLayoutModule->paperwidthL->setEnabled(custom);
814         pageLayoutModule->paperwidthLE->setEnabled(custom);
815         pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
816         pageLayoutModule->paperheightL->setEnabled(custom);
817         pageLayoutModule->paperheightLE->setEnabled(custom);
818         pageLayoutModule->paperheightLE->setFocus();
819         pageLayoutModule->paperheightUnitCO->setEnabled(custom);
820 }
821
822
823 void GuiDocument::setCustomMargins(bool custom)
824 {
825         marginsModule->topL->setEnabled(!custom);
826         marginsModule->topLE->setEnabled(!custom);
827         marginsModule->topUnit->setEnabled(!custom);
828
829         marginsModule->bottomL->setEnabled(!custom);
830         marginsModule->bottomLE->setEnabled(!custom);
831         marginsModule->bottomUnit->setEnabled(!custom);
832
833         marginsModule->innerL->setEnabled(!custom);
834         marginsModule->innerLE->setEnabled(!custom);
835         marginsModule->innerUnit->setEnabled(!custom);
836
837         marginsModule->outerL->setEnabled(!custom);
838         marginsModule->outerLE->setEnabled(!custom);
839         marginsModule->outerUnit->setEnabled(!custom);
840
841         marginsModule->headheightL->setEnabled(!custom);
842         marginsModule->headheightLE->setEnabled(!custom);
843         marginsModule->headheightUnit->setEnabled(!custom);
844
845         marginsModule->headsepL->setEnabled(!custom);
846         marginsModule->headsepLE->setEnabled(!custom);
847         marginsModule->headsepUnit->setEnabled(!custom);
848
849         marginsModule->footskipL->setEnabled(!custom);
850         marginsModule->footskipLE->setEnabled(!custom);
851         marginsModule->footskipUnit->setEnabled(!custom);
852 }
853
854
855 void GuiDocument::updateFontsize(string const & items, string const & sel)
856 {
857         fontModule->fontsizeCO->clear();
858         fontModule->fontsizeCO->addItem(qt_("Default"));
859
860         for (int n = 0; !token(items,'|',n).empty(); ++n)
861                 fontModule->fontsizeCO->
862                         addItem(toqstr(token(items,'|',n)));
863
864         for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
865                 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
866                         fontModule->fontsizeCO->setCurrentIndex(n);
867                         break;
868                 }
869         }
870 }
871
872
873 void GuiDocument::romanChanged(int item)
874 {
875         string const font = tex_fonts_roman[item];
876         fontModule->fontScCB->setEnabled(providesSC(font));
877         fontModule->fontOsfCB->setEnabled(providesOSF(font));
878 }
879
880
881 void GuiDocument::sansChanged(int item)
882 {
883         string const font = tex_fonts_sans[item];
884         bool scaleable = providesScale(font);
885         fontModule->scaleSansSB->setEnabled(scaleable);
886         fontModule->scaleSansLA->setEnabled(scaleable);
887 }
888
889
890 void GuiDocument::ttChanged(int item)
891 {
892         string const font = tex_fonts_monospaced[item];
893         bool scaleable = providesScale(font);
894         fontModule->scaleTypewriterSB->setEnabled(scaleable);
895         fontModule->scaleTypewriterLA->setEnabled(scaleable);
896 }
897
898
899 void GuiDocument::updatePagestyle(string const & items, string const & sel)
900 {
901         pagestyles.clear();
902         pageLayoutModule->pagestyleCO->clear();
903         pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
904
905         for (int n = 0; !token(items,'|',n).empty(); ++n) {
906                 string style = token(items, '|', n);
907                 docstring style_gui = _(style);
908                 pagestyles.push_back(pair<string, docstring>(style, style_gui));
909                 pageLayoutModule->pagestyleCO->addItem(toqstr(style_gui));
910         }
911
912         if (sel == "default") {
913                 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
914                 return;
915         }
916
917         int nn = 0;
918
919         for (size_t i = 0; i < pagestyles.size(); ++i)
920                 if (pagestyles[i].first == sel)
921                         nn = pageLayoutModule->pagestyleCO->findText(
922                                         toqstr(pagestyles[i].second));
923
924         if (nn > 0)
925                 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
926 }
927
928
929 void GuiDocument::classChanged()
930 {
931         textclass_type const tc = latexModule->classCO->currentIndex();
932         bp_.setJustBaseClass(tc);
933         if (lyxrc.auto_reset_options)
934                 bp_.useClassDefaults();
935         updateContents();
936 }
937
938
939 void GuiDocument::updateModuleInfo()
940 {
941         selectionManager->update();
942         //Module description
943         QListView const * const lv = selectionManager->selectedFocused() ?
944                                      latexModule->selectedLV :
945                         latexModule->availableLV;
946         if (lv->selectionModel()->selectedIndexes().isEmpty())
947                 latexModule->infoML->document()->clear();
948         else {
949                 QModelIndex const idx = lv->selectionModel()->currentIndex();
950                 string const modName = fromqstr(idx.data().toString());
951                 string desc = getModuleDescription(modName);
952                 vector<string> pkgList = getPackageList(modName);
953                 string pkgdesc;
954                 //this mess formats the package list as "pkg1, pkg2, and pkg3"
955                 int const pkgListSize = pkgList.size();
956                 for (int i = 0; i < pkgListSize; ++i) {
957                         if (i == 1) {
958                                 if (i == pkgListSize - 1) //last element
959                                         pkgdesc += " and ";
960                                 else
961                                         pkgdesc += ", ";
962                         } else if (i > 1) {
963                                 if (i == pkgListSize - 1) //last element
964                                         pkgdesc += ", and ";
965                                 else
966                                         pkgdesc += ", ";
967                         }
968                         pkgdesc += pkgList[i];
969                 }
970                 if (!pkgdesc.empty())
971                         desc += " Requires " + pkgdesc + ".";
972                 latexModule->infoML->document()->setPlainText(toqstr(desc));
973         }
974 }
975
976
977 void GuiDocument::updateNumbering()
978 {
979         TextClass const & tclass = bp_.getTextClass();
980
981         numberingModule->tocTW->setUpdatesEnabled(false);
982         numberingModule->tocTW->clear();
983
984         int const depth = numberingModule->depthSL->value();
985         int const toc = numberingModule->tocSL->value();
986         QString const no = qt_("No");
987         QString const yes = qt_("Yes");
988         TextClass::const_iterator end = tclass.end();
989         TextClass::const_iterator cit = tclass.begin();
990         QTreeWidgetItem * item = 0;
991         for ( ; cit != end ; ++cit) {
992                 int const toclevel = (*cit)->toclevel;
993                 if (toclevel != Layout::NOT_IN_TOC
994                     && (*cit)->labeltype == LABEL_COUNTER) {
995                         item = new QTreeWidgetItem(numberingModule->tocTW);
996                         item->setText(0, toqstr(translateIfPossible((*cit)->name())));
997                         item->setText(1, (toclevel <= depth) ? yes : no);
998                         item->setText(2, (toclevel <= toc) ? yes : no);
999                 }
1000         }
1001
1002         numberingModule->tocTW->setUpdatesEnabled(true);
1003         numberingModule->tocTW->update();
1004 }
1005
1006
1007 void GuiDocument::apply(BufferParams & params)
1008 {
1009         // preamble
1010         preambleModule->apply(params);
1011
1012         // biblio
1013         params.setCiteEngine(biblio::ENGINE_BASIC);
1014
1015         if (biblioModule->citeNatbibRB->isChecked()) {
1016                 bool const use_numerical_citations =
1017                         biblioModule->citeStyleCO->currentIndex();
1018                 if (use_numerical_citations)
1019                         params.setCiteEngine(biblio::ENGINE_NATBIB_NUMERICAL);
1020                 else
1021                         params.setCiteEngine(biblio::ENGINE_NATBIB_AUTHORYEAR);
1022
1023         } else if (biblioModule->citeJurabibRB->isChecked())
1024                 params.setCiteEngine(biblio::ENGINE_JURABIB);
1025
1026         params.use_bibtopic =
1027                 biblioModule->bibtopicCB->isChecked();
1028
1029         // language & quotes
1030         if (langModule->defaultencodingRB->isChecked()) {
1031                 params.inputenc = "auto";
1032         } else {
1033                 int i = langModule->encodingCO->currentIndex();
1034                 if (i == 0)
1035                         params.inputenc = "default";
1036                 else
1037                         params.inputenc =
1038                                 fromqstr(langModule->encodingCO->currentText());
1039         }
1040
1041         InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
1042         switch (langModule->quoteStyleCO->currentIndex()) {
1043         case 0:
1044                 lga = InsetQuotes::EnglishQ;
1045                 break;
1046         case 1:
1047                 lga = InsetQuotes::SwedishQ;
1048                 break;
1049         case 2:
1050                 lga = InsetQuotes::GermanQ;
1051                 break;
1052         case 3:
1053                 lga = InsetQuotes::PolishQ;
1054                 break;
1055         case 4:
1056                 lga = InsetQuotes::FrenchQ;
1057                 break;
1058         case 5:
1059                 lga = InsetQuotes::DanishQ;
1060                 break;
1061         }
1062         params.quotes_language = lga;
1063
1064         int const pos = langModule->languageCO->currentIndex();
1065         params.language = lyx::languages.getLanguage(lang_[pos]);
1066
1067         // numbering
1068         if (params.getTextClass().hasTocLevels()) {
1069                 params.tocdepth = numberingModule->tocSL->value();
1070                 params.secnumdepth = numberingModule->depthSL->value();
1071         }
1072
1073         // bullets
1074         params.user_defined_bullet(0) = bulletsModule->getBullet(0);
1075         params.user_defined_bullet(1) = bulletsModule->getBullet(1);
1076         params.user_defined_bullet(2) = bulletsModule->getBullet(2);
1077         params.user_defined_bullet(3) = bulletsModule->getBullet(3);
1078
1079         // packages
1080         params.graphicsDriver =
1081                 tex_graphics[latexModule->psdriverCO->currentIndex()];
1082         
1083         // Modules
1084         params.clearLayoutModules();
1085         QStringList const selMods = selectedModel()->stringList();
1086         for (int i = 0; i != selMods.size(); ++i)
1087                 params.addLayoutModule(lyx::fromqstr(selMods[i]));
1088
1089
1090         if (mathsModule->amsautoCB->isChecked()) {
1091                 params.use_amsmath = BufferParams::package_auto;
1092         } else {
1093                 if (mathsModule->amsCB->isChecked())
1094                         params.use_amsmath = BufferParams::package_on;
1095                 else
1096                         params.use_amsmath = BufferParams::package_off;
1097         }
1098
1099         if (mathsModule->esintautoCB->isChecked())
1100                 params.use_esint = BufferParams::package_auto;
1101         else {
1102                 if (mathsModule->esintCB->isChecked())
1103                         params.use_esint = BufferParams::package_on;
1104                 else
1105                         params.use_esint = BufferParams::package_off;
1106         }
1107
1108         // text layout
1109         params.setJustBaseClass(latexModule->classCO->currentIndex());
1110
1111         if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
1112                 params.pagestyle = "default";
1113         else {
1114                 docstring style_gui =
1115                         qstring_to_ucs4(pageLayoutModule->pagestyleCO->currentText());
1116                 for (size_t i = 0; i < pagestyles.size(); ++i)
1117                         if (pagestyles[i].second == style_gui)
1118                                 params.pagestyle = pagestyles[i].first;
1119         }
1120
1121         switch (textLayoutModule->lspacingCO->currentIndex()) {
1122         case 0:
1123                 params.spacing().set(Spacing::Single);
1124                 break;
1125         case 1:
1126                 params.spacing().set(Spacing::Onehalf);
1127                 break;
1128         case 2:
1129                 params.spacing().set(Spacing::Double);
1130                 break;
1131         case 3:
1132                 params.spacing().set(Spacing::Other,
1133                         fromqstr(textLayoutModule->lspacingLE->text()));
1134                 break;
1135         }
1136
1137         if (textLayoutModule->twoColumnCB->isChecked())
1138                 params.columns = 2;
1139         else
1140                 params.columns = 1;
1141
1142         // text should have passed validation
1143         params.listings_params =
1144                 InsetListingsParams(fromqstr(textLayoutModule->listingsED->toPlainText())).params();
1145
1146         if (textLayoutModule->indentRB->isChecked())
1147                 params.paragraph_separation = BufferParams::PARSEP_INDENT;
1148         else
1149                 params.paragraph_separation = BufferParams::PARSEP_SKIP;
1150
1151         switch (textLayoutModule->skipCO->currentIndex()) {
1152         case 0:
1153                 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
1154                 break;
1155         case 1:
1156                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1157                 break;
1158         case 2:
1159                 params.setDefSkip(VSpace(VSpace::BIGSKIP));
1160                 break;
1161         case 3:
1162         {
1163                 VSpace vs = VSpace(
1164                         widgetsToLength(textLayoutModule->skipLE,
1165                                 textLayoutModule->skipLengthCO)
1166                         );
1167                 params.setDefSkip(vs);
1168                 break;
1169         }
1170         default:
1171                 // DocumentDefskipCB assures that this never happens
1172                 // so Assert then !!!  - jbl
1173                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1174                 break;
1175         }
1176
1177         params.options =
1178                 fromqstr(latexModule->optionsLE->text());
1179
1180         params.float_placement = floatModule->get();
1181
1182         // fonts
1183         params.fontsRoman =
1184                 tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
1185
1186         params.fontsSans =
1187                 tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
1188
1189         params.fontsTypewriter =
1190                 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
1191
1192         params.fontsSansScale = fontModule->scaleSansSB->value();
1193
1194         params.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
1195
1196         params.fontsSC = fontModule->fontScCB->isChecked();
1197
1198         params.fontsOSF = fontModule->fontOsfCB->isChecked();
1199
1200         params.fontsDefaultFamily = GuiDocument::fontfamilies[
1201                 fontModule->fontsDefaultCO->currentIndex()];
1202
1203         if (fontModule->fontsizeCO->currentIndex() == 0)
1204                 params.fontsize = "default";
1205         else
1206                 params.fontsize =
1207                         fromqstr(fontModule->fontsizeCO->currentText());
1208
1209         // paper
1210         params.papersize = PAPER_SIZE(
1211                 pageLayoutModule->papersizeCO->currentIndex());
1212
1213         // custom, A3, B3 and B4 paper sizes need geometry
1214         int psize = pageLayoutModule->papersizeCO->currentIndex();
1215         bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
1216
1217         params.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
1218                 pageLayoutModule->paperwidthUnitCO);
1219
1220         params.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
1221                 pageLayoutModule->paperheightUnitCO);
1222
1223         if (pageLayoutModule->facingPagesCB->isChecked())
1224                 params.sides = TextClass::TwoSides;
1225         else
1226                 params.sides = TextClass::OneSide;
1227
1228         if (pageLayoutModule->landscapeRB->isChecked())
1229                 params.orientation = ORIENTATION_LANDSCAPE;
1230         else
1231                 params.orientation = ORIENTATION_PORTRAIT;
1232
1233         // margins
1234         params.use_geometry =
1235                 (!marginsModule->marginCB->isChecked()
1236                 || geom_papersize);
1237
1238         Ui::MarginsUi const * m(marginsModule);
1239
1240         params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
1241         params.topmargin = widgetsToLength(m->topLE, m->topUnit);
1242         params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
1243         params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
1244         params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
1245         params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
1246         params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
1247
1248         branchesModule->apply(params);
1249
1250         // PDF support
1251         PDFOptions & pdf = params.pdfoptions();
1252         pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
1253         pdf.title = fromqstr(pdfSupportModule->titleLE->text());
1254         pdf.author = fromqstr(pdfSupportModule->authorLE->text());
1255         pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
1256         pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
1257
1258         pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
1259         pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
1260         pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
1261         pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
1262
1263         pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
1264         pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
1265         pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
1266         pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
1267         pdf.backref = pdfSupportModule->backrefCB->isChecked();
1268         pdf.pagebackref = pdfSupportModule->pagebackrefCB->isChecked();
1269         if (pdfSupportModule->fullscreenCB->isChecked())
1270                 pdf.pagemode = pdf.pagemode_fullscreen;
1271         else
1272                 pdf.pagemode.clear();
1273         pdf.quoted_options = fromqstr(pdfSupportModule->optionsLE->text());
1274
1275         // Embedded files
1276         // FIXME
1277 }
1278
1279
1280 /** Return the position of val in the vector if found.
1281     If not found, return 0.
1282  */
1283 template<class A>
1284 static size_t findPos(std::vector<A> const & vec, A const & val)
1285 {
1286         typename std::vector<A>::const_iterator it =
1287                 std::find(vec.begin(), vec.end(), val);
1288         if (it == vec.end())
1289                 return 0;
1290         return distance(vec.begin(), it);
1291 }
1292
1293
1294 void GuiDocument::updateParams()
1295 {
1296         updateParams(bp_);
1297 }
1298
1299
1300 void GuiDocument::updateParams(BufferParams const & params)
1301 {
1302         // set the default unit
1303         Length::UNIT defaultUnit = Length::CM;
1304         switch (lyxrc.default_papersize) {
1305                 case PAPER_DEFAULT: break;
1306
1307                 case PAPER_USLETTER:
1308                 case PAPER_USLEGAL:
1309                 case PAPER_USEXECUTIVE:
1310                         defaultUnit = Length::IN;
1311                         break;
1312
1313                 case PAPER_A3:
1314                 case PAPER_A4:
1315                 case PAPER_A5:
1316                 case PAPER_B3:
1317                 case PAPER_B4:
1318                 case PAPER_B5:
1319                         defaultUnit = Length::CM;
1320                         break;
1321                 case PAPER_CUSTOM:
1322                         break;
1323         }
1324
1325         // preamble
1326         preambleModule->update(params, id());
1327
1328         // biblio
1329         biblioModule->citeDefaultRB->setChecked(
1330                 params.getEngine() == biblio::ENGINE_BASIC);
1331
1332         biblioModule->citeNatbibRB->setChecked(
1333                 params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL ||
1334                 params.getEngine() == biblio::ENGINE_NATBIB_AUTHORYEAR);
1335
1336         biblioModule->citeStyleCO->setCurrentIndex(
1337                 params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL);
1338
1339         biblioModule->citeJurabibRB->setChecked(
1340                 params.getEngine() == biblio::ENGINE_JURABIB);
1341
1342         biblioModule->bibtopicCB->setChecked(
1343                 params.use_bibtopic);
1344
1345         // language & quotes
1346         int const pos = int(findPos(lang_,
1347                                     params.language->lang()));
1348         langModule->languageCO->setCurrentIndex(pos);
1349
1350         langModule->quoteStyleCO->setCurrentIndex(
1351                 params.quotes_language);
1352
1353         bool default_enc = true;
1354         if (params.inputenc != "auto") {
1355                 default_enc = false;
1356                 if (params.inputenc == "default") {
1357                         langModule->encodingCO->setCurrentIndex(0);
1358                 } else {
1359                         int const i = langModule->encodingCO->findText(
1360                                         toqstr(params.inputenc));
1361                         if (i >= 0)
1362                                 langModule->encodingCO->setCurrentIndex(i);
1363                         else
1364                                 // unknown encoding. Set to default.
1365                                 default_enc = true;
1366                 }
1367         }
1368         langModule->defaultencodingRB->setChecked(default_enc);
1369         langModule->otherencodingRB->setChecked(!default_enc);
1370
1371         // numbering
1372         int const min_toclevel = textClass().min_toclevel();
1373         int const max_toclevel = textClass().max_toclevel();
1374         if (textClass().hasTocLevels()) {
1375                 numberingModule->setEnabled(true);
1376                 numberingModule->depthSL->setMinimum(min_toclevel - 1);
1377                 numberingModule->depthSL->setMaximum(max_toclevel);
1378                 numberingModule->depthSL->setValue(params.secnumdepth);
1379                 numberingModule->tocSL->setMaximum(min_toclevel - 1);
1380                 numberingModule->tocSL->setMaximum(max_toclevel);
1381                 numberingModule->tocSL->setValue(params.tocdepth);
1382                 updateNumbering();
1383         } else {
1384                 numberingModule->setEnabled(false);
1385                 numberingModule->tocTW->clear();
1386         }
1387
1388         // bullets
1389         bulletsModule->setBullet(0, params.user_defined_bullet(0));
1390         bulletsModule->setBullet(1, params.user_defined_bullet(1));
1391         bulletsModule->setBullet(2, params.user_defined_bullet(2));
1392         bulletsModule->setBullet(3, params.user_defined_bullet(3));
1393         bulletsModule->init();
1394
1395         // packages
1396         int nitem = findToken(tex_graphics, params.graphicsDriver);
1397         if (nitem >= 0)
1398                 latexModule->psdriverCO->setCurrentIndex(nitem);
1399         updateModuleInfo();
1400         
1401         mathsModule->amsCB->setChecked(
1402                 params.use_amsmath == BufferParams::package_on);
1403         mathsModule->amsautoCB->setChecked(
1404                 params.use_amsmath == BufferParams::package_auto);
1405
1406         mathsModule->esintCB->setChecked(
1407                 params.use_esint == BufferParams::package_on);
1408         mathsModule->esintautoCB->setChecked(
1409                 params.use_esint == BufferParams::package_auto);
1410
1411         switch (params.spacing().getSpace()) {
1412                 case Spacing::Other: nitem = 3; break;
1413                 case Spacing::Double: nitem = 2; break;
1414                 case Spacing::Onehalf: nitem = 1; break;
1415                 case Spacing::Default: case Spacing::Single: nitem = 0; break;
1416         }
1417
1418         // text layout
1419         latexModule->classCO->setCurrentIndex(params.getBaseClass());
1420         
1421         updatePagestyle(textClass().opt_pagestyle(),
1422                                  params.pagestyle);
1423
1424         textLayoutModule->lspacingCO->setCurrentIndex(nitem);
1425         if (params.spacing().getSpace() == Spacing::Other) {
1426                 textLayoutModule->lspacingLE->setText(
1427                         toqstr(params.spacing().getValueAsString()));
1428         }
1429         setLSpacing(nitem);
1430
1431         if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
1432                 textLayoutModule->indentRB->setChecked(true);
1433         else
1434                 textLayoutModule->skipRB->setChecked(true);
1435
1436         int skip = 0;
1437         switch (params.getDefSkip().kind()) {
1438         case VSpace::SMALLSKIP:
1439                 skip = 0;
1440                 break;
1441         case VSpace::MEDSKIP:
1442                 skip = 1;
1443                 break;
1444         case VSpace::BIGSKIP:
1445                 skip = 2;
1446                 break;
1447         case VSpace::LENGTH:
1448         {
1449                 skip = 3;
1450                 string const length = params.getDefSkip().asLyXCommand();
1451                 lengthToWidgets(textLayoutModule->skipLE,
1452                         textLayoutModule->skipLengthCO,
1453                         length, defaultUnit);
1454                 break;
1455         }
1456         default:
1457                 skip = 0;
1458                 break;
1459         }
1460         textLayoutModule->skipCO->setCurrentIndex(skip);
1461         setSkip(skip);
1462
1463         textLayoutModule->twoColumnCB->setChecked(
1464                 params.columns == 2);
1465
1466         // break listings_params to multiple lines
1467         string lstparams =
1468                 InsetListingsParams(params.listings_params).separatedParams();
1469         textLayoutModule->listingsED->setPlainText(toqstr(lstparams));
1470
1471         if (!params.options.empty()) {
1472                 latexModule->optionsLE->setText(
1473                         toqstr(params.options));
1474         } else {
1475                 latexModule->optionsLE->setText(QString());
1476         }
1477
1478         floatModule->set(params.float_placement);
1479
1480         // Fonts
1481         updateFontsize(textClass().opt_fontsize(),
1482                         params.fontsize);
1483
1484         int n = findToken(tex_fonts_roman, params.fontsRoman);
1485         if (n >= 0) {
1486                 fontModule->fontsRomanCO->setCurrentIndex(n);
1487                 romanChanged(n);
1488         }
1489
1490         n = findToken(tex_fonts_sans, params.fontsSans);
1491         if (n >= 0)     {
1492                 fontModule->fontsSansCO->setCurrentIndex(n);
1493                 sansChanged(n);
1494         }
1495
1496         n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
1497         if (n >= 0) {
1498                 fontModule->fontsTypewriterCO->setCurrentIndex(n);
1499                 ttChanged(n);
1500         }
1501
1502         fontModule->fontScCB->setChecked(params.fontsSC);
1503         fontModule->fontOsfCB->setChecked(params.fontsOSF);
1504         fontModule->scaleSansSB->setValue(params.fontsSansScale);
1505         fontModule->scaleTypewriterSB->setValue(params.fontsTypewriterScale);
1506         n = findToken(GuiDocument::fontfamilies, params.fontsDefaultFamily);
1507         if (n >= 0)
1508                 fontModule->fontsDefaultCO->setCurrentIndex(n);
1509
1510         // paper
1511         int const psize = params.papersize;
1512         pageLayoutModule->papersizeCO->setCurrentIndex(psize);
1513         setCustomPapersize(psize);
1514
1515         bool const landscape =
1516                 params.orientation == ORIENTATION_LANDSCAPE;
1517         pageLayoutModule->landscapeRB->setChecked(landscape);
1518         pageLayoutModule->portraitRB->setChecked(!landscape);
1519
1520         pageLayoutModule->facingPagesCB->setChecked(
1521                 params.sides == TextClass::TwoSides);
1522
1523
1524         lengthToWidgets(pageLayoutModule->paperwidthLE,
1525                 pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
1526
1527         lengthToWidgets(pageLayoutModule->paperheightLE,
1528                 pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
1529
1530         // margins
1531         Ui::MarginsUi * m = marginsModule;
1532
1533         setMargins(!params.use_geometry);
1534
1535         lengthToWidgets(m->topLE, m->topUnit,
1536                 params.topmargin, defaultUnit);
1537
1538         lengthToWidgets(m->bottomLE, m->bottomUnit,
1539                 params.bottommargin, defaultUnit);
1540
1541         lengthToWidgets(m->innerLE, m->innerUnit,
1542                 params.leftmargin, defaultUnit);
1543
1544         lengthToWidgets(m->outerLE, m->outerUnit,
1545                 params.rightmargin, defaultUnit);
1546
1547         lengthToWidgets(m->headheightLE, m->headheightUnit,
1548                 params.headheight, defaultUnit);
1549
1550         lengthToWidgets(m->headsepLE, m->headsepUnit,
1551                 params.headsep, defaultUnit);
1552
1553         lengthToWidgets(m->footskipLE, m->footskipUnit,
1554                 params.footskip, defaultUnit);
1555
1556         branchesModule->update(params);
1557
1558         // PDF support
1559         PDFOptions const & pdf = params.pdfoptions();
1560         pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
1561         pdfSupportModule->titleLE->setText(toqstr(pdf.title));
1562         pdfSupportModule->authorLE->setText(toqstr(pdf.author));
1563         pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
1564         pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
1565
1566         pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
1567         pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
1568         pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
1569
1570         pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
1571
1572         pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
1573         pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
1574         pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
1575         pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
1576         pdfSupportModule->backrefCB->setChecked(pdf.backref);
1577         pdfSupportModule->pagebackrefCB->setChecked(pdf.pagebackref);
1578         pdfSupportModule->fullscreenCB->setChecked
1579                 (pdf.pagemode == pdf.pagemode_fullscreen);
1580
1581         pdfSupportModule->optionsLE->setText(
1582                 toqstr(pdf.quoted_options));
1583 }
1584
1585
1586 void GuiDocument::applyView()
1587 {
1588         apply(params());
1589 }
1590
1591
1592 void GuiDocument::saveDocDefault()
1593 {
1594         // we have to apply the params first
1595         applyView();
1596         saveAsDefault();
1597 }
1598
1599
1600 void GuiDocument::updateContents()
1601 {
1602         //update list of available modules
1603         QStringList strlist;
1604         vector<string> const modNames = getModuleNames();
1605         vector<string>::const_iterator it = modNames.begin();
1606         for (; it != modNames.end(); ++it)
1607                 strlist.push_back(toqstr(*it));
1608         available_model_.setStringList(strlist);
1609         //and selected ones, too
1610         QStringList strlist2;
1611         vector<string> const & selMods = getSelectedModules();
1612         it = selMods.begin();
1613         for (; it != selMods.end(); ++it)
1614                 strlist2.push_back(toqstr(*it));
1615         selected_model_.setStringList(strlist2);
1616
1617         updateParams(bp_);
1618 }
1619
1620 void GuiDocument::useClassDefaults()
1621 {
1622         bp_.setJustBaseClass(latexModule->classCO->currentIndex());
1623         bp_.useClassDefaults();
1624         updateContents();
1625 }
1626
1627
1628 bool GuiDocument::isValid()
1629 {
1630         return validate_listings_params().empty();
1631 }
1632
1633
1634 char const * const GuiDocument::fontfamilies[5] = {
1635         "default", "rmdefault", "sfdefault", "ttdefault", ""
1636 };
1637
1638
1639 char const * GuiDocument::fontfamilies_gui[5] = {
1640         N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
1641 };
1642
1643
1644 bool GuiDocument::initialiseParams(string const &)
1645 {
1646         bp_ = buffer().params();
1647         loadModuleNames();
1648         return true;
1649 }
1650
1651
1652 void GuiDocument::clearParams()
1653 {
1654         bp_ = BufferParams();
1655 }
1656
1657
1658 BufferId GuiDocument::id() const
1659 {
1660         return &buffer();
1661 }
1662
1663
1664 vector<string> GuiDocument::getModuleNames()
1665 {
1666         return moduleNames_;
1667 }
1668
1669
1670 vector<string> const & GuiDocument::getSelectedModules()
1671 {
1672         return params().getModules();
1673 }
1674
1675
1676 string GuiDocument::getModuleDescription(string const & modName) const
1677 {
1678         LyXModule const * const mod = moduleList[modName];
1679         if (!mod)
1680                 return string("Module unavailable!");
1681         return mod->description;
1682 }
1683
1684
1685 vector<string>
1686 GuiDocument::getPackageList(string const & modName) const
1687 {
1688         LyXModule const * const mod = moduleList[modName];
1689         if (!mod)
1690                 return vector<string>(); //empty such thing
1691         return mod->packageList;
1692 }
1693
1694
1695 TextClass const & GuiDocument::textClass() const
1696 {
1697         return textclasslist[bp_.getBaseClass()];
1698 }
1699
1700
1701 static void dispatch_bufferparams(Dialog const & dialog,
1702         BufferParams const & bp, kb_action lfun)
1703 {
1704         ostringstream ss;
1705         ss << "\\begin_header\n";
1706         bp.writeFile(ss);
1707         ss << "\\end_header\n";
1708         dialog.dispatch(FuncRequest(lfun, ss.str()));
1709 }
1710
1711
1712 void GuiDocument::dispatchParams()
1713 {
1714         // This must come first so that a language change is correctly noticed
1715         setLanguage();
1716
1717         // Apply the BufferParams. Note that this will set the base class
1718         // and then update the buffer's layout.
1719         //FIXME Could this be done last? Then, I think, we'd get the automatic
1720         //update mentioned in the next FIXME...
1721         dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
1722
1723         // Generate the colours requested by each new branch.
1724         BranchList & branchlist = params().branchlist();
1725         if (!branchlist.empty()) {
1726                 BranchList::const_iterator it = branchlist.begin();
1727                 BranchList::const_iterator const end = branchlist.end();
1728                 for (; it != end; ++it) {
1729                         docstring const & current_branch = it->getBranch();
1730                         Branch const * branch = branchlist.find(current_branch);
1731                         string const x11hexname = X11hexname(branch->getColor());
1732                         // display the new color
1733                         docstring const str = current_branch + ' ' + from_ascii(x11hexname);
1734                         dispatch(FuncRequest(LFUN_SET_COLOR, str));
1735                 }
1736
1737                 // Open insets of selected branches, close deselected ones
1738                 dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
1739                         "assign branch"));
1740         }
1741         // FIXME: If we used an LFUN, we would not need those two lines:
1742         bufferview()->processUpdateFlags(Update::Force | Update::FitCursor);
1743 }
1744
1745
1746 void GuiDocument::setLanguage() const
1747 {
1748         Language const * const newL = bp_.language;
1749         if (buffer().params().language == newL)
1750                 return;
1751
1752         string const & lang_name = newL->lang();
1753         dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
1754 }
1755
1756
1757 void GuiDocument::saveAsDefault() const
1758 {
1759         dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
1760 }
1761
1762
1763 bool GuiDocument::isFontAvailable(string const & font) const
1764 {
1765         if (font == "default" || font == "cmr"
1766             || font == "cmss" || font == "cmtt")
1767                 // these are standard
1768                 return true;
1769         if (font == "lmodern" || font == "lmss" || font == "lmtt")
1770                 return LaTeXFeatures::isAvailable("lmodern");
1771         if (font == "times" || font == "palatino"
1772                  || font == "helvet" || font == "courier")
1773                 return LaTeXFeatures::isAvailable("psnfss");
1774         if (font == "cmbr" || font == "cmtl")
1775                 return LaTeXFeatures::isAvailable("cmbright");
1776         if (font == "utopia")
1777                 return LaTeXFeatures::isAvailable("utopia")
1778                         || LaTeXFeatures::isAvailable("fourier");
1779         if (font == "beraserif" || font == "berasans"
1780                 || font == "beramono")
1781                 return LaTeXFeatures::isAvailable("bera");
1782         return LaTeXFeatures::isAvailable(font);
1783 }
1784
1785
1786 bool GuiDocument::providesOSF(string const & font) const
1787 {
1788         if (font == "cmr")
1789                 return isFontAvailable("eco");
1790         if (font == "palatino")
1791                 return isFontAvailable("mathpazo");
1792         return false;
1793 }
1794
1795
1796 bool GuiDocument::providesSC(string const & font) const
1797 {
1798         if (font == "palatino")
1799                 return isFontAvailable("mathpazo");
1800         if (font == "utopia")
1801                 return isFontAvailable("fourier");
1802         return false;
1803 }
1804
1805
1806 bool GuiDocument::providesScale(string const & font) const
1807 {
1808         return font == "helvet" || font == "luximono"
1809                 || font == "berasans"  || font == "beramono";
1810 }
1811
1812
1813 void GuiDocument::loadModuleNames ()
1814 {
1815         moduleNames_.clear();
1816         LyXModuleList::const_iterator it = moduleList.begin();
1817         for (; it != moduleList.end(); ++it)
1818                 moduleNames_.push_back(it->name);
1819         if (!moduleNames_.empty())
1820                 sort(moduleNames_.begin(), moduleNames_.end());
1821 }
1822
1823
1824 Dialog * createGuiDocument(LyXView & lv) { return new GuiDocument(lv); }
1825
1826
1827 } // namespace frontend
1828 } // namespace lyx
1829
1830 #include "GuiDocument_moc.cpp"