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 styleMonitor = Dali::StyleMonitor( new StyleMonitor() );
81 service.Register( typeid( styleMonitor ), styleMonitor );
88 StyleMonitor::StyleMonitor()
89 : mDefaultFontSize(-1)
91 mFontClient = TextAbstraction::FontClient::Get();
92 GetSystemDefaultFontFamily( mFontClient, mDefaultFontFamily );
93 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "StyleMonitor::StyleMonitor::DefaultFontFamily(%s)\n", mDefaultFontFamily.c_str() );
94 mDefaultFontSize = mFontClient.GetDefaultFontSize();
97 StyleMonitor::~StyleMonitor()
101 void StyleMonitor::StyleChanged( StyleChange::Type styleChange )
103 switch ( styleChange )
105 case StyleChange::DEFAULT_FONT_CHANGE:
109 mFontClient.ResetSystemDefaults();
110 GetSystemDefaultFontFamily( mFontClient, mDefaultFontFamily );
112 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "StyleMonitor::StyleChanged::DefaultFontFamily(%s)\n", mDefaultFontFamily.c_str() );
116 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
118 mDefaultFontSize = mFontClient.GetDefaultFontSize();
122 case StyleChange::THEME_CHANGE:
128 EmitStyleChangeSignal(styleChange);
131 std::string StyleMonitor::GetDefaultFontFamily() const
133 return mDefaultFontFamily;
136 std::string StyleMonitor::GetDefaultFontStyle() const
138 return mDefaultFontStyle;
141 int StyleMonitor::GetDefaultFontSize() const
143 return mDefaultFontSize;
146 const std::string& StyleMonitor::GetTheme() const
148 return mUserDefinedThemeFilePath;
151 void StyleMonitor::SetTheme(const std::string& path)
153 mUserDefinedThemeFilePath = path;
154 EmitStyleChangeSignal( StyleChange::THEME_CHANGE );
157 bool StyleMonitor::LoadThemeFile( const std::string& filename, std::string& output )
159 bool retval( false );
160 std::ifstream in( filename.c_str(), std::ios::in );
163 std::stringstream buffer;
164 buffer << in.rdbuf();
166 output = buffer.str();
174 Dali::StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal()
176 return mStyleChangeSignal;
179 void StyleMonitor::EmitStyleChangeSignal( StyleChange::Type styleChange )
181 if( !mStyleChangeSignal.Empty() )
183 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "StyleMonitor::EmitStyleChangeSignal\n" );
184 Dali::StyleMonitor handle( this );
185 mStyleChangeSignal.Emit( handle, styleChange );
189 } // namespace Adaptor
191 } // namespace Internal