Enhance Toolbar Widget
authorsung-su.kim <sung-su.kim@samsung.com>
Thu, 18 May 2017 08:06:28 +0000 (17:06 +0900)
committersung-su.kim <sung-su.kim@samsung.com>
Thu, 1 Jun 2017 02:33:35 +0000 (11:33 +0900)
Change-Id: Id1e901a50ea3f362d2e3338e42ef1cc34b9ec559

src/ElmSharp/ElmSharp/Toolbar.cs
src/ElmSharp/Interop/Interop.Elementary.Toolbar.cs
test/ElmSharp.Test/ElmSharp.Test.csproj
test/ElmSharp.Test/TC/ToolbarTest4.cs [new file with mode: 0755]

index 63ebd93..7d5e65f 100755 (executable)
@@ -15,6 +15,7 @@
  */
 
 using System;
+using System.ComponentModel;
 
 namespace ElmSharp
 {
@@ -76,6 +77,32 @@ namespace ElmSharp
     }
 
     /// <summary>
+    /// Enumeration for the icon lookup order of Toolbar.
+    /// </summary>
+    public enum ToolbarIconLookupOrder
+    {
+        /// <summary>
+        /// Icon look up order: freedesktop, theme.
+        /// </summary>
+        FreedesktopTheme,
+
+        /// <summary>
+        /// Icon look up order: theme, freedesktop.
+        /// </summary>
+        ThemeFreedesktop,
+
+        /// <summary>
+        /// Icon look up order: freedesktop.
+        /// </summary>
+        Freedesktop,
+
+        /// <summary>
+        /// Icon look up order: theme.
+        /// </summary>
+        Theme,
+    }
+
+    /// <summary>
     /// Event arguments for events of <see cref="ToolbarItem"/>.
     /// </summary>
     /// <remarks>
@@ -185,6 +212,68 @@ namespace ElmSharp
         }
 
         /// <summary>
+        /// 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.
+        /// </summary>
+        //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);
+            }
+        }
+
+        /// <summary>
+        /// 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.
+        /// </summary>
+        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);
+            }
+        }
+
+        /// <summary>
+        /// Sets or gets the icon size of a given toolbar widget.
+        /// Default value is 32 pixels, to be used by toolbar items.
+        /// </summary>
+        public int IconSize
+        {
+            get
+            {
+                return Interop.Elementary.elm_toolbar_icon_size_get(RealHandle);
+            }
+            set
+            {
+                Interop.Elementary.elm_toolbar_icon_size_set(RealHandle, value);
+            }
+        }
+
+        /// <summary>
+        /// Gets the number of items in a toolbar widget.
+        /// </summary>
+        public int ItemsCount
+        {
+            get
+            {
+                return Interop.Elementary.elm_toolbar_items_count(RealHandle);
+            }
+        }
+
+        /// <summary>
         /// Sets or gets the alignment of the items.
         /// </summary>
         /// <remarks>The toolbar items alignment, a float between 0.0 and 1.0</remarks>
@@ -304,6 +393,32 @@ namespace ElmSharp
         }
 
         /// <summary>
+        /// Inserts a new item which contains label and icon into the toolbar object after item <paramref name="after"/>.
+        /// </summary>
+        /// <param name="after">The toolbar item to insert after</param>
+        /// <param name="label">The label of the item</param>
+        /// <param name="icon">A string with the icon name or the absolute path of an image file</param>
+        /// <returns>The new <see cref="ToolbarItem"/> which insert into the toolbar</returns>
+        /// <seealso cref="InsertAfter(ToolbarItem, string)"/>
+        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;
+        }
+
+        /// <summary>
+        /// Find the item with that label in the toolbar.
+        /// </summary>
+        /// <param name="label">The label of the item</param>
+        /// <returns>The <see cref="ToolbarItem"/> into the toolbar</returns>
+        public ToolbarItem FindItemByLabel(string label)
+        {
+            IntPtr handle = Interop.Elementary.elm_toolbar_item_find_by_label(RealHandle, label);
+            return ItemObject.GetItemByHandle(handle) as ToolbarItem;
+        }
+
+        /// <summary>
         /// Gets the selected ToolbarItemItem of the toolbar.
         /// </summary>
         public ToolbarItem SelectedItem
@@ -315,6 +430,30 @@ namespace ElmSharp
             }
         }
 
+        /// <summary>
+        /// Gets the first ToolbarItemItem of the toolbar.
+        /// </summary>
+        public ToolbarItem FirstItem
+        {
+            get
+            {
+                IntPtr handle = Interop.Elementary.elm_toolbar_first_item_get(RealHandle);
+                return ItemObject.GetItemByHandle(handle) as ToolbarItem;
+            }
+        }
+
+        /// <summary>
+        /// Gets the last ToolbarItemItem of the toolbar.
+        /// </summary>
+        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);
index 5c5b519..d753827 100644 (file)
@@ -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);
     }
 }
index 8457572..85131a5 100755 (executable)
     <Compile Include="TC\ToolbarTest1.cs" />
     <Compile Include="TC\ToolbarTest2.cs" />
     <Compile Include="TC\ToolbarTest3.cs" />
+    <Compile Include="TC\ToolbarTest4.cs" />
     <Compile Include="TC\WindowInternalTest.cs" />
     <Compile Include="TestCaseBase.cs" />
     <Compile Include="TestRunner.cs" />
       </FlavorProperties>
     </VisualStudio>
   </ProjectExtensions>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/test/ElmSharp.Test/TC/ToolbarTest4.cs b/test/ElmSharp.Test/TC/ToolbarTest4.cs
new file mode 100755 (executable)
index 0000000..db2ee47
--- /dev/null
@@ -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