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