Merge remote-tracking branch 'origin/tizen' into new_text
[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 <dali/public-api/object/type-registry.h>
23
24 // INTERNAL INCLUDES
25 #include <adaptor-impl.h>
26 #include <singleton-service-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     Dali::SingletonService service( SingletonService::Get() );
47     if ( service )
48     {
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;
53     }
54   }
55
56   return handle;
57 }
58 TypeRegistration STYLE_MONITOR_TYPE( typeid(Dali::StyleMonitor), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
59
60 } // unnamed namespace
61
62 Dali::StyleMonitor StyleMonitor::Get()
63 {
64   Dali::StyleMonitor styleMonitor;
65
66   Dali::SingletonService service( SingletonService::Get() );
67   if ( service )
68   {
69     // Check whether the singleton is already created
70     Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::StyleMonitor ) );
71     if(handle)
72     {
73       // If so, downcast the handle
74       styleMonitor = Dali::StyleMonitor( dynamic_cast< StyleMonitor* >( handle.GetObjectPtr() ) );
75     }
76   }
77
78   return styleMonitor;
79 }
80
81 StyleMonitor::StyleMonitor(Integration::PlatformAbstraction& platformAbstraction)
82 : mPlatformAbstraction(platformAbstraction)
83 {
84 }
85
86 StyleMonitor::~StyleMonitor()
87 {
88 }
89
90 void StyleMonitor::StyleChanged(StyleChange styleChange)
91 {
92   if (styleChange.defaultFontChange || styleChange.defaultFontSizeChange)
93   {
94     //mPlatformAbstraction.UpdateDefaultsFromDevice();
95   }
96
97   EmitStyleChangeSignal(styleChange);
98 }
99
100 std::string StyleMonitor::GetDefaultFontFamily() const
101 {
102   //return mPlatformAbstraction.GetDefaultFontFamily();
103   return std::string();
104 }
105
106 float StyleMonitor::GetDefaultFontSize() const
107 {
108   //return mPlatformAbstraction.GetDefaultFontSize();
109   return float();
110 }
111
112 const std::string& StyleMonitor::GetTheme() const
113 {
114   return mUserDefinedThemeFilePath;
115 }
116
117 void StyleMonitor::SetTheme(const std::string& path)
118 {
119   StyleChange styleChange;
120   styleChange.themeChange = true;
121   styleChange.themeFilePath = path;
122   mUserDefinedThemeFilePath = path;
123
124   EmitStyleChangeSignal(styleChange);
125 }
126
127 Dali::StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal()
128 {
129   return mStyleChangeSignal;
130 }
131
132 void StyleMonitor::EmitStyleChangeSignal(StyleChange styleChange)
133 {
134   if( !mStyleChangeSignal.Empty() )
135   {
136     Dali::StyleMonitor handle( this );
137     mStyleChangeSignal.Emit( handle, styleChange );
138   }
139 }
140
141 } // namespace Adaptor
142
143 } // namespace Internal
144
145 } // namespace Dali