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