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 public enum ToolbarSelectionMode
28 /// Default select mode.
33 /// Always select mode.
43 /// No select mode with no finger size rule.
49 /// Enumeration that sets the toolbar items display behavior, it can be scrollable, can show a menu with exceeding items, or simply hide them.
51 public enum ToolbarShrinkMode
54 /// Sets minimum toolbar size to fit all the items.
59 /// Hides exceeding items.
64 /// Allows accessing exceeding items through a scroller.
69 /// Inserts a button to pop up a menu with exceeding items.
74 /// Expands all items according to the size of the toolbar.
80 /// Enumeration for the icon lookup order of Toolbar.
82 public enum ToolbarIconLookupOrder
85 /// Icon look up order: freedesktop, theme.
90 /// Icon look up order: theme, freedesktop.
95 /// Icon look up order: freedesktop.
100 /// Icon look up order: theme.
106 /// Event arguments for events of <see cref="ToolbarItem"/>.
109 /// Inherits EventArgs.
111 public class ToolbarItemEventArgs : EventArgs
114 /// Gets the ToolbarItem.
116 public ToolbarItem Item { get; private set; }
118 internal static ToolbarItemEventArgs CreateFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info)
120 ToolbarItem item = ItemObject.GetItemByHandle(info) as ToolbarItem;
121 return new ToolbarItemEventArgs() { Item = item };
126 /// The Toolbar is a widget that displays a list of items inside a box.
128 public class Toolbar : Widget, IScrollable
130 ScrollableAdapter _scroller;
131 SmartEvent<ToolbarItemEventArgs> _clicked;
132 SmartEvent<ToolbarItemEventArgs> _selected;
133 SmartEvent<ToolbarItemEventArgs> _longpressed;
136 /// Creates and initializes a new instance of the Toolbar class.
138 /// <param name="parent">
139 /// A EvasObject to which the new Table instance will be attached.
141 public Toolbar(EvasObject parent) : base(parent)
143 _selected = new SmartEvent<ToolbarItemEventArgs>(this, this.RealHandle, "selected", ToolbarItemEventArgs.CreateFromSmartEvent);
144 _selected.On += (s, e) =>
148 Selected?.Invoke(this, e);
149 e.Item.SendSelected();
152 _longpressed = new SmartEvent<ToolbarItemEventArgs>(this, this.RealHandle, "longpressed", ToolbarItemEventArgs.CreateFromSmartEvent);
153 _longpressed.On += (s, e) =>
155 e.Item?.SendLongPressed();
157 _clicked = new SmartEvent<ToolbarItemEventArgs>(this, this.RealHandle, "clicked", ToolbarItemEventArgs.CreateFromSmartEvent);
158 _clicked.On += (s, e) =>
160 e.Item?.SendClicked();
163 _scroller = new ScrollableAdapter(this);
167 /// Selected will be triggered when toolbar have been selected.
169 public event EventHandler<ToolbarItemEventArgs> Selected;
172 /// Sets or gets whether the layout of this toolbar is homogeneous.
174 /// <remarks>True for homogeneous, False for no homogeneous</remarks>
175 public bool Homogeneous
179 return Interop.Elementary.elm_toolbar_homogeneous_get(RealHandle);
183 Interop.Elementary.elm_toolbar_homogeneous_set(RealHandle, value);
188 /// Sets or gets the slection mode of a given Toolbar widget.
190 public ToolbarSelectionMode SelectionMode
194 return (ToolbarSelectionMode)Interop.Elementary.elm_toolbar_select_mode_get(RealHandle);
198 Interop.Elementary.elm_toolbar_select_mode_set(RealHandle, (int)value);
203 /// Sets or gets the shrink mode of a given Toolbar widget.
205 public ToolbarShrinkMode ShrinkMode
209 return (ToolbarShrinkMode)Interop.Elementary.elm_toolbar_shrink_mode_get(RealHandle);
213 Interop.Elementary.elm_toolbar_shrink_mode_set(RealHandle, (int)value);
218 /// Sets or gets toolbar's current orientation.
220 [EditorBrowsable(EditorBrowsableState.Never)]
221 public bool IsHorizontal
225 return Interop.Elementary.elm_toolbar_horizontal_get(RealHandle);
229 Interop.Elementary.elm_toolbar_horizontal_set(RealHandle, value);
234 /// Sets or gets the icon lookup order, for toolbar items' icons.
235 /// The default lookup order is ToolbarIocnLookupOrder.ThemeFreedesktop.
236 /// Icons added before calling this function will not be affected.
238 public ToolbarIconLookupOrder IconLookupOrder
242 return (ToolbarIconLookupOrder)Interop.Elementary.elm_toolbar_icon_order_lookup_get(RealHandle);
246 Interop.Elementary.elm_toolbar_icon_order_lookup_set(RealHandle, (int)value);
251 /// Sets or gets the icon size of a given toolbar widget.
252 /// Default value is 32 pixels, to be used by toolbar items.
258 return Interop.Elementary.elm_toolbar_icon_size_get(RealHandle);
262 Interop.Elementary.elm_toolbar_icon_size_set(RealHandle, value);
267 /// Gets the number of items in a toolbar widget.
269 public int ItemsCount
273 return Interop.Elementary.elm_toolbar_items_count(RealHandle);
278 /// Sets or gets the alignment of the items.
280 /// <remarks>The toolbar items alignment, a float between 0.0 and 1.0</remarks>
281 public double ItemAlignment
285 return Interop.Elementary.elm_toolbar_align_get(RealHandle);
289 Interop.Elementary.elm_toolbar_align_set(RealHandle, value);
294 /// Sets or gets the item's transverse expansion of a given toolbar widget.
297 /// The transverse expansion of the item, true for on and false for off.
298 /// By default it's false.
300 public bool TransverseExpansion
304 return Interop.Elementary.elm_toolbar_transverse_expanded_get(RealHandle);
308 Interop.Elementary.elm_toolbar_transverse_expanded_set(RealHandle, value);
313 /// Appends ToolbarItem which just contains label to the toolbar.
315 /// <param name="label">The label of the item</param>
316 /// <returns>The new ToolbarItem which appended to the toolbar</returns>
317 /// <seealso cref="Append(string, string)"/>
318 /// <seealso cref="Prepend(string)"/>
319 public ToolbarItem Append(string label)
321 return Append(label, null);
325 /// Appends ToolbarItem which contains label and icon to the toolbar.
327 /// <param name="label">The label of the item</param>
328 /// <param name="icon">A string with the icon name or the absolute path of an image file</param>
329 /// <returns>The new ToolbarItem which appended to the toolbar</returns>
330 /// <seealso cref="Append(string)"/>
331 /// <seealso cref="Prepend(string)"/>
332 /// <seealso cref="Prepend(string, string)"/>
333 public ToolbarItem Append(string label, string icon)
335 ToolbarItem item = new ToolbarItem(label, icon);
336 item.Handle = Interop.Elementary.elm_toolbar_item_append(RealHandle, icon, label, null, (IntPtr)item.Id);
341 /// Prepends ToolbarItem which just contains label to the toolbar.
343 /// <param name="label">The label of the item</param>
344 /// <returns>The new ToolbarItem which prepended to the toolbar</returns>
345 /// <seealso cref="Append(string)"/>
346 /// <seealso cref="Append(string, string)"/>
347 /// <seealso cref="Prepend(string, string)"/>
348 public ToolbarItem Prepend(string label)
350 return Prepend(label, null);
354 /// Prepends ToolbarItem which contains label and icon to the toolbar.
356 /// <param name="label">The label of the item</param>
357 /// <param name="icon">A string with the icon name or the absolute path of an image file</param>
358 /// <returns>The new <see cref="ToolbarItem"/> which prepended to the toolbar</returns>
359 /// <seealso cref="Append(string)"/>
360 /// <seealso cref="Append(string, string)"/>
361 /// <seealso cref="Prepend(string)"/>
362 public ToolbarItem Prepend(string label, string icon)
364 ToolbarItem item = new ToolbarItem(label, icon);
365 item.Handle = Interop.Elementary.elm_toolbar_item_prepend(RealHandle, icon, label, null, (IntPtr)item.Id);
370 /// Inserts a new item which just contains label into the toolbar object before item <paramref name="before"/>.
372 /// <param name="before">The toolbar item to insert before</param>
373 /// <param name="label">The label of the item</param>
374 /// <returns>The new <see cref="ToolbarItem"/> which insert into the toolbar</returns>
375 /// <seealso cref="InsertBefore(ToolbarItem, string, string)"/>
376 public ToolbarItem InsertBefore(ToolbarItem before, string label)
378 return InsertBefore(before, label, string.Empty);
382 /// Inserts a new item which contains label and icon into the toolbar object before item <paramref name="before"/>.
384 /// <param name="before">The toolbar item to insert before</param>
385 /// <param name="label">The label of the item</param>
386 /// <param name="icon">A string with the icon name or the absolute path of an image file</param>
387 /// <returns>The new <see cref="ToolbarItem"/> which insert into the toolbar</returns>
388 /// <seealso cref="InsertBefore(ToolbarItem, string)"/>
389 public ToolbarItem InsertBefore(ToolbarItem before, string label, string icon)
391 ToolbarItem item = new ToolbarItem(label, icon);
392 item.Handle = Interop.Elementary.elm_toolbar_item_insert_before(RealHandle, before, icon, label, null, (IntPtr)item.Id);
397 /// Inserts a new item which contains label and icon into the toolbar object after item <paramref name="after"/>.
399 /// <param name="after">The toolbar item to insert after</param>
400 /// <param name="label">The label of the item</param>
401 /// <param name="icon">A string with the icon name or the absolute path of an image file</param>
402 /// <returns>The new <see cref="ToolbarItem"/> which insert into the toolbar</returns>
403 public ToolbarItem InsertAfter(ToolbarItem after, string label, string icon)
405 ToolbarItem item = new ToolbarItem(label, icon);
406 item.Handle = Interop.Elementary.elm_toolbar_item_insert_after(RealHandle, after, icon, label, null, (IntPtr)item.Id);
411 /// Find the item with that label in the toolbar.
413 /// <param name="label">The label of the item</param>
414 /// <returns>The <see cref="ToolbarItem"/> into the toolbar</returns>
415 public ToolbarItem FindItemByLabel(string label)
417 IntPtr handle = Interop.Elementary.elm_toolbar_item_find_by_label(RealHandle, label);
418 return ItemObject.GetItemByHandle(handle) as ToolbarItem;
422 /// Gets the selected ToolbarItemItem of the toolbar.
424 public ToolbarItem SelectedItem
428 IntPtr handle = Interop.Elementary.elm_toolbar_selected_item_get(RealHandle);
429 return ItemObject.GetItemByHandle(handle) as ToolbarItem;
434 /// Gets the first ToolbarItemItem of the toolbar.
436 public ToolbarItem FirstItem
440 IntPtr handle = Interop.Elementary.elm_toolbar_first_item_get(RealHandle);
441 return ItemObject.GetItemByHandle(handle) as ToolbarItem;
446 /// Gets the last ToolbarItemItem of the toolbar.
448 public ToolbarItem LastItem
452 IntPtr handle = Interop.Elementary.elm_toolbar_last_item_get(RealHandle);
453 return ItemObject.GetItemByHandle(handle) as ToolbarItem;
458 /// Creates a widget handle.
460 /// <param name="parent">Parent EvasObject</param>
461 /// <returns>Handle IntPtr</returns>
462 protected override IntPtr CreateHandle(EvasObject parent)
464 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
465 Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
467 RealHandle = Interop.Elementary.elm_toolbar_add(handle);
468 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
473 #region IScroller Implementation
476 /// Scrolled will be triggered when the content has been scrolled.
478 public event EventHandler Scrolled
480 add => _scroller.Scrolled += value;
481 remove => _scroller.Scrolled -= value;
485 /// DragStart will be triggered when dragging the contents around has started.
487 public event EventHandler DragStart
489 add => _scroller.DragStart += value;
490 remove => _scroller.DragStart -= value;
494 /// DragStop will be triggered when dragging the contents around has stopped.
496 public event EventHandler DragStop
498 add => _scroller.DragStop += value;
499 remove => _scroller.DragStop -= value;
503 /// PageScrolled will be triggered when the visible page has changed.
505 public event EventHandler PageScrolled
507 add => _scroller.PageScrolled += value;
508 remove => _scroller.PageScrolled -= value;
512 /// Gets the current region in the content object that is visible through the Scroller.
514 public Rect CurrentRegion => _scroller.CurrentRegion;
517 /// Sets or gets the value of HorizontalScrollBarVisiblePolicy
520 /// ScrollBarVisiblePolicy.Auto means the horizontal scrollbar is made visible if it is needed, and otherwise kept hidden.
521 /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
523 public virtual ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy
525 get => _scroller.HorizontalScrollBarVisiblePolicy;
526 set => _scroller.HorizontalScrollBarVisiblePolicy = value;
530 /// Sets or gets the value of VerticalScrollBarVisiblePolicy
533 /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden.
534 /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
536 public virtual ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy
538 get => _scroller.VerticalScrollBarVisiblePolicy;
539 set => _scroller.VerticalScrollBarVisiblePolicy = value;
543 /// Sets or gets the value of ScrollBlock.
546 /// This function will block scrolling movement in a given direction.One can disable movements in the X axis, the Y axis or both.
547 /// The default value is ScrollBlock.None, where movements are allowed in both directions.
549 public ScrollBlock ScrollBlock
551 get => _scroller.ScrollBlock;
552 set => _scroller.ScrollBlock = value;
556 /// Sets or gets scroll current page number.
559 /// Current page means the page which meets the top of the viewport.
560 /// If there are two or more pages in the viewport, it returns the number of the page which meets the top of the viewport.
561 /// The page number starts from 0. 0 is the first page.
563 public int VerticalPageIndex => _scroller.VerticalPageIndex;
566 /// Sets or gets scroll current page number.
569 /// Current page means the page which meets the left of the viewport.
570 /// If there are two or more pages in the viewport, it returns the number of the page which meets the left of the viewport.
571 /// The page number starts from 0. 0 is the first page.
573 public int HorizontalPageIndex => _scroller.HorizontalPageIndex;
576 /// Sets or gets the maximum limit of the movable page at vertical direction.
578 public int VerticalPageScrollLimit
580 get => _scroller.VerticalPageScrollLimit;
581 set => _scroller.VerticalPageScrollLimit = value;
585 /// Sets or gets the maximum limit of the movable page at horizontal direction.
587 public int HorizontalPageScrollLimit
589 get => _scroller.HorizontalPageScrollLimit;
590 set => _scroller.HorizontalPageScrollLimit = value;
594 /// Sets or gets the vertical bounce behaviour.
595 /// When scrolling, the scroller may "bounce" when reaching an edge of the content object.
596 /// This is a visual way to indicate the end has been reached.
597 /// This is enabled by default for both axis.
598 /// This API will set if it is enabled for the given axis with the boolean parameters for each axis.
600 public bool VerticalBounce
602 get => _scroller.VerticalBounce;
603 set => _scroller.VerticalBounce = value;
607 /// Sets or gets the horizontal bounce behaviour.
608 /// When scrolling, the scroller may "bounce" when reaching an edge of the content object.
609 /// This is a visual way to indicate the end has been reached.
610 /// This is enabled by default for both axis.
611 /// This API will set if it is enabled for the given axis with the boolean parameters for each axis.
613 public bool HorizontalBounce
615 get => _scroller.HorizontalBounce;
616 set => _scroller.HorizontalBounce = value;
620 /// Gets the width of the content object of the scroller.
622 public int ChildWidth
624 get => _scroller.ChildWidth;
628 /// Gets the height of the content object of the scroller.
630 public int ChildHeight
632 get => _scroller.ChildHeight;
636 /// Set scrolling gravity values for a scroller.
637 /// The gravity, defines how the scroller will adjust its view when the size of the scroller contents increase.
638 /// The scroller will adjust the view to glue itself as follows.
639 /// x=0.0, for staying where it is relative to the left edge of the content x=1.0, for staying where it is relative to the rigth edge of the content y=0.0, for staying where it is relative to the top edge of the content y=1.0, for staying where it is relative to the bottom edge of the content
640 /// Default values for x and y are 0.0
642 public double HorizontalGravity
644 get => _scroller.HorizontalGravity;
645 set => _scroller.HorizontalGravity = value;
649 /// Set scrolling gravity values for a scroller.
650 /// The gravity, defines how the scroller will adjust its view when the size of the scroller contents increase.
651 /// The scroller will adjust the view to glue itself as follows.
652 /// x=0.0, for staying where it is relative to the left edge of the content x=1.0, for staying where it is relative to the rigth edge of the content y=0.0, for staying where it is relative to the top edge of the content y=1.0, for staying where it is relative to the bottom edge of the content
653 /// Default values for x and y are 0.0
655 public double VerticalGravity
657 get => _scroller.VerticalGravity;
658 set => _scroller.VerticalGravity = value;
662 /// Get scroll last page number.
663 /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages.
665 public int LastVerticalPageNumber => _scroller.LastVerticalPageNumber;
668 /// Get scroll last page number.
669 /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages.
671 public int LastHorizontalPageNumber => _scroller.LastHorizontalPageNumber;
674 /// Set an infinite loop_ for a scroller.
675 /// This function sets the infinite loop vertically.
676 /// If the content is set, it will be shown repeatedly.
678 public bool VerticalLoop
680 get => _scroller.VerticalLoop;
681 set => _scroller.VerticalLoop = value;
685 /// Set an infinite loop_ for a scroller.
686 /// This function sets the infinite loop horizontally.
687 /// If the content is set, it will be shown repeatedly.
689 public bool HorizontalLoop
691 get => _scroller.HorizontalLoop;
692 set => _scroller.HorizontalLoop = value;
696 /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis.
698 public int HorizontalPageSize
700 get => _scroller.HorizontalPageSize;
701 set => _scroller.HorizontalPageSize = value;
705 /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis.
707 public int VerticalPageSize
709 get => _scroller.VerticalPageSize;
710 set => _scroller.VerticalPageSize = value;
714 /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size.
716 public double VerticalRelativePageSize
718 get => _scroller.VerticalRelativePageSize;
719 set => _scroller.VerticalRelativePageSize = value;
723 /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size.
725 public double HorizontalRelativePageSize
727 get => _scroller.HorizontalRelativePageSize;
728 set => _scroller.HorizontalRelativePageSize = value;
732 /// Gets or Sets the page snapping behavior of a scroller.
735 /// When scrolling, if a scroller is paged (see VerticalRelativePageSize),
736 /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further,
737 /// it will stop at the next page boundaries. This is disabled, by default, for both axis.
738 /// This function will set if it that is enabled or not, for each axis.
740 public bool VerticalSnap
742 get => _scroller.VerticalSnap;
743 set => _scroller.VerticalSnap = value;
747 /// Gets or Sets the page snapping behavior of a scroller.
750 /// When scrolling, if a scroller is paged (see HorizontalRelativePageSize),
751 /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further,
752 /// it will stop at the next page boundaries. This is disabled, by default, for both axis.
753 /// This function will set if it that is enabled or not, for each axis.
755 public bool HorizontalSnap
757 get => _scroller.HorizontalSnap;
758 set => _scroller.HorizontalSnap = value;
762 /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis.
764 public int PageHeight
766 get => _scroller.PageHeight;
767 set => _scroller.PageHeight = value;
771 /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis.
775 get => _scroller.PageWidth;
776 set => _scroller.PageWidth = value;
780 /// Gets or sets the step size to move scroller by key event.
782 public int HorizontalStepSize
784 get => _scroller.HorizontalStepSize;
785 set => _scroller.HorizontalStepSize = value;
789 /// Gets or sets the step size to move scroller by key event.
791 public int VerticalStepSize
793 get => _scroller.VerticalStepSize;
794 set => _scroller.VerticalStepSize = value;
798 /// Gets or sets a value whether mouse wheel is enabled or not over the scroller.
800 public bool WheelDisabled
802 get => _scroller.WheelDisabled;
803 set => _scroller.WheelDisabled = value;
807 /// Gets or sets the type of single direction scroll.
809 public ScrollSingleDirection SingleDirection
811 get => _scroller.SingleDirection;
812 set => _scroller.SingleDirection = value;
816 /// Sets the scroller minimum size limited to the minimum size of the content.
817 /// By default the scroller will be as small as its design allows, irrespective of its content.
818 /// This will make the scroller minimum size the right size horizontally and/or vertically to perfectly fit its content in that direction.
820 /// <param name="horizontal">Enable limiting minimum size horizontally</param>
821 /// <param name="vertical">Enable limiting minimum size vertically</param>
822 public void MinimumLimit(bool horizontal, bool vertical)
824 _scroller.MinimumLimit(horizontal, vertical);
828 /// Shows a specific virtual region within the scroller content object by the page number.
829 /// (0, 0) of the indicated page is located at the top-left corner of the viewport.
831 /// <param name="horizontalPageIndex">The horizontal page number.</param>
832 /// <param name="verticalPageIndex">The vertical page number.</param>
833 /// <param name="animated">True means slider with animation.</param>
834 public void ScrollTo(int horizontalPageIndex, int verticalPageIndex, bool animated)
836 _scroller.ScrollTo(horizontalPageIndex, verticalPageIndex, animated);
840 /// Shows a specific virtual region within the scroller content object.
843 /// This ensures that all (or part, if it does not fit) of the designated region in the virtual content object ((0, 0)
844 /// starting at the top-left of the virtual content object) is shown within the scroller.
845 /// If set "animated" to true, it will allows the scroller to "smoothly slide" to this location
846 /// (if configuration in general calls for transitions).
847 /// It may not jump immediately to the new location and may take a while and show other content along the way.
849 /// <param name="region">Rect struct of region.</param>
850 /// <param name="animated">True means allows the scroller to "smoothly slide" to this location.</param>
851 public void ScrollTo(Rect region, bool animated)
853 _scroller.ScrollTo(region, animated);