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