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