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);
726 std::cerr << params.leftmargin << std::endl;
729 getLengthFromWidgets(paper_->input_top_margin,
730 paper_->choice_top_margin_units);
733 getLengthFromWidgets(paper_->input_right_margin,
734 paper_->choice_right_margin_units);
736 params.bottommargin =
737 getLengthFromWidgets(paper_->input_bottom_margin,
738 paper_->choice_bottom_margin_units);
741 getLengthFromWidgets(paper_->input_head_height,
742 paper_->choice_head_height_units);
745 getLengthFromWidgets(paper_->input_head_sep,
746 paper_->choice_head_sep_units);
749 getLengthFromWidgets(paper_->input_foot_skip,
750 paper_->choice_foot_skip_units);
754 bool FormDocument::language_apply()
756 BufferParams & params = lv_->buffer()->params;
757 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
760 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
762 lga = InsetQuotes::EnglishQ;
765 lga = InsetQuotes::SwedishQ;
768 lga = InsetQuotes::GermanQ;
771 lga = InsetQuotes::PolishQ;
774 lga = InsetQuotes::FrenchQ;
777 lga = InsetQuotes::DanishQ;
780 params.quotes_language = lga;
781 if (fl_get_button(language_->radio_single))
782 params.quotes_times = InsetQuotes::SingleQ;
784 params.quotes_times = InsetQuotes::DoubleQ;
786 Language const * old_language = params.language;
787 Language const * new_language =
788 languages.getLanguage(combo_language->getline());
790 new_language = default_language;
792 if (old_language != new_language
793 && old_language->RightToLeft() == new_language->RightToLeft()
794 && !lv_->buffer()->isMultiLingual())
795 lv_->buffer()->changeLanguage(old_language, new_language);
796 if (old_language != new_language) {
799 params.language = new_language;
800 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
806 bool FormDocument::options_apply()
808 BufferParams & params = lv_->buffer()->params;
811 params.graphicsDriver =
812 fl_get_choice_text(options_->choice_postscript_driver);
813 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
814 params.use_natbib = fl_get_button(options_->check_use_natbib);
815 params.use_numerical_citations =
816 fl_get_choice(options_->choice_citation_format)-1;
818 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
819 if (params.secnumdepth != tmpchar)
821 params.secnumdepth = tmpchar;
823 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
825 params.float_placement =
826 fl_get_input(options_->input_float_placement);
832 void FormDocument::bullets_apply()
834 /* update the bullet settings */
835 BufferParams & param = lv_->buffer()->params;
837 // a little bit of loop unrolling
838 param.user_defined_bullets[0] = param.temp_bullets[0];
839 param.user_defined_bullets[1] = param.temp_bullets[1];
840 param.user_defined_bullets[2] = param.temp_bullets[2];
841 param.user_defined_bullets[3] = param.temp_bullets[3];
845 void FormDocument::class_update(BufferParams const & params)
850 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
852 combo_doc_class->select(
853 textclasslist.DescOfClass(params.textclass));
854 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
855 fl_clear_choice(class_->choice_doc_fontsize);
856 fl_addto_choice(class_->choice_doc_fontsize, "default");
857 fl_addto_choice(class_->choice_doc_fontsize,
858 tclass.opt_fontsize().c_str());
859 fl_set_choice(class_->choice_doc_fontsize,
860 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
861 fl_clear_choice(class_->choice_doc_pagestyle);
862 fl_addto_choice(class_->choice_doc_pagestyle, "default");
863 fl_addto_choice(class_->choice_doc_pagestyle,
864 tclass.opt_pagestyle().c_str());
865 fl_set_choice(class_->choice_doc_pagestyle,
866 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
867 fl_set_button(class_->radio_doc_indent, 0);
868 fl_set_button(class_->radio_doc_skip, 0);
869 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
870 fl_set_button(class_->radio_doc_indent, 1);
872 fl_set_button(class_->radio_doc_skip, 1);
873 switch (params.getDefSkip().kind()) {
874 case VSpace::SMALLSKIP:
875 fl_set_choice (class_->choice_doc_skip, 1);
877 case VSpace::MEDSKIP:
878 fl_set_choice (class_->choice_doc_skip, 2);
880 case VSpace::BIGSKIP:
881 fl_set_choice (class_->choice_doc_skip, 3);
884 fl_set_choice (class_->choice_doc_skip, 4);
885 fl_set_input (class_->input_doc_skip,
886 params.getDefSkip().asLyXCommand().c_str());
889 fl_set_choice (class_->choice_doc_skip, 2);
892 fl_set_button(class_->radio_doc_sides_one, 0);
893 fl_set_button(class_->radio_doc_sides_two, 0);
894 if (params.sides == LyXTextClass::TwoSides)
895 fl_set_button(class_->radio_doc_sides_two, 1);
897 fl_set_button(class_->radio_doc_sides_one, 1);
898 fl_set_button(class_->radio_doc_columns_one, 0);
899 fl_set_button(class_->radio_doc_columns_two, 0);
900 if (params.columns == 2)
901 fl_set_button(class_->radio_doc_columns_two, 1);
903 fl_set_button(class_->radio_doc_columns_one, 1);
904 fl_set_input(class_->input_doc_spacing, "");
905 switch (params.spacing.getSpace()) {
906 case Spacing::Default: // nothing bad should happen with this
907 case Spacing::Single:
909 fl_set_choice(class_->choice_doc_spacing, 1);
911 case Spacing::Onehalf:
913 fl_set_choice(class_->choice_doc_spacing, 2);
915 case Spacing::Double:
917 fl_set_choice(class_->choice_doc_spacing, 3);
921 fl_set_choice(class_->choice_doc_spacing, 4);
923 sprintf(sval,"%g",params.spacing.getValue());
924 fl_set_input(class_->input_doc_spacing, sval);
928 if (!params.options.empty())
929 fl_set_input(class_->input_doc_extra, params.options.c_str());
931 fl_set_input(class_->input_doc_extra, "");
935 void FormDocument::language_update(BufferParams const & params)
937 if (!language_.get())
940 combo_language->select(params.language->lang());
941 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
942 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
943 fl_set_button(language_->radio_single, 0);
944 fl_set_button(language_->radio_double, 0);
945 if (params.quotes_times == InsetQuotes::SingleQ)
946 fl_set_button(language_->radio_single, 1);
948 fl_set_button(language_->radio_double, 1);
952 void FormDocument::options_update(BufferParams const & params)
957 fl_set_choice_text(options_->choice_postscript_driver,
958 params.graphicsDriver.c_str());
959 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
960 fl_set_button(options_->check_use_natbib, params.use_natbib);
961 fl_set_choice(options_->choice_citation_format,
962 int(params.use_numerical_citations)+1);
963 setEnabled(options_->choice_citation_format, params.use_natbib);
964 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
965 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
966 if (!params.float_placement.empty())
967 fl_set_input(options_->input_float_placement,
968 params.float_placement.c_str());
970 fl_set_input(options_->input_float_placement, "");
974 void FormDocument::paper_update(BufferParams const & params)
979 fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
980 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
981 fl_set_button(paper_->check_use_geometry, params.use_geometry);
983 int const paperchoice = fl_get_choice(paper_->choice_papersize);
984 bool const useCustom = paperchoice == 2;
985 bool const useGeom = fl_get_button(paper_->check_use_geometry);
987 fl_set_button(paper_->radio_portrait, 0);
988 setEnabled(paper_->radio_portrait, !useCustom);
989 fl_set_button(paper_->radio_landscape, 0);
990 setEnabled(paper_->radio_landscape, !useCustom);
992 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
993 fl_set_button(paper_->radio_landscape, 1);
995 fl_set_button(paper_->radio_portrait, 1);
996 setEnabled(paper_->choice_paperpackage,
997 //either default papersize (preferences)
998 //or document papersize has to be A4
1000 || paperchoice == 1 && lyxrc.default_papersize == 5)
1001 && fl_get_button(paper_->radio_portrait));
1003 // Default unit choice is cm if metric, inches if US paper.
1004 bool const metric = paperchoice < 3 || paperchoice > 5;
1005 string const default_unit = metric ? "cm" : "in";
1006 updateWidgetsFromLengthString(paper_->input_custom_width,
1007 paper_->choice_custom_width_units,
1008 params.paperwidth, default_unit);
1009 setEnabled(paper_->input_custom_width, useCustom);
1010 setEnabled(paper_->choice_custom_width_units, useCustom);
1012 updateWidgetsFromLengthString(paper_->input_custom_height,
1013 paper_->choice_custom_height_units,
1014 params.paperheight, default_unit);
1015 setEnabled(paper_->input_custom_height, useCustom);
1016 setEnabled(paper_->choice_custom_height_units, useCustom);
1018 updateWidgetsFromLengthString(paper_->input_left_margin,
1019 paper_->choice_left_margin_units,
1020 params.leftmargin, default_unit);
1021 setEnabled(paper_->input_left_margin, useGeom);
1022 setEnabled(paper_->choice_left_margin_units, useGeom);
1024 updateWidgetsFromLengthString(paper_->input_top_margin,
1025 paper_->choice_top_margin_units,
1026 params.topmargin, default_unit);
1027 setEnabled(paper_->input_top_margin, useGeom);
1028 setEnabled(paper_->choice_top_margin_units, useGeom);
1030 updateWidgetsFromLengthString(paper_->input_right_margin,
1031 paper_->choice_right_margin_units,
1032 params.rightmargin, default_unit);
1033 setEnabled(paper_->input_right_margin, useGeom);
1034 setEnabled(paper_->choice_right_margin_units, useGeom);
1036 updateWidgetsFromLengthString(paper_->input_bottom_margin,
1037 paper_->choice_bottom_margin_units,
1038 params.bottommargin, default_unit);
1039 setEnabled(paper_->input_bottom_margin, useGeom);
1040 setEnabled(paper_->choice_bottom_margin_units, useGeom);
1042 updateWidgetsFromLengthString(paper_->input_head_height,
1043 paper_->choice_head_height_units,
1044 params.headheight, default_unit);
1045 setEnabled(paper_->input_head_height, useGeom);
1046 setEnabled(paper_->choice_head_height_units, useGeom);
1048 updateWidgetsFromLengthString(paper_->input_head_sep,
1049 paper_->choice_head_sep_units,
1050 params.headsep, default_unit);
1051 setEnabled(paper_->input_head_sep, useGeom);
1052 setEnabled(paper_->choice_head_sep_units, useGeom);
1054 updateWidgetsFromLengthString(paper_->input_foot_skip,
1055 paper_->choice_foot_skip_units,
1056 params.footskip, default_unit);
1057 setEnabled(paper_->input_foot_skip, useGeom);
1058 setEnabled(paper_->choice_foot_skip_units, useGeom);
1060 fl_set_focus_object(paper_->form, paper_->choice_papersize);
1064 void FormDocument::bullets_update(BufferParams const & params)
1066 if (!bullets_.get() ||
1068 (XpmVersion==4 && XpmRevision<7)))
1071 bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
1072 setEnabled(fbullet, !isLinuxDoc);
1074 if (isLinuxDoc) return;
1076 fl_set_button(bullets_->radio_bullet_depth_1, 1);
1077 fl_set_input(bullets_->input_bullet_latex,
1078 params.user_defined_bullets[0].getText().c_str());
1079 fl_set_choice(bullets_->choice_bullet_size,
1080 params.user_defined_bullets[0].getSize() + 2);
1084 void FormDocument::checkReadOnly()
1086 if (bc().readOnly(lv_->buffer()->isReadonly())) {
1087 combo_doc_class->deactivate();
1088 combo_language->deactivate();
1089 fl_set_object_label(dialog_->text_warning,
1090 _("Document is read-only."
1091 " No changes to layout permitted."));
1092 fl_show_object(dialog_->text_warning);
1094 combo_doc_class->activate();
1095 combo_language->activate();
1096 fl_hide_object(dialog_->text_warning);
1101 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
1107 // "Synchronize" the choice and the input field, so that it
1108 // is impossible to commit senseless data.
1109 input = fl_get_input (class_->input_doc_skip);
1110 if (ob == class_->input_doc_skip) {
1112 fl_set_choice (class_->choice_doc_skip, 2);
1113 } else if (isValidGlueLength (input)) {
1114 fl_set_choice (class_->choice_doc_skip, 4);
1116 fl_set_choice(class_->choice_doc_skip, 4);
1120 if (*input && !isValidGlueLength(input))
1124 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
1126 else if (fl_get_choice(class_->choice_doc_skip) != 4)
1127 fl_set_input (class_->input_doc_skip, "");
1129 input = fl_get_input(class_->input_doc_spacing);
1130 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
1132 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
1133 fl_set_input (class_->input_doc_spacing, "");
1138 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
1140 BufferParams & param = lv_->buffer()->params;
1142 // convert from 1-6 range to -1-4
1143 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1144 fl_set_input(bullets_->input_bullet_latex,
1145 param.temp_bullets[current_bullet_depth].getText().c_str());
1149 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1151 BufferParams & param = lv_->buffer()->params;
1153 param.temp_bullets[current_bullet_depth].
1154 setText(fl_get_input(bullets_->input_bullet_latex));
1158 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
1160 /* Should I do the following: */
1161 /* 1. change to the panel that the current bullet belongs in */
1162 /* 2. show that bullet as selected */
1163 /* 3. change the size setting to the size of the bullet in Q.*/
1164 /* 4. display the latex equivalent in the latex box */
1166 /* I'm inclined to just go with 3 and 4 at the moment and */
1167 /* maybe try to support the others later */
1168 BufferParams & param = lv_->buffer()->params;
1171 if (cb == BULLETDEPTH1 )
1173 else if (cb == BULLETDEPTH2 )
1175 else if (cb == BULLETDEPTH3 )
1177 else if (cb == BULLETDEPTH4 )
1180 switch (fl_get_button_numb(ob)) {
1182 // right mouse button resets to default
1183 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1185 current_bullet_depth = data;
1186 fl_set_input(bullets_->input_bullet_latex,
1187 param.temp_bullets[data].getText().c_str());
1188 fl_set_choice(bullets_->choice_bullet_size,
1189 param.temp_bullets[data].getSize() + 2);
1194 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
1196 /* Here we have to change the background pixmap to that selected */
1197 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1200 if (cb == BULLETPANEL1 )
1202 else if (cb == BULLETPANEL2 )
1204 else if (cb == BULLETPANEL3 )
1206 else if (cb == BULLETPANEL4 )
1208 else if (cb == BULLETPANEL5 )
1210 else if (cb == BULLETPANEL6 )
1213 if (data != current_bullet_panel) {
1214 fl_freeze_form(bullets_->form);
1215 current_bullet_panel = data;
1217 /* free the current pixmap */
1218 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1221 /* display the new one */
1223 new_panel = "standard";
1226 new_panel = "amssymb";
1229 new_panel = "psnfss1";
1232 new_panel = "psnfss2";
1235 new_panel = "psnfss3";
1238 new_panel = "psnfss4";
1241 /* something very wrong happened */
1242 // play it safe for now but should be an exception
1243 current_bullet_panel = 0; // standard panel
1244 new_panel = "standard";
1247 new_panel += ".xpm";
1248 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1249 LibFileSearch("images", new_panel).c_str());
1250 fl_redraw_object(bullets_->bmtable_bullet_panel);
1251 fl_unfreeze_form(bullets_->form);
1256 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1258 /* handle the user input by setting the current bullet depth's pixmap */
1259 /* to that extracted from the current chosen position of the BMTable */
1260 /* Don't forget to free the button's old pixmap first. */
1262 BufferParams & param = lv_->buffer()->params;
1263 int bmtable_button = fl_get_bmtable(ob);
1265 /* try to keep the button held down till another is pushed */
1266 /* fl_set_bmtable(ob, 1, bmtable_button); */
1267 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1268 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1269 fl_set_input(bullets_->input_bullet_latex,
1270 param.temp_bullets[current_bullet_depth].getText().c_str());
1274 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1277 ob = class_->choice_doc_class;
1279 lv_->prohibitInput();
1281 unsigned int tc = combo_doc_class->get() - 1;
1282 if (textclasslist.Load(tc)) {
1283 // we use a copy of the bufferparams because we do not
1284 // want to modify them yet.
1285 BufferParams params = lv_->buffer()->params;
1287 if (lyxrc.auto_reset_options) {
1288 params.textclass = tc;
1289 params.useClassDefaults();
1290 UpdateLayoutDocument(params);
1293 // unable to load new style
1294 WriteAlert(_("Conversion Errors!"),
1295 _("Unable to switch to new document class."),
1296 _("Reverting to original document class."));
1297 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1303 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1309 class_update(params);
1310 paper_update(params);
1311 language_update(params);
1312 options_update(params);
1313 bullets_update(params);