theme change needs to be synchronous so that application can create controls immediat...
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / styling / style-manager-impl.cpp
index 57be231..0e43c19 100644 (file)
@@ -21,7 +21,6 @@
 #include <dali-toolkit/public-api/controls/control.h>
 #include <dali-toolkit/public-api/controls/control-impl.h>
 #include <dali-toolkit/public-api/styling/style-manager.h>
-#include <dali-toolkit/internal/styling/util.h>
 #include <dali/integration-api/debug.h>
 
 // EXTERNAL INCLUDES
@@ -108,32 +107,33 @@ Toolkit::StyleManager StyleManager::Get()
 }
 
 StyleManager::StyleManager()
-  : mOrientationDegrees( 0 ),  // Portrait
-    mSetThemeConnection( false )
+  : mOrientationDegrees( 0 )  // Portrait
 {
   // Add theme builder constants
   mThemeBuilderConstants[ PACKAGE_PATH_KEY ] = DEFAULT_PACKAGE_PATH;
 
   RequestDefaultTheme();
 
-  if( Adaptor::IsAvailable() )
+  StyleMonitor styleMonitor( StyleMonitor::Get() );
+  if( styleMonitor )
   {
-    StyleMonitor::Get().StyleChangeSignal().Connect( this, &StyleManager::StyleMonitorChange );
+    styleMonitor.StyleChangeSignal().Connect( this, &StyleManager::StyleMonitorChange );
   }
 }
 
 StyleManager::~StyleManager()
 {
-  // Disconnect from signal
-  SetOrientation( Orientation() );
 }
 
 void StyleManager::SetOrientationValue( int orientation )
 {
-  mOrientationDegrees = orientation;
-
-  Util::ConnectEventProcessingFinishedSignal();
-  mSetThemeConnection = true;
+  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()
@@ -181,12 +181,9 @@ bool StyleManager::GetStyleConstant( const std::string& key, Property::Value& va
 void StyleManager::OnOrientationChanged( Orientation orientation )
 {
   mOrientation = orientation;
-
-  if( mOrientation )
-  {
-    Util::ConnectEventProcessingFinishedSignal();
-    mSetThemeConnection = true;
-  }
+  // 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::CreateBuilder( const PropertyValueMap& constants )
@@ -349,8 +346,8 @@ void StyleManager::RequestThemeChange( const std::string& themeFile )
 {
   mThemeFile = themeFile;
 
-  Util::ConnectEventProcessingFinishedSignal();
-  mSetThemeConnection = true;
+  // need to do style change synchronously as app might create a UI control on the next line
+  SetTheme();
 }
 
 void StyleManager::RequestDefaultTheme()
@@ -358,18 +355,11 @@ void StyleManager::RequestDefaultTheme()
   RequestThemeChange( DEFAULT_THEME );
 }
 
-bool StyleManager::IsThemeRequestPending()
-{
-  return mSetThemeConnection;
-}
-
 void StyleManager::SetTheme()
 {
   mThemeBuilder = CreateBuilder( mThemeBuilderConstants );
   LoadJSON( mThemeBuilder, mThemeFile );
 
-  mSetThemeConnection = false;
-
   StyleChange change;
   change.themeChange = true;
   mStyleChangeSignal.Emit( Toolkit::StyleManager::Get(), change );