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