From db0ee701fd721e64a619a89ac8ffe59d36d79d6c Mon Sep 17 00:00:00 2001 From: "sung-su.kim" Date: Thu, 18 May 2017 17:06:28 +0900 Subject: [PATCH] Enhance Toolbar Widget Change-Id: Id1e901a50ea3f362d2e3338e42ef1cc34b9ec559 --- ElmSharp.Test/ElmSharp.Test.csproj | 3 +- ElmSharp.Test/TC/ToolbarTest4.cs | 135 ++++++++++++++++++++++++ ElmSharp/ElmSharp/Toolbar.cs | 139 +++++++++++++++++++++++++ ElmSharp/Interop/Interop.Elementary.Toolbar.cs | 36 +++++++ 4 files changed, 312 insertions(+), 1 deletion(-) create mode 100755 ElmSharp.Test/TC/ToolbarTest4.cs diff --git a/ElmSharp.Test/ElmSharp.Test.csproj b/ElmSharp.Test/ElmSharp.Test.csproj index 8457572..85131a5 100755 --- a/ElmSharp.Test/ElmSharp.Test.csproj +++ b/ElmSharp.Test/ElmSharp.Test.csproj @@ -111,6 +111,7 @@ + @@ -208,4 +209,4 @@ - \ No newline at end of file + diff --git a/ElmSharp.Test/TC/ToolbarTest4.cs b/ElmSharp.Test/TC/ToolbarTest4.cs new file mode 100755 index 0000000..db2ee47 --- /dev/null +++ b/ElmSharp.Test/TC/ToolbarTest4.cs @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using ElmSharp; +using System.Collections.Generic; + +namespace ElmSharp.Test +{ + public class ToolbarTest3 : TestCaseBase + { + public override string TestName => "ToolbarTest3"; + public override string TestDescription => "To test basic operation of Toolbar"; + + public override void Run(Window window) + { + Conformant conformant = new Conformant(window); + conformant.Show(); + Box outterBox = new Box(window) + { + AlignmentX = -1, + AlignmentY = -1, + WeightX = 1, + WeightY = 1, + IsHorizontal = false, + BackgroundColor = Color.Aqua, + }; + outterBox.Show(); + + Toolbar toolbar = new Toolbar(window) + { + AlignmentX = -1, + WeightX = 1, + ShrinkMode = ToolbarShrinkMode.Scroll, + IconLookupOrder = ToolbarIconLookupOrder.ThemeFreedesktop, + }; + toolbar.Show(); + outterBox.PackEnd(toolbar); + + toolbar.Append("FirstItem", "home"); + toolbar.Append("LastItem", "home"); + ToolbarItem result = toolbar.InsertAfter(toolbar.FirstItem, "Result", ""); + + Button bt1 = new Button(window) + { + Text = "Change IconSize", + MinimumWidth = 400 + }; + bt1.Clicked += (s, e) => + { + if (toolbar.IconSize < 50) + toolbar.IconSize = 100; + else + toolbar.IconSize = 32; + result.Text = string.Format("IconSize{0}", toolbar.IconSize.ToString()); + }; + bt1.Show(); + outterBox.PackEnd(bt1); + + Button bt2 = new Button(window) + { + Text = "Find FirstItem", + MinimumWidth = 400 + }; + bt2.Clicked += (s, e) => + { + ToolbarItem item1 = toolbar.FirstItem; + ToolbarItem item2 = toolbar.FindItemByLabel("FirstItem"); + if (item1 == null || item2 == null || item1 != item2) + result.Text = "FAIL"; + else + result.Text = "PASS"; + }; + bt2.Show(); + outterBox.PackEnd(bt2); + + Button bt3 = new Button(window) + { + Text = "Find LastItem", + MinimumWidth = 400 + }; + bt3.Clicked += (s, e) => + { + ToolbarItem item1 = toolbar.LastItem; + ToolbarItem item2 = toolbar.FindItemByLabel("LastItem"); + if (item1 == null || item2 == null || item1 != item2) + result.Text = "FAIL"; + else + result.Text = "PASS"; + }; + bt3.Show(); + outterBox.PackEnd(bt3); + + Button bt4 = new Button(window) + { + Text = "Get ItemsCount", + MinimumWidth = 400 + }; + bt4.Clicked += (s, e) => + { + result.Text = toolbar.ItemsCount.ToString(); + }; + bt4.Show(); + outterBox.PackEnd(bt4); + + Button bt5 = new Button(window) + { + Text = "Change IconLookupOrder", + MinimumWidth = 400 + }; + bt5.Clicked += (s, e) => + { + toolbar.IconLookupOrder = (ToolbarIconLookupOrder)(((int)toolbar.IconLookupOrder + 1) % 4); + result.Text = toolbar.IconLookupOrder.ToString(); + }; + bt5.Show(); + outterBox.PackEnd(bt5); + + conformant.SetContent(outterBox); + } + } +} \ No newline at end of file diff --git a/ElmSharp/ElmSharp/Toolbar.cs b/ElmSharp/ElmSharp/Toolbar.cs index 63ebd93..7d5e65f 100755 --- a/ElmSharp/ElmSharp/Toolbar.cs +++ b/ElmSharp/ElmSharp/Toolbar.cs @@ -15,6 +15,7 @@ */ using System; +using System.ComponentModel; namespace ElmSharp { @@ -76,6 +77,32 @@ namespace ElmSharp } /// + /// Enumeration for the icon lookup order of Toolbar. + /// + public enum ToolbarIconLookupOrder + { + /// + /// Icon look up order: freedesktop, theme. + /// + FreedesktopTheme, + + /// + /// Icon look up order: theme, freedesktop. + /// + ThemeFreedesktop, + + /// + /// Icon look up order: freedesktop. + /// + Freedesktop, + + /// + /// Icon look up order: theme. + /// + Theme, + } + + /// /// Event arguments for events of . /// /// @@ -185,6 +212,68 @@ namespace ElmSharp } /// + /// Sets or gets the orientation of a given toolbar widget. + /// By default, a toolbar will be horizontal. Use this function to create a vertical toolbar. + /// + //TODO: Below browsable limitation will be removed when the EFL-929 issue is resolved. + [EditorBrowsable(EditorBrowsableState.Never)] + public bool IsHorizontal + { + get + { + return Interop.Elementary.elm_toolbar_horizontal_get(RealHandle); + } + set + { + Interop.Elementary.elm_toolbar_horizontal_set(RealHandle, value); + } + } + + /// + /// Sets or gets the icon lookup order, for toolbar items' icons. + /// The default lookup order is ToolbarIocnLookupOrder.ThemeFreedesktop. + /// Icons added before calling this function will not be affected. + /// + public ToolbarIconLookupOrder IconLookupOrder + { + get + { + return (ToolbarIconLookupOrder)Interop.Elementary.elm_toolbar_icon_order_lookup_get(RealHandle); + } + set + { + Interop.Elementary.elm_toolbar_icon_order_lookup_set(RealHandle, (int)value); + } + } + + /// + /// Sets or gets the icon size of a given toolbar widget. + /// Default value is 32 pixels, to be used by toolbar items. + /// + public int IconSize + { + get + { + return Interop.Elementary.elm_toolbar_icon_size_get(RealHandle); + } + set + { + Interop.Elementary.elm_toolbar_icon_size_set(RealHandle, value); + } + } + + /// + /// Gets the number of items in a toolbar widget. + /// + public int ItemsCount + { + get + { + return Interop.Elementary.elm_toolbar_items_count(RealHandle); + } + } + + /// /// Sets or gets the alignment of the items. /// /// The toolbar items alignment, a float between 0.0 and 1.0 @@ -304,6 +393,32 @@ namespace ElmSharp } /// + /// Inserts a new item which contains label and icon into the toolbar object after item . + /// + /// The toolbar item to insert after + /// The label of the item + /// A string with the icon name or the absolute path of an image file + /// The new which insert into the toolbar + /// + public ToolbarItem InsertAfter(ToolbarItem after, string label, string icon) + { + ToolbarItem item = new ToolbarItem(label, icon); + item.Handle = Interop.Elementary.elm_toolbar_item_insert_after(RealHandle, after, icon, label, null, (IntPtr)item.Id); + return item; + } + + /// + /// Find the item with that label in the toolbar. + /// + /// The label of the item + /// The into the toolbar + public ToolbarItem FindItemByLabel(string label) + { + IntPtr handle = Interop.Elementary.elm_toolbar_item_find_by_label(RealHandle, label); + return ItemObject.GetItemByHandle(handle) as ToolbarItem; + } + + /// /// Gets the selected ToolbarItemItem of the toolbar. /// public ToolbarItem SelectedItem @@ -315,6 +430,30 @@ namespace ElmSharp } } + /// + /// Gets the first ToolbarItemItem of the toolbar. + /// + public ToolbarItem FirstItem + { + get + { + IntPtr handle = Interop.Elementary.elm_toolbar_first_item_get(RealHandle); + return ItemObject.GetItemByHandle(handle) as ToolbarItem; + } + } + + /// + /// Gets the last ToolbarItemItem of the toolbar. + /// + public ToolbarItem LastItem + { + get + { + IntPtr handle = Interop.Elementary.elm_toolbar_last_item_get(RealHandle); + return ItemObject.GetItemByHandle(handle) as ToolbarItem; + } + } + protected override IntPtr CreateHandle(EvasObject parent) { IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle); diff --git a/ElmSharp/Interop/Interop.Elementary.Toolbar.cs b/ElmSharp/Interop/Interop.Elementary.Toolbar.cs index 5c5b519..d753827 100644 --- a/ElmSharp/Interop/Interop.Elementary.Toolbar.cs +++ b/ElmSharp/Interop/Interop.Elementary.Toolbar.cs @@ -64,6 +64,24 @@ internal static partial class Interop internal static extern bool elm_toolbar_homogeneous_get(IntPtr obj); [DllImport(Libraries.Elementary)] + internal static extern bool elm_toolbar_horizontal_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_toolbar_horizontal_set(IntPtr obj, bool horizontal); + + [DllImport(Libraries.Elementary)] + internal static extern int elm_toolbar_icon_order_lookup_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_toolbar_icon_order_lookup_set(IntPtr obj, int order); + + [DllImport(Libraries.Elementary)] + internal static extern int elm_toolbar_icon_size_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_toolbar_icon_size_set(IntPtr obj, int size); + + [DllImport(Libraries.Elementary)] internal static extern void elm_toolbar_item_icon_set(IntPtr obj, string icon); [DllImport(Libraries.Elementary, EntryPoint = "elm_toolbar_item_icon_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)] @@ -94,5 +112,23 @@ internal static partial class Interop [DllImport(Libraries.Elementary)] internal static extern void elm_toolbar_item_separator_set(IntPtr obj, bool separator); + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_toolbar_item_find_by_label(IntPtr obj, string label); + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_toolbar_item_insert_after(IntPtr obj, IntPtr after, string icon, string label, Evas_Smart_Cb func, IntPtr data); + + [DllImport(Libraries.Elementary)] + internal static extern int elm_toolbar_items_count(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_toolbar_menu_parent_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_toolbar_menu_parent_set(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_toolbar_more_item_get(IntPtr obj); } } -- 2.7.4