Add BackButtonPressed/MoreButtonPressed event on EvasObject
authorSeungkeun Lee <sngn.lee@samsung.com>
Fri, 12 May 2017 06:11:46 +0000 (15:11 +0900)
committerSeungkeun Lee <sngn.lee@samsung.com>
Mon, 15 May 2017 04:57:35 +0000 (13:57 +0900)
 - Using eext_object_event_callback_add
 - It automatically routing Button event depend on Z-order

Change-Id: I29759e6cdad3d176b5f493f54400a3fd64d33b40

packaging/elm-sharp.spec
src/ElmSharp/ElmSharp.csproj
src/ElmSharp/ElmSharp/EvasObject.cs [changed mode: 0755->0644]
src/ElmSharp/Interop/Interop.Eext.Event.cs [new file with mode: 0644]
test/ElmSharp.Test/TC/PopupTest1.cs
test/ElmSharp.Test/TestRunner.cs

index 52bb918..8970287 100644 (file)
@@ -1,4 +1,4 @@
-%define DEV_VERSION beta-023
+%define DEV_VERSION beta-024
 
 Name:       elm-sharp
 Summary:    C# Binding for Elementary
index 8a90bfb..1379553 100644 (file)
@@ -51,6 +51,7 @@
     <Compile Include="ElmSharp\IAccessibleObject.cs" />
     <Compile Include="ElmSharp\ItemObjectExtension.cs" />
     <Compile Include="ElmSharp\ReadingInfoType.cs" />
+    <Compile Include="Interop\Interop.Eext.Event.cs" />
     <Compile Include="Interop\Interop.Elementary.Accessibility.cs" />
     <Compile Include="ElmSharp\Background.cs" />
     <Compile Include="ElmSharp\Box.cs" />
old mode 100755 (executable)
new mode 100644 (file)
index f885c0b..a927914
@@ -26,6 +26,11 @@ namespace ElmSharp
     public abstract class EvasObject
     {
         private IntPtr _realHandle = IntPtr.Zero;
+        private event EventHandler _backButtonPressed;
+        private event EventHandler _moreButtonPressed;
+        private Interop.Eext.EextEventCallback _backButtonHandler;
+        private Interop.Eext.EextEventCallback _moreButtonHandler;
+
         internal IntPtr Handle { get; set; }
         internal EvasObject Parent { get; set; }
         internal IntPtr RealHandle
@@ -65,6 +70,9 @@ namespace ElmSharp
         /// </summary>
         protected EvasObject()
         {
+            _backButtonHandler = new Interop.Eext.EextEventCallback((d, o, i) => { _backButtonPressed?.Invoke(this, EventArgs.Empty); });
+            _moreButtonHandler = new Interop.Eext.EextEventCallback((d, o, i) => { _moreButtonPressed?.Invoke(this, EventArgs.Empty); });
+
             OnInstantiated();
         }
 
@@ -88,6 +96,54 @@ namespace ElmSharp
         /// KeyDown will be triggered when key is preesd down
         /// </summary>
         public event EventHandler<EvasKeyEventArgs> KeyDown;
+
+        /// <summary>
+        /// BackButtonPressed will be triggered when Back button is pressed
+        /// </summary>
+        public event EventHandler BackButtonPressed
+        {
+            add
+            {
+                if (_backButtonPressed == null)
+                {
+                    Interop.Eext.eext_object_event_callback_add(RealHandle, Interop.Eext.EextCallbackType.EEXT_CALLBACK_BACK, _backButtonHandler, IntPtr.Zero);
+                }
+                _backButtonPressed += value;
+            }
+            remove
+            {
+                _backButtonPressed -= value;
+                if (_backButtonPressed == null)
+                {
+                    Interop.Eext.eext_object_event_callback_del(RealHandle, Interop.Eext.EextCallbackType.EEXT_CALLBACK_BACK, _backButtonHandler);
+                }
+            }
+        }
+
+        /// <summary>
+        /// MoreButtonPressed will be triggered when More button is pressed
+        /// </summary>
+        public event EventHandler MoreButtonPressed
+        {
+            add
+            {
+                if (_moreButtonPressed == null)
+                {
+                    Interop.Eext.eext_object_event_callback_add(RealHandle, Interop.Eext.EextCallbackType.EEXT_CALLBACK_MORE, _moreButtonHandler, IntPtr.Zero);
+                }
+                _moreButtonPressed += value;
+            }
+            remove
+            {
+                _moreButtonPressed -= value;
+                if (_moreButtonPressed == null)
+                {
+                    Interop.Eext.eext_object_event_callback_del(RealHandle, Interop.Eext.EextCallbackType.EEXT_CALLBACK_MORE, _moreButtonHandler);
+                }
+            }
+        }
+
+
         /// <summary>
         /// Moved will be triggered when widght is moved
         /// </summary>
diff --git a/src/ElmSharp/Interop/Interop.Eext.Event.cs b/src/ElmSharp/Interop/Interop.Eext.Event.cs
new file mode 100644 (file)
index 0000000..02420dc
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2017 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 Eext
+    {
+        public enum EextCallbackType
+        {
+            EEXT_CALLBACK_BACK, // H/W Back Key Event
+            EEXT_CALLBACK_MORE,  // H/W More Key Event
+        }
+        internal delegate void EextEventCallback(IntPtr data, IntPtr obj, IntPtr info);
+
+        [DllImport(Libraries.Eext)]
+        internal static extern void eext_object_event_callback_add(IntPtr obj, EextCallbackType type, EextEventCallback callback, IntPtr data);
+
+
+        [DllImport(Libraries.Eext)]
+        internal static extern void eext_object_event_callback_del(IntPtr obj, EextCallbackType type, EextEventCallback callback);
+    }
+}
index c3e0a5d..90eda9c 100644 (file)
@@ -62,13 +62,18 @@ namespace ElmSharp.Test
             popup.TimedOut += (s, e) =>
             {
                 Console.WriteLine("Popup time out");
-                popup.Show();
             };
 
             popup.Append("Label1");
             popup.Append("Label2");
             popup.Append("Label3");
 
