]> git.lyx.org Git - features.git/blob - src/frontends/xforms/FormPreferences.C
Use lyxlex to parse rgb.txt + small compilation fixes
[features.git] / src / frontends / xforms / FormPreferences.C
1 /* FormPreferences.C
2  * FormPreferences Interface Class Implementation
3  */
4
5 #include <utility>
6 #include <config.h>
7
8 #include FORMS_H_LOCATION
9
10 #ifdef __GNUG_
11 #pragma implementation
12 #endif
13
14 #include "Lsstream.h"
15 #include "FormPreferences.h"
16 #include "form_preferences.h"
17 #include "input_validators.h"
18 #include "LyXView.h"
19 #include "language.h"
20 #include "lyxfunc.h"
21 #include "Dialogs.h"
22 #include "lyxrc.h"
23 #include "combox.h"
24 #include "debug.h"
25 #include "support/FileInfo.h"
26 #include "support/filetools.h"
27 #include "lyx_gui_misc.h"
28 #include "lyxlex.h"
29 #include "input_validators.h"
30 #include "xform_helpers.h" // formatted()
31 #include "xform_macros.h"
32 #include "converter.h"
33 #include "support/lyxfunctional.h"
34
35
36 #ifdef SIGC_CXX_NAMESPACES
37 using SigC::slot;
38 #endif
39
40 using std::find;
41 using std::find_if;
42 using std::pair;
43 using std::sort;
44 using std::vector;
45
46 extern string fmt(char const * fmtstr ...);
47 extern string system_lyxdir;
48 extern Languages languages;
49
50 static string const colourFile("/usr/lib/X11/rgb.txt");
51 vector<FormPreferences::X11Colour> FormPreferences::colourDB;
52 pair<vector<string>, vector<string> > FormPreferences::dirlist;
53     
54 FormPreferences::FormPreferences(LyXView * lv, Dialogs * d)
55         : FormBaseBI(lv, d, _("Preferences"), new PreferencesPolicy),
56           dialog_(0),
57           converters_tab_(0), inputs_tab_(0), look_n_feel_tab_(0),
58           outputs_tab_(0),  usage_tab_(0),
59           colours_(0), converters_(0), formats_(0), inputs_misc_(0),
60           interface_(0), language_(0), lnf_misc_(0), outputs_misc_(0),
61           paths_(0), printer_(0), screen_fonts_(0), spellchecker_(0),
62           combo_default_lang(0), combo_kbmap_1(0), combo_kbmap_2(0),
63           feedbackObj(0)
64 {
65         // let the dialog be shown
66         // This is a permanent connection so we won't bother
67         // storing a copy because we won't be disconnecting.
68         d->showPreferences.connect(slot(this, &FormPreferences::show));
69 }
70
71
72 FormPreferences::~FormPreferences()
73 {
74         delete combo_default_lang;
75         delete combo_kbmap_1;
76         delete combo_kbmap_2;
77
78         delete converters_tab_;
79         delete inputs_tab_;
80         delete look_n_feel_tab_;
81         delete outputs_tab_;
82         delete usage_tab_;
83
84         delete colours_;
85         delete converters_;
86         delete formats_;
87         delete inputs_misc_;
88         delete interface_;
89         delete language_;
90         delete lnf_misc_;
91         delete outputs_misc_;
92         delete paths_;
93         delete printer_;
94         delete screen_fonts_;
95         delete spellchecker_;
96
97         // Must delete dialog last or we'll end up with a SIGSEGV trying to
98         // access dialog_->timer_feedback in feedbackPost().
99         delete dialog_;
100 }
101
102
103 FL_FORM * FormPreferences::form() const
104 {
105         if (dialog_) return dialog_->form;
106         return 0;
107 }
108
109
110 void FormPreferences::ok()
111 {
112         FormBase::ok();
113         lv_->getLyXFunc()->Dispatch(LFUN_SAVEPREFERENCES);
114 }
115
116
117 void FormPreferences::hide()
118 {
119         // We need to hide the active tabfolder otherwise we get a
120         // BadDrawable error from X windows and LyX crashes without saving.
121         FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder_prefs);
122         if (outer_form
123             && outer_form->visible) {
124                 fl_hide_form(outer_form);
125         }
126         FormBase::hide();
127 }
128
129
130 void FormPreferences::build()
131 {
132         dialog_ = build_preferences();
133
134         // manage the restore, save, apply and cancel/close buttons
135         bc_.setOK(dialog_->button_ok);
136         bc_.setApply(dialog_->button_apply);
137         bc_.setCancel(dialog_->button_cancel);
138         bc_.setUndoAll(dialog_->button_restore);
139         bc_.refresh();
140
141         // Workaround dumb xforms sizing bug
142         minw_ = form()->w;
143         minh_ = form()->h;
144
145         // build the tab folders
146         converters_tab_ = build_outer_tab();
147         look_n_feel_tab_ = build_outer_tab();
148         inputs_tab_ = build_outer_tab();
149         outputs_tab_ = build_outer_tab();
150         usage_tab_ = build_outer_tab();
151
152         // build actual tabfolder contents
153         // these will become nested tabfolders
154         buildColours();
155         buildConverters();
156         buildFormats();
157         buildInputsMisc();
158         buildInterface();
159         buildLanguage();
160         buildLnFmisc();
161         buildOutputsMisc();
162         buildPaths();
163         buildPrinter();
164         buildScreenFonts();
165         buildSpellchecker();
166
167         // Now add them to the tabfolder
168         fl_addto_tabfolder(dialog_->tabfolder_prefs,
169                            _("Look and Feel"),
170                            look_n_feel_tab_->form);
171         fl_addto_tabfolder(dialog_->tabfolder_prefs,
172                            _("Usage"),
173                            usage_tab_->form);
174         fl_addto_tabfolder(dialog_->tabfolder_prefs,
175                            _("Converters"),
176                            converters_tab_->form);
177         fl_addto_tabfolder(dialog_->tabfolder_prefs,
178                            _("Inputs"),
179                            inputs_tab_->form);
180         fl_addto_tabfolder(dialog_->tabfolder_prefs,
181                            _("Outputs"),
182                            outputs_tab_->form);
183
184         // now build the nested tabfolders
185         // Starting with look and feel
186         fl_addto_tabfolder(look_n_feel_tab_->tabfolder_outer,
187                            _("Screen Fonts"),
188                            screen_fonts_->form);
189         fl_addto_tabfolder(look_n_feel_tab_->tabfolder_outer,
190                            _("Interface"),
191                            interface_->form);
192         fl_addto_tabfolder(look_n_feel_tab_->tabfolder_outer,
193                            _("Colours"),
194                            colours_->form);
195         fl_addto_tabfolder(look_n_feel_tab_->tabfolder_outer,
196                            _("Misc"),
197                            lnf_misc_->form);
198
199         // then build converters
200         fl_addto_tabfolder(converters_tab_->tabfolder_outer,
201                            _("Formats"),
202                            formats_->form);
203         fl_addto_tabfolder(converters_tab_->tabfolder_outer,
204                            _("Converters"),
205                            converters_->form);
206
207         // then build inputs
208         // Paths should probably go in a few outer_tab called Files
209         fl_addto_tabfolder(inputs_tab_->tabfolder_outer,
210                            _("Paths"),
211                            paths_->form);
212         fl_addto_tabfolder(inputs_tab_->tabfolder_outer,
213                            _("Misc"),
214                            inputs_misc_->form);
215
216         // then building outputs
217         fl_addto_tabfolder(outputs_tab_->tabfolder_outer,
218                            _("Printer"),
219                            printer_->form);
220         fl_addto_tabfolder(outputs_tab_->tabfolder_outer,
221                            _("Misc"),
222                            outputs_misc_->form);
223
224         // then building usage
225         fl_addto_tabfolder(usage_tab_->tabfolder_outer,
226                            _("Spell checker"),
227                            spellchecker_->form);
228         fl_addto_tabfolder(usage_tab_->tabfolder_outer,
229                            _("Language"),
230                            language_->form);
231 }
232
233
234 void FormPreferences::apply()
235 {
236         // set the new lyxrc entries
237         // many of these need to trigger other functions when the assignment
238         // is made.  For example, screen zoom and font types.  These could be
239         // handled either by signals/slots in lyxrc or just directly call the
240         // associated functions here.
241         // There are other problems with this scheme.  We really should check
242         // what we copy to make sure that it really is necessary to do things
243         // like update the screen fonts because that flushes the textcache
244         // and other stuff which may cost us a lot on slower/high-load machines.
245
246         applyColours();
247         applyConverters();
248         applyFormats();
249         applyInputsMisc();
250         applyInterface();
251         applyLanguage();
252         applyLnFmisc();
253         applyOutputsMisc();
254         applyPaths();
255         applyPrinter();
256         applyScreenFonts();
257         applySpellChecker();
258 }
259
260
261 void FormPreferences::feedback( FL_OBJECT * ob )
262 {
263         if( !ob ) return;
264
265         string str;
266
267         if (ob->form->fdui == colours_) {
268                 str = feedbackColours( ob );
269         } else if (ob->form->fdui == converters_) {
270                 str = feedbackConverters( ob );
271         } else if (ob->form->fdui == formats_) {
272                 str = feedbackFormats( ob );
273         } else if (ob->form->fdui == inputs_misc_) {
274                 str = feedbackInputsMisc( ob );
275         } else if (ob->form->fdui == interface_) {
276                 str = feedbackInterface( ob );
277         } else if (ob->form->fdui == language_) {
278                 str = feedbackLanguage( ob );
279         } else if (ob->form->fdui == lnf_misc_) {
280                 str = feedbackLnFmisc( ob );
281         } else if (ob->form->fdui == outputs_misc_) {
282                 str = feedbackOutputsMisc( ob );
283         } else if (ob->form->fdui == paths_) {
284                 str = feedbackPaths( ob );
285         } else if (ob->form->fdui == printer_) {
286                 str = feedbackPrinter( ob );
287         } else if (ob->form->fdui == screen_fonts_) {
288                 str = feedbackScreenFonts( ob );
289         } else if (ob->form->fdui == spellchecker_) {
290                 str = feedbackSpellChecker( ob );
291         }
292
293         str = formatted( str, dialog_->text_warning->w-10,
294                          FL_SMALL_SIZE, FL_NORMAL_STYLE );
295
296         fl_set_object_label(dialog_->text_warning, str.c_str());
297         fl_set_object_lsize(dialog_->text_warning, FL_SMALL_SIZE);
298 }
299
300
301 bool FormPreferences::input(FL_OBJECT * ob, long)
302 {
303         Assert(ob);
304         
305         // whatever checks you need to ensure the user hasn't entered
306         // some totally ridiculous value somewhere.  Change activate to suit.
307         // comments before each test describe what is _valid_
308
309         if (ob->form->fdui == colours_)
310                 return inputColours(ob);
311         else if (ob->form->fdui == language_)
312                 return inputLanguage(ob);
313         else if (ob->form->fdui == paths_)
314                 return inputPaths(ob);
315         else if (ob->form->fdui == screen_fonts_)
316                 return inputScreenFonts();
317         else if (ob->form->fdui == spellchecker_)
318                 return inputSpellChecker(ob);
319         else if (ob->form->fdui == formats_)
320                 return inputFormats(ob);
321
322         return true;
323 }
324
325
326 void FormPreferences::update()
327 {
328         if (!dialog_) return;
329     
330         // read lyxrc entries
331         updateColours();
332         updateConverters();
333         updateFormats();
334         updateInputsMisc();
335         updateInterface();
336         updateLanguage();
337         updateLnFmisc();
338         updateOutputsMisc();
339         updatePaths();
340         updatePrinter();
341         updateScreenFonts();
342         updateSpellChecker();
343 }
344
345
346 void FormPreferences::applyColours() const
347 {
348 }
349
350
351 void FormPreferences::buildColours()
352 {
353         colours_ = build_colours();
354
355         FL_OBJECT * obj = colours_->valslider_red;
356         fl_set_slider_bounds(obj, 0, 255);
357         fl_set_slider_precision(obj, 0);
358         fl_set_slider_return(obj, FL_RETURN_END_CHANGED);
359         
360         obj = colours_->valslider_green;
361         fl_set_slider_bounds(obj, 0, 255);
362         fl_set_slider_precision(obj, 0);
363         fl_set_slider_return(obj, FL_RETURN_END_CHANGED);
364         
365         obj = colours_->valslider_blue;
366         fl_set_slider_bounds(obj, 0, 255);
367         fl_set_slider_precision(obj, 0);
368         fl_set_slider_return(obj, FL_RETURN_END_CHANGED);
369
370         fl_set_object_color(colours_->button_colour,
371                             FL_FREE_COL4, FL_FREE_COL4);
372         
373         fl_set_input_return(colours_->input_name, FL_RETURN_END_CHANGED);
374
375         if (ColoursLoadBrowser(colourFile) )
376                 fl_set_input(colours_->input_name, colourFile.c_str());
377         else
378                 fl_set_input(colours_->input_name, N_("No file found"));
379
380         // deactivate the browse button because it isn't implemented
381         fl_deactivate_object(colours_->button_browse);
382         fl_set_object_lcol(colours_->button_browse, FL_INACTIVE);
383 }
384
385
386 string const
387 FormPreferences::feedbackColours(FL_OBJECT const * const ob) const
388 {
389         Assert(ob);
390         return string();
391 }
392
393
394 bool FormPreferences::inputColours( FL_OBJECT const * const ob )
395 {
396         Assert(ob);
397         bool activate = true;
398         
399         if (ob == colours_->browser_x11) {
400                 int i = fl_get_browser(colours_->browser_x11);
401                 if (i > 0) {
402                         ColoursUpdateBrowser(i-1);
403                 }
404
405         } else if (ob == colours_->valslider_red
406                    || ob == colours_->valslider_green
407                    || ob == colours_->valslider_blue) {
408                 ColoursUpdateRGB();
409
410         } else if (ob == colours_->input_name) {
411                 string file = fl_get_input(colours_->input_name);
412                 if (ColoursLoadBrowser(file) )
413                         fl_set_input(colours_->input_name, file.c_str());
414                 else if (ColoursLoadBrowser(colourFile) )
415                         fl_set_input(colours_->input_name, colourFile.c_str());
416                 else
417                         fl_set_input(colours_->input_name, N_("No file found"));
418         }
419
420         return activate;
421 }
422
423
424 bool FormPreferences::ColoursLoadBrowser(string const & filename)
425 {
426         LyXLex lex(0, 0);
427         lex.setCommentChar('!');
428         
429         if (!lex.setFile(filename))
430                 return false;
431
432         vector<RGB> cols;
433         vector<string> names;
434         
435         while (lex.next()) {
436                 RGB col;
437                 col.r = lex.GetInteger();
438                 lex.next();
439                 col.g = lex.GetInteger();
440                 lex.next();
441                 col.b = lex.GetInteger();
442                 lex.EatLine();
443                 string name = frontStrip(lex.GetString(), " \t");
444
445                 // remove redundant entries on the fly
446                 bool add = cols.empty();
447                 if (!add) {
448                         vector<RGB>::const_iterator it = 
449                                 find( cols.begin(), cols.end(), col );
450                         add = (it == cols.end());
451                 }
452                 
453                 if (add) {
454                         name = lowercase( name );
455                         if (name == "gray0" )   name = "black";
456                         if (name == "gray100" ) name = "white";
457                         
458                         if (name == "black" || name == "white") {
459                                 cols.insert(cols.begin(), col);
460                                 names.insert(names.begin(), name);
461                         } else {
462                                 cols.push_back(col);
463                                 names.push_back(name);
464                         }
465                 }
466         }
467         
468         vector<string>::iterator sit = names.begin();
469         for (vector<RGB>::const_iterator iit = cols.begin();
470              iit != cols.end(); ++iit, ++sit) {
471                 colourDB.push_back( X11Colour(*sit, *iit) );
472         }
473         
474         FL_OBJECT * colbr = colours_->browser_x11;
475         fl_freeze_form(colours_->form);
476         fl_clear_browser( colbr );
477
478         for (vector<X11Colour>::const_iterator cit = colourDB.begin();
479              cit != colourDB.end(); ++cit) {
480                 string name = (*cit).first;
481                 //RGB col     = (*cit).second;
482                 //name += "  (" + tostr(col.r) + ", " + tostr(col.g) +
483                 //      ", " + tostr(col.b) + ")";
484                 fl_addto_browser(colbr, name.c_str());
485         }
486
487         fl_set_browser_topline(colbr, 1);
488         fl_select_browser_line(colbr, 1);
489         ColoursUpdateBrowser(0);
490         fl_unfreeze_form(colours_->form);
491         
492         return true;
493 }
494
495
496 int FormPreferences::ColoursSearchEntry(RGB const & col) const
497 {
498         int mindiff = 0x7fffffff;
499         vector<X11Colour>::const_iterator mincit = colourDB.begin();
500
501         for (vector<X11Colour>::const_iterator cit = colourDB.begin();
502              cit != colourDB.end(); ++cit) {
503                 RGB colDB = (*cit).second;
504                 RGB diff;
505                 diff.r = col.r - colDB.r;
506                 diff.g = col.g - colDB.g;
507                 diff.b = col.b - colDB.b;
508
509                 int d = (2 * (diff.r * diff.r) +
510                          3 * (diff.g * diff.g) +
511                              (diff.b * diff.b));
512
513                 if (mindiff > d) {
514                         mindiff = d;
515                         mincit = cit;
516                 }
517         }
518         return static_cast<int>(mincit - colourDB.begin());
519 }
520
521
522 void FormPreferences::ColoursUpdateBrowser(int i)
523 {
524         fl_freeze_form(colours_->form);
525
526         RGB col = colourDB[i].second;
527     
528         fl_mapcolor(FL_FREE_COL4 + i, col.r, col.g, col.b);
529         fl_mapcolor(FL_FREE_COL4, col.r, col.g, col.b);
530         fl_set_slider_value(colours_->valslider_red,   col.r);
531         fl_set_slider_value(colours_->valslider_green, col.g);
532         fl_set_slider_value(colours_->valslider_blue,  col.b);
533         fl_redraw_object(colours_->button_colour);
534
535         fl_unfreeze_form(colours_->form);
536 }
537
538
539 void FormPreferences::ColoursUpdateRGB()
540 {
541         fl_freeze_form(colours_->form);
542
543         RGB col;
544         col.r = int(fl_get_slider_value(colours_->valslider_red));
545         col.g = int(fl_get_slider_value(colours_->valslider_green));
546         col.b = int(fl_get_slider_value(colours_->valslider_blue));
547     
548         fl_mapcolor(FL_FREE_COL4, col.r, col.g, col.b);
549         fl_redraw_object(colours_->button_colour);
550
551         int const i = ColoursSearchEntry( col );
552         // change topline only if necessary
553         // int top = fl_get_browser_topline(colours_->browser_x11);
554         // if (i < top || i > (top+15))
555         fl_set_browser_topline(colours_->browser_x11, i - 5);
556         fl_select_browser_line(colours_->browser_x11, i + 1);
557
558         fl_unfreeze_form(colours_->form);
559 }
560
561
562 void FormPreferences::updateColours()
563 {}
564
565
566 void FormPreferences::applyConverters() const
567 {}
568
569
570 void FormPreferences::buildConverters()
571 {
572         converters_ = build_converters();
573         
574         fl_set_input_return(converters_->input_converter, FL_RETURN_CHANGED);
575         fl_set_input_return(converters_->input_flags, FL_RETURN_CHANGED);
576         
577         updateConverters();     
578 }
579
580
581 string const
582 FormPreferences::feedbackConverters( FL_OBJECT const * const ob) const
583 {
584         Assert(ob);
585         return string();
586 }
587
588
589 void FormPreferences::updateConverters()
590 {
591         vector<Command> commands = Converter::GetAllCommands();
592         
593         vector<string> names;
594         for(vector<Command>::const_iterator cit = commands.begin();
595              cit != commands.end(); ++cit) {
596                 string from = cit->from->prettyname;
597                 string to   = cit->to->prettyname;
598                 string name = from + " -> " + to;
599                 names.push_back(name);
600         }
601         sort(names.begin(), names.end());
602         
603         fl_clear_browser(converters_->browser_converters);
604         for (vector<string>::const_iterator cit = names.begin();
605              cit != names.end(); ++cit)
606                 fl_addto_browser(converters_->browser_converters,
607                                  cit->c_str());
608         fl_deactivate_object(converters_->button_add);
609         fl_set_object_lcol(converters_->button_add, FL_INACTIVE);
610         
611         fl_deactivate_object(converters_->button_delete);
612         fl_set_object_lcol(converters_->button_delete, FL_INACTIVE);
613 }
614
615
616 void FormPreferences::applyFormats() const
617 {
618         vector<Format> old = formats.GetAllFormats();
619         for (vector<Format>::const_iterator it = old.begin();
620              it != old.end(); ++it)
621                 if (find_if(formats_vec.begin(),formats_vec.end(),
622                             compare_memfun(&Format::getname, it->name))
623                     == formats_vec.end()) {
624                         formats.Add(it->name, string(), string(), string());
625                 }
626
627         for (vector<Format>::const_iterator it = formats_vec.begin();
628              it != formats_vec.end(); ++it) {
629                 formats.Add(it->name, it->extension, it->prettyname, 
630                             it->shortcut);
631                 formats.SetViewer(it->name, it->viewer);
632         }
633 }
634
635
636 void FormPreferences::buildFormats()
637 {
638         formats_ = build_formats();
639
640         fl_set_input_return(formats_->input_format, FL_RETURN_CHANGED);
641         fl_set_input_return(formats_->input_viewer, FL_RETURN_CHANGED);
642         fl_set_input_return(formats_->input_shrtcut, FL_RETURN_CHANGED);
643         fl_set_input_return(formats_->input_gui_name, FL_RETURN_CHANGED);
644         fl_set_input_return(formats_->input_extension, FL_RETURN_CHANGED);
645
646         fl_set_input_filter(formats_->input_format, fl_lowercase_filter);
647
648         updateFormats();
649 }
650
651
652 string const
653 FormPreferences::feedbackFormats(FL_OBJECT const * const ob) const
654 {
655         Assert(ob);
656         
657         //if( !ob ) return;
658
659         string str;
660
661         return str;
662 }
663
664
665 bool FormPreferences::inputFormats(FL_OBJECT const * const ob)
666 {
667         Assert(ob);
668         
669         //if( !ob ) return false;
670
671         if (ob == formats_->browser_formats) {
672                 FormatsInputBrowser();
673
674         } else if (ob == formats_->input_format) {
675                 FormatsInputInput();
676
677         } else if (ob == formats_->button_add) {
678                 FormatsInputAdd();
679
680         } else if (ob == formats_->button_delete) {
681                 FormatsInputDelete();
682         }
683         return true;
684 }
685
686
687 void FormPreferences::updateFormats()
688 {
689         formats_vec = formats.GetAllFormats();
690
691         vector<string> names;
692         for (vector<Format>::const_iterator it = formats_vec.begin();
693              it != formats_vec.end(); ++it)
694                 names.push_back( it->name.c_str() );
695         sort(names.begin(), names.end());
696
697         fl_clear_browser(formats_->browser_formats);
698         for (vector<string>::const_iterator it = names.begin();
699              it != names.end(); ++it)
700                 fl_addto_browser(formats_->browser_formats, it->c_str());
701
702         fl_deactivate_object(formats_->button_add);
703         fl_set_object_lcol(formats_->button_add, FL_INACTIVE);
704
705         fl_deactivate_object(formats_->button_delete);
706         fl_set_object_lcol(formats_->button_delete, FL_INACTIVE);
707 }
708
709
710 bool FormPreferences::FormatsInputAdd()
711 {
712         string name = fl_get_input(formats_->input_format);
713         string prettyname = fl_get_input(formats_->input_gui_name);
714         string extension = fl_get_input(formats_->input_extension);
715         string viewer =  fl_get_input(formats_->input_viewer);
716         string shortcut =  fl_get_input(formats_->input_shrtcut);
717         if (prettyname.empty())
718                 return false;
719
720         Format format(name, extension, prettyname, shortcut, viewer);
721         vector<Format>::iterator it =
722                 find_if(formats_vec.begin(), formats_vec.end(),
723                         compare_memfun(&Format::getname, name));
724
725         if (it == formats_vec.end()) {
726                 fl_freeze_form(formats_->form);
727
728                 formats_vec.push_back(format);
729
730                 vector<string> names;
731                 for (vector<Format>::const_iterator it = formats_vec.begin();
732                      it != formats_vec.end(); ++it)
733                         names.push_back( it->name.c_str() );
734
735                 sort( names.begin(), names.end() );
736
737                 fl_clear_browser( formats_->browser_formats );
738                 for (vector<string>::const_iterator it = names.begin();
739                      it != names.end(); ++it)
740                         fl_addto_browser(formats_->browser_formats, 
741                                          it->c_str()); 
742
743                 fl_set_input(formats_->input_format, "");
744                 fl_set_input(formats_->input_gui_name, "");
745                 fl_set_input(formats_->input_shrtcut, "");
746                 fl_set_input(formats_->input_extension, "");
747                 fl_set_input(formats_->input_viewer, "");
748
749                 fl_set_object_label( formats_->button_add,
750                                      idex(_("Add|#A")) );
751                 fl_set_button_shortcut( formats_->button_add,
752                                         scex(_("Add|#A")), 1);
753
754                 fl_deactivate_object(formats_->button_add);
755                 fl_set_object_lcol(formats_->button_add, FL_INACTIVE);
756
757                 fl_deactivate_object(formats_->button_delete);
758                 fl_set_object_lcol(formats_->button_delete, FL_INACTIVE);
759                         
760                 fl_unfreeze_form(formats_->form);
761
762         } else {
763                 //if (*it == format)
764                 //      return false;
765                 *it = format;
766         }
767         return true;
768 }
769
770
771 bool FormPreferences::FormatsInputDelete()
772 {
773         string name = fl_get_input(formats_->input_format);
774         vector<Format>::iterator it =
775                 find_if(formats_vec.begin(), formats_vec.end(),
776                         compare_memfun(&Format::getname, name));
777
778         fl_freeze_form(formats_->form);
779
780         if (it == formats_vec.end()) {
781                 fl_deactivate_object(formats_->button_delete);
782                 fl_set_object_lcol(formats_->button_delete, FL_INACTIVE);
783
784         } else {
785                 int sel = 0;
786                 for( int i = 0;
787                      i < fl_get_browser_maxline(formats_->browser_formats); 
788                      ++i ) {
789                         string str = fl_get_browser_line( formats_->browser_formats, i+1 );
790                         if( str == name ) {
791                                 sel = i+1;
792                                 break;
793                         }
794                 }
795                 
796                 if( sel != 0 ) {
797                         fl_delete_browser_line(formats_->browser_formats, sel );
798
799                         fl_set_input(formats_->input_format, "");
800                         fl_set_input(formats_->input_gui_name, "");
801                         fl_set_input(formats_->input_shrtcut, "");
802                         fl_set_input(formats_->input_extension, "");
803                         fl_set_input(formats_->input_viewer, "");
804
805                         fl_set_object_label( formats_->button_add,
806                                              idex(_("Add|#A")) );
807                         fl_set_button_shortcut( formats_->button_add,
808                                                 scex(_("Add|#A")), 1);
809
810                         fl_deactivate_object(formats_->button_add);
811                         fl_set_object_lcol(formats_->button_add, FL_INACTIVE);
812
813                         fl_deactivate_object(formats_->button_delete);
814                         fl_set_object_lcol(formats_->button_delete,
815                                            FL_INACTIVE);
816                 }
817         }
818         
819         fl_unfreeze_form(formats_->form);
820
821         return true;
822 }
823
824
825 bool FormPreferences::FormatsInputBrowser() 
826 {
827         int const i = fl_get_browser(formats_->browser_formats);
828         if( i <= 0 ) return true;
829
830         string name = fl_get_browser_line(formats_->browser_formats, i);
831         vector<Format>::iterator it =
832                 find_if(formats_vec.begin(), formats_vec.end(),
833                         compare_memfun(&Format::getname, name));
834
835         if (it != formats_vec.end()) {
836                 fl_freeze_form(formats_->form);
837
838                 fl_set_input(formats_->input_format, it->name.c_str());
839                 fl_set_input(formats_->input_gui_name, it->prettyname.c_str());
840                 fl_set_input(formats_->input_shrtcut, it->shortcut.c_str());
841                 fl_set_input(formats_->input_extension, it->extension.c_str());
842                 fl_set_input(formats_->input_viewer, it->viewer.c_str());
843
844                 fl_set_object_label( formats_->button_add,
845                                      idex(_("Modify|#M")) );
846                 fl_set_button_shortcut( formats_->button_add, 
847                                         scex(_("Modify|#M")), 1);
848
849                 fl_activate_object(formats_->button_add);
850                 fl_set_object_lcol(formats_->button_add, FL_BLACK);
851
852                 fl_activate_object(formats_->button_delete);
853                 fl_set_object_lcol(formats_->button_delete, FL_BLACK);
854                                 
855                 fl_unfreeze_form(formats_->form);
856         }
857         return true;
858 }
859
860
861 bool FormPreferences::FormatsInputInput()
862 {
863         string const name = fl_get_input(formats_->input_format);
864         vector<Format>::iterator it =
865                 find_if(formats_vec.begin(), formats_vec.end(),
866                         compare_memfun(&Format::getname, name));
867
868         fl_freeze_form(formats_->form);
869
870         if (it == formats_vec.end()) {
871                 fl_set_object_label( formats_->button_add,
872                                      idex(_("Add|#A")) );
873                 fl_set_button_shortcut( formats_->button_add,
874                                         scex(_("Add|#A")), 1);
875
876                 if( name.empty() ) {
877                         fl_deactivate_object(formats_->button_add);
878                         fl_set_object_lcol(formats_->button_add, FL_INACTIVE);
879                 } else {
880                         fl_activate_object(formats_->button_add);
881                         fl_set_object_lcol(formats_->button_add, FL_BLACK);
882                 }
883
884                 fl_deselect_browser(formats_->browser_formats);
885
886                 fl_deactivate_object(formats_->button_delete);
887                 fl_set_object_lcol(formats_->button_delete, FL_INACTIVE);
888
889         } else {
890                 fl_set_object_label( formats_->button_add,
891                                      idex(_("Modify|#M")) );
892                 fl_set_button_shortcut( formats_->button_add,
893                                         scex(_("Modify|#M")), 1);
894
895                 int sel = 0;
896                 for( int i = 0;
897                      i < fl_get_browser_maxline(formats_->browser_formats);
898                      ++i ) {
899                         string str = fl_get_browser_line( formats_->browser_formats, i+1 );
900                         if( str == name ) {
901                                 sel = i+1;
902                                 break;
903                         }
904                 }
905
906                 int top = sel - 6;
907                 if( top < 1 ) top = 0;
908                 fl_set_browser_topline(formats_->browser_formats, top);
909                 fl_select_browser_line(formats_->browser_formats, sel);
910                 
911                 fl_activate_object(formats_->button_add);
912                 fl_set_object_lcol(formats_->button_add, FL_BLACK);
913
914                 fl_activate_object(formats_->button_delete);
915                 fl_set_object_lcol(formats_->button_delete, FL_BLACK);
916         }
917
918         fl_unfreeze_form(formats_->form);
919         return true;
920 }
921
922
923 void FormPreferences::applyInputsMisc() const
924 {
925         lyxrc.date_insert_format =
926                 fl_get_input(inputs_misc_->input_date_format);
927 }
928
929
930 void FormPreferences::buildInputsMisc()
931 {
932         inputs_misc_ = build_inputs_misc();
933
934         fl_set_input_return(inputs_misc_->input_date_format,
935                             FL_RETURN_CHANGED);
936
937         // set up the feedback mechanism
938         fl_addto_form(inputs_misc_->form);
939
940         setPostHandler( inputs_misc_->input_date_format );
941
942         fl_end_form();
943 }
944
945
946 string const
947 FormPreferences::feedbackInputsMisc(FL_OBJECT const * const ob) const
948 {
949         Assert(ob);
950         
951         //if( !ob ) return string();
952
953         string str;
954
955         if (ob == inputs_misc_->input_date_format )
956                 str = lyxrc.getDescription( LyXRC::RC_DATE_INSERT_FORMAT );
957
958         return str;
959 }
960
961
962 void FormPreferences::updateInputsMisc()
963 {
964         fl_set_input(inputs_misc_->input_date_format,
965                      lyxrc.date_insert_format.c_str());
966 }
967
968
969 void FormPreferences::applyInterface() const
970 {
971         lyxrc.popup_font_name =
972                 fl_get_input(interface_->input_popup_font);
973         lyxrc.menu_font_name = fl_get_input(interface_->input_menu_font);
974         lyxrc.font_norm_menu =
975                 fl_get_input(interface_->input_popup_encoding);
976         lyxrc.bind_file = fl_get_input(interface_->input_bind_file);
977         lyxrc.ui_file = fl_get_input(interface_->input_ui_file);
978         lyxrc.override_x_deadkeys =
979                 fl_get_button(interface_->check_override_x_dead_keys);
980 }
981
982
983 void FormPreferences::buildInterface()
984 {
985         interface_ = build_interface();
986
987         fl_set_input_return(interface_->input_popup_font, FL_RETURN_CHANGED);
988         fl_set_input_return(interface_->input_menu_font, FL_RETURN_CHANGED);
989         fl_set_input_return(interface_->input_popup_encoding, 
990                             FL_RETURN_CHANGED);
991         fl_set_input_return(interface_->input_bind_file, FL_RETURN_CHANGED);
992         fl_set_input_return(interface_->input_ui_file, FL_RETURN_CHANGED);
993
994         // deactivate the browse buttons because they aren't implemented
995         fl_deactivate_object(interface_->button_bind_file_browse);
996         fl_deactivate_object(interface_->button_ui_file_browse);
997         fl_set_object_lcol(interface_->button_bind_file_browse, FL_INACTIVE);
998         fl_set_object_lcol(interface_->button_ui_file_browse, FL_INACTIVE);
999
1000         // set up the feedback mechanism
1001         fl_addto_form(interface_->form);
1002
1003         setPostHandler( interface_->input_popup_font );
1004         setPostHandler( interface_->input_menu_font );
1005         setPostHandler( interface_->input_popup_encoding );
1006         setPostHandler( interface_->input_bind_file );
1007         setPostHandler( interface_->button_bind_file_browse );
1008         setPostHandler( interface_->input_ui_file );
1009         setPostHandler( interface_->button_ui_file_browse );
1010         setPostHandler( interface_->check_override_x_dead_keys );
1011
1012         fl_end_form();
1013 }
1014
1015
1016 string const
1017 FormPreferences::feedbackInterface( FL_OBJECT const * const ob ) const
1018 {
1019         Assert(ob);
1020         
1021         //if( !ob ) return string();
1022
1023         string str;
1024
1025         if (ob == interface_->input_popup_font )
1026                 str = lyxrc.getDescription( LyXRC::RC_SCREEN_FONT_POPUP );
1027         else if (ob == interface_->input_menu_font )
1028                 str = lyxrc.getDescription( LyXRC::RC_SCREEN_FONT_MENU );
1029         else if (ob == interface_->input_popup_encoding )
1030                 str = lyxrc.getDescription( LyXRC::RC_SCREEN_FONT_ENCODING_MENU );
1031         else if (ob == interface_->input_bind_file )
1032                 str = lyxrc.getDescription( LyXRC::RC_BINDFILE );
1033         else if (ob == interface_->input_ui_file )
1034                 str = lyxrc.getDescription( LyXRC::RC_UIFILE );
1035         else if (ob == interface_->check_override_x_dead_keys )
1036                 str = lyxrc.getDescription( LyXRC::RC_OVERRIDE_X_DEADKEYS );
1037
1038         return str;
1039 }
1040
1041
1042 void FormPreferences::updateInterface()
1043 {
1044         fl_set_input(interface_->input_popup_font,
1045                      lyxrc.popup_font_name.c_str());
1046         fl_set_input(interface_->input_menu_font,
1047                      lyxrc.menu_font_name.c_str());
1048         fl_set_input(interface_->input_popup_encoding,
1049                      lyxrc.font_norm_menu.c_str());
1050         fl_set_input(interface_->input_bind_file,
1051                      lyxrc.bind_file.c_str());
1052         fl_set_input(interface_->input_ui_file,
1053                      lyxrc.ui_file.c_str());
1054         fl_set_button(interface_->check_override_x_dead_keys,
1055                       lyxrc.override_x_deadkeys);
1056 }
1057
1058
1059 void FormPreferences::applyLanguage()
1060 {
1061         lyxrc.default_language = combo_default_lang->getline();
1062
1063         int button = fl_get_button(language_->check_use_kbmap);
1064         string name_1 = combo_kbmap_1->getline();
1065         string name_2 = combo_kbmap_2->getline();
1066         if( button )
1067                 button = ( !name_1.empty() && !name_2.empty() );
1068         lyxrc.use_kbmap = static_cast<bool>(button);
1069
1070         if (button) {
1071                 vector<string>::iterator it =
1072                         find( dirlist.second.begin(), dirlist.second.end(),
1073                               name_1 );
1074                 vector<string>::size_type sel = it - dirlist.second.begin();
1075                 lyxrc.primary_kbmap = dirlist.first[sel];
1076
1077                 it = find( dirlist.second.begin(), dirlist.second.end(),
1078                            name_2 );
1079                 sel = it - dirlist.second.begin();
1080                 lyxrc.secondary_kbmap = dirlist.first[sel];
1081         }
1082         
1083         button = fl_get_button(language_->check_rtl_support);
1084         lyxrc.rtl_support = static_cast<bool>(button);
1085
1086         button = fl_get_button(language_->check_auto_begin);
1087         lyxrc.language_auto_begin = static_cast<bool>(button);
1088
1089         button = fl_get_button(language_->check_auto_end);
1090         lyxrc.language_auto_end = static_cast<bool>(button);
1091
1092         button = fl_get_button(language_->check_mark_foreign);
1093         lyxrc.mark_foreign_language = static_cast<bool>(button);
1094
1095         lyxrc.language_package = fl_get_input(language_->input_package);
1096         lyxrc.language_command_begin = fl_get_input(language_->input_command_begin);
1097         lyxrc.language_command_end = fl_get_input(language_->input_command_end);
1098
1099         // Ensure that all is self-consistent.
1100         updateLanguage();
1101 }
1102
1103
1104 void FormPreferences::buildLanguage()
1105 {
1106         language_ = build_language();
1107
1108         fl_set_input_return(language_->input_package, FL_RETURN_CHANGED);
1109         fl_set_input_return(language_->input_command_begin, FL_RETURN_CHANGED);
1110         fl_set_input_return(language_->input_command_end, FL_RETURN_CHANGED);
1111
1112         // The default_language is a combo-box and has to be inserted manually
1113         fl_freeze_form(language_->form);
1114         fl_addto_form(language_->form);
1115
1116         FL_OBJECT * obj = language_->choice_default_lang;
1117         fl_deactivate_object(language_->choice_default_lang);
1118         combo_default_lang = new Combox(FL_COMBOX_DROPLIST);
1119         combo_default_lang->add(obj->x, obj->y, obj->w, obj->h, 400);
1120         combo_default_lang->shortcut("#L",1);
1121         combo_default_lang->setcallback(ComboLanguageCB, this);
1122
1123         for (Languages::const_iterator cit = languages.begin();
1124             cit != languages.end(); cit++) {
1125                 combo_default_lang->addto((*cit).second.lang());
1126         }
1127
1128         // ditto kbmap_1
1129         string dir = AddPath(system_lyxdir, "kbd");
1130         vector<string> dirlist = DirList(dir , "kmap");
1131
1132         obj = language_->choice_kbmap_1;
1133         fl_deactivate_object(language_->choice_kbmap_1);
1134         combo_kbmap_1 = new Combox(FL_COMBOX_DROPLIST);
1135         combo_kbmap_1->add(obj->x, obj->y, obj->w, obj->h, 400);
1136         combo_kbmap_1->shortcut("#1",1);
1137         combo_kbmap_1->setcallback(ComboLanguageCB, this);
1138
1139         for (vector<string>::const_iterator cit = dirlist.begin();
1140             cit != dirlist.end(); cit++) {
1141                 combo_kbmap_1->addto(*cit);
1142         }
1143
1144         // ditto kbmap_2
1145         obj = language_->choice_kbmap_2;
1146         fl_deactivate_object(language_->choice_kbmap_2);
1147         combo_kbmap_2 = new Combox(FL_COMBOX_DROPLIST);
1148         combo_kbmap_2->add(obj->x, obj->y, obj->w, obj->h, 400);
1149         combo_kbmap_2->shortcut("#2",1);
1150         combo_kbmap_2->setcallback(ComboLanguageCB, this);
1151
1152         for (vector<string>::const_iterator cit = dirlist.begin();
1153             cit != dirlist.end(); cit++) {
1154                 combo_kbmap_2->addto(*cit);
1155         }
1156
1157         fl_end_form();
1158         fl_unfreeze_form(language_->form);
1159
1160         // set up the feedback mechanism
1161         fl_addto_form(language_->form);
1162
1163         setPostHandler( language_->input_package );
1164         setPostHandler( language_->check_use_kbmap );
1165
1166         // This is safe, as nothing is done to the pointer, other than
1167         // to use its address in a block-if statement.
1168         //setPostHandler( reinterpret_cast<FL_OBJECT *>(combo_default_lang) );
1169         //setPostHandler( reinterpret_cast<FL_OBJECT *>(combo_kbmap_1) );
1170         //setPostHandler( reinterpret_cast<FL_OBJECT *>(combo_kbmap_2) );
1171
1172         setPostHandler( language_->check_rtl_support );
1173         setPostHandler( language_->check_mark_foreign );
1174         setPostHandler( language_->check_auto_begin );
1175         setPostHandler( language_->check_auto_end );
1176         setPostHandler( language_->input_command_begin );
1177         setPostHandler( language_->input_command_end );
1178
1179         fl_end_form();
1180
1181         // Activate/Deactivate the input fields dependent on the state of the
1182         // buttons.
1183         inputLanguage( 0 );
1184 }
1185
1186
1187 string const
1188 FormPreferences::feedbackLanguage(FL_OBJECT const * const ob) const
1189 {
1190         Assert(ob);
1191         
1192         //if( !ob ) return string();
1193
1194         string str;
1195
1196         if (reinterpret_cast<Combox const *>(ob) == combo_default_lang )
1197                 str = lyxrc.getDescription( LyXRC::RC_DEFAULT_LANGUAGE );
1198         else if (ob == language_->check_use_kbmap )
1199                 str = lyxrc.getDescription( LyXRC::RC_KBMAP );
1200         else if (reinterpret_cast<Combox const *>(ob) == combo_kbmap_1)
1201                 str = lyxrc.getDescription( LyXRC::RC_KBMAP_PRIMARY );
1202         else if (reinterpret_cast<Combox const *>(ob) == combo_kbmap_2 )
1203                 str = lyxrc.getDescription( LyXRC::RC_KBMAP_SECONDARY );
1204         else if (ob == language_->check_rtl_support )
1205                 str = lyxrc.getDescription( LyXRC::RC_RTL_SUPPORT );
1206         else if (ob == language_->check_auto_begin )
1207                 str = lyxrc.getDescription( LyXRC::RC_LANGUAGE_AUTO_BEGIN );
1208         else if (ob == language_->check_auto_end )
1209                 str = lyxrc.getDescription( LyXRC::RC_LANGUAGE_AUTO_END );
1210         else if (ob == language_->check_mark_foreign )
1211                 str = lyxrc.getDescription( LyXRC::RC_MARK_FOREIGN_LANGUAGE );
1212         else if (ob == language_->input_package )
1213                 str = lyxrc.getDescription( LyXRC::RC_LANGUAGE_PACKAGE );
1214         else if (ob == language_->input_command_begin )
1215                 str = lyxrc.getDescription( LyXRC::RC_LANGUAGE_COMMAND_BEGIN );
1216         else if (ob == language_->input_command_end )
1217                 str = lyxrc.getDescription( LyXRC::RC_LANGUAGE_COMMAND_END );
1218
1219         return str;
1220 }
1221
1222
1223 bool FormPreferences::inputLanguage( FL_OBJECT const * const ob )
1224 {
1225         bool activate = true;
1226
1227         if (!ob || ob == language_->check_use_kbmap) {
1228                 if (fl_get_button(language_->check_use_kbmap)) {
1229                         combo_kbmap_1->activate();
1230                         combo_kbmap_2->activate();
1231                 } else {
1232                         combo_kbmap_1->deactivate();
1233                         combo_kbmap_2->deactivate();
1234                 }
1235         }
1236
1237         return activate;
1238 }
1239
1240
1241 void FormPreferences::updateLanguage()
1242 {
1243         fl_set_button(language_->check_use_kbmap,
1244                       lyxrc.use_kbmap);
1245
1246         combo_default_lang->select_text( lyxrc.default_language );
1247
1248         if (lyxrc.use_kbmap) {
1249                 string fullpath = lyxrc.primary_kbmap;
1250                 vector<string>::iterator it =
1251                         find( dirlist.first.begin(), dirlist.first.end(),
1252                               fullpath );
1253                 vector<string>::size_type sel = it - dirlist.first.begin();
1254                 combo_kbmap_1->select_text( dirlist.second[sel] );
1255
1256                 fullpath = lyxrc.secondary_kbmap;
1257                 it = find( dirlist.first.begin(), dirlist.first.end(),
1258                            fullpath );
1259                 sel = it - dirlist.first.begin();
1260                 combo_kbmap_2->select_text( dirlist.second[sel] );
1261         } else {
1262                 combo_kbmap_1->select_text( "" );
1263                 combo_kbmap_2->select_text( "" );
1264         }
1265         
1266         fl_set_button(language_->check_rtl_support, lyxrc.rtl_support);
1267         fl_set_button(language_->check_auto_begin,  lyxrc.language_auto_begin);
1268         fl_set_button(language_->check_auto_end,    lyxrc.language_auto_end);
1269         fl_set_button(language_->check_mark_foreign,
1270                       lyxrc.mark_foreign_language);
1271
1272         fl_set_input(language_->input_package,
1273                      lyxrc.language_package.c_str());
1274         fl_set_input(language_->input_command_begin,
1275                      lyxrc.language_command_begin.c_str());
1276         fl_set_input(language_->input_command_end,
1277                      lyxrc.language_command_end.c_str());
1278
1279         // Activate/Deactivate the input fields dependent on the state of the
1280         // buttons.
1281         inputLanguage( 0 );
1282 }
1283
1284
1285 void FormPreferences::applyLnFmisc() const
1286 {
1287         lyxrc.show_banner = fl_get_button(lnf_misc_->check_banner);
1288         lyxrc.auto_region_delete = fl_get_button(lnf_misc_->
1289                                                  check_auto_region_delete);
1290         lyxrc.exit_confirmation = fl_get_button(lnf_misc_->check_exit_confirm);
1291         lyxrc.display_shortcuts =
1292                 fl_get_button(lnf_misc_->check_display_shrtcuts);
1293         lyxrc.new_ask_filename = fl_get_button(lnf_misc_->check_ask_new_file);
1294         lyxrc.cursor_follows_scrollbar =
1295                 fl_get_button(lnf_misc_->check_cursor_follows_scrollbar);
1296         lyxrc.autosave = static_cast<unsigned int>
1297                 (fl_get_counter_value(lnf_misc_->counter_autosave));
1298         lyxrc.wheel_jump = static_cast<unsigned int>
1299                 (fl_get_counter_value(lnf_misc_->counter_wm_jump));
1300 }
1301
1302
1303 void FormPreferences::buildLnFmisc()
1304 {
1305         lnf_misc_ = build_lnf_misc();
1306
1307         fl_set_counter_return(lnf_misc_->counter_autosave,
1308                               FL_RETURN_CHANGED);
1309         fl_set_counter_return(lnf_misc_->counter_wm_jump,
1310                               FL_RETURN_CHANGED);
1311
1312         // set up the feedback mechanism
1313         fl_addto_form(lnf_misc_->form);
1314
1315         setPostHandler( lnf_misc_->check_banner );
1316         setPostHandler( lnf_misc_->check_auto_region_delete );
1317         setPostHandler( lnf_misc_->check_exit_confirm );
1318         setPostHandler( lnf_misc_->check_display_shrtcuts );
1319         setPostHandler( lnf_misc_->counter_autosave );
1320         setPostHandler( lnf_misc_->check_ask_new_file );
1321         setPostHandler( lnf_misc_->check_cursor_follows_scrollbar );
1322         setPostHandler( lnf_misc_->counter_wm_jump );
1323
1324         fl_end_form();
1325 }
1326
1327
1328 string const FormPreferences::feedbackLnFmisc(FL_OBJECT const * const ob) const
1329 {
1330         Assert(ob);
1331         
1332         //if( !ob ) return string();
1333
1334         string str;
1335
1336         if (ob == lnf_misc_->check_banner )
1337                 str = lyxrc.getDescription( LyXRC::RC_SHOW_BANNER );
1338         else if (ob == lnf_misc_->check_auto_region_delete )
1339                 str = lyxrc.getDescription( LyXRC::RC_AUTOREGIONDELETE );
1340         else if (ob == lnf_misc_->check_exit_confirm )
1341                 str = lyxrc.getDescription( LyXRC::RC_EXIT_CONFIRMATION );
1342         else if (ob == lnf_misc_->check_display_shrtcuts )
1343                 str = lyxrc.getDescription( LyXRC::RC_DISPLAY_SHORTCUTS );
1344         else if (ob == lnf_misc_->check_ask_new_file )
1345                 str = lyxrc.getDescription( LyXRC::RC_NEW_ASK_FILENAME );
1346         else if (ob == lnf_misc_->check_cursor_follows_scrollbar )
1347                 str = lyxrc.getDescription( LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR );
1348         else if (ob == lnf_misc_->counter_autosave )
1349                 str = lyxrc.getDescription( LyXRC::RC_AUTOSAVE );
1350         else if (ob == lnf_misc_->counter_wm_jump )
1351                 str = lyxrc.getDescription( LyXRC::RC_WHEEL_JUMP );
1352
1353         return str;
1354 }
1355
1356
1357 void FormPreferences::updateLnFmisc()
1358 {
1359         fl_set_button(lnf_misc_->check_banner,
1360                       lyxrc.show_banner);
1361         fl_set_button(lnf_misc_->check_auto_region_delete,
1362                       lyxrc.auto_region_delete);
1363         fl_set_button(lnf_misc_->check_exit_confirm,
1364                       lyxrc.exit_confirmation);
1365         fl_set_button(lnf_misc_->check_display_shrtcuts,
1366                       lyxrc.display_shortcuts);
1367         fl_set_button(lnf_misc_->check_ask_new_file,
1368                       lyxrc.new_ask_filename);
1369         fl_set_button(lnf_misc_->check_cursor_follows_scrollbar,
1370                       lyxrc.cursor_follows_scrollbar);
1371         fl_set_counter_value(lnf_misc_->counter_autosave,
1372                              lyxrc.autosave);
1373         fl_set_counter_value(lnf_misc_->counter_wm_jump,
1374                              lyxrc.wheel_jump);
1375 }
1376
1377
1378 void FormPreferences::applyOutputsMisc() const
1379 {
1380         lyxrc.ascii_linelen = static_cast<unsigned int>
1381                 (fl_get_counter_value(outputs_misc_->counter_line_len));
1382         lyxrc.fontenc = fl_get_input(outputs_misc_->input_tex_encoding);
1383
1384         int choice =
1385                 fl_get_choice(outputs_misc_->choice_default_papersize) - 1;
1386         lyxrc.default_papersize = static_cast<BufferParams::PAPER_SIZE>(choice);
1387
1388         lyxrc.ascii_roff_command = fl_get_input(outputs_misc_->input_ascii_roff);
1389         lyxrc.chktex_command = fl_get_input(outputs_misc_->input_checktex);
1390 }
1391
1392
1393 void FormPreferences::buildOutputsMisc()
1394 {
1395         outputs_misc_ = build_outputs_misc();
1396
1397         fl_set_counter_return(outputs_misc_->counter_line_len,
1398                               FL_RETURN_CHANGED);
1399         fl_set_input_return(outputs_misc_->input_tex_encoding,
1400                             FL_RETURN_CHANGED);
1401         fl_set_input_return(outputs_misc_->input_ascii_roff,
1402                             FL_RETURN_CHANGED);
1403         fl_set_input_return(outputs_misc_->input_checktex,
1404                             FL_RETURN_CHANGED);
1405         fl_addto_choice(outputs_misc_->choice_default_papersize,
1406                         _(" default | US letter | legal | executive | A3 | A4 | A5 | B5 "));
1407
1408         // set up the feedback mechanism
1409         fl_addto_form(outputs_misc_->form);
1410
1411         setPostHandler( outputs_misc_->counter_line_len );
1412         setPostHandler( outputs_misc_->input_tex_encoding );
1413         setPostHandler( outputs_misc_->choice_default_papersize );
1414         setPostHandler( outputs_misc_->input_ascii_roff );
1415         setPostHandler( outputs_misc_->input_checktex );
1416
1417         fl_end_form();
1418 }
1419
1420
1421 string const
1422 FormPreferences::feedbackOutputsMisc(FL_OBJECT const * const ob) const
1423 {
1424         Assert(ob);
1425         
1426         //if( !ob ) return string();
1427
1428         string str;
1429
1430         if (ob == outputs_misc_->counter_line_len )
1431                 str = lyxrc.getDescription( LyXRC::RC_ASCII_LINELEN );
1432         else if (ob == outputs_misc_->input_tex_encoding )
1433                 str = lyxrc.getDescription( LyXRC::RC_FONT_ENCODING );
1434         else if (ob == outputs_misc_->input_ascii_roff )
1435                 str = lyxrc.getDescription( LyXRC::RC_ASCIIROFF_COMMAND );
1436         else if (ob == outputs_misc_->input_checktex )
1437                 str = lyxrc.getDescription( LyXRC::RC_CHKTEX_COMMAND );
1438         else if (ob == outputs_misc_->choice_default_papersize )
1439                 str = lyxrc.getDescription( LyXRC::RC_DEFAULT_PAPERSIZE );
1440
1441         return str;
1442 }
1443
1444
1445 void FormPreferences::updateOutputsMisc()
1446 {
1447         fl_set_counter_value(outputs_misc_->counter_line_len,
1448                              lyxrc.ascii_linelen);
1449         fl_set_input(outputs_misc_->input_tex_encoding,
1450                      lyxrc.fontenc.c_str());
1451         fl_set_choice(outputs_misc_->choice_default_papersize,
1452                       lyxrc.default_papersize+1);
1453         fl_set_input(outputs_misc_->input_ascii_roff,
1454                      lyxrc.ascii_roff_command.c_str());
1455         fl_set_input(outputs_misc_->input_checktex,
1456                      lyxrc.chktex_command.c_str());
1457 }
1458
1459
1460 void FormPreferences::applyPaths()
1461 {
1462         lyxrc.document_path = fl_get_input(paths_->input_default_path);
1463         lyxrc.template_path = fl_get_input(paths_->input_template_path);
1464
1465         int button = fl_get_button(paths_->check_use_temp_dir);
1466         string str  = fl_get_input(paths_->input_temp_dir);
1467         if (!button ) str.erase();
1468
1469         lyxrc.use_tempdir = button;
1470         lyxrc.tempdir_path = str;
1471
1472         button = fl_get_button(paths_->check_last_files);
1473         str = fl_get_input(paths_->input_lastfiles);
1474         if (!button ) str.erase();
1475         
1476         lyxrc.check_lastfiles = button;
1477         lyxrc.lastfiles = str;
1478         lyxrc.num_lastfiles = static_cast<unsigned int>
1479                 (fl_get_counter_value(paths_->counter_lastfiles));
1480
1481         button = fl_get_button(paths_->check_make_backups);
1482         str = fl_get_input(paths_->input_backup_path);
1483         if (!button ) str.erase();
1484
1485         lyxrc.make_backup = button;
1486         lyxrc.backupdir_path = str;
1487
1488         lyxrc.lyxpipes = fl_get_input(paths_->input_serverpipe);
1489
1490         // update view
1491         updatePaths();
1492 }
1493
1494
1495 void FormPreferences::buildPaths()
1496 {
1497         paths_ = build_paths();
1498
1499         fl_set_input_return(paths_->input_default_path, FL_RETURN_CHANGED);
1500         fl_set_input_return(paths_->input_template_path, FL_RETURN_CHANGED);
1501         fl_set_input_return(paths_->input_temp_dir, FL_RETURN_CHANGED);
1502         fl_set_input_return(paths_->input_lastfiles, FL_RETURN_CHANGED);
1503         fl_set_input_return(paths_->input_backup_path, FL_RETURN_CHANGED);
1504         fl_set_counter_return(paths_->counter_lastfiles, FL_RETURN_CHANGED);
1505         fl_set_input_return(paths_->input_serverpipe, FL_RETURN_CHANGED);
1506
1507         // deactivate the browse buttons because they aren't implemented
1508         fl_deactivate_object(paths_->button_document_browse);
1509         fl_deactivate_object(paths_->button_template_browse);
1510         fl_deactivate_object(paths_->button_temp_dir_browse);
1511         fl_deactivate_object(paths_->button_lastfiles_browse);
1512         fl_deactivate_object(paths_->button_backup_path_browse);
1513         fl_deactivate_object(paths_->button_serverpipe_browse);
1514         fl_set_object_lcol(paths_->button_document_browse, FL_INACTIVE);
1515         fl_set_object_lcol(paths_->button_template_browse, FL_INACTIVE);
1516         fl_set_object_lcol(paths_->button_temp_dir_browse, FL_INACTIVE);
1517         fl_set_object_lcol(paths_->button_lastfiles_browse, FL_INACTIVE);
1518         fl_set_object_lcol(paths_->button_backup_path_browse, FL_INACTIVE);
1519         fl_set_object_lcol(paths_->button_serverpipe_browse, FL_INACTIVE);
1520
1521         // set up the feedback mechanism
1522         fl_addto_form(paths_->form);
1523
1524         setPostHandler( paths_->input_default_path );
1525         setPostHandler( paths_->button_document_browse );
1526         setPostHandler( paths_->counter_lastfiles );
1527         setPostHandler( paths_->input_template_path );
1528         setPostHandler( paths_->button_template_browse );
1529         setPostHandler( paths_->check_last_files );
1530         setPostHandler( paths_->button_temp_dir_browse );
1531         setPostHandler( paths_->input_lastfiles );
1532         setPostHandler( paths_->button_lastfiles_browse );
1533         setPostHandler( paths_->check_make_backups );
1534         setPostHandler( paths_->input_backup_path );
1535         setPostHandler( paths_->button_backup_path_browse );
1536         setPostHandler( paths_->input_serverpipe );
1537         setPostHandler( paths_->button_serverpipe_browse );
1538         setPostHandler( paths_->input_temp_dir );
1539         setPostHandler( paths_->check_use_temp_dir );
1540
1541         fl_end_form();
1542 }
1543
1544
1545 string const FormPreferences::feedbackPaths( FL_OBJECT const * const ob ) const
1546 {
1547         Assert(ob);
1548         
1549         //if( !ob ) return string();
1550
1551         string str;
1552
1553         if (ob == paths_->input_default_path )
1554                 str = lyxrc.getDescription( LyXRC::RC_DOCUMENTPATH );
1555         else if (ob == paths_->input_template_path )
1556                 str = lyxrc.getDescription( LyXRC::RC_TEMPLATEPATH );
1557         else if (ob == paths_->check_use_temp_dir )
1558                 str = lyxrc.getDescription( LyXRC::RC_USETEMPDIR );
1559         else if (ob == paths_->input_temp_dir )
1560                 str = lyxrc.getDescription( LyXRC::RC_TEMPDIRPATH );
1561         else if (ob == paths_->check_last_files )
1562                 str = lyxrc.getDescription( LyXRC::RC_CHECKLASTFILES );
1563         else if (ob == paths_->input_lastfiles )
1564                 str = lyxrc.getDescription( LyXRC::RC_LASTFILES );
1565         else if (ob == paths_->counter_lastfiles )
1566                 str = lyxrc.getDescription( LyXRC::RC_NUMLASTFILES );
1567         else if (ob == paths_->check_make_backups )
1568                 str = lyxrc.getDescription( LyXRC::RC_MAKE_BACKUP );
1569         else if (ob == paths_->input_backup_path )
1570                 str = lyxrc.getDescription( LyXRC::RC_BACKUPDIR_PATH );
1571         else if (ob == paths_->input_serverpipe )
1572                 str = lyxrc.getDescription( LyXRC::RC_SERVERPIPE );
1573
1574         return str;
1575 }
1576
1577
1578 bool FormPreferences::inputPaths( FL_OBJECT const * const ob )
1579 {
1580         // what kind of coding is this? Do you plan for a ob == NULL?
1581         // When is that allowed? (Lgb)
1582         //Assert(ob);
1583         
1584         bool activate = true;
1585         
1586         if (!ob || ob == paths_->check_use_temp_dir) {
1587                 if (fl_get_button(paths_->check_use_temp_dir)) {
1588                         fl_activate_object(paths_->input_temp_dir);
1589                         fl_set_object_lcol(paths_->input_temp_dir,
1590                                            FL_BLACK);
1591                 } else {
1592                         fl_deactivate_object(paths_->input_temp_dir);
1593                         fl_set_object_lcol(paths_->input_temp_dir,
1594                                            FL_INACTIVE);
1595                 }
1596         }
1597
1598         if (!ob || ob == paths_->check_last_files) {
1599                 if (fl_get_button(paths_->check_last_files)) {
1600                         fl_activate_object(paths_->input_lastfiles);
1601                         fl_set_object_lcol(paths_->input_lastfiles,
1602                                            FL_BLACK);
1603                 } else {
1604                         fl_deactivate_object(paths_->input_lastfiles);
1605                         fl_set_object_lcol(paths_->input_lastfiles,
1606                                            FL_INACTIVE);
1607                 }
1608         }
1609
1610         if (!ob || ob == paths_->check_make_backups) {
1611                 if (fl_get_button(paths_->check_make_backups)) {
1612                         fl_activate_object(paths_->input_backup_path);
1613                         fl_set_object_lcol(paths_->input_backup_path,
1614                                            FL_BLACK);
1615                 } else {
1616                         fl_deactivate_object(paths_->input_backup_path);
1617                         fl_set_object_lcol(paths_->input_backup_path,
1618                                            FL_INACTIVE);
1619                 }
1620         }
1621
1622         if (!ob || ob == paths_->input_default_path) {
1623                 string name = fl_get_input(paths_->input_default_path);
1624                 if (!WriteableDir(name) )
1625                         return false;
1626         }
1627
1628         if (!ob || ob == paths_->input_template_path) {
1629                 string name = fl_get_input(paths_->input_template_path);
1630                 if (!ReadableDir(name) )
1631                     return false;
1632         }
1633
1634         if (!ob || ob == paths_->input_temp_dir) {
1635                 string name = fl_get_input(paths_->input_temp_dir);
1636                 if (fl_get_button(paths_->check_make_backups)
1637                     && !name.empty()
1638                     && !WriteableDir(name) )
1639                         return false;
1640         }
1641
1642         if (!ob || ob == paths_->input_backup_path) {
1643                 string name = fl_get_input(paths_->input_backup_path);
1644                 if (fl_get_button(paths_->check_make_backups)
1645                     && !name.empty()
1646                     && !WriteableDir(name) )
1647                         return false;
1648         }
1649
1650         if (!ob || ob == paths_->input_lastfiles) {
1651                 string name = fl_get_input(paths_->input_lastfiles);
1652                 if (fl_get_button(paths_->check_last_files)
1653                     && !name.empty()
1654                     && !WriteableFile(name) )
1655                         return false;
1656         }
1657
1658         if (!ob || ob == paths_->input_serverpipe) {
1659                 string name = fl_get_input(paths_->input_serverpipe);
1660                 if (!name.empty()) {
1661                         if (!WriteableFile(name, ".in"))
1662                                 return false;
1663                         if (!WriteableFile(name, ".out"))
1664                                 return false;
1665                 }
1666         }
1667
1668         return activate;
1669 }
1670
1671
1672 void FormPreferences::updatePaths()
1673 {
1674         fl_set_input(paths_->input_default_path,
1675                      lyxrc.document_path.c_str());
1676         fl_set_input(paths_->input_template_path,
1677                      lyxrc.template_path.c_str());
1678
1679         string str;
1680         if (lyxrc.make_backup) str = lyxrc.backupdir_path;
1681
1682         fl_set_button(paths_->check_make_backups,
1683                       lyxrc.make_backup);
1684         fl_set_input(paths_->input_backup_path, str.c_str());
1685
1686         str.erase();
1687         if (lyxrc.use_tempdir) str = lyxrc.tempdir_path;
1688
1689         fl_set_button(paths_->check_use_temp_dir,
1690                       lyxrc.use_tempdir);
1691         fl_set_input(paths_->input_temp_dir, str.c_str());
1692
1693         str.erase();
1694         if (lyxrc.check_lastfiles) str = lyxrc.lastfiles;
1695
1696         fl_set_button(paths_->check_last_files,
1697                       lyxrc.check_lastfiles);           
1698         fl_set_input(paths_->input_lastfiles, str.c_str());
1699         fl_set_counter_value(paths_->counter_lastfiles,
1700                              lyxrc.num_lastfiles);
1701
1702         fl_set_input(paths_->input_serverpipe, lyxrc.lyxpipes.c_str());
1703
1704         // Activate/Deactivate the input fields dependent on the state of the
1705         // buttons.
1706         inputPaths( 0 );
1707 }
1708
1709
1710 void FormPreferences::applyPrinter() const
1711 {
1712         lyxrc.print_adapt_output = fl_get_button(printer_->check_adapt_output);
1713         lyxrc.print_command = fl_get_input(printer_->input_command);
1714         lyxrc.print_pagerange_flag = fl_get_input(printer_->input_page_range);
1715         lyxrc.print_copies_flag = fl_get_input(printer_->input_copies);
1716         lyxrc.print_reverse_flag = fl_get_input(printer_->input_reverse);
1717         lyxrc.print_to_printer = fl_get_input(printer_->input_to_printer);
1718         lyxrc.print_file_extension =
1719                 fl_get_input(printer_->input_file_extension);
1720         lyxrc.print_spool_command =
1721                 fl_get_input(printer_->input_spool_command);
1722         lyxrc.print_paper_flag = fl_get_input(printer_->input_paper_type);
1723         lyxrc.print_evenpage_flag = fl_get_input(printer_->input_even_pages);
1724         lyxrc.print_oddpage_flag = fl_get_input(printer_->input_odd_pages);
1725         lyxrc.print_collcopies_flag = fl_get_input(printer_->input_collated);
1726         lyxrc.print_landscape_flag = fl_get_input(printer_->input_landscape);
1727         lyxrc.print_to_file = fl_get_input(printer_->input_to_file);
1728         lyxrc.print_extra_options =
1729                 fl_get_input(printer_->input_extra_options);
1730         lyxrc.print_spool_printerprefix =
1731                 fl_get_input(printer_->input_spool_prefix);
1732         lyxrc.print_paper_dimension_flag =
1733                 fl_get_input(printer_->input_paper_size);
1734         lyxrc.printer = fl_get_input(printer_->input_name);
1735 }
1736
1737
1738 string const
1739 FormPreferences::feedbackPrinter(FL_OBJECT const * const ob) const
1740 {
1741         Assert(ob);
1742         
1743         //if( !ob ) return string();
1744
1745         string str;
1746
1747         if (ob == printer_->input_command )
1748                 str = lyxrc.getDescription( LyXRC::RC_PRINT_COMMAND );
1749         else if (ob == printer_->check_adapt_output )
1750                 str = lyxrc.getDescription( LyXRC::RC_PRINT_ADAPTOUTPUT );
1751         else if (ob == printer_->input_to_printer )
1752                 str = lyxrc.getDescription( LyXRC::RC_PRINTTOPRINTER );
1753         else if (ob == printer_->input_to_file )
1754                 str = lyxrc.getDescription( LyXRC::RC_PRINTTOFILE );
1755         else if (ob == printer_->input_file_extension )
1756                 str = lyxrc.getDescription( LyXRC::RC_PRINTFILEEXTENSION );
1757         else if (ob == printer_->input_extra_options )
1758                 str = lyxrc.getDescription( LyXRC::RC_PRINTEXSTRAOPTIONS );
1759         else if (ob == printer_->input_spool_command )
1760                 str = lyxrc.getDescription( LyXRC::RC_PRINTSPOOL_COMMAND );
1761         else if (ob == printer_->input_spool_prefix )
1762                 str = lyxrc.getDescription( LyXRC::RC_PRINTSPOOL_PRINTERPREFIX );
1763         else if (ob == printer_->input_name )
1764                 str = lyxrc.getDescription( LyXRC::RC_PRINTER );
1765         else if (ob == printer_->input_even_pages )
1766                 str = lyxrc.getDescription( LyXRC::RC_PRINTEVENPAGEFLAG );
1767         else if (ob == printer_->input_odd_pages )
1768                 str = lyxrc.getDescription( LyXRC::RC_PRINTODDPAGEFLAG );
1769         else if (ob == printer_->input_page_range )
1770                 str = lyxrc.getDescription( LyXRC::RC_PRINTPAGERANGEFLAG );
1771         else if (ob == printer_->input_reverse )
1772                 str = lyxrc.getDescription( LyXRC::RC_PRINTREVERSEFLAG );
1773         else if (ob == printer_->input_landscape )
1774                 str = lyxrc.getDescription( LyXRC::RC_PRINTLANDSCAPEFLAG );
1775         else if (ob == printer_->input_copies )
1776                 str = lyxrc.getDescription( LyXRC::RC_PRINTCOLLCOPIESFLAG );
1777         else if (ob == printer_->input_collated )
1778                 str = lyxrc.getDescription( LyXRC::RC_PRINTCOPIESFLAG );
1779         else if (ob == printer_->input_paper_type )
1780                 str = lyxrc.getDescription( LyXRC::RC_PRINTPAPERFLAG );
1781         else if (ob == printer_->input_paper_size )
1782                 str = lyxrc.getDescription( LyXRC::RC_PRINTPAPERDIMENSIONFLAG );
1783
1784         return str;
1785 }
1786
1787
1788 void FormPreferences::buildPrinter()
1789 {
1790         printer_ = build_printer();
1791
1792         fl_set_input_return(printer_->input_command, FL_RETURN_CHANGED);
1793         fl_set_input_return(printer_->input_page_range, FL_RETURN_CHANGED);
1794         fl_set_input_return(printer_->input_copies, FL_RETURN_CHANGED);
1795         fl_set_input_return(printer_->input_reverse, FL_RETURN_CHANGED);
1796         fl_set_input_return(printer_->input_to_printer, FL_RETURN_CHANGED);
1797         fl_set_input_return(printer_->input_file_extension, FL_RETURN_CHANGED);
1798         fl_set_input_return(printer_->input_spool_command, FL_RETURN_CHANGED);
1799         fl_set_input_return(printer_->input_paper_type, FL_RETURN_CHANGED);
1800         fl_set_input_return(printer_->input_even_pages, FL_RETURN_CHANGED);
1801         fl_set_input_return(printer_->input_odd_pages, FL_RETURN_CHANGED);
1802         fl_set_input_return(printer_->input_collated, FL_RETURN_CHANGED);
1803         fl_set_input_return(printer_->input_landscape, FL_RETURN_CHANGED);
1804         fl_set_input_return(printer_->input_to_file, FL_RETURN_CHANGED);
1805         fl_set_input_return(printer_->input_extra_options, FL_RETURN_CHANGED);
1806         fl_set_input_return(printer_->input_spool_prefix, FL_RETURN_CHANGED);
1807         fl_set_input_return(printer_->input_paper_size, FL_RETURN_CHANGED);
1808         fl_set_input_return(printer_->input_name, FL_RETURN_CHANGED);
1809
1810         // set up the feedback mechanism
1811         fl_addto_form(printer_->form);
1812
1813         setPostHandler( printer_->input_command );
1814         setPostHandler( printer_->input_page_range );
1815         setPostHandler( printer_->input_copies );
1816         setPostHandler( printer_->input_reverse );
1817         setPostHandler( printer_->input_to_printer );
1818         setPostHandler( printer_->input_file_extension );
1819         setPostHandler( printer_->input_spool_command );
1820         setPostHandler( printer_->input_paper_type );
1821         setPostHandler( printer_->input_even_pages );
1822         setPostHandler( printer_->input_odd_pages );
1823         setPostHandler( printer_->input_collated );
1824         setPostHandler( printer_->input_landscape );
1825         setPostHandler( printer_->input_to_file );
1826         setPostHandler( printer_->input_extra_options );
1827         setPostHandler( printer_->input_spool_prefix );
1828         setPostHandler( printer_->input_paper_size );
1829         setPostHandler( printer_->input_name );
1830         setPostHandler( printer_->check_adapt_output );
1831
1832         fl_end_form();
1833 }
1834
1835
1836 void FormPreferences::updatePrinter()
1837 {
1838         fl_set_button(printer_->check_adapt_output,
1839                       lyxrc.print_adapt_output);
1840         fl_set_input(printer_->input_command,
1841                      lyxrc.print_command.c_str());
1842         fl_set_input(printer_->input_page_range,
1843                      lyxrc.print_pagerange_flag.c_str());
1844         fl_set_input(printer_->input_copies,
1845                      lyxrc.print_copies_flag.c_str());
1846         fl_set_input(printer_->input_reverse,
1847                      lyxrc.print_reverse_flag.c_str());
1848         fl_set_input(printer_->input_to_printer,
1849                      lyxrc.print_to_printer.c_str());
1850         fl_set_input(printer_->input_file_extension,
1851                      lyxrc.print_file_extension.c_str());
1852         fl_set_input(printer_->input_spool_command,
1853                      lyxrc.print_spool_command.c_str());
1854         fl_set_input(printer_->input_paper_type,
1855                      lyxrc.print_paper_flag.c_str());
1856         fl_set_input(printer_->input_even_pages,
1857                      lyxrc.print_evenpage_flag.c_str());
1858         fl_set_input(printer_->input_odd_pages,
1859                      lyxrc.print_oddpage_flag.c_str());
1860         fl_set_input(printer_->input_collated,
1861                      lyxrc.print_collcopies_flag.c_str());
1862         fl_set_input(printer_->input_landscape,
1863                      lyxrc.print_landscape_flag.c_str());
1864         fl_set_input(printer_->input_to_file,
1865                      lyxrc.print_to_file.c_str());
1866         fl_set_input(printer_->input_extra_options,
1867                      lyxrc.print_extra_options.c_str());
1868         fl_set_input(printer_->input_spool_prefix,
1869                      lyxrc.print_spool_printerprefix.c_str());
1870         fl_set_input(printer_->input_paper_size,
1871                      lyxrc.print_paper_dimension_flag.c_str());
1872         fl_set_input(printer_->input_name,
1873                      lyxrc.printer.c_str());
1874 }
1875
1876
1877 void FormPreferences::applyScreenFonts() const
1878 {
1879         bool changed = false;
1880
1881         string str = fl_get_input(screen_fonts_->input_roman);
1882         if (lyxrc.roman_font_name != str) {
1883                 changed = true;
1884                 lyxrc.roman_font_name = str;
1885         }
1886
1887         str = fl_get_input(screen_fonts_->input_sans);
1888         if (lyxrc.sans_font_name != str) {
1889                 changed = true;
1890                 lyxrc.sans_font_name = str;
1891         }
1892
1893         str = fl_get_input(screen_fonts_->input_typewriter);
1894         if (lyxrc.typewriter_font_name != str) {
1895                 changed = true;
1896                 lyxrc.typewriter_font_name = str;
1897         }
1898
1899         str = fl_get_input(screen_fonts_->input_screen_encoding);
1900         if (lyxrc.font_norm != str) {
1901                 changed = true;
1902                 lyxrc.font_norm = str;
1903         }
1904
1905         bool button = fl_get_button(screen_fonts_->check_scalable);
1906         if (lyxrc.use_scalable_fonts != button) {
1907                 changed = true;
1908                 lyxrc.use_scalable_fonts = button;
1909         }
1910
1911         unsigned int ivalue = static_cast<unsigned int>
1912                 (fl_get_counter_value(screen_fonts_->counter_zoom));
1913         if (lyxrc.zoom != ivalue) {
1914                 changed = true;
1915                 lyxrc.zoom = ivalue;
1916         }
1917
1918         ivalue = static_cast<unsigned int>
1919                 (fl_get_counter_value(screen_fonts_->counter_dpi));
1920         if (lyxrc.dpi != ivalue) {
1921                 changed = true;
1922                 lyxrc.dpi = ivalue;
1923         }
1924         
1925         double dvalue = strToDbl(fl_get_input(screen_fonts_->input_tiny));
1926         if (lyxrc.font_sizes[LyXFont::SIZE_TINY] != dvalue) {
1927                 changed = true;
1928                 lyxrc.font_sizes[LyXFont::SIZE_TINY] = dvalue;
1929         }
1930
1931         dvalue = strToDbl(fl_get_input(screen_fonts_->input_script));
1932         if (lyxrc.font_sizes[LyXFont::SIZE_SCRIPT] != dvalue) {
1933                 changed = true;
1934                 lyxrc.font_sizes[LyXFont::SIZE_SCRIPT] = dvalue;
1935         }
1936
1937         dvalue = strToDbl(fl_get_input(screen_fonts_->input_footnote));
1938         if (lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE] != dvalue) {
1939                 changed = true;
1940                 lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE] = dvalue;
1941         }
1942
1943         dvalue = strToDbl(fl_get_input(screen_fonts_->input_small));
1944         if (lyxrc.font_sizes[LyXFont::SIZE_SMALL] != dvalue) {
1945                 changed = true;
1946                 lyxrc.font_sizes[LyXFont::SIZE_SMALL] = dvalue;
1947         }
1948
1949         dvalue = strToDbl(fl_get_input(screen_fonts_->input_normal));
1950         if (lyxrc.font_sizes[LyXFont::SIZE_NORMAL] != dvalue) {
1951                 changed = true;
1952                 lyxrc.font_sizes[LyXFont::SIZE_NORMAL] = dvalue;
1953         }
1954
1955         dvalue = strToDbl(fl_get_input(screen_fonts_->input_large));
1956         if (lyxrc.font_sizes[LyXFont::SIZE_LARGE] != dvalue) {
1957                 changed = true;
1958                 lyxrc.font_sizes[LyXFont::SIZE_LARGE] = dvalue;
1959         }
1960
1961         dvalue = strToDbl(fl_get_input(screen_fonts_->input_larger));
1962         if (lyxrc.font_sizes[LyXFont::SIZE_LARGER] != dvalue) {
1963                 changed = true;
1964                 lyxrc.font_sizes[LyXFont::SIZE_LARGER] = dvalue;
1965         }
1966
1967         dvalue = strToDbl(fl_get_input(screen_fonts_->input_largest));
1968         if (lyxrc.font_sizes[LyXFont::SIZE_LARGEST] != dvalue) {
1969                 changed = true;
1970                 lyxrc.font_sizes[LyXFont::SIZE_LARGEST] = dvalue;
1971         }
1972
1973         dvalue = strToDbl(fl_get_input(screen_fonts_->input_huge));
1974         if (lyxrc.font_sizes[LyXFont::SIZE_HUGE] != dvalue) {
1975                 changed = true;
1976                 lyxrc.font_sizes[LyXFont::SIZE_HUGE] = dvalue;
1977         }
1978
1979         dvalue = strToDbl(fl_get_input(screen_fonts_->input_huger));
1980         if (lyxrc.font_sizes[LyXFont::SIZE_HUGER] != dvalue) {
1981                 changed = true;
1982                 lyxrc.font_sizes[LyXFont::SIZE_HUGER] = dvalue;
1983         }
1984
1985         if (changed) {
1986                 // Now update the buffers
1987                 // Can anything below here affect the redraw process?
1988                 lv_->getLyXFunc()->Dispatch(LFUN_SCREEN_FONT_UPDATE);
1989         }
1990 }
1991
1992
1993 void FormPreferences::buildScreenFonts()
1994 {
1995         screen_fonts_ = build_screen_fonts();
1996
1997         fl_set_input_return(screen_fonts_->input_roman, FL_RETURN_CHANGED);
1998         fl_set_input_return(screen_fonts_->input_sans, FL_RETURN_CHANGED);
1999         fl_set_input_return(screen_fonts_->input_typewriter,
2000                             FL_RETURN_CHANGED);
2001         fl_set_input_return(screen_fonts_->input_screen_encoding,
2002                             FL_RETURN_CHANGED);
2003         fl_set_counter_return(screen_fonts_->counter_zoom, FL_RETURN_CHANGED);
2004         fl_set_counter_return(screen_fonts_->counter_dpi, FL_RETURN_CHANGED);
2005         fl_set_input_return(screen_fonts_->input_tiny, FL_RETURN_CHANGED);
2006         fl_set_input_return(screen_fonts_->input_script, FL_RETURN_CHANGED);
2007         fl_set_input_return(screen_fonts_->input_footnote, FL_RETURN_CHANGED);
2008         fl_set_input_return(screen_fonts_->input_small, FL_RETURN_CHANGED);
2009         fl_set_input_return(screen_fonts_->input_normal, FL_RETURN_CHANGED);
2010         fl_set_input_return(screen_fonts_->input_large, FL_RETURN_CHANGED);
2011         fl_set_input_return(screen_fonts_->input_larger, FL_RETURN_CHANGED);
2012         fl_set_input_return(screen_fonts_->input_largest, FL_RETURN_CHANGED);
2013         fl_set_input_return(screen_fonts_->input_huge, FL_RETURN_CHANGED);
2014         fl_set_input_return(screen_fonts_->input_huger, FL_RETURN_CHANGED);
2015
2016         fl_set_input_filter(screen_fonts_->input_tiny,
2017                             fl_unsigned_int_filter);
2018         fl_set_input_filter(screen_fonts_->input_script,
2019                             fl_unsigned_int_filter);
2020         fl_set_input_filter(screen_fonts_->input_footnote,
2021                             fl_unsigned_int_filter);
2022         fl_set_input_filter(screen_fonts_->input_small,
2023                             fl_unsigned_int_filter);
2024         fl_set_input_filter(screen_fonts_->input_normal,
2025                             fl_unsigned_int_filter);
2026         fl_set_input_filter(screen_fonts_->input_large,
2027                             fl_unsigned_int_filter);
2028         fl_set_input_filter(screen_fonts_->input_larger,
2029                             fl_unsigned_int_filter);
2030         fl_set_input_filter(screen_fonts_->input_largest,
2031                             fl_unsigned_int_filter);
2032         fl_set_input_filter(screen_fonts_->input_huge,
2033                             fl_unsigned_int_filter);
2034         fl_set_input_filter(screen_fonts_->input_huger,
2035                             fl_unsigned_int_filter);
2036
2037         // set up the feedback mechanism
2038         fl_addto_form(screen_fonts_->form);
2039
2040         setPostHandler( screen_fonts_->input_roman );
2041         setPostHandler( screen_fonts_->input_sans );
2042         setPostHandler( screen_fonts_->input_typewriter );
2043         setPostHandler( screen_fonts_->counter_zoom );
2044         setPostHandler( screen_fonts_->counter_dpi );
2045         setPostHandler( screen_fonts_->check_scalable );
2046         setPostHandler( screen_fonts_->input_screen_encoding );
2047         setPostHandler( screen_fonts_->input_tiny );
2048         setPostHandler( screen_fonts_->input_script );
2049         setPostHandler( screen_fonts_->input_footnote );
2050         setPostHandler( screen_fonts_->input_small );
2051         setPostHandler( screen_fonts_->input_large );
2052         setPostHandler( screen_fonts_->input_larger );
2053         setPostHandler( screen_fonts_->input_largest );
2054         setPostHandler( screen_fonts_->input_normal );
2055         setPostHandler( screen_fonts_->input_huge );
2056         setPostHandler( screen_fonts_->input_huger );
2057
2058         fl_end_form();
2059 }
2060
2061         
2062 string const
2063 FormPreferences::feedbackScreenFonts(FL_OBJECT const * const ob ) const
2064 {
2065         Assert(ob);
2066         
2067         //if( !ob ) return string();
2068
2069         string str;
2070
2071         if (ob == screen_fonts_->input_roman )
2072                 str = lyxrc.getDescription( LyXRC::RC_SCREEN_FONT_ROMAN );
2073         else if (ob == screen_fonts_->input_sans )
2074                 str = lyxrc.getDescription( LyXRC::RC_SCREEN_FONT_SANS );
2075         else if (ob == screen_fonts_->input_typewriter )
2076                 str = lyxrc.getDescription( LyXRC::RC_SCREEN_FONT_TYPEWRITER );
2077         else if (ob == screen_fonts_->check_scalable )
2078                 str = lyxrc.getDescription( LyXRC::RC_SCREEN_FONT_SCALABLE );
2079         else if (ob == screen_fonts_->input_screen_encoding )
2080                 str = lyxrc.getDescription( LyXRC::RC_SCREEN_FONT_ENCODING );
2081         else if (ob == screen_fonts_->counter_zoom )
2082                 str = lyxrc.getDescription( LyXRC::RC_SCREEN_ZOOM );
2083         else if (ob == screen_fonts_->counter_dpi ) 
2084                 str = lyxrc.getDescription( LyXRC::RC_SCREEN_DPI );
2085         else if (ob == screen_fonts_->input_tiny
2086                  || ob == screen_fonts_->input_script
2087                  || ob == screen_fonts_->input_footnote
2088                  || ob == screen_fonts_->input_small
2089                  || ob == screen_fonts_->input_large
2090                  || ob == screen_fonts_->input_larger
2091                  || ob == screen_fonts_->input_larger
2092                  || ob == screen_fonts_->input_largest
2093                  || ob == screen_fonts_->input_normal
2094                  || ob == screen_fonts_->input_huge
2095                  || ob == screen_fonts_->input_huger )
2096                 str = lyxrc.getDescription( LyXRC::RC_SCREEN_FONT_SIZES );
2097
2098         return str;
2099 }
2100
2101
2102 bool FormPreferences::inputScreenFonts()
2103 {
2104         bool activate = true;
2105         string str;
2106
2107         // Make sure that all fonts all have positive entries
2108         // Also note that an empty entry is returned as 0.0 by strToDbl
2109         if (0.0 >= strToDbl(fl_get_input(screen_fonts_->input_tiny))
2110             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_script))
2111             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_footnote))
2112             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_small))
2113             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_normal))
2114             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_large))
2115             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_larger))
2116             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_largest))
2117             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_huge))
2118             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_huger))) {
2119                 activate = false;
2120                 str = N_("WARNING! Fonts must be positive!");
2121
2122         // Fontsizes -- tiny < script < footnote etc.
2123         } else if (strToDbl(fl_get_input(screen_fonts_->input_tiny)) >
2124                    strToDbl(fl_get_input(screen_fonts_->input_script)) ||
2125                    strToDbl(fl_get_input(screen_fonts_->input_script)) >
2126                    strToDbl(fl_get_input(screen_fonts_->input_footnote)) ||
2127                    strToDbl(fl_get_input(screen_fonts_->input_footnote)) >
2128                    strToDbl(fl_get_input(screen_fonts_->input_small)) ||
2129                    strToDbl(fl_get_input(screen_fonts_->input_small)) >
2130                    strToDbl(fl_get_input(screen_fonts_->input_normal)) ||
2131                    strToDbl(fl_get_input(screen_fonts_->input_normal)) >
2132                    strToDbl(fl_get_input(screen_fonts_->input_large)) ||
2133                    strToDbl(fl_get_input(screen_fonts_->input_large)) >
2134                    strToDbl(fl_get_input(screen_fonts_->input_larger)) ||
2135                    strToDbl(fl_get_input(screen_fonts_->input_larger)) >
2136                    strToDbl(fl_get_input(screen_fonts_->input_largest)) ||
2137                    strToDbl(fl_get_input(screen_fonts_->input_largest)) >
2138                    strToDbl(fl_get_input(screen_fonts_->input_huge)) ||
2139                    strToDbl(fl_get_input(screen_fonts_->input_huge)) >
2140                    strToDbl(fl_get_input(screen_fonts_->input_huger))) {
2141                 activate = false;
2142
2143                 str = N_("WARNING! Fonts must be input in the order tiny > script>\nfootnote > small > normal > large > larger > largest > huge > huger.");
2144         }
2145
2146         if (!activate) {
2147                 fl_set_object_label(dialog_->text_warning, str.c_str());
2148                 fl_set_object_lsize(dialog_->text_warning, FL_SMALL_SIZE);
2149         }
2150         
2151         return activate;
2152 }
2153
2154
2155 void FormPreferences::updateScreenFonts()
2156 {
2157         fl_set_input(screen_fonts_->input_roman,
2158                      lyxrc.roman_font_name.c_str());
2159         fl_set_input(screen_fonts_->input_sans,
2160                      lyxrc.sans_font_name.c_str());
2161         fl_set_input(screen_fonts_->input_typewriter,
2162                      lyxrc.typewriter_font_name.c_str());
2163         fl_set_input(screen_fonts_->input_screen_encoding,
2164                      lyxrc.font_norm.c_str());
2165         fl_set_button(screen_fonts_->check_scalable,
2166                       lyxrc.use_scalable_fonts);
2167         fl_set_counter_value(screen_fonts_->counter_zoom, lyxrc.zoom);
2168         fl_set_counter_value(screen_fonts_->counter_dpi,  lyxrc.dpi);
2169         fl_set_input(screen_fonts_->input_tiny,
2170                      tostr(lyxrc.font_sizes[LyXFont::SIZE_TINY]).c_str());
2171         fl_set_input(screen_fonts_->input_script,
2172                      tostr(lyxrc.font_sizes[LyXFont::SIZE_SCRIPT]).c_str());
2173         fl_set_input(screen_fonts_->input_footnote,
2174                      tostr(lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE]).c_str());
2175         fl_set_input(screen_fonts_->input_small,
2176                      tostr(lyxrc.font_sizes[LyXFont::SIZE_SMALL]).c_str());
2177         fl_set_input(screen_fonts_->input_normal,
2178                      tostr(lyxrc.font_sizes[LyXFont::SIZE_NORMAL]).c_str());
2179         fl_set_input(screen_fonts_->input_large,
2180                      tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGE]).c_str());
2181         fl_set_input(screen_fonts_->input_larger,
2182                      tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGER]).c_str());
2183         fl_set_input(screen_fonts_->input_largest,
2184                      tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGEST]).c_str());
2185         fl_set_input(screen_fonts_->input_huge,
2186                      tostr(lyxrc.font_sizes[LyXFont::SIZE_HUGE]).c_str());
2187         fl_set_input(screen_fonts_->input_huger,
2188                      tostr(lyxrc.font_sizes[LyXFont::SIZE_HUGER]).c_str());
2189 }
2190
2191
2192 void FormPreferences::applySpellChecker()
2193 {
2194
2195         string choice = "none";
2196         switch (fl_get_choice(spellchecker_->choice_spell_command)) {
2197         case 1:
2198                 choice = "none";
2199                 break;
2200         case 2:
2201                 choice = "ispell";
2202                 break;
2203         case 3:
2204                 choice = "aspell";
2205                 break;
2206         default:
2207                 break;
2208         }
2209         lyxrc.isp_command = choice;
2210
2211         // If spell checker == "none", all other input set to off.
2212         if (fl_get_choice(spellchecker_->choice_spell_command) == 1) {
2213                 lyxrc.isp_use_alt_lang = false;
2214                 lyxrc.isp_alt_lang.erase();
2215
2216                 lyxrc.isp_use_esc_chars = false;
2217                 lyxrc.isp_esc_chars.erase();
2218
2219                 lyxrc.isp_use_pers_dict = false;
2220                 lyxrc.isp_pers_dict.erase();
2221
2222                 lyxrc.isp_accept_compound = false;
2223                 lyxrc.isp_use_input_encoding = false;
2224         } else {
2225                 int button = fl_get_button(spellchecker_->check_alt_lang);
2226                 choice = fl_get_input(spellchecker_->input_alt_lang);
2227                 if (button && choice.empty() ) button = 0;
2228                 if (!button ) choice.erase();
2229
2230                 lyxrc.isp_use_alt_lang = static_cast<bool>(button);
2231                 lyxrc.isp_alt_lang = choice;
2232
2233                 button = fl_get_button(spellchecker_->check_escape_chars);
2234                 choice = fl_get_input(spellchecker_->input_escape_chars);
2235                 if (button && choice.empty() ) button = 0;
2236                 if (!button ) choice.erase();
2237         
2238                 lyxrc.isp_use_esc_chars = static_cast<bool>(button);
2239                 lyxrc.isp_esc_chars = choice;
2240
2241                 button = fl_get_button(spellchecker_->check_personal_dict);
2242                 choice = fl_get_input(spellchecker_->input_personal_dict);
2243                 if (button && choice.empty() ) button = 0;
2244                 if (!button ) choice.erase();
2245
2246                 lyxrc.isp_use_pers_dict = static_cast<bool>(button);
2247                 lyxrc.isp_pers_dict = choice;
2248
2249                 button = fl_get_button(spellchecker_->check_compound_words);
2250                 lyxrc.isp_accept_compound = static_cast<bool>(button);
2251
2252                 button = fl_get_button(spellchecker_->check_input_enc);
2253                 lyxrc.isp_use_input_encoding = static_cast<bool>(button);
2254         }
2255
2256         // Reset view
2257         updateSpellChecker();
2258 }
2259
2260
2261 void FormPreferences::buildSpellchecker()
2262 {
2263         spellchecker_ = build_spellchecker();
2264
2265         fl_addto_choice(spellchecker_->choice_spell_command,
2266                         _(" none | ispell | aspell "));
2267         fl_set_input_return(spellchecker_->input_alt_lang,
2268                             FL_RETURN_CHANGED);
2269         fl_set_input_return(spellchecker_->input_escape_chars,
2270                             FL_RETURN_CHANGED);
2271         fl_set_input_return(spellchecker_->input_personal_dict,
2272                             FL_RETURN_CHANGED);
2273
2274         // deactivate the browse button because it isn't implemented
2275         fl_deactivate_object(spellchecker_->button_personal_dict);
2276         fl_set_object_lcol(spellchecker_->button_personal_dict,
2277                            FL_INACTIVE);
2278
2279         // set up the feedback mechanism
2280         fl_addto_form(spellchecker_->form);
2281
2282         setPostHandler( spellchecker_->choice_spell_command );
2283         setPostHandler( spellchecker_->check_alt_lang );
2284         setPostHandler( spellchecker_->input_alt_lang );
2285         setPostHandler( spellchecker_->check_escape_chars );
2286         setPostHandler( spellchecker_->input_escape_chars );
2287         setPostHandler( spellchecker_->check_personal_dict );
2288         setPostHandler( spellchecker_->input_personal_dict );
2289         setPostHandler( spellchecker_->button_personal_dict );
2290         setPostHandler( spellchecker_->check_compound_words );
2291         setPostHandler( spellchecker_->check_input_enc );
2292
2293         fl_end_form();
2294 }
2295
2296
2297 string const
2298 FormPreferences::feedbackSpellChecker(FL_OBJECT const * const ob) const
2299 {
2300         Assert(ob);
2301         
2302         //if( !ob ) return string();
2303
2304         string str;
2305
2306         if (ob == spellchecker_->choice_spell_command )
2307                 str = lyxrc.getDescription( LyXRC::RC_SPELL_COMMAND );
2308         else if (ob == spellchecker_->check_alt_lang )
2309                 str = lyxrc.getDescription( LyXRC::RC_USE_ALT_LANG );
2310         else if (ob == spellchecker_->input_alt_lang )
2311                 str = lyxrc.getDescription( LyXRC::RC_ALT_LANG );
2312         else if (ob == spellchecker_->check_escape_chars )
2313                 str = lyxrc.getDescription( LyXRC::RC_USE_ESC_CHARS );
2314         else if (ob == spellchecker_->input_escape_chars )
2315                 str = lyxrc.getDescription( LyXRC::RC_ESC_CHARS );
2316         else if (ob == spellchecker_->check_personal_dict )
2317                 str = lyxrc.getDescription( LyXRC::RC_USE_PERS_DICT );
2318         else if (ob == spellchecker_->input_personal_dict )
2319                 str = lyxrc.getDescription( LyXRC::RC_PERS_DICT );
2320         else if (ob == spellchecker_->check_compound_words )
2321                 str = lyxrc.getDescription( LyXRC::RC_ACCEPT_COMPOUND );
2322         else if (ob == spellchecker_->check_input_enc )
2323                 str = lyxrc.getDescription( LyXRC::RC_USE_INP_ENC );
2324
2325         return str;
2326 }
2327
2328
2329 bool FormPreferences::inputSpellChecker( FL_OBJECT const * const ob )
2330 {
2331         // ditto ob! (Lgb)
2332         
2333         // Allow/dissallow input
2334
2335         // If spell checker == "none", disable all input.
2336         if (!ob || ob == spellchecker_->choice_spell_command) {
2337                 if (fl_get_choice(spellchecker_->choice_spell_command) == 1) {
2338                         fl_deactivate_object( spellchecker_->check_alt_lang );
2339                         fl_deactivate_object( spellchecker_->input_alt_lang );
2340                         fl_deactivate_object( spellchecker_->check_escape_chars );
2341                         fl_deactivate_object( spellchecker_->input_escape_chars );
2342                         fl_deactivate_object( spellchecker_->check_personal_dict );
2343                         fl_deactivate_object( spellchecker_->input_personal_dict );
2344                         fl_deactivate_object( spellchecker_->check_compound_words );
2345                         fl_deactivate_object( spellchecker_->check_input_enc );
2346                         return true;
2347                 } else {
2348                         fl_activate_object( spellchecker_->check_alt_lang );
2349                         fl_activate_object( spellchecker_->check_escape_chars );
2350                         fl_activate_object( spellchecker_->check_personal_dict );
2351                         fl_activate_object( spellchecker_->check_compound_words );
2352                         fl_activate_object( spellchecker_->check_input_enc );
2353                 }
2354         }
2355
2356         if (!ob || ob == spellchecker_->check_alt_lang) {
2357                 if (fl_get_button(spellchecker_->check_alt_lang)) {
2358                         fl_activate_object(spellchecker_->input_alt_lang);
2359                         fl_set_object_lcol(spellchecker_->input_alt_lang,
2360                                            FL_BLACK);
2361                 } else {
2362                         fl_deactivate_object(spellchecker_->input_alt_lang);
2363                         fl_set_object_lcol(spellchecker_->input_alt_lang,
2364                                            FL_INACTIVE);
2365                 }
2366         }
2367
2368         if (!ob || ob == spellchecker_->check_escape_chars) {
2369                 if (fl_get_button(spellchecker_->check_escape_chars)) {
2370                         fl_activate_object(spellchecker_->input_escape_chars);
2371                         fl_set_object_lcol(spellchecker_->input_escape_chars,
2372                                            FL_BLACK);
2373                 } else {
2374                         fl_deactivate_object(spellchecker_->input_escape_chars);
2375                         fl_set_object_lcol(spellchecker_->input_escape_chars,
2376                                            FL_INACTIVE);
2377                 }
2378         }
2379
2380         if (!ob || ob == spellchecker_->check_personal_dict) {
2381                 if (fl_get_button(spellchecker_->check_personal_dict)) {
2382                         fl_activate_object(spellchecker_->input_personal_dict);
2383                         fl_set_object_lcol(spellchecker_->input_personal_dict,
2384                                            FL_BLACK);
2385                 } else {
2386                         fl_deactivate_object(spellchecker_->input_personal_dict);
2387                         fl_set_object_lcol(spellchecker_->input_personal_dict,
2388                                            FL_INACTIVE);
2389                 }
2390         }
2391         
2392         return true; // All input is valid!
2393 }
2394
2395
2396 void FormPreferences::updateSpellChecker()
2397 {
2398         int choice = 1;
2399         if (lyxrc.isp_command == "none" )
2400                 choice = 1;
2401         else if (lyxrc.isp_command == "ispell" )
2402                 choice = 2;
2403         else if (lyxrc.isp_command == "aspell" )
2404                 choice = 3;
2405         fl_set_choice(spellchecker_->choice_spell_command, choice);
2406         
2407         string str;
2408         if (lyxrc.isp_use_alt_lang ) str = lyxrc.isp_alt_lang;
2409
2410         fl_set_button(spellchecker_->check_alt_lang,
2411                       lyxrc.isp_use_alt_lang);
2412         fl_set_input(spellchecker_->input_alt_lang, str.c_str());
2413         
2414         str.erase();
2415         if (lyxrc.isp_use_esc_chars ) str = lyxrc.isp_esc_chars;
2416
2417         fl_set_button(spellchecker_->check_escape_chars,
2418                       lyxrc.isp_use_esc_chars);
2419         fl_set_input(spellchecker_->input_escape_chars, str.c_str());
2420
2421         str.erase();
2422         if (lyxrc.isp_use_pers_dict ) str = lyxrc.isp_pers_dict;
2423
2424         fl_set_button(spellchecker_->check_personal_dict,
2425                       lyxrc.isp_use_pers_dict);
2426         fl_set_input(spellchecker_->input_personal_dict, str.c_str());
2427
2428         fl_set_button(spellchecker_->check_compound_words,
2429                       lyxrc.isp_accept_compound);
2430         fl_set_button(spellchecker_->check_input_enc,
2431                       lyxrc.isp_use_input_encoding);
2432
2433         // Activate/Deactivate the input fields dependent on the state of the
2434         // buttons.
2435         inputSpellChecker( 0 );
2436 }
2437
2438
2439 bool FormPreferences::WriteableDir(string const & name) const
2440 {
2441         bool success = true;
2442         string str;
2443
2444         if (!AbsolutePath(name)) {
2445                 success = false;
2446                 str = N_("WARNING! The absolute path is required.");
2447         }
2448
2449         FileInfo const tp(name);
2450         if (success && !tp.isDir()) {
2451                 success = false;
2452                 str = N_("WARNING! Directory does not exist.");
2453         }
2454
2455         if (success && !tp.writable()) {
2456                 success = false;
2457                 str = N_("WARNING! Cannot write to this directory.");
2458         }
2459
2460         if (!success) {
2461                 fl_set_object_label(dialog_->text_warning, str.c_str());
2462                 fl_set_object_lsize(dialog_->text_warning, FL_SMALL_SIZE);
2463         }
2464         
2465         return success;
2466 }
2467
2468
2469 bool FormPreferences::ReadableDir(string const & name) const
2470 {
2471         bool success = true;
2472         string str;
2473
2474         if (!AbsolutePath(name)) {
2475                 success = false;
2476                 str = N_("WARNING! The absolute path is required.");
2477         }
2478
2479         FileInfo const tp(name);
2480         if (success && !tp.isDir()) {
2481                 success = false;
2482                 str = N_("WARNING! Directory does not exist.");
2483         }
2484
2485         if (success && !tp.readable()) {
2486                 success = false;
2487                 str = N_("WARNING! Cannot read this directory.");
2488         }
2489
2490         if (!success) {
2491                 fl_set_object_label(dialog_->text_warning, str.c_str());
2492                 fl_set_object_lsize(dialog_->text_warning, FL_SMALL_SIZE);
2493         }
2494
2495         return success;
2496 }
2497
2498
2499 bool FormPreferences::WriteableFile(string const & name,
2500                                     string const & suffix) const
2501 {
2502         // A writeable file is either:
2503         // * An existing file to which we have write access, or
2504         // * A file that doesn't yet exist but that would exist in a writeable
2505         //   directory.
2506
2507         bool success = true;
2508         string str;
2509
2510         if (name.empty()) {
2511                 success = false;
2512                 str = N_("WARNING! No file input.");
2513         }
2514
2515         string const dir = OnlyPath(name);
2516         if (success && !AbsolutePath(dir)) {
2517                 success = false;
2518                 str = N_("WARNING! The absolute path is required.");
2519         }
2520
2521 #if 0
2522         // This is not a nice way to use FileInfo (Lgb)
2523         FileInfo d;
2524         
2525         {
2526                 FileInfo d1(dir);
2527                 FileInfo d2(name);
2528                 if (d2.isDir() )
2529                         d = d2;
2530                 else
2531                         d = d1;
2532         }
2533 #else
2534         // This should be equivalent (Lgb)
2535         FileInfo d(name);
2536         if (!d.isDir()) {
2537                 d.newFile(dir);
2538         }
2539 #endif
2540         if (success && !d.isDir()) {
2541                 success = false;
2542                 str = N_("WARNING! Directory does not exist.");
2543         }
2544         
2545         if (success && !d.writable()) {
2546                 success = false;
2547                 str = N_("WARNING! Cannot write to this directory.");
2548         }
2549
2550         FileInfo f(name+suffix);
2551         if (success && (dir == name || f.isDir())) {
2552                 success = false;
2553                 str = N_("WARNING! A file is required, not a directory.");
2554         }
2555
2556         if (success && (f.exist() && !f.writable())) {
2557                 success = false;
2558                 str = N_("WARNING! Cannot write to this file.");
2559         }
2560         
2561         if (!success) {
2562                 fl_set_object_label(dialog_->text_warning, str.c_str());
2563                 fl_set_object_lsize(dialog_->text_warning, FL_SMALL_SIZE);
2564         }
2565
2566         return success;
2567 }
2568
2569
2570 void FormPreferences::ComboLanguageCB(int, void * v, Combox * combox)
2571 {
2572         Assert(v && combox);
2573         FormPreferences * pre = static_cast<FormPreferences*>(v);
2574         // This is safe, as nothing is done to the pointer, other than
2575         // to use its address in a block-if statement.
2576         pre->bc_.valid(pre->input(reinterpret_cast<FL_OBJECT *>(combox), 0));
2577 }
2578
2579
2580 // C functions for the timer callback used to give the user feedback
2581 C_GENERICCB(FormPreferences, FeedbackCB)
2582
2583         
2584 void FormPreferences::FeedbackCB(FL_OBJECT * ob, long)
2585 {
2586         Assert(ob);
2587         
2588         //if( !ob ) return;
2589
2590         FormPreferences * pre =
2591                 static_cast<FormPreferences*>(ob->form->u_vdata);
2592         Assert(pre);
2593         
2594         pre->feedback( pre->feedbackObj );
2595 }
2596
2597
2598 extern "C"
2599 int C_FormPreferencesFeedbackPost(FL_OBJECT * ob, int event,
2600                                   FL_Coord, FL_Coord, int, void *)
2601 {
2602         // can occur when form is being deleted. This seems an easier fix than
2603         // a call "fl_set_object_posthandler(ob, 0)" for each and every object
2604         // in the destructor.
2605         if (!ob ) return 0;
2606         if (!ob->form ) return 0;
2607
2608         FormPreferences * pre =
2609                 static_cast<FormPreferences*>(ob->form->u_vdata);
2610         pre->feedbackPost(ob, event);
2611         return 0;
2612 }
2613
2614
2615 // post_handler for feedback messages
2616 void FormPreferences::feedbackPost(FL_OBJECT * ob, int event)
2617 {
2618         Assert(ob);
2619         
2620         //if( !ob ) return;
2621         
2622         // We do not test for empty help here, since this can never happen
2623         if (event == FL_ENTER) {
2624                 // Used as a placeholder for ob, so that we don't have to
2625                 // a horrible reinterpret_cast to long and pass it as an
2626                 // argument in fl_set_object_callback.
2627                 feedbackObj = ob;
2628                 fl_set_object_callback(dialog_->timer_feedback,
2629                                        C_FormPreferencesFeedbackCB,
2630                                        0);
2631                 fl_set_timer(dialog_->timer_feedback, 0.5);
2632         } else if (event != FL_MOTION) {
2633                 fl_set_timer(dialog_->timer_feedback, 0);
2634                 feedbackObj = 0;
2635                 fl_set_object_label(dialog_->text_warning, "");
2636         }
2637 }
2638
2639
2640 void FormPreferences::setPostHandler(FL_OBJECT * ob) const
2641 {
2642         Assert(ob);
2643         
2644         //if( !ob ) return;
2645
2646         fl_set_object_posthandler(ob, C_FormPreferencesFeedbackPost);
2647 }