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