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