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