]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormPreferences.C
merge booktabs branch
[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 "session.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         setPrehandler(dialog_->check_document);
1317 }
1318
1319
1320 string const
1321 FormPreferences::Formats::feedback(FL_OBJECT const * const ob) const
1322 {
1323         if (ob == dialog_->browser_all)
1324                 return  _("All the currently defined formats known to LyX.");
1325
1326         if (ob == dialog_->input_format)
1327                 return  _("The format identifier.");
1328
1329         if (ob == dialog_->input_gui_name)
1330                 return  _("The format name as it will appear in the menus.");
1331
1332         if (ob == dialog_->input_shrtcut)
1333                 return  _("The keyboard accelerator. Use a letter in the GUI name. "
1334                           "Case sensitive.");
1335
1336         if (ob == dialog_->input_extension)
1337                 return  _("Used to recognize the file. E.g., ps, pdf, tex.");
1338
1339         if (ob == dialog_->input_viewer)
1340                 return  _("The command used to launch the viewer application.");
1341
1342         if (ob == dialog_->input_editor)
1343                 return  _("The command used to launch the editor application.");
1344
1345         if (ob == dialog_->button_delete)
1346                 return  _("Remove the current format from the list of available "
1347                           "formats. Note: you must then \"Apply\" the change.");
1348
1349         if (ob == dialog_->check_document)
1350                 return  _("Tell whether this format is a document format. "
1351                           "A document can not be exported to or viewed in a non-document format.");
1352
1353         if (ob == dialog_->button_add) {
1354                 if (string(ob->label) == _("Add"))
1355                         return  _("Add the current format to the list of available "
1356                                   "formats. Note: you must then \"Apply\" the change.");
1357                 else
1358                         return  _("Modify the contents of the current format. Note: "
1359                                   "you must then \"Apply\" the change.");
1360         }
1361
1362         return string();
1363 }
1364
1365
1366 bool FormPreferences::Formats::input(FL_OBJECT const * const ob)
1367 {
1368         if (ob == dialog_->browser_all)
1369                 return Browser();
1370
1371         if (ob == dialog_->input_format
1372             || ob == dialog_->input_gui_name
1373             || ob == dialog_->input_shrtcut
1374             || ob == dialog_->input_extension
1375             || ob == dialog_->input_viewer
1376             || ob == dialog_->input_editor
1377             || ob == dialog_->check_document)
1378                 return Input();
1379
1380         if (ob == dialog_->button_add)
1381                 return Add();
1382
1383         if (ob == dialog_->button_delete)
1384                 return erase();
1385
1386         return false;
1387 }
1388
1389
1390 void FormPreferences::Formats::update()
1391 {
1392         UpdateBrowser();
1393 }
1394
1395
1396 void FormPreferences::Formats::UpdateBrowser()
1397 {
1398         formats().sort();
1399
1400         fl_freeze_form(dialog_->form);
1401         fl_deselect_browser(dialog_->browser_all);
1402         fl_clear_browser(dialog_->browser_all);
1403         for (::Formats::const_iterator cit = formats().begin();
1404              cit != formats().end(); ++cit)
1405                 fl_addto_browser(dialog_->browser_all,
1406                                  cit->prettyname().c_str());
1407
1408         Input();
1409         fl_unfreeze_form(dialog_->form);
1410
1411         // Mustn't forget to update the Formats available to the converters_
1412         parent_.converters_.UpdateChoices();
1413         converters().update(formats());
1414 }
1415
1416
1417 bool FormPreferences::Formats::Add()
1418 {
1419         string const name = getString(dialog_->input_format);
1420         string const prettyname = getString(dialog_->input_gui_name);
1421         string const extension = getString(dialog_->input_extension);
1422         string const shortcut =  getString(dialog_->input_shrtcut);
1423         string const viewer =  getString(dialog_->input_viewer);
1424         string const editor =  getString(dialog_->input_editor);
1425         bool const document = fl_get_button(dialog_->check_document);
1426
1427         Format const * old = formats().getFormat(name);
1428         string const old_prettyname = old ? old->prettyname() : string();
1429         formats().add(name, extension, prettyname, shortcut, viewer, editor,
1430                       document);
1431         if (!old || prettyname != old_prettyname) {
1432                 UpdateBrowser();
1433                 if (old)
1434                         parent_.converters_.UpdateBrowser();
1435         }
1436         setEnabled(dialog_->button_add, false);
1437
1438         return true;
1439 }
1440
1441
1442 bool FormPreferences::Formats::Browser()
1443 {
1444         int const i = fl_get_browser(dialog_->browser_all);
1445         if (i <= 0)
1446                 return false;
1447
1448         fl_freeze_form(dialog_->form);
1449
1450         Format const & f = formats().get(i - 1);
1451
1452         fl_set_input(dialog_->input_format, f.name().c_str());
1453         fl_set_input(dialog_->input_gui_name, f.prettyname().c_str());
1454         fl_set_input(dialog_->input_shrtcut, f.shortcut().c_str());
1455         fl_set_input(dialog_->input_extension, f.extension().c_str());
1456         fl_set_input(dialog_->input_viewer, f.viewer().c_str());
1457         fl_set_input(dialog_->input_editor, f.editor().c_str());
1458         fl_set_button(dialog_->check_document, f.documentFormat());
1459
1460         fl_set_object_label(dialog_->button_add,
1461                             idex(_("Modify|#M")).c_str());
1462         fl_set_button_shortcut(dialog_->button_add,
1463                                scex(_("Modify|#M")).c_str(), 1);
1464
1465         setEnabled(dialog_->button_add,    false);
1466         setEnabled(dialog_->button_delete, true);
1467
1468         fl_unfreeze_form(dialog_->form);
1469         return false;
1470 }
1471
1472
1473 bool FormPreferences::Formats::erase()
1474 {
1475         string const name = getString(dialog_->input_format);
1476
1477         if (converters().formatIsUsed(name)) {
1478                 parent_.postWarning(_("Cannot remove a Format used by a Converter. "
1479                                       "Remove the converter first."));
1480                 setEnabled(dialog_->button_delete, false);
1481                 return false;
1482         }
1483
1484         formats().erase(name);
1485         UpdateBrowser();
1486         return true;
1487 }
1488
1489
1490 bool FormPreferences::Formats::Input()
1491 {
1492         string const name = getString(dialog_->input_format);
1493         int const sel = formats().getNumber(name);
1494         fl_freeze_form(dialog_->form);
1495
1496         if (sel < 0) {
1497                 fl_set_object_label(dialog_->button_add,
1498                                     idex(_("Add|#A")).c_str());
1499                 fl_set_button_shortcut(dialog_->button_add,
1500                                        scex(_("Add|#A")).c_str(), 1);
1501
1502                 fl_deselect_browser(dialog_->browser_all);
1503                 setEnabled(dialog_->button_delete, false);
1504
1505         } else {
1506                 fl_set_object_label(dialog_->button_add,
1507                                     idex(_("Modify|#M")).c_str());
1508                 fl_set_button_shortcut(dialog_->button_add,
1509                                        scex(_("Modify|#M")).c_str(), 1);
1510
1511                 int const top = max(sel-5, 0);
1512                 fl_set_browser_topline(dialog_->browser_all, top);
1513                 fl_select_browser_line(dialog_->browser_all, sel+1);
1514
1515                 setEnabled(dialog_->button_add, true);
1516                 setEnabled(dialog_->button_delete, true);
1517         }
1518
1519         string const prettyname = getString(dialog_->input_gui_name);
1520         bool const enable = !(name.empty() || prettyname.empty());
1521         setEnabled(dialog_->button_add, enable);
1522
1523         fl_unfreeze_form(dialog_->form);
1524         return false;
1525 }
1526
1527
1528 FormPreferences::Identity::Identity(FormPreferences & p)
1529         : parent_(p)
1530 {}
1531
1532
1533 FD_preferences_identity const * FormPreferences::Identity::dialog()
1534 {
1535         return dialog_.get();
1536 }
1537
1538
1539 void FormPreferences::Identity::apply(LyXRC & rc) const
1540 {
1541         rc.user_name = getString(dialog_->input_user_name);
1542         rc.user_email = getString(dialog_->input_user_email);
1543 }
1544
1545
1546 void FormPreferences::Identity::build()
1547 {
1548         dialog_.reset(build_preferences_identity(&parent_));
1549         fl_set_input_return(dialog_->input_user_name, FL_RETURN_CHANGED);
1550         fl_set_input_return(dialog_->input_user_email, FL_RETURN_CHANGED);
1551 }
1552
1553
1554 void FormPreferences::Identity::update(LyXRC const & rc)
1555 {
1556         fl_set_input(dialog_->input_user_name, rc.user_name.c_str());
1557         fl_set_input(dialog_->input_user_email, rc.user_email.c_str());
1558 }
1559
1560
1561 FormPreferences::InputsMisc::InputsMisc(FormPreferences &  p)
1562         : parent_(p)
1563 {}
1564
1565
1566 FD_preferences_inputs_misc const * FormPreferences::InputsMisc::dialog()
1567 {
1568         return dialog_.get();
1569 }
1570
1571
1572 void FormPreferences::InputsMisc::apply(LyXRC & rc) const
1573 {
1574         rc.date_insert_format =
1575                 getString(dialog_->input_date_format);
1576 }
1577
1578
1579 void FormPreferences::InputsMisc::build()
1580 {
1581         dialog_.reset(build_preferences_inputs_misc(&parent_));
1582
1583         fl_set_input_return(dialog_->input_date_format, FL_RETURN_CHANGED);
1584
1585         // set up the feedback mechanism
1586         setPrehandler(dialog_->input_date_format);
1587 }
1588
1589
1590 string const
1591 FormPreferences::InputsMisc::feedback(FL_OBJECT const * const ob) const
1592 {
1593         if (ob == dialog_->input_date_format)
1594                 return LyXRC::getDescription(LyXRC::RC_DATE_INSERT_FORMAT);
1595         return string();
1596 }
1597
1598
1599 void FormPreferences::InputsMisc::update(LyXRC const & rc)
1600 {
1601         fl_set_input(dialog_->input_date_format,
1602                      rc.date_insert_format.c_str());
1603 }
1604
1605
1606 FormPreferences::Interface::Interface(FormPreferences &  p)
1607         : parent_(p)
1608 {}
1609
1610
1611 FD_preferences_interface const * FormPreferences::Interface::dialog()
1612 {
1613         return dialog_.get();
1614 }
1615
1616
1617 void FormPreferences::Interface::apply(LyXRC & rc) const
1618 {
1619         rc.popup_normal_font =
1620                 getString(dialog_->input_popup_normal_font);
1621         rc.popup_bold_font = getString(dialog_->input_popup_bold_font);
1622         rc.popup_font_encoding =
1623                 getString(dialog_->input_popup_font_encoding);
1624         rc.bind_file = getString(dialog_->input_bind_file);
1625         rc.ui_file = getString(dialog_->input_ui_file);
1626 }
1627
1628
1629 void FormPreferences::Interface::build()
1630 {
1631         dialog_.reset(build_preferences_interface(&parent_));
1632
1633         fl_set_input_return(dialog_->input_popup_normal_font, FL_RETURN_CHANGED);
1634         fl_set_input_return(dialog_->input_popup_bold_font, FL_RETURN_CHANGED);
1635         fl_set_input_return(dialog_->input_popup_font_encoding, FL_RETURN_CHANGED);
1636         fl_set_input_return(dialog_->input_bind_file, FL_RETURN_CHANGED);
1637         fl_set_input_return(dialog_->input_ui_file, FL_RETURN_CHANGED);
1638
1639         // set up the feedback mechanism
1640         setPrehandler(dialog_->input_popup_normal_font);
1641         setPrehandler(dialog_->input_popup_bold_font);
1642         setPrehandler(dialog_->input_popup_font_encoding);
1643         setPrehandler(dialog_->input_bind_file);
1644         setPrehandler(dialog_->button_bind_file_browse);
1645         setPrehandler(dialog_->input_ui_file);
1646         setPrehandler(dialog_->button_ui_file_browse);
1647 }
1648
1649
1650 string const
1651 FormPreferences::Interface::feedback(FL_OBJECT const * const ob) const
1652 {
1653         if (ob == dialog_->input_popup_normal_font)
1654                 return LyXRC::getDescription(LyXRC::RC_POPUP_NORMAL_FONT);
1655         if (ob == dialog_->input_popup_bold_font)
1656                 return LyXRC::getDescription(LyXRC::RC_POPUP_BOLD_FONT);
1657         if (ob == dialog_->input_popup_font_encoding)
1658                 return LyXRC::getDescription(LyXRC::RC_POPUP_FONT_ENCODING);
1659         if (ob == dialog_->input_bind_file)
1660                 return LyXRC::getDescription(LyXRC::RC_BINDFILE);
1661         if (ob == dialog_->input_ui_file)
1662                 return LyXRC::getDescription(LyXRC::RC_UIFILE);
1663         return string();
1664 }
1665
1666
1667 bool FormPreferences::Interface::input(FL_OBJECT const * const ob)
1668 {
1669         if (ob == dialog_->button_bind_file_browse) {
1670                 string f = parent_.controller().browsebind(
1671                         getString(dialog_->input_bind_file));
1672
1673                 fl_set_input(dialog_->input_bind_file, f.c_str());
1674         } else if (ob == dialog_->button_ui_file_browse) {
1675                 string f = parent_.controller().browseUI(
1676                         getString(dialog_->input_ui_file));
1677
1678                 fl_set_input(dialog_->input_ui_file, f.c_str());
1679         }
1680
1681         return true;
1682 }
1683
1684
1685 void FormPreferences::Interface::update(LyXRC const & rc)
1686 {
1687         fl_set_input(dialog_->input_popup_normal_font,
1688                      rc.popup_normal_font.c_str());
1689         fl_set_input(dialog_->input_popup_bold_font,
1690                      rc.popup_bold_font.c_str());
1691         fl_set_input(dialog_->input_popup_font_encoding,
1692                      rc.popup_font_encoding.c_str());
1693         fl_set_input(dialog_->input_bind_file,
1694                      rc.bind_file.c_str());
1695         fl_set_input(dialog_->input_ui_file,
1696                      rc.ui_file.c_str());
1697 }
1698
1699
1700 FormPreferences::Language::Language(FormPreferences &  p)
1701         : parent_(p)
1702 {}
1703
1704
1705 FD_preferences_language const * FormPreferences::Language::dialog()
1706 {
1707         return dialog_.get();
1708 }
1709
1710
1711 void FormPreferences::Language::apply(LyXRC & rc)
1712 {
1713         int const pos = fl_get_combox(dialog_->combox_default_lang);
1714         rc.default_language = lang_[pos-1];
1715
1716         int button = fl_get_button(dialog_->check_use_kbmap);
1717         string const name_1 = getString(dialog_->input_kbmap1);
1718         string const name_2 = getString(dialog_->input_kbmap2);
1719         if (button)
1720                 button = !(name_1.empty() && name_2.empty());
1721         rc.use_kbmap = static_cast<bool>(button);
1722
1723         if (rc.use_kbmap) {
1724                 rc.primary_kbmap = name_1;
1725                 rc.secondary_kbmap = name_2;
1726         }
1727
1728         button = fl_get_button(dialog_->check_rtl_support);
1729         rc.rtl_support = static_cast<bool>(button);
1730
1731         button = fl_get_button(dialog_->check_mark_foreign);
1732         rc.mark_foreign_language = static_cast<bool>(button);
1733
1734         button = fl_get_button(dialog_->check_auto_begin);
1735         rc.language_auto_begin = static_cast<bool>(button);
1736
1737         button = fl_get_button(dialog_->check_auto_end);
1738         rc.language_auto_end = static_cast<bool>(button);
1739
1740         button = fl_get_button(dialog_->check_use_babel);
1741         rc.language_use_babel = static_cast<bool>(button);
1742
1743         button = fl_get_button(dialog_->check_global_options);
1744         rc.language_global_options = static_cast<bool>(button);
1745
1746         rc.language_package = getString(dialog_->input_package);
1747         rc.language_command_begin = getString(dialog_->input_command_begin);
1748         rc.language_command_end = getString(dialog_->input_command_end);
1749
1750         // Ensure that all is self-consistent.
1751         update(rc);
1752 }
1753
1754
1755 void FormPreferences::Language::build()
1756 {
1757         dialog_.reset(build_preferences_language(&parent_));
1758
1759         fl_set_input_return(dialog_->input_package, FL_RETURN_CHANGED);
1760         fl_set_input_return(dialog_->input_command_begin, FL_RETURN_CHANGED);
1761         fl_set_input_return(dialog_->input_command_end, FL_RETURN_CHANGED);
1762
1763         // Store the lang identifiers for later
1764         vector<LanguagePair> const langs = getLanguageData(false);
1765         lang_ = getSecond(langs);
1766
1767         FL_OBJECT * obj = dialog_->combox_default_lang;
1768         vector<LanguagePair>::const_iterator lit  = langs.begin();
1769         vector<LanguagePair>::const_iterator lend = langs.end();
1770         for (; lit != lend; ++lit) {
1771                 fl_addto_combox(obj, lit->first.c_str());
1772         }
1773         fl_set_combox_browser_height(obj, 400);
1774
1775         // set up the feedback mechanism
1776         setPrehandler(dialog_->input_package);
1777         setPrehandler(dialog_->check_use_kbmap);
1778         setPrehandler(dialog_->combox_default_lang);
1779         setPrehandler(dialog_->input_kbmap1);
1780         setPrehandler(dialog_->input_kbmap2);
1781         setPrehandler(dialog_->check_rtl_support);
1782         setPrehandler(dialog_->check_mark_foreign);
1783         setPrehandler(dialog_->check_auto_begin);
1784         setPrehandler(dialog_->check_auto_end);
1785         setPrehandler(dialog_->check_use_babel);
1786         setPrehandler(dialog_->check_global_options);
1787         setPrehandler(dialog_->input_command_begin);
1788         setPrehandler(dialog_->input_command_end);
1789
1790         // Activate/Deactivate the input fields dependent on the state of the
1791         // buttons.
1792         input(0);
1793 }
1794
1795
1796 string const
1797 FormPreferences::Language::feedback(FL_OBJECT const * const ob) const
1798 {
1799         if (ob == dialog_->combox_default_lang)
1800                 return LyXRC::getDescription(LyXRC::RC_DEFAULT_LANGUAGE);
1801         if (ob == dialog_->check_use_kbmap)
1802                 return LyXRC::getDescription(LyXRC::RC_KBMAP);
1803         if (ob == dialog_->input_kbmap1)
1804                 return LyXRC::getDescription(LyXRC::RC_KBMAP_PRIMARY);
1805         if (ob == dialog_->input_kbmap2)
1806                 return LyXRC::getDescription(LyXRC::RC_KBMAP_SECONDARY);
1807         if (ob == dialog_->check_rtl_support)
1808                 return LyXRC::getDescription(LyXRC::RC_RTL_SUPPORT);
1809         if (ob == dialog_->check_mark_foreign)
1810                 return LyXRC::getDescription(LyXRC::RC_MARK_FOREIGN_LANGUAGE);
1811         if (ob == dialog_->check_auto_begin)
1812                 return LyXRC::getDescription(LyXRC::RC_LANGUAGE_AUTO_BEGIN);
1813         if (ob == dialog_->check_auto_end)
1814                 return LyXRC::getDescription(LyXRC::RC_LANGUAGE_AUTO_END);
1815         if (ob == dialog_->check_use_babel)
1816                 return LyXRC::getDescription(LyXRC::RC_LANGUAGE_USE_BABEL);
1817         if (ob == dialog_->check_global_options)
1818                 return LyXRC::getDescription(LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS);
1819         if (ob == dialog_->input_package)
1820                 return LyXRC::getDescription(LyXRC::RC_LANGUAGE_PACKAGE);
1821         if (ob == dialog_->input_command_begin)
1822                 return LyXRC::getDescription(LyXRC::RC_LANGUAGE_COMMAND_BEGIN);
1823         if (ob == dialog_->input_command_end)
1824                 return LyXRC::getDescription(LyXRC::RC_LANGUAGE_COMMAND_END);
1825         return string();
1826 }
1827
1828
1829 bool FormPreferences::Language::input(FL_OBJECT const * const ob)
1830 {
1831         bool activate = true;
1832
1833         // !ob if function is called from Language::build() to de/activate
1834         // objects,
1835         // otherwise the function is called by an xforms CB via input().
1836         if (!ob || ob == dialog_->check_use_kbmap) {
1837                 bool const enable = fl_get_button(dialog_->check_use_kbmap);
1838                 setEnabled(dialog_->button_kbmap1_browse, enable);
1839                 setEnabled(dialog_->button_kbmap2_browse, enable);
1840                 setEnabled(dialog_->input_kbmap1, enable);
1841                 setEnabled(dialog_->input_kbmap2, enable);
1842         }
1843
1844         if (ob == dialog_->button_kbmap1_browse) {
1845                 string f = parent_.controller().browsekbmap(
1846                         getString(dialog_->input_kbmap1));
1847
1848                 fl_set_input(dialog_->input_kbmap1, f.c_str());
1849         } else if (ob == dialog_->button_kbmap2_browse) {
1850                 string f = parent_.controller().browsekbmap(
1851                         getString(dialog_->input_kbmap2));
1852
1853                 fl_set_input(dialog_->input_kbmap2, f.c_str());
1854         }
1855
1856         return activate;
1857 }
1858
1859
1860 void FormPreferences::Language::update(LyXRC const & rc)
1861 {
1862         fl_set_button(dialog_->check_use_kbmap,
1863                       rc.use_kbmap);
1864
1865         int const pos = int(findPos(lang_, rc.default_language));
1866         fl_set_combox(dialog_->combox_default_lang, pos + 1);
1867
1868         if (rc.use_kbmap) {
1869                 fl_set_input(dialog_->input_kbmap1,
1870                              rc.primary_kbmap.c_str());
1871                 fl_set_input(dialog_->input_kbmap2,
1872                              rc.secondary_kbmap.c_str());
1873         } else {
1874                 fl_set_input(dialog_->input_kbmap1, "");
1875                 fl_set_input(dialog_->input_kbmap2, "");
1876         }
1877
1878         fl_set_button(dialog_->check_rtl_support, rc.rtl_support);
1879         fl_set_button(dialog_->check_mark_foreign,
1880                       rc.mark_foreign_language);
1881         fl_set_button(dialog_->check_auto_begin, rc.language_auto_begin);
1882         fl_set_button(dialog_->check_auto_end, rc.language_auto_end);
1883         fl_set_button(dialog_->check_use_babel, rc.language_use_babel);
1884         fl_set_button(dialog_->check_global_options,
1885                       rc.language_global_options);
1886
1887         fl_set_input(dialog_->input_package,
1888                      rc.language_package.c_str());
1889         fl_set_input(dialog_->input_command_begin,
1890                      rc.language_command_begin.c_str());
1891         fl_set_input(dialog_->input_command_end,
1892                      rc.language_command_end.c_str());
1893
1894         // Activate/Deactivate the input fields dependent on the state of the
1895         // buttons.
1896         input(0);
1897 }
1898
1899
1900 FormPreferences::LnFmisc::LnFmisc(FormPreferences &  p)
1901         : parent_(p)
1902 {}
1903
1904
1905 FD_preferences_lnf_misc const * FormPreferences::LnFmisc::dialog()
1906 {
1907         return dialog_.get();
1908 }
1909
1910
1911 void FormPreferences::LnFmisc::apply(LyXRC & rc) const
1912 {
1913         rc.auto_region_delete =
1914                 fl_get_button(dialog_->check_auto_region_delete);
1915         rc.cursor_follows_scrollbar =
1916                 fl_get_button(dialog_->check_cursor_follows_scrollbar);
1917         rc.dialogs_iconify_with_main =
1918                 fl_get_button(dialog_->check_dialogs_iconify_with_main);
1919
1920         switch (fl_get_choice(dialog_->choice_instant_preview)) {
1921         case 1:
1922                 rc.preview = LyXRC::PREVIEW_OFF;
1923                 break;
1924         case 2:
1925                 rc.preview = LyXRC::PREVIEW_NO_MATH;
1926                 break;
1927         case 3:
1928                 rc.preview = LyXRC::PREVIEW_ON;
1929                 break;
1930         }
1931
1932         rc.autosave = static_cast<unsigned int>
1933                 (fl_get_counter_value(dialog_->counter_autosave));
1934         rc.wheel_jump = static_cast<unsigned int>
1935                 (fl_get_counter_value(dialog_->counter_wm_jump));
1936
1937         // See FIXME below
1938         // graphics::DisplayType old_value = rc.display_graphics;
1939         switch (fl_get_choice(dialog_->choice_graphics_display)) {
1940         case 4:
1941                 rc.display_graphics = graphics::NoDisplay;
1942                 break;
1943         case 3:
1944                 rc.display_graphics = graphics::ColorDisplay;
1945                 break;
1946         case 2:
1947                 rc.display_graphics = graphics::GrayscaleDisplay;
1948                 break;
1949         case 1:
1950                 rc.display_graphics = graphics::MonochromeDisplay;
1951                 break;
1952         default:
1953                 rc.display_graphics = graphics::ColorDisplay;
1954                 break;
1955         }
1956
1957 #ifdef WITH_WARNINGS
1958 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
1959 #endif
1960 #if 0
1961         if (old_value != rc.display_graphics) {
1962                 graphics::GCache & gc = graphics::GCache::get();
1963                 gc.changeDisplay();
1964         }
1965 #endif
1966 }
1967
1968
1969 void FormPreferences::LnFmisc::build()
1970 {
1971         dialog_.reset(build_preferences_lnf_misc(&parent_));
1972
1973         fl_set_counter_step(dialog_->counter_autosave, 1, 10);
1974         fl_set_counter_step(dialog_->counter_wm_jump, 1, 10);
1975
1976         fl_set_counter_return(dialog_->counter_autosave, FL_RETURN_CHANGED);
1977         fl_set_counter_return(dialog_->counter_wm_jump, FL_RETURN_CHANGED);
1978
1979         // set up the feedback mechanism
1980         setPrehandler(dialog_->check_auto_region_delete);
1981         setPrehandler(dialog_->counter_autosave);
1982         setPrehandler(dialog_->check_cursor_follows_scrollbar);
1983         setPrehandler(dialog_->check_dialogs_iconify_with_main);
1984         setPrehandler(dialog_->choice_instant_preview);
1985         setPrehandler(dialog_->counter_wm_jump);
1986
1987         fl_addto_choice(dialog_->choice_graphics_display,
1988                         _("Monochrome|Grayscale|Color|Do not display").c_str());
1989
1990         fl_addto_choice(dialog_->choice_instant_preview,
1991                         _("Off|No math|On").c_str());
1992 }
1993
1994
1995 string const
1996 FormPreferences::LnFmisc::feedback(FL_OBJECT const * const ob) const
1997 {
1998         if (ob == dialog_->check_auto_region_delete)
1999                 return LyXRC::getDescription(LyXRC::RC_AUTOREGIONDELETE);
2000         if (ob == dialog_->check_cursor_follows_scrollbar)
2001                 return LyXRC::getDescription(LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR);
2002         if (ob == dialog_->check_dialogs_iconify_with_main)
2003                 return LyXRC::getDescription(LyXRC::RC_DIALOGS_ICONIFY_WITH_MAIN);
2004         if (ob == dialog_->choice_instant_preview)
2005                 return LyXRC::getDescription(LyXRC::RC_PREVIEW);
2006         if (ob == dialog_->counter_autosave)
2007                 return LyXRC::getDescription(LyXRC::RC_AUTOSAVE);
2008         if (ob == dialog_->counter_wm_jump)
2009                 return LyXRC::getDescription(LyXRC::RC_WHEEL_JUMP);
2010         if (ob == dialog_->choice_graphics_display)
2011                 return LyXRC::getDescription(LyXRC::RC_DISPLAY_GRAPHICS);
2012         return string();
2013 }
2014
2015
2016 void FormPreferences::LnFmisc::update(LyXRC const & rc)
2017 {
2018         fl_set_button(dialog_->check_auto_region_delete,
2019                       rc.auto_region_delete);
2020         fl_set_button(dialog_->check_cursor_follows_scrollbar,
2021                       rc.cursor_follows_scrollbar);
2022         fl_set_button(dialog_->check_dialogs_iconify_with_main,
2023                       rc.dialogs_iconify_with_main);
2024
2025         switch (rc.preview) {
2026         case LyXRC::PREVIEW_OFF:
2027                 fl_set_choice(dialog_->choice_instant_preview, 1);
2028                 break;
2029         case LyXRC::PREVIEW_NO_MATH:
2030                 fl_set_choice(dialog_->choice_instant_preview, 2);
2031                 break;
2032         case LyXRC::PREVIEW_ON:
2033                 fl_set_choice(dialog_->choice_instant_preview, 3);
2034                 break;
2035         }
2036
2037         fl_set_counter_value(dialog_->counter_autosave, rc.autosave);
2038         fl_set_counter_value(dialog_->counter_wm_jump, rc.wheel_jump);
2039
2040         switch (rc.display_graphics) {
2041         case graphics::NoDisplay:
2042                 fl_set_choice(dialog_->choice_graphics_display, 4);
2043                 break;
2044         case graphics::ColorDisplay:
2045                 fl_set_choice(dialog_->choice_graphics_display, 3);
2046                 break;
2047         case graphics::GrayscaleDisplay:
2048                 fl_set_choice(dialog_->choice_graphics_display, 2);
2049                 break;
2050         case graphics::MonochromeDisplay:
2051                 fl_set_choice(dialog_->choice_graphics_display, 1);
2052                 break;
2053         default:
2054                 fl_set_choice(dialog_->choice_graphics_display, 3);
2055                 break;
2056         }
2057 }
2058
2059
2060 FormPreferences::OutputsMisc::OutputsMisc(FormPreferences &  p)
2061         : parent_(p)
2062 {}
2063
2064
2065 FD_preferences_outputs_misc const * FormPreferences::OutputsMisc::dialog()
2066 {
2067         return dialog_.get();
2068 }
2069
2070
2071 void FormPreferences::OutputsMisc::apply(LyXRC & rc) const
2072 {
2073         rc.ascii_linelen = static_cast<unsigned int>
2074                 (fl_get_counter_value(dialog_->counter_line_len));
2075         rc.fontenc = getString(dialog_->input_tex_encoding);
2076
2077         int const choice =
2078                 fl_get_choice(dialog_->choice_default_papersize) - 1;
2079         rc.default_papersize = parent_.controller().toPaperSize(choice);
2080
2081         rc.ascii_roff_command = getString(dialog_->input_ascii_roff);
2082         rc.chktex_command = getString(dialog_->input_checktex);
2083         rc.bibtex_command = getString(dialog_->input_bibtex);
2084         rc.index_command = getString(dialog_->input_index);
2085         rc.view_dvi_paper_option = getString(dialog_->input_paperoption);
2086         rc.auto_reset_options = fl_get_button(dialog_->check_autoreset_classopt);
2087
2088 #if defined(__CYGWIN__) || defined(_WIN32)
2089         rc.windows_style_tex_paths =
2090                 fl_get_button(dialog_->check_windows_style_tex_paths);
2091 #endif
2092 }
2093
2094
2095 void FormPreferences::OutputsMisc::build()
2096 {
2097         dialog_.reset(build_preferences_outputs_misc(&parent_));
2098
2099         fl_set_counter_step(dialog_->counter_line_len, 1, 10);
2100
2101         fl_set_counter_return(dialog_->counter_line_len, FL_RETURN_CHANGED);
2102         fl_set_input_return(dialog_->input_tex_encoding, FL_RETURN_CHANGED);
2103         fl_set_input_return(dialog_->input_ascii_roff,   FL_RETURN_CHANGED);
2104         fl_set_input_return(dialog_->input_bibtex,       FL_RETURN_CHANGED);
2105         fl_set_input_return(dialog_->input_checktex,     FL_RETURN_CHANGED);
2106         fl_set_input_return(dialog_->input_index,        FL_RETURN_CHANGED);
2107         fl_set_input_return(dialog_->input_paperoption,  FL_RETURN_CHANGED);
2108
2109 #if defined(__CYGWIN__) || defined(_WIN32)
2110 #else
2111         setEnabled(dialog_->check_windows_style_tex_paths, false);
2112 #endif
2113
2114         fl_addto_choice(dialog_->choice_default_papersize,
2115                         _(" default | US letter | US legal "
2116                           "| US executive | A3 | A4 | A5 | B5 ").c_str());
2117
2118         // set up the feedback mechanism
2119         setPrehandler(dialog_->counter_line_len);
2120         setPrehandler(dialog_->input_tex_encoding);
2121         setPrehandler(dialog_->choice_default_papersize);
2122         setPrehandler(dialog_->input_ascii_roff);
2123         setPrehandler(dialog_->input_bibtex);
2124         setPrehandler(dialog_->input_checktex);
2125         setPrehandler(dialog_->input_index);
2126         setPrehandler(dialog_->input_paperoption);
2127         setPrehandler(dialog_->check_autoreset_classopt);
2128 #if defined(__CYGWIN__) || defined(_WIN32)
2129         setPrehandler(dialog_->check_windows_style_tex_paths);
2130 #endif
2131 }
2132
2133
2134 string const
2135 FormPreferences::OutputsMisc::feedback(FL_OBJECT const * const ob) const
2136 {
2137         if (ob == dialog_->counter_line_len)
2138                 return LyXRC::getDescription(LyXRC::RC_ASCII_LINELEN);
2139         if (ob == dialog_->input_tex_encoding)
2140                 return LyXRC::getDescription(LyXRC::RC_FONT_ENCODING);
2141         if (ob == dialog_->input_ascii_roff)
2142                 return LyXRC::getDescription(LyXRC::RC_ASCIIROFF_COMMAND);
2143         if (ob == dialog_->input_bibtex)
2144                 return LyXRC::getDescription(LyXRC::RC_BIBTEX_COMMAND);
2145         if (ob == dialog_->input_checktex)
2146                 return LyXRC::getDescription(LyXRC::RC_CHKTEX_COMMAND);
2147         if (ob == dialog_->input_index)
2148                 return LyXRC::getDescription(LyXRC::RC_INDEX_COMMAND);
2149         if (ob == dialog_->choice_default_papersize)
2150                 return LyXRC::getDescription(LyXRC::RC_DEFAULT_PAPERSIZE);
2151         if (ob == dialog_->input_paperoption)
2152                 return LyXRC::getDescription(LyXRC::RC_VIEWDVI_PAPEROPTION);
2153         if (ob == dialog_->check_autoreset_classopt)
2154                 return LyXRC::getDescription(LyXRC::RC_AUTORESET_OPTIONS);
2155 #if defined(__CYGWIN__) || defined(_WIN32)
2156         if (ob == dialog_->check_windows_style_tex_paths)
2157                 return _("Select if LyX should output Windows-style paths "
2158                          "rather than Posix-style paths to LaTeX files. "
2159                          "Useful if you're using the native Windows MikTeX "
2160                          "rather than the Cygwin teTeX.");
2161 #endif
2162         return string();
2163 }
2164
2165
2166 void FormPreferences::OutputsMisc::update(LyXRC const & rc)
2167 {
2168         fl_set_counter_value(dialog_->counter_line_len,
2169                              rc.ascii_linelen);
2170         fl_set_input(dialog_->input_tex_encoding,
2171                      rc.fontenc.c_str());
2172         fl_set_choice(dialog_->choice_default_papersize,
2173                       parent_.controller().fromPaperSize(rc.default_papersize) + 1);
2174         fl_set_input(dialog_->input_ascii_roff,
2175                      rc.ascii_roff_command.c_str());
2176         fl_set_input(dialog_->input_checktex,
2177                      rc.chktex_command.c_str());
2178         fl_set_input(dialog_->input_bibtex,
2179                      rc.bibtex_command.c_str());
2180         fl_set_input(dialog_->input_index,
2181                      rc.index_command.c_str());
2182         fl_set_input(dialog_->input_paperoption,
2183                      rc.view_dvi_paper_option.c_str());
2184         fl_set_button(dialog_->check_autoreset_classopt,
2185                       rc.auto_reset_options);
2186 #if defined(__CYGWIN__) || defined(_WIN32)
2187         fl_set_button(dialog_->check_windows_style_tex_paths,
2188                       rc.windows_style_tex_paths);
2189 #endif
2190 }
2191
2192
2193 FormPreferences::Paths::Paths(FormPreferences &  p)
2194         : parent_(p)
2195 {}
2196
2197
2198 FD_preferences_paths const * FormPreferences::Paths::dialog()
2199 {
2200         return dialog_.get();
2201 }
2202
2203
2204 void FormPreferences::Paths::apply(LyXRC & rc)
2205 {
2206         rc.document_path = getString(dialog_->input_default_path);
2207         rc.template_path = getString(dialog_->input_template_path);
2208         rc.tempdir_path  = getString(dialog_->input_temp_dir);
2209         rc.path_prefix  = getString(dialog_->input_path_prefix);
2210
2211         int button = fl_get_button(dialog_->check_last_files);
2212         string str = getString(dialog_->input_lastfiles);
2213         if (!button) str.erase();
2214
2215         rc.check_lastfiles = button;
2216         rc.num_lastfiles = static_cast<unsigned int>
2217                 (fl_get_counter_value(dialog_->counter_lastfiles));
2218
2219         button = fl_get_button(dialog_->check_make_backups);
2220         str = getString(dialog_->input_backup_path);
2221         if (!button)
2222                 str.erase();
2223
2224         rc.make_backup = button;
2225         rc.backupdir_path = str;
2226
2227         rc.lyxpipes = getString(dialog_->input_serverpipe);
2228
2229         // update view
2230         update(rc);
2231 }
2232
2233
2234 void FormPreferences::Paths::build()
2235 {
2236         dialog_.reset(build_preferences_paths(&parent_));
2237
2238         fl_set_input_return(dialog_->input_default_path, FL_RETURN_CHANGED);
2239         fl_set_input_return(dialog_->input_template_path, FL_RETURN_CHANGED);
2240         fl_set_input_return(dialog_->input_temp_dir, FL_RETURN_CHANGED);
2241         fl_set_input_return(dialog_->input_path_prefix, FL_RETURN_CHANGED);
2242         fl_set_input_return(dialog_->input_lastfiles, FL_RETURN_CHANGED);
2243         fl_set_input_return(dialog_->input_backup_path, FL_RETURN_CHANGED);
2244         fl_set_counter_bounds(dialog_->counter_lastfiles, 0, maxlastfiles);
2245         fl_set_counter_return(dialog_->counter_lastfiles, FL_RETURN_CHANGED);
2246         fl_set_input_return(dialog_->input_serverpipe, FL_RETURN_CHANGED);
2247
2248         // set up the feedback mechanism
2249         setPrehandler(dialog_->input_default_path);
2250         setPrehandler(dialog_->counter_lastfiles);
2251         setPrehandler(dialog_->input_template_path);
2252         setPrehandler(dialog_->input_path_prefix);
2253         setPrehandler(dialog_->check_last_files);
2254         setPrehandler(dialog_->input_lastfiles);
2255         setPrehandler(dialog_->check_make_backups);
2256         setPrehandler(dialog_->input_backup_path);
2257         setPrehandler(dialog_->input_serverpipe);
2258         setPrehandler(dialog_->input_temp_dir);
2259 }
2260
2261
2262 string const
2263 FormPreferences::Paths::feedback(FL_OBJECT const * const ob) const
2264 {
2265         if (ob == dialog_->input_default_path)
2266                 return LyXRC::getDescription(LyXRC::RC_DOCUMENTPATH);
2267         if (ob == dialog_->input_template_path)
2268                 return LyXRC::getDescription(LyXRC::RC_TEMPLATEPATH);
2269         if (ob == dialog_->input_temp_dir)
2270                 return LyXRC::getDescription(LyXRC::RC_TEMPDIRPATH);
2271         if (ob == dialog_->check_last_files)
2272                 return LyXRC::getDescription(LyXRC::RC_CHECKLASTFILES);
2273         if (ob == dialog_->counter_lastfiles)
2274                 return LyXRC::getDescription(LyXRC::RC_NUMLASTFILES);
2275         if (ob == dialog_->check_make_backups)
2276                 return LyXRC::getDescription(LyXRC::RC_MAKE_BACKUP);
2277         if (ob == dialog_->input_backup_path)
2278                 return LyXRC::getDescription(LyXRC::RC_BACKUPDIR_PATH);
2279         if (ob == dialog_->input_serverpipe)
2280                 return LyXRC::getDescription(LyXRC::RC_SERVERPIPE);
2281         if (ob == dialog_->input_path_prefix)
2282                 return LyXRC::getDescription(LyXRC::RC_PATH_PREFIX);
2283         return string();
2284 }
2285
2286
2287 bool FormPreferences::Paths::input(FL_OBJECT const * const ob)
2288 {
2289         bool activate = true;
2290
2291         // !ob if function is called from Paths::update() to de/activate
2292         // objects,
2293         // otherwise the function is called by an xforms CB via input().
2294         if (!ob || ob == dialog_->check_last_files) {
2295                 bool const enable = fl_get_button(dialog_->check_last_files);
2296                 setEnabled(dialog_->input_lastfiles, enable);
2297         }
2298
2299         if (!ob || ob == dialog_->check_make_backups) {
2300                 bool const enable = fl_get_button(dialog_->check_make_backups);
2301                 setEnabled(dialog_->input_backup_path, enable);
2302         }
2303
2304         if (!ob || ob == dialog_->input_default_path) {
2305                 string const name = getString(dialog_->input_default_path);
2306                 if (!name.empty() && !RWInfo::WriteableDir(name)) {
2307                         parent_.postWarning(RWInfo::ErrorMessage());
2308                         return false;
2309                 }
2310         }
2311
2312         if (!ob || ob == dialog_->input_template_path) {
2313                 string const name = getString(dialog_->input_template_path);
2314                 if (!name.empty() && !RWInfo::ReadableDir(name)) {
2315                         parent_.postWarning(RWInfo::ErrorMessage());
2316                         return false;
2317                 }
2318         }
2319
2320         if (!ob || ob == dialog_->input_temp_dir) {
2321                 string const name = getString(dialog_->input_temp_dir);
2322                 if (fl_get_button(dialog_->check_make_backups)
2323                     && !name.empty()
2324                     && !RWInfo::WriteableDir(name)) {
2325                         parent_.postWarning(RWInfo::ErrorMessage());
2326                         return false;
2327                 }
2328         }
2329
2330         if (!ob || ob == dialog_->input_backup_path) {
2331                 string const name = getString(dialog_->input_backup_path);
2332                 if (fl_get_button(dialog_->check_make_backups)
2333                     && !name.empty()
2334                     && !RWInfo::WriteableDir(name)) {
2335                         parent_.postWarning(RWInfo::ErrorMessage());
2336                         return false;
2337                 }
2338         }
2339
2340         if (!ob || ob == dialog_->input_lastfiles) {
2341                 string const name = getString(dialog_->input_lastfiles);
2342                 if (fl_get_button(dialog_->check_last_files)
2343                     && !name.empty()
2344                     && !RWInfo::WriteableFile(name)) {
2345                         parent_.postWarning(RWInfo::ErrorMessage());
2346                         return false;
2347                 }
2348         }
2349
2350         if (!ob || ob == dialog_->input_serverpipe) {
2351                 string const name = getString(dialog_->input_serverpipe);
2352                 if (!name.empty()) {
2353                         // strip off the extension
2354                         string const str = changeExtension(name, "");
2355                         if (!RWInfo::WriteableFile(str + ".in")) {
2356                                 parent_.postWarning(RWInfo::ErrorMessage());
2357                                 return false;
2358                         }
2359                         if (!RWInfo::WriteableFile(str + ".out")) {
2360                                 parent_.postWarning(RWInfo::ErrorMessage());
2361                                 return false;
2362                         }
2363                 }
2364         }
2365
2366         if (ob == dialog_->button_default_path_browse) {
2367                 string f = parent_.controller().browsedir(
2368                         getString(dialog_->input_default_path), _("Default path"));
2369                 if (!f.empty())
2370                         fl_set_input(dialog_->input_default_path, f.c_str());
2371         } else if (ob == dialog_->button_template_path_browse) {
2372                 string f = parent_.controller().browsedir(
2373                         getString(dialog_->input_template_path), _("Template path"));
2374                 if (!f.empty())
2375                         fl_set_input(dialog_->input_template_path, f.c_str());
2376         } else if (ob == dialog_->button_temp_dir_browse) {
2377                 string f = parent_.controller().browsedir(
2378                         getString(dialog_->input_temp_dir), _("Temporary dir"));
2379                 if (!f.empty())
2380                         fl_set_input(dialog_->input_temp_dir, f.c_str());
2381         } else if (ob == dialog_->button_lastfiles_browse) {
2382                 string f = parent_.controller().browse(
2383                         getString(dialog_->input_lastfiles), _("Last files"));
2384                 if (!f.empty())
2385                         fl_set_input(dialog_->input_lastfiles, f.c_str());
2386         } else if (ob == dialog_->button_backup_path_browse) {
2387                 string f = parent_.controller().browsedir(
2388                         getString(dialog_->input_backup_path), _("Backup path"));
2389                 if (!f.empty())
2390                         fl_set_input(dialog_->input_backup_path, f.c_str());
2391         } else if (ob == dialog_->button_serverpipe_browse) {
2392                 string f = parent_.controller().browse(
2393                         getString(dialog_->input_serverpipe), _("LyX server pipes"));
2394                 if (!f.empty())
2395                         fl_set_input(dialog_->input_serverpipe, f.c_str());
2396         }
2397
2398         return activate;
2399 }
2400
2401
2402 void FormPreferences::Paths::update(LyXRC const & rc)
2403 {
2404         fl_set_input(dialog_->input_default_path,
2405                      rc.document_path.c_str());
2406         fl_set_input(dialog_->input_template_path,
2407                      rc.template_path.c_str());
2408
2409         string str;
2410         if (rc.make_backup)
2411                 str = rc.backupdir_path;
2412
2413         fl_set_button(dialog_->check_make_backups,
2414                       rc.make_backup);
2415         fl_set_input(dialog_->input_backup_path, str.c_str());
2416
2417         fl_set_input(dialog_->input_temp_dir, rc.tempdir_path.c_str());
2418         fl_set_input(dialog_->input_path_prefix, rc.path_prefix.c_str());
2419
2420         fl_set_button(dialog_->check_last_files,
2421                       rc.check_lastfiles);
2422         fl_set_counter_value(dialog_->counter_lastfiles,
2423                              rc.num_lastfiles);
2424
2425         fl_set_input(dialog_->input_serverpipe, rc.lyxpipes.c_str());
2426
2427         // Activate/Deactivate the input fields dependent on the state of the
2428         // buttons.
2429         input(0);
2430 }
2431
2432
2433 FormPreferences::Printer::Printer(FormPreferences &  p)
2434         : parent_(p)
2435 {}
2436
2437
2438 FD_preferences_printer const * FormPreferences::Printer::dialog()
2439 {
2440         return dialog_.get();
2441 }
2442
2443
2444 void FormPreferences::Printer::apply(LyXRC & rc) const
2445 {
2446         rc.print_adapt_output = fl_get_button(dialog_->check_adapt_output);
2447         rc.print_command = getString(dialog_->input_command);
2448         rc.print_pagerange_flag = getString(dialog_->input_page_range);
2449         rc.print_copies_flag = getString(dialog_->input_copies);
2450         rc.print_reverse_flag = getString(dialog_->input_reverse);
2451         rc.print_to_printer = getString(dialog_->input_to_printer);
2452         rc.print_file_extension =
2453                 getString(dialog_->input_file_extension);
2454         rc.print_spool_command =
2455                 getString(dialog_->input_spool_command);
2456         rc.print_paper_flag = getString(dialog_->input_paper_type);
2457         rc.print_evenpage_flag = getString(dialog_->input_even_pages);
2458         rc.print_oddpage_flag = getString(dialog_->input_odd_pages);
2459         rc.print_collcopies_flag = getString(dialog_->input_collated);
2460         rc.print_landscape_flag = getString(dialog_->input_landscape);
2461         rc.print_to_file = getString(dialog_->input_to_file);
2462         rc.print_extra_options =
2463                 getString(dialog_->input_extra_options);
2464         rc.print_spool_printerprefix =
2465                 getString(dialog_->input_spool_prefix);
2466         rc.print_paper_dimension_flag =
2467                 getString(dialog_->input_paper_size);
2468         rc.printer = getString(dialog_->input_name);
2469 }
2470
2471
2472 string const
2473 FormPreferences::Printer::feedback(FL_OBJECT const * const ob) const
2474 {
2475         if (ob == dialog_->input_command)
2476                 return LyXRC::getDescription(LyXRC::RC_PRINT_COMMAND);
2477         if (ob == dialog_->check_adapt_output)
2478                 return LyXRC::getDescription(LyXRC::RC_PRINT_ADAPTOUTPUT);
2479         if (ob == dialog_->input_to_printer)
2480                 return LyXRC::getDescription(LyXRC::RC_PRINTTOPRINTER);
2481         if (ob == dialog_->input_to_file)
2482                 return LyXRC::getDescription(LyXRC::RC_PRINTTOFILE);
2483         if (ob == dialog_->input_file_extension)
2484                 return LyXRC::getDescription(LyXRC::RC_PRINTFILEEXTENSION);
2485         if (ob == dialog_->input_extra_options)
2486                 return LyXRC::getDescription(LyXRC::RC_PRINTEXSTRAOPTIONS);
2487         if (ob == dialog_->input_spool_command)
2488                 return LyXRC::getDescription(LyXRC::RC_PRINTSPOOL_COMMAND);
2489         if (ob == dialog_->input_spool_prefix)
2490                 return LyXRC::getDescription(LyXRC::RC_PRINTSPOOL_PRINTERPREFIX);
2491         if (ob == dialog_->input_name)
2492                 return LyXRC::getDescription(LyXRC::RC_PRINTER);
2493         if (ob == dialog_->input_even_pages)
2494                 return LyXRC::getDescription(LyXRC::RC_PRINTEVENPAGEFLAG);
2495         if (ob == dialog_->input_odd_pages)
2496                 return LyXRC::getDescription(LyXRC::RC_PRINTODDPAGEFLAG);
2497         if (ob == dialog_->input_page_range)
2498                 return LyXRC::getDescription(LyXRC::RC_PRINTPAGERANGEFLAG);
2499         if (ob == dialog_->input_reverse)
2500                 return LyXRC::getDescription(LyXRC::RC_PRINTREVERSEFLAG);
2501         if (ob == dialog_->input_landscape)
2502                 return LyXRC::getDescription(LyXRC::RC_PRINTLANDSCAPEFLAG);
2503         if (ob == dialog_->input_copies)
2504                 return LyXRC::getDescription(LyXRC::RC_PRINTCOPIESFLAG);
2505         if (ob == dialog_->input_collated)
2506                 return LyXRC::getDescription(LyXRC::RC_PRINTCOLLCOPIESFLAG);
2507         if (ob == dialog_->input_paper_type)
2508                 return LyXRC::getDescription(LyXRC::RC_PRINTPAPERFLAG);
2509         if (ob == dialog_->input_paper_size)
2510                 return LyXRC::getDescription(LyXRC::RC_PRINTPAPERDIMENSIONFLAG);
2511         return string();
2512 }
2513
2514
2515 void FormPreferences::Printer::build()
2516 {
2517         dialog_.reset(build_preferences_printer(&parent_));
2518
2519         fl_set_input_return(dialog_->input_command, FL_RETURN_CHANGED);
2520         fl_set_input_return(dialog_->input_page_range, FL_RETURN_CHANGED);
2521         fl_set_input_return(dialog_->input_copies, FL_RETURN_CHANGED);
2522         fl_set_input_return(dialog_->input_reverse, FL_RETURN_CHANGED);
2523         fl_set_input_return(dialog_->input_to_printer, FL_RETURN_CHANGED);
2524         fl_set_input_return(dialog_->input_file_extension, FL_RETURN_CHANGED);
2525         fl_set_input_return(dialog_->input_spool_command, FL_RETURN_CHANGED);
2526         fl_set_input_return(dialog_->input_paper_type, FL_RETURN_CHANGED);
2527         fl_set_input_return(dialog_->input_even_pages, FL_RETURN_CHANGED);
2528         fl_set_input_return(dialog_->input_odd_pages, FL_RETURN_CHANGED);
2529         fl_set_input_return(dialog_->input_collated, FL_RETURN_CHANGED);
2530         fl_set_input_return(dialog_->input_landscape, FL_RETURN_CHANGED);
2531         fl_set_input_return(dialog_->input_to_file, FL_RETURN_CHANGED);
2532         fl_set_input_return(dialog_->input_extra_options, FL_RETURN_CHANGED);
2533         fl_set_input_return(dialog_->input_spool_prefix, FL_RETURN_CHANGED);
2534         fl_set_input_return(dialog_->input_paper_size, FL_RETURN_CHANGED);
2535         fl_set_input_return(dialog_->input_name, FL_RETURN_CHANGED);
2536
2537         // set up the feedback mechanism
2538         setPrehandler(dialog_->input_command);
2539         setPrehandler(dialog_->input_page_range);
2540         setPrehandler(dialog_->input_copies);
2541         setPrehandler(dialog_->input_reverse);
2542         setPrehandler(dialog_->input_to_printer);
2543         setPrehandler(dialog_->input_file_extension);
2544         setPrehandler(dialog_->input_spool_command);
2545         setPrehandler(dialog_->input_paper_type);
2546         setPrehandler(dialog_->input_even_pages);
2547         setPrehandler(dialog_->input_odd_pages);
2548         setPrehandler(dialog_->input_collated);
2549         setPrehandler(dialog_->input_landscape);
2550         setPrehandler(dialog_->input_to_file);
2551         setPrehandler(dialog_->input_extra_options);
2552         setPrehandler(dialog_->input_spool_prefix);
2553         setPrehandler(dialog_->input_paper_size);
2554         setPrehandler(dialog_->input_name);
2555         setPrehandler(dialog_->check_adapt_output);
2556 }
2557
2558
2559 void FormPreferences::Printer::update(LyXRC const & rc)
2560 {
2561         fl_set_button(dialog_->check_adapt_output,
2562                       rc.print_adapt_output);
2563         fl_set_input(dialog_->input_command,
2564                      rc.print_command.c_str());
2565         fl_set_input(dialog_->input_page_range,
2566                      rc.print_pagerange_flag.c_str());
2567         fl_set_input(dialog_->input_copies,
2568                      rc.print_copies_flag.c_str());
2569         fl_set_input(dialog_->input_reverse,
2570                      rc.print_reverse_flag.c_str());
2571         fl_set_input(dialog_->input_to_printer,
2572                      rc.print_to_printer.c_str());
2573         fl_set_input(dialog_->input_file_extension,
2574                      rc.print_file_extension.c_str());
2575         fl_set_input(dialog_->input_spool_command,
2576                      rc.print_spool_command.c_str());
2577         fl_set_input(dialog_->input_paper_type,
2578                      rc.print_paper_flag.c_str());
2579         fl_set_input(dialog_->input_even_pages,
2580                      rc.print_evenpage_flag.c_str());
2581         fl_set_input(dialog_->input_odd_pages,
2582                      rc.print_oddpage_flag.c_str());
2583         fl_set_input(dialog_->input_collated,
2584                      rc.print_collcopies_flag.c_str());
2585         fl_set_input(dialog_->input_landscape,
2586                      rc.print_landscape_flag.c_str());
2587         fl_set_input(dialog_->input_to_file,
2588                      rc.print_to_file.c_str());
2589         fl_set_input(dialog_->input_extra_options,
2590                      rc.print_extra_options.c_str());
2591         fl_set_input(dialog_->input_spool_prefix,
2592                      rc.print_spool_printerprefix.c_str());
2593         fl_set_input(dialog_->input_paper_size,
2594                      rc.print_paper_dimension_flag.c_str());
2595         fl_set_input(dialog_->input_name,
2596                      rc.printer.c_str());
2597 }
2598
2599
2600 FormPreferences::ScreenFonts::ScreenFonts(FormPreferences &  p)
2601         : parent_(p)
2602 {}
2603
2604
2605 FD_preferences_screen_fonts const * FormPreferences::ScreenFonts::dialog()
2606 {
2607         return dialog_.get();
2608 }
2609
2610
2611 void FormPreferences::ScreenFonts::apply(LyXRC & rc) const
2612 {
2613         bool changed = false;
2614
2615         pair<string, string> tmp =
2616                 parseFontName(getString(dialog_->input_roman));
2617         if (rc.roman_font_name != tmp.first ||
2618             rc.roman_font_foundry != tmp.second) {
2619                 changed = true;
2620                 rc.roman_font_name = tmp.first;
2621                 rc.roman_font_foundry = tmp.second;
2622         }
2623
2624         tmp = parseFontName(getString(dialog_->input_sans));
2625         if (rc.sans_font_name != tmp.first ||
2626             rc.sans_font_foundry != tmp.second) {
2627                 changed = true;
2628                 rc.sans_font_name = tmp.first;
2629                 rc.sans_font_foundry = tmp.second;
2630         }
2631
2632         tmp = parseFontName(getString(dialog_->input_typewriter));
2633         if (rc.typewriter_font_name != tmp.first ||
2634             rc.typewriter_font_foundry != tmp.second) {
2635                 changed = true;
2636                 rc.typewriter_font_name = tmp.first;
2637                 rc.typewriter_font_foundry = tmp.second;
2638         }
2639
2640         string str = getString(dialog_->input_screen_encoding);
2641         if (rc.font_norm != str) {
2642                 changed = true;
2643                 rc.font_norm = str;
2644                 rc.set_font_norm_type();
2645         }
2646
2647         bool button = fl_get_button(dialog_->check_scalable);
2648         if (rc.use_scalable_fonts != button) {
2649                 changed = true;
2650                 rc.use_scalable_fonts = button;
2651         }
2652
2653         unsigned int ivalue = static_cast<unsigned int>
2654                 (fl_get_counter_value(dialog_->counter_zoom));
2655         if (rc.zoom != ivalue) {
2656                 changed = true;
2657                 rc.zoom = ivalue;
2658         }
2659
2660         ivalue = static_cast<unsigned int>
2661                 (fl_get_counter_value(dialog_->counter_dpi));
2662         if (rc.dpi != ivalue) {
2663                 changed = true;
2664                 rc.dpi = ivalue;
2665         }
2666
2667         string dvalue = getString(dialog_->input_tiny);
2668         if (rc.font_sizes[LyXFont::SIZE_TINY] != dvalue) {
2669                 changed = true;
2670                 rc.font_sizes[LyXFont::SIZE_TINY] = dvalue;
2671         }
2672
2673         dvalue = getString(dialog_->input_script);
2674         if (rc.font_sizes[LyXFont::SIZE_SCRIPT] != dvalue) {
2675                 changed = true;
2676                 rc.font_sizes[LyXFont::SIZE_SCRIPT] = dvalue;
2677         }
2678
2679         dvalue = getString(dialog_->input_footnote);
2680         if (rc.font_sizes[LyXFont::SIZE_FOOTNOTE] != dvalue) {
2681                 changed = true;
2682                 rc.font_sizes[LyXFont::SIZE_FOOTNOTE] = dvalue;
2683         }
2684
2685         dvalue = getString(dialog_->input_small);
2686         if (rc.font_sizes[LyXFont::SIZE_SMALL] != dvalue) {
2687                 changed = true;
2688                 rc.font_sizes[LyXFont::SIZE_SMALL] = dvalue;
2689         }
2690
2691         dvalue = getString(dialog_->input_normal);
2692         if (rc.font_sizes[LyXFont::SIZE_NORMAL] != dvalue) {
2693                 changed = true;
2694                 rc.font_sizes[LyXFont::SIZE_NORMAL] = dvalue;
2695         }
2696
2697         dvalue = getString(dialog_->input_large);
2698         if (rc.font_sizes[LyXFont::SIZE_LARGE] != dvalue) {
2699                 changed = true;
2700                 rc.font_sizes[LyXFont::SIZE_LARGE] = dvalue;
2701         }
2702
2703         dvalue = getString(dialog_->input_larger);
2704         if (rc.font_sizes[LyXFont::SIZE_LARGER] != dvalue) {
2705                 changed = true;
2706                 rc.font_sizes[LyXFont::SIZE_LARGER] = dvalue;
2707         }
2708
2709         dvalue = getString(dialog_->input_largest);
2710         if (rc.font_sizes[LyXFont::SIZE_LARGEST] != dvalue) {
2711                 changed = true;
2712                 rc.font_sizes[LyXFont::SIZE_LARGEST] = dvalue;
2713         }
2714
2715         dvalue = getString(dialog_->input_huge);
2716         if (rc.font_sizes[LyXFont::SIZE_HUGE] != dvalue) {
2717                 changed = true;
2718                 rc.font_sizes[LyXFont::SIZE_HUGE] = dvalue;
2719         }
2720
2721         dvalue = getString(dialog_->input_huger);
2722         if (rc.font_sizes[LyXFont::SIZE_HUGER] != dvalue) {
2723                 changed = true;
2724                 rc.font_sizes[LyXFont::SIZE_HUGER] = dvalue;
2725         }
2726
2727         if (changed) {
2728                 // Now update the buffers
2729                 // Can anything below here affect the redraw process?
2730                 parent_.controller().updateScreenFonts();
2731         }
2732 }
2733
2734
2735 void FormPreferences::ScreenFonts::build()
2736 {
2737         dialog_.reset(build_preferences_screen_fonts(&parent_));
2738
2739         fl_set_counter_step(dialog_->counter_zoom, 1, 10);
2740         fl_set_counter_step(dialog_->counter_dpi,  1, 10);
2741
2742         fl_set_input_return(dialog_->input_roman,           FL_RETURN_CHANGED);
2743         fl_set_input_return(dialog_->input_sans,            FL_RETURN_CHANGED);
2744         fl_set_input_return(dialog_->input_typewriter,      FL_RETURN_CHANGED);
2745         fl_set_input_return(dialog_->input_screen_encoding, FL_RETURN_CHANGED);
2746         fl_set_counter_return(dialog_->counter_zoom,        FL_RETURN_CHANGED);
2747         fl_set_counter_return(dialog_->counter_dpi,         FL_RETURN_CHANGED);
2748         fl_set_input_return(dialog_->input_tiny,            FL_RETURN_CHANGED);
2749         fl_set_input_return(dialog_->input_script,          FL_RETURN_CHANGED);
2750         fl_set_input_return(dialog_->input_footnote,        FL_RETURN_CHANGED);
2751         fl_set_input_return(dialog_->input_small,           FL_RETURN_CHANGED);
2752         fl_set_input_return(dialog_->input_normal,          FL_RETURN_CHANGED);
2753         fl_set_input_return(dialog_->input_large,           FL_RETURN_CHANGED);
2754         fl_set_input_return(dialog_->input_larger,          FL_RETURN_CHANGED);
2755         fl_set_input_return(dialog_->input_largest,         FL_RETURN_CHANGED);
2756         fl_set_input_return(dialog_->input_huge,            FL_RETURN_CHANGED);
2757         fl_set_input_return(dialog_->input_huger,           FL_RETURN_CHANGED);
2758
2759         fl_set_input_filter(dialog_->input_tiny,     fl_unsigned_float_filter);
2760         fl_set_input_filter(dialog_->input_script,   fl_unsigned_float_filter);
2761         fl_set_input_filter(dialog_->input_footnote, fl_unsigned_float_filter);
2762         fl_set_input_filter(dialog_->input_small,    fl_unsigned_float_filter);
2763         fl_set_input_filter(dialog_->input_normal,   fl_unsigned_float_filter);
2764         fl_set_input_filter(dialog_->input_large,    fl_unsigned_float_filter);
2765         fl_set_input_filter(dialog_->input_larger,   fl_unsigned_float_filter);
2766         fl_set_input_filter(dialog_->input_largest,  fl_unsigned_float_filter);
2767         fl_set_input_filter(dialog_->input_huge,     fl_unsigned_float_filter);
2768         fl_set_input_filter(dialog_->input_huger,    fl_unsigned_float_filter);
2769
2770         // set up the feedback mechanism
2771         setPrehandler(dialog_->input_roman);
2772         setPrehandler(dialog_->input_sans);
2773         setPrehandler(dialog_->input_typewriter);
2774         setPrehandler(dialog_->counter_zoom);
2775         setPrehandler(dialog_->counter_dpi);
2776         setPrehandler(dialog_->check_scalable);
2777         setPrehandler(dialog_->input_screen_encoding);
2778         setPrehandler(dialog_->input_tiny);
2779         setPrehandler(dialog_->input_script);
2780         setPrehandler(dialog_->input_footnote);
2781         setPrehandler(dialog_->input_small);
2782         setPrehandler(dialog_->input_large);
2783         setPrehandler(dialog_->input_larger);
2784         setPrehandler(dialog_->input_largest);
2785         setPrehandler(dialog_->input_normal);
2786         setPrehandler(dialog_->input_huge);
2787         setPrehandler(dialog_->input_huger);
2788 }
2789
2790
2791 string const
2792 FormPreferences::ScreenFonts::feedback(FL_OBJECT const * const ob) const
2793 {
2794         if (ob == dialog_->input_roman)
2795                 return LyXRC::getDescription(LyXRC::RC_SCREEN_FONT_ROMAN);
2796         if (ob == dialog_->input_sans)
2797                 return LyXRC::getDescription(LyXRC::RC_SCREEN_FONT_SANS);
2798         if (ob == dialog_->input_typewriter)
2799                 return LyXRC::getDescription(LyXRC::RC_SCREEN_FONT_TYPEWRITER);
2800         if (ob == dialog_->check_scalable)
2801                 return LyXRC::getDescription(LyXRC::RC_SCREEN_FONT_SCALABLE);
2802         if (ob == dialog_->input_screen_encoding)
2803                 return LyXRC::getDescription(LyXRC::RC_SCREEN_FONT_ENCODING);
2804         if (ob == dialog_->counter_zoom)
2805                 return LyXRC::getDescription(LyXRC::RC_SCREEN_ZOOM);
2806         if (ob == dialog_->counter_dpi)
2807                 return LyXRC::getDescription(LyXRC::RC_SCREEN_DPI);
2808         if (ob == dialog_->input_tiny
2809             || ob == dialog_->input_script
2810             || ob == dialog_->input_footnote
2811             || ob == dialog_->input_small
2812             || ob == dialog_->input_large
2813             || ob == dialog_->input_larger
2814             || ob == dialog_->input_larger
2815             || ob == dialog_->input_largest
2816             || ob == dialog_->input_normal
2817             || ob == dialog_->input_huge
2818             || ob == dialog_->input_huger)
2819                 return LyXRC::getDescription(LyXRC::RC_SCREEN_FONT_SIZES);
2820         return string();
2821 }
2822
2823
2824 bool FormPreferences::ScreenFonts::input()
2825 {
2826         bool activate = true;
2827         string str;
2828
2829         // Make sure that all fonts all have positive entries
2830         // Also note that an empty entry is returned as 0.0 by strToDbl
2831         if (0.0 >= convert<double>(fl_get_input(dialog_->input_tiny))
2832             || 0.0 >= convert<double>(fl_get_input(dialog_->input_script))
2833             || 0.0 >= convert<double>(fl_get_input(dialog_->input_footnote))
2834             || 0.0 >= convert<double>(fl_get_input(dialog_->input_small))
2835             || 0.0 >= convert<double>(fl_get_input(dialog_->input_normal))
2836             || 0.0 >= convert<double>(fl_get_input(dialog_->input_large))
2837             || 0.0 >= convert<double>(fl_get_input(dialog_->input_larger))
2838             || 0.0 >= convert<double>(fl_get_input(dialog_->input_largest))
2839             || 0.0 >= convert<double>(fl_get_input(dialog_->input_huge))
2840             || 0.0 >= convert<double>(fl_get_input(dialog_->input_huger))) {
2841                 activate = false;
2842                 str = _("Fonts must be positive!");
2843         } else if (convert<double>(fl_get_input(dialog_->input_tiny)) >
2844                    // Fontsizes -- tiny < script < footnote etc.
2845                    convert<double>(fl_get_input(dialog_->input_script)) ||
2846                    convert<double>(fl_get_input(dialog_->input_script)) >
2847                    convert<double>(fl_get_input(dialog_->input_footnote)) ||
2848                    convert<double>(fl_get_input(dialog_->input_footnote)) >
2849                    convert<double>(fl_get_input(dialog_->input_small)) ||
2850                    convert<double>(fl_get_input(dialog_->input_small)) >
2851                    convert<double>(fl_get_input(dialog_->input_normal)) ||
2852                    convert<double>(fl_get_input(dialog_->input_normal)) >
2853                    convert<double>(fl_get_input(dialog_->input_large)) ||
2854                    convert<double>(fl_get_input(dialog_->input_large)) >
2855                    convert<double>(fl_get_input(dialog_->input_larger)) ||
2856                    convert<double>(fl_get_input(dialog_->input_larger)) >
2857                    convert<double>(fl_get_input(dialog_->input_largest)) ||
2858                    convert<double>(fl_get_input(dialog_->input_largest)) >
2859                    convert<double>(fl_get_input(dialog_->input_huge)) ||
2860                    convert<double>(fl_get_input(dialog_->input_huge)) >
2861                    convert<double>(fl_get_input(dialog_->input_huger))) {
2862                 activate = false;
2863
2864                 str = _("Fonts must be input in the order Tiny > Smallest > Smaller > Small > Normal > Large > Larger > Largest > Huge > Huger.");
2865         }
2866
2867         if (!activate)
2868                 parent_.postWarning(str);
2869
2870         return activate;
2871 }
2872
2873
2874 void FormPreferences::ScreenFonts::update(LyXRC const & rc)
2875 {
2876         fl_set_input(dialog_->input_roman,
2877                      makeFontName(rc.roman_font_name,
2878                                   rc.roman_font_foundry).c_str());
2879         fl_set_input(dialog_->input_sans,
2880                      makeFontName(rc.sans_font_name,
2881                                   rc.sans_font_foundry).c_str());
2882         fl_set_input(dialog_->input_typewriter,
2883                      makeFontName(rc.typewriter_font_name,
2884                                   rc.typewriter_font_foundry).c_str());
2885         fl_set_input(dialog_->input_screen_encoding,
2886                      rc.font_norm.c_str());
2887         fl_set_button(dialog_->check_scalable,
2888                       rc.use_scalable_fonts);
2889         fl_set_counter_value(dialog_->counter_zoom, rc.zoom);
2890         fl_set_counter_value(dialog_->counter_dpi,  rc.dpi);
2891         fl_set_input(dialog_->input_tiny,
2892                      rc.font_sizes[LyXFont::SIZE_TINY].c_str());
2893         fl_set_input(dialog_->input_script,
2894                      rc.font_sizes[LyXFont::SIZE_SCRIPT].c_str());
2895         fl_set_input(dialog_->input_footnote,
2896                      rc.font_sizes[LyXFont::SIZE_FOOTNOTE].c_str());
2897         fl_set_input(dialog_->input_small,
2898                      rc.font_sizes[LyXFont::SIZE_SMALL].c_str());
2899         fl_set_input(dialog_->input_normal,
2900                      rc.font_sizes[LyXFont::SIZE_NORMAL].c_str());
2901         fl_set_input(dialog_->input_large,
2902                      rc.font_sizes[LyXFont::SIZE_LARGE].c_str());
2903         fl_set_input(dialog_->input_larger,
2904                      rc.font_sizes[LyXFont::SIZE_LARGER].c_str());
2905         fl_set_input(dialog_->input_largest,
2906                      rc.font_sizes[LyXFont::SIZE_LARGEST].c_str());
2907         fl_set_input(dialog_->input_huge,
2908                      rc.font_sizes[LyXFont::SIZE_HUGE].c_str());
2909         fl_set_input(dialog_->input_huger,
2910                      rc.font_sizes[LyXFont::SIZE_HUGER].c_str());
2911 }
2912
2913
2914
2915 FormPreferences::SpellOptions::SpellOptions(FormPreferences &  p)
2916         : parent_(p)
2917 {}
2918
2919
2920 FD_preferences_spelloptions const * FormPreferences::SpellOptions::dialog()
2921 {
2922         return dialog_.get();
2923 }
2924
2925
2926 void FormPreferences::SpellOptions::apply(LyXRC & rc)
2927 {
2928         string choice = fl_get_choice_text(dialog_->choice_spell_command);
2929         choice = trim(choice);
2930
2931         rc.isp_command = choice;
2932
2933 #if 0
2934         // If spellchecker == "", all other input set to off.
2935         if (fl_get_choice(dialog_->choice_spell_command) == 1) {
2936                 rc.isp_use_alt_lang = false;
2937                 rc.isp_alt_lang.erase();
2938
2939                 rc.isp_use_esc_chars = false;
2940                 rc.isp_esc_chars.erase();
2941
2942                 rc.isp_use_pers_dict = false;
2943                 rc.isp_pers_dict.erase();
2944
2945                 rc.isp_accept_compound = false;
2946                 rc.isp_use_input_encoding = false;
2947         } else {
2948 #else
2949                 int button = fl_get_button(dialog_->check_alt_lang);
2950                 choice = getString(dialog_->input_alt_lang);
2951                 if (button && choice.empty()) button = 0;
2952                 if (!button) choice.erase();
2953
2954                 rc.isp_use_alt_lang = static_cast<bool>(button);
2955                 rc.isp_alt_lang = choice;
2956
2957                 button = fl_get_button(dialog_->check_escape_chars);
2958                 choice = getString(dialog_->input_escape_chars);
2959                 if (button && choice.empty()) button = 0;
2960                 if (!button) choice.erase();
2961
2962                 rc.isp_use_esc_chars = static_cast<bool>(button);
2963                 rc.isp_esc_chars = choice;
2964
2965                 button = fl_get_button(dialog_->check_personal_dict);
2966                 choice = getString(dialog_->input_personal_dict);
2967                 if (button && choice.empty()) button = 0;
2968                 if (!button) choice.erase();
2969
2970                 rc.isp_use_pers_dict = static_cast<bool>(button);
2971                 rc.isp_pers_dict = choice;
2972
2973                 button = fl_get_button(dialog_->check_compound_words);
2974                 rc.isp_accept_compound = static_cast<bool>(button);
2975
2976                 button = fl_get_button(dialog_->check_input_enc);
2977                 rc.isp_use_input_encoding = static_cast<bool>(button);
2978 #endif
2979 #if 0
2980         }
2981 #endif
2982
2983         // Reset view
2984         update(rc);
2985 }
2986
2987
2988 void FormPreferences::SpellOptions::build()
2989 {
2990         dialog_.reset(build_preferences_spelloptions(&parent_));
2991
2992         fl_addto_choice(dialog_->choice_spell_command,
2993                         _(" ispell | aspell ").c_str());
2994         fl_set_input_return(dialog_->input_alt_lang,      FL_RETURN_CHANGED);
2995         fl_set_input_return(dialog_->input_escape_chars,  FL_RETURN_CHANGED);
2996         fl_set_input_return(dialog_->input_personal_dict, FL_RETURN_CHANGED);
2997
2998 #if !defined (USE_ISPELL)
2999         setEnabled(dialog_->choice_spell_command, false);
3000 #endif
3001
3002         // set up the feedback mechanism
3003         setPrehandler(dialog_->choice_spell_command);
3004         setPrehandler(dialog_->check_alt_lang);
3005         setPrehandler(dialog_->input_alt_lang);
3006         setPrehandler(dialog_->check_escape_chars);
3007         setPrehandler(dialog_->input_escape_chars);
3008         setPrehandler(dialog_->check_personal_dict);
3009         setPrehandler(dialog_->input_personal_dict);
3010         setPrehandler(dialog_->button_personal_dict);
3011         setPrehandler(dialog_->check_compound_words);
3012         setPrehandler(dialog_->check_input_enc);
3013 }
3014
3015
3016 string const
3017 FormPreferences::SpellOptions::feedback(FL_OBJECT const * const ob) const
3018 {
3019         if (ob == dialog_->choice_spell_command)
3020                 return LyXRC::getDescription(LyXRC::RC_SPELL_COMMAND);
3021         if (ob == dialog_->check_alt_lang)
3022                 return LyXRC::getDescription(LyXRC::RC_USE_ALT_LANG);
3023         if (ob == dialog_->input_alt_lang)
3024                 return LyXRC::getDescription(LyXRC::RC_ALT_LANG);
3025         if (ob == dialog_->check_escape_chars)
3026                 return LyXRC::getDescription(LyXRC::RC_USE_ESC_CHARS);
3027         if (ob == dialog_->input_escape_chars)
3028                 return LyXRC::getDescription(LyXRC::RC_ESC_CHARS);
3029         if (ob == dialog_->check_personal_dict)
3030                 return LyXRC::getDescription(LyXRC::RC_USE_PERS_DICT);
3031         if (ob == dialog_->input_personal_dict)
3032                 return LyXRC::getDescription(LyXRC::RC_PERS_DICT);
3033         if (ob == dialog_->check_compound_words)
3034                 return LyXRC::getDescription(LyXRC::RC_ACCEPT_COMPOUND);
3035         if (ob == dialog_->check_input_enc)
3036                 return LyXRC::getDescription(LyXRC::RC_USE_INP_ENC);
3037         return string();
3038 }
3039
3040
3041 bool FormPreferences::SpellOptions::input(FL_OBJECT const * const ob)
3042 {
3043         // !ob if function is called from updateSpellOptions() to de/activate
3044         // objects,
3045         // otherwise the function is called by an xforms CB via input().
3046
3047 #if 0
3048         // If spellchecker == "", disable all input.
3049         if (!ob || ob == dialog_->choice_spell_command) {
3050                 if (fl_get_choice(dialog_->choice_spell_command) == 1) {
3051                         fl_deactivate_object(dialog_->check_alt_lang);
3052                         fl_deactivate_object(dialog_->input_alt_lang);
3053                         fl_deactivate_object(dialog_->check_escape_chars);
3054                         fl_deactivate_object(dialog_->input_escape_chars);
3055                         fl_deactivate_object(dialog_->check_personal_dict);
3056                         fl_deactivate_object(dialog_->input_personal_dict);
3057                         fl_deactivate_object(dialog_->check_compound_words);
3058                         fl_deactivate_object(dialog_->check_input_enc);
3059                         return true;
3060                 } else {
3061                         fl_activate_object(dialog_->check_alt_lang);
3062                         fl_activate_object(dialog_->check_escape_chars);
3063                         fl_activate_object(dialog_->check_personal_dict);
3064                         fl_activate_object(dialog_->check_compound_words);
3065                         fl_activate_object(dialog_->check_input_enc);
3066                 }
3067         }
3068 #endif
3069
3070         if (!ob || ob == dialog_->check_alt_lang) {
3071                 bool const enable = fl_get_button(dialog_->check_alt_lang);
3072                 setEnabled(dialog_->input_alt_lang, enable);
3073         }
3074
3075         if (!ob || ob == dialog_->check_escape_chars) {
3076                 bool const enable = fl_get_button(dialog_->check_escape_chars);
3077                 setEnabled(dialog_->input_escape_chars, enable);
3078         }
3079
3080         if (!ob || ob == dialog_->check_personal_dict) {
3081                 bool const enable = fl_get_button(dialog_->check_personal_dict);
3082                 setEnabled(dialog_->input_personal_dict, enable);
3083         }
3084
3085         if (ob == dialog_->button_personal_dict) {
3086                 string f = parent_.controller().browsedict(
3087                         getString(dialog_->input_personal_dict));
3088                 fl_set_input(dialog_->input_personal_dict, f.c_str());
3089         }
3090
3091         return true; // All input is valid!
3092 }
3093
3094
3095 void FormPreferences::SpellOptions::update(LyXRC const & rc)
3096 {
3097         int choice = 1;
3098 #if 0
3099         if (rc.isp_command == "")
3100                 choice = 1;
3101         else if (rc.isp_command == "ispell")
3102                 choice = 2;
3103         else if (rc.isp_command == "aspell")
3104                 choice = 3;
3105 #else
3106         if (rc.isp_command == "ispell")
3107                 choice = 1;
3108         else if (rc.isp_command == "aspell")
3109                 choice = 2;
3110 #endif
3111         fl_set_choice(dialog_->choice_spell_command, choice);
3112
3113         string str;
3114         if (rc.isp_use_alt_lang)
3115                 str = rc.isp_alt_lang;
3116
3117         fl_set_button(dialog_->check_alt_lang,
3118                       rc.isp_use_alt_lang);
3119         fl_set_input(dialog_->input_alt_lang, str.c_str());
3120
3121         str.erase();
3122         if (rc.isp_use_esc_chars)
3123                 str = rc.isp_esc_chars;
3124
3125         fl_set_button(dialog_->check_escape_chars,
3126                       rc.isp_use_esc_chars);
3127         fl_set_input(dialog_->input_escape_chars, str.c_str());
3128
3129         str.erase();
3130         if (rc.isp_use_pers_dict)
3131                 str = rc.isp_pers_dict;
3132
3133         fl_set_button(dialog_->check_personal_dict,
3134                       rc.isp_use_pers_dict);
3135         fl_set_input(dialog_->input_personal_dict, str.c_str());
3136
3137         fl_set_button(dialog_->check_compound_words,
3138                       rc.isp_accept_compound);
3139         fl_set_button(dialog_->check_input_enc,
3140                       rc.isp_use_input_encoding);
3141
3142         // Activate/Deactivate the input fields dependent on the state of the
3143         // buttons.
3144         input(0);
3145 }
3146
3147 } // namespace frontend
3148 } // namespace lyx