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( _( "latin5" ) );
157 dialog->inputEncCO->insertItem( _( "latin9" ) );
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 (int 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);
216 void QDocument::apply()
218 //if (!lv_->view()->available() || !dialog_.get())
222 bool redo = class_apply();
224 redo = language_apply() || redo;
225 redo = options_apply() || redo;
229 lv_->view()->redoCurrentBuffer();
231 lv_->buffer()->markDirty();
232 setMinibuffer(lv_, _("Document layout set"));
237 void QDocument::cancel()
240 // this avoids confusion when reopening
241 BufferParams & param = lv_->buffer()->params;
242 param.temp_bullets[0] = param.user_defined_bullets[0];
243 param.temp_bullets[1] = param.user_defined_bullets[1];
244 param.temp_bullets[2] = param.user_defined_bullets[2];
245 param.temp_bullets[3] = param.user_defined_bullets[3];
251 void QDocument::update_contents()
259 BufferParams const & params = lv_->buffer()->params;
261 class_update(params);
262 paper_update(params);
263 language_update(params);
264 options_update(params);
265 bullets_update(params);
271 bool QDocument::input( FL_OBJECT * ob, long data )
273 State cb = static_cast<State>( data );
276 case CHECKCHOICECLASS:
277 CheckChoiceClass(ob, 0);
279 case CHOICEBULLETSIZE:
280 ChoiceBulletSize(ob, 0);
282 case INPUTBULLETLATEX:
283 InputBulletLaTeX(ob, 0);
300 BulletBMTable(ob, 0);
308 case CHECKCHOICECLASS:
309 case CHOICEBULLETSIZE:
310 case INPUTBULLETLATEX:
312 return CheckDocumentInput(ob, 0);
321 void QDocument::ComboInputCB(int, void * v, Combox * combox)
323 QDocument * pre = static_cast<QDocument*>(v);
324 if (combox == pre->combo_doc_class.get())
325 pre->CheckChoiceClass(0, 0);
326 pre->bc().valid(pre->CheckDocumentInput(0,0));
329 bool QDocument::class_apply()
332 BufferParams ¶ms = lv_->buffer()->params;
334 // If default skip is a "Length" but there's no text in the
335 // input field, reset the kind to "Medskip", which is the default.
336 if( ( dialog_->docSkipCO->currentItem() == 3 ) &&
337 dialog_->docSkipED->text().isEmpty() )
338 dialog_->docSkipCO->setCurrentItem( 1 );
340 params.fonts = dialog_->docFontsCO->currentText();
341 params.fontsize = dialog_->docFontSizeCO->currentText();
342 params.pagestyle = dialog->docPagestyleCO->currentText();
344 unsigned int const new_class = dialog_->docClassCO->currentItem();
346 if (params.textclass != new_class) {
347 // try to load new_class
348 if (textclasslist.Load(new_class)) {
349 // successfully loaded
351 setMinibuffer(lv_, _("Converting document to new document class..."));
353 int ret = cap.SwitchLayoutsBetweenClasses(params.textclass, new_class,
354 lv_->buffer()->paragraph);
358 s = _("One paragraph couldn't be converted");
361 s += _(" paragraphs couldn't be converted");
363 WriteAlert(_("Conversion Errors!"),s,
364 _("into chosen document class"));
367 params.textclass = new_class;
369 // problem changing class -- warn user and retain old style
370 WriteAlert(_("Conversion Errors!"),
371 _("Errors loading new document class."),
372 _("Reverting to original document class."));
373 dialog_->docClassCO->setCurrentItem( params.textclass );
376 BufferParams::PARSEP tmpsep = params.paragraph_separation;
377 if( dialog_->_docIndentRB->isChecked() )
378 params.paragraph_separation = BufferParams::PARSEP_INDENT;
380 params.paragraph_separation = BufferParams::PARSEP_SKIP;
381 if (tmpsep != params.paragraph_separation)
384 VSpace tmpdefskip = params.getDefSkip();
385 switch( dialog_->docSkipCO->currentItem() ) {
387 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
390 params.setDefSkip(VSpace(VSpace::MEDSKIP));
393 params.setDefSkip(VSpace(VSpace::BIGSKIP));
397 (VSpace(LyXGlueLength(dialog_->docSkipED->text())));
399 // DocumentDefskipCB assures that this never happens
400 // ... so why is there code for it ?
402 params.setDefSkip(VSpace(VSpace::MEDSKIP));
405 if (!(tmpdefskip == params.getDefSkip()))
408 if( dialog_->docColumnsTwo->isChecked() )
412 if( dialog_->docSidesTwo->isChecked() )
413 params.sides = LyXTextClass::TwoSides;
415 params.sides = LyXTextClass::OneSide;
417 Spacing tmpSpacing = params.spacing;
418 switch( dialog_->docSpacingCO->currentItem() ) {
420 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
421 params.spacing.set(Spacing::Single);
424 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
425 params.spacing.set(Spacing::Onehalf);
428 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
429 params.spacing.set(Spacing::Double);
432 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
433 params.spacing.set(Spacing::Other,
434 dialog_->docSpacingED->text() );
437 if (tmpSpacing != params.spacing)
440 params.options = docExtraED->text();
446 void QDocument::paper_apply()
448 BufferParams & params = lv_->buffer()->params;
451 static_cast<char>(dialog_->papersize2CO->currentItem());
452 params.paperpackage =
453 static_cast<char>(dialog_->paperPackageCO->currentItem() );
454 params.use_geometry = dialog_->useGeometryCB->isChecked();
455 if (dialog_->landscapeRB->isChecked() )
456 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
458 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
459 params.paperwidth = dialog_->customWidthED->text();
460 params.paperheight = dialog_->customHeightED->text();
461 params.leftmargin = dialog_->leftMarginED->text();
462 params.topmargin = dialog_->topMarginED->text();
463 params.rightmargin = dialog_->rightMarginED->text();
464 params.bottommargin = dialog_->bottomMarginED->text();
465 params.headheight = dialog_->headHeightED->text();
466 params.headsep = dialog_->headSepED->text();
467 params.footskip = dialog_->footSkipED->text();
468 lv_->buffer()->setPaperStuff();
472 bool QDocument::language_apply()
474 BufferParams & params = lv_->buffer()->params;
475 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
478 switch (dialog_->quotesLanguageCO->currentItem() ) {
480 lga = InsetQuotes::EnglishQ;
483 lga = InsetQuotes::SwedishQ;
486 lga = InsetQuotes::GermanQ;
489 lga = InsetQuotes::PolishQ;
492 lga = InsetQuotes::FrenchQ;
495 lga = InsetQuotes::DanishQ;
498 params.quotes_language = lga;
499 if (dialog_->singleRB->isChecked() )
500 params.quotes_times = InsetQuotes::SingleQ;
502 params.quotes_times = InsetQuotes::DoubleQ;
504 Language const * old_language = params.language;
505 Language const * new_language =
506 languages.getLanguage(dialog_->languageCO->currentItem() );
508 new_language = default_language;
510 if (old_language != new_language
511 && old_language->RightToLeft() == new_language->RightToLeft()
512 && !lv_->buffer()->isMultiLingual())
513 lv_->buffer()->ChangeLanguage(old_language, new_language);
515 if (old_language != new_language)
518 params.language = new_language;
519 params.inputenc = dialog_->inputEncCO->currentText();
525 bool QDocument::options_apply()
527 BufferParams & params = lv_->buffer()->params;
530 params.graphicsDriver =
531 dialog_->postscriptDriverCO->currentText();
532 params.use_amsmath = dialog_->useAmsMathCB->isChecked();
534 int tmpchar = int(dialog_->secNumDepth->value() );
535 if (params.secnumdepth != tmpchar)
537 params.secnumdepth = tmpchar;
539 params.tocdepth = int(dialog_->tocDepth->value() );
541 params.float_placement =
542 dialog_->floatPlacementED->text();
548 void QDocument::bullets_apply()
550 /* update the bullet settings */
551 BufferParams & param = lv_->buffer()->params;
553 // a little bit of loop unrolling
554 param.user_defined_bullets[0] = param.temp_bullets[0];
555 param.user_defined_bullets[1] = param.temp_bullets[1];
556 param.user_defined_bullets[2] = param.temp_bullets[2];
557 param.user_defined_bullets[3] = param.temp_bullets[3];
561 void QDocument::class_update(BufferParams const & params)
566 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
568 combo_doc_class->select_text(
569 textclasslist.DescOfClass(params.textclass));
570 Qt2Helper::setCurrentComboItem( dialog_->docFonts, params.fonts.c_str() );
571 dialog_->docFontSizeCO->clear();
572 dialog_->docFontSizeCO->insertItem( _( "default" ) );
573 dialog_->docFontSizeCO->insertItem( tclass.opt_fontsize().c_str());
574 dialog_->docFontSizeCO->setCurrentItem( tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+1);
575 dialog_->docPagestyleCO->clear();
576 dialog_->docPagestyleCO->insertItem( _( "default" ) );
577 dialog_->docPagestyleCO->insertItem( tclass.opt_pagestyle().c_str());
578 dialog_->docPagestyleCO->setCurrentItem( tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+1);
579 dialog_->docIndentRB->setChecked( false );
580 dialog_->docSkipRB->setChecked( false );
581 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
582 dialog_->docIndentRB->setChecked( true );
584 dialog_->docSkipRB->setChecked( true );
585 switch (params.getDefSkip().kind()) {
586 case VSpace::SMALLSKIP:
587 dialog_->docSkipCO->setCurrentItem( 0 );
589 case VSpace::MEDSKIP:
590 dialog_->docSkipCO->setCurrentItem( 1 );
592 case VSpace::BIGSKIP:
593 dialog_->docSkipCO->setCurrentItem( 2 );
596 dialog_->docSkipCO->setCurrentItem( 3 );
597 dialog_->docSkipED->setText( params.getDefSkip().asLyXCommand().c_str());
600 dialog_->docSkipCO->setCurrentItem( 1 );
603 dialog_->docSidesOneRB->setChecked( false );
604 dialog_->docSidesTwoRB->setChecked( false );
605 if (params.sides == LyXTextClass::TwoSides)
606 dialog_->docSidesTwo->setChecked( true );
608 dialog_->docSidesOne->setChecked( true );
609 dialog_->docColumnsOneRB->setChecked( false );
610 dialog_->docColumnsTwoRB->setChecked( false );
611 if (params.columns == 2)
612 dialog_->docColumnsTwoRB->setChecked( true );
614 dialog_->docColumnsOneRB->setChecked( true );
615 dialog_->docSpacingED->setText( "" );
616 switch (params.spacing.getSpace()) {
617 case Spacing::Default: // nothing bad should happen with this
618 case Spacing::Single:
620 dialog_->docSpacingCO->setCurrentItem( 0 );
622 case Spacing::Onehalf:
624 dialog_->docSpacingCO->setCurrentItem( 1 );
626 case Spacing::Double:
628 dialog_->docSpacingCO->setCurrentItem( 2 );
632 dialog_->docSpacingCO->setCurrentItem( 3 );
634 sval.sprintf("%g",params.spacing.getValue());
635 dialog_->docSpacingED->setText( sval );
639 if (!params.options.empty())
640 dialog_->docExtraED->setText(, params.options.c_str());
642 dialog_->docExtraED->setText( "" );
646 void QDocument::language_update(BufferParams const & params)
648 if (!language_.get())
651 Qt2Helper::setCurrentItemText( dialog_->languageCO, params.language->lang() );
652 Qt2Helper::setCurrentItemText( dialog_->inputEncCO, params.inputenc.c_str() );
653 dialog_->quotesLanguageCO->setCurrentItem( params.quotes_language );
654 dialog_->singleRB->setChecked( false );
655 dialog_->doubleRB->setChecked( false );
656 if (params.quotes_times == InsetQuotes::SingleQ)
657 dialog_->singleRB->setChecked( true );
659 dialog_->doubleRB->setChecked( true );
663 void QDocument::options_update(BufferParams const & params)
668 Qt2Helper::setCurrentItemText( dialog_->postscriptDriverCO,
669 params.graphicsDriver.c_str());
670 dialog_->useAmsMathCB->setChecked( params.use_amsmath );
671 dialog_->secNumDepthSB->setValue( params.secnumdepth );
672 dialog_->setTocDepthSB->setValue( params.tocdepth );
673 if (!params.float_placement.empty())
674 dialog_->floatPlacementED->setText( params.float_placement.c_str());
676 dialog_->floatPlacementED->setText( "" );
680 void QDocument::paper_update(BufferParams const & params)
685 dialog_->papersize2CO->setCurrentItem( params.papersize2 );
686 dialog_->paperPackageCO->setCurrentItem( params.paperpackage );
687 dialog_->useGeometryCB->setChecked( params.use_geometry );
688 dialog_->portraitRB->setChecked( false );
689 dialog_->landscapeRB->setChecked( false );
690 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
691 dialog_->landscapeRB->setChecked( true );
693 dialog_->portraitRB->setChecked( true );
694 dialog_->customWidthED->setText( params.paperwidth.c_str());
695 dialog_->customHeightED->setText( params.paperheight.c_str());
696 dialog_->leftMarginED->setText( params.leftmargin.c_str());
697 dialog_->topMarginED->setText( params.topmargin.c_str());
698 dialog_->rightMarginED->setText( params.rightmargin.c_str());
699 dialog_->bottomMarginED->setText( params.bottommargin.c_str());
700 dialog_->headHeightED->setText( params.headheight.c_str());
701 dialog_->headSepED->setText( params.headsep.c_str());
702 dialog_->footSkipED->setText( params.footskip.c_str());
703 dialog_->papersize2CO->setFocus();
707 void QDocument::bullets_update(BufferParams const & params)
709 bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
710 setEnabled(fbullet, !isLinuxDoc);
712 if (isLinuxDoc) return;
714 dialog_->bulletDepth1RB->setChecked( true );
715 dialog_->bulletLatexED->setText( params.user_defined_bullets[0].getText().c_str());
716 dialog_->bulletSizeCO->setCurrentItem( params.user_defined_bullets[0].getSize() + 1);
720 void QDocument::checkReadOnly()
722 if (bc().readOnly(lv_->buffer()->isReadonly())) {
723 dialog_->docClassCO->setEnabled( false );
724 dialog_->languageCO->setEnabled( false );
725 dialog_->warningLA->setText( _("Document is read-only."
726 " No changes to layout permitted."));
727 dialog_->warningLA->show();
729 dialog_->docClassCO->setEnabled( true );
730 dialog_->languageCO->setEnabled( true );
731 dialog_->warningLA->hide();
736 void QDocument::checkMarginValues()
738 bool const not_empty =
739 !dialog_->topMarginED->text().isEmpty() ||
740 !dialog_->bottomMarginED->text().isEmpty() ||
741 !dialog_->leftMarginED->text().isEmpty() ||
742 !dialog_->rightMarginED->text().isEmpty() ||
743 !dialog_->headHeightED->text().isEmpty() ||
744 !dialog_->headSepED->text().isEmpty() ||
745 !dialog_->footSkipED->text().isEmpty() ||
746 !dialog_->customWidthED->text().isEmpty() ||
747 !dialog_->customHeightED->text().isEmpty();
749 dialog_->useGeometryCB->setChecked( true );
752 #ifdef I_SUPPOSE_THIS_NEEDS_TO_FIXED
753 bool QDocument::CheckDocumentInput(FL_OBJECT * ob, long)
761 if (ob == paper_->choice_papersize2) {
762 val = fl_get_choice(paper_->choice_papersize2)-1;
763 if (val == BufferParams::VM_PAPER_DEFAULT) {
764 fl_set_button(paper_->push_use_geometry, 0);
767 if ((val != BufferParams::VM_PAPER_USLETTER) &&
768 (val != BufferParams::VM_PAPER_USLEGAL) &&
769 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
770 (val != BufferParams::VM_PAPER_A4) &&
771 (val != BufferParams::VM_PAPER_A5) &&
772 (val != BufferParams::VM_PAPER_B5)) {
773 fl_set_button(paper_->push_use_geometry, 1);
775 fl_set_choice(paper_->choice_paperpackage,
776 BufferParams::PACKAGE_NONE + 1);
778 } else if (ob == paper_->choice_paperpackage) {
779 val = fl_get_choice(paper_->choice_paperpackage)-1;
780 if (val != BufferParams::PACKAGE_NONE) {
781 fl_set_choice(paper_->choice_papersize2,
782 BufferParams::VM_PAPER_DEFAULT + 1);
783 fl_set_button(paper_->push_use_geometry, 0);
785 } else if (ob == class_->input_doc_spacing) {
786 input = fl_get_input(class_->input_doc_spacing);
788 fl_set_choice (class_->choice_doc_spacing, 1);
790 fl_set_choice(class_->choice_doc_spacing, 4);
793 // this has to be all out of if/elseif because it has to deactivate
794 // the document buttons and so the whole stuff has to be tested again.
795 str = fl_get_input(paper_->input_custom_width);
796 ok = ok && (str.empty() || isValidLength(str));
797 str = fl_get_input(paper_->input_custom_height);
798 ok = ok && (str.empty() || isValidLength(str));
799 str = fl_get_input(paper_->input_left_margin);
800 ok = ok && (str.empty() || isValidLength(str));
801 str = fl_get_input(paper_->input_right_margin);
802 ok = ok && (str.empty() || isValidLength(str));
803 str = fl_get_input(paper_->input_top_margin);
804 ok = ok && (str.empty() || isValidLength(str));
805 str = fl_get_input(paper_->input_bottom_margin);
806 ok = ok && (str.empty() || isValidLength(str));
807 str = fl_get_input(paper_->input_head_height);
808 ok = ok && (str.empty() || isValidLength(str));
809 str = fl_get_input(paper_->input_head_sep);
810 ok = ok && (str.empty() || isValidLength(str));
811 str = fl_get_input(paper_->input_foot_skip);
812 ok = ok && (str.empty() || isValidLength(str));
813 // "Synchronize" the choice and the input field, so that it
814 // is impossible to commit senseless data.
815 input = fl_get_input (class_->input_doc_skip);
816 if (ob == class_->input_doc_skip) {
818 fl_set_choice (class_->choice_doc_skip, 2);
819 } else if (isValidGlueLength (input)) {
820 fl_set_choice (class_->choice_doc_skip, 4);
822 fl_set_choice(class_->choice_doc_skip, 4);
826 if (*input && !isValidGlueLength(input))
829 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
831 else if (fl_get_choice(class_->choice_doc_skip) != 4)
832 fl_set_input (class_->input_doc_skip, "");
834 input = fl_get_input(class_->input_doc_spacing);
835 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
837 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
838 fl_set_input (class_->input_doc_spacing, "");
843 void QDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
845 BufferParams & param = lv_->buffer()->params;
847 // convert from 1-6 range to -1-4
848 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
849 fl_set_input(bullets_->input_bullet_latex,
850 param.temp_bullets[current_bullet_depth].getText().c_str());
854 void QDocument::InputBulletLaTeX(FL_OBJECT *, long)
856 BufferParams & param = lv_->buffer()->params;
858 param.temp_bullets[current_bullet_depth].
859 setText(fl_get_input(bullets_->input_bullet_latex));
863 void QDocument::BulletDepth(FL_OBJECT * ob, State cb)
865 /* Should I do the following:
866 * 1. change to the panel that the current bullet belongs in
867 * 2. show that bullet as selected
868 * 3. change the size setting to the size of the bullet in Q.
869 * 4. display the latex equivalent in the latex box
871 * I'm inclined to just go with 3 and 4 at the moment and
872 * maybe try to support the others later
874 BufferParams & param = lv_->buffer()->params;
877 if (cb == BULLETDEPTH1 )
879 else if (cb == BULLETDEPTH2 )
881 else if (cb == BULLETDEPTH3 )
883 else if (cb == BULLETDEPTH4 )
886 switch (fl_get_button_numb(ob)) {
888 // right mouse button resets to default
889 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
891 current_bullet_depth = data;
892 fl_set_input(bullets_->input_bullet_latex,
893 param.temp_bullets[data].getText().c_str());
894 fl_set_choice(bullets_->choice_bullet_size,
895 param.temp_bullets[data].getSize() + 2);
900 void QDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
902 /* Here we have to change the background pixmap to that selected */
903 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
906 if (cb == BULLETPANEL1 )
908 else if (cb == BULLETPANEL2 )
910 else if (cb == BULLETPANEL3 )
912 else if (cb == BULLETPANEL4 )
914 else if (cb == BULLETPANEL5 )
916 else if (cb == BULLETPANEL6 )
919 if (data != current_bullet_panel) {
920 fl_freeze_form(bullets_->form);
921 current_bullet_panel = data;
923 /* free the current pixmap */
924 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
927 /* display the new one */
929 new_panel = "standard";
932 new_panel = "amssymb";
935 new_panel = "psnfss1";
938 new_panel = "psnfss2";
941 new_panel = "psnfss3";
944 new_panel = "psnfss4";
947 /* something very wrong happened */
948 // play it safe for now but should be an exception
949 current_bullet_panel = 0; // standard panel
950 new_panel = "standard";
954 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
955 LibFileSearch("images", new_panel).c_str());
956 fl_redraw_object(bullets_->bmtable_bullet_panel);
957 fl_unfreeze_form(bullets_->form);
962 void QDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
964 /* handle the user input by setting the current bullet depth's pixmap */
965 /* to that extracted from the current chosen position of the BMTable */
966 /* Don't forget to free the button's old pixmap first. */
968 BufferParams & param = lv_->buffer()->params;
969 int bmtable_button = fl_get_bmtable(ob);
971 /* try to keep the button held down till another is pushed */
972 /* fl_set_bmtable(ob, 1, bmtable_button); */
973 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
974 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
975 fl_set_input(bullets_->input_bullet_latex,
976 param.temp_bullets[current_bullet_depth].getText().c_str());
980 void QDocument::CheckChoiceClass(FL_OBJECT * ob, long)
983 ob = class_->choice_doc_class;
985 ProhibitInput(lv_->view());
987 unsigned int tc = combo_doc_class->get() - 1;
988 if (textclasslist.Load(tc)) {
989 // we use a copy of the bufferparams because we do not
990 // want to modify them yet.
991 BufferParams params = lv_->buffer()->params;
993 if (params.textclass != tc
994 && AskQuestion(_("Should I set some parameters to"),
995 _("the defaults of this document class?"))) {
996 params.textclass = tc;
997 params.useClassDefaults();
998 UpdateLayoutDocument(params);
1001 // unable to load new style
1002 WriteAlert(_("Conversion Errors!"),
1003 _("Unable to switch to new document class."),
1004 _("Reverting to original document class."));
1005 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1007 AllowInput(lv_->view());
1011 void QDocument::UpdateLayoutDocument(BufferParams const & params)
1017 class_update(params);
1018 paper_update(params);
1019 language_update(params);
1020 options_update(params);
1021 bullets_update(params);