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