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