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"
28 //#include "BufferView.h"
29 #include "CutAndPaste.h"
32 //#include "lyx_main.h" // for user_lyxdir
34 #include "lyxtextclasslist.h"
35 #include "tex-strings.h"
37 #include "controllers/frnt_lang.h"
38 #include "controllers/helper_funcs.h"
40 #include "support/lstrings.h" // contains_functor, getStringFromVector
41 #include "support/filetools.h" // LibFileSearch
43 #include XPM_H_LOCATION
44 #include FORMS_H_LOCATION
46 #include <boost/bind.hpp>
54 typedef FormCB<ControlDocument, FormDB<FD_document> > base_class;
56 FormDocument::FormDocument()
57 : base_class(_("Document Layout"), false),
58 ActCell(0), Confirmed(0),
59 current_bullet_panel(0), current_bullet_depth(0), fbullet(0)
63 void FormDocument::redraw()
65 if (form() && form()->visible)
66 fl_redraw_form(form());
70 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder);
71 if (outer_form && outer_form->visible)
72 fl_redraw_form(outer_form);
76 void FormDocument::build()
79 dialog_.reset(build_document(this));
81 // Allow the base class to control messages
82 setMessageWidget(dialog_->text_warning);
84 // Manage the restore, ok, apply, restore and cancel/close buttons
85 bcview().setOK(dialog_->button_ok);
86 bcview().setApply(dialog_->button_apply);
87 bcview().setCancel(dialog_->button_close);
88 bcview().setRestore(dialog_->button_restore);
90 // the document class form
91 class_.reset(build_document_class(this));
93 // disable for read-only documents
94 bcview().addReadOnly(class_->radio_doc_indent);
95 bcview().addReadOnly(class_->radio_doc_skip);
96 bcview().addReadOnly(class_->choice_doc_pagestyle);
97 bcview().addReadOnly(class_->choice_doc_fonts);
98 bcview().addReadOnly(class_->choice_doc_fontsize);
99 bcview().addReadOnly(class_->radio_doc_sides_one);
100 bcview().addReadOnly(class_->radio_doc_sides_two);
101 bcview().addReadOnly(class_->radio_doc_columns_one);
102 bcview().addReadOnly(class_->radio_doc_columns_two);
103 bcview().addReadOnly(class_->input_doc_extra);
104 bcview().addReadOnly(class_->input_doc_skip);
105 bcview().addReadOnly(class_->choice_doc_skip);
106 bcview().addReadOnly(class_->choice_doc_spacing);
107 bcview().addReadOnly(class_->input_doc_spacing);
109 // check validity of "length + unit" input
110 addCheckedGlueLength(bcview(), class_->input_doc_skip,
111 class_->choice_doc_skip);
113 // trigger an input event for cut&paste with middle mouse button.
114 setPrehandler(class_->input_doc_extra);
115 setPrehandler(class_->input_doc_skip);
116 setPrehandler(class_->input_doc_spacing);
118 fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
119 fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
120 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
124 // the class list is a combo-box and has to be inserted manually
125 obj = class_->choice_doc_class;
126 fl_deactivate_object(obj);
127 fl_addto_form(class_->form);
128 combo_doc_class.reset(new Combox(FL_COMBOX_DROPLIST));
129 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400);
130 combo_doc_class->shortcut("#C",1);
131 combo_doc_class->setcallback(ComboInputCB, this);
133 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
134 cit != textclasslist.end(); ++cit) {
135 combo_doc_class->addto(cit->description());
138 fl_addto_choice(class_->choice_doc_spacing,
139 _(" Single | OneHalf | Double | Custom "));
140 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
141 for (int n = 0; tex_fonts[n][0]; ++n) {
142 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
145 // Create the contents of the unit choices; don't include the
147 vector<string> units_vec = getLatexUnits();
148 vector<string>::iterator ret =
149 std::remove_if(units_vec.begin(),
151 bind2nd(contains_functor(), "%"));
152 units_vec.erase(ret, units_vec.end());
154 string const units = getStringFromVector(units_vec, "|");
156 fl_addto_choice(class_->choice_doc_pagestyle,
157 "default|empty|plain|headings|fancy");
158 fl_addto_choice(class_->choice_doc_skip,
159 _(" SmallSkip | MedSkip | BigSkip | Length "));
160 fl_addto_choice(class_->choice_doc_skip_units, units.c_str());
162 // Set input filters on doc spacing to make it accept only
164 fl_set_input_filter(class_->input_doc_spacing,
165 fl_unsigned_float_filter);
167 // disable for read-only documents
168 bcview().addReadOnly(dialog_->button_save_defaults);
169 bcview().addReadOnly(dialog_->button_reset_defaults);
171 // the document paper form
172 paper_.reset(build_document_paper(this));
174 // disable for read-only documents
175 bcview().addReadOnly(paper_->choice_paperpackage);
176 bcview().addReadOnly(paper_->radio_portrait);
177 bcview().addReadOnly(paper_->radio_landscape);
178 bcview().addReadOnly(paper_->choice_papersize);
179 bcview().addReadOnly(paper_->check_use_geometry);
180 bcview().addReadOnly(paper_->input_custom_width);
181 bcview().addReadOnly(paper_->input_custom_height);
182 bcview().addReadOnly(paper_->input_top_margin);
183 bcview().addReadOnly(paper_->input_bottom_margin);
184 bcview().addReadOnly(paper_->input_inner_margin);
185 bcview().addReadOnly(paper_->input_outer_margin);
186 bcview().addReadOnly(paper_->input_head_height);
187 bcview().addReadOnly(paper_->input_head_sep);
188 bcview().addReadOnly(paper_->input_foot_skip);
190 // check validity of "length + unit" input
191 addCheckedGlueLength(bcview(), paper_->input_custom_width);
192 addCheckedGlueLength(bcview(), paper_->input_custom_height);
193 addCheckedGlueLength(bcview(), paper_->input_top_margin);
194 addCheckedGlueLength(bcview(), paper_->input_bottom_margin);
195 addCheckedGlueLength(bcview(), paper_->input_inner_margin);
196 addCheckedGlueLength(bcview(), paper_->input_outer_margin);
197 addCheckedGlueLength(bcview(), paper_->input_head_height);
198 addCheckedGlueLength(bcview(), paper_->input_head_sep);
199 addCheckedGlueLength(bcview(), paper_->input_foot_skip);
201 // trigger an input event for cut&paste with middle mouse button.
202 setPrehandler(paper_->input_custom_width);
203 setPrehandler(paper_->input_custom_height);
204 setPrehandler(paper_->input_top_margin);
205 setPrehandler(paper_->input_bottom_margin);
206 setPrehandler(paper_->input_inner_margin);
207 setPrehandler(paper_->input_outer_margin);
208 setPrehandler(paper_->input_head_height);
209 setPrehandler(paper_->input_head_sep);
210 setPrehandler(paper_->input_foot_skip);
212 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
213 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
214 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
215 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
216 fl_set_input_return(paper_->input_inner_margin, FL_RETURN_CHANGED);
217 fl_set_input_return(paper_->input_outer_margin, FL_RETURN_CHANGED);
218 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
219 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
220 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
222 fl_addto_choice(paper_->choice_papersize,
223 _(" Default | Custom | US letter | US legal "
224 "| US executive | A3 | A4 | A5 | B3 | B4 | B5 "));
225 fl_addto_choice(paper_->choice_paperpackage,
228 "| Very small Margins "
229 "| Very wide Margins "));
231 fl_addto_choice(paper_->choice_custom_width_units, units.c_str());
232 fl_addto_choice(paper_->choice_custom_height_units, units.c_str());
233 fl_addto_choice(paper_->choice_top_margin_units, units.c_str());
234 fl_addto_choice(paper_->choice_bottom_margin_units, units.c_str());
235 fl_addto_choice(paper_->choice_inner_margin_units, units.c_str());
236 fl_addto_choice(paper_->choice_outer_margin_units, units.c_str());
237 fl_addto_choice(paper_->choice_head_height_units, units.c_str());
238 fl_addto_choice(paper_->choice_head_sep_units, units.c_str());
239 fl_addto_choice(paper_->choice_foot_skip_units, units.c_str());
241 // the document language form
242 language_.reset(build_document_language(this));
244 // disable for read-only documents
245 bcview().addReadOnly(language_->choice_inputenc);
246 bcview().addReadOnly(language_->choice_quotes_language);
247 bcview().addReadOnly(language_->radio_single);
248 bcview().addReadOnly(language_->radio_double);
250 fl_addto_choice(language_->choice_inputenc,
251 "default|auto|latin1|latin2|latin3|latin4|latin5|latin9"
252 "|koi8-r|koi8-u|cp866|cp1251|iso88595|pt154");
254 vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
255 // Store the identifiers for later
256 lang_ = getSecond(langs);
258 // The language is a combo-box and has to be inserted manually
259 obj = language_->choice_language;
260 fl_deactivate_object(obj);
261 fl_addto_form(language_->form);
262 combo_language.reset(new Combox(FL_COMBOX_DROPLIST));
263 combo_language->add(obj->x, obj->y, obj->w, obj->h, 400);
264 combo_language->shortcut("#L",1);
265 combo_language->setcallback(ComboInputCB, this);
268 vector<frnt::LanguagePair>::const_iterator lit = langs.begin();
269 vector<frnt::LanguagePair>::const_iterator lend = langs.end();
270 for (; lit != lend; ++lit) {
271 combo_language->addto(lit->first);
273 combo_language->select(1);
275 fl_addto_choice(language_->choice_quotes_language,
276 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
277 " «text» | »text« "));
279 // the document options form
280 options_.reset(build_document_options(this));
282 // disable for read-only documents
283 bcview().addReadOnly(options_->counter_secnumdepth);
284 bcview().addReadOnly(options_->counter_tocdepth);
285 bcview().addReadOnly(options_->choice_ams_math);
286 bcview().addReadOnly(options_->check_use_natbib);
287 bcview().addReadOnly(options_->choice_citation_format);
288 bcview().addReadOnly(options_->input_float_placement);
289 bcview().addReadOnly(options_->choice_postscript_driver);
291 // trigger an input event for cut&paste with middle mouse button.
292 setPrehandler(options_->input_float_placement);
294 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
296 fl_addto_choice(options_->choice_ams_math,
297 _("Never | Automatically | Yes "));
299 for (int n = 0; tex_graphics[n][0]; ++n) {
300 fl_addto_choice(options_->choice_postscript_driver,
303 fl_addto_choice(options_->choice_citation_format,
304 _(" Author-year | Numerical "));
306 // the document bullets form
307 bullets_.reset(build_document_bullet(this));
309 // disable for read-only documents
310 bcview().addReadOnly(bullets_->radio_bullet_depth_1);
311 bcview().addReadOnly(bullets_->radio_bullet_depth_2);
312 bcview().addReadOnly(bullets_->radio_bullet_depth_3);
313 bcview().addReadOnly(bullets_->radio_bullet_depth_4);
314 bcview().addReadOnly(bullets_->radio_bullet_panel_standard);
315 bcview().addReadOnly(bullets_->radio_bullet_panel_maths);
316 bcview().addReadOnly(bullets_->radio_bullet_panel_ding1);
317 bcview().addReadOnly(bullets_->radio_bullet_panel_ding2);
318 bcview().addReadOnly(bullets_->radio_bullet_panel_ding3);
319 bcview().addReadOnly(bullets_->radio_bullet_panel_ding4);
320 bcview().addReadOnly(bullets_->bmtable_bullet_panel);
321 bcview().addReadOnly(bullets_->choice_bullet_size);
322 bcview().addReadOnly(bullets_->input_bullet_latex);
324 // trigger an input event for cut&paste with middle mouse button.
325 setPrehandler(bullets_->input_bullet_latex);
327 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
329 fl_addto_choice(bullets_->choice_bullet_size,
330 _(" Default | Tiny | Smallest | Smaller | Small |"
331 " Normal | Large | Larger | Largest | Huge | Huger "));
332 fl_set_choice(bullets_->choice_bullet_size, 1);
334 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
336 string const bmtablefile = LibFileSearch("images", "standard", "xpm");
337 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
338 bmtablefile.c_str());
340 fl_addto_tabfolder(dialog_->tabfolder,_("Document"),
342 fl_addto_tabfolder(dialog_->tabfolder,_("Paper"),
344 fl_addto_tabfolder(dialog_->tabfolder,_("Language"),
346 fl_addto_tabfolder(dialog_->tabfolder,_("Extra"),
348 fbullet = fl_addto_tabfolder(dialog_->tabfolder,_("Bullets"),
351 // work-around xforms bug re update of folder->x, folder->y coords.
352 setPrehandler(dialog_->tabfolder);
354 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
355 lyxerr << _("Your version of libXpm is older than 4.7.\n"
356 "The `bullet' tab of the document dialog "
357 "has been disabled") << '\n';
358 fl_deactivate_object(fbullet);
359 fl_set_object_lcol(fbullet, FL_INACTIVE);
364 void FormDocument::apply()
366 BufferParams & params = controller().params();
370 language_apply(params);
371 options_apply(params);
372 bullets_apply(params);
376 void FormDocument::update()
383 BufferParams const & params = controller().params();
385 class_update(params);
386 paper_update(params);
387 language_update(params);
388 options_update(params);
389 bullets_update(params);
393 ButtonPolicy::SMInput FormDocument::input(FL_OBJECT * ob, long)
395 if (ob == bullets_->choice_bullet_size) {
396 ChoiceBulletSize(ob, 0);
398 } else if (ob == bullets_->input_bullet_latex) {
399 InputBulletLaTeX(ob, 0);
401 } else if (ob == bullets_->radio_bullet_depth_1 ||
402 ob == bullets_->radio_bullet_depth_2 ||
403 ob == bullets_->radio_bullet_depth_3 ||
404 ob == bullets_->radio_bullet_depth_4) {
407 } else if (ob == bullets_->radio_bullet_panel_standard ||
408 ob == bullets_->radio_bullet_panel_maths ||
409 ob == bullets_->radio_bullet_panel_ding1 ||
410 ob == bullets_->radio_bullet_panel_ding2 ||
411 ob == bullets_->radio_bullet_panel_ding3 ||
412 ob == bullets_->radio_bullet_panel_ding4) {
415 } else if (ob == bullets_->bmtable_bullet_panel) {
416 BulletBMTable(ob, 0);
418 } else if (ob == class_->choice_doc_spacing) {
419 setEnabled(class_->input_doc_spacing,
420 fl_get_choice(class_->choice_doc_spacing) == 4);
422 } else if (ob == class_->radio_doc_skip ||
423 ob == class_->radio_doc_indent ||
424 ob == class_->choice_doc_skip) {
425 bool const skip_used = fl_get_button(class_->radio_doc_skip);
426 setEnabled(class_->choice_doc_skip, skip_used);
428 bool const length_input =
429 fl_get_choice(class_->choice_doc_skip) == 4;
430 setEnabled(class_->input_doc_skip,
431 skip_used && length_input);
432 setEnabled(class_->choice_doc_skip_units,
433 skip_used && length_input);
435 // Default unit choice is cm if metric, inches if US paper.
436 // If papersize is default, check the lyxrc-settings
437 int const paperchoice = fl_get_choice(paper_->choice_papersize);
438 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
439 || paperchoice == 2 || paperchoice > 5;
440 string const default_unit = metric ? "cm" : "in";
441 if (getString(class_->input_doc_skip).empty())
442 fl_set_choice_text(class_->choice_doc_skip_units,
443 default_unit.c_str());
445 } else if (ob == options_->check_use_natbib) {
446 setEnabled(options_->choice_citation_format,
447 fl_get_button(options_->check_use_natbib));
449 } else if (ob == dialog_->button_save_defaults) {
451 controller().saveAsDefault();
453 } else if (ob == dialog_->button_reset_defaults) {
454 BufferParams & params = controller().params();
455 params.textclass = combo_doc_class->get() - 1;
456 params.useClassDefaults();
457 UpdateLayoutDocument(params);
459 } else if (ob == paper_->radio_landscape) {
460 fl_set_choice(paper_->choice_paperpackage,
461 BufferParams::PACKAGE_NONE + 1);
463 } else if (ob == paper_->choice_papersize) {
464 int const paperchoice = fl_get_choice(paper_->choice_papersize);
465 bool const defsize = paperchoice == 1;
466 bool const custom = paperchoice == 2;
467 bool const a3size = paperchoice == 6;
468 bool const b3size = paperchoice == 9;
469 bool const b4size = paperchoice == 10;
472 fl_set_button(paper_->radio_portrait, 1);
474 bool const use_geom = (custom || a3size || b3size || b4size);
476 fl_set_button(paper_->check_use_geometry, int(use_geom));
478 setEnabled(paper_->input_top_margin, use_geom);
479 setEnabled(paper_->input_bottom_margin, use_geom);
480 setEnabled(paper_->input_inner_margin, use_geom);
481 setEnabled(paper_->input_outer_margin, use_geom);
482 setEnabled(paper_->input_head_height, use_geom);
483 setEnabled(paper_->input_head_sep, use_geom);
484 setEnabled(paper_->input_foot_skip, use_geom);
485 setEnabled(paper_->choice_top_margin_units, use_geom);
486 setEnabled(paper_->choice_bottom_margin_units, use_geom);
487 setEnabled(paper_->choice_inner_margin_units, use_geom);
488 setEnabled(paper_->choice_outer_margin_units, use_geom);
489 setEnabled(paper_->choice_head_height_units, use_geom);
490 setEnabled(paper_->choice_head_sep_units, use_geom);
491 setEnabled(paper_->choice_foot_skip_units, use_geom);
492 setEnabled(paper_->choice_custom_width_units, use_geom);
493 setEnabled(paper_->choice_custom_height_units, use_geom);
495 setEnabled(paper_->input_custom_width, custom);
496 setEnabled(paper_->input_custom_height, custom);
497 setEnabled(paper_->choice_custom_width_units, custom);
498 setEnabled(paper_->choice_custom_height_units, custom);
499 setEnabled(paper_->radio_portrait, !custom);
500 setEnabled(paper_->radio_landscape, !custom);
502 // Default unit choice is cm if metric, inches if US paper.
503 // If papersize is default, use the lyxrc-settings
504 bool const metric = (defsize && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
505 || paperchoice == 2 || paperchoice > 5;
506 string const default_unit = metric ? "cm" : "in";
507 if (getString(paper_->input_custom_width).empty())
508 fl_set_choice_text(paper_->choice_custom_width_units,
509 default_unit.c_str());
510 if (getString(paper_->input_custom_height).empty())
511 fl_set_choice_text(paper_->choice_custom_height_units,
512 default_unit.c_str());
513 if (getString(paper_->input_top_margin).empty())
514 fl_set_choice_text(paper_->choice_top_margin_units,
515 default_unit.c_str());
516 if (getString(paper_->input_bottom_margin).empty())
517 fl_set_choice_text(paper_->choice_bottom_margin_units,
518 default_unit.c_str());
519 if (getString(paper_->input_inner_margin).empty())
520 fl_set_choice_text(paper_->choice_inner_margin_units,
521 default_unit.c_str());
522 if (getString(paper_->input_outer_margin).empty())
523 fl_set_choice_text(paper_->choice_outer_margin_units,
524 default_unit.c_str());
525 if (getString(paper_->input_head_height).empty())
526 fl_set_choice_text(paper_->choice_head_height_units,
527 default_unit.c_str());
528 if (getString(paper_->input_head_sep).empty())
529 fl_set_choice_text(paper_->choice_head_sep_units,
530 default_unit.c_str());
531 if (getString(paper_->input_foot_skip).empty())
532 fl_set_choice_text(paper_->choice_foot_skip_units,
533 default_unit.c_str());
535 } else if (ob == paper_->choice_paperpackage &&
536 fl_get_choice(paper_->choice_paperpackage) != 1) {
538 fl_set_button(paper_->check_use_geometry, 0);
539 setEnabled(paper_->input_top_margin, false);
540 setEnabled(paper_->input_bottom_margin, false);
541 setEnabled(paper_->input_inner_margin, false);
542 setEnabled(paper_->input_outer_margin, false);
543 setEnabled(paper_->input_head_height, false);
544 setEnabled(paper_->input_head_sep, false);
545 setEnabled(paper_->input_foot_skip, false);
546 setEnabled(paper_->choice_top_margin_units, false);
547 setEnabled(paper_->choice_bottom_margin_units, false);
548 setEnabled(paper_->choice_inner_margin_units, false);
549 setEnabled(paper_->choice_outer_margin_units, false);
550 setEnabled(paper_->choice_head_height_units, false);
551 setEnabled(paper_->choice_head_sep_units, false);
552 setEnabled(paper_->choice_foot_skip_units, false);
554 } else if (ob == paper_->check_use_geometry) {
555 // don't allow switching geometry off in custom papersize
556 // mode nor in A3, B3, and B4
557 int const choice = fl_get_choice(paper_->choice_papersize);
558 if (choice == 2 || choice == 6 || choice == 9 || choice == 10)
559 fl_set_button(paper_->check_use_geometry, 1);
561 fl_set_choice(paper_->choice_paperpackage,
562 BufferParams::PACKAGE_NONE + 1);
564 bool const use_geom = fl_get_button(paper_->check_use_geometry);
565 setEnabled(paper_->input_top_margin, use_geom);
566 setEnabled(paper_->input_bottom_margin, use_geom);
567 setEnabled(paper_->input_inner_margin, use_geom);
568 setEnabled(paper_->input_outer_margin, use_geom);
569 setEnabled(paper_->input_head_height, use_geom);
570 setEnabled(paper_->input_head_sep, use_geom);
571 setEnabled(paper_->input_foot_skip, use_geom);
572 setEnabled(paper_->choice_top_margin_units, use_geom);
573 setEnabled(paper_->choice_bottom_margin_units, use_geom);
574 setEnabled(paper_->choice_inner_margin_units, use_geom);
575 setEnabled(paper_->choice_outer_margin_units, use_geom);
576 setEnabled(paper_->choice_head_height_units, use_geom);
577 setEnabled(paper_->choice_head_sep_units, use_geom);
578 setEnabled(paper_->choice_foot_skip_units, use_geom);
581 if (ob == paper_->choice_papersize || ob == paper_->radio_portrait
582 || ob == paper_->radio_landscape) {
583 // either default papersize (preferences) or document
584 // papersize has to be A4
585 bool const enable = ( fl_get_choice(paper_->choice_papersize) == 1
586 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER )
587 || fl_get_choice(paper_->choice_papersize) == 7;
589 fl_set_choice(paper_->choice_paperpackage,
590 BufferParams::PACKAGE_NONE + 1);
591 setEnabled(paper_->choice_paperpackage,
592 enable && fl_get_button(paper_->radio_portrait));
595 return ButtonPolicy::SMI_VALID;
599 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
601 FormDocument * pre = static_cast<FormDocument*>(v);
602 if (combox == pre->combo_doc_class.get())
603 pre->CheckChoiceClass();
608 bool FormDocument::class_apply(BufferParams ¶ms)
612 // If default skip is a "Length" but there's no text in the
613 // input field, reset the kind to "MedSkip", which is the default.
614 if (fl_get_choice(class_->choice_doc_skip) == 4 &&
615 getString(class_->input_doc_skip).empty()) {
616 fl_set_choice(class_->choice_doc_skip, 2);
618 params.fonts = getString(class_->choice_doc_fonts);
619 params.fontsize = getString(class_->choice_doc_fontsize);
620 params.pagestyle = getString(class_->choice_doc_pagestyle);
622 params.textclass = combo_doc_class->get() - 1;
624 BufferParams::PARSEP tmpsep = params.paragraph_separation;
625 if (fl_get_button(class_->radio_doc_indent))
626 params.paragraph_separation = BufferParams::PARSEP_INDENT;
628 params.paragraph_separation = BufferParams::PARSEP_SKIP;
629 if (tmpsep != params.paragraph_separation)
632 VSpace tmpdefskip = params.getDefSkip();
633 switch (fl_get_choice(class_->choice_doc_skip)) {
635 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
638 params.setDefSkip(VSpace(VSpace::MEDSKIP));
641 params.setDefSkip(VSpace(VSpace::BIGSKIP));
645 string const length =
646 getLengthFromWidgets(class_->input_doc_skip,
647 class_->choice_doc_skip_units);
649 params.setDefSkip(VSpace(LyXGlueLength(length)));
653 // DocumentDefskipCB assures that this never happens
654 params.setDefSkip(VSpace(VSpace::MEDSKIP));
657 if (!(tmpdefskip == params.getDefSkip()))
660 if (fl_get_button(class_->radio_doc_columns_two))
664 if (fl_get_button(class_->radio_doc_sides_two))
665 params.sides = LyXTextClass::TwoSides;
667 params.sides = LyXTextClass::OneSide;
669 Spacing tmpSpacing = params.spacing;
670 switch (fl_get_choice(class_->choice_doc_spacing)) {
672 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
673 params.spacing.set(Spacing::Single);
676 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
677 params.spacing.set(Spacing::Onehalf);
680 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
681 params.spacing.set(Spacing::Double);
684 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
685 params.spacing.set(Spacing::Other,
686 getString(class_->input_doc_spacing));
689 if (tmpSpacing != params.spacing)
692 params.options = getString(class_->input_doc_extra);
698 void FormDocument::paper_apply(BufferParams & params)
700 params.papersize2 = char(fl_get_choice(paper_->choice_papersize) - 1);
702 params.paperpackage =
703 char(fl_get_choice(paper_->choice_paperpackage) - 1);
705 // set params.papersize from params.papersize2 and params.paperpackage
706 params.setPaperStuff();
708 params.use_geometry = fl_get_button(paper_->check_use_geometry);
710 if (fl_get_button(paper_->radio_landscape))
711 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
713 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
716 getLengthFromWidgets(paper_->input_custom_width,
717 paper_->choice_custom_width_units);
720 getLengthFromWidgets(paper_->input_custom_height,
721 paper_->choice_custom_height_units);
724 getLengthFromWidgets(paper_->input_inner_margin,
725 paper_->choice_inner_margin_units);
728 getLengthFromWidgets(paper_->input_top_margin,
729 paper_->choice_top_margin_units);
732 getLengthFromWidgets(paper_->input_outer_margin,
733 paper_->choice_outer_margin_units);
735 params.bottommargin =
736 getLengthFromWidgets(paper_->input_bottom_margin,
737 paper_->choice_bottom_margin_units);
740 getLengthFromWidgets(paper_->input_head_height,
741 paper_->choice_head_height_units);
744 getLengthFromWidgets(paper_->input_head_sep,
745 paper_->choice_head_sep_units);
748 getLengthFromWidgets(paper_->input_foot_skip,
749 paper_->choice_foot_skip_units);
753 bool FormDocument::language_apply(BufferParams & params)
755 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
758 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
760 lga = InsetQuotes::EnglishQ;
763 lga = InsetQuotes::SwedishQ;
766 lga = InsetQuotes::GermanQ;
769 lga = InsetQuotes::PolishQ;
772 lga = InsetQuotes::FrenchQ;
775 lga = InsetQuotes::DanishQ;
778 params.quotes_language = lga;
779 if (fl_get_button(language_->radio_single))
780 params.quotes_times = InsetQuotes::SingleQ;
782 params.quotes_times = InsetQuotes::DoubleQ;
784 int const pos = combo_language->get();
785 Language const * new_language = languages.getLanguage(lang_[pos-1]);
787 new_language = default_language;
789 params.language = new_language;
790 params.inputenc = getString(language_->choice_inputenc);
796 bool FormDocument::options_apply(BufferParams & params)
800 params.graphicsDriver = getString(options_->choice_postscript_driver);
801 params.use_amsmath = static_cast<BufferParams::AMS>(
802 fl_get_choice(options_->choice_ams_math) - 1);
803 params.use_natbib = fl_get_button(options_->check_use_natbib);
804 params.use_numerical_citations =
805 fl_get_choice(options_->choice_citation_format) - 1;
807 int tmpchar = int(fl_get_counter_value(options_->counter_secnumdepth));
808 if (params.secnumdepth != tmpchar)
810 params.secnumdepth = tmpchar;
812 params.tocdepth = int(fl_get_counter_value(options_->counter_tocdepth));
814 params.float_placement =
815 getString(options_->input_float_placement);
821 void FormDocument::bullets_apply(BufferParams & params)
823 /* update the bullet settings */
824 BufferParams & buf_params = controller().params();
826 // a little bit of loop unrolling
827 params.user_defined_bullets[0] = buf_params.temp_bullets[0];
828 params.user_defined_bullets[1] = buf_params.temp_bullets[1];
829 params.user_defined_bullets[2] = buf_params.temp_bullets[2];
830 params.user_defined_bullets[3] = buf_params.temp_bullets[3];
834 void FormDocument::UpdateClassParams(BufferParams const & params)
836 // These are the params that have to be updated on any class change
837 // (even if the class defaults are not used) (JSpitzm 2002-04-08)
839 LyXTextClass const & tclass = textclasslist[params.textclass];
841 combo_doc_class->select(tclass.description());
842 fl_clear_choice(class_->choice_doc_fontsize);
843 fl_addto_choice(class_->choice_doc_fontsize, "default");
844 fl_addto_choice(class_->choice_doc_fontsize,
845 tclass.opt_fontsize().c_str());
846 fl_set_choice_text(class_->choice_doc_fontsize,
847 params.fontsize.c_str());
848 fl_clear_choice(class_->choice_doc_pagestyle);
849 fl_addto_choice(class_->choice_doc_pagestyle, "default");
850 fl_addto_choice(class_->choice_doc_pagestyle,
851 tclass.opt_pagestyle().c_str());
852 fl_set_choice_text(class_->choice_doc_pagestyle,
853 params.pagestyle.c_str());
857 void FormDocument::class_update(BufferParams const & params)
862 UpdateClassParams(params);
864 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
866 bool const indent = params.paragraph_separation == BufferParams::PARSEP_INDENT;
867 fl_set_button(class_->radio_doc_indent, indent);
868 fl_set_button(class_->radio_doc_skip, !indent);
872 pos = 2; // VSpace::MEDSKIP is default
874 switch (params.getDefSkip().kind()) {
878 case VSpace::BIGSKIP:
881 case VSpace::SMALLSKIP:
884 case VSpace::MEDSKIP:
890 fl_set_choice (class_->choice_doc_skip, pos);
892 bool const length_input = pos == 4;
894 int const paperchoice = fl_get_choice(paper_->choice_papersize);
895 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
896 || paperchoice == 2 || paperchoice > 5;
897 string const default_unit = metric ? "cm" : "in";
898 string const length = params.getDefSkip().asLyXCommand();
899 updateWidgetsFromLengthString(class_->input_doc_skip,
900 class_->choice_doc_skip_units,
901 length, default_unit);
904 fl_set_input(class_->input_doc_skip, "");
906 setEnabled(class_->choice_doc_skip, !indent);
907 setEnabled(class_->input_doc_skip, length_input);
908 setEnabled(class_->choice_doc_skip_units, length_input);
910 bool const two_sides = params.sides == LyXTextClass::TwoSides;
911 fl_set_button(class_->radio_doc_sides_one, !two_sides);
912 fl_set_button(class_->radio_doc_sides_two, two_sides);
914 bool const two_columns = params.columns == 2;
915 fl_set_button(class_->radio_doc_columns_one, !two_columns);
916 fl_set_button(class_->radio_doc_columns_two, two_columns);
918 fl_set_input(class_->input_doc_extra, params.options.c_str());
920 switch (params.spacing.getSpace()) {
924 case Spacing::Double: // \doublespacing
927 case Spacing::Onehalf: // \onehalfspacing
930 case Spacing::Single: // \singlespacing
931 case Spacing::Default: // nothing bad should happen with this
936 fl_set_choice(class_->choice_doc_spacing, pos);
938 bool const spacing_input = pos == 4;
939 setEnabled(class_->input_doc_spacing, spacing_input);
940 string const input = spacing_input ? tostr(params.spacing.getValue()) : string();
941 fl_set_input(class_->input_doc_spacing, input.c_str());
945 void FormDocument::language_update(BufferParams const & params)
947 if (!language_.get())
950 int const pos = int(findPos(lang_, params.language->lang()));
951 combo_language->select(pos+1);
953 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
954 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
955 fl_set_button(language_->radio_single, 0);
956 fl_set_button(language_->radio_double, 0);
957 if (params.quotes_times == InsetQuotes::SingleQ)
958 fl_set_button(language_->radio_single, 1);
960 fl_set_button(language_->radio_double, 1);
964 void FormDocument::options_update(BufferParams const & params)
969 fl_set_choice_text(options_->choice_postscript_driver,
970 params.graphicsDriver.c_str());
971 fl_set_choice(options_->choice_ams_math, params.use_amsmath + 1);
972 fl_set_button(options_->check_use_natbib, params.use_natbib);
973 fl_set_choice(options_->choice_citation_format,
974 int(params.use_numerical_citations)+1);
975 setEnabled(options_->choice_citation_format, params.use_natbib);
976 fl_set_counter_value(options_->counter_secnumdepth, params.secnumdepth);
977 fl_set_counter_value(options_->counter_tocdepth, params.tocdepth);
978 if (!params.float_placement.empty())
979 fl_set_input(options_->input_float_placement,
980 params.float_placement.c_str());
982 fl_set_input(options_->input_float_placement, "");
986 void FormDocument::paper_update(BufferParams const & params)
991 fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
992 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
993 fl_set_button(paper_->check_use_geometry, params.use_geometry);
995 int const paperchoice = fl_get_choice(paper_->choice_papersize);
996 bool const useCustom = paperchoice == 2;
997 bool const useGeom = fl_get_button(paper_->check_use_geometry);
999 fl_set_button(paper_->radio_portrait, 0);
1000 setEnabled(paper_->radio_portrait, !useCustom);
1001 fl_set_button(paper_->radio_landscape, 0);
1002 setEnabled(paper_->radio_landscape, !useCustom);
1004 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1005 fl_set_button(paper_->radio_landscape, 1);
1007 fl_set_button(paper_->radio_portrait, 1);
1008 setEnabled(paper_->choice_paperpackage,
1009 //either default papersize (preferences)
1010 //or document papersize has to be A4
1012 || paperchoice == 1 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER)
1013 && fl_get_button(paper_->radio_portrait));
1015 // Default unit choice is cm if metric, inches if US paper.
1016 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
1017 || paperchoice == 2 || paperchoice > 5;
1018 string const default_unit = metric ? "cm" : "in";
1019 updateWidgetsFromLengthString(paper_->input_custom_width,
1020 paper_->choice_custom_width_units,
1021 params.paperwidth, default_unit);
1022 setEnabled(paper_->input_custom_width, useCustom);
1023 setEnabled(paper_->choice_custom_width_units, useCustom);
1025 updateWidgetsFromLengthString(paper_->input_custom_height,
1026 paper_->choice_custom_height_units,
1027 params.paperheight, default_unit);
1028 setEnabled(paper_->input_custom_height, useCustom);
1029 setEnabled(paper_->choice_custom_height_units, useCustom);
1031 updateWidgetsFromLengthString(paper_->input_inner_margin,
1032 paper_->choice_inner_margin_units,
1033 params.leftmargin, default_unit);
1034 setEnabled(paper_->input_inner_margin, useGeom);
1035 setEnabled(paper_->choice_inner_margin_units, useGeom);
1037 updateWidgetsFromLengthString(paper_->input_top_margin,
1038 paper_->choice_top_margin_units,
1039 params.topmargin, default_unit);
1040 setEnabled(paper_->input_top_margin, useGeom);
1041 setEnabled(paper_->choice_top_margin_units, useGeom);
1043 updateWidgetsFromLengthString(paper_->input_outer_margin,
1044 paper_->choice_outer_margin_units,
1045 params.rightmargin, default_unit);
1046 setEnabled(paper_->input_outer_margin, useGeom);
1047 setEnabled(paper_->choice_outer_margin_units, useGeom);
1049 updateWidgetsFromLengthString(paper_->input_bottom_margin,
1050 paper_->choice_bottom_margin_units,
1051 params.bottommargin, default_unit);
1052 setEnabled(paper_->input_bottom_margin, useGeom);
1053 setEnabled(paper_->choice_bottom_margin_units, useGeom);
1055 updateWidgetsFromLengthString(paper_->input_head_height,
1056 paper_->choice_head_height_units,
1057 params.headheight, default_unit);
1058 setEnabled(paper_->input_head_height, useGeom);
1059 setEnabled(paper_->choice_head_height_units, useGeom);
1061 updateWidgetsFromLengthString(paper_->input_head_sep,
1062 paper_->choice_head_sep_units,
1063 params.headsep, default_unit);
1064 setEnabled(paper_->input_head_sep, useGeom);
1065 setEnabled(paper_->choice_head_sep_units, useGeom);
1067 updateWidgetsFromLengthString(paper_->input_foot_skip,
1068 paper_->choice_foot_skip_units,
1069 params.footskip, default_unit);
1070 setEnabled(paper_->input_foot_skip, useGeom);
1071 setEnabled(paper_->choice_foot_skip_units, useGeom);
1073 fl_set_focus_object(paper_->form, paper_->choice_papersize);
1077 void FormDocument::bullets_update(BufferParams const & params)
1079 if (!bullets_.get() ||
1081 (XpmVersion==4 && XpmRevision<7)))
1084 bool const isLinuxDoc =
1085 controller().docType() == ControlDocument::LINUXDOC;
1086 setEnabled(fbullet, !isLinuxDoc);
1088 if (isLinuxDoc) return;
1090 fl_set_button(bullets_->radio_bullet_depth_1, 1);
1091 fl_set_input(bullets_->input_bullet_latex,
1092 params.user_defined_bullets[0].getText().c_str());
1093 fl_set_choice(bullets_->choice_bullet_size,
1094 params.user_defined_bullets[0].getSize() + 2);
1098 void FormDocument::checkReadOnly()
1100 if (bc().readOnly(controller().bufferIsReadonly())) {
1101 combo_doc_class->deactivate();
1102 combo_language->deactivate();
1103 postWarning(_("Document is read-only."
1104 " No changes to layout permitted."));
1106 combo_doc_class->activate();
1107 combo_language->activate();
1113 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/)
1115 BufferParams & param = controller().params();
1117 // convert from 1-6 range to -1-4
1118 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1119 fl_set_input(bullets_->input_bullet_latex,
1120 param.temp_bullets[current_bullet_depth].getText().c_str());
1124 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1126 BufferParams & param = controller().params();
1128 param.temp_bullets[current_bullet_depth].
1129 setText(getString(bullets_->input_bullet_latex));
1133 void FormDocument::BulletDepth(FL_OBJECT * ob)
1135 /* Should I do the following: */
1136 /* 1. change to the panel that the current bullet belongs in */
1137 /* 2. show that bullet as selected */
1138 /* 3. change the size setting to the size of the bullet in Q.*/
1139 /* 4. display the latex equivalent in the latex box */
1141 /* I'm inclined to just go with 3 and 4 at the moment and */
1142 /* maybe try to support the others later */
1143 BufferParams & param = controller().params();
1146 if (ob == bullets_->radio_bullet_depth_1)
1148 else if (ob == bullets_->radio_bullet_depth_2)
1150 else if (ob == bullets_->radio_bullet_depth_3)
1152 else if (ob == bullets_->radio_bullet_depth_4)
1155 switch (fl_get_button_numb(ob)) {
1157 // right mouse button resets to default
1158 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1160 current_bullet_depth = data;
1161 fl_set_input(bullets_->input_bullet_latex,
1162 param.temp_bullets[data].getText().c_str());
1163 fl_set_choice(bullets_->choice_bullet_size,
1164 param.temp_bullets[data].getSize() + 2);
1169 void FormDocument::BulletPanel(FL_OBJECT * ob)
1171 /* Here we have to change the background pixmap to that selected */
1172 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1175 if (ob == bullets_->radio_bullet_panel_standard)
1177 else if (ob == bullets_->radio_bullet_panel_maths)
1179 else if (ob == bullets_->radio_bullet_panel_ding2)
1181 else if (ob == bullets_->radio_bullet_panel_ding3)
1183 else if (ob == bullets_->radio_bullet_panel_ding4)
1185 else if (ob == bullets_->radio_bullet_panel_ding1)
1188 if (data != current_bullet_panel) {
1189 fl_freeze_form(bullets_->form);
1190 current_bullet_panel = data;
1192 /* free the current pixmap */
1193 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1195 if (ob == bullets_->radio_bullet_panel_standard) {
1196 new_panel = "standard";
1197 } else if (ob == bullets_->radio_bullet_panel_maths ) {
1198 new_panel = "amssymb";
1199 } else if (ob == bullets_->radio_bullet_panel_ding2) {
1200 new_panel = "psnfss1";
1201 } else if (ob == bullets_->radio_bullet_panel_ding3) {
1202 new_panel = "psnfss2";
1203 } else if (ob == bullets_->radio_bullet_panel_ding4) {
1204 new_panel = "psnfss3";
1205 } else if (ob == bullets_->radio_bullet_panel_ding1) {
1206 new_panel = "psnfss4";
1208 /* something very wrong happened */
1209 // play it safe for now but should be an exception
1210 current_bullet_panel = 0; // standard panel
1211 new_panel = "standard";
1213 new_panel += ".xpm";
1214 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1215 LibFileSearch("images", new_panel).c_str());
1216 fl_redraw_object(bullets_->bmtable_bullet_panel);
1217 fl_unfreeze_form(bullets_->form);
1222 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/)
1224 /* handle the user input by setting the current bullet depth's pixmap */
1225 /* to that extracted from the current chosen position of the BMTable */
1226 /* Don't forget to free the button's old pixmap first. */
1228 BufferParams & param = controller().params();
1229 int bmtable_button = fl_get_bmtable(ob);
1231 /* try to keep the button held down till another is pushed */
1232 /* fl_set_bmtable(ob, 1, bmtable_button); */
1233 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1234 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1235 fl_set_input(bullets_->input_bullet_latex,
1236 param.temp_bullets[current_bullet_depth].getText().c_str());
1240 void FormDocument::CheckChoiceClass()
1242 BufferParams & params = controller().params();
1244 lyx::textclass_type const tc = combo_doc_class->get() - 1;
1246 if (controller().loadTextclass(tc)) {
1247 params.textclass = tc;
1249 if (lyxrc.auto_reset_options) {
1250 params.useClassDefaults();
1251 UpdateLayoutDocument(params);
1253 // update the params which are needed in any case
1254 // (fontsizes, pagestyle)
1255 UpdateClassParams(params);
1259 int const revert = int(params.textclass);
1260 combo_doc_class->select(revert + 1);
1265 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1271 class_update(params);
1272 paper_update(params);
1273 language_update(params);
1274 options_update(params);
1275 bullets_update(params);