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