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