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