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