diff options
author | Jeonghyun Yun <jh0506.yun@samsung.com> | 2017-03-14 03:02:18 -0700 |
---|---|---|
committer | Gerrit Code Review <gerrit@review.vlan103.tizen.org> | 2017-03-14 03:02:18 -0700 |
commit | 040a3cea831cfa9455b287ef8f545107955e75f6 (patch) | |
tree | 1b8c4442d9dd208a755e4ff9afc2c687c6fab124 | |
parent | 7b810d170200f0a3671f4b3b659afeeb398c1be0 (diff) | |
parent | 12a9516763b6a535eca259b4c73e91a226ab47e6 (diff) | |
download | elm-sharp-040a3cea831cfa9455b287ef8f545107955e75f6.tar.gz elm-sharp-040a3cea831cfa9455b287ef8f545107955e75f6.tar.bz2 elm-sharp-040a3cea831cfa9455b287ef8f545107955e75f6.zip |
Merge "Add MultiButtonEntry" into tizen
-rw-r--r-- | ElmSharp.Test/ElmSharp.Test.csproj | 1 | ||||
-rw-r--r-- | ElmSharp.Test/TC/MultibuttonEntryTest1.cs | 119 | ||||
-rwxr-xr-x | ElmSharp/ElmSharp.csproj | 3 | ||||
-rw-r--r-- | ElmSharp/ElmSharp/MultiButtonEntry.cs | 247 | ||||
-rw-r--r-- | ElmSharp/ElmSharp/MultiButtonEntryItem.cs | 65 | ||||
-rw-r--r-- | ElmSharp/Interop/Interop.Elementary.MultiButtonEntry.cs | 92 |
6 files changed, 527 insertions, 0 deletions
diff --git a/ElmSharp.Test/ElmSharp.Test.csproj b/ElmSharp.Test/ElmSharp.Test.csproj index 55aec94..01e4434 100644 --- a/ElmSharp.Test/ElmSharp.Test.csproj +++ b/ElmSharp.Test/ElmSharp.Test.csproj @@ -43,6 +43,7 @@ <Compile Include="TC\BackgroundTest1.cs" /> <Compile Include="TC\BackgroundTest2.cs" /> <Compile Include="TC\BackgroundTest3.cs" /> + <Compile Include="TC\MultibuttonEntryTest1.cs" /> <Compile Include="TC\DateTimeSelectorTest2.cs" /> <Compile Include="TC\EntryTest2.cs" /> <Compile Include="TC\FlipSelectorTest.cs" /> diff --git a/ElmSharp.Test/TC/MultibuttonEntryTest1.cs b/ElmSharp.Test/TC/MultibuttonEntryTest1.cs new file mode 100644 index 0000000..b27f0d2 --- /dev/null +++ b/ElmSharp.Test/TC/MultibuttonEntryTest1.cs @@ -0,0 +1,119 @@ +/* + * 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; +using ElmSharp; + +namespace ElmSharp.Test +{ + class MultiButtonEntryTest1 : TestCaseBase + { + public override string TestName => "MultiButtonEntryTest1"; + public override string TestDescription => "To test basic operation of MultiButtonEntry"; + + public override void Run(Window window) + { + Background bg = new Background(window); + bg.Color = Color.White; + bg.Move(0, 0); + bg.Resize(window.ScreenSize.Width, window.ScreenSize.Height); + bg.Show(); + + MultiButtonEntry mbe = new MultiButtonEntry(window) + { + IsEditable = true, + IsExpanded = true, + Text = "To: " + }; + + var test = mbe.Append("test"); + mbe.Prepend("prepend"); + mbe.Append("append"); + mbe.InsertBefore(test, "insertBefore"); + mbe.InsertAfter(test, "insertAfter"); + + mbe.ItemSelected += (s, e) => + { + Console.WriteLine("item selected: " + e.Item.Label); + if (e.Item.Next != null) + Console.WriteLine("next item: " + e.Item.Next); + if (e.Item.Prev != null) + Console.WriteLine("next item: " + e.Item.Prev); + }; + + mbe.ItemClicked += (s, e) => + { + Console.WriteLine("item clicked: " + e.Item.Label); + }; + + mbe.ItemLongPressed += (s, e) => + { + Console.WriteLine("item longpressed: " + e.Item.Label); + }; + + mbe.ItemAdded += (s, e) => + { + Console.WriteLine("item added: " + e.Item.Label); + }; + + mbe.ItemDeleted += (s, e) => + { + Console.WriteLine("item deleted: " + e.Item.Label); + }; + + mbe.AppendFilter((label) => + { + if (label.Contains("a")) + { + Console.WriteLine("appended filter : Item has 'a', It won't be added until 'a' is removed."); + return false; + } + else + { + return true; + } + }); + + mbe.PrependFilter((label) => + { + if (label.Contains("p")) + { + Console.WriteLine("prepended filter : Item has 'p', It won't be added until 'p' is removed."); + return false; + } + else + { + return true; + } + }); + + Label label1 = new Label(window) + { + Text = "MultiButtonEntry Test", + Color = Color.Blue + }; + + label1.Resize(600, 100); + label1.Move(50, 50); + label1.Show(); + + mbe.Resize(600, 600); + mbe.Move(0, 100); + mbe.Show(); + } + } +}
\ No newline at end of file diff --git a/ElmSharp/ElmSharp.csproj b/ElmSharp/ElmSharp.csproj index 2b2261d..56d3785 100755 --- a/ElmSharp/ElmSharp.csproj +++ b/ElmSharp/ElmSharp.csproj @@ -56,6 +56,8 @@ <Compile Include="ElmSharp\HoverselItem.cs" /> <Compile Include="ElmSharp\Conformant.cs" /> <Compile Include="ElmSharp\Container.cs" /> + <Compile Include="ElmSharp\MultiButtonEntryItem.cs" /> + <Compile Include="ElmSharp\MultiButtonEntry.cs" /> <Compile Include="ElmSharp\ContextPopup.cs" /> <Compile Include="ElmSharp\ColorSelectorItem.cs" /> <Compile Include="ElmSharp\ContextPopupItem.cs" /> @@ -121,6 +123,7 @@ <Compile Include="Interop\Interop.Eina.cs" /> <Compile Include="Interop\Interop.Elementary.Hoversel.cs" /> <Compile Include="Interop\Interop.Elementary.FlipSelector.cs" /> + <Compile Include="Interop\Interop.Elementary.MultiButtonEntry.cs" /> <Compile Include="Interop\Interop.Eo.cs" /> <Compile Include="Interop\Interop.Ecore.cs" /> <Compile Include="Interop\Interop.Elementary.Bg.cs" /> diff --git a/ElmSharp/ElmSharp/MultiButtonEntry.cs b/ElmSharp/ElmSharp/MultiButtonEntry.cs new file mode 100644 index 0000000..dc377b8 --- /dev/null +++ b/ElmSharp/ElmSharp/MultiButtonEntry.cs @@ -0,0 +1,247 @@ +/* + * 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 MultiButtonEntry : Layout + { + HashSet<MultiButtonEntryItem> _children = new HashSet<MultiButtonEntryItem>(); + List<Func<string, bool>> _filters = new List<Func<string, bool>>(); + + Interop.Elementary.MultiButtonEntryItemFilterCallback _filtercallback; + + SmartEvent _clicked; + SmartEvent _expanded; + SmartEvent _contracted; + SmartEvent _expandedStateChanged; + SmartEvent<MultiButtonEntryArgs> _itemSelected; + SmartEvent<MultiButtonEntryArgs> _itemClicked; + SmartEvent<MultiButtonEntryArgs> _itemLongPressed; + SmartEvent<MultiButtonEntryArgs> _itemAdded; + + public MultiButtonEntry(EvasObject parent) : base(parent) + { + _clicked = new SmartEvent(this, "clicked"); + _expanded = new SmartEvent(this, "expanded"); + _contracted = new SmartEvent(this, "contracted"); + _expandedStateChanged = new SmartEvent(this, "expand,state,changed"); + + _itemSelected = new SmartEvent<MultiButtonEntryArgs>(this, "item,selected", MultiButtonEntryArgs.CreateFromSmartEvent); + _itemClicked = new SmartEvent<MultiButtonEntryArgs>(this, "item,clicked", MultiButtonEntryArgs.CreateFromSmartEvent); + _itemLongPressed = new SmartEvent<MultiButtonEntryArgs>(this, "item,longpressed", MultiButtonEntryArgs.CreateFromSmartEvent); + _itemAdded = new SmartEvent<MultiButtonEntryArgs>(this, "item,added", MultiButtonEntryArgs.CreateAndAddFromSmartEvent); + + _filtercallback = new Interop.Elementary.MultiButtonEntryItemFilterCallback(FilterCallbackHandler); + + _clicked.On += (sender, e) => Clicked?.Invoke(this, EventArgs.Empty); + _expanded.On += (sender, e) => Expanded?.Invoke(this, EventArgs.Empty); + _contracted.On += (sender, e) => Contracted?.Invoke(this, EventArgs.Empty); + _expandedStateChanged.On += (sender, e) => ExpandedStateChanged?.Invoke(this, EventArgs.Empty); + + _itemSelected.On += (sender, e) => { ItemSelected?.Invoke(this, e); }; + _itemClicked.On += (sender, e) => { ItemClicked?.Invoke(this, e); }; + _itemLongPressed.On += (sender, e) => { ItemLongPressed?.Invoke(this, e); }; + _itemAdded.On += OnItemAdded; + } + + public event EventHandler Clicked; + + public event EventHandler Expanded; + + public event EventHandler Contracted; + + public event EventHandler ExpandedStateChanged; + + public event EventHandler<MultiButtonEntryArgs> ItemSelected; + + public event EventHandler<MultiButtonEntryArgs> ItemClicked; + + public event EventHandler<MultiButtonEntryArgs> ItemLongPressed; + + public event EventHandler<MultiButtonEntryArgs> ItemAdded; + + public event EventHandler<MultiButtonEntryArgs> ItemDeleted; + + public MultiButtonEntryItem SelectedItem + { + get + { + IntPtr handle = Interop.Elementary.elm_multibuttonentry_selected_item_get(Handle); + return ItemObject.GetItemByHandle(handle) as MultiButtonEntryItem; + } + } + + public bool IsEditable + { + get + { + return Interop.Elementary.elm_multibuttonentry_editable_get(Handle); + } + set + { + Interop.Elementary.elm_multibuttonentry_editable_set(Handle, value); + } + } + + public bool IsExpanded + { + get + { + return Interop.Elementary.elm_multibuttonentry_expanded_get(Handle); + } + set + { + Interop.Elementary.elm_multibuttonentry_expanded_set(Handle, value); + } + } + + public MultiButtonEntryItem FirstItem + { + get + { + IntPtr handle = Interop.Elementary.elm_multibuttonentry_first_item_get(Handle); + return ItemObject.GetItemByHandle(handle) as MultiButtonEntryItem; + } + } + + public MultiButtonEntryItem LastItem + { + get + { + IntPtr handle = Interop.Elementary.elm_multibuttonentry_last_item_get(Handle); + return ItemObject.GetItemByHandle(handle) as MultiButtonEntryItem; + } + } + + protected override IntPtr CreateHandle(EvasObject parent) + { + return Interop.Elementary.elm_multibuttonentry_add(parent.Handle); + } + + public MultiButtonEntryItem Append(string label) + { + var handle = Interop.Elementary.elm_multibuttonentry_item_append(Handle, label, null, IntPtr.Zero); + MultiButtonEntryItem item = ItemObject.GetItemByHandle(handle) as MultiButtonEntryItem; + return item; + } + + public MultiButtonEntryItem Prepend(string label) + { + var handle = Interop.Elementary.elm_multibuttonentry_item_prepend(Handle, label, null, IntPtr.Zero); + MultiButtonEntryItem item = ItemObject.GetItemByHandle(handle) as MultiButtonEntryItem; + return item; + } + + public MultiButtonEntryItem InsertBefore(MultiButtonEntryItem before, string label) + { + var handle = Interop.Elementary.elm_multibuttonentry_item_insert_before(Handle, before.Handle, label, null, IntPtr.Zero); + MultiButtonEntryItem item = ItemObject.GetItemByHandle(handle) as MultiButtonEntryItem; + return item; + } + + public MultiButtonEntryItem InsertAfter(MultiButtonEntryItem after, string label) + { + var handle = Interop.Elementary.elm_multibuttonentry_item_insert_after(Handle, after.Handle, label, null, IntPtr.Zero); + MultiButtonEntryItem item = ItemObject.GetItemByHandle(handle) as MultiButtonEntryItem; + return item; + } + + public void Clear() + { + Interop.Elementary.elm_multibuttonentry_clear(Handle); + _children.Clear(); + } + + public void AppendFilter(Func<string, bool> func) + { + _filters.Add(func); + if (_filters.Count == 1) + { + Interop.Elementary.elm_multibuttonentry_item_filter_append(Handle, _filtercallback, IntPtr.Zero); + } + } + + public void PrependFilter(Func<string, bool> func) + { + _filters.Insert(0, func); + if (_filters.Count == 1) + { + Interop.Elementary.elm_multibuttonentry_item_filter_prepend(Handle, _filtercallback, IntPtr.Zero); + } + } + + public void RemoveFilter(Func<string, bool> func) + { + _filters.Remove(func); + if (_filters.Count == 0) + { + Interop.Elementary.elm_multibuttonentry_item_filter_remove(Handle, _filtercallback, IntPtr.Zero); + } + } + + void Item_Deleted(object sender, EventArgs e) + { + var removed = sender as MultiButtonEntryItem; + _children.Remove(removed); + + // "item,deleted" event will be called after removing the item from ItemObject has been done. + // ItemObject will no longer have the item instance that is deleted after this. + // So, ItemDelete event with the removed item should be triggered here. + ItemDeleted?.Invoke(this, new MultiButtonEntryArgs() { Item = removed }); + } + + void OnItemAdded(object sender, MultiButtonEntryArgs e) + { + _children.Add(e.Item); + e.Item.Deleted += Item_Deleted; + ItemAdded?.Invoke(this, e); + } + + bool FilterCallbackHandler(IntPtr obj, string label, IntPtr itemData, IntPtr data) + { + foreach (var func in _filters) + { + if (!func(label)) + return false; + } + return true; + } + } + + public class MultiButtonEntryArgs : EventArgs + { + public MultiButtonEntryItem Item { get; set; } + + internal static MultiButtonEntryArgs CreateFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info) + { + MultiButtonEntryItem item = ItemObject.GetItemByHandle(info) as MultiButtonEntryItem; + return new MultiButtonEntryArgs() { Item = item }; + } + + internal static MultiButtonEntryArgs CreateAndAddFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info) + { + // Item can be added throught calling Append method and user input. + // And since "item.added" event will be called before xx_append() method returns, + // ItemObject does NOT have an item that contains handle matched to "info" at this time. + // So, item should be created and added internally here. + MultiButtonEntryItem item = new MultiButtonEntryItem(info); + return new MultiButtonEntryArgs() { Item = item }; + } + } +}
\ No newline at end of file diff --git a/ElmSharp/ElmSharp/MultiButtonEntryItem.cs b/ElmSharp/ElmSharp/MultiButtonEntryItem.cs new file mode 100644 index 0000000..2cce78e --- /dev/null +++ b/ElmSharp/ElmSharp/MultiButtonEntryItem.cs @@ -0,0 +1,65 @@ +/* + * 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 MultiButtonEntryItem : ItemObject + { + public MultiButtonEntryItem(string text) : base(IntPtr.Zero) + { + Label = text; + } + + internal MultiButtonEntryItem(IntPtr handle) : base(handle) + { + Label = Interop.Elementary.elm_object_item_part_text_get(handle, null); + } + + public string Label { get; private set; } + + public bool IsSelected + { + get + { + return Interop.Elementary.elm_multibuttonentry_item_selected_get(Handle); + } + set + { + Interop.Elementary.elm_multibuttonentry_item_selected_set(Handle, value); + } + } + + public MultiButtonEntryItem Next + { + get + { + var next = Interop.Elementary.elm_multibuttonentry_item_next_get(Handle); + return ItemObject.GetItemByHandle(next) as MultiButtonEntryItem; + } + } + + public MultiButtonEntryItem Prev + { + get + { + var prev = Interop.Elementary.elm_multibuttonentry_item_prev_get(Handle); + return ItemObject.GetItemByHandle(prev) as MultiButtonEntryItem; + } + } + } +}
\ No newline at end of file diff --git a/ElmSharp/Interop/Interop.Elementary.MultiButtonEntry.cs b/ElmSharp/Interop/Interop.Elementary.MultiButtonEntry.cs new file mode 100644 index 0000000..cf9e0db --- /dev/null +++ b/ElmSharp/Interop/Interop.Elementary.MultiButtonEntry.cs @@ -0,0 +1,92 @@ +/* + * 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 + { + public delegate bool MultiButtonEntryItemFilterCallback(IntPtr obj, string label, IntPtr itemData, IntPtr data); + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_multibuttonentry_add(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_multibuttonentry_entry_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern bool elm_multibuttonentry_expanded_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_multibuttonentry_expanded_set(IntPtr obj, bool expanded); + + [DllImport(Libraries.Elementary)] + internal static extern bool elm_multibuttonentry_editable_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_multibuttonentry_editable_set(IntPtr obj, bool editable); + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_multibuttonentry_item_prepend(IntPtr obj, string label, Evas.SmartCallback func, IntPtr data); + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_multibuttonentry_item_append(IntPtr obj, string label, Evas.SmartCallback func, IntPtr data); + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_multibuttonentry_item_insert_before(IntPtr obj, IntPtr before, string label, Evas.SmartCallback func, IntPtr data); + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_multibuttonentry_item_insert_after(IntPtr obj, IntPtr after, string label, Evas.SmartCallback func, IntPtr data); + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_multibuttonentry_items_get(IntPtr obj); //return list + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_multibuttonentry_first_item_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_multibuttonentry_last_item_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_multibuttonentry_selected_item_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_multibuttonentry_item_selected_set(IntPtr obj, bool selected); + + [DllImport(Libraries.Elementary)] + internal static extern bool elm_multibuttonentry_item_selected_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_multibuttonentry_clear(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_multibuttonentry_item_prev_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern IntPtr elm_multibuttonentry_item_next_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_multibuttonentry_item_filter_append(IntPtr obj, MultiButtonEntryItemFilterCallback callback, IntPtr data); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_multibuttonentry_item_filter_prepend(IntPtr obj, MultiButtonEntryItemFilterCallback callback, IntPtr data); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_multibuttonentry_item_filter_remove(IntPtr obj, MultiButtonEntryItemFilterCallback callback, IntPtr data); + } +}
\ No newline at end of file |