Browse Source

实现Windows环境下使用Flutter的TitleBar

loki.wu 2 years ago
parent
commit
abcb0d9330

+ 7 - 6
fis/BaseWindow.cs

@@ -21,6 +21,7 @@ namespace fis.Win.Utilities
     public class BaseWindow : Window
     {
         private TextBlock? _title;
+        private string _plateformName = "";
         private AvaloniaCefBrowser _browser;
 
         /// <summary>
@@ -49,18 +50,17 @@ namespace fis.Win.Utilities
                 _browser = BrowserManager.SlaveBrowser;
             }
             var browserContainer = this.FindControl<Border>("BrowserBorder");
-            IPlatformService platformService;
             if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
             {
                 this.FindControl<MacosTitleBar>("MacTitleBar").IsVisible = false;
-                _title = this.FindControl<WindowsTitleBar>("WinTitleBar").FindControl<TextBlock>("WindowsTitle");
-                platformService = new WinService();
+                _title = new TextBlock();
+                _plateformName = "Win-X86";
             }
             else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
             {
                 this.FindControl<WindowsTitleBar>("WinTitleBar").IsVisible = false;
                 _title = this.FindControl<MacosTitleBar>("MacTitleBar").FindControl<TextBlock>("MacosTitle");
-                platformService = new MacService();
+                _plateformName = "MacOS-X64";
             }
             else
             {
@@ -77,9 +77,10 @@ namespace fis.Win.Utilities
                 {
                     _title.Text = "FLYINSONO";
                 }
-                var scriptObj = new FisBrowserScriptObject(_title, platformService);
-                _browser.RegisterJavascriptObject(scriptObj, "FisShellApi");
+           
             }
+            var scriptObj = new FisBrowserScriptObject(_title, _plateformName);
+            _browser.RegisterJavascriptObject(scriptObj, "FisShellApi");
             _browser.BrowserInitialized += () =>
             {
 #if DEBUG

+ 2 - 2
fis/MainWindow.axaml

@@ -10,11 +10,11 @@
 		<Border Name="WindowBorder" BorderBrush="#BFBFBF" BorderThickness="1">
 			<Grid>
 				<Grid.RowDefinitions>
-					<RowDefinition Height="32"/>
+					<RowDefinition Height="auto"/>
 					<RowDefinition Height="*"/>
 				</Grid.RowDefinitions>
 				<Grid Grid.Row="0">
-					<titlebars:WindowsTitleBar Name="WinTitleBar" IsSeamless="True"/>
+					<titlebars:WindowsTitleBar Name="WinTitleBar" Height ="0" IsSeamless="True"/>
 					<titlebars:MacosTitleBar  Name="MacTitleBar" IsSeamless="False"/>
 				</Grid>
 				<Border Grid.Row="1" BorderThickness="0" x:Name="BrowserBorder"/>

+ 0 - 5
fis/Managers/BrowserManager.cs

@@ -67,11 +67,6 @@ namespace fis.Managers
 
         public const string NotificationName = "externalNotification";
 
-        /// <summary>
-        /// 获取rpc通信的Service
-        /// </summary>
-        public static IPlatformService PlatformService => _platformService;
-
         static BrowserManager()
         {
             if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))

+ 1 - 2
fis/Managers/SecondaryScreenManager.cs

@@ -1,5 +1,4 @@
 using Avalonia;
-using Avalonia.Controls;
 using Avalonia.Threading;
 using fis.Managers.Interfaces;
 using fis.Utilities;
