]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormPreferences.C
a4eaeea4e002ebdbf8e1e0a16a29be47aaecb3e6
[lyx.git] / src / frontends / xforms / FormPreferences.C
1 /**
2  * \file FormPreferences.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "FormPreferences.h"
14 #include "forms/form_preferences.h"
15
16 #include "FormColorpicker.h"
17 #include "forms_gettext.h"
18 #include "input_validators.h"
19 #include "xformsBC.h"
20 #include "xforms_helpers.h"
21
22 #include "controllers/ControlPrefs.h"
23 #include "controllers/frnt_lang.h"
24 #include "controllers/helper_funcs.h" // getSecond
25
26 #include "buffer.h"
27 #include "lastfiles.h"
28 #include "LColor.h"
29 #include "lyxfont.h"
30
31 #include "support/lstrings.h"
32 #include "support/tostr.h"
33 #include "support/path_defines.h"
34 #include "support/filetools.h"
35
36 #include "lyx_forms.h"
37 #include "combox.h"
38
39 #include <iomanip>
40
41 using std::endl;
42 using std::make_pair;
43 using std::max;
44 using std::min;
45
46 using std::pair;
47 using std::vector;
48 using std::string;
49
50 namespace lyx {
51
52 using support::AddName;
53 using support::ChangeExtension;
54 using support::rtrim;
55 using support::strToDbl;
56 using support::trim;
57 using support::user_lyxdir;
58
59 namespace frontend {
60
61 namespace {
62
63 string makeFontName(string const & family, string const & foundry)
64 {
65         if (foundry.empty())
66                 return family;
67         return family + ',' + foundry;
68 }
69
70
71 pair<string,string> parseFontName(string const & name)
72 {
73         string::size_type const idx = name.find(',');
74         if (idx == string::npos)
75                 return make_pair(name, string());
76         return make_pair(name.substr(0, idx),
77                          name.substr(idx+1));
78 }
79
80
81
82 #if FL_VERSION == 0 || (FL_REVISION == 0 && FL_FIXLEVEL < 2)
83 bool const scalableTabfolders = false;
84 #else
85 bool const scalableTabfolders = true;
86 #endif
87
88 } // namespace anon
89
90
91 typedef FormController<ControlPrefs, FormView<FD_preferences> > base_class;
92
93
94 FormPreferences::FormPreferences(Dialog & parent)
95         : base_class(parent, _("Preferences"), scalableTabfolders),
96           colors_(*this), converters_(*this), inputs_misc_(*this),
97           formats_(*this), interface_(*this), language_(*this),
98           lnf_misc_(*this), identity_(*this), outputs_misc_(*this),
99           paths_(*this), printer_(*this), screen_fonts_(*this),
100           spelloptions_(*this)
101 {
102 }
103
104
105 void FormPreferences::redraw()
106 {
107         if (!(form() && form()->visible))
108                 return;
109         fl_redraw_form(form());
110
111         FL_FORM * form2 = fl_get_active_folder(dialog_->tabfolder_prefs);
112         if (!(form2 && form2->visible))
113                 return;
114         fl_redraw_form(form2);
115
116         FL_FORM * form3 = 0;
117         if (form2 == converters_tab_->form)
118                 form3 = fl_get_active_folder(converters_tab_->tabfolder_inner);
119
120         else if (form2 == look_n_feel_tab_->form)
121                 form3 = fl_get_active_folder(look_n_feel_tab_->tabfolder_inner);
122
123         else if (form2 == inputs_tab_->form)
124                 form3 = fl_get_active_folder(inputs_tab_->tabfolder_inner);
125
126         else if (form2 == outputs_tab_->form)
127                 form3 = fl_get_active_folder(outputs_tab_->tabfolder_inner);
128
129         else if (form2 == lang_opts_tab_->form)
130                 form3 = fl_get_active_folder(lang_opts_tab_->tabfolder_inner);
131
132         if (form3 && form3->visible)
133                 fl_redraw_form(form3);
134 }
135
136
137 void FormPreferences::hide()
138 {
139         // We need to hide the active tabfolder otherwise we get a
140         // BadDrawable error from X window and LyX crashes without saving.
141         FL_FORM * inner_form = fl_get_active_folder(dialog_->tabfolder_prefs);
142         if (inner_form && inner_form->visible)
143                 fl_hide_form(inner_form);
144         FormDialogView::hide();
145 }
146
147
148 void FormPreferences::build()
149 {
150         dialog_.reset(build_preferences(this));
151
152         // Manage the restore, save, apply and cancel/close buttons
153         bcview().setOK(dialog_->button_ok);
154         bcview().setApply(dialog_->button_apply);
155         bcview().setCancel(dialog_->button_close);
156         bcview().setRestore(dialog_->button_restore);
157
158         // Allow the base class to control messages
159         setMessageWidget(dialog_->text_warning);
160
161         // build the tab folders
162         converters_tab_.reset(build_preferences_inner_tab(this));
163         look_n_feel_tab_.reset(build_preferences_inner_tab(this));
164         inputs_tab_.reset(build_preferences_inner_tab(this));
165         outputs_tab_.reset(build_preferences_inner_tab(this));
166         lang_opts_tab_.reset(build_preferences_inner_tab(this));
167
168         // build actual tabfolder contents
169         // these will become nested tabfolders
170         colors_.build();
171         converters_.build();
172         formats_.build();
173         inputs_misc_.build();
174         interface_.build();
175         language_.build();
176         lnf_misc_.build();
177         identity_.build();
178         outputs_misc_.build();
179         paths_.build();
180         printer_.build();
181         screen_fonts_.build();
182         spelloptions_.build();
183
184         // Enable the tabfolders to be rescaled correctly.
185         if (scalableTabfolders) {
186                 FL_OBJECT * folder = dialog_->tabfolder_prefs;
187                 fl_set_tabfolder_autofit(folder, FL_FIT);
188
189                 folder = look_n_feel_tab_->tabfolder_inner;
190                 fl_set_tabfolder_autofit(folder, FL_FIT);
191
192                 folder = converters_tab_->tabfolder_inner;
193                 fl_set_tabfolder_autofit(folder, FL_FIT);
194
195                 folder = inputs_tab_->tabfolder_inner;
196                 fl_set_tabfolder_autofit(folder, FL_FIT);
197
198                 folder = outputs_tab_->tabfolder_inner;
199                 fl_set_tabfolder_autofit(folder, FL_FIT);
200
201                 folder = lang_opts_tab_->tabfolder_inner;
202                 fl_set_tabfolder_autofit(folder, FL_FIT);
203         }
204
205         // Stack tabs
206         // Now add them to the tabfolder
207         fl_addto_tabfolder(dialog_->tabfolder_prefs,
208                            _("Look & Feel").c_str(),
209                            look_n_feel_tab_->form);
210         fl_addto_tabfolder(dialog_->tabfolder_prefs,
211                            _("Lang Opts").c_str(),
212                            lang_opts_tab_->form);
213         fl_addto_tabfolder(dialog_->tabfolder_prefs,
214                            _("Conversion").c_str(),
215                            converters_tab_->form);
216         fl_addto_tabfolder(dialog_->tabfolder_prefs,
217                            _("Inputs").c_str(),
218                            inputs_tab_->form);
219         fl_addto_tabfolder(dialog_->tabfolder_prefs,
220                            _("Outputs").c_str(),
221                            outputs_tab_->form);
222
223         // now build the nested tabfolders
224         // Starting with look and feel
225         fl_addto_tabfolder(look_n_feel_tab_->tabfolder_inner,
226                            _("Screen Fonts").c_str(),
227                            screen_fonts_.dialog()->form);
228         fl_addto_tabfolder(look_n_feel_tab_->tabfolder_inner,
229                            _("Interface").c_str(),
230                            interface_.dialog()->form);
231         fl_addto_tabfolder(look_n_feel_tab_->tabfolder_inner,
232                            _("Colors").c_str(),
233                            colors_.dialog()->form);
234         fl_addto_tabfolder(look_n_feel_tab_->tabfolder_inner,
235                            _("Misc").c_str(),
236                            lnf_misc_.dialog()->form);
237         fl_addto_tabfolder(look_n_feel_tab_->tabfolder_inner,
238                            _("Identity").c_str(),
239                            identity_.dialog()->form);
240
241         // then build converters
242         fl_addto_tabfolder(converters_tab_->tabfolder_inner,
243                            _("Formats").c_str(),
244                            formats_.dialog()->form);
245         fl_addto_tabfolder(converters_tab_->tabfolder_inner,
246                            _("Converters").c_str(),
247                            converters_.dialog()->form);
248
249         // then build inputs
250         // Paths should probably go in a few inner_tab called Files
251         fl_addto_tabfolder(inputs_tab_->tabfolder_inner,
252                            _("Paths").c_str(),
253                            paths_.dialog()->form);
254         fl_addto_tabfolder(inputs_tab_->tabfolder_inner,
255                            _("Misc").c_str(),
256                            inputs_misc_.dialog()->form);
257
258         // then building outputs
259         fl_addto_tabfolder(outputs_tab_->tabfolder_inner,
260                            _("Printer").c_str(),
261                            printer_.dialog()->form);
262         fl_addto_tabfolder(outputs_tab_->tabfolder_inner,
263                            _("Misc").c_str(),
264                            outputs_misc_.dialog()->form);
265
266         // then building usage
267         fl_addto_tabfolder(lang_opts_tab_->tabfolder_inner,
268                            _("Spell checker").c_str(),
269                            spelloptions_.dialog()->form);
270         fl_addto_tabfolder(lang_opts_tab_->tabfolder_inner,
271                            _("Language").c_str(),
272                            language_.dialog()->form);
273 }
274
275
276 void FormPreferences::apply()
277 {
278         // set the new lyxrc entries
279         // many of these need to trigger other functions when the assignment
280         // is made.  For example, screen zoom and font types.  These could be
281         // handled either by signals/slots in lyxrc or just directly call the
282         // associated functions here.
283         // There are other problems with this scheme.  We really should check
284         // what we copy to make sure that it really is necessary to do things
285         // like update the screen fonts because that flushes the textcache
286         // and other stuff which may cost us a lot on slower/high-load
287         // machines.
288
289         LyXRC & rc(controller().rc());
290
291         colors_.apply();
292         inputs_misc_.apply(rc);
293         interface_.apply(rc);
294         language_.apply(rc);
295         lnf_misc_.apply(rc);
296         identity_.apply(rc);
297         outputs_misc_.apply(rc);
298         paths_.apply(rc);
299         printer_.apply(rc);
300         screen_fonts_.apply(rc);
301         spelloptions_.apply(rc);
302
303         // The "Save" button has been pressed.
304         if (dialog().isClosing() && colors_.modifiedXformsPrefs) {
305                 string const filename =
306                         AddName(user_lyxdir(), "preferences.xform");
307                 colors_.modifiedXformsPrefs = !XformsColor::write(filename);
308         }
309 }
310
311
312 string const FormPreferences::getFeedback(FL_OBJECT * ob)
313 {
314         BOOST_ASSERT(ob);
315
316         if (ob->form->fdui == colors_.dialog())
317                 return colors_.feedback(ob);
318         if (ob->form->fdui == converters_.dialog())
319                 return converters_.feedback(ob);
320         if (ob->form->fdui == formats_.dialog())
321                 return formats_.feedback(ob);
322         if (ob->form->fdui == inputs_misc_.dialog())
323                 return inputs_misc_.feedback(ob);
324         if (ob->form->fdui == interface_.dialog())
325                 return interface_.feedback(ob);
326         if (ob->form->fdui == language_.dialog())
327                 return language_.feedback(ob);
328         if (ob->form->fdui == lnf_misc_.dialog())
329                 return lnf_misc_.feedback(ob);
330         if (ob->form->fdui == outputs_misc_.dialog())
331                 return outputs_misc_.feedback(ob);
332         if (ob->form->fdui == paths_.dialog())
333                 return paths_.feedback(ob);
334         if (ob->form->fdui == printer_.dialog())
335                 return printer_.feedback(ob);
336         if (ob->form->fdui == screen_fonts_.dialog())
337                 return screen_fonts_.feedback(ob);
338         if (ob->form->fdui == spelloptions_.dialog())
339                 return spelloptions_.feedback(ob);
340
341         return string();
342 }
343
344
345 ButtonPolicy::SMInput FormPreferences::input(FL_OBJECT * ob, long)
346 {
347         BOOST_ASSERT(ob);
348
349         bool valid = true;
350
351         // whatever checks you need to ensure the user hasn't entered
352         // some totally ridiculous value somewhere.  Change activate to suit.
353         // comments before each test describe what is _valid_
354
355         if (ob->form->fdui == colors_.dialog()) {
356                 colors_.input(ob);
357         } else if (ob->form->fdui == converters_.dialog()) {
358                 valid = converters_.input(ob);
359         } else if (ob->form->fdui == formats_.dialog()) {
360                 valid = formats_.input(ob);
361         } else if  (ob->form->fdui == interface_.dialog()) {
362                 valid = interface_.input(ob);
363         } else if  (ob->form->fdui == language_.dialog()) {
364                 valid = language_.input(ob);
365         } else if  (ob->form->fdui == paths_.dialog()) {
366                 valid = paths_.input(ob);
367         } else if  (ob->form->fdui == screen_fonts_.dialog()) {
368                 valid = screen_fonts_.input();
369         } else if  (ob->form->fdui == spelloptions_.dialog()) {
370                 valid = spelloptions_.input(ob);
371         }
372
373         return valid ? ButtonPolicy::SMI_VALID : ButtonPolicy::SMI_INVALID;
374 }
375
376
377 void FormPreferences::update()
378 {
379         if (!dialog_.get()) return;
380
381         LyXRC const & rc(controller().rc());
382
383         // read lyxrc entries
384         colors_.update();
385         formats_.update();   // Must be before converters_.update()
386         converters_.update();
387         inputs_misc_.update(rc);
388         interface_.update(rc);
389         language_.update(rc);
390         lnf_misc_.update(rc);
391         identity_.update(rc);
392         outputs_misc_.update(rc);
393         paths_.update(rc);
394         printer_.update(rc);
395         screen_fonts_.update(rc);
396         spelloptions_.update(rc);
397 }
398
399
400 FormPreferences::Colors::Colors(FormPreferences & p)
401         : modifiedXformsPrefs(false), parent_(p)
402 {}
403
404
405 FD_preferences_colors const * FormPreferences::Colors::dialog()
406 {
407         return dialog_.get();
408 }
409
410
411 void FormPreferences::Colors::apply()
412 {
413         bool modifiedText = false;
414         bool modifiedBackground = false;
415
416         for (vector<XformsColor>::const_iterator cit = xformsColorDB.begin();
417              cit != xformsColorDB.end(); ++cit) {
418                 RGBColor col;
419                 fl_getmcolor(cit->colorID, &col.r, &col.g, &col.b);
420                 if (col != cit->color()) {
421                         modifiedXformsPrefs = true;
422                         if (cit->colorID == FL_BLACK)
423                                 modifiedText = true;
424                         if (cit->colorID == FL_COL1)
425                                 modifiedBackground = true;
426                 }
427         }
428
429         if (modifiedXformsPrefs) {
430                 for (vector<XformsColor>::const_iterator cit =
431                              xformsColorDB.begin();
432                      cit != xformsColorDB.end(); ++cit) {
433                         fl_mapcolor(cit->colorID, cit->r, cit->g, cit->b);
434
435                         if (modifiedText && cit->colorID == FL_BLACK) {
436                                 AdjustVal(FL_INACTIVE, FL_BLACK, 0.5);
437                         }
438
439                         if (modifiedBackground && cit->colorID == FL_COL1) {
440                                 AdjustVal(FL_MCOL,      FL_COL1, 0.1);
441                                 AdjustVal(FL_TOP_BCOL,  FL_COL1, 0.1);
442                                 AdjustVal(FL_LEFT_BCOL, FL_COL1, 0.1);
443
444                                 AdjustVal(FL_RIGHT_BCOL,  FL_COL1, -0.5);
445                                 AdjustVal(FL_BOTTOM_BCOL, FL_COL1, -0.5);
446                         }
447
448                         if (cit->colorID == GUI_COLOR_CURSOR) {
449                                 fl_mapcolor(GUI_COLOR_CURSOR,
450                                             cit->r, cit->g, cit->b);
451                                 setCursorColor(GUI_COLOR_CURSOR);
452                         }
453                 }
454                 parent_.controller().redrawGUI();
455         }
456
457         // Now do the same for the LyX LColors...
458         for (vector<NamedColor>::const_iterator cit = lyxColorDB.begin();
459              cit != lyxColorDB.end(); ++cit) {
460                 LColor::color lc = lcolor.getFromLyXName(cit->lyxname);
461                 if (lc == LColor::inherit) continue;
462
463                 // Create a valid X11 name of the form "#rrggbb"
464                 string const hexname = X11hexname(cit->color());
465
466                 if (lcolor.getX11Name(lc) != hexname) {
467                         lyxerr[Debug::GUI]
468                                 << "FormPreferences::Colors::apply: "
469                                 << "resetting LColor " << lcolor.getGUIName(lc)
470                                 << " from \"" << lcolor.getX11Name(lc)
471                                 << "\" to \"" << hexname << "\"."
472                                 << endl;
473
474                         parent_.controller().setColor(lc, hexname);
475                 }
476         }
477 }
478
479
480 void FormPreferences::Colors::build()
481 {
482         picker_.reset(new FormColorpicker);
483         dialog_.reset(build_preferences_colors(&parent_));
484
485         fl_set_object_color(dialog_->button_color,
486                             GUI_COLOR_CHOICE, GUI_COLOR_CHOICE);
487
488         // set up the feedback mechanism
489         setPrehandler(dialog_->browser_lyx_objs);
490         setPrehandler(dialog_->button_color);
491         setPrehandler(dialog_->button_modify);
492 }
493
494
495 string const
496 FormPreferences::Colors::feedback(FL_OBJECT const * const ob) const
497 {
498         if (ob == dialog_->browser_lyx_objs)
499                 return _("LyX objects that can be assigned a color.");
500
501         if (ob == dialog_->button_modify)
502                 return _("Modify the LyX object's color. Note: you must then \"Apply\" the change.");
503
504         return string();
505 }
506
507
508 void FormPreferences::Colors::input(FL_OBJECT const * const ob)
509 {
510         if (ob == dialog_->browser_lyx_objs) {
511                 InputBrowserLyX();
512
513         } else if (ob == dialog_->button_modify) {
514                 Modify();
515         }
516 }
517
518
519 void FormPreferences::Colors::AdjustVal(int colAdjust, int colParent,
520                                         double addVal) const
521 {
522         RGBColor rgb;
523         fl_getmcolor(colParent, &rgb.r, &rgb.g, &rgb.b);
524
525         HSVColor hsv(rgb);
526         hsv.v += addVal;
527         hsv.v = min(1.0, max(0.0, hsv.v));
528
529         rgb = RGBColor(hsv);
530         fl_mapcolor(colAdjust, rgb.r, rgb.g, rgb.b);
531 }
532
533
534 void FormPreferences::Colors::InputBrowserLyX() const
535 {
536         vector<NamedColor>::size_type const selLyX =
537                 fl_get_browser(dialog_->browser_lyx_objs);
538         if (selLyX < 1) return;
539
540         // Is the choice an Xforms color...
541         RGBColor col;
542
543         if (selLyX - 1 < xformsColorDB.size()) {
544                 vector<XformsColor>::size_type const i = selLyX - 1;
545                 col = xformsColorDB[i].color();
546         }
547         // or a LyX Logical color?
548         else {
549                 vector<NamedColor>::size_type const i = selLyX - 1 -
550                         xformsColorDB.size();
551                 col = lyxColorDB[i].color();
552         }
553
554         fl_freeze_form(dialog_->form);
555
556         fl_mapcolor(GUI_COLOR_CHOICE, col.r, col.g, col.b);
557         fl_redraw_object(dialog_->button_color);
558
559         fl_unfreeze_form(dialog_->form);
560 }
561
562
563 void FormPreferences::Colors::LoadBrowserLyX()
564 {
565         if (!dialog_->browser_lyx_objs->visible)
566                 return;
567
568         // First, define the modifiable xforms colors
569         xformsColorDB.clear();
570         XformsColor xcol;
571
572         xcol.lyxname = "GUI background";
573         xcol.guiname = _("GUI background");
574         xcol.colorID = FL_COL1;
575         fl_getmcolor(FL_COL1, &xcol.r, &xcol.g, &xcol.b);
576
577         xformsColorDB.push_back(xcol);
578
579         xcol.lyxname = "GUI text";
580         xcol.guiname = _("GUI text");
581         xcol.colorID = FL_BLACK;
582         fl_getmcolor(FL_BLACK, &xcol.r, &xcol.g, &xcol.b);
583
584         xformsColorDB.push_back(xcol);
585
586         xcol.lyxname = "GUI selection";
587         xcol.guiname = _("GUI selection");
588         xcol.colorID = FL_YELLOW;
589         fl_getmcolor(FL_YELLOW, &xcol.r, &xcol.g, &xcol.b);
590
591         xformsColorDB.push_back(xcol);
592
593         xcol.lyxname = "GUI pointer";
594         xcol.guiname = _("GUI pointer");
595         xcol.colorID = GUI_COLOR_CURSOR;
596         fl_getmcolor(GUI_COLOR_CURSOR, &xcol.r, &xcol.g, &xcol.b);
597
598         xformsColorDB.push_back(xcol);
599
600         // Now create the the LyX LColors database
601         lyxColorDB.clear();
602         for (int i=0; i<LColor::ignore; ++i) {
603                 LColor::color lc = static_cast<LColor::color>(i);
604                 if (lc == LColor::none
605                     || lc == LColor::black
606                     || lc == LColor::white
607                     || lc == LColor::red
608                     || lc == LColor::green
609                     || lc == LColor::blue
610                     || lc == LColor::cyan
611                     || lc == LColor::magenta
612                     || lc == LColor::yellow
613                     || lc == LColor::inherit
614                     || lc == LColor::ignore) continue;
615
616                 RGBColor col;
617                 bool const success = getRGBColor(lc, col.r, col.g, col.b);
618                 if (!success) {
619                         lyxerr << "FormPreferences::Colors::LoadBrowserLyX:\n"
620                                << "LColor " << lcolor.getLyXName(lc)
621                                << ": X can't find color \""
622                                << lcolor.getX11Name(lc)
623                                << "\". Set to \"black\"!" << endl;
624
625                         string const arg = lcolor.getLyXName(lc) + " black";
626                         parent_.controller().setColor(lc, "black");
627                         continue;
628                 }
629
630                 // Create a valid X11 name of the form "#rrggbb" and change the
631                 // LColor X11name to this. Don't want to trigger a redraw,
632                 // as we're just changing the name not the RGB values.
633                 // Also reset the system_lcolor names, so that we don't output
634                 // unnecessary changes.
635                 string const hexname = X11hexname(col);
636
637                 if (lcolor.getX11Name(lc) != hexname) {
638                         lcolor.setColor(lc, hexname);
639                         system_lcolor.setColor(lc, hexname);
640                 }
641
642                 // Finally, push the color onto the database
643                 NamedColor ncol(lcolor.getLyXName(lc), lcolor.getGUIName(lc), col);
644                 lyxColorDB.push_back(ncol);
645         }
646
647         // Now construct the browser
648         FL_OBJECT * colbr = dialog_->browser_lyx_objs;
649         fl_freeze_form(dialog_->form);
650         fl_clear_browser(colbr);
651         for (vector<XformsColor>::const_iterator cit = xformsColorDB.begin();
652              cit != xformsColorDB.end(); ++cit) {
653                 fl_addto_browser(colbr, cit->guiname.c_str());
654         }
655         for (vector<NamedColor>::const_iterator cit = lyxColorDB.begin();
656              cit != lyxColorDB.end(); ++cit) {
657                 fl_addto_browser(colbr, cit->guiname.c_str());
658         }
659
660         // just to be safe...
661         fl_set_browser_topline(dialog_->browser_lyx_objs, 1);
662         fl_select_browser_line(dialog_->browser_lyx_objs, 1);
663         fl_unfreeze_form(dialog_->form);
664
665         InputBrowserLyX();
666 }
667
668
669 void FormPreferences::Colors::Modify()
670 {
671         vector<NamedColor>::size_type const selLyX =
672                 fl_get_browser(dialog_->browser_lyx_objs);
673         if (selLyX < 1)
674                 return;
675
676         RGBColor before;
677         fl_getmcolor(GUI_COLOR_CHOICE, &before.r, &before.g, &before.b);
678
679         RGBColor col = picker_->requestColor(before);
680         if (before == col)
681                 return;
682
683         fl_mapcolor(GUI_COLOR_CHOICE, col.r, col.g, col.b);
684         fl_redraw_object(dialog_->button_color);
685
686         // Is the choice an Xforms color...
687         if (selLyX - 1 < xformsColorDB.size()) {
688                 vector<XformsColor>::size_type const i = selLyX - 1;
689                 xformsColorDB[i].r  = col.r;
690                 xformsColorDB[i].g  = col.g;
691                 xformsColorDB[i].b  = col.b;
692         }
693         // or a LyX Logical color?
694         else {
695                 vector<NamedColor>::size_type const i = selLyX - 1 -
696                         xformsColorDB.size();
697                 lyxColorDB[i].r  = col.r;
698                 lyxColorDB[i].g  = col.g;
699                 lyxColorDB[i].b  = col.b;
700         }
701 }
702
703
704 FormPreferences::Converters::Converters(FormPreferences & p)
705         : parent_(p)
706 {}
707
708
709 FD_preferences_converters const * FormPreferences::Converters::dialog()
710 {
711         return dialog_.get();
712 }
713
714
715 ::Converters & FormPreferences::Converters::converters()
716 {
717         return parent_.controller().converters();
718 }
719
720
721 ::Formats & FormPreferences::Converters::formats()
722 {
723         return parent_.controller().formats();
724 }
725
726
727 void FormPreferences::Converters::build()
728 {
729         dialog_.reset(build_preferences_converters(&parent_));
730
731         fl_set_input_return(dialog_->input_converter, FL_RETURN_CHANGED);
732         fl_set_input_return(dialog_->input_flags, FL_RETURN_CHANGED);
733
734         // set up the feedback mechanism
735         setPrehandler(dialog_->browser_all);
736         setPrehandler(dialog_->button_delete);
737         setPrehandler(dialog_->button_add);
738         setPrehandler(dialog_->input_converter);
739         setPrehandler(dialog_->choice_from);
740         setPrehandler(dialog_->choice_to);
741         setPrehandler(dialog_->input_flags);
742 }
743
744
745 string const
746 FormPreferences::Converters::feedback(FL_OBJECT const * const ob) const
747 {
748         if (ob == dialog_->browser_all)
749                 return _("All explicitly defined converters for LyX");
750
751         if (ob == dialog_->choice_from)
752                 return _("Convert \"from\" this format");
753
754         if (ob == dialog_->choice_to)
755                 return _("Convert \"to\" this format");
756
757         if (ob == dialog_->input_converter)
758                 return _("The conversion command. $$i is the input file name, "
759                          "$$b is the file name without its extension and $$o is "
760                          "the name of the output file. $$s can be used as path to "
761                          "LyX's own collection of conversion scripts.");
762
763         if (ob == dialog_->input_flags)
764                 return _("Extra information for the Converter class, whether and "
765                          "how to parse the result, and various other things.");
766
767         if (ob == dialog_->button_delete)
768                 return _("Remove the current converter from the list of available "
769                          "converters. Note: you must then \"Apply\" the change.");
770
771         if (ob == dialog_->button_add) {
772                 if (string(ob->label) == _("Add"))
773                         return _("Add the current converter to the list of available "
774                                  "converters. Note: you must then \"Apply\" the change.");
775                 else
776                         return _("Modify the contents of the current converter. "
777                                  "Note: you must then \"Apply\" the change.");
778         }
779
780         return string();
781 }
782
783
784 bool FormPreferences::Converters::input(FL_OBJECT const * const ob)
785 {
786         if (ob == dialog_->browser_all)
787                 return Browser();
788
789         if (ob == dialog_->choice_from
790             || ob == dialog_->choice_to
791             || ob == dialog_->input_converter
792             || ob == dialog_->input_flags)
793                 return Input();
794
795         if (ob == dialog_->button_add)
796                 return Add();
797
798         if (ob == dialog_->button_delete)
799                 return erase();
800
801         return true;
802 }
803
804
805 void FormPreferences::Converters::update()
806 {
807         UpdateBrowser();
808 }
809
810
811 void FormPreferences::Converters::UpdateBrowser()
812 {
813         converters().sort();
814
815         fl_freeze_form(dialog_->form);
816         fl_clear_browser(dialog_->browser_all);
817         for (::Converters::const_iterator cit = converters().begin();
818              cit != converters().end(); ++cit) {
819                 string const name = cit->From->prettyname() + " -> "
820                         + cit->To->prettyname();
821                 fl_addto_browser(dialog_->browser_all, name.c_str());
822         }
823         Input();
824         fl_unfreeze_form(dialog_->form);
825 }
826
827
828 bool FormPreferences::Converters::Add()
829 {
830         string const from = GetFrom();
831         string const to = GetTo();
832         string const command = fl_get_input(dialog_->input_converter);
833         string const flags = fl_get_input(dialog_->input_flags);
834
835         Converter const * old = converters().getConverter(from, to);
836         converters().add(from, to, command, flags);
837         if (!old) {
838                 converters().updateLast(formats());
839                 UpdateBrowser();
840         }
841         setEnabled(dialog_->button_add, false);
842
843         return true;
844 }
845
846
847 bool FormPreferences::Converters::Browser()
848 {
849         int const i = fl_get_browser(dialog_->browser_all);
850         if (i <= 0) return false;
851
852         fl_freeze_form(dialog_->form);
853
854         Converter const & c = converters().get(i - 1);
855         int j = formats().getNumber(c.from);
856         if (j >= 0)
857                 fl_set_choice(dialog_->choice_from, j + 1);
858
859         j = formats().getNumber(c.to);
860         if (j >= 0)
861                 fl_set_choice(dialog_->choice_to, j + 1);
862
863         fl_set_input(dialog_->input_converter, c.command.c_str());
864         fl_set_input(dialog_->input_flags, c.flags.c_str());
865
866         fl_set_object_label(dialog_->button_add, idex(_("Modify|#M")).c_str());
867         fl_set_button_shortcut(dialog_->button_add,
868                                scex(_("Modify|#M")).c_str(), 1);
869
870         setEnabled(dialog_->button_add,    false);
871         setEnabled(dialog_->button_delete, true);
872
873         fl_unfreeze_form(dialog_->form);
874         return false;
875 }
876
877
878 bool FormPreferences::Converters::erase()
879 {
880         string const from = GetFrom();
881         string const to = GetTo();
882
883         converters().erase(from, to);
884         UpdateBrowser();
885         return true;
886 }
887
888
889 bool FormPreferences::Converters::Input()
890 {
891         string const from = GetFrom();
892         string const to = GetTo();
893         int const sel = converters().getNumber(from, to);
894
895         fl_freeze_form(dialog_->form);
896
897         if (sel < 0) {
898                 fl_set_object_label(dialog_->button_add,
899                                     idex(_("Add|#A")).c_str());
900                 fl_set_button_shortcut(dialog_->button_add,
901                                        scex(_("Add|#A")).c_str(), 1);
902
903                 fl_deselect_browser(dialog_->browser_all);
904                 setEnabled(dialog_->button_delete, false);
905
906         } else {
907                 fl_set_object_label(dialog_->button_add,
908                                     idex(_("Modify|#M")).c_str());
909                 fl_set_button_shortcut(dialog_->button_add,
910                                        scex(_("Modify|#M")).c_str(), 1);
911
912                 int top = max(sel-5, 0);
913                 fl_set_browser_topline(dialog_->browser_all, top);
914                 fl_select_browser_line(dialog_->browser_all, sel+1);
915                 setEnabled(dialog_->button_delete, true);
916         }
917
918         string const command = rtrim(fl_get_input(dialog_->input_converter));
919         bool const enable = !(command.empty() || from == to);
920         setEnabled(dialog_->button_add, enable);
921
922         fl_unfreeze_form(dialog_->form);
923         return false;
924 }
925
926
927 string const FormPreferences::Converters::GetFrom()
928 {
929         ::Formats::FormatList::size_type const i =
930                   fl_get_choice(dialog_->choice_from);
931
932         if (i > 0 && i <= formats().size())
933                 return formats().get(i - 1).name();
934
935         lyxerr << "FormPreferences::Converters::GetFrom: No choice!" << endl;
936         return "???";
937 }
938
939
940 string const FormPreferences::Converters::GetTo()
941 {
942         ::Formats::FormatList::size_type const i =
943                   fl_get_choice(dialog_->choice_to);
944
945         if (i > 0 && i <= formats().size())
946                 return formats().get(i - 1).name();
947
948         lyxerr << "FormPreferences::Converters::GetTo: No choice!" << endl;
949         return "???";
950 }
951
952
953 void FormPreferences::Converters::UpdateChoices()
954 {
955         string choice;
956         for (::Formats::const_iterator cit = formats().begin();
957              cit != formats().end(); ++cit) {
958                 if (!choice.empty())
959                         choice += " | ";
960                 else
961                         choice += ' ';
962                 choice += cit->prettyname();
963         }
964         choice += ' ';
965
966         fl_clear_choice(dialog_->choice_from);
967         fl_addto_choice(dialog_->choice_from, choice.c_str());
968
969         fl_clear_choice(dialog_->choice_to);
970         fl_addto_choice(dialog_->choice_to, choice.c_str());
971 }
972
973
974 FormPreferences::Formats::Formats(FormPreferences &  p)
975         : parent_(p)
976 {}
977
978
979 FD_preferences_formats const * FormPreferences::Formats::dialog()
980 {
981         return dialog_.get();
982 }
983
984
985 ::Converters & FormPreferences::Formats::converters()
986 {
987         return parent_.controller().converters();
988 }
989
990
991 ::Formats & FormPreferences::Formats::formats()
992 {
993         return parent_.controller().formats();
994 }
995
996
997 void FormPreferences::Formats::build()
998 {
999         dialog_.reset(build_preferences_formats(&parent_));
1000
1001         fl_set_input_return(dialog_->input_format, FL_RETURN_CHANGED);
1002         fl_set_input_return(dialog_->input_viewer, FL_RETURN_CHANGED);
1003         fl_set_input_return(dialog_->input_editor, FL_RETURN_CHANGED);
1004         fl_set_input_return(dialog_->input_shrtcut, FL_RETURN_CHANGED);
1005         fl_set_input_return(dialog_->input_gui_name, FL_RETURN_CHANGED);
1006         fl_set_input_return(dialog_->input_extension, FL_RETURN_CHANGED);
1007
1008         fl_set_input_filter(dialog_->input_format, fl_lowercase_filter);
1009
1010         // set up the feedback mechanism
1011         setPrehandler(dialog_->browser_all);
1012         setPrehandler(dialog_->input_format);
1013         setPrehandler(dialog_->input_gui_name);
1014         setPrehandler(dialog_->button_delete);
1015         setPrehandler(dialog_->button_add);
1016         setPrehandler(dialog_->input_extension);
1017         setPrehandler(dialog_->input_viewer);
1018         setPrehandler(dialog_->input_editor);
1019         setPrehandler(dialog_->input_shrtcut);
1020 }
1021
1022
1023 string const
1024 FormPreferences::Formats::feedback(FL_OBJECT const * const ob) const
1025 {
1026         if (ob == dialog_->browser_all)
1027                 return  _("All the currently defined formats known to LyX.");
1028
1029         if (ob == dialog_->input_format)
1030                 return  _("The format identifier.");
1031
1032         if (ob == dialog_->input_gui_name)
1033                 return  _("The format name as it will appear in the menus.");
1034
1035         if (ob == dialog_->input_shrtcut)
1036                 return  _("The keyboard accelerator. Use a letter in the GUI name. "
1037                           "Case sensitive.");
1038
1039         if (ob == dialog_->input_extension)
1040                 return  _("Used to recognize the file. E.g., ps, pdf, tex.");
1041
1042         if (ob == dialog_->input_viewer)
1043                 return  _("The command used to launch the viewer application.");
1044
1045         if (ob == dialog_->input_editor)
1046                 return  _("The command used to launch the editor application.");
1047
1048         if (ob == dialog_->button_delete)
1049                 return  _("Remove the current format from the list of available "
1050                           "formats. Note: you must then \"Apply\" the change.");
1051
1052         if (ob == dialog_->button_add) {
1053                 if (string(ob->label) == _("Add"))
1054                         return  _("Add the current format to the list of available "
1055                                   "formats. Note: you must then \"Apply\" the change.");
1056                 else
1057                         return  _("Modify the contents of the current format. Note: "
1058                                   "you must then \"Apply\" the change.");
1059         }
1060
1061         return string();
1062 }
1063
1064
1065 bool FormPreferences::Formats::input(FL_OBJECT const * const ob)
1066 {
1067         if (ob == dialog_->browser_all)
1068                 return Browser();
1069
1070         if (ob == dialog_->input_format
1071             || ob == dialog_->input_gui_name
1072             || ob == dialog_->input_shrtcut
1073             || ob == dialog_->input_extension
1074             || ob == dialog_->input_viewer
1075             || ob == dialog_->input_editor)
1076                 return Input();
1077
1078         if (ob == dialog_->button_add)
1079                 return Add();
1080
1081         if (ob == dialog_->button_delete)
1082                 return erase();
1083
1084         return false;
1085 }
1086
1087
1088 void FormPreferences::Formats::update()
1089 {
1090         UpdateBrowser();
1091 }
1092
1093
1094 void FormPreferences::Formats::UpdateBrowser()
1095 {
1096         formats().sort();
1097
1098         fl_freeze_form(dialog_->form);
1099         fl_deselect_browser(dialog_->browser_all);
1100         fl_clear_browser(dialog_->browser_all);
1101         for (::Formats::const_iterator cit = formats().begin();
1102              cit != formats().end(); ++cit)
1103                 fl_addto_browser(dialog_->browser_all,
1104                                  cit->prettyname().c_str());
1105
1106         Input();
1107         fl_unfreeze_form(dialog_->form);
1108
1109         // Mustn't forget to update the Formats available to the converters_
1110         parent_.converters_.UpdateChoices();
1111         converters().update(formats());
1112 }
1113
1114
1115 bool FormPreferences::Formats::Add()
1116 {
1117         string const name = fl_get_input(dialog_->input_format);
1118         string const prettyname = fl_get_input(dialog_->input_gui_name);
1119         string const extension = fl_get_input(dialog_->input_extension);
1120         string const shortcut =  fl_get_input(dialog_->input_shrtcut);
1121         string const viewer =  fl_get_input(dialog_->input_viewer);
1122         string const editor =  fl_get_input(dialog_->input_editor);
1123
1124         Format const * old = formats().getFormat(name);
1125         string const old_prettyname = old ? old->prettyname() : string();
1126         formats().add(name, extension, prettyname, shortcut, viewer, editor);
1127         if (!old || prettyname != old_prettyname) {
1128                 UpdateBrowser();
1129                 if (old)
1130                         parent_.converters_.UpdateBrowser();
1131         }
1132         setEnabled(dialog_->button_add, false);
1133
1134         return true;
1135 }
1136
1137
1138 bool FormPreferences::Formats::Browser()
1139 {
1140         int const i = fl_get_browser(dialog_->browser_all);
1141         if (i <= 0)
1142                 return false;
1143
1144         fl_freeze_form(dialog_->form);
1145
1146         Format const & f = formats().get(i - 1);
1147
1148         fl_set_input(dialog_->input_format, f.name().c_str());
1149         fl_set_input(dialog_->input_gui_name, f.prettyname().c_str());
1150         fl_set_input(dialog_->input_shrtcut, f.shortcut().c_str());
1151         fl_set_input(dialog_->input_extension, f.extension().c_str());
1152         fl_set_input(dialog_->input_viewer, f.viewer().c_str());
1153         fl_set_input(dialog_->input_editor, f.editor().c_str());
1154
1155         fl_set_object_label(dialog_->button_add,
1156                             idex(_("Modify|#M")).c_str());
1157         fl_set_button_shortcut(dialog_->button_add,
1158                                scex(_("Modify|#M")).c_str(), 1);
1159
1160         setEnabled(dialog_->button_add,    false);
1161         setEnabled(dialog_->button_delete, true);
1162
1163         fl_unfreeze_form(dialog_->form);
1164         return false;
1165 }
1166
1167
1168 bool FormPreferences::Formats::erase()
1169 {
1170         string const name = fl_get_input(dialog_->input_format);
1171
1172         if (converters().formatIsUsed(name)) {
1173                 parent_.postWarning(_("Cannot remove a Format used by a Converter. "
1174                                       "Remove the converter first."));
1175                 setEnabled(dialog_->button_delete, false);
1176                 return false;
1177         }
1178
1179         formats().erase(name);
1180         UpdateBrowser();
1181         return true;
1182 }
1183
1184
1185 bool FormPreferences::Formats::Input()
1186 {
1187         string const name = fl_get_input(dialog_->input_format);
1188         int const sel = formats().getNumber(name);
1189         fl_freeze_form(dialog_->form);
1190
1191         if (sel < 0) {
1192                 fl_set_object_label(dialog_->button_add,
1193                                     idex(_("Add|#A")).c_str());
1194                 fl_set_button_shortcut(dialog_->button_add,
1195                                        scex(_("Add|#A")).c_str(), 1);
1196
1197                 fl_deselect_browser(dialog_->browser_all);
1198                 setEnabled(dialog_->button_delete, false);
1199
1200         } else {
1201                 fl_set_object_label(dialog_->button_add,
1202                                     idex(_("Modify|#M")).c_str());
1203                 fl_set_button_shortcut(dialog_->button_add,
1204                                        scex(_("Modify|#M")).c_str(), 1);
1205
1206                 int const top = max(sel-5, 0);
1207                 fl_set_browser_topline(dialog_->browser_all, top);
1208                 fl_select_browser_line(dialog_->browser_all, sel+1);
1209
1210                 setEnabled(dialog_->button_add, true);
1211                 setEnabled(dialog_->button_delete, true);
1212         }
1213
1214         string const prettyname = fl_get_input(dialog_->input_gui_name);
1215         bool const enable = !(name.empty() || prettyname.empty());
1216         setEnabled(dialog_->button_add, enable);
1217
1218         fl_unfreeze_form(dialog_->form);
1219         return false;
1220 }
1221
1222
1223 FormPreferences::Identity::Identity(FormPreferences & p)
1224         : parent_(p)
1225 {}
1226
1227
1228 FD_preferences_identity const * FormPreferences::Identity::dialog()
1229 {
1230         return dialog_.get();
1231 }
1232
1233
1234 void FormPreferences::Identity::apply(LyXRC & rc) const
1235 {
1236         rc.user_name = fl_get_input(dialog_->input_user_name);
1237         rc.user_email = fl_get_input(dialog_->input_user_email);
1238 }
1239
1240
1241 void FormPreferences::Identity::build()
1242 {
1243         dialog_.reset(build_preferences_identity(&parent_));
1244         fl_set_input_return(dialog_->input_user_name, FL_RETURN_CHANGED);
1245         fl_set_input_return(dialog_->input_user_email, FL_RETURN_CHANGED);
1246 }
1247
1248
1249 void FormPreferences::Identity::update(LyXRC const & rc)
1250 {
1251         fl_set_input(dialog_->input_user_name, rc.user_name.c_str());
1252         fl_set_input(dialog_->input_user_email, rc.user_email.c_str());
1253 }
1254
1255
1256 FormPreferences::InputsMisc::InputsMisc(FormPreferences &  p)
1257         : parent_(p)
1258 {}
1259
1260
1261 FD_preferences_inputs_misc const * FormPreferences::InputsMisc::dialog()
1262 {
1263         return dialog_.get();
1264 }
1265
1266
1267 void FormPreferences::InputsMisc::apply(LyXRC & rc) const
1268 {
1269         rc.date_insert_format =
1270                 fl_get_input(dialog_->input_date_format);
1271 }
1272
1273
1274 void FormPreferences::InputsMisc::build()
1275 {
1276         dialog_.reset(build_preferences_inputs_misc(&parent_));
1277
1278         fl_set_input_return(dialog_->input_date_format, FL_RETURN_CHANGED);
1279
1280         // set up the feedback mechanism
1281         setPrehandler(dialog_->input_date_format);
1282 }
1283
1284
1285 string const
1286 FormPreferences::InputsMisc::feedback(FL_OBJECT const * const ob) const
1287 {
1288         if (ob == dialog_->input_date_format)
1289                 return LyXRC::getDescription(LyXRC::RC_DATE_INSERT_FORMAT);
1290         return string();
1291 }
1292
1293
1294 void FormPreferences::InputsMisc::update(LyXRC const & rc)
1295 {
1296         fl_set_input(dialog_->input_date_format,
1297                      rc.date_insert_format.c_str());
1298 }
1299
1300
1301 FormPreferences::Interface::Interface(FormPreferences &  p)
1302         : parent_(p)
1303 {}
1304
1305
1306 FD_preferences_interface const * FormPreferences::Interface::dialog()
1307 {
1308         return dialog_.get();
1309 }
1310
1311
1312 void FormPreferences::Interface::apply(LyXRC & rc) const
1313 {
1314         rc.popup_normal_font =
1315                 fl_get_input(dialog_->input_popup_normal_font);
1316         rc.popup_bold_font = fl_get_input(dialog_->input_popup_bold_font);
1317         rc.popup_font_encoding =
1318                 fl_get_input(dialog_->input_popup_font_encoding);
1319         rc.bind_file = fl_get_input(dialog_->input_bind_file);
1320         rc.ui_file = fl_get_input(dialog_->input_ui_file);
1321 }
1322
1323
1324 void FormPreferences::Interface::build()
1325 {
1326         dialog_.reset(build_preferences_interface(&parent_));
1327
1328         fl_set_input_return(dialog_->input_popup_normal_font, FL_RETURN_CHANGED);
1329         fl_set_input_return(dialog_->input_popup_bold_font, FL_RETURN_CHANGED);
1330         fl_set_input_return(dialog_->input_popup_font_encoding, FL_RETURN_CHANGED);
1331         fl_set_input_return(dialog_->input_bind_file, FL_RETURN_CHANGED);
1332         fl_set_input_return(dialog_->input_ui_file, FL_RETURN_CHANGED);
1333
1334         // set up the feedback mechanism
1335         setPrehandler(dialog_->input_popup_normal_font);
1336         setPrehandler(dialog_->input_popup_bold_font);
1337         setPrehandler(dialog_->input_popup_font_encoding);
1338         setPrehandler(dialog_->input_bind_file);
1339         setPrehandler(dialog_->button_bind_file_browse);
1340         setPrehandler(dialog_->input_ui_file);
1341         setPrehandler(dialog_->button_ui_file_browse);
1342 }
1343
1344
1345 string const
1346 FormPreferences::Interface::feedback(FL_OBJECT const * const ob) const
1347 {
1348         if (ob == dialog_->input_popup_normal_font)
1349                 return LyXRC::getDescription(LyXRC::RC_POPUP_NORMAL_FONT);
1350         if (ob == dialog_->input_popup_bold_font)
1351                 return LyXRC::getDescription(LyXRC::RC_POPUP_BOLD_FONT);
1352         if (ob == dialog_->input_popup_font_encoding)
1353                 return LyXRC::getDescription(LyXRC::RC_POPUP_FONT_ENCODING);
1354         if (ob == dialog_->input_bind_file)
1355                 return LyXRC::getDescription(LyXRC::RC_BINDFILE);
1356         if (ob == dialog_->input_ui_file)
1357                 return LyXRC::getDescription(LyXRC::RC_UIFILE);
1358         return string();
1359 }
1360
1361
1362 bool FormPreferences::Interface::input(FL_OBJECT const * const ob)
1363 {
1364         if (ob == dialog_->button_bind_file_browse) {
1365                 string f = parent_.controller().browsebind(
1366                         fl_get_input(dialog_->input_bind_file));
1367
1368                 fl_set_input(dialog_->input_bind_file, f.c_str());
1369         } else if (ob == dialog_->button_ui_file_browse) {
1370                 string f = parent_.controller().browseUI(
1371                         fl_get_input(dialog_->input_ui_file));
1372
1373                 fl_set_input(dialog_->input_ui_file, f.c_str());
1374         }
1375
1376         return true;
1377 }
1378
1379
1380 void FormPreferences::Interface::update(LyXRC const & rc)
1381 {
1382         fl_set_input(dialog_->input_popup_normal_font,
1383                      rc.popup_normal_font.c_str());
1384         fl_set_input(dialog_->input_popup_bold_font,
1385                      rc.popup_bold_font.c_str());
1386         fl_set_input(dialog_->input_popup_font_encoding,
1387                      rc.popup_font_encoding.c_str());
1388         fl_set_input(dialog_->input_bind_file,
1389                      rc.bind_file.c_str());
1390         fl_set_input(dialog_->input_ui_file,
1391                      rc.ui_file.c_str());
1392 }
1393
1394
1395 FormPreferences::Language::Language(FormPreferences &  p)
1396         : parent_(p)
1397 {}
1398
1399
1400 FD_preferences_language const * FormPreferences::Language::dialog()
1401 {
1402         return dialog_.get();
1403 }
1404
1405
1406 void FormPreferences::Language::apply(LyXRC & rc)
1407 {
1408         int const pos = fl_get_combox(dialog_->combox_default_lang);
1409         rc.default_language = lang_[pos-1];
1410
1411         int button = fl_get_button(dialog_->check_use_kbmap);
1412         string const name_1 = fl_get_input(dialog_->input_kbmap1);
1413         string const name_2 = fl_get_input(dialog_->input_kbmap2);
1414         if (button)
1415                 button = !(name_1.empty() && name_2.empty());
1416         rc.use_kbmap = static_cast<bool>(button);
1417
1418         if (rc.use_kbmap) {
1419                 rc.primary_kbmap = name_1;
1420                 rc.secondary_kbmap = name_2;
1421         }
1422
1423         button = fl_get_button(dialog_->check_rtl_support);
1424         rc.rtl_support = static_cast<bool>(button);
1425
1426         button = fl_get_button(dialog_->check_mark_foreign);
1427         rc.mark_foreign_language = static_cast<bool>(button);
1428
1429         button = fl_get_button(dialog_->check_auto_begin);
1430         rc.language_auto_begin = static_cast<bool>(button);
1431
1432         button = fl_get_button(dialog_->check_auto_end);
1433         rc.language_auto_end = static_cast<bool>(button);
1434
1435         button = fl_get_button(dialog_->check_use_babel);
1436         rc.language_use_babel = static_cast<bool>(button);
1437
1438         button = fl_get_button(dialog_->check_global_options);
1439         rc.language_global_options = static_cast<bool>(button);
1440
1441         rc.language_package = fl_get_input(dialog_->input_package);
1442         rc.language_command_begin = fl_get_input(dialog_->input_command_begin);
1443         rc.language_command_end = fl_get_input(dialog_->input_command_end);
1444
1445         // Ensure that all is self-consistent.
1446         update(rc);
1447 }
1448
1449
1450 void FormPreferences::Language::build()
1451 {
1452         dialog_.reset(build_preferences_language(&parent_));
1453
1454         fl_set_input_return(dialog_->input_package, FL_RETURN_CHANGED);
1455         fl_set_input_return(dialog_->input_command_begin, FL_RETURN_CHANGED);
1456         fl_set_input_return(dialog_->input_command_end, FL_RETURN_CHANGED);
1457
1458         // Store the lang identifiers for later
1459         vector<LanguagePair> const langs = getLanguageData(false);
1460         lang_ = getSecond(langs);
1461
1462         FL_OBJECT * obj = dialog_->combox_default_lang;
1463         vector<LanguagePair>::const_iterator lit  = langs.begin();
1464         vector<LanguagePair>::const_iterator lend = langs.end();
1465         for (; lit != lend; ++lit) {
1466                 fl_addto_combox(obj, lit->first.c_str());
1467         }
1468         fl_set_combox_browser_height(obj, 400);
1469
1470         // set up the feedback mechanism
1471         setPrehandler(dialog_->input_package);
1472         setPrehandler(dialog_->check_use_kbmap);
1473         setPrehandler(dialog_->combox_default_lang);
1474         setPrehandler(dialog_->input_kbmap1);
1475         setPrehandler(dialog_->input_kbmap2);
1476         setPrehandler(dialog_->check_rtl_support);
1477         setPrehandler(dialog_->check_mark_foreign);
1478         setPrehandler(dialog_->check_auto_begin);
1479         setPrehandler(dialog_->check_auto_end);
1480         setPrehandler(dialog_->check_use_babel);
1481         setPrehandler(dialog_->check_global_options);
1482         setPrehandler(dialog_->input_command_begin);
1483         setPrehandler(dialog_->input_command_end);
1484
1485         // Activate/Deactivate the input fields dependent on the state of the
1486         // buttons.
1487         input(0);
1488 }
1489
1490
1491 string const
1492 FormPreferences::Language::feedback(FL_OBJECT const * const ob) const
1493 {
1494         if (ob == dialog_->combox_default_lang)
1495                 return LyXRC::getDescription(LyXRC::RC_DEFAULT_LANGUAGE);
1496         if (ob == dialog_->check_use_kbmap)
1497                 return LyXRC::getDescription(LyXRC::RC_KBMAP);
1498         if (ob == dialog_->input_kbmap1)
1499                 return LyXRC::getDescription(LyXRC::RC_KBMAP_PRIMARY);
1500         if (ob == dialog_->input_kbmap2)
1501                 return LyXRC::getDescription(LyXRC::RC_KBMAP_SECONDARY);
1502         if (ob == dialog_->check_rtl_support)
1503                 return LyXRC::getDescription(LyXRC::RC_RTL_SUPPORT);
1504         if (ob == dialog_->check_mark_foreign)
1505                 return LyXRC::getDescription(LyXRC::RC_MARK_FOREIGN_LANGUAGE);
1506         if (ob == dialog_->check_auto_begin)
1507                 return LyXRC::getDescription(LyXRC::RC_LANGUAGE_AUTO_BEGIN);
1508         if (ob == dialog_->check_auto_end)
1509                 return LyXRC::getDescription(LyXRC::RC_LANGUAGE_AUTO_END);
1510         if (ob == dialog_->check_use_babel)
1511                 return LyXRC::getDescription(LyXRC::RC_LANGUAGE_USE_BABEL);
1512         if (ob == dialog_->check_global_options)
1513                 return LyXRC::getDescription(LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS);
1514         if (ob == dialog_->input_package)
1515                 return LyXRC::getDescription(LyXRC::RC_LANGUAGE_PACKAGE);
1516         if (ob == dialog_->input_command_begin)
1517                 return LyXRC::getDescription(LyXRC::RC_LANGUAGE_COMMAND_BEGIN);
1518         if (ob == dialog_->input_command_end)
1519                 return LyXRC::getDescription(LyXRC::RC_LANGUAGE_COMMAND_END);
1520         return string();
1521 }
1522
1523
1524 bool FormPreferences::Language::input(FL_OBJECT const * const ob)
1525 {
1526         bool activate = true;
1527
1528         // !ob if function is called from Language::build() to de/activate
1529         // objects,
1530         // otherwise the function is called by an xforms CB via input().
1531         if (!ob || ob == dialog_->check_use_kbmap) {
1532                 bool const enable = fl_get_button(dialog_->check_use_kbmap);
1533                 setEnabled(dialog_->button_kbmap1_browse, enable);
1534                 setEnabled(dialog_->button_kbmap2_browse, enable);
1535                 setEnabled(dialog_->input_kbmap1, enable);
1536                 setEnabled(dialog_->input_kbmap2, enable);
1537         }
1538
1539         if (ob == dialog_->button_kbmap1_browse) {
1540                 string f = parent_.controller().browsekbmap(
1541                         fl_get_input(dialog_->input_kbmap1));
1542
1543                 fl_set_input(dialog_->input_kbmap1, f.c_str());
1544         } else if (ob == dialog_->button_kbmap2_browse) {
1545                 string f = parent_.controller().browsekbmap(
1546                         fl_get_input(dialog_->input_kbmap2));
1547
1548                 fl_set_input(dialog_->input_kbmap2, f.c_str());
1549         }
1550
1551         return activate;
1552 }
1553
1554
1555 void FormPreferences::Language::update(LyXRC const & rc)
1556 {
1557         fl_set_button(dialog_->check_use_kbmap,
1558                       rc.use_kbmap);
1559
1560         int const pos = int(findPos(lang_, rc.default_language));
1561         fl_set_combox(dialog_->combox_default_lang, pos + 1);
1562
1563         if (rc.use_kbmap) {
1564                 fl_set_input(dialog_->input_kbmap1,
1565                              rc.primary_kbmap.c_str());
1566                 fl_set_input(dialog_->input_kbmap2,
1567                              rc.secondary_kbmap.c_str());
1568         } else {
1569                 fl_set_input(dialog_->input_kbmap1, "");
1570                 fl_set_input(dialog_->input_kbmap2, "");
1571         }
1572
1573         fl_set_button(dialog_->check_rtl_support, rc.rtl_support);
1574         fl_set_button(dialog_->check_mark_foreign,
1575                       rc.mark_foreign_language);
1576         fl_set_button(dialog_->check_auto_begin, rc.language_auto_begin);
1577         fl_set_button(dialog_->check_auto_end, rc.language_auto_end);
1578         fl_set_button(dialog_->check_use_babel, rc.language_use_babel);
1579         fl_set_button(dialog_->check_global_options,
1580                       rc.language_global_options);
1581
1582         fl_set_input(dialog_->input_package,
1583                      rc.language_package.c_str());
1584         fl_set_input(dialog_->input_command_begin,
1585                      rc.language_command_begin.c_str());
1586         fl_set_input(dialog_->input_command_end,
1587                      rc.language_command_end.c_str());
1588
1589         // Activate/Deactivate the input fields dependent on the state of the
1590         // buttons.
1591         input(0);
1592 }
1593
1594
1595 FormPreferences::LnFmisc::LnFmisc(FormPreferences &  p)
1596         : parent_(p)
1597 {}
1598
1599
1600 FD_preferences_lnf_misc const * FormPreferences::LnFmisc::dialog()
1601 {
1602         return dialog_.get();
1603 }
1604
1605
1606 void FormPreferences::LnFmisc::apply(LyXRC & rc) const
1607 {
1608         rc.auto_region_delete =
1609                 fl_get_button(dialog_->check_auto_region_delete);
1610         rc.cursor_follows_scrollbar =
1611                 fl_get_button(dialog_->check_cursor_follows_scrollbar);
1612         rc.dialogs_iconify_with_main =
1613                 fl_get_button(dialog_->check_dialogs_iconify_with_main);
1614
1615         switch (fl_get_choice(dialog_->choice_instant_preview)) {
1616         case 1:
1617                 rc.preview = LyXRC::PREVIEW_OFF;
1618                 break;
1619         case 2:
1620                 rc.preview = LyXRC::PREVIEW_NO_MATH;
1621                 break;
1622         case 3:
1623                 rc.preview = LyXRC::PREVIEW_ON;
1624                 break;
1625         }
1626
1627         rc.autosave = static_cast<unsigned int>
1628                 (fl_get_counter_value(dialog_->counter_autosave));
1629         rc.wheel_jump = static_cast<unsigned int>
1630                 (fl_get_counter_value(dialog_->counter_wm_jump));
1631
1632         // See FIXME below
1633         // graphics::DisplayType old_value = rc.display_graphics;
1634         switch (fl_get_choice(dialog_->choice_graphics_display)) {
1635         case 4:
1636                 rc.display_graphics = graphics::NoDisplay;
1637                 break;
1638         case 3:
1639                 rc.display_graphics = graphics::ColorDisplay;
1640                 break;
1641         case 2:
1642                 rc.display_graphics = graphics::GrayscaleDisplay;
1643                 break;
1644         case 1:
1645                 rc.display_graphics = graphics::MonochromeDisplay;
1646                 break;
1647         default:
1648                 rc.display_graphics = graphics::ColorDisplay;
1649                 break;
1650         }
1651
1652 #ifdef WITH_WARNINGS
1653 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
1654 #endif
1655 #if 0
1656         if (old_value != rc.display_graphics) {
1657                 graphics::GCache & gc = graphics::GCache::get();
1658                 gc.changeDisplay();
1659         }
1660 #endif
1661 }
1662
1663
1664 void FormPreferences::LnFmisc::build()
1665 {
1666         dialog_.reset(build_preferences_lnf_misc(&parent_));
1667
1668         fl_set_counter_step(dialog_->counter_autosave, 1, 10);
1669         fl_set_counter_step(dialog_->counter_wm_jump, 1, 10);
1670
1671         fl_set_counter_return(dialog_->counter_autosave, FL_RETURN_CHANGED);
1672         fl_set_counter_return(dialog_->counter_wm_jump, FL_RETURN_CHANGED);
1673
1674         // set up the feedback mechanism
1675         setPrehandler(dialog_->check_auto_region_delete);
1676         setPrehandler(dialog_->counter_autosave);
1677         setPrehandler(dialog_->check_cursor_follows_scrollbar);
1678         setPrehandler(dialog_->check_dialogs_iconify_with_main);
1679         setPrehandler(dialog_->choice_instant_preview);
1680         setPrehandler(dialog_->counter_wm_jump);
1681
1682         fl_addto_choice(dialog_->choice_graphics_display,
1683                         _("Monochrome|Grayscale|Color|Do not display").c_str());
1684
1685         fl_addto_choice(dialog_->choice_instant_preview,
1686                         _("Off|No math|On").c_str());
1687 }
1688
1689
1690 string const
1691 FormPreferences::LnFmisc::feedback(FL_OBJECT const * const ob) const
1692 {
1693         if (ob == dialog_->check_auto_region_delete)
1694                 return LyXRC::getDescription(LyXRC::RC_AUTOREGIONDELETE);
1695         if (ob == dialog_->check_cursor_follows_scrollbar)
1696                 return LyXRC::getDescription(LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR);
1697         if (ob == dialog_->check_dialogs_iconify_with_main)
1698                 return LyXRC::getDescription(LyXRC::RC_DIALOGS_ICONIFY_WITH_MAIN);
1699         if (ob == dialog_->choice_instant_preview)
1700                 return LyXRC::getDescription(LyXRC::RC_PREVIEW);
1701         if (ob == dialog_->counter_autosave)
1702                 return LyXRC::getDescription(LyXRC::RC_AUTOSAVE);
1703         if (ob == dialog_->counter_wm_jump)
1704                 return LyXRC::getDescription(LyXRC::RC_WHEEL_JUMP);
1705         if (ob == dialog_->choice_graphics_display)
1706                 return LyXRC::getDescription(LyXRC::RC_DISPLAY_GRAPHICS);
1707         return string();
1708 }
1709
1710
1711 void FormPreferences::LnFmisc::update(LyXRC const & rc)
1712 {
1713         fl_set_button(dialog_->check_auto_region_delete,
1714                       rc.auto_region_delete);
1715         fl_set_button(dialog_->check_cursor_follows_scrollbar,
1716                       rc.cursor_follows_scrollbar);
1717         fl_set_button(dialog_->check_dialogs_iconify_with_main,
1718                       rc.dialogs_iconify_with_main);
1719
1720         switch (rc.preview) {
1721         case LyXRC::PREVIEW_OFF:
1722                 fl_set_choice(dialog_->choice_instant_preview, 1);
1723                 break;
1724         case LyXRC::PREVIEW_NO_MATH:
1725                 fl_set_choice(dialog_->choice_instant_preview, 2);
1726                 break;
1727         case LyXRC::PREVIEW_ON:
1728                 fl_set_choice(dialog_->choice_instant_preview, 3);
1729                 break;
1730         }
1731
1732         fl_set_counter_value(dialog_->counter_autosave, rc.autosave);
1733         fl_set_counter_value(dialog_->counter_wm_jump, rc.wheel_jump);
1734
1735         switch (rc.display_graphics) {
1736         case graphics::NoDisplay:
1737                 fl_set_choice(dialog_->choice_graphics_display, 4);
1738                 break;
1739         case graphics::ColorDisplay:
1740                 fl_set_choice(dialog_->choice_graphics_display, 3);
1741                 break;
1742         case graphics::GrayscaleDisplay:
1743                 fl_set_choice(dialog_->choice_graphics_display, 2);
1744                 break;
1745         case graphics::MonochromeDisplay:
1746                 fl_set_choice(dialog_->choice_graphics_display, 1);
1747                 break;
1748         default:
1749                 fl_set_choice(dialog_->choice_graphics_display, 3);
1750                 break;
1751         }
1752 }
1753
1754
1755 FormPreferences::OutputsMisc::OutputsMisc(FormPreferences &  p)
1756         : parent_(p)
1757 {}
1758
1759
1760 FD_preferences_outputs_misc const * FormPreferences::OutputsMisc::dialog()
1761 {
1762         return dialog_.get();
1763 }
1764
1765
1766 void FormPreferences::OutputsMisc::apply(LyXRC & rc) const
1767 {
1768         rc.ascii_linelen = static_cast<unsigned int>
1769                 (fl_get_counter_value(dialog_->counter_line_len));
1770         rc.fontenc = fl_get_input(dialog_->input_tex_encoding);
1771
1772         int const choice =
1773                 fl_get_choice(dialog_->choice_default_papersize) - 1;
1774         rc.default_papersize = static_cast<PAPER_SIZE>(choice);
1775
1776         rc.ascii_roff_command = fl_get_input(dialog_->input_ascii_roff);
1777         rc.chktex_command = fl_get_input(dialog_->input_checktex);
1778         rc.bibtex_command = fl_get_input(dialog_->input_bibtex);
1779         rc.index_command = fl_get_input(dialog_->input_index);
1780         rc.view_dvi_paper_option = fl_get_input(dialog_->input_paperoption);
1781         rc.auto_reset_options = fl_get_button(dialog_->check_autoreset_classopt);
1782 }
1783
1784
1785 void FormPreferences::OutputsMisc::build()
1786 {
1787         dialog_.reset(build_preferences_outputs_misc(&parent_));
1788
1789         fl_set_counter_step(dialog_->counter_line_len, 1, 10);
1790
1791         fl_set_counter_return(dialog_->counter_line_len, FL_RETURN_CHANGED);
1792         fl_set_input_return(dialog_->input_tex_encoding, FL_RETURN_CHANGED);
1793         fl_set_input_return(dialog_->input_ascii_roff,   FL_RETURN_CHANGED);
1794         fl_set_input_return(dialog_->input_bibtex,       FL_RETURN_CHANGED);
1795         fl_set_input_return(dialog_->input_checktex,     FL_RETURN_CHANGED);
1796         fl_set_input_return(dialog_->input_index,        FL_RETURN_CHANGED);
1797         fl_set_input_return(dialog_->input_paperoption,  FL_RETURN_CHANGED);
1798
1799         fl_addto_choice(dialog_->choice_default_papersize,
1800                         _(" default | US letter | US legal "
1801                           "| US executive | A3 | A4 | A5 | B5 ").c_str());
1802
1803         // set up the feedback mechanism
1804         setPrehandler(dialog_->counter_line_len);
1805         setPrehandler(dialog_->input_tex_encoding);
1806         setPrehandler(dialog_->choice_default_papersize);
1807         setPrehandler(dialog_->input_ascii_roff);
1808         setPrehandler(dialog_->input_bibtex);
1809         setPrehandler(dialog_->input_checktex);
1810         setPrehandler(dialog_->input_index);
1811         setPrehandler(dialog_->input_paperoption);
1812         setPrehandler(dialog_->check_autoreset_classopt);
1813 }
1814
1815
1816 string const
1817 FormPreferences::OutputsMisc::feedback(FL_OBJECT const * const ob) const
1818 {
1819         if (ob == dialog_->counter_line_len)
1820                 return LyXRC::getDescription(LyXRC::RC_ASCII_LINELEN);
1821         if (ob == dialog_->input_tex_encoding)
1822                 return LyXRC::getDescription(LyXRC::RC_FONT_ENCODING);
1823         if (ob == dialog_->input_ascii_roff)
1824                 return LyXRC::getDescription(LyXRC::RC_ASCIIROFF_COMMAND);
1825         if (ob == dialog_->input_bibtex)
1826                 return LyXRC::getDescription(LyXRC::RC_BIBTEX_COMMAND);
1827         if (ob == dialog_->input_checktex)
1828                 return LyXRC::getDescription(LyXRC::RC_CHKTEX_COMMAND);
1829         if (ob == dialog_->input_index)
1830                 return LyXRC::getDescription(LyXRC::RC_INDEX_COMMAND);
1831         if (ob == dialog_->choice_default_papersize)
1832                 return LyXRC::getDescription(LyXRC::RC_DEFAULT_PAPERSIZE);
1833         if (ob == dialog_->input_paperoption)
1834                 return LyXRC::getDescription(LyXRC::RC_VIEWDVI_PAPEROPTION);
1835         if (ob == dialog_->check_autoreset_classopt)
1836                 return LyXRC::getDescription(LyXRC::RC_AUTORESET_OPTIONS);
1837         return string();
1838 }
1839
1840
1841 void FormPreferences::OutputsMisc::update(LyXRC const & rc)
1842 {
1843         fl_set_counter_value(dialog_->counter_line_len,
1844                              rc.ascii_linelen);
1845         fl_set_input(dialog_->input_tex_encoding,
1846                      rc.fontenc.c_str());
1847         fl_set_choice(dialog_->choice_default_papersize,
1848                       rc.default_papersize + 1);
1849         fl_set_input(dialog_->input_ascii_roff,
1850                      rc.ascii_roff_command.c_str());
1851         fl_set_input(dialog_->input_checktex,
1852                      rc.chktex_command.c_str());
1853         fl_set_input(dialog_->input_bibtex,
1854                      rc.bibtex_command.c_str());
1855         fl_set_input(dialog_->input_index,
1856                      rc.index_command.c_str());
1857         fl_set_input(dialog_->input_paperoption,
1858                      rc.view_dvi_paper_option.c_str());
1859         fl_set_button(dialog_->check_autoreset_classopt,
1860                       rc.auto_reset_options);
1861
1862 }
1863
1864
1865 FormPreferences::Paths::Paths(FormPreferences &  p)
1866         : parent_(p)
1867 {}
1868
1869
1870 FD_preferences_paths const * FormPreferences::Paths::dialog()
1871 {
1872         return dialog_.get();
1873 }
1874
1875
1876 void FormPreferences::Paths::apply(LyXRC & rc)
1877 {
1878         rc.document_path = fl_get_input(dialog_->input_default_path);
1879         rc.template_path = fl_get_input(dialog_->input_template_path);
1880         rc.tempdir_path  = fl_get_input(dialog_->input_temp_dir);
1881
1882         int button = fl_get_button(dialog_->check_last_files);
1883         string str = fl_get_input(dialog_->input_lastfiles);
1884         if (!button) str.erase();
1885
1886         rc.check_lastfiles = button;
1887         rc.lastfiles = str;
1888         rc.num_lastfiles = static_cast<unsigned int>
1889                 (fl_get_counter_value(dialog_->counter_lastfiles));
1890
1891         button = fl_get_button(dialog_->check_make_backups);
1892         str = fl_get_input(dialog_->input_backup_path);
1893         if (!button)
1894                 str.erase();
1895
1896         rc.make_backup = button;
1897         rc.backupdir_path = str;
1898
1899         rc.lyxpipes = fl_get_input(dialog_->input_serverpipe);
1900
1901         // update view
1902         update(rc);
1903 }
1904
1905
1906 void FormPreferences::Paths::build()
1907 {
1908         dialog_.reset(build_preferences_paths(&parent_));
1909
1910         fl_set_input_return(dialog_->input_default_path, FL_RETURN_CHANGED);
1911         fl_set_input_return(dialog_->input_template_path, FL_RETURN_CHANGED);
1912         fl_set_input_return(dialog_->input_temp_dir, FL_RETURN_CHANGED);
1913         fl_set_input_return(dialog_->input_lastfiles, FL_RETURN_CHANGED);
1914         fl_set_input_return(dialog_->input_backup_path, FL_RETURN_CHANGED);
1915         fl_set_counter_bounds(dialog_->counter_lastfiles, 0, maxlastfiles);
1916         fl_set_counter_return(dialog_->counter_lastfiles, FL_RETURN_CHANGED);
1917         fl_set_input_return(dialog_->input_serverpipe, FL_RETURN_CHANGED);
1918
1919         // set up the feedback mechanism
1920         setPrehandler(dialog_->input_default_path);
1921         setPrehandler(dialog_->counter_lastfiles);
1922         setPrehandler(dialog_->input_template_path);
1923         setPrehandler(dialog_->check_last_files);
1924         setPrehandler(dialog_->input_lastfiles);
1925         setPrehandler(dialog_->check_make_backups);
1926         setPrehandler(dialog_->input_backup_path);
1927         setPrehandler(dialog_->input_serverpipe);
1928         setPrehandler(dialog_->input_temp_dir);
1929 }
1930
1931
1932 string const
1933 FormPreferences::Paths::feedback(FL_OBJECT const * const ob) const
1934 {
1935         if (ob == dialog_->input_default_path)
1936                 return LyXRC::getDescription(LyXRC::RC_DOCUMENTPATH);
1937         if (ob == dialog_->input_template_path)
1938                 return LyXRC::getDescription(LyXRC::RC_TEMPLATEPATH);
1939         if (ob == dialog_->input_temp_dir)
1940                 return LyXRC::getDescription(LyXRC::RC_TEMPDIRPATH);
1941         if (ob == dialog_->check_last_files)
1942                 return LyXRC::getDescription(LyXRC::RC_CHECKLASTFILES);
1943         if (ob == dialog_->input_lastfiles)
1944                 return LyXRC::getDescription(LyXRC::RC_LASTFILES);
1945         if (ob == dialog_->counter_lastfiles)
1946                 return LyXRC::getDescription(LyXRC::RC_NUMLASTFILES);
1947         if (ob == dialog_->check_make_backups)
1948                 return LyXRC::getDescription(LyXRC::RC_MAKE_BACKUP);
1949         if (ob == dialog_->input_backup_path)
1950                 return LyXRC::getDescription(LyXRC::RC_BACKUPDIR_PATH);
1951         if (ob == dialog_->input_serverpipe)
1952                 return LyXRC::getDescription(LyXRC::RC_SERVERPIPE);
1953         return string();
1954 }
1955
1956
1957 bool FormPreferences::Paths::input(FL_OBJECT const * const ob)
1958 {
1959         bool activate = true;
1960
1961         // !ob if function is called from Paths::update() to de/activate
1962         // objects,
1963         // otherwise the function is called by an xforms CB via input().
1964         if (!ob || ob == dialog_->check_last_files) {
1965                 bool const enable = fl_get_button(dialog_->check_last_files);
1966                 setEnabled(dialog_->input_lastfiles, enable);
1967         }
1968
1969         if (!ob || ob == dialog_->check_make_backups) {
1970                 bool const enable = fl_get_button(dialog_->check_make_backups);
1971                 setEnabled(dialog_->input_backup_path, enable);
1972         }
1973
1974         if (!ob || ob == dialog_->input_default_path) {
1975                 string const name = fl_get_input(dialog_->input_default_path);
1976                 if (!name.empty() && !RWInfo::WriteableDir(name)) {
1977                         parent_.postWarning(RWInfo::ErrorMessage());
1978                         return false;
1979                 }
1980         }
1981
1982         if (!ob || ob == dialog_->input_template_path) {
1983                 string const name = fl_get_input(dialog_->input_template_path);
1984                 if (!name.empty() && !RWInfo::ReadableDir(name)) {
1985                         parent_.postWarning(RWInfo::ErrorMessage());
1986                         return false;
1987                 }
1988         }
1989
1990         if (!ob || ob == dialog_->input_temp_dir) {
1991                 string const name = fl_get_input(dialog_->input_temp_dir);
1992                 if (fl_get_button(dialog_->check_make_backups)
1993                     && !name.empty()
1994                     && !RWInfo::WriteableDir(name)) {
1995                         parent_.postWarning(RWInfo::ErrorMessage());
1996                         return false;
1997                 }
1998         }
1999
2000         if (!ob || ob == dialog_->input_backup_path) {
2001                 string const name = fl_get_input(dialog_->input_backup_path);
2002                 if (fl_get_button(dialog_->check_make_backups)
2003                     && !name.empty()
2004                     && !RWInfo::WriteableDir(name)) {
2005                         parent_.postWarning(RWInfo::ErrorMessage());
2006                         return false;
2007                 }
2008         }
2009
2010         if (!ob || ob == dialog_->input_lastfiles) {
2011                 string const name = fl_get_input(dialog_->input_lastfiles);
2012                 if (fl_get_button(dialog_->check_last_files)
2013                     && !name.empty()
2014                     && !RWInfo::WriteableFile(name)) {
2015                         parent_.postWarning(RWInfo::ErrorMessage());
2016                         return false;
2017                 }
2018         }
2019
2020         if (!ob || ob == dialog_->input_serverpipe) {
2021                 string const name = fl_get_input(dialog_->input_serverpipe);
2022                 if (!name.empty()) {
2023                         // strip off the extension
2024                         string const str = ChangeExtension(name, "");
2025                         if (!RWInfo::WriteableFile(str + ".in")) {
2026                                 parent_.postWarning(RWInfo::ErrorMessage());
2027                                 return false;
2028                         }
2029                         if (!RWInfo::WriteableFile(str + ".out")) {
2030                                 parent_.postWarning(RWInfo::ErrorMessage());
2031                                 return false;
2032                         }
2033                 }
2034         }
2035
2036         if (ob == dialog_->button_default_path_browse) {
2037                 string f = parent_.controller().browsedir(
2038                         fl_get_input(dialog_->input_default_path), _("Default path"));
2039                 if (!f.empty())
2040                         fl_set_input(dialog_->input_default_path, f.c_str());
2041         } else if (ob == dialog_->button_template_path_browse) {
2042                 string f = parent_.controller().browsedir(
2043                         fl_get_input(dialog_->input_template_path), _("Template path"));
2044                 if (!f.empty())
2045                         fl_set_input(dialog_->input_template_path, f.c_str());
2046         } else if (ob == dialog_->button_temp_dir_browse) {
2047                 string f = parent_.controller().browsedir(
2048                         fl_get_input(dialog_->input_temp_dir), _("Temporary dir"));
2049                 if (!f.empty())
2050                         fl_set_input(dialog_->input_temp_dir, f.c_str());
2051         } else if (ob == dialog_->button_lastfiles_browse) {
2052                 string f = parent_.controller().browse(
2053                         fl_get_input(dialog_->input_lastfiles), _("Last files"));
2054                 if (!f.empty())
2055                         fl_set_input(dialog_->input_lastfiles, f.c_str());
2056         } else if (ob == dialog_->button_backup_path_browse) {
2057                 string f = parent_.controller().browsedir(
2058                         fl_get_input(dialog_->input_backup_path), _("Backup path"));
2059                 if (!f.empty())
2060                         fl_set_input(dialog_->input_backup_path, f.c_str());
2061         } else if (ob == dialog_->button_serverpipe_browse) {
2062                 string f = parent_.controller().browse(
2063                         fl_get_input(dialog_->input_serverpipe), _("LyX server pipes"));
2064                 if (!f.empty())
2065                         fl_set_input(dialog_->input_serverpipe, f.c_str());
2066         }
2067
2068         return activate;
2069 }
2070
2071
2072 void FormPreferences::Paths::update(LyXRC const & rc)
2073 {
2074         fl_set_input(dialog_->input_default_path,
2075                      rc.document_path.c_str());
2076         fl_set_input(dialog_->input_template_path,
2077                      rc.template_path.c_str());
2078
2079         string str;
2080         if (rc.make_backup)
2081                 str = rc.backupdir_path;
2082
2083         fl_set_button(dialog_->check_make_backups,
2084                       rc.make_backup);
2085         fl_set_input(dialog_->input_backup_path, str.c_str());
2086
2087         fl_set_input(dialog_->input_temp_dir, rc.tempdir_path.c_str());
2088
2089         str.erase();
2090         if (rc.check_lastfiles)
2091                 str = rc.lastfiles;
2092
2093         fl_set_button(dialog_->check_last_files,
2094                       rc.check_lastfiles);
2095         fl_set_input(dialog_->input_lastfiles, str.c_str());
2096         fl_set_counter_value(dialog_->counter_lastfiles,
2097                              rc.num_lastfiles);
2098
2099         fl_set_input(dialog_->input_serverpipe, rc.lyxpipes.c_str());
2100
2101         // Activate/Deactivate the input fields dependent on the state of the
2102         // buttons.
2103         input(0);
2104 }
2105
2106
2107 FormPreferences::Printer::Printer(FormPreferences &  p)
2108         : parent_(p)
2109 {}
2110
2111
2112 FD_preferences_printer const * FormPreferences::Printer::dialog()
2113 {
2114         return dialog_.get();
2115 }
2116
2117
2118 void FormPreferences::Printer::apply(LyXRC & rc) const
2119 {
2120         rc.print_adapt_output = fl_get_button(dialog_->check_adapt_output);
2121         rc.print_command = fl_get_input(dialog_->input_command);
2122         rc.print_pagerange_flag = fl_get_input(dialog_->input_page_range);
2123         rc.print_copies_flag = fl_get_input(dialog_->input_copies);
2124         rc.print_reverse_flag = fl_get_input(dialog_->input_reverse);
2125         rc.print_to_printer = fl_get_input(dialog_->input_to_printer);
2126         rc.print_file_extension =
2127                 fl_get_input(dialog_->input_file_extension);
2128         rc.print_spool_command =
2129                 fl_get_input(dialog_->input_spool_command);
2130         rc.print_paper_flag = fl_get_input(dialog_->input_paper_type);
2131         rc.print_evenpage_flag = fl_get_input(dialog_->input_even_pages);
2132         rc.print_oddpage_flag = fl_get_input(dialog_->input_odd_pages);
2133         rc.print_collcopies_flag = fl_get_input(dialog_->input_collated);
2134         rc.print_landscape_flag = fl_get_input(dialog_->input_landscape);
2135         rc.print_to_file = fl_get_input(dialog_->input_to_file);
2136         rc.print_extra_options =
2137                 fl_get_input(dialog_->input_extra_options);
2138         rc.print_spool_printerprefix =
2139                 fl_get_input(dialog_->input_spool_prefix);
2140         rc.print_paper_dimension_flag =
2141                 fl_get_input(dialog_->input_paper_size);
2142         rc.printer = fl_get_input(dialog_->input_name);
2143 }
2144
2145
2146 string const
2147 FormPreferences::Printer::feedback(FL_OBJECT const * const ob) const
2148 {
2149         if (ob == dialog_->input_command)
2150                 return LyXRC::getDescription(LyXRC::RC_PRINT_COMMAND);
2151         if (ob == dialog_->check_adapt_output)
2152                 return LyXRC::getDescription(LyXRC::RC_PRINT_ADAPTOUTPUT);
2153         if (ob == dialog_->input_to_printer)
2154                 return LyXRC::getDescription(LyXRC::RC_PRINTTOPRINTER);
2155         if (ob == dialog_->input_to_file)
2156                 return LyXRC::getDescription(LyXRC::RC_PRINTTOFILE);
2157         if (ob == dialog_->input_file_extension)
2158                 return LyXRC::getDescription(LyXRC::RC_PRINTFILEEXTENSION);
2159         if (ob == dialog_->input_extra_options)
2160                 return LyXRC::getDescription(LyXRC::RC_PRINTEXSTRAOPTIONS);
2161         if (ob == dialog_->input_spool_command)
2162                 return LyXRC::getDescription(LyXRC::RC_PRINTSPOOL_COMMAND);
2163         if (ob == dialog_->input_spool_prefix)
2164                 return LyXRC::getDescription(LyXRC::RC_PRINTSPOOL_PRINTERPREFIX);
2165         if (ob == dialog_->input_name)
2166                 return LyXRC::getDescription(LyXRC::RC_PRINTER);
2167         if (ob == dialog_->input_even_pages)
2168                 return LyXRC::getDescription(LyXRC::RC_PRINTEVENPAGEFLAG);
2169         if (ob == dialog_->input_odd_pages)
2170                 return LyXRC::getDescription(LyXRC::RC_PRINTODDPAGEFLAG);
2171         if (ob == dialog_->input_page_range)
2172                 return LyXRC::getDescription(LyXRC::RC_PRINTPAGERANGEFLAG);
2173         if (ob == dialog_->input_reverse)
2174                 return LyXRC::getDescription(LyXRC::RC_PRINTREVERSEFLAG);
2175         if (ob == dialog_->input_landscape)
2176                 return LyXRC::getDescription(LyXRC::RC_PRINTLANDSCAPEFLAG);
2177         if (ob == dialog_->input_copies)
2178                 return LyXRC::getDescription(LyXRC::RC_PRINTCOPIESFLAG);
2179         if (ob == dialog_->input_collated)
2180                 return LyXRC::getDescription(LyXRC::RC_PRINTCOLLCOPIESFLAG);
2181         if (ob == dialog_->input_paper_type)
2182                 return LyXRC::getDescription(LyXRC::RC_PRINTPAPERFLAG);
2183         if (ob == dialog_->input_paper_size)
2184                 return LyXRC::getDescription(LyXRC::RC_PRINTPAPERDIMENSIONFLAG);
2185         return string();
2186 }
2187
2188
2189 void FormPreferences::Printer::build()
2190 {
2191         dialog_.reset(build_preferences_printer(&parent_));
2192
2193         fl_set_input_return(dialog_->input_command, FL_RETURN_CHANGED);
2194         fl_set_input_return(dialog_->input_page_range, FL_RETURN_CHANGED);
2195         fl_set_input_return(dialog_->input_copies, FL_RETURN_CHANGED);
2196         fl_set_input_return(dialog_->input_reverse, FL_RETURN_CHANGED);
2197         fl_set_input_return(dialog_->input_to_printer, FL_RETURN_CHANGED);
2198         fl_set_input_return(dialog_->input_file_extension, FL_RETURN_CHANGED);
2199         fl_set_input_return(dialog_->input_spool_command, FL_RETURN_CHANGED);
2200         fl_set_input_return(dialog_->input_paper_type, FL_RETURN_CHANGED);
2201         fl_set_input_return(dialog_->input_even_pages, FL_RETURN_CHANGED);
2202         fl_set_input_return(dialog_->input_odd_pages, FL_RETURN_CHANGED);
2203         fl_set_input_return(dialog_->input_collated, FL_RETURN_CHANGED);
2204         fl_set_input_return(dialog_->input_landscape, FL_RETURN_CHANGED);
2205         fl_set_input_return(dialog_->input_to_file, FL_RETURN_CHANGED);
2206         fl_set_input_return(dialog_->input_extra_options, FL_RETURN_CHANGED);
2207         fl_set_input_return(dialog_->input_spool_prefix, FL_RETURN_CHANGED);
2208         fl_set_input_return(dialog_->input_paper_size, FL_RETURN_CHANGED);
2209         fl_set_input_return(dialog_->input_name, FL_RETURN_CHANGED);
2210
2211         // set up the feedback mechanism
2212         setPrehandler(dialog_->input_command);
2213         setPrehandler(dialog_->input_page_range);
2214         setPrehandler(dialog_->input_copies);
2215         setPrehandler(dialog_->input_reverse);
2216         setPrehandler(dialog_->input_to_printer);
2217         setPrehandler(dialog_->input_file_extension);
2218         setPrehandler(dialog_->input_spool_command);
2219         setPrehandler(dialog_->input_paper_type);
2220         setPrehandler(dialog_->input_even_pages);
2221         setPrehandler(dialog_->input_odd_pages);
2222         setPrehandler(dialog_->input_collated);
2223         setPrehandler(dialog_->input_landscape);
2224         setPrehandler(dialog_->input_to_file);
2225         setPrehandler(dialog_->input_extra_options);
2226         setPrehandler(dialog_->input_spool_prefix);
2227         setPrehandler(dialog_->input_paper_size);
2228         setPrehandler(dialog_->input_name);
2229         setPrehandler(dialog_->check_adapt_output);
2230 }
2231
2232
2233 void FormPreferences::Printer::update(LyXRC const & rc)
2234 {
2235         fl_set_button(dialog_->check_adapt_output,
2236                       rc.print_adapt_output);
2237         fl_set_input(dialog_->input_command,
2238                      rc.print_command.c_str());
2239         fl_set_input(dialog_->input_page_range,
2240                      rc.print_pagerange_flag.c_str());
2241         fl_set_input(dialog_->input_copies,
2242                      rc.print_copies_flag.c_str());
2243         fl_set_input(dialog_->input_reverse,
2244                      rc.print_reverse_flag.c_str());
2245         fl_set_input(dialog_->input_to_printer,
2246                      rc.print_to_printer.c_str());
2247         fl_set_input(dialog_->input_file_extension,
2248                      rc.print_file_extension.c_str());
2249         fl_set_input(dialog_->input_spool_command,
2250                      rc.print_spool_command.c_str());
2251         fl_set_input(dialog_->input_paper_type,
2252                      rc.print_paper_flag.c_str());
2253         fl_set_input(dialog_->input_even_pages,
2254                      rc.print_evenpage_flag.c_str());
2255         fl_set_input(dialog_->input_odd_pages,
2256                      rc.print_oddpage_flag.c_str());
2257         fl_set_input(dialog_->input_collated,
2258                      rc.print_collcopies_flag.c_str());
2259         fl_set_input(dialog_->input_landscape,
2260                      rc.print_landscape_flag.c_str());
2261         fl_set_input(dialog_->input_to_file,
2262                      rc.print_to_file.c_str());
2263         fl_set_input(dialog_->input_extra_options,
2264                      rc.print_extra_options.c_str());
2265         fl_set_input(dialog_->input_spool_prefix,
2266                      rc.print_spool_printerprefix.c_str());
2267         fl_set_input(dialog_->input_paper_size,
2268                      rc.print_paper_dimension_flag.c_str());
2269         fl_set_input(dialog_->input_name,
2270                      rc.printer.c_str());
2271 }
2272
2273
2274 FormPreferences::ScreenFonts::ScreenFonts(FormPreferences &  p)
2275         : parent_(p)
2276 {}
2277
2278
2279 FD_preferences_screen_fonts const * FormPreferences::ScreenFonts::dialog()
2280 {
2281         return dialog_.get();
2282 }
2283
2284
2285 void FormPreferences::ScreenFonts::apply(LyXRC & rc) const
2286 {
2287         bool changed = false;
2288
2289         pair<string, string> tmp =
2290                 parseFontName(fl_get_input(dialog_->input_roman));
2291         if (rc.roman_font_name != tmp.first ||
2292             rc.roman_font_foundry != tmp.second) {
2293                 changed = true;
2294                 rc.roman_font_name = tmp.first;
2295                 rc.roman_font_foundry = tmp.second;
2296         }
2297
2298         tmp = parseFontName(fl_get_input(dialog_->input_sans));
2299         if (rc.sans_font_name != tmp.first ||
2300             rc.sans_font_foundry != tmp.second) {
2301                 changed = true;
2302                 rc.sans_font_name = tmp.first;
2303                 rc.sans_font_foundry = tmp.second;
2304         }
2305
2306         tmp = parseFontName(fl_get_input(dialog_->input_typewriter));
2307         if (rc.typewriter_font_name != tmp.first ||
2308             rc.typewriter_font_foundry != tmp.second) {
2309                 changed = true;
2310                 rc.typewriter_font_name = tmp.first;
2311                 rc.typewriter_font_foundry = tmp.second;
2312         }
2313
2314         string str = fl_get_input(dialog_->input_screen_encoding);
2315         if (rc.font_norm != str) {
2316                 changed = true;
2317                 rc.font_norm = str;
2318                 rc.set_font_norm_type();
2319         }
2320
2321         bool button = fl_get_button(dialog_->check_scalable);
2322         if (rc.use_scalable_fonts != button) {
2323                 changed = true;
2324                 rc.use_scalable_fonts = button;
2325         }
2326
2327         unsigned int ivalue = static_cast<unsigned int>
2328                 (fl_get_counter_value(dialog_->counter_zoom));
2329         if (rc.zoom != ivalue) {
2330                 changed = true;
2331                 rc.zoom = ivalue;
2332         }
2333
2334         ivalue = static_cast<unsigned int>
2335                 (fl_get_counter_value(dialog_->counter_dpi));
2336         if (rc.dpi != ivalue) {
2337                 changed = true;
2338                 rc.dpi = ivalue;
2339         }
2340
2341         double dvalue = strToDbl(fl_get_input(dialog_->input_tiny));
2342         if (rc.font_sizes[LyXFont::SIZE_TINY] != dvalue) {
2343                 changed = true;
2344                 rc.font_sizes[LyXFont::SIZE_TINY] = dvalue;
2345         }
2346
2347         dvalue = strToDbl(fl_get_input(dialog_->input_script));
2348         if (rc.font_sizes[LyXFont::SIZE_SCRIPT] != dvalue) {
2349                 changed = true;
2350                 rc.font_sizes[LyXFont::SIZE_SCRIPT] = dvalue;
2351         }
2352
2353         dvalue = strToDbl(fl_get_input(dialog_->input_footnote));
2354         if (rc.font_sizes[LyXFont::SIZE_FOOTNOTE] != dvalue) {
2355                 changed = true;
2356                 rc.font_sizes[LyXFont::SIZE_FOOTNOTE] = dvalue;
2357         }
2358
2359         dvalue = strToDbl(fl_get_input(dialog_->input_small));
2360         if (rc.font_sizes[LyXFont::SIZE_SMALL] != dvalue) {
2361                 changed = true;
2362                 rc.font_sizes[LyXFont::SIZE_SMALL] = dvalue;
2363         }
2364
2365         dvalue = strToDbl(fl_get_input(dialog_->input_normal));
2366         if (rc.font_sizes[LyXFont::SIZE_NORMAL] != dvalue) {
2367                 changed = true;
2368                 rc.font_sizes[LyXFont::SIZE_NORMAL] = dvalue;
2369         }
2370
2371         dvalue = strToDbl(fl_get_input(dialog_->input_large));
2372         if (rc.font_sizes[LyXFont::SIZE_LARGE] != dvalue) {
2373                 changed = true;
2374                 rc.font_sizes[LyXFont::SIZE_LARGE] = dvalue;
2375         }
2376
2377         dvalue = strToDbl(fl_get_input(dialog_->input_larger));
2378         if (rc.font_sizes[LyXFont::SIZE_LARGER] != dvalue) {
2379                 changed = true;
2380                 rc.font_sizes[LyXFont::SIZE_LARGER] = dvalue;
2381         }
2382
2383         dvalue = strToDbl(fl_get_input(dialog_->input_largest));
2384         if (rc.font_sizes[LyXFont::SIZE_LARGEST] != dvalue) {
2385                 changed = true;
2386                 rc.font_sizes[LyXFont::SIZE_LARGEST] = dvalue;
2387         }
2388
2389         dvalue = strToDbl(fl_get_input(dialog_->input_huge));
2390         if (rc.font_sizes[LyXFont::SIZE_HUGE] != dvalue) {
2391                 changed = true;
2392                 rc.font_sizes[LyXFont::SIZE_HUGE] = dvalue;
2393         }
2394
2395         dvalue = strToDbl(fl_get_input(dialog_->input_huger));
2396         if (rc.font_sizes[LyXFont::SIZE_HUGER] != dvalue) {
2397                 changed = true;
2398                 rc.font_sizes[LyXFont::SIZE_HUGER] = dvalue;
2399         }
2400
2401         if (changed) {
2402                 // Now update the buffers
2403                 // Can anything below here affect the redraw process?
2404                 parent_.controller().updateScreenFonts();
2405         }
2406 }
2407
2408
2409 void FormPreferences::ScreenFonts::build()
2410 {
2411         dialog_.reset(build_preferences_screen_fonts(&parent_));
2412
2413         fl_set_counter_step(dialog_->counter_zoom, 1, 10);
2414         fl_set_counter_step(dialog_->counter_dpi,  1, 10);
2415
2416         fl_set_input_return(dialog_->input_roman,           FL_RETURN_CHANGED);
2417         fl_set_input_return(dialog_->input_sans,            FL_RETURN_CHANGED);
2418         fl_set_input_return(dialog_->input_typewriter,      FL_RETURN_CHANGED);
2419         fl_set_input_return(dialog_->input_screen_encoding, FL_RETURN_CHANGED);
2420         fl_set_counter_return(dialog_->counter_zoom,        FL_RETURN_CHANGED);
2421         fl_set_counter_return(dialog_->counter_dpi,         FL_RETURN_CHANGED);
2422         fl_set_input_return(dialog_->input_tiny,            FL_RETURN_CHANGED);
2423         fl_set_input_return(dialog_->input_script,          FL_RETURN_CHANGED);
2424         fl_set_input_return(dialog_->input_footnote,        FL_RETURN_CHANGED);
2425         fl_set_input_return(dialog_->input_small,           FL_RETURN_CHANGED);
2426         fl_set_input_return(dialog_->input_normal,          FL_RETURN_CHANGED);
2427         fl_set_input_return(dialog_->input_large,           FL_RETURN_CHANGED);
2428         fl_set_input_return(dialog_->input_larger,          FL_RETURN_CHANGED);
2429         fl_set_input_return(dialog_->input_largest,         FL_RETURN_CHANGED);
2430         fl_set_input_return(dialog_->input_huge,            FL_RETURN_CHANGED);
2431         fl_set_input_return(dialog_->input_huger,           FL_RETURN_CHANGED);
2432
2433         fl_set_input_filter(dialog_->input_tiny,     fl_unsigned_float_filter);
2434         fl_set_input_filter(dialog_->input_script,   fl_unsigned_float_filter);
2435         fl_set_input_filter(dialog_->input_footnote, fl_unsigned_float_filter);
2436         fl_set_input_filter(dialog_->input_small,    fl_unsigned_float_filter);
2437         fl_set_input_filter(dialog_->input_normal,   fl_unsigned_float_filter);
2438         fl_set_input_filter(dialog_->input_large,    fl_unsigned_float_filter);
2439         fl_set_input_filter(dialog_->input_larger,   fl_unsigned_float_filter);
2440         fl_set_input_filter(dialog_->input_largest,  fl_unsigned_float_filter);
2441         fl_set_input_filter(dialog_->input_huge,     fl_unsigned_float_filter);
2442         fl_set_input_filter(dialog_->input_huger,    fl_unsigned_float_filter);
2443
2444         // set up the feedback mechanism
2445         setPrehandler(dialog_->input_roman);
2446         setPrehandler(dialog_->input_sans);
2447         setPrehandler(dialog_->input_typewriter);
2448         setPrehandler(dialog_->counter_zoom);
2449         setPrehandler(dialog_->counter_dpi);
2450         setPrehandler(dialog_->check_scalable);
2451         setPrehandler(dialog_->input_screen_encoding);
2452         setPrehandler(dialog_->input_tiny);
2453         setPrehandler(dialog_->input_script);
2454         setPrehandler(dialog_->input_footnote);
2455         setPrehandler(dialog_->input_small);
2456         setPrehandler(dialog_->input_large);
2457         setPrehandler(dialog_->input_larger);
2458         setPrehandler(dialog_->input_largest);
2459         setPrehandler(dialog_->input_normal);
2460         setPrehandler(dialog_->input_huge);
2461         setPrehandler(dialog_->input_huger);
2462 }
2463
2464
2465 string const
2466 FormPreferences::ScreenFonts::feedback(FL_OBJECT const * const ob) const
2467 {
2468         if (ob == dialog_->input_roman)
2469                 return LyXRC::getDescription(LyXRC::RC_SCREEN_FONT_ROMAN);
2470         if (ob == dialog_->input_sans)
2471                 return LyXRC::getDescription(LyXRC::RC_SCREEN_FONT_SANS);
2472         if (ob == dialog_->input_typewriter)
2473                 return LyXRC::getDescription(LyXRC::RC_SCREEN_FONT_TYPEWRITER);
2474         if (ob == dialog_->check_scalable)
2475                 return LyXRC::getDescription(LyXRC::RC_SCREEN_FONT_SCALABLE);
2476         if (ob == dialog_->input_screen_encoding)
2477                 return LyXRC::getDescription(LyXRC::RC_SCREEN_FONT_ENCODING);
2478         if (ob == dialog_->counter_zoom)
2479                 return LyXRC::getDescription(LyXRC::RC_SCREEN_ZOOM);
2480         if (ob == dialog_->counter_dpi)
2481                 return LyXRC::getDescription(LyXRC::RC_SCREEN_DPI);
2482         if (ob == dialog_->input_tiny
2483             || ob == dialog_->input_script
2484             || ob == dialog_->input_footnote
2485             || ob == dialog_->input_small
2486             || ob == dialog_->input_large
2487             || ob == dialog_->input_larger
2488             || ob == dialog_->input_larger
2489             || ob == dialog_->input_largest
2490             || ob == dialog_->input_normal
2491             || ob == dialog_->input_huge
2492             || ob == dialog_->input_huger)
2493                 return LyXRC::getDescription(LyXRC::RC_SCREEN_FONT_SIZES);
2494         return string();
2495 }
2496
2497
2498 bool FormPreferences::ScreenFonts::input()
2499 {
2500         bool activate = true;
2501         string str;
2502
2503         // Make sure that all fonts all have positive entries
2504         // Also note that an empty entry is returned as 0.0 by strToDbl
2505         if (0.0 >= strToDbl(fl_get_input(dialog_->input_tiny))
2506             || 0.0 >= strToDbl(fl_get_input(dialog_->input_script))
2507             || 0.0 >= strToDbl(fl_get_input(dialog_->input_footnote))
2508             || 0.0 >= strToDbl(fl_get_input(dialog_->input_small))
2509             || 0.0 >= strToDbl(fl_get_input(dialog_->input_normal))
2510             || 0.0 >= strToDbl(fl_get_input(dialog_->input_large))
2511             || 0.0 >= strToDbl(fl_get_input(dialog_->input_larger))
2512             || 0.0 >= strToDbl(fl_get_input(dialog_->input_largest))
2513             || 0.0 >= strToDbl(fl_get_input(dialog_->input_huge))
2514             || 0.0 >= strToDbl(fl_get_input(dialog_->input_huger))) {
2515                 activate = false;
2516                 str = _("Fonts must be positive!");
2517
2518         } else if (strToDbl(fl_get_input(dialog_->input_tiny)) >
2519                    // Fontsizes -- tiny < script < footnote etc.
2520                    strToDbl(fl_get_input(dialog_->input_script)) ||
2521                    strToDbl(fl_get_input(dialog_->input_script)) >
2522                    strToDbl(fl_get_input(dialog_->input_footnote)) ||
2523                    strToDbl(fl_get_input(dialog_->input_footnote)) >
2524                    strToDbl(fl_get_input(dialog_->input_small)) ||
2525                    strToDbl(fl_get_input(dialog_->input_small)) >
2526                    strToDbl(fl_get_input(dialog_->input_normal)) ||
2527                    strToDbl(fl_get_input(dialog_->input_normal)) >
2528                    strToDbl(fl_get_input(dialog_->input_large)) ||
2529                    strToDbl(fl_get_input(dialog_->input_large)) >
2530                    strToDbl(fl_get_input(dialog_->input_larger)) ||
2531                    strToDbl(fl_get_input(dialog_->input_larger)) >
2532                    strToDbl(fl_get_input(dialog_->input_largest)) ||
2533                    strToDbl(fl_get_input(dialog_->input_largest)) >
2534                    strToDbl(fl_get_input(dialog_->input_huge)) ||
2535                    strToDbl(fl_get_input(dialog_->input_huge)) >
2536                    strToDbl(fl_get_input(dialog_->input_huger))) {
2537                 activate = false;
2538
2539                 str = _("Fonts must be input in the order Tiny > Smallest > Smaller > Small > Normal > Large > Larger > Largest > Huge > Huger.");
2540         }
2541
2542         if (!activate)
2543                 parent_.postWarning(str);
2544
2545         return activate;
2546 }
2547
2548
2549 void FormPreferences::ScreenFonts::update(LyXRC const & rc)
2550 {
2551         fl_set_input(dialog_->input_roman,
2552                      makeFontName(rc.roman_font_name,
2553                                   rc.roman_font_foundry).c_str());
2554         fl_set_input(dialog_->input_sans,
2555                      makeFontName(rc.sans_font_name,
2556                                   rc.sans_font_foundry).c_str());
2557         fl_set_input(dialog_->input_typewriter,
2558                      makeFontName(rc.typewriter_font_name,
2559                                   rc.typewriter_font_foundry).c_str());
2560         fl_set_input(dialog_->input_screen_encoding,
2561                      rc.font_norm.c_str());
2562         fl_set_button(dialog_->check_scalable,
2563                       rc.use_scalable_fonts);
2564         fl_set_counter_value(dialog_->counter_zoom, rc.zoom);
2565         fl_set_counter_value(dialog_->counter_dpi,  rc.dpi);
2566         fl_set_input(dialog_->input_tiny,
2567                      tostr(rc.font_sizes[LyXFont::SIZE_TINY]).c_str());
2568         fl_set_input(dialog_->input_script,
2569                      tostr(rc.font_sizes[LyXFont::SIZE_SCRIPT]).c_str());
2570         fl_set_input(dialog_->input_footnote,
2571                      tostr(rc.font_sizes[LyXFont::SIZE_FOOTNOTE]).c_str());
2572         fl_set_input(dialog_->input_small,
2573                      tostr(rc.font_sizes[LyXFont::SIZE_SMALL]).c_str());
2574         fl_set_input(dialog_->input_normal,
2575                      tostr(rc.font_sizes[LyXFont::SIZE_NORMAL]).c_str());
2576         fl_set_input(dialog_->input_large,
2577                      tostr(rc.font_sizes[LyXFont::SIZE_LARGE]).c_str());
2578         fl_set_input(dialog_->input_larger,
2579                      tostr(rc.font_sizes[LyXFont::SIZE_LARGER]).c_str());
2580         fl_set_input(dialog_->input_largest,
2581                      tostr(rc.font_sizes[LyXFont::SIZE_LARGEST]).c_str());
2582         fl_set_input(dialog_->input_huge,
2583                      tostr(rc.font_sizes[LyXFont::SIZE_HUGE]).c_str());
2584         fl_set_input(dialog_->input_huger,
2585                      tostr(rc.font_sizes[LyXFont::SIZE_HUGER]).c_str());
2586 }
2587
2588
2589
2590 FormPreferences::SpellOptions::SpellOptions(FormPreferences &  p)
2591         : parent_(p)
2592 {}
2593
2594
2595 FD_preferences_spelloptions const * FormPreferences::SpellOptions::dialog()
2596 {
2597         return dialog_.get();
2598 }
2599
2600
2601 void FormPreferences::SpellOptions::apply(LyXRC & rc)
2602 {
2603         string choice = fl_get_choice_text(dialog_->choice_spell_command);
2604         choice = trim(choice);
2605
2606         rc.isp_command = choice;
2607
2608 #if 0
2609         // If spell checker == "none", all other input set to off.
2610         if (fl_get_choice(dialog_->choice_spell_command) == 1) {
2611                 rc.isp_use_alt_lang = false;
2612                 rc.isp_alt_lang.erase();
2613
2614                 rc.isp_use_esc_chars = false;
2615                 rc.isp_esc_chars.erase();
2616
2617                 rc.isp_use_pers_dict = false;
2618                 rc.isp_pers_dict.erase();
2619
2620                 rc.isp_accept_compound = false;
2621                 rc.isp_use_input_encoding = false;
2622         } else {
2623 #else
2624                 int button = fl_get_button(dialog_->check_alt_lang);
2625                 choice = fl_get_input(dialog_->input_alt_lang);
2626                 if (button && choice.empty()) button = 0;
2627                 if (!button) choice.erase();
2628
2629                 rc.isp_use_alt_lang = static_cast<bool>(button);
2630                 rc.isp_alt_lang = choice;
2631
2632                 button = fl_get_button(dialog_->check_escape_chars);
2633                 choice = fl_get_input(dialog_->input_escape_chars);
2634                 if (button && choice.empty()) button = 0;
2635                 if (!button) choice.erase();
2636
2637                 rc.isp_use_esc_chars = static_cast<bool>(button);
2638                 rc.isp_esc_chars = choice;
2639
2640                 button = fl_get_button(dialog_->check_personal_dict);
2641                 choice = fl_get_input(dialog_->input_personal_dict);
2642                 if (button && choice.empty()) button = 0;
2643                 if (!button) choice.erase();
2644
2645                 rc.isp_use_pers_dict = static_cast<bool>(button);
2646                 rc.isp_pers_dict = choice;
2647
2648                 button = fl_get_button(dialog_->check_compound_words);
2649                 rc.isp_accept_compound = static_cast<bool>(button);
2650
2651                 button = fl_get_button(dialog_->check_input_enc);
2652                 rc.isp_use_input_encoding = static_cast<bool>(button);
2653 #endif
2654 #if 0
2655         }
2656 #endif
2657
2658         // Reset view
2659         update(rc);
2660 }
2661
2662
2663 void FormPreferences::SpellOptions::build()
2664 {
2665         dialog_.reset(build_preferences_spelloptions(&parent_));
2666
2667         fl_addto_choice(dialog_->choice_spell_command,
2668                         _(" ispell | aspell ").c_str());
2669         fl_set_input_return(dialog_->input_alt_lang,      FL_RETURN_CHANGED);
2670         fl_set_input_return(dialog_->input_escape_chars,  FL_RETURN_CHANGED);
2671         fl_set_input_return(dialog_->input_personal_dict, FL_RETURN_CHANGED);
2672
2673         // set up the feedback mechanism
2674         setPrehandler(dialog_->choice_spell_command);
2675         setPrehandler(dialog_->check_alt_lang);
2676         setPrehandler(dialog_->input_alt_lang);
2677         setPrehandler(dialog_->check_escape_chars);
2678         setPrehandler(dialog_->input_escape_chars);
2679         setPrehandler(dialog_->check_personal_dict);
2680         setPrehandler(dialog_->input_personal_dict);
2681         setPrehandler(dialog_->button_personal_dict);
2682         setPrehandler(dialog_->check_compound_words);
2683         setPrehandler(dialog_->check_input_enc);
2684 }
2685
2686
2687 string const
2688 FormPreferences::SpellOptions::feedback(FL_OBJECT const * const ob) const
2689 {
2690         if (ob == dialog_->choice_spell_command)
2691                 return LyXRC::getDescription(LyXRC::RC_SPELL_COMMAND);
2692         if (ob == dialog_->check_alt_lang)
2693                 return LyXRC::getDescription(LyXRC::RC_USE_ALT_LANG);
2694         if (ob == dialog_->input_alt_lang)
2695                 return LyXRC::getDescription(LyXRC::RC_ALT_LANG);
2696         if (ob == dialog_->check_escape_chars)
2697                 return LyXRC::getDescription(LyXRC::RC_USE_ESC_CHARS);
2698         if (ob == dialog_->input_escape_chars)
2699                 return LyXRC::getDescription(LyXRC::RC_ESC_CHARS);
2700         if (ob == dialog_->check_personal_dict)
2701                 return LyXRC::getDescription(LyXRC::RC_USE_PERS_DICT);
2702         if (ob == dialog_->input_personal_dict)
2703                 return LyXRC::getDescription(LyXRC::RC_PERS_DICT);
2704         if (ob == dialog_->check_compound_words)
2705                 return LyXRC::getDescription(LyXRC::RC_ACCEPT_COMPOUND);
2706         if (ob == dialog_->check_input_enc)
2707                 return LyXRC::getDescription(LyXRC::RC_USE_INP_ENC);
2708         return string();
2709 }
2710
2711
2712 bool FormPreferences::SpellOptions::input(FL_OBJECT const * const ob)
2713 {
2714         // !ob if function is called from updateSpellOptions() to de/activate
2715         // objects,
2716         // otherwise the function is called by an xforms CB via input().
2717
2718 #if 0
2719         // If spell checker == "none", disable all input.
2720         if (!ob || ob == dialog_->choice_spell_command) {
2721                 if (fl_get_choice(dialog_->choice_spell_command) == 1) {
2722                         fl_deactivate_object(dialog_->check_alt_lang);
2723                         fl_deactivate_object(dialog_->input_alt_lang);
2724                         fl_deactivate_object(dialog_->check_escape_chars);
2725                         fl_deactivate_object(dialog_->input_escape_chars);
2726                         fl_deactivate_object(dialog_->check_personal_dict);
2727                         fl_deactivate_object(dialog_->input_personal_dict);
2728                         fl_deactivate_object(dialog_->check_compound_words);
2729                         fl_deactivate_object(dialog_->check_input_enc);
2730                         return true;
2731                 } else {
2732                         fl_activate_object(dialog_->check_alt_lang);
2733                         fl_activate_object(dialog_->check_escape_chars);
2734                         fl_activate_object(dialog_->check_personal_dict);
2735                         fl_activate_object(dialog_->check_compound_words);
2736                         fl_activate_object(dialog_->check_input_enc);
2737                 }
2738         }
2739 #endif
2740
2741         if (!ob || ob == dialog_->check_alt_lang) {
2742                 bool const enable = fl_get_button(dialog_->check_alt_lang);
2743                 setEnabled(dialog_->input_alt_lang, enable);
2744         }
2745
2746         if (!ob || ob == dialog_->check_escape_chars) {
2747                 bool const enable = fl_get_button(dialog_->check_escape_chars);
2748                 setEnabled(dialog_->input_escape_chars, enable);
2749         }
2750
2751         if (!ob || ob == dialog_->check_personal_dict) {
2752                 bool const enable = fl_get_button(dialog_->check_personal_dict);
2753                 setEnabled(dialog_->input_personal_dict, enable);
2754         }
2755
2756         if (ob == dialog_->button_personal_dict) {
2757                 string f = parent_.controller().browsedict(
2758                         fl_get_input(dialog_->input_personal_dict));
2759                 fl_set_input(dialog_->input_personal_dict, f.c_str());
2760         }
2761
2762         return true; // All input is valid!
2763 }
2764
2765
2766 void FormPreferences::SpellOptions::update(LyXRC const & rc)
2767 {
2768         int choice = 1;
2769 #if 0
2770         if (rc.isp_command == "none")
2771                 choice = 1;
2772         else if (rc.isp_command == "ispell")
2773                 choice = 2;
2774         else if (rc.isp_command == "aspell")
2775                 choice = 3;
2776 #else
2777         if (rc.isp_command == "ispell")
2778                 choice = 1;
2779         else if (rc.isp_command == "aspell")
2780                 choice = 2;
2781 #endif
2782         fl_set_choice(dialog_->choice_spell_command, choice);
2783
2784         string str;
2785         if (rc.isp_use_alt_lang)
2786                 str = rc.isp_alt_lang;
2787
2788         fl_set_button(dialog_->check_alt_lang,
2789                       rc.isp_use_alt_lang);
2790         fl_set_input(dialog_->input_alt_lang, str.c_str());
2791
2792         str.erase();
2793         if (rc.isp_use_esc_chars)
2794                 str = rc.isp_esc_chars;
2795
2796         fl_set_button(dialog_->check_escape_chars,
2797                       rc.isp_use_esc_chars);
2798         fl_set_input(dialog_->input_escape_chars, str.c_str());
2799
2800         str.erase();
2801         if (rc.isp_use_pers_dict)
2802                 str = rc.isp_pers_dict;
2803
2804         fl_set_button(dialog_->check_personal_dict,
2805                       rc.isp_use_pers_dict);
2806         fl_set_input(dialog_->input_personal_dict, str.c_str());
2807
2808         fl_set_button(dialog_->check_compound_words,
2809                       rc.isp_accept_compound);
2810         fl_set_button(dialog_->check_input_enc,
2811                       rc.isp_use_input_encoding);
2812
2813         // Activate/Deactivate the input fields dependent on the state of the
2814         // buttons.
2815         input(0);
2816 }
2817
2818 } // namespace frontend
2819 } // namespace lyx