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