]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormDocument.C
Whitespace only
[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_->check_use_amsmath);
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         for (int n = 0; tex_graphics[n][0]; ++n) {
296                 fl_addto_choice(options_->choice_postscript_driver,
297                                 tex_graphics[n]);
298         }
299         fl_addto_choice(options_->choice_citation_format,
300                         _(" Author-year | Numerical "));
301
302         // the document bullets form
303         bullets_.reset(build_document_bullet(this));
304
305         // disable for read-only documents
306         bc().addReadOnly(bullets_->radio_bullet_depth_1);
307         bc().addReadOnly(bullets_->radio_bullet_depth_2);
308         bc().addReadOnly(bullets_->radio_bullet_depth_3);
309         bc().addReadOnly(bullets_->radio_bullet_depth_4);
310         bc().addReadOnly(bullets_->radio_bullet_panel_standard);
311         bc().addReadOnly(bullets_->radio_bullet_panel_maths);
312         bc().addReadOnly(bullets_->radio_bullet_panel_ding1);
313         bc().addReadOnly(bullets_->radio_bullet_panel_ding2);
314         bc().addReadOnly(bullets_->radio_bullet_panel_ding3);
315         bc().addReadOnly(bullets_->radio_bullet_panel_ding4);
316         bc().addReadOnly(bullets_->bmtable_bullet_panel);
317         bc().addReadOnly(bullets_->choice_bullet_size);
318         bc().addReadOnly(bullets_->input_bullet_latex);
319
320         // trigger an input event for cut&paste with middle mouse button.
321         setPrehandler(bullets_->input_bullet_latex);
322
323         fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
324
325         fl_addto_choice(bullets_->choice_bullet_size,
326                         _(" Default | Tiny | Smallest | Smaller | Small |"
327                           " Normal | Large | Larger | Largest | Huge | Huger "));
328         fl_set_choice(bullets_->choice_bullet_size, 1);
329
330         fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
331
332         string const bmtablefile = LibFileSearch("images", "standard", "xpm");
333         fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
334                                    bmtablefile.c_str());
335
336         fl_addto_tabfolder(dialog_->tabfolder,_("Document"),
337                            class_->form);
338         fl_addto_tabfolder(dialog_->tabfolder,_("Paper"),
339                            paper_->form);
340         fl_addto_tabfolder(dialog_->tabfolder,_("Language"),
341                            language_->form);
342         fl_addto_tabfolder(dialog_->tabfolder,_("Extra"),
343                            options_->form);
344         fbullet = fl_addto_tabfolder(dialog_->tabfolder,_("Bullets"),
345                                      bullets_->form);
346
347         // work-around xforms bug re update of folder->x, folder->y coords.
348         setPrehandler(dialog_->tabfolder);
349
350         if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
351                 lyxerr << _("Your version of libXpm is older than 4.7.\n"
352                             "The `bullet' tab of the document dialog "
353                             "has been disabled") << '\n';
354                 fl_deactivate_object(fbullet);
355                 fl_set_object_lcol(fbullet, FL_INACTIVE);
356         }
357 }
358
359
360 void FormDocument::apply()
361 {
362         BufferParams & params = controller().params();
363
364         class_apply(params);
365         paper_apply(params);
366         language_apply(params);
367         options_apply(params);
368         bullets_apply(params);
369 }
370
371
372 void FormDocument::update()
373 {
374         if (!dialog_.get())
375                 return;
376
377         checkReadOnly();
378
379         BufferParams const & params = controller().params();
380
381         class_update(params);
382         paper_update(params);
383         language_update(params);
384         options_update(params);
385         bullets_update(params);
386 }
387
388
389 ButtonPolicy::SMInput FormDocument::input(FL_OBJECT * ob, long)
390 {
391         if (ob == bullets_->choice_bullet_size) {
392                 ChoiceBulletSize(ob, 0);
393
394         } else if (ob == bullets_->input_bullet_latex) {
395                 InputBulletLaTeX(ob, 0);
396
397         } else if (ob == bullets_->radio_bullet_depth_1 ||
398                    ob == bullets_->radio_bullet_depth_2 ||
399                    ob == bullets_->radio_bullet_depth_3 ||
400                    ob == bullets_->radio_bullet_depth_4) {
401                 BulletDepth(ob);
402
403         } else if (ob == bullets_->radio_bullet_panel_standard ||
404                    ob == bullets_->radio_bullet_panel_maths ||
405                    ob == bullets_->radio_bullet_panel_ding1 ||
406                    ob == bullets_->radio_bullet_panel_ding2 ||
407                    ob == bullets_->radio_bullet_panel_ding3 ||
408                    ob == bullets_->radio_bullet_panel_ding4) {
409                 BulletPanel(ob);
410
411         } else if (ob == bullets_->bmtable_bullet_panel) {
412                 BulletBMTable(ob, 0);
413
414         } else if (ob == class_->choice_doc_spacing) {
415                 setEnabled(class_->input_doc_spacing,
416                            fl_get_choice(class_->choice_doc_spacing) == 4);
417
418         } else if (ob == class_->radio_doc_skip ||
419                    ob == class_->radio_doc_indent ||
420                    ob == class_->choice_doc_skip) {
421                 bool const skip_used = fl_get_button(class_->radio_doc_skip);
422                 setEnabled(class_->choice_doc_skip, skip_used);
423
424                 bool const length_input =
425                         fl_get_choice(class_->choice_doc_skip) == 4;
426                 setEnabled(class_->input_doc_skip,
427                            skip_used && length_input);
428                 setEnabled(class_->choice_doc_skip_units,
429                            skip_used && length_input);
430
431                 // Default unit choice is cm if metric, inches if US paper.
432                 // If papersize is default, check the lyxrc-settings
433                 int const paperchoice = fl_get_choice(paper_->choice_papersize);
434                 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
435                         || paperchoice == 2 || paperchoice > 5;
436                 string const default_unit = metric ? "cm" : "in";
437                 if (getString(class_->input_doc_skip).empty())
438                         fl_set_choice_text(class_->choice_doc_skip_units,
439                                                 default_unit.c_str());
440
441         } else if (ob == options_->check_use_natbib) {
442                 setEnabled(options_->choice_citation_format,
443                            fl_get_button(options_->check_use_natbib));
444
445         } else if (ob == dialog_->button_save_defaults) {
446                 apply();
447                 controller().saveAsDefault();
448
449         } else if (ob == dialog_->button_reset_defaults) {
450                 BufferParams & params = controller().params();
451                 params.textclass = combo_doc_class->get() - 1;
452                 params.useClassDefaults();
453                 UpdateLayoutDocument(params);
454
455         } else if (ob == paper_->radio_landscape) {
456                 fl_set_choice(paper_->choice_paperpackage,
457                               BufferParams::PACKAGE_NONE + 1);
458
459         } else if (ob == paper_->choice_papersize) {
460                 int const paperchoice = fl_get_choice(paper_->choice_papersize);
461                 bool const defsize = paperchoice == 1;
462                 bool const custom = paperchoice == 2;
463                 bool const a3size = paperchoice == 6;
464                 bool const b3size = paperchoice == 9;
465                 bool const b4size = paperchoice == 10;
466
467                 if (custom)
468                         fl_set_button(paper_->radio_portrait, 1);
469
470                 bool const use_geom = (custom || a3size || b3size || b4size);
471
472                 fl_set_button(paper_->check_use_geometry, int(use_geom));
473
474                 setEnabled(paper_->input_top_margin,    use_geom);
475                 setEnabled(paper_->input_bottom_margin, use_geom);
476                 setEnabled(paper_->input_inner_margin,  use_geom);
477                 setEnabled(paper_->input_outer_margin,  use_geom);
478                 setEnabled(paper_->input_head_height,   use_geom);
479                 setEnabled(paper_->input_head_sep,      use_geom);
480                 setEnabled(paper_->input_foot_skip,     use_geom);
481                 setEnabled(paper_->choice_top_margin_units,    use_geom);
482                 setEnabled(paper_->choice_bottom_margin_units, use_geom);
483                 setEnabled(paper_->choice_inner_margin_units,  use_geom);
484                 setEnabled(paper_->choice_outer_margin_units,  use_geom);
485                 setEnabled(paper_->choice_head_height_units,   use_geom);
486                 setEnabled(paper_->choice_head_sep_units,      use_geom);
487                 setEnabled(paper_->choice_foot_skip_units,     use_geom);
488                 setEnabled(paper_->choice_custom_width_units,  use_geom);
489                 setEnabled(paper_->choice_custom_height_units, use_geom);
490
491                 setEnabled(paper_->input_custom_width,  custom);
492                 setEnabled(paper_->input_custom_height, custom);
493                 setEnabled(paper_->choice_custom_width_units,  custom);
494                 setEnabled(paper_->choice_custom_height_units, custom);
495                 setEnabled(paper_->radio_portrait,  !custom);
496                 setEnabled(paper_->radio_landscape, !custom);
497
498                 // Default unit choice is cm if metric, inches if US paper.
499                 // If papersize is default, use the lyxrc-settings
500                 bool const metric = (defsize && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
501                         || paperchoice == 2 || paperchoice > 5;
502                 string const default_unit = metric ? "cm" : "in";
503                 if (getString(paper_->input_custom_width).empty())
504                         fl_set_choice_text(paper_->choice_custom_width_units,
505                                            default_unit.c_str());
506                 if (getString(paper_->input_custom_height).empty())
507                         fl_set_choice_text(paper_->choice_custom_height_units,
508                                            default_unit.c_str());
509                 if (getString(paper_->input_top_margin).empty())
510                         fl_set_choice_text(paper_->choice_top_margin_units,
511                                            default_unit.c_str());
512                 if (getString(paper_->input_bottom_margin).empty())
513                         fl_set_choice_text(paper_->choice_bottom_margin_units,
514                                            default_unit.c_str());
515                 if (getString(paper_->input_inner_margin).empty())
516                         fl_set_choice_text(paper_->choice_inner_margin_units,
517                                            default_unit.c_str());
518                 if (getString(paper_->input_outer_margin).empty())
519                         fl_set_choice_text(paper_->choice_outer_margin_units,
520                                            default_unit.c_str());
521                 if (getString(paper_->input_head_height).empty())
522                         fl_set_choice_text(paper_->choice_head_height_units,
523                                            default_unit.c_str());
524                 if (getString(paper_->input_head_sep).empty())
525                         fl_set_choice_text(paper_->choice_head_sep_units,
526                                            default_unit.c_str());
527                 if (getString(paper_->input_foot_skip).empty())
528                         fl_set_choice_text(paper_->choice_foot_skip_units,
529                                            default_unit.c_str());
530
531         } else if (ob == paper_->choice_paperpackage &&
532                    fl_get_choice(paper_->choice_paperpackage) != 1) {
533
534                 fl_set_button(paper_->check_use_geometry, 0);
535                 setEnabled(paper_->input_top_margin,    false);
536                 setEnabled(paper_->input_bottom_margin, false);
537                 setEnabled(paper_->input_inner_margin,  false);
538                 setEnabled(paper_->input_outer_margin,  false);
539                 setEnabled(paper_->input_head_height,   false);
540                 setEnabled(paper_->input_head_sep,      false);
541                 setEnabled(paper_->input_foot_skip,     false);
542                 setEnabled(paper_->choice_top_margin_units,    false);
543                 setEnabled(paper_->choice_bottom_margin_units, false);
544                 setEnabled(paper_->choice_inner_margin_units,  false);
545                 setEnabled(paper_->choice_outer_margin_units,  false);
546                 setEnabled(paper_->choice_head_height_units,   false);
547                 setEnabled(paper_->choice_head_sep_units,      false);
548                 setEnabled(paper_->choice_foot_skip_units,     false);
549
550         } else if (ob == paper_->check_use_geometry) {
551                 // don't allow switching geometry off in custom papersize
552                 // mode nor in A3, B3, and B4
553                 int const choice = fl_get_choice(paper_->choice_papersize);
554                 if (choice == 2 || choice == 6 || choice == 9 || choice == 10)
555                         fl_set_button(paper_->check_use_geometry, 1);
556
557                 fl_set_choice(paper_->choice_paperpackage,
558                               BufferParams::PACKAGE_NONE + 1);
559
560                 bool const use_geom = fl_get_button(paper_->check_use_geometry);
561                 setEnabled(paper_->input_top_margin,    use_geom);
562                 setEnabled(paper_->input_bottom_margin, use_geom);
563                 setEnabled(paper_->input_inner_margin,  use_geom);
564                 setEnabled(paper_->input_outer_margin,  use_geom);
565                 setEnabled(paper_->input_head_height,   use_geom);
566                 setEnabled(paper_->input_head_sep,      use_geom);
567                 setEnabled(paper_->input_foot_skip,     use_geom);
568                 setEnabled(paper_->choice_top_margin_units,    use_geom);
569                 setEnabled(paper_->choice_bottom_margin_units, use_geom);
570                 setEnabled(paper_->choice_inner_margin_units,  use_geom);
571                 setEnabled(paper_->choice_outer_margin_units,  use_geom);
572                 setEnabled(paper_->choice_head_height_units,   use_geom);
573                 setEnabled(paper_->choice_head_sep_units,      use_geom);
574                 setEnabled(paper_->choice_foot_skip_units,     use_geom);
575         }
576
577         if (ob == paper_->choice_papersize || ob == paper_->radio_portrait
578                         || ob == paper_->radio_landscape) {
579                 // either default papersize (preferences) or document
580                 // papersize has to be A4
581                 bool const enable = ( fl_get_choice(paper_->choice_papersize) == 1
582                                         && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER )
583                                 || fl_get_choice(paper_->choice_papersize) == 7;
584                 if (!enable)
585                         fl_set_choice(paper_->choice_paperpackage,
586                                 BufferParams::PACKAGE_NONE + 1);
587                 setEnabled(paper_->choice_paperpackage,
588                         enable && fl_get_button(paper_->radio_portrait));
589         }
590
591         return ButtonPolicy::SMI_VALID;
592 }
593
594
595 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
596 {
597         FormDocument * pre = static_cast<FormDocument*>(v);
598         if (combox == pre->combo_doc_class.get())
599                 pre->CheckChoiceClass();
600         pre->bc().valid();
601 }
602
603
604 bool FormDocument::class_apply(BufferParams &params)
605 {
606         bool redo = false;
607
608         // If default skip is a "Length" but there's no text in the
609         // input field, reset the kind to "MedSkip", which is the default.
610         if (fl_get_choice(class_->choice_doc_skip) == 4 &&
611             getString(class_->input_doc_skip).empty()) {
612                 fl_set_choice(class_->choice_doc_skip, 2);
613         }
614         params.fonts = getString(class_->choice_doc_fonts);
615         params.fontsize = getString(class_->choice_doc_fontsize);
616         params.pagestyle = getString(class_->choice_doc_pagestyle);
617
618         params.textclass = combo_doc_class->get() - 1;
619
620         BufferParams::PARSEP tmpsep = params.paragraph_separation;
621         if (fl_get_button(class_->radio_doc_indent))
622                 params.paragraph_separation = BufferParams::PARSEP_INDENT;
623         else
624                 params.paragraph_separation = BufferParams::PARSEP_SKIP;
625         if (tmpsep != params.paragraph_separation)
626                 redo = true;
627
628         VSpace tmpdefskip = params.getDefSkip();
629         switch (fl_get_choice(class_->choice_doc_skip)) {
630         case 1:
631                 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
632                 break;
633         case 2:
634                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
635                 break;
636         case 3:
637                 params.setDefSkip(VSpace(VSpace::BIGSKIP));
638                 break;
639         case 4:
640         {
641                 string const length =
642                         getLengthFromWidgets(class_->input_doc_skip,
643                                              class_->choice_doc_skip_units);
644
645                 params.setDefSkip(VSpace(LyXGlueLength(length)));
646                 break;
647         }
648         default:
649                 // DocumentDefskipCB assures that this never happens
650                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
651                 break;
652         }
653         if (!(tmpdefskip == params.getDefSkip()))
654                 redo = true;
655
656         if (fl_get_button(class_->radio_doc_columns_two))
657                 params.columns = 2;
658         else
659                 params.columns = 1;
660         if (fl_get_button(class_->radio_doc_sides_two))
661                 params.sides = LyXTextClass::TwoSides;
662         else
663                 params.sides = LyXTextClass::OneSide;
664
665         Spacing tmpSpacing = params.spacing;
666         switch (fl_get_choice(class_->choice_doc_spacing)) {
667         case 1:
668                 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
669                 params.spacing.set(Spacing::Single);
670                 break;
671         case 2:
672                 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
673                 params.spacing.set(Spacing::Onehalf);
674                 break;
675         case 3:
676                 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
677                 params.spacing.set(Spacing::Double);
678                 break;
679         case 4:
680                 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
681                 params.spacing.set(Spacing::Other,
682                                    getString(class_->input_doc_spacing));
683                 break;
684         }
685         if (tmpSpacing != params.spacing)
686                 redo = true;
687
688         params.options = getString(class_->input_doc_extra);
689
690         return redo;
691 }
692
693
694 void FormDocument::paper_apply(BufferParams & params)
695 {
696         params.papersize2 = char(fl_get_choice(paper_->choice_papersize) - 1);
697
698         params.paperpackage =
699                 char(fl_get_choice(paper_->choice_paperpackage) - 1);
700
701         // set params.papersize from params.papersize2 and params.paperpackage
702         params.setPaperStuff();
703
704         params.use_geometry = fl_get_button(paper_->check_use_geometry);
705
706         if (fl_get_button(paper_->radio_landscape))
707                 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
708         else
709                 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
710
711         params.paperwidth =
712                 getLengthFromWidgets(paper_->input_custom_width,
713                                      paper_->choice_custom_width_units);
714
715         params.paperheight =
716                 getLengthFromWidgets(paper_->input_custom_height,
717                                      paper_->choice_custom_height_units);
718
719         params.leftmargin =
720                 getLengthFromWidgets(paper_->input_inner_margin,
721                                      paper_->choice_inner_margin_units);
722
723         params.topmargin =
724                 getLengthFromWidgets(paper_->input_top_margin,
725                                      paper_->choice_top_margin_units);
726
727         params.rightmargin =
728                 getLengthFromWidgets(paper_->input_outer_margin,
729                                      paper_->choice_outer_margin_units);
730
731         params.bottommargin =
732                 getLengthFromWidgets(paper_->input_bottom_margin,
733                                      paper_->choice_bottom_margin_units);
734
735         params.headheight =
736                 getLengthFromWidgets(paper_->input_head_height,
737                                      paper_->choice_head_height_units);
738
739         params.headsep =
740                 getLengthFromWidgets(paper_->input_head_sep,
741                                      paper_->choice_head_sep_units);
742
743         params.footskip =
744                 getLengthFromWidgets(paper_->input_foot_skip,
745                                      paper_->choice_foot_skip_units);
746 }
747
748
749 bool FormDocument::language_apply(BufferParams & params)
750 {
751         InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
752         bool redo = false;
753
754         switch (fl_get_choice(language_->choice_quotes_language) - 1) {
755         case 0:
756                 lga = InsetQuotes::EnglishQ;
757                 break;
758         case 1:
759                 lga = InsetQuotes::SwedishQ;
760                 break;
761         case 2:
762                 lga = InsetQuotes::GermanQ;
763                 break;
764         case 3:
765                 lga = InsetQuotes::PolishQ;
766                 break;
767         case 4:
768                 lga = InsetQuotes::FrenchQ;
769                 break;
770         case 5:
771                 lga = InsetQuotes::DanishQ;
772                 break;
773         }
774         params.quotes_language = lga;
775         if (fl_get_button(language_->radio_single))
776                 params.quotes_times = InsetQuotes::SingleQ;
777         else
778                 params.quotes_times = InsetQuotes::DoubleQ;
779
780         int const pos = combo_language->get();
781         Language const * new_language = languages.getLanguage(lang_[pos-1]);
782         if (!new_language)
783                 new_language = default_language;
784
785         params.language = new_language;
786         params.inputenc = getString(language_->choice_inputenc);
787
788         return redo;
789 }
790
791
792 bool FormDocument::options_apply(BufferParams & params)
793 {
794         bool redo = false;
795
796         params.graphicsDriver = getString(options_->choice_postscript_driver);
797         params.use_amsmath = fl_get_button(options_->check_use_amsmath);
798         params.use_natbib  = fl_get_button(options_->check_use_natbib);
799         params.use_numerical_citations  =
800                 fl_get_choice(options_->choice_citation_format) - 1;
801
802         int tmpchar = int(fl_get_counter_value(options_->counter_secnumdepth));
803         if (params.secnumdepth != tmpchar)
804                 redo = true;
805         params.secnumdepth = tmpchar;
806
807         params.tocdepth = int(fl_get_counter_value(options_->counter_tocdepth));
808
809         params.float_placement =
810                 getString(options_->input_float_placement);
811
812         return redo;
813 }
814
815
816 void FormDocument::bullets_apply(BufferParams & params)
817 {
818         /* update the bullet settings */
819         BufferParams & buf_params = controller().params();
820
821         // a little bit of loop unrolling
822         params.user_defined_bullets[0] = buf_params.temp_bullets[0];
823         params.user_defined_bullets[1] = buf_params.temp_bullets[1];
824         params.user_defined_bullets[2] = buf_params.temp_bullets[2];
825         params.user_defined_bullets[3] = buf_params.temp_bullets[3];
826 }
827
828
829 void FormDocument::UpdateClassParams(BufferParams const & params)
830 {
831         // These are the params that have to be updated on any class change
832         // (even if the class defaults are not used) (JSpitzm 2002-04-08)
833
834         LyXTextClass const & tclass = textclasslist[params.textclass];
835
836         combo_doc_class->select(tclass.description());
837         fl_clear_choice(class_->choice_doc_fontsize);
838         fl_addto_choice(class_->choice_doc_fontsize, "default");
839         fl_addto_choice(class_->choice_doc_fontsize,
840                         tclass.opt_fontsize().c_str());
841         fl_set_choice_text(class_->choice_doc_fontsize,
842                         params.fontsize.c_str());
843         fl_clear_choice(class_->choice_doc_pagestyle);
844         fl_addto_choice(class_->choice_doc_pagestyle, "default");
845         fl_addto_choice(class_->choice_doc_pagestyle,
846                         tclass.opt_pagestyle().c_str());
847         fl_set_choice_text(class_->choice_doc_pagestyle,
848                         params.pagestyle.c_str());
849
850 }
851
852 void FormDocument::class_update(BufferParams const & params)
853 {
854         if (!class_.get())
855                 return;
856
857         UpdateClassParams(params);
858
859         fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
860
861         bool const indent = params.paragraph_separation == BufferParams::PARSEP_INDENT;
862         fl_set_button(class_->radio_doc_indent, indent);
863         fl_set_button(class_->radio_doc_skip, !indent);
864
865         int pos;
866         if (indent) {
867                 pos = 2; // VSpace::MEDSKIP is default
868         } else {
869                 switch (params.getDefSkip().kind()) {
870                 case VSpace::LENGTH:
871                         pos = 4;
872                         break;
873                 case VSpace::BIGSKIP:
874                         pos = 3;
875                         break;
876                 case VSpace::SMALLSKIP:
877                         pos = 1;
878                         break;
879                 case VSpace::MEDSKIP:
880                 default:
881                         pos = 2;
882                         break;
883                 }
884         }
885         fl_set_choice (class_->choice_doc_skip, pos);
886
887         bool const length_input = pos == 4;
888         if (length_input) {
889                 int const paperchoice = fl_get_choice(paper_->choice_papersize);
890                 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
891                         || paperchoice == 2 || paperchoice > 5;
892                 string const default_unit = metric ? "cm" : "in";
893                 string const length = params.getDefSkip().asLyXCommand();
894                 updateWidgetsFromLengthString(class_->input_doc_skip,
895                                               class_->choice_doc_skip_units,
896                                               length, default_unit);
897
898         } else {
899                 fl_set_input(class_->input_doc_skip, "");
900         }
901         setEnabled(class_->choice_doc_skip, !indent);
902         setEnabled(class_->input_doc_skip, length_input);
903         setEnabled(class_->choice_doc_skip_units, length_input);
904
905         bool const two_sides = params.sides == LyXTextClass::TwoSides;
906         fl_set_button(class_->radio_doc_sides_one, !two_sides);
907         fl_set_button(class_->radio_doc_sides_two, two_sides);
908
909         bool const two_columns = params.columns == 2;
910         fl_set_button(class_->radio_doc_columns_one, !two_columns);
911         fl_set_button(class_->radio_doc_columns_two, two_columns);
912
913         fl_set_input(class_->input_doc_extra, params.options.c_str());
914
915         switch (params.spacing.getSpace()) {
916         case Spacing::Other:
917                 pos = 4;
918                 break;
919         case Spacing::Double: // \doublespacing
920                 pos = 3;
921                 break;
922         case Spacing::Onehalf: // \onehalfspacing
923                 pos = 2;
924                 break;
925         case Spacing::Single: // \singlespacing
926         case Spacing::Default: // nothing bad should happen with this
927         default:
928                 pos = 1;
929                 break;
930         }
931         fl_set_choice(class_->choice_doc_spacing, pos);
932
933         bool const spacing_input = pos == 4;
934         setEnabled(class_->input_doc_spacing, spacing_input);
935         string const input = spacing_input ? tostr(params.spacing.getValue()) : string();
936         fl_set_input(class_->input_doc_spacing, input.c_str());
937 }
938
939
940 void FormDocument::language_update(BufferParams const & params)
941 {
942         if (!language_.get())
943                 return;
944
945         int const pos = int(findPos(lang_, params.language->lang()));
946         combo_language->select(pos+1);
947
948         fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
949         fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
950         fl_set_button(language_->radio_single, 0);
951         fl_set_button(language_->radio_double, 0);
952         if (params.quotes_times == InsetQuotes::SingleQ)
953                 fl_set_button(language_->radio_single, 1);
954         else
955                 fl_set_button(language_->radio_double, 1);
956 }
957
958
959 void FormDocument::options_update(BufferParams const & params)
960 {
961         if (!options_.get())
962                 return;
963
964         fl_set_choice_text(options_->choice_postscript_driver,
965                            params.graphicsDriver.c_str());
966         fl_set_button(options_->check_use_amsmath, params.use_amsmath);
967         fl_set_button(options_->check_use_natbib,  params.use_natbib);
968         fl_set_choice(options_->choice_citation_format,
969                       int(params.use_numerical_citations)+1);
970         setEnabled(options_->choice_citation_format, params.use_natbib);
971         fl_set_counter_value(options_->counter_secnumdepth, params.secnumdepth);
972         fl_set_counter_value(options_->counter_tocdepth, params.tocdepth);
973         if (!params.float_placement.empty())
974                 fl_set_input(options_->input_float_placement,
975                              params.float_placement.c_str());
976         else
977                 fl_set_input(options_->input_float_placement, "");
978 }
979
980
981 void FormDocument::paper_update(BufferParams const & params)
982 {
983         if (!paper_.get())
984                 return;
985
986         fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
987         fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
988         fl_set_button(paper_->check_use_geometry, params.use_geometry);
989
990         int const paperchoice = fl_get_choice(paper_->choice_papersize);
991         bool const useCustom = paperchoice == 2;
992         bool const useGeom = fl_get_button(paper_->check_use_geometry);
993
994         fl_set_button(paper_->radio_portrait, 0);
995         setEnabled(paper_->radio_portrait, !useCustom);
996         fl_set_button(paper_->radio_landscape, 0);
997         setEnabled(paper_->radio_landscape, !useCustom);
998
999         if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1000                 fl_set_button(paper_->radio_landscape, 1);
1001         else
1002                 fl_set_button(paper_->radio_portrait, 1);
1003         setEnabled(paper_->choice_paperpackage,
1004                    //either default papersize (preferences)
1005                    //or document papersize has to be A4
1006                    (paperchoice == 7
1007                     || paperchoice == 1 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER)
1008                    && fl_get_button(paper_->radio_portrait));
1009
1010         // Default unit choice is cm if metric, inches if US paper.
1011         bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
1012                 || paperchoice == 2 || paperchoice > 5;
1013         string const default_unit = metric ? "cm" : "in";
1014         updateWidgetsFromLengthString(paper_->input_custom_width,
1015                                       paper_->choice_custom_width_units,
1016                                       params.paperwidth, default_unit);
1017         setEnabled(paper_->input_custom_width, useCustom);
1018         setEnabled(paper_->choice_custom_width_units, useCustom);
1019
1020         updateWidgetsFromLengthString(paper_->input_custom_height,
1021                                       paper_->choice_custom_height_units,
1022                                       params.paperheight, default_unit);
1023         setEnabled(paper_->input_custom_height, useCustom);
1024         setEnabled(paper_->choice_custom_height_units, useCustom);
1025
1026         updateWidgetsFromLengthString(paper_->input_inner_margin,
1027                                       paper_->choice_inner_margin_units,
1028                                       params.leftmargin, default_unit);
1029         setEnabled(paper_->input_inner_margin, useGeom);
1030         setEnabled(paper_->choice_inner_margin_units, useGeom);
1031
1032         updateWidgetsFromLengthString(paper_->input_top_margin,
1033                                       paper_->choice_top_margin_units,
1034                                       params.topmargin, default_unit);
1035         setEnabled(paper_->input_top_margin, useGeom);
1036         setEnabled(paper_->choice_top_margin_units, useGeom);
1037
1038         updateWidgetsFromLengthString(paper_->input_outer_margin,
1039                                       paper_->choice_outer_margin_units,
1040                                       params.rightmargin, default_unit);
1041         setEnabled(paper_->input_outer_margin, useGeom);
1042         setEnabled(paper_->choice_outer_margin_units, useGeom);
1043
1044         updateWidgetsFromLengthString(paper_->input_bottom_margin,
1045                                       paper_->choice_bottom_margin_units,
1046                                       params.bottommargin, default_unit);
1047         setEnabled(paper_->input_bottom_margin, useGeom);
1048         setEnabled(paper_->choice_bottom_margin_units, useGeom);
1049
1050         updateWidgetsFromLengthString(paper_->input_head_height,
1051                                       paper_->choice_head_height_units,
1052                                       params.headheight, default_unit);
1053         setEnabled(paper_->input_head_height, useGeom);
1054         setEnabled(paper_->choice_head_height_units, useGeom);
1055
1056         updateWidgetsFromLengthString(paper_->input_head_sep,
1057                                       paper_->choice_head_sep_units,
1058                                       params.headsep, default_unit);
1059         setEnabled(paper_->input_head_sep, useGeom);
1060         setEnabled(paper_->choice_head_sep_units, useGeom);
1061
1062         updateWidgetsFromLengthString(paper_->input_foot_skip,
1063                                       paper_->choice_foot_skip_units,
1064                                       params.footskip, default_unit);
1065         setEnabled(paper_->input_foot_skip, useGeom);
1066         setEnabled(paper_->choice_foot_skip_units, useGeom);
1067
1068         fl_set_focus_object(paper_->form, paper_->choice_papersize);
1069 }
1070
1071
1072 void FormDocument::bullets_update(BufferParams const & params)
1073 {
1074         if (!bullets_.get() ||
1075             ((XpmVersion<4) ||
1076              (XpmVersion==4 && XpmRevision<7)))
1077                 return;
1078
1079         bool const isLinuxDoc =
1080                 controller().docType() == ControlDocument::LINUXDOC;
1081         setEnabled(fbullet, !isLinuxDoc);
1082
1083         if (isLinuxDoc) return;
1084
1085         fl_set_button(bullets_->radio_bullet_depth_1, 1);
1086         fl_set_input(bullets_->input_bullet_latex,
1087                      params.user_defined_bullets[0].getText().c_str());
1088         fl_set_choice(bullets_->choice_bullet_size,
1089                       params.user_defined_bullets[0].getSize() + 2);
1090 }
1091
1092
1093 void FormDocument::checkReadOnly()
1094 {
1095         if (bc().readOnly(controller().bufferIsReadonly())) {
1096                 combo_doc_class->deactivate();
1097                 combo_language->deactivate();
1098                 postWarning(_("Document is read-only."
1099                               " No changes to layout permitted."));
1100         } else {
1101                 combo_doc_class->activate();
1102                 combo_language->activate();
1103                 clearMessage();
1104         }
1105 }
1106
1107
1108 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/)
1109 {
1110         BufferParams & param = controller().params();
1111
1112         // convert from 1-6 range to -1-4
1113         param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1114         fl_set_input(bullets_->input_bullet_latex,
1115                      param.temp_bullets[current_bullet_depth].getText().c_str());
1116 }
1117
1118
1119 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1120 {
1121         BufferParams & param = controller().params();
1122
1123         param.temp_bullets[current_bullet_depth].
1124                 setText(getString(bullets_->input_bullet_latex));
1125 }
1126
1127
1128 void FormDocument::BulletDepth(FL_OBJECT * ob)
1129 {
1130         /* Should I do the following:                                 */
1131         /*  1. change to the panel that the current bullet belongs in */
1132         /*  2. show that bullet as selected                           */
1133         /*  3. change the size setting to the size of the bullet in Q.*/
1134         /*  4. display the latex equivalent in the latex box          */
1135         /*                                                            */
1136         /* I'm inclined to just go with 3 and 4 at the moment and     */
1137         /* maybe try to support the others later                      */
1138         BufferParams & param = controller().params();
1139
1140         int data = 0;
1141         if (ob == bullets_->radio_bullet_depth_1)
1142                 data = 0;
1143         else if (ob == bullets_->radio_bullet_depth_2)
1144                 data = 1;
1145         else if (ob == bullets_->radio_bullet_depth_3)
1146                 data = 2;
1147         else if (ob == bullets_->radio_bullet_depth_4)
1148                 data = 3;
1149
1150         switch (fl_get_button_numb(ob)) {
1151         case 3:
1152                 // right mouse button resets to default
1153                 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1154         default:
1155                 current_bullet_depth = data;
1156                 fl_set_input(bullets_->input_bullet_latex,
1157                              param.temp_bullets[data].getText().c_str());
1158                 fl_set_choice(bullets_->choice_bullet_size,
1159                               param.temp_bullets[data].getSize() + 2);
1160         }
1161 }
1162
1163
1164 void FormDocument::BulletPanel(FL_OBJECT * ob)
1165 {
1166         /* Here we have to change the background pixmap to that selected */
1167         /* by the user. (eg. standard.xpm, psnfss1.xpm etc...)           */
1168
1169         int data = 0;
1170         if (ob == bullets_->radio_bullet_panel_standard)
1171                 data = 0;
1172         else if (ob == bullets_->radio_bullet_panel_maths)
1173                 data = 1;
1174         else if (ob == bullets_->radio_bullet_panel_ding2)
1175                 data = 2;
1176         else if (ob == bullets_->radio_bullet_panel_ding3)
1177                 data = 3;
1178         else if (ob == bullets_->radio_bullet_panel_ding4)
1179                 data = 4;
1180         else if (ob == bullets_->radio_bullet_panel_ding1)
1181                 data = 5;
1182
1183         if (data != current_bullet_panel) {
1184                 fl_freeze_form(bullets_->form);
1185                 current_bullet_panel = data;
1186
1187                 /* free the current pixmap */
1188                 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1189                 string new_panel;
1190                 if (ob == bullets_->radio_bullet_panel_standard) {
1191                         new_panel = "standard";
1192                 } else if (ob == bullets_->radio_bullet_panel_maths ) {
1193                         new_panel = "amssymb";
1194                 } else if (ob == bullets_->radio_bullet_panel_ding2) {
1195                         new_panel = "psnfss1";
1196                 } else if (ob == bullets_->radio_bullet_panel_ding3) {
1197                         new_panel = "psnfss2";
1198                 } else if (ob == bullets_->radio_bullet_panel_ding4) {
1199                         new_panel = "psnfss3";
1200                 } else if (ob == bullets_->radio_bullet_panel_ding1) {
1201                         new_panel = "psnfss4";
1202                 } else {
1203                         /* something very wrong happened */
1204                         // play it safe for now but should be an exception
1205                         current_bullet_panel = 0;  // standard panel
1206                         new_panel = "standard";
1207                 }
1208                 new_panel += ".xpm";
1209                 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1210                                            LibFileSearch("images", new_panel).c_str());
1211                 fl_redraw_object(bullets_->bmtable_bullet_panel);
1212                 fl_unfreeze_form(bullets_->form);
1213         }
1214 }
1215
1216
1217 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/)
1218 {
1219         /* handle the user input by setting the current bullet depth's pixmap */
1220         /* to that extracted from the current chosen position of the BMTable  */
1221         /* Don't forget to free the button's old pixmap first.                */
1222
1223         BufferParams & param = controller().params();
1224         int bmtable_button = fl_get_bmtable(ob);
1225
1226         /* try to keep the button held down till another is pushed */
1227         /*  fl_set_bmtable(ob, 1, bmtable_button); */
1228         param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1229         param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1230         fl_set_input(bullets_->input_bullet_latex,
1231                      param.temp_bullets[current_bullet_depth].getText().c_str());
1232 }
1233
1234
1235 void FormDocument::CheckChoiceClass()
1236 {
1237         BufferParams & params = controller().params();
1238
1239         lyx::textclass_type const tc = combo_doc_class->get() - 1;
1240
1241         if (controller().loadTextclass(tc)) {
1242                 params.textclass = tc;
1243
1244                 if (lyxrc.auto_reset_options) {
1245                         params.useClassDefaults();
1246                         UpdateLayoutDocument(params);
1247                 } else {
1248                         // update the params which are needed in any case
1249                         // (fontsizes, pagestyle)
1250                         UpdateClassParams(params);
1251                 }
1252
1253         } else {
1254                 int const revert = int(params.textclass);
1255                 combo_doc_class->select(revert + 1);
1256         }
1257 }
1258
1259
1260 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1261 {
1262         if (!dialog_.get())
1263                 return;
1264
1265         checkReadOnly();
1266         class_update(params);
1267         paper_update(params);
1268         language_update(params);
1269         options_update(params);
1270         bullets_update(params);
1271 }