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"
46 #include "input_validators.h" // fl_unsigned_float_filter
48 using Liason::setMinibuffer;
51 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
52 : FormBaseBD(lv, d, _("Document Layout")),
53 ActCell(0), Confirmed(0),
54 current_bullet_panel(0), current_bullet_depth(0), fbullet(0)
56 // let the dialog be shown
57 // This is a permanent connection so we won't bother
58 // storing a copy because we won't be disconnecting.
59 d->showDocument.connect(slot(this, &FormDocument::show));
63 void FormDocument::redraw()
65 if( form() && form()->visible )
66 fl_redraw_form( form() );
70 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabbed_folder);
71 if (outer_form && outer_form->visible)
72 fl_redraw_form( outer_form );
76 FL_FORM * FormDocument::form() const
78 if (dialog_.get()) return dialog_->form;
83 void FormDocument::build()
88 dialog_.reset(build_tabbed_document());
90 // Manage the restore, ok, apply, restore and cancel/close buttons
91 bc().setOK(dialog_->button_ok);
92 bc().setApply(dialog_->button_apply);
93 bc().setCancel(dialog_->button_cancel);
94 bc().setRestore(dialog_->button_restore);
95 bc().addReadOnly (dialog_->button_save_defaults);
96 bc().addReadOnly (dialog_->button_reset_defaults);
98 // the document paper form
99 paper_.reset(build_doc_paper());
100 fl_addto_choice(paper_->choice_papersize,
101 _(" Default | Custom | USletter | USlegal "
102 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
103 fl_addto_choice(paper_->choice_paperpackage,
106 "| Very small Margins "
107 "| Very wide Margins "));
109 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
110 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
111 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
112 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
113 fl_set_input_return(paper_->input_left_margin, FL_RETURN_CHANGED);
114 fl_set_input_return(paper_->input_right_margin, FL_RETURN_CHANGED);
115 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
116 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
117 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
119 // Set input filters on width and height to make them accept only
121 fl_set_input_filter(paper_->input_custom_width,
122 fl_unsigned_float_filter);
123 fl_set_input_filter(paper_->input_custom_height,
124 fl_unsigned_float_filter);
125 fl_set_input_filter(paper_->input_top_margin,
126 fl_unsigned_float_filter);
127 fl_set_input_filter(paper_->input_bottom_margin,
128 fl_unsigned_float_filter);
129 fl_set_input_filter(paper_->input_left_margin,
130 fl_unsigned_float_filter);
131 fl_set_input_filter(paper_->input_right_margin,
132 fl_unsigned_float_filter);
133 fl_set_input_filter(paper_->input_head_height,
134 fl_unsigned_float_filter);
135 fl_set_input_filter(paper_->input_head_sep,
136 fl_unsigned_float_filter);
137 fl_set_input_filter(paper_->input_foot_skip,
138 fl_unsigned_float_filter);
140 // Create the contents of the unit choices
141 string const units = " cm | inch ";
143 fl_addto_choice(paper_->choice_custom_width_units, units.c_str());
144 fl_addto_choice(paper_->choice_custom_height_units, units.c_str());
145 fl_addto_choice(paper_->choice_top_margin_units, units.c_str());
146 fl_addto_choice(paper_->choice_bottom_margin_units, units.c_str());
147 fl_addto_choice(paper_->choice_left_margin_units, units.c_str());
148 fl_addto_choice(paper_->choice_right_margin_units, units.c_str());
149 fl_addto_choice(paper_->choice_head_height_units, units.c_str());
150 fl_addto_choice(paper_->choice_head_sep_units, units.c_str());
151 fl_addto_choice(paper_->choice_foot_skip_units, units.c_str());
153 bc().addReadOnly (paper_->choice_paperpackage);
154 bc().addReadOnly (paper_->group_radio_orientation);
155 bc().addReadOnly (paper_->radio_portrait);
156 bc().addReadOnly (paper_->radio_landscape);
157 bc().addReadOnly (paper_->choice_papersize);
158 bc().addReadOnly (paper_->check_use_geometry);
159 bc().addReadOnly (paper_->input_custom_width);
160 bc().addReadOnly (paper_->input_custom_height);
161 bc().addReadOnly (paper_->input_top_margin);
162 bc().addReadOnly (paper_->input_bottom_margin);
163 bc().addReadOnly (paper_->input_left_margin);
164 bc().addReadOnly (paper_->input_right_margin);
165 bc().addReadOnly (paper_->input_head_height);
166 bc().addReadOnly (paper_->input_head_sep);
167 bc().addReadOnly (paper_->input_foot_skip);
169 // the document class form
170 class_.reset(build_doc_class());
173 // The language is a combo-box and has to be inserted manually
174 obj = class_->choice_doc_class;
175 fl_deactivate_object(obj);
176 fl_addto_form(class_->form);
177 combo_doc_class.reset(new Combox(FL_COMBOX_DROPLIST));
178 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400,
179 dialog_->tabbed_folder);
180 combo_doc_class->shortcut("#C",1);
181 combo_doc_class->setcallback(ComboInputCB, this);
183 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
184 cit != textclasslist.end(); ++cit) {
185 combo_doc_class->addto(cit->description());
188 fl_addto_choice(class_->choice_doc_spacing,
189 _(" Single | OneHalf | Double | Other "));
190 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
191 for (n=0; tex_fonts[n][0]; ++n) {
192 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
194 fl_addto_choice(class_->choice_doc_pagestyle,
195 "default|empty|plain|headings|fancy");
196 fl_addto_choice(class_->choice_doc_skip,
197 _(" Smallskip | Medskip | Bigskip | Length "));
198 fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
199 fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
200 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
202 bc().addReadOnly (class_->radio_doc_indent);
203 bc().addReadOnly (class_->radio_doc_skip);
205 bc().addReadOnly (class_->choice_doc_pagestyle);
206 bc().addReadOnly (class_->choice_doc_fonts);
207 bc().addReadOnly (class_->choice_doc_fontsize);
208 bc().addReadOnly (class_->radio_doc_sides_one);
209 bc().addReadOnly (class_->radio_doc_sides_two);
210 bc().addReadOnly (class_->radio_doc_columns_one);
211 bc().addReadOnly (class_->radio_doc_columns_two);
212 bc().addReadOnly (class_->input_doc_extra);
213 bc().addReadOnly (class_->input_doc_skip);
214 bc().addReadOnly (class_->choice_doc_skip);
215 bc().addReadOnly (class_->choice_doc_spacing);
216 bc().addReadOnly (class_->input_doc_spacing);
218 // the document language form
219 language_.reset(build_doc_language());
220 fl_addto_choice(language_->choice_inputenc,
221 "default|auto|latin1|latin2|latin3|latin4|latin5|latin9"
222 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
224 // The language is a combo-box and has to be inserted manually
225 obj = language_->choice_language;
226 fl_deactivate_object(obj);
227 fl_addto_form(language_->form);
228 combo_language.reset(new Combox(FL_COMBOX_DROPLIST));
229 combo_language->add(obj->x, obj->y, obj->w, obj->h, 400,
230 dialog_->tabbed_folder);
231 combo_language->shortcut("#L",1);
232 combo_language->setcallback(ComboInputCB, this);
235 for (Languages::const_iterator cit = languages.begin();
236 cit != languages.end(); ++cit) {
237 combo_language->addto(cit->second.lang());
240 fl_addto_choice(language_->choice_quotes_language,
241 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
242 " «text» | »text« "));
244 bc().addReadOnly (language_->choice_inputenc);
245 bc().addReadOnly (language_->choice_quotes_language);
246 bc().addReadOnly (language_->radio_single);
247 bc().addReadOnly (language_->radio_double);
249 // the document options form
250 options_.reset(build_doc_options());
251 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
252 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
253 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
254 fl_set_counter_step(options_->slider_secnumdepth,1,1);
255 fl_set_counter_step(options_->slider_tocdepth,1,1);
256 fl_set_counter_precision(options_->slider_secnumdepth, 0);
257 fl_set_counter_precision(options_->slider_tocdepth, 0);
258 for (n=0; tex_graphics[n][0]; ++n) {
259 fl_addto_choice(options_->choice_postscript_driver,
262 fl_addto_choice(options_->choice_citation_format,
263 _(" Author-year | Numerical "));
265 bc_.addReadOnly (options_->slider_secnumdepth);
266 bc_.addReadOnly (options_->slider_tocdepth);
267 bc_.addReadOnly (options_->check_use_amsmath);
268 bc_.addReadOnly (options_->check_use_natbib);
269 bc_.addReadOnly (options_->choice_citation_format);
270 bc_.addReadOnly (options_->input_float_placement);
271 bc_.addReadOnly (options_->choice_postscript_driver);
273 // the document bullets form
274 bullets_.reset(build_doc_bullet());
275 fl_addto_choice(bullets_->choice_bullet_size,
276 _(" default | tiny | script | footnote | small |"
277 " normal | large | Large | LARGE | huge | Huge"));
278 fl_set_choice(bullets_->choice_bullet_size, 1);
279 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
280 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
282 bc().addReadOnly (bullets_->bmtable_bullet_panel);
283 bc().addReadOnly (bullets_->choice_bullet_size);
284 bc().addReadOnly (bullets_->input_bullet_latex);
285 bc().addReadOnly (bullets_->radio_bullet_depth);
286 bc().addReadOnly (bullets_->radio_bullet_panel);
288 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
290 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
292 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
294 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
296 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
298 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
299 lyxerr << _("Your version of libXpm is older than 4.7.\n"
300 "The `bullet' tab of the document dialog "
301 "has been disabled") << '\n';
302 fl_deactivate_object(fbullet);
303 fl_set_object_lcol(fbullet, FL_INACTIVE);
308 void FormDocument::apply()
310 if (!lv_->view()->available() || !dialog_.get())
313 bool redo = class_apply();
315 redo = language_apply() || redo;
316 redo = options_apply() || redo;
320 lv_->view()->redoCurrentBuffer();
322 lv_->buffer()->markDirty();
323 setMinibuffer(lv_, _("Document layout set"));
327 void FormDocument::cancel()
329 // this avoids confusion when reopening
330 BufferParams & param = lv_->buffer()->params;
331 param.temp_bullets[0] = param.user_defined_bullets[0];
332 param.temp_bullets[1] = param.user_defined_bullets[1];
333 param.temp_bullets[2] = param.user_defined_bullets[2];
334 param.temp_bullets[3] = param.user_defined_bullets[3];
339 void FormDocument::update()
346 BufferParams const & params = lv_->buffer()->params;
348 // fl_set_object_label(dialog_->button_save_defaults,
349 // _("Save as Defaults"));
350 // fl_set_object_label(dialog_->button_reset_defaults,
351 // _("Use Class Defaults"));
352 setEnabled(dialog_->button_reset_defaults,
353 !params.hasClassDefaults());
355 class_update(params);
356 paper_update(params);
357 language_update(params);
358 options_update(params);
359 bullets_update(params);
363 bool FormDocument::input( FL_OBJECT * ob, long data )
365 State cb = static_cast<State>( data );
368 case CHECKCHOICECLASS:
369 CheckChoiceClass(ob, 0);
371 case CHOICEBULLETSIZE:
372 ChoiceBulletSize(ob, 0);
374 case INPUTBULLETLATEX:
375 InputBulletLaTeX(ob, 0);
392 BulletBMTable(ob, 0);
398 if (ob == options_->check_use_natbib) {
399 setEnabled(options_->choice_citation_format,
400 fl_get_button(options_->check_use_natbib));
403 if (ob == dialog_->button_save_defaults) {
404 lv_->getLyXFunc()->dispatch(LFUN_LAYOUT_SAVE_DEFAULT);
407 if (ob == dialog_->button_reset_defaults) {
408 BufferParams params = lv_->buffer()->params;
409 params.textclass = combo_doc_class->get() - 1;
410 params.useClassDefaults();
411 UpdateLayoutDocument(params);
414 if (ob == paper_->radio_landscape)
415 fl_set_choice(paper_->choice_paperpackage,
416 BufferParams::PACKAGE_NONE + 1);
418 if (ob == paper_->choice_papersize) {
419 if (fl_get_choice(paper_->choice_papersize) == 2)
420 fl_set_button(paper_->radio_portrait, 1);
422 fl_get_choice(paper_->choice_papersize) == 2;
423 setEnabled(paper_->input_custom_width, custom);
424 setEnabled(paper_->input_custom_height, custom);
425 setEnabled(paper_->choice_custom_width_units, custom);
426 setEnabled(paper_->choice_custom_height_units, custom);
427 setEnabled(paper_->radio_portrait, !custom);
428 setEnabled(paper_->radio_landscape, !custom);
431 if (ob == paper_->choice_papersize
432 || paper_->radio_portrait
433 || paper_->radio_landscape) {
435 setEnabled(paper_->choice_paperpackage,
436 //either default papersize (preferences)
437 //or document papersize has to be A4
438 (fl_get_choice(paper_->choice_papersize) == 7
439 || fl_get_choice(paper_->choice_papersize) == 1
440 && lyxrc.default_papersize == 5)
441 && fl_get_button(paper_->radio_portrait));
444 if (ob == paper_->choice_paperpackage) {
445 if (fl_get_choice(paper_->choice_paperpackage) != 1) {
446 fl_set_button(paper_->check_use_geometry, 0);
448 setEnabled(paper_->input_top_margin, false);
449 setEnabled(paper_->input_bottom_margin, false);
450 setEnabled(paper_->input_left_margin, false);
451 setEnabled(paper_->input_right_margin, false);
452 setEnabled(paper_->input_head_height, false);
453 setEnabled(paper_->input_head_sep, false);
454 setEnabled(paper_->input_foot_skip, false);
455 setEnabled(paper_->choice_top_margin_units, false);
456 setEnabled(paper_->choice_bottom_margin_units, false);
457 setEnabled(paper_->choice_left_margin_units, false);
458 setEnabled(paper_->choice_right_margin_units, false);
459 setEnabled(paper_->choice_head_height_units, false);
460 setEnabled(paper_->choice_head_sep_units, false);
461 setEnabled(paper_->choice_foot_skip_units, false);
465 if (ob == paper_->check_use_geometry) {
466 //don't allow switching geometry off in custom papersize mode
467 if (fl_get_choice(paper_->choice_papersize) == 2)
468 fl_set_button(paper_->check_use_geometry, 1);
469 fl_set_choice(paper_->choice_paperpackage,
470 BufferParams::PACKAGE_NONE + 1);
472 bool const use_geom = fl_get_button(paper_->check_use_geometry);
473 setEnabled(paper_->input_top_margin, use_geom);
474 setEnabled(paper_->input_bottom_margin, use_geom);
475 setEnabled(paper_->input_left_margin, use_geom);
476 setEnabled(paper_->input_right_margin, use_geom);
477 setEnabled(paper_->input_head_height, use_geom);
478 setEnabled(paper_->input_head_sep, use_geom);
479 setEnabled(paper_->input_foot_skip, use_geom);
480 setEnabled(paper_->choice_top_margin_units, use_geom);
481 setEnabled(paper_->choice_bottom_margin_units, use_geom);
482 setEnabled(paper_->choice_left_margin_units, use_geom);
483 setEnabled(paper_->choice_right_margin_units, use_geom);
484 setEnabled(paper_->choice_head_height_units, use_geom);
485 setEnabled(paper_->choice_head_sep_units, use_geom);
486 setEnabled(paper_->choice_foot_skip_units, use_geom);
489 setEnabled(dialog_->button_reset_defaults,
490 lv_->buffer()->params.hasClassDefaults());
494 case CHECKCHOICECLASS:
495 case CHOICEBULLETSIZE:
496 case INPUTBULLETLATEX:
498 return CheckDocumentInput(ob, 0);
507 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
509 FormDocument * pre = static_cast<FormDocument*>(v);
510 if (combox == pre->combo_doc_class.get())
511 pre->CheckChoiceClass(0, 0);
512 pre->bc().valid(pre->CheckDocumentInput(0,0));
516 bool FormDocument::class_apply()
519 BufferParams ¶ms = lv_->buffer()->params;
521 // If default skip is a "Length" but there's no text in the
522 // input field, reset the kind to "Medskip", which is the default.
523 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
524 !*(fl_get_input (class_->input_doc_skip))) {
525 fl_set_choice (class_->choice_doc_skip, 2);
527 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
528 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
529 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
531 unsigned int const new_class = combo_doc_class->get() - 1;
533 if (params.textclass != new_class) {
534 // try to load new_class
535 if (textclasslist.Load(new_class)) {
536 // successfully loaded
538 setMinibuffer(lv_, _("Converting document to new document class..."));
539 int ret = CutAndPaste::SwitchLayoutsBetweenClasses(
540 params.textclass, new_class,
541 lv_->buffer()->paragraph);
545 s = _("One paragraph couldn't be converted");
548 s += _(" paragraphs couldn't be converted");
550 WriteAlert(_("Conversion Errors!"),s,
551 _("into chosen document class"));
554 params.textclass = new_class;
556 // problem changing class -- warn user and retain old style
557 WriteAlert(_("Conversion Errors!"),
558 _("Errors loading new document class."),
559 _("Reverting to original document class."));
560 combo_doc_class->select(int(params.textclass) + 1);
563 BufferParams::PARSEP tmpsep = params.paragraph_separation;
564 if (fl_get_button(class_->radio_doc_indent))
565 params.paragraph_separation = BufferParams::PARSEP_INDENT;
567 params.paragraph_separation = BufferParams::PARSEP_SKIP;
568 if (tmpsep != params.paragraph_separation)
571 VSpace tmpdefskip = params.getDefSkip();
572 switch (fl_get_choice (class_->choice_doc_skip)) {
574 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
577 params.setDefSkip(VSpace(VSpace::MEDSKIP));
580 params.setDefSkip(VSpace(VSpace::BIGSKIP));
584 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
586 // DocumentDefskipCB assures that this never happens
588 params.setDefSkip(VSpace(VSpace::MEDSKIP));
591 if (!(tmpdefskip == params.getDefSkip()))
594 if (fl_get_button(class_->radio_doc_columns_two))
598 if (fl_get_button(class_->radio_doc_sides_two))
599 params.sides = LyXTextClass::TwoSides;
601 params.sides = LyXTextClass::OneSide;
603 Spacing tmpSpacing = params.spacing;
604 switch (fl_get_choice(class_->choice_doc_spacing)) {
606 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
607 params.spacing.set(Spacing::Single);
610 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
611 params.spacing.set(Spacing::Onehalf);
614 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
615 params.spacing.set(Spacing::Double);
618 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
619 params.spacing.set(Spacing::Other,
620 fl_get_input(class_->input_doc_spacing));
623 if (tmpSpacing != params.spacing)
626 params.options = fl_get_input(class_->input_doc_extra);
632 void FormDocument::paper_apply()
634 BufferParams & params = lv_->buffer()->params;
636 params.papersize2 = char(fl_get_choice(paper_->choice_papersize)-1);
638 params.paperpackage =
639 char(fl_get_choice(paper_->choice_paperpackage)-1);
641 // set params.papersize from params.papersize2 and params.paperpackage
642 lv_->buffer()->setPaperStuff();
644 params.use_geometry = fl_get_button(paper_->check_use_geometry);
646 if (fl_get_button(paper_->radio_landscape))
647 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
649 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
652 getLengthFromWidgets(paper_->input_custom_width,
653 paper_->choice_custom_width_units);
656 getLengthFromWidgets(paper_->input_custom_height,
657 paper_->choice_custom_height_units);
660 getLengthFromWidgets(paper_->input_left_margin,
661 paper_->choice_left_margin_units);
664 getLengthFromWidgets(paper_->input_top_margin,
665 paper_->choice_top_margin_units);
668 getLengthFromWidgets(paper_->input_right_margin,
669 paper_->choice_right_margin_units);
671 params.bottommargin =
672 getLengthFromWidgets(paper_->input_bottom_margin,
673 paper_->choice_bottom_margin_units);
676 getLengthFromWidgets(paper_->input_head_height,
677 paper_->choice_head_height_units);
680 getLengthFromWidgets(paper_->input_head_sep,
681 paper_->choice_head_sep_units);
684 getLengthFromWidgets(paper_->input_foot_skip,
685 paper_->choice_foot_skip_units);
689 bool FormDocument::language_apply()
691 BufferParams & params = lv_->buffer()->params;
692 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
695 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
697 lga = InsetQuotes::EnglishQ;
700 lga = InsetQuotes::SwedishQ;
703 lga = InsetQuotes::GermanQ;
706 lga = InsetQuotes::PolishQ;
709 lga = InsetQuotes::FrenchQ;
712 lga = InsetQuotes::DanishQ;
715 params.quotes_language = lga;
716 if (fl_get_button(language_->radio_single))
717 params.quotes_times = InsetQuotes::SingleQ;
719 params.quotes_times = InsetQuotes::DoubleQ;
721 Language const * old_language = params.language;
722 Language const * new_language =
723 languages.getLanguage(combo_language->getline());
725 new_language = default_language;
727 if (old_language != new_language
728 && old_language->RightToLeft() == new_language->RightToLeft()
729 && !lv_->buffer()->isMultiLingual())
730 lv_->buffer()->changeLanguage(old_language, new_language);
731 if (old_language != new_language) {
734 params.language = new_language;
735 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
741 bool FormDocument::options_apply()
743 BufferParams & params = lv_->buffer()->params;
746 params.graphicsDriver =
747 fl_get_choice_text(options_->choice_postscript_driver);
748 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
749 params.use_natbib = fl_get_button(options_->check_use_natbib);
750 params.use_numerical_citations =
751 fl_get_choice(options_->choice_citation_format)-1;
753 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
754 if (params.secnumdepth != tmpchar)
756 params.secnumdepth = tmpchar;
758 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
760 params.float_placement =
761 fl_get_input(options_->input_float_placement);
767 void FormDocument::bullets_apply()
769 /* update the bullet settings */
770 BufferParams & param = lv_->buffer()->params;
772 // a little bit of loop unrolling
773 param.user_defined_bullets[0] = param.temp_bullets[0];
774 param.user_defined_bullets[1] = param.temp_bullets[1];
775 param.user_defined_bullets[2] = param.temp_bullets[2];
776 param.user_defined_bullets[3] = param.temp_bullets[3];
780 void FormDocument::class_update(BufferParams const & params)
785 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
787 combo_doc_class->select(
788 textclasslist.DescOfClass(params.textclass));
789 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
790 fl_clear_choice(class_->choice_doc_fontsize);
791 fl_addto_choice(class_->choice_doc_fontsize, "default");
792 fl_addto_choice(class_->choice_doc_fontsize,
793 tclass.opt_fontsize().c_str());
794 fl_set_choice(class_->choice_doc_fontsize,
795 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
796 fl_clear_choice(class_->choice_doc_pagestyle);
797 fl_addto_choice(class_->choice_doc_pagestyle, "default");
798 fl_addto_choice(class_->choice_doc_pagestyle,
799 tclass.opt_pagestyle().c_str());
800 fl_set_choice(class_->choice_doc_pagestyle,
801 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
802 fl_set_button(class_->radio_doc_indent, 0);
803 fl_set_button(class_->radio_doc_skip, 0);
804 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
805 fl_set_button(class_->radio_doc_indent, 1);
807 fl_set_button(class_->radio_doc_skip, 1);
808 switch (params.getDefSkip().kind()) {
809 case VSpace::SMALLSKIP:
810 fl_set_choice (class_->choice_doc_skip, 1);
812 case VSpace::MEDSKIP:
813 fl_set_choice (class_->choice_doc_skip, 2);
815 case VSpace::BIGSKIP:
816 fl_set_choice (class_->choice_doc_skip, 3);
819 fl_set_choice (class_->choice_doc_skip, 4);
820 fl_set_input (class_->input_doc_skip,
821 params.getDefSkip().asLyXCommand().c_str());
824 fl_set_choice (class_->choice_doc_skip, 2);
827 fl_set_button(class_->radio_doc_sides_one, 0);
828 fl_set_button(class_->radio_doc_sides_two, 0);
829 if (params.sides == LyXTextClass::TwoSides)
830 fl_set_button(class_->radio_doc_sides_two, 1);
832 fl_set_button(class_->radio_doc_sides_one, 1);
833 fl_set_button(class_->radio_doc_columns_one, 0);
834 fl_set_button(class_->radio_doc_columns_two, 0);
835 if (params.columns == 2)
836 fl_set_button(class_->radio_doc_columns_two, 1);
838 fl_set_button(class_->radio_doc_columns_one, 1);
839 fl_set_input(class_->input_doc_spacing, "");
840 switch (params.spacing.getSpace()) {
841 case Spacing::Default: // nothing bad should happen with this
842 case Spacing::Single:
844 fl_set_choice(class_->choice_doc_spacing, 1);
846 case Spacing::Onehalf:
848 fl_set_choice(class_->choice_doc_spacing, 2);
850 case Spacing::Double:
852 fl_set_choice(class_->choice_doc_spacing, 3);
856 fl_set_choice(class_->choice_doc_spacing, 4);
858 sprintf(sval,"%g",params.spacing.getValue());
859 fl_set_input(class_->input_doc_spacing, sval);
863 if (!params.options.empty())
864 fl_set_input(class_->input_doc_extra, params.options.c_str());
866 fl_set_input(class_->input_doc_extra, "");
870 void FormDocument::language_update(BufferParams const & params)
872 if (!language_.get())
875 combo_language->select(params.language->lang());
876 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
877 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
878 fl_set_button(language_->radio_single, 0);
879 fl_set_button(language_->radio_double, 0);
880 if (params.quotes_times == InsetQuotes::SingleQ)
881 fl_set_button(language_->radio_single, 1);
883 fl_set_button(language_->radio_double, 1);
887 void FormDocument::options_update(BufferParams const & params)
892 fl_set_choice_text(options_->choice_postscript_driver,
893 params.graphicsDriver.c_str());
894 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
895 fl_set_button(options_->check_use_natbib, params.use_natbib);
896 fl_set_choice(options_->choice_citation_format,
897 int(params.use_numerical_citations)+1);
898 setEnabled(options_->choice_citation_format, params.use_natbib);
899 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
900 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
901 if (!params.float_placement.empty())
902 fl_set_input(options_->input_float_placement,
903 params.float_placement.c_str());
905 fl_set_input(options_->input_float_placement, "");
909 void FormDocument::paper_update(BufferParams const & params)
914 fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
915 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
916 fl_set_button(paper_->check_use_geometry, params.use_geometry);
918 bool const useCustom = fl_get_choice(paper_->choice_papersize) == 2;
919 bool const useGeom = fl_get_button(paper_->check_use_geometry);
921 fl_set_button(paper_->radio_portrait, 0);
922 setEnabled(paper_->radio_portrait, !useCustom);
923 fl_set_button(paper_->radio_landscape, 0);
924 setEnabled(paper_->radio_landscape, !useCustom);
926 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
927 fl_set_button(paper_->radio_landscape, 1);
929 fl_set_button(paper_->radio_portrait, 1);
930 setEnabled(paper_->choice_paperpackage,
931 //either default papersize (preferences)
932 //or document papersize has to be A4
933 (fl_get_choice(paper_->choice_papersize) == 7
934 || fl_get_choice(paper_->choice_papersize) == 1
935 && lyxrc.default_papersize == 5)
936 && fl_get_button(paper_->radio_portrait));
938 updateWidgetsFromLengthString(paper_->input_custom_width,
939 paper_->choice_custom_width_units,
941 setEnabled(paper_->input_custom_width, useCustom);
942 setEnabled(paper_->choice_custom_width_units, useCustom);
944 updateWidgetsFromLengthString(paper_->input_custom_height,
945 paper_->choice_custom_height_units,
947 setEnabled(paper_->input_custom_height, useCustom);
948 setEnabled(paper_->choice_custom_height_units, useCustom);
950 updateWidgetsFromLengthString(paper_->input_left_margin,
951 paper_->choice_left_margin_units,
953 setEnabled(paper_->input_left_margin, useGeom);
954 setEnabled(paper_->choice_left_margin_units, useGeom);
956 updateWidgetsFromLengthString(paper_->input_top_margin,
957 paper_->choice_top_margin_units,
959 setEnabled(paper_->input_top_margin, useGeom);
960 setEnabled(paper_->choice_top_margin_units, useGeom);
962 updateWidgetsFromLengthString(paper_->input_right_margin,
963 paper_->choice_right_margin_units,
965 setEnabled(paper_->input_right_margin, useGeom);
966 setEnabled(paper_->choice_right_margin_units, useGeom);
968 updateWidgetsFromLengthString(paper_->input_bottom_margin,
969 paper_->choice_bottom_margin_units,
970 params.bottommargin);
971 setEnabled(paper_->input_bottom_margin, useGeom);
972 setEnabled(paper_->choice_bottom_margin_units, useGeom);
974 updateWidgetsFromLengthString(paper_->input_head_height,
975 paper_->choice_head_height_units,
977 setEnabled(paper_->input_head_height, useGeom);
978 setEnabled(paper_->choice_head_height_units, useGeom);
980 updateWidgetsFromLengthString(paper_->input_head_sep,
981 paper_->choice_head_sep_units,
983 setEnabled(paper_->input_head_sep, useGeom);
984 setEnabled(paper_->choice_head_sep_units, useGeom);
986 updateWidgetsFromLengthString(paper_->input_foot_skip,
987 paper_->choice_foot_skip_units,
989 setEnabled(paper_->input_foot_skip, useGeom);
990 setEnabled(paper_->choice_foot_skip_units, useGeom);
992 fl_set_focus_object(paper_->form, paper_->choice_papersize);
996 void FormDocument::bullets_update(BufferParams const & params)
998 if (!bullets_.get() ||
1000 (XpmVersion==4 && XpmRevision<7)))
1003 bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
1004 setEnabled(fbullet, !isLinuxDoc);
1006 if (isLinuxDoc) return;
1008 fl_set_button(bullets_->radio_bullet_depth_1, 1);
1009 fl_set_input(bullets_->input_bullet_latex,
1010 params.user_defined_bullets[0].getText().c_str());
1011 fl_set_choice(bullets_->choice_bullet_size,
1012 params.user_defined_bullets[0].getSize() + 2);
1016 void FormDocument::checkReadOnly()
1018 if (bc().readOnly(lv_->buffer()->isReadonly())) {
1019 combo_doc_class->deactivate();
1020 combo_language->deactivate();
1021 fl_set_object_label(dialog_->text_warning,
1022 _("Document is read-only."
1023 " No changes to layout permitted."));
1024 fl_show_object(dialog_->text_warning);
1026 combo_doc_class->activate();
1027 combo_language->activate();
1028 fl_hide_object(dialog_->text_warning);
1033 void FormDocument::checkMarginValues()
1035 //this is not needed after the recent redesign (JSpitzm)
1037 bool const not_empty =
1038 strlen(fl_get_input(paper_->input_top_margin)) ||
1039 strlen(fl_get_input(paper_->input_bottom_margin)) ||
1040 strlen(fl_get_input(paper_->input_left_margin)) ||
1041 strlen(fl_get_input(paper_->input_right_margin)) ||
1042 strlen(fl_get_input(paper_->input_head_height)) ||
1043 strlen(fl_get_input(paper_->input_head_sep)) ||
1044 strlen(fl_get_input(paper_->input_foot_skip)) ||
1045 strlen(fl_get_input(paper_->input_custom_width)) ||
1046 strlen(fl_get_input(paper_->input_custom_height));
1052 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
1058 // this is not needed after the recent redesign (Angus)
1061 checkMarginValues();
1062 if (ob == paper_->choice_papersize) {
1063 val = fl_get_choice(paper_->choice_papersize)-1;
1064 if (val == BufferParams::VM_PAPER_DEFAULT) {
1065 fl_set_button(paper_->check_use_geometry, 0);
1066 setEnabled(paper_->input_top_margin,
1067 fl_get_button(paper_->check_use_geometry));
1068 setEnabled(paper_->input_bottom_margin,
1069 fl_get_button(paper_->check_use_geometry));
1070 setEnabled(paper_->input_left_margin,
1071 fl_get_button(paper_->check_use_geometry));
1072 setEnabled(paper_->input_right_margin,
1073 fl_get_button(paper_->check_use_geometry));
1074 setEnabled(paper_->input_head_height,
1075 fl_get_button(paper_->check_use_geometry));
1076 setEnabled(paper_->input_head_sep,
1077 fl_get_button(paper_->check_use_geometry));
1078 setEnabled(paper_->input_foot_skip,
1079 fl_get_button(paper_->check_use_geometry));
1080 checkMarginValues();
1082 if ((val != BufferParams::VM_PAPER_USLETTER) &&
1083 (val != BufferParams::VM_PAPER_USLEGAL) &&
1084 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
1085 (val != BufferParams::VM_PAPER_A4) &&
1086 (val != BufferParams::VM_PAPER_A5) &&
1087 (val != BufferParams::VM_PAPER_B5)) {
1088 fl_set_button(paper_->check_use_geometry, 1);
1089 setEnabled(paper_->input_top_margin,
1090 fl_get_button(paper_->check_use_geometry));
1091 setEnabled(paper_->input_bottom_margin,
1092 fl_get_button(paper_->check_use_geometry));
1093 setEnabled(paper_->input_left_margin,
1094 fl_get_button(paper_->check_use_geometry));
1095 setEnabled(paper_->input_right_margin,
1096 fl_get_button(paper_->check_use_geometry));
1097 setEnabled(paper_->input_head_height,
1098 fl_get_button(paper_->check_use_geometry));
1099 setEnabled(paper_->input_head_sep,
1100 fl_get_button(paper_->check_use_geometry));
1101 setEnabled(paper_->input_foot_skip,
1102 fl_get_button(paper_->check_use_geometry));
1104 fl_set_choice(paper_->choice_paperpackage,
1105 BufferParams::PACKAGE_NONE + 1);
1107 } else if (ob == paper_->choice_paperpackage) {
1108 val = fl_get_choice(paper_->choice_paperpackage)-1;
1109 if (val != BufferParams::PACKAGE_NONE) {
1110 fl_set_button(paper_->check_use_geometry, 0);
1111 setEnabled(paper_->input_top_margin,
1112 fl_get_button(paper_->check_use_geometry));
1113 setEnabled(paper_->input_bottom_margin,
1114 fl_get_button(paper_->check_use_geometry));
1115 setEnabled(paper_->input_left_margin,
1116 fl_get_button(paper_->check_use_geometry));
1117 setEnabled(paper_->input_right_margin,
1118 fl_get_button(paper_->check_use_geometry));
1119 setEnabled(paper_->input_head_height,
1120 fl_get_button(paper_->check_use_geometry));
1121 setEnabled(paper_->input_head_sep,
1122 fl_get_button(paper_->check_use_geometry));
1123 setEnabled(paper_->input_foot_skip,
1124 fl_get_button(paper_->check_use_geometry));
1126 } else if (ob == class_->input_doc_spacing) {
1127 input = fl_get_input(class_->input_doc_spacing);
1129 fl_set_choice (class_->choice_doc_spacing, 1);
1131 fl_set_choice(class_->choice_doc_spacing, 4);
1134 // this has to be all out of if/elseif because it has to deactivate
1135 // the document buttons and so the whole stuff has to be tested again.
1136 str = fl_get_input(paper_->input_custom_width);
1137 ok = ok && (str.empty() || isValidLength(str));
1138 str = fl_get_input(paper_->input_custom_height);
1139 ok = ok && (str.empty() || isValidLength(str));
1140 str = fl_get_input(paper_->input_left_margin);
1141 ok = ok && (str.empty() || isValidLength(str));
1142 str = fl_get_input(paper_->input_right_margin);
1143 ok = ok && (str.empty() || isValidLength(str));
1144 str = fl_get_input(paper_->input_top_margin);
1145 ok = ok && (str.empty() || isValidLength(str));
1146 str = fl_get_input(paper_->input_bottom_margin);
1147 ok = ok && (str.empty() || isValidLength(str));
1148 str = fl_get_input(paper_->input_head_height);
1149 ok = ok && (str.empty() || isValidLength(str));
1150 str = fl_get_input(paper_->input_head_sep);
1151 ok = ok && (str.empty() || isValidLength(str));
1152 str = fl_get_input(paper_->input_foot_skip);
1153 ok = ok && (str.empty() || isValidLength(str));
1156 // "Synchronize" the choice and the input field, so that it
1157 // is impossible to commit senseless data.
1158 input = fl_get_input (class_->input_doc_skip);
1159 if (ob == class_->input_doc_skip) {
1161 fl_set_choice (class_->choice_doc_skip, 2);
1162 } else if (isValidGlueLength (input)) {
1163 fl_set_choice (class_->choice_doc_skip, 4);
1165 fl_set_choice(class_->choice_doc_skip, 4);
1169 if (*input && !isValidGlueLength(input))
1173 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
1175 else if (fl_get_choice(class_->choice_doc_skip) != 4)
1176 fl_set_input (class_->input_doc_skip, "");
1178 input = fl_get_input(class_->input_doc_spacing);
1179 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
1181 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
1182 fl_set_input (class_->input_doc_spacing, "");
1187 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
1189 BufferParams & param = lv_->buffer()->params;
1191 // convert from 1-6 range to -1-4
1192 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1193 fl_set_input(bullets_->input_bullet_latex,
1194 param.temp_bullets[current_bullet_depth].getText().c_str());
1198 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1200 BufferParams & param = lv_->buffer()->params;
1202 param.temp_bullets[current_bullet_depth].
1203 setText(fl_get_input(bullets_->input_bullet_latex));
1207 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
1209 /* Should I do the following: */
1210 /* 1. change to the panel that the current bullet belongs in */
1211 /* 2. show that bullet as selected */
1212 /* 3. change the size setting to the size of the bullet in Q.*/
1213 /* 4. display the latex equivalent in the latex box */
1215 /* I'm inclined to just go with 3 and 4 at the moment and */
1216 /* maybe try to support the others later */
1217 BufferParams & param = lv_->buffer()->params;
1220 if (cb == BULLETDEPTH1 )
1222 else if (cb == BULLETDEPTH2 )
1224 else if (cb == BULLETDEPTH3 )
1226 else if (cb == BULLETDEPTH4 )
1229 switch (fl_get_button_numb(ob)) {
1231 // right mouse button resets to default
1232 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1234 current_bullet_depth = data;
1235 fl_set_input(bullets_->input_bullet_latex,
1236 param.temp_bullets[data].getText().c_str());
1237 fl_set_choice(bullets_->choice_bullet_size,
1238 param.temp_bullets[data].getSize() + 2);
1243 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
1245 /* Here we have to change the background pixmap to that selected */
1246 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1249 if (cb == BULLETPANEL1 )
1251 else if (cb == BULLETPANEL2 )
1253 else if (cb == BULLETPANEL3 )
1255 else if (cb == BULLETPANEL4 )
1257 else if (cb == BULLETPANEL5 )
1259 else if (cb == BULLETPANEL6 )
1262 if (data != current_bullet_panel) {
1263 fl_freeze_form(bullets_->form);
1264 current_bullet_panel = data;
1266 /* free the current pixmap */
1267 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1270 /* display the new one */
1272 new_panel = "standard";
1275 new_panel = "amssymb";
1278 new_panel = "psnfss1";
1281 new_panel = "psnfss2";
1284 new_panel = "psnfss3";
1287 new_panel = "psnfss4";
1290 /* something very wrong happened */
1291 // play it safe for now but should be an exception
1292 current_bullet_panel = 0; // standard panel
1293 new_panel = "standard";
1296 new_panel += ".xpm";
1297 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1298 LibFileSearch("images", new_panel).c_str());
1299 fl_redraw_object(bullets_->bmtable_bullet_panel);
1300 fl_unfreeze_form(bullets_->form);
1305 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1307 /* handle the user input by setting the current bullet depth's pixmap */
1308 /* to that extracted from the current chosen position of the BMTable */
1309 /* Don't forget to free the button's old pixmap first. */
1311 BufferParams & param = lv_->buffer()->params;
1312 int bmtable_button = fl_get_bmtable(ob);
1314 /* try to keep the button held down till another is pushed */
1315 /* fl_set_bmtable(ob, 1, bmtable_button); */
1316 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1317 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1318 fl_set_input(bullets_->input_bullet_latex,
1319 param.temp_bullets[current_bullet_depth].getText().c_str());
1323 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1326 ob = class_->choice_doc_class;
1328 lv_->prohibitInput();
1330 unsigned int tc = combo_doc_class->get() - 1;
1331 if (textclasslist.Load(tc)) {
1332 // we use a copy of the bufferparams because we do not
1333 // want to modify them yet.
1334 BufferParams params = lv_->buffer()->params;
1336 if (lyxrc.auto_reset_options) {
1337 params.textclass = tc;
1338 params.useClassDefaults();
1339 UpdateLayoutDocument(params);
1342 // unable to load new style
1343 WriteAlert(_("Conversion Errors!"),
1344 _("Unable to switch to new document class."),
1345 _("Reverting to original document class."));
1346 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1352 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1358 class_update(params);
1359 paper_update(params);
1360 language_update(params);
1361 options_update(params);
1362 bullets_update(params);