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