1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000-2001 The LyX Team.
10 *======================================================*/
14 #include FORMS_H_LOCATION
15 #include XPM_H_LOCATION
18 #pragma implementation
21 #include "lyx_gui_misc.h"
23 #include "FormDocument.h"
24 #include "form_document.h"
28 #include "tex-strings.h"
29 #include "bufferparams.h"
30 #include "insets/insetquotes.h"
33 #include "support/filetools.h"
34 #include "support/lstrings.h"
39 #include "BufferView.h"
42 #include "CutAndPaste.h"
43 #include "bufferview_funcs.h"
44 #include "xforms_helpers.h"
46 #include "input_validators.h" // fl_unsigned_float_filter
47 #include "helper_funcs.h"
48 #include "lyx_main.h" // for user_lyxdir
50 using Liason::setMinibuffer;
53 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
54 : FormBaseBD(lv, d, _("Document Layout")),
55 ActCell(0), Confirmed(0),
56 current_bullet_panel(0), current_bullet_depth(0), fbullet(0)
58 // let the dialog be shown
59 // This is a permanent connection so we won't bother
60 // storing a copy because we won't be disconnecting.
61 d->showDocument.connect(slot(this, &FormDocument::show));
65 void FormDocument::redraw()
67 if( form() && form()->visible )
68 fl_redraw_form( form() );
72 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabbed_folder);
73 if (outer_form && outer_form->visible)
74 fl_redraw_form( outer_form );
78 FL_FORM * FormDocument::form() const
80 if (dialog_.get()) return dialog_->form;
85 void FormDocument::build()
90 dialog_.reset(build_tabbed_document());
92 // Manage the restore, ok, apply, restore and cancel/close buttons
93 bc().setOK(dialog_->button_ok);
94 bc().setApply(dialog_->button_apply);
95 bc().setCancel(dialog_->button_cancel);
96 bc().setRestore(dialog_->button_restore);
97 bc().addReadOnly (dialog_->button_save_defaults);
98 bc().addReadOnly (dialog_->button_reset_defaults);
100 // the document paper form
101 paper_.reset(build_doc_paper());
102 fl_addto_choice(paper_->choice_papersize,
103 _(" Default | Custom | USletter | USlegal "
104 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
105 fl_addto_choice(paper_->choice_paperpackage,
108 "| Very small Margins "
109 "| Very wide Margins "));
111 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
112 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
113 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
114 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
115 fl_set_input_return(paper_->input_left_margin, FL_RETURN_CHANGED);
116 fl_set_input_return(paper_->input_right_margin, FL_RETURN_CHANGED);
117 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
118 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
119 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
121 // Set input filters on width and height to make them accept only
123 fl_set_input_filter(paper_->input_custom_width,
124 fl_unsigned_float_filter);
125 fl_set_input_filter(paper_->input_custom_height,
126 fl_unsigned_float_filter);
127 fl_set_input_filter(paper_->input_top_margin,
128 fl_unsigned_float_filter);
129 fl_set_input_filter(paper_->input_bottom_margin,
130 fl_unsigned_float_filter);
131 fl_set_input_filter(paper_->input_left_margin,
132 fl_unsigned_float_filter);
133 fl_set_input_filter(paper_->input_right_margin,
134 fl_unsigned_float_filter);
135 fl_set_input_filter(paper_->input_head_height,
136 fl_unsigned_float_filter);
137 fl_set_input_filter(paper_->input_head_sep,
138 fl_unsigned_float_filter);
139 fl_set_input_filter(paper_->input_foot_skip,
140 fl_unsigned_float_filter);
142 // Create the contents of the unit choices
143 // Don't include the "%" terms...
144 std::vector<string> units_vec = getLatexUnits();
145 for (std::vector<string>::iterator it = units_vec.begin();
146 it != units_vec.end(); ++it) {
147 if (contains(*it, "%"))
148 it = units_vec.erase(it, it+1) - 1;
150 string units = getStringFromVector(units_vec, "|");
152 fl_addto_choice(paper_->choice_custom_width_units, units.c_str());
153 fl_addto_choice(paper_->choice_custom_height_units, units.c_str());
154 fl_addto_choice(paper_->choice_top_margin_units, units.c_str());
155 fl_addto_choice(paper_->choice_bottom_margin_units, units.c_str());
156 fl_addto_choice(paper_->choice_left_margin_units, units.c_str());
157 fl_addto_choice(paper_->choice_right_margin_units, units.c_str());
158 fl_addto_choice(paper_->choice_head_height_units, units.c_str());
159 fl_addto_choice(paper_->choice_head_sep_units, units.c_str());
160 fl_addto_choice(paper_->choice_foot_skip_units, units.c_str());
162 bc().addReadOnly (paper_->choice_paperpackage);
163 bc().addReadOnly (paper_->group_radio_orientation);
164 bc().addReadOnly (paper_->radio_portrait);
165 bc().addReadOnly (paper_->radio_landscape);
166 bc().addReadOnly (paper_->choice_papersize);
167 bc().addReadOnly (paper_->check_use_geometry);
168 bc().addReadOnly (paper_->input_custom_width);
169 bc().addReadOnly (paper_->input_custom_height);
170 bc().addReadOnly (paper_->input_top_margin);
171 bc().addReadOnly (paper_->input_bottom_margin);
172 bc().addReadOnly (paper_->input_left_margin);
173 bc().addReadOnly (paper_->input_right_margin);
174 bc().addReadOnly (paper_->input_head_height);
175 bc().addReadOnly (paper_->input_head_sep);
176 bc().addReadOnly (paper_->input_foot_skip);
178 // the document class form
179 class_.reset(build_doc_class());
182 // The language is a combo-box and has to be inserted manually
183 obj = class_->choice_doc_class;
184 fl_deactivate_object(obj);
185 fl_addto_form(class_->form);
186 combo_doc_class.reset(new Combox(FL_COMBOX_DROPLIST));
187 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400,
188 dialog_->tabbed_folder);
189 combo_doc_class->shortcut("#C",1);
190 combo_doc_class->setcallback(ComboInputCB, this);
192 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
193 cit != textclasslist.end(); ++cit) {
194 combo_doc_class->addto(cit->description());
197 fl_addto_choice(class_->choice_doc_spacing,
198 _(" Single | OneHalf | Double | Other "));
199 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
200 for (n=0; tex_fonts[n][0]; ++n) {
201 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
203 fl_addto_choice(class_->choice_doc_pagestyle,
204 "default|empty|plain|headings|fancy");
205 fl_addto_choice(class_->choice_doc_skip,
206 _(" Smallskip | Medskip | Bigskip | Length "));
207 fl_addto_choice(class_->choice_default_skip_units, units.c_str());
208 fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
209 fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
210 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
212 // Set input filters on doc skip to make it accept only
214 fl_set_input_filter(class_->input_doc_skip,
215 fl_unsigned_float_filter);
217 bc().addReadOnly (class_->radio_doc_indent);
218 bc().addReadOnly (class_->radio_doc_skip);
220 bc().addReadOnly (class_->choice_doc_pagestyle);
221 bc().addReadOnly (class_->choice_doc_fonts);
222 bc().addReadOnly (class_->choice_doc_fontsize);
223 bc().addReadOnly (class_->radio_doc_sides_one);
224 bc().addReadOnly (class_->radio_doc_sides_two);
225 bc().addReadOnly (class_->radio_doc_columns_one);
226 bc().addReadOnly (class_->radio_doc_columns_two);
227 bc().addReadOnly (class_->input_doc_extra);
228 bc().addReadOnly (class_->input_doc_skip);
229 bc().addReadOnly (class_->choice_doc_skip);
230 bc().addReadOnly (class_->choice_doc_spacing);
231 bc().addReadOnly (class_->input_doc_spacing);
233 // the document language form
234 language_.reset(build_doc_language());
235 fl_addto_choice(language_->choice_inputenc,
236 "default|auto|latin1|latin2|latin3|latin4|latin5|latin9"
237 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
239 // The language is a combo-box and has to be inserted manually
240 obj = language_->choice_language;
241 fl_deactivate_object(obj);
242 fl_addto_form(language_->form);
243 combo_language.reset(new Combox(FL_COMBOX_DROPLIST));
244 combo_language->add(obj->x, obj->y, obj->w, obj->h, 400,
245 dialog_->tabbed_folder);
246 combo_language->shortcut("#L",1);
247 combo_language->setcallback(ComboInputCB, this);
250 for (Languages::const_iterator cit = languages.begin();
251 cit != languages.end(); ++cit) {
252 combo_language->addto(cit->second.lang());
255 fl_addto_choice(language_->choice_quotes_language,
256 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
257 " «text» | »text« "));
259 bc().addReadOnly (language_->choice_inputenc);
260 bc().addReadOnly (language_->choice_quotes_language);
261 bc().addReadOnly (language_->radio_single);
262 bc().addReadOnly (language_->radio_double);
264 // the document options form
265 options_.reset(build_doc_options());
266 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
267 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
268 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
269 fl_set_counter_step(options_->slider_secnumdepth,1,1);
270 fl_set_counter_step(options_->slider_tocdepth,1,1);
271 fl_set_counter_precision(options_->slider_secnumdepth, 0);
272 fl_set_counter_precision(options_->slider_tocdepth, 0);
273 for (n=0; tex_graphics[n][0]; ++n) {
274 fl_addto_choice(options_->choice_postscript_driver,
277 fl_addto_choice(options_->choice_citation_format,
278 _(" Author-year | Numerical "));
280 bc_.addReadOnly (options_->slider_secnumdepth);
281 bc_.addReadOnly (options_->slider_tocdepth);
282 bc_.addReadOnly (options_->check_use_amsmath);
283 bc_.addReadOnly (options_->check_use_natbib);
284 bc_.addReadOnly (options_->choice_citation_format);
285 bc_.addReadOnly (options_->input_float_placement);
286 bc_.addReadOnly (options_->choice_postscript_driver);
288 // the document bullets form
289 bullets_.reset(build_doc_bullet());
290 fl_addto_choice(bullets_->choice_bullet_size,
291 _(" default | tiny | script | footnote | small |"
292 " normal | large | Large | LARGE | huge | Huge"));
293 fl_set_choice(bullets_->choice_bullet_size, 1);
294 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
295 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
297 bc().addReadOnly (bullets_->bmtable_bullet_panel);
298 bc().addReadOnly (bullets_->choice_bullet_size);
299 bc().addReadOnly (bullets_->input_bullet_latex);
300 bc().addReadOnly (bullets_->radio_bullet_depth);
301 bc().addReadOnly (bullets_->radio_bullet_panel);
303 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
305 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
307 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
309 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
311 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
313 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
314 lyxerr << _("Your version of libXpm is older than 4.7.\n"
315 "The `bullet' tab of the document dialog "
316 "has been disabled") << '\n';
317 fl_deactivate_object(fbullet);
318 fl_set_object_lcol(fbullet, FL_INACTIVE);
323 void FormDocument::apply()
325 if (!lv_->view()->available() || !dialog_.get())
328 bool redo = class_apply();
330 redo = language_apply() || redo;
331 redo = options_apply() || redo;
335 lv_->view()->redoCurrentBuffer();
337 lv_->buffer()->markDirty();
338 setMinibuffer(lv_, _("Document layout set"));
342 void FormDocument::cancel()
344 // this avoids confusion when reopening
345 BufferParams & param = lv_->buffer()->params;
346 param.temp_bullets[0] = param.user_defined_bullets[0];
347 param.temp_bullets[1] = param.user_defined_bullets[1];
348 param.temp_bullets[2] = param.user_defined_bullets[2];
349 param.temp_bullets[3] = param.user_defined_bullets[3];
354 void FormDocument::update()
361 BufferParams const & params = lv_->buffer()->params;
363 setEnabled(dialog_->button_reset_defaults,
364 !params.hasClassDefaults());
366 class_update(params);
367 paper_update(params);
368 language_update(params);
369 options_update(params);
370 bullets_update(params);
375 // should this go elsewhere? Maybe a ControllerDocument? (JMarc)
376 /** Save the buffer's parameters as user default.
377 This function saves a file \c user_lyxdir/templates/defaults.lyx
378 which parameters are those of the current buffer. This file
379 is used as a default template when creating a new
380 file. Returns \c true on success.
382 bool saveParamsAsDefault(BufferParams const ¶ms)
384 if (!AskQuestion(_("Do you want to save the current settings"),
385 _("for document layout"),
386 _("as default for new documents?")))
389 string const fname = AddName(AddPath(user_lyxdir, "templates/"),
391 Buffer defaults = Buffer(fname);
392 defaults.params = params;
394 // add an empty paragraph. Is this enough?
395 defaults.paragraph = new Paragraph;
397 return defaults.writeFile(defaults.fileName(), false);
402 bool FormDocument::input( FL_OBJECT * ob, long data )
404 State cb = static_cast<State>( data );
407 case CHECKCHOICECLASS:
408 CheckChoiceClass(ob, 0);
410 case CHOICEBULLETSIZE:
411 ChoiceBulletSize(ob, 0);
413 case INPUTBULLETLATEX:
414 InputBulletLaTeX(ob, 0);
431 BulletBMTable(ob, 0);
437 bool const length_input = fl_get_choice(class_->choice_doc_skip) == 4;
438 if (ob == class_->choice_doc_skip) {
439 setEnabled(class_->input_doc_skip, length_input);
440 setEnabled(class_->choice_default_skip_units, length_input);
443 if (ob == class_->choice_doc_spacing)
444 setEnabled(class_->input_doc_spacing,
445 fl_get_choice(class_->choice_doc_spacing) == 4);
447 bool const skip_used = fl_get_button(class_->radio_doc_skip);
448 if (ob == class_->radio_doc_skip ||
449 ob == class_->radio_doc_indent) {
450 setEnabled(class_->choice_doc_skip, skip_used);
451 setEnabled(class_->input_doc_skip,
452 skip_used && length_input);
453 setEnabled(class_->choice_default_skip_units,
454 skip_used && length_input);
455 // Default unit choice is cm if metric, inches if US paper.
456 int const paperchoice = fl_get_choice(paper_->choice_papersize);
457 bool const metric = paperchoice < 3 || paperchoice > 5;
458 int const default_unit = metric ? 8 : 9;
459 if (strip(fl_get_input(class_->input_doc_skip)).empty())
460 fl_set_choice(class_->choice_default_skip_units,
464 if (ob == options_->check_use_natbib) {
465 setEnabled(options_->choice_citation_format,
466 fl_get_button(options_->check_use_natbib));
469 if (ob == dialog_->button_save_defaults) {
473 language_apply(params);
474 options_apply(params);
475 bullets_apply(params);
476 saveParamsAsDefault(params);
479 if (ob == dialog_->button_reset_defaults) {
480 BufferParams params = lv_->buffer()->params;
481 params.textclass = combo_doc_class->get() - 1;
482 params.useClassDefaults();
483 UpdateLayoutDocument(params);
486 if (ob == paper_->radio_landscape)
487 fl_set_choice(paper_->choice_paperpackage,
488 BufferParams::PACKAGE_NONE + 1);
490 if (ob == paper_->choice_papersize) {
491 int const paperchoice = fl_get_choice(paper_->choice_papersize);
492 bool const custom = paperchoice == 2;
493 bool const a3size = paperchoice == 6;
494 bool const b3size = paperchoice == 9;
495 bool const b4size = paperchoice == 10;
498 fl_set_button(paper_->radio_portrait, 1);
500 bool const use_geom = (custom || a3size || b3size || b4size);
502 fl_set_button(paper_->check_use_geometry, int(use_geom));
504 setEnabled(paper_->input_top_margin, use_geom);
505 setEnabled(paper_->input_bottom_margin, use_geom);
506 setEnabled(paper_->input_left_margin, use_geom);
507 setEnabled(paper_->input_right_margin, use_geom);
508 setEnabled(paper_->input_head_height, use_geom);
509 setEnabled(paper_->input_head_sep, use_geom);
510 setEnabled(paper_->input_foot_skip, use_geom);
511 setEnabled(paper_->choice_top_margin_units, use_geom);
512 setEnabled(paper_->choice_bottom_margin_units, use_geom);
513 setEnabled(paper_->choice_left_margin_units, use_geom);
514 setEnabled(paper_->choice_right_margin_units, use_geom);
515 setEnabled(paper_->choice_head_height_units, use_geom);
516 setEnabled(paper_->choice_head_sep_units, use_geom);
517 setEnabled(paper_->choice_foot_skip_units, use_geom);
518 setEnabled(paper_->choice_custom_width_units, use_geom);
519 setEnabled(paper_->choice_custom_height_units, use_geom);
521 setEnabled(paper_->input_custom_width, custom);
522 setEnabled(paper_->input_custom_height, custom);
523 setEnabled(paper_->choice_custom_width_units, custom);
524 setEnabled(paper_->choice_custom_height_units, custom);
525 setEnabled(paper_->radio_portrait, !custom);
526 setEnabled(paper_->radio_landscape, !custom);
528 // Default unit choice is cm if metric, inches if US paper.
529 bool const metric = paperchoice < 3 || paperchoice > 5;
530 int const default_unit = metric ? 8 : 9;
531 if (strip(fl_get_input(paper_->input_custom_width)).empty())
532 fl_set_choice(paper_->choice_custom_width_units,
534 if (strip(fl_get_input(paper_->input_custom_height)).empty())
535 fl_set_choice(paper_->choice_custom_height_units,
537 if (strip(fl_get_input(paper_->input_top_margin)).empty())
538 fl_set_choice(paper_->choice_top_margin_units,
540 if (strip(fl_get_input(paper_->input_bottom_margin)).empty())
541 fl_set_choice(paper_->choice_bottom_margin_units,
543 if (strip(fl_get_input(paper_->input_left_margin)).empty())
544 fl_set_choice(paper_->choice_left_margin_units,
546 if (strip(fl_get_input(paper_->input_right_margin)).empty())
547 fl_set_choice(paper_->choice_right_margin_units,
549 if (strip(fl_get_input(paper_->input_head_height)).empty())
550 fl_set_choice(paper_->choice_head_height_units,
552 if (strip(fl_get_input(paper_->input_head_sep)).empty())
553 fl_set_choice(paper_->choice_head_sep_units,
555 if (strip(fl_get_input(paper_->input_foot_skip)).empty())
556 fl_set_choice(paper_->choice_foot_skip_units,
560 if (ob == paper_->choice_papersize ||
561 ob == paper_->radio_portrait ||
562 ob == paper_->radio_landscape) {
564 setEnabled(paper_->choice_paperpackage,
565 //either default papersize (preferences)
566 //or document papersize has to be A4
567 (fl_get_choice(paper_->choice_papersize) == 7
568 || fl_get_choice(paper_->choice_papersize) == 1
569 && lyxrc.default_papersize == 5)
570 && fl_get_button(paper_->radio_portrait));
573 if (ob == paper_->choice_paperpackage) {
574 if (fl_get_choice(paper_->choice_paperpackage) != 1) {
575 fl_set_button(paper_->check_use_geometry, 0);
577 setEnabled(paper_->input_top_margin, false);
578 setEnabled(paper_->input_bottom_margin, false);
579 setEnabled(paper_->input_left_margin, false);
580 setEnabled(paper_->input_right_margin, false);
581 setEnabled(paper_->input_head_height, false);
582 setEnabled(paper_->input_head_sep, false);
583 setEnabled(paper_->input_foot_skip, false);
584 setEnabled(paper_->choice_top_margin_units, false);
585 setEnabled(paper_->choice_bottom_margin_units, false);
586 setEnabled(paper_->choice_left_margin_units, false);
587 setEnabled(paper_->choice_right_margin_units, false);
588 setEnabled(paper_->choice_head_height_units, false);
589 setEnabled(paper_->choice_head_sep_units, false);
590 setEnabled(paper_->choice_foot_skip_units, false);
594 if (ob == paper_->check_use_geometry) {
595 //don't allow switching geometry off in custom papersize mode
596 //nor in A3, B3, and B4
597 int const choice = fl_get_choice(paper_->choice_papersize);
598 if (choice == 2 || choice == 6 || choice == 9 || choice == 10)
599 fl_set_button(paper_->check_use_geometry, 1);
601 fl_set_choice(paper_->choice_paperpackage,
602 BufferParams::PACKAGE_NONE + 1);
604 bool const use_geom = fl_get_button(paper_->check_use_geometry);
605 setEnabled(paper_->input_top_margin, use_geom);
606 setEnabled(paper_->input_bottom_margin, use_geom);
607 setEnabled(paper_->input_left_margin, use_geom);
608 setEnabled(paper_->input_right_margin, use_geom);
609 setEnabled(paper_->input_head_height, use_geom);
610 setEnabled(paper_->input_head_sep, use_geom);
611 setEnabled(paper_->input_foot_skip, use_geom);
612 setEnabled(paper_->choice_top_margin_units, use_geom);
613 setEnabled(paper_->choice_bottom_margin_units, use_geom);
614 setEnabled(paper_->choice_left_margin_units, use_geom);
615 setEnabled(paper_->choice_right_margin_units, use_geom);
616 setEnabled(paper_->choice_head_height_units, use_geom);
617 setEnabled(paper_->choice_head_sep_units, use_geom);
618 setEnabled(paper_->choice_foot_skip_units, use_geom);
621 setEnabled(dialog_->button_reset_defaults,
622 lv_->buffer()->params.hasClassDefaults());
626 case CHECKCHOICECLASS:
627 case CHOICEBULLETSIZE:
628 case INPUTBULLETLATEX:
630 return CheckDocumentInput(ob, 0);
639 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
641 FormDocument * pre = static_cast<FormDocument*>(v);
642 if (combox == pre->combo_doc_class.get())
643 pre->CheckChoiceClass(0, 0);
644 pre->bc().valid(pre->CheckDocumentInput(0,0));
648 bool FormDocument::class_apply(BufferParams ¶ms)
652 // If default skip is a "Length" but there's no text in the
653 // input field, reset the kind to "Medskip", which is the default.
654 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
655 !*(fl_get_input (class_->input_doc_skip))) {
656 fl_set_choice (class_->choice_doc_skip, 2);
658 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
659 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
660 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
662 params.textclass = combo_doc_class->get() - 1;
664 BufferParams::PARSEP tmpsep = params.paragraph_separation;
665 if (fl_get_button(class_->radio_doc_indent))
666 params.paragraph_separation = BufferParams::PARSEP_INDENT;
668 params.paragraph_separation = BufferParams::PARSEP_SKIP;
669 if (tmpsep != params.paragraph_separation)
672 VSpace tmpdefskip = params.getDefSkip();
673 switch (fl_get_choice (class_->choice_doc_skip)) {
675 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
678 params.setDefSkip(VSpace(VSpace::MEDSKIP));
681 params.setDefSkip(VSpace(VSpace::BIGSKIP));
685 string const length =
686 getLengthFromWidgets(class_->input_doc_skip,
687 class_->choice_default_skip_units);
689 params.setDefSkip(VSpace(LyXGlueLength(length)));
693 // DocumentDefskipCB assures that this never happens
694 params.setDefSkip(VSpace(VSpace::MEDSKIP));
697 if (!(tmpdefskip == params.getDefSkip()))
700 if (fl_get_button(class_->radio_doc_columns_two))
704 if (fl_get_button(class_->radio_doc_sides_two))
705 params.sides = LyXTextClass::TwoSides;
707 params.sides = LyXTextClass::OneSide;
709 Spacing tmpSpacing = params.spacing;
710 switch (fl_get_choice(class_->choice_doc_spacing)) {
712 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
713 params.spacing.set(Spacing::Single);
716 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
717 params.spacing.set(Spacing::Onehalf);
720 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
721 params.spacing.set(Spacing::Double);
724 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
725 params.spacing.set(Spacing::Other,
726 fl_get_input(class_->input_doc_spacing));
729 if (tmpSpacing != params.spacing)
732 params.options = fl_get_input(class_->input_doc_extra);
738 bool FormDocument::class_apply()
740 BufferParams ¶ms = lv_->buffer()->params;
742 unsigned int const old_class = params.textclass;
744 bool redo = class_apply(params);
746 if (params.textclass != old_class) {
747 // try to load new_class
748 if (textclasslist.Load(params.textclass)) {
749 // successfully loaded
751 setMinibuffer(lv_, _("Converting document to new document class..."));
752 int ret = CutAndPaste::SwitchLayoutsBetweenClasses(
753 old_class, params.textclass,
754 lv_->buffer()->paragraph);
758 s = _("One paragraph couldn't be converted");
761 s += _(" paragraphs couldn't be converted");
763 WriteAlert(_("Conversion Errors!"),s,
764 _("into chosen document class"));
768 // problem changing class -- warn user and retain old style
769 WriteAlert(_("Conversion Errors!"),
770 _("Errors loading new document class."),
771 _("Reverting to original document class."));
772 combo_doc_class->select(int(old_class) + 1);
780 void FormDocument::paper_apply(BufferParams & params)
782 params.papersize2 = char(fl_get_choice(paper_->choice_papersize)-1);
784 params.paperpackage =
785 char(fl_get_choice(paper_->choice_paperpackage)-1);
787 // set params.papersize from params.papersize2 and params.paperpackage
788 params.setPaperStuff();
790 params.use_geometry = fl_get_button(paper_->check_use_geometry);
792 if (fl_get_button(paper_->radio_landscape))
793 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
795 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
798 getLengthFromWidgets(paper_->input_custom_width,
799 paper_->choice_custom_width_units);
802 getLengthFromWidgets(paper_->input_custom_height,
803 paper_->choice_custom_height_units);
806 getLengthFromWidgets(paper_->input_left_margin,
807 paper_->choice_left_margin_units);
810 getLengthFromWidgets(paper_->input_top_margin,
811 paper_->choice_top_margin_units);
814 getLengthFromWidgets(paper_->input_right_margin,
815 paper_->choice_right_margin_units);
817 params.bottommargin =
818 getLengthFromWidgets(paper_->input_bottom_margin,
819 paper_->choice_bottom_margin_units);
822 getLengthFromWidgets(paper_->input_head_height,
823 paper_->choice_head_height_units);
826 getLengthFromWidgets(paper_->input_head_sep,
827 paper_->choice_head_sep_units);
830 getLengthFromWidgets(paper_->input_foot_skip,
831 paper_->choice_foot_skip_units);
835 void FormDocument::paper_apply()
837 paper_apply(lv_->buffer()->params);
841 bool FormDocument::language_apply(BufferParams & params)
843 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
846 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
848 lga = InsetQuotes::EnglishQ;
851 lga = InsetQuotes::SwedishQ;
854 lga = InsetQuotes::GermanQ;
857 lga = InsetQuotes::PolishQ;
860 lga = InsetQuotes::FrenchQ;
863 lga = InsetQuotes::DanishQ;
866 params.quotes_language = lga;
867 if (fl_get_button(language_->radio_single))
868 params.quotes_times = InsetQuotes::SingleQ;
870 params.quotes_times = InsetQuotes::DoubleQ;
872 Language const * new_language =
873 languages.getLanguage(combo_language->getline());
875 new_language = default_language;
877 params.language = new_language;
878 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
884 bool FormDocument::language_apply()
886 BufferParams & params = lv_->buffer()->params;
887 Language const * old_language = params.language;
889 bool redo = language_apply(params);
891 if (old_language != params.language
892 && old_language->RightToLeft() == params.language->RightToLeft()
893 && !lv_->buffer()->isMultiLingual())
894 lv_->buffer()->changeLanguage(old_language, params.language);
895 if (old_language != params.language) {
903 bool FormDocument::options_apply(BufferParams & params)
907 params.graphicsDriver =
908 fl_get_choice_text(options_->choice_postscript_driver);
909 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
910 params.use_natbib = fl_get_button(options_->check_use_natbib);
911 params.use_numerical_citations =
912 fl_get_choice(options_->choice_citation_format)-1;
914 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
915 if (params.secnumdepth != tmpchar)
917 params.secnumdepth = tmpchar;
919 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
921 params.float_placement =
922 fl_get_input(options_->input_float_placement);
928 bool FormDocument::options_apply()
930 return options_apply(lv_->buffer()->params);
934 void FormDocument::bullets_apply(BufferParams & params)
936 /* update the bullet settings */
937 BufferParams & buf_params = lv_->buffer()->params;
939 // a little bit of loop unrolling
940 params.user_defined_bullets[0] = buf_params.temp_bullets[0];
941 params.user_defined_bullets[1] = buf_params.temp_bullets[1];
942 params.user_defined_bullets[2] = buf_params.temp_bullets[2];
943 params.user_defined_bullets[3] = buf_params.temp_bullets[3];
947 void FormDocument::bullets_apply()
949 bullets_apply(lv_->buffer()->params);
953 void FormDocument::class_update(BufferParams const & params)
958 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
960 combo_doc_class->select(
961 textclasslist.DescOfClass(params.textclass));
962 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
963 fl_clear_choice(class_->choice_doc_fontsize);
964 fl_addto_choice(class_->choice_doc_fontsize, "default");
965 fl_addto_choice(class_->choice_doc_fontsize,
966 tclass.opt_fontsize().c_str());
967 fl_set_choice(class_->choice_doc_fontsize,
968 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
969 fl_clear_choice(class_->choice_doc_pagestyle);
970 fl_addto_choice(class_->choice_doc_pagestyle, "default");
971 fl_addto_choice(class_->choice_doc_pagestyle,
972 tclass.opt_pagestyle().c_str());
973 fl_set_choice(class_->choice_doc_pagestyle,
974 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
975 fl_set_button(class_->radio_doc_indent, 0);
976 fl_set_button(class_->radio_doc_skip, 0);
977 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
978 fl_set_button(class_->radio_doc_indent, 1);
980 fl_set_button(class_->radio_doc_skip, 1);
982 bool const input_length = fl_get_choice(class_->choice_doc_skip) == 4;
983 setEnabled(class_->choice_default_skip_units, input_length);
984 setEnabled(class_->input_doc_skip, input_length);
986 switch (params.getDefSkip().kind()) {
987 case VSpace::SMALLSKIP:
988 fl_set_choice (class_->choice_doc_skip, 1);
990 case VSpace::MEDSKIP:
991 fl_set_choice (class_->choice_doc_skip, 2);
993 case VSpace::BIGSKIP:
994 fl_set_choice (class_->choice_doc_skip, 3);
998 int const paperchoice = params.papersize2 + 1;
999 bool const metric = paperchoice < 3 || paperchoice > 5;
1000 string const default_unit = metric ? "cm" : "in";
1001 string const length = params.getDefSkip().asLyXCommand();
1002 updateWidgetsFromLengthString(class_->input_doc_skip,
1003 class_->choice_default_skip_units,
1004 length, default_unit);
1008 fl_set_choice (class_->choice_doc_skip, 2);
1011 fl_set_button(class_->radio_doc_sides_one, 0);
1012 fl_set_button(class_->radio_doc_sides_two, 0);
1013 setEnabled(class_->choice_doc_skip,
1014 fl_get_button(class_->radio_doc_skip));
1016 if (params.sides == LyXTextClass::TwoSides)
1017 fl_set_button(class_->radio_doc_sides_two, 1);
1019 fl_set_button(class_->radio_doc_sides_one, 1);
1020 fl_set_button(class_->radio_doc_columns_one, 0);
1021 fl_set_button(class_->radio_doc_columns_two, 0);
1022 if (params.columns == 2)
1023 fl_set_button(class_->radio_doc_columns_two, 1);
1025 fl_set_button(class_->radio_doc_columns_one, 1);
1026 fl_set_input(class_->input_doc_spacing, "");
1028 setEnabled(class_->input_doc_spacing, input_length);
1030 switch (params.spacing.getSpace()) {
1031 case Spacing::Default: // nothing bad should happen with this
1032 case Spacing::Single:
1034 fl_set_choice(class_->choice_doc_spacing, 1);
1036 case Spacing::Onehalf:
1038 fl_set_choice(class_->choice_doc_spacing, 2);
1040 case Spacing::Double:
1042 fl_set_choice(class_->choice_doc_spacing, 3);
1044 case Spacing::Other:
1046 fl_set_choice(class_->choice_doc_spacing, 4);
1048 sprintf(sval,"%g",params.spacing.getValue());
1049 fl_set_input(class_->input_doc_spacing, sval);
1053 if (!params.options.empty())
1054 fl_set_input(class_->input_doc_extra, params.options.c_str());
1056 fl_set_input(class_->input_doc_extra, "");
1060 void FormDocument::language_update(BufferParams const & params)
1062 if (!language_.get())
1065 combo_language->select(params.language->lang());
1066 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
1067 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
1068 fl_set_button(language_->radio_single, 0);
1069 fl_set_button(language_->radio_double, 0);
1070 if (params.quotes_times == InsetQuotes::SingleQ)
1071 fl_set_button(language_->radio_single, 1);
1073 fl_set_button(language_->radio_double, 1);
1077 void FormDocument::options_update(BufferParams const & params)
1079 if (!options_.get())
1082 fl_set_choice_text(options_->choice_postscript_driver,
1083 params.graphicsDriver.c_str());
1084 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
1085 fl_set_button(options_->check_use_natbib, params.use_natbib);
1086 fl_set_choice(options_->choice_citation_format,
1087 int(params.use_numerical_citations)+1);
1088 setEnabled(options_->choice_citation_format, params.use_natbib);
1089 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
1090 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
1091 if (!params.float_placement.empty())
1092 fl_set_input(options_->input_float_placement,
1093 params.float_placement.c_str());
1095 fl_set_input(options_->input_float_placement, "");
1099 void FormDocument::paper_update(BufferParams const & params)
1104 fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
1105 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
1106 fl_set_button(paper_->check_use_geometry, params.use_geometry);
1108 int const paperchoice = fl_get_choice(paper_->choice_papersize);
1109 bool const useCustom = paperchoice == 2;
1110 bool const useGeom = fl_get_button(paper_->check_use_geometry);
1112 fl_set_button(paper_->radio_portrait, 0);
1113 setEnabled(paper_->radio_portrait, !useCustom);
1114 fl_set_button(paper_->radio_landscape, 0);
1115 setEnabled(paper_->radio_landscape, !useCustom);
1117 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1118 fl_set_button(paper_->radio_landscape, 1);
1120 fl_set_button(paper_->radio_portrait, 1);
1121 setEnabled(paper_->choice_paperpackage,
1122 //either default papersize (preferences)
1123 //or document papersize has to be A4
1125 || paperchoice == 1 && lyxrc.default_papersize == 5)
1126 && fl_get_button(paper_->radio_portrait));
1128 // Default unit choice is cm if metric, inches if US paper.
1129 bool const metric = paperchoice < 3 || paperchoice > 5;
1130 string const default_unit = metric ? "cm" : "in";
1131 updateWidgetsFromLengthString(paper_->input_custom_width,
1132 paper_->choice_custom_width_units,
1133 params.paperwidth, default_unit);
1134 setEnabled(paper_->input_custom_width, useCustom);
1135 setEnabled(paper_->choice_custom_width_units, useCustom);
1137 updateWidgetsFromLengthString(paper_->input_custom_height,
1138 paper_->choice_custom_height_units,
1139 params.paperheight, default_unit);
1140 setEnabled(paper_->input_custom_height, useCustom);
1141 setEnabled(paper_->choice_custom_height_units, useCustom);
1143 updateWidgetsFromLengthString(paper_->input_left_margin,
1144 paper_->choice_left_margin_units,
1145 params.leftmargin, default_unit);
1146 setEnabled(paper_->input_left_margin, useGeom);
1147 setEnabled(paper_->choice_left_margin_units, useGeom);
1149 updateWidgetsFromLengthString(paper_->input_top_margin,
1150 paper_->choice_top_margin_units,
1151 params.topmargin, default_unit);
1152 setEnabled(paper_->input_top_margin, useGeom);
1153 setEnabled(paper_->choice_top_margin_units, useGeom);
1155 updateWidgetsFromLengthString(paper_->input_right_margin,
1156 paper_->choice_right_margin_units,
1157 params.rightmargin, default_unit);
1158 setEnabled(paper_->input_right_margin, useGeom);
1159 setEnabled(paper_->choice_right_margin_units, useGeom);
1161 updateWidgetsFromLengthString(paper_->input_bottom_margin,
1162 paper_->choice_bottom_margin_units,
1163 params.bottommargin, default_unit);
1164 setEnabled(paper_->input_bottom_margin, useGeom);
1165 setEnabled(paper_->choice_bottom_margin_units, useGeom);
1167 updateWidgetsFromLengthString(paper_->input_head_height,
1168 paper_->choice_head_height_units,
1169 params.headheight, default_unit);
1170 setEnabled(paper_->input_head_height, useGeom);
1171 setEnabled(paper_->choice_head_height_units, useGeom);
1173 updateWidgetsFromLengthString(paper_->input_head_sep,
1174 paper_->choice_head_sep_units,
1175 params.headsep, default_unit);
1176 setEnabled(paper_->input_head_sep, useGeom);
1177 setEnabled(paper_->choice_head_sep_units, useGeom);
1179 updateWidgetsFromLengthString(paper_->input_foot_skip,
1180 paper_->choice_foot_skip_units,
1181 params.footskip, default_unit);
1182 setEnabled(paper_->input_foot_skip, useGeom);
1183 setEnabled(paper_->choice_foot_skip_units, useGeom);
1185 fl_set_focus_object(paper_->form, paper_->choice_papersize);
1189 void FormDocument::bullets_update(BufferParams const & params)
1191 if (!bullets_.get() ||
1193 (XpmVersion==4 && XpmRevision<7)))
1196 bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
1197 setEnabled(fbullet, !isLinuxDoc);
1199 if (isLinuxDoc) return;
1201 fl_set_button(bullets_->radio_bullet_depth_1, 1);
1202 fl_set_input(bullets_->input_bullet_latex,
1203 params.user_defined_bullets[0].getText().c_str());
1204 fl_set_choice(bullets_->choice_bullet_size,
1205 params.user_defined_bullets[0].getSize() + 2);
1209 void FormDocument::checkReadOnly()
1211 if (bc().readOnly(lv_->buffer()->isReadonly())) {
1212 combo_doc_class->deactivate();
1213 combo_language->deactivate();
1214 fl_set_object_label(dialog_->text_warning,
1215 _("Document is read-only."
1216 " No changes to layout permitted."));
1217 fl_show_object(dialog_->text_warning);
1219 combo_doc_class->activate();
1220 combo_language->activate();
1221 fl_hide_object(dialog_->text_warning);
1226 bool FormDocument::CheckDocumentInput(FL_OBJECT *, long)
1232 // "Synchronize" the choice and the input field, so that it
1233 // is impossible to commit senseless data.
1234 input = fl_get_input (class_->input_doc_skip);
1235 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
1237 else if (fl_get_choice(class_->choice_doc_skip) != 4)
1238 fl_set_input (class_->input_doc_skip, "");
1240 input = fl_get_input(class_->input_doc_spacing);
1241 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
1243 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
1244 fl_set_input (class_->input_doc_spacing, "");
1249 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
1251 BufferParams & param = lv_->buffer()->params;
1253 // convert from 1-6 range to -1-4
1254 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1255 fl_set_input(bullets_->input_bullet_latex,
1256 param.temp_bullets[current_bullet_depth].getText().c_str());
1260 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1262 BufferParams & param = lv_->buffer()->params;
1264 param.temp_bullets[current_bullet_depth].
1265 setText(fl_get_input(bullets_->input_bullet_latex));
1269 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
1271 /* Should I do the following: */
1272 /* 1. change to the panel that the current bullet belongs in */
1273 /* 2. show that bullet as selected */
1274 /* 3. change the size setting to the size of the bullet in Q.*/
1275 /* 4. display the latex equivalent in the latex box */
1277 /* I'm inclined to just go with 3 and 4 at the moment and */
1278 /* maybe try to support the others later */
1279 BufferParams & param = lv_->buffer()->params;
1282 if (cb == BULLETDEPTH1 )
1284 else if (cb == BULLETDEPTH2 )
1286 else if (cb == BULLETDEPTH3 )
1288 else if (cb == BULLETDEPTH4 )
1291 switch (fl_get_button_numb(ob)) {
1293 // right mouse button resets to default
1294 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1296 current_bullet_depth = data;
1297 fl_set_input(bullets_->input_bullet_latex,
1298 param.temp_bullets[data].getText().c_str());
1299 fl_set_choice(bullets_->choice_bullet_size,
1300 param.temp_bullets[data].getSize() + 2);
1305 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
1307 /* Here we have to change the background pixmap to that selected */
1308 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1311 if (cb == BULLETPANEL1 )
1313 else if (cb == BULLETPANEL2 )
1315 else if (cb == BULLETPANEL3 )
1317 else if (cb == BULLETPANEL4 )
1319 else if (cb == BULLETPANEL5 )
1321 else if (cb == BULLETPANEL6 )
1324 if (data != current_bullet_panel) {
1325 fl_freeze_form(bullets_->form);
1326 current_bullet_panel = data;
1328 /* free the current pixmap */
1329 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1332 /* display the new one */
1334 new_panel = "standard";
1337 new_panel = "amssymb";
1340 new_panel = "psnfss1";
1343 new_panel = "psnfss2";
1346 new_panel = "psnfss3";
1349 new_panel = "psnfss4";
1352 /* something very wrong happened */
1353 // play it safe for now but should be an exception
1354 current_bullet_panel = 0; // standard panel
1355 new_panel = "standard";
1358 new_panel += ".xpm";
1359 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1360 LibFileSearch("images", new_panel).c_str());
1361 fl_redraw_object(bullets_->bmtable_bullet_panel);
1362 fl_unfreeze_form(bullets_->form);
1367 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1369 /* handle the user input by setting the current bullet depth's pixmap */
1370 /* to that extracted from the current chosen position of the BMTable */
1371 /* Don't forget to free the button's old pixmap first. */
1373 BufferParams & param = lv_->buffer()->params;
1374 int bmtable_button = fl_get_bmtable(ob);
1376 /* try to keep the button held down till another is pushed */
1377 /* fl_set_bmtable(ob, 1, bmtable_button); */
1378 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1379 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1380 fl_set_input(bullets_->input_bullet_latex,
1381 param.temp_bullets[current_bullet_depth].getText().c_str());
1385 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1388 ob = class_->choice_doc_class;
1390 lv_->prohibitInput();
1392 unsigned int tc = combo_doc_class->get() - 1;
1393 if (textclasslist.Load(tc)) {
1394 // we use a copy of the bufferparams because we do not
1395 // want to modify them yet.
1396 BufferParams params = lv_->buffer()->params;
1398 if (lyxrc.auto_reset_options) {
1399 params.textclass = tc;
1400 params.useClassDefaults();
1401 UpdateLayoutDocument(params);
1404 // unable to load new style
1405 WriteAlert(_("Conversion Errors!"),
1406 _("Unable to switch to new document class."),
1407 _("Reverting to original document class."));
1408 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1414 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1420 class_update(params);
1421 paper_update(params);
1422 language_update(params);
1423 options_update(params);
1424 bullets_update(params);