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.ComponentModel;
23 /// Enumeration for the selection mode of Toolbar.
25 /// <since_tizen> preview </since_tizen>
26 public enum ToolbarSelectionMode
29 /// Default select mode.
34 /// Always select mode.
44 /// No select mode with no finger size rule.
50 /// Enumeration that sets the toolbar items display behavior, it can be scrollable, can show a menu with exceeding items, or simply hide them.
52 /// <since_tizen> preview </since_tizen>
53 public enum ToolbarShrinkMode
56 /// Sets minimum toolbar size to fit all the items.
61 /// Hides exceeding items.
66 /// Allows accessing exceeding items through a scroller.
71 /// Inserts a button to pop up a menu with exceeding items.
76 /// Expands all items according to the size of the toolbar.
82 /// Enumeration for the icon lookup order of Toolbar.
84 /// <since_tizen> preview </since_tizen>
85 public enum ToolbarIconLookupOrder
88 /// Icon look up order: freedesktop, theme.
93 /// Icon look up order: theme, freedesktop.
98 /// Icon look up order: freedesktop.
103 /// Icon look up order: theme.
109 /// Event arguments for events of <see cref="ToolbarItem"/>.
112 /// Inherits EventArgs.
114 /// <since_tizen> preview </since_tizen>
115 public class ToolbarItemEventArgs : EventArgs
118 /// Gets the ToolbarItem.
120 /// <since_tizen> preview </since_tizen>
121 public ToolbarItem Item { get; private set; }
123 internal static ToolbarItemEventArgs CreateFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info)
125 ToolbarItem item = ItemObject.GetItemByHandle(info) as ToolbarItem;
126 return new ToolbarItemEventArgs() { Item = item };
131 /// The Toolbar is a widget that displays a list of items inside a box.
133 /// <since_tizen> preview </since_tizen>
134 public class Toolbar : Widget
136 SmartEvent<ToolbarItemEventArgs> _clicked;
137 SmartEvent<ToolbarItemEventArgs> _selected;
138 SmartEvent<ToolbarItemEventArgs> _longpressed;
141 /// Creates and initializes a new instance of the Toolbar class.
143 /// <param name="parent">
144 /// A EvasObject to which the new Table instance will be attached.
146 /// <since_tizen> preview </since_tizen>
147 public Toolbar(EvasObject parent) : base(parent)
149 _selected = new SmartEvent<ToolbarItemEventArgs>(this, this.RealHandle, "selected", ToolbarItemEventArgs.CreateFromSmartEvent);
150 _selected.On += (s, e) =>
154 Selected?.Invoke(this, e);
155 e.Item.SendSelected();
158 _longpressed = new SmartEvent<ToolbarItemEventArgs>(this, this.RealHandle, "longpressed", ToolbarItemEventArgs.CreateFromSmartEvent);
159 _longpressed.On += (s, e) =>
161 e.Item?.SendLongPressed();
163 _clicked = new SmartEvent<ToolbarItemEventArgs>(this, this.RealHandle, "clicked", ToolbarItemEventArgs.CreateFromSmartEvent);
164 _clicked.On += (s, e) =>
166 e.Item?.SendClicked();
171 /// Selected will be triggered when toolbar have been selected.
173 /// <since_tizen> preview </since_tizen>
174 public event EventHandler<ToolbarItemEventArgs> Selected;
177 /// Sets or gets whether the layout of this toolbar is homogeneous.
179 /// <remarks>True for homogeneous, False for no homogeneous</remarks>
180 /// <since_tizen> preview </since_tizen>
181 public bool Homogeneous
185 return Interop.Elementary.elm_toolbar_homogeneous_get(RealHandle);
189 Interop.Elementary.elm_toolbar_homogeneous_set(RealHandle, value);
194 /// Sets or gets the slection mode of a given Toolbar widget.
196 /// <since_tizen> preview </since_tizen>
197 public ToolbarSelectionMode SelectionMode
201 return (ToolbarSelectionMode)Interop.Elementary.elm_toolbar_select_mode_get(RealHandle);
205 Interop.Elementary.elm_toolbar_select_mode_set(RealHandle, (int)value);
210 /// Sets or gets the shrink mode of a given Toolbar widget.
212 /// <since_tizen> preview </since_tizen>
213 public ToolbarShrinkMode ShrinkMode
217 return (ToolbarShrinkMode)Interop.Elementary.elm_toolbar_shrink_mode_get(RealHandle);
221 Interop.Elementary.elm_toolbar_shrink_mode_set(RealHandle, (int)value);
226 /// Sets or gets toolbar's current orientation.
228 /// <since_tizen> preview </since_tizen>
229 [EditorBrowsable(EditorBrowsableState.Never)]
230 public bool IsHorizontal
234 return Interop.Elementary.elm_toolbar_horizontal_get(RealHandle);
238 Interop.Elementary.elm_toolbar_horizontal_set(RealHandle, value);
243 /// Sets or gets the icon lookup order, for toolbar items' icons.
244 /// The default lookup order is ToolbarIocnLookupOrder.ThemeFreedesktop.
245 /// Icons added before calling this function will not be affected.
247 /// <since_tizen> preview </since_tizen>
248 public ToolbarIconLookupOrder IconLookupOrder
252 return (ToolbarIconLookupOrder)Interop.Elementary.elm_toolbar_icon_order_lookup_get(RealHandle);
256 Interop.Elementary.elm_toolbar_icon_order_lookup_set(RealHandle, (int)value);
261 /// Sets or gets the icon size of a given toolbar widget.
262 /// Default value is 32 pixels, to be used by toolbar items.
264 /// <since_tizen> preview </since_tizen>
269 return Interop.Elementary.elm_toolbar_icon_size_get(RealHandle);
273 Interop.Elementary.elm_toolbar_icon_size_set(RealHandle, value);
278 /// Gets the number of items in a toolbar widget.
280 /// <since_tizen> preview </since_tizen>
281 public int ItemsCount
285 return Interop.Elementary.elm_toolbar_items_count(RealHandle);
290 /// Sets or gets the alignment of the items.
292 /// <remarks>The toolbar items alignment, a float between 0.0 and 1.0</remarks>
293 /// <since_tizen> preview </since_tizen>
294 public double ItemAlignment
298 return Interop.Elementary.elm_toolbar_align_get(RealHandle);
302 Interop.Elementary.elm_toolbar_align_set(RealHandle, value);
307 /// Sets or gets the item's transverse expansion of a given toolbar widget.
310 /// The transverse expansion of the item, true for on and false for off.
311 /// By default it's false.
313 /// <since_tizen> preview </since_tizen>
314 public bool TransverseExpansion
318 return Interop.Elementary.elm_toolbar_transverse_expanded_get(RealHandle);
322 Interop.Elementary.elm_toolbar_transverse_expanded_set(RealHandle, value);
327 /// Appends ToolbarItem which just contains label to the toolbar.
329 /// <param name="label">The label of the item</param>
330 /// <returns>The new ToolbarItem which appended to the toolbar</returns>
331 /// <seealso cref="Append(string, string)"/>
332 /// <seealso cref="Prepend(string)"/>
333 /// <since_tizen> preview </since_tizen>
334 public ToolbarItem Append(string label)
336 return Append(label, null);
340 /// Appends ToolbarItem which contains label and icon to the toolbar.
342 /// <param name="label">The label of the item</param>
343 /// <param name="icon">A string with the icon name or the absolute path of an image file</param>
344 /// <returns>The new ToolbarItem which appended to the toolbar</returns>
345 /// <seealso cref="Append(string)"/>
346 /// <seealso cref="Prepend(string)"/>
347 /// <seealso cref="Prepend(string, string)"/>
348 /// <since_tizen> preview </since_tizen>
349 public ToolbarItem Append(string label, string icon)
351 ToolbarItem item = new ToolbarItem(label, icon);
352 item.Handle = Interop.Elementary.elm_toolbar_item_append(RealHandle, icon, label, null, (IntPtr)item.Id);
357 /// Prepends ToolbarItem which just contains label to the toolbar.
359 /// <param name="label">The label of the item</param>
360 /// <returns>The new ToolbarItem which prepended to the toolbar</returns>
361 /// <seealso cref="Append(string)"/>
362 /// <seealso cref="Append(string, string)"/>
363 /// <seealso cref="Prepend(string, string)"/>
364 /// <since_tizen> preview </since_tizen>
365 public ToolbarItem Prepend(string label)
367 return Prepend(label, null);
371 /// Prepends ToolbarItem which contains label and icon to the toolbar.
373 /// <param name="label">The label of the item</param>
374 /// <param name="icon">A string with the icon name or the absolute path of an image file</param>
375 /// <returns>The new <see cref="ToolbarItem"/> which prepended to the toolbar</returns>
376 /// <seealso cref="Append(string)"/>
377 /// <seealso cref="Append(string, string)"/>
378 /// <seealso cref="Prepend(string)"/>
379 /// <since_tizen> preview </since_tizen>
380 public ToolbarItem Prepend(string label, string icon)
382 ToolbarItem item = new ToolbarItem(label, icon);
383 item.Handle = Interop.Elementary.elm_toolbar_item_prepend(RealHandle, icon, label, null, (IntPtr)item.Id);
388 /// Inserts a new item which just contains label into the toolbar object before item <paramref name="before"/>.
390 /// <param name="before">The toolbar item to insert before</param>
391 /// <param name="label">The label of the item</param>
392 /// <returns>The new <see cref="ToolbarItem"/> which insert into the toolbar</returns>
393 /// <seealso cref="InsertBefore(ToolbarItem, string, string)"/>
394 /// <since_tizen> preview </since_tizen>
395 public ToolbarItem InsertBefore(ToolbarItem before, string label)
397 return InsertBefore(before, label, string.Empty);
401 /// Inserts a new item which contains label and icon into the toolbar object before item <paramref name="before"/>.
403 /// <param name="before">The toolbar item to insert before</param>
404 /// <param name="label">The label of the item</param>
405 /// <param name="icon">A string with the icon name or the absolute path of an image file</param>
406 /// <returns>The new <see cref="ToolbarItem"/> which insert into the toolbar</returns>
407 /// <seealso cref="InsertBefore(ToolbarItem, string)"/>
408 /// <since_tizen> preview </since_tizen>
409 public ToolbarItem InsertBefore(ToolbarItem before, string label, string icon)
411 ToolbarItem item = new ToolbarItem(label, icon);
412 item.Handle = Interop.Elementary.elm_toolbar_item_insert_before(RealHandle, before, icon, label, null, (IntPtr)item.Id);
417 /// Inserts a new item which contains label and icon into the toolbar object after item <paramref name="after"/>.
419 /// <param name="after">The toolbar item to insert after</param>
420 /// <param name="label">The label of the item</param>
421 /// <param name="icon">A string with the icon name or the absolute path of an image file</param>
422 /// <returns>The new <see cref="ToolbarItem"/> which insert into the toolbar</returns>
423 /// <since_tizen> preview </since_tizen>
424 public ToolbarItem InsertAfter(ToolbarItem after, string label, string icon)
426 ToolbarItem item = new ToolbarItem(label, icon);
427 item.Handle = Interop.Elementary.elm_toolbar_item_insert_after(RealHandle, after, icon, label, null, (IntPtr)item.Id);
432 /// Find the item with that label in the toolbar.
434 /// <param name="label">The label of the item</param>
435 /// <returns>The <see cref="ToolbarItem"/> into the toolbar</returns>
436 /// <since_tizen> preview </since_tizen>
437 public ToolbarItem FindItemByLabel(string label)
439 IntPtr handle = Interop.Elementary.elm_toolbar_item_find_by_label(RealHandle, label);
440 return ItemObject.GetItemByHandle(handle) as ToolbarItem;
444 /// Gets the selected ToolbarItemItem of the toolbar.
446 /// <since_tizen> preview </since_tizen>
447 public ToolbarItem SelectedItem
451 IntPtr handle = Interop.Elementary.elm_toolbar_selected_item_get(RealHandle);
452 return ItemObject.GetItemByHandle(handle) as ToolbarItem;
457 /// Gets the first ToolbarItemItem of the toolbar.
459 /// <since_tizen> preview </since_tizen>
460 public ToolbarItem FirstItem
464 IntPtr handle = Interop.Elementary.elm_toolbar_first_item_get(RealHandle);
465 return ItemObject.GetItemByHandle(handle) as ToolbarItem;
470 /// Gets the last ToolbarItemItem of the toolbar.
472 /// <since_tizen> preview </since_tizen>
473 public ToolbarItem LastItem
477 IntPtr handle = Interop.Elementary.elm_toolbar_last_item_get(RealHandle);
478 return ItemObject.GetItemByHandle(handle) as ToolbarItem;
483 /// Creates a widget handle.
485 /// <param name="parent">Parent EvasObject</param>
486 /// <returns>Handle IntPtr</returns>
487 /// <since_tizen> preview </since_tizen>
488 protected override IntPtr CreateHandle(EvasObject parent)
490 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
491 Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
493 RealHandle = Interop.Elementary.elm_toolbar_add(handle);
494 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);