2 * \file FormPreferences.C
3 * Copyright 2000-2001 The LyX Team.
4 * See the file COPYING.
6 * \author Angus Leeming, a.leeming@ic.ac.uk
12 #pragma implementation
15 #include "FormPreferences.h"
16 #include "forms/form_preferences.h"
20 #include "converter.h"
22 #include "frontends/LyXView.h"
24 #include "frnt_lang.h"
33 #include "input_validators.h"
34 #include "forms_gettext.h"
35 #include "xforms_helpers.h"
36 #include "helper_funcs.h"
38 #include "support/lyxfunctional.h"
39 #include "support/lyxmanip.h"
40 #include "support/filetools.h"
41 #include "support/LAssert.h"
43 #include "graphics/GraphicsCache.h"
45 #include <boost/bind.hpp>
47 #include FORMS_H_LOCATION
61 extern string system_lyxdir;
62 extern string user_lyxdir;
66 // These should probably go inside the class definition...
67 Formats local_formats;
68 Converters local_converters;
73 FormPreferences::FormPreferences(LyXView & lv, Dialogs & d)
74 : FormBaseBI(&lv, &d, _("Preferences"), false),
75 colors_(*this), converters_(*this), inputs_misc_(*this),
76 formats_(*this), interface_(*this), language_(*this),
77 lnf_misc_(*this), outputs_misc_(*this), paths_(*this),
78 printer_(*this), screen_fonts_(*this), spelloptions_(*this)
80 // let the dialog be shown
81 // This is a permanent connection so we won't bother
82 // storing a copy because we won't be disconnecting.
86 void FormPreferences::redraw()
88 if (!(form() && form()->visible))
90 fl_redraw_form(form());
92 FL_FORM * form2 = fl_get_active_folder(dialog_->tabfolder_prefs);
93 if (!(form2 && form2->visible))
95 fl_redraw_form(form2);
98 if (form2 == converters_tab_->form)
99 form3 = fl_get_active_folder(converters_tab_->tabfolder_inner);
101 else if (form2 == look_n_feel_tab_->form)
102 form3 = fl_get_active_folder(look_n_feel_tab_->tabfolder_inner);
104 else if (form2 == inputs_tab_->form)
105 form3 = fl_get_active_folder(inputs_tab_->tabfolder_inner);
107 else if (form2 == outputs_tab_->form)
108 form3 = fl_get_active_folder(outputs_tab_->tabfolder_inner);
110 else if (form2 == lang_opts_tab_->form)
111 form3 = fl_get_active_folder(lang_opts_tab_->tabfolder_inner);
113 if (form3 && form3->visible)
114 fl_redraw_form(form3);
118 FL_FORM * FormPreferences::form() const
120 return dialog_.get() ? dialog_->form : 0;
124 void FormPreferences::ok()
126 FormBaseDeprecated::ok();
128 if (colors_.modifiedXformsPrefs) {
129 string const filename =
130 AddName(user_lyxdir, "preferences.xform");
131 colors_.modifiedXformsPrefs = !XformsColor::write(filename);
134 lv_->getLyXFunc()->dispatch(LFUN_SAVEPREFERENCES);
138 void FormPreferences::hide()
140 // We need to hide the active tabfolder otherwise we get a
141 // BadDrawable error from X window and LyX crashes without saving.
142 FL_FORM * inner_form = fl_get_active_folder(dialog_->tabfolder_prefs);
143 if (inner_form && inner_form->visible)
144 fl_hide_form(inner_form);
145 FormBaseDeprecated::hide();
149 void FormPreferences::build()
151 dialog_.reset(build_preferences(this));
153 // Manage the restore, save, apply and cancel/close buttons
154 bc().setOK(dialog_->button_ok);
155 bc().setApply(dialog_->button_apply);
156 bc().setCancel(dialog_->button_close);
157 bc().setRestore(dialog_->button_restore);
159 // Allow the base class to control messages
160 setMessageWidget(dialog_->text_warning);
162 // build the tab folders
163 converters_tab_.reset(build_preferences_inner_tab(this));
164 look_n_feel_tab_.reset(build_preferences_inner_tab(this));
165 inputs_tab_.reset(build_preferences_inner_tab(this));
166 outputs_tab_.reset(build_preferences_inner_tab(this));
167 lang_opts_tab_.reset(build_preferences_inner_tab(this));
169 // build actual tabfolder contents
170 // these will become nested tabfolders
174 inputs_misc_.build();
178 outputs_misc_.build();
181 screen_fonts_.build();
182 spelloptions_.build();
184 // Now add them to the tabfolder
185 fl_addto_tabfolder(dialog_->tabfolder_prefs,
187 look_n_feel_tab_->form);
188 fl_addto_tabfolder(dialog_->tabfolder_prefs,
190 lang_opts_tab_->form);
191 fl_addto_tabfolder(dialog_->tabfolder_prefs,
193 converters_tab_->form);
194 fl_addto_tabfolder(dialog_->tabfolder_prefs,
197 fl_addto_tabfolder(dialog_->tabfolder_prefs,
201 // now build the nested tabfolders
202 // Starting with look and feel
203 fl_addto_tabfolder(look_n_feel_tab_->tabfolder_inner,
205 screen_fonts_.dialog()->form);
206 fl_addto_tabfolder(look_n_feel_tab_->tabfolder_inner,
208 interface_.dialog()->form);
209 fl_addto_tabfolder(look_n_feel_tab_->tabfolder_inner,
211 colors_.dialog()->form);
212 fl_addto_tabfolder(look_n_feel_tab_->tabfolder_inner,
214 lnf_misc_.dialog()->form);
216 // then build converters
217 fl_addto_tabfolder(converters_tab_->tabfolder_inner,
219 formats_.dialog()->form);
220 fl_addto_tabfolder(converters_tab_->tabfolder_inner,
222 converters_.dialog()->form);
225 // Paths should probably go in a few inner_tab called Files
226 fl_addto_tabfolder(inputs_tab_->tabfolder_inner,
228 paths_.dialog()->form);
229 fl_addto_tabfolder(inputs_tab_->tabfolder_inner,
231 inputs_misc_.dialog()->form);
233 // then building outputs
234 fl_addto_tabfolder(outputs_tab_->tabfolder_inner,
236 printer_.dialog()->form);
237 fl_addto_tabfolder(outputs_tab_->tabfolder_inner,
239 outputs_misc_.dialog()->form);
241 // then building usage
242 fl_addto_tabfolder(lang_opts_tab_->tabfolder_inner,
244 spelloptions_.dialog()->form);
245 fl_addto_tabfolder(lang_opts_tab_->tabfolder_inner,
247 language_.dialog()->form);
251 void FormPreferences::apply()
253 // set the new lyxrc entries
254 // many of these need to trigger other functions when the assignment
255 // is made. For example, screen zoom and font types. These could be
256 // handled either by signals/slots in lyxrc or just directly call the
257 // associated functions here.
258 // There are other problems with this scheme. We really should check
259 // what we copy to make sure that it really is necessary to do things
260 // like update the screen fonts because that flushes the textcache
261 // and other stuff which may cost us a lot on slower/high-load
265 formats_.apply(); // Must be before converters_.apply()
267 inputs_misc_.apply();
271 outputs_misc_.apply();
274 screen_fonts_.apply();
275 spelloptions_.apply();
279 string const FormPreferences::getFeedback(FL_OBJECT * ob)
283 if (ob->form->fdui == colors_.dialog())
284 return colors_.feedback(ob);
285 if (ob->form->fdui == converters_.dialog())
286 return converters_.feedback(ob);
287 if (ob->form->fdui == formats_.dialog())
288 return formats_.feedback(ob);
289 if (ob->form->fdui == inputs_misc_.dialog())
290 return inputs_misc_.feedback(ob);
291 if (ob->form->fdui == interface_.dialog())
292 return interface_.feedback(ob);
293 if (ob->form->fdui == language_.dialog())
294 return language_.feedback(ob);
295 if (ob->form->fdui == lnf_misc_.dialog())
296 return lnf_misc_.feedback(ob);
297 if (ob->form->fdui == outputs_misc_.dialog())
298 return outputs_misc_.feedback(ob);
299 if (ob->form->fdui == paths_.dialog())
300 return paths_.feedback(ob);
301 if (ob->form->fdui == printer_.dialog())
302 return printer_.feedback(ob);
303 if (ob->form->fdui == screen_fonts_.dialog())
304 return screen_fonts_.feedback(ob);
305 if (ob->form->fdui == spelloptions_.dialog())
306 return spelloptions_.feedback(ob);
312 bool FormPreferences::input(FL_OBJECT * ob, long)
316 // whatever checks you need to ensure the user hasn't entered
317 // some totally ridiculous value somewhere. Change activate to suit.
318 // comments before each test describe what is _valid_
320 if (ob->form->fdui == colors_.dialog()) {
324 if (ob->form->fdui == converters_.dialog())
325 return converters_.input(ob);
326 if (ob->form->fdui == formats_.dialog())
327 return formats_.input(ob);
328 if (ob->form->fdui == interface_.dialog())
329 return interface_.input(ob);
330 if (ob->form->fdui == language_.dialog())
331 return language_.input(ob);
332 if (ob->form->fdui == paths_.dialog())
333 return paths_.input(ob);
334 if (ob->form->fdui == screen_fonts_.dialog())
335 return screen_fonts_.input();
336 if (ob->form->fdui == spelloptions_.dialog())
337 return spelloptions_.input(ob);
343 void FormPreferences::update()
345 if (!dialog_.get()) return;
347 // read lyxrc entries
349 formats_.update(); // Must be before converters_.update()
350 converters_.update();
351 inputs_misc_.update();
355 outputs_misc_.update();
358 screen_fonts_.update();
359 spelloptions_.update();
363 FormPreferences::Colors::Colors(FormPreferences & p)
364 : modifiedXformsPrefs(false), parent_(p)
368 FD_preferences_colors const * FormPreferences::Colors::dialog()
370 return dialog_.get();
374 void FormPreferences::Colors::apply()
376 bool modifiedText = false;
377 bool modifiedBackground = false;
379 for (vector<XformsColor>::const_iterator cit = xformsColorDB.begin();
380 cit != xformsColorDB.end(); ++cit) {
382 fl_getmcolor(cit->colorID, &col.r, &col.g, &col.b);
383 if (col != cit->color()) {
384 modifiedXformsPrefs = true;
385 if (cit->colorID == FL_BLACK)
387 if (cit->colorID == FL_COL1)
388 modifiedBackground = true;
392 if (modifiedXformsPrefs) {
393 for (vector<XformsColor>::const_iterator cit =
394 xformsColorDB.begin();
395 cit != xformsColorDB.end(); ++cit) {
396 fl_mapcolor(cit->colorID, cit->r, cit->g, cit->b);
398 if (modifiedText && cit->colorID == FL_BLACK) {
399 AdjustVal(FL_INACTIVE, FL_BLACK, 0.5);
402 if (modifiedBackground && cit->colorID == FL_COL1) {
403 AdjustVal(FL_MCOL, FL_COL1, 0.1);
404 AdjustVal(FL_TOP_BCOL, FL_COL1, 0.1);
405 AdjustVal(FL_LEFT_BCOL, FL_COL1, 0.1);
407 AdjustVal(FL_RIGHT_BCOL, FL_COL1, -0.5);
408 AdjustVal(FL_BOTTOM_BCOL, FL_COL1, -0.5);
411 if (cit->colorID == GUI_COLOR_CURSOR) {
412 fl_mapcolor(GUI_COLOR_CURSOR,
413 cit->r, cit->g, cit->b);
414 setCursorColor(GUI_COLOR_CURSOR);
417 parent_.lv_->getDialogs()->redrawGUI();
420 // Now do the same for the LyX LColors...
421 for (vector<NamedColor>::const_iterator cit = lyxColorDB.begin();
422 cit != lyxColorDB.end(); ++cit) {
423 LColor::color lc = lcolor.getFromGUIName(cit->getname());
424 if (lc == LColor::inherit) continue;
426 // Create a valid X11 name of the form "#rrggbb"
427 string const hexname = X11hexname(cit->color());
429 if (lcolor.getX11Name(lc) != hexname) {
431 << "FormPreferences::Colors::apply: "
432 << "resetting LColor " << lcolor.getGUIName(lc)
433 << " from \"" << lcolor.getX11Name(lc)
434 << "\" to \"" << hexname << "\"."
437 string const s = lcolor.getLyXName(lc) + string(" ") +
439 parent_.lv_->getLyXFunc()->dispatch(LFUN_SET_COLOR, s);
445 void FormPreferences::Colors::build()
447 dialog_.reset(build_preferences_colors(&parent_));
449 fl_set_object_color(dialog_->button_color,
450 GUI_COLOR_CHOICE, GUI_COLOR_CHOICE);
452 fl_set_object_color(dialog_->dial_hue, GUI_COLOR_HUE_DIAL, FL_BLACK);
453 fl_set_dial_bounds(dialog_->dial_hue, 0.0, 360.0);
454 fl_set_dial_step(dialog_->dial_hue, 1.0);
455 fl_set_dial_return(dialog_->dial_hue, FL_RETURN_CHANGED);
457 fl_set_slider_bounds(dialog_->slider_saturation, 0.0, 1.0);
458 fl_set_slider_step(dialog_->slider_saturation, 0.01);
459 fl_set_slider_return(dialog_->slider_saturation, FL_RETURN_CHANGED);
461 fl_set_slider_bounds(dialog_->slider_value, 0.0, 1.0);
462 fl_set_slider_step(dialog_->slider_value, 0.01);
463 fl_set_slider_return(dialog_->slider_value, FL_RETURN_CHANGED);
465 fl_set_slider_bounds(dialog_->slider_red, 0.0, 255.0);
466 fl_set_slider_step(dialog_->slider_red, 1.0);
467 fl_set_slider_return(dialog_->slider_red, FL_RETURN_CHANGED);
469 fl_set_slider_bounds(dialog_->slider_green, 0.0, 255.0);
470 fl_set_slider_step(dialog_->slider_green, 1.0);
471 fl_set_slider_return(dialog_->slider_green, FL_RETURN_CHANGED);
473 fl_set_slider_bounds(dialog_->slider_blue, 0.0, 255.0);
474 fl_set_slider_step(dialog_->slider_blue, 1.0);
475 fl_set_slider_return(dialog_->slider_blue, FL_RETURN_CHANGED);
477 // set up the feedback mechanism
478 setPrehandler(dialog_->browser_lyx_objs);
479 setPrehandler(dialog_->button_color);
480 setPrehandler(dialog_->button_modify);
481 setPrehandler(dialog_->dial_hue);
482 setPrehandler(dialog_->slider_saturation);
483 setPrehandler(dialog_->slider_value);
484 setPrehandler(dialog_->slider_red);
485 setPrehandler(dialog_->slider_green);
486 setPrehandler(dialog_->slider_blue);
487 setPrehandler(dialog_->radio_rgb);
488 setPrehandler(dialog_->radio_hsv);
492 FormPreferences::Colors::feedback(FL_OBJECT const * const ob) const
494 if (ob == dialog_->browser_lyx_objs)
495 return _("LyX objects that can be assigned a color.");
497 if (ob == dialog_->button_modify)
498 return _("Modify the LyX object's color. Note: you must then \"Apply\" the change.");
500 if (ob == dialog_->dial_hue ||
501 ob == dialog_->slider_saturation ||
502 ob == dialog_->slider_value ||
503 ob == dialog_->slider_red ||
504 ob == dialog_->slider_green ||
505 ob == dialog_->slider_blue)
506 return _("Find a new color.");
508 if (ob == dialog_->radio_rgb || ob == dialog_->radio_hsv)
509 return _("Toggle between RGB and HSV color spaces.");
515 void FormPreferences::Colors::input(FL_OBJECT const * const ob)
517 if (ob == dialog_->browser_lyx_objs) {
520 } else if (ob == dialog_->dial_hue ||
521 ob == dialog_->slider_saturation ||
522 ob == dialog_->slider_value) {
525 } else if (ob == dialog_->slider_red ||
526 ob == dialog_->slider_green ||
527 ob == dialog_->slider_blue) {
530 } else if (ob == dialog_->radio_rgb ||
531 ob == dialog_->radio_hsv) {
534 } else if (ob == dialog_->button_modify) {
540 void FormPreferences::Colors::AdjustVal(int colAdjust, int colParent,
544 fl_getmcolor(colParent, &rgb.r, &rgb.g, &rgb.b);
548 hsv.v = min(1.0, max(0.0, hsv.v));
551 fl_mapcolor(colAdjust, rgb.r, rgb.g, rgb.b);
555 void FormPreferences::Colors::InputBrowserLyX() const
557 vector<NamedColor>::size_type const selLyX =
558 fl_get_browser(dialog_->browser_lyx_objs);
559 if (selLyX < 1) return;
561 // Is the choice an Xforms color...
564 if (selLyX - 1 < xformsColorDB.size()) {
565 vector<XformsColor>::size_type const i = selLyX - 1;
566 col = xformsColorDB[i].color();
568 // or a LyX Logical color?
570 vector<NamedColor>::size_type const i = selLyX - 1 -
571 xformsColorDB.size();
572 col = lyxColorDB[i].color();
575 fl_freeze_form(dialog_->form);
577 fl_mapcolor(GUI_COLOR_CHOICE, col.r, col.g, col.b);
578 fl_redraw_object(dialog_->button_color);
580 // Display either RGB or HSV but not both!
583 // Deactivate the modify button to begin with...
584 setEnabled(dialog_->button_modify, false);
586 fl_unfreeze_form(dialog_->form);
590 void FormPreferences::Colors::InputHSV()
592 double const hue = fl_get_dial_value(dialog_->dial_hue);
593 double const sat = fl_get_slider_value(dialog_->slider_saturation);
594 double const val = fl_get_slider_value(dialog_->slider_value);
596 int const h = int(hue);
597 int const s = int(100.0 * sat);
598 int const v = int(100.0 * val);
600 string const label = tostr(h) + string(", ") + tostr(s) + string(", ") +
602 fl_set_object_label(dialog_->text_color_values, label.c_str());
604 RGBColor col = HSVColor(hue, sat, val);
606 fl_freeze_form(dialog_->form);
608 fl_mapcolor(GUI_COLOR_CHOICE, col.r, col.g, col.b);
609 fl_redraw_object(dialog_->button_color);
611 col = HSVColor(hue, 1.0, 1.0);
612 col.r = max(col.r, 0);
613 fl_mapcolor(GUI_COLOR_HUE_DIAL, col.r, col.g, col.b);
614 fl_redraw_object(dialog_->dial_hue);
616 // Ascertain whether to activate the Modify button.
617 vector<NamedColor>::size_type const selLyX =
618 fl_get_browser(dialog_->browser_lyx_objs);
620 fl_unfreeze_form(dialog_->form);
621 if (selLyX < 1) return;
623 fl_getmcolor(GUI_COLOR_CHOICE, &col.r, &col.g, &col.b);
626 // Is the choice an Xforms color...
627 if (selLyX - 1 < xformsColorDB.size()) {
628 vector<XformsColor>::size_type const i = selLyX - 1;
629 modify = (xformsColorDB[i].color() != col);
631 // or a LyX Logical color?
633 vector<NamedColor>::size_type const i = selLyX - 1 -
634 xformsColorDB.size();
635 modify = (lyxColorDB[i].color() != col);
638 setEnabled(dialog_->button_modify, modify);
642 void FormPreferences::Colors::InputRGB()
644 int const red = int(fl_get_slider_value(dialog_->slider_red));
645 int const green = int(fl_get_slider_value(dialog_->slider_green));
646 int const blue = int(fl_get_slider_value(dialog_->slider_blue));
648 string const label = tostr(red) + string(", ") + tostr(green) +
649 string(", ") + tostr(blue);
650 fl_set_object_label(dialog_->text_color_values, label.c_str());
652 fl_freeze_form(dialog_->form);
654 RGBColor col = RGBColor(red, green, blue);
655 fl_mapcolor(GUI_COLOR_CHOICE, col.r, col.g, col.b);
656 fl_redraw_object(dialog_->button_color);
658 // Ascertain whether to activate the Modify button.
659 vector<NamedColor>::size_type const selLyX =
660 fl_get_browser(dialog_->browser_lyx_objs);
662 fl_unfreeze_form(dialog_->form);
663 if (selLyX < 1) return;
667 // Is the choice an Xforms color...
668 if (selLyX - 1 < xformsColorDB.size()) {
669 vector<XformsColor>::size_type const i = selLyX - 1;
670 modify = (xformsColorDB[i].color() != col);
672 // or a LyX Logical color?
674 vector<NamedColor>::size_type const i = selLyX - 1 -
675 xformsColorDB.size();
676 modify = (lyxColorDB[i].color() != col);
679 setEnabled(dialog_->button_modify, modify);
683 void FormPreferences::Colors::LoadBrowserLyX()
685 if (!dialog_->browser_lyx_objs->visible) return;
687 // First, define the modifiable xforms colors
688 xformsColorDB.clear();
691 xcol.name = _("GUI background");
692 xcol.colorID = FL_COL1;
693 fl_getmcolor(FL_COL1, &xcol.r, &xcol.g, &xcol.b);
695 xformsColorDB.push_back(xcol);
697 xcol.name = _("GUI text");
698 xcol.colorID = FL_BLACK;
699 fl_getmcolor(FL_BLACK, &xcol.r, &xcol.g, &xcol.b);
701 xformsColorDB.push_back(xcol);
703 xcol.name = _("GUI selection");
704 xcol.colorID = FL_YELLOW;
705 fl_getmcolor(FL_YELLOW, &xcol.r, &xcol.g, &xcol.b);
707 xformsColorDB.push_back(xcol);
709 xcol.name = _("GUI pointer");
710 xcol.colorID = GUI_COLOR_CURSOR;
711 fl_getmcolor(GUI_COLOR_CURSOR, &xcol.r, &xcol.g, &xcol.b);
713 xformsColorDB.push_back(xcol);
715 // Now create the the LyX LColors database
717 for (int i=0; i<LColor::ignore; ++i) {
718 LColor::color lc = static_cast<LColor::color>(i);
719 if (lc == LColor::none
720 || lc == LColor::black
721 || lc == LColor::white
723 || lc == LColor::green
724 || lc == LColor::blue
725 || lc == LColor::cyan
726 || lc == LColor::magenta
727 || lc == LColor::yellow
728 || lc == LColor::inherit
729 || lc == LColor::ignore) continue;
731 string const name = lcolor.getX11Name(lc);
732 Display * display = fl_get_display();;
733 Colormap const colormap = fl_state[fl_get_vclass()].colormap;
736 if (XLookupColor(display, colormap, name.c_str(), &xcol, &ccol)
738 lyxerr << "FormPreferences::Colors::LoadBrowserLyX:\n"
739 << "LColor " << lcolor.getLyXName(lc)
740 << ": X can't find color \"" << name
741 << "\". Set to \"black\"!" << endl;
743 string const arg = lcolor.getLyXName(lc) + " black";
744 parent_.lv_->getLyXFunc()->
745 dispatch(LFUN_SET_COLOR, arg);
749 // X has found the color. Now find the "appropriate" X11 name
752 // Note that X stores the RGB values in the range 0 - 65535
753 // whilst we require them in the range 0 - 255.
755 col.r = xcol.red / 256;
756 col.g = xcol.green / 256;
757 col.b = xcol.blue / 256;
759 // Create a valid X11 name of the form "#rrggbb" and change the
760 // LColor X11name to this. Don't want to trigger a redraw,
761 // as we're just changing the name not the RGB values.
762 // Also reset the system_lcolor names, so that we don't output
763 // unnecessary changes.
764 string const hexname = X11hexname(col);
766 if (lcolor.getX11Name(lc) != hexname) {
767 lcolor.setColor(lc, hexname);
768 system_lcolor.setColor(lc, hexname);
771 // Finally, push the color onto the database
772 NamedColor ncol(lcolor.getGUIName(lc), col);
773 lyxColorDB.push_back(ncol);
776 // Now construct the browser
777 FL_OBJECT * colbr = dialog_->browser_lyx_objs;
778 fl_freeze_form(dialog_->form);
779 fl_clear_browser(colbr);
780 for (vector<XformsColor>::const_iterator cit = xformsColorDB.begin();
781 cit != xformsColorDB.end(); ++cit) {
782 fl_addto_browser(colbr, cit->getname().c_str());
784 for (vector<NamedColor>::const_iterator cit = lyxColorDB.begin();
785 cit != lyxColorDB.end(); ++cit) {
786 fl_addto_browser(colbr, cit->getname().c_str());
789 // just to be safe...
790 fl_set_browser_topline(dialog_->browser_lyx_objs, 1);
791 fl_select_browser_line(dialog_->browser_lyx_objs, 1);
792 fl_unfreeze_form(dialog_->form);
798 void FormPreferences::Colors::Modify()
800 vector<NamedColor>::size_type const selLyX =
801 fl_get_browser(dialog_->browser_lyx_objs);
806 fl_getmcolor(GUI_COLOR_CHOICE, &col.r, &col.g, &col.b);
808 // Is the choice an Xforms color...
809 if (selLyX - 1 < xformsColorDB.size()) {
810 vector<XformsColor>::size_type const i = selLyX - 1;
811 xformsColorDB[i].r = col.r;
812 xformsColorDB[i].g = col.g;
813 xformsColorDB[i].b = col.b;
815 // or a LyX Logical color?
817 vector<NamedColor>::size_type const i = selLyX - 1 -
818 xformsColorDB.size();
819 lyxColorDB[i].r = col.r;
820 lyxColorDB[i].g = col.g;
821 lyxColorDB[i].b = col.b;
824 fl_freeze_form(dialog_->form);
825 setEnabled(dialog_->button_modify, false);
826 fl_unfreeze_form(dialog_->form);
830 void FormPreferences::Colors::SwitchColorSpace() const
832 bool const hsv = fl_get_button(dialog_->radio_hsv);
835 fl_getmcolor(GUI_COLOR_CHOICE, &col.r, &col.g, &col.b);
837 fl_freeze_form(dialog_->form);
840 fl_hide_object(dialog_->slider_red);
841 fl_hide_object(dialog_->slider_blue);
842 fl_hide_object(dialog_->slider_green);
843 fl_show_object(dialog_->dial_hue);
844 fl_show_object(dialog_->slider_saturation);
845 fl_show_object(dialog_->slider_value);
847 HSVColor hsv = HSVColor(col);
848 hsv.h = max(hsv.h, 0.0);
850 fl_set_dial_value(dialog_->dial_hue, hsv.h);
851 fl_set_slider_value(dialog_->slider_saturation, hsv.s);
852 fl_set_slider_value(dialog_->slider_value, hsv.v);
854 col = HSVColor(hsv.h, 1.0, 1.0);
855 col.r = max(col.r, 0);
856 fl_mapcolor(GUI_COLOR_HUE_DIAL, col.r, col.g, col.b);
857 fl_redraw_object(dialog_->dial_hue);
859 // Adjust the label a bit, but not the actual values.
860 // Means that toggling from one space to the other has no
861 // effect on the final color.
862 int const h = int(hsv.h);
863 int const s = int(100 * hsv.s);
864 int const v = int(100 * hsv.v);
865 string const label = tostr(h) + ", " + tostr(s) +
867 fl_set_object_label(dialog_->text_color_values, label.c_str());
870 fl_show_object(dialog_->slider_red);
871 fl_show_object(dialog_->slider_blue);
872 fl_show_object(dialog_->slider_green);
873 fl_hide_object(dialog_->dial_hue);
874 fl_hide_object(dialog_->slider_saturation);
875 fl_hide_object(dialog_->slider_value);
877 fl_set_slider_value(dialog_->slider_red, col.r);
878 fl_set_slider_value(dialog_->slider_green, col.g);
879 fl_set_slider_value(dialog_->slider_blue, col.b);
881 // Adjust the label a bit. Same reasoning as above.
882 int const r = int(col.r);
883 int const g = int(col.g);
884 int const b = int(col.b);
885 string const label = tostr(r) + ", " + tostr(g) +
887 fl_set_object_label(dialog_->text_color_values, label.c_str());
890 fl_unfreeze_form(dialog_->form);
893 string const FormPreferences::Colors::X11hexname(RGBColor const & col) const
897 ostr << "#" << std::setbase(16) << setfill('0')
902 return ostr.str().c_str();
906 FormPreferences::Converters::Converters(FormPreferences & p)
911 FD_preferences_converters const * FormPreferences::Converters::dialog()
913 return dialog_.get();
917 void FormPreferences::Converters::apply() const
919 converters = local_converters;
920 converters.update(formats);
921 converters.buildGraph();
925 void FormPreferences::Converters::build()
927 dialog_.reset(build_preferences_converters(&parent_));
929 fl_set_input_return(dialog_->input_converter, FL_RETURN_CHANGED);
930 fl_set_input_return(dialog_->input_flags, FL_RETURN_CHANGED);
932 // set up the feedback mechanism
933 setPrehandler(dialog_->browser_all);
934 setPrehandler(dialog_->button_delete);
935 setPrehandler(dialog_->button_add);
936 setPrehandler(dialog_->input_converter);
937 setPrehandler(dialog_->choice_from);
938 setPrehandler(dialog_->choice_to);
939 setPrehandler(dialog_->input_flags);
944 FormPreferences::Converters::feedback(FL_OBJECT const * const ob) const
946 if (ob == dialog_->browser_all)
947 return _("All the currently defined converters known to LyX.");
949 if (ob == dialog_->choice_from)
950 return _("Convert \"from\" this format");
952 if (ob == dialog_->choice_to)
953 return _("Convert \"to\" this format");
955 if (ob == dialog_->input_converter)
956 return _("The conversion command. $$i is the input file name, "
957 "$$b is the file name without its extension and $$o is "
958 "the name of the output file. $$s can be used as path to "
959 "LyX's own collection of conversion scripts.");
961 if (ob == dialog_->input_flags)
962 return _("Extra information for the Converter class, whether and "
963 "how to parse the result, and various other things.");
965 if (ob == dialog_->button_delete)
966 return _("Remove the current converter from the list of available "
967 "converters. Note: you must then \"Apply\" the change.");
969 if (ob == dialog_->button_add) {
970 if (string(ob->label) == _("Add"))
971 return _("Add the current converter to the list of available "
972 "converters. Note: you must then \"Apply\" the change.");
974 return _("Modify the contents of the current converter. "
975 "Note: you must then \"Apply\" the change.");
982 bool FormPreferences::Converters::input(FL_OBJECT const * const ob)
984 if (ob == dialog_->browser_all)
987 if (ob == dialog_->choice_from
988 || ob == dialog_->choice_to
989 || ob == dialog_->input_converter
990 || ob == dialog_->input_flags)
993 if (ob == dialog_->button_add)
996 if (ob == dialog_->button_delete)
1003 void FormPreferences::Converters::update()
1005 local_converters = converters;
1006 local_converters.update(local_formats);
1011 void FormPreferences::Converters::UpdateBrowser()
1013 local_converters.sort();
1015 fl_freeze_form(dialog_->form);
1016 fl_clear_browser(dialog_->browser_all);
1017 for (::Converters::const_iterator cit = local_converters.begin();
1018 cit != local_converters.end(); ++cit) {
1019 string const name = cit->From->prettyname() + " -> "
1020 + cit->To->prettyname();
1021 fl_addto_browser(dialog_->browser_all, name.c_str());
1024 fl_unfreeze_form(dialog_->form);
1028 bool FormPreferences::Converters::Add()
1030 string const from = GetFrom();
1031 string const to = GetTo();
1032 string const command = fl_get_input(dialog_->input_converter);
1033 string const flags = fl_get_input(dialog_->input_flags);
1035 Converter const * old = local_converters.getConverter(from, to);
1036 local_converters.add(from, to, command, flags);
1038 local_converters.updateLast(local_formats);
1041 setEnabled(dialog_->button_add, false);
1047 bool FormPreferences::Converters::Browser()
1049 int const i = fl_get_browser(dialog_->browser_all);
1050 if (i <= 0) return false;
1052 fl_freeze_form(dialog_->form);
1054 Converter const & c = local_converters.get(i - 1);
1055 int j = local_formats.getNumber(c.from);
1057 fl_set_choice(dialog_->choice_from, j + 1);
1059 j = local_formats.getNumber(c.to);
1061 fl_set_choice(dialog_->choice_to, j + 1);
1063 fl_set_input(dialog_->input_converter, c.command.c_str());
1064 fl_set_input(dialog_->input_flags, c.flags.c_str());
1066 fl_set_object_label(dialog_->button_add, idex(_("Modify|#M")));
1067 fl_set_button_shortcut(dialog_->button_add, scex(_("Modify|#M")), 1);
1069 setEnabled(dialog_->button_add, false);
1070 setEnabled(dialog_->button_delete, true);
1072 fl_unfreeze_form(dialog_->form);
1077 bool FormPreferences::Converters::erase()
1079 string const from = GetFrom();
1080 string const to = GetTo();
1082 local_converters.erase(from, to);
1088 bool FormPreferences::Converters::Input()
1090 string const from = GetFrom();
1091 string const to = GetTo();
1092 int const sel = local_converters.getNumber(from, to);
1094 fl_freeze_form(dialog_->form);
1097 fl_set_object_label(dialog_->button_add, idex(_("Add|#A")));
1098 fl_set_button_shortcut(dialog_->button_add,
1099 scex(_("Add|#A")), 1);
1101 fl_deselect_browser(dialog_->browser_all);
1102 setEnabled(dialog_->button_delete, false);
1105 fl_set_object_label(dialog_->button_add, idex(_("Modify|#M")));
1106 fl_set_button_shortcut(dialog_->button_add,
1107 scex(_("Modify|#M")), 1);
1109 int top = max(sel-5, 0);
1110 fl_set_browser_topline(dialog_->browser_all, top);
1111 fl_select_browser_line(dialog_->browser_all, sel+1);
1112 setEnabled(dialog_->button_delete, true);
1115 string const command = rtrim(fl_get_input(dialog_->input_converter));
1116 bool const enable = !(command.empty() || from == to);
1117 setEnabled(dialog_->button_add, enable);
1119 fl_unfreeze_form(dialog_->form);
1124 string const FormPreferences::Converters::GetFrom() const
1126 ::Formats::FormatList::size_type const i =
1127 fl_get_choice(dialog_->choice_from);
1129 if (i > 0 && i <= local_formats.size())
1130 return local_formats.get(i - 1).name();
1132 lyxerr << "FormPreferences::Converters::GetFrom: No choice!" << endl;
1137 string const FormPreferences::Converters::GetTo() const
1139 ::Formats::FormatList::size_type const i =
1140 fl_get_choice(dialog_->choice_to);
1142 if (i > 0 && i <= local_formats.size())
1143 return local_formats.get(i - 1).name();
1145 lyxerr << "FormPreferences::Converters::GetTo: No choice!" << endl;
1150 void FormPreferences::Converters::UpdateChoices() const
1153 for (::Formats::const_iterator cit = local_formats.begin();
1154 cit != local_formats.end(); ++cit) {
1155 if (!choice.empty())
1159 choice += cit->prettyname();
1163 fl_clear_choice(dialog_->choice_from);
1164 fl_addto_choice(dialog_->choice_from, choice.c_str());
1166 fl_clear_choice(dialog_->choice_to);
1167 fl_addto_choice(dialog_->choice_to, choice.c_str());
1171 FormPreferences::Formats::Formats(FormPreferences & p)
1176 FD_preferences_formats const * FormPreferences::Formats::dialog()
1178 return dialog_.get();
1182 void FormPreferences::Formats::apply() const
1184 formats = local_formats;
1188 void FormPreferences::Formats::build()
1190 dialog_.reset(build_preferences_formats(&parent_));
1192 fl_set_input_return(dialog_->input_format, FL_RETURN_CHANGED);
1193 fl_set_input_return(dialog_->input_viewer, FL_RETURN_CHANGED);
1194 fl_set_input_return(dialog_->input_shrtcut, FL_RETURN_CHANGED);
1195 fl_set_input_return(dialog_->input_gui_name, FL_RETURN_CHANGED);
1196 fl_set_input_return(dialog_->input_extension, FL_RETURN_CHANGED);
1198 fl_set_input_filter(dialog_->input_format, fl_lowercase_filter);
1200 // set up the feedback mechanism
1201 setPrehandler(dialog_->browser_all);
1202 setPrehandler(dialog_->input_format);
1203 setPrehandler(dialog_->input_gui_name);
1204 setPrehandler(dialog_->button_delete);
1205 setPrehandler(dialog_->button_add);
1206 setPrehandler(dialog_->input_extension);
1207 setPrehandler(dialog_->input_viewer);
1208 setPrehandler(dialog_->input_shrtcut);
1213 FormPreferences::Formats::feedback(FL_OBJECT const * const ob) const
1215 if (ob == dialog_->browser_all)
1216 return _("All the currently defined formats known to LyX.");
1218 if (ob == dialog_->input_format)
1219 return _("The format identifier.");
1221 if (ob == dialog_->input_gui_name)
1222 return _("The format name as it will appear in the menus.");
1224 if (ob == dialog_->input_shrtcut)
1225 return _("The keyboard accelerator. Use a letter in the GUI name. "
1228 if (ob == dialog_->input_extension)
1229 return _("Used to recognize the file. E.g., ps, pdf, tex.");
1231 if (ob == dialog_->input_viewer)
1232 return _("The command used to launch the viewer application.");
1234 if (ob == dialog_->button_delete)
1235 return _("Remove the current format from the list of available "
1236 "formats. Note: you must then \"Apply\" the change.");
1238 if (ob == dialog_->button_add) {
1239 if (string(ob->label) == _("Add"))
1240 return _("Add the current format to the list of available "
1241 "formats. Note: you must then \"Apply\" the change.");
1243 return _("Modify the contents of the current format. Note: "
1244 "you must then \"Apply\" the change.");
1251 bool FormPreferences::Formats::input(FL_OBJECT const * const ob)
1253 if (ob == dialog_->browser_all)
1256 if (ob == dialog_->input_format
1257 || ob == dialog_->input_gui_name
1258 || ob == dialog_->input_shrtcut
1259 || ob == dialog_->input_extension
1260 || ob == dialog_->input_viewer)
1263 if (ob == dialog_->button_add)
1266 if (ob == dialog_->button_delete)
1273 void FormPreferences::Formats::update()
1275 local_formats = formats;
1280 void FormPreferences::Formats::UpdateBrowser()
1282 local_formats.sort();
1284 fl_freeze_form(dialog_->form);
1285 fl_deselect_browser(dialog_->browser_all);
1286 fl_clear_browser(dialog_->browser_all);
1287 for (::Formats::const_iterator cit = local_formats.begin();
1288 cit != local_formats.end(); ++cit)
1289 fl_addto_browser(dialog_->browser_all,
1290 cit->prettyname().c_str());
1293 fl_unfreeze_form(dialog_->form);
1295 // Mustn't forget to update the Formats available to the converters_
1296 parent_.converters_.UpdateChoices();
1297 local_converters.update(local_formats);
1301 bool FormPreferences::Formats::Add()
1303 string const name = fl_get_input(dialog_->input_format);
1304 string const prettyname = fl_get_input(dialog_->input_gui_name);
1305 string const extension = fl_get_input(dialog_->input_extension);
1306 string const shortcut = fl_get_input(dialog_->input_shrtcut);
1307 string const viewer = fl_get_input(dialog_->input_viewer);
1309 Format const * old = local_formats.getFormat(name);
1310 string const old_prettyname = old ? old->prettyname() : string();
1311 local_formats.add(name, extension, prettyname, shortcut);
1312 local_formats.setViewer(name, viewer);
1313 if (!old || prettyname != old_prettyname) {
1316 parent_.converters_.UpdateBrowser();
1318 setEnabled(dialog_->button_add, false);
1324 bool FormPreferences::Formats::Browser()
1326 int const i = fl_get_browser(dialog_->browser_all);
1330 fl_freeze_form(dialog_->form);
1332 Format const & f = local_formats.get(i - 1);
1334 fl_set_input(dialog_->input_format, f.name().c_str());
1335 fl_set_input(dialog_->input_gui_name, f.prettyname().c_str());
1336 fl_set_input(dialog_->input_shrtcut, f.shortcut().c_str());
1337 fl_set_input(dialog_->input_extension, f.extension().c_str());
1338 fl_set_input(dialog_->input_viewer, f.viewer().c_str());
1340 fl_set_object_label(dialog_->button_add, idex(_("Modify|#M")));
1341 fl_set_button_shortcut(dialog_->button_add, scex(_("Modify|#M")), 1);
1343 setEnabled(dialog_->button_add, false);
1344 setEnabled(dialog_->button_delete, true);
1346 fl_unfreeze_form(dialog_->form);
1351 bool FormPreferences::Formats::erase()
1353 string const name = fl_get_input(dialog_->input_format);
1355 if (local_converters.formatIsUsed(name)) {
1356 parent_.postWarning(_("Cannot remove a Format used by a Converter. "
1357 "Remove the converter first."));
1358 setEnabled(dialog_->button_delete, false);
1362 local_formats.erase(name);
1368 bool FormPreferences::Formats::Input()
1370 string const name = fl_get_input(dialog_->input_format);
1371 int const sel = local_formats.getNumber(name);
1372 fl_freeze_form(dialog_->form);
1375 fl_set_object_label(dialog_->button_add,
1377 fl_set_button_shortcut(dialog_->button_add,
1378 scex(_("Add|#A")), 1);
1380 fl_deselect_browser(dialog_->browser_all);
1381 setEnabled(dialog_->button_delete, false);
1384 fl_set_object_label(dialog_->button_add,
1385 idex(_("Modify|#M")));
1386 fl_set_button_shortcut(dialog_->button_add,
1387 scex(_("Modify|#M")), 1);
1389 int const top = max(sel-5, 0);
1390 fl_set_browser_topline(dialog_->browser_all, top);
1391 fl_select_browser_line(dialog_->browser_all, sel+1);
1393 setEnabled(dialog_->button_add, true);
1394 setEnabled(dialog_->button_delete, true);
1397 string const prettyname = fl_get_input(dialog_->input_gui_name);
1398 bool const enable = !(name.empty() || prettyname.empty());
1399 setEnabled(dialog_->button_add, enable);
1401 fl_unfreeze_form(dialog_->form);
1406 FormPreferences::InputsMisc::InputsMisc(FormPreferences & p)
1411 FD_preferences_inputs_misc const * FormPreferences::InputsMisc::dialog()
1413 return dialog_.get();
1417 void FormPreferences::InputsMisc::apply() const
1419 lyxrc.date_insert_format =
1420 fl_get_input(dialog_->input_date_format);
1424 void FormPreferences::InputsMisc::build()
1426 dialog_.reset(build_preferences_inputs_misc(&parent_));
1428 fl_set_input_return(dialog_->input_date_format, FL_RETURN_CHANGED);
1430 // set up the feedback mechanism
1431 setPrehandler(dialog_->input_date_format);
1436 FormPreferences::InputsMisc::feedback(FL_OBJECT const * const ob) const
1438 if (ob == dialog_->input_date_format)
1439 return lyxrc.getDescription(LyXRC::RC_DATE_INSERT_FORMAT);
1444 void FormPreferences::InputsMisc::update()
1446 fl_set_input(dialog_->input_date_format,
1447 lyxrc.date_insert_format.c_str());
1451 FormPreferences::Interface::Interface(FormPreferences & p)
1456 FD_preferences_interface const * FormPreferences::Interface::dialog()
1458 return dialog_.get();
1462 void FormPreferences::Interface::apply() const
1464 lyxrc.popup_normal_font =
1465 fl_get_input(dialog_->input_popup_normal_font);
1466 lyxrc.popup_bold_font = fl_get_input(dialog_->input_popup_bold_font);
1467 lyxrc.popup_font_encoding =
1468 fl_get_input(dialog_->input_popup_font_encoding);
1469 lyxrc.bind_file = fl_get_input(dialog_->input_bind_file);
1470 lyxrc.ui_file = fl_get_input(dialog_->input_ui_file);
1471 lyxrc.override_x_deadkeys =
1472 fl_get_button(dialog_->check_override_x_dead_keys);
1476 void FormPreferences::Interface::build()
1478 dialog_.reset(build_preferences_interface(&parent_));
1480 fl_set_input_return(dialog_->input_popup_normal_font, FL_RETURN_CHANGED);
1481 fl_set_input_return(dialog_->input_popup_bold_font, FL_RETURN_CHANGED);
1482 fl_set_input_return(dialog_->input_popup_font_encoding, FL_RETURN_CHANGED);
1483 fl_set_input_return(dialog_->input_bind_file, FL_RETURN_CHANGED);
1484 fl_set_input_return(dialog_->input_ui_file, FL_RETURN_CHANGED);
1486 // set up the feedback mechanism
1487 setPrehandler(dialog_->input_popup_normal_font);
1488 setPrehandler(dialog_->input_popup_bold_font);
1489 setPrehandler(dialog_->input_popup_font_encoding);
1490 setPrehandler(dialog_->input_bind_file);
1491 setPrehandler(dialog_->button_bind_file_browse);
1492 setPrehandler(dialog_->input_ui_file);
1493 setPrehandler(dialog_->button_ui_file_browse);
1494 setPrehandler(dialog_->check_override_x_dead_keys);
1499 FormPreferences::Interface::feedback(FL_OBJECT const * const ob) const
1501 if (ob == dialog_->input_popup_normal_font)
1502 return lyxrc.getDescription(LyXRC::RC_POPUP_NORMAL_FONT);
1503 if (ob == dialog_->input_popup_bold_font)
1504 return lyxrc.getDescription(LyXRC::RC_POPUP_BOLD_FONT);
1505 if (ob == dialog_->input_popup_font_encoding)
1506 return lyxrc.getDescription(LyXRC::RC_POPUP_FONT_ENCODING);
1507 if (ob == dialog_->input_bind_file)
1508 return lyxrc.getDescription(LyXRC::RC_BINDFILE);
1509 if (ob == dialog_->input_ui_file)
1510 return lyxrc.getDescription(LyXRC::RC_UIFILE);
1511 if (ob == dialog_->check_override_x_dead_keys)
1512 return lyxrc.getDescription(LyXRC::RC_OVERRIDE_X_DEADKEYS);
1517 bool FormPreferences::Interface::input(FL_OBJECT const * const ob)
1519 if (ob == dialog_->button_bind_file_browse) {
1520 string dir = AddName(system_lyxdir, "bind");
1521 string name = _("Sys Bind|#S#s");
1522 pair<string,string> dir1(name, dir);
1524 dir = AddName(user_lyxdir, "bind");
1525 name = _("User Bind|#U#u");
1526 pair<string,string> dir2(name, dir);
1528 parent_.browse(dialog_->input_bind_file,
1529 _("Bind file"), "*.bind", dir1, dir2);
1531 } else if (ob == dialog_->button_ui_file_browse) {
1532 string dir = AddName(system_lyxdir, "ui");
1533 string name = _("Sys UI|#S#s");
1534 pair<string,string> dir1(name, dir);
1536 dir = AddName(user_lyxdir, "ui");
1537 name = _("User UI|#U#u");
1538 pair<string,string> dir2(name, dir);
1540 parent_.browse(dialog_->input_ui_file,
1541 _("UI file"), "*.ui", dir1, dir2);
1548 void FormPreferences::Interface::update()
1550 fl_set_input(dialog_->input_popup_normal_font,
1551 lyxrc.popup_normal_font.c_str());
1552 fl_set_input(dialog_->input_popup_bold_font,
1553 lyxrc.popup_bold_font.c_str());
1554 fl_set_input(dialog_->input_popup_font_encoding,
1555 lyxrc.popup_font_encoding.c_str());
1556 fl_set_input(dialog_->input_bind_file,
1557 lyxrc.bind_file.c_str());
1558 fl_set_input(dialog_->input_ui_file,
1559 lyxrc.ui_file.c_str());
1560 fl_set_button(dialog_->check_override_x_dead_keys,
1561 lyxrc.override_x_deadkeys);
1565 FormPreferences::Language::Language(FormPreferences & p)
1570 FD_preferences_language const * FormPreferences::Language::dialog()
1572 return dialog_.get();
1576 void FormPreferences::Language::apply()
1578 int const pos = combo_default_lang->get();
1579 lyxrc.default_language = lang_[pos-1];
1581 int button = fl_get_button(dialog_->check_use_kbmap);
1582 string const name_1 = fl_get_input(dialog_->input_kbmap1);
1583 string const name_2 = fl_get_input(dialog_->input_kbmap2);
1585 button = !(name_1.empty() && name_2.empty());
1586 lyxrc.use_kbmap = static_cast<bool>(button);
1588 if (lyxrc.use_kbmap) {
1589 lyxrc.primary_kbmap = name_1;
1590 lyxrc.secondary_kbmap = name_2;
1593 button = fl_get_button(dialog_->check_rtl_support);
1594 lyxrc.rtl_support = static_cast<bool>(button);
1596 button = fl_get_button(dialog_->check_mark_foreign);
1597 lyxrc.mark_foreign_language = static_cast<bool>(button);
1599 button = fl_get_button(dialog_->check_auto_begin);
1600 lyxrc.language_auto_begin = static_cast<bool>(button);
1602 button = fl_get_button(dialog_->check_auto_end);
1603 lyxrc.language_auto_end = static_cast<bool>(button);
1605 button = fl_get_button(dialog_->check_use_babel);
1606 lyxrc.language_use_babel = static_cast<bool>(button);
1608 button = fl_get_button(dialog_->check_global_options);
1609 lyxrc.language_global_options = static_cast<bool>(button);
1611 lyxrc.language_package = fl_get_input(dialog_->input_package);
1612 lyxrc.language_command_begin = fl_get_input(dialog_->input_command_begin);
1613 lyxrc.language_command_end = fl_get_input(dialog_->input_command_end);
1615 // Ensure that all is self-consistent.
1620 void FormPreferences::Language::build()
1622 dialog_.reset(build_preferences_language(&parent_));
1624 fl_set_input_return(dialog_->input_package, FL_RETURN_CHANGED);
1625 fl_set_input_return(dialog_->input_command_begin, FL_RETURN_CHANGED);
1626 fl_set_input_return(dialog_->input_command_end, FL_RETURN_CHANGED);
1628 // Store the lang identifiers for later
1629 vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
1630 lang_ = getSecond(langs);
1632 // The default_language is a combo-box and has to be inserted manually
1633 fl_freeze_form(dialog_->form);
1634 fl_addto_form(dialog_->form);
1636 FL_OBJECT * obj = dialog_->choice_default_lang;
1637 fl_deactivate_object(dialog_->choice_default_lang);
1638 combo_default_lang.reset(new Combox(FL_COMBOX_DROPLIST));
1639 combo_default_lang->add(obj->x, obj->y, obj->w, obj->h, 400,
1640 parent_.lang_opts_tab_->tabfolder_inner,
1641 parent_.dialog_->tabfolder_prefs);
1642 combo_default_lang->shortcut("#L",1);
1643 combo_default_lang->setcallback(ComboCB, &parent_);
1645 vector<frnt::LanguagePair>::const_iterator lit = langs.begin();
1646 vector<frnt::LanguagePair>::const_iterator lend = langs.end();
1647 for (; lit != lend; ++lit) {
1648 combo_default_lang->addto(lit->first);
1650 combo_default_lang->select(1);
1653 fl_unfreeze_form(dialog_->form);
1655 // set up the feedback mechanism
1656 setPrehandler(dialog_->input_package);
1657 setPrehandler(dialog_->check_use_kbmap);
1659 // This is safe, as nothing is done to the pointer, other than
1660 // to use its address in a block-if statement.
1661 // No it's not! Leads to crash.
1663 // reinterpret_cast<FL_OBJECT *>(combo_default_lang),
1664 // C_FormPreferencesFeedbackCB);
1666 setPrehandler(dialog_->input_kbmap1);
1667 setPrehandler(dialog_->input_kbmap2);
1668 setPrehandler(dialog_->check_rtl_support);
1669 setPrehandler(dialog_->check_mark_foreign);
1670 setPrehandler(dialog_->check_auto_begin);
1671 setPrehandler(dialog_->check_auto_end);
1672 setPrehandler(dialog_->check_use_babel);
1673 setPrehandler(dialog_->check_global_options);
1674 setPrehandler(dialog_->input_command_begin);
1675 setPrehandler(dialog_->input_command_end);
1677 // Activate/Deactivate the input fields dependent on the state of the
1684 FormPreferences::Language::feedback(FL_OBJECT const * const ob) const
1686 if (reinterpret_cast<Combox const *>(ob) == combo_default_lang.get())
1687 return lyxrc.getDescription(LyXRC::RC_DEFAULT_LANGUAGE);
1688 if (ob == dialog_->check_use_kbmap)
1689 return lyxrc.getDescription(LyXRC::RC_KBMAP);
1690 if (ob == dialog_->input_kbmap1)
1691 return lyxrc.getDescription(LyXRC::RC_KBMAP_PRIMARY);
1692 if (ob == dialog_->input_kbmap2)
1693 return lyxrc.getDescription(LyXRC::RC_KBMAP_SECONDARY);
1694 if (ob == dialog_->check_rtl_support)
1695 return lyxrc.getDescription(LyXRC::RC_RTL_SUPPORT);
1696 if (ob == dialog_->check_mark_foreign)
1697 return lyxrc.getDescription(LyXRC::RC_MARK_FOREIGN_LANGUAGE);
1698 if (ob == dialog_->check_auto_begin)
1699 return lyxrc.getDescription(LyXRC::RC_LANGUAGE_AUTO_BEGIN);
1700 if (ob == dialog_->check_auto_end)
1701 return lyxrc.getDescription(LyXRC::RC_LANGUAGE_AUTO_END);
1702 if (ob == dialog_->check_use_babel)
1703 return lyxrc.getDescription(LyXRC::RC_LANGUAGE_USE_BABEL);
1704 if (ob == dialog_->check_global_options)
1705 return lyxrc.getDescription(LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS);
1706 if (ob == dialog_->input_package)
1707 return lyxrc.getDescription(LyXRC::RC_LANGUAGE_PACKAGE);
1708 if (ob == dialog_->input_command_begin)
1709 return lyxrc.getDescription(LyXRC::RC_LANGUAGE_COMMAND_BEGIN);
1710 if (ob == dialog_->input_command_end)
1711 return lyxrc.getDescription(LyXRC::RC_LANGUAGE_COMMAND_END);
1716 bool FormPreferences::Language::input(FL_OBJECT const * const ob)
1718 bool activate = true;
1720 // !ob if function is called from Language::build() to de/activate
1722 // otherwise the function is called by an xforms CB via input().
1723 if (!ob || ob == dialog_->check_use_kbmap) {
1724 bool const enable = fl_get_button(dialog_->check_use_kbmap);
1725 setEnabled(dialog_->button_kbmap1_browse, enable);
1726 setEnabled(dialog_->button_kbmap2_browse, enable);
1727 setEnabled(dialog_->input_kbmap1, enable);
1728 setEnabled(dialog_->input_kbmap2, enable);
1731 if (ob == dialog_->button_kbmap1_browse) {
1732 string const dir = AddName(system_lyxdir, "kbd");
1733 string const name = _("Key maps|#K#k");
1734 pair<string, string> dir1(name, dir);
1736 parent_.browse(dialog_->input_kbmap1,
1737 _("Keyboard map"), "*.kmap", dir1);
1738 } else if (ob == dialog_->button_kbmap2_browse) {
1739 string const dir = AddName(system_lyxdir, "kbd");
1740 string const name = _("Key maps|#K#k");
1741 pair<string, string> dir1(name, dir);
1743 parent_.browse(dialog_->input_kbmap2,
1744 _("Keyboard map"), "*.kmap", dir1);
1751 void FormPreferences::Language::update()
1753 fl_set_button(dialog_->check_use_kbmap,
1756 int const pos = int(findPos(lang_, lyxrc.default_language));
1757 combo_default_lang->select(pos + 1);
1759 if (lyxrc.use_kbmap) {
1760 fl_set_input(dialog_->input_kbmap1,
1761 lyxrc.primary_kbmap.c_str());
1762 fl_set_input(dialog_->input_kbmap2,
1763 lyxrc.secondary_kbmap.c_str());
1765 fl_set_input(dialog_->input_kbmap1, "");
1766 fl_set_input(dialog_->input_kbmap2, "");
1769 fl_set_button(dialog_->check_rtl_support, lyxrc.rtl_support);
1770 fl_set_button(dialog_->check_mark_foreign,
1771 lyxrc.mark_foreign_language);
1772 fl_set_button(dialog_->check_auto_begin, lyxrc.language_auto_begin);
1773 fl_set_button(dialog_->check_auto_end, lyxrc.language_auto_end);
1774 fl_set_button(dialog_->check_use_babel, lyxrc.language_use_babel);
1775 fl_set_button(dialog_->check_global_options,
1776 lyxrc.language_global_options);
1778 fl_set_input(dialog_->input_package,
1779 lyxrc.language_package.c_str());
1780 fl_set_input(dialog_->input_command_begin,
1781 lyxrc.language_command_begin.c_str());
1782 fl_set_input(dialog_->input_command_end,
1783 lyxrc.language_command_end.c_str());
1785 // Activate/Deactivate the input fields dependent on the state of the
1791 void FormPreferences::Language::ComboCB(int, void * v, Combox * combox)
1793 FormPreferences * pre = static_cast<FormPreferences*>(v);
1794 // This is safe, as nothing is done to the pointer, other than
1795 // to use its address in a block-if statement.
1796 pre->bc().valid(pre->input(reinterpret_cast<FL_OBJECT *>(combox), 0));
1800 FormPreferences::LnFmisc::LnFmisc(FormPreferences & p)
1805 FD_preferences_lnf_misc const * FormPreferences::LnFmisc::dialog()
1807 return dialog_.get();
1811 void FormPreferences::LnFmisc::apply() const
1813 lyxrc.auto_region_delete =
1814 fl_get_button(dialog_->check_auto_region_delete);
1815 lyxrc.cursor_follows_scrollbar =
1816 fl_get_button(dialog_->check_cursor_follows_scrollbar);
1817 lyxrc.dialogs_iconify_with_main =
1818 fl_get_button(dialog_->check_dialogs_iconify_with_main);
1819 lyxrc.preview = fl_get_button(dialog_->check_preview_latex);
1820 lyxrc.autosave = static_cast<unsigned int>
1821 (fl_get_counter_value(dialog_->counter_autosave));
1822 lyxrc.wheel_jump = static_cast<unsigned int>
1823 (fl_get_counter_value(dialog_->counter_wm_jump));
1825 string const old_value = lyxrc.display_graphics;
1826 if (fl_get_button(dialog_->radio_display_monochrome)) {
1827 lyxrc.display_graphics = "mono";
1828 } else if (fl_get_button(dialog_->radio_display_grayscale)) {
1829 lyxrc.display_graphics = "gray";
1830 } else if (fl_get_button(dialog_->radio_display_color)) {
1831 lyxrc.display_graphics = "color";
1833 lyxrc.display_graphics = "no";
1836 #ifdef WITH_WARNINGS
1837 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
1840 if (old_value != lyxrc.display_graphics) {
1841 grfx::GCache & gc = grfx::GCache::get();
1848 void FormPreferences::LnFmisc::build()
1850 dialog_.reset(build_preferences_lnf_misc(&parent_));
1852 fl_set_counter_step(dialog_->counter_autosave, 1, 10);
1853 fl_set_counter_step(dialog_->counter_wm_jump, 1, 10);
1855 fl_set_counter_return(dialog_->counter_autosave, FL_RETURN_CHANGED);
1856 fl_set_counter_return(dialog_->counter_wm_jump, FL_RETURN_CHANGED);
1858 // set up the feedback mechanism
1859 setPrehandler(dialog_->check_auto_region_delete);
1860 setPrehandler(dialog_->counter_autosave);
1861 setPrehandler(dialog_->check_cursor_follows_scrollbar);
1862 setPrehandler(dialog_->check_dialogs_iconify_with_main);
1863 setPrehandler(dialog_->check_preview_latex);
1864 setPrehandler(dialog_->counter_wm_jump);
1865 setPrehandler(dialog_->radio_display_monochrome);
1866 setPrehandler(dialog_->radio_display_grayscale);
1867 setPrehandler(dialog_->radio_display_color);
1868 setPrehandler(dialog_->radio_no_display);
1873 FormPreferences::LnFmisc::feedback(FL_OBJECT const * const ob) const
1875 if (ob == dialog_->check_auto_region_delete)
1876 return lyxrc.getDescription(LyXRC::RC_AUTOREGIONDELETE);
1877 if (ob == dialog_->check_cursor_follows_scrollbar)
1878 return lyxrc.getDescription(LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR);
1879 if (ob == dialog_->check_dialogs_iconify_with_main)
1880 return lyxrc.getDescription(LyXRC::RC_DIALOGS_ICONIFY_WITH_MAIN);
1881 if (ob == dialog_->check_preview_latex)
1882 return lyxrc.getDescription(LyXRC::RC_PREVIEW);
1883 if (ob == dialog_->counter_autosave)
1884 return lyxrc.getDescription(LyXRC::RC_AUTOSAVE);
1885 if (ob == dialog_->counter_wm_jump)
1886 return lyxrc.getDescription(LyXRC::RC_WHEEL_JUMP);
1887 if (ob == dialog_->radio_display_monochrome ||
1888 ob == dialog_->radio_display_grayscale ||
1889 ob == dialog_->radio_display_color ||
1890 ob == dialog_->radio_no_display)
1891 return lyxrc.getDescription(LyXRC::RC_DISPLAY_GRAPHICS);
1896 void FormPreferences::LnFmisc::update()
1898 fl_set_button(dialog_->check_auto_region_delete,
1899 lyxrc.auto_region_delete);
1900 fl_set_button(dialog_->check_cursor_follows_scrollbar,
1901 lyxrc.cursor_follows_scrollbar);
1902 fl_set_button(dialog_->check_dialogs_iconify_with_main,
1903 lyxrc.dialogs_iconify_with_main);
1904 fl_set_button(dialog_->check_preview_latex,
1906 fl_set_counter_value(dialog_->counter_autosave, lyxrc.autosave);
1907 fl_set_counter_value(dialog_->counter_wm_jump, lyxrc.wheel_jump);
1909 if (lyxrc.display_graphics == "mono") {
1910 fl_set_button(dialog_->radio_display_monochrome, 1);
1911 } else if (lyxrc.display_graphics == "gray") {
1912 fl_set_button(dialog_->radio_display_grayscale, 1);
1913 } else if (lyxrc.display_graphics == "color") {
1914 fl_set_button(dialog_->radio_display_color, 1);
1916 fl_set_button(dialog_->radio_no_display, 1);
1921 FormPreferences::OutputsMisc::OutputsMisc(FormPreferences & p)
1926 FD_preferences_outputs_misc const * FormPreferences::OutputsMisc::dialog()
1928 return dialog_.get();
1932 void FormPreferences::OutputsMisc::apply() const
1934 lyxrc.ascii_linelen = static_cast<unsigned int>
1935 (fl_get_counter_value(dialog_->counter_line_len));
1936 lyxrc.fontenc = fl_get_input(dialog_->input_tex_encoding);
1939 fl_get_choice(dialog_->choice_default_papersize) - 1;
1940 lyxrc.default_papersize = static_cast<BufferParams::PAPER_SIZE>(choice);
1942 lyxrc.ascii_roff_command = fl_get_input(dialog_->input_ascii_roff);
1943 lyxrc.chktex_command = fl_get_input(dialog_->input_checktex);
1944 lyxrc.view_dvi_paper_option = fl_get_input(dialog_->input_paperoption);
1945 lyxrc.auto_reset_options = fl_get_button(dialog_->check_autoreset_classopt);
1949 void FormPreferences::OutputsMisc::build()
1951 dialog_.reset(build_preferences_outputs_misc(&parent_));
1953 fl_set_counter_step(dialog_->counter_line_len, 1, 10);
1955 fl_set_counter_return(dialog_->counter_line_len, FL_RETURN_CHANGED);
1956 fl_set_input_return(dialog_->input_tex_encoding, FL_RETURN_CHANGED);
1957 fl_set_input_return(dialog_->input_ascii_roff, FL_RETURN_CHANGED);
1958 fl_set_input_return(dialog_->input_checktex, FL_RETURN_CHANGED);
1959 fl_set_input_return(dialog_->input_paperoption, FL_RETURN_CHANGED);
1961 fl_addto_choice(dialog_->choice_default_papersize,
1962 _(" default | US letter | US legal | US executive | A3 | A4 | A5 | B5 "));
1964 // set up the feedback mechanism
1965 setPrehandler(dialog_->counter_line_len);
1966 setPrehandler(dialog_->input_tex_encoding);
1967 setPrehandler(dialog_->choice_default_papersize);
1968 setPrehandler(dialog_->input_ascii_roff);
1969 setPrehandler(dialog_->input_checktex);
1970 setPrehandler(dialog_->input_paperoption);
1971 setPrehandler(dialog_->check_autoreset_classopt);
1976 FormPreferences::OutputsMisc::feedback(FL_OBJECT const * const ob) const
1978 if (ob == dialog_->counter_line_len)
1979 return lyxrc.getDescription(LyXRC::RC_ASCII_LINELEN);
1980 if (ob == dialog_->input_tex_encoding)
1981 return lyxrc.getDescription(LyXRC::RC_FONT_ENCODING);
1982 if (ob == dialog_->input_ascii_roff)
1983 return lyxrc.getDescription(LyXRC::RC_ASCIIROFF_COMMAND);
1984 if (ob == dialog_->input_checktex)
1985 return lyxrc.getDescription(LyXRC::RC_CHKTEX_COMMAND);
1986 if (ob == dialog_->choice_default_papersize)
1987 return lyxrc.getDescription(LyXRC::RC_DEFAULT_PAPERSIZE);
1988 if (ob == dialog_->input_paperoption)
1989 return lyxrc.getDescription(LyXRC::RC_VIEWDVI_PAPEROPTION);
1990 if (ob == dialog_->check_autoreset_classopt)
1991 return lyxrc.getDescription(LyXRC::RC_AUTORESET_OPTIONS);
1996 void FormPreferences::OutputsMisc::update()
1998 fl_set_counter_value(dialog_->counter_line_len,
1999 lyxrc.ascii_linelen);
2000 fl_set_input(dialog_->input_tex_encoding,
2001 lyxrc.fontenc.c_str());
2002 fl_set_choice(dialog_->choice_default_papersize,
2003 lyxrc.default_papersize+1);
2004 fl_set_input(dialog_->input_ascii_roff,
2005 lyxrc.ascii_roff_command.c_str());
2006 fl_set_input(dialog_->input_checktex,
2007 lyxrc.chktex_command.c_str());
2008 fl_set_input(dialog_->input_paperoption,
2009 lyxrc.view_dvi_paper_option.c_str());
2010 fl_set_button(dialog_->check_autoreset_classopt,
2011 lyxrc.auto_reset_options);
2016 FormPreferences::Paths::Paths(FormPreferences & p)
2021 FD_preferences_paths const * FormPreferences::Paths::dialog()
2023 return dialog_.get();
2027 void FormPreferences::Paths::apply()
2029 lyxrc.document_path = fl_get_input(dialog_->input_default_path);
2030 lyxrc.template_path = fl_get_input(dialog_->input_template_path);
2032 int button = fl_get_button(dialog_->check_use_temp_dir);
2033 string str = fl_get_input(dialog_->input_temp_dir);
2037 lyxrc.use_tempdir = button;
2038 lyxrc.tempdir_path = str;
2040 button = fl_get_button(dialog_->check_last_files);
2041 str = fl_get_input(dialog_->input_lastfiles);
2042 if (!button) str.erase();
2044 lyxrc.check_lastfiles = button;
2045 lyxrc.lastfiles = str;
2046 lyxrc.num_lastfiles = static_cast<unsigned int>
2047 (fl_get_counter_value(dialog_->counter_lastfiles));
2049 button = fl_get_button(dialog_->check_make_backups);
2050 str = fl_get_input(dialog_->input_backup_path);
2054 lyxrc.make_backup = button;
2055 lyxrc.backupdir_path = str;
2057 lyxrc.lyxpipes = fl_get_input(dialog_->input_serverpipe);
2064 void FormPreferences::Paths::build()
2066 dialog_.reset(build_preferences_paths(&parent_));
2068 fl_set_input_return(dialog_->input_default_path, FL_RETURN_CHANGED);
2069 fl_set_input_return(dialog_->input_template_path, FL_RETURN_CHANGED);
2070 fl_set_input_return(dialog_->input_temp_dir, FL_RETURN_CHANGED);
2071 fl_set_input_return(dialog_->input_lastfiles, FL_RETURN_CHANGED);
2072 fl_set_input_return(dialog_->input_backup_path, FL_RETURN_CHANGED);
2073 fl_set_counter_return(dialog_->counter_lastfiles, FL_RETURN_CHANGED);
2074 fl_set_input_return(dialog_->input_serverpipe, FL_RETURN_CHANGED);
2076 // set up the feedback mechanism
2077 setPrehandler(dialog_->input_default_path);
2078 setPrehandler(dialog_->counter_lastfiles);
2079 setPrehandler(dialog_->input_template_path);
2080 setPrehandler(dialog_->check_last_files);
2081 setPrehandler(dialog_->input_lastfiles);
2082 setPrehandler(dialog_->check_make_backups);
2083 setPrehandler(dialog_->input_backup_path);
2084 setPrehandler(dialog_->input_serverpipe);
2085 setPrehandler(dialog_->input_temp_dir);
2086 setPrehandler(dialog_->check_use_temp_dir);
2091 FormPreferences::Paths::feedback(FL_OBJECT const * const ob) const
2093 if (ob == dialog_->input_default_path)
2094 return lyxrc.getDescription(LyXRC::RC_DOCUMENTPATH);
2095 if (ob == dialog_->input_template_path)
2096 return lyxrc.getDescription(LyXRC::RC_TEMPLATEPATH);
2097 if (ob == dialog_->check_use_temp_dir)
2098 return lyxrc.getDescription(LyXRC::RC_USETEMPDIR);
2099 if (ob == dialog_->input_temp_dir)
2100 return lyxrc.getDescription(LyXRC::RC_TEMPDIRPATH);
2101 if (ob == dialog_->check_last_files)
2102 return lyxrc.getDescription(LyXRC::RC_CHECKLASTFILES);
2103 if (ob == dialog_->input_lastfiles)
2104 return lyxrc.getDescription(LyXRC::RC_LASTFILES);
2105 if (ob == dialog_->counter_lastfiles)
2106 return lyxrc.getDescription(LyXRC::RC_NUMLASTFILES);
2107 if (ob == dialog_->check_make_backups)
2108 return lyxrc.getDescription(LyXRC::RC_MAKE_BACKUP);
2109 if (ob == dialog_->input_backup_path)
2110 return lyxrc.getDescription(LyXRC::RC_BACKUPDIR_PATH);
2111 if (ob == dialog_->input_serverpipe)
2112 return lyxrc.getDescription(LyXRC::RC_SERVERPIPE);
2117 bool FormPreferences::Paths::input(FL_OBJECT const * const ob)
2119 bool activate = true;
2121 // !ob if function is called from Paths::update() to de/activate
2123 // otherwise the function is called by an xforms CB via input().
2124 if (!ob || ob == dialog_->check_use_temp_dir) {
2125 bool const enable = fl_get_button(dialog_->check_use_temp_dir);
2126 setEnabled(dialog_->input_temp_dir, enable);
2129 if (!ob || ob == dialog_->check_last_files) {
2130 bool const enable = fl_get_button(dialog_->check_last_files);
2131 setEnabled(dialog_->input_lastfiles, enable);
2134 if (!ob || ob == dialog_->check_make_backups) {
2135 bool const enable = fl_get_button(dialog_->check_make_backups);
2136 setEnabled(dialog_->input_backup_path, enable);
2139 if (!ob || ob == dialog_->input_default_path) {
2140 string const name = fl_get_input(dialog_->input_default_path);
2141 if (!name.empty() && !RWInfo::WriteableDir(name)) {
2142 parent_.postWarning(RWInfo::ErrorMessage());
2147 if (!ob || ob == dialog_->input_template_path) {
2148 string const name = fl_get_input(dialog_->input_template_path);
2149 if (!name.empty() && !RWInfo::ReadableDir(name)) {
2150 parent_.postWarning(RWInfo::ErrorMessage());
2155 if (!ob || ob == dialog_->input_temp_dir) {
2156 string const name = fl_get_input(dialog_->input_temp_dir);
2157 if (fl_get_button(dialog_->check_make_backups)
2159 && !RWInfo::WriteableDir(name)) {
2160 parent_.postWarning(RWInfo::ErrorMessage());
2165 if (!ob || ob == dialog_->input_backup_path) {
2166 string const name = fl_get_input(dialog_->input_backup_path);
2167 if (fl_get_button(dialog_->check_make_backups)
2169 && !RWInfo::WriteableDir(name)) {
2170 parent_.postWarning(RWInfo::ErrorMessage());
2175 if (!ob || ob == dialog_->input_lastfiles) {
2176 string const name = fl_get_input(dialog_->input_lastfiles);
2177 if (fl_get_button(dialog_->check_last_files)
2179 && !RWInfo::WriteableFile(name)) {
2180 parent_.postWarning(RWInfo::ErrorMessage());
2185 if (!ob || ob == dialog_->input_serverpipe) {
2186 string const name = fl_get_input(dialog_->input_serverpipe);
2187 if (!name.empty()) {
2188 // strip off the extension
2189 string const str = ChangeExtension(name, "");
2190 if (!RWInfo::WriteableFile(str + ".in")) {
2191 parent_.postWarning(RWInfo::ErrorMessage());
2194 if (!RWInfo::WriteableFile(str + ".out")) {
2195 parent_.postWarning(RWInfo::ErrorMessage());
2201 if (ob == dialog_->button_default_path_browse) {
2202 parent_.browse(dialog_->input_default_path,
2203 _("Default path"), string());
2204 } else if (ob == dialog_->button_template_path_browse) {
2205 parent_.browse(dialog_->input_template_path,
2206 _("Template path"), string());
2207 } else if (ob == dialog_->button_temp_dir_browse) {
2208 parent_.browse(dialog_->input_temp_dir,
2209 _("Temp dir"), string());
2210 } else if (ob == dialog_->button_lastfiles_browse) {
2211 pair<string, string> dir(_("User|#U#u"), user_lyxdir);
2213 parent_.browse(dialog_->input_lastfiles,
2214 _("Lastfiles"), string(), dir);
2215 } else if (ob == dialog_->button_backup_path_browse) {
2216 parent_.browse(dialog_->input_backup_path,
2217 _("Backup path"), string());
2218 } else if (ob == dialog_->button_serverpipe_browse) {
2219 parent_.browse(dialog_->input_serverpipe,
2220 _("LyX Server pipes"), string());
2227 void FormPreferences::Paths::update()
2229 fl_set_input(dialog_->input_default_path,
2230 lyxrc.document_path.c_str());
2231 fl_set_input(dialog_->input_template_path,
2232 lyxrc.template_path.c_str());
2235 if (lyxrc.make_backup)
2236 str = lyxrc.backupdir_path;
2238 fl_set_button(dialog_->check_make_backups,
2240 fl_set_input(dialog_->input_backup_path, str.c_str());
2243 if (lyxrc.use_tempdir)
2244 str = lyxrc.tempdir_path;
2246 fl_set_button(dialog_->check_use_temp_dir,
2248 fl_set_input(dialog_->input_temp_dir, str.c_str());
2251 if (lyxrc.check_lastfiles)
2252 str = lyxrc.lastfiles;
2254 fl_set_button(dialog_->check_last_files,
2255 lyxrc.check_lastfiles);
2256 fl_set_input(dialog_->input_lastfiles, str.c_str());
2257 fl_set_counter_value(dialog_->counter_lastfiles,
2258 lyxrc.num_lastfiles);
2260 fl_set_input(dialog_->input_serverpipe, lyxrc.lyxpipes.c_str());
2262 // Activate/Deactivate the input fields dependent on the state of the
2268 FormPreferences::Printer::Printer(FormPreferences & p)
2273 FD_preferences_printer const * FormPreferences::Printer::dialog()
2275 return dialog_.get();
2279 void FormPreferences::Printer::apply() const
2281 lyxrc.print_adapt_output = fl_get_button(dialog_->check_adapt_output);
2282 lyxrc.print_command = fl_get_input(dialog_->input_command);
2283 lyxrc.print_pagerange_flag = fl_get_input(dialog_->input_page_range);
2284 lyxrc.print_copies_flag = fl_get_input(dialog_->input_copies);
2285 lyxrc.print_reverse_flag = fl_get_input(dialog_->input_reverse);
2286 lyxrc.print_to_printer = fl_get_input(dialog_->input_to_printer);
2287 lyxrc.print_file_extension =
2288 fl_get_input(dialog_->input_file_extension);
2289 lyxrc.print_spool_command =
2290 fl_get_input(dialog_->input_spool_command);
2291 lyxrc.print_paper_flag = fl_get_input(dialog_->input_paper_type);
2292 lyxrc.print_evenpage_flag = fl_get_input(dialog_->input_even_pages);
2293 lyxrc.print_oddpage_flag = fl_get_input(dialog_->input_odd_pages);
2294 lyxrc.print_collcopies_flag = fl_get_input(dialog_->input_collated);
2295 lyxrc.print_landscape_flag = fl_get_input(dialog_->input_landscape);
2296 lyxrc.print_to_file = fl_get_input(dialog_->input_to_file);
2297 lyxrc.print_extra_options =
2298 fl_get_input(dialog_->input_extra_options);
2299 lyxrc.print_spool_printerprefix =
2300 fl_get_input(dialog_->input_spool_prefix);
2301 lyxrc.print_paper_dimension_flag =
2302 fl_get_input(dialog_->input_paper_size);
2303 lyxrc.printer = fl_get_input(dialog_->input_name);
2308 FormPreferences::Printer::feedback(FL_OBJECT const * const ob) const
2310 if (ob == dialog_->input_command)
2311 return lyxrc.getDescription(LyXRC::RC_PRINT_COMMAND);
2312 if (ob == dialog_->check_adapt_output)
2313 return lyxrc.getDescription(LyXRC::RC_PRINT_ADAPTOUTPUT);
2314 if (ob == dialog_->input_to_printer)
2315 return lyxrc.getDescription(LyXRC::RC_PRINTTOPRINTER);
2316 if (ob == dialog_->input_to_file)
2317 return lyxrc.getDescription(LyXRC::RC_PRINTTOFILE);
2318 if (ob == dialog_->input_file_extension)
2319 return lyxrc.getDescription(LyXRC::RC_PRINTFILEEXTENSION);
2320 if (ob == dialog_->input_extra_options)
2321 return lyxrc.getDescription(LyXRC::RC_PRINTEXSTRAOPTIONS);
2322 if (ob == dialog_->input_spool_command)
2323 return lyxrc.getDescription(LyXRC::RC_PRINTSPOOL_COMMAND);
2324 if (ob == dialog_->input_spool_prefix)
2325 return lyxrc.getDescription(LyXRC::RC_PRINTSPOOL_PRINTERPREFIX);
2326 if (ob == dialog_->input_name)
2327 return lyxrc.getDescription(LyXRC::RC_PRINTER);
2328 if (ob == dialog_->input_even_pages)
2329 return lyxrc.getDescription(LyXRC::RC_PRINTEVENPAGEFLAG);
2330 if (ob == dialog_->input_odd_pages)
2331 return lyxrc.getDescription(LyXRC::RC_PRINTODDPAGEFLAG);
2332 if (ob == dialog_->input_page_range)
2333 return lyxrc.getDescription(LyXRC::RC_PRINTPAGERANGEFLAG);
2334 if (ob == dialog_->input_reverse)
2335 return lyxrc.getDescription(LyXRC::RC_PRINTREVERSEFLAG);
2336 if (ob == dialog_->input_landscape)
2337 return lyxrc.getDescription(LyXRC::RC_PRINTLANDSCAPEFLAG);
2338 if (ob == dialog_->input_copies)
2339 return lyxrc.getDescription(LyXRC::RC_PRINTCOPIESFLAG);
2340 if (ob == dialog_->input_collated)
2341 return lyxrc.getDescription(LyXRC::RC_PRINTCOLLCOPIESFLAG);
2342 if (ob == dialog_->input_paper_type)
2343 return lyxrc.getDescription(LyXRC::RC_PRINTPAPERFLAG);
2344 if (ob == dialog_->input_paper_size)
2345 return lyxrc.getDescription(LyXRC::RC_PRINTPAPERDIMENSIONFLAG);
2350 void FormPreferences::Printer::build()
2352 dialog_.reset(build_preferences_printer(&parent_));
2354 fl_set_input_return(dialog_->input_command, FL_RETURN_CHANGED);
2355 fl_set_input_return(dialog_->input_page_range, FL_RETURN_CHANGED);
2356 fl_set_input_return(dialog_->input_copies, FL_RETURN_CHANGED);
2357 fl_set_input_return(dialog_->input_reverse, FL_RETURN_CHANGED);
2358 fl_set_input_return(dialog_->input_to_printer, FL_RETURN_CHANGED);
2359 fl_set_input_return(dialog_->input_file_extension, FL_RETURN_CHANGED);
2360 fl_set_input_return(dialog_->input_spool_command, FL_RETURN_CHANGED);
2361 fl_set_input_return(dialog_->input_paper_type, FL_RETURN_CHANGED);
2362 fl_set_input_return(dialog_->input_even_pages, FL_RETURN_CHANGED);
2363 fl_set_input_return(dialog_->input_odd_pages, FL_RETURN_CHANGED);
2364 fl_set_input_return(dialog_->input_collated, FL_RETURN_CHANGED);
2365 fl_set_input_return(dialog_->input_landscape, FL_RETURN_CHANGED);
2366 fl_set_input_return(dialog_->input_to_file, FL_RETURN_CHANGED);
2367 fl_set_input_return(dialog_->input_extra_options, FL_RETURN_CHANGED);
2368 fl_set_input_return(dialog_->input_spool_prefix, FL_RETURN_CHANGED);
2369 fl_set_input_return(dialog_->input_paper_size, FL_RETURN_CHANGED);
2370 fl_set_input_return(dialog_->input_name, FL_RETURN_CHANGED);
2372 // set up the feedback mechanism
2373 setPrehandler(dialog_->input_command);
2374 setPrehandler(dialog_->input_page_range);
2375 setPrehandler(dialog_->input_copies);
2376 setPrehandler(dialog_->input_reverse);
2377 setPrehandler(dialog_->input_to_printer);
2378 setPrehandler(dialog_->input_file_extension);
2379 setPrehandler(dialog_->input_spool_command);
2380 setPrehandler(dialog_->input_paper_type);
2381 setPrehandler(dialog_->input_even_pages);
2382 setPrehandler(dialog_->input_odd_pages);
2383 setPrehandler(dialog_->input_collated);
2384 setPrehandler(dialog_->input_landscape);
2385 setPrehandler(dialog_->input_to_file);
2386 setPrehandler(dialog_->input_extra_options);
2387 setPrehandler(dialog_->input_spool_prefix);
2388 setPrehandler(dialog_->input_paper_size);
2389 setPrehandler(dialog_->input_name);
2390 setPrehandler(dialog_->check_adapt_output);
2394 void FormPreferences::Printer::update()
2396 fl_set_button(dialog_->check_adapt_output,
2397 lyxrc.print_adapt_output);
2398 fl_set_input(dialog_->input_command,
2399 lyxrc.print_command.c_str());
2400 fl_set_input(dialog_->input_page_range,
2401 lyxrc.print_pagerange_flag.c_str());
2402 fl_set_input(dialog_->input_copies,
2403 lyxrc.print_copies_flag.c_str());
2404 fl_set_input(dialog_->input_reverse,
2405 lyxrc.print_reverse_flag.c_str());
2406 fl_set_input(dialog_->input_to_printer,
2407 lyxrc.print_to_printer.c_str());
2408 fl_set_input(dialog_->input_file_extension,
2409 lyxrc.print_file_extension.c_str());
2410 fl_set_input(dialog_->input_spool_command,
2411 lyxrc.print_spool_command.c_str());
2412 fl_set_input(dialog_->input_paper_type,
2413 lyxrc.print_paper_flag.c_str());
2414 fl_set_input(dialog_->input_even_pages,
2415 lyxrc.print_evenpage_flag.c_str());
2416 fl_set_input(dialog_->input_odd_pages,
2417 lyxrc.print_oddpage_flag.c_str());
2418 fl_set_input(dialog_->input_collated,
2419 lyxrc.print_collcopies_flag.c_str());
2420 fl_set_input(dialog_->input_landscape,
2421 lyxrc.print_landscape_flag.c_str());
2422 fl_set_input(dialog_->input_to_file,
2423 lyxrc.print_to_file.c_str());
2424 fl_set_input(dialog_->input_extra_options,
2425 lyxrc.print_extra_options.c_str());
2426 fl_set_input(dialog_->input_spool_prefix,
2427 lyxrc.print_spool_printerprefix.c_str());
2428 fl_set_input(dialog_->input_paper_size,
2429 lyxrc.print_paper_dimension_flag.c_str());
2430 fl_set_input(dialog_->input_name,
2431 lyxrc.printer.c_str());
2435 FormPreferences::ScreenFonts::ScreenFonts(FormPreferences & p)
2440 FD_preferences_screen_fonts const * FormPreferences::ScreenFonts::dialog()
2442 return dialog_.get();
2446 void FormPreferences::ScreenFonts::apply() const
2448 bool changed = false;
2450 string str = fl_get_input(dialog_->input_roman);
2451 if (lyxrc.roman_font_name != str) {
2453 lyxrc.roman_font_name = str;
2456 str = fl_get_input(dialog_->input_sans);
2457 if (lyxrc.sans_font_name != str) {
2459 lyxrc.sans_font_name = str;
2462 str = fl_get_input(dialog_->input_typewriter);
2463 if (lyxrc.typewriter_font_name != str) {
2465 lyxrc.typewriter_font_name = str;
2468 str = fl_get_input(dialog_->input_screen_encoding);
2469 if (lyxrc.font_norm != str) {
2471 lyxrc.font_norm = str;
2474 bool button = fl_get_button(dialog_->check_scalable);
2475 if (lyxrc.use_scalable_fonts != button) {
2477 lyxrc.use_scalable_fonts = button;
2480 unsigned int ivalue = static_cast<unsigned int>
2481 (fl_get_counter_value(dialog_->counter_zoom));
2482 if (lyxrc.zoom != ivalue) {
2484 lyxrc.zoom = ivalue;
2487 ivalue = static_cast<unsigned int>
2488 (fl_get_counter_value(dialog_->counter_dpi));
2489 if (lyxrc.dpi != ivalue) {
2494 double dvalue = strToDbl(fl_get_input(dialog_->input_tiny));
2495 if (lyxrc.font_sizes[LyXFont::SIZE_TINY] != dvalue) {
2497 lyxrc.font_sizes[LyXFont::SIZE_TINY] = dvalue;
2500 dvalue = strToDbl(fl_get_input(dialog_->input_script));
2501 if (lyxrc.font_sizes[LyXFont::SIZE_SCRIPT] != dvalue) {
2503 lyxrc.font_sizes[LyXFont::SIZE_SCRIPT] = dvalue;
2506 dvalue = strToDbl(fl_get_input(dialog_->input_footnote));
2507 if (lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE] != dvalue) {
2509 lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE] = dvalue;
2512 dvalue = strToDbl(fl_get_input(dialog_->input_small));
2513 if (lyxrc.font_sizes[LyXFont::SIZE_SMALL] != dvalue) {
2515 lyxrc.font_sizes[LyXFont::SIZE_SMALL] = dvalue;
2518 dvalue = strToDbl(fl_get_input(dialog_->input_normal));
2519 if (lyxrc.font_sizes[LyXFont::SIZE_NORMAL] != dvalue) {
2521 lyxrc.font_sizes[LyXFont::SIZE_NORMAL] = dvalue;
2524 dvalue = strToDbl(fl_get_input(dialog_->input_large));
2525 if (lyxrc.font_sizes[LyXFont::SIZE_LARGE] != dvalue) {
2527 lyxrc.font_sizes[LyXFont::SIZE_LARGE] = dvalue;
2530 dvalue = strToDbl(fl_get_input(dialog_->input_larger));
2531 if (lyxrc.font_sizes[LyXFont::SIZE_LARGER] != dvalue) {
2533 lyxrc.font_sizes[LyXFont::SIZE_LARGER] = dvalue;
2536 dvalue = strToDbl(fl_get_input(dialog_->input_largest));
2537 if (lyxrc.font_sizes[LyXFont::SIZE_LARGEST] != dvalue) {
2539 lyxrc.font_sizes[LyXFont::SIZE_LARGEST] = dvalue;
2542 dvalue = strToDbl(fl_get_input(dialog_->input_huge));
2543 if (lyxrc.font_sizes[LyXFont::SIZE_HUGE] != dvalue) {
2545 lyxrc.font_sizes[LyXFont::SIZE_HUGE] = dvalue;
2548 dvalue = strToDbl(fl_get_input(dialog_->input_huger));
2549 if (lyxrc.font_sizes[LyXFont::SIZE_HUGER] != dvalue) {
2551 lyxrc.font_sizes[LyXFont::SIZE_HUGER] = dvalue;
2555 // Now update the buffers
2556 // Can anything below here affect the redraw process?
2557 parent_.lv_->getLyXFunc()->dispatch(LFUN_SCREEN_FONT_UPDATE);
2562 void FormPreferences::ScreenFonts::build()
2564 dialog_.reset(build_preferences_screen_fonts(&parent_));
2566 fl_set_counter_step(dialog_->counter_zoom, 1, 10);
2567 fl_set_counter_step(dialog_->counter_dpi, 1, 10);
2569 fl_set_input_return(dialog_->input_roman, FL_RETURN_CHANGED);
2570 fl_set_input_return(dialog_->input_sans, FL_RETURN_CHANGED);
2571 fl_set_input_return(dialog_->input_typewriter, FL_RETURN_CHANGED);
2572 fl_set_input_return(dialog_->input_screen_encoding, FL_RETURN_CHANGED);
2573 fl_set_counter_return(dialog_->counter_zoom, FL_RETURN_CHANGED);
2574 fl_set_counter_return(dialog_->counter_dpi, FL_RETURN_CHANGED);
2575 fl_set_input_return(dialog_->input_tiny, FL_RETURN_CHANGED);
2576 fl_set_input_return(dialog_->input_script, FL_RETURN_CHANGED);
2577 fl_set_input_return(dialog_->input_footnote, FL_RETURN_CHANGED);
2578 fl_set_input_return(dialog_->input_small, FL_RETURN_CHANGED);
2579 fl_set_input_return(dialog_->input_normal, FL_RETURN_CHANGED);
2580 fl_set_input_return(dialog_->input_large, FL_RETURN_CHANGED);
2581 fl_set_input_return(dialog_->input_larger, FL_RETURN_CHANGED);
2582 fl_set_input_return(dialog_->input_largest, FL_RETURN_CHANGED);
2583 fl_set_input_return(dialog_->input_huge, FL_RETURN_CHANGED);
2584 fl_set_input_return(dialog_->input_huger, FL_RETURN_CHANGED);
2586 fl_set_input_filter(dialog_->input_tiny, fl_unsigned_float_filter);
2587 fl_set_input_filter(dialog_->input_script, fl_unsigned_float_filter);
2588 fl_set_input_filter(dialog_->input_footnote, fl_unsigned_float_filter);
2589 fl_set_input_filter(dialog_->input_small, fl_unsigned_float_filter);
2590 fl_set_input_filter(dialog_->input_normal, fl_unsigned_float_filter);
2591 fl_set_input_filter(dialog_->input_large, fl_unsigned_float_filter);
2592 fl_set_input_filter(dialog_->input_larger, fl_unsigned_float_filter);
2593 fl_set_input_filter(dialog_->input_largest, fl_unsigned_float_filter);
2594 fl_set_input_filter(dialog_->input_huge, fl_unsigned_float_filter);
2595 fl_set_input_filter(dialog_->input_huger, fl_unsigned_float_filter);
2597 // set up the feedback mechanism
2598 setPrehandler(dialog_->input_roman);
2599 setPrehandler(dialog_->input_sans);
2600 setPrehandler(dialog_->input_typewriter);
2601 setPrehandler(dialog_->counter_zoom);
2602 setPrehandler(dialog_->counter_dpi);
2603 setPrehandler(dialog_->check_scalable);
2604 setPrehandler(dialog_->input_screen_encoding);
2605 setPrehandler(dialog_->input_tiny);
2606 setPrehandler(dialog_->input_script);
2607 setPrehandler(dialog_->input_footnote);
2608 setPrehandler(dialog_->input_small);
2609 setPrehandler(dialog_->input_large);
2610 setPrehandler(dialog_->input_larger);
2611 setPrehandler(dialog_->input_largest);
2612 setPrehandler(dialog_->input_normal);
2613 setPrehandler(dialog_->input_huge);
2614 setPrehandler(dialog_->input_huger);
2619 FormPreferences::ScreenFonts::feedback(FL_OBJECT const * const ob) const
2621 if (ob == dialog_->input_roman)
2622 return lyxrc.getDescription(LyXRC::RC_SCREEN_FONT_ROMAN);
2623 if (ob == dialog_->input_sans)
2624 return lyxrc.getDescription(LyXRC::RC_SCREEN_FONT_SANS);
2625 if (ob == dialog_->input_typewriter)
2626 return lyxrc.getDescription(LyXRC::RC_SCREEN_FONT_TYPEWRITER);
2627 if (ob == dialog_->check_scalable)
2628 return lyxrc.getDescription(LyXRC::RC_SCREEN_FONT_SCALABLE);
2629 if (ob == dialog_->input_screen_encoding)
2630 return lyxrc.getDescription(LyXRC::RC_SCREEN_FONT_ENCODING);
2631 if (ob == dialog_->counter_zoom)
2632 return lyxrc.getDescription(LyXRC::RC_SCREEN_ZOOM);
2633 if (ob == dialog_->counter_dpi)
2634 return lyxrc.getDescription(LyXRC::RC_SCREEN_DPI);
2635 if (ob == dialog_->input_tiny
2636 || ob == dialog_->input_script
2637 || ob == dialog_->input_footnote
2638 || ob == dialog_->input_small
2639 || ob == dialog_->input_large
2640 || ob == dialog_->input_larger
2641 || ob == dialog_->input_larger
2642 || ob == dialog_->input_largest
2643 || ob == dialog_->input_normal
2644 || ob == dialog_->input_huge
2645 || ob == dialog_->input_huger)
2646 return lyxrc.getDescription(LyXRC::RC_SCREEN_FONT_SIZES);
2651 bool FormPreferences::ScreenFonts::input()
2653 bool activate = true;
2656 // Make sure that all fonts all have positive entries
2657 // Also note that an empty entry is returned as 0.0 by strToDbl
2658 if (0.0 >= strToDbl(fl_get_input(dialog_->input_tiny))
2659 || 0.0 >= strToDbl(fl_get_input(dialog_->input_script))
2660 || 0.0 >= strToDbl(fl_get_input(dialog_->input_footnote))
2661 || 0.0 >= strToDbl(fl_get_input(dialog_->input_small))
2662 || 0.0 >= strToDbl(fl_get_input(dialog_->input_normal))
2663 || 0.0 >= strToDbl(fl_get_input(dialog_->input_large))
2664 || 0.0 >= strToDbl(fl_get_input(dialog_->input_larger))
2665 || 0.0 >= strToDbl(fl_get_input(dialog_->input_largest))
2666 || 0.0 >= strToDbl(fl_get_input(dialog_->input_huge))
2667 || 0.0 >= strToDbl(fl_get_input(dialog_->input_huger))) {
2669 str = _("Fonts must be positive!");
2671 } else if (strToDbl(fl_get_input(dialog_->input_tiny)) >
2672 // Fontsizes -- tiny < script < footnote etc.
2673 strToDbl(fl_get_input(dialog_->input_script)) ||
2674 strToDbl(fl_get_input(dialog_->input_script)) >
2675 strToDbl(fl_get_input(dialog_->input_footnote)) ||
2676 strToDbl(fl_get_input(dialog_->input_footnote)) >
2677 strToDbl(fl_get_input(dialog_->input_small)) ||
2678 strToDbl(fl_get_input(dialog_->input_small)) >
2679 strToDbl(fl_get_input(dialog_->input_normal)) ||
2680 strToDbl(fl_get_input(dialog_->input_normal)) >
2681 strToDbl(fl_get_input(dialog_->input_large)) ||
2682 strToDbl(fl_get_input(dialog_->input_large)) >
2683 strToDbl(fl_get_input(dialog_->input_larger)) ||
2684 strToDbl(fl_get_input(dialog_->input_larger)) >
2685 strToDbl(fl_get_input(dialog_->input_largest)) ||
2686 strToDbl(fl_get_input(dialog_->input_largest)) >
2687 strToDbl(fl_get_input(dialog_->input_huge)) ||
2688 strToDbl(fl_get_input(dialog_->input_huge)) >
2689 strToDbl(fl_get_input(dialog_->input_huger))) {
2692 str = _("Fonts must be input in the order tiny > script> footnote > small > normal > large > larger > largest > huge > huger.");
2696 parent_.postWarning(str);
2702 void FormPreferences::ScreenFonts::update()
2704 fl_set_input(dialog_->input_roman,
2705 lyxrc.roman_font_name.c_str());
2706 fl_set_input(dialog_->input_sans,
2707 lyxrc.sans_font_name.c_str());
2708 fl_set_input(dialog_->input_typewriter,
2709 lyxrc.typewriter_font_name.c_str());
2710 fl_set_input(dialog_->input_screen_encoding,
2711 lyxrc.font_norm.c_str());
2712 fl_set_button(dialog_->check_scalable,
2713 lyxrc.use_scalable_fonts);
2714 fl_set_counter_value(dialog_->counter_zoom, lyxrc.zoom);
2715 fl_set_counter_value(dialog_->counter_dpi, lyxrc.dpi);
2716 fl_set_input(dialog_->input_tiny,
2717 tostr(lyxrc.font_sizes[LyXFont::SIZE_TINY]).c_str());
2718 fl_set_input(dialog_->input_script,
2719 tostr(lyxrc.font_sizes[LyXFont::SIZE_SCRIPT]).c_str());
2720 fl_set_input(dialog_->input_footnote,
2721 tostr(lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE]).c_str());
2722 fl_set_input(dialog_->input_small,
2723 tostr(lyxrc.font_sizes[LyXFont::SIZE_SMALL]).c_str());
2724 fl_set_input(dialog_->input_normal,
2725 tostr(lyxrc.font_sizes[LyXFont::SIZE_NORMAL]).c_str());
2726 fl_set_input(dialog_->input_large,
2727 tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGE]).c_str());
2728 fl_set_input(dialog_->input_larger,
2729 tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGER]).c_str());
2730 fl_set_input(dialog_->input_largest,
2731 tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGEST]).c_str());
2732 fl_set_input(dialog_->input_huge,
2733 tostr(lyxrc.font_sizes[LyXFont::SIZE_HUGE]).c_str());
2734 fl_set_input(dialog_->input_huger,
2735 tostr(lyxrc.font_sizes[LyXFont::SIZE_HUGER]).c_str());
2740 FormPreferences::SpellOptions::SpellOptions(FormPreferences & p)
2745 FD_preferences_spelloptions const * FormPreferences::SpellOptions::dialog()
2747 return dialog_.get();
2751 void FormPreferences::SpellOptions::apply()
2754 string choice = fl_get_choice_text(dialog_->choice_spell_command);
2755 choice = trim(choice);
2757 lyxrc.isp_command = choice;
2760 // If spell checker == "none", all other input set to off.
2761 if (fl_get_choice(dialog_->choice_spell_command) == 1) {
2762 lyxrc.isp_use_alt_lang = false;
2763 lyxrc.isp_alt_lang.erase();
2765 lyxrc.isp_use_esc_chars = false;
2766 lyxrc.isp_esc_chars.erase();
2768 lyxrc.isp_use_pers_dict = false;
2769 lyxrc.isp_pers_dict.erase();
2771 lyxrc.isp_accept_compound = false;
2772 lyxrc.isp_use_input_encoding = false;
2775 int button = fl_get_button(dialog_->check_alt_lang);
2776 choice = fl_get_input(dialog_->input_alt_lang);
2777 if (button && choice.empty()) button = 0;
2778 if (!button) choice.erase();
2780 lyxrc.isp_use_alt_lang = static_cast<bool>(button);
2781 lyxrc.isp_alt_lang = choice;
2783 button = fl_get_button(dialog_->check_escape_chars);
2784 choice = fl_get_input(dialog_->input_escape_chars);
2785 if (button && choice.empty()) button = 0;
2786 if (!button) choice.erase();
2788 lyxrc.isp_use_esc_chars = static_cast<bool>(button);
2789 lyxrc.isp_esc_chars = choice;
2791 button = fl_get_button(dialog_->check_personal_dict);
2792 choice = fl_get_input(dialog_->input_personal_dict);
2793 if (button && choice.empty()) button = 0;
2794 if (!button) choice.erase();
2796 lyxrc.isp_use_pers_dict = static_cast<bool>(button);
2797 lyxrc.isp_pers_dict = choice;
2799 button = fl_get_button(dialog_->check_compound_words);
2800 lyxrc.isp_accept_compound = static_cast<bool>(button);
2802 button = fl_get_button(dialog_->check_input_enc);
2803 lyxrc.isp_use_input_encoding = static_cast<bool>(button);
2814 void FormPreferences::SpellOptions::build()
2816 dialog_.reset(build_preferences_spelloptions(&parent_));
2818 fl_addto_choice(dialog_->choice_spell_command,
2819 _(" ispell | aspell "));
2820 fl_set_input_return(dialog_->input_alt_lang, FL_RETURN_CHANGED);
2821 fl_set_input_return(dialog_->input_escape_chars, FL_RETURN_CHANGED);
2822 fl_set_input_return(dialog_->input_personal_dict, FL_RETURN_CHANGED);
2824 // set up the feedback mechanism
2825 setPrehandler(dialog_->choice_spell_command);
2826 setPrehandler(dialog_->check_alt_lang);
2827 setPrehandler(dialog_->input_alt_lang);
2828 setPrehandler(dialog_->check_escape_chars);
2829 setPrehandler(dialog_->input_escape_chars);
2830 setPrehandler(dialog_->check_personal_dict);
2831 setPrehandler(dialog_->input_personal_dict);
2832 setPrehandler(dialog_->button_personal_dict);
2833 setPrehandler(dialog_->check_compound_words);
2834 setPrehandler(dialog_->check_input_enc);
2839 FormPreferences::SpellOptions::feedback(FL_OBJECT const * const ob) const
2841 if (ob == dialog_->choice_spell_command)
2842 return lyxrc.getDescription(LyXRC::RC_SPELL_COMMAND);
2843 if (ob == dialog_->check_alt_lang)
2844 return lyxrc.getDescription(LyXRC::RC_USE_ALT_LANG);
2845 if (ob == dialog_->input_alt_lang)
2846 return lyxrc.getDescription(LyXRC::RC_ALT_LANG);
2847 if (ob == dialog_->check_escape_chars)
2848 return lyxrc.getDescription(LyXRC::RC_USE_ESC_CHARS);
2849 if (ob == dialog_->input_escape_chars)
2850 return lyxrc.getDescription(LyXRC::RC_ESC_CHARS);
2851 if (ob == dialog_->check_personal_dict)
2852 return lyxrc.getDescription(LyXRC::RC_USE_PERS_DICT);
2853 if (ob == dialog_->input_personal_dict)
2854 return lyxrc.getDescription(LyXRC::RC_PERS_DICT);
2855 if (ob == dialog_->check_compound_words)
2856 return lyxrc.getDescription(LyXRC::RC_ACCEPT_COMPOUND);
2857 if (ob == dialog_->check_input_enc)
2858 return lyxrc.getDescription(LyXRC::RC_USE_INP_ENC);
2863 bool FormPreferences::SpellOptions::input(FL_OBJECT const * const ob)
2865 // !ob if function is called from updateSpellOptions() to de/activate
2867 // otherwise the function is called by an xforms CB via input().
2870 // If spell checker == "none", disable all input.
2871 if (!ob || ob == dialog_->choice_spell_command) {
2872 if (fl_get_choice(dialog_->choice_spell_command) == 1) {
2873 fl_deactivate_object(dialog_->check_alt_lang);
2874 fl_deactivate_object(dialog_->input_alt_lang);
2875 fl_deactivate_object(dialog_->check_escape_chars);
2876 fl_deactivate_object(dialog_->input_escape_chars);
2877 fl_deactivate_object(dialog_->check_personal_dict);
2878 fl_deactivate_object(dialog_->input_personal_dict);
2879 fl_deactivate_object(dialog_->check_compound_words);
2880 fl_deactivate_object(dialog_->check_input_enc);
2883 fl_activate_object(dialog_->check_alt_lang);
2884 fl_activate_object(dialog_->check_escape_chars);
2885 fl_activate_object(dialog_->check_personal_dict);
2886 fl_activate_object(dialog_->check_compound_words);
2887 fl_activate_object(dialog_->check_input_enc);
2892 if (!ob || ob == dialog_->check_alt_lang) {
2893 bool const enable = fl_get_button(dialog_->check_alt_lang);
2894 setEnabled(dialog_->input_alt_lang, enable);
2897 if (!ob || ob == dialog_->check_escape_chars) {
2898 bool const enable = fl_get_button(dialog_->check_escape_chars);
2899 setEnabled(dialog_->input_escape_chars, enable);
2902 if (!ob || ob == dialog_->check_personal_dict) {
2903 bool const enable = fl_get_button(dialog_->check_personal_dict);
2904 setEnabled(dialog_->input_personal_dict, enable);
2907 if (ob == dialog_->button_personal_dict) {
2908 parent_.browse(dialog_->input_personal_dict,
2909 _("Personal dictionary"), "*.ispell");
2912 return true; // All input is valid!
2916 void FormPreferences::SpellOptions::update()
2920 if (lyxrc.isp_command == "none")
2922 else if (lyxrc.isp_command == "ispell")
2924 else if (lyxrc.isp_command == "aspell")
2927 if (lyxrc.isp_command == "ispell")
2929 else if (lyxrc.isp_command == "aspell")
2932 fl_set_choice(dialog_->choice_spell_command, choice);
2935 if (lyxrc.isp_use_alt_lang)
2936 str = lyxrc.isp_alt_lang;
2938 fl_set_button(dialog_->check_alt_lang,
2939 lyxrc.isp_use_alt_lang);
2940 fl_set_input(dialog_->input_alt_lang, str.c_str());
2943 if (lyxrc.isp_use_esc_chars)
2944 str = lyxrc.isp_esc_chars;
2946 fl_set_button(dialog_->check_escape_chars,
2947 lyxrc.isp_use_esc_chars);
2948 fl_set_input(dialog_->input_escape_chars, str.c_str());
2951 if (lyxrc.isp_use_pers_dict)
2952 str = lyxrc.isp_pers_dict;
2954 fl_set_button(dialog_->check_personal_dict,
2955 lyxrc.isp_use_pers_dict);
2956 fl_set_input(dialog_->input_personal_dict, str.c_str());
2958 fl_set_button(dialog_->check_compound_words,
2959 lyxrc.isp_accept_compound);
2960 fl_set_button(dialog_->check_input_enc,
2961 lyxrc.isp_use_input_encoding);
2963 // Activate/Deactivate the input fields dependent on the state of the
2969 void FormPreferences::browse(FL_OBJECT * inpt,
2970 string const & title,
2971 string const & pattern,
2972 pair<string,string> const & dir1,
2973 pair<string,string> const & dir2)
2975 // Get the filename from the dialog
2976 string const filename = fl_get_input(inpt);
2978 // Show the file browser dialog
2979 string const new_filename =
2980 browseFile(lv_, filename, title, pattern, dir1, dir2);
2982 // Save the filename to the dialog
2983 if (new_filename != filename && !new_filename.empty()) {
2984 fl_set_input(inpt, new_filename.c_str());