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