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
40 #include "lyx_forms.h"
43 #include <boost/bind.hpp>
47 using namespace lyx::support;
55 #if FL_VERSION == 0 || (FL_REVISION == 0 && FL_FIXLEVEL < 2)
56 bool const scalableTabfolders = false;
58 bool const scalableTabfolders = true;
64 typedef FormCB<ControlDocument, FormDB<FD_document> > base_class;
66 FormDocument::FormDocument()
67 : base_class(_("Document Settings"), scalableTabfolders),
68 ActCell(0), Confirmed(0),
69 current_bullet_panel(0), current_bullet_depth(0), fbullet(0)
73 void FormDocument::redraw()
75 if (form() && form()->visible)
76 fl_redraw_form(form());
80 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder);
81 if (outer_form && outer_form->visible)
82 fl_redraw_form(outer_form);
86 void FormDocument::build()
89 dialog_.reset(build_document(this));
91 // Allow the base class to control messages
92 setMessageWidget(dialog_->text_warning);
94 // Manage the restore, ok, apply, restore and cancel/close buttons
95 bcview().setOK(dialog_->button_ok);
96 bcview().setApply(dialog_->button_apply);
97 bcview().setCancel(dialog_->button_close);
98 bcview().setRestore(dialog_->button_restore);
100 // the document class form
101 class_.reset(build_document_class(this));
103 // disable for read-only documents
104 bcview().addReadOnly(class_->combox_class);
105 bcview().addReadOnly(class_->radio_indent);
106 bcview().addReadOnly(class_->radio_skip);
107 bcview().addReadOnly(class_->choice_pagestyle);
108 bcview().addReadOnly(class_->choice_fonts);
109 bcview().addReadOnly(class_->choice_fontsize);
110 bcview().addReadOnly(class_->radio_sides_one);
111 bcview().addReadOnly(class_->radio_sides_two);
112 bcview().addReadOnly(class_->radio_columns_one);
113 bcview().addReadOnly(class_->radio_columns_two);
114 bcview().addReadOnly(class_->input_extra);
115 bcview().addReadOnly(class_->input_skip);
116 bcview().addReadOnly(class_->choice_skip);
117 bcview().addReadOnly(class_->choice_spacing);
118 bcview().addReadOnly(class_->input_spacing);
120 // check validity of "length + unit" input
121 addCheckedGlueLength(bcview(), class_->input_skip,
122 class_->choice_skip);
124 // trigger an input event for cut&paste with middle mouse button.
125 setPrehandler(class_->input_extra);
126 setPrehandler(class_->input_skip);
127 setPrehandler(class_->input_spacing);
129 fl_set_input_return(class_->input_extra, FL_RETURN_CHANGED);
130 fl_set_input_return(class_->input_skip, FL_RETURN_CHANGED);
131 fl_set_input_return(class_->input_spacing, FL_RETURN_CHANGED);
135 // Fill the combox and choices.
136 obj = class_->combox_class;
137 LyXTextClassList::const_iterator tit = textclasslist.begin();
138 LyXTextClassList::const_iterator tend = textclasslist.end();
139 for (; tit != tend; ++tit) {
140 if (tit->isTeXClassAvailable()) {
141 fl_addto_combox(obj, tit->description().c_str());
143 string item = bformat(_("Unavailable: %1$s"), tit->description());
144 fl_addto_combox(obj, item.c_str());
147 fl_set_combox_browser_height(obj, 400);
149 fl_addto_choice(class_->choice_spacing,
150 _(" Single | OneHalf | Double | Custom ").c_str());
151 fl_addto_choice(class_->choice_fontsize, "default|10|11|12");
152 for (int n = 0; tex_fonts[n][0]; ++n) {
153 fl_addto_choice(class_->choice_fonts,tex_fonts[n]);
156 // Create the contents of the unit choices; don't include the
158 vector<string> units_vec = getLatexUnits();
159 vector<string>::iterator ret =
160 std::remove_if(units_vec.begin(),
162 bind2nd(contains_functor(), "%"));
163 units_vec.erase(ret, units_vec.end());
165 string const units = getStringFromVector(units_vec, "|");
167 fl_addto_choice(class_->choice_pagestyle,
168 "default|empty|plain|headings|fancy");
169 fl_addto_choice(class_->choice_skip,
170 _(" SmallSkip | MedSkip | BigSkip | Length ").c_str());
171 fl_addto_choice(class_->choice_skip_units, units.c_str());
173 // Set input filters on doc spacing to make it accept only
175 fl_set_input_filter(class_->input_spacing,
176 fl_unsigned_float_filter);
178 // disable for read-only documents
179 bcview().addReadOnly(dialog_->button_save_defaults);
180 bcview().addReadOnly(dialog_->button_reset_defaults);
182 // the document paper form
183 paper_.reset(build_document_paper(this));
185 // disable for read-only documents
186 bcview().addReadOnly(paper_->choice_paperpackage);
187 bcview().addReadOnly(paper_->radio_portrait);
188 bcview().addReadOnly(paper_->radio_landscape);
189 bcview().addReadOnly(paper_->choice_papersize);
190 bcview().addReadOnly(paper_->check_use_geometry);
191 bcview().addReadOnly(paper_->input_custom_width);
192 bcview().addReadOnly(paper_->input_custom_height);
193 bcview().addReadOnly(paper_->input_top_margin);
194 bcview().addReadOnly(paper_->input_bottom_margin);
195 bcview().addReadOnly(paper_->input_inner_margin);
196 bcview().addReadOnly(paper_->input_outer_margin);
197 bcview().addReadOnly(paper_->input_head_height);
198 bcview().addReadOnly(paper_->input_head_sep);
199 bcview().addReadOnly(paper_->input_foot_skip);
201 // check validity of "length + unit" input
202 addCheckedGlueLength(bcview(), paper_->input_custom_width);
203 addCheckedGlueLength(bcview(), paper_->input_custom_height);
204 addCheckedGlueLength(bcview(), paper_->input_top_margin);
205 addCheckedGlueLength(bcview(), paper_->input_bottom_margin);
206 addCheckedGlueLength(bcview(), paper_->input_inner_margin);
207 addCheckedGlueLength(bcview(), paper_->input_outer_margin);
208 addCheckedGlueLength(bcview(), paper_->input_head_height);
209 addCheckedGlueLength(bcview(), paper_->input_head_sep);
210 addCheckedGlueLength(bcview(), paper_->input_foot_skip);
212 // trigger an input event for cut&paste with middle mouse button.
213 setPrehandler(paper_->input_custom_width);
214 setPrehandler(paper_->input_custom_height);
215 setPrehandler(paper_->input_top_margin);
216 setPrehandler(paper_->input_bottom_margin);
217 setPrehandler(paper_->input_inner_margin);
218 setPrehandler(paper_->input_outer_margin);
219 setPrehandler(paper_->input_head_height);
220 setPrehandler(paper_->input_head_sep);
221 setPrehandler(paper_->input_foot_skip);
223 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
224 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
225 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
226 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
227 fl_set_input_return(paper_->input_inner_margin, FL_RETURN_CHANGED);
228 fl_set_input_return(paper_->input_outer_margin, FL_RETURN_CHANGED);
229 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
230 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
231 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
233 fl_addto_choice(paper_->choice_papersize,
234 _(" Default | Custom | US letter | US legal "
235 "| US executive | A3 | A4 | A5 "
236 "| B3 | B4 | B5 ").c_str());
237 fl_addto_choice(paper_->choice_paperpackage,
240 "| Very small Margins "
241 "| Very wide Margins ").c_str());
243 fl_addto_choice(paper_->choice_custom_width_units, units.c_str());
244 fl_addto_choice(paper_->choice_custom_height_units, units.c_str());
245 fl_addto_choice(paper_->choice_top_margin_units, units.c_str());
246 fl_addto_choice(paper_->choice_bottom_margin_units, units.c_str());
247 fl_addto_choice(paper_->choice_inner_margin_units, units.c_str());
248 fl_addto_choice(paper_->choice_outer_margin_units, units.c_str());
249 fl_addto_choice(paper_->choice_head_height_units, units.c_str());
250 fl_addto_choice(paper_->choice_head_sep_units, units.c_str());
251 fl_addto_choice(paper_->choice_foot_skip_units, units.c_str());
253 // the document language form
254 language_.reset(build_document_language(this));
256 // disable for read-only documents
257 bcview().addReadOnly(language_->combox_language);
258 bcview().addReadOnly(language_->choice_inputenc);
259 bcview().addReadOnly(language_->choice_quotes_language);
260 bcview().addReadOnly(language_->radio_single);
261 bcview().addReadOnly(language_->radio_double);
263 fl_addto_choice(language_->choice_inputenc,
264 "default|auto|latin1|latin2|latin3|latin4|latin5|latin9"
265 "|koi8-r|koi8-u|cp866|cp1251|iso88595|pt154");
267 vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
268 // Store the identifiers for later
269 lang_ = getSecond(langs);
271 vector<frnt::LanguagePair>::const_iterator lit = langs.begin();
272 vector<frnt::LanguagePair>::const_iterator lend = langs.end();
273 for (; lit != lend; ++lit) {
274 fl_addto_combox(language_->combox_language,
277 fl_set_combox_browser_height(language_->combox_language, 400);
279 fl_addto_choice(language_->choice_quotes_language,
280 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
281 " «text» | »text« ").c_str());
283 // the document options form
284 options_.reset(build_document_options(this));
286 // disable for read-only documents
287 bcview().addReadOnly(options_->counter_secnumdepth);
288 bcview().addReadOnly(options_->counter_tocdepth);
289 bcview().addReadOnly(options_->choice_ams_math);
290 bcview().addReadOnly(options_->check_use_natbib);
291 bcview().addReadOnly(options_->choice_citation_format);
292 bcview().addReadOnly(options_->input_float_placement);
293 bcview().addReadOnly(options_->choice_postscript_driver);
295 // trigger an input event for cut&paste with middle mouse button.
296 setPrehandler(options_->input_float_placement);
298 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
300 fl_addto_choice(options_->choice_ams_math,
301 _("Never | Automatically | Yes ").c_str());
303 for (int n = 0; tex_graphics[n][0]; ++n) {
304 fl_addto_choice(options_->choice_postscript_driver,
307 fl_addto_choice(options_->choice_citation_format,
308 _(" Author-year | Numerical ").c_str());
310 // the document bullets form
311 bullets_.reset(build_document_bullet(this));
313 // disable for read-only documents
314 bcview().addReadOnly(bullets_->radio_depth_1);
315 bcview().addReadOnly(bullets_->radio_depth_2);
316 bcview().addReadOnly(bullets_->radio_depth_3);
317 bcview().addReadOnly(bullets_->radio_depth_4);
318 bcview().addReadOnly(bullets_->radio_panel_standard);
319 bcview().addReadOnly(bullets_->radio_panel_maths);
320 bcview().addReadOnly(bullets_->radio_panel_ding1);
321 bcview().addReadOnly(bullets_->radio_panel_ding2);
322 bcview().addReadOnly(bullets_->radio_panel_ding3);
323 bcview().addReadOnly(bullets_->radio_panel_ding4);
324 bcview().addReadOnly(bullets_->bmtable_panel);
325 bcview().addReadOnly(bullets_->choice_size);
326 bcview().addReadOnly(bullets_->input_latex);
328 // trigger an input event for cut&paste with middle mouse button.
329 setPrehandler(bullets_->input_latex);
331 fl_set_input_return(bullets_->input_latex, FL_RETURN_CHANGED);
333 fl_addto_choice(bullets_->choice_size,
334 _(" Default | Tiny | Smallest | Smaller "
335 "| Small | Normal | Large | Larger | Largest "
336 "| Huge | Huger ").c_str());
337 fl_set_choice(bullets_->choice_size, 1);
339 fl_set_input_maxchars(bullets_->input_latex, 80);
341 string const bmtablefile = LibFileSearch("images", "standard", "xpm");
342 fl_set_bmtable_pixmap_file(bullets_->bmtable_panel, 6, 6,
343 bmtablefile.c_str());
345 // Enable the tabfolder to be rescaled correctly.
346 if (scalableTabfolders)
347 fl_set_tabfolder_autofit(dialog_->tabfolder, FL_FIT);
350 fl_addto_tabfolder(dialog_->tabfolder,_("Document").c_str(),
352 fl_addto_tabfolder(dialog_->tabfolder,_("Paper").c_str(),
354 fl_addto_tabfolder(dialog_->tabfolder,_("Language").c_str(),
356 fl_addto_tabfolder(dialog_->tabfolder,_("Extra").c_str(),
358 fbullet = fl_addto_tabfolder(dialog_->tabfolder,_("Bullets").c_str(),
361 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
362 lyxerr << _("Your version of libXpm is older than 4.7.\n"
363 "The `bullet' tab of the document dialog "
364 "has been disabled") << '\n';
365 fl_deactivate_object(fbullet);
366 fl_set_object_lcol(fbullet, FL_INACTIVE);
371 void FormDocument::apply()
373 BufferParams & params = controller().params();
377 language_apply(params);
378 options_apply(params);
379 bullets_apply(params);
383 void FormDocument::update()
390 BufferParams const & params = controller().params();
392 class_update(params);
393 paper_update(params);
394 language_update(params);
395 options_update(params);
396 bullets_update(params);
400 ButtonPolicy::SMInput FormDocument::input(FL_OBJECT * ob, long)
402 if (ob == bullets_->choice_size) {
403 ChoiceBulletSize(ob, 0);
405 } else if (ob == bullets_->input_latex) {
406 InputBulletLaTeX(ob, 0);
408 } else if (ob == bullets_->radio_depth_1 ||
409 ob == bullets_->radio_depth_2 ||
410 ob == bullets_->radio_depth_3 ||
411 ob == bullets_->radio_depth_4) {
414 } else if (ob == bullets_->radio_panel_standard ||
415 ob == bullets_->radio_panel_maths ||
416 ob == bullets_->radio_panel_ding1 ||
417 ob == bullets_->radio_panel_ding2 ||
418 ob == bullets_->radio_panel_ding3 ||
419 ob == bullets_->radio_panel_ding4) {
422 } else if (ob == bullets_->bmtable_panel) {
423 BulletBMTable(ob, 0);
425 } else if (ob == class_->choice_spacing) {
426 setEnabled(class_->input_spacing,
427 fl_get_choice(class_->choice_spacing) == 4);
429 } else if (ob == class_->combox_class) {
431 } else if (ob == class_->radio_skip ||
432 ob == class_->radio_indent ||
433 ob == class_->choice_skip) {
434 bool const skip_used = fl_get_button(class_->radio_skip);
435 setEnabled(class_->choice_skip, skip_used);
437 bool const length_input =
438 fl_get_choice(class_->choice_skip) == 4;
439 setEnabled(class_->input_skip,
440 skip_used && length_input);
441 setEnabled(class_->choice_skip_units,
442 skip_used && length_input);
444 // Default unit choice is cm if metric, inches if US paper.
445 // If papersize is default, check the lyxrc-settings
446 int const paperchoice = fl_get_choice(paper_->choice_papersize);
447 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
448 || paperchoice == 2 || paperchoice > 5;
449 string const default_unit = metric ? "cm" : "in";
450 if (getString(class_->input_skip).empty())
451 fl_set_choice_text(class_->choice_skip_units,
452 default_unit.c_str());
454 } else if (ob == options_->check_use_natbib) {
455 setEnabled(options_->choice_citation_format,
456 fl_get_button(options_->check_use_natbib));
458 } else if (ob == dialog_->button_save_defaults) {
460 controller().saveAsDefault();
462 } else if (ob == dialog_->button_reset_defaults) {
463 BufferParams & params = controller().params();
464 params.textclass = fl_get_combox(class_->combox_class) - 1;
465 params.useClassDefaults();
466 UpdateLayoutDocument(params);
468 } else if (ob == paper_->radio_landscape) {
469 fl_set_choice(paper_->choice_paperpackage,
470 BufferParams::PACKAGE_NONE + 1);
472 } else if (ob == paper_->choice_papersize) {
473 int const paperchoice = fl_get_choice(paper_->choice_papersize);
474 bool const defsize = paperchoice == 1;
475 bool const custom = paperchoice == 2;
476 bool const a3size = paperchoice == 6;
477 bool const b3size = paperchoice == 9;
478 bool const b4size = paperchoice == 10;
481 fl_set_button(paper_->radio_portrait, 1);
483 bool const use_geom = (custom || a3size || b3size || b4size);
485 fl_set_button(paper_->check_use_geometry, int(use_geom));
487 setEnabled(paper_->input_top_margin, use_geom);
488 setEnabled(paper_->input_bottom_margin, use_geom);
489 setEnabled(paper_->input_inner_margin, use_geom);
490 setEnabled(paper_->input_outer_margin, use_geom);
491 setEnabled(paper_->input_head_height, use_geom);
492 setEnabled(paper_->input_head_sep, use_geom);
493 setEnabled(paper_->input_foot_skip, use_geom);
494 setEnabled(paper_->choice_top_margin_units, use_geom);
495 setEnabled(paper_->choice_bottom_margin_units, use_geom);
496 setEnabled(paper_->choice_inner_margin_units, use_geom);
497 setEnabled(paper_->choice_outer_margin_units, use_geom);
498 setEnabled(paper_->choice_head_height_units, use_geom);
499 setEnabled(paper_->choice_head_sep_units, use_geom);
500 setEnabled(paper_->choice_foot_skip_units, use_geom);
501 setEnabled(paper_->choice_custom_width_units, use_geom);
502 setEnabled(paper_->choice_custom_height_units, use_geom);
504 setEnabled(paper_->input_custom_width, custom);
505 setEnabled(paper_->input_custom_height, custom);
506 setEnabled(paper_->choice_custom_width_units, custom);
507 setEnabled(paper_->choice_custom_height_units, custom);
508 setEnabled(paper_->radio_portrait, !custom);
509 setEnabled(paper_->radio_landscape, !custom);
511 // Default unit choice is cm if metric, inches if US paper.
512 // If papersize is default, use the lyxrc-settings
513 bool const metric = (defsize && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
514 || paperchoice == 2 || paperchoice > 5;
515 string const default_unit = metric ? "cm" : "in";
516 if (getString(paper_->input_custom_width).empty())
517 fl_set_choice_text(paper_->choice_custom_width_units,
518 default_unit.c_str());
519 if (getString(paper_->input_custom_height).empty())
520 fl_set_choice_text(paper_->choice_custom_height_units,
521 default_unit.c_str());
522 if (getString(paper_->input_top_margin).empty())
523 fl_set_choice_text(paper_->choice_top_margin_units,
524 default_unit.c_str());
525 if (getString(paper_->input_bottom_margin).empty())
526 fl_set_choice_text(paper_->choice_bottom_margin_units,
527 default_unit.c_str());
528 if (getString(paper_->input_inner_margin).empty())
529 fl_set_choice_text(paper_->choice_inner_margin_units,
530 default_unit.c_str());
531 if (getString(paper_->input_outer_margin).empty())
532 fl_set_choice_text(paper_->choice_outer_margin_units,
533 default_unit.c_str());
534 if (getString(paper_->input_head_height).empty())
535 fl_set_choice_text(paper_->choice_head_height_units,
536 default_unit.c_str());
537 if (getString(paper_->input_head_sep).empty())
538 fl_set_choice_text(paper_->choice_head_sep_units,
539 default_unit.c_str());
540 if (getString(paper_->input_foot_skip).empty())
541 fl_set_choice_text(paper_->choice_foot_skip_units,
542 default_unit.c_str());
544 } else if (ob == paper_->choice_paperpackage &&
545 fl_get_choice(paper_->choice_paperpackage) != 1) {
547 fl_set_button(paper_->check_use_geometry, 0);
548 setEnabled(paper_->input_top_margin, false);
549 setEnabled(paper_->input_bottom_margin, false);
550 setEnabled(paper_->input_inner_margin, false);
551 setEnabled(paper_->input_outer_margin, false);
552 setEnabled(paper_->input_head_height, false);
553 setEnabled(paper_->input_head_sep, false);
554 setEnabled(paper_->input_foot_skip, false);
555 setEnabled(paper_->choice_top_margin_units, false);
556 setEnabled(paper_->choice_bottom_margin_units, false);
557 setEnabled(paper_->choice_inner_margin_units, false);
558 setEnabled(paper_->choice_outer_margin_units, false);
559 setEnabled(paper_->choice_head_height_units, false);
560 setEnabled(paper_->choice_head_sep_units, false);
561 setEnabled(paper_->choice_foot_skip_units, false);
563 } else if (ob == paper_->check_use_geometry) {
564 // don't allow switching geometry off in custom papersize
565 // mode nor in A3, B3, and B4
566 int const choice = fl_get_choice(paper_->choice_papersize);
567 if (choice == 2 || choice == 6 || choice == 9 || choice == 10)
568 fl_set_button(paper_->check_use_geometry, 1);
570 fl_set_choice(paper_->choice_paperpackage,
571 BufferParams::PACKAGE_NONE + 1);
573 bool const use_geom = fl_get_button(paper_->check_use_geometry);
574 setEnabled(paper_->input_top_margin, use_geom);
575 setEnabled(paper_->input_bottom_margin, use_geom);
576 setEnabled(paper_->input_inner_margin, use_geom);
577 setEnabled(paper_->input_outer_margin, use_geom);
578 setEnabled(paper_->input_head_height, use_geom);
579 setEnabled(paper_->input_head_sep, use_geom);
580 setEnabled(paper_->input_foot_skip, use_geom);
581 setEnabled(paper_->choice_top_margin_units, use_geom);
582 setEnabled(paper_->choice_bottom_margin_units, use_geom);
583 setEnabled(paper_->choice_inner_margin_units, use_geom);
584 setEnabled(paper_->choice_outer_margin_units, use_geom);
585 setEnabled(paper_->choice_head_height_units, use_geom);
586 setEnabled(paper_->choice_head_sep_units, use_geom);
587 setEnabled(paper_->choice_foot_skip_units, use_geom);
590 if (ob == paper_->choice_papersize || ob == paper_->radio_portrait
591 || ob == paper_->radio_landscape) {
592 // either default papersize (preferences) or document
593 // papersize has to be A4
594 bool const enable = ( fl_get_choice(paper_->choice_papersize) == 1
595 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER )
596 || fl_get_choice(paper_->choice_papersize) == 7;
598 fl_set_choice(paper_->choice_paperpackage,
599 BufferParams::PACKAGE_NONE + 1);
600 setEnabled(paper_->choice_paperpackage,
601 enable && fl_get_button(paper_->radio_portrait));
604 return ButtonPolicy::SMI_VALID;
608 bool FormDocument::class_apply(BufferParams ¶ms)
612 // If default skip is a "Length" but there's no text in the
613 // input field, reset the kind to "MedSkip", which is the default.
614 if (fl_get_choice(class_->choice_skip) == 4 &&
615 getString(class_->input_skip).empty()) {
616 fl_set_choice(class_->choice_skip, 2);
618 params.fonts = getString(class_->choice_fonts);
619 params.fontsize = getString(class_->choice_fontsize);
620 params.pagestyle = getString(class_->choice_pagestyle);
622 params.textclass = fl_get_combox(class_->combox_class) - 1;
624 BufferParams::PARSEP tmpsep = params.paragraph_separation;
625 if (fl_get_button(class_->radio_indent))
626 params.paragraph_separation = BufferParams::PARSEP_INDENT;
628 params.paragraph_separation = BufferParams::PARSEP_SKIP;
629 if (tmpsep != params.paragraph_separation)
632 VSpace tmpdefskip = params.getDefSkip();
633 switch (fl_get_choice(class_->choice_skip)) {
635 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
638 params.setDefSkip(VSpace(VSpace::MEDSKIP));
641 params.setDefSkip(VSpace(VSpace::BIGSKIP));
645 string const length =
646 getLengthFromWidgets(class_->input_skip,
647 class_->choice_skip_units);
649 params.setDefSkip(VSpace(LyXGlueLength(length)));
653 // DocumentDefskipCB assures that this never happens
654 params.setDefSkip(VSpace(VSpace::MEDSKIP));
657 if (!(tmpdefskip == params.getDefSkip()))
660 if (fl_get_button(class_->radio_columns_two))
664 if (fl_get_button(class_->radio_sides_two))
665 params.sides = LyXTextClass::TwoSides;
667 params.sides = LyXTextClass::OneSide;
669 Spacing tmpSpacing = params.spacing;
670 switch (fl_get_choice(class_->choice_spacing)) {
672 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
673 params.spacing.set(Spacing::Single);
676 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
677 params.spacing.set(Spacing::Onehalf);
680 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
681 params.spacing.set(Spacing::Double);
684 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
685 params.spacing.set(Spacing::Other,
686 getString(class_->input_spacing));
689 if (tmpSpacing != params.spacing)
692 params.options = getString(class_->input_extra);
698 void FormDocument::paper_apply(BufferParams & params)
700 params.papersize2 = BufferParams::VMARGIN_PAPER_TYPE(fl_get_choice(paper_->choice_papersize) - 1);
702 params.paperpackage =
703 BufferParams::PAPER_PACKAGES(fl_get_choice(paper_->choice_paperpackage) - 1);
705 // set params.papersize from params.papersize2 and params.paperpackage
706 params.setPaperStuff();
708 params.use_geometry = fl_get_button(paper_->check_use_geometry);
710 if (fl_get_button(paper_->radio_landscape))
711 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
713 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
716 getLengthFromWidgets(paper_->input_custom_width,
717 paper_->choice_custom_width_units);
720 getLengthFromWidgets(paper_->input_custom_height,
721 paper_->choice_custom_height_units);
724 getLengthFromWidgets(paper_->input_inner_margin,
725 paper_->choice_inner_margin_units);
728 getLengthFromWidgets(paper_->input_top_margin,
729 paper_->choice_top_margin_units);
732 getLengthFromWidgets(paper_->input_outer_margin,
733 paper_->choice_outer_margin_units);
735 params.bottommargin =
736 getLengthFromWidgets(paper_->input_bottom_margin,
737 paper_->choice_bottom_margin_units);
740 getLengthFromWidgets(paper_->input_head_height,
741 paper_->choice_head_height_units);
744 getLengthFromWidgets(paper_->input_head_sep,
745 paper_->choice_head_sep_units);
748 getLengthFromWidgets(paper_->input_foot_skip,
749 paper_->choice_foot_skip_units);
753 bool FormDocument::language_apply(BufferParams & params)
755 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
758 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
760 lga = InsetQuotes::EnglishQ;
763 lga = InsetQuotes::SwedishQ;
766 lga = InsetQuotes::GermanQ;
769 lga = InsetQuotes::PolishQ;
772 lga = InsetQuotes::FrenchQ;
775 lga = InsetQuotes::DanishQ;
778 params.quotes_language = lga;
779 if (fl_get_button(language_->radio_single))
780 params.quotes_times = InsetQuotes::SingleQ;
782 params.quotes_times = InsetQuotes::DoubleQ;
784 int const pos = fl_get_combox(language_->combox_language);
785 Language const * new_language = languages.getLanguage(lang_[pos-1]);
787 new_language = default_language;
789 params.language = new_language;
790 params.inputenc = getString(language_->choice_inputenc);
796 bool FormDocument::options_apply(BufferParams & params)
800 params.graphicsDriver = getString(options_->choice_postscript_driver);
801 params.use_amsmath = static_cast<BufferParams::AMS>(
802 fl_get_choice(options_->choice_ams_math) - 1);
803 params.use_natbib = fl_get_button(options_->check_use_natbib);
804 params.use_numerical_citations =
805 fl_get_choice(options_->choice_citation_format) - 1;
807 int tmpchar = int(fl_get_counter_value(options_->counter_secnumdepth));
808 if (params.secnumdepth != tmpchar)
810 params.secnumdepth = tmpchar;
812 params.tocdepth = int(fl_get_counter_value(options_->counter_tocdepth));
814 params.float_placement =
815 getString(options_->input_float_placement);
821 void FormDocument::bullets_apply(BufferParams & params)
823 /* update the bullet settings */
824 BufferParams & buf_params = controller().params();
826 for (int i = 0; i < 4; ++i) {
827 params.user_defined_bullets[i] = buf_params.temp_bullets[i];
832 void FormDocument::UpdateClassParams(BufferParams const & params)
834 // These are the params that have to be updated on any class change
835 // (even if the class defaults are not used) (JSpitzm 2002-04-08)
837 LyXTextClass const & tclass = textclasslist[params.textclass];
839 fl_set_combox(class_->combox_class, params.textclass + 1);
840 fl_clear_choice(class_->choice_fontsize);
841 fl_addto_choice(class_->choice_fontsize, "default");
842 fl_addto_choice(class_->choice_fontsize,
843 tclass.opt_fontsize().c_str());
844 fl_set_choice_text(class_->choice_fontsize,
845 params.fontsize.c_str());
846 fl_clear_choice(class_->choice_pagestyle);
847 fl_addto_choice(class_->choice_pagestyle, "default");
848 fl_addto_choice(class_->choice_pagestyle,
849 tclass.opt_pagestyle().c_str());
850 fl_set_choice_text(class_->choice_pagestyle,
851 params.pagestyle.c_str());
855 void FormDocument::class_update(BufferParams const & params)
860 UpdateClassParams(params);
862 fl_set_choice_text(class_->choice_fonts, params.fonts.c_str());
864 bool const indent = params.paragraph_separation == BufferParams::PARSEP_INDENT;
865 fl_set_button(class_->radio_indent, indent);
866 fl_set_button(class_->radio_skip, !indent);
870 pos = 2; // VSpace::MEDSKIP is default
872 switch (params.getDefSkip().kind()) {
876 case VSpace::BIGSKIP:
879 case VSpace::SMALLSKIP:
882 case VSpace::MEDSKIP:
888 fl_set_choice (class_->choice_skip, pos);
890 bool const length_input = pos == 4;
892 int const paperchoice = fl_get_choice(paper_->choice_papersize);
893 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
894 || paperchoice == 2 || paperchoice > 5;
895 string const default_unit = metric ? "cm" : "in";
896 string const length = params.getDefSkip().asLyXCommand();
897 updateWidgetsFromLengthString(class_->input_skip,
898 class_->choice_skip_units,
899 length, default_unit);
902 fl_set_input(class_->input_skip, "");
904 setEnabled(class_->choice_skip, !indent);
905 setEnabled(class_->input_skip, length_input);
906 setEnabled(class_->choice_skip_units, length_input);
908 bool const two_sides = params.sides == LyXTextClass::TwoSides;
909 fl_set_button(class_->radio_sides_one, !two_sides);
910 fl_set_button(class_->radio_sides_two, two_sides);
912 bool const two_columns = params.columns == 2;
913 fl_set_button(class_->radio_columns_one, !two_columns);
914 fl_set_button(class_->radio_columns_two, two_columns);
916 fl_set_input(class_->input_extra, params.options.c_str());
918 switch (params.spacing.getSpace()) {
922 case Spacing::Double: // \doublespacing
925 case Spacing::Onehalf: // \onehalfspacing
928 case Spacing::Single: // \singlespacing
929 case Spacing::Default: // nothing bad should happen with this
934 fl_set_choice(class_->choice_spacing, pos);
936 bool const spacing_input = pos == 4;
937 setEnabled(class_->input_spacing, spacing_input);
938 string const input = spacing_input ? tostr(params.spacing.getValue()) : string();
939 fl_set_input(class_->input_spacing, input.c_str());
943 void FormDocument::language_update(BufferParams const & params)
945 if (!language_.get())
948 int const pos = int(findPos(lang_, params.language->lang()));
949 fl_set_combox(language_->combox_language, pos+1);
951 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
952 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
953 fl_set_button(language_->radio_single, 0);
954 fl_set_button(language_->radio_double, 0);
955 if (params.quotes_times == InsetQuotes::SingleQ)
956 fl_set_button(language_->radio_single, 1);
958 fl_set_button(language_->radio_double, 1);
962 void FormDocument::options_update(BufferParams const & params)
967 fl_set_choice_text(options_->choice_postscript_driver,
968 params.graphicsDriver.c_str());
969 fl_set_choice(options_->choice_ams_math, params.use_amsmath + 1);
970 fl_set_button(options_->check_use_natbib, params.use_natbib);
971 fl_set_choice(options_->choice_citation_format,
972 int(params.use_numerical_citations)+1);
973 setEnabled(options_->choice_citation_format, params.use_natbib);
974 fl_set_counter_value(options_->counter_secnumdepth, params.secnumdepth);
975 fl_set_counter_value(options_->counter_tocdepth, params.tocdepth);
976 if (!params.float_placement.empty())
977 fl_set_input(options_->input_float_placement,
978 params.float_placement.c_str());
980 fl_set_input(options_->input_float_placement, "");
984 void FormDocument::paper_update(BufferParams const & params)
989 fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
990 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
991 fl_set_button(paper_->check_use_geometry, params.use_geometry);
993 int const paperchoice = fl_get_choice(paper_->choice_papersize);
994 bool const useCustom = paperchoice == 2;
995 bool const useGeom = fl_get_button(paper_->check_use_geometry);
997 fl_set_button(paper_->radio_portrait, 0);
998 setEnabled(paper_->radio_portrait, !useCustom);
999 fl_set_button(paper_->radio_landscape, 0);
1000 setEnabled(paper_->radio_landscape, !useCustom);
1002 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1003 fl_set_button(paper_->radio_landscape, 1);
1005 fl_set_button(paper_->radio_portrait, 1);
1006 setEnabled(paper_->choice_paperpackage,
1007 //either default papersize (preferences)
1008 //or document papersize has to be A4
1010 || paperchoice == 1 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER)
1011 && fl_get_button(paper_->radio_portrait));
1013 // Default unit choice is cm if metric, inches if US paper.
1014 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
1015 || paperchoice == 2 || paperchoice > 5;
1016 string const default_unit = metric ? "cm" : "in";
1017 updateWidgetsFromLengthString(paper_->input_custom_width,
1018 paper_->choice_custom_width_units,
1019 params.paperwidth, default_unit);
1020 setEnabled(paper_->input_custom_width, useCustom);
1021 setEnabled(paper_->choice_custom_width_units, useCustom);
1023 updateWidgetsFromLengthString(paper_->input_custom_height,
1024 paper_->choice_custom_height_units,
1025 params.paperheight, default_unit);
1026 setEnabled(paper_->input_custom_height, useCustom);
1027 setEnabled(paper_->choice_custom_height_units, useCustom);
1029 updateWidgetsFromLengthString(paper_->input_inner_margin,
1030 paper_->choice_inner_margin_units,
1031 params.leftmargin, default_unit);
1032 setEnabled(paper_->input_inner_margin, useGeom);
1033 setEnabled(paper_->choice_inner_margin_units, useGeom);
1035 updateWidgetsFromLengthString(paper_->input_top_margin,
1036 paper_->choice_top_margin_units,
1037 params.topmargin, default_unit);
1038 setEnabled(paper_->input_top_margin, useGeom);
1039 setEnabled(paper_->choice_top_margin_units, useGeom);
1041 updateWidgetsFromLengthString(paper_->input_outer_margin,
1042 paper_->choice_outer_margin_units,
1043 params.rightmargin, default_unit);
1044 setEnabled(paper_->input_outer_margin, useGeom);
1045 setEnabled(paper_->choice_outer_margin_units, useGeom);
1047 updateWidgetsFromLengthString(paper_->input_bottom_margin,
1048 paper_->choice_bottom_margin_units,
1049 params.bottommargin, default_unit);
1050 setEnabled(paper_->input_bottom_margin, useGeom);
1051 setEnabled(paper_->choice_bottom_margin_units, useGeom);
1053 updateWidgetsFromLengthString(paper_->input_head_height,
1054 paper_->choice_head_height_units,
1055 params.headheight, default_unit);
1056 setEnabled(paper_->input_head_height, useGeom);
1057 setEnabled(paper_->choice_head_height_units, useGeom);
1059 updateWidgetsFromLengthString(paper_->input_head_sep,
1060 paper_->choice_head_sep_units,
1061 params.headsep, default_unit);
1062 setEnabled(paper_->input_head_sep, useGeom);
1063 setEnabled(paper_->choice_head_sep_units, useGeom);
1065 updateWidgetsFromLengthString(paper_->input_foot_skip,
1066 paper_->choice_foot_skip_units,
1067 params.footskip, default_unit);
1068 setEnabled(paper_->input_foot_skip, useGeom);
1069 setEnabled(paper_->choice_foot_skip_units, useGeom);
1071 fl_set_focus_object(paper_->form, paper_->choice_papersize);
1075 void FormDocument::bullets_update(BufferParams const & params)
1077 if (!bullets_.get() ||
1079 (XpmVersion==4 && XpmRevision<7)))
1082 bool const isLinuxDoc =
1083 controller().docType() == ControlDocument::LINUXDOC;
1084 setEnabled(fbullet, !isLinuxDoc);
1086 if (isLinuxDoc) return;
1088 fl_set_button(bullets_->radio_depth_1, 1);
1089 fl_set_input(bullets_->input_latex,
1090 params.user_defined_bullets[0].getText().c_str());
1091 fl_set_choice(bullets_->choice_size,
1092 params.user_defined_bullets[0].getSize() + 2);
1096 void FormDocument::checkReadOnly()
1098 if (bc().readOnly(controller().bufferIsReadonly())) {
1099 postWarning(_("Document is read-only."
1100 " No changes to layout permitted."));
1107 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/)
1109 BufferParams & param = controller().params();
1111 // convert from 1-6 range to -1-4
1112 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1113 fl_set_input(bullets_->input_latex,
1114 param.temp_bullets[current_bullet_depth].getText().c_str());
1118 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1120 BufferParams & param = controller().params();
1122 param.temp_bullets[current_bullet_depth].
1123 setText(getString(bullets_->input_latex));
1127 void FormDocument::BulletDepth(FL_OBJECT * ob)
1129 /* Should I do the following: */
1130 /* 1. change to the panel that the current bullet belongs in */
1131 /* 2. show that bullet as selected */
1132 /* 3. change the size setting to the size of the bullet in Q.*/
1133 /* 4. display the latex equivalent in the latex box */
1135 /* I'm inclined to just go with 3 and 4 at the moment and */
1136 /* maybe try to support the others later */
1137 BufferParams & param = controller().params();
1140 if (ob == bullets_->radio_depth_1)
1142 else if (ob == bullets_->radio_depth_2)
1144 else if (ob == bullets_->radio_depth_3)
1146 else if (ob == bullets_->radio_depth_4)
1149 switch (fl_get_button_numb(ob)) {
1151 // right mouse button resets to default
1152 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1154 current_bullet_depth = data;
1155 fl_set_input(bullets_->input_latex,
1156 param.temp_bullets[data].getText().c_str());
1157 fl_set_choice(bullets_->choice_size,
1158 param.temp_bullets[data].getSize() + 2);
1163 void FormDocument::BulletPanel(FL_OBJECT * ob)
1165 /* Here we have to change the background pixmap to that selected */
1166 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1169 if (ob == bullets_->radio_panel_standard)
1171 else if (ob == bullets_->radio_panel_maths)
1173 else if (ob == bullets_->radio_panel_ding2)
1175 else if (ob == bullets_->radio_panel_ding3)
1177 else if (ob == bullets_->radio_panel_ding4)
1179 else if (ob == bullets_->radio_panel_ding1)
1182 if (data != current_bullet_panel) {
1183 fl_freeze_form(bullets_->form);
1184 current_bullet_panel = data;
1186 /* free the current pixmap */
1187 fl_free_bmtable_pixmap(bullets_->bmtable_panel);
1189 if (ob == bullets_->radio_panel_standard) {
1190 new_panel = "standard";
1191 } else if (ob == bullets_->radio_panel_maths ) {
1192 new_panel = "amssymb";
1193 } else if (ob == bullets_->radio_panel_ding2) {
1194 new_panel = "psnfss1";
1195 } else if (ob == bullets_->radio_panel_ding3) {
1196 new_panel = "psnfss2";
1197 } else if (ob == bullets_->radio_panel_ding4) {
1198 new_panel = "psnfss3";
1199 } else if (ob == bullets_->radio_panel_ding1) {
1200 new_panel = "psnfss4";
1202 /* something very wrong happened */
1203 // play it safe for now but should be an exception
1204 current_bullet_panel = 0; // standard panel
1205 new_panel = "standard";
1207 new_panel += ".xpm";
1208 fl_set_bmtable_pixmap_file(bullets_->bmtable_panel, 6, 6,
1209 LibFileSearch("images", new_panel).c_str());
1210 fl_redraw_object(bullets_->bmtable_panel);
1211 fl_unfreeze_form(bullets_->form);
1216 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/)
1218 /* handle the user input by setting the current bullet depth's pixmap */
1219 /* to that extracted from the current chosen position of the BMTable */
1220 /* Don't forget to free the button's old pixmap first. */
1222 BufferParams & param = controller().params();
1223 int bmtable_button = fl_get_bmtable(ob);
1225 /* try to keep the button held down till another is pushed */
1226 /* fl_set_bmtable(ob, 1, bmtable_button); */
1227 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1228 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1229 fl_set_input(bullets_->input_latex,
1230 param.temp_bullets[current_bullet_depth].getText().c_str());
1234 void FormDocument::CheckChoiceClass()
1236 BufferParams & params = controller().params();
1238 lyx::textclass_type const tc =
1239 fl_get_combox(class_->combox_class) - 1;
1241 if (controller().loadTextclass(tc)) {
1242 params.textclass = tc;
1244 if (lyxrc.auto_reset_options) {
1245 params.useClassDefaults();
1246 UpdateLayoutDocument(params);
1248 // update the params which are needed in any case
1249 // (fontsizes, pagestyle)
1250 UpdateClassParams(params);
1254 int const revert = int(params.textclass);
1255 fl_set_combox(class_->combox_class, revert + 1);
1260 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1266 class_update(params);
1267 paper_update(params);
1268 language_update(params);
1269 options_update(params);
1270 bullets_update(params);