2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "toolkit-style-monitor.h"
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>
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);
33 const char* DEFAULT_THEME=
37 " \"fontStyle\":\"Regular\",\n"
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;
56 * Stub for the StyleMonitor
58 class StyleMonitor : public BaseObject
60 public: // Creation & Destruction
61 static Dali::StyleMonitor Get();
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 );
74 Dali::StyleMonitor::StyleChangeSignalType& StyleChangeSignal();
76 void EmitStyleChangeSignal(StyleChange::Type styleChange)
78 mStyleChangeSignal.Emit(Dali::StyleMonitor(this), styleChange);
82 Dali::StyleMonitor::StyleChangeSignalType mStyleChangeSignal;
83 static Dali::StyleMonitor mToolkitStyleMonitor;
86 std::string mOutput; //<<< Test output. Use SetThemeFileOutput in a testharness to use it.
89 Dali::StyleMonitor StyleMonitor::mToolkitStyleMonitor;
91 Dali::StyleMonitor StyleMonitor::Get()
93 if( ! mToolkitStyleMonitor )
95 mToolkitStyleMonitor = Dali::StyleMonitor( new Dali::Internal::Adaptor::StyleMonitor() );
97 return mToolkitStyleMonitor;
100 StyleMonitor::StyleMonitor()
105 StyleMonitor::~StyleMonitor()
109 std::string StyleMonitor::GetDefaultFontFamily() const
114 std::string StyleMonitor::GetDefaultFontStyle() const
119 float StyleMonitor::GetDefaultFontSize() const
125 const std::string& StyleMonitor::GetTheme() const
130 void StyleMonitor::SetTheme(std::string path)
133 EmitStyleChangeSignal( StyleChange::THEME_CHANGE );
136 bool StyleMonitor::LoadThemeFile( const std::string& filename, std::string& output )
138 if( !gTheme.empty() )
144 output = DEFAULT_THEME;
149 Dali::StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal()
151 return mStyleChangeSignal;
154 } // namespace Adaptor
155 } // namespace Internal
157 ////////////////////////////////////////////////////////////////////////////////////////////////////
159 Internal::Adaptor::StyleMonitor& GetImplementation(Dali::StyleMonitor& monitor)
161 BaseObject& object = monitor.GetBaseObject();
162 return static_cast<Internal::Adaptor::StyleMonitor&>(object);
164 const Internal::Adaptor::StyleMonitor& GetImplementation(const Dali::StyleMonitor& monitor)
166 const BaseObject& object = monitor.GetBaseObject();
167 return static_cast<const Internal::Adaptor::StyleMonitor&>(object);
170 StyleMonitor::StyleMonitor()
174 StyleMonitor::StyleMonitor(const StyleMonitor& monitor)
175 : BaseHandle(monitor)
179 StyleMonitor StyleMonitor::StyleMonitor::Get()
181 return Internal::Adaptor::StyleMonitor::Get();
184 StyleMonitor::~StyleMonitor()
188 std::string StyleMonitor::GetDefaultFontFamily() const
190 return GetImplementation(*this).GetDefaultFontFamily();
193 std::string StyleMonitor::GetDefaultFontStyle() const
195 return GetImplementation(*this).GetDefaultFontStyle();
198 float StyleMonitor::GetDefaultFontSize() const
200 return GetImplementation(*this).GetDefaultFontSize();
203 const std::string& StyleMonitor::GetTheme() const
205 return GetImplementation(*this).GetTheme();
208 void StyleMonitor::SetTheme(std::string themeFilePath)
210 GetImplementation(*this).SetTheme(themeFilePath);
213 StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal()
215 return GetImplementation(*this).StyleChangeSignal();
218 void StyleMonitor::EmitStyleChangeSignal(StyleChange::Type styleChange)
220 GetImplementation(*this).EmitStyleChangeSignal(styleChange);
223 bool StyleMonitor::LoadThemeFile( const std::string& filename, std::string& output )
225 return GetImplementation(*this).LoadThemeFile(filename, output);
228 StyleMonitor& StyleMonitor::operator=(const StyleMonitor& monitor)
230 if( *this != monitor )
232 BaseHandle::operator=(monitor);
237 StyleMonitor::StyleMonitor(Internal::Adaptor::StyleMonitor* internal)
238 : BaseHandle(internal)
246 namespace StyleMonitor
249 void SetThemeFileOutput( const std::string& output )
254 void SetDefaultFontFamily(const std::string& family)
256 gFontFamily = family;
259 void SetDefaultFontStyle(const std::string& style)
264 void SetDefaultFontSize( float size )