]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormPreferences.C
f2d4d8ec8500e08f2d2dbe3a3a0d90612ee36cc3
[lyx.git] / src / frontends / xforms / FormPreferences.C
1 /**
2  * \file FormPreferences.C
3  * Copyright 2000-2001 The LyX Team.
4  * See the file COPYING.
5  *
6  * \author Angus Leeming, a.leeming@ic.ac.uk
7  */
8
9 #include <config.h>
10
11 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include "FormPreferences.h"
16 #include "forms/form_preferences.h"
17 #include "Dialogs.h"
18
19 #include "buffer.h"
20 #include "converter.h"
21 #include "debug.h"
22 #include "frontends/LyXView.h"
23 #include "language.h"
24 #include "frnt_lang.h"
25 #include "lyxfunc.h"
26 #include "lyxlex.h"
27 #include "lyxrc.h"
28 #include "LColor.h"
29 #include "Lsstream.h"
30 #include "funcrequest.h"
31
32 #include "combox.h"
33 #include "Color.h"
34 #include "input_validators.h"
35 #include "forms_gettext.h"
36 #include "xforms_helpers.h"
37 #include "helper_funcs.h"
38
39 #include "support/lyxfunctional.h"
40 #include "support/lyxmanip.h"
41 #include "support/filetools.h"
42 #include "support/LAssert.h"
43
44 #include "graphics/GraphicsCache.h"
45
46 #include <boost/bind.hpp>
47
48 #include FORMS_H_LOCATION
49 #include <utility>
50 #include <iomanip>
51 #include <X11/Xlib.h>
52
53 using std::endl;
54 using std::pair;
55 using std::make_pair;
56 using std::max;
57 using std::min;
58 using std::vector;
59 using std::setw;
60 using std::setfill;
61
62 extern string system_lyxdir;
63 extern string user_lyxdir;
64
65 namespace {
66
67 // These should probably go inside the class definition...
68 Formats    local_formats;
69 Converters local_converters;
70
71 } // namespace anon
72
73
74 FormPreferences::FormPreferences(LyXView & lv, Dialogs & d)
75         : FormBaseBI(&lv, &d, _("Preferences"), false),
76           colors_(*this), converters_(*this), inputs_misc_(*this),
77           formats_(*this), interface_(*this), language_(*this),
78           lnf_misc_(*this), outputs_misc_(*this), paths_(*this),
79           printer_(*this), screen_fonts_(*this), spelloptions_(*this)
80 {
81         // let the dialog be shown
82         // This is a permanent connection so we won't bother
83         // storing a copy because we won't be disconnecting.
84 }
85
86
87 void FormPreferences::redraw()
88 {
89         if (!(form() && form()->visible))
90                 return;
91         fl_redraw_form(form());
92
93         FL_FORM * form2 = fl_get_active_folder(dialog_->tabfolder_prefs);
94         if (!(form2 && form2->visible))
95                 return;
96         fl_redraw_form(form2);
97
98         FL_FORM * form3 = 0;
99         if (form2 == converters_tab_->form)
100                 form3 = fl_get_active_folder(converters_tab_->tabfolder_inner);
101
102         else if (form2 == look_n_feel_tab_->form)
103                 form3 = fl_get_active_folder(look_n_feel_tab_->tabfolder_inner);
104
105         else if (form2 == inputs_tab_->form)
106                 form3 = fl_get_active_folder(inputs_tab_->tabfolder_inner);
107
108         else if (form2 == outputs_tab_->form)
109                 form3 = fl_get_active_folder(outputs_tab_->tabfolder_inner);
110
111         else if (form2 == lang_opts_tab_->form)
112                 form3 = fl_get_active_folder(lang_opts_tab_->tabfolder_inner);
113
114         if (form3 && form3->visible)
115                 fl_redraw_form(form3);
116 }
117
118
119 FL_FORM * FormPreferences::form() const
120 {
121         return dialog_.get() ? dialog_->form : 0;
122 }
123
124
125 void FormPreferences::ok()
126 {
127         FormBaseDeprecated::ok();
128
129         if (colors_.modifiedXformsPrefs) {
130                 string const filename =
131                         AddName(user_lyxdir, "preferences.xform");
132                 colors_.modifiedXformsPrefs = !XformsColor::write(filename);
133         }
134
135         lv_->getLyXFunc()->dispatch(LFUN_SAVEPREFERENCES);
136 }
137
138
139 void FormPreferences::hide()
140 {
141         // We need to hide the active tabfolder otherwise we get a
142         // BadDrawable error from X window and LyX crashes without saving.
143         FL_FORM * inner_form = fl_get_active_folder(dialog_->tabfolder_prefs);
144         if (inner_form && inner_form->visible)
145                 fl_hide_form(inner_form);
146         FormBaseDeprecated::hide();
147 }
148
149
150 void FormPreferences::build()
151 {
152         dialog_.reset(build_preferences(this));
153
154         // Manage the restore, save, apply and cancel/close buttons
155         bc().setOK(dialog_->button_ok);
156         bc().setApply(dialog_->button_apply);
157         bc().setCancel(dialog_->button_close);
158         bc().setRestore(dialog_->button_restore);
159
160         // Allow the base class to control messages
161         setMessageWidget(dialog_->text_warning);
162
163         // build the tab folders
164         converters_tab_.reset(build_preferences_inner_tab(this));
165         look_n_feel_tab_.reset(build_preferences_inner_tab(this));
166         inputs_tab_.reset(build_preferences_inner_tab(this));
167         outputs_tab_.reset(build_preferences_inner_tab(this));
168         lang_opts_tab_.reset(build_preferences_inner_tab(this));
169
170         // build actual tabfolder contents
171         // these will become nested tabfolders
172         colors_.build();
173         converters_.build();
174         formats_.build();
175         inputs_misc_.build();
176         interface_.build();
177         language_.build();
178         lnf_misc_.build();
179         outputs_misc_.build();
180         paths_.build();
181         printer_.build();
182         screen_fonts_.build();
183         spelloptions_.build();
184
185         // Now add them to the tabfolder
186         fl_addto_tabfolder(dialog_->tabfolder_prefs,
187                            _("Look & Feel"),
188                            look_n_feel_tab_->form);
189         fl_addto_tabfolder(dialog_->tabfolder_prefs,
190                            _("Lang Opts"),
191                            lang_opts_tab_->form);
192         fl_addto_tabfolder(dialog_->tabfolder_prefs,
193                            _("Conversion"),
194                            converters_tab_->form);
195         fl_addto_tabfolder(dialog_->tabfolder_prefs,
196                            _("Inputs"),
197                            inputs_tab_->form);
198         fl_addto_tabfolder(dialog_->tabfolder_prefs,
199                            _("Outputs"),
200                            outputs_tab_->form);
201
202         // now build the nested tabfolders
203         // Starting with look and feel
204         fl_addto_tabfolder(look_n_feel_tab_->tabfolder_inner,
205                            _("Screen Fonts"),
206                            screen_fonts_.dialog()->form);
207         fl_addto_tabfolder(look_n_feel_tab_->tabfolder_inner,
208                            _("Interface"),
209                            interface_.dialog()->form);
210         fl_addto_tabfolder(look_n_feel_tab_->tabfolder_inner,
211                            _("Colors"),
212                            colors_.dialog()->form);
213         fl_addto_tabfolder(look_n_feel_tab_->tabfolder_inner,
214                            _("Misc"),
215                            lnf_misc_.dialog()->form);
216
217         // then build converters
218         fl_addto_tabfolder(converters_tab_->tabfolder_inner,
219                            _("Formats"),
220                            formats_.dialog()->form);
221         fl_addto_tabfolder(converters_tab_->tabfolder_inner,
222                            _("Converters"),
223                            converters_.dialog()->form);
224
225         // then build inputs
226         // Paths should probably go in a few inner_tab called Files
227         fl_addto_tabfolder(inputs_tab_->tabfolder_inner,
228                            _("Paths"),
229                            paths_.dialog()->form);
230         fl_addto_tabfolder(inputs_tab_->tabfolder_inner,
231                            _("Misc"),
232                            inputs_misc_.dialog()->form);
233
234         // then building outputs
235         fl_addto_tabfolder(outputs_tab_->tabfolder_inner,
236                            _("Printer"),
237                            printer_.dialog()->form);
238         fl_addto_tabfolder(outputs_tab_->tabfolder_inner,
239                            _("Misc"),
240                            outputs_misc_.dialog()->form);
241
242         // then building usage
243         fl_addto_tabfolder(lang_opts_tab_->tabfolder_inner,
244                            _("Spell checker"),
245                            spelloptions_.dialog()->form);
246         fl_addto_tabfolder(lang_opts_tab_->tabfolder_inner,
247                            _("Language"),
248                            language_.dialog()->form);
249 }
250
251
252 void FormPreferences::apply()
253 {
254         // set the new lyxrc entries
255         // many of these need to trigger other functions when the assignment
256         // is made.  For example, screen zoom and font types.  These could be
257         // handled either by signals/slots in lyxrc or just directly call the
258         // associated functions here.
259         // There are other problems with this scheme.  We really should check
260         // what we copy to make sure that it really is necessary to do things
261         // like update the screen fonts because that flushes the textcache
262         // and other stuff which may cost us a lot on slower/high-load
263         // machines.
264
265         colors_.apply();
266         formats_.apply();    // Must be before converters_.apply()
267         converters_.apply();
268         inputs_misc_.apply();
269         interface_.apply();
270         language_.apply();
271         lnf_misc_.apply();
272         outputs_misc_.apply();
273         paths_.apply();
274         printer_.apply();
275         screen_fonts_.apply();
276         spelloptions_.apply();
277 }
278
279
280 string const FormPreferences::getFeedback(FL_OBJECT * ob)
281 {
282         lyx::Assert(ob);
283
284         if (ob->form->fdui == colors_.dialog())
285                 return colors_.feedback(ob);
286         if (ob->form->fdui == converters_.dialog())
287                 return converters_.feedback(ob);
288         if (ob->form->fdui == formats_.dialog())
289                 return formats_.feedback(ob);
290         if (ob->form->fdui == inputs_misc_.dialog())
291                 return inputs_misc_.feedback(ob);
292         if (ob->form->fdui == interface_.dialog())
293                 return interface_.feedback(ob);
294         if (ob->form->fdui == language_.dialog())
295                 return language_.feedback(ob);
296         if (ob->form->fdui == lnf_misc_.dialog())
297                 return lnf_misc_.feedback(ob);
298         if (ob->form->fdui == outputs_misc_.dialog())
299                 return outputs_misc_.feedback(ob);
300         if (ob->form->fdui == paths_.dialog())
301                 return paths_.feedback(ob);
302         if (ob->form->fdui == printer_.dialog())
303                 return printer_.feedback(ob);
304         if (ob->form->fdui == screen_fonts_.dialog())
305                 return screen_fonts_.feedback(ob);
306         if (ob->form->fdui == spelloptions_.dialog())
307                 return spelloptions_.feedback(ob);
308
309         return string();
310 }
311
312
313 bool FormPreferences::input(FL_OBJECT * ob, long)
314 {
315         lyx::Assert(ob);
316
317         // whatever checks you need to ensure the user hasn't entered
318         // some totally ridiculous value somewhere.  Change activate to suit.
319         // comments before each test describe what is _valid_
320
321         if (ob->form->fdui == colors_.dialog()) {
322                 colors_.input(ob);
323                 return true;
324         }
325         if (ob->form->fdui == converters_.dialog())
326                 return converters_.input(ob);
327         if (ob->form->fdui == formats_.dialog())
328                 return formats_.input(ob);
329         if (ob->form->fdui == interface_.dialog())
330                 return interface_.input(ob);
331         if (ob->form->fdui == language_.dialog())
332                 return language_.input(ob);
333         if (ob->form->fdui == paths_.dialog())
334                 return paths_.input(ob);
335         if (ob->form->fdui == screen_fonts_.dialog())
336                 return screen_fonts_.input();
337         if (ob->form->fdui == spelloptions_.dialog())
338                 return spelloptions_.input(ob);
339
340         return true;
341 }
342
343
344 void FormPreferences::update()
345 {
346         if (!dialog_.get()) return;
347
348         // read lyxrc entries
349         colors_.update();
350         formats_.update();   // Must be before converters_.update()
351         converters_.update();
352         inputs_misc_.update();
353         interface_.update();
354         language_.update();
355         lnf_misc_.update();
356         outputs_misc_.update();
357         paths_.update();
358         printer_.update();
359         screen_fonts_.update();
360         spelloptions_.update();
361 }
362
363
364 FormPreferences::Colors::Colors(FormPreferences & p)
365         : modifiedXformsPrefs(false), parent_(p)
366 {}
367
368
369 FD_preferences_colors const * FormPreferences::Colors::dialog()
370 {
371         return dialog_.get();
372 }
373
374
375 void FormPreferences::Colors::apply()
376 {
377         bool modifiedText = false;
378         bool modifiedBackground = false;
379
380         for (vector<XformsColor>::const_iterator cit = xformsColorDB.begin();
381              cit != xformsColorDB.end(); ++cit) {
382                 RGBColor col;
383                 fl_getmcolor(cit->colorID, &col.r, &col.g, &col.b);
384                 if (col != cit->color()) {
385                         modifiedXformsPrefs = true;
386                         if (cit->colorID == FL_BLACK)
387                                 modifiedText = true;
388                         if (cit->colorID == FL_COL1)
389                                 modifiedBackground = true;
390                 }
391         }
392
393         if (modifiedXformsPrefs) {
394                 for (vector<XformsColor>::const_iterator cit =
395                              xformsColorDB.begin();
396                      cit != xformsColorDB.end(); ++cit) {
397                         fl_mapcolor(cit->colorID, cit->r, cit->g, cit->b);
398
399                         if (modifiedText && cit->colorID == FL_BLACK) {
400                                 AdjustVal(FL_INACTIVE, FL_BLACK, 0.5);
401                         }
402
403                         if (modifiedBackground && cit->colorID == FL_COL1) {
404                                 AdjustVal(FL_MCOL,      FL_COL1, 0.1);
405                                 AdjustVal(FL_TOP_BCOL,  FL_COL1, 0.1);
406                                 AdjustVal(FL_LEFT_BCOL, FL_COL1, 0.1);
407
408                                 AdjustVal(FL_RIGHT_BCOL,  FL_COL1, -0.5);
409                                 AdjustVal(FL_BOTTOM_BCOL, FL_COL1, -0.5);
410                         }
411
412                         if (cit->colorID == GUI_COLOR_CURSOR) {
413                                 fl_mapcolor(GUI_COLOR_CURSOR,
414                                             cit->r, cit->g, cit->b);
415                                 setCursorColor(GUI_COLOR_CURSOR);
416                         }
417                 }
418                 parent_.lv_->getDialogs()->redrawGUI();
419         }
420
421         // Now do the same for the LyX LColors...
422         for (vector<NamedColor>::const_iterator cit = lyxColorDB.begin();
423              cit != lyxColorDB.end(); ++cit) {
424                 LColor::color lc = lcolor.getFromGUIName(cit->getname());
425                 if (lc == LColor::inherit) continue;
426
427                 // Create a valid X11 name of the form "#rrggbb"
428                 string const hexname = X11hexname(cit->color());
429
430                 if (lcolor.getX11Name(lc) != hexname) {
431                         lyxerr[Debug::GUI]
432                                 << "FormPreferences::Colors::apply: "
433                                 << "resetting LColor " << lcolor.getGUIName(lc)
434                                 << " from \"" << lcolor.getX11Name(lc)
435                                 << "\" to \"" << hexname << "\"."
436                                 << endl;
437
438                         string const s = lcolor.getLyXName(lc) + string(" ") +
439                                 hexname;
440                         parent_.lv_->getLyXFunc()->dispatch(FuncRequest(LFUN_SET_COLOR, s));
441                 }
442         }
443 }
444
445
446 void FormPreferences::Colors::build()
447 {
448         dialog_.reset(build_preferences_colors(&parent_));
449
450         fl_set_object_color(dialog_->button_color,
451                             GUI_COLOR_CHOICE, GUI_COLOR_CHOICE);
452
453         fl_set_object_color(dialog_->dial_hue, GUI_COLOR_HUE_DIAL, FL_BLACK);
454         fl_set_dial_bounds(dialog_->dial_hue, 0.0, 360.0);
455         fl_set_dial_step(dialog_->dial_hue, 1.0);
456         fl_set_dial_return(dialog_->dial_hue, FL_RETURN_CHANGED);
457
458         fl_set_slider_bounds(dialog_->slider_saturation, 0.0, 1.0);
459         fl_set_slider_step(dialog_->slider_saturation, 0.01);
460         fl_set_slider_return(dialog_->slider_saturation, FL_RETURN_CHANGED);
461
462         fl_set_slider_bounds(dialog_->slider_value, 0.0, 1.0);
463         fl_set_slider_step(dialog_->slider_value, 0.01);
464         fl_set_slider_return(dialog_->slider_value, FL_RETURN_CHANGED);
465
466         fl_set_slider_bounds(dialog_->slider_red, 0.0, 255.0);
467         fl_set_slider_step(dialog_->slider_red, 1.0);
468         fl_set_slider_return(dialog_->slider_red, FL_RETURN_CHANGED);
469
470         fl_set_slider_bounds(dialog_->slider_green, 0.0, 255.0);
471         fl_set_slider_step(dialog_->slider_green, 1.0);
472         fl_set_slider_return(dialog_->slider_green, FL_RETURN_CHANGED);
473
474         fl_set_slider_bounds(dialog_->slider_blue, 0.0, 255.0);
475         fl_set_slider_step(dialog_->slider_blue, 1.0);
476         fl_set_slider_return(dialog_->slider_blue, FL_RETURN_CHANGED);
477
478         // set up the feedback mechanism
479         setPrehandler(dialog_->browser_lyx_objs);
480         setPrehandler(dialog_->button_color);
481         setPrehandler(dialog_->button_modify);
482         setPrehandler(dialog_->dial_hue);
483         setPrehandler(dialog_->slider_saturation);
484         setPrehandler(dialog_->slider_value);
485         setPrehandler(dialog_->slider_red);
486         setPrehandler(dialog_->slider_green);
487         setPrehandler(dialog_->slider_blue);
488         setPrehandler(dialog_->radio_rgb);
489         setPrehandler(dialog_->radio_hsv);
490 }
491
492
493 string const
494 FormPreferences::Colors::feedback(FL_OBJECT const * const ob) const
495 {
496         if (ob == dialog_->browser_lyx_objs)
497                 return _("LyX objects that can be assigned a color.");
498
499         if (ob == dialog_->button_modify)
500                 return _("Modify the LyX object's color. Note: you must then \"Apply\" the change.");
501
502         if (ob == dialog_->dial_hue ||
503                   ob == dialog_->slider_saturation ||
504                   ob == dialog_->slider_value ||
505                   ob == dialog_->slider_red ||
506                   ob == dialog_->slider_green ||
507                   ob == dialog_->slider_blue)
508                 return  _("Find a new color.");
509
510         if (ob == dialog_->radio_rgb || ob == dialog_->radio_hsv)
511                 return _("Toggle between RGB and HSV color spaces.");
512
513         return string();
514 }
515
516
517 void FormPreferences::Colors::input(FL_OBJECT const * const ob)
518 {
519         if (ob == dialog_->browser_lyx_objs) {
520                 InputBrowserLyX();
521
522         } else if (ob == dialog_->dial_hue ||
523                    ob == dialog_->slider_saturation ||
524                    ob == dialog_->slider_value) {
525                 InputHSV();
526
527         } else if (ob == dialog_->slider_red ||
528                    ob == dialog_->slider_green ||
529                    ob == dialog_->slider_blue) {
530                 InputRGB();
531
532         } else if (ob == dialog_->radio_rgb ||
533                    ob == dialog_->radio_hsv) {
534                 SwitchColorSpace();
535
536         } else if (ob == dialog_->button_modify) {
537                 Modify();
538         }
539 }
540
541
542 void FormPreferences::Colors::AdjustVal(int colAdjust, int colParent,
543                                         double addVal) const
544 {
545         RGBColor rgb;
546         fl_getmcolor(colParent, &rgb.r, &rgb.g, &rgb.b);
547
548         HSVColor hsv(rgb);
549         hsv.v += addVal;
550         hsv.v = min(1.0, max(0.0, hsv.v));
551
552         rgb = RGBColor(hsv);
553         fl_mapcolor(colAdjust, rgb.r, rgb.g, rgb.b);
554 }
555
556
557 void FormPreferences::Colors::InputBrowserLyX() const
558 {
559         vector<NamedColor>::size_type const selLyX =
560                 fl_get_browser(dialog_->browser_lyx_objs);
561         if (selLyX < 1) return;
562
563         // Is the choice an Xforms color...
564         RGBColor col;
565
566         if (selLyX - 1 < xformsColorDB.size()) {
567                 vector<XformsColor>::size_type const i = selLyX - 1;
568                 col = xformsColorDB[i].color();
569         }
570         // or a LyX Logical color?
571         else {
572                 vector<NamedColor>::size_type const i = selLyX - 1 -
573                         xformsColorDB.size();
574                 col = lyxColorDB[i].color();
575         }
576
577         fl_freeze_form(dialog_->form);
578
579         fl_mapcolor(GUI_COLOR_CHOICE, col.r, col.g, col.b);
580         fl_redraw_object(dialog_->button_color);
581
582         // Display either RGB or HSV but not both!
583         SwitchColorSpace();
584
585         // Deactivate the modify button to begin with...
586         setEnabled(dialog_->button_modify, false);
587
588         fl_unfreeze_form(dialog_->form);
589 }
590
591
592 void FormPreferences::Colors::InputHSV()
593 {
594         double const hue = fl_get_dial_value(dialog_->dial_hue);
595         double const sat = fl_get_slider_value(dialog_->slider_saturation);
596         double const val = fl_get_slider_value(dialog_->slider_value);
597
598         int const h = int(hue);
599         int const s = int(100.0 * sat);
600         int const v = int(100.0 * val);
601
602         string const label = tostr(h) + string(", ") + tostr(s) + string(", ") +
603                 tostr(v);
604         fl_set_object_label(dialog_->text_color_values, label.c_str());
605
606         RGBColor col = HSVColor(hue, sat, val);
607
608         fl_freeze_form(dialog_->form);
609
610         fl_mapcolor(GUI_COLOR_CHOICE, col.r, col.g, col.b);
611         fl_redraw_object(dialog_->button_color);
612
613         col = HSVColor(hue, 1.0, 1.0);
614         col.r = max(col.r, 0);
615         fl_mapcolor(GUI_COLOR_HUE_DIAL, col.r, col.g, col.b);
616         fl_redraw_object(dialog_->dial_hue);
617
618         // Ascertain whether to activate the Modify button.
619         vector<NamedColor>::size_type const selLyX =
620                 fl_get_browser(dialog_->browser_lyx_objs);
621
622         fl_unfreeze_form(dialog_->form);
623         if (selLyX < 1) return;
624
625         fl_getmcolor(GUI_COLOR_CHOICE, &col.r, &col.g, &col.b);
626         bool modify = false;
627
628         // Is the choice an Xforms color...
629         if (selLyX - 1 < xformsColorDB.size()) {
630                 vector<XformsColor>::size_type const i = selLyX - 1;
631                 modify = (xformsColorDB[i].color() != col);
632         }
633         // or a LyX Logical color?
634         else {
635                 vector<NamedColor>::size_type const i = selLyX - 1 -
636                         xformsColorDB.size();
637                 modify = (lyxColorDB[i].color() != col);
638         }
639
640         setEnabled(dialog_->button_modify, modify);
641 }
642
643
644 void FormPreferences::Colors::InputRGB()
645 {
646         int const red   = int(fl_get_slider_value(dialog_->slider_red));
647         int const green = int(fl_get_slider_value(dialog_->slider_green));
648         int const blue  = int(fl_get_slider_value(dialog_->slider_blue));
649
650         string const label = tostr(red) + string(", ") + tostr(green) +
651                 string(", ") + tostr(blue);
652         fl_set_object_label(dialog_->text_color_values, label.c_str());
653
654         fl_freeze_form(dialog_->form);
655
656         RGBColor col = RGBColor(red, green, blue);
657         fl_mapcolor(GUI_COLOR_CHOICE, col.r, col.g, col.b);
658         fl_redraw_object(dialog_->button_color);
659
660         // Ascertain whether to activate the Modify button.
661         vector<NamedColor>::size_type const selLyX =
662                 fl_get_browser(dialog_->browser_lyx_objs);
663
664         fl_unfreeze_form(dialog_->form);
665         if (selLyX < 1) return;
666
667         bool modify = false;
668
669         // Is the choice an Xforms color...
670         if (selLyX - 1 < xformsColorDB.size()) {
671                 vector<XformsColor>::size_type const i = selLyX - 1;
672                 modify = (xformsColorDB[i].color() != col);
673         }
674         // or a LyX Logical color?
675         else {
676                 vector<NamedColor>::size_type const i = selLyX - 1 -
677                         xformsColorDB.size();
678                 modify = (lyxColorDB[i].color() != col);
679         }
680
681         setEnabled(dialog_->button_modify, modify);
682 }
683
684
685 void FormPreferences::Colors::LoadBrowserLyX()
686 {
687         if (!dialog_->browser_lyx_objs->visible)
688                 return;
689
690         // First, define the modifiable xforms colors
691         xformsColorDB.clear();
692         XformsColor xcol;
693
694         xcol.name = _("GUI background");
695         xcol.colorID = FL_COL1;
696         fl_getmcolor(FL_COL1, &xcol.r, &xcol.g, &xcol.b);
697
698         xformsColorDB.push_back(xcol);
699
700         xcol.name = _("GUI text");
701         xcol.colorID = FL_BLACK;
702         fl_getmcolor(FL_BLACK, &xcol.r, &xcol.g, &xcol.b);
703
704         xformsColorDB.push_back(xcol);
705
706         xcol.name = _("GUI selection");
707         xcol.colorID = FL_YELLOW;
708         fl_getmcolor(FL_YELLOW, &xcol.r, &xcol.g, &xcol.b);
709
710         xformsColorDB.push_back(xcol);
711
712         xcol.name = _("GUI pointer");
713         xcol.colorID = GUI_COLOR_CURSOR;
714         fl_getmcolor(GUI_COLOR_CURSOR, &xcol.r, &xcol.g, &xcol.b);
715
716         xformsColorDB.push_back(xcol);
717
718         // Now create the the LyX LColors database
719         lyxColorDB.clear();
720         for (int i=0; i<LColor::ignore; ++i) {
721                 LColor::color lc = static_cast<LColor::color>(i);
722                 if (lc == LColor::none
723                     || lc == LColor::black
724                     || lc == LColor::white
725                     || lc == LColor::red
726                     || lc == LColor::green
727                     || lc == LColor::blue
728                     || lc == LColor::cyan
729                     || lc == LColor::magenta
730                     || lc == LColor::yellow
731                     || lc == LColor::inherit
732                     || lc == LColor::ignore) continue;
733
734                 string const name = lcolor.getX11Name(lc);
735                 Display * display = fl_get_display();;
736                 Colormap const colormap = fl_state[fl_get_vclass()].colormap;
737                 XColor xcol, ccol;
738
739                 if (XLookupColor(display, colormap, name.c_str(), &xcol, &ccol)
740                     == 0) {
741                         lyxerr << "FormPreferences::Colors::LoadBrowserLyX:\n"
742                                << "LColor " << lcolor.getLyXName(lc)
743                                << ": X can't find color \"" << name
744                                << "\". Set to \"black\"!" << endl;
745
746                         string const arg = lcolor.getLyXName(lc) + " black";
747                         parent_.lv_->getLyXFunc()->
748                                 dispatch(FuncRequest(LFUN_SET_COLOR, arg));
749                         continue;
750                 }
751
752                 // X has found the color. Now find the "appropriate" X11 name
753                 // for this color.
754
755                 // Note that X stores the RGB values in the range 0 - 65535
756                 // whilst we require them in the range 0 - 255.
757                 RGBColor col;
758                 col.r = xcol.red   / 256;
759                 col.g = xcol.green / 256;
760                 col.b = xcol.blue  / 256;
761
762                 // Create a valid X11 name of the form "#rrggbb" and change the
763                 // LColor X11name to this. Don't want to trigger a redraw,
764                 // as we're just changing the name not the RGB values.
765                 // Also reset the system_lcolor names, so that we don't output
766                 // unnecessary changes.
767                 string const hexname = X11hexname(col);
768
769                 if (lcolor.getX11Name(lc) != hexname) {
770                         lcolor.setColor(lc, hexname);
771                         system_lcolor.setColor(lc, hexname);
772                 }
773
774                 // Finally, push the color onto the database
775                 NamedColor ncol(lcolor.getGUIName(lc), col);
776                 lyxColorDB.push_back(ncol);
777         }
778
779         // Now construct the browser
780         FL_OBJECT * colbr = dialog_->browser_lyx_objs;
781         fl_freeze_form(dialog_->form);
782         fl_clear_browser(colbr);
783         for (vector<XformsColor>::const_iterator cit = xformsColorDB.begin();
784              cit != xformsColorDB.end(); ++cit) {
785                 fl_addto_browser(colbr, cit->getname().c_str());
786         }
787         for (vector<NamedColor>::const_iterator cit = lyxColorDB.begin();
788              cit != lyxColorDB.end(); ++cit) {
789                 fl_addto_browser(colbr, cit->getname().c_str());
790         }
791
792         // just to be safe...
793         fl_set_browser_topline(dialog_->browser_lyx_objs, 1);
794         fl_select_browser_line(dialog_->browser_lyx_objs, 1);
795         fl_unfreeze_form(dialog_->form);
796
797         InputBrowserLyX();
798 }
799
800
801 void FormPreferences::Colors::Modify()
802 {
803         vector<NamedColor>::size_type const selLyX =
804                 fl_get_browser(dialog_->browser_lyx_objs);
805         if (selLyX < 1)
806                 return;
807
808         RGBColor col;
809         fl_getmcolor(GUI_COLOR_CHOICE, &col.r, &col.g, &col.b);
810
811         // Is the choice an Xforms color...
812         if (selLyX - 1 < xformsColorDB.size()) {
813                 vector<XformsColor>::size_type const i = selLyX - 1;
814                 xformsColorDB[i].r  = col.r;
815                 xformsColorDB[i].g  = col.g;
816                 xformsColorDB[i].b  = col.b;
817         }
818         // or a LyX Logical color?
819         else {
820                 vector<NamedColor>::size_type const i = selLyX - 1 -
821                         xformsColorDB.size();
822                 lyxColorDB[i].r  = col.r;
823                 lyxColorDB[i].g  = col.g;
824                 lyxColorDB[i].b  = col.b;
825         }
826
827         fl_freeze_form(dialog_->form);
828         setEnabled(dialog_->button_modify, false);
829         fl_unfreeze_form(dialog_->form);
830 }
831
832
833 void FormPreferences::Colors::SwitchColorSpace() const
834 {
835         bool const hsv = fl_get_button(dialog_->radio_hsv);
836
837         RGBColor col;
838         fl_getmcolor(GUI_COLOR_CHOICE, &col.r, &col.g, &col.b);
839
840         fl_freeze_form(dialog_->form);
841
842         if (hsv) {
843                 fl_hide_object(dialog_->slider_red);
844                 fl_hide_object(dialog_->slider_blue);
845                 fl_hide_object(dialog_->slider_green);
846                 fl_show_object(dialog_->dial_hue);
847                 fl_show_object(dialog_->slider_saturation);
848                 fl_show_object(dialog_->slider_value);
849
850                 HSVColor hsv = HSVColor(col);
851                 hsv.h = max(hsv.h, 0.0);
852
853                 fl_set_dial_value(dialog_->dial_hue, hsv.h);
854                 fl_set_slider_value(dialog_->slider_saturation, hsv.s);
855                 fl_set_slider_value(dialog_->slider_value, hsv.v);
856
857                 col = HSVColor(hsv.h, 1.0, 1.0);
858                 col.r = max(col.r, 0);
859                 fl_mapcolor(GUI_COLOR_HUE_DIAL, col.r, col.g, col.b);
860                 fl_redraw_object(dialog_->dial_hue);
861
862                 // Adjust the label a bit, but not the actual values.
863                 // Means that toggling from one space to the other has no
864                 // effect on the final color.
865                 int const h = int(hsv.h);
866                 int const s = int(100 * hsv.s);
867                 int const v = int(100 * hsv.v);
868                 string const label = tostr(h) + ", " + tostr(s) +
869                         ", " + tostr(v);
870                 fl_set_object_label(dialog_->text_color_values, label.c_str());
871
872         } else {
873                 fl_show_object(dialog_->slider_red);
874                 fl_show_object(dialog_->slider_blue);
875                 fl_show_object(dialog_->slider_green);
876                 fl_hide_object(dialog_->dial_hue);
877                 fl_hide_object(dialog_->slider_saturation);
878                 fl_hide_object(dialog_->slider_value);
879
880                 fl_set_slider_value(dialog_->slider_red,   col.r);
881                 fl_set_slider_value(dialog_->slider_green, col.g);
882                 fl_set_slider_value(dialog_->slider_blue,  col.b);
883
884                 // Adjust the label a bit. Same reasoning as above.
885                 int const r = int(col.r);
886                 int const g = int(col.g);
887                 int const b = int(col.b);
888                 string const label = tostr(r) + ", " + tostr(g) +
889                         ", " + tostr(b);
890                 fl_set_object_label(dialog_->text_color_values, label.c_str());
891         }
892
893         fl_unfreeze_form(dialog_->form);
894 }
895
896 string const FormPreferences::Colors::X11hexname(RGBColor const & col) const
897 {
898         ostringstream ostr;
899
900         ostr << "#" << std::setbase(16) << setfill('0')
901              << setw(2) << col.r
902              << setw(2) << col.g
903              << setw(2) << col.b;
904
905         return ostr.str().c_str();
906 }
907
908
909 FormPreferences::Converters::Converters(FormPreferences & p)
910         : parent_(p)
911 {}
912
913
914 FD_preferences_converters const * FormPreferences::Converters::dialog()
915 {
916         return dialog_.get();
917 }
918
919
920 void FormPreferences::Converters::apply() const
921 {
922         converters = local_converters;
923         converters.update(formats);
924         converters.buildGraph();
925 }
926
927
928 void FormPreferences::Converters::build()
929 {
930         dialog_.reset(build_preferences_converters(&parent_));
931
932         fl_set_input_return(dialog_->input_converter, FL_RETURN_CHANGED);
933         fl_set_input_return(dialog_->input_flags, FL_RETURN_CHANGED);
934
935         // set up the feedback mechanism
936         setPrehandler(dialog_->browser_all);
937         setPrehandler(dialog_->button_delete);
938         setPrehandler(dialog_->button_add);
939         setPrehandler(dialog_->input_converter);
940         setPrehandler(dialog_->choice_from);
941         setPrehandler(dialog_->choice_to);
942         setPrehandler(dialog_->input_flags);
943 }
944
945
946 string const
947 FormPreferences::Converters::feedback(FL_OBJECT const * const ob) const
948 {
949         if (ob == dialog_->browser_all)
950                 return _("All the currently defined converters known to LyX.");
951
952         if (ob == dialog_->choice_from)
953                 return _("Convert \"from\" this format");
954
955         if (ob == dialog_->choice_to)
956                 return _("Convert \"to\" this format");
957
958         if (ob == dialog_->input_converter)
959                 return _("The conversion command. $$i is the input file name, "
960                          "$$b is the file name without its extension and $$o is "
961                          "the name of the output file. $$s can be used as path to "
962                          "LyX's own collection of conversion scripts.");
963
964         if (ob == dialog_->input_flags)
965                 return _("Extra information for the Converter class, whether and "
966                          "how to parse the result, and various other things.");
967
968         if (ob == dialog_->button_delete)
969                 return _("Remove the current converter from the list of available "
970                          "converters. Note: you must then \"Apply\" the change.");
971
972         if (ob == dialog_->button_add) {
973                 if (string(ob->label) == _("Add"))
974                         return _("Add the current converter to the list of available "
975                                  "converters. Note: you must then \"Apply\" the change.");
976                 else
977                         return _("Modify the contents of the current converter. "
978                                  "Note: you must then \"Apply\" the change.");
979         }
980
981         return string();
982 }
983
984
985 bool FormPreferences::Converters::input(FL_OBJECT const * const ob)
986 {
987         if (ob == dialog_->browser_all)
988                 return Browser();
989
990         if (ob == dialog_->choice_from
991                    || ob == dialog_->choice_to
992                    || ob == dialog_->input_converter
993                    || ob == dialog_->input_flags)
994                 return Input();
995
996         if (ob == dialog_->button_add)
997                 return Add();
998
999         if (ob == dialog_->button_delete)
1000                 return erase();
1001
1002         return true;
1003 }
1004
1005
1006 void FormPreferences::Converters::update()
1007 {
1008         local_converters = converters;
1009         local_converters.update(local_formats);
1010         UpdateBrowser();
1011 }
1012
1013
1014 void FormPreferences::Converters::UpdateBrowser()
1015 {
1016         local_converters.sort();
1017
1018         fl_freeze_form(dialog_->form);
1019         fl_clear_browser(dialog_->browser_all);
1020         for (::Converters::const_iterator cit = local_converters.begin();
1021              cit != local_converters.end(); ++cit) {
1022                 string const name = cit->From->prettyname() + " -> "
1023                         + cit->To->prettyname();
1024                 fl_addto_browser(dialog_->browser_all, name.c_str());
1025         }
1026         Input();
1027         fl_unfreeze_form(dialog_->form);
1028 }
1029
1030
1031 bool FormPreferences::Converters::Add()
1032 {
1033         string const from = GetFrom();
1034         string const to = GetTo();
1035         string const command = fl_get_input(dialog_->input_converter);
1036         string const flags = fl_get_input(dialog_->input_flags);
1037
1038         Converter const * old = local_converters.getConverter(from, to);
1039         local_converters.add(from, to, command, flags);
1040         if (!old) {
1041                 local_converters.updateLast(local_formats);
1042                 UpdateBrowser();
1043         }
1044         setEnabled(dialog_->button_add, false);
1045
1046         return true;
1047 }
1048
1049
1050 bool FormPreferences::Converters::Browser()
1051 {
1052         int const i = fl_get_browser(dialog_->browser_all);
1053         if (i <= 0) return false;
1054
1055         fl_freeze_form(dialog_->form);
1056
1057         Converter const & c = local_converters.get(i - 1);
1058         int j = local_formats.getNumber(c.from);
1059         if (j >= 0)
1060                 fl_set_choice(dialog_->choice_from, j + 1);
1061
1062         j = local_formats.getNumber(c.to);
1063         if (j >= 0)
1064                 fl_set_choice(dialog_->choice_to, j + 1);
1065
1066         fl_set_input(dialog_->input_converter, c.command.c_str());
1067         fl_set_input(dialog_->input_flags, c.flags.c_str());
1068
1069         fl_set_object_label(dialog_->button_add, idex(_("Modify|#M")));
1070         fl_set_button_shortcut(dialog_->button_add, scex(_("Modify|#M")), 1);
1071
1072         setEnabled(dialog_->button_add,    false);
1073         setEnabled(dialog_->button_delete, true);
1074
1075         fl_unfreeze_form(dialog_->form);
1076         return false;
1077 }
1078
1079
1080 bool FormPreferences::Converters::erase()
1081 {
1082         string const from = GetFrom();
1083         string const to = GetTo();
1084
1085         local_converters.erase(from, to);
1086         UpdateBrowser();
1087         return true;
1088 }
1089
1090
1091 bool FormPreferences::Converters::Input()
1092 {
1093         string const from = GetFrom();
1094         string const to = GetTo();
1095         int const sel = local_converters.getNumber(from, to);
1096
1097         fl_freeze_form(dialog_->form);
1098
1099         if (sel < 0) {
1100                 fl_set_object_label(dialog_->button_add, idex(_("Add|#A")));
1101                 fl_set_button_shortcut(dialog_->button_add,
1102                                        scex(_("Add|#A")), 1);
1103
1104                 fl_deselect_browser(dialog_->browser_all);
1105                 setEnabled(dialog_->button_delete, false);
1106
1107         } else {
1108                 fl_set_object_label(dialog_->button_add, idex(_("Modify|#M")));
1109                 fl_set_button_shortcut(dialog_->button_add,
1110                                        scex(_("Modify|#M")), 1);
1111
1112                 int top = max(sel-5, 0);
1113                 fl_set_browser_topline(dialog_->browser_all, top);
1114                 fl_select_browser_line(dialog_->browser_all, sel+1);
1115                 setEnabled(dialog_->button_delete, true);
1116         }
1117
1118         string const command = rtrim(fl_get_input(dialog_->input_converter));
1119         bool const enable = !(command.empty() || from == to);
1120         setEnabled(dialog_->button_add, enable);
1121
1122         fl_unfreeze_form(dialog_->form);
1123         return false;
1124 }
1125
1126
1127 string const FormPreferences::Converters::GetFrom() const
1128 {
1129         ::Formats::FormatList::size_type const i =
1130                 fl_get_choice(dialog_->choice_from);
1131
1132         if (i > 0 && i <= local_formats.size())
1133                 return local_formats.get(i - 1).name();
1134
1135         lyxerr << "FormPreferences::Converters::GetFrom: No choice!" << endl;
1136         return "???";
1137 }
1138
1139
1140 string const FormPreferences::Converters::GetTo() const
1141 {
1142         ::Formats::FormatList::size_type const i =
1143                 fl_get_choice(dialog_->choice_to);
1144
1145         if (i > 0 && i <= local_formats.size())
1146                 return local_formats.get(i - 1).name();
1147
1148         lyxerr << "FormPreferences::Converters::GetTo: No choice!" << endl;
1149         return "???";
1150 }
1151
1152
1153 void FormPreferences::Converters::UpdateChoices() const
1154 {
1155         string choice;
1156         for (::Formats::const_iterator cit = local_formats.begin();
1157              cit != local_formats.end(); ++cit) {
1158                 if (!choice.empty())
1159                         choice += " | ";
1160                 else
1161                         choice += " ";
1162                 choice += cit->prettyname();
1163         }
1164         choice += " ";
1165
1166         fl_clear_choice(dialog_->choice_from);
1167         fl_addto_choice(dialog_->choice_from, choice.c_str());
1168
1169         fl_clear_choice(dialog_->choice_to);
1170         fl_addto_choice(dialog_->choice_to, choice.c_str());
1171 }
1172
1173
1174 FormPreferences::Formats::Formats(FormPreferences &  p)
1175         : parent_(p)
1176 {}
1177
1178
1179 FD_preferences_formats const * FormPreferences::Formats::dialog()
1180 {
1181         return dialog_.get();
1182 }
1183
1184
1185 void FormPreferences::Formats::apply() const
1186 {
1187         formats = local_formats;
1188 }
1189
1190
1191 void FormPreferences::Formats::build()
1192 {
1193         dialog_.reset(build_preferences_formats(&parent_));
1194
1195         fl_set_input_return(dialog_->input_format, FL_RETURN_CHANGED);
1196         fl_set_input_return(dialog_->input_viewer, FL_RETURN_CHANGED);
1197         fl_set_input_return(dialog_->input_shrtcut, FL_RETURN_CHANGED);
1198         fl_set_input_return(dialog_->input_gui_name, FL_RETURN_CHANGED);
1199         fl_set_input_return(dialog_->input_extension, FL_RETURN_CHANGED);
1200
1201         fl_set_input_filter(dialog_->input_format, fl_lowercase_filter);
1202
1203         // set up the feedback mechanism
1204         setPrehandler(dialog_->browser_all);
1205         setPrehandler(dialog_->input_format);
1206         setPrehandler(dialog_->input_gui_name);
1207         setPrehandler(dialog_->button_delete);
1208         setPrehandler(dialog_->button_add);
1209         setPrehandler(dialog_->input_extension);
1210         setPrehandler(dialog_->input_viewer);
1211         setPrehandler(dialog_->input_shrtcut);
1212 }
1213
1214
1215 string const
1216 FormPreferences::Formats::feedback(FL_OBJECT const * const ob) const
1217 {
1218         if (ob == dialog_->browser_all)
1219                 return  _("All the currently defined formats known to LyX.");
1220
1221         if (ob == dialog_->input_format)
1222                 return  _("The format identifier.");
1223
1224         if (ob == dialog_->input_gui_name)
1225                 return  _("The format name as it will appear in the menus.");
1226
1227         if (ob == dialog_->input_shrtcut)
1228                 return  _("The keyboard accelerator. Use a letter in the GUI name. "
1229                           "Case sensitive.");
1230
1231         if (ob == dialog_->input_extension)
1232                 return  _("Used to recognize the file. E.g., ps, pdf, tex.");
1233
1234         if (ob == dialog_->input_viewer)
1235                 return  _("The command used to launch the viewer application.");
1236
1237         if (ob == dialog_->button_delete)
1238                 return  _("Remove the current format from the list of available "
1239                           "formats. Note: you must then \"Apply\" the change.");
1240
1241         if (ob == dialog_->button_add) {
1242                 if (string(ob->label) == _("Add"))
1243                         return  _("Add the current format to the list of available "
1244                                   "formats. Note: you must then \"Apply\" the change.");
1245                 else
1246                         return  _("Modify the contents of the current format. Note: "
1247                                   "you must then \"Apply\" the change.");
1248         }
1249
1250         return string();
1251 }
1252
1253
1254 bool FormPreferences::Formats::input(FL_OBJECT const * const ob)
1255 {
1256         if (ob == dialog_->browser_all)
1257                 return Browser();
1258
1259         if (ob == dialog_->input_format
1260          || ob == dialog_->input_gui_name
1261          || ob == dialog_->input_shrtcut
1262          || ob == dialog_->input_extension
1263          || ob == dialog_->input_viewer)
1264                 return Input();
1265
1266         if (ob == dialog_->button_add)
1267                 return Add();
1268
1269         if (ob == dialog_->button_delete)
1270                 return erase();
1271
1272         return false;
1273 }
1274
1275
1276 void FormPreferences::Formats::update()
1277 {
1278         local_formats = formats;
1279         UpdateBrowser();
1280 }
1281
1282
1283 void FormPreferences::Formats::UpdateBrowser()
1284 {
1285         local_formats.sort();
1286
1287         fl_freeze_form(dialog_->form);
1288         fl_deselect_browser(dialog_->browser_all);
1289         fl_clear_browser(dialog_->browser_all);
1290         for (::Formats::const_iterator cit = local_formats.begin();
1291              cit != local_formats.end(); ++cit)
1292                 fl_addto_browser(dialog_->browser_all,
1293                                  cit->prettyname().c_str());
1294
1295         Input();
1296         fl_unfreeze_form(dialog_->form);
1297
1298         // Mustn't forget to update the Formats available to the converters_
1299         parent_.converters_.UpdateChoices();
1300         local_converters.update(local_formats);
1301 }
1302
1303
1304 bool FormPreferences::Formats::Add()
1305 {
1306         string const name = fl_get_input(dialog_->input_format);
1307         string const prettyname = fl_get_input(dialog_->input_gui_name);
1308         string const extension = fl_get_input(dialog_->input_extension);
1309         string const shortcut =  fl_get_input(dialog_->input_shrtcut);
1310         string const viewer =  fl_get_input(dialog_->input_viewer);
1311
1312         Format const * old = local_formats.getFormat(name);
1313         string const old_prettyname = old ? old->prettyname() : string();
1314         local_formats.add(name, extension, prettyname, shortcut);
1315         local_formats.setViewer(name, viewer);
1316         if (!old || prettyname != old_prettyname) {
1317                 UpdateBrowser();
1318                 if (old)
1319                         parent_.converters_.UpdateBrowser();
1320         }
1321         setEnabled(dialog_->button_add, false);
1322
1323         return true;
1324 }
1325
1326
1327 bool FormPreferences::Formats::Browser()
1328 {
1329         int const i = fl_get_browser(dialog_->browser_all);
1330         if (i <= 0)
1331                 return false;
1332
1333         fl_freeze_form(dialog_->form);
1334
1335         Format const & f = local_formats.get(i - 1);
1336
1337         fl_set_input(dialog_->input_format, f.name().c_str());
1338         fl_set_input(dialog_->input_gui_name, f.prettyname().c_str());
1339         fl_set_input(dialog_->input_shrtcut, f.shortcut().c_str());
1340         fl_set_input(dialog_->input_extension, f.extension().c_str());
1341         fl_set_input(dialog_->input_viewer, f.viewer().c_str());
1342
1343         fl_set_object_label(dialog_->button_add, idex(_("Modify|#M")));
1344         fl_set_button_shortcut(dialog_->button_add, scex(_("Modify|#M")), 1);
1345
1346         setEnabled(dialog_->button_add,    false);
1347         setEnabled(dialog_->button_delete, true);
1348
1349         fl_unfreeze_form(dialog_->form);
1350         return false;
1351 }
1352
1353
1354 bool FormPreferences::Formats::erase()
1355 {
1356         string const name = fl_get_input(dialog_->input_format);
1357
1358         if (local_converters.formatIsUsed(name)) {
1359                 parent_.postWarning(_("Cannot remove a Format used by a Converter. "
1360                                       "Remove the converter first."));
1361                 setEnabled(dialog_->button_delete, false);
1362                 return false;
1363         }
1364
1365         local_formats.erase(name);
1366         UpdateBrowser();
1367         return true;
1368 }
1369
1370
1371 bool FormPreferences::Formats::Input()
1372 {
1373         string const name = fl_get_input(dialog_->input_format);
1374         int const sel = local_formats.getNumber(name);
1375         fl_freeze_form(dialog_->form);
1376
1377         if (sel < 0) {
1378                 fl_set_object_label(dialog_->button_add,
1379                                     idex(_("Add|#A")));
1380                 fl_set_button_shortcut(dialog_->button_add,
1381                                        scex(_("Add|#A")), 1);
1382
1383                 fl_deselect_browser(dialog_->browser_all);
1384                 setEnabled(dialog_->button_delete, false);
1385
1386         } else {
1387                 fl_set_object_label(dialog_->button_add,
1388                                     idex(_("Modify|#M")));
1389                 fl_set_button_shortcut(dialog_->button_add,
1390                                        scex(_("Modify|#M")), 1);
1391
1392                 int const top = max(sel-5, 0);
1393                 fl_set_browser_topline(dialog_->browser_all, top);
1394                 fl_select_browser_line(dialog_->browser_all, sel+1);
1395
1396                 setEnabled(dialog_->button_add, true);
1397                 setEnabled(dialog_->button_delete, true);
1398         }
1399
1400         string const prettyname = fl_get_input(dialog_->input_gui_name);
1401         bool const enable = !(name.empty() || prettyname.empty());
1402         setEnabled(dialog_->button_add, enable);
1403
1404         fl_unfreeze_form(dialog_->form);
1405         return false;
1406 }
1407
1408
1409 FormPreferences::InputsMisc::InputsMisc(FormPreferences &  p)
1410         : parent_(p)
1411 {}
1412
1413
1414 FD_preferences_inputs_misc const * FormPreferences::InputsMisc::dialog()
1415 {
1416         return dialog_.get();
1417 }
1418
1419
1420 void FormPreferences::InputsMisc::apply() const
1421 {
1422         lyxrc.date_insert_format =
1423                 fl_get_input(dialog_->input_date_format);
1424 }
1425
1426
1427 void FormPreferences::InputsMisc::build()
1428 {
1429         dialog_.reset(build_preferences_inputs_misc(&parent_));
1430
1431         fl_set_input_return(dialog_->input_date_format, FL_RETURN_CHANGED);
1432
1433         // set up the feedback mechanism
1434         setPrehandler(dialog_->input_date_format);
1435 }
1436
1437
1438 string const
1439 FormPreferences::InputsMisc::feedback(FL_OBJECT const * const ob) const
1440 {
1441         if (ob == dialog_->input_date_format)
1442                 return lyxrc.getDescription(LyXRC::RC_DATE_INSERT_FORMAT);
1443         return string();
1444 }
1445
1446
1447 void FormPreferences::InputsMisc::update()
1448 {
1449         fl_set_input(dialog_->input_date_format,
1450                      lyxrc.date_insert_format.c_str());
1451 }
1452
1453
1454 FormPreferences::Interface::Interface(FormPreferences &  p)
1455         : parent_(p)
1456 {}
1457
1458
1459 FD_preferences_interface const * FormPreferences::Interface::dialog()
1460 {
1461         return dialog_.get();
1462 }
1463
1464
1465 void FormPreferences::Interface::apply() const
1466 {
1467         lyxrc.popup_normal_font =
1468                 fl_get_input(dialog_->input_popup_normal_font);
1469         lyxrc.popup_bold_font = fl_get_input(dialog_->input_popup_bold_font);
1470         lyxrc.popup_font_encoding =
1471                 fl_get_input(dialog_->input_popup_font_encoding);
1472         lyxrc.bind_file = fl_get_input(dialog_->input_bind_file);
1473         lyxrc.ui_file = fl_get_input(dialog_->input_ui_file);
1474         lyxrc.override_x_deadkeys =
1475                 fl_get_button(dialog_->check_override_x_dead_keys);
1476 }
1477
1478
1479 void FormPreferences::Interface::build()
1480 {
1481         dialog_.reset(build_preferences_interface(&parent_));
1482
1483         fl_set_input_return(dialog_->input_popup_normal_font, FL_RETURN_CHANGED);
1484         fl_set_input_return(dialog_->input_popup_bold_font, FL_RETURN_CHANGED);
1485         fl_set_input_return(dialog_->input_popup_font_encoding, FL_RETURN_CHANGED);
1486         fl_set_input_return(dialog_->input_bind_file, FL_RETURN_CHANGED);
1487         fl_set_input_return(dialog_->input_ui_file, FL_RETURN_CHANGED);
1488
1489         // set up the feedback mechanism
1490         setPrehandler(dialog_->input_popup_normal_font);
1491         setPrehandler(dialog_->input_popup_bold_font);
1492         setPrehandler(dialog_->input_popup_font_encoding);
1493         setPrehandler(dialog_->input_bind_file);
1494         setPrehandler(dialog_->button_bind_file_browse);
1495         setPrehandler(dialog_->input_ui_file);
1496         setPrehandler(dialog_->button_ui_file_browse);
1497         setPrehandler(dialog_->check_override_x_dead_keys);
1498 }
1499
1500
1501 string const
1502 FormPreferences::Interface::feedback(FL_OBJECT const * const ob) const
1503 {
1504         if (ob == dialog_->input_popup_normal_font)
1505                 return lyxrc.getDescription(LyXRC::RC_POPUP_NORMAL_FONT);
1506         if (ob == dialog_->input_popup_bold_font)
1507                 return lyxrc.getDescription(LyXRC::RC_POPUP_BOLD_FONT);
1508         if (ob == dialog_->input_popup_font_encoding)
1509                 return lyxrc.getDescription(LyXRC::RC_POPUP_FONT_ENCODING);
1510         if (ob == dialog_->input_bind_file)
1511                 return lyxrc.getDescription(LyXRC::RC_BINDFILE);
1512         if (ob == dialog_->input_ui_file)
1513                 return lyxrc.getDescription(LyXRC::RC_UIFILE);
1514         if (ob == dialog_->check_override_x_dead_keys)
1515                 return lyxrc.getDescription(LyXRC::RC_OVERRIDE_X_DEADKEYS);
1516         return string();
1517 }
1518
1519
1520 bool FormPreferences::Interface::input(FL_OBJECT const * const ob)
1521 {
1522         if (ob == dialog_->button_bind_file_browse) {
1523                 string dir  = AddName(system_lyxdir, "bind");
1524                 string name = _("Sys Bind|#S#s");
1525                 pair<string,string> dir1(name, dir);
1526
1527                 dir = AddName(user_lyxdir, "bind");
1528                 name = _("User Bind|#U#u");
1529                 pair<string,string> dir2(name, dir);
1530
1531                 parent_.browse(dialog_->input_bind_file,
1532                                _("Bind file"), "*.bind", dir1, dir2);
1533
1534         } else if (ob == dialog_->button_ui_file_browse) {
1535                 string dir  = AddName(system_lyxdir, "ui");
1536                 string name = _("Sys UI|#S#s");
1537                 pair<string,string> dir1(name, dir);
1538
1539                 dir = AddName(user_lyxdir, "ui");
1540                 name = _("User UI|#U#u");
1541                 pair<string,string> dir2(name, dir);
1542
1543                 parent_.browse(dialog_->input_ui_file,
1544                                _("UI file"), "*.ui", dir1, dir2);
1545         }
1546
1547         return true;
1548 }
1549
1550
1551 void FormPreferences::Interface::update()
1552 {
1553         fl_set_input(dialog_->input_popup_normal_font,
1554                      lyxrc.popup_normal_font.c_str());
1555         fl_set_input(dialog_->input_popup_bold_font,
1556                      lyxrc.popup_bold_font.c_str());
1557         fl_set_input(dialog_->input_popup_font_encoding,
1558                      lyxrc.popup_font_encoding.c_str());
1559         fl_set_input(dialog_->input_bind_file,
1560                      lyxrc.bind_file.c_str());
1561         fl_set_input(dialog_->input_ui_file,
1562                      lyxrc.ui_file.c_str());
1563         fl_set_button(dialog_->check_override_x_dead_keys,
1564                       lyxrc.override_x_deadkeys);
1565 }
1566
1567
1568 FormPreferences::Language::Language(FormPreferences &  p)
1569         : parent_(p)
1570 {}
1571
1572
1573 FD_preferences_language const * FormPreferences::Language::dialog()
1574 {
1575         return dialog_.get();
1576 }
1577
1578
1579 void FormPreferences::Language::apply()
1580 {
1581         int const pos = combo_default_lang->get();
1582         lyxrc.default_language = lang_[pos-1];
1583
1584         int button = fl_get_button(dialog_->check_use_kbmap);
1585         string const name_1 = fl_get_input(dialog_->input_kbmap1);
1586         string const name_2 = fl_get_input(dialog_->input_kbmap2);
1587         if (button)
1588                 button = !(name_1.empty() && name_2.empty());
1589         lyxrc.use_kbmap = static_cast<bool>(button);
1590
1591         if (lyxrc.use_kbmap) {
1592                 lyxrc.primary_kbmap = name_1;
1593                 lyxrc.secondary_kbmap = name_2;
1594         }
1595
1596         button = fl_get_button(dialog_->check_rtl_support);
1597         lyxrc.rtl_support = static_cast<bool>(button);
1598
1599         button = fl_get_button(dialog_->check_mark_foreign);
1600         lyxrc.mark_foreign_language = static_cast<bool>(button);
1601
1602         button = fl_get_button(dialog_->check_auto_begin);
1603         lyxrc.language_auto_begin = static_cast<bool>(button);
1604
1605         button = fl_get_button(dialog_->check_auto_end);
1606         lyxrc.language_auto_end = static_cast<bool>(button);
1607
1608         button = fl_get_button(dialog_->check_use_babel);
1609         lyxrc.language_use_babel = static_cast<bool>(button);
1610
1611         button = fl_get_button(dialog_->check_global_options);
1612         lyxrc.language_global_options = static_cast<bool>(button);
1613
1614         lyxrc.language_package = fl_get_input(dialog_->input_package);
1615         lyxrc.language_command_begin = fl_get_input(dialog_->input_command_begin);
1616         lyxrc.language_command_end = fl_get_input(dialog_->input_command_end);
1617
1618         // Ensure that all is self-consistent.
1619         update();
1620 }
1621
1622
1623 void FormPreferences::Language::build()
1624 {
1625         dialog_.reset(build_preferences_language(&parent_));
1626
1627         fl_set_input_return(dialog_->input_package, FL_RETURN_CHANGED);
1628         fl_set_input_return(dialog_->input_command_begin, FL_RETURN_CHANGED);
1629         fl_set_input_return(dialog_->input_command_end, FL_RETURN_CHANGED);
1630
1631         // Store the lang identifiers for later
1632         vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
1633         lang_ = getSecond(langs);
1634
1635         // The default_language is a combo-box and has to be inserted manually
1636         fl_freeze_form(dialog_->form);
1637         fl_addto_form(dialog_->form);
1638
1639         FL_OBJECT * obj = dialog_->choice_default_lang;
1640         fl_deactivate_object(dialog_->choice_default_lang);
1641         combo_default_lang.reset(new Combox(FL_COMBOX_DROPLIST));
1642         combo_default_lang->add(obj->x, obj->y, obj->w, obj->h, 400,
1643                                 parent_.lang_opts_tab_->tabfolder_inner,
1644                                 parent_.dialog_->tabfolder_prefs);
1645         combo_default_lang->shortcut("#L",1);
1646         combo_default_lang->setcallback(ComboCB, &parent_);
1647
1648         vector<frnt::LanguagePair>::const_iterator lit  = langs.begin();
1649         vector<frnt::LanguagePair>::const_iterator lend = langs.end();
1650         for (; lit != lend; ++lit) {
1651                 combo_default_lang->addto(lit->first);
1652         }
1653         combo_default_lang->select(1);
1654
1655         fl_end_form();
1656         fl_unfreeze_form(dialog_->form);
1657
1658         // set up the feedback mechanism
1659         setPrehandler(dialog_->input_package);
1660         setPrehandler(dialog_->check_use_kbmap);
1661
1662         // This is safe, as nothing is done to the pointer, other than
1663         // to use its address in a block-if statement.
1664         // No it's not! Leads to crash.
1665         // setPrehandler(
1666         //              reinterpret_cast<FL_OBJECT *>(combo_default_lang),
1667         //              C_FormPreferencesFeedbackCB);
1668
1669         setPrehandler(dialog_->input_kbmap1);
1670         setPrehandler(dialog_->input_kbmap2);
1671         setPrehandler(dialog_->check_rtl_support);
1672         setPrehandler(dialog_->check_mark_foreign);
1673         setPrehandler(dialog_->check_auto_begin);
1674         setPrehandler(dialog_->check_auto_end);
1675         setPrehandler(dialog_->check_use_babel);
1676         setPrehandler(dialog_->check_global_options);
1677         setPrehandler(dialog_->input_command_begin);
1678         setPrehandler(dialog_->input_command_end);
1679
1680         // Activate/Deactivate the input fields dependent on the state of the
1681         // buttons.
1682         input(0);
1683 }
1684
1685
1686 string const
1687 FormPreferences::Language::feedback(FL_OBJECT const * const ob) const
1688 {
1689         if (reinterpret_cast<Combox const *>(ob) == combo_default_lang.get())
1690                 return lyxrc.getDescription(LyXRC::RC_DEFAULT_LANGUAGE);
1691         if (ob == dialog_->check_use_kbmap)
1692                 return lyxrc.getDescription(LyXRC::RC_KBMAP);
1693         if (ob == dialog_->input_kbmap1)
1694                 return lyxrc.getDescription(LyXRC::RC_KBMAP_PRIMARY);
1695         if (ob == dialog_->input_kbmap2)
1696                 return lyxrc.getDescription(LyXRC::RC_KBMAP_SECONDARY);
1697         if (ob == dialog_->check_rtl_support)
1698                 return lyxrc.getDescription(LyXRC::RC_RTL_SUPPORT);
1699         if (ob == dialog_->check_mark_foreign)
1700                 return lyxrc.getDescription(LyXRC::RC_MARK_FOREIGN_LANGUAGE);
1701         if (ob == dialog_->check_auto_begin)
1702                 return lyxrc.getDescription(LyXRC::RC_LANGUAGE_AUTO_BEGIN);
1703         if (ob == dialog_->check_auto_end)
1704                 return lyxrc.getDescription(LyXRC::RC_LANGUAGE_AUTO_END);
1705         if (ob == dialog_->check_use_babel)
1706                 return lyxrc.getDescription(LyXRC::RC_LANGUAGE_USE_BABEL);
1707         if (ob == dialog_->check_global_options)
1708                 return lyxrc.getDescription(LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS);
1709         if (ob == dialog_->input_package)
1710                 return lyxrc.getDescription(LyXRC::RC_LANGUAGE_PACKAGE);
1711         if (ob == dialog_->input_command_begin)
1712                 return lyxrc.getDescription(LyXRC::RC_LANGUAGE_COMMAND_BEGIN);
1713         if (ob == dialog_->input_command_end)
1714                 return lyxrc.getDescription(LyXRC::RC_LANGUAGE_COMMAND_END);
1715         return string();
1716 }
1717
1718
1719 bool FormPreferences::Language::input(FL_OBJECT const * const ob)
1720 {
1721         bool activate = true;
1722
1723         // !ob if function is called from Language::build() to de/activate
1724         // objects,
1725         // otherwise the function is called by an xforms CB via input().
1726         if (!ob || ob == dialog_->check_use_kbmap) {
1727                 bool const enable = fl_get_button(dialog_->check_use_kbmap);
1728                 setEnabled(dialog_->button_kbmap1_browse, enable);
1729                 setEnabled(dialog_->button_kbmap2_browse, enable);
1730                 setEnabled(dialog_->input_kbmap1, enable);
1731                 setEnabled(dialog_->input_kbmap2, enable);
1732         }
1733
1734         if (ob == dialog_->button_kbmap1_browse) {
1735                 string const dir  = AddName(system_lyxdir, "kbd");
1736                 string const name = _("Key maps|#K#k");
1737                 pair<string, string> dir1(name, dir);
1738
1739                 parent_.browse(dialog_->input_kbmap1,
1740                                _("Keyboard map"), "*.kmap", dir1);
1741         } else if (ob == dialog_->button_kbmap2_browse) {
1742                 string const dir  = AddName(system_lyxdir, "kbd");
1743                 string const name = _("Key maps|#K#k");
1744                 pair<string, string> dir1(name, dir);
1745
1746                 parent_.browse(dialog_->input_kbmap2,
1747                                _("Keyboard map"), "*.kmap", dir1);
1748         }
1749
1750         return activate;
1751 }
1752
1753
1754 void FormPreferences::Language::update()
1755 {
1756         fl_set_button(dialog_->check_use_kbmap,
1757                       lyxrc.use_kbmap);
1758
1759         int const pos = int(findPos(lang_, lyxrc.default_language));
1760         combo_default_lang->select(pos + 1);
1761
1762         if (lyxrc.use_kbmap) {
1763                 fl_set_input(dialog_->input_kbmap1,
1764                              lyxrc.primary_kbmap.c_str());
1765                 fl_set_input(dialog_->input_kbmap2,
1766                              lyxrc.secondary_kbmap.c_str());
1767         } else {
1768                 fl_set_input(dialog_->input_kbmap1, "");
1769                 fl_set_input(dialog_->input_kbmap2, "");
1770         }
1771
1772         fl_set_button(dialog_->check_rtl_support, lyxrc.rtl_support);
1773         fl_set_button(dialog_->check_mark_foreign,
1774                       lyxrc.mark_foreign_language);
1775         fl_set_button(dialog_->check_auto_begin, lyxrc.language_auto_begin);
1776         fl_set_button(dialog_->check_auto_end, lyxrc.language_auto_end);
1777         fl_set_button(dialog_->check_use_babel, lyxrc.language_use_babel);
1778         fl_set_button(dialog_->check_global_options,
1779                       lyxrc.language_global_options);
1780
1781         fl_set_input(dialog_->input_package,
1782                      lyxrc.language_package.c_str());
1783         fl_set_input(dialog_->input_command_begin,
1784                      lyxrc.language_command_begin.c_str());
1785         fl_set_input(dialog_->input_command_end,
1786                      lyxrc.language_command_end.c_str());
1787
1788         // Activate/Deactivate the input fields dependent on the state of the
1789         // buttons.
1790         input(0);
1791 }
1792
1793
1794 void FormPreferences::Language::ComboCB(int, void * v, Combox * combox)
1795 {
1796         FormPreferences * pre = static_cast<FormPreferences*>(v);
1797         // This is safe, as nothing is done to the pointer, other than
1798         // to use its address in a block-if statement.
1799         pre->bc().valid(pre->input(reinterpret_cast<FL_OBJECT *>(combox), 0));
1800 }
1801
1802
1803 FormPreferences::LnFmisc::LnFmisc(FormPreferences &  p)
1804         : parent_(p)
1805 {}
1806
1807
1808 FD_preferences_lnf_misc const * FormPreferences::LnFmisc::dialog()
1809 {
1810         return dialog_.get();
1811 }
1812
1813
1814 void FormPreferences::LnFmisc::apply() const
1815 {
1816         lyxrc.auto_region_delete =
1817                 fl_get_button(dialog_->check_auto_region_delete);
1818         lyxrc.cursor_follows_scrollbar =
1819                 fl_get_button(dialog_->check_cursor_follows_scrollbar);
1820         lyxrc.dialogs_iconify_with_main =
1821                 fl_get_button(dialog_->check_dialogs_iconify_with_main);
1822         lyxrc.preview = fl_get_button(dialog_->check_preview_latex);
1823         lyxrc.autosave = static_cast<unsigned int>
1824                 (fl_get_counter_value(dialog_->counter_autosave));
1825         lyxrc.wheel_jump = static_cast<unsigned int>
1826                 (fl_get_counter_value(dialog_->counter_wm_jump));
1827
1828         string const old_value = lyxrc.display_graphics;
1829         if (fl_get_button(dialog_->radio_display_monochrome)) {
1830                 lyxrc.display_graphics = "mono";
1831         } else if (fl_get_button(dialog_->radio_display_grayscale)) {
1832                 lyxrc.display_graphics = "gray";
1833         } else if (fl_get_button(dialog_->radio_display_color)) {
1834                 lyxrc.display_graphics = "color";
1835         } else {
1836                 lyxrc.display_graphics = "no";
1837         }
1838
1839 #ifdef WITH_WARNINGS
1840 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
1841 #endif
1842 #if 0
1843         if (old_value != lyxrc.display_graphics) {
1844                 grfx::GCache & gc = grfx::GCache::get();
1845                 gc.changeDisplay();
1846         }
1847 #endif
1848 }
1849
1850
1851 void FormPreferences::LnFmisc::build()
1852 {
1853         dialog_.reset(build_preferences_lnf_misc(&parent_));
1854
1855         fl_set_counter_step(dialog_->counter_autosave, 1, 10);
1856         fl_set_counter_step(dialog_->counter_wm_jump, 1, 10);
1857
1858         fl_set_counter_return(dialog_->counter_autosave, FL_RETURN_CHANGED);
1859         fl_set_counter_return(dialog_->counter_wm_jump, FL_RETURN_CHANGED);
1860
1861         // set up the feedback mechanism
1862         setPrehandler(dialog_->check_auto_region_delete);
1863         setPrehandler(dialog_->counter_autosave);
1864         setPrehandler(dialog_->check_cursor_follows_scrollbar);
1865         setPrehandler(dialog_->check_dialogs_iconify_with_main);
1866         setPrehandler(dialog_->check_preview_latex);
1867         setPrehandler(dialog_->counter_wm_jump);
1868         setPrehandler(dialog_->radio_display_monochrome);
1869         setPrehandler(dialog_->radio_display_grayscale);
1870         setPrehandler(dialog_->radio_display_color);
1871         setPrehandler(dialog_->radio_no_display);
1872 }
1873
1874
1875 string const
1876 FormPreferences::LnFmisc::feedback(FL_OBJECT const * const ob) const
1877 {
1878         if (ob == dialog_->check_auto_region_delete)
1879                 return lyxrc.getDescription(LyXRC::RC_AUTOREGIONDELETE);
1880         if (ob == dialog_->check_cursor_follows_scrollbar)
1881                 return lyxrc.getDescription(LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR);
1882         if (ob == dialog_->check_dialogs_iconify_with_main)
1883                 return lyxrc.getDescription(LyXRC::RC_DIALOGS_ICONIFY_WITH_MAIN);
1884         if (ob == dialog_->check_preview_latex)
1885                 return lyxrc.getDescription(LyXRC::RC_PREVIEW);
1886         if (ob == dialog_->counter_autosave)
1887                 return lyxrc.getDescription(LyXRC::RC_AUTOSAVE);
1888         if (ob == dialog_->counter_wm_jump)
1889                 return lyxrc.getDescription(LyXRC::RC_WHEEL_JUMP);
1890         if (ob == dialog_->radio_display_monochrome ||
1891                  ob == dialog_->radio_display_grayscale ||
1892                  ob == dialog_->radio_display_color ||
1893                  ob == dialog_->radio_no_display)
1894                 return lyxrc.getDescription(LyXRC::RC_DISPLAY_GRAPHICS);
1895         return string();
1896 }
1897
1898
1899 void FormPreferences::LnFmisc::update()
1900 {
1901         fl_set_button(dialog_->check_auto_region_delete,
1902                       lyxrc.auto_region_delete);
1903         fl_set_button(dialog_->check_cursor_follows_scrollbar,
1904                       lyxrc.cursor_follows_scrollbar);
1905         fl_set_button(dialog_->check_dialogs_iconify_with_main,
1906                       lyxrc.dialogs_iconify_with_main);
1907         fl_set_button(dialog_->check_preview_latex,
1908                       lyxrc.preview);
1909         fl_set_counter_value(dialog_->counter_autosave, lyxrc.autosave);
1910         fl_set_counter_value(dialog_->counter_wm_jump, lyxrc.wheel_jump);
1911
1912         if (lyxrc.display_graphics == "mono") {
1913                 fl_set_button(dialog_->radio_display_monochrome, 1);
1914         } else if (lyxrc.display_graphics == "gray") {
1915                 fl_set_button(dialog_->radio_display_grayscale, 1);
1916         } else if (lyxrc.display_graphics == "color") {
1917                 fl_set_button(dialog_->radio_display_color, 1);
1918         } else {
1919                 fl_set_button(dialog_->radio_no_display, 1);
1920         }
1921 }
1922
1923
1924 FormPreferences::OutputsMisc::OutputsMisc(FormPreferences &  p)
1925         : parent_(p)
1926 {}
1927
1928
1929 FD_preferences_outputs_misc const * FormPreferences::OutputsMisc::dialog()
1930 {
1931         return dialog_.get();
1932 }
1933
1934
1935 void FormPreferences::OutputsMisc::apply() const
1936 {
1937         lyxrc.ascii_linelen = static_cast<unsigned int>
1938                 (fl_get_counter_value(dialog_->counter_line_len));
1939         lyxrc.fontenc = fl_get_input(dialog_->input_tex_encoding);
1940
1941         int const choice =
1942                 fl_get_choice(dialog_->choice_default_papersize) - 1;
1943         lyxrc.default_papersize = static_cast<BufferParams::PAPER_SIZE>(choice);
1944
1945         lyxrc.ascii_roff_command = fl_get_input(dialog_->input_ascii_roff);
1946         lyxrc.chktex_command = fl_get_input(dialog_->input_checktex);
1947         lyxrc.view_dvi_paper_option = fl_get_input(dialog_->input_paperoption);
1948         lyxrc.auto_reset_options = fl_get_button(dialog_->check_autoreset_classopt);
1949 }
1950
1951
1952 void FormPreferences::OutputsMisc::build()
1953 {
1954         dialog_.reset(build_preferences_outputs_misc(&parent_));
1955
1956         fl_set_counter_step(dialog_->counter_line_len, 1, 10);
1957
1958         fl_set_counter_return(dialog_->counter_line_len, FL_RETURN_CHANGED);
1959         fl_set_input_return(dialog_->input_tex_encoding, FL_RETURN_CHANGED);
1960         fl_set_input_return(dialog_->input_ascii_roff,   FL_RETURN_CHANGED);
1961         fl_set_input_return(dialog_->input_checktex,     FL_RETURN_CHANGED);
1962         fl_set_input_return(dialog_->input_paperoption,  FL_RETURN_CHANGED);
1963
1964         fl_addto_choice(dialog_->choice_default_papersize,
1965                         _(" default | US letter | US legal | US executive | A3 | A4 | A5 | B5 "));
1966
1967         // set up the feedback mechanism
1968         setPrehandler(dialog_->counter_line_len);
1969         setPrehandler(dialog_->input_tex_encoding);
1970         setPrehandler(dialog_->choice_default_papersize);
1971         setPrehandler(dialog_->input_ascii_roff);
1972         setPrehandler(dialog_->input_checktex);
1973         setPrehandler(dialog_->input_paperoption);
1974         setPrehandler(dialog_->check_autoreset_classopt);
1975 }
1976
1977
1978 string const
1979 FormPreferences::OutputsMisc::feedback(FL_OBJECT const * const ob) const
1980 {
1981         if (ob == dialog_->counter_line_len)
1982                 return lyxrc.getDescription(LyXRC::RC_ASCII_LINELEN);
1983         if (ob == dialog_->input_tex_encoding)
1984                 return lyxrc.getDescription(LyXRC::RC_FONT_ENCODING);
1985         if (ob == dialog_->input_ascii_roff)
1986                 return lyxrc.getDescription(LyXRC::RC_ASCIIROFF_COMMAND);
1987         if (ob == dialog_->input_checktex)
1988                 return lyxrc.getDescription(LyXRC::RC_CHKTEX_COMMAND);
1989         if (ob == dialog_->choice_default_papersize)
1990                 return lyxrc.getDescription(LyXRC::RC_DEFAULT_PAPERSIZE);
1991         if (ob == dialog_->input_paperoption)
1992                 return lyxrc.getDescription(LyXRC::RC_VIEWDVI_PAPEROPTION);
1993         if (ob == dialog_->check_autoreset_classopt)
1994                 return lyxrc.getDescription(LyXRC::RC_AUTORESET_OPTIONS);
1995         return string();
1996 }
1997
1998
1999 void FormPreferences::OutputsMisc::update()
2000 {
2001         fl_set_counter_value(dialog_->counter_line_len,
2002                              lyxrc.ascii_linelen);
2003         fl_set_input(dialog_->input_tex_encoding,
2004                      lyxrc.fontenc.c_str());
2005         fl_set_choice(dialog_->choice_default_papersize,
2006                       lyxrc.default_papersize+1);
2007         fl_set_input(dialog_->input_ascii_roff,
2008                      lyxrc.ascii_roff_command.c_str());
2009         fl_set_input(dialog_->input_checktex,
2010                      lyxrc.chktex_command.c_str());
2011         fl_set_input(dialog_->input_paperoption,
2012                      lyxrc.view_dvi_paper_option.c_str());
2013         fl_set_button(dialog_->check_autoreset_classopt,
2014                       lyxrc.auto_reset_options);
2015
2016 }
2017
2018
2019 FormPreferences::Paths::Paths(FormPreferences &  p)
2020         : parent_(p)
2021 {}
2022
2023
2024 FD_preferences_paths const * FormPreferences::Paths::dialog()
2025 {
2026         return dialog_.get();
2027 }
2028
2029
2030 void FormPreferences::Paths::apply()
2031 {
2032         lyxrc.document_path = fl_get_input(dialog_->input_default_path);
2033         lyxrc.template_path = fl_get_input(dialog_->input_template_path);
2034
2035         int button = fl_get_button(dialog_->check_use_temp_dir);
2036         string str  = fl_get_input(dialog_->input_temp_dir);
2037         if (!button)
2038                 str.erase();
2039
2040         lyxrc.use_tempdir = button;
2041         lyxrc.tempdir_path = str;
2042
2043         button = fl_get_button(dialog_->check_last_files);
2044         str = fl_get_input(dialog_->input_lastfiles);
2045         if (!button) str.erase();
2046
2047         lyxrc.check_lastfiles = button;
2048         lyxrc.lastfiles = str;
2049         lyxrc.num_lastfiles = static_cast<unsigned int>
2050                 (fl_get_counter_value(dialog_->counter_lastfiles));
2051
2052         button = fl_get_button(dialog_->check_make_backups);
2053         str = fl_get_input(dialog_->input_backup_path);
2054         if (!button)
2055                 str.erase();
2056
2057         lyxrc.make_backup = button;
2058         lyxrc.backupdir_path = str;
2059
2060         lyxrc.lyxpipes = fl_get_input(dialog_->input_serverpipe);
2061
2062         // update view
2063         update();
2064 }
2065
2066
2067 void FormPreferences::Paths::build()
2068 {
2069         dialog_.reset(build_preferences_paths(&parent_));
2070
2071         fl_set_input_return(dialog_->input_default_path, FL_RETURN_CHANGED);
2072         fl_set_input_return(dialog_->input_template_path, FL_RETURN_CHANGED);
2073         fl_set_input_return(dialog_->input_temp_dir, FL_RETURN_CHANGED);
2074         fl_set_input_return(dialog_->input_lastfiles, FL_RETURN_CHANGED);
2075         fl_set_input_return(dialog_->input_backup_path, FL_RETURN_CHANGED);
2076         fl_set_counter_return(dialog_->counter_lastfiles, FL_RETURN_CHANGED);
2077         fl_set_input_return(dialog_->input_serverpipe, FL_RETURN_CHANGED);
2078
2079         // set up the feedback mechanism
2080         setPrehandler(dialog_->input_default_path);
2081         setPrehandler(dialog_->counter_lastfiles);
2082         setPrehandler(dialog_->input_template_path);
2083         setPrehandler(dialog_->check_last_files);
2084         setPrehandler(dialog_->input_lastfiles);
2085         setPrehandler(dialog_->check_make_backups);
2086         setPrehandler(dialog_->input_backup_path);
2087         setPrehandler(dialog_->input_serverpipe);
2088         setPrehandler(dialog_->input_temp_dir);
2089         setPrehandler(dialog_->check_use_temp_dir);
2090 }
2091
2092
2093 string const
2094 FormPreferences::Paths::feedback(FL_OBJECT const * const ob) const
2095 {
2096         if (ob == dialog_->input_default_path)
2097                 return lyxrc.getDescription(LyXRC::RC_DOCUMENTPATH);
2098         if (ob == dialog_->input_template_path)
2099                 return lyxrc.getDescription(LyXRC::RC_TEMPLATEPATH);
2100         if (ob == dialog_->check_use_temp_dir)
2101                 return lyxrc.getDescription(LyXRC::RC_USETEMPDIR);
2102         if (ob == dialog_->input_temp_dir)
2103                 return lyxrc.getDescription(LyXRC::RC_TEMPDIRPATH);
2104         if (ob == dialog_->check_last_files)
2105                 return lyxrc.getDescription(LyXRC::RC_CHECKLASTFILES);
2106         if (ob == dialog_->input_lastfiles)
2107                 return lyxrc.getDescription(LyXRC::RC_LASTFILES);
2108         if (ob == dialog_->counter_lastfiles)
2109                 return lyxrc.getDescription(LyXRC::RC_NUMLASTFILES);
2110         if (ob == dialog_->check_make_backups)
2111                 return lyxrc.getDescription(LyXRC::RC_MAKE_BACKUP);
2112         if (ob == dialog_->input_backup_path)
2113                 return lyxrc.getDescription(LyXRC::RC_BACKUPDIR_PATH);
2114         if (ob == dialog_->input_serverpipe)
2115                 return lyxrc.getDescription(LyXRC::RC_SERVERPIPE);
2116         return string();
2117 }
2118
2119
2120 bool FormPreferences::Paths::input(FL_OBJECT const * const ob)
2121 {
2122         bool activate = true;
2123
2124         // !ob if function is called from Paths::update() to de/activate
2125         // objects,
2126         // otherwise the function is called by an xforms CB via input().
2127         if (!ob || ob == dialog_->check_use_temp_dir) {
2128                 bool const enable = fl_get_button(dialog_->check_use_temp_dir);
2129                 setEnabled(dialog_->input_temp_dir, enable);
2130         }
2131
2132         if (!ob || ob == dialog_->check_last_files) {
2133                 bool const enable = fl_get_button(dialog_->check_last_files);
2134                 setEnabled(dialog_->input_lastfiles, enable);
2135         }
2136
2137         if (!ob || ob == dialog_->check_make_backups) {
2138                 bool const enable = fl_get_button(dialog_->check_make_backups);
2139                 setEnabled(dialog_->input_backup_path, enable);
2140         }
2141
2142         if (!ob || ob == dialog_->input_default_path) {
2143                 string const name = fl_get_input(dialog_->input_default_path);
2144                 if (!name.empty() && !RWInfo::WriteableDir(name)) {
2145                         parent_.postWarning(RWInfo::ErrorMessage());
2146                         return false;
2147                 }
2148         }
2149
2150         if (!ob || ob == dialog_->input_template_path) {
2151                 string const name = fl_get_input(dialog_->input_template_path);
2152                 if (!name.empty() && !RWInfo::ReadableDir(name)) {
2153                         parent_.postWarning(RWInfo::ErrorMessage());
2154                         return false;
2155                 }
2156         }
2157
2158         if (!ob || ob == dialog_->input_temp_dir) {
2159                 string const name = fl_get_input(dialog_->input_temp_dir);
2160                 if (fl_get_button(dialog_->check_make_backups)
2161                     && !name.empty()
2162                     && !RWInfo::WriteableDir(name)) {
2163                         parent_.postWarning(RWInfo::ErrorMessage());
2164                         return false;
2165                 }
2166         }
2167
2168         if (!ob || ob == dialog_->input_backup_path) {
2169                 string const name = fl_get_input(dialog_->input_backup_path);
2170                 if (fl_get_button(dialog_->check_make_backups)
2171                     && !name.empty()
2172                     && !RWInfo::WriteableDir(name)) {
2173                         parent_.postWarning(RWInfo::ErrorMessage());
2174                         return false;
2175                 }
2176         }
2177
2178         if (!ob || ob == dialog_->input_lastfiles) {
2179                 string const name = fl_get_input(dialog_->input_lastfiles);
2180                 if (fl_get_button(dialog_->check_last_files)
2181                     && !name.empty()
2182                     && !RWInfo::WriteableFile(name)) {
2183                         parent_.postWarning(RWInfo::ErrorMessage());
2184                         return false;
2185                 }
2186         }
2187
2188         if (!ob || ob == dialog_->input_serverpipe) {
2189                 string const name = fl_get_input(dialog_->input_serverpipe);
2190                 if (!name.empty()) {
2191                         // strip off the extension
2192                         string const str = ChangeExtension(name, "");
2193                         if (!RWInfo::WriteableFile(str + ".in")) {
2194                                 parent_.postWarning(RWInfo::ErrorMessage());
2195                                 return false;
2196                         }
2197                         if (!RWInfo::WriteableFile(str + ".out")) {
2198                                 parent_.postWarning(RWInfo::ErrorMessage());
2199                                 return false;
2200                         }
2201                 }
2202         }
2203
2204         if (ob == dialog_->button_default_path_browse) {
2205                 parent_.browse(dialog_->input_default_path,
2206                                _("Default path"), string());
2207         } else if (ob == dialog_->button_template_path_browse) {
2208                 parent_.browse(dialog_->input_template_path,
2209                                _("Template path"), string());
2210         } else if (ob == dialog_->button_temp_dir_browse) {
2211                 parent_.browse(dialog_->input_temp_dir,
2212                                _("Temp dir"), string());
2213         } else if (ob == dialog_->button_lastfiles_browse) {
2214                 pair<string, string> dir(_("User|#U#u"), user_lyxdir);
2215
2216                 parent_.browse(dialog_->input_lastfiles,
2217                                _("Lastfiles"), string(), dir);
2218         } else if (ob == dialog_->button_backup_path_browse) {
2219                 parent_.browse(dialog_->input_backup_path,
2220                                _("Backup path"), string());
2221         } else if (ob == dialog_->button_serverpipe_browse) {
2222                 parent_.browse(dialog_->input_serverpipe,
2223                                _("LyX Server pipes"), string());
2224         }
2225
2226         return activate;
2227 }
2228
2229
2230 void FormPreferences::Paths::update()
2231 {
2232         fl_set_input(dialog_->input_default_path,
2233                      lyxrc.document_path.c_str());
2234         fl_set_input(dialog_->input_template_path,
2235                      lyxrc.template_path.c_str());
2236
2237         string str;
2238         if (lyxrc.make_backup)
2239                 str = lyxrc.backupdir_path;
2240
2241         fl_set_button(dialog_->check_make_backups,
2242                       lyxrc.make_backup);
2243         fl_set_input(dialog_->input_backup_path, str.c_str());
2244
2245         str.erase();
2246         if (lyxrc.use_tempdir)
2247                 str = lyxrc.tempdir_path;
2248
2249         fl_set_button(dialog_->check_use_temp_dir,
2250                       lyxrc.use_tempdir);
2251         fl_set_input(dialog_->input_temp_dir, str.c_str());
2252
2253         str.erase();
2254         if (lyxrc.check_lastfiles)
2255                 str = lyxrc.lastfiles;
2256
2257         fl_set_button(dialog_->check_last_files,
2258                       lyxrc.check_lastfiles);
2259         fl_set_input(dialog_->input_lastfiles, str.c_str());
2260         fl_set_counter_value(dialog_->counter_lastfiles,
2261                              lyxrc.num_lastfiles);
2262
2263         fl_set_input(dialog_->input_serverpipe, lyxrc.lyxpipes.c_str());
2264
2265         // Activate/Deactivate the input fields dependent on the state of the
2266         // buttons.
2267         input(0);
2268 }
2269
2270
2271 FormPreferences::Printer::Printer(FormPreferences &  p)
2272         : parent_(p)
2273 {}
2274
2275
2276 FD_preferences_printer const * FormPreferences::Printer::dialog()
2277 {
2278         return dialog_.get();
2279 }
2280
2281
2282 void FormPreferences::Printer::apply() const
2283 {
2284         lyxrc.print_adapt_output = fl_get_button(dialog_->check_adapt_output);
2285         lyxrc.print_command = fl_get_input(dialog_->input_command);
2286         lyxrc.print_pagerange_flag = fl_get_input(dialog_->input_page_range);
2287         lyxrc.print_copies_flag = fl_get_input(dialog_->input_copies);
2288         lyxrc.print_reverse_flag = fl_get_input(dialog_->input_reverse);
2289         lyxrc.print_to_printer = fl_get_input(dialog_->input_to_printer);
2290         lyxrc.print_file_extension =
2291                 fl_get_input(dialog_->input_file_extension);
2292         lyxrc.print_spool_command =
2293                 fl_get_input(dialog_->input_spool_command);
2294         lyxrc.print_paper_flag = fl_get_input(dialog_->input_paper_type);
2295         lyxrc.print_evenpage_flag = fl_get_input(dialog_->input_even_pages);
2296         lyxrc.print_oddpage_flag = fl_get_input(dialog_->input_odd_pages);
2297         lyxrc.print_collcopies_flag = fl_get_input(dialog_->input_collated);
2298         lyxrc.print_landscape_flag = fl_get_input(dialog_->input_landscape);
2299         lyxrc.print_to_file = fl_get_input(dialog_->input_to_file);
2300         lyxrc.print_extra_options =
2301                 fl_get_input(dialog_->input_extra_options);
2302         lyxrc.print_spool_printerprefix =
2303                 fl_get_input(dialog_->input_spool_prefix);
2304         lyxrc.print_paper_dimension_flag =
2305                 fl_get_input(dialog_->input_paper_size);
2306         lyxrc.printer = fl_get_input(dialog_->input_name);
2307 }
2308
2309
2310 string const
2311 FormPreferences::Printer::feedback(FL_OBJECT const * const ob) const
2312 {
2313         if (ob == dialog_->input_command)
2314                 return lyxrc.getDescription(LyXRC::RC_PRINT_COMMAND);
2315         if (ob == dialog_->check_adapt_output)
2316                 return lyxrc.getDescription(LyXRC::RC_PRINT_ADAPTOUTPUT);
2317         if (ob == dialog_->input_to_printer)
2318                 return lyxrc.getDescription(LyXRC::RC_PRINTTOPRINTER);
2319         if (ob == dialog_->input_to_file)
2320                 return lyxrc.getDescription(LyXRC::RC_PRINTTOFILE);
2321         if (ob == dialog_->input_file_extension)
2322                 return lyxrc.getDescription(LyXRC::RC_PRINTFILEEXTENSION);
2323         if (ob == dialog_->input_extra_options)
2324                 return lyxrc.getDescription(LyXRC::RC_PRINTEXSTRAOPTIONS);
2325         if (ob == dialog_->input_spool_command)
2326                 return lyxrc.getDescription(LyXRC::RC_PRINTSPOOL_COMMAND);
2327         if (ob == dialog_->input_spool_prefix)
2328                 return lyxrc.getDescription(LyXRC::RC_PRINTSPOOL_PRINTERPREFIX);
2329         if (ob == dialog_->input_name)
2330                 return lyxrc.getDescription(LyXRC::RC_PRINTER);
2331         if (ob == dialog_->input_even_pages)
2332                 return lyxrc.getDescription(LyXRC::RC_PRINTEVENPAGEFLAG);
2333         if (ob == dialog_->input_odd_pages)
2334                 return lyxrc.getDescription(LyXRC::RC_PRINTODDPAGEFLAG);
2335         if (ob == dialog_->input_page_range)
2336                 return lyxrc.getDescription(LyXRC::RC_PRINTPAGERANGEFLAG);
2337         if (ob == dialog_->input_reverse)
2338                 return lyxrc.getDescription(LyXRC::RC_PRINTREVERSEFLAG);
2339         if (ob == dialog_->input_landscape)
2340                 return lyxrc.getDescription(LyXRC::RC_PRINTLANDSCAPEFLAG);
2341         if (ob == dialog_->input_copies)
2342                 return lyxrc.getDescription(LyXRC::RC_PRINTCOPIESFLAG);
2343         if (ob == dialog_->input_collated)
2344                 return lyxrc.getDescription(LyXRC::RC_PRINTCOLLCOPIESFLAG);
2345         if (ob == dialog_->input_paper_type)
2346                 return lyxrc.getDescription(LyXRC::RC_PRINTPAPERFLAG);
2347         if (ob == dialog_->input_paper_size)
2348                 return lyxrc.getDescription(LyXRC::RC_PRINTPAPERDIMENSIONFLAG);
2349         return string();
2350 }
2351
2352
2353 void FormPreferences::Printer::build()
2354 {
2355         dialog_.reset(build_preferences_printer(&parent_));
2356
2357         fl_set_input_return(dialog_->input_command, FL_RETURN_CHANGED);
2358         fl_set_input_return(dialog_->input_page_range, FL_RETURN_CHANGED);
2359         fl_set_input_return(dialog_->input_copies, FL_RETURN_CHANGED);
2360         fl_set_input_return(dialog_->input_reverse, FL_RETURN_CHANGED);
2361         fl_set_input_return(dialog_->input_to_printer, FL_RETURN_CHANGED);
2362         fl_set_input_return(dialog_->input_file_extension, FL_RETURN_CHANGED);
2363         fl_set_input_return(dialog_->input_spool_command, FL_RETURN_CHANGED);
2364         fl_set_input_return(dialog_->input_paper_type, FL_RETURN_CHANGED);
2365         fl_set_input_return(dialog_->input_even_pages, FL_RETURN_CHANGED);
2366         fl_set_input_return(dialog_->input_odd_pages, FL_RETURN_CHANGED);
2367         fl_set_input_return(dialog_->input_collated, FL_RETURN_CHANGED);
2368         fl_set_input_return(dialog_->input_landscape, FL_RETURN_CHANGED);
2369         fl_set_input_return(dialog_->input_to_file, FL_RETURN_CHANGED);
2370         fl_set_input_return(dialog_->input_extra_options, FL_RETURN_CHANGED);
2371         fl_set_input_return(dialog_->input_spool_prefix, FL_RETURN_CHANGED);
2372         fl_set_input_return(dialog_->input_paper_size, FL_RETURN_CHANGED);
2373         fl_set_input_return(dialog_->input_name, FL_RETURN_CHANGED);
2374
2375         // set up the feedback mechanism
2376         setPrehandler(dialog_->input_command);
2377         setPrehandler(dialog_->input_page_range);
2378         setPrehandler(dialog_->input_copies);
2379         setPrehandler(dialog_->input_reverse);
2380         setPrehandler(dialog_->input_to_printer);
2381         setPrehandler(dialog_->input_file_extension);
2382         setPrehandler(dialog_->input_spool_command);
2383         setPrehandler(dialog_->input_paper_type);
2384         setPrehandler(dialog_->input_even_pages);
2385         setPrehandler(dialog_->input_odd_pages);
2386         setPrehandler(dialog_->input_collated);
2387         setPrehandler(dialog_->input_landscape);
2388         setPrehandler(dialog_->input_to_file);
2389         setPrehandler(dialog_->input_extra_options);
2390         setPrehandler(dialog_->input_spool_prefix);
2391         setPrehandler(dialog_->input_paper_size);
2392         setPrehandler(dialog_->input_name);
2393         setPrehandler(dialog_->check_adapt_output);
2394 }
2395
2396
2397 void FormPreferences::Printer::update()
2398 {
2399         fl_set_button(dialog_->check_adapt_output,
2400                       lyxrc.print_adapt_output);
2401         fl_set_input(dialog_->input_command,
2402                      lyxrc.print_command.c_str());
2403         fl_set_input(dialog_->input_page_range,
2404                      lyxrc.print_pagerange_flag.c_str());
2405         fl_set_input(dialog_->input_copies,
2406                      lyxrc.print_copies_flag.c_str());
2407         fl_set_input(dialog_->input_reverse,
2408                      lyxrc.print_reverse_flag.c_str());
2409         fl_set_input(dialog_->input_to_printer,
2410                      lyxrc.print_to_printer.c_str());
2411         fl_set_input(dialog_->input_file_extension,
2412                      lyxrc.print_file_extension.c_str());
2413         fl_set_input(dialog_->input_spool_command,
2414                      lyxrc.print_spool_command.c_str());
2415         fl_set_input(dialog_->input_paper_type,
2416                      lyxrc.print_paper_flag.c_str());
2417         fl_set_input(dialog_->input_even_pages,
2418                      lyxrc.print_evenpage_flag.c_str());
2419         fl_set_input(dialog_->input_odd_pages,
2420                      lyxrc.print_oddpage_flag.c_str());
2421         fl_set_input(dialog_->input_collated,
2422                      lyxrc.print_collcopies_flag.c_str());
2423         fl_set_input(dialog_->input_landscape,
2424                      lyxrc.print_landscape_flag.c_str());
2425         fl_set_input(dialog_->input_to_file,
2426                      lyxrc.print_to_file.c_str());
2427         fl_set_input(dialog_->input_extra_options,
2428                      lyxrc.print_extra_options.c_str());
2429         fl_set_input(dialog_->input_spool_prefix,
2430                      lyxrc.print_spool_printerprefix.c_str());
2431         fl_set_input(dialog_->input_paper_size,
2432                      lyxrc.print_paper_dimension_flag.c_str());
2433         fl_set_input(dialog_->input_name,
2434                      lyxrc.printer.c_str());
2435 }
2436
2437
2438 FormPreferences::ScreenFonts::ScreenFonts(FormPreferences &  p)
2439         : parent_(p)
2440 {}
2441
2442
2443 FD_preferences_screen_fonts const * FormPreferences::ScreenFonts::dialog()
2444 {
2445         return dialog_.get();
2446 }
2447
2448
2449 void FormPreferences::ScreenFonts::apply() const
2450 {
2451         bool changed = false;
2452
2453         string str = fl_get_input(dialog_->input_roman);
2454         if (lyxrc.roman_font_name != str) {
2455                 changed = true;
2456                 lyxrc.roman_font_name = str;
2457         }
2458
2459         str = fl_get_input(dialog_->input_sans);
2460         if (lyxrc.sans_font_name != str) {
2461                 changed = true;
2462                 lyxrc.sans_font_name = str;
2463         }
2464
2465         str = fl_get_input(dialog_->input_typewriter);
2466         if (lyxrc.typewriter_font_name != str) {
2467                 changed = true;
2468                 lyxrc.typewriter_font_name = str;
2469         }
2470
2471         str = fl_get_input(dialog_->input_screen_encoding);
2472         if (lyxrc.font_norm != str) {
2473                 changed = true;
2474                 lyxrc.font_norm = str;
2475         }
2476
2477         bool button = fl_get_button(dialog_->check_scalable);
2478         if (lyxrc.use_scalable_fonts != button) {
2479                 changed = true;
2480                 lyxrc.use_scalable_fonts = button;
2481         }
2482
2483         unsigned int ivalue = static_cast<unsigned int>
2484                 (fl_get_counter_value(dialog_->counter_zoom));
2485         if (lyxrc.zoom != ivalue) {
2486                 changed = true;
2487                 lyxrc.zoom = ivalue;
2488         }
2489
2490         ivalue = static_cast<unsigned int>
2491                 (fl_get_counter_value(dialog_->counter_dpi));
2492         if (lyxrc.dpi != ivalue) {
2493                 changed = true;
2494                 lyxrc.dpi = ivalue;
2495         }
2496
2497         double dvalue = strToDbl(fl_get_input(dialog_->input_tiny));
2498         if (lyxrc.font_sizes[LyXFont::SIZE_TINY] != dvalue) {
2499                 changed = true;
2500                 lyxrc.font_sizes[LyXFont::SIZE_TINY] = dvalue;
2501         }
2502
2503         dvalue = strToDbl(fl_get_input(dialog_->input_script));
2504         if (lyxrc.font_sizes[LyXFont::SIZE_SCRIPT] != dvalue) {
2505                 changed = true;
2506                 lyxrc.font_sizes[LyXFont::SIZE_SCRIPT] = dvalue;
2507         }
2508
2509         dvalue = strToDbl(fl_get_input(dialog_->input_footnote));
2510         if (lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE] != dvalue) {
2511                 changed = true;
2512                 lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE] = dvalue;
2513         }
2514
2515         dvalue = strToDbl(fl_get_input(dialog_->input_small));
2516         if (lyxrc.font_sizes[LyXFont::SIZE_SMALL] != dvalue) {
2517                 changed = true;
2518                 lyxrc.font_sizes[LyXFont::SIZE_SMALL] = dvalue;
2519         }
2520
2521         dvalue = strToDbl(fl_get_input(dialog_->input_normal));
2522         if (lyxrc.font_sizes[LyXFont::SIZE_NORMAL] != dvalue) {
2523                 changed = true;
2524                 lyxrc.font_sizes[LyXFont::SIZE_NORMAL] = dvalue;
2525         }
2526
2527         dvalue = strToDbl(fl_get_input(dialog_->input_large));
2528         if (lyxrc.font_sizes[LyXFont::SIZE_LARGE] != dvalue) {
2529                 changed = true;
2530                 lyxrc.font_sizes[LyXFont::SIZE_LARGE] = dvalue;
2531         }
2532
2533         dvalue = strToDbl(fl_get_input(dialog_->input_larger));
2534         if (lyxrc.font_sizes[LyXFont::SIZE_LARGER] != dvalue) {
2535                 changed = true;
2536                 lyxrc.font_sizes[LyXFont::SIZE_LARGER] = dvalue;
2537         }
2538
2539         dvalue = strToDbl(fl_get_input(dialog_->input_largest));
2540         if (lyxrc.font_sizes[LyXFont::SIZE_LARGEST] != dvalue) {
2541                 changed = true;
2542                 lyxrc.font_sizes[LyXFont::SIZE_LARGEST] = dvalue;
2543         }
2544
2545         dvalue = strToDbl(fl_get_input(dialog_->input_huge));
2546         if (lyxrc.font_sizes[LyXFont::SIZE_HUGE] != dvalue) {
2547                 changed = true;
2548                 lyxrc.font_sizes[LyXFont::SIZE_HUGE] = dvalue;
2549         }
2550
2551         dvalue = strToDbl(fl_get_input(dialog_->input_huger));
2552         if (lyxrc.font_sizes[LyXFont::SIZE_HUGER] != dvalue) {
2553                 changed = true;
2554                 lyxrc.font_sizes[LyXFont::SIZE_HUGER] = dvalue;
2555         }
2556
2557         if (changed) {
2558                 // Now update the buffers
2559                 // Can anything below here affect the redraw process?
2560                 parent_.lv_->getLyXFunc()->dispatch(LFUN_SCREEN_FONT_UPDATE);
2561         }
2562 }
2563
2564
2565 void FormPreferences::ScreenFonts::build()
2566 {
2567         dialog_.reset(build_preferences_screen_fonts(&parent_));
2568
2569         fl_set_counter_step(dialog_->counter_zoom, 1, 10);
2570         fl_set_counter_step(dialog_->counter_dpi,  1, 10);
2571
2572         fl_set_input_return(dialog_->input_roman,           FL_RETURN_CHANGED);
2573         fl_set_input_return(dialog_->input_sans,            FL_RETURN_CHANGED);
2574         fl_set_input_return(dialog_->input_typewriter,      FL_RETURN_CHANGED);
2575         fl_set_input_return(dialog_->input_screen_encoding, FL_RETURN_CHANGED);
2576         fl_set_counter_return(dialog_->counter_zoom,        FL_RETURN_CHANGED);
2577         fl_set_counter_return(dialog_->counter_dpi,         FL_RETURN_CHANGED);
2578         fl_set_input_return(dialog_->input_tiny,            FL_RETURN_CHANGED);
2579         fl_set_input_return(dialog_->input_script,          FL_RETURN_CHANGED);
2580         fl_set_input_return(dialog_->input_footnote,        FL_RETURN_CHANGED);
2581         fl_set_input_return(dialog_->input_small,           FL_RETURN_CHANGED);
2582         fl_set_input_return(dialog_->input_normal,          FL_RETURN_CHANGED);
2583         fl_set_input_return(dialog_->input_large,           FL_RETURN_CHANGED);
2584         fl_set_input_return(dialog_->input_larger,          FL_RETURN_CHANGED);
2585         fl_set_input_return(dialog_->input_largest,         FL_RETURN_CHANGED);
2586         fl_set_input_return(dialog_->input_huge,            FL_RETURN_CHANGED);
2587         fl_set_input_return(dialog_->input_huger,           FL_RETURN_CHANGED);
2588
2589         fl_set_input_filter(dialog_->input_tiny,     fl_unsigned_float_filter);
2590         fl_set_input_filter(dialog_->input_script,   fl_unsigned_float_filter);
2591         fl_set_input_filter(dialog_->input_footnote, fl_unsigned_float_filter);
2592         fl_set_input_filter(dialog_->input_small,    fl_unsigned_float_filter);
2593         fl_set_input_filter(dialog_->input_normal,   fl_unsigned_float_filter);
2594         fl_set_input_filter(dialog_->input_large,    fl_unsigned_float_filter);
2595         fl_set_input_filter(dialog_->input_larger,   fl_unsigned_float_filter);
2596         fl_set_input_filter(dialog_->input_largest,  fl_unsigned_float_filter);
2597         fl_set_input_filter(dialog_->input_huge,     fl_unsigned_float_filter);
2598         fl_set_input_filter(dialog_->input_huger,    fl_unsigned_float_filter);
2599
2600         // set up the feedback mechanism
2601         setPrehandler(dialog_->input_roman);
2602         setPrehandler(dialog_->input_sans);
2603         setPrehandler(dialog_->input_typewriter);
2604         setPrehandler(dialog_->counter_zoom);
2605         setPrehandler(dialog_->counter_dpi);
2606         setPrehandler(dialog_->check_scalable);
2607         setPrehandler(dialog_->input_screen_encoding);
2608         setPrehandler(dialog_->input_tiny);
2609         setPrehandler(dialog_->input_script);
2610         setPrehandler(dialog_->input_footnote);
2611         setPrehandler(dialog_->input_small);
2612         setPrehandler(dialog_->input_large);
2613         setPrehandler(dialog_->input_larger);
2614         setPrehandler(dialog_->input_largest);
2615         setPrehandler(dialog_->input_normal);
2616         setPrehandler(dialog_->input_huge);
2617         setPrehandler(dialog_->input_huger);
2618 }
2619
2620
2621 string const
2622 FormPreferences::ScreenFonts::feedback(FL_OBJECT const * const ob) const
2623 {
2624         if (ob == dialog_->input_roman)
2625                 return lyxrc.getDescription(LyXRC::RC_SCREEN_FONT_ROMAN);
2626         if (ob == dialog_->input_sans)
2627                 return lyxrc.getDescription(LyXRC::RC_SCREEN_FONT_SANS);
2628         if (ob == dialog_->input_typewriter)
2629                 return lyxrc.getDescription(LyXRC::RC_SCREEN_FONT_TYPEWRITER);
2630         if (ob == dialog_->check_scalable)
2631                 return lyxrc.getDescription(LyXRC::RC_SCREEN_FONT_SCALABLE);
2632         if (ob == dialog_->input_screen_encoding)
2633                 return lyxrc.getDescription(LyXRC::RC_SCREEN_FONT_ENCODING);
2634         if (ob == dialog_->counter_zoom)
2635                 return lyxrc.getDescription(LyXRC::RC_SCREEN_ZOOM);
2636         if (ob == dialog_->counter_dpi)
2637                 return lyxrc.getDescription(LyXRC::RC_SCREEN_DPI);
2638         if (ob == dialog_->input_tiny
2639                  || ob == dialog_->input_script
2640                  || ob == dialog_->input_footnote
2641                  || ob == dialog_->input_small
2642                  || ob == dialog_->input_large
2643                  || ob == dialog_->input_larger
2644                  || ob == dialog_->input_larger
2645                  || ob == dialog_->input_largest
2646                  || ob == dialog_->input_normal
2647                  || ob == dialog_->input_huge
2648                  || ob == dialog_->input_huger)
2649                 return lyxrc.getDescription(LyXRC::RC_SCREEN_FONT_SIZES);
2650         return string();
2651 }
2652
2653
2654 bool FormPreferences::ScreenFonts::input()
2655 {
2656         bool activate = true;
2657         string str;
2658
2659         // Make sure that all fonts all have positive entries
2660         // Also note that an empty entry is returned as 0.0 by strToDbl
2661         if (0.0 >= strToDbl(fl_get_input(dialog_->input_tiny))
2662             || 0.0 >= strToDbl(fl_get_input(dialog_->input_script))
2663             || 0.0 >= strToDbl(fl_get_input(dialog_->input_footnote))
2664             || 0.0 >= strToDbl(fl_get_input(dialog_->input_small))
2665             || 0.0 >= strToDbl(fl_get_input(dialog_->input_normal))
2666             || 0.0 >= strToDbl(fl_get_input(dialog_->input_large))
2667             || 0.0 >= strToDbl(fl_get_input(dialog_->input_larger))
2668             || 0.0 >= strToDbl(fl_get_input(dialog_->input_largest))
2669             || 0.0 >= strToDbl(fl_get_input(dialog_->input_huge))
2670             || 0.0 >= strToDbl(fl_get_input(dialog_->input_huger))) {
2671                 activate = false;
2672                 str = _("Fonts must be positive!");
2673
2674         } else if (strToDbl(fl_get_input(dialog_->input_tiny)) >
2675                    // Fontsizes -- tiny < script < footnote etc.
2676                    strToDbl(fl_get_input(dialog_->input_script)) ||
2677                    strToDbl(fl_get_input(dialog_->input_script)) >
2678                    strToDbl(fl_get_input(dialog_->input_footnote)) ||
2679                    strToDbl(fl_get_input(dialog_->input_footnote)) >
2680                    strToDbl(fl_get_input(dialog_->input_small)) ||
2681                    strToDbl(fl_get_input(dialog_->input_small)) >
2682                    strToDbl(fl_get_input(dialog_->input_normal)) ||
2683                    strToDbl(fl_get_input(dialog_->input_normal)) >
2684                    strToDbl(fl_get_input(dialog_->input_large)) ||
2685                    strToDbl(fl_get_input(dialog_->input_large)) >
2686                    strToDbl(fl_get_input(dialog_->input_larger)) ||
2687                    strToDbl(fl_get_input(dialog_->input_larger)) >
2688                    strToDbl(fl_get_input(dialog_->input_largest)) ||
2689                    strToDbl(fl_get_input(dialog_->input_largest)) >
2690                    strToDbl(fl_get_input(dialog_->input_huge)) ||
2691                    strToDbl(fl_get_input(dialog_->input_huge)) >
2692                    strToDbl(fl_get_input(dialog_->input_huger))) {
2693                 activate = false;
2694
2695                 str = _("Fonts must be input in the order tiny > script> footnote > small > normal > large > larger > largest > huge > huger.");
2696         }
2697
2698         if (!activate)
2699                 parent_.postWarning(str);
2700
2701         return activate;
2702 }
2703
2704
2705 void FormPreferences::ScreenFonts::update()
2706 {
2707         fl_set_input(dialog_->input_roman,
2708                      lyxrc.roman_font_name.c_str());
2709         fl_set_input(dialog_->input_sans,
2710                      lyxrc.sans_font_name.c_str());
2711         fl_set_input(dialog_->input_typewriter,
2712                      lyxrc.typewriter_font_name.c_str());
2713         fl_set_input(dialog_->input_screen_encoding,
2714                      lyxrc.font_norm.c_str());
2715         fl_set_button(dialog_->check_scalable,
2716                       lyxrc.use_scalable_fonts);
2717         fl_set_counter_value(dialog_->counter_zoom, lyxrc.zoom);
2718         fl_set_counter_value(dialog_->counter_dpi,  lyxrc.dpi);
2719         fl_set_input(dialog_->input_tiny,
2720                      tostr(lyxrc.font_sizes[LyXFont::SIZE_TINY]).c_str());
2721         fl_set_input(dialog_->input_script,
2722                      tostr(lyxrc.font_sizes[LyXFont::SIZE_SCRIPT]).c_str());
2723         fl_set_input(dialog_->input_footnote,
2724                      tostr(lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE]).c_str());
2725         fl_set_input(dialog_->input_small,
2726                      tostr(lyxrc.font_sizes[LyXFont::SIZE_SMALL]).c_str());
2727         fl_set_input(dialog_->input_normal,
2728                      tostr(lyxrc.font_sizes[LyXFont::SIZE_NORMAL]).c_str());
2729         fl_set_input(dialog_->input_large,
2730                      tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGE]).c_str());
2731         fl_set_input(dialog_->input_larger,
2732                      tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGER]).c_str());
2733         fl_set_input(dialog_->input_largest,
2734                      tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGEST]).c_str());
2735         fl_set_input(dialog_->input_huge,
2736                      tostr(lyxrc.font_sizes[LyXFont::SIZE_HUGE]).c_str());
2737         fl_set_input(dialog_->input_huger,
2738                      tostr(lyxrc.font_sizes[LyXFont::SIZE_HUGER]).c_str());
2739 }
2740
2741
2742
2743 FormPreferences::SpellOptions::SpellOptions(FormPreferences &  p)
2744         : parent_(p)
2745 {}
2746
2747
2748 FD_preferences_spelloptions const * FormPreferences::SpellOptions::dialog()
2749 {
2750         return dialog_.get();
2751 }
2752
2753
2754 void FormPreferences::SpellOptions::apply()
2755 {
2756
2757         string choice = fl_get_choice_text(dialog_->choice_spell_command);
2758         choice = trim(choice);
2759
2760         lyxrc.isp_command = choice;
2761
2762 #if 0
2763         // If spell checker == "none", all other input set to off.
2764         if (fl_get_choice(dialog_->choice_spell_command) == 1) {
2765                 lyxrc.isp_use_alt_lang = false;
2766                 lyxrc.isp_alt_lang.erase();
2767
2768                 lyxrc.isp_use_esc_chars = false;
2769                 lyxrc.isp_esc_chars.erase();
2770
2771                 lyxrc.isp_use_pers_dict = false;
2772                 lyxrc.isp_pers_dict.erase();
2773
2774                 lyxrc.isp_accept_compound = false;
2775                 lyxrc.isp_use_input_encoding = false;
2776         } else {
2777 #else
2778                 int button = fl_get_button(dialog_->check_alt_lang);
2779                 choice = fl_get_input(dialog_->input_alt_lang);
2780                 if (button && choice.empty()) button = 0;
2781                 if (!button) choice.erase();
2782
2783                 lyxrc.isp_use_alt_lang = static_cast<bool>(button);
2784                 lyxrc.isp_alt_lang = choice;
2785
2786                 button = fl_get_button(dialog_->check_escape_chars);
2787                 choice = fl_get_input(dialog_->input_escape_chars);
2788                 if (button && choice.empty()) button = 0;
2789                 if (!button) choice.erase();
2790
2791                 lyxrc.isp_use_esc_chars = static_cast<bool>(button);
2792                 lyxrc.isp_esc_chars = choice;
2793
2794                 button = fl_get_button(dialog_->check_personal_dict);
2795                 choice = fl_get_input(dialog_->input_personal_dict);
2796                 if (button && choice.empty()) button = 0;
2797                 if (!button) choice.erase();
2798
2799                 lyxrc.isp_use_pers_dict = static_cast<bool>(button);
2800                 lyxrc.isp_pers_dict = choice;
2801
2802                 button = fl_get_button(dialog_->check_compound_words);
2803                 lyxrc.isp_accept_compound = static_cast<bool>(button);
2804
2805                 button = fl_get_button(dialog_->check_input_enc);
2806                 lyxrc.isp_use_input_encoding = static_cast<bool>(button);
2807 #endif
2808 #if 0
2809         }
2810 #endif
2811
2812         // Reset view
2813         update();
2814 }
2815
2816
2817 void FormPreferences::SpellOptions::build()
2818 {
2819         dialog_.reset(build_preferences_spelloptions(&parent_));
2820
2821         fl_addto_choice(dialog_->choice_spell_command,
2822                         _(" ispell | aspell "));
2823         fl_set_input_return(dialog_->input_alt_lang,      FL_RETURN_CHANGED);
2824         fl_set_input_return(dialog_->input_escape_chars,  FL_RETURN_CHANGED);
2825         fl_set_input_return(dialog_->input_personal_dict, FL_RETURN_CHANGED);
2826
2827         // set up the feedback mechanism
2828         setPrehandler(dialog_->choice_spell_command);
2829         setPrehandler(dialog_->check_alt_lang);
2830         setPrehandler(dialog_->input_alt_lang);
2831         setPrehandler(dialog_->check_escape_chars);
2832         setPrehandler(dialog_->input_escape_chars);
2833         setPrehandler(dialog_->check_personal_dict);
2834         setPrehandler(dialog_->input_personal_dict);
2835         setPrehandler(dialog_->button_personal_dict);
2836         setPrehandler(dialog_->check_compound_words);
2837         setPrehandler(dialog_->check_input_enc);
2838 }
2839
2840
2841 string const
2842 FormPreferences::SpellOptions::feedback(FL_OBJECT const * const ob) const
2843 {
2844         if (ob == dialog_->choice_spell_command)
2845                 return lyxrc.getDescription(LyXRC::RC_SPELL_COMMAND);
2846         if (ob == dialog_->check_alt_lang)
2847                 return lyxrc.getDescription(LyXRC::RC_USE_ALT_LANG);
2848         if (ob == dialog_->input_alt_lang)
2849                 return lyxrc.getDescription(LyXRC::RC_ALT_LANG);
2850         if (ob == dialog_->check_escape_chars)
2851                 return lyxrc.getDescription(LyXRC::RC_USE_ESC_CHARS);
2852         if (ob == dialog_->input_escape_chars)
2853                 return lyxrc.getDescription(LyXRC::RC_ESC_CHARS);
2854         if (ob == dialog_->check_personal_dict)
2855                 return lyxrc.getDescription(LyXRC::RC_USE_PERS_DICT);
2856         if (ob == dialog_->input_personal_dict)
2857                 return lyxrc.getDescription(LyXRC::RC_PERS_DICT);
2858         if (ob == dialog_->check_compound_words)
2859                 return lyxrc.getDescription(LyXRC::RC_ACCEPT_COMPOUND);
2860         if (ob == dialog_->check_input_enc)
2861                 return lyxrc.getDescription(LyXRC::RC_USE_INP_ENC);
2862         return string();
2863 }
2864
2865
2866 bool FormPreferences::SpellOptions::input(FL_OBJECT const * const ob)
2867 {
2868         // !ob if function is called from updateSpellOptions() to de/activate
2869         // objects,
2870         // otherwise the function is called by an xforms CB via input().
2871
2872 #if 0
2873         // If spell checker == "none", disable all input.
2874         if (!ob || ob == dialog_->choice_spell_command) {
2875                 if (fl_get_choice(dialog_->choice_spell_command) == 1) {
2876                         fl_deactivate_object(dialog_->check_alt_lang);
2877                         fl_deactivate_object(dialog_->input_alt_lang);
2878                         fl_deactivate_object(dialog_->check_escape_chars);
2879                         fl_deactivate_object(dialog_->input_escape_chars);
2880                         fl_deactivate_object(dialog_->check_personal_dict);
2881                         fl_deactivate_object(dialog_->input_personal_dict);
2882                         fl_deactivate_object(dialog_->check_compound_words);
2883                         fl_deactivate_object(dialog_->check_input_enc);
2884                         return true;
2885                 } else {
2886                         fl_activate_object(dialog_->check_alt_lang);
2887                         fl_activate_object(dialog_->check_escape_chars);
2888                         fl_activate_object(dialog_->check_personal_dict);
2889                         fl_activate_object(dialog_->check_compound_words);
2890                         fl_activate_object(dialog_->check_input_enc);
2891                 }
2892         }
2893 #endif
2894
2895         if (!ob || ob == dialog_->check_alt_lang) {
2896                 bool const enable = fl_get_button(dialog_->check_alt_lang);
2897                 setEnabled(dialog_->input_alt_lang, enable);
2898         }
2899
2900         if (!ob || ob == dialog_->check_escape_chars) {
2901                 bool const enable = fl_get_button(dialog_->check_escape_chars);
2902                 setEnabled(dialog_->input_escape_chars, enable);
2903         }
2904
2905         if (!ob || ob == dialog_->check_personal_dict) {
2906                 bool const enable = fl_get_button(dialog_->check_personal_dict);
2907                 setEnabled(dialog_->input_personal_dict, enable);
2908         }
2909
2910         if (ob == dialog_->button_personal_dict) {
2911                 parent_.browse(dialog_->input_personal_dict,
2912                                _("Personal dictionary"), "*.ispell");
2913         }
2914
2915         return true; // All input is valid!
2916 }
2917
2918
2919 void FormPreferences::SpellOptions::update()
2920 {
2921         int choice = 1;
2922 #if 0
2923         if (lyxrc.isp_command == "none")
2924                 choice = 1;
2925         else if (lyxrc.isp_command == "ispell")
2926                 choice = 2;
2927         else if (lyxrc.isp_command == "aspell")
2928                 choice = 3;
2929 #else
2930         if (lyxrc.isp_command == "ispell")
2931                 choice = 1;
2932         else if (lyxrc.isp_command == "aspell")
2933                 choice = 2;
2934 #endif
2935         fl_set_choice(dialog_->choice_spell_command, choice);
2936
2937         string str;
2938         if (lyxrc.isp_use_alt_lang)
2939                 str = lyxrc.isp_alt_lang;
2940
2941         fl_set_button(dialog_->check_alt_lang,
2942                       lyxrc.isp_use_alt_lang);
2943         fl_set_input(dialog_->input_alt_lang, str.c_str());
2944
2945         str.erase();
2946         if (lyxrc.isp_use_esc_chars)
2947                 str = lyxrc.isp_esc_chars;
2948
2949         fl_set_button(dialog_->check_escape_chars,
2950                       lyxrc.isp_use_esc_chars);
2951         fl_set_input(dialog_->input_escape_chars, str.c_str());
2952
2953         str.erase();
2954         if (lyxrc.isp_use_pers_dict)
2955                 str = lyxrc.isp_pers_dict;
2956
2957         fl_set_button(dialog_->check_personal_dict,
2958                       lyxrc.isp_use_pers_dict);
2959         fl_set_input(dialog_->input_personal_dict, str.c_str());
2960
2961         fl_set_button(dialog_->check_compound_words,
2962                       lyxrc.isp_accept_compound);
2963         fl_set_button(dialog_->check_input_enc,
2964                       lyxrc.isp_use_input_encoding);
2965
2966         // Activate/Deactivate the input fields dependent on the state of the
2967         // buttons.
2968         input(0);
2969 }
2970
2971
2972 void FormPreferences::browse(FL_OBJECT * inpt,
2973                              string const & title,
2974                              string const & pattern,
2975                              pair<string,string> const & dir1,
2976                              pair<string,string> const & dir2)
2977 {
2978         // Get the filename from the dialog
2979         string const filename = fl_get_input(inpt);
2980
2981         // Show the file browser dialog
2982         string const new_filename =
2983                 browseFile(lv_, filename, title, pattern, dir1, dir2);
2984
2985         // Save the filename to the dialog
2986         if (new_filename != filename && !new_filename.empty()) {
2987                 fl_set_input(inpt, new_filename.c_str());
2988                 input(inpt, 0);
2989         }
2990 }