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   mDefaultFontSize(-1)
84 {
85   mPlatformAbstraction.GetDefaultFontDescription( mDefaultFontFamily, mDefaultFontStyle );
86   mDefaultFontSize = mPlatformAbstraction.GetDefaultFontSize();
87 }
88
89 StyleMonitor::~StyleMonitor()
90 {
91 }
92
93 void StyleMonitor::StyleChanged(StyleChange styleChange)
94 {
95   if ( styleChange.defaultFontChange )
96   {
97     mPlatformAbstraction.GetDefaultFontDescription( mDefaultFontFamily, mDefaultFontStyle );
98   }
99   if ( styleChange.defaultFontSizeChange )
100   {
101     mDefaultFontSize = mPlatformAbstraction.GetDefaultFontSize();
102   }
103
104   EmitStyleChangeSignal(styleChange);
105 }
106
107 std::string StyleMonitor::GetDefaultFontFamily() const
108 {
109   return mDefaultFontFamily;
110 }
111
112 std::string StyleMonitor::GetDefaultFontStyle() const
113 {
114   return mDefaultFontStyle;
115 }
116
117 int StyleMonitor::GetDefaultFontSize() const
118 {
119   return mDefaultFontSize;
120 }
121
122 const std::string& StyleMonitor::GetTheme() const
123 {
124   return mUserDefinedThemeFilePath;
125 }
126
127 void StyleMonitor::SetTheme(const std::string& path)
128 {
129   StyleChange styleChange;
130   styleChange.themeChange = true;
131   styleChange.themeFilePath = path;
132   mUserDefinedThemeFilePath = path;
133
134   EmitStyleChangeSignal(styleChange);
135 }
136
137 Dali::StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal()
138 {
139   return mStyleChangeSignal;
140 }
141
142 void StyleMonitor::EmitStyleChangeSignal(StyleChange styleChange)
143 {
144   if( !mStyleChangeSignal.Empty() )
145   {
146     Dali::StyleMonitor handle( this );
147     mStyleChangeSignal.Emit( handle, styleChange );
148   }
149 }
150
151 } // namespace Adaptor
152
153 } // namespace Internal
154
155 } // namespace Dali