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"
21 #include "checkedwidgets.h"
23 #include "input_validators.h" // fl_unsigned_float_filter
24 #include "xforms_helpers.h"
27 //#include "BufferView.h"
28 #include "CutAndPaste.h"
31 //#include "lyx_main.h" // for user_lyxdir
33 #include "lyxtextclasslist.h"
34 #include "tex-strings.h"
36 #include "controllers/frnt_lang.h"
37 #include "controllers/helper_funcs.h"
39 #include "support/lstrings.h" // contains_functor, getStringFromVector
40 #include "support/filetools.h" // LibFileSearch
42 #include XPM_H_LOCATION
43 #include FORMS_H_LOCATION
45 #include <boost/bind.hpp>
53 typedef FormCB<ControlDocument, FormDB<FD_document> > base_class;
55 FormDocument::FormDocument()
56 : base_class(_("Document Layout"), false),
57 ActCell(0), Confirmed(0),
58 current_bullet_panel(0), current_bullet_depth(0), fbullet(0)
62 void FormDocument::redraw()
64 if (form() && form()->visible)
65 fl_redraw_form(form());
69 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder);
70 if (outer_form && outer_form->visible)
71 fl_redraw_form(outer_form);
75 void FormDocument::build()
78 dialog_.reset(build_document(this));
80 // Allow the base class to control messages
81 setMessageWidget(dialog_->text_warning);
83 // Manage the restore, ok, apply, restore and cancel/close buttons
84 bc().setOK(dialog_->button_ok);
85 bc().setApply(dialog_->button_apply);
86 bc().setCancel(dialog_->button_close);
87 bc().setRestore(dialog_->button_restore);
89 // the document class form
90 class_.reset(build_document_class(this));
92 // disable for read-only documents
93 bc().addReadOnly(class_->radio_doc_indent);
94 bc().addReadOnly(class_->radio_doc_skip);
95 bc().addReadOnly(class_->choice_doc_pagestyle);
96 bc().addReadOnly(class_->choice_doc_fonts);
97 bc().addReadOnly(class_->choice_doc_fontsize);
98 bc().addReadOnly(class_->radio_doc_sides_one);
99 bc().addReadOnly(class_->radio_doc_sides_two);
100 bc().addReadOnly(class_->radio_doc_columns_one);
101 bc().addReadOnly(class_->radio_doc_columns_two);
102 bc().addReadOnly(class_->input_doc_extra);
103 bc().addReadOnly(class_->input_doc_skip);
104 bc().addReadOnly(class_->choice_doc_skip);
105 bc().addReadOnly(class_->choice_doc_spacing);
106 bc().addReadOnly(class_->input_doc_spacing);
108 // check validity of "length + unit" input
109 addCheckedGlueLength(bc(), class_->input_doc_skip,
110 class_->choice_doc_skip);
112 // trigger an input event for cut&paste with middle mouse button.
113 setPrehandler(class_->input_doc_extra);
114 setPrehandler(class_->input_doc_skip);
115 setPrehandler(class_->input_doc_spacing);
117 fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
118 fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
119 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
123 // the class list is a combo-box and has to be inserted manually
124 obj = class_->choice_doc_class;
125 fl_deactivate_object(obj);
126 fl_addto_form(class_->form);
127 combo_doc_class.reset(new Combox(FL_COMBOX_DROPLIST));
128 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400);
129 combo_doc_class->shortcut("#C",1);
130 combo_doc_class->setcallback(ComboInputCB, this);
132 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
133 cit != textclasslist.end(); ++cit) {
134 combo_doc_class->addto(cit->description());
137 fl_addto_choice(class_->choice_doc_spacing,
138 _(" Single | OneHalf | Double | Custom "));
139 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
140 for (int n = 0; tex_fonts[n][0]; ++n) {
141 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
144 // Create the contents of the unit choices; don't include the
146 vector<string> units_vec = getLatexUnits();
147 vector<string>::iterator ret =
148 std::remove_if(units_vec.begin(),
150 bind2nd(contains_functor(), "%"));
151 units_vec.erase(ret, units_vec.end());
153 string const units = getStringFromVector(units_vec, "|");
155 fl_addto_choice(class_->choice_doc_pagestyle,
156 "default|empty|plain|headings|fancy");
157 fl_addto_choice(class_->choice_doc_skip,
158 _(" SmallSkip | MedSkip | BigSkip | Length "));
159 fl_addto_choice(class_->choice_doc_skip_units, units.c_str());
161 // Set input filters on doc spacing to make it accept only
163 fl_set_input_filter(class_->input_doc_spacing,
164 fl_unsigned_float_filter);
166 // disable for read-only documents
167 bc().addReadOnly(dialog_->button_save_defaults);
168 bc().addReadOnly(dialog_->button_reset_defaults);
170 // the document paper form
171 paper_.reset(build_document_paper(this));
173 // disable for read-only documents
174 bc().addReadOnly(paper_->choice_paperpackage);
175 bc().addReadOnly(paper_->radio_portrait);
176 bc().addReadOnly(paper_->radio_landscape);
177 bc().addReadOnly(paper_->choice_papersize);
178 bc().addReadOnly(paper_->check_use_geometry);
179 bc().addReadOnly(paper_->input_custom_width);
180 bc().addReadOnly(paper_->input_custom_height);
181 bc().addReadOnly(paper_->input_top_margin);
182 bc().addReadOnly(paper_->input_bottom_margin);
183 bc().addReadOnly(paper_->input_inner_margin);
184 bc().addReadOnly(paper_->input_outer_margin);
185 bc().addReadOnly(paper_->input_head_height);
186 bc().addReadOnly(paper_->input_head_sep);
187 bc().addReadOnly(paper_->input_foot_skip);
189 // check validity of "length + unit" input
190 addCheckedGlueLength(bc(), paper_->input_custom_width);
191 addCheckedGlueLength(bc(), paper_->input_custom_height);
192 addCheckedGlueLength(bc(), paper_->input_top_margin);
193 addCheckedGlueLength(bc(), paper_->input_bottom_margin);
194 addCheckedGlueLength(bc(), paper_->input_inner_margin);
195 addCheckedGlueLength(bc(), paper_->input_outer_margin);
196 addCheckedGlueLength(bc(), paper_->input_head_height);
197 addCheckedGlueLength(bc(), paper_->input_head_sep);
198 addCheckedGlueLength(bc(), paper_->input_foot_skip);
200 // trigger an input event for cut&paste with middle mouse button.
201 setPrehandler(paper_->input_custom_width);
202 setPrehandler(paper_->input_custom_height);
203 setPrehandler(paper_->input_top_margin);
204 setPrehandler(paper_->input_bottom_margin);
205 setPrehandler(paper_->input_inner_margin);
206 setPrehandler(paper_->input_outer_margin);
207 setPrehandler(paper_->input_head_height);
208 setPrehandler(paper_->input_head_sep);
209 setPrehandler(paper_->input_foot_skip);
211 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
212 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
213 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
214 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
215 fl_set_input_return(paper_->input_inner_margin, FL_RETURN_CHANGED);
216 fl_set_input_return(paper_->input_outer_margin, FL_RETURN_CHANGED);
217 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
218 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
219 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
221 fl_addto_choice(paper_->choice_papersize,
222 _(" Default | Custom | US letter | US legal "
223 "| US executive | A3 | A4 | A5 | B3 | B4 | B5 "));
224 fl_addto_choice(paper_->choice_paperpackage,
227 "| Very small Margins "
228 "| Very wide Margins "));
230 fl_addto_choice(paper_->choice_custom_width_units, units.c_str());
231 fl_addto_choice(paper_->choice_custom_height_units, units.c_str());
232 fl_addto_choice(paper_->choice_top_margin_units, units.c_str());
233 fl_addto_choice(paper_->choice_bottom_margin_units, units.c_str());
234 fl_addto_choice(paper_->choice_inner_margin_units, units.c_str());
235 fl_addto_choice(paper_->choice_outer_margin_units, units.c_str());
236 fl_addto_choice(paper_->choice_head_height_units, units.c_str());
237 fl_addto_choice(paper_->choice_head_sep_units, units.c_str());
238 fl_addto_choice(paper_->choice_foot_skip_units, units.c_str());
240 // the document language form
241 language_.reset(build_document_language(this));
243 // disable for read-only documents
244 bc().addReadOnly(language_->choice_inputenc);
245 bc().addReadOnly(language_->choice_quotes_language);
246 bc().addReadOnly(language_->radio_single);
247 bc().addReadOnly(language_->radio_double);
249 fl_addto_choice(language_->choice_inputenc,
250 "default|auto|latin1|latin2|latin3|latin4|latin5|latin9"
251 "|koi8-r|koi8-u|cp866|cp1251|iso88595|pt154");
253 vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
254 // Store the identifiers for later
255 lang_ = getSecond(langs);
257 // The language is a combo-box and has to be inserted manually
258 obj = language_->choice_language;
259 fl_deactivate_object(obj);
260 fl_addto_form(language_->form);
261 combo_language.reset(new Combox(FL_COMBOX_DROPLIST));
262 combo_language->add(obj->x, obj->y, obj->w, obj->h, 400);
263 combo_language->shortcut("#L",1);
264 combo_language->setcallback(ComboInputCB, this);
267 vector<frnt::LanguagePair>::const_iterator lit = langs.begin();
268 vector<frnt::LanguagePair>::const_iterator lend = langs.end();
269 for (; lit != lend; ++lit) {
270 combo_language->addto(lit->first);
272 combo_language->select(1);
274 fl_addto_choice(language_->choice_quotes_language,
275 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
276 " «text» | »text« "));
278 // the document options form
279 options_.reset(build_document_options(this));
281 // disable for read-only documents
282 bc().addReadOnly(options_->counter_secnumdepth);
283 bc().addReadOnly(options_->counter_tocdepth);
284 bc().addReadOnly(options_->check_use_amsmath);
285 bc().addReadOnly(options_->check_use_natbib);
286 bc().addReadOnly(options_->choice_citation_format);
287 bc().addReadOnly(options_->input_float_placement);
288 bc().addReadOnly(options_->choice_postscript_driver);
290 // trigger an input event for cut&paste with middle mouse button.
291 setPrehandler(options_->input_float_placement);
293 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
295 for (int n = 0; tex_graphics[n][0]; ++n) {
296 fl_addto_choice(options_->choice_postscript_driver,
299 fl_addto_choice(options_->choice_citation_format,
300 _(" Author-year | Numerical "));
302 // the document bullets form
303 bullets_.reset(build_document_bullet(this));
305 // disable for read-only documents
306 bc().addReadOnly(bullets_->radio_bullet_depth_1);
307 bc().addReadOnly(bullets_->radio_bullet_depth_2);
308 bc().addReadOnly(bullets_->radio_bullet_depth_3);
309 bc().addReadOnly(bullets_->radio_bullet_depth_4);
310 bc().addReadOnly(bullets_->radio_bullet_panel_standard);
311 bc().addReadOnly(bullets_->radio_bullet_panel_maths);
312 bc().addReadOnly(bullets_->radio_bullet_panel_ding1);
313 bc().addReadOnly(bullets_->radio_bullet_panel_ding2);
314 bc().addReadOnly(bullets_->radio_bullet_panel_ding3);
315 bc().addReadOnly(bullets_->radio_bullet_panel_ding4);
316 bc().addReadOnly(bullets_->bmtable_bullet_panel);
317 bc().addReadOnly(bullets_->choice_bullet_size);
318 bc().addReadOnly(bullets_->input_bullet_latex);
320 // trigger an input event for cut&paste with middle mouse button.
321 setPrehandler(bullets_->input_bullet_latex);
323 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
325 fl_addto_choice(bullets_->choice_bullet_size,
326 _(" Default | Tiny | Smallest | Smaller | Small |"
327 " Normal | Large | Larger | Largest | Huge | Huger "));
328 fl_set_choice(bullets_->choice_bullet_size, 1);
330 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
332 string const bmtablefile = LibFileSearch("images", "standard", "xpm");
333 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
334 bmtablefile.c_str());
336 fl_addto_tabfolder(dialog_->tabfolder,_("Document"),
338 fl_addto_tabfolder(dialog_->tabfolder,_("Paper"),
340 fl_addto_tabfolder(dialog_->tabfolder,_("Language"),
342 fl_addto_tabfolder(dialog_->tabfolder,_("Extra"),
344 fbullet = fl_addto_tabfolder(dialog_->tabfolder,_("Bullets"),
347 // work-around xforms bug re update of folder->x, folder->y coords.
348 setPrehandler(dialog_->tabfolder);
350 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
351 lyxerr << _("Your version of libXpm is older than 4.7.\n"
352 "The `bullet' tab of the document dialog "
353 "has been disabled") << '\n';
354 fl_deactivate_object(fbullet);
355 fl_set_object_lcol(fbullet, FL_INACTIVE);
360 void FormDocument::apply()
362 BufferParams & params = controller().params();
366 language_apply(params);
367 options_apply(params);
368 bullets_apply(params);
372 void FormDocument::update()
379 BufferParams const & params = controller().params();
381 class_update(params);
382 paper_update(params);
383 language_update(params);
384 options_update(params);
385 bullets_update(params);
389 ButtonPolicy::SMInput FormDocument::input(FL_OBJECT * ob, long)
391 if (ob == bullets_->choice_bullet_size) {
392 ChoiceBulletSize(ob, 0);
394 } else if (ob == bullets_->input_bullet_latex) {
395 InputBulletLaTeX(ob, 0);
397 } else if (ob == bullets_->radio_bullet_depth_1 ||
398 ob == bullets_->radio_bullet_depth_2 ||
399 ob == bullets_->radio_bullet_depth_3 ||
400 ob == bullets_->radio_bullet_depth_4) {
403 } else if (ob == bullets_->radio_bullet_panel_standard ||
404 ob == bullets_->radio_bullet_panel_maths ||
405 ob == bullets_->radio_bullet_panel_ding1 ||
406 ob == bullets_->radio_bullet_panel_ding2 ||
407 ob == bullets_->radio_bullet_panel_ding3 ||
408 ob == bullets_->radio_bullet_panel_ding4) {
411 } else if (ob == bullets_->bmtable_bullet_panel) {
412 BulletBMTable(ob, 0);
414 } else if (ob == class_->choice_doc_spacing) {
415 setEnabled(class_->input_doc_spacing,
416 fl_get_choice(class_->choice_doc_spacing) == 4);
418 } else if (ob == class_->radio_doc_skip ||
419 ob == class_->radio_doc_indent ||
420 ob == class_->choice_doc_skip) {
421 bool const skip_used = fl_get_button(class_->radio_doc_skip);
422 setEnabled(class_->choice_doc_skip, skip_used);
424 bool const length_input =
425 fl_get_choice(class_->choice_doc_skip) == 4;
426 setEnabled(class_->input_doc_skip,
427 skip_used && length_input);
428 setEnabled(class_->choice_doc_skip_units,
429 skip_used && length_input);
431 // Default unit choice is cm if metric, inches if US paper.
432 // If papersize is default, check the lyxrc-settings
433 int const paperchoice = fl_get_choice(paper_->choice_papersize);
434 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
435 || paperchoice == 2 || paperchoice > 5;
436 string const default_unit = metric ? "cm" : "in";
437 if (getString(class_->input_doc_skip).empty())
438 fl_set_choice_text(class_->choice_doc_skip_units,
439 default_unit.c_str());
441 } else if (ob == options_->check_use_natbib) {
442 setEnabled(options_->choice_citation_format,
443 fl_get_button(options_->check_use_natbib));
445 } else if (ob == dialog_->button_save_defaults) {
447 controller().saveAsDefault();
449 } else if (ob == dialog_->button_reset_defaults) {
450 BufferParams & params = controller().params();
451 params.textclass = combo_doc_class->get() - 1;
452 params.useClassDefaults();
453 UpdateLayoutDocument(params);
455 } else if (ob == paper_->radio_landscape) {
456 fl_set_choice(paper_->choice_paperpackage,
457 BufferParams::PACKAGE_NONE + 1);
459 } else if (ob == paper_->choice_papersize) {
460 int const paperchoice = fl_get_choice(paper_->choice_papersize);
461 bool const defsize = paperchoice == 1;
462 bool const custom = paperchoice == 2;
463 bool const a3size = paperchoice == 6;
464 bool const b3size = paperchoice == 9;
465 bool const b4size = paperchoice == 10;
468 fl_set_button(paper_->radio_portrait, 1);
470 bool const use_geom = (custom || a3size || b3size || b4size);
472 fl_set_button(paper_->check_use_geometry, int(use_geom));
474 setEnabled(paper_->input_top_margin, use_geom);
475 setEnabled(paper_->input_bottom_margin, use_geom);
476 setEnabled(paper_->input_inner_margin, use_geom);
477 setEnabled(paper_->input_outer_margin, use_geom);
478 setEnabled(paper_->input_head_height, use_geom);
479 setEnabled(paper_->input_head_sep, use_geom);
480 setEnabled(paper_->input_foot_skip, use_geom);
481 setEnabled(paper_->choice_top_margin_units, use_geom);
482 setEnabled(paper_->choice_bottom_margin_units, use_geom);
483 setEnabled(paper_->choice_inner_margin_units, use_geom);
484 setEnabled(paper_->choice_outer_margin_units, use_geom);
485 setEnabled(paper_->choice_head_height_units, use_geom);
486 setEnabled(paper_->choice_head_sep_units, use_geom);
487 setEnabled(paper_->choice_foot_skip_units, use_geom);
488 setEnabled(paper_->choice_custom_width_units, use_geom);
489 setEnabled(paper_->choice_custom_height_units, use_geom);
491 setEnabled(paper_->input_custom_width, custom);
492 setEnabled(paper_->input_custom_height, custom);
493 setEnabled(paper_->choice_custom_width_units, custom);
494 setEnabled(paper_->choice_custom_height_units, custom);
495 setEnabled(paper_->radio_portrait, !custom);
496 setEnabled(paper_->radio_landscape, !custom);
498 // Default unit choice is cm if metric, inches if US paper.
499 // If papersize is default, use the lyxrc-settings
500 bool const metric = (defsize && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
501 || paperchoice == 2 || paperchoice > 5;
502 string const default_unit = metric ? "cm" : "in";
503 if (getString(paper_->input_custom_width).empty())
504 fl_set_choice_text(paper_->choice_custom_width_units,
505 default_unit.c_str());
506 if (getString(paper_->input_custom_height).empty())
507 fl_set_choice_text(paper_->choice_custom_height_units,
508 default_unit.c_str());
509 if (getString(paper_->input_top_margin).empty())
510 fl_set_choice_text(paper_->choice_top_margin_units,
511 default_unit.c_str());
512 if (getString(paper_->input_bottom_margin).empty())
513 fl_set_choice_text(paper_->choice_bottom_margin_units,
514 default_unit.c_str());
515 if (getString(paper_->input_inner_margin).empty())
516 fl_set_choice_text(paper_->choice_inner_margin_units,
517 default_unit.c_str());
518 if (getString(paper_->input_outer_margin).empty())
519 fl_set_choice_text(paper_->choice_outer_margin_units,
520 default_unit.c_str());
521 if (getString(paper_->input_head_height).empty())
522 fl_set_choice_text(paper_->choice_head_height_units,
523 default_unit.c_str());
524 if (getString(paper_->input_head_sep).empty())
525 fl_set_choice_text(paper_->choice_head_sep_units,
526 default_unit.c_str());
527 if (getString(paper_->input_foot_skip).empty())
528 fl_set_choice_text(paper_->choice_foot_skip_units,
529 default_unit.c_str());
531 } else if (ob == paper_->choice_paperpackage &&
532 fl_get_choice(paper_->choice_paperpackage) != 1) {
534 fl_set_button(paper_->check_use_geometry, 0);
535 setEnabled(paper_->input_top_margin, false);
536 setEnabled(paper_->input_bottom_margin, false);
537 setEnabled(paper_->input_inner_margin, false);
538 setEnabled(paper_->input_outer_margin, false);
539 setEnabled(paper_->input_head_height, false);
540 setEnabled(paper_->input_head_sep, false);
541 setEnabled(paper_->input_foot_skip, false);
542 setEnabled(paper_->choice_top_margin_units, false);
543 setEnabled(paper_->choice_bottom_margin_units, false);
544 setEnabled(paper_->choice_inner_margin_units, false);
545 setEnabled(paper_->choice_outer_margin_units, false);
546 setEnabled(paper_->choice_head_height_units, false);
547 setEnabled(paper_->choice_head_sep_units, false);
548 setEnabled(paper_->choice_foot_skip_units, false);
550 } else if (ob == paper_->check_use_geometry) {
551 // don't allow switching geometry off in custom papersize
552 // mode nor in A3, B3, and B4
553 int const choice = fl_get_choice(paper_->choice_papersize);
554 if (choice == 2 || choice == 6 || choice == 9 || choice == 10)
555 fl_set_button(paper_->check_use_geometry, 1);
557 fl_set_choice(paper_->choice_paperpackage,
558 BufferParams::PACKAGE_NONE + 1);
560 bool const use_geom = fl_get_button(paper_->check_use_geometry);
561 setEnabled(paper_->input_top_margin, use_geom);
562 setEnabled(paper_->input_bottom_margin, use_geom);
563 setEnabled(paper_->input_inner_margin, use_geom);
564 setEnabled(paper_->input_outer_margin, use_geom);
565 setEnabled(paper_->input_head_height, use_geom);
566 setEnabled(paper_->input_head_sep, use_geom);
567 setEnabled(paper_->input_foot_skip, use_geom);
568 setEnabled(paper_->choice_top_margin_units, use_geom);
569 setEnabled(paper_->choice_bottom_margin_units, use_geom);
570 setEnabled(paper_->choice_inner_margin_units, use_geom);
571 setEnabled(paper_->choice_outer_margin_units, use_geom);
572 setEnabled(paper_->choice_head_height_units, use_geom);
573 setEnabled(paper_->choice_head_sep_units, use_geom);
574 setEnabled(paper_->choice_foot_skip_units, use_geom);
577 if (ob == paper_->choice_papersize || ob == paper_->radio_portrait
578 || ob == paper_->radio_landscape) {
579 // either default papersize (preferences) or document
580 // papersize has to be A4
581 bool const enable = ( fl_get_choice(paper_->choice_papersize) == 1
582 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER )
583 || fl_get_choice(paper_->choice_papersize) == 7;
585 fl_set_choice(paper_->choice_paperpackage,
586 BufferParams::PACKAGE_NONE + 1);
587 setEnabled(paper_->choice_paperpackage,
588 enable && fl_get_button(paper_->radio_portrait));
591 return ButtonPolicy::SMI_VALID;
595 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
597 FormDocument * pre = static_cast<FormDocument*>(v);
598 if (combox == pre->combo_doc_class.get())
599 pre->CheckChoiceClass();
604 bool FormDocument::class_apply(BufferParams ¶ms)
608 // If default skip is a "Length" but there's no text in the
609 // input field, reset the kind to "MedSkip", which is the default.
610 if (fl_get_choice(class_->choice_doc_skip) == 4 &&
611 getString(class_->input_doc_skip).empty()) {
612 fl_set_choice(class_->choice_doc_skip, 2);
614 params.fonts = getString(class_->choice_doc_fonts);
615 params.fontsize = getString(class_->choice_doc_fontsize);
616 params.pagestyle = getString(class_->choice_doc_pagestyle);
618 params.textclass = combo_doc_class->get() - 1;
620 BufferParams::PARSEP tmpsep = params.paragraph_separation;
621 if (fl_get_button(class_->radio_doc_indent))
622 params.paragraph_separation = BufferParams::PARSEP_INDENT;
624 params.paragraph_separation = BufferParams::PARSEP_SKIP;
625 if (tmpsep != params.paragraph_separation)
628 VSpace tmpdefskip = params.getDefSkip();
629 switch (fl_get_choice(class_->choice_doc_skip)) {
631 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
634 params.setDefSkip(VSpace(VSpace::MEDSKIP));
637 params.setDefSkip(VSpace(VSpace::BIGSKIP));
641 string const length =
642 getLengthFromWidgets(class_->input_doc_skip,
643 class_->choice_doc_skip_units);
645 params.setDefSkip(VSpace(LyXGlueLength(length)));
649 // DocumentDefskipCB assures that this never happens
650 params.setDefSkip(VSpace(VSpace::MEDSKIP));
653 if (!(tmpdefskip == params.getDefSkip()))
656 if (fl_get_button(class_->radio_doc_columns_two))
660 if (fl_get_button(class_->radio_doc_sides_two))
661 params.sides = LyXTextClass::TwoSides;
663 params.sides = LyXTextClass::OneSide;
665 Spacing tmpSpacing = params.spacing;
666 switch (fl_get_choice(class_->choice_doc_spacing)) {
668 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
669 params.spacing.set(Spacing::Single);
672 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
673 params.spacing.set(Spacing::Onehalf);
676 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
677 params.spacing.set(Spacing::Double);
680 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
681 params.spacing.set(Spacing::Other,
682 getString(class_->input_doc_spacing));
685 if (tmpSpacing != params.spacing)
688 params.options = getString(class_->input_doc_extra);
694 void FormDocument::paper_apply(BufferParams & params)
696 params.papersize2 = char(fl_get_choice(paper_->choice_papersize) - 1);
698 params.paperpackage =
699 char(fl_get_choice(paper_->choice_paperpackage) - 1);
701 // set params.papersize from params.papersize2 and params.paperpackage
702 params.setPaperStuff();
704 params.use_geometry = fl_get_button(paper_->check_use_geometry);
706 if (fl_get_button(paper_->radio_landscape))
707 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
709 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
712 getLengthFromWidgets(paper_->input_custom_width,
713 paper_->choice_custom_width_units);
716 getLengthFromWidgets(paper_->input_custom_height,
717 paper_->choice_custom_height_units);
720 getLengthFromWidgets(paper_->input_inner_margin,
721 paper_->choice_inner_margin_units);
724 getLengthFromWidgets(paper_->input_top_margin,
725 paper_->choice_top_margin_units);
728 getLengthFromWidgets(paper_->input_outer_margin,
729 paper_->choice_outer_margin_units);
731 params.bottommargin =
732 getLengthFromWidgets(paper_->input_bottom_margin,
733 paper_->choice_bottom_margin_units);
736 getLengthFromWidgets(paper_->input_head_height,
737 paper_->choice_head_height_units);
740 getLengthFromWidgets(paper_->input_head_sep,
741 paper_->choice_head_sep_units);
744 getLengthFromWidgets(paper_->input_foot_skip,
745 paper_->choice_foot_skip_units);
749 bool FormDocument::language_apply(BufferParams & params)
751 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
754 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
756 lga = InsetQuotes::EnglishQ;
759 lga = InsetQuotes::SwedishQ;
762 lga = InsetQuotes::GermanQ;
765 lga = InsetQuotes::PolishQ;
768 lga = InsetQuotes::FrenchQ;
771 lga = InsetQuotes::DanishQ;
774 params.quotes_language = lga;
775 if (fl_get_button(language_->radio_single))
776 params.quotes_times = InsetQuotes::SingleQ;
778 params.quotes_times = InsetQuotes::DoubleQ;
780 int const pos = combo_language->get();
781 Language const * new_language = languages.getLanguage(lang_[pos-1]);
783 new_language = default_language;
785 params.language = new_language;
786 params.inputenc = getString(language_->choice_inputenc);
792 bool FormDocument::options_apply(BufferParams & params)
796 params.graphicsDriver = getString(options_->choice_postscript_driver);
797 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
798 params.use_natbib = fl_get_button(options_->check_use_natbib);
799 params.use_numerical_citations =
800 fl_get_choice(options_->choice_citation_format) - 1;
802 int tmpchar = int(fl_get_counter_value(options_->counter_secnumdepth));
803 if (params.secnumdepth != tmpchar)
805 params.secnumdepth = tmpchar;
807 params.tocdepth = int(fl_get_counter_value(options_->counter_tocdepth));
809 params.float_placement =
810 getString(options_->input_float_placement);
816 void FormDocument::bullets_apply(BufferParams & params)
818 /* update the bullet settings */
819 BufferParams & buf_params = controller().params();
821 // a little bit of loop unrolling
822 params.user_defined_bullets[0] = buf_params.temp_bullets[0];
823 params.user_defined_bullets[1] = buf_params.temp_bullets[1];
824 params.user_defined_bullets[2] = buf_params.temp_bullets[2];
825 params.user_defined_bullets[3] = buf_params.temp_bullets[3];
829 void FormDocument::UpdateClassParams(BufferParams const & params)
831 // These are the params that have to be updated on any class change
832 // (even if the class defaults are not used) (JSpitzm 2002-04-08)
834 LyXTextClass const & tclass = textclasslist[params.textclass];
836 combo_doc_class->select(tclass.description());
837 fl_clear_choice(class_->choice_doc_fontsize);
838 fl_addto_choice(class_->choice_doc_fontsize, "default");
839 fl_addto_choice(class_->choice_doc_fontsize,
840 tclass.opt_fontsize().c_str());
841 fl_set_choice_text(class_->choice_doc_fontsize,
842 params.fontsize.c_str());
843 fl_clear_choice(class_->choice_doc_pagestyle);
844 fl_addto_choice(class_->choice_doc_pagestyle, "default");
845 fl_addto_choice(class_->choice_doc_pagestyle,
846 tclass.opt_pagestyle().c_str());
847 fl_set_choice_text(class_->choice_doc_pagestyle,
848 params.pagestyle.c_str());
852 void FormDocument::class_update(BufferParams const & params)
857 UpdateClassParams(params);
859 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
861 bool const indent = params.paragraph_separation == BufferParams::PARSEP_INDENT;
862 fl_set_button(class_->radio_doc_indent, indent);
863 fl_set_button(class_->radio_doc_skip, !indent);
867 pos = 2; // VSpace::MEDSKIP is default
869 switch (params.getDefSkip().kind()) {
873 case VSpace::BIGSKIP:
876 case VSpace::SMALLSKIP:
879 case VSpace::MEDSKIP:
885 fl_set_choice (class_->choice_doc_skip, pos);
887 bool const length_input = pos == 4;
889 int const paperchoice = fl_get_choice(paper_->choice_papersize);
890 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
891 || paperchoice == 2 || paperchoice > 5;
892 string const default_unit = metric ? "cm" : "in";
893 string const length = params.getDefSkip().asLyXCommand();
894 updateWidgetsFromLengthString(class_->input_doc_skip,
895 class_->choice_doc_skip_units,
896 length, default_unit);
899 fl_set_input(class_->input_doc_skip, "");
901 setEnabled(class_->choice_doc_skip, !indent);
902 setEnabled(class_->input_doc_skip, length_input);
903 setEnabled(class_->choice_doc_skip_units, length_input);
905 bool const two_sides = params.sides == LyXTextClass::TwoSides;
906 fl_set_button(class_->radio_doc_sides_one, !two_sides);
907 fl_set_button(class_->radio_doc_sides_two, two_sides);
909 bool const two_columns = params.columns == 2;
910 fl_set_button(class_->radio_doc_columns_one, !two_columns);
911 fl_set_button(class_->radio_doc_columns_two, two_columns);
913 fl_set_input(class_->input_doc_extra, params.options.c_str());
915 switch (params.spacing.getSpace()) {
919 case Spacing::Double: // \doublespacing
922 case Spacing::Onehalf: // \onehalfspacing
925 case Spacing::Single: // \singlespacing
926 case Spacing::Default: // nothing bad should happen with this
931 fl_set_choice(class_->choice_doc_spacing, pos);
933 bool const spacing_input = pos == 4;
934 setEnabled(class_->input_doc_spacing, spacing_input);
935 string const input = spacing_input ? tostr(params.spacing.getValue()) : string();
936 fl_set_input(class_->input_doc_spacing, input.c_str());
940 void FormDocument::language_update(BufferParams const & params)
942 if (!language_.get())
945 int const pos = int(findPos(lang_, params.language->lang()));
946 combo_language->select(pos+1);
948 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
949 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
950 fl_set_button(language_->radio_single, 0);
951 fl_set_button(language_->radio_double, 0);
952 if (params.quotes_times == InsetQuotes::SingleQ)
953 fl_set_button(language_->radio_single, 1);
955 fl_set_button(language_->radio_double, 1);
959 void FormDocument::options_update(BufferParams const & params)
964 fl_set_choice_text(options_->choice_postscript_driver,
965 params.graphicsDriver.c_str());
966 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
967 fl_set_button(options_->check_use_natbib, params.use_natbib);
968 fl_set_choice(options_->choice_citation_format,
969 int(params.use_numerical_citations)+1);
970 setEnabled(options_->choice_citation_format, params.use_natbib);
971 fl_set_counter_value(options_->counter_secnumdepth, params.secnumdepth);
972 fl_set_counter_value(options_->counter_tocdepth, params.tocdepth);
973 if (!params.float_placement.empty())
974 fl_set_input(options_->input_float_placement,
975 params.float_placement.c_str());
977 fl_set_input(options_->input_float_placement, "");
981 void FormDocument::paper_update(BufferParams const & params)
986 fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
987 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
988 fl_set_button(paper_->check_use_geometry, params.use_geometry);
990 int const paperchoice = fl_get_choice(paper_->choice_papersize);
991 bool const useCustom = paperchoice == 2;
992 bool const useGeom = fl_get_button(paper_->check_use_geometry);
994 fl_set_button(paper_->radio_portrait, 0);
995 setEnabled(paper_->radio_portrait, !useCustom);
996 fl_set_button(paper_->radio_landscape, 0);
997 setEnabled(paper_->radio_landscape, !useCustom);
999 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1000 fl_set_button(paper_->radio_landscape, 1);
1002 fl_set_button(paper_->radio_portrait, 1);
1003 setEnabled(paper_->choice_paperpackage,
1004 //either default papersize (preferences)
1005 //or document papersize has to be A4
1007 || paperchoice == 1 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER)
1008 && fl_get_button(paper_->radio_portrait));
1010 // Default unit choice is cm if metric, inches if US paper.
1011 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
1012 || paperchoice == 2 || paperchoice > 5;
1013 string const default_unit = metric ? "cm" : "in";
1014 updateWidgetsFromLengthString(paper_->input_custom_width,
1015 paper_->choice_custom_width_units,
1016 params.paperwidth, default_unit);
1017 setEnabled(paper_->input_custom_width, useCustom);
1018 setEnabled(paper_->choice_custom_width_units, useCustom);
1020 updateWidgetsFromLengthString(paper_->input_custom_height,
1021 paper_->choice_custom_height_units,
1022 params.paperheight, default_unit);
1023 setEnabled(paper_->input_custom_height, useCustom);
1024 setEnabled(paper_->choice_custom_height_units, useCustom);
1026 updateWidgetsFromLengthString(paper_->input_inner_margin,
1027 paper_->choice_inner_margin_units,
1028 params.leftmargin, default_unit);
1029 setEnabled(paper_->input_inner_margin, useGeom);
1030 setEnabled(paper_->choice_inner_margin_units, useGeom);
1032 updateWidgetsFromLengthString(paper_->input_top_margin,
1033 paper_->choice_top_margin_units,
1034 params.topmargin, default_unit);
1035 setEnabled(paper_->input_top_margin, useGeom);
1036 setEnabled(paper_->choice_top_margin_units, useGeom);
1038 updateWidgetsFromLengthString(paper_->input_outer_margin,
1039 paper_->choice_outer_margin_units,
1040 params.rightmargin, default_unit);
1041 setEnabled(paper_->input_outer_margin, useGeom);
1042 setEnabled(paper_->choice_outer_margin_units, useGeom);
1044 updateWidgetsFromLengthString(paper_->input_bottom_margin,
1045 paper_->choice_bottom_margin_units,
1046 params.bottommargin, default_unit);
1047 setEnabled(paper_->input_bottom_margin, useGeom);
1048 setEnabled(paper_->choice_bottom_margin_units, useGeom);
1050 updateWidgetsFromLengthString(paper_->input_head_height,
1051 paper_->choice_head_height_units,
1052 params.headheight, default_unit);
1053 setEnabled(paper_->input_head_height, useGeom);
1054 setEnabled(paper_->choice_head_height_units, useGeom);
1056 updateWidgetsFromLengthString(paper_->input_head_sep,
1057 paper_->choice_head_sep_units,
1058 params.headsep, default_unit);
1059 setEnabled(paper_->input_head_sep, useGeom);
1060 setEnabled(paper_->choice_head_sep_units, useGeom);
1062 updateWidgetsFromLengthString(paper_->input_foot_skip,
1063 paper_->choice_foot_skip_units,
1064 params.footskip, default_unit);
1065 setEnabled(paper_->input_foot_skip, useGeom);
1066 setEnabled(paper_->choice_foot_skip_units, useGeom);
1068 fl_set_focus_object(paper_->form, paper_->choice_papersize);
1072 void FormDocument::bullets_update(BufferParams const & params)
1074 if (!bullets_.get() ||
1076 (XpmVersion==4 && XpmRevision<7)))
1079 bool const isLinuxDoc =
1080 controller().docType() == ControlDocument::LINUXDOC;
1081 setEnabled(fbullet, !isLinuxDoc);
1083 if (isLinuxDoc) return;
1085 fl_set_button(bullets_->radio_bullet_depth_1, 1);
1086 fl_set_input(bullets_->input_bullet_latex,
1087 params.user_defined_bullets[0].getText().c_str());
1088 fl_set_choice(bullets_->choice_bullet_size,
1089 params.user_defined_bullets[0].getSize() + 2);
1093 void FormDocument::checkReadOnly()
1095 if (bc().readOnly(controller().bufferIsReadonly())) {
1096 combo_doc_class->deactivate();
1097 combo_language->deactivate();
1098 postWarning(_("Document is read-only."
1099 " No changes to layout permitted."));
1101 combo_doc_class->activate();
1102 combo_language->activate();
1108 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/)
1110 BufferParams & param = controller().params();
1112 // convert from 1-6 range to -1-4
1113 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1114 fl_set_input(bullets_->input_bullet_latex,
1115 param.temp_bullets[current_bullet_depth].getText().c_str());
1119 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1121 BufferParams & param = controller().params();
1123 param.temp_bullets[current_bullet_depth].
1124 setText(getString(bullets_->input_bullet_latex));
1128 void FormDocument::BulletDepth(FL_OBJECT * ob)
1130 /* Should I do the following: */
1131 /* 1. change to the panel that the current bullet belongs in */
1132 /* 2. show that bullet as selected */
1133 /* 3. change the size setting to the size of the bullet in Q.*/
1134 /* 4. display the latex equivalent in the latex box */
1136 /* I'm inclined to just go with 3 and 4 at the moment and */
1137 /* maybe try to support the others later */
1138 BufferParams & param = controller().params();
1141 if (ob == bullets_->radio_bullet_depth_1)
1143 else if (ob == bullets_->radio_bullet_depth_2)
1145 else if (ob == bullets_->radio_bullet_depth_3)
1147 else if (ob == bullets_->radio_bullet_depth_4)
1150 switch (fl_get_button_numb(ob)) {
1152 // right mouse button resets to default
1153 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1155 current_bullet_depth = data;
1156 fl_set_input(bullets_->input_bullet_latex,
1157 param.temp_bullets[data].getText().c_str());
1158 fl_set_choice(bullets_->choice_bullet_size,
1159 param.temp_bullets[data].getSize() + 2);
1164 void FormDocument::BulletPanel(FL_OBJECT * ob)
1166 /* Here we have to change the background pixmap to that selected */
1167 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1170 if (ob == bullets_->radio_bullet_panel_standard)
1172 else if (ob == bullets_->radio_bullet_panel_maths)
1174 else if (ob == bullets_->radio_bullet_panel_ding2)
1176 else if (ob == bullets_->radio_bullet_panel_ding3)
1178 else if (ob == bullets_->radio_bullet_panel_ding4)
1180 else if (ob == bullets_->radio_bullet_panel_ding1)
1183 if (data != current_bullet_panel) {
1184 fl_freeze_form(bullets_->form);
1185 current_bullet_panel = data;
1187 /* free the current pixmap */
1188 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1190 if (ob == bullets_->radio_bullet_panel_standard) {
1191 new_panel = "standard";
1192 } else if (ob == bullets_->radio_bullet_panel_maths ) {
1193 new_panel = "amssymb";
1194 } else if (ob == bullets_->radio_bullet_panel_ding2) {
1195 new_panel = "psnfss1";
1196 } else if (ob == bullets_->radio_bullet_panel_ding3) {
1197 new_panel = "psnfss2";
1198 } else if (ob == bullets_->radio_bullet_panel_ding4) {
1199 new_panel = "psnfss3";
1200 } else if (ob == bullets_->radio_bullet_panel_ding1) {
1201 new_panel = "psnfss4";
1203 /* something very wrong happened */
1204 // play it safe for now but should be an exception
1205 current_bullet_panel = 0; // standard panel
1206 new_panel = "standard";
1208 new_panel += ".xpm";
1209 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1210 LibFileSearch("images", new_panel).c_str());
1211 fl_redraw_object(bullets_->bmtable_bullet_panel);
1212 fl_unfreeze_form(bullets_->form);
1217 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/)
1219 /* handle the user input by setting the current bullet depth's pixmap */
1220 /* to that extracted from the current chosen position of the BMTable */
1221 /* Don't forget to free the button's old pixmap first. */
1223 BufferParams & param = controller().params();
1224 int bmtable_button = fl_get_bmtable(ob);
1226 /* try to keep the button held down till another is pushed */
1227 /* fl_set_bmtable(ob, 1, bmtable_button); */
1228 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1229 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1230 fl_set_input(bullets_->input_bullet_latex,
1231 param.temp_bullets[current_bullet_depth].getText().c_str());
1235 void FormDocument::CheckChoiceClass()
1237 BufferParams & params = controller().params();
1239 lyx::textclass_type const tc = combo_doc_class->get() - 1;
1241 if (controller().loadTextclass(tc)) {
1242 params.textclass = tc;
1244 if (lyxrc.auto_reset_options) {
1245 params.useClassDefaults();
1246 UpdateLayoutDocument(params);
1248 // update the params which are needed in any case
1249 // (fontsizes, pagestyle)
1250 UpdateClassParams(params);
1254 int const revert = int(params.textclass);
1255 combo_doc_class->select(revert + 1);
1260 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1266 class_update(params);
1267 paper_update(params);
1268 language_update(params);
1269 options_update(params);
1270 bullets_update(params);