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