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