]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/FormDocument.C
Another quick fix to get qt2 frontend to compile
[lyx.git] / src / frontends / qt2 / FormDocument.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *           Copyright 2000 The LyX Team.
7  *
8  *           @author Jürgen Vigna, Kalle Dalheimer
9  *
10  *======================================================*/
11
12 #include <config.h>
13
14 #ifdef __GNUG_
15 #pragma implementation
16 #endif
17
18 #include "FormDocumentDialog.h"
19 #undef emit
20
21 #include "lyx_gui_misc.h"
22 #include "gettext.h"
23 //#include FORMS_H_LOCATION
24 #include XPM_H_LOCATION
25
26 #include "FormDocument.h"
27 //#include "xform_macros.h"
28 #include "Dialogs.h"
29 #include "layout.h"
30 #include "combox.h"
31 #include "tex-strings.h"
32 #include "bufferparams.h"
33 #include "insets/insetquotes.h"
34 #include "vspace.h"
35 #include "bmtable.h"
36 #include "support/filetools.h"
37 #include "language.h"
38 #include "LyXView.h"
39 #include "BufferView.h"
40 #include "buffer.h"
41 #include "Liason.h"
42 #include "CutAndPaste.h"
43 #include "bufferview_funcs.h"
44 #include "ButtonController.h"
45
46 #ifdef SIGC_CXX_NAMESPACES
47 using SigC::slot;
48 #endif
49
50 #ifdef CXX_WORKING_NAMESPACES
51 using Liason::setMinibuffer;
52 #endif
53
54 #define USE_CLASS_COMBO 1
55
56 #include <qcombobox.h>
57 #include <qlineedit.h>
58 #include <qradiobutton.h>
59 #include <qtoolbutton.h>
60 #include <qcheckbox.h>
61 #include <qspinbox.h>
62 #include <qbuttongroup.h>
63 #include <qlabel.h>
64
65 // Bullet images
66 #include "../../../lib/images/standard.xpm"
67 #include "../../../lib/images/psnfss1.xpm"
68 #include "../../../lib/images/psnfss2.xpm"
69 #include "../../../lib/images/psnfss3.xpm"
70 #include "../../../lib/images/psnfss4.xpm"
71 #include "../../../lib/images/amssymb.xpm"
72
73
74 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
75   : FormBaseBD( lv, d, _( "Document Layout" ), 
76                                 new NoRepeatedApplyReadOnlyPolicy ),
77   dialog_(0), lv_(lv), d_(d), u_(0), h_(0),
78   status(POPUP_UNMODIFIED) ,
79   currentBulletPanel(0),
80   currentBulletDepth(0)
81 {
82     // let the popup be shown
83     // This is a permanent connection so we won't bother
84     // storing a copy because we won't be disconnecting.
85     d->showLayoutDocument.connect(slot(this, &FormDocument::show));
86
87     // load the images
88     standardpix = new QPixmap( standard );
89     amssymbpix = new QPixmap( amssymb );
90     psnfss1pix = new QPixmap( psnfss1 );
91     psnfss2pix = new QPixmap( psnfss2 );
92     psnfss3pix = new QPixmap( psnfss3 );
93     psnfss4pix = new QPixmap( psnfss4 );
94 }
95
96
97 FormDocument::~FormDocument()
98 {
99   delete standardpix;
100   delete amssymbpix;
101   delete psnfss1pix;
102   delete psnfss2pix;
103   delete psnfss3pix;
104   delete psnfss4pix;
105 }
106
107
108 void FormDocument::build()
109 {
110     int n;
111
112     dialog_ = new FormDocumentDialog( this, 0, _( "Document Layout" ) );
113
114     for (LyXTextClassList::const_iterator cit = textclasslist.begin();
115          cit != textclasslist.end(); ++cit)
116     {
117         dialog_->classesCO->insertItem((*cit).description().c_str());
118     }
119
120     for (n=0; tex_fonts[n][0]; ++n) {
121       dialog_->fontsCO->insertItem( tex_fonts[n] );
122     }
123
124     for(Languages::const_iterator cit = languages.begin();
125         cit != languages.end(); ++cit) {
126         dialog_->languageCO->insertItem((*cit).second.lang().c_str());
127     }
128
129     for (n=0; tex_graphics[n][0]; ++n) {
130       dialog_->psDriverCO->insertItem( tex_graphics[n] );
131     }
132
133     dialog_->bulletDepth1PB->setOn( true );
134 }
135
136
137 void FormDocument::apply()
138 {
139     if (!lv_->view()->available() || !dialog_)
140         return;
141
142     bool redo = class_apply();
143     paper_apply();
144     redo = language_apply() || redo;
145     redo = options_apply() || redo;
146     bullets_apply();
147
148     if (redo) {
149             lv_->view()->redoCurrentBuffer();
150     }
151     lv_->buffer()->markDirty();
152     setMinibuffer(lv_, _("Document layout set"));
153 }
154
155
156 bool FormDocument::class_apply()
157 {
158         bool redo = false;
159         BufferParams &params = lv_->buffer()->params;
160
161         // If default skip is a "Length" but there's no text in the
162         // input field, reset the kind to "Medskip", which is the default.
163         if( ( dialog_->defaultSkipCO->currentItem() == 4 ) &&
164             ( dialog_->defaultSkipED->text().isEmpty() ) )
165           dialog_->defaultSkipCO->setCurrentItem( 1 );
166         params.fonts = dialog_->fontsCO->currentText();
167         params.fontsize = dialog_->fontSizeCO->currentText();
168         params.pagestyle = dialog_->pagestyleCO->currentText();
169
170         unsigned int new_class = dialog_->classesCO->currentItem();
171         if (params.textclass != new_class) {
172                 // try to load new_class
173                 if (textclasslist.Load(new_class)) {
174                         // successfully loaded
175                         redo = true;
176                         setMinibuffer(lv_, _("Converting document to new document class..."));
177                         CutAndPaste cap;
178                         int ret = cap.SwitchLayoutsBetweenClasses(
179                             params.textclass, new_class,
180                             lv_->buffer()->paragraph);
181                         if (ret) {
182                                 string s;
183                                 if (ret==1) {
184                                         s = _("One paragraph couldn't be converted");
185                                 } else {
186                                         s += tostr(ret);
187                                         s += _(" paragraphs couldn't be converted");
188                                 }
189                                 WriteAlert(_("Conversion Errors!"),s,
190                                            _("into chosen document class"));
191                         }
192                         
193                         params.textclass = new_class;
194                 } else {
195                         // problem changing class -- warn user and retain old style
196                         WriteAlert(_("Conversion Errors!"),
197                                    _("Errors loading new document class."),
198                                    _("Reverting to original document class."));
199                         dialog_->classesCO->setCurrentItem( params.textclass );
200                 }
201         }
202         char tmpsep = params.paragraph_separation;
203         if( dialog_->indentRB->isChecked() )
204                 params.paragraph_separation = BufferParams::PARSEP_INDENT;
205         else
206                 params.paragraph_separation = BufferParams::PARSEP_SKIP;
207         if (tmpsep != params.paragraph_separation)
208                 redo = true;
209         
210         VSpace tmpdefskip = params.getDefSkip();
211         switch( dialog_->defaultSkipCO->currentItem() ) {
212         case 0:
213                 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
214                 break;
215         case 1:
216                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
217                 break;
218         case 2:
219             params.setDefSkip(VSpace(VSpace::BIGSKIP));
220             break;
221         case 3:
222                 params.setDefSkip
223                         (VSpace(LyXGlueLength(dialog_->defaultSkipED->text().latin1())));
224                 break;
225                 // DocumentDefskipCB assures that this never happens
226         default:
227                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
228                 break;
229         }
230         if (!(tmpdefskip == params.getDefSkip()))
231                 redo = true;
232         
233         if( dialog_->twoColumnsRB->isChecked() )
234                 params.columns = 2;
235         else
236                 params.columns = 1;
237         if( dialog_->twoSidesRB->isChecked() )
238                 params.sides = LyXTextClass::TwoSides;
239         else
240                 params.sides = LyXTextClass::OneSide;
241         
242         Spacing tmpSpacing = params.spacing;
243         switch( dialog_->spacingCO->currentItem() ) {
244         case 0:
245                 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
246                 params.spacing.set(Spacing::Single);
247                 break;
248         case 1:
249                 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
250                 params.spacing.set(Spacing::Onehalf);
251                 break;
252         case 2:
253                 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
254                 params.spacing.set(Spacing::Double);
255                 break;
256         case 3:
257                 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
258                 params.spacing.set(Spacing::Other, 
259                                    dialog_->defaultSkipED->text().latin1() );
260                 break;
261         }
262         if (tmpSpacing != params.spacing)
263                 redo = true;
264         
265         params.options = dialog_->extraOptionsED->text();
266         
267         return redo;
268 }
269
270
271 void FormDocument::paper_apply()
272 {
273     BufferParams & params = lv_->buffer()->params;
274     
275     params.papersize2 = dialog_->papersizeCO->currentItem();
276     params.paperpackage = dialog_->specialCO->currentItem();
277     params.use_geometry = dialog_->CheckBox1->isChecked();
278     if( dialog_->landscapeRB->isChecked() )
279         params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
280     else
281         params.orientation = BufferParams::ORIENTATION_PORTRAIT;
282     params.paperwidth = dialog_->customWidthED->text();
283     params.paperheight = dialog_->customHeightED->text();
284     params.leftmargin = dialog_->marginLeftED->text();
285     params.topmargin = dialog_->marginTopED->text();
286     params.rightmargin = dialog_->marginRightED->text();
287     params.bottommargin = dialog_->marginBottomED->text();
288     params.headheight = dialog_->headheightED->text();
289     params.headsep = dialog_->headsepED->text();
290     params.footskip = dialog_->footskipED->text();
291     lv_->buffer()->setPaperStuff();
292 }
293
294
295 bool FormDocument::language_apply()
296 {
297     BufferParams & params = lv_->buffer()->params;
298     InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
299     bool redo = false;
300
301     switch( dialog_->quoteStyleTypeCO->currentItem() ) {
302     case 0:
303         lga = InsetQuotes::EnglishQ;
304         break;
305     case 1:
306         lga = InsetQuotes::SwedishQ;
307         break;
308     case 2:
309         lga = InsetQuotes::GermanQ;
310         break;
311     case 3:
312         lga = InsetQuotes::PolishQ;
313         break;
314     case 4:
315         lga = InsetQuotes::FrenchQ;
316         break;
317     case 5:
318         lga = InsetQuotes::DanishQ;
319         break;
320     }
321     params.quotes_language = lga;
322     if( dialog_->quoteStyleSingleRB->isChecked() )
323         params.quotes_times = InsetQuotes::SingleQ;
324     else
325         params.quotes_times = InsetQuotes::DoubleQ;
326
327     Language const * old_language = params.language;
328     Language const * new_language =
329           languages.getLanguage( dialog_->languageCO->currentText().latin1() );
330         if( !new_language )
331           new_language = default_language;
332
333     if (old_language != new_language
334         && old_language->RightToLeft() == new_language->RightToLeft()
335         && !lv_->buffer()->isMultiLingual())
336         lv_->buffer()->ChangeLanguage(old_language, new_language);
337     if (old_language != new_language) {
338         redo = true;
339     }
340     params.language = new_language;
341     params.inputenc = dialog_->encodingCO->currentText();
342
343     return redo;
344 }
345
346
347 bool FormDocument::options_apply()
348 {
349     BufferParams & params = lv_->buffer()->params;
350     bool redo = false;
351
352     params.graphicsDriver =
353       dialog_->psDriverCO->currentText();
354     params.use_amsmath = dialog_->amsMathCB->isChecked();
355
356     int tmpchar = dialog_->sectionNumberDepthSB->value();
357     if (params.secnumdepth != tmpchar)
358         redo = true;
359     params.secnumdepth = tmpchar;
360    
361     params.tocdepth = dialog_->tocDepthSB->value();
362
363     params.float_placement =
364       dialog_->floatPlacementED->text();
365
366     return redo;
367 }
368
369
370 void FormDocument::bullets_apply()
371 {
372     /* update the bullet settings */
373     BufferParams & param = lv_->buffer()->params;
374     
375     // a little bit of loop unrolling
376     param.user_defined_bullets[0] = param.temp_bullets[0];
377     param.user_defined_bullets[1] = param.temp_bullets[1];
378     param.user_defined_bullets[2] = param.temp_bullets[2];
379     param.user_defined_bullets[3] = param.temp_bullets[3];
380 }
381
382
383 void FormDocument::cancel()
384 {
385     // this avoids confusion when reopening
386     BufferParams & param = lv_->buffer()->params;
387     param.temp_bullets[0] = param.user_defined_bullets[0];
388     param.temp_bullets[1] = param.user_defined_bullets[1];
389     param.temp_bullets[2] = param.user_defined_bullets[2];
390     param.temp_bullets[3] = param.user_defined_bullets[3];
391 }
392
393
394 void FormDocument::update()
395 {
396     if (!dialog_)
397         return;
398
399     checkReadOnly();
400
401     BufferParams const & params = lv_->buffer()->params;
402
403     class_update(params);
404     paper_update(params);
405     language_update(params);
406     options_update(params);
407     bullets_update(params);
408 }
409
410
411 void FormDocument::class_update(BufferParams const & params)
412 {
413     LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
414
415     for( int i = 0; i < dialog_->classesCO->count(); i++ )
416       if( dialog_->classesCO->text( i ) == textclasslist.DescOfClass( params.textclass ).c_str() )
417         dialog_->classesCO->setCurrentItem( i );
418
419     for( int i = 0; i < dialog_->fontsCO->count(); i++ )
420       if( dialog_->fontsCO->text( i ) == params.fonts.c_str() )
421         dialog_->fontsCO->setCurrentItem( i );
422
423     dialog_->fontSizeCO->clear();
424     dialog_->fontSizeCO->insertItem( _("default") );
425     dialog_->fontSizeCO->insertStringList( QStringList::split( "|", tclass.opt_fontsize().c_str() ) );
426     for( int i = 0; i < dialog_->fontSizeCO->count(); i++ )
427       if( dialog_->fontSizeCO->text( i ) ==
428           tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2)
429         dialog_->fontSizeCO->setCurrentItem( i );
430
431     dialog_->pagestyleCO->clear();
432     dialog_->pagestyleCO->insertItem( _("default") );
433     dialog_->pagestyleCO->insertStringList( QStringList::split( "|", tclass.opt_pagestyle().c_str() ) );
434     for( int i = 0; i < dialog_->pagestyleCO->count(); i++ )
435       if( dialog_->pagestyleCO->text( i ) ==
436           tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2)
437         dialog_->pagestyleCO->setCurrentItem( i );
438
439     if (params.paragraph_separation == BufferParams::PARSEP_INDENT) {
440       dialog_->indentRB->setChecked( true );
441       dialog_->skipRB->setChecked( false );
442     } else {
443       dialog_->skipRB->setChecked( true );
444       dialog_->indentRB->setChecked( false );
445     }
446     switch (params.getDefSkip().kind()) {
447     case VSpace::SMALLSKIP: 
448       dialog_->defaultSkipCO->setCurrentItem( 0 );
449         break;
450     case VSpace::MEDSKIP: 
451       dialog_->defaultSkipCO->setCurrentItem( 1 );
452         break;
453     case VSpace::BIGSKIP: 
454       dialog_->defaultSkipCO->setCurrentItem( 2 );
455         break;
456     case VSpace::LENGTH: 
457       dialog_->defaultSkipCO->setCurrentItem( 3 );
458       dialog_->defaultSkipED->setText( params.getDefSkip().asLyXCommand().c_str() );
459         break;
460     default:
461       dialog_->defaultSkipCO->setCurrentItem( 1 );
462         break;
463     }
464
465     if( params.sides == 2 ) {
466       dialog_->twoSidesRB->setChecked( true );
467       dialog_->oneSideRB->setChecked( false );
468     } else {
469       dialog_->twoSidesRB->setChecked( false );
470       dialog_->oneSideRB->setChecked( true );
471     }
472
473     if( params.columns == 2 ) {
474       dialog_->twoColumnsRB->setChecked( true );
475       dialog_->oneColumnRB->setChecked( false );
476     } else {
477       dialog_->twoColumnsRB->setChecked( false );
478       dialog_->oneColumnRB->setChecked( true );
479     }
480
481     dialog_->spacingED->setText( "" );
482     switch (params.spacing.getSpace()) {
483     case Spacing::Default: // nothing bad should happen with this
484     case Spacing::Single:
485       // \singlespacing
486       dialog_->spacingCO->setCurrentItem( 0 );
487       break;
488     case Spacing::Onehalf:
489       // \onehalfspacing
490       dialog_->spacingCO->setCurrentItem( 1 );
491       break;
492     case Spacing::Double:
493       // \doublespacing
494       dialog_->spacingCO->setCurrentItem( 2 );
495       break;
496     case Spacing::Other:
497       {
498         dialog_->spacingCO->setCurrentItem( 3 );
499         QString sval;
500         sval.sprintf("%g",params.spacing.getValue()); 
501         dialog_->spacingED->setText( sval );
502         break;
503       }
504     }
505     if (!params.options.empty())
506       dialog_->extraOptionsED->setText( params.options.c_str());
507     else
508       dialog_->extraOptionsED->setText( "" );
509 }
510
511
512 void FormDocument::language_update(BufferParams const & params)
513 {
514     for( int i = 0; i < dialog_->languageCO->count(); i++ )
515       if( dialog_->languageCO->text( i ) == params.language->lang().c_str() )
516         dialog_->languageCO->setCurrentItem( i );
517     
518
519     for( int i = 0; i < dialog_->encodingCO->count(); i++ )
520       if( dialog_->encodingCO->text( i ) == params.inputenc.c_str() )
521         dialog_->encodingCO->setCurrentItem( i );
522
523     dialog_->quoteStyleTypeCO->setCurrentItem( params.quotes_language );
524
525     if( params.quotes_times == InsetQuotes::SingleQ ) {
526       dialog_->quoteStyleSingleRB->setChecked( true );
527       dialog_->quoteStyleDoubleRB->setChecked( false );
528     } else {
529       dialog_->quoteStyleSingleRB->setChecked( false );
530       dialog_->quoteStyleDoubleRB->setChecked( true );
531     }
532 }
533
534
535 void FormDocument::options_update(BufferParams const & params)
536 {
537     for( int i = 0; i < dialog_->psDriverCO->count(); i++ )
538       if( dialog_->psDriverCO->text( i ) == params.graphicsDriver.c_str() )
539         dialog_->psDriverCO->setCurrentItem( i );
540
541     dialog_->amsMathCB->setChecked( params.use_amsmath );
542     dialog_->sectionNumberDepthSB->setValue( params.secnumdepth );
543     dialog_->tocDepthSB->setValue( params.tocdepth );
544
545     if (!params.float_placement.empty())
546       dialog_->floatPlacementED->setText( params.float_placement.c_str());
547     else
548       dialog_->floatPlacementED->setText( "" );
549 }
550
551
552 void FormDocument::paper_update(BufferParams const & params)
553 {
554     dialog_->papersizeCO->setCurrentItem( params.papersize2 );
555     dialog_->specialCO->setCurrentItem( params.paperpackage );
556     dialog_->CheckBox1->setChecked( params.use_geometry );
557     
558     if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
559       dialog_->landscapeRB->setChecked( true );
560       dialog_->portraitRB->setChecked( false );
561     } else {
562       dialog_->landscapeRB->setChecked( false );
563       dialog_->portraitRB->setChecked( true );
564     }
565
566     dialog_->customWidthED->setText( params.paperwidth.c_str());
567     dialog_->customHeightED->setText( params.paperheight.c_str());
568     dialog_->marginLeftED->setText( params.leftmargin.c_str());
569     dialog_->marginTopED->setText( params.topmargin.c_str());
570     dialog_->marginRightED->setText( params.rightmargin.c_str());
571     dialog_->marginBottomED->setText( params.bottommargin.c_str());
572     dialog_->headheightED->setText( params.headheight.c_str());
573     dialog_->headsepED->setText( params.headsep.c_str());
574     dialog_->footskipED->setText( params.footskip.c_str());
575     dialog_->papersizeCO->setFocus();
576 }
577
578
579 void FormDocument::bullets_update(BufferParams const & params)
580 {
581     if (lv_->buffer()->isLinuxDoc()) {
582       dialog_->bulletTypeBG->setEnabled( false );
583       dialog_->bulletDepth1PB->setEnabled( false );
584       dialog_->bulletDepth2PB->setEnabled( false );
585       dialog_->bulletDepth3PB->setEnabled( false );
586       dialog_->bulletDepth4PB->setEnabled( false );
587       dialog_->bulletSizeCO->setEnabled( false );
588       dialog_->latexED->setEnabled( false );
589       return;
590     } else {
591       dialog_->bulletTypeBG->setEnabled( true );
592       dialog_->bulletDepth1PB->setEnabled( true );
593       dialog_->bulletDepth2PB->setEnabled( true );
594       dialog_->bulletDepth3PB->setEnabled( true );
595       dialog_->bulletDepth4PB->setEnabled( true );
596       dialog_->bulletSizeCO->setEnabled( true );
597       dialog_->latexED->setEnabled( true );
598     }
599     if (lv_->buffer()->isReadonly()) {
600       dialog_->bulletTypeBG->setEnabled( false );
601       dialog_->bulletSizeCO->setEnabled( false );
602       dialog_->latexED->setEnabled( false );
603     } else {
604       dialog_->bulletTypeBG->setEnabled( true );
605       dialog_->bulletSizeCO->setEnabled( true );
606       dialog_->latexED->setEnabled( true );
607     }
608
609     dialog_->bulletDepth1PB->setOn( true );
610     dialog_->latexED->setText( params.user_defined_bullets[0].getText().c_str());
611     dialog_->bulletSizeCO->setCurrentItem( params.user_defined_bullets[0].getSize() + 1);
612     dialog_->bulletStandardPB->setOn( false );
613     dialog_->bulletMathsPB->setOn( false );
614     dialog_->bulletDing1PB->setOn( false );
615     dialog_->bulletDing2PB->setOn( false );
616     dialog_->bulletDing3PB->setOn( false );
617     dialog_->bulletDing4PB->setOn( false );
618     switch( params.user_defined_bullets[0].getFont() ) {
619     case 0:
620       dialog_->bulletStandardPB->setOn( true );
621       break;
622     case 1:
623       dialog_->bulletMathsPB->setOn( true );
624       break;
625     case 2:
626       dialog_->bulletDing1PB->setOn( true );
627       break;
628     case 3:
629       dialog_->bulletDing2PB->setOn( true );
630       break;
631     case 4:
632       dialog_->bulletDing3PB->setOn( true );
633       break;
634     case 5:
635       dialog_->bulletDing4PB->setOn( true );
636       break;
637     default:
638       // should not happen
639       dialog_->bulletStandardPB->setOn( true );
640     }
641 }
642
643
644 void FormDocument::free()
645 {
646     if (dialog_) {
647         hide();
648         delete dialog_;
649         dialog_ = 0;
650     }
651 }
652
653
654 void FormDocument::checkReadOnly()
655 {
656     if (bc_.readOnly(lv_->buffer()->isReadonly())) {
657       dialog_->classesCO->setEnabled( false );
658       dialog_->languageCO->setEnabled( false );
659       dialog_->warningLA->setText( _("Document is read-only."
660                                      " No changes to layout permitted."));
661       dialog_->warningLA->show();
662     } else {
663       dialog_->classesCO->setEnabled( true );
664       dialog_->languageCO->setEnabled( true );
665       dialog_->warningLA->hide();
666     }   
667 }
668
669
670 void FormDocument::checkMarginValues()
671 {
672   const int allEmpty = 
673     dialog_->marginTopED->text().isEmpty() &&
674     dialog_->marginBottomED->text().isEmpty() &&
675     dialog_->marginLeftED->text().isEmpty() &&
676     dialog_->marginRightED->text().isEmpty() &&
677     dialog_->headheightED->text().isEmpty() &&
678     dialog_->headsepED->text().isEmpty() &&
679     dialog_->footskipED->text().isEmpty() &&
680     dialog_->customWidthED->text().isEmpty() &&
681     dialog_->customHeightED->text().isEmpty();
682     if (!allEmpty)
683       dialog_->CheckBox1->setChecked( true );
684 }
685
686 bool FormDocument::checkDocumentInput(QWidget* w)
687 {
688     string str;
689     char val;
690     bool ok = true;
691     QString input;
692     
693     checkMarginValues();
694     if (w == dialog_->papersizeCO) {
695         val = dialog_->papersizeCO->currentItem();
696
697         if (val == BufferParams::VM_PAPER_DEFAULT) {
698           dialog_->CheckBox1->setChecked( false );
699             checkMarginValues();
700         } else {
701             if ((val != BufferParams::VM_PAPER_USLETTER) &&
702                 (val != BufferParams::VM_PAPER_USLEGAL) &&
703                 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
704                 (val != BufferParams::VM_PAPER_A4) &&
705                 (val != BufferParams::VM_PAPER_A5) &&
706                 (val != BufferParams::VM_PAPER_B5)) {
707               dialog_->CheckBox1->setChecked( true );
708             }
709             dialog_->specialCO->setCurrentItem( BufferParams::PACKAGE_NONE );
710         }
711     } else if (w == dialog_->specialCO ) {
712       val = dialog_->specialCO->currentItem();
713       if (val != BufferParams::PACKAGE_NONE) {
714         dialog_->papersizeCO->setCurrentItem( BufferParams::VM_PAPER_DEFAULT );
715         dialog_->CheckBox1->setChecked( false );
716       }
717     } else if (w == dialog_->spacingED) {
718         input = dialog_->spacingED->text();
719         if (input.isEmpty()) {
720           dialog_->spacingCO->setCurrentItem( 0 );
721         } else {
722           dialog_->spacingCO->setCurrentItem( 3 );
723         }
724     }
725     // this has to be all out of if/elseif because it has to deactivate
726     // the document buttons and so the whole stuff has to be tested again.
727     str = dialog_->customWidthED->text();
728     ok = ok && (str.empty() || isValidLength(str));
729     str = dialog_->customHeightED->text();
730     ok = ok && (str.empty() || isValidLength(str));
731     str = dialog_->marginLeftED->text();
732     ok = ok && (str.empty() || isValidLength(str));
733     str = dialog_->marginRightED->text();
734     ok = ok && (str.empty() || isValidLength(str));
735     str = dialog_->marginTopED->text();
736     ok = ok && (str.empty() || isValidLength(str));
737     str = dialog_->marginBottomED->text();
738     ok = ok && (str.empty() || isValidLength(str));
739     str = dialog_->headheightED->text();
740     ok = ok && (str.empty() || isValidLength(str));
741     str = dialog_->headsepED->text();
742     ok = ok && (str.empty() || isValidLength(str));
743     str = dialog_->footskipED->text();
744     ok = ok && (str.empty() || isValidLength(str));
745     // "Synchronize" the choice and the input field, so that it
746     // is impossible to commit senseless data.
747     input = dialog_->defaultSkipED->text();
748     if (w == dialog_->defaultSkipED) {
749         if (input.isEmpty()) {
750           dialog_->defaultSkipCO->setCurrentItem( 1 );
751         } else if (isValidGlueLength (input.latin1())) {
752           dialog_->defaultSkipCO->setCurrentItem( 3 );
753         } else {
754           dialog_->defaultSkipCO->setCurrentItem( 3 );
755             ok = false;
756         }
757     } else {
758         if (!input.isEmpty() && !isValidGlueLength(input.latin1()))
759             ok = false;
760     }
761     if(( dialog_->defaultSkipCO->currentItem() == 3 ) && input.isEmpty() )
762         ok = false;
763     else if( dialog_->defaultSkipCO->currentItem() != 3 )
764       dialog_->defaultSkipED->setText( "" );
765
766     input = dialog_->spacingED->text();
767     if( ( dialog_->spacingCO->currentItem() == 3 ) && input.isEmpty() )
768         ok = false;
769     else if( dialog_->spacingCO->currentItem() != 3 )
770       dialog_->spacingED->setText( "" );
771     return ok;
772 }
773
774
775 void FormDocument::choiceBulletSize()
776 {
777     BufferParams & param = lv_->buffer()->params;
778
779     // convert from 0-5 range to -1-4 
780     param.temp_bullets[currentBulletDepth].setSize(dialog_->bulletSizeCO->currentItem() - 1);
781     dialog_->latexED->setText( param.temp_bullets[currentBulletDepth].getText().c_str());
782 }
783
784
785 void FormDocument::inputBulletLaTeX()
786 {
787     BufferParams & param = lv_->buffer()->params;
788
789     param.temp_bullets[currentBulletDepth].
790         setText(dialog_->latexED->text().latin1() );
791 }
792
793
794 void FormDocument::bulletDepth(int depth)
795 {
796     /* Should I do the following:                                 */
797     /*  1. change to the panel that the current bullet belongs in */
798     /*  2. show that bullet as selected                           */
799     /*  3. change the size setting to the size of the bullet in Q.*/
800     /*  4. display the latex equivalent in the latex box          */
801     /*                                                            */
802     /* I'm inclined to just go with 3 and 4 at the moment and     */
803     /* maybe try to support the others later                      */
804     BufferParams & param = lv_->buffer()->params;
805
806     // reset on right mouse button not supported in KLyX
807     // right mouse button resets to default
808     param.temp_bullets[depth] = ITEMIZE_DEFAULTS[depth];
809     dialog_->latexED->setText( param.temp_bullets[depth].getText().c_str());
810     dialog_->bulletSizeCO->setCurrentItem( param.temp_bullets[depth].getSize() + 1 );
811
812     currentBulletDepth = depth;
813 }
814
815
816 // PENDING(kalle) Call this.
817 void FormDocument::setBulletPics()
818 {
819   QPixmap* currentpix = 0;
820   if( dialog_->bulletStandardPB->isOn() ) {
821     currentpix = standardpix;
822     currentBulletPanel = 0;
823   } else if( dialog_->bulletMathsPB->isOn() ) {
824     currentpix = amssymbpix;
825     currentBulletPanel = 1;
826   } else if( dialog_->bulletDing1PB->isOn() ) {
827     currentpix = psnfss1pix;
828     currentBulletPanel = 2;
829   } else if( dialog_->bulletDing2PB->isOn() ) {
830     currentpix = psnfss2pix;
831     currentBulletPanel = 3;
832   } else if( dialog_->bulletDing3PB->isOn() ) {
833     currentpix = psnfss3pix;
834     currentBulletPanel = 4;
835   } else if( dialog_->bulletDing4PB->isOn() ) {
836     currentpix = psnfss4pix;
837     currentBulletPanel = 5;
838   }
839
840   for( int x = 0; x < 6; x++ )
841     for( int y = 0; y < 6; y++ ) {
842       bulletpics[x*6+y].resize( 44, 29 );
843       bitBlt( &bulletpics[x*6+y], 0, 0, currentpix, x*44, y*29, 44, 29 );
844     }
845
846   // This is disgusting, but the only way since the designer does not
847   // support widget arrays.
848   dialog_->bullet00PB->setPixmap( bulletpics[0] );
849   dialog_->bullet01PB->setPixmap( bulletpics[1] );
850   dialog_->bullet02PB->setPixmap( bulletpics[2] );
851   dialog_->bullet03PB->setPixmap( bulletpics[3] );
852   dialog_->bullet04PB->setPixmap( bulletpics[4] );
853   dialog_->bullet05PB->setPixmap( bulletpics[5] );
854   dialog_->bullet10PB->setPixmap( bulletpics[6] );
855   dialog_->bullet11PB->setPixmap( bulletpics[7] );
856   dialog_->bullet12PB->setPixmap( bulletpics[8] );
857   dialog_->bullet13PB->setPixmap( bulletpics[9] );
858   dialog_->bullet14PB->setPixmap( bulletpics[10] );
859   dialog_->bullet15PB->setPixmap( bulletpics[11] );
860   dialog_->bullet20PB->setPixmap( bulletpics[12] );
861   dialog_->bullet21PB->setPixmap( bulletpics[13] );
862   dialog_->bullet22PB->setPixmap( bulletpics[14] );
863   dialog_->bullet23PB->setPixmap( bulletpics[15] );
864   dialog_->bullet24PB->setPixmap( bulletpics[16] );
865   dialog_->bullet25PB->setPixmap( bulletpics[17] );
866   dialog_->bullet30PB->setPixmap( bulletpics[18] );
867   dialog_->bullet31PB->setPixmap( bulletpics[19] );
868   dialog_->bullet32PB->setPixmap( bulletpics[20] );
869   dialog_->bullet33PB->setPixmap( bulletpics[21] );
870   dialog_->bullet34PB->setPixmap( bulletpics[22] );
871   dialog_->bullet35PB->setPixmap( bulletpics[23] );
872   dialog_->bullet40PB->setPixmap( bulletpics[24] );
873   dialog_->bullet41PB->setPixmap( bulletpics[25] );
874   dialog_->bullet42PB->setPixmap( bulletpics[26] );
875   dialog_->bullet43PB->setPixmap( bulletpics[27] );
876   dialog_->bullet44PB->setPixmap( bulletpics[28] );
877   dialog_->bullet45PB->setPixmap( bulletpics[29] );
878   dialog_->bullet50PB->setPixmap( bulletpics[30] );
879   dialog_->bullet51PB->setPixmap( bulletpics[31] );
880   dialog_->bullet52PB->setPixmap( bulletpics[32] );
881   dialog_->bullet53PB->setPixmap( bulletpics[33] );
882   dialog_->bullet54PB->setPixmap( bulletpics[34] );
883   dialog_->bullet55PB->setPixmap( bulletpics[35] );
884 }
885
886
887 void FormDocument::bulletBMTable(int button)
888 {
889     /* handle the user input by setting the current bullet depth's pixmap */
890     /* to that extracted from the current chosen position of the BMTable  */
891     /* Don't forget to free the button's old pixmap first.                */
892
893     BufferParams & param = lv_->buffer()->params;
894
895     /* try to keep the button held down till another is pushed */
896     /*  fl_set_bmtable(ob, 1, bmtable_button); */
897     param.temp_bullets[currentBulletDepth].setFont(currentBulletPanel);
898     param.temp_bullets[currentBulletDepth].setCharacter(button);
899     dialog_->latexED->setText( param.temp_bullets[currentBulletDepth].getText().c_str());
900 }
901
902
903 void FormDocument::checkChoiceClass(QComboBox* cb)
904 {
905     if (!cb)
906         cb = dialog_->classesCO;
907
908     ProhibitInput(lv_->view());
909     int tc;
910     string tct;
911
912     tc = cb->currentItem();
913     tct = cb->currentText();
914
915     if (textclasslist.Load(tc)) {
916         if (AskQuestion(_("Should I set some parameters to"), tct,
917                         _("the defaults of this document class?"))) {
918             BufferParams & params = lv_->buffer()->params;
919
920             params.textclass = tc;
921             params.useClassDefaults();
922             UpdateLayoutDocument(params);
923         }
924     } else {
925         // unable to load new style
926         WriteAlert(_("Conversion Errors!"),
927                    _("Unable to switch to new document class."),
928                    _("Reverting to original document class."));
929
930         dialog_->classesCO->setCurrentItem(
931                                            lv_->buffer()->params.textclass );
932     }
933     AllowInput(lv_->view());
934 }
935
936
937 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
938 {
939     if (!dialog_)
940         return;
941
942     checkReadOnly();
943     class_update(params);
944     paper_update(params);
945     language_update(params);
946     options_update(params);
947     bullets_update(params);
948 }