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 <adaptor-impl.h>
26 #include <singleton-service-impl.h>
42 BaseHandle handle( StyleMonitor::Get() );
44 if ( !handle && Adaptor::IsAvailable() )
46 Dali::SingletonService service( SingletonService::Get() );
49 Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
50 Dali::StyleMonitor styleMonitor = Dali::StyleMonitor( new StyleMonitor( adaptorImpl.GetPlatformAbstraction() ) );
51 service.Register( typeid( styleMonitor ), styleMonitor );
52 handle = styleMonitor;
58 TypeRegistration STYLE_MONITOR_TYPE( typeid(Dali::StyleMonitor), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
60 } // unnamed namespace
62 Dali::StyleMonitor StyleMonitor::Get()
64 Dali::StyleMonitor styleMonitor;
66 Dali::SingletonService service( SingletonService::Get() );
69 // Check whether the singleton is already created
70 Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::StyleMonitor ) );
73 // If so, downcast the handle
74 styleMonitor = Dali::StyleMonitor( dynamic_cast< StyleMonitor* >( handle.GetObjectPtr() ) );
81 StyleMonitor::StyleMonitor(Integration::PlatformAbstraction& platformAbstraction)
82 : mPlatformAbstraction(platformAbstraction),
85 mPlatformAbstraction.GetDefaultFontDescription( mDefaultFontFamily, mDefaultFontStyle );
86 mDefaultFontSize = mPlatformAbstraction.GetDefaultFontSize();
89 StyleMonitor::~StyleMonitor()
93 void StyleMonitor::StyleChanged(StyleChange styleChange)
95 if ( styleChange.defaultFontChange )
97 mPlatformAbstraction.GetDefaultFontDescription( mDefaultFontFamily, mDefaultFontStyle );
99 if ( styleChange.defaultFontSizeChange )
101 mDefaultFontSize = mPlatformAbstraction.GetDefaultFontSize();
104 EmitStyleChangeSignal(styleChange);
107 std::string StyleMonitor::GetDefaultFontFamily() const
109 return mDefaultFontFamily;
112 std::string StyleMonitor::GetDefaultFontStyle() const
114 return mDefaultFontStyle;
117 int StyleMonitor::GetDefaultFontSize() const
119 return mDefaultFontSize;
122 const std::string& StyleMonitor::GetTheme() const
124 return mUserDefinedThemeFilePath;
127 void StyleMonitor::SetTheme(const std::string& path)
129 StyleChange styleChange;
130 styleChange.themeChange = true;
131 styleChange.themeFilePath = path;
132 mUserDefinedThemeFilePath = path;
134 EmitStyleChangeSignal(styleChange);
137 Dali::StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal()
139 return mStyleChangeSignal;
142 void StyleMonitor::EmitStyleChangeSignal(StyleChange styleChange)
144 if( !mStyleChangeSignal.Empty() )
146 Dali::StyleMonitor handle( this );
147 mStyleChangeSignal.Emit( handle, styleChange );
151 } // namespace Adaptor
153 } // namespace Internal