Support to Color.Default
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Layout.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18
19 namespace ElmSharp
20 {
21     public class Layout : Widget
22     {
23         SmartEvent _languageChanged;
24         SmartEvent _themeChanged;
25
26         IntPtr _edjeHandle;
27
28         public Layout(EvasObject parent) : base(parent)
29         {
30             _languageChanged = new SmartEvent(this, "language,changed");
31             _languageChanged.On += (s, e) => {
32                 LanguageChanged?.Invoke(this, EventArgs.Empty);
33             };
34
35             _themeChanged = new SmartEvent(this, "theme,changed");
36             _themeChanged.On += (s, e) =>
37             {
38                 ThemeChanged?.Invoke(this, EventArgs.Empty);
39             };
40         }
41
42         public event EventHandler LanguageChanged;
43
44         public event EventHandler ThemeChanged;
45
46         public EdjeObject EdjeObject
47         {
48             get
49             {
50                 if (_edjeHandle == IntPtr.Zero)
51                     _edjeHandle = Interop.Elementary.elm_layout_edje_get(Handle);
52                 return new EdjeObject(_edjeHandle);
53             }
54         }
55
56         public void SetTheme(string klass, string group, string style)
57         {
58             Interop.Elementary.elm_layout_theme_set(Handle, klass, group, style);
59         }
60
61         public void SetFile(string file, string group)
62         {
63             Interop.Elementary.elm_layout_file_set(Handle, file, group);
64         }
65
66         public override Color BackgroundColor
67         {
68             set
69             {
70                 if(value.IsDefault)
71                 {
72                     string part = ClassName.ToLower().Replace("elm_", "") + "/" + "bg";
73                     EdjeObject.DeleteColorClass(part);
74                 }
75                 else
76                 {
77                     SetPartColor("bg", value);
78                 }
79                 _backgroundColor = value;
80             }
81         }
82
83         protected override IntPtr CreateHandle(EvasObject parent)
84         {
85             return Interop.Elementary.elm_layout_add(parent.Handle);
86         }
87     }
88 }