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