2 * Copyright(c) 2019 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 using System.Collections.Generic;
19 using System.ComponentModel;
21 namespace Tizen.NUI.Components
24 /// StyleManager is a class to manager all style.
26 /// <since_tizen> 6 </since_tizen>
27 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
28 [EditorBrowsable(EditorBrowsableState.Never)]
29 public sealed class StyleManager
31 private string theme = "default";
32 private Dictionary<string, Dictionary<string, Type>> themeStyleSet = new Dictionary<string, Dictionary<string, Type>>();
33 private Dictionary<string, Type> defaultStyleSet = new Dictionary<string, Type>();
34 private EventHandler<ThemeChangeEventArgs> themeChangeHander;
37 /// StyleManager construct.
39 /// <since_tizen> 6 </since_tizen>
40 private StyleManager()
44 /// An event for the theme changed signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
46 /// <since_tizen> 6 </since_tizen>
47 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
48 [EditorBrowsable(EditorBrowsableState.Never)]
49 public event EventHandler<ThemeChangeEventArgs> ThemeChangedEvent
53 themeChangeHander += value;
57 themeChangeHander -= value;
62 /// StyleManager static instance.
64 /// <since_tizen> 6 </since_tizen>
65 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
66 [EditorBrowsable(EditorBrowsableState.Never)]
67 public static StyleManager Instance { get; } = new StyleManager();
72 /// <since_tizen> 6 </since_tizen>
73 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
74 [EditorBrowsable(EditorBrowsableState.Never)]
87 themeChangeHander?.Invoke(null, new ThemeChangeEventArgs { CurrentTheme = theme });
93 /// Register style in StyleManager.
95 /// <param name="style">Style name.</param>
96 /// <param name="theme">Theme.</param>
97 /// <param name="styleType">Style type.</param>
98 /// <param name="bDefault">Flag to decide if it is default style.</param>
99 /// <since_tizen> 6 </since_tizen>
100 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
101 [EditorBrowsable(EditorBrowsableState.Never)]
102 public void RegisterStyle(string style, string theme, Type styleType, bool bDefault = false)
106 throw new InvalidOperationException($"style can't be null");
109 if(theme == null || bDefault == true)
111 if(defaultStyleSet.ContainsKey(style))
113 throw new InvalidOperationException($"{style}] already be used");
117 defaultStyleSet.Add(style, styleType);
122 if(themeStyleSet.ContainsKey(style) && themeStyleSet[style].ContainsKey(theme))
124 throw new InvalidOperationException($"{style}] already be used");
126 if(!themeStyleSet.ContainsKey(style))
128 themeStyleSet.Add(style, new Dictionary<string, Type>());
130 themeStyleSet[style].Add(theme, styleType);
134 /// Get attributes by style.
136 /// <param name="style">Style name.</param>
137 /// <since_tizen> 6 </since_tizen>
138 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
139 [EditorBrowsable(EditorBrowsableState.Never)]
140 public Attributes GetAttributes(string style)
148 if(themeStyleSet.ContainsKey(style) && themeStyleSet[style].ContainsKey(Theme))
150 obj = Activator.CreateInstance(themeStyleSet[style][Theme]);
152 else if(defaultStyleSet.ContainsKey(style))
154 obj = Activator.CreateInstance(defaultStyleSet[style]);
157 return (obj as StyleBase)?.GetAttributes();
161 /// ThemeChangeEventArgs is a class to record theme change event arguments which will sent to user.
163 /// <since_tizen> 6 </since_tizen>
164 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
165 [EditorBrowsable(EditorBrowsableState.Never)]
166 public class ThemeChangeEventArgs : EventArgs
168 public string CurrentTheme;