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