-void StyleManager::OnOrientationChanged( Orientation orientation )
-{
- 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();
-}
-
-Toolkit::Builder StyleManager::CreateBuilder( const Property::Map& constants )
-{
- Toolkit::Builder builder = Toolkit::Builder::New();
- builder.AddConstants( constants );
-
- return builder;
-}
-
-bool StyleManager::LoadJSON( Toolkit::Builder builder, const std::string& jsonFilePath )
-{
- std::string fileString;
- if( LoadFile( jsonFilePath, fileString ) )
- {
- builder.LoadFromString( fileString );
- return true;
- }
- else
- {
- DALI_LOG_WARNING("Error loading file '%s'\n", jsonFilePath.c_str());
- return false;
- }
-}
-
-void StyleManager::CollectQualifiers( StringList& qualifiersOut )
-{
- // Append the relevant qualifier for orientation
- int orientation = mOrientationDegrees;
-
- if( mOrientation )
- {
- orientation = mOrientation.GetDegrees();
- }
-
- 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;
- }
- }
-}
-
-void StyleManager::BuildQualifiedStyleName( const std::string& styleName, const StringList& qualifiers, std::string& qualifiedStyleOut )
-{
- qualifiedStyleOut.append( styleName );
-
- for( StringList::const_iterator it = qualifiers.begin(), itEnd = qualifiers.end(); it != itEnd; ++it )
- {
- const std::string& str = *it;
-
- qualifiedStyleOut.append( "-" );
- qualifiedStyleOut.append( str );
- }
-}
-
-void StyleManager::ApplyStyle( Toolkit::Builder builder, Toolkit::Control control )
-{
- 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;
- CollectQualifiers( qualifiers );
-
- while( true )
- {
- std::string qualifiedStyleName;
- 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 )
- {
- break;
- }
-
- // 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 );
- }
-}
-