Merge changes I0645dc99,I9115d8e9 into tizen
[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, this.RealHandle, "language,changed");
31             _languageChanged.On += (s, e) =>
32             {
33                 LanguageChanged?.Invoke(this, EventArgs.Empty);
34             };
35
36             _themeChanged = new SmartEvent(this, this.RealHandle, "theme,changed");
37             _themeChanged.On += (s, e) =>
38             {
39                 ThemeChanged?.Invoke(this, EventArgs.Empty);
40             };
41         }
42
43         public event EventHandler LanguageChanged;
44
45         public event EventHandler ThemeChanged;
46
47         public EdjeObject EdjeObject
48         {
49             get
50             {
51                 if (_edjeHandle == IntPtr.Zero)
52                     _edjeHandle = Interop.Elementary.elm_layout_edje_get(RealHandle);
53                 return new EdjeObject(_edjeHandle);
54             }
55         }
56
57         public void SetTheme(string klass, string group, string style)
58         {
59             Interop.Elementary.elm_layout_theme_set(RealHandle, klass, group, style);
60         }
61
62         public void SetFile(string file, string group)
63         {
64             Interop.Elementary.elm_layout_file_set(RealHandle, file, group);
65         }
66
67         public override Color BackgroundColor
68         {
69             set
70             {
71                 if (value.IsDefault)
72                 {
73                     string part = ClassName.ToLower().Replace("elm_", "") + "/" + "bg";
74                     EdjeObject.DeleteColorClass(part);
75                 }
76                 else
77                 {
78                     SetPartColor("bg", value);
79                 }
80                 _backgroundColor = value;
81             }
82         }
83
84         protected override IntPtr CreateHandle(EvasObject parent)
85         {
86             return Interop.Elementary.elm_layout_add(parent.Handle);
87         }
88     }
89 }