3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS
14 #include "ControlDocument.h"
15 #include "FormDocument.h"
16 #include "forms/form_document.h"
18 #include "ButtonController.h"
21 #include "checkedwidgets.h"
22 #include "input_validators.h" // fl_unsigned_float_filter
23 #include "xforms_helpers.h"
25 #include "CutAndPaste.h"
29 #include "lyxtextclasslist.h"
30 #include "tex-strings.h"
32 #include "controllers/frnt_lang.h"
33 #include "controllers/helper_funcs.h"
35 #include "support/tostr.h"
36 #include "support/lstrings.h" // contains_functor, getStringFromVector
37 #include "support/filetools.h" // LibFileSearch
40 #include "lyx_forms.h"
43 #include <boost/bind.hpp>
47 using namespace lyx::support;
56 #if FL_VERSION == 0 || (FL_REVISION == 0 && FL_FIXLEVEL < 2)
57 bool const scalableTabfolders = false;
59 bool const scalableTabfolders = true;
65 typedef FormCB<ControlDocument, FormDB<FD_document> > base_class;
67 FormDocument::FormDocument()
68 : base_class(_("Document Settings"), scalableTabfolders),
69 ActCell(0), Confirmed(0),
70 current_bullet_panel(0), current_bullet_depth(0), fbullet(0)
74 void FormDocument::redraw()
76 if (form() && form()->visible)
77 fl_redraw_form(form());
81 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder);
82 if (outer_form && outer_form->visible)
83 fl_redraw_form(outer_form);
87 void FormDocument::build()
90 dialog_.reset(build_document(this));
92 // Allow the base class to control messages
93 setMessageWidget(dialog_->text_warning);
95 // Manage the restore, ok, apply, restore and cancel/close buttons
96 bcview().setOK(dialog_->button_ok);
97 bcview().setApply(dialog_->button_apply);
98 bcview().setCancel(dialog_->button_close);
99 bcview().setRestore(dialog_->button_restore);
101 // the document class form
102 class_.reset(build_document_class(this));
104 // disable for read-only documents
105 bcview().addReadOnly(class_->combox_class);
106 bcview().addReadOnly(class_->radio_indent);
107 bcview().addReadOnly(class_->radio_skip);
108 bcview().addReadOnly(class_->choice_pagestyle);
109 bcview().addReadOnly(class_->choice_fonts);
110 bcview().addReadOnly(class_->choice_fontsize);
111 bcview().addReadOnly(class_->radio_sides_one);
112 bcview().addReadOnly(class_->radio_sides_two);
113 bcview().addReadOnly(class_->radio_columns_one);
114 bcview().addReadOnly(class_->radio_columns_two);
115 bcview().addReadOnly(class_->input_extra);
116 bcview().addReadOnly(class_->input_skip);
117 bcview().addReadOnly(class_->choice_skip);
118 bcview().addReadOnly(class_->choice_spacing);
119 bcview().addReadOnly(class_->input_spacing);
121 // check validity of "length + unit" input
122 addCheckedGlueLength(bcview(), class_->input_skip,
123 class_->choice_skip);
125 // trigger an input event for cut&paste with middle mouse button.
126 setPrehandler(class_->input_extra);
127 setPrehandler(class_->input_skip);
128 setPrehandler(class_->input_spacing);
130 fl_set_input_return(class_->input_extra, FL_RETURN_CHANGED);
131 fl_set_input_return(class_->input_skip, FL_RETURN_CHANGED);
132 fl_set_input_return(class_->input_spacing, FL_RETURN_CHANGED);
136 // Fill the combox and choices.
137 obj = class_->combox_class;
138 LyXTextClassList::const_iterator tit = textclasslist.begin();
139 LyXTextClassList::const_iterator tend = textclasslist.end();
140 for (; tit != tend; ++tit) {
141 if (tit->isTeXClassAvailable()) {
142 fl_addto_combox(obj, tit->description().c_str());
144 string item = bformat(_("Unavailable: %1$s"), tit->description());
145 fl_addto_combox(obj, item.c_str());
148 fl_set_combox_browser_height(obj, 400);
150 fl_addto_choice(class_->choice_spacing,
151 _(" Single | OneHalf | Double | Custom ").c_str());
152 fl_addto_choice(class_->choice_fontsize, "default|10|11|12");
153 for (int n = 0; tex_fonts[n][0]; ++n) {
154 fl_addto_choice(class_->choice_fonts,tex_fonts[n]);
157 // Create the contents of the unit choices; don't include the
159 vector<string> units_vec = getLatexUnits();
160 vector<string>::iterator ret =
161 std::remove_if(units_vec.begin(),
163 bind2nd(contains_functor(), "%"));
164 units_vec.erase(ret, units_vec.end());
166 string const units = getStringFromVector(units_vec, "|");
168 fl_addto_choice(class_->choice_pagestyle,
169 "default|empty|plain|headings|fancy");
170 fl_addto_choice(class_->choice_skip,
171 _(" SmallSkip | MedSkip | BigSkip | Length ").c_str());
172 fl_addto_choice(class_->choice_skip_units, units.c_str());
174 // Set input filters on doc spacing to make it accept only
176 fl_set_input_filter(class_->input_spacing,
177 fl_unsigned_float_filter);
179 // disable for read-only documents
180 bcview().addReadOnly(dialog_->button_save_defaults);
181 bcview().addReadOnly(dialog_->button_reset_defaults);
183 // the document paper form
184 paper_.reset(build_document_paper(this));
186 // disable for read-only documents
187 bcview().addReadOnly(paper_->choice_paperpackage);
188 bcview().addReadOnly(paper_->radio_portrait);
189 bcview().addReadOnly(paper_->radio_landscape);
190 bcview().addReadOnly(paper_->choice_papersize);
191 bcview().addReadOnly(paper_->check_use_geometry);
192 bcview().addReadOnly(paper_->input_custom_width);
193 bcview().addReadOnly(paper_->input_custom_height);
194 bcview().addReadOnly(paper_->input_top_margin);
195 bcview().addReadOnly(paper_->input_bottom_margin);
196 bcview().addReadOnly(paper_->input_inner_margin);
197 bcview().addReadOnly(paper_->input_outer_margin);
198 bcview().addReadOnly(paper_->input_head_height);
199 bcview().addReadOnly(paper_->input_head_sep);
200 bcview().addReadOnly(paper_->input_foot_skip);
202 // check validity of "length + unit" input
203 addCheckedGlueLength(bcview(), paper_->input_custom_width);
204 addCheckedGlueLength(bcview(), paper_->input_custom_height);
205 addCheckedGlueLength(bcview(), paper_->input_top_margin);
206 addCheckedGlueLength(bcview(), paper_->input_bottom_margin);
207 addCheckedGlueLength(bcview(), paper_->input_inner_margin);
208 addCheckedGlueLength(bcview(), paper_->input_outer_margin);
209 addCheckedGlueLength(bcview(), paper_->input_head_height);
210 addCheckedGlueLength(bcview(), paper_->input_head_sep);
211 addCheckedGlueLength(bcview(), paper_->input_foot_skip);
213 // trigger an input event for cut&paste with middle mouse button.
214 setPrehandler(paper_->input_custom_width);
215 setPrehandler(paper_->input_custom_height);
216 setPrehandler(paper_->input_top_margin);
217 setPrehandler(paper_->input_bottom_margin);
218 setPrehandler(paper_->input_inner_margin);
219 setPrehandler(paper_->input_outer_margin);
220 setPrehandler(paper_->input_head_height);
221 setPrehandler(paper_->input_head_sep);
222 setPrehandler(paper_->input_foot_skip);
224 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
225 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
226 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
227 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
228 fl_set_input_return(paper_->input_inner_margin, FL_RETURN_CHANGED);
229 fl_set_input_return(paper_->input_outer_margin, FL_RETURN_CHANGED);
230 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
231 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
232 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
234 fl_addto_choice(paper_->choice_papersize,
235 _(" Default | Custom | US letter | US legal "
236 "| US executive | A3 | A4 | A5 "
237 "| B3 | B4 | B5 ").c_str());
238 fl_addto_choice(paper_->choice_paperpackage,
241 "| Very small Margins "
242 "| Very wide Margins ").c_str());
244 fl_addto_choice(paper_->choice_custom_width_units, units.c_str());
245 fl_addto_choice(paper_->choice_custom_height_units, units.c_str());
246 fl_addto_choice(paper_->choice_top_margin_units, units.c_str());
247 fl_addto_choice(paper_->choice_bottom_margin_units, units.c_str());
248 fl_addto_choice(paper_->choice_inner_margin_units, units.c_str());
249 fl_addto_choice(paper_->choice_outer_margin_units, units.c_str());
250 fl_addto_choice(paper_->choice_head_height_units, units.c_str());
251 fl_addto_choice(paper_->choice_head_sep_units, units.c_str());
252 fl_addto_choice(paper_->choice_foot_skip_units, units.c_str());
254 // the document language form
255 language_.reset(build_document_language(this));
257 // disable for read-only documents
258 bcview().addReadOnly(language_->combox_language);
259 bcview().addReadOnly(language_->choice_inputenc);
260 bcview().addReadOnly(language_->choice_quotes_language);
261 bcview().addReadOnly(language_->radio_single);
262 bcview().addReadOnly(language_->radio_double);
264 fl_addto_choice(language_->choice_inputenc,
265 "default|auto|latin1|latin2|latin3|latin4|latin5|latin9"
266 "|koi8-r|koi8-u|cp866|cp1251|iso88595|pt154");
268 vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
269 // Store the identifiers for later
270 lang_ = getSecond(langs);
272 vector<frnt::LanguagePair>::const_iterator lit = langs.begin();
273 vector<frnt::LanguagePair>::const_iterator lend = langs.end();
274 for (; lit != lend; ++lit) {
275 fl_addto_combox(language_->combox_language,
278 fl_set_combox_browser_height(language_->combox_language, 400);
280 fl_addto_choice(language_->choice_quotes_language,
281 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
282 " «text» | »text« ").c_str());
284 // the document options form
285 options_.reset(build_document_options(this));
287 // disable for read-only documents
288 bcview().addReadOnly(options_->counter_secnumdepth);
289 bcview().addReadOnly(options_->counter_tocdepth);
290 bcview().addReadOnly(options_->choice_ams_math);
291 bcview().addReadOnly(options_->check_use_natbib);
292 bcview().addReadOnly(options_->choice_citation_format);
293 bcview().addReadOnly(options_->input_float_placement);
294 bcview().addReadOnly(options_->choice_postscript_driver);
296 // trigger an input event for cut&paste with middle mouse button.
297 setPrehandler(options_->input_float_placement);
299 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
301 fl_addto_choice(options_->choice_ams_math,
302 _("Never | Automatically | Yes ").c_str());
304 for (int n = 0; tex_graphics[n][0]; ++n) {
305 fl_addto_choice(options_->choice_postscript_driver,
308 fl_addto_choice(options_->choice_citation_format,
309 _(" Author-year | Numerical ").c_str());
311 // the document bullets form
312 bullets_.reset(build_document_bullet(this));
314 // disable for read-only documents
315 bcview().addReadOnly(bullets_->radio_depth_1);
316 bcview().addReadOnly(bullets_->radio_depth_2);
317 bcview().addReadOnly(bullets_->radio_depth_3);
318 bcview().addReadOnly(bullets_->radio_depth_4);
319 bcview().addReadOnly(bullets_->radio_panel_standard);
320 bcview().addReadOnly(bullets_->radio_panel_maths);
321 bcview().addReadOnly(bullets_->radio_panel_ding1);
322 bcview().addReadOnly(bullets_->radio_panel_ding2);
323 bcview().addReadOnly(bullets_->radio_panel_ding3);
324 bcview().addReadOnly(bullets_->radio_panel_ding4);
325 bcview().addReadOnly(bullets_->bmtable_panel);
326 bcview().addReadOnly(bullets_->choice_size);
327 bcview().addReadOnly(bullets_->input_latex);
329 // trigger an input event for cut&paste with middle mouse button.
330 setPrehandler(bullets_->input_latex);
332 fl_set_input_return(bullets_->input_latex, FL_RETURN_CHANGED);
334 fl_addto_choice(bullets_->choice_size,
335 _(" Default | Tiny | Smallest | Smaller "
336 "| Small | Normal | Large | Larger | Largest "
337 "| Huge | Huger ").c_str());
338 fl_set_choice(bullets_->choice_size, 1);
340 fl_set_input_maxchars(bullets_->input_latex, 80);
342 string const bmtablefile = LibFileSearch("images", "standard", "xpm");
343 fl_set_bmtable_pixmap_file(bullets_->bmtable_panel, 6, 6,
344 bmtablefile.c_str());
346 // Enable the tabfolder to be rescaled correctly.
347 if (scalableTabfolders)
348 fl_set_tabfolder_autofit(dialog_->tabfolder, FL_FIT);
351 fl_addto_tabfolder(dialog_->tabfolder,_("Document").c_str(),
353 fl_addto_tabfolder(dialog_->tabfolder,_("Paper").c_str(),
355 fl_addto_tabfolder(dialog_->tabfolder,_("Language").c_str(),
357 fl_addto_tabfolder(dialog_->tabfolder,_("Extra").c_str(),
359 fbullet = fl_addto_tabfolder(dialog_->tabfolder,_("Bullets").c_str(),
362 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
363 lyxerr << _("Your version of libXpm is older than 4.7.\n"
364 "The `bullet' tab of the document dialog "
365 "has been disabled") << '\n';
366 fl_deactivate_object(fbullet);
367 fl_set_object_lcol(fbullet, FL_INACTIVE);
372 void FormDocument::apply()
374 BufferParams & params = controller().params();
378 language_apply(params);
379 options_apply(params);
380 bullets_apply(params);
384 void FormDocument::update()
391 BufferParams const & params = controller().params();
393 class_update(params);
394 paper_update(params);
395 language_update(params);
396 options_update(params);
397 bullets_update(params);
401 ButtonPolicy::SMInput FormDocument::input(FL_OBJECT * ob, long)
403 if (ob == bullets_->choice_size) {
404 ChoiceBulletSize(ob, 0);
406 } else if (ob == bullets_->input_latex) {
407 InputBulletLaTeX(ob, 0);
409 } else if (ob == bullets_->radio_depth_1 ||
410 ob == bullets_->radio_depth_2 ||
411 ob == bullets_->radio_depth_3 ||
412 ob == bullets_->radio_depth_4) {
415 } else if (ob == bullets_->radio_panel_standard ||
416 ob == bullets_->radio_panel_maths ||
417 ob == bullets_->radio_panel_ding1 ||
418 ob == bullets_->radio_panel_ding2 ||
419 ob == bullets_->radio_panel_ding3 ||
420 ob == bullets_->radio_panel_ding4) {
423 } else if (ob == bullets_->bmtable_panel) {
424 BulletBMTable(ob, 0);
426 } else if (ob == class_->choice_spacing) {
427 setEnabled(class_->input_spacing,
428 fl_get_choice(class_->choice_spacing) == 4);
430 } else if (ob == class_->combox_class) {
432 } else if (ob == class_->radio_skip ||
433 ob == class_->radio_indent ||
434 ob == class_->choice_skip) {
435 bool const skip_used = fl_get_button(class_->radio_skip);
436 setEnabled(class_->choice_skip, skip_used);
438 bool const length_input =
439 fl_get_choice(class_->choice_skip) == 4;
440 setEnabled(class_->input_skip,
441 skip_used && length_input);
442 setEnabled(class_->choice_skip_units,
443 skip_used && length_input);
445 // Default unit choice is cm if metric, inches if US paper.
446 // If papersize is default, check the lyxrc-settings
447 int const paperchoice = fl_get_choice(paper_->choice_papersize);
448 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > PAPER_EXECUTIVEPAPER)
449 || paperchoice == 2 || paperchoice > 5;
450 string const default_unit = metric ? "cm" : "in";
451 if (getString(class_->input_skip).empty())
452 fl_set_choice_text(class_->choice_skip_units,
453 default_unit.c_str());
455 } else if (ob == options_->check_use_natbib) {
456 setEnabled(options_->choice_citation_format,
457 fl_get_button(options_->check_use_natbib));
459 } else if (ob == dialog_->button_save_defaults) {
461 controller().saveAsDefault();
463 } else if (ob == dialog_->button_reset_defaults) {
464 BufferParams & params = controller().params();
465 params.textclass = fl_get_combox(class_->combox_class) - 1;
466 params.useClassDefaults();
467 UpdateLayoutDocument(params);
469 } else if (ob == paper_->radio_landscape) {
470 fl_set_choice(paper_->choice_paperpackage,
473 } else if (ob == paper_->choice_papersize) {
474 int const paperchoice = fl_get_choice(paper_->choice_papersize);
475 bool const defsize = paperchoice == 1;
476 bool const custom = paperchoice == 2;
477 bool const a3size = paperchoice == 6;
478 bool const b3size = paperchoice == 9;
479 bool const b4size = paperchoice == 10;
482 fl_set_button(paper_->radio_portrait, 1);
484 bool const use_geom = (custom || a3size || b3size || b4size);
486 fl_set_button(paper_->check_use_geometry, int(use_geom));
488 setEnabled(paper_->input_top_margin, use_geom);
489 setEnabled(paper_->input_bottom_margin, use_geom);
490 setEnabled(paper_->input_inner_margin, use_geom);
491 setEnabled(paper_->input_outer_margin, use_geom);
492 setEnabled(paper_->input_head_height, use_geom);
493 setEnabled(paper_->input_head_sep, use_geom);
494 setEnabled(paper_->input_foot_skip, use_geom);
495 setEnabled(paper_->choice_top_margin_units, use_geom);
496 setEnabled(paper_->choice_bottom_margin_units, use_geom);
497 setEnabled(paper_->choice_inner_margin_units, use_geom);
498 setEnabled(paper_->choice_outer_margin_units, use_geom);
499 setEnabled(paper_->choice_head_height_units, use_geom);
500 setEnabled(paper_->choice_head_sep_units, use_geom);
501 setEnabled(paper_->choice_foot_skip_units, use_geom);
502 setEnabled(paper_->choice_custom_width_units, use_geom);
503 setEnabled(paper_->choice_custom_height_units, use_geom);
505 setEnabled(paper_->input_custom_width, custom);
506 setEnabled(paper_->input_custom_height, custom);
507 setEnabled(paper_->choice_custom_width_units, custom);
508 setEnabled(paper_->choice_custom_height_units, custom);
509 setEnabled(paper_->radio_portrait, !custom);
510 setEnabled(paper_->radio_landscape, !custom);
512 // Default unit choice is cm if metric, inches if US paper.
513 // If papersize is default, use the lyxrc-settings
514 bool const metric = (defsize && lyxrc.default_papersize > PAPER_EXECUTIVEPAPER)
515 || paperchoice == 2 || paperchoice > 5;
516 string const default_unit = metric ? "cm" : "in";
517 if (getString(paper_->input_custom_width).empty())
518 fl_set_choice_text(paper_->choice_custom_width_units,
519 default_unit.c_str());
520 if (getString(paper_->input_custom_height).empty())
521 fl_set_choice_text(paper_->choice_custom_height_units,
522 default_unit.c_str());
523 if (getString(paper_->input_top_margin).empty())
524 fl_set_choice_text(paper_->choice_top_margin_units,
525 default_unit.c_str());
526 if (getString(paper_->input_bottom_margin).empty())
527 fl_set_choice_text(paper_->choice_bottom_margin_units,
528 default_unit.c_str());
529 if (getString(paper_->input_inner_margin).empty())
530 fl_set_choice_text(paper_->choice_inner_margin_units,
531 default_unit.c_str());
532 if (getString(paper_->input_outer_margin).empty())
533 fl_set_choice_text(paper_->choice_outer_margin_units,
534 default_unit.c_str());
535 if (getString(paper_->input_head_height).empty())
536 fl_set_choice_text(paper_->choice_head_height_units,
537 default_unit.c_str());
538 if (getString(paper_->input_head_sep).empty())
539 fl_set_choice_text(paper_->choice_head_sep_units,
540 default_unit.c_str());
541 if (getString(paper_->input_foot_skip).empty())
542 fl_set_choice_text(paper_->choice_foot_skip_units,
543 default_unit.c_str());
545 } else if (ob == paper_->choice_paperpackage &&
546 fl_get_choice(paper_->choice_paperpackage) != 1) {
548 fl_set_button(paper_->check_use_geometry, 0);
549 setEnabled(paper_->input_top_margin, false);
550 setEnabled(paper_->input_bottom_margin, false);
551 setEnabled(paper_->input_inner_margin, false);
552 setEnabled(paper_->input_outer_margin, false);
553 setEnabled(paper_->input_head_height, false);
554 setEnabled(paper_->input_head_sep, false);
555 setEnabled(paper_->input_foot_skip, false);
556 setEnabled(paper_->choice_top_margin_units, false);
557 setEnabled(paper_->choice_bottom_margin_units, false);
558 setEnabled(paper_->choice_inner_margin_units, false);
559 setEnabled(paper_->choice_outer_margin_units, false);
560 setEnabled(paper_->choice_head_height_units, false);
561 setEnabled(paper_->choice_head_sep_units, false);
562 setEnabled(paper_->choice_foot_skip_units, false);
564 } else if (ob == paper_->check_use_geometry) {
565 // don't allow switching geometry off in custom papersize
566 // mode nor in A3, B3, and B4
567 int const choice = fl_get_choice(paper_->choice_papersize);
568 if (choice == 2 || choice == 6 || choice == 9 || choice == 10)
569 fl_set_button(paper_->check_use_geometry, 1);
571 fl_set_choice(paper_->choice_paperpackage,
574 bool const use_geom = fl_get_button(paper_->check_use_geometry);
575 setEnabled(paper_->input_top_margin, use_geom);
576 setEnabled(paper_->input_bottom_margin, use_geom);
577 setEnabled(paper_->input_inner_margin, use_geom);
578 setEnabled(paper_->input_outer_margin, use_geom);
579 setEnabled(paper_->input_head_height, use_geom);
580 setEnabled(paper_->input_head_sep, use_geom);
581 setEnabled(paper_->input_foot_skip, use_geom);
582 setEnabled(paper_->choice_top_margin_units, use_geom);
583 setEnabled(paper_->choice_bottom_margin_units, use_geom);
584 setEnabled(paper_->choice_inner_margin_units, use_geom);
585 setEnabled(paper_->choice_outer_margin_units, use_geom);
586 setEnabled(paper_->choice_head_height_units, use_geom);
587 setEnabled(paper_->choice_head_sep_units, use_geom);
588 setEnabled(paper_->choice_foot_skip_units, use_geom);
591 if (ob == paper_->choice_papersize || ob == paper_->radio_portrait
592 || ob == paper_->radio_landscape) {
593 // either default papersize (preferences) or document
594 // papersize has to be A4
595 bool const enable = ( fl_get_choice(paper_->choice_papersize) == 1
596 && lyxrc.default_papersize == PAPER_A4PAPER )
597 || fl_get_choice(paper_->choice_papersize) == 7;
599 fl_set_choice(paper_->choice_paperpackage,
601 setEnabled(paper_->choice_paperpackage,
602 enable && fl_get_button(paper_->radio_portrait));
605 return ButtonPolicy::SMI_VALID;
609 bool FormDocument::class_apply(BufferParams ¶ms)
613 // If default skip is a "Length" but there's no text in the
614 // input field, reset the kind to "MedSkip", which is the default.
615 if (fl_get_choice(class_->choice_skip) == 4 &&
616 getString(class_->input_skip).empty()) {
617 fl_set_choice(class_->choice_skip, 2);
619 params.fonts = getString(class_->choice_fonts);
620 params.fontsize = getString(class_->choice_fontsize);
621 params.pagestyle = getString(class_->choice_pagestyle);
623 params.textclass = fl_get_combox(class_->combox_class) - 1;
625 BufferParams::PARSEP tmpsep = params.paragraph_separation;
626 if (fl_get_button(class_->radio_indent))
627 params.paragraph_separation = BufferParams::PARSEP_INDENT;
629 params.paragraph_separation = BufferParams::PARSEP_SKIP;
630 if (tmpsep != params.paragraph_separation)
633 VSpace tmpdefskip = params.getDefSkip();
634 switch (fl_get_choice(class_->choice_skip)) {
636 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
639 params.setDefSkip(VSpace(VSpace::MEDSKIP));
642 params.setDefSkip(VSpace(VSpace::BIGSKIP));
646 string const length =
647 getLengthFromWidgets(class_->input_skip,
648 class_->choice_skip_units);
650 params.setDefSkip(VSpace(LyXGlueLength(length)));
654 // DocumentDefskipCB assures that this never happens
655 params.setDefSkip(VSpace(VSpace::MEDSKIP));
658 if (!(tmpdefskip == params.getDefSkip()))
661 if (fl_get_button(class_->radio_columns_two))
665 if (fl_get_button(class_->radio_sides_two))
666 params.sides = LyXTextClass::TwoSides;
668 params.sides = LyXTextClass::OneSide;
670 Spacing tmpSpacing = params.spacing;
671 switch (fl_get_choice(class_->choice_spacing)) {
673 lyxerr[Debug::INFO] << "Spacing: SINGLE" << endl;
674 params.spacing.set(Spacing::Single);
677 lyxerr[Debug::INFO] << "Spacing: ONEHALF" << endl;
678 params.spacing.set(Spacing::Onehalf);
681 lyxerr[Debug::INFO] << "Spacing: DOUBLE" << endl;
682 params.spacing.set(Spacing::Double);
685 lyxerr[Debug::INFO] << "Spacing: OTHER" << endl;
686 params.spacing.set(Spacing::Other,
687 getString(class_->input_spacing));
690 if (tmpSpacing != params.spacing)
693 params.options = getString(class_->input_extra);
699 void FormDocument::paper_apply(BufferParams & params)
701 params.papersize2 = VMARGIN_PAPER_TYPE(fl_get_choice(paper_->choice_papersize) - 1);
703 params.paperpackage =
704 PAPER_PACKAGES(fl_get_choice(paper_->choice_paperpackage) - 1);
706 // set params.papersize from params.papersize2 and params.paperpackage
707 params.setPaperStuff();
709 params.use_geometry = fl_get_button(paper_->check_use_geometry);
711 if (fl_get_button(paper_->radio_landscape))
712 params.orientation = ORIENTATION_LANDSCAPE;
714 params.orientation = ORIENTATION_PORTRAIT;
717 getLengthFromWidgets(paper_->input_custom_width,
718 paper_->choice_custom_width_units);
721 getLengthFromWidgets(paper_->input_custom_height,
722 paper_->choice_custom_height_units);
725 getLengthFromWidgets(paper_->input_inner_margin,
726 paper_->choice_inner_margin_units);
729 getLengthFromWidgets(paper_->input_top_margin,
730 paper_->choice_top_margin_units);
733 getLengthFromWidgets(paper_->input_outer_margin,
734 paper_->choice_outer_margin_units);
736 params.bottommargin =
737 getLengthFromWidgets(paper_->input_bottom_margin,
738 paper_->choice_bottom_margin_units);
741 getLengthFromWidgets(paper_->input_head_height,
742 paper_->choice_head_height_units);
745 getLengthFromWidgets(paper_->input_head_sep,
746 paper_->choice_head_sep_units);
749 getLengthFromWidgets(paper_->input_foot_skip,
750 paper_->choice_foot_skip_units);
754 bool FormDocument::language_apply(BufferParams & params)
756 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
759 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
761 lga = InsetQuotes::EnglishQ;
764 lga = InsetQuotes::SwedishQ;
767 lga = InsetQuotes::GermanQ;
770 lga = InsetQuotes::PolishQ;
773 lga = InsetQuotes::FrenchQ;
776 lga = InsetQuotes::DanishQ;
779 params.quotes_language = lga;
780 if (fl_get_button(language_->radio_single))
781 params.quotes_times = InsetQuotes::SingleQ;
783 params.quotes_times = InsetQuotes::DoubleQ;
785 int const pos = fl_get_combox(language_->combox_language);
786 Language const * new_language = languages.getLanguage(lang_[pos-1]);
788 new_language = default_language;
790 params.language = new_language;
791 params.inputenc = getString(language_->choice_inputenc);
797 bool FormDocument::options_apply(BufferParams & params)
801 params.graphicsDriver = getString(options_->choice_postscript_driver);
802 params.use_amsmath = static_cast<BufferParams::AMS>(
803 fl_get_choice(options_->choice_ams_math) - 1);
804 params.use_natbib = fl_get_button(options_->check_use_natbib);
805 params.use_numerical_citations =
806 fl_get_choice(options_->choice_citation_format) - 1;
808 int tmpchar = int(fl_get_counter_value(options_->counter_secnumdepth));
809 if (params.secnumdepth != tmpchar)
811 params.secnumdepth = tmpchar;
813 params.tocdepth = int(fl_get_counter_value(options_->counter_tocdepth));
815 params.float_placement =
816 getString(options_->input_float_placement);
822 void FormDocument::bullets_apply(BufferParams & params)
824 /* update the bullet settings */
825 BufferParams & buf_params = controller().params();
827 for (int i = 0; i < 4; ++i) {
828 params.user_defined_bullets[i] = buf_params.temp_bullets[i];
833 void FormDocument::UpdateClassParams(BufferParams const & params)
835 // These are the params that have to be updated on any class change
836 // (even if the class defaults are not used) (JSpitzm 2002-04-08)
838 LyXTextClass const & tclass = textclasslist[params.textclass];
840 fl_set_combox(class_->combox_class, params.textclass + 1);
841 fl_clear_choice(class_->choice_fontsize);
842 fl_addto_choice(class_->choice_fontsize, "default");
843 fl_addto_choice(class_->choice_fontsize,
844 tclass.opt_fontsize().c_str());
845 fl_set_choice_text(class_->choice_fontsize,
846 params.fontsize.c_str());
847 fl_clear_choice(class_->choice_pagestyle);
848 fl_addto_choice(class_->choice_pagestyle, "default");
849 fl_addto_choice(class_->choice_pagestyle,
850 tclass.opt_pagestyle().c_str());
851 fl_set_choice_text(class_->choice_pagestyle,
852 params.pagestyle.c_str());
856 void FormDocument::class_update(BufferParams const & params)
861 UpdateClassParams(params);
863 fl_set_choice_text(class_->choice_fonts, params.fonts.c_str());
865 bool const indent = params.paragraph_separation == BufferParams::PARSEP_INDENT;
866 fl_set_button(class_->radio_indent, indent);
867 fl_set_button(class_->radio_skip, !indent);
871 pos = 2; // VSpace::MEDSKIP is default
873 switch (params.getDefSkip().kind()) {
877 case VSpace::BIGSKIP:
880 case VSpace::SMALLSKIP:
883 case VSpace::MEDSKIP:
889 fl_set_choice (class_->choice_skip, pos);
891 bool const length_input = pos == 4;
893 int const paperchoice = fl_get_choice(paper_->choice_papersize);
894 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > PAPER_EXECUTIVEPAPER)
895 || paperchoice == 2 || paperchoice > 5;
896 string const default_unit = metric ? "cm" : "in";
897 string const length = params.getDefSkip().asLyXCommand();
898 updateWidgetsFromLengthString(class_->input_skip,
899 class_->choice_skip_units,
900 length, default_unit);
903 fl_set_input(class_->input_skip, "");
905 setEnabled(class_->choice_skip, !indent);
906 setEnabled(class_->input_skip, length_input);
907 setEnabled(class_->choice_skip_units, length_input);
909 bool const two_sides = params.sides == LyXTextClass::TwoSides;
910 fl_set_button(class_->radio_sides_one, !two_sides);
911 fl_set_button(class_->radio_sides_two, two_sides);
913 bool const two_columns = params.columns == 2;
914 fl_set_button(class_->radio_columns_one, !two_columns);
915 fl_set_button(class_->radio_columns_two, two_columns);
917 fl_set_input(class_->input_extra, params.options.c_str());
919 switch (params.spacing.getSpace()) {
923 case Spacing::Double: // \doublespacing
926 case Spacing::Onehalf: // \onehalfspacing
929 case Spacing::Single: // \singlespacing
930 case Spacing::Default: // nothing bad should happen with this
935 fl_set_choice(class_->choice_spacing, pos);
937 bool const spacing_input = pos == 4;
938 setEnabled(class_->input_spacing, spacing_input);
939 string const input = spacing_input ? tostr(params.spacing.getValue()) : string();
940 fl_set_input(class_->input_spacing, input.c_str());
944 void FormDocument::language_update(BufferParams const & params)
946 if (!language_.get())
949 int const pos = int(findPos(lang_, params.language->lang()));
950 fl_set_combox(language_->combox_language, pos+1);
952 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
953 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
954 fl_set_button(language_->radio_single, 0);
955 fl_set_button(language_->radio_double, 0);
956 if (params.quotes_times == InsetQuotes::SingleQ)
957 fl_set_button(language_->radio_single, 1);
959 fl_set_button(language_->radio_double, 1);
963 void FormDocument::options_update(BufferParams const & params)
968 fl_set_choice_text(options_->choice_postscript_driver,
969 params.graphicsDriver.c_str());
970 fl_set_choice(options_->choice_ams_math, params.use_amsmath + 1);
971 fl_set_button(options_->check_use_natbib, params.use_natbib);
972 fl_set_choice(options_->choice_citation_format,
973 int(params.use_numerical_citations)+1);
974 setEnabled(options_->choice_citation_format, params.use_natbib);
975 fl_set_counter_value(options_->counter_secnumdepth, params.secnumdepth);
976 fl_set_counter_value(options_->counter_tocdepth, params.tocdepth);
977 if (!params.float_placement.empty())
978 fl_set_input(options_->input_float_placement,
979 params.float_placement.c_str());
981 fl_set_input(options_->input_float_placement, "");
985 void FormDocument::paper_update(BufferParams const & params)
990 fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
991 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
992 fl_set_button(paper_->check_use_geometry, params.use_geometry);
994 int const paperchoice = fl_get_choice(paper_->choice_papersize);
995 bool const useCustom = paperchoice == 2;
996 bool const useGeom = fl_get_button(paper_->check_use_geometry);
998 fl_set_button(paper_->radio_portrait, 0);
999 setEnabled(paper_->radio_portrait, !useCustom);
1000 fl_set_button(paper_->radio_landscape, 0);
1001 setEnabled(paper_->radio_landscape, !useCustom);
1003 if (params.orientation == ORIENTATION_LANDSCAPE)
1004 fl_set_button(paper_->radio_landscape, 1);
1006 fl_set_button(paper_->radio_portrait, 1);
1007 setEnabled(paper_->choice_paperpackage,
1008 //either default papersize (preferences)
1009 //or document papersize has to be A4
1011 || paperchoice == 1 && lyxrc.default_papersize == PAPER_A4PAPER)
1012 && fl_get_button(paper_->radio_portrait));
1014 // Default unit choice is cm if metric, inches if US paper.
1015 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > PAPER_EXECUTIVEPAPER)
1016 || paperchoice == 2 || paperchoice > 5;
1017 string const default_unit = metric ? "cm" : "in";
1018 updateWidgetsFromLengthString(paper_->input_custom_width,
1019 paper_->choice_custom_width_units,
1020 params.paperwidth, default_unit);
1021 setEnabled(paper_->input_custom_width, useCustom);
1022 setEnabled(paper_->choice_custom_width_units, useCustom);
1024 updateWidgetsFromLengthString(paper_->input_custom_height,
1025 paper_->choice_custom_height_units,
1026 params.paperheight, default_unit);
1027 setEnabled(paper_->input_custom_height, useCustom);
1028 setEnabled(paper_->choice_custom_height_units, useCustom);
1030 updateWidgetsFromLengthString(paper_->input_inner_margin,
1031 paper_->choice_inner_margin_units,
1032 params.leftmargin, default_unit);
1033 setEnabled(paper_->input_inner_margin, useGeom);
1034 setEnabled(paper_->choice_inner_margin_units, useGeom);
1036 updateWidgetsFromLengthString(paper_->input_top_margin,
1037 paper_->choice_top_margin_units,
1038 params.topmargin, default_unit);
1039 setEnabled(paper_->input_top_margin, useGeom);
1040 setEnabled(paper_->choice_top_margin_units, useGeom);
1042 updateWidgetsFromLengthString(paper_->input_outer_margin,
1043 paper_->choice_outer_margin_units,
1044 params.rightmargin, default_unit);
1045 setEnabled(paper_->input_outer_margin, useGeom);
1046 setEnabled(paper_->choice_outer_margin_units, useGeom);
1048 updateWidgetsFromLengthString(paper_->input_bottom_margin,
1049 paper_->choice_bottom_margin_units,
1050 params.bottommargin, default_unit);
1051 setEnabled(paper_->input_bottom_margin, useGeom);
1052 setEnabled(paper_->choice_bottom_margin_units, useGeom);
1054 updateWidgetsFromLengthString(paper_->input_head_height,
1055 paper_->choice_head_height_units,
1056 params.headheight, default_unit);
1057 setEnabled(paper_->input_head_height, useGeom);
1058 setEnabled(paper_->choice_head_height_units, useGeom);
1060 updateWidgetsFromLengthString(paper_->input_head_sep,
1061 paper_->choice_head_sep_units,
1062 params.headsep, default_unit);
1063 setEnabled(paper_->input_head_sep, useGeom);
1064 setEnabled(paper_->choice_head_sep_units, useGeom);
1066 updateWidgetsFromLengthString(paper_->input_foot_skip,
1067 paper_->choice_foot_skip_units,
1068 params.footskip, default_unit);
1069 setEnabled(paper_->input_foot_skip, useGeom);
1070 setEnabled(paper_->choice_foot_skip_units, useGeom);
1072 fl_set_focus_object(paper_->form, paper_->choice_papersize);
1076 void FormDocument::bullets_update(BufferParams const & params)
1078 if (!bullets_.get() ||
1080 (XpmVersion==4 && XpmRevision<7)))
1083 bool const isLinuxDoc =
1084 controller().docType() == ControlDocument::LINUXDOC;
1085 setEnabled(fbullet, !isLinuxDoc);
1087 if (isLinuxDoc) return;
1089 fl_set_button(bullets_->radio_depth_1, 1);
1090 fl_set_input(bullets_->input_latex,
1091 params.user_defined_bullets[0].getText().c_str());
1092 fl_set_choice(bullets_->choice_size,
1093 params.user_defined_bullets[0].getSize() + 2);
1097 void FormDocument::checkReadOnly()
1099 if (bc().readOnly(controller().bufferIsReadonly())) {
1100 postWarning(_("Document is read-only."
1101 " No changes to layout permitted."));
1108 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/)
1110 BufferParams & param = controller().params();
1112 // convert from 1-6 range to -1-4
1113 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1114 fl_set_input(bullets_->input_latex,
1115 param.temp_bullets[current_bullet_depth].getText().c_str());
1119 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1121 BufferParams & param = controller().params();
1123 param.temp_bullets[current_bullet_depth].
1124 setText(getString(bullets_->input_latex));
1128 void FormDocument::BulletDepth(FL_OBJECT * ob)
1130 /* Should I do the following: */
1131 /* 1. change to the panel that the current bullet belongs in */
1132 /* 2. show that bullet as selected */
1133 /* 3. change the size setting to the size of the bullet in Q.*/
1134 /* 4. display the latex equivalent in the latex box */
1136 /* I'm inclined to just go with 3 and 4 at the moment and */
1137 /* maybe try to support the others later */
1138 BufferParams & param = controller().params();
1141 if (ob == bullets_->radio_depth_1)
1143 else if (ob == bullets_->radio_depth_2)
1145 else if (ob == bullets_->radio_depth_3)
1147 else if (ob == bullets_->radio_depth_4)
1150 switch (fl_get_button_numb(ob)) {
1152 // right mouse button resets to default
1153 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1155 current_bullet_depth = data;
1156 fl_set_input(bullets_->input_latex,
1157 param.temp_bullets[data].getText().c_str());
1158 fl_set_choice(bullets_->choice_size,
1159 param.temp_bullets[data].getSize() + 2);
1164 void FormDocument::BulletPanel(FL_OBJECT * ob)
1166 /* Here we have to change the background pixmap to that selected */
1167 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1170 if (ob == bullets_->radio_panel_standard)
1172 else if (ob == bullets_->radio_panel_maths)
1174 else if (ob == bullets_->radio_panel_ding2)
1176 else if (ob == bullets_->radio_panel_ding3)
1178 else if (ob == bullets_->radio_panel_ding4)
1180 else if (ob == bullets_->radio_panel_ding1)
1183 if (data != current_bullet_panel) {
1184 fl_freeze_form(bullets_->form);
1185 current_bullet_panel = data;
1187 /* free the current pixmap */
1188 fl_free_bmtable_pixmap(bullets_->bmtable_panel);
1190 if (ob == bullets_->radio_panel_standard) {
1191 new_panel = "standard";
1192 } else if (ob == bullets_->radio_panel_maths ) {
1193 new_panel = "amssymb";
1194 } else if (ob == bullets_->radio_panel_ding2) {
1195 new_panel = "psnfss1";
1196 } else if (ob == bullets_->radio_panel_ding3) {
1197 new_panel = "psnfss2";
1198 } else if (ob == bullets_->radio_panel_ding4) {
1199 new_panel = "psnfss3";
1200 } else if (ob == bullets_->radio_panel_ding1) {
1201 new_panel = "psnfss4";
1203 /* something very wrong happened */
1204 // play it safe for now but should be an exception
1205 current_bullet_panel = 0; // standard panel
1206 new_panel = "standard";
1208 new_panel += ".xpm";
1209 fl_set_bmtable_pixmap_file(bullets_->bmtable_panel, 6, 6,
1210 LibFileSearch("images", new_panel).c_str());
1211 fl_redraw_object(bullets_->bmtable_panel);
1212 fl_unfreeze_form(bullets_->form);
1217 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/)
1219 /* handle the user input by setting the current bullet depth's pixmap */
1220 /* to that extracted from the current chosen position of the BMTable */
1221 /* Don't forget to free the button's old pixmap first. */
1223 BufferParams & param = controller().params();
1224 int bmtable_button = fl_get_bmtable(ob);
1226 /* try to keep the button held down till another is pushed */
1227 /* fl_set_bmtable(ob, 1, bmtable_button); */
1228 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1229 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1230 fl_set_input(bullets_->input_latex,
1231 param.temp_bullets[current_bullet_depth].getText().c_str());
1235 void FormDocument::CheckChoiceClass()
1237 BufferParams & params = controller().params();
1239 lyx::textclass_type const tc =
1240 fl_get_combox(class_->combox_class) - 1;
1242 if (controller().loadTextclass(tc)) {
1243 params.textclass = tc;
1245 if (lyxrc.auto_reset_options) {
1246 params.useClassDefaults();
1247 UpdateLayoutDocument(params);
1249 // update the params which are needed in any case
1250 // (fontsizes, pagestyle)
1251 UpdateClassParams(params);
1255 int const revert = int(params.textclass);
1256 fl_set_combox(class_->combox_class, revert + 1);
1261 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1267 class_update(params);
1268 paper_update(params);
1269 language_update(params);
1270 options_update(params);
1271 bullets_update(params);