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"))
52 void QDocument::build()
57 //dialog_.reset(new QDocumentDialog());
60 // Manage the restore, ok, apply, restore and cancel/close buttons
61 bc().setOK(dialog_->okPB);
62 bc().setApply(dialog_->applyPB);
63 bc().setCancel(dialog_->cancelPB);
64 bc().setRestore(dialog_->restorePB);
67 // the document paper page
68 QDocumentDialog * dialog = dialog_.get();
69 dialog->papersize2CO->insertItem( _( "Default" ) );
70 dialog->papersize2CO->insertItem( _( "Custom" ) );
71 dialog->papersize2CO->insertItem( _( "USletter" ) );
72 dialog->papersize2CO->insertItem( _( "USlegal" ) );
73 dialog->papersize2CO->insertItem( _( "USexecutive" ) );
74 dialog->papersize2CO->insertItem( _( "A3" ) );
75 dialog->papersize2CO->insertItem( _( "A4" ) );
76 dialog->papersize2CO->insertItem( _( "A5" ) );
77 dialog->papersize2CO->insertItem( _( "B3" ) );
78 dialog->papersize2CO->insertItem( _( "B4" ) );
79 dialog->papersize2CO->insertItem( _( "B5" ) );
81 dialog->paperPackageCO->insertItem( _( "None" ) );
82 dialog->paperPackageCO->insertItem( _( "A4 small Margins (only portrait)" ) );
83 dialog->paperPackageCO->insertItem( _( "A4 very small Margins (only portrait)" ) );
84 dialog->paperPackageCO->insertItem( _( "A4 very wide margins (only portrait)" ) );
86 bc().addReadOnly (dialog->paperPackageCO);
87 bc().addReadOnly (dialog->orientationBG);
88 bc().addReadOnly (dialog->portraitRB);
89 bc().addReadOnly (dialog->landscapeRB);
90 bc().addReadOnly (dialog->papersize2CO);
91 bc().addReadOnly (dialog->useGeometryCB);
92 bc().addReadOnly (dialog->customWidthED);
93 bc().addReadOnly (dialog->customHeightED);
94 bc().addReadOnly (dialog->topMarginED);
95 bc().addReadOnly (dialog->bottomMarginED);
96 bc().addReadOnly (dialog->leftMarginED);
97 bc().addReadOnly (dialog->rightMarginED);
98 bc().addReadOnly (dialog->headHeightED);
99 bc().addReadOnly (dialog->headSepED);
100 bc().addReadOnly (dialog->footSkipED);
103 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
104 cit != textclasslist.end(); ++cit) {
105 docClassCO->insertItem( (*cit).description().c_str() );
108 dialog->docSpacingCO->insertItem( _( "Single" ) );
109 dialog->docSpacingCO->insertItem( _( "OneHalf" ) );
110 dialog->docSpacingCO->insertItem( _( "Double" ) );
111 dialog->docSpacingCO->insertItem( _( "Other" ) );
113 dialog->docFontSizeCO->insertItem( _( "default" ) );
114 dialog->docFontSizeCO->insertItem( _( "10" ) );
115 dialog->docFontSizeCO->insertItem( _( "11" ) );
116 dialog->docFontSizeCO->insertItem( _( "12" ) );
117 for (n=0; tex_fonts[n][0]; ++n) {
118 dialog->docFontsCO->insertItem( tex_fonts[n] );
121 dialog->docPagestyleCO->insertItem( _( "default" ) );
122 dialog->docPagestyleCO->insertItem( _( "empty" ) );
123 dialog->docPagestyleCO->insertItem( _( "plain" ) );
124 dialog->docPagestyleCO->insertItem( _( "headings" ) );
125 dialog->docPagestyleCO->insertItem( _( "fancy" ) );
127 dialog->docSkipCO->insertItem( _( "Smallskip" ) );
128 dialog->docSkipCO->insertItem( _( "Medskip" ) );
129 dialog->docSkipCO->insertItem( _( "Bigskip" ) );
130 dialog->docSkipCO->insertItem( _( "Length" ) );
132 bc().addReadOnly (dialog->docIndentRB);
133 bc().addReadOnly (dialog->docSkipRB);
135 bc().addReadOnly (dialog->docPagestyleCO);
136 bc().addReadOnly (dialog->docFontsCO);
137 bc().addReadOnly (dialog->docFontsizeCO);
138 bc().addReadOnly (dialog->docSidesOneRB);
139 bc().addReadOnly (dialog->docSidesTwoRB);
140 bc().addReadOnly (dialog->docColumnsOneRB);
141 bc().addReadOnly (dialog->docColumnsTwoRB);
142 bc().addReadOnly (dialog->docExtraED);
143 bc().addReadOnly (dialog->docSkipED);
144 bc().addReadOnly (dialog->docSkipCO);
145 bc().addReadOnly (dialog->docSpacingCO);
146 bc().addReadOnly (dialog->docSpacingED);
148 // the document language page
149 dialog->inputEncCO->insertItem( _( "default" ) );
150 dialog->inputEncCO->insertItem( _( "auto" ) );
151 dialog->inputEncCO->insertItem( _( "latin1" ) );
152 dialog->inputEncCO->insertItem( _( "latin2" ) );
153 dialog->inputEncCO->insertItem( _( "latin5" ) );
154 dialog->inputEncCO->insertItem( _( "latin9" ) );
155 dialog->inputEncCO->insertItem( _( "koi8-r" ) );
156 dialog->inputEncCO->insertItem( _( "koi8-u" ) );
157 dialog->inputEncCO->insertItem( _( "cp866" ) );
158 dialog->inputEncCO->insertItem( _( "cp1251" ) );
159 dialog->inputEncCO->insertItem( _( "iso88595" ) );
161 for (Languages::const_iterator cit = languages.begin();
162 cit != languages.end(); ++cit) {
163 dialog->languageCO->insertItem( (*cit).second.lang() );
166 dialog->quotesLanguageCO->insertItem( _( "``text''" ) );
167 dialog->quotesLanguageCO->insertItem( _( "''text''" ) );
168 dialog->quotesLanguageCO->insertItem( _( ",,text``" ) );
169 dialog->quotesLanguageCO->insertItem( _( ",,text''" ) );
170 dialog->quotesLanguageCO->insertItem( _( "«text»" ) );
171 dialog->quotesLanguageCO->insertItem( _( "»text«" ) );
173 bc().addReadOnly (dialog->inputEncCO);
175 // the document options page
176 dialog->secNumDepthSB->setRange( -2, 5 );
177 dialog->tocDepthSB->setRange( -1, 5 );
178 dialog->secNumDepthSB->setSteps( 1, 1 );
179 dialog->tocDepthSB->setRange( 1, 1 );
180 for (n=0; tex_graphics[n][0]; ++n) {
181 dialog->postscriptDriverCO->insertItem( tex_graphics[n] );
184 bc().addReadOnly (dialog->secNumDepthSB);
185 bc().addReadOnly (dialog->tocDepthSB);
186 bc().addReadOnly (dialog->useAmsMathCB);
187 bc().addReadOnly (dialog->floatPlacementED);
188 bc().addReadOnly (dialog->postscriptDriverCO);
190 // the document bullets page
191 dialog->bulletSizeCO->insertItem( _( "default" ) );
192 dialog->bulletSizeCO->insertItem( _( "tiny" ) );
193 dialog->bulletSizeCO->insertItem( _( "script" ) );
194 dialog->bulletSizeCO->insertItem( _( "footnote" ) );
195 dialog->bulletSizeCO->insertItem( _( "small" ) );
196 dialog->bulletSizeCO->insertItem( _( "normal" ) );
197 dialog->bulletSizeCO->insertItem( _( "large" ) );
198 dialog->bulletSizeCO->insertItem( _( "Large" ) );
199 dialog->bulletSizeCO->insertItem( _( "LARGE" ) );
200 dialog->bulletSizeCO->insertItem( _( "huge" ) );
201 dialog->bulletSizeCO->insertItem( _( "Huge" ) );
203 dialog->bulletSizeCO->setCurrentItem( 0 );
204 dialog->bulletLatexED->setMaxLength( 80 );
206 bc().addReadOnly (dialog->bulletPanelBG);
207 bc().addReadOnly (dialog->bulletSizeCO);
208 bc().addReadOnly (dialog->bulletLatexED);
213 void QDocument::apply()
215 //if (!lv_->view()->available() || !dialog_.get())
219 bool redo = class_apply();
221 redo = language_apply() || redo;
222 redo = options_apply() || redo;
226 lv_->view()->redoCurrentBuffer();
228 lv_->buffer()->markDirty();
229 setMinibuffer(lv_, _("Document layout set"));
234 void QDocument::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];
248 void QDocument::update()
256 BufferParams const & params = lv_->buffer()->params;
258 class_update(params);
259 paper_update(params);
260 language_update(params);
261 options_update(params);
262 bullets_update(params);
268 bool QDocument::input( FL_OBJECT * ob, long data )
270 State cb = static_cast<State>( data );
273 case CHECKCHOICECLASS:
274 CheckChoiceClass(ob, 0);
276 case CHOICEBULLETSIZE:
277 ChoiceBulletSize(ob, 0);
279 case INPUTBULLETLATEX:
280 InputBulletLaTeX(ob, 0);
297 BulletBMTable(ob, 0);
305 case CHECKCHOICECLASS:
306 case CHOICEBULLETSIZE:
307 case INPUTBULLETLATEX:
309 return CheckDocumentInput(ob, 0);
318 void QDocument::ComboInputCB(int, void * v, Combox * combox)
320 QDocument * pre = static_cast<QDocument*>(v);
321 if (combox == pre->combo_doc_class.get())
322 pre->CheckChoiceClass(0, 0);
323 pre->bc().valid(pre->CheckDocumentInput(0,0));
326 bool QDocument::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(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
397 // ... so why is there code for it ?
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 QDocument::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 QDocument::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);
512 if (old_language != new_language)
515 params.language = new_language;
516 params.inputenc = dialog_->inputEncCO->currentText();
522 bool QDocument::options_apply()
524 BufferParams & params = lv_->buffer()->params;
527 params.graphicsDriver =
528 dialog_->postscriptDriverCO->currentText();
529 params.use_amsmath = dialog_->useAmsMathCB->isChecked();
531 int tmpchar = int(dialog_->secNumDepth->value() );
532 if (params.secnumdepth != tmpchar)
534 params.secnumdepth = tmpchar;
536 params.tocdepth = int(dialog_->tocDepth->value() );
538 params.float_placement =
539 dialog_->floatPlacementED->text();
545 void QDocument::bullets_apply()
547 /* update the bullet settings */
548 BufferParams & param = lv_->buffer()->params;
550 // a little bit of loop unrolling
551 param.user_defined_bullets[0] = param.temp_bullets[0];
552 param.user_defined_bullets[1] = param.temp_bullets[1];
553 param.user_defined_bullets[2] = param.temp_bullets[2];
554 param.user_defined_bullets[3] = param.temp_bullets[3];
558 void QDocument::class_update(BufferParams const & params)
563 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
565 combo_doc_class->select_text(
566 textclasslist.DescOfClass(params.textclass));
567 Qt2Helper::setCurrentComboItem( dialog_->docFonts, params.fonts.c_str() );
568 dialog_->docFontSizeCO->clear();
569 dialog_->docFontSizeCO->insertItem( _( "default" ) );
570 dialog_->docFontSizeCO->insertItem( tclass.opt_fontsize().c_str());
571 dialog_->docFontSizeCO->setCurrentItem( tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+1);
572 dialog_->docPagestyleCO->clear();
573 dialog_->docPagestyleCO->insertItem( _( "default" ) );
574 dialog_->docPagestyleCO->insertItem( tclass.opt_pagestyle().c_str());
575 dialog_->docPagestyleCO->setCurrentItem( tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+1);
576 dialog_->docIndentRB->setChecked( false );
577 dialog_->docSkipRB->setChecked( false );
578 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
579 dialog_->docIndentRB->setChecked( true );
581 dialog_->docSkipRB->setChecked( true );
582 switch (params.getDefSkip().kind()) {
583 case VSpace::SMALLSKIP:
584 dialog_->docSkipCO->setCurrentItem( 0 );
586 case VSpace::MEDSKIP:
587 dialog_->docSkipCO->setCurrentItem( 1 );
589 case VSpace::BIGSKIP:
590 dialog_->docSkipCO->setCurrentItem( 2 );
593 dialog_->docSkipCO->setCurrentItem( 3 );
594 dialog_->docSkipED->setText( params.getDefSkip().asLyXCommand().c_str());
597 dialog_->docSkipCO->setCurrentItem( 1 );
600 dialog_->docSidesOneRB->setChecked( false );
601 dialog_->docSidesTwoRB->setChecked( false );
602 if (params.sides == LyXTextClass::TwoSides)
603 dialog_->docSidesTwo->setChecked( true );
605 dialog_->docSidesOne->setChecked( true );
606 dialog_->docColumnsOneRB->setChecked( false );
607 dialog_->docColumnsTwoRB->setChecked( false );
608 if (params.columns == 2)
609 dialog_->docColumnsTwoRB->setChecked( true );
611 dialog_->docColumnsOneRB->setChecked( true );
612 dialog_->docSpacingED->setText( "" );
613 switch (params.spacing.getSpace()) {
614 case Spacing::Default: // nothing bad should happen with this
615 case Spacing::Single:
617 dialog_->docSpacingCO->setCurrentItem( 0 );
619 case Spacing::Onehalf:
621 dialog_->docSpacingCO->setCurrentItem( 1 );
623 case Spacing::Double:
625 dialog_->docSpacingCO->setCurrentItem( 2 );
629 dialog_->docSpacingCO->setCurrentItem( 3 );
631 sval.sprintf("%g",params.spacing.getValue());
632 dialog_->docSpacingED->setText( sval );
636 if (!params.options.empty())
637 dialog_->docExtraED->setText(, params.options.c_str());
639 dialog_->docExtraED->setText( "" );
643 void QDocument::language_update(BufferParams const & params)
645 if (!language_.get())
648 Qt2Helper::setCurrentItemText( dialog_->languageCO, params.language->lang() );
649 Qt2Helper::setCurrentItemText( dialog_->inputEncCO, params.inputenc.c_str() );
650 dialog_->quotesLanguageCO->setCurrentItem( params.quotes_language );
651 dialog_->singleRB->setChecked( false );
652 dialog_->doubleRB->setChecked( false );
653 if (params.quotes_times == InsetQuotes::SingleQ)
654 dialog_->singleRB->setChecked( true );
656 dialog_->doubleRB->setChecked( true );
660 void QDocument::options_update(BufferParams const & params)
665 Qt2Helper::setCurrentItemText( dialog_->postscriptDriverCO,
666 params.graphicsDriver.c_str());
667 dialog_->useAmsMathCB->setChecked( params.use_amsmath );
668 dialog_->secNumDepthSB->setValue( params.secnumdepth );
669 dialog_->setTocDepthSB->setValue( params.tocdepth );
670 if (!params.float_placement.empty())
671 dialog_->floatPlacementED->setText( params.float_placement.c_str());
673 dialog_->floatPlacementED->setText( "" );
677 void QDocument::paper_update(BufferParams const & params)
682 dialog_->papersize2CO->setCurrentItem( params.papersize2 );
683 dialog_->paperPackageCO->setCurrentItem( params.paperpackage );
684 dialog_->useGeometryCB->setChecked( params.use_geometry );
685 dialog_->portraitRB->setChecked( false );
686 dialog_->landscapeRB->setChecked( false );
687 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
688 dialog_->landscapeRB->setChecked( true );
690 dialog_->portraitRB->setChecked( true );
691 dialog_->customWidthED->setText( params.paperwidth.c_str());
692 dialog_->customHeightED->setText( params.paperheight.c_str());
693 dialog_->leftMarginED->setText( params.leftmargin.c_str());
694 dialog_->topMarginED->setText( params.topmargin.c_str());
695 dialog_->rightMarginED->setText( params.rightmargin.c_str());
696 dialog_->bottomMarginED->setText( params.bottommargin.c_str());
697 dialog_->headHeightED->setText( params.headheight.c_str());
698 dialog_->headSepED->setText( params.headsep.c_str());
699 dialog_->footSkipED->setText( params.footskip.c_str());
700 dialog_->papersize2CO->setFocus();
704 void QDocument::bullets_update(BufferParams const & params)
706 bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
707 setEnabled(fbullet, !isLinuxDoc);
709 if (isLinuxDoc) return;
711 dialog_->bulletDepth1RB->setChecked( true );
712 dialog_->bulletLatexED->setText( params.user_defined_bullets[0].getText().c_str());
713 dialog_->bulletSizeCO->setCurrentItem( params.user_defined_bullets[0].getSize() + 1);
717 void QDocument::checkReadOnly()
719 if (bc().readOnly(lv_->buffer()->isReadonly())) {
720 dialog_->docClassCO->setEnabled( false );
721 dialog_->languageCO->setEnabled( false );
722 dialog_->warningLA->setText( _("Document is read-only."
723 " No changes to layout permitted."));
724 dialog_->warningLA->show();
726 dialog_->docClassCO->setEnabled( true );
727 dialog_->languageCO->setEnabled( true );
728 dialog_->warningLA->hide();
733 void QDocument::checkMarginValues()
735 bool const not_empty =
736 !dialog_->topMarginED->text().isEmpty() ||
737 !dialog_->bottomMarginED->text().isEmpty() ||
738 !dialog_->leftMarginED->text().isEmpty() ||
739 !dialog_->rightMarginED->text().isEmpty() ||
740 !dialog_->headHeightED->text().isEmpty() ||
741 !dialog_->headSepED->text().isEmpty() ||
742 !dialog_->footSkipED->text().isEmpty() ||
743 !dialog_->customWidthED->text().isEmpty() ||
744 !dialog_->customHeightED->text().isEmpty();
746 dialog_->useGeometryCB->setChecked( true );
749 #ifdef I_SUPPOSE_THIS_NEEDS_TO_FIXED
750 bool QDocument::CheckDocumentInput(FL_OBJECT * ob, long)
758 if (ob == paper_->choice_papersize2) {
759 val = fl_get_choice(paper_->choice_papersize2)-1;
760 if (val == BufferParams::VM_PAPER_DEFAULT) {
761 fl_set_button(paper_->push_use_geometry, 0);
764 if ((val != BufferParams::VM_PAPER_USLETTER) &&
765 (val != BufferParams::VM_PAPER_USLEGAL) &&
766 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
767 (val != BufferParams::VM_PAPER_A4) &&
768 (val != BufferParams::VM_PAPER_A5) &&
769 (val != BufferParams::VM_PAPER_B5)) {
770 fl_set_button(paper_->push_use_geometry, 1);
772 fl_set_choice(paper_->choice_paperpackage,
773 BufferParams::PACKAGE_NONE + 1);
775 } else if (ob == paper_->choice_paperpackage) {
776 val = fl_get_choice(paper_->choice_paperpackage)-1;
777 if (val != BufferParams::PACKAGE_NONE) {
778 fl_set_choice(paper_->choice_papersize2,
779 BufferParams::VM_PAPER_DEFAULT + 1);
780 fl_set_button(paper_->push_use_geometry, 0);
782 } else if (ob == class_->input_doc_spacing) {
783 input = fl_get_input(class_->input_doc_spacing);
785 fl_set_choice (class_->choice_doc_spacing, 1);
787 fl_set_choice(class_->choice_doc_spacing, 4);
790 // this has to be all out of if/elseif because it has to deactivate
791 // the document buttons and so the whole stuff has to be tested again.
792 str = fl_get_input(paper_->input_custom_width);
793 ok = ok && (str.empty() || isValidLength(str));
794 str = fl_get_input(paper_->input_custom_height);
795 ok = ok && (str.empty() || isValidLength(str));
796 str = fl_get_input(paper_->input_left_margin);
797 ok = ok && (str.empty() || isValidLength(str));
798 str = fl_get_input(paper_->input_right_margin);
799 ok = ok && (str.empty() || isValidLength(str));
800 str = fl_get_input(paper_->input_top_margin);
801 ok = ok && (str.empty() || isValidLength(str));
802 str = fl_get_input(paper_->input_bottom_margin);
803 ok = ok && (str.empty() || isValidLength(str));
804 str = fl_get_input(paper_->input_head_height);
805 ok = ok && (str.empty() || isValidLength(str));
806 str = fl_get_input(paper_->input_head_sep);
807 ok = ok && (str.empty() || isValidLength(str));
808 str = fl_get_input(paper_->input_foot_skip);
809 ok = ok && (str.empty() || isValidLength(str));
810 // "Synchronize" the choice and the input field, so that it
811 // is impossible to commit senseless data.
812 input = fl_get_input (class_->input_doc_skip);
813 if (ob == class_->input_doc_skip) {
815 fl_set_choice (class_->choice_doc_skip, 2);
816 } else if (isValidGlueLength (input)) {
817 fl_set_choice (class_->choice_doc_skip, 4);
819 fl_set_choice(class_->choice_doc_skip, 4);
823 if (*input && !isValidGlueLength(input))
826 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
828 else if (fl_get_choice(class_->choice_doc_skip) != 4)
829 fl_set_input (class_->input_doc_skip, "");
831 input = fl_get_input(class_->input_doc_spacing);
832 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
834 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
835 fl_set_input (class_->input_doc_spacing, "");
840 void QDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
842 BufferParams & param = lv_->buffer()->params;
844 // convert from 1-6 range to -1-4
845 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
846 fl_set_input(bullets_->input_bullet_latex,
847 param.temp_bullets[current_bullet_depth].getText().c_str());
851 void QDocument::InputBulletLaTeX(FL_OBJECT *, long)
853 BufferParams & param = lv_->buffer()->params;
855 param.temp_bullets[current_bullet_depth].
856 setText(fl_get_input(bullets_->input_bullet_latex));
860 void QDocument::BulletDepth(FL_OBJECT * ob, State cb)
862 /* Should I do the following:
863 * 1. change to the panel that the current bullet belongs in
864 * 2. show that bullet as selected
865 * 3. change the size setting to the size of the bullet in Q.
866 * 4. display the latex equivalent in the latex box
868 * I'm inclined to just go with 3 and 4 at the moment and
869 * maybe try to support the others later
871 BufferParams & param = lv_->buffer()->params;
874 if (cb == BULLETDEPTH1 )
876 else if (cb == BULLETDEPTH2 )
878 else if (cb == BULLETDEPTH3 )
880 else if (cb == BULLETDEPTH4 )
883 switch (fl_get_button_numb(ob)) {
885 // right mouse button resets to default
886 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
888 current_bullet_depth = data;
889 fl_set_input(bullets_->input_bullet_latex,
890 param.temp_bullets[data].getText().c_str());
891 fl_set_choice(bullets_->choice_bullet_size,
892 param.temp_bullets[data].getSize() + 2);
897 void QDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
899 /* Here we have to change the background pixmap to that selected */
900 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
903 if (cb == BULLETPANEL1 )
905 else if (cb == BULLETPANEL2 )
907 else if (cb == BULLETPANEL3 )
909 else if (cb == BULLETPANEL4 )
911 else if (cb == BULLETPANEL5 )
913 else if (cb == BULLETPANEL6 )
916 if (data != current_bullet_panel) {
917 fl_freeze_form(bullets_->form);
918 current_bullet_panel = data;
920 /* free the current pixmap */
921 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
924 /* display the new one */
926 new_panel = "standard";
929 new_panel = "amssymb";
932 new_panel = "psnfss1";
935 new_panel = "psnfss2";
938 new_panel = "psnfss3";
941 new_panel = "psnfss4";
944 /* something very wrong happened */
945 // play it safe for now but should be an exception
946 current_bullet_panel = 0; // standard panel
947 new_panel = "standard";
951 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
952 LibFileSearch("images", new_panel).c_str());
953 fl_redraw_object(bullets_->bmtable_bullet_panel);
954 fl_unfreeze_form(bullets_->form);
959 void QDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
961 /* handle the user input by setting the current bullet depth's pixmap */
962 /* to that extracted from the current chosen position of the BMTable */
963 /* Don't forget to free the button's old pixmap first. */
965 BufferParams & param = lv_->buffer()->params;
966 int bmtable_button = fl_get_bmtable(ob);
968 /* try to keep the button held down till another is pushed */
969 /* fl_set_bmtable(ob, 1, bmtable_button); */
970 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
971 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
972 fl_set_input(bullets_->input_bullet_latex,
973 param.temp_bullets[current_bullet_depth].getText().c_str());
977 void QDocument::CheckChoiceClass(FL_OBJECT * ob, long)
980 ob = class_->choice_doc_class;
982 ProhibitInput(lv_->view());
984 unsigned int tc = combo_doc_class->get() - 1;
985 if (textclasslist.Load(tc)) {
986 // we use a copy of the bufferparams because we do not
987 // want to modify them yet.
988 BufferParams params = lv_->buffer()->params;
990 if (params.textclass != tc
991 && AskQuestion(_("Should I set some parameters to"),
992 _("the defaults of this document class?"))) {
993 params.textclass = tc;
994 params.useClassDefaults();
995 UpdateLayoutDocument(params);
998 // unable to load new style
999 WriteAlert(_("Conversion Errors!"),
1000 _("Unable to switch to new document class."),
1001 _("Reverting to original document class."));
1002 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1004 AllowInput(lv_->view());
1008 void QDocument::UpdateLayoutDocument(BufferParams const & params)
1014 class_update(params);
1015 paper_update(params);
1016 language_update(params);
1017 options_update(params);
1018 bullets_update(params);