From: hjhun <36876573+hjhun@users.noreply.github.com> Date: Thu, 9 Mar 2023 01:37:44 +0000 (+0900) Subject: [Applications.Common / UI] Add new internal APIs (#5068) X-Git-Tag: accepted/tizen/7.0/unified/20230327.042640~1^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8b9f787e49cd6edadfcc63d73c80fc684bfa71aa;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [Applications.Common / UI] Add new internal APIs (#5068) * [Applications.Common] Add new internal AppControl APIs Adds: - SetWindowPosition() - GetWindowPosition() Signed-off-by: Hwankyu Jhun * [Applications.UI] Add a new internal API Adds: - GetWindowPosition() Signed-off-by: Hwankyu Jhun --------- Signed-off-by: Hwankyu Jhun --- diff --git a/src/Tizen.Applications.Common/Interop/Interop.AppControl.cs b/src/Tizen.Applications.Common/Interop/Interop.AppControl.cs index ee60e6e..9156ad2 100755 --- a/src/Tizen.Applications.Common/Interop/Interop.AppControl.cs +++ b/src/Tizen.Applications.Common/Interop/Interop.AppControl.cs @@ -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); } } diff --git a/src/Tizen.Applications.Common/Tizen.Applications/AppControl.cs b/src/Tizen.Applications.Common/Tizen.Applications/AppControl.cs index 4f911a0..a8a2677 100755 --- a/src/Tizen.Applications.Common/Tizen.Applications/AppControl.cs +++ b/src/Tizen.Applications.Common/Tizen.Applications/AppControl.cs @@ -830,6 +830,63 @@ namespace Tizen.Applications } /// + /// Sets the window position. + /// + /// The window position object. + /// Thrown when the argument is null. + /// Thrown when the argument is invalid. + /// Thrown when the invalid operation error occurs. + /// 10 + [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); + } + } + } + + /// + /// Gets the window position. + /// + /// The window position. + /// Thrown when the argument is null. + /// Thrown when the argument is invalid. + /// Thrown when the invalid operation error occurs. + /// 10 + [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); + } + + /// /// Class for extra data. /// /// 3 diff --git a/src/Tizen.Applications.Common/Tizen.Applications/WindowPosition.cs b/src/Tizen.Applications.Common/Tizen.Applications/WindowPosition.cs new file mode 100755 index 0000000..5b5de74 --- /dev/null +++ b/src/Tizen.Applications.Common/Tizen.Applications/WindowPosition.cs @@ -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 +{ + /// + /// Represents the window position of the application. + /// + /// 10 + [EditorBrowsable(EditorBrowsableState.Never)] + public class WindowPosition + { + /// + /// Initializes the instance of the WindowPosition class. + /// + /// The X position. + /// The Y position. + /// The width. + /// The height. + /// 10 + public WindowPosition(int x, int y, int w, int h) + { + PositionX = x; + PositionY = y; + ScreenWidth = w; + ScreenHeight = h; + } + + /// + /// The X position. + /// + /// 10 + public int PositionX + { + set; + get; + } + + /// + /// The Y position. + /// + /// 10 + public int PositionY + { + set; + get; + } + + /// + /// The width. + /// + /// 10 + public int ScreenWidth + { + set; + get; + } + + /// + /// The height. + /// + /// 10 + public int ScreenHeight + { + set; + get; + } + } +} diff --git a/src/Tizen.Applications.UI/Interop/Interop.Application.cs b/src/Tizen.Applications.UI/Interop/Interop.Application.cs index 3423151..305811e 100755 --- a/src/Tizen.Applications.UI/Interop/Interop.Application.cs +++ b/src/Tizen.Applications.UI/Interop/Interop.Application.cs @@ -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)] diff --git a/src/Tizen.Applications.UI/Tizen.Applications/CoreUIApplication.cs b/src/Tizen.Applications.UI/Tizen.Applications/CoreUIApplication.cs index d27f2cb..79b4856 100755 --- a/src/Tizen.Applications.UI/Tizen.Applications/CoreUIApplication.cs +++ b/src/Tizen.Applications.UI/Tizen.Applications/CoreUIApplication.cs @@ -15,8 +15,10 @@ */ 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); } + + /// + /// Gets the window position of the application. + /// + /// The window position. + /// Thrown when there is no window position. + /// 10 + [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); + } } }