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