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