+            popup.BackButtonPressed += (s, e) =>
+            {
+                Console.WriteLine("!!! BackButtonPressed Event on Popup!!");
+                popup.Hide();
+            };
+
             btn.Clicked += (s, e) =>
             {
                 popup.Show();
index ebdab32..3ee156b 100644 (file)
@@ -107,27 +107,19 @@ namespace ElmSharp.Test
             window.Show();
             if (isSecond)
             {
-                window.KeyGrab(EvasKeyEventArgs.PlatformBackButtonName, true);
-                window.KeyUp += (s, e) =>
+                window.BackButtonPressed += (s, e) =>
                 {
-                    if (e.KeyName == EvasKeyEventArgs.PlatformBackButtonName)
-                    {
-                        window.Hide();
-                        window.Unrealize();
-                        GC.Collect();
-                        GC.WaitForPendingFinalizers();
-                    }
+                    window.Hide();
+                    window.Unrealize();
+                    GC.Collect();
+                    GC.WaitForPendingFinalizers();
                 };
             }
             else
             {
-                window.KeyGrab(EvasKeyEventArgs.PlatformBackButtonName, false);
-                window.KeyUp += (s, e) =>
+                window.BackButtonPressed += (s, e) =>
                 {
-                    if (e.KeyName == EvasKeyEventArgs.PlatformBackButtonName)
-                    {
-                        UIExit();
-                    }
+                    UIExit();
                 };
             }
             return window;
@@ -147,7 +139,10 @@ namespace ElmSharp.Test
                 WeightY = 1,
             };
             box.Show();
-            conformant.SetContent(box);
+            var bg = new Background(_firstPageWindow);
+            bg.Color = Color.White;
+            bg.SetContent(box);
+            conformant.SetContent(bg);
 
             GenList list = new GenList(_firstPageWindow)
             {