]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormCharacter.C
fix crash with "save as"
[lyx.git] / src / frontends / xforms / FormCharacter.C
index 5324a56149ad02c709f7c1fb9e0faddeba8cf57c..4e5ae3a9d39066ee05eee511e77935b0582897e5 100644 (file)
@@ -1,16 +1,17 @@
-// -*- C++ -*-
 /**
  * \file FormCharacter.C
- * Copyright 2001 The LyX Team.
- * See the file COPYING.
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * \author Edwin Leuven,  leuven@fee.uva.nl
- * \author Angus Leeming, a.leeming@ic.ac.uk
+ * \author Edwin Leuven
+ * \author Angus Leeming 
+ *
+ * Full author contact details are available in file CREDITS
  */
 
 #include <vector>
 
-#ifdef __GNUG_
+#ifdef __GNUG__
 #pragma implementation
 #endif
 
 #include "xformsBC.h"
 #include "ControlCharacter.h"
 #include "FormCharacter.h"
-#include "form_character.h"
+#include "forms/form_character.h"
 #include "gettext.h"
 #include "combox.h"
 #include "helper_funcs.h"
+#include "xforms_helpers.h"
+#include FORMS_H_LOCATION
+
+#include "frnt_lang.h"
+
+#include "support/lstrings.h"
 
 using std::vector;
-using std::back_inserter;
-using std::transform;
-using namespace character;
+using std::find;
 
-typedef FormCB<ControlCharacter, FormDB<FD_form_character> > base_class;
+using namespace frnt;
 
-FormCharacter::FormCharacter(ControlCharacter & c)
-       : base_class(c, _("Character Layout"))
+typedef FormCB<ControlCharacter, FormDB<FD_character> > base_class;
+
+FormCharacter::FormCharacter()
+       : base_class(_("Character Layout"), false)
 {}
 
 
-void FormCharacter::ComboInputCB(int, void * v, Combox * combox)
+void FormCharacter::ComboInputCB(int, void * v, Combox *)
 {
        FormCharacter * pre = static_cast<FormCharacter*>(v);
-       pre->InputCB(reinterpret_cast<FL_OBJECT *>(combox), 0);
+       // must use input() directly, to avoid treating the Combox
+       // as an FL_OBJECT, leading to a crash (bug 406)
+       pre->bc().input(pre->input(0, 0));
 }
 
 void FormCharacter::build()
 {
-       dialog_.reset(build_character());
+       dialog_.reset(build_character(this));
 
-       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();
+       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<LanguagePair> const langs  = getLanguageData(true);
 
-       // Store the enums for later
+       // Store the identifiers for later
        family_ = getSecond(family);
        series_ = getSecond(series);
-       shape_ = getSecond(shape);
-       size_ = getSecond(size);
-       bar_ = getSecond(bar);
-       color_ = getSecond(color);
+       shape_  = getSecond(shape);
+       size_   = getSecond(size);
+       bar_    = getSecond(bar);
+       color_  = getSecond(color);
+       lang_   = getSecond(langs);
 
        // create a string of entries " entry1 | entry2 | entry3 | entry4 "
        // with which to initialise the xforms choice object.
@@ -87,21 +97,22 @@ void FormCharacter::build()
 
        // insert default language box manually
        fl_addto_form(dialog_->form);
-               FL_OBJECT * ob = dialog_->choice_language;
-               fl_deactivate_object(dialog_->choice_language);
+       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);
-               combo_language2_->setcallback(ComboInputCB, this);
+       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);
+       combo_language2_->setcallback(ComboInputCB, this);
        fl_end_form();
 
        // build up the combox entries
-       for (vector<string>::const_iterator cit = language.begin(); 
-            cit != language.end(); ++cit) {
-               combo_language2_->addto(*cit);
+       vector<LanguagePair>::const_iterator it  = langs.begin();
+       vector<LanguagePair>::const_iterator end = langs.end();
+       for (; it != end; ++it) {
+               combo_language2_->addto(it->first);
        }
-       combo_language2_->select_text(*language.begin());
+       combo_language2_->select(1);
 
        // Manage the ok, apply and cancel/close buttons
        bc().setApply(dialog_->button_apply);
@@ -115,48 +126,36 @@ void FormCharacter::apply()
        if (!form()) return;
 
        int pos = fl_get_choice(dialog_->choice_family);
-       controller().setFamily(family_[pos-1]);
+       controller().setFamily(family_[pos - 1]);
 
        pos = fl_get_choice(dialog_->choice_series);
-       controller().setSeries(series_[pos-1]);
-   
+       controller().setSeries(series_[pos - 1]);
+
        pos = fl_get_choice(dialog_->choice_shape);
-       controller().setShape(shape_[pos-1]);
+       controller().setShape(shape_[pos - 1]);
 
        pos = fl_get_choice(dialog_->choice_size);
-       controller().setSize(size_[pos-1]);
-   
+       controller().setSize(size_[pos - 1]);
+
        pos = fl_get_choice(dialog_->choice_bar);
-       controller().setBar(bar_[pos-1]);
-   
+       controller().setBar(bar_[pos - 1]);
+
        pos = fl_get_choice(dialog_->choice_color);
-       controller().setColor(color_[pos-1]);
+       controller().setColor(color_[pos - 1]);
 
-       controller().setLanguage(combo_language2_->getline());
+       pos = combo_language2_->get();
+       controller().setLanguage(lang_[pos - 1]);
 
        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);
 
@@ -172,7 +171,8 @@ void FormCharacter::update()
        pos = int(findPos(color_, controller().getColor()));
        fl_set_choice(dialog_->choice_color, pos+1);
 
-       combo_language2_->select_text(controller().getLanguage());
+       pos = int(findPos(lang_, controller().getLanguage()));
+       combo_language2_->select(pos+1);
 
        fl_set_button(dialog_->check_toggle_all, controller().getToggleAll());
 }
@@ -183,31 +183,31 @@ 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)
+       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)
+       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)
+       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)
+       if (size_[pos - 1] != LyXFont::IGNORE_SIZE)
                activate = ButtonPolicy::SMI_VALID;
 
        pos = fl_get_choice(dialog_->choice_bar);
-       if (bar_[pos-1] != character::IGNORE)
+       if (bar_[pos - 1] != frnt::IGNORE)
                activate = ButtonPolicy::SMI_VALID;
 
        pos = fl_get_choice(dialog_->choice_color);
-       if (color_[pos-1] != LColor::ignore)
+       if (color_[pos - 1] != LColor::ignore)
                activate = ButtonPolicy::SMI_VALID;
 
-       string const language = combo_language2_->getline();
-       if (language != _("No change"))
+       pos = combo_language2_->get();
+       if (lang_[pos - 1] != "No change")
                activate = ButtonPolicy::SMI_VALID;
 
        return activate;