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"
40 #include "xforms_helpers.h"
42 #ifdef CXX_WORKING_NAMESPACES
43 using Liason::setMinibuffer;
46 #define USE_CLASS_COMBO 1
48 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
49 : FormBaseBD(lv, d, _("Document Layout"),
50 new NoRepeatedApplyReadOnlyPolicy),
51 dialog_(0), paper_(0), class_(0), language_(0), options_(0),
52 bullets_(0), current_bullet_panel(0), current_bullet_depth(0),
53 fbullet(0), combo_language(0), combo_doc_class(0)
55 // let the popup be shown
56 // This is a permanent connection so we won't bother
57 // storing a copy because we won't be disconnecting.
58 d->showLayoutDocument.connect(slot(this, &FormDocument::show));
62 FormDocument::~FormDocument()
64 #ifdef USE_CLASS_COMBO
65 delete combo_doc_class;
69 delete combo_language;
77 void FormDocument::redraw()
79 if( form() && form()->visible )
80 fl_redraw_form( form() );
84 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabbed_folder);
85 if (outer_form && outer_form->visible)
86 fl_redraw_form( outer_form );
90 FL_FORM * FormDocument::form() const
92 if (dialog_) return dialog_->form;
97 void FormDocument::build()
102 dialog_ = build_tabbed_document();
104 // Manage the restore, ok, apply, restore and cancel/close buttons
105 bc_.setOK(dialog_->button_ok);
106 bc_.setApply(dialog_->button_apply);
107 bc_.setCancel(dialog_->button_cancel);
108 bc_.setUndoAll(dialog_->button_restore);
111 // Workaround dumb xforms sizing bug
115 // the document paper form
116 paper_ = build_doc_paper();
117 fl_addto_choice(paper_->choice_papersize2,
118 _(" Default | Custom | USletter | USlegal "
119 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
120 fl_addto_choice(paper_->choice_paperpackage,
122 "| A4 small Margins (only portrait) "
123 "| A4 very small Margins (only portrait) "
124 "| A4 very wide margins (only portrait) "));
125 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
126 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
127 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
128 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
129 fl_set_input_return(paper_->input_left_margin, FL_RETURN_CHANGED);
130 fl_set_input_return(paper_->input_right_margin, FL_RETURN_CHANGED);
131 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
132 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
133 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
135 bc_.addReadOnly (paper_->choice_paperpackage);
136 bc_.addReadOnly (paper_->greoup_radio_orientation);
137 bc_.addReadOnly (paper_->radio_portrait);
138 bc_.addReadOnly (paper_->radio_landscape);
139 bc_.addReadOnly (paper_->choice_papersize2);
140 bc_.addReadOnly (paper_->push_use_geometry);
141 bc_.addReadOnly (paper_->input_custom_width);
142 bc_.addReadOnly (paper_->input_custom_height);
143 bc_.addReadOnly (paper_->input_top_margin);
144 bc_.addReadOnly (paper_->input_bottom_margin);
145 bc_.addReadOnly (paper_->input_left_margin);
146 bc_.addReadOnly (paper_->input_right_margin);
147 bc_.addReadOnly (paper_->input_head_height);
148 bc_.addReadOnly (paper_->input_head_sep);
149 bc_.addReadOnly (paper_->input_foot_skip);
151 // the document class form
152 class_ = build_doc_class();
155 #ifdef USE_CLASS_COMBO
156 // The language is a combo-box and has to be inserted manually
157 obj = class_->choice_doc_class;
158 fl_deactivate_object(obj);
159 fl_addto_form(class_->form);
160 combo_doc_class = new Combox(FL_COMBOX_DROPLIST);
161 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400,
162 dialog_->tabbed_folder);
163 combo_doc_class->shortcut("#C",1);
164 combo_doc_class->setcallback(ComboInputCB, this);
166 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
167 cit != textclasslist.end(); ++cit)
169 combo_doc_class->addto((*cit).description());
172 fl_clear_choice(class_->choice_doc_class);
173 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
174 cit != textclasslist.end(); ++cit)
176 fl_addto_choice(class_->choice_doc_class,(*cit).description().c_str());
179 fl_addto_choice(class_->choice_doc_spacing,
180 _(" Single | OneHalf | Double | Other "));
181 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
182 for (n=0; tex_fonts[n][0]; ++n) {
183 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
185 fl_addto_choice(class_->choice_doc_pagestyle,
186 "default|empty|plain|headings|fancy");
187 fl_addto_choice(class_->choice_doc_skip,
188 _(" Smallskip | Medskip | Bigskip | Length "));
189 fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
190 fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
191 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
193 bc_.addReadOnly (class_->radio_doc_indent);
194 bc_.addReadOnly (class_->radio_doc_skip);
195 #ifndef USE_CLASS_COMBO
196 bc_.addReadOnly (class_->choice_doc_class);
198 bc_.addReadOnly (class_->choice_doc_pagestyle);
199 bc_.addReadOnly (class_->choice_doc_fonts);
200 bc_.addReadOnly (class_->choice_doc_fontsize);
201 bc_.addReadOnly (class_->radio_doc_sides_one);
202 bc_.addReadOnly (class_->radio_doc_sides_two);
203 bc_.addReadOnly (class_->radio_doc_columns_one);
204 bc_.addReadOnly (class_->radio_doc_columns_two);
205 bc_.addReadOnly (class_->input_doc_extra);
206 bc_.addReadOnly (class_->input_doc_skip);
207 bc_.addReadOnly (class_->choice_doc_skip);
208 bc_.addReadOnly (class_->choice_doc_spacing);
209 bc_.addReadOnly (class_->input_doc_spacing);
211 // the document language form
212 language_ = build_doc_language();
213 fl_addto_choice(language_->choice_inputenc,
214 "default|auto|latin1|latin2|latin5"
215 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
217 // The language is a combo-box and has to be inserted manually
218 obj = language_->choice_language;
219 fl_deactivate_object(obj);
220 fl_addto_form(language_->form);
221 combo_language = new Combox(FL_COMBOX_DROPLIST);
222 combo_language->add(obj->x, obj->y, obj->w, obj->h, 400,
223 dialog_->tabbed_folder);
224 combo_language->shortcut("#L",1);
225 combo_language->setcallback(ComboInputCB, this);
228 for (Languages::const_iterator cit = languages.begin();
229 cit != languages.end(); ++cit) {
230 combo_language->addto((*cit).second.lang());
233 fl_addto_choice(language_->choice_quotes_language,
234 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
235 " «text» | »text« "));
237 bc_.addReadOnly (language_->choice_inputenc);
239 // the document options form
240 options_ = build_doc_options();
241 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
242 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
243 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
244 fl_set_counter_step(options_->slider_secnumdepth,1,1);
245 fl_set_counter_step(options_->slider_tocdepth,1,1);
246 fl_set_counter_precision(options_->slider_secnumdepth, 0);
247 fl_set_counter_precision(options_->slider_tocdepth, 0);
248 for (n=0; tex_graphics[n][0]; ++n) {
249 fl_addto_choice(options_->choice_postscript_driver, tex_graphics[n]);
252 bc_.addReadOnly (options_->slider_secnumdepth);
253 bc_.addReadOnly (options_->slider_tocdepth);
254 bc_.addReadOnly (options_->check_use_amsmath);
255 bc_.addReadOnly (options_->input_float_placement);
256 bc_.addReadOnly (options_->choice_postscript_driver);
258 // the document bullets form
259 bullets_ = build_doc_bullet();
260 fl_addto_choice(bullets_->choice_bullet_size,
261 _(" default | tiny | script | footnote | small |"
262 " normal | large | Large | LARGE | huge | Huge"));
263 fl_set_choice(bullets_->choice_bullet_size, 1);
264 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
265 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
267 bc_.addReadOnly (bullets_->bmtable_bullet_panel);
268 bc_.addReadOnly (bullets_->choice_bullet_size);
269 bc_.addReadOnly (bullets_->input_bullet_latex);
271 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
273 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
275 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
277 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
279 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
281 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
282 lyxerr << _("Your version of libXpm is older than 4.7.\n"
283 "The `bullet' tab of the document popup "
284 "has been disabled") << '\n';
285 fl_deactivate_object(fbullet);
286 fl_set_object_lcol(fbullet, FL_INACTIVE);
291 void FormDocument::apply()
293 if (!lv_->view()->available() || !dialog_)
296 bool redo = class_apply();
298 redo = language_apply() || redo;
299 redo = options_apply() || redo;
303 lv_->view()->redoCurrentBuffer();
305 lv_->buffer()->markDirty();
306 setMinibuffer(lv_, _("Document layout set"));
310 void FormDocument::cancel()
312 // this avoids confusion when reopening
313 BufferParams & param = lv_->buffer()->params;
314 param.temp_bullets[0] = param.user_defined_bullets[0];
315 param.temp_bullets[1] = param.user_defined_bullets[1];
316 param.temp_bullets[2] = param.user_defined_bullets[2];
317 param.temp_bullets[3] = param.user_defined_bullets[3];
322 void FormDocument::update()
329 BufferParams const & params = lv_->buffer()->params;
331 class_update(params);
332 paper_update(params);
333 language_update(params);
334 options_update(params);
335 bullets_update(params);
339 bool FormDocument::input( FL_OBJECT * ob, long data )
341 State cb = static_cast<State>( data );
344 case CHECKCHOICECLASS:
345 CheckChoiceClass(ob, 0);
347 case CHOICEBULLETSIZE:
348 ChoiceBulletSize(ob, 0);
350 case INPUTBULLETLATEX:
351 InputBulletLaTeX(ob, 0);
368 BulletBMTable(ob, 0);
376 case CHECKCHOICECLASS:
377 case CHOICEBULLETSIZE:
378 case INPUTBULLETLATEX:
380 return CheckDocumentInput(ob, 0);
389 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
391 FormDocument * pre = static_cast<FormDocument*>(v);
392 if (combox == pre->combo_doc_class)
393 pre->CheckChoiceClass(0, 0);
394 pre->bc_.valid(pre->CheckDocumentInput(0,0));
398 bool FormDocument::class_apply()
401 BufferParams ¶ms = lv_->buffer()->params;
403 // If default skip is a "Length" but there's no text in the
404 // input field, reset the kind to "Medskip", which is the default.
405 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
406 !*(fl_get_input (class_->input_doc_skip))) {
407 fl_set_choice (class_->choice_doc_skip, 2);
409 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
410 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
411 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
413 #ifdef USE_CLASS_COMBO
414 unsigned int const new_class = combo_doc_class->get() - 1;
416 unsigned int const new_class = fl_get_choice(class_->choice_doc_class) - 1;
419 if (params.textclass != new_class) {
420 // try to load new_class
421 if (textclasslist.Load(new_class)) {
422 // successfully loaded
424 setMinibuffer(lv_, _("Converting document to new document class..."));
426 int ret = cap.SwitchLayoutsBetweenClasses(
427 params.textclass, new_class,
428 lv_->buffer()->paragraph);
432 s = _("One paragraph couldn't be converted");
435 s += _(" paragraphs couldn't be converted");
437 WriteAlert(_("Conversion Errors!"),s,
438 _("into chosen document class"));
441 params.textclass = new_class;
443 // problem changing class -- warn user and retain old style
444 WriteAlert(_("Conversion Errors!"),
445 _("Errors loading new document class."),
446 _("Reverting to original document class."));
447 #ifdef USE_CLASS_COMBO
448 combo_doc_class->select(int(params.textclass) + 1);
450 fl_set_choice(class_->choice_doc_class,
451 params.textclass + 1);
455 BufferParams::PARSEP tmpsep = params.paragraph_separation;
456 if (fl_get_button(class_->radio_doc_indent))
457 params.paragraph_separation = BufferParams::PARSEP_INDENT;
459 params.paragraph_separation = BufferParams::PARSEP_SKIP;
460 if (tmpsep != params.paragraph_separation)
463 VSpace tmpdefskip = params.getDefSkip();
464 switch (fl_get_choice (class_->choice_doc_skip)) {
466 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
469 params.setDefSkip(VSpace(VSpace::MEDSKIP));
472 params.setDefSkip(VSpace(VSpace::BIGSKIP));
476 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
478 // DocumentDefskipCB assures that this never happens
480 params.setDefSkip(VSpace(VSpace::MEDSKIP));
483 if (!(tmpdefskip == params.getDefSkip()))
486 if (fl_get_button(class_->radio_doc_columns_two))
490 if (fl_get_button(class_->radio_doc_sides_two))
491 params.sides = LyXTextClass::TwoSides;
493 params.sides = LyXTextClass::OneSide;
495 Spacing tmpSpacing = params.spacing;
496 switch (fl_get_choice(class_->choice_doc_spacing)) {
498 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
499 params.spacing.set(Spacing::Single);
502 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
503 params.spacing.set(Spacing::Onehalf);
506 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
507 params.spacing.set(Spacing::Double);
510 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
511 params.spacing.set(Spacing::Other,
512 fl_get_input(class_->input_doc_spacing));
515 if (tmpSpacing != params.spacing)
518 params.options = fl_get_input(class_->input_doc_extra);
524 void FormDocument::paper_apply()
526 BufferParams & params = lv_->buffer()->params;
529 static_cast<char>(fl_get_choice(paper_->choice_papersize2)-1);
530 params.paperpackage =
531 static_cast<char>(fl_get_choice(paper_->choice_paperpackage)-1);
532 params.use_geometry = fl_get_button(paper_->push_use_geometry);
533 if (fl_get_button(paper_->radio_landscape))
534 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
536 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
537 params.paperwidth = fl_get_input(paper_->input_custom_width);
538 params.paperheight = fl_get_input(paper_->input_custom_height);
539 params.leftmargin = fl_get_input(paper_->input_left_margin);
540 params.topmargin = fl_get_input(paper_->input_top_margin);
541 params.rightmargin = fl_get_input(paper_->input_right_margin);
542 params.bottommargin = fl_get_input(paper_->input_bottom_margin);
543 params.headheight = fl_get_input(paper_->input_head_height);
544 params.headsep = fl_get_input(paper_->input_head_sep);
545 params.footskip = fl_get_input(paper_->input_foot_skip);
546 lv_->buffer()->setPaperStuff();
550 bool FormDocument::language_apply()
552 BufferParams & params = lv_->buffer()->params;
553 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
556 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
558 lga = InsetQuotes::EnglishQ;
561 lga = InsetQuotes::SwedishQ;
564 lga = InsetQuotes::GermanQ;
567 lga = InsetQuotes::PolishQ;
570 lga = InsetQuotes::FrenchQ;
573 lga = InsetQuotes::DanishQ;
576 params.quotes_language = lga;
577 if (fl_get_button(language_->radio_single))
578 params.quotes_times = InsetQuotes::SingleQ;
580 params.quotes_times = InsetQuotes::DoubleQ;
582 Language const * old_language = params.language;
583 Language const * new_language =
584 languages.getLanguage(combo_language->getline());
586 new_language = default_language;
588 if (old_language != new_language
589 && old_language->RightToLeft() == new_language->RightToLeft()
590 && !lv_->buffer()->isMultiLingual())
591 lv_->buffer()->ChangeLanguage(old_language, new_language);
592 if (old_language != new_language) {
595 params.language = new_language;
596 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
602 bool FormDocument::options_apply()
604 BufferParams & params = lv_->buffer()->params;
607 params.graphicsDriver =
608 fl_get_choice_text(options_->choice_postscript_driver);
609 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
611 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
612 if (params.secnumdepth != tmpchar)
614 params.secnumdepth = tmpchar;
616 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
618 params.float_placement =
619 fl_get_input(options_->input_float_placement);
625 void FormDocument::bullets_apply()
627 /* update the bullet settings */
628 BufferParams & param = lv_->buffer()->params;
630 // a little bit of loop unrolling
631 param.user_defined_bullets[0] = param.temp_bullets[0];
632 param.user_defined_bullets[1] = param.temp_bullets[1];
633 param.user_defined_bullets[2] = param.temp_bullets[2];
634 param.user_defined_bullets[3] = param.temp_bullets[3];
638 void FormDocument::class_update(BufferParams const & params)
643 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
645 #ifdef USE_CLASS_COMBO
646 combo_doc_class->select_text(
647 textclasslist.DescOfClass(params.textclass));
649 fl_set_choice_text(class_->choice_doc_class,
650 textclasslist.DescOfClass(params.textclass).c_str());
652 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
653 fl_clear_choice(class_->choice_doc_fontsize);
654 fl_addto_choice(class_->choice_doc_fontsize, "default");
655 fl_addto_choice(class_->choice_doc_fontsize,
656 tclass.opt_fontsize().c_str());
657 fl_set_choice(class_->choice_doc_fontsize,
658 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
659 fl_clear_choice(class_->choice_doc_pagestyle);
660 fl_addto_choice(class_->choice_doc_pagestyle, "default");
661 fl_addto_choice(class_->choice_doc_pagestyle,
662 tclass.opt_pagestyle().c_str());
663 fl_set_choice(class_->choice_doc_pagestyle,
664 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
665 fl_set_button(class_->radio_doc_indent, 0);
666 fl_set_button(class_->radio_doc_skip, 0);
667 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
668 fl_set_button(class_->radio_doc_indent, 1);
670 fl_set_button(class_->radio_doc_skip, 1);
671 switch (params.getDefSkip().kind()) {
672 case VSpace::SMALLSKIP:
673 fl_set_choice (class_->choice_doc_skip, 1);
675 case VSpace::MEDSKIP:
676 fl_set_choice (class_->choice_doc_skip, 2);
678 case VSpace::BIGSKIP:
679 fl_set_choice (class_->choice_doc_skip, 3);
682 fl_set_choice (class_->choice_doc_skip, 4);
683 fl_set_input (class_->input_doc_skip,
684 params.getDefSkip().asLyXCommand().c_str());
687 fl_set_choice (class_->choice_doc_skip, 2);
690 fl_set_button(class_->radio_doc_sides_one, 0);
691 fl_set_button(class_->radio_doc_sides_two, 0);
692 if (params.sides == LyXTextClass::TwoSides)
693 fl_set_button(class_->radio_doc_sides_two, 1);
695 fl_set_button(class_->radio_doc_sides_one, 1);
696 fl_set_button(class_->radio_doc_columns_one, 0);
697 fl_set_button(class_->radio_doc_columns_two, 0);
698 if (params.columns == 2)
699 fl_set_button(class_->radio_doc_columns_two, 1);
701 fl_set_button(class_->radio_doc_columns_one, 1);
702 fl_set_input(class_->input_doc_spacing, "");
703 switch (params.spacing.getSpace()) {
704 case Spacing::Default: // nothing bad should happen with this
705 case Spacing::Single:
707 fl_set_choice(class_->choice_doc_spacing, 1);
709 case Spacing::Onehalf:
711 fl_set_choice(class_->choice_doc_spacing, 2);
713 case Spacing::Double:
715 fl_set_choice(class_->choice_doc_spacing, 3);
719 fl_set_choice(class_->choice_doc_spacing, 4);
721 sprintf(sval,"%g",params.spacing.getValue());
722 fl_set_input(class_->input_doc_spacing, sval);
726 if (!params.options.empty())
727 fl_set_input(class_->input_doc_extra, params.options.c_str());
729 fl_set_input(class_->input_doc_extra, "");
733 void FormDocument::language_update(BufferParams const & params)
738 combo_language->select_text(params.language->lang());
739 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
740 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
741 fl_set_button(language_->radio_single, 0);
742 fl_set_button(language_->radio_double, 0);
743 if (params.quotes_times == InsetQuotes::SingleQ)
744 fl_set_button(language_->radio_single, 1);
746 fl_set_button(language_->radio_double, 1);
750 void FormDocument::options_update(BufferParams const & params)
755 fl_set_choice_text(options_->choice_postscript_driver,
756 params.graphicsDriver.c_str());
757 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
758 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
759 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
760 if (!params.float_placement.empty())
761 fl_set_input(options_->input_float_placement,
762 params.float_placement.c_str());
764 fl_set_input(options_->input_float_placement, "");
768 void FormDocument::paper_update(BufferParams const & params)
773 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
774 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
775 fl_set_button(paper_->push_use_geometry, params.use_geometry);
776 fl_set_button(paper_->radio_portrait, 0);
777 fl_set_button(paper_->radio_landscape, 0);
778 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
779 fl_set_button(paper_->radio_landscape, 1);
781 fl_set_button(paper_->radio_portrait, 1);
782 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
783 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
784 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
785 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
786 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
787 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
788 fl_set_input(paper_->input_head_height, params.headheight.c_str());
789 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
790 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
791 fl_set_focus_object(paper_->form, paper_->choice_papersize2);
795 void FormDocument::bullets_update(BufferParams const & params)
797 if (!bullets_ || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
800 bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
801 setEnabled(fbullet, !isLinuxDoc);
803 if (isLinuxDoc) return;
805 fl_set_button(bullets_->radio_bullet_depth_1, 1);
806 fl_set_input(bullets_->input_bullet_latex,
807 params.user_defined_bullets[0].getText().c_str());
808 fl_set_choice(bullets_->choice_bullet_size,
809 params.user_defined_bullets[0].getSize() + 2);
813 void FormDocument::checkReadOnly()
815 if (bc_.readOnly(lv_->buffer()->isReadonly())) {
816 combo_doc_class->deactivate();
817 combo_language->deactivate();
818 fl_set_object_label(dialog_->text_warning,
819 _("Document is read-only."
820 " No changes to layout permitted."));
821 fl_show_object(dialog_->text_warning);
823 combo_doc_class->activate();
824 combo_language->activate();
825 fl_hide_object(dialog_->text_warning);
830 void FormDocument::checkMarginValues()
832 bool const not_empty =
833 strlen(fl_get_input(paper_->input_top_margin)) ||
834 strlen(fl_get_input(paper_->input_bottom_margin)) ||
835 strlen(fl_get_input(paper_->input_left_margin)) ||
836 strlen(fl_get_input(paper_->input_right_margin)) ||
837 strlen(fl_get_input(paper_->input_head_height)) ||
838 strlen(fl_get_input(paper_->input_head_sep)) ||
839 strlen(fl_get_input(paper_->input_foot_skip)) ||
840 strlen(fl_get_input(paper_->input_custom_width)) ||
841 strlen(fl_get_input(paper_->input_custom_height));
843 fl_set_button(paper_->push_use_geometry, 1);
847 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
855 if (ob == paper_->choice_papersize2) {
856 val = fl_get_choice(paper_->choice_papersize2)-1;
857 if (val == BufferParams::VM_PAPER_DEFAULT) {
858 fl_set_button(paper_->push_use_geometry, 0);
861 if ((val != BufferParams::VM_PAPER_USLETTER) &&
862 (val != BufferParams::VM_PAPER_USLEGAL) &&
863 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
864 (val != BufferParams::VM_PAPER_A4) &&
865 (val != BufferParams::VM_PAPER_A5) &&
866 (val != BufferParams::VM_PAPER_B5)) {
867 fl_set_button(paper_->push_use_geometry, 1);
869 fl_set_choice(paper_->choice_paperpackage,
870 BufferParams::PACKAGE_NONE + 1);
872 } else if (ob == paper_->choice_paperpackage) {
873 val = fl_get_choice(paper_->choice_paperpackage)-1;
874 if (val != BufferParams::PACKAGE_NONE) {
875 fl_set_choice(paper_->choice_papersize2,
876 BufferParams::VM_PAPER_DEFAULT + 1);
877 fl_set_button(paper_->push_use_geometry, 0);
879 } else if (ob == class_->input_doc_spacing) {
880 input = fl_get_input(class_->input_doc_spacing);
882 fl_set_choice (class_->choice_doc_spacing, 1);
884 fl_set_choice(class_->choice_doc_spacing, 4);
887 // this has to be all out of if/elseif because it has to deactivate
888 // the document buttons and so the whole stuff has to be tested again.
889 str = fl_get_input(paper_->input_custom_width);
890 ok = ok && (str.empty() || isValidLength(str));
891 str = fl_get_input(paper_->input_custom_height);
892 ok = ok && (str.empty() || isValidLength(str));
893 str = fl_get_input(paper_->input_left_margin);
894 ok = ok && (str.empty() || isValidLength(str));
895 str = fl_get_input(paper_->input_right_margin);
896 ok = ok && (str.empty() || isValidLength(str));
897 str = fl_get_input(paper_->input_top_margin);
898 ok = ok && (str.empty() || isValidLength(str));
899 str = fl_get_input(paper_->input_bottom_margin);
900 ok = ok && (str.empty() || isValidLength(str));
901 str = fl_get_input(paper_->input_head_height);
902 ok = ok && (str.empty() || isValidLength(str));
903 str = fl_get_input(paper_->input_head_sep);
904 ok = ok && (str.empty() || isValidLength(str));
905 str = fl_get_input(paper_->input_foot_skip);
906 ok = ok && (str.empty() || isValidLength(str));
907 // "Synchronize" the choice and the input field, so that it
908 // is impossible to commit senseless data.
909 input = fl_get_input (class_->input_doc_skip);
910 if (ob == class_->input_doc_skip) {
912 fl_set_choice (class_->choice_doc_skip, 2);
913 } else if (isValidGlueLength (input)) {
914 fl_set_choice (class_->choice_doc_skip, 4);
916 fl_set_choice(class_->choice_doc_skip, 4);
920 if (*input && !isValidGlueLength(input))
923 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
925 else if (fl_get_choice(class_->choice_doc_skip) != 4)
926 fl_set_input (class_->input_doc_skip, "");
928 input = fl_get_input(class_->input_doc_spacing);
929 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
931 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
932 fl_set_input (class_->input_doc_spacing, "");
937 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
939 BufferParams & param = lv_->buffer()->params;
941 // convert from 1-6 range to -1-4
942 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
943 fl_set_input(bullets_->input_bullet_latex,
944 param.temp_bullets[current_bullet_depth].getText().c_str());
948 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
950 BufferParams & param = lv_->buffer()->params;
952 param.temp_bullets[current_bullet_depth].
953 setText(fl_get_input(bullets_->input_bullet_latex));
957 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
959 /* Should I do the following: */
960 /* 1. change to the panel that the current bullet belongs in */
961 /* 2. show that bullet as selected */
962 /* 3. change the size setting to the size of the bullet in Q.*/
963 /* 4. display the latex equivalent in the latex box */
965 /* I'm inclined to just go with 3 and 4 at the moment and */
966 /* maybe try to support the others later */
967 BufferParams & param = lv_->buffer()->params;
970 if (cb == BULLETDEPTH1 )
972 else if (cb == BULLETDEPTH2 )
974 else if (cb == BULLETDEPTH3 )
976 else if (cb == BULLETDEPTH4 )
979 switch (fl_get_button_numb(ob)) {
981 // right mouse button resets to default
982 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
984 current_bullet_depth = data;
985 fl_set_input(bullets_->input_bullet_latex,
986 param.temp_bullets[data].getText().c_str());
987 fl_set_choice(bullets_->choice_bullet_size,
988 param.temp_bullets[data].getSize() + 2);
993 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
995 /* Here we have to change the background pixmap to that selected */
996 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
999 if (cb == BULLETPANEL1 )
1001 else if (cb == BULLETPANEL2 )
1003 else if (cb == BULLETPANEL3 )
1005 else if (cb == BULLETPANEL4 )
1007 else if (cb == BULLETPANEL5 )
1009 else if (cb == BULLETPANEL6 )
1012 if (data != current_bullet_panel) {
1013 fl_freeze_form(bullets_->form);
1014 current_bullet_panel = data;
1016 /* free the current pixmap */
1017 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1020 /* display the new one */
1022 new_panel = "standard";
1025 new_panel = "amssymb";
1028 new_panel = "psnfss1";
1031 new_panel = "psnfss2";
1034 new_panel = "psnfss3";
1037 new_panel = "psnfss4";
1040 /* something very wrong happened */
1041 // play it safe for now but should be an exception
1042 current_bullet_panel = 0; // standard panel
1043 new_panel = "standard";
1046 new_panel += ".xpm";
1047 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1048 LibFileSearch("images", new_panel).c_str());
1049 fl_redraw_object(bullets_->bmtable_bullet_panel);
1050 fl_unfreeze_form(bullets_->form);
1055 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1057 /* handle the user input by setting the current bullet depth's pixmap */
1058 /* to that extracted from the current chosen position of the BMTable */
1059 /* Don't forget to free the button's old pixmap first. */
1061 BufferParams & param = lv_->buffer()->params;
1062 int bmtable_button = fl_get_bmtable(ob);
1064 /* try to keep the button held down till another is pushed */
1065 /* fl_set_bmtable(ob, 1, bmtable_button); */
1066 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1067 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1068 fl_set_input(bullets_->input_bullet_latex,
1069 param.temp_bullets[current_bullet_depth].getText().c_str());
1073 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1076 ob = class_->choice_doc_class;
1078 ProhibitInput(lv_->view());
1080 #ifdef USE_CLASS_COMBO
1081 unsigned int tc = combo_doc_class->get() - 1;
1082 string tct = combo_doc_class->getline();
1084 int tc = fl_get_choice(ob) - 1;
1085 string tct = fl_get_choice_text(ob);
1087 if (textclasslist.Load(tc)) {
1088 // we use a copy of the bufferparams because we do not
1089 // want to modify them yet.
1090 BufferParams params = lv_->buffer()->params;
1092 if (params.textclass != tc
1093 && AskQuestion(_("Should I set some parameters to"),
1094 _("the defaults of this document class?"))) {
1095 params.textclass = tc;
1096 params.useClassDefaults();
1097 UpdateLayoutDocument(params);
1100 // unable to load new style
1101 WriteAlert(_("Conversion Errors!"),
1102 _("Unable to switch to new document class."),
1103 _("Reverting to original document class."));
1104 #ifdef USE_CLASS_COMBO
1105 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1107 fl_set_choice(class_->choice_doc_class,
1108 lv_->buffer()->params.textclass + 1);
1111 AllowInput(lv_->view());
1115 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1121 class_update(params);
1122 paper_update(params);
1123 language_update(params);
1124 options_update(params);
1125 bullets_update(params);