Procházet zdrojové kódy

Added Position property, moved Hide/Show to ITopLevelImpl

Nikita Tsukanov před 10 roky
rodič
revize
84af63ce1e

+ 2 - 0
src/Android/Perspex.Android/Platform/SkiaPlatform/WindowImpl.cs

@@ -137,6 +137,8 @@ namespace Perspex.Android.Platform.SkiaPlatform
             //Not supported
         }
 
+        public Point Position { get; set; }
+
         public IDisposable ShowDialog()
         {
             throw new NotImplementedException();

+ 0 - 5
src/Gtk/Perspex.Gtk/PopupImpl.cs

@@ -12,10 +12,5 @@ namespace Perspex.Gtk
             : base(WindowType.Popup)
         {
         }
-
-        public void SetPosition(Point p)
-        {
-            Move((int)p.X, (int)p.Y);
-        }
     }
 }

+ 14 - 0
src/Gtk/Perspex.Gtk/WindowImpl.cs

@@ -179,6 +179,20 @@ namespace Perspex.Gtk
             BeginResizeDrag((Gdk.WindowEdge) (int) edge, 1, x, y, 0);
         }
 
+        public Point Position
+        {
+            get
+            {
+                int x, y;
+                GetPosition(out x, out y);
+                return new Point(x, y);
+            }
+            set
+            {
+                Move((int)value.X, (int)value.Y);
+            }
+        }
+
         public IDisposable ShowDialog()
         {
             Modal = true;

+ 0 - 9
src/Perspex.Controls/Platform/IPopupImpl.cs

@@ -8,15 +8,6 @@ namespace Perspex.Platform
     /// </summary>
     public interface IPopupImpl : ITopLevelImpl
     {
-        /// <summary>
-        /// Sets the position of the popup.
-        /// </summary>
-        /// <param name="p">The position, in screen coordinates.</param>
-        void SetPosition(Point p);
 
-        /// <summary>
-        /// Hides the popup.
-        /// </summary>
-        void Hide();
     }
 }

+ 7 - 0
src/Perspex.Controls/Platform/ITopLevelImpl.cs

@@ -89,6 +89,11 @@ namespace Perspex.Platform
         /// Shows the toplevel.
         /// </summary>
         void Show();
+        
+        /// <summary>
+        /// Hides the window.
+        /// </summary>
+        void Hide();
 
         /// <summary>
         /// Starts moving a window with left button being held. Should be called from left mouse button press event handler.
@@ -100,5 +105,7 @@ namespace Perspex.Platform
         /// Should be called from left mouse button press event handler
         /// </summary>
         void BeginResizeDrag(WindowEdge edge);
+
+        Point Position { get; set; }
     }
 }

+ 0 - 5
src/Perspex.Controls/Platform/IWindowImpl.cs

@@ -29,11 +29,6 @@ namespace Perspex.Platform
         /// </returns>
         IDisposable ShowDialog();
 
-        /// <summary>
-        /// Hides the window.
-        /// </summary>
-        void Hide();
-
         /// <summary>
         /// Enables of disables system window decorations (title bar, buttons, etc)
         /// </summary>

+ 6 - 5
src/Perspex.Controls/Platform/PlatformManager.cs

@@ -155,11 +155,6 @@ namespace Perspex.Controls.Platform
                 set { _tl.Deactivated = value; }
             }
 
-            public void SetPosition(Point p)
-            {
-                _popup.SetPosition(p*ScalingFactor);
-            }
-            
             public void Dispose() => _tl.Dispose();
 
             public IPlatformHandle Handle => _tl.Handle;
@@ -177,6 +172,12 @@ namespace Perspex.Controls.Platform
             public void BeginMoveDrag() => _tl.BeginMoveDrag();
             public void BeginResizeDrag(WindowEdge edge) => _tl.BeginResizeDrag(edge);
 
+            public Point Position
+            {
+                get { return _tl.Position; }
+                set { _tl.Position = value; }
+            }
+
             public IDisposable ShowDialog() => _window.ShowDialog();
 
             public void Hide() => _popup.Hide();

+ 1 - 1
src/Perspex.Controls/Primitives/Popup.cs

