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>
53 #if FL_VERSION == 0 || (FL_REVISION == 0 && FL_FIXLEVEL < 2)
54 bool const scalableTabfolders = false;
56 bool const scalableTabfolders = true;
62 typedef FormCB<ControlDocument, FormDB<FD_document> > base_class;
64 FormDocument::FormDocument()
65 : base_class(_("Document Settings"), scalableTabfolders),
66 ActCell(0), Confirmed(0),
67 current_bullet_panel(0), current_bullet_depth(0), fbullet(0)
71 void FormDocument::redraw()
73 if (form() && form()->visible)
74 fl_redraw_form(form());
78 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder);
79 if (outer_form && outer_form->visible)
80 fl_redraw_form(outer_form);
84 void FormDocument::build()
87 dialog_.reset(build_document(this));
89 // Allow the base class to control messages
90 setMessageWidget(dialog_->text_warning);
92 // Manage the restore, ok, apply, restore and cancel/close buttons
93 bcview().setOK(dialog_->button_ok);
94 bcview().setApply(dialog_->button_apply);
95 bcview().setCancel(dialog_->button_close);
96 bcview().setRestore(dialog_->button_restore);
98 // the document class form
99 class_.reset(build_document_class(this));
101 // disable for read-only documents
102 bcview().addReadOnly(class_->combox_class);
103 bcview().addReadOnly(class_->radio_indent);
104 bcview().addReadOnly(class_->radio_skip);
105 bcview().addReadOnly(class_->choice_pagestyle);
106 bcview().addReadOnly(class_->choice_fonts);
107 bcview().addReadOnly(class_->choice_fontsize);
108 bcview().addReadOnly(class_->radio_sides_one);
109 bcview().addReadOnly(class_->radio_sides_two);
110 bcview().addReadOnly(class_->radio_columns_one);
111 bcview().addReadOnly(class_->radio_columns_two);
112 bcview().addReadOnly(class_->input_extra);
113 bcview().addReadOnly(class_->input_skip);
114 bcview().addReadOnly(class_->choice_skip);
115 bcview().addReadOnly(class_->choice_spacing);
116 bcview().addReadOnly(class_->input_spacing);
118 // check validity of "length + unit" input
119 addCheckedGlueLength(bcview(), class_->input_skip,
120 class_->choice_skip);
122 // trigger an input event for cut&paste with middle mouse button.
123 setPrehandler(class_->input_extra);
124 setPrehandler(class_->input_skip);
125 setPrehandler(class_->input_spacing);
127 fl_set_input_return(class_->input_extra, FL_RETURN_CHANGED);
128 fl_set_input_return(class_->input_skip, FL_RETURN_CHANGED);
129 fl_set_input_return(class_->input_spacing, FL_RETURN_CHANGED);
133 // Fill the combox and choices.
134 obj = class_->combox_class;
135 LyXTextClassList::const_iterator tit = textclasslist.begin();
136 LyXTextClassList::const_iterator tend = textclasslist.end();
137 for (; tit != tend; ++tit) {
138 if (tit->isTeXClassAvailable()) {
139 fl_addto_combox(obj, tit->description().c_str());
141 string item = bformat(_("Unavailable: %1$s"), tit->description());
142 fl_addto_combox(obj, item.c_str());
145 fl_set_combox_browser_height(obj, 400);
147 fl_addto_choice(class_->choice_spacing,
148 _(" Single | OneHalf | Double | Custom ").c_str());
149 fl_addto_choice(class_->choice_fontsize, "default|10|11|12");
150 for (int n = 0; tex_fonts[n][0]; ++n) {
151 fl_addto_choice(class_->choice_fonts,tex_fonts[n]);
154 // Create the contents of the unit choices; don't include the
156 vector<string> units_vec = getLatexUnits();
157 vector<string>::iterator ret =
158 std::remove_if(units_vec.begin(),
160 bind2nd(contains_functor(), "%"));
161 units_vec.erase(ret, units_vec.end());
163 string const units = getStringFromVector(units_vec, "|");
165 fl_addto_choice(class_->choice_pagestyle,
166 "default|empty|plain|headings|fancy");
167 fl_addto_choice(class_->choice_skip,
168 _(" SmallSkip | MedSkip | BigSkip | Length ").c_str());
169 fl_addto_choice(class_->choice_skip_units, units.c_str());
171 // Set input filters on doc spacing to make it accept only
173 fl_set_input_filter(class_->input_spacing,
174 fl_unsigned_float_filter);
176 // disable for read-only documents
177 bcview().addReadOnly(dialog_->button_save_defaults);
178 bcview().addReadOnly(dialog_->button_reset_defaults);
180 // the document paper form
181 paper_.reset(build_document_paper(this));
183 // disable for read-only documents
184 bcview().addReadOnly(paper_->choice_paperpackage);
185 bcview().addReadOnly(paper_->radio_portrait);
186 bcview().addReadOnly(paper_->radio_landscape);
187 bcview().addReadOnly(paper_->choice_papersize);
188 bcview().addReadOnly(paper_->check_use_geometry);
189 bcview().addReadOnly(paper_->input_custom_width);
190 bcview().addReadOnly(paper_->input_custom_height);
191 bcview().addReadOnly(paper_->input_top_margin);
192 bcview().addReadOnly(paper_->input_bottom_margin);
193 bcview().addReadOnly(paper_->input_inner_margin);
194 bcview().addReadOnly(paper_->input_outer_margin);
195 bcview().addReadOnly(paper_->input_head_height);
196 bcview().addReadOnly(paper_->input_head_sep);
197 bcview().addReadOnly(paper_->input_foot_skip);
199 // check validity of "length + unit" input
200 addCheckedGlueLength(bcview(), paper_->input_custom_width);
201 addCheckedGlueLength(bcview(), paper_->input_custom_height);
202 addCheckedGlueLength(bcview(), paper_->input_top_margin);
203 addCheckedGlueLength(bcview(), paper_->input_bottom_margin);
204 addCheckedGlueLength(bcview(), paper_->input_inner_margin);
205 addCheckedGlueLength(bcview(), paper_->input_outer_margin);
206 addCheckedGlueLength(bcview(), paper_->input_head_height);
207 addCheckedGlueLength(bcview(), paper_->input_head_sep);
208 addCheckedGlueLength(bcview(), paper_->input_foot_skip);
210 // trigger an input event for cut&paste with middle mouse button.
211 setPrehandler(paper_->input_custom_width);
212 setPrehandler(paper_->input_custom_height);
213 setPrehandler(paper_->input_top_margin);
214 setPrehandler(paper_->input_bottom_margin);
215 setPrehandler(paper_->input_inner_margin);
216 setPrehandler(paper_->input_outer_margin);
217 setPrehandler(paper_->input_head_height);
218 setPrehandler(paper_->input_head_sep);
219 setPrehandler(paper_->input_foot_skip);
221 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
222 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
223 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
224 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
225 fl_set_input_return(paper_->input_inner_margin, FL_RETURN_CHANGED);
226 fl_set_input_return(paper_->input_outer_margin, FL_RETURN_CHANGED);
227 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
228 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
229 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
231 fl_addto_choice(paper_->choice_papersize,
232 _(" Default | Custom | US letter | US legal "
233 "| US executive | A3 | A4 | A5 "
234 "| B3 | B4 | B5 ").c_str());
235 fl_addto_choice(paper_->choice_paperpackage,
238 "| Very small Margins "
239 "| Very wide Margins ").c_str());
241 fl_addto_choice(paper_->choice_custom_width_units, units.c_str());
242 fl_addto_choice(paper_->choice_custom_height_units, units.c_str());
243 fl_addto_choice(paper_->choice_top_margin_units, units.c_str());
244 fl_addto_choice(paper_->choice_bottom_margin_units, units.c_str());
245 fl_addto_choice(paper_->choice_inner_margin_units, units.c_str());
246 fl_addto_choice(paper_->choice_outer_margin_units, units.c_str());
247 fl_addto_choice(paper_->choice_head_height_units, units.c_str());
248 fl_addto_choice(paper_->choice_head_sep_units, units.c_str());
249 fl_addto_choice(paper_->choice_foot_skip_units, units.c_str());
251 // the document language form
252 language_.reset(build_document_language(this));
254 // disable for read-only documents
255 bcview().addReadOnly(language_->combox_language);
256 bcview().addReadOnly(language_->choice_inputenc);
257 bcview().addReadOnly(language_->choice_quotes_language);
258 bcview().addReadOnly(language_->radio_single);
259 bcview().addReadOnly(language_->radio_double);
261 fl_addto_choice(language_->choice_inputenc,
262 "default|auto|latin1|latin2|latin3|latin4|latin5|latin9"
263 "|koi8-r|koi8-u|cp866|cp1251|iso88595|pt154");
265 vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
266 // Store the identifiers for later
267 lang_ = getSecond(langs);
269 vector<frnt::LanguagePair>::const_iterator lit = langs.begin();
270 vector<frnt::LanguagePair>::const_iterator lend = langs.end();
271 for (; lit != lend; ++lit) {
272 fl_addto_combox(language_->combox_language,
275 fl_set_combox_browser_height(language_->combox_language, 400);
277 fl_addto_choice(language_->choice_quotes_language,
278 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
279 " «text» | »text« ").c_str());
281 // the document options form
282 options_.reset(build_document_options(this));
284 // disable for read-only documents
285 bcview().addReadOnly(options_->counter_secnumdepth);
286 bcview().addReadOnly(options_->counter_tocdepth);
287 bcview().addReadOnly(options_->choice_ams_math);
288 bcview().addReadOnly(options_->check_use_natbib);
289 bcview().addReadOnly(options_->choice_citation_format);
290 bcview().addReadOnly(options_->input_float_placement);
291 bcview().addReadOnly(options_->choice_postscript_driver);
293 // trigger an input event for cut&paste with middle mouse button.
294 setPrehandler(options_->input_float_placement);
296 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
298 fl_addto_choice(options_->choice_ams_math,
299 _("Never | Automatically | Yes ").c_str());
301 for (int n = 0; tex_graphics[n][0]; ++n) {
302 fl_addto_choice(options_->choice_postscript_driver,
305 fl_addto_choice(options_->choice_citation_format,
306 _(" Author-year | Numerical ").c_str());
308 // the document bullets form
309 bullets_.reset(build_document_bullet(this));
311 // disable for read-only documents
312 bcview().addReadOnly(bullets_->radio_depth_1);
313 bcview().addReadOnly(bullets_->radio_depth_2);
314 bcview().addReadOnly(bullets_->radio_depth_3);
315 bcview().addReadOnly(bullets_->radio_depth_4);
316 bcview().addReadOnly(bullets_->radio_panel_standard);
317 bcview().addReadOnly(bullets_->radio_panel_maths);
318 bcview().addReadOnly(bullets_->radio_panel_ding1);
319 bcview().addReadOnly(bullets_->radio_panel_ding2);
320 bcview().addReadOnly(bullets_->radio_panel_ding3);
321 bcview().addReadOnly(bullets_->radio_panel_ding4);
322 bcview().addReadOnly(bullets_->bmtable_panel);
323 bcview().addReadOnly(bullets_->choice_size);
324 bcview().addReadOnly(bullets_->input_latex);
326 // trigger an input event for cut&paste with middle mouse button.
327 setPrehandler(bullets_->input_latex);
329 fl_set_input_return(bullets_->input_latex, FL_RETURN_CHANGED);
331 fl_addto_choice(bullets_->choice_size,
332 _(" Default | Tiny | Smallest | Smaller "
333 "| Small | Normal | Large | Larger | Largest "
334 "| Huge | Huger ").c_str());
335 fl_set_choice(bullets_->choice_size, 1);
337 fl_set_input_maxchars(bullets_->input_latex, 80);
339 string const bmtablefile = LibFileSearch("images", "standard", "xpm");
340 fl_set_bmtable_pixmap_file(bullets_->bmtable_panel, 6, 6,
341 bmtablefile.c_str());
343 // Enable the tabfolder to be rescaled correctly.
344 if (scalableTabfolders)
345 fl_set_tabfolder_autofit(dialog_->tabfolder, FL_FIT);
348 fl_addto_tabfolder(dialog_->tabfolder,_("Document").c_str(),
350 fl_addto_tabfolder(dialog_->tabfolder,_("Paper").c_str(),
352 fl_addto_tabfolder(dialog_->tabfolder,_("Language").c_str(),
354 fl_addto_tabfolder(dialog_->tabfolder,_("Extra").c_str(),
356 fbullet = fl_addto_tabfolder(dialog_->tabfolder,_("Bullets").c_str(),
359 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
360 lyxerr << _("Your version of libXpm is older than 4.7.\n"
361 "The `bullet' tab of the document dialog "
362 "has been disabled") << '\n';
363 fl_deactivate_object(fbullet);
364 fl_set_object_lcol(fbullet, FL_INACTIVE);
369 void FormDocument::apply()
371 BufferParams & params = controller().params();
375 language_apply(params);
376 options_apply(params);
377 bullets_apply(params);
381 void FormDocument::update()
388 BufferParams const & params = controller().params();
390 class_update(params);
391 paper_update(params);
392 language_update(params);
393 options_update(params);
394 bullets_update(params);
398 ButtonPolicy::SMInput FormDocument::input(FL_OBJECT * ob, long)
400 if (ob == bullets_->choice_size) {
401 ChoiceBulletSize(ob, 0);
403 } else if (ob == bullets_->input_latex) {
404 InputBulletLaTeX(ob, 0);
406 } else if (ob == bullets_->radio_depth_1 ||
407 ob == bullets_->radio_depth_2 ||
408 ob == bullets_->radio_depth_3 ||
409 ob == bullets_->radio_depth_4) {
412 } else if (ob == bullets_->radio_panel_standard ||
413 ob == bullets_->radio_panel_maths ||
414 ob == bullets_->radio_panel_ding1 ||
415 ob == bullets_->radio_panel_ding2 ||
416 ob == bullets_->radio_panel_ding3 ||
417 ob == bullets_->radio_panel_ding4) {
420 } else if (ob == bullets_->bmtable_panel) {
421 BulletBMTable(ob, 0);
423 } else if (ob == class_->choice_spacing) {
424 setEnabled(class_->input_spacing,
425 fl_get_choice(class_->choice_spacing) == 4);
427 } else if (ob == class_->combox_class) {
429 } else if (ob == class_->radio_skip ||
430 ob == class_->radio_indent ||
431 ob == class_->choice_skip) {
432 bool const skip_used = fl_get_button(class_->radio_skip);
433 setEnabled(class_->choice_skip, skip_used);
435 bool const length_input =
436 fl_get_choice(class_->choice_skip) == 4;
437 setEnabled(class_->input_skip,
438 skip_used && length_input);
439 setEnabled(class_->choice_skip_units,
440 skip_used && length_input);
442 // Default unit choice is cm if metric, inches if US paper.
443 // If papersize is default, check the lyxrc-settings
444 int const paperchoice = fl_get_choice(paper_->choice_papersize);
445 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
446 || paperchoice == 2 || paperchoice > 5;
447 string const default_unit = metric ? "cm" : "in";
448 if (getString(class_->input_skip).empty())
449 fl_set_choice_text(class_->choice_skip_units,
450 default_unit.c_str());
452 } else if (ob == options_->check_use_natbib) {
453 setEnabled(options_->choice_citation_format,
454 fl_get_button(options_->check_use_natbib));
456 } else if (ob == dialog_->button_save_defaults) {
458 controller().saveAsDefault();
460 } else if (ob == dialog_->button_reset_defaults) {
461 BufferParams & params = controller().params();
462 params.textclass = fl_get_combox(class_->combox_class) - 1;
463 params.useClassDefaults();
464 UpdateLayoutDocument(params);
466 } else if (ob == paper_->radio_landscape) {
467 fl_set_choice(paper_->choice_paperpackage,
468 BufferParams::PACKAGE_NONE + 1);
470 } else if (ob == paper_->choice_papersize) {
471 int const paperchoice = fl_get_choice(paper_->choice_papersize);
472 bool const defsize = paperchoice == 1;
473 bool const custom = paperchoice == 2;
474 bool const a3size = paperchoice == 6;
475 bool const b3size = paperchoice == 9;
476 bool const b4size = paperchoice == 10;
479 fl_set_button(paper_->radio_portrait, 1);
481 bool const use_geom = (custom || a3size || b3size || b4size);
483 fl_set_button(paper_->check_use_geometry, int(use_geom));
485 setEnabled(paper_->input_top_margin, use_geom);
486 setEnabled(paper_->input_bottom_margin, use_geom);
487 setEnabled(paper_->input_inner_margin, use_geom);
488 setEnabled(paper_->input_outer_margin, use_geom);
489 setEnabled(paper_->input_head_height, use_geom);
490 setEnabled(paper_->input_head_sep, use_geom);
491 setEnabled(paper_->input_foot_skip, use_geom);
492 setEnabled(paper_->choice_top_margin_units, use_geom);
493 setEnabled(paper_->choice_bottom_margin_units, use_geom);
494 setEnabled(paper_->choice_inner_margin_units, use_geom);
495 setEnabled(paper_->choice_outer_margin_units, use_geom);
496 setEnabled(paper_->choice_head_height_units, use_geom);
497 setEnabled(paper_->choice_head_sep_units, use_geom);
498 setEnabled(paper_->choice_foot_skip_units, use_geom);
499 setEnabled(paper_->choice_custom_width_units, use_geom);
500 setEnabled(paper_->choice_custom_height_units, use_geom);
502 setEnabled(paper_->input_custom_width, custom);
503 setEnabled(paper_->input_custom_height, custom);
504 setEnabled(paper_->choice_custom_width_units, custom);
505 setEnabled(paper_->choice_custom_height_units, custom);
506 setEnabled(paper_->radio_portrait, !custom);
507 setEnabled(paper_->radio_landscape, !custom);
509 // Default unit choice is cm if metric, inches if US paper.
510 // If papersize is default, use the lyxrc-settings
511 bool const metric = (defsize && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
512 || paperchoice == 2 || paperchoice > 5;
513 string const default_unit = metric ? "cm" : "in";
514 if (getString(paper_->input_custom_width).empty())
515 fl_set_choice_text(paper_->choice_custom_width_units,
516 default_unit.c_str());
517 if (getString(paper_->input_custom_height).empty())
518 fl_set_choice_text(paper_->choice_custom_height_units,
519 default_unit.c_str());
520 if (getString(paper_->input_top_margin).empty())
521 fl_set_choice_text(paper_->choice_top_margin_units,
522 default_unit.c_str());
523 if (getString(paper_->input_bottom_margin).empty())
524 fl_set_choice_text(paper_->choice_bottom_margin_units,
525 default_unit.c_str());
526 if (getString(paper_->input_inner_margin).empty())
527 fl_set_choice_text(paper_->choice_inner_margin_units,
528 default_unit.c_str());
529 if (getString(paper_->input_outer_margin).empty())
530 fl_set_choice_text(paper_->choice_outer_margin_units,
531 default_unit.c_str());
532 if (getString(paper_->input_head_height).empty())
533 fl_set_choice_text(paper_->choice_head_height_units,
534 default_unit.c_str());
535 if (getString(paper_->input_head_sep).empty())
536 fl_set_choice_text(paper_->choice_head_sep_units,
537 default_unit.c_str());
538 if (getString(paper_->input_foot_skip).empty())
539 fl_set_choice_text(paper_->choice_foot_skip_units,
540 default_unit.c_str());
542 } else if (ob == paper_->choice_paperpackage &&
543 fl_get_choice(paper_->choice_paperpackage) != 1) {
545 fl_set_button(paper_->check_use_geometry, 0);
546 setEnabled(paper_->input_top_margin, false);
547 setEnabled(paper_->input_bottom_margin, false);
548 setEnabled(paper_->input_inner_margin, false);
549 setEnabled(paper_->input_outer_margin, false);
550 setEnabled(paper_->input_head_height, false);
551 setEnabled(paper_->input_head_sep, false);
552 setEnabled(paper_->input_foot_skip, false);
553 setEnabled(paper_->choice_top_margin_units, false);
554 setEnabled(paper_->choice_bottom_margin_units, false);
555 setEnabled(paper_->choice_inner_margin_units, false);
556 setEnabled(paper_->choice_outer_margin_units, false);
557 setEnabled(paper_->choice_head_height_units, false);
558 setEnabled(paper_->choice_head_sep_units, false);
559 setEnabled(paper_->choice_foot_skip_units, false);
561 } else if (ob == paper_->check_use_geometry) {
562 // don't allow switching geometry off in custom papersize
563 // mode nor in A3, B3, and B4
564 int const choice = fl_get_choice(paper_->choice_papersize);
565 if (choice == 2 || choice == 6 || choice == 9 || choice == 10)
566 fl_set_button(paper_->check_use_geometry, 1);
568 fl_set_choice(paper_->choice_paperpackage,
569 BufferParams::PACKAGE_NONE + 1);
571 bool const use_geom = fl_get_button(paper_->check_use_geometry);
572 setEnabled(paper_->input_top_margin, use_geom);
573 setEnabled(paper_->input_bottom_margin, use_geom);
574 setEnabled(paper_->input_inner_margin, use_geom);
575 setEnabled(paper_->input_outer_margin, use_geom);
576 setEnabled(paper_->input_head_height, use_geom);
577 setEnabled(paper_->input_head_sep, use_geom);
578 setEnabled(paper_->input_foot_skip, use_geom);
579 setEnabled(paper_->choice_top_margin_units, use_geom);
580 setEnabled(paper_->choice_bottom_margin_units, use_geom);
581 setEnabled(paper_->choice_inner_margin_units, use_geom);
582 setEnabled(paper_->choice_outer_margin_units, use_geom);
583 setEnabled(paper_->choice_head_height_units, use_geom);
584 setEnabled(paper_->choice_head_sep_units, use_geom);
585 setEnabled(paper_->choice_foot_skip_units, use_geom);
588 if (ob == paper_->choice_papersize || ob == paper_->radio_portrait
589 || ob == paper_->radio_landscape) {
590 // either default papersize (preferences) or document
591 // papersize has to be A4
592 bool const enable = ( fl_get_choice(paper_->choice_papersize) == 1
593 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER )
594 || fl_get_choice(paper_->choice_papersize) == 7;
596 fl_set_choice(paper_->choice_paperpackage,
597 BufferParams::PACKAGE_NONE + 1);
598 setEnabled(paper_->choice_paperpackage,
599 enable && fl_get_button(paper_->radio_portrait));
602 return ButtonPolicy::SMI_VALID;
606 bool FormDocument::class_apply(BufferParams ¶ms)
610 // If default skip is a "Length" but there's no text in the
611 // input field, reset the kind to "MedSkip", which is the default.
612 if (fl_get_choice(class_->choice_skip) == 4 &&
613 getString(class_->input_skip).empty()) {
614 fl_set_choice(class_->choice_skip, 2);
616 params.fonts = getString(class_->choice_fonts);
617 params.fontsize = getString(class_->choice_fontsize);
618 params.pagestyle = getString(class_->choice_pagestyle);
620 params.textclass = fl_get_combox(class_->combox_class) - 1;
622 BufferParams::PARSEP tmpsep = params.paragraph_separation;
623 if (fl_get_button(class_->radio_indent))
624 params.paragraph_separation = BufferParams::PARSEP_INDENT;
626 params.paragraph_separation = BufferParams::PARSEP_SKIP;
627 if (tmpsep != params.paragraph_separation)
630 VSpace tmpdefskip = params.getDefSkip();
631 switch (fl_get_choice(class_->choice_skip)) {
633 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
636 params.setDefSkip(VSpace(VSpace::MEDSKIP));
639 params.setDefSkip(VSpace(VSpace::BIGSKIP));
643 string const length =
644 getLengthFromWidgets(class_->input_skip,
645 class_->choice_skip_units);
647 params.setDefSkip(VSpace(LyXGlueLength(length)));
651 // DocumentDefskipCB assures that this never happens
652 params.setDefSkip(VSpace(VSpace::MEDSKIP));
655 if (!(tmpdefskip == params.getDefSkip()))
658 if (fl_get_button(class_->radio_columns_two))
662 if (fl_get_button(class_->radio_sides_two))
663 params.sides = LyXTextClass::TwoSides;
665 params.sides = LyXTextClass::OneSide;
667 Spacing tmpSpacing = params.spacing;
668 switch (fl_get_choice(class_->choice_spacing)) {
670 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
671 params.spacing.set(Spacing::Single);
674 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
675 params.spacing.set(Spacing::Onehalf);
678 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
679 params.spacing.set(Spacing::Double);
682 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
683 params.spacing.set(Spacing::Other,
684 getString(class_->input_spacing));
687 if (tmpSpacing != params.spacing)
690 params.options = getString(class_->input_extra);
696 void FormDocument::paper_apply(BufferParams & params)
698 params.papersize2 = BufferParams::VMARGIN_PAPER_TYPE(fl_get_choice(paper_->choice_papersize) - 1);
700 params.paperpackage =
701 BufferParams::PAPER_PACKAGES(fl_get_choice(paper_->choice_paperpackage) - 1);
703 // set params.papersize from params.papersize2 and params.paperpackage
704 params.setPaperStuff();
706 params.use_geometry = fl_get_button(paper_->check_use_geometry);
708 if (fl_get_button(paper_->radio_landscape))
709 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
711 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
714 getLengthFromWidgets(paper_->input_custom_width,
715 paper_->choice_custom_width_units);
718 getLengthFromWidgets(paper_->input_custom_height,
719 paper_->choice_custom_height_units);
722 getLengthFromWidgets(paper_->input_inner_margin,
723 paper_->choice_inner_margin_units);
726 getLengthFromWidgets(paper_->input_top_margin,
727 paper_->choice_top_margin_units);
730 getLengthFromWidgets(paper_->input_outer_margin,
731 paper_->choice_outer_margin_units);
733 params.bottommargin =
734 getLengthFromWidgets(paper_->input_bottom_margin,
735 paper_->choice_bottom_margin_units);
738 getLengthFromWidgets(paper_->input_head_height,
739 paper_->choice_head_height_units);
742 getLengthFromWidgets(paper_->input_head_sep,
743 paper_->choice_head_sep_units);
746 getLengthFromWidgets(paper_->input_foot_skip,
747 paper_->choice_foot_skip_units);
751 bool FormDocument::language_apply(BufferParams & params)
753 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
756 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
758 lga = InsetQuotes::EnglishQ;
761 lga = InsetQuotes::SwedishQ;
764 lga = InsetQuotes::GermanQ;
767 lga = InsetQuotes::PolishQ;
770 lga = InsetQuotes::FrenchQ;
773 lga = InsetQuotes::DanishQ;
776 params.quotes_language = lga;
777 if (fl_get_button(language_->radio_single))
778 params.quotes_times = InsetQuotes::SingleQ;
780 params.quotes_times = InsetQuotes::DoubleQ;
782 int const pos = fl_get_combox(language_->combox_language);
783 Language const * new_language = languages.getLanguage(lang_[pos-1]);
785 new_language = default_language;
787 params.language = new_language;
788 params.inputenc = getString(language_->choice_inputenc);
794 bool FormDocument::options_apply(BufferParams & params)
798 params.graphicsDriver = getString(options_->choice_postscript_driver);
799 params.use_amsmath = static_cast<BufferParams::AMS>(
800 fl_get_choice(options_->choice_ams_math) - 1);
801 params.use_natbib = fl_get_button(options_->check_use_natbib);
802 params.use_numerical_citations =
803 fl_get_choice(options_->choice_citation_format) - 1;
805 int tmpchar = int(fl_get_counter_value(options_->counter_secnumdepth));
806 if (params.secnumdepth != tmpchar)
808 params.secnumdepth = tmpchar;
810 params.tocdepth = int(fl_get_counter_value(options_->counter_tocdepth));
812 params.float_placement =
813 getString(options_->input_float_placement);
819 void FormDocument::bullets_apply(BufferParams & params)
821 /* update the bullet settings */
822 BufferParams & buf_params = controller().params();
824 for (int i = 0; i < 4; ++i) {
825 params.user_defined_bullets[i] = buf_params.temp_bullets[i];
830 void FormDocument::UpdateClassParams(BufferParams const & params)
832 // These are the params that have to be updated on any class change
833 // (even if the class defaults are not used) (JSpitzm 2002-04-08)
835 LyXTextClass const & tclass = textclasslist[params.textclass];
837 fl_set_combox(class_->combox_class, params.textclass + 1);
838 fl_clear_choice(class_->choice_fontsize);
839 fl_addto_choice(class_->choice_fontsize, "default");
840 fl_addto_choice(class_->choice_fontsize,
841 tclass.opt_fontsize().c_str());
842 fl_set_choice_text(class_->choice_fontsize,
843 params.fontsize.c_str());
844 fl_clear_choice(class_->choice_pagestyle);
845 fl_addto_choice(class_->choice_pagestyle, "default");
846 fl_addto_choice(class_->choice_pagestyle,
847 tclass.opt_pagestyle().c_str());
848 fl_set_choice_text(class_->choice_pagestyle,
849 params.pagestyle.c_str());
853 void FormDocument::class_update(BufferParams const & params)
858 UpdateClassParams(params);
860 fl_set_choice_text(class_->choice_fonts, params.fonts.c_str());
862 bool const indent = params.paragraph_separation == BufferParams::PARSEP_INDENT;
863 fl_set_button(class_->radio_indent, indent);
864 fl_set_button(class_->radio_skip, !indent);
868 pos = 2; // VSpace::MEDSKIP is default
870 switch (params.getDefSkip().kind()) {
874 case VSpace::BIGSKIP:
877 case VSpace::SMALLSKIP:
880 case VSpace::MEDSKIP:
886 fl_set_choice (class_->choice_skip, pos);
888 bool const length_input = pos == 4;
890 int const paperchoice = fl_get_choice(paper_->choice_papersize);
891 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
892 || paperchoice == 2 || paperchoice > 5;
893 string const default_unit = metric ? "cm" : "in";
894 string const length = params.getDefSkip().asLyXCommand();
895 updateWidgetsFromLengthString(class_->input_skip,
896 class_->choice_skip_units,
897 length, default_unit);
900 fl_set_input(class_->input_skip, "");
902 setEnabled(class_->choice_skip, !indent);
903 setEnabled(class_->input_skip, length_input);
904 setEnabled(class_->choice_skip_units, length_input);
906 bool const two_sides = params.sides == LyXTextClass::TwoSides;
907 fl_set_button(class_->radio_sides_one, !two_sides);
908 fl_set_button(class_->radio_sides_two, two_sides);
910 bool const two_columns = params.columns == 2;
911 fl_set_button(class_->radio_columns_one, !two_columns);
912 fl_set_button(class_->radio_columns_two, two_columns);
914 fl_set_input(class_->input_extra, params.options.c_str());
916 switch (params.spacing.getSpace()) {
920 case Spacing::Double: // \doublespacing
923 case Spacing::Onehalf: // \onehalfspacing
926 case Spacing::Single: // \singlespacing
927 case Spacing::Default: // nothing bad should happen with this
932 fl_set_choice(class_->choice_spacing, pos);
934 bool const spacing_input = pos == 4;
935 setEnabled(class_->input_spacing, spacing_input);
936 string const input = spacing_input ? tostr(params.spacing.getValue()) : string();
937 fl_set_input(class_->input_spacing, input.c_str());
941 void FormDocument::language_update(BufferParams const & params)
943 if (!language_.get())
946 int const pos = int(findPos(lang_, params.language->lang()));
947 fl_set_combox(language_->combox_language, pos+1);
949 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
950 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
951 fl_set_button(language_->radio_single, 0);
952 fl_set_button(language_->radio_double, 0);
953 if (params.quotes_times == InsetQuotes::SingleQ)
954 fl_set_button(language_->radio_single, 1);
956 fl_set_button(language_->radio_double, 1);
960 void FormDocument::options_update(BufferParams const & params)
965 fl_set_choice_text(options_->choice_postscript_driver,
966 params.graphicsDriver.c_str());
967 fl_set_choice(options_->choice_ams_math, params.use_amsmath + 1);
968 fl_set_button(options_->check_use_natbib, params.use_natbib);
969 fl_set_choice(options_->choice_citation_format,
970 int(params.use_numerical_citations)+1);
971 setEnabled(options_->choice_citation_format, params.use_natbib);
972 fl_set_counter_value(options_->counter_secnumdepth, params.secnumdepth);
973 fl_set_counter_value(options_->counter_tocdepth, params.tocdepth);
974 if (!params.float_placement.empty())
975 fl_set_input(options_->input_float_placement,
976 params.float_placement.c_str());
978 fl_set_input(options_->input_float_placement, "");
982 void FormDocument::paper_update(BufferParams const & params)
987 fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
988 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
989 fl_set_button(paper_->check_use_geometry, params.use_geometry);
991 int const paperchoice = fl_get_choice(paper_->choice_papersize);
992 bool const useCustom = paperchoice == 2;
993 bool const useGeom = fl_get_button(paper_->check_use_geometry);
995 fl_set_button(paper_->radio_portrait, 0);
996 setEnabled(paper_->radio_portrait, !useCustom);
997 fl_set_button(paper_->radio_landscape, 0);
998 setEnabled(paper_->radio_landscape, !useCustom);
1000 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1001 fl_set_button(paper_->radio_landscape, 1);
1003 fl_set_button(paper_->radio_portrait, 1);
1004 setEnabled(paper_->choice_paperpackage,
1005 //either default papersize (preferences)
1006 //or document papersize has to be A4
1008 || paperchoice == 1 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER)
1009 && fl_get_button(paper_->radio_portrait));
1011 // Default unit choice is cm if metric, inches if US paper.
1012 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
1013 || paperchoice == 2 || paperchoice > 5;
1014 string const default_unit = metric ? "cm" : "in";
1015 updateWidgetsFromLengthString(paper_->input_custom_width,
1016 paper_->choice_custom_width_units,
1017 params.paperwidth, default_unit);
1018 setEnabled(paper_->input_custom_width, useCustom);
1019 setEnabled(paper_->choice_custom_width_units, useCustom);
1021 updateWidgetsFromLengthString(paper_->input_custom_height,
1022 paper_->choice_custom_height_units,
1023 params.paperheight, default_unit);
1024 setEnabled(paper_->input_custom_height, useCustom);
1025 setEnabled(paper_->choice_custom_height_units, useCustom);
1027 updateWidgetsFromLengthString(paper_->input_inner_margin,
1028 paper_->choice_inner_margin_units,
1029 params.leftmargin, default_unit);
1030 setEnabled(paper_->input_inner_margin, useGeom);
1031 setEnabled(paper_->choice_inner_margin_units, useGeom);
1033 updateWidgetsFromLengthString(paper_->input_top_margin,
1034 paper_->choice_top_margin_units,
1035 params.topmargin, default_unit);
1036 setEnabled(paper_->input_top_margin, useGeom);
1037 setEnabled(paper_->choice_top_margin_units, useGeom);
1039 updateWidgetsFromLengthString(paper_->input_outer_margin,
1040 paper_->choice_outer_margin_units,
1041 params.rightmargin, default_unit);
1042 setEnabled(paper_->input_outer_margin, useGeom);
1043 setEnabled(paper_->choice_outer_margin_units, useGeom);
1045 updateWidgetsFromLengthString(paper_->input_bottom_margin,
1046 paper_->choice_bottom_margin_units,
1047 params.bottommargin, default_unit);
1048 setEnabled(paper_->input_bottom_margin, useGeom);
1049 setEnabled(paper_->choice_bottom_margin_units, useGeom);
1051 updateWidgetsFromLengthString(paper_->input_head_height,
1052 paper_->choice_head_height_units,
1053 params.headheight, default_unit);
1054 setEnabled(paper_->input_head_height, useGeom);
1055 setEnabled(paper_->choice_head_height_units, useGeom);
1057 updateWidgetsFromLengthString(paper_->input_head_sep,
1058 paper_->choice_head_sep_units,
1059 params.headsep, default_unit);
1060 setEnabled(paper_->input_head_sep, useGeom);
1061 setEnabled(paper_->choice_head_sep_units, useGeom);
1063 updateWidgetsFromLengthString(paper_->input_foot_skip,
1064 paper_->choice_foot_skip_units,
1065 params.footskip, default_unit);
1066 setEnabled(paper_->input_foot_skip, useGeom);
1067 setEnabled(paper_->choice_foot_skip_units, useGeom);
1069 fl_set_focus_object(paper_->form, paper_->choice_papersize);
1073 void FormDocument::bullets_update(BufferParams const & params)
1075 if (!bullets_.get() ||
1077 (XpmVersion==4 && XpmRevision<7)))
1080 bool const isLinuxDoc =
1081 controller().docType() == ControlDocument::LINUXDOC;
1082 setEnabled(fbullet, !isLinuxDoc);
1084 if (isLinuxDoc) return;
1086 fl_set_button(bullets_->radio_depth_1, 1);
1087 fl_set_input(bullets_->input_latex,
1088 params.user_defined_bullets[0].getText().c_str());
1089 fl_set_choice(bullets_->choice_size,
1090 params.user_defined_bullets[0].getSize() + 2);
1094 void FormDocument::checkReadOnly()
1096 if (bc().readOnly(controller().bufferIsReadonly())) {
1097 postWarning(_("Document is read-only."
1098 " No changes to layout permitted."));
1105 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/)
1107 BufferParams & param = controller().params();
1109 // convert from 1-6 range to -1-4
1110 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1111 fl_set_input(bullets_->input_latex,
1112 param.temp_bullets[current_bullet_depth].getText().c_str());
1116 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1118 BufferParams & param = controller().params();
1120 param.temp_bullets[current_bullet_depth].
1121 setText(getString(bullets_->input_latex));
1125 void FormDocument::BulletDepth(FL_OBJECT * ob)
1127 /* Should I do the following: */
1128 /* 1. change to the panel that the current bullet belongs in */
1129 /* 2. show that bullet as selected */
1130 /* 3. change the size setting to the size of the bullet in Q.*/
1131 /* 4. display the latex equivalent in the latex box */
1133 /* I'm inclined to just go with 3 and 4 at the moment and */
1134 /* maybe try to support the others later */
1135 BufferParams & param = controller().params();
1138 if (ob == bullets_->radio_depth_1)
1140 else if (ob == bullets_->radio_depth_2)
1142 else if (ob == bullets_->radio_depth_3)
1144 else if (ob == bullets_->radio_depth_4)
1147 switch (fl_get_button_numb(ob)) {
1149 // right mouse button resets to default
1150 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1152 current_bullet_depth = data;
1153 fl_set_input(bullets_->input_latex,
1154 param.temp_bullets[data].getText().c_str());
1155 fl_set_choice(bullets_->choice_size,
1156 param.temp_bullets[data].getSize() + 2);
1161 void FormDocument::BulletPanel(FL_OBJECT * ob)
1163 /* Here we have to change the background pixmap to that selected */
1164 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1167 if (ob == bullets_->radio_panel_standard)
1169 else if (ob == bullets_->radio_panel_maths)
1171 else if (ob == bullets_->radio_panel_ding2)
1173 else if (ob == bullets_->radio_panel_ding3)
1175 else if (ob == bullets_->radio_panel_ding4)
1177 else if (ob == bullets_->radio_panel_ding1)
1180 if (data != current_bullet_panel) {
1181 fl_freeze_form(bullets_->form);
1182 current_bullet_panel = data;
1184 /* free the current pixmap */
1185 fl_free_bmtable_pixmap(bullets_->bmtable_panel);
1187 if (ob == bullets_->radio_panel_standard) {
1188 new_panel = "standard";
1189 } else if (ob == bullets_->radio_panel_maths ) {
1190 new_panel = "amssymb";
1191 } else if (ob == bullets_->radio_panel_ding2) {
1192 new_panel = "psnfss1";
1193 } else if (ob == bullets_->radio_panel_ding3) {
1194 new_panel = "psnfss2";
1195 } else if (ob == bullets_->radio_panel_ding4) {
1196 new_panel = "psnfss3";
1197 } else if (ob == bullets_->radio_panel_ding1) {
1198 new_panel = "psnfss4";
1200 /* something very wrong happened */
1201 // play it safe for now but should be an exception
1202 current_bullet_panel = 0; // standard panel
1203 new_panel = "standard";
1205 new_panel += ".xpm";
1206 fl_set_bmtable_pixmap_file(bullets_->bmtable_panel, 6, 6,
1207 LibFileSearch("images", new_panel).c_str());
1208 fl_redraw_object(bullets_->bmtable_panel);
1209 fl_unfreeze_form(bullets_->form);
1214 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/)
1216 /* handle the user input by setting the current bullet depth's pixmap */
1217 /* to that extracted from the current chosen position of the BMTable */
1218 /* Don't forget to free the button's old pixmap first. */
1220 BufferParams & param = controller().params();
1221 int bmtable_button = fl_get_bmtable(ob);
1223 /* try to keep the button held down till another is pushed */
1224 /* fl_set_bmtable(ob, 1, bmtable_button); */
1225 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1226 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1227 fl_set_input(bullets_->input_latex,
1228 param.temp_bullets[current_bullet_depth].getText().c_str());
1232 void FormDocument::CheckChoiceClass()
1234 BufferParams & params = controller().params();
1236 lyx::textclass_type const tc =
1237 fl_get_combox(class_->combox_class) - 1;
1239 if (controller().loadTextclass(tc)) {
1240 params.textclass = tc;
1242 if (lyxrc.auto_reset_options) {
1243 params.useClassDefaults();
1244 UpdateLayoutDocument(params);
1246 // update the params which are needed in any case
1247 // (fontsizes, pagestyle)
1248 UpdateClassParams(params);
1252 int const revert = int(params.textclass);
1253 fl_set_combox(class_->combox_class, revert + 1);
1258 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1264 class_update(params);
1265 paper_update(params);
1266 language_update(params);
1267 options_update(params);
1268 bullets_update(params);