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