2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
18 #include "style-monitor-impl.h"
24 #include <dali/public-api/object/type-registry.h>
25 #include <internal/common/adaptor-impl.h>
39 void DefaultFontSizeChangeNotification(keynode_t* node, void* data)
41 StyleMonitor* styleMonitor = static_cast<StyleMonitor*>(data);
43 StyleChange styleChange;
44 styleChange.defaultFontSizeChange = true;
45 styleMonitor->StyleChanged(styleChange);
50 BaseHandle handle( StyleMonitor::Get() );
52 if ( !handle && Adaptor::IsAvailable() )
54 Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
55 Dali::StyleMonitor styleMonitor = Dali::StyleMonitor( new StyleMonitor( adaptorImpl.GetPlatformAbstraction() ) );
56 adaptorImpl.RegisterSingleton( typeid( styleMonitor ), styleMonitor );
57 handle = styleMonitor;
62 TypeRegistration STYLE_MONITOR_TYPE( typeid(Dali::StyleMonitor), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
64 } // unnamed namespace
66 Dali::StyleMonitor StyleMonitor::Get()
68 Dali::StyleMonitor styleMonitor;
70 if ( Adaptor::IsAvailable() )
72 // Check whether the singleton is already created
73 Dali::BaseHandle handle = Dali::Adaptor::Get().GetSingleton( typeid( Dali::StyleMonitor ) );
76 // If so, downcast the handle
77 styleMonitor = Dali::StyleMonitor( dynamic_cast< StyleMonitor* >( handle.GetObjectPtr() ) );
84 StyleMonitor::StyleMonitor(Integration::PlatformAbstraction& platformAbstraction)
85 : mPlatformAbstraction(platformAbstraction)
87 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, DefaultFontSizeChangeNotification, this );
90 StyleMonitor::~StyleMonitor()
92 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, DefaultFontSizeChangeNotification );
95 void StyleMonitor::StyleChanged(StyleChange styleChange)
97 if (styleChange.defaultFontChange || styleChange.defaultFontSizeChange)
99 mPlatformAbstraction.UpdateDefaultsFromDevice();
102 EmitStyleChangeSignal(styleChange);
105 std::string StyleMonitor::GetDefaultFontFamily() const
107 return mPlatformAbstraction.GetDefaultFontFamily();
110 float StyleMonitor::GetDefaultFontSize() const
112 return mPlatformAbstraction.GetDefaultFontSize();
115 const std::string& StyleMonitor::GetTheme() const
117 return mUserDefinedThemeFilePath;
120 void StyleMonitor::SetTheme(const std::string& path)
122 StyleChange styleChange;
123 styleChange.themeChange = true;
124 styleChange.themeFilePath = path;
125 mUserDefinedThemeFilePath = path;
127 EmitStyleChangeSignal(styleChange);
130 Dali::StyleMonitor::StyleChangeSignalV2& StyleMonitor::StyleChangeSignal()
132 return mStyleChangeSignalV2;
135 void StyleMonitor::EmitStyleChangeSignal(StyleChange styleChange)
137 if( !mStyleChangeSignalV2.Empty() )
139 Dali::StyleMonitor handle( this );
140 mStyleChangeSignalV2.Emit( handle, styleChange );
144 } // namespace Adaptor
146 } // namespace Internal