]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/FormDocument.C
add iso8859-15 support
[lyx.git] / src / frontends / qt2 / FormDocument.C
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 2000 The LyX Team.
7  *
8  *           @author Kalle Dalheimer
9  *
10  *======================================================*/
11
12 #include <config.h>
13
14 #ifdef __GNUG_
15 #pragma implementation
16 #endif
17
18 #include "FormDocument.h"
19 #include "FormDocumentDialogImpl.h"
20 #undef emit
21
22 #include "lyx_gui_misc.h"
23
24 #include "Dialogs.h"
25 #include "layout.h"
26 #include "tex-strings.h"
27 #include "bufferparams.h"
28 #include "insets/insetquotes.h"
29 #include "vspace.h"
30 #include "support/filetools.h"
31 #include "language.h"
32 #include "LyXView.h"
33 #include "BufferView.h"
34 #include "buffer.h"
35 #include "Liason.h"
36 #include "CutAndPaste.h"
37 #include "bufferview_funcs.h"
38
39 #include <qcombobox.h>
40 #include <qlineedit.h>
41 #include <qradiobutton.h>
42 #include <qspinbox.h>
43
44 using Liason::setMinibuffer;
45 using SigC::slot;
46
47 typedef Qt2CB<ControlDocument, Qt2DB<FormDocumentDialogImpl> > base_class;
48
49 FormDocument::FormDocument( ControlDocument& c )
50     : base_class( c, _("Document Layout"))
51 {
52 }
53
54
55 void FormDocument::build()
56 {
57     int n;
58
59     // the tabbed folder
60     // PENDING(kalle) Parent???
61     dialog_.reset( new FormDocumentDialogImpl());
62
63     // Manage the restore, ok, apply, restore and cancel/close buttons
64     bc().setOK(dialog_->okPB);
65     bc().setApply(dialog_->applyPB);
66     bc().setCancel(dialog_->cancelPB);
67     bc().setRestore(dialog_->restorePB);
68     bc().refresh();
69
70     // the document paper page
71     FormDocumentDialogImpl* dialog = dialog_.get();
72     dialog->papersize2CO->insertItem( _( "Default" ) );
73     dialog->papersize2CO->insertItem( _( "Custom" ) );
74     dialog->papersize2CO->insertItem( _( "USletter" ) );
75     dialog->papersize2CO->insertItem( _( "USlegal" ) );
76     dialog->papersize2CO->insertItem( _( "USexecutive" ) );
77     dialog->papersize2CO->insertItem( _( "A3" ) );
78     dialog->papersize2CO->insertItem( _( "A4" ) );
79     dialog->papersize2CO->insertItem( _( "A5" ) );
80     dialog->papersize2CO->insertItem( _( "B3" ) );
81     dialog->papersize2CO->insertItem( _( "B4" ) );
82     dialog->papersize2CO->insertItem( _( "B5" ) );
83
84     dialog->paperPackageCO->insertItem( _( "None" ) );
85     dialog->paperPackageCO->insertItem( _( "A4 small Margins (only portrait)" ) );
86     dialog->paperPackageCO->insertItem( _( "A4 very small Margins (only portrait)" ) );
87     dialog->paperPackageCO->insertItem( _( "A4 very wide margins (only portrait)" ) );
88
89     bc().addReadOnly (dialog->paperPackageCO);
90     bc().addReadOnly (dialog->orientationBG);
91     bc().addReadOnly (dialog->portraitRB);
92     bc().addReadOnly (dialog->landscapeRB);
93     bc().addReadOnly (dialog->papersize2CO);
94     bc().addReadOnly (dialog->useGeometryCB);
95     bc().addReadOnly (dialog->customWidthED);
96     bc().addReadOnly (dialog->customHeightED);
97     bc().addReadOnly (dialog->topMarginED);
98     bc().addReadOnly (dialog->bottomMarginED);
99     bc().addReadOnly (dialog->leftMarginED);
100     bc().addReadOnly (dialog->rightMarginED);
101     bc().addReadOnly (dialog->headHeightED);
102     bc().addReadOnly (dialog->headSepED);
103     bc().addReadOnly (dialog->footSkipED);
104
105     // the document page
106     for (LyXTextClassList::const_iterator cit = textclasslist.begin();
107          cit != textclasslist.end(); ++cit)
108         {
109             docClassCO->insertItem( (*cit).description().c_str() );
110         }
111
112     dialog->docSpacingCO->insertItem( _( "Single" ) );
113     dialog->docSpacingCO->insertItem( _( "OneHalf" ) );
114     dialog->docSpacingCO->insertItem( _( "Double" ) );
115     dialog->docSpacingCO->insertItem( _( "Other" ) );
116
117     dialog->docFontSizeCO->insertItem( _( "default" ) );
118     dialog->docFontSizeCO->insertItem( _( "10" ) );
119     dialog->docFontSizeCO->insertItem( _( "11" ) );
120     dialog->docFontSizeCO->insertItem( _( "12" ) );
121     for (n=0; tex_fonts[n][0]; ++n) {
122         dialog->docFontsCO->insertItem( tex_fonts[n] );
123     }
124
125     dialog->docPagestyleCO->insertItem( _( "default" ) );
126     dialog->docPagestyleCO->insertItem( _( "empty" ) );
127     dialog->docPagestyleCO->insertItem( _( "plain" ) );
128     dialog->docPagestyleCO->insertItem( _( "headings" ) );
129     dialog->docPagestyleCO->insertItem( _( "fancy" ) );
130
131     dialog->docSkipCO->insertItem( _( "Smallskip" ) );
132     dialog->docSkipCO->insertItem( _( "Medskip" ) );
133     dialog->docSkipCO->insertItem( _( "Bigskip" ) );
134     dialog->docSkipCO->insertItem( _( "Length" ) );
135
136     bc().addReadOnly (dialog->docIndentRB);
137     bc().addReadOnly (dialog->docSkipRB);
138
139     bc().addReadOnly (dialog->docPagestyleCO);
140     bc().addReadOnly (dialog->docFontsCO);
141     bc().addReadOnly (dialog->docFontsizeCO);
142     bc().addReadOnly (dialog->docSidesOneRB);
143     bc().addReadOnly (dialog->docSidesTwoRB);
144     bc().addReadOnly (dialog->docColumnsOneRB);
145     bc().addReadOnly (dialog->docColumnsTwoRB);
146     bc().addReadOnly (dialog->docExtraED);
147     bc().addReadOnly (dialog->docSkipED);
148     bc().addReadOnly (dialog->docSkipCO);
149     bc().addReadOnly (dialog->docSpacingCO);
150     bc().addReadOnly (dialog->docSpacingED);
151
152     // the document language page
153     dialog->inputEncCO->insertItem( _( "default" ) );
154     dialog->inputEncCO->insertItem( _( "auto" ) );
155     dialog->inputEncCO->insertItem( _( "latin1" ) );
156     dialog->inputEncCO->insertItem( _( "latin2" ) );
157     dialog->inputEncCO->insertItem( _( "latin5" ) );
158     dialog->inputEncCO->insertItem( _( "latin9" ) );
159     dialog->inputEncCO->insertItem( _( "koi8-r" ) );
160     dialog->inputEncCO->insertItem( _( "koi8-u" ) );
161     dialog->inputEncCO->insertItem( _( "cp866" ) );
162     dialog->inputEncCO->insertItem( _( "cp1251" ) );
163     dialog->inputEncCO->insertItem( _( "iso88595" ) );
164
165     for (Languages::const_iterator cit = languages.begin();
166          cit != languages.end(); ++cit) {
167         dialog->languageCO->insertItem( (*cit).second.lang() );
168     }
169
170     dialog->quotesLanguageCO->insertItem( _( "``text''" ) );
171     dialog->quotesLanguageCO->insertItem( _( "''text''" ) );
172     dialog->quotesLanguageCO->insertItem( _( ",,text``" ) );
173     dialog->quotesLanguageCO->insertItem( _( ",,text''" ) );
174     dialog->quotesLanguageCO->insertItem( _( "«text»" ) );
175     dialog->quotesLanguageCO->insertItem( _( "»text«" ) );
176
177     bc().addReadOnly (dialog->inputEncCO);
178
179     // the document options page
180     dialog->secNumDepthSB->setRange( -2, 5 );
181     dialog->tocDepthSB->setRange( -1, 5 );
182     dialog->secNumDepthSB->setSteps( 1, 1 );
183     dialog->tocDepthSB->setRange( 1, 1 );
184     for (n=0; tex_graphics[n][0]; ++n) {
185         dialog->postscriptDriverCO->insertItem( tex_graphics[n] );
186     }
187
188     bc().addReadOnly (dialog->secNumDepthSB);
189     bc().addReadOnly (dialog->tocDepthSB);
190     bc().addReadOnly (dialog->useAmsMathCB);
191     bc().addReadOnly (dialog->floatPlacementED);
192     bc().addReadOnly (dialog->postscriptDriverCO);
193
194     // the document bullets page
195     dialog->bulletSizeCO->insertItem( _( "default" ) );
196     dialog->bulletSizeCO->insertItem( _( "tiny" ) );
197     dialog->bulletSizeCO->insertItem( _( "script" ) );
198     dialog->bulletSizeCO->insertItem( _( "footnote" ) );
199     dialog->bulletSizeCO->insertItem( _( "small" ) );
200     dialog->bulletSizeCO->insertItem( _( "normal" ) );
201     dialog->bulletSizeCO->insertItem( _( "large" ) );
202     dialog->bulletSizeCO->insertItem( _( "Large" ) );
203     dialog->bulletSizeCO->insertItem( _( "LARGE" ) );
204     dialog->bulletSizeCO->insertItem( _( "huge" ) );
205     dialog->bulletSizeCO->insertItem( _( "Huge" ) );
206
207     dialog->bulletSizeCO->setCurrentItem( 0 );
208     dialog->bulletLatexED->setMaxLength( 80 );
209
210     bc().addReadOnly (dialog->bulletPanelBG);
211     bc().addReadOnly (dialog->bulletSizeCO);
212     bc().addReadOnly (dialog->bulletLatexED);
213 }
214
215
216 void FormDocument::apply()
217 {
218     if (!lv_->view()->available() || !dialog_.get())
219         return;
220
221     bool redo = class_apply();
222     paper_apply();
223     redo = language_apply() || redo;
224     redo = options_apply() || redo;
225     bullets_apply();
226
227     if (redo) {
228         lv_->view()->redoCurrentBuffer();
229     }
230     lv_->buffer()->markDirty();
231     setMinibuffer(lv_, _("Document layout set"));
232 }
233
234
235 void FormDocument::cancel()
236 {
237     // this avoids confusion when reopening
238     BufferParams & param = lv_->buffer()->params;
239     param.temp_bullets[0] = param.user_defined_bullets[0];
240     param.temp_bullets[1] = param.user_defined_bullets[1];
241     param.temp_bullets[2] = param.user_defined_bullets[2];
242     param.temp_bullets[3] = param.user_defined_bullets[3];
243     hide();
244 }
245
246
247 void FormDocument::update()
248 {
249     if (!dialog_.get())
250         return;
251
252     checkReadOnly();
253
254     BufferParams const & params = lv_->buffer()->params;
255
256     class_update(params);
257     paper_update(params);
258     language_update(params);
259     options_update(params);
260     bullets_update(params);
261 }
262
263
264 #ifdef K
265 bool FormDocument::input( FL_OBJECT * ob, long data )
266 {
267     State cb = static_cast<State>( data );
268
269     switch (cb) {
270     case CHECKCHOICECLASS:
271         CheckChoiceClass(ob, 0);
272         break;
273     case CHOICEBULLETSIZE:
274         ChoiceBulletSize(ob, 0);
275         break;
276     case INPUTBULLETLATEX:
277         InputBulletLaTeX(ob, 0);
278         break;
279     case BULLETDEPTH1:
280     case BULLETDEPTH2:
281     case BULLETDEPTH3:
282     case BULLETDEPTH4:
283         BulletDepth(ob, cb);
284         break;
285     case BULLETPANEL1:
286     case BULLETPANEL2:
287     case BULLETPANEL3:
288     case BULLETPANEL4:
289     case BULLETPANEL5:
290     case BULLETPANEL6:
291         BulletPanel(ob, cb);
292         break;
293     case BULLETBMTABLE:
294         BulletBMTable(ob, 0);
295         break;
296     default:
297         break;
298     }
299
300     switch (data) {
301     case INPUT:
302     case CHECKCHOICECLASS:
303     case CHOICEBULLETSIZE:
304     case INPUTBULLETLATEX:
305     case BULLETBMTABLE:
306         return CheckDocumentInput(ob, 0);
307     default:
308         break;
309     }
310
311     return true;
312 }
313 #endif
314
315
316 #ifdef K
317 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
318 {
319     FormDocument * pre = static_cast<FormDocument*>(v);
320     if (combox == pre->combo_doc_class.get())
321         pre->CheckChoiceClass(0, 0);
322     pre->bc().valid(pre->CheckDocumentInput(0,0));
323 }
324 #endif
325
326 bool FormDocument::class_apply()
327 {
328     bool redo = false;
329     BufferParams &params = lv_->buffer()->params;
330
331     // If default skip is a "Length" but there's no text in the
332     // input field, reset the kind to "Medskip", which is the default.
333     if( ( dialog_->docSkipCO->currentItem() == 3 ) &&
334         dialog_->docSkipED->text().isEmpty() )
335         dialog_->docSkipCO->setCurrentItem( 1 );
336
337     params.fonts = dialog_->docFontsCO->currentText();
338     params.fontsize = dialog_->docFontSizeCO->currentText();
339     params.pagestyle = dialog->docPagestyleCO->currentText();
340     
341     unsigned int const new_class = dialog_->docClassCO->currentItem();
342     
343     if (params.textclass != new_class) {
344         // try to load new_class
345         if (textclasslist.Load(new_class)) {
346             // successfully loaded
347             redo = true;
348             setMinibuffer(lv_, _("Converting document to new document class..."));
349             CutAndPaste cap;
350             int ret = cap.SwitchLayoutsBetweenClasses(
351                                                       params.textclass, new_class,
352                                                       lv_->buffer()->paragraph);                
353             if (ret) {  
354                 string s;
355                 if (ret==1) {
356                     s = _("One paragraph couldn't be converted");
357                 } else {
358                     s += tostr(ret);
359                     s += _(" paragraphs couldn't be converted");
360                 }
361                 WriteAlert(_("Conversion Errors!"),s,
362                            _("into chosen document class"));
363             }
364
365             params.textclass = new_class;
366         } else {
367             // problem changing class -- warn user and retain old style
368             WriteAlert(_("Conversion Errors!"),
369                        _("Errors loading new document class."),
370                        _("Reverting to original document class."));
371             dialog_->docClassCO->setCurrentItem( params.textclass );
372         }
373     }
374     BufferParams::PARSEP tmpsep = params.paragraph_separation;
375     if( dialog_->_docIndentRB->isChecked() )
376         params.paragraph_separation = BufferParams::PARSEP_INDENT;
377     else
378         params.paragraph_separation = BufferParams::PARSEP_SKIP;
379     if (tmpsep != params.paragraph_separation)
380         redo = true;
381
382     VSpace tmpdefskip = params.getDefSkip();
383     switch( dialog_->docSkipCO->currentItem() ) {
384     case 0:
385         params.setDefSkip(VSpace(VSpace::SMALLSKIP));
386         break;
387     case 1:
388         params.setDefSkip(VSpace(VSpace::MEDSKIP));
389         break;
390     case 2:
391         params.setDefSkip(VSpace(VSpace::BIGSKIP));
392         break;
393     case 3:
394         params.setDefSkip
395             (VSpace(LyXGlueLength(dialog_->docSkipED->text())));
396         break;
397         // DocumentDefskipCB assures that this never happens
398     default:
399         params.setDefSkip(VSpace(VSpace::MEDSKIP));
400         break;
401     }
402     if (!(tmpdefskip == params.getDefSkip()))
403         redo = true;
404
405     if( dialog_->docColumnsTwo->isChecked() )
406         params.columns = 2;
407     else
408         params.columns = 1;
409     if( dialog_->docSidesTwo->isChecked() )
410         params.sides = LyXTextClass::TwoSides;
411     else
412         params.sides = LyXTextClass::OneSide;
413
414     Spacing tmpSpacing = params.spacing;
415     switch( dialog_->docSpacingCO->currentItem() ) {
416     case 0:
417         lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
418         params.spacing.set(Spacing::Single);
419         break;
420     case 1:
421         lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
422         params.spacing.set(Spacing::Onehalf);
423         break;
424     case 2:
425         lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
426         params.spacing.set(Spacing::Double);
427         break;
428     case 3:
429         lyxerr[Debug::INFO] << "Spacing: OTHER\n";
430         params.spacing.set(Spacing::Other,
431                            dialog_->docSpacingED->text() );
432         break;
433     }
434     if (tmpSpacing != params.spacing)
435         redo = true;
436
437     params.options = docExtraED->text();
438
439     return redo;
440 }
441
442
443 void FormDocument::paper_apply()
444 {
445     BufferParams & params = lv_->buffer()->params;
446
447     params.papersize2 =
448         static_cast<char>(dialog_->papersize2CO->currentItem());
449     params.paperpackage =
450         static_cast<char>(dialog_->paperPackageCO->currentItem() );
451     params.use_geometry = dialog_->useGeometryCB->isChecked();
452     if (dialog_->landscapeRB->isChecked() )
453         params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
454     else
455         params.orientation = BufferParams::ORIENTATION_PORTRAIT;
456     params.paperwidth = dialog_->customWidthED->text();
457     params.paperheight = dialog_->customHeightED->text();
458     params.leftmargin = dialog_->leftMarginED->text();
459     params.topmargin = dialog_->topMarginED->text();
460     params.rightmargin = dialog_->rightMarginED->text();
461     params.bottommargin = dialog_->bottomMarginED->text();
462     params.headheight = dialog_->headHeightED->text();
463     params.headsep = dialog_->headSepED->text();
464     params.footskip = dialog_->footSkipED->text();
465     lv_->buffer()->setPaperStuff();
466 }
467
468
469 bool FormDocument::language_apply()
470 {
471     BufferParams & params = lv_->buffer()->params;
472     InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
473     bool redo = false;
474
475     switch (dialog_->quotesLanguageCO->currentItem() ) {
476     case 0:
477         lga = InsetQuotes::EnglishQ;
478         break;
479     case 1:
480         lga = InsetQuotes::SwedishQ;
481         break;
482     case 2:
483         lga = InsetQuotes::GermanQ;
484         break;
485     case 3:
486         lga = InsetQuotes::PolishQ;
487         break;
488     case 4:
489         lga = InsetQuotes::FrenchQ;
490         break;
491     case 5:
492         lga = InsetQuotes::DanishQ;
493         break;
494     }
495     params.quotes_language = lga;
496     if (dialog_->singleRB->isChecked() )
497         params.quotes_times = InsetQuotes::SingleQ;
498     else
499         params.quotes_times = InsetQuotes::DoubleQ;
500
501     Language const * old_language = params.language;
502     Language const * new_language =
503         languages.getLanguage(dialog_->languageCO->currentItem() );
504     if (!new_language)
505         new_language = default_language;
506
507     if (old_language != new_language
508         && old_language->RightToLeft() == new_language->RightToLeft()
509         && !lv_->buffer()->isMultiLingual())
510         lv_->buffer()->ChangeLanguage(old_language, new_language);
511     if (old_language != new_language) {
512         redo = true;
513     }
514     params.language = new_language;
515     params.inputenc = dialog_->inputEncCO->currentText();
516
517     return redo;
518 }
519
520
521 bool FormDocument::options_apply()
522 {
523     BufferParams & params = lv_->buffer()->params;
524     bool redo = false;
525
526     params.graphicsDriver =
527         dialog_->postscriptDriverCO->currentText();
528     params.use_amsmath = dialog_->useAmsMathCB->isChecked();
529
530     int tmpchar = int(dialog_->secNumDepth->value() );
531     if (params.secnumdepth != tmpchar)
532         redo = true;
533     params.secnumdepth = tmpchar;
534
535     params.tocdepth = int(dialog_->tocDepth->value() );
536
537     params.float_placement =
538         dialog_->floatPlacementED->text();
539
540     return redo;
541 }
542
543
544 void FormDocument::bullets_apply()
545 {
546     /* update the bullet settings */
547     BufferParams & param = lv_->buffer()->params;
548
549     // a little bit of loop unrolling
550     param.user_defined_bullets[0] = param.temp_bullets[0];
551     param.user_defined_bullets[1] = param.temp_bullets[1];
552     param.user_defined_bullets[2] = param.temp_bullets[2];
553     param.user_defined_bullets[3] = param.temp_bullets[3];
554 }
555
556
557 void FormDocument::class_update(BufferParams const & params)
558 {
559     if (!class_.get())
560         return;
561
562     LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
563
564     combo_doc_class->select_text(
565                                  textclasslist.DescOfClass(params.textclass));
566     Qt2Helper::setCurrentComboItem( dialog_->docFonts, params.fonts.c_str() );
567     dialog_->docFontSizeCO->clear();
568     dialog_->docFontSizeCO->insertItem( _( "default" ) );
569     dialog_->docFontSizeCO->insertItem( tclass.opt_fontsize().c_str());
570     dialog_->docFontSizeCO->setCurrentItem( tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+1);
571     dialog_->docPagestyleCO->clear();
572     dialog_->docPagestyleCO->insertItem( _( "default" ) );
573     dialog_->docPagestyleCO->insertItem( tclass.opt_pagestyle().c_str());
574     dialog_->docPagestyleCO->setCurrentItem( tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+1);
575     dialog_->docIndentRB->setChecked( false );
576     dialog_->docSkipRB->setChecked( false );
577     if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
578         dialog_->docIndentRB->setChecked( true );
579     else
580         dialog_->docSkipRB->setChecked( true );
581     switch (params.getDefSkip().kind()) {
582     case VSpace::SMALLSKIP:
583         dialog_->docSkipCO->setCurrentItem( 0 );
584         break;
585     case VSpace::MEDSKIP:
586         dialog_->docSkipCO->setCurrentItem( 1 );
587         break;
588     case VSpace::BIGSKIP:
589         dialog_->docSkipCO->setCurrentItem( 2 );
590         break;
591     case VSpace::LENGTH:
592         dialog_->docSkipCO->setCurrentItem( 3 );
593         dialog_->docSkipED->setText( params.getDefSkip().asLyXCommand().c_str());
594         break;
595     default:
596         dialog_->docSkipCO->setCurrentItem( 1 );
597         break;
598     }
599     dialog_->docSidesOneRB->setChecked( false );
600     dialog_->docSidesTwoRB->setChecked( false );
601     if (params.sides == LyXTextClass::TwoSides)
602         dialog_->docSidesTwo->setChecked( true );
603     else
604         dialog_->docSidesOne->setChecked( true );
605     dialog_->docColumnsOneRB->setChecked( false );
606     dialog_->docColumnsTwoRB->setChecked( false );
607     if (params.columns == 2)
608         dialog_->docColumnsTwoRB->setChecked( true );
609     else
610         dialog_->docColumnsOneRB->setChecked( true );
611     dialog_->docSpacingED->setText( "" );
612     switch (params.spacing.getSpace()) {
613     case Spacing::Default: // nothing bad should happen with this
614     case Spacing::Single:
615         // \singlespacing
616         dialog_->docSpacingCO->setCurrentItem( 0 );
617         break;
618     case Spacing::Onehalf:
619         // \onehalfspacing
620         dialog_->docSpacingCO->setCurrentItem( 1 );
621         break;
622     case Spacing::Double:
623         // \doublespacing
624         dialog_->docSpacingCO->setCurrentItem( 2 );
625         break;
626     case Spacing::Other:
627         {
628             dialog_->docSpacingCO->setCurrentItem( 3 );
629             QString sval;
630             sval.sprintf("%g",params.spacing.getValue());
631             dialog_->docSpacingED->setText( sval );
632             break;
633         }
634     }
635     if (!params.options.empty())
636         dialog_->docExtraED->setText(, params.options.c_str());
637     else
638         dialog_->docExtraED->setText( "" );
639 }
640
641
642 void FormDocument::language_update(BufferParams const & params)
643 {
644     if (!language_.get())
645         return;
646
647     Qt2Helper::setCurrentItemText( dialog_->languageCO, params.language->lang() );
648     Qt2Helper::setCurrentItemText( dialog_->inputEncCO, params.inputenc.c_str() );
649     dialog_->quotesLanguageCO->setCurrentItem( params.quotes_language );
650     dialog_->singleRB->setChecked( false );
651     dialog_->doubleRB->setChecked( false );
652     if (params.quotes_times == InsetQuotes::SingleQ)
653         dialog_->singleRB->setChecked( true );
654     else
655         dialog_->doubleRB->setChecked( true );
656 }
657
658
659 void FormDocument::options_update(BufferParams const & params)
660 {
661     if (!options_.get())
662         return;
663
664     Qt2Helper::setCurrentItemText( dialog_->postscriptDriverCO,
665                                    params.graphicsDriver.c_str());
666     dialog_->useAmsMathCB->setChecked( params.use_amsmath );
667     dialog_->secNumDepthSB->setValue( params.secnumdepth );
668     dialog_->setTocDepthSB->setValue( params.tocdepth );
669     if (!params.float_placement.empty())
670         dialog_->floatPlacementED->setText( params.float_placement.c_str());
671     else
672         dialog_->floatPlacementED->setText( "" );
673 }
674
675
676 void FormDocument::paper_update(BufferParams const & params)
677 {
678     if (!paper_.get())
679         return;
680
681     dialog_->papersize2CO->setCurrentItem( params.papersize2 );
682     dialog_->paperPackageCO->setCurrentItem( params.paperpackage );
683     dialog_->useGeometryCB->setChecked( params.use_geometry );
684     dialog_->portraitRB->setChecked( false );
685     dialog_->landscapeRB->setChecked( false );
686     if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
687         dialog_->landscapeRB->setChecked( true );
688     else
689         dialog_->portraitRB->setChecked( true );
690     dialog_->customWidthED->setText( params.paperwidth.c_str());
691     dialog_->customHeightED->setText( params.paperheight.c_str());
692     dialog_->leftMarginED->setText( params.leftmargin.c_str());
693     dialog_->topMarginED->setText( params.topmargin.c_str());
694     dialog_->rightMarginED->setText( params.rightmargin.c_str());
695     dialog_->bottomMarginED->setText( params.bottommargin.c_str());
696     dialog_->headHeightED->setText( params.headheight.c_str());
697     dialog_->headSepED->setText( params.headsep.c_str());
698     dialog_->footSkipED->setText( params.footskip.c_str());
699     dialog_->papersize2CO->setFocus();
700 }
701
702
703 void FormDocument::bullets_update(BufferParams const & params)
704 {
705     bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
706     setEnabled(fbullet, !isLinuxDoc);
707
708     if (isLinuxDoc) return;
709
710     dialog_->bulletDepth1RB->setChecked( true );
711     dialog_->bulletLatexED->setText( params.user_defined_bullets[0].getText().c_str());
712     dialog_->bulletSizeCO->setCurrentItem( params.user_defined_bullets[0].getSize() + 1);
713 }
714
715
716 void FormDocument::checkReadOnly()
717 {
718     if (bc().readOnly(lv_->buffer()->isReadonly())) {
719         dialog_->docClassCO->setEnabled( false );
720         dialog_->languageCO->setEnabled( false );
721         dialog_->warningLA->setText( _("Document is read-only."
722                                        " No changes to layout permitted."));
723         dialog_->warningLA->show();
724     } else {
725         dialog_->docClassCO->setEnabled( true );
726         dialog_->languageCO->setEnabled( true );
727         dialog_->warningLA->hide();
728     }
729 }
730
731
732 void FormDocument::checkMarginValues()
733 {
734     bool const not_empty =
735         !dialog_->topMarginED->text().isEmpty() ||
736         !dialog_->bottomMarginED->text().isEmpty() ||
737         !dialog_->leftMarginED->text().isEmpty() ||
738         !dialog_->rightMarginED->text().isEmpty() ||
739         !dialog_->headHeightED->text().isEmpty() ||
740         !dialog_->headSepED->text().isEmpty() ||
741         !dialog_->footSkipED->text().isEmpty() ||
742         !dialog_->customWidthED->text().isEmpty() ||
743         !dialog_->customHeightED->text().isEmpty();
744     if (not_empty)
745         dialog_->useGeometryCB->setChecked( true );
746 }
747
748 #ifdef K
749 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
750 {
751     string str;
752     int val;
753     bool ok = true;
754     char const * input;
755
756     checkMarginValues();
757     if (ob == paper_->choice_papersize2) {
758         val = fl_get_choice(paper_->choice_papersize2)-1;
759         if (val == BufferParams::VM_PAPER_DEFAULT) {
760             fl_set_button(paper_->push_use_geometry, 0);
761             checkMarginValues();
762         } else {
763             if ((val != BufferParams::VM_PAPER_USLETTER) &&
764                 (val != BufferParams::VM_PAPER_USLEGAL) &&
765                 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
766                 (val != BufferParams::VM_PAPER_A4) &&
767                 (val != BufferParams::VM_PAPER_A5) &&
768                 (val != BufferParams::VM_PAPER_B5)) {
769                 fl_set_button(paper_->push_use_geometry, 1);
770             }
771             fl_set_choice(paper_->choice_paperpackage,
772                           BufferParams::PACKAGE_NONE + 1);
773         }
774     } else if (ob == paper_->choice_paperpackage) {
775         val = fl_get_choice(paper_->choice_paperpackage)-1;
776         if (val != BufferParams::PACKAGE_NONE) {
777             fl_set_choice(paper_->choice_papersize2,
778                           BufferParams::VM_PAPER_DEFAULT + 1);
779             fl_set_button(paper_->push_use_geometry, 0);
780         }
781     } else if (ob == class_->input_doc_spacing) {
782         input = fl_get_input(class_->input_doc_spacing);
783         if (!*input) {
784             fl_set_choice (class_->choice_doc_spacing, 1);
785         } else {
786             fl_set_choice(class_->choice_doc_spacing, 4);
787         }
788     }
789     // this has to be all out of if/elseif because it has to deactivate
790     // the document buttons and so the whole stuff has to be tested again.
791     str = fl_get_input(paper_->input_custom_width);
792     ok = ok && (str.empty() || isValidLength(str));
793     str = fl_get_input(paper_->input_custom_height);
794     ok = ok && (str.empty() || isValidLength(str));
795     str = fl_get_input(paper_->input_left_margin);
796     ok = ok && (str.empty() || isValidLength(str));
797     str = fl_get_input(paper_->input_right_margin);
798     ok = ok && (str.empty() || isValidLength(str));
799     str = fl_get_input(paper_->input_top_margin);
800     ok = ok && (str.empty() || isValidLength(str));
801     str = fl_get_input(paper_->input_bottom_margin);
802     ok = ok && (str.empty() || isValidLength(str));
803     str = fl_get_input(paper_->input_head_height);
804     ok = ok && (str.empty() || isValidLength(str));
805     str = fl_get_input(paper_->input_head_sep);
806     ok = ok && (str.empty() || isValidLength(str));
807     str = fl_get_input(paper_->input_foot_skip);
808     ok = ok && (str.empty() || isValidLength(str));
809     // "Synchronize" the choice and the input field, so that it
810     // is impossible to commit senseless data.
811     input = fl_get_input (class_->input_doc_skip);
812     if (ob == class_->input_doc_skip) {
813         if (!*input) {
814             fl_set_choice (class_->choice_doc_skip, 2);
815         } else if (isValidGlueLength (input)) {
816             fl_set_choice (class_->choice_doc_skip, 4);
817         } else {
818             fl_set_choice(class_->choice_doc_skip, 4);
819             ok = false;
820         }
821     } else {
822         if (*input && !isValidGlueLength(input))
823             ok = false;
824     }
825     if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
826         ok = false;
827     else if (fl_get_choice(class_->choice_doc_skip) != 4)
828         fl_set_input (class_->input_doc_skip, "");
829
830     input = fl_get_input(class_->input_doc_spacing);
831     if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
832         ok = false;
833     else  if (fl_get_choice(class_->choice_doc_spacing) != 4)
834         fl_set_input (class_->input_doc_spacing, "");
835     return ok;
836 }
837
838
839 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
840 {
841     BufferParams & param = lv_->buffer()->params;
842
843     // convert from 1-6 range to -1-4
844     param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
845     fl_set_input(bullets_->input_bullet_latex,
846                  param.temp_bullets[current_bullet_depth].getText().c_str());
847 }
848
849
850 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
851 {
852     BufferParams & param = lv_->buffer()->params;
853
854     param.temp_bullets[current_bullet_depth].
855         setText(fl_get_input(bullets_->input_bullet_latex));
856 }
857
858
859 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
860 {
861     /* Should I do the following:                                 */
862     /*  1. change to the panel that the current bullet belongs in */
863     /*  2. show that bullet as selected                           */
864     /*  3. change the size setting to the size of the bullet in Q.*/
865     /*  4. display the latex equivalent in the latex box          */
866     /*                                                            */
867     /* I'm inclined to just go with 3 and 4 at the moment and     */
868     /* maybe try to support the others later                      */
869     BufferParams & param = lv_->buffer()->params;
870
871     int data = 0;
872     if (cb == BULLETDEPTH1 )
873         data = 0;
874     else if (cb == BULLETDEPTH2 )
875         data = 1;
876     else if (cb == BULLETDEPTH3 )
877         data = 2;
878     else if (cb == BULLETDEPTH4 )
879         data = 3;
880
881     switch (fl_get_button_numb(ob)) {
882     case 3:
883         // right mouse button resets to default
884         param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
885     default:
886         current_bullet_depth = data;
887         fl_set_input(bullets_->input_bullet_latex,
888                      param.temp_bullets[data].getText().c_str());
889         fl_set_choice(bullets_->choice_bullet_size,
890                       param.temp_bullets[data].getSize() + 2);
891     }
892 }
893
894
895 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
896 {
897     /* Here we have to change the background pixmap to that selected */
898     /* by the user. (eg. standard.xpm, psnfss1.xpm etc...)           */
899
900     int data = 0;
901     if (cb == BULLETPANEL1 )
902         data = 0;
903     else if (cb == BULLETPANEL2 )
904         data = 1;
905     else if (cb == BULLETPANEL3 )
906         data = 2;
907     else if (cb == BULLETPANEL4 )
908         data = 3;
909     else if (cb == BULLETPANEL5 )
910         data = 4;
911     else if (cb == BULLETPANEL6 )
912         data = 5;
913
914     if (data != current_bullet_panel) {
915         fl_freeze_form(bullets_->form);
916         current_bullet_panel = data;
917
918         /* free the current pixmap */
919         fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
920         string new_panel;
921         switch (cb) {
922             /* display the new one */
923         case BULLETPANEL1 :
924             new_panel = "standard";
925             break;
926         case BULLETPANEL2 :
927             new_panel = "amssymb";
928             break;
929         case BULLETPANEL3 :
930             new_panel = "psnfss1";
931             break;
932         case BULLETPANEL4 :
933             new_panel = "psnfss2";
934             break;
935         case BULLETPANEL5 :
936             new_panel = "psnfss3";
937             break;
938         case BULLETPANEL6 :
939             new_panel = "psnfss4";
940             break;
941         default :
942             /* something very wrong happened */
943             // play it safe for now but should be an exception
944             current_bullet_panel = 0;  // standard panel
945             new_panel = "standard";
946             break;
947         }
948         new_panel += ".xpm";
949         fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
950                                    LibFileSearch("images", new_panel).c_str());
951         fl_redraw_object(bullets_->bmtable_bullet_panel);
952         fl_unfreeze_form(bullets_->form);
953     }
954 }
955
956
957 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
958 {
959     /* handle the user input by setting the current bullet depth's pixmap */
960     /* to that extracted from the current chosen position of the BMTable  */
961     /* Don't forget to free the button's old pixmap first.                */
962
963     BufferParams & param = lv_->buffer()->params;
964     int bmtable_button = fl_get_bmtable(ob);
965
966     /* try to keep the button held down till another is pushed */
967     /*  fl_set_bmtable(ob, 1, bmtable_button); */
968     param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
969     param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
970     fl_set_input(bullets_->input_bullet_latex,
971                  param.temp_bullets[current_bullet_depth].getText().c_str());
972 }
973
974
975 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
976 {
977     if (!ob)
978         ob = class_->choice_doc_class;
979
980     ProhibitInput(lv_->view());
981
982     unsigned int tc = combo_doc_class->get() - 1;
983     if (textclasslist.Load(tc)) {
984         // we use a copy of the bufferparams because we do not
985         // want to modify them yet.
986         BufferParams params = lv_->buffer()->params;
987
988         if (params.textclass != tc
989             && AskQuestion(_("Should I set some parameters to"),
990                            _("the defaults of this document class?"))) {
991             params.textclass = tc;
992             params.useClassDefaults();
993             UpdateLayoutDocument(params);
994         }
995     } else {
996         // unable to load new style
997         WriteAlert(_("Conversion Errors!"),
998                    _("Unable to switch to new document class."),
999                    _("Reverting to original document class."));
1000         combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1001     }
1002     AllowInput(lv_->view());
1003 }
1004 #endif
1005
1006 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1007 {
1008     if (!dialog_.get())
1009         return;
1010
1011     checkReadOnly();
1012     class_update(params);
1013     paper_update(params);
1014     language_update(params);
1015     options_update(params);
1016     bullets_update(params);
1017 }