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