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