]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormPreferences.C
4e5c5cc468a7c814d929d9f1416eb666c9b998ef
[lyx.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 <vector>
14
15 #include "FormPreferences.h"
16 #include "form_preferences.h"
17 #include "input_validators.h"
18 #include "LyXView.h"
19 #include "language.h"
20 #include "lyxfunc.h"
21 #include "Dialogs.h"
22 #include "lyxrc.h"
23 #include "debug.h"
24 #include "support/FileInfo.h"
25 #include "support/filetools.h"
26 #include "lyx_gui_misc.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 static vector<string> languageNames;
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 {
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 dialog_;
55         delete look_n_feel_tab_;
56         delete inputs_tab_;
57         delete outputs_tab_;
58         delete usage_tab_;
59         delete colours_;
60         delete inputs_misc_;
61         delete interface_;
62         delete language_;
63         delete lnf_misc_;
64         delete outputs_misc_;
65         delete paths_;
66         delete printer_;
67         delete screen_fonts_;
68         delete spellchecker_;
69 }
70
71
72 FL_FORM * FormPreferences::form() const
73 {
74         if (dialog_) return dialog_->form;
75         return 0;
76 }
77
78
79 void FormPreferences::ok()
80 {
81         FormBase::ok();
82         lv_->getLyXFunc()->Dispatch(LFUN_SAVEPREFERENCES);
83 }
84
85
86 void FormPreferences::restore()
87 {
88         update();
89 // if I add an error message line to the dialog it'll have to be controlled
90 // within input().  I don't need it yet so I'll leave it commented out.
91 //      bc_.valid(input(0));
92 }
93
94
95 void FormPreferences::hide()
96 {
97         // We need to hide the active tabfolder otherwise we get a
98         // BadDrawable error from X windows and LyX crashes without saving.
99         FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder_prefs);
100         if (outer_form
101             && outer_form->visible) {
102                 fl_hide_form(outer_form);
103         }
104         FormBase::hide();
105 }
106
107
108 void FormPreferences::build()
109 {
110         dialog_ = build_preferences();
111
112         // manage the restore, save, apply and cancel/close buttons
113         bc_.setOK(dialog_->button_ok);
114         bc_.setApply(dialog_->button_apply);
115         bc_.setCancel(dialog_->button_cancel);
116         bc_.setUndoAll(dialog_->button_restore);
117         bc_.refresh();
118
119         // Workaround dumb xforms sizing bug
120         minw_ = form()->w;
121         minh_ = form()->h;
122
123         // build the tab folders
124         outputs_tab_ = build_outer_tab();
125         look_n_feel_tab_ = build_outer_tab();
126         inputs_tab_ = build_outer_tab();
127         usage_tab_ = build_outer_tab();
128
129         // build actual tabfolder contents
130         // these will become nested tabfolders
131         buildColours();
132         buildInputsMisc();
133         buildInterface();
134         buildLanguage();
135         buildLnFmisc();
136         buildOutputsMisc();
137         buildPaths();
138         buildPrinter();
139         buildScreenFonts();
140         buildSpellchecker();
141
142         // Now add them to the tabfolder
143         fl_addto_tabfolder(dialog_->tabfolder_prefs,
144                            _("Look and Feel"),
145                            look_n_feel_tab_->form);
146         fl_addto_tabfolder(dialog_->tabfolder_prefs,
147                            _("Inputs"),
148                            inputs_tab_->form);
149         fl_addto_tabfolder(dialog_->tabfolder_prefs,
150                            _("Outputs"),
151                            outputs_tab_->form);
152         fl_addto_tabfolder(dialog_->tabfolder_prefs,
153                            _("Usage"),
154                            usage_tab_->form);
155
156         // now build the nested tabfolders
157         // Starting with look and feel
158         fl_addto_tabfolder(look_n_feel_tab_->tabfolder_outer,
159                            _("Screen Fonts"),
160                            screen_fonts_->form);
161         fl_addto_tabfolder(look_n_feel_tab_->tabfolder_outer,
162                            _("Interface"),
163                            interface_->form);
164         fl_addto_tabfolder(look_n_feel_tab_->tabfolder_outer,
165                            _("Colours"),
166                            colours_->form);
167         fl_addto_tabfolder(look_n_feel_tab_->tabfolder_outer,
168                            _("Misc"),
169                            lnf_misc_->form);
170
171         // then build inputs
172         // Paths should probably go in a few outer_tab called Files
173         fl_addto_tabfolder(inputs_tab_->tabfolder_outer,
174                            _("Paths"),
175                            paths_->form);
176         fl_addto_tabfolder(inputs_tab_->tabfolder_outer,
177                            _("Misc"),
178                            inputs_misc_->form);
179
180         // then building outputs
181         fl_addto_tabfolder(outputs_tab_->tabfolder_outer,
182                            _("Printer"),
183                            printer_->form);
184         fl_addto_tabfolder(outputs_tab_->tabfolder_outer,
185                            _("Misc"),
186                            outputs_misc_->form);
187
188         // then building usage
189         fl_addto_tabfolder(usage_tab_->tabfolder_outer,
190                            _("Spell checker"),
191                            spellchecker_->form);
192         fl_addto_tabfolder(usage_tab_->tabfolder_outer,
193                            _("Language"),
194                            language_->form);
195 }
196
197
198 void FormPreferences::apply()
199 {
200         // set the new lyxrc entries
201         // many of these need to trigger other functions when the assignment
202         // is made.  For example, screen zoom and font types.  These could be
203         // handled either by signals/slots in lyxrc or just directly call the
204         // associated functions here.
205         // There are other problems with this scheme.  We really should check
206         // what we copy to make sure that it really is necessary to do things
207         // like update the screen fonts because that flushes the textcache
208         // and other stuff which may cost us a lot on slower/high-load machines.
209
210         applyColours();
211         applyInputsMisc();
212         applyInterface();
213         applyLanguage();
214         applyLnFmisc();
215         applyOutputsMisc();
216         applyPaths();
217         applyPrinter();
218         applyScreenFonts();
219         applySpellChecker();
220 }
221
222
223 void FormPreferences::update()
224 {
225         if (!dialog_) return;
226     
227         // read lyxrc entries
228         updateColours();
229         updateInputsMisc();
230         updateInterface();
231         updateLanguage();
232         updateLnFmisc();
233         updateOutputsMisc();
234         updatePaths();
235         updatePrinter();
236         updateScreenFonts();
237         updateSpellChecker();
238 }
239
240
241 bool FormPreferences::input(FL_OBJECT * ob, long data)
242 {
243         bool activate = true;
244
245         // Remove any existing messages
246         fl_set_object_label(dialog_->text_warning, " ");
247
248         // whatever checks you need to ensure the user hasn't entered
249         // some totally ridiculous value somewhere.  Change activate to suit.
250         // comments before each test describe what is _valid_
251
252         State cb = static_cast<State>( data );
253         switch( cb ) {
254         case COLOURS:
255                 feedbackColours( ob );
256                 break;
257
258         case INPUTSMISC:
259                 feedbackInputsMisc( ob );
260                 break;
261
262         case INTERFACE:
263                 feedbackInterface( ob );
264                 break;
265
266         case LANGUAGE:
267                 feedbackLanguage( ob );
268                 if( ! inputLanguage( ob ) )
269                         activate = false;
270                 break;
271
272         case LOOKNFEELMISC:
273                 feedbackLnFmisc( ob );
274                 break;
275
276         case OUTPUTSMISC:
277                 feedbackOutputsMisc( ob );
278                 break;
279
280         case PATHS:
281                 feedbackPaths( ob );
282                 if( ! inputPaths( ob ) )
283                         activate = false;
284                 break;
285
286         case PRINTER:
287                 feedbackPrinter( ob );
288                 break;
289
290         case SCREENFONTS:
291                 feedbackScreenFonts( ob );
292                 if( ! inputScreenFonts() )
293                         activate = false;
294                 break;
295
296         case SPELLCHECKER:
297                 feedbackSpellChecker( ob );
298                 if( ! inputSpellChecker( ob ) )
299                         activate = false;
300                 break;
301
302         case TABS:
303                 break;
304         }
305
306         return activate;
307 }
308
309
310 void FormPreferences::applyColours()
311 {
312 }
313
314
315 void FormPreferences::buildColours()
316 {
317         colours_ = build_colours();
318 }
319
320
321 void FormPreferences::feedbackColours( FL_OBJECT const * const )
322 {
323 }
324
325
326 void FormPreferences::updateColours()
327 {
328 }
329
330
331 void FormPreferences::applyInputsMisc()
332 {
333         lyxrc.date_insert_format = fl_get_input(inputs_misc_->input_date_format);
334 }
335
336
337 void FormPreferences::buildInputsMisc()
338 {
339         inputs_misc_ = build_inputs_misc();
340
341         fl_set_input_return(inputs_misc_->input_date_format,
342                             FL_RETURN_CHANGED);
343 }
344
345
346 void FormPreferences::feedbackInputsMisc( FL_OBJECT const * const ob )
347 {
348         string str;
349
350         if( ob == inputs_misc_->input_date_format ) {
351                 str = N_("This accepts the normal strftime formats; see man strftime for full details.\nE.g.\"%A, %e. %B %Y\".");
352         }
353
354         fl_set_object_label(dialog_->text_warning, str.c_str());
355         fl_set_object_lsize(dialog_->text_warning, FL_SMALL_SIZE);
356 }
357
358
359 void FormPreferences::updateInputsMisc()
360 {
361         fl_set_input(inputs_misc_->input_date_format,
362                      lyxrc.date_insert_format.c_str());
363 }
364
365
366 void FormPreferences::applyInterface()
367 {
368         lyxrc.popup_font_name =
369                 fl_get_input(interface_->input_popup_font);
370         lyxrc.menu_font_name = fl_get_input(interface_->input_menu_font);
371         lyxrc.font_norm_menu =
372                 fl_get_input(interface_->input_popup_encoding);
373         lyxrc.bind_file = fl_get_input(interface_->input_bind_file);
374         lyxrc.ui_file = fl_get_input(interface_->input_ui_file);
375         lyxrc.override_x_deadkeys =
376                 fl_get_button(interface_->check_override_x_dead_keys);
377 }
378
379
380 void FormPreferences::buildInterface()
381 {
382         interface_ = build_interface();
383
384         fl_set_input_return(interface_->input_popup_font, FL_RETURN_CHANGED);
385         fl_set_input_return(interface_->input_menu_font, FL_RETURN_CHANGED);
386         fl_set_input_return(interface_->input_popup_encoding, 
387                             FL_RETURN_CHANGED);
388         fl_set_input_return(interface_->input_bind_file, FL_RETURN_CHANGED);
389         fl_set_input_return(interface_->input_ui_file, FL_RETURN_CHANGED);
390
391         // deactivate the browse buttons because they aren't implemented
392         fl_deactivate_object(interface_->button_bind_file_browse);
393         fl_deactivate_object(interface_->button_ui_file_browse);
394         fl_set_object_lcol(interface_->button_bind_file_browse, FL_INACTIVE);
395         fl_set_object_lcol(interface_->button_ui_file_browse, FL_INACTIVE);
396 }
397
398
399 void FormPreferences::feedbackInterface( FL_OBJECT const * const ob )
400 {
401         string str;
402
403         if( ob == interface_->input_popup_font ) {
404                 str = N_("The font for popups.");
405         } else if ( ob == interface_->input_menu_font ) {
406                 str = N_("The font for menus (and groups titles in popups).");
407         } else if ( ob == interface_->input_popup_encoding ) {
408                 str = N_("The norm for the menu/popups fonts.");
409         } else if ( ob == interface_->input_bind_file ) {
410                 str = N_("Keybindings file. Can either specify an absolute path,\nor LyX will look in its global and local bind/ directories.");
411         } else if ( ob == interface_->input_ui_file ) {
412                 str = N_("The  UI (user interface) file. Can either specify an absolute path,\nor LyX will look in its global and local ui/ directories.");
413         } else if ( ob == interface_->check_override_x_dead_keys ) {
414                 str = N_("Set to true for LyX to take over the handling of the dead keys\n(a.k.a accent keys) that may be defined for your keyboard.");
415         }
416
417         fl_set_object_label(dialog_->text_warning, str.c_str());
418         fl_set_object_lsize(dialog_->text_warning, FL_SMALL_SIZE);
419 }
420
421
422 void FormPreferences::updateInterface()
423 {
424         fl_set_input(interface_->input_popup_font,
425                      lyxrc.popup_font_name.c_str());
426         fl_set_input(interface_->input_menu_font,
427                      lyxrc.menu_font_name.c_str());
428         fl_set_input(interface_->input_popup_encoding,
429                      lyxrc.font_norm_menu.c_str());
430         fl_set_input(interface_->input_bind_file,
431                      lyxrc.bind_file.c_str());
432         fl_set_input(interface_->input_ui_file,
433                      lyxrc.ui_file.c_str());
434         fl_set_button(interface_->check_override_x_dead_keys,
435                       lyxrc.override_x_deadkeys);
436 }
437
438
439 void FormPreferences::applyLanguage()
440 {
441         vector<string>::size_type choice =
442                 fl_get_choice(language_->choice_default_lang) - 1;
443         lyxrc.default_language = languageNames[choice];
444
445         int button = fl_get_button(language_->check_use_kbmap);
446         lyxrc.use_kbmap = static_cast<bool>(button);
447
448         if( button ) {
449             choice = fl_get_choice(language_->choice_kbmap_1) - 1;
450             lyxrc.primary_kbmap = languageNames[choice];
451
452             choice = fl_get_choice(language_->choice_kbmap_2) - 1;
453             lyxrc.secondary_kbmap = languageNames[choice];
454         }
455         
456         button = fl_get_button(language_->check_rtl_support);
457         lyxrc.rtl_support = static_cast<bool>(button);
458
459         button = fl_get_button(language_->check_auto_begin);
460         lyxrc.language_auto_begin = static_cast<bool>(button);
461
462         button = fl_get_button(language_->check_auto_end);
463         lyxrc.language_auto_end = static_cast<bool>(button);
464
465         button = fl_get_button(language_->check_mark_foreign);
466         lyxrc.mark_foreign_language = static_cast<bool>(button);
467
468         lyxrc.language_package = fl_get_input(language_->input_package);
469         lyxrc.language_command_begin = fl_get_input(language_->input_command_begin);
470         lyxrc.language_command_end = fl_get_input(language_->input_command_end);
471 }
472
473
474 void FormPreferences::buildLanguage()
475 {
476         language_ = build_language();
477
478         fl_set_input_return(language_->input_package, FL_RETURN_CHANGED);
479         fl_set_input_return(language_->input_command_begin, FL_RETURN_CHANGED);
480         fl_set_input_return(language_->input_command_end, FL_RETURN_CHANGED);
481
482         // Only do this the first time buildLanguage() is called.
483         if( languageNames.empty() ) {
484                 for( Languages::const_iterator lang = languages.begin();
485                      lang != languages.end(); lang++ ) {
486                         languageNames.push_back( (*lang).second.lang() );
487                 }
488         }
489
490         string names = " " + languageNames.front();
491         for( vector<string>::const_iterator lang = languageNames.begin();
492              lang != languageNames.end(); ++lang ) {
493                 names += " | " + (*lang);
494         }
495         names += " ";
496         
497         fl_addto_choice(language_->choice_default_lang, names.c_str());
498         fl_addto_choice(language_->choice_kbmap_1, names.c_str());
499         fl_addto_choice(language_->choice_kbmap_2, names.c_str());
500 }
501
502
503 void FormPreferences::feedbackLanguage( FL_OBJECT const * const ob )
504 {
505         string str;
506
507         if( ob == language_->choice_default_lang ) {
508                 str = N_("New documents will be assigned this language.");
509         } else if( ob == language_->check_use_kbmap
510                    || ob == language_->choice_kbmap_1
511                    || ob == language_->choice_kbmap_2 ) {
512                 str = N_("Use this to set the correct mapping file for your keyboard.\nYou'll need this if you for instance want to type German documents\non an American keyboard.");
513         } else if( ob == language_->check_rtl_support ) {
514                 str = N_("Use to enable support of right-to-left languages (e.g. Hebrew, Arabic).");
515         } else if( ob == language_->check_auto_begin ) {
516                 str = N_("Use if a language switching command is needed at the beginning\nof the document.");
517         } else if( ob == language_->check_auto_end ) {
518                 str = N_("Use if a language switching command is needed at the end\nof the document.");
519         } else if( ob == language_->check_mark_foreign ) {
520                 str = N_("Use to control the highlighting of words with a language foreign to\nthat of the document.");
521         } else if( ob == language_->input_package ) {
522                 str = N_("The latex command for loading the language package.\nE.g. \"\\usepackage{babel}\", \"\\usepackage{omega}\".");
523         } else if( ob == language_->input_command_begin ) {
524                 str = N_("The latex command for changing from the language of the document\nto another language.\nE.g. \\selectlanguage{$$lang} where $$lang is substituted by the name\nof the second language.");
525         } else if( ob == language_->input_command_end ) {
526                 str = N_("The latex command for changing back to the language of the document.");
527         }
528
529         fl_set_object_label(dialog_->text_warning, str.c_str());
530         fl_set_object_lsize(dialog_->text_warning, FL_SMALL_SIZE);
531 }
532
533
534 bool FormPreferences::inputLanguage( FL_OBJECT const * const ob )
535 {
536         bool activate = true;
537         
538         if( !ob || ob == language_->check_use_kbmap ) {
539                 if( fl_get_button(language_->check_use_kbmap) ) {
540                         fl_activate_object(language_->choice_kbmap_1);
541                         fl_activate_object(language_->choice_kbmap_2);
542                         fl_set_object_lcol(language_->choice_kbmap_1,
543                                            FL_BLACK);
544                         fl_set_object_lcol(language_->choice_kbmap_2,
545                                            FL_BLACK);
546                 } else {
547                         fl_deactivate_object(language_->choice_kbmap_1);
548                         fl_deactivate_object(language_->choice_kbmap_2);
549                         fl_set_object_lcol(language_->choice_kbmap_1,
550                                            FL_INACTIVE);
551                         fl_set_object_lcol(language_->choice_kbmap_2,
552                                            FL_INACTIVE);
553                 }
554         }
555
556         return activate;
557 }
558
559
560 void FormPreferences::updateLanguage()
561 {
562         fl_set_button(language_->check_use_kbmap,
563                       lyxrc.use_kbmap);
564
565         vector<string>::iterator it =
566                 find( languageNames.begin(), languageNames.end(),
567                       lyxrc.default_language );
568         int choice = 0;
569         if( it != languageNames.end() )
570                 choice = static_cast<int>( it - languageNames.begin() );
571
572         fl_set_choice(language_->choice_default_lang, choice+1);
573
574         it = find( languageNames.begin(), languageNames.end(),
575                    lyxrc.primary_kbmap );
576         choice = 0;
577         if( it != languageNames.end() )
578                 choice = static_cast<int>( it - languageNames.begin() );
579         
580         fl_set_choice(language_->choice_kbmap_1, choice+1);
581
582         it = find( languageNames.begin(), languageNames.end(),
583                    lyxrc.secondary_kbmap );
584         choice = 0;
585         if( it != languageNames.end() )
586                 choice = static_cast<int>( it - languageNames.begin() );
587
588         fl_set_choice(language_->choice_kbmap_2, choice+1);
589         
590         fl_set_button(language_->check_rtl_support, lyxrc.rtl_support);
591         fl_set_button(language_->check_auto_begin,  lyxrc.language_auto_begin);
592         fl_set_button(language_->check_auto_end,    lyxrc.language_auto_end);
593         fl_set_button(language_->check_mark_foreign,
594                       lyxrc.mark_foreign_language);
595
596         fl_set_input(language_->input_package,
597                      lyxrc.language_package.c_str());
598         fl_set_input(language_->input_command_begin,
599                      lyxrc.language_command_begin.c_str());
600         fl_set_input(language_->input_command_end,
601                      lyxrc.language_command_end.c_str());
602
603         // Activate/Deactivate the input fields dependent on the state of the
604         // buttons.
605         inputLanguage( 0 );
606 }
607
608
609 void FormPreferences::applyLnFmisc()
610 {
611         lyxrc.show_banner = fl_get_button(lnf_misc_->check_banner);
612         lyxrc.auto_region_delete = fl_get_button(lnf_misc_->
613                                                  check_auto_region_delete);
614         lyxrc.exit_confirmation = fl_get_button(lnf_misc_->check_exit_confirm);
615         lyxrc.display_shortcuts =
616                 fl_get_button(lnf_misc_->check_display_shortcuts);
617         lyxrc.new_ask_filename = fl_get_button(lnf_misc_->check_ask_new_file);
618         lyxrc.cursor_follows_scrollbar =
619                 fl_get_button(lnf_misc_->check_cursor_follows_scrollbar);
620         lyxrc.autosave = static_cast<unsigned int>
621                 (fl_get_counter_value(lnf_misc_->counter_autosave));
622         lyxrc.wheel_jump = static_cast<unsigned int>
623                 (fl_get_counter_value(lnf_misc_->counter_wm_jump));
624 }
625
626
627 void FormPreferences::buildLnFmisc()
628 {
629         lnf_misc_ = build_lnf_misc();
630
631         fl_set_counter_return(lnf_misc_->counter_autosave,
632                               FL_RETURN_CHANGED);
633         fl_set_counter_return(lnf_misc_->counter_wm_jump,
634                               FL_RETURN_CHANGED);
635 }
636
637
638 void FormPreferences::feedbackLnFmisc( FL_OBJECT const * const ob )
639 {
640         string str;
641
642         if( ob == lnf_misc_->check_banner ) {
643                 str = N_("Set to false if you don't want the startup banner.");
644         } else if( ob == lnf_misc_->check_auto_region_delete ) {
645                 str = N_("Set to false if you don't want the current selection to be replaced\nautomatically by what you type.");
646         } else if( ob == lnf_misc_->check_exit_confirm ) {
647                 str = N_("Sets whether LyX asks for a second confirmation to exit when you have\nchanged documents.\n(LyX will still ask to save changed documents.)");
648         } else if( ob == lnf_misc_->check_display_shortcuts ) {
649                 str = N_("LyX continously displays names of last command executed,\nalong with a list of defined short-cuts for it in the minibuffer.\nSet to false if LyX seems slow.");
650         } else if( ob == lnf_misc_->check_ask_new_file ) {
651                 str = N_("This sets the behaviour if you want to be asked for a filename when\ncreating a new document or wait until you save it and be asked then.");
652         } else if( ob == lnf_misc_->check_cursor_follows_scrollbar ) {
653                 str = N_("LyX normally doesn't update the cursor position if you move the scrollbar.\nSet to true if you'd prefer to always have the cursor on screen.");
654         } else if( ob == lnf_misc_->counter_autosave ) {
655                 str = N_("The time interval between auto-saves (in seconds).\n0 means no auto-save");
656         } else if( ob == lnf_misc_->counter_wm_jump ) {
657                 str = N_("The wheel movement factor (for mice with wheels or five button mice)");
658         } 
659         
660         fl_set_object_label(dialog_->text_warning, str.c_str());
661         fl_set_object_lsize(dialog_->text_warning, FL_SMALL_SIZE);
662 }
663
664 void FormPreferences::updateLnFmisc()
665 {
666         fl_set_button(lnf_misc_->check_banner,
667                       lyxrc.show_banner);
668         fl_set_button(lnf_misc_->check_auto_region_delete,
669                       lyxrc.auto_region_delete);
670         fl_set_button(lnf_misc_->check_exit_confirm,
671                       lyxrc.exit_confirmation);
672         fl_set_button(lnf_misc_->check_display_shortcuts,
673                       lyxrc.display_shortcuts);
674         fl_set_button(lnf_misc_->check_ask_new_file,
675                       lyxrc.new_ask_filename);
676         fl_set_button(lnf_misc_->check_cursor_follows_scrollbar,
677                       lyxrc.cursor_follows_scrollbar);
678         fl_set_counter_value(lnf_misc_->counter_autosave,
679                              lyxrc.autosave);
680         fl_set_counter_value(lnf_misc_->counter_wm_jump,
681                              lyxrc.wheel_jump);
682 }
683
684
685 void FormPreferences::applyOutputsMisc()
686 {
687         lyxrc.ascii_linelen = static_cast<unsigned int>
688                 (fl_get_counter_value(outputs_misc_->counter_line_len));
689         lyxrc.fontenc = fl_get_input(outputs_misc_->input_tex_encoding);
690
691         int choice =
692                 fl_get_choice(outputs_misc_->choice_default_papersize) - 1;
693         lyxrc.default_papersize = static_cast<BufferParams::PAPER_SIZE>(choice);
694
695         lyxrc.ascii_roff_command = fl_get_input(outputs_misc_->input_ascii_roff);
696         lyxrc.chktex_command = fl_get_input(outputs_misc_->input_checktex);
697 }
698
699
700 void FormPreferences::buildOutputsMisc()
701 {
702         outputs_misc_ = build_outputs_misc();
703
704         fl_set_counter_return(outputs_misc_->counter_line_len,
705                               FL_RETURN_CHANGED);
706         fl_set_input_return(outputs_misc_->input_tex_encoding,
707                             FL_RETURN_CHANGED);
708         fl_set_input_return(outputs_misc_->input_ascii_roff,
709                             FL_RETURN_CHANGED);
710         fl_set_input_return(outputs_misc_->input_checktex,
711                             FL_RETURN_CHANGED);
712         fl_addto_choice(outputs_misc_->choice_default_papersize,
713                         _(" default | US letter | legal | executive | A3 | A4 | A5 | B5 "));
714 }
715
716
717 void FormPreferences::feedbackOutputsMisc(FL_OBJECT const * const ob )
718 {
719         string str;
720
721         if( ob == outputs_misc_->counter_line_len ) {
722                 str = N_("This is the maximum line length of an exported ASCII file\n(LaTeX, SGML or plain text).");
723         } else if( ob == outputs_misc_->input_tex_encoding ) {
724                 str = N_("The font encoding used for the LaTeX2e fontenc package.\nT1 is highly recommended for non-English languages.");
725         } else if( ob == outputs_misc_->input_ascii_roff ) {
726                 str = N_("Use to define an external program to render tables in the ASCII output.\nE.g. \"groff -t -Tlatin1 $$FName\"  where $$FName is the input file.\nIf \"none\" is specified, an internal routine is used.");
727         } else if( ob == outputs_misc_->input_checktex ) {
728                 str = N_("Define how to run chktex.\nE.g. \"chktex -n11 -n1 -n3 -n6 -n9 -22 -n25 -n30 -n38\"\nRefer to the ChkTeX documentation.");
729         } else if( ob == outputs_misc_->choice_default_papersize ) {
730                 str = N_("Specify the default paper size.");
731         } 
732                 
733         fl_set_object_label(dialog_->text_warning, str.c_str());
734         fl_set_object_lsize(dialog_->text_warning, FL_SMALL_SIZE);
735 }
736
737
738 void FormPreferences::updateOutputsMisc()
739 {
740         fl_set_counter_value(outputs_misc_->counter_line_len,
741                              lyxrc.ascii_linelen);
742         fl_set_input(outputs_misc_->input_tex_encoding,
743                      lyxrc.fontenc.c_str());
744         fl_set_choice(outputs_misc_->choice_default_papersize,
745                       lyxrc.default_papersize+1);
746         fl_set_input(outputs_misc_->input_ascii_roff,
747                      lyxrc.ascii_roff_command.c_str());
748         fl_set_input(outputs_misc_->input_checktex,
749                      lyxrc.chktex_command.c_str());
750 }
751
752
753 void FormPreferences::applyPaths()
754 {
755         lyxrc.document_path = fl_get_input(paths_->input_default_path);
756         lyxrc.template_path = fl_get_input(paths_->input_template_path);
757
758         int button = fl_get_button(paths_->check_use_temp_dir);
759         string str  = fl_get_input(paths_->input_temp_dir);
760         if( !button ) str.erase();
761
762         lyxrc.use_tempdir = button;
763         lyxrc.tempdir_path = str;
764
765         button = fl_get_button(paths_->check_last_files);
766         str = fl_get_input(paths_->input_lastfiles);
767         if( !button ) str.erase();
768         
769         lyxrc.check_lastfiles = button;
770         lyxrc.lastfiles = str;
771         lyxrc.num_lastfiles = static_cast<unsigned int>
772                 (fl_get_counter_value(paths_->counter_lastfiles));
773
774         button = fl_get_button(paths_->check_make_backups);
775         str = fl_get_input(paths_->input_backup_path);
776         if( !button ) str.erase();
777
778         lyxrc.make_backup = button;
779         lyxrc.backupdir_path = str;
780
781         lyxrc.lyxpipes = fl_get_input(paths_->input_serverpipe);
782
783         // update view
784         updatePaths();
785 }
786
787
788 void FormPreferences::buildPaths()
789 {
790         paths_ = build_paths();
791
792         fl_set_input_return(paths_->input_default_path, FL_RETURN_CHANGED);
793         fl_set_input_return(paths_->input_template_path, FL_RETURN_CHANGED);
794         fl_set_input_return(paths_->input_temp_dir, FL_RETURN_CHANGED);
795         fl_set_input_return(paths_->input_lastfiles, FL_RETURN_CHANGED);
796         fl_set_input_return(paths_->input_backup_path, FL_RETURN_CHANGED);
797         fl_set_counter_return(paths_->counter_lastfiles, FL_RETURN_CHANGED);
798         fl_set_input_return(paths_->input_serverpipe, FL_RETURN_CHANGED);
799
800         // deactivate the browse buttons because they aren't implemented
801         fl_deactivate_object(paths_->button_document_browse);
802         fl_deactivate_object(paths_->button_template_browse);
803         fl_deactivate_object(paths_->button_temp_dir_browse);
804         fl_deactivate_object(paths_->button_lastfiles_browse);
805         fl_deactivate_object(paths_->button_backup_path_browse);
806         fl_deactivate_object(paths_->button_serverpipe_browse);
807         fl_set_object_lcol(paths_->button_document_browse, FL_INACTIVE);
808         fl_set_object_lcol(paths_->button_template_browse, FL_INACTIVE);
809         fl_set_object_lcol(paths_->button_temp_dir_browse, FL_INACTIVE);
810         fl_set_object_lcol(paths_->button_lastfiles_browse, FL_INACTIVE);
811         fl_set_object_lcol(paths_->button_backup_path_browse, FL_INACTIVE);
812         fl_set_object_lcol(paths_->button_serverpipe_browse, FL_INACTIVE);
813 }
814
815
816 void FormPreferences::feedbackPaths( FL_OBJECT const * const ob )
817 {
818         string str;
819         if( ob == paths_->input_default_path ) {
820                 str = N_("The default path for your documents.");
821         } else if ( ob == paths_->input_template_path ) {
822                 str = N_("The path that LyX will set when offering to choose a template.");
823         } else if ( ob == paths_->check_use_temp_dir ) {
824                 str = N_("Specify to use a temporary directory to store temporary TeX output.\nThis directory is deleted when you quit LyX.");
825         } else if ( ob == paths_->input_temp_dir ) {
826                 str = N_("The path that LyX will use to store temporary TeX output.");
827         } else if ( ob == paths_->check_last_files ) {
828                 str = N_("Specify to check whether the lastfiles still exist.");
829         } else if ( ob == paths_->input_lastfiles ) {
830                 str = N_("The file where the last-files information should be stored.");
831         } else if ( ob == paths_->counter_lastfiles ) {
832                 str = N_("Maximal number of lastfiles. Up to 9 can appear in the file menu.");
833         } else if ( ob == paths_->check_make_backups ) {
834                 str = N_("Set to false if you don't want LyX to create backup files.");
835         } else if ( ob == paths_->input_backup_path ) {
836                 str = N_("The path for storing backup files. If it is an empty string,\nLyX will store the backup file in the same directory as the original file.");
837         } else if ( ob == paths_->input_serverpipe ) {
838                 str = N_("This starts the lyxserver. The pipes get an additional extension\n\".in\" and \".out\". Only for advanced users.");
839         }
840         
841         fl_set_object_label(dialog_->text_warning, str.c_str());
842         fl_set_object_lsize(dialog_->text_warning, FL_SMALL_SIZE);
843 }
844
845
846 bool FormPreferences::inputPaths( FL_OBJECT const * const ob )
847 {
848         bool activate = true;
849         
850         if( !ob || ob == paths_->check_use_temp_dir ) {
851                 if( fl_get_button(paths_->check_use_temp_dir) ) {
852                         fl_activate_object(paths_->input_temp_dir);
853                         fl_set_object_lcol(paths_->input_temp_dir,
854                                            FL_BLACK);
855                 } else {
856                         fl_deactivate_object(paths_->input_temp_dir);
857                         fl_set_object_lcol(paths_->input_temp_dir,
858                                            FL_INACTIVE);
859                 }
860         }
861
862         if( !ob || ob == paths_->check_last_files ) {
863                 if( fl_get_button(paths_->check_last_files) ) {
864                         fl_activate_object(paths_->input_lastfiles);
865                         fl_set_object_lcol(paths_->input_lastfiles,
866                                            FL_BLACK);
867                 } else {
868                         fl_deactivate_object(paths_->input_lastfiles);
869                         fl_set_object_lcol(paths_->input_lastfiles,
870                                            FL_INACTIVE);
871                 }
872         }
873
874         if( !ob || ob == paths_->check_make_backups ) {
875                 if( fl_get_button(paths_->check_make_backups) ) {
876                         fl_activate_object(paths_->input_backup_path);
877                         fl_set_object_lcol(paths_->input_backup_path,
878                                            FL_BLACK);
879                 } else {
880                         fl_deactivate_object(paths_->input_backup_path);
881                         fl_set_object_lcol(paths_->input_backup_path,
882                                            FL_INACTIVE);
883                 }
884         }
885
886         if( !ob || ob == paths_->input_default_path ) {
887                 string name = fl_get_input(paths_->input_default_path);
888                 if( !WriteableDir(name) )
889                         return false;
890         }
891
892         if( !ob || ob == paths_->input_template_path ) {
893                 string name = fl_get_input(paths_->input_template_path);
894                 if( !ReadableDir(name) )
895                     return false;
896         }
897
898         if( !ob || ob == paths_->input_temp_dir ) {
899                 string name = fl_get_input(paths_->input_temp_dir);
900                 if( fl_get_button(paths_->check_make_backups)
901                     && !name.empty()
902                     && !WriteableDir(name) )
903                         return false;
904         }
905
906         if( !ob || ob == paths_->input_backup_path ) {
907                 string name = fl_get_input(paths_->input_backup_path);
908                 if( fl_get_button(paths_->check_make_backups)
909                     && !name.empty()
910                     && !WriteableDir(name) )
911                         return false;
912         }
913
914         if( !ob || ob == paths_->input_lastfiles ) {
915                 string name = fl_get_input(paths_->input_lastfiles);
916                 if( fl_get_button(paths_->check_last_files)
917                     && !name.empty()
918                     && !WriteableFile(name) )
919                         return false;
920         }
921
922         if( !ob || ob == paths_->input_serverpipe ) {
923                 string name = fl_get_input(paths_->input_serverpipe);
924                 if( !name.empty() ) {
925                         if( !WriteableFile(name, ".in") )
926                                 return false;
927                         if( !WriteableFile(name, ".out") )
928                                 return false;
929                 }
930         }
931
932         return activate;
933 }
934
935
936 void FormPreferences::updatePaths()
937 {
938         fl_set_input(paths_->input_default_path,
939                      lyxrc.document_path.c_str());
940         fl_set_input(paths_->input_template_path,
941                      lyxrc.template_path.c_str());
942
943         string str = string();
944         if( lyxrc.make_backup ) str = lyxrc.backupdir_path;
945
946         fl_set_button(paths_->check_make_backups,
947                       lyxrc.make_backup);
948         fl_set_input(paths_->input_backup_path, str.c_str());
949
950         str.erase();
951         if( lyxrc.use_tempdir ) str = lyxrc.tempdir_path;
952
953         fl_set_button(paths_->check_use_temp_dir,
954                       lyxrc.use_tempdir);
955         fl_set_input(paths_->input_temp_dir, str.c_str());
956
957         str.erase();
958         if( lyxrc.check_lastfiles ) str = lyxrc.lastfiles;
959
960         fl_set_button(paths_->check_last_files,
961                       lyxrc.check_lastfiles);           
962         fl_set_input(paths_->input_lastfiles, str.c_str());
963         fl_set_counter_value(paths_->counter_lastfiles,
964                              lyxrc.num_lastfiles);
965
966         fl_set_input(paths_->input_serverpipe, lyxrc.lyxpipes.c_str());
967
968         // Activate/Deactivate the input fields dependent on the state of the
969         // buttons.
970         inputPaths( 0 );
971 }
972
973
974 void FormPreferences::applyPrinter()
975 {
976         lyxrc.print_adapt_output = fl_get_button(printer_->check_adapt_output);
977         lyxrc.print_command = fl_get_input(printer_->input_command);
978         lyxrc.print_pagerange_flag = fl_get_input(printer_->input_page_range);
979         lyxrc.print_copies_flag = fl_get_input(printer_->input_copies);
980         lyxrc.print_reverse_flag = fl_get_input(printer_->input_reverse);
981         lyxrc.print_to_printer = fl_get_input(printer_->input_to_printer);
982         lyxrc.print_file_extension =
983                 fl_get_input(printer_->input_file_extension);
984         lyxrc.print_spool_command =
985                 fl_get_input(printer_->input_spool_command);
986         lyxrc.print_paper_flag = fl_get_input(printer_->input_paper_type);
987         lyxrc.print_evenpage_flag = fl_get_input(printer_->input_even_pages);
988         lyxrc.print_oddpage_flag = fl_get_input(printer_->input_odd_pages);
989         lyxrc.print_collcopies_flag = fl_get_input(printer_->input_collated);
990         lyxrc.print_landscape_flag = fl_get_input(printer_->input_landscape);
991         lyxrc.print_to_file = fl_get_input(printer_->input_to_file);
992         lyxrc.print_extra_options =
993                 fl_get_input(printer_->input_extra_options);
994         lyxrc.print_spool_printerprefix =
995                 fl_get_input(printer_->input_spool_prefix);
996         lyxrc.print_paper_dimension_flag =
997                 fl_get_input(printer_->input_paper_size);
998         lyxrc.printer = fl_get_input(printer_->input_name);
999 }
1000
1001
1002 void FormPreferences::feedbackPrinter( FL_OBJECT const * const ob )
1003 {
1004         string str;
1005
1006         if( ob == printer_->input_command ) {
1007                 str = N_("Your favorite print program, eg \"dvips\", \"dvilj4\"");
1008         } else if( ob == printer_->check_adapt_output ) {
1009                 str = N_("Set to true for LyX to pass the name of the destination printer to your\nprint command.");
1010         } else if( ob == printer_->input_to_printer ) {
1011                 str = N_("Option to pass to the print program to print on a specific printer.");
1012         } else if( ob == printer_->input_to_file ) {
1013                 str = N_("Option to pass to the print program to print to a file.");
1014         } else if( ob == printer_->input_file_extension ) {
1015                 str = N_("Extension of printer program output file. Usually .ps");
1016         } else if( ob == printer_->input_extra_options ) {
1017                 str = N_("Extra options to pass to printing program after everything else,\nbut before the filename of the DVI file to be printed.");
1018         } else if( ob == printer_->input_spool_command ) {
1019                 str = N_("When set, this printer option automatically prints to a file and then calls\na separate print spooling program on that file with the given name\nand arguments.");
1020         } else if( ob == printer_->input_spool_prefix ) {
1021                 str = N_("If you specify a printer name in the print dialog, the following argument\nis prepended along with the printer name after the spool command.");
1022         } else if( ob == printer_->input_name ) {
1023                 str = N_("The default printer to print on. If none is specified, LyX will\nuse the environment variable PRINTER.");
1024         } else if( ob == printer_->input_even_pages
1025                  || ob == printer_->input_odd_pages
1026                  || ob == printer_->input_page_range
1027                  || ob == printer_->input_reverse
1028                  || ob == printer_->input_landscape
1029                  || ob == printer_->input_copies
1030                  || ob == printer_->input_collated
1031                  || ob == printer_->input_paper_type
1032                  || ob == printer_->input_paper_size ) {
1033                 str = N_("Look at the man page for your favorite print program to learn\nwhich options to use.");
1034         }
1035         
1036         
1037         fl_set_object_label(dialog_->text_warning, str.c_str());
1038         fl_set_object_lsize(dialog_->text_warning, FL_SMALL_SIZE);
1039 }
1040
1041
1042 void FormPreferences::buildPrinter()
1043 {
1044         printer_ = build_printer();
1045
1046         fl_set_input_return(printer_->input_command, FL_RETURN_CHANGED);
1047         fl_set_input_return(printer_->input_page_range, FL_RETURN_CHANGED);
1048         fl_set_input_return(printer_->input_copies, FL_RETURN_CHANGED);
1049         fl_set_input_return(printer_->input_reverse, FL_RETURN_CHANGED);
1050         fl_set_input_return(printer_->input_to_printer, FL_RETURN_CHANGED);
1051         fl_set_input_return(printer_->input_file_extension, FL_RETURN_CHANGED);
1052         fl_set_input_return(printer_->input_spool_command, FL_RETURN_CHANGED);
1053         fl_set_input_return(printer_->input_paper_type, FL_RETURN_CHANGED);
1054         fl_set_input_return(printer_->input_even_pages, FL_RETURN_CHANGED);
1055         fl_set_input_return(printer_->input_odd_pages, FL_RETURN_CHANGED);
1056         fl_set_input_return(printer_->input_collated, FL_RETURN_CHANGED);
1057         fl_set_input_return(printer_->input_landscape, FL_RETURN_CHANGED);
1058         fl_set_input_return(printer_->input_to_file, FL_RETURN_CHANGED);
1059         fl_set_input_return(printer_->input_extra_options, FL_RETURN_CHANGED);
1060         fl_set_input_return(printer_->input_spool_prefix, FL_RETURN_CHANGED);
1061         fl_set_input_return(printer_->input_paper_size, FL_RETURN_CHANGED);
1062         fl_set_input_return(printer_->input_name, FL_RETURN_CHANGED);
1063 }
1064
1065
1066 void FormPreferences::updatePrinter()
1067 {
1068         fl_set_button(printer_->check_adapt_output,
1069                       lyxrc.print_adapt_output);
1070         fl_set_input(printer_->input_command,
1071                      lyxrc.print_command.c_str());
1072         fl_set_input(printer_->input_page_range,
1073                      lyxrc.print_pagerange_flag.c_str());
1074         fl_set_input(printer_->input_copies,
1075                      lyxrc.print_copies_flag.c_str());
1076         fl_set_input(printer_->input_reverse,
1077                      lyxrc.print_reverse_flag.c_str());
1078         fl_set_input(printer_->input_to_printer,
1079                      lyxrc.print_to_printer.c_str());
1080         fl_set_input(printer_->input_file_extension,
1081                      lyxrc.print_file_extension.c_str());
1082         fl_set_input(printer_->input_spool_command,
1083                      lyxrc.print_spool_command.c_str());
1084         fl_set_input(printer_->input_paper_type,
1085                      lyxrc.print_paper_flag.c_str());
1086         fl_set_input(printer_->input_even_pages,
1087                      lyxrc.print_evenpage_flag.c_str());
1088         fl_set_input(printer_->input_odd_pages,
1089                      lyxrc.print_oddpage_flag.c_str());
1090         fl_set_input(printer_->input_collated,
1091                      lyxrc.print_collcopies_flag.c_str());
1092         fl_set_input(printer_->input_landscape,
1093                      lyxrc.print_landscape_flag.c_str());
1094         fl_set_input(printer_->input_to_file,
1095                      lyxrc.print_to_file.c_str());
1096         fl_set_input(printer_->input_extra_options,
1097                      lyxrc.print_extra_options.c_str());
1098         fl_set_input(printer_->input_spool_prefix,
1099                      lyxrc.print_spool_printerprefix.c_str());
1100         fl_set_input(printer_->input_paper_size,
1101                      lyxrc.print_paper_dimension_flag.c_str());
1102         fl_set_input(printer_->input_name,
1103                      lyxrc.printer.c_str());
1104 }
1105
1106
1107 void FormPreferences::applyScreenFonts()
1108 {
1109         bool changed = false;
1110
1111         string str = fl_get_input(screen_fonts_->input_roman);
1112         if( lyxrc.roman_font_name != str ) {
1113                 changed = true;
1114                 lyxrc.roman_font_name = str;
1115         }
1116
1117         str = fl_get_input(screen_fonts_->input_sans);
1118         if( lyxrc.sans_font_name != str ) {
1119                 changed = true;
1120                 lyxrc.sans_font_name = str;
1121         }
1122
1123         str = fl_get_input(screen_fonts_->input_typewriter);
1124         if( lyxrc.typewriter_font_name != str ) {
1125                 changed = true;
1126                 lyxrc.typewriter_font_name = str;
1127         }
1128
1129         str = fl_get_input(screen_fonts_->input_screen_encoding);
1130         if( lyxrc.font_norm != str ) {
1131                 changed = true;
1132                 lyxrc.font_norm = str;
1133         }
1134
1135         bool button = fl_get_button(screen_fonts_->check_scalable);
1136         if( lyxrc.use_scalable_fonts != button ) {
1137                 changed = true;
1138                 lyxrc.use_scalable_fonts = button;
1139         }
1140
1141         int ivalue = fl_get_counter_value(screen_fonts_->counter_zoom);
1142         if( lyxrc.zoom != static_cast<unsigned int>( ivalue ) ) {
1143                 changed = true;
1144                 lyxrc.zoom = static_cast<unsigned int>( ivalue );
1145         }
1146         
1147         double dvalue = strToDbl(fl_get_input(screen_fonts_->input_tiny));
1148         if( lyxrc.font_sizes[LyXFont::SIZE_TINY] != dvalue ) {
1149                 changed = true;
1150                 lyxrc.font_sizes[LyXFont::SIZE_TINY] = dvalue;
1151         }
1152
1153         dvalue = strToDbl(fl_get_input(screen_fonts_->input_script));
1154         if( lyxrc.font_sizes[LyXFont::SIZE_SCRIPT] != dvalue ) {
1155                 changed = true;
1156                 lyxrc.font_sizes[LyXFont::SIZE_SCRIPT] = dvalue;
1157         }
1158
1159         dvalue = strToDbl(fl_get_input(screen_fonts_->input_footnote));
1160         if( lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE] != dvalue ) {
1161                 changed = true;
1162                 lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE] = dvalue;
1163         }
1164
1165         dvalue = strToDbl(fl_get_input(screen_fonts_->input_small));
1166         if( lyxrc.font_sizes[LyXFont::SIZE_SMALL] != dvalue ) {
1167                 changed = true;
1168                 lyxrc.font_sizes[LyXFont::SIZE_SMALL] = dvalue;
1169         }
1170
1171         dvalue = strToDbl(fl_get_input(screen_fonts_->input_normal));
1172         if( lyxrc.font_sizes[LyXFont::SIZE_NORMAL] != dvalue ) {
1173                 changed = true;
1174                 lyxrc.font_sizes[LyXFont::SIZE_NORMAL] = dvalue;
1175         }
1176
1177         dvalue = strToDbl(fl_get_input(screen_fonts_->input_large));
1178         if( lyxrc.font_sizes[LyXFont::SIZE_LARGE] != dvalue ) {
1179                 changed = true;
1180                 lyxrc.font_sizes[LyXFont::SIZE_LARGE] = dvalue;
1181         }
1182
1183         dvalue = strToDbl(fl_get_input(screen_fonts_->input_larger));
1184         if( lyxrc.font_sizes[LyXFont::SIZE_LARGER] != dvalue ) {
1185                 changed = true;
1186                 lyxrc.font_sizes[LyXFont::SIZE_LARGER] = dvalue;
1187         }
1188
1189         dvalue = strToDbl(fl_get_input(screen_fonts_->input_largest));
1190         if( lyxrc.font_sizes[LyXFont::SIZE_LARGEST] != dvalue ) {
1191                 changed = true;
1192                 lyxrc.font_sizes[LyXFont::SIZE_LARGEST] = dvalue;
1193         }
1194
1195         dvalue = strToDbl(fl_get_input(screen_fonts_->input_huge));
1196         if( lyxrc.font_sizes[LyXFont::SIZE_HUGE] != dvalue ) {
1197                 changed = true;
1198                 lyxrc.font_sizes[LyXFont::SIZE_HUGE] = dvalue;
1199         }
1200
1201         dvalue = strToDbl(fl_get_input(screen_fonts_->input_huger));
1202         if( lyxrc.font_sizes[LyXFont::SIZE_HUGER] != dvalue ) {
1203                 changed = true;
1204                 lyxrc.font_sizes[LyXFont::SIZE_HUGER] = dvalue;
1205         }
1206
1207         if( changed ) {
1208                 // Now update the buffers
1209                 // Can anything below here affect the redraw process?
1210                 lv_->getLyXFunc()->Dispatch(LFUN_SCREEN_FONT_UPDATE);
1211         }
1212 }
1213
1214
1215 void FormPreferences::buildScreenFonts()
1216 {
1217         screen_fonts_ = build_screen_fonts();
1218
1219         fl_set_input_return(screen_fonts_->input_roman, FL_RETURN_CHANGED);
1220         fl_set_input_return(screen_fonts_->input_sans, FL_RETURN_CHANGED);
1221         fl_set_input_return(screen_fonts_->input_typewriter,
1222                             FL_RETURN_CHANGED);
1223         fl_set_input_return(screen_fonts_->input_screen_encoding,
1224                             FL_RETURN_CHANGED);
1225         fl_set_counter_return(screen_fonts_->counter_zoom, FL_RETURN_CHANGED);
1226         fl_set_input_return(screen_fonts_->input_tiny, FL_RETURN_CHANGED);
1227         fl_set_input_return(screen_fonts_->input_script, FL_RETURN_CHANGED);
1228         fl_set_input_return(screen_fonts_->input_footnote, FL_RETURN_CHANGED);
1229         fl_set_input_return(screen_fonts_->input_small, FL_RETURN_CHANGED);
1230         fl_set_input_return(screen_fonts_->input_normal, FL_RETURN_CHANGED);
1231         fl_set_input_return(screen_fonts_->input_large, FL_RETURN_CHANGED);
1232         fl_set_input_return(screen_fonts_->input_larger, FL_RETURN_CHANGED);
1233         fl_set_input_return(screen_fonts_->input_largest, FL_RETURN_CHANGED);
1234         fl_set_input_return(screen_fonts_->input_huge, FL_RETURN_CHANGED);
1235         fl_set_input_return(screen_fonts_->input_huger, FL_RETURN_CHANGED);
1236 }
1237
1238         
1239 void FormPreferences::feedbackScreenFonts(FL_OBJECT const * const ob )
1240 {
1241         string str;
1242
1243         if( ob == screen_fonts_->input_roman
1244             || ob == screen_fonts_->input_sans
1245             || ob == screen_fonts_->input_typewriter ) {
1246                 str = N_("The screen fonts used to display the text while editing.");
1247         } else if( ob == screen_fonts_->check_scalable ) {
1248                 str = N_("Allow the use of scalable screen fonts? If false, LyX will use the\nclosest existing size for a match. Use this if the scalable fonts\nlook bad and you have many fixed size fonts.");
1249         } else if( ob == screen_fonts_->input_screen_encoding ) {
1250                 str = N_("The norm for the screen fonts.");
1251         } else if( ob == screen_fonts_->counter_zoom ) {
1252                 str = N_("The zoom percentage for screen fonts.\nA setting of 100% will make the fonts roughly the same size as on paper.");
1253         } else if( ob == screen_fonts_->input_tiny
1254                    || ob == screen_fonts_->input_script
1255                    || ob == screen_fonts_->input_footnote
1256                    || ob == screen_fonts_->input_small
1257                    || ob == screen_fonts_->input_large
1258                    || ob == screen_fonts_->input_larger
1259                    || ob == screen_fonts_->input_larger
1260                    || ob == screen_fonts_->input_largest
1261                    || ob == screen_fonts_->input_normal
1262                    || ob == screen_fonts_->input_huge
1263                    || ob == screen_fonts_->input_huger ) {
1264                 str = N_("The font sizes used for calculating the scaling of the screen fonts.");
1265         }
1266         
1267         fl_set_object_label(dialog_->text_warning, str.c_str());
1268         fl_set_object_lsize(dialog_->text_warning, FL_SMALL_SIZE);
1269 }
1270
1271
1272 bool FormPreferences::inputScreenFonts()
1273 {
1274         bool activate = true;
1275         string str;
1276
1277         // Make sure that all fonts all have positive entries
1278         // Also note that an empty entry is returned as 0.0 by strToDbl
1279         if (0.0 >= strToDbl(fl_get_input(screen_fonts_->input_tiny))
1280             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_script))
1281             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_footnote))
1282             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_small))
1283             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_normal))
1284             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_large))
1285             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_larger))
1286             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_largest))
1287             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_huge))
1288             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_huger))) {
1289                 activate = false;
1290                 str = N_("WARNING! Fonts must be positive!");
1291
1292         // Fontsizes -- tiny < script < footnote etc.
1293         } else if (strToDbl(fl_get_input(screen_fonts_->input_tiny)) >
1294                    strToDbl(fl_get_input(screen_fonts_->input_script)) ||
1295                    strToDbl(fl_get_input(screen_fonts_->input_script)) >
1296                    strToDbl(fl_get_input(screen_fonts_->input_footnote)) ||
1297                    strToDbl(fl_get_input(screen_fonts_->input_footnote)) >
1298                    strToDbl(fl_get_input(screen_fonts_->input_small)) ||
1299                    strToDbl(fl_get_input(screen_fonts_->input_small)) >
1300                    strToDbl(fl_get_input(screen_fonts_->input_normal)) ||
1301                    strToDbl(fl_get_input(screen_fonts_->input_normal)) >
1302                    strToDbl(fl_get_input(screen_fonts_->input_large)) ||
1303                    strToDbl(fl_get_input(screen_fonts_->input_large)) >
1304                    strToDbl(fl_get_input(screen_fonts_->input_larger)) ||
1305                    strToDbl(fl_get_input(screen_fonts_->input_larger)) >
1306                    strToDbl(fl_get_input(screen_fonts_->input_largest)) ||
1307                    strToDbl(fl_get_input(screen_fonts_->input_largest)) >
1308                    strToDbl(fl_get_input(screen_fonts_->input_huge)) ||
1309                    strToDbl(fl_get_input(screen_fonts_->input_huge)) >
1310                    strToDbl(fl_get_input(screen_fonts_->input_huger))) {
1311                 activate = false;
1312
1313                 str = N_("WARNING! Fonts must be input in the order tiny > script>\nfootnote > small > normal > large > larger > largest > huge > huger.");
1314         }
1315
1316         if( !activate ) {
1317                 fl_set_object_label(dialog_->text_warning, str.c_str());
1318                 fl_set_object_lsize(dialog_->text_warning, FL_SMALL_SIZE);
1319         }
1320         
1321         return activate;
1322 }
1323
1324
1325 void FormPreferences::updateScreenFonts()
1326 {
1327         fl_set_input(screen_fonts_->input_roman,
1328                      lyxrc.roman_font_name.c_str());
1329         fl_set_input(screen_fonts_->input_sans,
1330                      lyxrc.sans_font_name.c_str());
1331         fl_set_input(screen_fonts_->input_typewriter,
1332                      lyxrc.typewriter_font_name.c_str());
1333         fl_set_input(screen_fonts_->input_screen_encoding,
1334                      lyxrc.font_norm.c_str());
1335         fl_set_button(screen_fonts_->check_scalable,
1336                       lyxrc.use_scalable_fonts);
1337         fl_set_counter_value(screen_fonts_->counter_zoom,
1338                              lyxrc.zoom);
1339         fl_set_input(screen_fonts_->input_tiny,
1340                      tostr(lyxrc.font_sizes[LyXFont::SIZE_TINY]).c_str());
1341         fl_set_input(screen_fonts_->input_script,
1342                      tostr(lyxrc.font_sizes[LyXFont::SIZE_SCRIPT]).c_str());
1343         fl_set_input(screen_fonts_->input_footnote,
1344                      tostr(lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE]).c_str());
1345         fl_set_input(screen_fonts_->input_small,
1346                      tostr(lyxrc.font_sizes[LyXFont::SIZE_SMALL]).c_str());
1347         fl_set_input(screen_fonts_->input_normal,
1348                      tostr(lyxrc.font_sizes[LyXFont::SIZE_NORMAL]).c_str());
1349         fl_set_input(screen_fonts_->input_large,
1350                      tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGE]).c_str());
1351         fl_set_input(screen_fonts_->input_larger,
1352                      tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGER]).c_str());
1353         fl_set_input(screen_fonts_->input_largest,
1354                      tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGEST]).c_str());
1355         fl_set_input(screen_fonts_->input_huge,
1356                      tostr(lyxrc.font_sizes[LyXFont::SIZE_HUGE]).c_str());
1357         fl_set_input(screen_fonts_->input_huger,
1358                      tostr(lyxrc.font_sizes[LyXFont::SIZE_HUGER]).c_str());
1359 }
1360
1361
1362 void FormPreferences::applySpellChecker()
1363 {
1364
1365         string choice = "none";
1366         switch(fl_get_choice(spellchecker_->choice_spell_command)) {
1367         case 1:
1368                 choice = "none";
1369                 break;
1370         case 2:
1371                 choice = "ispell";
1372                 break;
1373         case 3:
1374                 choice = "aspell";
1375                 break;
1376         default:
1377                 break;
1378         }
1379         lyxrc.isp_command = choice;
1380
1381         // If spell checker == "none", all other input set to off.
1382         if( fl_get_choice(spellchecker_->choice_spell_command) == 1 ) {
1383                 lyxrc.isp_use_alt_lang = false;
1384                 lyxrc.isp_alt_lang.erase();
1385
1386                 lyxrc.isp_use_esc_chars = false;
1387                 lyxrc.isp_esc_chars.erase();
1388
1389                 lyxrc.isp_use_pers_dict = false;
1390                 lyxrc.isp_pers_dict.erase();
1391
1392                 lyxrc.isp_accept_compound = false;
1393                 lyxrc.isp_use_input_encoding = false;
1394         } else {
1395                 int button = fl_get_button(spellchecker_->check_alt_lang);
1396                 choice = fl_get_input(spellchecker_->input_alt_lang);
1397                 if( button && choice.empty() ) button = 0;
1398                 if( !button ) choice.erase();
1399
1400                 lyxrc.isp_use_alt_lang = static_cast<bool>(button);
1401                 lyxrc.isp_alt_lang = choice;
1402
1403                 button = fl_get_button(spellchecker_->check_escape_chars);
1404                 choice = fl_get_input(spellchecker_->input_escape_chars);
1405                 if( button && choice.empty() ) button = 0;
1406                 if( !button ) choice.erase();
1407         
1408                 lyxrc.isp_use_esc_chars = static_cast<bool>(button);
1409                 lyxrc.isp_esc_chars = choice;
1410
1411                 button = fl_get_button(spellchecker_->check_personal_dict);
1412                 choice = fl_get_input(spellchecker_->input_personal_dict);
1413                 if( button && choice.empty() ) button = 0;
1414                 if( !button ) choice.erase();
1415
1416                 lyxrc.isp_use_pers_dict = static_cast<bool>(button);
1417                 lyxrc.isp_pers_dict = choice;
1418
1419                 button = fl_get_button(spellchecker_->check_compound_words);
1420                 lyxrc.isp_accept_compound = static_cast<bool>(button);
1421
1422                 button = fl_get_button(spellchecker_->check_input_enc);
1423                 lyxrc.isp_use_input_encoding = static_cast<bool>(button);
1424         }
1425
1426         // Reset view
1427         updateSpellChecker();
1428 }
1429
1430
1431 void FormPreferences::buildSpellchecker()
1432 {
1433         spellchecker_ = build_spellchecker();
1434
1435         fl_addto_choice(spellchecker_->choice_spell_command,
1436                         _(" none | ispell | aspell "));
1437         fl_set_input_return(spellchecker_->input_alt_lang,
1438                             FL_RETURN_CHANGED);
1439         fl_set_input_return(spellchecker_->input_escape_chars,
1440                             FL_RETURN_CHANGED);
1441         fl_set_input_return(spellchecker_->input_personal_dict,
1442                             FL_RETURN_CHANGED);
1443
1444         // deactivate the browse button because it isn't implemented
1445         fl_deactivate_object(spellchecker_->button_personal_dict);
1446         fl_set_object_lcol(spellchecker_->button_personal_dict,
1447                            FL_INACTIVE);
1448 }
1449
1450
1451 void FormPreferences::feedbackSpellChecker( FL_OBJECT const * const ob )
1452 {
1453         string str;
1454         if( ob == spellchecker_->choice_spell_command ) {
1455                 str = N_("What command runs the spell checker?");
1456         } else if( ob == spellchecker_->check_alt_lang ) {
1457                 str = N_("Specify an alternate language.\nThe default is to use the language of the document.");
1458         } else if( ob == spellchecker_->check_escape_chars ) {
1459                 str = N_("Specify additional chars that can be part of a word.");
1460         } else if( ob == spellchecker_->check_personal_dict ) {
1461                 str = N_("Specify an alternate personal dictionary file.\nE.g. \".ispell_english\".");
1462         } else if( ob == spellchecker_->check_compound_words ) {
1463                 str = N_("Consider run-together words, such as \"notthe\" for \"not the\",\nas legal words?");
1464         } else if( ob == spellchecker_->check_input_enc ) {
1465                 str = N_("Specify whether to pass the -T input encoding option to ispell.\nEnable this if you can't spellcheck words with international letters\nin them.\nThis may not work with all dictionaries.");
1466         }
1467
1468         fl_set_object_label(dialog_->text_warning, str.c_str());
1469         fl_set_object_lsize(dialog_->text_warning, FL_SMALL_SIZE);
1470 }
1471
1472
1473 bool FormPreferences::inputSpellChecker( FL_OBJECT const * const ob )
1474 {
1475         // Allow/dissallow input
1476
1477         // If spell checker == "none", disable all input.
1478         if( !ob || ob == spellchecker_->choice_spell_command ) {
1479                 if( fl_get_choice(spellchecker_->choice_spell_command) == 1 ) {
1480                         fl_deactivate_object( spellchecker_->check_alt_lang );
1481                         fl_deactivate_object( spellchecker_->input_alt_lang );
1482                         fl_deactivate_object( spellchecker_->check_escape_chars );
1483                         fl_deactivate_object( spellchecker_->input_escape_chars );
1484                         fl_deactivate_object( spellchecker_->check_personal_dict );
1485                         fl_deactivate_object( spellchecker_->input_personal_dict );
1486                         fl_deactivate_object( spellchecker_->check_compound_words );
1487                         fl_deactivate_object( spellchecker_->check_input_enc );
1488                         return true;
1489                 } else {
1490                         fl_activate_object( spellchecker_->check_alt_lang );
1491                         fl_activate_object( spellchecker_->check_escape_chars );
1492                         fl_activate_object( spellchecker_->check_personal_dict );
1493                         fl_activate_object( spellchecker_->check_compound_words );
1494                         fl_activate_object( spellchecker_->check_input_enc );
1495                 }
1496         }
1497
1498         if( !ob || ob == spellchecker_->check_alt_lang ) {
1499                 if( fl_get_button(spellchecker_->check_alt_lang) ) {
1500                         fl_activate_object(spellchecker_->input_alt_lang);
1501                         fl_set_object_lcol(spellchecker_->input_alt_lang,
1502                                            FL_BLACK);
1503                 } else {
1504                         fl_deactivate_object(spellchecker_->input_alt_lang);
1505                         fl_set_object_lcol(spellchecker_->input_alt_lang,
1506                                            FL_INACTIVE);
1507                 }
1508         }
1509
1510         if( !ob || ob == spellchecker_->check_escape_chars ) {
1511                 if( fl_get_button(spellchecker_->check_escape_chars) ) {
1512                         fl_activate_object(spellchecker_->input_escape_chars);
1513                         fl_set_object_lcol(spellchecker_->input_escape_chars,
1514                                            FL_BLACK);
1515                 } else {
1516                         fl_deactivate_object(spellchecker_->input_escape_chars);
1517                         fl_set_object_lcol(spellchecker_->input_escape_chars,
1518                                            FL_INACTIVE);
1519                 }
1520         }
1521
1522         if( !ob || ob == spellchecker_->check_personal_dict ) {
1523                 if( fl_get_button(spellchecker_->check_personal_dict) ) {
1524                         fl_activate_object(spellchecker_->input_personal_dict);
1525                         fl_set_object_lcol(spellchecker_->input_personal_dict,
1526                                            FL_BLACK);
1527                 } else {
1528                         fl_deactivate_object(spellchecker_->input_personal_dict);
1529                         fl_set_object_lcol(spellchecker_->input_personal_dict,
1530                                            FL_INACTIVE);
1531                 }
1532         }
1533         
1534         return true; // all input is valid!
1535 }
1536
1537
1538 void FormPreferences::updateSpellChecker()
1539 {
1540         int choice = 1;
1541         if( lyxrc.isp_command == "none" )
1542                 choice = 1;
1543         else if( lyxrc.isp_command == "ispell" )
1544                 choice = 2;
1545         else if( lyxrc.isp_command == "aspell" )
1546                 choice = 3;
1547         fl_set_choice(spellchecker_->choice_spell_command, choice);
1548         
1549         string str = string();
1550         if( lyxrc.isp_use_alt_lang ) str = lyxrc.isp_alt_lang;
1551
1552         fl_set_button(spellchecker_->check_alt_lang,
1553                       lyxrc.isp_use_alt_lang);
1554         fl_set_input(spellchecker_->input_alt_lang, str.c_str());
1555         
1556         str.erase();
1557         if( lyxrc.isp_use_esc_chars ) str = lyxrc.isp_esc_chars;
1558
1559         fl_set_button(spellchecker_->check_escape_chars,
1560                       lyxrc.isp_use_esc_chars);
1561         fl_set_input(spellchecker_->input_escape_chars, str.c_str());
1562
1563         str.erase();
1564         if( lyxrc.isp_use_pers_dict ) str = lyxrc.isp_pers_dict;
1565
1566         fl_set_button(spellchecker_->check_personal_dict,
1567                       lyxrc.isp_use_pers_dict);
1568         fl_set_input(spellchecker_->input_personal_dict, str.c_str());
1569
1570         fl_set_button(spellchecker_->check_compound_words,
1571                       lyxrc.isp_accept_compound);
1572         fl_set_button(spellchecker_->check_input_enc,
1573                       lyxrc.isp_use_input_encoding);
1574
1575         // Activate/Deactivate the input fields dependent on the state of the
1576         // buttons.
1577         inputSpellChecker( 0 );
1578 }
1579
1580
1581 bool FormPreferences::WriteableDir( string const & name ) const
1582 {
1583         bool success = true;
1584         string str;
1585
1586         if( !AbsolutePath(name) ) {
1587                 success = false;
1588                 str = N_("WARNING! The absolute path is required.");
1589         }
1590
1591         FileInfo tp(name);
1592         if( success && !tp.isDir() ) {
1593                 success = false;
1594                 str = N_("WARNING! Directory does not exist.");
1595         }
1596
1597         if( success && !tp.writable() ) {
1598                 success = false;
1599                 str = N_("WARNING! Cannot write to this directory.");
1600         }
1601
1602         if( !success ) {
1603                 fl_set_object_label(dialog_->text_warning, str.c_str());
1604                 fl_set_object_lsize(dialog_->text_warning, FL_SMALL_SIZE);
1605         }
1606         
1607         return success;
1608 }
1609
1610
1611 bool FormPreferences::ReadableDir( string const & name ) const
1612 {
1613         bool success = true;
1614         string str;
1615
1616         if( !AbsolutePath(name) ) {
1617                 success = false;
1618                 str = N_("WARNING! The absolute path is required.");
1619         }
1620
1621         FileInfo tp(name);
1622         if( success && !tp.isDir() ) {
1623                 success = false;
1624                 str = N_("WARNING! Directory does not exist.");
1625         }
1626
1627         if( success && !tp.readable() ) {
1628                 success = false;
1629                 str = N_("WARNING! Cannot read this directory.");
1630         }
1631
1632         if( !success ) {
1633                 fl_set_object_label(dialog_->text_warning, str.c_str());
1634                 fl_set_object_lsize(dialog_->text_warning, FL_SMALL_SIZE);
1635         }
1636
1637         return success;
1638 }
1639
1640
1641 bool FormPreferences::WriteableFile( string const & name, string const & suffix ) const
1642 {
1643         // A writeable file is either:
1644         // * An existing file to which we have write access, or
1645         // * A file that doesn't yet exist but that would exist in a writeable
1646         //   directory.
1647
1648         bool success = true;
1649         string str;
1650
1651         if( name.empty() ) {
1652                 success = false;
1653                 str = N_("WARNING! No file input.");
1654         }
1655
1656         string dir = OnlyPath(name);
1657         if( success && !AbsolutePath(dir) ) {
1658                 success = false;
1659                 str = N_("WARNING! The absolute path is required.");
1660         }
1661
1662         FileInfo d;
1663         {
1664                 FileInfo d1(dir);
1665                 FileInfo d2(name);
1666                 if( d2.isDir() )
1667                         d = d2;
1668                 else
1669                         d = d1;
1670         }
1671         
1672         if( success && !d.isDir()) {
1673                 success = false;
1674                 str = N_("WARNING! Directory does not exist.");
1675         }
1676         
1677         if( success && !d.writable() ) {
1678                 success = false;
1679                 str = N_("WARNING! Cannot write to this directory.");
1680         }
1681
1682         FileInfo f(name+suffix);
1683         if( success && (dir == name || f.isDir()) ) {
1684                 success = false;
1685                 str = N_("WARNING! A file is required, not a directory.");
1686         }
1687
1688         if( success && (f.exist() && !f.writable()) ) {
1689                 success = false;
1690                 str = N_("WARNING! Cannot write to this file.");
1691         }
1692         
1693         if( !success ) {
1694                 fl_set_object_label(dialog_->text_warning, str.c_str());
1695                 fl_set_object_lsize(dialog_->text_warning, FL_SMALL_SIZE);
1696         }
1697
1698         return success;
1699 }