Support alpha to Background
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Widget.cs
1 using System;
2 using System.Collections.Generic;
3
4 namespace ElmSharp
5 {
6     public abstract class Widget : EvasObject
7     {
8         Dictionary<string, EvasObject> _partContents = new Dictionary<string, EvasObject>();
9
10         Interop.SmartEvent _focused;
11         Interop.SmartEvent _unfocused;
12
13         protected Widget()
14         {
15         }
16
17         internal Widget(EvasObject parent) : base(parent)
18         {
19             _focused = new Interop.SmartEvent(this, Handle, "focused");
20             _focused.On += (s, e) => Focused?.Invoke(this, EventArgs.Empty);
21
22             _unfocused = new Interop.SmartEvent(this, Handle, "unfocused");
23             _unfocused.On += (s, e) => Unfocused?.Invoke(this, EventArgs.Empty);
24
25         }
26
27         public event EventHandler Focused;
28
29         public event EventHandler Unfocused;
30
31         public bool IsEnabled
32         {
33             get
34             {
35                 return !Interop.Elementary.elm_object_disabled_get(Handle);
36             }
37             set
38             {
39                 Interop.Elementary.elm_object_disabled_set(Handle, !value);
40             }
41         }
42
43         public string Style
44         {
45             get
46             {
47                 return Interop.Elementary.elm_object_style_get(Handle);
48             }
49             set
50             {
51                 Interop.Elementary.elm_object_style_set(Handle, value);
52             }
53         }
54
55         public bool IsFocused
56         {
57             get
58             {
59                 return Interop.Elementary.elm_object_focus_get(Handle);
60             }
61         }
62
63         public string Text
64         {
65             get
66             {
67                 return Interop.Elementary.elm_object_part_text_get(Handle);
68             }
69             set
70             {
71                 Interop.Elementary.elm_object_part_text_set(Handle, IntPtr.Zero, value);
72             }
73         }
74
75         public void SetFocus(bool isFocus)
76         {
77             Interop.Elementary.elm_object_focus_set(Handle, isFocus);
78         }
79
80         public void SetPartContent(string part, EvasObject content)
81         {
82             SetPartContent(part, content, false);
83         }
84
85         public void SetPartContent(string part, EvasObject content, bool preserveOldContent)
86         {
87             if (preserveOldContent)
88             {
89                 Interop.Elementary.elm_object_part_content_unset(Handle, part);
90             }
91             Interop.Elementary.elm_object_part_content_set(Handle, part, content);
92
93             _partContents[part ?? "__default__"] = content;
94         }
95
96         public void SetContent(EvasObject content)
97         {
98             SetContent(content, false);
99         }
100
101         public void SetContent(EvasObject content, bool preserveOldContent)
102         {
103             if (preserveOldContent)
104             {
105                 Interop.Elementary.elm_object_content_unset(Handle);
106             }
107
108             Interop.Elementary.elm_object_content_set(Handle, content);
109             _partContents["___default__"] = content;
110         }
111
112         public void SetPartText(string part, string text)
113         {
114             Interop.Elementary.elm_object_part_text_set(Handle, part, text);
115         }
116
117         public string GetPartText(string part)
118         {
119             return Interop.Elementary.elm_object_part_text_get(Handle, part);
120         }
121
122         public void SetPartColor(string part, Color color)
123         {
124             Interop.Elementary.elm_object_part_color_set(Handle, part, color.R, color.G, color.B, color.A);
125         }
126
127         internal IntPtr GetPartContent(string part)
128         {
129             return Interop.Elementary.elm_object_part_content_get(Handle, part);
130         }
131     }
132 }