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"
45 NamedTheme( const std::string& name, const std::string& theme )
46 : name(name), theme(theme)
53 typedef std::vector< NamedTheme > NamedThemes;
57 std::string gFontFamily = Dali::StyleMonitor::DEFAULT_FONT_FAMILY;
58 std::string gFontStyle = Dali::StyleMonitor::DEFAULT_FONT_STYLE;
59 float gFontSize = Dali::StyleMonitor::DEFAULT_FONT_SIZE;
69 * Stub for the StyleMonitor
71 class StyleMonitor : public BaseObject
73 public: // Creation & Destruction
74 static Dali::StyleMonitor Get();
78 public: // Style Information
79 std::string GetDefaultFontFamily() const;
80 std::string GetDefaultFontStyle() const;
81 float GetDefaultFontSize() const;
82 const std::string& GetTheme() const;
83 void SetTheme(std::string theme);
84 bool LoadThemeFile( const std::string& filename, std::string& output );
87 Dali::StyleMonitor::StyleChangeSignalType& StyleChangeSignal();
89 void EmitStyleChangeSignal(StyleChange::Type styleChange)
91 mStyleChangeSignal.Emit(Dali::StyleMonitor(this), styleChange);
95 Dali::StyleMonitor::StyleChangeSignalType mStyleChangeSignal;
96 static Dali::StyleMonitor mToolkitStyleMonitor;
98 std::string mTheme; ///<< Current theme name
101 Dali::StyleMonitor StyleMonitor::mToolkitStyleMonitor;
103 Dali::StyleMonitor StyleMonitor::Get()
105 if( ! mToolkitStyleMonitor )
107 mToolkitStyleMonitor = Dali::StyleMonitor( new Dali::Internal::Adaptor::StyleMonitor() );
109 return mToolkitStyleMonitor;
112 StyleMonitor::StyleMonitor()
117 StyleMonitor::~StyleMonitor()
121 std::string StyleMonitor::GetDefaultFontFamily() const
126 std::string StyleMonitor::GetDefaultFontStyle() const
131 float StyleMonitor::GetDefaultFontSize() const
137 const std::string& StyleMonitor::GetTheme() const
142 void StyleMonitor::SetTheme(std::string path)
145 EmitStyleChangeSignal( StyleChange::THEME_CHANGE );
148 bool StyleMonitor::LoadThemeFile( const std::string& filename, std::string& output )
150 for( NamedThemes::iterator iter = gThemes.begin(); iter != gThemes.end(); ++iter )
152 NamedTheme& theme = *iter;
153 if( theme.name == filename )
155 output = theme.theme;
160 if( !gTheme.empty() )
166 output = DEFAULT_THEME;
171 Dali::StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal()
173 return mStyleChangeSignal;
176 } // namespace Adaptor
177 } // namespace Internal
179 ////////////////////////////////////////////////////////////////////////////////////////////////////
181 Internal::Adaptor::StyleMonitor& GetImplementation(Dali::StyleMonitor& monitor)
183 BaseObject& object = monitor.GetBaseObject();
184 return static_cast<Internal::Adaptor::StyleMonitor&>(object);
186 const Internal::Adaptor::StyleMonitor& GetImplementation(const Dali::StyleMonitor& monitor)
188 const BaseObject& object = monitor.GetBaseObject();
189 return static_cast<const Internal::Adaptor::StyleMonitor&>(object);
192 StyleMonitor::StyleMonitor()
196 StyleMonitor::StyleMonitor(const StyleMonitor& monitor)
197 : BaseHandle(monitor)
201 StyleMonitor StyleMonitor::StyleMonitor::Get()
203 return Internal::Adaptor::StyleMonitor::Get();
206 StyleMonitor::~StyleMonitor()
210 std::string StyleMonitor::GetDefaultFontFamily() const
212 return GetImplementation(*this).GetDefaultFontFamily();
215 std::string StyleMonitor::GetDefaultFontStyle() const
217 return GetImplementation(*this).GetDefaultFontStyle();
220 float StyleMonitor::GetDefaultFontSize() const
222 return GetImplementation(*this).GetDefaultFontSize();
225 const std::string& StyleMonitor::GetTheme() const
227 return GetImplementation(*this).GetTheme();
230 void StyleMonitor::SetTheme(std::string themeFilePath)
232 GetImplementation(*this).SetTheme(themeFilePath);
235 StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal()
237 return GetImplementation(*this).StyleChangeSignal();
240 void StyleMonitor::EmitStyleChangeSignal(StyleChange::Type styleChange)
242 GetImplementation(*this).EmitStyleChangeSignal(styleChange);
245 bool StyleMonitor::LoadThemeFile( const std::string& filename, std::string& output )
247 return GetImplementation(*this).LoadThemeFile(filename, output);
250 StyleMonitor& StyleMonitor::operator=(const StyleMonitor& monitor)
252 if( *this != monitor )
254 BaseHandle::operator=(monitor);
259 StyleMonitor::StyleMonitor(Internal::Adaptor::StyleMonitor* internal)
260 : BaseHandle(internal)
268 namespace StyleMonitor
271 void SetThemeFileOutput( const std::string& name, const std::string& output )
273 for( NamedThemes::iterator iter = gThemes.begin(); iter != gThemes.end(); ++iter )
275 NamedTheme& theme = *iter;
276 if( theme.name == name )
278 theme.theme = output;
283 gThemes.push_back( NamedTheme( name, output ) );
286 void SetDefaultFontFamily(const std::string& family)
288 gFontFamily = family;
291 void SetDefaultFontStyle(const std::string& style)
296 void SetDefaultFontSize( float size )