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=814421e9a56f143450c04bf091aa06290b17b40e;hp=1ee0e9ed315bcb01133cf3989383aa667c8aea36;hb=2af79c9045fb0df64012413c08e7a17efbf16d4b;hpb=306d2f61a1b64179e801fa8a0bb2bd7b4e9dd682 diff --git a/dali-toolkit/internal/styling/style-manager-impl.cpp b/dali-toolkit/internal/styling/style-manager-impl.cpp index 1ee0e9e..814421e 100644 --- a/dali-toolkit/internal/styling/style-manager-impl.cpp +++ b/dali-toolkit/internal/styling/style-manager-impl.cpp @@ -18,25 +18,24 @@ #include "style-manager-impl.h" // EXTERNAL INCLUDES -#include -#include -#include -#include +#include #include +#include #include // INTERNAL INCLUDES #include #include -#include +#include namespace { const char* LANDSCAPE_QUALIFIER = "landscape"; const char* PORTRAIT_QUALIFIER = "portrait"; +const char* FONT_SIZE_QUALIFIER = "font-size-"; -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/"; @@ -72,7 +71,9 @@ BaseHandle Create() return handle; } -TypeRegistration STYLE_MANAGER_TYPE( typeid(Dali::Toolkit::StyleManager), typeid(Dali::BaseHandle), Create, true /* Create instance at startup */ ); + +DALI_TYPE_REGISTRATION_BEGIN_CREATE( Toolkit::StyleManager, Dali::BaseHandle, Create, true ) +DALI_TYPE_REGISTRATION_END() } // namespace @@ -96,17 +97,19 @@ Toolkit::StyleManager StyleManager::Get() } StyleManager::StyleManager() - : mOrientationDegrees( 0 ) // Portrait +: mOrientationDegrees( 0 ), // Portrait + mDefaultFontSize( -1 ), + mThemeFile( DEFAULT_THEME ) { // 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 = mStyleMonitor.GetDefaultFontSize(); } } @@ -241,9 +244,13 @@ 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; @@ -263,6 +270,14 @@ void StyleManager::ApplyStyle( Toolkit::Builder builder, Toolkit::Control contro // Remove the last qualifier in an attempt to find a style that is valid qualifiers.pop_back(); } + + if( mDefaultFontSize >= 0 ) + { + // Apply the style for logical font size + std::stringstream fontSizeQualifier; + fontSizeQualifier << styleName << "-" << FONT_SIZE_QUALIFIER << mDefaultFontSize; + builder.ApplyStyle( fontSizeQualifier.str(), control ); + } } void StyleManager::ApplyThemeStyle( Toolkit::Control control ) @@ -310,17 +325,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; @@ -349,9 +358,7 @@ void StyleManager::SetTheme() mThemeBuilder = CreateBuilder( mThemeBuilderConstants ); if ( LoadJSON( mThemeBuilder, mThemeFile ) ) { - StyleChange change; - change.themeChange = true; - mStyleChangeSignal.Emit( Toolkit::StyleManager::Get(), change ); + mStyleChangeSignal.Emit( Toolkit::StyleManager::Get(), StyleChange::THEME_CHANGE ); } else { @@ -375,8 +382,38 @@ 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 ) { + switch ( styleChange ) + { + case StyleChange::DEFAULT_FONT_CHANGE: + { + 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 ); }