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