[Applications] Add Set/Get window position api for AppControl (#5084)
authorsukhyungkang <35091460+sukhyungkang@users.noreply.github.com>
Mon, 17 Apr 2023 07:55:47 +0000 (16:55 +0900)
committerGitHub <noreply@github.com>
Mon, 17 Apr 2023 07:55:47 +0000 (16:55 +0900)
Signed-off-by: SukhyungKang <shine.kang@samsung.com>
Co-authored-by: hjhun <36876573+hjhun@users.noreply.github.com>
src/Tizen.Applications.Common/Interop/Interop.AppControl.cs
src/Tizen.Applications.Common/Tizen.Applications/AppControl.cs
src/Tizen.Applications.Common/Tizen.Applications/WindowPosition.cs [new file with mode: 0755]

index 2ec3d9b..c0dbfaa 100755 (executable)
@@ -164,5 +164,10 @@ internal static partial class Interop
         [DllImport(Libraries.AppControl, EntryPoint = "app_control_foreach_default_application")]
         internal static extern ErrorCode ForeachDefaultApplication(DefaultApplicationCallback callback, IntPtr userData);
 
+        [DllImport(Libraries.AppControl, EntryPoint = "app_control_set_window_position")]
+        internal static extern ErrorCode SetWindowPosition(SafeAppControlHandle handle, int x, int y, int w, int h);
+
+        [DllImport(Libraries.AppControl, EntryPoint = "app_control_get_window_position")]
+        internal static extern ErrorCode GetWindowPosition(SafeAppControlHandle handle, out int x, out int y, out int w, out int h);
     }
 }
index c134061..da9bbc2 100755 (executable)
@@ -985,6 +985,52 @@ namespace Tizen.Applications
         }
 
         /// <summary>
+        /// Sets the window position.
+        /// </summary>
+        /// <param name="windowPosition">The window position object.</param>
+        /// <exception cref="ArgumentNullException">Thrown when the argument is null.</exception>
+        /// <exception cref="ArgumentException">Thrown when the argument is invalid.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the invalid operation error occurs.</exception>
+        /// <since_tizen> 11 </since_tizen>
+        public void SetWindowPosition(WindowPosition windowPosition)
+        {
+            if (windowPosition == null)
+            {
+                throw new ArgumentNullException(nameof(windowPosition));
+            }
+
+            Interop.AppControl.ErrorCode err = Interop.AppControl.SetWindowPosition(this.SafeAppControlHandle, windowPosition.PositionX, windowPosition.PositionY, windowPosition.Width, windowPosition.Height);
+            if (err != Interop.AppControl.ErrorCode.None)
+            {
+                if (err == Interop.AppControl.ErrorCode.InvalidParameter)
+                {
+                    throw new ArgumentException("Invalid arguments");
+                }
+                else
+                {
+                    throw new InvalidOperationException("err = " + err);
+                }
+            }
+        }
+
+        /// <summary>
+        /// Gets the window position.
+        /// </summary>
+        /// <returns>The window position.</returns>
+        /// <exception cref="InvalidOperationException">Thrown when the invalid operation error occurs.</exception>
+        /// <since_tizen> 11 </since_tizen>
+        public WindowPosition GetWindowPosition()
+        {
+            Interop.AppControl.ErrorCode err = Interop.AppControl.GetWindowPosition(this.SafeAppControlHandle, out int x, out int y, out int w, out int h);
+            if (err != Interop.AppControl.ErrorCode.None)
+            {
+                throw new InvalidOperationException("err = " + err);
+            }
+
+            return new WindowPosition(x, y, w, h);
+        }
+
+        /// <summary>
         /// Class for extra data.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
diff --git a/src/Tizen.Applications.Common/Tizen.Applications/WindowPosition.cs b/src/Tizen.Applications.Common/Tizen.Applications/WindowPosition.cs
new file mode 100755 (executable)
index 0000000..be56e5f
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2023 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.ComponentModel;
+
+namespace Tizen.Applications
+{
+    /// <summary>
+    /// Represents the window position of the application.
+    /// </summary>
+    /// <since_tizen> 11 </since_tizen>
+    public class WindowPosition
+    {
+        /// <summary>
+        /// Initializes the instance of the WindowPosition class.
+        /// </summary>
+        /// <param name="x">The X position.</param>
+        /// <param name="y">The Y position.</param>
+        /// <param name="w">The width.</param>
+        /// <param name="h">The height.</param>
+        /// <since_tizen> 11 </since_tizen>
+        public WindowPosition(int x, int y, int w, int h)
+        {
+            PositionX = x;
+            PositionY = y;
+            Width = w;
+            Height = h;
+        }
+
+        /// <summary>
+        /// The X position.
+        /// </summary>
+        /// <since_tizen> 11 </since_tizen>
+        public int PositionX
+        {
+            set;
+            get;
+        }
+        
+        /// <summary>
+        /// The Y position.
+        /// </summary>
+        /// <since_tizen> 11 </since_tizen>
+        public int PositionY
+        {
+            set;
+            get;
+        }
+
+        /// <summary>
+        /// The width.
+        /// </summary>
+        /// <since_tizen> 11 </since_tizen>
+        public int Width
+        {
+            set;
+            get;
+        }
+
+        /// <summary>
+        /// The height.
+        /// </summary>
+        /// <since_tizen> 11 </since_tizen>
+        public int Height
+        {
+            set;
+            get;
+        }
+    }
+}