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