فهرست منبع

Merge branch 'master' into features/keyboard-input

danwalmsley 7 سال پیش
والد
کامیت
3ebf8aa3c8

+ 4 - 0
src/Avalonia.Native.OSX/Avalonia.Native.OSX.xcodeproj/project.pbxproj

@@ -7,6 +7,7 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
+		37A517B32159597E00FBA241 /* Screens.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37A517B22159597E00FBA241 /* Screens.mm */; };
 		37C09D8821580FE4006A6758 /* SystemDialogs.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37C09D8721580FE4006A6758 /* SystemDialogs.mm */; };
 		37E2330F21583241000CB7E2 /* KeyTransform.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37E2330E21583241000CB7E2 /* KeyTransform.mm */; };
 		AB00E4F72147CA920032A60A /* main.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB00E4F62147CA920032A60A /* main.mm */; };
@@ -18,6 +19,7 @@
 /* Begin PBXFileReference section */
 		379860FE214DA0C000CD0246 /* KeyTransform.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KeyTransform.h; sourceTree = "<group>"; };
 		379A4506214D0F6500CC143D /* headers */ = {isa = PBXFileReference; lastKnownFileType = folder; name = headers; path = ../headers; sourceTree = "<group>"; };
+		37A517B22159597E00FBA241 /* Screens.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = Screens.mm; sourceTree = "<group>"; };
 		37C09D8721580FE4006A6758 /* SystemDialogs.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SystemDialogs.mm; sourceTree = "<group>"; };
 		37C09D8A21581EF2006A6758 /* window.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = window.h; sourceTree = "<group>"; };
 		37E2330E21583241000CB7E2 /* KeyTransform.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = KeyTransform.mm; sourceTree = "<group>"; };
@@ -60,6 +62,7 @@
 				AB661C1F2148286E00291242 /* window.mm */,
 				37C09D8A21581EF2006A6758 /* window.h */,
 				AB00E4F62147CA920032A60A /* main.mm */,
+				37A517B22159597E00FBA241 /* Screens.mm */,
 				37C09D8721580FE4006A6758 /* SystemDialogs.mm */,
 				AB7A61F02147C815003C5833 /* Products */,
 				AB661C1C2148230E00291242 /* Frameworks */,
@@ -143,6 +146,7 @@
 			files = (
 				AB8F7D6B21482D7F0057DBA5 /* platformthreading.mm in Sources */,
 				37E2330F21583241000CB7E2 /* KeyTransform.mm in Sources */,
+				37A517B32159597E00FBA241 /* Screens.mm in Sources */,
 				AB00E4F72147CA920032A60A /* main.mm in Sources */,
 				37C09D8821580FE4006A6758 /* SystemDialogs.mm in Sources */,
 				AB661C202148286E00291242 /* window.mm in Sources */,

+ 42 - 0
src/Avalonia.Native.OSX/Screens.mm

@@ -0,0 +1,42 @@
+#include "common.h"
+
+class Screens : public ComSingleObject<IAvnScreens, &IID_IAvnScreens>
+{
+    public:
+    
+    virtual HRESULT GetScreenCount (int* ret)
+    {
+        *ret = (int)[NSScreen screens].count;
+        
+        return S_OK;
+    }
+    
+    virtual HRESULT GetScreen (int index, AvnScreen* ret)
+    {
+        if(index < 0 || index >= [NSScreen screens].count)
+        {
+            return E_INVALIDARG;
+        }
+        
+        auto screen = [[NSScreen screens] objectAtIndex:index];
+        
+        ret->Bounds.X = [screen frame].origin.x;
+        ret->Bounds.Y = [screen frame].origin.y;
+        ret->Bounds.Height = [screen frame].size.height;
+        ret->Bounds.Width = [screen frame].size.width;
+        
+        ret->WorkingArea.X = [screen visibleFrame].origin.x;
+        ret->WorkingArea.Y = [screen visibleFrame].origin.y;
+        ret->WorkingArea.Height = [screen visibleFrame].size.height;
+        ret->WorkingArea.Width = [screen visibleFrame].size.width;
+        
+        ret->Primary = index == 0;
+        
+        return S_OK;
+    }
+};
+
+extern IAvnScreens* CreateScreens()
+{
+    return new Screens();
+}

+ 1 - 0
src/Avalonia.Native.OSX/common.h

@@ -11,6 +11,7 @@ extern IAvnPlatformThreadingInterface* CreatePlatformThreading();
 extern IAvnWindow* CreateAvnWindow(IAvnWindowEvents*events);
 extern IAvnPopup* CreateAvnPopup(IAvnWindowEvents*events);
 extern IAvnSystemDialogs* CreateSystemDialogs();
+extern IAvnScreens* CreateScreens();
 
 extern NSPoint ToNSPoint (AvnPoint p);
 extern AvnPoint ToAvnPoint (NSPoint p);

+ 6 - 0
src/Avalonia.Native.OSX/main.mm

@@ -100,6 +100,12 @@ public:
         *ppv = ::CreateSystemDialogs();
         return  S_OK;
     }
