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