committed by
GitHub
3016 changed files with 174985 additions and 109240 deletions
@ -1 +1,2 @@ |
|||
github: avaloniaui |
|||
open_collective: avalonia |
|||
|
|||
@ -0,0 +1,5 @@ |
|||
<ProjectConfiguration> |
|||
<Settings> |
|||
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> |
|||
</Settings> |
|||
</ProjectConfiguration> |
|||
@ -0,0 +1,5 @@ |
|||
<ProjectConfiguration> |
|||
<Settings> |
|||
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> |
|||
</Settings> |
|||
</ProjectConfiguration> |
|||
@ -0,0 +1,5 @@ |
|||
<ProjectConfiguration> |
|||
<Settings> |
|||
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> |
|||
</Settings> |
|||
</ProjectConfiguration> |
|||
@ -1,7 +1,3 @@ |
|||
<ProjectConfiguration> |
|||
<Settings> |
|||
<AdditionalFilesToIncludeForProject> |
|||
<Value>..\..\tools\MicroComGenerator\bin\Debug\net6.0\**.*</Value> |
|||
</AdditionalFilesToIncludeForProject> |
|||
</Settings> |
|||
<Settings /> |
|||
</ProjectConfiguration> |
|||
@ -1,7 +1,3 @@ |
|||
<ProjectConfiguration> |
|||
<Settings> |
|||
<AdditionalFilesToIncludeForProject> |
|||
<Value>..\..\tools\MicroComGenerator\bin\Debug\net6.0\**.*</Value> |
|||
</AdditionalFilesToIncludeForProject> |
|||
</Settings> |
|||
<Settings /> |
|||
</ProjectConfiguration> |
|||
@ -0,0 +1,5 @@ |
|||
<ProjectConfiguration> |
|||
<Settings> |
|||
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> |
|||
</Settings> |
|||
</ProjectConfiguration> |
|||
@ -0,0 +1,5 @@ |
|||
<ProjectConfiguration> |
|||
<Settings> |
|||
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> |
|||
</Settings> |
|||
</ProjectConfiguration> |
|||
@ -0,0 +1,5 @@ |
|||
<ProjectConfiguration> |
|||
<Settings> |
|||
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> |
|||
</Settings> |
|||
</ProjectConfiguration> |
|||
@ -0,0 +1,5 @@ |
|||
<ProjectConfiguration> |
|||
<Settings> |
|||
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> |
|||
</Settings> |
|||
</ProjectConfiguration> |
|||
@ -0,0 +1,5 @@ |
|||
<ProjectConfiguration> |
|||
<Settings> |
|||
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> |
|||
</Settings> |
|||
</ProjectConfiguration> |
|||
@ -0,0 +1,5 @@ |
|||
<ProjectConfiguration> |
|||
<Settings> |
|||
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> |
|||
</Settings> |
|||
</ProjectConfiguration> |
|||
@ -0,0 +1,5 @@ |
|||
<ProjectConfiguration> |
|||
<Settings> |
|||
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> |
|||
</Settings> |
|||
</ProjectConfiguration> |
|||
@ -0,0 +1,5 @@ |
|||
<ProjectConfiguration> |
|||
<Settings> |
|||
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> |
|||
</Settings> |
|||
</ProjectConfiguration> |
|||
@ -0,0 +1,5 @@ |
|||
<ProjectConfiguration> |
|||
<Settings> |
|||
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> |
|||
</Settings> |
|||
</ProjectConfiguration> |
|||
@ -0,0 +1,5 @@ |
|||
<ProjectConfiguration> |
|||
<Settings> |
|||
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> |
|||
</Settings> |
|||
</ProjectConfiguration> |
|||
@ -0,0 +1,148 @@ |
|||
{ |
|||
"$schema": "http://json-schema.org/draft-04/schema#", |
|||
"title": "Build Schema", |
|||
"$ref": "#/definitions/build", |
|||
"definitions": { |
|||
"build": { |
|||
"type": "object", |
|||
"properties": { |
|||
"Configuration": { |
|||
"type": "string", |
|||
"description": "configuration" |
|||
}, |
|||
"Continue": { |
|||
"type": "boolean", |
|||
"description": "Indicates to continue a previously failed build attempt" |
|||
}, |
|||
"ForceNugetVersion": { |
|||
"type": "string", |
|||
"description": "force-nuget-version" |
|||
}, |
|||
"Help": { |
|||
"type": "boolean", |
|||
"description": "Shows the help text for this build assembly" |
|||
}, |
|||
"Host": { |
|||
"type": "string", |
|||
"description": "Host for execution. Default is 'automatic'", |
|||
"enum": [ |
|||
"AppVeyor", |
|||
"AzurePipelines", |
|||
"Bamboo", |
|||
"Bitbucket", |
|||
"Bitrise", |
|||
"GitHubActions", |
|||
"GitLab", |
|||
"Jenkins", |
|||
"Rider", |
|||
"SpaceAutomation", |
|||
"TeamCity", |
|||
"Terminal", |
|||
"TravisCI", |
|||
"VisualStudio", |
|||
"VSCode" |
|||
] |
|||
}, |
|||
"NoLogo": { |
|||
"type": "boolean", |
|||
"description": "Disables displaying the NUKE logo" |
|||
}, |
|||
"Partition": { |
|||
"type": "string", |
|||
"description": "Partition to use on CI" |
|||
}, |
|||
"Plan": { |
|||
"type": "boolean", |
|||
"description": "Shows the execution plan (HTML)" |
|||
}, |
|||
"Profile": { |
|||
"type": "array", |
|||
"description": "Defines the profiles to load", |
|||
"items": { |
|||
"type": "string" |
|||
} |
|||
}, |
|||
"Root": { |
|||
"type": "string", |
|||
"description": "Root directory during build execution" |
|||
}, |
|||
"Skip": { |
|||
"type": "array", |
|||
"description": "List of targets to be skipped. Empty list skips all dependencies", |
|||
"items": { |
|||
"type": "string", |
|||
"enum": [ |
|||
"CiAzureLinux", |
|||
"CiAzureOSX", |
|||
"CiAzureWindows", |
|||
"Clean", |
|||
"Compile", |
|||
"CompileHtmlPreviewer", |
|||
"CompileNative", |
|||
"CreateIntermediateNugetPackages", |
|||
"CreateNugetPackages", |
|||
"GenerateCppHeaders", |
|||
"Package", |
|||
"RunCoreLibsTests", |
|||
"RunDesignerTests", |
|||
"RunHtmlPreviewerTests", |
|||
"RunLeakTests", |
|||
"RunRenderTests", |
|||
"RunTests", |
|||
"ZipFiles" |
|||
] |
|||
} |
|||
}, |
|||
"SkipPreviewer": { |
|||
"type": "boolean", |
|||
"description": "skip-previewer" |
|||
}, |
|||
"SkipTests": { |
|||
"type": "boolean", |
|||
"description": "skip-tests" |
|||
}, |
|||
"Solution": { |
|||
"type": "string", |
|||
"description": "Path to a solution file that is automatically loaded. Default is Avalonia.sln" |
|||
}, |
|||
"Target": { |
|||
"type": "array", |
|||
"description": "List of targets to be invoked. Default is '{default_target}'", |
|||
"items": { |
|||
"type": "string", |
|||
"enum": [ |
|||
"CiAzureLinux", |
|||
"CiAzureOSX", |
|||
"CiAzureWindows", |
|||
"Clean", |
|||
"Compile", |
|||
"CompileHtmlPreviewer", |
|||
"CompileNative", |
|||
"CreateIntermediateNugetPackages", |
|||
"CreateNugetPackages", |
|||
"GenerateCppHeaders", |
|||
"Package", |
|||
"RunCoreLibsTests", |
|||
"RunDesignerTests", |
|||
"RunHtmlPreviewerTests", |
|||
"RunLeakTests", |
|||
"RunRenderTests", |
|||
"RunTests", |
|||
"ZipFiles" |
|||
] |
|||
} |
|||
}, |
|||
"Verbosity": { |
|||
"type": "string", |
|||
"description": "Logging verbosity during build execution. Default is 'Normal'", |
|||
"enum": [ |
|||
"Minimal", |
|||
"Normal", |
|||
"Quiet", |
|||
"Verbose" |
|||
] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,4 @@ |
|||
{ |
|||
"$schema": "./build.schema.json", |
|||
"Solution": "" |
|||
} |
|||
@ -0,0 +1,60 @@ |
|||
{ |
|||
"solution": { |
|||
"path": "Avalonia.sln", |
|||
"projects": [ |
|||
"packages\\Avalonia\\Avalonia.csproj", |
|||
"samples\\ControlCatalog.NetCore\\ControlCatalog.NetCore.csproj", |
|||
"samples\\ControlCatalog\\ControlCatalog.csproj", |
|||
"samples\\IntegrationTestApp\\IntegrationTestApp.csproj", |
|||
"samples\\MiniMvvm\\MiniMvvm.csproj", |
|||
"samples\\SampleControls\\ControlSamples.csproj", |
|||
"samples\\Sandbox\\Sandbox.csproj", |
|||
"src\\Avalonia.Base\\Avalonia.Base.csproj", |
|||
"src\\Avalonia.Build.Tasks\\Avalonia.Build.Tasks.csproj", |
|||
"src\\Avalonia.Controls.ColorPicker\\Avalonia.Controls.ColorPicker.csproj", |
|||
"src\\Avalonia.Controls.DataGrid\\Avalonia.Controls.DataGrid.csproj", |
|||
"src\\Avalonia.Controls\\Avalonia.Controls.csproj", |
|||
"src\\Avalonia.DesignerSupport\\Avalonia.DesignerSupport.csproj", |
|||
"src\\Avalonia.Desktop\\Avalonia.Desktop.csproj", |
|||
"src\\Avalonia.Diagnostics\\Avalonia.Diagnostics.csproj", |
|||
"src\\Avalonia.Dialogs\\Avalonia.Dialogs.csproj", |
|||
"src\\Avalonia.FreeDesktop\\Avalonia.FreeDesktop.csproj", |
|||
"src\\Avalonia.Headless.Vnc\\Avalonia.Headless.Vnc.csproj", |
|||
"src\\Avalonia.Headless\\Avalonia.Headless.csproj", |
|||
"src\\Avalonia.MicroCom\\Avalonia.MicroCom.csproj", |
|||
"src\\Avalonia.Native\\Avalonia.Native.csproj", |
|||
"src\\Avalonia.OpenGL\\Avalonia.OpenGL.csproj", |
|||
"src\\Avalonia.ReactiveUI\\Avalonia.ReactiveUI.csproj", |
|||
"src\\Avalonia.Remote.Protocol\\Avalonia.Remote.Protocol.csproj", |
|||
"src\\Avalonia.Themes.Fluent\\Avalonia.Themes.Fluent.csproj", |
|||
"src\\Avalonia.Themes.Simple\\Avalonia.Themes.Simple.csproj", |
|||
"src\\Avalonia.X11\\Avalonia.X11.csproj", |
|||
"src\\Linux\\Avalonia.LinuxFramebuffer\\Avalonia.LinuxFramebuffer.csproj", |
|||
"src\\Markup\\Avalonia.Markup.Xaml.Loader\\Avalonia.Markup.Xaml.Loader.csproj", |
|||
"src\\Markup\\Avalonia.Markup.Xaml\\Avalonia.Markup.Xaml.csproj", |
|||
"src\\Markup\\Avalonia.Markup\\Avalonia.Markup.csproj", |
|||
"src\\Skia\\Avalonia.Skia\\Avalonia.Skia.csproj", |
|||
"src\\Windows\\Avalonia.Direct2D1\\Avalonia.Direct2D1.csproj", |
|||
"src\\Windows\\Avalonia.Win32.Interop\\Avalonia.Win32.Interop.csproj", |
|||
"src\\Windows\\Avalonia.Win32\\Avalonia.Win32.csproj", |
|||
"src\\tools\\DevAnalyzers\\DevAnalyzers.csproj", |
|||
"src\\tools\\DevGenerators\\DevGenerators.csproj", |
|||
"tests\\Avalonia.Base.UnitTests\\Avalonia.Base.UnitTests.csproj", |
|||
"tests\\Avalonia.Benchmarks\\Avalonia.Benchmarks.csproj", |
|||
"tests\\Avalonia.Controls.DataGrid.UnitTests\\Avalonia.Controls.DataGrid.UnitTests.csproj", |
|||
"tests\\Avalonia.Controls.UnitTests\\Avalonia.Controls.UnitTests.csproj", |
|||
"tests\\Avalonia.DesignerSupport.TestApp\\Avalonia.DesignerSupport.TestApp.csproj", |
|||
"tests\\Avalonia.DesignerSupport.Tests\\Avalonia.DesignerSupport.Tests.csproj", |
|||
"tests\\Avalonia.Direct2D1.RenderTests\\Avalonia.Direct2D1.RenderTests.csproj", |
|||
"tests\\Avalonia.Direct2D1.UnitTests\\Avalonia.Direct2D1.UnitTests.csproj", |
|||
"tests\\Avalonia.IntegrationTests.Appium\\Avalonia.IntegrationTests.Appium.csproj", |
|||
"tests\\Avalonia.LeakTests\\Avalonia.LeakTests.csproj", |
|||
"tests\\Avalonia.Markup.UnitTests\\Avalonia.Markup.UnitTests.csproj", |
|||
"tests\\Avalonia.Markup.Xaml.UnitTests\\Avalonia.Markup.Xaml.UnitTests.csproj", |
|||
"tests\\Avalonia.ReactiveUI.UnitTests\\Avalonia.ReactiveUI.UnitTests.csproj", |
|||
"tests\\Avalonia.Skia.RenderTests\\Avalonia.Skia.RenderTests.csproj", |
|||
"tests\\Avalonia.Skia.UnitTests\\Avalonia.Skia.UnitTests.csproj", |
|||
"tests\\Avalonia.UnitTests\\Avalonia.UnitTests.csproj" |
|||
] |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -1,9 +1,11 @@ |
|||
<Project> |
|||
<Import Project="$(MSBuildThisFileDirectory)/build/AvaloniaPublicKey.props"/> |
|||
<PropertyGroup> |
|||
<PackageOutputPath Condition="'$(PackageOutputPath)' == ''">$(MSBuildThisFileDirectory)build-intermediate/nuget</PackageOutputPath> |
|||
<AvaloniaPreviewerNetCoreToolPath>$(MSBuildThisFileDirectory)\src\tools\Avalonia.Designer.HostApp\bin\$(Configuration)\netcoreapp2.0\Avalonia.Designer.HostApp.dll</AvaloniaPreviewerNetCoreToolPath> |
|||
<!-- https://github.com/dotnet/msbuild/issues/2661 --> |
|||
<AddSyntheticProjectReferencesForSolutionDependencies>false</AddSyntheticProjectReferencesForSolutionDependencies> |
|||
<MSBuildEnableWorkloadResolver>false</MSBuildEnableWorkloadResolver> |
|||
<RunApiCompat>False</RunApiCompat> |
|||
</PropertyGroup> |
|||
</Project> |
|||
|
|||
@ -0,0 +1,5 @@ |
|||
<Project> |
|||
<PropertyGroup Condition="$(NETCoreSdkVersion.StartsWith('7.0'))"> |
|||
<DefineConstants>$(DefineConstants);NET7SDK</DefineConstants> |
|||
</PropertyGroup> |
|||
</Project> |
|||
@ -0,0 +1,83 @@ |
|||
# Starter pipeline |
|||
# Start with a minimal pipeline that you can customize to build and deploy your code. |
|||
# Add steps that build, run tests, deploy, and more: |
|||
# https://aka.ms/yaml |
|||
|
|||
trigger: |
|||
- master |
|||
|
|||
jobs: |
|||
- job: Mac |
|||
pool: |
|||
name: 'AvaloniaMacPool' |
|||
|
|||
steps: |
|||
- task: UseDotNet@2 |
|||
displayName: 'Use .NET Core SDK 6.0.401' |
|||
inputs: |
|||
version: 6.0.401 |
|||
|
|||
- task: UseDotNet@2 |
|||
displayName: 'Use .NET Core SDK 7.0.100' |
|||
inputs: |
|||
version: 7.0.100 |
|||
|
|||
- script: system_profiler SPDisplaysDataType |grep Resolution |
|||
|
|||
- script: | |
|||
pkill node |
|||
appium & |
|||
pkill IntegrationTestApp |
|||
./build.sh CompileNative |
|||
rm -rf $(osascript -e "POSIX path of (path to application id \"net.avaloniaui.avalonia.integrationtestapp\")") |
|||
pkill IntegrationTestApp |
|||
./samples/IntegrationTestApp/bundle.sh |
|||
open -n ./samples/IntegrationTestApp/bin/Debug/net7.0/osx-arm64/publish/IntegrationTestApp.app |
|||
pkill IntegrationTestApp |
|||
|
|||
- task: DotNetCoreCLI@2 |
|||
inputs: |
|||
command: 'test' |
|||
projects: 'tests/Avalonia.IntegrationTests.Appium/Avalonia.IntegrationTests.Appium.csproj' |
|||
|
|||
- script: | |
|||
pkill IntegrationTestApp |
|||
pkill node |
|||
|
|||
|
|||
- job: Windows |
|||
pool: |
|||
vmImage: 'windows-2022' |
|||
|
|||
steps: |
|||
- task: UseDotNet@2 |
|||
displayName: 'Use .NET Core SDK 6.0.401' |
|||
inputs: |
|||
version: 6.0.401 |
|||
|
|||
- task: UseDotNet@2 |
|||
displayName: 'Use .NET Core SDK 7.0.100' |
|||
inputs: |
|||
version: 7.0.100 |
|||
|
|||
- task: Windows Application Driver@0 |
|||
inputs: |
|||
OperationType: 'Start' |
|||
AgentResolution: '4K' |
|||
displayName: 'Start WinAppDriver' |
|||
|
|||
- task: DotNetCoreCLI@2 |
|||
inputs: |
|||
command: 'build' |
|||
projects: 'samples/IntegrationTestApp/IntegrationTestApp.csproj' |
|||
|
|||
- task: DotNetCoreCLI@2 |
|||
retryCountOnTaskFailure: 3 |
|||
inputs: |
|||
command: 'test' |
|||
projects: 'tests/Avalonia.IntegrationTests.Appium/Avalonia.IntegrationTests.Appium.csproj' |
|||
|
|||
- task: Windows Application Driver@0 |
|||
inputs: |
|||
OperationType: 'Stop' |
|||
displayName: 'Stop WinAppDriver' |
|||
@ -0,0 +1,7 @@ |
|||
:; set -eo pipefail |
|||
:; SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) |
|||
:; ${SCRIPT_DIR}/build.sh "$@" |
|||
:; exit $? |
|||
|
|||
@ECHO OFF |
|||
powershell -ExecutionPolicy ByPass -NoProfile -File "%~dp0build.ps1" %* |
|||
@ -0,0 +1,2 @@ |
|||
T:Avalonia.Metadata.NotClientImplementableAttribute |
|||
T:Avalonia.Metadata.UnstableAttribute |
|||
@ -0,0 +1,5 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<PropertyGroup> |
|||
<AvaloniaPublicKey>0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87</AvaloniaPublicKey> |
|||
</PropertyGroup> |
|||
</Project> |
|||
@ -1,22 +1,12 @@ |
|||
<Project> |
|||
<ItemGroup> |
|||
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.Base/Avalonia.Base.csproj" /> |
|||
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.Animation/Avalonia.Animation.csproj" /> |
|||
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.Controls/Avalonia.Controls.csproj" /> |
|||
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.DesignerSupport/Avalonia.DesignerSupport.csproj" /> |
|||
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.Input/Avalonia.Input.csproj" /> |
|||
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.Interactivity/Avalonia.Interactivity.csproj" /> |
|||
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.Layout/Avalonia.Layout.csproj" /> |
|||
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.Visuals/Avalonia.Visuals.csproj" /> |
|||
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.Styling/Avalonia.Styling.csproj" /> |
|||
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.Themes.Default/Avalonia.Themes.Default.csproj" /> |
|||
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.Themes.Fluent/Avalonia.Themes.Fluent.csproj" /> |
|||
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.OpenGL/Avalonia.OpenGL.csproj" /> |
|||
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.Dialogs/Avalonia.Dialogs.csproj" /> |
|||
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Markup/Avalonia.Markup/Avalonia.Markup.csproj" /> |
|||
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj" /> |
|||
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.MicroCom/Avalonia.MicroCom.csproj" /> |
|||
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.DesktopRuntime/Avalonia.DesktopRuntime.csproj" Condition="'$(TargetFramework)' != 'netstandard2.0'" /> |
|||
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.PlatformSupport/Avalonia.PlatformSupport.csproj" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
|
|||
@ -0,0 +1,9 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<ItemGroup> |
|||
<ProjectReference Include="$(MSBuildThisFileDirectory)..\src\tools\DevAnalyzers\DevAnalyzers.csproj" |
|||
PrivateAssets="all" |
|||
ReferenceOutputAssembly="false" |
|||
OutputItemType="Analyzer" |
|||
SetTargetFramework="TargetFramework=netstandard2.0"/> |
|||
</ItemGroup> |
|||
</Project> |
|||
@ -1,7 +1,7 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<ItemGroup> |
|||
<PackageReference Include="HarfBuzzSharp" Version="2.8.2-preview.178" /> |
|||
<PackageReference Condition="'$(IncludeLinuxSkia)' == 'true'" Include="HarfBuzzSharp.NativeAssets.Linux" Version="2.8.2-preview.178" /> |
|||
<PackageReference Condition="'$(IncludeWasmSkia)' == 'true'" Include="HarfBuzzSharp.NativeAssets.WebAssembly" Version="2.8.2-preview.178"/> |
|||
<PackageReference Include="HarfBuzzSharp" Version="2.8.2.1-preview.108" /> |
|||
<PackageReference Condition="'$(IncludeLinuxSkia)' == 'true'" Include="HarfBuzzSharp.NativeAssets.Linux" Version="2.8.2.1-preview.108" /> |
|||
<PackageReference Condition="'$(IncludeWasmSkia)' == 'true'" Include="HarfBuzzSharp.NativeAssets.WebAssembly" Version="2.8.2.1-preview.108" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
|
|||
@ -0,0 +1,5 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<ItemGroup> |
|||
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.1" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
@ -1,5 +1,5 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<ItemGroup> |
|||
<PackageReference Include="JetBrains.DotMemoryUnit" Version="3.1.20200127.214830" /> |
|||
<PackageReference Include="JetBrains.DotMemoryUnit" Version="3.2.20220510" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
|
|||
@ -1,5 +0,0 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<ItemGroup> |
|||
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="7.9.0.2" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
@ -0,0 +1,5 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<PropertyGroup> |
|||
<EnableNETAnalyzers>true</EnableNETAnalyzers> |
|||
</PropertyGroup> |
|||
</Project> |
|||
@ -1,7 +1,6 @@ |
|||
<Project> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
|
|||
@ -1,5 +1,5 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<ItemGroup> |
|||
<PackageReference Include="ReactiveUI" Version="13.2.10" /> |
|||
<PackageReference Include="ReactiveUI" Version="18.3.1" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
|
|||
@ -1,7 +1,7 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<ItemGroup> |
|||
<PackageReference Include="SkiaSharp" Version="2.88.0-preview.178" /> |
|||
<PackageReference Condition="'$(IncludeLinuxSkia)' == 'true'" Include="SkiaSharp.NativeAssets.Linux" Version="2.88.0-preview.178" /> |
|||
<PackageReference Condition="'$(IncludeWasmSkia)' == 'true'" Include="SkiaSharp.NativeAssets.WebAssembly" Version="2.88.0-preview.178"/> |
|||
<PackageReference Include="SkiaSharp" Version="2.88.1" /> |
|||
<PackageReference Condition="'$(IncludeLinuxSkia)' == 'true'" Include="SkiaSharp.NativeAssets.Linux" Version="2.88.1" /> |
|||
<PackageReference Condition="'$(IncludeWasmSkia)' == 'true'" Include="SkiaSharp.NativeAssets.WebAssembly" Version="2.88.1" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
|
|||
@ -0,0 +1,10 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<ItemGroup> |
|||
<ProjectReference |
|||
Include="$(MSBuildThisFileDirectory)/../src/tools/DevGenerators/DevGenerators.csproj" |
|||
OutputItemType="Analyzer" |
|||
ReferenceOutputAssembly="false" |
|||
PrivateAssets="all" /> |
|||
<Compile Include="$(MSBuildThisFileDirectory)/../src/Shared/SourceGeneratorAttributes.cs" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
@ -0,0 +1,17 @@ |
|||
//
|
|||
// Created by Dan Walmsley on 05/05/2022.
|
|||
// Copyright (c) 2022 Avalonia. All rights reserved.
|
|||
//
|
|||
|
|||
#pragma once |
|||
|
|||
#import <Foundation/Foundation.h> |
|||
#include "avalonia-native.h" |
|||
|
|||
@interface AutoFitContentView : NSView |
|||
-(AutoFitContentView* _Nonnull) initWithContent: (NSView* _Nonnull) content; |
|||
-(void) ShowTitleBar: (bool) show; |
|||
-(void) SetTitleBarHeightHint: (double) height; |
|||
|
|||
-(void) ShowBlur: (bool) show; |
|||
@end |
|||
@ -0,0 +1,106 @@ |
|||
// |
|||
// Created by Dan Walmsley on 05/05/2022. |
|||
// Copyright (c) 2022 Avalonia. All rights reserved. |
|||
// |
|||
|
|||
#include "AvnView.h" |
|||
#include "AutoFitContentView.h" |
|||
#include "WindowInterfaces.h" |
|||
#include "WindowProtocol.h" |
|||
|
|||
@implementation AutoFitContentView |
|||
{ |
|||
NSVisualEffectView* _titleBarMaterial; |
|||
NSBox* _titleBarUnderline; |
|||
NSView* _content; |
|||
NSVisualEffectView* _blurBehind; |
|||
double _titleBarHeightHint; |
|||
bool _settingSize; |
|||
} |
|||
|
|||
-(AutoFitContentView* _Nonnull) initWithContent:(NSView *)content |
|||
{ |
|||
_titleBarHeightHint = -1; |
|||
_content = content; |
|||
_settingSize = false; |
|||
|
|||
[self setAutoresizesSubviews:true]; |
|||
[self setWantsLayer:true]; |
|||
|
|||
_titleBarMaterial = [NSVisualEffectView new]; |
|||
[_titleBarMaterial setBlendingMode:NSVisualEffectBlendingModeWithinWindow]; |
|||
[_titleBarMaterial setMaterial:NSVisualEffectMaterialTitlebar]; |
|||
[_titleBarMaterial setWantsLayer:true]; |
|||
_titleBarMaterial.hidden = true; |
|||
|
|||
_titleBarUnderline = [NSBox new]; |
|||
_titleBarUnderline.boxType = NSBoxSeparator; |
|||
_titleBarUnderline.fillColor = [NSColor underPageBackgroundColor]; |
|||
_titleBarUnderline.hidden = true; |
|||
|
|||
[self addSubview:_titleBarMaterial]; |
|||
[self addSubview:_titleBarUnderline]; |
|||
|
|||
_blurBehind = [NSVisualEffectView new]; |
|||
[_blurBehind setBlendingMode:NSVisualEffectBlendingModeBehindWindow]; |
|||
[_blurBehind setMaterial:NSVisualEffectMaterialLight]; |
|||
[_blurBehind setWantsLayer:true]; |
|||
_blurBehind.hidden = true; |
|||
|
|||
[_blurBehind setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
|||
[_content setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
|||
|
|||
[self addSubview:_blurBehind]; |
|||
[self addSubview:_content]; |
|||
|
|||
[self setWantsLayer:true]; |
|||
return self; |
|||
} |
|||
|
|||
-(void) ShowBlur:(bool)show |
|||
{ |
|||
_blurBehind.hidden = !show; |
|||
} |
|||
|
|||
-(void) ShowTitleBar: (bool) show |
|||
{ |
|||
_titleBarMaterial.hidden = !show; |
|||
_titleBarUnderline.hidden = !show; |
|||
} |
|||
|
|||
-(void) SetTitleBarHeightHint: (double) height |
|||
{ |
|||
_titleBarHeightHint = height; |
|||
|
|||
[self setFrameSize:self.frame.size]; |
|||
} |
|||
|
|||
-(void)setFrameSize:(NSSize)newSize |
|||
{ |
|||
if(_settingSize) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
_settingSize = true; |
|||
[super setFrameSize:newSize]; |
|||
|
|||
auto window = (id <AvnWindowProtocol>) [self window]; |
|||
|
|||
// TODO get actual titlebar size |
|||
|
|||
double height = _titleBarHeightHint == -1 ? [window getExtendedTitleBarHeight] : _titleBarHeightHint; |
|||
|
|||
NSRect tbar; |
|||
tbar.origin.x = 0; |
|||
tbar.origin.y = newSize.height - height; |
|||
tbar.size.width = newSize.width; |
|||
tbar.size.height = height; |
|||
|
|||
[_titleBarMaterial setFrame:tbar]; |
|||
tbar.size.height = height < 1 ? 0 : 1; |
|||
[_titleBarUnderline setFrame:tbar]; |
|||
|
|||
_settingSize = false; |
|||
} |
|||
@end |
|||
@ -0,0 +1,9 @@ |
|||
// |
|||
// Created by Dan Walmsley on 06/05/2022. |
|||
// Copyright (c) 2022 Avalonia. All rights reserved. |
|||
// |
|||
|
|||
#define IS_NSPANEL |
|||
|
|||
#include "AvnWindow.mm" |
|||
|
|||
@ -0,0 +1,27 @@ |
|||
//
|
|||
// Created by Dan Walmsley on 05/05/2022.
|
|||
// Copyright (c) 2022 Avalonia. All rights reserved.
|
|||
//
|
|||
#pragma once |
|||
#import <Foundation/Foundation.h> |
|||
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
#import <AppKit/AppKit.h> |
|||
#include "common.h" |
|||
#include "WindowImpl.h" |
|||
#include "KeyTransform.h" |
|||
|
|||
@class AvnAccessibilityElement; |
|||
|
|||
@interface AvnView : NSView<NSTextInputClient, NSDraggingDestination> |
|||
-(AvnView* _Nonnull) initWithParent: (WindowBaseImpl* _Nonnull) parent; |
|||
-(NSEvent* _Nonnull) lastMouseDownEvent; |
|||
-(AvnPoint) translateLocalPoint:(AvnPoint)pt; |
|||
-(void) setSwRenderedFrame: (AvnFramebuffer* _Nonnull) fb dispose: (IUnknown* _Nonnull) dispose; |
|||
-(void) onClosed; |
|||
|
|||
-(AvnPlatformResizeReason) getResizeReason; |
|||
-(void) setResizeReason:(AvnPlatformResizeReason)reason; |
|||
+ (AvnPoint)toAvnPoint:(CGPoint)p; |
|||
@end |
|||
@ -0,0 +1,721 @@ |
|||
// |
|||
// Created by Dan Walmsley on 05/05/2022. |
|||
// Copyright (c) 2022 Avalonia. All rights reserved. |
|||
// |
|||
|
|||
#import <AppKit/AppKit.h> |
|||
#include "AvnView.h" |
|||
#include "automation.h" |
|||
#import "WindowInterfaces.h" |
|||
|
|||
@implementation AvnView |
|||
{ |
|||
ComPtr<WindowBaseImpl> _parent; |
|||
NSTrackingArea* _area; |
|||
bool _isLeftPressed, _isMiddlePressed, _isRightPressed, _isXButton1Pressed, _isXButton2Pressed; |
|||
AvnInputModifiers _modifierState; |
|||
NSEvent* _lastMouseDownEvent; |
|||
bool _lastKeyHandled; |
|||
AvnPixelSize _lastPixelSize; |
|||
NSObject<IRenderTarget>* _renderTarget; |
|||
AvnPlatformResizeReason _resizeReason; |
|||
AvnAccessibilityElement* _accessibilityChild; |
|||
} |
|||
|
|||
- (void)onClosed |
|||
{ |
|||
@synchronized (self) |
|||
{ |
|||
_parent = nullptr; |
|||
} |
|||
} |
|||
|
|||
- (NSEvent*) lastMouseDownEvent |
|||
{ |
|||
return _lastMouseDownEvent; |
|||
} |
|||
|
|||
- (void) updateRenderTarget |
|||
{ |
|||
[_renderTarget resize:_lastPixelSize withScale:static_cast<float>([[self window] backingScaleFactor])]; |
|||
[self setNeedsDisplayInRect:[self frame]]; |
|||
} |
|||
|
|||
-(AvnView*) initWithParent: (WindowBaseImpl*) parent |
|||
{ |
|||
self = [super init]; |
|||
_renderTarget = parent->renderTarget; |
|||
[self setWantsLayer:YES]; |
|||
[self setLayerContentsRedrawPolicy: NSViewLayerContentsRedrawDuringViewResize]; |
|||
|
|||
_parent = parent; |
|||
_area = nullptr; |
|||
_lastPixelSize.Height = 100; |
|||
_lastPixelSize.Width = 100; |
|||
[self registerForDraggedTypes: @[@"public.data", GetAvnCustomDataType()]]; |
|||
|
|||
_modifierState = AvnInputModifiersNone; |
|||
return self; |
|||
} |
|||
|
|||
- (BOOL)isFlipped |
|||
{ |
|||
return YES; |
|||
} |
|||
|
|||
- (BOOL)wantsUpdateLayer |
|||
{ |
|||
return YES; |
|||
} |
|||
|
|||
- (void)setLayer:(CALayer *)layer |
|||
{ |
|||
[_renderTarget setNewLayer: layer]; |
|||
[super setLayer: layer]; |
|||
} |
|||
|
|||
- (BOOL)isOpaque |
|||
{ |
|||
return YES; |
|||
} |
|||
|
|||
- (BOOL)acceptsFirstResponder |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
- (BOOL)acceptsFirstMouse:(NSEvent *)event |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
- (BOOL)canBecomeKeyView |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
-(void)setFrameSize:(NSSize)newSize |
|||
{ |
|||
[super setFrameSize:newSize]; |
|||
|
|||
if(_area != nullptr) |
|||
{ |
|||
[self removeTrackingArea:_area]; |
|||
_area = nullptr; |
|||
} |
|||
|
|||
if (_parent == nullptr) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
NSRect rect = NSZeroRect; |
|||
rect.size = newSize; |
|||
|
|||
NSTrackingAreaOptions options = NSTrackingActiveAlways | NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited | NSTrackingEnabledDuringMouseDrag; |
|||
_area = [[NSTrackingArea alloc] initWithRect:rect options:options owner:self userInfo:nullptr]; |
|||
[self addTrackingArea:_area]; |
|||
|
|||
_parent->UpdateCursor(); |
|||
|
|||
auto fsize = [self convertSizeToBacking: [self frame].size]; |
|||
|
|||
if(_lastPixelSize.Width != (int)fsize.width || _lastPixelSize.Height != (int)fsize.height) |
|||
{ |
|||
_lastPixelSize.Width = (int)fsize.width; |
|||
_lastPixelSize.Height = (int)fsize.height; |
|||
[self updateRenderTarget]; |
|||
|
|||
auto reason = [self inLiveResize] ? ResizeUser : _resizeReason; |
|||
|
|||
if(_parent->IsShown()) |
|||
{ |
|||
_parent->BaseEvents->Resized(AvnSize{newSize.width, newSize.height}, reason); |
|||
} |
|||
} |
|||
} |
|||
|
|||
- (void)updateLayer |
|||
{ |
|||
AvnInsidePotentialDeadlock deadlock; |
|||
if (_parent == nullptr) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
_parent->BaseEvents->RunRenderPriorityJobs(); |
|||
|
|||
if (_parent == nullptr) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
_parent->BaseEvents->Paint(); |
|||
} |
|||
|
|||
- (void)drawRect:(NSRect)dirtyRect |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
-(void) setSwRenderedFrame: (AvnFramebuffer*) fb dispose: (IUnknown*) dispose |
|||
{ |
|||
@autoreleasepool { |
|||
[_renderTarget setSwFrame:fb]; |
|||
dispose->Release(); |
|||
} |
|||
} |
|||
|
|||
- (AvnPoint) translateLocalPoint:(AvnPoint)pt |
|||
{ |
|||
pt.Y = [self bounds].size.height - pt.Y; |
|||
return pt; |
|||
} |
|||
|
|||
+ (AvnPoint)toAvnPoint:(CGPoint)p |
|||
{ |
|||
AvnPoint result; |
|||
|
|||
result.X = p.x; |
|||
result.Y = p.y; |
|||
|
|||
return result; |
|||
} |
|||
|
|||
- (void) viewDidChangeBackingProperties |
|||
{ |
|||
auto fsize = [self convertSizeToBacking: [self frame].size]; |
|||
_lastPixelSize.Width = (int)fsize.width; |
|||
_lastPixelSize.Height = (int)fsize.height; |
|||
[self updateRenderTarget]; |
|||
|
|||
if(_parent != nullptr) |
|||
{ |
|||
_parent->BaseEvents->ScalingChanged([_parent->Window backingScaleFactor]); |
|||
} |
|||
|
|||
[super viewDidChangeBackingProperties]; |
|||
} |
|||
|
|||
- (bool) ignoreUserInput:(bool)trigerInputWhenDisabled |
|||
{ |
|||
if(_parent == nullptr) |
|||
{ |
|||
return TRUE; |
|||
} |
|||
|
|||
auto parentWindow = _parent->GetWindowProtocol(); |
|||
|
|||
if(parentWindow == nil || ![parentWindow shouldTryToHandleEvents]) |
|||
{ |
|||
if(trigerInputWhenDisabled) |
|||
{ |
|||
auto window = dynamic_cast<WindowImpl*>(_parent.getRaw()); |
|||
|
|||
if(window != nullptr) |
|||
{ |
|||
window->WindowEvents->GotInputWhenDisabled(); |
|||
} |
|||
} |
|||
|
|||
return TRUE; |
|||
} |
|||
|
|||
return FALSE; |
|||
} |
|||
|
|||
- (void)mouseEvent:(NSEvent *)event withType:(AvnRawMouseEventType) type |
|||
{ |
|||
bool triggerInputWhenDisabled = type != Move && type != LeaveWindow; |
|||
|
|||
if([self ignoreUserInput: triggerInputWhenDisabled]) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
auto localPoint = [self convertPoint:[event locationInWindow] toView:self]; |
|||
auto avnPoint = [AvnView toAvnPoint:localPoint]; |
|||
auto point = [self translateLocalPoint:avnPoint]; |
|||
AvnVector delta = { 0, 0}; |
|||
|
|||
if(type == Wheel) |
|||
{ |
|||
auto speed = 5; |
|||
|
|||
if([event hasPreciseScrollingDeltas]) |
|||
{ |
|||
speed = 50; |
|||
} |
|||
|
|||
delta.X = [event scrollingDeltaX] / speed; |
|||
delta.Y = [event scrollingDeltaY] / speed; |
|||
|
|||
if(delta.X == 0 && delta.Y == 0) |
|||
{ |
|||
return; |
|||
} |
|||
} |
|||
else if (type == Magnify) |
|||
{ |
|||
delta.X = delta.Y = [event magnification]; |
|||
} |
|||
else if (type == Rotate) |
|||
{ |
|||
delta.X = delta.Y = [event rotation]; |
|||
} |
|||
else if (type == Swipe) |
|||
{ |
|||
delta.X = [event deltaX]; |
|||
delta.Y = [event deltaY]; |
|||
} |
|||
|
|||
uint32 timestamp = static_cast<uint32>([event timestamp] * 1000); |
|||
auto modifiers = [self getModifiers:[event modifierFlags]]; |
|||
|
|||
if(type != Move || |
|||
( |
|||
[self window] != nil && |
|||
( |
|||
[[self window] firstResponder] == nil |
|||
|| ![[[self window] firstResponder] isKindOfClass: [NSView class]] |
|||
) |
|||
) |
|||
) |
|||
[self becomeFirstResponder]; |
|||
|
|||
if(_parent != nullptr) |
|||
{ |
|||
_parent->BaseEvents->RawMouseEvent(type, timestamp, modifiers, point, delta); |
|||
} |
|||
|
|||
[super mouseMoved:event]; |
|||
} |
|||
|
|||
- (BOOL) resignFirstResponder |
|||
{ |
|||
_parent->BaseEvents->LostFocus(); |
|||
return YES; |
|||
} |
|||
|
|||
- (void)mouseMoved:(NSEvent *)event |
|||
{ |
|||
[self mouseEvent:event withType:Move]; |
|||
} |
|||
|
|||
- (void)mouseDown:(NSEvent *)event |
|||
{ |
|||
_isLeftPressed = true; |
|||
_lastMouseDownEvent = event; |
|||
[self mouseEvent:event withType:LeftButtonDown]; |
|||
} |
|||
|
|||
- (void)otherMouseDown:(NSEvent *)event |
|||
{ |
|||
_lastMouseDownEvent = event; |
|||
|
|||
switch(event.buttonNumber) |
|||
{ |
|||
case 2: |
|||
case 3: |
|||
_isMiddlePressed = true; |
|||
[self mouseEvent:event withType:MiddleButtonDown]; |
|||
break; |
|||
case 4: |
|||
_isXButton1Pressed = true; |
|||
[self mouseEvent:event withType:XButton1Down]; |
|||
break; |
|||
case 5: |
|||
_isXButton2Pressed = true; |
|||
[self mouseEvent:event withType:XButton2Down]; |
|||
break; |
|||
|
|||
default: |
|||
break; |
|||
} |
|||
} |
|||
|
|||
- (void)rightMouseDown:(NSEvent *)event |
|||
{ |
|||
_isRightPressed = true; |
|||
_lastMouseDownEvent = event; |
|||
[self mouseEvent:event withType:RightButtonDown]; |
|||
} |
|||
|
|||
- (void)mouseUp:(NSEvent *)event |
|||
{ |
|||
_isLeftPressed = false; |
|||
[self mouseEvent:event withType:LeftButtonUp]; |
|||
} |
|||
|
|||
- (void)otherMouseUp:(NSEvent *)event |
|||
{ |
|||
switch(event.buttonNumber) |
|||
{ |
|||
case 2: |
|||
case 3: |
|||
_isMiddlePressed = false; |
|||
[self mouseEvent:event withType:MiddleButtonUp]; |
|||
break; |
|||
case 4: |
|||
_isXButton1Pressed = false; |
|||
[self mouseEvent:event withType:XButton1Up]; |
|||
break; |
|||
case 5: |
|||
_isXButton2Pressed = false; |
|||
[self mouseEvent:event withType:XButton2Up]; |
|||
break; |
|||
|
|||
default: |
|||
break; |
|||
} |
|||
} |
|||
|
|||
- (void)rightMouseUp:(NSEvent *)event |
|||
{ |
|||
_isRightPressed = false; |
|||
[self mouseEvent:event withType:RightButtonUp]; |
|||
} |
|||
|
|||
- (void)mouseDragged:(NSEvent *)event |
|||
{ |
|||
[self mouseEvent:event withType:Move]; |
|||
[super mouseDragged:event]; |
|||
} |
|||
|
|||
- (void)otherMouseDragged:(NSEvent *)event |
|||
{ |
|||
[self mouseEvent:event withType:Move]; |
|||
[super otherMouseDragged:event]; |
|||
} |
|||
|
|||
- (void)rightMouseDragged:(NSEvent *)event |
|||
{ |
|||
[self mouseEvent:event withType:Move]; |
|||
[super rightMouseDragged:event]; |
|||
} |
|||
|
|||
- (void)scrollWheel:(NSEvent *)event |
|||
{ |
|||
[self mouseEvent:event withType:Wheel]; |
|||
[super scrollWheel:event]; |
|||
} |
|||
|
|||
- (void)magnifyWithEvent:(NSEvent *)event |
|||
{ |
|||
[self mouseEvent:event withType:Magnify]; |
|||
[super magnifyWithEvent:event]; |
|||
} |
|||
|
|||
- (void)rotateWithEvent:(NSEvent *)event |
|||
{ |
|||
[self mouseEvent:event withType:Rotate]; |
|||
[super rotateWithEvent:event]; |
|||
} |
|||
|
|||
- (void)swipeWithEvent:(NSEvent *)event |
|||
{ |
|||
[self mouseEvent:event withType:Swipe]; |
|||
[super swipeWithEvent:event]; |
|||
} |
|||
|
|||
- (void)mouseEntered:(NSEvent *)event |
|||
{ |
|||
[super mouseEntered:event]; |
|||
} |
|||
|
|||
- (void)mouseExited:(NSEvent *)event |
|||
{ |
|||
[self mouseEvent:event withType:LeaveWindow]; |
|||
[super mouseExited:event]; |
|||
} |
|||
|
|||
- (void) keyboardEvent: (NSEvent *) event withType: (AvnRawKeyEventType)type |
|||
{ |
|||
if([self ignoreUserInput: false]) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
auto key = s_KeyMap[[event keyCode]]; |
|||
|
|||
uint32_t timestamp = static_cast<uint32_t>([event timestamp] * 1000); |
|||
auto modifiers = [self getModifiers:[event modifierFlags]]; |
|||
|
|||
if(_parent != nullptr) |
|||
{ |
|||
auto handled = _parent->BaseEvents->RawKeyEvent(type, timestamp, modifiers, key); |
|||
if (key != LeftCtrl && key != RightCtrl) { |
|||
_lastKeyHandled = handled; |
|||
} else { |
|||
_lastKeyHandled = false; |
|||
} |
|||
} |
|||
} |
|||
|
|||
- (BOOL)performKeyEquivalent:(NSEvent *)event |
|||
{ |
|||
bool result = _lastKeyHandled; |
|||
|
|||
_lastKeyHandled = false; |
|||
|
|||
return result; |
|||
} |
|||
|
|||
- (void)flagsChanged:(NSEvent *)event |
|||
{ |
|||
auto newModifierState = [self getModifiers:[event modifierFlags]]; |
|||
|
|||
bool isAltCurrentlyPressed = (_modifierState & Alt) == Alt; |
|||
bool isControlCurrentlyPressed = (_modifierState & Control) == Control; |
|||
bool isShiftCurrentlyPressed = (_modifierState & Shift) == Shift; |
|||
bool isCommandCurrentlyPressed = (_modifierState & Windows) == Windows; |
|||
|
|||
bool isAltPressed = (newModifierState & Alt) == Alt; |
|||
bool isControlPressed = (newModifierState & Control) == Control; |
|||
bool isShiftPressed = (newModifierState & Shift) == Shift; |
|||
bool isCommandPressed = (newModifierState & Windows) == Windows; |
|||
|
|||
|
|||
if (isAltPressed && !isAltCurrentlyPressed) |
|||
{ |
|||
[self keyboardEvent:event withType:KeyDown]; |
|||
} |
|||
else if (isAltCurrentlyPressed && !isAltPressed) |
|||
{ |
|||
[self keyboardEvent:event withType:KeyUp]; |
|||
} |
|||
|
|||
if (isControlPressed && !isControlCurrentlyPressed) |
|||
{ |
|||
[self keyboardEvent:event withType:KeyDown]; |
|||
} |
|||
else if (isControlCurrentlyPressed && !isControlPressed) |
|||
{ |
|||
[self keyboardEvent:event withType:KeyUp]; |
|||
} |
|||
|
|||
if (isShiftPressed && !isShiftCurrentlyPressed) |
|||
{ |
|||
[self keyboardEvent:event withType:KeyDown]; |
|||
} |
|||
else if(isShiftCurrentlyPressed && !isShiftPressed) |
|||
{ |
|||
[self keyboardEvent:event withType:KeyUp]; |
|||
} |
|||
|
|||
if(isCommandPressed && !isCommandCurrentlyPressed) |
|||
{ |
|||
[self keyboardEvent:event withType:KeyDown]; |
|||
} |
|||
else if(isCommandCurrentlyPressed && ! isCommandPressed) |
|||
{ |
|||
[self keyboardEvent:event withType:KeyUp]; |
|||
} |
|||
|
|||
_modifierState = newModifierState; |
|||
|
|||
[[self inputContext] handleEvent:event]; |
|||
[super flagsChanged:event]; |
|||
} |
|||
|
|||
- (void)keyDown:(NSEvent *)event |
|||
{ |
|||
[self keyboardEvent:event withType:KeyDown]; |
|||
[[self inputContext] handleEvent:event]; |
|||
[super keyDown:event]; |
|||
} |
|||
|
|||
- (void)keyUp:(NSEvent *)event |
|||
{ |
|||
[self keyboardEvent:event withType:KeyUp]; |
|||
[super keyUp:event]; |
|||
} |
|||
|
|||
- (AvnInputModifiers)getModifiers:(NSEventModifierFlags)mod |
|||
{ |
|||
unsigned int rv = 0; |
|||
|
|||
if (mod & NSEventModifierFlagControl) |
|||
rv |= Control; |
|||
if (mod & NSEventModifierFlagShift) |
|||
rv |= Shift; |
|||
if (mod & NSEventModifierFlagOption) |
|||
rv |= Alt; |
|||
if (mod & NSEventModifierFlagCommand) |
|||
rv |= Windows; |
|||
|
|||
if (_isLeftPressed) |
|||
rv |= LeftMouseButton; |
|||
if (_isMiddlePressed) |
|||
rv |= MiddleMouseButton; |
|||
if (_isRightPressed) |
|||
rv |= RightMouseButton; |
|||
if (_isXButton1Pressed) |
|||
rv |= XButton1MouseButton; |
|||
if (_isXButton2Pressed) |
|||
rv |= XButton2MouseButton; |
|||
|
|||
return (AvnInputModifiers)rv; |
|||
} |
|||
|
|||
- (BOOL)hasMarkedText |
|||
{ |
|||
return _lastKeyHandled; |
|||
} |
|||
|
|||
- (NSRange)markedRange |
|||
{ |
|||
return NSMakeRange(NSNotFound, 0); |
|||
} |
|||
|
|||
- (NSRange)selectedRange |
|||
{ |
|||
return NSMakeRange(NSNotFound, 0); |
|||
} |
|||
|
|||
- (void)setMarkedText:(id)string selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange |
|||
{ |
|||
|
|||
} |
|||
|
|||
- (void)unmarkText |
|||
{ |
|||
|
|||
} |
|||
|
|||
- (NSArray<NSString *> *)validAttributesForMarkedText |
|||
{ |
|||
return [NSArray new]; |
|||
} |
|||
|
|||
- (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)range actualRange:(NSRangePointer)actualRange |
|||
{ |
|||
return [NSAttributedString new]; |
|||
} |
|||
|
|||
- (void)insertText:(id)string replacementRange:(NSRange)replacementRange |
|||
{ |
|||
if(!_lastKeyHandled) |
|||
{ |
|||
if(_parent != nullptr) |
|||
{ |
|||
_lastKeyHandled = _parent->BaseEvents->RawTextInputEvent(0, [string UTF8String]); |
|||
} |
|||
} |
|||
} |
|||
|
|||
- (NSUInteger)characterIndexForPoint:(NSPoint)point |
|||
{ |
|||
return 0; |
|||
} |
|||
|
|||
- (NSRect)firstRectForCharacterRange:(NSRange)range actualRange:(NSRangePointer)actualRange |
|||
{ |
|||
CGRect result = { 0 }; |
|||
|
|||
return result; |
|||
} |
|||
|
|||
- (NSDragOperation)triggerAvnDragEvent: (AvnDragEventType) type info: (id <NSDraggingInfo>)info |
|||
{ |
|||
auto localPoint = [self convertPoint:[info draggingLocation] toView:self]; |
|||
auto avnPoint = [AvnView toAvnPoint:localPoint]; |
|||
auto point = [self translateLocalPoint:avnPoint]; |
|||
auto modifiers = [self getModifiers:[[NSApp currentEvent] modifierFlags]]; |
|||
NSDragOperation nsop = [info draggingSourceOperationMask]; |
|||
|
|||
auto effects = ConvertDragDropEffects(nsop); |
|||
int reffects = (int)_parent->BaseEvents |
|||
->DragEvent(type, point, modifiers, effects, |
|||
CreateClipboard([info draggingPasteboard], nil), |
|||
GetAvnDataObjectHandleFromDraggingInfo(info)); |
|||
|
|||
NSDragOperation ret = static_cast<NSDragOperation>(0); |
|||
|
|||
// Ensure that the managed part didn't add any new effects |
|||
reffects = (int)effects & reffects; |
|||
|
|||
// OSX requires exactly one operation |
|||
if((reffects & (int)AvnDragDropEffects::Copy) != 0) |
|||
ret = NSDragOperationCopy; |
|||
else if((reffects & (int)AvnDragDropEffects::Move) != 0) |
|||
ret = NSDragOperationMove; |
|||
else if((reffects & (int)AvnDragDropEffects::Link) != 0) |
|||
ret = NSDragOperationLink; |
|||
if(ret == 0) |
|||
ret = NSDragOperationNone; |
|||
return ret; |
|||
} |
|||
|
|||
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender |
|||
{ |
|||
return [self triggerAvnDragEvent: AvnDragEventType::Enter info:sender]; |
|||
} |
|||
|
|||
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender |
|||
{ |
|||
return [self triggerAvnDragEvent: AvnDragEventType::Over info:sender]; |
|||
} |
|||
|
|||
- (void)draggingExited:(id <NSDraggingInfo>)sender |
|||
{ |
|||
[self triggerAvnDragEvent: AvnDragEventType::Leave info:sender]; |
|||
} |
|||
|
|||
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender |
|||
{ |
|||
return [self triggerAvnDragEvent: AvnDragEventType::Over info:sender] != NSDragOperationNone; |
|||
} |
|||
|
|||
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender |
|||
{ |
|||
return [self triggerAvnDragEvent: AvnDragEventType::Drop info:sender] != NSDragOperationNone; |
|||
} |
|||
|
|||
- (void)concludeDragOperation:(nullable id <NSDraggingInfo>)sender |
|||
{ |
|||
|
|||
} |
|||
|
|||
- (AvnPlatformResizeReason)getResizeReason |
|||
{ |
|||
return _resizeReason; |
|||
} |
|||
|
|||
- (void)setResizeReason:(AvnPlatformResizeReason)reason |
|||
{ |
|||
_resizeReason = reason; |
|||
} |
|||
|
|||
- (AvnAccessibilityElement *) accessibilityChild |
|||
{ |
|||
if (_accessibilityChild == nil) |
|||
{ |
|||
auto peer = _parent->BaseEvents->GetAutomationPeer(); |
|||
|
|||
if (peer == nil) |
|||
return nil; |
|||
|
|||
_accessibilityChild = [AvnAccessibilityElement acquire:peer]; |
|||
} |
|||
|
|||
return _accessibilityChild; |
|||
} |
|||
|
|||
- (NSArray *)accessibilityChildren |
|||
{ |
|||
auto child = [self accessibilityChild]; |
|||
return NSAccessibilityUnignoredChildrenForOnlyChild(child); |
|||
} |
|||
|
|||
- (id)accessibilityHitTest:(NSPoint)point |
|||
{ |
|||
return [[self accessibilityChild] accessibilityHitTest:point]; |
|||
} |
|||
|
|||
- (id)accessibilityFocusedUIElement |
|||
{ |
|||
return [[self accessibilityChild] accessibilityFocusedUIElement]; |
|||
} |
|||
|
|||
@end |
|||
@ -0,0 +1,484 @@ |
|||
// |
|||
// Created by Dan Walmsley on 06/05/2022. |
|||
// Copyright (c) 2022 Avalonia. All rights reserved. |
|||
// |
|||
|
|||
|
|||
#import <AppKit/AppKit.h> |
|||
#import "WindowProtocol.h" |
|||
#import "WindowBaseImpl.h" |
|||
|
|||
#ifdef IS_NSPANEL |
|||
#define BASE_CLASS NSPanel |
|||
#define CLASS_NAME AvnPanel |
|||
#else |
|||
#define BASE_CLASS NSWindow |
|||
#define CLASS_NAME AvnWindow |
|||
#endif |
|||
|
|||
#import <AppKit/AppKit.h> |
|||
#include "common.h" |
|||
#include "menu.h" |
|||
#include "automation.h" |
|||
#include "WindowBaseImpl.h" |
|||
#include "WindowImpl.h" |
|||
#include "AvnView.h" |
|||
#include "WindowInterfaces.h" |
|||
#include "PopupImpl.h" |
|||
|
|||
@implementation CLASS_NAME |
|||
{ |
|||
ComPtr<WindowBaseImpl> _parent; |
|||
bool _closed; |
|||
bool _isEnabled; |
|||
bool _canBecomeKeyWindow; |
|||
bool _isExtended; |
|||
bool _isTransitioningToFullScreen; |
|||
AvnMenu* _menu; |
|||
} |
|||
|
|||
-(void) setIsExtended:(bool)value; |
|||
{ |
|||
_isExtended = value; |
|||
} |
|||
|
|||
-(bool) isDialog |
|||
{ |
|||
return _parent->IsDialog(); |
|||
} |
|||
|
|||
-(double) getExtendedTitleBarHeight |
|||
{ |
|||
if(_isExtended) |
|||
{ |
|||
for (id subview in self.contentView.superview.subviews) |
|||
{ |
|||
if ([subview isKindOfClass:NSClassFromString(@"NSTitlebarContainerView")]) |
|||
{ |
|||
NSView *titlebarView = [subview subviews][0]; |
|||
|
|||
return (double)titlebarView.frame.size.height; |
|||
} |
|||
} |
|||
|
|||
return -1; |
|||
} |
|||
else |
|||
{ |
|||
return 0; |
|||
} |
|||
} |
|||
|
|||
- (void)performClose:(id _Nullable )sender |
|||
{ |
|||
if([[self delegate] respondsToSelector:@selector(windowShouldClose:)]) |
|||
{ |
|||
if(![[self delegate] windowShouldClose:self]) return; |
|||
} |
|||
else if([self respondsToSelector:@selector(windowShouldClose:)]) |
|||
{ |
|||
if(![self windowShouldClose:self]) return; |
|||
} |
|||
|
|||
[self close]; |
|||
} |
|||
|
|||
- (void)pollModalSession:(nonnull NSModalSession)session |
|||
{ |
|||
auto response = [NSApp runModalSession:session]; |
|||
|
|||
if(response == NSModalResponseContinue) |
|||
{ |
|||
dispatch_async(dispatch_get_main_queue(), ^{ |
|||
[self pollModalSession:session]; |
|||
}); |
|||
} |
|||
else if (!_closed) |
|||
{ |
|||
[self orderOut:self]; |
|||
[NSApp endModalSession:session]; |
|||
} |
|||
} |
|||
|
|||
-(void) showWindowMenuWithAppMenu |
|||
{ |
|||
if(_menu != nullptr) |
|||
{ |
|||
auto appMenuItem = ::GetAppMenuItem(); |
|||
|
|||
if(appMenuItem != nullptr) |
|||
{ |
|||
auto appMenu = [appMenuItem menu]; |
|||
|
|||
[appMenu removeItem:appMenuItem]; |
|||
|
|||
[_menu insertItem:appMenuItem atIndex:0]; |
|||
|
|||
[_menu setHasGlobalMenuItem:true]; |
|||
} |
|||
|
|||
[NSApp setMenu:_menu]; |
|||
} |
|||
else |
|||
{ |
|||
[self showAppMenuOnly]; |
|||
} |
|||
} |
|||
|
|||
-(void) showAppMenuOnly |
|||
{ |
|||
auto appMenuItem = ::GetAppMenuItem(); |
|||
|
|||
if(appMenuItem != nullptr) |
|||
{ |
|||
auto appMenu = ::GetAppMenu(); |
|||
|
|||
auto nativeAppMenu = dynamic_cast<AvnAppMenu*>(appMenu); |
|||
|
|||
[[appMenuItem menu] removeItem:appMenuItem]; |
|||
|
|||
if(_menu != nullptr) |
|||
{ |
|||
[_menu setHasGlobalMenuItem:false]; |
|||
} |
|||
|
|||
[nativeAppMenu->GetNative() addItem:appMenuItem]; |
|||
|
|||
[NSApp setMenu:nativeAppMenu->GetNative()]; |
|||
} |
|||
} |
|||
|
|||
-(void) applyMenu:(AvnMenu *_Nullable)menu |
|||
{ |
|||
if(menu == nullptr) |
|||
{ |
|||
menu = [AvnMenu new]; |
|||
} |
|||
|
|||
_menu = menu; |
|||
} |
|||
|
|||
-(CLASS_NAME*_Nonnull) initWithParent: (WindowBaseImpl*_Nonnull) parent contentRect: (NSRect)contentRect styleMask: (NSWindowStyleMask)styleMask; |
|||
{ |
|||
// https://jameshfisher.com/2020/07/10/why-is-the-contentrect-of-my-nswindow-ignored/ |
|||
// create nswindow with specific contentRect, otherwise we wont be able to resize the window |
|||
// until several ms after the window is physically on the screen. |
|||
self = [super initWithContentRect:contentRect styleMask: styleMask backing:NSBackingStoreBuffered defer:false]; |
|||
|
|||
[self setReleasedWhenClosed:false]; |
|||
_parent = parent; |
|||
[self setDelegate:self]; |
|||
_closed = false; |
|||
_isEnabled = true; |
|||
|
|||
[self backingScaleFactor]; |
|||
[self setOpaque:NO]; |
|||
[self setBackgroundColor: [NSColor clearColor]]; |
|||
|
|||
_isExtended = false; |
|||
_isTransitioningToFullScreen = false; |
|||
|
|||
if(self.isDialog) |
|||
{ |
|||
[self setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces|NSWindowCollectionBehaviorFullScreenAuxiliary]; |
|||
} |
|||
|
|||
return self; |
|||
} |
|||
|
|||
- (BOOL)windowShouldClose:(NSWindow *_Nonnull)sender |
|||
{ |
|||
auto window = dynamic_cast<WindowImpl*>(_parent.getRaw()); |
|||
|
|||
if(window != nullptr) |
|||
{ |
|||
return !window->WindowEvents->Closing(); |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
- (void)windowDidChangeBackingProperties:(NSNotification *_Nonnull)notification |
|||
{ |
|||
[self backingScaleFactor]; |
|||
} |
|||
|
|||
|
|||
|
|||
- (void)windowWillClose:(NSNotification *_Nonnull)notification |
|||
{ |
|||
_closed = true; |
|||
if(_parent) |
|||
{ |
|||
ComPtr<WindowBaseImpl> parent = _parent; |
|||
_parent = NULL; |
|||
|
|||
auto window = dynamic_cast<WindowImpl*>(parent.getRaw()); |
|||
|
|||
if(window != nullptr) |
|||
{ |
|||
window->SetParent(nullptr); |
|||
} |
|||
|
|||
parent->BaseEvents->Closed(); |
|||
[parent->View onClosed]; |
|||
} |
|||
} |
|||
|
|||
-(BOOL)canBecomeKeyWindow |
|||
{ |
|||
if(_canBecomeKeyWindow) |
|||
{ |
|||
// If the window has a child window being shown as a dialog then don't allow it to become the key window. |
|||
auto parent = dynamic_cast<WindowImpl*>(_parent.getRaw()); |
|||
|
|||
if(parent != nullptr) |
|||
{ |
|||
return parent->CanBecomeKeyWindow(); |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
#ifndef IS_NSPANEL |
|||
-(BOOL)canBecomeMainWindow |
|||
{ |
|||
return true; |
|||
} |
|||
#endif |
|||
|
|||
-(void)setCanBecomeKeyWindow:(bool)value |
|||
{ |
|||
_canBecomeKeyWindow = value; |
|||
} |
|||
|
|||
-(bool)shouldTryToHandleEvents |
|||
{ |
|||
return _isEnabled; |
|||
} |
|||
|
|||
-(void) setEnabled:(bool)enable |
|||
{ |
|||
_isEnabled = enable; |
|||
|
|||
[[self standardWindowButton:NSWindowCloseButton] setEnabled:enable]; |
|||
[[self standardWindowButton:NSWindowMiniaturizeButton] setEnabled:enable]; |
|||
[[self standardWindowButton:NSWindowZoomButton] setEnabled:enable]; |
|||
} |
|||
|
|||
-(void)becomeKeyWindow |
|||
{ |
|||
[self showWindowMenuWithAppMenu]; |
|||
|
|||
if(_parent != nullptr) |
|||
{ |
|||
_parent->BaseEvents->Activated(); |
|||
} |
|||
|
|||
[super becomeKeyWindow]; |
|||
} |
|||
|
|||
- (void)windowDidBecomeKey:(NSNotification *_Nonnull)notification |
|||
{ |
|||
_parent->BringToFront(); |
|||
|
|||
dispatch_async(dispatch_get_main_queue(), ^{ |
|||
@try { |
|||
[self invalidateShadow]; |
|||
} |
|||
@finally{ |
|||
} |
|||
}); |
|||
} |
|||
|
|||
- (void)windowDidMiniaturize:(NSNotification *_Nonnull)notification |
|||
{ |
|||
auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->()); |
|||
|
|||
if(parent != nullptr) |
|||
{ |
|||
parent->WindowStateChanged(); |
|||
} |
|||
} |
|||
|
|||
- (void)windowDidDeminiaturize:(NSNotification *_Nonnull)notification |
|||
{ |
|||
auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->()); |
|||
|
|||
if(parent != nullptr) |
|||
{ |
|||
parent->WindowStateChanged(); |
|||
} |
|||
} |
|||
|
|||
- (void)windowDidResize:(NSNotification *_Nonnull)notification |
|||
{ |
|||
auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->()); |
|||
|
|||
if(parent != nullptr) |
|||
{ |
|||
parent->WindowStateChanged(); |
|||
} |
|||
} |
|||
|
|||
- (void)windowWillExitFullScreen:(NSNotification *_Nonnull)notification |
|||
{ |
|||
auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->()); |
|||
|
|||
if(parent != nullptr) |
|||
{ |
|||
parent->StartStateTransition(); |
|||
} |
|||
} |
|||
|
|||
- (void)windowDidExitFullScreen:(NSNotification *_Nonnull)notification |
|||
{ |
|||
auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->()); |
|||
|
|||
if(parent != nullptr) |
|||
{ |
|||
parent->EndStateTransition(); |
|||
|
|||
if(parent->Decorations() != SystemDecorationsFull && parent->WindowState() == Maximized) |
|||
{ |
|||
NSRect screenRect = [[self screen] visibleFrame]; |
|||
[self setFrame:screenRect display:YES]; |
|||
} |
|||
|
|||
if(parent->WindowState() == Minimized) |
|||
{ |
|||
[self miniaturize:nullptr]; |
|||
} |
|||
|
|||
parent->WindowStateChanged(); |
|||
} |
|||
} |
|||
|
|||
- (void)windowWillEnterFullScreen:(NSNotification *_Nonnull)notification |
|||
{ |
|||
_isTransitioningToFullScreen = true; |
|||
auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->()); |
|||
|
|||
if(parent != nullptr) |
|||
{ |
|||
parent->StartStateTransition(); |
|||
} |
|||
} |
|||
|
|||
- (void)windowDidEnterFullScreen:(NSNotification *_Nonnull)notification |
|||
{ |
|||
_isTransitioningToFullScreen = false; |
|||
auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->()); |
|||
|
|||
if(parent != nullptr) |
|||
{ |
|||
parent->EndStateTransition(); |
|||
parent->WindowStateChanged(); |
|||
} |
|||
} |
|||
|
|||
- (BOOL)windowShouldZoom:(NSWindow *_Nonnull)window toFrame:(NSRect)newFrame |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
-(void)windowDidResignKey:(NSNotification *)notification |
|||
{ |
|||
if(_parent) |
|||
_parent->BaseEvents->Deactivated(); |
|||
|
|||
[self showAppMenuOnly]; |
|||
|
|||
[self invalidateShadow]; |
|||
} |
|||
|
|||
- (void)windowDidMove:(NSNotification *_Nonnull)notification |
|||
{ |
|||
AvnPoint position; |
|||
|
|||
if(_parent != nullptr) |
|||
{ |
|||
auto cparent = dynamic_cast<WindowImpl*>(_parent.getRaw()); |
|||
|
|||
if(cparent != nullptr) |
|||
{ |
|||
if(!cparent->IsShown()) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
if(cparent->WindowState() == Maximized) |
|||
{ |
|||
cparent->SetWindowState(Normal); |
|||
} |
|||
} |
|||
|
|||
_parent->GetPosition(&position); |
|||
_parent->BaseEvents->PositionChanged(position); |
|||
} |
|||
} |
|||
|
|||
- (AvnPoint) translateLocalPoint:(AvnPoint)pt |
|||
{ |
|||
pt.Y = [self frame].size.height - pt.Y; |
|||
return pt; |
|||
} |
|||
|
|||
- (void)sendEvent:(NSEvent *_Nonnull)event |
|||
{ |
|||
[super sendEvent:event]; |
|||
|
|||
/// This is to detect non-client clicks. This can only be done on Windows... not popups, hence the dynamic_cast. |
|||
if(_parent != nullptr && dynamic_cast<WindowImpl*>(_parent.getRaw()) != nullptr) |
|||
{ |
|||
switch(event.type) |
|||
{ |
|||
case NSEventTypeLeftMouseDown: |
|||
{ |
|||
AvnView* view = _parent->View; |
|||
NSPoint windowPoint = [event locationInWindow]; |
|||
NSPoint viewPoint = [view convertPoint:windowPoint fromView:nil]; |
|||
|
|||
if (!NSPointInRect(viewPoint, view.bounds)) |
|||
{ |
|||
auto avnPoint = [AvnView toAvnPoint:windowPoint]; |
|||
auto point = [self translateLocalPoint:avnPoint]; |
|||
AvnVector delta = { 0, 0 }; |
|||
|
|||
_parent->BaseEvents->RawMouseEvent(NonClientLeftButtonDown, static_cast<uint32>([event timestamp] * 1000), AvnInputModifiersNone, point, delta); |
|||
} |
|||
|
|||
if(!_isTransitioningToFullScreen) |
|||
{ |
|||
_parent->BringToFront(); |
|||
} |
|||
} |
|||
break; |
|||
|
|||
case NSEventTypeMouseEntered: |
|||
{ |
|||
_parent->UpdateCursor(); |
|||
} |
|||
break; |
|||
|
|||
case NSEventTypeMouseExited: |
|||
{ |
|||
[[NSCursor arrowCursor] set]; |
|||
} |
|||
break; |
|||
|
|||
default: |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
- (void)disconnectParent { |
|||
_parent = nullptr; |
|||
} |
|||
|
|||
@end |
|||
|
|||
@ -0,0 +1,17 @@ |
|||
//
|
|||
// Created by Dan Walmsley on 04/05/2022.
|
|||
// Copyright (c) 2022 Avalonia. All rights reserved.
|
|||
//
|
|||
|
|||
#ifndef AVALONIA_NATIVE_OSX_INSWINDOWHOLDER_H |
|||
#define AVALONIA_NATIVE_OSX_INSWINDOWHOLDER_H |
|||
|
|||
@class AvnView; |
|||
|
|||
struct INSWindowHolder |
|||
{ |
|||
virtual NSWindow* _Nonnull GetNSWindow () = 0; |
|||
virtual AvnView* _Nonnull GetNSView () = 0; |
|||
}; |
|||
|
|||
#endif //AVALONIA_NATIVE_OSX_INSWINDOWHOLDER_H
|
|||
@ -0,0 +1,18 @@ |
|||
//
|
|||
// Created by Dan Walmsley on 04/05/2022.
|
|||
// Copyright (c) 2022 Avalonia. All rights reserved.
|
|||
//
|
|||
|
|||
#ifndef AVALONIA_NATIVE_OSX_IWINDOWSTATECHANGED_H |
|||
#define AVALONIA_NATIVE_OSX_IWINDOWSTATECHANGED_H |
|||
|
|||
struct IWindowStateChanged |
|||
{ |
|||
virtual void WindowStateChanged () = 0; |
|||
virtual void StartStateTransition () = 0; |
|||
virtual void EndStateTransition () = 0; |
|||
virtual SystemDecorations Decorations () = 0; |
|||
virtual AvnWindowState WindowState () = 0; |
|||
}; |
|||
|
|||
#endif //AVALONIA_NATIVE_OSX_IWINDOWSTATECHANGED_H
|
|||
@ -0,0 +1,9 @@ |
|||
//
|
|||
// Created by Dan Walmsley on 06/05/2022.
|
|||
// Copyright (c) 2022 Avalonia. All rights reserved.
|
|||
//
|
|||
|
|||
#ifndef AVALONIA_NATIVE_OSX_POPUPIMPL_H |
|||
#define AVALONIA_NATIVE_OSX_POPUPIMPL_H |
|||
|
|||
#endif //AVALONIA_NATIVE_OSX_POPUPIMPL_H
|
|||
@ -0,0 +1,57 @@ |
|||
// |
|||
// Created by Dan Walmsley on 06/05/2022. |
|||
// Copyright (c) 2022 Avalonia. All rights reserved. |
|||
// |
|||
|
|||
#include "WindowInterfaces.h" |
|||
#include "AvnView.h" |
|||
#include "WindowImpl.h" |
|||
#include "automation.h" |
|||
#include "menu.h" |
|||
#include "common.h" |
|||
#import "WindowBaseImpl.h" |
|||
#import "WindowProtocol.h" |
|||
#import <AppKit/AppKit.h> |
|||
#include "PopupImpl.h" |
|||
|
|||
class PopupImpl : public virtual WindowBaseImpl, public IAvnPopup |
|||
{ |
|||
private: |
|||
BEGIN_INTERFACE_MAP() |
|||
INHERIT_INTERFACE_MAP(WindowBaseImpl) |
|||
INTERFACE_MAP_ENTRY(IAvnPopup, IID_IAvnPopup) |
|||
END_INTERFACE_MAP() |
|||
virtual ~PopupImpl(){} |
|||
ComPtr<IAvnWindowEvents> WindowEvents; |
|||
PopupImpl(IAvnWindowEvents* events, IAvnGlContext* gl) : WindowBaseImpl(events, gl) |
|||
{ |
|||
WindowEvents = events; |
|||
[Window setLevel:NSPopUpMenuWindowLevel]; |
|||
} |
|||
protected: |
|||
virtual NSWindowStyleMask GetStyle() override |
|||
{ |
|||
return NSWindowStyleMaskBorderless; |
|||
} |
|||
|
|||
public: |
|||
virtual bool ShouldTakeFocusOnShow() override |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
virtual HRESULT Show(bool activate, bool isDialog) override |
|||
{ |
|||
return WindowBaseImpl::Show(activate, true); |
|||
} |
|||
}; |
|||
|
|||
|
|||
extern IAvnPopup* CreateAvnPopup(IAvnWindowEvents*events, IAvnGlContext* gl) |
|||
{ |
|||
@autoreleasepool |
|||
{ |
|||
IAvnPopup* ptr = dynamic_cast<IAvnPopup*>(new PopupImpl(events, gl)); |
|||
return ptr; |
|||
} |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
//
|
|||
// Created by Dan Walmsley on 04/05/2022.
|
|||
// Copyright (c) 2022 Avalonia. All rights reserved.
|
|||
//
|
|||
|
|||
#ifndef AVALONIA_NATIVE_OSX_RESIZESCOPE_H |
|||
#define AVALONIA_NATIVE_OSX_RESIZESCOPE_H |
|||
|
|||
#include "avalonia-native.h" |
|||
|
|||
@class AvnView; |
|||
|
|||
class ResizeScope |
|||
{ |
|||
public: |
|||
ResizeScope(AvnView* _Nonnull view, AvnPlatformResizeReason reason); |
|||
|
|||
~ResizeScope(); |
|||
private: |
|||
AvnView* _Nonnull _view; |
|||
AvnPlatformResizeReason _restore; |
|||
}; |
|||
|
|||
#endif //AVALONIA_NATIVE_OSX_RESIZESCOPE_H
|
|||
@ -0,0 +1,18 @@ |
|||
// |
|||
// Created by Dan Walmsley on 04/05/2022. |
|||
// Copyright (c) 2022 Avalonia. All rights reserved. |
|||
// |
|||
|
|||
#import <AppKit/AppKit.h> |
|||
#include "ResizeScope.h" |
|||
#include "AvnView.h" |
|||
|
|||
ResizeScope::ResizeScope(AvnView *view, AvnPlatformResizeReason reason) { |
|||
_view = view; |
|||
_restore = [view getResizeReason]; |
|||
[view setResizeReason:reason]; |
|||
} |
|||
|
|||
ResizeScope::~ResizeScope() { |
|||
[_view setResizeReason:_restore]; |
|||
} |
|||
@ -0,0 +1,135 @@ |
|||
//
|
|||
// Created by Dan Walmsley on 04/05/2022.
|
|||
// Copyright (c) 2022 Avalonia. All rights reserved.
|
|||
//
|
|||
|
|||
#ifndef AVALONIA_NATIVE_OSX_WINDOWBASEIMPL_H |
|||
#define AVALONIA_NATIVE_OSX_WINDOWBASEIMPL_H |
|||
|
|||
#include "rendertarget.h" |
|||
#include "INSWindowHolder.h" |
|||
|
|||
@class AutoFitContentView; |
|||
@class AvnMenu; |
|||
@protocol AvnWindowProtocol; |
|||
|
|||
class WindowBaseImpl : public virtual ComObject, |
|||
public virtual IAvnWindowBase, |
|||
public INSWindowHolder { |
|||
|
|||
public: |
|||
FORWARD_IUNKNOWN() |
|||
|
|||
BEGIN_INTERFACE_MAP() |
|||
INTERFACE_MAP_ENTRY(IAvnWindowBase, IID_IAvnWindowBase) |
|||
END_INTERFACE_MAP() |
|||
|
|||
virtual ~WindowBaseImpl(); |
|||
|
|||
WindowBaseImpl(IAvnWindowBaseEvents *events, IAvnGlContext *gl, bool usePanel = false); |
|||
|
|||
virtual HRESULT ObtainNSWindowHandle(void **ret) override; |
|||
|
|||
virtual HRESULT ObtainNSWindowHandleRetained(void **ret) override; |
|||
|
|||
virtual HRESULT ObtainNSViewHandle(void **ret) override; |
|||
|
|||
virtual HRESULT ObtainNSViewHandleRetained(void **ret) override; |
|||
|
|||
virtual NSWindow *GetNSWindow() override; |
|||
|
|||
virtual AvnView *GetNSView() override; |
|||
|
|||
virtual HRESULT Show(bool activate, bool isDialog) override; |
|||
|
|||
virtual bool IsShown (); |
|||
|
|||
virtual bool ShouldTakeFocusOnShow(); |
|||
|
|||
virtual HRESULT Hide() override; |
|||
|
|||
virtual HRESULT Activate() override; |
|||
|
|||
virtual HRESULT SetTopMost(bool value) override; |
|||
|
|||
virtual HRESULT Close() override; |
|||
|
|||
virtual HRESULT GetClientSize(AvnSize *ret) override; |
|||
|
|||
virtual HRESULT GetFrameSize(AvnSize *ret) override; |
|||
|
|||
virtual HRESULT GetScaling(double *ret) override; |
|||
|
|||
virtual HRESULT SetMinMaxSize(AvnSize minSize, AvnSize maxSize) override; |
|||
|
|||
virtual HRESULT Resize(double x, double y, AvnPlatformResizeReason reason) override; |
|||
|
|||
virtual HRESULT Invalidate(__attribute__((unused)) AvnRect rect) override; |
|||
|
|||
virtual HRESULT SetMainMenu(IAvnMenu *menu) override; |
|||
|
|||
virtual HRESULT BeginMoveDrag() override; |
|||
|
|||
virtual HRESULT BeginResizeDrag(__attribute__((unused)) AvnWindowEdge edge) override; |
|||
|
|||
virtual HRESULT GetPosition(AvnPoint *ret) override; |
|||
|
|||
virtual HRESULT SetPosition(AvnPoint point) override; |
|||
|
|||
virtual HRESULT PointToClient(AvnPoint point, AvnPoint *ret) override; |
|||
|
|||
virtual HRESULT PointToScreen(AvnPoint point, AvnPoint *ret) override; |
|||
|
|||
virtual HRESULT ThreadSafeSetSwRenderedFrame(AvnFramebuffer *fb, IUnknown *dispose) override; |
|||
|
|||
virtual HRESULT SetCursor(IAvnCursor *cursor) override; |
|||
|
|||
virtual void UpdateCursor(); |
|||
|
|||
virtual HRESULT CreateGlRenderTarget(IAvnGlSurfaceRenderTarget **ppv) override; |
|||
|
|||
virtual HRESULT CreateNativeControlHost(IAvnNativeControlHost **retOut) override; |
|||
|
|||
virtual HRESULT SetBlurEnabled(bool enable) override; |
|||
|
|||
virtual HRESULT BeginDragAndDropOperation(AvnDragDropEffects effects, AvnPoint point, |
|||
IAvnClipboard *clipboard, IAvnDndResultCallback *cb, |
|||
void *sourceHandle) override; |
|||
|
|||
virtual bool IsDialog(); |
|||
|
|||
id<AvnWindowProtocol> GetWindowProtocol (); |
|||
|
|||
virtual void BringToFront (); |
|||
|
|||
protected: |
|||
virtual NSWindowStyleMask GetStyle(); |
|||
|
|||
void UpdateStyle(); |
|||
|
|||
private: |
|||
void CreateNSWindow (bool isDialog); |
|||
void CleanNSWindow (); |
|||
|
|||
NSCursor *cursor; |
|||
ComPtr<IAvnGlContext> _glContext; |
|||
bool hasPosition; |
|||
NSSize lastSize; |
|||
NSSize lastMinSize; |
|||
NSSize lastMaxSize; |
|||
AvnMenu* lastMenu; |
|||
bool _inResize; |
|||
|
|||
protected: |
|||
AvnPoint lastPositionSet; |
|||
AutoFitContentView *StandardContainer; |
|||
bool _shown; |
|||
|
|||
public: |
|||
NSObject <IRenderTarget> *renderTarget; |
|||
NSWindow * Window; |
|||
ComPtr<IAvnWindowBaseEvents> BaseEvents; |
|||
AvnView *View; |
|||
}; |
|||
|
|||
#endif //AVALONIA_NATIVE_OSX_WINDOWBASEIMPL_H
|
|||
@ -0,0 +1,603 @@ |
|||
// |
|||
// Created by Dan Walmsley on 04/05/2022. |
|||
// Copyright (c) 2022 Avalonia. All rights reserved. |
|||
// |
|||
|
|||
#import <AppKit/AppKit.h> |
|||
#include "common.h" |
|||
#include "AvnView.h" |
|||
#include "menu.h" |
|||
#include "automation.h" |
|||
#include "cursor.h" |
|||
#include "ResizeScope.h" |
|||
#include "AutoFitContentView.h" |
|||
#import "WindowProtocol.h" |
|||
#import "WindowInterfaces.h" |
|||
#include "WindowBaseImpl.h" |
|||
|
|||
|
|||
WindowBaseImpl::~WindowBaseImpl() { |
|||
View = nullptr; |
|||
Window = nullptr; |
|||
} |
|||
|
|||
WindowBaseImpl::WindowBaseImpl(IAvnWindowBaseEvents *events, IAvnGlContext *gl, bool usePanel) { |
|||
_shown = false; |
|||
_inResize = false; |
|||
BaseEvents = events; |
|||
_glContext = gl; |
|||
renderTarget = [[IOSurfaceRenderTarget alloc] initWithOpenGlContext:gl]; |
|||
View = [[AvnView alloc] initWithParent:this]; |
|||
StandardContainer = [[AutoFitContentView new] initWithContent:View]; |
|||
|
|||
lastPositionSet = { 0, 0 }; |
|||
hasPosition = false; |
|||
lastSize = NSSize { 100, 100 }; |
|||
lastMaxSize = NSSize { CGFLOAT_MAX, CGFLOAT_MAX}; |
|||
lastMinSize = NSSize { 0, 0 }; |
|||
|
|||
lastMenu = nullptr; |
|||
|
|||
CreateNSWindow(usePanel); |
|||
|
|||
[Window setContentView:StandardContainer]; |
|||
[Window setStyleMask:NSWindowStyleMaskBorderless]; |
|||
[Window setBackingType:NSBackingStoreBuffered]; |
|||
|
|||
[Window setContentMinSize:lastMinSize]; |
|||
[Window setContentMaxSize:lastMaxSize]; |
|||
|
|||
[Window setOpaque:false]; |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::ObtainNSViewHandle(void **ret) { |
|||
START_COM_CALL; |
|||
|
|||
if (ret == nullptr) { |
|||
return E_POINTER; |
|||
} |
|||
|
|||
*ret = (__bridge void *) View; |
|||
|
|||
return S_OK; |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::ObtainNSViewHandleRetained(void **ret) { |
|||
START_COM_CALL; |
|||
|
|||
if (ret == nullptr) { |
|||
return E_POINTER; |
|||
} |
|||
|
|||
*ret = (__bridge_retained void *) View; |
|||
|
|||
return S_OK; |
|||
} |
|||
|
|||
NSWindow *WindowBaseImpl::GetNSWindow() { |
|||
return Window; |
|||
} |
|||
|
|||
AvnView *WindowBaseImpl::GetNSView() { |
|||
return View; |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::ObtainNSWindowHandleRetained(void **ret) { |
|||
START_COM_CALL; |
|||
|
|||
if (ret == nullptr) { |
|||
return E_POINTER; |
|||
} |
|||
|
|||
*ret = (__bridge_retained void *) Window; |
|||
|
|||
return S_OK; |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::Show(bool activate, bool isDialog) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
[Window setContentSize:lastSize]; |
|||
|
|||
if(hasPosition) |
|||
{ |
|||
SetPosition(lastPositionSet); |
|||
} else |
|||
{ |
|||
[Window center]; |
|||
} |
|||
|
|||
UpdateStyle(); |
|||
|
|||
[Window invalidateShadow]; |
|||
|
|||
if (ShouldTakeFocusOnShow() && activate) { |
|||
[Window orderFront:Window]; |
|||
[Window makeKeyAndOrderFront:Window]; |
|||
[Window makeFirstResponder:View]; |
|||
[NSApp activateIgnoringOtherApps:YES]; |
|||
} else { |
|||
[Window orderFront:Window]; |
|||
} |
|||
|
|||
_shown = true; |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
bool WindowBaseImpl::IsShown () |
|||
{ |
|||
return _shown; |
|||
} |
|||
|
|||
bool WindowBaseImpl::ShouldTakeFocusOnShow() { |
|||
return true; |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::ObtainNSWindowHandle(void **ret) { |
|||
START_COM_CALL; |
|||
|
|||
if (ret == nullptr) { |
|||
return E_POINTER; |
|||
} |
|||
|
|||
*ret = (__bridge void *) Window; |
|||
|
|||
return S_OK; |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::Hide() { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
if (Window != nullptr) { |
|||
[Window orderOut:Window]; |
|||
} |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::Activate() { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
if (Window != nullptr) { |
|||
[Window makeKeyAndOrderFront:nil]; |
|||
[NSApp activateIgnoringOtherApps:YES]; |
|||
} |
|||
} |
|||
|
|||
return S_OK; |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::SetTopMost(bool value) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
[Window setLevel:value ? NSFloatingWindowLevel : NSNormalWindowLevel]; |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::Close() { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
if (Window != nullptr) { |
|||
auto window = Window; |
|||
Window = nullptr; |
|||
|
|||
try { |
|||
// Seems to throw sometimes on application exit. |
|||
[window close]; |
|||
} |
|||
catch (NSException *) {} |
|||
} |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::GetClientSize(AvnSize *ret) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
if (ret == nullptr) |
|||
return E_POINTER; |
|||
|
|||
ret->Width = lastSize.width; |
|||
ret->Height = lastSize.height; |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::GetFrameSize(AvnSize *ret) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
if (ret == nullptr) |
|||
return E_POINTER; |
|||
|
|||
if(Window != nullptr && _shown){ |
|||
auto frame = [Window frame]; |
|||
ret->Width = frame.size.width; |
|||
ret->Height = frame.size.height; |
|||
} |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::GetScaling(double *ret) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
if (ret == nullptr) |
|||
return E_POINTER; |
|||
|
|||
if (Window == nullptr) { |
|||
*ret = 1; |
|||
return S_OK; |
|||
} |
|||
|
|||
*ret = [Window backingScaleFactor]; |
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::SetMinMaxSize(AvnSize minSize, AvnSize maxSize) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
lastMinSize = ToNSSize(minSize); |
|||
lastMaxSize = ToNSSize(maxSize); |
|||
|
|||
if(Window != nullptr) { |
|||
[Window setContentMinSize:lastMinSize]; |
|||
[Window setContentMaxSize:lastMaxSize]; |
|||
} |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::Resize(double x, double y, AvnPlatformResizeReason reason) { |
|||
if (_inResize) { |
|||
return S_OK; |
|||
} |
|||
|
|||
_inResize = true; |
|||
|
|||
START_COM_CALL; |
|||
auto resizeBlock = ResizeScope(View, reason); |
|||
|
|||
@autoreleasepool { |
|||
auto maxSize = lastMaxSize; |
|||
auto minSize = lastMinSize; |
|||
|
|||
if (x < minSize.width) { |
|||
x = minSize.width; |
|||
} |
|||
|
|||
if (y < minSize.height) { |
|||
y = minSize.height; |
|||
} |
|||
|
|||
if (x > maxSize.width) { |
|||
x = maxSize.width; |
|||
} |
|||
|
|||
if (y > maxSize.height) { |
|||
y = maxSize.height; |
|||
} |
|||
|
|||
@try { |
|||
if(x != lastSize.width || y != lastSize.height) { |
|||
lastSize = NSSize{x, y}; |
|||
|
|||
if (!_shown) { |
|||
BaseEvents->Resized(AvnSize{x, y}, reason); |
|||
} else if (Window != nullptr) { |
|||
[Window setContentSize:lastSize]; |
|||
[Window invalidateShadow]; |
|||
} |
|||
} |
|||
} |
|||
@finally { |
|||
_inResize = false; |
|||
} |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::Invalidate(__attribute__((unused)) AvnRect rect) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
[View setNeedsDisplayInRect:[View frame]]; |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::SetMainMenu(IAvnMenu *menu) { |
|||
START_COM_CALL; |
|||
|
|||
auto nativeMenu = dynamic_cast<AvnAppMenu *>(menu); |
|||
|
|||
lastMenu = nativeMenu->GetNative(); |
|||
|
|||
if(Window != nullptr) { |
|||
[GetWindowProtocol() applyMenu:lastMenu]; |
|||
|
|||
if ([Window isKeyWindow]) { |
|||
[GetWindowProtocol() showWindowMenuWithAppMenu]; |
|||
} |
|||
} |
|||
|
|||
return S_OK; |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::BeginMoveDrag() { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
auto lastEvent = [View lastMouseDownEvent]; |
|||
|
|||
if (lastEvent == nullptr) { |
|||
return S_OK; |
|||
} |
|||
|
|||
[Window performWindowDragWithEvent:lastEvent]; |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::BeginResizeDrag(__attribute__((unused)) AvnWindowEdge edge) { |
|||
START_COM_CALL; |
|||
|
|||
return S_OK; |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::GetPosition(AvnPoint *ret) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
if (ret == nullptr) { |
|||
return E_POINTER; |
|||
} |
|||
|
|||
if(Window != nullptr) { |
|||
auto frame = [Window frame]; |
|||
|
|||
ret->X = frame.origin.x; |
|||
ret->Y = frame.origin.y + frame.size.height; |
|||
|
|||
*ret = ConvertPointY(*ret); |
|||
} else |
|||
{ |
|||
*ret = lastPositionSet; |
|||
} |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::SetPosition(AvnPoint point) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
lastPositionSet = point; |
|||
hasPosition = true; |
|||
|
|||
if(Window != nullptr) { |
|||
[Window setFrameTopLeftPoint:ToNSPoint(ConvertPointY(point))]; |
|||
} |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::PointToClient(AvnPoint point, AvnPoint *ret) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
if (ret == nullptr) { |
|||
return E_POINTER; |
|||
} |
|||
|
|||
point = ConvertPointY(point); |
|||
NSRect convertRect = [Window convertRectFromScreen:NSMakeRect(point.X, point.Y, 0.0, 0.0)]; |
|||
auto viewPoint = NSMakePoint(convertRect.origin.x, convertRect.origin.y); |
|||
|
|||
*ret = [View translateLocalPoint:ToAvnPoint(viewPoint)]; |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::PointToScreen(AvnPoint point, AvnPoint *ret) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
if (ret == nullptr) { |
|||
return E_POINTER; |
|||
} |
|||
|
|||
auto cocoaViewPoint = ToNSPoint([View translateLocalPoint:point]); |
|||
NSRect convertRect = [Window convertRectToScreen:NSMakeRect(cocoaViewPoint.x, cocoaViewPoint.y, 0.0, 0.0)]; |
|||
auto cocoaScreenPoint = NSPointFromCGPoint(NSMakePoint(convertRect.origin.x, convertRect.origin.y)); |
|||
*ret = ConvertPointY(ToAvnPoint(cocoaScreenPoint)); |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::ThreadSafeSetSwRenderedFrame(AvnFramebuffer *fb, IUnknown *dispose) { |
|||
START_COM_CALL; |
|||
|
|||
[View setSwRenderedFrame:fb dispose:dispose]; |
|||
return S_OK; |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::SetCursor(IAvnCursor *cursor) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
Cursor *avnCursor = dynamic_cast<Cursor *>(cursor); |
|||
this->cursor = avnCursor->GetNative(); |
|||
UpdateCursor(); |
|||
|
|||
if (avnCursor->IsHidden()) { |
|||
[NSCursor hide]; |
|||
} else { |
|||
[NSCursor unhide]; |
|||
} |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
void WindowBaseImpl::UpdateCursor() { |
|||
if (cursor != nil) { |
|||
[cursor set]; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::CreateGlRenderTarget(IAvnGlSurfaceRenderTarget **ppv) { |
|||
START_COM_CALL; |
|||
|
|||
if (View == NULL) |
|||
return E_FAIL; |
|||
*ppv = [renderTarget createSurfaceRenderTarget]; |
|||
return static_cast<HRESULT>(*ppv == nil ? E_FAIL : S_OK); |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::CreateNativeControlHost(IAvnNativeControlHost **retOut) { |
|||
START_COM_CALL; |
|||
|
|||
if (View == NULL) |
|||
return E_FAIL; |
|||
*retOut = ::CreateNativeControlHost(View); |
|||
return S_OK; |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::SetBlurEnabled(bool enable) { |
|||
START_COM_CALL; |
|||
|
|||
[StandardContainer ShowBlur:enable]; |
|||
|
|||
return S_OK; |
|||
} |
|||
|
|||
HRESULT WindowBaseImpl::BeginDragAndDropOperation(AvnDragDropEffects effects, AvnPoint point, IAvnClipboard *clipboard, IAvnDndResultCallback *cb, void *sourceHandle) { |
|||
START_COM_CALL; |
|||
|
|||
auto item = TryGetPasteboardItem(clipboard); |
|||
[item setString:@"" forType:GetAvnCustomDataType()]; |
|||
if (item == nil) |
|||
return E_INVALIDARG; |
|||
if (View == NULL) |
|||
return E_FAIL; |
|||
|
|||
auto nsevent = [NSApp currentEvent]; |
|||
auto nseventType = [nsevent type]; |
|||
|
|||
// If current event isn't a mouse one (probably due to malfunctioning user app) |
|||
// attempt to forge a new one |
|||
if (!((nseventType >= NSEventTypeLeftMouseDown && nseventType <= NSEventTypeMouseExited) |
|||
|| (nseventType >= NSEventTypeOtherMouseDown && nseventType <= NSEventTypeOtherMouseDragged))) { |
|||
NSRect convertRect = [Window convertRectToScreen:NSMakeRect(point.X, point.Y, 0.0, 0.0)]; |
|||
auto nspoint = NSMakePoint(convertRect.origin.x, convertRect.origin.y); |
|||
CGPoint cgpoint = NSPointToCGPoint(nspoint); |
|||
auto cgevent = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown, cgpoint, kCGMouseButtonLeft); |
|||
nsevent = [NSEvent eventWithCGEvent:cgevent]; |
|||
CFRelease(cgevent); |
|||
} |
|||
|
|||
auto dragItem = [[NSDraggingItem alloc] initWithPasteboardWriter:item]; |
|||
|
|||
auto dragItemImage = [NSImage imageNamed:NSImageNameMultipleDocuments]; |
|||
NSRect dragItemRect = {(float) point.X, (float) point.Y, [dragItemImage size].width, [dragItemImage size].height}; |
|||
[dragItem setDraggingFrame:dragItemRect contents:dragItemImage]; |
|||
|
|||
int op = 0; |
|||
int ieffects = (int) effects; |
|||
if ((ieffects & (int) AvnDragDropEffects::Copy) != 0) |
|||
op |= NSDragOperationCopy; |
|||
if ((ieffects & (int) AvnDragDropEffects::Link) != 0) |
|||
op |= NSDragOperationLink; |
|||
if ((ieffects & (int) AvnDragDropEffects::Move) != 0) |
|||
op |= NSDragOperationMove; |
|||
[View beginDraggingSessionWithItems:@[dragItem] event:nsevent |
|||
source:CreateDraggingSource((NSDragOperation) op, cb, sourceHandle)]; |
|||
return S_OK; |
|||
} |
|||
|
|||
bool WindowBaseImpl::IsDialog() { |
|||
return false; |
|||
} |
|||
|
|||
NSWindowStyleMask WindowBaseImpl::GetStyle() { |
|||
return NSWindowStyleMaskBorderless; |
|||
} |
|||
|
|||
void WindowBaseImpl::UpdateStyle() { |
|||
[Window setStyleMask:GetStyle()]; |
|||
} |
|||
|
|||
void WindowBaseImpl::CleanNSWindow() { |
|||
if(Window != nullptr) { |
|||
[GetWindowProtocol() disconnectParent]; |
|||
[Window close]; |
|||
Window = nullptr; |
|||
} |
|||
} |
|||
|
|||
void WindowBaseImpl::CreateNSWindow(bool isDialog) { |
|||
if (isDialog) { |
|||
if (![Window isKindOfClass:[AvnPanel class]]) { |
|||
CleanNSWindow(); |
|||
|
|||
Window = [[AvnPanel alloc] initWithParent:this contentRect:NSRect{0, 0, lastSize} styleMask:GetStyle()]; |
|||
|
|||
[Window setHidesOnDeactivate:false]; |
|||
} |
|||
} else { |
|||
if (![Window isKindOfClass:[AvnWindow class]]) { |
|||
CleanNSWindow(); |
|||
|
|||
Window = [[AvnWindow alloc] initWithParent:this contentRect:NSRect{0, 0, lastSize} styleMask:GetStyle()]; |
|||
} |
|||
} |
|||
} |
|||
|
|||
id <AvnWindowProtocol> WindowBaseImpl::GetWindowProtocol() { |
|||
if(Window == nullptr) |
|||
{ |
|||
return nullptr; |
|||
} |
|||
|
|||
return (id <AvnWindowProtocol>) Window; |
|||
} |
|||
|
|||
void WindowBaseImpl::BringToFront() |
|||
{ |
|||
// do nothing. |
|||
} |
|||
|
|||
extern IAvnWindow* CreateAvnWindow(IAvnWindowEvents*events, IAvnGlContext* gl) |
|||
{ |
|||
@autoreleasepool |
|||
{ |
|||
IAvnWindow* ptr = (IAvnWindow*)new WindowImpl(events, gl); |
|||
return ptr; |
|||
} |
|||
} |
|||
@ -0,0 +1,108 @@ |
|||
//
|
|||
// Created by Dan Walmsley on 04/05/2022.
|
|||
// Copyright (c) 2022 Avalonia. All rights reserved.
|
|||
//
|
|||
|
|||
#ifndef AVALONIA_NATIVE_OSX_WINDOWIMPL_H |
|||
#define AVALONIA_NATIVE_OSX_WINDOWIMPL_H |
|||
|
|||
#import "WindowBaseImpl.h" |
|||
#include "IWindowStateChanged.h" |
|||
#include <list> |
|||
|
|||
class WindowImpl : public virtual WindowBaseImpl, public virtual IAvnWindow, public IWindowStateChanged |
|||
{ |
|||
private: |
|||
bool _isEnabled; |
|||
bool _canResize; |
|||
bool _fullScreenActive; |
|||
SystemDecorations _decorations; |
|||
AvnWindowState _lastWindowState; |
|||
AvnWindowState _actualWindowState; |
|||
bool _inSetWindowState; |
|||
NSRect _preZoomSize; |
|||
bool _transitioningWindowState; |
|||
bool _isClientAreaExtended; |
|||
bool _isDialog; |
|||
WindowImpl* _parent; |
|||
std::list<WindowImpl*> _children; |
|||
AvnExtendClientAreaChromeHints _extendClientHints; |
|||
|
|||
FORWARD_IUNKNOWN() |
|||
BEGIN_INTERFACE_MAP() |
|||
INHERIT_INTERFACE_MAP(WindowBaseImpl) |
|||
INTERFACE_MAP_ENTRY(IAvnWindow, IID_IAvnWindow) |
|||
END_INTERFACE_MAP() |
|||
virtual ~WindowImpl() |
|||
{ |
|||
} |
|||
|
|||
ComPtr<IAvnWindowEvents> WindowEvents; |
|||
|
|||
WindowImpl(IAvnWindowEvents* events, IAvnGlContext* gl); |
|||
|
|||
void HideOrShowTrafficLights (); |
|||
|
|||
virtual HRESULT Show (bool activate, bool isDialog) override; |
|||
|
|||
virtual HRESULT SetEnabled (bool enable) override; |
|||
|
|||
virtual HRESULT SetParent (IAvnWindow* parent) override; |
|||
|
|||
void StartStateTransition () override ; |
|||
|
|||
void EndStateTransition () override ; |
|||
|
|||
SystemDecorations Decorations () override ; |
|||
|
|||
AvnWindowState WindowState () override ; |
|||
|
|||
void WindowStateChanged () override ; |
|||
|
|||
bool UndecoratedIsMaximized (); |
|||
|
|||
bool IsZoomed (); |
|||
|
|||
void DoZoom(); |
|||
|
|||
virtual HRESULT SetCanResize(bool value) override; |
|||
|
|||
virtual HRESULT SetDecorations(SystemDecorations value) override; |
|||
|
|||
virtual HRESULT SetTitle (char* utf8title) override; |
|||
|
|||
virtual HRESULT SetTitleBarColor(AvnColor color) override; |
|||
|
|||
virtual HRESULT GetWindowState (AvnWindowState*ret) override; |
|||
|
|||
virtual HRESULT TakeFocusFromChildren () override; |
|||
|
|||
virtual HRESULT SetExtendClientArea (bool enable) override; |
|||
|
|||
virtual HRESULT SetExtendClientAreaHints (AvnExtendClientAreaChromeHints hints) override; |
|||
|
|||
virtual HRESULT GetExtendTitleBarHeight (double*ret) override; |
|||
|
|||
virtual HRESULT SetExtendTitleBarHeight (double value) override; |
|||
|
|||
void EnterFullScreenMode (); |
|||
|
|||
void ExitFullScreenMode (); |
|||
|
|||
virtual HRESULT SetWindowState (AvnWindowState state) override; |
|||
|
|||
virtual bool IsDialog() override; |
|||
|
|||
virtual void BringToFront () override; |
|||
|
|||
bool CanBecomeKeyWindow (); |
|||
|
|||
protected: |
|||
virtual NSWindowStyleMask GetStyle() override; |
|||
|
|||
private: |
|||
void OnInitialiseNSWindow(); |
|||
NSString *_lastTitle; |
|||
}; |
|||
|
|||
#endif //AVALONIA_NATIVE_OSX_WINDOWIMPL_H
|
|||
@ -0,0 +1,603 @@ |
|||
// |
|||
// Created by Dan Walmsley on 04/05/2022. |
|||
// Copyright (c) 2022 Avalonia. All rights reserved. |
|||
// |
|||
|
|||
#import <AppKit/AppKit.h> |
|||
#include "AutoFitContentView.h" |
|||
#include "AvnView.h" |
|||
#include "automation.h" |
|||
#include "WindowProtocol.h" |
|||
|
|||
WindowImpl::WindowImpl(IAvnWindowEvents *events, IAvnGlContext *gl) : WindowBaseImpl(events, gl) { |
|||
_isEnabled = true; |
|||
_children = std::list<WindowImpl*>(); |
|||
_isClientAreaExtended = false; |
|||
_extendClientHints = AvnDefaultChrome; |
|||
_fullScreenActive = false; |
|||
_canResize = true; |
|||
_decorations = SystemDecorationsFull; |
|||
_transitioningWindowState = false; |
|||
_inSetWindowState = false; |
|||
_lastWindowState = Normal; |
|||
_actualWindowState = Normal; |
|||
_lastTitle = @""; |
|||
_parent = nullptr; |
|||
WindowEvents = events; |
|||
|
|||
[Window setHasShadow:true]; |
|||
|
|||
OnInitialiseNSWindow(); |
|||
} |
|||
|
|||
void WindowImpl::HideOrShowTrafficLights() { |
|||
if (Window == nil) { |
|||
return; |
|||
} |
|||
|
|||
bool wantsChrome = (_extendClientHints & AvnSystemChrome) || (_extendClientHints & AvnPreferSystemChrome); |
|||
bool hasTrafficLights = _isClientAreaExtended ? wantsChrome : _decorations == SystemDecorationsFull; |
|||
|
|||
[[Window standardWindowButton:NSWindowCloseButton] setHidden:!hasTrafficLights]; |
|||
[[Window standardWindowButton:NSWindowMiniaturizeButton] setHidden:!hasTrafficLights]; |
|||
[[Window standardWindowButton:NSWindowZoomButton] setHidden:!hasTrafficLights]; |
|||
} |
|||
|
|||
void WindowImpl::OnInitialiseNSWindow(){ |
|||
[GetWindowProtocol() setCanBecomeKeyWindow:true]; |
|||
|
|||
[Window disableCursorRects]; |
|||
[Window setTabbingMode:NSWindowTabbingModeDisallowed]; |
|||
[Window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary]; |
|||
|
|||
[Window setTitle:_lastTitle]; |
|||
|
|||
if(_isClientAreaExtended) |
|||
{ |
|||
[GetWindowProtocol() setIsExtended:true]; |
|||
SetExtendClientArea(true); |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowImpl::Show(bool activate, bool isDialog) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
_isDialog = isDialog || _parent != nullptr; |
|||
|
|||
WindowBaseImpl::Show(activate, isDialog); |
|||
|
|||
HideOrShowTrafficLights(); |
|||
|
|||
return SetWindowState(_lastWindowState); |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowImpl::SetEnabled(bool enable) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
_isEnabled = enable; |
|||
[GetWindowProtocol() setEnabled:enable]; |
|||
UpdateStyle(); |
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowImpl::SetParent(IAvnWindow *parent) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
if(_parent != nullptr) |
|||
{ |
|||
_parent->_children.remove(this); |
|||
} |
|||
|
|||
auto cparent = dynamic_cast<WindowImpl *>(parent); |
|||
|
|||
_parent = cparent; |
|||
|
|||
_isDialog = _parent != nullptr; |
|||
|
|||
if(_parent != nullptr && Window != nullptr){ |
|||
// If one tries to show a child window with a minimized parent window, then the parent window will be |
|||
// restored but macOS isn't kind enough to *tell* us that, so the window will be left in a non-interactive |
|||
// state. Detect this and explicitly restore the parent window ourselves to avoid this situation. |
|||
if (cparent->WindowState() == Minimized) |
|||
cparent->SetWindowState(Normal); |
|||
|
|||
[Window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary]; |
|||
|
|||
cparent->_children.push_back(this); |
|||
|
|||
UpdateStyle(); |
|||
} |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
void WindowImpl::BringToFront() |
|||
{ |
|||
if(Window != nullptr) |
|||
{ |
|||
if ([Window isVisible] && ![Window isMiniaturized]) |
|||
{ |
|||
if(IsDialog()) |
|||
{ |
|||
Activate(); |
|||
} |
|||
else |
|||
{ |
|||
[Window orderFront:nullptr]; |
|||
} |
|||
} |
|||
|
|||
[Window invalidateShadow]; |
|||
|
|||
for(auto iterator = _children.begin(); iterator != _children.end(); iterator++) |
|||
{ |
|||
(*iterator)->BringToFront(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
bool WindowImpl::CanBecomeKeyWindow() |
|||
{ |
|||
for(auto iterator = _children.begin(); iterator != _children.end(); iterator++) |
|||
{ |
|||
if((*iterator)->IsDialog()) |
|||
{ |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
void WindowImpl::StartStateTransition() { |
|||
_transitioningWindowState = true; |
|||
} |
|||
|
|||
void WindowImpl::EndStateTransition() { |
|||
_transitioningWindowState = false; |
|||
} |
|||
|
|||
SystemDecorations WindowImpl::Decorations() { |
|||
return _decorations; |
|||
} |
|||
|
|||
AvnWindowState WindowImpl::WindowState() { |
|||
return _lastWindowState; |
|||
} |
|||
|
|||
void WindowImpl::WindowStateChanged() { |
|||
if (_shown && !_inSetWindowState && !_transitioningWindowState) { |
|||
AvnWindowState state; |
|||
GetWindowState(&state); |
|||
|
|||
if (_lastWindowState != state) { |
|||
if (_isClientAreaExtended) { |
|||
if (_lastWindowState == FullScreen) { |
|||
// we exited fs. |
|||
if (_extendClientHints & AvnOSXThickTitleBar) { |
|||
Window.toolbar = [NSToolbar new]; |
|||
Window.toolbar.showsBaselineSeparator = false; |
|||
} |
|||
|
|||
[Window setTitlebarAppearsTransparent:true]; |
|||
|
|||
[StandardContainer setFrameSize:StandardContainer.frame.size]; |
|||
} else if (state == FullScreen) { |
|||
// we entered fs. |
|||
if (_extendClientHints & AvnOSXThickTitleBar) { |
|||
Window.toolbar = nullptr; |
|||
} |
|||
|
|||
[Window setTitlebarAppearsTransparent:false]; |
|||
|
|||
[StandardContainer setFrameSize:StandardContainer.frame.size]; |
|||
} |
|||
} |
|||
|
|||
_lastWindowState = state; |
|||
_actualWindowState = state; |
|||
WindowEvents->WindowStateChanged(state); |
|||
} |
|||
} |
|||
} |
|||
|
|||
bool WindowImpl::UndecoratedIsMaximized() { |
|||
auto windowSize = [Window frame]; |
|||
auto available = [Window screen].visibleFrame; |
|||
return CGRectEqualToRect(windowSize, available); |
|||
} |
|||
|
|||
bool WindowImpl::IsZoomed() { |
|||
return _decorations == SystemDecorationsFull ? [Window isZoomed] : UndecoratedIsMaximized(); |
|||
} |
|||
|
|||
void WindowImpl::DoZoom() { |
|||
switch (_decorations) { |
|||
case SystemDecorationsNone: |
|||
case SystemDecorationsBorderOnly: |
|||
[Window setFrame:[Window screen].visibleFrame display:true]; |
|||
break; |
|||
|
|||
|
|||
case SystemDecorationsFull: |
|||
[Window performZoom:Window]; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowImpl::SetCanResize(bool value) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
_canResize = value; |
|||
UpdateStyle(); |
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowImpl::SetDecorations(SystemDecorations value) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
auto currentWindowState = _lastWindowState; |
|||
_decorations = value; |
|||
|
|||
if (_fullScreenActive) { |
|||
return S_OK; |
|||
} |
|||
|
|||
UpdateStyle(); |
|||
|
|||
HideOrShowTrafficLights(); |
|||
|
|||
switch (_decorations) { |
|||
case SystemDecorationsNone: |
|||
[Window setHasShadow:NO]; |
|||
[Window setTitleVisibility:NSWindowTitleHidden]; |
|||
[Window setTitlebarAppearsTransparent:YES]; |
|||
|
|||
if (currentWindowState == Maximized) { |
|||
if (!UndecoratedIsMaximized()) { |
|||
DoZoom(); |
|||
} |
|||
} |
|||
break; |
|||
|
|||
case SystemDecorationsBorderOnly: |
|||
[Window setHasShadow:YES]; |
|||
[Window setTitleVisibility:NSWindowTitleHidden]; |
|||
[Window setTitlebarAppearsTransparent:YES]; |
|||
|
|||
if (currentWindowState == Maximized) { |
|||
if (!UndecoratedIsMaximized()) { |
|||
DoZoom(); |
|||
} |
|||
} |
|||
break; |
|||
|
|||
case SystemDecorationsFull: |
|||
[Window setHasShadow:YES]; |
|||
[Window setTitleVisibility:NSWindowTitleVisible]; |
|||
[Window setTitlebarAppearsTransparent:NO]; |
|||
[Window setTitle:_lastTitle]; |
|||
|
|||
if (currentWindowState == Maximized) { |
|||
auto newFrame = [Window contentRectForFrameRect:[Window frame]].size; |
|||
|
|||
[View setFrameSize:newFrame]; |
|||
} |
|||
break; |
|||
} |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowImpl::SetTitle(char *utf8title) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
_lastTitle = [NSString stringWithUTF8String:(const char *) utf8title]; |
|||
[Window setTitle:_lastTitle]; |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowImpl::SetTitleBarColor(AvnColor color) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
float a = (float) color.Alpha / 255.0f; |
|||
float r = (float) color.Red / 255.0f; |
|||
float g = (float) color.Green / 255.0f; |
|||
float b = (float) color.Blue / 255.0f; |
|||
|
|||
auto nscolor = [NSColor colorWithSRGBRed:r green:g blue:b alpha:a]; |
|||
|
|||
// Based on the titlebar color we have to choose either light or dark |
|||
// OSX doesnt let you set a foreground color for titlebar. |
|||
if ((r * 0.299 + g * 0.587 + b * 0.114) > 186.0f / 255.0f) { |
|||
[Window setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameVibrantLight]]; |
|||
} else { |
|||
[Window setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameVibrantDark]]; |
|||
} |
|||
|
|||
[Window setTitlebarAppearsTransparent:true]; |
|||
[Window setBackgroundColor:nscolor]; |
|||
} |
|||
|
|||
return S_OK; |
|||
} |
|||
|
|||
HRESULT WindowImpl::GetWindowState(AvnWindowState *ret) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
if (ret == nullptr) { |
|||
return E_POINTER; |
|||
} |
|||
|
|||
if (([Window styleMask] & NSWindowStyleMaskFullScreen) == NSWindowStyleMaskFullScreen) { |
|||
*ret = FullScreen; |
|||
return S_OK; |
|||
} |
|||
|
|||
if ([Window isMiniaturized]) { |
|||
*ret = Minimized; |
|||
return S_OK; |
|||
} |
|||
|
|||
if (IsZoomed()) { |
|||
*ret = Maximized; |
|||
return S_OK; |
|||
} |
|||
|
|||
*ret = Normal; |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowImpl::TakeFocusFromChildren() { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
if (Window == nil) |
|||
return S_OK; |
|||
if ([Window isKeyWindow]) |
|||
[Window makeFirstResponder:View]; |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowImpl::SetExtendClientArea(bool enable) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
_isClientAreaExtended = enable; |
|||
|
|||
if(Window != nullptr) { |
|||
if (enable) { |
|||
Window.titleVisibility = NSWindowTitleHidden; |
|||
|
|||
[Window setTitlebarAppearsTransparent:true]; |
|||
|
|||
auto wantsTitleBar = (_extendClientHints & AvnSystemChrome) || (_extendClientHints & AvnPreferSystemChrome); |
|||
|
|||
if (wantsTitleBar) { |
|||
[StandardContainer ShowTitleBar:true]; |
|||
} else { |
|||
[StandardContainer ShowTitleBar:false]; |
|||
} |
|||
|
|||
if (_extendClientHints & AvnOSXThickTitleBar) { |
|||
Window.toolbar = [NSToolbar new]; |
|||
Window.toolbar.showsBaselineSeparator = false; |
|||
} else { |
|||
Window.toolbar = nullptr; |
|||
} |
|||
} else { |
|||
Window.titleVisibility = NSWindowTitleVisible; |
|||
Window.toolbar = nullptr; |
|||
[Window setTitlebarAppearsTransparent:false]; |
|||
View.layer.zPosition = 0; |
|||
} |
|||
|
|||
[GetWindowProtocol() setIsExtended:enable]; |
|||
|
|||
HideOrShowTrafficLights(); |
|||
|
|||
UpdateStyle(); |
|||
} |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowImpl::SetExtendClientAreaHints(AvnExtendClientAreaChromeHints hints) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
_extendClientHints = hints; |
|||
|
|||
SetExtendClientArea(_isClientAreaExtended); |
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowImpl::GetExtendTitleBarHeight(double *ret) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
if (ret == nullptr) { |
|||
return E_POINTER; |
|||
} |
|||
|
|||
*ret = [GetWindowProtocol() getExtendedTitleBarHeight]; |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
HRESULT WindowImpl::SetExtendTitleBarHeight(double value) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
[StandardContainer SetTitleBarHeightHint:value]; |
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
void WindowImpl::EnterFullScreenMode() { |
|||
_fullScreenActive = true; |
|||
|
|||
[Window setTitle:_lastTitle]; |
|||
[Window toggleFullScreen:nullptr]; |
|||
} |
|||
|
|||
void WindowImpl::ExitFullScreenMode() { |
|||
[Window toggleFullScreen:nullptr]; |
|||
|
|||
_fullScreenActive = false; |
|||
|
|||
SetDecorations(_decorations); |
|||
} |
|||
|
|||
HRESULT WindowImpl::SetWindowState(AvnWindowState state) { |
|||
START_COM_CALL; |
|||
|
|||
@autoreleasepool { |
|||
auto currentState = _actualWindowState; |
|||
_lastWindowState = state; |
|||
|
|||
if (Window == nullptr) { |
|||
return S_OK; |
|||
} |
|||
|
|||
if (_actualWindowState == state) { |
|||
return S_OK; |
|||
} |
|||
|
|||
_inSetWindowState = true; |
|||
|
|||
if (currentState == Normal) { |
|||
_preZoomSize = [Window frame]; |
|||
} |
|||
|
|||
if (_shown) { |
|||
_actualWindowState = _lastWindowState; |
|||
|
|||
switch (state) { |
|||
case Maximized: |
|||
if (currentState == FullScreen) { |
|||
ExitFullScreenMode(); |
|||
} |
|||
|
|||
lastPositionSet.X = 0; |
|||
lastPositionSet.Y = 0; |
|||
|
|||
if ([Window isMiniaturized]) { |
|||
[Window deminiaturize:Window]; |
|||
} |
|||
|
|||
if (!IsZoomed()) { |
|||
DoZoom(); |
|||
} |
|||
break; |
|||
|
|||
case Minimized: |
|||
if (currentState == FullScreen) { |
|||
ExitFullScreenMode(); |
|||
} else { |
|||
[Window miniaturize:Window]; |
|||
} |
|||
break; |
|||
|
|||
case FullScreen: |
|||
if ([Window isMiniaturized]) { |
|||
[Window deminiaturize:Window]; |
|||
} |
|||
|
|||
EnterFullScreenMode(); |
|||
break; |
|||
|
|||
case Normal: |
|||
if ([Window isMiniaturized]) { |
|||
[Window deminiaturize:Window]; |
|||
} |
|||
|
|||
if (currentState == FullScreen) { |
|||
ExitFullScreenMode(); |
|||
} |
|||
|
|||
if (IsZoomed()) { |
|||
if (_decorations == SystemDecorationsFull) { |
|||
DoZoom(); |
|||
} else { |
|||
[Window setFrame:_preZoomSize display:true]; |
|||
auto newFrame = [Window contentRectForFrameRect:[Window frame]].size; |
|||
|
|||
[View setFrameSize:newFrame]; |
|||
} |
|||
|
|||
} |
|||
break; |
|||
} |
|||
|
|||
WindowEvents->WindowStateChanged(_actualWindowState); |
|||
} |
|||
|
|||
|
|||
_inSetWindowState = false; |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
bool WindowImpl::IsDialog() { |
|||
return _isDialog; |
|||
} |
|||
|
|||
NSWindowStyleMask WindowImpl::GetStyle() { |
|||
unsigned long s = NSWindowStyleMaskBorderless; |
|||
|
|||
if(_actualWindowState == FullScreen) |
|||
{ |
|||
s |= NSWindowStyleMaskFullScreen; |
|||
} |
|||
|
|||
switch (_decorations) { |
|||
case SystemDecorationsNone: |
|||
s = s | NSWindowStyleMaskFullSizeContentView; |
|||
break; |
|||
|
|||
case SystemDecorationsBorderOnly: |
|||
s = s | NSWindowStyleMaskTitled | NSWindowStyleMaskFullSizeContentView; |
|||
break; |
|||
|
|||
case SystemDecorationsFull: |
|||
s = s | NSWindowStyleMaskTitled | NSWindowStyleMaskClosable; |
|||
|
|||
if (_canResize && _isEnabled) { |
|||
s = s | NSWindowStyleMaskResizable; |
|||
} |
|||
break; |
|||
} |
|||
|
|||
if (!IsDialog()) { |
|||
s |= NSWindowStyleMaskMiniaturizable; |
|||
} |
|||
|
|||
if (_isClientAreaExtended) { |
|||
s |= NSWindowStyleMaskFullSizeContentView | NSWindowStyleMaskTexturedBackground; |
|||
} |
|||
return s; |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
//
|
|||
// Created by Dan Walmsley on 06/05/2022.
|
|||
// Copyright (c) 2022 Avalonia. All rights reserved.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
#import <AppKit/AppKit.h> |
|||
#include "WindowProtocol.h" |
|||
#include "WindowBaseImpl.h" |
|||
|
|||
@interface AvnWindow : NSWindow <AvnWindowProtocol, NSWindowDelegate> |
|||
-(AvnWindow* _Nonnull) initWithParent: (WindowBaseImpl* _Nonnull) parent contentRect: (NSRect)contentRect styleMask: (NSWindowStyleMask)styleMask; |
|||
@end |
|||
|
|||
@interface AvnPanel : NSPanel <AvnWindowProtocol, NSWindowDelegate> |
|||
-(AvnPanel* _Nonnull) initWithParent: (WindowBaseImpl* _Nonnull) parent contentRect: (NSRect)contentRect styleMask: (NSWindowStyleMask)styleMask; |
|||
@end |
|||
@ -0,0 +1,26 @@ |
|||
//
|
|||
// Created by Dan Walmsley on 06/05/2022.
|
|||
// Copyright (c) 2022 Avalonia. All rights reserved.
|
|||
//
|
|||
|
|||
#pragma once |
|||
|
|||
#import <AppKit/AppKit.h> |
|||
|
|||
@class AvnMenu; |
|||
|
|||
@protocol AvnWindowProtocol |
|||
-(void) pollModalSession: (NSModalSession _Nonnull) session; |
|||
-(bool) shouldTryToHandleEvents; |
|||
-(void) setEnabled: (bool) enable; |
|||
-(void) showAppMenuOnly; |
|||
-(void) showWindowMenuWithAppMenu; |
|||
-(void) applyMenu:(AvnMenu* _Nullable)menu; |
|||
|
|||
-(double) getExtendedTitleBarHeight; |
|||
-(void) setIsExtended:(bool)value; |
|||
-(void) disconnectParent; |
|||
-(bool) isDialog; |
|||
|
|||
-(void) setCanBecomeKeyWindow:(bool)value; |
|||
@end |
|||
@ -0,0 +1,12 @@ |
|||
#pragma once |
|||
|
|||
#import <Cocoa/Cocoa.h> |
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
class IAvnAutomationPeer; |
|||
|
|||
@interface AvnAccessibilityElement : NSAccessibilityElement |
|||
+ (AvnAccessibilityElement *) acquire:(IAvnAutomationPeer *) peer; |
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,497 @@ |
|||
#include "common.h" |
|||
#include "automation.h" |
|||
#include "AvnString.h" |
|||
#include "INSWindowHolder.h" |
|||
#include "AvnView.h" |
|||
|
|||
@interface AvnAccessibilityElement (Events) |
|||
- (void) raiseChildrenChanged; |
|||
@end |
|||
|
|||
@interface AvnRootAccessibilityElement : AvnAccessibilityElement |
|||
- (AvnView *) ownerView; |
|||
- (AvnRootAccessibilityElement *) initWithPeer:(IAvnAutomationPeer *) peer owner:(AvnView*) owner; |
|||
- (void) raiseFocusChanged; |
|||
@end |
|||
|
|||
class AutomationNode : public ComSingleObject<IAvnAutomationNode, &IID_IAvnAutomationNode> |
|||
{ |
|||
public: |
|||
FORWARD_IUNKNOWN() |
|||
|
|||
AutomationNode(AvnAccessibilityElement* owner) |
|||
{ |
|||
_owner = owner; |
|||
} |
|||
|
|||
AvnAccessibilityElement* GetOwner() |
|||
{ |
|||
return _owner; |
|||
} |
|||
|
|||
virtual void Dispose() override |
|||
{ |
|||
_owner = nil; |
|||
} |
|||
|
|||
virtual void ChildrenChanged () override |
|||
{ |
|||
[_owner raiseChildrenChanged]; |
|||
} |
|||
|
|||
virtual void PropertyChanged (AvnAutomationProperty property) override |
|||
{ |
|||
|
|||
} |
|||
|
|||
virtual void FocusChanged () override |
|||
{ |
|||
[(AvnRootAccessibilityElement*)_owner raiseFocusChanged]; |
|||
} |
|||
|
|||
private: |
|||
__strong AvnAccessibilityElement* _owner; |
|||
}; |
|||
|
|||
@implementation AvnAccessibilityElement |
|||
{ |
|||
IAvnAutomationPeer* _peer; |
|||
AutomationNode* _node; |
|||
NSMutableArray* _children; |
|||
} |
|||
|
|||
+ (AvnAccessibilityElement *)acquire:(IAvnAutomationPeer *)peer |
|||
{ |
|||
if (peer == nullptr) |
|||
return nil; |
|||
|
|||
auto instance = peer->GetNode(); |
|||
|
|||
if (instance != nullptr) |
|||
return dynamic_cast<AutomationNode*>(instance)->GetOwner(); |
|||
|
|||
if (peer->IsRootProvider()) |
|||
{ |
|||
auto window = peer->RootProvider_GetWindow(); |
|||
auto holder = dynamic_cast<INSWindowHolder*>(window); |
|||
auto view = holder->GetNSView(); |
|||
return [[AvnRootAccessibilityElement alloc] initWithPeer:peer owner:view]; |
|||
} |
|||
else |
|||
{ |
|||
return [[AvnAccessibilityElement alloc] initWithPeer:peer]; |
|||
} |
|||
} |
|||
|
|||
- (AvnAccessibilityElement *)initWithPeer:(IAvnAutomationPeer *)peer |
|||
{ |
|||
self = [super init]; |
|||
_peer = peer; |
|||
_node = new AutomationNode(self); |
|||
_peer->SetNode(_node); |
|||
return self; |
|||
} |
|||
|
|||
- (void)dealloc |
|||
{ |
|||
if (_node) |
|||
delete _node; |
|||
_node = nullptr; |
|||
} |
|||
|
|||
- (NSString *)description |
|||
{ |
|||
return [NSString stringWithFormat:@"%@ '%@' (%p)", |
|||
GetNSStringAndRelease(_peer->GetClassName()), |
|||
GetNSStringAndRelease(_peer->GetName()), |
|||
_peer]; |
|||
} |
|||
|
|||
- (IAvnAutomationPeer *)peer |
|||
{ |
|||
return _peer; |
|||
} |
|||
|
|||
- (BOOL)isAccessibilityElement |
|||
{ |
|||
return _peer->IsControlElement(); |
|||
} |
|||
|
|||
- (NSAccessibilityRole)accessibilityRole |
|||
{ |
|||
auto controlType = _peer->GetAutomationControlType(); |
|||
|
|||
switch (controlType) { |
|||
case AutomationButton: return NSAccessibilityButtonRole; |
|||
case AutomationCalendar: return NSAccessibilityGridRole; |
|||
case AutomationCheckBox: return NSAccessibilityCheckBoxRole; |
|||
case AutomationComboBox: return NSAccessibilityPopUpButtonRole; |
|||
case AutomationComboBoxItem: return NSAccessibilityMenuItemRole; |
|||
case AutomationEdit: return NSAccessibilityTextFieldRole; |
|||
case AutomationHyperlink: return NSAccessibilityLinkRole; |
|||
case AutomationImage: return NSAccessibilityImageRole; |
|||
case AutomationListItem: return NSAccessibilityRowRole; |
|||
case AutomationList: return NSAccessibilityTableRole; |
|||
case AutomationMenu: return NSAccessibilityMenuBarRole; |
|||
case AutomationMenuBar: return NSAccessibilityMenuBarRole; |
|||
case AutomationMenuItem: return NSAccessibilityMenuItemRole; |
|||
case AutomationProgressBar: return NSAccessibilityProgressIndicatorRole; |
|||
case AutomationRadioButton: return NSAccessibilityRadioButtonRole; |
|||
case AutomationScrollBar: return NSAccessibilityScrollBarRole; |
|||
case AutomationSlider: return NSAccessibilitySliderRole; |
|||
case AutomationSpinner: return NSAccessibilityIncrementorRole; |
|||
case AutomationStatusBar: return NSAccessibilityTableRole; |
|||
case AutomationTab: return NSAccessibilityTabGroupRole; |
|||
case AutomationTabItem: return NSAccessibilityRadioButtonRole; |
|||
case AutomationText: return NSAccessibilityStaticTextRole; |
|||
case AutomationToolBar: return NSAccessibilityToolbarRole; |
|||
case AutomationToolTip: return NSAccessibilityPopoverRole; |
|||
case AutomationTree: return NSAccessibilityOutlineRole; |
|||
case AutomationTreeItem: return NSAccessibilityCellRole; |
|||
case AutomationCustom: return NSAccessibilityUnknownRole; |
|||
case AutomationGroup: return NSAccessibilityGroupRole; |
|||
case AutomationThumb: return NSAccessibilityHandleRole; |
|||
case AutomationDataGrid: return NSAccessibilityGridRole; |
|||
case AutomationDataItem: return NSAccessibilityCellRole; |
|||
case AutomationDocument: return NSAccessibilityStaticTextRole; |
|||
case AutomationSplitButton: return NSAccessibilityPopUpButtonRole; |
|||
case AutomationWindow: return NSAccessibilityWindowRole; |
|||
case AutomationPane: return NSAccessibilityGroupRole; |
|||
case AutomationHeader: return NSAccessibilityGroupRole; |
|||
case AutomationHeaderItem: return NSAccessibilityButtonRole; |
|||
case AutomationTable: return NSAccessibilityTableRole; |
|||
case AutomationTitleBar: return NSAccessibilityGroupRole; |
|||
// Treat unknown roles as generic group container items. Returning |
|||
// NSAccessibilityUnknownRole is also possible but makes the screen |
|||
// reader focus on the item instead of passing focus to child items. |
|||
default: return NSAccessibilityGroupRole; |
|||
} |
|||
} |
|||
|
|||
- (NSString *)accessibilityIdentifier |
|||
{ |
|||
return GetNSStringAndRelease(_peer->GetAutomationId()); |
|||
} |
|||
|
|||
- (NSString *)accessibilityTitle |
|||
{ |
|||
// StaticText exposes its text via the value property. |
|||
if (_peer->GetAutomationControlType() != AutomationText) |
|||
{ |
|||
return GetNSStringAndRelease(_peer->GetName()); |
|||
} |
|||
|
|||
return [super accessibilityTitle]; |
|||
} |
|||
|
|||
- (id)accessibilityValue |
|||
{ |
|||
if (_peer->IsRangeValueProvider()) |
|||
{ |
|||
return [NSNumber numberWithDouble:_peer->RangeValueProvider_GetValue()]; |
|||
} |
|||
else if (_peer->IsToggleProvider()) |
|||
{ |
|||
switch (_peer->ToggleProvider_GetToggleState()) { |
|||
case 0: return [NSNumber numberWithBool:NO]; |
|||
case 1: return [NSNumber numberWithBool:YES]; |
|||
default: return [NSNumber numberWithInt:2]; |
|||
} |
|||
} |
|||
else if (_peer->IsValueProvider()) |
|||
{ |
|||
return GetNSStringAndRelease(_peer->ValueProvider_GetValue()); |
|||
} |
|||
else if (_peer->GetAutomationControlType() == AutomationText) |
|||
{ |
|||
return GetNSStringAndRelease(_peer->GetName()); |
|||
} |
|||
|
|||
return [super accessibilityValue]; |
|||
} |
|||
|
|||
- (id)accessibilityMinValue |
|||
{ |
|||
if (_peer->IsRangeValueProvider()) |
|||
{ |
|||
return [NSNumber numberWithDouble:_peer->RangeValueProvider_GetMinimum()]; |
|||
} |
|||
|
|||
return [super accessibilityMinValue]; |
|||
} |
|||
|
|||
- (id)accessibilityMaxValue |
|||
{ |
|||
if (_peer->IsRangeValueProvider()) |
|||
{ |
|||
return [NSNumber numberWithDouble:_peer->RangeValueProvider_GetMaximum()]; |
|||
} |
|||
|
|||
return [super accessibilityMaxValue]; |
|||
} |
|||
|
|||
- (BOOL)isAccessibilityEnabled |
|||
{ |
|||
return _peer->IsEnabled(); |
|||
} |
|||
|
|||
- (BOOL)isAccessibilityFocused |
|||
{ |
|||
return _peer->HasKeyboardFocus(); |
|||
} |
|||
|
|||
- (NSArray *)accessibilityChildren |
|||
{ |
|||
if (_children == nullptr && _peer != nullptr) |
|||
[self recalculateChildren]; |
|||
return _children; |
|||
} |
|||
|
|||
- (NSRect)accessibilityFrame |
|||
{ |
|||
id topLevel = [self accessibilityTopLevelUIElement]; |
|||
auto result = NSZeroRect; |
|||
|
|||
if ([topLevel isKindOfClass:[AvnRootAccessibilityElement class]]) |
|||
{ |
|||
auto root = (AvnRootAccessibilityElement*)topLevel; |
|||
auto view = [root ownerView]; |
|||
|
|||
if (view) |
|||
{ |
|||
auto window = [view window]; |
|||
auto bounds = ToNSRect(_peer->GetBoundingRectangle()); |
|||
auto windowBounds = [view convertRect:bounds toView:nil]; |
|||
auto screenBounds = [window convertRectToScreen:windowBounds]; |
|||
result = screenBounds; |
|||
} |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
|
|||
- (id)accessibilityParent |
|||
{ |
|||
auto parentPeer = _peer->GetParent(); |
|||
return parentPeer ? [AvnAccessibilityElement acquire:parentPeer] : [NSApplication sharedApplication]; |
|||
} |
|||
|
|||
- (id)accessibilityTopLevelUIElement |
|||
{ |
|||
auto rootPeer = _peer->GetRootPeer(); |
|||
return [AvnAccessibilityElement acquire:rootPeer]; |
|||
} |
|||
|
|||
- (id)accessibilityWindow |
|||
{ |
|||
id topLevel = [self accessibilityTopLevelUIElement]; |
|||
return [topLevel isKindOfClass:[NSWindow class]] ? topLevel : nil; |
|||
} |
|||
|
|||
- (BOOL)isAccessibilityExpanded |
|||
{ |
|||
if (!_peer->IsExpandCollapseProvider()) |
|||
return NO; |
|||
return _peer->ExpandCollapseProvider_GetIsExpanded(); |
|||
} |
|||
|
|||
- (void)setAccessibilityExpanded:(BOOL)accessibilityExpanded |
|||
{ |
|||
if (!_peer->IsExpandCollapseProvider()) |
|||
return; |
|||
if (accessibilityExpanded) |
|||
_peer->ExpandCollapseProvider_Expand(); |
|||
else |
|||
_peer->ExpandCollapseProvider_Collapse(); |
|||
} |
|||
|
|||
- (BOOL)accessibilityPerformPress |
|||
{ |
|||
if (_peer->IsInvokeProvider()) |
|||
{ |
|||
_peer->InvokeProvider_Invoke(); |
|||
} |
|||
else if (_peer->IsExpandCollapseProvider()) |
|||
{ |
|||
_peer->ExpandCollapseProvider_Expand(); |
|||
} |
|||
else if (_peer->IsToggleProvider()) |
|||
{ |
|||
_peer->ToggleProvider_Toggle(); |
|||
} |
|||
return YES; |
|||
} |
|||
|
|||
- (BOOL)accessibilityPerformIncrement |
|||
{ |
|||
if (!_peer->IsRangeValueProvider()) |
|||
return NO; |
|||
auto value = _peer->RangeValueProvider_GetValue(); |
|||
value += _peer->RangeValueProvider_GetSmallChange(); |
|||
_peer->RangeValueProvider_SetValue(value); |
|||
return YES; |
|||
} |
|||
|
|||
- (BOOL)accessibilityPerformDecrement |
|||
{ |
|||
if (!_peer->IsRangeValueProvider()) |
|||
return NO; |
|||
auto value = _peer->RangeValueProvider_GetValue(); |
|||
value -= _peer->RangeValueProvider_GetSmallChange(); |
|||
_peer->RangeValueProvider_SetValue(value); |
|||
return YES; |
|||
} |
|||
|
|||
- (BOOL)accessibilityPerformShowMenu |
|||
{ |
|||
if (!_peer->IsExpandCollapseProvider()) |
|||
return NO; |
|||
_peer->ExpandCollapseProvider_Expand(); |
|||
return YES; |
|||
} |
|||
|
|||
- (BOOL)isAccessibilitySelected |
|||
{ |
|||
if (_peer->IsSelectionItemProvider()) |
|||
return _peer->SelectionItemProvider_IsSelected(); |
|||
return NO; |
|||
} |
|||
|
|||
- (BOOL)isAccessibilitySelectorAllowed:(SEL)selector |
|||
{ |
|||
if (selector == @selector(accessibilityPerformShowMenu)) |
|||
{ |
|||
return _peer->IsExpandCollapseProvider() && _peer->ExpandCollapseProvider_GetShowsMenu(); |
|||
} |
|||
else if (selector == @selector(isAccessibilityExpanded)) |
|||
{ |
|||
return _peer->IsExpandCollapseProvider(); |
|||
} |
|||
else if (selector == @selector(accessibilityPerformPress)) |
|||
{ |
|||
return _peer->IsInvokeProvider() || _peer->IsExpandCollapseProvider() || _peer->IsToggleProvider(); |
|||
} |
|||
else if (selector == @selector(accessibilityPerformIncrement) || |
|||
selector == @selector(accessibilityPerformDecrement) || |
|||
selector == @selector(accessibilityMinValue) || |
|||
selector == @selector(accessibilityMaxValue)) |
|||
{ |
|||
return _peer->IsRangeValueProvider(); |
|||
} |
|||
|
|||
return [super isAccessibilitySelectorAllowed:selector]; |
|||
} |
|||
|
|||
- (void)raiseChildrenChanged |
|||
{ |
|||
auto changed = _children ? [NSMutableSet setWithArray:_children] : [NSMutableSet set]; |
|||
|
|||
[self recalculateChildren]; |
|||
|
|||
if (_children) |
|||
[changed addObjectsFromArray:_children]; |
|||
|
|||
NSAccessibilityPostNotificationWithUserInfo( |
|||
self, |
|||
NSAccessibilityLayoutChangedNotification, |
|||
@{ NSAccessibilityUIElementsKey: [changed allObjects]}); |
|||
} |
|||
|
|||
- (void)raisePropertyChanged |
|||
{ |
|||
} |
|||
|
|||
- (void)setAccessibilityFocused:(BOOL)accessibilityFocused |
|||
{ |
|||
if (accessibilityFocused) |
|||
_peer->SetFocus(); |
|||
} |
|||
|
|||
- (void)recalculateChildren |
|||
{ |
|||
auto childPeers = _peer->GetChildren(); |
|||
auto childCount = childPeers != nullptr ? childPeers->GetCount() : 0; |
|||
|
|||
if (childCount > 0) |
|||
{ |
|||
_children = [[NSMutableArray alloc] initWithCapacity:childCount]; |
|||
|
|||
for (int i = 0; i < childCount; ++i) |
|||
{ |
|||
IAvnAutomationPeer* child; |
|||
|
|||
if (childPeers->Get(i, &child) == S_OK) |
|||
{ |
|||
auto element = [AvnAccessibilityElement acquire:child]; |
|||
[_children addObject:element]; |
|||
} |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
_children = nil; |
|||
} |
|||
} |
|||
|
|||
@end |
|||
|
|||
@implementation AvnRootAccessibilityElement |
|||
{ |
|||
AvnView* _owner; |
|||
} |
|||
|
|||
- (AvnRootAccessibilityElement *)initWithPeer:(IAvnAutomationPeer *)peer owner:(AvnView *)owner |
|||
{ |
|||
self = [super initWithPeer:peer]; |
|||
_owner = owner; |
|||
|
|||
// Seems we need to raise a focus changed notification here if we have focus |
|||
auto focusedPeer = [self peer]->RootProvider_GetFocus(); |
|||
id focused = [AvnAccessibilityElement acquire:focusedPeer]; |
|||
|
|||
if (focused) |
|||
NSAccessibilityPostNotification(focused, NSAccessibilityFocusedUIElementChangedNotification); |
|||
|
|||
return self; |
|||
} |
|||
|
|||
- (AvnView *)ownerView |
|||
{ |
|||
return _owner; |
|||
} |
|||
|
|||
- (id)accessibilityFocusedUIElement |
|||
{ |
|||
auto focusedPeer = [self peer]->RootProvider_GetFocus(); |
|||
return [AvnAccessibilityElement acquire:focusedPeer]; |
|||
} |
|||
|
|||
- (id)accessibilityHitTest:(NSPoint)point |
|||
{ |
|||
auto clientPoint = [[_owner window] convertPointFromScreen:point]; |
|||
auto localPoint = [_owner translateLocalPoint:ToAvnPoint(clientPoint)]; |
|||
auto hit = [self peer]->RootProvider_GetPeerFromPoint(localPoint); |
|||
return [AvnAccessibilityElement acquire:hit]; |
|||
} |
|||
|
|||
- (id)accessibilityParent |
|||
{ |
|||
return _owner; |
|||
} |
|||
|
|||
- (void)raiseFocusChanged |
|||
{ |
|||
id focused = [self accessibilityFocusedUIElement]; |
|||
NSAccessibilityPostNotification(focused, NSAccessibilityFocusedUIElementChangedNotification); |
|||
} |
|||
|
|||
// Although this method is marked as deprecated we get runtime warnings if we don't handle it. |
|||
#pragma clang diagnostic push |
|||
#pragma clang diagnostic ignored "-Wdeprecated-implementations" |
|||
- (void)accessibilityPerformAction:(NSAccessibilityActionName)action |
|||
{ |
|||
[_owner accessibilityPerformAction:action]; |
|||
} |
|||
#pragma clang diagnostic pop |
|||
|
|||
@end |
|||
@ -1,76 +0,0 @@ |
|||
#ifndef window_h |
|||
#define window_h |
|||
|
|||
class WindowBaseImpl; |
|||
|
|||
@interface AvnView : NSView<NSTextInputClient, NSDraggingDestination> |
|||
-(AvnView* _Nonnull) initWithParent: (WindowBaseImpl* _Nonnull) parent; |
|||
-(NSEvent* _Nonnull) lastMouseDownEvent; |
|||
-(AvnPoint) translateLocalPoint:(AvnPoint)pt; |
|||
-(void) setSwRenderedFrame: (AvnFramebuffer* _Nonnull) fb dispose: (IUnknown* _Nonnull) dispose; |
|||
-(void) onClosed; |
|||
-(AvnPixelSize) getPixelSize; |
|||
-(AvnPlatformResizeReason) getResizeReason; |
|||
-(void) setResizeReason:(AvnPlatformResizeReason)reason; |
|||
+ (AvnPoint)toAvnPoint:(CGPoint)p; |
|||
@end |
|||
|
|||
@interface AutoFitContentView : NSView |
|||
-(AutoFitContentView* _Nonnull) initWithContent: (NSView* _Nonnull) content; |
|||
-(void) ShowTitleBar: (bool) show; |
|||
-(void) SetTitleBarHeightHint: (double) height; |
|||
-(void) SetContent: (NSView* _Nonnull) content; |
|||
-(void) ShowBlur: (bool) show; |
|||
@end |
|||
|
|||
@interface AvnWindow : NSWindow <NSWindowDelegate> |
|||
+(void) closeAll; |
|||
-(AvnWindow* _Nonnull) initWithParent: (WindowBaseImpl* _Nonnull) parent; |
|||
-(void) setCanBecomeKeyAndMain; |
|||
-(void) pollModalSession: (NSModalSession _Nonnull) session; |
|||
-(void) restoreParentWindow; |
|||
-(bool) shouldTryToHandleEvents; |
|||
-(void) setEnabled: (bool) enable; |
|||
-(void) showAppMenuOnly; |
|||
-(void) showWindowMenuWithAppMenu; |
|||
-(void) applyMenu:(NSMenu* _Nullable)menu; |
|||
-(double) getScaling; |
|||
-(double) getExtendedTitleBarHeight; |
|||
-(void) setIsExtended:(bool)value; |
|||
-(bool) isDialog; |
|||
@end |
|||
|
|||
struct INSWindowHolder |
|||
{ |
|||
virtual AvnWindow* _Nonnull GetNSWindow () = 0; |
|||
}; |
|||
|
|||
struct IWindowStateChanged |
|||
{ |
|||
virtual void WindowStateChanged () = 0; |
|||
virtual void StartStateTransition () = 0; |
|||
virtual void EndStateTransition () = 0; |
|||
virtual SystemDecorations Decorations () = 0; |
|||
virtual AvnWindowState WindowState () = 0; |
|||
}; |
|||
|
|||
class ResizeScope |
|||
{ |
|||
public: |
|||
ResizeScope(AvnView* _Nonnull view, AvnPlatformResizeReason reason) |
|||
{ |
|||
_view = view; |
|||
_restore = [view getResizeReason]; |
|||
[view setResizeReason:reason]; |
|||
} |
|||
|
|||
~ResizeScope() |
|||
{ |
|||
[_view setResizeReason:_restore]; |
|||
} |
|||
private: |
|||
AvnView* _Nonnull _view; |
|||
AvnPlatformResizeReason _restore; |
|||
}; |
|||
|
|||
#endif /* window_h */ |
|||
File diff suppressed because it is too large
@ -0,0 +1,57 @@ |
|||
using System.Globalization; |
|||
using JetBrains.Annotations; |
|||
using Nuke.Common.Tools.DotNet; |
|||
// ReSharper disable ReturnValueOfPureMethodIsNotUsed
|
|||
|
|||
public class DotNetConfigHelper |
|||
{ |
|||
public DotNetBuildSettings Build; |
|||
public DotNetPackSettings Pack; |
|||
public DotNetTestSettings Test; |
|||
|
|||
public DotNetConfigHelper(DotNetBuildSettings s) |
|||
{ |
|||
Build = s; |
|||
} |
|||
|
|||
public DotNetConfigHelper(DotNetPackSettings s) |
|||
{ |
|||
Pack = s; |
|||
} |
|||
|
|||
public DotNetConfigHelper(DotNetTestSettings s) |
|||
{ |
|||
Test = s; |
|||
} |
|||
|
|||
public DotNetConfigHelper AddProperty(string key, bool value) => |
|||
AddProperty(key, value.ToString(CultureInfo.InvariantCulture).ToLowerInvariant()); |
|||
public DotNetConfigHelper AddProperty(string key, string value) |
|||
{ |
|||
Build = Build?.AddProperty(key, value); |
|||
Pack = Pack?.AddProperty(key, value); |
|||
Test = Test?.AddProperty(key, value); |
|||
|
|||
return this; |
|||
} |
|||
|
|||
public DotNetConfigHelper SetConfiguration(string configuration) |
|||
{ |
|||
Build = Build?.SetConfiguration(configuration); |
|||
Pack = Pack?.SetConfiguration(configuration); |
|||
Test = Test?.SetConfiguration(configuration); |
|||
return this; |
|||
} |
|||
|
|||
public DotNetConfigHelper SetVerbosity(DotNetVerbosity verbosity) |
|||
{ |
|||
Build = Build?.SetVerbosity(verbosity); |
|||
Pack = Pack?.SetVerbosity(verbosity); |
|||
Test = Test?.SetVerbosity(verbosity); |
|||
return this; |
|||
} |
|||
|
|||
public static implicit operator DotNetConfigHelper(DotNetBuildSettings s) => new DotNetConfigHelper(s); |
|||
public static implicit operator DotNetConfigHelper(DotNetPackSettings s) => new DotNetConfigHelper(s); |
|||
public static implicit operator DotNetConfigHelper(DotNetTestSettings s) => new DotNetConfigHelper(s); |
|||
} |
|||
@ -1,14 +0,0 @@ |
|||
using System.IO; |
|||
using MicroCom.CodeGenerator; |
|||
using Nuke.Common; |
|||
|
|||
partial class Build : NukeBuild |
|||
{ |
|||
Target GenerateCppHeaders => _ => _.Executes(() => |
|||
{ |
|||
var file = MicroComCodeGenerator.Parse( |
|||
File.ReadAllText(RootDirectory / "src" / "Avalonia.Native" / "avn.idl")); |
|||
File.WriteAllText(RootDirectory / "native" / "Avalonia.Native" / "inc" / "avalonia-native.h", |
|||
file.GenerateCppHeader()); |
|||
}); |
|||
} |
|||
@ -1,42 +1,48 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<OutputType>Exe</OutputType> |
|||
<TargetFramework>netcoreapp3.1</TargetFramework> |
|||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> |
|||
<RootNamespace></RootNamespace> |
|||
<IsPackable>False</IsPackable> |
|||
<NoWarn>CS0649;CS0169</NoWarn> |
|||
<NoWarn>CS0649;CS0169;SYSLIB0011</NoWarn> |
|||
<NukeTelemetryVersion>1</NukeTelemetryVersion> |
|||
<TargetFramework>net7.0</TargetFramework> |
|||
</PropertyGroup> |
|||
|
|||
|
|||
<Import Project="..\build\JetBrains.dotMemoryUnit.props" /> |
|||
<ItemGroup> |
|||
<PackageReference Include="Nuke.Common" Version="5.0.0" /> |
|||
<PackageReference Include="xunit.runner.console" Version="2.3.1" /> |
|||
<PackageReference Include="JetBrains.dotMemoryUnit" Version="3.0.20171219.105559" /> |
|||
<PackageReference Include="Nuke.Common" Version="6.2.1" /> |
|||
<PackageReference Include="vswhere" Version="2.6.7" Condition=" '$(OS)' == 'Windows_NT' " /> |
|||
<PackageReference Include="ILRepack.NETStandard" Version="2.0.4" /> |
|||
<PackageReference Include="MicroCom.CodeGenerator" Version="0.10.4" /> |
|||
<PackageReference Include="MicroCom.CodeGenerator" Version="0.11.0" /> |
|||
<!-- Keep in sync with Avalonia.Build.Tasks --> |
|||
<PackageReference Include="Mono.Cecil" Version="0.11.2" /> |
|||
<PackageReference Include="Mono.Cecil" Version="0.11.4" /> |
|||
<PackageReference Include="SourceLink" Version="1.1.0" GeneratePathProperty="true" /> |
|||
<PackageReference Include="Microsoft.Build.Framework" Version="17.3.2" PrivateAssets="All" /> |
|||
<PackageReference Include="xunit.runner.console" Version="2.4.2"> |
|||
<PrivateAssets>all</PrivateAssets> |
|||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> |
|||
</PackageReference> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<NukeMetadata Include="**\*.json" Exclude="bin\**;obj\**" /> |
|||
<NukeExternalFiles Include="**\*.*.ext" Exclude="bin\**;obj\**" /> |
|||
<None Remove="*.csproj.DotSettings;*.ref.*.txt" /> |
|||
|
|||
<!-- Common build related files --> |
|||
<None Include="..\build.ps1" /> |
|||
<None Include="..\build.sh" /> |
|||
<None Include="..\.nuke" /> |
|||
<None Include="..\global.json" Condition="Exists('..\global.json')" /> |
|||
<None Include="..\nuget.config" Condition="Exists('..\nuget.config')" /> |
|||
<None Include="..\Jenkinsfile" Condition="Exists('..\Jenkinsfile')" /> |
|||
<None Include="..\appveyor.yml" Condition="Exists('..\appveyor.yml')" /> |
|||
<None Include="..\.travis.yml" Condition="Exists('..\.travis.yml')" /> |
|||
<None Include="..\GitVersion.yml" Condition="Exists('..\GitVersion.yml')" /> |
|||
<Compile Remove="Numerge/**/*.*" /> |
|||
<Compile Include="Numerge/Numerge/**/*.cs" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<EmbeddedResource Include="$(NuGetPackageRoot)sourcelink/1.1.0/tools/pdbstr.exe"></EmbeddedResource> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<Compile Remove="il-repack\ILRepack\Application.cs" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<Folder Include="Numerge\Numerge.Console\" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
|
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue