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