From ccae50465418547f93c0221929fd4fff6de23692 Mon Sep 17 00:00:00 2001 From: "jh5.cho" Date: Wed, 22 Feb 2017 13:59:25 +0900 Subject: [PATCH] Add Hoversel to implement DropdownList - RFC: http://suprem.sec.samsung.net/confluence/pages/viewpage.action?pageId=73052518 - Add Interop, Hoversel / HoverselItem / HoverselTest1 Change-Id: I69ce9f0cc22c4e8346a49011b051e571234afb77 --- ElmSharp.Test/ElmSharp.Test.csproj | 1 + ElmSharp.Test/TC/HoverselTest1.cs | 82 +++++++++++++++ ElmSharp/ElmSharp.csproj | 5 +- ElmSharp/ElmSharp/Hoversel.cs | 131 ++++++++++++++++++++++++ ElmSharp/ElmSharp/HoverselItem.cs | 36 +++++++ ElmSharp/Interop/Interop.Elementary.Hoversel.cs | 67 ++++++++++++ 6 files changed, 321 insertions(+), 1 deletion(-) create mode 100755 ElmSharp.Test/TC/HoverselTest1.cs create mode 100755 ElmSharp/ElmSharp/Hoversel.cs create mode 100755 ElmSharp/ElmSharp/HoverselItem.cs create mode 100755 ElmSharp/Interop/Interop.Elementary.Hoversel.cs diff --git a/ElmSharp.Test/ElmSharp.Test.csproj b/ElmSharp.Test/ElmSharp.Test.csproj index 219b24d..ac57622 100644 --- a/ElmSharp.Test/ElmSharp.Test.csproj +++ b/ElmSharp.Test/ElmSharp.Test.csproj @@ -48,6 +48,7 @@ + diff --git a/ElmSharp.Test/TC/HoverselTest1.cs b/ElmSharp.Test/TC/HoverselTest1.cs new file mode 100755 index 0000000..01dd1ef --- /dev/null +++ b/ElmSharp.Test/TC/HoverselTest1.cs @@ -0,0 +1,82 @@ +/* + * 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 HoverselTest1 : TestCaseBase + { + public override string TestName => "HoverselTest1"; + public override string TestDescription => "To test basic operation of Hoversel"; + + public override void Run(Window window) + { + Background bg = new Background(window) + { + AlignmentX = -1, + AlignmentY = -1, + WeightX = 1, + WeightY = 1, + Color = Color.White + }; + bg.Show(); + window.AddResizeObject(bg); + + Hoversel hoversel = new Hoversel(window) + { + IsHorizontal = false, + HoverParent = window, + Text = "Hoversel" + }; + hoversel.ItemSelected += (s, e) => + { + Console.WriteLine("ItemSelected : " + e.Item.Label); + }; + + HoverselItem item1 = hoversel.AddItem("item1"); + HoverselItem item2 = hoversel.AddItem("item2"); + HoverselItem item3 = hoversel.AddItem("item3"); + + EventHandler handler = (s, e) => + { + var item = s as HoverselItem; + Console.WriteLine($"{item?.Label} is selected"); + }; + item1.ItemSelected += handler; + item2.ItemSelected += handler; + item3.ItemSelected += handler; + + hoversel.Resize(200, 100); + hoversel.Move(100, 100); + hoversel.Show(); + + Button beginButton = new Button(window) + { + Text = "Begin" + }; + beginButton.Clicked += (s, e) => + { + hoversel.HoverBegin(); + }; + beginButton.Resize(200, 100); + beginButton.Move(100, 500); + beginButton.Show(); + } + } +} diff --git a/ElmSharp/ElmSharp.csproj b/ElmSharp/ElmSharp.csproj index 4f35a2a..c135b7c 100755 --- a/ElmSharp/ElmSharp.csproj +++ b/ElmSharp/ElmSharp.csproj @@ -53,6 +53,7 @@ + @@ -82,6 +83,7 @@ + @@ -116,6 +118,7 @@ + @@ -178,4 +181,4 @@ <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory) true - + \ No newline at end of file diff --git a/ElmSharp/ElmSharp/Hoversel.cs b/ElmSharp/ElmSharp/Hoversel.cs new file mode 100755 index 0000000..cf214e9 --- /dev/null +++ b/ElmSharp/ElmSharp/Hoversel.cs @@ -0,0 +1,131 @@ +/* + * 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; + +namespace ElmSharp +{ + public class HoverselItemEventArgs : EventArgs + { + public HoverselItem Item { get; set; } + + internal static HoverselItemEventArgs CreateFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info) + { + HoverselItem item = ItemObject.GetItemByHandle(info) as HoverselItem; + return new HoverselItemEventArgs() { Item = item }; + } + } + + public class Hoversel : Layout + { + SmartEvent _selected; + Interop.Evas.SmartCallback _onItemSelected; + + public Hoversel(EvasObject parent) : base(parent) + { + _selected = new SmartEvent(this, RealHandle, "selected", HoverselItemEventArgs.CreateFromSmartEvent); + _selected.On += (s, e) => + { + if (e.Item != null) ItemSelected?.Invoke(this, e); + }; + _onItemSelected = (data, obj, info) => + { + HoverselItem item = ItemObject.GetItemById((int)data) as HoverselItem; + item?.SendItemSelected(); + }; + } + + public event EventHandler ItemSelected; + + public bool IsHorizontal + { + get + { + return Interop.Elementary.elm_hoversel_horizontal_get(RealHandle); + } + set + { + Interop.Elementary.elm_hoversel_horizontal_set(RealHandle, value); + } + } + + public IntPtr HoverParent + { + get + { + return Interop.Elementary.elm_hoversel_hover_parent_get(RealHandle); + } + set + { + Interop.Elementary.elm_hoversel_hover_parent_set(RealHandle, value); + } + } + + public bool IsExpanded + { + get + { + return Interop.Elementary.elm_hoversel_expanded_get(RealHandle); + } + } + + public bool AutoUpdate + { + get + { + return Interop.Elementary.elm_hoversel_auto_update_get(RealHandle); + } + set + { + Interop.Elementary.elm_hoversel_auto_update_set(RealHandle, value); + } + } + + public void HoverBegin() + { + Interop.Elementary.elm_hoversel_hover_begin(RealHandle); + } + + public void HoverEnd() + { + Interop.Elementary.elm_hoversel_hover_end(RealHandle); + } + + public void Clear() + { + Interop.Elementary.elm_hoversel_clear(RealHandle); + } + + public HoverselItem AddItem(string label) + { + HoverselItem item = new HoverselItem(); + item.Label = label; + item.Handle = Interop.Elementary.elm_hoversel_item_add(RealHandle, label, null, 0, _onItemSelected, (IntPtr)item.Id); + return item; + } + + protected override IntPtr CreateHandle(EvasObject parent) + { + IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle); + Interop.Elementary.elm_layout_theme_set(handle, "layout", "background", "default"); + + RealHandle = Interop.Elementary.elm_hoversel_add(handle); + Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle); + + return handle; + } + } +} diff --git a/ElmSharp/ElmSharp/HoverselItem.cs b/ElmSharp/ElmSharp/HoverselItem.cs new file mode 100755 index 0000000..de88cbc --- /dev/null +++ b/ElmSharp/ElmSharp/HoverselItem.cs @@ -0,0 +1,36 @@ +/* + * 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; + +namespace ElmSharp +{ + public class HoverselItem : ItemObject + { + internal HoverselItem() : base(IntPtr.Zero) + { + } + + public string Label { get; internal set; } + + public event EventHandler ItemSelected; + + internal void SendItemSelected() + { + ItemSelected?.Invoke(this, EventArgs.Empty); + } + } +} diff --git a/ElmSharp/Interop/Interop.Elementary.Hoversel.cs b/ElmSharp/Interop/Interop.Elementary.Hoversel.cs new file mode 100755 index 0000000..ca8cefe --- /dev/null +++ b/ElmSharp/Interop/Interop.Elementary.Hoversel.cs @@ -0,0 +1,67 @@ +/* + * 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 System.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static partial class Elementary + { + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_hoversel_add(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_hoversel_horizontal_set(IntPtr obj, bool horizontal); + + [DllImport(Libraries.Elementary)] + internal static extern bool elm_hoversel_horizontal_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_hoversel_hover_parent_set(IntPtr obj, IntPtr parent); + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_hoversel_hover_parent_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern bool elm_hoversel_expanded_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_hoversel_auto_update_set(IntPtr obj, bool auto_update); + + [DllImport(Libraries.Elementary)] + internal static extern bool elm_hoversel_auto_update_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_hoversel_hover_begin(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_hoversel_clear(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_hoversel_hover_end(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_hoversel_item_add(IntPtr obj, string label, string icon_file, int icon_type, Evas.SmartCallback func, IntPtr data); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_hoversel_item_icon_set(IntPtr obj, string icon_file, string icon_group, int icon_type); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_hoversel_item_icon_get(IntPtr obj, out string icon_file, out string icon_group, int icon_type); + } +} + -- 2.7.4