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