]> git.lyx.org Git - features.git/blob - src/frontends/xforms/FormPreferences.C
John's patches (except for [PATCH] fix quit etc. from inset about which I
[features.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_text(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
1957         fl_addto_choice(dialog_->choice_default_papersize,
1958                         _(" default | US letter | legal | executive | A3 | A4 | A5 | B5 "));
1959
1960         // set up the feedback mechanism
1961         setPreHandler(dialog_->counter_line_len);
1962         setPreHandler(dialog_->input_tex_encoding);
1963         setPreHandler(dialog_->choice_default_papersize);
1964         setPreHandler(dialog_->input_ascii_roff);
1965         setPreHandler(dialog_->input_checktex);
1966         setPreHandler(dialog_->input_paperoption);
1967 }
1968
1969
1970 string const
1971 FormPreferences::OutputsMisc::feedback(FL_OBJECT const * const ob) const
1972 {
1973         string str;
1974
1975         if (ob == dialog_->counter_line_len)
1976                 str = lyxrc.getDescription(LyXRC::RC_ASCII_LINELEN);
1977         else if (ob == dialog_->input_tex_encoding)
1978                 str = lyxrc.getDescription(LyXRC::RC_FONT_ENCODING);
1979         else if (ob == dialog_->input_ascii_roff)
1980                 str = lyxrc.getDescription(LyXRC::RC_ASCIIROFF_COMMAND);
1981         else if (ob == dialog_->input_checktex)
1982                 str = lyxrc.getDescription(LyXRC::RC_CHKTEX_COMMAND);
1983         else if (ob == dialog_->choice_default_papersize)
1984                 str = lyxrc.getDescription(LyXRC::RC_DEFAULT_PAPERSIZE);
1985         else if (ob == dialog_->input_paperoption)
1986                 str = lyxrc.getDescription(LyXRC::RC_VIEWDVI_PAPEROPTION);
1987
1988         return str;
1989 }
1990
1991
1992 void FormPreferences::OutputsMisc::update()
1993 {
1994         fl_set_counter_value(dialog_->counter_line_len,
1995                              lyxrc.ascii_linelen);
1996         fl_set_input(dialog_->input_tex_encoding,
1997                      lyxrc.fontenc.c_str());
1998         fl_set_choice(dialog_->choice_default_papersize,
1999                       lyxrc.default_papersize+1);
2000         fl_set_input(dialog_->input_ascii_roff,
2001                      lyxrc.ascii_roff_command.c_str());
2002         fl_set_input(dialog_->input_checktex,
2003                      lyxrc.chktex_command.c_str());
2004         fl_set_input(dialog_->input_paperoption,
2005                      lyxrc.view_dvi_paper_option.c_str());
2006 }
2007
2008
2009 FormPreferences::Paths::Paths( FormPreferences &  p )
2010         : parent_(p)
2011 {}
2012
2013
2014 FD_form_paths const * FormPreferences::Paths::dialog()
2015 {
2016         return dialog_.get();
2017 }
2018
2019
2020 void FormPreferences::Paths::apply()
2021 {
2022         lyxrc.document_path = fl_get_input(dialog_->input_default_path);
2023         lyxrc.template_path = fl_get_input(dialog_->input_template_path);
2024
2025         int button = fl_get_button(dialog_->check_use_temp_dir);
2026         string str  = fl_get_input(dialog_->input_temp_dir);
2027         if (!button) str.erase();
2028
2029         lyxrc.use_tempdir = button;
2030         lyxrc.tempdir_path = str;
2031
2032         button = fl_get_button(dialog_->check_last_files);
2033         str = fl_get_input(dialog_->input_lastfiles);
2034         if (!button) str.erase();
2035         
2036         lyxrc.check_lastfiles = button;
2037         lyxrc.lastfiles = str;
2038         lyxrc.num_lastfiles = static_cast<unsigned int>
2039                 (fl_get_counter_value(dialog_->counter_lastfiles));
2040
2041         button = fl_get_button(dialog_->check_make_backups);
2042         str = fl_get_input(dialog_->input_backup_path);
2043         if (!button) str.erase();
2044
2045         lyxrc.make_backup = button;
2046         lyxrc.backupdir_path = str;
2047
2048         lyxrc.lyxpipes = fl_get_input(dialog_->input_serverpipe);
2049
2050         // update view
2051         update();
2052 }
2053
2054
2055 void FormPreferences::Paths::build()
2056 {
2057         dialog_.reset(parent_.build_paths());
2058
2059         fl_set_input_return(dialog_->input_default_path, FL_RETURN_CHANGED);
2060         fl_set_input_return(dialog_->input_template_path, FL_RETURN_CHANGED);
2061         fl_set_input_return(dialog_->input_temp_dir, FL_RETURN_CHANGED);
2062         fl_set_input_return(dialog_->input_lastfiles, FL_RETURN_CHANGED);
2063         fl_set_input_return(dialog_->input_backup_path, FL_RETURN_CHANGED);
2064         fl_set_counter_return(dialog_->counter_lastfiles, FL_RETURN_CHANGED);
2065         fl_set_input_return(dialog_->input_serverpipe, FL_RETURN_CHANGED);
2066
2067         // set up the feedback mechanism
2068         setPreHandler(dialog_->input_default_path);
2069         setPreHandler(dialog_->counter_lastfiles);
2070         setPreHandler(dialog_->input_template_path);
2071         setPreHandler(dialog_->check_last_files);
2072         setPreHandler(dialog_->input_lastfiles);
2073         setPreHandler(dialog_->check_make_backups);
2074         setPreHandler(dialog_->input_backup_path);
2075         setPreHandler(dialog_->input_serverpipe);
2076         setPreHandler(dialog_->input_temp_dir);
2077         setPreHandler(dialog_->check_use_temp_dir);
2078 }
2079
2080
2081 string const
2082 FormPreferences::Paths::feedback(FL_OBJECT const * const ob) const
2083 {
2084         string str;
2085
2086         if (ob == dialog_->input_default_path)
2087                 str = lyxrc.getDescription(LyXRC::RC_DOCUMENTPATH);
2088         else if (ob == dialog_->input_template_path)
2089                 str = lyxrc.getDescription(LyXRC::RC_TEMPLATEPATH);
2090         else if (ob == dialog_->check_use_temp_dir)
2091                 str = lyxrc.getDescription(LyXRC::RC_USETEMPDIR);
2092         else if (ob == dialog_->input_temp_dir)
2093                 str = lyxrc.getDescription(LyXRC::RC_TEMPDIRPATH);
2094         else if (ob == dialog_->check_last_files)
2095                 str = lyxrc.getDescription(LyXRC::RC_CHECKLASTFILES);
2096         else if (ob == dialog_->input_lastfiles)
2097                 str = lyxrc.getDescription(LyXRC::RC_LASTFILES);
2098         else if (ob == dialog_->counter_lastfiles)
2099                 str = lyxrc.getDescription(LyXRC::RC_NUMLASTFILES);
2100         else if (ob == dialog_->check_make_backups)
2101                 str = lyxrc.getDescription(LyXRC::RC_MAKE_BACKUP);
2102         else if (ob == dialog_->input_backup_path)
2103                 str = lyxrc.getDescription(LyXRC::RC_BACKUPDIR_PATH);
2104         else if (ob == dialog_->input_serverpipe) {
2105                 str = lyxrc.getDescription(LyXRC::RC_SERVERPIPE);
2106         }
2107
2108         return str;
2109 }
2110
2111
2112 bool FormPreferences::Paths::input(FL_OBJECT const * const ob)
2113 {
2114         bool activate = true;
2115         
2116         // !ob if function is called from Paths::update() to de/activate
2117         // objects,
2118         // otherwise the function is called by an xforms CB via input().
2119         if (!ob || ob == dialog_->check_use_temp_dir) {
2120                 bool const enable = fl_get_button(dialog_->check_use_temp_dir);
2121                 setEnabled(dialog_->input_temp_dir, enable);
2122         }
2123
2124         if (!ob || ob == dialog_->check_last_files) {
2125                 bool const enable = fl_get_button(dialog_->check_last_files);
2126                 setEnabled(dialog_->input_lastfiles, enable);
2127         }
2128
2129         if (!ob || ob == dialog_->check_make_backups) {
2130                 bool const enable = fl_get_button(dialog_->check_make_backups);
2131                 setEnabled(dialog_->input_backup_path, enable);
2132         }
2133
2134         if (!ob || ob == dialog_->input_default_path) {
2135                 string const name = fl_get_input(dialog_->input_default_path);
2136                 if (!RWInfo::WriteableDir(name)) {
2137                         parent_.printWarning(RWInfo::ErrorMessage());
2138                         return false;
2139                 }
2140         }
2141
2142         if (!ob || ob == dialog_->input_template_path) {
2143                 string const name = fl_get_input(dialog_->input_template_path);
2144                 if (!RWInfo::ReadableDir(name)) {
2145                         parent_.printWarning(RWInfo::ErrorMessage());
2146                         return false;
2147                 }
2148         }
2149
2150         if (!ob || ob == dialog_->input_temp_dir) {
2151                 string const name = fl_get_input(dialog_->input_temp_dir);
2152                 if (fl_get_button(dialog_->check_make_backups)
2153                     && !name.empty()
2154                     && !RWInfo::WriteableDir(name)) {
2155                         parent_.printWarning(RWInfo::ErrorMessage());
2156                         return false;
2157                 }
2158         }
2159
2160         if (!ob || ob == dialog_->input_backup_path) {
2161                 string const name = fl_get_input(dialog_->input_backup_path);
2162                 if (fl_get_button(dialog_->check_make_backups)
2163                     && !name.empty()
2164                     && !RWInfo::WriteableDir(name)) {
2165                         parent_.printWarning(RWInfo::ErrorMessage());
2166                         return false;
2167                 }
2168         }
2169
2170         if (!ob || ob == dialog_->input_lastfiles) {
2171                 string const name = fl_get_input(dialog_->input_lastfiles);
2172                 if (fl_get_button(dialog_->check_last_files)
2173                     && !name.empty()
2174                     && !RWInfo::WriteableFile(name)) {
2175                         parent_.printWarning(RWInfo::ErrorMessage());
2176                         return false;
2177                 }
2178         }
2179
2180         if (!ob || ob == dialog_->input_serverpipe) {
2181                 string const name = fl_get_input(dialog_->input_serverpipe);
2182                 if (!name.empty()) {
2183                         // strip off the extension
2184                         string const str = ChangeExtension(name, "");
2185                         if (!RWInfo::WriteableFile(str + ".in")) {
2186                                 parent_.printWarning(RWInfo::ErrorMessage());
2187                                 return false;
2188                         }
2189                         if (!RWInfo::WriteableFile(str + ".out")) {
2190                                 parent_.printWarning(RWInfo::ErrorMessage());
2191                                 return false;
2192                         }
2193                 }
2194         }
2195
2196         if (ob == dialog_->button_default_path_browse) {
2197                 parent_.browse(dialog_->input_default_path,
2198                                N_("Default path"), string(),
2199                                make_pair(string(), string()),
2200                                make_pair(string(), string()));
2201         } else if (ob == dialog_->button_template_path_browse) {
2202                 parent_.browse(dialog_->input_template_path,
2203                                N_("Template path"), string(),
2204                                make_pair(string(), string()),
2205                                make_pair(string(), string()));
2206         } else if (ob == dialog_->button_temp_dir_browse) {
2207                 parent_.browse(dialog_->input_temp_dir,
2208                                N_("Temp dir"), string(),
2209                                make_pair(string(), string()),
2210                                make_pair(string(), string()));
2211         } else if (ob == dialog_->button_lastfiles_browse) {
2212                 pair<string, string> dir(_("User"), user_lyxdir);
2213
2214                 parent_.browse(dialog_->input_lastfiles,
2215                                N_("Lastfiles"), string(), dir,
2216                                make_pair(string(), string()));
2217         } else if (ob == dialog_->button_backup_path_browse) {
2218                 parent_.browse(dialog_->input_backup_path,
2219                                N_("Backup path"), string(),
2220                                make_pair(string(), string()),
2221                                make_pair(string(), string()));
2222         } else if (ob == dialog_->button_serverpipe_browse) {
2223                 parent_.browse(dialog_->input_serverpipe,
2224                                N_("LyX Server pipes"), string(),
2225                                make_pair(string(), string()),
2226                                make_pair(string(), string()));
2227         }
2228         
2229         return activate;
2230 }
2231
2232
2233 void FormPreferences::Paths::update()
2234 {
2235         fl_set_input(dialog_->input_default_path,
2236                      lyxrc.document_path.c_str());
2237         fl_set_input(dialog_->input_template_path,
2238                      lyxrc.template_path.c_str());
2239
2240         string str;
2241         if (lyxrc.make_backup) str = lyxrc.backupdir_path;
2242
2243         fl_set_button(dialog_->check_make_backups,
2244                       lyxrc.make_backup);
2245         fl_set_input(dialog_->input_backup_path, str.c_str());
2246
2247         str.erase();
2248         if (lyxrc.use_tempdir) str = lyxrc.tempdir_path;
2249
2250         fl_set_button(dialog_->check_use_temp_dir,
2251                       lyxrc.use_tempdir);
2252         fl_set_input(dialog_->input_temp_dir, str.c_str());
2253
2254         str.erase();
2255         if (lyxrc.check_lastfiles) str = lyxrc.lastfiles;
2256
2257         fl_set_button(dialog_->check_last_files,
2258                       lyxrc.check_lastfiles);           
2259         fl_set_input(dialog_->input_lastfiles, str.c_str());
2260         fl_set_counter_value(dialog_->counter_lastfiles,
2261                              lyxrc.num_lastfiles);
2262
2263         fl_set_input(dialog_->input_serverpipe, lyxrc.lyxpipes.c_str());
2264
2265         // Activate/Deactivate the input fields dependent on the state of the
2266         // buttons.
2267         input(0);
2268 }
2269
2270
2271 FormPreferences::Printer::Printer(FormPreferences &  p)
2272         : parent_(p)
2273 {}
2274
2275
2276 FD_form_printer const * FormPreferences::Printer::dialog()
2277 {
2278         return dialog_.get();
2279 }
2280
2281
2282 void FormPreferences::Printer::apply() const
2283 {
2284         lyxrc.print_adapt_output = fl_get_button(dialog_->check_adapt_output);
2285         lyxrc.print_command = fl_get_input(dialog_->input_command);
2286         lyxrc.print_pagerange_flag = fl_get_input(dialog_->input_page_range);
2287         lyxrc.print_copies_flag = fl_get_input(dialog_->input_copies);
2288         lyxrc.print_reverse_flag = fl_get_input(dialog_->input_reverse);
2289         lyxrc.print_to_printer = fl_get_input(dialog_->input_to_printer);
2290         lyxrc.print_file_extension =
2291                 fl_get_input(dialog_->input_file_extension);
2292         lyxrc.print_spool_command =
2293                 fl_get_input(dialog_->input_spool_command);
2294         lyxrc.print_paper_flag = fl_get_input(dialog_->input_paper_type);
2295         lyxrc.print_evenpage_flag = fl_get_input(dialog_->input_even_pages);
2296         lyxrc.print_oddpage_flag = fl_get_input(dialog_->input_odd_pages);
2297         lyxrc.print_collcopies_flag = fl_get_input(dialog_->input_collated);
2298         lyxrc.print_landscape_flag = fl_get_input(dialog_->input_landscape);
2299         lyxrc.print_to_file = fl_get_input(dialog_->input_to_file);
2300         lyxrc.print_extra_options =
2301                 fl_get_input(dialog_->input_extra_options);
2302         lyxrc.print_spool_printerprefix =
2303                 fl_get_input(dialog_->input_spool_prefix);
2304         lyxrc.print_paper_dimension_flag =
2305                 fl_get_input(dialog_->input_paper_size);
2306         lyxrc.printer = fl_get_input(dialog_->input_name);
2307 }
2308
2309
2310 string const
2311 FormPreferences::Printer::feedback(FL_OBJECT const * const ob) const
2312 {
2313         string str;
2314
2315         if (ob == dialog_->input_command)
2316                 str = lyxrc.getDescription(LyXRC::RC_PRINT_COMMAND);
2317         else if (ob == dialog_->check_adapt_output)
2318                 str = lyxrc.getDescription(LyXRC::RC_PRINT_ADAPTOUTPUT);
2319         else if (ob == dialog_->input_to_printer)
2320                 str = lyxrc.getDescription(LyXRC::RC_PRINTTOPRINTER);
2321         else if (ob == dialog_->input_to_file)
2322                 str = lyxrc.getDescription(LyXRC::RC_PRINTTOFILE);
2323         else if (ob == dialog_->input_file_extension)
2324                 str = lyxrc.getDescription(LyXRC::RC_PRINTFILEEXTENSION);
2325         else if (ob == dialog_->input_extra_options)
2326                 str = lyxrc.getDescription(LyXRC::RC_PRINTEXSTRAOPTIONS);
2327         else if (ob == dialog_->input_spool_command)
2328                 str = lyxrc.getDescription(LyXRC::RC_PRINTSPOOL_COMMAND);
2329         else if (ob == dialog_->input_spool_prefix)
2330                 str = lyxrc.getDescription(LyXRC::RC_PRINTSPOOL_PRINTERPREFIX);
2331         else if (ob == dialog_->input_name)
2332                 str = lyxrc.getDescription(LyXRC::RC_PRINTER);
2333         else if (ob == dialog_->input_even_pages)
2334                 str = lyxrc.getDescription(LyXRC::RC_PRINTEVENPAGEFLAG);
2335         else if (ob == dialog_->input_odd_pages)
2336                 str = lyxrc.getDescription(LyXRC::RC_PRINTODDPAGEFLAG);
2337         else if (ob == dialog_->input_page_range)
2338                 str = lyxrc.getDescription(LyXRC::RC_PRINTPAGERANGEFLAG);
2339         else if (ob == dialog_->input_reverse)
2340                 str = lyxrc.getDescription(LyXRC::RC_PRINTREVERSEFLAG);
2341         else if (ob == dialog_->input_landscape)
2342                 str = lyxrc.getDescription(LyXRC::RC_PRINTLANDSCAPEFLAG);
2343         else if (ob == dialog_->input_copies)
2344                 str = lyxrc.getDescription(LyXRC::RC_PRINTCOPIESFLAG);
2345         else if (ob == dialog_->input_collated)
2346                 str = lyxrc.getDescription(LyXRC::RC_PRINTCOLLCOPIESFLAG);
2347         else if (ob == dialog_->input_paper_type)
2348                 str = lyxrc.getDescription(LyXRC::RC_PRINTPAPERFLAG);
2349         else if (ob == dialog_->input_paper_size)
2350                 str = lyxrc.getDescription(LyXRC::RC_PRINTPAPERDIMENSIONFLAG);
2351
2352         return str;
2353 }
2354
2355
2356 void FormPreferences::Printer::build()
2357 {
2358         dialog_.reset(parent_.build_printer());
2359
2360         fl_set_input_return(dialog_->input_command, FL_RETURN_CHANGED);
2361         fl_set_input_return(dialog_->input_page_range, FL_RETURN_CHANGED);
2362         fl_set_input_return(dialog_->input_copies, FL_RETURN_CHANGED);
2363         fl_set_input_return(dialog_->input_reverse, FL_RETURN_CHANGED);
2364         fl_set_input_return(dialog_->input_to_printer, FL_RETURN_CHANGED);
2365         fl_set_input_return(dialog_->input_file_extension, FL_RETURN_CHANGED);
2366         fl_set_input_return(dialog_->input_spool_command, FL_RETURN_CHANGED);
2367         fl_set_input_return(dialog_->input_paper_type, FL_RETURN_CHANGED);
2368         fl_set_input_return(dialog_->input_even_pages, FL_RETURN_CHANGED);
2369         fl_set_input_return(dialog_->input_odd_pages, FL_RETURN_CHANGED);
2370         fl_set_input_return(dialog_->input_collated, FL_RETURN_CHANGED);
2371         fl_set_input_return(dialog_->input_landscape, FL_RETURN_CHANGED);
2372         fl_set_input_return(dialog_->input_to_file, FL_RETURN_CHANGED);
2373         fl_set_input_return(dialog_->input_extra_options, FL_RETURN_CHANGED);
2374         fl_set_input_return(dialog_->input_spool_prefix, FL_RETURN_CHANGED);
2375         fl_set_input_return(dialog_->input_paper_size, FL_RETURN_CHANGED);
2376         fl_set_input_return(dialog_->input_name, FL_RETURN_CHANGED);
2377
2378         // set up the feedback mechanism
2379         setPreHandler(dialog_->input_command);
2380         setPreHandler(dialog_->input_page_range);
2381         setPreHandler(dialog_->input_copies);
2382         setPreHandler(dialog_->input_reverse);
2383         setPreHandler(dialog_->input_to_printer);
2384         setPreHandler(dialog_->input_file_extension);
2385         setPreHandler(dialog_->input_spool_command);
2386         setPreHandler(dialog_->input_paper_type);
2387         setPreHandler(dialog_->input_even_pages);
2388         setPreHandler(dialog_->input_odd_pages);
2389         setPreHandler(dialog_->input_collated);
2390         setPreHandler(dialog_->input_landscape);
2391         setPreHandler(dialog_->input_to_file);
2392         setPreHandler(dialog_->input_extra_options);
2393         setPreHandler(dialog_->input_spool_prefix);
2394         setPreHandler(dialog_->input_paper_size);
2395         setPreHandler(dialog_->input_name);
2396         setPreHandler(dialog_->check_adapt_output);
2397 }
2398
2399
2400 void FormPreferences::Printer::update()
2401 {
2402         fl_set_button(dialog_->check_adapt_output,
2403                       lyxrc.print_adapt_output);
2404         fl_set_input(dialog_->input_command,
2405                      lyxrc.print_command.c_str());
2406         fl_set_input(dialog_->input_page_range,
2407                      lyxrc.print_pagerange_flag.c_str());
2408         fl_set_input(dialog_->input_copies,
2409                      lyxrc.print_copies_flag.c_str());
2410         fl_set_input(dialog_->input_reverse,
2411                      lyxrc.print_reverse_flag.c_str());
2412         fl_set_input(dialog_->input_to_printer,
2413                      lyxrc.print_to_printer.c_str());
2414         fl_set_input(dialog_->input_file_extension,
2415                      lyxrc.print_file_extension.c_str());
2416         fl_set_input(dialog_->input_spool_command,
2417                      lyxrc.print_spool_command.c_str());
2418         fl_set_input(dialog_->input_paper_type,
2419                      lyxrc.print_paper_flag.c_str());
2420         fl_set_input(dialog_->input_even_pages,
2421                      lyxrc.print_evenpage_flag.c_str());
2422         fl_set_input(dialog_->input_odd_pages,
2423                      lyxrc.print_oddpage_flag.c_str());
2424         fl_set_input(dialog_->input_collated,
2425                      lyxrc.print_collcopies_flag.c_str());
2426         fl_set_input(dialog_->input_landscape,
2427                      lyxrc.print_landscape_flag.c_str());
2428         fl_set_input(dialog_->input_to_file,
2429                      lyxrc.print_to_file.c_str());
2430         fl_set_input(dialog_->input_extra_options,
2431                      lyxrc.print_extra_options.c_str());
2432         fl_set_input(dialog_->input_spool_prefix,
2433                      lyxrc.print_spool_printerprefix.c_str());
2434         fl_set_input(dialog_->input_paper_size,
2435                      lyxrc.print_paper_dimension_flag.c_str());
2436         fl_set_input(dialog_->input_name,
2437                      lyxrc.printer.c_str());
2438 }
2439
2440
2441 FormPreferences::ScreenFonts::ScreenFonts( FormPreferences &  p )
2442         : parent_(p)
2443 {}
2444
2445
2446 FD_form_screen_fonts const * FormPreferences::ScreenFonts::dialog()
2447 {
2448         return dialog_.get();
2449 }
2450
2451
2452 void FormPreferences::ScreenFonts::apply() const
2453 {
2454         bool changed = false;
2455
2456         string str = fl_get_input(dialog_->input_roman);
2457         if (lyxrc.roman_font_name != str) {
2458                 changed = true;
2459                 lyxrc.roman_font_name = str;
2460         }
2461
2462         str = fl_get_input(dialog_->input_sans);
2463         if (lyxrc.sans_font_name != str) {
2464                 changed = true;
2465                 lyxrc.sans_font_name = str;
2466         }
2467
2468         str = fl_get_input(dialog_->input_typewriter);
2469         if (lyxrc.typewriter_font_name != str) {
2470                 changed = true;
2471                 lyxrc.typewriter_font_name = str;
2472         }
2473
2474         str = fl_get_input(dialog_->input_screen_encoding);
2475         if (lyxrc.font_norm != str) {
2476                 changed = true;
2477                 lyxrc.font_norm = str;
2478         }
2479
2480         bool button = fl_get_button(dialog_->check_scalable);
2481         if (lyxrc.use_scalable_fonts != button) {
2482                 changed = true;
2483                 lyxrc.use_scalable_fonts = button;
2484         }
2485
2486         unsigned int ivalue = static_cast<unsigned int>
2487                 (fl_get_counter_value(dialog_->counter_zoom));
2488         if (lyxrc.zoom != ivalue) {
2489                 changed = true;
2490                 lyxrc.zoom = ivalue;
2491         }
2492
2493         ivalue = static_cast<unsigned int>
2494                 (fl_get_counter_value(dialog_->counter_dpi));
2495         if (lyxrc.dpi != ivalue) {
2496                 changed = true;
2497                 lyxrc.dpi = ivalue;
2498         }
2499         
2500         double dvalue = strToDbl(fl_get_input(dialog_->input_tiny));
2501         if (lyxrc.font_sizes[LyXFont::SIZE_TINY] != dvalue) {
2502                 changed = true;
2503                 lyxrc.font_sizes[LyXFont::SIZE_TINY] = dvalue;
2504         }
2505
2506         dvalue = strToDbl(fl_get_input(dialog_->input_script));
2507         if (lyxrc.font_sizes[LyXFont::SIZE_SCRIPT] != dvalue) {
2508                 changed = true;
2509                 lyxrc.font_sizes[LyXFont::SIZE_SCRIPT] = dvalue;
2510         }
2511
2512         dvalue = strToDbl(fl_get_input(dialog_->input_footnote));
2513         if (lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE] != dvalue) {
2514                 changed = true;
2515                 lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE] = dvalue;
2516         }
2517
2518         dvalue = strToDbl(fl_get_input(dialog_->input_small));
2519         if (lyxrc.font_sizes[LyXFont::SIZE_SMALL] != dvalue) {
2520                 changed = true;
2521                 lyxrc.font_sizes[LyXFont::SIZE_SMALL] = dvalue;
2522         }
2523
2524         dvalue = strToDbl(fl_get_input(dialog_->input_normal));
2525         if (lyxrc.font_sizes[LyXFont::SIZE_NORMAL] != dvalue) {
2526                 changed = true;
2527                 lyxrc.font_sizes[LyXFont::SIZE_NORMAL] = dvalue;
2528         }
2529
2530         dvalue = strToDbl(fl_get_input(dialog_->input_large));
2531         if (lyxrc.font_sizes[LyXFont::SIZE_LARGE] != dvalue) {
2532                 changed = true;
2533                 lyxrc.font_sizes[LyXFont::SIZE_LARGE] = dvalue;
2534         }
2535
2536         dvalue = strToDbl(fl_get_input(dialog_->input_larger));
2537         if (lyxrc.font_sizes[LyXFont::SIZE_LARGER] != dvalue) {
2538                 changed = true;
2539                 lyxrc.font_sizes[LyXFont::SIZE_LARGER] = dvalue;
2540         }
2541
2542         dvalue = strToDbl(fl_get_input(dialog_->input_largest));
2543         if (lyxrc.font_sizes[LyXFont::SIZE_LARGEST] != dvalue) {
2544                 changed = true;
2545                 lyxrc.font_sizes[LyXFont::SIZE_LARGEST] = dvalue;
2546         }
2547
2548         dvalue = strToDbl(fl_get_input(dialog_->input_huge));
2549         if (lyxrc.font_sizes[LyXFont::SIZE_HUGE] != dvalue) {
2550                 changed = true;
2551                 lyxrc.font_sizes[LyXFont::SIZE_HUGE] = dvalue;
2552         }
2553
2554         dvalue = strToDbl(fl_get_input(dialog_->input_huger));
2555         if (lyxrc.font_sizes[LyXFont::SIZE_HUGER] != dvalue) {
2556                 changed = true;
2557                 lyxrc.font_sizes[LyXFont::SIZE_HUGER] = dvalue;
2558         }
2559
2560         if (changed) {
2561                 // Now update the buffers
2562                 // Can anything below here affect the redraw process?
2563                 parent_.lv_->getLyXFunc()->dispatch(LFUN_SCREEN_FONT_UPDATE);
2564         }
2565 }
2566
2567
2568 void FormPreferences::ScreenFonts::build()
2569 {
2570         dialog_.reset(parent_.build_screen_fonts());
2571
2572         fl_set_counter_step(dialog_->counter_zoom, 1, 10);
2573         fl_set_counter_step(dialog_->counter_dpi,  1, 10);
2574
2575         fl_set_input_return(dialog_->input_roman,           FL_RETURN_CHANGED);
2576         fl_set_input_return(dialog_->input_sans,            FL_RETURN_CHANGED);
2577         fl_set_input_return(dialog_->input_typewriter,      FL_RETURN_CHANGED);
2578         fl_set_input_return(dialog_->input_screen_encoding, FL_RETURN_CHANGED);
2579         fl_set_counter_return(dialog_->counter_zoom,        FL_RETURN_CHANGED);
2580         fl_set_counter_return(dialog_->counter_dpi,         FL_RETURN_CHANGED);
2581         fl_set_input_return(dialog_->input_tiny,            FL_RETURN_CHANGED);
2582         fl_set_input_return(dialog_->input_script,          FL_RETURN_CHANGED);
2583         fl_set_input_return(dialog_->input_footnote,        FL_RETURN_CHANGED);
2584         fl_set_input_return(dialog_->input_small,           FL_RETURN_CHANGED);
2585         fl_set_input_return(dialog_->input_normal,          FL_RETURN_CHANGED);
2586         fl_set_input_return(dialog_->input_large,           FL_RETURN_CHANGED);
2587         fl_set_input_return(dialog_->input_larger,          FL_RETURN_CHANGED);
2588         fl_set_input_return(dialog_->input_largest,         FL_RETURN_CHANGED);
2589         fl_set_input_return(dialog_->input_huge,            FL_RETURN_CHANGED);
2590         fl_set_input_return(dialog_->input_huger,           FL_RETURN_CHANGED);
2591
2592         fl_set_input_filter(dialog_->input_tiny,     fl_unsigned_float_filter);
2593         fl_set_input_filter(dialog_->input_script,   fl_unsigned_float_filter);
2594         fl_set_input_filter(dialog_->input_footnote, fl_unsigned_float_filter);
2595         fl_set_input_filter(dialog_->input_small,    fl_unsigned_float_filter);
2596         fl_set_input_filter(dialog_->input_normal,   fl_unsigned_float_filter);
2597         fl_set_input_filter(dialog_->input_large,    fl_unsigned_float_filter);
2598         fl_set_input_filter(dialog_->input_larger,   fl_unsigned_float_filter);
2599         fl_set_input_filter(dialog_->input_largest,  fl_unsigned_float_filter);
2600         fl_set_input_filter(dialog_->input_huge,     fl_unsigned_float_filter);
2601         fl_set_input_filter(dialog_->input_huger,    fl_unsigned_float_filter);
2602
2603         // set up the feedback mechanism
2604         setPreHandler(dialog_->input_roman);
2605         setPreHandler(dialog_->input_sans);
2606         setPreHandler(dialog_->input_typewriter);
2607         setPreHandler(dialog_->counter_zoom);
2608         setPreHandler(dialog_->counter_dpi);
2609         setPreHandler(dialog_->check_scalable);
2610         setPreHandler(dialog_->input_screen_encoding);
2611         setPreHandler(dialog_->input_tiny);
2612         setPreHandler(dialog_->input_script);
2613         setPreHandler(dialog_->input_footnote);
2614         setPreHandler(dialog_->input_small);
2615         setPreHandler(dialog_->input_large);
2616         setPreHandler(dialog_->input_larger);
2617         setPreHandler(dialog_->input_largest);
2618         setPreHandler(dialog_->input_normal);
2619         setPreHandler(dialog_->input_huge);
2620         setPreHandler(dialog_->input_huger);
2621 }
2622
2623         
2624 string const
2625 FormPreferences::ScreenFonts::feedback(FL_OBJECT const * const ob) const
2626 {
2627         string str;
2628
2629         if (ob == dialog_->input_roman)
2630                 str = lyxrc.getDescription(LyXRC::RC_SCREEN_FONT_ROMAN);
2631         else if (ob == dialog_->input_sans)
2632                 str = lyxrc.getDescription(LyXRC::RC_SCREEN_FONT_SANS);
2633         else if (ob == dialog_->input_typewriter)
2634                 str = lyxrc.getDescription(LyXRC::RC_SCREEN_FONT_TYPEWRITER);
2635         else if (ob == dialog_->check_scalable)
2636                 str = lyxrc.getDescription(LyXRC::RC_SCREEN_FONT_SCALABLE);
2637         else if (ob == dialog_->input_screen_encoding)
2638                 str = lyxrc.getDescription(LyXRC::RC_SCREEN_FONT_ENCODING);
2639         else if (ob == dialog_->counter_zoom)
2640                 str = lyxrc.getDescription(LyXRC::RC_SCREEN_ZOOM);
2641         else if (ob == dialog_->counter_dpi) 
2642                 str = lyxrc.getDescription(LyXRC::RC_SCREEN_DPI);
2643         else if (ob == dialog_->input_tiny
2644                  || ob == dialog_->input_script
2645                  || ob == dialog_->input_footnote
2646                  || ob == dialog_->input_small
2647                  || ob == dialog_->input_large
2648                  || ob == dialog_->input_larger
2649                  || ob == dialog_->input_larger
2650                  || ob == dialog_->input_largest
2651                  || ob == dialog_->input_normal
2652                  || ob == dialog_->input_huge
2653                  || ob == dialog_->input_huger)
2654                 str = lyxrc.getDescription(LyXRC::RC_SCREEN_FONT_SIZES);
2655
2656         return str;
2657 }
2658
2659
2660 bool FormPreferences::ScreenFonts::input()
2661 {
2662         bool activate = true;
2663         string str;
2664
2665         // Make sure that all fonts all have positive entries
2666         // Also note that an empty entry is returned as 0.0 by strToDbl
2667         if (0.0 >= strToDbl(fl_get_input(dialog_->input_tiny))
2668             || 0.0 >= strToDbl(fl_get_input(dialog_->input_script))
2669             || 0.0 >= strToDbl(fl_get_input(dialog_->input_footnote))
2670             || 0.0 >= strToDbl(fl_get_input(dialog_->input_small))
2671             || 0.0 >= strToDbl(fl_get_input(dialog_->input_normal))
2672             || 0.0 >= strToDbl(fl_get_input(dialog_->input_large))
2673             || 0.0 >= strToDbl(fl_get_input(dialog_->input_larger))
2674             || 0.0 >= strToDbl(fl_get_input(dialog_->input_largest))
2675             || 0.0 >= strToDbl(fl_get_input(dialog_->input_huge))
2676             || 0.0 >= strToDbl(fl_get_input(dialog_->input_huger))) {
2677                 activate = false;
2678                 str = N_("Fonts must be positive!");
2679
2680         // Fontsizes -- tiny < script < footnote etc.
2681         } else if (strToDbl(fl_get_input(dialog_->input_tiny)) >
2682                    strToDbl(fl_get_input(dialog_->input_script)) ||
2683                    strToDbl(fl_get_input(dialog_->input_script)) >
2684                    strToDbl(fl_get_input(dialog_->input_footnote)) ||
2685                    strToDbl(fl_get_input(dialog_->input_footnote)) >
2686                    strToDbl(fl_get_input(dialog_->input_small)) ||
2687                    strToDbl(fl_get_input(dialog_->input_small)) >
2688                    strToDbl(fl_get_input(dialog_->input_normal)) ||
2689                    strToDbl(fl_get_input(dialog_->input_normal)) >
2690                    strToDbl(fl_get_input(dialog_->input_large)) ||
2691                    strToDbl(fl_get_input(dialog_->input_large)) >
2692                    strToDbl(fl_get_input(dialog_->input_larger)) ||
2693                    strToDbl(fl_get_input(dialog_->input_larger)) >
2694                    strToDbl(fl_get_input(dialog_->input_largest)) ||
2695                    strToDbl(fl_get_input(dialog_->input_largest)) >
2696                    strToDbl(fl_get_input(dialog_->input_huge)) ||
2697                    strToDbl(fl_get_input(dialog_->input_huge)) >
2698                    strToDbl(fl_get_input(dialog_->input_huger))) {
2699                 activate = false;
2700
2701                 str = N_("Fonts must be input in the order tiny > script> footnote > small > normal > large > larger > largest > huge > huger.");
2702         }
2703
2704         if (!activate)
2705                 parent_.printWarning(str);
2706         
2707         return activate;
2708 }
2709
2710
2711 void FormPreferences::ScreenFonts::update()
2712 {
2713         fl_set_input(dialog_->input_roman,
2714                      lyxrc.roman_font_name.c_str());
2715         fl_set_input(dialog_->input_sans,
2716                      lyxrc.sans_font_name.c_str());
2717         fl_set_input(dialog_->input_typewriter,
2718                      lyxrc.typewriter_font_name.c_str());
2719         fl_set_input(dialog_->input_screen_encoding,
2720                      lyxrc.font_norm.c_str());
2721         fl_set_button(dialog_->check_scalable,
2722                       lyxrc.use_scalable_fonts);
2723         fl_set_counter_value(dialog_->counter_zoom, lyxrc.zoom);
2724         fl_set_counter_value(dialog_->counter_dpi,  lyxrc.dpi);
2725         fl_set_input(dialog_->input_tiny,
2726                      tostr(lyxrc.font_sizes[LyXFont::SIZE_TINY]).c_str());
2727         fl_set_input(dialog_->input_script,
2728                      tostr(lyxrc.font_sizes[LyXFont::SIZE_SCRIPT]).c_str());
2729         fl_set_input(dialog_->input_footnote,
2730                      tostr(lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE]).c_str());
2731         fl_set_input(dialog_->input_small,
2732                      tostr(lyxrc.font_sizes[LyXFont::SIZE_SMALL]).c_str());
2733         fl_set_input(dialog_->input_normal,
2734                      tostr(lyxrc.font_sizes[LyXFont::SIZE_NORMAL]).c_str());
2735         fl_set_input(dialog_->input_large,
2736                      tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGE]).c_str());
2737         fl_set_input(dialog_->input_larger,
2738                      tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGER]).c_str());
2739         fl_set_input(dialog_->input_largest,
2740                      tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGEST]).c_str());
2741         fl_set_input(dialog_->input_huge,
2742                      tostr(lyxrc.font_sizes[LyXFont::SIZE_HUGE]).c_str());
2743         fl_set_input(dialog_->input_huger,
2744                      tostr(lyxrc.font_sizes[LyXFont::SIZE_HUGER]).c_str());
2745 }
2746
2747
2748
2749 FormPreferences::SpellOptions::SpellOptions( FormPreferences &  p )
2750         : parent_(p)
2751 {}
2752
2753
2754 FD_form_spelloptions const * FormPreferences::SpellOptions::dialog()
2755 {
2756         return dialog_.get();
2757 }
2758
2759
2760 void FormPreferences::SpellOptions::apply()
2761 {
2762
2763         string choice = fl_get_choice_text(dialog_->choice_spell_command);
2764         choice = strip(frontStrip(choice));
2765         
2766         lyxrc.isp_command = choice;
2767
2768 #if 0
2769         // If spell checker == "none", all other input set to off.
2770         if (fl_get_choice(dialog_->choice_spell_command) == 1) {
2771                 lyxrc.isp_use_alt_lang = false;
2772                 lyxrc.isp_alt_lang.erase();
2773
2774                 lyxrc.isp_use_esc_chars = false;
2775                 lyxrc.isp_esc_chars.erase();
2776
2777                 lyxrc.isp_use_pers_dict = false;
2778                 lyxrc.isp_pers_dict.erase();
2779
2780                 lyxrc.isp_accept_compound = false;
2781                 lyxrc.isp_use_input_encoding = false;
2782         } else {
2783 #else
2784                 int button = fl_get_button(dialog_->check_alt_lang);
2785                 choice = fl_get_input(dialog_->input_alt_lang);
2786                 if (button && choice.empty()) button = 0;
2787                 if (!button) choice.erase();
2788
2789                 lyxrc.isp_use_alt_lang = static_cast<bool>(button);
2790                 lyxrc.isp_alt_lang = choice;
2791
2792                 button = fl_get_button(dialog_->check_escape_chars);
2793                 choice = fl_get_input(dialog_->input_escape_chars);
2794                 if (button && choice.empty()) button = 0;
2795                 if (!button) choice.erase();
2796         
2797                 lyxrc.isp_use_esc_chars = static_cast<bool>(button);
2798                 lyxrc.isp_esc_chars = choice;
2799
2800                 button = fl_get_button(dialog_->check_personal_dict);
2801                 choice = fl_get_input(dialog_->input_personal_dict);
2802                 if (button && choice.empty()) button = 0;
2803                 if (!button) choice.erase();
2804
2805                 lyxrc.isp_use_pers_dict = static_cast<bool>(button);
2806                 lyxrc.isp_pers_dict = choice;
2807
2808                 button = fl_get_button(dialog_->check_compound_words);
2809                 lyxrc.isp_accept_compound = static_cast<bool>(button);
2810
2811                 button = fl_get_button(dialog_->check_input_enc);
2812                 lyxrc.isp_use_input_encoding = static_cast<bool>(button);
2813 #endif
2814 #if 0
2815         }
2816 #endif
2817
2818         // Reset view
2819         update();
2820 }
2821
2822
2823 void FormPreferences::SpellOptions::build()
2824 {
2825         dialog_.reset(parent_.build_spelloptions());
2826
2827         fl_addto_choice(dialog_->choice_spell_command,
2828 #if 0
2829                         _(" none | ispell | aspell "));
2830 #else
2831                         _(" ispell | aspell "));
2832 #endif
2833         fl_set_input_return(dialog_->input_alt_lang,      FL_RETURN_CHANGED);
2834         fl_set_input_return(dialog_->input_escape_chars,  FL_RETURN_CHANGED);
2835         fl_set_input_return(dialog_->input_personal_dict, FL_RETURN_CHANGED);
2836
2837         // set up the feedback mechanism
2838         setPreHandler(dialog_->choice_spell_command);
2839         setPreHandler(dialog_->check_alt_lang);
2840         setPreHandler(dialog_->input_alt_lang);
2841         setPreHandler(dialog_->check_escape_chars);
2842         setPreHandler(dialog_->input_escape_chars);
2843         setPreHandler(dialog_->check_personal_dict);
2844         setPreHandler(dialog_->input_personal_dict);
2845         setPreHandler(dialog_->button_personal_dict);
2846         setPreHandler(dialog_->check_compound_words);
2847         setPreHandler(dialog_->check_input_enc);
2848 }
2849
2850
2851 string const
2852 FormPreferences::SpellOptions::feedback(FL_OBJECT const * const ob) const
2853 {
2854         string str;
2855
2856         if (ob == dialog_->choice_spell_command)
2857                 str = lyxrc.getDescription(LyXRC::RC_SPELL_COMMAND);
2858         else if (ob == dialog_->check_alt_lang)
2859                 str = lyxrc.getDescription(LyXRC::RC_USE_ALT_LANG);
2860         else if (ob == dialog_->input_alt_lang)
2861                 str = lyxrc.getDescription(LyXRC::RC_ALT_LANG);
2862         else if (ob == dialog_->check_escape_chars)
2863                 str = lyxrc.getDescription(LyXRC::RC_USE_ESC_CHARS);
2864         else if (ob == dialog_->input_escape_chars)
2865                 str = lyxrc.getDescription(LyXRC::RC_ESC_CHARS);
2866         else if (ob == dialog_->check_personal_dict)
2867                 str = lyxrc.getDescription(LyXRC::RC_USE_PERS_DICT);
2868         else if (ob == dialog_->input_personal_dict)
2869                 str = lyxrc.getDescription(LyXRC::RC_PERS_DICT);
2870         else if (ob == dialog_->check_compound_words)
2871                 str = lyxrc.getDescription(LyXRC::RC_ACCEPT_COMPOUND);
2872         else if (ob == dialog_->check_input_enc)
2873                 str = lyxrc.getDescription(LyXRC::RC_USE_INP_ENC);
2874
2875         return str;
2876 }
2877
2878
2879 bool FormPreferences::SpellOptions::input(FL_OBJECT const * const ob)
2880 {
2881         // !ob if function is called from updateSpellOptions() to de/activate
2882         // objects,
2883         // otherwise the function is called by an xforms CB via input().
2884
2885 #if 0
2886         // If spell checker == "none", disable all input.
2887         if (!ob || ob == dialog_->choice_spell_command) {
2888                 if (fl_get_choice(dialog_->choice_spell_command) == 1) {
2889                         fl_deactivate_object(dialog_->check_alt_lang);
2890                         fl_deactivate_object(dialog_->input_alt_lang);
2891                         fl_deactivate_object(dialog_->check_escape_chars);
2892                         fl_deactivate_object(dialog_->input_escape_chars);
2893                         fl_deactivate_object(dialog_->check_personal_dict);
2894                         fl_deactivate_object(dialog_->input_personal_dict);
2895                         fl_deactivate_object(dialog_->check_compound_words);
2896                         fl_deactivate_object(dialog_->check_input_enc);
2897                         return true;
2898                 } else {
2899                         fl_activate_object(dialog_->check_alt_lang);
2900                         fl_activate_object(dialog_->check_escape_chars);
2901                         fl_activate_object(dialog_->check_personal_dict);
2902                         fl_activate_object(dialog_->check_compound_words);
2903                         fl_activate_object(dialog_->check_input_enc);
2904                 }
2905         }
2906 #endif
2907
2908         if (!ob || ob == dialog_->check_alt_lang) {
2909                 bool const enable = fl_get_button(dialog_->check_alt_lang);
2910                 setEnabled(dialog_->input_alt_lang, enable);
2911         }
2912
2913         if (!ob || ob == dialog_->check_escape_chars) {
2914                 bool const enable = fl_get_button(dialog_->check_escape_chars);
2915                 setEnabled(dialog_->input_escape_chars, enable);
2916         }
2917
2918         if (!ob || ob == dialog_->check_personal_dict) {
2919                 bool const enable = fl_get_button(dialog_->check_personal_dict);
2920                 setEnabled(dialog_->input_personal_dict, enable);
2921         }
2922
2923         if (ob == dialog_->button_personal_dict) {
2924                 parent_.browse(dialog_->input_personal_dict,
2925                                N_("Personal dictionary"), "*.ispell",
2926                                make_pair(string(), string()),
2927                                make_pair(string(), string()));
2928         }
2929         
2930         return true; // All input is valid!
2931 }
2932
2933
2934 void FormPreferences::SpellOptions::update()
2935 {
2936         int choice = 1;
2937 #if 0
2938         if (lyxrc.isp_command == "none")
2939                 choice = 1;
2940         else if (lyxrc.isp_command == "ispell")
2941                 choice = 2;
2942         else if (lyxrc.isp_command == "aspell")
2943                 choice = 3;
2944 #else
2945         if (lyxrc.isp_command == "ispell")
2946                 choice = 1;
2947         else if (lyxrc.isp_command == "aspell")
2948                 choice = 2;
2949 #endif
2950         fl_set_choice(dialog_->choice_spell_command, choice);
2951         
2952         string str;
2953         if (lyxrc.isp_use_alt_lang) str = lyxrc.isp_alt_lang;
2954
2955         fl_set_button(dialog_->check_alt_lang,
2956                       lyxrc.isp_use_alt_lang);
2957         fl_set_input(dialog_->input_alt_lang, str.c_str());
2958         
2959         str.erase();
2960         if (lyxrc.isp_use_esc_chars) str = lyxrc.isp_esc_chars;
2961
2962         fl_set_button(dialog_->check_escape_chars,
2963                       lyxrc.isp_use_esc_chars);
2964         fl_set_input(dialog_->input_escape_chars, str.c_str());
2965
2966         str.erase();
2967         if (lyxrc.isp_use_pers_dict) str = lyxrc.isp_pers_dict;
2968
2969         fl_set_button(dialog_->check_personal_dict,
2970                       lyxrc.isp_use_pers_dict);
2971         fl_set_input(dialog_->input_personal_dict, str.c_str());
2972
2973         fl_set_button(dialog_->check_compound_words,
2974                       lyxrc.isp_accept_compound);
2975         fl_set_button(dialog_->check_input_enc,
2976                       lyxrc.isp_use_input_encoding);
2977
2978         // Activate/Deactivate the input fields dependent on the state of the
2979         // buttons.
2980         input(0);
2981 }
2982
2983
2984 void FormPreferences::printWarning(string const & warning)
2985 {
2986         warningPosted = true;
2987
2988         string str = _("WARNING!") + string(" ") + warning;
2989         str = formatted(str, dialog_->text_warning->w-10, FL_SMALL_SIZE);
2990
2991         fl_set_object_label(dialog_->text_warning, str.c_str());
2992         fl_set_object_lsize(dialog_->text_warning, FL_SMALL_SIZE);
2993 }
2994
2995
2996 void FormPreferences::browse(FL_OBJECT * inpt,
2997                              string const & title,
2998                              string const & pattern, 
2999                              pair<string,string> const & dir1,
3000                              pair<string,string> const & dir2)
3001 {
3002         // Get the filename from the dialog
3003         string const filename = fl_get_input(inpt);
3004
3005         // Show the file browser dialog
3006         string const new_filename =
3007                 browseFile(lv_, filename, title, pattern, dir1, dir2);
3008
3009         // Save the filename to the dialog
3010         if (new_filename != filename && !new_filename.empty()) {
3011                 fl_set_input(inpt, new_filename.c_str());
3012                 input(inpt, 0);
3013         }
3014 }
3015
3016
3017 // C function wrapper, required by xforms.
3018 extern "C" int C_FormPreferencesFeedbackCB(FL_OBJECT * ob, int event,
3019                                            FL_Coord mx, FL_Coord my,
3020                                            int key, void * xev)
3021 {
3022         return FormPreferences::FeedbackCB(ob, event, mx, my, key, xev);
3023 }
3024
3025 int FormPreferences::FeedbackCB(FL_OBJECT * ob, int event,
3026                                 FL_Coord, FL_Coord, int, void *)
3027 {
3028         // Note that the return value is important in the pre-emptive handler.
3029         // Don't return anything other than 0.
3030
3031         lyx::Assert(ob);
3032         // Don't Assert this one, as it can happen quite reasonably when things
3033         // are being deleted in the d-tor.
3034         //Assert(ob->form);
3035         if (!ob->form) return 0;
3036
3037         FormPreferences * pre =
3038                 static_cast<FormPreferences*>(ob->form->u_vdata);
3039         pre->Feedback(ob, event);
3040         return 0;
3041 }
3042
3043
3044 // preemptive handler for feedback messages
3045 void FormPreferences::Feedback(FL_OBJECT * ob, int event)
3046 {
3047         lyx::Assert(ob);
3048
3049         switch (event) {
3050         case FL_ENTER:
3051                 warningPosted = false;
3052                 feedback(ob);
3053                 break;
3054
3055         case FL_LEAVE:
3056                 if (!warningPosted)
3057                         fl_set_object_label(dialog_->text_warning, "");
3058                 break;
3059
3060         default:
3061                 break;
3062         }
3063 }
3064
3065
3066 void FormPreferences::setPreHandler(FL_OBJECT * ob)
3067 {
3068         lyx::Assert(ob);
3069         fl_set_object_prehandler(ob, C_FormPreferencesFeedbackCB);
3070 }