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"
24 #include "input_validators.h" // fl_unsigned_float_filter
25 #include "xforms_helpers.h"
27 #include "CutAndPaste.h"
31 #include "lyxtextclasslist.h"
32 #include "tex-strings.h"
34 #include "controllers/frnt_lang.h"
35 #include "controllers/helper_funcs.h"
37 #include "support/lstrings.h" // contains_functor, getStringFromVector
38 #include "support/filetools.h" // LibFileSearch
40 #include XPM_H_LOCATION
41 #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_->radio_doc_indent);
92 bcview().addReadOnly(class_->radio_doc_skip);
93 bcview().addReadOnly(class_->choice_doc_pagestyle);
94 bcview().addReadOnly(class_->choice_doc_fonts);
95 bcview().addReadOnly(class_->choice_doc_fontsize);
96 bcview().addReadOnly(class_->radio_doc_sides_one);
97 bcview().addReadOnly(class_->radio_doc_sides_two);
98 bcview().addReadOnly(class_->radio_doc_columns_one);
99 bcview().addReadOnly(class_->radio_doc_columns_two);
100 bcview().addReadOnly(class_->input_doc_extra);
101 bcview().addReadOnly(class_->input_doc_skip);
102 bcview().addReadOnly(class_->choice_doc_skip);
103 bcview().addReadOnly(class_->choice_doc_spacing);
104 bcview().addReadOnly(class_->input_doc_spacing);
106 // check validity of "length + unit" input
107 addCheckedGlueLength(bcview(), class_->input_doc_skip,
108 class_->choice_doc_skip);
110 // trigger an input event for cut&paste with middle mouse button.
111 setPrehandler(class_->input_doc_extra);
112 setPrehandler(class_->input_doc_skip);
113 setPrehandler(class_->input_doc_spacing);
115 fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
116 fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
117 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
121 // the class list is a combo-box and has to be inserted manually
122 obj = class_->choice_doc_class;
123 fl_deactivate_object(obj);
124 fl_addto_form(class_->form);
125 combo_doc_class.reset(new Combox(FL_COMBOX_DROPLIST));
126 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400);
127 combo_doc_class->shortcut("#C",1);
128 combo_doc_class->setcallback(ComboInputCB, this);
130 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
131 cit != textclasslist.end(); ++cit) {
132 combo_doc_class->addto(cit->description());
135 fl_addto_choice(class_->choice_doc_spacing,
136 _(" Single | OneHalf | Double | Custom "));
137 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
138 for (int n = 0; tex_fonts[n][0]; ++n) {
139 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
142 // Create the contents of the unit choices; don't include the
144 vector<string> units_vec = getLatexUnits();
145 vector<string>::iterator ret =
146 std::remove_if(units_vec.begin(),
148 bind2nd(contains_functor(), "%"));
149 units_vec.erase(ret, units_vec.end());
151 string const units = getStringFromVector(units_vec, "|");
153 fl_addto_choice(class_->choice_doc_pagestyle,
154 "default|empty|plain|headings|fancy");
155 fl_addto_choice(class_->choice_doc_skip,
156 _(" SmallSkip | MedSkip | BigSkip | Length "));
157 fl_addto_choice(class_->choice_doc_skip_units, units.c_str());
159 // Set input filters on doc spacing to make it accept only
161 fl_set_input_filter(class_->input_doc_spacing,
162 fl_unsigned_float_filter);
164 // disable for read-only documents
165 bcview().addReadOnly(dialog_->button_save_defaults);
166 bcview().addReadOnly(dialog_->button_reset_defaults);
168 // the document paper form
169 paper_.reset(build_document_paper(this));
171 // disable for read-only documents
172 bcview().addReadOnly(paper_->choice_paperpackage);
173 bcview().addReadOnly(paper_->radio_portrait);
174 bcview().addReadOnly(paper_->radio_landscape);
175 bcview().addReadOnly(paper_->choice_papersize);
176 bcview().addReadOnly(paper_->check_use_geometry);
177 bcview().addReadOnly(paper_->input_custom_width);
178 bcview().addReadOnly(paper_->input_custom_height);
179 bcview().addReadOnly(paper_->input_top_margin);
180 bcview().addReadOnly(paper_->input_bottom_margin);
181 bcview().addReadOnly(paper_->input_inner_margin);
182 bcview().addReadOnly(paper_->input_outer_margin);
183 bcview().addReadOnly(paper_->input_head_height);
184 bcview().addReadOnly(paper_->input_head_sep);
185 bcview().addReadOnly(paper_->input_foot_skip);
187 // check validity of "length + unit" input
188 addCheckedGlueLength(bcview(), paper_->input_custom_width);
189 addCheckedGlueLength(bcview(), paper_->input_custom_height);
190 addCheckedGlueLength(bcview(), paper_->input_top_margin);
191 addCheckedGlueLength(bcview(), paper_->input_bottom_margin);
192 addCheckedGlueLength(bcview(), paper_->input_inner_margin);
193 addCheckedGlueLength(bcview(), paper_->input_outer_margin);
194 addCheckedGlueLength(bcview(), paper_->input_head_height);
195 addCheckedGlueLength(bcview(), paper_->input_head_sep);
196 addCheckedGlueLength(bcview(), paper_->input_foot_skip);
198 // trigger an input event for cut&paste with middle mouse button.
199 setPrehandler(paper_->input_custom_width);
200 setPrehandler(paper_->input_custom_height);
201 setPrehandler(paper_->input_top_margin);
202 setPrehandler(paper_->input_bottom_margin);
203 setPrehandler(paper_->input_inner_margin);
204 setPrehandler(paper_->input_outer_margin);
205 setPrehandler(paper_->input_head_height);
206 setPrehandler(paper_->input_head_sep);
207 setPrehandler(paper_->input_foot_skip);
209 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
210 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
211 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
212 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
213 fl_set_input_return(paper_->input_inner_margin, FL_RETURN_CHANGED);
214 fl_set_input_return(paper_->input_outer_margin, FL_RETURN_CHANGED);
215 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
216 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
217 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
219 fl_addto_choice(paper_->choice_papersize,
220 _(" Default | Custom | US letter | US legal "
221 "| US executive | A3 | A4 | A5 | B3 | B4 | B5 "));
222 fl_addto_choice(paper_->choice_paperpackage,
225 "| Very small Margins "
226 "| Very wide Margins "));
228 fl_addto_choice(paper_->choice_custom_width_units, units.c_str());
229 fl_addto_choice(paper_->choice_custom_height_units, units.c_str());
230 fl_addto_choice(paper_->choice_top_margin_units, units.c_str());
231 fl_addto_choice(paper_->choice_bottom_margin_units, units.c_str());
232 fl_addto_choice(paper_->choice_inner_margin_units, units.c_str());
233 fl_addto_choice(paper_->choice_outer_margin_units, units.c_str());
234 fl_addto_choice(paper_->choice_head_height_units, units.c_str());
235 fl_addto_choice(paper_->choice_head_sep_units, units.c_str());
236 fl_addto_choice(paper_->choice_foot_skip_units, units.c_str());
238 // the document language form
239 language_.reset(build_document_language(this));
241 // disable for read-only documents
242 bcview().addReadOnly(language_->choice_inputenc);
243 bcview().addReadOnly(language_->choice_quotes_language);
244 bcview().addReadOnly(language_->radio_single);
245 bcview().addReadOnly(language_->radio_double);
247 fl_addto_choice(language_->choice_inputenc,
248 "default|auto|latin1|latin2|latin3|latin4|latin5|latin9"
249 "|koi8-r|koi8-u|cp866|cp1251|iso88595|pt154");
251 vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
252 // Store the identifiers for later
253 lang_ = getSecond(langs);
255 // The language is a combo-box and has to be inserted manually
256 obj = language_->choice_language;
257 fl_deactivate_object(obj);
258 fl_addto_form(language_->form);
259 combo_language.reset(new Combox(FL_COMBOX_DROPLIST));
260 combo_language->add(obj->x, obj->y, obj->w, obj->h, 400);
261 combo_language->shortcut("#L",1);
262 combo_language->setcallback(ComboInputCB, this);
265 vector<frnt::LanguagePair>::const_iterator lit = langs.begin();
266 vector<frnt::LanguagePair>::const_iterator lend = langs.end();
267 for (; lit != lend; ++lit) {
268 combo_language->addto(lit->first);
270 combo_language->select(1);
272 fl_addto_choice(language_->choice_quotes_language,
273 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
274 " «text» | »text« "));
276 // the document options form
277 options_.reset(build_document_options(this));
279 // disable for read-only documents
280 bcview().addReadOnly(options_->counter_secnumdepth);
281 bcview().addReadOnly(options_->counter_tocdepth);
282 bcview().addReadOnly(options_->choice_ams_math);
283 bcview().addReadOnly(options_->check_use_natbib);
284 bcview().addReadOnly(options_->choice_citation_format);
285 bcview().addReadOnly(options_->input_float_placement);
286 bcview().addReadOnly(options_->choice_postscript_driver);
288 // trigger an input event for cut&paste with middle mouse button.
289 setPrehandler(options_->input_float_placement);
291 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
293 fl_addto_choice(options_->choice_ams_math,
294 _("Never | Automatically | Yes "));
296 for (int n = 0; tex_graphics[n][0]; ++n) {
297 fl_addto_choice(options_->choice_postscript_driver,
300 fl_addto_choice(options_->choice_citation_format,
301 _(" Author-year | Numerical "));
303 // the document bullets form
304 bullets_.reset(build_document_bullet(this));
306 // disable for read-only documents
307 bcview().addReadOnly(bullets_->radio_bullet_depth_1);
308 bcview().addReadOnly(bullets_->radio_bullet_depth_2);
309 bcview().addReadOnly(bullets_->radio_bullet_depth_3);
310 bcview().addReadOnly(bullets_->radio_bullet_depth_4);
311 bcview().addReadOnly(bullets_->radio_bullet_panel_standard);
312 bcview().addReadOnly(bullets_->radio_bullet_panel_maths);
313 bcview().addReadOnly(bullets_->radio_bullet_panel_ding1);
314 bcview().addReadOnly(bullets_->radio_bullet_panel_ding2);
315 bcview().addReadOnly(bullets_->radio_bullet_panel_ding3);
316 bcview().addReadOnly(bullets_->radio_bullet_panel_ding4);
317 bcview().addReadOnly(bullets_->bmtable_bullet_panel);
318 bcview().addReadOnly(bullets_->choice_bullet_size);
319 bcview().addReadOnly(bullets_->input_bullet_latex);
321 // trigger an input event for cut&paste with middle mouse button.
322 setPrehandler(bullets_->input_bullet_latex);
324 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
326 fl_addto_choice(bullets_->choice_bullet_size,
327 _(" Default | Tiny | Smallest | Smaller | Small |"
328 " Normal | Large | Larger | Largest | Huge | Huger "));
329 fl_set_choice(bullets_->choice_bullet_size, 1);
331 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
333 string const bmtablefile = LibFileSearch("images", "standard", "xpm");
334 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
335 bmtablefile.c_str());
337 fl_addto_tabfolder(dialog_->tabfolder,_("Document"),
339 fl_addto_tabfolder(dialog_->tabfolder,_("Paper"),
341 fl_addto_tabfolder(dialog_->tabfolder,_("Language"),
343 fl_addto_tabfolder(dialog_->tabfolder,_("Extra"),
345 fbullet = fl_addto_tabfolder(dialog_->tabfolder,_("Bullets"),
348 // work-around xforms bug re update of folder->x, folder->y coords.
349 setPrehandler(dialog_->tabfolder);
351 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
352 lyxerr << _("Your version of libXpm is older than 4.7.\n"
353 "The `bullet' tab of the document dialog "
354 "has been disabled") << '\n';
355 fl_deactivate_object(fbullet);
356 fl_set_object_lcol(fbullet, FL_INACTIVE);
361 void FormDocument::apply()
363 BufferParams & params = controller().params();
367 language_apply(params);
368 options_apply(params);
369 bullets_apply(params);
373 void FormDocument::update()
380 BufferParams const & params = controller().params();
382 class_update(params);
383 paper_update(params);
384 language_update(params);
385 options_update(params);
386 bullets_update(params);
390 ButtonPolicy::SMInput FormDocument::input(FL_OBJECT * ob, long)
392 if (ob == bullets_->choice_bullet_size) {
393 ChoiceBulletSize(ob, 0);
395 } else if (ob == bullets_->input_bullet_latex) {
396 InputBulletLaTeX(ob, 0);
398 } else if (ob == bullets_->radio_bullet_depth_1 ||
399 ob == bullets_->radio_bullet_depth_2 ||
400 ob == bullets_->radio_bullet_depth_3 ||
401 ob == bullets_->radio_bullet_depth_4) {
404 } else if (ob == bullets_->radio_bullet_panel_standard ||
405 ob == bullets_->radio_bullet_panel_maths ||
406 ob == bullets_->radio_bullet_panel_ding1 ||
407 ob == bullets_->radio_bullet_panel_ding2 ||
408 ob == bullets_->radio_bullet_panel_ding3 ||
409 ob == bullets_->radio_bullet_panel_ding4) {
412 } else if (ob == bullets_->bmtable_bullet_panel) {
413 BulletBMTable(ob, 0);
415 } else if (ob == class_->choice_doc_spacing) {
416 setEnabled(class_->input_doc_spacing,
417 fl_get_choice(class_->choice_doc_spacing) == 4);
419 } else if (ob == class_->radio_doc_skip ||
420 ob == class_->radio_doc_indent ||
421 ob == class_->choice_doc_skip) {
422 bool const skip_used = fl_get_button(class_->radio_doc_skip);
423 setEnabled(class_->choice_doc_skip, skip_used);
425 bool const length_input =
426 fl_get_choice(class_->choice_doc_skip) == 4;
427 setEnabled(class_->input_doc_skip,
428 skip_used && length_input);
429 setEnabled(class_->choice_doc_skip_units,
430 skip_used && length_input);
432 // Default unit choice is cm if metric, inches if US paper.
433 // If papersize is default, check the lyxrc-settings
434 int const paperchoice = fl_get_choice(paper_->choice_papersize);
435 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
436 || paperchoice == 2 || paperchoice > 5;
437 string const default_unit = metric ? "cm" : "in";
438 if (getString(class_->input_doc_skip).empty())
439 fl_set_choice_text(class_->choice_doc_skip_units,
440 default_unit.c_str());
442 } else if (ob == options_->check_use_natbib) {
443 setEnabled(options_->choice_citation_format,
444 fl_get_button(options_->check_use_natbib));
446 } else if (ob == dialog_->button_save_defaults) {
448 controller().saveAsDefault();
450 } else if (ob == dialog_->button_reset_defaults) {
451 BufferParams & params = controller().params();
452 params.textclass = combo_doc_class->get() - 1;
453 params.useClassDefaults();
454 UpdateLayoutDocument(params);
456 } else if (ob == paper_->radio_landscape) {
457 fl_set_choice(paper_->choice_paperpackage,
458 BufferParams::PACKAGE_NONE + 1);
460 } else if (ob == paper_->choice_papersize) {
461 int const paperchoice = fl_get_choice(paper_->choice_papersize);
462 bool const defsize = paperchoice == 1;
463 bool const custom = paperchoice == 2;
464 bool const a3size = paperchoice == 6;
465 bool const b3size = paperchoice == 9;
466 bool const b4size = paperchoice == 10;
469 fl_set_button(paper_->radio_portrait, 1);
471 bool const use_geom = (custom || a3size || b3size || b4size);
473 fl_set_button(paper_->check_use_geometry, int(use_geom));
475 setEnabled(paper_->input_top_margin, use_geom);
476 setEnabled(paper_->input_bottom_margin, use_geom);
477 setEnabled(paper_->input_inner_margin, use_geom);
478 setEnabled(paper_->input_outer_margin, use_geom);
479 setEnabled(paper_->input_head_height, use_geom);
480 setEnabled(paper_->input_head_sep, use_geom);
481 setEnabled(paper_->input_foot_skip, use_geom);
482 setEnabled(paper_->choice_top_margin_units, use_geom);
483 setEnabled(paper_->choice_bottom_margin_units, use_geom);
484 setEnabled(paper_->choice_inner_margin_units, use_geom);
485 setEnabled(paper_->choice_outer_margin_units, use_geom);
486 setEnabled(paper_->choice_head_height_units, use_geom);
487 setEnabled(paper_->choice_head_sep_units, use_geom);
488 setEnabled(paper_->choice_foot_skip_units, use_geom);
489 setEnabled(paper_->choice_custom_width_units, use_geom);
490 setEnabled(paper_->choice_custom_height_units, use_geom);
492 setEnabled(paper_->input_custom_width, custom);
493 setEnabled(paper_->input_custom_height, custom);
494 setEnabled(paper_->choice_custom_width_units, custom);
495 setEnabled(paper_->choice_custom_height_units, custom);
496 setEnabled(paper_->radio_portrait, !custom);
497 setEnabled(paper_->radio_landscape, !custom);
499 // Default unit choice is cm if metric, inches if US paper.
500 // If papersize is default, use the lyxrc-settings
501 bool const metric = (defsize && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
502 || paperchoice == 2 || paperchoice > 5;
503 string const default_unit = metric ? "cm" : "in";
504 if (getString(paper_->input_custom_width).empty())
505 fl_set_choice_text(paper_->choice_custom_width_units,
506 default_unit.c_str());
507 if (getString(paper_->input_custom_height).empty())
508 fl_set_choice_text(paper_->choice_custom_height_units,
509 default_unit.c_str());
510 if (getString(paper_->input_top_margin).empty())
511 fl_set_choice_text(paper_->choice_top_margin_units,
512 default_unit.c_str());
513 if (getString(paper_->input_bottom_margin).empty())
514 fl_set_choice_text(paper_->choice_bottom_margin_units,
515 default_unit.c_str());
516 if (getString(paper_->input_inner_margin).empty())
517 fl_set_choice_text(paper_->choice_inner_margin_units,
518 default_unit.c_str());
519 if (getString(paper_->input_outer_margin).empty())
520 fl_set_choice_text(paper_->choice_outer_margin_units,
521 default_unit.c_str());
522 if (getString(paper_->input_head_height).empty())
523 fl_set_choice_text(paper_->choice_head_height_units,
524 default_unit.c_str());
525 if (getString(paper_->input_head_sep).empty())
526 fl_set_choice_text(paper_->choice_head_sep_units,
527 default_unit.c_str());
528 if (getString(paper_->input_foot_skip).empty())
529 fl_set_choice_text(paper_->choice_foot_skip_units,
530 default_unit.c_str());
532 } else if (ob == paper_->choice_paperpackage &&
533 fl_get_choice(paper_->choice_paperpackage) != 1) {
535 fl_set_button(paper_->check_use_geometry, 0);
536 setEnabled(paper_->input_top_margin, false);
537 setEnabled(paper_->input_bottom_margin, false);
538 setEnabled(paper_->input_inner_margin, false);
539 setEnabled(paper_->input_outer_margin, false);
540 setEnabled(paper_->input_head_height, false);
541 setEnabled(paper_->input_head_sep, false);
542 setEnabled(paper_->input_foot_skip, false);
543 setEnabled(paper_->choice_top_margin_units, false);
544 setEnabled(paper_->choice_bottom_margin_units, false);
545 setEnabled(paper_->choice_inner_margin_units, false);
546 setEnabled(paper_->choice_outer_margin_units, false);
547 setEnabled(paper_->choice_head_height_units, false);
548 setEnabled(paper_->choice_head_sep_units, false);
549 setEnabled(paper_->choice_foot_skip_units, false);
551 } else if (ob == paper_->check_use_geometry) {
552 // don't allow switching geometry off in custom papersize
553 // mode nor in A3, B3, and B4
554 int const choice = fl_get_choice(paper_->choice_papersize);
555 if (choice == 2 || choice == 6 || choice == 9 || choice == 10)
556 fl_set_button(paper_->check_use_geometry, 1);
558 fl_set_choice(paper_->choice_paperpackage,
559 BufferParams::PACKAGE_NONE + 1);
561 bool const use_geom = fl_get_button(paper_->check_use_geometry);
562 setEnabled(paper_->input_top_margin, use_geom);
563 setEnabled(paper_->input_bottom_margin, use_geom);
564 setEnabled(paper_->input_inner_margin, use_geom);
565 setEnabled(paper_->input_outer_margin, use_geom);
566 setEnabled(paper_->input_head_height, use_geom);
567 setEnabled(paper_->input_head_sep, use_geom);
568 setEnabled(paper_->input_foot_skip, use_geom);
569 setEnabled(paper_->choice_top_margin_units, use_geom);
570 setEnabled(paper_->choice_bottom_margin_units, use_geom);
571 setEnabled(paper_->choice_inner_margin_units, use_geom);
572 setEnabled(paper_->choice_outer_margin_units, use_geom);
573 setEnabled(paper_->choice_head_height_units, use_geom);
574 setEnabled(paper_->choice_head_sep_units, use_geom);
575 setEnabled(paper_->choice_foot_skip_units, use_geom);
578 if (ob == paper_->choice_papersize || ob == paper_->radio_portrait
579 || ob == paper_->radio_landscape) {
580 // either default papersize (preferences) or document
581 // papersize has to be A4
582 bool const enable = ( fl_get_choice(paper_->choice_papersize) == 1
583 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER )
584 || fl_get_choice(paper_->choice_papersize) == 7;
586 fl_set_choice(paper_->choice_paperpackage,
587 BufferParams::PACKAGE_NONE + 1);
588 setEnabled(paper_->choice_paperpackage,
589 enable && fl_get_button(paper_->radio_portrait));
592 return ButtonPolicy::SMI_VALID;
596 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
598 FormDocument * pre = static_cast<FormDocument*>(v);
599 if (combox == pre->combo_doc_class.get())
600 pre->CheckChoiceClass();
605 bool FormDocument::class_apply(BufferParams ¶ms)
609 // If default skip is a "Length" but there's no text in the
610 // input field, reset the kind to "MedSkip", which is the default.
611 if (fl_get_choice(class_->choice_doc_skip) == 4 &&
612 getString(class_->input_doc_skip).empty()) {
613 fl_set_choice(class_->choice_doc_skip, 2);
615 params.fonts = getString(class_->choice_doc_fonts);
616 params.fontsize = getString(class_->choice_doc_fontsize);
617 params.pagestyle = getString(class_->choice_doc_pagestyle);
619 params.textclass = combo_doc_class->get() - 1;
621 BufferParams::PARSEP tmpsep = params.paragraph_separation;
622 if (fl_get_button(class_->radio_doc_indent))
623 params.paragraph_separation = BufferParams::PARSEP_INDENT;
625 params.paragraph_separation = BufferParams::PARSEP_SKIP;
626 if (tmpsep != params.paragraph_separation)
629 VSpace tmpdefskip = params.getDefSkip();
630 switch (fl_get_choice(class_->choice_doc_skip)) {
632 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
635 params.setDefSkip(VSpace(VSpace::MEDSKIP));
638 params.setDefSkip(VSpace(VSpace::BIGSKIP));
642 string const length =
643 getLengthFromWidgets(class_->input_doc_skip,
644 class_->choice_doc_skip_units);
646 params.setDefSkip(VSpace(LyXGlueLength(length)));
650 // DocumentDefskipCB assures that this never happens
651 params.setDefSkip(VSpace(VSpace::MEDSKIP));
654 if (!(tmpdefskip == params.getDefSkip()))
657 if (fl_get_button(class_->radio_doc_columns_two))
661 if (fl_get_button(class_->radio_doc_sides_two))
662 params.sides = LyXTextClass::TwoSides;
664 params.sides = LyXTextClass::OneSide;
666 Spacing tmpSpacing = params.spacing;
667 switch (fl_get_choice(class_->choice_doc_spacing)) {
669 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
670 params.spacing.set(Spacing::Single);
673 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
674 params.spacing.set(Spacing::Onehalf);
677 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
678 params.spacing.set(Spacing::Double);
681 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
682 params.spacing.set(Spacing::Other,
683 getString(class_->input_doc_spacing));
686 if (tmpSpacing != params.spacing)
689 params.options = getString(class_->input_doc_extra);
695 void FormDocument::paper_apply(BufferParams & params)
697 params.papersize2 = char(fl_get_choice(paper_->choice_papersize) - 1);
699 params.paperpackage =
700 char(fl_get_choice(paper_->choice_paperpackage) - 1);
702 // set params.papersize from params.papersize2 and params.paperpackage
703 params.setPaperStuff();
705 params.use_geometry = fl_get_button(paper_->check_use_geometry);
707 if (fl_get_button(paper_->radio_landscape))
708 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
710 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
713 getLengthFromWidgets(paper_->input_custom_width,
714 paper_->choice_custom_width_units);
717 getLengthFromWidgets(paper_->input_custom_height,
718 paper_->choice_custom_height_units);
721 getLengthFromWidgets(paper_->input_inner_margin,
722 paper_->choice_inner_margin_units);
725 getLengthFromWidgets(paper_->input_top_margin,
726 paper_->choice_top_margin_units);
729 getLengthFromWidgets(paper_->input_outer_margin,
730 paper_->choice_outer_margin_units);
732 params.bottommargin =
733 getLengthFromWidgets(paper_->input_bottom_margin,
734 paper_->choice_bottom_margin_units);
737 getLengthFromWidgets(paper_->input_head_height,
738 paper_->choice_head_height_units);
741 getLengthFromWidgets(paper_->input_head_sep,
742 paper_->choice_head_sep_units);
745 getLengthFromWidgets(paper_->input_foot_skip,
746 paper_->choice_foot_skip_units);
750 bool FormDocument::language_apply(BufferParams & params)
752 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
755 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
757 lga = InsetQuotes::EnglishQ;
760 lga = InsetQuotes::SwedishQ;
763 lga = InsetQuotes::GermanQ;
766 lga = InsetQuotes::PolishQ;
769 lga = InsetQuotes::FrenchQ;
772 lga = InsetQuotes::DanishQ;
775 params.quotes_language = lga;
776 if (fl_get_button(language_->radio_single))
777 params.quotes_times = InsetQuotes::SingleQ;
779 params.quotes_times = InsetQuotes::DoubleQ;
781 int const pos = combo_language->get();
782 Language const * new_language = languages.getLanguage(lang_[pos-1]);
784 new_language = default_language;
786 params.language = new_language;
787 params.inputenc = getString(language_->choice_inputenc);
793 bool FormDocument::options_apply(BufferParams & params)
797 params.graphicsDriver = getString(options_->choice_postscript_driver);
798 params.use_amsmath = static_cast<BufferParams::AMS>(
799 fl_get_choice(options_->choice_ams_math) - 1);
800 params.use_natbib = fl_get_button(options_->check_use_natbib);
801 params.use_numerical_citations =
802 fl_get_choice(options_->choice_citation_format) - 1;
804 int tmpchar = int(fl_get_counter_value(options_->counter_secnumdepth));
805 if (params.secnumdepth != tmpchar)
807 params.secnumdepth = tmpchar;
809 params.tocdepth = int(fl_get_counter_value(options_->counter_tocdepth));
811 params.float_placement =
812 getString(options_->input_float_placement);
818 void FormDocument::bullets_apply(BufferParams & params)
820 /* update the bullet settings */
821 BufferParams & buf_params = controller().params();
823 // a little bit of loop unrolling
824 params.user_defined_bullets[0] = buf_params.temp_bullets[0];
825 params.user_defined_bullets[1] = buf_params.temp_bullets[1];
826 params.user_defined_bullets[2] = buf_params.temp_bullets[2];
827 params.user_defined_bullets[3] = buf_params.temp_bullets[3];
831 void FormDocument::UpdateClassParams(BufferParams const & params)
833 // These are the params that have to be updated on any class change
834 // (even if the class defaults are not used) (JSpitzm 2002-04-08)
836 LyXTextClass const & tclass = textclasslist[params.textclass];
838 combo_doc_class->select(tclass.description());
839 fl_clear_choice(class_->choice_doc_fontsize);
840 fl_addto_choice(class_->choice_doc_fontsize, "default");
841 fl_addto_choice(class_->choice_doc_fontsize,
842 tclass.opt_fontsize().c_str());
843 fl_set_choice_text(class_->choice_doc_fontsize,
844 params.fontsize.c_str());
845 fl_clear_choice(class_->choice_doc_pagestyle);
846 fl_addto_choice(class_->choice_doc_pagestyle, "default");
847 fl_addto_choice(class_->choice_doc_pagestyle,
848 tclass.opt_pagestyle().c_str());
849 fl_set_choice_text(class_->choice_doc_pagestyle,
850 params.pagestyle.c_str());
854 void FormDocument::class_update(BufferParams const & params)
859 UpdateClassParams(params);
861 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
863 bool const indent = params.paragraph_separation == BufferParams::PARSEP_INDENT;
864 fl_set_button(class_->radio_doc_indent, indent);
865 fl_set_button(class_->radio_doc_skip, !indent);
869 pos = 2; // VSpace::MEDSKIP is default
871 switch (params.getDefSkip().kind()) {
875 case VSpace::BIGSKIP:
878 case VSpace::SMALLSKIP:
881 case VSpace::MEDSKIP:
887 fl_set_choice (class_->choice_doc_skip, pos);
889 bool const length_input = pos == 4;
891 int const paperchoice = fl_get_choice(paper_->choice_papersize);
892 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
893 || paperchoice == 2 || paperchoice > 5;
894 string const default_unit = metric ? "cm" : "in";
895 string const length = params.getDefSkip().asLyXCommand();
896 updateWidgetsFromLengthString(class_->input_doc_skip,
897 class_->choice_doc_skip_units,
898 length, default_unit);
901 fl_set_input(class_->input_doc_skip, "");
903 setEnabled(class_->choice_doc_skip, !indent);
904 setEnabled(class_->input_doc_skip, length_input);
905 setEnabled(class_->choice_doc_skip_units, length_input);
907 bool const two_sides = params.sides == LyXTextClass::TwoSides;
908 fl_set_button(class_->radio_doc_sides_one, !two_sides);
909 fl_set_button(class_->radio_doc_sides_two, two_sides);
911 bool const two_columns = params.columns == 2;
912 fl_set_button(class_->radio_doc_columns_one, !two_columns);
913 fl_set_button(class_->radio_doc_columns_two, two_columns);
915 fl_set_input(class_->input_doc_extra, params.options.c_str());
917 switch (params.spacing.getSpace()) {
921 case Spacing::Double: // \doublespacing
924 case Spacing::Onehalf: // \onehalfspacing
927 case Spacing::Single: // \singlespacing
928 case Spacing::Default: // nothing bad should happen with this
933 fl_set_choice(class_->choice_doc_spacing, pos);
935 bool const spacing_input = pos == 4;
936 setEnabled(class_->input_doc_spacing, spacing_input);
937 string const input = spacing_input ? tostr(params.spacing.getValue()) : string();
938 fl_set_input(class_->input_doc_spacing, input.c_str());
942 void FormDocument::language_update(BufferParams const & params)
944 if (!language_.get())
947 int const pos = int(findPos(lang_, params.language->lang()));
948 combo_language->select(pos+1);
950 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
951 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
952 fl_set_button(language_->radio_single, 0);
953 fl_set_button(language_->radio_double, 0);
954 if (params.quotes_times == InsetQuotes::SingleQ)
955 fl_set_button(language_->radio_single, 1);
957 fl_set_button(language_->radio_double, 1);
961 void FormDocument::options_update(BufferParams const & params)
966 fl_set_choice_text(options_->choice_postscript_driver,
967 params.graphicsDriver.c_str());
968 fl_set_choice(options_->choice_ams_math, params.use_amsmath + 1);
969 fl_set_button(options_->check_use_natbib, params.use_natbib);
970 fl_set_choice(options_->choice_citation_format,
971 int(params.use_numerical_citations)+1);
972 setEnabled(options_->choice_citation_format, params.use_natbib);
973 fl_set_counter_value(options_->counter_secnumdepth, params.secnumdepth);
974 fl_set_counter_value(options_->counter_tocdepth, params.tocdepth);
975 if (!params.float_placement.empty())
976 fl_set_input(options_->input_float_placement,
977 params.float_placement.c_str());
979 fl_set_input(options_->input_float_placement, "");
983 void FormDocument::paper_update(BufferParams const & params)
988 fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
989 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
990 fl_set_button(paper_->check_use_geometry, params.use_geometry);
992 int const paperchoice = fl_get_choice(paper_->choice_papersize);
993 bool const useCustom = paperchoice == 2;
994 bool const useGeom = fl_get_button(paper_->check_use_geometry);
996 fl_set_button(paper_->radio_portrait, 0);
997 setEnabled(paper_->radio_portrait, !useCustom);
998 fl_set_button(paper_->radio_landscape, 0);
999 setEnabled(paper_->radio_landscape, !useCustom);
1001 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1002 fl_set_button(paper_->radio_landscape, 1);
1004 fl_set_button(paper_->radio_portrait, 1);
1005 setEnabled(paper_->choice_paperpackage,
1006 //either default papersize (preferences)
1007 //or document papersize has to be A4
1009 || paperchoice == 1 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER)
1010 && fl_get_button(paper_->radio_portrait));
1012 // Default unit choice is cm if metric, inches if US paper.
1013 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
1014 || paperchoice == 2 || paperchoice > 5;
1015 string const default_unit = metric ? "cm" : "in";
1016 updateWidgetsFromLengthString(paper_->input_custom_width,
1017 paper_->choice_custom_width_units,
1018 params.paperwidth, default_unit);
1019 setEnabled(paper_->input_custom_width, useCustom);
1020 setEnabled(paper_->choice_custom_width_units, useCustom);
1022 updateWidgetsFromLengthString(paper_->input_custom_height,
1023 paper_->choice_custom_height_units,
1024 params.paperheight, default_unit);
1025 setEnabled(paper_->input_custom_height, useCustom);
1026 setEnabled(paper_->choice_custom_height_units, useCustom);
1028 updateWidgetsFromLengthString(paper_->input_inner_margin,
1029 paper_->choice_inner_margin_units,
1030 params.leftmargin, default_unit);
1031 setEnabled(paper_->input_inner_margin, useGeom);
1032 setEnabled(paper_->choice_inner_margin_units, useGeom);
1034 updateWidgetsFromLengthString(paper_->input_top_margin,
1035 paper_->choice_top_margin_units,
1036 params.topmargin, default_unit);
1037 setEnabled(paper_->input_top_margin, useGeom);
1038 setEnabled(paper_->choice_top_margin_units, useGeom);
1040 updateWidgetsFromLengthString(paper_->input_outer_margin,
1041 paper_->choice_outer_margin_units,
1042 params.rightmargin, default_unit);
1043 setEnabled(paper_->input_outer_margin, useGeom);
1044 setEnabled(paper_->choice_outer_margin_units, useGeom);
1046 updateWidgetsFromLengthString(paper_->input_bottom_margin,
1047 paper_->choice_bottom_margin_units,
1048 params.bottommargin, default_unit);
1049 setEnabled(paper_->input_bottom_margin, useGeom);
1050 setEnabled(paper_->choice_bottom_margin_units, useGeom);
1052 updateWidgetsFromLengthString(paper_->input_head_height,
1053 paper_->choice_head_height_units,
1054 params.headheight, default_unit);
1055 setEnabled(paper_->input_head_height, useGeom);
1056 setEnabled(paper_->choice_head_height_units, useGeom);
1058 updateWidgetsFromLengthString(paper_->input_head_sep,
1059 paper_->choice_head_sep_units,
1060 params.headsep, default_unit);
1061 setEnabled(paper_->input_head_sep, useGeom);
1062 setEnabled(paper_->choice_head_sep_units, useGeom);
1064 updateWidgetsFromLengthString(paper_->input_foot_skip,
1065 paper_->choice_foot_skip_units,
1066 params.footskip, default_unit);
1067 setEnabled(paper_->input_foot_skip, useGeom);
1068 setEnabled(paper_->choice_foot_skip_units, useGeom);
1070 fl_set_focus_object(paper_->form, paper_->choice_papersize);
1074 void FormDocument::bullets_update(BufferParams const & params)
1076 if (!bullets_.get() ||
1078 (XpmVersion==4 && XpmRevision<7)))
1081 bool const isLinuxDoc =
1082 controller().docType() == ControlDocument::LINUXDOC;
1083 setEnabled(fbullet, !isLinuxDoc);
1085 if (isLinuxDoc) return;
1087 fl_set_button(bullets_->radio_bullet_depth_1, 1);
1088 fl_set_input(bullets_->input_bullet_latex,
1089 params.user_defined_bullets[0].getText().c_str());
1090 fl_set_choice(bullets_->choice_bullet_size,
1091 params.user_defined_bullets[0].getSize() + 2);
1095 void FormDocument::checkReadOnly()
1097 if (bc().readOnly(controller().bufferIsReadonly())) {
1098 combo_doc_class->deactivate();
1099 combo_language->deactivate();
1100 postWarning(_("Document is read-only."
1101 " No changes to layout permitted."));
1103 combo_doc_class->activate();
1104 combo_language->activate();
1110 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/)
1112 BufferParams & param = controller().params();
1114 // convert from 1-6 range to -1-4
1115 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1116 fl_set_input(bullets_->input_bullet_latex,
1117 param.temp_bullets[current_bullet_depth].getText().c_str());
1121 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1123 BufferParams & param = controller().params();
1125 param.temp_bullets[current_bullet_depth].
1126 setText(getString(bullets_->input_bullet_latex));
1130 void FormDocument::BulletDepth(FL_OBJECT * ob)
1132 /* Should I do the following: */
1133 /* 1. change to the panel that the current bullet belongs in */
1134 /* 2. show that bullet as selected */
1135 /* 3. change the size setting to the size of the bullet in Q.*/
1136 /* 4. display the latex equivalent in the latex box */
1138 /* I'm inclined to just go with 3 and 4 at the moment and */
1139 /* maybe try to support the others later */
1140 BufferParams & param = controller().params();
1143 if (ob == bullets_->radio_bullet_depth_1)
1145 else if (ob == bullets_->radio_bullet_depth_2)
1147 else if (ob == bullets_->radio_bullet_depth_3)
1149 else if (ob == bullets_->radio_bullet_depth_4)
1152 switch (fl_get_button_numb(ob)) {
1154 // right mouse button resets to default
1155 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1157 current_bullet_depth = data;
1158 fl_set_input(bullets_->input_bullet_latex,
1159 param.temp_bullets[data].getText().c_str());
1160 fl_set_choice(bullets_->choice_bullet_size,
1161 param.temp_bullets[data].getSize() + 2);
1166 void FormDocument::BulletPanel(FL_OBJECT * ob)
1168 /* Here we have to change the background pixmap to that selected */
1169 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1172 if (ob == bullets_->radio_bullet_panel_standard)
1174 else if (ob == bullets_->radio_bullet_panel_maths)
1176 else if (ob == bullets_->radio_bullet_panel_ding2)
1178 else if (ob == bullets_->radio_bullet_panel_ding3)
1180 else if (ob == bullets_->radio_bullet_panel_ding4)
1182 else if (ob == bullets_->radio_bullet_panel_ding1)
1185 if (data != current_bullet_panel) {
1186 fl_freeze_form(bullets_->form);
1187 current_bullet_panel = data;
1189 /* free the current pixmap */
1190 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1192 if (ob == bullets_->radio_bullet_panel_standard) {
1193 new_panel = "standard";
1194 } else if (ob == bullets_->radio_bullet_panel_maths ) {
1195 new_panel = "amssymb";
1196 } else if (ob == bullets_->radio_bullet_panel_ding2) {
1197 new_panel = "psnfss1";
1198 } else if (ob == bullets_->radio_bullet_panel_ding3) {
1199 new_panel = "psnfss2";
1200 } else if (ob == bullets_->radio_bullet_panel_ding4) {
1201 new_panel = "psnfss3";
1202 } else if (ob == bullets_->radio_bullet_panel_ding1) {
1203 new_panel = "psnfss4";
1205 /* something very wrong happened */
1206 // play it safe for now but should be an exception
1207 current_bullet_panel = 0; // standard panel
1208 new_panel = "standard";
1210 new_panel += ".xpm";
1211 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1212 LibFileSearch("images", new_panel).c_str());
1213 fl_redraw_object(bullets_->bmtable_bullet_panel);
1214 fl_unfreeze_form(bullets_->form);
1219 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/)
1221 /* handle the user input by setting the current bullet depth's pixmap */
1222 /* to that extracted from the current chosen position of the BMTable */
1223 /* Don't forget to free the button's old pixmap first. */
1225 BufferParams & param = controller().params();
1226 int bmtable_button = fl_get_bmtable(ob);
1228 /* try to keep the button held down till another is pushed */
1229 /* fl_set_bmtable(ob, 1, bmtable_button); */
1230 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1231 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1232 fl_set_input(bullets_->input_bullet_latex,
1233 param.temp_bullets[current_bullet_depth].getText().c_str());
1237 void FormDocument::CheckChoiceClass()
1239 BufferParams & params = controller().params();
1241 lyx::textclass_type const tc = combo_doc_class->get() - 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 combo_doc_class->select(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);