1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000 The LyX Team.
8 * @author Kalle Dalheimer
10 *======================================================*/
15 #pragma implementation
18 #include "FormDocument.h"
19 #include "FormDocumentDialogImpl.h"
22 #include "lyx_gui_misc.h"
26 #include "tex-strings.h"
27 #include "bufferparams.h"
28 #include "insets/insetquotes.h"
30 #include "support/filetools.h"
33 #include "BufferView.h"
36 #include "CutAndPaste.h"
37 #include "bufferview_funcs.h"
39 #include <qcombobox.h>
40 #include <qlineedit.h>
41 #include <qradiobutton.h>
44 using Liason::setMinibuffer;
47 typedef Qt2CB<ControlDocument, Qt2DB<FormDocumentDialogImpl> > base_class;
49 FormDocument::FormDocument( ControlDocument& c )
50 : base_class( c, _("Document Layout"))
55 void FormDocument::build()
60 // PENDING(kalle) Parent???
61 dialog_.reset( new FormDocumentDialogImpl());
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().setUndoAll(dialog_->restorePB);
70 // the document paper page
71 FormDocumentDialogImpl* 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)
109 docClassCO->insertItem( (*cit).description().c_str() );
112 dialog->docSpacingCO->insertItem( _( "Single" ) );
113 dialog->docSpacingCO->insertItem( _( "OneHalf" ) );
114 dialog->docSpacingCO->insertItem( _( "Double" ) );
115 dialog->docSpacingCO->insertItem( _( "Other" ) );
117 dialog->docFontSizeCO->insertItem( _( "default" ) );
118 dialog->docFontSizeCO->insertItem( _( "10" ) );
119 dialog->docFontSizeCO->insertItem( _( "11" ) );
120 dialog->docFontSizeCO->insertItem( _( "12" ) );
121 for (n=0; tex_fonts[n][0]; ++n) {
122 dialog->docFontsCO->insertItem( tex_fonts[n] );
125 dialog->docPagestyleCO->insertItem( _( "default" ) );
126 dialog->docPagestyleCO->insertItem( _( "empty" ) );
127 dialog->docPagestyleCO->insertItem( _( "plain" ) );
128 dialog->docPagestyleCO->insertItem( _( "headings" ) );
129 dialog->docPagestyleCO->insertItem( _( "fancy" ) );
131 dialog->docSkipCO->insertItem( _( "Smallskip" ) );
132 dialog->docSkipCO->insertItem( _( "Medskip" ) );
133 dialog->docSkipCO->insertItem( _( "Bigskip" ) );
134 dialog->docSkipCO->insertItem( _( "Length" ) );
136 bc().addReadOnly (dialog->docIndentRB);
137 bc().addReadOnly (dialog->docSkipRB);
139 bc().addReadOnly (dialog->docPagestyleCO);
140 bc().addReadOnly (dialog->docFontsCO);
141 bc().addReadOnly (dialog->docFontsizeCO);
142 bc().addReadOnly (dialog->docSidesOneRB);
143 bc().addReadOnly (dialog->docSidesTwoRB);
144 bc().addReadOnly (dialog->docColumnsOneRB);
145 bc().addReadOnly (dialog->docColumnsTwoRB);
146 bc().addReadOnly (dialog->docExtraED);
147 bc().addReadOnly (dialog->docSkipED);
148 bc().addReadOnly (dialog->docSkipCO);
149 bc().addReadOnly (dialog->docSpacingCO);
150 bc().addReadOnly (dialog->docSpacingED);
152 // the document language page
153 dialog->inputEncCO->insertItem( _( "default" ) );
154 dialog->inputEncCO->insertItem( _( "auto" ) );
155 dialog->inputEncCO->insertItem( _( "latin1" ) );
156 dialog->inputEncCO->insertItem( _( "latin2" ) );
157 dialog->inputEncCO->insertItem( _( "latin5" ) );
158 dialog->inputEncCO->insertItem( _( "koi8-r" ) );
159 dialog->inputEncCO->insertItem( _( "koi8-u" ) );
160 dialog->inputEncCO->insertItem( _( "cp866" ) );
161 dialog->inputEncCO->insertItem( _( "cp1251" ) );
162 dialog->inputEncCO->insertItem( _( "iso88595" ) );
164 for (Languages::const_iterator cit = languages.begin();
165 cit != languages.end(); ++cit) {
166 dialog->languageCO->insertItem( (*cit).second.lang() );
169 dialog->quotesLanguageCO->insertItem( _( "``text''" ) );
170 dialog->quotesLanguageCO->insertItem( _( "''text''" ) );
171 dialog->quotesLanguageCO->insertItem( _( ",,text``" ) );
172 dialog->quotesLanguageCO->insertItem( _( ",,text''" ) );
173 dialog->quotesLanguageCO->insertItem( _( "«text»" ) );
174 dialog->quotesLanguageCO->insertItem( _( "»text«" ) );
176 bc().addReadOnly (dialog->inputEncCO);
178 // the document options page
179 dialog->secNumDepthSB->setRange( -2, 5 );
180 dialog->tocDepthSB->setRange( -1, 5 );
181 dialog->secNumDepthSB->setSteps( 1, 1 );
182 dialog->tocDepthSB->setRange( 1, 1 );
183 for (n=0; tex_graphics[n][0]; ++n) {
184 dialog->postscriptDriverCO->insertItem( tex_graphics[n] );
187 bc().addReadOnly (dialog->secNumDepthSB);
188 bc().addReadOnly (dialog->tocDepthSB);
189 bc().addReadOnly (dialog->useAmsMathCB);
190 bc().addReadOnly (dialog->floatPlacementED);
191 bc().addReadOnly (dialog->postscriptDriverCO);
193 // the document bullets page
194 dialog->bulletSizeCO->insertItem( _( "default" ) );
195 dialog->bulletSizeCO->insertItem( _( "tiny" ) );
196 dialog->bulletSizeCO->insertItem( _( "script" ) );
197 dialog->bulletSizeCO->insertItem( _( "footnote" ) );
198 dialog->bulletSizeCO->insertItem( _( "small" ) );
199 dialog->bulletSizeCO->insertItem( _( "normal" ) );
200 dialog->bulletSizeCO->insertItem( _( "large" ) );
201 dialog->bulletSizeCO->insertItem( _( "Large" ) );
202 dialog->bulletSizeCO->insertItem( _( "LARGE" ) );
203 dialog->bulletSizeCO->insertItem( _( "huge" ) );
204 dialog->bulletSizeCO->insertItem( _( "Huge" ) );
206 dialog->bulletSizeCO->setCurrentItem( 0 );
207 dialog->bulletLatexED->setMaxLength( 80 );
209 bc().addReadOnly (dialog->bulletPanelBG);
210 bc().addReadOnly (dialog->bulletSizeCO);
211 bc().addReadOnly (dialog->bulletLatexED);
215 void FormDocument::apply()
217 if (!lv_->view()->available() || !dialog_.get())
220 bool redo = class_apply();
222 redo = language_apply() || redo;
223 redo = options_apply() || redo;
227 lv_->view()->redoCurrentBuffer();
229 lv_->buffer()->markDirty();
230 setMinibuffer(lv_, _("Document layout set"));
234 void FormDocument::cancel()
236 // this avoids confusion when reopening
237 BufferParams & param = lv_->buffer()->params;
238 param.temp_bullets[0] = param.user_defined_bullets[0];
239 param.temp_bullets[1] = param.user_defined_bullets[1];
240 param.temp_bullets[2] = param.user_defined_bullets[2];
241 param.temp_bullets[3] = param.user_defined_bullets[3];
246 void FormDocument::update()
253 BufferParams const & params = lv_->buffer()->params;
255 class_update(params);
256 paper_update(params);
257 language_update(params);
258 options_update(params);
259 bullets_update(params);
264 bool FormDocument::input( FL_OBJECT * ob, long data )
266 State cb = static_cast<State>( data );
269 case CHECKCHOICECLASS:
270 CheckChoiceClass(ob, 0);
272 case CHOICEBULLETSIZE:
273 ChoiceBulletSize(ob, 0);
275 case INPUTBULLETLATEX:
276 InputBulletLaTeX(ob, 0);
293 BulletBMTable(ob, 0);
301 case CHECKCHOICECLASS:
302 case CHOICEBULLETSIZE:
303 case INPUTBULLETLATEX:
305 return CheckDocumentInput(ob, 0);
316 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
318 FormDocument * pre = static_cast<FormDocument*>(v);
319 if (combox == pre->combo_doc_class.get())
320 pre->CheckChoiceClass(0, 0);
321 pre->bc().valid(pre->CheckDocumentInput(0,0));
325 bool FormDocument::class_apply()
328 BufferParams ¶ms = lv_->buffer()->params;
330 // If default skip is a "Length" but there's no text in the
331 // input field, reset the kind to "Medskip", which is the default.
332 if( ( dialog_->docSkipCO->currentItem() == 3 ) &&
333 dialog_->docSkipED->text().isEmpty() )
334 dialog_->docSkipCO->setCurrentItem( 1 );
336 params.fonts = dialog_->docFontsCO->currentText();
337 params.fontsize = dialog_->docFontSizeCO->currentText();
338 params.pagestyle = dialog->docPagestyleCO->currentText();
340 unsigned int const new_class = dialog_->docClassCO->currentItem();
342 if (params.textclass != new_class) {
343 // try to load new_class
344 if (textclasslist.Load(new_class)) {
345 // successfully loaded
347 setMinibuffer(lv_, _("Converting document to new document class..."));
349 int ret = cap.SwitchLayoutsBetweenClasses(
350 params.textclass, new_class,
351 lv_->buffer()->paragraph);
355 s = _("One paragraph couldn't be converted");
358 s += _(" paragraphs couldn't be converted");
360 WriteAlert(_("Conversion Errors!"),s,
361 _("into chosen document class"));
364 params.textclass = new_class;
366 // problem changing class -- warn user and retain old style
367 WriteAlert(_("Conversion Errors!"),
368 _("Errors loading new document class."),
369 _("Reverting to original document class."));
370 dialog_->docClassCO->setCurrentItem( params.textclass );
373 BufferParams::PARSEP tmpsep = params.paragraph_separation;
374 if( dialog_->_docIndentRB->isChecked() )
375 params.paragraph_separation = BufferParams::PARSEP_INDENT;
377 params.paragraph_separation = BufferParams::PARSEP_SKIP;
378 if (tmpsep != params.paragraph_separation)
381 VSpace tmpdefskip = params.getDefSkip();
382 switch( dialog_->docSkipCO->currentItem() ) {
384 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
387 params.setDefSkip(VSpace(VSpace::MEDSKIP));
390 params.setDefSkip(VSpace(VSpace::BIGSKIP));
394 (VSpace(LyXGlueLength(dialog_->docSkipED->text())));
396 // DocumentDefskipCB assures that this never happens
398 params.setDefSkip(VSpace(VSpace::MEDSKIP));
401 if (!(tmpdefskip == params.getDefSkip()))
404 if( dialog_->docColumnsTwo->isChecked() )
408 if( dialog_->docSidesTwo->isChecked() )
409 params.sides = LyXTextClass::TwoSides;
411 params.sides = LyXTextClass::OneSide;
413 Spacing tmpSpacing = params.spacing;
414 switch( dialog_->docSpacingCO->currentItem() ) {
416 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
417 params.spacing.set(Spacing::Single);
420 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
421 params.spacing.set(Spacing::Onehalf);
424 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
425 params.spacing.set(Spacing::Double);
428 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
429 params.spacing.set(Spacing::Other,
430 dialog_->docSpacingED->text() );
433 if (tmpSpacing != params.spacing)
436 params.options = docExtraED->text();
442 void FormDocument::paper_apply()
444 BufferParams & params = lv_->buffer()->params;
447 static_cast<char>(dialog_->papersize2CO->currentItem());
448 params.paperpackage =
449 static_cast<char>(dialog_->paperPackageCO->currentItem() );
450 params.use_geometry = dialog_->useGeometryCB->isChecked();
451 if (dialog_->landscapeRB->isChecked() )
452 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
454 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
455 params.paperwidth = dialog_->customWidthED->text();
456 params.paperheight = dialog_->customHeightED->text();
457 params.leftmargin = dialog_->leftMarginED->text();
458 params.topmargin = dialog_->topMarginED->text();
459 params.rightmargin = dialog_->rightMarginED->text();
460 params.bottommargin = dialog_->bottomMarginED->text();
461 params.headheight = dialog_->headHeightED->text();
462 params.headsep = dialog_->headSepED->text();
463 params.footskip = dialog_->footSkipED->text();
464 lv_->buffer()->setPaperStuff();
468 bool FormDocument::language_apply()
470 BufferParams & params = lv_->buffer()->params;
471 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
474 switch (dialog_->quotesLanguageCO->currentItem() ) {
476 lga = InsetQuotes::EnglishQ;
479 lga = InsetQuotes::SwedishQ;
482 lga = InsetQuotes::GermanQ;
485 lga = InsetQuotes::PolishQ;
488 lga = InsetQuotes::FrenchQ;
491 lga = InsetQuotes::DanishQ;
494 params.quotes_language = lga;
495 if (dialog_->singleRB->isChecked() )
496 params.quotes_times = InsetQuotes::SingleQ;
498 params.quotes_times = InsetQuotes::DoubleQ;
500 Language const * old_language = params.language;
501 Language const * new_language =
502 languages.getLanguage(dialog_->languageCO->currentItem() );
504 new_language = default_language;
506 if (old_language != new_language
507 && old_language->RightToLeft() == new_language->RightToLeft()
508 && !lv_->buffer()->isMultiLingual())
509 lv_->buffer()->ChangeLanguage(old_language, new_language);
510 if (old_language != new_language) {
513 params.language = new_language;
514 params.inputenc = dialog_->inputEncCO->currentText();
520 bool FormDocument::options_apply()
522 BufferParams & params = lv_->buffer()->params;
525 params.graphicsDriver =
526 dialog_->postscriptDriverCO->currentText();
527 params.use_amsmath = dialog_->useAmsMathCB->isChecked();
529 int tmpchar = int(dialog_->secNumDepth->value() );
530 if (params.secnumdepth != tmpchar)
532 params.secnumdepth = tmpchar;
534 params.tocdepth = int(dialog_->tocDepth->value() );
536 params.float_placement =
537 dialog_->floatPlacementED->text();
543 void FormDocument::bullets_apply()
545 /* update the bullet settings */
546 BufferParams & param = lv_->buffer()->params;
548 // a little bit of loop unrolling
549 param.user_defined_bullets[0] = param.temp_bullets[0];
550 param.user_defined_bullets[1] = param.temp_bullets[1];
551 param.user_defined_bullets[2] = param.temp_bullets[2];
552 param.user_defined_bullets[3] = param.temp_bullets[3];
556 void FormDocument::class_update(BufferParams const & params)
561 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
563 combo_doc_class->select_text(
564 textclasslist.DescOfClass(params.textclass));
565 Qt2Helper::setCurrentComboItem( dialog_->docFonts, params.fonts.c_str() );
566 dialog_->docFontSizeCO->clear();
567 dialog_->docFontSizeCO->insertItem( _( "default" ) );
568 dialog_->docFontSizeCO->insertItem( tclass.opt_fontsize().c_str());
569 dialog_->docFontSizeCO->setCurrentItem( tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+1);
570 dialog_->docPagestyleCO->clear();
571 dialog_->docPagestyleCO->insertItem( _( "default" ) );
572 dialog_->docPagestyleCO->insertItem( tclass.opt_pagestyle().c_str());
573 dialog_->docPagestyleCO->setCurrentItem( tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+1);
574 dialog_->docIndentRB->setChecked( false );
575 dialog_->docSkipRB->setChecked( false );
576 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
577 dialog_->docIndentRB->setChecked( true );
579 dialog_->docSkipRB->setChecked( true );
580 switch (params.getDefSkip().kind()) {
581 case VSpace::SMALLSKIP:
582 dialog_->docSkipCO->setCurrentItem( 0 );
584 case VSpace::MEDSKIP:
585 dialog_->docSkipCO->setCurrentItem( 1 );
587 case VSpace::BIGSKIP:
588 dialog_->docSkipCO->setCurrentItem( 2 );
591 dialog_->docSkipCO->setCurrentItem( 3 );
592 dialog_->docSkipED->setText( params.getDefSkip().asLyXCommand().c_str());
595 dialog_->docSkipCO->setCurrentItem( 1 );
598 dialog_->docSidesOneRB->setChecked( false );
599 dialog_->docSidesTwoRB->setChecked( false );
600 if (params.sides == LyXTextClass::TwoSides)
601 dialog_->docSidesTwo->setChecked( true );
603 dialog_->docSidesOne->setChecked( true );
604 dialog_->docColumnsOneRB->setChecked( false );
605 dialog_->docColumnsTwoRB->setChecked( false );
606 if (params.columns == 2)
607 dialog_->docColumnsTwoRB->setChecked( true );
609 dialog_->docColumnsOneRB->setChecked( true );
610 dialog_->docSpacingED->setText( "" );
611 switch (params.spacing.getSpace()) {
612 case Spacing::Default: // nothing bad should happen with this
613 case Spacing::Single:
615 dialog_->docSpacingCO->setCurrentItem( 0 );
617 case Spacing::Onehalf:
619 dialog_->docSpacingCO->setCurrentItem( 1 );
621 case Spacing::Double:
623 dialog_->docSpacingCO->setCurrentItem( 2 );
627 dialog_->docSpacingCO->setCurrentItem( 3 );
629 sval.sprintf("%g",params.spacing.getValue());
630 dialog_->docSpacingED->setText( sval );
634 if (!params.options.empty())
635 dialog_->docExtraED->setText(, params.options.c_str());
637 dialog_->docExtraED->setText( "" );
641 void FormDocument::language_update(BufferParams const & params)
643 if (!language_.get())
646 Qt2Helper::setCurrentItemText( dialog_->languageCO, params.language->lang() );
647 Qt2Helper::setCurrentItemText( dialog_->inputEncCO, params.inputenc.c_str() );
648 dialog_->quotesLanguageCO->setCurrentItem( params.quotes_language );
649 dialog_->singleRB->setChecked( false );
650 dialog_->doubleRB->setChecked( false );
651 if (params.quotes_times == InsetQuotes::SingleQ)
652 dialog_->singleRB->setChecked( true );
654 dialog_->doubleRB->setChecked( true );
658 void FormDocument::options_update(BufferParams const & params)
663 Qt2Helper::setCurrentItemText( dialog_->postscriptDriverCO,
664 params.graphicsDriver.c_str());
665 dialog_->useAmsMathCB->setChecked( params.use_amsmath );
666 dialog_->secNumDepthSB->setValue( params.secnumdepth );
667 dialog_->setTocDepthSB->setValue( params.tocdepth );
668 if (!params.float_placement.empty())
669 dialog_->floatPlacementED->setText( params.float_placement.c_str());
671 dialog_->floatPlacementED->setText( "" );
675 void FormDocument::paper_update(BufferParams const & params)
680 dialog_->papersize2CO->setCurrentItem( params.papersize2 );
681 dialog_->paperPackageCO->setCurrentItem( params.paperpackage );
682 dialog_->useGeometryCB->setChecked( params.use_geometry );
683 dialog_->portraitRB->setChecked( false );
684 dialog_->landscapeRB->setChecked( false );
685 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
686 dialog_->landscapeRB->setChecked( true );
688 dialog_->portraitRB->setChecked( true );
689 dialog_->customWidthED->setText( params.paperwidth.c_str());
690 dialog_->customHeightED->setText( params.paperheight.c_str());
691 dialog_->leftMarginED->setText( params.leftmargin.c_str());
692 dialog_->topMarginED->setText( params.topmargin.c_str());
693 dialog_->rightMarginED->setText( params.rightmargin.c_str());
694 dialog_->bottomMarginED->setText( params.bottommargin.c_str());
695 dialog_->headHeightED->setText( params.headheight.c_str());
696 dialog_->headSepED->setText( params.headsep.c_str());
697 dialog_->footSkipED->setText( params.footskip.c_str());
698 dialog_->papersize2CO->setFocus();
702 void FormDocument::bullets_update(BufferParams const & params)
704 bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
705 setEnabled(fbullet, !isLinuxDoc);
707 if (isLinuxDoc) return;
709 dialog_->bulletDepth1RB->setChecked( true );
710 dialog_->bulletLatexED->setText( params.user_defined_bullets[0].getText().c_str());
711 dialog_->bulletSizeCO->setCurrentItem( params.user_defined_bullets[0].getSize() + 1);
715 void FormDocument::checkReadOnly()
717 if (bc().readOnly(lv_->buffer()->isReadonly())) {
718 dialog_->docClassCO->setEnabled( false );
719 dialog_->languageCO->setEnabled( false );
720 dialog_->warningLA->setText( _("Document is read-only."
721 " No changes to layout permitted."));
722 dialog_->warningLA->show();
724 dialog_->docClassCO->setEnabled( true );
725 dialog_->languageCO->setEnabled( true );
726 dialog_->warningLA->hide();
731 void FormDocument::checkMarginValues()
733 bool const not_empty =
734 !dialog_->topMarginED->text().isEmpty() ||
735 !dialog_->bottomMarginED->text().isEmpty() ||
736 !dialog_->leftMarginED->text().isEmpty() ||
737 !dialog_->rightMarginED->text().isEmpty() ||
738 !dialog_->headHeightED->text().isEmpty() ||
739 !dialog_->headSepED->text().isEmpty() ||
740 !dialog_->footSkipED->text().isEmpty() ||
741 !dialog_->customWidthED->text().isEmpty() ||
742 !dialog_->customHeightED->text().isEmpty();
744 dialog_->useGeometryCB->setChecked( true );
748 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
756 if (ob == paper_->choice_papersize2) {
757 val = fl_get_choice(paper_->choice_papersize2)-1;
758 if (val == BufferParams::VM_PAPER_DEFAULT) {
759 fl_set_button(paper_->push_use_geometry, 0);
762 if ((val != BufferParams::VM_PAPER_USLETTER) &&
763 (val != BufferParams::VM_PAPER_USLEGAL) &&
764 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
765 (val != BufferParams::VM_PAPER_A4) &&
766 (val != BufferParams::VM_PAPER_A5) &&
767 (val != BufferParams::VM_PAPER_B5)) {
768 fl_set_button(paper_->push_use_geometry, 1);
770 fl_set_choice(paper_->choice_paperpackage,
771 BufferParams::PACKAGE_NONE + 1);
773 } else if (ob == paper_->choice_paperpackage) {
774 val = fl_get_choice(paper_->choice_paperpackage)-1;
775 if (val != BufferParams::PACKAGE_NONE) {
776 fl_set_choice(paper_->choice_papersize2,
777 BufferParams::VM_PAPER_DEFAULT + 1);
778 fl_set_button(paper_->push_use_geometry, 0);
780 } else if (ob == class_->input_doc_spacing) {
781 input = fl_get_input(class_->input_doc_spacing);
783 fl_set_choice (class_->choice_doc_spacing, 1);
785 fl_set_choice(class_->choice_doc_spacing, 4);
788 // this has to be all out of if/elseif because it has to deactivate
789 // the document buttons and so the whole stuff has to be tested again.
790 str = fl_get_input(paper_->input_custom_width);
791 ok = ok && (str.empty() || isValidLength(str));
792 str = fl_get_input(paper_->input_custom_height);
793 ok = ok && (str.empty() || isValidLength(str));
794 str = fl_get_input(paper_->input_left_margin);
795 ok = ok && (str.empty() || isValidLength(str));
796 str = fl_get_input(paper_->input_right_margin);
797 ok = ok && (str.empty() || isValidLength(str));
798 str = fl_get_input(paper_->input_top_margin);
799 ok = ok && (str.empty() || isValidLength(str));
800 str = fl_get_input(paper_->input_bottom_margin);
801 ok = ok && (str.empty() || isValidLength(str));
802 str = fl_get_input(paper_->input_head_height);
803 ok = ok && (str.empty() || isValidLength(str));
804 str = fl_get_input(paper_->input_head_sep);
805 ok = ok && (str.empty() || isValidLength(str));
806 str = fl_get_input(paper_->input_foot_skip);
807 ok = ok && (str.empty() || isValidLength(str));
808 // "Synchronize" the choice and the input field, so that it
809 // is impossible to commit senseless data.
810 input = fl_get_input (class_->input_doc_skip);
811 if (ob == class_->input_doc_skip) {
813 fl_set_choice (class_->choice_doc_skip, 2);
814 } else if (isValidGlueLength (input)) {
815 fl_set_choice (class_->choice_doc_skip, 4);
817 fl_set_choice(class_->choice_doc_skip, 4);
821 if (*input && !isValidGlueLength(input))
824 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
826 else if (fl_get_choice(class_->choice_doc_skip) != 4)
827 fl_set_input (class_->input_doc_skip, "");
829 input = fl_get_input(class_->input_doc_spacing);
830 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
832 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
833 fl_set_input (class_->input_doc_spacing, "");
838 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
840 BufferParams & param = lv_->buffer()->params;
842 // convert from 1-6 range to -1-4
843 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
844 fl_set_input(bullets_->input_bullet_latex,
845 param.temp_bullets[current_bullet_depth].getText().c_str());
849 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
851 BufferParams & param = lv_->buffer()->params;
853 param.temp_bullets[current_bullet_depth].
854 setText(fl_get_input(bullets_->input_bullet_latex));
858 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
860 /* Should I do the following: */
861 /* 1. change to the panel that the current bullet belongs in */
862 /* 2. show that bullet as selected */
863 /* 3. change the size setting to the size of the bullet in Q.*/
864 /* 4. display the latex equivalent in the latex box */
866 /* I'm inclined to just go with 3 and 4 at the moment and */
867 /* maybe try to support the others later */
868 BufferParams & param = lv_->buffer()->params;
871 if (cb == BULLETDEPTH1 )
873 else if (cb == BULLETDEPTH2 )
875 else if (cb == BULLETDEPTH3 )
877 else if (cb == BULLETDEPTH4 )
880 switch (fl_get_button_numb(ob)) {
882 // right mouse button resets to default
883 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
885 current_bullet_depth = data;
886 fl_set_input(bullets_->input_bullet_latex,
887 param.temp_bullets[data].getText().c_str());
888 fl_set_choice(bullets_->choice_bullet_size,
889 param.temp_bullets[data].getSize() + 2);
894 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
896 /* Here we have to change the background pixmap to that selected */
897 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
900 if (cb == BULLETPANEL1 )
902 else if (cb == BULLETPANEL2 )
904 else if (cb == BULLETPANEL3 )
906 else if (cb == BULLETPANEL4 )
908 else if (cb == BULLETPANEL5 )
910 else if (cb == BULLETPANEL6 )
913 if (data != current_bullet_panel) {
914 fl_freeze_form(bullets_->form);
915 current_bullet_panel = data;
917 /* free the current pixmap */
918 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
921 /* display the new one */
923 new_panel = "standard";
926 new_panel = "amssymb";
929 new_panel = "psnfss1";
932 new_panel = "psnfss2";
935 new_panel = "psnfss3";
938 new_panel = "psnfss4";
941 /* something very wrong happened */
942 // play it safe for now but should be an exception
943 current_bullet_panel = 0; // standard panel
944 new_panel = "standard";
948 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
949 LibFileSearch("images", new_panel).c_str());
950 fl_redraw_object(bullets_->bmtable_bullet_panel);
951 fl_unfreeze_form(bullets_->form);
956 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
958 /* handle the user input by setting the current bullet depth's pixmap */
959 /* to that extracted from the current chosen position of the BMTable */
960 /* Don't forget to free the button's old pixmap first. */
962 BufferParams & param = lv_->buffer()->params;
963 int bmtable_button = fl_get_bmtable(ob);
965 /* try to keep the button held down till another is pushed */
966 /* fl_set_bmtable(ob, 1, bmtable_button); */
967 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
968 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
969 fl_set_input(bullets_->input_bullet_latex,
970 param.temp_bullets[current_bullet_depth].getText().c_str());
974 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
977 ob = class_->choice_doc_class;
979 ProhibitInput(lv_->view());
981 unsigned int tc = combo_doc_class->get() - 1;
982 if (textclasslist.Load(tc)) {
983 // we use a copy of the bufferparams because we do not
984 // want to modify them yet.
985 BufferParams params = lv_->buffer()->params;
987 if (params.textclass != tc
988 && AskQuestion(_("Should I set some parameters to"),
989 _("the defaults of this document class?"))) {
990 params.textclass = tc;
991 params.useClassDefaults();
992 UpdateLayoutDocument(params);
995 // unable to load new style
996 WriteAlert(_("Conversion Errors!"),
997 _("Unable to switch to new document class."),
998 _("Reverting to original document class."));
999 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1001 AllowInput(lv_->view());
1005 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1011 class_update(params);
1012 paper_update(params);
1013 language_update(params);
1014 options_update(params);
1015 bullets_update(params);