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