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