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.
22 /// This is a container widget that takes a standard Edje design file and wraps it very thinly in a widget.
25 public class Layout : Container
27 SmartEvent _languageChanged;
28 SmartEvent _themeChanged;
33 /// Creates and initializes a new instance of Layout class.
35 /// <param name="parent">The parent is a given container which will be attached by Layout as a child. It's <see cref="EvasObject"/> type.</param>
36 public Layout(EvasObject parent) : base(parent)
38 _languageChanged = new SmartEvent(this, this.RealHandle, "language,changed");
39 _languageChanged.On += (s, e) =>
41 LanguageChanged?.Invoke(this, EventArgs.Empty);
44 _themeChanged = new SmartEvent(this, this.RealHandle, "theme,changed");
45 _themeChanged.On += (s, e) =>
47 ThemeChanged?.Invoke(this, EventArgs.Empty);
52 /// LanguageChanged will be triggered when the program's language is changed.
54 public event EventHandler LanguageChanged;
57 /// ThemeChanged will be triggered when the theme is changed.
59 public event EventHandler ThemeChanged;
62 /// Gets the edje layout.
64 public EdjeObject EdjeObject
68 if (_edjeHandle == IntPtr.Zero)
69 _edjeHandle = Interop.Elementary.elm_layout_edje_get(RealHandle);
70 return new EdjeObject(_edjeHandle);
75 /// Gets or sets accessibility state of texblock(text) parts in the layout object.
77 public bool TextBlockAccessibility
81 return Interop.Elementary.elm_layout_edje_object_can_access_get(RealHandle);
85 Interop.Elementary.elm_layout_edje_object_can_access_set(RealHandle, value);
90 /// Freezes the Elementary layout object.
91 /// This function puts all changes on hold.
92 /// Successive freezes will nest, requiring an equal number of thaws.
94 /// <returns>The frozen state or 0 if the object is not frozen or on error.</returns>
97 return Interop.Elementary.elm_layout_freeze(RealHandle);
101 /// Thaws the Elementary object.
102 /// If sucessives freezes were done, an equal number of thaws will be required.
104 /// <returns>The frozen state or 0 if the object is not frozen or on error.</returns>
107 return Interop.Elementary.elm_layout_thaw(RealHandle);
112 /// Manually forces a sizing re-evaluation.
113 /// This is useful when the minimum size required by the edje theme of this layout has changed.
114 /// The change on the minimum size required by the edje theme is not immediately reported to the elementary layout, so one needs to call this function in order to tell the widget (layout) that it needs to reevaluate its own size.
115 /// The minimum size of the theme is calculated based on minimum size of parts, the size of elements inside containers like box and table, etc.
116 /// All of this can change due to state changes, and that's when this function should be called.
118 public void Resizing()
120 Interop.Elementary.elm_layout_sizing_eval(RealHandle);
124 /// Request sizing reevaluation, restricted to current width and/or height.
125 /// Useful mostly when there are TEXTBLOCK parts defining the height of the object and nothing else restricting it to a minimum width.Calling this function will restrict the minimum size in the Edje calculation to whatever size it the layout has at the moment.
127 /// <param name="width">Restrict minimum size ot the current width.</param>
128 /// <param name="height">Restrict minimum size ot the current height.</param>
129 public void Resizing(bool width, bool height)
131 Interop.Elementary.elm_layout_sizing_restricted_eval(RealHandle, width, height);
135 /// Get the edje data from the given layout.
136 /// This function fetches data specified inside the edje theme of this layout.
137 /// This function return NULL if data is not found.
139 /// <param name="key">The data key</param>
140 /// <returns>The data</returns>
141 public string GetEdjeData(string key)
143 return Interop.Elementary.elm_layout_data_get(RealHandle, key);
147 /// Gets the text set in the given part.
149 /// <param name="part">The TEXT part to retrieve the text off.</param>
150 /// <returns></returns>
151 public override string GetPartText(string part)
153 return Interop.Elementary.elm_layout_text_get(RealHandle, part);
157 /// Sets the text set in the given part.
159 /// <param name="part">The TEXT part to retrieve the text off.</param>
160 /// <param name="text">The text to set.</param>
161 /// <returns></returns>
162 public override bool SetPartText(string part, string text)
164 return Interop.Elementary.elm_layout_text_set(RealHandle, part, text);
168 /// Append child to layout box part.
169 /// Once the object is appended, it will become child of the layout.
170 /// Its lifetime will be bound to the layout, whenever the layout dies the child will be deleted automatically.
172 /// <param name="part">The part</param>
173 /// <param name="child">The Object to append</param>
174 /// <returns>Sucess is true</returns>
175 public bool BoxAppend(string part, EvasObject child)
178 return Interop.Elementary.elm_layout_box_append(RealHandle, part, child.Handle);
182 /// Prepend child to layout box part.
183 /// Once the object is prepended, it will become child of the layout.
184 /// Its lifetime will be bound to the layout, whenever the layout dies the child will be deleted automatically.
186 /// <param name="part">The part</param>
187 /// <param name="child">The Object to prepend</param>
188 /// <returns>Sucess is true</returns>
189 public bool BoxPrepend(string part, EvasObject child)
192 return Interop.Elementary.elm_layout_box_prepend(RealHandle, part, child.Handle);
196 /// Remove a child of the given part box.
197 /// The object will be removed from the box part and its lifetime will not be handled by the layout anymore.
199 /// <param name="part">The part</param>
200 /// <param name="child">The Object to remove</param>
201 /// <returns>Sucess is true</returns>
202 public bool BoxRemove(string part, EvasObject child)
205 return Interop.Elementary.elm_layout_box_remove(RealHandle, part, child.Handle) != null;
209 /// Remove all children of the given part box.
210 /// The objects will be removed from the box part and their lifetime will not be handled by the layout anymore.
212 /// <param name="part">The part</param>
213 /// <param name="clear">If true, then all objects will be deleted as well, otherwise they will just be removed and will be dangling on the canvas.</param>
214 /// <returns>Sucess is true</returns>
215 public bool BoxRemoveAll(string part, bool clear)
218 return Interop.Elementary.elm_layout_box_remove_all(RealHandle, part, clear);
222 /// Insert child to layout box part at a given position.
223 /// Once the object is inserted, it will become child of the layout.
224 /// Its lifetime will be bound to the layout, whenever the layout dies the child will be deleted automatically.
226 /// <param name="part">The part</param>
227 /// <param name="child">The child object to insert into box.</param>
228 /// <param name="position">The numeric position >=0 to insert the child.</param>
229 /// <returns>Sucess is true</returns>
230 public bool BoxInsertAt(string part, EvasObject child, uint position)
233 return Interop.Elementary.elm_layout_box_insert_at(RealHandle, part, child.Handle, position);
237 /// Insert child to layout box part before a reference object.
238 /// Once the object is inserted, it will become child of the layout.
239 /// Its lifetime will be bound to the layout, whenever the layout dies the child will be deleted automatically.
241 /// <param name="part"></param>
242 /// <param name="child">The child object to insert into box.</param>
243 /// <param name="reference">Another reference object to insert before in box.</param>
244 /// <returns>Sucess is true</returns>
245 public bool BoxInsertBefore(string part, EvasObject child, EvasObject reference)
248 return Interop.Elementary.elm_layout_box_insert_before(RealHandle, part, child.Handle, reference.Handle);
252 /// Sets the layout content.
254 /// <param name="part">The swallow part name in the edje file</param>
255 /// <param name="content">The child that will be added in this layout object.</param>
256 /// <returns>TRUE on success, FALSE otherwise</returns>
257 public override bool SetPartContent(string part, EvasObject content)
259 return SetPartContent(part, content, false);
263 /// Sets the layout content.
265 /// <param name="part">The name of particular part</param>
266 /// <param name="content">The content</param>
267 /// <param name="preserveOldContent">true, preserve old content will be unset. false, preserve old content will not be unset.</param>
268 /// <returns>TRUE on success, FALSE otherwise</returns>
269 public override bool SetPartContent(string part, EvasObject content, bool preserveOldContent)
271 if (preserveOldContent)
273 Interop.Elementary.elm_layout_content_unset(RealHandle, part);
275 UpdatePartContents(content, part);
276 return Interop.Elementary.elm_layout_content_set(RealHandle, part, content);
280 /// Sets the edje group from the elementary theme that is used as a layout.
282 /// <param name="klass">The class of the group</param>
283 /// <param name="group">The group</param>
284 /// <param name="style">The style to use</param>
285 public void SetTheme(string klass, string group, string style)
287 Interop.Elementary.elm_layout_theme_set(RealHandle, klass, group, style);
291 /// Sets the file that is used as a layout.
293 /// <param name="file">The path to the file (edj) that is used as a layout</param>
294 /// <param name="group">The group that the layout belongs to in the edje file</param>
295 public void SetFile(string file, string group)
297 Interop.Elementary.elm_layout_file_set(RealHandle, file, group);
301 /// Sets the back ground color of layout
303 public override Color BackgroundColor
307 if (value.IsDefault && ClassName != null)
309 string part = ClassName.ToLower().Replace("elm_", "") + "/" + "bg";
310 EdjeObject.DeleteColorClass(part);
314 SetPartColor("bg", value);
316 _backgroundColor = value;
321 /// Sets the vertical text alignment of layout's text part
324 /// API, elm_layout_text_valign_set, is an internal API only in Tizen. Avalilable since Tizen_4.0.
326 public virtual void SetVerticalTextAlignment(string part, double valign)
328 Interop.Elementary.elm_layout_text_valign_set(RealHandle, part, valign);
332 /// Gets the vertical text alignment of layout's text part
335 /// API, elm_layout_text_valign_get, is internal API only in Tizen. Avalilable since Tizen_4.0.
337 public virtual double GetVerticalTextAlignment(string part)
339 return Interop.Elementary.elm_layout_text_valign_get(RealHandle, part);
343 /// Sets the content at a part of a given container widget.
345 /// <param name="parent">The parent is a given container which will be attached by Layout as a child. It's <see cref="EvasObject"/> type.</param>
346 /// <returns>The new object, otherwise null if it cannot be created</returns>
347 protected override IntPtr CreateHandle(EvasObject parent)
349 return Interop.Elementary.elm_layout_add(parent.Handle);