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