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 "));
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 "));
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 | B3 | B4 | B5 "));
241 fl_addto_choice(paper_->choice_paperpackage,
244 "| Very small Margins "
245 "| Very wide Margins "));
247 fl_addto_choice(paper_->choice_custom_width_units, units.c_str());
248 fl_addto_choice(paper_->choice_custom_height_units, units.c_str());
249 fl_addto_choice(paper_->choice_top_margin_units, units.c_str());
250 fl_addto_choice(paper_->choice_bottom_margin_units, units.c_str());
251 fl_addto_choice(paper_->choice_inner_margin_units, units.c_str());
252 fl_addto_choice(paper_->choice_outer_margin_units, units.c_str());
253 fl_addto_choice(paper_->choice_head_height_units, units.c_str());
254 fl_addto_choice(paper_->choice_head_sep_units, units.c_str());
255 fl_addto_choice(paper_->choice_foot_skip_units, units.c_str());
257 // the document language form
258 language_.reset(build_document_language(this));
260 // disable for read-only documents
261 bcview().addReadOnly(language_->combox_language);
262 bcview().addReadOnly(language_->choice_inputenc);
263 bcview().addReadOnly(language_->choice_quotes_language);
264 bcview().addReadOnly(language_->radio_single);
265 bcview().addReadOnly(language_->radio_double);
267 fl_addto_choice(language_->choice_inputenc,
268 "default|auto|latin1|latin2|latin3|latin4|latin5|latin9"
269 "|koi8-r|koi8-u|cp866|cp1251|iso88595|pt154");
271 vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
272 // Store the identifiers for later
273 lang_ = getSecond(langs);
275 vector<frnt::LanguagePair>::const_iterator lit = langs.begin();
276 vector<frnt::LanguagePair>::const_iterator lend = langs.end();
277 for (; lit != lend; ++lit) {
278 fl_addto_combox(language_->combox_language,
281 fl_set_combox_browser_height(language_->combox_language, 400);
283 fl_addto_choice(language_->choice_quotes_language,
284 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
285 " «text» | »text« "));
287 // the document options form
288 options_.reset(build_document_options(this));
290 // disable for read-only documents
291 bcview().addReadOnly(options_->counter_secnumdepth);
292 bcview().addReadOnly(options_->counter_tocdepth);
293 bcview().addReadOnly(options_->choice_ams_math);
294 bcview().addReadOnly(options_->check_use_natbib);
295 bcview().addReadOnly(options_->choice_citation_format);
296 bcview().addReadOnly(options_->input_float_placement);
297 bcview().addReadOnly(options_->choice_postscript_driver);
299 // trigger an input event for cut&paste with middle mouse button.
300 setPrehandler(options_->input_float_placement);
302 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
304 fl_addto_choice(options_->choice_ams_math,
305 _("Never | Automatically | Yes "));
307 for (int n = 0; tex_graphics[n][0]; ++n) {
308 fl_addto_choice(options_->choice_postscript_driver,
311 fl_addto_choice(options_->choice_citation_format,
312 _(" Author-year | Numerical "));
314 // the document bullets form
315 bullets_.reset(build_document_bullet(this));
317 // disable for read-only documents
318 bcview().addReadOnly(bullets_->radio_depth_1);
319 bcview().addReadOnly(bullets_->radio_depth_2);
320 bcview().addReadOnly(bullets_->radio_depth_3);
321 bcview().addReadOnly(bullets_->radio_depth_4);
322 bcview().addReadOnly(bullets_->radio_panel_standard);
323 bcview().addReadOnly(bullets_->radio_panel_maths);
324 bcview().addReadOnly(bullets_->radio_panel_ding1);
325 bcview().addReadOnly(bullets_->radio_panel_ding2);
326 bcview().addReadOnly(bullets_->radio_panel_ding3);
327 bcview().addReadOnly(bullets_->radio_panel_ding4);
328 bcview().addReadOnly(bullets_->bmtable_panel);
329 bcview().addReadOnly(bullets_->choice_size);
330 bcview().addReadOnly(bullets_->input_latex);
332 // trigger an input event for cut&paste with middle mouse button.
333 setPrehandler(bullets_->input_latex);
335 fl_set_input_return(bullets_->input_latex, FL_RETURN_CHANGED);
337 fl_addto_choice(bullets_->choice_size,
338 _(" Default | Tiny | Smallest | Smaller | Small |"
339 " Normal | Large | Larger | Largest | Huge | Huger "));
340 fl_set_choice(bullets_->choice_size, 1);
342 fl_set_input_maxchars(bullets_->input_latex, 80);
344 string const bmtablefile = LibFileSearch("images", "standard", "xpm");
345 fl_set_bmtable_pixmap_file(bullets_->bmtable_panel, 6, 6,
346 bmtablefile.c_str());
348 // Enable the tabfolder to be rescaled correctly.
349 if (scalableTabfolders)
350 fl_set_tabfolder_autofit(dialog_->tabfolder, FL_FIT);
353 fl_addto_tabfolder(dialog_->tabfolder,_("Document"),
355 fl_addto_tabfolder(dialog_->tabfolder,_("Paper"),
357 fl_addto_tabfolder(dialog_->tabfolder,_("Language"),
359 fl_addto_tabfolder(dialog_->tabfolder,_("Extra"),
361 fbullet = fl_addto_tabfolder(dialog_->tabfolder,_("Bullets"),
364 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
365 lyxerr << _("Your version of libXpm is older than 4.7.\n"
366 "The `bullet' tab of the document dialog "
367 "has been disabled") << '\n';
368 fl_deactivate_object(fbullet);
369 fl_set_object_lcol(fbullet, FL_INACTIVE);
374 void FormDocument::apply()
376 BufferParams & params = controller().params();
380 language_apply(params);
381 options_apply(params);
382 bullets_apply(params);
386 void FormDocument::update()
393 BufferParams const & params = controller().params();
395 class_update(params);
396 paper_update(params);
397 language_update(params);
398 options_update(params);
399 bullets_update(params);
403 ButtonPolicy::SMInput FormDocument::input(FL_OBJECT * ob, long)
405 if (ob == bullets_->choice_size) {
406 ChoiceBulletSize(ob, 0);
408 } else if (ob == bullets_->input_latex) {
409 InputBulletLaTeX(ob, 0);
411 } else if (ob == bullets_->radio_depth_1 ||
412 ob == bullets_->radio_depth_2 ||
413 ob == bullets_->radio_depth_3 ||
414 ob == bullets_->radio_depth_4) {
417 } else if (ob == bullets_->radio_panel_standard ||
418 ob == bullets_->radio_panel_maths ||
419 ob == bullets_->radio_panel_ding1 ||
420 ob == bullets_->radio_panel_ding2 ||
421 ob == bullets_->radio_panel_ding3 ||
422 ob == bullets_->radio_panel_ding4) {
425 } else if (ob == bullets_->bmtable_panel) {
426 BulletBMTable(ob, 0);
428 } else if (ob == class_->choice_spacing) {
429 setEnabled(class_->input_spacing,
430 fl_get_choice(class_->choice_spacing) == 4);
432 } else if (ob == class_->combox_class) {
434 } else if (ob == class_->radio_skip ||
435 ob == class_->radio_indent ||
436 ob == class_->choice_skip) {
437 bool const skip_used = fl_get_button(class_->radio_skip);
438 setEnabled(class_->choice_skip, skip_used);
440 bool const length_input =
441 fl_get_choice(class_->choice_skip) == 4;
442 setEnabled(class_->input_skip,
443 skip_used && length_input);
444 setEnabled(class_->choice_skip_units,
445 skip_used && length_input);
447 // Default unit choice is cm if metric, inches if US paper.
448 // If papersize is default, check the lyxrc-settings
449 int const paperchoice = fl_get_choice(paper_->choice_papersize);
450 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
451 || paperchoice == 2 || paperchoice > 5;
452 string const default_unit = metric ? "cm" : "in";
453 if (getString(class_->input_skip).empty())
454 fl_set_choice_text(class_->choice_skip_units,
455 default_unit.c_str());
457 } else if (ob == options_->check_use_natbib) {
458 setEnabled(options_->choice_citation_format,
459 fl_get_button(options_->check_use_natbib));
461 } else if (ob == dialog_->button_save_defaults) {
463 controller().saveAsDefault();
465 } else if (ob == dialog_->button_reset_defaults) {
466 BufferParams & params = controller().params();
467 params.textclass = fl_get_combox(class_->combox_class) - 1;
468 params.useClassDefaults();
469 UpdateLayoutDocument(params);
471 } else if (ob == paper_->radio_landscape) {
472 fl_set_choice(paper_->choice_paperpackage,
473 BufferParams::PACKAGE_NONE + 1);
475 } else if (ob == paper_->choice_papersize) {
476 int const paperchoice = fl_get_choice(paper_->choice_papersize);
477 bool const defsize = paperchoice == 1;
478 bool const custom = paperchoice == 2;
479 bool const a3size = paperchoice == 6;
480 bool const b3size = paperchoice == 9;
481 bool const b4size = paperchoice == 10;
484 fl_set_button(paper_->radio_portrait, 1);
486 bool const use_geom = (custom || a3size || b3size || b4size);
488 fl_set_button(paper_->check_use_geometry, int(use_geom));
490 setEnabled(paper_->input_top_margin, use_geom);
491 setEnabled(paper_->input_bottom_margin, use_geom);
492 setEnabled(paper_->input_inner_margin, use_geom);
493 setEnabled(paper_->input_outer_margin, use_geom);
494 setEnabled(paper_->input_head_height, use_geom);
495 setEnabled(paper_->input_head_sep, use_geom);
496 setEnabled(paper_->input_foot_skip, use_geom);
497 setEnabled(paper_->choice_top_margin_units, use_geom);
498 setEnabled(paper_->choice_bottom_margin_units, use_geom);
499 setEnabled(paper_->choice_inner_margin_units, use_geom);
500 setEnabled(paper_->choice_outer_margin_units, use_geom);
501 setEnabled(paper_->choice_head_height_units, use_geom);
502 setEnabled(paper_->choice_head_sep_units, use_geom);
503 setEnabled(paper_->choice_foot_skip_units, use_geom);
504 setEnabled(paper_->choice_custom_width_units, use_geom);
505 setEnabled(paper_->choice_custom_height_units, use_geom);
507 setEnabled(paper_->input_custom_width, custom);
508 setEnabled(paper_->input_custom_height, custom);
509 setEnabled(paper_->choice_custom_width_units, custom);
510 setEnabled(paper_->choice_custom_height_units, custom);
511 setEnabled(paper_->radio_portrait, !custom);
512 setEnabled(paper_->radio_landscape, !custom);
514 // Default unit choice is cm if metric, inches if US paper.
515 // If papersize is default, use the lyxrc-settings
516 bool const metric = (defsize && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
517 || paperchoice == 2 || paperchoice > 5;
518 string const default_unit = metric ? "cm" : "in";
519 if (getString(paper_->input_custom_width).empty())
520 fl_set_choice_text(paper_->choice_custom_width_units,
521 default_unit.c_str());
522 if (getString(paper_->input_custom_height).empty())
523 fl_set_choice_text(paper_->choice_custom_height_units,
524 default_unit.c_str());
525 if (getString(paper_->input_top_margin).empty())
526 fl_set_choice_text(paper_->choice_top_margin_units,
527 default_unit.c_str());
528 if (getString(paper_->input_bottom_margin).empty())
529 fl_set_choice_text(paper_->choice_bottom_margin_units,
530 default_unit.c_str());
531 if (getString(paper_->input_inner_margin).empty())
532 fl_set_choice_text(paper_->choice_inner_margin_units,
533 default_unit.c_str());
534 if (getString(paper_->input_outer_margin).empty())
535 fl_set_choice_text(paper_->choice_outer_margin_units,
536 default_unit.c_str());
537 if (getString(paper_->input_head_height).empty())
538 fl_set_choice_text(paper_->choice_head_height_units,
539 default_unit.c_str());
540 if (getString(paper_->input_head_sep).empty())
541 fl_set_choice_text(paper_->choice_head_sep_units,
542 default_unit.c_str());
543 if (getString(paper_->input_foot_skip).empty())
544 fl_set_choice_text(paper_->choice_foot_skip_units,
545 default_unit.c_str());
547 } else if (ob == paper_->choice_paperpackage &&
548 fl_get_choice(paper_->choice_paperpackage) != 1) {
550 fl_set_button(paper_->check_use_geometry, 0);
551 setEnabled(paper_->input_top_margin, false);
552 setEnabled(paper_->input_bottom_margin, false);
553 setEnabled(paper_->input_inner_margin, false);
554 setEnabled(paper_->input_outer_margin, false);
555 setEnabled(paper_->input_head_height, false);
556 setEnabled(paper_->input_head_sep, false);
557 setEnabled(paper_->input_foot_skip, false);
558 setEnabled(paper_->choice_top_margin_units, false);
559 setEnabled(paper_->choice_bottom_margin_units, false);
560 setEnabled(paper_->choice_inner_margin_units, false);
561 setEnabled(paper_->choice_outer_margin_units, false);
562 setEnabled(paper_->choice_head_height_units, false);
563 setEnabled(paper_->choice_head_sep_units, false);
564 setEnabled(paper_->choice_foot_skip_units, false);
566 } else if (ob == paper_->check_use_geometry) {
567 // don't allow switching geometry off in custom papersize
568 // mode nor in A3, B3, and B4
569 int const choice = fl_get_choice(paper_->choice_papersize);
570 if (choice == 2 || choice == 6 || choice == 9 || choice == 10)
571 fl_set_button(paper_->check_use_geometry, 1);
573 fl_set_choice(paper_->choice_paperpackage,
574 BufferParams::PACKAGE_NONE + 1);
576 bool const use_geom = fl_get_button(paper_->check_use_geometry);
577 setEnabled(paper_->input_top_margin, use_geom);
578 setEnabled(paper_->input_bottom_margin, use_geom);
579 setEnabled(paper_->input_inner_margin, use_geom);
580 setEnabled(paper_->input_outer_margin, use_geom);
581 setEnabled(paper_->input_head_height, use_geom);
582 setEnabled(paper_->input_head_sep, use_geom);
583 setEnabled(paper_->input_foot_skip, use_geom);
584 setEnabled(paper_->choice_top_margin_units, use_geom);
585 setEnabled(paper_->choice_bottom_margin_units, use_geom);
586 setEnabled(paper_->choice_inner_margin_units, use_geom);
587 setEnabled(paper_->choice_outer_margin_units, use_geom);
588 setEnabled(paper_->choice_head_height_units, use_geom);
589 setEnabled(paper_->choice_head_sep_units, use_geom);
590 setEnabled(paper_->choice_foot_skip_units, use_geom);
593 if (ob == paper_->choice_papersize || ob == paper_->radio_portrait
594 || ob == paper_->radio_landscape) {
595 // either default papersize (preferences) or document
596 // papersize has to be A4
597 bool const enable = ( fl_get_choice(paper_->choice_papersize) == 1
598 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER )
599 || fl_get_choice(paper_->choice_papersize) == 7;
601 fl_set_choice(paper_->choice_paperpackage,
602 BufferParams::PACKAGE_NONE + 1);
603 setEnabled(paper_->choice_paperpackage,
604 enable && fl_get_button(paper_->radio_portrait));
607 return ButtonPolicy::SMI_VALID;
611 bool FormDocument::class_apply(BufferParams ¶ms)
615 // If default skip is a "Length" but there's no text in the
616 // input field, reset the kind to "MedSkip", which is the default.
617 if (fl_get_choice(class_->choice_skip) == 4 &&
618 getString(class_->input_skip).empty()) {
619 fl_set_choice(class_->choice_skip, 2);
621 params.fonts = getString(class_->choice_fonts);
622 params.fontsize = getString(class_->choice_fontsize);
623 params.pagestyle = getString(class_->choice_pagestyle);
625 params.textclass = fl_get_combox(class_->combox_class) - 1;
627 BufferParams::PARSEP tmpsep = params.paragraph_separation;
628 if (fl_get_button(class_->radio_indent))
629 params.paragraph_separation = BufferParams::PARSEP_INDENT;
631 params.paragraph_separation = BufferParams::PARSEP_SKIP;
632 if (tmpsep != params.paragraph_separation)
635 VSpace tmpdefskip = params.getDefSkip();
636 switch (fl_get_choice(class_->choice_skip)) {
638 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
641 params.setDefSkip(VSpace(VSpace::MEDSKIP));
644 params.setDefSkip(VSpace(VSpace::BIGSKIP));
648 string const length =
649 getLengthFromWidgets(class_->input_skip,
650 class_->choice_skip_units);
652 params.setDefSkip(VSpace(LyXGlueLength(length)));
656 // DocumentDefskipCB assures that this never happens
657 params.setDefSkip(VSpace(VSpace::MEDSKIP));
660 if (!(tmpdefskip == params.getDefSkip()))
663 if (fl_get_button(class_->radio_columns_two))
667 if (fl_get_button(class_->radio_sides_two))
668 params.sides = LyXTextClass::TwoSides;
670 params.sides = LyXTextClass::OneSide;
672 Spacing tmpSpacing = params.spacing;
673 switch (fl_get_choice(class_->choice_spacing)) {
675 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
676 params.spacing.set(Spacing::Single);
679 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
680 params.spacing.set(Spacing::Onehalf);
683 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
684 params.spacing.set(Spacing::Double);
687 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
688 params.spacing.set(Spacing::Other,
689 getString(class_->input_spacing));
692 if (tmpSpacing != params.spacing)
695 params.options = getString(class_->input_extra);
701 void FormDocument::paper_apply(BufferParams & params)
703 params.papersize2 = char(fl_get_choice(paper_->choice_papersize) - 1);
705 params.paperpackage =
706 char(fl_get_choice(paper_->choice_paperpackage) - 1);
708 // set params.papersize from params.papersize2 and params.paperpackage
709 params.setPaperStuff();
711 params.use_geometry = fl_get_button(paper_->check_use_geometry);
713 if (fl_get_button(paper_->radio_landscape))
714 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
716 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
719 getLengthFromWidgets(paper_->input_custom_width,
720 paper_->choice_custom_width_units);
723 getLengthFromWidgets(paper_->input_custom_height,
724 paper_->choice_custom_height_units);
727 getLengthFromWidgets(paper_->input_inner_margin,
728 paper_->choice_inner_margin_units);
731 getLengthFromWidgets(paper_->input_top_margin,
732 paper_->choice_top_margin_units);
735 getLengthFromWidgets(paper_->input_outer_margin,
736 paper_->choice_outer_margin_units);
738 params.bottommargin =
739 getLengthFromWidgets(paper_->input_bottom_margin,
740 paper_->choice_bottom_margin_units);
743 getLengthFromWidgets(paper_->input_head_height,
744 paper_->choice_head_height_units);
747 getLengthFromWidgets(paper_->input_head_sep,
748 paper_->choice_head_sep_units);
751 getLengthFromWidgets(paper_->input_foot_skip,
752 paper_->choice_foot_skip_units);
756 bool FormDocument::language_apply(BufferParams & params)
758 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
761 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
763 lga = InsetQuotes::EnglishQ;
766 lga = InsetQuotes::SwedishQ;
769 lga = InsetQuotes::GermanQ;
772 lga = InsetQuotes::PolishQ;
775 lga = InsetQuotes::FrenchQ;
778 lga = InsetQuotes::DanishQ;
781 params.quotes_language = lga;
782 if (fl_get_button(language_->radio_single))
783 params.quotes_times = InsetQuotes::SingleQ;
785 params.quotes_times = InsetQuotes::DoubleQ;
787 int const pos = fl_get_combox(language_->combox_language);
788 Language const * new_language = languages.getLanguage(lang_[pos-1]);
790 new_language = default_language;
792 params.language = new_language;
793 params.inputenc = getString(language_->choice_inputenc);
799 bool FormDocument::options_apply(BufferParams & params)
803 params.graphicsDriver = getString(options_->choice_postscript_driver);
804 params.use_amsmath = static_cast<BufferParams::AMS>(
805 fl_get_choice(options_->choice_ams_math) - 1);
806 params.use_natbib = fl_get_button(options_->check_use_natbib);
807 params.use_numerical_citations =
808 fl_get_choice(options_->choice_citation_format) - 1;
810 int tmpchar = int(fl_get_counter_value(options_->counter_secnumdepth));
811 if (params.secnumdepth != tmpchar)
813 params.secnumdepth = tmpchar;
815 params.tocdepth = int(fl_get_counter_value(options_->counter_tocdepth));
817 params.float_placement =
818 getString(options_->input_float_placement);
824 void FormDocument::bullets_apply(BufferParams & params)
826 /* update the bullet settings */
827 BufferParams & buf_params = controller().params();
829 for (int i = 0; i < 4; ++i) {
830 params.user_defined_bullets[i] = buf_params.temp_bullets[i];
835 void FormDocument::UpdateClassParams(BufferParams const & params)
837 // These are the params that have to be updated on any class change
838 // (even if the class defaults are not used) (JSpitzm 2002-04-08)
840 LyXTextClass const & tclass = textclasslist[params.textclass];
842 fl_set_combox(class_->combox_class, params.textclass + 1);
843 fl_clear_choice(class_->choice_fontsize);
844 fl_addto_choice(class_->choice_fontsize, "default");
845 fl_addto_choice(class_->choice_fontsize,
846 tclass.opt_fontsize().c_str());
847 fl_set_choice_text(class_->choice_fontsize,
848 params.fontsize.c_str());
849 fl_clear_choice(class_->choice_pagestyle);
850 fl_addto_choice(class_->choice_pagestyle, "default");
851 fl_addto_choice(class_->choice_pagestyle,
852 tclass.opt_pagestyle().c_str());
853 fl_set_choice_text(class_->choice_pagestyle,
854 params.pagestyle.c_str());
858 void FormDocument::class_update(BufferParams const & params)
863 UpdateClassParams(params);
865 fl_set_choice_text(class_->choice_fonts, params.fonts.c_str());
867 bool const indent = params.paragraph_separation == BufferParams::PARSEP_INDENT;
868 fl_set_button(class_->radio_indent, indent);
869 fl_set_button(class_->radio_skip, !indent);
873 pos = 2; // VSpace::MEDSKIP is default
875 switch (params.getDefSkip().kind()) {
879 case VSpace::BIGSKIP:
882 case VSpace::SMALLSKIP:
885 case VSpace::MEDSKIP:
891 fl_set_choice (class_->choice_skip, pos);
893 bool const length_input = pos == 4;
895 int const paperchoice = fl_get_choice(paper_->choice_papersize);
896 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
897 || paperchoice == 2 || paperchoice > 5;
898 string const default_unit = metric ? "cm" : "in";
899 string const length = params.getDefSkip().asLyXCommand();
900 updateWidgetsFromLengthString(class_->input_skip,
901 class_->choice_skip_units,
902 length, default_unit);
905 fl_set_input(class_->input_skip, "");
907 setEnabled(class_->choice_skip, !indent);
908 setEnabled(class_->input_skip, length_input);
909 setEnabled(class_->choice_skip_units, length_input);
911 bool const two_sides = params.sides == LyXTextClass::TwoSides;
912 fl_set_button(class_->radio_sides_one, !two_sides);
913 fl_set_button(class_->radio_sides_two, two_sides);
915 bool const two_columns = params.columns == 2;
916 fl_set_button(class_->radio_columns_one, !two_columns);
917 fl_set_button(class_->radio_columns_two, two_columns);
919 fl_set_input(class_->input_extra, params.options.c_str());
921 switch (params.spacing.getSpace()) {
925 case Spacing::Double: // \doublespacing
928 case Spacing::Onehalf: // \onehalfspacing
931 case Spacing::Single: // \singlespacing
932 case Spacing::Default: // nothing bad should happen with this
937 fl_set_choice(class_->choice_spacing, pos);
939 bool const spacing_input = pos == 4;
940 setEnabled(class_->input_spacing, spacing_input);
941 string const input = spacing_input ? tostr(params.spacing.getValue()) : string();
942 fl_set_input(class_->input_spacing, input.c_str());
946 void FormDocument::language_update(BufferParams const & params)
948 if (!language_.get())
951 int const pos = int(findPos(lang_, params.language->lang()));
952 fl_set_combox(language_->combox_language, pos+1);
954 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
955 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
956 fl_set_button(language_->radio_single, 0);
957 fl_set_button(language_->radio_double, 0);
958 if (params.quotes_times == InsetQuotes::SingleQ)
959 fl_set_button(language_->radio_single, 1);
961 fl_set_button(language_->radio_double, 1);
965 void FormDocument::options_update(BufferParams const & params)
970 fl_set_choice_text(options_->choice_postscript_driver,
971 params.graphicsDriver.c_str());
972 fl_set_choice(options_->choice_ams_math, params.use_amsmath + 1);
973 fl_set_button(options_->check_use_natbib, params.use_natbib);
974 fl_set_choice(options_->choice_citation_format,
975 int(params.use_numerical_citations)+1);
976 setEnabled(options_->choice_citation_format, params.use_natbib);
977 fl_set_counter_value(options_->counter_secnumdepth, params.secnumdepth);
978 fl_set_counter_value(options_->counter_tocdepth, params.tocdepth);
979 if (!params.float_placement.empty())
980 fl_set_input(options_->input_float_placement,
981 params.float_placement.c_str());
983 fl_set_input(options_->input_float_placement, "");
987 void FormDocument::paper_update(BufferParams const & params)
992 fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
993 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
994 fl_set_button(paper_->check_use_geometry, params.use_geometry);
996 int const paperchoice = fl_get_choice(paper_->choice_papersize);
997 bool const useCustom = paperchoice == 2;
998 bool const useGeom = fl_get_button(paper_->check_use_geometry);
1000 fl_set_button(paper_->radio_portrait, 0);
1001 setEnabled(paper_->radio_portrait, !useCustom);
1002 fl_set_button(paper_->radio_landscape, 0);
1003 setEnabled(paper_->radio_landscape, !useCustom);
1005 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1006 fl_set_button(paper_->radio_landscape, 1);
1008 fl_set_button(paper_->radio_portrait, 1);
1009 setEnabled(paper_->choice_paperpackage,
1010 //either default papersize (preferences)
1011 //or document papersize has to be A4
1013 || paperchoice == 1 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER)
1014 && fl_get_button(paper_->radio_portrait));
1016 // Default unit choice is cm if metric, inches if US paper.
1017 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
1018 || paperchoice == 2 || paperchoice > 5;
1019 string const default_unit = metric ? "cm" : "in";
1020 updateWidgetsFromLengthString(paper_->input_custom_width,
1021 paper_->choice_custom_width_units,
1022 params.paperwidth, default_unit);
1023 setEnabled(paper_->input_custom_width, useCustom);
1024 setEnabled(paper_->choice_custom_width_units, useCustom);
1026 updateWidgetsFromLengthString(paper_->input_custom_height,
1027 paper_->choice_custom_height_units,
1028 params.paperheight, default_unit);
1029 setEnabled(paper_->input_custom_height, useCustom);
1030 setEnabled(paper_->choice_custom_height_units, useCustom);
1032 updateWidgetsFromLengthString(paper_->input_inner_margin,
1033 paper_->choice_inner_margin_units,
1034 params.leftmargin, default_unit);
1035 setEnabled(paper_->input_inner_margin, useGeom);
1036 setEnabled(paper_->choice_inner_margin_units, useGeom);
1038 updateWidgetsFromLengthString(paper_->input_top_margin,
1039 paper_->choice_top_margin_units,
1040 params.topmargin, default_unit);
1041 setEnabled(paper_->input_top_margin, useGeom);
1042 setEnabled(paper_->choice_top_margin_units, useGeom);
1044 updateWidgetsFromLengthString(paper_->input_outer_margin,
1045 paper_->choice_outer_margin_units,
1046 params.rightmargin, default_unit);
1047 setEnabled(paper_->input_outer_margin, useGeom);
1048 setEnabled(paper_->choice_outer_margin_units, useGeom);
1050 updateWidgetsFromLengthString(paper_->input_bottom_margin,
1051 paper_->choice_bottom_margin_units,
1052 params.bottommargin, default_unit);
1053 setEnabled(paper_->input_bottom_margin, useGeom);
1054 setEnabled(paper_->choice_bottom_margin_units, useGeom);
1056 updateWidgetsFromLengthString(paper_->input_head_height,
1057 paper_->choice_head_height_units,
1058 params.headheight, default_unit);
1059 setEnabled(paper_->input_head_height, useGeom);
1060 setEnabled(paper_->choice_head_height_units, useGeom);
1062 updateWidgetsFromLengthString(paper_->input_head_sep,
1063 paper_->choice_head_sep_units,
1064 params.headsep, default_unit);
1065 setEnabled(paper_->input_head_sep, useGeom);
1066 setEnabled(paper_->choice_head_sep_units, useGeom);
1068 updateWidgetsFromLengthString(paper_->input_foot_skip,
1069 paper_->choice_foot_skip_units,
1070 params.footskip, default_unit);
1071 setEnabled(paper_->input_foot_skip, useGeom);
1072 setEnabled(paper_->choice_foot_skip_units, useGeom);
1074 fl_set_focus_object(paper_->form, paper_->choice_papersize);
1078 void FormDocument::bullets_update(BufferParams const & params)
1080 if (!bullets_.get() ||
1082 (XpmVersion==4 && XpmRevision<7)))
1085 bool const isLinuxDoc =
1086 controller().docType() == ControlDocument::LINUXDOC;
1087 setEnabled(fbullet, !isLinuxDoc);
1089 if (isLinuxDoc) return;
1091 fl_set_button(bullets_->radio_depth_1, 1);
1092 fl_set_input(bullets_->input_latex,
1093 params.user_defined_bullets[0].getText().c_str());
1094 fl_set_choice(bullets_->choice_size,
1095 params.user_defined_bullets[0].getSize() + 2);
1099 void FormDocument::checkReadOnly()
1101 if (bc().readOnly(controller().bufferIsReadonly())) {
1102 postWarning(_("Document is read-only."
1103 " No changes to layout permitted."));
1110 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/)
1112 BufferParams & param = controller().params();
1114 // convert from 1-6 range to -1-4
1115 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1116 fl_set_input(bullets_->input_latex,
1117 param.temp_bullets[current_bullet_depth].getText().c_str());
1121 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1123 BufferParams & param = controller().params();
1125 param.temp_bullets[current_bullet_depth].
1126 setText(getString(bullets_->input_latex));
1130 void FormDocument::BulletDepth(FL_OBJECT * ob)
1132 /* Should I do the following: */
1133 /* 1. change to the panel that the current bullet belongs in */
1134 /* 2. show that bullet as selected */
1135 /* 3. change the size setting to the size of the bullet in Q.*/
1136 /* 4. display the latex equivalent in the latex box */
1138 /* I'm inclined to just go with 3 and 4 at the moment and */
1139 /* maybe try to support the others later */
1140 BufferParams & param = controller().params();
1143 if (ob == bullets_->radio_depth_1)
1145 else if (ob == bullets_->radio_depth_2)
1147 else if (ob == bullets_->radio_depth_3)
1149 else if (ob == bullets_->radio_depth_4)
1152 switch (fl_get_button_numb(ob)) {
1154 // right mouse button resets to default
1155 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1157 current_bullet_depth = data;
1158 fl_set_input(bullets_->input_latex,
1159 param.temp_bullets[data].getText().c_str());
1160 fl_set_choice(bullets_->choice_size,
1161 param.temp_bullets[data].getSize() + 2);
1166 void FormDocument::BulletPanel(FL_OBJECT * ob)
1168 /* Here we have to change the background pixmap to that selected */
1169 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1172 if (ob == bullets_->radio_panel_standard)
1174 else if (ob == bullets_->radio_panel_maths)
1176 else if (ob == bullets_->radio_panel_ding2)
1178 else if (ob == bullets_->radio_panel_ding3)
1180 else if (ob == bullets_->radio_panel_ding4)
1182 else if (ob == bullets_->radio_panel_ding1)
1185 if (data != current_bullet_panel) {
1186 fl_freeze_form(bullets_->form);
1187 current_bullet_panel = data;
1189 /* free the current pixmap */
1190 fl_free_bmtable_pixmap(bullets_->bmtable_panel);
1192 if (ob == bullets_->radio_panel_standard) {
1193 new_panel = "standard";
1194 } else if (ob == bullets_->radio_panel_maths ) {
1195 new_panel = "amssymb";
1196 } else if (ob == bullets_->radio_panel_ding2) {
1197 new_panel = "psnfss1";
1198 } else if (ob == bullets_->radio_panel_ding3) {
1199 new_panel = "psnfss2";
1200 } else if (ob == bullets_->radio_panel_ding4) {
1201 new_panel = "psnfss3";
1202 } else if (ob == bullets_->radio_panel_ding1) {
1203 new_panel = "psnfss4";
1205 /* something very wrong happened */
1206 // play it safe for now but should be an exception
1207 current_bullet_panel = 0; // standard panel
1208 new_panel = "standard";
1210 new_panel += ".xpm";
1211 fl_set_bmtable_pixmap_file(bullets_->bmtable_panel, 6, 6,
1212 LibFileSearch("images", new_panel).c_str());
1213 fl_redraw_object(bullets_->bmtable_panel);
1214 fl_unfreeze_form(bullets_->form);
1219 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/)
1221 /* handle the user input by setting the current bullet depth's pixmap */
1222 /* to that extracted from the current chosen position of the BMTable */
1223 /* Don't forget to free the button's old pixmap first. */
1225 BufferParams & param = controller().params();
1226 int bmtable_button = fl_get_bmtable(ob);
1228 /* try to keep the button held down till another is pushed */
1229 /* fl_set_bmtable(ob, 1, bmtable_button); */
1230 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1231 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1232 fl_set_input(bullets_->input_latex,
1233 param.temp_bullets[current_bullet_depth].getText().c_str());
1237 void FormDocument::CheckChoiceClass()
1239 BufferParams & params = controller().params();
1241 lyx::textclass_type const tc =
1242 fl_get_combox(class_->combox_class) - 1;
1244 if (controller().loadTextclass(tc)) {
1245 params.textclass = tc;
1247 if (lyxrc.auto_reset_options) {
1248 params.useClassDefaults();
1249 UpdateLayoutDocument(params);
1251 // update the params which are needed in any case
1252 // (fontsizes, pagestyle)
1253 UpdateClassParams(params);
1257 int const revert = int(params.textclass);
1258 fl_set_combox(class_->combox_class, revert + 1);
1263 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1269 class_update(params);
1270 paper_update(params);
1271 language_update(params);
1272 options_update(params);
1273 bullets_update(params);