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
15 #include "ControlDocument.h"
16 #include "FormDocument.h"
17 #include "forms/form_document.h"
19 #include "ButtonController.h"
22 #include "checkedwidgets.h"
23 #include "input_validators.h" // fl_unsigned_float_filter
24 #include "xforms_helpers.h"
26 #include "CutAndPaste.h"
30 #include "lyxtextclasslist.h"
31 #include "tex-strings.h"
33 #include "controllers/frnt_lang.h"
34 #include "controllers/helper_funcs.h"
36 #include "support/lstrings.h" // contains_functor, getStringFromVector
37 #include "support/filetools.h" // LibFileSearch
39 #include XPM_H_LOCATION
40 #include FORMS_H_LOCATION
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 fl_addto_combox(obj, tit->description().c_str());
140 fl_set_combox_browser_height(obj, 400);
142 fl_addto_choice(class_->choice_spacing,
143 _(" Single | OneHalf | Double | Custom "));
144 fl_addto_choice(class_->choice_fontsize, "default|10|11|12");
145 for (int n = 0; tex_fonts[n][0]; ++n) {
146 fl_addto_choice(class_->choice_fonts,tex_fonts[n]);
149 // Create the contents of the unit choices; don't include the
151 vector<string> units_vec = getLatexUnits();
152 vector<string>::iterator ret =
153 std::remove_if(units_vec.begin(),
155 bind2nd(contains_functor(), "%"));
156 units_vec.erase(ret, units_vec.end());
158 string const units = getStringFromVector(units_vec, "|");
160 fl_addto_choice(class_->choice_pagestyle,
161 "default|empty|plain|headings|fancy");
162 fl_addto_choice(class_->choice_skip,
163 _(" SmallSkip | MedSkip | BigSkip | Length "));
164 fl_addto_choice(class_->choice_skip_units, units.c_str());
166 // Set input filters on doc spacing to make it accept only
168 fl_set_input_filter(class_->input_spacing,
169 fl_unsigned_float_filter);
171 // disable for read-only documents
172 bcview().addReadOnly(dialog_->button_save_defaults);
173 bcview().addReadOnly(dialog_->button_reset_defaults);
175 // the document paper form
176 paper_.reset(build_document_paper(this));
178 // disable for read-only documents
179 bcview().addReadOnly(paper_->choice_paperpackage);
180 bcview().addReadOnly(paper_->radio_portrait);
181 bcview().addReadOnly(paper_->radio_landscape);
182 bcview().addReadOnly(paper_->choice_papersize);
183 bcview().addReadOnly(paper_->check_use_geometry);
184 bcview().addReadOnly(paper_->input_custom_width);
185 bcview().addReadOnly(paper_->input_custom_height);
186 bcview().addReadOnly(paper_->input_top_margin);
187 bcview().addReadOnly(paper_->input_bottom_margin);
188 bcview().addReadOnly(paper_->input_inner_margin);
189 bcview().addReadOnly(paper_->input_outer_margin);
190 bcview().addReadOnly(paper_->input_head_height);
191 bcview().addReadOnly(paper_->input_head_sep);
192 bcview().addReadOnly(paper_->input_foot_skip);
194 // check validity of "length + unit" input
195 addCheckedGlueLength(bcview(), paper_->input_custom_width);
196 addCheckedGlueLength(bcview(), paper_->input_custom_height);
197 addCheckedGlueLength(bcview(), paper_->input_top_margin);
198 addCheckedGlueLength(bcview(), paper_->input_bottom_margin);
199 addCheckedGlueLength(bcview(), paper_->input_inner_margin);
200 addCheckedGlueLength(bcview(), paper_->input_outer_margin);
201 addCheckedGlueLength(bcview(), paper_->input_head_height);
202 addCheckedGlueLength(bcview(), paper_->input_head_sep);
203 addCheckedGlueLength(bcview(), paper_->input_foot_skip);
205 // trigger an input event for cut&paste with middle mouse button.
206 setPrehandler(paper_->input_custom_width);
207 setPrehandler(paper_->input_custom_height);
208 setPrehandler(paper_->input_top_margin);
209 setPrehandler(paper_->input_bottom_margin);
210 setPrehandler(paper_->input_inner_margin);
211 setPrehandler(paper_->input_outer_margin);
212 setPrehandler(paper_->input_head_height);
213 setPrehandler(paper_->input_head_sep);
214 setPrehandler(paper_->input_foot_skip);
216 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
217 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
218 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
219 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
220 fl_set_input_return(paper_->input_inner_margin, FL_RETURN_CHANGED);
221 fl_set_input_return(paper_->input_outer_margin, FL_RETURN_CHANGED);
222 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
223 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
224 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
226 fl_addto_choice(paper_->choice_papersize,
227 _(" Default | Custom | US letter | US legal "
228 "| US executive | A3 | A4 | A5 | B3 | B4 | B5 "));
229 fl_addto_choice(paper_->choice_paperpackage,
232 "| Very small Margins "
233 "| Very wide Margins "));
235 fl_addto_choice(paper_->choice_custom_width_units, units.c_str());
236 fl_addto_choice(paper_->choice_custom_height_units, units.c_str());
237 fl_addto_choice(paper_->choice_top_margin_units, units.c_str());
238 fl_addto_choice(paper_->choice_bottom_margin_units, units.c_str());
239 fl_addto_choice(paper_->choice_inner_margin_units, units.c_str());
240 fl_addto_choice(paper_->choice_outer_margin_units, units.c_str());
241 fl_addto_choice(paper_->choice_head_height_units, units.c_str());
242 fl_addto_choice(paper_->choice_head_sep_units, units.c_str());
243 fl_addto_choice(paper_->choice_foot_skip_units, units.c_str());
245 // the document language form
246 language_.reset(build_document_language(this));
248 // disable for read-only documents
249 bcview().addReadOnly(language_->combox_language);
250 bcview().addReadOnly(language_->choice_inputenc);
251 bcview().addReadOnly(language_->choice_quotes_language);
252 bcview().addReadOnly(language_->radio_single);
253 bcview().addReadOnly(language_->radio_double);
255 fl_addto_choice(language_->choice_inputenc,
256 "default|auto|latin1|latin2|latin3|latin4|latin5|latin9"
257 "|koi8-r|koi8-u|cp866|cp1251|iso88595|pt154");
259 vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
260 // Store the identifiers for later
261 lang_ = getSecond(langs);
263 vector<frnt::LanguagePair>::const_iterator lit = langs.begin();
264 vector<frnt::LanguagePair>::const_iterator lend = langs.end();
265 for (; lit != lend; ++lit) {
266 fl_addto_combox(language_->combox_language,
269 fl_set_combox_browser_height(language_->combox_language, 400);
271 fl_addto_choice(language_->choice_quotes_language,
272 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
273 " «text» | »text« "));
275 // the document options form
276 options_.reset(build_document_options(this));
278 // disable for read-only documents
279 bcview().addReadOnly(options_->counter_secnumdepth);
280 bcview().addReadOnly(options_->counter_tocdepth);
281 bcview().addReadOnly(options_->choice_ams_math);
282 bcview().addReadOnly(options_->check_use_natbib);
283 bcview().addReadOnly(options_->choice_citation_format);
284 bcview().addReadOnly(options_->input_float_placement);
285 bcview().addReadOnly(options_->choice_postscript_driver);
287 // trigger an input event for cut&paste with middle mouse button.
288 setPrehandler(options_->input_float_placement);
290 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
292 fl_addto_choice(options_->choice_ams_math,
293 _("Never | Automatically | Yes "));
295 for (int n = 0; tex_graphics[n][0]; ++n) {
296 fl_addto_choice(options_->choice_postscript_driver,
299 fl_addto_choice(options_->choice_citation_format,
300 _(" Author-year | Numerical "));
302 // the document bullets form
303 bullets_.reset(build_document_bullet(this));
305 // disable for read-only documents
306 bcview().addReadOnly(bullets_->radio_depth_1);
307 bcview().addReadOnly(bullets_->radio_depth_2);
308 bcview().addReadOnly(bullets_->radio_depth_3);
309 bcview().addReadOnly(bullets_->radio_depth_4);
310 bcview().addReadOnly(bullets_->radio_panel_standard);
311 bcview().addReadOnly(bullets_->radio_panel_maths);
312 bcview().addReadOnly(bullets_->radio_panel_ding1);
313 bcview().addReadOnly(bullets_->radio_panel_ding2);
314 bcview().addReadOnly(bullets_->radio_panel_ding3);
315 bcview().addReadOnly(bullets_->radio_panel_ding4);
316 bcview().addReadOnly(bullets_->bmtable_panel);
317 bcview().addReadOnly(bullets_->choice_size);
318 bcview().addReadOnly(bullets_->input_latex);
320 // trigger an input event for cut&paste with middle mouse button.
321 setPrehandler(bullets_->input_latex);
323 fl_set_input_return(bullets_->input_latex, FL_RETURN_CHANGED);
325 fl_addto_choice(bullets_->choice_size,
326 _(" Default | Tiny | Smallest | Smaller | Small |"
327 " Normal | Large | Larger | Largest | Huge | Huger "));
328 fl_set_choice(bullets_->choice_size, 1);
330 fl_set_input_maxchars(bullets_->input_latex, 80);
332 string const bmtablefile = LibFileSearch("images", "standard", "xpm");
333 fl_set_bmtable_pixmap_file(bullets_->bmtable_panel, 6, 6,
334 bmtablefile.c_str());
336 // Enable the tabfolder to be rescaled correctly.
337 if (scalableTabfolders)
338 fl_set_tabfolder_autofit(dialog_->tabfolder, FL_FIT);
341 fl_addto_tabfolder(dialog_->tabfolder,_("Document"),
343 fl_addto_tabfolder(dialog_->tabfolder,_("Paper"),
345 fl_addto_tabfolder(dialog_->tabfolder,_("Language"),
347 fl_addto_tabfolder(dialog_->tabfolder,_("Extra"),
349 fbullet = fl_addto_tabfolder(dialog_->tabfolder,_("Bullets"),
352 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
353 lyxerr << _("Your version of libXpm is older than 4.7.\n"
354 "The `bullet' tab of the document dialog "
355 "has been disabled") << '\n';
356 fl_deactivate_object(fbullet);
357 fl_set_object_lcol(fbullet, FL_INACTIVE);
362 void FormDocument::apply()
364 BufferParams & params = controller().params();
368 language_apply(params);
369 options_apply(params);
370 bullets_apply(params);
374 void FormDocument::update()
381 BufferParams const & params = controller().params();
383 class_update(params);
384 paper_update(params);
385 language_update(params);
386 options_update(params);
387 bullets_update(params);
391 ButtonPolicy::SMInput FormDocument::input(FL_OBJECT * ob, long)
393 if (ob == bullets_->choice_size) {
394 ChoiceBulletSize(ob, 0);
396 } else if (ob == bullets_->input_latex) {
397 InputBulletLaTeX(ob, 0);
399 } else if (ob == bullets_->radio_depth_1 ||
400 ob == bullets_->radio_depth_2 ||
401 ob == bullets_->radio_depth_3 ||
402 ob == bullets_->radio_depth_4) {
405 } else if (ob == bullets_->radio_panel_standard ||
406 ob == bullets_->radio_panel_maths ||
407 ob == bullets_->radio_panel_ding1 ||
408 ob == bullets_->radio_panel_ding2 ||
409 ob == bullets_->radio_panel_ding3 ||
410 ob == bullets_->radio_panel_ding4) {
413 } else if (ob == bullets_->bmtable_panel) {
414 BulletBMTable(ob, 0);
416 } else if (ob == class_->choice_spacing) {
417 setEnabled(class_->input_spacing,
418 fl_get_choice(class_->choice_spacing) == 4);
420 } else if (ob == class_->combox_class) {
422 } else if (ob == class_->radio_skip ||
423 ob == class_->radio_indent ||
424 ob == class_->choice_skip) {
425 bool const skip_used = fl_get_button(class_->radio_skip);
426 setEnabled(class_->choice_skip, skip_used);
428 bool const length_input =
429 fl_get_choice(class_->choice_skip) == 4;
430 setEnabled(class_->input_skip,
431 skip_used && length_input);
432 setEnabled(class_->choice_skip_units,
433 skip_used && length_input);
435 // Default unit choice is cm if metric, inches if US paper.
436 // If papersize is default, check the lyxrc-settings
437 int const paperchoice = fl_get_choice(paper_->choice_papersize);
438 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
439 || paperchoice == 2 || paperchoice > 5;
440 string const default_unit = metric ? "cm" : "in";
441 if (getString(class_->input_skip).empty())
442 fl_set_choice_text(class_->choice_skip_units,
443 default_unit.c_str());
445 } else if (ob == options_->check_use_natbib) {
446 setEnabled(options_->choice_citation_format,
447 fl_get_button(options_->check_use_natbib));
449 } else if (ob == dialog_->button_save_defaults) {
451 controller().saveAsDefault();
453 } else if (ob == dialog_->button_reset_defaults) {
454 BufferParams & params = controller().params();
455 params.textclass = fl_get_combox(class_->combox_class) - 1;
456 params.useClassDefaults();
457 UpdateLayoutDocument(params);
459 } else if (ob == paper_->radio_landscape) {
460 fl_set_choice(paper_->choice_paperpackage,
461 BufferParams::PACKAGE_NONE + 1);
463 } else if (ob == paper_->choice_papersize) {
464 int const paperchoice = fl_get_choice(paper_->choice_papersize);
465 bool const defsize = paperchoice == 1;
466 bool const custom = paperchoice == 2;
467 bool const a3size = paperchoice == 6;
468 bool const b3size = paperchoice == 9;
469 bool const b4size = paperchoice == 10;
472 fl_set_button(paper_->radio_portrait, 1);
474 bool const use_geom = (custom || a3size || b3size || b4size);
476 fl_set_button(paper_->check_use_geometry, int(use_geom));
478 setEnabled(paper_->input_top_margin, use_geom);
479 setEnabled(paper_->input_bottom_margin, use_geom);
480 setEnabled(paper_->input_inner_margin, use_geom);
481 setEnabled(paper_->input_outer_margin, use_geom);
482 setEnabled(paper_->input_head_height, use_geom);
483 setEnabled(paper_->input_head_sep, use_geom);
484 setEnabled(paper_->input_foot_skip, use_geom);
485 setEnabled(paper_->choice_top_margin_units, use_geom);
486 setEnabled(paper_->choice_bottom_margin_units, use_geom);
487 setEnabled(paper_->choice_inner_margin_units, use_geom);
488 setEnabled(paper_->choice_outer_margin_units, use_geom);
489 setEnabled(paper_->choice_head_height_units, use_geom);
490 setEnabled(paper_->choice_head_sep_units, use_geom);
491 setEnabled(paper_->choice_foot_skip_units, use_geom);
492 setEnabled(paper_->choice_custom_width_units, use_geom);
493 setEnabled(paper_->choice_custom_height_units, use_geom);
495 setEnabled(paper_->input_custom_width, custom);
496 setEnabled(paper_->input_custom_height, custom);
497 setEnabled(paper_->choice_custom_width_units, custom);
498 setEnabled(paper_->choice_custom_height_units, custom);
499 setEnabled(paper_->radio_portrait, !custom);
500 setEnabled(paper_->radio_landscape, !custom);
502 // Default unit choice is cm if metric, inches if US paper.
503 // If papersize is default, use the lyxrc-settings
504 bool const metric = (defsize && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
505 || paperchoice == 2 || paperchoice > 5;
506 string const default_unit = metric ? "cm" : "in";
507 if (getString(paper_->input_custom_width).empty())
508 fl_set_choice_text(paper_->choice_custom_width_units,
509 default_unit.c_str());
510 if (getString(paper_->input_custom_height).empty())
511 fl_set_choice_text(paper_->choice_custom_height_units,
512 default_unit.c_str());
513 if (getString(paper_->input_top_margin).empty())
514 fl_set_choice_text(paper_->choice_top_margin_units,
515 default_unit.c_str());
516 if (getString(paper_->input_bottom_margin).empty())
517 fl_set_choice_text(paper_->choice_bottom_margin_units,
518 default_unit.c_str());
519 if (getString(paper_->input_inner_margin).empty())
520 fl_set_choice_text(paper_->choice_inner_margin_units,
521 default_unit.c_str());
522 if (getString(paper_->input_outer_margin).empty())
523 fl_set_choice_text(paper_->choice_outer_margin_units,
524 default_unit.c_str());
525 if (getString(paper_->input_head_height).empty())
526 fl_set_choice_text(paper_->choice_head_height_units,
527 default_unit.c_str());
528 if (getString(paper_->input_head_sep).empty())
529 fl_set_choice_text(paper_->choice_head_sep_units,
530 default_unit.c_str());
531 if (getString(paper_->input_foot_skip).empty())
532 fl_set_choice_text(paper_->choice_foot_skip_units,
533 default_unit.c_str());
535 } else if (ob == paper_->choice_paperpackage &&
536 fl_get_choice(paper_->choice_paperpackage) != 1) {
538 fl_set_button(paper_->check_use_geometry, 0);
539 setEnabled(paper_->input_top_margin, false);
540 setEnabled(paper_->input_bottom_margin, false);
541 setEnabled(paper_->input_inner_margin, false);
542 setEnabled(paper_->input_outer_margin, false);
543 setEnabled(paper_->input_head_height, false);
544 setEnabled(paper_->input_head_sep, false);
545 setEnabled(paper_->input_foot_skip, false);
546 setEnabled(paper_->choice_top_margin_units, false);
547 setEnabled(paper_->choice_bottom_margin_units, false);
548 setEnabled(paper_->choice_inner_margin_units, false);
549 setEnabled(paper_->choice_outer_margin_units, false);
550 setEnabled(paper_->choice_head_height_units, false);
551 setEnabled(paper_->choice_head_sep_units, false);
552 setEnabled(paper_->choice_foot_skip_units, false);
554 } else if (ob == paper_->check_use_geometry) {
555 // don't allow switching geometry off in custom papersize
556 // mode nor in A3, B3, and B4
557 int const choice = fl_get_choice(paper_->choice_papersize);
558 if (choice == 2 || choice == 6 || choice == 9 || choice == 10)
559 fl_set_button(paper_->check_use_geometry, 1);
561 fl_set_choice(paper_->choice_paperpackage,
562 BufferParams::PACKAGE_NONE + 1);
564 bool const use_geom = fl_get_button(paper_->check_use_geometry);
565 setEnabled(paper_->input_top_margin, use_geom);
566 setEnabled(paper_->input_bottom_margin, use_geom);
567 setEnabled(paper_->input_inner_margin, use_geom);
568 setEnabled(paper_->input_outer_margin, use_geom);
569 setEnabled(paper_->input_head_height, use_geom);
570 setEnabled(paper_->input_head_sep, use_geom);
571 setEnabled(paper_->input_foot_skip, use_geom);
572 setEnabled(paper_->choice_top_margin_units, use_geom);
573 setEnabled(paper_->choice_bottom_margin_units, use_geom);
574 setEnabled(paper_->choice_inner_margin_units, use_geom);
575 setEnabled(paper_->choice_outer_margin_units, use_geom);
576 setEnabled(paper_->choice_head_height_units, use_geom);
577 setEnabled(paper_->choice_head_sep_units, use_geom);
578 setEnabled(paper_->choice_foot_skip_units, use_geom);
581 if (ob == paper_->choice_papersize || ob == paper_->radio_portrait
582 || ob == paper_->radio_landscape) {
583 // either default papersize (preferences) or document
584 // papersize has to be A4
585 bool const enable = ( fl_get_choice(paper_->choice_papersize) == 1
586 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER )
587 || fl_get_choice(paper_->choice_papersize) == 7;
589 fl_set_choice(paper_->choice_paperpackage,
590 BufferParams::PACKAGE_NONE + 1);
591 setEnabled(paper_->choice_paperpackage,
592 enable && fl_get_button(paper_->radio_portrait));
595 return ButtonPolicy::SMI_VALID;
599 bool FormDocument::class_apply(BufferParams ¶ms)
603 // If default skip is a "Length" but there's no text in the
604 // input field, reset the kind to "MedSkip", which is the default.
605 if (fl_get_choice(class_->choice_skip) == 4 &&
606 getString(class_->input_skip).empty()) {
607 fl_set_choice(class_->choice_skip, 2);
609 params.fonts = getString(class_->choice_fonts);
610 params.fontsize = getString(class_->choice_fontsize);
611 params.pagestyle = getString(class_->choice_pagestyle);
613 params.textclass = fl_get_combox(class_->combox_class) - 1;
615 BufferParams::PARSEP tmpsep = params.paragraph_separation;
616 if (fl_get_button(class_->radio_indent))
617 params.paragraph_separation = BufferParams::PARSEP_INDENT;
619 params.paragraph_separation = BufferParams::PARSEP_SKIP;
620 if (tmpsep != params.paragraph_separation)
623 VSpace tmpdefskip = params.getDefSkip();
624 switch (fl_get_choice(class_->choice_skip)) {
626 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
629 params.setDefSkip(VSpace(VSpace::MEDSKIP));
632 params.setDefSkip(VSpace(VSpace::BIGSKIP));
636 string const length =
637 getLengthFromWidgets(class_->input_skip,
638 class_->choice_skip_units);
640 params.setDefSkip(VSpace(LyXGlueLength(length)));
644 // DocumentDefskipCB assures that this never happens
645 params.setDefSkip(VSpace(VSpace::MEDSKIP));
648 if (!(tmpdefskip == params.getDefSkip()))
651 if (fl_get_button(class_->radio_columns_two))
655 if (fl_get_button(class_->radio_sides_two))
656 params.sides = LyXTextClass::TwoSides;
658 params.sides = LyXTextClass::OneSide;
660 Spacing tmpSpacing = params.spacing;
661 switch (fl_get_choice(class_->choice_spacing)) {
663 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
664 params.spacing.set(Spacing::Single);
667 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
668 params.spacing.set(Spacing::Onehalf);
671 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
672 params.spacing.set(Spacing::Double);
675 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
676 params.spacing.set(Spacing::Other,
677 getString(class_->input_spacing));
680 if (tmpSpacing != params.spacing)
683 params.options = getString(class_->input_extra);
689 void FormDocument::paper_apply(BufferParams & params)
691 params.papersize2 = char(fl_get_choice(paper_->choice_papersize) - 1);
693 params.paperpackage =
694 char(fl_get_choice(paper_->choice_paperpackage) - 1);
696 // set params.papersize from params.papersize2 and params.paperpackage
697 params.setPaperStuff();
699 params.use_geometry = fl_get_button(paper_->check_use_geometry);
701 if (fl_get_button(paper_->radio_landscape))
702 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
704 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
707 getLengthFromWidgets(paper_->input_custom_width,
708 paper_->choice_custom_width_units);
711 getLengthFromWidgets(paper_->input_custom_height,
712 paper_->choice_custom_height_units);
715 getLengthFromWidgets(paper_->input_inner_margin,
716 paper_->choice_inner_margin_units);
719 getLengthFromWidgets(paper_->input_top_margin,
720 paper_->choice_top_margin_units);
723 getLengthFromWidgets(paper_->input_outer_margin,
724 paper_->choice_outer_margin_units);
726 params.bottommargin =
727 getLengthFromWidgets(paper_->input_bottom_margin,
728 paper_->choice_bottom_margin_units);
731 getLengthFromWidgets(paper_->input_head_height,
732 paper_->choice_head_height_units);
735 getLengthFromWidgets(paper_->input_head_sep,
736 paper_->choice_head_sep_units);
739 getLengthFromWidgets(paper_->input_foot_skip,
740 paper_->choice_foot_skip_units);
744 bool FormDocument::language_apply(BufferParams & params)
746 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
749 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
751 lga = InsetQuotes::EnglishQ;
754 lga = InsetQuotes::SwedishQ;
757 lga = InsetQuotes::GermanQ;
760 lga = InsetQuotes::PolishQ;
763 lga = InsetQuotes::FrenchQ;
766 lga = InsetQuotes::DanishQ;
769 params.quotes_language = lga;
770 if (fl_get_button(language_->radio_single))
771 params.quotes_times = InsetQuotes::SingleQ;
773 params.quotes_times = InsetQuotes::DoubleQ;
775 int const pos = fl_get_combox(language_->combox_language);
776 Language const * new_language = languages.getLanguage(lang_[pos-1]);
778 new_language = default_language;
780 params.language = new_language;
781 params.inputenc = getString(language_->choice_inputenc);
787 bool FormDocument::options_apply(BufferParams & params)
791 params.graphicsDriver = getString(options_->choice_postscript_driver);
792 params.use_amsmath = static_cast<BufferParams::AMS>(
793 fl_get_choice(options_->choice_ams_math) - 1);
794 params.use_natbib = fl_get_button(options_->check_use_natbib);
795 params.use_numerical_citations =
796 fl_get_choice(options_->choice_citation_format) - 1;
798 int tmpchar = int(fl_get_counter_value(options_->counter_secnumdepth));
799 if (params.secnumdepth != tmpchar)
801 params.secnumdepth = tmpchar;
803 params.tocdepth = int(fl_get_counter_value(options_->counter_tocdepth));
805 params.float_placement =
806 getString(options_->input_float_placement);
812 void FormDocument::bullets_apply(BufferParams & params)
814 /* update the bullet settings */
815 BufferParams & buf_params = controller().params();
817 for (int i = 0; i < 4; ++i) {
818 params.user_defined_bullets[i] = buf_params.temp_bullets[i];
823 void FormDocument::UpdateClassParams(BufferParams const & params)
825 // These are the params that have to be updated on any class change
826 // (even if the class defaults are not used) (JSpitzm 2002-04-08)
828 LyXTextClass const & tclass = textclasslist[params.textclass];
830 fl_set_combox(class_->combox_class, params.textclass + 1);
831 fl_clear_choice(class_->choice_fontsize);
832 fl_addto_choice(class_->choice_fontsize, "default");
833 fl_addto_choice(class_->choice_fontsize,
834 tclass.opt_fontsize().c_str());
835 fl_set_choice_text(class_->choice_fontsize,
836 params.fontsize.c_str());
837 fl_clear_choice(class_->choice_pagestyle);
838 fl_addto_choice(class_->choice_pagestyle, "default");
839 fl_addto_choice(class_->choice_pagestyle,
840 tclass.opt_pagestyle().c_str());
841 fl_set_choice_text(class_->choice_pagestyle,
842 params.pagestyle.c_str());
846 void FormDocument::class_update(BufferParams const & params)
851 UpdateClassParams(params);
853 fl_set_choice_text(class_->choice_fonts, params.fonts.c_str());
855 bool const indent = params.paragraph_separation == BufferParams::PARSEP_INDENT;
856 fl_set_button(class_->radio_indent, indent);
857 fl_set_button(class_->radio_skip, !indent);
861 pos = 2; // VSpace::MEDSKIP is default
863 switch (params.getDefSkip().kind()) {
867 case VSpace::BIGSKIP:
870 case VSpace::SMALLSKIP:
873 case VSpace::MEDSKIP:
879 fl_set_choice (class_->choice_skip, pos);
881 bool const length_input = pos == 4;
883 int const paperchoice = fl_get_choice(paper_->choice_papersize);
884 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
885 || paperchoice == 2 || paperchoice > 5;
886 string const default_unit = metric ? "cm" : "in";
887 string const length = params.getDefSkip().asLyXCommand();
888 updateWidgetsFromLengthString(class_->input_skip,
889 class_->choice_skip_units,
890 length, default_unit);
893 fl_set_input(class_->input_skip, "");
895 setEnabled(class_->choice_skip, !indent);
896 setEnabled(class_->input_skip, length_input);
897 setEnabled(class_->choice_skip_units, length_input);
899 bool const two_sides = params.sides == LyXTextClass::TwoSides;
900 fl_set_button(class_->radio_sides_one, !two_sides);
901 fl_set_button(class_->radio_sides_two, two_sides);
903 bool const two_columns = params.columns == 2;
904 fl_set_button(class_->radio_columns_one, !two_columns);
905 fl_set_button(class_->radio_columns_two, two_columns);
907 fl_set_input(class_->input_extra, params.options.c_str());
909 switch (params.spacing.getSpace()) {
913 case Spacing::Double: // \doublespacing
916 case Spacing::Onehalf: // \onehalfspacing
919 case Spacing::Single: // \singlespacing
920 case Spacing::Default: // nothing bad should happen with this
925 fl_set_choice(class_->choice_spacing, pos);
927 bool const spacing_input = pos == 4;
928 setEnabled(class_->input_spacing, spacing_input);
929 string const input = spacing_input ? tostr(params.spacing.getValue()) : string();
930 fl_set_input(class_->input_spacing, input.c_str());
934 void FormDocument::language_update(BufferParams const & params)
936 if (!language_.get())
939 int const pos = int(findPos(lang_, params.language->lang()));
940 fl_set_combox(language_->combox_language, pos+1);
942 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
943 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
944 fl_set_button(language_->radio_single, 0);
945 fl_set_button(language_->radio_double, 0);
946 if (params.quotes_times == InsetQuotes::SingleQ)
947 fl_set_button(language_->radio_single, 1);
949 fl_set_button(language_->radio_double, 1);
953 void FormDocument::options_update(BufferParams const & params)
958 fl_set_choice_text(options_->choice_postscript_driver,
959 params.graphicsDriver.c_str());
960 fl_set_choice(options_->choice_ams_math, params.use_amsmath + 1);
961 fl_set_button(options_->check_use_natbib, params.use_natbib);
962 fl_set_choice(options_->choice_citation_format,
963 int(params.use_numerical_citations)+1);
964 setEnabled(options_->choice_citation_format, params.use_natbib);
965 fl_set_counter_value(options_->counter_secnumdepth, params.secnumdepth);
966 fl_set_counter_value(options_->counter_tocdepth, params.tocdepth);
967 if (!params.float_placement.empty())
968 fl_set_input(options_->input_float_placement,
969 params.float_placement.c_str());
971 fl_set_input(options_->input_float_placement, "");
975 void FormDocument::paper_update(BufferParams const & params)
980 fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
981 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
982 fl_set_button(paper_->check_use_geometry, params.use_geometry);
984 int const paperchoice = fl_get_choice(paper_->choice_papersize);
985 bool const useCustom = paperchoice == 2;
986 bool const useGeom = fl_get_button(paper_->check_use_geometry);
988 fl_set_button(paper_->radio_portrait, 0);
989 setEnabled(paper_->radio_portrait, !useCustom);
990 fl_set_button(paper_->radio_landscape, 0);
991 setEnabled(paper_->radio_landscape, !useCustom);
993 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
994 fl_set_button(paper_->radio_landscape, 1);
996 fl_set_button(paper_->radio_portrait, 1);
997 setEnabled(paper_->choice_paperpackage,
998 //either default papersize (preferences)
999 //or document papersize has to be A4
1001 || paperchoice == 1 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER)
1002 && fl_get_button(paper_->radio_portrait));
1004 // Default unit choice is cm if metric, inches if US paper.
1005 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
1006 || paperchoice == 2 || paperchoice > 5;
1007 string const default_unit = metric ? "cm" : "in";
1008 updateWidgetsFromLengthString(paper_->input_custom_width,
1009 paper_->choice_custom_width_units,
1010 params.paperwidth, default_unit);
1011 setEnabled(paper_->input_custom_width, useCustom);
1012 setEnabled(paper_->choice_custom_width_units, useCustom);
1014 updateWidgetsFromLengthString(paper_->input_custom_height,
1015 paper_->choice_custom_height_units,
1016 params.paperheight, default_unit);
1017 setEnabled(paper_->input_custom_height, useCustom);
1018 setEnabled(paper_->choice_custom_height_units, useCustom);
1020 updateWidgetsFromLengthString(paper_->input_inner_margin,
1021 paper_->choice_inner_margin_units,
1022 params.leftmargin, default_unit);
1023 setEnabled(paper_->input_inner_margin, useGeom);
1024 setEnabled(paper_->choice_inner_margin_units, useGeom);
1026 updateWidgetsFromLengthString(paper_->input_top_margin,
1027 paper_->choice_top_margin_units,
1028 params.topmargin, default_unit);
1029 setEnabled(paper_->input_top_margin, useGeom);
1030 setEnabled(paper_->choice_top_margin_units, useGeom);
1032 updateWidgetsFromLengthString(paper_->input_outer_margin,
1033 paper_->choice_outer_margin_units,
1034 params.rightmargin, default_unit);
1035 setEnabled(paper_->input_outer_margin, useGeom);
1036 setEnabled(paper_->choice_outer_margin_units, useGeom);
1038 updateWidgetsFromLengthString(paper_->input_bottom_margin,
1039 paper_->choice_bottom_margin_units,
1040 params.bottommargin, default_unit);
1041 setEnabled(paper_->input_bottom_margin, useGeom);
1042 setEnabled(paper_->choice_bottom_margin_units, useGeom);
1044 updateWidgetsFromLengthString(paper_->input_head_height,
1045 paper_->choice_head_height_units,
1046 params.headheight, default_unit);
1047 setEnabled(paper_->input_head_height, useGeom);
1048 setEnabled(paper_->choice_head_height_units, useGeom);
1050 updateWidgetsFromLengthString(paper_->input_head_sep,
1051 paper_->choice_head_sep_units,
1052 params.headsep, default_unit);
1053 setEnabled(paper_->input_head_sep, useGeom);
1054 setEnabled(paper_->choice_head_sep_units, useGeom);
1056 updateWidgetsFromLengthString(paper_->input_foot_skip,
1057 paper_->choice_foot_skip_units,
1058 params.footskip, default_unit);
1059 setEnabled(paper_->input_foot_skip, useGeom);
1060 setEnabled(paper_->choice_foot_skip_units, useGeom);
1062 fl_set_focus_object(paper_->form, paper_->choice_papersize);
1066 void FormDocument::bullets_update(BufferParams const & params)
1068 if (!bullets_.get() ||
1070 (XpmVersion==4 && XpmRevision<7)))
1073 bool const isLinuxDoc =
1074 controller().docType() == ControlDocument::LINUXDOC;
1075 setEnabled(fbullet, !isLinuxDoc);
1077 if (isLinuxDoc) return;
1079 fl_set_button(bullets_->radio_depth_1, 1);
1080 fl_set_input(bullets_->input_latex,
1081 params.user_defined_bullets[0].getText().c_str());
1082 fl_set_choice(bullets_->choice_size,
1083 params.user_defined_bullets[0].getSize() + 2);
1087 void FormDocument::checkReadOnly()
1089 if (bc().readOnly(controller().bufferIsReadonly())) {
1090 postWarning(_("Document is read-only."
1091 " No changes to layout permitted."));
1098 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/)
1100 BufferParams & param = controller().params();
1102 // convert from 1-6 range to -1-4
1103 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1104 fl_set_input(bullets_->input_latex,
1105 param.temp_bullets[current_bullet_depth].getText().c_str());
1109 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1111 BufferParams & param = controller().params();
1113 param.temp_bullets[current_bullet_depth].
1114 setText(getString(bullets_->input_latex));
1118 void FormDocument::BulletDepth(FL_OBJECT * ob)
1120 /* Should I do the following: */
1121 /* 1. change to the panel that the current bullet belongs in */
1122 /* 2. show that bullet as selected */
1123 /* 3. change the size setting to the size of the bullet in Q.*/
1124 /* 4. display the latex equivalent in the latex box */
1126 /* I'm inclined to just go with 3 and 4 at the moment and */
1127 /* maybe try to support the others later */
1128 BufferParams & param = controller().params();
1131 if (ob == bullets_->radio_depth_1)
1133 else if (ob == bullets_->radio_depth_2)
1135 else if (ob == bullets_->radio_depth_3)
1137 else if (ob == bullets_->radio_depth_4)
1140 switch (fl_get_button_numb(ob)) {
1142 // right mouse button resets to default
1143 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1145 current_bullet_depth = data;
1146 fl_set_input(bullets_->input_latex,
1147 param.temp_bullets[data].getText().c_str());
1148 fl_set_choice(bullets_->choice_size,
1149 param.temp_bullets[data].getSize() + 2);
1154 void FormDocument::BulletPanel(FL_OBJECT * ob)
1156 /* Here we have to change the background pixmap to that selected */
1157 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1160 if (ob == bullets_->radio_panel_standard)
1162 else if (ob == bullets_->radio_panel_maths)
1164 else if (ob == bullets_->radio_panel_ding2)
1166 else if (ob == bullets_->radio_panel_ding3)
1168 else if (ob == bullets_->radio_panel_ding4)
1170 else if (ob == bullets_->radio_panel_ding1)
1173 if (data != current_bullet_panel) {
1174 fl_freeze_form(bullets_->form);
1175 current_bullet_panel = data;
1177 /* free the current pixmap */
1178 fl_free_bmtable_pixmap(bullets_->bmtable_panel);
1180 if (ob == bullets_->radio_panel_standard) {
1181 new_panel = "standard";
1182 } else if (ob == bullets_->radio_panel_maths ) {
1183 new_panel = "amssymb";
1184 } else if (ob == bullets_->radio_panel_ding2) {
1185 new_panel = "psnfss1";
1186 } else if (ob == bullets_->radio_panel_ding3) {
1187 new_panel = "psnfss2";
1188 } else if (ob == bullets_->radio_panel_ding4) {
1189 new_panel = "psnfss3";
1190 } else if (ob == bullets_->radio_panel_ding1) {
1191 new_panel = "psnfss4";
1193 /* something very wrong happened */
1194 // play it safe for now but should be an exception
1195 current_bullet_panel = 0; // standard panel
1196 new_panel = "standard";
1198 new_panel += ".xpm";
1199 fl_set_bmtable_pixmap_file(bullets_->bmtable_panel, 6, 6,
1200 LibFileSearch("images", new_panel).c_str());
1201 fl_redraw_object(bullets_->bmtable_panel);
1202 fl_unfreeze_form(bullets_->form);
1207 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/)
1209 /* handle the user input by setting the current bullet depth's pixmap */
1210 /* to that extracted from the current chosen position of the BMTable */
1211 /* Don't forget to free the button's old pixmap first. */
1213 BufferParams & param = controller().params();
1214 int bmtable_button = fl_get_bmtable(ob);
1216 /* try to keep the button held down till another is pushed */
1217 /* fl_set_bmtable(ob, 1, bmtable_button); */
1218 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1219 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1220 fl_set_input(bullets_->input_latex,
1221 param.temp_bullets[current_bullet_depth].getText().c_str());
1225 void FormDocument::CheckChoiceClass()
1227 BufferParams & params = controller().params();
1229 lyx::textclass_type const tc =
1230 fl_get_combox(class_->combox_class) - 1;
1232 if (controller().loadTextclass(tc)) {
1233 params.textclass = tc;
1235 if (lyxrc.auto_reset_options) {
1236 params.useClassDefaults();
1237 UpdateLayoutDocument(params);
1239 // update the params which are needed in any case
1240 // (fontsizes, pagestyle)
1241 UpdateClassParams(params);
1245 int const revert = int(params.textclass);
1246 fl_set_combox(class_->combox_class, revert + 1);
1251 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1257 class_update(params);
1258 paper_update(params);
1259 language_update(params);
1260 options_update(params);
1261 bullets_update(params);