3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS
14 #include "ControlDocument.h"
15 #include "FormDocument.h"
16 #include "forms/form_document.h"
18 #include "ButtonController.h"
21 #include "checkedwidgets.h"
22 #include "input_validators.h" // fl_unsigned_float_filter
23 #include "xforms_helpers.h"
25 #include "CutAndPaste.h"
29 #include "lyxtextclasslist.h"
30 #include "tex-strings.h"
32 #include "controllers/frnt_lang.h"
33 #include "controllers/helper_funcs.h"
35 #include "support/tostr.h"
36 #include "support/lstrings.h" // contains_functor, getStringFromVector
37 #include "support/filetools.h" // LibFileSearch
38 #include "support/BoostFormat.h"
41 #include "lyx_forms.h"
44 #include <boost/bind.hpp>
54 #if FL_VERSION == 0 || (FL_REVISION == 0 && FL_FIXLEVEL < 2)
55 bool const scalableTabfolders = false;
57 bool const scalableTabfolders = true;
63 typedef FormCB<ControlDocument, FormDB<FD_document> > base_class;
65 FormDocument::FormDocument()
66 : base_class(_("Document Settings"), scalableTabfolders),
67 ActCell(0), Confirmed(0),
68 current_bullet_panel(0), current_bullet_depth(0), fbullet(0)
72 void FormDocument::redraw()
74 if (form() && form()->visible)
75 fl_redraw_form(form());
79 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder);
80 if (outer_form && outer_form->visible)
81 fl_redraw_form(outer_form);
85 void FormDocument::build()
88 dialog_.reset(build_document(this));
90 // Allow the base class to control messages
91 setMessageWidget(dialog_->text_warning);
93 // Manage the restore, ok, apply, restore and cancel/close buttons
94 bcview().setOK(dialog_->button_ok);
95 bcview().setApply(dialog_->button_apply);
96 bcview().setCancel(dialog_->button_close);
97 bcview().setRestore(dialog_->button_restore);
99 // the document class form
100 class_.reset(build_document_class(this));
102 // disable for read-only documents
103 bcview().addReadOnly(class_->combox_class);
104 bcview().addReadOnly(class_->radio_indent);
105 bcview().addReadOnly(class_->radio_skip);
106 bcview().addReadOnly(class_->choice_pagestyle);
107 bcview().addReadOnly(class_->choice_fonts);
108 bcview().addReadOnly(class_->choice_fontsize);
109 bcview().addReadOnly(class_->radio_sides_one);
110 bcview().addReadOnly(class_->radio_sides_two);
111 bcview().addReadOnly(class_->radio_columns_one);
112 bcview().addReadOnly(class_->radio_columns_two);
113 bcview().addReadOnly(class_->input_extra);
114 bcview().addReadOnly(class_->input_skip);
115 bcview().addReadOnly(class_->choice_skip);
116 bcview().addReadOnly(class_->choice_spacing);
117 bcview().addReadOnly(class_->input_spacing);
119 // check validity of "length + unit" input
120 addCheckedGlueLength(bcview(), class_->input_skip,
121 class_->choice_skip);
123 // trigger an input event for cut&paste with middle mouse button.
124 setPrehandler(class_->input_extra);
125 setPrehandler(class_->input_skip);
126 setPrehandler(class_->input_spacing);
128 fl_set_input_return(class_->input_extra, FL_RETURN_CHANGED);
129 fl_set_input_return(class_->input_skip, FL_RETURN_CHANGED);
130 fl_set_input_return(class_->input_spacing, FL_RETURN_CHANGED);
134 // Fill the combox and choices.
135 obj = class_->combox_class;
136 LyXTextClassList::const_iterator tit = textclasslist.begin();
137 LyXTextClassList::const_iterator tend = textclasslist.end();
138 for (; tit != tend; ++tit) {
139 if (tit->isTeXClassAvailable()) {
140 fl_addto_combox(obj, tit->description().c_str());
144 STRCONV(boost::io::str(boost::format(_("Unavailable: %1$s"))
145 % tit->description()));
147 _("Unavailable: ") + tit->description();
149 fl_addto_combox(obj, item.c_str());
152 fl_set_combox_browser_height(obj, 400);
154 fl_addto_choice(class_->choice_spacing,
155 _(" Single | OneHalf | Double | Custom ").c_str());
156 fl_addto_choice(class_->choice_fontsize, "default|10|11|12");
157 for (int n = 0; tex_fonts[n][0]; ++n) {
158 fl_addto_choice(class_->choice_fonts,tex_fonts[n]);
161 // Create the contents of the unit choices; don't include the
163 vector<string> units_vec = getLatexUnits();
164 vector<string>::iterator ret =
165 std::remove_if(units_vec.begin(),
167 bind2nd(contains_functor(), "%"));
168 units_vec.erase(ret, units_vec.end());
170 string const units = getStringFromVector(units_vec, "|");
172 fl_addto_choice(class_->choice_pagestyle,
173 "default|empty|plain|headings|fancy");
174 fl_addto_choice(class_->choice_skip,
175 _(" SmallSkip | MedSkip | BigSkip | Length ").c_str());
176 fl_addto_choice(class_->choice_skip_units, units.c_str());
178 // Set input filters on doc spacing to make it accept only
180 fl_set_input_filter(class_->input_spacing,
181 fl_unsigned_float_filter);
183 // disable for read-only documents
184 bcview().addReadOnly(dialog_->button_save_defaults);
185 bcview().addReadOnly(dialog_->button_reset_defaults);
187 // the document paper form
188 paper_.reset(build_document_paper(this));
190 // disable for read-only documents
191 bcview().addReadOnly(paper_->choice_paperpackage);
192 bcview().addReadOnly(paper_->radio_portrait);
193 bcview().addReadOnly(paper_->radio_landscape);
194 bcview().addReadOnly(paper_->choice_papersize);
195 bcview().addReadOnly(paper_->check_use_geometry);
196 bcview().addReadOnly(paper_->input_custom_width);
197 bcview().addReadOnly(paper_->input_custom_height);
198 bcview().addReadOnly(paper_->input_top_margin);
199 bcview().addReadOnly(paper_->input_bottom_margin);
200 bcview().addReadOnly(paper_->input_inner_margin);
201 bcview().addReadOnly(paper_->input_outer_margin);
202 bcview().addReadOnly(paper_->input_head_height);
203 bcview().addReadOnly(paper_->input_head_sep);
204 bcview().addReadOnly(paper_->input_foot_skip);
206 // check validity of "length + unit" input
207 addCheckedGlueLength(bcview(), paper_->input_custom_width);
208 addCheckedGlueLength(bcview(), paper_->input_custom_height);
209 addCheckedGlueLength(bcview(), paper_->input_top_margin);
210 addCheckedGlueLength(bcview(), paper_->input_bottom_margin);
211 addCheckedGlueLength(bcview(), paper_->input_inner_margin);
212 addCheckedGlueLength(bcview(), paper_->input_outer_margin);
213 addCheckedGlueLength(bcview(), paper_->input_head_height);
214 addCheckedGlueLength(bcview(), paper_->input_head_sep);
215 addCheckedGlueLength(bcview(), paper_->input_foot_skip);
217 // trigger an input event for cut&paste with middle mouse button.
218 setPrehandler(paper_->input_custom_width);
219 setPrehandler(paper_->input_custom_height);
220 setPrehandler(paper_->input_top_margin);
221 setPrehandler(paper_->input_bottom_margin);
222 setPrehandler(paper_->input_inner_margin);
223 setPrehandler(paper_->input_outer_margin);
224 setPrehandler(paper_->input_head_height);
225 setPrehandler(paper_->input_head_sep);
226 setPrehandler(paper_->input_foot_skip);
228 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
229 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
230 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
231 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
232 fl_set_input_return(paper_->input_inner_margin, FL_RETURN_CHANGED);
233 fl_set_input_return(paper_->input_outer_margin, FL_RETURN_CHANGED);
234 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
235 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
236 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
238 fl_addto_choice(paper_->choice_papersize,
239 _(" Default | Custom | US letter | US legal "
240 "| US executive | A3 | A4 | A5 "
241 "| B3 | B4 | B5 ").c_str());
242 fl_addto_choice(paper_->choice_paperpackage,
245 "| Very small Margins "
246 "| Very wide Margins ").c_str());
248 fl_addto_choice(paper_->choice_custom_width_units, units.c_str());
249 fl_addto_choice(paper_->choice_custom_height_units, units.c_str());
250 fl_addto_choice(paper_->choice_top_margin_units, units.c_str());
251 fl_addto_choice(paper_->choice_bottom_margin_units, units.c_str());
252 fl_addto_choice(paper_->choice_inner_margin_units, units.c_str());
253 fl_addto_choice(paper_->choice_outer_margin_units, units.c_str());
254 fl_addto_choice(paper_->choice_head_height_units, units.c_str());
255 fl_addto_choice(paper_->choice_head_sep_units, units.c_str());
256 fl_addto_choice(paper_->choice_foot_skip_units, units.c_str());
258 // the document language form
259 language_.reset(build_document_language(this));
261 // disable for read-only documents
262 bcview().addReadOnly(language_->combox_language);
263 bcview().addReadOnly(language_->choice_inputenc);
264 bcview().addReadOnly(language_->choice_quotes_language);
265 bcview().addReadOnly(language_->radio_single);
266 bcview().addReadOnly(language_->radio_double);
268 fl_addto_choice(language_->choice_inputenc,
269 "default|auto|latin1|latin2|latin3|latin4|latin5|latin9"
270 "|koi8-r|koi8-u|cp866|cp1251|iso88595|pt154");
272 vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
273 // Store the identifiers for later
274 lang_ = getSecond(langs);
276 vector<frnt::LanguagePair>::const_iterator lit = langs.begin();
277 vector<frnt::LanguagePair>::const_iterator lend = langs.end();
278 for (; lit != lend; ++lit) {
279 fl_addto_combox(language_->combox_language,
282 fl_set_combox_browser_height(language_->combox_language, 400);
284 fl_addto_choice(language_->choice_quotes_language,
285 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
286 " «text» | »text« ").c_str());
288 // the document options form
289 options_.reset(build_document_options(this));
291 // disable for read-only documents
292 bcview().addReadOnly(options_->counter_secnumdepth);
293 bcview().addReadOnly(options_->counter_tocdepth);
294 bcview().addReadOnly(options_->choice_ams_math);
295 bcview().addReadOnly(options_->check_use_natbib);
296 bcview().addReadOnly(options_->choice_citation_format);
297 bcview().addReadOnly(options_->input_float_placement);
298 bcview().addReadOnly(options_->choice_postscript_driver);
300 // trigger an input event for cut&paste with middle mouse button.
301 setPrehandler(options_->input_float_placement);
303 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
305 fl_addto_choice(options_->choice_ams_math,
306 _("Never | Automatically | Yes ").c_str());
308 for (int n = 0; tex_graphics[n][0]; ++n) {
309 fl_addto_choice(options_->choice_postscript_driver,
312 fl_addto_choice(options_->choice_citation_format,
313 _(" Author-year | Numerical ").c_str());
315 // the document bullets form
316 bullets_.reset(build_document_bullet(this));
318 // disable for read-only documents
319 bcview().addReadOnly(bullets_->radio_depth_1);
320 bcview().addReadOnly(bullets_->radio_depth_2);
321 bcview().addReadOnly(bullets_->radio_depth_3);
322 bcview().addReadOnly(bullets_->radio_depth_4);
323 bcview().addReadOnly(bullets_->radio_panel_standard);
324 bcview().addReadOnly(bullets_->radio_panel_maths);
325 bcview().addReadOnly(bullets_->radio_panel_ding1);
326 bcview().addReadOnly(bullets_->radio_panel_ding2);
327 bcview().addReadOnly(bullets_->radio_panel_ding3);
328 bcview().addReadOnly(bullets_->radio_panel_ding4);
329 bcview().addReadOnly(bullets_->bmtable_panel);
330 bcview().addReadOnly(bullets_->choice_size);
331 bcview().addReadOnly(bullets_->input_latex);
333 // trigger an input event for cut&paste with middle mouse button.
334 setPrehandler(bullets_->input_latex);
336 fl_set_input_return(bullets_->input_latex, FL_RETURN_CHANGED);
338 fl_addto_choice(bullets_->choice_size,
339 _(" Default | Tiny | Smallest | Smaller "
340 "| Small | Normal | Large | Larger | Largest "
341 "| Huge | Huger ").c_str());
342 fl_set_choice(bullets_->choice_size, 1);
344 fl_set_input_maxchars(bullets_->input_latex, 80);
346 string const bmtablefile = LibFileSearch("images", "standard", "xpm");
347 fl_set_bmtable_pixmap_file(bullets_->bmtable_panel, 6, 6,
348 bmtablefile.c_str());
350 // Enable the tabfolder to be rescaled correctly.
351 if (scalableTabfolders)
352 fl_set_tabfolder_autofit(dialog_->tabfolder, FL_FIT);
355 fl_addto_tabfolder(dialog_->tabfolder,_("Document").c_str(),
357 fl_addto_tabfolder(dialog_->tabfolder,_("Paper").c_str(),
359 fl_addto_tabfolder(dialog_->tabfolder,_("Language").c_str(),
361 fl_addto_tabfolder(dialog_->tabfolder,_("Extra").c_str(),
363 fbullet = fl_addto_tabfolder(dialog_->tabfolder,_("Bullets").c_str(),
366 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
367 lyxerr << _("Your version of libXpm is older than 4.7.\n"
368 "The `bullet' tab of the document dialog "
369 "has been disabled") << '\n';
370 fl_deactivate_object(fbullet);
371 fl_set_object_lcol(fbullet, FL_INACTIVE);
376 void FormDocument::apply()
378 BufferParams & params = controller().params();
382 language_apply(params);
383 options_apply(params);
384 bullets_apply(params);
388 void FormDocument::update()
395 BufferParams const & params = controller().params();
397 class_update(params);
398 paper_update(params);
399 language_update(params);
400 options_update(params);
401 bullets_update(params);
405 ButtonPolicy::SMInput FormDocument::input(FL_OBJECT * ob, long)
407 if (ob == bullets_->choice_size) {
408 ChoiceBulletSize(ob, 0);
410 } else if (ob == bullets_->input_latex) {
411 InputBulletLaTeX(ob, 0);
413 } else if (ob == bullets_->radio_depth_1 ||
414 ob == bullets_->radio_depth_2 ||
415 ob == bullets_->radio_depth_3 ||
416 ob == bullets_->radio_depth_4) {
419 } else if (ob == bullets_->radio_panel_standard ||
420 ob == bullets_->radio_panel_maths ||
421 ob == bullets_->radio_panel_ding1 ||
422 ob == bullets_->radio_panel_ding2 ||
423 ob == bullets_->radio_panel_ding3 ||
424 ob == bullets_->radio_panel_ding4) {
427 } else if (ob == bullets_->bmtable_panel) {
428 BulletBMTable(ob, 0);
430 } else if (ob == class_->choice_spacing) {
431 setEnabled(class_->input_spacing,
432 fl_get_choice(class_->choice_spacing) == 4);
434 } else if (ob == class_->combox_class) {
436 } else if (ob == class_->radio_skip ||
437 ob == class_->radio_indent ||
438 ob == class_->choice_skip) {
439 bool const skip_used = fl_get_button(class_->radio_skip);
440 setEnabled(class_->choice_skip, skip_used);
442 bool const length_input =
443 fl_get_choice(class_->choice_skip) == 4;
444 setEnabled(class_->input_skip,
445 skip_used && length_input);
446 setEnabled(class_->choice_skip_units,
447 skip_used && length_input);
449 // Default unit choice is cm if metric, inches if US paper.
450 // If papersize is default, check the lyxrc-settings
451 int const paperchoice = fl_get_choice(paper_->choice_papersize);
452 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
453 || paperchoice == 2 || paperchoice > 5;
454 string const default_unit = metric ? "cm" : "in";
455 if (getString(class_->input_skip).empty())
456 fl_set_choice_text(class_->choice_skip_units,
457 default_unit.c_str());
459 } else if (ob == options_->check_use_natbib) {
460 setEnabled(options_->choice_citation_format,
461 fl_get_button(options_->check_use_natbib));
463 } else if (ob == dialog_->button_save_defaults) {
465 controller().saveAsDefault();
467 } else if (ob == dialog_->button_reset_defaults) {
468 BufferParams & params = controller().params();
469 params.textclass = fl_get_combox(class_->combox_class) - 1;
470 params.useClassDefaults();
471 UpdateLayoutDocument(params);
473 } else if (ob == paper_->radio_landscape) {
474 fl_set_choice(paper_->choice_paperpackage,
475 BufferParams::PACKAGE_NONE + 1);
477 } else if (ob == paper_->choice_papersize) {
478 int const paperchoice = fl_get_choice(paper_->choice_papersize);
479 bool const defsize = paperchoice == 1;
480 bool const custom = paperchoice == 2;
481 bool const a3size = paperchoice == 6;
482 bool const b3size = paperchoice == 9;
483 bool const b4size = paperchoice == 10;
486 fl_set_button(paper_->radio_portrait, 1);
488 bool const use_geom = (custom || a3size || b3size || b4size);
490 fl_set_button(paper_->check_use_geometry, int(use_geom));
492 setEnabled(paper_->input_top_margin, use_geom);
493 setEnabled(paper_->input_bottom_margin, use_geom);
494 setEnabled(paper_->input_inner_margin, use_geom);
495 setEnabled(paper_->input_outer_margin, use_geom);
496 setEnabled(paper_->input_head_height, use_geom);
497 setEnabled(paper_->input_head_sep, use_geom);
498 setEnabled(paper_->input_foot_skip, use_geom);
499 setEnabled(paper_->choice_top_margin_units, use_geom);
500 setEnabled(paper_->choice_bottom_margin_units, use_geom);
501 setEnabled(paper_->choice_inner_margin_units, use_geom);
502 setEnabled(paper_->choice_outer_margin_units, use_geom);
503 setEnabled(paper_->choice_head_height_units, use_geom);
504 setEnabled(paper_->choice_head_sep_units, use_geom);
505 setEnabled(paper_->choice_foot_skip_units, use_geom);
506 setEnabled(paper_->choice_custom_width_units, use_geom);
507 setEnabled(paper_->choice_custom_height_units, use_geom);
509 setEnabled(paper_->input_custom_width, custom);
510 setEnabled(paper_->input_custom_height, custom);
511 setEnabled(paper_->choice_custom_width_units, custom);
512 setEnabled(paper_->choice_custom_height_units, custom);
513 setEnabled(paper_->radio_portrait, !custom);
514 setEnabled(paper_->radio_landscape, !custom);
516 // Default unit choice is cm if metric, inches if US paper.
517 // If papersize is default, use the lyxrc-settings
518 bool const metric = (defsize && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
519 || paperchoice == 2 || paperchoice > 5;
520 string const default_unit = metric ? "cm" : "in";
521 if (getString(paper_->input_custom_width).empty())
522 fl_set_choice_text(paper_->choice_custom_width_units,
523 default_unit.c_str());
524 if (getString(paper_->input_custom_height).empty())
525 fl_set_choice_text(paper_->choice_custom_height_units,
526 default_unit.c_str());
527 if (getString(paper_->input_top_margin).empty())
528 fl_set_choice_text(paper_->choice_top_margin_units,
529 default_unit.c_str());
530 if (getString(paper_->input_bottom_margin).empty())
531 fl_set_choice_text(paper_->choice_bottom_margin_units,
532 default_unit.c_str());
533 if (getString(paper_->input_inner_margin).empty())
534 fl_set_choice_text(paper_->choice_inner_margin_units,
535 default_unit.c_str());
536 if (getString(paper_->input_outer_margin).empty())
537 fl_set_choice_text(paper_->choice_outer_margin_units,
538 default_unit.c_str());
539 if (getString(paper_->input_head_height).empty())
540 fl_set_choice_text(paper_->choice_head_height_units,
541 default_unit.c_str());
542 if (getString(paper_->input_head_sep).empty())
543 fl_set_choice_text(paper_->choice_head_sep_units,
544 default_unit.c_str());
545 if (getString(paper_->input_foot_skip).empty())
546 fl_set_choice_text(paper_->choice_foot_skip_units,
547 default_unit.c_str());
549 } else if (ob == paper_->choice_paperpackage &&
550 fl_get_choice(paper_->choice_paperpackage) != 1) {
552 fl_set_button(paper_->check_use_geometry, 0);
553 setEnabled(paper_->input_top_margin, false);
554 setEnabled(paper_->input_bottom_margin, false);
555 setEnabled(paper_->input_inner_margin, false);
556 setEnabled(paper_->input_outer_margin, false);
557 setEnabled(paper_->input_head_height, false);
558 setEnabled(paper_->input_head_sep, false);
559 setEnabled(paper_->input_foot_skip, false);
560 setEnabled(paper_->choice_top_margin_units, false);
561 setEnabled(paper_->choice_bottom_margin_units, false);
562 setEnabled(paper_->choice_inner_margin_units, false);
563 setEnabled(paper_->choice_outer_margin_units, false);
564 setEnabled(paper_->choice_head_height_units, false);
565 setEnabled(paper_->choice_head_sep_units, false);
566 setEnabled(paper_->choice_foot_skip_units, false);
568 } else if (ob == paper_->check_use_geometry) {
569 // don't allow switching geometry off in custom papersize
570 // mode nor in A3, B3, and B4
571 int const choice = fl_get_choice(paper_->choice_papersize);
572 if (choice == 2 || choice == 6 || choice == 9 || choice == 10)
573 fl_set_button(paper_->check_use_geometry, 1);
575 fl_set_choice(paper_->choice_paperpackage,
576 BufferParams::PACKAGE_NONE + 1);
578 bool const use_geom = fl_get_button(paper_->check_use_geometry);
579 setEnabled(paper_->input_top_margin, use_geom);
580 setEnabled(paper_->input_bottom_margin, use_geom);
581 setEnabled(paper_->input_inner_margin, use_geom);
582 setEnabled(paper_->input_outer_margin, use_geom);
583 setEnabled(paper_->input_head_height, use_geom);
584 setEnabled(paper_->input_head_sep, use_geom);
585 setEnabled(paper_->input_foot_skip, use_geom);
586 setEnabled(paper_->choice_top_margin_units, use_geom);
587 setEnabled(paper_->choice_bottom_margin_units, use_geom);
588 setEnabled(paper_->choice_inner_margin_units, use_geom);
589 setEnabled(paper_->choice_outer_margin_units, use_geom);
590 setEnabled(paper_->choice_head_height_units, use_geom);
591 setEnabled(paper_->choice_head_sep_units, use_geom);
592 setEnabled(paper_->choice_foot_skip_units, use_geom);
595 if (ob == paper_->choice_papersize || ob == paper_->radio_portrait
596 || ob == paper_->radio_landscape) {
597 // either default papersize (preferences) or document
598 // papersize has to be A4
599 bool const enable = ( fl_get_choice(paper_->choice_papersize) == 1
600 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER )
601 || fl_get_choice(paper_->choice_papersize) == 7;
603 fl_set_choice(paper_->choice_paperpackage,
604 BufferParams::PACKAGE_NONE + 1);
605 setEnabled(paper_->choice_paperpackage,
606 enable && fl_get_button(paper_->radio_portrait));
609 return ButtonPolicy::SMI_VALID;
613 bool FormDocument::class_apply(BufferParams ¶ms)
617 // If default skip is a "Length" but there's no text in the
618 // input field, reset the kind to "MedSkip", which is the default.
619 if (fl_get_choice(class_->choice_skip) == 4 &&
620 getString(class_->input_skip).empty()) {
621 fl_set_choice(class_->choice_skip, 2);
623 params.fonts = getString(class_->choice_fonts);
624 params.fontsize = getString(class_->choice_fontsize);
625 params.pagestyle = getString(class_->choice_pagestyle);
627 params.textclass = fl_get_combox(class_->combox_class) - 1;
629 BufferParams::PARSEP tmpsep = params.paragraph_separation;
630 if (fl_get_button(class_->radio_indent))
631 params.paragraph_separation = BufferParams::PARSEP_INDENT;
633 params.paragraph_separation = BufferParams::PARSEP_SKIP;
634 if (tmpsep != params.paragraph_separation)
637 VSpace tmpdefskip = params.getDefSkip();
638 switch (fl_get_choice(class_->choice_skip)) {
640 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
643 params.setDefSkip(VSpace(VSpace::MEDSKIP));
646 params.setDefSkip(VSpace(VSpace::BIGSKIP));
650 string const length =
651 getLengthFromWidgets(class_->input_skip,
652 class_->choice_skip_units);
654 params.setDefSkip(VSpace(LyXGlueLength(length)));
658 // DocumentDefskipCB assures that this never happens
659 params.setDefSkip(VSpace(VSpace::MEDSKIP));
662 if (!(tmpdefskip == params.getDefSkip()))
665 if (fl_get_button(class_->radio_columns_two))
669 if (fl_get_button(class_->radio_sides_two))
670 params.sides = LyXTextClass::TwoSides;
672 params.sides = LyXTextClass::OneSide;
674 Spacing tmpSpacing = params.spacing;
675 switch (fl_get_choice(class_->choice_spacing)) {
677 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
678 params.spacing.set(Spacing::Single);
681 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
682 params.spacing.set(Spacing::Onehalf);
685 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
686 params.spacing.set(Spacing::Double);
689 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
690 params.spacing.set(Spacing::Other,
691 getString(class_->input_spacing));
694 if (tmpSpacing != params.spacing)
697 params.options = getString(class_->input_extra);
703 void FormDocument::paper_apply(BufferParams & params)
705 params.papersize2 = BufferParams::VMARGIN_PAPER_TYPE(fl_get_choice(paper_->choice_papersize) - 1);
707 params.paperpackage =
708 BufferParams::PAPER_PACKAGES(fl_get_choice(paper_->choice_paperpackage) - 1);
710 // set params.papersize from params.papersize2 and params.paperpackage
711 params.setPaperStuff();
713 params.use_geometry = fl_get_button(paper_->check_use_geometry);
715 if (fl_get_button(paper_->radio_landscape))
716 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
718 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
721 getLengthFromWidgets(paper_->input_custom_width,
722 paper_->choice_custom_width_units);
725 getLengthFromWidgets(paper_->input_custom_height,
726 paper_->choice_custom_height_units);
729 getLengthFromWidgets(paper_->input_inner_margin,
730 paper_->choice_inner_margin_units);
733 getLengthFromWidgets(paper_->input_top_margin,
734 paper_->choice_top_margin_units);
737 getLengthFromWidgets(paper_->input_outer_margin,
738 paper_->choice_outer_margin_units);
740 params.bottommargin =
741 getLengthFromWidgets(paper_->input_bottom_margin,
742 paper_->choice_bottom_margin_units);
745 getLengthFromWidgets(paper_->input_head_height,
746 paper_->choice_head_height_units);
749 getLengthFromWidgets(paper_->input_head_sep,
750 paper_->choice_head_sep_units);
753 getLengthFromWidgets(paper_->input_foot_skip,
754 paper_->choice_foot_skip_units);
758 bool FormDocument::language_apply(BufferParams & params)
760 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
763 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
765 lga = InsetQuotes::EnglishQ;
768 lga = InsetQuotes::SwedishQ;
771 lga = InsetQuotes::GermanQ;
774 lga = InsetQuotes::PolishQ;
777 lga = InsetQuotes::FrenchQ;
780 lga = InsetQuotes::DanishQ;
783 params.quotes_language = lga;
784 if (fl_get_button(language_->radio_single))
785 params.quotes_times = InsetQuotes::SingleQ;
787 params.quotes_times = InsetQuotes::DoubleQ;
789 int const pos = fl_get_combox(language_->combox_language);
790 Language const * new_language = languages.getLanguage(lang_[pos-1]);
792 new_language = default_language;
794 params.language = new_language;
795 params.inputenc = getString(language_->choice_inputenc);
801 bool FormDocument::options_apply(BufferParams & params)
805 params.graphicsDriver = getString(options_->choice_postscript_driver);
806 params.use_amsmath = static_cast<BufferParams::AMS>(
807 fl_get_choice(options_->choice_ams_math) - 1);
808 params.use_natbib = fl_get_button(options_->check_use_natbib);
809 params.use_numerical_citations =
810 fl_get_choice(options_->choice_citation_format) - 1;
812 int tmpchar = int(fl_get_counter_value(options_->counter_secnumdepth));
813 if (params.secnumdepth != tmpchar)
815 params.secnumdepth = tmpchar;
817 params.tocdepth = int(fl_get_counter_value(options_->counter_tocdepth));
819 params.float_placement =
820 getString(options_->input_float_placement);
826 void FormDocument::bullets_apply(BufferParams & params)
828 /* update the bullet settings */
829 BufferParams & buf_params = controller().params();
831 for (int i = 0; i < 4; ++i) {
832 params.user_defined_bullets[i] = buf_params.temp_bullets[i];
837 void FormDocument::UpdateClassParams(BufferParams const & params)
839 // These are the params that have to be updated on any class change
840 // (even if the class defaults are not used) (JSpitzm 2002-04-08)
842 LyXTextClass const & tclass = textclasslist[params.textclass];
844 fl_set_combox(class_->combox_class, params.textclass + 1);
845 fl_clear_choice(class_->choice_fontsize);
846 fl_addto_choice(class_->choice_fontsize, "default");
847 fl_addto_choice(class_->choice_fontsize,
848 tclass.opt_fontsize().c_str());
849 fl_set_choice_text(class_->choice_fontsize,
850 params.fontsize.c_str());
851 fl_clear_choice(class_->choice_pagestyle);
852 fl_addto_choice(class_->choice_pagestyle, "default");
853 fl_addto_choice(class_->choice_pagestyle,
854 tclass.opt_pagestyle().c_str());
855 fl_set_choice_text(class_->choice_pagestyle,
856 params.pagestyle.c_str());
860 void FormDocument::class_update(BufferParams const & params)
865 UpdateClassParams(params);
867 fl_set_choice_text(class_->choice_fonts, params.fonts.c_str());
869 bool const indent = params.paragraph_separation == BufferParams::PARSEP_INDENT;
870 fl_set_button(class_->radio_indent, indent);
871 fl_set_button(class_->radio_skip, !indent);
875 pos = 2; // VSpace::MEDSKIP is default
877 switch (params.getDefSkip().kind()) {
881 case VSpace::BIGSKIP:
884 case VSpace::SMALLSKIP:
887 case VSpace::MEDSKIP:
893 fl_set_choice (class_->choice_skip, pos);
895 bool const length_input = pos == 4;
897 int const paperchoice = fl_get_choice(paper_->choice_papersize);
898 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
899 || paperchoice == 2 || paperchoice > 5;
900 string const default_unit = metric ? "cm" : "in";
901 string const length = params.getDefSkip().asLyXCommand();
902 updateWidgetsFromLengthString(class_->input_skip,
903 class_->choice_skip_units,
904 length, default_unit);
907 fl_set_input(class_->input_skip, "");
909 setEnabled(class_->choice_skip, !indent);
910 setEnabled(class_->input_skip, length_input);
911 setEnabled(class_->choice_skip_units, length_input);
913 bool const two_sides = params.sides == LyXTextClass::TwoSides;
914 fl_set_button(class_->radio_sides_one, !two_sides);
915 fl_set_button(class_->radio_sides_two, two_sides);
917 bool const two_columns = params.columns == 2;
918 fl_set_button(class_->radio_columns_one, !two_columns);
919 fl_set_button(class_->radio_columns_two, two_columns);
921 fl_set_input(class_->input_extra, params.options.c_str());
923 switch (params.spacing.getSpace()) {
927 case Spacing::Double: // \doublespacing
930 case Spacing::Onehalf: // \onehalfspacing
933 case Spacing::Single: // \singlespacing
934 case Spacing::Default: // nothing bad should happen with this
939 fl_set_choice(class_->choice_spacing, pos);
941 bool const spacing_input = pos == 4;
942 setEnabled(class_->input_spacing, spacing_input);
943 string const input = spacing_input ? tostr(params.spacing.getValue()) : string();
944 fl_set_input(class_->input_spacing, input.c_str());
948 void FormDocument::language_update(BufferParams const & params)
950 if (!language_.get())
953 int const pos = int(findPos(lang_, params.language->lang()));
954 fl_set_combox(language_->combox_language, pos+1);
956 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
957 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
958 fl_set_button(language_->radio_single, 0);
959 fl_set_button(language_->radio_double, 0);
960 if (params.quotes_times == InsetQuotes::SingleQ)
961 fl_set_button(language_->radio_single, 1);
963 fl_set_button(language_->radio_double, 1);
967 void FormDocument::options_update(BufferParams const & params)
972 fl_set_choice_text(options_->choice_postscript_driver,
973 params.graphicsDriver.c_str());
974 fl_set_choice(options_->choice_ams_math, params.use_amsmath + 1);
975 fl_set_button(options_->check_use_natbib, params.use_natbib);
976 fl_set_choice(options_->choice_citation_format,
977 int(params.use_numerical_citations)+1);
978 setEnabled(options_->choice_citation_format, params.use_natbib);
979 fl_set_counter_value(options_->counter_secnumdepth, params.secnumdepth);
980 fl_set_counter_value(options_->counter_tocdepth, params.tocdepth);
981 if (!params.float_placement.empty())
982 fl_set_input(options_->input_float_placement,
983 params.float_placement.c_str());
985 fl_set_input(options_->input_float_placement, "");
989 void FormDocument::paper_update(BufferParams const & params)
994 fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
995 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
996 fl_set_button(paper_->check_use_geometry, params.use_geometry);
998 int const paperchoice = fl_get_choice(paper_->choice_papersize);
999 bool const useCustom = paperchoice == 2;
1000 bool const useGeom = fl_get_button(paper_->check_use_geometry);
1002 fl_set_button(paper_->radio_portrait, 0);
1003 setEnabled(paper_->radio_portrait, !useCustom);
1004 fl_set_button(paper_->radio_landscape, 0);
1005 setEnabled(paper_->radio_landscape, !useCustom);
1007 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1008 fl_set_button(paper_->radio_landscape, 1);
1010 fl_set_button(paper_->radio_portrait, 1);
1011 setEnabled(paper_->choice_paperpackage,
1012 //either default papersize (preferences)
1013 //or document papersize has to be A4
1015 || paperchoice == 1 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER)
1016 && fl_get_button(paper_->radio_portrait));
1018 // Default unit choice is cm if metric, inches if US paper.
1019 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
1020 || paperchoice == 2 || paperchoice > 5;
1021 string const default_unit = metric ? "cm" : "in";
1022 updateWidgetsFromLengthString(paper_->input_custom_width,
1023 paper_->choice_custom_width_units,
1024 params.paperwidth, default_unit);
1025 setEnabled(paper_->input_custom_width, useCustom);
1026 setEnabled(paper_->choice_custom_width_units, useCustom);
1028 updateWidgetsFromLengthString(paper_->input_custom_height,
1029 paper_->choice_custom_height_units,
1030 params.paperheight, default_unit);
1031 setEnabled(paper_->input_custom_height, useCustom);
1032 setEnabled(paper_->choice_custom_height_units, useCustom);
1034 updateWidgetsFromLengthString(paper_->input_inner_margin,
1035 paper_->choice_inner_margin_units,
1036 params.leftmargin, default_unit);
1037 setEnabled(paper_->input_inner_margin, useGeom);
1038 setEnabled(paper_->choice_inner_margin_units, useGeom);
1040 updateWidgetsFromLengthString(paper_->input_top_margin,
1041 paper_->choice_top_margin_units,
1042 params.topmargin, default_unit);
1043 setEnabled(paper_->input_top_margin, useGeom);
1044 setEnabled(paper_->choice_top_margin_units, useGeom);
1046 updateWidgetsFromLengthString(paper_->input_outer_margin,
1047 paper_->choice_outer_margin_units,
1048 params.rightmargin, default_unit);
1049 setEnabled(paper_->input_outer_margin, useGeom);
1050 setEnabled(paper_->choice_outer_margin_units, useGeom);
1052 updateWidgetsFromLengthString(paper_->input_bottom_margin,
1053 paper_->choice_bottom_margin_units,
1054 params.bottommargin, default_unit);
1055 setEnabled(paper_->input_bottom_margin, useGeom);
1056 setEnabled(paper_->choice_bottom_margin_units, useGeom);
1058 updateWidgetsFromLengthString(paper_->input_head_height,
1059 paper_->choice_head_height_units,
1060 params.headheight, default_unit);
1061 setEnabled(paper_->input_head_height, useGeom);
1062 setEnabled(paper_->choice_head_height_units, useGeom);
1064 updateWidgetsFromLengthString(paper_->input_head_sep,
1065 paper_->choice_head_sep_units,
1066 params.headsep, default_unit);
1067 setEnabled(paper_->input_head_sep, useGeom);
1068 setEnabled(paper_->choice_head_sep_units, useGeom);
1070 updateWidgetsFromLengthString(paper_->input_foot_skip,
1071 paper_->choice_foot_skip_units,
1072 params.footskip, default_unit);
1073 setEnabled(paper_->input_foot_skip, useGeom);
1074 setEnabled(paper_->choice_foot_skip_units, useGeom);
1076 fl_set_focus_object(paper_->form, paper_->choice_papersize);
1080 void FormDocument::bullets_update(BufferParams const & params)
1082 if (!bullets_.get() ||
1084 (XpmVersion==4 && XpmRevision<7)))
1087 bool const isLinuxDoc =
1088 controller().docType() == ControlDocument::LINUXDOC;
1089 setEnabled(fbullet, !isLinuxDoc);
1091 if (isLinuxDoc) return;
1093 fl_set_button(bullets_->radio_depth_1, 1);
1094 fl_set_input(bullets_->input_latex,
1095 params.user_defined_bullets[0].getText().c_str());
1096 fl_set_choice(bullets_->choice_size,
1097 params.user_defined_bullets[0].getSize() + 2);
1101 void FormDocument::checkReadOnly()
1103 if (bc().readOnly(controller().bufferIsReadonly())) {
1104 postWarning(_("Document is read-only."
1105 " No changes to layout permitted."));
1112 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/)
1114 BufferParams & param = controller().params();
1116 // convert from 1-6 range to -1-4
1117 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1118 fl_set_input(bullets_->input_latex,
1119 param.temp_bullets[current_bullet_depth].getText().c_str());
1123 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1125 BufferParams & param = controller().params();
1127 param.temp_bullets[current_bullet_depth].
1128 setText(getString(bullets_->input_latex));
1132 void FormDocument::BulletDepth(FL_OBJECT * ob)
1134 /* Should I do the following: */
1135 /* 1. change to the panel that the current bullet belongs in */
1136 /* 2. show that bullet as selected */
1137 /* 3. change the size setting to the size of the bullet in Q.*/
1138 /* 4. display the latex equivalent in the latex box */
1140 /* I'm inclined to just go with 3 and 4 at the moment and */
1141 /* maybe try to support the others later */
1142 BufferParams & param = controller().params();
1145 if (ob == bullets_->radio_depth_1)
1147 else if (ob == bullets_->radio_depth_2)
1149 else if (ob == bullets_->radio_depth_3)
1151 else if (ob == bullets_->radio_depth_4)
1154 switch (fl_get_button_numb(ob)) {
1156 // right mouse button resets to default
1157 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1159 current_bullet_depth = data;
1160 fl_set_input(bullets_->input_latex,
1161 param.temp_bullets[data].getText().c_str());
1162 fl_set_choice(bullets_->choice_size,
1163 param.temp_bullets[data].getSize() + 2);
1168 void FormDocument::BulletPanel(FL_OBJECT * ob)
1170 /* Here we have to change the background pixmap to that selected */
1171 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1174 if (ob == bullets_->radio_panel_standard)
1176 else if (ob == bullets_->radio_panel_maths)
1178 else if (ob == bullets_->radio_panel_ding2)
1180 else if (ob == bullets_->radio_panel_ding3)
1182 else if (ob == bullets_->radio_panel_ding4)
1184 else if (ob == bullets_->radio_panel_ding1)
1187 if (data != current_bullet_panel) {
1188 fl_freeze_form(bullets_->form);
1189 current_bullet_panel = data;
1191 /* free the current pixmap */
1192 fl_free_bmtable_pixmap(bullets_->bmtable_panel);
1194 if (ob == bullets_->radio_panel_standard) {
1195 new_panel = "standard";
1196 } else if (ob == bullets_->radio_panel_maths ) {
1197 new_panel = "amssymb";
1198 } else if (ob == bullets_->radio_panel_ding2) {
1199 new_panel = "psnfss1";
1200 } else if (ob == bullets_->radio_panel_ding3) {
1201 new_panel = "psnfss2";
1202 } else if (ob == bullets_->radio_panel_ding4) {
1203 new_panel = "psnfss3";
1204 } else if (ob == bullets_->radio_panel_ding1) {
1205 new_panel = "psnfss4";
1207 /* something very wrong happened */
1208 // play it safe for now but should be an exception
1209 current_bullet_panel = 0; // standard panel
1210 new_panel = "standard";
1212 new_panel += ".xpm";
1213 fl_set_bmtable_pixmap_file(bullets_->bmtable_panel, 6, 6,
1214 LibFileSearch("images", new_panel).c_str());
1215 fl_redraw_object(bullets_->bmtable_panel);
1216 fl_unfreeze_form(bullets_->form);
1221 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/)
1223 /* handle the user input by setting the current bullet depth's pixmap */
1224 /* to that extracted from the current chosen position of the BMTable */
1225 /* Don't forget to free the button's old pixmap first. */
1227 BufferParams & param = controller().params();
1228 int bmtable_button = fl_get_bmtable(ob);
1230 /* try to keep the button held down till another is pushed */
1231 /* fl_set_bmtable(ob, 1, bmtable_button); */
1232 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1233 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1234 fl_set_input(bullets_->input_latex,
1235 param.temp_bullets[current_bullet_depth].getText().c_str());
1239 void FormDocument::CheckChoiceClass()
1241 BufferParams & params = controller().params();
1243 lyx::textclass_type const tc =
1244 fl_get_combox(class_->combox_class) - 1;
1246 if (controller().loadTextclass(tc)) {
1247 params.textclass = tc;
1249 if (lyxrc.auto_reset_options) {
1250 params.useClassDefaults();
1251 UpdateLayoutDocument(params);
1253 // update the params which are needed in any case
1254 // (fontsizes, pagestyle)
1255 UpdateClassParams(params);
1259 int const revert = int(params.textclass);
1260 fl_set_combox(class_->combox_class, revert + 1);
1265 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1271 class_update(params);
1272 paper_update(params);
1273 language_update(params);
1274 options_update(params);
1275 bullets_update(params);