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
38 #include "support/BoostFormat.h"
40 #include XPM_H_LOCATION
41 #include FORMS_H_LOCATION
44 #include <boost/bind.hpp>
54 #if FL_VERSION == 0 || (FL_REVISION == 0 && FL_FIXLEVEL < 2)
55 bool const scalableTabfolders = false;
57 bool const scalableTabfolders = true;
63 typedef FormCB<ControlDocument, FormDB<FD_document> > base_class;
65 FormDocument::FormDocument()
66 : base_class(_("Document Settings"), scalableTabfolders),
67 ActCell(0), Confirmed(0),
68 current_bullet_panel(0), current_bullet_depth(0), fbullet(0)
72 void FormDocument::redraw()
74 if (form() && form()->visible)
75 fl_redraw_form(form());
79 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder);
80 if (outer_form && outer_form->visible)
81 fl_redraw_form(outer_form);
85 void FormDocument::build()
88 dialog_.reset(build_document(this));
90 // Allow the base class to control messages
91 setMessageWidget(dialog_->text_warning);
93 // Manage the restore, ok, apply, restore and cancel/close buttons
94 bcview().setOK(dialog_->button_ok);
95 bcview().setApply(dialog_->button_apply);
96 bcview().setCancel(dialog_->button_close);
97 bcview().setRestore(dialog_->button_restore);
99 // the document class form
100 class_.reset(build_document_class(this));
102 // disable for read-only documents
103 bcview().addReadOnly(class_->combox_class);
104 bcview().addReadOnly(class_->radio_indent);
105 bcview().addReadOnly(class_->radio_skip);
106 bcview().addReadOnly(class_->choice_pagestyle);
107 bcview().addReadOnly(class_->choice_fonts);
108 bcview().addReadOnly(class_->choice_fontsize);
109 bcview().addReadOnly(class_->radio_sides_one);
110 bcview().addReadOnly(class_->radio_sides_two);
111 bcview().addReadOnly(class_->radio_columns_one);
112 bcview().addReadOnly(class_->radio_columns_two);
113 bcview().addReadOnly(class_->input_extra);
114 bcview().addReadOnly(class_->input_skip);
115 bcview().addReadOnly(class_->choice_skip);
116 bcview().addReadOnly(class_->choice_spacing);
117 bcview().addReadOnly(class_->input_spacing);
119 // check validity of "length + unit" input
120 addCheckedGlueLength(bcview(), class_->input_skip,
121 class_->choice_skip);
123 // trigger an input event for cut&paste with middle mouse button.
124 setPrehandler(class_->input_extra);
125 setPrehandler(class_->input_skip);
126 setPrehandler(class_->input_spacing);
128 fl_set_input_return(class_->input_extra, FL_RETURN_CHANGED);
129 fl_set_input_return(class_->input_skip, FL_RETURN_CHANGED);
130 fl_set_input_return(class_->input_spacing, FL_RETURN_CHANGED);
134 // Fill the combox and choices.
135 obj = class_->combox_class;
136 LyXTextClassList::const_iterator tit = textclasslist.begin();
137 LyXTextClassList::const_iterator tend = textclasslist.end();
138 for (; tit != tend; ++tit) {
139 if (tit->isTeXClassAvailable()) {
140 fl_addto_combox(obj, tit->description().c_str());
144 boost::io::str(boost::format(_("Unavailable: %1$s")) % tit->description());
146 _("Unavailable: ") + tit->description();
148 fl_addto_combox(obj, item.c_str());
151 fl_set_combox_browser_height(obj, 400);
153 fl_addto_choice(class_->choice_spacing,
154 _(" Single | OneHalf | Double | Custom "));
155 fl_addto_choice(class_->choice_fontsize, "default|10|11|12");
156 for (int n = 0; tex_fonts[n][0]; ++n) {
157 fl_addto_choice(class_->choice_fonts,tex_fonts[n]);
160 // Create the contents of the unit choices; don't include the
162 vector<string> units_vec = getLatexUnits();
163 vector<string>::iterator ret =
164 std::remove_if(units_vec.begin(),
166 bind2nd(contains_functor(), "%"));
167 units_vec.erase(ret, units_vec.end());
169 string const units = getStringFromVector(units_vec, "|");
171 fl_addto_choice(class_->choice_pagestyle,
172 "default|empty|plain|headings|fancy");
173 fl_addto_choice(class_->choice_skip,
174 _(" SmallSkip | MedSkip | BigSkip | Length "));
175 fl_addto_choice(class_->choice_skip_units, units.c_str());
177 // Set input filters on doc spacing to make it accept only
179 fl_set_input_filter(class_->input_spacing,
180 fl_unsigned_float_filter);
182 // disable for read-only documents
183 bcview().addReadOnly(dialog_->button_save_defaults);
184 bcview().addReadOnly(dialog_->button_reset_defaults);
186 // the document paper form
187 paper_.reset(build_document_paper(this));
189 // disable for read-only documents
190 bcview().addReadOnly(paper_->choice_paperpackage);
191 bcview().addReadOnly(paper_->radio_portrait);
192 bcview().addReadOnly(paper_->radio_landscape);
193 bcview().addReadOnly(paper_->choice_papersize);
194 bcview().addReadOnly(paper_->check_use_geometry);
195 bcview().addReadOnly(paper_->input_custom_width);
196 bcview().addReadOnly(paper_->input_custom_height);
197 bcview().addReadOnly(paper_->input_top_margin);
198 bcview().addReadOnly(paper_->input_bottom_margin);
199 bcview().addReadOnly(paper_->input_inner_margin);
200 bcview().addReadOnly(paper_->input_outer_margin);
201 bcview().addReadOnly(paper_->input_head_height);
202 bcview().addReadOnly(paper_->input_head_sep);
203 bcview().addReadOnly(paper_->input_foot_skip);
205 // check validity of "length + unit" input
206 addCheckedGlueLength(bcview(), paper_->input_custom_width);
207 addCheckedGlueLength(bcview(), paper_->input_custom_height);
208 addCheckedGlueLength(bcview(), paper_->input_top_margin);
209 addCheckedGlueLength(bcview(), paper_->input_bottom_margin);
210 addCheckedGlueLength(bcview(), paper_->input_inner_margin);
211 addCheckedGlueLength(bcview(), paper_->input_outer_margin);
212 addCheckedGlueLength(bcview(), paper_->input_head_height);
213 addCheckedGlueLength(bcview(), paper_->input_head_sep);
214 addCheckedGlueLength(bcview(), paper_->input_foot_skip);
216 // trigger an input event for cut&paste with middle mouse button.
217 setPrehandler(paper_->input_custom_width);
218 setPrehandler(paper_->input_custom_height);
219 setPrehandler(paper_->input_top_margin);
220 setPrehandler(paper_->input_bottom_margin);
221 setPrehandler(paper_->input_inner_margin);
222 setPrehandler(paper_->input_outer_margin);
223 setPrehandler(paper_->input_head_height);
224 setPrehandler(paper_->input_head_sep);
225 setPrehandler(paper_->input_foot_skip);
227 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
228 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
229 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
230 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
231 fl_set_input_return(paper_->input_inner_margin, FL_RETURN_CHANGED);
232 fl_set_input_return(paper_->input_outer_margin, FL_RETURN_CHANGED);
233 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
234 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
235 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
237 fl_addto_choice(paper_->choice_papersize,
238 _(" Default | Custom | US letter | US legal "
239 "| US executive | A3 | A4 | A5 | B3 | B4 | B5 "));
240 fl_addto_choice(paper_->choice_paperpackage,
243 "| Very small Margins "
244 "| Very wide Margins "));
246 fl_addto_choice(paper_->choice_custom_width_units, units.c_str());
247 fl_addto_choice(paper_->choice_custom_height_units, units.c_str());
248 fl_addto_choice(paper_->choice_top_margin_units, units.c_str());
249 fl_addto_choice(paper_->choice_bottom_margin_units, units.c_str());
250 fl_addto_choice(paper_->choice_inner_margin_units, units.c_str());
251 fl_addto_choice(paper_->choice_outer_margin_units, units.c_str());
252 fl_addto_choice(paper_->choice_head_height_units, units.c_str());
253 fl_addto_choice(paper_->choice_head_sep_units, units.c_str());
254 fl_addto_choice(paper_->choice_foot_skip_units, units.c_str());
256 // the document language form
257 language_.reset(build_document_language(this));
259 // disable for read-only documents
260 bcview().addReadOnly(language_->combox_language);
261 bcview().addReadOnly(language_->choice_inputenc);
262 bcview().addReadOnly(language_->choice_quotes_language);
263 bcview().addReadOnly(language_->radio_single);
264 bcview().addReadOnly(language_->radio_double);
266 fl_addto_choice(language_->choice_inputenc,
267 "default|auto|latin1|latin2|latin3|latin4|latin5|latin9"
268 "|koi8-r|koi8-u|cp866|cp1251|iso88595|pt154");
270 vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
271 // Store the identifiers for later
272 lang_ = getSecond(langs);
274 vector<frnt::LanguagePair>::const_iterator lit = langs.begin();
275 vector<frnt::LanguagePair>::const_iterator lend = langs.end();
276 for (; lit != lend; ++lit) {
277 fl_addto_combox(language_->combox_language,
280 fl_set_combox_browser_height(language_->combox_language, 400);
282 fl_addto_choice(language_->choice_quotes_language,
283 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
284 " «text» | »text« "));
286 // the document options form
287 options_.reset(build_document_options(this));
289 // disable for read-only documents
290 bcview().addReadOnly(options_->counter_secnumdepth);
291 bcview().addReadOnly(options_->counter_tocdepth);
292 bcview().addReadOnly(options_->choice_ams_math);
293 bcview().addReadOnly(options_->check_use_natbib);
294 bcview().addReadOnly(options_->choice_citation_format);
295 bcview().addReadOnly(options_->input_float_placement);
296 bcview().addReadOnly(options_->choice_postscript_driver);
298 // trigger an input event for cut&paste with middle mouse button.
299 setPrehandler(options_->input_float_placement);
301 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
303 fl_addto_choice(options_->choice_ams_math,
304 _("Never | Automatically | Yes "));
306 for (int n = 0; tex_graphics[n][0]; ++n) {
307 fl_addto_choice(options_->choice_postscript_driver,
310 fl_addto_choice(options_->choice_citation_format,
311 _(" Author-year | Numerical "));
313 // the document bullets form
314 bullets_.reset(build_document_bullet(this));
316 // disable for read-only documents
317 bcview().addReadOnly(bullets_->radio_depth_1);
318 bcview().addReadOnly(bullets_->radio_depth_2);
319 bcview().addReadOnly(bullets_->radio_depth_3);
320 bcview().addReadOnly(bullets_->radio_depth_4);
321 bcview().addReadOnly(bullets_->radio_panel_standard);
322 bcview().addReadOnly(bullets_->radio_panel_maths);
323 bcview().addReadOnly(bullets_->radio_panel_ding1);
324 bcview().addReadOnly(bullets_->radio_panel_ding2);
325 bcview().addReadOnly(bullets_->radio_panel_ding3);
326 bcview().addReadOnly(bullets_->radio_panel_ding4);
327 bcview().addReadOnly(bullets_->bmtable_panel);
328 bcview().addReadOnly(bullets_->choice_size);
329 bcview().addReadOnly(bullets_->input_latex);
331 // trigger an input event for cut&paste with middle mouse button.
332 setPrehandler(bullets_->input_latex);
334 fl_set_input_return(bullets_->input_latex, FL_RETURN_CHANGED);
336 fl_addto_choice(bullets_->choice_size,
337 _(" Default | Tiny | Smallest | Smaller | Small |"
338 " Normal | Large | Larger | Largest | Huge | Huger "));
339 fl_set_choice(bullets_->choice_size, 1);
341 fl_set_input_maxchars(bullets_->input_latex, 80);
343 string const bmtablefile = LibFileSearch("images", "standard", "xpm");
344 fl_set_bmtable_pixmap_file(bullets_->bmtable_panel, 6, 6,
345 bmtablefile.c_str());
347 // Enable the tabfolder to be rescaled correctly.
348 if (scalableTabfolders)
349 fl_set_tabfolder_autofit(dialog_->tabfolder, FL_FIT);
352 fl_addto_tabfolder(dialog_->tabfolder,_("Document"),
354 fl_addto_tabfolder(dialog_->tabfolder,_("Paper"),
356 fl_addto_tabfolder(dialog_->tabfolder,_("Language"),
358 fl_addto_tabfolder(dialog_->tabfolder,_("Extra"),
360 fbullet = fl_addto_tabfolder(dialog_->tabfolder,_("Bullets"),
363 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
364 lyxerr << _("Your version of libXpm is older than 4.7.\n"
365 "The `bullet' tab of the document dialog "
366 "has been disabled") << '\n';
367 fl_deactivate_object(fbullet);
368 fl_set_object_lcol(fbullet, FL_INACTIVE);
373 void FormDocument::apply()
375 BufferParams & params = controller().params();
379 language_apply(params);
380 options_apply(params);
381 bullets_apply(params);
385 void FormDocument::update()
392 BufferParams const & params = controller().params();
394 class_update(params);
395 paper_update(params);
396 language_update(params);
397 options_update(params);
398 bullets_update(params);
402 ButtonPolicy::SMInput FormDocument::input(FL_OBJECT * ob, long)
404 if (ob == bullets_->choice_size) {
405 ChoiceBulletSize(ob, 0);
407 } else if (ob == bullets_->input_latex) {
408 InputBulletLaTeX(ob, 0);
410 } else if (ob == bullets_->radio_depth_1 ||
411 ob == bullets_->radio_depth_2 ||
412 ob == bullets_->radio_depth_3 ||
413 ob == bullets_->radio_depth_4) {
416 } else if (ob == bullets_->radio_panel_standard ||
417 ob == bullets_->radio_panel_maths ||
418 ob == bullets_->radio_panel_ding1 ||
419 ob == bullets_->radio_panel_ding2 ||
420 ob == bullets_->radio_panel_ding3 ||
421 ob == bullets_->radio_panel_ding4) {
424 } else if (ob == bullets_->bmtable_panel) {
425 BulletBMTable(ob, 0);
427 } else if (ob == class_->choice_spacing) {
428 setEnabled(class_->input_spacing,
429 fl_get_choice(class_->choice_spacing) == 4);
431 } else if (ob == class_->combox_class) {
433 } else if (ob == class_->radio_skip ||
434 ob == class_->radio_indent ||
435 ob == class_->choice_skip) {
436 bool const skip_used = fl_get_button(class_->radio_skip);
437 setEnabled(class_->choice_skip, skip_used);
439 bool const length_input =
440 fl_get_choice(class_->choice_skip) == 4;
441 setEnabled(class_->input_skip,
442 skip_used && length_input);
443 setEnabled(class_->choice_skip_units,
444 skip_used && length_input);
446 // Default unit choice is cm if metric, inches if US paper.
447 // If papersize is default, check the lyxrc-settings
448 int const paperchoice = fl_get_choice(paper_->choice_papersize);
449 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
450 || paperchoice == 2 || paperchoice > 5;
451 string const default_unit = metric ? "cm" : "in";
452 if (getString(class_->input_skip).empty())
453 fl_set_choice_text(class_->choice_skip_units,
454 default_unit.c_str());
456 } else if (ob == options_->check_use_natbib) {
457 setEnabled(options_->choice_citation_format,
458 fl_get_button(options_->check_use_natbib));
460 } else if (ob == dialog_->button_save_defaults) {
462 controller().saveAsDefault();
464 } else if (ob == dialog_->button_reset_defaults) {
465 BufferParams & params = controller().params();
466 params.textclass = fl_get_combox(class_->combox_class) - 1;
467 params.useClassDefaults();
468 UpdateLayoutDocument(params);
470 } else if (ob == paper_->radio_landscape) {
471 fl_set_choice(paper_->choice_paperpackage,
472 BufferParams::PACKAGE_NONE + 1);
474 } else if (ob == paper_->choice_papersize) {
475 int const paperchoice = fl_get_choice(paper_->choice_papersize);
476 bool const defsize = paperchoice == 1;
477 bool const custom = paperchoice == 2;
478 bool const a3size = paperchoice == 6;
479 bool const b3size = paperchoice == 9;
480 bool const b4size = paperchoice == 10;
483 fl_set_button(paper_->radio_portrait, 1);
485 bool const use_geom = (custom || a3size || b3size || b4size);
487 fl_set_button(paper_->check_use_geometry, int(use_geom));
489 setEnabled(paper_->input_top_margin, use_geom);
490 setEnabled(paper_->input_bottom_margin, use_geom);
491 setEnabled(paper_->input_inner_margin, use_geom);
492 setEnabled(paper_->input_outer_margin, use_geom);
493 setEnabled(paper_->input_head_height, use_geom);
494 setEnabled(paper_->input_head_sep, use_geom);
495 setEnabled(paper_->input_foot_skip, use_geom);
496 setEnabled(paper_->choice_top_margin_units, use_geom);
497 setEnabled(paper_->choice_bottom_margin_units, use_geom);
498 setEnabled(paper_->choice_inner_margin_units, use_geom);
499 setEnabled(paper_->choice_outer_margin_units, use_geom);
500 setEnabled(paper_->choice_head_height_units, use_geom);
501 setEnabled(paper_->choice_head_sep_units, use_geom);
502 setEnabled(paper_->choice_foot_skip_units, use_geom);
503 setEnabled(paper_->choice_custom_width_units, use_geom);
504 setEnabled(paper_->choice_custom_height_units, use_geom);
506 setEnabled(paper_->input_custom_width, custom);
507 setEnabled(paper_->input_custom_height, custom);
508 setEnabled(paper_->choice_custom_width_units, custom);
509 setEnabled(paper_->choice_custom_height_units, custom);
510 setEnabled(paper_->radio_portrait, !custom);
511 setEnabled(paper_->radio_landscape, !custom);
513 // Default unit choice is cm if metric, inches if US paper.
514 // If papersize is default, use the lyxrc-settings
515 bool const metric = (defsize && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
516 || paperchoice == 2 || paperchoice > 5;
517 string const default_unit = metric ? "cm" : "in";
518 if (getString(paper_->input_custom_width).empty())
519 fl_set_choice_text(paper_->choice_custom_width_units,
520 default_unit.c_str());
521 if (getString(paper_->input_custom_height).empty())
522 fl_set_choice_text(paper_->choice_custom_height_units,
523 default_unit.c_str());
524 if (getString(paper_->input_top_margin).empty())
525 fl_set_choice_text(paper_->choice_top_margin_units,
526 default_unit.c_str());
527 if (getString(paper_->input_bottom_margin).empty())
528 fl_set_choice_text(paper_->choice_bottom_margin_units,
529 default_unit.c_str());
530 if (getString(paper_->input_inner_margin).empty())
531 fl_set_choice_text(paper_->choice_inner_margin_units,
532 default_unit.c_str());
533 if (getString(paper_->input_outer_margin).empty())
534 fl_set_choice_text(paper_->choice_outer_margin_units,
535 default_unit.c_str());
536 if (getString(paper_->input_head_height).empty())
537 fl_set_choice_text(paper_->choice_head_height_units,
538 default_unit.c_str());
539 if (getString(paper_->input_head_sep).empty())
540 fl_set_choice_text(paper_->choice_head_sep_units,
541 default_unit.c_str());
542 if (getString(paper_->input_foot_skip).empty())
543 fl_set_choice_text(paper_->choice_foot_skip_units,
544 default_unit.c_str());
546 } else if (ob == paper_->choice_paperpackage &&
547 fl_get_choice(paper_->choice_paperpackage) != 1) {
549 fl_set_button(paper_->check_use_geometry, 0);
550 setEnabled(paper_->input_top_margin, false);
551 setEnabled(paper_->input_bottom_margin, false);
552 setEnabled(paper_->input_inner_margin, false);
553 setEnabled(paper_->input_outer_margin, false);
554 setEnabled(paper_->input_head_height, false);
555 setEnabled(paper_->input_head_sep, false);
556 setEnabled(paper_->input_foot_skip, false);
557 setEnabled(paper_->choice_top_margin_units, false);
558 setEnabled(paper_->choice_bottom_margin_units, false);
559 setEnabled(paper_->choice_inner_margin_units, false);
560 setEnabled(paper_->choice_outer_margin_units, false);
561 setEnabled(paper_->choice_head_height_units, false);
562 setEnabled(paper_->choice_head_sep_units, false);
563 setEnabled(paper_->choice_foot_skip_units, false);
565 } else if (ob == paper_->check_use_geometry) {
566 // don't allow switching geometry off in custom papersize
567 // mode nor in A3, B3, and B4
568 int const choice = fl_get_choice(paper_->choice_papersize);
569 if (choice == 2 || choice == 6 || choice == 9 || choice == 10)
570 fl_set_button(paper_->check_use_geometry, 1);
572 fl_set_choice(paper_->choice_paperpackage,
573 BufferParams::PACKAGE_NONE + 1);
575 bool const use_geom = fl_get_button(paper_->check_use_geometry);
576 setEnabled(paper_->input_top_margin, use_geom);
577 setEnabled(paper_->input_bottom_margin, use_geom);
578 setEnabled(paper_->input_inner_margin, use_geom);
579 setEnabled(paper_->input_outer_margin, use_geom);
580 setEnabled(paper_->input_head_height, use_geom);
581 setEnabled(paper_->input_head_sep, use_geom);
582 setEnabled(paper_->input_foot_skip, use_geom);
583 setEnabled(paper_->choice_top_margin_units, use_geom);
584 setEnabled(paper_->choice_bottom_margin_units, use_geom);
585 setEnabled(paper_->choice_inner_margin_units, use_geom);
586 setEnabled(paper_->choice_outer_margin_units, use_geom);
587 setEnabled(paper_->choice_head_height_units, use_geom);
588 setEnabled(paper_->choice_head_sep_units, use_geom);
589 setEnabled(paper_->choice_foot_skip_units, use_geom);
592 if (ob == paper_->choice_papersize || ob == paper_->radio_portrait
593 || ob == paper_->radio_landscape) {
594 // either default papersize (preferences) or document
595 // papersize has to be A4
596 bool const enable = ( fl_get_choice(paper_->choice_papersize) == 1
597 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER )
598 || fl_get_choice(paper_->choice_papersize) == 7;
600 fl_set_choice(paper_->choice_paperpackage,
601 BufferParams::PACKAGE_NONE + 1);
602 setEnabled(paper_->choice_paperpackage,
603 enable && fl_get_button(paper_->radio_portrait));
606 return ButtonPolicy::SMI_VALID;
610 bool FormDocument::class_apply(BufferParams ¶ms)
614 // If default skip is a "Length" but there's no text in the
615 // input field, reset the kind to "MedSkip", which is the default.
616 if (fl_get_choice(class_->choice_skip) == 4 &&
617 getString(class_->input_skip).empty()) {
618 fl_set_choice(class_->choice_skip, 2);
620 params.fonts = getString(class_->choice_fonts);
621 params.fontsize = getString(class_->choice_fontsize);
622 params.pagestyle = getString(class_->choice_pagestyle);
624 params.textclass = fl_get_combox(class_->combox_class) - 1;
626 BufferParams::PARSEP tmpsep = params.paragraph_separation;
627 if (fl_get_button(class_->radio_indent))
628 params.paragraph_separation = BufferParams::PARSEP_INDENT;
630 params.paragraph_separation = BufferParams::PARSEP_SKIP;
631 if (tmpsep != params.paragraph_separation)
634 VSpace tmpdefskip = params.getDefSkip();
635 switch (fl_get_choice(class_->choice_skip)) {
637 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
640 params.setDefSkip(VSpace(VSpace::MEDSKIP));
643 params.setDefSkip(VSpace(VSpace::BIGSKIP));
647 string const length =
648 getLengthFromWidgets(class_->input_skip,
649 class_->choice_skip_units);
651 params.setDefSkip(VSpace(LyXGlueLength(length)));
655 // DocumentDefskipCB assures that this never happens
656 params.setDefSkip(VSpace(VSpace::MEDSKIP));
659 if (!(tmpdefskip == params.getDefSkip()))
662 if (fl_get_button(class_->radio_columns_two))
666 if (fl_get_button(class_->radio_sides_two))
667 params.sides = LyXTextClass::TwoSides;
669 params.sides = LyXTextClass::OneSide;
671 Spacing tmpSpacing = params.spacing;
672 switch (fl_get_choice(class_->choice_spacing)) {
674 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
675 params.spacing.set(Spacing::Single);
678 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
679 params.spacing.set(Spacing::Onehalf);
682 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
683 params.spacing.set(Spacing::Double);
686 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
687 params.spacing.set(Spacing::Other,
688 getString(class_->input_spacing));
691 if (tmpSpacing != params.spacing)
694 params.options = getString(class_->input_extra);
700 void FormDocument::paper_apply(BufferParams & params)
702 params.papersize2 = char(fl_get_choice(paper_->choice_papersize) - 1);
704 params.paperpackage =
705 char(fl_get_choice(paper_->choice_paperpackage) - 1);
707 // set params.papersize from params.papersize2 and params.paperpackage
708 params.setPaperStuff();
710 params.use_geometry = fl_get_button(paper_->check_use_geometry);
712 if (fl_get_button(paper_->radio_landscape))
713 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
715 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
718 getLengthFromWidgets(paper_->input_custom_width,
719 paper_->choice_custom_width_units);
722 getLengthFromWidgets(paper_->input_custom_height,
723 paper_->choice_custom_height_units);
726 getLengthFromWidgets(paper_->input_inner_margin,
727 paper_->choice_inner_margin_units);
730 getLengthFromWidgets(paper_->input_top_margin,
731 paper_->choice_top_margin_units);
734 getLengthFromWidgets(paper_->input_outer_margin,
735 paper_->choice_outer_margin_units);
737 params.bottommargin =
738 getLengthFromWidgets(paper_->input_bottom_margin,
739 paper_->choice_bottom_margin_units);
742 getLengthFromWidgets(paper_->input_head_height,
743 paper_->choice_head_height_units);
746 getLengthFromWidgets(paper_->input_head_sep,
747 paper_->choice_head_sep_units);
750 getLengthFromWidgets(paper_->input_foot_skip,
751 paper_->choice_foot_skip_units);
755 bool FormDocument::language_apply(BufferParams & params)
757 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
760 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
762 lga = InsetQuotes::EnglishQ;
765 lga = InsetQuotes::SwedishQ;
768 lga = InsetQuotes::GermanQ;
771 lga = InsetQuotes::PolishQ;
774 lga = InsetQuotes::FrenchQ;
777 lga = InsetQuotes::DanishQ;
780 params.quotes_language = lga;
781 if (fl_get_button(language_->radio_single))
782 params.quotes_times = InsetQuotes::SingleQ;
784 params.quotes_times = InsetQuotes::DoubleQ;
786 int const pos = fl_get_combox(language_->combox_language);
787 Language const * new_language = languages.getLanguage(lang_[pos-1]);
789 new_language = default_language;
791 params.language = new_language;
792 params.inputenc = getString(language_->choice_inputenc);
798 bool FormDocument::options_apply(BufferParams & params)
802 params.graphicsDriver = getString(options_->choice_postscript_driver);
803 params.use_amsmath = static_cast<BufferParams::AMS>(
804 fl_get_choice(options_->choice_ams_math) - 1);
805 params.use_natbib = fl_get_button(options_->check_use_natbib);
806 params.use_numerical_citations =
807 fl_get_choice(options_->choice_citation_format) - 1;
809 int tmpchar = int(fl_get_counter_value(options_->counter_secnumdepth));
810 if (params.secnumdepth != tmpchar)
812 params.secnumdepth = tmpchar;
814 params.tocdepth = int(fl_get_counter_value(options_->counter_tocdepth));
816 params.float_placement =
817 getString(options_->input_float_placement);
823 void FormDocument::bullets_apply(BufferParams & params)
825 /* update the bullet settings */
826 BufferParams & buf_params = controller().params();
828 for (int i = 0; i < 4; ++i) {
829 params.user_defined_bullets[i] = buf_params.temp_bullets[i];
834 void FormDocument::UpdateClassParams(BufferParams const & params)
836 // These are the params that have to be updated on any class change
837 // (even if the class defaults are not used) (JSpitzm 2002-04-08)
839 LyXTextClass const & tclass = textclasslist[params.textclass];
841 fl_set_combox(class_->combox_class, params.textclass + 1);
842 fl_clear_choice(class_->choice_fontsize);
843 fl_addto_choice(class_->choice_fontsize, "default");
844 fl_addto_choice(class_->choice_fontsize,
845 tclass.opt_fontsize().c_str());
846 fl_set_choice_text(class_->choice_fontsize,
847 params.fontsize.c_str());
848 fl_clear_choice(class_->choice_pagestyle);
849 fl_addto_choice(class_->choice_pagestyle, "default");
850 fl_addto_choice(class_->choice_pagestyle,
851 tclass.opt_pagestyle().c_str());
852 fl_set_choice_text(class_->choice_pagestyle,
853 params.pagestyle.c_str());
857 void FormDocument::class_update(BufferParams const & params)
862 UpdateClassParams(params);
864 fl_set_choice_text(class_->choice_fonts, params.fonts.c_str());
866 bool const indent = params.paragraph_separation == BufferParams::PARSEP_INDENT;
867 fl_set_button(class_->radio_indent, indent);
868 fl_set_button(class_->radio_skip, !indent);
872 pos = 2; // VSpace::MEDSKIP is default
874 switch (params.getDefSkip().kind()) {
878 case VSpace::BIGSKIP:
881 case VSpace::SMALLSKIP:
884 case VSpace::MEDSKIP:
890 fl_set_choice (class_->choice_skip, pos);
892 bool const length_input = pos == 4;
894 int const paperchoice = fl_get_choice(paper_->choice_papersize);
895 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
896 || paperchoice == 2 || paperchoice > 5;
897 string const default_unit = metric ? "cm" : "in";
898 string const length = params.getDefSkip().asLyXCommand();
899 updateWidgetsFromLengthString(class_->input_skip,
900 class_->choice_skip_units,
901 length, default_unit);
904 fl_set_input(class_->input_skip, "");
906 setEnabled(class_->choice_skip, !indent);
907 setEnabled(class_->input_skip, length_input);
908 setEnabled(class_->choice_skip_units, length_input);
910 bool const two_sides = params.sides == LyXTextClass::TwoSides;
911 fl_set_button(class_->radio_sides_one, !two_sides);
912 fl_set_button(class_->radio_sides_two, two_sides);
914 bool const two_columns = params.columns == 2;
915 fl_set_button(class_->radio_columns_one, !two_columns);
916 fl_set_button(class_->radio_columns_two, two_columns);
918 fl_set_input(class_->input_extra, params.options.c_str());
920 switch (params.spacing.getSpace()) {
924 case Spacing::Double: // \doublespacing
927 case Spacing::Onehalf: // \onehalfspacing
930 case Spacing::Single: // \singlespacing
931 case Spacing::Default: // nothing bad should happen with this
936 fl_set_choice(class_->choice_spacing, pos);
938 bool const spacing_input = pos == 4;
939 setEnabled(class_->input_spacing, spacing_input);
940 string const input = spacing_input ? tostr(params.spacing.getValue()) : string();
941 fl_set_input(class_->input_spacing, input.c_str());
945 void FormDocument::language_update(BufferParams const & params)
947 if (!language_.get())
950 int const pos = int(findPos(lang_, params.language->lang()));
951 fl_set_combox(language_->combox_language, pos+1);
953 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
954 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
955 fl_set_button(language_->radio_single, 0);
956 fl_set_button(language_->radio_double, 0);
957 if (params.quotes_times == InsetQuotes::SingleQ)
958 fl_set_button(language_->radio_single, 1);
960 fl_set_button(language_->radio_double, 1);
964 void FormDocument::options_update(BufferParams const & params)
969 fl_set_choice_text(options_->choice_postscript_driver,
970 params.graphicsDriver.c_str());
971 fl_set_choice(options_->choice_ams_math, params.use_amsmath + 1);
972 fl_set_button(options_->check_use_natbib, params.use_natbib);
973 fl_set_choice(options_->choice_citation_format,
974 int(params.use_numerical_citations)+1);
975 setEnabled(options_->choice_citation_format, params.use_natbib);
976 fl_set_counter_value(options_->counter_secnumdepth, params.secnumdepth);
977 fl_set_counter_value(options_->counter_tocdepth, params.tocdepth);
978 if (!params.float_placement.empty())
979 fl_set_input(options_->input_float_placement,
980 params.float_placement.c_str());
982 fl_set_input(options_->input_float_placement, "");
986 void FormDocument::paper_update(BufferParams const & params)
991 fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
992 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
993 fl_set_button(paper_->check_use_geometry, params.use_geometry);
995 int const paperchoice = fl_get_choice(paper_->choice_papersize);
996 bool const useCustom = paperchoice == 2;
997 bool const useGeom = fl_get_button(paper_->check_use_geometry);
999 fl_set_button(paper_->radio_portrait, 0);
1000 setEnabled(paper_->radio_portrait, !useCustom);
1001 fl_set_button(paper_->radio_landscape, 0);
1002 setEnabled(paper_->radio_landscape, !useCustom);
1004 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1005 fl_set_button(paper_->radio_landscape, 1);
1007 fl_set_button(paper_->radio_portrait, 1);
1008 setEnabled(paper_->choice_paperpackage,
1009 //either default papersize (preferences)
1010 //or document papersize has to be A4
1012 || paperchoice == 1 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER)
1013 && fl_get_button(paper_->radio_portrait));
1015 // Default unit choice is cm if metric, inches if US paper.
1016 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
1017 || paperchoice == 2 || paperchoice > 5;
1018 string const default_unit = metric ? "cm" : "in";
1019 updateWidgetsFromLengthString(paper_->input_custom_width,
1020 paper_->choice_custom_width_units,
1021 params.paperwidth, default_unit);
1022 setEnabled(paper_->input_custom_width, useCustom);
1023 setEnabled(paper_->choice_custom_width_units, useCustom);
1025 updateWidgetsFromLengthString(paper_->input_custom_height,
1026 paper_->choice_custom_height_units,
1027 params.paperheight, default_unit);
1028 setEnabled(paper_->input_custom_height, useCustom);
1029 setEnabled(paper_->choice_custom_height_units, useCustom);
1031 updateWidgetsFromLengthString(paper_->input_inner_margin,
1032 paper_->choice_inner_margin_units,
1033 params.leftmargin, default_unit);
1034 setEnabled(paper_->input_inner_margin, useGeom);
1035 setEnabled(paper_->choice_inner_margin_units, useGeom);
1037 updateWidgetsFromLengthString(paper_->input_top_margin,
1038 paper_->choice_top_margin_units,
1039 params.topmargin, default_unit);
1040 setEnabled(paper_->input_top_margin, useGeom);
1041 setEnabled(paper_->choice_top_margin_units, useGeom);
1043 updateWidgetsFromLengthString(paper_->input_outer_margin,
1044 paper_->choice_outer_margin_units,
1045 params.rightmargin, default_unit);
1046 setEnabled(paper_->input_outer_margin, useGeom);
1047 setEnabled(paper_->choice_outer_margin_units, useGeom);
1049 updateWidgetsFromLengthString(paper_->input_bottom_margin,
1050 paper_->choice_bottom_margin_units,
1051 params.bottommargin, default_unit);
1052 setEnabled(paper_->input_bottom_margin, useGeom);
1053 setEnabled(paper_->choice_bottom_margin_units, useGeom);
1055 updateWidgetsFromLengthString(paper_->input_head_height,
1056 paper_->choice_head_height_units,
1057 params.headheight, default_unit);
1058 setEnabled(paper_->input_head_height, useGeom);
1059 setEnabled(paper_->choice_head_height_units, useGeom);
1061 updateWidgetsFromLengthString(paper_->input_head_sep,
1062 paper_->choice_head_sep_units,
1063 params.headsep, default_unit);
1064 setEnabled(paper_->input_head_sep, useGeom);
1065 setEnabled(paper_->choice_head_sep_units, useGeom);
1067 updateWidgetsFromLengthString(paper_->input_foot_skip,
1068 paper_->choice_foot_skip_units,
1069 params.footskip, default_unit);
1070 setEnabled(paper_->input_foot_skip, useGeom);
1071 setEnabled(paper_->choice_foot_skip_units, useGeom);
1073 fl_set_focus_object(paper_->form, paper_->choice_papersize);
1077 void FormDocument::bullets_update(BufferParams const & params)
1079 if (!bullets_.get() ||
1081 (XpmVersion==4 && XpmRevision<7)))
1084 bool const isLinuxDoc =
1085 controller().docType() == ControlDocument::LINUXDOC;
1086 setEnabled(fbullet, !isLinuxDoc);
1088 if (isLinuxDoc) return;
1090 fl_set_button(bullets_->radio_depth_1, 1);
1091 fl_set_input(bullets_->input_latex,
1092 params.user_defined_bullets[0].getText().c_str());
1093 fl_set_choice(bullets_->choice_size,
1094 params.user_defined_bullets[0].getSize() + 2);
1098 void FormDocument::checkReadOnly()
1100 if (bc().readOnly(controller().bufferIsReadonly())) {
1101 postWarning(_("Document is read-only."
1102 " No changes to layout permitted."));
1109 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/)
1111 BufferParams & param = controller().params();
1113 // convert from 1-6 range to -1-4
1114 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1115 fl_set_input(bullets_->input_latex,
1116 param.temp_bullets[current_bullet_depth].getText().c_str());
1120 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1122 BufferParams & param = controller().params();
1124 param.temp_bullets[current_bullet_depth].
1125 setText(getString(bullets_->input_latex));
1129 void FormDocument::BulletDepth(FL_OBJECT * ob)
1131 /* Should I do the following: */
1132 /* 1. change to the panel that the current bullet belongs in */
1133 /* 2. show that bullet as selected */
1134 /* 3. change the size setting to the size of the bullet in Q.*/
1135 /* 4. display the latex equivalent in the latex box */
1137 /* I'm inclined to just go with 3 and 4 at the moment and */
1138 /* maybe try to support the others later */
1139 BufferParams & param = controller().params();
1142 if (ob == bullets_->radio_depth_1)
1144 else if (ob == bullets_->radio_depth_2)
1146 else if (ob == bullets_->radio_depth_3)
1148 else if (ob == bullets_->radio_depth_4)
1151 switch (fl_get_button_numb(ob)) {
1153 // right mouse button resets to default
1154 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1156 current_bullet_depth = data;
1157 fl_set_input(bullets_->input_latex,
1158 param.temp_bullets[data].getText().c_str());
1159 fl_set_choice(bullets_->choice_size,
1160 param.temp_bullets[data].getSize() + 2);
1165 void FormDocument::BulletPanel(FL_OBJECT * ob)
1167 /* Here we have to change the background pixmap to that selected */
1168 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1171 if (ob == bullets_->radio_panel_standard)
1173 else if (ob == bullets_->radio_panel_maths)
1175 else if (ob == bullets_->radio_panel_ding2)
1177 else if (ob == bullets_->radio_panel_ding3)
1179 else if (ob == bullets_->radio_panel_ding4)
1181 else if (ob == bullets_->radio_panel_ding1)
1184 if (data != current_bullet_panel) {
1185 fl_freeze_form(bullets_->form);
1186 current_bullet_panel = data;
1188 /* free the current pixmap */
1189 fl_free_bmtable_pixmap(bullets_->bmtable_panel);
1191 if (ob == bullets_->radio_panel_standard) {
1192 new_panel = "standard";
1193 } else if (ob == bullets_->radio_panel_maths ) {
1194 new_panel = "amssymb";
1195 } else if (ob == bullets_->radio_panel_ding2) {
1196 new_panel = "psnfss1";
1197 } else if (ob == bullets_->radio_panel_ding3) {
1198 new_panel = "psnfss2";
1199 } else if (ob == bullets_->radio_panel_ding4) {
1200 new_panel = "psnfss3";
1201 } else if (ob == bullets_->radio_panel_ding1) {
1202 new_panel = "psnfss4";
1204 /* something very wrong happened */
1205 // play it safe for now but should be an exception
1206 current_bullet_panel = 0; // standard panel
1207 new_panel = "standard";
1209 new_panel += ".xpm";
1210 fl_set_bmtable_pixmap_file(bullets_->bmtable_panel, 6, 6,
1211 LibFileSearch("images", new_panel).c_str());
1212 fl_redraw_object(bullets_->bmtable_panel);
1213 fl_unfreeze_form(bullets_->form);
1218 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/)
1220 /* handle the user input by setting the current bullet depth's pixmap */
1221 /* to that extracted from the current chosen position of the BMTable */
1222 /* Don't forget to free the button's old pixmap first. */
1224 BufferParams & param = controller().params();
1225 int bmtable_button = fl_get_bmtable(ob);
1227 /* try to keep the button held down till another is pushed */
1228 /* fl_set_bmtable(ob, 1, bmtable_button); */
1229 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1230 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1231 fl_set_input(bullets_->input_latex,
1232 param.temp_bullets[current_bullet_depth].getText().c_str());
1236 void FormDocument::CheckChoiceClass()
1238 BufferParams & params = controller().params();
1240 lyx::textclass_type const tc =
1241 fl_get_combox(class_->combox_class) - 1;
1243 if (controller().loadTextclass(tc)) {
1244 params.textclass = tc;
1246 if (lyxrc.auto_reset_options) {
1247 params.useClassDefaults();
1248 UpdateLayoutDocument(params);
1250 // update the params which are needed in any case
1251 // (fontsizes, pagestyle)
1252 UpdateClassParams(params);
1256 int const revert = int(params.textclass);
1257 fl_set_combox(class_->combox_class, revert + 1);
1262 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1268 class_update(params);
1269 paper_update(params);
1270 language_update(params);
1271 options_update(params);
1272 bullets_update(params);