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