X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fstyling%2Fstyle-manager-impl.cpp;h=5178020ddd838ff6681c3b9ccf756d09372e3d29;hp=bc249b3de8b35e7682c553d64a7fbe322a5783f2;hb=c04d1be7d4dec47c2274160833021aafe10f720d;hpb=dd846cfb29b79dcc270562a4d46de1e28f545254 diff --git a/dali-toolkit/internal/styling/style-manager-impl.cpp b/dali-toolkit/internal/styling/style-manager-impl.cpp index bc249b3..5178020 100644 --- a/dali-toolkit/internal/styling/style-manager-impl.cpp +++ b/dali-toolkit/internal/styling/style-manager-impl.cpp @@ -18,9 +18,6 @@ #include "style-manager-impl.h" // EXTERNAL INCLUDES -#include -#include -#include #include #include #include @@ -30,15 +27,16 @@ #include #include #include +#include namespace { const char* LANDSCAPE_QUALIFIER = "landscape"; const char* PORTRAIT_QUALIFIER = "portrait"; -const char* FONT_SIZE_QUALIFIER = "font-size-"; +const char* FONT_SIZE_QUALIFIER = "FontSize"; -const char* DEFAULT_THEME = DALI_STYLE_DIR "tizen-default-theme.json"; +const char* DEFAULT_THEME = DALI_STYLE_DIR "dali-toolkit-default-theme.json"; const char* PACKAGE_PATH_KEY = "PACKAGE_PATH"; const char* DEFAULT_PACKAGE_PATH = DALI_DATA_READ_ONLY_DIR "/toolkit/"; @@ -102,22 +100,28 @@ Toolkit::StyleManager StyleManager::Get() StyleManager::StyleManager() : mOrientationDegrees( 0 ), // Portrait mDefaultFontSize( -1 ), - mThemeFile( DEFAULT_THEME ) + mDefaultFontFamily(""), + mThemeFile( DEFAULT_THEME ), + mFeedbackStyle( NULL ) { // Add theme builder constants mThemeBuilderConstants[ PACKAGE_PATH_KEY ] = DEFAULT_PACKAGE_PATH; - StyleMonitor styleMonitor( StyleMonitor::Get() ); - if( styleMonitor ) + mStyleMonitor = StyleMonitor::Get(); + if( mStyleMonitor ) { - styleMonitor.StyleChangeSignal().Connect( this, &StyleManager::StyleMonitorChange ); + mStyleMonitor.StyleChangeSignal().Connect( this, &StyleManager::StyleMonitorChange ); - mDefaultFontSize = styleMonitor.GetDefaultFontSize(); + mDefaultFontSize = mStyleMonitor.GetDefaultFontSize(); } + + // Sound & haptic style + mFeedbackStyle = new FeedbackStyle(); } StyleManager::~StyleManager() { + delete mFeedbackStyle; } void StyleManager::SetOrientationValue( int orientation ) @@ -156,6 +160,11 @@ Orientation StyleManager::GetOrientation() return mOrientation; } +std::string StyleManager::GetDefaultFontFamily() const +{ + return mDefaultFontFamily; +} + void StyleManager::SetStyleConstant( const std::string& key, const Property::Value& value ) { mStyleBuilderConstants[ key ] = value; @@ -173,14 +182,114 @@ bool StyleManager::GetStyleConstant( const std::string& key, Property::Value& va return false; } -void StyleManager::OnOrientationChanged( Orientation orientation ) +void StyleManager::RequestThemeChange( const std::string& themeFile ) { - 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 + 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(); + } + + if( mThemeBuilder ) + { + ApplyStyle( mThemeBuilder, control ); + } +} + +void StyleManager::ApplyThemeStyleAtInit( Toolkit::Control control ) +{ + ApplyThemeStyle( control ); + + if(mFeedbackStyle) + { + mFeedbackStyle->ObjectCreated( control ); + } +} + +void StyleManager::ApplyStyle( Toolkit::Control control, const std::string& jsonFileName, const std::string& styleName ) +{ + bool builderReady = false; + + // First look in the cache + Toolkit::Builder builder = FindCachedBuilder( jsonFileName ); + if( builder ) + { + builderReady = true; + } + else + { + // Merge theme and style constants + Property::Map constants( mThemeBuilderConstants ); + constants.Merge( mStyleBuilderConstants ); + + // Create it + builder = CreateBuilder( constants ); + + if( LoadJSON( builder, jsonFileName ) ) + { + CacheBuilder( builder, jsonFileName ); + builderReady = true; + } + } + + // Apply the style to the control + if( builderReady ) + { + builder.ApplyStyle( styleName, control ); + } +} + +Toolkit::StyleManager::StyleChangeSignalType& StyleManager::StyleChangeSignal() +{ + return mStyleChangeSignal; +} + + +void StyleManager::SetTheme() +{ + mThemeBuilder = CreateBuilder( mThemeBuilderConstants ); + + if( LoadJSON( mThemeBuilder, mThemeFile ) ) + { + if(mFeedbackStyle) + { + mFeedbackStyle->StyleChanged( mThemeFile, StyleChange::THEME_CHANGE ); + } + + mStyleChangeSignal.Emit( Toolkit::StyleManager::Get(), StyleChange::THEME_CHANGE ); + } + else + { + mThemeBuilder.Reset(); + } +} + +bool StyleManager::LoadFile( const std::string& filename, std::string& stringOut ) +{ + DALI_ASSERT_DEBUG( 0 != filename.length()); + + // as toolkit is platform agnostic, it cannot load files from filesystem + // ask style monitor to load the style sheet + if( mStyleMonitor ) + { + return mStyleMonitor.LoadThemeFile( filename, stringOut ); + } + + return false; +} + Toolkit::Builder StyleManager::CreateBuilder( const Property::Map& constants ) { Toolkit::Builder builder = Toolkit::Builder::New(); @@ -248,6 +357,7 @@ void StyleManager::BuildQualifiedStyleName( const std::string& styleName, const void StyleManager::ApplyStyle( Toolkit::Builder builder, Toolkit::Control control ) { std::string styleName = control.GetStyleName(); + if( styleName.empty() ) { // Convert control name to lower case @@ -278,104 +388,19 @@ void StyleManager::ApplyStyle( Toolkit::Builder builder, Toolkit::Control contro { // Apply the style for logical font size std::stringstream fontSizeQualifier; - fontSizeQualifier << styleName << "-" << FONT_SIZE_QUALIFIER << mDefaultFontSize; + fontSizeQualifier << styleName << FONT_SIZE_QUALIFIER << mDefaultFontSize; builder.ApplyStyle( fontSizeQualifier.str(), control ); } } -void StyleManager::ApplyThemeStyle( Toolkit::Control control ) -{ - if( mThemeBuilder ) - { - ApplyStyle( mThemeBuilder, control ); - } -} - -void StyleManager::ApplyStyle( Toolkit::Control control, const std::string& jsonFileName, const std::string& styleName ) -{ - bool builderReady = false; - - // First look in the cache - Toolkit::Builder builder = FindCachedBuilder( jsonFileName ); - if( builder ) - { - builderReady = true; - } - else - { - // Merge theme and style constants - Property::Map constants( mThemeBuilderConstants ); - constants.Merge( mStyleBuilderConstants ); - - // Create it - builder = CreateBuilder( constants ); - - if( LoadJSON( builder, jsonFileName ) ) - { - CacheBuilder( builder, jsonFileName ); - builderReady = true; - } - } - - // Apply the style to the control - if( builderReady ) - { - builder.ApplyStyle( styleName, control ); - } -} - -bool StyleManager::LoadFile( const std::string& filename, std::string& stringOut ) -{ - DALI_ASSERT_DEBUG( 0 != filename.length()); - - std::ifstream in( filename.c_str(), std::ios::in ); - if( in ) - { - std::stringstream buffer; - buffer << in.rdbuf(); - - stringOut = buffer.str(); - - in.close(); - - return true; - } - - return false; -} - -Toolkit::StyleManager::StyleChangeSignalType& StyleManager::StyleChangeSignal() -{ - return mStyleChangeSignal; -} - -void StyleManager::RequestThemeChange( const std::string& themeFile ) +void StyleManager::OnOrientationChanged( Orientation orientation ) { - mThemeFile = themeFile; - - // need to do style change synchronously as app might create a UI control on the next line + 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(); } -void StyleManager::RequestDefaultTheme() -{ - RequestThemeChange( DEFAULT_THEME ); -} - -void StyleManager::SetTheme() -{ - mThemeBuilder = CreateBuilder( mThemeBuilderConstants ); - if ( LoadJSON( mThemeBuilder, mThemeFile ) ) - { - StyleChange change; - change.themeChange = true; - mStyleChangeSignal.Emit( Toolkit::StyleManager::Get(), change ); - } - else - { - mThemeBuilder.Reset(); - } -} Toolkit::Builder StyleManager::FindCachedBuilder( const std::string& key ) { @@ -393,25 +418,37 @@ void StyleManager::CacheBuilder( Toolkit::Builder builder, const std::string& ke mBuilderCache[ key ] = builder; } -void StyleManager::StyleMonitorChange( StyleMonitor styleMonitor, StyleChange styleChange ) +void StyleManager::StyleMonitorChange( StyleMonitor styleMonitor, StyleChange::Type styleChange ) { - if( styleChange.defaultFontSizeChange ) - { - mDefaultFontSize = styleMonitor.GetDefaultFontSize(); - } - - if( styleChange.themeChange ) + switch ( styleChange ) { - if( ! styleChange.themeFilePath.empty() ) + case StyleChange::DEFAULT_FONT_CHANGE: { - mThemeFile = styleChange.themeFilePath; + mDefaultFontFamily = styleMonitor.GetDefaultFontFamily(); + break; } - else + + case StyleChange::DEFAULT_FONT_SIZE_CHANGE: { - mThemeFile = DEFAULT_THEME; + mDefaultFontSize = styleMonitor.GetDefaultFontSize(); + break; } - SetTheme(); + case StyleChange::THEME_CHANGE: + { + const std::string& newTheme = styleMonitor.GetTheme(); + if( ! newTheme.empty() ) + { + mThemeFile = newTheme; + } + else + { + mThemeFile = DEFAULT_THEME; + } + + SetTheme(); + break; + } } mStyleChangeSignal.Emit( Toolkit::StyleManager::Get(), styleChange );