3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
6 * \author Kalle Dalheimer <kalle@klaralvdalens-datakonsult.se>
12 #pragma implementation
15 #include "QDocument.h"
16 #include "QDocumentDialog.h"
18 #include "lyx_gui_misc.h"
22 #include "tex-strings.h"
23 #include "bufferparams.h"
24 #include "insets/insetquotes.h"
26 #include "support/filetools.h"
28 #include "BufferView.h"
31 #include "CutAndPaste.h"
32 #include "bufferview_funcs.h"
34 #include <qcombobox.h>
35 #include <qlineedit.h>
36 #include <qradiobutton.h>
39 using Liason::setMinibuffer;
42 typedef Qt2CB<ControlDocument, Qt2DB<QDocumentDialog> > base_class;
45 QDocument::QDocument(ControlDocument & c)
46 : base_class(c, _("Document Settings"))
51 QDocument::QDocument(LyXView *, Dialogs *)
57 void QDocument::build_dialog()
60 //dialog_.reset(new QDocumentDialog());
63 // Manage the restore, ok, apply, restore and cancel/close buttons
64 bc().setOK(dialog_->okPB);
65 bc().setApply(dialog_->applyPB);
66 bc().setCancel(dialog_->cancelPB);
67 bc().setRestore(dialog_->restorePB);
70 // the document paper page
71 QDocumentDialog * dialog = dialog_.get();
72 dialog->papersize2CO->insertItem( _( "Default" ) );
73 dialog->papersize2CO->insertItem( _( "Custom" ) );
74 dialog->papersize2CO->insertItem( _( "USletter" ) );
75 dialog->papersize2CO->insertItem( _( "USlegal" ) );
76 dialog->papersize2CO->insertItem( _( "USexecutive" ) );
77 dialog->papersize2CO->insertItem( _( "A3" ) );
78 dialog->papersize2CO->insertItem( _( "A4" ) );
79 dialog->papersize2CO->insertItem( _( "A5" ) );
80 dialog->papersize2CO->insertItem( _( "B3" ) );
81 dialog->papersize2CO->insertItem( _( "B4" ) );
82 dialog->papersize2CO->insertItem( _( "B5" ) );
84 dialog->paperPackageCO->insertItem( _( "None" ) );
85 dialog->paperPackageCO->insertItem( _( "A4 small Margins (only portrait)" ) );
86 dialog->paperPackageCO->insertItem( _( "A4 very small Margins (only portrait)" ) );
87 dialog->paperPackageCO->insertItem( _( "A4 very wide margins (only portrait)" ) );
89 bc().addReadOnly (dialog->paperPackageCO);
90 bc().addReadOnly (dialog->orientationBG);
91 bc().addReadOnly (dialog->portraitRB);
92 bc().addReadOnly (dialog->landscapeRB);
93 bc().addReadOnly (dialog->papersize2CO);
94 bc().addReadOnly (dialog->useGeometryCB);
95 bc().addReadOnly (dialog->customWidthED);
96 bc().addReadOnly (dialog->customHeightED);
97 bc().addReadOnly (dialog->topMarginED);
98 bc().addReadOnly (dialog->bottomMarginED);
99 bc().addReadOnly (dialog->leftMarginED);
100 bc().addReadOnly (dialog->rightMarginED);
101 bc().addReadOnly (dialog->headHeightED);
102 bc().addReadOnly (dialog->headSepED);
103 bc().addReadOnly (dialog->footSkipED);
106 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
107 cit != textclasslist.end(); ++cit) {
108 docClassCO->insertItem( (*cit).description().c_str() );
111 dialog->docSpacingCO->insertItem( _( "Single" ) );
112 dialog->docSpacingCO->insertItem( _( "OneHalf" ) );
113 dialog->docSpacingCO->insertItem( _( "Double" ) );
114 dialog->docSpacingCO->insertItem( _( "Other" ) );
116 dialog->docFontSizeCO->insertItem( _( "default" ) );
117 dialog->docFontSizeCO->insertItem( _( "10" ) );
118 dialog->docFontSizeCO->insertItem( _( "11" ) );
119 dialog->docFontSizeCO->insertItem( _( "12" ) );
120 for (int n=0; tex_fonts[n][0]; ++n) {
121 dialog->docFontsCO->insertItem( tex_fonts[n] );
124 dialog->docPagestyleCO->insertItem( _( "default" ) );
125 dialog->docPagestyleCO->insertItem( _( "empty" ) );
126 dialog->docPagestyleCO->insertItem( _( "plain" ) );
127 dialog->docPagestyleCO->insertItem( _( "headings" ) );
128 dialog->docPagestyleCO->insertItem( _( "fancy" ) );
130 dialog->docSkipCO->insertItem( _( "Smallskip" ) );
131 dialog->docSkipCO->insertItem( _( "Medskip" ) );
132 dialog->docSkipCO->insertItem( _( "Bigskip" ) );
133 dialog->docSkipCO->insertItem( _( "Length" ) );
135 bc().addReadOnly (dialog->docIndentRB);
136 bc().addReadOnly (dialog->docSkipRB);
138 bc().addReadOnly (dialog->docPagestyleCO);
139 bc().addReadOnly (dialog->docFontsCO);
140 bc().addReadOnly (dialog->docFontsizeCO);
141 bc().addReadOnly (dialog->docSidesOneRB);
142 bc().addReadOnly (dialog->docSidesTwoRB);
143 bc().addReadOnly (dialog->docColumnsOneRB);
144 bc().addReadOnly (dialog->docColumnsTwoRB);
145 bc().addReadOnly (dialog->docExtraED);
146 bc().addReadOnly (dialog->docSkipED);
147 bc().addReadOnly (dialog->docSkipCO);
148 bc().addReadOnly (dialog->docSpacingCO);
149 bc().addReadOnly (dialog->docSpacingED);
151 // the document language page
152 dialog->inputEncCO->insertItem( _( "default" ) );
153 dialog->inputEncCO->insertItem( _( "auto" ) );
154 dialog->inputEncCO->insertItem( _( "latin1" ) );
155 dialog->inputEncCO->insertItem( _( "latin2" ) );
156 dialog->inputEncCO->insertItem( _( "latin3" ) );
157 dialog->inputEncCO->insertItem( _( "latin4" ) );
158 dialog->inputEncCO->insertItem( _( "latin5" ) );
159 dialog->inputEncCO->insertItem( _( "latin9" ) );
160 dialog->inputEncCO->insertItem( _( "koi8-r" ) );
161 dialog->inputEncCO->insertItem( _( "koi8-u" ) );
162 dialog->inputEncCO->insertItem( _( "cp866" ) );
163 dialog->inputEncCO->insertItem( _( "cp1251" ) );
164 dialog->inputEncCO->insertItem( _( "iso88595" ) );
166 for (Languages::const_iterator cit = languages.begin();
167 cit != languages.end(); ++cit) {
168 dialog->languageCO->insertItem( (*cit).second.lang() );
171 dialog->quotesLanguageCO->insertItem( _( "``text''" ) );
172 dialog->quotesLanguageCO->insertItem( _( "''text''" ) );
173 dialog->quotesLanguageCO->insertItem( _( ",,text``" ) );
174 dialog->quotesLanguageCO->insertItem( _( ",,text''" ) );
175 dialog->quotesLanguageCO->insertItem( _( "«text»" ) );
176 dialog->quotesLanguageCO->insertItem( _( "»text«" ) );
178 bc().addReadOnly (dialog->inputEncCO);
180 // the document options page
181 dialog->secNumDepthSB->setRange( -2, 5 );
182 dialog->tocDepthSB->setRange( -1, 5 );
183 dialog->secNumDepthSB->setSteps( 1, 1 );
184 dialog->tocDepthSB->setRange( 1, 1 );
185 for (int n=0; tex_graphics[n][0]; ++n) {
186 dialog->postscriptDriverCO->insertItem( tex_graphics[n] );
189 bc().addReadOnly (dialog->secNumDepthSB);
190 bc().addReadOnly (dialog->tocDepthSB);
191 bc().addReadOnly (dialog->useAmsMathCB);
192 bc().addReadOnly (dialog->floatPlacementED);
193 bc().addReadOnly (dialog->postscriptDriverCO);
195 // the document bullets page
196 dialog->bulletSizeCO->insertItem( _( "default" ) );
197 dialog->bulletSizeCO->insertItem( _( "tiny" ) );
198 dialog->bulletSizeCO->insertItem( _( "script" ) );
199 dialog->bulletSizeCO->insertItem( _( "footnote" ) );
200 dialog->bulletSizeCO->insertItem( _( "small" ) );
201 dialog->bulletSizeCO->insertItem( _( "normal" ) );
202 dialog->bulletSizeCO->insertItem( _( "large" ) );
203 dialog->bulletSizeCO->insertItem( _( "Large" ) );
204 dialog->bulletSizeCO->insertItem( _( "LARGE" ) );
205 dialog->bulletSizeCO->insertItem( _( "huge" ) );
206 dialog->bulletSizeCO->insertItem( _( "Huge" ) );
208 dialog->bulletSizeCO->setCurrentItem( 0 );
209 dialog->bulletLatexED->setMaxLength( 80 );
211 bc().addReadOnly (dialog->bulletPanelBG);
212 bc().addReadOnly (dialog->bulletSizeCO);
213 bc().addReadOnly (dialog->bulletLatexED);
218 void QDocument::apply()
220 //if (!lv_->view()->available() || !dialog_.get())
224 bool redo = class_apply();
226 redo = language_apply() || redo;
227 redo = options_apply() || redo;
231 lv_->view()->redoCurrentBuffer();
233 lv_->buffer()->markDirty();
234 setMinibuffer(lv_, _("Document layout set"));
239 void QDocument::cancel()
242 // this avoids confusion when reopening
243 BufferParams & param = lv_->buffer()->params;
244 param.temp_bullets[0] = param.user_defined_bullets[0];
245 param.temp_bullets[1] = param.user_defined_bullets[1];
246 param.temp_bullets[2] = param.user_defined_bullets[2];
247 param.temp_bullets[3] = param.user_defined_bullets[3];
253 void QDocument::update_contents()
261 BufferParams const & params = lv_->buffer()->params;
263 class_update(params);
264 paper_update(params);
265 language_update(params);
266 options_update(params);
267 bullets_update(params);
273 bool QDocument::input( FL_OBJECT * ob, long data )
275 State cb = static_cast<State>( data );
278 case CHECKCHOICECLASS:
279 CheckChoiceClass(ob, 0);
281 case CHOICEBULLETSIZE:
282 ChoiceBulletSize(ob, 0);
284 case INPUTBULLETLATEX:
285 InputBulletLaTeX(ob, 0);
302 BulletBMTable(ob, 0);
310 case CHECKCHOICECLASS:
311 case CHOICEBULLETSIZE:
312 case INPUTBULLETLATEX:
314 return CheckDocumentInput(ob, 0);
323 void QDocument::ComboInputCB(int, void * v, Combox * combox)
325 QDocument * pre = static_cast<QDocument*>(v);
326 if (combox == pre->combo_doc_class.get())
327 pre->CheckChoiceClass(0, 0);
328 pre->bc().valid(pre->CheckDocumentInput(0,0));
331 bool QDocument::class_apply()
334 BufferParams ¶ms = lv_->buffer()->params;
336 // If default skip is a "Length" but there's no text in the
337 // input field, reset the kind to "Medskip", which is the default.
338 if( ( dialog_->docSkipCO->currentItem() == 3 ) &&
339 dialog_->docSkipED->text().isEmpty() )
340 dialog_->docSkipCO->setCurrentItem( 1 );
342 params.fonts = dialog_->docFontsCO->currentText();
343 params.fontsize = dialog_->docFontSizeCO->currentText();
344 params.pagestyle = dialog->docPagestyleCO->currentText();
346 unsigned int const new_class = dialog_->docClassCO->currentItem();
348 if (params.textclass != new_class) {
349 // try to load new_class
350 if (textclasslist.Load(new_class)) {
351 // successfully loaded
353 setMinibuffer(lv_, _("Converting document to new document class..."));
355 int ret = cap.SwitchLayoutsBetweenClasses(params.textclass, new_class,
356 lv_->buffer()->paragraph,
357 lv_->buffer()->params);
361 s = _("One paragraph couldn't be converted");
364 s += _(" paragraphs couldn't be converted");
366 Alert::alert(_("Conversion Errors!"),s,
367 _("into chosen document class"));
370 params.textclass = new_class;
372 // problem changing class -- warn user and retain old style
373 Alert::alert(_("Conversion Errors!"),
374 _("Errors loading new document class."),
375 _("Reverting to original document class."));
376 dialog_->docClassCO->setCurrentItem( params.textclass );
379 BufferParams::PARSEP tmpsep = params.paragraph_separation;
380 if( dialog_->_docIndentRB->isChecked() )
381 params.paragraph_separation = BufferParams::PARSEP_INDENT;
383 params.paragraph_separation = BufferParams::PARSEP_SKIP;
384 if (tmpsep != params.paragraph_separation)
387 VSpace tmpdefskip = params.getDefSkip();
388 switch( dialog_->docSkipCO->currentItem() ) {
390 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
393 params.setDefSkip(VSpace(VSpace::MEDSKIP));
396 params.setDefSkip(VSpace(VSpace::BIGSKIP));
400 (VSpace(LyXGlueLength(dialog_->docSkipED->text())));
402 // DocumentDefskipCB assures that this never happens
403 // ... so why is there code for it ?
405 params.setDefSkip(VSpace(VSpace::MEDSKIP));
408 if (!(tmpdefskip == params.getDefSkip()))
411 if( dialog_->docColumnsTwo->isChecked() )
415 if( dialog_->docSidesTwo->isChecked() )
416 params.sides = LyXTextClass::TwoSides;
418 params.sides = LyXTextClass::OneSide;
420 Spacing tmpSpacing = params.spacing;
421 switch( dialog_->docSpacingCO->currentItem() ) {
423 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
424 params.spacing.set(Spacing::Single);
427 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
428 params.spacing.set(Spacing::Onehalf);
431 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
432 params.spacing.set(Spacing::Double);
435 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
436 params.spacing.set(Spacing::Other,
437 dialog_->docSpacingED->text() );
440 if (tmpSpacing != params.spacing)
443 params.options = docExtraED->text();
449 void QDocument::paper_apply()
451 BufferParams & params = lv_->buffer()->params;
454 static_cast<char>(dialog_->papersize2CO->currentItem());
455 params.paperpackage =
456 static_cast<char>(dialog_->paperPackageCO->currentItem() );
457 params.use_geometry = dialog_->useGeometryCB->isChecked();
458 if (dialog_->landscapeRB->isChecked() )
459 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
461 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
462 params.paperwidth = dialog_->customWidthED->text();
463 params.paperheight = dialog_->customHeightED->text();
464 params.leftmargin = dialog_->leftMarginED->text();
465 params.topmargin = dialog_->topMarginED->text();
466 params.rightmargin = dialog_->rightMarginED->text();
467 params.bottommargin = dialog_->bottomMarginED->text();
468 params.headheight = dialog_->headHeightED->text();
469 params.headsep = dialog_->headSepED->text();
470 params.footskip = dialog_->footSkipED->text();
471 lv_->buffer()->setPaperStuff();
475 bool QDocument::language_apply()
477 BufferParams & params = lv_->buffer()->params;
478 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
481 switch (dialog_->quotesLanguageCO->currentItem() ) {
483 lga = InsetQuotes::EnglishQ;
486 lga = InsetQuotes::SwedishQ;
489 lga = InsetQuotes::GermanQ;
492 lga = InsetQuotes::PolishQ;
495 lga = InsetQuotes::FrenchQ;
498 lga = InsetQuotes::DanishQ;
501 params.quotes_language = lga;
502 if (dialog_->singleRB->isChecked() )
503 params.quotes_times = InsetQuotes::SingleQ;
505 params.quotes_times = InsetQuotes::DoubleQ;
507 Language const * old_language = params.language;
508 Language const * new_language =
509 languages.getLanguage(dialog_->languageCO->currentItem() );
511 new_language = default_language;
513 if (old_language != new_language
514 && old_language->RightToLeft() == new_language->RightToLeft()
515 && !lv_->buffer()->isMultiLingual())
516 lv_->buffer()->ChangeLanguage(old_language, new_language);
518 if (old_language != new_language)
521 params.language = new_language;
522 params.inputenc = dialog_->inputEncCO->currentText();
528 bool QDocument::options_apply()
530 BufferParams & params = lv_->buffer()->params;
533 params.graphicsDriver =
534 dialog_->postscriptDriverCO->currentText();
535 params.use_amsmath = dialog_->useAmsMathCB->isChecked();
537 int tmpchar = int(dialog_->secNumDepth->value() );
538 if (params.secnumdepth != tmpchar)
540 params.secnumdepth = tmpchar;
542 params.tocdepth = int(dialog_->tocDepth->value() );
544 params.float_placement =
545 dialog_->floatPlacementED->text();
551 void QDocument::bullets_apply()
553 /* update the bullet settings */
554 BufferParams & param = lv_->buffer()->params;
556 // a little bit of loop unrolling
557 param.user_defined_bullets[0] = param.temp_bullets[0];
558 param.user_defined_bullets[1] = param.temp_bullets[1];
559 param.user_defined_bullets[2] = param.temp_bullets[2];
560 param.user_defined_bullets[3] = param.temp_bullets[3];
564 void QDocument::class_update(BufferParams const & params)
569 LyXTextClass const & tclass = textclasslist[params.textclass];
571 combo_doc_class->select_text(
572 textclasslist.DescOfClass(params.textclass));
573 Qt2Helper::setCurrentComboItem( dialog_->docFonts, params.fonts.c_str() );
574 dialog_->docFontSizeCO->clear();
575 dialog_->docFontSizeCO->insertItem( _( "default" ) );
576 dialog_->docFontSizeCO->insertItem( tclass.opt_fontsize().c_str());
577 dialog_->docFontSizeCO->setCurrentItem( tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+1);
578 dialog_->docPagestyleCO->clear();
579 dialog_->docPagestyleCO->insertItem( _( "default" ) );
580 dialog_->docPagestyleCO->insertItem( tclass.opt_pagestyle().c_str());
581 dialog_->docPagestyleCO->setCurrentItem( tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+1);
582 dialog_->docIndentRB->setChecked( false );
583 dialog_->docSkipRB->setChecked( false );
584 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
585 dialog_->docIndentRB->setChecked( true );
587 dialog_->docSkipRB->setChecked( true );
588 switch (params.getDefSkip().kind()) {
589 case VSpace::SMALLSKIP:
590 dialog_->docSkipCO->setCurrentItem( 0 );
592 case VSpace::MEDSKIP:
593 dialog_->docSkipCO->setCurrentItem( 1 );
595 case VSpace::BIGSKIP:
596 dialog_->docSkipCO->setCurrentItem( 2 );
599 dialog_->docSkipCO->setCurrentItem( 3 );
600 dialog_->docSkipED->setText( params.getDefSkip().asLyXCommand().c_str());
603 dialog_->docSkipCO->setCurrentItem( 1 );
606 dialog_->docSidesOneRB->setChecked( false );
607 dialog_->docSidesTwoRB->setChecked( false );
608 if (params.sides == LyXTextClass::TwoSides)
609 dialog_->docSidesTwo->setChecked( true );
611 dialog_->docSidesOne->setChecked( true );
612 dialog_->docColumnsOneRB->setChecked( false );
613 dialog_->docColumnsTwoRB->setChecked( false );
614 if (params.columns == 2)
615 dialog_->docColumnsTwoRB->setChecked( true );
617 dialog_->docColumnsOneRB->setChecked( true );
618 dialog_->docSpacingED->setText( "" );
619 switch (params.spacing.getSpace()) {
620 case Spacing::Default: // nothing bad should happen with this
621 case Spacing::Single:
623 dialog_->docSpacingCO->setCurrentItem( 0 );
625 case Spacing::Onehalf:
627 dialog_->docSpacingCO->setCurrentItem( 1 );
629 case Spacing::Double:
631 dialog_->docSpacingCO->setCurrentItem( 2 );
635 dialog_->docSpacingCO->setCurrentItem( 3 );
637 sval.sprintf("%g",params.spacing.getValue());
638 dialog_->docSpacingED->setText( sval );
642 if (!params.options.empty())
643 dialog_->docExtraED->setText(, params.options.c_str());
645 dialog_->docExtraED->setText( "" );
649 void QDocument::language_update(BufferParams const & params)
651 if (!language_.get())
654 Qt2Helper::setCurrentItemText( dialog_->languageCO, params.language->lang() );
655 Qt2Helper::setCurrentItemText( dialog_->inputEncCO, params.inputenc.c_str() );
656 dialog_->quotesLanguageCO->setCurrentItem( params.quotes_language );
657 dialog_->singleRB->setChecked( false );
658 dialog_->doubleRB->setChecked( false );
659 if (params.quotes_times == InsetQuotes::SingleQ)
660 dialog_->singleRB->setChecked( true );
662 dialog_->doubleRB->setChecked( true );
666 void QDocument::options_update(BufferParams const & params)
671 Qt2Helper::setCurrentItemText( dialog_->postscriptDriverCO,
672 params.graphicsDriver.c_str());
673 dialog_->useAmsMathCB->setChecked( params.use_amsmath );
674 dialog_->secNumDepthSB->setValue( params.secnumdepth );
675 dialog_->setTocDepthSB->setValue( params.tocdepth );
676 if (!params.float_placement.empty())
677 dialog_->floatPlacementED->setText( params.float_placement.c_str());
679 dialog_->floatPlacementED->setText( "" );
683 void QDocument::paper_update(BufferParams const & params)
688 dialog_->papersize2CO->setCurrentItem( params.papersize2 );
689 dialog_->paperPackageCO->setCurrentItem( params.paperpackage );
690 dialog_->useGeometryCB->setChecked( params.use_geometry );
691 dialog_->portraitRB->setChecked( false );
692 dialog_->landscapeRB->setChecked( false );
693 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
694 dialog_->landscapeRB->setChecked( true );
696 dialog_->portraitRB->setChecked( true );
697 dialog_->customWidthED->setText( params.paperwidth.c_str());
698 dialog_->customHeightED->setText( params.paperheight.c_str());
699 dialog_->leftMarginED->setText( params.leftmargin.c_str());
700 dialog_->topMarginED->setText( params.topmargin.c_str());
701 dialog_->rightMarginED->setText( params.rightmargin.c_str());
702 dialog_->bottomMarginED->setText( params.bottommargin.c_str());
703 dialog_->headHeightED->setText( params.headheight.c_str());
704 dialog_->headSepED->setText( params.headsep.c_str());
705 dialog_->footSkipED->setText( params.footskip.c_str());
706 dialog_->papersize2CO->setFocus();
710 void QDocument::bullets_update(BufferParams const & params)
712 bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
713 setEnabled(fbullet, !isLinuxDoc);
715 if (isLinuxDoc) return;
717 dialog_->bulletDepth1RB->setChecked( true );
718 dialog_->bulletLatexED->setText( params.user_defined_bullets[0].getText().c_str());
719 dialog_->bulletSizeCO->setCurrentItem( params.user_defined_bullets[0].getSize() + 1);
723 void QDocument::checkReadOnly()
725 if (bc().readOnly(lv_->buffer()->isReadonly())) {
726 dialog_->docClassCO->setEnabled( false );
727 dialog_->languageCO->setEnabled( false );
728 dialog_->warningLA->setText( _("Document is read-only."
729 " No changes to layout permitted."));
730 dialog_->warningLA->show();
732 dialog_->docClassCO->setEnabled( true );
733 dialog_->languageCO->setEnabled( true );
734 dialog_->warningLA->hide();
739 void QDocument::checkMarginValues()
741 bool const not_empty =
742 !dialog_->topMarginED->text().isEmpty() ||
743 !dialog_->bottomMarginED->text().isEmpty() ||
744 !dialog_->leftMarginED->text().isEmpty() ||
745 !dialog_->rightMarginED->text().isEmpty() ||
746 !dialog_->headHeightED->text().isEmpty() ||
747 !dialog_->headSepED->text().isEmpty() ||
748 !dialog_->footSkipED->text().isEmpty() ||
749 !dialog_->customWidthED->text().isEmpty() ||
750 !dialog_->customHeightED->text().isEmpty();
752 dialog_->useGeometryCB->setChecked( true );
755 #ifdef I_SUPPOSE_THIS_NEEDS_TO_FIXED
756 bool QDocument::CheckDocumentInput(FL_OBJECT * ob, long)
764 if (ob == paper_->choice_papersize2) {
765 val = fl_get_choice(paper_->choice_papersize2)-1;
766 if (val == BufferParams::VM_PAPER_DEFAULT) {
767 fl_set_button(paper_->push_use_geometry, 0);
770 if ((val != BufferParams::VM_PAPER_USLETTER) &&
771 (val != BufferParams::VM_PAPER_USLEGAL) &&
772 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
773 (val != BufferParams::VM_PAPER_A4) &&
774 (val != BufferParams::VM_PAPER_A5) &&
775 (val != BufferParams::VM_PAPER_B5)) {
776 fl_set_button(paper_->push_use_geometry, 1);
778 fl_set_choice(paper_->choice_paperpackage,
779 BufferParams::PACKAGE_NONE + 1);
781 } else if (ob == paper_->choice_paperpackage) {
782 val = fl_get_choice(paper_->choice_paperpackage)-1;
783 if (val != BufferParams::PACKAGE_NONE) {
784 fl_set_choice(paper_->choice_papersize2,
785 BufferParams::VM_PAPER_DEFAULT + 1);
786 fl_set_button(paper_->push_use_geometry, 0);
788 } else if (ob == class_->input_doc_spacing) {
789 input = fl_get_input(class_->input_doc_spacing);
791 fl_set_choice (class_->choice_doc_spacing, 1);
793 fl_set_choice(class_->choice_doc_spacing, 4);
796 // this has to be all out of if/elseif because it has to deactivate
797 // the document buttons and so the whole stuff has to be tested again.
798 str = fl_get_input(paper_->input_custom_width);
799 ok = ok && (str.empty() || isValidLength(str));
800 str = fl_get_input(paper_->input_custom_height);
801 ok = ok && (str.empty() || isValidLength(str));
802 str = fl_get_input(paper_->input_left_margin);
803 ok = ok && (str.empty() || isValidLength(str));
804 str = fl_get_input(paper_->input_right_margin);
805 ok = ok && (str.empty() || isValidLength(str));
806 str = fl_get_input(paper_->input_top_margin);
807 ok = ok && (str.empty() || isValidLength(str));
808 str = fl_get_input(paper_->input_bottom_margin);
809 ok = ok && (str.empty() || isValidLength(str));
810 str = fl_get_input(paper_->input_head_height);
811 ok = ok && (str.empty() || isValidLength(str));
812 str = fl_get_input(paper_->input_head_sep);
813 ok = ok && (str.empty() || isValidLength(str));
814 str = fl_get_input(paper_->input_foot_skip);
815 ok = ok && (str.empty() || isValidLength(str));
816 // "Synchronize" the choice and the input field, so that it
817 // is impossible to commit senseless data.
818 input = fl_get_input (class_->input_doc_skip);
819 if (ob == class_->input_doc_skip) {
821 fl_set_choice (class_->choice_doc_skip, 2);
822 } else if (isValidGlueLength (input)) {
823 fl_set_choice (class_->choice_doc_skip, 4);
825 fl_set_choice(class_->choice_doc_skip, 4);
829 if (*input && !isValidGlueLength(input))
832 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
834 else if (fl_get_choice(class_->choice_doc_skip) != 4)
835 fl_set_input (class_->input_doc_skip, "");
837 input = fl_get_input(class_->input_doc_spacing);
838 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
840 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
841 fl_set_input (class_->input_doc_spacing, "");
846 void QDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
848 BufferParams & param = lv_->buffer()->params;
850 // convert from 1-6 range to -1-4
851 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
852 fl_set_input(bullets_->input_bullet_latex,
853 param.temp_bullets[current_bullet_depth].getText().c_str());
857 void QDocument::InputBulletLaTeX(FL_OBJECT *, long)
859 BufferParams & param = lv_->buffer()->params;
861 param.temp_bullets[current_bullet_depth].
862 setText(fl_get_input(bullets_->input_bullet_latex));
866 void QDocument::BulletDepth(FL_OBJECT * ob, State cb)
868 /* Should I do the following:
869 * 1. change to the panel that the current bullet belongs in
870 * 2. show that bullet as selected
871 * 3. change the size setting to the size of the bullet in Q.
872 * 4. display the latex equivalent in the latex box
874 * I'm inclined to just go with 3 and 4 at the moment and
875 * maybe try to support the others later
877 BufferParams & param = lv_->buffer()->params;
880 if (cb == BULLETDEPTH1 )
882 else if (cb == BULLETDEPTH2 )
884 else if (cb == BULLETDEPTH3 )
886 else if (cb == BULLETDEPTH4 )
889 switch (fl_get_button_numb(ob)) {
891 // right mouse button resets to default
892 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
894 current_bullet_depth = data;
895 fl_set_input(bullets_->input_bullet_latex,
896 param.temp_bullets[data].getText().c_str());
897 fl_set_choice(bullets_->choice_bullet_size,
898 param.temp_bullets[data].getSize() + 2);
903 void QDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
905 /* Here we have to change the background pixmap to that selected */
906 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
909 if (cb == BULLETPANEL1 )
911 else if (cb == BULLETPANEL2 )
913 else if (cb == BULLETPANEL3 )
915 else if (cb == BULLETPANEL4 )
917 else if (cb == BULLETPANEL5 )
919 else if (cb == BULLETPANEL6 )
922 if (data != current_bullet_panel) {
923 fl_freeze_form(bullets_->form);
924 current_bullet_panel = data;
926 /* free the current pixmap */
927 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
930 /* display the new one */
932 new_panel = "standard";
935 new_panel = "amssymb";
938 new_panel = "psnfss1";
941 new_panel = "psnfss2";
944 new_panel = "psnfss3";
947 new_panel = "psnfss4";
950 /* something very wrong happened */
951 // play it safe for now but should be an exception
952 current_bullet_panel = 0; // standard panel
953 new_panel = "standard";
957 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
958 LibFileSearch("images", new_panel).c_str());
959 fl_redraw_object(bullets_->bmtable_bullet_panel);
960 fl_unfreeze_form(bullets_->form);
965 void QDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
967 /* handle the user input by setting the current bullet depth's pixmap */
968 /* to that extracted from the current chosen position of the BMTable */
969 /* Don't forget to free the button's old pixmap first. */
971 BufferParams & param = lv_->buffer()->params;
972 int bmtable_button = fl_get_bmtable(ob);
974 /* try to keep the button held down till another is pushed */
975 /* fl_set_bmtable(ob, 1, bmtable_button); */
976 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
977 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
978 fl_set_input(bullets_->input_bullet_latex,
979 param.temp_bullets[current_bullet_depth].getText().c_str());
983 void QDocument::CheckChoiceClass(FL_OBJECT * ob, long)
986 ob = class_->choice_doc_class;
988 ProhibitInput(lv_->view());
990 unsigned int tc = combo_doc_class->get() - 1;
991 if (textclasslist.Load(tc)) {
992 // we use a copy of the bufferparams because we do not
993 // want to modify them yet.
994 BufferParams params = lv_->buffer()->params;
996 if (params.textclass != tc
997 && Alert::askQuestion(_("Should I set some parameters to"),
998 _("the defaults of this document class?"))) {
999 params.textclass = tc;
1000 params.useClassDefaults();
1001 UpdateLayoutDocument(params);
1004 // unable to load new style
1005 Alert::alert(_("Conversion Errors!"),
1006 _("Unable to switch to new document class."),
1007 _("Reverting to original document class."));
1008 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1010 AllowInput(lv_->view());
1014 void QDocument::UpdateLayoutDocument(BufferParams const & params)
1020 class_update(params);
1021 paper_update(params);
1022 language_update(params);
1023 options_update(params);
1024 bullets_update(params);