Updated Gradient renderer to use SetTexture
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / styling / style-manager-impl.cpp
index 5178020..71baa96 100644 (file)
 // EXTERNAL INCLUDES
 #include <dali/devel-api/adaptor-framework/singleton-service.h>
 #include <dali/public-api/object/type-registry.h>
-#include <dali/devel-api/object/type-registry-helper.h>
+#include <dali/public-api/object/type-registry-helper.h>
 #include <dali/integration-api/debug.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/control.h>
 #include <dali-toolkit/public-api/controls/control-impl.h>
-#include <dali-toolkit/devel-api/styling/style-manager.h>
+#include <dali-toolkit/public-api/styling/style-manager.h>
 #include <dali-toolkit/internal/feedback/feedback-style.h>
 
 namespace
@@ -98,10 +98,8 @@ Toolkit::StyleManager StyleManager::Get()
 }
 
 StyleManager::StyleManager()
-: mOrientationDegrees( 0 ),  // Portrait
-  mDefaultFontSize( -1 ),
+: mDefaultFontSize( -1 ),
   mDefaultFontFamily(""),
-  mThemeFile( DEFAULT_THEME ),
   mFeedbackStyle( NULL )
 {
   // Add theme builder constants
@@ -124,43 +122,18 @@ StyleManager::~StyleManager()
   delete mFeedbackStyle;
 }
 
-void StyleManager::SetOrientationValue( int orientation )
+void StyleManager::ApplyTheme( const std::string& themeFile )
 {
-  if( orientation !=  mOrientationDegrees )
-  {
-    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();
-  }
-}
-
-int StyleManager::GetOrientationValue()
-{
-  return mOrientationDegrees;
+  SetTheme( themeFile );
 }
 
-void StyleManager::SetOrientation( Orientation orientation )
+void StyleManager::ApplyDefaultTheme()
 {
-  if( mOrientation )
-  {
-    mOrientation.ChangedSignal().Disconnect( this, &StyleManager::OnOrientationChanged );
-  }
-
-  OnOrientationChanged( orientation );
-
-  if( mOrientation )
-  {
-    mOrientation.ChangedSignal().Connect( this, &StyleManager::OnOrientationChanged );
-  }
+  std::string empty;
+  SetTheme( empty );
 }
 
-Orientation StyleManager::GetOrientation()
-{
-  return mOrientation;
-}
-
-std::string StyleManager::GetDefaultFontFamily() const
+const std::string& StyleManager::GetDefaultFontFamily() const
 {
   return mDefaultFontFamily;
 }
@@ -182,24 +155,11 @@ bool StyleManager::GetStyleConstant( const std::string& key, Property::Value& va
   return false;
 }
 
-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();
-}
-
-void StyleManager::RequestDefaultTheme()
-{
-  RequestThemeChange( DEFAULT_THEME );
-}
-
 void StyleManager::ApplyThemeStyle( Toolkit::Control control )
 {
   if( !mThemeBuilder )
   {
-    RequestDefaultTheme();
+    ApplyDefaultTheme();
   }
 
   if( mThemeBuilder )
@@ -251,24 +211,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
   {
@@ -316,13 +291,7 @@ bool StyleManager::LoadJSON( Toolkit::Builder builder, const std::string& jsonFi
 void StyleManager::CollectQualifiers( StringList& qualifiersOut )
 {
   // Append the relevant qualifier for orientation
-  int orientation = mOrientationDegrees;
-
-  if( mOrientation )
-  {
-    orientation = mOrientation.GetDegrees();
-  }
-
+  int orientation = 0; // Get the orientation from the system
   switch( orientation )
   {
     case 90:
@@ -393,15 +362,6 @@ void StyleManager::ApplyStyle( Toolkit::Builder builder, Toolkit::Control contro
   }
 }
 
-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();
-}
-
-
 Toolkit::Builder StyleManager::FindCachedBuilder( const std::string& key )
 {
   BuilderMap::iterator builderIt = mBuilderCache.find( key );
@@ -436,24 +396,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();
 
-  mStyleChangeSignal.Emit( Toolkit::StyleManager::Get(), styleChange );
+  // Update Controls first
+  mControlStyleChangeSignal.Emit( styleManager, styleChange );
+
+  // Inform application last
+  mStyleChangedSignal.Emit( styleManager, styleChange );
 }
 
+
 } // namespace Internal
 
 } // namespace Toolkit