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