2 * Copyright (c) 2018 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-toolkit/public-api/dali-toolkit-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 " \"brokenImageUrl\":\"{DALI_IMAGE_DIR}broken.png\"\n"
39 " \"fontStyle\":{\"weight\":\"normal\"},\n"
47 NamedTheme( const std::string& name, const std::string& theme )
48 : name(name), theme(theme)
55 typedef std::vector< NamedTheme > NamedThemes;
59 std::string gFontFamily("LucidaSans");
60 std::string gFontStyle("Regular");
71 * Stub for the StyleMonitor
73 class StyleMonitor : public BaseObject
75 public: // Creation & Destruction
76 static Dali::StyleMonitor Get();
80 public: // Style Information
81 std::string GetDefaultFontFamily() const;
82 std::string GetDefaultFontStyle() const;
83 float GetDefaultFontSize() const;
84 const std::string& GetTheme() const;
85 void SetTheme(std::string theme);
86 bool LoadThemeFile( const std::string& filename, std::string& output );
89 Dali::StyleMonitor::StyleChangeSignalType& StyleChangeSignal();
91 void EmitStyleChangeSignal(StyleChange::Type styleChange)
93 mStyleChangeSignal.Emit(Dali::StyleMonitor(this), styleChange);
97 Dali::StyleMonitor::StyleChangeSignalType mStyleChangeSignal;
98 static Dali::StyleMonitor mToolkitStyleMonitor;
100 std::string mTheme; ///<< Current theme name
103 Dali::StyleMonitor StyleMonitor::mToolkitStyleMonitor;
105 Dali::StyleMonitor StyleMonitor::Get()
107 if( ! mToolkitStyleMonitor )
109 mToolkitStyleMonitor = Dali::StyleMonitor( new Dali::Internal::Adaptor::StyleMonitor() );
111 return mToolkitStyleMonitor;
114 StyleMonitor::StyleMonitor()
119 StyleMonitor::~StyleMonitor()
123 std::string StyleMonitor::GetDefaultFontFamily() const
128 std::string StyleMonitor::GetDefaultFontStyle() const
133 float StyleMonitor::GetDefaultFontSize() const
138 const std::string& StyleMonitor::GetTheme() const
143 void StyleMonitor::SetTheme(std::string path)
146 EmitStyleChangeSignal( StyleChange::THEME_CHANGE );
149 bool StyleMonitor::LoadThemeFile( const std::string& filename, std::string& output )
151 for( NamedThemes::iterator iter = gThemes.begin(); iter != gThemes.end(); ++iter )
153 NamedTheme& theme = *iter;
154 if( theme.name == filename )
156 output = theme.theme;
161 if( !gTheme.empty() )
167 output = DEFAULT_THEME;
172 Dali::StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal()
174 return mStyleChangeSignal;
177 } // namespace Adaptor
178 } // namespace Internal
180 ////////////////////////////////////////////////////////////////////////////////////////////////////
182 Internal::Adaptor::StyleMonitor& GetImplementation(Dali::StyleMonitor& monitor)
184 BaseObject& object = monitor.GetBaseObject();
185 return static_cast<Internal::Adaptor::StyleMonitor&>(object);
187 const Internal::Adaptor::StyleMonitor& GetImplementation(const Dali::StyleMonitor& monitor)
189 const BaseObject& object = monitor.GetBaseObject();
190 return static_cast<const Internal::Adaptor::StyleMonitor&>(object);
193 StyleMonitor::StyleMonitor()
197 StyleMonitor::StyleMonitor(const StyleMonitor& monitor)
198 : BaseHandle(monitor)
202 StyleMonitor StyleMonitor::StyleMonitor::Get()
204 return Internal::Adaptor::StyleMonitor::Get();
207 StyleMonitor::~StyleMonitor()
211 std::string StyleMonitor::GetDefaultFontFamily() const
213 return GetImplementation(*this).GetDefaultFontFamily();
216 std::string StyleMonitor::GetDefaultFontStyle() const
218 return GetImplementation(*this).GetDefaultFontStyle();
221 int StyleMonitor::GetDefaultFontSize() const
223 return GetImplementation(*this).GetDefaultFontSize();
226 const std::string& StyleMonitor::GetTheme() const
228 return GetImplementation(*this).GetTheme();
231 void StyleMonitor::SetTheme(const std::string& themeFilePath)
233 GetImplementation(*this).SetTheme(themeFilePath);
236 StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal()
238 return GetImplementation(*this).StyleChangeSignal();
241 bool StyleMonitor::LoadThemeFile( const std::string& filename, std::string& output )
243 return GetImplementation(*this).LoadThemeFile(filename, output);
246 StyleMonitor& StyleMonitor::operator=(const StyleMonitor& monitor)
248 if( *this != monitor )
250 BaseHandle::operator=(monitor);
255 StyleMonitor::StyleMonitor(Internal::Adaptor::StyleMonitor* internal)
256 : BaseHandle(internal)
264 namespace StyleMonitor
267 void SetThemeFileOutput( const std::string& name, const std::string& output )
269 for( NamedThemes::iterator iter = gThemes.begin(); iter != gThemes.end(); ++iter )
271 NamedTheme& theme = *iter;
272 if( theme.name == name )
274 theme.theme = output;
279 gThemes.push_back( NamedTheme( name, output ) );
282 void SetDefaultFontFamily(const std::string& family)
284 gFontFamily = family;
287 void SetDefaultFontStyle(const std::string& style)
292 void SetDefaultFontSize( float size )