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