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