@@ -35,7 +34,7 @@ namespace fis.Managers
                     SlaveWindow.init(host, keyValuePairs);
                     if (SlaveWindow.Screens.ScreenCount > 1)
                     {
-                        var screen = SlaveWindow.Screens.All.FirstOrDefault<Avalonia.Platform.Screen>(x => x.Primary == false);
+                        var screen = SlaveWindow.Screens.All.FirstOrDefault(x => !x.Primary);
                         if (screen != null)
                         {
                             SlaveWindow.Position = new PixelPoint(screen.Bounds.X, screen.Bounds.Y);

+ 4 - 4
fis/Utilities/FisBrowserScriptObject.cs

@@ -20,17 +20,17 @@ namespace fis.Utilities
 {
     internal class FisBrowserScriptObject
     {
-        IPlatformService _platformService;
+        String _platformName;
         TextBlock _title;
         private string _lastClipData;
         private readonly SliceHelper _sliceHelper;
         public event EventHandler<bool> MeasureStateChanged;
         private readonly IUltra3DManager _ultr3DManager;
         private object _adjustlock = new object();
-        internal FisBrowserScriptObject(TextBlock title, IPlatformService platformService)
+        internal FisBrowserScriptObject(TextBlock title, string platformName)
         {
             _title = title;
-            _platformService = platformService;
+            _platformName = platformName;
              _ultr3DManager = AppManager.Get<IUltra3DManager>();
             _sliceHelper = _ultr3DManager.Parse3DModelManager.SliceHelper;
         }
@@ -40,7 +40,7 @@ namespace fis.Utilities
         /// 获取平台名
         /// </summary>
         /// <returns></returns>
-        public string GetPlatformName() => _platformService.GetPlatformName();
+        public string GetPlatformName() => _platformName;
 
         /// <summary>
         /// 写日志

+ 1 - 0
fis/Utilities/TargetMethodName.cs

@@ -30,5 +30,6 @@
 
         OpenReportDesignerPage,
         Logout,
+        OnWindowStateChange,
     }
 }

+ 34 - 1
fis/Win/WindowDragingHelper.cs

@@ -1,6 +1,10 @@
-using System;
+using Avalonia.Controls;
+using fis.Managers;
+using fis.Utilities;
+using System;
 using System.Collections.Generic;
 using System.ComponentModel;
+using System.Linq;
 using System.Runtime.InteropServices;
 
 namespace fis.Win
@@ -623,6 +627,7 @@ namespace fis.Win
             WH_MOUSE_LL = 14
         }
 
+        private static WindowState _windowState = WindowState.Normal;
 
         [StructLayout(LayoutKind.Sequential)]
         public struct POINT
@@ -652,6 +657,22 @@ namespace fis.Win
         }
 
 
+        public static WindowState WindowState 
+        {
+            get {
+                return _windowState;
+            }
+            set 
+            {
+                if (_windowState != value) 
+                {
+                    _windowState = value;
+                    string[] list = { ((int)_windowState).ToString() };
+                    BrowserManager.ExecuteJS(TargetMethodName.OnWindowStateChange, list.ToList());
+                }
+            }
+        }
+
         /// <summary>
         /// 声明鼠标钩子的封送结构类型
         /// </summary>
@@ -838,11 +859,15 @@ namespace fis.Win
 
         }
 
+
         //Start drag the window.
         public static void BeginWindowDrag(string windowName)
         {
             if (_windowHandles.TryGetValue(windowName, out var windowHandle))
             {
+                if (WindowState == WindowState.Maximized) {
+                    WindowState = WindowState.Normal;
+                }
                 if (GetCursorPos(out var dragPoint))
                 {
                     if (GetWindowRect(windowHandle, out var rect))
@@ -884,6 +909,7 @@ namespace fis.Win
         {
             if (_windowHandles.TryGetValue(windowName, out var windowHandle))
             {
+                WindowState = WindowState.Minimized;
                 //SW_MINIMIZE = 6
                 //SW_SHOWMINIMIZED = 2
                 //SW_SHOWMINNOACTIVE = 7
@@ -898,6 +924,12 @@ namespace fis.Win
         {
             if (_windowHandles.TryGetValue(windowName, out var windowHandle))
             {
+                if (WindowState == WindowState.Maximized) 
+                {
+                    RestoreWindow(windowName);
+                    return;
+                }
+                WindowState = WindowState.Maximized;
                 //SW_MAXIMIZE = 3
                 ShowWindow(windowHandle, 3);
                 EndWindowDrag(windowName);
@@ -909,6 +941,7 @@ namespace fis.Win
         {
             if (_windowHandles.TryGetValue(windowName, out var windowHandle))
             {
+                WindowState = WindowState.Normal;
                 //SW_RESTORE = 9
                 ShowWindow(windowHandle, 9);
                 EndWindowDrag(windowName);