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