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 /// <since_tizen> preview </since_tizen>
26 public class Layout : Container
28 SmartEvent _languageChanged;
29 SmartEvent _themeChanged;
34 /// Creates and initializes a new instance of the Layout class.
36 /// <param name="parent">The parent is a given container, which will be attached by the layout as a child. It's <see cref="EvasObject"/> type.</param>
37 /// <since_tizen> preview </since_tizen>
38 public Layout(EvasObject parent) : base(parent)
43 /// Creates and initializes a new instance of the Layout class.
45 /// <since_tizen> preview </since_tizen>
46 protected Layout() : base()
51 /// LanguageChanged will be triggered when the program's language is changed.
53 /// <since_tizen> preview </since_tizen>
54 public event EventHandler LanguageChanged;
57 /// ThemeChanged will be triggered when the theme is changed.
59 /// <since_tizen> preview </since_tizen>
60 public event EventHandler ThemeChanged;
63 /// Gets the edje layout.
65 /// <since_tizen> preview </since_tizen>
66 public EdjeObject EdjeObject
70 if (_edjeHandle == IntPtr.Zero)
71 _edjeHandle = Interop.Elementary.elm_layout_edje_get(RealHandle);
72 return new EdjeObject(_edjeHandle);
77 /// Gets or sets the accessibility state of texblock (text) parts in a layout object.
79 /// <since_tizen> preview </since_tizen>
80 public bool TextBlockAccessibility
84 return Interop.Elementary.elm_layout_edje_object_can_access_get(RealHandle);
88 Interop.Elementary.elm_layout_edje_object_can_access_set(RealHandle, value);
93 /// Freezes the Elementary layout object.
94 /// This function puts all the changes on hold.
95 /// Successive freezes will nest, requiring an equal number of thaws.
97 /// <returns>The frozen state, or 0 if the object is not frozen or on error.</returns>
98 /// <since_tizen> preview </since_tizen>
101 return Interop.Elementary.elm_layout_freeze(RealHandle);
105 /// Thaws the Elementary object.
106 /// If sucessives freezes were done, an equal number of thaws will be required.
108 /// <returns>The frozen state, or 0 if the object is not frozen or on error.</returns>
109 /// <since_tizen> preview </since_tizen>
112 return Interop.Elementary.elm_layout_thaw(RealHandle);
117 /// Manually forces a sizing re-evaluation.
118 /// This is useful when the minimum size required by the edje theme of this layout has changed.
119 /// 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.
120 /// The minimum size of the theme is calculated based on the minimum size of parts, the size of elements inside containers like the box and table, etc.
121 /// All of this can change due to state changes, and that's when this function should be called.
123 /// <since_tizen> preview </since_tizen>
124 public void Resizing()
126 Interop.Elementary.elm_layout_sizing_eval(RealHandle);
130 /// Requests sizing re-evaluation, restricted to the current width and/or height.
131 /// Useful mostly when there are TEXTBLOCK parts defining the height of an object and nothing else, restricting it to a minimum width. Calling this function will restrict minimum size in the Edje calculation to whatever size the layout has at the moment.
133 /// <param name="width">Restrict minimum size of the current width.</param>
134 /// <param name="height">Restrict minimum size of the current height.</param>
135 /// <since_tizen> preview </since_tizen>
136 public void Resizing(bool width, bool height)
138 Interop.Elementary.elm_layout_sizing_restricted_eval(RealHandle, width, height);
142 /// Gets the edje data from the given layout.
143 /// This function fetches the data specified inside the edje theme of this layout.
144 /// This function returns null if the data is not found.
146 /// <param name="key">The data key.</param>
147 /// <returns>The data.</returns>
148 /// <since_tizen> preview </since_tizen>
149 public string GetEdjeData(string key)
151 return Interop.Elementary.elm_layout_data_get(RealHandle, key);
155 /// Gets the text set in the given part.
157 /// <param name="part">The text part to retrieve the text off.</param>
158 /// <returns></returns>
159 /// <since_tizen> preview </since_tizen>
160 public override string GetPartText(string part)
162 return Interop.Elementary.elm_layout_text_get(RealHandle, part);
166 /// Sets the text set in the given part.
168 /// <param name="part">The text part to retrieve the text off.</param>
169 /// <param name="text">The text to set.</param>
170 /// <returns></returns>
171 /// <since_tizen> preview </since_tizen>
172 public override bool SetPartText(string part, string text)
174 return Interop.Elementary.elm_layout_text_set(RealHandle, part, text);
178 /// Appends a child to the layout box part.
179 /// Once the object is appended, it will become a child of the layout.
180 /// Its lifetime will be bound to the layout. Whenever the layout dies, the child will be deleted automatically.
183 /// This will only work if the layout edc have box part.
185 /// <param name="part">The part.</param>
186 /// <param name="child">The object to append.</param>
187 /// <returns>Success is true.</returns>
188 /// <since_tizen> preview </since_tizen>
189 public bool BoxAppend(string part, EvasObject child)
192 return Interop.Elementary.elm_layout_box_append(RealHandle, part, child.Handle);
196 /// Prepends a child to the layout box part.
197 /// Once the object is prepended, it will become a child of the layout.
198 /// Its lifetime will be bound to the layout. Whenever the layout dies, the child will be deleted automatically.
201 /// This will only work if the layout edc have box part.
203 /// <param name="part">The part.</param>
204 /// <param name="child">The object to prepend.</param>
205 /// <returns>Success is true.</returns>
206 /// <since_tizen> preview </since_tizen>
207 public bool BoxPrepend(string part, EvasObject child)
210 return Interop.Elementary.elm_layout_box_prepend(RealHandle, part, child.Handle);
214 /// Removes a child from the given part box.
215 /// The object will be removed from the box part and its lifetime will not be handled by the layout anymore.
218 /// This will only work if the layout edc have box part.
220 /// <param name="part">The part.</param>
221 /// <param name="child">The object to remove.</param>
222 /// <returns>Success if true</returns>
223 /// <since_tizen> preview </since_tizen>
224 public bool BoxRemove(string part, EvasObject child)
227 return Interop.Elementary.elm_layout_box_remove(RealHandle, part, child.Handle) != IntPtr.Zero;
231 /// Removes all the children from the given part box.
232 /// The objects will be removed from the box part and their lifetime will not be handled by the layout anymore.
235 /// This will only work if the layout edc have box part.
237 /// <param name="part">The part.</param>
238 /// <param name="clear">If true, then all the objects will be deleted as well, otherwise they will just be removed and will be dangling on the canvas.</param>
239 /// <returns>Success if true.</returns>
240 /// <since_tizen> preview </since_tizen>
241 public bool BoxRemoveAll(string part, bool clear)
244 return Interop.Elementary.elm_layout_box_remove_all(RealHandle, part, clear);
248 /// Inserts a child to the layout box part at a given position.
249 /// Once the object is inserted, it will become a child of the layout.
250 /// Its lifetime will be bound to the layout. Whenever the layout dies, the child will be deleted automatically.
253 /// This will only work if the layout edc have box part.
255 /// <param name="part">The part.</param>
256 /// <param name="child">The child object to insert into the box.</param>
257 /// <param name="position">The numeric position >=0 to insert the child.</param>
258 /// <returns>Success if true.</returns>
259 /// <since_tizen> preview </since_tizen>
260 public bool BoxInsertAt(string part, EvasObject child, uint position)
263 return Interop.Elementary.elm_layout_box_insert_at(RealHandle, part, child.Handle, position);
267 /// Inserts a child to the layout box part before a reference object.
268 /// Once the object is inserted, it will become child of the layout.
269 /// Its lifetime will be bound to the layout. Whenever the layout dies, the child will be deleted automatically.
272 /// This will only work if the layout edc have box part.
274 /// <param name="part">The part.</param>
275 /// <param name="child">The child object to insert into the box.</param>
276 /// <param name="reference">Another reference object to insert before the box.</param>
277 /// <returns>Success is true.</returns>
278 /// <since_tizen> preview </since_tizen>
279 public bool BoxInsertBefore(string part, EvasObject child, EvasObject reference)
282 return Interop.Elementary.elm_layout_box_insert_before(RealHandle, part, child.Handle, reference.Handle);
286 /// Sets the layout content.
288 /// <param name="part">The swallow part name in the edje file.</param>
289 /// <param name="content">The child that will be added in this layout object.</param>
290 /// <returns>TRUE on success, FALSE otherwise.</returns>
291 /// <since_tizen> preview </since_tizen>
292 public override bool SetPartContent(string part, EvasObject content)
294 return SetPartContent(part, content, false);
298 /// Sets the layout content.
300 /// <param name="part">The name of a particular part.</param>
301 /// <param name="content">The content.</param>
302 /// <param name="preserveOldContent">true, preserve old content will be unset. false, preserve old content will not be unset.</param>
303 /// <returns>TRUE on success, FALSE otherwise.</returns>
304 /// <since_tizen> preview </since_tizen>
305 public override bool SetPartContent(string part, EvasObject content, bool preserveOldContent)
307 if (preserveOldContent)
309 Interop.Elementary.elm_layout_content_unset(RealHandle, part);
311 UpdatePartContents(content, part);
312 return Interop.Elementary.elm_layout_content_set(RealHandle, part, content);
316 /// Sets the edje group from the elementary theme that is used as a layout.
318 /// <param name="klass">The class of the group.</param>
319 /// <param name="group">The group.</param>
320 /// <param name="style">The style to use.</param>
321 /// <since_tizen> preview </since_tizen>
322 public void SetTheme(string klass, string group, string style)
324 Interop.Elementary.elm_layout_theme_set(RealHandle, klass, group, style);
328 /// Sets the file that is used as a layout.
330 /// <param name="file">The path to the file (edje) that is used as a layout.</param>
331 /// <param name="group">The group that the layout belongs to in the edje file.</param>
332 /// <since_tizen> preview </since_tizen>
333 public void SetFile(string file, string group)
335 Interop.Elementary.elm_layout_file_set(RealHandle, file, group);
339 /// Sets the background color of a layout.
341 /// <since_tizen> preview </since_tizen>
342 public override Color BackgroundColor
348 Interop.Elementary.elm_object_color_class_del(RealHandle, "bg");
352 SetPartColor("bg", value);
354 _backgroundColor = value;
359 /// Sets the vertical text alignment of the layout's text part.
362 /// API, elm_layout_text_valign_set, is an internal API only in Tizen. Available since Tizen_4.0.
364 /// <since_tizen> preview </since_tizen>
365 public virtual void SetVerticalTextAlignment(string part, double valign)
367 Interop.Elementary.elm_layout_text_valign_set(RealHandle, part, valign);
371 /// Gets the vertical text alignment of the layout's text part.
374 /// API, elm_layout_text_valign_get, is an internal API only in Tizen. Available since Tizen_4.0.
376 /// <since_tizen> preview </since_tizen>
377 public virtual double GetVerticalTextAlignment(string part)
379 return Interop.Elementary.elm_layout_text_valign_get(RealHandle, part);
383 /// The callback of the Realized Event.
385 /// <since_tizen> preview </since_tizen>
386 protected override void OnRealized()
389 _languageChanged = new SmartEvent(this, this.RealHandle, "language,changed");
390 _languageChanged.On += (s, e) =>
392 LanguageChanged?.Invoke(this, EventArgs.Empty);
395 _themeChanged = new SmartEvent(this, this.RealHandle, "theme,changed");
396 _themeChanged.On += (s, e) =>
398 ThemeChanged?.Invoke(this, EventArgs.Empty);
403 /// Sets the content at a part of a given container widget.
405 /// <param name="parent">The parent is a given container which will be attached by the layout as a child. It's <see cref="EvasObject"/> type.</param>
406 /// <returns>The new object, otherwise null if it cannot be created.</returns>
407 /// <since_tizen> preview </since_tizen>
408 protected override IntPtr CreateHandle(EvasObject parent)
410 return Interop.Elementary.elm_layout_add(parent.Handle);