Changed signal order for StyleManager
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-style-monitor.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 #include "toolkit-style-monitor.h"
19
20 #include <dali/public-api/common/dali-common.h>
21 #include <dali/public-api/object/base-object.h>
22 #include <dali/public-api/signals/dali-signal.h>
23
24 namespace Dali
25 {
26 const std::string Dali::StyleMonitor::DEFAULT_FONT_FAMILY("DefaultFont");
27 const std::string Dali::StyleMonitor::DEFAULT_FONT_STYLE("Regular");
28 const float       Dali::StyleMonitor::DEFAULT_FONT_SIZE(1.0f);
29 }
30
31 namespace
32 {
33 const char* DEFAULT_THEME=
34   "{\"styles\":{\n"
35   "  \"textlabel\":\n"
36   "    {\n"
37   "      \"fontStyle\":\"Regular\",\n"
38   "      \"pointSize\":18\n"
39   "    }\n"
40   "  }\n"
41   "}\n";
42
43 std::string gTheme;
44 std::string gFontFamily = Dali::StyleMonitor::DEFAULT_FONT_FAMILY;
45 std::string gFontStyle  = Dali::StyleMonitor::DEFAULT_FONT_STYLE;
46 float       gFontSize   = Dali::StyleMonitor::DEFAULT_FONT_SIZE;
47 }
48
49 namespace Dali
50 {
51 namespace Internal
52 {
53 namespace Adaptor
54 {
55 /**
56  * Stub for the StyleMonitor
57  */
58 class StyleMonitor : public BaseObject
59 {
60 public: // Creation & Destruction
61   static Dali::StyleMonitor Get();
62   StyleMonitor();
63   ~StyleMonitor();
64
65 public: // Style Information
66   std::string GetDefaultFontFamily() const;
67   std::string GetDefaultFontStyle() const;
68   float GetDefaultFontSize() const;
69   const std::string& GetTheme() const;
70   void SetTheme(std::string theme);
71   bool LoadThemeFile( const std::string& filename, std::string& output );
72
73 public: // Signals
74   Dali::StyleMonitor::StyleChangeSignalType& StyleChangeSignal();
75
76   void EmitStyleChangeSignal(StyleChange::Type styleChange)
77   {
78     mStyleChangeSignal.Emit(Dali::StyleMonitor(this), styleChange);
79   }
80
81 private:
82   Dali::StyleMonitor::StyleChangeSignalType mStyleChangeSignal;
83   static Dali::StyleMonitor mToolkitStyleMonitor;
84   std::string mTheme;
85
86   std::string mOutput; //<<< Test output. Use SetThemeFileOutput in a testharness to use it.
87 };
88
89 Dali::StyleMonitor StyleMonitor::mToolkitStyleMonitor;
90
91 Dali::StyleMonitor StyleMonitor::Get()
92 {
93   if( ! mToolkitStyleMonitor )
94   {
95     mToolkitStyleMonitor = Dali::StyleMonitor( new Dali::Internal::Adaptor::StyleMonitor() );
96   }
97   return mToolkitStyleMonitor;
98 }
99
100 StyleMonitor::StyleMonitor()
101 : mTheme("default")
102 {
103 }
104
105 StyleMonitor::~StyleMonitor()
106 {
107 }
108
109 std::string StyleMonitor::GetDefaultFontFamily() const
110 {
111   return gFontFamily;
112 }
113
114 std::string StyleMonitor::GetDefaultFontStyle() const
115 {
116   return gFontStyle;
117 }
118
119 float StyleMonitor::GetDefaultFontSize() const
120 {
121   return gFontSize;
122
123 }
124
125 const std::string& StyleMonitor::GetTheme() const
126 {
127   return mTheme;
128 }
129
130 void StyleMonitor::SetTheme(std::string path)
131 {
132   mTheme = path;
133   EmitStyleChangeSignal( StyleChange::THEME_CHANGE );
134 }
135
136 bool StyleMonitor::LoadThemeFile( const std::string& filename, std::string& output )
137 {
138   if( !gTheme.empty() )
139   {
140     output = gTheme;
141   }
142   else
143   {
144     output = DEFAULT_THEME;
145   }
146   return true;
147 }
148
149 Dali::StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal()
150 {
151   return mStyleChangeSignal;
152 }
153
154 } // namespace Adaptor
155 } // namespace Internal
156
157 ////////////////////////////////////////////////////////////////////////////////////////////////////
158
159 Internal::Adaptor::StyleMonitor& GetImplementation(Dali::StyleMonitor& monitor)
160 {
161   BaseObject& object = monitor.GetBaseObject();
162   return static_cast<Internal::Adaptor::StyleMonitor&>(object);
163 }
164 const Internal::Adaptor::StyleMonitor& GetImplementation(const Dali::StyleMonitor& monitor)
165 {
166   const BaseObject& object = monitor.GetBaseObject();
167   return static_cast<const Internal::Adaptor::StyleMonitor&>(object);
168 }
169
170 StyleMonitor::StyleMonitor()
171 {
172 }
173
174 StyleMonitor::StyleMonitor(const StyleMonitor& monitor)
175 : BaseHandle(monitor)
176 {
177 }
178
179 StyleMonitor StyleMonitor::StyleMonitor::Get()
180 {
181   return Internal::Adaptor::StyleMonitor::Get();
182 }
183
184 StyleMonitor::~StyleMonitor()
185 {
186 }
187
188 std::string StyleMonitor::GetDefaultFontFamily() const
189 {
190   return GetImplementation(*this).GetDefaultFontFamily();
191 }
192
193 std::string StyleMonitor::GetDefaultFontStyle() const
194 {
195   return GetImplementation(*this).GetDefaultFontStyle();
196 }
197
198 float StyleMonitor::GetDefaultFontSize() const
199 {
200   return GetImplementation(*this).GetDefaultFontSize();
201 }
202
203 const std::string& StyleMonitor::GetTheme() const
204 {
205   return GetImplementation(*this).GetTheme();
206 }
207
208 void StyleMonitor::SetTheme(std::string themeFilePath)
209 {
210   GetImplementation(*this).SetTheme(themeFilePath);
211 }
212
213 StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal()
214 {
215   return GetImplementation(*this).StyleChangeSignal();
216 }
217
218 void StyleMonitor::EmitStyleChangeSignal(StyleChange::Type styleChange)
219 {
220   GetImplementation(*this).EmitStyleChangeSignal(styleChange);
221 }
222
223 bool StyleMonitor::LoadThemeFile( const std::string& filename, std::string& output )
224 {
225   return GetImplementation(*this).LoadThemeFile(filename, output);
226 }
227
228 StyleMonitor& StyleMonitor::operator=(const StyleMonitor& monitor)
229 {
230   if( *this != monitor )
231   {
232     BaseHandle::operator=(monitor);
233   }
234   return *this;
235 }
236
237 StyleMonitor::StyleMonitor(Internal::Adaptor::StyleMonitor* internal)
238 : BaseHandle(internal)
239 {
240 }
241
242 } // namespace Dali
243
244 namespace Test
245 {
246 namespace StyleMonitor
247 {
248
249 void SetThemeFileOutput( const std::string& output )
250 {
251   gTheme = output;
252 }
253
254 void SetDefaultFontFamily(const std::string& family)
255 {
256   gFontFamily = family;
257 }
258
259 void SetDefaultFontStyle(const std::string& style)
260 {
261   gFontStyle = style;
262 }
263
264 void SetDefaultFontSize( float size )
265 {
266   gFontSize = size;
267 }
268
269 } // StyleMonitor
270 } // Test