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