+    
+     virtual HRESULT CreateScreens (IAvnScreens** ppv)
+    {
+        *ppv = ::CreateScreens ();
+        return S_OK;
+    }
 };
 
 extern "C" IAvaloniaNativeFactory* CreateAvaloniaNative()

+ 0 - 1
src/Avalonia.Native/AvaloniaNativePlatform.cs

@@ -70,7 +70,6 @@ namespace Avalonia.Native
                 .Bind<IMouseDevice>().ToConstant(MouseDevice)
                 .Bind<IPlatformSettings>().ToConstant(this)
                 .Bind<IWindowingPlatform>().ToConstant(this)
-                .Bind<ISystemDialogImpl>().ToSingleton<SystemDialogImpl>()
                 .Bind<IClipboard>().ToSingleton<ClipboardImpl>()
                 .Bind<IRenderLoop>().ToConstant(new RenderLoop())
                 .Bind<IRenderTimer>().ToConstant(new DefaultRenderTimer(60))

+ 5 - 0
src/Avalonia.Native/Helpers.cs

@@ -19,5 +19,10 @@ namespace Avalonia.Native
         {
             return new Size(size.Width, size.Height);
         }
+
+        public static Rect ToAvaloniaRect (this AvnRect rect)
+        {
+            return new Rect(rect.X, rect.Y, rect.Width, rect.Height);
+        }
     }
 }

+ 7 - 1
src/Avalonia.Native/PopupImpl.cs

@@ -11,7 +11,13 @@ namespace Avalonia.Native
         public PopupImpl(IAvaloniaNativeFactory factory)
         {
             using (var e = new PopupEvents(this))
-                Init(_native = factory.CreatePopup(e));
+                Init(_native = factory.CreatePopup(e), factory.CreateScreens());
+        }
+
+        public override void Dispose()
+        {
+            _native.Dispose();
+            base.Dispose();
         }
 
         class PopupEvents : WindowBaseEvents, IAvnWindowEvents

+ 42 - 0
src/Avalonia.Native/ScreenImpl.cs

@@ -0,0 +1,42 @@
+using System;
+using Avalonia.Native.Interop;
+using Avalonia.Platform;
+
+namespace Avalonia.Native
+{
+    class ScreenImpl : IScreenImpl, IDisposable
+    {
+        private IAvnScreens _native;
+
+        public ScreenImpl(IAvnScreens native)
+        {
+            _native = native;
+        }
+
+        public int ScreenCount => _native.GetScreenCount();
+
+        public Screen[] AllScreens
+        {
+            get
+            {
+                var count = ScreenCount;
+                var result = new Screen[count];
+
+                for(int i = 0; i < count; i++)
+                {
+                    var screen = _native.GetScreen(i);
+
+                    result[i] = new Screen(screen.Bounds.ToAvaloniaRect(), screen.WorkingArea.ToAvaloniaRect(), screen.Primary);
+                }
+
+                return result;
+            }
+        }
+
+        public void Dispose ()
+        {
+            _native.Dispose();
+            _native = null;
+        }
+    }
+}

+ 1 - 21
src/Avalonia.Native/Stubs.cs

@@ -7,20 +7,7 @@ using Avalonia.Input.Platform;
 using Avalonia.Platform;
 
 namespace Avalonia.Native
