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>
25 #include <dali/integration-api/debug.h>
28 #include <adaptor-impl.h>
29 #include <singleton-service-impl.h>
43 #if defined(DEBUG_ENABLED)
44 Dali::Integration::Log::Filter* gLogFilter = Dali::Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_STYLE_MONITOR");
49 BaseHandle handle( StyleMonitor::Get() );
51 if ( !handle && Adaptor::IsAvailable() )
53 Dali::SingletonService service( SingletonService::Get() );
56 Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
57 Dali::StyleMonitor styleMonitor = Dali::StyleMonitor( new StyleMonitor( adaptorImpl.GetPlatformAbstraction() ) );
58 service.Register( typeid( styleMonitor ), styleMonitor );
59 handle = styleMonitor;
65 TypeRegistration STYLE_MONITOR_TYPE( typeid(Dali::StyleMonitor), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
68 * Use font client to get the system default font family
69 * @param[in] fontClient handle to font client
70 * @param[out] fontFamily string representing font family
72 void GetSystemDefaultFontFamily( TextAbstraction::FontClient& fontClient, std::string& fontFamily )
74 TextAbstraction::FontDescription defaultFontDescription;
77 fontClient.GetDefaultPlatformFontDescription( defaultFontDescription );
78 fontFamily = defaultFontDescription.family;
82 } // unnamed namespace
84 Dali::StyleMonitor StyleMonitor::Get()
86 Dali::StyleMonitor styleMonitor;
88 Dali::SingletonService service( SingletonService::Get() );
91 // Check whether the singleton is already created
92 Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::StyleMonitor ) );
95 // If so, downcast the handle
96 styleMonitor = Dali::StyleMonitor( dynamic_cast< StyleMonitor* >( handle.GetObjectPtr() ) );
103 StyleMonitor::StyleMonitor(Integration::PlatformAbstraction& platformAbstraction)
104 : mPlatformAbstraction(platformAbstraction),
107 mfontClient = TextAbstraction::FontClient::Get();
108 GetSystemDefaultFontFamily( mfontClient, mDefaultFontFamily );
109 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "StyleMonitor::StyleMonitor::DefaultFontFamily(%s)\n", mDefaultFontFamily.c_str() );
110 mDefaultFontSize = mPlatformAbstraction.GetDefaultFontSize();
113 StyleMonitor::~StyleMonitor()
117 void StyleMonitor::StyleChanged( StyleChange::Type styleChange )
119 switch ( styleChange )
121 case StyleChange::DEFAULT_FONT_CHANGE:
123 GetSystemDefaultFontFamily( mfontClient, mDefaultFontFamily );
124 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "StyleMonitor::StyleChanged::DefaultFontFamily(%s)\n", mDefaultFontFamily.c_str() );
128 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
130 mDefaultFontSize = mPlatformAbstraction.GetDefaultFontSize();
134 case StyleChange::THEME_CHANGE:
140 EmitStyleChangeSignal(styleChange);
143 std::string StyleMonitor::GetDefaultFontFamily() const
145 return mDefaultFontFamily;
148 std::string StyleMonitor::GetDefaultFontStyle() const
150 return mDefaultFontStyle;
153 int StyleMonitor::GetDefaultFontSize() const
155 return mDefaultFontSize;
158 const std::string& StyleMonitor::GetTheme() const
160 return mUserDefinedThemeFilePath;
163 void StyleMonitor::SetTheme(const std::string& path)
165 mUserDefinedThemeFilePath = path;
166 EmitStyleChangeSignal( StyleChange::THEME_CHANGE );
169 bool StyleMonitor::LoadThemeFile( const std::string& filename, std::string& output )
171 bool retval( false );
172 std::ifstream in( filename.c_str(), std::ios::in );
175 std::stringstream buffer;
176 buffer << in.rdbuf();
178 output = buffer.str();
186 Dali::StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal()
188 return mStyleChangeSignal;
191 void StyleMonitor::EmitStyleChangeSignal( StyleChange::Type styleChange )
193 if( !mStyleChangeSignal.Empty() )
195 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "StyleMonitor::EmitStyleChangeSignal\n" );
196 Dali::StyleMonitor handle( this );
197 mStyleChangeSignal.Emit( handle, styleChange );
201 } // namespace Adaptor
203 } // namespace Internal