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"
49 using Liason::setMinibuffer;
52 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
53 : FormBaseBD(lv, d, _("Document Layout")),
54 ActCell(0), Confirmed(0),
55 current_bullet_panel(0), current_bullet_depth(0), fbullet(0)
57 // let the dialog be shown
58 // This is a permanent connection so we won't bother
59 // storing a copy because we won't be disconnecting.
60 d->showDocument.connect(slot(this, &FormDocument::show));
64 void FormDocument::redraw()
66 if( form() && form()->visible )
67 fl_redraw_form( form() );
71 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabbed_folder);
72 if (outer_form && outer_form->visible)
73 fl_redraw_form( outer_form );
77 FL_FORM * FormDocument::form() const
79 if (dialog_.get()) return dialog_->form;
84 void FormDocument::build()
89 dialog_.reset(build_tabbed_document());
91 // Manage the restore, ok, apply, restore and cancel/close buttons
92 bc().setOK(dialog_->button_ok);
93 bc().setApply(dialog_->button_apply);
94 bc().setCancel(dialog_->button_cancel);
95 bc().setRestore(dialog_->button_restore);
96 bc().addReadOnly (dialog_->button_save_defaults);
97 bc().addReadOnly (dialog_->button_reset_defaults);
99 // the document paper form
100 paper_.reset(build_doc_paper());
101 fl_addto_choice(paper_->choice_papersize,
102 _(" Default | Custom | USletter | USlegal "
103 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
104 fl_addto_choice(paper_->choice_paperpackage,
107 "| Very small Margins "
108 "| Very wide Margins "));
110 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
111 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
112 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
113 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
114 fl_set_input_return(paper_->input_left_margin, FL_RETURN_CHANGED);
115 fl_set_input_return(paper_->input_right_margin, FL_RETURN_CHANGED);
116 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
117 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
118 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
120 // Set input filters on width and height to make them accept only
122 fl_set_input_filter(paper_->input_custom_width,
123 fl_unsigned_float_filter);
124 fl_set_input_filter(paper_->input_custom_height,
125 fl_unsigned_float_filter);
126 fl_set_input_filter(paper_->input_top_margin,
127 fl_unsigned_float_filter);
128 fl_set_input_filter(paper_->input_bottom_margin,
129 fl_unsigned_float_filter);
130 fl_set_input_filter(paper_->input_left_margin,
131 fl_unsigned_float_filter);
132 fl_set_input_filter(paper_->input_right_margin,
133 fl_unsigned_float_filter);
134 fl_set_input_filter(paper_->input_head_height,
135 fl_unsigned_float_filter);
136 fl_set_input_filter(paper_->input_head_sep,
137 fl_unsigned_float_filter);
138 fl_set_input_filter(paper_->input_foot_skip,
139 fl_unsigned_float_filter);
141 // Create the contents of the unit choices
142 // Don't include the "%" terms...
143 std::vector<string> units_vec = getLatexUnits();
144 for (std::vector<string>::iterator it = units_vec.begin();
145 it != units_vec.end(); ++it) {
146 if (contains(*it, "%"))
147 it = units_vec.erase(it, it+1) - 1;
149 string units = getStringFromVector(units_vec, "|");
151 fl_addto_choice(paper_->choice_custom_width_units, units.c_str());
152 fl_addto_choice(paper_->choice_custom_height_units, units.c_str());
153 fl_addto_choice(paper_->choice_top_margin_units, units.c_str());
154 fl_addto_choice(paper_->choice_bottom_margin_units, units.c_str());
155 fl_addto_choice(paper_->choice_left_margin_units, units.c_str());
156 fl_addto_choice(paper_->choice_right_margin_units, units.c_str());
157 fl_addto_choice(paper_->choice_head_height_units, units.c_str());
158 fl_addto_choice(paper_->choice_head_sep_units, units.c_str());
159 fl_addto_choice(paper_->choice_foot_skip_units, units.c_str());
161 bc().addReadOnly (paper_->choice_paperpackage);
162 bc().addReadOnly (paper_->group_radio_orientation);
163 bc().addReadOnly (paper_->radio_portrait);
164 bc().addReadOnly (paper_->radio_landscape);
165 bc().addReadOnly (paper_->choice_papersize);
166 bc().addReadOnly (paper_->check_use_geometry);
167 bc().addReadOnly (paper_->input_custom_width);
168 bc().addReadOnly (paper_->input_custom_height);
169 bc().addReadOnly (paper_->input_top_margin);
170 bc().addReadOnly (paper_->input_bottom_margin);
171 bc().addReadOnly (paper_->input_left_margin);
172 bc().addReadOnly (paper_->input_right_margin);
173 bc().addReadOnly (paper_->input_head_height);
174 bc().addReadOnly (paper_->input_head_sep);
175 bc().addReadOnly (paper_->input_foot_skip);
177 // the document class form
178 class_.reset(build_doc_class());
181 // The language is a combo-box and has to be inserted manually
182 obj = class_->choice_doc_class;
183 fl_deactivate_object(obj);
184 fl_addto_form(class_->form);
185 combo_doc_class.reset(new Combox(FL_COMBOX_DROPLIST));
186 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400,
187 dialog_->tabbed_folder);
188 combo_doc_class->shortcut("#C",1);
189 combo_doc_class->setcallback(ComboInputCB, this);
191 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
192 cit != textclasslist.end(); ++cit) {
193 combo_doc_class->addto(cit->description());
196 fl_addto_choice(class_->choice_doc_spacing,
197 _(" Single | OneHalf | Double | Other "));
198 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
199 for (n=0; tex_fonts[n][0]; ++n) {
200 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
202 fl_addto_choice(class_->choice_doc_pagestyle,
203 "default|empty|plain|headings|fancy");
204 fl_addto_choice(class_->choice_doc_skip,
205 _(" Smallskip | Medskip | Bigskip | Length "));
206 fl_addto_choice(class_->choice_default_skip_units, units.c_str());
207 fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
208 fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
209 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
211 // Set input filters on doc skip to make it accept only
213 fl_set_input_filter(class_->input_doc_skip,
214 fl_unsigned_float_filter);
216 bc().addReadOnly (class_->radio_doc_indent);
217 bc().addReadOnly (class_->radio_doc_skip);
219 bc().addReadOnly (class_->choice_doc_pagestyle);
220 bc().addReadOnly (class_->choice_doc_fonts);
221 bc().addReadOnly (class_->choice_doc_fontsize);
222 bc().addReadOnly (class_->radio_doc_sides_one);
223 bc().addReadOnly (class_->radio_doc_sides_two);
224 bc().addReadOnly (class_->radio_doc_columns_one);
225 bc().addReadOnly (class_->radio_doc_columns_two);
226 bc().addReadOnly (class_->input_doc_extra);
227 bc().addReadOnly (class_->input_doc_skip);
228 bc().addReadOnly (class_->choice_doc_skip);
229 bc().addReadOnly (class_->choice_doc_spacing);
230 bc().addReadOnly (class_->input_doc_spacing);
232 // the document language form
233 language_.reset(build_doc_language());
234 fl_addto_choice(language_->choice_inputenc,
235 "default|auto|latin1|latin2|latin3|latin4|latin5|latin9"
236 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
238 // The language is a combo-box and has to be inserted manually
239 obj = language_->choice_language;
240 fl_deactivate_object(obj);
241 fl_addto_form(language_->form);
242 combo_language.reset(new Combox(FL_COMBOX_DROPLIST));
243 combo_language->add(obj->x, obj->y, obj->w, obj->h, 400,
244 dialog_->tabbed_folder);
245 combo_language->shortcut("#L",1);
246 combo_language->setcallback(ComboInputCB, this);
249 for (Languages::const_iterator cit = languages.begin();
250 cit != languages.end(); ++cit) {
251 combo_language->addto(cit->second.lang());
254 fl_addto_choice(language_->choice_quotes_language,
255 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
256 " «text» | »text« "));
258 bc().addReadOnly (language_->choice_inputenc);
259 bc().addReadOnly (language_->choice_quotes_language);
260 bc().addReadOnly (language_->radio_single);
261 bc().addReadOnly (language_->radio_double);
263 // the document options form
264 options_.reset(build_doc_options());
265 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
266 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
267 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
268 fl_set_counter_step(options_->slider_secnumdepth,1,1);
269 fl_set_counter_step(options_->slider_tocdepth,1,1);
270 fl_set_counter_precision(options_->slider_secnumdepth, 0);
271 fl_set_counter_precision(options_->slider_tocdepth, 0);
272 for (n=0; tex_graphics[n][0]; ++n) {
273 fl_addto_choice(options_->choice_postscript_driver,
276 fl_addto_choice(options_->choice_citation_format,
277 _(" Author-year | Numerical "));
279 bc_.addReadOnly (options_->slider_secnumdepth);
280 bc_.addReadOnly (options_->slider_tocdepth);
281 bc_.addReadOnly (options_->check_use_amsmath);
282 bc_.addReadOnly (options_->check_use_natbib);
283 bc_.addReadOnly (options_->choice_citation_format);
284 bc_.addReadOnly (options_->input_float_placement);
285 bc_.addReadOnly (options_->choice_postscript_driver);
287 // the document bullets form
288 bullets_.reset(build_doc_bullet());
289 fl_addto_choice(bullets_->choice_bullet_size,
290 _(" default | tiny | script | footnote | small |"
291 " normal | large | Large | LARGE | huge | Huge"));
292 fl_set_choice(bullets_->choice_bullet_size, 1);
293 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
294 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
296 bc().addReadOnly (bullets_->bmtable_bullet_panel);
297 bc().addReadOnly (bullets_->choice_bullet_size);
298 bc().addReadOnly (bullets_->input_bullet_latex);
299 bc().addReadOnly (bullets_->radio_bullet_depth);
300 bc().addReadOnly (bullets_->radio_bullet_panel);
302 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
304 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
306 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
308 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
310 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
312 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
313 lyxerr << _("Your version of libXpm is older than 4.7.\n"
314 "The `bullet' tab of the document dialog "
315 "has been disabled") << '\n';
316 fl_deactivate_object(fbullet);
317 fl_set_object_lcol(fbullet, FL_INACTIVE);
322 void FormDocument::apply()
324 if (!lv_->view()->available() || !dialog_.get())
327 bool redo = class_apply();
329 redo = language_apply() || redo;
330 redo = options_apply() || redo;
334 lv_->view()->redoCurrentBuffer();
336 lv_->buffer()->markDirty();
337 setMinibuffer(lv_, _("Document layout set"));
341 void FormDocument::cancel()
343 // this avoids confusion when reopening
344 BufferParams & param = lv_->buffer()->params;
345 param.temp_bullets[0] = param.user_defined_bullets[0];
346 param.temp_bullets[1] = param.user_defined_bullets[1];
347 param.temp_bullets[2] = param.user_defined_bullets[2];
348 param.temp_bullets[3] = param.user_defined_bullets[3];
353 void FormDocument::update()
360 BufferParams const & params = lv_->buffer()->params;
362 setEnabled(dialog_->button_reset_defaults,
363 !params.hasClassDefaults());
365 class_update(params);
366 paper_update(params);
367 language_update(params);
368 options_update(params);
369 bullets_update(params);
373 bool FormDocument::input( FL_OBJECT * ob, long data )
375 State cb = static_cast<State>( data );
378 case CHECKCHOICECLASS:
379 CheckChoiceClass(ob, 0);
381 case CHOICEBULLETSIZE:
382 ChoiceBulletSize(ob, 0);
384 case INPUTBULLETLATEX:
385 InputBulletLaTeX(ob, 0);
402 BulletBMTable(ob, 0);
408 bool const length_input = fl_get_choice(class_->choice_doc_skip) == 4;
409 if (ob == class_->choice_doc_skip) {
410 setEnabled(class_->input_doc_skip, length_input);
411 setEnabled(class_->choice_default_skip_units, length_input);
414 if (ob == class_->choice_doc_spacing)
415 setEnabled(class_->input_doc_spacing,
416 fl_get_choice(class_->choice_doc_spacing) == 4);
418 bool const skip_used = fl_get_button(class_->radio_doc_skip);
419 if (ob == class_->radio_doc_skip ||
420 ob == class_->radio_doc_indent) {
421 setEnabled(class_->choice_doc_skip, skip_used);
422 setEnabled(class_->input_doc_skip,
423 skip_used && length_input);
424 setEnabled(class_->choice_default_skip_units,
425 skip_used && length_input);
426 // Default unit choice is cm if metric, inches if US paper.
427 int const paperchoice = fl_get_choice(paper_->choice_papersize);
428 bool const metric = paperchoice < 3 || paperchoice > 5;
429 int const default_unit = metric ? 8 : 9;
430 if (strip(fl_get_input(class_->input_doc_skip)).empty())
431 fl_set_choice(class_->choice_default_skip_units,
435 if (ob == options_->check_use_natbib) {
436 setEnabled(options_->choice_citation_format,
437 fl_get_button(options_->check_use_natbib));
440 if (ob == dialog_->button_save_defaults) {
441 lv_->getLyXFunc()->dispatch(LFUN_LAYOUT_SAVE_DEFAULT);
444 if (ob == dialog_->button_reset_defaults) {
445 BufferParams params = lv_->buffer()->params;
446 params.textclass = combo_doc_class->get() - 1;
447 params.useClassDefaults();
448 UpdateLayoutDocument(params);
451 if (ob == paper_->radio_landscape)
452 fl_set_choice(paper_->choice_paperpackage,
453 BufferParams::PACKAGE_NONE + 1);
455 if (ob == paper_->choice_papersize) {
456 int const paperchoice = fl_get_choice(paper_->choice_papersize);
457 bool const custom = paperchoice == 2;
458 bool const a3size = paperchoice == 6;
459 bool const b3size = paperchoice == 9;
460 bool const b4size = paperchoice == 10;
463 fl_set_button(paper_->radio_portrait, 1);
465 bool const use_geom = (custom || a3size || b3size || b4size);
467 fl_set_button(paper_->check_use_geometry, int(use_geom));
469 setEnabled(paper_->input_top_margin, use_geom);
470 setEnabled(paper_->input_bottom_margin, use_geom);
471 setEnabled(paper_->input_left_margin, use_geom);
472 setEnabled(paper_->input_right_margin, use_geom);
473 setEnabled(paper_->input_head_height, use_geom);
474 setEnabled(paper_->input_head_sep, use_geom);
475 setEnabled(paper_->input_foot_skip, use_geom);
476 setEnabled(paper_->choice_top_margin_units, use_geom);
477 setEnabled(paper_->choice_bottom_margin_units, use_geom);
478 setEnabled(paper_->choice_left_margin_units, use_geom);
479 setEnabled(paper_->choice_right_margin_units, use_geom);
480 setEnabled(paper_->choice_head_height_units, use_geom);
481 setEnabled(paper_->choice_head_sep_units, use_geom);
482 setEnabled(paper_->choice_foot_skip_units, use_geom);
483 setEnabled(paper_->choice_custom_width_units, use_geom);
484 setEnabled(paper_->choice_custom_height_units, use_geom);
486 setEnabled(paper_->input_custom_width, custom);
487 setEnabled(paper_->input_custom_height, custom);
488 setEnabled(paper_->choice_custom_width_units, custom);
489 setEnabled(paper_->choice_custom_height_units, custom);
490 setEnabled(paper_->radio_portrait, !custom);
491 setEnabled(paper_->radio_landscape, !custom);
493 // Default unit choice is cm if metric, inches if US paper.
494 bool const metric = paperchoice < 3 || paperchoice > 5;
495 int const default_unit = metric ? 8 : 9;
496 if (strip(fl_get_input(paper_->input_custom_width)).empty())
497 fl_set_choice(paper_->choice_custom_width_units,
499 if (strip(fl_get_input(paper_->input_custom_height)).empty())
500 fl_set_choice(paper_->choice_custom_height_units,
502 if (strip(fl_get_input(paper_->input_top_margin)).empty())
503 fl_set_choice(paper_->choice_top_margin_units,
505 if (strip(fl_get_input(paper_->input_bottom_margin)).empty())
506 fl_set_choice(paper_->choice_bottom_margin_units,
508 if (strip(fl_get_input(paper_->input_left_margin)).empty())
509 fl_set_choice(paper_->choice_left_margin_units,
511 if (strip(fl_get_input(paper_->input_right_margin)).empty())
512 fl_set_choice(paper_->choice_right_margin_units,
514 if (strip(fl_get_input(paper_->input_head_height)).empty())
515 fl_set_choice(paper_->choice_head_height_units,
517 if (strip(fl_get_input(paper_->input_head_sep)).empty())
518 fl_set_choice(paper_->choice_head_sep_units,
520 if (strip(fl_get_input(paper_->input_foot_skip)).empty())
521 fl_set_choice(paper_->choice_foot_skip_units,
525 if (ob == paper_->choice_papersize ||
526 ob == paper_->radio_portrait ||
527 ob == paper_->radio_landscape) {
529 setEnabled(paper_->choice_paperpackage,
530 //either default papersize (preferences)
531 //or document papersize has to be A4
532 (fl_get_choice(paper_->choice_papersize) == 7
533 || fl_get_choice(paper_->choice_papersize) == 1
534 && lyxrc.default_papersize == 5)
535 && fl_get_button(paper_->radio_portrait));
538 if (ob == paper_->choice_paperpackage) {
539 if (fl_get_choice(paper_->choice_paperpackage) != 1) {
540 fl_set_button(paper_->check_use_geometry, 0);
542 setEnabled(paper_->input_top_margin, false);
543 setEnabled(paper_->input_bottom_margin, false);
544 setEnabled(paper_->input_left_margin, false);
545 setEnabled(paper_->input_right_margin, false);
546 setEnabled(paper_->input_head_height, false);
547 setEnabled(paper_->input_head_sep, false);
548 setEnabled(paper_->input_foot_skip, false);
549 setEnabled(paper_->choice_top_margin_units, false);
550 setEnabled(paper_->choice_bottom_margin_units, false);
551 setEnabled(paper_->choice_left_margin_units, false);
552 setEnabled(paper_->choice_right_margin_units, false);
553 setEnabled(paper_->choice_head_height_units, false);
554 setEnabled(paper_->choice_head_sep_units, false);
555 setEnabled(paper_->choice_foot_skip_units, false);
559 if (ob == paper_->check_use_geometry) {
560 //don't allow switching geometry off in custom papersize mode
561 //nor in A3, B3, and B4
562 int const choice = fl_get_choice(paper_->choice_papersize);
563 if (choice == 2 || choice == 6 || choice == 9 || choice == 10)
564 fl_set_button(paper_->check_use_geometry, 1);
566 fl_set_choice(paper_->choice_paperpackage,
567 BufferParams::PACKAGE_NONE + 1);
569 bool const use_geom = fl_get_button(paper_->check_use_geometry);
570 setEnabled(paper_->input_top_margin, use_geom);
571 setEnabled(paper_->input_bottom_margin, use_geom);
572 setEnabled(paper_->input_left_margin, use_geom);
573 setEnabled(paper_->input_right_margin, use_geom);
574 setEnabled(paper_->input_head_height, use_geom);
575 setEnabled(paper_->input_head_sep, use_geom);
576 setEnabled(paper_->input_foot_skip, use_geom);
577 setEnabled(paper_->choice_top_margin_units, use_geom);
578 setEnabled(paper_->choice_bottom_margin_units, use_geom);
579 setEnabled(paper_->choice_left_margin_units, use_geom);
580 setEnabled(paper_->choice_right_margin_units, use_geom);
581 setEnabled(paper_->choice_head_height_units, use_geom);
582 setEnabled(paper_->choice_head_sep_units, use_geom);
583 setEnabled(paper_->choice_foot_skip_units, use_geom);
586 setEnabled(dialog_->button_reset_defaults,
587 lv_->buffer()->params.hasClassDefaults());
591 case CHECKCHOICECLASS:
592 case CHOICEBULLETSIZE:
593 case INPUTBULLETLATEX:
595 return CheckDocumentInput(ob, 0);
604 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
606 FormDocument * pre = static_cast<FormDocument*>(v);
607 if (combox == pre->combo_doc_class.get())
608 pre->CheckChoiceClass(0, 0);
609 pre->bc().valid(pre->CheckDocumentInput(0,0));
613 bool FormDocument::class_apply(BufferParams ¶ms)
617 // If default skip is a "Length" but there's no text in the
618 // input field, reset the kind to "Medskip", which is the default.
619 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
620 !*(fl_get_input (class_->input_doc_skip))) {
621 fl_set_choice (class_->choice_doc_skip, 2);
623 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
624 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
625 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
627 params.textclass = combo_doc_class->get() - 1;
629 BufferParams::PARSEP tmpsep = params.paragraph_separation;
630 if (fl_get_button(class_->radio_doc_indent))
631 params.paragraph_separation = BufferParams::PARSEP_INDENT;
633 params.paragraph_separation = BufferParams::PARSEP_SKIP;
634 if (tmpsep != params.paragraph_separation)
637 VSpace tmpdefskip = params.getDefSkip();
638 switch (fl_get_choice (class_->choice_doc_skip)) {
640 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
643 params.setDefSkip(VSpace(VSpace::MEDSKIP));
646 params.setDefSkip(VSpace(VSpace::BIGSKIP));
650 string const length =
651 getLengthFromWidgets(class_->input_doc_skip,
652 class_->choice_default_skip_units);
654 params.setDefSkip(VSpace(LyXGlueLength(length)));
658 // DocumentDefskipCB assures that this never happens
659 params.setDefSkip(VSpace(VSpace::MEDSKIP));
662 if (!(tmpdefskip == params.getDefSkip()))
665 if (fl_get_button(class_->radio_doc_columns_two))
669 if (fl_get_button(class_->radio_doc_sides_two))
670 params.sides = LyXTextClass::TwoSides;
672 params.sides = LyXTextClass::OneSide;
674 Spacing tmpSpacing = params.spacing;
675 switch (fl_get_choice(class_->choice_doc_spacing)) {
677 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
678 params.spacing.set(Spacing::Single);
681 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
682 params.spacing.set(Spacing::Onehalf);
685 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
686 params.spacing.set(Spacing::Double);
689 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
690 params.spacing.set(Spacing::Other,
691 fl_get_input(class_->input_doc_spacing));
694 if (tmpSpacing != params.spacing)
697 params.options = fl_get_input(class_->input_doc_extra);
703 bool FormDocument::class_apply()
705 BufferParams ¶ms = lv_->buffer()->params;
707 unsigned int const old_class = params.textclass;
709 bool redo = class_apply(params);
711 if (params.textclass != old_class) {
712 // try to load new_class
713 if (textclasslist.Load(params.textclass)) {
714 // successfully loaded
716 setMinibuffer(lv_, _("Converting document to new document class..."));
717 int ret = CutAndPaste::SwitchLayoutsBetweenClasses(
718 old_class, params.textclass,
719 lv_->buffer()->paragraph);
723 s = _("One paragraph couldn't be converted");
726 s += _(" paragraphs couldn't be converted");
728 WriteAlert(_("Conversion Errors!"),s,
729 _("into chosen document class"));
733 // problem changing class -- warn user and retain old style
734 WriteAlert(_("Conversion Errors!"),
735 _("Errors loading new document class."),
736 _("Reverting to original document class."));
737 combo_doc_class->select(int(old_class) + 1);
745 void FormDocument::paper_apply(BufferParams & params)
747 params.papersize2 = char(fl_get_choice(paper_->choice_papersize)-1);
749 params.paperpackage =
750 char(fl_get_choice(paper_->choice_paperpackage)-1);
752 // set params.papersize from params.papersize2 and params.paperpackage
753 params.setPaperStuff();
755 params.use_geometry = fl_get_button(paper_->check_use_geometry);
757 if (fl_get_button(paper_->radio_landscape))
758 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
760 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
763 getLengthFromWidgets(paper_->input_custom_width,
764 paper_->choice_custom_width_units);
767 getLengthFromWidgets(paper_->input_custom_height,
768 paper_->choice_custom_height_units);
771 getLengthFromWidgets(paper_->input_left_margin,
772 paper_->choice_left_margin_units);
775 getLengthFromWidgets(paper_->input_top_margin,
776 paper_->choice_top_margin_units);
779 getLengthFromWidgets(paper_->input_right_margin,
780 paper_->choice_right_margin_units);
782 params.bottommargin =
783 getLengthFromWidgets(paper_->input_bottom_margin,
784 paper_->choice_bottom_margin_units);
787 getLengthFromWidgets(paper_->input_head_height,
788 paper_->choice_head_height_units);
791 getLengthFromWidgets(paper_->input_head_sep,
792 paper_->choice_head_sep_units);
795 getLengthFromWidgets(paper_->input_foot_skip,
796 paper_->choice_foot_skip_units);
800 void FormDocument::paper_apply()
802 paper_apply(lv_->buffer()->params);
806 bool FormDocument::language_apply(BufferParams & params)
808 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
811 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
813 lga = InsetQuotes::EnglishQ;
816 lga = InsetQuotes::SwedishQ;
819 lga = InsetQuotes::GermanQ;
822 lga = InsetQuotes::PolishQ;
825 lga = InsetQuotes::FrenchQ;
828 lga = InsetQuotes::DanishQ;
831 params.quotes_language = lga;
832 if (fl_get_button(language_->radio_single))
833 params.quotes_times = InsetQuotes::SingleQ;
835 params.quotes_times = InsetQuotes::DoubleQ;
837 Language const * new_language =
838 languages.getLanguage(combo_language->getline());
840 new_language = default_language;
842 params.language = new_language;
843 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
849 bool FormDocument::language_apply()
851 BufferParams & params = lv_->buffer()->params;
852 Language const * old_language = params.language;
854 bool redo = language_apply(params);
856 if (old_language != params.language
857 && old_language->RightToLeft() == params.language->RightToLeft()
858 && !lv_->buffer()->isMultiLingual())
859 lv_->buffer()->changeLanguage(old_language, params.language);
860 if (old_language != params.language) {
868 bool FormDocument::options_apply(BufferParams & params)
872 params.graphicsDriver =
873 fl_get_choice_text(options_->choice_postscript_driver);
874 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
875 params.use_natbib = fl_get_button(options_->check_use_natbib);
876 params.use_numerical_citations =
877 fl_get_choice(options_->choice_citation_format)-1;
879 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
880 if (params.secnumdepth != tmpchar)
882 params.secnumdepth = tmpchar;
884 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
886 params.float_placement =
887 fl_get_input(options_->input_float_placement);
893 bool FormDocument::options_apply()
895 return options_apply(lv_->buffer()->params);
899 void FormDocument::bullets_apply(BufferParams & params)
901 /* update the bullet settings */
902 BufferParams & params_doc = lv_->buffer()->params;
904 // a little bit of loop unrolling
905 params.user_defined_bullets[0] = params_doc.temp_bullets[0];
906 params.user_defined_bullets[1] = params_doc.temp_bullets[1];
907 params.user_defined_bullets[2] = params_doc.temp_bullets[2];
908 params.user_defined_bullets[3] = params_doc.temp_bullets[3];
912 void FormDocument::bullets_apply()
914 bullets_apply(lv_->buffer()->params);
918 void FormDocument::class_update(BufferParams const & params)
923 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
925 combo_doc_class->select(
926 textclasslist.DescOfClass(params.textclass));
927 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
928 fl_clear_choice(class_->choice_doc_fontsize);
929 fl_addto_choice(class_->choice_doc_fontsize, "default");
930 fl_addto_choice(class_->choice_doc_fontsize,
931 tclass.opt_fontsize().c_str());
932 fl_set_choice(class_->choice_doc_fontsize,
933 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
934 fl_clear_choice(class_->choice_doc_pagestyle);
935 fl_addto_choice(class_->choice_doc_pagestyle, "default");
936 fl_addto_choice(class_->choice_doc_pagestyle,
937 tclass.opt_pagestyle().c_str());
938 fl_set_choice(class_->choice_doc_pagestyle,
939 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
940 fl_set_button(class_->radio_doc_indent, 0);
941 fl_set_button(class_->radio_doc_skip, 0);
942 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
943 fl_set_button(class_->radio_doc_indent, 1);
945 fl_set_button(class_->radio_doc_skip, 1);
947 bool const input_length = fl_get_choice(class_->choice_doc_skip) == 4;
948 setEnabled(class_->choice_default_skip_units, input_length);
949 setEnabled(class_->input_doc_skip, input_length);
951 switch (params.getDefSkip().kind()) {
952 case VSpace::SMALLSKIP:
953 fl_set_choice (class_->choice_doc_skip, 1);
955 case VSpace::MEDSKIP:
956 fl_set_choice (class_->choice_doc_skip, 2);
958 case VSpace::BIGSKIP:
959 fl_set_choice (class_->choice_doc_skip, 3);
963 int const paperchoice = params.papersize2 + 1;
964 bool const metric = paperchoice < 3 || paperchoice > 5;
965 string const default_unit = metric ? "cm" : "in";
966 string const length = params.getDefSkip().asLyXCommand();
967 updateWidgetsFromLengthString(class_->input_doc_skip,
968 class_->choice_default_skip_units,
969 length, default_unit);
973 fl_set_choice (class_->choice_doc_skip, 2);
976 fl_set_button(class_->radio_doc_sides_one, 0);
977 fl_set_button(class_->radio_doc_sides_two, 0);
978 setEnabled(class_->choice_doc_skip,
979 fl_get_button(class_->radio_doc_skip));
981 if (params.sides == LyXTextClass::TwoSides)
982 fl_set_button(class_->radio_doc_sides_two, 1);
984 fl_set_button(class_->radio_doc_sides_one, 1);
985 fl_set_button(class_->radio_doc_columns_one, 0);
986 fl_set_button(class_->radio_doc_columns_two, 0);
987 if (params.columns == 2)
988 fl_set_button(class_->radio_doc_columns_two, 1);
990 fl_set_button(class_->radio_doc_columns_one, 1);
991 fl_set_input(class_->input_doc_spacing, "");
993 setEnabled(class_->input_doc_spacing, input_length);
995 switch (params.spacing.getSpace()) {
996 case Spacing::Default: // nothing bad should happen with this
997 case Spacing::Single:
999 fl_set_choice(class_->choice_doc_spacing, 1);
1001 case Spacing::Onehalf:
1003 fl_set_choice(class_->choice_doc_spacing, 2);
1005 case Spacing::Double:
1007 fl_set_choice(class_->choice_doc_spacing, 3);
1009 case Spacing::Other:
1011 fl_set_choice(class_->choice_doc_spacing, 4);
1013 sprintf(sval,"%g",params.spacing.getValue());
1014 fl_set_input(class_->input_doc_spacing, sval);
1018 if (!params.options.empty())
1019 fl_set_input(class_->input_doc_extra, params.options.c_str());
1021 fl_set_input(class_->input_doc_extra, "");
1025 void FormDocument::language_update(BufferParams const & params)
1027 if (!language_.get())
1030 combo_language->select(params.language->lang());
1031 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
1032 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
1033 fl_set_button(language_->radio_single, 0);
1034 fl_set_button(language_->radio_double, 0);
1035 if (params.quotes_times == InsetQuotes::SingleQ)
1036 fl_set_button(language_->radio_single, 1);
1038 fl_set_button(language_->radio_double, 1);
1042 void FormDocument::options_update(BufferParams const & params)
1044 if (!options_.get())
1047 fl_set_choice_text(options_->choice_postscript_driver,
1048 params.graphicsDriver.c_str());
1049 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
1050 fl_set_button(options_->check_use_natbib, params.use_natbib);
1051 fl_set_choice(options_->choice_citation_format,
1052 int(params.use_numerical_citations)+1);
1053 setEnabled(options_->choice_citation_format, params.use_natbib);
1054 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
1055 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
1056 if (!params.float_placement.empty())
1057 fl_set_input(options_->input_float_placement,
1058 params.float_placement.c_str());
1060 fl_set_input(options_->input_float_placement, "");
1064 void FormDocument::paper_update(BufferParams const & params)
1069 fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
1070 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
1071 fl_set_button(paper_->check_use_geometry, params.use_geometry);
1073 int const paperchoice = fl_get_choice(paper_->choice_papersize);
1074 bool const useCustom = paperchoice == 2;
1075 bool const useGeom = fl_get_button(paper_->check_use_geometry);
1077 fl_set_button(paper_->radio_portrait, 0);
1078 setEnabled(paper_->radio_portrait, !useCustom);
1079 fl_set_button(paper_->radio_landscape, 0);
1080 setEnabled(paper_->radio_landscape, !useCustom);
1082 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1083 fl_set_button(paper_->radio_landscape, 1);
1085 fl_set_button(paper_->radio_portrait, 1);
1086 setEnabled(paper_->choice_paperpackage,
1087 //either default papersize (preferences)
1088 //or document papersize has to be A4
1090 || paperchoice == 1 && lyxrc.default_papersize == 5)
1091 && fl_get_button(paper_->radio_portrait));
1093 // Default unit choice is cm if metric, inches if US paper.
1094 bool const metric = paperchoice < 3 || paperchoice > 5;
1095 string const default_unit = metric ? "cm" : "in";
1096 updateWidgetsFromLengthString(paper_->input_custom_width,
1097 paper_->choice_custom_width_units,
1098 params.paperwidth, default_unit);
1099 setEnabled(paper_->input_custom_width, useCustom);
1100 setEnabled(paper_->choice_custom_width_units, useCustom);
1102 updateWidgetsFromLengthString(paper_->input_custom_height,
1103 paper_->choice_custom_height_units,
1104 params.paperheight, default_unit);
1105 setEnabled(paper_->input_custom_height, useCustom);
1106 setEnabled(paper_->choice_custom_height_units, useCustom);
1108 updateWidgetsFromLengthString(paper_->input_left_margin,
1109 paper_->choice_left_margin_units,
1110 params.leftmargin, default_unit);
1111 setEnabled(paper_->input_left_margin, useGeom);
1112 setEnabled(paper_->choice_left_margin_units, useGeom);
1114 updateWidgetsFromLengthString(paper_->input_top_margin,
1115 paper_->choice_top_margin_units,
1116 params.topmargin, default_unit);
1117 setEnabled(paper_->input_top_margin, useGeom);
1118 setEnabled(paper_->choice_top_margin_units, useGeom);
1120 updateWidgetsFromLengthString(paper_->input_right_margin,
1121 paper_->choice_right_margin_units,
1122 params.rightmargin, default_unit);
1123 setEnabled(paper_->input_right_margin, useGeom);
1124 setEnabled(paper_->choice_right_margin_units, useGeom);
1126 updateWidgetsFromLengthString(paper_->input_bottom_margin,
1127 paper_->choice_bottom_margin_units,
1128 params.bottommargin, default_unit);
1129 setEnabled(paper_->input_bottom_margin, useGeom);
1130 setEnabled(paper_->choice_bottom_margin_units, useGeom);
1132 updateWidgetsFromLengthString(paper_->input_head_height,
1133 paper_->choice_head_height_units,
1134 params.headheight, default_unit);
1135 setEnabled(paper_->input_head_height, useGeom);
1136 setEnabled(paper_->choice_head_height_units, useGeom);
1138 updateWidgetsFromLengthString(paper_->input_head_sep,
1139 paper_->choice_head_sep_units,
1140 params.headsep, default_unit);
1141 setEnabled(paper_->input_head_sep, useGeom);
1142 setEnabled(paper_->choice_head_sep_units, useGeom);
1144 updateWidgetsFromLengthString(paper_->input_foot_skip,
1145 paper_->choice_foot_skip_units,
1146 params.footskip, default_unit);
1147 setEnabled(paper_->input_foot_skip, useGeom);
1148 setEnabled(paper_->choice_foot_skip_units, useGeom);
1150 fl_set_focus_object(paper_->form, paper_->choice_papersize);
1154 void FormDocument::bullets_update(BufferParams const & params)
1156 if (!bullets_.get() ||
1158 (XpmVersion==4 && XpmRevision<7)))
1161 bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
1162 setEnabled(fbullet, !isLinuxDoc);
1164 if (isLinuxDoc) return;
1166 fl_set_button(bullets_->radio_bullet_depth_1, 1);
1167 fl_set_input(bullets_->input_bullet_latex,
1168 params.user_defined_bullets[0].getText().c_str());
1169 fl_set_choice(bullets_->choice_bullet_size,
1170 params.user_defined_bullets[0].getSize() + 2);
1174 void FormDocument::checkReadOnly()
1176 if (bc().readOnly(lv_->buffer()->isReadonly())) {
1177 combo_doc_class->deactivate();
1178 combo_language->deactivate();
1179 fl_set_object_label(dialog_->text_warning,
1180 _("Document is read-only."
1181 " No changes to layout permitted."));
1182 fl_show_object(dialog_->text_warning);
1184 combo_doc_class->activate();
1185 combo_language->activate();
1186 fl_hide_object(dialog_->text_warning);
1191 bool FormDocument::CheckDocumentInput(FL_OBJECT *, long)
1197 // "Synchronize" the choice and the input field, so that it
1198 // is impossible to commit senseless data.
1199 input = fl_get_input (class_->input_doc_skip);
1200 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
1202 else if (fl_get_choice(class_->choice_doc_skip) != 4)
1203 fl_set_input (class_->input_doc_skip, "");
1205 input = fl_get_input(class_->input_doc_spacing);
1206 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
1208 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
1209 fl_set_input (class_->input_doc_spacing, "");
1214 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
1216 BufferParams & param = lv_->buffer()->params;
1218 // convert from 1-6 range to -1-4
1219 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1220 fl_set_input(bullets_->input_bullet_latex,
1221 param.temp_bullets[current_bullet_depth].getText().c_str());
1225 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1227 BufferParams & param = lv_->buffer()->params;
1229 param.temp_bullets[current_bullet_depth].
1230 setText(fl_get_input(bullets_->input_bullet_latex));
1234 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
1236 /* Should I do the following: */
1237 /* 1. change to the panel that the current bullet belongs in */
1238 /* 2. show that bullet as selected */
1239 /* 3. change the size setting to the size of the bullet in Q.*/
1240 /* 4. display the latex equivalent in the latex box */
1242 /* I'm inclined to just go with 3 and 4 at the moment and */
1243 /* maybe try to support the others later */
1244 BufferParams & param = lv_->buffer()->params;
1247 if (cb == BULLETDEPTH1 )
1249 else if (cb == BULLETDEPTH2 )
1251 else if (cb == BULLETDEPTH3 )
1253 else if (cb == BULLETDEPTH4 )
1256 switch (fl_get_button_numb(ob)) {
1258 // right mouse button resets to default
1259 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1261 current_bullet_depth = data;
1262 fl_set_input(bullets_->input_bullet_latex,
1263 param.temp_bullets[data].getText().c_str());
1264 fl_set_choice(bullets_->choice_bullet_size,
1265 param.temp_bullets[data].getSize() + 2);
1270 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
1272 /* Here we have to change the background pixmap to that selected */
1273 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1276 if (cb == BULLETPANEL1 )
1278 else if (cb == BULLETPANEL2 )
1280 else if (cb == BULLETPANEL3 )
1282 else if (cb == BULLETPANEL4 )
1284 else if (cb == BULLETPANEL5 )
1286 else if (cb == BULLETPANEL6 )
1289 if (data != current_bullet_panel) {
1290 fl_freeze_form(bullets_->form);
1291 current_bullet_panel = data;
1293 /* free the current pixmap */
1294 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1297 /* display the new one */
1299 new_panel = "standard";
1302 new_panel = "amssymb";
1305 new_panel = "psnfss1";
1308 new_panel = "psnfss2";
1311 new_panel = "psnfss3";
1314 new_panel = "psnfss4";
1317 /* something very wrong happened */
1318 // play it safe for now but should be an exception
1319 current_bullet_panel = 0; // standard panel
1320 new_panel = "standard";
1323 new_panel += ".xpm";
1324 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1325 LibFileSearch("images", new_panel).c_str());
1326 fl_redraw_object(bullets_->bmtable_bullet_panel);
1327 fl_unfreeze_form(bullets_->form);
1332 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1334 /* handle the user input by setting the current bullet depth's pixmap */
1335 /* to that extracted from the current chosen position of the BMTable */
1336 /* Don't forget to free the button's old pixmap first. */
1338 BufferParams & param = lv_->buffer()->params;
1339 int bmtable_button = fl_get_bmtable(ob);
1341 /* try to keep the button held down till another is pushed */
1342 /* fl_set_bmtable(ob, 1, bmtable_button); */
1343 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1344 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1345 fl_set_input(bullets_->input_bullet_latex,
1346 param.temp_bullets[current_bullet_depth].getText().c_str());
1350 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1353 ob = class_->choice_doc_class;
1355 lv_->prohibitInput();
1357 unsigned int tc = combo_doc_class->get() - 1;
1358 if (textclasslist.Load(tc)) {
1359 // we use a copy of the bufferparams because we do not
1360 // want to modify them yet.
1361 BufferParams params = lv_->buffer()->params;
1363 if (lyxrc.auto_reset_options) {
1364 params.textclass = tc;
1365 params.useClassDefaults();
1366 UpdateLayoutDocument(params);
1369 // unable to load new style
1370 WriteAlert(_("Conversion Errors!"),
1371 _("Unable to switch to new document class."),
1372 _("Reverting to original document class."));
1373 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1379 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1385 class_update(params);
1386 paper_update(params);
1387 language_update(params);
1388 options_update(params);
1389 bullets_update(params);