-{
-    class SystemDialogImpl : ISystemDialogImpl
-    {
-        public Task<string[]> ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent)
-        {
-            return Task.FromResult((string[])null);
-        }
-
-        public Task<string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent)
-        {
-            return Task.FromResult<string>(null);
-        }
-    }
-
+{ 
     class ClipboardImpl : IClipboard
     {
         public Task ClearAsync()
@@ -38,11 +25,4 @@ namespace Avalonia.Native
             return Task.CompletedTask;
         }
     }
-
-    class ScreenImpl : IScreenImpl
-    {
-        public int ScreenCount => 1;
-
-        public Screen[] AllScreens => new[] { new Screen(new Rect(0, 0, 1600, 900), new Rect(0, 0, 1600, 900), true) };
-    }
 }

+ 1 - 1
src/Avalonia.Native/WindowImpl.cs

@@ -11,7 +11,7 @@ namespace Avalonia.Native
         public WindowImpl(IAvaloniaNativeFactory factory)
         {
             using (var e = new WindowEvents(this))
-                Init(_native = factory.CreateWindow(e));
+                Init(_native = factory.CreateWindow(e), factory.CreateScreens());
         }
 
         class WindowEvents : WindowBaseEvents, IAvnWindowEvents

+ 7 - 3
src/Avalonia.Native/WindowImplBase.cs

@@ -28,9 +28,11 @@ namespace Avalonia.Native
             _mouse = AvaloniaLocator.Current.GetService<IMouseDevice>();
         }
 
-        protected void Init(IAvnWindowBase window)
+        protected void Init(IAvnWindowBase window, IAvnScreens screens)
         {
             _native = window;
+            
+            Screen = new ScreenImpl(screens);
             _savedLogicalSize = ClientSize;
             _savedScaling = Scaling;
         }
@@ -198,11 +200,13 @@ namespace Avalonia.Native
             return new ImmediateRenderer(root);
         }
 
-        public void Dispose()
+        public virtual void Dispose()
         {
             _native.Close();
             _native.Dispose();
             _native = null;
+
+            (Screen as ScreenImpl)?.Dispose();
         }
 
 
@@ -272,7 +276,7 @@ namespace Avalonia.Native
         public IPlatformHandle Handle => new PlatformHandle(IntPtr.Zero, "NOT SUPPORTED");
 
 
-        public IScreenImpl Screen => new ScreenImpl();
+        public IScreenImpl Screen { get; private set; }
 
         Action<double> ITopLevelImpl.ScalingChanged { get; set; }
 

+ 16 - 0
src/headers/avalonia-native.h

@@ -10,6 +10,7 @@ struct IAvnMacOptions;
 struct IAvnPlatformThreadingInterface;
 struct IAvnSystemDialogEvents;
 struct IAvnSystemDialogs;
+struct IAvnScreens;
 
 struct AvnSize
 {
@@ -31,6 +32,13 @@ struct AvnPoint
     double X, Y;
 };
 
+struct AvnScreen
+{
+    AvnRect Bounds;
+    AvnRect WorkingArea;
+    bool Primary;
+};
+
 enum AvnPixelFormat
 {
     kAvnRgb565,
@@ -89,6 +97,7 @@ public:
     virtual HRESULT CreatePopup (IAvnWindowEvents* cb, IAvnPopup** ppv) = 0;
     virtual HRESULT CreatePlatformThreadingInterface(IAvnPlatformThreadingInterface** ppv) = 0;
     virtual HRESULT CreateSystemDialogs (IAvnSystemDialogs** ppv) = 0;
+    virtual HRESULT CreateScreens (IAvnScreens** ppv) = 0;
 };
 
 AVNCOM(IAvnWindowBase, 02) : virtual IUnknown
@@ -204,4 +213,11 @@ AVNCOM(IAvnSystemDialogs, 0d) : virtual IUnknown
                                  const char* filters) = 0;
 };
 
+AVNCOM(IAvnScreens, 0e) : virtual IUnknown
+{
+    virtual HRESULT GetScreenCount (int* ret) = 0;
+    virtual HRESULT GetScreen (int index, AvnScreen* ret) = 0;
+    
+};
+
 extern "C" IAvaloniaNativeFactory* CreateAvaloniaNative();