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