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 char* DEFAULT_THEME=
33 " \"fontStyle\":{\"weight\":\"normal\"},\n"
41 NamedTheme( const std::string& name, const std::string& theme )
42 : name(name), theme(theme)
49 typedef std::vector< NamedTheme > NamedThemes;
53 std::string gFontFamily("LucidaSans");
54 std::string gFontStyle("Regular");
65 * Stub for the StyleMonitor
67 class StyleMonitor : public BaseObject
69 public: // Creation & Destruction
70 static Dali::StyleMonitor Get();
74 public: // Style Information
75 std::string GetDefaultFontFamily() const;
76 std::string GetDefaultFontStyle() const;
77 float GetDefaultFontSize() const;
78 const std::string& GetTheme() const;
79 void SetTheme(std::string theme);
80 bool LoadThemeFile( const std::string& filename, std::string& output );
83 Dali::StyleMonitor::StyleChangeSignalType& StyleChangeSignal();
85 void EmitStyleChangeSignal(StyleChange::Type styleChange)
87 mStyleChangeSignal.Emit(Dali::StyleMonitor(this), styleChange);
91 Dali::StyleMonitor::StyleChangeSignalType mStyleChangeSignal;
92 static Dali::StyleMonitor mToolkitStyleMonitor;
94 std::string mTheme; ///<< Current theme name
97 Dali::StyleMonitor StyleMonitor::mToolkitStyleMonitor;
99 Dali::StyleMonitor StyleMonitor::Get()
101 if( ! mToolkitStyleMonitor )
103 mToolkitStyleMonitor = Dali::StyleMonitor( new Dali::Internal::Adaptor::StyleMonitor() );
105 return mToolkitStyleMonitor;
108 StyleMonitor::StyleMonitor()
113 StyleMonitor::~StyleMonitor()
117 std::string StyleMonitor::GetDefaultFontFamily() const
122 std::string StyleMonitor::GetDefaultFontStyle() const
127 float StyleMonitor::GetDefaultFontSize() const
132 const std::string& StyleMonitor::GetTheme() const
137 void StyleMonitor::SetTheme(std::string path)
140 EmitStyleChangeSignal( StyleChange::THEME_CHANGE );
143 bool StyleMonitor::LoadThemeFile( const std::string& filename, std::string& output )
145 for( NamedThemes::iterator iter = gThemes.begin(); iter != gThemes.end(); ++iter )
147 NamedTheme& theme = *iter;
148 if( theme.name == filename )
150 output = theme.theme;
155 if( !gTheme.empty() )
161 output = DEFAULT_THEME;
166 Dali::StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal()
168 return mStyleChangeSignal;
171 } // namespace Adaptor
172 } // namespace Internal
174 ////////////////////////////////////////////////////////////////////////////////////////////////////
176 Internal::Adaptor::StyleMonitor& GetImplementation(Dali::StyleMonitor& monitor)
178 BaseObject& object = monitor.GetBaseObject();
179 return static_cast<Internal::Adaptor::StyleMonitor&>(object);
181 const Internal::Adaptor::StyleMonitor& GetImplementation(const Dali::StyleMonitor& monitor)
183 const BaseObject& object = monitor.GetBaseObject();
184 return static_cast<const Internal::Adaptor::StyleMonitor&>(object);
187 StyleMonitor::StyleMonitor()
191 StyleMonitor::StyleMonitor(const StyleMonitor& monitor)
192 : BaseHandle(monitor)
196 StyleMonitor StyleMonitor::StyleMonitor::Get()
198 return Internal::Adaptor::StyleMonitor::Get();
201 StyleMonitor::~StyleMonitor()
205 std::string StyleMonitor::GetDefaultFontFamily() const
207 return GetImplementation(*this).GetDefaultFontFamily();
210 std::string StyleMonitor::GetDefaultFontStyle() const
212 return GetImplementation(*this).GetDefaultFontStyle();
215 int StyleMonitor::GetDefaultFontSize() const
217 return GetImplementation(*this).GetDefaultFontSize();
220 const std::string& StyleMonitor::GetTheme() const
222 return GetImplementation(*this).GetTheme();
225 void StyleMonitor::SetTheme(const std::string& themeFilePath)
227 GetImplementation(*this).SetTheme(themeFilePath);
230 StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal()
232 return GetImplementation(*this).StyleChangeSignal();
235 bool StyleMonitor::LoadThemeFile( const std::string& filename, std::string& output )
237 return GetImplementation(*this).LoadThemeFile(filename, output);
240 StyleMonitor& StyleMonitor::operator=(const StyleMonitor& monitor)
242 if( *this != monitor )
244 BaseHandle::operator=(monitor);
249 StyleMonitor::StyleMonitor(Internal::Adaptor::StyleMonitor* internal)
250 : BaseHandle(internal)
258 namespace StyleMonitor
261 void SetThemeFileOutput( const std::string& name, const std::string& output )
263 for( NamedThemes::iterator iter = gThemes.begin(); iter != gThemes.end(); ++iter )
265 NamedTheme& theme = *iter;
266 if( theme.name == name )
268 theme.theme = output;
273 gThemes.push_back( NamedTheme( name, output ) );
276 void SetDefaultFontFamily(const std::string& family)
278 gFontFamily = family;
281 void SetDefaultFontStyle(const std::string& style)
286 void SetDefaultFontSize( float size )