[Applications.Common / UI] Add new internal APIs (#5068)
authorhjhun <36876573+hjhun@users.noreply.github.com>
Thu, 9 Mar 2023 01:37:44 +0000 (10:37 +0900)
committerGitHub <noreply@github.com>
Thu, 9 Mar 2023 01:37:44 +0000 (10:37 +0900)
* [Applications.Common] Add new internal AppControl APIs

Adds:
 - SetWindowPosition()
 - GetWindowPosition()

Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
* [Applications.UI] Add a new internal API

Adds:
 - GetWindowPosition()

Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
---------

Signed-off-by: Hwankyu Jhun <h.jhun@samsung.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]
src/Tizen.Applications.UI/Interop/Interop.Application.cs
src/Tizen.Applications.UI/Tizen.Applications/CoreUIApplication.cs

index ee60e6e..9156ad2 100755 (executable)
@@ -154,5 +154,11 @@ internal static partial class Interop
 
         [DllImport(Libraries.AppControl, EntryPoint = "app_control_set_auto_restart")]
         internal static extern ErrorCode SetAutoRestart(SafeAppControlHandle handle);
+
+        [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 4f911a0..a8a2677 100755 (executable)
@@ -830,6 +830,63 @@ 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> 10 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        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.ScreenWidth, windowPosition.ScreenHeight);
+            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="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> 10 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        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)
+            {
+                if (err == Interop.AppControl.ErrorCode.InvalidParameter)
+                {
+                    throw new ArgumentException("Invalid arguments");
+                }
+                else
+                {
+                    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..5b5de74
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * 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> 10 </since_tizen>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    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> 10 </since_tizen>
+        public WindowPosition(int x, int y, int w, int h)
+        {
+            PositionX = x;
+            PositionY = y;
+            ScreenWidth = w;
+            ScreenHeight = h;
+        }
+
+        /// <summary>
+        /// The X position.
+        /// </summary>
+        /// <since_tizen> 10 </since_tizen>
+        public int PositionX
+        {
+            set;
+            get;
+        }
+        
+        /// <summary>
+        /// The Y position.
+        /// </summary>
+        /// <since_tizen> 10 </since_tizen>
+        public int PositionY
+        {
+            set;
+            get;
+        }
+
+        /// <summary>
+        /// The width.
+        /// </summary>
+        /// <since_tizen> 10 </since_tizen>
+        public int ScreenWidth
+        {
+            set;
+            get;
+        }
+
+        /// <summary>
+        /// The height.
+        /// </summary>
+        /// <since_tizen> 10 </since_tizen>
+        public int ScreenHeight
+        {
+            set;
+            get;
+        }
+    }
+}
index 3423151..305811e 100755 (executable)
@@ -53,6 +53,9 @@ internal static partial class Interop
         [DllImport(Libraries.Application, EntryPoint = "ui_app_remove_event_handler")]
         internal static extern ErrorCode RemoveEventHandler(IntPtr handle);
 
+        [DllImport(Libraries.Application, EntryPoint = "ui_app_get_window_position")]
+        internal static extern ErrorCode GetWindowPosition(out int x, out int y, out int w, out int h);
+
 
         [NativeStruct("ui_app_lifecycle_callback_s", Include="app.h", PkgConfig="capi-appfw-application")]
         [StructLayout(LayoutKind.Sequential)]
index d27f2cb..79b4856 100755 (executable)
  */
 
 using System;
+using System.ComponentModel;
 
 using Tizen.Applications.CoreBackend;
+using Tizen.Internals.Errors;
 
 namespace Tizen.Applications
 {
@@ -113,5 +115,23 @@ namespace Tizen.Applications
         {
             Paused?.Invoke(this, EventArgs.Empty);
         }
+
+        /// <summary>
+        /// Gets the window position of the application.
+        /// </summary>
+        /// <returns>The window position.</returns>
+        /// <exception cref="InvalidOperationException">Thrown when there is no window position.</exception>
+        /// <since_tizen> 10 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public WindowPosition GetWindowPosition()
+        {
+            ErrorCode err = Interop.Application.GetWindowPosition(out int x, out int y, out int w, out int h);
+            if (err != ErrorCode.None)
+            {
+                throw new InvalidOperationException("Failed to get window position");
+            }
+
+            return new WindowPosition(x, y, w, h);
+        }
     }
 }