[ElmSharp] Fix TrackObject issue (#162)
authorshmin <shmin.dev@gmail.com>
Tue, 20 Mar 2018 04:31:27 +0000 (13:31 +0900)
committerarosis78 <35049857+arosis78@users.noreply.github.com>
Tue, 20 Mar 2018 04:31:27 +0000 (13:31 +0900)
src/ElmSharp/ElmSharp/ItemObject.cs
src/ElmSharp/Interop/Interop.Elementary.Item.cs
test/ElmSharp.Test/TC/ItemEvasObjectTest.cs [new file with mode: 0644]

index 6a6342c..ea16c8d 100644 (file)
@@ -81,8 +81,10 @@ namespace ElmSharp
         {
             get
             {
-                if (_trackObject == null)
+                if (_trackObject == null || Interop.Elementary.elm_object_item_track_get(Handle) == 0)
+                {
                     _trackObject = new ItemEvasObject(Handle);
+                }
                 return _trackObject;
             }
         }
@@ -392,7 +394,7 @@ namespace ElmSharp
 
         class ItemEvasObject : EvasObject
         {
-            IntPtr _parent = IntPtr.Zero;
+            IntPtr _trackHandle = IntPtr.Zero;
 
             /// <summary>
             /// Creates and initializes a new instance of the ItemEvasObject class.
@@ -400,8 +402,11 @@ namespace ElmSharp
             /// <param name="parent">IntPtr</param>
             public ItemEvasObject(IntPtr parent) : base()
             {
-                _parent = parent;
-                Realize(null);
+                _trackHandle = Interop.Elementary.elm_object_item_track(parent);
+                if (_trackHandle != IntPtr.Zero)
+                {
+                    Realize(null);
+                }
             }
 
             /// <summary>
@@ -411,7 +416,7 @@ namespace ElmSharp
             /// <returns>Handle IntPtr.</returns>
             protected override IntPtr CreateHandle(EvasObject parent)
             {
-                return Interop.Elementary.elm_object_item_track(_parent);
+                return _trackHandle;
             }
         }
     }
index c0e4f3f..88ae655 100644 (file)
@@ -85,6 +85,9 @@ internal static partial class Interop
         internal static extern IntPtr elm_object_item_track(IntPtr obj);
 
         [DllImport(Libraries.Elementary)]
+        internal static extern int elm_object_item_track_get(IntPtr obj);
+
+        [DllImport(Libraries.Elementary)]
         internal static extern void elm_object_item_untrack(IntPtr obj);
 
         [DllImport(Libraries.Elementary)]
diff --git a/test/ElmSharp.Test/TC/ItemEvasObjectTest.cs b/test/ElmSharp.Test/TC/ItemEvasObjectTest.cs
new file mode 100644 (file)
index 0000000..e485ddc
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * 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;
+
+namespace ElmSharp.Test
+{
+    class ItemEvasObjectTest : TestCaseBase
+    {
+        public override string TestName => "ItemEvasObjectTest";
+        public override string TestDescription => "To test basic operation of ItemEvasObject";
+
+        public override void Run(Window window)
+        {
+            Conformant conformant = new Conformant(window);
+            conformant.Show();
+
+            Box box = new Box(window)
+            {
+                AlignmentX = -1,
+                AlignmentY = -1,
+                WeightX = 1,
+                WeightY = 1
+            };
+            conformant.SetContent(box);
+            box.Show();
+
+            Label label = new Label(window)
+            {
+                AlignmentX = -1,
+                WeightX = 1,
+                BackgroundColor = Color.White,
+                Text = "Selected"
+            };
+
+            GenList list = new GenList(window)
+            {
+                Homogeneous = true,
+                AlignmentX = -1,
+                AlignmentY = -1,
+                WeightX = 1,
+                WeightY = 1
+            };
+
+            GenItemClass defaultClass = new GenItemClass("default")
+            {
+                GetTextHandler = (obj, part) =>
+                {
+                    return string.Format("{0} - {1}", (string)obj, part);
+                }
+            };
+
+            for (int i = 0; i < 100; i++)
+            {
+                list.Append(defaultClass, string.Format("{0} Item", i));
+            }
+            list.SelectionMode = GenItemSelectionMode.Always;
+            list.ItemSelected += (s, e) =>
+            {
+                Log.Debug((string)(e.Item.Data) + "item selected");
+                Log.Debug("Item Geometry: " + e.Item.TrackObject.Geometry.ToString());
+
+                label.Text = "selected Item Geometry: " + e.Item.TrackObject.Geometry.ToString();
+            };
+
+            label.Show();
+            list.Show();
+
+            box.PackEnd(label);
+            box.PackEnd(list);
+        }
+    }
+}