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