1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000-2001 The LyX Team.
10 *======================================================*/
14 #include FORMS_H_LOCATION
15 #include XPM_H_LOCATION
18 #pragma implementation
21 #include "lyx_gui_misc.h"
23 #include "FormDocument.h"
24 #include "form_document.h"
28 #include "tex-strings.h"
29 #include "bufferparams.h"
30 #include "insets/insetquotes.h"
33 #include "support/filetools.h"
34 #include "support/lstrings.h"
39 #include "BufferView.h"
42 #include "CutAndPaste.h"
43 #include "bufferview_funcs.h"
44 #include "xforms_helpers.h"
47 using Liason::setMinibuffer;
50 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
51 : FormBaseBD(lv, d, _("Document Layout")),
52 ActCell(0), Confirmed(0),
53 current_bullet_panel(0), current_bullet_depth(0), fbullet(0)
55 // let the dialog 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->showDocument.connect(slot(this, &FormDocument::show));
62 void FormDocument::redraw()
64 if( form() && form()->visible )
65 fl_redraw_form( form() );
69 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabbed_folder);
70 if (outer_form && outer_form->visible)
71 fl_redraw_form( outer_form );
75 FL_FORM * FormDocument::form() const
77 if (dialog_.get()) return dialog_->form;
82 void FormDocument::build()
87 dialog_.reset(build_tabbed_document());
89 // Manage the restore, ok, apply, restore and cancel/close buttons
90 bc().setOK(dialog_->button_ok);
91 bc().setApply(dialog_->button_apply);
92 bc().setCancel(dialog_->button_cancel);
93 bc().setRestore(dialog_->button_restore);
95 // the document paper form
96 paper_.reset(build_doc_paper());
97 fl_addto_choice(paper_->choice_papersize2,
98 _(" Default | Custom | USletter | USlegal "
99 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
100 fl_addto_choice(paper_->choice_paperpackage,
102 "| A4 small Margins (only portrait) "
103 "| A4 very small Margins (only portrait) "
104 "| A4 very wide margins (only portrait) "));
105 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
106 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
107 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
108 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
109 fl_set_input_return(paper_->input_left_margin, FL_RETURN_CHANGED);
110 fl_set_input_return(paper_->input_right_margin, FL_RETURN_CHANGED);
111 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
112 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
113 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
115 bc().addReadOnly (paper_->choice_paperpackage);
116 bc().addReadOnly (paper_->greoup_radio_orientation);
117 bc().addReadOnly (paper_->radio_portrait);
118 bc().addReadOnly (paper_->radio_landscape);
119 bc().addReadOnly (paper_->choice_papersize2);
120 bc().addReadOnly (paper_->push_use_geometry);
121 bc().addReadOnly (paper_->input_custom_width);
122 bc().addReadOnly (paper_->input_custom_height);
123 bc().addReadOnly (paper_->input_top_margin);
124 bc().addReadOnly (paper_->input_bottom_margin);
125 bc().addReadOnly (paper_->input_left_margin);
126 bc().addReadOnly (paper_->input_right_margin);
127 bc().addReadOnly (paper_->input_head_height);
128 bc().addReadOnly (paper_->input_head_sep);
129 bc().addReadOnly (paper_->input_foot_skip);
131 // the document class form
132 class_.reset(build_doc_class());
135 // The language is a combo-box and has to be inserted manually
136 obj = class_->choice_doc_class;
137 fl_deactivate_object(obj);
138 fl_addto_form(class_->form);
139 combo_doc_class.reset(new Combox(FL_COMBOX_DROPLIST));
140 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400,
141 dialog_->tabbed_folder);
142 combo_doc_class->shortcut("#C",1);
143 combo_doc_class->setcallback(ComboInputCB, this);
145 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
146 cit != textclasslist.end(); ++cit)
148 combo_doc_class->addto(cit->description());
151 fl_addto_choice(class_->choice_doc_spacing,
152 _(" Single | OneHalf | Double | Other "));
153 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
154 for (n=0; tex_fonts[n][0]; ++n) {
155 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
157 fl_addto_choice(class_->choice_doc_pagestyle,
158 "default|empty|plain|headings|fancy");
159 fl_addto_choice(class_->choice_doc_skip,
160 _(" Smallskip | Medskip | Bigskip | Length "));
161 fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
162 fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
163 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
165 bc().addReadOnly (class_->radio_doc_indent);
166 bc().addReadOnly (class_->radio_doc_skip);
168 bc().addReadOnly (class_->choice_doc_pagestyle);
169 bc().addReadOnly (class_->choice_doc_fonts);
170 bc().addReadOnly (class_->choice_doc_fontsize);
171 bc().addReadOnly (class_->radio_doc_sides_one);
172 bc().addReadOnly (class_->radio_doc_sides_two);
173 bc().addReadOnly (class_->radio_doc_columns_one);
174 bc().addReadOnly (class_->radio_doc_columns_two);
175 bc().addReadOnly (class_->input_doc_extra);
176 bc().addReadOnly (class_->input_doc_skip);
177 bc().addReadOnly (class_->choice_doc_skip);
178 bc().addReadOnly (class_->choice_doc_spacing);
179 bc().addReadOnly (class_->input_doc_spacing);
180 bc().addReadOnly (class_->radio_auto_reset);
181 bc().addReadOnly (class_->button_reset_defaults);
182 bc().addReadOnly (class_->button_save_defaults);
185 // the document language form
186 language_.reset(build_doc_language());
187 fl_addto_choice(language_->choice_inputenc,
188 "default|auto|latin1|latin2|latin5|latin9"
189 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
191 // The language is a combo-box and has to be inserted manually
192 obj = language_->choice_language;
193 fl_deactivate_object(obj);
194 fl_addto_form(language_->form);
195 combo_language.reset(new Combox(FL_COMBOX_DROPLIST));
196 combo_language->add(obj->x, obj->y, obj->w, obj->h, 400,
197 dialog_->tabbed_folder);
198 combo_language->shortcut("#L",1);
199 combo_language->setcallback(ComboInputCB, this);
202 for (Languages::const_iterator cit = languages.begin();
203 cit != languages.end(); ++cit) {
204 combo_language->addto(cit->second.lang());
207 fl_addto_choice(language_->choice_quotes_language,
208 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
209 " «text» | »text« "));
211 bc().addReadOnly (language_->choice_inputenc);
212 bc().addReadOnly (language_->choice_quotes_language);
213 bc().addReadOnly (language_->radio_single);
214 bc().addReadOnly (language_->radio_double);
216 // the document options form
217 options_.reset(build_doc_options());
218 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
219 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
220 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
221 fl_set_counter_step(options_->slider_secnumdepth,1,1);
222 fl_set_counter_step(options_->slider_tocdepth,1,1);
223 fl_set_counter_precision(options_->slider_secnumdepth, 0);
224 fl_set_counter_precision(options_->slider_tocdepth, 0);
225 for (n=0; tex_graphics[n][0]; ++n) {
226 fl_addto_choice(options_->choice_postscript_driver, tex_graphics[n]);
228 fl_addto_choice(options_->choice_citation_format,
229 _(" Author-year | Numerical "));
231 bc_.addReadOnly (options_->slider_secnumdepth);
232 bc_.addReadOnly (options_->slider_tocdepth);
233 bc_.addReadOnly (options_->check_use_amsmath);
234 bc_.addReadOnly (options_->check_use_natbib);
235 bc_.addReadOnly (options_->choice_citation_format);
236 bc_.addReadOnly (options_->input_float_placement);
237 bc_.addReadOnly (options_->choice_postscript_driver);
239 // the document bullets form
240 bullets_.reset(build_doc_bullet());
241 fl_addto_choice(bullets_->choice_bullet_size,
242 _(" default | tiny | script | footnote | small |"
243 " normal | large | Large | LARGE | huge | Huge"));
244 fl_set_choice(bullets_->choice_bullet_size, 1);
245 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
246 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
248 bc().addReadOnly (bullets_->bmtable_bullet_panel);
249 bc().addReadOnly (bullets_->choice_bullet_size);
250 bc().addReadOnly (bullets_->input_bullet_latex);
251 bc().addReadOnly (bullets_->radio_bullet_depth);
252 bc().addReadOnly (bullets_->radio_bullet_panel);
254 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
256 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
258 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
260 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
262 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
264 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
265 lyxerr << _("Your version of libXpm is older than 4.7.\n"
266 "The `bullet' tab of the document dialog "
267 "has been disabled") << '\n';
268 fl_deactivate_object(fbullet);
269 fl_set_object_lcol(fbullet, FL_INACTIVE);
274 void FormDocument::apply()
276 if (!lv_->view()->available() || !dialog_.get())
279 bool redo = class_apply();
281 redo = language_apply() || redo;
282 redo = options_apply() || redo;
286 lv_->view()->redoCurrentBuffer();
288 lv_->buffer()->markDirty();
289 setMinibuffer(lv_, _("Document layout set"));
293 void FormDocument::cancel()
295 // this avoids confusion when reopening
296 BufferParams & param = lv_->buffer()->params;
297 param.temp_bullets[0] = param.user_defined_bullets[0];
298 param.temp_bullets[1] = param.user_defined_bullets[1];
299 param.temp_bullets[2] = param.user_defined_bullets[2];
300 param.temp_bullets[3] = param.user_defined_bullets[3];
305 void FormDocument::update()
312 BufferParams const & params = lv_->buffer()->params;
314 class_update(params);
315 paper_update(params);
316 language_update(params);
317 options_update(params);
318 bullets_update(params);
322 bool FormDocument::input( FL_OBJECT * ob, long data )
324 State cb = static_cast<State>( data );
327 case CHECKCHOICECLASS:
328 CheckChoiceClass(ob, 0);
330 case CHOICEBULLETSIZE:
331 ChoiceBulletSize(ob, 0);
333 case INPUTBULLETLATEX:
334 InputBulletLaTeX(ob, 0);
351 BulletBMTable(ob, 0);
357 if (ob == options_->check_use_natbib) {
358 setEnabled(options_->choice_citation_format,
359 fl_get_button(options_->check_use_natbib));
362 if (ob == class_->radio_auto_reset) {
363 lyxrc.auto_reset_options = fl_get_button(class_->radio_auto_reset);
366 if (ob == class_->button_save_defaults) {
367 lv_->getLyXFunc()->dispatch(LFUN_LAYOUT_SAVE_DEFAULT);
370 if (ob == class_->button_reset_defaults) {
371 BufferParams params = lv_->buffer()->params;
372 params.textclass = combo_doc_class->get() - 1;
373 params.useClassDefaults();
374 UpdateLayoutDocument(params);
378 setEnabled(class_->button_reset_defaults,
379 lv_->buffer()->params.hasClassDefaults());
384 case CHECKCHOICECLASS:
385 case CHOICEBULLETSIZE:
386 case INPUTBULLETLATEX:
388 return CheckDocumentInput(ob, 0);
397 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
399 FormDocument * pre = static_cast<FormDocument*>(v);
400 if (combox == pre->combo_doc_class.get())
401 pre->CheckChoiceClass(0, 0);
402 pre->bc().valid(pre->CheckDocumentInput(0,0));
406 bool FormDocument::class_apply()
409 BufferParams ¶ms = lv_->buffer()->params;
411 // If default skip is a "Length" but there's no text in the
412 // input field, reset the kind to "Medskip", which is the default.
413 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
414 !*(fl_get_input (class_->input_doc_skip))) {
415 fl_set_choice (class_->choice_doc_skip, 2);
417 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
418 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
419 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
421 unsigned int const new_class = combo_doc_class->get() - 1;
423 if (params.textclass != new_class) {
424 // try to load new_class
425 if (textclasslist.Load(new_class)) {
426 // successfully loaded
428 setMinibuffer(lv_, _("Converting document to new document class..."));
429 int ret = CutAndPaste::SwitchLayoutsBetweenClasses(
430 params.textclass, new_class,
431 lv_->buffer()->paragraph);
435 s = _("One paragraph couldn't be converted");
438 s += _(" paragraphs couldn't be converted");
440 WriteAlert(_("Conversion Errors!"),s,
441 _("into chosen document class"));
444 params.textclass = new_class;
446 // problem changing class -- warn user and retain old style
447 WriteAlert(_("Conversion Errors!"),
448 _("Errors loading new document class."),
449 _("Reverting to original document class."));
450 combo_doc_class->select(int(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);
608 params.use_natbib = fl_get_button(options_->check_use_natbib);
609 params.use_numerical_citations =
610 fl_get_choice(options_->choice_citation_format)-1;
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 combo_doc_class->select(
647 textclasslist.DescOfClass(params.textclass));
648 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
649 fl_clear_choice(class_->choice_doc_fontsize);
650 fl_addto_choice(class_->choice_doc_fontsize, "default");
651 fl_addto_choice(class_->choice_doc_fontsize,
652 tclass.opt_fontsize().c_str());
653 fl_set_choice(class_->choice_doc_fontsize,
654 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
655 fl_clear_choice(class_->choice_doc_pagestyle);
656 fl_addto_choice(class_->choice_doc_pagestyle, "default");
657 fl_addto_choice(class_->choice_doc_pagestyle,
658 tclass.opt_pagestyle().c_str());
659 fl_set_choice(class_->choice_doc_pagestyle,
660 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
661 fl_set_button(class_->radio_doc_indent, 0);
662 fl_set_button(class_->radio_doc_skip, 0);
663 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
664 fl_set_button(class_->radio_doc_indent, 1);
666 fl_set_button(class_->radio_doc_skip, 1);
667 switch (params.getDefSkip().kind()) {
668 case VSpace::SMALLSKIP:
669 fl_set_choice (class_->choice_doc_skip, 1);
671 case VSpace::MEDSKIP:
672 fl_set_choice (class_->choice_doc_skip, 2);
674 case VSpace::BIGSKIP:
675 fl_set_choice (class_->choice_doc_skip, 3);
678 fl_set_choice (class_->choice_doc_skip, 4);
679 fl_set_input (class_->input_doc_skip,
680 params.getDefSkip().asLyXCommand().c_str());
683 fl_set_choice (class_->choice_doc_skip, 2);
686 fl_set_button(class_->radio_doc_sides_one, 0);
687 fl_set_button(class_->radio_doc_sides_two, 0);
688 if (params.sides == LyXTextClass::TwoSides)
689 fl_set_button(class_->radio_doc_sides_two, 1);
691 fl_set_button(class_->radio_doc_sides_one, 1);
692 fl_set_button(class_->radio_doc_columns_one, 0);
693 fl_set_button(class_->radio_doc_columns_two, 0);
694 if (params.columns == 2)
695 fl_set_button(class_->radio_doc_columns_two, 1);
697 fl_set_button(class_->radio_doc_columns_one, 1);
698 fl_set_input(class_->input_doc_spacing, "");
699 switch (params.spacing.getSpace()) {
700 case Spacing::Default: // nothing bad should happen with this
701 case Spacing::Single:
703 fl_set_choice(class_->choice_doc_spacing, 1);
705 case Spacing::Onehalf:
707 fl_set_choice(class_->choice_doc_spacing, 2);
709 case Spacing::Double:
711 fl_set_choice(class_->choice_doc_spacing, 3);
715 fl_set_choice(class_->choice_doc_spacing, 4);
717 sprintf(sval,"%g",params.spacing.getValue());
718 fl_set_input(class_->input_doc_spacing, sval);
722 if (!params.options.empty())
723 fl_set_input(class_->input_doc_extra, params.options.c_str());
725 fl_set_input(class_->input_doc_extra, "");
726 fl_set_button(class_->radio_auto_reset, lyxrc.auto_reset_options);
727 fl_set_object_label(class_->button_reset_defaults, _("Reset"));
728 setEnabled(class_->button_reset_defaults, !params.hasClassDefaults());
729 fl_set_object_label(class_->button_save_defaults, _("Save as Defaults"));
734 void FormDocument::language_update(BufferParams const & params)
736 if (!language_.get())
739 combo_language->select(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_button(options_->check_use_natbib, params.use_natbib);
760 fl_set_choice(options_->choice_citation_format,
761 int(params.use_numerical_citations)+1);
762 setEnabled(options_->choice_citation_format, params.use_natbib);
763 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
764 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
765 if (!params.float_placement.empty())
766 fl_set_input(options_->input_float_placement,
767 params.float_placement.c_str());
769 fl_set_input(options_->input_float_placement, "");
773 void FormDocument::paper_update(BufferParams const & params)
778 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
779 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
780 fl_set_button(paper_->push_use_geometry, params.use_geometry);
781 fl_set_button(paper_->radio_portrait, 0);
782 fl_set_button(paper_->radio_landscape, 0);
783 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
784 fl_set_button(paper_->radio_landscape, 1);
786 fl_set_button(paper_->radio_portrait, 1);
787 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
788 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
789 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
790 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
791 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
792 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
793 fl_set_input(paper_->input_head_height, params.headheight.c_str());
794 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
795 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
796 fl_set_focus_object(paper_->form, paper_->choice_papersize2);
800 void FormDocument::bullets_update(BufferParams const & params)
802 if (!bullets_.get() || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
805 bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
806 setEnabled(fbullet, !isLinuxDoc);
808 if (isLinuxDoc) return;
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()
837 bool const not_empty =
838 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);
852 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
860 if (ob == paper_->choice_papersize2) {
861 val = fl_get_choice(paper_->choice_papersize2)-1;
862 if (val == BufferParams::VM_PAPER_DEFAULT) {
863 fl_set_button(paper_->push_use_geometry, 0);
866 if ((val != BufferParams::VM_PAPER_USLETTER) &&
867 (val != BufferParams::VM_PAPER_USLEGAL) &&
868 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
869 (val != BufferParams::VM_PAPER_A4) &&
870 (val != BufferParams::VM_PAPER_A5) &&
871 (val != BufferParams::VM_PAPER_B5)) {
872 fl_set_button(paper_->push_use_geometry, 1);
874 fl_set_choice(paper_->choice_paperpackage,
875 BufferParams::PACKAGE_NONE + 1);
877 } else if (ob == paper_->choice_paperpackage) {
878 val = fl_get_choice(paper_->choice_paperpackage)-1;
879 if (val != BufferParams::PACKAGE_NONE) {
880 fl_set_choice(paper_->choice_papersize2,
881 BufferParams::VM_PAPER_DEFAULT + 1);
882 fl_set_button(paper_->push_use_geometry, 0);
884 } else if (ob == class_->input_doc_spacing) {
885 input = fl_get_input(class_->input_doc_spacing);
887 fl_set_choice (class_->choice_doc_spacing, 1);
889 fl_set_choice(class_->choice_doc_spacing, 4);
892 // this has to be all out of if/elseif because it has to deactivate
893 // the document buttons and so the whole stuff has to be tested again.
894 str = fl_get_input(paper_->input_custom_width);
895 ok = ok && (str.empty() || isValidLength(str));
896 str = fl_get_input(paper_->input_custom_height);
897 ok = ok && (str.empty() || isValidLength(str));
898 str = fl_get_input(paper_->input_left_margin);
899 ok = ok && (str.empty() || isValidLength(str));
900 str = fl_get_input(paper_->input_right_margin);
901 ok = ok && (str.empty() || isValidLength(str));
902 str = fl_get_input(paper_->input_top_margin);
903 ok = ok && (str.empty() || isValidLength(str));
904 str = fl_get_input(paper_->input_bottom_margin);
905 ok = ok && (str.empty() || isValidLength(str));
906 str = fl_get_input(paper_->input_head_height);
907 ok = ok && (str.empty() || isValidLength(str));
908 str = fl_get_input(paper_->input_head_sep);
909 ok = ok && (str.empty() || isValidLength(str));
910 str = fl_get_input(paper_->input_foot_skip);
911 ok = ok && (str.empty() || isValidLength(str));
912 // "Synchronize" the choice and the input field, so that it
913 // is impossible to commit senseless data.
914 input = fl_get_input (class_->input_doc_skip);
915 if (ob == class_->input_doc_skip) {
917 fl_set_choice (class_->choice_doc_skip, 2);
918 } else if (isValidGlueLength (input)) {
919 fl_set_choice (class_->choice_doc_skip, 4);
921 fl_set_choice(class_->choice_doc_skip, 4);
925 if (*input && !isValidGlueLength(input))
928 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
930 else if (fl_get_choice(class_->choice_doc_skip) != 4)
931 fl_set_input (class_->input_doc_skip, "");
933 input = fl_get_input(class_->input_doc_spacing);
934 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
936 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
937 fl_set_input (class_->input_doc_spacing, "");
942 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
944 BufferParams & param = lv_->buffer()->params;
946 // convert from 1-6 range to -1-4
947 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
948 fl_set_input(bullets_->input_bullet_latex,
949 param.temp_bullets[current_bullet_depth].getText().c_str());
953 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
955 BufferParams & param = lv_->buffer()->params;
957 param.temp_bullets[current_bullet_depth].
958 setText(fl_get_input(bullets_->input_bullet_latex));
962 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
964 /* Should I do the following: */
965 /* 1. change to the panel that the current bullet belongs in */
966 /* 2. show that bullet as selected */
967 /* 3. change the size setting to the size of the bullet in Q.*/
968 /* 4. display the latex equivalent in the latex box */
970 /* I'm inclined to just go with 3 and 4 at the moment and */
971 /* maybe try to support the others later */
972 BufferParams & param = lv_->buffer()->params;
975 if (cb == BULLETDEPTH1 )
977 else if (cb == BULLETDEPTH2 )
979 else if (cb == BULLETDEPTH3 )
981 else if (cb == BULLETDEPTH4 )
984 switch (fl_get_button_numb(ob)) {
986 // right mouse button resets to default
987 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
989 current_bullet_depth = data;
990 fl_set_input(bullets_->input_bullet_latex,
991 param.temp_bullets[data].getText().c_str());
992 fl_set_choice(bullets_->choice_bullet_size,
993 param.temp_bullets[data].getSize() + 2);
998 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
1000 /* Here we have to change the background pixmap to that selected */
1001 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1004 if (cb == BULLETPANEL1 )
1006 else if (cb == BULLETPANEL2 )
1008 else if (cb == BULLETPANEL3 )
1010 else if (cb == BULLETPANEL4 )
1012 else if (cb == BULLETPANEL5 )
1014 else if (cb == BULLETPANEL6 )
1017 if (data != current_bullet_panel) {
1018 fl_freeze_form(bullets_->form);
1019 current_bullet_panel = data;
1021 /* free the current pixmap */
1022 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1025 /* display the new one */
1027 new_panel = "standard";
1030 new_panel = "amssymb";
1033 new_panel = "psnfss1";
1036 new_panel = "psnfss2";
1039 new_panel = "psnfss3";
1042 new_panel = "psnfss4";
1045 /* something very wrong happened */
1046 // play it safe for now but should be an exception
1047 current_bullet_panel = 0; // standard panel
1048 new_panel = "standard";
1051 new_panel += ".xpm";
1052 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1053 LibFileSearch("images", new_panel).c_str());
1054 fl_redraw_object(bullets_->bmtable_bullet_panel);
1055 fl_unfreeze_form(bullets_->form);
1060 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1062 /* handle the user input by setting the current bullet depth's pixmap */
1063 /* to that extracted from the current chosen position of the BMTable */
1064 /* Don't forget to free the button's old pixmap first. */
1066 BufferParams & param = lv_->buffer()->params;
1067 int bmtable_button = fl_get_bmtable(ob);
1069 /* try to keep the button held down till another is pushed */
1070 /* fl_set_bmtable(ob, 1, bmtable_button); */
1071 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1072 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1073 fl_set_input(bullets_->input_bullet_latex,
1074 param.temp_bullets[current_bullet_depth].getText().c_str());
1078 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1081 ob = class_->choice_doc_class;
1083 lv_->prohibitInput();
1085 unsigned int tc = combo_doc_class->get() - 1;
1086 if (textclasslist.Load(tc)) {
1087 // we use a copy of the bufferparams because we do not
1088 // want to modify them yet.
1089 BufferParams params = lv_->buffer()->params;
1091 if (lyxrc.auto_reset_options) {
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 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1107 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1113 class_update(params);
1114 paper_update(params);
1115 language_update(params);
1116 options_update(params);
1117 bullets_update(params);