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