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