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