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