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