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