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.
19 #include "toolkit-style-monitor.h"
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <dali/public-api/object/base-object.h>
25 #include <dali/public-api/signals/dali-signal.h>
29 const std::string Dali::StyleMonitor::DEFAULT_FONT_FAMILY("DefaultFont");
30 const std::string Dali::StyleMonitor::DEFAULT_FONT_STYLE("Regular");
31 const float Dali::StyleMonitor::DEFAULT_FONT_SIZE(1.0f);
36 const char* DEFAULT_THEME=
40 " \"fontStyle\":\"Regular\",\n"
48 NamedTheme( const std::string& name, const std::string& theme )
49 : name(name), theme(theme)
56 typedef std::vector< NamedTheme > NamedThemes;
60 std::string gFontFamily = Dali::StyleMonitor::DEFAULT_FONT_FAMILY;
61 std::string gFontStyle = Dali::StyleMonitor::DEFAULT_FONT_STYLE;
62 float gFontSize = Dali::StyleMonitor::DEFAULT_FONT_SIZE;
72 * Stub for the StyleMonitor
74 class StyleMonitor : public BaseObject
76 public: // Creation & Destruction
77 static Dali::StyleMonitor Get();
81 public: // Style Information
82 std::string GetDefaultFontFamily() const;
83 std::string GetDefaultFontStyle() const;
84 float GetDefaultFontSize() const;
85 const std::string& GetTheme() const;
86 void SetTheme(std::string theme);
87 bool LoadThemeFile( const std::string& filename, std::string& output );
90 Dali::StyleMonitor::StyleChangeSignalType& StyleChangeSignal();
92 void EmitStyleChangeSignal(StyleChange::Type styleChange)
94 mStyleChangeSignal.Emit(Dali::StyleMonitor(this), styleChange);
98 Dali::StyleMonitor::StyleChangeSignalType mStyleChangeSignal;
99 static Dali::StyleMonitor mToolkitStyleMonitor;
101 std::string mTheme; ///<< Current theme name
104 Dali::StyleMonitor StyleMonitor::mToolkitStyleMonitor;
106 Dali::StyleMonitor StyleMonitor::Get()
108 if( ! mToolkitStyleMonitor )
110 mToolkitStyleMonitor = Dali::StyleMonitor( new Dali::Internal::Adaptor::StyleMonitor() );
112 return mToolkitStyleMonitor;
115 StyleMonitor::StyleMonitor()
120 StyleMonitor::~StyleMonitor()
124 std::string StyleMonitor::GetDefaultFontFamily() const
129 std::string StyleMonitor::GetDefaultFontStyle() const
134 float StyleMonitor::GetDefaultFontSize() const
140 const std::string& StyleMonitor::GetTheme() const
145 void StyleMonitor::SetTheme(std::string path)
148 EmitStyleChangeSignal( StyleChange::THEME_CHANGE );
151 bool StyleMonitor::LoadThemeFile( const std::string& filename, std::string& output )
153 for( NamedThemes::iterator iter = gThemes.begin(); iter != gThemes.end(); ++iter )
155 NamedTheme& theme = *iter;
156 if( theme.name == filename )
158 output = theme.theme;
163 if( !gTheme.empty() )
169 output = DEFAULT_THEME;
174 Dali::StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal()
176 return mStyleChangeSignal;
179 } // namespace Adaptor
180 } // namespace Internal
182 ////////////////////////////////////////////////////////////////////////////////////////////////////
184 Internal::Adaptor::StyleMonitor& GetImplementation(Dali::StyleMonitor& monitor)
186 BaseObject& object = monitor.GetBaseObject();
187 return static_cast<Internal::Adaptor::StyleMonitor&>(object);
189 const Internal::Adaptor::StyleMonitor& GetImplementation(const Dali::StyleMonitor& monitor)
191 const BaseObject& object = monitor.GetBaseObject();
192 return static_cast<const Internal::Adaptor::StyleMonitor&>(object);
195 StyleMonitor::StyleMonitor()
199 StyleMonitor::StyleMonitor(const StyleMonitor& monitor)
200 : BaseHandle(monitor)
204 StyleMonitor StyleMonitor::StyleMonitor::Get()
206 return Internal::Adaptor::StyleMonitor::Get();
209 StyleMonitor::~StyleMonitor()
213 std::string StyleMonitor::GetDefaultFontFamily() const
215 return GetImplementation(*this).GetDefaultFontFamily();
218 std::string StyleMonitor::GetDefaultFontStyle() const
220 return GetImplementation(*this).GetDefaultFontStyle();
223 float StyleMonitor::GetDefaultFontSize() const
225 return GetImplementation(*this).GetDefaultFontSize();
228 const std::string& StyleMonitor::GetTheme() const
230 return GetImplementation(*this).GetTheme();
233 void StyleMonitor::SetTheme(std::string themeFilePath)
235 GetImplementation(*this).SetTheme(themeFilePath);
238 StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal()
240 return GetImplementation(*this).StyleChangeSignal();
243 void StyleMonitor::EmitStyleChangeSignal(StyleChange::Type styleChange)
245 GetImplementation(*this).EmitStyleChangeSignal(styleChange);
248 bool StyleMonitor::LoadThemeFile( const std::string& filename, std::string& output )
250 return GetImplementation(*this).LoadThemeFile(filename, output);
253 StyleMonitor& StyleMonitor::operator=(const StyleMonitor& monitor)
255 if( *this != monitor )
257 BaseHandle::operator=(monitor);
262 StyleMonitor::StyleMonitor(Internal::Adaptor::StyleMonitor* internal)
263 : BaseHandle(internal)
271 namespace StyleMonitor
274 void SetThemeFileOutput( const std::string& name, const std::string& output )
276 for( NamedThemes::iterator iter = gThemes.begin(); iter != gThemes.end(); ++iter )
278 NamedTheme& theme = *iter;
279 if( theme.name == name )
281 theme.theme = output;
286 gThemes.push_back( NamedTheme( name, output ) );
289 void SetDefaultFontFamily(const std::string& family)
291 gFontFamily = family;
294 void SetDefaultFontStyle(const std::string& style)
299 void SetDefaultFontSize( float size )