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