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=2861611eb80c0e2085f27a94b2d562514535e9c2;hp=60fa86800cd7239c86ef689ec3b79e4af57fbda3;hb=f3da11c2818c6d17706fbb2417f21b602b3190f5;hpb=f12006bb207999beb65a3927d4c88292c504ac12 diff --git a/dali-toolkit/internal/styling/style-manager-impl.cpp b/dali-toolkit/internal/styling/style-manager-impl.cpp index 60fa868..2861611 100644 --- a/dali-toolkit/internal/styling/style-manager-impl.cpp +++ b/dali-toolkit/internal/styling/style-manager-impl.cpp @@ -18,27 +18,25 @@ #include "style-manager-impl.h" // EXTERNAL INCLUDES -#include -#include -#include -#include +#include #include -#include +#include #include // INTERNAL INCLUDES #include #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/"; @@ -101,24 +99,30 @@ Toolkit::StyleManager StyleManager::Get() StyleManager::StyleManager() : mOrientationDegrees( 0 ), // Portrait - mDefaultFontSize( -1 ) + mDefaultFontSize( -1 ), + mDefaultFontFamily(""), + mThemeFile( DEFAULT_THEME ), + mFeedbackStyle( NULL ) { // Add theme builder constants mThemeBuilderConstants[ PACKAGE_PATH_KEY ] = DEFAULT_PACKAGE_PATH; - RequestDefaultTheme(); - - 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 ) @@ -152,6 +156,11 @@ void StyleManager::SetOrientation( Orientation orientation ) } } +std::string StyleManager::GetDefaultFontFamily() const +{ + return mDefaultFontFamily; +} + Orientation StyleManager::GetOrientation() { return mOrientation; @@ -248,9 +257,14 @@ void StyleManager::BuildQualifiedStyleName( const std::string& styleName, const void StyleManager::ApplyStyle( Toolkit::Builder builder, Toolkit::Control control ) { - // Convert control name to lower case - std::string styleName = control.GetTypeName(); - std::transform( styleName.begin(), styleName.end(), styleName.begin(), ::tolower ); + std::string styleName = control.GetStyleName(); + + if( styleName.empty() ) + { + // Convert control name to lower case + styleName = control.GetTypeName(); + std::transform( styleName.begin(), styleName.end(), styleName.begin(), ::tolower ); + } // Apply the style after choosing the correct actual style (e.g. landscape or portrait) StringList qualifiers; @@ -275,19 +289,34 @@ 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 ) + { + 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; @@ -325,17 +354,11 @@ 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 ) + // as toolkit is platform agnostic, it cannot load files from filesystem + // ask style monitor to load the style sheet + if( mStyleMonitor ) { - std::stringstream buffer; - buffer << in.rdbuf(); - - stringOut = buffer.str(); - - in.close(); - - return true; + return mStyleMonitor.LoadThemeFile( filename, stringOut ); } return false; @@ -362,11 +385,15 @@ void StyleManager::RequestDefaultTheme() void StyleManager::SetTheme() { mThemeBuilder = CreateBuilder( mThemeBuilderConstants ); - if ( LoadJSON( mThemeBuilder, mThemeFile ) ) + + if( LoadJSON( mThemeBuilder, mThemeFile ) ) { - StyleChange change; - change.themeChange = true; - mStyleChangeSignal.Emit( Toolkit::StyleManager::Get(), change ); + if(mFeedbackStyle) + { + mFeedbackStyle->StyleChanged( mThemeFile, StyleChange::THEME_CHANGE ); + } + + mStyleChangeSignal.Emit( Toolkit::StyleManager::Get(), StyleChange::THEME_CHANGE ); } else { @@ -390,11 +417,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 ) + switch ( styleChange ) { - mDefaultFontSize = styleMonitor.GetDefaultFontSize(); + case StyleChange::DEFAULT_FONT_CHANGE: + { + mDefaultFontFamily = styleMonitor.GetDefaultFontFamily(); + break; + } + + case StyleChange::DEFAULT_FONT_SIZE_CHANGE: + { + mDefaultFontSize = styleMonitor.GetDefaultFontSize(); + break; + } + + 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 );