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>
51 typedef FormCB<ControlDocument, FormDB<FD_document> > base_class;
53 FormDocument::FormDocument()
54 : base_class(_("Document Layout"), false),
55 ActCell(0), Confirmed(0),
56 current_bullet_panel(0), current_bullet_depth(0), fbullet(0)
60 void FormDocument::redraw()
62 if (form() && form()->visible)
63 fl_redraw_form(form());
67 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder);
68 if (outer_form && outer_form->visible)
69 fl_redraw_form(outer_form);
73 void FormDocument::build()
76 dialog_.reset(build_document(this));
78 // Allow the base class to control messages
79 setMessageWidget(dialog_->text_warning);
81 // Manage the restore, ok, apply, restore and cancel/close buttons
82 bcview().setOK(dialog_->button_ok);
83 bcview().setApply(dialog_->button_apply);
84 bcview().setCancel(dialog_->button_close);
85 bcview().setRestore(dialog_->button_restore);
87 // the document class form
88 class_.reset(build_document_class(this));
90 // disable for read-only documents
91 bcview().addReadOnly(class_->combox_doc_class);
92 bcview().addReadOnly(class_->radio_doc_indent);
93 bcview().addReadOnly(class_->radio_doc_skip);
94 bcview().addReadOnly(class_->choice_doc_pagestyle);
95 bcview().addReadOnly(class_->choice_doc_fonts);
96 bcview().addReadOnly(class_->choice_doc_fontsize);
97 bcview().addReadOnly(class_->radio_doc_sides_one);
98 bcview().addReadOnly(class_->radio_doc_sides_two);
99 bcview().addReadOnly(class_->radio_doc_columns_one);
100 bcview().addReadOnly(class_->radio_doc_columns_two);
101 bcview().addReadOnly(class_->input_doc_extra);
102 bcview().addReadOnly(class_->input_doc_skip);
103 bcview().addReadOnly(class_->choice_doc_skip);
104 bcview().addReadOnly(class_->choice_doc_spacing);
105 bcview().addReadOnly(class_->input_doc_spacing);
107 // check validity of "length + unit" input
108 addCheckedGlueLength(bcview(), class_->input_doc_skip,
109 class_->choice_doc_skip);
111 // trigger an input event for cut&paste with middle mouse button.
112 setPrehandler(class_->input_doc_extra);
113 setPrehandler(class_->input_doc_skip);
114 setPrehandler(class_->input_doc_spacing);
116 fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
117 fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
118 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
122 // Fill the combox and choices.
123 obj = class_->combox_doc_class;
124 LyXTextClassList::const_iterator tit = textclasslist.begin();
125 LyXTextClassList::const_iterator tend = textclasslist.end();
126 for (; tit != tend; ++tit) {
127 fl_addto_combox(obj, tit->description().c_str());
129 fl_set_combox_browser_height(obj, 400);
131 fl_addto_choice(class_->choice_doc_spacing,
132 _(" Single | OneHalf | Double | Custom "));
133 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
134 for (int n = 0; tex_fonts[n][0]; ++n) {
135 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
138 // Create the contents of the unit choices; don't include the
140 vector<string> units_vec = getLatexUnits();
141 vector<string>::iterator ret =
142 std::remove_if(units_vec.begin(),
144 bind2nd(contains_functor(), "%"));
145 units_vec.erase(ret, units_vec.end());
147 string const units = getStringFromVector(units_vec, "|");
149 fl_addto_choice(class_->choice_doc_pagestyle,
150 "default|empty|plain|headings|fancy");
151 fl_addto_choice(class_->choice_doc_skip,
152 _(" SmallSkip | MedSkip | BigSkip | Length "));
153 fl_addto_choice(class_->choice_doc_skip_units, units.c_str());
155 // Set input filters on doc spacing to make it accept only
157 fl_set_input_filter(class_->input_doc_spacing,
158 fl_unsigned_float_filter);
160 // disable for read-only documents
161 bcview().addReadOnly(dialog_->button_save_defaults);
162 bcview().addReadOnly(dialog_->button_reset_defaults);
164 // the document paper form
165 paper_.reset(build_document_paper(this));
167 // disable for read-only documents
168 bcview().addReadOnly(paper_->choice_paperpackage);
169 bcview().addReadOnly(paper_->radio_portrait);
170 bcview().addReadOnly(paper_->radio_landscape);
171 bcview().addReadOnly(paper_->choice_papersize);
172 bcview().addReadOnly(paper_->check_use_geometry);
173 bcview().addReadOnly(paper_->input_custom_width);
174 bcview().addReadOnly(paper_->input_custom_height);
175 bcview().addReadOnly(paper_->input_top_margin);
176 bcview().addReadOnly(paper_->input_bottom_margin);
177 bcview().addReadOnly(paper_->input_inner_margin);
178 bcview().addReadOnly(paper_->input_outer_margin);
179 bcview().addReadOnly(paper_->input_head_height);
180 bcview().addReadOnly(paper_->input_head_sep);
181 bcview().addReadOnly(paper_->input_foot_skip);
183 // check validity of "length + unit" input
184 addCheckedGlueLength(bcview(), paper_->input_custom_width);
185 addCheckedGlueLength(bcview(), paper_->input_custom_height);
186 addCheckedGlueLength(bcview(), paper_->input_top_margin);
187 addCheckedGlueLength(bcview(), paper_->input_bottom_margin);
188 addCheckedGlueLength(bcview(), paper_->input_inner_margin);
189 addCheckedGlueLength(bcview(), paper_->input_outer_margin);
190 addCheckedGlueLength(bcview(), paper_->input_head_height);
191 addCheckedGlueLength(bcview(), paper_->input_head_sep);
192 addCheckedGlueLength(bcview(), paper_->input_foot_skip);
194 // trigger an input event for cut&paste with middle mouse button.
195 setPrehandler(paper_->input_custom_width);
196 setPrehandler(paper_->input_custom_height);
197 setPrehandler(paper_->input_top_margin);
198 setPrehandler(paper_->input_bottom_margin);
199 setPrehandler(paper_->input_inner_margin);
200 setPrehandler(paper_->input_outer_margin);
201 setPrehandler(paper_->input_head_height);
202 setPrehandler(paper_->input_head_sep);
203 setPrehandler(paper_->input_foot_skip);
205 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
206 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
207 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
208 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
209 fl_set_input_return(paper_->input_inner_margin, FL_RETURN_CHANGED);
210 fl_set_input_return(paper_->input_outer_margin, FL_RETURN_CHANGED);
211 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
212 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
213 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
215 fl_addto_choice(paper_->choice_papersize,
216 _(" Default | Custom | US letter | US legal "
217 "| US executive | A3 | A4 | A5 | B3 | B4 | B5 "));
218 fl_addto_choice(paper_->choice_paperpackage,
221 "| Very small Margins "
222 "| Very wide Margins "));
224 fl_addto_choice(paper_->choice_custom_width_units, units.c_str());
225 fl_addto_choice(paper_->choice_custom_height_units, units.c_str());
226 fl_addto_choice(paper_->choice_top_margin_units, units.c_str());
227 fl_addto_choice(paper_->choice_bottom_margin_units, units.c_str());
228 fl_addto_choice(paper_->choice_inner_margin_units, units.c_str());
229 fl_addto_choice(paper_->choice_outer_margin_units, units.c_str());
230 fl_addto_choice(paper_->choice_head_height_units, units.c_str());
231 fl_addto_choice(paper_->choice_head_sep_units, units.c_str());
232 fl_addto_choice(paper_->choice_foot_skip_units, units.c_str());
234 // the document language form
235 language_.reset(build_document_language(this));
237 // disable for read-only documents
238 bcview().addReadOnly(language_->combox_language);
239 bcview().addReadOnly(language_->choice_inputenc);
240 bcview().addReadOnly(language_->choice_quotes_language);
241 bcview().addReadOnly(language_->radio_single);
242 bcview().addReadOnly(language_->radio_double);
244 fl_addto_choice(language_->choice_inputenc,
245 "default|auto|latin1|latin2|latin3|latin4|latin5|latin9"
246 "|koi8-r|koi8-u|cp866|cp1251|iso88595|pt154");
248 vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
249 // Store the identifiers for later
250 lang_ = getSecond(langs);
252 vector<frnt::LanguagePair>::const_iterator lit = langs.begin();
253 vector<frnt::LanguagePair>::const_iterator lend = langs.end();
254 for (; lit != lend; ++lit) {
255 fl_addto_combox(language_->combox_language,
258 fl_set_combox_browser_height(language_->combox_language, 400);
260 fl_addto_choice(language_->choice_quotes_language,
261 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
262 " «text» | »text« "));
264 // the document options form
265 options_.reset(build_document_options(this));
267 // disable for read-only documents
268 bcview().addReadOnly(options_->counter_secnumdepth);
269 bcview().addReadOnly(options_->counter_tocdepth);
270 bcview().addReadOnly(options_->choice_ams_math);
271 bcview().addReadOnly(options_->check_use_natbib);
272 bcview().addReadOnly(options_->choice_citation_format);
273 bcview().addReadOnly(options_->input_float_placement);
274 bcview().addReadOnly(options_->choice_postscript_driver);
276 // trigger an input event for cut&paste with middle mouse button.
277 setPrehandler(options_->input_float_placement);
279 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
281 fl_addto_choice(options_->choice_ams_math,
282 _("Never | Automatically | Yes "));
284 for (int n = 0; tex_graphics[n][0]; ++n) {
285 fl_addto_choice(options_->choice_postscript_driver,
288 fl_addto_choice(options_->choice_citation_format,
289 _(" Author-year | Numerical "));
291 // the document bullets form
292 bullets_.reset(build_document_bullet(this));
294 // disable for read-only documents
295 bcview().addReadOnly(bullets_->radio_bullet_depth_1);
296 bcview().addReadOnly(bullets_->radio_bullet_depth_2);
297 bcview().addReadOnly(bullets_->radio_bullet_depth_3);
298 bcview().addReadOnly(bullets_->radio_bullet_depth_4);
299 bcview().addReadOnly(bullets_->radio_bullet_panel_standard);
300 bcview().addReadOnly(bullets_->radio_bullet_panel_maths);
301 bcview().addReadOnly(bullets_->radio_bullet_panel_ding1);
302 bcview().addReadOnly(bullets_->radio_bullet_panel_ding2);
303 bcview().addReadOnly(bullets_->radio_bullet_panel_ding3);
304 bcview().addReadOnly(bullets_->radio_bullet_panel_ding4);
305 bcview().addReadOnly(bullets_->bmtable_bullet_panel);
306 bcview().addReadOnly(bullets_->choice_bullet_size);
307 bcview().addReadOnly(bullets_->input_bullet_latex);
309 // trigger an input event for cut&paste with middle mouse button.
310 setPrehandler(bullets_->input_bullet_latex);
312 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
314 fl_addto_choice(bullets_->choice_bullet_size,
315 _(" Default | Tiny | Smallest | Smaller | Small |"
316 " Normal | Large | Larger | Largest | Huge | Huger "));
317 fl_set_choice(bullets_->choice_bullet_size, 1);
319 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
321 string const bmtablefile = LibFileSearch("images", "standard", "xpm");
322 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
323 bmtablefile.c_str());
325 fl_addto_tabfolder(dialog_->tabfolder,_("Document"),
327 fl_addto_tabfolder(dialog_->tabfolder,_("Paper"),
329 fl_addto_tabfolder(dialog_->tabfolder,_("Language"),
331 fl_addto_tabfolder(dialog_->tabfolder,_("Extra"),
333 fbullet = fl_addto_tabfolder(dialog_->tabfolder,_("Bullets"),
336 // work-around xforms bug re update of folder->x, folder->y coords.
337 setPrehandler(dialog_->tabfolder);
339 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
340 lyxerr << _("Your version of libXpm is older than 4.7.\n"
341 "The `bullet' tab of the document dialog "
342 "has been disabled") << '\n';
343 fl_deactivate_object(fbullet);
344 fl_set_object_lcol(fbullet, FL_INACTIVE);
349 void FormDocument::apply()
351 BufferParams & params = controller().params();
355 language_apply(params);
356 options_apply(params);
357 bullets_apply(params);
361 void FormDocument::update()
368 BufferParams const & params = controller().params();
370 class_update(params);
371 paper_update(params);
372 language_update(params);
373 options_update(params);
374 bullets_update(params);
378 ButtonPolicy::SMInput FormDocument::input(FL_OBJECT * ob, long)
380 if (ob == bullets_->choice_bullet_size) {
381 ChoiceBulletSize(ob, 0);
383 } else if (ob == bullets_->input_bullet_latex) {
384 InputBulletLaTeX(ob, 0);
386 } else if (ob == bullets_->radio_bullet_depth_1 ||
387 ob == bullets_->radio_bullet_depth_2 ||
388 ob == bullets_->radio_bullet_depth_3 ||
389 ob == bullets_->radio_bullet_depth_4) {
392 } else if (ob == bullets_->radio_bullet_panel_standard ||
393 ob == bullets_->radio_bullet_panel_maths ||
394 ob == bullets_->radio_bullet_panel_ding1 ||
395 ob == bullets_->radio_bullet_panel_ding2 ||
396 ob == bullets_->radio_bullet_panel_ding3 ||
397 ob == bullets_->radio_bullet_panel_ding4) {
400 } else if (ob == bullets_->bmtable_bullet_panel) {
401 BulletBMTable(ob, 0);
403 } else if (ob == class_->choice_doc_spacing) {
404 setEnabled(class_->input_doc_spacing,
405 fl_get_choice(class_->choice_doc_spacing) == 4);
407 } else if (ob == class_->combox_doc_class) {
409 } else if (ob == class_->radio_doc_skip ||
410 ob == class_->radio_doc_indent ||
411 ob == class_->choice_doc_skip) {
412 bool const skip_used = fl_get_button(class_->radio_doc_skip);
413 setEnabled(class_->choice_doc_skip, skip_used);
415 bool const length_input =
416 fl_get_choice(class_->choice_doc_skip) == 4;
417 setEnabled(class_->input_doc_skip,
418 skip_used && length_input);
419 setEnabled(class_->choice_doc_skip_units,
420 skip_used && length_input);
422 // Default unit choice is cm if metric, inches if US paper.
423 // If papersize is default, check the lyxrc-settings
424 int const paperchoice = fl_get_choice(paper_->choice_papersize);
425 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
426 || paperchoice == 2 || paperchoice > 5;
427 string const default_unit = metric ? "cm" : "in";
428 if (getString(class_->input_doc_skip).empty())
429 fl_set_choice_text(class_->choice_doc_skip_units,
430 default_unit.c_str());
432 } else if (ob == options_->check_use_natbib) {
433 setEnabled(options_->choice_citation_format,
434 fl_get_button(options_->check_use_natbib));
436 } else if (ob == dialog_->button_save_defaults) {
438 controller().saveAsDefault();
440 } else if (ob == dialog_->button_reset_defaults) {
441 BufferParams & params = controller().params();
442 params.textclass = fl_get_combox(class_->combox_doc_class) - 1;
443 params.useClassDefaults();
444 UpdateLayoutDocument(params);
446 } else if (ob == paper_->radio_landscape) {
447 fl_set_choice(paper_->choice_paperpackage,
448 BufferParams::PACKAGE_NONE + 1);
450 } else if (ob == paper_->choice_papersize) {
451 int const paperchoice = fl_get_choice(paper_->choice_papersize);
452 bool const defsize = paperchoice == 1;
453 bool const custom = paperchoice == 2;
454 bool const a3size = paperchoice == 6;
455 bool const b3size = paperchoice == 9;
456 bool const b4size = paperchoice == 10;
459 fl_set_button(paper_->radio_portrait, 1);
461 bool const use_geom = (custom || a3size || b3size || b4size);
463 fl_set_button(paper_->check_use_geometry, int(use_geom));
465 setEnabled(paper_->input_top_margin, use_geom);
466 setEnabled(paper_->input_bottom_margin, use_geom);
467 setEnabled(paper_->input_inner_margin, use_geom);
468 setEnabled(paper_->input_outer_margin, use_geom);
469 setEnabled(paper_->input_head_height, use_geom);
470 setEnabled(paper_->input_head_sep, use_geom);
471 setEnabled(paper_->input_foot_skip, use_geom);
472 setEnabled(paper_->choice_top_margin_units, use_geom);
473 setEnabled(paper_->choice_bottom_margin_units, use_geom);
474 setEnabled(paper_->choice_inner_margin_units, use_geom);
475 setEnabled(paper_->choice_outer_margin_units, use_geom);
476 setEnabled(paper_->choice_head_height_units, use_geom);
477 setEnabled(paper_->choice_head_sep_units, use_geom);
478 setEnabled(paper_->choice_foot_skip_units, use_geom);
479 setEnabled(paper_->choice_custom_width_units, use_geom);
480 setEnabled(paper_->choice_custom_height_units, use_geom);
482 setEnabled(paper_->input_custom_width, custom);
483 setEnabled(paper_->input_custom_height, custom);
484 setEnabled(paper_->choice_custom_width_units, custom);
485 setEnabled(paper_->choice_custom_height_units, custom);
486 setEnabled(paper_->radio_portrait, !custom);
487 setEnabled(paper_->radio_landscape, !custom);
489 // Default unit choice is cm if metric, inches if US paper.
490 // If papersize is default, use the lyxrc-settings
491 bool const metric = (defsize && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
492 || paperchoice == 2 || paperchoice > 5;
493 string const default_unit = metric ? "cm" : "in";
494 if (getString(paper_->input_custom_width).empty())
495 fl_set_choice_text(paper_->choice_custom_width_units,
496 default_unit.c_str());
497 if (getString(paper_->input_custom_height).empty())
498 fl_set_choice_text(paper_->choice_custom_height_units,
499 default_unit.c_str());
500 if (getString(paper_->input_top_margin).empty())
501 fl_set_choice_text(paper_->choice_top_margin_units,
502 default_unit.c_str());
503 if (getString(paper_->input_bottom_margin).empty())
504 fl_set_choice_text(paper_->choice_bottom_margin_units,
505 default_unit.c_str());
506 if (getString(paper_->input_inner_margin).empty())
507 fl_set_choice_text(paper_->choice_inner_margin_units,
508 default_unit.c_str());
509 if (getString(paper_->input_outer_margin).empty())
510 fl_set_choice_text(paper_->choice_outer_margin_units,
511 default_unit.c_str());
512 if (getString(paper_->input_head_height).empty())
513 fl_set_choice_text(paper_->choice_head_height_units,
514 default_unit.c_str());
515 if (getString(paper_->input_head_sep).empty())
516 fl_set_choice_text(paper_->choice_head_sep_units,
517 default_unit.c_str());
518 if (getString(paper_->input_foot_skip).empty())
519 fl_set_choice_text(paper_->choice_foot_skip_units,
520 default_unit.c_str());
522 } else if (ob == paper_->choice_paperpackage &&
523 fl_get_choice(paper_->choice_paperpackage) != 1) {
525 fl_set_button(paper_->check_use_geometry, 0);
526 setEnabled(paper_->input_top_margin, false);
527 setEnabled(paper_->input_bottom_margin, false);
528 setEnabled(paper_->input_inner_margin, false);
529 setEnabled(paper_->input_outer_margin, false);
530 setEnabled(paper_->input_head_height, false);
531 setEnabled(paper_->input_head_sep, false);
532 setEnabled(paper_->input_foot_skip, false);
533 setEnabled(paper_->choice_top_margin_units, false);
534 setEnabled(paper_->choice_bottom_margin_units, false);
535 setEnabled(paper_->choice_inner_margin_units, false);
536 setEnabled(paper_->choice_outer_margin_units, false);
537 setEnabled(paper_->choice_head_height_units, false);
538 setEnabled(paper_->choice_head_sep_units, false);
539 setEnabled(paper_->choice_foot_skip_units, false);
541 } else if (ob == paper_->check_use_geometry) {
542 // don't allow switching geometry off in custom papersize
543 // mode nor in A3, B3, and B4
544 int const choice = fl_get_choice(paper_->choice_papersize);
545 if (choice == 2 || choice == 6 || choice == 9 || choice == 10)
546 fl_set_button(paper_->check_use_geometry, 1);
548 fl_set_choice(paper_->choice_paperpackage,
549 BufferParams::PACKAGE_NONE + 1);
551 bool const use_geom = fl_get_button(paper_->check_use_geometry);
552 setEnabled(paper_->input_top_margin, use_geom);
553 setEnabled(paper_->input_bottom_margin, use_geom);
554 setEnabled(paper_->input_inner_margin, use_geom);
555 setEnabled(paper_->input_outer_margin, use_geom);
556 setEnabled(paper_->input_head_height, use_geom);
557 setEnabled(paper_->input_head_sep, use_geom);
558 setEnabled(paper_->input_foot_skip, use_geom);
559 setEnabled(paper_->choice_top_margin_units, use_geom);
560 setEnabled(paper_->choice_bottom_margin_units, use_geom);
561 setEnabled(paper_->choice_inner_margin_units, use_geom);
562 setEnabled(paper_->choice_outer_margin_units, use_geom);
563 setEnabled(paper_->choice_head_height_units, use_geom);
564 setEnabled(paper_->choice_head_sep_units, use_geom);
565 setEnabled(paper_->choice_foot_skip_units, use_geom);
568 if (ob == paper_->choice_papersize || ob == paper_->radio_portrait
569 || ob == paper_->radio_landscape) {
570 // either default papersize (preferences) or document
571 // papersize has to be A4
572 bool const enable = ( fl_get_choice(paper_->choice_papersize) == 1
573 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER )
574 || fl_get_choice(paper_->choice_papersize) == 7;
576 fl_set_choice(paper_->choice_paperpackage,
577 BufferParams::PACKAGE_NONE + 1);
578 setEnabled(paper_->choice_paperpackage,
579 enable && fl_get_button(paper_->radio_portrait));
582 return ButtonPolicy::SMI_VALID;
586 bool FormDocument::class_apply(BufferParams ¶ms)
590 // If default skip is a "Length" but there's no text in the
591 // input field, reset the kind to "MedSkip", which is the default.
592 if (fl_get_choice(class_->choice_doc_skip) == 4 &&
593 getString(class_->input_doc_skip).empty()) {
594 fl_set_choice(class_->choice_doc_skip, 2);
596 params.fonts = getString(class_->choice_doc_fonts);
597 params.fontsize = getString(class_->choice_doc_fontsize);
598 params.pagestyle = getString(class_->choice_doc_pagestyle);
600 params.textclass = fl_get_combox(class_->combox_doc_class) - 1;
602 BufferParams::PARSEP tmpsep = params.paragraph_separation;
603 if (fl_get_button(class_->radio_doc_indent))
604 params.paragraph_separation = BufferParams::PARSEP_INDENT;
606 params.paragraph_separation = BufferParams::PARSEP_SKIP;
607 if (tmpsep != params.paragraph_separation)
610 VSpace tmpdefskip = params.getDefSkip();
611 switch (fl_get_choice(class_->choice_doc_skip)) {
613 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
616 params.setDefSkip(VSpace(VSpace::MEDSKIP));
619 params.setDefSkip(VSpace(VSpace::BIGSKIP));
623 string const length =
624 getLengthFromWidgets(class_->input_doc_skip,
625 class_->choice_doc_skip_units);
627 params.setDefSkip(VSpace(LyXGlueLength(length)));
631 // DocumentDefskipCB assures that this never happens
632 params.setDefSkip(VSpace(VSpace::MEDSKIP));
635 if (!(tmpdefskip == params.getDefSkip()))
638 if (fl_get_button(class_->radio_doc_columns_two))
642 if (fl_get_button(class_->radio_doc_sides_two))
643 params.sides = LyXTextClass::TwoSides;
645 params.sides = LyXTextClass::OneSide;
647 Spacing tmpSpacing = params.spacing;
648 switch (fl_get_choice(class_->choice_doc_spacing)) {
650 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
651 params.spacing.set(Spacing::Single);
654 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
655 params.spacing.set(Spacing::Onehalf);
658 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
659 params.spacing.set(Spacing::Double);
662 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
663 params.spacing.set(Spacing::Other,
664 getString(class_->input_doc_spacing));
667 if (tmpSpacing != params.spacing)
670 params.options = getString(class_->input_doc_extra);
676 void FormDocument::paper_apply(BufferParams & params)
678 params.papersize2 = char(fl_get_choice(paper_->choice_papersize) - 1);
680 params.paperpackage =
681 char(fl_get_choice(paper_->choice_paperpackage) - 1);
683 // set params.papersize from params.papersize2 and params.paperpackage
684 params.setPaperStuff();
686 params.use_geometry = fl_get_button(paper_->check_use_geometry);
688 if (fl_get_button(paper_->radio_landscape))
689 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
691 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
694 getLengthFromWidgets(paper_->input_custom_width,
695 paper_->choice_custom_width_units);
698 getLengthFromWidgets(paper_->input_custom_height,
699 paper_->choice_custom_height_units);
702 getLengthFromWidgets(paper_->input_inner_margin,
703 paper_->choice_inner_margin_units);
706 getLengthFromWidgets(paper_->input_top_margin,
707 paper_->choice_top_margin_units);
710 getLengthFromWidgets(paper_->input_outer_margin,
711 paper_->choice_outer_margin_units);
713 params.bottommargin =
714 getLengthFromWidgets(paper_->input_bottom_margin,
715 paper_->choice_bottom_margin_units);
718 getLengthFromWidgets(paper_->input_head_height,
719 paper_->choice_head_height_units);
722 getLengthFromWidgets(paper_->input_head_sep,
723 paper_->choice_head_sep_units);
726 getLengthFromWidgets(paper_->input_foot_skip,
727 paper_->choice_foot_skip_units);
731 bool FormDocument::language_apply(BufferParams & params)
733 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
736 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
738 lga = InsetQuotes::EnglishQ;
741 lga = InsetQuotes::SwedishQ;
744 lga = InsetQuotes::GermanQ;
747 lga = InsetQuotes::PolishQ;
750 lga = InsetQuotes::FrenchQ;
753 lga = InsetQuotes::DanishQ;
756 params.quotes_language = lga;
757 if (fl_get_button(language_->radio_single))
758 params.quotes_times = InsetQuotes::SingleQ;
760 params.quotes_times = InsetQuotes::DoubleQ;
762 int const pos = fl_get_combox(language_->combox_language);
763 Language const * new_language = languages.getLanguage(lang_[pos-1]);
765 new_language = default_language;
767 params.language = new_language;
768 params.inputenc = getString(language_->choice_inputenc);
774 bool FormDocument::options_apply(BufferParams & params)
778 params.graphicsDriver = getString(options_->choice_postscript_driver);
779 params.use_amsmath = static_cast<BufferParams::AMS>(
780 fl_get_choice(options_->choice_ams_math) - 1);
781 params.use_natbib = fl_get_button(options_->check_use_natbib);
782 params.use_numerical_citations =
783 fl_get_choice(options_->choice_citation_format) - 1;
785 int tmpchar = int(fl_get_counter_value(options_->counter_secnumdepth));
786 if (params.secnumdepth != tmpchar)
788 params.secnumdepth = tmpchar;
790 params.tocdepth = int(fl_get_counter_value(options_->counter_tocdepth));
792 params.float_placement =
793 getString(options_->input_float_placement);
799 void FormDocument::bullets_apply(BufferParams & params)
801 /* update the bullet settings */
802 BufferParams & buf_params = controller().params();
804 for (int i = 0; i < 4; ++i) {
805 params.user_defined_bullets[i] = buf_params.temp_bullets[i];
810 void FormDocument::UpdateClassParams(BufferParams const & params)
812 // These are the params that have to be updated on any class change
813 // (even if the class defaults are not used) (JSpitzm 2002-04-08)
815 LyXTextClass const & tclass = textclasslist[params.textclass];
817 fl_set_combox(class_->combox_doc_class, params.textclass + 1);
818 fl_clear_choice(class_->choice_doc_fontsize);
819 fl_addto_choice(class_->choice_doc_fontsize, "default");
820 fl_addto_choice(class_->choice_doc_fontsize,
821 tclass.opt_fontsize().c_str());
822 fl_set_choice_text(class_->choice_doc_fontsize,
823 params.fontsize.c_str());
824 fl_clear_choice(class_->choice_doc_pagestyle);
825 fl_addto_choice(class_->choice_doc_pagestyle, "default");
826 fl_addto_choice(class_->choice_doc_pagestyle,
827 tclass.opt_pagestyle().c_str());
828 fl_set_choice_text(class_->choice_doc_pagestyle,
829 params.pagestyle.c_str());
833 void FormDocument::class_update(BufferParams const & params)
838 UpdateClassParams(params);
840 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
842 bool const indent = params.paragraph_separation == BufferParams::PARSEP_INDENT;
843 fl_set_button(class_->radio_doc_indent, indent);
844 fl_set_button(class_->radio_doc_skip, !indent);
848 pos = 2; // VSpace::MEDSKIP is default
850 switch (params.getDefSkip().kind()) {
854 case VSpace::BIGSKIP:
857 case VSpace::SMALLSKIP:
860 case VSpace::MEDSKIP:
866 fl_set_choice (class_->choice_doc_skip, pos);
868 bool const length_input = pos == 4;
870 int const paperchoice = fl_get_choice(paper_->choice_papersize);
871 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
872 || paperchoice == 2 || paperchoice > 5;
873 string const default_unit = metric ? "cm" : "in";
874 string const length = params.getDefSkip().asLyXCommand();
875 updateWidgetsFromLengthString(class_->input_doc_skip,
876 class_->choice_doc_skip_units,
877 length, default_unit);
880 fl_set_input(class_->input_doc_skip, "");
882 setEnabled(class_->choice_doc_skip, !indent);
883 setEnabled(class_->input_doc_skip, length_input);
884 setEnabled(class_->choice_doc_skip_units, length_input);
886 bool const two_sides = params.sides == LyXTextClass::TwoSides;
887 fl_set_button(class_->radio_doc_sides_one, !two_sides);
888 fl_set_button(class_->radio_doc_sides_two, two_sides);
890 bool const two_columns = params.columns == 2;
891 fl_set_button(class_->radio_doc_columns_one, !two_columns);
892 fl_set_button(class_->radio_doc_columns_two, two_columns);
894 fl_set_input(class_->input_doc_extra, params.options.c_str());
896 switch (params.spacing.getSpace()) {
900 case Spacing::Double: // \doublespacing
903 case Spacing::Onehalf: // \onehalfspacing
906 case Spacing::Single: // \singlespacing
907 case Spacing::Default: // nothing bad should happen with this
912 fl_set_choice(class_->choice_doc_spacing, pos);
914 bool const spacing_input = pos == 4;
915 setEnabled(class_->input_doc_spacing, spacing_input);
916 string const input = spacing_input ? tostr(params.spacing.getValue()) : string();
917 fl_set_input(class_->input_doc_spacing, input.c_str());
921 void FormDocument::language_update(BufferParams const & params)
923 if (!language_.get())
926 int const pos = int(findPos(lang_, params.language->lang()));
927 fl_set_combox(language_->combox_language, pos+1);
929 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
930 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
931 fl_set_button(language_->radio_single, 0);
932 fl_set_button(language_->radio_double, 0);
933 if (params.quotes_times == InsetQuotes::SingleQ)
934 fl_set_button(language_->radio_single, 1);
936 fl_set_button(language_->radio_double, 1);
940 void FormDocument::options_update(BufferParams const & params)
945 fl_set_choice_text(options_->choice_postscript_driver,
946 params.graphicsDriver.c_str());
947 fl_set_choice(options_->choice_ams_math, params.use_amsmath + 1);
948 fl_set_button(options_->check_use_natbib, params.use_natbib);
949 fl_set_choice(options_->choice_citation_format,
950 int(params.use_numerical_citations)+1);
951 setEnabled(options_->choice_citation_format, params.use_natbib);
952 fl_set_counter_value(options_->counter_secnumdepth, params.secnumdepth);
953 fl_set_counter_value(options_->counter_tocdepth, params.tocdepth);
954 if (!params.float_placement.empty())
955 fl_set_input(options_->input_float_placement,
956 params.float_placement.c_str());
958 fl_set_input(options_->input_float_placement, "");
962 void FormDocument::paper_update(BufferParams const & params)
967 fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
968 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
969 fl_set_button(paper_->check_use_geometry, params.use_geometry);
971 int const paperchoice = fl_get_choice(paper_->choice_papersize);
972 bool const useCustom = paperchoice == 2;
973 bool const useGeom = fl_get_button(paper_->check_use_geometry);
975 fl_set_button(paper_->radio_portrait, 0);
976 setEnabled(paper_->radio_portrait, !useCustom);
977 fl_set_button(paper_->radio_landscape, 0);
978 setEnabled(paper_->radio_landscape, !useCustom);
980 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
981 fl_set_button(paper_->radio_landscape, 1);
983 fl_set_button(paper_->radio_portrait, 1);
984 setEnabled(paper_->choice_paperpackage,
985 //either default papersize (preferences)
986 //or document papersize has to be A4
988 || paperchoice == 1 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER)
989 && fl_get_button(paper_->radio_portrait));
991 // Default unit choice is cm if metric, inches if US paper.
992 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
993 || paperchoice == 2 || paperchoice > 5;
994 string const default_unit = metric ? "cm" : "in";
995 updateWidgetsFromLengthString(paper_->input_custom_width,
996 paper_->choice_custom_width_units,
997 params.paperwidth, default_unit);
998 setEnabled(paper_->input_custom_width, useCustom);
999 setEnabled(paper_->choice_custom_width_units, useCustom);
1001 updateWidgetsFromLengthString(paper_->input_custom_height,
1002 paper_->choice_custom_height_units,
1003 params.paperheight, default_unit);
1004 setEnabled(paper_->input_custom_height, useCustom);
1005 setEnabled(paper_->choice_custom_height_units, useCustom);
1007 updateWidgetsFromLengthString(paper_->input_inner_margin,
1008 paper_->choice_inner_margin_units,
1009 params.leftmargin, default_unit);
1010 setEnabled(paper_->input_inner_margin, useGeom);
1011 setEnabled(paper_->choice_inner_margin_units, useGeom);
1013 updateWidgetsFromLengthString(paper_->input_top_margin,
1014 paper_->choice_top_margin_units,
1015 params.topmargin, default_unit);
1016 setEnabled(paper_->input_top_margin, useGeom);
1017 setEnabled(paper_->choice_top_margin_units, useGeom);
1019 updateWidgetsFromLengthString(paper_->input_outer_margin,
1020 paper_->choice_outer_margin_units,
1021 params.rightmargin, default_unit);
1022 setEnabled(paper_->input_outer_margin, useGeom);
1023 setEnabled(paper_->choice_outer_margin_units, useGeom);
1025 updateWidgetsFromLengthString(paper_->input_bottom_margin,
1026 paper_->choice_bottom_margin_units,
1027 params.bottommargin, default_unit);
1028 setEnabled(paper_->input_bottom_margin, useGeom);
1029 setEnabled(paper_->choice_bottom_margin_units, useGeom);
1031 updateWidgetsFromLengthString(paper_->input_head_height,
1032 paper_->choice_head_height_units,
1033 params.headheight, default_unit);
1034 setEnabled(paper_->input_head_height, useGeom);
1035 setEnabled(paper_->choice_head_height_units, useGeom);
1037 updateWidgetsFromLengthString(paper_->input_head_sep,
1038 paper_->choice_head_sep_units,
1039 params.headsep, default_unit);
1040 setEnabled(paper_->input_head_sep, useGeom);
1041 setEnabled(paper_->choice_head_sep_units, useGeom);
1043 updateWidgetsFromLengthString(paper_->input_foot_skip,
1044 paper_->choice_foot_skip_units,
1045 params.footskip, default_unit);
1046 setEnabled(paper_->input_foot_skip, useGeom);
1047 setEnabled(paper_->choice_foot_skip_units, useGeom);
1049 fl_set_focus_object(paper_->form, paper_->choice_papersize);
1053 void FormDocument::bullets_update(BufferParams const & params)
1055 if (!bullets_.get() ||
1057 (XpmVersion==4 && XpmRevision<7)))
1060 bool const isLinuxDoc =
1061 controller().docType() == ControlDocument::LINUXDOC;
1062 setEnabled(fbullet, !isLinuxDoc);
1064 if (isLinuxDoc) return;
1066 fl_set_button(bullets_->radio_bullet_depth_1, 1);
1067 fl_set_input(bullets_->input_bullet_latex,
1068 params.user_defined_bullets[0].getText().c_str());
1069 fl_set_choice(bullets_->choice_bullet_size,
1070 params.user_defined_bullets[0].getSize() + 2);
1074 void FormDocument::checkReadOnly()
1076 if (bc().readOnly(controller().bufferIsReadonly())) {
1077 postWarning(_("Document is read-only."
1078 " No changes to layout permitted."));
1085 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/)
1087 BufferParams & param = controller().params();
1089 // convert from 1-6 range to -1-4
1090 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1091 fl_set_input(bullets_->input_bullet_latex,
1092 param.temp_bullets[current_bullet_depth].getText().c_str());
1096 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1098 BufferParams & param = controller().params();
1100 param.temp_bullets[current_bullet_depth].
1101 setText(getString(bullets_->input_bullet_latex));
1105 void FormDocument::BulletDepth(FL_OBJECT * ob)
1107 /* Should I do the following: */
1108 /* 1. change to the panel that the current bullet belongs in */
1109 /* 2. show that bullet as selected */
1110 /* 3. change the size setting to the size of the bullet in Q.*/
1111 /* 4. display the latex equivalent in the latex box */
1113 /* I'm inclined to just go with 3 and 4 at the moment and */
1114 /* maybe try to support the others later */
1115 BufferParams & param = controller().params();
1118 if (ob == bullets_->radio_bullet_depth_1)
1120 else if (ob == bullets_->radio_bullet_depth_2)
1122 else if (ob == bullets_->radio_bullet_depth_3)
1124 else if (ob == bullets_->radio_bullet_depth_4)
1127 switch (fl_get_button_numb(ob)) {
1129 // right mouse button resets to default
1130 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1132 current_bullet_depth = data;
1133 fl_set_input(bullets_->input_bullet_latex,
1134 param.temp_bullets[data].getText().c_str());
1135 fl_set_choice(bullets_->choice_bullet_size,
1136 param.temp_bullets[data].getSize() + 2);
1141 void FormDocument::BulletPanel(FL_OBJECT * ob)
1143 /* Here we have to change the background pixmap to that selected */
1144 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1147 if (ob == bullets_->radio_bullet_panel_standard)
1149 else if (ob == bullets_->radio_bullet_panel_maths)
1151 else if (ob == bullets_->radio_bullet_panel_ding2)
1153 else if (ob == bullets_->radio_bullet_panel_ding3)
1155 else if (ob == bullets_->radio_bullet_panel_ding4)
1157 else if (ob == bullets_->radio_bullet_panel_ding1)
1160 if (data != current_bullet_panel) {
1161 fl_freeze_form(bullets_->form);
1162 current_bullet_panel = data;
1164 /* free the current pixmap */
1165 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1167 if (ob == bullets_->radio_bullet_panel_standard) {
1168 new_panel = "standard";
1169 } else if (ob == bullets_->radio_bullet_panel_maths ) {
1170 new_panel = "amssymb";
1171 } else if (ob == bullets_->radio_bullet_panel_ding2) {
1172 new_panel = "psnfss1";
1173 } else if (ob == bullets_->radio_bullet_panel_ding3) {
1174 new_panel = "psnfss2";
1175 } else if (ob == bullets_->radio_bullet_panel_ding4) {
1176 new_panel = "psnfss3";
1177 } else if (ob == bullets_->radio_bullet_panel_ding1) {
1178 new_panel = "psnfss4";
1180 /* something very wrong happened */
1181 // play it safe for now but should be an exception
1182 current_bullet_panel = 0; // standard panel
1183 new_panel = "standard";
1185 new_panel += ".xpm";
1186 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1187 LibFileSearch("images", new_panel).c_str());
1188 fl_redraw_object(bullets_->bmtable_bullet_panel);
1189 fl_unfreeze_form(bullets_->form);
1194 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/)
1196 /* handle the user input by setting the current bullet depth's pixmap */
1197 /* to that extracted from the current chosen position of the BMTable */
1198 /* Don't forget to free the button's old pixmap first. */
1200 BufferParams & param = controller().params();
1201 int bmtable_button = fl_get_bmtable(ob);
1203 /* try to keep the button held down till another is pushed */
1204 /* fl_set_bmtable(ob, 1, bmtable_button); */
1205 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1206 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1207 fl_set_input(bullets_->input_bullet_latex,
1208 param.temp_bullets[current_bullet_depth].getText().c_str());
1212 void FormDocument::CheckChoiceClass()
1214 BufferParams & params = controller().params();
1216 lyx::textclass_type const tc =
1217 fl_get_combox(class_->combox_doc_class) - 1;
1219 if (controller().loadTextclass(tc)) {
1220 params.textclass = tc;
1222 if (lyxrc.auto_reset_options) {
1223 params.useClassDefaults();
1224 UpdateLayoutDocument(params);
1226 // update the params which are needed in any case
1227 // (fontsizes, pagestyle)
1228 UpdateClassParams(params);
1232 int const revert = int(params.textclass);
1233 fl_set_combox(class_->combox_doc_class, revert + 1);
1238 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1244 class_update(params);
1245 paper_update(params);
1246 language_update(params);
1247 options_update(params);
1248 bullets_update(params);