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