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