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