1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000 The LyX Team.
10 *======================================================*/
15 #pragma implementation
18 #include "lyx_gui_misc.h"
19 #include FORMS_H_LOCATION
20 #include XPM_H_LOCATION
22 #include "FormDocument.h"
23 #include "form_document.h"
27 #include "tex-strings.h"
28 #include "bufferparams.h"
29 #include "insets/insetquotes.h"
32 #include "support/filetools.h"
35 #include "BufferView.h"
38 #include "CutAndPaste.h"
39 #include "bufferview_funcs.h"
41 #ifdef CXX_WORKING_NAMESPACES
42 using Liason::setMinibuffer;
45 #define USE_CLASS_COMBO 1
47 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
48 : FormBaseBD(lv, d, _("Document Layout"),
49 new NoRepeatedApplyReadOnlyPolicy),
50 dialog_(0), paper_(0), class_(0), language_(0), options_(0),
51 bullets_(0), current_bullet_panel(0), current_bullet_depth(0),
52 fbullet(0), combo_language(0), combo_doc_class(0)
54 // let the popup be shown
55 // This is a permanent connection so we won't bother
56 // storing a copy because we won't be disconnecting.
57 d->showLayoutDocument.connect(slot(this, &FormDocument::show));
61 FormDocument::~FormDocument()
63 #ifdef USE_CLASS_COMBO
64 delete combo_doc_class;
68 delete combo_language;
76 void FormDocument::redraw()
78 if( form() && form()->visible )
79 fl_redraw_form( form() );
83 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabbed_folder);
84 if (outer_form && outer_form->visible)
85 fl_redraw_form( outer_form );
89 FL_FORM * FormDocument::form() const
91 if (dialog_) return dialog_->form;
96 void FormDocument::build()
101 dialog_ = build_tabbed_document();
103 // Manage the restore, ok, apply, restore and cancel/close buttons
104 bc_.setOK(dialog_->button_ok);
105 bc_.setApply(dialog_->button_apply);
106 bc_.setCancel(dialog_->button_cancel);
107 bc_.setUndoAll(dialog_->button_restore);
110 // Workaround dumb xforms sizing bug
114 // the document paper form
115 paper_ = build_doc_paper();
116 fl_addto_choice(paper_->choice_papersize2,
117 _(" Default | Custom | USletter | USlegal "
118 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
119 fl_addto_choice(paper_->choice_paperpackage,
121 "| A4 small Margins (only portrait) "
122 "| A4 very small Margins (only portrait) "
123 "| A4 very wide margins (only portrait) "));
124 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
125 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
126 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
127 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
128 fl_set_input_return(paper_->input_left_margin, FL_RETURN_CHANGED);
129 fl_set_input_return(paper_->input_right_margin, FL_RETURN_CHANGED);
130 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
131 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
132 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
134 bc_.addReadOnly (paper_->choice_paperpackage);
135 bc_.addReadOnly (paper_->greoup_radio_orientation);
136 bc_.addReadOnly (paper_->radio_portrait);
137 bc_.addReadOnly (paper_->radio_landscape);
138 bc_.addReadOnly (paper_->choice_papersize2);
139 bc_.addReadOnly (paper_->push_use_geometry);
140 bc_.addReadOnly (paper_->input_custom_width);
141 bc_.addReadOnly (paper_->input_custom_height);
142 bc_.addReadOnly (paper_->input_top_margin);
143 bc_.addReadOnly (paper_->input_bottom_margin);
144 bc_.addReadOnly (paper_->input_left_margin);
145 bc_.addReadOnly (paper_->input_right_margin);
146 bc_.addReadOnly (paper_->input_head_height);
147 bc_.addReadOnly (paper_->input_head_sep);
148 bc_.addReadOnly (paper_->input_foot_skip);
150 // the document class form
151 class_ = build_doc_class();
154 #ifdef USE_CLASS_COMBO
155 // The language is a combo-box and has to be inserted manually
156 obj = class_->choice_doc_class;
157 fl_deactivate_object(obj);
158 fl_addto_form(class_->form);
159 combo_doc_class = new Combox(FL_COMBOX_DROPLIST);
160 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400,
161 dialog_->tabbed_folder);
162 combo_doc_class->shortcut("#C",1);
163 combo_doc_class->setcallback(ComboInputCB, this);
165 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
166 cit != textclasslist.end(); ++cit)
168 combo_doc_class->addto((*cit).description());
171 fl_clear_choice(class_->choice_doc_class);
172 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
173 cit != textclasslist.end(); ++cit)
175 fl_addto_choice(class_->choice_doc_class,(*cit).description().c_str());
178 fl_addto_choice(class_->choice_doc_spacing,
179 _(" Single | OneHalf | Double | Other "));
180 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
181 for (n=0; tex_fonts[n][0]; ++n) {
182 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
184 fl_addto_choice(class_->choice_doc_pagestyle,
185 "default|empty|plain|headings|fancy");
186 fl_addto_choice(class_->choice_doc_skip,
187 _(" Smallskip | Medskip | Bigskip | Length "));
188 fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
189 fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
190 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
192 bc_.addReadOnly (class_->radio_doc_indent);
193 bc_.addReadOnly (class_->radio_doc_skip);
194 #ifndef USE_CLASS_COMBO
195 bc_.addReadOnly (class_->choice_doc_class);
197 bc_.addReadOnly (class_->choice_doc_pagestyle);
198 bc_.addReadOnly (class_->choice_doc_fonts);
199 bc_.addReadOnly (class_->choice_doc_fontsize);
200 bc_.addReadOnly (class_->radio_doc_sides_one);
201 bc_.addReadOnly (class_->radio_doc_sides_two);
202 bc_.addReadOnly (class_->radio_doc_columns_one);
203 bc_.addReadOnly (class_->radio_doc_columns_two);
204 bc_.addReadOnly (class_->input_doc_extra);
205 bc_.addReadOnly (class_->input_doc_skip);
206 bc_.addReadOnly (class_->choice_doc_skip);
207 bc_.addReadOnly (class_->choice_doc_spacing);
208 bc_.addReadOnly (class_->input_doc_spacing);
210 // the document language form
211 language_ = build_doc_language();
212 fl_addto_choice(language_->choice_inputenc,
213 "default|auto|latin1|latin2|latin5"
214 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
216 // The language is a combo-box and has to be inserted manually
217 obj = language_->choice_language;
218 fl_deactivate_object(obj);
219 fl_addto_form(language_->form);
220 combo_language = new Combox(FL_COMBOX_DROPLIST);
221 combo_language->add(obj->x, obj->y, obj->w, obj->h, 400,
222 dialog_->tabbed_folder);
223 combo_language->shortcut("#L",1);
224 combo_language->setcallback(ComboInputCB, this);
226 // "default" is not part of the languages array any more.
227 #ifdef DO_USE_DEFAULT_LANGUAGE
228 combo_language->addto("default");
230 for (Languages::const_iterator cit = languages.begin();
231 cit != languages.end(); ++cit) {
232 combo_language->addto((*cit).second.lang());
235 fl_addto_choice(language_->choice_quotes_language,
236 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
237 " «text» | »text« "));
239 bc_.addReadOnly (language_->choice_inputenc);
241 // the document options form
242 options_ = build_doc_options();
243 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
244 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
245 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
246 fl_set_counter_step(options_->slider_secnumdepth,1,1);
247 fl_set_counter_step(options_->slider_tocdepth,1,1);
248 fl_set_counter_precision(options_->slider_secnumdepth, 0);
249 fl_set_counter_precision(options_->slider_tocdepth, 0);
250 for (n=0; tex_graphics[n][0]; ++n) {
251 fl_addto_choice(options_->choice_postscript_driver, tex_graphics[n]);
254 bc_.addReadOnly (options_->slider_secnumdepth);
255 bc_.addReadOnly (options_->slider_tocdepth);
256 bc_.addReadOnly (options_->check_use_amsmath);
257 bc_.addReadOnly (options_->input_float_placement);
258 bc_.addReadOnly (options_->choice_postscript_driver);
260 // the document bullets form
261 bullets_ = build_doc_bullet();
262 fl_addto_choice(bullets_->choice_bullet_size,
263 _(" default | tiny | script | footnote | small |"
264 " normal | large | Large | LARGE | huge | Huge"));
265 fl_set_choice(bullets_->choice_bullet_size, 1);
266 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
267 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
269 bc_.addReadOnly (bullets_->bmtable_bullet_panel);
270 bc_.addReadOnly (bullets_->choice_bullet_size);
271 bc_.addReadOnly (bullets_->input_bullet_latex);
273 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
275 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
277 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
279 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
281 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
283 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
284 lyxerr << _("Your version of libXpm is older than 4.7.\n"
285 "The `bullet' tab of the document popup "
286 "has been disabled") << '\n';
287 fl_deactivate_object(fbullet);
288 fl_set_object_lcol(fbullet, FL_INACTIVE);
293 void FormDocument::apply()
295 if (!lv_->view()->available() || !dialog_)
298 bool redo = class_apply();
300 redo = language_apply() || redo;
301 redo = options_apply() || redo;
305 lv_->view()->redoCurrentBuffer();
307 lv_->buffer()->markDirty();
308 setMinibuffer(lv_, _("Document layout set"));
312 void FormDocument::cancel()
314 // this avoids confusion when reopening
315 BufferParams & param = lv_->buffer()->params;
316 param.temp_bullets[0] = param.user_defined_bullets[0];
317 param.temp_bullets[1] = param.user_defined_bullets[1];
318 param.temp_bullets[2] = param.user_defined_bullets[2];
319 param.temp_bullets[3] = param.user_defined_bullets[3];
324 void FormDocument::update()
331 BufferParams const & params = lv_->buffer()->params;
333 class_update(params);
334 paper_update(params);
335 language_update(params);
336 options_update(params);
337 bullets_update(params);
341 bool FormDocument::input( FL_OBJECT * ob, long data )
343 State cb = static_cast<State>( data );
346 case CHECKCHOICECLASS:
347 CheckChoiceClass(ob, 0);
349 case CHOICEBULLETSIZE:
350 ChoiceBulletSize(ob, 0);
352 case INPUTBULLETLATEX:
353 InputBulletLaTeX(ob, 0);
370 BulletBMTable(ob, 0);
378 case CHECKCHOICECLASS:
379 case CHOICEBULLETSIZE:
380 case INPUTBULLETLATEX:
382 return CheckDocumentInput(ob, 0);
391 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
393 FormDocument * pre = static_cast<FormDocument*>(v);
394 if (combox == pre->combo_doc_class)
395 pre->CheckChoiceClass(0, 0);
396 pre->bc_.valid(pre->CheckDocumentInput(0,0));
400 bool FormDocument::class_apply()
403 BufferParams ¶ms = lv_->buffer()->params;
405 // If default skip is a "Length" but there's no text in the
406 // input field, reset the kind to "Medskip", which is the default.
407 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
408 !*(fl_get_input (class_->input_doc_skip))) {
409 fl_set_choice (class_->choice_doc_skip, 2);
411 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
412 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
413 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
415 #ifdef USE_CLASS_COMBO
416 unsigned int const new_class = combo_doc_class->get() - 1;
418 unsigned int const new_class = fl_get_choice(class_->choice_doc_class) - 1;
420 if (params.textclass != new_class) {
421 // try to load new_class
422 if (textclasslist.Load(new_class)) {
423 // successfully loaded
425 setMinibuffer(lv_, _("Converting document to new document class..."));
427 int ret = cap.SwitchLayoutsBetweenClasses(
428 params.textclass, new_class,
429 lv_->buffer()->paragraph);
433 s = _("One paragraph couldn't be converted");
436 s += _(" paragraphs couldn't be converted");
438 WriteAlert(_("Conversion Errors!"),s,
439 _("into chosen document class"));
442 params.textclass = new_class;
444 // problem changing class -- warn user and retain old style
445 WriteAlert(_("Conversion Errors!"),
446 _("Errors loading new document class."),
447 _("Reverting to original document class."));
448 #ifdef USE_CLASS_COMBO
449 combo_doc_class->select(int(params.textclass) + 1);
451 fl_set_choice(class_->choice_doc_class,
452 params.textclass + 1);
456 BufferParams::PARSEP tmpsep = params.paragraph_separation;
457 if (fl_get_button(class_->radio_doc_indent))
458 params.paragraph_separation = BufferParams::PARSEP_INDENT;
460 params.paragraph_separation = BufferParams::PARSEP_SKIP;
461 if (tmpsep != params.paragraph_separation)
464 VSpace tmpdefskip = params.getDefSkip();
465 switch (fl_get_choice (class_->choice_doc_skip)) {
467 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
470 params.setDefSkip(VSpace(VSpace::MEDSKIP));
473 params.setDefSkip(VSpace(VSpace::BIGSKIP));
477 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
479 // DocumentDefskipCB assures that this never happens
481 params.setDefSkip(VSpace(VSpace::MEDSKIP));
484 if (!(tmpdefskip == params.getDefSkip()))
487 if (fl_get_button(class_->radio_doc_columns_two))
491 if (fl_get_button(class_->radio_doc_sides_two))
492 params.sides = LyXTextClass::TwoSides;
494 params.sides = LyXTextClass::OneSide;
496 Spacing tmpSpacing = params.spacing;
497 switch (fl_get_choice(class_->choice_doc_spacing)) {
499 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
500 params.spacing.set(Spacing::Single);
503 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
504 params.spacing.set(Spacing::Onehalf);
507 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
508 params.spacing.set(Spacing::Double);
511 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
512 params.spacing.set(Spacing::Other,
513 fl_get_input(class_->input_doc_spacing));
516 if (tmpSpacing != params.spacing)
519 params.options = fl_get_input(class_->input_doc_extra);
525 void FormDocument::paper_apply()
527 BufferParams & params = lv_->buffer()->params;
530 static_cast<char>(fl_get_choice(paper_->choice_papersize2)-1);
531 params.paperpackage =
532 static_cast<char>(fl_get_choice(paper_->choice_paperpackage)-1);
533 params.use_geometry = fl_get_button(paper_->push_use_geometry);
534 if (fl_get_button(paper_->radio_landscape))
535 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
537 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
538 params.paperwidth = fl_get_input(paper_->input_custom_width);
539 params.paperheight = fl_get_input(paper_->input_custom_height);
540 params.leftmargin = fl_get_input(paper_->input_left_margin);
541 params.topmargin = fl_get_input(paper_->input_top_margin);
542 params.rightmargin = fl_get_input(paper_->input_right_margin);
543 params.bottommargin = fl_get_input(paper_->input_bottom_margin);
544 params.headheight = fl_get_input(paper_->input_head_height);
545 params.headsep = fl_get_input(paper_->input_head_sep);
546 params.footskip = fl_get_input(paper_->input_foot_skip);
547 lv_->buffer()->setPaperStuff();
551 bool FormDocument::language_apply()
553 BufferParams & params = lv_->buffer()->params;
554 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
557 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
559 lga = InsetQuotes::EnglishQ;
562 lga = InsetQuotes::SwedishQ;
565 lga = InsetQuotes::GermanQ;
568 lga = InsetQuotes::PolishQ;
571 lga = InsetQuotes::FrenchQ;
574 lga = InsetQuotes::DanishQ;
577 params.quotes_language = lga;
578 if (fl_get_button(language_->radio_single))
579 params.quotes_times = InsetQuotes::SingleQ;
581 params.quotes_times = InsetQuotes::DoubleQ;
583 Language const * old_language = params.language;
584 Language const * new_language =
585 languages.getLanguage(combo_language->getline());
587 new_language = default_language;
589 if (old_language != new_language
590 && old_language->RightToLeft() == new_language->RightToLeft()
591 && !lv_->buffer()->isMultiLingual())
592 lv_->buffer()->ChangeLanguage(old_language, new_language);
593 if (old_language != new_language) {
596 params.language = new_language;
597 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
603 bool FormDocument::options_apply()
605 BufferParams & params = lv_->buffer()->params;
608 params.graphicsDriver =
609 fl_get_choice_text(options_->choice_postscript_driver);
610 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
612 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
613 if (params.secnumdepth != tmpchar)
615 params.secnumdepth = tmpchar;
617 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
619 params.float_placement =
620 fl_get_input(options_->input_float_placement);
626 void FormDocument::bullets_apply()
628 /* update the bullet settings */
629 BufferParams & param = lv_->buffer()->params;
631 // a little bit of loop unrolling
632 param.user_defined_bullets[0] = param.temp_bullets[0];
633 param.user_defined_bullets[1] = param.temp_bullets[1];
634 param.user_defined_bullets[2] = param.temp_bullets[2];
635 param.user_defined_bullets[3] = param.temp_bullets[3];
639 void FormDocument::class_update(BufferParams const & params)
644 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
646 #ifdef USE_CLASS_COMBO
647 combo_doc_class->select_text(
648 textclasslist.DescOfClass(params.textclass));
650 fl_set_choice_text(class_->choice_doc_class,
651 textclasslist.DescOfClass(params.textclass).c_str());
653 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
654 fl_clear_choice(class_->choice_doc_fontsize);
655 fl_addto_choice(class_->choice_doc_fontsize, "default");
656 fl_addto_choice(class_->choice_doc_fontsize,
657 tclass.opt_fontsize().c_str());
658 fl_set_choice(class_->choice_doc_fontsize,
659 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
660 fl_clear_choice(class_->choice_doc_pagestyle);
661 fl_addto_choice(class_->choice_doc_pagestyle, "default");
662 fl_addto_choice(class_->choice_doc_pagestyle,
663 tclass.opt_pagestyle().c_str());
664 fl_set_choice(class_->choice_doc_pagestyle,
665 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
666 fl_set_button(class_->radio_doc_indent, 0);
667 fl_set_button(class_->radio_doc_skip, 0);
668 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
669 fl_set_button(class_->radio_doc_indent, 1);
671 fl_set_button(class_->radio_doc_skip, 1);
672 switch (params.getDefSkip().kind()) {
673 case VSpace::SMALLSKIP:
674 fl_set_choice (class_->choice_doc_skip, 1);
676 case VSpace::MEDSKIP:
677 fl_set_choice (class_->choice_doc_skip, 2);
679 case VSpace::BIGSKIP:
680 fl_set_choice (class_->choice_doc_skip, 3);
683 fl_set_choice (class_->choice_doc_skip, 4);
684 fl_set_input (class_->input_doc_skip,
685 params.getDefSkip().asLyXCommand().c_str());
688 fl_set_choice (class_->choice_doc_skip, 2);
691 fl_set_button(class_->radio_doc_sides_one, 0);
692 fl_set_button(class_->radio_doc_sides_two, 0);
693 if (params.sides == LyXTextClass::TwoSides)
694 fl_set_button(class_->radio_doc_sides_two, 1);
696 fl_set_button(class_->radio_doc_sides_one, 1);
697 fl_set_button(class_->radio_doc_columns_one, 0);
698 fl_set_button(class_->radio_doc_columns_two, 0);
699 if (params.columns == 2)
700 fl_set_button(class_->radio_doc_columns_two, 1);
702 fl_set_button(class_->radio_doc_columns_one, 1);
703 fl_set_input(class_->input_doc_spacing, "");
704 switch (params.spacing.getSpace()) {
705 case Spacing::Default: // nothing bad should happen with this
706 case Spacing::Single:
708 fl_set_choice(class_->choice_doc_spacing, 1);
710 case Spacing::Onehalf:
712 fl_set_choice(class_->choice_doc_spacing, 2);
714 case Spacing::Double:
716 fl_set_choice(class_->choice_doc_spacing, 3);
720 fl_set_choice(class_->choice_doc_spacing, 4);
722 sprintf(sval,"%g",params.spacing.getValue());
723 fl_set_input(class_->input_doc_spacing, sval);
727 if (!params.options.empty())
728 fl_set_input(class_->input_doc_extra, params.options.c_str());
730 fl_set_input(class_->input_doc_extra, "");
734 void FormDocument::language_update(BufferParams const & params)
739 combo_language->select_text(params.language->lang());
740 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
741 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
742 fl_set_button(language_->radio_single, 0);
743 fl_set_button(language_->radio_double, 0);
744 if (params.quotes_times == InsetQuotes::SingleQ)
745 fl_set_button(language_->radio_single, 1);
747 fl_set_button(language_->radio_double, 1);
751 void FormDocument::options_update(BufferParams const & params)
756 fl_set_choice_text(options_->choice_postscript_driver,
757 params.graphicsDriver.c_str());
758 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
759 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
760 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
761 if (!params.float_placement.empty())
762 fl_set_input(options_->input_float_placement,
763 params.float_placement.c_str());
765 fl_set_input(options_->input_float_placement, "");
769 void FormDocument::paper_update(BufferParams const & params)
774 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
775 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
776 fl_set_button(paper_->push_use_geometry, params.use_geometry);
777 fl_set_button(paper_->radio_portrait, 0);
778 fl_set_button(paper_->radio_landscape, 0);
779 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
780 fl_set_button(paper_->radio_landscape, 1);
782 fl_set_button(paper_->radio_portrait, 1);
783 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
784 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
785 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
786 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
787 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
788 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
789 fl_set_input(paper_->input_head_height, params.headheight.c_str());
790 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
791 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
792 fl_set_focus_object(paper_->form, paper_->choice_papersize2);
796 void FormDocument::bullets_update(BufferParams const & params)
798 if (!bullets_ || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
801 if (lv_->buffer()->isLinuxDoc()) {
802 fl_deactivate_object(fbullet);
803 fl_set_object_lcol(fbullet, FL_INACTIVE);
806 fl_activate_object(fbullet);
807 fl_set_object_lcol(fbullet, FL_BLACK);
810 fl_set_button(bullets_->radio_bullet_depth_1, 1);
811 fl_set_input(bullets_->input_bullet_latex,
812 params.user_defined_bullets[0].getText().c_str());
813 fl_set_choice(bullets_->choice_bullet_size,
814 params.user_defined_bullets[0].getSize() + 2);
818 void FormDocument::checkReadOnly()
820 if (bc_.readOnly(lv_->buffer()->isReadonly())) {
821 combo_doc_class->deactivate();
822 combo_language->deactivate();
823 fl_set_object_label(dialog_->text_warning,
824 _("Document is read-only."
825 " No changes to layout permitted."));
826 fl_show_object(dialog_->text_warning);
828 combo_doc_class->activate();
829 combo_language->activate();
830 fl_hide_object(dialog_->text_warning);
835 void FormDocument::checkMarginValues()
838 int const allEmpty = (!strlen(fl_get_input(paper_->input_top_margin)) &&
839 !strlen(fl_get_input(paper_->input_bottom_margin)) &&
840 !strlen(fl_get_input(paper_->input_left_margin)) &&
841 !strlen(fl_get_input(paper_->input_right_margin)) &&
842 !strlen(fl_get_input(paper_->input_head_height)) &&
843 !strlen(fl_get_input(paper_->input_head_sep)) &&
844 !strlen(fl_get_input(paper_->input_foot_skip)) &&
845 !strlen(fl_get_input(paper_->input_custom_width)) &&
846 !strlen(fl_get_input(paper_->input_custom_height)));
848 fl_set_button(paper_->push_use_geometry, 1);
853 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
861 if (ob == paper_->choice_papersize2) {
862 val = fl_get_choice(paper_->choice_papersize2)-1;
863 if (val == BufferParams::VM_PAPER_DEFAULT) {
864 fl_set_button(paper_->push_use_geometry, 0);
867 if ((val != BufferParams::VM_PAPER_USLETTER) &&
868 (val != BufferParams::VM_PAPER_USLEGAL) &&
869 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
870 (val != BufferParams::VM_PAPER_A4) &&
871 (val != BufferParams::VM_PAPER_A5) &&
872 (val != BufferParams::VM_PAPER_B5)) {
873 fl_set_button(paper_->push_use_geometry, 1);
875 fl_set_choice(paper_->choice_paperpackage,
876 BufferParams::PACKAGE_NONE + 1);
878 } else if (ob == paper_->choice_paperpackage) {
879 val = fl_get_choice(paper_->choice_paperpackage)-1;
880 if (val != BufferParams::PACKAGE_NONE) {
881 fl_set_choice(paper_->choice_papersize2,
882 BufferParams::VM_PAPER_DEFAULT + 1);
883 fl_set_button(paper_->push_use_geometry, 0);
885 } else if (ob == class_->input_doc_spacing) {
886 input = fl_get_input(class_->input_doc_spacing);
888 fl_set_choice (class_->choice_doc_spacing, 1);
890 fl_set_choice(class_->choice_doc_spacing, 4);
893 // this has to be all out of if/elseif because it has to deactivate
894 // the document buttons and so the whole stuff has to be tested again.
895 str = fl_get_input(paper_->input_custom_width);
896 ok = ok && (str.empty() || isValidLength(str));
897 str = fl_get_input(paper_->input_custom_height);
898 ok = ok && (str.empty() || isValidLength(str));
899 str = fl_get_input(paper_->input_left_margin);
900 ok = ok && (str.empty() || isValidLength(str));
901 str = fl_get_input(paper_->input_right_margin);
902 ok = ok && (str.empty() || isValidLength(str));
903 str = fl_get_input(paper_->input_top_margin);
904 ok = ok && (str.empty() || isValidLength(str));
905 str = fl_get_input(paper_->input_bottom_margin);
906 ok = ok && (str.empty() || isValidLength(str));
907 str = fl_get_input(paper_->input_head_height);
908 ok = ok && (str.empty() || isValidLength(str));
909 str = fl_get_input(paper_->input_head_sep);
910 ok = ok && (str.empty() || isValidLength(str));
911 str = fl_get_input(paper_->input_foot_skip);
912 ok = ok && (str.empty() || isValidLength(str));
913 // "Synchronize" the choice and the input field, so that it
914 // is impossible to commit senseless data.
915 input = fl_get_input (class_->input_doc_skip);
916 if (ob == class_->input_doc_skip) {
918 fl_set_choice (class_->choice_doc_skip, 2);
919 } else if (isValidGlueLength (input)) {
920 fl_set_choice (class_->choice_doc_skip, 4);
922 fl_set_choice(class_->choice_doc_skip, 4);
926 if (*input && !isValidGlueLength(input))
929 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
931 else if (fl_get_choice(class_->choice_doc_skip) != 4)
932 fl_set_input (class_->input_doc_skip, "");
934 input = fl_get_input(class_->input_doc_spacing);
935 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
937 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
938 fl_set_input (class_->input_doc_spacing, "");
943 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
945 BufferParams & param = lv_->buffer()->params;
947 // convert from 1-6 range to -1-4
948 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
949 fl_set_input(bullets_->input_bullet_latex,
950 param.temp_bullets[current_bullet_depth].getText().c_str());
954 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
956 BufferParams & param = lv_->buffer()->params;
958 param.temp_bullets[current_bullet_depth].
959 setText(fl_get_input(bullets_->input_bullet_latex));
963 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
965 /* Should I do the following: */
966 /* 1. change to the panel that the current bullet belongs in */
967 /* 2. show that bullet as selected */
968 /* 3. change the size setting to the size of the bullet in Q.*/
969 /* 4. display the latex equivalent in the latex box */
971 /* I'm inclined to just go with 3 and 4 at the moment and */
972 /* maybe try to support the others later */
973 BufferParams & param = lv_->buffer()->params;
976 if (cb == BULLETDEPTH1 )
978 else if (cb == BULLETDEPTH2 )
980 else if (cb == BULLETDEPTH3 )
982 else if (cb == BULLETDEPTH4 )
985 switch (fl_get_button_numb(ob)) {
987 // right mouse button resets to default
988 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
990 current_bullet_depth = data;
991 fl_set_input(bullets_->input_bullet_latex,
992 param.temp_bullets[data].getText().c_str());
993 fl_set_choice(bullets_->choice_bullet_size,
994 param.temp_bullets[data].getSize() + 2);
999 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
1001 /* Here we have to change the background pixmap to that selected */
1002 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1005 if (cb == BULLETPANEL1 )
1007 else if (cb == BULLETPANEL2 )
1009 else if (cb == BULLETPANEL3 )
1011 else if (cb == BULLETPANEL4 )
1013 else if (cb == BULLETPANEL5 )
1015 else if (cb == BULLETPANEL6 )
1018 if (data != current_bullet_panel) {
1019 fl_freeze_form(bullets_->form);
1020 current_bullet_panel = data;
1022 /* free the current pixmap */
1023 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1026 /* display the new one */
1028 new_panel = "standard";
1031 new_panel = "amssymb";
1034 new_panel = "psnfss1";
1037 new_panel = "psnfss2";
1040 new_panel = "psnfss3";
1043 new_panel = "psnfss4";
1046 /* something very wrong happened */
1047 // play it safe for now but should be an exception
1048 current_bullet_panel = 0; // standard panel
1049 new_panel = "standard";
1052 new_panel += ".xpm";
1053 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1054 LibFileSearch("images", new_panel).c_str());
1055 fl_redraw_object(bullets_->bmtable_bullet_panel);
1056 fl_unfreeze_form(bullets_->form);
1061 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1063 /* handle the user input by setting the current bullet depth's pixmap */
1064 /* to that extracted from the current chosen position of the BMTable */
1065 /* Don't forget to free the button's old pixmap first. */
1067 BufferParams & param = lv_->buffer()->params;
1068 int bmtable_button = fl_get_bmtable(ob);
1070 /* try to keep the button held down till another is pushed */
1071 /* fl_set_bmtable(ob, 1, bmtable_button); */
1072 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1073 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1074 fl_set_input(bullets_->input_bullet_latex,
1075 param.temp_bullets[current_bullet_depth].getText().c_str());
1079 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1082 ob = class_->choice_doc_class;
1084 ProhibitInput(lv_->view());
1086 #ifdef USE_CLASS_COMBO
1087 int tc = combo_doc_class->get() - 1;
1088 string tct = combo_doc_class->getline();
1090 int tc = fl_get_choice(ob) - 1;
1091 string tct = fl_get_choice_text(ob);
1093 if (textclasslist.Load(tc)) {
1094 if (AskQuestion(_("Should I set some parameters to"), tct,
1095 _("the defaults of this document class?"))) {
1096 BufferParams & params = lv_->buffer()->params;
1098 params.textclass = tc;
1099 params.useClassDefaults();
1100 UpdateLayoutDocument(params);
1103 // unable to load new style
1104 WriteAlert(_("Conversion Errors!"),
1105 _("Unable to switch to new document class."),
1106 _("Reverting to original document class."));
1107 #ifdef USE_CLASS_COMBO
1108 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1110 fl_set_choice(class_->choice_doc_class,
1111 lv_->buffer()->params.textclass + 1);
1114 AllowInput(lv_->view());
1118 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1124 class_update(params);
1125 paper_update(params);
1126 language_update(params);
1127 options_update(params);
1128 bullets_update(params);