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