]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormCharacter.C
Bugfixes: checkboxes to radiobuttons (from J�rgen S) and remove a little
[lyx.git] / src / frontends / xforms / FormCharacter.C
index 22779640769e0a3e084ca67856e085dda7b2479d..f9357d35d2c6559717b3e8efecab3802fcbfa2c5 100644 (file)
 #include "helper_funcs.h"
 
 using std::vector;
-using std::back_inserter;
-using std::transform;
+using namespace character;
 
 typedef FormCB<ControlCharacter, FormDB<FD_form_character> > base_class;
 
 FormCharacter::FormCharacter(ControlCharacter & c)
-       : base_class(c, _("Character Layout"))
+       : base_class(c, _("Character Layout"), false)
 {}
 
 
@@ -44,12 +43,12 @@ void FormCharacter::build()
 {
        dialog_.reset(build_character());
 
-       vector<ControlCharacter::FamilyPair> const family = getFamilyData();
-       vector<ControlCharacter::SeriesPair> const series = getSeriesData();
-       vector<ControlCharacter::ShapePair>  const shape  = getShapeData();
-       vector<ControlCharacter::SizePair>   const size   = getSizeData();
-       vector<ControlCharacter::BarPair>    const bar    = getBarData();
-       vector<ControlCharacter::ColorPair>  const color  = getColorData();
+       vector<FamilyPair> const family = getFamilyData();
+       vector<SeriesPair> const series = getSeriesData();
+       vector<ShapePair>  const shape  = getShapeData();
+       vector<SizePair>   const size   = getSizeData();
+       vector<BarPair>    const bar    = getBarData();
+       vector<ColorPair>  const color  = getColorData();
        vector<string> const language = getLanguageData();
 
        // Store the enums for later
@@ -81,12 +80,13 @@ void FormCharacter::build()
        fl_addto_choice(dialog_->choice_color, choice.c_str());
 
        // xforms appears to need this to prevent a crash...
-       // fl_addto_choice(dialog_->choice_language,
-       //              _(" English %l| German | French "));
+       fl_addto_choice(dialog_->choice_language, "prevent crash");
 
        // insert default language box manually
        fl_addto_form(dialog_->form);
                FL_OBJECT * ob = dialog_->choice_language;
+               fl_hide_object(dialog_->choice_language);
+
                combo_language2_.reset(new Combox(FL_COMBOX_DROPLIST));
                combo_language2_->add(ob->x, ob->y, ob->w, ob->h, 250);
                combo_language2_->shortcut("#L", 1);
@@ -98,18 +98,19 @@ void FormCharacter::build()
             cit != language.end(); ++cit) {
                combo_language2_->addto(*cit);
        }
-       combo_language2_->select_text(*language.begin());
+       combo_language2_->select(*language.begin());
 
        // Manage the ok, apply and cancel/close buttons
        bc().setApply(dialog_->button_apply);
        bc().setCancel(dialog_->button_close);
-       bc().refresh();
        bc().addReadOnly(dialog_->check_toggle_all);
 }
 
 
 void FormCharacter::apply()
 {
+       if (!form()) return;
+
        int pos = fl_get_choice(dialog_->choice_family);
        controller().setFamily(family_[pos-1]);
 
@@ -133,3 +134,78 @@ void FormCharacter::apply()
        bool const toggleall = fl_get_button(dialog_->check_toggle_all);
        controller().setToggleAll(toggleall);
 }
+
+namespace {
+
+template<class A>
+typename vector<A>::size_type findPos(vector<A> const & vec, A const & val)
+{
+       vector<A>::const_iterator it =
+               std::find(vec.begin(), vec.end(), val);
+       if (it == vec.end())
+               return 0;
+       return it - vec.begin();
+}
+} // namespace anon
+
+void FormCharacter::update()
+{
+       int pos = int(findPos(family_, controller().getFamily()));
+       fl_set_choice(dialog_->choice_family, pos+1);
+       
+       pos = int(findPos(series_, controller().getSeries()));
+       fl_set_choice(dialog_->choice_series, pos+1);
+
+       pos = int(findPos(shape_, controller().getShape()));
+       fl_set_choice(dialog_->choice_shape, pos+1);
+
+       pos = int(findPos(size_, controller().getSize()));
+       fl_set_choice(dialog_->choice_size, pos+1);
+
+       pos = int(findPos(bar_, controller().getBar()));
+       fl_set_choice(dialog_->choice_bar, pos+1);
+
+       pos = int(findPos(color_, controller().getColor()));
+       fl_set_choice(dialog_->choice_color, pos+1);
+
+       combo_language2_->select(controller().getLanguage());
+
+       fl_set_button(dialog_->check_toggle_all, controller().getToggleAll());
+}
+
+
+ButtonPolicy::SMInput FormCharacter::input(FL_OBJECT *, long)
+{
+       ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
+
+       int pos = fl_get_choice(dialog_->choice_family);
+       if (family_[pos-1] != LyXFont::IGNORE_FAMILY)
+               activate = ButtonPolicy::SMI_VALID;
+       
+       pos = fl_get_choice(dialog_->choice_series);
+       if (series_[pos-1] != LyXFont::IGNORE_SERIES)
+               activate = ButtonPolicy::SMI_VALID;
+
+       pos = fl_get_choice(dialog_->choice_shape);
+       if (shape_[pos-1] != LyXFont::IGNORE_SHAPE)
+               activate = ButtonPolicy::SMI_VALID;
+
+       pos = fl_get_choice(dialog_->choice_size);
+       if (size_[pos-1] != LyXFont::IGNORE_SIZE)
+               activate = ButtonPolicy::SMI_VALID;
+
+       pos = fl_get_choice(dialog_->choice_bar);
+       if (bar_[pos-1] != character::IGNORE)
+               activate = ButtonPolicy::SMI_VALID;
+
+       pos = fl_get_choice(dialog_->choice_color);
+       if (color_[pos-1] != LColor::ignore)
+               activate = ButtonPolicy::SMI_VALID;
+
+       string const language = combo_language2_->getline();
+       if (language != _("No change"))
+               activate = ButtonPolicy::SMI_VALID;
+
+       return activate;
+}