2 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
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;
20 using System.Runtime.InteropServices;
22 namespace Tizen.Applications.ThemeManager
27 /// <since_tizen> 8 </since_tizen>
28 [EditorBrowsable(EditorBrowsableState.Never)]
29 public class Theme : IDisposable
31 private bool _disposed = false;
32 private IntPtr _handle;
33 private string _id = String.Empty;
34 private string _version = String.Empty;
35 private string _toolVersion = String.Empty;
36 private string _title = String.Empty;
37 private string _resolution = String.Empty;
38 private string _preview = String.Empty;
39 private string _description = String.Empty;
42 /// A copy constructor of Theme.
44 /// <param name="theme">Theme class.</param>
45 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
46 /// <exception cref="InvalidOperationException">Thrown when failed because of system error.</exception>
47 /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
48 /// <since_tizen> 8 </since_tizen>
49 [EditorBrowsable(EditorBrowsableState.Never)]
50 public Theme(Theme theme)
52 if (theme == null || theme._handle == IntPtr.Zero)
54 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(Interop.ThemeManager.ErrorCode.InvalidParameter, "Invalid parameter");
57 var err = Interop.ThemeManager.ErrorCode.None;
58 err = Interop.ThemeManager.ThemeClone(theme._handle, out _handle);
59 if (err != Interop.ThemeManager.ErrorCode.None)
61 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to clone handle");
65 internal Theme(IntPtr handle)
68 var err = Interop.ThemeManager.ErrorCode.None;
69 err = Interop.ThemeManager.GetId(handle, out _id);
70 if (err != Interop.ThemeManager.ErrorCode.None)
72 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get id");
75 err = Interop.ThemeManager.GetVersion(handle, out _version);
76 if (err != Interop.ThemeManager.ErrorCode.None)
78 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get version");
81 err = Interop.ThemeManager.GetToolVersion(handle, out _toolVersion);
82 if (err != Interop.ThemeManager.ErrorCode.None)
84 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get tool version");
87 err = Interop.ThemeManager.GetTitle(handle, out _title);
88 if (err != Interop.ThemeManager.ErrorCode.None)
90 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get title");
93 err = Interop.ThemeManager.GetResolution(handle, out _resolution);
94 if (err != Interop.ThemeManager.ErrorCode.None)
96 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get resolution");
99 err = Interop.ThemeManager.GetPreview(handle, out _preview);
100 if (err != Interop.ThemeManager.ErrorCode.None)
102 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get preview");
105 err = Interop.ThemeManager.GetDescription(handle, out _description);
106 if (err != Interop.ThemeManager.ErrorCode.None)
108 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get description");
115 /// <since_tizen> 8 </since_tizen>
116 [EditorBrowsable(EditorBrowsableState.Never)]
117 public string Id { get { return _id; } }
122 /// <since_tizen> 8 </since_tizen>
123 [EditorBrowsable(EditorBrowsableState.Never)]
124 public string Version { get { return _version; } }
127 /// A Theme ToolVersion
129 /// <since_tizen> 8 </since_tizen>
130 [EditorBrowsable(EditorBrowsableState.Never)]
131 public string ToolVersion { get { return _toolVersion; } }
136 /// <since_tizen> 8 </since_tizen>
137 [EditorBrowsable(EditorBrowsableState.Never)]
138 public string Title { get { return _title; } }
141 /// A Theme Resolution
143 /// <since_tizen> 8 </since_tizen>
144 [EditorBrowsable(EditorBrowsableState.Never)]
145 public string Resolution { get { return _resolution; } }
150 /// <since_tizen> 8 </since_tizen>
151 [EditorBrowsable(EditorBrowsableState.Never)]
152 public string Preview { get { return _preview; } }
155 /// A Theme Description
157 /// <since_tizen> 8 </since_tizen>
158 [EditorBrowsable(EditorBrowsableState.Never)]
159 public string Description { get { return _description; } }
163 /// Gets the string corresponding with given key.
165 /// <param name="key">The string key to find information.</param>
166 /// <since_tizen> 8 </since_tizen>
167 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
168 /// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
169 /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
170 [EditorBrowsable(EditorBrowsableState.Never)]
171 public string GetString(string key)
174 var err = Interop.ThemeManager.GetString(_handle, key, out str);
175 if (err != Interop.ThemeManager.ErrorCode.None)
177 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get string value of the key");
184 /// Gets the string array corresponding with given key.
186 /// <param name="key">The string key to find information.</param>
187 /// <since_tizen> 8 </since_tizen>
188 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
189 /// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
190 /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
191 [EditorBrowsable(EditorBrowsableState.Never)]
192 public IEnumerable<string> GetStrings(string key)
197 var err = Interop.ThemeManager.GetStringArray(_handle, key, out val, out count);
198 if (err != Interop.ThemeManager.ErrorCode.None)
200 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get string array value of the key");
203 IntPtrToStringArray(val, count, out strings);
208 /// Gets the integer corresponding with given key.
210 /// <param name="key">The string key to find information.</param>
211 /// <since_tizen> 8 </since_tizen>
212 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
213 /// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
214 /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
215 [EditorBrowsable(EditorBrowsableState.Never)]
216 public int GetInt(string key)
219 var err = Interop.ThemeManager.GetInt(_handle, key, out val);
220 if (err != Interop.ThemeManager.ErrorCode.None)
222 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get integer value of the key");
229 /// Gets the float corresponding with given key.
231 /// <param name="key">The string key to find information.</param>
232 /// <since_tizen> 8 </since_tizen>
233 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
234 /// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
235 /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
236 [EditorBrowsable(EditorBrowsableState.Never)]
237 public float GetFloat(string key)
240 var err = Interop.ThemeManager.GetFloat(_handle, key, out val);
241 if (err != Interop.ThemeManager.ErrorCode.None)
243 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get float value of the key");
250 /// Gets the bool corresponding with given key.
252 /// <param name="key">The string key to find information.</param>
253 /// <since_tizen> 8 </since_tizen>
254 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
255 /// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
256 /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
257 [EditorBrowsable(EditorBrowsableState.Never)]
258 public bool GetBool(string key)
261 var err = Interop.ThemeManager.GetBool(_handle, key, out val);
262 if (err != Interop.ThemeManager.ErrorCode.None)
264 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get bool value of the key");
271 /// Gets the path corresponding with given key.
273 /// <param name="key">The string key to find information.</param>
274 /// <since_tizen> 8 </since_tizen>
275 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
276 /// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
277 /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
278 [EditorBrowsable(EditorBrowsableState.Never)]
279 public string GetPath(string key)
282 var err = Interop.ThemeManager.GetPath(_handle, key, out val);
283 if (err != Interop.ThemeManager.ErrorCode.None)
285 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get path value of the key");
292 /// Gets the path array corresponding with given key.
294 /// <param name="key">The string key to find information.</param>
295 /// <since_tizen> 8 </since_tizen>
296 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
297 /// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
298 /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
299 [EditorBrowsable(EditorBrowsableState.Never)]
300 public IEnumerable<string> GetPaths(string key)
305 var err = Interop.ThemeManager.GetPathArray(_handle, key, out val, out count);
306 if (err != Interop.ThemeManager.ErrorCode.None)
308 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get path array value of the key");
311 IntPtrToStringArray(val, count, out paths);
315 static void IntPtrToStringArray(IntPtr unmanagedArray, int size, out string[] managedArray)
317 managedArray = new string[size];
318 IntPtr[] IntPtrArray = new IntPtr[size];
319 Marshal.Copy(unmanagedArray, IntPtrArray, 0, size);
320 for (int iterator = 0; iterator < size; iterator++)
322 managedArray[iterator] = Marshal.PtrToStringAnsi(IntPtrArray[iterator]);
327 /// Check the given key is exist or not.
329 /// <param name="key">The string key to find information.</param>
330 /// <since_tizen> 9 </since_tizen>
331 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
332 [EditorBrowsable(EditorBrowsableState.Never)]
333 public bool HasKey(string key)
336 var err = Interop.ThemeManager.IsKeyExist(_handle, key, out val);
337 if (err != Interop.ThemeManager.ErrorCode.None)
339 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to check existence of the key");
346 /// Releases all resources used by the Theme class.
348 /// <since_tizen> 8 </since_tizen>
349 [EditorBrowsable(EditorBrowsableState.Never)]
350 public void Dispose()
353 GC.SuppressFinalize(this);
357 /// Releases the unmanaged resources used by the Theme class specifying whether to perform a normal dispose operation.
359 /// <param name="disposing">true for a normal dispose operation; false to finalize the handle.</param>
360 protected virtual void Dispose(bool disposing)
365 if (_handle != IntPtr.Zero)
367 Interop.ThemeManager.ThemeDestroy(_handle);
368 _handle = IntPtr.Zero;