-
Notifications
You must be signed in to change notification settings - Fork 241
/
Theme.cs
executable file
·373 lines (334 loc) · 15.5 KB
/
Theme.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
/*
* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.InteropServices;
namespace Tizen.Applications.ThemeManager
{
/// <summary>
///
/// </summary>
/// <since_tizen> 8 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public class Theme : IDisposable
{
private bool _disposed = false;
private IntPtr _handle;
private string _id = String.Empty;
private string _version = String.Empty;
private string _toolVersion = String.Empty;
private string _title = String.Empty;
private string _resolution = String.Empty;
private string _preview = String.Empty;
private string _description = String.Empty;
/// <summary>
/// A copy constructor of Theme.
/// </summary>
/// <param name="theme">Theme class.</param>
/// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
/// <exception cref="InvalidOperationException">Thrown when failed because of system error.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
/// <since_tizen> 8 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public Theme(Theme theme)
{
if (theme == null || theme._handle == IntPtr.Zero)
{
throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(Interop.ThemeManager.ErrorCode.InvalidParameter, "Invalid parameter");
}
var err = Interop.ThemeManager.ErrorCode.None;
err = Interop.ThemeManager.ThemeClone(theme._handle, out _handle);
if (err != Interop.ThemeManager.ErrorCode.None)
{
throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to clone handle");
}
}
internal Theme(IntPtr handle)
{
_handle = handle;
var err = Interop.ThemeManager.ErrorCode.None;
err = Interop.ThemeManager.GetId(handle, out _id);
if (err != Interop.ThemeManager.ErrorCode.None)
{
throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get id");
}
err = Interop.ThemeManager.GetVersion(handle, out _version);
if (err != Interop.ThemeManager.ErrorCode.None)
{
throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get version");
}
err = Interop.ThemeManager.GetToolVersion(handle, out _toolVersion);
if (err != Interop.ThemeManager.ErrorCode.None)
{
throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get tool version");
}
err = Interop.ThemeManager.GetTitle(handle, out _title);
if (err != Interop.ThemeManager.ErrorCode.None)
{
throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get title");
}
err = Interop.ThemeManager.GetResolution(handle, out _resolution);
if (err != Interop.ThemeManager.ErrorCode.None)
{
throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get resolution");
}
err = Interop.ThemeManager.GetPreview(handle, out _preview);
if (err != Interop.ThemeManager.ErrorCode.None)
{
throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get preview");
}
err = Interop.ThemeManager.GetDescription(handle, out _description);
if (err != Interop.ThemeManager.ErrorCode.None)
{
throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get description");
}
}
/// <summary>
/// A Theme ID
/// </summary>
/// <since_tizen> 8 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public string Id { get { return _id; } }
/// <summary>
/// A Theme Version
/// </summary>
/// <since_tizen> 8 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public string Version { get { return _version; } }
/// <summary>
/// A Theme ToolVersion
/// </summary>
/// <since_tizen> 8 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public string ToolVersion { get { return _toolVersion; } }
/// <summary>
/// A Theme Title
/// </summary>
/// <since_tizen> 8 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public string Title { get { return _title; } }
/// <summary>
/// A Theme Resolution
/// </summary>
/// <since_tizen> 8 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public string Resolution { get { return _resolution; } }
/// <summary>
/// A Theme Preview
/// </summary>
/// <since_tizen> 8 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public string Preview { get { return _preview; } }
/// <summary>
/// A Theme Description
/// </summary>
/// <since_tizen> 8 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public string Description { get { return _description; } }
/// <summary>
/// Gets the string corresponding with given key.
/// </summary>
/// <param name="key">The string key to find information.</param>
/// <since_tizen> 8 </since_tizen>
/// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
/// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
[EditorBrowsable(EditorBrowsableState.Never)]
public string GetString(string key)
{
string str;
var err = Interop.ThemeManager.GetString(_handle, key, out str);
if (err != Interop.ThemeManager.ErrorCode.None)
{
throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get string value of the key");
}
return str;
}
/// <summary>
/// Gets the string array corresponding with given key.
/// </summary>
/// <param name="key">The string key to find information.</param>
/// <since_tizen> 8 </since_tizen>
/// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
/// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
[EditorBrowsable(EditorBrowsableState.Never)]
public IEnumerable<string> GetStrings(string key)
{
IntPtr val;
int count;
string[] strings;
var err = Interop.ThemeManager.GetStringArray(_handle, key, out val, out count);
if (err != Interop.ThemeManager.ErrorCode.None)
{
throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get string array value of the key");
}
IntPtrToStringArray(val, count, out strings);
return strings;
}
/// <summary>
/// Gets the integer corresponding with given key.
/// </summary>
/// <param name="key">The string key to find information.</param>
/// <since_tizen> 8 </since_tizen>
/// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
/// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
[EditorBrowsable(EditorBrowsableState.Never)]
public int GetInt(string key)
{
int val;
var err = Interop.ThemeManager.GetInt(_handle, key, out val);
if (err != Interop.ThemeManager.ErrorCode.None)
{
throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get integer value of the key");
}
return val;
}
/// <summary>
/// Gets the float corresponding with given key.
/// </summary>
/// <param name="key">The string key to find information.</param>
/// <since_tizen> 8 </since_tizen>
/// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
/// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
[EditorBrowsable(EditorBrowsableState.Never)]
public float GetFloat(string key)
{
float val;
var err = Interop.ThemeManager.GetFloat(_handle, key, out val);
if (err != Interop.ThemeManager.ErrorCode.None)
{
throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get float value of the key");
}
return val;
}
/// <summary>
/// Gets the bool corresponding with given key.
/// </summary>
/// <param name="key">The string key to find information.</param>
/// <since_tizen> 8 </since_tizen>
/// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
/// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool GetBool(string key)
{
bool val;
var err = Interop.ThemeManager.GetBool(_handle, key, out val);
if (err != Interop.ThemeManager.ErrorCode.None)
{
throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get bool value of the key");
}
return val;
}
/// <summary>
/// Gets the path corresponding with given key.
/// </summary>
/// <param name="key">The string key to find information.</param>
/// <since_tizen> 8 </since_tizen>
/// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
/// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
[EditorBrowsable(EditorBrowsableState.Never)]
public string GetPath(string key)
{
string val;
var err = Interop.ThemeManager.GetPath(_handle, key, out val);
if (err != Interop.ThemeManager.ErrorCode.None)
{
throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get path value of the key");
}
return val;
}
/// <summary>
/// Gets the path array corresponding with given key.
/// </summary>
/// <param name="key">The string key to find information.</param>
/// <since_tizen> 8 </since_tizen>
/// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
/// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
[EditorBrowsable(EditorBrowsableState.Never)]
public IEnumerable<string> GetPaths(string key)
{
IntPtr val;
int count;
string[] paths;
var err = Interop.ThemeManager.GetPathArray(_handle, key, out val, out count);
if (err != Interop.ThemeManager.ErrorCode.None)
{
throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get path array value of the key");
}
IntPtrToStringArray(val, count, out paths);
return paths;
}
static void IntPtrToStringArray(IntPtr unmanagedArray, int size, out string[] managedArray)
{
managedArray = new string[size];
IntPtr[] IntPtrArray = new IntPtr[size];
Marshal.Copy(unmanagedArray, IntPtrArray, 0, size);
for (int iterator = 0; iterator < size; iterator++)
{
managedArray[iterator] = Marshal.PtrToStringAnsi(IntPtrArray[iterator]);
}
}
/// <summary>
/// Check the given key is exist or not.
/// </summary>
/// <param name="key">The string key to find information.</param>
/// <since_tizen> 9 </since_tizen>
/// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool HasKey(string key)
{
bool val;
var err = Interop.ThemeManager.IsKeyExist(_handle, key, out val);
if (err != Interop.ThemeManager.ErrorCode.None)
{
throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to check existence of the key");
}
return val;
}
/// <summary>
/// Releases all resources used by the Theme class.
/// </summary>
/// <since_tizen> 8 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Releases the unmanaged resources used by the Theme class specifying whether to perform a normal dispose operation.
/// </summary>
/// <param name="disposing">true for a normal dispose operation; false to finalize the handle.</param>
protected virtual void Dispose(bool disposing)
{
if (_disposed)
return;
if (_handle != IntPtr.Zero)
{
Interop.ThemeManager.ThemeDestroy(_handle);
_handle = IntPtr.Zero;
}
_disposed = true;
}
}
}