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