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.
182 /// <param name="part">The part.</param>
183 /// <param name="child">The object to append.</param>
184 /// <returns>Success is true.</returns>
185 /// <since_tizen> preview </since_tizen>
186 public bool BoxAppend(string part, EvasObject child)
189 return Interop.Elementary.elm_layout_box_append(RealHandle, part, child.Handle);
193 /// Prepends a child to the layout box part.
194 /// Once the object is prepended, it will become a child of the layout.
195 /// Its lifetime will be bound to the layout. Whenever the layout dies, the child will be deleted automatically.
197 /// <param name="part">The part.</param>
198 /// <param name="child">The object to prepend.</param>
199 /// <returns>Success is true.</returns>
200 /// <since_tizen> preview </since_tizen>
201 public bool BoxPrepend(string part, EvasObject child)
204 return Interop.Elementary.elm_layout_box_prepend(RealHandle, part, child.Handle);
208 /// Removes a child from the given part box.
209 /// The object will be removed from the box part and its lifetime will not be handled by the layout anymore.
211 /// <param name="part">The part.</param>
212 /// <param name="child">The object to remove.</param>
213 /// <returns>Success if true</returns>
214 /// <since_tizen> preview </since_tizen>
215 public bool BoxRemove(string part, EvasObject child)
218 return Interop.Elementary.elm_layout_box_remove(RealHandle, part, child.Handle) != null;
222 /// Removes all the children from the given part box.
223 /// The objects will be removed from the box part and their lifetime will not be handled by the layout anymore.
225 /// <param name="part">The part.</param>
226 /// <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>
227 /// <returns>Success if true.</returns>
228 /// <since_tizen> preview </since_tizen>
229 public bool BoxRemoveAll(string part, bool clear)
232 return Interop.Elementary.elm_layout_box_remove_all(RealHandle, part, clear);
236 /// Inserts a child to the layout box part at a given position.
237 /// Once the object is inserted, it will become a child of the layout.
238 /// Its lifetime will be bound to the layout. Whenever the layout dies, the child will be deleted automatically.
240 /// <param name="part">The part.</param>
241 /// <param name="child">The child object to insert into the box.</param>
242 /// <param name="position">The numeric position >=0 to insert the child.</param>
243 /// <returns>Success if true.</returns>
244 /// <since_tizen> preview </since_tizen>
245 public bool BoxInsertAt(string part, EvasObject child, uint position)
248 return Interop.Elementary.elm_layout_box_insert_at(RealHandle, part, child.Handle, position);
252 /// Inserts a child to the layout box part before a reference object.
253 /// Once the object is inserted, it will become child of the layout.
254 /// Its lifetime will be bound to the layout. Whenever the layout dies, the child will be deleted automatically.
256 /// <param name="part">The part.</param>
257 /// <param name="child">The child object to insert into the box.</param>
258 /// <param name="reference">Another reference object to insert before the box.</param>
259 /// <returns>Success is true.</returns>
260 /// <since_tizen> preview </since_tizen>
261 public bool BoxInsertBefore(string part, EvasObject child, EvasObject reference)
264 return Interop.Elementary.elm_layout_box_insert_before(RealHandle, part, child.Handle, reference.Handle);
268 /// Sets the layout content.
270 /// <param name="part">The swallow part name in the edje file.</param>
271 /// <param name="content">The child that will be added in this layout object.</param>
272 /// <returns>TRUE on success, FALSE otherwise.</returns>
273 /// <since_tizen> preview </since_tizen>
274 public override bool SetPartContent(string part, EvasObject content)
276 return SetPartContent(part, content, false);
280 /// Sets the layout content.
282 /// <param name="part">The name of a particular part.</param>
283 /// <param name="content">The content.</param>
284 /// <param name="preserveOldContent">true, preserve old content will be unset. false, preserve old content will not be unset.</param>
285 /// <returns>TRUE on success, FALSE otherwise.</returns>
286 /// <since_tizen> preview </since_tizen>
287 public override bool SetPartContent(string part, EvasObject content, bool preserveOldContent)
289 if (preserveOldContent)
291 Interop.Elementary.elm_layout_content_unset(RealHandle, part);
293 UpdatePartContents(content, part);
294 return Interop.Elementary.elm_layout_content_set(RealHandle, part, content);
298 /// Sets the edje group from the elementary theme that is used as a layout.
300 /// <param name="klass">The class of the group.</param>
301 /// <param name="group">The group.</param>
302 /// <param name="style">The style to use.</param>
303 /// <since_tizen> preview </since_tizen>
304 public void SetTheme(string klass, string group, string style)
306 Interop.Elementary.elm_layout_theme_set(RealHandle, klass, group, style);
310 /// Sets the file that is used as a layout.
312 /// <param name="file">The path to the file (edje) that is used as a layout.</param>
313 /// <param name="group">The group that the layout belongs to in the edje file.</param>
314 /// <since_tizen> preview </since_tizen>
315 public void SetFile(string file, string group)
317 Interop.Elementary.elm_layout_file_set(RealHandle, file, group);
321 /// Sets the background color of a layout.
323 /// <since_tizen> preview </since_tizen>
324 public override Color BackgroundColor
328 if (value.IsDefault && ClassName != null)
330 string part = ClassName.ToLower().Replace("elm_", "") + "/" + "bg";
331 EdjeObject.DeleteColorClass(part);
335 SetPartColor("bg", value);
337 _backgroundColor = value;
342 /// Sets the vertical text alignment of the layout's text part.
345 /// API, elm_layout_text_valign_set, is an internal API only in Tizen. Available since Tizen_4.0.
347 /// <since_tizen> preview </since_tizen>
348 public virtual void SetVerticalTextAlignment(string part, double valign)
350 Interop.Elementary.elm_layout_text_valign_set(RealHandle, part, valign);
354 /// Gets the vertical text alignment of the layout's text part.
357 /// API, elm_layout_text_valign_get, is an internal API only in Tizen. Available since Tizen_4.0.
359 /// <since_tizen> preview </since_tizen>
360 public virtual double GetVerticalTextAlignment(string part)
362 return Interop.Elementary.elm_layout_text_valign_get(RealHandle, part);
366 /// The callback of the Realized Event.
368 /// <since_tizen> preview </since_tizen>
369 protected override void OnRealized()
372 _languageChanged = new SmartEvent(this, this.RealHandle, "language,changed");
373 _languageChanged.On += (s, e) =>
375 LanguageChanged?.Invoke(this, EventArgs.Empty);
378 _themeChanged = new SmartEvent(this, this.RealHandle, "theme,changed");
379 _themeChanged.On += (s, e) =>
381 ThemeChanged?.Invoke(this, EventArgs.Empty);
386 /// Sets the content at a part of a given container widget.
388 /// <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>
389 /// <returns>The new object, otherwise null if it cannot be created.</returns>
390 /// <since_tizen> preview </since_tizen>
391 protected override IntPtr CreateHandle(EvasObject parent)
393 return Interop.Elementary.elm_layout_add(parent.Handle);