Merge "Changes following "Make TextureSet a non property owner"" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / styling / style-manager-impl.cpp
index 5178020..f9569b9 100644 (file)
@@ -101,7 +101,6 @@ StyleManager::StyleManager()
 : mOrientationDegrees( 0 ),  // Portrait
   mDefaultFontSize( -1 ),
   mDefaultFontFamily(""),
-  mThemeFile( DEFAULT_THEME ),
   mFeedbackStyle( NULL )
 {
   // Add theme builder constants
@@ -131,7 +130,7 @@ void StyleManager::SetOrientationValue( int orientation )
     mOrientationDegrees = orientation;
     // TODO: if orientation changed, apply the new style to all controls
     // dont want to really do the whole load from file again if the bundle contains both portrait & landscape
-    SetTheme();
+    SetTheme( mThemeFile );
   }
 }
 
@@ -184,15 +183,13 @@ bool StyleManager::GetStyleConstant( const std::string& key, Property::Value& va
 
 void StyleManager::RequestThemeChange( const std::string& themeFile )
 {
-  mThemeFile = themeFile;
-
-  // need to do style change synchronously as app might create a UI control on the next line
-  SetTheme();
+  SetTheme( themeFile );
 }
 
 void StyleManager::RequestDefaultTheme()
 {
-  RequestThemeChange( DEFAULT_THEME );
+  std::string empty;
+  SetTheme( empty );
 }
 
 void StyleManager::ApplyThemeStyle( Toolkit::Control control )
@@ -251,24 +248,39 @@ void StyleManager::ApplyStyle( Toolkit::Control control, const std::string& json
   }
 }
 
-Toolkit::StyleManager::StyleChangeSignalType& StyleManager::StyleChangeSignal()
+Toolkit::StyleManager::StyleChangedSignalType& StyleManager::StyleChangedSignal()
 {
-  return mStyleChangeSignal;
+  return mStyleChangedSignal;
 }
 
+Toolkit::StyleManager::StyleChangedSignalType& StyleManager::ControlStyleChangeSignal()
+{
+  return mControlStyleChangeSignal;
+}
 
-void StyleManager::SetTheme()
+void StyleManager::SetTheme( const std::string& themeFile )
 {
+  bool themeLoaded = false;
+
   mThemeBuilder = CreateBuilder( mThemeBuilderConstants );
 
-  if( LoadJSON( mThemeBuilder, mThemeFile ) )
+  // Always load the default theme first, then merge in the custom theme if present
+  themeLoaded = LoadJSON( mThemeBuilder, DEFAULT_THEME );
+
+  if( ! themeFile.empty() )
+  {
+    mThemeFile = themeFile;
+    themeLoaded = LoadJSON( mThemeBuilder, mThemeFile );
+  }
+
+  if( themeLoaded )
   {
     if(mFeedbackStyle)
     {
       mFeedbackStyle->StyleChanged( mThemeFile, StyleChange::THEME_CHANGE );
     }
 
-    mStyleChangeSignal.Emit( Toolkit::StyleManager::Get(), StyleChange::THEME_CHANGE );
+    EmitStyleChangeSignals(StyleChange::THEME_CHANGE);
   }
   else
   {
@@ -398,7 +410,7 @@ void StyleManager::OnOrientationChanged( Orientation orientation )
   mOrientation = orientation;
   // TODO: if orientation changed, apply the new style to all controls
   // dont want to really do the whole load from file again if the bundle contains both portrait & landscape
-  SetTheme();
+  SetTheme( mThemeFile );
 }
 
 
@@ -436,24 +448,25 @@ void StyleManager::StyleMonitorChange( StyleMonitor styleMonitor, StyleChange::T
 
     case StyleChange::THEME_CHANGE:
     {
-      const std::string& newTheme = styleMonitor.GetTheme();
-      if( ! newTheme.empty() )
-      {
-        mThemeFile = newTheme;
-      }
-      else
-      {
-        mThemeFile = DEFAULT_THEME;
-      }
-
-      SetTheme();
+      SetTheme( styleMonitor.GetTheme() );
       break;
     }
   }
+  EmitStyleChangeSignals( styleChange );
+}
+
+void StyleManager::EmitStyleChangeSignals( StyleChange::Type styleChange )
+{
+  Toolkit::StyleManager styleManager = StyleManager::Get();
+
+  // Update Controls first
+  mControlStyleChangeSignal.Emit( styleManager, styleChange );
 
-  mStyleChangeSignal.Emit( Toolkit::StyleManager::Get(), styleChange );
+  // Inform application last
+  mStyleChangedSignal.Emit( styleManager, styleChange );
 }
 
+
 } // namespace Internal
 
 } // namespace Toolkit