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