From 310deba24e22affe9e4207f242d2610d2388e525 Mon Sep 17 00:00:00 2001 From: "sung-su.kim" Date: Thu, 9 Feb 2017 16:55:31 +0900 Subject: [PATCH] Add FlipSelector Change-Id: I946f39e91986680d50af8d5f0fb6490cf4b3dbff --- src/ElmSharp/ElmSharp.Net45.csproj | 5 +- src/ElmSharp/ElmSharp.csproj | 3 + src/ElmSharp/ElmSharp/FlipSelector.cs | 133 ++++++++++++++++++ src/ElmSharp/ElmSharp/FlipSelectorItem.cs | 37 +++++ .../Interop.Elementary.FlipSelector.cs | 54 +++++++ test/ElmSharp.Test/ElmSharp.Test.csproj | 3 +- test/ElmSharp.Test/TC/FlipSelectorTest.cs | 113 +++++++++++++++ 7 files changed, 346 insertions(+), 2 deletions(-) mode change 100644 => 100755 src/ElmSharp/ElmSharp.Net45.csproj create mode 100644 src/ElmSharp/ElmSharp/FlipSelector.cs create mode 100644 src/ElmSharp/ElmSharp/FlipSelectorItem.cs create mode 100644 src/ElmSharp/Interop/Interop.Elementary.FlipSelector.cs mode change 100644 => 100755 test/ElmSharp.Test/ElmSharp.Test.csproj create mode 100644 test/ElmSharp.Test/TC/FlipSelectorTest.cs diff --git a/src/ElmSharp/ElmSharp.Net45.csproj b/src/ElmSharp/ElmSharp.Net45.csproj old mode 100644 new mode 100755 index 9d53b098f..0a80aac0c --- a/src/ElmSharp/ElmSharp.Net45.csproj +++ b/src/ElmSharp/ElmSharp.Net45.csproj @@ -74,6 +74,8 @@ + + @@ -125,6 +127,7 @@ + @@ -163,4 +166,4 @@ --> - + \ No newline at end of file diff --git a/src/ElmSharp/ElmSharp.csproj b/src/ElmSharp/ElmSharp.csproj index 463f68ae1..3cef166dc 100755 --- a/src/ElmSharp/ElmSharp.csproj +++ b/src/ElmSharp/ElmSharp.csproj @@ -71,6 +71,8 @@ + + @@ -113,6 +115,7 @@ + diff --git a/src/ElmSharp/ElmSharp/FlipSelector.cs b/src/ElmSharp/ElmSharp/FlipSelector.cs new file mode 100644 index 000000000..3a58f8e23 --- /dev/null +++ b/src/ElmSharp/ElmSharp/FlipSelector.cs @@ -0,0 +1,133 @@ +/* + * 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.Collections.Generic; + +namespace ElmSharp +{ + public class FlipSelector : Layout + { + SmartEvent _selected; + SmartEvent _overflowed; + SmartEvent _underflowed; + + public FlipSelector(EvasObject parent) : base(parent) + { + _selected = new SmartEvent(this, Handle, "selected"); + _overflowed = new SmartEvent(this, Handle, "overflowed"); + _underflowed = new SmartEvent(this, Handle, "underflowed"); + + _selected.On += SelectedChanged; + _overflowed.On += OverflowedChanged; + _underflowed.On += UnderflowedChanged; + } + + public event EventHandler Selected; + public event EventHandler Overflowed; + public event EventHandler Underflowed; + + public double Interval + { + get + { + return Interop.Elementary.elm_flipselector_first_interval_get(Handle); + } + set + { + Interop.Elementary.elm_flipselector_first_interval_set(Handle, value); + } + } + + public FlipSelectorItem SelectedItem + { + get + { + IntPtr handle = Interop.Elementary.elm_flipselector_selected_item_get(Handle); + return ItemObject.GetItemByHandle(handle) as FlipSelectorItem; + } + } + + public FlipSelectorItem FirstItem + { + get + { + IntPtr handle = Interop.Elementary.elm_flipselector_first_item_get(Handle); + return ItemObject.GetItemByHandle(handle) as FlipSelectorItem; + } + } + + public FlipSelectorItem LastItem + { + get + { + IntPtr handle = Interop.Elementary.elm_flipselector_last_item_get(Handle); + return ItemObject.GetItemByHandle(handle) as FlipSelectorItem; + } + } + + public FlipSelectorItem Append(string text) + { + FlipSelectorItem item = new FlipSelectorItem(text); + item.Handle = Interop.Elementary.elm_flipselector_item_append(Handle, text, null, (IntPtr)item.Id); + return item; + } + + public FlipSelectorItem Prepend(string text) + { + FlipSelectorItem item = new FlipSelectorItem(text); + item.Handle = Interop.Elementary.elm_flipselector_item_prepend(Handle, text, null, (IntPtr)item.Id); + return item; + } + + public void Remove(FlipSelectorItem item) + { + if (item as FlipSelectorItem != null) + item.Delete(); + } + + public void Next() + { + Interop.Elementary.elm_flipselector_flip_next(Handle); + } + + public void Prev() + { + Interop.Elementary.elm_flipselector_flip_prev(Handle); + } + + protected override IntPtr CreateHandle(EvasObject parent) + { + return Interop.Elementary.elm_flipselector_add(parent.Handle); + } + + void SelectedChanged(object sender, EventArgs e) + { + SelectedItem?.SendSelected(); + Selected?.Invoke(this, EventArgs.Empty); + } + + void OverflowedChanged(object sender, EventArgs e) + { + Overflowed?.Invoke(this, e); + } + + void UnderflowedChanged(object sender, EventArgs e) + { + Underflowed?.Invoke(this, e); + } + } +} diff --git a/src/ElmSharp/ElmSharp/FlipSelectorItem.cs b/src/ElmSharp/ElmSharp/FlipSelectorItem.cs new file mode 100644 index 000000000..a957acf07 --- /dev/null +++ b/src/ElmSharp/ElmSharp/FlipSelectorItem.cs @@ -0,0 +1,37 @@ +/* + * 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 FlipSelectorItem : ItemObject + { + public string Text { get; private set; } + + public event EventHandler Selected; + + public FlipSelectorItem(string text) : base(IntPtr.Zero) + { + Text = text; + } + + internal void SendSelected() + { + Selected?.Invoke(this, EventArgs.Empty); + } + } +} diff --git a/src/ElmSharp/Interop/Interop.Elementary.FlipSelector.cs b/src/ElmSharp/Interop/Interop.Elementary.FlipSelector.cs new file mode 100644 index 000000000..976857167 --- /dev/null +++ b/src/ElmSharp/Interop/Interop.Elementary.FlipSelector.cs @@ -0,0 +1,54 @@ +/* + * 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_flipselector_add(IntPtr parent); + + [DllImport(Libraries.Elementary)] + internal static extern double elm_flipselector_first_interval_get(IntPtr flipSelector); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_flipselector_first_interval_set(IntPtr flipSelector, double interval); + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_flipselector_item_append(IntPtr flipSelector, string text, Evas.SmartCallback func, IntPtr data); + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_flipselector_item_prepend(IntPtr flipSelector, string text, Evas.SmartCallback func, IntPtr data); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_flipselector_flip_next(IntPtr flipSelector); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_flipselector_flip_prev(IntPtr flipSelector); + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_flipselector_selected_item_get(IntPtr flipSelector); + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_flipselector_first_item_get(IntPtr flipSelector); + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_flipselector_last_item_get(IntPtr flipSelector); + } +} diff --git a/test/ElmSharp.Test/ElmSharp.Test.csproj b/test/ElmSharp.Test/ElmSharp.Test.csproj old mode 100644 new mode 100755 index 78f355639..74232bd87 --- a/test/ElmSharp.Test/ElmSharp.Test.csproj +++ b/test/ElmSharp.Test/ElmSharp.Test.csproj @@ -45,6 +45,7 @@ + @@ -193,4 +194,4 @@ - + \ No newline at end of file diff --git a/test/ElmSharp.Test/TC/FlipSelectorTest.cs b/test/ElmSharp.Test/TC/FlipSelectorTest.cs new file mode 100644 index 000000000..0c2a85dce --- /dev/null +++ b/test/ElmSharp.Test/TC/FlipSelectorTest.cs @@ -0,0 +1,113 @@ +using System; +using ElmSharp; + +namespace ElmSharp.Test +{ + public class FlipSelectorTest : TestCaseBase + { + public override string TestName => "FlipSelectorTest"; + public override string TestDescription => "To test FlipSelector"; + + 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, + }; + outterBox.Show(); + + Box box = new Box(window) + { + AlignmentX = -1, + AlignmentY = -1, + WeightX = 1, + WeightY = 1, + IsHorizontal = true, + }; + box.Show(); + + FlipSelector flip = new FlipSelector(window) + { + Interval = 1.0, + }; + + flip.Append("two"); + flip.Prepend("one"); + + flip.Show(); + box.PackEnd(flip); + + conformant.SetContent(outterBox); + outterBox.PackEnd(box); + + Button prev = new Button(window) + { + AlignmentX = -1, + WeightX = 1, + Text = "Prev" + }; + prev.Clicked += (s, e) => { flip.Prev(); }; + prev.Show(); + + Button next = new Button(window) + { + AlignmentX = -1, + WeightX = 1, + Text = "next" + }; + next.Clicked += (s, e) => { flip.Next(); }; + next.Show(); + + Button prepend = new Button(window) + { + AlignmentX = -1, + WeightX = 1, + Text = "prepend" + }; + prepend.Clicked += (s, e) => { + + var random = new Random(); + int value = random.Next(99); + flip.Prepend(value.ToString()); + }; + prepend.Show(); + + Button append = new Button(window) + { + AlignmentX = -1, + WeightX = 1, + Text = "append" + }; + append.Clicked += (s, e) => { + + var random = new Random(); + int value = random.Next(99); + flip.Append(value.ToString()); + }; + append.Show(); + + Button remove = new Button(window) + { + AlignmentX = -1, + WeightX = 1, + Text = "remove" + }; + remove.Clicked += (s, e) => { flip.Remove(flip.SelectedItem); }; + remove.Show(); + + outterBox.PackEnd(box); + outterBox.PackEnd(prev); + outterBox.PackEnd(next); + outterBox.PackEnd(append); + outterBox.PackEnd(prepend); + outterBox.PackEnd(remove); + } + } +} -- 2.34.1