X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fstyling%2Fstyle-manager-impl.cpp;h=df885d9fc1174a2e261811c4eb4fef16a3df5b6c;hb=7cca1061ed3db08d2e7f511a8f6ef707e688703d;hp=d1fa38837dcdd3a37e42a68d81d388906cf3ba42;hpb=cbff244b295bcd2758fe93155a9b3199d85ee164;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/styling/style-manager-impl.cpp b/dali-toolkit/internal/styling/style-manager-impl.cpp index d1fa388..df885d9 100644 --- a/dali-toolkit/internal/styling/style-manager-impl.cpp +++ b/dali-toolkit/internal/styling/style-manager-impl.cpp @@ -25,6 +25,7 @@ #include // INTERNAL INCLUDES +#include #include #include #include @@ -33,7 +34,7 @@ namespace { -const char* LANDSCAPE_QUALIFIER = "landscape"; +//const char* LANDSCAPE_QUALIFIER = "landscape"; const char* PORTRAIT_QUALIFIER = "portrait"; const char* FONT_SIZE_QUALIFIER = "fontsize"; @@ -132,8 +133,7 @@ void StyleManager::ApplyTheme( const std::string& themeFile ) void StyleManager::ApplyDefaultTheme() { - std::string empty; - SetTheme( empty ); + SetTheme( DEFAULT_THEME ); } const std::string& StyleManager::GetDefaultFontFamily() const @@ -228,15 +228,22 @@ void StyleManager::SetTheme( const std::string& themeFile ) { bool themeLoaded = false; - mThemeBuilder = CreateBuilder( mThemeBuilderConstants ); - - // Always load the default theme first, then merge in the custom theme if present - themeLoaded = LoadJSON( mThemeBuilder, DEFAULT_THEME ); + if( mThemeFile.compare(DEFAULT_THEME) == 0 && mThemeBuilder ) + { + // We have already loaded the default theme into mThemeBuilder + } + else + { + // Reload the default theme + mThemeBuilder = CreateBuilder( mThemeBuilderConstants ); + themeLoaded = LoadJSON( mThemeBuilder, DEFAULT_THEME ); + } - if( ! themeFile.empty() ) + if( themeFile.compare(DEFAULT_THEME) != 0 ) { + // The theme is different to the default: Merge it + themeLoaded = LoadJSON( mThemeBuilder, themeFile ); mThemeFile = themeFile; - themeLoaded = LoadJSON( mThemeBuilder, mThemeFile ); } if( themeLoaded ) @@ -254,6 +261,32 @@ void StyleManager::SetTheme( const std::string& themeFile ) } } +const Property::Map StyleManager::GetConfigurations() +{ + Property::Map result; + if( mThemeBuilder ) + { + result = mThemeBuilder.GetConfigurations(); + } + else + { + bool themeLoaded = false; + + mThemeBuilder = CreateBuilder( mThemeBuilderConstants ); + + // Load default theme because this is first try to load stylesheet. + themeLoaded = LoadJSON( mThemeBuilder, DEFAULT_THEME ); + mThemeFile = DEFAULT_THEME; + + if( themeLoaded ) + { + result = mThemeBuilder.GetConfigurations(); + } + } + + return result; +} + bool StyleManager::LoadFile( const std::string& filename, std::string& stringOut ) { DALI_ASSERT_DEBUG( 0 != filename.length()); @@ -291,33 +324,39 @@ bool StyleManager::LoadJSON( Toolkit::Builder builder, const std::string& jsonFi } } -void StyleManager::CollectQualifiers( StringList& qualifiersOut ) +static void CollectQualifiers( std::vector& qualifiersOut ) { // Append the relevant qualifier for orientation - int orientation = 0; // Get the orientation from the system - switch( orientation ) - { - case 90: - case 270: - { - qualifiersOut.push_back( std::string( LANDSCAPE_QUALIFIER ) ); - break; - } - case 180: - case 0: // fall through - default: - { - qualifiersOut.push_back( std::string( PORTRAIT_QUALIFIER ) ); - break; - } - } + // int orientation = 0; // Get the orientation from the system + /* + //// To Do ///// + Getting orientation from the system, and determine Qualifie LANDSCAPE or PORTRAIT + orientation 0, 180 : PORTRAIT_QUALIFIER (default) + orientation 90, 270 : LANDSCAPE_QUALIFIER + */ + + qualifiersOut.push_back( std::string( PORTRAIT_QUALIFIER ) ); + } -void StyleManager::BuildQualifiedStyleName( const std::string& styleName, const StringList& qualifiers, std::string& qualifiedStyleOut ) +/** + * @brief Construct a qualified style name out of qualifiers + * + * A qualifed style name will be in the format: style-qualifier0-qualifier1-qualifierN + * + * @param[in] styleName The root name of the style + * @param[in] qualifiers List of qualifier names + * @param[out] qualifiedStyleOut The qualified style name + */ +static void BuildQualifiedStyleName( + const std::string& styleName, + const std::vector& qualifiers, + std::string& qualifiedStyleOut ) { qualifiedStyleOut.append( styleName ); - for( StringList::const_iterator it = qualifiers.begin(), itEnd = qualifiers.end(); it != itEnd; ++it ) + for( std::vector::const_iterator it = qualifiers.begin(), + itEnd = qualifiers.end(); it != itEnd; ++it ) { const std::string& str = *it; @@ -326,9 +365,9 @@ void StyleManager::BuildQualifiedStyleName( const std::string& styleName, const } } -void StyleManager::ApplyStyle( Toolkit::Builder builder, Toolkit::Control control ) +static bool GetStyleNameForControl( Toolkit::Builder builder, Toolkit::Control control, std::string& styleName) { - std::string styleName = control.GetStyleName(); + styleName = control.GetStyleName(); if( styleName.empty() ) { @@ -336,22 +375,43 @@ void StyleManager::ApplyStyle( Toolkit::Builder builder, Toolkit::Control contro } // Apply the style after choosing the correct actual style (e.g. landscape or portrait) - StringList qualifiers; + std::vector qualifiers; CollectQualifiers( qualifiers ); - while( true ) + bool found = 0; + std::string qualifiedStyleName; + do { - std::string qualifiedStyleName; + qualifiedStyleName.clear(); BuildQualifiedStyleName( styleName, qualifiers, qualifiedStyleName ); // Break if style found or we have tried the root style name (qualifiers is empty) - if( builder.ApplyStyle( qualifiedStyleName, control ) || qualifiers.size() == 0 ) + if( GetImpl(builder).LookupStyleName( qualifiedStyleName ) ) + { + found = true; + break; + } + if( qualifiers.size() == 0 ) { break; } - // Remove the last qualifier in an attempt to find a style that is valid qualifiers.pop_back(); + } while (!found); + + if(found) + { + styleName = qualifiedStyleName; + } + return found; +} + +void StyleManager::ApplyStyle( Toolkit::Builder builder, Toolkit::Control control ) +{ + std::string styleName = control.GetStyleName(); + if( GetStyleNameForControl( builder, control, styleName ) ) + { + builder.ApplyStyle( styleName, control ); } if( mDefaultFontSize >= 0 ) @@ -363,6 +423,21 @@ void StyleManager::ApplyStyle( Toolkit::Builder builder, Toolkit::Control contro } } +const StylePtr StyleManager::GetRecordedStyle( Toolkit::Control control ) +{ + if( mThemeBuilder ) + { + std::string styleName = control.GetStyleName(); + + if( GetStyleNameForControl( mThemeBuilder, control, styleName ) ) + { + const StylePtr style = GetImpl(mThemeBuilder).GetStyle( styleName ); + return style; + } + } + return StylePtr(NULL); +} + Toolkit::Builder StyleManager::FindCachedBuilder( const std::string& key ) { BuilderMap::iterator builderIt = mBuilderCache.find( key );