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