From: Kingsley Stephens Date: Thu, 29 May 2014 14:27:41 +0000 (+0100) Subject: (StyleManager) Add style monitor signal into StyleManager X-Git-Tag: dali_1.0.0~72 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=f4d5b3ffc194fc1b1c14f4a79e3efa435a31bc32 (StyleManager) Add style monitor signal into StyleManager [problem] The StyleManager was missing the StyleMonitor signal [solution] Connect StyleManager to StyleMonitor style change signal patch 2: combine ThemeChangeSignal and StyleChangeSignal into one Change-Id: I8141b0b71091b42b6c0a2db047272ded6d21b273 --- diff --git a/automated-tests/TET/dali-test-suite/control/dummy-control.h b/automated-tests/TET/dali-test-suite/control/dummy-control.h index 18c10f9..0adee2d 100644 --- a/automated-tests/TET/dali-test-suite/control/dummy-control.h +++ b/automated-tests/TET/dali-test-suite/control/dummy-control.h @@ -138,7 +138,8 @@ private: DummyControlImplOverride() : DummyControlImpl(), initializeCalled(false), - styleChangeCalled(false), + themeChangeCalled(false), + fontChangeCalled( false ), pinchCalled(false), panCalled(false), tapCalled(false), @@ -162,7 +163,8 @@ private: private: // From ControlImpl virtual void OnInitialize() { initializeCalled = true; } - virtual void OnStyleChange(StyleChange change) { styleChangeCalled = true;} + virtual void OnThemeChange( StyleManager styleManager ) { themeChangeCalled = true } + virtual void OnFontChange( bool defaultFontChange, bool defaultFontSizeChange ) { fontChangeCalled = true;} virtual void OnPinch(PinchGesture pinch) { pinchCalled = true; } virtual void OnPan(PanGesture pan) { panCalled = true; } virtual void OnTap(TapGesture tap) { tapCalled = true; } @@ -185,7 +187,8 @@ private: // From CustomActorImpl public: bool initializeCalled; - bool styleChangeCalled; + bool themeChangeCalled; + bool fontChangeCalled; bool pinchCalled; bool panCalled; bool tapCalled; diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.cpp index 8640002..76893de 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.cpp @@ -16,6 +16,8 @@ #include "dummy-control.h" +#include + namespace Dali { @@ -65,7 +67,7 @@ DummyControl DummyControlImpl::New() } DummyControlImpl::DummyControlImpl() -: Control(true) +: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ) { } @@ -85,7 +87,8 @@ DummyControl DummyControlImplOverride::New() DummyControlImplOverride::DummyControlImplOverride() : DummyControlImpl(), initializeCalled(false), - styleChangeCalled(false), + themeChangeCalled( false ), + fontChangeCalled( false ), pinchCalled(false), panCalled(false), tapCalled(false), @@ -108,7 +111,8 @@ DummyControlImplOverride::~DummyControlImplOverride() { } void DummyControlImplOverride::OnInitialize() { initializeCalled = true; } -void DummyControlImplOverride::OnStyleChange(StyleChange change) { styleChangeCalled = true;} +void DummyControlImplOverride::OnThemeChange(StyleManager change) { themeChangeCalled = true;} +void DummyControlImplOverride::OnFontChange(bool defaultFontChange, bool defaultFontSizeChange) { fontChangeCalled = true; } void DummyControlImplOverride::OnPinch(PinchGesture pinch) { pinchCalled = true; } void DummyControlImplOverride::OnPan(PanGesture pan) { panCalled = true; } void DummyControlImplOverride::OnTap(TapGesture tap) { tapCalled = true; } diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.h b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.h index 649ac0a..40dcf4f 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.h +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.h @@ -104,7 +104,8 @@ private: private: // From Internal::Control virtual void OnInitialize(); - virtual void OnStyleChange(StyleChange change); + virtual void OnThemeChange( StyleManager styleManager ); + virtual void OnFontChange(bool defaultFontChange, bool defaultFontSizeChange); virtual void OnPinch(PinchGesture pinch); virtual void OnPan(PanGesture pan); virtual void OnTap(TapGesture tap); @@ -127,7 +128,8 @@ private: // From CustomActorImpl public: bool initializeCalled; - bool styleChangeCalled; + bool themeChangeCalled; + bool fontChangeCalled; bool pinchCalled; bool panCalled; bool tapCalled; diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ControlImpl.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ControlImpl.cpp index f704531..1e40bcc 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ControlImpl.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ControlImpl.cpp @@ -652,13 +652,13 @@ int UtcDaliControlImplStyleChange(void) Actor actor = Actor::New(); dummy.Add(actor); - DALI_TEST_EQUALS( dummyImpl.styleChangeCalled, false, TEST_LOCATION ); + DALI_TEST_EQUALS( dummyImpl.fontChangeCalled, false, TEST_LOCATION ); StyleChange styleChange; styleChange.defaultFontChange = true; Dali::StyleMonitor styleMonitor = application.GetAdaptor().GetToolkitStyleMonitor(); styleMonitor.EmitStyleChangeSignal(styleChange); - DALI_TEST_EQUALS( dummyImpl.styleChangeCalled, true, TEST_LOCATION ); + DALI_TEST_EQUALS( dummyImpl.fontChangeCalled, true, TEST_LOCATION ); Stage::GetCurrent().Remove(dummy); END_TEST; diff --git a/base/dali-toolkit/internal/controls/buttons/button-impl.cpp b/base/dali-toolkit/internal/controls/buttons/button-impl.cpp index 941ebcc..f3efbc3 100644 --- a/base/dali-toolkit/internal/controls/buttons/button-impl.cpp +++ b/base/dali-toolkit/internal/controls/buttons/button-impl.cpp @@ -52,7 +52,7 @@ PropertyRegistration property1( typeRegistration, "dimmed", Toolkit::Button::PRO } // unnamed namespace Button::Button() -: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_THEME_CHANGE_SIGNALS ) ), +: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ), mState( ButtonUp ), mDimmed( false ), mPainter( NULL ) diff --git a/base/dali-toolkit/internal/controls/popup/popup-impl.cpp b/base/dali-toolkit/internal/controls/popup/popup-impl.cpp index 7f3b7c0..e453401 100755 --- a/base/dali-toolkit/internal/controls/popup/popup-impl.cpp +++ b/base/dali-toolkit/internal/controls/popup/popup-impl.cpp @@ -169,7 +169,7 @@ Dali::Toolkit::Popup Popup::New() } Popup::Popup(PopupStyle& style) -: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_THEME_CHANGE_SIGNALS ) ), +: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ), mShowing(false), mState(Toolkit::Popup::POPUP_NONE), // Initially, the popup state should not be set, it's set in OnInitialize mAlterAddedChild(false), diff --git a/base/dali-toolkit/internal/controls/scrollable/scrollable-impl.cpp b/base/dali-toolkit/internal/controls/scrollable/scrollable-impl.cpp index 6c4da93..ac8b7f1 100644 --- a/base/dali-toolkit/internal/controls/scrollable/scrollable-impl.cpp +++ b/base/dali-toolkit/internal/controls/scrollable/scrollable-impl.cpp @@ -61,7 +61,7 @@ const Vector4 Scrollable::DEFAULT_OVERSHOOT_COLOUR(0.0f, 0.64f, 0.85f, 0.6f) /////////////////////////////////////////////////////////////////////////////////////////////////// Scrollable::Scrollable() -: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_THEME_CHANGE_SIGNALS ) ), +: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ), mPropertyRelativePosition(Property::INVALID_INDEX), mPropertyPositionMin(Property::INVALID_INDEX), mPropertyPositionMax(Property::INVALID_INDEX), diff --git a/base/dali-toolkit/internal/controls/style-change-processor.cpp b/base/dali-toolkit/internal/controls/style-change-processor.cpp deleted file mode 100644 index 46f940e..0000000 --- a/base/dali-toolkit/internal/controls/style-change-processor.cpp +++ /dev/null @@ -1,122 +0,0 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#include "style-change-processor.h" - -#include - -#include "dali-toolkit/public-api/controls/control.h" -#include "dali-toolkit/public-api/controls/control-impl.h" - -namespace Dali -{ - -namespace Toolkit -{ - -namespace Internal -{ - -namespace -{ -boost::thread_specific_ptr gThreadLocalStyleChangeProcessor; -} // unnamed namespace - -StyleChangeProcessor::~StyleChangeProcessor() -{ -} - -void StyleChangeProcessor::Register( Control* control ) -{ - // Only create a style change processor if we have not created one in the local thread storage. - if (!gThreadLocalStyleChangeProcessor.get()) - { - gThreadLocalStyleChangeProcessor.reset(new StyleChangeProcessor); - } - - gThreadLocalStyleChangeProcessor->Reference(); - - std::vector& controls( gThreadLocalStyleChangeProcessor->mControls ); - - // Store the Control raw pointer to allow traverse all off stage controls. - DALI_ASSERT_ALWAYS( ( std::find( controls.begin(), controls.end(), control ) == controls.end() ) && "StyleChangeProcessor::Register. The control has been registered twice." ); - - controls.push_back( control ); -} - -void StyleChangeProcessor::Unregister( Control* control ) -{ - if (gThreadLocalStyleChangeProcessor.get()) - { - std::vector& controls( gThreadLocalStyleChangeProcessor->mControls ); - - // Removes the control from the vector as is not needed to notify it about style changes. - std::vector::iterator it = std::find( controls.begin(), controls.end(), control ); - std::vector::iterator endIt = controls.end(); - DALI_ASSERT_ALWAYS( ( it != endIt ) && "StyleChangeProcessor::UnRegister. The control has not been registered in the StyleChangeProcessor." ); - - *it = *(endIt - 1); - controls.erase( endIt - 1 ); - - gThreadLocalStyleChangeProcessor->Unreference(); - } -} - -void StyleChangeProcessor::Reference() -{ - ++mCount; -} - -void StyleChangeProcessor::Unreference() -{ - if (--mCount == 0) - { - // If our count is 0, then we should reset the local storage which will call our destructor as well. - gThreadLocalStyleChangeProcessor.reset(); - } -} - -StyleChangeProcessor::StyleChangeProcessor() -: mCount(0) -{ - if ( Adaptor::IsAvailable() ) - { - StyleMonitor::Get().StyleChangeSignal().Connect(this, &StyleChangeProcessor::StyleChanged); - } -} - -void StyleChangeProcessor::StyleChanged(Dali::StyleMonitor styleMonitor, StyleChange styleChange) -{ - // Traverse all registered controls. - std::vector& controls( gThreadLocalStyleChangeProcessor->mControls ); - - for( std::vector::iterator it = controls.begin(), endIt = controls.end(); it != endIt; ++it ) - { - // Create a valid handle. - IntrusivePtr implementation( *it ); - - if (implementation) - { - implementation->OnStyleChange( styleChange ); - } - } -} - -} // namespace Internal - -} // namespace Toolkit - -} // namespace Dali diff --git a/base/dali-toolkit/internal/controls/style-change-processor.h b/base/dali-toolkit/internal/controls/style-change-processor.h deleted file mode 100644 index 062bd5e..0000000 --- a/base/dali-toolkit/internal/controls/style-change-processor.h +++ /dev/null @@ -1,125 +0,0 @@ -#ifndef __DALI_TOOLKIT_INTERNAL_STYLE_CHANGE_PROCESSOR_H_ -#define __DALI_TOOLKIT_INTERNAL_STYLE_CHANGE_PROCESSOR_H_ - -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -// INTERNAL INCLUDES -#include - -namespace Dali -{ - -namespace Toolkit -{ - -namespace Internal -{ - -class Control; - -/** - * This observes and processes when any style changes occur. When they do occur, it traverses through - * all registered controls and calls the StyleChanged method. - * - * This is created when a control first registers with it. Subsequent registrations increase the - * reference count. When the last control unregisters, i.e. the reference count is 0, the instance - * is also destroyed. - */ -class StyleChangeProcessor : public ConnectionTracker -{ -public: - - /** - * Non virtual destructor. - * We should not derive from StyleChangeProcessor. - * Destructor is called when the last control unregisters. - */ - ~StyleChangeProcessor(); - - /** - * Registers a control with the StyleChangeProcessor. - * @param[in] control The raw Control pointer. - */ - static void Register( Control* control ); - - /** - * Unregisters a control from the StyleChangeProcessor. - * @param[in] control The raw Control pointer. - */ - static void Unregister( Control* control ); - -public: - - /** - * Increment the processor's reference count. - */ - void Reference(); - - /** - * Decrement the processor's reference count. - */ - void Unreference(); - - /** - * Retrieve the processor's reference count. - * @return The reference count - */ - unsigned int ReferenceCount() const; - -private: - - /** - * Constructor. - * We should only create an instance upon first registration. - */ - StyleChangeProcessor(); - - // Undefined - StyleChangeProcessor(const StyleChangeProcessor&); - StyleChangeProcessor& operator=(const StyleChangeProcessor&); - -private: - - /** - * Callback for the StyleMonitor when the style changes on the platform. - * @param[in] styleMonitor The Style Monitor. - * @param[in] styleChange The style change information. - */ - void StyleChanged(Dali::StyleMonitor styleMonitor, Dali::StyleChange styleChange); - - /** - * Propagates the style change to all Controls in the actor hierarchy. - * This is done with a bottom-up approach, i.e. the leaf Control's StyleChange method gets - * called first followed by its parent and so on. - * @param[in] actor The actor whose children to process and send style change notification to. - * @param[in] change The style change. - */ - static void PropagateStyleChange(Actor actor, Dali::StyleChange change); - -private: - - unsigned int mCount; ///< The reference count - std::vector mControls; ///< Stores all registered controls. -}; - -} // namespace Internal - -} // namespace Toolkit - -} // namespace Dali - -#endif // __DALI_TOOLKIT_INTERNAL_STYLE_CHANGE_PROCESSOR_H_ diff --git a/base/dali-toolkit/internal/controls/table-view/table-view-impl.cpp b/base/dali-toolkit/internal/controls/table-view/table-view-impl.cpp index fff8bc4..72d58af 100644 --- a/base/dali-toolkit/internal/controls/table-view/table-view-impl.cpp +++ b/base/dali-toolkit/internal/controls/table-view/table-view-impl.cpp @@ -794,7 +794,7 @@ void TableView::OnControlChildRemove( Actor& child ) } TableView::TableView( unsigned int initialRows, unsigned int initialColumns ) -: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_THEME_CHANGE_SIGNALS ) ), +: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ), mCellData( initialRows, initialColumns ), mLayoutingChild( false ), mConstraintDuration( DEFAULT_CONSTRAINT_DURATION ) diff --git a/base/dali-toolkit/internal/controls/text-input/text-input-impl.cpp b/base/dali-toolkit/internal/controls/text-input/text-input-impl.cpp index 3d79aad..ed8211d 100644 --- a/base/dali-toolkit/internal/controls/text-input/text-input-impl.cpp +++ b/base/dali-toolkit/internal/controls/text-input/text-input-impl.cpp @@ -269,7 +269,7 @@ Dali::Toolkit::TextInput TextInput::New() } TextInput::TextInput() -:Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_THEME_CHANGE_SIGNALS ) ), +:Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ), mState( StateEdit ), mStyledText(), mInputStyle(), diff --git a/base/dali-toolkit/internal/controls/text-view/text-view-impl.cpp b/base/dali-toolkit/internal/controls/text-view/text-view-impl.cpp index 78c4980..728bee6 100644 --- a/base/dali-toolkit/internal/controls/text-view/text-view-impl.cpp +++ b/base/dali-toolkit/internal/controls/text-view/text-view-impl.cpp @@ -1009,7 +1009,7 @@ TextView::RelayoutData& TextView::RelayoutData::operator=( const TextView::Relay } TextView::TextView() -: Control( REQUIRES_THEME_CHANGE_SIGNALS ), +: Control( REQUIRES_STYLE_CHANGE_SIGNALS ), mCurrentStyledText(), mTextViewProcessorOperations(), mLayoutParameters( Toolkit::TextView::SplitByNewLineChar, @@ -1149,7 +1149,7 @@ void TextView::OnInitialize() } -void TextView::OnStyleChange( StyleChange change ) +void TextView::OnFontChange( bool defaultFontChange, bool defaultFontSizeChange ) { mRelayoutData.mTextLayoutInfo.mEllipsizeLayoutInfo = TextViewProcessor::WordLayoutInfo(); TextViewProcessor::CreateWordTextInfo( mLayoutParameters.mEllipsizeText, diff --git a/base/dali-toolkit/internal/controls/text-view/text-view-impl.h b/base/dali-toolkit/internal/controls/text-view/text-view-impl.h index e4e7dd4..8c66ae2 100644 --- a/base/dali-toolkit/internal/controls/text-view/text-view-impl.h +++ b/base/dali-toolkit/internal/controls/text-view/text-view-impl.h @@ -363,9 +363,9 @@ private: // From Control virtual void OnInitialize(); /** - * @copydoc Toolkit::Control::OnStyleChange() + * @copydoc Toolkit::Control::OnFontChange( ) */ - virtual void OnStyleChange( StyleChange change ); + virtual void OnFontChange( bool defaultFontChange, bool defaultFontSizeChange ); /** * @copydoc Toolkit::Control::OnControlSizeSet() diff --git a/base/dali-toolkit/internal/styling/style-manager-impl.cpp b/base/dali-toolkit/internal/styling/style-manager-impl.cpp index 56b97f8..46e9162 100644 --- a/base/dali-toolkit/internal/styling/style-manager-impl.cpp +++ b/base/dali-toolkit/internal/styling/style-manager-impl.cpp @@ -110,6 +110,11 @@ StyleManager::StyleManager() mThemeBuilderConstants[ PACKAGE_PATH_KEY ] = DEFAULT_PACKAGE_PATH; RequestDefaultTheme(); + + if( Adaptor::IsAvailable() ) + { + StyleMonitor::Get().StyleChangeSignal().Connect( this, &StyleManager::StyleMonitorChange ); + } } StyleManager::~StyleManager() @@ -330,17 +335,9 @@ bool StyleManager::LoadFile( const std::string& filename, std::string& stringOut return false; } -Toolkit::StyleManager::ThemeChangeSignalType& StyleManager::ThemeChangeSignal() +Toolkit::StyleManager::StyleChangeSignalType& StyleManager::StyleChangeSignal() { - return mThemeChangeSignal; -} - -void StyleManager::EmitThemeChangeSignal() -{ - if( !mThemeChangeSignal.Empty() ) - { - mThemeChangeSignal.Emit( Toolkit::StyleManager::Get() ); - } + return mStyleChangeSignal; } void StyleManager::RequestThemeChange( const std::string& themeFile ) @@ -368,7 +365,9 @@ void StyleManager::SetTheme() mSetThemeConnection = false; - EmitThemeChangeSignal(); + StyleChange change; + change.themeChange = true; + mStyleChangeSignal.Emit( Toolkit::StyleManager::Get(), change ); } Toolkit::Builder StyleManager::FindCachedBuilder( const std::string& key ) @@ -387,6 +386,11 @@ void StyleManager::CacheBuilder( Toolkit::Builder builder, const std::string& ke mBuilderCache[ key ] = builder; } +void StyleManager::StyleMonitorChange( StyleMonitor styleMonitor, StyleChange styleChange ) +{ + mStyleChangeSignal.Emit( Toolkit::StyleManager::Get(), styleChange ); +} + } // namespace Internal } // namespace Toolkit diff --git a/base/dali-toolkit/internal/styling/style-manager-impl.h b/base/dali-toolkit/internal/styling/style-manager-impl.h index 2c15f89..2fae34a 100644 --- a/base/dali-toolkit/internal/styling/style-manager-impl.h +++ b/base/dali-toolkit/internal/styling/style-manager-impl.h @@ -116,9 +116,9 @@ public: // SIGNALS /** - * @copydoc Toolkit::StyleManager::ThemeChangeSignal + * @copydoc Toolkit::StyleManager::StyleChangeSignal */ - Toolkit::StyleManager::ThemeChangeSignalType& ThemeChangeSignal(); + Toolkit::StyleManager::StyleChangeSignalType& StyleChangeSignal(); protected: @@ -193,11 +193,6 @@ private: void ApplyStyle( Toolkit::Builder builder, Toolkit::Control control ); /** - * @brief Emit theme changed signal - */ - void EmitThemeChangeSignal(); - - /** * @brief Callback for orientation changes * * @param[in] orientation The orientation object @@ -220,6 +215,14 @@ private: */ void CacheBuilder( Toolkit::Builder builder, const std::string& key ); + /** + * Callback for when style monitor raises a signal + * + * @param[in] styleMonitor The style monitor object + * @param[in] styleChange The style change data + */ + void StyleMonitorChange( StyleMonitor styleMonitor, StyleChange styleChange ); + // Undefined StyleManager(const StyleManager&); @@ -245,7 +248,7 @@ private: bool mSetThemeConnection; ///< Has the callback to set the theme been set // Signals - Toolkit::StyleManager::ThemeChangeSignalType mThemeChangeSignal; ///< Emitted when the theme changes + Toolkit::StyleManager::StyleChangeSignalType mStyleChangeSignal; ///< Emitted when the style( theme/font ) changes }; } // namespace Internal diff --git a/base/dali-toolkit/public-api/controls/control-impl.cpp b/base/dali-toolkit/public-api/controls/control-impl.cpp index d8d1e36..5ecacd7 100644 --- a/base/dali-toolkit/public-api/controls/control-impl.cpp +++ b/base/dali-toolkit/public-api/controls/control-impl.cpp @@ -576,15 +576,12 @@ void Control::Initialize() // Calling deriving classes OnInitialize(); - if( mImpl->mFlags & REQUIRES_THEME_CHANGE_SIGNALS ) + if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS ) { Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get(); - // Register for font/theme changes - styleManager.ThemeChangeSignal().Connect( this, &ControlImpl::OnThemeChange ); - - // Set theme - GetImpl( styleManager ).ApplyThemeStyle( GetOwner() ); + // Register for style changes + styleManager.StyleChangeSignal().Connect( this, &ControlImpl::DoStyleChange ); } mImpl->mInitialized = true; @@ -743,6 +740,11 @@ Actor Control::GetBackgroundActor() const return Actor(); } +void Control::OnThemeChange( Toolkit::StyleManager styleManager ) +{ + GetImpl( styleManager ).ApplyThemeStyle( GetOwner() ); +} + void Control::OnPinch(PinchGesture pinch) { if (pinch.state == Gesture::Started) @@ -906,6 +908,21 @@ void Control::DoActivatedAction(const PropertyValueContainer& attributes) OnActivated(); } +void Control::DoStyleChange( Toolkit::StyleManager styleManager, StyleChange change ) +{ + if( change.themeChange ) + { + OnThemeChange( styleManager ); + } + else if( change.defaultFontChange || change.defaultFontSizeChange ) + { + // This OnStyleChange(StyleChange change ) is deprecated, use OnFontChange instead + OnStyleChange( change ); + + OnFontChange( change.defaultFontChange, change.defaultFontSizeChange ); + } +} + Toolkit::Control::KeyEventSignalV2& Control::KeyEventSignal() { return mImpl->mKeyEventSignalV2; @@ -1188,11 +1205,6 @@ void Control::NegotiateSize( Vector2 allocatedSize, ActorSizeContainer& containe Relayout( size, container ); } -void Control::OnThemeChange( Toolkit::StyleManager styleManager ) -{ - GetImpl( styleManager ).ApplyThemeStyle( GetOwner() ); -} - bool Control::EmitKeyEventSignal( const KeyEvent& event ) { // Guard against destruction during signal emission diff --git a/base/dali-toolkit/public-api/controls/scrollable/scroll-component-impl.cpp b/base/dali-toolkit/public-api/controls/scrollable/scroll-component-impl.cpp index 2b089f7..45bff67 100644 --- a/base/dali-toolkit/public-api/controls/scrollable/scroll-component-impl.cpp +++ b/base/dali-toolkit/public-api/controls/scrollable/scroll-component-impl.cpp @@ -54,7 +54,7 @@ Toolkit::ScrollConnector ScrollComponentImpl::GetScrollConnector() const } ScrollComponentImpl::ScrollComponentImpl() -: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_THEME_CHANGE_SIGNALS ) ) +: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ) { } diff --git a/base/dali-toolkit/public-api/styling/style-manager.cpp b/base/dali-toolkit/public-api/styling/style-manager.cpp index bdef3d1..633ada9 100644 --- a/base/dali-toolkit/public-api/styling/style-manager.cpp +++ b/base/dali-toolkit/public-api/styling/style-manager.cpp @@ -83,9 +83,9 @@ StyleManager::StyleManager( Internal::StyleManager *impl ) { } -StyleManager::ThemeChangeSignalType& StyleManager::ThemeChangeSignal() +StyleManager::StyleChangeSignalType& StyleManager::StyleChangeSignal() { - return GetImpl( *this ).ThemeChangeSignal(); + return GetImpl( *this ).StyleChangeSignal(); } void StyleManager::RequestThemeChange( const std::string& themeFile ) diff --git a/base/dali-toolkit/public-api/styling/style-manager.h b/base/dali-toolkit/public-api/styling/style-manager.h index 6b42f8d..b795b13 100644 --- a/base/dali-toolkit/public-api/styling/style-manager.h +++ b/base/dali-toolkit/public-api/styling/style-manager.h @@ -63,7 +63,7 @@ class StyleManager : public BaseHandle public: // Signals - typedef SignalV2< void ( StyleManager ) > ThemeChangeSignalType; + typedef SignalV2< void ( StyleManager, StyleChange ) > StyleChangeSignalType; /** * @brief Create a StyleManager handle; this can be initialised with StyleManager::Get() @@ -162,14 +162,14 @@ public: public: // Signals /** - * @brief This signal is emitted whenever the theme is changed on device + * @brief This signal is emitted whenever the style (e.g. theme/font change) is changed on device * A callback of the following type may be connected: * @code - * void YourCallbackName( StyleManager styleManager ); + * void YourCallbackName( StyleManager styleManager, StyleChange change ); * @endcode * @return The signal to connect to. */ - ThemeChangeSignalType& ThemeChangeSignal(); + StyleChangeSignalType& StyleChangeSignal(); public: diff --git a/capi/dali-toolkit/public-api/controls/control-impl.h b/capi/dali-toolkit/public-api/controls/control-impl.h index 3ab3acf..840af0a 100644 --- a/capi/dali-toolkit/public-api/controls/control-impl.h +++ b/capi/dali-toolkit/public-api/controls/control-impl.h @@ -299,11 +299,34 @@ private: // For derived classes to override virtual void OnInitialize() { } /** - * @brief Callback for when the theme changes. + * @brief This method should be overridden by deriving classes when + * they wish to be notified when the style manager changes the theme. + * + * @param[in] styleManager The StyleManager object. */ virtual void OnThemeChange( Toolkit::StyleManager styleManager ); /** + * @brief This method should be overridden by deriving classes when + * they wish to be notified when the style changes the default font. + * + * @param[in] defaultFontChange Information denoting whether the default font has changed. + * @param[in] defaultFontSizeChange Information denoting whether the default font size has changed. + */ + virtual void OnFontChange( bool defaultFontChange, bool defaultFontSizeChange ){ } + + /** + * @deprecated Use OnFontChange() instead. + * Before the using of StyleManager, the StyleChange only deals with font change. + * + * @brief This method should be overridden by deriving classes when + * they wish to be notified when the style changes. + * + * @param[in] change Information denoting what has changed. + */ + virtual void OnStyleChange( StyleChange change ) { } + + /** * @brief Called whenever a pinch gesture is detected on this control. * * This can be overridden by deriving classes when pinch detection @@ -518,14 +541,22 @@ private: */ void DoActivatedAction(const PropertyValueContainer& attributes); + /** + * @brief This method is the callback for the StyleChangeSignal from StyleManager + * + * @param[in] styleManager The StyleManager Object + * @param[in] change Information denoting what has changed. + */ + void DoStyleChange( Toolkit::StyleManager styleManager, StyleChange change ); + protected: // Construction // Flags for the constructor enum ControlBehaviour { - CONTROL_BEHAVIOUR_NONE = 0x0, - REQUIRES_TOUCH_EVENTS = 0x1, ///< True if the OnTouchEvent() callback is required. - REQUIRES_THEME_CHANGE_SIGNALS = 0x2 ///< True if this control should listen to theme change signals + CONTROL_BEHAVIOUR_NONE = 0x0, + REQUIRES_TOUCH_EVENTS = 0x1, ///< True if the OnTouchEvent() callback is required. + REQUIRES_STYLE_CHANGE_SIGNALS = 0x2 ///< True if needs to monitor style change signals such as theme/font change }; /** diff --git a/optional/dali-toolkit/internal/controls/cluster/cluster-impl.cpp b/optional/dali-toolkit/internal/controls/cluster/cluster-impl.cpp index 4a5e45e..0ecc544 100644 --- a/optional/dali-toolkit/internal/controls/cluster/cluster-impl.cpp +++ b/optional/dali-toolkit/internal/controls/cluster/cluster-impl.cpp @@ -80,7 +80,7 @@ Dali::Toolkit::Cluster Cluster::New(Toolkit::ClusterStyle& style) } Cluster::Cluster(Toolkit::ClusterStyle& style) -: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_THEME_CHANGE_SIGNALS ) ), +: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ), mClusterStyle(style), mExpandedCount(0) { diff --git a/optional/dali-toolkit/internal/controls/image-view/image-view-impl.cpp b/optional/dali-toolkit/internal/controls/image-view/image-view-impl.cpp index edd6f4a..f360f5e 100644 --- a/optional/dali-toolkit/internal/controls/image-view/image-view-impl.cpp +++ b/optional/dali-toolkit/internal/controls/image-view/image-view-impl.cpp @@ -86,7 +86,7 @@ Dali::Toolkit::ImageView ImageView::New() } ImageView::ImageView() -: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_THEME_CHANGE_SIGNALS ) ) +: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ) { } diff --git a/optional/dali-toolkit/internal/controls/image-view/masked-image-view-impl.cpp b/optional/dali-toolkit/internal/controls/image-view/masked-image-view-impl.cpp index 38a05a4..c534d4d 100644 --- a/optional/dali-toolkit/internal/controls/image-view/masked-image-view-impl.cpp +++ b/optional/dali-toolkit/internal/controls/image-view/masked-image-view-impl.cpp @@ -474,7 +474,7 @@ Dali::Toolkit::MaskedImageView::MaskedImageViewSignal& MaskedImageView::MaskFini } MaskedImageView::MaskedImageView() -: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_THEME_CHANGE_SIGNALS ) ), +: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ), mEditMode( Dali::Toolkit::MaskedImageView::EDIT_DISABLED ), mSelfPropertySetting( false ), mSourceRotation( Dali::Toolkit::MaskedImageView::ROTATE_0 ), diff --git a/optional/dali-toolkit/internal/controls/slider/slider-impl.cpp b/optional/dali-toolkit/internal/controls/slider/slider-impl.cpp index 8a3bbb2..87495b2 100755 --- a/optional/dali-toolkit/internal/controls/slider/slider-impl.cpp +++ b/optional/dali-toolkit/internal/controls/slider/slider-impl.cpp @@ -168,7 +168,7 @@ Dali::Toolkit::Slider Slider::New() } Slider::Slider() -: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_THEME_CHANGE_SIGNALS ) ), +: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ), mState( NORMAL ), mDisableColor( 0.0f, 0.0f, 0.0f, 0.0f ), mPopupTextColor( 0.0f, 0.0f, 0.0f, 0.0f ),