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