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