[dali_1.0.4] Merge branch 'tizen'
[platform/core/uifw/dali-adaptor.git] / adaptors / common / style-monitor-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include "style-monitor-impl.h"
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry.h>
23 #include <adaptor-impl.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 namespace Adaptor
32 {
33
34 namespace
35 {
36
37 BaseHandle Create()
38 {
39   BaseHandle handle( StyleMonitor::Get() );
40
41   if ( !handle && Adaptor::IsAvailable() )
42   {
43     Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
44     Dali::StyleMonitor styleMonitor = Dali::StyleMonitor( new StyleMonitor( adaptorImpl.GetPlatformAbstraction() ) );
45     adaptorImpl.RegisterSingleton( typeid( styleMonitor ), styleMonitor );
46     handle = styleMonitor;
47   }
48
49   return handle;
50 }
51 TypeRegistration STYLE_MONITOR_TYPE( typeid(Dali::StyleMonitor), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
52
53 } // unnamed namespace
54
55 Dali::StyleMonitor StyleMonitor::Get()
56 {
57   Dali::StyleMonitor styleMonitor;
58
59   if ( Adaptor::IsAvailable() )
60   {
61     // Check whether the singleton is already created
62     Dali::BaseHandle handle = Dali::Adaptor::Get().GetSingleton( typeid( Dali::StyleMonitor ) );
63     if(handle)
64     {
65       // If so, downcast the handle
66       styleMonitor = Dali::StyleMonitor( dynamic_cast< StyleMonitor* >( handle.GetObjectPtr() ) );
67     }
68   }
69
70   return styleMonitor;
71 }
72
73 StyleMonitor::StyleMonitor(Integration::PlatformAbstraction& platformAbstraction)
74 : mPlatformAbstraction(platformAbstraction)
75 {
76 }
77
78 StyleMonitor::~StyleMonitor()
79 {
80 }
81
82 void StyleMonitor::StyleChanged(StyleChange styleChange)
83 {
84   if (styleChange.defaultFontChange || styleChange.defaultFontSizeChange)
85   {
86     mPlatformAbstraction.UpdateDefaultsFromDevice();
87   }
88
89   EmitStyleChangeSignal(styleChange);
90 }
91
92 std::string StyleMonitor::GetDefaultFontFamily() const
93 {
94   return mPlatformAbstraction.GetDefaultFontFamily();
95 }
96
97 float StyleMonitor::GetDefaultFontSize() const
98 {
99   return mPlatformAbstraction.GetDefaultFontSize();
100 }
101
102 const std::string& StyleMonitor::GetTheme() const
103 {
104   return mUserDefinedThemeFilePath;
105 }
106
107 void StyleMonitor::SetTheme(const std::string& path)
108 {
109   StyleChange styleChange;
110   styleChange.themeChange = true;
111   styleChange.themeFilePath = path;
112   mUserDefinedThemeFilePath = path;
113
114   EmitStyleChangeSignal(styleChange);
115 }
116
117 Dali::StyleMonitor::StyleChangeSignalV2& StyleMonitor::StyleChangeSignal()
118 {
119   return mStyleChangeSignalV2;
120 }
121
122 void StyleMonitor::EmitStyleChangeSignal(StyleChange styleChange)
123 {
124   if( !mStyleChangeSignalV2.Empty() )
125   {
126     Dali::StyleMonitor handle( this );
127     mStyleChangeSignalV2.Emit( handle, styleChange );
128   }
129 }
130
131 } // namespace Adaptor
132
133 } // namespace Internal
134
135 } // namespace Dali