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