2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "style-monitor-impl.h"
22 #include <dali/public-api/object/type-registry.h>
27 #include <adaptor-impl.h>
28 #include <singleton-service-impl.h>
44 BaseHandle handle( StyleMonitor::Get() );
46 if ( !handle && Adaptor::IsAvailable() )
48 Dali::SingletonService service( SingletonService::Get() );
51 Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
52 Dali::StyleMonitor styleMonitor = Dali::StyleMonitor( new StyleMonitor( adaptorImpl.GetPlatformAbstraction() ) );
53 service.Register( typeid( styleMonitor ), styleMonitor );
54 handle = styleMonitor;
60 TypeRegistration STYLE_MONITOR_TYPE( typeid(Dali::StyleMonitor), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
62 } // unnamed namespace
64 Dali::StyleMonitor StyleMonitor::Get()
66 Dali::StyleMonitor styleMonitor;
68 Dali::SingletonService service( SingletonService::Get() );
71 // Check whether the singleton is already created
72 Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::StyleMonitor ) );
75 // If so, downcast the handle
76 styleMonitor = Dali::StyleMonitor( dynamic_cast< StyleMonitor* >( handle.GetObjectPtr() ) );
83 StyleMonitor::StyleMonitor(Integration::PlatformAbstraction& platformAbstraction)
84 : mPlatformAbstraction(platformAbstraction),
87 mPlatformAbstraction.GetDefaultFontDescription( mDefaultFontFamily, mDefaultFontStyle );
88 mDefaultFontSize = mPlatformAbstraction.GetDefaultFontSize();
91 StyleMonitor::~StyleMonitor()
95 void StyleMonitor::StyleChanged( StyleChange::Type styleChange )
97 switch ( styleChange )
99 case StyleChange::DEFAULT_FONT_CHANGE:
101 mPlatformAbstraction.GetDefaultFontDescription( mDefaultFontFamily, mDefaultFontStyle );
105 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
107 mDefaultFontSize = mPlatformAbstraction.GetDefaultFontSize();
111 case StyleChange::THEME_CHANGE:
117 EmitStyleChangeSignal(styleChange);
120 std::string StyleMonitor::GetDefaultFontFamily() const
122 return mDefaultFontFamily;
125 std::string StyleMonitor::GetDefaultFontStyle() const
127 return mDefaultFontStyle;
130 int StyleMonitor::GetDefaultFontSize() const
132 return mDefaultFontSize;
135 const std::string& StyleMonitor::GetTheme() const
137 return mUserDefinedThemeFilePath;
140 void StyleMonitor::SetTheme(const std::string& path)
142 mUserDefinedThemeFilePath = path;
143 EmitStyleChangeSignal( StyleChange::THEME_CHANGE );
146 bool StyleMonitor::LoadThemeFile( const std::string& filename, std::string& output )
148 bool retval( false );
149 std::ifstream in( filename.c_str(), std::ios::in );
152 std::stringstream buffer;
153 buffer << in.rdbuf();
155 output = buffer.str();
163 Dali::StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal()
165 return mStyleChangeSignal;
168 void StyleMonitor::EmitStyleChangeSignal( StyleChange::Type styleChange )
170 if( !mStyleChangeSignal.Empty() )
172 Dali::StyleMonitor handle( this );
173 mStyleChangeSignal.Emit( handle, styleChange );
177 } // namespace Adaptor
179 } // namespace Internal