| @@ -181,6 +181,15 @@ public: | |||||
| /** Returns the property ID of the referenced property. */ | /** Returns the property ID of the referenced property. */ | ||||
| Identifier& getPropertyID() noexcept { return targetProperty; } | Identifier& getPropertyID() noexcept { return targetProperty; } | ||||
| //============================================================================== | |||||
| ValueWithDefault& operator= (const ValueWithDefault& other) | |||||
| { | |||||
| referToWithDefault (other.targetTree, other.targetProperty, other.undoManager, | |||||
| other.defaultValue, other.delimiter); | |||||
| return *this; | |||||
| } | |||||
| private: | private: | ||||
| //============================================================================== | //============================================================================== | ||||
| ValueTree targetTree; | ValueTree targetTree; | ||||
| @@ -191,7 +200,7 @@ private: | |||||
| String delimiter; | String delimiter; | ||||
| //============================================================================== | //============================================================================== | ||||
| void referToWithDefault (ValueTree& v, const Identifier& i, UndoManager* um, | |||||
| void referToWithDefault (const ValueTree& v, const Identifier& i, UndoManager* um, | |||||
| const var& defaultVal, StringRef del) | const var& defaultVal, StringRef del) | ||||
| { | { | ||||
| targetTree = v; | targetTree = v; | ||||
| @@ -225,6 +234,9 @@ private: | |||||
| return arr; | return arr; | ||||
| } | } | ||||
| //============================================================================== | |||||
| JUCE_DECLARE_WEAK_REFERENCEABLE (ValueWithDefault) | |||||
| }; | }; | ||||
| } // namespace juce | } // namespace juce | ||||
| @@ -83,6 +83,9 @@ public: | |||||
| var getValue() const override | var getValue() const override | ||||
| { | { | ||||
| if (valueWithDefault == nullptr) | |||||
| return {}; | |||||
| if (valueWithDefault->isUsingDefault()) | if (valueWithDefault->isUsingDefault()) | ||||
| return -1; | return -1; | ||||
| @@ -97,6 +100,9 @@ public: | |||||
| void setValue (const var& newValue) override | void setValue (const var& newValue) override | ||||
| { | { | ||||
| if (valueWithDefault == nullptr) | |||||
| return; | |||||
| auto newValueInt = static_cast<int> (newValue); | auto newValueInt = static_cast<int> (newValue); | ||||
| if (newValueInt == -1) | if (newValueInt == -1) | ||||
| @@ -115,7 +121,7 @@ public: | |||||
| private: | private: | ||||
| void valueChanged (Value&) override { sendChangeMessage (true); } | void valueChanged (Value&) override { sendChangeMessage (true); } | ||||
| ValueWithDefault* valueWithDefault = nullptr; | |||||
| WeakReference<ValueWithDefault> valueWithDefault; | |||||
| Value sourceValue; | Value sourceValue; | ||||
| Array<var> mappings; | Array<var> mappings; | ||||
| @@ -84,7 +84,6 @@ public: | |||||
| default value with an ID of -1. | default value with an ID of -1. | ||||
| @param valueToControl the ValueWithDefault object that contains the Value object that the combo box will read and control. | @param valueToControl the ValueWithDefault object that contains the Value object that the combo box will read and control. | ||||
| NB: this object must outlive the ChoicePropertyComponent. | |||||
| @param propertyName the name of the property | @param propertyName the name of the property | ||||
| @param choices the list of possible values that the drop-down list will contain | @param choices the list of possible values that the drop-down list will contain | ||||
| @param correspondingValues a list of values corresponding to each item in the 'choices' StringArray. | @param correspondingValues a list of values corresponding to each item in the 'choices' StringArray. | ||||
| @@ -154,7 +153,7 @@ private: | |||||
| ComboBox comboBox; | ComboBox comboBox; | ||||
| bool isCustomClass = false; | bool isCustomClass = false; | ||||
| ValueWithDefault* valueWithDefault = nullptr; | |||||
| WeakReference<ValueWithDefault> valueWithDefault; | |||||
| //============================================================================== | //============================================================================== | ||||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChoicePropertyComponent) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChoicePropertyComponent) | ||||
| @@ -118,6 +118,9 @@ public: | |||||
| var getValue() const override | var getValue() const override | ||||
| { | { | ||||
| if (valueWithDefault == nullptr) | |||||
| return {}; | |||||
| auto v = valueWithDefault->get(); | auto v = valueWithDefault->get(); | ||||
| if (auto* arr = v.getArray()) | if (auto* arr = v.getArray()) | ||||
| @@ -134,6 +137,9 @@ public: | |||||
| void setValue (const var& newValue) override | void setValue (const var& newValue) override | ||||
| { | { | ||||
| if (valueWithDefault == nullptr) | |||||
| return; | |||||
| auto v = valueWithDefault->get(); | auto v = valueWithDefault->get(); | ||||
| OptionalScopedPointer<Array<var>> arrayToControl; | OptionalScopedPointer<Array<var>> arrayToControl; | ||||
| @@ -191,7 +197,7 @@ private: | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| ValueWithDefault* valueWithDefault = nullptr; | |||||
| WeakReference<ValueWithDefault> valueWithDefault; | |||||
| var varToControl; | var varToControl; | ||||
| Value sourceValue; | Value sourceValue; | ||||
| @@ -67,7 +67,6 @@ public: | |||||
| /** Creates the component using a ValueWithDefault object. This will select the default options. | /** Creates the component using a ValueWithDefault object. This will select the default options. | ||||
| @param valueToControl the ValueWithDefault object that contains the Value object that the ToggleButtons will read and control. | @param valueToControl the ValueWithDefault object that contains the Value object that the ToggleButtons will read and control. | ||||
| NB: This object must outlive the MultiChoicePropertyComponent. | |||||
| @param propertyName the name of the property | @param propertyName the name of the property | ||||
| @param choices the list of possible values that will be represented | @param choices the list of possible values that will be represented | ||||
| @param correspondingValues a list of values corresponding to each item in the 'choices' StringArray. | @param correspondingValues a list of values corresponding to each item in the 'choices' StringArray. | ||||
| @@ -119,7 +118,7 @@ private: | |||||
| void lookAndFeelChanged() override; | void lookAndFeelChanged() override; | ||||
| //============================================================================== | //============================================================================== | ||||
| ValueWithDefault* valueWithDefault = nullptr; | |||||
| WeakReference<ValueWithDefault> valueWithDefault; | |||||
| int maxHeight = 0; | int maxHeight = 0; | ||||
| int numHidden = 0; | int numHidden = 0; | ||||
| @@ -131,11 +131,17 @@ public: | |||||
| var getValue() const override | var getValue() const override | ||||
| { | { | ||||
| return valueWithDefault->isUsingDefault() ? var() : valueWithDefault->get(); | |||||
| if (valueWithDefault == nullptr || valueWithDefault->isUsingDefault()) | |||||
| return {}; | |||||
| return valueWithDefault->get(); | |||||
| } | } | ||||
| void setValue (const var& newValue) override | void setValue (const var& newValue) override | ||||
| { | { | ||||
| if (valueWithDefault == nullptr) | |||||
| return; | |||||
| if (newValue.toString().isEmpty()) | if (newValue.toString().isEmpty()) | ||||
| valueWithDefault->resetToDefault(); | valueWithDefault->resetToDefault(); | ||||
| else | else | ||||
| @@ -143,7 +149,7 @@ public: | |||||
| } | } | ||||
| private: | private: | ||||
| ValueWithDefault* valueWithDefault = nullptr; | |||||
| WeakReference<ValueWithDefault> valueWithDefault; | |||||
| //============================================================================== | //============================================================================== | ||||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (RemapperValueSourceWithDefault) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (RemapperValueSourceWithDefault) | ||||
| @@ -75,7 +75,6 @@ public: | |||||
| /** Creates a text property component with a default value. | /** Creates a text property component with a default value. | ||||
| @param valueToControl The ValueWithDefault that is controlled by the TextPropertyComponent. | @param valueToControl The ValueWithDefault that is controlled by the TextPropertyComponent. | ||||
| NB: this object must outlive the TextPropertyComponent. | |||||
| @param propertyName The name of the property | @param propertyName The name of the property | ||||
| @param maxNumChars If not zero, then this specifies the maximum allowable length of | @param maxNumChars If not zero, then this specifies the maximum allowable length of | ||||
| the string. If zero, then the string will have no length limit. | the string. If zero, then the string will have no length limit. | ||||
| @@ -183,7 +182,7 @@ private: | |||||
| std::unique_ptr<LabelComp> textEditor; | std::unique_ptr<LabelComp> textEditor; | ||||
| ListenerList<Listener> listenerList; | ListenerList<Listener> listenerList; | ||||
| ValueWithDefault* valueWithDefault = nullptr; | |||||
| WeakReference<ValueWithDefault> valueWithDefault; | |||||
| //============================================================================== | //============================================================================== | ||||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TextPropertyComponent) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TextPropertyComponent) | ||||