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_addto_form(class_->form);
158 combo_doc_class = new Combox(FL_COMBOX_DROPLIST);
159 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400);
160 combo_doc_class->shortcut("#C",1);
161 combo_doc_class->setcallback(ComboInputCB, this);
163 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
164 cit != textclasslist.end(); ++cit)
166 combo_doc_class->addto((*cit).description());
169 fl_clear_choice(class_->choice_doc_class);
170 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
171 cit != textclasslist.end(); ++cit)
173 fl_addto_choice(class_->choice_doc_class,(*cit).description().c_str());
176 fl_addto_choice(class_->choice_doc_spacing,
177 _(" Single | OneHalf | Double | Other "));
178 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
179 for (n=0; tex_fonts[n][0]; ++n) {
180 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
182 fl_addto_choice(class_->choice_doc_pagestyle,
183 "default|empty|plain|headings|fancy");
184 fl_addto_choice(class_->choice_doc_skip,
185 _(" Smallskip | Medskip | Bigskip | Length "));
186 fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
187 fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
188 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
190 bc_.addReadOnly (class_->radio_doc_indent);
191 bc_.addReadOnly (class_->radio_doc_skip);
192 #ifndef USE_CLASS_COMBO
193 bc_.addReadOnly (class_->choice_doc_class);
195 bc_.addReadOnly (class_->choice_doc_pagestyle);
196 bc_.addReadOnly (class_->choice_doc_fonts);
197 bc_.addReadOnly (class_->choice_doc_fontsize);
198 bc_.addReadOnly (class_->radio_doc_sides_one);
199 bc_.addReadOnly (class_->radio_doc_sides_two);
200 bc_.addReadOnly (class_->radio_doc_columns_one);
201 bc_.addReadOnly (class_->radio_doc_columns_two);
202 bc_.addReadOnly (class_->input_doc_extra);
203 bc_.addReadOnly (class_->input_doc_skip);
204 bc_.addReadOnly (class_->choice_doc_skip);
205 bc_.addReadOnly (class_->choice_doc_spacing);
206 bc_.addReadOnly (class_->input_doc_spacing);
208 // the document language form
209 language_ = build_doc_language();
210 fl_addto_choice(language_->choice_inputenc,
211 "default|auto|latin1|latin2|latin5"
212 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
214 // The language is a combo-box and has to be inserted manually
215 obj = language_->choice_language;
216 fl_addto_form(language_->form);
217 combo_language = new Combox(FL_COMBOX_DROPLIST);
218 combo_language->add(obj->x, obj->y, obj->w, obj->h, 400);
219 combo_language->shortcut("#L",1);
220 combo_language->setcallback(ComboInputCB, this);
222 // "default" is not part of the languages array any more.
223 #ifdef DO_USE_DEFAULT_LANGUAGE
224 combo_language->addto("default");
226 for (Languages::const_iterator cit = languages.begin();
227 cit != languages.end(); ++cit) {
228 combo_language->addto((*cit).second.lang());
231 fl_addto_choice(language_->choice_quotes_language,
232 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
233 " «text» | »text« "));
235 bc_.addReadOnly (language_->choice_language);
236 bc_.addReadOnly (language_->choice_inputenc);
238 // the document options form
239 options_ = build_doc_options();
240 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
241 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
242 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
243 fl_set_counter_step(options_->slider_secnumdepth,1,1);
244 fl_set_counter_step(options_->slider_tocdepth,1,1);
245 fl_set_counter_precision(options_->slider_secnumdepth, 0);
246 fl_set_counter_precision(options_->slider_tocdepth, 0);
247 for (n=0; tex_graphics[n][0]; ++n) {
248 fl_addto_choice(options_->choice_postscript_driver, tex_graphics[n]);
251 bc_.addReadOnly (options_->slider_secnumdepth);
252 bc_.addReadOnly (options_->slider_tocdepth);
253 bc_.addReadOnly (options_->check_use_amsmath);
254 bc_.addReadOnly (options_->input_float_placement);
255 bc_.addReadOnly (options_->choice_postscript_driver);
257 // the document bullets form
258 bullets_ = build_doc_bullet();
259 fl_addto_choice(bullets_->choice_bullet_size,
260 _(" default | tiny | script | footnote | small |"
261 " normal | large | Large | LARGE | huge | Huge"));
262 fl_set_choice(bullets_->choice_bullet_size, 1);
263 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
264 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
266 bc_.addReadOnly (bullets_->bmtable_bullet_panel);
267 bc_.addReadOnly (bullets_->choice_bullet_size);
268 bc_.addReadOnly (bullets_->input_bullet_latex);
270 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
272 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
274 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
276 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
278 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
280 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
281 lyxerr << _("Your version of libXpm is older than 4.7.\n"
282 "The `bullet' tab of the document popup "
283 "has been disabled") << '\n';
284 fl_deactivate_object(fbullet);
285 fl_set_object_lcol(fbullet, FL_INACTIVE);
290 void FormDocument::apply()
292 if (!lv_->view()->available() || !dialog_)
295 bool redo = class_apply();
297 redo = language_apply() || redo;
298 redo = options_apply() || redo;
302 lv_->view()->redoCurrentBuffer();
304 lv_->buffer()->markDirty();
305 setMinibuffer(lv_, _("Document layout set"));
309 void FormDocument::cancel()
311 // this avoids confusion when reopening
312 BufferParams & param = lv_->buffer()->params;
313 param.temp_bullets[0] = param.user_defined_bullets[0];
314 param.temp_bullets[1] = param.user_defined_bullets[1];
315 param.temp_bullets[2] = param.user_defined_bullets[2];
316 param.temp_bullets[3] = param.user_defined_bullets[3];
321 void FormDocument::update()
328 BufferParams const & params = lv_->buffer()->params;
330 class_update(params);
331 paper_update(params);
332 language_update(params);
333 options_update(params);
334 bullets_update(params);
338 bool FormDocument::input( FL_OBJECT * ob, long data )
340 State cb = static_cast<State>( data );
343 case CHECKCHOICECLASS:
344 CheckChoiceClass(ob, 0);
346 case CHOICEBULLETSIZE:
347 ChoiceBulletSize(ob, 0);
349 case INPUTBULLETLATEX:
350 InputBulletLaTeX(ob, 0);
367 BulletBMTable(ob, 0);
375 case CHECKCHOICECLASS:
376 case CHOICEBULLETSIZE:
377 case INPUTBULLETLATEX:
379 return CheckDocumentInput(ob, 0);
388 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
390 FormDocument * pre = static_cast<FormDocument*>(v);
391 if (combox == pre->combo_doc_class)
392 pre->CheckChoiceClass(0, 0);
393 pre->bc_.valid(pre->CheckDocumentInput(0,0));
397 bool FormDocument::class_apply()
400 BufferParams ¶ms = lv_->buffer()->params;
402 // If default skip is a "Length" but there's no text in the
403 // input field, reset the kind to "Medskip", which is the default.
404 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
405 !*(fl_get_input (class_->input_doc_skip))) {
406 fl_set_choice (class_->choice_doc_skip, 2);
408 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
409 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
410 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
412 #ifdef USE_CLASS_COMBO
413 unsigned int const new_class = combo_doc_class->get() - 1;
415 unsigned int const new_class = fl_get_choice(class_->choice_doc_class) - 1;
417 if (params.textclass != new_class) {
418 // try to load new_class
419 if (textclasslist.Load(new_class)) {
420 // successfully loaded
422 setMinibuffer(lv_, _("Converting document to new document class..."));
424 int ret = cap.SwitchLayoutsBetweenClasses(
425 params.textclass, new_class,
426 lv_->buffer()->paragraph);
430 s = _("One paragraph couldn't be converted");
433 s += _(" paragraphs couldn't be converted");
435 WriteAlert(_("Conversion Errors!"),s,
436 _("into chosen document class"));
439 params.textclass = new_class;
441 // problem changing class -- warn user and retain old style
442 WriteAlert(_("Conversion Errors!"),
443 _("Errors loading new document class."),
444 _("Reverting to original document class."));
445 #ifdef USE_CLASS_COMBO
446 combo_doc_class->select(int(params.textclass) + 1);
448 fl_set_choice(class_->choice_doc_class,
449 params.textclass + 1);
453 BufferParams::PARSEP tmpsep = params.paragraph_separation;
454 if (fl_get_button(class_->radio_doc_indent))
455 params.paragraph_separation = BufferParams::PARSEP_INDENT;
457 params.paragraph_separation = BufferParams::PARSEP_SKIP;
458 if (tmpsep != params.paragraph_separation)
461 VSpace tmpdefskip = params.getDefSkip();
462 switch (fl_get_choice (class_->choice_doc_skip)) {
464 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
467 params.setDefSkip(VSpace(VSpace::MEDSKIP));
470 params.setDefSkip(VSpace(VSpace::BIGSKIP));
474 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
476 // DocumentDefskipCB assures that this never happens
478 params.setDefSkip(VSpace(VSpace::MEDSKIP));
481 if (!(tmpdefskip == params.getDefSkip()))
484 if (fl_get_button(class_->radio_doc_columns_two))
488 if (fl_get_button(class_->radio_doc_sides_two))
489 params.sides = LyXTextClass::TwoSides;
491 params.sides = LyXTextClass::OneSide;
493 Spacing tmpSpacing = params.spacing;
494 switch (fl_get_choice(class_->choice_doc_spacing)) {
496 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
497 params.spacing.set(Spacing::Single);
500 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
501 params.spacing.set(Spacing::Onehalf);
504 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
505 params.spacing.set(Spacing::Double);
508 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
509 params.spacing.set(Spacing::Other,
510 fl_get_input(class_->input_doc_spacing));
513 if (tmpSpacing != params.spacing)
516 params.options = fl_get_input(class_->input_doc_extra);
522 void FormDocument::paper_apply()
524 BufferParams & params = lv_->buffer()->params;
527 static_cast<char>(fl_get_choice(paper_->choice_papersize2)-1);
528 params.paperpackage =
529 static_cast<char>(fl_get_choice(paper_->choice_paperpackage)-1);
530 params.use_geometry = fl_get_button(paper_->push_use_geometry);
531 if (fl_get_button(paper_->radio_landscape))
532 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
534 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
535 params.paperwidth = fl_get_input(paper_->input_custom_width);
536 params.paperheight = fl_get_input(paper_->input_custom_height);
537 params.leftmargin = fl_get_input(paper_->input_left_margin);
538 params.topmargin = fl_get_input(paper_->input_top_margin);
539 params.rightmargin = fl_get_input(paper_->input_right_margin);
540 params.bottommargin = fl_get_input(paper_->input_bottom_margin);
541 params.headheight = fl_get_input(paper_->input_head_height);
542 params.headsep = fl_get_input(paper_->input_head_sep);
543 params.footskip = fl_get_input(paper_->input_foot_skip);
544 lv_->buffer()->setPaperStuff();
548 bool FormDocument::language_apply()
550 BufferParams & params = lv_->buffer()->params;
551 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
554 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
556 lga = InsetQuotes::EnglishQ;
559 lga = InsetQuotes::SwedishQ;
562 lga = InsetQuotes::GermanQ;
565 lga = InsetQuotes::PolishQ;
568 lga = InsetQuotes::FrenchQ;
571 lga = InsetQuotes::DanishQ;
574 params.quotes_language = lga;
575 if (fl_get_button(language_->radio_single))
576 params.quotes_times = InsetQuotes::SingleQ;
578 params.quotes_times = InsetQuotes::DoubleQ;
580 Language const * old_language = params.language;
581 Language const * new_language =
582 languages.getLanguage(combo_language->getline());
584 new_language = default_language;
586 if (old_language != new_language
587 && old_language->RightToLeft() == new_language->RightToLeft()
588 && !lv_->buffer()->isMultiLingual())
589 lv_->buffer()->ChangeLanguage(old_language, new_language);
590 if (old_language != new_language) {
593 params.language = new_language;
594 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
600 bool FormDocument::options_apply()
602 BufferParams & params = lv_->buffer()->params;
605 params.graphicsDriver =
606 fl_get_choice_text(options_->choice_postscript_driver);
607 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
609 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
610 if (params.secnumdepth != tmpchar)
612 params.secnumdepth = tmpchar;
614 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
616 params.float_placement =
617 fl_get_input(options_->input_float_placement);
623 void FormDocument::bullets_apply()
625 /* update the bullet settings */
626 BufferParams & param = lv_->buffer()->params;
628 // a little bit of loop unrolling
629 param.user_defined_bullets[0] = param.temp_bullets[0];
630 param.user_defined_bullets[1] = param.temp_bullets[1];
631 param.user_defined_bullets[2] = param.temp_bullets[2];
632 param.user_defined_bullets[3] = param.temp_bullets[3];
636 void FormDocument::class_update(BufferParams const & params)
641 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
643 #ifdef USE_CLASS_COMBO
644 combo_doc_class->select_text(
645 textclasslist.DescOfClass(params.textclass));
647 fl_set_choice_text(class_->choice_doc_class,
648 textclasslist.DescOfClass(params.textclass).c_str());
650 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
651 fl_clear_choice(class_->choice_doc_fontsize);
652 fl_addto_choice(class_->choice_doc_fontsize, "default");
653 fl_addto_choice(class_->choice_doc_fontsize,
654 tclass.opt_fontsize().c_str());
655 fl_set_choice(class_->choice_doc_fontsize,
656 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
657 fl_clear_choice(class_->choice_doc_pagestyle);
658 fl_addto_choice(class_->choice_doc_pagestyle, "default");
659 fl_addto_choice(class_->choice_doc_pagestyle,
660 tclass.opt_pagestyle().c_str());
661 fl_set_choice(class_->choice_doc_pagestyle,
662 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
663 fl_set_button(class_->radio_doc_indent, 0);
664 fl_set_button(class_->radio_doc_skip, 0);
665 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
666 fl_set_button(class_->radio_doc_indent, 1);
668 fl_set_button(class_->radio_doc_skip, 1);
669 switch (params.getDefSkip().kind()) {
670 case VSpace::SMALLSKIP:
671 fl_set_choice (class_->choice_doc_skip, 1);
673 case VSpace::MEDSKIP:
674 fl_set_choice (class_->choice_doc_skip, 2);
676 case VSpace::BIGSKIP:
677 fl_set_choice (class_->choice_doc_skip, 3);
680 fl_set_choice (class_->choice_doc_skip, 4);
681 fl_set_input (class_->input_doc_skip,
682 params.getDefSkip().asLyXCommand().c_str());
685 fl_set_choice (class_->choice_doc_skip, 2);
688 fl_set_button(class_->radio_doc_sides_one, 0);
689 fl_set_button(class_->radio_doc_sides_two, 0);
690 if (params.sides == LyXTextClass::TwoSides)
691 fl_set_button(class_->radio_doc_sides_two, 1);
693 fl_set_button(class_->radio_doc_sides_one, 1);
694 fl_set_button(class_->radio_doc_columns_one, 0);
695 fl_set_button(class_->radio_doc_columns_two, 0);
696 if (params.columns == 2)
697 fl_set_button(class_->radio_doc_columns_two, 1);
699 fl_set_button(class_->radio_doc_columns_one, 1);
700 fl_set_input(class_->input_doc_spacing, "");
701 switch (params.spacing.getSpace()) {
702 case Spacing::Default: // nothing bad should happen with this
703 case Spacing::Single:
705 fl_set_choice(class_->choice_doc_spacing, 1);
707 case Spacing::Onehalf:
709 fl_set_choice(class_->choice_doc_spacing, 2);
711 case Spacing::Double:
713 fl_set_choice(class_->choice_doc_spacing, 3);
717 fl_set_choice(class_->choice_doc_spacing, 4);
719 sprintf(sval,"%g",params.spacing.getValue());
720 fl_set_input(class_->input_doc_spacing, sval);
724 if (!params.options.empty())
725 fl_set_input(class_->input_doc_extra, params.options.c_str());
727 fl_set_input(class_->input_doc_extra, "");
731 void FormDocument::language_update(BufferParams const & params)
736 combo_language->select_text(params.language->lang());
737 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
738 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
739 fl_set_button(language_->radio_single, 0);
740 fl_set_button(language_->radio_double, 0);
741 if (params.quotes_times == InsetQuotes::SingleQ)
742 fl_set_button(language_->radio_single, 1);
744 fl_set_button(language_->radio_double, 1);
748 void FormDocument::options_update(BufferParams const & params)
753 fl_set_choice_text(options_->choice_postscript_driver,
754 params.graphicsDriver.c_str());
755 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
756 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
757 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
758 if (!params.float_placement.empty())
759 fl_set_input(options_->input_float_placement,
760 params.float_placement.c_str());
762 fl_set_input(options_->input_float_placement, "");
766 void FormDocument::paper_update(BufferParams const & params)
771 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
772 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
773 fl_set_button(paper_->push_use_geometry, params.use_geometry);
774 fl_set_button(paper_->radio_portrait, 0);
775 fl_set_button(paper_->radio_landscape, 0);
776 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
777 fl_set_button(paper_->radio_landscape, 1);
779 fl_set_button(paper_->radio_portrait, 1);
780 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
781 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
782 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
783 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
784 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
785 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
786 fl_set_input(paper_->input_head_height, params.headheight.c_str());
787 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
788 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
789 fl_set_focus_object(paper_->form, paper_->choice_papersize2);
793 void FormDocument::bullets_update(BufferParams const & params)
795 if (!bullets_ || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
798 if (lv_->buffer()->isLinuxDoc()) {
799 fl_deactivate_object(fbullet);
800 fl_set_object_lcol(fbullet, FL_INACTIVE);
803 fl_activate_object(fbullet);
804 fl_set_object_lcol(fbullet, FL_BLACK);
807 fl_set_button(bullets_->radio_bullet_depth_1, 1);
808 fl_set_input(bullets_->input_bullet_latex,
809 params.user_defined_bullets[0].getText().c_str());
810 fl_set_choice(bullets_->choice_bullet_size,
811 params.user_defined_bullets[0].getSize() + 2);
815 void FormDocument::checkReadOnly()
817 if (bc_.readOnly(lv_->buffer()->isReadonly())) {
818 combo_doc_class->deactivate();
819 combo_language->deactivate();
820 fl_set_object_label(dialog_->text_warning,
821 _("Document is read-only."
822 " No changes to layout permitted."));
823 fl_show_object(dialog_->text_warning);
825 combo_doc_class->activate();
826 combo_language->activate();
827 fl_hide_object(dialog_->text_warning);
832 void FormDocument::checkMarginValues()
834 int const allEmpty = (!strlen(fl_get_input(paper_->input_top_margin)) &&
835 !strlen(fl_get_input(paper_->input_bottom_margin)) &&
836 !strlen(fl_get_input(paper_->input_left_margin)) &&
837 !strlen(fl_get_input(paper_->input_right_margin)) &&
838 !strlen(fl_get_input(paper_->input_head_height)) &&
839 !strlen(fl_get_input(paper_->input_head_sep)) &&
840 !strlen(fl_get_input(paper_->input_foot_skip)) &&
841 !strlen(fl_get_input(paper_->input_custom_width)) &&
842 !strlen(fl_get_input(paper_->input_custom_height)));
844 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 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 if (AskQuestion(_("Should I set some parameters to"), tct,
1089 _("the defaults of this document class?"))) {
1090 BufferParams & params = lv_->buffer()->params;
1092 params.textclass = tc;
1093 params.useClassDefaults();
1094 UpdateLayoutDocument(params);
1097 // unable to load new style
1098 WriteAlert(_("Conversion Errors!"),
1099 _("Unable to switch to new document class."),
1100 _("Reverting to original document class."));
1101 #ifdef USE_CLASS_COMBO
1102 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1104 fl_set_choice(class_->choice_doc_class,
1105 lv_->buffer()->params.textclass + 1);
1108 AllowInput(lv_->view());
1112 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1118 class_update(params);
1119 paper_update(params);
1120 language_update(params);
1121 options_update(params);
1122 bullets_update(params);