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