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