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