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);
94 bc().addReadOnly (dialog_->button_save_defaults);
96 // the document paper form
97 paper_.reset(build_doc_paper());
98 fl_addto_choice(paper_->choice_papersize2,
99 _(" Default | Custom | USletter | USlegal "
100 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
101 fl_addto_choice(paper_->choice_paperpackage,
103 "| A4 small Margins (only portrait) "
104 "| A4 very small Margins (only portrait) "
105 "| A4 very wide margins (only portrait) "));
106 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
107 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
108 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
109 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
110 fl_set_input_return(paper_->input_left_margin, FL_RETURN_CHANGED);
111 fl_set_input_return(paper_->input_right_margin, FL_RETURN_CHANGED);
112 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
113 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
114 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
116 bc().addReadOnly (paper_->choice_paperpackage);
117 bc().addReadOnly (paper_->greoup_radio_orientation);
118 bc().addReadOnly (paper_->radio_portrait);
119 bc().addReadOnly (paper_->radio_landscape);
120 bc().addReadOnly (paper_->choice_papersize2);
121 bc().addReadOnly (paper_->push_use_geometry);
122 bc().addReadOnly (paper_->input_custom_width);
123 bc().addReadOnly (paper_->input_custom_height);
124 bc().addReadOnly (paper_->input_top_margin);
125 bc().addReadOnly (paper_->input_bottom_margin);
126 bc().addReadOnly (paper_->input_left_margin);
127 bc().addReadOnly (paper_->input_right_margin);
128 bc().addReadOnly (paper_->input_head_height);
129 bc().addReadOnly (paper_->input_head_sep);
130 bc().addReadOnly (paper_->input_foot_skip);
132 // the document class form
133 class_.reset(build_doc_class());
136 // The language is a combo-box and has to be inserted manually
137 obj = class_->choice_doc_class;
138 fl_deactivate_object(obj);
139 fl_addto_form(class_->form);
140 combo_doc_class.reset(new Combox(FL_COMBOX_DROPLIST));
141 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400,
142 dialog_->tabbed_folder);
143 combo_doc_class->shortcut("#C",1);
144 combo_doc_class->setcallback(ComboInputCB, this);
146 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
147 cit != textclasslist.end(); ++cit)
149 combo_doc_class->addto(cit->description());
152 fl_addto_choice(class_->choice_doc_spacing,
153 _(" Single | OneHalf | Double | Other "));
154 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
155 for (n=0; tex_fonts[n][0]; ++n) {
156 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
158 fl_addto_choice(class_->choice_doc_pagestyle,
159 "default|empty|plain|headings|fancy");
160 fl_addto_choice(class_->choice_doc_skip,
161 _(" Smallskip | Medskip | Bigskip | Length "));
162 fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
163 fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
164 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
166 bc().addReadOnly (class_->radio_doc_indent);
167 bc().addReadOnly (class_->radio_doc_skip);
169 bc().addReadOnly (class_->choice_doc_pagestyle);
170 bc().addReadOnly (class_->choice_doc_fonts);
171 bc().addReadOnly (class_->choice_doc_fontsize);
172 bc().addReadOnly (class_->radio_doc_sides_one);
173 bc().addReadOnly (class_->radio_doc_sides_two);
174 bc().addReadOnly (class_->radio_doc_columns_one);
175 bc().addReadOnly (class_->radio_doc_columns_two);
176 bc().addReadOnly (class_->input_doc_extra);
177 bc().addReadOnly (class_->input_doc_skip);
178 bc().addReadOnly (class_->choice_doc_skip);
179 bc().addReadOnly (class_->choice_doc_spacing);
180 bc().addReadOnly (class_->input_doc_spacing);
181 bc().addReadOnly (class_->radio_auto_reset);
182 bc().addReadOnly (class_->button_reset_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 fl_set_object_label(dialog_->button_save_defaults,
313 _("Save as Defaults"));
315 BufferParams const & params = lv_->buffer()->params;
317 class_update(params);
318 paper_update(params);
319 language_update(params);
320 options_update(params);
321 bullets_update(params);
325 bool FormDocument::input( FL_OBJECT * ob, long data )
327 State cb = static_cast<State>( data );
330 case CHECKCHOICECLASS:
331 CheckChoiceClass(ob, 0);
333 case CHOICEBULLETSIZE:
334 ChoiceBulletSize(ob, 0);
336 case INPUTBULLETLATEX:
337 InputBulletLaTeX(ob, 0);
354 BulletBMTable(ob, 0);
360 if (ob == options_->check_use_natbib) {
361 setEnabled(options_->choice_citation_format,
362 fl_get_button(options_->check_use_natbib));
365 if (ob == class_->radio_auto_reset) {
366 lyxrc.auto_reset_options = fl_get_button(class_->radio_auto_reset);
369 if (ob == dialog_->button_save_defaults) {
370 lv_->getLyXFunc()->dispatch(LFUN_LAYOUT_SAVE_DEFAULT);
373 if (ob == class_->button_reset_defaults) {
374 BufferParams params = lv_->buffer()->params;
375 params.textclass = combo_doc_class->get() - 1;
376 params.useClassDefaults();
377 UpdateLayoutDocument(params);
381 setEnabled(class_->button_reset_defaults,
382 lv_->buffer()->params.hasClassDefaults());
387 case CHECKCHOICECLASS:
388 case CHOICEBULLETSIZE:
389 case INPUTBULLETLATEX:
391 return CheckDocumentInput(ob, 0);
400 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
402 FormDocument * pre = static_cast<FormDocument*>(v);
403 if (combox == pre->combo_doc_class.get())
404 pre->CheckChoiceClass(0, 0);
405 pre->bc().valid(pre->CheckDocumentInput(0,0));
409 bool FormDocument::class_apply()
412 BufferParams ¶ms = lv_->buffer()->params;
414 // If default skip is a "Length" but there's no text in the
415 // input field, reset the kind to "Medskip", which is the default.
416 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
417 !*(fl_get_input (class_->input_doc_skip))) {
418 fl_set_choice (class_->choice_doc_skip, 2);
420 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
421 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
422 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
424 unsigned int const new_class = combo_doc_class->get() - 1;
426 if (params.textclass != new_class) {
427 // try to load new_class
428 if (textclasslist.Load(new_class)) {
429 // successfully loaded
431 setMinibuffer(lv_, _("Converting document to new document class..."));
432 int ret = CutAndPaste::SwitchLayoutsBetweenClasses(
433 params.textclass, new_class,
434 lv_->buffer()->paragraph);
438 s = _("One paragraph couldn't be converted");
441 s += _(" paragraphs couldn't be converted");
443 WriteAlert(_("Conversion Errors!"),s,
444 _("into chosen document class"));
447 params.textclass = new_class;
449 // problem changing class -- warn user and retain old style
450 WriteAlert(_("Conversion Errors!"),
451 _("Errors loading new document class."),
452 _("Reverting to original document class."));
453 combo_doc_class->select(int(params.textclass) + 1);
456 BufferParams::PARSEP tmpsep = params.paragraph_separation;
457 if (fl_get_button(class_->radio_doc_indent))
458 params.paragraph_separation = BufferParams::PARSEP_INDENT;
460 params.paragraph_separation = BufferParams::PARSEP_SKIP;
461 if (tmpsep != params.paragraph_separation)
464 VSpace tmpdefskip = params.getDefSkip();
465 switch (fl_get_choice (class_->choice_doc_skip)) {
467 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
470 params.setDefSkip(VSpace(VSpace::MEDSKIP));
473 params.setDefSkip(VSpace(VSpace::BIGSKIP));
477 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
479 // DocumentDefskipCB assures that this never happens
481 params.setDefSkip(VSpace(VSpace::MEDSKIP));
484 if (!(tmpdefskip == params.getDefSkip()))
487 if (fl_get_button(class_->radio_doc_columns_two))
491 if (fl_get_button(class_->radio_doc_sides_two))
492 params.sides = LyXTextClass::TwoSides;
494 params.sides = LyXTextClass::OneSide;
496 Spacing tmpSpacing = params.spacing;
497 switch (fl_get_choice(class_->choice_doc_spacing)) {
499 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
500 params.spacing.set(Spacing::Single);
503 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
504 params.spacing.set(Spacing::Onehalf);
507 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
508 params.spacing.set(Spacing::Double);
511 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
512 params.spacing.set(Spacing::Other,
513 fl_get_input(class_->input_doc_spacing));
516 if (tmpSpacing != params.spacing)
519 params.options = fl_get_input(class_->input_doc_extra);
525 void FormDocument::paper_apply()
527 BufferParams & params = lv_->buffer()->params;
530 static_cast<char>(fl_get_choice(paper_->choice_papersize2)-1);
531 params.paperpackage =
532 static_cast<char>(fl_get_choice(paper_->choice_paperpackage)-1);
533 params.use_geometry = fl_get_button(paper_->push_use_geometry);
534 if (fl_get_button(paper_->radio_landscape))
535 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
537 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
538 params.paperwidth = fl_get_input(paper_->input_custom_width);
539 params.paperheight = fl_get_input(paper_->input_custom_height);
540 params.leftmargin = fl_get_input(paper_->input_left_margin);
541 params.topmargin = fl_get_input(paper_->input_top_margin);
542 params.rightmargin = fl_get_input(paper_->input_right_margin);
543 params.bottommargin = fl_get_input(paper_->input_bottom_margin);
544 params.headheight = fl_get_input(paper_->input_head_height);
545 params.headsep = fl_get_input(paper_->input_head_sep);
546 params.footskip = fl_get_input(paper_->input_foot_skip);
547 lv_->buffer()->setPaperStuff();
551 bool FormDocument::language_apply()
553 BufferParams & params = lv_->buffer()->params;
554 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
557 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
559 lga = InsetQuotes::EnglishQ;
562 lga = InsetQuotes::SwedishQ;
565 lga = InsetQuotes::GermanQ;
568 lga = InsetQuotes::PolishQ;
571 lga = InsetQuotes::FrenchQ;
574 lga = InsetQuotes::DanishQ;
577 params.quotes_language = lga;
578 if (fl_get_button(language_->radio_single))
579 params.quotes_times = InsetQuotes::SingleQ;
581 params.quotes_times = InsetQuotes::DoubleQ;
583 Language const * old_language = params.language;
584 Language const * new_language =
585 languages.getLanguage(combo_language->getline());
587 new_language = default_language;
589 if (old_language != new_language
590 && old_language->RightToLeft() == new_language->RightToLeft()
591 && !lv_->buffer()->isMultiLingual())
592 lv_->buffer()->changeLanguage(old_language, new_language);
593 if (old_language != new_language) {
596 params.language = new_language;
597 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
603 bool FormDocument::options_apply()
605 BufferParams & params = lv_->buffer()->params;
608 params.graphicsDriver =
609 fl_get_choice_text(options_->choice_postscript_driver);
610 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
611 params.use_natbib = fl_get_button(options_->check_use_natbib);
612 params.use_numerical_citations =
613 fl_get_choice(options_->choice_citation_format)-1;
615 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
616 if (params.secnumdepth != tmpchar)
618 params.secnumdepth = tmpchar;
620 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
622 params.float_placement =
623 fl_get_input(options_->input_float_placement);
629 void FormDocument::bullets_apply()
631 /* update the bullet settings */
632 BufferParams & param = lv_->buffer()->params;
634 // a little bit of loop unrolling
635 param.user_defined_bullets[0] = param.temp_bullets[0];
636 param.user_defined_bullets[1] = param.temp_bullets[1];
637 param.user_defined_bullets[2] = param.temp_bullets[2];
638 param.user_defined_bullets[3] = param.temp_bullets[3];
642 void FormDocument::class_update(BufferParams const & params)
647 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
649 combo_doc_class->select(
650 textclasslist.DescOfClass(params.textclass));
651 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
652 fl_clear_choice(class_->choice_doc_fontsize);
653 fl_addto_choice(class_->choice_doc_fontsize, "default");
654 fl_addto_choice(class_->choice_doc_fontsize,
655 tclass.opt_fontsize().c_str());
656 fl_set_choice(class_->choice_doc_fontsize,
657 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
658 fl_clear_choice(class_->choice_doc_pagestyle);
659 fl_addto_choice(class_->choice_doc_pagestyle, "default");
660 fl_addto_choice(class_->choice_doc_pagestyle,
661 tclass.opt_pagestyle().c_str());
662 fl_set_choice(class_->choice_doc_pagestyle,
663 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
664 fl_set_button(class_->radio_doc_indent, 0);
665 fl_set_button(class_->radio_doc_skip, 0);
666 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
667 fl_set_button(class_->radio_doc_indent, 1);
669 fl_set_button(class_->radio_doc_skip, 1);
670 switch (params.getDefSkip().kind()) {
671 case VSpace::SMALLSKIP:
672 fl_set_choice (class_->choice_doc_skip, 1);
674 case VSpace::MEDSKIP:
675 fl_set_choice (class_->choice_doc_skip, 2);
677 case VSpace::BIGSKIP:
678 fl_set_choice (class_->choice_doc_skip, 3);
681 fl_set_choice (class_->choice_doc_skip, 4);
682 fl_set_input (class_->input_doc_skip,
683 params.getDefSkip().asLyXCommand().c_str());
686 fl_set_choice (class_->choice_doc_skip, 2);
689 fl_set_button(class_->radio_doc_sides_one, 0);
690 fl_set_button(class_->radio_doc_sides_two, 0);
691 if (params.sides == LyXTextClass::TwoSides)
692 fl_set_button(class_->radio_doc_sides_two, 1);
694 fl_set_button(class_->radio_doc_sides_one, 1);
695 fl_set_button(class_->radio_doc_columns_one, 0);
696 fl_set_button(class_->radio_doc_columns_two, 0);
697 if (params.columns == 2)
698 fl_set_button(class_->radio_doc_columns_two, 1);
700 fl_set_button(class_->radio_doc_columns_one, 1);
701 fl_set_input(class_->input_doc_spacing, "");
702 switch (params.spacing.getSpace()) {
703 case Spacing::Default: // nothing bad should happen with this
704 case Spacing::Single:
706 fl_set_choice(class_->choice_doc_spacing, 1);
708 case Spacing::Onehalf:
710 fl_set_choice(class_->choice_doc_spacing, 2);
712 case Spacing::Double:
714 fl_set_choice(class_->choice_doc_spacing, 3);
718 fl_set_choice(class_->choice_doc_spacing, 4);
720 sprintf(sval,"%g",params.spacing.getValue());
721 fl_set_input(class_->input_doc_spacing, sval);
725 if (!params.options.empty())
726 fl_set_input(class_->input_doc_extra, params.options.c_str());
728 fl_set_input(class_->input_doc_extra, "");
729 fl_set_button(class_->radio_auto_reset, lyxrc.auto_reset_options);
730 fl_set_object_label(class_->button_reset_defaults, _("Reset"));
731 setEnabled(class_->button_reset_defaults, !params.hasClassDefaults());
736 void FormDocument::language_update(BufferParams const & params)
738 if (!language_.get())
741 combo_language->select(params.language->lang());
742 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
743 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
744 fl_set_button(language_->radio_single, 0);
745 fl_set_button(language_->radio_double, 0);
746 if (params.quotes_times == InsetQuotes::SingleQ)
747 fl_set_button(language_->radio_single, 1);
749 fl_set_button(language_->radio_double, 1);
753 void FormDocument::options_update(BufferParams const & params)
758 fl_set_choice_text(options_->choice_postscript_driver,
759 params.graphicsDriver.c_str());
760 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
761 fl_set_button(options_->check_use_natbib, params.use_natbib);
762 fl_set_choice(options_->choice_citation_format,
763 int(params.use_numerical_citations)+1);
764 setEnabled(options_->choice_citation_format, params.use_natbib);
765 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
766 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
767 if (!params.float_placement.empty())
768 fl_set_input(options_->input_float_placement,
769 params.float_placement.c_str());
771 fl_set_input(options_->input_float_placement, "");
775 void FormDocument::paper_update(BufferParams const & params)
780 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
781 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
782 fl_set_button(paper_->push_use_geometry, params.use_geometry);
783 fl_set_button(paper_->radio_portrait, 0);
784 fl_set_button(paper_->radio_landscape, 0);
785 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
786 fl_set_button(paper_->radio_landscape, 1);
788 fl_set_button(paper_->radio_portrait, 1);
789 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
790 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
791 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
792 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
793 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
794 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
795 fl_set_input(paper_->input_head_height, params.headheight.c_str());
796 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
797 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
798 fl_set_focus_object(paper_->form, paper_->choice_papersize2);
802 void FormDocument::bullets_update(BufferParams const & params)
804 if (!bullets_.get() || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
807 bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
808 setEnabled(fbullet, !isLinuxDoc);
810 if (isLinuxDoc) return;
812 fl_set_button(bullets_->radio_bullet_depth_1, 1);
813 fl_set_input(bullets_->input_bullet_latex,
814 params.user_defined_bullets[0].getText().c_str());
815 fl_set_choice(bullets_->choice_bullet_size,
816 params.user_defined_bullets[0].getSize() + 2);
820 void FormDocument::checkReadOnly()
822 if (bc().readOnly(lv_->buffer()->isReadonly())) {
823 combo_doc_class->deactivate();
824 combo_language->deactivate();
825 fl_set_object_label(dialog_->text_warning,
826 _("Document is read-only."
827 " No changes to layout permitted."));
828 fl_show_object(dialog_->text_warning);
830 combo_doc_class->activate();
831 combo_language->activate();
832 fl_hide_object(dialog_->text_warning);
837 void FormDocument::checkMarginValues()
839 bool const not_empty =
840 strlen(fl_get_input(paper_->input_top_margin)) ||
841 strlen(fl_get_input(paper_->input_bottom_margin)) ||
842 strlen(fl_get_input(paper_->input_left_margin)) ||
843 strlen(fl_get_input(paper_->input_right_margin)) ||
844 strlen(fl_get_input(paper_->input_head_height)) ||
845 strlen(fl_get_input(paper_->input_head_sep)) ||
846 strlen(fl_get_input(paper_->input_foot_skip)) ||
847 strlen(fl_get_input(paper_->input_custom_width)) ||
848 strlen(fl_get_input(paper_->input_custom_height));
850 fl_set_button(paper_->push_use_geometry, 1);
854 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
862 if (ob == paper_->choice_papersize2) {
863 val = fl_get_choice(paper_->choice_papersize2)-1;
864 if (val == BufferParams::VM_PAPER_DEFAULT) {
865 fl_set_button(paper_->push_use_geometry, 0);
868 if ((val != BufferParams::VM_PAPER_USLETTER) &&
869 (val != BufferParams::VM_PAPER_USLEGAL) &&
870 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
871 (val != BufferParams::VM_PAPER_A4) &&
872 (val != BufferParams::VM_PAPER_A5) &&
873 (val != BufferParams::VM_PAPER_B5)) {
874 fl_set_button(paper_->push_use_geometry, 1);
876 fl_set_choice(paper_->choice_paperpackage,
877 BufferParams::PACKAGE_NONE + 1);
879 } else if (ob == paper_->choice_paperpackage) {
880 val = fl_get_choice(paper_->choice_paperpackage)-1;
881 if (val != BufferParams::PACKAGE_NONE) {
882 fl_set_choice(paper_->choice_papersize2,
883 BufferParams::VM_PAPER_DEFAULT + 1);
884 fl_set_button(paper_->push_use_geometry, 0);
886 } else if (ob == class_->input_doc_spacing) {
887 input = fl_get_input(class_->input_doc_spacing);
889 fl_set_choice (class_->choice_doc_spacing, 1);
891 fl_set_choice(class_->choice_doc_spacing, 4);
894 // this has to be all out of if/elseif because it has to deactivate
895 // the document buttons and so the whole stuff has to be tested again.
896 str = fl_get_input(paper_->input_custom_width);
897 ok = ok && (str.empty() || isValidLength(str));
898 str = fl_get_input(paper_->input_custom_height);
899 ok = ok && (str.empty() || isValidLength(str));
900 str = fl_get_input(paper_->input_left_margin);
901 ok = ok && (str.empty() || isValidLength(str));
902 str = fl_get_input(paper_->input_right_margin);
903 ok = ok && (str.empty() || isValidLength(str));
904 str = fl_get_input(paper_->input_top_margin);
905 ok = ok && (str.empty() || isValidLength(str));
906 str = fl_get_input(paper_->input_bottom_margin);
907 ok = ok && (str.empty() || isValidLength(str));
908 str = fl_get_input(paper_->input_head_height);
909 ok = ok && (str.empty() || isValidLength(str));
910 str = fl_get_input(paper_->input_head_sep);
911 ok = ok && (str.empty() || isValidLength(str));
912 str = fl_get_input(paper_->input_foot_skip);
913 ok = ok && (str.empty() || isValidLength(str));
914 // "Synchronize" the choice and the input field, so that it
915 // is impossible to commit senseless data.
916 input = fl_get_input (class_->input_doc_skip);
917 if (ob == class_->input_doc_skip) {
919 fl_set_choice (class_->choice_doc_skip, 2);
920 } else if (isValidGlueLength (input)) {
921 fl_set_choice (class_->choice_doc_skip, 4);
923 fl_set_choice(class_->choice_doc_skip, 4);
927 if (*input && !isValidGlueLength(input))
930 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
932 else if (fl_get_choice(class_->choice_doc_skip) != 4)
933 fl_set_input (class_->input_doc_skip, "");
935 input = fl_get_input(class_->input_doc_spacing);
936 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
938 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
939 fl_set_input (class_->input_doc_spacing, "");
944 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
946 BufferParams & param = lv_->buffer()->params;
948 // convert from 1-6 range to -1-4
949 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
950 fl_set_input(bullets_->input_bullet_latex,
951 param.temp_bullets[current_bullet_depth].getText().c_str());
955 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
957 BufferParams & param = lv_->buffer()->params;
959 param.temp_bullets[current_bullet_depth].
960 setText(fl_get_input(bullets_->input_bullet_latex));
964 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
966 /* Should I do the following: */
967 /* 1. change to the panel that the current bullet belongs in */
968 /* 2. show that bullet as selected */
969 /* 3. change the size setting to the size of the bullet in Q.*/
970 /* 4. display the latex equivalent in the latex box */
972 /* I'm inclined to just go with 3 and 4 at the moment and */
973 /* maybe try to support the others later */
974 BufferParams & param = lv_->buffer()->params;
977 if (cb == BULLETDEPTH1 )
979 else if (cb == BULLETDEPTH2 )
981 else if (cb == BULLETDEPTH3 )
983 else if (cb == BULLETDEPTH4 )
986 switch (fl_get_button_numb(ob)) {
988 // right mouse button resets to default
989 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
991 current_bullet_depth = data;
992 fl_set_input(bullets_->input_bullet_latex,
993 param.temp_bullets[data].getText().c_str());
994 fl_set_choice(bullets_->choice_bullet_size,
995 param.temp_bullets[data].getSize() + 2);
1000 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
1002 /* Here we have to change the background pixmap to that selected */
1003 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1006 if (cb == BULLETPANEL1 )
1008 else if (cb == BULLETPANEL2 )
1010 else if (cb == BULLETPANEL3 )
1012 else if (cb == BULLETPANEL4 )
1014 else if (cb == BULLETPANEL5 )
1016 else if (cb == BULLETPANEL6 )
1019 if (data != current_bullet_panel) {
1020 fl_freeze_form(bullets_->form);
1021 current_bullet_panel = data;
1023 /* free the current pixmap */
1024 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1027 /* display the new one */
1029 new_panel = "standard";
1032 new_panel = "amssymb";
1035 new_panel = "psnfss1";
1038 new_panel = "psnfss2";
1041 new_panel = "psnfss3";
1044 new_panel = "psnfss4";
1047 /* something very wrong happened */
1048 // play it safe for now but should be an exception
1049 current_bullet_panel = 0; // standard panel
1050 new_panel = "standard";
1053 new_panel += ".xpm";
1054 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1055 LibFileSearch("images", new_panel).c_str());
1056 fl_redraw_object(bullets_->bmtable_bullet_panel);
1057 fl_unfreeze_form(bullets_->form);
1062 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1064 /* handle the user input by setting the current bullet depth's pixmap */
1065 /* to that extracted from the current chosen position of the BMTable */
1066 /* Don't forget to free the button's old pixmap first. */
1068 BufferParams & param = lv_->buffer()->params;
1069 int bmtable_button = fl_get_bmtable(ob);
1071 /* try to keep the button held down till another is pushed */
1072 /* fl_set_bmtable(ob, 1, bmtable_button); */
1073 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1074 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1075 fl_set_input(bullets_->input_bullet_latex,
1076 param.temp_bullets[current_bullet_depth].getText().c_str());
1080 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1083 ob = class_->choice_doc_class;
1085 lv_->prohibitInput();
1087 unsigned int tc = combo_doc_class->get() - 1;
1088 if (textclasslist.Load(tc)) {
1089 // we use a copy of the bufferparams because we do not
1090 // want to modify them yet.
1091 BufferParams params = lv_->buffer()->params;
1093 if (lyxrc.auto_reset_options) {
1094 params.textclass = tc;
1095 params.useClassDefaults();
1096 UpdateLayoutDocument(params);
1099 // unable to load new style
1100 WriteAlert(_("Conversion Errors!"),
1101 _("Unable to switch to new document class."),
1102 _("Reverting to original document class."));
1103 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1109 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1115 class_update(params);
1116 paper_update(params);
1117 language_update(params);
1118 options_update(params);
1119 bullets_update(params);