]> git.lyx.org Git - features.git/blob - src/frontends/xforms/FormPreferences.C
91f47461c20c333ae940472531be78b33c789716
[features.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
14 #include "ControlPrefs.h"
15 #include "FormPreferences.h"
16 #include "forms/form_preferences.h"
17 #include "xformsBC.h"
18 #include "ButtonController.h"
19
20 #include "Color.h"
21 #include "input_validators.h"
22 #include "forms_gettext.h"
23 #include "xforms_helpers.h"
24 #include "helper_funcs.h" // getSecond
25
26 #include "buffer.h"
27 #include "converter.h"
28 #include "format.h"
29 #include "debug.h"
30 #include "language.h"
31 #include "frnt_lang.h"
32 #include "lyxlex.h"
33 #include "lyxrc.h"
34 #include "LColor.h"
35 #include "Lsstream.h"
36 #include "funcrequest.h"
37 #include "author.h"
38
39 #include "support/lyxfunctional.h"
40 #include "support/lyxmanip.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) + string(", ") + tostr(s) + string(", ") +
661                 tostr(v);
662         fl_set_object_label(dialog_->text_color_values, label.c_str());
663
664         RGBColor col = HSVColor(hue, sat, val);
665
666         fl_freeze_form(dialog_->form);
667
668         fl_mapcolor(GUI_COLOR_CHOICE, col.r, col.g, col.b);
669         fl_redraw_object(dialog_->button_color);
670
671         col = HSVColor(hue, 1.0, 1.0);
672         col.r = max(col.r, 0u);
673         fl_mapcolor(GUI_COLOR_HUE_DIAL, col.r, col.g, col.b);
674         fl_redraw_object(dialog_->dial_hue);
675
676         // Ascertain whether to activate the Modify button.
677         vector<NamedColor>::size_type const selLyX =
678                 fl_get_browser(dialog_->browser_lyx_objs);
679
680         fl_unfreeze_form(dialog_->form);
681         if (selLyX < 1) return;
682
683         fl_getmcolor(GUI_COLOR_CHOICE, &col.r, &col.g, &col.b);
684         bool modify = false;
685
686         // Is the choice an Xforms color...
687         if (selLyX - 1 < xformsColorDB.size()) {
688                 vector<XformsColor>::size_type const i = selLyX - 1;
689                 modify = (xformsColorDB[i].color() != col);
690         }
691         // or a LyX Logical color?
692         else {
693                 vector<NamedColor>::size_type const i = selLyX - 1 -
694                         xformsColorDB.size();
695                 modify = (lyxColorDB[i].color() != col);
696         }
697
698         setEnabled(dialog_->button_modify, modify);
699 }
700
701
702 void FormPreferences::Colors::InputRGB()
703 {
704         int const red   = int(fl_get_slider_value(dialog_->slider_red));
705         int const green = int(fl_get_slider_value(dialog_->slider_green));
706         int const blue  = int(fl_get_slider_value(dialog_->slider_blue));
707
708         string const label = tostr(red) + string(", ") + tostr(green) +
709                 string(", ") + tostr(blue);
710         fl_set_object_label(dialog_->text_color_values, label.c_str());
711
712         fl_freeze_form(dialog_->form);
713
714         RGBColor col = RGBColor(red, green, blue);
715         fl_mapcolor(GUI_COLOR_CHOICE, col.r, col.g, col.b);
716         fl_redraw_object(dialog_->button_color);
717
718         // Ascertain whether to activate the Modify button.
719         vector<NamedColor>::size_type const selLyX =
720                 fl_get_browser(dialog_->browser_lyx_objs);
721
722         fl_unfreeze_form(dialog_->form);
723         if (selLyX < 1) return;
724
725         bool modify = false;
726
727         // Is the choice an Xforms color...
728         if (selLyX - 1 < xformsColorDB.size()) {
729                 vector<XformsColor>::size_type const i = selLyX - 1;
730                 modify = (xformsColorDB[i].color() != col);
731         }
732         // or a LyX Logical color?
733         else {
734                 vector<NamedColor>::size_type const i = selLyX - 1 -
735                         xformsColorDB.size();
736                 modify = (lyxColorDB[i].color() != col);
737         }
738
739         setEnabled(dialog_->button_modify, modify);
740 }
741
742
743 void FormPreferences::Colors::LoadBrowserLyX()
744 {
745         if (!dialog_->browser_lyx_objs->visible)
746                 return;
747
748         // First, define the modifiable xforms colors
749         xformsColorDB.clear();
750         XformsColor xcol;
751
752         xcol.name = _("GUI background");
753         xcol.colorID = FL_COL1;
754         fl_getmcolor(FL_COL1, &xcol.r, &xcol.g, &xcol.b);
755
756         xformsColorDB.push_back(xcol);
757
758         xcol.name = _("GUI text");
759         xcol.colorID = FL_BLACK;
760         fl_getmcolor(FL_BLACK, &xcol.r, &xcol.g, &xcol.b);
761
762         xformsColorDB.push_back(xcol);
763
764         xcol.name = _("GUI selection");
765         xcol.colorID = FL_YELLOW;
766         fl_getmcolor(FL_YELLOW, &xcol.r, &xcol.g, &xcol.b);
767
768         xformsColorDB.push_back(xcol);
769
770         xcol.name = _("GUI pointer");
771         xcol.colorID = GUI_COLOR_CURSOR;
772         fl_getmcolor(GUI_COLOR_CURSOR, &xcol.r, &xcol.g, &xcol.b);
773
774         xformsColorDB.push_back(xcol);
775
776         // Now create the the LyX LColors database
777         lyxColorDB.clear();
778         for (int i=0; i<LColor::ignore; ++i) {
779                 LColor::color lc = static_cast<LColor::color>(i);
780                 if (lc == LColor::none
781                     || lc == LColor::black
782                     || lc == LColor::white
783                     || lc == LColor::red
784                     || lc == LColor::green
785                     || lc == LColor::blue
786                     || lc == LColor::cyan
787                     || lc == LColor::magenta
788                     || lc == LColor::yellow
789                     || lc == LColor::inherit
790                     || lc == LColor::ignore) continue;
791
792                 RGBColor col;
793                 bool const success = getRGBColor(lc, col.r, col.g, col.b);
794                 if (!success) {
795                         lyxerr << "FormPreferences::Colors::LoadBrowserLyX:\n"
796                                << "LColor " << lcolor.getLyXName(lc)
797                                << ": X can't find color \""
798                                << lcolor.getX11Name(lc)
799                                << "\". Set to \"black\"!" << endl;
800
801                         string const arg = lcolor.getLyXName(lc) + " black";
802                         parent_.controller().setColor(lc, "black");
803                         continue;
804                 }
805
806                 // Create a valid X11 name of the form "#rrggbb" and change the
807                 // LColor X11name to this. Don't want to trigger a redraw,
808                 // as we're just changing the name not the RGB values.
809                 // Also reset the system_lcolor names, so that we don't output
810                 // unnecessary changes.
811                 string const hexname = X11hexname(col);
812
813                 if (lcolor.getX11Name(lc) != hexname) {
814                         lcolor.setColor(lc, hexname);
815                         system_lcolor.setColor(lc, hexname);
816                 }
817
818                 // Finally, push the color onto the database
819                 NamedColor ncol(lcolor.getGUIName(lc), col);
820                 lyxColorDB.push_back(ncol);
821         }
822
823         // Now construct the browser
824         FL_OBJECT * colbr = dialog_->browser_lyx_objs;
825         fl_freeze_form(dialog_->form);
826         fl_clear_browser(colbr);
827         for (vector<XformsColor>::const_iterator cit = xformsColorDB.begin();
828              cit != xformsColorDB.end(); ++cit) {
829                 fl_addto_browser(colbr, cit->getname().c_str());
830         }
831         for (vector<NamedColor>::const_iterator cit = lyxColorDB.begin();
832              cit != lyxColorDB.end(); ++cit) {
833                 fl_addto_browser(colbr, cit->getname().c_str());
834         }
835
836         // just to be safe...
837         fl_set_browser_topline(dialog_->browser_lyx_objs, 1);
838         fl_select_browser_line(dialog_->browser_lyx_objs, 1);
839         fl_unfreeze_form(dialog_->form);
840
841         InputBrowserLyX();
842 }
843
844
845 void FormPreferences::Colors::Modify()
846 {
847         vector<NamedColor>::size_type const selLyX =
848                 fl_get_browser(dialog_->browser_lyx_objs);
849         if (selLyX < 1)
850                 return;
851
852         RGBColor col;
853         fl_getmcolor(GUI_COLOR_CHOICE, &col.r, &col.g, &col.b);
854
855         // Is the choice an Xforms color...
856         if (selLyX - 1 < xformsColorDB.size()) {
857                 vector<XformsColor>::size_type const i = selLyX - 1;
858                 xformsColorDB[i].r  = col.r;
859                 xformsColorDB[i].g  = col.g;
860                 xformsColorDB[i].b  = col.b;
861         }
862         // or a LyX Logical color?
863         else {
864                 vector<NamedColor>::size_type const i = selLyX - 1 -
865                         xformsColorDB.size();
866                 lyxColorDB[i].r  = col.r;
867                 lyxColorDB[i].g  = col.g;
868                 lyxColorDB[i].b  = col.b;
869         }
870
871         fl_freeze_form(dialog_->form);
872         setEnabled(dialog_->button_modify, false);
873         fl_unfreeze_form(dialog_->form);
874 }
875
876
877 void FormPreferences::Colors::SwitchColorSpace() const
878 {
879         bool const hsv = fl_get_button(dialog_->radio_hsv);
880
881         RGBColor col;
882         fl_getmcolor(GUI_COLOR_CHOICE, &col.r, &col.g, &col.b);
883
884         fl_freeze_form(dialog_->form);
885
886         if (hsv) {
887                 fl_hide_object(dialog_->slider_red);
888                 fl_hide_object(dialog_->slider_blue);
889                 fl_hide_object(dialog_->slider_green);
890                 fl_show_object(dialog_->dial_hue);
891                 fl_show_object(dialog_->slider_saturation);
892                 fl_show_object(dialog_->slider_value);
893
894                 HSVColor hsv = HSVColor(col);
895                 hsv.h = max(hsv.h, 0.0);
896
897                 fl_set_dial_value(dialog_->dial_hue, hsv.h);
898                 fl_set_slider_value(dialog_->slider_saturation, hsv.s);
899                 fl_set_slider_value(dialog_->slider_value, hsv.v);
900
901                 col = HSVColor(hsv.h, 1.0, 1.0);
902                 col.r = max(col.r, 0u);
903                 fl_mapcolor(GUI_COLOR_HUE_DIAL, col.r, col.g, col.b);
904                 fl_redraw_object(dialog_->dial_hue);
905
906                 // Adjust the label a bit, but not the actual values.
907                 // Means that toggling from one space to the other has no
908                 // effect on the final color.
909                 int const h = int(hsv.h);
910                 int const s = int(100 * hsv.s);
911                 int const v = int(100 * hsv.v);
912                 string const label = tostr(h) + ", " + tostr(s) +
913                         ", " + tostr(v);
914                 fl_set_object_label(dialog_->text_color_values, label.c_str());
915
916         } else {
917                 fl_show_object(dialog_->slider_red);
918                 fl_show_object(dialog_->slider_blue);
919                 fl_show_object(dialog_->slider_green);
920                 fl_hide_object(dialog_->dial_hue);
921                 fl_hide_object(dialog_->slider_saturation);
922                 fl_hide_object(dialog_->slider_value);
923
924                 fl_set_slider_value(dialog_->slider_red,   col.r);
925                 fl_set_slider_value(dialog_->slider_green, col.g);
926                 fl_set_slider_value(dialog_->slider_blue,  col.b);
927
928                 // Adjust the label a bit. Same reasoning as above.
929                 int const r = int(col.r);
930                 int const g = int(col.g);
931                 int const b = int(col.b);
932                 string const label = tostr(r) + ", " + tostr(g) +
933                         ", " + tostr(b);
934                 fl_set_object_label(dialog_->text_color_values, label.c_str());
935         }
936
937         fl_unfreeze_form(dialog_->form);
938 }
939
940
941 FormPreferences::Converters::Converters(FormPreferences & p)
942         : parent_(p)
943 {}
944
945
946 FD_preferences_converters const * FormPreferences::Converters::dialog()
947 {
948         return dialog_.get();
949 }
950
951
952 void FormPreferences::Converters::apply() const
953 {
954         parent_.controller().setConverters(local_converters);
955 }
956
957
958 void FormPreferences::Converters::build()
959 {
960         dialog_.reset(build_preferences_converters(&parent_));
961
962         fl_set_input_return(dialog_->input_converter, FL_RETURN_CHANGED);
963         fl_set_input_return(dialog_->input_flags, FL_RETURN_CHANGED);
964
965         // set up the feedback mechanism
966         setPrehandler(dialog_->browser_all);
967         setPrehandler(dialog_->button_delete);
968         setPrehandler(dialog_->button_add);
969         setPrehandler(dialog_->input_converter);
970         setPrehandler(dialog_->choice_from);
971         setPrehandler(dialog_->choice_to);
972         setPrehandler(dialog_->input_flags);
973 }
974
975
976 string const
977 FormPreferences::Converters::feedback(FL_OBJECT const * const ob) const
978 {
979         if (ob == dialog_->browser_all)
980                 return _("All the currently defined converters known to LyX.");
981
982         if (ob == dialog_->choice_from)
983                 return _("Convert \"from\" this format");
984
985         if (ob == dialog_->choice_to)
986                 return _("Convert \"to\" this format");
987
988         if (ob == dialog_->input_converter)
989                 return _("The conversion command. $$i is the input file name, "
990                          "$$b is the file name without its extension and $$o is "
991                          "the name of the output file. $$s can be used as path to "
992                          "LyX's own collection of conversion scripts.");
993
994         if (ob == dialog_->input_flags)
995                 return _("Extra information for the Converter class, whether and "
996                          "how to parse the result, and various other things.");
997
998         if (ob == dialog_->button_delete)
999                 return _("Remove the current converter from the list of available "
1000                          "converters. Note: you must then \"Apply\" the change.");
1001
1002         if (ob == dialog_->button_add) {
1003                 if (string(ob->label) == _("Add"))
1004                         return _("Add the current converter to the list of available "
1005                                  "converters. Note: you must then \"Apply\" the change.");
1006                 else
1007                         return _("Modify the contents of the current converter. "
1008                                  "Note: you must then \"Apply\" the change.");
1009         }
1010
1011         return string();
1012 }
1013
1014
1015 bool FormPreferences::Converters::input(FL_OBJECT const * const ob)
1016 {
1017         if (ob == dialog_->browser_all)
1018                 return Browser();
1019
1020         if (ob == dialog_->choice_from
1021             || ob == dialog_->choice_to
1022             || ob == dialog_->input_converter
1023             || ob == dialog_->input_flags)
1024                 return Input();
1025
1026         if (ob == dialog_->button_add)
1027                 return Add();
1028
1029         if (ob == dialog_->button_delete)
1030                 return erase();
1031
1032         return true;
1033 }
1034
1035
1036 void FormPreferences::Converters::update()
1037 {
1038         local_converters = converters;
1039         local_converters.update(local_formats);
1040         UpdateBrowser();
1041 }
1042
1043
1044 void FormPreferences::Converters::UpdateBrowser()
1045 {
1046         local_converters.sort();
1047
1048         fl_freeze_form(dialog_->form);
1049         fl_clear_browser(dialog_->browser_all);
1050         for (::Converters::const_iterator cit = local_converters.begin();
1051              cit != local_converters.end(); ++cit) {
1052                 string const name = cit->From->prettyname() + " -> "
1053                         + cit->To->prettyname();
1054                 fl_addto_browser(dialog_->browser_all, name.c_str());
1055         }
1056         Input();
1057         fl_unfreeze_form(dialog_->form);
1058 }
1059
1060
1061 bool FormPreferences::Converters::Add()
1062 {
1063         string const from = GetFrom();
1064         string const to = GetTo();
1065         string const command = fl_get_input(dialog_->input_converter);
1066         string const flags = fl_get_input(dialog_->input_flags);
1067
1068         Converter const * old = local_converters.getConverter(from, to);
1069         local_converters.add(from, to, command, flags);
1070         if (!old) {
1071                 local_converters.updateLast(local_formats);
1072                 UpdateBrowser();
1073         }
1074         setEnabled(dialog_->button_add, false);
1075
1076         return true;
1077 }
1078
1079
1080 bool FormPreferences::Converters::Browser()
1081 {
1082         int const i = fl_get_browser(dialog_->browser_all);
1083         if (i <= 0) return false;
1084
1085         fl_freeze_form(dialog_->form);
1086
1087         Converter const & c = local_converters.get(i - 1);
1088         int j = local_formats.getNumber(c.from);
1089         if (j >= 0)
1090                 fl_set_choice(dialog_->choice_from, j + 1);
1091
1092         j = local_formats.getNumber(c.to);
1093         if (j >= 0)
1094                 fl_set_choice(dialog_->choice_to, j + 1);
1095
1096         fl_set_input(dialog_->input_converter, c.command.c_str());
1097         fl_set_input(dialog_->input_flags, c.flags.c_str());
1098
1099         fl_set_object_label(dialog_->button_add, idex(_("Modify|#M")).c_str());
1100         fl_set_button_shortcut(dialog_->button_add,
1101                                scex(_("Modify|#M")).c_str(), 1);
1102
1103         setEnabled(dialog_->button_add,    false);
1104         setEnabled(dialog_->button_delete, true);
1105
1106         fl_unfreeze_form(dialog_->form);
1107         return false;
1108 }
1109
1110
1111 bool FormPreferences::Converters::erase()
1112 {
1113         string const from = GetFrom();
1114         string const to = GetTo();
1115
1116         local_converters.erase(from, to);
1117         UpdateBrowser();
1118         return true;
1119 }
1120
1121
1122 bool FormPreferences::Converters::Input()
1123 {
1124         string const from = GetFrom();
1125         string const to = GetTo();
1126         int const sel = local_converters.getNumber(from, to);
1127
1128         fl_freeze_form(dialog_->form);
1129
1130         if (sel < 0) {
1131                 fl_set_object_label(dialog_->button_add,
1132                                     idex(_("Add|#A")).c_str());
1133                 fl_set_button_shortcut(dialog_->button_add,
1134                                        scex(_("Add|#A")).c_str(), 1);
1135
1136                 fl_deselect_browser(dialog_->browser_all);
1137                 setEnabled(dialog_->button_delete, false);
1138
1139         } else {
1140                 fl_set_object_label(dialog_->button_add,
1141                                     idex(_("Modify|#M")).c_str());
1142                 fl_set_button_shortcut(dialog_->button_add,
1143                                        scex(_("Modify|#M")).c_str(), 1);
1144
1145                 int top = max(sel-5, 0);
1146                 fl_set_browser_topline(dialog_->browser_all, top);
1147                 fl_select_browser_line(dialog_->browser_all, sel+1);
1148                 setEnabled(dialog_->button_delete, true);
1149         }
1150
1151         string const command = rtrim(fl_get_input(dialog_->input_converter));
1152         bool const enable = !(command.empty() || from == to);
1153         setEnabled(dialog_->button_add, enable);
1154
1155         fl_unfreeze_form(dialog_->form);
1156         return false;
1157 }
1158
1159
1160 string const FormPreferences::Converters::GetFrom() const
1161 {
1162         ::Formats::FormatList::size_type const i =
1163                   fl_get_choice(dialog_->choice_from);
1164
1165         if (i > 0 && i <= local_formats.size())
1166                 return local_formats.get(i - 1).name();
1167
1168         lyxerr << "FormPreferences::Converters::GetFrom: No choice!" << endl;
1169         return "???";
1170 }
1171
1172
1173 string const FormPreferences::Converters::GetTo() const
1174 {
1175         ::Formats::FormatList::size_type const i =
1176                   fl_get_choice(dialog_->choice_to);
1177
1178         if (i > 0 && i <= local_formats.size())
1179                 return local_formats.get(i - 1).name();
1180
1181         lyxerr << "FormPreferences::Converters::GetTo: No choice!" << endl;
1182         return "???";
1183 }
1184
1185
1186 void FormPreferences::Converters::UpdateChoices() const
1187 {
1188         string choice;
1189         for (::Formats::const_iterator cit = local_formats.begin();
1190              cit != local_formats.end(); ++cit) {
1191                 if (!choice.empty())
1192                         choice += " | ";
1193                 else
1194                         choice += ' ';
1195                 choice += cit->prettyname();
1196         }
1197         choice += ' ';
1198
1199         fl_clear_choice(dialog_->choice_from);
1200         fl_addto_choice(dialog_->choice_from, choice.c_str());
1201
1202         fl_clear_choice(dialog_->choice_to);
1203         fl_addto_choice(dialog_->choice_to, choice.c_str());
1204 }
1205
1206
1207 FormPreferences::Formats::Formats(FormPreferences &  p)
1208         : parent_(p)
1209 {}
1210
1211
1212 FD_preferences_formats const * FormPreferences::Formats::dialog()
1213 {
1214         return dialog_.get();
1215 }
1216
1217
1218 void FormPreferences::Formats::apply() const
1219 {
1220         parent_.controller().setFormats(local_formats);
1221 }
1222
1223
1224 void FormPreferences::Formats::build()
1225 {
1226         dialog_.reset(build_preferences_formats(&parent_));
1227
1228         fl_set_input_return(dialog_->input_format, FL_RETURN_CHANGED);
1229         fl_set_input_return(dialog_->input_viewer, FL_RETURN_CHANGED);
1230         fl_set_input_return(dialog_->input_shrtcut, FL_RETURN_CHANGED);
1231         fl_set_input_return(dialog_->input_gui_name, FL_RETURN_CHANGED);
1232         fl_set_input_return(dialog_->input_extension, FL_RETURN_CHANGED);
1233
1234         fl_set_input_filter(dialog_->input_format, fl_lowercase_filter);
1235
1236         // set up the feedback mechanism
1237         setPrehandler(dialog_->browser_all);
1238         setPrehandler(dialog_->input_format);
1239         setPrehandler(dialog_->input_gui_name);
1240         setPrehandler(dialog_->button_delete);
1241         setPrehandler(dialog_->button_add);
1242         setPrehandler(dialog_->input_extension);
1243         setPrehandler(dialog_->input_viewer);
1244         setPrehandler(dialog_->input_shrtcut);
1245 }
1246
1247
1248 string const
1249 FormPreferences::Formats::feedback(FL_OBJECT const * const ob) const
1250 {
1251         if (ob == dialog_->browser_all)
1252                 return  _("All the currently defined formats known to LyX.");
1253
1254         if (ob == dialog_->input_format)
1255                 return  _("The format identifier.");
1256
1257         if (ob == dialog_->input_gui_name)
1258                 return  _("The format name as it will appear in the menus.");
1259
1260         if (ob == dialog_->input_shrtcut)
1261                 return  _("The keyboard accelerator. Use a letter in the GUI name. "
1262                           "Case sensitive.");
1263
1264         if (ob == dialog_->input_extension)
1265                 return  _("Used to recognize the file. E.g., ps, pdf, tex.");
1266
1267         if (ob == dialog_->input_viewer)
1268                 return  _("The command used to launch the viewer application.");
1269
1270         if (ob == dialog_->button_delete)
1271                 return  _("Remove the current format from the list of available "
1272                           "formats. Note: you must then \"Apply\" the change.");
1273
1274         if (ob == dialog_->button_add) {
1275                 if (string(ob->label) == _("Add"))
1276                         return  _("Add the current format to the list of available "
1277                                   "formats. Note: you must then \"Apply\" the change.");
1278                 else
1279                         return  _("Modify the contents of the current format. Note: "
1280                                   "you must then \"Apply\" the change.");
1281         }
1282
1283         return string();
1284 }
1285
1286
1287 bool FormPreferences::Formats::input(FL_OBJECT const * const ob)
1288 {
1289         if (ob == dialog_->browser_all)
1290                 return Browser();
1291
1292         if (ob == dialog_->input_format
1293             || ob == dialog_->input_gui_name
1294             || ob == dialog_->input_shrtcut
1295             || ob == dialog_->input_extension
1296             || ob == dialog_->input_viewer)
1297                 return Input();
1298
1299         if (ob == dialog_->button_add)
1300                 return Add();
1301
1302         if (ob == dialog_->button_delete)
1303                 return erase();
1304
1305         return false;
1306 }
1307
1308
1309 void FormPreferences::Formats::update()
1310 {
1311         local_formats = formats;
1312         UpdateBrowser();
1313 }
1314
1315
1316 void FormPreferences::Formats::UpdateBrowser()
1317 {
1318         local_formats.sort();
1319
1320         fl_freeze_form(dialog_->form);
1321         fl_deselect_browser(dialog_->browser_all);
1322         fl_clear_browser(dialog_->browser_all);
1323         for (::Formats::const_iterator cit = local_formats.begin();
1324              cit != local_formats.end(); ++cit)
1325                 fl_addto_browser(dialog_->browser_all,
1326                                  cit->prettyname().c_str());
1327
1328         Input();
1329         fl_unfreeze_form(dialog_->form);
1330
1331         // Mustn't forget to update the Formats available to the converters_
1332         parent_.converters_.UpdateChoices();
1333         local_converters.update(local_formats);
1334 }
1335
1336
1337 bool FormPreferences::Formats::Add()
1338 {
1339         string const name = fl_get_input(dialog_->input_format);
1340         string const prettyname = fl_get_input(dialog_->input_gui_name);
1341         string const extension = fl_get_input(dialog_->input_extension);
1342         string const shortcut =  fl_get_input(dialog_->input_shrtcut);
1343         string const viewer =  fl_get_input(dialog_->input_viewer);
1344
1345         Format const * old = local_formats.getFormat(name);
1346         string const old_prettyname = old ? old->prettyname() : string();
1347         local_formats.add(name, extension, prettyname, shortcut);
1348         local_formats.setViewer(name, viewer);
1349         if (!old || prettyname != old_prettyname) {
1350                 UpdateBrowser();
1351                 if (old)
1352                         parent_.converters_.UpdateBrowser();
1353         }
1354         setEnabled(dialog_->button_add, false);
1355
1356         return true;
1357 }
1358
1359
1360 bool FormPreferences::Formats::Browser()
1361 {
1362         int const i = fl_get_browser(dialog_->browser_all);
1363         if (i <= 0)
1364                 return false;
1365
1366         fl_freeze_form(dialog_->form);
1367
1368         Format const & f = local_formats.get(i - 1);
1369
1370         fl_set_input(dialog_->input_format, f.name().c_str());
1371         fl_set_input(dialog_->input_gui_name, f.prettyname().c_str());
1372         fl_set_input(dialog_->input_shrtcut, f.shortcut().c_str());
1373         fl_set_input(dialog_->input_extension, f.extension().c_str());
1374         fl_set_input(dialog_->input_viewer, f.viewer().c_str());
1375
1376         fl_set_object_label(dialog_->button_add,
1377                             idex(_("Modify|#M")).c_str());
1378         fl_set_button_shortcut(dialog_->button_add,
1379                                scex(_("Modify|#M")).c_str(), 1);
1380
1381         setEnabled(dialog_->button_add,    false);
1382         setEnabled(dialog_->button_delete, true);
1383
1384         fl_unfreeze_form(dialog_->form);
1385         return false;
1386 }
1387
1388
1389 bool FormPreferences::Formats::erase()
1390 {
1391         string const name = fl_get_input(dialog_->input_format);
1392
1393         if (local_converters.formatIsUsed(name)) {
1394                 parent_.postWarning(_("Cannot remove a Format used by a Converter. "
1395                                       "Remove the converter first."));
1396                 setEnabled(dialog_->button_delete, false);
1397                 return false;
1398         }
1399
1400         local_formats.erase(name);
1401         UpdateBrowser();
1402         return true;
1403 }
1404
1405
1406 bool FormPreferences::Formats::Input()
1407 {
1408         string const name = fl_get_input(dialog_->input_format);
1409         int const sel = local_formats.getNumber(name);
1410         fl_freeze_form(dialog_->form);
1411
1412         if (sel < 0) {
1413                 fl_set_object_label(dialog_->button_add,
1414                                     idex(_("Add|#A")).c_str());
1415                 fl_set_button_shortcut(dialog_->button_add,
1416                                        scex(_("Add|#A")).c_str(), 1);
1417
1418                 fl_deselect_browser(dialog_->browser_all);
1419                 setEnabled(dialog_->button_delete, false);
1420
1421         } else {
1422                 fl_set_object_label(dialog_->button_add,
1423                                     idex(_("Modify|#M")).c_str());
1424                 fl_set_button_shortcut(dialog_->button_add,
1425                                        scex(_("Modify|#M")).c_str(), 1);
1426
1427                 int const top = max(sel-5, 0);
1428                 fl_set_browser_topline(dialog_->browser_all, top);
1429                 fl_select_browser_line(dialog_->browser_all, sel+1);
1430
1431                 setEnabled(dialog_->button_add, true);
1432                 setEnabled(dialog_->button_delete, true);
1433         }
1434
1435         string const prettyname = fl_get_input(dialog_->input_gui_name);
1436         bool const enable = !(name.empty() || prettyname.empty());
1437         setEnabled(dialog_->button_add, enable);
1438
1439         fl_unfreeze_form(dialog_->form);
1440         return false;
1441 }
1442
1443
1444 FormPreferences::Identity::Identity(FormPreferences & p)
1445         : parent_(p)
1446 {}
1447
1448
1449 FD_preferences_identity const * FormPreferences::Identity::dialog()
1450 {
1451         return dialog_.get();
1452 }
1453
1454
1455 void FormPreferences::Identity::apply(LyXRC & rc) const
1456 {
1457         rc.user_name = fl_get_input(dialog_->input_user_name);
1458         rc.user_email = fl_get_input(dialog_->input_user_email);
1459 }
1460
1461
1462 void FormPreferences::Identity::build()
1463 {
1464         dialog_.reset(build_preferences_identity(&parent_));
1465         fl_set_input_return(dialog_->input_user_name, FL_RETURN_CHANGED);
1466         fl_set_input_return(dialog_->input_user_email, FL_RETURN_CHANGED);
1467 }
1468
1469
1470 void FormPreferences::Identity::update(LyXRC const & rc)
1471 {
1472         fl_set_input(dialog_->input_user_name, rc.user_name.c_str());
1473         fl_set_input(dialog_->input_user_email, rc.user_email.c_str());
1474 }
1475
1476
1477 FormPreferences::InputsMisc::InputsMisc(FormPreferences &  p)
1478         : parent_(p)
1479 {}
1480
1481
1482 FD_preferences_inputs_misc const * FormPreferences::InputsMisc::dialog()
1483 {
1484         return dialog_.get();
1485 }
1486
1487
1488 void FormPreferences::InputsMisc::apply(LyXRC & rc) const
1489 {
1490         rc.date_insert_format =
1491                 fl_get_input(dialog_->input_date_format);
1492 }
1493
1494
1495 void FormPreferences::InputsMisc::build()
1496 {
1497         dialog_.reset(build_preferences_inputs_misc(&parent_));
1498
1499         fl_set_input_return(dialog_->input_date_format, FL_RETURN_CHANGED);
1500
1501         // set up the feedback mechanism
1502         setPrehandler(dialog_->input_date_format);
1503 }
1504
1505
1506 string const
1507 FormPreferences::InputsMisc::feedback(FL_OBJECT const * const ob) const
1508 {
1509         if (ob == dialog_->input_date_format)
1510                 return LyXRC::getDescription(LyXRC::RC_DATE_INSERT_FORMAT);
1511         return string();
1512 }
1513
1514
1515 void FormPreferences::InputsMisc::update(LyXRC const & rc)
1516 {
1517         fl_set_input(dialog_->input_date_format,
1518                      rc.date_insert_format.c_str());
1519 }
1520
1521
1522 FormPreferences::Interface::Interface(FormPreferences &  p)
1523         : parent_(p)
1524 {}
1525
1526
1527 FD_preferences_interface const * FormPreferences::Interface::dialog()
1528 {
1529         return dialog_.get();
1530 }
1531
1532
1533 void FormPreferences::Interface::apply(LyXRC & rc) const
1534 {
1535         rc.popup_normal_font =
1536                 fl_get_input(dialog_->input_popup_normal_font);
1537         rc.popup_bold_font = fl_get_input(dialog_->input_popup_bold_font);
1538         rc.popup_font_encoding =
1539                 fl_get_input(dialog_->input_popup_font_encoding);
1540         rc.bind_file = fl_get_input(dialog_->input_bind_file);
1541         rc.ui_file = fl_get_input(dialog_->input_ui_file);
1542 }
1543
1544
1545 void FormPreferences::Interface::build()
1546 {
1547         dialog_.reset(build_preferences_interface(&parent_));
1548
1549         fl_set_input_return(dialog_->input_popup_normal_font, FL_RETURN_CHANGED);
1550         fl_set_input_return(dialog_->input_popup_bold_font, FL_RETURN_CHANGED);
1551         fl_set_input_return(dialog_->input_popup_font_encoding, FL_RETURN_CHANGED);
1552         fl_set_input_return(dialog_->input_bind_file, FL_RETURN_CHANGED);
1553         fl_set_input_return(dialog_->input_ui_file, FL_RETURN_CHANGED);
1554
1555         // set up the feedback mechanism
1556         setPrehandler(dialog_->input_popup_normal_font);
1557         setPrehandler(dialog_->input_popup_bold_font);
1558         setPrehandler(dialog_->input_popup_font_encoding);
1559         setPrehandler(dialog_->input_bind_file);
1560         setPrehandler(dialog_->button_bind_file_browse);
1561         setPrehandler(dialog_->input_ui_file);
1562         setPrehandler(dialog_->button_ui_file_browse);
1563 }
1564
1565
1566 string const
1567 FormPreferences::Interface::feedback(FL_OBJECT const * const ob) const
1568 {
1569         if (ob == dialog_->input_popup_normal_font)
1570                 return LyXRC::getDescription(LyXRC::RC_POPUP_NORMAL_FONT);
1571         if (ob == dialog_->input_popup_bold_font)
1572                 return LyXRC::getDescription(LyXRC::RC_POPUP_BOLD_FONT);
1573         if (ob == dialog_->input_popup_font_encoding)
1574                 return LyXRC::getDescription(LyXRC::RC_POPUP_FONT_ENCODING);
1575         if (ob == dialog_->input_bind_file)
1576                 return LyXRC::getDescription(LyXRC::RC_BINDFILE);
1577         if (ob == dialog_->input_ui_file)
1578                 return LyXRC::getDescription(LyXRC::RC_UIFILE);
1579         return string();
1580 }
1581
1582
1583 bool FormPreferences::Interface::input(FL_OBJECT const * const ob)
1584 {
1585         if (ob == dialog_->button_bind_file_browse) {
1586                 string f = parent_.controller().browsebind(
1587                         fl_get_input(dialog_->input_bind_file));
1588
1589                 fl_set_input(dialog_->input_bind_file, f.c_str());
1590         } else if (ob == dialog_->button_ui_file_browse) {
1591                 string f = parent_.controller().browseUI(
1592                         fl_get_input(dialog_->input_ui_file));
1593
1594                 fl_set_input(dialog_->input_ui_file, f.c_str());
1595         }
1596
1597         return true;
1598 }
1599
1600
1601 void FormPreferences::Interface::update(LyXRC const & rc)
1602 {
1603         fl_set_input(dialog_->input_popup_normal_font,
1604                      rc.popup_normal_font.c_str());
1605         fl_set_input(dialog_->input_popup_bold_font,
1606                      rc.popup_bold_font.c_str());
1607         fl_set_input(dialog_->input_popup_font_encoding,
1608                      rc.popup_font_encoding.c_str());
1609         fl_set_input(dialog_->input_bind_file,
1610                      rc.bind_file.c_str());
1611         fl_set_input(dialog_->input_ui_file,
1612                      rc.ui_file.c_str());
1613 }
1614
1615
1616 FormPreferences::Language::Language(FormPreferences &  p)
1617         : parent_(p)
1618 {}
1619
1620
1621 FD_preferences_language const * FormPreferences::Language::dialog()
1622 {
1623         return dialog_.get();
1624 }
1625
1626
1627 void FormPreferences::Language::apply(LyXRC & rc)
1628 {
1629         int const pos = fl_get_combox(dialog_->combox_default_lang);
1630         rc.default_language = lang_[pos-1];
1631
1632         int button = fl_get_button(dialog_->check_use_kbmap);
1633         string const name_1 = fl_get_input(dialog_->input_kbmap1);
1634         string const name_2 = fl_get_input(dialog_->input_kbmap2);
1635         if (button)
1636                 button = !(name_1.empty() && name_2.empty());
1637         rc.use_kbmap = static_cast<bool>(button);
1638
1639         if (rc.use_kbmap) {
1640                 rc.primary_kbmap = name_1;
1641                 rc.secondary_kbmap = name_2;
1642         }
1643
1644         button = fl_get_button(dialog_->check_rtl_support);
1645         rc.rtl_support = static_cast<bool>(button);
1646
1647         button = fl_get_button(dialog_->check_mark_foreign);
1648         rc.mark_foreign_language = static_cast<bool>(button);
1649
1650         button = fl_get_button(dialog_->check_auto_begin);
1651         rc.language_auto_begin = static_cast<bool>(button);
1652
1653         button = fl_get_button(dialog_->check_auto_end);
1654         rc.language_auto_end = static_cast<bool>(button);
1655
1656         button = fl_get_button(dialog_->check_use_babel);
1657         rc.language_use_babel = static_cast<bool>(button);
1658
1659         button = fl_get_button(dialog_->check_global_options);
1660         rc.language_global_options = static_cast<bool>(button);
1661
1662         rc.language_package = fl_get_input(dialog_->input_package);
1663         rc.language_command_begin = fl_get_input(dialog_->input_command_begin);
1664         rc.language_command_end = fl_get_input(dialog_->input_command_end);
1665
1666         // Ensure that all is self-consistent.
1667         update(rc);
1668 }
1669
1670
1671 void FormPreferences::Language::build()
1672 {
1673         dialog_.reset(build_preferences_language(&parent_));
1674
1675         fl_set_input_return(dialog_->input_package, FL_RETURN_CHANGED);
1676         fl_set_input_return(dialog_->input_command_begin, FL_RETURN_CHANGED);
1677         fl_set_input_return(dialog_->input_command_end, FL_RETURN_CHANGED);
1678
1679         // Store the lang identifiers for later
1680         vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
1681         lang_ = getSecond(langs);
1682
1683         FL_OBJECT * obj = dialog_->combox_default_lang;
1684         vector<frnt::LanguagePair>::const_iterator lit  = langs.begin();
1685         vector<frnt::LanguagePair>::const_iterator lend = langs.end();
1686         for (; lit != lend; ++lit) {
1687                 fl_addto_combox(obj, lit->first.c_str());
1688         }
1689         fl_set_combox_browser_height(obj, 400);
1690
1691         // set up the feedback mechanism
1692         setPrehandler(dialog_->input_package);
1693         setPrehandler(dialog_->check_use_kbmap);
1694         setPrehandler(dialog_->combox_default_lang);
1695         setPrehandler(dialog_->input_kbmap1);
1696         setPrehandler(dialog_->input_kbmap2);
1697         setPrehandler(dialog_->check_rtl_support);
1698         setPrehandler(dialog_->check_mark_foreign);
1699         setPrehandler(dialog_->check_auto_begin);
1700         setPrehandler(dialog_->check_auto_end);
1701         setPrehandler(dialog_->check_use_babel);
1702         setPrehandler(dialog_->check_global_options);
1703         setPrehandler(dialog_->input_command_begin);
1704         setPrehandler(dialog_->input_command_end);
1705
1706         // Activate/Deactivate the input fields dependent on the state of the
1707         // buttons.
1708         input(0);
1709 }
1710
1711
1712 string const
1713 FormPreferences::Language::feedback(FL_OBJECT const * const ob) const
1714 {
1715         if (ob == dialog_->combox_default_lang)
1716                 return LyXRC::getDescription(LyXRC::RC_DEFAULT_LANGUAGE);
1717         if (ob == dialog_->check_use_kbmap)
1718                 return LyXRC::getDescription(LyXRC::RC_KBMAP);
1719         if (ob == dialog_->input_kbmap1)
1720                 return LyXRC::getDescription(LyXRC::RC_KBMAP_PRIMARY);
1721         if (ob == dialog_->input_kbmap2)
1722                 return LyXRC::getDescription(LyXRC::RC_KBMAP_SECONDARY);
1723         if (ob == dialog_->check_rtl_support)
1724                 return LyXRC::getDescription(LyXRC::RC_RTL_SUPPORT);
1725         if (ob == dialog_->check_mark_foreign)
1726                 return LyXRC::getDescription(LyXRC::RC_MARK_FOREIGN_LANGUAGE);
1727         if (ob == dialog_->check_auto_begin)
1728                 return LyXRC::getDescription(LyXRC::RC_LANGUAGE_AUTO_BEGIN);
1729         if (ob == dialog_->check_auto_end)
1730                 return LyXRC::getDescription(LyXRC::RC_LANGUAGE_AUTO_END);
1731         if (ob == dialog_->check_use_babel)
1732                 return LyXRC::getDescription(LyXRC::RC_LANGUAGE_USE_BABEL);
1733         if (ob == dialog_->check_global_options)
1734                 return LyXRC::getDescription(LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS);
1735         if (ob == dialog_->input_package)
1736                 return LyXRC::getDescription(LyXRC::RC_LANGUAGE_PACKAGE);
1737         if (ob == dialog_->input_command_begin)
1738                 return LyXRC::getDescription(LyXRC::RC_LANGUAGE_COMMAND_BEGIN);
1739         if (ob == dialog_->input_command_end)
1740                 return LyXRC::getDescription(LyXRC::RC_LANGUAGE_COMMAND_END);
1741         return string();
1742 }
1743
1744
1745 bool FormPreferences::Language::input(FL_OBJECT const * const ob)
1746 {
1747         bool activate = true;
1748
1749         // !ob if function is called from Language::build() to de/activate
1750         // objects,
1751         // otherwise the function is called by an xforms CB via input().
1752         if (!ob || ob == dialog_->check_use_kbmap) {
1753                 bool const enable = fl_get_button(dialog_->check_use_kbmap);
1754                 setEnabled(dialog_->button_kbmap1_browse, enable);
1755                 setEnabled(dialog_->button_kbmap2_browse, enable);
1756                 setEnabled(dialog_->input_kbmap1, enable);
1757                 setEnabled(dialog_->input_kbmap2, enable);
1758         }
1759
1760         if (ob == dialog_->button_kbmap1_browse) {
1761                 string f = parent_.controller().browsekbmap(
1762                         fl_get_input(dialog_->input_kbmap1));
1763
1764                 fl_set_input(dialog_->input_kbmap1, f.c_str());
1765         } else if (ob == dialog_->button_kbmap2_browse) {
1766                 string f = parent_.controller().browsekbmap(
1767                         fl_get_input(dialog_->input_kbmap2));
1768
1769                 fl_set_input(dialog_->input_kbmap2, f.c_str());
1770         }
1771
1772         return activate;
1773 }
1774
1775
1776 void FormPreferences::Language::update(LyXRC const & rc)
1777 {
1778         fl_set_button(dialog_->check_use_kbmap,
1779                       rc.use_kbmap);
1780
1781         int const pos = int(findPos(lang_, rc.default_language));
1782         fl_set_combox(dialog_->combox_default_lang, pos + 1);
1783
1784         if (rc.use_kbmap) {
1785                 fl_set_input(dialog_->input_kbmap1,
1786                              rc.primary_kbmap.c_str());
1787                 fl_set_input(dialog_->input_kbmap2,
1788                              rc.secondary_kbmap.c_str());
1789         } else {
1790                 fl_set_input(dialog_->input_kbmap1, "");
1791                 fl_set_input(dialog_->input_kbmap2, "");
1792         }
1793
1794         fl_set_button(dialog_->check_rtl_support, rc.rtl_support);
1795         fl_set_button(dialog_->check_mark_foreign,
1796                       rc.mark_foreign_language);
1797         fl_set_button(dialog_->check_auto_begin, rc.language_auto_begin);
1798         fl_set_button(dialog_->check_auto_end, rc.language_auto_end);
1799         fl_set_button(dialog_->check_use_babel, rc.language_use_babel);
1800         fl_set_button(dialog_->check_global_options,
1801                       rc.language_global_options);
1802
1803         fl_set_input(dialog_->input_package,
1804                      rc.language_package.c_str());
1805         fl_set_input(dialog_->input_command_begin,
1806                      rc.language_command_begin.c_str());
1807         fl_set_input(dialog_->input_command_end,
1808                      rc.language_command_end.c_str());
1809
1810         // Activate/Deactivate the input fields dependent on the state of the
1811         // buttons.
1812         input(0);
1813 }
1814
1815
1816 FormPreferences::LnFmisc::LnFmisc(FormPreferences &  p)
1817         : parent_(p)
1818 {}
1819
1820
1821 FD_preferences_lnf_misc const * FormPreferences::LnFmisc::dialog()
1822 {
1823         return dialog_.get();
1824 }
1825
1826
1827 void FormPreferences::LnFmisc::apply(LyXRC & rc) const
1828 {
1829         rc.auto_region_delete =
1830                 fl_get_button(dialog_->check_auto_region_delete);
1831         rc.cursor_follows_scrollbar =
1832                 fl_get_button(dialog_->check_cursor_follows_scrollbar);
1833         rc.dialogs_iconify_with_main =
1834                 fl_get_button(dialog_->check_dialogs_iconify_with_main);
1835         rc.preview = fl_get_button(dialog_->check_preview_latex);
1836         rc.autosave = static_cast<unsigned int>
1837                 (fl_get_counter_value(dialog_->counter_autosave));
1838         rc.wheel_jump = static_cast<unsigned int>
1839                 (fl_get_counter_value(dialog_->counter_wm_jump));
1840
1841         // See FIXME below
1842         // grfx::DisplayType old_value = rc.display_graphics;
1843         switch (fl_get_choice(dialog_->choice_display)) {
1844         case 4:
1845                 rc.display_graphics = grfx::NoDisplay;
1846                 break;
1847         case 3:
1848                 rc.display_graphics = grfx::ColorDisplay;
1849                 break;
1850         case 2:
1851                 rc.display_graphics = grfx::GrayscaleDisplay;
1852                 break;
1853         case 1:
1854                 rc.display_graphics = grfx::MonochromeDisplay;
1855                 break;
1856         default:
1857                 rc.display_graphics = grfx::ColorDisplay;
1858                 break;
1859         }
1860
1861 #ifdef WITH_WARNINGS
1862 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
1863 #endif
1864 #if 0
1865         if (old_value != rc.display_graphics) {
1866                 grfx::GCache & gc = grfx::GCache::get();
1867                 gc.changeDisplay();
1868         }
1869 #endif
1870 }
1871
1872
1873 void FormPreferences::LnFmisc::build()
1874 {
1875         dialog_.reset(build_preferences_lnf_misc(&parent_));
1876
1877         fl_set_counter_step(dialog_->counter_autosave, 1, 10);
1878         fl_set_counter_step(dialog_->counter_wm_jump, 1, 10);
1879
1880         fl_set_counter_return(dialog_->counter_autosave, FL_RETURN_CHANGED);
1881         fl_set_counter_return(dialog_->counter_wm_jump, FL_RETURN_CHANGED);
1882
1883         // set up the feedback mechanism
1884         setPrehandler(dialog_->check_auto_region_delete);
1885         setPrehandler(dialog_->counter_autosave);
1886         setPrehandler(dialog_->check_cursor_follows_scrollbar);
1887         setPrehandler(dialog_->check_dialogs_iconify_with_main);
1888         setPrehandler(dialog_->check_preview_latex);
1889         setPrehandler(dialog_->counter_wm_jump);
1890
1891         fl_addto_choice(dialog_->choice_display, _("Monochrome|Grayscale|Color|Do not display"));
1892 }
1893
1894
1895 string const
1896 FormPreferences::LnFmisc::feedback(FL_OBJECT const * const ob) const
1897 {
1898         if (ob == dialog_->check_auto_region_delete)
1899                 return LyXRC::getDescription(LyXRC::RC_AUTOREGIONDELETE);
1900         if (ob == dialog_->check_cursor_follows_scrollbar)
1901                 return LyXRC::getDescription(LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR);
1902         if (ob == dialog_->check_dialogs_iconify_with_main)
1903                 return LyXRC::getDescription(LyXRC::RC_DIALOGS_ICONIFY_WITH_MAIN);
1904         if (ob == dialog_->check_preview_latex)
1905                 return LyXRC::getDescription(LyXRC::RC_PREVIEW);
1906         if (ob == dialog_->counter_autosave)
1907                 return LyXRC::getDescription(LyXRC::RC_AUTOSAVE);
1908         if (ob == dialog_->counter_wm_jump)
1909                 return LyXRC::getDescription(LyXRC::RC_WHEEL_JUMP);
1910         if (ob == dialog_->choice_display)
1911                 return LyXRC::getDescription(LyXRC::RC_DISPLAY_GRAPHICS);
1912         return string();
1913 }
1914
1915
1916 void FormPreferences::LnFmisc::update(LyXRC const & rc)
1917 {
1918         fl_set_button(dialog_->check_auto_region_delete,
1919                       rc.auto_region_delete);
1920         fl_set_button(dialog_->check_cursor_follows_scrollbar,
1921                       rc.cursor_follows_scrollbar);
1922         fl_set_button(dialog_->check_dialogs_iconify_with_main,
1923                       rc.dialogs_iconify_with_main);
1924         fl_set_button(dialog_->check_preview_latex,
1925                       rc.preview);
1926         fl_set_counter_value(dialog_->counter_autosave, rc.autosave);
1927         fl_set_counter_value(dialog_->counter_wm_jump, rc.wheel_jump);
1928
1929         switch (rc.display_graphics) {
1930         case grfx::NoDisplay:
1931                 fl_set_choice(dialog_->choice_display, 4);
1932                 break;
1933         case grfx::ColorDisplay:
1934                 fl_set_choice(dialog_->choice_display, 3);
1935                 break;
1936         case grfx::GrayscaleDisplay:
1937                 fl_set_choice(dialog_->choice_display, 2);
1938                 break;
1939         case grfx::MonochromeDisplay:
1940                 fl_set_choice(dialog_->choice_display, 1);
1941                 break;
1942         default:
1943                 fl_set_choice(dialog_->choice_display, 3);
1944                 break;
1945         }
1946 }
1947
1948
1949 FormPreferences::OutputsMisc::OutputsMisc(FormPreferences &  p)
1950         : parent_(p)
1951 {}
1952
1953
1954 FD_preferences_outputs_misc const * FormPreferences::OutputsMisc::dialog()
1955 {
1956         return dialog_.get();
1957 }
1958
1959
1960 void FormPreferences::OutputsMisc::apply(LyXRC & rc) const
1961 {
1962         rc.ascii_linelen = static_cast<unsigned int>
1963                 (fl_get_counter_value(dialog_->counter_line_len));
1964         rc.fontenc = fl_get_input(dialog_->input_tex_encoding);
1965
1966         int const choice =
1967                 fl_get_choice(dialog_->choice_default_papersize) - 1;
1968         rc.default_papersize = static_cast<BufferParams::PAPER_SIZE>(choice);
1969
1970         rc.ascii_roff_command = fl_get_input(dialog_->input_ascii_roff);
1971         rc.chktex_command = fl_get_input(dialog_->input_checktex);
1972         rc.view_dvi_paper_option = fl_get_input(dialog_->input_paperoption);
1973         rc.auto_reset_options = fl_get_button(dialog_->check_autoreset_classopt);
1974 }
1975
1976
1977 void FormPreferences::OutputsMisc::build()
1978 {
1979         dialog_.reset(build_preferences_outputs_misc(&parent_));
1980
1981         fl_set_counter_step(dialog_->counter_line_len, 1, 10);
1982
1983         fl_set_counter_return(dialog_->counter_line_len, FL_RETURN_CHANGED);
1984         fl_set_input_return(dialog_->input_tex_encoding, FL_RETURN_CHANGED);
1985         fl_set_input_return(dialog_->input_ascii_roff,   FL_RETURN_CHANGED);
1986         fl_set_input_return(dialog_->input_checktex,     FL_RETURN_CHANGED);
1987         fl_set_input_return(dialog_->input_paperoption,  FL_RETURN_CHANGED);
1988
1989         fl_addto_choice(dialog_->choice_default_papersize,
1990                         _(" default | US letter | US legal | US executive | A3 | A4 | A5 | B5 "));
1991
1992         // set up the feedback mechanism
1993         setPrehandler(dialog_->counter_line_len);
1994         setPrehandler(dialog_->input_tex_encoding);
1995         setPrehandler(dialog_->choice_default_papersize);
1996         setPrehandler(dialog_->input_ascii_roff);
1997         setPrehandler(dialog_->input_checktex);
1998         setPrehandler(dialog_->input_paperoption);
1999         setPrehandler(dialog_->check_autoreset_classopt);
2000 }
2001
2002
2003 string const
2004 FormPreferences::OutputsMisc::feedback(FL_OBJECT const * const ob) const
2005 {
2006         if (ob == dialog_->counter_line_len)
2007                 return LyXRC::getDescription(LyXRC::RC_ASCII_LINELEN);
2008         if (ob == dialog_->input_tex_encoding)
2009                 return LyXRC::getDescription(LyXRC::RC_FONT_ENCODING);
2010         if (ob == dialog_->input_ascii_roff)
2011                 return LyXRC::getDescription(LyXRC::RC_ASCIIROFF_COMMAND);
2012         if (ob == dialog_->input_checktex)
2013                 return LyXRC::getDescription(LyXRC::RC_CHKTEX_COMMAND);
2014         if (ob == dialog_->choice_default_papersize)
2015                 return LyXRC::getDescription(LyXRC::RC_DEFAULT_PAPERSIZE);
2016         if (ob == dialog_->input_paperoption)
2017                 return LyXRC::getDescription(LyXRC::RC_VIEWDVI_PAPEROPTION);
2018         if (ob == dialog_->check_autoreset_classopt)
2019                 return LyXRC::getDescription(LyXRC::RC_AUTORESET_OPTIONS);
2020         return string();
2021 }
2022
2023
2024 void FormPreferences::OutputsMisc::update(LyXRC const & rc)
2025 {
2026         fl_set_counter_value(dialog_->counter_line_len,
2027                              rc.ascii_linelen);
2028         fl_set_input(dialog_->input_tex_encoding,
2029                      rc.fontenc.c_str());
2030         fl_set_choice(dialog_->choice_default_papersize,
2031                       rc.default_papersize + 1);
2032         fl_set_input(dialog_->input_ascii_roff,
2033                      rc.ascii_roff_command.c_str());
2034         fl_set_input(dialog_->input_checktex,
2035                      rc.chktex_command.c_str());
2036         fl_set_input(dialog_->input_paperoption,
2037                      rc.view_dvi_paper_option.c_str());
2038         fl_set_button(dialog_->check_autoreset_classopt,
2039                       rc.auto_reset_options);
2040
2041 }
2042
2043
2044 FormPreferences::Paths::Paths(FormPreferences &  p)
2045         : parent_(p)
2046 {}
2047
2048
2049 FD_preferences_paths const * FormPreferences::Paths::dialog()
2050 {
2051         return dialog_.get();
2052 }
2053
2054
2055 void FormPreferences::Paths::apply(LyXRC & rc)
2056 {
2057         rc.document_path = fl_get_input(dialog_->input_default_path);
2058         rc.template_path = fl_get_input(dialog_->input_template_path);
2059
2060         int button = fl_get_button(dialog_->check_use_temp_dir);
2061         string str  = fl_get_input(dialog_->input_temp_dir);
2062         if (!button)
2063                 str.erase();
2064
2065         rc.use_tempdir = button;
2066         rc.tempdir_path = str;
2067
2068         button = fl_get_button(dialog_->check_last_files);
2069         str = fl_get_input(dialog_->input_lastfiles);
2070         if (!button) str.erase();
2071
2072         rc.check_lastfiles = button;
2073         rc.lastfiles = str;
2074         rc.num_lastfiles = static_cast<unsigned int>
2075                 (fl_get_counter_value(dialog_->counter_lastfiles));
2076
2077         button = fl_get_button(dialog_->check_make_backups);
2078         str = fl_get_input(dialog_->input_backup_path);
2079         if (!button)
2080                 str.erase();
2081
2082         rc.make_backup = button;
2083         rc.backupdir_path = str;
2084
2085         rc.lyxpipes = fl_get_input(dialog_->input_serverpipe);
2086
2087         // update view
2088         update(rc);
2089 }
2090
2091
2092 void FormPreferences::Paths::build()
2093 {
2094         dialog_.reset(build_preferences_paths(&parent_));
2095
2096         fl_set_input_return(dialog_->input_default_path, FL_RETURN_CHANGED);
2097         fl_set_input_return(dialog_->input_template_path, FL_RETURN_CHANGED);
2098         fl_set_input_return(dialog_->input_temp_dir, FL_RETURN_CHANGED);
2099         fl_set_input_return(dialog_->input_lastfiles, FL_RETURN_CHANGED);
2100         fl_set_input_return(dialog_->input_backup_path, FL_RETURN_CHANGED);
2101         fl_set_counter_return(dialog_->counter_lastfiles, FL_RETURN_CHANGED);
2102         fl_set_input_return(dialog_->input_serverpipe, FL_RETURN_CHANGED);
2103
2104         // set up the feedback mechanism
2105         setPrehandler(dialog_->input_default_path);
2106         setPrehandler(dialog_->counter_lastfiles);
2107         setPrehandler(dialog_->input_template_path);
2108         setPrehandler(dialog_->check_last_files);
2109         setPrehandler(dialog_->input_lastfiles);
2110         setPrehandler(dialog_->check_make_backups);
2111         setPrehandler(dialog_->input_backup_path);
2112         setPrehandler(dialog_->input_serverpipe);
2113         setPrehandler(dialog_->input_temp_dir);
2114         setPrehandler(dialog_->check_use_temp_dir);
2115 }
2116
2117
2118 string const
2119 FormPreferences::Paths::feedback(FL_OBJECT const * const ob) const
2120 {
2121         if (ob == dialog_->input_default_path)
2122                 return LyXRC::getDescription(LyXRC::RC_DOCUMENTPATH);
2123         if (ob == dialog_->input_template_path)
2124                 return LyXRC::getDescription(LyXRC::RC_TEMPLATEPATH);
2125         if (ob == dialog_->check_use_temp_dir)
2126                 return LyXRC::getDescription(LyXRC::RC_USETEMPDIR);
2127         if (ob == dialog_->input_temp_dir)
2128                 return LyXRC::getDescription(LyXRC::RC_TEMPDIRPATH);
2129         if (ob == dialog_->check_last_files)
2130                 return LyXRC::getDescription(LyXRC::RC_CHECKLASTFILES);
2131         if (ob == dialog_->input_lastfiles)
2132                 return LyXRC::getDescription(LyXRC::RC_LASTFILES);
2133         if (ob == dialog_->counter_lastfiles)
2134                 return LyXRC::getDescription(LyXRC::RC_NUMLASTFILES);
2135         if (ob == dialog_->check_make_backups)
2136                 return LyXRC::getDescription(LyXRC::RC_MAKE_BACKUP);
2137         if (ob == dialog_->input_backup_path)
2138                 return LyXRC::getDescription(LyXRC::RC_BACKUPDIR_PATH);
2139         if (ob == dialog_->input_serverpipe)
2140                 return LyXRC::getDescription(LyXRC::RC_SERVERPIPE);
2141         return string();
2142 }
2143
2144
2145 bool FormPreferences::Paths::input(FL_OBJECT const * const ob)
2146 {
2147         bool activate = true;
2148
2149         // !ob if function is called from Paths::update() to de/activate
2150         // objects,
2151         // otherwise the function is called by an xforms CB via input().
2152         if (!ob || ob == dialog_->check_use_temp_dir) {
2153                 bool const enable = fl_get_button(dialog_->check_use_temp_dir);
2154                 setEnabled(dialog_->input_temp_dir, enable);
2155         }
2156
2157         if (!ob || ob == dialog_->check_last_files) {
2158                 bool const enable = fl_get_button(dialog_->check_last_files);
2159                 setEnabled(dialog_->input_lastfiles, enable);
2160         }
2161
2162         if (!ob || ob == dialog_->check_make_backups) {
2163                 bool const enable = fl_get_button(dialog_->check_make_backups);
2164                 setEnabled(dialog_->input_backup_path, enable);
2165         }
2166
2167         if (!ob || ob == dialog_->input_default_path) {
2168                 string const name = fl_get_input(dialog_->input_default_path);
2169                 if (!name.empty() && !RWInfo::WriteableDir(name)) {
2170                         parent_.postWarning(RWInfo::ErrorMessage());
2171                         return false;
2172                 }
2173         }
2174
2175         if (!ob || ob == dialog_->input_template_path) {
2176                 string const name = fl_get_input(dialog_->input_template_path);
2177                 if (!name.empty() && !RWInfo::ReadableDir(name)) {
2178                         parent_.postWarning(RWInfo::ErrorMessage());
2179                         return false;
2180                 }
2181         }
2182
2183         if (!ob || ob == dialog_->input_temp_dir) {
2184                 string const name = fl_get_input(dialog_->input_temp_dir);
2185                 if (fl_get_button(dialog_->check_make_backups)
2186                     && !name.empty()
2187                     && !RWInfo::WriteableDir(name)) {
2188                         parent_.postWarning(RWInfo::ErrorMessage());
2189                         return false;
2190                 }
2191         }
2192
2193         if (!ob || ob == dialog_->input_backup_path) {
2194                 string const name = fl_get_input(dialog_->input_backup_path);
2195                 if (fl_get_button(dialog_->check_make_backups)
2196                     && !name.empty()
2197                     && !RWInfo::WriteableDir(name)) {
2198                         parent_.postWarning(RWInfo::ErrorMessage());
2199                         return false;
2200                 }
2201         }
2202
2203         if (!ob || ob == dialog_->input_lastfiles) {
2204                 string const name = fl_get_input(dialog_->input_lastfiles);
2205                 if (fl_get_button(dialog_->check_last_files)
2206                     && !name.empty()
2207                     && !RWInfo::WriteableFile(name)) {
2208                         parent_.postWarning(RWInfo::ErrorMessage());
2209                         return false;
2210                 }
2211         }
2212
2213         if (!ob || ob == dialog_->input_serverpipe) {
2214                 string const name = fl_get_input(dialog_->input_serverpipe);
2215                 if (!name.empty()) {
2216                         // strip off the extension
2217                         string const str = ChangeExtension(name, "");
2218                         if (!RWInfo::WriteableFile(str + ".in")) {
2219                                 parent_.postWarning(RWInfo::ErrorMessage());
2220                                 return false;
2221                         }
2222                         if (!RWInfo::WriteableFile(str + ".out")) {
2223                                 parent_.postWarning(RWInfo::ErrorMessage());
2224                                 return false;
2225                         }
2226                 }
2227         }
2228
2229         if (ob == dialog_->button_default_path_browse) {
2230                 string f = parent_.controller().browsedir(
2231                         fl_get_input(dialog_->input_default_path), _("Default path"));
2232                 if (!f.empty())
2233                         fl_set_input(dialog_->input_default_path, f.c_str());
2234         } else if (ob == dialog_->button_template_path_browse) {
2235                 string f = parent_.controller().browsedir(
2236                         fl_get_input(dialog_->input_template_path), _("Template path"));
2237                 if (!f.empty())
2238                         fl_set_input(dialog_->input_template_path, f.c_str());
2239         } else if (ob == dialog_->button_temp_dir_browse) {
2240                 string f = parent_.controller().browsedir(
2241                         fl_get_input(dialog_->input_temp_dir), _("Temporary dir"));
2242                 if (!f.empty())
2243                         fl_set_input(dialog_->input_temp_dir, f.c_str());
2244         } else if (ob == dialog_->button_lastfiles_browse) {
2245                 string f = parent_.controller().browse(
2246                         fl_get_input(dialog_->input_lastfiles), _("Last files"));
2247                 if (!f.empty())
2248                         fl_set_input(dialog_->input_lastfiles, f.c_str());
2249         } else if (ob == dialog_->button_backup_path_browse) {
2250                 string f = parent_.controller().browsedir(
2251                         fl_get_input(dialog_->input_backup_path), _("Backup path"));
2252                 if (!f.empty())
2253                         fl_set_input(dialog_->input_backup_path, f.c_str());
2254         } else if (ob == dialog_->button_serverpipe_browse) {
2255                 string f = parent_.controller().browse(
2256                         fl_get_input(dialog_->input_serverpipe), _("LyX server pipes"));
2257                 if (!f.empty())
2258                         fl_set_input(dialog_->input_serverpipe, f.c_str());
2259         }
2260
2261         return activate;
2262 }
2263
2264
2265 void FormPreferences::Paths::update(LyXRC const & rc)
2266 {
2267         fl_set_input(dialog_->input_default_path,
2268                      rc.document_path.c_str());
2269         fl_set_input(dialog_->input_template_path,
2270                      rc.template_path.c_str());
2271
2272         string str;
2273         if (rc.make_backup)
2274                 str = rc.backupdir_path;
2275
2276         fl_set_button(dialog_->check_make_backups,
2277                       rc.make_backup);
2278         fl_set_input(dialog_->input_backup_path, str.c_str());
2279
2280         str.erase();
2281         if (rc.use_tempdir)
2282                 str = rc.tempdir_path;
2283
2284         fl_set_button(dialog_->check_use_temp_dir,
2285                       rc.use_tempdir);
2286         fl_set_input(dialog_->input_temp_dir, str.c_str());
2287
2288         str.erase();
2289         if (rc.check_lastfiles)
2290                 str = rc.lastfiles;
2291
2292         fl_set_button(dialog_->check_last_files,
2293                       rc.check_lastfiles);
2294         fl_set_input(dialog_->input_lastfiles, str.c_str());
2295         fl_set_counter_value(dialog_->counter_lastfiles,
2296                              rc.num_lastfiles);
2297
2298         fl_set_input(dialog_->input_serverpipe, rc.lyxpipes.c_str());
2299
2300         // Activate/Deactivate the input fields dependent on the state of the
2301         // buttons.
2302         input(0);
2303 }
2304
2305
2306 FormPreferences::Printer::Printer(FormPreferences &  p)
2307         : parent_(p)
2308 {}
2309
2310
2311 FD_preferences_printer const * FormPreferences::Printer::dialog()
2312 {
2313         return dialog_.get();
2314 }
2315
2316
2317 void FormPreferences::Printer::apply(LyXRC & rc) const
2318 {
2319         rc.print_adapt_output = fl_get_button(dialog_->check_adapt_output);
2320         rc.print_command = fl_get_input(dialog_->input_command);
2321         rc.print_pagerange_flag = fl_get_input(dialog_->input_page_range);
2322         rc.print_copies_flag = fl_get_input(dialog_->input_copies);
2323         rc.print_reverse_flag = fl_get_input(dialog_->input_reverse);
2324         rc.print_to_printer = fl_get_input(dialog_->input_to_printer);
2325         rc.print_file_extension =
2326                 fl_get_input(dialog_->input_file_extension);
2327         rc.print_spool_command =
2328                 fl_get_input(dialog_->input_spool_command);
2329         rc.print_paper_flag = fl_get_input(dialog_->input_paper_type);
2330         rc.print_evenpage_flag = fl_get_input(dialog_->input_even_pages);
2331         rc.print_oddpage_flag = fl_get_input(dialog_->input_odd_pages);
2332         rc.print_collcopies_flag = fl_get_input(dialog_->input_collated);
2333         rc.print_landscape_flag = fl_get_input(dialog_->input_landscape);
2334         rc.print_to_file = fl_get_input(dialog_->input_to_file);
2335         rc.print_extra_options =
2336                 fl_get_input(dialog_->input_extra_options);
2337         rc.print_spool_printerprefix =
2338                 fl_get_input(dialog_->input_spool_prefix);
2339         rc.print_paper_dimension_flag =
2340                 fl_get_input(dialog_->input_paper_size);
2341         rc.printer = fl_get_input(dialog_->input_name);
2342 }
2343
2344
2345 string const
2346 FormPreferences::Printer::feedback(FL_OBJECT const * const ob) const
2347 {
2348         if (ob == dialog_->input_command)
2349                 return LyXRC::getDescription(LyXRC::RC_PRINT_COMMAND);
2350         if (ob == dialog_->check_adapt_output)
2351                 return LyXRC::getDescription(LyXRC::RC_PRINT_ADAPTOUTPUT);
2352         if (ob == dialog_->input_to_printer)
2353                 return LyXRC::getDescription(LyXRC::RC_PRINTTOPRINTER);
2354         if (ob == dialog_->input_to_file)
2355                 return LyXRC::getDescription(LyXRC::RC_PRINTTOFILE);
2356         if (ob == dialog_->input_file_extension)
2357                 return LyXRC::getDescription(LyXRC::RC_PRINTFILEEXTENSION);
2358         if (ob == dialog_->input_extra_options)
2359                 return LyXRC::getDescription(LyXRC::RC_PRINTEXSTRAOPTIONS);
2360         if (ob == dialog_->input_spool_command)
2361                 return LyXRC::getDescription(LyXRC::RC_PRINTSPOOL_COMMAND);
2362         if (ob == dialog_->input_spool_prefix)
2363                 return LyXRC::getDescription(LyXRC::RC_PRINTSPOOL_PRINTERPREFIX);
2364         if (ob == dialog_->input_name)
2365                 return LyXRC::getDescription(LyXRC::RC_PRINTER);
2366         if (ob == dialog_->input_even_pages)
2367                 return LyXRC::getDescription(LyXRC::RC_PRINTEVENPAGEFLAG);
2368         if (ob == dialog_->input_odd_pages)
2369                 return LyXRC::getDescription(LyXRC::RC_PRINTODDPAGEFLAG);
2370         if (ob == dialog_->input_page_range)
2371                 return LyXRC::getDescription(LyXRC::RC_PRINTPAGERANGEFLAG);
2372         if (ob == dialog_->input_reverse)
2373                 return LyXRC::getDescription(LyXRC::RC_PRINTREVERSEFLAG);
2374         if (ob == dialog_->input_landscape)
2375                 return LyXRC::getDescription(LyXRC::RC_PRINTLANDSCAPEFLAG);
2376         if (ob == dialog_->input_copies)
2377                 return LyXRC::getDescription(LyXRC::RC_PRINTCOPIESFLAG);
2378         if (ob == dialog_->input_collated)
2379                 return LyXRC::getDescription(LyXRC::RC_PRINTCOLLCOPIESFLAG);
2380         if (ob == dialog_->input_paper_type)
2381                 return LyXRC::getDescription(LyXRC::RC_PRINTPAPERFLAG);
2382         if (ob == dialog_->input_paper_size)
2383                 return LyXRC::getDescription(LyXRC::RC_PRINTPAPERDIMENSIONFLAG);
2384         return string();
2385 }
2386
2387
2388 void FormPreferences::Printer::build()
2389 {
2390         dialog_.reset(build_preferences_printer(&parent_));
2391
2392         fl_set_input_return(dialog_->input_command, FL_RETURN_CHANGED);
2393         fl_set_input_return(dialog_->input_page_range, FL_RETURN_CHANGED);
2394         fl_set_input_return(dialog_->input_copies, FL_RETURN_CHANGED);
2395         fl_set_input_return(dialog_->input_reverse, FL_RETURN_CHANGED);
2396         fl_set_input_return(dialog_->input_to_printer, FL_RETURN_CHANGED);
2397         fl_set_input_return(dialog_->input_file_extension, FL_RETURN_CHANGED);
2398         fl_set_input_return(dialog_->input_spool_command, FL_RETURN_CHANGED);
2399         fl_set_input_return(dialog_->input_paper_type, FL_RETURN_CHANGED);
2400         fl_set_input_return(dialog_->input_even_pages, FL_RETURN_CHANGED);
2401         fl_set_input_return(dialog_->input_odd_pages, FL_RETURN_CHANGED);
2402         fl_set_input_return(dialog_->input_collated, FL_RETURN_CHANGED);
2403         fl_set_input_return(dialog_->input_landscape, FL_RETURN_CHANGED);
2404         fl_set_input_return(dialog_->input_to_file, FL_RETURN_CHANGED);
2405         fl_set_input_return(dialog_->input_extra_options, FL_RETURN_CHANGED);
2406         fl_set_input_return(dialog_->input_spool_prefix, FL_RETURN_CHANGED);
2407         fl_set_input_return(dialog_->input_paper_size, FL_RETURN_CHANGED);
2408         fl_set_input_return(dialog_->input_name, FL_RETURN_CHANGED);
2409
2410         // set up the feedback mechanism
2411         setPrehandler(dialog_->input_command);
2412         setPrehandler(dialog_->input_page_range);
2413         setPrehandler(dialog_->input_copies);
2414         setPrehandler(dialog_->input_reverse);
2415         setPrehandler(dialog_->input_to_printer);
2416         setPrehandler(dialog_->input_file_extension);
2417         setPrehandler(dialog_->input_spool_command);
2418         setPrehandler(dialog_->input_paper_type);
2419         setPrehandler(dialog_->input_even_pages);
2420         setPrehandler(dialog_->input_odd_pages);
2421         setPrehandler(dialog_->input_collated);
2422         setPrehandler(dialog_->input_landscape);
2423         setPrehandler(dialog_->input_to_file);
2424         setPrehandler(dialog_->input_extra_options);
2425         setPrehandler(dialog_->input_spool_prefix);
2426         setPrehandler(dialog_->input_paper_size);
2427         setPrehandler(dialog_->input_name);
2428         setPrehandler(dialog_->check_adapt_output);
2429 }
2430
2431
2432 void FormPreferences::Printer::update(LyXRC const & rc)
2433 {
2434         fl_set_button(dialog_->check_adapt_output,
2435                       rc.print_adapt_output);
2436         fl_set_input(dialog_->input_command,
2437                      rc.print_command.c_str());
2438         fl_set_input(dialog_->input_page_range,
2439                      rc.print_pagerange_flag.c_str());
2440         fl_set_input(dialog_->input_copies,
2441                      rc.print_copies_flag.c_str());
2442         fl_set_input(dialog_->input_reverse,
2443                      rc.print_reverse_flag.c_str());
2444         fl_set_input(dialog_->input_to_printer,
2445                      rc.print_to_printer.c_str());
2446         fl_set_input(dialog_->input_file_extension,
2447                      rc.print_file_extension.c_str());
2448         fl_set_input(dialog_->input_spool_command,
2449                      rc.print_spool_command.c_str());
2450         fl_set_input(dialog_->input_paper_type,
2451                      rc.print_paper_flag.c_str());
2452         fl_set_input(dialog_->input_even_pages,
2453                      rc.print_evenpage_flag.c_str());
2454         fl_set_input(dialog_->input_odd_pages,
2455                      rc.print_oddpage_flag.c_str());
2456         fl_set_input(dialog_->input_collated,
2457                      rc.print_collcopies_flag.c_str());
2458         fl_set_input(dialog_->input_landscape,
2459                      rc.print_landscape_flag.c_str());
2460         fl_set_input(dialog_->input_to_file,
2461                      rc.print_to_file.c_str());
2462         fl_set_input(dialog_->input_extra_options,
2463                      rc.print_extra_options.c_str());
2464         fl_set_input(dialog_->input_spool_prefix,
2465                      rc.print_spool_printerprefix.c_str());
2466         fl_set_input(dialog_->input_paper_size,
2467                      rc.print_paper_dimension_flag.c_str());
2468         fl_set_input(dialog_->input_name,
2469                      rc.printer.c_str());
2470 }
2471
2472
2473 FormPreferences::ScreenFonts::ScreenFonts(FormPreferences &  p)
2474         : parent_(p)
2475 {}
2476
2477
2478 FD_preferences_screen_fonts const * FormPreferences::ScreenFonts::dialog()
2479 {
2480         return dialog_.get();
2481 }
2482
2483
2484 void FormPreferences::ScreenFonts::apply(LyXRC & rc) const
2485 {
2486         bool changed = false;
2487
2488         pair<string, string> tmp =
2489                 parseFontName(fl_get_input(dialog_->input_roman));
2490         if (rc.roman_font_name != tmp.first ||
2491             rc.roman_font_foundry != tmp.second) {
2492                 changed = true;
2493                 rc.roman_font_name = tmp.first;
2494                 rc.roman_font_foundry = tmp.second;
2495         }
2496
2497         tmp = parseFontName(fl_get_input(dialog_->input_sans));
2498         if (rc.sans_font_name != tmp.first ||
2499             rc.sans_font_foundry != tmp.second) {
2500                 changed = true;
2501                 rc.sans_font_name = tmp.first;
2502                 rc.sans_font_foundry = tmp.second;
2503         }
2504
2505         tmp = parseFontName(fl_get_input(dialog_->input_typewriter));
2506         if (rc.typewriter_font_name != tmp.first ||
2507             rc.typewriter_font_foundry != tmp.second) {
2508                 changed = true;
2509                 rc.typewriter_font_name = tmp.first;
2510                 rc.typewriter_font_foundry = tmp.second;
2511         }
2512
2513         string str = fl_get_input(dialog_->input_screen_encoding);
2514         if (rc.font_norm != str) {
2515                 changed = true;
2516                 rc.font_norm = str;
2517                 rc.set_font_norm_type();
2518         }
2519
2520         bool button = fl_get_button(dialog_->check_scalable);
2521         if (rc.use_scalable_fonts != button) {
2522                 changed = true;
2523                 rc.use_scalable_fonts = button;
2524         }
2525
2526         unsigned int ivalue = static_cast<unsigned int>
2527                 (fl_get_counter_value(dialog_->counter_zoom));
2528         if (rc.zoom != ivalue) {
2529                 changed = true;
2530                 rc.zoom = ivalue;
2531         }
2532
2533         ivalue = static_cast<unsigned int>
2534                 (fl_get_counter_value(dialog_->counter_dpi));
2535         if (rc.dpi != ivalue) {
2536                 changed = true;
2537                 rc.dpi = ivalue;
2538         }
2539
2540         double dvalue = strToDbl(fl_get_input(dialog_->input_tiny));
2541         if (rc.font_sizes[LyXFont::SIZE_TINY] != dvalue) {
2542                 changed = true;
2543                 rc.font_sizes[LyXFont::SIZE_TINY] = dvalue;
2544         }
2545
2546         dvalue = strToDbl(fl_get_input(dialog_->input_script));
2547         if (rc.font_sizes[LyXFont::SIZE_SCRIPT] != dvalue) {
2548                 changed = true;
2549                 rc.font_sizes[LyXFont::SIZE_SCRIPT] = dvalue;
2550         }
2551
2552         dvalue = strToDbl(fl_get_input(dialog_->input_footnote));
2553         if (rc.font_sizes[LyXFont::SIZE_FOOTNOTE] != dvalue) {
2554                 changed = true;
2555                 rc.font_sizes[LyXFont::SIZE_FOOTNOTE] = dvalue;
2556         }
2557
2558         dvalue = strToDbl(fl_get_input(dialog_->input_small));
2559         if (rc.font_sizes[LyXFont::SIZE_SMALL] != dvalue) {
2560                 changed = true;
2561                 rc.font_sizes[LyXFont::SIZE_SMALL] = dvalue;
2562         }
2563
2564         dvalue = strToDbl(fl_get_input(dialog_->input_normal));
2565         if (rc.font_sizes[LyXFont::SIZE_NORMAL] != dvalue) {
2566                 changed = true;
2567                 rc.font_sizes[LyXFont::SIZE_NORMAL] = dvalue;
2568         }
2569
2570         dvalue = strToDbl(fl_get_input(dialog_->input_large));
2571         if (rc.font_sizes[LyXFont::SIZE_LARGE] != dvalue) {
2572                 changed = true;
2573                 rc.font_sizes[LyXFont::SIZE_LARGE] = dvalue;
2574         }
2575
2576         dvalue = strToDbl(fl_get_input(dialog_->input_larger));
2577         if (rc.font_sizes[LyXFont::SIZE_LARGER] != dvalue) {
2578                 changed = true;
2579                 rc.font_sizes[LyXFont::SIZE_LARGER] = dvalue;
2580         }
2581
2582         dvalue = strToDbl(fl_get_input(dialog_->input_largest));
2583         if (rc.font_sizes[LyXFont::SIZE_LARGEST] != dvalue) {
2584                 changed = true;
2585                 rc.font_sizes[LyXFont::SIZE_LARGEST] = dvalue;
2586         }
2587
2588         dvalue = strToDbl(fl_get_input(dialog_->input_huge));
2589         if (rc.font_sizes[LyXFont::SIZE_HUGE] != dvalue) {
2590                 changed = true;
2591                 rc.font_sizes[LyXFont::SIZE_HUGE] = dvalue;
2592         }
2593
2594         dvalue = strToDbl(fl_get_input(dialog_->input_huger));
2595         if (rc.font_sizes[LyXFont::SIZE_HUGER] != dvalue) {
2596                 changed = true;
2597                 rc.font_sizes[LyXFont::SIZE_HUGER] = dvalue;
2598         }
2599
2600         if (changed) {
2601                 // Now update the buffers
2602                 // Can anything below here affect the redraw process?
2603                 parent_.controller().updateScreenFonts();
2604         }
2605 }
2606
2607
2608 void FormPreferences::ScreenFonts::build()
2609 {
2610         dialog_.reset(build_preferences_screen_fonts(&parent_));
2611
2612         fl_set_counter_step(dialog_->counter_zoom, 1, 10);
2613         fl_set_counter_step(dialog_->counter_dpi,  1, 10);
2614
2615         fl_set_input_return(dialog_->input_roman,           FL_RETURN_CHANGED);
2616         fl_set_input_return(dialog_->input_sans,            FL_RETURN_CHANGED);
2617         fl_set_input_return(dialog_->input_typewriter,      FL_RETURN_CHANGED);
2618         fl_set_input_return(dialog_->input_screen_encoding, FL_RETURN_CHANGED);
2619         fl_set_counter_return(dialog_->counter_zoom,        FL_RETURN_CHANGED);
2620         fl_set_counter_return(dialog_->counter_dpi,         FL_RETURN_CHANGED);
2621         fl_set_input_return(dialog_->input_tiny,            FL_RETURN_CHANGED);
2622         fl_set_input_return(dialog_->input_script,          FL_RETURN_CHANGED);
2623         fl_set_input_return(dialog_->input_footnote,        FL_RETURN_CHANGED);
2624         fl_set_input_return(dialog_->input_small,           FL_RETURN_CHANGED);
2625         fl_set_input_return(dialog_->input_normal,          FL_RETURN_CHANGED);
2626         fl_set_input_return(dialog_->input_large,           FL_RETURN_CHANGED);
2627         fl_set_input_return(dialog_->input_larger,          FL_RETURN_CHANGED);
2628         fl_set_input_return(dialog_->input_largest,         FL_RETURN_CHANGED);
2629         fl_set_input_return(dialog_->input_huge,            FL_RETURN_CHANGED);
2630         fl_set_input_return(dialog_->input_huger,           FL_RETURN_CHANGED);
2631
2632         fl_set_input_filter(dialog_->input_tiny,     fl_unsigned_float_filter);
2633         fl_set_input_filter(dialog_->input_script,   fl_unsigned_float_filter);
2634         fl_set_input_filter(dialog_->input_footnote, fl_unsigned_float_filter);
2635         fl_set_input_filter(dialog_->input_small,    fl_unsigned_float_filter);
2636         fl_set_input_filter(dialog_->input_normal,   fl_unsigned_float_filter);
2637         fl_set_input_filter(dialog_->input_large,    fl_unsigned_float_filter);
2638         fl_set_input_filter(dialog_->input_larger,   fl_unsigned_float_filter);
2639         fl_set_input_filter(dialog_->input_largest,  fl_unsigned_float_filter);
2640         fl_set_input_filter(dialog_->input_huge,     fl_unsigned_float_filter);
2641         fl_set_input_filter(dialog_->input_huger,    fl_unsigned_float_filter);
2642
2643         // set up the feedback mechanism
2644         setPrehandler(dialog_->input_roman);
2645         setPrehandler(dialog_->input_sans);
2646         setPrehandler(dialog_->input_typewriter);
2647         setPrehandler(dialog_->counter_zoom);
2648         setPrehandler(dialog_->counter_dpi);
2649         setPrehandler(dialog_->check_scalable);
2650         setPrehandler(dialog_->input_screen_encoding);
2651         setPrehandler(dialog_->input_tiny);
2652         setPrehandler(dialog_->input_script);
2653         setPrehandler(dialog_->input_footnote);
2654         setPrehandler(dialog_->input_small);
2655         setPrehandler(dialog_->input_large);
2656         setPrehandler(dialog_->input_larger);
2657         setPrehandler(dialog_->input_largest);
2658         setPrehandler(dialog_->input_normal);
2659         setPrehandler(dialog_->input_huge);
2660         setPrehandler(dialog_->input_huger);
2661 }
2662
2663
2664 string const
2665 FormPreferences::ScreenFonts::feedback(FL_OBJECT const * const ob) const
2666 {
2667         if (ob == dialog_->input_roman)
2668                 return LyXRC::getDescription(LyXRC::RC_SCREEN_FONT_ROMAN);
2669         if (ob == dialog_->input_sans)
2670                 return LyXRC::getDescription(LyXRC::RC_SCREEN_FONT_SANS);
2671         if (ob == dialog_->input_typewriter)
2672                 return LyXRC::getDescription(LyXRC::RC_SCREEN_FONT_TYPEWRITER);
2673         if (ob == dialog_->check_scalable)
2674                 return LyXRC::getDescription(LyXRC::RC_SCREEN_FONT_SCALABLE);
2675         if (ob == dialog_->input_screen_encoding)
2676                 return LyXRC::getDescription(LyXRC::RC_SCREEN_FONT_ENCODING);
2677         if (ob == dialog_->counter_zoom)
2678                 return LyXRC::getDescription(LyXRC::RC_SCREEN_ZOOM);
2679         if (ob == dialog_->counter_dpi)
2680                 return LyXRC::getDescription(LyXRC::RC_SCREEN_DPI);
2681         if (ob == dialog_->input_tiny
2682             || ob == dialog_->input_script
2683             || ob == dialog_->input_footnote
2684             || ob == dialog_->input_small
2685             || ob == dialog_->input_large
2686             || ob == dialog_->input_larger
2687             || ob == dialog_->input_larger
2688             || ob == dialog_->input_largest
2689             || ob == dialog_->input_normal
2690             || ob == dialog_->input_huge
2691             || ob == dialog_->input_huger)
2692                 return LyXRC::getDescription(LyXRC::RC_SCREEN_FONT_SIZES);
2693         return string();
2694 }
2695
2696
2697 bool FormPreferences::ScreenFonts::input()
2698 {
2699         bool activate = true;
2700         string str;
2701
2702         // Make sure that all fonts all have positive entries
2703         // Also note that an empty entry is returned as 0.0 by strToDbl
2704         if (0.0 >= strToDbl(fl_get_input(dialog_->input_tiny))
2705             || 0.0 >= strToDbl(fl_get_input(dialog_->input_script))
2706             || 0.0 >= strToDbl(fl_get_input(dialog_->input_footnote))
2707             || 0.0 >= strToDbl(fl_get_input(dialog_->input_small))
2708             || 0.0 >= strToDbl(fl_get_input(dialog_->input_normal))
2709             || 0.0 >= strToDbl(fl_get_input(dialog_->input_large))
2710             || 0.0 >= strToDbl(fl_get_input(dialog_->input_larger))
2711             || 0.0 >= strToDbl(fl_get_input(dialog_->input_largest))
2712             || 0.0 >= strToDbl(fl_get_input(dialog_->input_huge))
2713             || 0.0 >= strToDbl(fl_get_input(dialog_->input_huger))) {
2714                 activate = false;
2715                 str = _("Fonts must be positive!");
2716
2717         } else if (strToDbl(fl_get_input(dialog_->input_tiny)) >
2718                    // Fontsizes -- tiny < script < footnote etc.
2719                    strToDbl(fl_get_input(dialog_->input_script)) ||
2720                    strToDbl(fl_get_input(dialog_->input_script)) >
2721                    strToDbl(fl_get_input(dialog_->input_footnote)) ||
2722                    strToDbl(fl_get_input(dialog_->input_footnote)) >
2723                    strToDbl(fl_get_input(dialog_->input_small)) ||
2724                    strToDbl(fl_get_input(dialog_->input_small)) >
2725                    strToDbl(fl_get_input(dialog_->input_normal)) ||
2726                    strToDbl(fl_get_input(dialog_->input_normal)) >
2727                    strToDbl(fl_get_input(dialog_->input_large)) ||
2728                    strToDbl(fl_get_input(dialog_->input_large)) >
2729                    strToDbl(fl_get_input(dialog_->input_larger)) ||
2730                    strToDbl(fl_get_input(dialog_->input_larger)) >
2731                    strToDbl(fl_get_input(dialog_->input_largest)) ||
2732                    strToDbl(fl_get_input(dialog_->input_largest)) >
2733                    strToDbl(fl_get_input(dialog_->input_huge)) ||
2734                    strToDbl(fl_get_input(dialog_->input_huge)) >
2735                    strToDbl(fl_get_input(dialog_->input_huger))) {
2736                 activate = false;
2737
2738                 str = _("Fonts must be input in the order Tiny > Smallest > Smaller > Small > Normal > Large > Larger > Largest > Huge > Huger.");
2739         }
2740
2741         if (!activate)
2742                 parent_.postWarning(str);
2743
2744         return activate;
2745 }
2746
2747
2748 void FormPreferences::ScreenFonts::update(LyXRC const & rc)
2749 {
2750         fl_set_input(dialog_->input_roman,
2751                      makeFontName(rc.roman_font_name,
2752                                   rc.roman_font_foundry).c_str());
2753         fl_set_input(dialog_->input_sans,
2754                      makeFontName(rc.sans_font_name,
2755                                   rc.sans_font_foundry).c_str());
2756         fl_set_input(dialog_->input_typewriter,
2757                      makeFontName(rc.typewriter_font_name,
2758                                   rc.typewriter_font_foundry).c_str());
2759         fl_set_input(dialog_->input_screen_encoding,
2760                      rc.font_norm.c_str());
2761         fl_set_button(dialog_->check_scalable,
2762                       rc.use_scalable_fonts);
2763         fl_set_counter_value(dialog_->counter_zoom, rc.zoom);
2764         fl_set_counter_value(dialog_->counter_dpi,  rc.dpi);
2765         fl_set_input(dialog_->input_tiny,
2766                      tostr(rc.font_sizes[LyXFont::SIZE_TINY]).c_str());
2767         fl_set_input(dialog_->input_script,
2768                      tostr(rc.font_sizes[LyXFont::SIZE_SCRIPT]).c_str());
2769         fl_set_input(dialog_->input_footnote,
2770                      tostr(rc.font_sizes[LyXFont::SIZE_FOOTNOTE]).c_str());
2771         fl_set_input(dialog_->input_small,
2772                      tostr(rc.font_sizes[LyXFont::SIZE_SMALL]).c_str());
2773         fl_set_input(dialog_->input_normal,
2774                      tostr(rc.font_sizes[LyXFont::SIZE_NORMAL]).c_str());
2775         fl_set_input(dialog_->input_large,
2776                      tostr(rc.font_sizes[LyXFont::SIZE_LARGE]).c_str());
2777         fl_set_input(dialog_->input_larger,
2778                      tostr(rc.font_sizes[LyXFont::SIZE_LARGER]).c_str());
2779         fl_set_input(dialog_->input_largest,
2780                      tostr(rc.font_sizes[LyXFont::SIZE_LARGEST]).c_str());
2781         fl_set_input(dialog_->input_huge,
2782                      tostr(rc.font_sizes[LyXFont::SIZE_HUGE]).c_str());
2783         fl_set_input(dialog_->input_huger,
2784                      tostr(rc.font_sizes[LyXFont::SIZE_HUGER]).c_str());
2785 }
2786
2787
2788
2789 FormPreferences::SpellOptions::SpellOptions(FormPreferences &  p)
2790         : parent_(p)
2791 {}
2792
2793
2794 FD_preferences_spelloptions const * FormPreferences::SpellOptions::dialog()
2795 {
2796         return dialog_.get();
2797 }
2798
2799
2800 void FormPreferences::SpellOptions::apply(LyXRC & rc)
2801 {
2802         string choice = fl_get_choice_text(dialog_->choice_spell_command);
2803         choice = trim(choice);
2804
2805         rc.isp_command = choice;
2806
2807 #if 0
2808         // If spell checker == "none", all other input set to off.
2809         if (fl_get_choice(dialog_->choice_spell_command) == 1) {
2810                 rc.isp_use_alt_lang = false;
2811                 rc.isp_alt_lang.erase();
2812
2813                 rc.isp_use_esc_chars = false;
2814                 rc.isp_esc_chars.erase();
2815
2816                 rc.isp_use_pers_dict = false;
2817                 rc.isp_pers_dict.erase();
2818
2819                 rc.isp_accept_compound = false;
2820                 rc.isp_use_input_encoding = false;
2821         } else {
2822 #else
2823                 int button = fl_get_button(dialog_->check_alt_lang);
2824                 choice = fl_get_input(dialog_->input_alt_lang);
2825                 if (button && choice.empty()) button = 0;
2826                 if (!button) choice.erase();
2827
2828                 rc.isp_use_alt_lang = static_cast<bool>(button);
2829                 rc.isp_alt_lang = choice;
2830
2831                 button = fl_get_button(dialog_->check_escape_chars);
2832                 choice = fl_get_input(dialog_->input_escape_chars);
2833                 if (button && choice.empty()) button = 0;
2834                 if (!button) choice.erase();
2835
2836                 rc.isp_use_esc_chars = static_cast<bool>(button);
2837                 rc.isp_esc_chars = choice;
2838
2839                 button = fl_get_button(dialog_->check_personal_dict);
2840                 choice = fl_get_input(dialog_->input_personal_dict);
2841                 if (button && choice.empty()) button = 0;
2842                 if (!button) choice.erase();
2843
2844                 rc.isp_use_pers_dict = static_cast<bool>(button);
2845                 rc.isp_pers_dict = choice;
2846
2847                 button = fl_get_button(dialog_->check_compound_words);
2848                 rc.isp_accept_compound = static_cast<bool>(button);
2849
2850                 button = fl_get_button(dialog_->check_input_enc);
2851                 rc.isp_use_input_encoding = static_cast<bool>(button);
2852 #endif
2853 #if 0
2854         }
2855 #endif
2856
2857         // Reset view
2858         update(rc);
2859 }
2860
2861
2862 void FormPreferences::SpellOptions::build()
2863 {
2864         dialog_.reset(build_preferences_spelloptions(&parent_));
2865
2866         fl_addto_choice(dialog_->choice_spell_command,
2867                         _(" ispell | aspell "));
2868         fl_set_input_return(dialog_->input_alt_lang,      FL_RETURN_CHANGED);
2869         fl_set_input_return(dialog_->input_escape_chars,  FL_RETURN_CHANGED);
2870         fl_set_input_return(dialog_->input_personal_dict, FL_RETURN_CHANGED);
2871
2872         // set up the feedback mechanism
2873         setPrehandler(dialog_->choice_spell_command);
2874         setPrehandler(dialog_->check_alt_lang);
2875         setPrehandler(dialog_->input_alt_lang);
2876         setPrehandler(dialog_->check_escape_chars);
2877         setPrehandler(dialog_->input_escape_chars);
2878         setPrehandler(dialog_->check_personal_dict);
2879         setPrehandler(dialog_->input_personal_dict);
2880         setPrehandler(dialog_->button_personal_dict);
2881         setPrehandler(dialog_->check_compound_words);
2882         setPrehandler(dialog_->check_input_enc);
2883 }
2884
2885
2886 string const
2887 FormPreferences::SpellOptions::feedback(FL_OBJECT const * const ob) const
2888 {
2889         if (ob == dialog_->choice_spell_command)
2890                 return LyXRC::getDescription(LyXRC::RC_SPELL_COMMAND);
2891         if (ob == dialog_->check_alt_lang)
2892                 return LyXRC::getDescription(LyXRC::RC_USE_ALT_LANG);
2893         if (ob == dialog_->input_alt_lang)
2894                 return LyXRC::getDescription(LyXRC::RC_ALT_LANG);
2895         if (ob == dialog_->check_escape_chars)
2896                 return LyXRC::getDescription(LyXRC::RC_USE_ESC_CHARS);
2897         if (ob == dialog_->input_escape_chars)
2898                 return LyXRC::getDescription(LyXRC::RC_ESC_CHARS);
2899         if (ob == dialog_->check_personal_dict)
2900                 return LyXRC::getDescription(LyXRC::RC_USE_PERS_DICT);
2901         if (ob == dialog_->input_personal_dict)
2902                 return LyXRC::getDescription(LyXRC::RC_PERS_DICT);
2903         if (ob == dialog_->check_compound_words)
2904                 return LyXRC::getDescription(LyXRC::RC_ACCEPT_COMPOUND);
2905         if (ob == dialog_->check_input_enc)
2906                 return LyXRC::getDescription(LyXRC::RC_USE_INP_ENC);
2907         return string();
2908 }
2909
2910
2911 bool FormPreferences::SpellOptions::input(FL_OBJECT const * const ob)
2912 {
2913         // !ob if function is called from updateSpellOptions() to de/activate
2914         // objects,
2915         // otherwise the function is called by an xforms CB via input().
2916
2917 #if 0
2918         // If spell checker == "none", disable all input.
2919         if (!ob || ob == dialog_->choice_spell_command) {
2920                 if (fl_get_choice(dialog_->choice_spell_command) == 1) {
2921                         fl_deactivate_object(dialog_->check_alt_lang);
2922                         fl_deactivate_object(dialog_->input_alt_lang);
2923                         fl_deactivate_object(dialog_->check_escape_chars);
2924                         fl_deactivate_object(dialog_->input_escape_chars);
2925                         fl_deactivate_object(dialog_->check_personal_dict);
2926                         fl_deactivate_object(dialog_->input_personal_dict);
2927                         fl_deactivate_object(dialog_->check_compound_words);
2928                         fl_deactivate_object(dialog_->check_input_enc);
2929                         return true;
2930                 } else {
2931                         fl_activate_object(dialog_->check_alt_lang);
2932                         fl_activate_object(dialog_->check_escape_chars);
2933                         fl_activate_object(dialog_->check_personal_dict);
2934                         fl_activate_object(dialog_->check_compound_words);
2935                         fl_activate_object(dialog_->check_input_enc);
2936                 }
2937         }
2938 #endif
2939
2940         if (!ob || ob == dialog_->check_alt_lang) {
2941                 bool const enable = fl_get_button(dialog_->check_alt_lang);
2942                 setEnabled(dialog_->input_alt_lang, enable);
2943         }
2944
2945         if (!ob || ob == dialog_->check_escape_chars) {
2946                 bool const enable = fl_get_button(dialog_->check_escape_chars);
2947                 setEnabled(dialog_->input_escape_chars, enable);
2948         }
2949
2950         if (!ob || ob == dialog_->check_personal_dict) {
2951                 bool const enable = fl_get_button(dialog_->check_personal_dict);
2952                 setEnabled(dialog_->input_personal_dict, enable);
2953         }
2954
2955         if (ob == dialog_->button_personal_dict) {
2956                 string f = parent_.controller().browsedict(
2957                         fl_get_input(dialog_->input_personal_dict));
2958                 fl_set_input(dialog_->input_personal_dict, f.c_str());
2959         }
2960
2961         return true; // All input is valid!
2962 }
2963
2964
2965 void FormPreferences::SpellOptions::update(LyXRC const & rc)
2966 {
2967         int choice = 1;
2968 #if 0
2969         if (rc.isp_command == "none")
2970                 choice = 1;
2971         else if (rc.isp_command == "ispell")
2972                 choice = 2;
2973         else if (rc.isp_command == "aspell")
2974                 choice = 3;
2975 #else
2976         if (rc.isp_command == "ispell")
2977                 choice = 1;
2978         else if (rc.isp_command == "aspell")
2979                 choice = 2;
2980 #endif
2981         fl_set_choice(dialog_->choice_spell_command, choice);
2982
2983         string str;
2984         if (rc.isp_use_alt_lang)
2985                 str = rc.isp_alt_lang;
2986
2987         fl_set_button(dialog_->check_alt_lang,
2988                       rc.isp_use_alt_lang);
2989         fl_set_input(dialog_->input_alt_lang, str.c_str());
2990
2991         str.erase();
2992         if (rc.isp_use_esc_chars)
2993                 str = rc.isp_esc_chars;
2994
2995         fl_set_button(dialog_->check_escape_chars,
2996                       rc.isp_use_esc_chars);
2997         fl_set_input(dialog_->input_escape_chars, str.c_str());
2998
2999         str.erase();
3000         if (rc.isp_use_pers_dict)
3001                 str = rc.isp_pers_dict;
3002
3003         fl_set_button(dialog_->check_personal_dict,
3004                       rc.isp_use_pers_dict);
3005         fl_set_input(dialog_->input_personal_dict, str.c_str());
3006
3007         fl_set_button(dialog_->check_compound_words,
3008                       rc.isp_accept_compound);
3009         fl_set_button(dialog_->check_input_enc,
3010                       rc.isp_use_input_encoding);
3011
3012         // Activate/Deactivate the input fields dependent on the state of the
3013         // buttons.
3014         input(0);
3015 }