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 #pragma implementation
18 #include "ControlDocument.h"
19 #include "FormDocument.h"
20 #include "forms/form_document.h"
24 #include "checkedwidgets.h"
26 #include "input_validators.h" // fl_unsigned_float_filter
27 #include "xforms_helpers.h"
30 //#include "BufferView.h"
31 #include "CutAndPaste.h"
34 //#include "lyx_main.h" // for user_lyxdir
36 #include "lyxtextclasslist.h"
37 #include "tex-strings.h"
39 #include "controllers/frnt_lang.h"
40 #include "controllers/helper_funcs.h"
42 #include "support/lstrings.h" // contains_functor, getStringFromVector
43 #include "support/filetools.h" // LibFileSearch
45 #include XPM_H_LOCATION
46 #include FORMS_H_LOCATION
48 #include <boost/bind.hpp>
56 typedef FormCB<ControlDocument, FormDB<FD_document> > base_class;
58 FormDocument::FormDocument()
59 : base_class(_("Document Layout"), false),
60 ActCell(0), Confirmed(0),
61 current_bullet_panel(0), current_bullet_depth(0), fbullet(0)
65 void FormDocument::redraw()
67 if (form() && form()->visible)
68 fl_redraw_form(form());
72 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder);
73 if (outer_form && outer_form->visible)
74 fl_redraw_form(outer_form);
78 void FormDocument::build()
81 dialog_.reset(build_document(this));
83 // Allow the base class to control messages
84 setMessageWidget(dialog_->text_warning);
86 // Manage the restore, ok, apply, restore and cancel/close buttons
87 bc().setOK(dialog_->button_ok);
88 bc().setApply(dialog_->button_apply);
89 bc().setCancel(dialog_->button_close);
90 bc().setRestore(dialog_->button_restore);
92 // the document class form
93 class_.reset(build_document_class(this));
95 // disable for read-only documents
96 bc().addReadOnly(class_->radio_doc_indent);
97 bc().addReadOnly(class_->radio_doc_skip);
98 bc().addReadOnly(class_->choice_doc_pagestyle);
99 bc().addReadOnly(class_->choice_doc_fonts);
100 bc().addReadOnly(class_->choice_doc_fontsize);
101 bc().addReadOnly(class_->radio_doc_sides_one);
102 bc().addReadOnly(class_->radio_doc_sides_two);
103 bc().addReadOnly(class_->radio_doc_columns_one);
104 bc().addReadOnly(class_->radio_doc_columns_two);
105 bc().addReadOnly(class_->input_doc_extra);
106 bc().addReadOnly(class_->input_doc_skip);
107 bc().addReadOnly(class_->choice_doc_skip);
108 bc().addReadOnly(class_->choice_doc_spacing);
109 bc().addReadOnly(class_->input_doc_spacing);
111 // check validity of "length + unit" input
112 addCheckedGlueLength(bc(), class_->input_doc_skip,
113 class_->choice_doc_skip);
115 // trigger an input event for cut&paste with middle mouse button.
116 setPrehandler(class_->input_doc_extra);
117 setPrehandler(class_->input_doc_skip);
118 setPrehandler(class_->input_doc_spacing);
120 fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
121 fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
122 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
126 // the class list is a combo-box and has to be inserted manually
127 obj = class_->choice_doc_class;
128 fl_deactivate_object(obj);
129 fl_addto_form(class_->form);
130 combo_doc_class.reset(new Combox(FL_COMBOX_DROPLIST));
131 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400);
132 combo_doc_class->shortcut("#C",1);
133 combo_doc_class->setcallback(ComboInputCB, this);
135 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
136 cit != textclasslist.end(); ++cit) {
137 combo_doc_class->addto(cit->description());
140 fl_addto_choice(class_->choice_doc_spacing,
141 _(" Single | OneHalf | Double | Custom "));
142 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
143 for (int n = 0; tex_fonts[n][0]; ++n) {
144 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
147 // Create the contents of the unit choices; don't include the
149 vector<string> units_vec = getLatexUnits();
150 vector<string>::iterator ret =
151 std::remove_if(units_vec.begin(),
153 bind2nd(contains_functor(), "%"));
154 units_vec.erase(ret, units_vec.end());
156 string const units = getStringFromVector(units_vec, "|");
158 fl_addto_choice(class_->choice_doc_pagestyle,
159 "default|empty|plain|headings|fancy");
160 fl_addto_choice(class_->choice_doc_skip,
161 _(" SmallSkip | MedSkip | BigSkip | Length "));
162 fl_addto_choice(class_->choice_doc_skip_units, units.c_str());
164 // Set input filters on doc spacing to make it accept only
166 fl_set_input_filter(class_->input_doc_spacing,
167 fl_unsigned_float_filter);
169 // disable for read-only documents
170 bc().addReadOnly(dialog_->button_save_defaults);
171 bc().addReadOnly(dialog_->button_reset_defaults);
173 // the document paper form
174 paper_.reset(build_document_paper(this));
176 // disable for read-only documents
177 bc().addReadOnly(paper_->choice_paperpackage);
178 bc().addReadOnly(paper_->radio_portrait);
179 bc().addReadOnly(paper_->radio_landscape);
180 bc().addReadOnly(paper_->choice_papersize);
181 bc().addReadOnly(paper_->check_use_geometry);
182 bc().addReadOnly(paper_->input_custom_width);
183 bc().addReadOnly(paper_->input_custom_height);
184 bc().addReadOnly(paper_->input_top_margin);
185 bc().addReadOnly(paper_->input_bottom_margin);
186 bc().addReadOnly(paper_->input_inner_margin);
187 bc().addReadOnly(paper_->input_outer_margin);
188 bc().addReadOnly(paper_->input_head_height);
189 bc().addReadOnly(paper_->input_head_sep);
190 bc().addReadOnly(paper_->input_foot_skip);
192 // check validity of "length + unit" input
193 addCheckedGlueLength(bc(), paper_->input_custom_width);
194 addCheckedGlueLength(bc(), paper_->input_custom_height);
195 addCheckedGlueLength(bc(), paper_->input_top_margin);
196 addCheckedGlueLength(bc(), paper_->input_bottom_margin);
197 addCheckedGlueLength(bc(), paper_->input_inner_margin);
198 addCheckedGlueLength(bc(), paper_->input_outer_margin);
199 addCheckedGlueLength(bc(), paper_->input_head_height);
200 addCheckedGlueLength(bc(), paper_->input_head_sep);
201 addCheckedGlueLength(bc(), paper_->input_foot_skip);
203 // trigger an input event for cut&paste with middle mouse button.
204 setPrehandler(paper_->input_custom_width);
205 setPrehandler(paper_->input_custom_height);
206 setPrehandler(paper_->input_top_margin);
207 setPrehandler(paper_->input_bottom_margin);
208 setPrehandler(paper_->input_inner_margin);
209 setPrehandler(paper_->input_outer_margin);
210 setPrehandler(paper_->input_head_height);
211 setPrehandler(paper_->input_head_sep);
212 setPrehandler(paper_->input_foot_skip);
214 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
215 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
216 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
217 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
218 fl_set_input_return(paper_->input_inner_margin, FL_RETURN_CHANGED);
219 fl_set_input_return(paper_->input_outer_margin, FL_RETURN_CHANGED);
220 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
221 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
222 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
224 fl_addto_choice(paper_->choice_papersize,
225 _(" Default | Custom | US letter | US legal "
226 "| US executive | A3 | A4 | A5 | B3 | B4 | B5 "));
227 fl_addto_choice(paper_->choice_paperpackage,
230 "| Very small Margins "
231 "| Very wide Margins "));
233 fl_addto_choice(paper_->choice_custom_width_units, units.c_str());
234 fl_addto_choice(paper_->choice_custom_height_units, units.c_str());
235 fl_addto_choice(paper_->choice_top_margin_units, units.c_str());
236 fl_addto_choice(paper_->choice_bottom_margin_units, units.c_str());
237 fl_addto_choice(paper_->choice_inner_margin_units, units.c_str());
238 fl_addto_choice(paper_->choice_outer_margin_units, units.c_str());
239 fl_addto_choice(paper_->choice_head_height_units, units.c_str());
240 fl_addto_choice(paper_->choice_head_sep_units, units.c_str());
241 fl_addto_choice(paper_->choice_foot_skip_units, units.c_str());
243 // the document language form
244 language_.reset(build_document_language(this));
246 // disable for read-only documents
247 bc().addReadOnly(language_->choice_inputenc);
248 bc().addReadOnly(language_->choice_quotes_language);
249 bc().addReadOnly(language_->radio_single);
250 bc().addReadOnly(language_->radio_double);
252 fl_addto_choice(language_->choice_inputenc,
253 "default|auto|latin1|latin2|latin3|latin4|latin5|latin9"
254 "|koi8-r|koi8-u|cp866|cp1251|iso88595|pt154");
256 vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
257 // Store the identifiers for later
258 lang_ = getSecond(langs);
260 // The language is a combo-box and has to be inserted manually
261 obj = language_->choice_language;
262 fl_deactivate_object(obj);
263 fl_addto_form(language_->form);
264 combo_language.reset(new Combox(FL_COMBOX_DROPLIST));
265 combo_language->add(obj->x, obj->y, obj->w, obj->h, 400);
266 combo_language->shortcut("#L",1);
267 combo_language->setcallback(ComboInputCB, this);
270 vector<frnt::LanguagePair>::const_iterator lit = langs.begin();
271 vector<frnt::LanguagePair>::const_iterator lend = langs.end();
272 for (; lit != lend; ++lit) {
273 combo_language->addto(lit->first);
275 combo_language->select(1);
277 fl_addto_choice(language_->choice_quotes_language,
278 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
279 " «text» | »text« "));
281 // the document options form
282 options_.reset(build_document_options(this));
284 // disable for read-only documents
285 bc().addReadOnly(options_->counter_secnumdepth);
286 bc().addReadOnly(options_->counter_tocdepth);
287 bc().addReadOnly(options_->check_use_amsmath);
288 bc().addReadOnly(options_->check_use_natbib);
289 bc().addReadOnly(options_->choice_citation_format);
290 bc().addReadOnly(options_->input_float_placement);
291 bc().addReadOnly(options_->choice_postscript_driver);
293 // trigger an input event for cut&paste with middle mouse button.
294 setPrehandler(options_->input_float_placement);
296 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
298 for (int n = 0; tex_graphics[n][0]; ++n) {
299 fl_addto_choice(options_->choice_postscript_driver,
302 fl_addto_choice(options_->choice_citation_format,
303 _(" Author-year | Numerical "));
305 // the document bullets form
306 bullets_.reset(build_document_bullet(this));
308 // disable for read-only documents
309 bc().addReadOnly(bullets_->radio_bullet_depth_1);
310 bc().addReadOnly(bullets_->radio_bullet_depth_2);
311 bc().addReadOnly(bullets_->radio_bullet_depth_3);
312 bc().addReadOnly(bullets_->radio_bullet_depth_4);
313 bc().addReadOnly(bullets_->radio_bullet_panel_standard);
314 bc().addReadOnly(bullets_->radio_bullet_panel_maths);
315 bc().addReadOnly(bullets_->radio_bullet_panel_ding1);
316 bc().addReadOnly(bullets_->radio_bullet_panel_ding2);
317 bc().addReadOnly(bullets_->radio_bullet_panel_ding3);
318 bc().addReadOnly(bullets_->radio_bullet_panel_ding4);
319 bc().addReadOnly(bullets_->bmtable_bullet_panel);
320 bc().addReadOnly(bullets_->choice_bullet_size);
321 bc().addReadOnly(bullets_->input_bullet_latex);
323 // trigger an input event for cut&paste with middle mouse button.
324 setPrehandler(bullets_->input_bullet_latex);
326 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
328 fl_addto_choice(bullets_->choice_bullet_size,
329 _(" Default | Tiny | Smallest | Smaller | Small |"
330 " Normal | Large | Larger | Largest | Huge | Huger "));
331 fl_set_choice(bullets_->choice_bullet_size, 1);
333 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
335 string const bmtablefile = LibFileSearch("images", "standard", "xpm");
336 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
337 bmtablefile.c_str());
339 fl_addto_tabfolder(dialog_->tabfolder,_("Document"),
341 fl_addto_tabfolder(dialog_->tabfolder,_("Paper"),
343 fl_addto_tabfolder(dialog_->tabfolder,_("Language"),
345 fl_addto_tabfolder(dialog_->tabfolder,_("Extra"),
347 fbullet = fl_addto_tabfolder(dialog_->tabfolder,_("Bullets"),
350 // work-around xforms bug re update of folder->x, folder->y coords.
351 setPrehandler(dialog_->tabfolder);
353 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
354 lyxerr << _("Your version of libXpm is older than 4.7.\n"
355 "The `bullet' tab of the document dialog "
356 "has been disabled") << '\n';
357 fl_deactivate_object(fbullet);
358 fl_set_object_lcol(fbullet, FL_INACTIVE);
363 void FormDocument::apply()
365 BufferParams & params = controller().params();
369 language_apply(params);
370 options_apply(params);
371 bullets_apply(params);
375 void FormDocument::update()
382 BufferParams const & params = controller().params();
384 class_update(params);
385 paper_update(params);
386 language_update(params);
387 options_update(params);
388 bullets_update(params);
392 ButtonPolicy::SMInput FormDocument::input(FL_OBJECT * ob, long)
394 if (ob == bullets_->choice_bullet_size) {
395 ChoiceBulletSize(ob, 0);
397 } else if (ob == bullets_->input_bullet_latex) {
398 InputBulletLaTeX(ob, 0);
400 } else if (ob == bullets_->radio_bullet_depth_1 ||
401 ob == bullets_->radio_bullet_depth_2 ||
402 ob == bullets_->radio_bullet_depth_3 ||
403 ob == bullets_->radio_bullet_depth_4) {
406 } else if (ob == bullets_->radio_bullet_panel_standard ||
407 ob == bullets_->radio_bullet_panel_maths ||
408 ob == bullets_->radio_bullet_panel_ding1 ||
409 ob == bullets_->radio_bullet_panel_ding2 ||
410 ob == bullets_->radio_bullet_panel_ding3 ||
411 ob == bullets_->radio_bullet_panel_ding4) {
414 } else if (ob == bullets_->bmtable_bullet_panel) {
415 BulletBMTable(ob, 0);
417 } else if (ob == class_->choice_doc_spacing) {
418 setEnabled(class_->input_doc_spacing,
419 fl_get_choice(class_->choice_doc_spacing) == 4);
421 } else if (ob == class_->radio_doc_skip ||
422 ob == class_->radio_doc_indent ||
423 ob == class_->choice_doc_skip) {
424 bool const skip_used = fl_get_button(class_->radio_doc_skip);
425 setEnabled(class_->choice_doc_skip, skip_used);
427 bool const length_input =
428 fl_get_choice(class_->choice_doc_skip) == 4;
429 setEnabled(class_->input_doc_skip,
430 skip_used && length_input);
431 setEnabled(class_->choice_doc_skip_units,
432 skip_used && length_input);
434 // Default unit choice is cm if metric, inches if US paper.
435 // If papersize is default, check the lyxrc-settings
436 int const paperchoice = fl_get_choice(paper_->choice_papersize);
437 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
438 || paperchoice == 2 || paperchoice > 5;
439 string const default_unit = metric ? "cm" : "in";
440 if (getString(class_->input_doc_skip).empty())
441 fl_set_choice_text(class_->choice_doc_skip_units,
442 default_unit.c_str());
444 } else if (ob == options_->check_use_natbib) {
445 setEnabled(options_->choice_citation_format,
446 fl_get_button(options_->check_use_natbib));
448 } else if (ob == dialog_->button_save_defaults) {
450 controller().saveAsDefault();
452 } else if (ob == dialog_->button_reset_defaults) {
453 BufferParams & params = controller().params();
454 params.textclass = combo_doc_class->get() - 1;
455 params.useClassDefaults();
456 UpdateLayoutDocument(params);
458 } else if (ob == paper_->radio_landscape) {
459 fl_set_choice(paper_->choice_paperpackage,
460 BufferParams::PACKAGE_NONE + 1);
462 } else if (ob == paper_->choice_papersize) {
463 int const paperchoice = fl_get_choice(paper_->choice_papersize);
464 bool const defsize = paperchoice == 1;
465 bool const custom = paperchoice == 2;
466 bool const a3size = paperchoice == 6;
467 bool const b3size = paperchoice == 9;
468 bool const b4size = paperchoice == 10;
471 fl_set_button(paper_->radio_portrait, 1);
473 bool const use_geom = (custom || a3size || b3size || b4size);
475 fl_set_button(paper_->check_use_geometry, int(use_geom));
477 setEnabled(paper_->input_top_margin, use_geom);
478 setEnabled(paper_->input_bottom_margin, use_geom);
479 setEnabled(paper_->input_inner_margin, use_geom);
480 setEnabled(paper_->input_outer_margin, use_geom);
481 setEnabled(paper_->input_head_height, use_geom);
482 setEnabled(paper_->input_head_sep, use_geom);
483 setEnabled(paper_->input_foot_skip, use_geom);
484 setEnabled(paper_->choice_top_margin_units, use_geom);
485 setEnabled(paper_->choice_bottom_margin_units, use_geom);
486 setEnabled(paper_->choice_inner_margin_units, use_geom);
487 setEnabled(paper_->choice_outer_margin_units, use_geom);
488 setEnabled(paper_->choice_head_height_units, use_geom);
489 setEnabled(paper_->choice_head_sep_units, use_geom);
490 setEnabled(paper_->choice_foot_skip_units, use_geom);
491 setEnabled(paper_->choice_custom_width_units, use_geom);
492 setEnabled(paper_->choice_custom_height_units, use_geom);
494 setEnabled(paper_->input_custom_width, custom);
495 setEnabled(paper_->input_custom_height, custom);
496 setEnabled(paper_->choice_custom_width_units, custom);
497 setEnabled(paper_->choice_custom_height_units, custom);
498 setEnabled(paper_->radio_portrait, !custom);
499 setEnabled(paper_->radio_landscape, !custom);
501 // Default unit choice is cm if metric, inches if US paper.
502 // If papersize is default, use the lyxrc-settings
503 bool const metric = (defsize && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
504 || paperchoice == 2 || paperchoice > 5;
505 string const default_unit = metric ? "cm" : "in";
506 if (getString(paper_->input_custom_width).empty())
507 fl_set_choice_text(paper_->choice_custom_width_units,
508 default_unit.c_str());
509 if (getString(paper_->input_custom_height).empty())
510 fl_set_choice_text(paper_->choice_custom_height_units,
511 default_unit.c_str());
512 if (getString(paper_->input_top_margin).empty())
513 fl_set_choice_text(paper_->choice_top_margin_units,
514 default_unit.c_str());
515 if (getString(paper_->input_bottom_margin).empty())
516 fl_set_choice_text(paper_->choice_bottom_margin_units,
517 default_unit.c_str());
518 if (getString(paper_->input_inner_margin).empty())
519 fl_set_choice_text(paper_->choice_inner_margin_units,
520 default_unit.c_str());
521 if (getString(paper_->input_outer_margin).empty())
522 fl_set_choice_text(paper_->choice_outer_margin_units,
523 default_unit.c_str());
524 if (getString(paper_->input_head_height).empty())
525 fl_set_choice_text(paper_->choice_head_height_units,
526 default_unit.c_str());
527 if (getString(paper_->input_head_sep).empty())
528 fl_set_choice_text(paper_->choice_head_sep_units,
529 default_unit.c_str());
530 if (getString(paper_->input_foot_skip).empty())
531 fl_set_choice_text(paper_->choice_foot_skip_units,
532 default_unit.c_str());
534 } else if (ob == paper_->choice_paperpackage &&
535 fl_get_choice(paper_->choice_paperpackage) != 1) {
537 fl_set_button(paper_->check_use_geometry, 0);
538 setEnabled(paper_->input_top_margin, false);
539 setEnabled(paper_->input_bottom_margin, false);
540 setEnabled(paper_->input_inner_margin, false);
541 setEnabled(paper_->input_outer_margin, false);
542 setEnabled(paper_->input_head_height, false);
543 setEnabled(paper_->input_head_sep, false);
544 setEnabled(paper_->input_foot_skip, false);
545 setEnabled(paper_->choice_top_margin_units, false);
546 setEnabled(paper_->choice_bottom_margin_units, false);
547 setEnabled(paper_->choice_inner_margin_units, false);
548 setEnabled(paper_->choice_outer_margin_units, false);
549 setEnabled(paper_->choice_head_height_units, false);
550 setEnabled(paper_->choice_head_sep_units, false);
551 setEnabled(paper_->choice_foot_skip_units, false);
553 } else if (ob == paper_->check_use_geometry) {
554 // don't allow switching geometry off in custom papersize
555 // mode nor in A3, B3, and B4
556 int const choice = fl_get_choice(paper_->choice_papersize);
557 if (choice == 2 || choice == 6 || choice == 9 || choice == 10)
558 fl_set_button(paper_->check_use_geometry, 1);
560 fl_set_choice(paper_->choice_paperpackage,
561 BufferParams::PACKAGE_NONE + 1);
563 bool const use_geom = fl_get_button(paper_->check_use_geometry);
564 setEnabled(paper_->input_top_margin, use_geom);
565 setEnabled(paper_->input_bottom_margin, use_geom);
566 setEnabled(paper_->input_inner_margin, use_geom);
567 setEnabled(paper_->input_outer_margin, use_geom);
568 setEnabled(paper_->input_head_height, use_geom);
569 setEnabled(paper_->input_head_sep, use_geom);
570 setEnabled(paper_->input_foot_skip, use_geom);
571 setEnabled(paper_->choice_top_margin_units, use_geom);
572 setEnabled(paper_->choice_bottom_margin_units, use_geom);
573 setEnabled(paper_->choice_inner_margin_units, use_geom);
574 setEnabled(paper_->choice_outer_margin_units, use_geom);
575 setEnabled(paper_->choice_head_height_units, use_geom);
576 setEnabled(paper_->choice_head_sep_units, use_geom);
577 setEnabled(paper_->choice_foot_skip_units, use_geom);
580 if (ob == paper_->choice_papersize || ob == paper_->radio_portrait
581 || ob == paper_->radio_landscape) {
582 // either default papersize (preferences) or document
583 // papersize has to be A4
584 bool const enable = ( fl_get_choice(paper_->choice_papersize) == 1
585 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER )
586 || fl_get_choice(paper_->choice_papersize) == 7;
587 setEnabled(paper_->choice_paperpackage, enable && fl_get_button(paper_->radio_portrait));
590 return ButtonPolicy::SMI_VALID;
594 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
596 FormDocument * pre = static_cast<FormDocument*>(v);
597 if (combox == pre->combo_doc_class.get())
598 pre->CheckChoiceClass();
603 bool FormDocument::class_apply(BufferParams ¶ms)
607 // If default skip is a "Length" but there's no text in the
608 // input field, reset the kind to "MedSkip", which is the default.
609 if (fl_get_choice(class_->choice_doc_skip) == 4 &&
610 getString(class_->input_doc_skip).empty()) {
611 fl_set_choice(class_->choice_doc_skip, 2);
613 params.fonts = getString(class_->choice_doc_fonts);
614 params.fontsize = getString(class_->choice_doc_fontsize);
615 params.pagestyle = getString(class_->choice_doc_pagestyle);
617 params.textclass = combo_doc_class->get() - 1;
619 BufferParams::PARSEP tmpsep = params.paragraph_separation;
620 if (fl_get_button(class_->radio_doc_indent))
621 params.paragraph_separation = BufferParams::PARSEP_INDENT;
623 params.paragraph_separation = BufferParams::PARSEP_SKIP;
624 if (tmpsep != params.paragraph_separation)
627 VSpace tmpdefskip = params.getDefSkip();
628 switch (fl_get_choice(class_->choice_doc_skip)) {
630 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
633 params.setDefSkip(VSpace(VSpace::MEDSKIP));
636 params.setDefSkip(VSpace(VSpace::BIGSKIP));
640 string const length =
641 getLengthFromWidgets(class_->input_doc_skip,
642 class_->choice_doc_skip_units);
644 params.setDefSkip(VSpace(LyXGlueLength(length)));
648 // DocumentDefskipCB assures that this never happens
649 params.setDefSkip(VSpace(VSpace::MEDSKIP));
652 if (!(tmpdefskip == params.getDefSkip()))
655 if (fl_get_button(class_->radio_doc_columns_two))
659 if (fl_get_button(class_->radio_doc_sides_two))
660 params.sides = LyXTextClass::TwoSides;
662 params.sides = LyXTextClass::OneSide;
664 Spacing tmpSpacing = params.spacing;
665 switch (fl_get_choice(class_->choice_doc_spacing)) {
667 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
668 params.spacing.set(Spacing::Single);
671 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
672 params.spacing.set(Spacing::Onehalf);
675 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
676 params.spacing.set(Spacing::Double);
679 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
680 params.spacing.set(Spacing::Other,
681 getString(class_->input_doc_spacing));
684 if (tmpSpacing != params.spacing)
687 params.options = getString(class_->input_doc_extra);
693 void FormDocument::paper_apply(BufferParams & params)
695 params.papersize2 = char(fl_get_choice(paper_->choice_papersize) - 1);
697 params.paperpackage =
698 char(fl_get_choice(paper_->choice_paperpackage) - 1);
700 // set params.papersize from params.papersize2 and params.paperpackage
701 params.setPaperStuff();
703 params.use_geometry = fl_get_button(paper_->check_use_geometry);
705 if (fl_get_button(paper_->radio_landscape))
706 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
708 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
711 getLengthFromWidgets(paper_->input_custom_width,
712 paper_->choice_custom_width_units);
715 getLengthFromWidgets(paper_->input_custom_height,
716 paper_->choice_custom_height_units);
719 getLengthFromWidgets(paper_->input_inner_margin,
720 paper_->choice_inner_margin_units);
723 getLengthFromWidgets(paper_->input_top_margin,
724 paper_->choice_top_margin_units);
727 getLengthFromWidgets(paper_->input_outer_margin,
728 paper_->choice_outer_margin_units);
730 params.bottommargin =
731 getLengthFromWidgets(paper_->input_bottom_margin,
732 paper_->choice_bottom_margin_units);
735 getLengthFromWidgets(paper_->input_head_height,
736 paper_->choice_head_height_units);
739 getLengthFromWidgets(paper_->input_head_sep,
740 paper_->choice_head_sep_units);
743 getLengthFromWidgets(paper_->input_foot_skip,
744 paper_->choice_foot_skip_units);
748 bool FormDocument::language_apply(BufferParams & params)
750 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
753 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
755 lga = InsetQuotes::EnglishQ;
758 lga = InsetQuotes::SwedishQ;
761 lga = InsetQuotes::GermanQ;
764 lga = InsetQuotes::PolishQ;
767 lga = InsetQuotes::FrenchQ;
770 lga = InsetQuotes::DanishQ;
773 params.quotes_language = lga;
774 if (fl_get_button(language_->radio_single))
775 params.quotes_times = InsetQuotes::SingleQ;
777 params.quotes_times = InsetQuotes::DoubleQ;
779 int const pos = combo_language->get();
780 Language const * new_language = languages.getLanguage(lang_[pos-1]);
782 new_language = default_language;
784 params.language = new_language;
785 params.inputenc = getString(language_->choice_inputenc);
791 bool FormDocument::options_apply(BufferParams & params)
795 params.graphicsDriver = getString(options_->choice_postscript_driver);
796 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
797 params.use_natbib = fl_get_button(options_->check_use_natbib);
798 params.use_numerical_citations =
799 fl_get_choice(options_->choice_citation_format) - 1;
801 int tmpchar = int(fl_get_counter_value(options_->counter_secnumdepth));
802 if (params.secnumdepth != tmpchar)
804 params.secnumdepth = tmpchar;
806 params.tocdepth = int(fl_get_counter_value(options_->counter_tocdepth));
808 params.float_placement =
809 getString(options_->input_float_placement);
815 void FormDocument::bullets_apply(BufferParams & params)
817 /* update the bullet settings */
818 BufferParams & buf_params = controller().params();
820 // a little bit of loop unrolling
821 params.user_defined_bullets[0] = buf_params.temp_bullets[0];
822 params.user_defined_bullets[1] = buf_params.temp_bullets[1];
823 params.user_defined_bullets[2] = buf_params.temp_bullets[2];
824 params.user_defined_bullets[3] = buf_params.temp_bullets[3];
828 void FormDocument::UpdateClassParams(BufferParams const & params)
830 // These are the params that have to be updated on any class change
831 // (even if the class defaults are not used) (JSpitzm 2002-04-08)
833 LyXTextClass const & tclass = textclasslist[params.textclass];
835 combo_doc_class->select(tclass.description());
836 fl_clear_choice(class_->choice_doc_fontsize);
837 fl_addto_choice(class_->choice_doc_fontsize, "default");
838 fl_addto_choice(class_->choice_doc_fontsize,
839 tclass.opt_fontsize().c_str());
840 fl_set_choice_text(class_->choice_doc_fontsize,
841 params.fontsize.c_str());
842 fl_clear_choice(class_->choice_doc_pagestyle);
843 fl_addto_choice(class_->choice_doc_pagestyle, "default");
844 fl_addto_choice(class_->choice_doc_pagestyle,
845 tclass.opt_pagestyle().c_str());
846 fl_set_choice_text(class_->choice_doc_pagestyle,
847 params.pagestyle.c_str());
851 void FormDocument::class_update(BufferParams const & params)
856 UpdateClassParams(params);
858 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
860 bool const indent = params.paragraph_separation == BufferParams::PARSEP_INDENT;
861 fl_set_button(class_->radio_doc_indent, indent);
862 fl_set_button(class_->radio_doc_skip, !indent);
866 pos = 2; // VSpace::MEDSKIP is default
868 switch (params.getDefSkip().kind()) {
872 case VSpace::BIGSKIP:
875 case VSpace::SMALLSKIP:
878 case VSpace::MEDSKIP:
884 fl_set_choice (class_->choice_doc_skip, pos);
886 bool const length_input = pos == 4;
888 int const paperchoice = fl_get_choice(paper_->choice_papersize);
889 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
890 || paperchoice == 2 || paperchoice > 5;
891 string const default_unit = metric ? "cm" : "in";
892 string const length = params.getDefSkip().asLyXCommand();
893 updateWidgetsFromLengthString(class_->input_doc_skip,
894 class_->choice_doc_skip_units,
895 length, default_unit);
898 fl_set_input(class_->input_doc_skip, "");
900 setEnabled(class_->choice_doc_skip, !indent);
901 setEnabled(class_->input_doc_skip, length_input);
902 setEnabled(class_->choice_doc_skip_units, length_input);
904 bool const two_sides = params.sides == LyXTextClass::TwoSides;
905 fl_set_button(class_->radio_doc_sides_one, !two_sides);
906 fl_set_button(class_->radio_doc_sides_two, two_sides);
908 bool const two_columns = params.columns == 2;
909 fl_set_button(class_->radio_doc_columns_one, !two_columns);
910 fl_set_button(class_->radio_doc_columns_two, two_columns);
912 fl_set_input(class_->input_doc_extra, params.options.c_str());
914 switch (params.spacing.getSpace()) {
918 case Spacing::Double: // \doublespacing
921 case Spacing::Onehalf: // \onehalfspacing
924 case Spacing::Single: // \singlespacing
925 case Spacing::Default: // nothing bad should happen with this
930 fl_set_choice(class_->choice_doc_spacing, pos);
932 bool const spacing_input = pos == 4;
933 setEnabled(class_->input_doc_spacing, spacing_input);
934 string const input = spacing_input ? tostr(params.spacing.getValue()) : string();
935 fl_set_input(class_->input_doc_spacing, input.c_str());
939 void FormDocument::language_update(BufferParams const & params)
941 if (!language_.get())
944 int const pos = int(findPos(lang_, params.language->lang()));
945 combo_language->select(pos+1);
947 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
948 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
949 fl_set_button(language_->radio_single, 0);
950 fl_set_button(language_->radio_double, 0);
951 if (params.quotes_times == InsetQuotes::SingleQ)
952 fl_set_button(language_->radio_single, 1);
954 fl_set_button(language_->radio_double, 1);
958 void FormDocument::options_update(BufferParams const & params)
963 fl_set_choice_text(options_->choice_postscript_driver,
964 params.graphicsDriver.c_str());
965 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
966 fl_set_button(options_->check_use_natbib, params.use_natbib);
967 fl_set_choice(options_->choice_citation_format,
968 int(params.use_numerical_citations)+1);
969 setEnabled(options_->choice_citation_format, params.use_natbib);
970 fl_set_counter_value(options_->counter_secnumdepth, params.secnumdepth);
971 fl_set_counter_value(options_->counter_tocdepth, params.tocdepth);
972 if (!params.float_placement.empty())
973 fl_set_input(options_->input_float_placement,
974 params.float_placement.c_str());
976 fl_set_input(options_->input_float_placement, "");
980 void FormDocument::paper_update(BufferParams const & params)
985 fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
986 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
987 fl_set_button(paper_->check_use_geometry, params.use_geometry);
989 int const paperchoice = fl_get_choice(paper_->choice_papersize);
990 bool const useCustom = paperchoice == 2;
991 bool const useGeom = fl_get_button(paper_->check_use_geometry);
993 fl_set_button(paper_->radio_portrait, 0);
994 setEnabled(paper_->radio_portrait, !useCustom);
995 fl_set_button(paper_->radio_landscape, 0);
996 setEnabled(paper_->radio_landscape, !useCustom);
998 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
999 fl_set_button(paper_->radio_landscape, 1);
1001 fl_set_button(paper_->radio_portrait, 1);
1002 setEnabled(paper_->choice_paperpackage,
1003 //either default papersize (preferences)
1004 //or document papersize has to be A4
1006 || paperchoice == 1 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER)
1007 && fl_get_button(paper_->radio_portrait));
1009 // Default unit choice is cm if metric, inches if US paper.
1010 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
1011 || paperchoice == 2 || paperchoice > 5;
1012 string const default_unit = metric ? "cm" : "in";
1013 updateWidgetsFromLengthString(paper_->input_custom_width,
1014 paper_->choice_custom_width_units,
1015 params.paperwidth, default_unit);
1016 setEnabled(paper_->input_custom_width, useCustom);
1017 setEnabled(paper_->choice_custom_width_units, useCustom);
1019 updateWidgetsFromLengthString(paper_->input_custom_height,
1020 paper_->choice_custom_height_units,
1021 params.paperheight, default_unit);
1022 setEnabled(paper_->input_custom_height, useCustom);
1023 setEnabled(paper_->choice_custom_height_units, useCustom);
1025 updateWidgetsFromLengthString(paper_->input_inner_margin,
1026 paper_->choice_inner_margin_units,
1027 params.leftmargin, default_unit);
1028 setEnabled(paper_->input_inner_margin, useGeom);
1029 setEnabled(paper_->choice_inner_margin_units, useGeom);
1031 updateWidgetsFromLengthString(paper_->input_top_margin,
1032 paper_->choice_top_margin_units,
1033 params.topmargin, default_unit);
1034 setEnabled(paper_->input_top_margin, useGeom);
1035 setEnabled(paper_->choice_top_margin_units, useGeom);
1037 updateWidgetsFromLengthString(paper_->input_outer_margin,
1038 paper_->choice_outer_margin_units,
1039 params.rightmargin, default_unit);
1040 setEnabled(paper_->input_outer_margin, useGeom);
1041 setEnabled(paper_->choice_outer_margin_units, useGeom);
1043 updateWidgetsFromLengthString(paper_->input_bottom_margin,
1044 paper_->choice_bottom_margin_units,
1045 params.bottommargin, default_unit);
1046 setEnabled(paper_->input_bottom_margin, useGeom);
1047 setEnabled(paper_->choice_bottom_margin_units, useGeom);
1049 updateWidgetsFromLengthString(paper_->input_head_height,
1050 paper_->choice_head_height_units,
1051 params.headheight, default_unit);
1052 setEnabled(paper_->input_head_height, useGeom);
1053 setEnabled(paper_->choice_head_height_units, useGeom);
1055 updateWidgetsFromLengthString(paper_->input_head_sep,
1056 paper_->choice_head_sep_units,
1057 params.headsep, default_unit);
1058 setEnabled(paper_->input_head_sep, useGeom);
1059 setEnabled(paper_->choice_head_sep_units, useGeom);
1061 updateWidgetsFromLengthString(paper_->input_foot_skip,
1062 paper_->choice_foot_skip_units,
1063 params.footskip, default_unit);
1064 setEnabled(paper_->input_foot_skip, useGeom);
1065 setEnabled(paper_->choice_foot_skip_units, useGeom);
1067 fl_set_focus_object(paper_->form, paper_->choice_papersize);
1071 void FormDocument::bullets_update(BufferParams const & params)
1073 if (!bullets_.get() ||
1075 (XpmVersion==4 && XpmRevision<7)))
1078 bool const isLinuxDoc =
1079 controller().docType() == ControlDocument::LINUXDOC;
1080 setEnabled(fbullet, !isLinuxDoc);
1082 if (isLinuxDoc) return;
1084 fl_set_button(bullets_->radio_bullet_depth_1, 1);
1085 fl_set_input(bullets_->input_bullet_latex,
1086 params.user_defined_bullets[0].getText().c_str());
1087 fl_set_choice(bullets_->choice_bullet_size,
1088 params.user_defined_bullets[0].getSize() + 2);
1092 void FormDocument::checkReadOnly()
1094 if (bc().readOnly(controller().bufferIsReadonly())) {
1095 combo_doc_class->deactivate();
1096 combo_language->deactivate();
1097 postWarning(_("Document is read-only."
1098 " No changes to layout permitted."));
1100 combo_doc_class->activate();
1101 combo_language->activate();
1107 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/)
1109 BufferParams & param = controller().params();
1111 // convert from 1-6 range to -1-4
1112 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1113 fl_set_input(bullets_->input_bullet_latex,
1114 param.temp_bullets[current_bullet_depth].getText().c_str());
1118 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1120 BufferParams & param = controller().params();
1122 param.temp_bullets[current_bullet_depth].
1123 setText(getString(bullets_->input_bullet_latex));
1127 void FormDocument::BulletDepth(FL_OBJECT * ob)
1129 /* Should I do the following: */
1130 /* 1. change to the panel that the current bullet belongs in */
1131 /* 2. show that bullet as selected */
1132 /* 3. change the size setting to the size of the bullet in Q.*/
1133 /* 4. display the latex equivalent in the latex box */
1135 /* I'm inclined to just go with 3 and 4 at the moment and */
1136 /* maybe try to support the others later */
1137 BufferParams & param = controller().params();
1140 if (ob == bullets_->radio_bullet_depth_1)
1142 else if (ob == bullets_->radio_bullet_depth_2)
1144 else if (ob == bullets_->radio_bullet_depth_3)
1146 else if (ob == bullets_->radio_bullet_depth_4)
1149 switch (fl_get_button_numb(ob)) {
1151 // right mouse button resets to default
1152 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1154 current_bullet_depth = data;
1155 fl_set_input(bullets_->input_bullet_latex,
1156 param.temp_bullets[data].getText().c_str());
1157 fl_set_choice(bullets_->choice_bullet_size,
1158 param.temp_bullets[data].getSize() + 2);
1163 void FormDocument::BulletPanel(FL_OBJECT * ob)
1165 /* Here we have to change the background pixmap to that selected */
1166 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1169 if (ob == bullets_->radio_bullet_panel_standard)
1171 else if (ob == bullets_->radio_bullet_panel_maths)
1173 else if (ob == bullets_->radio_bullet_panel_ding2)
1175 else if (ob == bullets_->radio_bullet_panel_ding3)
1177 else if (ob == bullets_->radio_bullet_panel_ding4)
1179 else if (ob == bullets_->radio_bullet_panel_ding1)
1182 if (data != current_bullet_panel) {
1183 fl_freeze_form(bullets_->form);
1184 current_bullet_panel = data;
1186 /* free the current pixmap */
1187 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1189 if (ob == bullets_->radio_bullet_panel_standard) {
1190 new_panel = "standard";
1191 } else if (ob == bullets_->radio_bullet_panel_maths ) {
1192 new_panel = "amssymb";
1193 } else if (ob == bullets_->radio_bullet_panel_ding2) {
1194 new_panel = "psnfss1";
1195 } else if (ob == bullets_->radio_bullet_panel_ding3) {
1196 new_panel = "psnfss2";
1197 } else if (ob == bullets_->radio_bullet_panel_ding4) {
1198 new_panel = "psnfss3";
1199 } else if (ob == bullets_->radio_bullet_panel_ding1) {
1200 new_panel = "psnfss4";
1202 /* something very wrong happened */
1203 // play it safe for now but should be an exception
1204 current_bullet_panel = 0; // standard panel
1205 new_panel = "standard";
1207 new_panel += ".xpm";
1208 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1209 LibFileSearch("images", new_panel).c_str());
1210 fl_redraw_object(bullets_->bmtable_bullet_panel);
1211 fl_unfreeze_form(bullets_->form);
1216 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/)
1218 /* handle the user input by setting the current bullet depth's pixmap */
1219 /* to that extracted from the current chosen position of the BMTable */
1220 /* Don't forget to free the button's old pixmap first. */
1222 BufferParams & param = controller().params();
1223 int bmtable_button = fl_get_bmtable(ob);
1225 /* try to keep the button held down till another is pushed */
1226 /* fl_set_bmtable(ob, 1, bmtable_button); */
1227 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1228 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1229 fl_set_input(bullets_->input_bullet_latex,
1230 param.temp_bullets[current_bullet_depth].getText().c_str());
1234 void FormDocument::CheckChoiceClass()
1236 BufferParams & params = controller().params();
1238 lyx::textclass_type const tc = combo_doc_class->get() - 1;
1240 if (controller().loadTextclass(tc)) {
1241 params.textclass = tc;
1243 if (lyxrc.auto_reset_options) {
1244 params.useClassDefaults();
1245 UpdateLayoutDocument(params);
1247 // update the params which are needed in any case
1248 // (fontsizes, pagestyle)
1249 UpdateClassParams(params);
1253 int const revert = int(params.textclass);
1254 combo_doc_class->select(revert + 1);
1259 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1265 class_update(params);
1266 paper_update(params);
1267 language_update(params);
1268 options_update(params);
1269 bullets_update(params);