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