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");
48 * Use font client to get the system default font family
49 * @param[in] fontClient handle to font client
50 * @param[out] fontFamily string representing font family
52 void GetSystemDefaultFontFamily( TextAbstraction::FontClient& fontClient, std::string& fontFamily )
54 TextAbstraction::FontDescription defaultFontDescription;
57 fontClient.GetDefaultPlatformFontDescription( defaultFontDescription );
58 fontFamily = defaultFontDescription.family;
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() ) );
80 Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
81 styleMonitor = Dali::StyleMonitor( new StyleMonitor( adaptorImpl.GetPlatformAbstraction() ) );
82 service.Register( typeid( styleMonitor ), styleMonitor );
89 StyleMonitor::StyleMonitor(Integration::PlatformAbstraction& platformAbstraction)
90 : mPlatformAbstraction(platformAbstraction),
93 mFontClient = TextAbstraction::FontClient::Get();
94 GetSystemDefaultFontFamily( mFontClient, mDefaultFontFamily );
95 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "StyleMonitor::StyleMonitor::DefaultFontFamily(%s)\n", mDefaultFontFamily.c_str() );
96 mDefaultFontSize = mPlatformAbstraction.GetDefaultFontSize();
99 StyleMonitor::~StyleMonitor()
103 void StyleMonitor::StyleChanged( StyleChange::Type styleChange )
105 switch ( styleChange )
107 case StyleChange::DEFAULT_FONT_CHANGE:
111 mFontClient.ResetSystemDefaults();
112 GetSystemDefaultFontFamily( mFontClient, mDefaultFontFamily );
114 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "StyleMonitor::StyleChanged::DefaultFontFamily(%s)\n", mDefaultFontFamily.c_str() );
118 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
120 mDefaultFontSize = mPlatformAbstraction.GetDefaultFontSize();
124 case StyleChange::THEME_CHANGE:
130 EmitStyleChangeSignal(styleChange);
133 std::string StyleMonitor::GetDefaultFontFamily() const
135 return mDefaultFontFamily;
138 std::string StyleMonitor::GetDefaultFontStyle() const
140 return mDefaultFontStyle;
143 int StyleMonitor::GetDefaultFontSize() const
145 return mDefaultFontSize;
148 const std::string& StyleMonitor::GetTheme() const
150 return mUserDefinedThemeFilePath;
153 void StyleMonitor::SetTheme(const std::string& path)
155 mUserDefinedThemeFilePath = path;
156 EmitStyleChangeSignal( StyleChange::THEME_CHANGE );
159 bool StyleMonitor::LoadThemeFile( const std::string& filename, std::string& output )
161 bool retval( false );
162 std::ifstream in( filename.c_str(), std::ios::in );
165 std::stringstream buffer;
166 buffer << in.rdbuf();
168 output = buffer.str();
176 Dali::StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal()
178 return mStyleChangeSignal;
181 void StyleMonitor::EmitStyleChangeSignal( StyleChange::Type styleChange )
183 if( !mStyleChangeSignal.Empty() )
185 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "StyleMonitor::EmitStyleChangeSignal\n" );
186 Dali::StyleMonitor handle( this );
187 mStyleChangeSignal.Emit( handle, styleChange );
191 } // namespace Adaptor
193 } // namespace Internal