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