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_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
207 fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
208 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
210 bc().addReadOnly (class_->radio_doc_indent);
211 bc().addReadOnly (class_->radio_doc_skip);
213 bc().addReadOnly (class_->choice_doc_pagestyle);
214 bc().addReadOnly (class_->choice_doc_fonts);
215 bc().addReadOnly (class_->choice_doc_fontsize);
216 bc().addReadOnly (class_->radio_doc_sides_one);
217 bc().addReadOnly (class_->radio_doc_sides_two);
218 bc().addReadOnly (class_->radio_doc_columns_one);
219 bc().addReadOnly (class_->radio_doc_columns_two);
220 bc().addReadOnly (class_->input_doc_extra);
221 bc().addReadOnly (class_->input_doc_skip);
222 bc().addReadOnly (class_->choice_doc_skip);
223 bc().addReadOnly (class_->choice_doc_spacing);
224 bc().addReadOnly (class_->input_doc_spacing);
226 // the document language form
227 language_.reset(build_doc_language());
228 fl_addto_choice(language_->choice_inputenc,
229 "default|auto|latin1|latin2|latin3|latin4|latin5|latin9"
230 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
232 // The language is a combo-box and has to be inserted manually
233 obj = language_->choice_language;
234 fl_deactivate_object(obj);
235 fl_addto_form(language_->form);
236 combo_language.reset(new Combox(FL_COMBOX_DROPLIST));
237 combo_language->add(obj->x, obj->y, obj->w, obj->h, 400,
238 dialog_->tabbed_folder);
239 combo_language->shortcut("#L",1);
240 combo_language->setcallback(ComboInputCB, this);
243 for (Languages::const_iterator cit = languages.begin();
244 cit != languages.end(); ++cit) {
245 combo_language->addto(cit->second.lang());
248 fl_addto_choice(language_->choice_quotes_language,
249 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
250 " «text» | »text« "));
252 bc().addReadOnly (language_->choice_inputenc);
253 bc().addReadOnly (language_->choice_quotes_language);
254 bc().addReadOnly (language_->radio_single);
255 bc().addReadOnly (language_->radio_double);
257 // the document options form
258 options_.reset(build_doc_options());
259 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
260 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
261 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
262 fl_set_counter_step(options_->slider_secnumdepth,1,1);
263 fl_set_counter_step(options_->slider_tocdepth,1,1);
264 fl_set_counter_precision(options_->slider_secnumdepth, 0);
265 fl_set_counter_precision(options_->slider_tocdepth, 0);
266 for (n=0; tex_graphics[n][0]; ++n) {
267 fl_addto_choice(options_->choice_postscript_driver,
270 fl_addto_choice(options_->choice_citation_format,
271 _(" Author-year | Numerical "));
273 bc_.addReadOnly (options_->slider_secnumdepth);
274 bc_.addReadOnly (options_->slider_tocdepth);
275 bc_.addReadOnly (options_->check_use_amsmath);
276 bc_.addReadOnly (options_->check_use_natbib);
277 bc_.addReadOnly (options_->choice_citation_format);
278 bc_.addReadOnly (options_->input_float_placement);
279 bc_.addReadOnly (options_->choice_postscript_driver);
281 // the document bullets form
282 bullets_.reset(build_doc_bullet());
283 fl_addto_choice(bullets_->choice_bullet_size,
284 _(" default | tiny | script | footnote | small |"
285 " normal | large | Large | LARGE | huge | Huge"));
286 fl_set_choice(bullets_->choice_bullet_size, 1);
287 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
288 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
290 bc().addReadOnly (bullets_->bmtable_bullet_panel);
291 bc().addReadOnly (bullets_->choice_bullet_size);
292 bc().addReadOnly (bullets_->input_bullet_latex);
293 bc().addReadOnly (bullets_->radio_bullet_depth);
294 bc().addReadOnly (bullets_->radio_bullet_panel);
296 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
298 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
300 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
302 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
304 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
306 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
307 lyxerr << _("Your version of libXpm is older than 4.7.\n"
308 "The `bullet' tab of the document dialog "
309 "has been disabled") << '\n';
310 fl_deactivate_object(fbullet);
311 fl_set_object_lcol(fbullet, FL_INACTIVE);
316 void FormDocument::apply()
318 if (!lv_->view()->available() || !dialog_.get())
321 bool redo = class_apply();
323 redo = language_apply() || redo;
324 redo = options_apply() || redo;
328 lv_->view()->redoCurrentBuffer();
330 lv_->buffer()->markDirty();
331 setMinibuffer(lv_, _("Document layout set"));
335 void FormDocument::cancel()
337 // this avoids confusion when reopening
338 BufferParams & param = lv_->buffer()->params;
339 param.temp_bullets[0] = param.user_defined_bullets[0];
340 param.temp_bullets[1] = param.user_defined_bullets[1];
341 param.temp_bullets[2] = param.user_defined_bullets[2];
342 param.temp_bullets[3] = param.user_defined_bullets[3];
347 void FormDocument::update()
354 BufferParams const & params = lv_->buffer()->params;
356 setEnabled(dialog_->button_reset_defaults,
357 !params.hasClassDefaults());
359 class_update(params);
360 paper_update(params);
361 language_update(params);
362 options_update(params);
363 bullets_update(params);
367 bool FormDocument::input( FL_OBJECT * ob, long data )
369 State cb = static_cast<State>( data );
372 case CHECKCHOICECLASS:
373 CheckChoiceClass(ob, 0);
375 case CHOICEBULLETSIZE:
376 ChoiceBulletSize(ob, 0);
378 case INPUTBULLETLATEX:
379 InputBulletLaTeX(ob, 0);
396 BulletBMTable(ob, 0);
402 if (ob == options_->check_use_natbib) {
403 setEnabled(options_->choice_citation_format,
404 fl_get_button(options_->check_use_natbib));
407 if (ob == dialog_->button_save_defaults) {
408 lv_->getLyXFunc()->dispatch(LFUN_LAYOUT_SAVE_DEFAULT);
411 if (ob == dialog_->button_reset_defaults) {
412 BufferParams params = lv_->buffer()->params;
413 params.textclass = combo_doc_class->get() - 1;
414 params.useClassDefaults();
415 UpdateLayoutDocument(params);
418 if (ob == paper_->radio_landscape)
419 fl_set_choice(paper_->choice_paperpackage,
420 BufferParams::PACKAGE_NONE + 1);
422 if (ob == paper_->choice_papersize) {
423 int const paperchoice = fl_get_choice(paper_->choice_papersize);
424 bool const custom = paperchoice == 2;
425 bool const a3size = paperchoice == 6;
426 bool const b3size = paperchoice == 9;
427 bool const b4size = paperchoice == 10;
430 fl_set_button(paper_->radio_portrait, 1);
432 bool const use_geom = (custom || a3size || b3size || b4size);
434 fl_set_button(paper_->check_use_geometry, int(use_geom));
436 setEnabled(paper_->input_top_margin, use_geom);
437 setEnabled(paper_->input_bottom_margin, use_geom);
438 setEnabled(paper_->input_left_margin, use_geom);
439 setEnabled(paper_->input_right_margin, use_geom);
440 setEnabled(paper_->input_head_height, use_geom);
441 setEnabled(paper_->input_head_sep, use_geom);
442 setEnabled(paper_->input_foot_skip, use_geom);
443 setEnabled(paper_->choice_top_margin_units, use_geom);
444 setEnabled(paper_->choice_bottom_margin_units, use_geom);
445 setEnabled(paper_->choice_left_margin_units, use_geom);
446 setEnabled(paper_->choice_right_margin_units, use_geom);
447 setEnabled(paper_->choice_head_height_units, use_geom);
448 setEnabled(paper_->choice_head_sep_units, use_geom);
449 setEnabled(paper_->choice_foot_skip_units, use_geom);
450 setEnabled(paper_->choice_custom_width_units, use_geom);
451 setEnabled(paper_->choice_custom_height_units, use_geom);
453 setEnabled(paper_->input_custom_width, custom);
454 setEnabled(paper_->input_custom_height, custom);
455 setEnabled(paper_->choice_custom_width_units, custom);
456 setEnabled(paper_->choice_custom_height_units, custom);
457 setEnabled(paper_->radio_portrait, !custom);
458 setEnabled(paper_->radio_landscape, !custom);
460 // Default unit choice is cm if metric, inches if US paper.
461 bool const metric = paperchoice < 3 || paperchoice > 5;
462 int const default_unit = metric ? 8 : 9;
463 if (strip(fl_get_input(paper_->input_custom_width)).empty())
464 fl_set_choice(paper_->choice_custom_width_units,
466 if (strip(fl_get_input(paper_->input_custom_height)).empty())
467 fl_set_choice(paper_->choice_custom_height_units,
469 if (strip(fl_get_input(paper_->input_top_margin)).empty())
470 fl_set_choice(paper_->choice_top_margin_units,
472 if (strip(fl_get_input(paper_->input_bottom_margin)).empty())
473 fl_set_choice(paper_->choice_bottom_margin_units,
475 if (strip(fl_get_input(paper_->input_left_margin)).empty())
476 fl_set_choice(paper_->choice_left_margin_units,
478 if (strip(fl_get_input(paper_->input_right_margin)).empty())
479 fl_set_choice(paper_->choice_right_margin_units,
481 if (strip(fl_get_input(paper_->input_head_height)).empty())
482 fl_set_choice(paper_->choice_head_height_units,
484 if (strip(fl_get_input(paper_->input_head_sep)).empty())
485 fl_set_choice(paper_->choice_head_sep_units,
487 if (strip(fl_get_input(paper_->input_foot_skip)).empty())
488 fl_set_choice(paper_->choice_foot_skip_units,
492 if (ob == paper_->choice_papersize ||
493 ob == paper_->radio_portrait ||
494 ob == paper_->radio_landscape) {
496 setEnabled(paper_->choice_paperpackage,
497 //either default papersize (preferences)
498 //or document papersize has to be A4
499 (fl_get_choice(paper_->choice_papersize) == 7
500 || fl_get_choice(paper_->choice_papersize) == 1
501 && lyxrc.default_papersize == 5)
502 && fl_get_button(paper_->radio_portrait));
505 if (ob == paper_->choice_paperpackage) {
506 if (fl_get_choice(paper_->choice_paperpackage) != 1) {
507 fl_set_button(paper_->check_use_geometry, 0);
509 setEnabled(paper_->input_top_margin, false);
510 setEnabled(paper_->input_bottom_margin, false);
511 setEnabled(paper_->input_left_margin, false);
512 setEnabled(paper_->input_right_margin, false);
513 setEnabled(paper_->input_head_height, false);
514 setEnabled(paper_->input_head_sep, false);
515 setEnabled(paper_->input_foot_skip, false);
516 setEnabled(paper_->choice_top_margin_units, false);
517 setEnabled(paper_->choice_bottom_margin_units, false);
518 setEnabled(paper_->choice_left_margin_units, false);
519 setEnabled(paper_->choice_right_margin_units, false);
520 setEnabled(paper_->choice_head_height_units, false);
521 setEnabled(paper_->choice_head_sep_units, false);
522 setEnabled(paper_->choice_foot_skip_units, false);
526 if (ob == paper_->check_use_geometry) {
527 //don't allow switching geometry off in custom papersize mode
528 //nor in A3, B3, and B4
529 int const choice = fl_get_choice(paper_->choice_papersize);
530 if (choice == 2 || choice == 6 || choice == 9 || choice == 10)
531 fl_set_button(paper_->check_use_geometry, 1);
533 fl_set_choice(paper_->choice_paperpackage,
534 BufferParams::PACKAGE_NONE + 1);
536 bool const use_geom = fl_get_button(paper_->check_use_geometry);
537 setEnabled(paper_->input_top_margin, use_geom);
538 setEnabled(paper_->input_bottom_margin, use_geom);
539 setEnabled(paper_->input_left_margin, use_geom);
540 setEnabled(paper_->input_right_margin, use_geom);
541 setEnabled(paper_->input_head_height, use_geom);
542 setEnabled(paper_->input_head_sep, use_geom);
543 setEnabled(paper_->input_foot_skip, use_geom);
544 setEnabled(paper_->choice_top_margin_units, use_geom);
545 setEnabled(paper_->choice_bottom_margin_units, use_geom);
546 setEnabled(paper_->choice_left_margin_units, use_geom);
547 setEnabled(paper_->choice_right_margin_units, use_geom);
548 setEnabled(paper_->choice_head_height_units, use_geom);
549 setEnabled(paper_->choice_head_sep_units, use_geom);
550 setEnabled(paper_->choice_foot_skip_units, use_geom);
553 setEnabled(dialog_->button_reset_defaults,
554 lv_->buffer()->params.hasClassDefaults());
558 case CHECKCHOICECLASS:
559 case CHOICEBULLETSIZE:
560 case INPUTBULLETLATEX:
562 return CheckDocumentInput(ob, 0);
571 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
573 FormDocument * pre = static_cast<FormDocument*>(v);
574 if (combox == pre->combo_doc_class.get())
575 pre->CheckChoiceClass(0, 0);
576 pre->bc().valid(pre->CheckDocumentInput(0,0));
580 bool FormDocument::class_apply()
583 BufferParams ¶ms = lv_->buffer()->params;
585 // If default skip is a "Length" but there's no text in the
586 // input field, reset the kind to "Medskip", which is the default.
587 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
588 !*(fl_get_input (class_->input_doc_skip))) {
589 fl_set_choice (class_->choice_doc_skip, 2);
591 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
592 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
593 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
595 unsigned int const new_class = combo_doc_class->get() - 1;
597 if (params.textclass != new_class) {
598 // try to load new_class
599 if (textclasslist.Load(new_class)) {
600 // successfully loaded
602 setMinibuffer(lv_, _("Converting document to new document class..."));
603 int ret = CutAndPaste::SwitchLayoutsBetweenClasses(
604 params.textclass, new_class,
605 lv_->buffer()->paragraph);
609 s = _("One paragraph couldn't be converted");
612 s += _(" paragraphs couldn't be converted");
614 WriteAlert(_("Conversion Errors!"),s,
615 _("into chosen document class"));
618 params.textclass = new_class;
620 // problem changing class -- warn user and retain old style
621 WriteAlert(_("Conversion Errors!"),
622 _("Errors loading new document class."),
623 _("Reverting to original document class."));
624 combo_doc_class->select(int(params.textclass) + 1);
627 BufferParams::PARSEP tmpsep = params.paragraph_separation;
628 if (fl_get_button(class_->radio_doc_indent))
629 params.paragraph_separation = BufferParams::PARSEP_INDENT;
631 params.paragraph_separation = BufferParams::PARSEP_SKIP;
632 if (tmpsep != params.paragraph_separation)
635 VSpace tmpdefskip = params.getDefSkip();
636 switch (fl_get_choice (class_->choice_doc_skip)) {
638 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
641 params.setDefSkip(VSpace(VSpace::MEDSKIP));
644 params.setDefSkip(VSpace(VSpace::BIGSKIP));
648 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
650 // DocumentDefskipCB assures that this never happens
652 params.setDefSkip(VSpace(VSpace::MEDSKIP));
655 if (!(tmpdefskip == params.getDefSkip()))
658 if (fl_get_button(class_->radio_doc_columns_two))
662 if (fl_get_button(class_->radio_doc_sides_two))
663 params.sides = LyXTextClass::TwoSides;
665 params.sides = LyXTextClass::OneSide;
667 Spacing tmpSpacing = params.spacing;
668 switch (fl_get_choice(class_->choice_doc_spacing)) {
670 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
671 params.spacing.set(Spacing::Single);
674 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
675 params.spacing.set(Spacing::Onehalf);
678 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
679 params.spacing.set(Spacing::Double);
682 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
683 params.spacing.set(Spacing::Other,
684 fl_get_input(class_->input_doc_spacing));
687 if (tmpSpacing != params.spacing)
690 params.options = fl_get_input(class_->input_doc_extra);
696 void FormDocument::paper_apply()
698 BufferParams & params = lv_->buffer()->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 lv_->buffer()->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_left_margin,
725 paper_->choice_left_margin_units);
728 getLengthFromWidgets(paper_->input_top_margin,
729 paper_->choice_top_margin_units);
732 getLengthFromWidgets(paper_->input_right_margin,
733 paper_->choice_right_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()
755 BufferParams & params = lv_->buffer()->params;
756 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
759 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
761 lga = InsetQuotes::EnglishQ;
764 lga = InsetQuotes::SwedishQ;
767 lga = InsetQuotes::GermanQ;
770 lga = InsetQuotes::PolishQ;
773 lga = InsetQuotes::FrenchQ;
776 lga = InsetQuotes::DanishQ;
779 params.quotes_language = lga;
780 if (fl_get_button(language_->radio_single))
781 params.quotes_times = InsetQuotes::SingleQ;
783 params.quotes_times = InsetQuotes::DoubleQ;
785 Language const * old_language = params.language;
786 Language const * new_language =
787 languages.getLanguage(combo_language->getline());
789 new_language = default_language;
791 if (old_language != new_language
792 && old_language->RightToLeft() == new_language->RightToLeft()
793 && !lv_->buffer()->isMultiLingual())
794 lv_->buffer()->changeLanguage(old_language, new_language);
795 if (old_language != new_language) {
798 params.language = new_language;
799 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
805 bool FormDocument::options_apply()
807 BufferParams & params = lv_->buffer()->params;
810 params.graphicsDriver =
811 fl_get_choice_text(options_->choice_postscript_driver);
812 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
813 params.use_natbib = fl_get_button(options_->check_use_natbib);
814 params.use_numerical_citations =
815 fl_get_choice(options_->choice_citation_format)-1;
817 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
818 if (params.secnumdepth != tmpchar)
820 params.secnumdepth = tmpchar;
822 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
824 params.float_placement =
825 fl_get_input(options_->input_float_placement);
831 void FormDocument::bullets_apply()
833 /* update the bullet settings */
834 BufferParams & param = lv_->buffer()->params;
836 // a little bit of loop unrolling
837 param.user_defined_bullets[0] = param.temp_bullets[0];
838 param.user_defined_bullets[1] = param.temp_bullets[1];
839 param.user_defined_bullets[2] = param.temp_bullets[2];
840 param.user_defined_bullets[3] = param.temp_bullets[3];
844 void FormDocument::class_update(BufferParams const & params)
849 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
851 combo_doc_class->select(
852 textclasslist.DescOfClass(params.textclass));
853 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
854 fl_clear_choice(class_->choice_doc_fontsize);
855 fl_addto_choice(class_->choice_doc_fontsize, "default");
856 fl_addto_choice(class_->choice_doc_fontsize,
857 tclass.opt_fontsize().c_str());
858 fl_set_choice(class_->choice_doc_fontsize,
859 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
860 fl_clear_choice(class_->choice_doc_pagestyle);
861 fl_addto_choice(class_->choice_doc_pagestyle, "default");
862 fl_addto_choice(class_->choice_doc_pagestyle,
863 tclass.opt_pagestyle().c_str());
864 fl_set_choice(class_->choice_doc_pagestyle,
865 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
866 fl_set_button(class_->radio_doc_indent, 0);
867 fl_set_button(class_->radio_doc_skip, 0);
868 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
869 fl_set_button(class_->radio_doc_indent, 1);
871 fl_set_button(class_->radio_doc_skip, 1);
872 switch (params.getDefSkip().kind()) {
873 case VSpace::SMALLSKIP:
874 fl_set_choice (class_->choice_doc_skip, 1);
876 case VSpace::MEDSKIP:
877 fl_set_choice (class_->choice_doc_skip, 2);
879 case VSpace::BIGSKIP:
880 fl_set_choice (class_->choice_doc_skip, 3);
883 fl_set_choice (class_->choice_doc_skip, 4);
884 fl_set_input (class_->input_doc_skip,
885 params.getDefSkip().asLyXCommand().c_str());
888 fl_set_choice (class_->choice_doc_skip, 2);
891 fl_set_button(class_->radio_doc_sides_one, 0);
892 fl_set_button(class_->radio_doc_sides_two, 0);
893 if (params.sides == LyXTextClass::TwoSides)
894 fl_set_button(class_->radio_doc_sides_two, 1);
896 fl_set_button(class_->radio_doc_sides_one, 1);
897 fl_set_button(class_->radio_doc_columns_one, 0);
898 fl_set_button(class_->radio_doc_columns_two, 0);
899 if (params.columns == 2)
900 fl_set_button(class_->radio_doc_columns_two, 1);
902 fl_set_button(class_->radio_doc_columns_one, 1);
903 fl_set_input(class_->input_doc_spacing, "");
904 switch (params.spacing.getSpace()) {
905 case Spacing::Default: // nothing bad should happen with this
906 case Spacing::Single:
908 fl_set_choice(class_->choice_doc_spacing, 1);
910 case Spacing::Onehalf:
912 fl_set_choice(class_->choice_doc_spacing, 2);
914 case Spacing::Double:
916 fl_set_choice(class_->choice_doc_spacing, 3);
920 fl_set_choice(class_->choice_doc_spacing, 4);
922 sprintf(sval,"%g",params.spacing.getValue());
923 fl_set_input(class_->input_doc_spacing, sval);
927 if (!params.options.empty())
928 fl_set_input(class_->input_doc_extra, params.options.c_str());
930 fl_set_input(class_->input_doc_extra, "");
934 void FormDocument::language_update(BufferParams const & params)
936 if (!language_.get())
939 combo_language->select(params.language->lang());
940 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
941 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
942 fl_set_button(language_->radio_single, 0);
943 fl_set_button(language_->radio_double, 0);
944 if (params.quotes_times == InsetQuotes::SingleQ)
945 fl_set_button(language_->radio_single, 1);
947 fl_set_button(language_->radio_double, 1);
951 void FormDocument::options_update(BufferParams const & params)
956 fl_set_choice_text(options_->choice_postscript_driver,
957 params.graphicsDriver.c_str());
958 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
959 fl_set_button(options_->check_use_natbib, params.use_natbib);
960 fl_set_choice(options_->choice_citation_format,
961 int(params.use_numerical_citations)+1);
962 setEnabled(options_->choice_citation_format, params.use_natbib);
963 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
964 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
965 if (!params.float_placement.empty())
966 fl_set_input(options_->input_float_placement,
967 params.float_placement.c_str());
969 fl_set_input(options_->input_float_placement, "");
973 void FormDocument::paper_update(BufferParams const & params)
978 fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
979 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
980 fl_set_button(paper_->check_use_geometry, params.use_geometry);
982 int const paperchoice = fl_get_choice(paper_->choice_papersize);
983 bool const useCustom = paperchoice == 2;
984 bool const useGeom = fl_get_button(paper_->check_use_geometry);
986 fl_set_button(paper_->radio_portrait, 0);
987 setEnabled(paper_->radio_portrait, !useCustom);
988 fl_set_button(paper_->radio_landscape, 0);
989 setEnabled(paper_->radio_landscape, !useCustom);
991 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
992 fl_set_button(paper_->radio_landscape, 1);
994 fl_set_button(paper_->radio_portrait, 1);
995 setEnabled(paper_->choice_paperpackage,
996 //either default papersize (preferences)
997 //or document papersize has to be A4
999 || paperchoice == 1 && lyxrc.default_papersize == 5)
1000 && fl_get_button(paper_->radio_portrait));
1002 // Default unit choice is cm if metric, inches if US paper.
1003 bool const metric = paperchoice < 3 || paperchoice > 5;
1004 string const default_unit = metric ? "cm" : "in";
1005 updateWidgetsFromLengthString(paper_->input_custom_width,
1006 paper_->choice_custom_width_units,
1007 params.paperwidth, default_unit);
1008 setEnabled(paper_->input_custom_width, useCustom);
1009 setEnabled(paper_->choice_custom_width_units, useCustom);
1011 updateWidgetsFromLengthString(paper_->input_custom_height,
1012 paper_->choice_custom_height_units,
1013 params.paperheight, default_unit);
1014 setEnabled(paper_->input_custom_height, useCustom);
1015 setEnabled(paper_->choice_custom_height_units, useCustom);
1017 updateWidgetsFromLengthString(paper_->input_left_margin,
1018 paper_->choice_left_margin_units,
1019 params.leftmargin, default_unit);
1020 setEnabled(paper_->input_left_margin, useGeom);
1021 setEnabled(paper_->choice_left_margin_units, useGeom);
1023 updateWidgetsFromLengthString(paper_->input_top_margin,
1024 paper_->choice_top_margin_units,
1025 params.topmargin, default_unit);
1026 setEnabled(paper_->input_top_margin, useGeom);
1027 setEnabled(paper_->choice_top_margin_units, useGeom);
1029 updateWidgetsFromLengthString(paper_->input_right_margin,
1030 paper_->choice_right_margin_units,
1031 params.rightmargin, default_unit);
1032 setEnabled(paper_->input_right_margin, useGeom);
1033 setEnabled(paper_->choice_right_margin_units, useGeom);
1035 updateWidgetsFromLengthString(paper_->input_bottom_margin,
1036 paper_->choice_bottom_margin_units,
1037 params.bottommargin, default_unit);
1038 setEnabled(paper_->input_bottom_margin, useGeom);
1039 setEnabled(paper_->choice_bottom_margin_units, useGeom);
1041 updateWidgetsFromLengthString(paper_->input_head_height,
1042 paper_->choice_head_height_units,
1043 params.headheight, default_unit);
1044 setEnabled(paper_->input_head_height, useGeom);
1045 setEnabled(paper_->choice_head_height_units, useGeom);
1047 updateWidgetsFromLengthString(paper_->input_head_sep,
1048 paper_->choice_head_sep_units,
1049 params.headsep, default_unit);
1050 setEnabled(paper_->input_head_sep, useGeom);
1051 setEnabled(paper_->choice_head_sep_units, useGeom);
1053 updateWidgetsFromLengthString(paper_->input_foot_skip,
1054 paper_->choice_foot_skip_units,
1055 params.footskip, default_unit);
1056 setEnabled(paper_->input_foot_skip, useGeom);
1057 setEnabled(paper_->choice_foot_skip_units, useGeom);
1059 fl_set_focus_object(paper_->form, paper_->choice_papersize);
1063 void FormDocument::bullets_update(BufferParams const & params)
1065 if (!bullets_.get() ||
1067 (XpmVersion==4 && XpmRevision<7)))
1070 bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
1071 setEnabled(fbullet, !isLinuxDoc);
1073 if (isLinuxDoc) return;
1075 fl_set_button(bullets_->radio_bullet_depth_1, 1);
1076 fl_set_input(bullets_->input_bullet_latex,
1077 params.user_defined_bullets[0].getText().c_str());
1078 fl_set_choice(bullets_->choice_bullet_size,
1079 params.user_defined_bullets[0].getSize() + 2);
1083 void FormDocument::checkReadOnly()
1085 if (bc().readOnly(lv_->buffer()->isReadonly())) {
1086 combo_doc_class->deactivate();
1087 combo_language->deactivate();
1088 fl_set_object_label(dialog_->text_warning,
1089 _("Document is read-only."
1090 " No changes to layout permitted."));
1091 fl_show_object(dialog_->text_warning);
1093 combo_doc_class->activate();
1094 combo_language->activate();
1095 fl_hide_object(dialog_->text_warning);
1100 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
1106 // "Synchronize" the choice and the input field, so that it
1107 // is impossible to commit senseless data.
1108 input = fl_get_input (class_->input_doc_skip);
1109 if (ob == class_->input_doc_skip) {
1111 fl_set_choice (class_->choice_doc_skip, 2);
1112 } else if (isValidGlueLength (input)) {
1113 fl_set_choice (class_->choice_doc_skip, 4);
1115 fl_set_choice(class_->choice_doc_skip, 4);
1119 if (*input && !isValidGlueLength(input))
1123 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
1125 else if (fl_get_choice(class_->choice_doc_skip) != 4)
1126 fl_set_input (class_->input_doc_skip, "");
1128 input = fl_get_input(class_->input_doc_spacing);
1129 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
1131 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
1132 fl_set_input (class_->input_doc_spacing, "");
1137 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
1139 BufferParams & param = lv_->buffer()->params;
1141 // convert from 1-6 range to -1-4
1142 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1143 fl_set_input(bullets_->input_bullet_latex,
1144 param.temp_bullets[current_bullet_depth].getText().c_str());
1148 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1150 BufferParams & param = lv_->buffer()->params;
1152 param.temp_bullets[current_bullet_depth].
1153 setText(fl_get_input(bullets_->input_bullet_latex));
1157 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
1159 /* Should I do the following: */
1160 /* 1. change to the panel that the current bullet belongs in */
1161 /* 2. show that bullet as selected */
1162 /* 3. change the size setting to the size of the bullet in Q.*/
1163 /* 4. display the latex equivalent in the latex box */
1165 /* I'm inclined to just go with 3 and 4 at the moment and */
1166 /* maybe try to support the others later */
1167 BufferParams & param = lv_->buffer()->params;
1170 if (cb == BULLETDEPTH1 )
1172 else if (cb == BULLETDEPTH2 )
1174 else if (cb == BULLETDEPTH3 )
1176 else if (cb == BULLETDEPTH4 )
1179 switch (fl_get_button_numb(ob)) {
1181 // right mouse button resets to default
1182 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1184 current_bullet_depth = data;
1185 fl_set_input(bullets_->input_bullet_latex,
1186 param.temp_bullets[data].getText().c_str());
1187 fl_set_choice(bullets_->choice_bullet_size,
1188 param.temp_bullets[data].getSize() + 2);
1193 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
1195 /* Here we have to change the background pixmap to that selected */
1196 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1199 if (cb == BULLETPANEL1 )
1201 else if (cb == BULLETPANEL2 )
1203 else if (cb == BULLETPANEL3 )
1205 else if (cb == BULLETPANEL4 )
1207 else if (cb == BULLETPANEL5 )
1209 else if (cb == BULLETPANEL6 )
1212 if (data != current_bullet_panel) {
1213 fl_freeze_form(bullets_->form);
1214 current_bullet_panel = data;
1216 /* free the current pixmap */
1217 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1220 /* display the new one */
1222 new_panel = "standard";
1225 new_panel = "amssymb";
1228 new_panel = "psnfss1";
1231 new_panel = "psnfss2";
1234 new_panel = "psnfss3";
1237 new_panel = "psnfss4";
1240 /* something very wrong happened */
1241 // play it safe for now but should be an exception
1242 current_bullet_panel = 0; // standard panel
1243 new_panel = "standard";
1246 new_panel += ".xpm";
1247 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1248 LibFileSearch("images", new_panel).c_str());
1249 fl_redraw_object(bullets_->bmtable_bullet_panel);
1250 fl_unfreeze_form(bullets_->form);
1255 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1257 /* handle the user input by setting the current bullet depth's pixmap */
1258 /* to that extracted from the current chosen position of the BMTable */
1259 /* Don't forget to free the button's old pixmap first. */
1261 BufferParams & param = lv_->buffer()->params;
1262 int bmtable_button = fl_get_bmtable(ob);
1264 /* try to keep the button held down till another is pushed */
1265 /* fl_set_bmtable(ob, 1, bmtable_button); */
1266 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1267 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1268 fl_set_input(bullets_->input_bullet_latex,
1269 param.temp_bullets[current_bullet_depth].getText().c_str());
1273 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1276 ob = class_->choice_doc_class;
1278 lv_->prohibitInput();
1280 unsigned int tc = combo_doc_class->get() - 1;
1281 if (textclasslist.Load(tc)) {
1282 // we use a copy of the bufferparams because we do not
1283 // want to modify them yet.
1284 BufferParams params = lv_->buffer()->params;
1286 if (lyxrc.auto_reset_options) {
1287 params.textclass = tc;
1288 params.useClassDefaults();
1289 UpdateLayoutDocument(params);
1292 // unable to load new style
1293 WriteAlert(_("Conversion Errors!"),
1294 _("Unable to switch to new document class."),
1295 _("Reverting to original document class."));
1296 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1302 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1308 class_update(params);
1309 paper_update(params);
1310 language_update(params);
1311 options_update(params);
1312 bullets_update(params);