]> git.lyx.org Git - features.git/blob - src/frontends/xforms/FormDocument.C
(Rob Laheye): changes to the document dialog + some trivia.
[features.git] / src / frontends / xforms / FormDocument.C
1 /**
2  * \file FormDocument.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Jürgen Vigna
7  * \author Rob Lahaye
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #include <config.h>
13
14 #include FORMS_H_LOCATION
15 #include XPM_H_LOCATION
16
17 #ifdef __GNUG__
18 #pragma implementation
19 #endif
20
21 #include "FormDocument.h"
22 #include "forms/form_document.h"
23 #include "Alert.h"
24 #include "lyxtextclasslist.h"
25 #include "combox.h"
26 #include "tex-strings.h"
27 #include "bufferparams.h"
28 #include "vspace.h"
29 #include "bmtable.h"
30 #include "language.h"
31 #include "frnt_lang.h"
32 #include "frontends/LyXView.h"
33 #include "lyxfunc.h"
34 #include "lyxrc.h"
35 #include "BufferView.h"
36 #include "buffer.h"
37 #include "CutAndPaste.h"
38 #include "bufferview_funcs.h"
39 #include "xforms_helpers.h"
40 #include "checkedwidgets.h"
41 #include "debug.h"
42 #include "input_validators.h" // fl_unsigned_float_filter
43 #include "helper_funcs.h"
44 #include "lyx_main.h" // for user_lyxdir
45
46 #include "insets/insetquotes.h"
47
48 #include "support/filetools.h"
49 #include "support/lstrings.h"
50
51 #include FORMS_H_LOCATION
52
53 #include <boost/bind.hpp>
54
55 #include <functional>
56
57 using std::bind2nd;
58 using std::vector;
59
60
61 FormDocument::FormDocument(LyXView & lv, Dialogs & d)
62         : FormBaseBD(lv, d, _("Document Layout"), false),
63           ActCell(0), Confirmed(0),
64           current_bullet_panel(0), current_bullet_depth(0), fbullet(0)
65 {}
66
67
68 void FormDocument::redraw()
69 {
70         if (form() && form()->visible)
71                 fl_redraw_form(form());
72         else
73                 return;
74
75         FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder);
76         if (outer_form && outer_form->visible)
77                 fl_redraw_form(outer_form);
78 }
79
80
81 FL_FORM * FormDocument::form() const
82 {
83         if (dialog_.get()) return dialog_->form;
84         return 0;
85 }
86
87
88 void FormDocument::build()
89 {
90         // the tabbed folder
91         dialog_.reset(build_document(this));
92
93         // Allow the base class to control messages
94         setMessageWidget(dialog_->text_warning);
95
96         // Manage the restore, ok, apply, restore and cancel/close buttons
97         bc().setOK(dialog_->button_ok);
98         bc().setApply(dialog_->button_apply);
99         bc().setCancel(dialog_->button_close);
100         bc().setRestore(dialog_->button_restore);
101
102         // the document class form
103         class_.reset(build_document_class(this));
104
105         // disable for read-only documents
106         bc().addReadOnly(class_->radio_doc_indent);
107         bc().addReadOnly(class_->radio_doc_skip);
108         bc().addReadOnly(class_->choice_doc_pagestyle);
109         bc().addReadOnly(class_->choice_doc_fonts);
110         bc().addReadOnly(class_->choice_doc_fontsize);
111         bc().addReadOnly(class_->radio_doc_sides_one);
112         bc().addReadOnly(class_->radio_doc_sides_two);
113         bc().addReadOnly(class_->radio_doc_columns_one);
114         bc().addReadOnly(class_->radio_doc_columns_two);
115         bc().addReadOnly(class_->input_doc_extra);
116         bc().addReadOnly(class_->input_doc_skip);
117         bc().addReadOnly(class_->choice_doc_skip);
118         bc().addReadOnly(class_->choice_doc_spacing);
119         bc().addReadOnly(class_->input_doc_spacing);
120
121         // check validity of "length + unit" input
122         addCheckedGlueLength(bc(), class_->input_doc_skip,
123                              class_->choice_doc_skip);
124
125         // trigger an input event for cut&paste with middle mouse button.
126         setPrehandler(class_->input_doc_extra);
127         setPrehandler(class_->input_doc_skip);
128         setPrehandler(class_->input_doc_spacing);
129
130         fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
131         fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
132         fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
133
134         FL_OBJECT * obj;
135
136         // the class list is a combo-box and has to be inserted manually
137         obj = class_->choice_doc_class;
138         fl_deactivate_object(obj);
139         fl_addto_form(class_->form);
140         combo_doc_class.reset(new Combox(FL_COMBOX_DROPLIST));
141         combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400);
142         combo_doc_class->shortcut("#C",1);
143         combo_doc_class->setcallback(ComboInputCB, this);
144         fl_end_form();
145         for (LyXTextClassList::const_iterator cit = textclasslist.begin();
146              cit != textclasslist.end(); ++cit) {
147                 combo_doc_class->addto(cit->description());
148         }
149
150         fl_addto_choice(class_->choice_doc_spacing,
151                         _(" Single | OneHalf | Double | Custom "));
152         fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
153         for (int n = 0; tex_fonts[n][0]; ++n) {
154                 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
155         }
156
157         // Create the contents of the unit choices; don't include the
158         // "%" terms...
159         vector<string> units_vec = getLatexUnits();
160         vector<string>::iterator ret =
161                 std::remove_if(units_vec.begin(),
162                                units_vec.end(),
163                                bind2nd(contains_functor(), "%"));
164         units_vec.erase(ret, units_vec.end());
165
166         string const units = getStringFromVector(units_vec, "|");
167
168         fl_addto_choice(class_->choice_doc_pagestyle,
169                         "default|empty|plain|headings|fancy");
170         fl_addto_choice(class_->choice_doc_skip,
171                         _(" Smallskip | Medskip | Bigskip | Length "));
172         fl_addto_choice(class_->choice_doc_skip_units,  units.c_str());
173
174         // Set input filters on doc spacing to make it accept only
175         // unsigned numbers.
176         fl_set_input_filter(class_->input_doc_spacing,
177                             fl_unsigned_float_filter);
178
179         // disable for read-only documents
180         bc().addReadOnly(dialog_->button_save_defaults);
181         bc().addReadOnly(dialog_->button_reset_defaults);
182
183         // the document paper form
184         paper_.reset(build_document_paper(this));
185
186         // disable for read-only documents
187         bc().addReadOnly(paper_->choice_paperpackage);
188         bc().addReadOnly(paper_->radio_portrait);
189         bc().addReadOnly(paper_->radio_landscape);
190         bc().addReadOnly(paper_->choice_papersize);
191         bc().addReadOnly(paper_->check_use_geometry);
192         bc().addReadOnly(paper_->input_custom_width);
193         bc().addReadOnly(paper_->input_custom_height);
194         bc().addReadOnly(paper_->input_top_margin);
195         bc().addReadOnly(paper_->input_bottom_margin);
196         bc().addReadOnly(paper_->input_inner_margin);
197         bc().addReadOnly(paper_->input_outer_margin);
198         bc().addReadOnly(paper_->input_head_height);
199         bc().addReadOnly(paper_->input_head_sep);
200         bc().addReadOnly(paper_->input_foot_skip);
201
202         // check validity of "length + unit" input
203         addCheckedGlueLength(bc(), paper_->input_custom_width);
204         addCheckedGlueLength(bc(), paper_->input_custom_height);
205         addCheckedGlueLength(bc(), paper_->input_top_margin);
206         addCheckedGlueLength(bc(), paper_->input_bottom_margin);
207         addCheckedGlueLength(bc(), paper_->input_inner_margin);
208         addCheckedGlueLength(bc(), paper_->input_outer_margin);
209         addCheckedGlueLength(bc(), paper_->input_head_height);
210         addCheckedGlueLength(bc(), paper_->input_head_sep);
211         addCheckedGlueLength(bc(), paper_->input_foot_skip);
212
213         // trigger an input event for cut&paste with middle mouse button.
214         setPrehandler(paper_->input_custom_width);
215         setPrehandler(paper_->input_custom_height);
216         setPrehandler(paper_->input_top_margin);
217         setPrehandler(paper_->input_bottom_margin);
218         setPrehandler(paper_->input_inner_margin);
219         setPrehandler(paper_->input_outer_margin);
220         setPrehandler(paper_->input_head_height);
221         setPrehandler(paper_->input_head_sep);
222         setPrehandler(paper_->input_foot_skip);
223
224         fl_set_input_return(paper_->input_custom_width,  FL_RETURN_CHANGED);
225         fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
226         fl_set_input_return(paper_->input_top_margin,    FL_RETURN_CHANGED);
227         fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
228         fl_set_input_return(paper_->input_inner_margin,  FL_RETURN_CHANGED);
229         fl_set_input_return(paper_->input_outer_margin,  FL_RETURN_CHANGED);
230         fl_set_input_return(paper_->input_head_height,   FL_RETURN_CHANGED);
231         fl_set_input_return(paper_->input_head_sep,      FL_RETURN_CHANGED);
232         fl_set_input_return(paper_->input_foot_skip,     FL_RETURN_CHANGED);
233
234         fl_addto_choice(paper_->choice_papersize,
235                         _(" Default | Custom | US letter | US legal "
236                           "| US executive | A3 | A4 | A5 | B3 | B4 | B5 "));
237         fl_addto_choice(paper_->choice_paperpackage,
238                         _(" None "
239                           "| Small Margins "
240                           "| Very small Margins "
241                           "| Very wide Margins "));
242
243         fl_addto_choice(paper_->choice_custom_width_units,  units.c_str());
244         fl_addto_choice(paper_->choice_custom_height_units, units.c_str());
245         fl_addto_choice(paper_->choice_top_margin_units,    units.c_str());
246         fl_addto_choice(paper_->choice_bottom_margin_units, units.c_str());
247         fl_addto_choice(paper_->choice_inner_margin_units,  units.c_str());
248         fl_addto_choice(paper_->choice_outer_margin_units,  units.c_str());
249         fl_addto_choice(paper_->choice_head_height_units,   units.c_str());
250         fl_addto_choice(paper_->choice_head_sep_units,      units.c_str());
251         fl_addto_choice(paper_->choice_foot_skip_units,     units.c_str());
252
253         // the document language form
254         language_.reset(build_document_language(this));
255
256         // disable for read-only documents
257         bc().addReadOnly(language_->choice_inputenc);
258         bc().addReadOnly(language_->choice_quotes_language);
259         bc().addReadOnly(language_->radio_single);
260         bc().addReadOnly(language_->radio_double);
261
262         fl_addto_choice(language_->choice_inputenc,
263                         "default|auto|latin1|latin2|latin3|latin4|latin5|latin9"
264                         "|koi8-r|koi8-u|cp866|cp1251|iso88595|pt154");
265
266         vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
267         // Store the identifiers for later
268         lang_ = getSecond(langs);
269
270         // The language is a combo-box and has to be inserted manually
271         obj = language_->choice_language;
272         fl_deactivate_object(obj);
273         fl_addto_form(language_->form);
274         combo_language.reset(new Combox(FL_COMBOX_DROPLIST));
275         combo_language->add(obj->x, obj->y, obj->w, obj->h, 400);
276         combo_language->shortcut("#L",1);
277         combo_language->setcallback(ComboInputCB, this);
278         fl_end_form();
279
280         vector<frnt::LanguagePair>::const_iterator lit  = langs.begin();
281         vector<frnt::LanguagePair>::const_iterator lend = langs.end();
282         for (; lit != lend; ++lit) {
283                 combo_language->addto(lit->first);
284         }
285         combo_language->select(1);
286
287         fl_addto_choice(language_->choice_quotes_language,
288                         _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
289                           " «text» | »text« "));
290
291         // the document options form
292         options_.reset(build_document_options(this));
293
294         // disable for read-only documents
295         bc_.addReadOnly(options_->counter_secnumdepth);
296         bc_.addReadOnly(options_->counter_tocdepth);
297         bc_.addReadOnly(options_->check_use_amsmath);
298         bc_.addReadOnly(options_->check_use_natbib);
299         bc_.addReadOnly(options_->choice_citation_format);
300         bc_.addReadOnly(options_->input_float_placement);
301         bc_.addReadOnly(options_->choice_postscript_driver);
302
303         // trigger an input event for cut&paste with middle mouse button.
304         setPrehandler(options_->input_float_placement);
305
306         fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
307
308         for (int n = 0; tex_graphics[n][0]; ++n) {
309                 fl_addto_choice(options_->choice_postscript_driver,
310                                 tex_graphics[n]);
311         }
312         fl_addto_choice(options_->choice_citation_format,
313                         _(" Author-year | Numerical "));
314
315         // the document bullets form
316         bullets_.reset(build_document_bullet(this));
317
318         // disable for read-only documents
319         bc_.addReadOnly(bullets_->radio_bullet_depth_1);
320         bc_.addReadOnly(bullets_->radio_bullet_depth_2);
321         bc_.addReadOnly(bullets_->radio_bullet_depth_3);
322         bc_.addReadOnly(bullets_->radio_bullet_depth_4);
323         bc_.addReadOnly(bullets_->radio_bullet_panel_standard);
324         bc_.addReadOnly(bullets_->radio_bullet_panel_maths);
325         bc_.addReadOnly(bullets_->radio_bullet_panel_ding1);
326         bc_.addReadOnly(bullets_->radio_bullet_panel_ding2);
327         bc_.addReadOnly(bullets_->radio_bullet_panel_ding3);
328         bc_.addReadOnly(bullets_->radio_bullet_panel_ding4);
329         bc().addReadOnly(bullets_->bmtable_bullet_panel);
330         bc().addReadOnly(bullets_->choice_bullet_size);
331         bc().addReadOnly(bullets_->input_bullet_latex);
332
333         // trigger an input event for cut&paste with middle mouse button.
334         setPrehandler(bullets_->input_bullet_latex);
335
336         fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
337
338         fl_addto_choice(bullets_->choice_bullet_size,
339                         _(" default | tiny | script | footnote | small |"
340                           " normal | large | Large | LARGE | huge | Huge"));
341         fl_set_choice(bullets_->choice_bullet_size, 1);
342
343         fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
344
345         string const bmtablefile = LibFileSearch("images", "standard", "xpm");
346         fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
347                                    bmtablefile.c_str());
348
349         fl_addto_tabfolder(dialog_->tabfolder,_("Document"),
350                            class_->form);
351         fl_addto_tabfolder(dialog_->tabfolder,_("Paper"),
352                            paper_->form);
353         fl_addto_tabfolder(dialog_->tabfolder,_("Language"),
354                            language_->form);
355         fl_addto_tabfolder(dialog_->tabfolder,_("Extra"),
356                            options_->form);
357         fbullet = fl_addto_tabfolder(dialog_->tabfolder,_("Bullets"),
358                                      bullets_->form);
359
360         // work-around xforms bug re update of folder->x, folder->y coords.
361         setPrehandler(dialog_->tabfolder);
362
363         if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
364                 lyxerr << _("Your version of libXpm is older than 4.7.\n"
365                             "The `bullet' tab of the document dialog "
366                             "has been disabled") << '\n';
367                 fl_deactivate_object(fbullet);
368                 fl_set_object_lcol(fbullet, FL_INACTIVE);
369         }
370 }
371
372
373 void FormDocument::apply()
374 {
375         if (!lv_.view()->available() || !dialog_.get())
376                 return;
377
378         bool redo = class_apply();
379         paper_apply();
380         redo = language_apply() || redo;
381         redo = options_apply() || redo;
382         bullets_apply();
383
384         if (redo) {
385                 lv_.view()->redoCurrentBuffer();
386         }
387         lv_.buffer()->markDirty();
388         lv_.message(_("Document layout set"));
389 }
390
391
392 void FormDocument::cancel()
393 {
394         // this avoids confusion when reopening
395         BufferParams & param = lv_.buffer()->params;
396         param.temp_bullets[0] = param.user_defined_bullets[0];
397         param.temp_bullets[1] = param.user_defined_bullets[1];
398         param.temp_bullets[2] = param.user_defined_bullets[2];
399         param.temp_bullets[3] = param.user_defined_bullets[3];
400         hide();
401 }
402
403
404 void FormDocument::update()
405 {
406         if (!dialog_.get())
407                 return;
408
409         checkReadOnly();
410
411         BufferParams const & params = lv_.buffer()->params;
412
413         class_update(params);
414         paper_update(params);
415         language_update(params);
416         options_update(params);
417         bullets_update(params);
418 }
419
420
421 namespace {
422 // should this go elsewhere? Maybe a ControllerDocument? (JMarc)
423 /** Save the buffer's parameters as user default.
424     This function saves a file \c user_lyxdir/templates/defaults.lyx
425     which parameters are those of the current buffer. This file
426     is used as a default template when creating a new
427     file. Returns \c true on success.
428 */
429 bool saveParamsAsDefault(BufferParams const &params)
430 {
431         if (!Alert::askQuestion(_("Do you want to save the current settings"),
432                                 _("for the document layout as default?"),
433                                 _("(they will be valid for any new document)")))
434                 return false;
435
436         string const fname = AddName(AddPath(user_lyxdir, "templates/"),
437                                      "defaults.lyx");
438         Buffer defaults(fname);
439         defaults.params = params;
440
441         // add an empty paragraph. Is this enough?
442         Paragraph * par = new Paragraph;
443         par->layout(params.getLyXTextClass().defaultLayout());
444         defaults.paragraphs.set(par);
445
446         return defaults.writeFile(defaults.fileName());
447 }
448
449 } //namespace
450
451
452 bool FormDocument::input(FL_OBJECT * ob, long)
453 {
454         if (ob == class_->choice_doc_class) {
455                 CheckChoiceClass(ob, 0);
456
457         } else if (ob == bullets_->choice_bullet_size) {
458                 ChoiceBulletSize(ob, 0);
459
460         } else if (ob == bullets_->input_bullet_latex) {
461                 InputBulletLaTeX(ob, 0);
462
463         } else if (ob == bullets_->radio_bullet_depth_1 ||
464                    ob == bullets_->radio_bullet_depth_2 ||
465                    ob == bullets_->radio_bullet_depth_3 ||
466                    ob == bullets_->radio_bullet_depth_4) {
467                 BulletDepth(ob);
468
469         } else if (ob == bullets_->radio_bullet_panel_standard ||
470                    ob == bullets_->radio_bullet_panel_maths ||
471                    ob == bullets_->radio_bullet_panel_ding1 ||
472                    ob == bullets_->radio_bullet_panel_ding2 ||
473                    ob == bullets_->radio_bullet_panel_ding3 ||
474                    ob == bullets_->radio_bullet_panel_ding4) {
475                 BulletPanel(ob);
476
477         } else if (ob == bullets_->bmtable_bullet_panel) {
478                 BulletBMTable(ob, 0);
479
480         } else if (ob == class_->choice_doc_spacing) {
481                 setEnabled(class_->input_doc_spacing,
482                            fl_get_choice(class_->choice_doc_spacing) == 4);
483
484         } else if (ob == class_->radio_doc_skip ||
485                    ob == class_->radio_doc_indent ||
486                    ob == class_->choice_doc_skip) {
487                 bool const skip_used = fl_get_button(class_->radio_doc_skip);
488                 setEnabled(class_->choice_doc_skip, skip_used);
489
490                 bool const length_input =
491                         fl_get_choice(class_->choice_doc_skip) == 4;
492                 setEnabled(class_->input_doc_skip,
493                            skip_used && length_input);
494                 setEnabled(class_->choice_doc_skip_units,
495                            skip_used && length_input);
496         
497                 // Default unit choice is cm if metric, inches if US paper.
498                 // If papersize is default, check the lyxrc-settings
499                 int const paperchoice = fl_get_choice(paper_->choice_papersize);
500                 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
501                         || paperchoice == 2 || paperchoice > 5;
502                 string const default_unit = metric ? "cm" : "in";
503                 if (getString(class_->input_doc_skip).empty())
504                         fl_set_choice_text(class_->choice_doc_skip_units,
505                                                 default_unit.c_str());
506
507         } else if (ob == options_->check_use_natbib) {
508                 setEnabled(options_->choice_citation_format,
509                            fl_get_button(options_->check_use_natbib));
510
511         } else if (ob == dialog_->button_save_defaults) {
512                 BufferParams params;
513                 class_apply(params);
514                 paper_apply(params);
515                 language_apply(params);
516                 options_apply(params);
517                 bullets_apply(params);
518                 params.preamble = lv_.buffer()->params.preamble;
519                 saveParamsAsDefault(params);
520
521         } else if (ob == dialog_->button_reset_defaults) {
522                 BufferParams params = lv_.buffer()->params;
523                 params.textclass = combo_doc_class->get() - 1;
524                 params.useClassDefaults();
525                 UpdateLayoutDocument(params);
526
527         } else if (ob == paper_->radio_landscape) {
528                 fl_set_choice(paper_->choice_paperpackage,
529                               BufferParams::PACKAGE_NONE + 1);
530
531         } else if (ob == paper_->choice_papersize) {
532                 int const paperchoice = fl_get_choice(paper_->choice_papersize);
533                 bool const defsize = paperchoice == 1;
534                 bool const custom = paperchoice == 2;
535                 bool const a3size = paperchoice == 6;
536                 bool const b3size = paperchoice == 9;
537                 bool const b4size = paperchoice == 10;
538
539                 if (custom)
540                         fl_set_button(paper_->radio_portrait, 1);
541
542                 bool const use_geom = (custom || a3size || b3size || b4size);
543
544                 fl_set_button(paper_->check_use_geometry, int(use_geom));
545
546                 setEnabled(paper_->input_top_margin,    use_geom);
547                 setEnabled(paper_->input_bottom_margin, use_geom);
548                 setEnabled(paper_->input_inner_margin,  use_geom);
549                 setEnabled(paper_->input_outer_margin,  use_geom);
550                 setEnabled(paper_->input_head_height,   use_geom);
551                 setEnabled(paper_->input_head_sep,      use_geom);
552                 setEnabled(paper_->input_foot_skip,     use_geom);
553                 setEnabled(paper_->choice_top_margin_units,    use_geom);
554                 setEnabled(paper_->choice_bottom_margin_units, use_geom);
555                 setEnabled(paper_->choice_inner_margin_units,  use_geom);
556                 setEnabled(paper_->choice_outer_margin_units,  use_geom);
557                 setEnabled(paper_->choice_head_height_units,   use_geom);
558                 setEnabled(paper_->choice_head_sep_units,      use_geom);
559                 setEnabled(paper_->choice_foot_skip_units,     use_geom);
560                 setEnabled(paper_->choice_custom_width_units,  use_geom);
561                 setEnabled(paper_->choice_custom_height_units, use_geom);
562
563                 setEnabled(paper_->input_custom_width,  custom);
564                 setEnabled(paper_->input_custom_height, custom);
565                 setEnabled(paper_->choice_custom_width_units,  custom);
566                 setEnabled(paper_->choice_custom_height_units, custom);
567                 setEnabled(paper_->radio_portrait,  !custom);
568                 setEnabled(paper_->radio_landscape, !custom);
569
570                 // Default unit choice is cm if metric, inches if US paper.
571                 // If papersize is default, use the lyxrc-settings
572                 bool const metric = (defsize && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
573                         || paperchoice == 2 || paperchoice > 5;
574                 string const default_unit = metric ? "cm" : "in";
575                 if (getString(paper_->input_custom_width).empty())
576                         fl_set_choice_text(paper_->choice_custom_width_units,
577                                            default_unit.c_str());
578                 if (getString(paper_->input_custom_height).empty())
579                         fl_set_choice_text(paper_->choice_custom_height_units,
580                                            default_unit.c_str());
581                 if (getString(paper_->input_top_margin).empty())
582                         fl_set_choice_text(paper_->choice_top_margin_units,
583                                            default_unit.c_str());
584                 if (getString(paper_->input_bottom_margin).empty())
585                         fl_set_choice_text(paper_->choice_bottom_margin_units,
586                                            default_unit.c_str());
587                 if (getString(paper_->input_inner_margin).empty())
588                         fl_set_choice_text(paper_->choice_inner_margin_units,
589                                            default_unit.c_str());
590                 if (getString(paper_->input_outer_margin).empty())
591                         fl_set_choice_text(paper_->choice_outer_margin_units,
592                                            default_unit.c_str());
593                 if (getString(paper_->input_head_height).empty())
594                         fl_set_choice_text(paper_->choice_head_height_units,
595                                            default_unit.c_str());
596                 if (getString(paper_->input_head_sep).empty())
597                         fl_set_choice_text(paper_->choice_head_sep_units,
598                                            default_unit.c_str());
599                 if (getString(paper_->input_foot_skip).empty())
600                         fl_set_choice_text(paper_->choice_foot_skip_units,
601                                            default_unit.c_str());
602
603         } else if (ob == paper_->choice_paperpackage &&
604                    fl_get_choice(paper_->choice_paperpackage) != 1) {
605
606                 fl_set_button(paper_->check_use_geometry, 0);
607                 setEnabled(paper_->input_top_margin,    false);
608                 setEnabled(paper_->input_bottom_margin, false);
609                 setEnabled(paper_->input_inner_margin,  false);
610                 setEnabled(paper_->input_outer_margin,  false);
611                 setEnabled(paper_->input_head_height,   false);
612                 setEnabled(paper_->input_head_sep,      false);
613                 setEnabled(paper_->input_foot_skip,     false);
614                 setEnabled(paper_->choice_top_margin_units,    false);
615                 setEnabled(paper_->choice_bottom_margin_units, false);
616                 setEnabled(paper_->choice_inner_margin_units,  false);
617                 setEnabled(paper_->choice_outer_margin_units,  false);
618                 setEnabled(paper_->choice_head_height_units,   false);
619                 setEnabled(paper_->choice_head_sep_units,      false);
620                 setEnabled(paper_->choice_foot_skip_units,     false);
621
622         } else if (ob == paper_->check_use_geometry) {
623                 // don't allow switching geometry off in custom papersize
624                 // mode nor in A3, B3, and B4
625                 int const choice = fl_get_choice(paper_->choice_papersize);
626                 if (choice == 2 || choice == 6 || choice == 9 || choice == 10)
627                         fl_set_button(paper_->check_use_geometry, 1);
628
629                 fl_set_choice(paper_->choice_paperpackage,
630                               BufferParams::PACKAGE_NONE + 1);
631
632                 bool const use_geom = fl_get_button(paper_->check_use_geometry);
633                 setEnabled(paper_->input_top_margin,    use_geom);
634                 setEnabled(paper_->input_bottom_margin, use_geom);
635                 setEnabled(paper_->input_inner_margin,  use_geom);
636                 setEnabled(paper_->input_outer_margin,  use_geom);
637                 setEnabled(paper_->input_head_height,   use_geom);
638                 setEnabled(paper_->input_head_sep,      use_geom);
639                 setEnabled(paper_->input_foot_skip,     use_geom);
640                 setEnabled(paper_->choice_top_margin_units,    use_geom);
641                 setEnabled(paper_->choice_bottom_margin_units, use_geom);
642                 setEnabled(paper_->choice_inner_margin_units,  use_geom);
643                 setEnabled(paper_->choice_outer_margin_units,  use_geom);
644                 setEnabled(paper_->choice_head_height_units,   use_geom);
645                 setEnabled(paper_->choice_head_sep_units,      use_geom);
646                 setEnabled(paper_->choice_foot_skip_units,     use_geom);
647         }
648
649         if (ob == paper_->choice_papersize || ob == paper_->radio_portrait
650                         || ob == paper_->radio_landscape) {
651                 // either default papersize (preferences) or document
652                 // papersize has to be A4
653                 bool const enable = ( fl_get_choice(paper_->choice_papersize) == 1
654                                         && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER )
655                                 || fl_get_choice(paper_->choice_papersize) == 7;
656                 setEnabled(paper_->choice_paperpackage, enable && fl_get_button(paper_->radio_portrait));
657         }
658
659         return true;
660 }
661
662
663 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
664 {
665         FormDocument * pre = static_cast<FormDocument*>(v);
666         if (combox == pre->combo_doc_class.get())
667                 pre->CheckChoiceClass(0, 0);
668         pre->bc().valid();
669 }
670
671
672 bool FormDocument::class_apply(BufferParams &params)
673 {
674         bool redo = false;
675
676         // If default skip is a "Length" but there's no text in the
677         // input field, reset the kind to "Medskip", which is the default.
678         if (fl_get_choice(class_->choice_doc_skip) == 4 &&
679             getString(class_->input_doc_skip).empty()) {
680                 fl_set_choice(class_->choice_doc_skip, 2);
681         }
682         params.fonts = getString(class_->choice_doc_fonts);
683         params.fontsize = getString(class_->choice_doc_fontsize);
684         params.pagestyle = getString(class_->choice_doc_pagestyle);
685
686         params.textclass = combo_doc_class->get() - 1;
687
688         BufferParams::PARSEP tmpsep = params.paragraph_separation;
689         if (fl_get_button(class_->radio_doc_indent))
690                 params.paragraph_separation = BufferParams::PARSEP_INDENT;
691         else
692                 params.paragraph_separation = BufferParams::PARSEP_SKIP;
693         if (tmpsep != params.paragraph_separation)
694                 redo = true;
695
696         VSpace tmpdefskip = params.getDefSkip();
697         switch (fl_get_choice(class_->choice_doc_skip)) {
698         case 1:
699                 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
700                 break;
701         case 2:
702                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
703                 break;
704         case 3:
705                 params.setDefSkip(VSpace(VSpace::BIGSKIP));
706                 break;
707         case 4:
708         {
709                 string const length =
710                         getLengthFromWidgets(class_->input_doc_skip,
711                                              class_->choice_doc_skip_units);
712
713                 params.setDefSkip(VSpace(LyXGlueLength(length)));
714                 break;
715         }
716         default:
717                 // DocumentDefskipCB assures that this never happens
718                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
719                 break;
720         }
721         if (!(tmpdefskip == params.getDefSkip()))
722                 redo = true;
723
724         if (fl_get_button(class_->radio_doc_columns_two))
725                 params.columns = 2;
726         else
727                 params.columns = 1;
728         if (fl_get_button(class_->radio_doc_sides_two))
729                 params.sides = LyXTextClass::TwoSides;
730         else
731                 params.sides = LyXTextClass::OneSide;
732
733         Spacing tmpSpacing = params.spacing;
734         switch (fl_get_choice(class_->choice_doc_spacing)) {
735         case 1:
736                 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
737                 params.spacing.set(Spacing::Single);
738                 break;
739         case 2:
740                 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
741                 params.spacing.set(Spacing::Onehalf);
742                 break;
743         case 3:
744                 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
745                 params.spacing.set(Spacing::Double);
746                 break;
747         case 4:
748                 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
749                 params.spacing.set(Spacing::Other,
750                                    getString(class_->input_doc_spacing));
751                 break;
752         }
753         if (tmpSpacing != params.spacing)
754                 redo = true;
755
756         params.options = getString(class_->input_doc_extra);
757
758         return redo;
759 }
760
761
762 bool FormDocument::class_apply()
763 {
764         BufferParams &params = lv_.buffer()->params;
765
766         unsigned int const old_class = params.textclass;
767
768         bool redo = class_apply(params);
769
770         if (params.textclass != old_class) {
771                 // try to load new_class
772                 if (textclasslist[params.textclass].load()) {
773                         // successfully loaded
774                         redo = true;
775                         lv_.message(_("Converting document to new document class..."));
776                         int ret = CutAndPaste::SwitchLayoutsBetweenClasses(
777                                 old_class, params.textclass,
778                                 &*(lv_.buffer()->paragraphs.begin()),
779                                 lv_.buffer()->params);
780                         if (ret) {
781                                 string s;
782                                 if (ret == 1) {
783                                         s = _("One paragraph couldn't be converted");
784                                 } else {
785                                         s += tostr(ret);
786                                         s += _(" paragraphs couldn't be converted");
787                                 }
788                                 Alert::alert(_("Conversion Errors!"),s,
789                                              _("into chosen document class"));
790                         }
791
792                 } else {
793                         // problem changing class -- warn user and retain old style
794                         Alert::alert(_("Conversion Errors!"),
795                                      _("Errors loading new document class."),
796                                      _("Reverting to original document class."));
797                         combo_doc_class->select(int(old_class) + 1);
798                 }
799         }
800
801         return redo;
802 }
803
804
805 void FormDocument::paper_apply(BufferParams & params)
806 {
807         params.papersize2 = char(fl_get_choice(paper_->choice_papersize) - 1);
808
809         params.paperpackage =
810                 char(fl_get_choice(paper_->choice_paperpackage) - 1);
811
812         // set params.papersize from params.papersize2 and params.paperpackage
813         params.setPaperStuff();
814
815         params.use_geometry = fl_get_button(paper_->check_use_geometry);
816
817         if (fl_get_button(paper_->radio_landscape))
818                 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
819         else
820                 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
821
822         params.paperwidth =
823                 getLengthFromWidgets(paper_->input_custom_width,
824                                      paper_->choice_custom_width_units);
825
826         params.paperheight =
827                 getLengthFromWidgets(paper_->input_custom_height,
828                                      paper_->choice_custom_height_units);
829
830         params.leftmargin =
831                 getLengthFromWidgets(paper_->input_inner_margin,
832                                      paper_->choice_inner_margin_units);
833
834         params.topmargin =
835                 getLengthFromWidgets(paper_->input_top_margin,
836                                      paper_->choice_top_margin_units);
837
838         params.rightmargin =
839                 getLengthFromWidgets(paper_->input_outer_margin,
840                                      paper_->choice_outer_margin_units);
841
842         params.bottommargin =
843                 getLengthFromWidgets(paper_->input_bottom_margin,
844                                      paper_->choice_bottom_margin_units);
845
846         params.headheight =
847                 getLengthFromWidgets(paper_->input_head_height,
848                                      paper_->choice_head_height_units);
849
850         params.headsep =
851                 getLengthFromWidgets(paper_->input_head_sep,
852                                      paper_->choice_head_sep_units);
853
854         params.footskip =
855                 getLengthFromWidgets(paper_->input_foot_skip,
856                                      paper_->choice_foot_skip_units);
857 }
858
859
860 void FormDocument::paper_apply()
861 {
862         paper_apply(lv_.buffer()->params);
863 }
864
865
866 bool FormDocument::language_apply(BufferParams & params)
867 {
868         InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
869         bool redo = false;
870
871         switch (fl_get_choice(language_->choice_quotes_language) - 1) {
872         case 0:
873                 lga = InsetQuotes::EnglishQ;
874                 break;
875         case 1:
876                 lga = InsetQuotes::SwedishQ;
877                 break;
878         case 2:
879                 lga = InsetQuotes::GermanQ;
880                 break;
881         case 3:
882                 lga = InsetQuotes::PolishQ;
883                 break;
884         case 4:
885                 lga = InsetQuotes::FrenchQ;
886                 break;
887         case 5:
888                 lga = InsetQuotes::DanishQ;
889                 break;
890         }
891         params.quotes_language = lga;
892         if (fl_get_button(language_->radio_single))
893                 params.quotes_times = InsetQuotes::SingleQ;
894         else
895                 params.quotes_times = InsetQuotes::DoubleQ;
896
897         int const pos = combo_language->get();
898         Language const * old_language = params.language;
899         Language const * new_language = languages.getLanguage(lang_[pos-1]);
900         if (!new_language)
901                 new_language = default_language;
902
903         if (old_language != new_language
904             && old_language->RightToLeft() == new_language->RightToLeft()
905             && !lv_.buffer()->isMultiLingual())
906                 lv_.buffer()->changeLanguage(old_language, new_language);
907
908         if (old_language != new_language) {
909                 redo = true;
910         }
911
912         params.language = new_language;
913         params.inputenc = getString(language_->choice_inputenc);
914
915         return redo;
916 }
917
918
919 bool FormDocument::language_apply()
920 {
921         return language_apply(lv_.buffer()->params);
922 }
923
924
925 bool FormDocument::options_apply(BufferParams & params)
926 {
927         bool redo = false;
928
929         params.graphicsDriver = getString(options_->choice_postscript_driver);
930         params.use_amsmath = fl_get_button(options_->check_use_amsmath);
931         params.use_natbib  = fl_get_button(options_->check_use_natbib);
932         params.use_numerical_citations  =
933                 fl_get_choice(options_->choice_citation_format) - 1;
934
935         int tmpchar = int(fl_get_counter_value(options_->counter_secnumdepth));
936         if (params.secnumdepth != tmpchar)
937                 redo = true;
938         params.secnumdepth = tmpchar;
939
940         params.tocdepth = int(fl_get_counter_value(options_->counter_tocdepth));
941
942         params.float_placement =
943                 getString(options_->input_float_placement);
944
945         return redo;
946 }
947
948
949 bool FormDocument::options_apply()
950 {
951         return options_apply(lv_.buffer()->params);
952 }
953
954
955 void FormDocument::bullets_apply(BufferParams & params)
956 {
957         /* update the bullet settings */
958         BufferParams & buf_params = lv_.buffer()->params;
959
960         // a little bit of loop unrolling
961         params.user_defined_bullets[0] = buf_params.temp_bullets[0];
962         params.user_defined_bullets[1] = buf_params.temp_bullets[1];
963         params.user_defined_bullets[2] = buf_params.temp_bullets[2];
964         params.user_defined_bullets[3] = buf_params.temp_bullets[3];
965 }
966
967
968 void FormDocument::bullets_apply()
969 {
970         bullets_apply(lv_.buffer()->params);
971 }
972
973 void FormDocument::UpdateClassParams(BufferParams const & params)
974 {
975         // These are the params that have to be updated on any class change
976         // (even if the class defaults are not used) (JSpitzm 2002-04-08)
977
978         LyXTextClass const & tclass = textclasslist[params.textclass];
979
980         combo_doc_class->select(tclass.description());
981         fl_clear_choice(class_->choice_doc_fontsize);
982         fl_addto_choice(class_->choice_doc_fontsize, "default");
983         fl_addto_choice(class_->choice_doc_fontsize,
984                         tclass.opt_fontsize().c_str());
985         fl_set_choice_text(class_->choice_doc_fontsize,
986                         params.fontsize.c_str());
987         fl_clear_choice(class_->choice_doc_pagestyle);
988         fl_addto_choice(class_->choice_doc_pagestyle, "default");
989         fl_addto_choice(class_->choice_doc_pagestyle,
990                         tclass.opt_pagestyle().c_str());
991         fl_set_choice_text(class_->choice_doc_pagestyle,
992                         params.pagestyle.c_str());
993
994 }
995
996 void FormDocument::class_update(BufferParams const & params)
997 {
998         if (!class_.get())
999                 return;
1000
1001         UpdateClassParams(params);
1002
1003         fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
1004
1005         bool const indent = params.paragraph_separation == BufferParams::PARSEP_INDENT;
1006         fl_set_button(class_->radio_doc_indent, indent);
1007         fl_set_button(class_->radio_doc_skip, !indent);
1008
1009         int pos;
1010         if (indent) {
1011                 pos = 2; // VSpace::MEDSKIP is default
1012         } else {
1013                 switch (params.getDefSkip().kind()) {
1014                 case VSpace::LENGTH:
1015                         pos = 4;
1016                         break;
1017                 case VSpace::BIGSKIP:
1018                         pos = 3;
1019                         break;
1020                 case VSpace::SMALLSKIP:
1021                         pos = 1;
1022                         break;
1023                 case VSpace::MEDSKIP:
1024                 default:
1025                         pos = 2;
1026                         break;
1027                 }
1028         }
1029         fl_set_choice (class_->choice_doc_skip, pos);
1030
1031         bool const length_input = pos == 4;
1032         if (length_input) {
1033                 int const paperchoice = fl_get_choice(paper_->choice_papersize);
1034                 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
1035                         || paperchoice == 2 || paperchoice > 5;
1036                 string const default_unit = metric ? "cm" : "in";
1037                 string const length = params.getDefSkip().asLyXCommand();
1038                 updateWidgetsFromLengthString(class_->input_doc_skip,
1039                                               class_->choice_doc_skip_units,
1040                                               length, default_unit);
1041
1042         } else {
1043                 fl_set_input(class_->input_doc_skip, "");
1044         }
1045         setEnabled(class_->choice_doc_skip, !indent);
1046         setEnabled(class_->input_doc_skip, length_input);
1047         setEnabled(class_->choice_doc_skip_units, length_input);
1048
1049         bool const two_sides = params.sides == LyXTextClass::TwoSides;
1050         fl_set_button(class_->radio_doc_sides_one, !two_sides);
1051         fl_set_button(class_->radio_doc_sides_two, two_sides);
1052
1053         bool const two_columns = params.columns == 2;
1054         fl_set_button(class_->radio_doc_columns_one, !two_columns);
1055         fl_set_button(class_->radio_doc_columns_two, two_columns);
1056
1057         fl_set_input(class_->input_doc_extra, params.options.c_str());
1058
1059         switch (params.spacing.getSpace()) {
1060         case Spacing::Other:
1061                 pos = 4;
1062                 break;
1063         case Spacing::Double: // \doublespacing
1064                 pos = 3;
1065                 break;
1066         case Spacing::Onehalf: // \onehalfspacing
1067                 pos = 2;
1068                 break;
1069         case Spacing::Single: // \singlespacing
1070         case Spacing::Default: // nothing bad should happen with this
1071         default:
1072                 pos = 1;
1073                 break;
1074         }
1075         fl_set_choice(class_->choice_doc_spacing, pos);
1076
1077         bool const spacing_input = pos == 4;
1078         setEnabled(class_->input_doc_spacing, spacing_input);
1079         string const input = spacing_input ? tostr(params.spacing.getValue()) : string();
1080         fl_set_input(class_->input_doc_spacing, input.c_str());
1081 }
1082
1083
1084 void FormDocument::language_update(BufferParams const & params)
1085 {
1086         if (!language_.get())
1087                 return;
1088
1089         int const pos = int(findPos(lang_, params.language->lang()));
1090         combo_language->select(pos+1);
1091
1092         fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
1093         fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
1094         fl_set_button(language_->radio_single, 0);
1095         fl_set_button(language_->radio_double, 0);
1096         if (params.quotes_times == InsetQuotes::SingleQ)
1097                 fl_set_button(language_->radio_single, 1);
1098         else
1099                 fl_set_button(language_->radio_double, 1);
1100 }
1101
1102
1103 void FormDocument::options_update(BufferParams const & params)
1104 {
1105         if (!options_.get())
1106                 return;
1107
1108         fl_set_choice_text(options_->choice_postscript_driver,
1109                            params.graphicsDriver.c_str());
1110         fl_set_button(options_->check_use_amsmath, params.use_amsmath);
1111         fl_set_button(options_->check_use_natbib,  params.use_natbib);
1112         fl_set_choice(options_->choice_citation_format,
1113                       int(params.use_numerical_citations)+1);
1114         setEnabled(options_->choice_citation_format, params.use_natbib);
1115         fl_set_counter_value(options_->counter_secnumdepth, params.secnumdepth);
1116         fl_set_counter_value(options_->counter_tocdepth, params.tocdepth);
1117         if (!params.float_placement.empty())
1118                 fl_set_input(options_->input_float_placement,
1119                              params.float_placement.c_str());
1120         else
1121                 fl_set_input(options_->input_float_placement, "");
1122 }
1123
1124
1125 void FormDocument::paper_update(BufferParams const & params)
1126 {
1127         if (!paper_.get())
1128                 return;
1129
1130         fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
1131         fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
1132         fl_set_button(paper_->check_use_geometry, params.use_geometry);
1133
1134         int const paperchoice = fl_get_choice(paper_->choice_papersize);
1135         bool const useCustom = paperchoice == 2;
1136         bool const useGeom = fl_get_button(paper_->check_use_geometry);
1137
1138         fl_set_button(paper_->radio_portrait, 0);
1139         setEnabled(paper_->radio_portrait, !useCustom);
1140         fl_set_button(paper_->radio_landscape, 0);
1141         setEnabled(paper_->radio_landscape, !useCustom);
1142
1143         if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1144                 fl_set_button(paper_->radio_landscape, 1);
1145         else
1146                 fl_set_button(paper_->radio_portrait, 1);
1147         setEnabled(paper_->choice_paperpackage,
1148                    //either default papersize (preferences)
1149                    //or document papersize has to be A4
1150                    (paperchoice == 7
1151                     || paperchoice == 1 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER)
1152                    && fl_get_button(paper_->radio_portrait));
1153
1154         // Default unit choice is cm if metric, inches if US paper.
1155         bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
1156                 || paperchoice == 2 || paperchoice > 5;
1157         string const default_unit = metric ? "cm" : "in";
1158         updateWidgetsFromLengthString(paper_->input_custom_width,
1159                                       paper_->choice_custom_width_units,
1160                                       params.paperwidth, default_unit);
1161         setEnabled(paper_->input_custom_width, useCustom);
1162         setEnabled(paper_->choice_custom_width_units, useCustom);
1163
1164         updateWidgetsFromLengthString(paper_->input_custom_height,
1165                                       paper_->choice_custom_height_units,
1166                                       params.paperheight, default_unit);
1167         setEnabled(paper_->input_custom_height, useCustom);
1168         setEnabled(paper_->choice_custom_height_units, useCustom);
1169
1170         updateWidgetsFromLengthString(paper_->input_inner_margin,
1171                                       paper_->choice_inner_margin_units,
1172                                       params.leftmargin, default_unit);
1173         setEnabled(paper_->input_inner_margin, useGeom);
1174         setEnabled(paper_->choice_inner_margin_units, useGeom);
1175
1176         updateWidgetsFromLengthString(paper_->input_top_margin,
1177                                       paper_->choice_top_margin_units,
1178                                       params.topmargin, default_unit);
1179         setEnabled(paper_->input_top_margin, useGeom);
1180         setEnabled(paper_->choice_top_margin_units, useGeom);
1181
1182         updateWidgetsFromLengthString(paper_->input_outer_margin,
1183                                       paper_->choice_outer_margin_units,
1184                                       params.rightmargin, default_unit);
1185         setEnabled(paper_->input_outer_margin, useGeom);
1186         setEnabled(paper_->choice_outer_margin_units, useGeom);
1187
1188         updateWidgetsFromLengthString(paper_->input_bottom_margin,
1189                                       paper_->choice_bottom_margin_units,
1190                                       params.bottommargin, default_unit);
1191         setEnabled(paper_->input_bottom_margin, useGeom);
1192         setEnabled(paper_->choice_bottom_margin_units, useGeom);
1193
1194         updateWidgetsFromLengthString(paper_->input_head_height,
1195                                       paper_->choice_head_height_units,
1196                                       params.headheight, default_unit);
1197         setEnabled(paper_->input_head_height, useGeom);
1198         setEnabled(paper_->choice_head_height_units, useGeom);
1199
1200         updateWidgetsFromLengthString(paper_->input_head_sep,
1201                                       paper_->choice_head_sep_units,
1202                                       params.headsep, default_unit);
1203         setEnabled(paper_->input_head_sep, useGeom);
1204         setEnabled(paper_->choice_head_sep_units, useGeom);
1205
1206         updateWidgetsFromLengthString(paper_->input_foot_skip,
1207                                       paper_->choice_foot_skip_units,
1208                                       params.footskip, default_unit);
1209         setEnabled(paper_->input_foot_skip, useGeom);
1210         setEnabled(paper_->choice_foot_skip_units, useGeom);
1211
1212         fl_set_focus_object(paper_->form, paper_->choice_papersize);
1213 }
1214
1215
1216 void FormDocument::bullets_update(BufferParams const & params)
1217 {
1218         if (!bullets_.get() ||
1219             ((XpmVersion<4) ||
1220              (XpmVersion==4 && XpmRevision<7)))
1221                 return;
1222
1223         bool const isLinuxDoc = lv_.buffer()->isLinuxDoc();
1224         setEnabled(fbullet, !isLinuxDoc);
1225
1226         if (isLinuxDoc) return;
1227
1228         fl_set_button(bullets_->radio_bullet_depth_1, 1);
1229         fl_set_input(bullets_->input_bullet_latex,
1230                      params.user_defined_bullets[0].getText().c_str());
1231         fl_set_choice(bullets_->choice_bullet_size,
1232                       params.user_defined_bullets[0].getSize() + 2);
1233 }
1234
1235
1236 void FormDocument::checkReadOnly()
1237 {
1238         if (bc().readOnly(lv_.buffer()->isReadonly())) {
1239                 combo_doc_class->deactivate();
1240                 combo_language->deactivate();
1241                 postWarning(_("Document is read-only."
1242                               " No changes to layout permitted."));
1243         } else {
1244                 combo_doc_class->activate();
1245                 combo_language->activate();
1246                 clearMessage();
1247         }
1248 }
1249
1250
1251 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/)
1252 {
1253         BufferParams & param = lv_.buffer()->params;
1254
1255         // convert from 1-6 range to -1-4
1256         param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1257         fl_set_input(bullets_->input_bullet_latex,
1258                      param.temp_bullets[current_bullet_depth].getText().c_str());
1259 }
1260
1261
1262 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1263 {
1264         BufferParams & param = lv_.buffer()->params;
1265
1266         param.temp_bullets[current_bullet_depth].
1267                 setText(getString(bullets_->input_bullet_latex));
1268 }
1269
1270
1271 void FormDocument::BulletDepth(FL_OBJECT * ob)
1272 {
1273         /* Should I do the following:                                 */
1274         /*  1. change to the panel that the current bullet belongs in */
1275         /*  2. show that bullet as selected                           */
1276         /*  3. change the size setting to the size of the bullet in Q.*/
1277         /*  4. display the latex equivalent in the latex box          */
1278         /*                                                            */
1279         /* I'm inclined to just go with 3 and 4 at the moment and     */
1280         /* maybe try to support the others later                      */
1281         BufferParams & param = lv_.buffer()->params;
1282
1283         int data = 0;
1284         if (ob == bullets_->radio_bullet_depth_1)
1285                 data = 0;
1286         else if (ob == bullets_->radio_bullet_depth_2)
1287                 data = 1;
1288         else if (ob == bullets_->radio_bullet_depth_3)
1289                 data = 2;
1290         else if (ob == bullets_->radio_bullet_depth_4)
1291                 data = 3;
1292
1293         switch (fl_get_button_numb(ob)) {
1294         case 3:
1295                 // right mouse button resets to default
1296                 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1297         default:
1298                 current_bullet_depth = data;
1299                 fl_set_input(bullets_->input_bullet_latex,
1300                              param.temp_bullets[data].getText().c_str());
1301                 fl_set_choice(bullets_->choice_bullet_size,
1302                               param.temp_bullets[data].getSize() + 2);
1303         }
1304 }
1305
1306
1307 void FormDocument::BulletPanel(FL_OBJECT * ob)
1308 {
1309         /* Here we have to change the background pixmap to that selected */
1310         /* by the user. (eg. standard.xpm, psnfss1.xpm etc...)           */
1311
1312         int data = 0;
1313         if (ob == bullets_->radio_bullet_panel_standard)
1314                 data = 0;
1315         else if (ob == bullets_->radio_bullet_panel_maths)
1316                 data = 1;
1317         else if (ob == bullets_->radio_bullet_panel_ding2)
1318                 data = 2;
1319         else if (ob == bullets_->radio_bullet_panel_ding3)
1320                 data = 3;
1321         else if (ob == bullets_->radio_bullet_panel_ding4)
1322                 data = 4;
1323         else if (ob == bullets_->radio_bullet_panel_ding1)
1324                 data = 5;
1325
1326         if (data != current_bullet_panel) {
1327                 fl_freeze_form(bullets_->form);
1328                 current_bullet_panel = data;
1329
1330                 /* free the current pixmap */
1331                 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1332                 string new_panel;
1333                 if (ob == bullets_->radio_bullet_panel_standard) {
1334                         new_panel = "standard";
1335                 } else if (ob == bullets_->radio_bullet_panel_maths ) {
1336                         new_panel = "amssymb";
1337                 } else if (ob == bullets_->radio_bullet_panel_ding2) {
1338                         new_panel = "psnfss1";
1339                 } else if (ob == bullets_->radio_bullet_panel_ding3) {
1340                         new_panel = "psnfss2";
1341                 } else if (ob == bullets_->radio_bullet_panel_ding4) {
1342                         new_panel = "psnfss3";
1343                 } else if (ob == bullets_->radio_bullet_panel_ding1) {
1344                         new_panel = "psnfss4";
1345                 } else {
1346                         /* something very wrong happened */
1347                         // play it safe for now but should be an exception
1348                         current_bullet_panel = 0;  // standard panel
1349                         new_panel = "standard";
1350                 }
1351                 new_panel += ".xpm";
1352                 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1353                                            LibFileSearch("images", new_panel).c_str());
1354                 fl_redraw_object(bullets_->bmtable_bullet_panel);
1355                 fl_unfreeze_form(bullets_->form);
1356         }
1357 }
1358
1359
1360 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/)
1361 {
1362         /* handle the user input by setting the current bullet depth's pixmap */
1363         /* to that extracted from the current chosen position of the BMTable  */
1364         /* Don't forget to free the button's old pixmap first.                */
1365
1366         BufferParams & param = lv_.buffer()->params;
1367         int bmtable_button = fl_get_bmtable(ob);
1368
1369         /* try to keep the button held down till another is pushed */
1370         /*  fl_set_bmtable(ob, 1, bmtable_button); */
1371         param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1372         param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1373         fl_set_input(bullets_->input_bullet_latex,
1374                      param.temp_bullets[current_bullet_depth].getText().c_str());
1375 }
1376
1377
1378 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1379 {
1380         if (!ob)
1381                 ob = class_->choice_doc_class;
1382
1383         lv_.prohibitInput();
1384
1385         unsigned int tc = combo_doc_class->get() - 1;
1386         if (textclasslist[tc].load()) {
1387                 // we use a copy of the bufferparams because we do not
1388                 // want to modify them yet.
1389                 BufferParams params = lv_.buffer()->params;
1390
1391                 if (lyxrc.auto_reset_options) {
1392                         params.textclass = tc;
1393                         params.useClassDefaults();
1394                         UpdateLayoutDocument(params);
1395                 } else {
1396                         // update the params which are needed in any case
1397                         // (fontsizes, pagestyle)
1398                         params.textclass = tc;
1399                         UpdateClassParams(params);
1400                 }
1401
1402         } else {
1403                 // unable to load new style
1404                 Alert::alert(_("Conversion Errors!"),
1405                              _("Unable to switch to new document class."),
1406                              _("Reverting to original document class."));
1407                 combo_doc_class->select(int(lv_.buffer()->params.textclass) + 1);
1408         }
1409         lv_.allowInput();
1410 }
1411
1412
1413 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1414 {
1415         if (!dialog_.get())
1416                 return;
1417
1418         checkReadOnly();
1419         class_update(params);
1420         paper_update(params);
1421         language_update(params);
1422         options_update(params);
1423         bullets_update(params);
1424 }