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