]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormDocument.C
fix crash on doc settings for non-branched doc (reported Kayvan)
[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  * \author Martin Vermeer
9  * \author Juergen Spitzmueller
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #include <config.h>
15
16 #include "ControlDocument.h"
17 #include "FormDocument.h"
18 #include "forms/form_document.h"
19 #include "xformsBC.h"
20 #include "ButtonController.h"
21
22 #include "FormColorpicker.h"
23 #include "LColor.h"
24 #include "Lsstream.h"
25 #include "bmtable.h"
26 #include "checkedwidgets.h"
27 #include "Tooltips.h"
28 #include "input_validators.h" // fl_unsigned_float_filter
29 #include "xforms_helpers.h"
30
31 #include "bufferparams.h"
32 #include "CutAndPaste.h"
33 #include "debug.h"
34 #include "language.h"
35 #include "lyxrc.h"
36 #include "lyxtextclasslist.h"
37 #include "tex-strings.h"
38 #include "ColorHandler.h"
39
40 #include "controllers/frnt_lang.h"
41 #include "controllers/helper_funcs.h"
42
43 #include "support/tostr.h"
44 #include "support/lstrings.h" // contains_functor, getStringFromVector
45 #include "support/filetools.h" // LibFileSearch
46
47 #include "lyx_xpm.h"
48 #include "lyx_forms.h"
49 #include "combox.h"
50
51 #include <boost/bind.hpp>
52
53 #include <functional>
54 #include <iomanip>
55
56 using namespace lyx::support;
57
58 using std::bind2nd;
59 using std::vector;
60 using std::endl;
61 using std::setw;
62 using std::setfill;
63
64
65 namespace {
66
67 #if FL_VERSION == 0 || (FL_REVISION == 0 && FL_FIXLEVEL < 2)
68 bool const scalableTabfolders = false;
69 #else
70 bool const scalableTabfolders = true;
71 #endif
72
73
74 } // namespace anon
75
76
77 typedef FormCB<ControlDocument, FormDB<FD_document> > base_class;
78
79 FormDocument::FormDocument()
80         : base_class(_("Document Settings"), scalableTabfolders),
81           ActCell(0), Confirmed(0),
82           current_bullet_panel(0), current_bullet_depth(0), fbullet(0)
83 {}
84
85
86 void FormDocument::redraw()
87 {
88         if (form() && form()->visible)
89                 fl_redraw_form(form());
90         else
91                 return;
92
93         FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder);
94         if (outer_form && outer_form->visible)
95                 fl_redraw_form(outer_form);
96 }
97
98
99 void FormDocument::build()
100 {
101         // the tabbed folder
102         dialog_.reset(build_document(this));
103
104         // Allow the base class to control messages
105         setMessageWidget(dialog_->text_warning);
106
107         // Manage the restore, ok, apply, restore and cancel/close buttons
108         bcview().setOK(dialog_->button_ok);
109         bcview().setApply(dialog_->button_apply);
110         bcview().setCancel(dialog_->button_close);
111         bcview().setRestore(dialog_->button_restore);
112
113         // the document class form
114         class_.reset(build_document_class(this));
115
116         // disable for read-only documents
117         bcview().addReadOnly(class_->combox_class);
118         bcview().addReadOnly(class_->radio_indent);
119         bcview().addReadOnly(class_->radio_skip);
120         bcview().addReadOnly(class_->choice_pagestyle);
121         bcview().addReadOnly(class_->choice_fonts);
122         bcview().addReadOnly(class_->choice_fontsize);
123         bcview().addReadOnly(class_->radio_sides_one);
124         bcview().addReadOnly(class_->radio_sides_two);
125         bcview().addReadOnly(class_->radio_columns_one);
126         bcview().addReadOnly(class_->radio_columns_two);
127         bcview().addReadOnly(class_->input_extra);
128         bcview().addReadOnly(class_->input_skip);
129         bcview().addReadOnly(class_->choice_skip);
130         bcview().addReadOnly(class_->choice_spacing);
131         bcview().addReadOnly(class_->input_spacing);
132
133         // check validity of "length + unit" input
134         addCheckedGlueLength(bcview(), class_->input_skip,
135                              class_->choice_skip);
136
137         // trigger an input event for cut&paste with middle mouse button.
138         setPrehandler(class_->input_extra);
139         setPrehandler(class_->input_skip);
140         setPrehandler(class_->input_spacing);
141
142         fl_set_input_return(class_->input_extra, FL_RETURN_CHANGED);
143         fl_set_input_return(class_->input_skip, FL_RETURN_CHANGED);
144         fl_set_input_return(class_->input_spacing, FL_RETURN_CHANGED);
145
146         FL_OBJECT * obj;
147
148         // Fill the combox and choices.
149         obj = class_->combox_class;
150         LyXTextClassList::const_iterator tit  = textclasslist.begin();
151         LyXTextClassList::const_iterator tend = textclasslist.end();
152         for (; tit != tend; ++tit) {
153                 if (tit->isTeXClassAvailable()) {
154                         fl_addto_combox(obj, tit->description().c_str());
155                 } else {
156                         string item = bformat(_("Unavailable: %1$s"), tit->description());
157                         fl_addto_combox(obj, item.c_str());
158                 }
159         }
160         fl_set_combox_browser_height(obj, 400);
161
162         fl_addto_choice(class_->choice_spacing,
163                         _(" Single | OneHalf | Double | Custom ").c_str());
164         fl_addto_choice(class_->choice_fontsize, "default|10|11|12");
165         for (int n = 0; tex_fonts[n][0]; ++n) {
166                 fl_addto_choice(class_->choice_fonts,tex_fonts[n]);
167         }
168
169         // Create the contents of the unit choices; don't include the
170         // "%" terms...
171         vector<string> units_vec = getLatexUnits();
172         vector<string>::iterator ret =
173                 std::remove_if(units_vec.begin(),
174                                units_vec.end(),
175                                bind2nd(contains_functor(), "%"));
176         units_vec.erase(ret, units_vec.end());
177
178         string const units = getStringFromVector(units_vec, "|");
179
180         fl_addto_choice(class_->choice_pagestyle,
181                         "default|empty|plain|headings|fancy");
182         fl_addto_choice(class_->choice_skip,
183                         _(" SmallSkip | MedSkip | BigSkip | Length ").c_str());
184         fl_addto_choice(class_->choice_skip_units,  units.c_str());
185
186         // Set input filters on doc spacing to make it accept only
187         // unsigned numbers.
188         fl_set_input_filter(class_->input_spacing,
189                             fl_unsigned_float_filter);
190
191         // disable for read-only documents
192         bcview().addReadOnly(dialog_->button_save_defaults);
193         bcview().addReadOnly(dialog_->button_reset_defaults);
194
195         // the document paper form
196         paper_.reset(build_document_paper(this));
197
198         // disable for read-only documents
199         bcview().addReadOnly(paper_->choice_paperpackage);
200         bcview().addReadOnly(paper_->radio_portrait);
201         bcview().addReadOnly(paper_->radio_landscape);
202         bcview().addReadOnly(paper_->choice_papersize);
203         bcview().addReadOnly(paper_->check_use_geometry);
204         bcview().addReadOnly(paper_->input_custom_width);
205         bcview().addReadOnly(paper_->input_custom_height);
206         bcview().addReadOnly(paper_->input_top_margin);
207         bcview().addReadOnly(paper_->input_bottom_margin);
208         bcview().addReadOnly(paper_->input_inner_margin);
209         bcview().addReadOnly(paper_->input_outer_margin);
210         bcview().addReadOnly(paper_->input_head_height);
211         bcview().addReadOnly(paper_->input_head_sep);
212         bcview().addReadOnly(paper_->input_foot_skip);
213
214         // check validity of "length + unit" input
215         addCheckedGlueLength(bcview(), paper_->input_custom_width);
216         addCheckedGlueLength(bcview(), paper_->input_custom_height);
217         addCheckedGlueLength(bcview(), paper_->input_top_margin);
218         addCheckedGlueLength(bcview(), paper_->input_bottom_margin);
219         addCheckedGlueLength(bcview(), paper_->input_inner_margin);
220         addCheckedGlueLength(bcview(), paper_->input_outer_margin);
221         addCheckedGlueLength(bcview(), paper_->input_head_height);
222         addCheckedGlueLength(bcview(), paper_->input_head_sep);
223         addCheckedGlueLength(bcview(), paper_->input_foot_skip);
224
225         // trigger an input event for cut&paste with middle mouse button.
226         setPrehandler(paper_->input_custom_width);
227         setPrehandler(paper_->input_custom_height);
228         setPrehandler(paper_->input_top_margin);
229         setPrehandler(paper_->input_bottom_margin);
230         setPrehandler(paper_->input_inner_margin);
231         setPrehandler(paper_->input_outer_margin);
232         setPrehandler(paper_->input_head_height);
233         setPrehandler(paper_->input_head_sep);
234         setPrehandler(paper_->input_foot_skip);
235
236         fl_set_input_return(paper_->input_custom_width,  FL_RETURN_CHANGED);
237         fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
238         fl_set_input_return(paper_->input_top_margin,    FL_RETURN_CHANGED);
239         fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
240         fl_set_input_return(paper_->input_inner_margin,  FL_RETURN_CHANGED);
241         fl_set_input_return(paper_->input_outer_margin,  FL_RETURN_CHANGED);
242         fl_set_input_return(paper_->input_head_height,   FL_RETURN_CHANGED);
243         fl_set_input_return(paper_->input_head_sep,      FL_RETURN_CHANGED);
244         fl_set_input_return(paper_->input_foot_skip,     FL_RETURN_CHANGED);
245
246         fl_addto_choice(paper_->choice_papersize,
247                         _(" Default | Custom | US letter | US legal "
248                           "| US executive | A3 | A4 | A5 "
249                           "| B3 | B4 | B5 ").c_str());
250         fl_addto_choice(paper_->choice_paperpackage,
251                         _(" None "
252                           "| Small Margins "
253                           "| Very small Margins "
254                           "| Very wide Margins ").c_str());
255
256         fl_addto_choice(paper_->choice_custom_width_units,  units.c_str());
257         fl_addto_choice(paper_->choice_custom_height_units, units.c_str());
258         fl_addto_choice(paper_->choice_top_margin_units,    units.c_str());
259         fl_addto_choice(paper_->choice_bottom_margin_units, units.c_str());
260         fl_addto_choice(paper_->choice_inner_margin_units,  units.c_str());
261         fl_addto_choice(paper_->choice_outer_margin_units,  units.c_str());
262         fl_addto_choice(paper_->choice_head_height_units,   units.c_str());
263         fl_addto_choice(paper_->choice_head_sep_units,      units.c_str());
264         fl_addto_choice(paper_->choice_foot_skip_units,     units.c_str());
265
266         // the document language form
267         language_.reset(build_document_language(this));
268
269         // disable for read-only documents
270         bcview().addReadOnly(language_->combox_language);
271         bcview().addReadOnly(language_->choice_inputenc);
272         bcview().addReadOnly(language_->choice_quotes_language);
273         bcview().addReadOnly(language_->radio_single);
274         bcview().addReadOnly(language_->radio_double);
275
276         fl_addto_choice(language_->choice_inputenc,
277                         "default|auto|latin1|latin2|latin3|latin4|latin5|latin9"
278                         "|koi8-r|koi8-u|cp866|cp1251|iso88595|pt154");
279
280         vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
281         // Store the identifiers for later
282         lang_ = getSecond(langs);
283
284         vector<frnt::LanguagePair>::const_iterator lit  = langs.begin();
285         vector<frnt::LanguagePair>::const_iterator lend = langs.end();
286         for (; lit != lend; ++lit) {
287                 fl_addto_combox(language_->combox_language,
288                                 lit->first.c_str());
289         }
290         fl_set_combox_browser_height(language_->combox_language, 400);
291
292         fl_addto_choice(language_->choice_quotes_language,
293                         _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
294                           " «text» | »text« ").c_str());
295
296         // the document options form
297         options_.reset(build_document_options(this));
298
299         // disable for read-only documents
300         bcview().addReadOnly(options_->counter_secnumdepth);
301         bcview().addReadOnly(options_->counter_tocdepth);
302         bcview().addReadOnly(options_->choice_ams_math);
303         bcview().addReadOnly(options_->check_use_natbib);
304         bcview().addReadOnly(options_->choice_citation_format);
305         bcview().addReadOnly(options_->input_float_placement);
306         bcview().addReadOnly(options_->choice_postscript_driver);
307
308         // trigger an input event for cut&paste with middle mouse button.
309         setPrehandler(options_->input_float_placement);
310
311         fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
312
313         fl_addto_choice(options_->choice_ams_math,
314                         _("Never | Automatically | Yes ").c_str());
315
316         for (int n = 0; tex_graphics[n][0]; ++n) {
317                 fl_addto_choice(options_->choice_postscript_driver,
318                                 tex_graphics[n]);
319         }
320         fl_addto_choice(options_->choice_citation_format,
321                         _(" Author-year | Numerical ").c_str());
322
323         // the document bullets form
324         bullets_.reset(build_document_bullet(this));
325
326         // disable for read-only documents
327         bcview().addReadOnly(bullets_->radio_depth_1);
328         bcview().addReadOnly(bullets_->radio_depth_2);
329         bcview().addReadOnly(bullets_->radio_depth_3);
330         bcview().addReadOnly(bullets_->radio_depth_4);
331         bcview().addReadOnly(bullets_->radio_panel_standard);
332         bcview().addReadOnly(bullets_->radio_panel_maths);
333         bcview().addReadOnly(bullets_->radio_panel_ding1);
334         bcview().addReadOnly(bullets_->radio_panel_ding2);
335         bcview().addReadOnly(bullets_->radio_panel_ding3);
336         bcview().addReadOnly(bullets_->radio_panel_ding4);
337         bcview().addReadOnly(bullets_->bmtable_panel);
338         bcview().addReadOnly(bullets_->choice_size);
339         bcview().addReadOnly(bullets_->input_latex);
340
341         // trigger an input event for cut&paste with middle mouse button.
342         setPrehandler(bullets_->input_latex);
343
344         fl_set_input_return(bullets_->input_latex, FL_RETURN_CHANGED);
345
346         fl_addto_choice(bullets_->choice_size,
347                         _(" Default | Tiny | Smallest | Smaller "
348                           "| Small | Normal | Large | Larger | Largest "
349                           "| Huge | Huger ").c_str());
350         fl_set_choice(bullets_->choice_size, 1);
351
352         fl_set_input_maxchars(bullets_->input_latex, 80);
353
354         string const bmtablefile = LibFileSearch("images", "standard", "xpm");
355         fl_set_bmtable_pixmap_file(bullets_->bmtable_panel, 6, 6,
356                                    bmtablefile.c_str());
357
358         picker_.reset(new FormColorpicker);
359         
360         // the document branches form
361         branch_.reset(build_document_branch(this));
362
363         fl_set_object_color(branch_->button_color,
364                 GUI_COLOR_CHOICE, GUI_COLOR_CHOICE);
365         
366         bcview().addReadOnly(branch_->input_all_branches);
367         bcview().addReadOnly(branch_->button_add_branch);
368         bcview().addReadOnly(branch_->button_remove_branch);
369         bcview().addReadOnly(branch_->button_select);
370         bcview().addReadOnly(branch_->button_deselect);
371         bcview().addReadOnly(branch_->button_modify);
372         bcview().addReadOnly(branch_->browser_all_branches);
373
374         // set up the tooltips for branches form
375         string str = _("Enter the name of a new branch.");
376         tooltips().init(branch_->input_all_branches, str);
377         str = _("Add a new branch to the document.");
378         tooltips().init(branch_->button_add_branch, str);
379         str = _("Remove the selected branch from the document.");
380         tooltips().init(branch_->button_remove_branch, str);
381         str = _("Activate the selected branch for output.");
382         tooltips().init(branch_->button_select, str);
383         str = _("Deactivate the selected activated branch.");
384         tooltips().init(branch_->button_deselect, str);
385         str = _("Available branches for this document.");
386         tooltips().init(branch_->browser_all_branches, str);
387         str = _("Activated branches. Content will occur in the document\'s output");
388         tooltips().init(branch_->browser_selection, str);
389         str = _("Modify background color of branch inset");
390         tooltips().init(branch_->button_modify, str);
391         str = _("Background color of branch inset");
392         tooltips().init(branch_->button_color, str);
393
394         // Handle middle mouse paint:
395         setPrehandler(branch_->input_all_branches);
396         fl_set_input_return(branch_->input_all_branches, FL_RETURN_CHANGED);
397
398         // Enable the tabfolder to be rescaled correctly.
399         if (scalableTabfolders)
400                 fl_set_tabfolder_autofit(dialog_->tabfolder, FL_FIT);
401
402         // Stack tabs
403         fl_addto_tabfolder(dialog_->tabfolder,_("Document").c_str(),
404                            class_->form);
405         fl_addto_tabfolder(dialog_->tabfolder,_("Paper").c_str(),
406                            paper_->form);
407         fl_addto_tabfolder(dialog_->tabfolder,_("Language").c_str(),
408                            language_->form);
409         fl_addto_tabfolder(dialog_->tabfolder,_("Extra").c_str(),
410                            options_->form);
411         fbullet = fl_addto_tabfolder(dialog_->tabfolder,_("Bullets").c_str(),
412                                      bullets_->form);
413
414         if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
415                 lyxerr << _("Your version of libXpm is older than 4.7.\n"
416                             "The `bullet' tab of the document dialog "
417                             "has been disabled") << '\n';
418                 fl_deactivate_object(fbullet);
419                 fl_set_object_lcol(fbullet, FL_INACTIVE);
420         }
421
422         fl_addto_tabfolder(dialog_->tabfolder,_("Branches").c_str(),
423                                      branch_->form);
424 }
425
426
427 void FormDocument::apply()
428 {
429         BufferParams & params = controller().params();
430
431         class_apply(params);
432         paper_apply(params);
433         language_apply(params);
434         options_apply(params);
435         bullets_apply(params);
436         branch_apply(params);
437 }
438
439
440 void FormDocument::update()
441 {
442         if (!dialog_.get())
443                 return;
444
445         checkReadOnly();
446
447         BufferParams const & params = controller().params();
448
449         class_update(params);
450         paper_update(params);
451         language_update(params);
452         options_update(params);
453         bullets_update(params);
454         branch_update(params);
455 }
456
457
458 ButtonPolicy::SMInput FormDocument::input(FL_OBJECT * ob, long)
459 {
460         if (ob == bullets_->choice_size) {
461                 ChoiceBulletSize(ob, 0);
462
463         } else if (ob == bullets_->input_latex) {
464                 InputBulletLaTeX(ob, 0);
465
466         } else if (ob == bullets_->radio_depth_1 ||
467                    ob == bullets_->radio_depth_2 ||
468                    ob == bullets_->radio_depth_3 ||
469                    ob == bullets_->radio_depth_4) {
470                 BulletDepth(ob);
471
472         } else if (ob == bullets_->radio_panel_standard ||
473                    ob == bullets_->radio_panel_maths ||
474                    ob == bullets_->radio_panel_ding1 ||
475                    ob == bullets_->radio_panel_ding2 ||
476                    ob == bullets_->radio_panel_ding3 ||
477                    ob == bullets_->radio_panel_ding4) {
478                 BulletPanel(ob);
479
480         } else if (ob == bullets_->bmtable_panel) {
481                 BulletBMTable(ob, 0);
482
483         } else if (ob == class_->choice_spacing) {
484                 setEnabled(class_->input_spacing,
485                            fl_get_choice(class_->choice_spacing) == 4);
486
487         } else if (ob == class_->combox_class) {
488                 CheckChoiceClass();
489         } else if (ob == class_->radio_skip ||
490                    ob == class_->radio_indent ||
491                    ob == class_->choice_skip) {
492                 bool const skip_used = fl_get_button(class_->radio_skip);
493                 setEnabled(class_->choice_skip, skip_used);
494
495                 bool const length_input =
496                         fl_get_choice(class_->choice_skip) == 4;
497                 setEnabled(class_->input_skip,
498                            skip_used && length_input);
499                 setEnabled(class_->choice_skip_units,
500                            skip_used && length_input);
501
502                 // Default unit choice is cm if metric, inches if US paper.
503                 // If papersize is default, check the lyxrc-settings
504                 int const paperchoice = fl_get_choice(paper_->choice_papersize);
505                 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > PAPER_EXECUTIVEPAPER)
506                         || paperchoice == 2 || paperchoice > 5;
507                 string const default_unit = metric ? "cm" : "in";
508                 if (getString(class_->input_skip).empty())
509                         fl_set_choice_text(class_->choice_skip_units,
510                                            default_unit.c_str());
511
512         } else if (ob == options_->check_use_natbib) {
513                 setEnabled(options_->choice_citation_format,
514                            fl_get_button(options_->check_use_natbib));
515
516         } else if (ob == branch_->browser_all_branches ||
517                         ob == branch_->browser_selection ||
518                         ob == branch_->button_add_branch ||
519                         ob == branch_->button_remove_branch ||
520                         ob == branch_->button_modify ||
521                         ob == branch_->button_select ||
522                         ob == branch_->button_deselect ||
523                         ob == branch_->button_deselect) {
524                 branch_input(ob);
525         } else if (ob == dialog_->button_save_defaults) {
526                 apply();
527                 controller().saveAsDefault();
528
529         } else if (ob == dialog_->button_reset_defaults) {
530                 BufferParams & params = controller().params();
531                 params.textclass = fl_get_combox(class_->combox_class) - 1;
532                 params.useClassDefaults();
533                 UpdateLayoutDocument(params);
534
535         } else if (ob == paper_->radio_landscape) {
536                 fl_set_choice(paper_->choice_paperpackage,
537                               PACKAGE_NONE + 1);
538
539         } else if (ob == paper_->choice_papersize) {
540                 int const paperchoice = fl_get_choice(paper_->choice_papersize);
541                 bool const defsize = paperchoice == 1;
542                 bool const custom = paperchoice == 2;
543                 bool const a3size = paperchoice == 6;
544                 bool const b3size = paperchoice == 9;
545                 bool const b4size = paperchoice == 10;
546
547                 if (custom)
548                         fl_set_button(paper_->radio_portrait, 1);
549
550                 bool const use_geom = (custom || a3size || b3size || b4size);
551
552                 fl_set_button(paper_->check_use_geometry, int(use_geom));
553
554                 setEnabled(paper_->input_top_margin,    use_geom);
555                 setEnabled(paper_->input_bottom_margin, use_geom);
556                 setEnabled(paper_->input_inner_margin,  use_geom);
557                 setEnabled(paper_->input_outer_margin,  use_geom);
558                 setEnabled(paper_->input_head_height,   use_geom);
559                 setEnabled(paper_->input_head_sep,      use_geom);
560                 setEnabled(paper_->input_foot_skip,     use_geom);
561                 setEnabled(paper_->choice_top_margin_units,    use_geom);
562                 setEnabled(paper_->choice_bottom_margin_units, use_geom);
563                 setEnabled(paper_->choice_inner_margin_units,  use_geom);
564                 setEnabled(paper_->choice_outer_margin_units,  use_geom);
565                 setEnabled(paper_->choice_head_height_units,   use_geom);
566                 setEnabled(paper_->choice_head_sep_units,      use_geom);
567                 setEnabled(paper_->choice_foot_skip_units,     use_geom);
568                 setEnabled(paper_->choice_custom_width_units,  use_geom);
569                 setEnabled(paper_->choice_custom_height_units, use_geom);
570
571                 setEnabled(paper_->input_custom_width,  custom);
572                 setEnabled(paper_->input_custom_height, custom);
573                 setEnabled(paper_->choice_custom_width_units,  custom);
574                 setEnabled(paper_->choice_custom_height_units, custom);
575                 setEnabled(paper_->radio_portrait,  !custom);
576                 setEnabled(paper_->radio_landscape, !custom);
577
578                 // Default unit choice is cm if metric, inches if US paper.
579                 // If papersize is default, use the lyxrc-settings
580                 bool const metric = (defsize && lyxrc.default_papersize > PAPER_EXECUTIVEPAPER)
581                         || paperchoice == 2 || paperchoice > 5;
582                 string const default_unit = metric ? "cm" : "in";
583                 if (getString(paper_->input_custom_width).empty())
584                         fl_set_choice_text(paper_->choice_custom_width_units,
585                                            default_unit.c_str());
586                 if (getString(paper_->input_custom_height).empty())
587                         fl_set_choice_text(paper_->choice_custom_height_units,
588                                            default_unit.c_str());
589                 if (getString(paper_->input_top_margin).empty())
590                         fl_set_choice_text(paper_->choice_top_margin_units,
591                                            default_unit.c_str());
592                 if (getString(paper_->input_bottom_margin).empty())
593                         fl_set_choice_text(paper_->choice_bottom_margin_units,
594                                            default_unit.c_str());
595                 if (getString(paper_->input_inner_margin).empty())
596                         fl_set_choice_text(paper_->choice_inner_margin_units,
597                                            default_unit.c_str());
598                 if (getString(paper_->input_outer_margin).empty())
599                         fl_set_choice_text(paper_->choice_outer_margin_units,
600                                            default_unit.c_str());
601                 if (getString(paper_->input_head_height).empty())
602                         fl_set_choice_text(paper_->choice_head_height_units,
603                                            default_unit.c_str());
604                 if (getString(paper_->input_head_sep).empty())
605                         fl_set_choice_text(paper_->choice_head_sep_units,
606                                            default_unit.c_str());
607                 if (getString(paper_->input_foot_skip).empty())
608                         fl_set_choice_text(paper_->choice_foot_skip_units,
609                                            default_unit.c_str());
610
611         } else if (ob == paper_->choice_paperpackage &&
612                    fl_get_choice(paper_->choice_paperpackage) != 1) {
613
614                 fl_set_button(paper_->check_use_geometry, 0);
615                 setEnabled(paper_->input_top_margin,    false);
616                 setEnabled(paper_->input_bottom_margin, false);
617                 setEnabled(paper_->input_inner_margin,  false);
618                 setEnabled(paper_->input_outer_margin,  false);
619                 setEnabled(paper_->input_head_height,   false);
620                 setEnabled(paper_->input_head_sep,      false);
621                 setEnabled(paper_->input_foot_skip,     false);
622                 setEnabled(paper_->choice_top_margin_units,    false);
623                 setEnabled(paper_->choice_bottom_margin_units, false);
624                 setEnabled(paper_->choice_inner_margin_units,  false);
625                 setEnabled(paper_->choice_outer_margin_units,  false);
626                 setEnabled(paper_->choice_head_height_units,   false);
627                 setEnabled(paper_->choice_head_sep_units,      false);
628                 setEnabled(paper_->choice_foot_skip_units,     false);
629
630         } else if (ob == paper_->check_use_geometry) {
631                 // don't allow switching geometry off in custom papersize
632                 // mode nor in A3, B3, and B4
633                 int const choice = fl_get_choice(paper_->choice_papersize);
634                 if (choice == 2 || choice == 6 || choice == 9 || choice == 10)
635                         fl_set_button(paper_->check_use_geometry, 1);
636
637                 fl_set_choice(paper_->choice_paperpackage,
638                               PACKAGE_NONE + 1);
639
640                 bool const use_geom = fl_get_button(paper_->check_use_geometry);
641                 setEnabled(paper_->input_top_margin,    use_geom);
642                 setEnabled(paper_->input_bottom_margin, use_geom);
643                 setEnabled(paper_->input_inner_margin,  use_geom);
644                 setEnabled(paper_->input_outer_margin,  use_geom);
645                 setEnabled(paper_->input_head_height,   use_geom);
646                 setEnabled(paper_->input_head_sep,      use_geom);
647                 setEnabled(paper_->input_foot_skip,     use_geom);
648                 setEnabled(paper_->choice_top_margin_units,    use_geom);
649                 setEnabled(paper_->choice_bottom_margin_units, use_geom);
650                 setEnabled(paper_->choice_inner_margin_units,  use_geom);
651                 setEnabled(paper_->choice_outer_margin_units,  use_geom);
652                 setEnabled(paper_->choice_head_height_units,   use_geom);
653                 setEnabled(paper_->choice_head_sep_units,      use_geom);
654                 setEnabled(paper_->choice_foot_skip_units,     use_geom);
655         }
656
657         if (ob == paper_->choice_papersize || ob == paper_->radio_portrait
658             || ob == paper_->radio_landscape) {
659                 // either default papersize (preferences) or document
660                 // papersize has to be A4
661                 bool const enable = ( fl_get_choice(paper_->choice_papersize) == 1
662                                       && lyxrc.default_papersize == PAPER_A4PAPER )
663                         || fl_get_choice(paper_->choice_papersize) == 7;
664                 if (!enable)
665                         fl_set_choice(paper_->choice_paperpackage,
666                                       PACKAGE_NONE + 1);
667                 setEnabled(paper_->choice_paperpackage,
668                            enable && fl_get_button(paper_->radio_portrait));
669         }
670
671         return ButtonPolicy::SMI_VALID;
672 }
673
674
675 void FormDocument::branch_input(FL_OBJECT * ob)
676 {
677         BufferParams & params = controller().params();
678         std::vector<string> vec;
679
680         if (ob == branch_->button_add_branch) {
681                 string new_branch = fl_get_input(branch_->input_all_branches);
682                 if (!new_branch.empty()) {
683                         params.branchlist.add(new_branch);
684                         fl_set_input(branch_->input_all_branches, "");
685                         // Update branch list
686                         string const all_branches = params.branchlist.allBranches();
687                         fl_clear_browser(branch_->browser_all_branches);
688                         vec = getVectorFromString(all_branches, "|");
689                         for (unsigned i = 0; i < vec.size(); ++i) {
690                                 fl_addto_browser(branch_->browser_all_branches,
691                                                                 vec[i].c_str());
692                         }
693                         LColor::color c = static_cast<LColor::color>(lcolor.size());
694                         lcolor.fill(c, new_branch, lcolor.getX11Name(LColor::background));
695                 }
696
697         } else if (ob == branch_->button_remove_branch) {
698                 unsigned i = fl_get_browser(branch_->browser_all_branches);
699                 string const current_branch =
700                         fl_get_browser_line(branch_->browser_all_branches, i);
701                 if (!current_branch.empty()) {
702                         params.branchlist.remove(current_branch);
703                         // Update branch list
704                         string const all_branches = params.branchlist.allBranches();
705                         fl_clear_browser(branch_->browser_all_branches);
706                         vec = getVectorFromString(all_branches, "|");
707                         for (unsigned i = 0; i < vec.size(); ++i) {
708                                 fl_addto_browser(branch_->browser_all_branches,
709                                                                 vec[i].c_str());
710                         }
711                         // Update selected-list...
712                         string const all_selected = params.branchlist.allSelected();
713                         fl_clear_browser(branch_->browser_selection);
714                         vec = getVectorFromString(all_selected, "|");
715                         for (unsigned i = 0; i < vec.size(); ++i) {
716                                 fl_addto_browser(branch_->browser_selection, vec[i].c_str());
717                         }
718                 }
719         } else if (ob == branch_->button_select) {
720                 unsigned i = fl_get_browser(branch_->browser_all_branches);
721                 string const current_branch =
722                         fl_get_browser_line(branch_->browser_all_branches, i);
723                 if (!current_branch.empty()) {
724                         fl_clear_browser(branch_->browser_selection);
725                         params.branchlist.setSelected(current_branch, true);
726                         string const all_selected = params.branchlist.allSelected();
727                         vec = getVectorFromString(all_selected, "|");
728                         for (unsigned i = 0; i < vec.size(); ++i) {
729                                 fl_addto_browser(branch_->browser_selection,
730                                                         vec[i].c_str());
731                         }
732                 }
733         } else if (ob == branch_->button_deselect) {
734                 unsigned i = fl_get_browser(branch_->browser_selection);
735                 string const current_sel =
736                         fl_get_browser_line(branch_->browser_selection, i);
737                 if (!current_sel.empty()) {
738                         fl_clear_browser(branch_->browser_selection);
739                         params.branchlist.setSelected(current_sel, false);
740                         string const all_selected = params.branchlist.allSelected();
741                         vec = getVectorFromString(all_selected, "|");
742                         for (unsigned i = 0; i < vec.size(); ++i) {
743                                 fl_addto_browser(branch_->browser_selection,
744                                                         vec[i].c_str());
745                         }
746                 }
747         } else if (ob == branch_->button_modify) {
748                 unsigned i = fl_get_browser(branch_->browser_all_branches);
749                 string const current_branch =
750                         fl_get_browser_line(branch_->browser_all_branches, i);
751                 
752                 RGBColor before;
753                 string x11hexname = params.branchlist.getColor(current_branch);
754                 if (x11hexname[0] == '#') {
755                         before = RGBColor(x11hexname);
756                 } else{
757                         fl_getmcolor(FL_COL1, &before.r, &before.g, &before.b);
758                 }
759
760                 RGBColor col = picker_->requestColor(before);
761                 if (before != col) {
762                         fl_mapcolor(GUI_COLOR_CHOICE, col.r, col.g, col.b);
763                         fl_redraw_object(branch_->button_color);
764                         // Figure out here how to stash the new colour into the
765                         // LyX colour database.
766
767                         x11hexname = X11hexname(col);
768
769                         // current_branch already in database
770                         LColor::color c = lcolor.getFromLyXName(current_branch);
771                         lcolor.setColor(current_branch, x11hexname);
772                         // Make sure that new colour is also displayed ;-)
773                         lyxColorHandler->getGCForeground(c);
774                         lyxColorHandler->updateColor(c);
775                         // what about system_lcolor?
776                         // Here set colour in BranchList:
777                         params.branchlist.setColor(current_branch, x11hexname);
778                 }
779         } else if (ob == branch_->browser_all_branches) {
780                 unsigned i = fl_get_browser(branch_->browser_all_branches);
781                 string const current_branch =
782                         fl_get_browser_line(branch_->browser_all_branches, i);
783                 // make button_color track selected branch:
784
785                 RGBColor rgb;
786                 string x11hexname = params.branchlist.getColor(current_branch);
787                 if (x11hexname[0] == '#') {
788                         rgb = RGBColor(x11hexname);
789                 } else {
790                         fl_getmcolor(FL_COL1, &rgb.r, &rgb.g, &rgb.b);
791                 }
792                 fl_mapcolor(GUI_COLOR_CHOICE, rgb.r, rgb.g, rgb.b);
793                 fl_redraw_object(branch_->button_color);
794         }
795         setEnabled(branch_->button_select,
796                 (fl_get_browser(branch_->browser_all_branches) > 0));
797         setEnabled(branch_->button_deselect,
798                 (fl_get_browser(branch_->browser_selection) > 0));
799         setEnabled(branch_->button_remove_branch,
800                 (fl_get_browser(branch_->browser_all_branches) > 0));
801         setEnabled(branch_->button_modify,
802                 (fl_get_browser(branch_->browser_all_branches) > 0));
803
804         branchlist_ = params.branchlist;
805 }
806
807
808 bool FormDocument::class_apply(BufferParams &params)
809 {
810         bool redo = false;
811
812         // If default skip is a "Length" but there's no text in the
813         // input field, reset the kind to "MedSkip", which is the default.
814         if (fl_get_choice(class_->choice_skip) == 4 &&
815             getString(class_->input_skip).empty()) {
816                 fl_set_choice(class_->choice_skip, 2);
817         }
818         params.fonts = getString(class_->choice_fonts);
819         params.fontsize = getString(class_->choice_fontsize);
820         params.pagestyle = getString(class_->choice_pagestyle);
821
822         params.textclass = fl_get_combox(class_->combox_class) - 1;
823
824         BufferParams::PARSEP tmpsep = params.paragraph_separation;
825         if (fl_get_button(class_->radio_indent))
826                 params.paragraph_separation = BufferParams::PARSEP_INDENT;
827         else
828                 params.paragraph_separation = BufferParams::PARSEP_SKIP;
829         if (tmpsep != params.paragraph_separation)
830                 redo = true;
831
832         VSpace tmpdefskip = params.getDefSkip();
833         switch (fl_get_choice(class_->choice_skip)) {
834         case 1:
835                 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
836                 break;
837         case 2:
838                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
839                 break;
840         case 3:
841                 params.setDefSkip(VSpace(VSpace::BIGSKIP));
842                 break;
843         case 4:
844         {
845                 string const length =
846                         getLengthFromWidgets(class_->input_skip,
847                                              class_->choice_skip_units);
848
849                 params.setDefSkip(VSpace(LyXGlueLength(length)));
850                 break;
851         }
852         default:
853                 // DocumentDefskipCB assures that this never happens
854                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
855                 break;
856         }
857         if (!(tmpdefskip == params.getDefSkip()))
858                 redo = true;
859
860         if (fl_get_button(class_->radio_columns_two))
861                 params.columns = 2;
862         else
863                 params.columns = 1;
864         if (fl_get_button(class_->radio_sides_two))
865                 params.sides = LyXTextClass::TwoSides;
866         else
867                 params.sides = LyXTextClass::OneSide;
868
869         Spacing tmpSpacing = params.spacing;
870         switch (fl_get_choice(class_->choice_spacing)) {
871         case 1:
872                 lyxerr[Debug::INFO] << "Spacing: SINGLE" << endl;
873                 params.spacing.set(Spacing::Single);
874                 break;
875         case 2:
876                 lyxerr[Debug::INFO] << "Spacing: ONEHALF" << endl;
877                 params.spacing.set(Spacing::Onehalf);
878                 break;
879         case 3:
880                 lyxerr[Debug::INFO] << "Spacing: DOUBLE" << endl;
881                 params.spacing.set(Spacing::Double);
882                 break;
883         case 4:
884                 lyxerr[Debug::INFO] << "Spacing: OTHER" << endl;
885                 params.spacing.set(Spacing::Other,
886                                    getString(class_->input_spacing));
887                 break;
888         }
889         if (tmpSpacing != params.spacing)
890                 redo = true;
891
892         params.options = getString(class_->input_extra);
893
894         return redo;
895 }
896
897
898 void FormDocument::paper_apply(BufferParams & params)
899 {
900         params.papersize2 = VMARGIN_PAPER_TYPE(fl_get_choice(paper_->choice_papersize) - 1);
901
902         params.paperpackage =
903                 PAPER_PACKAGES(fl_get_choice(paper_->choice_paperpackage) - 1);
904
905         // set params.papersize from params.papersize2 and params.paperpackage
906         params.setPaperStuff();
907
908         params.use_geometry = fl_get_button(paper_->check_use_geometry);
909
910         if (fl_get_button(paper_->radio_landscape))
911                 params.orientation = ORIENTATION_LANDSCAPE;
912         else
913                 params.orientation = ORIENTATION_PORTRAIT;
914
915         params.paperwidth =
916                 getLengthFromWidgets(paper_->input_custom_width,
917                                      paper_->choice_custom_width_units);
918
919         params.paperheight =
920                 getLengthFromWidgets(paper_->input_custom_height,
921                                      paper_->choice_custom_height_units);
922
923         params.leftmargin =
924                 getLengthFromWidgets(paper_->input_inner_margin,
925                                      paper_->choice_inner_margin_units);
926
927         params.topmargin =
928                 getLengthFromWidgets(paper_->input_top_margin,
929                                      paper_->choice_top_margin_units);
930
931         params.rightmargin =
932                 getLengthFromWidgets(paper_->input_outer_margin,
933                                      paper_->choice_outer_margin_units);
934
935         params.bottommargin =
936                 getLengthFromWidgets(paper_->input_bottom_margin,
937                                      paper_->choice_bottom_margin_units);
938
939         params.headheight =
940                 getLengthFromWidgets(paper_->input_head_height,
941                                      paper_->choice_head_height_units);
942
943         params.headsep =
944                 getLengthFromWidgets(paper_->input_head_sep,
945                                      paper_->choice_head_sep_units);
946
947         params.footskip =
948                 getLengthFromWidgets(paper_->input_foot_skip,
949                                      paper_->choice_foot_skip_units);
950 }
951
952
953 bool FormDocument::language_apply(BufferParams & params)
954 {
955         InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
956         bool redo = false;
957
958         switch (fl_get_choice(language_->choice_quotes_language) - 1) {
959         case 0:
960                 lga = InsetQuotes::EnglishQ;
961                 break;
962         case 1:
963                 lga = InsetQuotes::SwedishQ;
964                 break;
965         case 2:
966                 lga = InsetQuotes::GermanQ;
967                 break;
968         case 3:
969                 lga = InsetQuotes::PolishQ;
970                 break;
971         case 4:
972                 lga = InsetQuotes::FrenchQ;
973                 break;
974         case 5:
975                 lga = InsetQuotes::DanishQ;
976                 break;
977         }
978         params.quotes_language = lga;
979         if (fl_get_button(language_->radio_single))
980                 params.quotes_times = InsetQuotes::SingleQ;
981         else
982                 params.quotes_times = InsetQuotes::DoubleQ;
983
984         int const pos = fl_get_combox(language_->combox_language);
985         Language const * new_language = languages.getLanguage(lang_[pos-1]);
986         if (!new_language)
987                 new_language = default_language;
988
989         params.language = new_language;
990         params.inputenc = getString(language_->choice_inputenc);
991
992         return redo;
993 }
994
995
996 bool FormDocument::options_apply(BufferParams & params)
997 {
998         bool redo = false;
999
1000         params.graphicsDriver = getString(options_->choice_postscript_driver);
1001         params.use_amsmath = static_cast<BufferParams::AMS>(
1002                 fl_get_choice(options_->choice_ams_math) - 1);
1003         params.use_natbib  = fl_get_button(options_->check_use_natbib);
1004         params.use_numerical_citations  =
1005                 fl_get_choice(options_->choice_citation_format) - 1;
1006
1007         int tmpchar = int(fl_get_counter_value(options_->counter_secnumdepth));
1008         if (params.secnumdepth != tmpchar)
1009                 redo = true;
1010         params.secnumdepth = tmpchar;
1011
1012         params.tocdepth = int(fl_get_counter_value(options_->counter_tocdepth));
1013
1014         params.float_placement =
1015                 getString(options_->input_float_placement);
1016
1017         return redo;
1018 }
1019
1020
1021 void FormDocument::bullets_apply(BufferParams & params)
1022 {
1023         /* update the bullet settings */
1024         BufferParams & buf_params = controller().params();
1025
1026         for (int i = 0; i < 4; ++i) {
1027                 params.user_defined_bullets[i] = buf_params.temp_bullets[i];
1028         }
1029 }
1030
1031
1032 void FormDocument::branch_apply(BufferParams & params)
1033 {
1034         BufferParams & prms = controller().params();
1035         if (branchlist_.empty())
1036                 branchlist_ = prms.branchlist;
1037         params.branchlist = branchlist_;
1038         branchlist_.clear();
1039 }
1040
1041                 
1042 void FormDocument::UpdateClassParams(BufferParams const & params)
1043 {
1044         // These are the params that have to be updated on any class change
1045         // (even if the class defaults are not used) (JSpitzm 2002-04-08)
1046
1047         LyXTextClass const & tclass = textclasslist[params.textclass];
1048
1049         fl_set_combox(class_->combox_class, params.textclass + 1);
1050         fl_clear_choice(class_->choice_fontsize);
1051         fl_addto_choice(class_->choice_fontsize, "default");
1052         fl_addto_choice(class_->choice_fontsize,
1053                         tclass.opt_fontsize().c_str());
1054         fl_set_choice_text(class_->choice_fontsize,
1055                            params.fontsize.c_str());
1056         fl_clear_choice(class_->choice_pagestyle);
1057         fl_addto_choice(class_->choice_pagestyle, "default");
1058         fl_addto_choice(class_->choice_pagestyle,
1059                         tclass.opt_pagestyle().c_str());
1060         fl_set_choice_text(class_->choice_pagestyle,
1061                            params.pagestyle.c_str());
1062
1063         fl_set_input(class_->input_extra, tclass.options().c_str());
1064 }
1065
1066 void FormDocument::class_update(BufferParams const & params)
1067 {
1068         if (!class_.get())
1069                 return;
1070
1071         UpdateClassParams(params);
1072
1073         fl_set_choice_text(class_->choice_fonts, params.fonts.c_str());
1074
1075         bool const indent = params.paragraph_separation == BufferParams::PARSEP_INDENT;
1076         fl_set_button(class_->radio_indent, indent);
1077         fl_set_button(class_->radio_skip, !indent);
1078
1079         int pos;
1080         if (indent) {
1081                 pos = 2; // VSpace::MEDSKIP is default
1082         } else {
1083                 switch (params.getDefSkip().kind()) {
1084                 case VSpace::LENGTH:
1085                         pos = 4;
1086                         break;
1087                 case VSpace::BIGSKIP:
1088                         pos = 3;
1089                         break;
1090                 case VSpace::SMALLSKIP:
1091                         pos = 1;
1092                         break;
1093                 case VSpace::MEDSKIP:
1094                 default:
1095                         pos = 2;
1096                         break;
1097                 }
1098         }
1099         fl_set_choice (class_->choice_skip, pos);
1100
1101         bool const length_input = pos == 4;
1102         if (length_input) {
1103                 int const paperchoice = fl_get_choice(paper_->choice_papersize);
1104                 bool const metric = (paperchoice == 1 && lyxrc.default_papersize > PAPER_EXECUTIVEPAPER)
1105                         || paperchoice == 2 || paperchoice > 5;
1106                 string const default_unit = metric ? "cm" : "in";
1107                 string const length = params.getDefSkip().asLyXCommand();
1108                 updateWidgetsFromLengthString(class_->input_skip,
1109                                               class_->choice_skip_units,
1110                                               length, default_unit);
1111
1112         } else {
1113                 fl_set_input(class_->input_skip, "");
1114         }
1115         setEnabled(class_->choice_skip, !indent);
1116         setEnabled(class_->input_skip, length_input);
1117         setEnabled(class_->choice_skip_units, length_input);
1118
1119         bool const two_sides = params.sides == LyXTextClass::TwoSides;
1120         fl_set_button(class_->radio_sides_one, !two_sides);
1121         fl_set_button(class_->radio_sides_two, two_sides);
1122
1123         bool const two_columns = params.columns == 2;
1124         fl_set_button(class_->radio_columns_one, !two_columns);
1125         fl_set_button(class_->radio_columns_two, two_columns);
1126
1127         fl_set_input(class_->input_extra, params.options.c_str());
1128
1129         switch (params.spacing.getSpace()) {
1130         case Spacing::Other:
1131                 pos = 4;
1132                 break;
1133         case Spacing::Double: // \doublespacing
1134                 pos = 3;
1135                 break;
1136         case Spacing::Onehalf: // \onehalfspacing
1137                 pos = 2;
1138                 break;
1139         case Spacing::Single: // \singlespacing
1140         case Spacing::Default: // nothing bad should happen with this
1141         default:
1142                 pos = 1;
1143                 break;
1144         }
1145         fl_set_choice(class_->choice_spacing, pos);
1146
1147         bool const spacing_input = pos == 4;
1148         setEnabled(class_->input_spacing, spacing_input);
1149         string const input = spacing_input ? tostr(params.spacing.getValue()) : string();
1150         fl_set_input(class_->input_spacing, input.c_str());
1151 }
1152
1153
1154 void FormDocument::language_update(BufferParams const & params)
1155 {
1156         if (!language_.get())
1157                 return;
1158
1159         int const pos = int(findPos(lang_, params.language->lang()));
1160         fl_set_combox(language_->combox_language, pos+1);
1161
1162         fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
1163         fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
1164         fl_set_button(language_->radio_single, 0);
1165         fl_set_button(language_->radio_double, 0);
1166         if (params.quotes_times == InsetQuotes::SingleQ)
1167                 fl_set_button(language_->radio_single, 1);
1168         else
1169                 fl_set_button(language_->radio_double, 1);
1170 }
1171
1172
1173 void FormDocument::options_update(BufferParams const & params)
1174 {
1175         if (!options_.get())
1176                 return;
1177
1178         fl_set_choice_text(options_->choice_postscript_driver,
1179                            params.graphicsDriver.c_str());
1180         fl_set_choice(options_->choice_ams_math, params.use_amsmath + 1);
1181         fl_set_button(options_->check_use_natbib,  params.use_natbib);
1182         fl_set_choice(options_->choice_citation_format,
1183                       int(params.use_numerical_citations)+1);
1184         setEnabled(options_->choice_citation_format, params.use_natbib);
1185         fl_set_counter_value(options_->counter_secnumdepth, params.secnumdepth);
1186         fl_set_counter_value(options_->counter_tocdepth, params.tocdepth);
1187         if (!params.float_placement.empty())
1188                 fl_set_input(options_->input_float_placement,
1189                              params.float_placement.c_str());
1190         else
1191                 fl_set_input(options_->input_float_placement, "");
1192 }
1193
1194
1195 void FormDocument::paper_update(BufferParams const & params)
1196 {
1197         if (!paper_.get())
1198                 return;
1199
1200         fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
1201         fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
1202         fl_set_button(paper_->check_use_geometry, params.use_geometry);
1203
1204         int const paperchoice = fl_get_choice(paper_->choice_papersize);
1205         bool const useCustom = paperchoice == 2;
1206         bool const useGeom = fl_get_button(paper_->check_use_geometry);
1207
1208         fl_set_button(paper_->radio_portrait, 0);
1209         setEnabled(paper_->radio_portrait, !useCustom);
1210         fl_set_button(paper_->radio_landscape, 0);
1211         setEnabled(paper_->radio_landscape, !useCustom);
1212
1213         if (params.orientation == ORIENTATION_LANDSCAPE)
1214                 fl_set_button(paper_->radio_landscape, 1);
1215         else
1216                 fl_set_button(paper_->radio_portrait, 1);
1217         setEnabled(paper_->choice_paperpackage,
1218                    //either default papersize (preferences)
1219                    //or document papersize has to be A4
1220                    (paperchoice == 7
1221                     || paperchoice == 1 && lyxrc.default_papersize == PAPER_A4PAPER)
1222                    && fl_get_button(paper_->radio_portrait));
1223
1224         // Default unit choice is cm if metric, inches if US paper.
1225         bool const metric = (paperchoice == 1 && lyxrc.default_papersize > PAPER_EXECUTIVEPAPER)
1226                 || paperchoice == 2 || paperchoice > 5;
1227         string const default_unit = metric ? "cm" : "in";
1228         updateWidgetsFromLengthString(paper_->input_custom_width,
1229                                       paper_->choice_custom_width_units,
1230                                       params.paperwidth, default_unit);
1231         setEnabled(paper_->input_custom_width, useCustom);
1232         setEnabled(paper_->choice_custom_width_units, useCustom);
1233
1234         updateWidgetsFromLengthString(paper_->input_custom_height,
1235                                       paper_->choice_custom_height_units,
1236                                       params.paperheight, default_unit);
1237         setEnabled(paper_->input_custom_height, useCustom);
1238         setEnabled(paper_->choice_custom_height_units, useCustom);
1239
1240         updateWidgetsFromLengthString(paper_->input_inner_margin,
1241                                       paper_->choice_inner_margin_units,
1242                                       params.leftmargin, default_unit);
1243         setEnabled(paper_->input_inner_margin, useGeom);
1244         setEnabled(paper_->choice_inner_margin_units, useGeom);
1245
1246         updateWidgetsFromLengthString(paper_->input_top_margin,
1247                                       paper_->choice_top_margin_units,
1248                                       params.topmargin, default_unit);
1249         setEnabled(paper_->input_top_margin, useGeom);
1250         setEnabled(paper_->choice_top_margin_units, useGeom);
1251
1252         updateWidgetsFromLengthString(paper_->input_outer_margin,
1253                                       paper_->choice_outer_margin_units,
1254                                       params.rightmargin, default_unit);
1255         setEnabled(paper_->input_outer_margin, useGeom);
1256         setEnabled(paper_->choice_outer_margin_units, useGeom);
1257
1258         updateWidgetsFromLengthString(paper_->input_bottom_margin,
1259                                       paper_->choice_bottom_margin_units,
1260                                       params.bottommargin, default_unit);
1261         setEnabled(paper_->input_bottom_margin, useGeom);
1262         setEnabled(paper_->choice_bottom_margin_units, useGeom);
1263
1264         updateWidgetsFromLengthString(paper_->input_head_height,
1265                                       paper_->choice_head_height_units,
1266                                       params.headheight, default_unit);
1267         setEnabled(paper_->input_head_height, useGeom);
1268         setEnabled(paper_->choice_head_height_units, useGeom);
1269
1270         updateWidgetsFromLengthString(paper_->input_head_sep,
1271                                       paper_->choice_head_sep_units,
1272                                       params.headsep, default_unit);
1273         setEnabled(paper_->input_head_sep, useGeom);
1274         setEnabled(paper_->choice_head_sep_units, useGeom);
1275
1276         updateWidgetsFromLengthString(paper_->input_foot_skip,
1277                                       paper_->choice_foot_skip_units,
1278                                       params.footskip, default_unit);
1279         setEnabled(paper_->input_foot_skip, useGeom);
1280         setEnabled(paper_->choice_foot_skip_units, useGeom);
1281
1282         fl_set_focus_object(paper_->form, paper_->choice_papersize);
1283 }
1284
1285
1286 void FormDocument::bullets_update(BufferParams const & params)
1287 {
1288         if (!bullets_.get() ||
1289             ((XpmVersion<4) ||
1290              (XpmVersion==4 && XpmRevision<7)))
1291                 return;
1292
1293         bool const isLinuxDoc =
1294                 controller().docType() == ControlDocument::LINUXDOC;
1295         setEnabled(fbullet, !isLinuxDoc);
1296
1297         if (isLinuxDoc) return;
1298
1299         fl_set_button(bullets_->radio_depth_1, 1);
1300         fl_set_input(bullets_->input_latex,
1301                      params.user_defined_bullets[0].getText().c_str());
1302         fl_set_choice(bullets_->choice_size,
1303                       params.user_defined_bullets[0].getSize() + 2);
1304 }
1305
1306
1307 void FormDocument::branch_update(BufferParams const & params)
1308 {
1309         if (!branch_.get())
1310                 return;
1311         
1312         string const all_branches = params.branchlist.allBranches();
1313         fl_clear_browser(branch_->browser_all_branches);
1314         string current_branch("none");
1315         
1316         if (!all_branches.empty()) {
1317                 std::vector<string> vec = getVectorFromString(all_branches, "|");
1318                 for (unsigned i = 0; i < vec.size(); ++i) {
1319                         fl_addto_browser(branch_->browser_all_branches, vec[i].c_str());
1320                 }
1321                 fl_select_browser_line(branch_->browser_all_branches, 1);
1322                 if (!vec.empty())
1323                         current_branch =
1324                                 fl_get_browser_line(branch_->browser_all_branches, 1);
1325                 else
1326                         current_branch = "none";
1327         }
1328
1329         // display proper selection...
1330         string const all_selected = params.branchlist.allSelected();
1331         fl_clear_browser(branch_->browser_selection);
1332         if (!all_selected.empty()) {
1333                 std::vector<string> vec = getVectorFromString(all_selected, "|");
1334                 for (unsigned i = 0; i < vec.size(); ++i) {
1335                         fl_addto_browser(branch_->browser_selection, vec[i].c_str());
1336                         }
1337         }
1338         // display proper colour...
1339         RGBColor rgb;
1340         string x11hexname;
1341         if (current_branch == "none")
1342                 x11hexname = "none";
1343         else
1344                 x11hexname = params.branchlist.getColor(current_branch);
1345         if (x11hexname[0] == '#') {
1346                 rgb = RGBColor(x11hexname);
1347         } else {
1348                 fl_getmcolor(FL_COL1, &rgb.r, &rgb.g, &rgb.b);
1349         }
1350         fl_mapcolor(GUI_COLOR_CHOICE, rgb.r, rgb.g, rgb.b);
1351         fl_redraw_object(branch_->button_color);
1352
1353         setEnabled(branch_->button_select,
1354                 (fl_get_browser(branch_->browser_all_branches) > 0));
1355         setEnabled(branch_->button_deselect,
1356                 (fl_get_browser(branch_->browser_selection) > 0));
1357         setEnabled(branch_->button_remove_branch,
1358                 (fl_get_browser(branch_->browser_all_branches) > 0));
1359         setEnabled(branch_->button_modify,
1360                 (fl_get_browser(branch_->browser_all_branches) > 0));
1361 }
1362
1363
1364 void FormDocument::checkReadOnly()
1365 {
1366         if (bc().readOnly(controller().bufferIsReadonly())) {
1367                 postWarning(_("Document is read-only."
1368                               " No changes to layout permitted."));
1369         } else {
1370                 clearMessage();
1371         }
1372 }
1373
1374
1375 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/)
1376 {
1377         BufferParams & param = controller().params();
1378
1379         // convert from 1-6 range to -1-4
1380         param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1381         fl_set_input(bullets_->input_latex,
1382                      param.temp_bullets[current_bullet_depth].getText().c_str());
1383 }
1384
1385
1386 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1387 {
1388         BufferParams & param = controller().params();
1389
1390         param.temp_bullets[current_bullet_depth].
1391                 setText(getString(bullets_->input_latex));
1392 }
1393
1394
1395 void FormDocument::BulletDepth(FL_OBJECT * ob)
1396 {
1397         /* Should I do the following:                                 */
1398         /*  1. change to the panel that the current bullet belongs in */
1399         /*  2. show that bullet as selected                           */
1400         /*  3. change the size setting to the size of the bullet in Q.*/
1401         /*  4. display the latex equivalent in the latex box          */
1402         /*                                                            */
1403         /* I'm inclined to just go with 3 and 4 at the moment and     */
1404         /* maybe try to support the others later                      */
1405         BufferParams & param = controller().params();
1406
1407         int data = 0;
1408         if (ob == bullets_->radio_depth_1)
1409                 data = 0;
1410         else if (ob == bullets_->radio_depth_2)
1411                 data = 1;
1412         else if (ob == bullets_->radio_depth_3)
1413                 data = 2;
1414         else if (ob == bullets_->radio_depth_4)
1415                 data = 3;
1416
1417         switch (fl_get_button_numb(ob)) {
1418         case 3:
1419                 // right mouse button resets to default
1420                 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1421         default:
1422                 current_bullet_depth = data;
1423                 fl_set_input(bullets_->input_latex,
1424                              param.temp_bullets[data].getText().c_str());
1425                 fl_set_choice(bullets_->choice_size,
1426                               param.temp_bullets[data].getSize() + 2);
1427         }
1428 }
1429
1430
1431 void FormDocument::BulletPanel(FL_OBJECT * ob)
1432 {
1433         /* Here we have to change the background pixmap to that selected */
1434         /* by the user. (eg. standard.xpm, psnfss1.xpm etc...)           */
1435
1436         int data = 0;
1437         if (ob == bullets_->radio_panel_standard)
1438                 data = 0;
1439         else if (ob == bullets_->radio_panel_maths)
1440                 data = 1;
1441         else if (ob == bullets_->radio_panel_ding2)
1442                 data = 2;
1443         else if (ob == bullets_->radio_panel_ding3)
1444                 data = 3;
1445         else if (ob == bullets_->radio_panel_ding4)
1446                 data = 4;
1447         else if (ob == bullets_->radio_panel_ding1)
1448                 data = 5;
1449
1450         if (data != current_bullet_panel) {
1451                 fl_freeze_form(bullets_->form);
1452                 current_bullet_panel = data;
1453
1454                 /* free the current pixmap */
1455                 fl_free_bmtable_pixmap(bullets_->bmtable_panel);
1456                 string new_panel;
1457                 if (ob == bullets_->radio_panel_standard) {
1458                         new_panel = "standard";
1459                 } else if (ob == bullets_->radio_panel_maths ) {
1460                         new_panel = "amssymb";
1461                 } else if (ob == bullets_->radio_panel_ding2) {
1462                         new_panel = "psnfss1";
1463                 } else if (ob == bullets_->radio_panel_ding3) {
1464                         new_panel = "psnfss2";
1465                 } else if (ob == bullets_->radio_panel_ding4) {
1466                         new_panel = "psnfss3";
1467                 } else if (ob == bullets_->radio_panel_ding1) {
1468                         new_panel = "psnfss4";
1469                 } else {
1470                         /* something very wrong happened */
1471                         // play it safe for now but should be an exception
1472                         current_bullet_panel = 0;  // standard panel
1473                         new_panel = "standard";
1474                 }
1475                 new_panel += ".xpm";
1476                 fl_set_bmtable_pixmap_file(bullets_->bmtable_panel, 6, 6,
1477                                            LibFileSearch("images", new_panel).c_str());
1478                 fl_redraw_object(bullets_->bmtable_panel);
1479                 fl_unfreeze_form(bullets_->form);
1480         }
1481 }
1482
1483
1484 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/)
1485 {
1486         /* handle the user input by setting the current bullet depth's pixmap */
1487         /* to that extracted from the current chosen position of the BMTable  */
1488         /* Don't forget to free the button's old pixmap first.                */
1489
1490         BufferParams & param = controller().params();
1491         int bmtable_button = fl_get_bmtable(ob);
1492
1493         /* try to keep the button held down till another is pushed */
1494         /*  fl_set_bmtable(ob, 1, bmtable_button); */
1495         param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1496         param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1497         fl_set_input(bullets_->input_latex,
1498                      param.temp_bullets[current_bullet_depth].getText().c_str());
1499 }
1500
1501
1502 void FormDocument::CheckChoiceClass()
1503 {
1504         BufferParams & params = controller().params();
1505
1506         lyx::textclass_type const tc =
1507                 fl_get_combox(class_->combox_class) - 1;
1508
1509         if (controller().loadTextclass(tc)) {
1510                 params.textclass = tc;
1511
1512                 if (lyxrc.auto_reset_options) {
1513                         params.useClassDefaults();
1514                         UpdateLayoutDocument(params);
1515                 } else {
1516                         // update the params which are needed in any case
1517                         // (fontsizes, pagestyle)
1518                         UpdateClassParams(params);
1519                 }
1520
1521         } else {
1522                 int const revert = int(params.textclass);
1523                 fl_set_combox(class_->combox_class, revert + 1);
1524         }
1525 }
1526
1527
1528 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1529 {
1530         if (!dialog_.get())
1531                 return;
1532
1533         checkReadOnly();
1534         class_update(params);
1535         paper_update(params);
1536         language_update(params);
1537         options_update(params);
1538         bullets_update(params);
1539 }