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