2 * Copyright (c) 2016 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;
22 public enum FocusDirection
32 public abstract class Widget : EvasObject
34 Dictionary<string, EvasObject> _partContents = new Dictionary<string, EvasObject>();
37 SmartEvent _unfocused;
39 internal Color _backgroundColor = Color.Default;
40 internal int _opacity = Color.Default.A;
46 protected Widget(EvasObject parent) : base(parent)
48 _focused = new SmartEvent(this, "focused");
49 _focused.On += (s, e) => Focused?.Invoke(this, EventArgs.Empty);
51 _unfocused = new SmartEvent(this, "unfocused");
52 _unfocused.On += (s, e) => Unfocused?.Invoke(this, EventArgs.Empty);
55 public event EventHandler Focused;
57 public event EventHandler Unfocused;
63 return !Interop.Elementary.elm_object_disabled_get(RealHandle);
67 Interop.Elementary.elm_object_disabled_set(RealHandle, !value);
75 return Interop.Elementary.elm_object_style_get(RealHandle);
79 Interop.Elementary.elm_object_style_set(RealHandle, value);
87 return Interop.Elementary.elm_object_focus_get(RealHandle);
91 public bool IsFocusAllowed
95 return Interop.Elementary.elm_object_focus_allow_get(RealHandle);
99 public virtual string Text
103 return Interop.Elementary.elm_object_part_text_get(RealHandle);
107 Interop.Elementary.elm_object_part_text_set(RealHandle, IntPtr.Zero, value);
111 public virtual Color BackgroundColor
115 if (!_backgroundColor.IsDefault)
117 _backgroundColor = GetPartColor("bg");
119 return _backgroundColor;
125 Console.WriteLine("Widget instance doesn't support to set BackgroundColor to Color.Default.");
129 SetPartColor("bg", value);
130 _backgroundColor = value;
135 public virtual int Opacity
139 if (_opacity != Color.Default.A)
141 _opacity = GetPartOpacity("opacity");
147 SetPartOpacity("opacity", value);
152 public void SetFocus(bool isFocus)
154 Interop.Elementary.elm_object_focus_set(RealHandle, isFocus);
157 public void AllowFocus(bool isAllowFocus)
159 Interop.Elementary.elm_object_focus_allow_set(RealHandle, isAllowFocus);
162 public void FocusNext(FocusDirection direction)
164 Interop.Elementary.elm_object_focus_next(RealHandle, (int)direction);
167 public void SetNextFocusObject(EvasObject next, FocusDirection direction)
169 Interop.Elementary.elm_object_focus_next_object_set(RealHandle, next.RealHandle, (int)direction);
172 public void SetPartContent(string part, EvasObject content)
174 SetPartContent(part, content, false);
177 public void SetPartContent(string part, EvasObject content, bool preserveOldContent)
179 if (preserveOldContent)
181 Interop.Elementary.elm_object_part_content_unset(RealHandle, part);
183 Interop.Elementary.elm_object_part_content_set(RealHandle, part, content);
185 _partContents[part ?? "__default__"] = content;
188 public void SetContent(EvasObject content)
190 SetContent(content, false);
193 public void SetContent(EvasObject content, bool preserveOldContent)
195 if (preserveOldContent)
197 Interop.Elementary.elm_object_content_unset(RealHandle);
200 Interop.Elementary.elm_object_content_set(RealHandle, content);
201 _partContents["__default__"] = content;
204 public void SetPartText(string part, string text)
206 Interop.Elementary.elm_object_part_text_set(RealHandle, part, text);
209 public string GetPartText(string part)
211 return Interop.Elementary.elm_object_part_text_get(RealHandle, part);
214 public virtual void SetPartColor(string part, Color color)
216 Interop.Elementary.elm_object_color_class_color_set(RealHandle, part, color.R * color.A / 255,
217 color.G * color.A / 255,
218 color.B * color.A / 255,
222 public virtual Color GetPartColor(string part)
225 Interop.Elementary.elm_object_color_class_color_get(RealHandle, part, out r, out g, out b, out a);
226 return new Color((int)(r / (a / 255.0)), (int)(g / (a / 255.0)), (int)(b / (a / 255.0)), a);
229 public void SetPartOpacity(string part, int opacity)
231 Interop.Elementary.elm_object_color_class_color_set(Handle, part, 255, 255, 255, opacity);
234 public int GetPartOpacity(string part)
237 Interop.Elementary.elm_object_color_class_color_get(Handle, part, out r, out g, out b, out a);
241 internal IntPtr GetPartContent(string part)
243 return Interop.Elementary.elm_object_part_content_get(RealHandle, part);