@@ -169,7 +169,7 @@ namespace Perspex.Controls.Primitives
                 ((ISetLogicalParent)_popupRoot).SetParent(this);
             }
 
-            _popupRoot.SetPosition(GetPosition());
+            _popupRoot.Position = GetPosition();
             _popupRoot.AddHandler(PointerPressedEvent, MaybeClose, RoutingStrategies.Bubble, true);
 
             if (_topLevel != null)

+ 0 - 9
src/Perspex.Controls/Primitives/PopupRoot.cs

@@ -65,15 +65,6 @@ namespace Perspex.Controls.Primitives
         /// </summary>
         IVisual IHostedVisualTreeRoot.Host => Parent;
 
-        /// <summary>
-        /// Sets the position of the popup in screen coordinates.
-        /// </summary>
-        /// <param name="p">The position.</param>
-        public void SetPosition(Point p)
-        {
-            PlatformImpl.SetPosition(p);
-        }
-
         /// <summary>
         /// Hides the popup.
         /// </summary>

+ 1 - 1
src/Perspex.Controls/ToolTip.cs

@@ -118,7 +118,7 @@ namespace Perspex.Controls
                 var position = control.PointToScreen(cp ?? new Point(0, 0)) + new Vector(0, 22);
 
                 ((ToolTip)s_popup.Content).Content = GetTip(control);
-                s_popup.SetPosition(position);
+                s_popup.Position = position;
                 s_popup.Show();
 
                 s_current = control;

+ 6 - 0
src/Perspex.Controls/TopLevel.cs

@@ -375,5 +375,11 @@ namespace Perspex.Controls
         /// Should be called from left mouse button press event handler
         /// </summary>
         public void BeginResizeDrag(WindowEdge edge) => PlatformImpl.BeginResizeDrag(edge);
+
+        public Point Position
+        {
+            get { return PlatformImpl.Position; }
+            set { PlatformImpl.Position = value; }
+        }
     }
 }

+ 0 - 12
src/Windows/Perspex.Win32/PopupImpl.cs

@@ -9,18 +9,6 @@ namespace Perspex.Win32
 {
     public class PopupImpl : WindowImpl, IPopupImpl
     {
-        public void SetPosition(Point p)
-        {
-            UnmanagedMethods.SetWindowPos(
-                Handle.Handle,
-                IntPtr.Zero,
-                (int)p.X,
-                (int)p.Y,
-                0,
-                0,
-                UnmanagedMethods.SetWindowPosFlags.SWP_NOSIZE | UnmanagedMethods.SetWindowPosFlags.SWP_NOACTIVATE);
-        }
-
         public override void Show()
         {
             UnmanagedMethods.ShowWindow(Handle.Handle, UnmanagedMethods.ShowWindowCommand.ShowNoActivate);

+ 22 - 0
src/Windows/Perspex.Win32/WindowImpl.cs

@@ -247,6 +247,28 @@ namespace Perspex.Win32
                 new IntPtr((int) EdgeDic[edge]), IntPtr.Zero);
         }
 
+        public Point Position
+        {
+            get
+            {
+                UnmanagedMethods.RECT rc;
+                UnmanagedMethods.GetWindowRect(_hwnd, out rc);
+                return new Point(rc.left, rc.top);
+            }
+            set
+            {
+                UnmanagedMethods.SetWindowPos(
+                    Handle.Handle,
+                    IntPtr.Zero,
+                    (int) value.X,
+                    (int) value.Y,
+                    0,
+                    0,
+                    UnmanagedMethods.SetWindowPosFlags.SWP_NOSIZE | UnmanagedMethods.SetWindowPosFlags.SWP_NOACTIVATE);
+
+            }
+        }
+
         public virtual IDisposable ShowDialog()
         {
             var disabled = s_instances.Where(x => x != this && x.IsEnabled).ToList();

+ 2 - 0
src/iOS/Perspex.iOS/PerspexView.cs

@@ -118,6 +118,8 @@ namespace Perspex.iOS
             //Not supported
         }
 
+        public Point Position { get; set; }
+
         public Size MaxClientSize => Bounds.Size.ToPerspex();
         public void SetTitle(string title)
         {