]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormDocument.C
John's AMS patch
[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
15 #include "ControlDocument.h"
16 #include "FormDocument.h"
17 #include "forms/form_document.h"
18 #include "xformsBC.h"
19
20 #include "bmtable.h"
21 #include "checkedwidgets.h"
22 #include "combox.h"
23 #include "input_validators.h" // fl_unsigned_float_filter
24 #include "xforms_helpers.h"
25
26 //#include "buffer.h"
27 //#include "BufferView.h"
28 #include "CutAndPaste.h"
29 #include "debug.h"
30 #include "language.h"
31 //#include "lyx_main.h" // for user_lyxdir
32 #include "lyxrc.h"
33 #include "lyxtextclasslist.h"
34 #include "tex-strings.h"
35
36 #include "controllers/frnt_lang.h"
37 #include "controllers/helper_funcs.h"
38
39 #include "support/lstrings.h" // contains_functor, getStringFromVector
40 #include "support/filetools.h" // LibFileSearch
41
42 #include XPM_H_LOCATION
43 #include FORMS_H_LOCATION
44
45 #include <boost/bind.hpp>
46
47 #include <functional>
48
49 using std::bind2nd;
50 using std::vector;
51
52
53 typedef FormCB<ControlDocument, FormDB<FD_document> > base_class;
54
55 FormDocument::FormDocument()
56         : base_class(_("Document Layout"), false),
57           ActCell(0), Confirmed(0),
58           current_bullet_panel(0), current_bullet_depth(0), fbullet(0)
59 {}
60
61
62 void FormDocument::redraw()
63 {
64         if (form() && form()->visible)
65                 fl_redraw_form(form());
66         else
67                 return;
68
69         FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder);
70         if (outer_form && outer_form->visible)
71                 fl_redraw_form(outer_form);
72 }
73
74
75 void FormDocument::build()
76 {
77         // the tabbed folder
78         dialog_.reset(build_document(this));
79
80         // Allow the base class to control messages
81         setMessageWidget(dialog_->text_warning);
82
83         // Manage the restore, ok, apply, restore and cancel/close buttons
84         bc().setOK(dialog_->button_ok);
85         bc().setApply(dialog_->button_apply);
86         bc().setCancel(dialog_->button_close);
87         bc().setRestore(dialog_->button_restore);
88
89         // the document class form
90         class_.reset(build_document_class(this));
91
92         // disable for read-only documents
93         bc().addReadOnly(class_->radio_doc_indent);
94         bc().addReadOnly(class_->radio_doc_skip);
95         bc().addReadOnly(class_->choice_doc_pagestyle);
96         bc().addReadOnly(class_->choice_doc_fonts);
97         bc().addReadOnly(class_->choice_doc_fontsize);
98         bc().addReadOnly(class_->radio_doc_sides_one);
99         bc().addReadOnly(class_->radio_doc_sides_two);
100         bc().addReadOnly(class_->radio_doc_columns_one);
101         bc().addReadOnly(class_->radio_doc_columns_two);
102         bc().addReadOnly(class_->input_doc_extra);
103         bc().addReadOnly(class_->input_doc_skip);
104         bc().addReadOnly(class_->choice_doc_skip);
105         bc().addReadOnly(class_->choice_doc_spacing);
106         bc().addReadOnly(class_->input_doc_spacing);
107
108         // check validity of "length + unit" input
109         addCheckedGlueLength(bc(), class_->input_doc_skip,
110                              class_->choice_doc_skip);
111
112         // trigger an input event for cut&paste with middle mouse button.
113         setPrehandler(class_->input_doc_extra);
114         setPrehandler(class_->input_doc_skip);
115         setPrehandler(class_->input_doc_spacing);
116
117         fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
118         fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
119         fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
120
121         FL_OBJECT * obj;
122
123         // the class list is a combo-box and has to be inserted manually
124         obj = class_->choice_doc_class;
125         fl_deactivate_object(obj);
126         fl_addto_form(class_->form);
127         combo_doc_class.reset(new Combox(FL_COMBOX_DROPLIST));
128         combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400);
129         combo_doc_class->shortcut("#C",1);
130         combo_doc_class->setcallback(ComboInputCB, this);
131         fl_end_form();
132         for (LyXTextClassList::const_iterator cit = textclasslist.begin();
133              cit != textclasslist.end(); ++cit) {
134                 combo_doc_class->addto(cit->description());
135         }
136
137         fl_addto_choice(class_->choice_doc_spacing,
138                         _(" Single | OneHalf | Double | Custom "));
139         fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
140         for (int n = 0; tex_fonts[n][0]; ++n) {
141                 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
142         }
143
144         // Create the contents of the unit choices; don't include the
145         // "%" terms...
146         vector<string> units_vec = getLatexUnits();
147         vector<string>::iterator ret =
148                 std::remove_if(units_vec.begin(),
149                                units_vec.end(),
150                                bind2nd(contains_functor(), "%"));
151         units_vec.erase(ret, units_vec.end());
152
153         string const units = getStringFromVector(units_vec, "|");
154
155         fl_addto_choice(class_->choice_doc_pagestyle,
156                         "default|empty|plain|headings|fancy");
157         fl_addto_choice(class_->choice_doc_skip,
158                         _(" SmallSkip | MedSkip | BigSkip | Length "));
159         fl_addto_choice(class_->choice_doc_skip_units,  units.c_str());
160
161         // Set input filters on doc spacing to make it accept only
162         // unsigned numbers.
163         fl_set_input_filter(class_->input_doc_spacing,
164                             fl_unsigned_float_filter);
165
166         // disable for read-only documents
167         bc().addReadOnly(dialog_->button_save_defaults);
168         bc().addReadOnly(dialog_->button_reset_defaults);
169
170         // the document paper form
171         paper_.reset(build_document_paper(this));
172
173         // disable for read-only documents
174         bc().addReadOnly(paper_->choice_paperpackage);
175         bc().addReadOnly(paper_->radio_portrait);
176         bc().addReadOnly(paper_->radio_landscape);
177         bc().addReadOnly(paper_->choice_papersize);
178         bc().addReadOnly(paper_->check_use_geometry);
179         bc().addReadOnly(paper_->input_custom_width);
180         bc().addReadOnly(paper_->input_custom_height);
181         bc().addReadOnly(paper_->input_top_margin);
182         bc().addReadOnly(paper_->input_bottom_margin);
183         bc().addReadOnly(paper_->input_inner_margin);
184         bc().addReadOnly(paper_->input_outer_margin);
185         bc().addReadOnly(paper_->input_head_height);
186         bc().addReadOnly(paper_->input_head_sep);
187         bc().addReadOnly(paper_->input_foot_skip);
188
189         // check validity of "length + unit" input
190         addCheckedGlueLength(bc(), paper_->input_custom_width);
191         addCheckedGlueLength(bc(), paper_->input_custom_height);
192         addCheckedGlueLength(bc(), paper_->input_top_margin);
193         addCheckedGlueLength(bc(), paper_->input_bottom_margin);
194         addCheckedGlueLength(bc(), paper_->input_inner_margin);
195         addCheckedGlueLength(bc(), paper_->input_outer_margin);
196         addCheckedGlueLength(bc(), paper_->input_head_height);
197         addCheckedGlueLength(bc(), paper_->input_head_sep);
198         addCheckedGlueLength(bc(), paper_->input_foot_skip);
199
200         // trigger an input event for cut&paste with middle mouse button.
201         setPrehandler(paper_->input_custom_width);
202         setPrehandler(paper_->input_custom_height);
203         setPrehandler(paper_->input_top_margin);
204         setPrehandler(paper_->input_bottom_margin);
205         setPrehandler(paper_->input_inner_margin);
206         setPrehandler(paper_->input_outer_margin);
207         setPrehandler(paper_->input_head_height);
208         setPrehandler(paper_->input_head_sep);
209         setPrehandler(paper_->input_foot_skip);
210
211         fl_set_input_return(paper_->input_custom_width,  FL_RETURN_CHANGED);
212         fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
213         fl_set_input_return(paper_->input_top_margin,    FL_RETURN_CHANGED);
214         fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
215         fl_set_input_return(paper_->input_inner_margin,  FL_RETURN_CHANGED);
216         fl_set_input_return(paper_->input_outer_margin,  FL_RETURN_CHANGED);
217         fl_set_input_return(paper_->input_head_height,   FL_RETURN_CHANGED);
218         fl_set_input_return(paper_->input_head_sep,      FL_RETURN_CHANGED);
219         fl_set_input_return(paper_->input_foot_skip,     FL_RETURN_CHANGED);
220
221         fl_addto_choice(paper_->choice_papersize,
222                         _(" Default | Custom | US letter | US legal "
223                           "| US executive | A3 | A4 | A5 | B3 | B4 | B5 "));
224         fl_addto_choice(paper_->choice_paperpackage,
225                         _(" None "
226                           "| Small Margins "
227                           "| Very small Margins "
228                           "| Very wide Margins "));
229
230         fl_addto_choice(paper_->choice_custom_width_units,  units.c_str());
231         fl_addto_choice(paper_->choice_custom_height_units, units.c_str());
232         fl_addto_choice(paper_->choice_top_margin_units,    units.c_str());
233         fl_addto_choice(paper_->choice_bottom_margin_units, units.c_str());
234         fl_addto_choice(paper_->choice_inner_margin_units,  units.c_str());
235         fl_addto_choice(paper_->choice_outer_margin_units,  units.c_str());
236         fl_addto_choice(paper_->choice_head_height_units,   units.c_str());
237         fl_addto_choice(paper_->choice_head_sep_units,      units.c_str());
238         fl_addto_choice(paper_->choice_foot_skip_units,     units.c_str());
239
240         // the document language form
241         language_.reset(build_document_language(this));
242
243         // disable for read-only documents
244         bc().addReadOnly(language_->choice_inputenc);
245         bc().addReadOnly(language_->choice_quotes_language);
246         bc().addReadOnly(language_->radio_single);
247         bc().addReadOnly(language_->radio_double);
248
249         fl_addto_choice(language_->choice_inputenc,
250                         "default|auto|latin1|latin2|latin3|latin4|latin5|latin9"
251                         "|koi8-r|koi8-u|cp866|cp1251|iso88595|pt154");
252
253         vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
254         // Store the identifiers for later
255         lang_ = getSecond(langs);
256
257         // The language is a combo-box and has to be inserted manually
258         obj = language_->choice_language;
259         fl_deactivate_object(obj);
260         fl_addto_form(language_->form);
261         combo_language.reset(new Combox(FL_COMBOX_DROPLIST));
262         combo_language->add(obj->x, obj->y, obj->w, obj->h, 400);
263         combo_language->shortcut("#L",1);
264         combo_language->setcallback(ComboInputCB, this);
265         fl_end_form();
266
267         vector<frnt::LanguagePair>::const_iterator lit  = langs.begin();
268         vector<frnt::LanguagePair>::const_iterator lend = langs.end();
269         for (; lit != lend; ++lit) {
270                 combo_language->addto(lit->first);
271         }
272         combo_language->select(1);
273
274         fl_addto_choice(language_->choice_quotes_language,
275                         _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
276                           " «text» | »text« "));
277
278         // the document options form
279         options_.reset(build_document_options(this));
280
281         // disable for read-only documents
282         bc().addReadOnly(options_->counter_secnumdepth);
283         bc().addReadOnly(options_->counter_tocdepth);
284         bc().addReadOnly(options_->choice_ams_math);
285         bc().addReadOnly(options_->check_use_natbib);
286         bc().addReadOnly(options_->choice_citation_format);
287         bc().addReadOnly(options_->input_float_placement);
288         bc().addReadOnly(options_->choice_postscript_driver);
289
290         // trigger an input event for cut&paste with middle mouse button.
291         setPrehandler(options_->input_float_placement);
292
293         fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
294
295         fl_addto_choice(options_->choice_ams_math, 
296                 _("Never | Automatically | Yes "));
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 = static_cast<BufferParams::AMS>(
801                 fl_get_choice(options_->choice_ams_math) - 1);
802         params.use_natbib  = fl_get_button(options_->check_use_natbib);
803         params.use_numerical_citations  =
804                 fl_get_choice(options_->choice_citation_format) - 1;
805
806         int tmpchar = int(fl_get_counter_value(options_->counter_secnumdepth));
807         if (params.secnumdepth != tmpchar)
808                 redo = true;
809         params.secnumdepth = tmpchar;
810
811         params.tocdepth = int(fl_get_counter_value(options_->counter_tocdepth));
812
813         params.float_placement =
814                 getString(options_->input_float_placement);
815
816         return redo;
817 }
818
819
820 void FormDocument::bullets_apply(BufferParams & params)
821 {
822         /* update the bullet settings */
823         BufferParams & buf_params = controller().params();
824
825         // a little bit of loop unrolling
826         params.user_defined_bullets[0] = buf_params.temp_bullets[0];
827         params.user_defined_bullets[1] = buf_params.temp_bullets[1];
828         params.user_defined_bullets[2] = buf_params.temp_bullets[2];
829         params.user_defined_bullets[3] = buf_params.temp_bullets[3];
830 }
831
832
833 void FormDocument::UpdateClassParams(BufferParams const & params)
834 {
835         // These are the params that have to be updated on any class change
836         // (even if the class defaults are not used) (JSpitzm 2002-04-08)
837
838         LyXTextClass const & tclass = textclasslist[params.textclass];
839
840         combo_doc_class->select(tclass.description());
841         fl_clear_choice(class_->choice_doc_fontsize);
842         fl_addto_choice(class_->choice_doc_fontsize, "default");
843         fl_addto_choice(class_->choice_doc_fontsize,
844                         tclass.opt_fontsize().c_str());
845         fl_set_choice_text(class_->choice_doc_fontsize,
846                         params.fontsize.c_str());
847         fl_clear_choice(class_->choice_doc_pagestyle);
848         fl_addto_choice(class_->choice_doc_pagestyle, "default");
849         fl_addto_choice(class_->choice_doc_pagestyle,
850                         tclass.opt_pagestyle().c_str());
851         fl_set_choice_text(class_->choice_doc_pagestyle,
852                         params.pagestyle.c_str());
853
854 }
855
856 void FormDocument::class_update(BufferParams const & params)
857 {
858         if (!class_.get())
859                 return;
860
861         UpdateClassParams(params);
862
863         fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
864
865         bool const indent = params.paragraph_separation == BufferParams::PARSEP_INDENT;
866         fl_set_button(class_->radio_doc_indent, indent);
867         fl_set_button(class_->radio_doc_skip, !indent);
868
869         int pos;
870         if (indent) {
871                 pos = 2; // VSpace::MEDSKIP is default
872         } else {
873                 switch (params.getDefSkip().kind()) {
874                 case VSpace::LENGTH:
875                         pos = 4;
876                         break;
877                 case VSpace::BIGSKIP:
878                         pos = 3;
879                         break;
880                 case VSpace::SMALLSKIP:
881                         pos = 1;
882                         break;
883                 case VSpace::MEDSKIP:
884                 default:
885                         pos = 2;
886                         break;
887                 }
888         }
889         fl_set_choice (class_->choice_doc_skip, pos);
890
891         bool const length_input = pos == 4;
892         if (length_input) {
893                 int const paperchoice = fl_get_choice(paper_->choice_papersize);
894                 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
895                         || paperchoice == 2 || paperchoice > 5;
896                 string const default_unit = metric ? "cm" : "in";
897                 string const length = params.getDefSkip().asLyXCommand();
898                 updateWidgetsFromLengthString(class_->input_doc_skip,
899                                               class_->choice_doc_skip_units,
900                                               length, default_unit);
901
902         } else {
903                 fl_set_input(class_->input_doc_skip, "");
904         }
905         setEnabled(class_->choice_doc_skip, !indent);
906         setEnabled(class_->input_doc_skip, length_input);
907         setEnabled(class_->choice_doc_skip_units, length_input);
908
909         bool const two_sides = params.sides == LyXTextClass::TwoSides;
910         fl_set_button(class_->radio_doc_sides_one, !two_sides);
911         fl_set_button(class_->radio_doc_sides_two, two_sides);
912
913         bool const two_columns = params.columns == 2;
914         fl_set_button(class_->radio_doc_columns_one, !two_columns);
915         fl_set_button(class_->radio_doc_columns_two, two_columns);
916
917         fl_set_input(class_->input_doc_extra, params.options.c_str());
918
919         switch (params.spacing.getSpace()) {
920         case Spacing::Other:
921                 pos = 4;
922                 break;
923         case Spacing::Double: // \doublespacing
924                 pos = 3;
925                 break;
926         case Spacing::Onehalf: // \onehalfspacing
927                 pos = 2;
928                 break;
929         case Spacing::Single: // \singlespacing
930         case Spacing::Default: // nothing bad should happen with this
931         default:
932                 pos = 1;
933                 break;
934         }
935         fl_set_choice(class_->choice_doc_spacing, pos);
936
937         bool const spacing_input = pos == 4;
938         setEnabled(class_->input_doc_spacing, spacing_input);
939         string const input = spacing_input ? tostr(params.spacing.getValue()) : string();
940         fl_set_input(class_->input_doc_spacing, input.c_str());
941 }
942
943
944 void FormDocument::language_update(BufferParams const & params)
945 {
946         if (!language_.get())
947                 return;
948
949         int const pos = int(findPos(lang_, params.language->lang()));
950         combo_language->select(pos+1);
951
952         fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
953         fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
954         fl_set_button(language_->radio_single, 0);
955         fl_set_button(language_->radio_double, 0);
956         if (params.quotes_times == InsetQuotes::SingleQ)
957                 fl_set_button(language_->radio_single, 1);
958         else
959                 fl_set_button(language_->radio_double, 1);
960 }
961
962
963 void FormDocument::options_update(BufferParams const & params)
964 {
965         if (!options_.get())
966                 return;
967
968         fl_set_choice_text(options_->choice_postscript_driver,
969                            params.graphicsDriver.c_str());
970         fl_set_choice(options_->choice_ams_math, params.use_amsmath + 1);
971         fl_set_button(options_->check_use_natbib,  params.use_natbib);
972         fl_set_choice(options_->choice_citation_format,
973                       int(params.use_numerical_citations)+1);
974         setEnabled(options_->choice_citation_format, params.use_natbib);
975         fl_set_counter_value(options_->counter_secnumdepth, params.secnumdepth);
976         fl_set_counter_value(options_->counter_tocdepth, params.tocdepth);
977         if (!params.float_placement.empty())
978                 fl_set_input(options_->input_float_placement,
979                              params.float_placement.c_str());
980         else
981                 fl_set_input(options_->input_float_placement, "");
982 }
983
984
985 void FormDocument::paper_update(BufferParams const & params)
986 {
987         if (!paper_.get())
988                 return;
989
990         fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
991         fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
992         fl_set_button(paper_->check_use_geometry, params.use_geometry);
993
994         int const paperchoice = fl_get_choice(paper_->choice_papersize);
995         bool const useCustom = paperchoice == 2;
996         bool const useGeom = fl_get_button(paper_->check_use_geometry);
997
998         fl_set_button(paper_->radio_portrait, 0);
999         setEnabled(paper_->radio_portrait, !useCustom);
1000         fl_set_button(paper_->radio_landscape, 0);
1001         setEnabled(paper_->radio_landscape, !useCustom);
1002
1003         if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1004                 fl_set_button(paper_->radio_landscape, 1);
1005         else
1006                 fl_set_button(paper_->radio_portrait, 1);
1007         setEnabled(paper_->choice_paperpackage,
1008                    //either default papersize (preferences)
1009                    //or document papersize has to be A4
1010                    (paperchoice == 7
1011                     || paperchoice == 1 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER)
1012                    && fl_get_button(paper_->radio_portrait));
1013
1014         // Default unit choice is cm if metric, inches if US paper.
1015         bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
1016                 || paperchoice == 2 || paperchoice > 5;
1017         string const default_unit = metric ? "cm" : "in";
1018         updateWidgetsFromLengthString(paper_->input_custom_width,
1019                                       paper_->choice_custom_width_units,
1020                                       params.paperwidth, default_unit);
1021         setEnabled(paper_->input_custom_width, useCustom);
1022         setEnabled(paper_->choice_custom_width_units, useCustom);
1023
1024         updateWidgetsFromLengthString(paper_->input_custom_height,
1025                                       paper_->choice_custom_height_units,
1026                                       params.paperheight, default_unit);
1027         setEnabled(paper_->input_custom_height, useCustom);
1028         setEnabled(paper_->choice_custom_height_units, useCustom);
1029
1030         updateWidgetsFromLengthString(paper_->input_inner_margin,
1031                                       paper_->choice_inner_margin_units,
1032                                       params.leftmargin, default_unit);
1033         setEnabled(paper_->input_inner_margin, useGeom);
1034         setEnabled(paper_->choice_inner_margin_units, useGeom);
1035
1036         updateWidgetsFromLengthString(paper_->input_top_margin,
1037                                       paper_->choice_top_margin_units,
1038                                       params.topmargin, default_unit);
1039         setEnabled(paper_->input_top_margin, useGeom);
1040         setEnabled(paper_->choice_top_margin_units, useGeom);
1041
1042         updateWidgetsFromLengthString(paper_->input_outer_margin,
1043                                       paper_->choice_outer_margin_units,
1044                                       params.rightmargin, default_unit);
1045         setEnabled(paper_->input_outer_margin, useGeom);
1046         setEnabled(paper_->choice_outer_margin_units, useGeom);
1047
1048         updateWidgetsFromLengthString(paper_->input_bottom_margin,
1049                                       paper_->choice_bottom_margin_units,
1050                                       params.bottommargin, default_unit);
1051         setEnabled(paper_->input_bottom_margin, useGeom);
1052         setEnabled(paper_->choice_bottom_margin_units, useGeom);
1053
1054         updateWidgetsFromLengthString(paper_->input_head_height,
1055                                       paper_->choice_head_height_units,
1056                                       params.headheight, default_unit);
1057         setEnabled(paper_->input_head_height, useGeom);
1058         setEnabled(paper_->choice_head_height_units, useGeom);
1059
1060         updateWidgetsFromLengthString(paper_->input_head_sep,
1061                                       paper_->choice_head_sep_units,
1062                                       params.headsep, default_unit);
1063         setEnabled(paper_->input_head_sep, useGeom);
1064         setEnabled(paper_->choice_head_sep_units, useGeom);
1065
1066         updateWidgetsFromLengthString(paper_->input_foot_skip,
1067                                       paper_->choice_foot_skip_units,
1068                                       params.footskip, default_unit);
1069         setEnabled(paper_->input_foot_skip, useGeom);
1070         setEnabled(paper_->choice_foot_skip_units, useGeom);
1071
1072         fl_set_focus_object(paper_->form, paper_->choice_papersize);
1073 }
1074
1075
1076 void FormDocument::bullets_update(BufferParams const & params)
1077 {
1078         if (!bullets_.get() ||
1079             ((XpmVersion<4) ||
1080              (XpmVersion==4 && XpmRevision<7)))
1081                 return;
1082
1083         bool const isLinuxDoc =
1084                 controller().docType() == ControlDocument::LINUXDOC;
1085         setEnabled(fbullet, !isLinuxDoc);
1086
1087         if (isLinuxDoc) return;
1088
1089         fl_set_button(bullets_->radio_bullet_depth_1, 1);
1090         fl_set_input(bullets_->input_bullet_latex,
1091                      params.user_defined_bullets[0].getText().c_str());
1092         fl_set_choice(bullets_->choice_bullet_size,
1093                       params.user_defined_bullets[0].getSize() + 2);
1094 }
1095
1096
1097 void FormDocument::checkReadOnly()
1098 {
1099         if (bc().readOnly(controller().bufferIsReadonly())) {
1100                 combo_doc_class->deactivate();
1101                 combo_language->deactivate();
1102                 postWarning(_("Document is read-only."
1103                               " No changes to layout permitted."));
1104         } else {
1105                 combo_doc_class->activate();
1106                 combo_language->activate();
1107                 clearMessage();
1108         }
1109 }
1110
1111
1112 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/)
1113 {
1114         BufferParams & param = controller().params();
1115
1116         // convert from 1-6 range to -1-4
1117         param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1118         fl_set_input(bullets_->input_bullet_latex,
1119                      param.temp_bullets[current_bullet_depth].getText().c_str());
1120 }
1121
1122
1123 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1124 {
1125         BufferParams & param = controller().params();
1126
1127         param.temp_bullets[current_bullet_depth].
1128                 setText(getString(bullets_->input_bullet_latex));
1129 }
1130
1131
1132 void FormDocument::BulletDepth(FL_OBJECT * ob)
1133 {
1134         /* Should I do the following:                                 */
1135         /*  1. change to the panel that the current bullet belongs in */
1136         /*  2. show that bullet as selected                           */
1137         /*  3. change the size setting to the size of the bullet in Q.*/
1138         /*  4. display the latex equivalent in the latex box          */
1139         /*                                                            */
1140         /* I'm inclined to just go with 3 and 4 at the moment and     */
1141         /* maybe try to support the others later                      */
1142         BufferParams & param = controller().params();
1143
1144         int data = 0;
1145         if (ob == bullets_->radio_bullet_depth_1)
1146                 data = 0;
1147         else if (ob == bullets_->radio_bullet_depth_2)
1148                 data = 1;
1149         else if (ob == bullets_->radio_bullet_depth_3)
1150                 data = 2;
1151         else if (ob == bullets_->radio_bullet_depth_4)
1152                 data = 3;
1153
1154         switch (fl_get_button_numb(ob)) {
1155         case 3:
1156                 // right mouse button resets to default
1157                 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1158         default:
1159                 current_bullet_depth = data;
1160                 fl_set_input(bullets_->input_bullet_latex,
1161                              param.temp_bullets[data].getText().c_str());
1162                 fl_set_choice(bullets_->choice_bullet_size,
1163                               param.temp_bullets[data].getSize() + 2);
1164         }
1165 }
1166
1167
1168 void FormDocument::BulletPanel(FL_OBJECT * ob)
1169 {
1170         /* Here we have to change the background pixmap to that selected */
1171         /* by the user. (eg. standard.xpm, psnfss1.xpm etc...)           */
1172
1173         int data = 0;
1174         if (ob == bullets_->radio_bullet_panel_standard)
1175                 data = 0;
1176         else if (ob == bullets_->radio_bullet_panel_maths)
1177                 data = 1;
1178         else if (ob == bullets_->radio_bullet_panel_ding2)
1179                 data = 2;
1180         else if (ob == bullets_->radio_bullet_panel_ding3)
1181                 data = 3;
1182         else if (ob == bullets_->radio_bullet_panel_ding4)
1183                 data = 4;
1184         else if (ob == bullets_->radio_bullet_panel_ding1)
1185                 data = 5;
1186
1187         if (data != current_bullet_panel) {
1188                 fl_freeze_form(bullets_->form);
1189                 current_bullet_panel = data;
1190
1191                 /* free the current pixmap */
1192                 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1193                 string new_panel;
1194                 if (ob == bullets_->radio_bullet_panel_standard) {
1195                         new_panel = "standard";
1196                 } else if (ob == bullets_->radio_bullet_panel_maths ) {
1197                         new_panel = "amssymb";
1198                 } else if (ob == bullets_->radio_bullet_panel_ding2) {
1199                         new_panel = "psnfss1";
1200                 } else if (ob == bullets_->radio_bullet_panel_ding3) {
1201                         new_panel = "psnfss2";
1202                 } else if (ob == bullets_->radio_bullet_panel_ding4) {
1203                         new_panel = "psnfss3";
1204                 } else if (ob == bullets_->radio_bullet_panel_ding1) {
1205                         new_panel = "psnfss4";
1206                 } else {
1207                         /* something very wrong happened */
1208                         // play it safe for now but should be an exception
1209                         current_bullet_panel = 0;  // standard panel
1210                         new_panel = "standard";
1211                 }
1212                 new_panel += ".xpm";
1213                 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1214                                            LibFileSearch("images", new_panel).c_str());
1215                 fl_redraw_object(bullets_->bmtable_bullet_panel);
1216                 fl_unfreeze_form(bullets_->form);
1217         }
1218 }
1219
1220
1221 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/)
1222 {
1223         /* handle the user input by setting the current bullet depth's pixmap */
1224         /* to that extracted from the current chosen position of the BMTable  */
1225         /* Don't forget to free the button's old pixmap first.                */
1226
1227         BufferParams & param = controller().params();
1228         int bmtable_button = fl_get_bmtable(ob);
1229
1230         /* try to keep the button held down till another is pushed */
1231         /*  fl_set_bmtable(ob, 1, bmtable_button); */
1232         param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1233         param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1234         fl_set_input(bullets_->input_bullet_latex,
1235                      param.temp_bullets[current_bullet_depth].getText().c_str());
1236 }
1237
1238
1239 void FormDocument::CheckChoiceClass()
1240 {
1241         BufferParams & params = controller().params();
1242
1243         lyx::textclass_type const tc = combo_doc_class->get() - 1;
1244
1245         if (controller().loadTextclass(tc)) {
1246                 params.textclass = tc;
1247
1248                 if (lyxrc.auto_reset_options) {
1249                         params.useClassDefaults();
1250                         UpdateLayoutDocument(params);
1251                 } else {
1252                         // update the params which are needed in any case
1253                         // (fontsizes, pagestyle)
1254                         UpdateClassParams(params);
1255                 }
1256
1257         } else {
1258                 int const revert = int(params.textclass);
1259                 combo_doc_class->select(revert + 1);
1260         }
1261 }
1262
1263
1264 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1265 {
1266         if (!dialog_.get())
1267                 return;
1268
1269         checkReadOnly();
1270         class_update(params);
1271         paper_update(params);
1272         language_update(params);
1273         options_update(params);
1274         bullets_update(params);
1275 }