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