From bcd61505ab6ddebd8fea484a94feb02314ec1dca Mon Sep 17 00:00:00 2001 From: jules Date: Thu, 6 Dec 2012 16:34:17 +0000 Subject: [PATCH] ChoicePropertyComponent: better handling of var types. --- .../juce_ChoicePropertyComponent.cpp | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/modules/juce_gui_basics/properties/juce_ChoicePropertyComponent.cpp b/modules/juce_gui_basics/properties/juce_ChoicePropertyComponent.cpp index e8a4995bd8..20ed7717d8 100644 --- a/modules/juce_gui_basics/properties/juce_ChoicePropertyComponent.cpp +++ b/modules/juce_gui_basics/properties/juce_ChoicePropertyComponent.cpp @@ -27,23 +27,28 @@ class ChoicePropertyComponent::RemapperValueSource : public Value::ValueSourc private ValueListener { public: - RemapperValueSource (const Value& sourceValue_, const Array& mappings_) - : sourceValue (sourceValue_), - mappings (mappings_) + RemapperValueSource (const Value& source, const Array& map) + : sourceValue (source), mappings (map) { sourceValue.addListener (this); } var getValue() const { - return mappings.indexOf (sourceValue.getValue()) + 1; + const var targetValue (sourceValue.getValue()); + + for (int i = 0; i < mappings.size(); ++i) + if (mappings.getReference(i).equalsWithSameType (targetValue)) + return i + 1; + + return mappings.indexOf (targetValue) + 1; } void setValue (const var& newValue) { - const var remappedVal (mappings [(int) newValue - 1]); + const var remappedVal (mappings [static_cast (newValue) - 1]); - if (remappedVal != sourceValue) + if (! remappedVal.equalsWithSameType (sourceValue)) sourceValue = remappedVal; } @@ -69,10 +74,10 @@ ChoicePropertyComponent::ChoicePropertyComponent (const String& name) ChoicePropertyComponent::ChoicePropertyComponent (const Value& valueToControl, const String& name, - const StringArray& choices_, + const StringArray& choiceList, const Array & correspondingValues) : PropertyComponent (name), - choices (choices_), + choices (choiceList), isCustomClass (false) { // The array of corresponding values must contain one value for each of the items in @@ -81,7 +86,8 @@ ChoicePropertyComponent::ChoicePropertyComponent (const Value& valueToControl, createComboBox(); - comboBox.getSelectedIdAsValue().referTo (Value (new RemapperValueSource (valueToControl, correspondingValues))); + comboBox.getSelectedIdAsValue().referTo (Value (new RemapperValueSource (valueToControl, + correspondingValues))); } ChoicePropertyComponent::~ChoicePropertyComponent()