]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormDocument.C
fix bug 844, and more
[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 | Smallest | Smaller | Small |"
330                           " Normal | Large | Larger | Largest | Huge | Huger "));
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                 if (!enable)
588                         fl_set_choice(paper_->choice_paperpackage,
589                                 BufferParams::PACKAGE_NONE + 1);
590                 setEnabled(paper_->choice_paperpackage, 
591                         enable && fl_get_button(paper_->radio_portrait));
592         }
593
594         return ButtonPolicy::SMI_VALID;
595 }
596
597
598 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
599 {
600         FormDocument * pre = static_cast<FormDocument*>(v);
601         if (combox == pre->combo_doc_class.get())
602                 pre->CheckChoiceClass();
603         pre->bc().valid();
604 }
605
606
607 bool FormDocument::class_apply(BufferParams &params)
608 {
609         bool redo = false;
610
611         // If default skip is a "Length" but there's no text in the
612         // input field, reset the kind to "MedSkip", which is the default.
613         if (fl_get_choice(class_->choice_doc_skip) == 4 &&
614             getString(class_->input_doc_skip).empty()) {
615                 fl_set_choice(class_->choice_doc_skip, 2);
616         }
617         params.fonts = getString(class_->choice_doc_fonts);
618         params.fontsize = getString(class_->choice_doc_fontsize);
619         params.pagestyle = getString(class_->choice_doc_pagestyle);
620
621         params.textclass = combo_doc_class->get() - 1;
622
623         BufferParams::PARSEP tmpsep = params.paragraph_separation;
624         if (fl_get_button(class_->radio_doc_indent))
625                 params.paragraph_separation = BufferParams::PARSEP_INDENT;
626         else
627                 params.paragraph_separation = BufferParams::PARSEP_SKIP;
628         if (tmpsep != params.paragraph_separation)
629                 redo = true;
630
631         VSpace tmpdefskip = params.getDefSkip();
632         switch (fl_get_choice(class_->choice_doc_skip)) {
633         case 1:
634                 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
635                 break;
636         case 2:
637                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
638                 break;
639         case 3:
640                 params.setDefSkip(VSpace(VSpace::BIGSKIP));
641                 break;
642         case 4:
643         {
644                 string const length =
645                         getLengthFromWidgets(class_->input_doc_skip,
646                                              class_->choice_doc_skip_units);
647
648                 params.setDefSkip(VSpace(LyXGlueLength(length)));
649                 break;
650         }
651         default:
652                 // DocumentDefskipCB assures that this never happens
653                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
654                 break;
655         }
656         if (!(tmpdefskip == params.getDefSkip()))
657                 redo = true;
658
659         if (fl_get_button(class_->radio_doc_columns_two))
660                 params.columns = 2;
661         else
662                 params.columns = 1;
663         if (fl_get_button(class_->radio_doc_sides_two))
664                 params.sides = LyXTextClass::TwoSides;
665         else
666                 params.sides = LyXTextClass::OneSide;
667
668         Spacing tmpSpacing = params.spacing;
669         switch (fl_get_choice(class_->choice_doc_spacing)) {
670         case 1:
671                 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
672                 params.spacing.set(Spacing::Single);
673                 break;
674         case 2:
675                 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
676                 params.spacing.set(Spacing::Onehalf);
677                 break;
678         case 3:
679                 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
680                 params.spacing.set(Spacing::Double);
681                 break;
682         case 4:
683                 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
684                 params.spacing.set(Spacing::Other,
685                                    getString(class_->input_doc_spacing));
686                 break;
687         }
688         if (tmpSpacing != params.spacing)
689                 redo = true;
690
691         params.options = getString(class_->input_doc_extra);
692
693         return redo;
694 }
695
696
697 void FormDocument::paper_apply(BufferParams & params)
698 {
699         params.papersize2 = char(fl_get_choice(paper_->choice_papersize) - 1);
700
701         params.paperpackage =
702                 char(fl_get_choice(paper_->choice_paperpackage) - 1);
703
704         // set params.papersize from params.papersize2 and params.paperpackage
705         params.setPaperStuff();
706
707         params.use_geometry = fl_get_button(paper_->check_use_geometry);
708
709         if (fl_get_button(paper_->radio_landscape))
710                 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
711         else
712                 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
713
714         params.paperwidth =
715                 getLengthFromWidgets(paper_->input_custom_width,
716                                      paper_->choice_custom_width_units);
717
718         params.paperheight =
719                 getLengthFromWidgets(paper_->input_custom_height,
720                                      paper_->choice_custom_height_units);
721
722         params.leftmargin =
723                 getLengthFromWidgets(paper_->input_inner_margin,
724                                      paper_->choice_inner_margin_units);
725
726         params.topmargin =
727                 getLengthFromWidgets(paper_->input_top_margin,
728                                      paper_->choice_top_margin_units);
729
730         params.rightmargin =
731                 getLengthFromWidgets(paper_->input_outer_margin,
732                                      paper_->choice_outer_margin_units);
733
734         params.bottommargin =
735                 getLengthFromWidgets(paper_->input_bottom_margin,
736                                      paper_->choice_bottom_margin_units);
737
738         params.headheight =
739                 getLengthFromWidgets(paper_->input_head_height,
740                                      paper_->choice_head_height_units);
741
742         params.headsep =
743                 getLengthFromWidgets(paper_->input_head_sep,
744                                      paper_->choice_head_sep_units);
745
746         params.footskip =
747                 getLengthFromWidgets(paper_->input_foot_skip,
748                                      paper_->choice_foot_skip_units);
749 }
750
751
752 bool FormDocument::language_apply(BufferParams & params)
753 {
754         InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
755         bool redo = false;
756
757         switch (fl_get_choice(language_->choice_quotes_language) - 1) {
758         case 0:
759                 lga = InsetQuotes::EnglishQ;
760                 break;
761         case 1:
762                 lga = InsetQuotes::SwedishQ;
763                 break;
764         case 2:
765                 lga = InsetQuotes::GermanQ;
766                 break;
767         case 3:
768                 lga = InsetQuotes::PolishQ;
769                 break;
770         case 4:
771                 lga = InsetQuotes::FrenchQ;
772                 break;
773         case 5:
774                 lga = InsetQuotes::DanishQ;
775                 break;
776         }
777         params.quotes_language = lga;
778         if (fl_get_button(language_->radio_single))
779                 params.quotes_times = InsetQuotes::SingleQ;
780         else
781                 params.quotes_times = InsetQuotes::DoubleQ;
782
783         int const pos = combo_language->get();
784         Language const * new_language = languages.getLanguage(lang_[pos-1]);
785         if (!new_language)
786                 new_language = default_language;
787
788         params.language = new_language;
789         params.inputenc = getString(language_->choice_inputenc);
790
791         return redo;
792 }
793
794
795 bool FormDocument::options_apply(BufferParams & params)
796 {
797         bool redo = false;
798
799         params.graphicsDriver = getString(options_->choice_postscript_driver);
800         params.use_amsmath = fl_get_button(options_->check_use_amsmath);
801         params.use_natbib  = fl_get_button(options_->check_use_natbib);
802         params.use_numerical_citations  =
803                 fl_get_choice(options_->choice_citation_format) - 1;
804
805         int tmpchar = int(fl_get_counter_value(options_->counter_secnumdepth));
806         if (params.secnumdepth != tmpchar)
807                 redo = true;
808         params.secnumdepth = tmpchar;
809
810         params.tocdepth = int(fl_get_counter_value(options_->counter_tocdepth));
811
812         params.float_placement =
813                 getString(options_->input_float_placement);
814
815         return redo;
816 }
817
818
819 void FormDocument::bullets_apply(BufferParams & params)
820 {
821         /* update the bullet settings */
822         BufferParams & buf_params = controller().params();
823
824         // a little bit of loop unrolling
825         params.user_defined_bullets[0] = buf_params.temp_bullets[0];
826         params.user_defined_bullets[1] = buf_params.temp_bullets[1];
827         params.user_defined_bullets[2] = buf_params.temp_bullets[2];
828         params.user_defined_bullets[3] = buf_params.temp_bullets[3];
829 }
830
831
832 void FormDocument::UpdateClassParams(BufferParams const & params)
833 {
834         // These are the params that have to be updated on any class change
835         // (even if the class defaults are not used) (JSpitzm 2002-04-08)
836
837         LyXTextClass const & tclass = textclasslist[params.textclass];
838
839         combo_doc_class->select(tclass.description());
840         fl_clear_choice(class_->choice_doc_fontsize);
841         fl_addto_choice(class_->choice_doc_fontsize, "default");
842         fl_addto_choice(class_->choice_doc_fontsize,
843                         tclass.opt_fontsize().c_str());
844         fl_set_choice_text(class_->choice_doc_fontsize,
845                         params.fontsize.c_str());
846         fl_clear_choice(class_->choice_doc_pagestyle);
847         fl_addto_choice(class_->choice_doc_pagestyle, "default");
848         fl_addto_choice(class_->choice_doc_pagestyle,
849                         tclass.opt_pagestyle().c_str());
850         fl_set_choice_text(class_->choice_doc_pagestyle,
851                         params.pagestyle.c_str());
852
853 }
854
855 void FormDocument::class_update(BufferParams const & params)
856 {
857         if (!class_.get())
858                 return;
859
860         UpdateClassParams(params);
861
862         fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
863
864         bool const indent = params.paragraph_separation == BufferParams::PARSEP_INDENT;
865         fl_set_button(class_->radio_doc_indent, indent);
866         fl_set_button(class_->radio_doc_skip, !indent);
867
868         int pos;
869         if (indent) {
870                 pos = 2; // VSpace::MEDSKIP is default
871         } else {
872                 switch (params.getDefSkip().kind()) {
873                 case VSpace::LENGTH:
874                         pos = 4;
875                         break;
876                 case VSpace::BIGSKIP:
877                         pos = 3;
878                         break;
879                 case VSpace::SMALLSKIP:
880                         pos = 1;
881                         break;
882                 case VSpace::MEDSKIP:
883                 default:
884                         pos = 2;
885                         break;
886                 }
887         }
888         fl_set_choice (class_->choice_doc_skip, pos);
889
890         bool const length_input = pos == 4;
891         if (length_input) {
892                 int const paperchoice = fl_get_choice(paper_->choice_papersize);
893                 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
894                         || paperchoice == 2 || paperchoice > 5;
895                 string const default_unit = metric ? "cm" : "in";
896                 string const length = params.getDefSkip().asLyXCommand();
897                 updateWidgetsFromLengthString(class_->input_doc_skip,
898                                               class_->choice_doc_skip_units,
899                                               length, default_unit);
900
901         } else {
902                 fl_set_input(class_->input_doc_skip, "");
903         }
904         setEnabled(class_->choice_doc_skip, !indent);
905         setEnabled(class_->input_doc_skip, length_input);
906         setEnabled(class_->choice_doc_skip_units, length_input);
907
908         bool const two_sides = params.sides == LyXTextClass::TwoSides;
909         fl_set_button(class_->radio_doc_sides_one, !two_sides);
910         fl_set_button(class_->radio_doc_sides_two, two_sides);
911
912         bool const two_columns = params.columns == 2;
913         fl_set_button(class_->radio_doc_columns_one, !two_columns);
914         fl_set_button(class_->radio_doc_columns_two, two_columns);
915
916         fl_set_input(class_->input_doc_extra, params.options.c_str());
917
918         switch (params.spacing.getSpace()) {
919         case Spacing::Other:
920                 pos = 4;
921                 break;
922         case Spacing::Double: // \doublespacing
923                 pos = 3;
924                 break;
925         case Spacing::Onehalf: // \onehalfspacing
926                 pos = 2;
927                 break;
928         case Spacing::Single: // \singlespacing
929         case Spacing::Default: // nothing bad should happen with this
930         default:
931                 pos = 1;
932                 break;
933         }
934         fl_set_choice(class_->choice_doc_spacing, pos);
935
936         bool const spacing_input = pos == 4;
937         setEnabled(class_->input_doc_spacing, spacing_input);
938         string const input = spacing_input ? tostr(params.spacing.getValue()) : string();
939         fl_set_input(class_->input_doc_spacing, input.c_str());
940 }
941
942
943 void FormDocument::language_update(BufferParams const & params)
944 {
945         if (!language_.get())
946                 return;
947
948         int const pos = int(findPos(lang_, params.language->lang()));
949         combo_language->select(pos+1);
950
951         fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
952         fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
953         fl_set_button(language_->radio_single, 0);
954         fl_set_button(language_->radio_double, 0);
955         if (params.quotes_times == InsetQuotes::SingleQ)
956                 fl_set_button(language_->radio_single, 1);
957         else
958                 fl_set_button(language_->radio_double, 1);
959 }
960
961
962 void FormDocument::options_update(BufferParams const & params)
963 {
964         if (!options_.get())
965                 return;
966
967         fl_set_choice_text(options_->choice_postscript_driver,
968                            params.graphicsDriver.c_str());
969         fl_set_button(options_->check_use_amsmath, params.use_amsmath);
970         fl_set_button(options_->check_use_natbib,  params.use_natbib);
971         fl_set_choice(options_->choice_citation_format,
972                       int(params.use_numerical_citations)+1);
973         setEnabled(options_->choice_citation_format, params.use_natbib);
974         fl_set_counter_value(options_->counter_secnumdepth, params.secnumdepth);
975         fl_set_counter_value(options_->counter_tocdepth, params.tocdepth);
976         if (!params.float_placement.empty())
977                 fl_set_input(options_->input_float_placement,
978                              params.float_placement.c_str());
979         else
980                 fl_set_input(options_->input_float_placement, "");
981 }
982
983
984 void FormDocument::paper_update(BufferParams const & params)
985 {
986         if (!paper_.get())
987                 return;
988
989         fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
990         fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
991         fl_set_button(paper_->check_use_geometry, params.use_geometry);
992
993         int const paperchoice = fl_get_choice(paper_->choice_papersize);
994         bool const useCustom = paperchoice == 2;
995         bool const useGeom = fl_get_button(paper_->check_use_geometry);
996
997         fl_set_button(paper_->radio_portrait, 0);
998         setEnabled(paper_->radio_portrait, !useCustom);
999         fl_set_button(paper_->radio_landscape, 0);
1000         setEnabled(paper_->radio_landscape, !useCustom);
1001
1002         if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1003                 fl_set_button(paper_->radio_landscape, 1);
1004         else
1005                 fl_set_button(paper_->radio_portrait, 1);
1006         setEnabled(paper_->choice_paperpackage,
1007                    //either default papersize (preferences)
1008                    //or document papersize has to be A4
1009                    (paperchoice == 7
1010                     || paperchoice == 1 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER)
1011                    && fl_get_button(paper_->radio_portrait));
1012
1013         // Default unit choice is cm if metric, inches if US paper.
1014         bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
1015                 || paperchoice == 2 || paperchoice > 5;
1016         string const default_unit = metric ? "cm" : "in";
1017         updateWidgetsFromLengthString(paper_->input_custom_width,
1018                                       paper_->choice_custom_width_units,
1019                                       params.paperwidth, default_unit);
1020         setEnabled(paper_->input_custom_width, useCustom);
1021         setEnabled(paper_->choice_custom_width_units, useCustom);
1022
1023         updateWidgetsFromLengthString(paper_->input_custom_height,
1024                                       paper_->choice_custom_height_units,
1025                                       params.paperheight, default_unit);
1026         setEnabled(paper_->input_custom_height, useCustom);
1027         setEnabled(paper_->choice_custom_height_units, useCustom);
1028
1029         updateWidgetsFromLengthString(paper_->input_inner_margin,
1030                                       paper_->choice_inner_margin_units,
1031                                       params.leftmargin, default_unit);
1032         setEnabled(paper_->input_inner_margin, useGeom);
1033         setEnabled(paper_->choice_inner_margin_units, useGeom);
1034
1035         updateWidgetsFromLengthString(paper_->input_top_margin,
1036                                       paper_->choice_top_margin_units,
1037                                       params.topmargin, default_unit);
1038         setEnabled(paper_->input_top_margin, useGeom);
1039         setEnabled(paper_->choice_top_margin_units, useGeom);
1040
1041         updateWidgetsFromLengthString(paper_->input_outer_margin,
1042                                       paper_->choice_outer_margin_units,
1043                                       params.rightmargin, default_unit);
1044         setEnabled(paper_->input_outer_margin, useGeom);
1045         setEnabled(paper_->choice_outer_margin_units, useGeom);
1046
1047         updateWidgetsFromLengthString(paper_->input_bottom_margin,
1048                                       paper_->choice_bottom_margin_units,
1049                                       params.bottommargin, default_unit);
1050         setEnabled(paper_->input_bottom_margin, useGeom);
1051         setEnabled(paper_->choice_bottom_margin_units, useGeom);
1052
1053         updateWidgetsFromLengthString(paper_->input_head_height,
1054                                       paper_->choice_head_height_units,
1055                                       params.headheight, default_unit);
1056         setEnabled(paper_->input_head_height, useGeom);
1057         setEnabled(paper_->choice_head_height_units, useGeom);
1058
1059         updateWidgetsFromLengthString(paper_->input_head_sep,
1060                                       paper_->choice_head_sep_units,
1061                                       params.headsep, default_unit);
1062         setEnabled(paper_->input_head_sep, useGeom);
1063         setEnabled(paper_->choice_head_sep_units, useGeom);
1064
1065         updateWidgetsFromLengthString(paper_->input_foot_skip,
1066                                       paper_->choice_foot_skip_units,
1067                                       params.footskip, default_unit);
1068         setEnabled(paper_->input_foot_skip, useGeom);
1069         setEnabled(paper_->choice_foot_skip_units, useGeom);
1070
1071         fl_set_focus_object(paper_->form, paper_->choice_papersize);
1072 }
1073
1074
1075 void FormDocument::bullets_update(BufferParams const & params)
1076 {
1077         if (!bullets_.get() ||
1078             ((XpmVersion<4) ||
1079              (XpmVersion==4 && XpmRevision<7)))
1080                 return;
1081
1082         bool const isLinuxDoc =
1083                 controller().docType() == ControlDocument::LINUXDOC;
1084         setEnabled(fbullet, !isLinuxDoc);
1085
1086         if (isLinuxDoc) return;
1087
1088         fl_set_button(bullets_->radio_bullet_depth_1, 1);
1089         fl_set_input(bullets_->input_bullet_latex,
1090                      params.user_defined_bullets[0].getText().c_str());
1091         fl_set_choice(bullets_->choice_bullet_size,
1092                       params.user_defined_bullets[0].getSize() + 2);
1093 }
1094
1095
1096 void FormDocument::checkReadOnly()
1097 {
1098         if (bc().readOnly(controller().bufferIsReadonly())) {
1099                 combo_doc_class->deactivate();
1100                 combo_language->deactivate();
1101                 postWarning(_("Document is read-only."
1102                               " No changes to layout permitted."));
1103         } else {
1104                 combo_doc_class->activate();
1105                 combo_language->activate();
1106                 clearMessage();
1107         }
1108 }
1109
1110
1111 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/)
1112 {
1113         BufferParams & param = controller().params();
1114
1115         // convert from 1-6 range to -1-4
1116         param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1117         fl_set_input(bullets_->input_bullet_latex,
1118                      param.temp_bullets[current_bullet_depth].getText().c_str());
1119 }
1120
1121
1122 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1123 {
1124         BufferParams & param = controller().params();
1125
1126         param.temp_bullets[current_bullet_depth].
1127                 setText(getString(bullets_->input_bullet_latex));
1128 }
1129
1130
1131 void FormDocument::BulletDepth(FL_OBJECT * ob)
1132 {
1133         /* Should I do the following:                                 */
1134         /*  1. change to the panel that the current bullet belongs in */
1135         /*  2. show that bullet as selected                           */
1136         /*  3. change the size setting to the size of the bullet in Q.*/
1137         /*  4. display the latex equivalent in the latex box          */
1138         /*                                                            */
1139         /* I'm inclined to just go with 3 and 4 at the moment and     */
1140         /* maybe try to support the others later                      */
1141         BufferParams & param = controller().params();
1142
1143         int data = 0;
1144         if (ob == bullets_->radio_bullet_depth_1)
1145                 data = 0;
1146         else if (ob == bullets_->radio_bullet_depth_2)
1147                 data = 1;
1148         else if (ob == bullets_->radio_bullet_depth_3)
1149                 data = 2;
1150         else if (ob == bullets_->radio_bullet_depth_4)
1151                 data = 3;
1152
1153         switch (fl_get_button_numb(ob)) {
1154         case 3:
1155                 // right mouse button resets to default
1156                 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1157         default:
1158                 current_bullet_depth = data;
1159                 fl_set_input(bullets_->input_bullet_latex,
1160                              param.temp_bullets[data].getText().c_str());
1161                 fl_set_choice(bullets_->choice_bullet_size,
1162                               param.temp_bullets[data].getSize() + 2);
1163         }
1164 }
1165
1166
1167 void FormDocument::BulletPanel(FL_OBJECT * ob)
1168 {
1169         /* Here we have to change the background pixmap to that selected */
1170         /* by the user. (eg. standard.xpm, psnfss1.xpm etc...)           */
1171
1172         int data = 0;
1173         if (ob == bullets_->radio_bullet_panel_standard)
1174                 data = 0;
1175         else if (ob == bullets_->radio_bullet_panel_maths)
1176                 data = 1;
1177         else if (ob == bullets_->radio_bullet_panel_ding2)
1178                 data = 2;
1179         else if (ob == bullets_->radio_bullet_panel_ding3)
1180                 data = 3;
1181         else if (ob == bullets_->radio_bullet_panel_ding4)
1182                 data = 4;
1183         else if (ob == bullets_->radio_bullet_panel_ding1)
1184                 data = 5;
1185
1186         if (data != current_bullet_panel) {
1187                 fl_freeze_form(bullets_->form);
1188                 current_bullet_panel = data;
1189
1190                 /* free the current pixmap */
1191                 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1192                 string new_panel;
1193                 if (ob == bullets_->radio_bullet_panel_standard) {
1194                         new_panel = "standard";
1195                 } else if (ob == bullets_->radio_bullet_panel_maths ) {
1196                         new_panel = "amssymb";
1197                 } else if (ob == bullets_->radio_bullet_panel_ding2) {
1198                         new_panel = "psnfss1";
1199                 } else if (ob == bullets_->radio_bullet_panel_ding3) {
1200                         new_panel = "psnfss2";
1201                 } else if (ob == bullets_->radio_bullet_panel_ding4) {
1202                         new_panel = "psnfss3";
1203                 } else if (ob == bullets_->radio_bullet_panel_ding1) {
1204                         new_panel = "psnfss4";
1205                 } else {
1206                         /* something very wrong happened */
1207                         // play it safe for now but should be an exception
1208                         current_bullet_panel = 0;  // standard panel
1209                         new_panel = "standard";
1210                 }
1211                 new_panel += ".xpm";
1212                 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1213                                            LibFileSearch("images", new_panel).c_str());
1214                 fl_redraw_object(bullets_->bmtable_bullet_panel);
1215                 fl_unfreeze_form(bullets_->form);
1216         }
1217 }
1218
1219
1220 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/)
1221 {
1222         /* handle the user input by setting the current bullet depth's pixmap */
1223         /* to that extracted from the current chosen position of the BMTable  */
1224         /* Don't forget to free the button's old pixmap first.                */
1225
1226         BufferParams & param = controller().params();
1227         int bmtable_button = fl_get_bmtable(ob);
1228
1229         /* try to keep the button held down till another is pushed */
1230         /*  fl_set_bmtable(ob, 1, bmtable_button); */
1231         param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1232         param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1233         fl_set_input(bullets_->input_bullet_latex,
1234                      param.temp_bullets[current_bullet_depth].getText().c_str());
1235 }
1236
1237
1238 void FormDocument::CheckChoiceClass()
1239 {
1240         BufferParams & params = controller().params();
1241
1242         lyx::textclass_type const tc = combo_doc_class->get() - 1;
1243
1244         if (controller().loadTextclass(tc)) {
1245                 params.textclass = tc;
1246
1247                 if (lyxrc.auto_reset_options) {
1248                         params.useClassDefaults();
1249                         UpdateLayoutDocument(params);
1250                 } else {
1251                         // update the params which are needed in any case
1252                         // (fontsizes, pagestyle)
1253                         UpdateClassParams(params);
1254                 }
1255
1256         } else {
1257                 int const revert = int(params.textclass);
1258                 combo_doc_class->select(revert + 1);
1259         }
1260 }
1261
1262
1263 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1264 {
1265         if (!dialog_.get())
1266                 return;
1267
1268         checkReadOnly();
1269         class_update(params);
1270         paper_update(params);
1271         language_update(params);
1272         options_update(params);
1273         bullets_update(params);
1274 }