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().setRestore(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( _( "latin9" ) );
159 dialog->inputEncCO->insertItem( _( "koi8-r" ) );
160 dialog->inputEncCO->insertItem( _( "koi8-u" ) );
161 dialog->inputEncCO->insertItem( _( "cp866" ) );
162 dialog->inputEncCO->insertItem( _( "cp1251" ) );
163 dialog->inputEncCO->insertItem( _( "iso88595" ) );
165 for (Languages::const_iterator cit = languages.begin();
166 cit != languages.end(); ++cit) {
167 dialog->languageCO->insertItem( (*cit).second.lang() );
170 dialog->quotesLanguageCO->insertItem( _( "``text''" ) );
171 dialog->quotesLanguageCO->insertItem( _( "''text''" ) );
172 dialog->quotesLanguageCO->insertItem( _( ",,text``" ) );
173 dialog->quotesLanguageCO->insertItem( _( ",,text''" ) );
174 dialog->quotesLanguageCO->insertItem( _( "«text»" ) );
175 dialog->quotesLanguageCO->insertItem( _( "»text«" ) );
177 bc().addReadOnly (dialog->inputEncCO);
179 // the document options page
180 dialog->secNumDepthSB->setRange( -2, 5 );
181 dialog->tocDepthSB->setRange( -1, 5 );
182 dialog->secNumDepthSB->setSteps( 1, 1 );
183 dialog->tocDepthSB->setRange( 1, 1 );
184 for (n=0; tex_graphics[n][0]; ++n) {
185 dialog->postscriptDriverCO->insertItem( tex_graphics[n] );
188 bc().addReadOnly (dialog->secNumDepthSB);
189 bc().addReadOnly (dialog->tocDepthSB);
190 bc().addReadOnly (dialog->useAmsMathCB);
191 bc().addReadOnly (dialog->floatPlacementED);
192 bc().addReadOnly (dialog->postscriptDriverCO);
194 // the document bullets page
195 dialog->bulletSizeCO->insertItem( _( "default" ) );
196 dialog->bulletSizeCO->insertItem( _( "tiny" ) );
197 dialog->bulletSizeCO->insertItem( _( "script" ) );
198 dialog->bulletSizeCO->insertItem( _( "footnote" ) );
199 dialog->bulletSizeCO->insertItem( _( "small" ) );
200 dialog->bulletSizeCO->insertItem( _( "normal" ) );
201 dialog->bulletSizeCO->insertItem( _( "large" ) );
202 dialog->bulletSizeCO->insertItem( _( "Large" ) );
203 dialog->bulletSizeCO->insertItem( _( "LARGE" ) );
204 dialog->bulletSizeCO->insertItem( _( "huge" ) );
205 dialog->bulletSizeCO->insertItem( _( "Huge" ) );
207 dialog->bulletSizeCO->setCurrentItem( 0 );
208 dialog->bulletLatexED->setMaxLength( 80 );
210 bc().addReadOnly (dialog->bulletPanelBG);
211 bc().addReadOnly (dialog->bulletSizeCO);
212 bc().addReadOnly (dialog->bulletLatexED);
216 void FormDocument::apply()
218 if (!lv_->view()->available() || !dialog_.get())
221 bool redo = class_apply();
223 redo = language_apply() || redo;
224 redo = options_apply() || redo;
228 lv_->view()->redoCurrentBuffer();
230 lv_->buffer()->markDirty();
231 setMinibuffer(lv_, _("Document layout set"));
235 void FormDocument::cancel()
237 // this avoids confusion when reopening
238 BufferParams & param = lv_->buffer()->params;
239 param.temp_bullets[0] = param.user_defined_bullets[0];
240 param.temp_bullets[1] = param.user_defined_bullets[1];
241 param.temp_bullets[2] = param.user_defined_bullets[2];
242 param.temp_bullets[3] = param.user_defined_bullets[3];
247 void FormDocument::update()
254 BufferParams const & params = lv_->buffer()->params;
256 class_update(params);
257 paper_update(params);
258 language_update(params);
259 options_update(params);
260 bullets_update(params);
265 bool FormDocument::input( FL_OBJECT * ob, long data )
267 State cb = static_cast<State>( data );
270 case CHECKCHOICECLASS:
271 CheckChoiceClass(ob, 0);
273 case CHOICEBULLETSIZE:
274 ChoiceBulletSize(ob, 0);
276 case INPUTBULLETLATEX:
277 InputBulletLaTeX(ob, 0);
294 BulletBMTable(ob, 0);
302 case CHECKCHOICECLASS:
303 case CHOICEBULLETSIZE:
304 case INPUTBULLETLATEX:
306 return CheckDocumentInput(ob, 0);
317 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
319 FormDocument * pre = static_cast<FormDocument*>(v);
320 if (combox == pre->combo_doc_class.get())
321 pre->CheckChoiceClass(0, 0);
322 pre->bc().valid(pre->CheckDocumentInput(0,0));
326 bool FormDocument::class_apply()
329 BufferParams ¶ms = lv_->buffer()->params;
331 // If default skip is a "Length" but there's no text in the
332 // input field, reset the kind to "Medskip", which is the default.
333 if( ( dialog_->docSkipCO->currentItem() == 3 ) &&
334 dialog_->docSkipED->text().isEmpty() )
335 dialog_->docSkipCO->setCurrentItem( 1 );
337 params.fonts = dialog_->docFontsCO->currentText();
338 params.fontsize = dialog_->docFontSizeCO->currentText();
339 params.pagestyle = dialog->docPagestyleCO->currentText();
341 unsigned int const new_class = dialog_->docClassCO->currentItem();
343 if (params.textclass != new_class) {
344 // try to load new_class
345 if (textclasslist.Load(new_class)) {
346 // successfully loaded
348 setMinibuffer(lv_, _("Converting document to new document class..."));
350 int ret = cap.SwitchLayoutsBetweenClasses(
351 params.textclass, new_class,
352 lv_->buffer()->paragraph);
356 s = _("One paragraph couldn't be converted");
359 s += _(" paragraphs couldn't be converted");
361 WriteAlert(_("Conversion Errors!"),s,
362 _("into chosen document class"));
365 params.textclass = new_class;
367 // problem changing class -- warn user and retain old style
368 WriteAlert(_("Conversion Errors!"),
369 _("Errors loading new document class."),
370 _("Reverting to original document class."));
371 dialog_->docClassCO->setCurrentItem( params.textclass );
374 BufferParams::PARSEP tmpsep = params.paragraph_separation;
375 if( dialog_->_docIndentRB->isChecked() )
376 params.paragraph_separation = BufferParams::PARSEP_INDENT;
378 params.paragraph_separation = BufferParams::PARSEP_SKIP;
379 if (tmpsep != params.paragraph_separation)
382 VSpace tmpdefskip = params.getDefSkip();
383 switch( dialog_->docSkipCO->currentItem() ) {
385 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
388 params.setDefSkip(VSpace(VSpace::MEDSKIP));
391 params.setDefSkip(VSpace(VSpace::BIGSKIP));
395 (VSpace(LyXGlueLength(dialog_->docSkipED->text())));
397 // DocumentDefskipCB assures that this never happens
399 params.setDefSkip(VSpace(VSpace::MEDSKIP));
402 if (!(tmpdefskip == params.getDefSkip()))
405 if( dialog_->docColumnsTwo->isChecked() )
409 if( dialog_->docSidesTwo->isChecked() )
410 params.sides = LyXTextClass::TwoSides;
412 params.sides = LyXTextClass::OneSide;
414 Spacing tmpSpacing = params.spacing;
415 switch( dialog_->docSpacingCO->currentItem() ) {
417 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
418 params.spacing.set(Spacing::Single);
421 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
422 params.spacing.set(Spacing::Onehalf);
425 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
426 params.spacing.set(Spacing::Double);
429 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
430 params.spacing.set(Spacing::Other,
431 dialog_->docSpacingED->text() );
434 if (tmpSpacing != params.spacing)
437 params.options = docExtraED->text();
443 void FormDocument::paper_apply()
445 BufferParams & params = lv_->buffer()->params;
448 static_cast<char>(dialog_->papersize2CO->currentItem());
449 params.paperpackage =
450 static_cast<char>(dialog_->paperPackageCO->currentItem() );
451 params.use_geometry = dialog_->useGeometryCB->isChecked();
452 if (dialog_->landscapeRB->isChecked() )
453 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
455 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
456 params.paperwidth = dialog_->customWidthED->text();
457 params.paperheight = dialog_->customHeightED->text();
458 params.leftmargin = dialog_->leftMarginED->text();
459 params.topmargin = dialog_->topMarginED->text();
460 params.rightmargin = dialog_->rightMarginED->text();
461 params.bottommargin = dialog_->bottomMarginED->text();
462 params.headheight = dialog_->headHeightED->text();
463 params.headsep = dialog_->headSepED->text();
464 params.footskip = dialog_->footSkipED->text();
465 lv_->buffer()->setPaperStuff();
469 bool FormDocument::language_apply()
471 BufferParams & params = lv_->buffer()->params;
472 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
475 switch (dialog_->quotesLanguageCO->currentItem() ) {
477 lga = InsetQuotes::EnglishQ;
480 lga = InsetQuotes::SwedishQ;
483 lga = InsetQuotes::GermanQ;
486 lga = InsetQuotes::PolishQ;
489 lga = InsetQuotes::FrenchQ;
492 lga = InsetQuotes::DanishQ;
495 params.quotes_language = lga;
496 if (dialog_->singleRB->isChecked() )
497 params.quotes_times = InsetQuotes::SingleQ;
499 params.quotes_times = InsetQuotes::DoubleQ;
501 Language const * old_language = params.language;
502 Language const * new_language =
503 languages.getLanguage(dialog_->languageCO->currentItem() );
505 new_language = default_language;
507 if (old_language != new_language
508 && old_language->RightToLeft() == new_language->RightToLeft()
509 && !lv_->buffer()->isMultiLingual())
510 lv_->buffer()->ChangeLanguage(old_language, new_language);
511 if (old_language != new_language) {
514 params.language = new_language;
515 params.inputenc = dialog_->inputEncCO->currentText();
521 bool FormDocument::options_apply()
523 BufferParams & params = lv_->buffer()->params;
526 params.graphicsDriver =
527 dialog_->postscriptDriverCO->currentText();
528 params.use_amsmath = dialog_->useAmsMathCB->isChecked();
530 int tmpchar = int(dialog_->secNumDepth->value() );
531 if (params.secnumdepth != tmpchar)
533 params.secnumdepth = tmpchar;
535 params.tocdepth = int(dialog_->tocDepth->value() );
537 params.float_placement =
538 dialog_->floatPlacementED->text();
544 void FormDocument::bullets_apply()
546 /* update the bullet settings */
547 BufferParams & param = lv_->buffer()->params;
549 // a little bit of loop unrolling
550 param.user_defined_bullets[0] = param.temp_bullets[0];
551 param.user_defined_bullets[1] = param.temp_bullets[1];
552 param.user_defined_bullets[2] = param.temp_bullets[2];
553 param.user_defined_bullets[3] = param.temp_bullets[3];
557 void FormDocument::class_update(BufferParams const & params)
562 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
564 combo_doc_class->select_text(
565 textclasslist.DescOfClass(params.textclass));
566 Qt2Helper::setCurrentComboItem( dialog_->docFonts, params.fonts.c_str() );
567 dialog_->docFontSizeCO->clear();
568 dialog_->docFontSizeCO->insertItem( _( "default" ) );
569 dialog_->docFontSizeCO->insertItem( tclass.opt_fontsize().c_str());
570 dialog_->docFontSizeCO->setCurrentItem( tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+1);
571 dialog_->docPagestyleCO->clear();
572 dialog_->docPagestyleCO->insertItem( _( "default" ) );
573 dialog_->docPagestyleCO->insertItem( tclass.opt_pagestyle().c_str());
574 dialog_->docPagestyleCO->setCurrentItem( tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+1);
575 dialog_->docIndentRB->setChecked( false );
576 dialog_->docSkipRB->setChecked( false );
577 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
578 dialog_->docIndentRB->setChecked( true );
580 dialog_->docSkipRB->setChecked( true );
581 switch (params.getDefSkip().kind()) {
582 case VSpace::SMALLSKIP:
583 dialog_->docSkipCO->setCurrentItem( 0 );
585 case VSpace::MEDSKIP:
586 dialog_->docSkipCO->setCurrentItem( 1 );
588 case VSpace::BIGSKIP:
589 dialog_->docSkipCO->setCurrentItem( 2 );
592 dialog_->docSkipCO->setCurrentItem( 3 );
593 dialog_->docSkipED->setText( params.getDefSkip().asLyXCommand().c_str());
596 dialog_->docSkipCO->setCurrentItem( 1 );
599 dialog_->docSidesOneRB->setChecked( false );
600 dialog_->docSidesTwoRB->setChecked( false );
601 if (params.sides == LyXTextClass::TwoSides)
602 dialog_->docSidesTwo->setChecked( true );
604 dialog_->docSidesOne->setChecked( true );
605 dialog_->docColumnsOneRB->setChecked( false );
606 dialog_->docColumnsTwoRB->setChecked( false );
607 if (params.columns == 2)
608 dialog_->docColumnsTwoRB->setChecked( true );
610 dialog_->docColumnsOneRB->setChecked( true );
611 dialog_->docSpacingED->setText( "" );
612 switch (params.spacing.getSpace()) {
613 case Spacing::Default: // nothing bad should happen with this
614 case Spacing::Single:
616 dialog_->docSpacingCO->setCurrentItem( 0 );
618 case Spacing::Onehalf:
620 dialog_->docSpacingCO->setCurrentItem( 1 );
622 case Spacing::Double:
624 dialog_->docSpacingCO->setCurrentItem( 2 );
628 dialog_->docSpacingCO->setCurrentItem( 3 );
630 sval.sprintf("%g",params.spacing.getValue());
631 dialog_->docSpacingED->setText( sval );
635 if (!params.options.empty())
636 dialog_->docExtraED->setText(, params.options.c_str());
638 dialog_->docExtraED->setText( "" );
642 void FormDocument::language_update(BufferParams const & params)
644 if (!language_.get())
647 Qt2Helper::setCurrentItemText( dialog_->languageCO, params.language->lang() );
648 Qt2Helper::setCurrentItemText( dialog_->inputEncCO, params.inputenc.c_str() );
649 dialog_->quotesLanguageCO->setCurrentItem( params.quotes_language );
650 dialog_->singleRB->setChecked( false );
651 dialog_->doubleRB->setChecked( false );
652 if (params.quotes_times == InsetQuotes::SingleQ)
653 dialog_->singleRB->setChecked( true );
655 dialog_->doubleRB->setChecked( true );
659 void FormDocument::options_update(BufferParams const & params)
664 Qt2Helper::setCurrentItemText( dialog_->postscriptDriverCO,
665 params.graphicsDriver.c_str());
666 dialog_->useAmsMathCB->setChecked( params.use_amsmath );
667 dialog_->secNumDepthSB->setValue( params.secnumdepth );
668 dialog_->setTocDepthSB->setValue( params.tocdepth );
669 if (!params.float_placement.empty())
670 dialog_->floatPlacementED->setText( params.float_placement.c_str());
672 dialog_->floatPlacementED->setText( "" );
676 void FormDocument::paper_update(BufferParams const & params)
681 dialog_->papersize2CO->setCurrentItem( params.papersize2 );
682 dialog_->paperPackageCO->setCurrentItem( params.paperpackage );
683 dialog_->useGeometryCB->setChecked( params.use_geometry );
684 dialog_->portraitRB->setChecked( false );
685 dialog_->landscapeRB->setChecked( false );
686 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
687 dialog_->landscapeRB->setChecked( true );
689 dialog_->portraitRB->setChecked( true );
690 dialog_->customWidthED->setText( params.paperwidth.c_str());
691 dialog_->customHeightED->setText( params.paperheight.c_str());
692 dialog_->leftMarginED->setText( params.leftmargin.c_str());
693 dialog_->topMarginED->setText( params.topmargin.c_str());
694 dialog_->rightMarginED->setText( params.rightmargin.c_str());
695 dialog_->bottomMarginED->setText( params.bottommargin.c_str());
696 dialog_->headHeightED->setText( params.headheight.c_str());
697 dialog_->headSepED->setText( params.headsep.c_str());
698 dialog_->footSkipED->setText( params.footskip.c_str());
699 dialog_->papersize2CO->setFocus();
703 void FormDocument::bullets_update(BufferParams const & params)
705 bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
706 setEnabled(fbullet, !isLinuxDoc);
708 if (isLinuxDoc) return;
710 dialog_->bulletDepth1RB->setChecked( true );
711 dialog_->bulletLatexED->setText( params.user_defined_bullets[0].getText().c_str());
712 dialog_->bulletSizeCO->setCurrentItem( params.user_defined_bullets[0].getSize() + 1);
716 void FormDocument::checkReadOnly()
718 if (bc().readOnly(lv_->buffer()->isReadonly())) {
719 dialog_->docClassCO->setEnabled( false );
720 dialog_->languageCO->setEnabled( false );
721 dialog_->warningLA->setText( _("Document is read-only."
722 " No changes to layout permitted."));
723 dialog_->warningLA->show();
725 dialog_->docClassCO->setEnabled( true );
726 dialog_->languageCO->setEnabled( true );
727 dialog_->warningLA->hide();
732 void FormDocument::checkMarginValues()
734 bool const not_empty =
735 !dialog_->topMarginED->text().isEmpty() ||
736 !dialog_->bottomMarginED->text().isEmpty() ||
737 !dialog_->leftMarginED->text().isEmpty() ||
738 !dialog_->rightMarginED->text().isEmpty() ||
739 !dialog_->headHeightED->text().isEmpty() ||
740 !dialog_->headSepED->text().isEmpty() ||
741 !dialog_->footSkipED->text().isEmpty() ||
742 !dialog_->customWidthED->text().isEmpty() ||
743 !dialog_->customHeightED->text().isEmpty();
745 dialog_->useGeometryCB->setChecked( true );
749 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
757 if (ob == paper_->choice_papersize2) {
758 val = fl_get_choice(paper_->choice_papersize2)-1;
759 if (val == BufferParams::VM_PAPER_DEFAULT) {
760 fl_set_button(paper_->push_use_geometry, 0);
763 if ((val != BufferParams::VM_PAPER_USLETTER) &&
764 (val != BufferParams::VM_PAPER_USLEGAL) &&
765 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
766 (val != BufferParams::VM_PAPER_A4) &&
767 (val != BufferParams::VM_PAPER_A5) &&
768 (val != BufferParams::VM_PAPER_B5)) {
769 fl_set_button(paper_->push_use_geometry, 1);
771 fl_set_choice(paper_->choice_paperpackage,
772 BufferParams::PACKAGE_NONE + 1);
774 } else if (ob == paper_->choice_paperpackage) {
775 val = fl_get_choice(paper_->choice_paperpackage)-1;
776 if (val != BufferParams::PACKAGE_NONE) {
777 fl_set_choice(paper_->choice_papersize2,
778 BufferParams::VM_PAPER_DEFAULT + 1);
779 fl_set_button(paper_->push_use_geometry, 0);
781 } else if (ob == class_->input_doc_spacing) {
782 input = fl_get_input(class_->input_doc_spacing);
784 fl_set_choice (class_->choice_doc_spacing, 1);
786 fl_set_choice(class_->choice_doc_spacing, 4);
789 // this has to be all out of if/elseif because it has to deactivate
790 // the document buttons and so the whole stuff has to be tested again.
791 str = fl_get_input(paper_->input_custom_width);
792 ok = ok && (str.empty() || isValidLength(str));
793 str = fl_get_input(paper_->input_custom_height);
794 ok = ok && (str.empty() || isValidLength(str));
795 str = fl_get_input(paper_->input_left_margin);
796 ok = ok && (str.empty() || isValidLength(str));
797 str = fl_get_input(paper_->input_right_margin);
798 ok = ok && (str.empty() || isValidLength(str));
799 str = fl_get_input(paper_->input_top_margin);
800 ok = ok && (str.empty() || isValidLength(str));
801 str = fl_get_input(paper_->input_bottom_margin);
802 ok = ok && (str.empty() || isValidLength(str));
803 str = fl_get_input(paper_->input_head_height);
804 ok = ok && (str.empty() || isValidLength(str));
805 str = fl_get_input(paper_->input_head_sep);
806 ok = ok && (str.empty() || isValidLength(str));
807 str = fl_get_input(paper_->input_foot_skip);
808 ok = ok && (str.empty() || isValidLength(str));
809 // "Synchronize" the choice and the input field, so that it
810 // is impossible to commit senseless data.
811 input = fl_get_input (class_->input_doc_skip);
812 if (ob == class_->input_doc_skip) {
814 fl_set_choice (class_->choice_doc_skip, 2);
815 } else if (isValidGlueLength (input)) {
816 fl_set_choice (class_->choice_doc_skip, 4);
818 fl_set_choice(class_->choice_doc_skip, 4);
822 if (*input && !isValidGlueLength(input))
825 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
827 else if (fl_get_choice(class_->choice_doc_skip) != 4)
828 fl_set_input (class_->input_doc_skip, "");
830 input = fl_get_input(class_->input_doc_spacing);
831 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
833 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
834 fl_set_input (class_->input_doc_spacing, "");
839 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
841 BufferParams & param = lv_->buffer()->params;
843 // convert from 1-6 range to -1-4
844 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
845 fl_set_input(bullets_->input_bullet_latex,
846 param.temp_bullets[current_bullet_depth].getText().c_str());
850 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
852 BufferParams & param = lv_->buffer()->params;
854 param.temp_bullets[current_bullet_depth].
855 setText(fl_get_input(bullets_->input_bullet_latex));
859 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
861 /* Should I do the following: */
862 /* 1. change to the panel that the current bullet belongs in */
863 /* 2. show that bullet as selected */
864 /* 3. change the size setting to the size of the bullet in Q.*/
865 /* 4. display the latex equivalent in the latex box */
867 /* I'm inclined to just go with 3 and 4 at the moment and */
868 /* maybe try to support the others later */
869 BufferParams & param = lv_->buffer()->params;
872 if (cb == BULLETDEPTH1 )
874 else if (cb == BULLETDEPTH2 )
876 else if (cb == BULLETDEPTH3 )
878 else if (cb == BULLETDEPTH4 )
881 switch (fl_get_button_numb(ob)) {
883 // right mouse button resets to default
884 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
886 current_bullet_depth = data;
887 fl_set_input(bullets_->input_bullet_latex,
888 param.temp_bullets[data].getText().c_str());
889 fl_set_choice(bullets_->choice_bullet_size,
890 param.temp_bullets[data].getSize() + 2);
895 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
897 /* Here we have to change the background pixmap to that selected */
898 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
901 if (cb == BULLETPANEL1 )
903 else if (cb == BULLETPANEL2 )
905 else if (cb == BULLETPANEL3 )
907 else if (cb == BULLETPANEL4 )
909 else if (cb == BULLETPANEL5 )
911 else if (cb == BULLETPANEL6 )
914 if (data != current_bullet_panel) {
915 fl_freeze_form(bullets_->form);
916 current_bullet_panel = data;
918 /* free the current pixmap */
919 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
922 /* display the new one */
924 new_panel = "standard";
927 new_panel = "amssymb";
930 new_panel = "psnfss1";
933 new_panel = "psnfss2";
936 new_panel = "psnfss3";
939 new_panel = "psnfss4";
942 /* something very wrong happened */
943 // play it safe for now but should be an exception
944 current_bullet_panel = 0; // standard panel
945 new_panel = "standard";
949 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
950 LibFileSearch("images", new_panel).c_str());
951 fl_redraw_object(bullets_->bmtable_bullet_panel);
952 fl_unfreeze_form(bullets_->form);
957 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
959 /* handle the user input by setting the current bullet depth's pixmap */
960 /* to that extracted from the current chosen position of the BMTable */
961 /* Don't forget to free the button's old pixmap first. */
963 BufferParams & param = lv_->buffer()->params;
964 int bmtable_button = fl_get_bmtable(ob);
966 /* try to keep the button held down till another is pushed */
967 /* fl_set_bmtable(ob, 1, bmtable_button); */
968 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
969 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
970 fl_set_input(bullets_->input_bullet_latex,
971 param.temp_bullets[current_bullet_depth].getText().c_str());
975 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
978 ob = class_->choice_doc_class;
980 ProhibitInput(lv_->view());
982 unsigned int tc = combo_doc_class->get() - 1;
983 if (textclasslist.Load(tc)) {
984 // we use a copy of the bufferparams because we do not
985 // want to modify them yet.
986 BufferParams params = lv_->buffer()->params;
988 if (params.textclass != tc
989 && AskQuestion(_("Should I set some parameters to"),
990 _("the defaults of this document class?"))) {
991 params.textclass = tc;
992 params.useClassDefaults();
993 UpdateLayoutDocument(params);
996 // unable to load new style
997 WriteAlert(_("Conversion Errors!"),
998 _("Unable to switch to new document class."),
999 _("Reverting to original document class."));
1000 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1002 AllowInput(lv_->view());
1006 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1012 class_update(params);
1013 paper_update(params);
1014 language_update(params);
1015 options_update(params);
1016 bullets_update(params);