diff --git a/.editorconfig b/.editorconfig index f6bce9cb76..c7a381b730 100644 --- a/.editorconfig +++ b/.editorconfig @@ -156,6 +156,9 @@ indent_size = 2 [*.{props,targets,config,nuspec}] indent_size = 2 +[*.json] +indent_size = 2 + # Shell scripts [*.sh] end_of_line = lf diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000000..80716520d9 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,31 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. Windows, Mac, Linux (State distribution)] + - Version [e.g. 0.10.0-rc1 or 0.9.12] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000000..bbcbbe7d61 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.ncrunch/Avalonia.Build.Tasks.v3.ncrunchproject b/.ncrunch/Avalonia.Build.Tasks.v3.ncrunchproject index 319cd523ce..95a483b433 100644 --- a/.ncrunch/Avalonia.Build.Tasks.v3.ncrunchproject +++ b/.ncrunch/Avalonia.Build.Tasks.v3.ncrunchproject @@ -1,5 +1,3 @@  - - True - + \ No newline at end of file diff --git a/.ncrunch/Avalonia.MicroCom.v3.ncrunchproject b/.ncrunch/Avalonia.MicroCom.v3.ncrunchproject new file mode 100644 index 0000000000..319cd523ce --- /dev/null +++ b/.ncrunch/Avalonia.MicroCom.v3.ncrunchproject @@ -0,0 +1,5 @@ + + + True + + \ No newline at end of file diff --git a/Avalonia.sln b/Avalonia.sln index 34ad19b41d..75f1dd8407 100644 --- a/Avalonia.sln +++ b/Avalonia.sln @@ -226,6 +226,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.ReactiveUI.Events" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sandbox", "samples\Sandbox\Sandbox.csproj", "{11BE52AF-E2DD-4CF0-B19A-05285ACAF571}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MicroComGenerator", "src\tools\MicroComGenerator\MicroComGenerator.csproj", "{AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.MicroCom", "src\Avalonia.MicroCom\Avalonia.MicroCom.csproj", "{FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniMvvm", "samples\MiniMvvm\MiniMvvm.csproj", "{BC594FD5-4AF2-409E-A1E6-04123F54D7C5}" +EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution src\Shared\RenderHelpers\RenderHelpers.projitems*{3c4c0cb4-0c0f-4450-a37b-148c84ff905f}*SharedItemsImports = 13 @@ -2064,6 +2070,78 @@ Global {11BE52AF-E2DD-4CF0-B19A-05285ACAF571}.Release|iPhone.Build.0 = Release|Any CPU {11BE52AF-E2DD-4CF0-B19A-05285ACAF571}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU {11BE52AF-E2DD-4CF0-B19A-05285ACAF571}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.AppStore|Any CPU.Build.0 = Debug|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.AppStore|iPhone.ActiveCfg = Debug|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.AppStore|iPhone.Build.0 = Debug|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.Debug|iPhone.Build.0 = Debug|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.Release|Any CPU.Build.0 = Release|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.Release|iPhone.ActiveCfg = Release|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.Release|iPhone.Build.0 = Release|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.AppStore|Any CPU.Build.0 = Debug|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.AppStore|iPhone.ActiveCfg = Debug|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.AppStore|iPhone.Build.0 = Debug|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.Debug|iPhone.Build.0 = Debug|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.Release|Any CPU.Build.0 = Release|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.Release|iPhone.ActiveCfg = Release|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.Release|iPhone.Build.0 = Release|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {FE2F3E5E-1E34-4972-8DC1-5C2C588E5ECE}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.AppStore|Any CPU.Build.0 = Debug|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.AppStore|iPhone.ActiveCfg = Debug|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.AppStore|iPhone.Build.0 = Debug|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.Debug|iPhone.Build.0 = Debug|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.Release|Any CPU.Build.0 = Release|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.Release|iPhone.ActiveCfg = Release|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.Release|iPhone.Build.0 = Release|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5}.Release|iPhoneSimulator.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -2123,6 +2201,8 @@ Global {3C84E04B-36CF-4D0D-B965-C26DD649D1F3} = {A0CC0258-D18C-4AB3-854F-7101680FC3F9} {909A8CBD-7D0E-42FD-B841-022AD8925820} = {8B6A8209-894F-4BA1-B880-965FD453982C} {11BE52AF-E2DD-4CF0-B19A-05285ACAF571} = {9B9E3891-2366-4253-A952-D08BCEB71098} + {AEC9031E-06EA-4A9E-9E7F-7D7C719404DD} = {4ED8B739-6F4E-4CD4-B993-545E6B5CE637} + {BC594FD5-4AF2-409E-A1E6-04123F54D7C5} = {9B9E3891-2366-4253-A952-D08BCEB71098} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {87366D66-1391-4D90-8999-95A620AD786A} diff --git a/Avalonia.sln.DotSettings b/Avalonia.sln.DotSettings index 7060f4a62a..2c0a6b9dc8 100644 --- a/Avalonia.sln.DotSettings +++ b/Avalonia.sln.DotSettings @@ -37,4 +37,6 @@ <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> <Policy Inspect="False" Prefix="T" Suffix="" Style="AaBb" /> <Policy Inspect="False" Prefix="" Suffix="" Style="AaBb" /> - True \ No newline at end of file + True + True + True \ No newline at end of file diff --git a/Avalonia.v3.ncrunchsolution b/Avalonia.v3.ncrunchsolution index afce1018ec..b97a8e54f5 100644 --- a/Avalonia.v3.ncrunchsolution +++ b/Avalonia.v3.ncrunchsolution @@ -4,6 +4,8 @@ tests\TestFiles\**.* src\Avalonia.Build.Tasks\bin\Debug\netstandard2.0\Avalonia.Build.Tasks.dll src\Avalonia.Build.Tasks\bin\Debug\netstandard2.0\Mono.Cecil.dll + src\Avalonia.Build.Tasks\bin\Debug\netstandard2.0\Mono.Cecil.Rocks.dll + src\Avalonia.Build.Tasks\bin\Debug\netstandard2.0\Mono.Cecil.Pdb.dll True diff --git a/Directory.Build.props b/Directory.Build.props index b41f8c488e..c6610695c4 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,5 +2,7 @@ $(MSBuildThisFileDirectory)build-intermediate/nuget $(MSBuildThisFileDirectory)\src\tools\Avalonia.Designer.HostApp\bin\$(Configuration)\netcoreapp2.0\Avalonia.Designer.HostApp.dll + + false diff --git a/Documentation/build.md b/Documentation/build.md index 8c2ef57b54..5f75290424 100644 --- a/Documentation/build.md +++ b/Documentation/build.md @@ -30,7 +30,7 @@ The build process needs [Xcode](https://developer.apple.com/xcode/) to build the Linux operating systems ship with their own respective package managers however we will use [Homebrew](https://brew.sh/) to manage packages on macOS. To install follow the instructions [here](https://docs.brew.sh/Installation). -### Install CastXML +### Install CastXML (pre Nov 2020) Avalonia requires [CastXML](https://github.com/CastXML/CastXML) for XML processing during the build process. The easiest way to install this is via the operating system's package managers, such as below. @@ -60,14 +60,10 @@ git submodule update --init --recursive ### Build native libraries (macOS only) -On macOS it is necessary to build and manually install the respective native libraries using [Xcode](https://developer.apple.com/xcode/). The steps to get this working correctly are: -- Navigate to the Avalonia/native/Avalonia.Native/src/OSX folder and open the `Avalonia.Native.OSX.xcodeproj` project -- Build the library via the Product->Build menu. This will generate binaries in your local path under ~/Library/Developer/Xcode/DerivedData/Avalonia.Native.OSX-*guid* where "guid" is uniquely generated every time you build. -- Manually install the native library by copying it from the build artifacts folder into the shared dynamic library path: +On macOS it is necessary to build and manually install the respective native libraries using [Xcode](https://developer.apple.com/xcode/). Execute the build script in the root project with the `CompileNative` task. It will build the headers, build the libraries, and place them in the appropriate place to allow .NET to find them at compilation and run time. -``` -cd ~/Library/Developer/Xcode/DerivedData/Avalonia.Native.OSX-[guid]/Build/Products/Debug -cp libAvalonia.Native.OSX.dylib /usr/local/lib/libAvaloniaNative.dylib +```bash +./build.sh CompileNative ``` ### Build and Run Avalonia diff --git a/NuGet.Config b/NuGet.Config index 3abd236d42..7a1f28bea7 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -4,6 +4,6 @@ - + diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e67fa14c57..fbd8507193 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -3,13 +3,6 @@ jobs: pool: vmImage: 'ubuntu-16.04' steps: - - task: CmdLine@2 - displayName: 'Install CastXML' - inputs: - script: | - sudo apt-get update - sudo apt-get install castxml - - task: CmdLine@2 displayName: 'Install Nuke' inputs: @@ -34,7 +27,7 @@ jobs: variables: SolutionDir: '$(Build.SourcesDirectory)' pool: - vmImage: 'macOS-10.14' + vmImage: 'macOS-10.15' steps: - task: UseDotNet@2 displayName: 'Use .NET Core SDK 3.1.401' @@ -48,14 +41,20 @@ jobs: curl -o ./mono.pkg https://download.mono-project.com/archive/5.18.0/macos-10-universal/MonoFramework-MDK-5.18.0.225.macos10.xamarin.universal.pkg sudo installer -verbose -pkg ./mono.pkg -target / + - task: CmdLine@2 + displayName: 'Generate avalonia-native' + inputs: + script: | + cd src/tools/MicroComGenerator; dotnet run -i ../../Avalonia.Native/avn.idl --cpp ../../../native/Avalonia.Native/inc/avalonia-native.h + - task: Xcode@5 inputs: actions: 'build' scheme: '' - sdk: 'macosx10.14' + sdk: 'macosx11.1' configuration: 'Release' xcWorkspacePath: '**/*.xcodeproj/project.xcworkspace' - xcodeVersion: '10' # Options: 8, 9, default, specifyPath + xcodeVersion: '12' # Options: 8, 9, default, specifyPath args: '-derivedDataPath ./' - task: CmdLine@2 diff --git a/build.ps1 b/build.ps1 index 57e2f80075..985e8abcee 100644 --- a/build.ps1 +++ b/build.ps1 @@ -43,7 +43,7 @@ if (Test-Path $DotNetGlobalFile) { } # If dotnet is installed locally, and expected version is not set or installation matches the expected version -if ((Get-Command "dotnet" -ErrorAction SilentlyContinue) -ne $null -and ` +if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue) -and ` (!(Test-Path variable:DotNetVersion) -or $(& dotnet --version) -eq $DotNetVersion)) { $env:DOTNET_EXE = (Get-Command "dotnet").Path } @@ -53,7 +53,7 @@ else { # Download install script $DotNetInstallFile = "$TempDirectory\dotnet-install.ps1" - md -force $TempDirectory > $null + mkdir -force $TempDirectory > $null (New-Object System.Net.WebClient).DownloadFile($DotNetInstallUrl, $DotNetInstallFile) # Install by channel or version @@ -62,6 +62,8 @@ else { } else { ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath } } + + $env:PATH="$DotNetDirectory;$env:PATH" } Write-Output "Microsoft (R) .NET Core SDK version $(& $env:DOTNET_EXE --version)" diff --git a/build.sh b/build.sh index a40e00f815..bd162fab9b 100755 --- a/build.sh +++ b/build.sh @@ -47,7 +47,7 @@ if [ -f "$DOTNET_GLOBAL_FILE" ]; then fi # If dotnet is installed locally, and expected version is not set or installation matches the expected version -if [[ -x "$(command -v dotnet)" && (-z ${DOTNET_VERSION+x} || $(dotnet --version) == "$DOTNET_VERSION") ]]; then +if [[ -x "$(command -v dotnet)" && (-z ${DOTNET_VERSION+x} || $(dotnet --version) == "$DOTNET_VERSION") || "$SKIP_DOTNET_DOWNLOAD" == "1" ]]; then export DOTNET_EXE="$(command -v dotnet)" else DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix" diff --git a/build/AndroidWorkarounds.props b/build/AndroidWorkarounds.props index 67947296b3..de86acc6de 100644 --- a/build/AndroidWorkarounds.props +++ b/build/AndroidWorkarounds.props @@ -2,7 +2,7 @@ - + diff --git a/build/ApiDiff.props b/build/ApiDiff.props index 3d322f56d5..da59ad4bf2 100644 --- a/build/ApiDiff.props +++ b/build/ApiDiff.props @@ -1,6 +1,6 @@  - 0.10.0-preview3 + 0.10.0-rc1 $(PackageId) Avalonia diff --git a/build/CoreLibraries.props b/build/CoreLibraries.props index d17eec0135..fff00041c3 100644 --- a/build/CoreLibraries.props +++ b/build/CoreLibraries.props @@ -15,6 +15,7 @@ + diff --git a/build/EmbedXaml.props b/build/EmbedXaml.props index 7ce0366dea..0bb8da4f47 100644 --- a/build/EmbedXaml.props +++ b/build/EmbedXaml.props @@ -4,8 +4,9 @@ %(Filename) + Designer - \ No newline at end of file + diff --git a/build/HarfBuzzSharp.props b/build/HarfBuzzSharp.props index e636461ad9..13419eb173 100644 --- a/build/HarfBuzzSharp.props +++ b/build/HarfBuzzSharp.props @@ -1,6 +1,6 @@  - - + + diff --git a/build/MicroCom.targets b/build/MicroCom.targets new file mode 100644 index 0000000000..b48e377fd4 --- /dev/null +++ b/build/MicroCom.targets @@ -0,0 +1,33 @@ + + + + + + false + all + true + + + + + + + + + + + + + + + + + + <_AvaloniaPatchComInterop>true + + + diff --git a/build/ReactiveUI.props b/build/ReactiveUI.props index d8e86e917e..f74ab07e31 100644 --- a/build/ReactiveUI.props +++ b/build/ReactiveUI.props @@ -1,5 +1,5 @@ - + diff --git a/build/Rx.props b/build/Rx.props index 8a15ccd6a9..fde1f80ea1 100644 --- a/build/Rx.props +++ b/build/Rx.props @@ -1,5 +1,5 @@  - + diff --git a/build/SharedVersion.props b/build/SharedVersion.props index d1e9f7b751..9a268a21e7 100644 --- a/build/SharedVersion.props +++ b/build/SharedVersion.props @@ -16,10 +16,11 @@ https://github.com/AvaloniaUI/Avalonia/releases git $(MSBuildThisFileDirectory)\avalonia.snk - True + true + $(DefineConstants);SIGNED_BUILD - + diff --git a/build/SourceLink.props b/build/SourceLink.props index e27727c9e8..1e007e01eb 100644 --- a/build/SourceLink.props +++ b/build/SourceLink.props @@ -1,5 +1,26 @@ + + true + false + true + embedded + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + + + + true + + + + true + + - + + + + + + diff --git a/build/XUnit.props b/build/XUnit.props index 53f524b8e9..a75e1bac86 100644 --- a/build/XUnit.props +++ b/build/XUnit.props @@ -13,6 +13,6 @@ $(MSBuildThisFileDirectory)\avalonia.snk - True + False diff --git a/native/Avalonia.Native/inc/.gitignore b/native/Avalonia.Native/inc/.gitignore new file mode 100644 index 0000000000..e7aa7fc6a5 --- /dev/null +++ b/native/Avalonia.Native/inc/.gitignore @@ -0,0 +1 @@ +avalonia-native.h diff --git a/native/Avalonia.Native/inc/avalonia-native.h b/native/Avalonia.Native/inc/avalonia-native.h deleted file mode 100644 index 9ff6130e5f..0000000000 --- a/native/Avalonia.Native/inc/avalonia-native.h +++ /dev/null @@ -1,516 +0,0 @@ -#include "com.h" -#include "key.h" -#include "stddef.h" - -#define AVNCOM(name, id) COMINTERFACE(name, 2e2cda0a, 9ae5, 4f1b, 8e, 20, 08, 1a, 04, 27, 9f, id) - -struct IAvnWindowEvents; -struct IAvnWindow; -struct IAvnPopup; -struct IAvnMacOptions; -struct IAvnPlatformThreadingInterface; -struct IAvnSystemDialogEvents; -struct IAvnSystemDialogs; -struct IAvnScreens; -struct IAvnClipboard; -struct IAvnCursor; -struct IAvnCursorFactory; -struct IAvnGlFeature; -struct IAvnGlContext; -struct IAvnGlDisplay; -struct IAvnGlSurfaceRenderTarget; -struct IAvnGlSurfaceRenderingSession; -struct IAvnMenu; -struct IAvnMenuItem; -struct IAvnStringArray; -struct IAvnDndResultCallback; -struct IAvnGCHandleDeallocatorCallback; -struct IAvnMenuEvents; -struct IAvnNativeControlHost; -struct IAvnNativeControlHostTopLevelAttachment; -enum SystemDecorations { - SystemDecorationsNone = 0, - SystemDecorationsBorderOnly = 1, - SystemDecorationsFull = 2, -}; - -struct AvnSize -{ - double Width, Height; -}; - -struct AvnPixelSize -{ - int Width, Height; -}; - -struct AvnRect -{ - double X, Y, Width, Height; -}; - -struct AvnVector -{ - double X, Y; -}; - -struct AvnPoint -{ - double X, Y; -}; - -struct AvnScreen -{ - AvnRect Bounds; - AvnRect WorkingArea; - float PixelDensity; - bool Primary; -}; - -enum AvnPixelFormat -{ - kAvnRgb565, - kAvnRgba8888, - kAvnBgra8888 -}; - -struct AvnFramebuffer -{ - void* Data; - int Width; - int Height; - int Stride; - AvnVector Dpi; - AvnPixelFormat PixelFormat; -}; - -struct AvnColor -{ - unsigned char Alpha; - unsigned char Red; - unsigned char Green; - unsigned char Blue; -}; - -enum AvnRawMouseEventType -{ - LeaveWindow, - LeftButtonDown, - LeftButtonUp, - RightButtonDown, - RightButtonUp, - MiddleButtonDown, - MiddleButtonUp, - XButton1Down, - XButton1Up, - XButton2Down, - XButton2Up, - Move, - Wheel, - NonClientLeftButtonDown, - TouchBegin, - TouchUpdate, - TouchEnd, - TouchCancel -}; - -enum AvnRawKeyEventType -{ - KeyDown, - KeyUp -}; - -enum AvnInputModifiers -{ - AvnInputModifiersNone = 0, - Alt = 1, - Control = 2, - Shift = 4, - Windows = 8, - LeftMouseButton = 16, - RightMouseButton = 32, - MiddleMouseButton = 64, - XButton1MouseButton = 128, - XButton2MouseButton = 256 -}; - -enum class AvnDragDropEffects -{ - None = 0, - Copy = 1, - Move = 2, - Link = 4, -}; - -enum class AvnDragEventType -{ - Enter, - Over, - Leave, - Drop -}; - -enum AvnWindowState -{ - Normal, - Minimized, - Maximized, - FullScreen, -}; - -enum AvnStandardCursorType -{ - CursorArrow, - CursorIbeam, - CursorWait, - CursorCross, - CursorUpArrow, - CursorSizeWestEast, - CursorSizeNorthSouth, - CursorSizeAll, - CursorNo, - CursorHand, - CursorAppStarting, - CursorHelp, - CursorTopSide, - CursorBottomSize, - CursorLeftSide, - CursorRightSide, - CursorTopLeftCorner, - CursorTopRightCorner, - CursorBottomLeftCorner, - CursorBottomRightCorner, - CursorDragMove, - CursorDragCopy, - CursorDragLink, - CursorNone -}; - -enum AvnWindowEdge -{ - WindowEdgeNorthWest, - WindowEdgeNorth, - WindowEdgeNorthEast, - WindowEdgeWest, - WindowEdgeEast, - WindowEdgeSouthWest, - WindowEdgeSouth, - WindowEdgeSouthEast -}; - -enum AvnMenuItemToggleType -{ - None, - CheckMark, - Radio -}; - -enum AvnExtendClientAreaChromeHints -{ - AvnNoChrome = 0, - AvnSystemChrome = 0x01, - AvnPreferSystemChrome = 0x02, - AvnOSXThickTitleBar = 0x08, - AvnDefaultChrome = AvnSystemChrome, -}; - -AVNCOM(IAvaloniaNativeFactory, 01) : IUnknown -{ -public: - virtual HRESULT Initialize(IAvnGCHandleDeallocatorCallback* deallocator) = 0; - virtual IAvnMacOptions* GetMacOptions() = 0; - virtual HRESULT CreateWindow(IAvnWindowEvents* cb, IAvnGlContext* gl, IAvnWindow** ppv) = 0; - virtual HRESULT CreatePopup (IAvnWindowEvents* cb, IAvnGlContext* gl, IAvnPopup** ppv) = 0; - virtual HRESULT CreatePlatformThreadingInterface(IAvnPlatformThreadingInterface** ppv) = 0; - virtual HRESULT CreateSystemDialogs (IAvnSystemDialogs** ppv) = 0; - virtual HRESULT CreateScreens (IAvnScreens** ppv) = 0; - virtual HRESULT CreateClipboard(IAvnClipboard** ppv) = 0; - virtual HRESULT CreateDndClipboard(IAvnClipboard** ppv) = 0; - virtual HRESULT CreateCursorFactory(IAvnCursorFactory** ppv) = 0; - virtual HRESULT ObtainGlDisplay(IAvnGlDisplay** ppv) = 0; - virtual HRESULT SetAppMenu(IAvnMenu* menu) = 0; - virtual HRESULT CreateMenu (IAvnMenuEvents* cb, IAvnMenu** ppv) = 0; - virtual HRESULT CreateMenuItem (IAvnMenuItem** ppv) = 0; - virtual HRESULT CreateMenuItemSeperator (IAvnMenuItem** ppv) = 0; -}; - -AVNCOM(IAvnString, 17) : IUnknown -{ - virtual HRESULT Pointer(void**retOut) = 0; - virtual HRESULT Length(int*ret) = 0; -}; - -AVNCOM(IAvnWindowBase, 02) : IUnknown -{ - virtual HRESULT Show() = 0; - virtual HRESULT Hide () = 0; - virtual HRESULT Close() = 0; - virtual HRESULT Activate () = 0; - virtual HRESULT GetClientSize(AvnSize*ret) = 0; - virtual HRESULT GetScaling(double*ret)=0; - virtual HRESULT SetMinMaxSize(AvnSize minSize, AvnSize maxSize) = 0; - virtual HRESULT Resize(double width, double height) = 0; - virtual HRESULT Invalidate (AvnRect rect) = 0; - virtual HRESULT BeginMoveDrag () = 0; - virtual HRESULT BeginResizeDrag (AvnWindowEdge edge) = 0; - virtual HRESULT GetPosition (AvnPoint*ret) = 0; - virtual HRESULT SetPosition (AvnPoint point) = 0; - virtual HRESULT PointToClient (AvnPoint point, AvnPoint*ret) = 0; - virtual HRESULT PointToScreen (AvnPoint point, AvnPoint*ret) = 0; - virtual HRESULT ThreadSafeSetSwRenderedFrame(AvnFramebuffer* fb, IUnknown* dispose) = 0; - virtual HRESULT SetTopMost (bool value) = 0; - virtual HRESULT SetCursor(IAvnCursor* cursor) = 0; - virtual HRESULT CreateGlRenderTarget(IAvnGlSurfaceRenderTarget** ret) = 0; - virtual HRESULT SetMainMenu(IAvnMenu* menu) = 0; - virtual HRESULT ObtainNSWindowHandle(void** retOut) = 0; - virtual HRESULT ObtainNSWindowHandleRetained(void** retOut) = 0; - virtual HRESULT ObtainNSViewHandle(void** retOut) = 0; - virtual HRESULT ObtainNSViewHandleRetained(void** retOut) = 0; - virtual HRESULT CreateNativeControlHost(IAvnNativeControlHost** retOut) = 0; - virtual HRESULT BeginDragAndDropOperation(AvnDragDropEffects effects, AvnPoint point, - IAvnClipboard* clipboard, IAvnDndResultCallback* cb, void* sourceHandle) = 0; - virtual HRESULT SetBlurEnabled (bool enable) = 0; -}; - -AVNCOM(IAvnPopup, 03) : virtual IAvnWindowBase -{ - -}; - -AVNCOM(IAvnWindow, 04) : virtual IAvnWindowBase -{ - virtual HRESULT SetEnabled (bool enable) = 0; - virtual HRESULT SetParent (IAvnWindow* parent) = 0; - virtual HRESULT SetCanResize(bool value) = 0; - virtual HRESULT SetDecorations(SystemDecorations value) = 0; - virtual HRESULT SetTitle (void* utf8Title) = 0; - virtual HRESULT SetTitleBarColor (AvnColor color) = 0; - virtual HRESULT SetWindowState(AvnWindowState state) = 0; - virtual HRESULT GetWindowState(AvnWindowState*ret) = 0; - virtual HRESULT TakeFocusFromChildren() = 0; - virtual HRESULT SetExtendClientArea (bool enable) = 0; - virtual HRESULT SetExtendClientAreaHints (AvnExtendClientAreaChromeHints hints) = 0; - virtual HRESULT GetExtendTitleBarHeight (double*ret) = 0; - virtual HRESULT SetExtendTitleBarHeight (double value) = 0; -}; - -AVNCOM(IAvnWindowBaseEvents, 05) : IUnknown -{ - virtual HRESULT Paint() = 0; - virtual void Closed() = 0; - virtual void Activated() = 0; - virtual void Deactivated() = 0; - virtual void Resized(const AvnSize& size) = 0; - virtual void PositionChanged (AvnPoint position) = 0; - virtual void RawMouseEvent (AvnRawMouseEventType type, - unsigned int timeStamp, - AvnInputModifiers modifiers, - AvnPoint point, - AvnVector delta) = 0; - virtual bool RawKeyEvent (AvnRawKeyEventType type, unsigned int timeStamp, AvnInputModifiers modifiers, unsigned int key) = 0; - virtual bool RawTextInputEvent (unsigned int timeStamp, const char* text) = 0; - virtual void ScalingChanged(double scaling) = 0; - virtual void RunRenderPriorityJobs() = 0; - virtual void LostFocus() = 0; - virtual AvnDragDropEffects DragEvent(AvnDragEventType type, AvnPoint position, - AvnInputModifiers modifiers, AvnDragDropEffects effects, - IAvnClipboard* clipboard, void* dataObjectHandle) = 0; -}; - - -AVNCOM(IAvnWindowEvents, 06) : IAvnWindowBaseEvents -{ - /** - * Closing Event - * Called when the user presses the OS window close button. - * return true to allow the close, return false to prevent close. - */ - virtual bool Closing () = 0; - - virtual void WindowStateChanged (AvnWindowState state) = 0; - - virtual void GotInputWhenDisabled () = 0; -}; - -AVNCOM(IAvnMacOptions, 07) : IUnknown -{ - virtual HRESULT SetShowInDock(int show) = 0; - virtual HRESULT SetApplicationTitle (void* utf8string) = 0; -}; - -AVNCOM(IAvnActionCallback, 08) : IUnknown -{ - virtual void Run() = 0; -}; - -AVNCOM(IAvnSignaledCallback, 09) : IUnknown -{ - virtual void Signaled(int priority, bool priorityContainsMeaningfulValue) = 0; -}; - -AVNCOM(IAvnLoopCancellation, 0a) : IUnknown -{ - virtual void Cancel() = 0; -}; - -AVNCOM(IAvnPlatformThreadingInterface, 0b) : IUnknown -{ - virtual bool GetCurrentThreadIsLoopThread() = 0; - virtual void SetSignaledCallback(IAvnSignaledCallback* cb) = 0; - virtual IAvnLoopCancellation* CreateLoopCancellation() = 0; - virtual HRESULT RunLoop(IAvnLoopCancellation* cancel) = 0; - // Can't pass int* to sharpgentools for some reason - virtual void Signal(int priority) = 0; - virtual IUnknown* StartTimer(int priority, int ms, IAvnActionCallback* callback) = 0; -}; - -AVNCOM(IAvnSystemDialogEvents, 0c) : IUnknown -{ - virtual void OnCompleted (int numResults, void* ptrFirstResult) = 0; -}; - -AVNCOM(IAvnSystemDialogs, 0d) : IUnknown -{ - virtual void SelectFolderDialog (IAvnWindow* parentWindowHandle, - IAvnSystemDialogEvents* events, - const char* title, - const char* initialPath) = 0; - - virtual void OpenFileDialog (IAvnWindow* parentWindowHandle, - IAvnSystemDialogEvents* events, - bool allowMultiple, - const char* title, - const char* initialDirectory, - const char* initialFile, - const char* filters) = 0; - - virtual void SaveFileDialog (IAvnWindow* parentWindowHandle, - IAvnSystemDialogEvents* events, - const char* title, - const char* initialDirectory, - const char* initialFile, - const char* filters) = 0; -}; - -AVNCOM(IAvnScreens, 0e) : IUnknown -{ - virtual HRESULT GetScreenCount (int* ret) = 0; - virtual HRESULT GetScreen (int index, AvnScreen* ret) = 0; -}; - -AVNCOM(IAvnClipboard, 0f) : IUnknown -{ - virtual HRESULT GetText (char* type, IAvnString**ppv) = 0; - virtual HRESULT SetText (char* type, void* utf8Text) = 0; - virtual HRESULT ObtainFormats(IAvnStringArray**ppv) = 0; - virtual HRESULT GetStrings(char* type, IAvnStringArray**ppv) = 0; - virtual HRESULT SetBytes(char* type, void* utf8Text, int len) = 0; - virtual HRESULT GetBytes(char* type, IAvnString**ppv) = 0; - - virtual HRESULT Clear() = 0; -}; - -AVNCOM(IAvnCursor, 10) : IUnknown -{ -}; - -AVNCOM(IAvnCursorFactory, 11) : IUnknown -{ - virtual HRESULT GetCursor (AvnStandardCursorType cursorType, IAvnCursor** retOut) = 0; -}; - -AVNCOM(IAvnGlDisplay, 13) : IUnknown -{ - virtual HRESULT CreateContext(IAvnGlContext* share, IAvnGlContext**ppv) = 0; - virtual void LegacyClearCurrentContext() = 0; - virtual HRESULT WrapContext(void* native, IAvnGlContext**ppv) = 0; - virtual void* GetProcAddress(char* proc) = 0; -}; - -AVNCOM(IAvnGlContext, 14) : IUnknown -{ - virtual HRESULT MakeCurrent(IUnknown** ppv) = 0; - virtual HRESULT LegacyMakeCurrent() = 0; - virtual int GetSampleCount() = 0; - virtual int GetStencilSize() = 0; - virtual void* GetNativeHandle() = 0; -}; - -AVNCOM(IAvnGlSurfaceRenderTarget, 15) : IUnknown -{ - virtual HRESULT BeginDrawing(IAvnGlSurfaceRenderingSession** ret) = 0; -}; - -AVNCOM(IAvnGlSurfaceRenderingSession, 16) : IUnknown -{ - virtual HRESULT GetPixelSize(AvnPixelSize* ret) = 0; - virtual HRESULT GetScaling(double* ret) = 0; -}; - -AVNCOM(IAvnMenu, 17) : IUnknown -{ - virtual HRESULT InsertItem (int index, IAvnMenuItem* item) = 0; - virtual HRESULT RemoveItem (IAvnMenuItem* item) = 0; - virtual HRESULT SetTitle (void* utf8String) = 0; - virtual HRESULT Clear () = 0; -}; - -AVNCOM(IAvnPredicateCallback, 18) : IUnknown -{ - virtual bool Evaluate() = 0; -}; - -AVNCOM(IAvnMenuItem, 19) : IUnknown -{ - virtual HRESULT SetSubMenu (IAvnMenu* menu) = 0; - virtual HRESULT SetTitle (void* utf8String) = 0; - virtual HRESULT SetGesture (void* utf8String, AvnInputModifiers modifiers) = 0; - virtual HRESULT SetAction (IAvnPredicateCallback* predicate, IAvnActionCallback* callback) = 0; - virtual HRESULT SetIsChecked (bool isChecked) = 0; - virtual HRESULT SetToggleType (AvnMenuItemToggleType toggleType) = 0; - virtual HRESULT SetIcon (void* data, size_t length) = 0; -}; - -AVNCOM(IAvnMenuEvents, 1A) : IUnknown -{ - /** - * NeedsUpdate - */ - virtual void NeedsUpdate () = 0; -}; - -AVNCOM(IAvnStringArray, 20) : IUnknown -{ - virtual unsigned int GetCount() = 0; - virtual HRESULT Get(unsigned int index, IAvnString**ppv) = 0; -}; - -AVNCOM(IAvnDndResultCallback, 21) : IUnknown -{ - virtual void OnDragAndDropComplete(AvnDragDropEffects effecct) = 0; -}; - -AVNCOM(IAvnGCHandleDeallocatorCallback, 22) : IUnknown -{ - virtual void FreeGCHandle(void* handle) = 0; -}; - -AVNCOM(IAvnNativeControlHost, 20) : IUnknown -{ - virtual HRESULT CreateDefaultChild(void* parent, void** retOut) = 0; - virtual IAvnNativeControlHostTopLevelAttachment* CreateAttachment() = 0; - virtual void DestroyDefaultChild(void* child) = 0; -}; - -AVNCOM(IAvnNativeControlHostTopLevelAttachment, 21) : IUnknown -{ - virtual void* GetParentHandle() = 0; - virtual HRESULT InitializeWithChildHandle(void* child) = 0; - virtual HRESULT AttachTo(IAvnNativeControlHost* host) = 0; - virtual void ShowInBounds(float x, float y, float width, float height) = 0; - virtual void HideWithSize(float width, float height) = 0; - virtual void ReleaseChild() = 0; -}; - - -extern "C" IAvaloniaNativeFactory* CreateAvaloniaNative(); diff --git a/native/Avalonia.Native/inc/key.h b/native/Avalonia.Native/inc/key.h deleted file mode 100644 index 12d283cc17..0000000000 --- a/native/Avalonia.Native/inc/key.h +++ /dev/null @@ -1,1020 +0,0 @@ -#ifndef _KEY_H_ -#define _KEY_H_ - -/// -/// Defines the keys available on a keyboard. -/// -enum AvnKey -{ - /// - /// No key pressed. - /// - AvnKeyNone = 0, - - /// - /// The Cancel key. - /// - AvnKeyCancel = 1, - - /// - /// The Back key. - /// - AvnKeyBack = 2, - - /// - /// The Tab key. - /// - AvnKeyTab = 3, - - /// - /// The Linefeed key. - /// - AvnKeyLineFeed = 4, - - /// - /// The Clear key. - /// - AvnKeyClear = 5, - - /// - /// The Return key. - /// - AvnKeyReturn = 6, - - /// - /// The Enter key. - /// - AvnKeyEnter = 6, - - /// - /// The Pause key. - /// - AvnKeyPause = 7, - - /// - /// The Caps Lock key. - /// - AvnKeyCapsLock = 8, - - /// - /// The Caps Lock key. - /// - AvnKeyCapital = 8, - - /// - /// The IME Hangul mode key. - /// - AvnKeyHangulMode = 9, - - /// - /// The IME Kana mode key. - /// - AvnKeyKanaMode = 9, - - /// - /// The IME Junja mode key. - /// - AvnKeyJunjaMode = 10, - - /// - /// The IME Final mode key. - /// - AvnKeyFinalMode = 11, - - /// - /// The IME Kanji mode key. - /// - AvnKeyKanjiMode = 12, - - /// - /// The IME Hanja mode key. - /// - HanjaMode = 12, - - /// - /// The Escape key. - /// - Escape = 13, - - /// - /// The IME Convert key. - /// - ImeConvert = 14, - - /// - /// The IME NonConvert key. - /// - ImeNonConvert = 15, - - /// - /// The IME Accept key. - /// - ImeAccept = 16, - - /// - /// The IME Mode change key. - /// - ImeModeChange = 17, - - /// - /// The space bar. - /// - Space = 18, - - /// - /// The Page Up key. - /// - PageUp = 19, - - /// - /// The Page Up key. - /// - Prior = 19, - - /// - /// The Page Down key. - /// - PageDown = 20, - - /// - /// The Page Down key. - /// - Next = 20, - - /// - /// The End key. - /// - End = 21, - - /// - /// The Home key. - /// - Home = 22, - - /// - /// The Left arrow key. - /// - Left = 23, - - /// - /// The Up arrow key. - /// - Up = 24, - - /// - /// The Right arrow key. - /// - Right = 25, - - /// - /// The Down arrow key. - /// - Down = 26, - - /// - /// The Select key. - /// - Select = 27, - - /// - /// The Print key. - /// - Print = 28, - - /// - /// The Execute key. - /// - Execute = 29, - - /// - /// The Print Screen key. - /// - Snapshot = 30, - - /// - /// The Print Screen key. - /// - PrintScreen = 30, - - /// - /// The Insert key. - /// - Insert = 31, - - /// - /// The Delete key. - /// - Delete = 32, - - /// - /// The Help key. - /// - Help = 33, - - /// - /// The 0 key. - /// - D0 = 34, - - /// - /// The 1 key. - /// - D1 = 35, - - /// - /// The 2 key. - /// - D2 = 36, - - /// - /// The 3 key. - /// - D3 = 37, - - /// - /// The 4 key. - /// - D4 = 38, - - /// - /// The 5 key. - /// - D5 = 39, - - /// - /// The 6 key. - /// - D6 = 40, - - /// - /// The 7 key. - /// - D7 = 41, - - /// - /// The 8 key. - /// - D8 = 42, - - /// - /// The 9 key. - /// - D9 = 43, - - /// - /// The A key. - /// - A = 44, - - /// - /// The B key. - /// - B = 45, - - /// - /// The C key. - /// - C = 46, - - /// - /// The D key. - /// - D = 47, - - /// - /// The E key. - /// - E = 48, - - /// - /// The F key. - /// - F = 49, - - /// - /// The G key. - /// - G = 50, - - /// - /// The H key. - /// - H = 51, - - /// - /// The I key. - /// - I = 52, - - /// - /// The J key. - /// - J = 53, - - /// - /// The K key. - /// - AvnKeyK = 54, - - /// - /// The L key. - /// - L = 55, - - /// - /// The M key. - /// - M = 56, - - /// - /// The N key. - /// - N = 57, - - /// - /// The O key. - /// - O = 58, - - /// - /// The P key. - /// - P = 59, - - /// - /// The Q key. - /// - Q = 60, - - /// - /// The R key. - /// - R = 61, - - /// - /// The S key. - /// - S = 62, - - /// - /// The T key. - /// - T = 63, - - /// - /// The U key. - /// - U = 64, - - /// - /// The V key. - /// - V = 65, - - /// - /// The W key. - /// - W = 66, - - /// - /// The X key. - /// - X = 67, - - /// - /// The Y key. - /// - Y = 68, - - /// - /// The Z key. - /// - Z = 69, - - /// - /// The left Windows key. - /// - LWin = 70, - - /// - /// The right Windows key. - /// - RWin = 71, - - /// - /// The Application key. - /// - Apps = 72, - - /// - /// The Sleep key. - /// - Sleep = 73, - - /// - /// The 0 key on the numeric keypad. - /// - NumPad0 = 74, - - /// - /// The 1 key on the numeric keypad. - /// - NumPad1 = 75, - - /// - /// The 2 key on the numeric keypad. - /// - NumPad2 = 76, - - /// - /// The 3 key on the numeric keypad. - /// - NumPad3 = 77, - - /// - /// The 4 key on the numeric keypad. - /// - NumPad4 = 78, - - /// - /// The 5 key on the numeric keypad. - /// - NumPad5 = 79, - - /// - /// The 6 key on the numeric keypad. - /// - NumPad6 = 80, - - /// - /// The 7 key on the numeric keypad. - /// - NumPad7 = 81, - - /// - /// The 8 key on the numeric keypad. - /// - NumPad8 = 82, - - /// - /// The 9 key on the numeric keypad. - /// - NumPad9 = 83, - - /// - /// The Multiply key. - /// - Multiply = 84, - - /// - /// The Add key. - /// - Add = 85, - - /// - /// The Separator key. - /// - Separator = 86, - - /// - /// The Subtract key. - /// - Subtract = 87, - - /// - /// The Decimal key. - /// - Decimal = 88, - - /// - /// The Divide key. - /// - Divide = 89, - - /// - /// The F1 key. - /// - F1 = 90, - - /// - /// The F2 key. - /// - F2 = 91, - - /// - /// The F3 key. - /// - F3 = 92, - - /// - /// The F4 key. - /// - F4 = 93, - - /// - /// The F5 key. - /// - F5 = 94, - - /// - /// The F6 key. - /// - F6 = 95, - - /// - /// The F7 key. - /// - F7 = 96, - - /// - /// The F8 key. - /// - F8 = 97, - - /// - /// The F9 key. - /// - F9 = 98, - - /// - /// The F10 key. - /// - F10 = 99, - - /// - /// The F11 key. - /// - F11 = 100, - - /// - /// The F12 key. - /// - F12 = 101, - - /// - /// The F13 key. - /// - F13 = 102, - - /// - /// The F14 key. - /// - F14 = 103, - - /// - /// The F15 key. - /// - F15 = 104, - - /// - /// The F16 key. - /// - F16 = 105, - - /// - /// The F17 key. - /// - F17 = 106, - - /// - /// The F18 key. - /// - F18 = 107, - - /// - /// The F19 key. - /// - F19 = 108, - - /// - /// The F20 key. - /// - F20 = 109, - - /// - /// The F21 key. - /// - F21 = 110, - - /// - /// The F22 key. - /// - F22 = 111, - - /// - /// The F23 key. - /// - F23 = 112, - - /// - /// The F24 key. - /// - F24 = 113, - - /// - /// The Numlock key. - /// - NumLock = 114, - - /// - /// The Scroll key. - /// - Scroll = 115, - - /// - /// The left Shift key. - /// - LeftShift = 116, - - /// - /// The right Shift key. - /// - RightShift = 117, - - /// - /// The left Ctrl key. - /// - LeftCtrl = 118, - - /// - /// The right Ctrl key. - /// - RightCtrl = 119, - - /// - /// The left Alt key. - /// - LeftAlt = 120, - - /// - /// The right Alt key. - /// - RightAlt = 121, - - /// - /// The browser Back key. - /// - BrowserBack = 122, - - /// - /// The browser Forward key. - /// - BrowserForward = 123, - - /// - /// The browser Refresh key. - /// - BrowserRefresh = 124, - - /// - /// The browser Stop key. - /// - BrowserStop = 125, - - /// - /// The browser Search key. - /// - BrowserSearch = 126, - - /// - /// The browser Favorites key. - /// - BrowserFavorites = 127, - - /// - /// The browser Home key. - /// - BrowserHome = 128, - - /// - /// The Volume Mute key. - /// - VolumeMute = 129, - - /// - /// The Volume Down key. - /// - VolumeDown = 130, - - /// - /// The Volume Up key. - /// - VolumeUp = 131, - - /// - /// The media Next Track key. - /// - MediaNextTrack = 132, - - /// - /// The media Previous Track key. - /// - MediaPreviousTrack = 133, - - /// - /// The media Stop key. - /// - MediaStop = 134, - - /// - /// The media Play/Pause key. - /// - MediaPlayPause = 135, - - /// - /// The Launch Mail key. - /// - LaunchMail = 136, - - /// - /// The Select Media key. - /// - SelectMedia = 137, - - /// - /// The Launch Application 1 key. - /// - LaunchApplication1 = 138, - - /// - /// The Launch Application 2 key. - /// - LaunchApplication2 = 139, - - /// - /// The OEM Semicolon key. - /// - OemSemicolon = 140, - - /// - /// The OEM 1 key. - /// - Oem1 = 140, - - /// - /// The OEM Plus key. - /// - OemPlus = 141, - - /// - /// The OEM Comma key. - /// - OemComma = 142, - - /// - /// The OEM Minus key. - /// - OemMinus = 143, - - /// - /// The OEM Period key. - /// - OemPeriod = 144, - - /// - /// The OEM Question Mark key. - /// - OemQuestion = 145, - - /// - /// The OEM 2 key. - /// - Oem2 = 145, - - /// - /// The OEM Tilde key. - /// - OemTilde = 146, - - /// - /// The OEM 3 key. - /// - Oem3 = 146, - - /// - /// The ABNT_C1 (Brazilian) key. - /// - AbntC1 = 147, - - /// - /// The ABNT_C2 (Brazilian) key. - /// - AbntC2 = 148, - - /// - /// The OEM Open Brackets key. - /// - OemOpenBrackets = 149, - - /// - /// The OEM 4 key. - /// - Oem4 = 149, - - /// - /// The OEM Pipe key. - /// - OemPipe = 150, - - /// - /// The OEM 5 key. - /// - Oem5 = 150, - - /// - /// The OEM Close Brackets key. - /// - OemCloseBrackets = 151, - - /// - /// The OEM 6 key. - /// - Oem6 = 151, - - /// - /// The OEM Quotes key. - /// - OemQuotes = 152, - - /// - /// The OEM 7 key. - /// - Oem7 = 152, - - /// - /// The OEM 8 key. - /// - Oem8 = 153, - - /// - /// The OEM Backslash key. - /// - OemBackslash = 154, - - /// - /// The OEM 3 key. - /// - Oem102 = 154, - - /// - /// A special key masking the real key being processed by an IME. - /// - ImeProcessed = 155, - - /// - /// A special key masking the real key being processed as a system key. - /// - System = 156, - - /// - /// The OEM ATTN key. - /// - OemAttn = 157, - - /// - /// The DBE_ALPHANUMERIC key. - /// - DbeAlphanumeric = 157, - - /// - /// The OEM Finish key. - /// - OemFinish = 158, - - /// - /// The DBE_KATAKANA key. - /// - DbeKatakana = 158, - - /// - /// The DBE_HIRAGANA key. - /// - DbeHiragana = 159, - - /// - /// The OEM Copy key. - /// - OemCopy = 159, - - /// - /// The DBE_SBCSCHAR key. - /// - DbeSbcsChar = 160, - - /// - /// The OEM Auto key. - /// - OemAuto = 160, - - /// - /// The DBE_DBCSCHAR key. - /// - DbeDbcsChar = 161, - - /// - /// The OEM ENLW key. - /// - OemEnlw = 161, - - /// - /// The OEM BackTab key. - /// - OemBackTab = 162, - - /// - /// The DBE_ROMAN key. - /// - DbeRoman = 162, - - /// - /// The DBE_NOROMAN key. - /// - DbeNoRoman = 163, - - /// - /// The ATTN key. - /// - Attn = 163, - - /// - /// The CRSEL key. - /// - CrSel = 164, - - /// - /// The DBE_ENTERWORDREGISTERMODE key. - /// - DbeEnterWordRegisterMode = 164, - - /// - /// The EXSEL key. - /// - ExSel = 165, - - /// - /// The DBE_ENTERIMECONFIGMODE key. - /// - DbeEnterImeConfigureMode = 165, - - /// - /// The ERASE EOF Key. - /// - EraseEof = 166, - - /// - /// The DBE_FLUSHSTRING key. - /// - DbeFlushString = 166, - - /// - /// The Play key. - /// - Play = 167, - - /// - /// The DBE_CODEINPUT key. - /// - DbeCodeInput = 167, - - /// - /// The DBE_NOCODEINPUT key. - /// - DbeNoCodeInput = 168, - - /// - /// The Zoom key. - /// - Zoom = 168, - - /// - /// Reserved for future use. - /// - NoName = 169, - - /// - /// The DBE_DETERMINESTRING key. - /// - DbeDetermineString = 169, - - /// - /// The DBE_ENTERDLGCONVERSIONMODE key. - /// - DbeEnterDialogConversionMode = 170, - - /// - /// The PA1 key. - /// - Pa1 = 170, - - /// - /// The OEM Clear key. - /// - OemClear = 171, - - /// - /// The key is used with another key to create a single combined character. - /// - DeadCharProcessed = 172, -}; - -#endif diff --git a/native/Avalonia.Native/src/OSX/Avalonia.Native.OSX.xcodeproj/project.pbxproj b/native/Avalonia.Native/src/OSX/Avalonia.Native.OSX.xcodeproj/project.pbxproj index d5cad4d1ca..dba3ee6d31 100644 --- a/native/Avalonia.Native/src/OSX/Avalonia.Native.OSX.xcodeproj/project.pbxproj +++ b/native/Avalonia.Native/src/OSX/Avalonia.Native.OSX.xcodeproj/project.pbxproj @@ -8,19 +8,20 @@ /* Begin PBXBuildFile section */ 1A002B9E232135EE00021753 /* app.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A002B9D232135EE00021753 /* app.mm */; }; + 1A1852DC23E05814008F0DED /* deadlock.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A1852DB23E05814008F0DED /* deadlock.mm */; }; 1A3E5EA823E9E83B00EDE661 /* rendertarget.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A3E5EA723E9E83B00EDE661 /* rendertarget.mm */; }; 1A3E5EAA23E9F26C00EDE661 /* IOSurface.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A3E5EA923E9F26C00EDE661 /* IOSurface.framework */; }; - 1A1852DC23E05814008F0DED /* deadlock.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A1852DB23E05814008F0DED /* deadlock.mm */; }; - 1AFD334123E03C4F0042899B /* controlhost.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AFD334023E03C4F0042899B /* controlhost.mm */; }; 1A3E5EAE23E9FB1300EDE661 /* cgl.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A3E5EAD23E9FB1300EDE661 /* cgl.mm */; }; 1A3E5EB023E9FE8300EDE661 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A3E5EAF23E9FE8300EDE661 /* QuartzCore.framework */; }; 1A465D10246AB61600C5858B /* dnd.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A465D0F246AB61600C5858B /* dnd.mm */; }; + 1AFD334123E03C4F0042899B /* controlhost.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AFD334023E03C4F0042899B /* controlhost.mm */; }; 37155CE4233C00EB0034DCE9 /* menu.h in Headers */ = {isa = PBXBuildFile; fileRef = 37155CE3233C00EB0034DCE9 /* menu.h */; }; 37A517B32159597E00FBA241 /* Screens.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37A517B22159597E00FBA241 /* Screens.mm */; }; 37C09D8821580FE4006A6758 /* SystemDialogs.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37C09D8721580FE4006A6758 /* SystemDialogs.mm */; }; 37DDA9B0219330F8002E132B /* AvnString.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37DDA9AF219330F8002E132B /* AvnString.mm */; }; 37E2330F21583241000CB7E2 /* KeyTransform.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37E2330E21583241000CB7E2 /* KeyTransform.mm */; }; 520624B322973F4100C4DCEF /* menu.mm in Sources */ = {isa = PBXBuildFile; fileRef = 520624B222973F4100C4DCEF /* menu.mm */; }; + 522D5959258159C1006F7F7A /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 522D5958258159C1006F7F7A /* Carbon.framework */; }; 5B21A982216530F500CEE36E /* cursor.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5B21A981216530F500CEE36E /* cursor.mm */; }; 5B8BD94F215BFEA6005ED2A7 /* clipboard.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5B8BD94E215BFEA6005ED2A7 /* clipboard.mm */; }; AB00E4F72147CA920032A60A /* main.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB00E4F62147CA920032A60A /* main.mm */; }; @@ -32,13 +33,13 @@ /* Begin PBXFileReference section */ 1A002B9D232135EE00021753 /* app.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = app.mm; sourceTree = ""; }; + 1A1852DB23E05814008F0DED /* deadlock.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = deadlock.mm; sourceTree = ""; }; 1A3E5EA723E9E83B00EDE661 /* rendertarget.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = rendertarget.mm; sourceTree = ""; }; 1A3E5EA923E9F26C00EDE661 /* IOSurface.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOSurface.framework; path = System/Library/Frameworks/IOSurface.framework; sourceTree = SDKROOT; }; - 1A1852DB23E05814008F0DED /* deadlock.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = deadlock.mm; sourceTree = ""; }; - 1AFD334023E03C4F0042899B /* controlhost.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = controlhost.mm; sourceTree = ""; }; 1A3E5EAD23E9FB1300EDE661 /* cgl.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = cgl.mm; sourceTree = ""; }; 1A3E5EAF23E9FE8300EDE661 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; 1A465D0F246AB61600C5858B /* dnd.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = dnd.mm; sourceTree = ""; }; + 1AFD334023E03C4F0042899B /* controlhost.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = controlhost.mm; sourceTree = ""; }; 37155CE3233C00EB0034DCE9 /* menu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = menu.h; sourceTree = ""; }; 379860FE214DA0C000CD0246 /* KeyTransform.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KeyTransform.h; sourceTree = ""; }; 37A4E71A2178846A00EACBCD /* headers */ = {isa = PBXFileReference; lastKnownFileType = folder; name = headers; path = ../../inc; sourceTree = ""; }; @@ -49,6 +50,7 @@ 37DDA9B121933371002E132B /* AvnString.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AvnString.h; sourceTree = ""; }; 37E2330E21583241000CB7E2 /* KeyTransform.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = KeyTransform.mm; sourceTree = ""; }; 520624B222973F4100C4DCEF /* menu.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = menu.mm; sourceTree = ""; }; + 522D5958258159C1006F7F7A /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = System/Library/Frameworks/Carbon.framework; sourceTree = SDKROOT; }; 5B21A981216530F500CEE36E /* cursor.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = cursor.mm; sourceTree = ""; }; 5B8BD94E215BFEA6005ED2A7 /* clipboard.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = clipboard.mm; sourceTree = ""; }; 5BF943652167AD1D009CAE35 /* cursor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = cursor.h; sourceTree = ""; }; @@ -69,6 +71,7 @@ 1A3E5EB023E9FE8300EDE661 /* QuartzCore.framework in Frameworks */, 1A3E5EAA23E9F26C00EDE661 /* IOSurface.framework in Frameworks */, AB1E522C217613570091CD71 /* OpenGL.framework in Frameworks */, + 522D5959258159C1006F7F7A /* Carbon.framework in Frameworks */, AB661C1E2148230F00291242 /* AppKit.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -79,6 +82,7 @@ AB661C1C2148230E00291242 /* Frameworks */ = { isa = PBXGroup; children = ( + 522D5958258159C1006F7F7A /* Carbon.framework */, 1A3E5EAF23E9FE8300EDE661 /* QuartzCore.framework */, 1A3E5EA923E9F26C00EDE661 /* IOSurface.framework */, AB1E522B217613570091CD71 /* OpenGL.framework */, diff --git a/native/Avalonia.Native/src/OSX/KeyTransform.h b/native/Avalonia.Native/src/OSX/KeyTransform.h index ea4fbecd5c..2f434570c9 100644 --- a/native/Avalonia.Native/src/OSX/KeyTransform.h +++ b/native/Avalonia.Native/src/OSX/KeyTransform.h @@ -1,9 +1,14 @@ #ifndef keytransform_h #define keytransform_h #include "common.h" -#include "key.h" #include extern std::map s_KeyMap; +extern std::map s_AvnKeyMap; + +extern std::map s_QwertyKeyMap; + +extern std::map s_UnicodeKeyMap; + #endif diff --git a/native/Avalonia.Native/src/OSX/KeyTransform.mm b/native/Avalonia.Native/src/OSX/KeyTransform.mm index ff1bf6b1af..6b7d95b619 100644 --- a/native/Avalonia.Native/src/OSX/KeyTransform.mm +++ b/native/Avalonia.Native/src/OSX/KeyTransform.mm @@ -120,6 +120,138 @@ const int kVK_UpArrow = 0x7E; //const int kVK_JIS_Eisu = 0x66; const int kVK_JIS_Kana = 0x68; +// converts from AvaloniaKeys to UnicodeSpecial keys. +std::map s_UnicodeKeyMap = +{ + { Up, NSUpArrowFunctionKey }, + { Down, NSDownArrowFunctionKey }, + { Left, NSLeftArrowFunctionKey }, + { Right, NSRightArrowFunctionKey }, + { F1, NSF1FunctionKey }, + { F2, NSF2FunctionKey }, + { F3, NSF3FunctionKey }, + { F4, NSF4FunctionKey }, + { F5, NSF5FunctionKey }, + { F6, NSF6FunctionKey }, + { F7, NSF7FunctionKey }, + { F8, NSF8FunctionKey }, + { F9, NSF9FunctionKey }, + { F10, NSF10FunctionKey }, + { F11, NSF11FunctionKey }, + { F12, NSF12FunctionKey }, + { F13, NSF13FunctionKey }, + { F14, NSF14FunctionKey }, + { F15, NSF15FunctionKey }, + { F16, NSF16FunctionKey }, + { F17, NSF17FunctionKey }, + { F18, NSF18FunctionKey }, + { F19, NSF19FunctionKey }, + { F20, NSF20FunctionKey }, + { F21, NSF21FunctionKey }, + { F22, NSF22FunctionKey }, + { F23, NSF23FunctionKey }, + { F24, NSF24FunctionKey }, + { Insert, NSInsertFunctionKey }, + { Delete, NSDeleteFunctionKey }, + { Home, NSHomeFunctionKey }, + //{ Begin, NSBeginFunctionKey }, + { End, NSEndFunctionKey }, + { PageUp, NSPageUpFunctionKey }, + { PageDown, NSPageDownFunctionKey }, + { PrintScreen, NSPrintScreenFunctionKey }, + { Scroll, NSScrollLockFunctionKey }, + //{ SysReq, NSSysReqFunctionKey }, + //{ Break, NSBreakFunctionKey }, + //{ Reset, NSResetFunctionKey }, + //{ Stop, NSStopFunctionKey }, + //{ Menu, NSMenuFunctionKey }, + //{ UserFunction, NSUserFunctionKey }, + //{ SystemFunction, NSSystemFunctionKey }, + { Print, NSPrintFunctionKey }, + //{ ClearLine, NSClearLineFunctionKey }, + //{ ClearDisplay, NSClearDisplayFunctionKey }, +}; + +// Converts from Ansi virtual keys to Qwerty Keyboard map. +std::map s_QwertyKeyMap = +{ + { 0, "a" }, + { 1, "s" }, + { 2, "d" }, + { 3, "f" }, + { 4, "h" }, + { 5, "g" }, + { 6, "z" }, + { 7, "x" }, + { 8, "c" }, + { 9, "v" }, + { 10, "§" }, + { 11, "b" }, + { 12, "q" }, + { 13, "w" }, + { 14, "e" }, + { 15, "r" }, + { 16, "y" }, + { 17, "t" }, + { 18, "1" }, + { 19, "2" }, + { 20, "3" }, + { 21, "4" }, + { 22, "6" }, + { 23, "5" }, + { 24, "=" }, + { 25, "9" }, + { 26, "7" }, + { 27, "-" }, + { 28, "8" }, + { 29, "0" }, + { 30, "]" }, + { 31, "o" }, + { 32, "u" }, + { 33, "[" }, + { 34, "i" }, + { 35, "p" }, + { 37, "l" }, + { 38, "j" }, + { 39, "'" }, + { 40, "k" }, + { 41, ";" }, + { 42, "\\" }, + { 43, "," }, + { 44, "/" }, + { 45, "n" }, + { 46, "m" }, + { 47, "." }, + { 49, " " }, + { 50, "`" }, + { 51, "" }, + { 52, "" }, + { 53, "" }, + { 65, "." }, + { 66, "" }, + { 67, "*" }, + { 69, "+" }, + { 70, "" }, + { 71, "" }, + { 72, "" }, + { 75, "/" }, + { 76, "" }, + { 77, "" }, + { 78, "-" }, + { 81, "=" }, + { 82, "0" }, + { 83, "1" }, + { 84, "2" }, + { 85, "3" }, + { 86, "4" }, + { 87, "5" }, + { 88, "6" }, + { 89, "7" }, + { 91, "8" }, + { 92, "9" } +}; + +// converts from ansi virtualkeys to AvnKeys. std::map s_KeyMap = { {kVK_ANSI_A, A}, @@ -237,3 +369,22 @@ const int kVK_JIS_Kana = 0x68; {kVK_UpArrow, Up}, {kVK_JIS_Kana, AvnKeyKanaMode}, }; + +static std::map BuildAvnKeyMap () +{ + std::map result; + + for( auto it = s_KeyMap.begin(); it != s_KeyMap.end(); ++it ) + { + int key = it->first; + AvnKey value = it->second; + + result[value] = key; + } + + return result; +} + +// Converts AvnKeys to Ansi VirtualKeys +std::map s_AvnKeyMap = BuildAvnKeyMap(); + diff --git a/native/Avalonia.Native/src/OSX/clipboard.mm b/native/Avalonia.Native/src/OSX/clipboard.mm index 116a08670e..303f727317 100644 --- a/native/Avalonia.Native/src/OSX/clipboard.mm +++ b/native/Avalonia.Native/src/OSX/clipboard.mm @@ -67,7 +67,7 @@ public: } } - virtual HRESULT SetText (char* type, void* utf8String) override + virtual HRESULT SetText (char* type, char* utf8String) override { Clear(); @autoreleasepool diff --git a/native/Avalonia.Native/src/OSX/main.mm b/native/Avalonia.Native/src/OSX/main.mm index e6c4a861fd..cd6ef73826 100644 --- a/native/Avalonia.Native/src/OSX/main.mm +++ b/native/Avalonia.Native/src/OSX/main.mm @@ -104,9 +104,9 @@ class MacOptions : public ComSingleObject public: FORWARD_IUNKNOWN() - virtual HRESULT SetApplicationTitle(void* utf8String) override + virtual HRESULT SetApplicationTitle(char* utf8String) override { - auto appTitle = [NSString stringWithUTF8String:(const char*)utf8String]; + auto appTitle = [NSString stringWithUTF8String: utf8String]; [[NSProcessInfo processInfo] setProcessName:appTitle]; diff --git a/native/Avalonia.Native/src/OSX/menu.h b/native/Avalonia.Native/src/OSX/menu.h index bfbc6801f8..564fdc132b 100644 --- a/native/Avalonia.Native/src/OSX/menu.h +++ b/native/Avalonia.Native/src/OSX/menu.h @@ -43,9 +43,9 @@ public: virtual HRESULT SetSubMenu (IAvnMenu* menu) override; - virtual HRESULT SetTitle (void* utf8String) override; + virtual HRESULT SetTitle (char* utf8String) override; - virtual HRESULT SetGesture (void* key, AvnInputModifiers modifiers) override; + virtual HRESULT SetGesture (AvnKey key, AvnInputModifiers modifiers) override; virtual HRESULT SetAction (IAvnPredicateCallback* predicate, IAvnActionCallback* callback) override; @@ -80,7 +80,7 @@ public: virtual HRESULT RemoveItem (IAvnMenuItem* item) override; - virtual HRESULT SetTitle (void* utf8String) override; + virtual HRESULT SetTitle (char* utf8String) override; virtual HRESULT Clear () override; }; diff --git a/native/Avalonia.Native/src/OSX/menu.mm b/native/Avalonia.Native/src/OSX/menu.mm index dc1245cd23..198b01714f 100644 --- a/native/Avalonia.Native/src/OSX/menu.mm +++ b/native/Avalonia.Native/src/OSX/menu.mm @@ -2,6 +2,9 @@ #include "common.h" #include "menu.h" #include "window.h" +#include "KeyTransform.h" +#include +#include /* For kVK_ constants, and TIS functions. */ @implementation AvnMenu { @@ -109,7 +112,7 @@ HRESULT AvnAppMenuItem::SetSubMenu (IAvnMenu* menu) } } -HRESULT AvnAppMenuItem::SetTitle (void* utf8String) +HRESULT AvnAppMenuItem::SetTitle (char* utf8String) { @autoreleasepool { @@ -122,23 +125,57 @@ HRESULT AvnAppMenuItem::SetTitle (void* utf8String) } } -HRESULT AvnAppMenuItem::SetGesture (void* key, AvnInputModifiers modifiers) + +HRESULT AvnAppMenuItem::SetGesture (AvnKey key, AvnInputModifiers modifiers) { @autoreleasepool { - NSEventModifierFlags flags = 0; - - if (modifiers & Control) - flags |= NSEventModifierFlagControl; - if (modifiers & Shift) - flags |= NSEventModifierFlagShift; - if (modifiers & Alt) - flags |= NSEventModifierFlagOption; - if (modifiers & Windows) - flags |= NSEventModifierFlagCommand; + if(key != AvnKeyNone) + { + NSEventModifierFlags flags = 0; + + if (modifiers & Control) + flags |= NSEventModifierFlagControl; + if (modifiers & Shift) + flags |= NSEventModifierFlagShift; + if (modifiers & Alt) + flags |= NSEventModifierFlagOption; + if (modifiers & Windows) + flags |= NSEventModifierFlagCommand; + + auto it = s_UnicodeKeyMap.find(key); + + if(it != s_UnicodeKeyMap.end()) + { + auto keyString= [NSString stringWithFormat:@"%C", (unsigned short)it->second]; + + [_native setKeyEquivalent: keyString]; + [_native setKeyEquivalentModifierMask:flags]; + + return S_OK; + } + else + { + auto it = s_AvnKeyMap.find(key); // check if a virtual key is mapped. + + if(it != s_AvnKeyMap.end()) + { + auto it1 = s_QwertyKeyMap.find(it->second); // convert virtual key to qwerty string. + + if(it1 != s_QwertyKeyMap.end()) + { + [_native setKeyEquivalent: [NSString stringWithUTF8String: it1->second]]; + [_native setKeyEquivalentModifierMask:flags]; + + return S_OK; + } + } + } + } - [_native setKeyEquivalent:[NSString stringWithUTF8String:(const char*)key]]; - [_native setKeyEquivalentModifierMask:flags]; + // Nothing matched... clear. + [_native setKeyEquivalent: @""]; + [_native setKeyEquivalentModifierMask: 0]; return S_OK; } @@ -296,7 +333,7 @@ HRESULT AvnAppMenu::RemoveItem (IAvnMenuItem* item) } } -HRESULT AvnAppMenu::SetTitle (void* utf8String) +HRESULT AvnAppMenu::SetTitle (char* utf8String) { @autoreleasepool { diff --git a/native/Avalonia.Native/src/OSX/platformthreading.mm b/native/Avalonia.Native/src/OSX/platformthreading.mm index f93436d157..e83bf53331 100644 --- a/native/Avalonia.Native/src/OSX/platformthreading.mm +++ b/native/Avalonia.Native/src/OSX/platformthreading.mm @@ -101,7 +101,7 @@ public: virtual bool GetCurrentThreadIsLoopThread() override { - return [[NSThread currentThread] isMainThread]; + return [NSThread isMainThread]; } virtual void SetSignaledCallback(IAvnSignaledCallback* cb) override { diff --git a/native/Avalonia.Native/src/OSX/rendertarget.mm b/native/Avalonia.Native/src/OSX/rendertarget.mm index 93a33bbbb0..b2d4341bb9 100644 --- a/native/Avalonia.Native/src/OSX/rendertarget.mm +++ b/native/Avalonia.Native/src/OSX/rendertarget.mm @@ -2,6 +2,7 @@ #include "rendertarget.h" #import #import +#import #include #include @@ -110,7 +111,11 @@ if(_renderbuffer != 0) glDeleteRenderbuffers(1, &_renderbuffer); } - CFRelease(surface); + + if(surface != nullptr) + { + CFRelease(surface); + } } @end @@ -143,13 +148,23 @@ static IAvnGlSurfaceRenderTarget* CreateGlRenderTarget(IOSurfaceRenderTarget* ta return _layer; } -- (void)resize:(AvnPixelSize)size withScale: (float) scale;{ +- (void)resize:(AvnPixelSize)size withScale: (float) scale{ + + if(size.Height <= 0) + size.Height = 1; + if(size.Width <= 0) + size.Width = 1; + @synchronized (lock) { if(surface == nil || surface->size.Width != size.Width || surface->size.Height != size.Height || surface->scale != scale) + { surface = [[IOSurfaceHolder alloc] initWithSize:size withScale:scale withOpenGlContext:_glContext.getRaw()]; + + [self updateLayer]; + } } } @@ -159,12 +174,15 @@ static IAvnGlSurfaceRenderTarget* CreateGlRenderTarget(IOSurfaceRenderTarget* ta @synchronized (lock) { if(_layer == nil) return; + [CATransaction begin]; [_layer setContents: nil]; if(surface != nil) { [_layer setContentsScale: surface->scale]; [_layer setContents: (__bridge IOSurface*) surface->surface]; } + [CATransaction commit]; + [CATransaction flush]; } } else diff --git a/native/Avalonia.Native/src/OSX/window.mm b/native/Avalonia.Native/src/OSX/window.mm index fb945a105e..8419258fe9 100644 --- a/native/Avalonia.Native/src/OSX/window.mm +++ b/native/Avalonia.Native/src/OSX/window.mm @@ -106,13 +106,13 @@ public: return Window; } - virtual HRESULT Show() override + virtual HRESULT Show(bool activate) override { @autoreleasepool { SetPosition(lastPositionSet); UpdateStyle(); - if(ShouldTakeFocusOnShow()) + if(ShouldTakeFocusOnShow() && activate) { [Window makeKeyAndOrderFront:Window]; [NSApp activateIgnoringOtherApps:YES]; @@ -561,11 +561,11 @@ private: } } - virtual HRESULT Show () override + virtual HRESULT Show (bool activate) override { @autoreleasepool { - WindowBaseImpl::Show(); + WindowBaseImpl::Show(activate); HideOrShowTrafficLights(); @@ -768,7 +768,7 @@ private: } } - virtual HRESULT SetTitle (void* utf8title) override + virtual HRESULT SetTitle (char* utf8title) override { @autoreleasepool { @@ -1338,6 +1338,12 @@ NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEvent } _parent->BaseEvents->RunRenderPriorityJobs(); + + if (_parent == nullptr) + { + return; + } + _parent->BaseEvents->Paint(); } diff --git a/nukebuild/Build.cs b/nukebuild/Build.cs index 097815cc69..8e331edab4 100644 --- a/nukebuild/Build.cs +++ b/nukebuild/Build.cs @@ -107,7 +107,7 @@ partial class Build : NukeBuild .AddProperty("JavaSdkDirectory", GetVariable("JAVA_HOME_8_X64"))) .AddProperty("PackageVersion", Parameters.Version) .AddProperty("iOSRoslynPathHackRequired", true) - .SetToolPath(MsBuildExe.Value) + .SetProcessToolPath(MsBuildExe.Value) .SetConfiguration(Parameters.Configuration) .SetVerbosity(MSBuildVerbosity.Minimal) .Apply(configurator)); @@ -132,15 +132,16 @@ partial class Build : NukeBuild var webappDir = RootDirectory / "src" / "Avalonia.DesignerSupport" / "Remote" / "HtmlTransport" / "webapp"; NpmTasks.NpmInstall(c => c - .SetWorkingDirectory(webappDir) - .SetArgumentConfigurator(a => a.Add("--silent"))); + .SetProcessWorkingDirectory(webappDir) + .SetProcessArgumentConfigurator(a => a.Add("--silent"))); NpmTasks.NpmRun(c => c - .SetWorkingDirectory(webappDir) + .SetProcessWorkingDirectory(webappDir) .SetCommand("dist")); }); Target CompileNative => _ => _ .DependsOn(Clean) + .DependsOn(GenerateCppHeaders) .OnlyWhenStatic(() => EnvironmentInfo.IsOsx) .Executes(() => { @@ -156,7 +157,7 @@ partial class Build : NukeBuild { if (Parameters.IsRunningOnWindows) MsBuildCommon(Parameters.MSBuildSolution, c => c - .SetArgumentConfigurator(a => a.Add("/r")) + .SetProcessArgumentConfigurator(a => a.Add("/r")) .AddTargets("Build") ); @@ -193,7 +194,7 @@ partial class Build : NukeBuild var eventsProject = Path.Combine(eventsDirectory, "Avalonia.ReactiveUI.Events.csproj"); if (Parameters.IsRunningOnWindows) MsBuildCommon(eventsProject, c => c - .SetArgumentConfigurator(a => a.Add("/r")) + .SetProcessArgumentConfigurator(a => a.Add("/r")) .AddTargets("Build") ); else @@ -233,6 +234,21 @@ partial class Build : NukeBuild } } + Target RunHtmlPreviewerTests => _ => _ + .DependsOn(CompileHtmlPreviewer) + .OnlyWhenStatic(() => !(Parameters.SkipPreviewer || Parameters.SkipTests)) + .Executes(() => + { + var webappTestDir = RootDirectory / "tests" / "Avalonia.DesignerSupport.Tests" / "Remote" / "HtmlTransport" / "webapp"; + + NpmTasks.NpmInstall(c => c + .SetProcessWorkingDirectory(webappTestDir) + .SetProcessArgumentConfigurator(a => a.Add("--silent"))); + NpmTasks.NpmRun(c => c + .SetProcessWorkingDirectory(webappTestDir) + .SetCommand("test")); + }); + Target RunCoreLibsTests => _ => _ .OnlyWhenStatic(() => !Parameters.SkipTests) .DependsOn(Compile) @@ -332,6 +348,7 @@ partial class Build : NukeBuild .DependsOn(RunCoreLibsTests) .DependsOn(RunRenderTests) .DependsOn(RunDesignerTests) + .DependsOn(RunHtmlPreviewerTests) .DependsOn(RunLeakTests); Target Package => _ => _ diff --git a/nukebuild/BuildParameters.cs b/nukebuild/BuildParameters.cs index a167e9d892..c76019d9eb 100644 --- a/nukebuild/BuildParameters.cs +++ b/nukebuild/BuildParameters.cs @@ -62,7 +62,7 @@ public partial class Build public AbsolutePath ZipTargetControlCatalogDesktopDir { get; } - public BuildParameters(Build b) + public BuildParameters(Build b) { // ARGUMENTS Configuration = b.Configuration ?? "Release"; diff --git a/nukebuild/BuildTasksPatcher.cs b/nukebuild/BuildTasksPatcher.cs index 0b650ca7cc..e3766ae23f 100644 --- a/nukebuild/BuildTasksPatcher.cs +++ b/nukebuild/BuildTasksPatcher.cs @@ -30,7 +30,10 @@ public class BuildTasksPatcher { temp, typeof(Mono.Cecil.AssemblyDefinition).Assembly.GetModules()[0] .FullyQualifiedName, - typeof(Mono.Cecil.Rocks.MethodBodyRocks).Assembly.GetModules()[0].FullyQualifiedName + typeof(Mono.Cecil.Rocks.MethodBodyRocks).Assembly.GetModules()[0].FullyQualifiedName, + typeof(Mono.Cecil.Pdb.PdbReaderProvider).Assembly.GetModules()[0].FullyQualifiedName, + typeof(Mono.Cecil.Mdb.MdbReaderProvider).Assembly.GetModules()[0].FullyQualifiedName + }, SearchDirectories = new string[0], OutputFile = output diff --git a/nukebuild/MicroComGen.cs b/nukebuild/MicroComGen.cs new file mode 100644 index 0000000000..06c8acbf23 --- /dev/null +++ b/nukebuild/MicroComGen.cs @@ -0,0 +1,14 @@ +using System.IO; +using MicroComGenerator; +using Nuke.Common; + +partial class Build : NukeBuild +{ + Target GenerateCppHeaders => _ => _.Executes(() => + { + var text = File.ReadAllText(RootDirectory / "src" / "Avalonia.Native" / "avn.idl"); + var ast = AstParser.Parse(text); + File.WriteAllText(RootDirectory / "native" / "Avalonia.Native" / "inc" / "avalonia-native.h", + CppGen.GenerateCpp(ast)); + }); +} \ No newline at end of file diff --git a/nukebuild/_build.csproj b/nukebuild/_build.csproj index 77cfb83427..b0380cc92b 100644 --- a/nukebuild/_build.csproj +++ b/nukebuild/_build.csproj @@ -10,7 +10,7 @@ - + @@ -39,4 +39,8 @@ + + + + diff --git a/packages/Avalonia/Avalonia.csproj b/packages/Avalonia/Avalonia.csproj index cd3ce9adcd..44e2290a0d 100644 --- a/packages/Avalonia/Avalonia.csproj +++ b/packages/Avalonia/Avalonia.csproj @@ -5,9 +5,10 @@ - - - + + + all + @@ -15,9 +16,7 @@ - + <_PackageFiles Include="$(DesignerHostAppPath)/Avalonia.Designer.HostApp/bin/$(Configuration)/netcoreapp2.0/Avalonia.Designer.HostApp.dll"> @@ -32,21 +31,23 @@ + true - build\ + build\;buildTransitive\ true - build\ + build\;buildTransitive\ true - build\ + build\;buildTransitive\ + diff --git a/packages/Avalonia/AvaloniaBuildTasks.targets b/packages/Avalonia/AvaloniaBuildTasks.targets index 612c368633..45a7f1aa44 100644 --- a/packages/Avalonia/AvaloniaBuildTasks.targets +++ b/packages/Avalonia/AvaloniaBuildTasks.targets @@ -3,6 +3,8 @@ <_AvaloniaUseExternalMSBuild>$(AvaloniaUseExternalMSBuild) <_AvaloniaUseExternalMSBuild Condition="'$(_AvaloniaForceInternalMSBuild)' == 'true'">false low + <_AvaloniaPatchComInterop Condition="'$(_AvaloniaPatchComInterop)' == ''">false + <_AvaloniaSkipXamlCompilation Condition="'$(_AvaloniaSkipXamlCompilation)' == ''">false @@ -90,6 +92,8 @@ AssemblyOriginatorKeyFile="$(AssemblyOriginatorKeyFile)" SignAssembly="$(SignAssembly)" DelaySign="$(DelaySign)" + EnableComInteropPatching="$(_AvaloniaPatchComInterop)" + SkipXamlCompilation="$(_AvaloniaSkipXamlCompilation)" /> +([Xaml Control Gallery](https://github.com/AvaloniaUI/xamlcontrolsgallery)) + > **Note:** The UI theme you see in the picture above is still work-in-progress and will be available in the upcoming Avalonia 0.10.0 release. However, you can connect to our nightly build feed and install latest pre-release versions of Avalonia NuGet packages, if you are willing to help out with the development and testing. See [Using nightly build feed](https://github.com/AvaloniaUI/Avalonia/wiki/Using-nightly-build-feed) for more info. To see the status of some of our features, please see our [Roadmap](https://github.com/AvaloniaUI/Avalonia/issues/2239). You can also see what [breaking changes](https://github.com/AvaloniaUI/Avalonia/issues/3538) we have planned and what our [past breaking changes](https://github.com/AvaloniaUI/Avalonia/wiki/Breaking-Changes) have been. [Awesome Avalonia](https://github.com/AvaloniaCommunity/awesome-avalonia) is community-curated list of awesome Avalonia UI tools, libraries, projects and resources. Go and see what people are building with Avalonia! @@ -31,15 +33,22 @@ Install-Package Avalonia.Desktop Examples of UIs built with Avalonia ![image](https://user-images.githubusercontent.com/4672627/84707589-5b69a880-af35-11ea-87a6-7ad57a31d314.png) +([Synfonia](https://github.com/jmacato/Synfonia)) + ![image](https://user-images.githubusercontent.com/4672627/85069644-d8419000-b18a-11ea-8732-be9055bb61fd.PNG) +([Xaml Control Gallery](https://github.com/AvaloniaUI/xamlcontrolsgallery)) ![image](https://user-images.githubusercontent.com/4672627/85069659-dc6dad80-b18a-11ea-8375-39ef95315b5c.PNG) +([Xaml Control Gallery](https://github.com/AvaloniaUI/xamlcontrolsgallery)) ![image](https://user-images.githubusercontent.com/4672627/84708947-c3b98980-af37-11ea-8c9d-503334615bbf.png) +([Xaml Control Gallery](https://github.com/AvaloniaUI/xamlcontrolsgallery)) ## JetBrains Rider -If you need to develop Avalonia app with JetBrains Rider, go and *vote* on [this issue](https://youtrack.jetbrains.com/issue/RIDER-39247) in their tracker. JetBrains won't do things without their users telling them that they want the feature, so only **YOU** can make it happen. +[JetBrains Rider](https://www.jetbrains.com/rider/whatsnew/?mkt_tok=eyJpIjoiTURBNU1HSmhNV0kwTUdFMiIsInQiOiJtNnU2VEc1TlNLa1ZRVkROYmdZYVpYREJsaU1qdUhmS3dxSzRHczdYWHl0RVlTNDMwSFwvNUs3VENTNVM0bVcyNFdaRmVYZzVWTTF1N3VrQWNGTkJreEhlam1hMlB4UVVWcHBGM1dNOUxoXC95YnRQdGgyUXl1YmZCM3h3d3BVWWdBIn0%3D#avalonia-support) now has official support for Avalonia. + +Code completion, inspections and refactorings are supported out of the box, for XAML previewer add `https://plugins.jetbrains.com/plugins/dev/14839` to plugin repositories and install [AvaloniaRider](https://github.com/ForNeVeR/AvaloniaRider) plugin. ## Bleeding Edge Builds diff --git a/samples/BindingDemo/App.xaml.cs b/samples/BindingDemo/App.xaml.cs index 5c38ab8305..8a5364c70b 100644 --- a/samples/BindingDemo/App.xaml.cs +++ b/samples/BindingDemo/App.xaml.cs @@ -1,7 +1,6 @@ using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; -using Avalonia.ReactiveUI; namespace BindingDemo { @@ -25,7 +24,6 @@ namespace BindingDemo public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure() .UsePlatformDetect() - .UseReactiveUI() - .LogToDebug(); + .LogToTrace(); } } diff --git a/samples/BindingDemo/BindingDemo.csproj b/samples/BindingDemo/BindingDemo.csproj index 817023fd71..d898b737a9 100644 --- a/samples/BindingDemo/BindingDemo.csproj +++ b/samples/BindingDemo/BindingDemo.csproj @@ -6,12 +6,11 @@ - + - diff --git a/samples/BindingDemo/ViewModels/ExceptionErrorViewModel.cs b/samples/BindingDemo/ViewModels/ExceptionErrorViewModel.cs index 0fe12a8ef7..7de083351e 100644 --- a/samples/BindingDemo/ViewModels/ExceptionErrorViewModel.cs +++ b/samples/BindingDemo/ViewModels/ExceptionErrorViewModel.cs @@ -1,9 +1,9 @@ -using ReactiveUI; +using MiniMvvm; using System; namespace BindingDemo.ViewModels { - public class ExceptionErrorViewModel : ReactiveObject + public class ExceptionErrorViewModel : ViewModelBase { private int _lessThan10; diff --git a/samples/BindingDemo/ViewModels/IndeiErrorViewModel.cs b/samples/BindingDemo/ViewModels/IndeiErrorViewModel.cs index caf75c846c..9ae8d9558f 100644 --- a/samples/BindingDemo/ViewModels/IndeiErrorViewModel.cs +++ b/samples/BindingDemo/ViewModels/IndeiErrorViewModel.cs @@ -1,11 +1,11 @@ -using ReactiveUI; +using MiniMvvm; using System; using System.ComponentModel; using System.Collections; namespace BindingDemo.ViewModels { - public class IndeiErrorViewModel : ReactiveObject, INotifyDataErrorInfo + public class IndeiErrorViewModel : ViewModelBase, INotifyDataErrorInfo { private int _maximum = 10; private int _value; diff --git a/samples/BindingDemo/ViewModels/MainWindowViewModel.cs b/samples/BindingDemo/ViewModels/MainWindowViewModel.cs index f0241cad48..18a7a01a69 100644 --- a/samples/BindingDemo/ViewModels/MainWindowViewModel.cs +++ b/samples/BindingDemo/ViewModels/MainWindowViewModel.cs @@ -5,14 +5,14 @@ using System.Reactive; using System.Reactive.Linq; using System.Threading.Tasks; using System.Threading; -using ReactiveUI; +using MiniMvvm; using Avalonia.Controls; using Avalonia.Metadata; using Avalonia.Controls.Selection; namespace BindingDemo.ViewModels { - public class MainWindowViewModel : ReactiveObject + public class MainWindowViewModel : ViewModelBase { private string _booleanString = "True"; private double _doubleValue = 5.0; @@ -32,13 +32,13 @@ namespace BindingDemo.ViewModels Selection = new SelectionModel { SingleSelect = false }; - ShuffleItems = ReactiveCommand.Create(() => + ShuffleItems = MiniCommand.Create(() => { var r = new Random(); Items.Move(r.Next(Items.Count), 1); }); - StringValueCommand = ReactiveCommand.Create(param => + StringValueCommand = MiniCommand.Create(param => { BooleanFlag = !BooleanFlag; StringValue = param.ToString(); @@ -60,7 +60,7 @@ namespace BindingDemo.ViewModels public ObservableCollection Items { get; } public SelectionModel Selection { get; } - public ReactiveCommand ShuffleItems { get; } + public MiniCommand ShuffleItems { get; } public string BooleanString { @@ -93,7 +93,7 @@ namespace BindingDemo.ViewModels } public IObservable CurrentTimeObservable { get; } - public ReactiveCommand StringValueCommand { get; } + public MiniCommand StringValueCommand { get; } public DataAnnotationsErrorViewModel DataAnnotationsValidation { get; } = new DataAnnotationsErrorViewModel(); public ExceptionErrorViewModel ExceptionDataValidation { get; } = new ExceptionErrorViewModel(); diff --git a/samples/BindingDemo/ViewModels/NestedCommandViewModel.cs b/samples/BindingDemo/ViewModels/NestedCommandViewModel.cs index 0e9139ab98..1c2222b0b0 100644 --- a/samples/BindingDemo/ViewModels/NestedCommandViewModel.cs +++ b/samples/BindingDemo/ViewModels/NestedCommandViewModel.cs @@ -1,18 +1,18 @@ -using ReactiveUI; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; +using MiniMvvm; namespace BindingDemo.ViewModels { - public class NestedCommandViewModel : ReactiveObject + public class NestedCommandViewModel : ViewModelBase { public NestedCommandViewModel() { - Command = ReactiveCommand.Create(() => { }); + Command = MiniCommand.Create(() => { }); } public ICommand Command { get; } diff --git a/samples/BindingDemo/ViewModels/TestItem.cs b/samples/BindingDemo/ViewModels/TestItem.cs index 5a9f192f58..2f49a3c99f 100644 --- a/samples/BindingDemo/ViewModels/TestItem.cs +++ b/samples/BindingDemo/ViewModels/TestItem.cs @@ -1,8 +1,8 @@ -using ReactiveUI; +using MiniMvvm; namespace BindingDemo.ViewModels { - public class TestItem : ReactiveObject + public class TestItem : ViewModelBase { private string _stringValue = "String Value"; private string _detail; diff --git a/samples/ControlCatalog.Android/ControlCatalog.Android.csproj b/samples/ControlCatalog.Android/ControlCatalog.Android.csproj index 5b82e2caee..97bd0eac86 100644 --- a/samples/ControlCatalog.Android/ControlCatalog.Android.csproj +++ b/samples/ControlCatalog.Android/ControlCatalog.Android.csproj @@ -16,7 +16,7 @@ Resources\Resource.Designer.cs Off False - v9.0 + v10.0 Properties\AndroidManifest.xml @@ -156,4 +156,4 @@ - + \ No newline at end of file diff --git a/samples/ControlCatalog.Android/Properties/AndroidManifest.xml b/samples/ControlCatalog.Android/Properties/AndroidManifest.xml index e39ec39f1c..02e97f3065 100644 --- a/samples/ControlCatalog.Android/Properties/AndroidManifest.xml +++ b/samples/ControlCatalog.Android/Properties/AndroidManifest.xml @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/samples/ControlCatalog.Android/Resources/Resource.Designer.cs b/samples/ControlCatalog.Android/Resources/Resource.Designer.cs index 96f0e76fd8..4d0a6eff58 100644 --- a/samples/ControlCatalog.Android/Resources/Resource.Designer.cs +++ b/samples/ControlCatalog.Android/Resources/Resource.Designer.cs @@ -2,7 +2,6 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -15,7 +14,7 @@ namespace ControlCatalog.Android { - [System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")] public partial class Resource { @@ -26,8 +25,6 @@ namespace ControlCatalog.Android public static void UpdateIdValues() { - global::Avalonia.Android.Resource.String.ApplicationName = global::ControlCatalog.Android.Resource.String.ApplicationName; - global::Avalonia.Android.Resource.String.Hello = global::ControlCatalog.Android.Resource.String.Hello; } public partial class Attribute @@ -46,8 +43,8 @@ namespace ControlCatalog.Android public partial class Drawable { - // aapt resource value: 0x7f020000 - public const int Icon = 2130837504; + // aapt resource value: 0x7F010000 + public const int Icon = 2130771968; static Drawable() { @@ -62,8 +59,8 @@ namespace ControlCatalog.Android public partial class Id { - // aapt resource value: 0x7f050000 - public const int MyButton = 2131034112; + // aapt resource value: 0x7F020000 + public const int MyButton = 2130837504; static Id() { @@ -78,7 +75,7 @@ namespace ControlCatalog.Android public partial class Layout { - // aapt resource value: 0x7f030000 + // aapt resource value: 0x7F030000 public const int Main = 2130903040; static Layout() @@ -94,11 +91,11 @@ namespace ControlCatalog.Android public partial class String { - // aapt resource value: 0x7f040001 - public const int ApplicationName = 2130968577; + // aapt resource value: 0x7F040000 + public const int ApplicationName = 2130968576; - // aapt resource value: 0x7f040000 - public const int Hello = 2130968576; + // aapt resource value: 0x7F040001 + public const int Hello = 2130968577; static String() { diff --git a/samples/ControlCatalog.Desktop/ControlCatalog.Desktop.csproj b/samples/ControlCatalog.Desktop/ControlCatalog.Desktop.csproj index 1a112d0d7d..c6405dabb6 100644 --- a/samples/ControlCatalog.Desktop/ControlCatalog.Desktop.csproj +++ b/samples/ControlCatalog.Desktop/ControlCatalog.Desktop.csproj @@ -3,6 +3,7 @@ Exe net461 + x64 diff --git a/samples/ControlCatalog.Desktop/Program.cs b/samples/ControlCatalog.Desktop/Program.cs index e0cc8cc904..7b8b27fff7 100644 --- a/samples/ControlCatalog.Desktop/Program.cs +++ b/samples/ControlCatalog.Desktop/Program.cs @@ -3,7 +3,6 @@ using System.Linq; using Avalonia; using Avalonia.Controls; using Avalonia.Platform; -using Avalonia.ReactiveUI; namespace ControlCatalog { @@ -18,9 +17,8 @@ namespace ControlCatalog /// public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure() - .LogToDebug() - .UsePlatformDetect() - .UseReactiveUI(); + .LogToTrace() + .UsePlatformDetect(); private static void ConfigureAssetAssembly(AppBuilder builder) { diff --git a/samples/ControlCatalog.NetCore/ControlCatalog.NetCore.csproj b/samples/ControlCatalog.NetCore/ControlCatalog.NetCore.csproj index 2752703e21..d5aedf7783 100644 --- a/samples/ControlCatalog.NetCore/ControlCatalog.NetCore.csproj +++ b/samples/ControlCatalog.NetCore/ControlCatalog.NetCore.csproj @@ -12,7 +12,7 @@ - + diff --git a/samples/ControlCatalog.NetCore/Program.cs b/samples/ControlCatalog.NetCore/Program.cs index 142736a0bb..0c8fd9465c 100644 --- a/samples/ControlCatalog.NetCore/Program.cs +++ b/samples/ControlCatalog.NetCore/Program.cs @@ -7,12 +7,10 @@ using System.Threading.Tasks; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Dialogs; using Avalonia.Headless; using Avalonia.LogicalTree; -using Avalonia.Skia; -using Avalonia.ReactiveUI; using Avalonia.Threading; -using Avalonia.Dialogs; namespace ControlCatalog.NetCore { @@ -111,17 +109,16 @@ namespace ControlCatalog.NetCore .With(new X11PlatformOptions { EnableMultiTouch = true, - UseDBusMenu = true + UseDBusMenu = true, + EnableIme = true, }) .With(new Win32PlatformOptions { - EnableMultitouch = true, - AllowEglInitialization = true + EnableMultitouch = true }) .UseSkia() - .UseReactiveUI() .UseManagedSystemDialogs() - .LogToDebug(); + .LogToTrace(); static void SilenceConsole() { diff --git a/samples/ControlCatalog/App.xaml b/samples/ControlCatalog/App.xaml index 9bac320c79..6aad44c0d5 100644 --- a/samples/ControlCatalog/App.xaml +++ b/samples/ControlCatalog/App.xaml @@ -12,6 +12,16 @@ + + + diff --git a/samples/ControlCatalog/App.xaml.cs b/samples/ControlCatalog/App.xaml.cs index 22f4e9be1f..020fb2fff3 100644 --- a/samples/ControlCatalog/App.xaml.cs +++ b/samples/ControlCatalog/App.xaml.cs @@ -23,7 +23,7 @@ namespace ControlCatalog { new StyleInclude(new Uri("avares://ControlCatalog/Styles")) { - Source = new Uri("avares://Avalonia.Themes.Fluent/Accents/FluentDark.xaml") + Source = new Uri("avares://Avalonia.Themes.Fluent/FluentDark.xaml") }, DataGridFluent }; @@ -32,7 +32,7 @@ namespace ControlCatalog { new StyleInclude(new Uri("avares://ControlCatalog/Styles")) { - Source = new Uri("avares://Avalonia.Themes.Fluent/Accents/FluentLight.xaml") + Source = new Uri("avares://Avalonia.Themes.Fluent/FluentLight.xaml") }, DataGridFluent }; diff --git a/samples/ControlCatalog/Assets/Fonts/WenQuanYiMicroHei-01.ttf b/samples/ControlCatalog/Assets/Fonts/WenQuanYiMicroHei-01.ttf new file mode 100644 index 0000000000..61e2583a6c Binary files /dev/null and b/samples/ControlCatalog/Assets/Fonts/WenQuanYiMicroHei-01.ttf differ diff --git a/samples/ControlCatalog/ControlCatalog.csproj b/samples/ControlCatalog/ControlCatalog.csproj index 8a88b89b48..1aa926a2a6 100644 --- a/samples/ControlCatalog/ControlCatalog.csproj +++ b/samples/ControlCatalog/ControlCatalog.csproj @@ -24,8 +24,8 @@ - + diff --git a/samples/ControlCatalog/DecoratedWindow.xaml b/samples/ControlCatalog/DecoratedWindow.xaml index 8e4c97b7f0..5251a2fa55 100644 --- a/samples/ControlCatalog/DecoratedWindow.xaml +++ b/samples/ControlCatalog/DecoratedWindow.xaml @@ -6,25 +6,21 @@ - - - - - - - - - - - + + + + + + + + + - - - - - - + + + + diff --git a/samples/ControlCatalog/MainView.xaml b/samples/ControlCatalog/MainView.xaml index 34ff4b1a54..142c532d75 100644 --- a/samples/ControlCatalog/MainView.xaml +++ b/samples/ControlCatalog/MainView.xaml @@ -48,6 +48,7 @@ ScrollViewer.HorizontalScrollBarVisibility="Disabled"> + diff --git a/samples/ControlCatalog/MainWindow.xaml b/samples/ControlCatalog/MainWindow.xaml index 97bd88f5e4..6a70bb082f 100644 --- a/samples/ControlCatalog/MainWindow.xaml +++ b/samples/ControlCatalog/MainWindow.xaml @@ -16,47 +16,39 @@ - - - - - - - - - - - - - + + + + + + + + + - - - - - - + + + + - - - - - - - + + + + + diff --git a/samples/ControlCatalog/MainWindow.xaml.cs b/samples/ControlCatalog/MainWindow.xaml.cs index a316321cd1..723351ae57 100644 --- a/samples/ControlCatalog/MainWindow.xaml.cs +++ b/samples/ControlCatalog/MainWindow.xaml.cs @@ -67,7 +67,7 @@ namespace ControlCatalog if (Application.Current.Styles.Contains(App.FluentDark) || Application.Current.Styles.Contains(App.FluentLight)) { - var theme = new Avalonia.Themes.Fluent.FluentTheme(); + var theme = new Avalonia.Themes.Fluent.Controls.FluentControls(); theme.TryGetResource("Button", out _); } else diff --git a/samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml b/samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml index a49616e543..1a53217842 100644 --- a/samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml +++ b/samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml @@ -1,5 +1,6 @@ AutoCompleteBox @@ -56,6 +57,16 @@ Width="200" Margin="0,0,0,8" FilterMode="None"/> + + + + + + + diff --git a/samples/ControlCatalog/Pages/ButtonSpinnerPage.xaml b/samples/ControlCatalog/Pages/ButtonSpinnerPage.xaml index c3f9f65dd9..4ac2330403 100644 --- a/samples/ControlCatalog/Pages/ButtonSpinnerPage.xaml +++ b/samples/ControlCatalog/Pages/ButtonSpinnerPage.xaml @@ -1,6 +1,7 @@  + x:Class="ControlCatalog.Pages.ButtonSpinnerPage" + xmlns:sys="clr-namespace:System;assembly=netstandard"> ButtonSpinner @@ -19,6 +20,14 @@ ShowButtonSpinner="{Binding #showSpinCheck.IsChecked}"> + + + + + + diff --git a/samples/ControlCatalog/Pages/ComboBoxPage.xaml b/samples/ControlCatalog/Pages/ComboBoxPage.xaml index 369f703718..025b85492c 100644 --- a/samples/ControlCatalog/Pages/ComboBoxPage.xaml +++ b/samples/ControlCatalog/Pages/ComboBoxPage.xaml @@ -1,6 +1,7 @@ + x:Class="ControlCatalog.Pages.ComboBoxPage" + xmlns:sys="clr-namespace:System;assembly=netstandard"> ComboBox A drop-down list. @@ -35,6 +36,16 @@ + + + Inline Items + Inline Item 2 + Inline Item 3 + Inline Item 4 + + + + diff --git a/samples/ControlCatalog/Pages/DataGridPage.xaml b/samples/ControlCatalog/Pages/DataGridPage.xaml index cacc2204bd..6817d0698e 100644 --- a/samples/ControlCatalog/Pages/DataGridPage.xaml +++ b/samples/ControlCatalog/Pages/DataGridPage.xaml @@ -38,8 +38,8 @@ - - + + diff --git a/samples/ControlCatalog/Pages/DateTimePickerPage.xaml b/samples/ControlCatalog/Pages/DateTimePickerPage.xaml index af6b6e8605..45056a9a76 100644 --- a/samples/ControlCatalog/Pages/DateTimePickerPage.xaml +++ b/samples/ControlCatalog/Pages/DateTimePickerPage.xaml @@ -2,6 +2,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:sys="clr-namespace:System;assembly=netstandard" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="ControlCatalog.Pages.DateTimePickerPage"> @@ -30,6 +31,16 @@ + + + + + + + + + A DatePicker with day formatted and year hidden. + + + + + + + + A TimePicker with a header and minute increments specified. diff --git a/samples/ControlCatalog/Pages/DialogsPage.xaml.cs b/samples/ControlCatalog/Pages/DialogsPage.xaml.cs index cf6c771e34..49921fb7f6 100644 --- a/samples/ControlCatalog/Pages/DialogsPage.xaml.cs +++ b/samples/ControlCatalog/Pages/DialogsPage.xaml.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Reflection; using Avalonia.Controls; using Avalonia.Dialogs; +using Avalonia.Layout; using Avalonia.Markup.Xaml; #pragma warning disable 4014 @@ -112,11 +113,29 @@ namespace ControlCatalog.Pages private Window CreateSampleWindow() { - var window = new Window(); - window.Height = 200; - window.Width = 200; - window.Content = new TextBlock { Text = "Hello world!" }; - window.WindowStartupLocation = WindowStartupLocation.CenterOwner; + Button button; + + var window = new Window + { + Height = 200, + Width = 200, + Content = new StackPanel + { + Spacing = 4, + Children = + { + new TextBlock { Text = "Hello world!" }, + (button = new Button + { + HorizontalAlignment = HorizontalAlignment.Center, + Content = "Click to close" + }) + } + }, + WindowStartupLocation = WindowStartupLocation.CenterOwner + }; + + button.Click += (_, __) => window.Close(); return window; } diff --git a/samples/ControlCatalog/Pages/LabelsPage.axaml b/samples/ControlCatalog/Pages/LabelsPage.axaml new file mode 100644 index 0000000000..961e7ba7e6 --- /dev/null +++ b/samples/ControlCatalog/Pages/LabelsPage.axaml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/ControlCatalog/Pages/LabelsPage.axaml.cs b/samples/ControlCatalog/Pages/LabelsPage.axaml.cs new file mode 100644 index 0000000000..a14978fd2c --- /dev/null +++ b/samples/ControlCatalog/Pages/LabelsPage.axaml.cs @@ -0,0 +1,42 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; +using ControlCatalog.Models; + +namespace ControlCatalog.Pages +{ + public class LabelsPage : UserControl + { + private Person _person; + + public LabelsPage() + { + CreateDefaultPerson(); + this.InitializeComponent(); + } + + private void CreateDefaultPerson() + { + DataContext = _person = new Person + { + FirstName = "John", + LastName = "Doe", + IsBanned = true, + }; + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } + + public void DoSave() + { + + } + public void DoCancel() + { + CreateDefaultPerson(); + } + } +} diff --git a/samples/ControlCatalog/Pages/ListBoxPage.xaml b/samples/ControlCatalog/Pages/ListBoxPage.xaml index 3521ad71a9..f515db84d4 100644 --- a/samples/ControlCatalog/Pages/ListBoxPage.xaml +++ b/samples/ControlCatalog/Pages/ListBoxPage.xaml @@ -20,6 +20,6 @@ + SelectionMode="{Binding SelectionMode^}"/> diff --git a/samples/ControlCatalog/Pages/MenuPage.xaml.cs b/samples/ControlCatalog/Pages/MenuPage.xaml.cs index 46dbe3dcad..5999510b6c 100644 --- a/samples/ControlCatalog/Pages/MenuPage.xaml.cs +++ b/samples/ControlCatalog/Pages/MenuPage.xaml.cs @@ -6,7 +6,6 @@ using System.Windows.Input; using Avalonia.Controls; using Avalonia.Markup.Xaml; using ControlCatalog.ViewModels; -using ReactiveUI; namespace ControlCatalog.Pages { diff --git a/samples/ControlCatalog/Pages/NumericUpDownPage.xaml b/samples/ControlCatalog/Pages/NumericUpDownPage.xaml index 0d7e5da17f..d75622f1fb 100644 --- a/samples/ControlCatalog/Pages/NumericUpDownPage.xaml +++ b/samples/ControlCatalog/Pages/NumericUpDownPage.xaml @@ -1,5 +1,6 @@  Numeric up-down control @@ -75,6 +76,15 @@ + + NumericUpDown with Validation Errors: + + + + + diff --git a/samples/ControlCatalog/Pages/NumericUpDownPage.xaml.cs b/samples/ControlCatalog/Pages/NumericUpDownPage.xaml.cs index 92da64d87e..31749edf08 100644 --- a/samples/ControlCatalog/Pages/NumericUpDownPage.xaml.cs +++ b/samples/ControlCatalog/Pages/NumericUpDownPage.xaml.cs @@ -6,7 +6,7 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Primitives; using Avalonia.Markup.Xaml; -using ReactiveUI; +using MiniMvvm; namespace ControlCatalog.Pages { @@ -26,7 +26,7 @@ namespace ControlCatalog.Pages } - public class NumbersPageViewModel : ReactiveObject + public class NumbersPageViewModel : ViewModelBase { private IList _formats; private FormatObject _selectedFormat; diff --git a/samples/ControlCatalog/Pages/RelativePanelPage.axaml b/samples/ControlCatalog/Pages/RelativePanelPage.axaml index 3657d52bd9..4dcdcc195f 100644 --- a/samples/ControlCatalog/Pages/RelativePanelPage.axaml +++ b/samples/ControlCatalog/Pages/RelativePanelPage.axaml @@ -23,16 +23,16 @@ - + - + - + @@ -41,19 +41,19 @@ - + - + - + - + - + diff --git a/samples/ControlCatalog/Pages/ScrollViewerPage.xaml.cs b/samples/ControlCatalog/Pages/ScrollViewerPage.xaml.cs index 36d3768b13..dcd7a88a56 100644 --- a/samples/ControlCatalog/Pages/ScrollViewerPage.xaml.cs +++ b/samples/ControlCatalog/Pages/ScrollViewerPage.xaml.cs @@ -2,11 +2,11 @@ using System.Collections.Generic; using Avalonia.Controls; using Avalonia.Controls.Primitives; using Avalonia.Markup.Xaml; -using ReactiveUI; +using MiniMvvm; namespace ControlCatalog.Pages { - public class ScrollViewerPageViewModel : ReactiveObject + public class ScrollViewerPageViewModel : ViewModelBase { private bool _allowAutoHide; private ScrollBarVisibility _horizontalScrollVisibility; diff --git a/samples/ControlCatalog/Pages/SliderPage.xaml b/samples/ControlCatalog/Pages/SliderPage.xaml index ea31ed0050..eeb198976b 100644 --- a/samples/ControlCatalog/Pages/SliderPage.xaml +++ b/samples/ControlCatalog/Pages/SliderPage.xaml @@ -1,5 +1,6 @@ Slider @@ -21,6 +22,29 @@ IsSnapToTickEnabled="True" Ticks="0,20,25,40,75,100" Width="300" /> + + + + + + + + + + + x:Class="ControlCatalog.Pages.TextBoxPage" + xmlns:sys="clr-namespace:System;assembly=netstandard"> - TextBox - A control into which the user can input text + + - + + + + + + + - + - - resm fonts - - - - - - - - res fonts - - - - - + + + + + + + + + + + + + + + + diff --git a/samples/ControlCatalog/Pages/ToolTipPage.xaml b/samples/ControlCatalog/Pages/ToolTipPage.xaml index ec073d48a9..de23c7a169 100644 --- a/samples/ControlCatalog/Pages/ToolTipPage.xaml +++ b/samples/ControlCatalog/Pages/ToolTipPage.xaml @@ -6,7 +6,7 @@ ToolTip A control which pops up a hint when a control is hovered - @@ -38,6 +38,31 @@ ToolTip bottom placement + + + + + Moving offset + diff --git a/samples/ControlCatalog/ViewModels/ContextMenuPageViewModel.cs b/samples/ControlCatalog/ViewModels/ContextMenuPageViewModel.cs index 5c2f74d2d5..3f5d0cd93c 100644 --- a/samples/ControlCatalog/ViewModels/ContextMenuPageViewModel.cs +++ b/samples/ControlCatalog/ViewModels/ContextMenuPageViewModel.cs @@ -3,7 +3,7 @@ using System.Reactive; using System.Threading.Tasks; using Avalonia.Controls; using Avalonia.VisualTree; -using ReactiveUI; +using MiniMvvm; namespace ControlCatalog.ViewModels { @@ -12,9 +12,9 @@ namespace ControlCatalog.ViewModels public Control View { get; set; } public ContextMenuPageViewModel() { - OpenCommand = ReactiveCommand.CreateFromTask(Open); - SaveCommand = ReactiveCommand.Create(Save); - OpenRecentCommand = ReactiveCommand.Create(OpenRecent); + OpenCommand = MiniCommand.CreateFromTask(Open); + SaveCommand = MiniCommand.Create(Save); + OpenRecentCommand = MiniCommand.Create(OpenRecent); MenuItems = new[] { @@ -44,9 +44,9 @@ namespace ControlCatalog.ViewModels } public IReadOnlyList MenuItems { get; set; } - public ReactiveCommand OpenCommand { get; } - public ReactiveCommand SaveCommand { get; } - public ReactiveCommand OpenRecentCommand { get; } + public MiniCommand OpenCommand { get; } + public MiniCommand SaveCommand { get; } + public MiniCommand OpenRecentCommand { get; } public async Task Open() { diff --git a/samples/ControlCatalog/ViewModels/ItemsRepeaterPageViewModel.cs b/samples/ControlCatalog/ViewModels/ItemsRepeaterPageViewModel.cs index f893a6e28e..ee1fa6ae77 100644 --- a/samples/ControlCatalog/ViewModels/ItemsRepeaterPageViewModel.cs +++ b/samples/ControlCatalog/ViewModels/ItemsRepeaterPageViewModel.cs @@ -2,11 +2,11 @@ using System.Collections.ObjectModel; using System.Linq; using Avalonia.Media; -using ReactiveUI; +using MiniMvvm; namespace ControlCatalog.ViewModels { - public class ItemsRepeaterPageViewModel : ReactiveObject + public class ItemsRepeaterPageViewModel : ViewModelBase { private int _newItemIndex = 1; private int _newGenerationIndex = 0; @@ -59,7 +59,7 @@ namespace ControlCatalog.ViewModels })); } - public class Item : ReactiveObject + public class Item : ViewModelBase { private double _height = double.NaN; diff --git a/samples/ControlCatalog/ViewModels/ListBoxPageViewModel.cs b/samples/ControlCatalog/ViewModels/ListBoxPageViewModel.cs index f75bc32105..7f2d6e9572 100644 --- a/samples/ControlCatalog/ViewModels/ListBoxPageViewModel.cs +++ b/samples/ControlCatalog/ViewModels/ListBoxPageViewModel.cs @@ -4,18 +4,18 @@ using System.Linq; using System.Reactive; using Avalonia.Controls; using Avalonia.Controls.Selection; -using ReactiveUI; +using MiniMvvm; namespace ControlCatalog.ViewModels { - public class ListBoxPageViewModel : ReactiveObject + public class ListBoxPageViewModel : ViewModelBase { private bool _multiple; private bool _toggle; private bool _alwaysSelected; private bool _autoScrollToSelectedItem = true; private int _counter; - private ObservableAsPropertyHelper _selectionMode; + private IObservable _selectionMode; public ListBoxPageViewModel() { @@ -29,14 +29,13 @@ namespace ControlCatalog.ViewModels x => x.Toggle, x => x.AlwaysSelected, (m, t, a) => - (m ? SelectionMode.Multiple : 0) | - (t ? SelectionMode.Toggle : 0) | - (a ? SelectionMode.AlwaysSelected : 0)) - .ToProperty(this, x => x.SelectionMode); + (m ? Avalonia.Controls.SelectionMode.Multiple : 0) | + (t ? Avalonia.Controls.SelectionMode.Toggle : 0) | + (a ? Avalonia.Controls.SelectionMode.AlwaysSelected : 0)); - AddItemCommand = ReactiveCommand.Create(() => Items.Add(GenerateItem())); + AddItemCommand = MiniCommand.Create(() => Items.Add(GenerateItem())); - RemoveItemCommand = ReactiveCommand.Create(() => + RemoveItemCommand = MiniCommand.Create(() => { var items = Selection.SelectedItems.ToList(); @@ -46,7 +45,7 @@ namespace ControlCatalog.ViewModels } }); - SelectRandomItemCommand = ReactiveCommand.Create(() => + SelectRandomItemCommand = MiniCommand.Create(() => { var random = new Random(); @@ -60,7 +59,7 @@ namespace ControlCatalog.ViewModels public ObservableCollection Items { get; } public SelectionModel Selection { get; } - public SelectionMode SelectionMode => _selectionMode.Value; + public IObservable SelectionMode => _selectionMode; public bool Multiple { @@ -86,9 +85,9 @@ namespace ControlCatalog.ViewModels set => this.RaiseAndSetIfChanged(ref _autoScrollToSelectedItem, value); } - public ReactiveCommand AddItemCommand { get; } - public ReactiveCommand RemoveItemCommand { get; } - public ReactiveCommand SelectRandomItemCommand { get; } + public MiniCommand AddItemCommand { get; } + public MiniCommand RemoveItemCommand { get; } + public MiniCommand SelectRandomItemCommand { get; } private string GenerateItem() => $"Item {_counter++.ToString()}"; } diff --git a/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs b/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs index 4356a032fa..4b3cfa9c9d 100644 --- a/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs +++ b/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs @@ -5,11 +5,11 @@ using Avalonia.Controls.Notifications; using Avalonia.Dialogs; using Avalonia.Platform; using System; -using ReactiveUI; +using MiniMvvm; namespace ControlCatalog.ViewModels { - class MainWindowViewModel : ReactiveObject + class MainWindowViewModel : ViewModelBase { private IManagedNotificationManager _notificationManager; @@ -27,22 +27,22 @@ namespace ControlCatalog.ViewModels { _notificationManager = notificationManager; - ShowCustomManagedNotificationCommand = ReactiveCommand.Create(() => + ShowCustomManagedNotificationCommand = MiniCommand.Create(() => { NotificationManager.Show(new NotificationViewModel(NotificationManager) { Title = "Hey There!", Message = "Did you know that Avalonia now supports Custom In-Window Notifications?" }); }); - ShowManagedNotificationCommand = ReactiveCommand.Create(() => + ShowManagedNotificationCommand = MiniCommand.Create(() => { NotificationManager.Show(new Avalonia.Controls.Notifications.Notification("Welcome", "Avalonia now supports Notifications.", NotificationType.Information)); }); - ShowNativeNotificationCommand = ReactiveCommand.Create(() => + ShowNativeNotificationCommand = MiniCommand.Create(() => { NotificationManager.Show(new Avalonia.Controls.Notifications.Notification("Error", "Native Notifications are not quite ready. Coming soon.", NotificationType.Error)); }); - AboutCommand = ReactiveCommand.CreateFromTask(async () => + AboutCommand = MiniCommand.CreateFromTask(async () => { var dialog = new AboutAvaloniaDialog(); @@ -51,12 +51,12 @@ namespace ControlCatalog.ViewModels await dialog.ShowDialog(mainWindow); }); - ExitCommand = ReactiveCommand.Create(() => + ExitCommand = MiniCommand.Create(() => { (App.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime).Shutdown(); }); - ToggleMenuItemCheckedCommand = ReactiveCommand.Create(() => + ToggleMenuItemCheckedCommand = MiniCommand.Create(() => { IsMenuItemChecked = !IsMenuItemChecked; }); @@ -153,16 +153,16 @@ namespace ControlCatalog.ViewModels set { this.RaiseAndSetIfChanged(ref _isMenuItemChecked, value); } } - public ReactiveCommand ShowCustomManagedNotificationCommand { get; } + public MiniCommand ShowCustomManagedNotificationCommand { get; } - public ReactiveCommand ShowManagedNotificationCommand { get; } + public MiniCommand ShowManagedNotificationCommand { get; } - public ReactiveCommand ShowNativeNotificationCommand { get; } + public MiniCommand ShowNativeNotificationCommand { get; } - public ReactiveCommand AboutCommand { get; } + public MiniCommand AboutCommand { get; } - public ReactiveCommand ExitCommand { get; } + public MiniCommand ExitCommand { get; } - public ReactiveCommand ToggleMenuItemCheckedCommand { get; } + public MiniCommand ToggleMenuItemCheckedCommand { get; } } } diff --git a/samples/ControlCatalog/ViewModels/MenuPageViewModel.cs b/samples/ControlCatalog/ViewModels/MenuPageViewModel.cs index 9e7ae8b716..ecbd59c5d7 100644 --- a/samples/ControlCatalog/ViewModels/MenuPageViewModel.cs +++ b/samples/ControlCatalog/ViewModels/MenuPageViewModel.cs @@ -4,7 +4,7 @@ using System.Reactive.Linq; using System.Threading.Tasks; using Avalonia.Controls; using Avalonia.VisualTree; -using ReactiveUI; +using MiniMvvm; namespace ControlCatalog.ViewModels { @@ -13,9 +13,9 @@ namespace ControlCatalog.ViewModels public Control View { get; set; } public MenuPageViewModel() { - OpenCommand = ReactiveCommand.CreateFromTask(Open); - SaveCommand = ReactiveCommand.Create(Save, Observable.Return(false)); - OpenRecentCommand = ReactiveCommand.Create(OpenRecent); + OpenCommand = MiniCommand.CreateFromTask(Open); + SaveCommand = MiniCommand.Create(Save); + OpenRecentCommand = MiniCommand.Create(OpenRecent); var recentItems = new[] { @@ -65,9 +65,9 @@ namespace ControlCatalog.ViewModels public IReadOnlyList MenuItems { get; set; } public IReadOnlyList RecentItems { get; set; } - public ReactiveCommand OpenCommand { get; } - public ReactiveCommand SaveCommand { get; } - public ReactiveCommand OpenRecentCommand { get; } + public MiniCommand OpenCommand { get; } + public MiniCommand SaveCommand { get; } + public MiniCommand OpenRecentCommand { get; } public async Task Open() { diff --git a/samples/ControlCatalog/ViewModels/NotificationViewModel.cs b/samples/ControlCatalog/ViewModels/NotificationViewModel.cs index 8724ba344b..2052481015 100644 --- a/samples/ControlCatalog/ViewModels/NotificationViewModel.cs +++ b/samples/ControlCatalog/ViewModels/NotificationViewModel.cs @@ -1,6 +1,6 @@ using System.Reactive; using Avalonia.Controls.Notifications; -using ReactiveUI; +using MiniMvvm; namespace ControlCatalog.ViewModels { @@ -8,12 +8,12 @@ namespace ControlCatalog.ViewModels { public NotificationViewModel(INotificationManager manager) { - YesCommand = ReactiveCommand.Create(() => + YesCommand = MiniCommand.Create(() => { manager.Show(new Avalonia.Controls.Notifications.Notification("Avalonia Notifications", "Start adding notifications to your app today.")); }); - NoCommand = ReactiveCommand.Create(() => + NoCommand = MiniCommand.Create(() => { manager.Show(new Avalonia.Controls.Notifications.Notification("Avalonia Notifications", "Start adding notifications to your app today. To find out more visit...")); }); @@ -22,9 +22,9 @@ namespace ControlCatalog.ViewModels public string Title { get; set; } public string Message { get; set; } - public ReactiveCommand YesCommand { get; } + public MiniCommand YesCommand { get; } - public ReactiveCommand NoCommand { get; } + public MiniCommand NoCommand { get; } } } diff --git a/samples/ControlCatalog/ViewModels/SplitViewPageViewModel.cs b/samples/ControlCatalog/ViewModels/SplitViewPageViewModel.cs index f27f605a8b..9e6932bb76 100644 --- a/samples/ControlCatalog/ViewModels/SplitViewPageViewModel.cs +++ b/samples/ControlCatalog/ViewModels/SplitViewPageViewModel.cs @@ -1,10 +1,10 @@ using System; using Avalonia.Controls; -using ReactiveUI; +using MiniMvvm; namespace ControlCatalog.ViewModels { - public class SplitViewPageViewModel : ReactiveObject + public class SplitViewPageViewModel : ViewModelBase { private bool _isLeft = true; private int _displayMode = 3; //CompactOverlay diff --git a/samples/ControlCatalog/ViewModels/TreeViewPageViewModel.cs b/samples/ControlCatalog/ViewModels/TreeViewPageViewModel.cs index 210e281ed6..c03379330f 100644 --- a/samples/ControlCatalog/ViewModels/TreeViewPageViewModel.cs +++ b/samples/ControlCatalog/ViewModels/TreeViewPageViewModel.cs @@ -3,11 +3,11 @@ using System.Collections.ObjectModel; using System.Linq; using System.Reactive; using Avalonia.Controls; -using ReactiveUI; +using MiniMvvm; namespace ControlCatalog.ViewModels { - public class TreeViewPageViewModel : ReactiveObject + public class TreeViewPageViewModel : ViewModelBase { private readonly Node _root; private SelectionMode _selectionMode; @@ -19,16 +19,16 @@ namespace ControlCatalog.ViewModels Items = _root.Children; SelectedItems = new ObservableCollection(); - AddItemCommand = ReactiveCommand.Create(AddItem); - RemoveItemCommand = ReactiveCommand.Create(RemoveItem); - SelectRandomItemCommand = ReactiveCommand.Create(SelectRandomItem); + AddItemCommand = MiniCommand.Create(AddItem); + RemoveItemCommand = MiniCommand.Create(RemoveItem); + SelectRandomItemCommand = MiniCommand.Create(SelectRandomItem); } public ObservableCollection Items { get; } public ObservableCollection SelectedItems { get; } - public ReactiveCommand AddItemCommand { get; } - public ReactiveCommand RemoveItemCommand { get; } - public ReactiveCommand SelectRandomItemCommand { get; } + public MiniCommand AddItemCommand { get; } + public MiniCommand RemoveItemCommand { get; } + public MiniCommand SelectRandomItemCommand { get; } public SelectionMode SelectionMode { diff --git a/samples/MiniMvvm/MiniCommand.cs b/samples/MiniMvvm/MiniCommand.cs new file mode 100644 index 0000000000..c6a9273c20 --- /dev/null +++ b/samples/MiniMvvm/MiniCommand.cs @@ -0,0 +1,66 @@ +using System; +using System.Threading.Tasks; +using System.Windows.Input; + +namespace MiniMvvm +{ + public sealed class MiniCommand : MiniCommand, ICommand + { + private readonly Action _cb; + private bool _busy; + private Func _acb; + + public MiniCommand(Action cb) + { + _cb = cb; + } + + public MiniCommand(Func cb) + { + _acb = cb; + } + + private bool Busy + { + get => _busy; + set + { + _busy = value; + CanExecuteChanged?.Invoke(this, EventArgs.Empty); + } + } + + + public override event EventHandler CanExecuteChanged; + public override bool CanExecute(object parameter) => !_busy; + + public override async void Execute(object parameter) + { + if(Busy) + return; + try + { + Busy = true; + if (_cb != null) + _cb((T)parameter); + else + await _acb((T)parameter); + } + finally + { + Busy = false; + } + } + } + + public abstract class MiniCommand : ICommand + { + public static MiniCommand Create(Action cb) => new MiniCommand(_ => cb()); + public static MiniCommand Create(Action cb) => new MiniCommand(cb); + public static MiniCommand CreateFromTask(Func cb) => new MiniCommand(_ => cb()); + + public abstract bool CanExecute(object parameter); + public abstract void Execute(object parameter); + public abstract event EventHandler CanExecuteChanged; + } +} diff --git a/samples/MiniMvvm/MiniMvvm.csproj b/samples/MiniMvvm/MiniMvvm.csproj new file mode 100644 index 0000000000..6535b2bdbd --- /dev/null +++ b/samples/MiniMvvm/MiniMvvm.csproj @@ -0,0 +1,6 @@ + + + netstandard2.0 + + + diff --git a/samples/MiniMvvm/PropertyChangedExtensions.cs b/samples/MiniMvvm/PropertyChangedExtensions.cs new file mode 100644 index 0000000000..f1065c7530 --- /dev/null +++ b/samples/MiniMvvm/PropertyChangedExtensions.cs @@ -0,0 +1,108 @@ +using System; +using System.ComponentModel; +using System.Linq.Expressions; +using System.Reactive.Linq; +using System.Reflection; + +namespace MiniMvvm +{ + public static class PropertyChangedExtensions + { + class PropertyObservable : IObservable + { + private readonly INotifyPropertyChanged _target; + private readonly PropertyInfo _info; + + public PropertyObservable(INotifyPropertyChanged target, PropertyInfo info) + { + _target = target; + _info = info; + } + + class Subscription : IDisposable + { + private readonly INotifyPropertyChanged _target; + private readonly PropertyInfo _info; + private readonly IObserver _observer; + + public Subscription(INotifyPropertyChanged target, PropertyInfo info, IObserver observer) + { + _target = target; + _info = info; + _observer = observer; + _target.PropertyChanged += OnPropertyChanged; + _observer.OnNext((T)_info.GetValue(_target)); + } + + private void OnPropertyChanged(object sender, PropertyChangedEventArgs e) + { + if (e.PropertyName == _info.Name) + _observer.OnNext((T)_info.GetValue(_target)); + } + + public void Dispose() + { + _target.PropertyChanged -= OnPropertyChanged; + _observer.OnCompleted(); + } + } + + public IDisposable Subscribe(IObserver observer) + { + return new Subscription(_target, _info, observer); + } + } + + public static IObservable WhenAnyValue(this TModel model, + Expression> expr) where TModel : INotifyPropertyChanged + { + var l = (LambdaExpression)expr; + var ma = (MemberExpression)l.Body; + var prop = (PropertyInfo)ma.Member; + return new PropertyObservable(model, prop); + } + + public static IObservable WhenAnyValue(this TModel model, + Expression> v1, + Func cb + ) where TModel : INotifyPropertyChanged + { + return model.WhenAnyValue(v1).Select(cb); + } + + public static IObservable WhenAnyValue(this TModel model, + Expression> v1, + Expression> v2, + Func cb + ) where TModel : INotifyPropertyChanged => + Observable.CombineLatest( + model.WhenAnyValue(v1), + model.WhenAnyValue(v2), + cb); + + public static IObservable> WhenAnyValue(this TModel model, + Expression> v1, + Expression> v2 + ) where TModel : INotifyPropertyChanged => + model.WhenAnyValue(v1, v2, (a1, a2) => (a1, a2)); + + public static IObservable WhenAnyValue(this TModel model, + Expression> v1, + Expression> v2, + Expression> v3, + Func cb + ) where TModel : INotifyPropertyChanged => + Observable.CombineLatest( + model.WhenAnyValue(v1), + model.WhenAnyValue(v2), + model.WhenAnyValue(v3), + cb); + + public static IObservable> WhenAnyValue(this TModel model, + Expression> v1, + Expression> v2, + Expression> v3 + ) where TModel : INotifyPropertyChanged => + model.WhenAnyValue(v1, v2, v3, (a1, a2, a3) => (a1, a2, a3)); + } +} diff --git a/samples/MiniMvvm/ViewModelBase.cs b/samples/MiniMvvm/ViewModelBase.cs new file mode 100644 index 0000000000..7256b05cef --- /dev/null +++ b/samples/MiniMvvm/ViewModelBase.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using System.ComponentModel; +using System.Reactive.Joins; +using System.Runtime.CompilerServices; + +namespace MiniMvvm +{ + public class ViewModelBase : INotifyPropertyChanged + { + public event PropertyChangedEventHandler PropertyChanged; + protected bool RaiseAndSetIfChanged(ref T field, T value, [CallerMemberName] string propertyName = null) + { + if (!EqualityComparer.Default.Equals(field, value)) + { + field = value; + RaisePropertyChanged(propertyName); + return true; + } + return false; + } + + + protected void RaisePropertyChanged([CallerMemberName] string propertyName = null) + => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } +} diff --git a/samples/Previewer/Previewer.csproj b/samples/Previewer/Previewer.csproj index cd3daf61e1..cfedb7ad9e 100644 --- a/samples/Previewer/Previewer.csproj +++ b/samples/Previewer/Previewer.csproj @@ -8,7 +8,6 @@ %(Filename) - diff --git a/samples/RenderDemo/App.xaml b/samples/RenderDemo/App.xaml index 61e4d2385b..7cdcea2e1d 100644 --- a/samples/RenderDemo/App.xaml +++ b/samples/RenderDemo/App.xaml @@ -3,7 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="RenderDemo.App"> - + diff --git a/samples/RenderDemo/App.xaml.cs b/samples/RenderDemo/App.xaml.cs index 2247fd7c5a..8054b06964 100644 --- a/samples/RenderDemo/App.xaml.cs +++ b/samples/RenderDemo/App.xaml.cs @@ -1,7 +1,6 @@ using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; -using Avalonia.ReactiveUI; namespace RenderDemo { @@ -32,7 +31,6 @@ namespace RenderDemo OverlayPopups = true, }) .UsePlatformDetect() - .UseReactiveUI() - .LogToDebug(); + .LogToTrace(); } } diff --git a/samples/RenderDemo/MainWindow.xaml.cs b/samples/RenderDemo/MainWindow.xaml.cs index b45a605e04..877eb8016a 100644 --- a/samples/RenderDemo/MainWindow.xaml.cs +++ b/samples/RenderDemo/MainWindow.xaml.cs @@ -3,7 +3,7 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; using RenderDemo.ViewModels; -using ReactiveUI; +using MiniMvvm; namespace RenderDemo { diff --git a/samples/RenderDemo/RenderDemo.csproj b/samples/RenderDemo/RenderDemo.csproj index d1654f4b54..0d33b4c111 100644 --- a/samples/RenderDemo/RenderDemo.csproj +++ b/samples/RenderDemo/RenderDemo.csproj @@ -9,12 +9,11 @@ - + - diff --git a/samples/RenderDemo/ViewModels/AnimationsPageViewModel.cs b/samples/RenderDemo/ViewModels/AnimationsPageViewModel.cs index 7b89b7944c..f8ba01f3d1 100644 --- a/samples/RenderDemo/ViewModels/AnimationsPageViewModel.cs +++ b/samples/RenderDemo/ViewModels/AnimationsPageViewModel.cs @@ -1,10 +1,10 @@ using System; -using ReactiveUI; +using MiniMvvm; using Avalonia.Animation; namespace RenderDemo.ViewModels { - public class AnimationsPageViewModel : ReactiveObject + public class AnimationsPageViewModel : ViewModelBase { private bool _isPlaying = true; diff --git a/samples/RenderDemo/ViewModels/MainWindowViewModel.cs b/samples/RenderDemo/ViewModels/MainWindowViewModel.cs index eda5e80530..19917c20df 100644 --- a/samples/RenderDemo/ViewModels/MainWindowViewModel.cs +++ b/samples/RenderDemo/ViewModels/MainWindowViewModel.cs @@ -1,11 +1,10 @@ using System.Reactive; using System.Threading.Tasks; - -using ReactiveUI; +using MiniMvvm; namespace RenderDemo.ViewModels { - public class MainWindowViewModel : ReactiveObject + public class MainWindowViewModel : ViewModelBase { private bool drawDirtyRects = false; private bool drawFps = true; @@ -14,9 +13,9 @@ namespace RenderDemo.ViewModels public MainWindowViewModel() { - ToggleDrawDirtyRects = ReactiveCommand.Create(() => DrawDirtyRects = !DrawDirtyRects); - ToggleDrawFps = ReactiveCommand.Create(() => DrawFps = !DrawFps); - ResizeWindow = ReactiveCommand.CreateFromTask(ResizeWindowAsync); + ToggleDrawDirtyRects = MiniCommand.Create(() => DrawDirtyRects = !DrawDirtyRects); + ToggleDrawFps = MiniCommand.Create(() => DrawFps = !DrawFps); + ResizeWindow = MiniCommand.CreateFromTask(ResizeWindowAsync); } public bool DrawDirtyRects @@ -43,9 +42,9 @@ namespace RenderDemo.ViewModels set => this.RaiseAndSetIfChanged(ref height, value); } - public ReactiveCommand ToggleDrawDirtyRects { get; } - public ReactiveCommand ToggleDrawFps { get; } - public ReactiveCommand ResizeWindow { get; } + public MiniCommand ToggleDrawDirtyRects { get; } + public MiniCommand ToggleDrawFps { get; } + public MiniCommand ResizeWindow { get; } private async Task ResizeWindowAsync() { diff --git a/samples/Sandbox/App.axaml b/samples/Sandbox/App.axaml index 699781eb94..f601f9f78f 100644 --- a/samples/Sandbox/App.axaml +++ b/samples/Sandbox/App.axaml @@ -3,6 +3,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="Sandbox.App"> - + diff --git a/samples/Sandbox/MainWindow.axaml.cs b/samples/Sandbox/MainWindow.axaml.cs index b7222e043d..3d54036d29 100644 --- a/samples/Sandbox/MainWindow.axaml.cs +++ b/samples/Sandbox/MainWindow.axaml.cs @@ -1,6 +1,7 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; +using Avalonia.Win32.WinRT.Composition; namespace Sandbox { diff --git a/samples/Sandbox/Program.cs b/samples/Sandbox/Program.cs index 4d7eda8d9f..1e74105196 100644 --- a/samples/Sandbox/Program.cs +++ b/samples/Sandbox/Program.cs @@ -1,5 +1,4 @@ using Avalonia; -using Avalonia.ReactiveUI; namespace Sandbox { @@ -9,8 +8,7 @@ namespace Sandbox { AppBuilder.Configure() .UsePlatformDetect() - .UseReactiveUI() - .LogToDebug() + .LogToTrace() .StartWithClassicDesktopLifetime(args); } } diff --git a/samples/Sandbox/Sandbox.csproj b/samples/Sandbox/Sandbox.csproj index 1a0a8a7ce5..0c19440a1e 100644 --- a/samples/Sandbox/Sandbox.csproj +++ b/samples/Sandbox/Sandbox.csproj @@ -8,7 +8,6 @@ - diff --git a/samples/VirtualizationDemo/Program.cs b/samples/VirtualizationDemo/Program.cs index c23bfd7ad9..febda46450 100644 --- a/samples/VirtualizationDemo/Program.cs +++ b/samples/VirtualizationDemo/Program.cs @@ -1,5 +1,4 @@ using Avalonia; -using Avalonia.ReactiveUI; namespace VirtualizationDemo { @@ -8,8 +7,7 @@ namespace VirtualizationDemo public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure() .UsePlatformDetect() - .UseReactiveUI() - .LogToDebug(); + .LogToTrace(); public static int Main(string[] args) => BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); diff --git a/samples/VirtualizationDemo/ViewModels/ItemViewModel.cs b/samples/VirtualizationDemo/ViewModels/ItemViewModel.cs index cf34980b40..9ba505ffe5 100644 --- a/samples/VirtualizationDemo/ViewModels/ItemViewModel.cs +++ b/samples/VirtualizationDemo/ViewModels/ItemViewModel.cs @@ -1,9 +1,9 @@ using System; -using ReactiveUI; +using MiniMvvm; namespace VirtualizationDemo.ViewModels { - internal class ItemViewModel : ReactiveObject + internal class ItemViewModel : ViewModelBase { private string _prefix; private int _index; diff --git a/samples/VirtualizationDemo/ViewModels/MainWindowViewModel.cs b/samples/VirtualizationDemo/ViewModels/MainWindowViewModel.cs index 852c01399f..514df691ae 100644 --- a/samples/VirtualizationDemo/ViewModels/MainWindowViewModel.cs +++ b/samples/VirtualizationDemo/ViewModels/MainWindowViewModel.cs @@ -5,13 +5,13 @@ using System.Reactive; using Avalonia.Collections; using Avalonia.Controls; using Avalonia.Controls.Primitives; -using ReactiveUI; using Avalonia.Layout; using Avalonia.Controls.Selection; +using MiniMvvm; namespace VirtualizationDemo.ViewModels { - internal class MainWindowViewModel : ReactiveObject + internal class MainWindowViewModel : ViewModelBase { private int _itemCount = 200; private string _newItemString = "New Item"; @@ -26,15 +26,15 @@ namespace VirtualizationDemo.ViewModels public MainWindowViewModel() { this.WhenAnyValue(x => x.ItemCount).Subscribe(ResizeItems); - RecreateCommand = ReactiveCommand.Create(() => Recreate()); + RecreateCommand = MiniCommand.Create(() => Recreate()); - AddItemCommand = ReactiveCommand.Create(() => AddItem()); + AddItemCommand = MiniCommand.Create(() => AddItem()); - RemoveItemCommand = ReactiveCommand.Create(() => Remove()); + RemoveItemCommand = MiniCommand.Create(() => Remove()); - SelectFirstCommand = ReactiveCommand.Create(() => SelectItem(0)); + SelectFirstCommand = MiniCommand.Create(() => SelectItem(0)); - SelectLastCommand = ReactiveCommand.Create(() => SelectItem(Items.Count - 1)); + SelectLastCommand = MiniCommand.Create(() => SelectItem(Items.Count - 1)); } public string NewItemString @@ -90,11 +90,11 @@ namespace VirtualizationDemo.ViewModels public IEnumerable VirtualizationModes => Enum.GetValues(typeof(ItemVirtualizationMode)).Cast(); - public ReactiveCommand AddItemCommand { get; private set; } - public ReactiveCommand RecreateCommand { get; private set; } - public ReactiveCommand RemoveItemCommand { get; private set; } - public ReactiveCommand SelectFirstCommand { get; private set; } - public ReactiveCommand SelectLastCommand { get; private set; } + public MiniCommand AddItemCommand { get; private set; } + public MiniCommand RecreateCommand { get; private set; } + public MiniCommand RemoveItemCommand { get; private set; } + public MiniCommand SelectFirstCommand { get; private set; } + public MiniCommand SelectLastCommand { get; private set; } public void RandomizeSize() { diff --git a/samples/VirtualizationDemo/VirtualizationDemo.csproj b/samples/VirtualizationDemo/VirtualizationDemo.csproj index 817023fd71..d898b737a9 100644 --- a/samples/VirtualizationDemo/VirtualizationDemo.csproj +++ b/samples/VirtualizationDemo/VirtualizationDemo.csproj @@ -6,12 +6,11 @@ - + - diff --git a/samples/interop/Direct3DInteropSample/Direct3DInteropSample.csproj b/samples/interop/Direct3DInteropSample/Direct3DInteropSample.csproj index bd6b6f170f..cd9963a2e5 100644 --- a/samples/interop/Direct3DInteropSample/Direct3DInteropSample.csproj +++ b/samples/interop/Direct3DInteropSample/Direct3DInteropSample.csproj @@ -22,9 +22,9 @@ - + diff --git a/samples/interop/Direct3DInteropSample/MainWindowViewModel.cs b/samples/interop/Direct3DInteropSample/MainWindowViewModel.cs index d39a21cd07..21679a99c5 100644 --- a/samples/interop/Direct3DInteropSample/MainWindowViewModel.cs +++ b/samples/interop/Direct3DInteropSample/MainWindowViewModel.cs @@ -3,11 +3,11 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using ReactiveUI; +using MiniMvvm; namespace Direct3DInteropSample { - public class MainWindowViewModel : ReactiveObject + public class MainWindowViewModel : ViewModelBase { private double _rotationX; diff --git a/samples/interop/NativeEmbedSample/NativeEmbedSample.csproj b/samples/interop/NativeEmbedSample/NativeEmbedSample.csproj index 0e0e71fbb2..c25442b52c 100644 --- a/samples/interop/NativeEmbedSample/NativeEmbedSample.csproj +++ b/samples/interop/NativeEmbedSample/NativeEmbedSample.csproj @@ -12,7 +12,7 @@ - + Designer diff --git a/samples/interop/WindowsInteropTest/WindowsInteropTest.csproj b/samples/interop/WindowsInteropTest/WindowsInteropTest.csproj index c067d38595..8394d7cb13 100644 --- a/samples/interop/WindowsInteropTest/WindowsInteropTest.csproj +++ b/samples/interop/WindowsInteropTest/WindowsInteropTest.csproj @@ -136,10 +136,6 @@ {42472427-4774-4c81-8aff-9f27b8e31721} Avalonia.Layout - - {6417b24e-49c2-4985-8db2-3ab9d898ec91} - Avalonia.ReactiveUI - {eb582467-6abb-43a1-b052-e981ba910e3a} Avalonia.Visuals @@ -190,4 +186,4 @@ - \ No newline at end of file + diff --git a/src/Android/Avalonia.Android/Platform/ClipboardImpl.cs b/src/Android/Avalonia.Android/Platform/ClipboardImpl.cs index 7802f336fb..d1a116345b 100644 --- a/src/Android/Avalonia.Android/Platform/ClipboardImpl.cs +++ b/src/Android/Avalonia.Android/Platform/ClipboardImpl.cs @@ -1,7 +1,11 @@ +using System; using System.Threading.Tasks; + using Android.Content; using Android.Runtime; using Android.Views; + +using Avalonia.Input; using Avalonia.Input.Platform; using Avalonia.Platform; diff --git a/src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs b/src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs index 71dce93ce7..360e76b2dc 100644 --- a/src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs +++ b/src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs @@ -6,6 +6,7 @@ using Android.Views; using Avalonia.Android.Platform.Input; using Avalonia.Android.Platform.Specific; using Avalonia.Android.Platform.Specific.Helpers; +using Avalonia.Controls; using Avalonia.Controls.Platform.Surfaces; using Avalonia.Input; using Avalonia.Input.Raw; @@ -196,7 +197,17 @@ namespace Avalonia.Android.Platform.SkiaPlatform public IPopupImpl CreatePopup() => null; public Action LostFocus { get; set; } + public Action TransparencyLevelChanged { get; set; } - ILockedFramebuffer IFramebufferPlatformSurface.Lock()=>new AndroidFramebuffer(_view.Holder.Surface); + public WindowTransparencyLevel TransparencyLevel => WindowTransparencyLevel.None; + + public AcrylicPlatformCompensationLevels AcrylicCompensationLevels => new AcrylicPlatformCompensationLevels(1, 1, 1); + + ILockedFramebuffer IFramebufferPlatformSurface.Lock() => new AndroidFramebuffer(_view.Holder.Surface); + + public void SetTransparencyLevelHint(WindowTransparencyLevel transparencyLevel) + { + throw new NotImplementedException(); + } } } diff --git a/src/Android/Avalonia.Android/Platform/Specific/Helpers/AndroidKeyboardEventsHelper.cs b/src/Android/Avalonia.Android/Platform/Specific/Helpers/AndroidKeyboardEventsHelper.cs index 1179ce9235..426b221738 100644 --- a/src/Android/Avalonia.Android/Platform/Specific/Helpers/AndroidKeyboardEventsHelper.cs +++ b/src/Android/Avalonia.Android/Platform/Specific/Helpers/AndroidKeyboardEventsHelper.cs @@ -5,14 +5,14 @@ using Android.Runtime; using Android.Views; using Android.Views.InputMethods; using Avalonia.Android.Platform.Input; +using Avalonia.Android.Platform.SkiaPlatform; using Avalonia.Controls; using Avalonia.Input; using Avalonia.Input.Raw; -using Avalonia.Platform; namespace Avalonia.Android.Platform.Specific.Helpers { - public class AndroidKeyboardEventsHelper : IDisposable where TView :ITopLevelImpl, IAndroidView + internal class AndroidKeyboardEventsHelper : IDisposable where TView : TopLevelImpl, IAndroidView { private TView _view; private IInputElement _lastFocusedElement; @@ -46,9 +46,11 @@ namespace Avalonia.Android.Platform.Specific.Helpers var rawKeyEvent = new RawKeyEventArgs( AndroidKeyboardDevice.Instance, - Convert.ToUInt32(e.EventTime), + Convert.ToUInt64(e.EventTime), + _view.InputRoot, e.Action == KeyEventActions.Down ? RawKeyEventType.KeyDown : RawKeyEventType.KeyUp, - AndroidKeyboardDevice.ConvertKey(e.KeyCode), GetModifierKeys(e)); + AndroidKeyboardDevice.ConvertKey(e.KeyCode), GetModifierKeys(e)); + _view.Input(rawKeyEvent); if (e.Action == KeyEventActions.Down && e.UnicodeChar >= 32) @@ -56,6 +58,7 @@ namespace Avalonia.Android.Platform.Specific.Helpers var rawTextEvent = new RawTextInputEventArgs( AndroidKeyboardDevice.Instance, Convert.ToUInt32(e.EventTime), + _view.InputRoot, Convert.ToChar(e.UnicodeChar).ToString() ); _view.Input(rawTextEvent); diff --git a/src/Android/Avalonia.Android/Resources/Resource.Designer.cs b/src/Android/Avalonia.Android/Resources/Resource.Designer.cs deleted file mode 100644 index 80cbbc51ec..0000000000 --- a/src/Android/Avalonia.Android/Resources/Resource.Designer.cs +++ /dev/null @@ -1,60 +0,0 @@ -#pragma warning disable 1591 -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -[assembly: global::Android.Runtime.ResourceDesignerAttribute("Avalonia.Android.Resource", IsApplication=false)] - -namespace Avalonia.Android -{ - - - [System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")] - public partial class Resource - { - - static Resource() - { - global::Android.Runtime.ResourceIdManager.UpdateIdValues(); - } - - public partial class Attribute - { - - static Attribute() - { - global::Android.Runtime.ResourceIdManager.UpdateIdValues(); - } - - private Attribute() - { - } - } - - public partial class String - { - - // aapt resource value: 0x7f020001 - public static int ApplicationName = 2130837505; - - // aapt resource value: 0x7f020000 - public static int Hello = 2130837504; - - static String() - { - global::Android.Runtime.ResourceIdManager.UpdateIdValues(); - } - - private String() - { - } - } - } -} -#pragma warning restore 1591 diff --git a/src/Android/Avalonia.Android/SystemDialogImpl.cs b/src/Android/Avalonia.Android/SystemDialogImpl.cs index a8d201d66e..1ed1f688b1 100644 --- a/src/Android/Avalonia.Android/SystemDialogImpl.cs +++ b/src/Android/Avalonia.Android/SystemDialogImpl.cs @@ -2,18 +2,17 @@ using System; using System.Threading.Tasks; using Avalonia.Controls; using Avalonia.Controls.Platform; -using Avalonia.Platform; namespace Avalonia.Android { internal class SystemDialogImpl : ISystemDialogImpl { - public Task ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent) + public Task ShowFileDialogAsync(FileDialog dialog, Window parent) { throw new NotImplementedException(); } - public Task ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent) + public Task ShowFolderDialogAsync(OpenFolderDialog dialog, Window parent) { throw new NotImplementedException(); } diff --git a/src/Android/Avalonia.AndroidTestApplication/Avalonia.AndroidTestApplication.csproj b/src/Android/Avalonia.AndroidTestApplication/Avalonia.AndroidTestApplication.csproj index b8697e0ca2..4f49f3a863 100644 --- a/src/Android/Avalonia.AndroidTestApplication/Avalonia.AndroidTestApplication.csproj +++ b/src/Android/Avalonia.AndroidTestApplication/Avalonia.AndroidTestApplication.csproj @@ -16,7 +16,7 @@ Resources\Resource.Designer.cs Off False - v9.0 + v10.0 Properties\AndroidManifest.xml @@ -127,10 +127,6 @@ {42472427-4774-4c81-8aff-9f27b8e31721} Avalonia.Layout - - {6417b24e-49c2-4985-8db2-3ab9d898ec91} - Avalonia.ReactiveUI - {eb582467-6abb-43a1-b052-e981ba910e3a} Avalonia.Visuals @@ -154,4 +150,4 @@ - + \ No newline at end of file diff --git a/src/Android/Avalonia.AndroidTestApplication/MainActivity.cs b/src/Android/Avalonia.AndroidTestApplication/MainActivity.cs index ad2cec2ae3..121acb6351 100644 --- a/src/Android/Avalonia.AndroidTestApplication/MainActivity.cs +++ b/src/Android/Avalonia.AndroidTestApplication/MainActivity.cs @@ -4,7 +4,6 @@ using Android.Content.PM; using Android.OS; using Avalonia.Android; using Avalonia.Controls; -using Avalonia.Controls.Templates; using Avalonia.Markup.Xaml; using Avalonia.Media; using Avalonia.Styling; @@ -38,8 +37,7 @@ namespace Avalonia.AndroidTestApplication { Styles.Add(new DefaultTheme()); - var loader = new AvaloniaXamlLoader(); - var baseLight = (IStyle)loader.Load( + var baseLight = (IStyle)AvaloniaXamlLoader.Load( new Uri("resm:Avalonia.Themes.Default.Accents.BaseLight.xaml?assembly=Avalonia.Themes.Default")); Styles.Add(baseLight); diff --git a/src/Android/Avalonia.AndroidTestApplication/Properties/AndroidManifest.xml b/src/Android/Avalonia.AndroidTestApplication/Properties/AndroidManifest.xml index 4792c8a1ec..e8e81da9de 100644 --- a/src/Android/Avalonia.AndroidTestApplication/Properties/AndroidManifest.xml +++ b/src/Android/Avalonia.AndroidTestApplication/Properties/AndroidManifest.xml @@ -1,6 +1,6 @@  - + \ No newline at end of file diff --git a/src/Android/Avalonia.AndroidTestApplication/Resources/Resource.Designer.cs b/src/Android/Avalonia.AndroidTestApplication/Resources/Resource.Designer.cs index e171dd6162..83db67fcee 100644 --- a/src/Android/Avalonia.AndroidTestApplication/Resources/Resource.Designer.cs +++ b/src/Android/Avalonia.AndroidTestApplication/Resources/Resource.Designer.cs @@ -2,7 +2,6 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -15,7 +14,7 @@ namespace Avalonia.AndroidTestApplication { - [System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")] public partial class Resource { @@ -26,8 +25,6 @@ namespace Avalonia.AndroidTestApplication public static void UpdateIdValues() { - global::Avalonia.Android.Resource.String.ApplicationName = global::Avalonia.AndroidTestApplication.Resource.String.ApplicationName; - global::Avalonia.Android.Resource.String.Hello = global::Avalonia.AndroidTestApplication.Resource.String.Hello; } public partial class Attribute @@ -46,8 +43,8 @@ namespace Avalonia.AndroidTestApplication public partial class Drawable { - // aapt resource value: 0x7f020000 - public const int Icon = 2130837504; + // aapt resource value: 0x7F010000 + public const int Icon = 2130771968; static Drawable() { @@ -62,11 +59,11 @@ namespace Avalonia.AndroidTestApplication public partial class String { - // aapt resource value: 0x7f030001 - public const int ApplicationName = 2130903041; + // aapt resource value: 0x7F020000 + public const int ApplicationName = 2130837504; - // aapt resource value: 0x7f030000 - public const int Hello = 2130903040; + // aapt resource value: 0x7F020001 + public const int Hello = 2130837505; static String() { diff --git a/src/Avalonia.Animation/Properties/AssemblyInfo.cs b/src/Avalonia.Animation/Properties/AssemblyInfo.cs index de0b4a9971..221b51e95a 100644 --- a/src/Avalonia.Animation/Properties/AssemblyInfo.cs +++ b/src/Avalonia.Animation/Properties/AssemblyInfo.cs @@ -6,5 +6,10 @@ using System.Runtime.CompilerServices; [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Animation.Easings")] [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Animation.Animators")] +#if SIGNED_BUILD [assembly: InternalsVisibleTo("Avalonia.LeakTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] [assembly: InternalsVisibleTo("Avalonia.Animation.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] +#else +[assembly: InternalsVisibleTo("Avalonia.LeakTests")] +[assembly: InternalsVisibleTo("Avalonia.Animation.UnitTests")] +#endif diff --git a/src/Avalonia.Base/ApiCompatBaseline.txt b/src/Avalonia.Base/ApiCompatBaseline.txt deleted file mode 100644 index 4668a572c5..0000000000 --- a/src/Avalonia.Base/ApiCompatBaseline.txt +++ /dev/null @@ -1,3 +0,0 @@ -Compat issues with assembly Avalonia.Base: -CannotAddAbstractMembers : Member 'protected System.IObservable Avalonia.AvaloniaProperty.GetChanged()' is abstract in the implementation but is missing in the contract. -Total Issues: 1 diff --git a/src/Avalonia.Base/Avalonia.Base.csproj b/src/Avalonia.Base/Avalonia.Base.csproj index 9bfd387ca9..0470dbfe89 100644 --- a/src/Avalonia.Base/Avalonia.Base.csproj +++ b/src/Avalonia.Base/Avalonia.Base.csproj @@ -5,9 +5,6 @@ Avalonia True - - - diff --git a/src/Avalonia.Base/AvaloniaProperty.cs b/src/Avalonia.Base/AvaloniaProperty.cs index 3ae0445e9b..5117fdb170 100644 --- a/src/Avalonia.Base/AvaloniaProperty.cs +++ b/src/Avalonia.Base/AvaloniaProperty.cs @@ -17,9 +17,9 @@ namespace Avalonia public static readonly object UnsetValue = new UnsetValueType(); private static int s_nextId; - private readonly PropertyMetadata _defaultMetadata; - private readonly Dictionary _metadata; - private readonly Dictionary _metadataCache = new Dictionary(); + private readonly AvaloniaPropertyMetadata _defaultMetadata; + private readonly Dictionary _metadata; + private readonly Dictionary _metadataCache = new Dictionary(); private bool _hasMetadataOverrides; @@ -35,7 +35,7 @@ namespace Avalonia string name, Type valueType, Type ownerType, - PropertyMetadata metadata, + AvaloniaPropertyMetadata metadata, Action notifying = null) { Contract.Requires(name != null); @@ -48,7 +48,7 @@ namespace Avalonia throw new ArgumentException("'name' may not contain periods."); } - _metadata = new Dictionary(); + _metadata = new Dictionary(); Name = name; PropertyType = valueType; @@ -69,12 +69,12 @@ namespace Avalonia protected AvaloniaProperty( AvaloniaProperty source, Type ownerType, - PropertyMetadata metadata) + AvaloniaPropertyMetadata metadata) { Contract.Requires(source != null); Contract.Requires(ownerType != null); - _metadata = new Dictionary(); + _metadata = new Dictionary(); Name = source.Name; PropertyType = source.PropertyType; @@ -419,7 +419,7 @@ namespace Avalonia /// /// The property metadata. /// - public PropertyMetadata GetMetadata() where T : IAvaloniaObject + public AvaloniaPropertyMetadata GetMetadata() where T : IAvaloniaObject { return GetMetadata(typeof(T)); } @@ -432,7 +432,7 @@ namespace Avalonia /// The property metadata. /// /// - public PropertyMetadata GetMetadata(Type type) + public AvaloniaPropertyMetadata GetMetadata(Type type) { if (!_hasMetadataOverrides) { @@ -521,7 +521,7 @@ namespace Avalonia /// /// The type. /// The metadata. - protected void OverrideMetadata(Type type, PropertyMetadata metadata) + protected void OverrideMetadata(Type type, AvaloniaPropertyMetadata metadata) { Contract.Requires(type != null); Contract.Requires(metadata != null); @@ -542,14 +542,14 @@ namespace Avalonia protected abstract IObservable GetChanged(); - private PropertyMetadata GetMetadataWithOverrides(Type type) + private AvaloniaPropertyMetadata GetMetadataWithOverrides(Type type) { if (type is null) { throw new ArgumentNullException(nameof(type)); } - if (_metadataCache.TryGetValue(type, out PropertyMetadata result)) + if (_metadataCache.TryGetValue(type, out AvaloniaPropertyMetadata result)) { return result; } diff --git a/src/Avalonia.Base/PropertyMetadata.cs b/src/Avalonia.Base/AvaloniaPropertyMetadata.cs similarity index 85% rename from src/Avalonia.Base/PropertyMetadata.cs rename to src/Avalonia.Base/AvaloniaPropertyMetadata.cs index 806051e1d1..2963567b14 100644 --- a/src/Avalonia.Base/PropertyMetadata.cs +++ b/src/Avalonia.Base/AvaloniaPropertyMetadata.cs @@ -5,15 +5,15 @@ namespace Avalonia /// /// Base class for avalonia property metadata. /// - public class PropertyMetadata + public class AvaloniaPropertyMetadata { private BindingMode _defaultBindingMode; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The default binding mode. - public PropertyMetadata( + public AvaloniaPropertyMetadata( BindingMode defaultBindingMode = BindingMode.Default) { _defaultBindingMode = defaultBindingMode; @@ -37,7 +37,7 @@ namespace Avalonia /// The base metadata to merge. /// The property to which the metadata is being applied. public virtual void Merge( - PropertyMetadata baseMetadata, + AvaloniaPropertyMetadata baseMetadata, AvaloniaProperty property) { if (_defaultBindingMode == BindingMode.Default) diff --git a/src/Avalonia.Base/AvaloniaProperty`1.cs b/src/Avalonia.Base/AvaloniaProperty`1.cs index d5549e979b..247ea0a25a 100644 --- a/src/Avalonia.Base/AvaloniaProperty`1.cs +++ b/src/Avalonia.Base/AvaloniaProperty`1.cs @@ -23,7 +23,7 @@ namespace Avalonia protected AvaloniaProperty( string name, Type ownerType, - PropertyMetadata metadata, + AvaloniaPropertyMetadata metadata, Action notifying = null) : base(name, typeof(TValue), ownerType, metadata, notifying) { @@ -40,7 +40,7 @@ namespace Avalonia protected AvaloniaProperty( AvaloniaProperty source, Type ownerType, - PropertyMetadata metadata) + AvaloniaPropertyMetadata metadata) : this(source as AvaloniaProperty ?? throw new InvalidOperationException(), ownerType, metadata) { } @@ -54,7 +54,7 @@ namespace Avalonia protected AvaloniaProperty( AvaloniaProperty source, Type ownerType, - PropertyMetadata metadata) + AvaloniaPropertyMetadata metadata) : base(source, ownerType, metadata) { _changed = source._changed; diff --git a/src/Avalonia.Base/Collections/AvaloniaList.cs b/src/Avalonia.Base/Collections/AvaloniaList.cs index d43b4e04bb..5681214222 100644 --- a/src/Avalonia.Base/Collections/AvaloniaList.cs +++ b/src/Avalonia.Base/Collections/AvaloniaList.cs @@ -63,6 +63,15 @@ namespace Avalonia.Collections _inner = new List(); } + /// + /// Initializes a new instance of the . + /// + /// Initial list capacity. + public AvaloniaList(int capacity) + { + _inner = new List(capacity); + } + /// /// Initializes a new instance of the class. /// @@ -175,6 +184,15 @@ namespace Avalonia.Collections set { this[index] = (T)value; } } + /// + /// Gets or sets the total number of elements the internal data structure can hold without resizing. + /// + public int Capacity + { + get => _inner.Capacity; + set => _inner.Capacity = value; + } + /// /// Adds an item to the collection. /// diff --git a/src/Avalonia.Base/Data/Core/Plugins/InpcPropertyAccessorPlugin.cs b/src/Avalonia.Base/Data/Core/Plugins/InpcPropertyAccessorPlugin.cs index 3bf6842cd6..d600603d5c 100644 --- a/src/Avalonia.Base/Data/Core/Plugins/InpcPropertyAccessorPlugin.cs +++ b/src/Avalonia.Base/Data/Core/Plugins/InpcPropertyAccessorPlugin.cs @@ -14,7 +14,7 @@ namespace Avalonia.Data.Core.Plugins { private readonly Dictionary<(Type, string), PropertyInfo> _propertyLookup = new Dictionary<(Type, string), PropertyInfo>(); - + /// public bool Match(object obj, string propertyName) => GetFirstPropertyWithName(obj.GetType(), propertyName) != null; @@ -51,7 +51,7 @@ namespace Avalonia.Data.Core.Plugins private PropertyInfo GetFirstPropertyWithName(Type type, string propertyName) { var key = (type, propertyName); - + if (!_propertyLookup.TryGetValue(key, out PropertyInfo propertyInfo)) { propertyInfo = TryFindAndCacheProperty(type, propertyName); @@ -59,7 +59,7 @@ namespace Avalonia.Data.Core.Plugins return propertyInfo; } - + private PropertyInfo TryFindAndCacheProperty(Type type, string propertyName) { PropertyInfo found = null; @@ -90,7 +90,7 @@ namespace Avalonia.Data.Core.Plugins private readonly PropertyInfo _property; private bool _eventRaised; - public Accessor(WeakReference reference, PropertyInfo property) + public Accessor(WeakReference reference, PropertyInfo property) { Contract.Requires(reference != null); Contract.Requires(property != null); diff --git a/src/Avalonia.Base/Data/Core/SettableNode.cs b/src/Avalonia.Base/Data/Core/SettableNode.cs index d0a918dc88..363d3da0ef 100644 --- a/src/Avalonia.Base/Data/Core/SettableNode.cs +++ b/src/Avalonia.Base/Data/Core/SettableNode.cs @@ -15,7 +15,8 @@ namespace Avalonia.Data.Core private bool ShouldNotSet(object value) { - if (PropertyType == null) + var propertyType = PropertyType; + if (propertyType == null) { return false; } @@ -37,7 +38,7 @@ namespace Avalonia.Data.Core return false; } - if (PropertyType.IsValueType) + if (propertyType.IsValueType) { return lastValue.Equals(value); } diff --git a/src/Avalonia.Base/Data/Core/TypeCastNode.cs b/src/Avalonia.Base/Data/Core/TypeCastNode.cs new file mode 100644 index 0000000000..476fd5527f --- /dev/null +++ b/src/Avalonia.Base/Data/Core/TypeCastNode.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Avalonia.Data.Core +{ + public class TypeCastNode : ExpressionNode + { + public override string Description => $"as {TargetType.FullName}"; + + public Type TargetType { get; } + + public TypeCastNode(Type type) + { + TargetType = type; + } + + protected virtual object Cast(object value) + { + return TargetType.IsInstanceOfType(value) ? value : null; + } + + protected override void StartListeningCore(WeakReference reference) + { + if (reference.TryGetTarget(out object target)) + { + target = Cast(target); + reference = target == null ? NullReference : new WeakReference(target); + } + + base.StartListeningCore(reference); + } + } +} diff --git a/src/Avalonia.Base/DirectPropertyBase.cs b/src/Avalonia.Base/DirectPropertyBase.cs index a2f113adb7..e6cc1edfdf 100644 --- a/src/Avalonia.Base/DirectPropertyBase.cs +++ b/src/Avalonia.Base/DirectPropertyBase.cs @@ -26,7 +26,7 @@ namespace Avalonia protected DirectPropertyBase( string name, Type ownerType, - PropertyMetadata metadata) + AvaloniaPropertyMetadata metadata) : base(name, ownerType, metadata) { } @@ -41,7 +41,7 @@ namespace Avalonia protected DirectPropertyBase( AvaloniaProperty source, Type ownerType, - PropertyMetadata metadata) + AvaloniaPropertyMetadata metadata) : this(source as DirectPropertyBase ?? throw new InvalidOperationException(), ownerType, metadata) { } @@ -55,7 +55,7 @@ namespace Avalonia protected DirectPropertyBase( DirectPropertyBase source, Type ownerType, - PropertyMetadata metadata) + AvaloniaPropertyMetadata metadata) : base(source, ownerType, metadata) { } diff --git a/src/Avalonia.Base/DirectPropertyMetadata`1.cs b/src/Avalonia.Base/DirectPropertyMetadata`1.cs index 59a60507dc..205967984d 100644 --- a/src/Avalonia.Base/DirectPropertyMetadata`1.cs +++ b/src/Avalonia.Base/DirectPropertyMetadata`1.cs @@ -5,7 +5,7 @@ namespace Avalonia /// /// Metadata for direct avalonia properties. /// - public class DirectPropertyMetadata : PropertyMetadata, IDirectPropertyMetadata + public class DirectPropertyMetadata : AvaloniaPropertyMetadata, IDirectPropertyMetadata { /// /// Initializes a new instance of the class. @@ -47,7 +47,7 @@ namespace Avalonia object IDirectPropertyMetadata.UnsetValue => UnsetValue; /// - public override void Merge(PropertyMetadata baseMetadata, AvaloniaProperty property) + public override void Merge(AvaloniaPropertyMetadata baseMetadata, AvaloniaProperty property) { base.Merge(baseMetadata, property); diff --git a/src/Avalonia.Base/Logging/LogArea.cs b/src/Avalonia.Base/Logging/LogArea.cs index 3c19b47a05..2ad220dddd 100644 --- a/src/Avalonia.Base/Logging/LogArea.cs +++ b/src/Avalonia.Base/Logging/LogArea.cs @@ -34,5 +34,10 @@ namespace Avalonia.Logging /// The log event comes from the control system. /// public const string Control = "Control"; + + /// + /// The log event comes from Win32Platform. + /// + public const string Win32Platform = nameof(Win32Platform); } } diff --git a/src/Avalonia.Base/Logging/DebugLogSink.cs b/src/Avalonia.Base/Logging/TraceLogSink.cs similarity index 92% rename from src/Avalonia.Base/Logging/DebugLogSink.cs rename to src/Avalonia.Base/Logging/TraceLogSink.cs index 3695afa860..f597844378 100644 --- a/src/Avalonia.Base/Logging/DebugLogSink.cs +++ b/src/Avalonia.Base/Logging/TraceLogSink.cs @@ -6,12 +6,12 @@ using Avalonia.Utilities; namespace Avalonia.Logging { - public class DebugLogSink : ILogSink + public class TraceLogSink : ILogSink { private readonly LogEventLevel _level; private readonly IList _areas; - public DebugLogSink( + public TraceLogSink( LogEventLevel minimumLevel, IList areas = null) { @@ -28,7 +28,7 @@ namespace Avalonia.Logging { if (IsEnabled(level, area)) { - Debug.WriteLine(Format(area, messageTemplate, source)); + Trace.WriteLine(Format(area, messageTemplate, source)); } } @@ -36,7 +36,7 @@ namespace Avalonia.Logging { if (IsEnabled(level, area)) { - Debug.WriteLine(Format(area, messageTemplate, source, propertyValue0)); + Trace.WriteLine(Format(area, messageTemplate, source, propertyValue0)); } } @@ -44,7 +44,7 @@ namespace Avalonia.Logging { if (IsEnabled(level, area)) { - Debug.WriteLine(Format(area, messageTemplate, source, propertyValue0, propertyValue1)); + Trace.WriteLine(Format(area, messageTemplate, source, propertyValue0, propertyValue1)); } } @@ -52,7 +52,7 @@ namespace Avalonia.Logging { if (IsEnabled(level, area)) { - Debug.WriteLine(Format(area, messageTemplate, source, propertyValue0, propertyValue1, propertyValue2)); + Trace.WriteLine(Format(area, messageTemplate, source, propertyValue0, propertyValue1, propertyValue2)); } } @@ -60,7 +60,7 @@ namespace Avalonia.Logging { if (IsEnabled(level, area)) { - Debug.WriteLine(Format(area, messageTemplate, source, propertyValues)); + Trace.WriteLine(Format(area, messageTemplate, source, propertyValues)); } } diff --git a/src/Avalonia.Base/Metadata/XmlnsPrefixAttribute.cs b/src/Avalonia.Base/Metadata/XmlnsPrefixAttribute.cs new file mode 100644 index 0000000000..ad017822e4 --- /dev/null +++ b/src/Avalonia.Base/Metadata/XmlnsPrefixAttribute.cs @@ -0,0 +1,39 @@ +using System; + +namespace Avalonia.Metadata +{ + /// + /// Use to predefine the prefix associated to an xml namespace in a xaml file + /// + /// + /// example: + /// [assembly: XmlnsPrefix("https://github.com/avaloniaui", "av")] + /// xaml: + /// xmlns:av="https://github.com/avaloniaui" + /// + [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] + public sealed class XmlnsPrefixAttribute : Attribute + { + /// + /// Constructor + /// + /// XML namespce + /// recommended prefix + public XmlnsPrefixAttribute(string xmlNamespace, string prefix) + { + XmlNamespace = xmlNamespace ?? throw new ArgumentNullException(nameof(xmlNamespace)); + + Prefix = prefix ?? throw new ArgumentNullException(nameof(prefix)); + } + + /// + /// XML Namespace + /// + public string XmlNamespace { get; } + + /// + /// New Xml Namespace + /// + public string Prefix { get; } + } +} diff --git a/src/Avalonia.Base/Properties/AssemblyInfo.cs b/src/Avalonia.Base/Properties/AssemblyInfo.cs index 73be561ae2..b054c186ae 100644 --- a/src/Avalonia.Base/Properties/AssemblyInfo.cs +++ b/src/Avalonia.Base/Properties/AssemblyInfo.cs @@ -5,8 +5,18 @@ using System.Runtime.CompilerServices; using Avalonia.Metadata; [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Data.Converters")] +#if SIGNED_BUILD [assembly: InternalsVisibleTo("Avalonia.Base.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] [assembly: InternalsVisibleTo("Avalonia.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] [assembly: InternalsVisibleTo("Avalonia.Controls.DataGrid, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] [assembly: InternalsVisibleTo("Avalonia.Markup.Xaml.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] +[assembly: InternalsVisibleTo("Avalonia.Visuals, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] +#else +[assembly: InternalsVisibleTo("Avalonia.Base.UnitTests")] +[assembly: InternalsVisibleTo("Avalonia.UnitTests")] +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] +[assembly: InternalsVisibleTo("Avalonia.Controls.DataGrid")] +[assembly: InternalsVisibleTo("Avalonia.Markup.Xaml.UnitTests")] +[assembly: InternalsVisibleTo("Avalonia.Visuals")] +#endif diff --git a/src/Avalonia.Base/StyledPropertyMetadata`1.cs b/src/Avalonia.Base/StyledPropertyMetadata`1.cs index cf0a0c34ec..ec7bff4dfb 100644 --- a/src/Avalonia.Base/StyledPropertyMetadata`1.cs +++ b/src/Avalonia.Base/StyledPropertyMetadata`1.cs @@ -6,7 +6,7 @@ namespace Avalonia /// /// Metadata for styled avalonia properties. /// - public class StyledPropertyMetadata : PropertyMetadata, IStyledPropertyMetadata + public class StyledPropertyMetadata : AvaloniaPropertyMetadata, IStyledPropertyMetadata { private Optional _defaultValue; @@ -39,7 +39,7 @@ namespace Avalonia object IStyledPropertyMetadata.DefaultValue => DefaultValue; /// - public override void Merge(PropertyMetadata baseMetadata, AvaloniaProperty property) + public override void Merge(AvaloniaPropertyMetadata baseMetadata, AvaloniaProperty property) { base.Merge(baseMetadata, property); diff --git a/src/Avalonia.Base/Threading/AvaloniaSynchronizationContext.cs b/src/Avalonia.Base/Threading/AvaloniaSynchronizationContext.cs index 40cf81358f..1a78792173 100644 --- a/src/Avalonia.Base/Threading/AvaloniaSynchronizationContext.cs +++ b/src/Avalonia.Base/Threading/AvaloniaSynchronizationContext.cs @@ -9,20 +9,6 @@ namespace Avalonia.Threading /// public class AvaloniaSynchronizationContext : SynchronizationContext { - public interface INonPumpingPlatformWaitProvider - { - int Wait(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout); - } - - private readonly INonPumpingPlatformWaitProvider _waitProvider; - - public AvaloniaSynchronizationContext(INonPumpingPlatformWaitProvider waitProvider) - { - _waitProvider = waitProvider; - if (_waitProvider != null) - SetWaitNotificationRequired(); - } - /// /// Controls if SynchronizationContext should be installed in InstallIfNeeded. Used by Designer. /// @@ -38,8 +24,7 @@ namespace Avalonia.Threading return; } - SetSynchronizationContext(new AvaloniaSynchronizationContext(AvaloniaLocator.Current - .GetService())); + SetSynchronizationContext(new AvaloniaSynchronizationContext()); } /// @@ -57,12 +42,6 @@ namespace Avalonia.Threading Dispatcher.UIThread.InvokeAsync(() => d(state), DispatcherPriority.Send).Wait(); } - [PrePrepareMethod] - public override int Wait(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout) - { - if (_waitProvider != null) - return _waitProvider.Wait(waitHandles, waitAll, millisecondsTimeout); - return base.Wait(waitHandles, waitAll, millisecondsTimeout); - } + } } diff --git a/src/Avalonia.Base/Utilities/AvaloniaPropertyValueStore.cs b/src/Avalonia.Base/Utilities/AvaloniaPropertyValueStore.cs index 0238446892..6e52b6770a 100644 --- a/src/Avalonia.Base/Utilities/AvaloniaPropertyValueStore.cs +++ b/src/Avalonia.Base/Utilities/AvaloniaPropertyValueStore.cs @@ -1,5 +1,8 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +#nullable enable namespace Avalonia.Utilities { @@ -9,12 +12,14 @@ namespace Avalonia.Utilities /// Stored value type. internal sealed class AvaloniaPropertyValueStore { + // The last item in the list is always int.MaxValue. + private static readonly Entry[] s_emptyEntries = { new Entry { PropertyId = int.MaxValue, Value = default! } }; + private Entry[] _entries; public AvaloniaPropertyValueStore() { - // The last item in the list is always int.MaxValue - _entries = new[] { new Entry { PropertyId = int.MaxValue, Value = default } }; + _entries = s_emptyEntries; } private (int, bool) TryFindEntry(int propertyId) @@ -86,7 +91,7 @@ namespace Avalonia.Utilities return (0, false); } - public bool TryGetValue(AvaloniaProperty property, out TValue value) + public bool TryGetValue(AvaloniaProperty property, [MaybeNull] out TValue value) { (int index, bool found) = TryFindEntry(property.Id); if (!found) @@ -132,7 +137,18 @@ namespace Avalonia.Utilities if (found) { - Entry[] entries = new Entry[_entries.Length - 1]; + var newLength = _entries.Length - 1; + + // Special case - one element left means that value store is empty so we can just reuse our "empty" array. + if (newLength == 1) + { + _entries = s_emptyEntries; + + return; + } + + var entries = new Entry[newLength]; + int ix = 0; for (int i = 0; i < _entries.Length; ++i) diff --git a/src/Avalonia.Base/Utilities/MathUtilities.cs b/src/Avalonia.Base/Utilities/MathUtilities.cs index 2a92e75f58..446b366dc8 100644 --- a/src/Avalonia.Base/Utilities/MathUtilities.cs +++ b/src/Avalonia.Base/Utilities/MathUtilities.cs @@ -5,7 +5,10 @@ namespace Avalonia.Utilities /// /// Provides math utilities not provided in System.Math. /// - public static class MathUtilities +#if !BUILDTASK + public +#endif + static class MathUtilities { // smallest such that 1.0+DoubleEpsilon != 1.0 internal static readonly double DoubleEpsilon = 2.2204460492503131e-016; diff --git a/src/Avalonia.Base/Utilities/NonPumpingLockHelper.cs b/src/Avalonia.Base/Utilities/NonPumpingLockHelper.cs new file mode 100644 index 0000000000..fd4e5d2ace --- /dev/null +++ b/src/Avalonia.Base/Utilities/NonPumpingLockHelper.cs @@ -0,0 +1,14 @@ +using System; + +namespace Avalonia.Utilities +{ + public class NonPumpingLockHelper + { + public interface IHelperImpl + { + IDisposable Use(); + } + + public static IDisposable Use() => AvaloniaLocator.Current.GetService()?.Use(); + } +} diff --git a/src/Avalonia.Base/Utilities/StringTokenizer.cs b/src/Avalonia.Base/Utilities/StringTokenizer.cs index a159bfb72e..24e99febb9 100644 --- a/src/Avalonia.Base/Utilities/StringTokenizer.cs +++ b/src/Avalonia.Base/Utilities/StringTokenizer.cs @@ -4,7 +4,10 @@ using static System.Char; namespace Avalonia.Utilities { - public struct StringTokenizer : IDisposable +#if !BUILDTASK + public +#endif + struct StringTokenizer : IDisposable { private const char DefaultSeparatorChar = ','; diff --git a/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj b/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj index 94ad4adb7d..90f6abc873 100644 --- a/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj +++ b/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj @@ -1,7 +1,7 @@  netstandard2.0 - netstandard2.0;netcoreapp2.0 + netstandard2.0;netcoreapp3.1 exe false tools @@ -45,6 +45,12 @@ Markup/%(RecursiveDir)%(FileName)%(Extension) + + Markup/%(RecursiveDir)%(FileName)%(Extension) + + + Markup/%(RecursiveDir)%(FileName)%(Extension) + Markup/%(RecursiveDir)%(FileName)%(Extension) @@ -57,6 +63,33 @@ Markup/%(RecursiveDir)%(FileName)%(Extension) + + Markup/%(RecursiveDir)%(FileName)%(Extension) + + + Markup/%(RecursiveDir)%(FileName)%(Extension) + + + Markup/%(RecursiveDir)%(FileName)%(Extension) + + + Markup/%(RecursiveDir)%(FileName)%(Extension) + + + Markup/%(RecursiveDir)%(FileName)%(Extension) + + + Markup/%(RecursiveDir)%(FileName)%(Extension) + + + Markup/%(RecursiveDir)%(FileName)%(Extension) + + + Markup/%(RecursiveDir)%(FileName)%(Extension) + + + Markup/%(RecursiveDir)%(FileName)%(Extension) + diff --git a/src/Avalonia.Build.Tasks/ComInteropHelper.cs b/src/Avalonia.Build.Tasks/ComInteropHelper.cs new file mode 100644 index 0000000000..007231417d --- /dev/null +++ b/src/Avalonia.Build.Tasks/ComInteropHelper.cs @@ -0,0 +1,130 @@ +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using Mono.Cecil; +using Mono.Cecil.Cil; +using XamlX.TypeSystem; +using MethodAttributes = Mono.Cecil.MethodAttributes; + +namespace Avalonia.Build.Tasks +{ + static class ComInteropHelper + { + public static void PatchAssembly(AssemblyDefinition asm, CecilTypeSystem typeSystem) + { + var classToRemoveList = new List(); + var initializers = new List(); + foreach (var type in asm.MainModule.Types) + { + var i = type.Methods.FirstOrDefault(m => m.Name == "__MicroComModuleInit"); + if (i != null) + initializers.Add(i); + + PatchType(type, classToRemoveList); + } + + // Remove All Interop classes + foreach (var type in classToRemoveList) + asm.MainModule.Types.Remove(type); + + + // Patch automatic registrations + if (initializers.Count != 0) + { + var moduleType = asm.MainModule.Types.First(x => x.Name == ""); + + // Needed for compatibility with upcoming .NET 5 feature, look for existing initializer first + var staticCtor = moduleType.Methods.FirstOrDefault(m => m.Name == ".cctor"); + if (staticCtor == null) + { + // Create a new static ctor if none exists + staticCtor = new MethodDefinition(".cctor", + MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName | + MethodAttributes.Static | MethodAttributes.Private, + asm.MainModule.TypeSystem.Void); + staticCtor.Body.Instructions.Add(Instruction.Create(OpCodes.Ret)); + moduleType.Methods.Add(staticCtor); + } + + foreach (var i in initializers) + staticCtor.Body.Instructions.Insert(0, Instruction.Create(OpCodes.Call, i)); + } + + } + + + + static void PatchMethod(MethodDefinition method) + { + if (method.HasBody) + { + var ilProcessor = method.Body.GetILProcessor(); + + var instructions = method.Body.Instructions; + for (int i = 0; i < instructions.Count; i++) + { + Instruction instruction = instructions[i]; + + if (instruction.OpCode == OpCodes.Call && instruction.Operand is MethodReference) + { + var methodDescription = (MethodReference)instruction.Operand; + + if (methodDescription.Name.StartsWith("Calli") && methodDescription.DeclaringType.Name == "LocalInterop") + { + var callSite = new CallSite(methodDescription.ReturnType) { CallingConvention = MethodCallingConvention.StdCall }; + + if (methodDescription.Name.StartsWith("CalliCdecl")) + { + callSite.CallingConvention = MethodCallingConvention.C; + } + else if(methodDescription.Name.StartsWith("CalliThisCall")) + { + callSite.CallingConvention = MethodCallingConvention.ThisCall; + } + else if(methodDescription.Name.StartsWith("CalliStdCall")) + { + callSite.CallingConvention = MethodCallingConvention.StdCall; + } + else if(methodDescription.Name.StartsWith("CalliFastCall")) + { + callSite.CallingConvention = MethodCallingConvention.FastCall; + } + + // Last parameter is the function ptr, so we don't add it as a parameter for calli + // as it is already an implicit parameter for calli + for (int j = 0; j < methodDescription.Parameters.Count - 1; j++) + { + var parameterDefinition = methodDescription.Parameters[j]; + callSite.Parameters.Add(parameterDefinition); + } + + // Create calli Instruction + var callIInstruction = ilProcessor.Create(OpCodes.Calli, callSite); + + // Replace instruction + ilProcessor.Replace(instruction, callIInstruction); + } + } + } + } + } + + /// + /// Patches the type. + /// + /// The type. + static void PatchType(TypeDefinition type, List classToRemoveList) + { + // Patch methods + foreach (var method in type.Methods) + PatchMethod(method); + + if (type.Name == "LocalInterop") + classToRemoveList.Add(type); + + // Patch nested types + foreach (var typeDefinition in type.NestedTypes) + PatchType(typeDefinition, classToRemoveList); + } + } +} diff --git a/src/Avalonia.Build.Tasks/CompileAvaloniaXamlTask.cs b/src/Avalonia.Build.Tasks/CompileAvaloniaXamlTask.cs index 8e1f6c257d..b85991fb77 100644 --- a/src/Avalonia.Build.Tasks/CompileAvaloniaXamlTask.cs +++ b/src/Avalonia.Build.Tasks/CompileAvaloniaXamlTask.cs @@ -40,8 +40,8 @@ namespace Avalonia.Build.Tasks var res = XamlCompilerTaskExecutor.Compile(BuildEngine, input, File.ReadAllLines(ReferencesFilePath).Where(l => !string.IsNullOrWhiteSpace(l)).ToArray(), ProjectDirectory, OutputPath, VerifyIl, outputImportance, - (SignAssembly && !DelaySign) ? AssemblyOriginatorKeyFile : null - ); + (SignAssembly && !DelaySign) ? AssemblyOriginatorKeyFile : null, + EnableComInteropPatching, SkipXamlCompilation); if (!res.Success) return false; if (!res.WrittenFile) @@ -76,6 +76,9 @@ namespace Avalonia.Build.Tasks public bool VerifyIl { get; set; } + public bool EnableComInteropPatching { get; set; } + public bool SkipXamlCompilation { get; set; } + public string AssemblyOriginatorKeyFile { get; set; } public bool SignAssembly { get; set; } public bool DelaySign { get; set; } diff --git a/src/Avalonia.Build.Tasks/Program.cs b/src/Avalonia.Build.Tasks/Program.cs index 1909c4c6ec..b18c19cd63 100644 --- a/src/Avalonia.Build.Tasks/Program.cs +++ b/src/Avalonia.Build.Tasks/Program.cs @@ -29,7 +29,8 @@ namespace Avalonia.Build.Tasks OutputPath = args[2], BuildEngine = new ConsoleBuildEngine(), ProjectDirectory = Directory.GetCurrentDirectory(), - VerifyIl = true + VerifyIl = true, + EnableComInteropPatching = true }.Execute() ? 0 : 2; diff --git a/src/Avalonia.Build.Tasks/SpanCompat.cs b/src/Avalonia.Build.Tasks/SpanCompat.cs index d5c406293e..f8960f56ec 100644 --- a/src/Avalonia.Build.Tasks/SpanCompat.cs +++ b/src/Avalonia.Build.Tasks/SpanCompat.cs @@ -1,3 +1,4 @@ +#if !NETCOREAPP3_1 namespace System { // This is a hack to enable our span code to work inside MSBuild task without referencing System.Memory @@ -63,6 +64,8 @@ namespace System } public override string ToString() => _length == 0 ? string.Empty : _s.Substring(_start, _length); + + public static implicit operator ReadOnlySpan(char[] arr) => new ReadOnlySpan(new string(arr)); } static class SpanCompatExtensions @@ -71,3 +74,4 @@ namespace System } } +#endif diff --git a/src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs b/src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs index 6b01af2ede..6ef8a98fae 100644 --- a/src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs +++ b/src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs @@ -40,17 +40,50 @@ namespace Avalonia.Build.Tasks WrittenFile = writtenFile; } } + + public static CompileResult Compile(IBuildEngine engine, string input, string[] references, + string projectDirectory, + string output, bool verifyIl, MessageImportance logImportance, string strongNameKey, bool patchCom, + bool skipXamlCompilation) + { + var typeSystem = new CecilTypeSystem(references + .Where(r => !r.ToLowerInvariant().EndsWith("avalonia.build.tasks.dll")) + .Concat(new[] { input }), input); + + var asm = typeSystem.TargetAssemblyDefinition; + + if (!skipXamlCompilation) + { + var compileRes = CompileCore(engine, typeSystem, projectDirectory, verifyIl, logImportance); + if (compileRes == null && !patchCom) + return new CompileResult(true); + if (compileRes == false) + return new CompileResult(false); + } + + if (patchCom) + ComInteropHelper.PatchAssembly(asm, typeSystem); + + var writerParameters = new WriterParameters { WriteSymbols = asm.MainModule.HasSymbols }; + if (!string.IsNullOrWhiteSpace(strongNameKey)) + writerParameters.StrongNameKeyBlob = File.ReadAllBytes(strongNameKey); + + asm.Write(output, writerParameters); + + return new CompileResult(true, true); + + } - public static CompileResult Compile(IBuildEngine engine, string input, string[] references, string projectDirectory, - string output, bool verifyIl, MessageImportance logImportance, string strongNameKey) + static bool? CompileCore(IBuildEngine engine, CecilTypeSystem typeSystem, + string projectDirectory, bool verifyIl, + MessageImportance logImportance) { - var typeSystem = new CecilTypeSystem(references.Concat(new[] {input}), input); var asm = typeSystem.TargetAssemblyDefinition; var emres = new EmbeddedResources(asm); var avares = new AvaloniaResources(asm, projectDirectory); if (avares.Resources.Count(CheckXamlName) == 0 && emres.Resources.Count(CheckXamlName) == 0) // Nothing to do - return new CompileResult(true); + return null; var clrPropertiesDef = new TypeDefinition("CompiledAvaloniaXaml", "XamlIlHelpers", TypeAttributes.Class, asm.MainModule.TypeSystem.Object); @@ -364,25 +397,17 @@ namespace Avalonia.Build.Tasks if (emres.Resources.Count(CheckXamlName) != 0) if (!CompileGroup(emres)) - return new CompileResult(false); + return false; if (avares.Resources.Count(CheckXamlName) != 0) { if (!CompileGroup(avares)) - return new CompileResult(false); + return false; avares.Save(); } loaderDispatcherMethod.Body.Instructions.Add(Instruction.Create(OpCodes.Ldnull)); loaderDispatcherMethod.Body.Instructions.Add(Instruction.Create(OpCodes.Ret)); - - - var writerParameters = new WriterParameters { WriteSymbols = asm.MainModule.HasSymbols }; - if (!string.IsNullOrWhiteSpace(strongNameKey)) - writerParameters.StrongNameKeyBlob = File.ReadAllBytes(strongNameKey); - - asm.Write(output, writerParameters); - - return new CompileResult(true, true); + return true; } } diff --git a/src/Avalonia.Controls.DataGrid/ApiCompatBaseline.txt b/src/Avalonia.Controls.DataGrid/ApiCompatBaseline.txt deleted file mode 100644 index 82472c505a..0000000000 --- a/src/Avalonia.Controls.DataGrid/ApiCompatBaseline.txt +++ /dev/null @@ -1,5 +0,0 @@ -Compat issues with assembly Avalonia.Controls.DataGrid: -MembersMustExist : Member 'public Avalonia.StyledProperty Avalonia.StyledProperty Avalonia.Controls.DataGridTextColumn.FontFamilyProperty' does not exist in the implementation but it does exist in the contract. -MembersMustExist : Member 'public System.String Avalonia.Controls.DataGridTextColumn.FontFamily.get()' does not exist in the implementation but it does exist in the contract. -MembersMustExist : Member 'public void Avalonia.Controls.DataGridTextColumn.FontFamily.set(System.String)' does not exist in the implementation but it does exist in the contract. -Total Issues: 3 diff --git a/src/Avalonia.Controls.DataGrid/DataGrid.cs b/src/Avalonia.Controls.DataGrid/DataGrid.cs index 5bb2763566..8f9b9583cf 100644 --- a/src/Avalonia.Controls.DataGrid/DataGrid.cs +++ b/src/Avalonia.Controls.DataGrid/DataGrid.cs @@ -1,6 +1,6 @@ // This source is subject to the Microsoft Public License (Ms-PL). // Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details. -// All other rights reserved. +// All other rights reserved. using Avalonia.Collections; using Avalonia.Controls.Primitives; @@ -92,7 +92,7 @@ namespace Avalonia.Controls private ContentControl _topRightCornerHeader; private Control _frozenColumnScrollBarSpacer; - // the sum of the widths in pixels of the scrolling columns preceding + // the sum of the widths in pixels of the scrolling columns preceding // the first displayed scrolling column private double _horizontalOffset; @@ -143,7 +143,7 @@ namespace Avalonia.Controls private object _uneditedValue; // Represents the original current cell value at the time it enters editing mode. private ICellEditBinding _currentCellEditBinding; - // An approximation of the sum of the heights in pixels of the scrolling rows preceding + // An approximation of the sum of the heights in pixels of the scrolling rows preceding // the first displayed scrolling row. Since the scrolled off rows are discarded, the grid // does not know their actual height. The heights used for the approximation are the ones // set as the rows were scrolled off. @@ -162,7 +162,7 @@ namespace Avalonia.Controls AvaloniaProperty.Register(nameof(CanUserReorderColumns)); /// - /// Gets or sets a value that indicates whether the user can change + /// Gets or sets a value that indicates whether the user can change /// the column display order by dragging column headers with the mouse. /// public bool CanUserReorderColumns @@ -247,8 +247,8 @@ namespace Avalonia.Controls /// Gets or sets the that is used to paint the background of odd-numbered rows. /// /// - /// The brush that is used to paint the background of odd-numbered rows. The default is a - /// with a + /// The brush that is used to paint the background of odd-numbered rows. The default is a + /// with a /// value of white (ARGB value #00FFFFFF). /// public IBrush AlternatingRowBackground @@ -379,8 +379,8 @@ namespace Avalonia.Controls public bool IsValid { get { return _isValid; } - internal set - { + internal set + { SetAndRaise(IsValidProperty, ref _isValid, value); PseudoClasses.Set(":invalid", !value); } @@ -398,7 +398,7 @@ namespace Avalonia.Controls } /// - /// Gets or sets the maximum width of columns in the . + /// Gets or sets the maximum width of columns in the . /// public double MaxColumnWidth { @@ -418,7 +418,7 @@ namespace Avalonia.Controls } /// - /// Gets or sets the minimum width of columns in the . + /// Gets or sets the minimum width of columns in the . /// public double MinColumnWidth { @@ -496,7 +496,7 @@ namespace Avalonia.Controls AvaloniaProperty.Register(nameof(VerticalGridLinesBrush)); /// - /// Gets or sets the that is used to paint grid lines separating columns. + /// Gets or sets the that is used to paint grid lines separating columns. /// public IBrush VerticalGridLinesBrush { @@ -542,7 +542,7 @@ namespace Avalonia.Controls /// /// /// The index of the current selection, or -1 if the selection is empty. - /// + /// public int SelectedIndex { get { return _selectedIndex; } @@ -582,7 +582,7 @@ namespace Avalonia.Controls AvaloniaProperty.Register(nameof(AutoGenerateColumns)); /// - /// Gets or sets a value that indicates whether columns are created + /// Gets or sets a value that indicates whether columns are created /// automatically when the property is set. /// public bool AutoGenerateColumns @@ -626,7 +626,7 @@ namespace Avalonia.Controls AvaloniaProperty.Register(nameof(AreRowDetailsFrozen)); /// - /// Gets or sets a value that indicates whether the row details sections remain + /// Gets or sets a value that indicates whether the row details sections remain /// fixed at the width of the display area or can scroll horizontally. /// public bool AreRowDetailsFrozen @@ -881,7 +881,7 @@ namespace Avalonia.Controls { int index = (int)e.NewValue; - // GetDataItem returns null if index is >= Count, we do not check newValue + // GetDataItem returns null if index is >= Count, we do not check newValue // against Count here to avoid enumerating through an Enumerable twice // Setting SelectedItem coerces the finally value of the SelectedIndex object newSelectedItem = (index < 0) ? null : DataConnection.GetDataItem(index); @@ -1168,14 +1168,14 @@ namespace Avalonia.Controls } /// - /// Occurs one time for each public, non-static property in the bound data type when the - /// property is changed and the + /// Occurs one time for each public, non-static property in the bound data type when the + /// property is changed and the /// property is true. /// public event EventHandler AutoGeneratingColumn; /// - /// Occurs before a cell or row enters editing mode. + /// Occurs before a cell or row enters editing mode. /// public event EventHandler BeginningEdit; @@ -1195,7 +1195,7 @@ namespace Avalonia.Controls public event EventHandler CellPointerPressed; /// - /// Occurs when the + /// Occurs when the /// property of a column changes. /// public event EventHandler ColumnDisplayIndexChanged; @@ -1218,14 +1218,14 @@ namespace Avalonia.Controls public event EventHandler CurrentCellChanged; /// - /// Occurs after a + /// Occurs after a /// is instantiated, so that you can customize it before it is used. /// public event EventHandler LoadingRow; /// /// Occurs when a cell in a enters editing mode. - /// + /// /// public event EventHandler PreparingCellForEdit; @@ -1243,7 +1243,7 @@ namespace Avalonia.Controls RoutedEvent.Register(nameof(SelectionChanged), RoutingStrategies.Bubble); /// - /// Occurs when the or + /// Occurs when the or /// property value changes. /// public event EventHandler SelectionChanged @@ -1258,19 +1258,19 @@ namespace Avalonia.Controls public event EventHandler Sorting; /// - /// Occurs when a + /// Occurs when a /// object becomes available for reuse. /// public event EventHandler UnloadingRow; /// - /// Occurs when a new row details template is applied to a row, so that you can customize + /// Occurs when a new row details template is applied to a row, so that you can customize /// the details section before it is used. /// public event EventHandler LoadingRowDetails; /// - /// Occurs when the + /// Occurs when the /// property value changes. /// public event EventHandler RowDetailsVisibilityChanged; @@ -1282,7 +1282,7 @@ namespace Avalonia.Controls /// /// Gets a collection that contains all the columns in the control. - /// + /// public ObservableCollection Columns { get @@ -1456,7 +1456,7 @@ namespace Avalonia.Controls } // Height currently available for cells this value is smaller. This height is reduced by the existence of ColumnHeaders - // or a horizontal scrollbar. Layout is asynchronous so changes to the ColumnHeaders or the horizontal scrollbar are + // or a horizontal scrollbar. Layout is asynchronous so changes to the ColumnHeaders or the horizontal scrollbar are // not reflected immediately. internal double CellsHeight { @@ -1555,7 +1555,7 @@ namespace Avalonia.Controls internal static double HorizontalGridLinesThickness => DATAGRID_horizontalGridLinesThickness; - // the sum of the widths in pixels of the scrolling columns preceding + // the sum of the widths in pixels of the scrolling columns preceding // the first displayed scrolling column internal double HorizontalOffset { @@ -2083,20 +2083,20 @@ namespace Avalonia.Controls } /// - /// Measures the children of a to prepare for - /// arranging them during the - /// pass. + /// Measures the children of a to prepare for + /// arranging them during the + /// pass. /// /// /// The size that the determines it needs during layout, based on its calculations of child object allocated sizes. /// /// - /// The available size that this element can give to child elements. Indicates an upper limit that + /// The available size that this element can give to child elements. Indicates an upper limit that /// child elements should not exceed. /// protected override Size MeasureOverride(Size availableSize) { - // Delay layout until after the initial measure to avoid invalid calculations when the + // Delay layout until after the initial measure to avoid invalid calculations when the // DataGrid is not part of the visual tree if (!_measured) { @@ -2285,6 +2285,17 @@ namespace Avalonia.Controls } } + /// + /// Comparator class so we can sort list by the display index + /// + public class DisplayIndexComparer : IComparer + { + int IComparer.Compare(DataGridColumn x, DataGridColumn y) + { + return (x.DisplayIndexWithFiller < y.DisplayIndexWithFiller) ? -1 : 1; + } + } + /// /// Builds the visual tree for the column header when a new template is applied. /// @@ -2309,8 +2320,11 @@ namespace Avalonia.Controls ColumnsInternal.FillerColumn.IsRepresented = false; } _columnHeadersPresenter.OwningGrid = this; - // Columns were added before before our Template was applied, add the ColumnHeaders now - foreach (DataGridColumn column in ColumnsItemsInternal) + + // Columns were added before our Template was applied, add the ColumnHeaders now + List sortedInternal = new List(ColumnsItemsInternal); + sortedInternal.Sort(new DisplayIndexComparer()); + foreach (DataGridColumn column in sortedInternal) { InsertDisplayedColumnHeader(column); } @@ -3006,7 +3020,7 @@ namespace Avalonia.Controls /// If the editing element has focus, this method will set focus to the DataGrid itself /// in order to force the element to lose focus. It will then wait for the editing element's /// LostFocus event, at which point it will perform the specified action. - /// + /// /// NOTE: It is important to understand that the specified action will be performed when the editing /// element loses focus only if this method returns true. If it returns false, then the action /// will not be performed later on, and should instead be performed by the caller, if necessary. @@ -3065,7 +3079,7 @@ namespace Avalonia.Controls { if (!_scrollingByHeight) { - // Update layout when RowDetails are expanded or collapsed, just updating the vertical scroll bar is not enough + // Update layout when RowDetails are expanded or collapsed, just updating the vertical scroll bar is not enough // since rows could be added or removed InvalidateMeasure(); } @@ -3278,7 +3292,7 @@ namespace Avalonia.Controls { // Current cell was reset because the commit deleted row(s). // Since the user wants to change the current cell, we don't - // want to end up with no current cell. We pick the last row + // want to end up with no current cell. We pick the last row // in the grid which may be the 'new row'. int lastSlot = LastVisibleSlot; if (forCurrentCellChange && @@ -3336,7 +3350,7 @@ namespace Avalonia.Controls if (_ignoreNextScrollBarsLayout) { _ignoreNextScrollBarsLayout = false; - // + // } @@ -3393,7 +3407,7 @@ namespace Avalonia.Controls } // Now cellsWidth is the width potentially available for displaying data cells. - // Now cellsHeight is the height potentially available for displaying data cells. + // Now cellsHeight is the height potentially available for displaying data cells. bool needHorizScrollbar = false; bool needVertScrollbar = false; @@ -3418,7 +3432,7 @@ namespace Avalonia.Controls Debug.Assert(cellsHeight >= 0); needHorizScrollbarWithoutVertScrollbar = needHorizScrollbar = true; - if (vertScrollBarWidth > 0 && + if (vertScrollBarWidth > 0 && allowVertScrollbar && (MathUtilities.LessThanOrClose(totalVisibleWidth - cellsWidth, vertScrollBarWidth) || MathUtilities.LessThanOrClose(cellsWidth - totalVisibleFrozenWidth, vertScrollBarWidth))) { @@ -3458,7 +3472,7 @@ namespace Avalonia.Controls // we compute the number of visible columns only after we set up the vertical scroll bar. ComputeDisplayedColumns(); - if ((vertScrollBarWidth > 0 || horizScrollBarHeight > 0) && + if ((vertScrollBarWidth > 0 || horizScrollBarHeight > 0) && allowHorizScrollbar && needVertScrollbar && !needHorizScrollbar && MathUtilities.GreaterThan(totalVisibleWidth, cellsWidth) && @@ -3963,7 +3977,8 @@ namespace Avalonia.Controls { var errorList = binding.ValidationErrors - .SelectMany(ex => ValidationUtil.UnpackException(ex)) + .SelectMany(ValidationUtil.UnpackException) + .Select(ValidationUtil.UnpackDataValidationException) .ToList(); DataValidationErrors.SetErrors(editingElement, errorList); @@ -4124,7 +4139,7 @@ namespace Avalonia.Controls } /// - /// Exits editing mode without trying to commit or revert the editing, and + /// Exits editing mode without trying to commit or revert the editing, and /// without repopulating the edited row's cell. /// //TODO TabStop @@ -5103,9 +5118,9 @@ namespace Avalonia.Controls { if (ctrl || _editingColumnIndex == -1 || IsReadOnly) { - //Go to the next/previous control on the page when + //Go to the next/previous control on the page when // - Ctrl key is used - // - Potential current cell is not edited, or the datagrid is read-only. + // - Potential current cell is not edited, or the datagrid is read-only. return false; } @@ -5516,11 +5531,11 @@ namespace Avalonia.Controls // v---v //|<|_____|###|>| // ^ ^ - // min max + // min max // we want to make the relative size of the thumb reflect the relative size of the viewing area // viewportSize / (max + viewportSize) = cellsWidth / max - // -> viewportSize = max * cellsWidth / (max - cellsWidth) + // -> viewportSize = max * cellsWidth / (max - cellsWidth) // always zero _hScrollBar.Minimum = 0; @@ -5572,7 +5587,7 @@ namespace Avalonia.Controls _hScrollBar.Maximum = 0; if (_hScrollBar.IsVisible) { - // This will trigger a call to this method via Cells_SizeChanged for + // This will trigger a call to this method via Cells_SizeChanged for // which no processing is needed. _hScrollBar.IsVisible = false; _ignoreNextScrollBarsLayout = true; @@ -5591,14 +5606,14 @@ namespace Avalonia.Controls // v---v //|<|_____|###|>| // ^ ^ - // min max + // min max // we want to make the relative size of the thumb reflect the relative size of the viewing area // viewportSize / (max + viewportSize) = cellsWidth / max // -> viewportSize = max * cellsHeight / (totalVisibleHeight - cellsHeight) // -> = max * cellsHeight / (totalVisibleHeight - cellsHeight) // -> = max * cellsHeight / max - // -> = cellsHeight + // -> = cellsHeight // always zero _vScrollBar.Minimum = 0; @@ -5621,7 +5636,7 @@ namespace Avalonia.Controls if (!_vScrollBar.IsVisible) { - // This will trigger a call to this method via Cells_SizeChanged for + // This will trigger a call to this method via Cells_SizeChanged for // which no processing is needed. _vScrollBar.IsVisible = true; if (_vScrollBar.DesiredSize.Width == 0) @@ -5637,7 +5652,7 @@ namespace Avalonia.Controls _vScrollBar.Maximum = 0; if (_vScrollBar.IsVisible) { - // This will trigger a call to this method via Cells_SizeChanged for + // This will trigger a call to this method via Cells_SizeChanged for // which no processing is needed. _vScrollBar.IsVisible = false; _ignoreNextScrollBarsLayout = true; @@ -5660,8 +5675,8 @@ namespace Avalonia.Controls Debug.Assert(slot >= 0); // Before changing selection, check if the current cell needs to be committed, and - // check if the current row needs to be committed. If any of those two operations are required and fail, - // do not change selection, and do not change current cell. + // check if the current row needs to be committed. If any of those two operations are required and fail, + // do not change selection, and do not change current cell. bool wasInEdit = EditingColumnIndex != -1; diff --git a/src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs b/src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs index 856d1f6566..7f8d205949 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs @@ -340,8 +340,6 @@ namespace Avalonia.Controls if (OwningGrid != null && OwningGrid.ColumnHeaders != null) { - args.Pointer.Capture(this); - _dragMode = DragMode.MouseDown; _frozenColumnsWidth = OwningGrid.ColumnsInternal.GetVisibleFrozenEdgedColumnsWidth(); _lastMousePositionHeaders = this.Translate(OwningGrid.ColumnHeaders, mousePosition); @@ -413,8 +411,9 @@ namespace Avalonia.Controls } //TODO DragEvents - internal void OnMouseMove(ref bool handled, Point mousePosition, Point mousePositionHeaders) + internal void OnMouseMove(PointerEventArgs args, Point mousePosition, Point mousePositionHeaders) { + var handled = args.Handled; if (handled || OwningGrid == null || OwningGrid.ColumnHeaders == null) { return; @@ -438,7 +437,10 @@ namespace Avalonia.Controls } _lastMousePositionHeaders = mousePositionHeaders; - + + if (args.Pointer.Captured != this && _dragMode == DragMode.Drag) + args.Pointer.Capture(this); + SetDragCursor(mousePosition); } @@ -506,8 +508,7 @@ namespace Avalonia.Controls Point mousePosition = e.GetPosition(this); Point mousePositionHeaders = e.GetPosition(OwningGrid.ColumnHeaders); - bool handled = false; - OnMouseMove(ref handled, mousePosition, mousePositionHeaders); + OnMouseMove(e, mousePosition, mousePositionHeaders); } /// diff --git a/src/Avalonia.Controls.DataGrid/Primitives/DataGridRowsPresenter.cs b/src/Avalonia.Controls.DataGrid/Primitives/DataGridRowsPresenter.cs index 6ad58bf250..0d19f4c479 100644 --- a/src/Avalonia.Controls.DataGrid/Primitives/DataGridRowsPresenter.cs +++ b/src/Avalonia.Controls.DataGrid/Primitives/DataGridRowsPresenter.cs @@ -3,14 +3,15 @@ // Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details. // All other rights reserved. -using Avalonia.Media; using System; using System.Diagnostics; +using Avalonia.Layout; +using Avalonia.Media; namespace Avalonia.Controls.Primitives { /// - /// Used within the template of a to specify the + /// Used within the template of a to specify the /// location in the control's visual tree where the rows are to be added. /// public sealed class DataGridRowsPresenter : Panel @@ -22,9 +23,10 @@ namespace Avalonia.Controls.Primitives } private double _measureHeightOffset = 0; + private double CalculateEstimatedAvailableHeight(Size availableSize) { - if(!Double.IsPositiveInfinity(availableSize.Height)) + if (!Double.IsPositiveInfinity(availableSize.Height)) { return availableSize.Height + _measureHeightOffset; } @@ -50,10 +52,10 @@ namespace Avalonia.Controls.Primitives return base.ArrangeOverride(finalSize); } - if(OwningGrid.RowsPresenterAvailableSize.HasValue) + if (OwningGrid.RowsPresenterAvailableSize.HasValue) { var availableHeight = OwningGrid.RowsPresenterAvailableSize.Value.Height; - if(!Double.IsPositiveInfinity(availableHeight)) + if (!Double.IsPositiveInfinity(availableHeight)) { _measureHeightOffset = finalSize.Height - availableHeight; OwningGrid.RowsPresenterEstimatedAvailableHeight = finalSize.Height; @@ -108,6 +110,18 @@ namespace Avalonia.Controls.Primitives /// protected override Size MeasureOverride(Size availableSize) { + if (double.IsInfinity(availableSize.Height)) + { + if (VisualRoot is TopLevel topLevel) + { + double maxHeight = topLevel.IsArrangeValid ? + topLevel.Bounds.Height : + LayoutHelper.ApplyLayoutConstraints(topLevel, availableSize).Height; + + availableSize = availableSize.WithHeight(maxHeight); + } + } + if (availableSize.Height == 0 || OwningGrid == null) { return base.MeasureOverride(availableSize); diff --git a/src/Avalonia.Controls.DataGrid/Properties/AssemblyInfo.cs b/src/Avalonia.Controls.DataGrid/Properties/AssemblyInfo.cs index 72dd949421..1b122996d2 100644 --- a/src/Avalonia.Controls.DataGrid/Properties/AssemblyInfo.cs +++ b/src/Avalonia.Controls.DataGrid/Properties/AssemblyInfo.cs @@ -1,10 +1,13 @@ using System.Reflection; using System.Runtime.CompilerServices; using Avalonia.Metadata; - +#if SIGNED_BUILD [assembly: InternalsVisibleTo("Avalonia.Controls.DataGrid.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] [assembly: InternalsVisibleTo("Avalonia.DesignerSupport, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] - +#else +[assembly: InternalsVisibleTo("Avalonia.Controls.DataGrid.UnitTests")] +[assembly: InternalsVisibleTo("Avalonia.DesignerSupport")] +#endif [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Controls")] [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Controls.Collections")] [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Controls.Primitives")] diff --git a/src/Avalonia.Controls.DataGrid/Themes/Default.xaml b/src/Avalonia.Controls.DataGrid/Themes/Default.xaml index cf062e0920..09d19c8e43 100644 --- a/src/Avalonia.Controls.DataGrid/Themes/Default.xaml +++ b/src/Avalonia.Controls.DataGrid/Themes/Default.xaml @@ -137,12 +137,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml.cs b/src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml.cs index c6bd5a18aa..c9568509f6 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml.cs @@ -1,10 +1,24 @@ +using System; using Avalonia.Controls; +using Avalonia.Controls.Shapes; using Avalonia.Markup.Xaml; +using Avalonia.VisualTree; namespace Avalonia.Diagnostics.Views { internal class ControlDetailsView : UserControl { + private ThicknessEditor _borderArea; + private ThicknessEditor _paddingArea; + private Rectangle _horizontalSizeBegin; + private Rectangle _horizontalSizeEnd; + private Rectangle _verticalSizeBegin; + private Rectangle _verticalSizeEnd; + private Grid _layoutRoot; + private Border _horizontalSize; + private Border _verticalSize; + private Border _contentArea; + public ControlDetailsView() { InitializeComponent(); @@ -13,6 +27,101 @@ namespace Avalonia.Diagnostics.Views private void InitializeComponent() { AvaloniaXamlLoader.Load(this); + + _borderArea = this.FindControl("BorderArea"); + _paddingArea = this.FindControl("PaddingArea"); + + _horizontalSizeBegin = this.FindControl("HorizontalSizeBegin"); + _horizontalSizeEnd = this.FindControl("HorizontalSizeEnd"); + _verticalSizeBegin = this.FindControl("VerticalSizeBegin"); + _verticalSizeEnd = this.FindControl("VerticalSizeEnd"); + + _horizontalSize = this.FindControl("HorizontalSize"); + _verticalSize = this.FindControl("VerticalSize"); + + _contentArea = this.FindControl("ContentArea"); + + _layoutRoot = this.FindControl("LayoutRoot"); + + void SubscribeToBounds(Visual visual) + { + visual.GetPropertyChangedObservable(TransformedBoundsProperty) + .Subscribe(UpdateSizeGuidelines); + } + + SubscribeToBounds(_borderArea); + SubscribeToBounds(_paddingArea); + SubscribeToBounds(_contentArea); + } + + private void UpdateSizeGuidelines(AvaloniaPropertyChangedEventArgs e) + { + void UpdateGuidelines(Visual area) + { + if (area.TransformedBounds is TransformedBounds bounds) + { + // Horizontal guideline + { + var sizeArea = TranslateToRoot((_horizontalSize.TransformedBounds ?? default).Bounds.BottomLeft, + _horizontalSize); + + var start = TranslateToRoot(bounds.Bounds.BottomLeft, area); + + SetPosition(_horizontalSizeBegin, start); + + var end = TranslateToRoot(bounds.Bounds.BottomRight, area); + + SetPosition(_horizontalSizeEnd, end.WithX(end.X - 1)); + + var height = sizeArea.Y - start.Y + 2; + + _horizontalSizeBegin.Height = height; + _horizontalSizeEnd.Height = height; + } + + // Vertical guideline + { + var sizeArea = TranslateToRoot((_verticalSize.TransformedBounds ?? default).Bounds.TopRight, _verticalSize); + + var start = TranslateToRoot(bounds.Bounds.TopRight, area); + + SetPosition(_verticalSizeBegin, start); + + var end = TranslateToRoot(bounds.Bounds.BottomRight, area); + + SetPosition(_verticalSizeEnd, end.WithY(end.Y - 1)); + + var width = sizeArea.X - start.X + 2; + + _verticalSizeBegin.Width = width; + _verticalSizeEnd.Width = width; + } + } + } + + Point TranslateToRoot(Point point, IVisual from) + { + return from.TranslatePoint(point, _layoutRoot) ?? default; + } + + static void SetPosition(Rectangle rect, Point start) + { + Canvas.SetLeft(rect, start.X); + Canvas.SetTop(rect, start.Y); + } + + if (_borderArea.IsPresent) + { + UpdateGuidelines(_borderArea); + } + else if (_paddingArea.IsPresent) + { + UpdateGuidelines(_paddingArea); + } + else + { + UpdateGuidelines(_contentArea); + } } } } diff --git a/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml b/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml index 3623e95597..7dd4ed0832 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml +++ b/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml @@ -12,6 +12,9 @@ + diff --git a/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs b/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs index 10861538ae..c4f9185728 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs @@ -76,7 +76,13 @@ namespace Avalonia.Diagnostics.Views if (e.Modifiers == modifiers) { var point = (Root as IInputRoot)?.MouseDevice?.GetPosition(Root) ?? default; - var control = Root.GetVisualsAt(point, x => (!(x is AdornerLayer) && x.IsVisible)) + + var control = Root.GetVisualsAt(point, x => + { + if (x is AdornerLayer || !x.IsVisible) return false; + if (!(x is IInputElement ie)) return true; + return ie.IsHitTestVisible; + }) .FirstOrDefault(); if (control != null) diff --git a/src/Avalonia.Diagnostics/Diagnostics/Views/ThicknessEditor.cs b/src/Avalonia.Diagnostics/Diagnostics/Views/ThicknessEditor.cs new file mode 100644 index 0000000000..c7611c8c46 --- /dev/null +++ b/src/Avalonia.Diagnostics/Diagnostics/Views/ThicknessEditor.cs @@ -0,0 +1,130 @@ +using Avalonia.Controls; +using Avalonia.Data; +using Avalonia.Data.Converters; +using Avalonia.Media; + +namespace Avalonia.Diagnostics.Views +{ + internal static class Converters + { + public static IValueConverter HasConstraintConverter = + new FuncValueConverter(ConvertToDecoration); + + private static TextDecorationCollection ConvertToDecoration(object arg) + { + return arg != null ? TextDecorations.Underline : null; + } + } + + internal class ThicknessEditor : ContentControl + { + public static readonly DirectProperty ThicknessProperty = + AvaloniaProperty.RegisterDirect(nameof(Thickness), o => o.Thickness, + (o, v) => o.Thickness = v, defaultBindingMode: BindingMode.TwoWay); + + public static readonly DirectProperty HeaderProperty = + AvaloniaProperty.RegisterDirect(nameof(Header), o => o.Header, + (o, v) => o.Header = v); + + public static readonly DirectProperty IsPresentProperty = + AvaloniaProperty.RegisterDirect(nameof(Header), o => o.IsPresent, + (o, v) => o.IsPresent = v); + + public static readonly DirectProperty LeftProperty = + AvaloniaProperty.RegisterDirect(nameof(Left), o => o.Left, (o, v) => o.Left = v); + + public static readonly DirectProperty TopProperty = + AvaloniaProperty.RegisterDirect(nameof(Top), o => o.Top, (o, v) => o.Top = v); + + public static readonly DirectProperty RightProperty = + AvaloniaProperty.RegisterDirect(nameof(Right), o => o.Right, + (o, v) => o.Right = v); + + public static readonly DirectProperty BottomProperty = + AvaloniaProperty.RegisterDirect(nameof(Bottom), o => o.Bottom, + (o, v) => o.Bottom = v); + + + private Thickness _thickness; + private string _header; + private bool _isPresent = true; + private double _left; + private double _top; + private double _right; + private double _bottom; + + private bool _isUpdatingThickness; + + public Thickness Thickness + { + get => _thickness; + set => SetAndRaise(ThicknessProperty, ref _thickness, value); + } + + public string Header + { + get => _header; + set => SetAndRaise(HeaderProperty, ref _header, value); + } + + public bool IsPresent + { + get => _isPresent; + set => SetAndRaise(IsPresentProperty, ref _isPresent, value); + } + + public double Left + { + get => _left; + set => SetAndRaise(LeftProperty, ref _left, value); + } + + public double Top + { + get => _top; + set => SetAndRaise(TopProperty, ref _top, value); + } + + public double Right + { + get => _right; + set => SetAndRaise(RightProperty, ref _right, value); + } + + public double Bottom + { + get => _bottom; + set => SetAndRaise(BottomProperty, ref _bottom, value); + } + + protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) + { + base.OnPropertyChanged(change); + + if (change.Property == ThicknessProperty) + { + try + { + _isUpdatingThickness = true; + + var value = change.NewValue.GetValueOrDefault(); + + Left = value.Left; + Top = value.Top; + Right = value.Right; + Bottom = value.Bottom; + } + finally + { + _isUpdatingThickness = false; + } + } + else if (!_isUpdatingThickness && + (change.Property == LeftProperty || change.Property == TopProperty || + change.Property == RightProperty || change.Property == BottomProperty)) + { + Thickness = new Thickness(Left, Top, Right, Bottom); + } + } + } +} diff --git a/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml b/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml index a1e6ca7d37..86137dfc57 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml +++ b/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml @@ -2,7 +2,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:vm="clr-namespace:Avalonia.Diagnostics.ViewModels" x:Class="Avalonia.Diagnostics.Views.TreePageView"> - + + diff --git a/src/Avalonia.Dialogs/AboutAvaloniaDialog.xaml b/src/Avalonia.Dialogs/AboutAvaloniaDialog.xaml index e51cc2f3ce..c5e1d43d80 100644 --- a/src/Avalonia.Dialogs/AboutAvaloniaDialog.xaml +++ b/src/Avalonia.Dialogs/AboutAvaloniaDialog.xaml @@ -79,8 +79,8 @@ - - + + @@ -102,4 +102,4 @@ - \ No newline at end of file + diff --git a/src/Avalonia.Dialogs/AboutAvaloniaDialog.xaml.cs b/src/Avalonia.Dialogs/AboutAvaloniaDialog.xaml.cs index 09fab0ed3f..55e30396e1 100644 --- a/src/Avalonia.Dialogs/AboutAvaloniaDialog.xaml.cs +++ b/src/Avalonia.Dialogs/AboutAvaloniaDialog.xaml.cs @@ -1,3 +1,4 @@ +using System; using System.Diagnostics; using System.Runtime.InteropServices; using Avalonia.Controls; @@ -7,12 +8,18 @@ namespace Avalonia.Dialogs { public class AboutAvaloniaDialog : Window { + private static readonly Version s_version = typeof(AboutAvaloniaDialog).Assembly.GetName().Version; + + public static string Version { get; } = s_version.ToString(2); + + public static bool IsDevelopmentBuild { get; } = s_version.Revision == 999; + public AboutAvaloniaDialog() { AvaloniaXamlLoader.Load(this); DataContext = this; } - + public static void OpenBrowser(string url) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) diff --git a/src/Avalonia.FreeDesktop/DBusCallQueue.cs b/src/Avalonia.FreeDesktop/DBusCallQueue.cs new file mode 100644 index 0000000000..5cd748be02 --- /dev/null +++ b/src/Avalonia.FreeDesktop/DBusCallQueue.cs @@ -0,0 +1,110 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Avalonia.FreeDesktop +{ + class DBusCallQueue + { + private readonly Func _errorHandler; + + class Item + { + public Func Callback; + public Action OnFinish; + } + private Queue _q = new Queue(); + private bool _processing; + + public DBusCallQueue(Func errorHandler) + { + _errorHandler = errorHandler; + } + + public void Enqueue(Func cb) + { + _q.Enqueue(new Item + { + Callback = cb + }); + Process(); + } + + public Task EnqueueAsync(Func cb) + { + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + _q.Enqueue(new Item + { + Callback = cb, + OnFinish = e => + { + if (e == null) + tcs.TrySetResult(0); + else + tcs.TrySetException(e); + } + }); + Process(); + return tcs.Task; + } + + public Task EnqueueAsync(Func> cb) + { + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + _q.Enqueue(new Item + { + Callback = async () => + { + var res = await cb(); + tcs.TrySetResult(res); + }, + OnFinish = e => + { + if (e != null) + tcs.TrySetException(e); + } + }); + Process(); + return tcs.Task; + } + + async void Process() + { + if(_processing) + return; + _processing = true; + try + { + while (_q.Count > 0) + { + var item = _q.Dequeue(); + try + { + await item.Callback(); + item.OnFinish?.Invoke(null); + } + catch(Exception e) + { + if (item.OnFinish != null) + item.OnFinish(e); + else + await _errorHandler(e); + } + } + } + finally + { + _processing = false; + } + } + + public void FailAll() + { + while (_q.Count>0) + { + var item = _q.Dequeue(); + item.OnFinish?.Invoke(new OperationCanceledException()); + } + } + } +} diff --git a/src/Avalonia.FreeDesktop/DBusHelper.cs b/src/Avalonia.FreeDesktop/DBusHelper.cs index 91c4c28995..7996a94dd0 100644 --- a/src/Avalonia.FreeDesktop/DBusHelper.cs +++ b/src/Avalonia.FreeDesktop/DBusHelper.cs @@ -1,5 +1,6 @@ using System; using System.Threading; +using Avalonia.Logging; using Avalonia.Threading; using Tmds.DBus; @@ -43,13 +44,15 @@ namespace Avalonia.FreeDesktop public void Initialized() { lock (_lock) - _ctx = new AvaloniaSynchronizationContext(null); + _ctx = new AvaloniaSynchronizationContext(); } } public static Connection Connection { get; private set; } - public static Exception TryInitialize(string dbusAddress = null) + public static Connection TryInitialize(string dbusAddress = null) { + if (Connection != null) + return Connection; var oldContext = SynchronizationContext.Current; try { @@ -70,13 +73,15 @@ namespace Avalonia.FreeDesktop } catch (Exception e) { - return e; + Logger.TryGet(LogEventLevel.Error, "DBUS") + ?.Log(null, "Unable to connect to DBus: " + e); } finally { SynchronizationContext.SetSynchronizationContext(oldContext); } - return null; + + return Connection; } } } diff --git a/src/Avalonia.FreeDesktop/DBusIme/DBusTextInputMethodBase.cs b/src/Avalonia.FreeDesktop/DBusIme/DBusTextInputMethodBase.cs new file mode 100644 index 0000000000..a7e83140ae --- /dev/null +++ b/src/Avalonia.FreeDesktop/DBusIme/DBusTextInputMethodBase.cs @@ -0,0 +1,288 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Reflection; +using System.Threading.Tasks; +using Avalonia.FreeDesktop.DBusIme.Fcitx; +using Avalonia.Input.Raw; +using Avalonia.Input.TextInput; +using Avalonia.Logging; +using Tmds.DBus; + +namespace Avalonia.FreeDesktop.DBusIme +{ + internal class DBusInputMethodFactory : IX11InputMethodFactory where T : ITextInputMethodImpl, IX11InputMethodControl + { + private readonly Func _factory; + + public DBusInputMethodFactory(Func factory) + { + _factory = factory; + } + + public (ITextInputMethodImpl method, IX11InputMethodControl control) CreateClient(IntPtr xid) + { + var im = _factory(xid); + return (im, im); + } + } + + internal abstract class DBusTextInputMethodBase : IX11InputMethodControl, ITextInputMethodImpl + { + private List _disposables = new List(); + private Queue _onlineNamesQueue = new Queue(); + protected Connection Connection { get; } + private readonly string[] _knownNames; + private bool _connecting; + private string _currentName; + private DBusCallQueue _queue; + private bool _controlActive, _windowActive; + private bool? _imeActive; + private Rect _logicalRect; + private PixelRect? _lastReportedRect; + private double _scaling = 1; + private PixelPoint _windowPosition; + + protected bool IsConnected => _currentName != null; + + public DBusTextInputMethodBase(Connection connection, params string[] knownNames) + { + _queue = new DBusCallQueue(QueueOnError); + Connection = connection; + _knownNames = knownNames; + Watch(); + } + + async void Watch() + { + foreach (var name in _knownNames) + _disposables.Add(await Connection.ResolveServiceOwnerAsync(name, OnNameChange)); + } + + protected abstract Task Connect(string name); + + protected string GetAppName() => + Application.Current.Name ?? Assembly.GetEntryAssembly()?.GetName()?.Name ?? "Avalonia"; + + private async void OnNameChange(ServiceOwnerChangedEventArgs args) + { + if (args.NewOwner != null && _currentName == null) + { + _onlineNamesQueue.Enqueue(args.ServiceName); + if(!_connecting) + { + _connecting = true; + try + { + while (_onlineNamesQueue.Count > 0) + { + var name = _onlineNamesQueue.Dequeue(); + try + { + if (await Connect(name)) + { + _onlineNamesQueue.Clear(); + _currentName = name; + return; + } + } + catch (Exception e) + { + Logger.TryGet(LogEventLevel.Error, "IME") + ?.Log(this, "Unable to create IME input context:\n" + e); + } + } + } + finally + { + _connecting = false; + } + } + + } + + // IME has crashed + if (args.NewOwner == null && args.ServiceName == _currentName) + { + _currentName = null; + foreach(var s in _disposables) + s.Dispose(); + _disposables.Clear(); + + OnDisconnected(); + Reset(); + + // Watch again + Watch(); + } + } + + protected virtual Task Disconnect() + { + return Task.CompletedTask; + } + + protected virtual void OnDisconnected() + { + + } + + protected virtual void Reset() + { + _lastReportedRect = null; + _imeActive = null; + } + + async Task QueueOnError(Exception e) + { + Logger.TryGet(LogEventLevel.Error, "IME") + ?.Log(this, "Error:\n" + e); + try + { + await Disconnect(); + } + catch (Exception ex) + { + Logger.TryGet(LogEventLevel.Error, "IME") + ?.Log(this, "Error while destroying the context:\n" + ex); + } + OnDisconnected(); + _currentName = null; + } + + protected void Enqueue(Func cb) => _queue.Enqueue(cb); + + protected void AddDisposable(IDisposable d) => _disposables.Add(d); + + public void Dispose() + { + foreach(var d in _disposables) + d.Dispose(); + _disposables.Clear(); + try + { + Disconnect().ContinueWith(_ => { }); + } + catch + { + // fire and forget + } + _currentName = null; + } + + protected abstract Task SetCursorRectCore(PixelRect rect); + protected abstract Task SetActiveCore(bool active); + protected abstract Task ResetContextCore(); + protected abstract Task HandleKeyCore(RawKeyEventArgs args, int keyVal, int keyCode); + + void UpdateActive() + { + _queue.Enqueue(async () => + { + if(!IsConnected) + return; + + var active = _windowActive && _controlActive; + if (active != _imeActive) + { + _imeActive = active; + await SetActiveCore(active); + } + }); + } + + + void IX11InputMethodControl.SetWindowActive(bool active) + { + _windowActive = active; + UpdateActive(); + } + + void ITextInputMethodImpl.SetActive(bool active) + { + _controlActive = active; + UpdateActive(); + } + + bool IX11InputMethodControl.IsEnabled => IsConnected && _imeActive == true; + + async ValueTask IX11InputMethodControl.HandleEventAsync(RawKeyEventArgs args, int keyVal, int keyCode) + { + try + { + return await _queue.EnqueueAsync(async () => await HandleKeyCore(args, keyVal, keyCode)); + } + // Disconnected + catch (OperationCanceledException) + { + return false; + } + // Error, disconnect + catch (Exception e) + { + await QueueOnError(e); + return false; + } + } + + private Action _onCommit; + event Action IX11InputMethodControl.Commit + { + add => _onCommit += value; + remove => _onCommit -= value; + } + + protected void FireCommit(string s) => _onCommit?.Invoke(s); + + private Action _onForward; + event Action IX11InputMethodControl.ForwardKey + { + add => _onForward += value; + remove => _onForward -= value; + } + + protected void FireForward(X11InputMethodForwardedKey k) => _onForward?.Invoke(k); + + void UpdateCursorRect() + { + _queue.Enqueue(async () => + { + if(!IsConnected) + return; + var cursorRect = PixelRect.FromRect(_logicalRect, _scaling); + cursorRect = cursorRect.Translate(_windowPosition); + if (cursorRect != _lastReportedRect) + { + _lastReportedRect = cursorRect; + await SetCursorRectCore(cursorRect); + } + }); + } + + void IX11InputMethodControl.UpdateWindowInfo(PixelPoint position, double scaling) + { + _windowPosition = position; + _scaling = scaling; + UpdateCursorRect(); + } + + void ITextInputMethodImpl.SetCursorRect(Rect rect) + { + _logicalRect = rect; + UpdateCursorRect(); + } + + public abstract void SetOptions(TextInputOptionsQueryEventArgs options); + + void ITextInputMethodImpl.Reset() + { + Reset(); + _queue.Enqueue(async () => + { + if (!IsConnected) + return; + await ResetContextCore(); + }); + } + } +} diff --git a/src/Avalonia.FreeDesktop/DBusIme/Fcitx/FcitxDBus.cs b/src/Avalonia.FreeDesktop/DBusIme/Fcitx/FcitxDBus.cs new file mode 100644 index 0000000000..7ce2339763 --- /dev/null +++ b/src/Avalonia.FreeDesktop/DBusIme/Fcitx/FcitxDBus.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; +using Tmds.DBus; + +[assembly: InternalsVisibleTo(Tmds.DBus.Connection.DynamicAssemblyName)] +namespace Avalonia.FreeDesktop.DBusIme.Fcitx +{ + [DBusInterface("org.fcitx.Fcitx.InputMethod")] + interface IFcitxInputMethod : IDBusObject + { + Task<(int icid, bool enable, uint keyval1, uint state1, uint keyval2, uint state2)> CreateICv3Async( + string Appname, int Pid); + } + + + [DBusInterface("org.fcitx.Fcitx.InputContext")] + interface IFcitxInputContext : IDBusObject + { + Task EnableICAsync(); + Task CloseICAsync(); + Task FocusInAsync(); + Task FocusOutAsync(); + Task ResetAsync(); + Task MouseEventAsync(int X); + Task SetCursorLocationAsync(int X, int Y); + Task SetCursorRectAsync(int X, int Y, int W, int H); + Task SetCapacityAsync(uint Caps); + Task SetSurroundingTextAsync(string Text, uint Cursor, uint Anchor); + Task SetSurroundingTextPositionAsync(uint Cursor, uint Anchor); + Task DestroyICAsync(); + Task ProcessKeyEventAsync(uint Keyval, uint Keycode, uint State, int Type, uint Time); + Task WatchEnableIMAsync(Action handler, Action onError = null); + Task WatchCloseIMAsync(Action handler, Action onError = null); + Task WatchCommitStringAsync(Action handler, Action onError = null); + Task WatchCurrentIMAsync(Action<(string name, string uniqueName, string langCode)> handler, Action onError = null); + Task WatchUpdatePreeditAsync(Action<(string str, int cursorpos)> handler, Action onError = null); + Task WatchUpdateFormattedPreeditAsync(Action<((string, int)[] str, int cursorpos)> handler, Action onError = null); + Task WatchUpdateClientSideUIAsync(Action<(string auxup, string auxdown, string preedit, string candidateword, string imname, int cursorpos)> handler, Action onError = null); + Task WatchForwardKeyAsync(Action<(uint keyval, uint state, int type)> handler, Action onError = null); + Task WatchDeleteSurroundingTextAsync(Action<(int offset, uint nchar)> handler, Action onError = null); + } + + [DBusInterface("org.fcitx.Fcitx.InputContext1")] + interface IFcitxInputContext1 : IDBusObject + { + Task FocusInAsync(); + Task FocusOutAsync(); + Task ResetAsync(); + Task SetCursorRectAsync(int X, int Y, int W, int H); + Task SetCapabilityAsync(ulong Caps); + Task SetSurroundingTextAsync(string Text, uint Cursor, uint Anchor); + Task SetSurroundingTextPositionAsync(uint Cursor, uint Anchor); + Task DestroyICAsync(); + Task ProcessKeyEventAsync(uint Keyval, uint Keycode, uint State, bool Type, uint Time); + Task WatchCommitStringAsync(Action handler, Action onError = null); + Task WatchCurrentIMAsync(Action<(string name, string uniqueName, string langCode)> handler, Action onError = null); + Task WatchUpdateFormattedPreeditAsync(Action<((string, int)[] str, int cursorpos)> handler, Action onError = null); + Task WatchForwardKeyAsync(Action<(uint keyval, uint state, bool type)> handler, Action onError = null); + Task WatchDeleteSurroundingTextAsync(Action<(int offset, uint nchar)> handler, Action onError = null); + } + + [DBusInterface("org.fcitx.Fcitx.InputMethod1")] + interface IFcitxInputMethod1 : IDBusObject + { + Task<(ObjectPath path, byte[] data)> CreateInputContextAsync((string, string)[] arg0); + } +} diff --git a/src/Avalonia.FreeDesktop/DBusIme/Fcitx/FcitxEnums.cs b/src/Avalonia.FreeDesktop/DBusIme/Fcitx/FcitxEnums.cs new file mode 100644 index 0000000000..6510a5877a --- /dev/null +++ b/src/Avalonia.FreeDesktop/DBusIme/Fcitx/FcitxEnums.cs @@ -0,0 +1,67 @@ +using System; + +namespace Avalonia.FreeDesktop.DBusIme.Fcitx +{ + enum FcitxKeyEventType + { + FCITX_PRESS_KEY, + FCITX_RELEASE_KEY + }; + + [Flags] + enum FcitxCapabilityFlags + { + CAPACITY_NONE = 0, + CAPACITY_CLIENT_SIDE_UI = (1 << 0), + CAPACITY_PREEDIT = (1 << 1), + CAPACITY_CLIENT_SIDE_CONTROL_STATE = (1 << 2), + CAPACITY_PASSWORD = (1 << 3), + CAPACITY_FORMATTED_PREEDIT = (1 << 4), + CAPACITY_CLIENT_UNFOCUS_COMMIT = (1 << 5), + CAPACITY_SURROUNDING_TEXT = (1 << 6), + CAPACITY_EMAIL = (1 << 7), + CAPACITY_DIGIT = (1 << 8), + CAPACITY_UPPERCASE = (1 << 9), + CAPACITY_LOWERCASE = (1 << 10), + CAPACITY_NOAUTOUPPERCASE = (1 << 11), + CAPACITY_URL = (1 << 12), + CAPACITY_DIALABLE = (1 << 13), + CAPACITY_NUMBER = (1 << 14), + CAPACITY_NO_ON_SCREEN_KEYBOARD = (1 << 15), + CAPACITY_SPELLCHECK = (1 << 16), + CAPACITY_NO_SPELLCHECK = (1 << 17), + CAPACITY_WORD_COMPLETION = (1 << 18), + CAPACITY_UPPERCASE_WORDS = (1 << 19), + CAPACITY_UPPERCASE_SENTENCES = (1 << 20), + CAPACITY_ALPHA = (1 << 21), + CAPACITY_NAME = (1 << 22), + CAPACITY_GET_IM_INFO_ON_FOCUS = (1 << 23), + CAPACITY_RELATIVE_CURSOR_RECT = (1 << 24), + }; + + [Flags] + enum FcitxKeyState + { + FcitxKeyState_None = 0, + FcitxKeyState_Shift = 1 << 0, + FcitxKeyState_CapsLock = 1 << 1, + FcitxKeyState_Ctrl = 1 << 2, + FcitxKeyState_Alt = 1 << 3, + FcitxKeyState_Alt_Shift = FcitxKeyState_Alt | FcitxKeyState_Shift, + FcitxKeyState_Ctrl_Shift = FcitxKeyState_Ctrl | FcitxKeyState_Shift, + FcitxKeyState_Ctrl_Alt = FcitxKeyState_Ctrl | FcitxKeyState_Alt, + + FcitxKeyState_Ctrl_Alt_Shift = + FcitxKeyState_Ctrl | FcitxKeyState_Alt | FcitxKeyState_Shift, + FcitxKeyState_NumLock = 1 << 4, + FcitxKeyState_Super = 1 << 6, + FcitxKeyState_ScrollLock = 1 << 7, + FcitxKeyState_MousePressed = 1 << 8, + FcitxKeyState_HandledMask = 1 << 24, + FcitxKeyState_IgnoredMask = 1 << 25, + FcitxKeyState_Super2 = 1 << 26, + FcitxKeyState_Hyper = 1 << 27, + FcitxKeyState_Meta = 1 << 28, + FcitxKeyState_UsedMask = 0x5c001fff + }; +} diff --git a/src/Avalonia.FreeDesktop/DBusIme/Fcitx/FcitxICWrapper.cs b/src/Avalonia.FreeDesktop/DBusIme/Fcitx/FcitxICWrapper.cs new file mode 100644 index 0000000000..a03ea213aa --- /dev/null +++ b/src/Avalonia.FreeDesktop/DBusIme/Fcitx/FcitxICWrapper.cs @@ -0,0 +1,51 @@ +using System; +using System.Threading.Tasks; + +namespace Avalonia.FreeDesktop.DBusIme.Fcitx +{ + internal class FcitxICWrapper + { + private readonly IFcitxInputContext1 _modern; + private readonly IFcitxInputContext _old; + + public FcitxICWrapper(IFcitxInputContext old) + { + _old = old; + } + + public FcitxICWrapper(IFcitxInputContext1 modern) + { + _modern = modern; + } + + public Task FocusInAsync() => _old?.FocusInAsync() ?? _modern.FocusInAsync(); + + public Task FocusOutAsync() => _old?.FocusOutAsync() ?? _modern.FocusOutAsync(); + + public Task ResetAsync() => _old?.ResetAsync() ?? _modern.ResetAsync(); + + public Task SetCursorRectAsync(int x, int y, int w, int h) => + _old?.SetCursorRectAsync(x, y, w, h) ?? _modern.SetCursorRectAsync(x, y, w, h); + public Task DestroyICAsync() => _old?.DestroyICAsync() ?? _modern.DestroyICAsync(); + + public async Task ProcessKeyEventAsync(uint keyVal, uint keyCode, uint state, int type, uint time) + { + if(_old!=null) + return await _old.ProcessKeyEventAsync(keyVal, keyCode, state, type, time) != 0; + return await _modern.ProcessKeyEventAsync(keyVal, keyCode, state, type > 0, time); + } + + public Task WatchCommitStringAsync(Action handler) => + _old?.WatchCommitStringAsync(handler) ?? _modern.WatchCommitStringAsync(handler); + + public Task WatchForwardKeyAsync(Action<(uint keyval, uint state, int type)> handler) + { + return _old?.WatchForwardKeyAsync(handler) + ?? _modern.WatchForwardKeyAsync(ev => + handler((ev.keyval, ev.state, ev.type ? 1 : 0))); + } + + public Task SetCapacityAsync(uint flags) => + _old?.SetCapacityAsync(flags) ?? _modern.SetCapabilityAsync(flags); + } +} diff --git a/src/Avalonia.FreeDesktop/DBusIme/Fcitx/FcitxX11TextInputMethod.cs b/src/Avalonia.FreeDesktop/DBusIme/Fcitx/FcitxX11TextInputMethod.cs new file mode 100644 index 0000000000..8239b3f35d --- /dev/null +++ b/src/Avalonia.FreeDesktop/DBusIme/Fcitx/FcitxX11TextInputMethod.cs @@ -0,0 +1,149 @@ +using System; +using System.Diagnostics; +using System.Reactive.Concurrency; +using System.Reflection; +using System.Threading.Tasks; +using Avalonia.Input; +using Avalonia.Input.Raw; +using Avalonia.Input.TextInput; +using Tmds.DBus; + +namespace Avalonia.FreeDesktop.DBusIme.Fcitx +{ + internal class FcitxX11TextInputMethod : DBusTextInputMethodBase + { + private FcitxICWrapper _context; + private FcitxCapabilityFlags? _lastReportedFlags; + + public FcitxX11TextInputMethod(Connection connection) : base(connection, + "org.fcitx.Fcitx", + "org.freedesktop.portal.Fcitx" + ) + { + + } + + protected override async Task Connect(string name) + { + if (name == "org.fcitx.Fcitx") + { + var method = Connection.CreateProxy(name, "/inputmethod"); + var resp = await method.CreateICv3Async(GetAppName(), + Process.GetCurrentProcess().Id); + + var proxy = Connection.CreateProxy(name, + "/inputcontext_" + resp.icid); + + _context = new FcitxICWrapper(proxy); + } + else + { + var method = Connection.CreateProxy(name, "/inputmethod"); + var resp = await method.CreateInputContextAsync(new[] { ("appName", GetAppName()) }); + var proxy = Connection.CreateProxy(name, resp.path); + _context = new FcitxICWrapper(proxy); + } + + AddDisposable(await _context.WatchCommitStringAsync(OnCommitString)); + AddDisposable(await _context.WatchForwardKeyAsync(OnForward)); + return true; + } + + protected override Task Disconnect() => _context.DestroyICAsync(); + + protected override void OnDisconnected() => _context = null; + + protected override void Reset() + { + _lastReportedFlags = null; + base.Reset(); + } + + protected override Task SetCursorRectCore(PixelRect cursorRect) => + _context.SetCursorRectAsync(cursorRect.X, cursorRect.Y, Math.Max(1, cursorRect.Width), + Math.Max(1, cursorRect.Height)); + + protected override Task SetActiveCore(bool active) + { + if (active) + return _context.FocusInAsync(); + else + return _context.FocusOutAsync(); + } + + protected override Task ResetContextCore() => _context.ResetAsync(); + + protected override async Task HandleKeyCore(RawKeyEventArgs args, int keyVal, int keyCode) + { + FcitxKeyState state = default; + if (args.Modifiers.HasFlagCustom(RawInputModifiers.Control)) + state |= FcitxKeyState.FcitxKeyState_Ctrl; + if (args.Modifiers.HasFlagCustom(RawInputModifiers.Alt)) + state |= FcitxKeyState.FcitxKeyState_Alt; + if (args.Modifiers.HasFlagCustom(RawInputModifiers.Shift)) + state |= FcitxKeyState.FcitxKeyState_Shift; + if (args.Modifiers.HasFlagCustom(RawInputModifiers.Meta)) + state |= FcitxKeyState.FcitxKeyState_Super; + + var type = args.Type == RawKeyEventType.KeyDown ? + FcitxKeyEventType.FCITX_PRESS_KEY : + FcitxKeyEventType.FCITX_RELEASE_KEY; + + return await _context.ProcessKeyEventAsync((uint)keyVal, (uint)keyCode, (uint)state, (int)type, + (uint)args.Timestamp).ConfigureAwait(false); + } + + public override void SetOptions(TextInputOptionsQueryEventArgs options) => + Enqueue(async () => + { + if(_context == null) + return; + FcitxCapabilityFlags flags = default; + if (options.Lowercase) + flags |= FcitxCapabilityFlags.CAPACITY_LOWERCASE; + if (options.Uppercase) + flags |= FcitxCapabilityFlags.CAPACITY_UPPERCASE; + if (!options.AutoCapitalization) + flags |= FcitxCapabilityFlags.CAPACITY_NOAUTOUPPERCASE; + if (options.ContentType == TextInputContentType.Email) + flags |= FcitxCapabilityFlags.CAPACITY_EMAIL; + else if (options.ContentType == TextInputContentType.Number) + flags |= FcitxCapabilityFlags.CAPACITY_NUMBER; + else if (options.ContentType == TextInputContentType.Password) + flags |= FcitxCapabilityFlags.CAPACITY_PASSWORD; + else if (options.ContentType == TextInputContentType.Phone) + flags |= FcitxCapabilityFlags.CAPACITY_DIALABLE; + else if (options.ContentType == TextInputContentType.Url) + flags |= FcitxCapabilityFlags.CAPACITY_URL; + if (flags != _lastReportedFlags) + { + _lastReportedFlags = flags; + await _context.SetCapacityAsync((uint)flags); + } + }); + + private void OnForward((uint keyval, uint state, int type) ev) + { + var state = (FcitxKeyState)ev.state; + KeyModifiers mods = default; + if (state.HasFlagCustom(FcitxKeyState.FcitxKeyState_Ctrl)) + mods |= KeyModifiers.Control; + if (state.HasFlagCustom(FcitxKeyState.FcitxKeyState_Alt)) + mods |= KeyModifiers.Alt; + if (state.HasFlagCustom(FcitxKeyState.FcitxKeyState_Shift)) + mods |= KeyModifiers.Shift; + if (state.HasFlagCustom(FcitxKeyState.FcitxKeyState_Super)) + mods |= KeyModifiers.Meta; + FireForward(new X11InputMethodForwardedKey + { + Modifiers = mods, + KeyVal = (int)ev.keyval, + Type = ev.type == (int)FcitxKeyEventType.FCITX_PRESS_KEY ? + RawKeyEventType.KeyDown : + RawKeyEventType.KeyUp + }); + } + + private void OnCommitString(string s) => FireCommit(s); + } +} diff --git a/src/Avalonia.FreeDesktop/DBusIme/IBus/IBusDBus.cs b/src/Avalonia.FreeDesktop/DBusIme/IBus/IBusDBus.cs new file mode 100644 index 0000000000..26c0d249f3 --- /dev/null +++ b/src/Avalonia.FreeDesktop/DBusIme/IBus/IBusDBus.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Threading.Tasks; +using Tmds.DBus; + +[assembly: InternalsVisibleTo(Connection.DynamicAssemblyName)] +namespace Avalonia.FreeDesktop.DBusIme.IBus +{ + [DBusInterface("org.freedesktop.IBus.InputContext")] + interface IIBusInputContext : IDBusObject + { + Task ProcessKeyEventAsync(uint Keyval, uint Keycode, uint State); + Task SetCursorLocationAsync(int X, int Y, int W, int H); + Task FocusInAsync(); + Task FocusOutAsync(); + Task ResetAsync(); + Task SetCapabilitiesAsync(uint Caps); + Task PropertyActivateAsync(string Name, int State); + Task SetEngineAsync(string Name); + Task GetEngineAsync(); + Task DestroyAsync(); + Task SetSurroundingTextAsync(object Text, uint CursorPos, uint AnchorPos); + Task WatchCommitTextAsync(Action cb, Action onError = null); + Task WatchForwardKeyEventAsync(Action<(uint keyval, uint keycode, uint state)> handler, Action onError = null); + Task WatchRequireSurroundingTextAsync(Action handler, Action onError = null); + Task WatchDeleteSurroundingTextAsync(Action<(int offset, uint nchars)> handler, Action onError = null); + Task WatchUpdatePreeditTextAsync(Action<(object text, uint cursorPos, bool visible)> handler, Action onError = null); + Task WatchShowPreeditTextAsync(Action handler, Action onError = null); + Task WatchHidePreeditTextAsync(Action handler, Action onError = null); + Task WatchUpdateAuxiliaryTextAsync(Action<(object text, bool visible)> handler, Action onError = null); + Task WatchShowAuxiliaryTextAsync(Action handler, Action onError = null); + Task WatchHideAuxiliaryTextAsync(Action handler, Action onError = null); + Task WatchUpdateLookupTableAsync(Action<(object table, bool visible)> handler, Action onError = null); + Task WatchShowLookupTableAsync(Action handler, Action onError = null); + Task WatchHideLookupTableAsync(Action handler, Action onError = null); + Task WatchPageUpLookupTableAsync(Action handler, Action onError = null); + Task WatchPageDownLookupTableAsync(Action handler, Action onError = null); + Task WatchCursorUpLookupTableAsync(Action handler, Action onError = null); + Task WatchCursorDownLookupTableAsync(Action handler, Action onError = null); + Task WatchRegisterPropertiesAsync(Action handler, Action onError = null); + Task WatchUpdatePropertyAsync(Action handler, Action onError = null); + } + + + [DBusInterface("org.freedesktop.IBus.Portal")] + interface IIBusPortal : IDBusObject + { + Task CreateInputContextAsync(string Name); + } +} diff --git a/src/Avalonia.FreeDesktop/DBusIme/IBus/IBusEnums.cs b/src/Avalonia.FreeDesktop/DBusIme/IBus/IBusEnums.cs new file mode 100644 index 0000000000..3070f51a8e --- /dev/null +++ b/src/Avalonia.FreeDesktop/DBusIme/IBus/IBusEnums.cs @@ -0,0 +1,45 @@ +using System; + +namespace Avalonia.FreeDesktop.DBusIme.IBus +{ + [Flags] + internal enum IBusModifierMask + { + ShiftMask = 1 << 0, + LockMask = 1 << 1, + ControlMask = 1 << 2, + Mod1Mask = 1 << 3, + Mod2Mask = 1 << 4, + Mod3Mask = 1 << 5, + Mod4Mask = 1 << 6, + Mod5Mask = 1 << 7, + Button1Mask = 1 << 8, + Button2Mask = 1 << 9, + Button3Mask = 1 << 10, + Button4Mask = 1 << 11, + Button5Mask = 1 << 12, + + HandledMask = 1 << 24, + ForwardMask = 1 << 25, + IgnoredMask = ForwardMask, + + SuperMask = 1 << 26, + HyperMask = 1 << 27, + MetaMask = 1 << 28, + + ReleaseMask = 1 << 30, + + ModifierMask = 0x5c001fff + } + + [Flags] + internal enum IBusCapability + { + CapPreeditText = 1 << 0, + CapAuxiliaryText = 1 << 1, + CapLookupTable = 1 << 2, + CapFocus = 1 << 3, + CapProperty = 1 << 4, + CapSurroundingText = 1 << 5, + } +} diff --git a/src/Avalonia.FreeDesktop/DBusIme/IBus/IBusX11TextInputMethod.cs b/src/Avalonia.FreeDesktop/DBusIme/IBus/IBusX11TextInputMethod.cs new file mode 100644 index 0000000000..74f54267d0 --- /dev/null +++ b/src/Avalonia.FreeDesktop/DBusIme/IBus/IBusX11TextInputMethod.cs @@ -0,0 +1,105 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Avalonia.Input; +using Avalonia.Input.Raw; +using Avalonia.Input.TextInput; +using Tmds.DBus; + +namespace Avalonia.FreeDesktop.DBusIme.IBus +{ + internal class IBusX11TextInputMethod : DBusTextInputMethodBase + { + private IIBusInputContext _context; + + public IBusX11TextInputMethod(Connection connection) : base(connection, + "org.freedesktop.portal.IBus") + { + } + + protected override async Task Connect(string name) + { + var path = + await Connection.CreateProxy(name, "/org/freedesktop/IBus") + .CreateInputContextAsync(GetAppName()); + + _context = Connection.CreateProxy(name, path); + AddDisposable(await _context.WatchCommitTextAsync(OnCommitText)); + AddDisposable(await _context.WatchForwardKeyEventAsync(OnForwardKey)); + Enqueue(() => _context.SetCapabilitiesAsync((uint)IBusCapability.CapFocus)); + return true; + } + + private void OnForwardKey((uint keyval, uint keycode, uint state) k) + { + var state = (IBusModifierMask)k.state; + KeyModifiers mods = default; + if (state.HasFlagCustom(IBusModifierMask.ControlMask)) + mods |= KeyModifiers.Control; + if (state.HasFlagCustom(IBusModifierMask.Mod1Mask)) + mods |= KeyModifiers.Alt; + if (state.HasFlagCustom(IBusModifierMask.ShiftMask)) + mods |= KeyModifiers.Shift; + if (state.HasFlagCustom(IBusModifierMask.Mod4Mask)) + mods |= KeyModifiers.Meta; + FireForward(new X11InputMethodForwardedKey + { + KeyVal = (int)k.keyval, + Type = state.HasFlagCustom(IBusModifierMask.ReleaseMask) ? RawKeyEventType.KeyUp : RawKeyEventType.KeyDown, + Modifiers = mods + }); + } + + + private void OnCommitText(object wtf) + { + // Hello darkness, my old friend + var prop = wtf.GetType().GetField("Item3"); + if (prop != null) + { + var text = (string)prop.GetValue(wtf); + if (!string.IsNullOrEmpty(text)) + FireCommit(text); + } + } + + protected override Task Disconnect() => _context.DestroyAsync(); + + protected override void OnDisconnected() + { + _context = null; + base.OnDisconnected(); + } + + protected override Task SetCursorRectCore(PixelRect rect) + => _context.SetCursorLocationAsync(rect.X, rect.Y, rect.Width, rect.Height); + + protected override Task SetActiveCore(bool active) + => active ? _context.FocusInAsync() : _context.FocusOutAsync(); + + protected override Task ResetContextCore() + => _context.ResetAsync(); + + protected override Task HandleKeyCore(RawKeyEventArgs args, int keyVal, int keyCode) + { + IBusModifierMask state = default; + if (args.Modifiers.HasFlagCustom(RawInputModifiers.Control)) + state |= IBusModifierMask.ControlMask; + if (args.Modifiers.HasFlagCustom(RawInputModifiers.Alt)) + state |= IBusModifierMask.Mod1Mask; + if (args.Modifiers.HasFlagCustom(RawInputModifiers.Shift)) + state |= IBusModifierMask.ShiftMask; + if (args.Modifiers.HasFlagCustom(RawInputModifiers.Meta)) + state |= IBusModifierMask.Mod4Mask; + + if (args.Type == RawKeyEventType.KeyUp) + state |= IBusModifierMask.ReleaseMask; + + return _context.ProcessKeyEventAsync((uint)keyVal, (uint)keyCode, (uint)state); + } + + public override void SetOptions(TextInputOptionsQueryEventArgs options) + { + // No-op, because ibus + } + } +} diff --git a/src/Avalonia.FreeDesktop/DBusIme/X11DBusImeHelper.cs b/src/Avalonia.FreeDesktop/DBusIme/X11DBusImeHelper.cs new file mode 100644 index 0000000000..7f71ecf0ff --- /dev/null +++ b/src/Avalonia.FreeDesktop/DBusIme/X11DBusImeHelper.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using Avalonia.FreeDesktop.DBusIme.Fcitx; +using Avalonia.FreeDesktop.DBusIme.IBus; +using Tmds.DBus; + +namespace Avalonia.FreeDesktop.DBusIme +{ + public class X11DBusImeHelper + { + private static readonly Dictionary> KnownMethods = + new Dictionary> + { + ["fcitx"] = conn => + new DBusInputMethodFactory(_ => new FcitxX11TextInputMethod(conn)), + ["ibus"] = conn => + new DBusInputMethodFactory(_ => new IBusX11TextInputMethod(conn)) + }; + + static Func DetectInputMethod() + { + foreach (var name in new[] { "AVALONIA_IM_MODULE", "GTK_IM_MODULE", "QT_IM_MODULE" }) + { + var value = Environment.GetEnvironmentVariable(name); + + if (value == "none") + return null; + + if (value != null && KnownMethods.TryGetValue(value, out var factory)) + return factory; + } + + return null; + } + + public static bool DetectAndRegister() + { + var factory = DetectInputMethod(); + if (factory != null) + { + var conn = DBusHelper.TryInitialize(); + if (conn != null) + { + AvaloniaLocator.CurrentMutable.Bind().ToConstant(factory(conn)); + return true; + } + } + + return false; + + } + } +} diff --git a/src/Avalonia.FreeDesktop/IX11InputMethod.cs b/src/Avalonia.FreeDesktop/IX11InputMethod.cs new file mode 100644 index 0000000000..5d91118978 --- /dev/null +++ b/src/Avalonia.FreeDesktop/IX11InputMethod.cs @@ -0,0 +1,31 @@ +using System; +using System.Threading.Tasks; +using Avalonia.Input; +using Avalonia.Input.Raw; +using Avalonia.Input.TextInput; + +namespace Avalonia.FreeDesktop +{ + public interface IX11InputMethodFactory + { + (ITextInputMethodImpl method, IX11InputMethodControl control) CreateClient(IntPtr xid); + } + + public struct X11InputMethodForwardedKey + { + public int KeyVal { get; set; } + public KeyModifiers Modifiers { get; set; } + public RawKeyEventType Type { get; set; } + } + + public interface IX11InputMethodControl : IDisposable + { + void SetWindowActive(bool active); + bool IsEnabled { get; } + ValueTask HandleEventAsync(RawKeyEventArgs args, int keyVal, int keyCode); + event Action Commit; + event Action ForwardKey; + + void UpdateWindowInfo(PixelPoint position, double scaling); + } +} diff --git a/src/Avalonia.Headless/HeadlessWindowImpl.cs b/src/Avalonia.Headless/HeadlessWindowImpl.cs index 2c52438743..af522f3e36 100644 --- a/src/Avalonia.Headless/HeadlessWindowImpl.cs +++ b/src/Avalonia.Headless/HeadlessWindowImpl.cs @@ -75,9 +75,10 @@ namespace Avalonia.Headless public Action Closed { get; set; } public IMouseDevice MouseDevice { get; } - public void Show() + public void Show(bool activate) { - Dispatcher.UIThread.Post(() => Activated?.Invoke(), DispatcherPriority.Input); + if (activate) + Dispatcher.UIThread.Post(() => Activated?.Invoke(), DispatcherPriority.Input); } public void Hide() @@ -148,7 +149,7 @@ namespace Avalonia.Headless public void ShowDialog(IWindowImpl parent) { - Show(); + Show(true); } public void SetSystemDecorations(bool enabled) diff --git a/src/Avalonia.Input/ICommandSource.cs b/src/Avalonia.Input/ICommandSource.cs new file mode 100644 index 0000000000..ba2e8eed4e --- /dev/null +++ b/src/Avalonia.Input/ICommandSource.cs @@ -0,0 +1,36 @@ +using System.Windows.Input; + +namespace Avalonia.Input +{ + /// + /// An interface for classes that know how to invoke a Command. + /// + public interface ICommandSource + { + /// + /// The command that will be executed when the class is "invoked." + /// Classes that implement this interface should enable or disable based on the command's CanExecute return value. + /// The property may be implemented as read-write if desired. + /// + ICommand Command { get; } + + /// + /// The parameter that will be passed to the command when executing the command. + /// The property may be implemented as read-write if desired. + /// + object CommandParameter { get; } + + + /// + /// Bor the bheavior CanExecuteChanged + /// + /// + /// + void CanExecuteChanged(object sender, System.EventArgs e); + + /// + /// Gets a value indicating whether this control and all its parents are enabled. + /// + bool IsEffectivelyEnabled { get; } + } +} diff --git a/src/Avalonia.Input/IInputElement.cs b/src/Avalonia.Input/IInputElement.cs index 12fec82368..7aa9c32bca 100644 --- a/src/Avalonia.Input/IInputElement.cs +++ b/src/Avalonia.Input/IInputElement.cs @@ -89,6 +89,11 @@ namespace Avalonia.Input /// value of this control and its parent controls. /// bool IsEffectivelyEnabled { get; } + + /// + /// Gets a value indicating whether keyboard focus is anywhere within the element or its visual tree child elements. + /// + bool IsKeyboardFocusWithin { get; } /// /// Gets a value indicating whether the control is focused. diff --git a/src/Avalonia.Input/InputElement.cs b/src/Avalonia.Input/InputElement.cs index 9ace7fd92d..f3996cea76 100644 --- a/src/Avalonia.Input/InputElement.cs +++ b/src/Avalonia.Input/InputElement.cs @@ -5,6 +5,7 @@ using Avalonia.Controls; using Avalonia.Controls.Metadata; using Avalonia.Data; using Avalonia.Input.GestureRecognizers; +using Avalonia.Input.TextInput; using Avalonia.Interactivity; using Avalonia.VisualTree; @@ -42,6 +43,14 @@ namespace Avalonia.Input public static readonly StyledProperty CursorProperty = AvaloniaProperty.Register(nameof(Cursor), null, true); + /// + /// Defines the property. + /// + public static readonly DirectProperty IsKeyboardFocusWithinProperty = + AvaloniaProperty.RegisterDirect( + nameof(IsKeyboardFocusWithin), + o => o.IsKeyboardFocusWithin); + /// /// Defines the property. /// @@ -95,6 +104,22 @@ namespace Avalonia.Input RoutedEvent.Register( "TextInput", RoutingStrategies.Tunnel | RoutingStrategies.Bubble); + + /// + /// Defines the event. + /// + public static readonly RoutedEvent TextInputMethodClientRequestedEvent = + RoutedEvent.Register( + "TextInputMethodClientRequested", + RoutingStrategies.Tunnel | RoutingStrategies.Bubble); + + /// + /// Defines the event. + /// + public static readonly RoutedEvent TextInputOptionsQueryEvent = + RoutedEvent.Register( + "TextInputOptionsQuery", + RoutingStrategies.Tunnel | RoutingStrategies.Bubble); /// /// Defines the event. @@ -160,6 +185,7 @@ namespace Avalonia.Input private bool _isEffectivelyEnabled = true; private bool _isFocused; + private bool _isKeyboardFocusWithin; private bool _isFocusVisible; private bool _isPointerOver; private GestureRecognizerCollection? _gestureRecognizers; @@ -234,6 +260,24 @@ namespace Avalonia.Input add { AddHandler(TextInputEvent, value); } remove { RemoveHandler(TextInputEvent, value); } } + + /// + /// Occurs when an input element gains input focus and input method is looking for the corresponding client + /// + public event EventHandler TextInputMethodClientRequested + { + add { AddHandler(TextInputMethodClientRequestedEvent, value); } + remove { RemoveHandler(TextInputMethodClientRequestedEvent, value); } + } + + /// + /// Occurs when an input element gains input focus and input method is asking for required content options + /// + public event EventHandler TextInputOptionsQuery + { + add { AddHandler(TextInputOptionsQueryEvent, value); } + remove { RemoveHandler(TextInputOptionsQueryEvent, value); } + } /// /// Occurs when the pointer enters the control. @@ -343,6 +387,15 @@ namespace Avalonia.Input get { return GetValue(CursorProperty); } set { SetValue(CursorProperty, value); } } + + /// + /// Gets a value indicating whether keyboard focus is anywhere within the element or its visual tree child elements. + /// + public bool IsKeyboardFocusWithin + { + get => _isKeyboardFocusWithin; + internal set => SetAndRaise(IsKeyboardFocusWithinProperty, ref _isKeyboardFocusWithin, value); + } /// /// Gets a value indicating whether the control is focused. @@ -544,6 +597,10 @@ namespace Avalonia.Input { UpdatePseudoClasses(null, change.NewValue.GetValueOrDefault()); } + else if (change.Property == IsKeyboardFocusWithinProperty) + { + PseudoClasses.Set(":focus-within", _isKeyboardFocusWithin); + } } /// diff --git a/src/Avalonia.Input/KeyboardDevice.cs b/src/Avalonia.Input/KeyboardDevice.cs index 187670a26b..5899824c29 100644 --- a/src/Avalonia.Input/KeyboardDevice.cs +++ b/src/Avalonia.Input/KeyboardDevice.cs @@ -1,6 +1,7 @@ using System.ComponentModel; using System.Runtime.CompilerServices; using Avalonia.Input.Raw; +using Avalonia.Input.TextInput; using Avalonia.Interactivity; using Avalonia.VisualTree; @@ -9,6 +10,7 @@ namespace Avalonia.Input public class KeyboardDevice : IKeyboardDevice, INotifyPropertyChanged { private IInputElement? _focusedElement; + private IInputRoot? _focusedRoot; public event PropertyChangedEventHandler? PropertyChanged; @@ -17,6 +19,10 @@ namespace Avalonia.Input public IInputManager InputManager => AvaloniaLocator.Current.GetService(); public IFocusManager FocusManager => AvaloniaLocator.Current.GetService(); + + // This should live in the FocusManager, but with the current outdated architecture + // the source of truth about the input focus is in KeyboardDevice + private readonly TextInputMethodManager _textInputManager = new TextInputMethodManager(); public IInputElement? FocusedElement { @@ -28,7 +34,113 @@ namespace Avalonia.Input private set { _focusedElement = value; + + if (_focusedElement != null && _focusedElement.IsAttachedToVisualTree) + { + _focusedRoot = _focusedElement.VisualRoot as IInputRoot; + } + else + { + _focusedRoot = null; + } + RaisePropertyChanged(); + _textInputManager.SetFocusedElement(value); + } + } + + private void ClearFocusWithinAncestors(IInputElement? element) + { + var el = element; + + while (el != null) + { + if (el is InputElement ie) + { + ie.IsKeyboardFocusWithin = false; + } + + el = (IInputElement)el.VisualParent; + } + } + + private void ClearFocusWithin(IInputElement element, bool clearRoot) + { + foreach (var visual in element.VisualChildren) + { + if (visual is IInputElement el && el.IsKeyboardFocusWithin) + { + ClearFocusWithin(el, true); + break; + } + } + + if (clearRoot) + { + if (element is InputElement ie) + { + ie.IsKeyboardFocusWithin = false; + } + } + } + + private void SetIsFocusWithin(IInputElement? oldElement, IInputElement? newElement) + { + if (newElement == null && oldElement != null) + { + ClearFocusWithinAncestors(oldElement); + return; + } + + IInputElement? branch = null; + + var el = newElement; + + while (el != null) + { + if (el.IsKeyboardFocusWithin) + { + branch = el; + break; + } + + el = el.VisualParent as IInputElement; + } + + el = oldElement; + + if (el != null && branch != null) + { + ClearFocusWithin(branch, false); + } + + el = newElement; + + while (el != null && el != branch) + { + if (el is InputElement ie) + { + ie.IsKeyboardFocusWithin = true; + } + + el = el.VisualParent as IInputElement; + } + } + + private void ClearChildrenFocusWithin(IInputElement element, bool clearRoot) + { + foreach (var visual in element.VisualChildren) + { + if (visual is IInputElement el && el.IsKeyboardFocusWithin) + { + ClearChildrenFocusWithin(el, true); + break; + } + } + + if (clearRoot && element is InputElement ie) + { + ie.IsKeyboardFocusWithin = false; } } @@ -40,6 +152,17 @@ namespace Avalonia.Input if (element != FocusedElement) { var interactive = FocusedElement as IInteractive; + + if (FocusedElement != null && + (!FocusedElement.IsAttachedToVisualTree || + _focusedRoot != element?.VisualRoot as IInputRoot) && + _focusedRoot != null) + { + ClearChildrenFocusWithin(_focusedRoot, true); + } + + SetIsFocusWithin(FocusedElement, element); + FocusedElement = element; interactive?.RaiseEvent(new RoutedEventArgs diff --git a/src/Avalonia.Input/MouseDevice.cs b/src/Avalonia.Input/MouseDevice.cs index cec5029c18..5c63546f5d 100644 --- a/src/Avalonia.Input/MouseDevice.cs +++ b/src/Avalonia.Input/MouseDevice.cs @@ -19,6 +19,7 @@ namespace Avalonia.Input private readonly Pointer _pointer; private bool _disposed; + private PixelPoint? _position; public MouseDevice(Pointer? pointer = null) { @@ -39,10 +40,11 @@ namespace Avalonia.Input /// /// Gets the mouse position, in screen coordinates. /// + [Obsolete("Use events instead")] public PixelPoint Position { - get; - protected set; + get => _position ?? new PixelPoint(-1, -1); + protected set => _position = value; } /// @@ -91,7 +93,16 @@ namespace Avalonia.Input public void SceneInvalidated(IInputRoot root, Rect rect) { - var clientPoint = root.PointToClient(Position); + // Pointer is outside of the target area + if (_position == null ) + { + if (root.PointerOverElement != null) + ClearPointerOver(this, 0, root, PointerPointProperties.None, KeyModifiers.None); + return; + } + + + var clientPoint = root.PointToClient(_position.Value); if (rect.Contains(clientPoint)) { @@ -132,7 +143,7 @@ namespace Avalonia.Input if(mouse._disposed) return; - Position = e.Root.PointToScreen(e.Position); + _position = e.Root.PointToScreen(e.Position); var props = CreateProperties(e); var keyModifiers = KeyModifiersUtils.ConvertToKey(e.InputModifiers); switch (e.Type) @@ -176,6 +187,7 @@ namespace Avalonia.Input device = device ?? throw new ArgumentNullException(nameof(device)); root = root ?? throw new ArgumentNullException(nameof(root)); + _position = null; ClearPointerOver(this, timestamp, root, properties, inputModifiers); } diff --git a/src/Avalonia.Input/NavigationDirection.cs b/src/Avalonia.Input/NavigationDirection.cs index 9b9af0b0a6..9bd6a8bb42 100644 --- a/src/Avalonia.Input/NavigationDirection.cs +++ b/src/Avalonia.Input/NavigationDirection.cs @@ -83,7 +83,7 @@ namespace Avalonia.Input /// public static bool IsDirectional(this NavigationDirection direction) { - return direction > NavigationDirection.Previous || + return direction > NavigationDirection.Previous && direction <= NavigationDirection.PageDown; } diff --git a/src/Avalonia.Input/TextInput/ITextInputMethodClient.cs b/src/Avalonia.Input/TextInput/ITextInputMethodClient.cs new file mode 100644 index 0000000000..d385f5b162 --- /dev/null +++ b/src/Avalonia.Input/TextInput/ITextInputMethodClient.cs @@ -0,0 +1,60 @@ +using System; +using Avalonia.VisualTree; + +namespace Avalonia.Input.TextInput +{ + public interface ITextInputMethodClient + { + /// + /// The cursor rectangle relative to the TextViewVisual + /// + Rect CursorRectangle { get; } + /// + /// Should be fired when cursor rectangle is changed inside the TextViewVisual + /// + event EventHandler CursorRectangleChanged; + /// + /// The visual that's showing the text + /// + IVisual TextViewVisual { get; } + /// + /// Should be fired when text-hosting visual is changed + /// + event EventHandler TextViewVisualChanged; + /// + /// Indicates if TextViewVisual is capable of displaying non-commited input on the cursor position + /// + bool SupportsPreedit { get; } + /// + /// Sets the non-commited input string + /// + void SetPreeditText(string text); + /// + /// Indicates if text input client is capable of providing the text around the cursor + /// + bool SupportsSurroundingText { get; } + /// + /// Returns the text around the cursor, usually the current paragraph, the cursor position inside that text and selection start position + /// + TextInputMethodSurroundingText SurroundingText { get; } + /// + /// Should be fired when surrounding text changed + /// + event EventHandler SurroundingTextChanged; + /// + /// Returns the text before the cursor. Must return a non-empty string if cursor is not at the beginning of the text entry + /// + string TextBeforeCursor { get; } + /// + /// Returns the text before the cursor. Must return a non-empty string if cursor is not at the end of the text entry + /// + string TextAfterCursor { get; } + } + + public struct TextInputMethodSurroundingText + { + public string Text { get; set; } + public int CursorOffset { get; set; } + public int AnchorOffset { get; set; } + } +} diff --git a/src/Avalonia.Input/TextInput/ITextInputMethodImpl.cs b/src/Avalonia.Input/TextInput/ITextInputMethodImpl.cs new file mode 100644 index 0000000000..0069314d28 --- /dev/null +++ b/src/Avalonia.Input/TextInput/ITextInputMethodImpl.cs @@ -0,0 +1,15 @@ +namespace Avalonia.Input.TextInput +{ + public interface ITextInputMethodImpl + { + void SetActive(bool active); + void SetCursorRect(Rect rect); + void SetOptions(TextInputOptionsQueryEventArgs options); + void Reset(); + } + + public interface ITextInputMethodRoot : IInputRoot + { + ITextInputMethodImpl InputMethod { get; } + } +} diff --git a/src/Avalonia.Input/TextInput/InputMethodManager.cs b/src/Avalonia.Input/TextInput/InputMethodManager.cs new file mode 100644 index 0000000000..207ba6096e --- /dev/null +++ b/src/Avalonia.Input/TextInput/InputMethodManager.cs @@ -0,0 +1,101 @@ +using System; +using Avalonia.VisualTree; + +namespace Avalonia.Input.TextInput +{ + internal class TextInputMethodManager + { + private ITextInputMethodImpl? _im; + private IInputElement? _focusedElement; + private ITextInputMethodClient? _client; + private readonly TransformTrackingHelper _transformTracker = new TransformTrackingHelper(); + + public TextInputMethodManager() => _transformTracker.MatrixChanged += UpdateCursorRect; + + private ITextInputMethodClient? Client + { + get => _client; + set + { + if(_client == value) + return; + if (_client != null) + { + _client.CursorRectangleChanged -= OnCursorRectangleChanged; + _client.TextViewVisualChanged -= OnTextViewVisualChanged; + } + + _client = value; + + if (_client != null) + { + _client.CursorRectangleChanged += OnCursorRectangleChanged; + _client.TextViewVisualChanged += OnTextViewVisualChanged; + var optionsQuery = new TextInputOptionsQueryEventArgs + { + RoutedEvent = InputElement.TextInputOptionsQueryEvent + }; + _focusedElement?.RaiseEvent(optionsQuery); + _im?.Reset(); + _im?.SetOptions(optionsQuery); + _transformTracker?.SetVisual(_client?.TextViewVisual); + UpdateCursorRect(); + _im?.SetActive(true); + } + else + { + _im?.SetActive(false); + _transformTracker.SetVisual(null); + } + } + } + + private void OnTextViewVisualChanged(object sender, EventArgs e) + => _transformTracker.SetVisual(_client?.TextViewVisual); + + private void UpdateCursorRect() + { + if (_im == null || _client == null || _focusedElement?.VisualRoot == null) + return; + var transform = _focusedElement.TransformToVisual(_focusedElement.VisualRoot); + if (transform == null) + _im.SetCursorRect(default); + else + _im.SetCursorRect(_client.CursorRectangle.TransformToAABB(transform.Value)); + } + + private void OnCursorRectangleChanged(object sender, EventArgs e) + { + if (sender == _client) + UpdateCursorRect(); + } + + public void SetFocusedElement(IInputElement? element) + { + if(_focusedElement == element) + return; + _focusedElement = element; + + var inputMethod = (element?.VisualRoot as ITextInputMethodRoot)?.InputMethod; + if(_im != inputMethod) + _im?.SetActive(false); + + _im = inputMethod; + + if (_focusedElement == null || _im == null) + { + Client = null; + _im?.SetActive(false); + return; + } + + var clientQuery = new TextInputMethodClientRequestedEventArgs + { + RoutedEvent = InputElement.TextInputMethodClientRequestedEvent + }; + + _focusedElement.RaiseEvent(clientQuery); + Client = clientQuery.Client; + } + } +} diff --git a/src/Avalonia.Input/TextInput/TextInputContentType.cs b/src/Avalonia.Input/TextInput/TextInputContentType.cs new file mode 100644 index 0000000000..5d73fc1552 --- /dev/null +++ b/src/Avalonia.Input/TextInput/TextInputContentType.cs @@ -0,0 +1,12 @@ +namespace Avalonia.Input.TextInput +{ + public enum TextInputContentType + { + Normal = 0, + Email = 1, + Phone = 2, + Number = 3, + Url = 4, + Password = 5 + } +} diff --git a/src/Avalonia.Input/TextInput/TextInputMethodClientRequestedEventArgs.cs b/src/Avalonia.Input/TextInput/TextInputMethodClientRequestedEventArgs.cs new file mode 100644 index 0000000000..bec43487d2 --- /dev/null +++ b/src/Avalonia.Input/TextInput/TextInputMethodClientRequestedEventArgs.cs @@ -0,0 +1,12 @@ +using Avalonia.Interactivity; + +namespace Avalonia.Input.TextInput +{ + public class TextInputMethodClientRequestedEventArgs : RoutedEventArgs + { + /// + /// Set this property to a valid text input client to enable input method interaction + /// + public ITextInputMethodClient? Client { get; set; } + } +} diff --git a/src/Avalonia.Input/TextInput/TextInputOptionsQueryEventArgs.cs b/src/Avalonia.Input/TextInput/TextInputOptionsQueryEventArgs.cs new file mode 100644 index 0000000000..924d0eb166 --- /dev/null +++ b/src/Avalonia.Input/TextInput/TextInputOptionsQueryEventArgs.cs @@ -0,0 +1,32 @@ +using Avalonia.Interactivity; + +namespace Avalonia.Input.TextInput +{ + public class TextInputOptionsQueryEventArgs : RoutedEventArgs + { + /// + /// The content type (mostly for determining the shape of the virtual keyboard) + /// + public TextInputContentType ContentType { get; set; } + /// + /// Text is multiline + /// + public bool Multiline { get; set; } + /// + /// Text is in lower case + /// + public bool Lowercase { get; set; } + /// + /// Text is in upper case + /// + public bool Uppercase { get; set; } + /// + /// Automatically capitalize letters at the start of the sentence + /// + public bool AutoCapitalization { get; set; } + /// + /// Text contains sensitive data like card numbers and should not be stored + /// + public bool IsSensitive { get; set; } + } +} diff --git a/src/Avalonia.Input/TextInput/TransformTrackingHelper.cs b/src/Avalonia.Input/TextInput/TransformTrackingHelper.cs new file mode 100644 index 0000000000..4211360a8f --- /dev/null +++ b/src/Avalonia.Input/TextInput/TransformTrackingHelper.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using Avalonia.Threading; +using Avalonia.VisualTree; + +namespace Avalonia.Input.TextInput +{ + class TransformTrackingHelper : IDisposable + { + private IVisual? _visual; + private bool _queuedForUpdate; + private readonly EventHandler _propertyChangedHandler; + private readonly List _propertyChangedSubscriptions = new List(); + + public TransformTrackingHelper() + { + _propertyChangedHandler = PropertyChangedHandler; + } + + public void SetVisual(IVisual? visual) + { + Dispose(); + _visual = visual; + if (visual != null) + { + visual.AttachedToVisualTree += OnAttachedToVisualTree; + visual.DetachedFromVisualTree -= OnDetachedFromVisualTree; + if (visual.IsAttachedToVisualTree) + SubscribeToParents(); + UpdateMatrix(); + } + } + + public Matrix? Matrix { get; private set; } + public event Action? MatrixChanged; + + public void Dispose() + { + if(_visual == null) + return; + UnsubscribeFromParents(); + _visual.AttachedToVisualTree -= OnAttachedToVisualTree; + _visual.DetachedFromVisualTree -= OnDetachedFromVisualTree; + _visual = null; + } + + private void SubscribeToParents() + { + var visual = _visual; + // ReSharper disable once ConditionIsAlwaysTrueOrFalse + // false positive + while (visual != null) + { + if (visual is Visual v) + { + v.PropertyChanged += _propertyChangedHandler; + _propertyChangedSubscriptions.Add(v); + } + + visual = visual.VisualParent; + } + } + + private void UnsubscribeFromParents() + { + foreach (var v in _propertyChangedSubscriptions) + v.PropertyChanged -= _propertyChangedHandler; + _propertyChangedSubscriptions.Clear(); + } + + void UpdateMatrix() + { + Matrix? matrix = null; + if (_visual != null && _visual.VisualRoot != null) + matrix = _visual.TransformToVisual(_visual.VisualRoot); + if (Matrix != matrix) + { + Matrix = matrix; + MatrixChanged?.Invoke(); + } + } + + private void OnAttachedToVisualTree(object sender, VisualTreeAttachmentEventArgs visualTreeAttachmentEventArgs) + { + SubscribeToParents(); + UpdateMatrix(); + } + + private void EnqueueForUpdate() + { + if(_queuedForUpdate) + return; + _queuedForUpdate = true; + Dispatcher.UIThread.Post(UpdateMatrix, DispatcherPriority.Render); + } + + private void PropertyChangedHandler(object sender, AvaloniaPropertyChangedEventArgs e) + { + if (e.IsEffectiveValueChange && e.Property == Visual.BoundsProperty) + EnqueueForUpdate(); + } + + private void OnDetachedFromVisualTree(object sender, VisualTreeAttachmentEventArgs visualTreeAttachmentEventArgs) + { + UnsubscribeFromParents(); + UpdateMatrix(); + } + } +} diff --git a/src/Avalonia.Layout/ElementManager.cs b/src/Avalonia.Layout/ElementManager.cs index 70805ba31c..bf5a45966b 100644 --- a/src/Avalonia.Layout/ElementManager.cs +++ b/src/Avalonia.Layout/ElementManager.cs @@ -129,7 +129,7 @@ namespace Avalonia.Layout { for (int i = 0; i < count; i++) { - // Clear from the edges so that ItemsRepeater can optimize on maintaining + // Clear from the edges so that ItemsRepeater can optimize on maintaining // realized indices without walking through all the children every time. int index = realizedIndex == 0 ? realizedIndex + i : (realizedIndex + count - 1) - i; var elementRef = _realizedElements[index]; @@ -212,7 +212,7 @@ namespace Avalonia.Layout public ILayoutable GetRealizedElement(int dataIndex) { return IsVirtualizingContext ? - GetAt(GetRealizedRangeIndexFromDataIndex(dataIndex)) : + GetAt(GetRealizedRangeIndexFromDataIndex(dataIndex)) : _context.GetOrCreateElementAt( dataIndex, ElementRealizationOptions.ForceCreate | ElementRealizationOptions.SuppressAutoRecycle); @@ -252,7 +252,6 @@ namespace Avalonia.Layout (orientation == ScrollOrientation.Vertical ? ScrollOrientation.Horizontal : ScrollOrientation.Vertical) : orientation; - var windowStart = effectiveOrientation == ScrollOrientation.Vertical ? window.Y : window.X; var windowEnd = effectiveOrientation == ScrollOrientation.Vertical ? window.Y + window.Height : window.X + window.Width; var firstElementStart = effectiveOrientation == ScrollOrientation.Vertical ? firstElementBounds.Y : firstElementBounds.X; @@ -273,53 +272,53 @@ namespace Avalonia.Layout switch (args.Action) { case NotifyCollectionChangedAction.Add: - { - OnItemsAdded(args.NewStartingIndex, args.NewItems.Count); - } - break; + { + OnItemsAdded(args.NewStartingIndex, args.NewItems.Count); + } + break; case NotifyCollectionChangedAction.Replace: - { - int oldSize = args.OldItems.Count; - int newSize = args.NewItems.Count; - int oldStartIndex = args.OldStartingIndex; - int newStartIndex = args.NewStartingIndex; - - if (oldSize == newSize && - oldStartIndex == newStartIndex && - IsDataIndexRealized(oldStartIndex) && - IsDataIndexRealized(oldStartIndex + oldSize -1)) { - // Straight up replace of n items within the realization window. - // Removing and adding might causes us to lose the anchor causing us - // to throw away all containers and start from scratch. - // Instead, we can just clear those items and set the element to - // null (sentinel) and let the next measure get new containers for them. - var startRealizedIndex = GetRealizedRangeIndexFromDataIndex(oldStartIndex); - for (int realizedIndex = startRealizedIndex; realizedIndex < startRealizedIndex + oldSize; realizedIndex++) + int oldSize = args.OldItems.Count; + int newSize = args.NewItems.Count; + int oldStartIndex = args.OldStartingIndex; + int newStartIndex = args.NewStartingIndex; + + if (oldSize == newSize && + oldStartIndex == newStartIndex && + IsDataIndexRealized(oldStartIndex) && + IsDataIndexRealized(oldStartIndex + oldSize - 1)) { - var elementRef = _realizedElements[realizedIndex]; - - if (elementRef != null) + // Straight up replace of n items within the realization window. + // Removing and adding might causes us to lose the anchor causing us + // to throw away all containers and start from scratch. + // Instead, we can just clear those items and set the element to + // null (sentinel) and let the next measure get new containers for them. + var startRealizedIndex = GetRealizedRangeIndexFromDataIndex(oldStartIndex); + for (int realizedIndex = startRealizedIndex; realizedIndex < startRealizedIndex + oldSize; realizedIndex++) { - _context.RecycleElement(elementRef); - _realizedElements[realizedIndex] = null; + var elementRef = _realizedElements[realizedIndex]; + + if (elementRef != null) + { + _context.RecycleElement(elementRef); + _realizedElements[realizedIndex] = null; + } } } + else + { + OnItemsRemoved(oldStartIndex, oldSize); + OnItemsAdded(newStartIndex, newSize); + } } - else - { - OnItemsRemoved(oldStartIndex, oldSize); - OnItemsAdded(newStartIndex, newSize); - } - } - break; + break; case NotifyCollectionChangedAction.Remove: - { - OnItemsRemoved(args.OldStartingIndex, args.OldItems.Count); - } - break; + { + OnItemsRemoved(args.OldStartingIndex, args.OldItems.Count); + } + break; case NotifyCollectionChangedAction.Reset: ClearRealizedRange(); @@ -376,7 +375,7 @@ namespace Avalonia.Layout int backCutoffIndex = realizedRangeSize; for (int i = 0; - i _firstRealizedDataIndex && + if (newStartingIndex >= _firstRealizedDataIndex && newStartingIndex <= lastRealizedDataIndex) { // Inserted within the realized range int insertRangeStartIndex = newStartingIndex - _firstRealizedDataIndex; for (int i = 0; i < count; i++) { - // Insert null (sentinel) here instead of an element, that way we dont + // Insert null (sentinel) here instead of an element, that way we dont // end up creating a lot of elements only to be thrown out in the next layout. int insertRangeIndex = insertRangeStartIndex + i; int dataIndex = newStartingIndex + i; diff --git a/src/Avalonia.Layout/LayoutContext.cs b/src/Avalonia.Layout/LayoutContext.cs index 45a8048ea2..dadce58c0c 100644 --- a/src/Avalonia.Layout/LayoutContext.cs +++ b/src/Avalonia.Layout/LayoutContext.cs @@ -14,7 +14,11 @@ namespace Avalonia.Layout /// /// Gets or sets an object that represents the state of a layout. /// - public object LayoutState { get; set; } + public object LayoutState + { + get => LayoutStateCore; + set => LayoutStateCore = value; + } /// /// Implements the behavior of in a derived or custom LayoutContext. diff --git a/src/Avalonia.Layout/Properties/AssemblyInfo.cs b/src/Avalonia.Layout/Properties/AssemblyInfo.cs index efcbf184b5..63afaa8e3e 100644 --- a/src/Avalonia.Layout/Properties/AssemblyInfo.cs +++ b/src/Avalonia.Layout/Properties/AssemblyInfo.cs @@ -1,7 +1,9 @@ using System.Runtime.CompilerServices; using Avalonia.Metadata; - +#if SIGNED_BUILD [assembly: InternalsVisibleTo("Avalonia.Layout.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] - +#else +[assembly: InternalsVisibleTo("Avalonia.Layout.UnitTests")] +#endif [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Layout")] diff --git a/src/Avalonia.MicroCom/Avalonia.MicroCom.csproj b/src/Avalonia.MicroCom/Avalonia.MicroCom.csproj new file mode 100644 index 0000000000..b796e173c4 --- /dev/null +++ b/src/Avalonia.MicroCom/Avalonia.MicroCom.csproj @@ -0,0 +1,16 @@ + + + netstandard2.0 + true + + + <_AvaloniaPatchComInterop>true + + + + false + all + + + + diff --git a/src/Avalonia.MicroCom/IMicroComExceptionCallback.cs b/src/Avalonia.MicroCom/IMicroComExceptionCallback.cs new file mode 100644 index 0000000000..08f20339ec --- /dev/null +++ b/src/Avalonia.MicroCom/IMicroComExceptionCallback.cs @@ -0,0 +1,9 @@ +using System; + +namespace Avalonia.MicroCom +{ + public interface IMicroComExceptionCallback + { + void RaiseException(Exception e); + } +} diff --git a/src/Avalonia.MicroCom/IMicroComShadowContainer.cs b/src/Avalonia.MicroCom/IMicroComShadowContainer.cs new file mode 100644 index 0000000000..a33d3a9811 --- /dev/null +++ b/src/Avalonia.MicroCom/IMicroComShadowContainer.cs @@ -0,0 +1,9 @@ +namespace Avalonia.MicroCom +{ + public interface IMicroComShadowContainer + { + MicroComShadow Shadow { get; set; } + void OnReferencedFromNative(); + void OnUnreferencedFromNative(); + } +} diff --git a/src/Avalonia.MicroCom/IUnknown.cs b/src/Avalonia.MicroCom/IUnknown.cs new file mode 100644 index 0000000000..0dc4106423 --- /dev/null +++ b/src/Avalonia.MicroCom/IUnknown.cs @@ -0,0 +1,8 @@ +using System; + +namespace Avalonia.MicroCom +{ + public interface IUnknown : IDisposable + { + } +} diff --git a/src/Avalonia.MicroCom/LocalInterop.cs b/src/Avalonia.MicroCom/LocalInterop.cs new file mode 100644 index 0000000000..785f4e03a5 --- /dev/null +++ b/src/Avalonia.MicroCom/LocalInterop.cs @@ -0,0 +1,17 @@ +using System; + +namespace Avalonia.MicroCom +{ + unsafe class LocalInterop + { + public static unsafe void CalliStdCallvoid(void* thisObject, void* methodPtr) + { + throw null; + } + + public static unsafe int CalliStdCallint(void* thisObject, Guid* guid, IntPtr* ppv, void* methodPtr) + { + throw null; + } + } +} diff --git a/src/Avalonia.MicroCom/MicroComProxyBase.cs b/src/Avalonia.MicroCom/MicroComProxyBase.cs new file mode 100644 index 0000000000..140af3e4ef --- /dev/null +++ b/src/Avalonia.MicroCom/MicroComProxyBase.cs @@ -0,0 +1,110 @@ +using System; +using System.Runtime.ConstrainedExecution; +using System.Runtime.InteropServices; +using System.Threading; + +namespace Avalonia.MicroCom +{ + public unsafe class MicroComProxyBase : CriticalFinalizerObject, IUnknown + { + private IntPtr _nativePointer; + private bool _ownsHandle; + private SynchronizationContext _synchronizationContext; + + public IntPtr NativePointer + { + get + { + if (_nativePointer == IntPtr.Zero) + throw new ObjectDisposedException(this.GetType().FullName); + return _nativePointer; + } + } + + public void*** PPV => (void***)NativePointer; + + public MicroComProxyBase(IntPtr nativePointer, bool ownsHandle) + { + _nativePointer = nativePointer; + _ownsHandle = ownsHandle; + _synchronizationContext = SynchronizationContext.Current; + if(!_ownsHandle) + GC.SuppressFinalize(this); + } + + protected virtual int VTableSize => 3; + + public void AddRef() + { + LocalInterop.CalliStdCallvoid(PPV, (*PPV)[1]); + } + + public void Release() + { + LocalInterop.CalliStdCallvoid(PPV, (*PPV)[2]); + } + + public int QueryInterface(Guid guid, out IntPtr ppv) + { + IntPtr r = default; + var rv = LocalInterop.CalliStdCallint(PPV, &guid, &r, (*PPV)[0]); + ppv = r; + return rv; + } + + public T QueryInterface() where T : IUnknown + { + var guid = MicroComRuntime.GetGuidFor(typeof(T)); + var rv = QueryInterface(guid, out var ppv); + if (rv == 0) + return (T)MicroComRuntime.CreateProxyFor(typeof(T), ppv, true); + throw new COMException("QueryInterface failed", rv); + } + + public bool IsDisposed => _nativePointer == IntPtr.Zero; + + protected virtual void Dispose(bool disposing) + { + if(_nativePointer == null) + return; + if (_ownsHandle) + { + Release(); + _ownsHandle = false; + } + _nativePointer = IntPtr.Zero; + GC.SuppressFinalize(this); + } + + public void Dispose() => Dispose(true); + + public bool OwnsHandle => _ownsHandle; + + public void EnsureOwned() + { + if (!_ownsHandle) + { + GC.ReRegisterForFinalize(true); + AddRef(); + _ownsHandle = true; + } + } + + private static readonly SendOrPostCallback _disposeDelegate = DisposeOnContext; + + private static void DisposeOnContext(object state) + { + (state as MicroComProxyBase)?.Dispose(false); + } + + ~MicroComProxyBase() + { + if(!_ownsHandle) + return; + if (_synchronizationContext == null) + Dispose(); + else + _synchronizationContext.Post(_disposeDelegate, this); + } + } +} diff --git a/src/Avalonia.MicroCom/MicroComRuntime.cs b/src/Avalonia.MicroCom/MicroComRuntime.cs new file mode 100644 index 0000000000..85507674d2 --- /dev/null +++ b/src/Avalonia.MicroCom/MicroComRuntime.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections.Concurrent; +using System.Runtime.InteropServices; + +namespace Avalonia.MicroCom +{ + public static unsafe class MicroComRuntime + { + private static ConcurrentDictionary _vtables = new ConcurrentDictionary(); + + private static ConcurrentDictionary> _factories = + new ConcurrentDictionary>(); + private static ConcurrentDictionary _guids = new ConcurrentDictionary(); + private static ConcurrentDictionary _guidsToTypes = new ConcurrentDictionary(); + + static MicroComRuntime() + { + Register(typeof(IUnknown), new Guid("00000000-0000-0000-C000-000000000046"), + (ppv, owns) => new MicroComProxyBase(ppv, owns)); + RegisterVTable(typeof(IUnknown), MicroComVtblBase.Vtable); + } + + public static void RegisterVTable(Type t, IntPtr vtable) + { + _vtables[t] = vtable; + } + + public static void Register(Type t, Guid guid, Func proxyFactory) + { + _factories[t] = proxyFactory; + _guids[t] = guid; + _guidsToTypes[guid] = t; + } + + public static Guid GetGuidFor(Type type) => _guids[type]; + + public static T CreateProxyFor(void* pObject, bool ownsHandle) => (T)CreateProxyFor(typeof(T), new IntPtr(pObject), ownsHandle); + public static T CreateProxyFor(IntPtr pObject, bool ownsHandle) => (T)CreateProxyFor(typeof(T), pObject, ownsHandle); + + public static object CreateProxyFor(Type type, IntPtr pObject, bool ownsHandle) => _factories[type](pObject, ownsHandle); + + public static IntPtr GetNativeIntPtr(this T obj, bool owned = false) where T : IUnknown + => new IntPtr(GetNativePointer(obj, owned)); + public static void* GetNativePointer(T obj, bool owned = false) where T : IUnknown + { + if (obj == null) + return null; + if (obj is MicroComProxyBase proxy) + { + if(owned) + proxy.AddRef(); + return (void*)proxy.NativePointer; + } + + if (obj is IMicroComShadowContainer container) + { + container.Shadow ??= new MicroComShadow(container); + void* ptr = null; + var res = container.Shadow.GetOrCreateNativePointer(typeof(T), &ptr); + if (res != 0) + throw new COMException( + "Unable to create native callable wrapper for type " + typeof(T) + " for instance of type " + + obj.GetType(), + res); + if (owned) + container.Shadow.AddRef((Ccw*)ptr); + return ptr; + } + throw new ArgumentException("Unable to get a native pointer for " + obj); + } + + public static object GetObjectFromCcw(IntPtr ccw) + { + var ptr = (Ccw*)ccw; + var shadow = (MicroComShadow)GCHandle.FromIntPtr(ptr->GcShadowHandle).Target; + return shadow.Target; + } + + public static bool TryGetTypeForGuid(Guid guid, out Type t) => _guidsToTypes.TryGetValue(guid, out t); + + public static bool GetVtableFor(Type type, out IntPtr ptr) => _vtables.TryGetValue(type, out ptr); + + public static void UnhandledException(object target, Exception e) + { + if (target is IMicroComExceptionCallback cb) + { + try + { + cb.RaiseException(e); + } + catch + { + // We've tried + } + } + + } + + public static T CloneReference(this T iface) where T : IUnknown + { + var proxy = (MicroComProxyBase)(object)iface; + var ownedPointer = GetNativePointer(iface, true); + return CreateProxyFor(ownedPointer, true); + } + + public static T QueryInterface(this IUnknown unknown) where T : IUnknown + { + var proxy = (MicroComProxyBase)unknown; + return proxy.QueryInterface(); + } + + public static void UnsafeAddRef(this IUnknown unknown) + { + ((MicroComProxyBase)unknown).AddRef(); + } + + public static void UnsafeRelease(this IUnknown unknown) + { + ((MicroComProxyBase)unknown).Release(); + } + } +} diff --git a/src/Avalonia.MicroCom/MicroComShadow.cs b/src/Avalonia.MicroCom/MicroComShadow.cs new file mode 100644 index 0000000000..a6a0fd519e --- /dev/null +++ b/src/Avalonia.MicroCom/MicroComShadow.cs @@ -0,0 +1,171 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Threading; + +namespace Avalonia.MicroCom +{ + public unsafe class MicroComShadow : IDisposable + { + private readonly object _lock = new object(); + private readonly Dictionary _shadows = new Dictionary(); + private readonly Dictionary _backShadows = new Dictionary(); + private GCHandle? _handle; + private volatile int _refCount; + internal IMicroComShadowContainer Target { get; } + internal MicroComShadow(IMicroComShadowContainer target) + { + Target = target; + Target.Shadow = this; + } + + internal int QueryInterface(Ccw* ccw, Guid* guid, void** ppv) + { + if (MicroComRuntime.TryGetTypeForGuid(*guid, out var type)) + return QueryInterface(type, ppv); + else + return unchecked((int)0x80004002u); + } + + internal int QueryInterface(Type type, void** ppv) + { + if (!type.IsInstanceOfType(Target)) + return unchecked((int)0x80004002u); + + var rv = GetOrCreateNativePointer(type, ppv); + if (rv == 0) + AddRef((Ccw*)*ppv); + return rv; + } + + internal int GetOrCreateNativePointer(Type type, void** ppv) + { + if (!MicroComRuntime.GetVtableFor(type, out var vtable)) + return unchecked((int)0x80004002u); + lock (_lock) + { + + if (_shadows.TryGetValue(type, out var shadow)) + { + var targetCcw = (Ccw*)shadow; + AddRef(targetCcw); + *ppv = targetCcw; + return 0; + } + else + { + var intPtr = Marshal.AllocHGlobal(Marshal.SizeOf()); + var targetCcw = (Ccw*)intPtr; + *targetCcw = default; + targetCcw->RefCount = 0; + targetCcw->VTable = vtable; + if (_handle == null) + _handle = GCHandle.Alloc(this); + targetCcw->GcShadowHandle = GCHandle.ToIntPtr(_handle.Value); + _shadows[type] = intPtr; + _backShadows[intPtr] = type; + *ppv = targetCcw; + + return 0; + } + } + } + + internal int AddRef(Ccw* ccw) + { + if (Interlocked.Increment(ref _refCount) == 1) + { + try + { + Target.OnReferencedFromNative(); + } + catch (Exception e) + { + MicroComRuntime.UnhandledException(Target, e); + } + } + + return Interlocked.Increment(ref ccw->RefCount); + } + + internal int Release(Ccw* ccw) + { + Interlocked.Decrement(ref _refCount); + var cnt = Interlocked.Decrement(ref ccw->RefCount); + if (cnt == 0) + return FreeCcw(ccw); + + return cnt; + } + + int FreeCcw(Ccw* ccw) + { + lock (_lock) + { + // Shadow got resurrected by a call to QueryInterface from another thread + if (ccw->RefCount != 0) + return ccw->RefCount; + + var intPtr = new IntPtr(ccw); + var type = _backShadows[intPtr]; + _backShadows.Remove(intPtr); + _shadows.Remove(type); + Marshal.FreeHGlobal(intPtr); + if (_shadows.Count == 0) + { + _handle?.Free(); + _handle = null; + try + { + Target.OnUnreferencedFromNative(); + } + catch(Exception e) + { + MicroComRuntime.UnhandledException(Target, e); + } + } + } + + return 0; + } + + /* + Needs to be called to support the following scenario: + 1) Object created + 2) Object passed to native code, shadow is created, CCW is created + 3) Native side has never called AddRef + + In that case the GC handle to the shadow object is still alive + */ + + public void Dispose() + { + lock (_lock) + { + List toRemove = null; + foreach (var kv in _backShadows) + { + var ccw = (Ccw*)kv.Key; + if (ccw->RefCount == 0) + { + toRemove ??= new List(); + toRemove.Add(kv.Key); + } + } + + if(toRemove != null) + foreach (var intPtr in toRemove) + FreeCcw((Ccw*)intPtr); + } + } + } + + [StructLayout(LayoutKind.Sequential)] + struct Ccw + { + public IntPtr VTable; + public IntPtr GcShadowHandle; + public volatile int RefCount; + public MicroComShadow GetShadow() => (MicroComShadow)GCHandle.FromIntPtr(GcShadowHandle).Target; + } +} diff --git a/src/Avalonia.MicroCom/MicroComVtblBase.cs b/src/Avalonia.MicroCom/MicroComVtblBase.cs new file mode 100644 index 0000000000..2f0607c0a8 --- /dev/null +++ b/src/Avalonia.MicroCom/MicroComVtblBase.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; + +namespace Avalonia.MicroCom +{ + public unsafe class MicroComVtblBase + { + private List _methods = new List(); + [UnmanagedFunctionPointerAttribute(CallingConvention.StdCall)] + private delegate int AddRefDelegate(Ccw* ccw); + + [UnmanagedFunctionPointerAttribute(CallingConvention.StdCall)] + private delegate int QueryInterfaceDelegate(Ccw* ccw, Guid* guid, void** ppv); + + public static IntPtr Vtable { get; } = new MicroComVtblBase().CreateVTable(); + public MicroComVtblBase() + { + AddMethod((QueryInterfaceDelegate)QueryInterface); + AddMethod((AddRefDelegate)AddRef); + AddMethod((AddRefDelegate)Release); + } + + protected void AddMethod(Delegate d) + { + GCHandle.Alloc(d); + _methods.Add(Marshal.GetFunctionPointerForDelegate(d)); + } + + protected unsafe IntPtr CreateVTable() + { + var ptr = (IntPtr*)Marshal.AllocHGlobal((IntPtr.Size + 1) * _methods.Count); + for (var c = 0; c < _methods.Count; c++) + ptr[c] = _methods[c]; + return new IntPtr(ptr); + } + + static int QueryInterface(Ccw* ccw, Guid* guid, void** ppv) => ccw->GetShadow().QueryInterface(ccw, guid, ppv); + static int AddRef(Ccw* ccw) => ccw->GetShadow().AddRef(ccw); + static int Release(Ccw* ccw) => ccw->GetShadow().Release(ccw); + } +} diff --git a/src/Avalonia.Native/.gitignore b/src/Avalonia.Native/.gitignore index b1153e777c..b270c05962 100644 --- a/src/Avalonia.Native/.gitignore +++ b/src/Avalonia.Native/.gitignore @@ -1 +1,2 @@ Generated/*.cs +*.Generated.cs diff --git a/src/Avalonia.Native/Avalonia.Native.csproj b/src/Avalonia.Native/Avalonia.Native.csproj index 49bd578290..3913484431 100644 --- a/src/Avalonia.Native/Avalonia.Native.csproj +++ b/src/Avalonia.Native/Avalonia.Native.csproj @@ -5,10 +5,7 @@ $(PackAvaloniaNative) true netstandard2.0 - /usr/bin/castxml - /usr/local/bin/castxml true - false @@ -21,11 +18,9 @@ - - - - + - \ No newline at end of file + + diff --git a/src/Avalonia.Native/AvaloniaNativeMenuExporter.cs b/src/Avalonia.Native/AvaloniaNativeMenuExporter.cs index 6d1b95b997..2e3408eca5 100644 --- a/src/Avalonia.Native/AvaloniaNativeMenuExporter.cs +++ b/src/Avalonia.Native/AvaloniaNativeMenuExporter.cs @@ -4,6 +4,7 @@ using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Controls.Platform; using Avalonia.Dialogs; using Avalonia.Native.Interop; +using Avalonia.Native.Interop.Impl; using Avalonia.Threading; namespace Avalonia.Native @@ -15,7 +16,7 @@ namespace Avalonia.Native private bool _exported = false; private IAvnWindow _nativeWindow; private NativeMenu _menu; - private IAvnMenu _nativeMenu; + private __MicroComIAvnMenuProxy _nativeMenu; public AvaloniaNativeMenuExporter(IAvnWindow nativeWindow, IAvaloniaNativeFactory factory) { @@ -59,7 +60,7 @@ namespace Avalonia.Native Header = "About Avalonia", }; - aboutItem.Clicked += async (sender, e) => + aboutItem.Click += async (sender, e) => { var dialog = new AboutAvaloniaDialog(); @@ -135,7 +136,7 @@ namespace Avalonia.Native if (_nativeMenu is null) { - _nativeMenu = IAvnMenu.Create(_factory); + _nativeMenu = (__MicroComIAvnMenuProxy)__MicroComIAvnMenuProxy.Create(_factory); _nativeMenu.Initialise(this, appMenuHolder, ""); @@ -156,7 +157,7 @@ namespace Avalonia.Native if (_nativeMenu is null) { - _nativeMenu = IAvnMenu.Create(_factory); + _nativeMenu = __MicroComIAvnMenuProxy.Create(_factory); _nativeMenu.Initialise(this, menu, ""); diff --git a/src/Avalonia.Native/AvaloniaNativePlatform.cs b/src/Avalonia.Native/AvaloniaNativePlatform.cs index c56a8404fa..edcbf90ebc 100644 --- a/src/Avalonia.Native/AvaloniaNativePlatform.cs +++ b/src/Avalonia.Native/AvaloniaNativePlatform.cs @@ -4,6 +4,7 @@ using System.Security.Cryptography; using Avalonia.Controls.Platform; using Avalonia.Input; using Avalonia.Input.Platform; +using Avalonia.MicroCom; using Avalonia.Native.Interop; using Avalonia.OpenGL; using Avalonia.Platform; @@ -29,7 +30,7 @@ namespace Avalonia.Native public static AvaloniaNativePlatform Initialize(IntPtr factory, AvaloniaNativePlatformOptions options) { - var result = new AvaloniaNativePlatform(new IAvaloniaNativeFactory(factory)); + var result = new AvaloniaNativePlatform(MicroComRuntime.CreateProxyFor(factory, true)); result.DoInitialize(options); return result; @@ -65,10 +66,7 @@ namespace Avalonia.Native { if(!string.IsNullOrWhiteSpace(Application.Current.Name)) { - using (var buffer = new Utf8Buffer(Application.Current.Name)) - { - _factory.MacOptions.SetApplicationTitle(buffer.DangerousGetHandle()); - } + _factory.MacOptions.SetApplicationTitle(Application.Current.Name); } } @@ -93,7 +91,7 @@ namespace Avalonia.Native { var macOpts = AvaloniaLocator.Current.GetService(); - _factory.MacOptions.ShowInDock = macOpts?.ShowInDock != false ? 1 : 0; + _factory.MacOptions.SetShowInDock(macOpts?.ShowInDock != false ? 1 : 0); } AvaloniaLocator.CurrentMutable @@ -153,7 +151,7 @@ namespace Avalonia.Native set { _showInDock = value; - _opts.ShowInDock = value ? 1 : 0; + _opts.SetShowInDock(value ? 1 : 0); } } } diff --git a/src/Avalonia.Native/AvaloniaNativePlatformOpenGlInterface.cs b/src/Avalonia.Native/AvaloniaNativePlatformOpenGlInterface.cs index dbe968b82f..3b3d8836fd 100644 --- a/src/Avalonia.Native/AvaloniaNativePlatformOpenGlInterface.cs +++ b/src/Avalonia.Native/AvaloniaNativePlatformOpenGlInterface.cs @@ -150,12 +150,12 @@ namespace Avalonia.Native { get { - var s = _session.GetPixelSize(); + var s = _session.PixelSize; return new PixelSize(s.Width, s.Height); } } - public double Scaling => _session.GetScaling(); + public double Scaling => _session.Scaling; public bool IsYFlipped => true; diff --git a/src/Avalonia.Native/AvnString.cs b/src/Avalonia.Native/AvnString.cs index 11b1a33276..dcd473bae3 100644 --- a/src/Avalonia.Native/AvnString.cs +++ b/src/Avalonia.Native/AvnString.cs @@ -1,8 +1,22 @@ +using System; using System.Runtime.InteropServices; namespace Avalonia.Native.Interop { - unsafe partial class IAvnString + partial interface IAvnString + { + public string String { get; } + public byte[] Bytes { get; } + } + + partial interface IAvnStringArray + { + string[] ToStringArray(); + } +} +namespace Avalonia.Native.Interop.Impl +{ + unsafe partial class __MicroComIAvnStringProxy { private string _managed; private byte[] _bytes; @@ -16,7 +30,7 @@ namespace Avalonia.Native.Interop var ptr = Pointer(); if (ptr == null) return null; - _managed = System.Text.Encoding.UTF8.GetString((byte*)ptr.ToPointer(), Length()); + _managed = System.Text.Encoding.UTF8.GetString((byte*)ptr, Length()); } return _managed; @@ -30,7 +44,7 @@ namespace Avalonia.Native.Interop if (_bytes == null) { _bytes = new byte[Length()]; - Marshal.Copy(Pointer(), _bytes, 0, _bytes.Length); + Marshal.Copy(new IntPtr(Pointer()), _bytes, 0, _bytes.Length); } return _bytes; @@ -40,7 +54,7 @@ namespace Avalonia.Native.Interop public override string ToString() => String; } - partial class IAvnStringArray + partial class __MicroComIAvnStringArrayProxy { public string[] ToStringArray() { diff --git a/src/Avalonia.Native/CallbackBase.cs b/src/Avalonia.Native/CallbackBase.cs index 4cda358d0a..455ed4b159 100644 --- a/src/Avalonia.Native/CallbackBase.cs +++ b/src/Avalonia.Native/CallbackBase.cs @@ -1,44 +1,30 @@ using System; using System.Runtime.ExceptionServices; -using SharpGen.Runtime; +using Avalonia.MicroCom; using Avalonia.Platform; namespace Avalonia.Native { - public class CallbackBase : SharpGen.Runtime.IUnknown, IExceptionCallback + public class CallbackBase : IUnknown, IMicroComShadowContainer, IMicroComExceptionCallback { - private uint _refCount; - private bool _disposed; private readonly object _lock = new object(); - private ShadowContainer _shadow; + private bool _referencedFromManaged = true; + private bool _referencedFromNative = false; + private bool _destroyed; + - public CallbackBase() - { - _refCount = 1; - } - - public ShadowContainer Shadow + protected virtual void Destroyed() { - get => _shadow; - set - { - lock (_lock) - { - if (_disposed && value != null) - { - throw new ObjectDisposedException("CallbackBase"); - } - _shadow = value; - } - } } - public uint AddRef() + public void RaiseException(Exception e) { - lock (_lock) + if (AvaloniaLocator.Current.GetService() is PlatformThreadingInterface threadingInterface) { - return ++_refCount; + threadingInterface.TerminateNativeApp(); + + threadingInterface.DispatchException(ExceptionDispatchInfo.Capture(e)); } } @@ -46,43 +32,35 @@ namespace Avalonia.Native { lock (_lock) { - if (!_disposed) - { - _disposed = true; - Release(); - } + _referencedFromManaged = false; + DestroyIfNeeded(); } } - public uint Release() + void DestroyIfNeeded() { - lock (_lock) + if(_destroyed) + return; + if (_referencedFromManaged == false && _referencedFromNative == false) { - _refCount--; - - if (_refCount == 0) - { - Shadow?.Dispose(); - Shadow = null; - Destroyed(); - } - - return _refCount; + _destroyed = true; + Destroyed(); } } - protected virtual void Destroyed() + public MicroComShadow Shadow { get; set; } + public void OnReferencedFromNative() { - + lock (_lock) + _referencedFromNative = true; } - public void RaiseException(Exception e) + public void OnUnreferencedFromNative() { - if (AvaloniaLocator.Current.GetService() is PlatformThreadingInterface threadingInterface) + lock (_lock) { - threadingInterface.TerminateNativeApp(); - - threadingInterface.DispatchException(ExceptionDispatchInfo.Capture(e)); + _referencedFromNative = false; + DestroyIfNeeded(); } } } diff --git a/src/Avalonia.Native/ClipboardImpl.cs b/src/Avalonia.Native/ClipboardImpl.cs index 554e7a497a..4ee590516b 100644 --- a/src/Avalonia.Native/ClipboardImpl.cs +++ b/src/Avalonia.Native/ClipboardImpl.cs @@ -35,17 +35,12 @@ namespace Avalonia.Native return Task.FromResult(text.String); } - public Task SetTextAsync(string text) + public unsafe Task SetTextAsync(string text) { _native.Clear(); - if (text != null) - { - using (var buffer = new Utf8Buffer(text)) - { - _native.SetText(NSPasteboardTypeString, buffer.DangerousGetHandle()); - } - } + if (text != null) + _native.SetText(NSPasteboardTypeString, text); return Task.CompletedTask; } @@ -90,11 +85,10 @@ namespace Avalonia.Native { var o = data.Get(fmt); if(o is string s) - using (var b = new Utf8Buffer(s)) - _native.SetText(fmt, b.DangerousGetHandle()); + _native.SetText(fmt, s); else if(o is byte[] bytes) fixed (byte* pbytes = bytes) - _native.SetBytes(fmt, new IntPtr(pbytes), bytes.Length); + _native.SetBytes(fmt, pbytes, bytes.Length); } return Task.CompletedTask; } diff --git a/src/Avalonia.Native/DeferredFramebuffer.cs b/src/Avalonia.Native/DeferredFramebuffer.cs index 8ea7b20b8c..950b6a3197 100644 --- a/src/Avalonia.Native/DeferredFramebuffer.cs +++ b/src/Avalonia.Native/DeferredFramebuffer.cs @@ -2,11 +2,10 @@ using System.Runtime.InteropServices; using Avalonia.Native.Interop; using Avalonia.Platform; -using SharpGen.Runtime; namespace Avalonia.Native { - public class DeferredFramebuffer : ILockedFramebuffer + internal unsafe class DeferredFramebuffer : ILockedFramebuffer { private readonly Func, bool> _lockWindow; @@ -56,7 +55,7 @@ namespace Avalonia.Native { var fb = new AvnFramebuffer { - Data = Address, + Data = Address.ToPointer(), Dpi = new AvnVector { X = Dpi.X, @@ -70,7 +69,7 @@ namespace Avalonia.Native using (var d = new Disposer(Address)) { - win.ThreadSafeSetSwRenderedFrame(ref fb, d); + win.ThreadSafeSetSwRenderedFrame(&fb, d); } })) { diff --git a/src/Avalonia.Native/DoubleClickHelper.cs b/src/Avalonia.Native/DoubleClickHelper.cs new file mode 100644 index 0000000000..7618d6976a --- /dev/null +++ b/src/Avalonia.Native/DoubleClickHelper.cs @@ -0,0 +1,31 @@ +using Avalonia.Platform; + +namespace Avalonia.Native +{ + internal class DoubleClickHelper + { + private int _clickCount; + private Rect _lastClickRect; + private ulong _lastClickTime; + + public bool IsDoubleClick( + ulong timestamp, + Point p) + { + var settings = AvaloniaLocator.Current.GetService(); + var doubleClickTime = settings.DoubleClickTime.TotalMilliseconds; + + if (!_lastClickRect.Contains(p) || timestamp - _lastClickTime > doubleClickTime) + { + _clickCount = 0; + } + + ++_clickCount; + _lastClickTime = timestamp; + _lastClickRect = new Rect(p, new Size()) + .Inflate(new Thickness(settings.DoubleClickSize.Width / 2, settings.DoubleClickSize.Height / 2)); + + return _clickCount == 2; + } + } +} diff --git a/src/Avalonia.Native/Extensions.cs b/src/Avalonia.Native/Extensions.cs new file mode 100644 index 0000000000..c0d90f7a85 --- /dev/null +++ b/src/Avalonia.Native/Extensions.cs @@ -0,0 +1,8 @@ +namespace Avalonia.Native +{ + internal static class Extensions + { + public static int AsComBool(this bool b) => b ? 1 : 0; + public static bool FromComBool(this int b) => b != 0; + } +} diff --git a/src/Avalonia.Native/Generated/Enumerations.cs b/src/Avalonia.Native/Generated/Enumerations.cs deleted file mode 100644 index 0b30ce50c0..0000000000 --- a/src/Avalonia.Native/Generated/Enumerations.cs +++ /dev/null @@ -1,628 +0,0 @@ -// - -namespace Avalonia.Native.Interop -{ - /// - /// No documentation. - /// - /// AvnDragDropEffects - /// AvnDragDropEffects - public enum AvnDragDropEffects : System.Int32 - { - /// - /// No documentation. - /// - /// None - /// None - None = unchecked ((System.Int32)(0)), - /// - /// No documentation. - /// - /// Copy - /// Copy - Copy = unchecked ((System.Int32)(1)), - /// - /// No documentation. - /// - /// Move - /// Move - Move = unchecked ((System.Int32)(2)), - /// - /// No documentation. - /// - /// Link - /// Link - Link = unchecked ((System.Int32)(4))} - - /// - /// No documentation. - /// - /// AvnDragEventType - /// AvnDragEventType - public enum AvnDragEventType : System.Int32 - { - /// - /// No documentation. - /// - /// Enter - /// Enter - Enter = unchecked ((System.Int32)(0)), - /// - /// No documentation. - /// - /// Over - /// Over - Over = unchecked ((System.Int32)(1)), - /// - /// No documentation. - /// - /// Leave - /// Leave - Leave = unchecked ((System.Int32)(2)), - /// - /// No documentation. - /// - /// Drop - /// Drop - Drop = unchecked ((System.Int32)(3))} - - /// - /// No documentation. - /// - /// AvnExtendClientAreaChromeHints - /// AvnExtendClientAreaChromeHints - public enum AvnExtendClientAreaChromeHints : System.Int32 - { - /// - /// No documentation. - /// - /// AvnNoChrome - /// AvnNoChrome - AvnNoChrome = unchecked ((System.Int32)(0)), - /// - /// No documentation. - /// - /// AvnSystemChrome - /// AvnSystemChrome - AvnSystemChrome = unchecked ((System.Int32)(1)), - /// - /// No documentation. - /// - /// AvnPreferSystemChrome - /// AvnPreferSystemChrome - AvnPreferSystemChrome = unchecked ((System.Int32)(2)), - /// - /// No documentation. - /// - /// AvnOSXThickTitleBar - /// AvnOSXThickTitleBar - AvnOSXThickTitleBar = unchecked ((System.Int32)(8)), - /// - /// No documentation. - /// - /// AvnDefaultChrome - /// AvnDefaultChrome - AvnDefaultChrome = unchecked ((System.Int32)(1))} - - /// - /// No documentation. - /// - /// AvnInputModifiers - /// AvnInputModifiers - public enum AvnInputModifiers : System.Int32 - { - /// - /// No documentation. - /// - /// AvnInputModifiersNone - /// AvnInputModifiersNone - AvnInputModifiersNone = unchecked ((System.Int32)(0)), - /// - /// No documentation. - /// - /// Alt - /// Alt - Alt = unchecked ((System.Int32)(1)), - /// - /// No documentation. - /// - /// Control - /// Control - Control = unchecked ((System.Int32)(2)), - /// - /// No documentation. - /// - /// Shift - /// Shift - Shift = unchecked ((System.Int32)(4)), - /// - /// No documentation. - /// - /// Windows - /// Windows - Windows = unchecked ((System.Int32)(8)), - /// - /// No documentation. - /// - /// LeftMouseButton - /// LeftMouseButton - LeftMouseButton = unchecked ((System.Int32)(16)), - /// - /// No documentation. - /// - /// RightMouseButton - /// RightMouseButton - RightMouseButton = unchecked ((System.Int32)(32)), - /// - /// No documentation. - /// - /// MiddleMouseButton - /// MiddleMouseButton - MiddleMouseButton = unchecked ((System.Int32)(64)), - /// - /// No documentation. - /// - /// XButton1MouseButton - /// XButton1MouseButton - XButton1MouseButton = unchecked ((System.Int32)(128)), - /// - /// No documentation. - /// - /// XButton2MouseButton - /// XButton2MouseButton - XButton2MouseButton = unchecked ((System.Int32)(256))} - - /// - /// No documentation. - /// - /// AvnMenuItemToggleType - /// AvnMenuItemToggleType - public enum AvnMenuItemToggleType : System.Int32 - { - /// - /// No documentation. - /// - /// None - /// None - None = unchecked ((System.Int32)(0)), - /// - /// No documentation. - /// - /// CheckMark - /// CheckMark - CheckMark = unchecked ((System.Int32)(1)), - /// - /// No documentation. - /// - /// Radio - /// Radio - Radio = unchecked ((System.Int32)(2))} - - /// - /// No documentation. - /// - /// AvnPixelFormat - /// AvnPixelFormat - public enum AvnPixelFormat : System.Int32 - { - /// - /// No documentation. - /// - /// kAvnRgb565 - /// kAvnRgb565 - KAvnRgb565 = unchecked ((System.Int32)(0)), - /// - /// No documentation. - /// - /// kAvnRgba8888 - /// kAvnRgba8888 - KAvnRgba8888 = unchecked ((System.Int32)(1)), - /// - /// No documentation. - /// - /// kAvnBgra8888 - /// kAvnBgra8888 - KAvnBgra8888 = unchecked ((System.Int32)(2))} - - /// - /// No documentation. - /// - /// AvnRawKeyEventType - /// AvnRawKeyEventType - public enum AvnRawKeyEventType : System.Int32 - { - /// - /// No documentation. - /// - /// KeyDown - /// KeyDown - KeyDown = unchecked ((System.Int32)(0)), - /// - /// No documentation. - /// - /// KeyUp - /// KeyUp - KeyUp = unchecked ((System.Int32)(1))} - - /// - /// No documentation. - /// - /// AvnRawMouseEventType - /// AvnRawMouseEventType - public enum AvnRawMouseEventType : System.Int32 - { - /// - /// No documentation. - /// - /// LeaveWindow - /// LeaveWindow - LeaveWindow = unchecked ((System.Int32)(0)), - /// - /// No documentation. - /// - /// LeftButtonDown - /// LeftButtonDown - LeftButtonDown = unchecked ((System.Int32)(1)), - /// - /// No documentation. - /// - /// LeftButtonUp - /// LeftButtonUp - LeftButtonUp = unchecked ((System.Int32)(2)), - /// - /// No documentation. - /// - /// RightButtonDown - /// RightButtonDown - RightButtonDown = unchecked ((System.Int32)(3)), - /// - /// No documentation. - /// - /// RightButtonUp - /// RightButtonUp - RightButtonUp = unchecked ((System.Int32)(4)), - /// - /// No documentation. - /// - /// MiddleButtonDown - /// MiddleButtonDown - MiddleButtonDown = unchecked ((System.Int32)(5)), - /// - /// No documentation. - /// - /// MiddleButtonUp - /// MiddleButtonUp - MiddleButtonUp = unchecked ((System.Int32)(6)), - /// - /// No documentation. - /// - /// XButton1Down - /// XButton1Down - XButton1Down = unchecked ((System.Int32)(7)), - /// - /// No documentation. - /// - /// XButton1Up - /// XButton1Up - XButton1Up = unchecked ((System.Int32)(8)), - /// - /// No documentation. - /// - /// XButton2Down - /// XButton2Down - XButton2Down = unchecked ((System.Int32)(9)), - /// - /// No documentation. - /// - /// XButton2Up - /// XButton2Up - XButton2Up = unchecked ((System.Int32)(10)), - /// - /// No documentation. - /// - /// Move - /// Move - Move = unchecked ((System.Int32)(11)), - /// - /// No documentation. - /// - /// Wheel - /// Wheel - Wheel = unchecked ((System.Int32)(12)), - /// - /// No documentation. - /// - /// NonClientLeftButtonDown - /// NonClientLeftButtonDown - NonClientLeftButtonDown = unchecked ((System.Int32)(13)), - /// - /// No documentation. - /// - /// TouchBegin - /// TouchBegin - TouchBegin = unchecked ((System.Int32)(14)), - /// - /// No documentation. - /// - /// TouchUpdate - /// TouchUpdate - TouchUpdate = unchecked ((System.Int32)(15)), - /// - /// No documentation. - /// - /// TouchEnd - /// TouchEnd - TouchEnd = unchecked ((System.Int32)(16)), - /// - /// No documentation. - /// - /// TouchCancel - /// TouchCancel - TouchCancel = unchecked ((System.Int32)(17))} - - /// - /// No documentation. - /// - /// AvnStandardCursorType - /// AvnStandardCursorType - public enum AvnStandardCursorType : System.Int32 - { - /// - /// No documentation. - /// - /// CursorArrow - /// CursorArrow - CursorArrow = unchecked ((System.Int32)(0)), - /// - /// No documentation. - /// - /// CursorIbeam - /// CursorIbeam - CursorIbeam = unchecked ((System.Int32)(1)), - /// - /// No documentation. - /// - /// CursorWait - /// CursorWait - CursorWait = unchecked ((System.Int32)(2)), - /// - /// No documentation. - /// - /// CursorCross - /// CursorCross - CursorCross = unchecked ((System.Int32)(3)), - /// - /// No documentation. - /// - /// CursorUpArrow - /// CursorUpArrow - CursorUpArrow = unchecked ((System.Int32)(4)), - /// - /// No documentation. - /// - /// CursorSizeWestEast - /// CursorSizeWestEast - CursorSizeWestEast = unchecked ((System.Int32)(5)), - /// - /// No documentation. - /// - /// CursorSizeNorthSouth - /// CursorSizeNorthSouth - CursorSizeNorthSouth = unchecked ((System.Int32)(6)), - /// - /// No documentation. - /// - /// CursorSizeAll - /// CursorSizeAll - CursorSizeAll = unchecked ((System.Int32)(7)), - /// - /// No documentation. - /// - /// CursorNo - /// CursorNo - CursorNo = unchecked ((System.Int32)(8)), - /// - /// No documentation. - /// - /// CursorHand - /// CursorHand - CursorHand = unchecked ((System.Int32)(9)), - /// - /// No documentation. - /// - /// CursorAppStarting - /// CursorAppStarting - CursorAppStarting = unchecked ((System.Int32)(10)), - /// - /// No documentation. - /// - /// CursorHelp - /// CursorHelp - CursorHelp = unchecked ((System.Int32)(11)), - /// - /// No documentation. - /// - /// CursorTopSide - /// CursorTopSide - CursorTopSide = unchecked ((System.Int32)(12)), - /// - /// No documentation. - /// - /// CursorBottomSize - /// CursorBottomSize - CursorBottomSize = unchecked ((System.Int32)(13)), - /// - /// No documentation. - /// - /// CursorLeftSide - /// CursorLeftSide - CursorLeftSide = unchecked ((System.Int32)(14)), - /// - /// No documentation. - /// - /// CursorRightSide - /// CursorRightSide - CursorRightSide = unchecked ((System.Int32)(15)), - /// - /// No documentation. - /// - /// CursorTopLeftCorner - /// CursorTopLeftCorner - CursorTopLeftCorner = unchecked ((System.Int32)(16)), - /// - /// No documentation. - /// - /// CursorTopRightCorner - /// CursorTopRightCorner - CursorTopRightCorner = unchecked ((System.Int32)(17)), - /// - /// No documentation. - /// - /// CursorBottomLeftCorner - /// CursorBottomLeftCorner - CursorBottomLeftCorner = unchecked ((System.Int32)(18)), - /// - /// No documentation. - /// - /// CursorBottomRightCorner - /// CursorBottomRightCorner - CursorBottomRightCorner = unchecked ((System.Int32)(19)), - /// - /// No documentation. - /// - /// CursorDragMove - /// CursorDragMove - CursorDragMove = unchecked ((System.Int32)(20)), - /// - /// No documentation. - /// - /// CursorDragCopy - /// CursorDragCopy - CursorDragCopy = unchecked ((System.Int32)(21)), - /// - /// No documentation. - /// - /// CursorDragLink - /// CursorDragLink - CursorDragLink = unchecked ((System.Int32)(22)), - /// - /// No documentation. - /// - /// CursorNone - /// CursorNone - CursorNone = unchecked ((System.Int32)(23))} - - /// - /// No documentation. - /// - /// AvnWindowEdge - /// AvnWindowEdge - public enum AvnWindowEdge : System.Int32 - { - /// - /// No documentation. - /// - /// WindowEdgeNorthWest - /// WindowEdgeNorthWest - WindowEdgeNorthWest = unchecked ((System.Int32)(0)), - /// - /// No documentation. - /// - /// WindowEdgeNorth - /// WindowEdgeNorth - WindowEdgeNorth = unchecked ((System.Int32)(1)), - /// - /// No documentation. - /// - /// WindowEdgeNorthEast - /// WindowEdgeNorthEast - WindowEdgeNorthEast = unchecked ((System.Int32)(2)), - /// - /// No documentation. - /// - /// WindowEdgeWest - /// WindowEdgeWest - WindowEdgeWest = unchecked ((System.Int32)(3)), - /// - /// No documentation. - /// - /// WindowEdgeEast - /// WindowEdgeEast - WindowEdgeEast = unchecked ((System.Int32)(4)), - /// - /// No documentation. - /// - /// WindowEdgeSouthWest - /// WindowEdgeSouthWest - WindowEdgeSouthWest = unchecked ((System.Int32)(5)), - /// - /// No documentation. - /// - /// WindowEdgeSouth - /// WindowEdgeSouth - WindowEdgeSouth = unchecked ((System.Int32)(6)), - /// - /// No documentation. - /// - /// WindowEdgeSouthEast - /// WindowEdgeSouthEast - WindowEdgeSouthEast = unchecked ((System.Int32)(7))} - - /// - /// No documentation. - /// - /// AvnWindowState - /// AvnWindowState - public enum AvnWindowState : System.Int32 - { - /// - /// No documentation. - /// - /// Normal - /// Normal - Normal = unchecked ((System.Int32)(0)), - /// - /// No documentation. - /// - /// Minimized - /// Minimized - Minimized = unchecked ((System.Int32)(1)), - /// - /// No documentation. - /// - /// Maximized - /// Maximized - Maximized = unchecked ((System.Int32)(2)), - /// - /// No documentation. - /// - /// FullScreen - /// FullScreen - FullScreen = unchecked ((System.Int32)(3))} - - /// - /// No documentation. - /// - /// SystemDecorations - /// SystemDecorations - public enum SystemDecorations : System.Int32 - { - /// - /// No documentation. - /// - /// SystemDecorationsNone - /// SystemDecorationsNone - SystemDecorationsNone = unchecked ((System.Int32)(0)), - /// - /// No documentation. - /// - /// SystemDecorationsBorderOnly - /// SystemDecorationsBorderOnly - SystemDecorationsBorderOnly = unchecked ((System.Int32)(1)), - /// - /// No documentation. - /// - /// SystemDecorationsFull - /// SystemDecorationsFull - SystemDecorationsFull = unchecked ((System.Int32)(2))} -} \ No newline at end of file diff --git a/src/Avalonia.Native/Generated/Functions.cs b/src/Avalonia.Native/Generated/Functions.cs deleted file mode 100644 index 6ab648dc50..0000000000 --- a/src/Avalonia.Native/Generated/Functions.cs +++ /dev/null @@ -1,5 +0,0 @@ -// - -namespace Avalonia.Native.Interop -{ -} \ No newline at end of file diff --git a/src/Avalonia.Native/Generated/Interfaces.cs b/src/Avalonia.Native/Generated/Interfaces.cs deleted file mode 100644 index 161ada1e50..0000000000 --- a/src/Avalonia.Native/Generated/Interfaces.cs +++ /dev/null @@ -1,3092 +0,0 @@ -// - -namespace Avalonia.Native.Interop -{ - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f01")] - public partial class IAvaloniaNativeFactory : SharpGen.Runtime.ComObject - { - public IAvaloniaNativeFactory(System.IntPtr nativePtr): base (nativePtr) - { - } - - public static explicit operator IAvaloniaNativeFactory(System.IntPtr nativePtr) => nativePtr == System.IntPtr.Zero ? null : new IAvaloniaNativeFactory(nativePtr); - /// - /// No documentation. - /// - /// GetMacOptions - /// GetMacOptions - public Avalonia.Native.Interop.IAvnMacOptions MacOptions - { - get => GetMacOptions(); - } - - /// - /// No documentation. - /// - /// SetAppMenu - /// SetAppMenu - public Avalonia.Native.Interop.IAvnMenu AppMenu - { - set => SetAppMenu(value); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvaloniaNativeFactory::Initialize([In] IAvnGCHandleDeallocatorCallback* deallocator) - /// IAvaloniaNativeFactory::Initialize - public unsafe void Initialize(Avalonia.Native.Interop.IAvnGCHandleDeallocatorCallback deallocator) - { - System.IntPtr deallocator_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - deallocator_ = SharpGen.Runtime.CppObject.ToCallbackPtr(deallocator); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)deallocator_, (*(void ***)this._nativePointer)[3]); - System.GC.KeepAlive(deallocator); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// IAvnMacOptions* IAvaloniaNativeFactory::GetMacOptions() - /// IAvaloniaNativeFactory::GetMacOptions - internal unsafe Avalonia.Native.Interop.IAvnMacOptions GetMacOptions() - { - Avalonia.Native.Interop.IAvnMacOptions __result__; - System.IntPtr __result__native = System.IntPtr.Zero; - __result__native = Avalonia.Native.LocalInterop.CalliThisCallSystemIntPtr(this._nativePointer, (*(void ***)this._nativePointer)[4]); - if (__result__native != System.IntPtr.Zero) - __result__ = new Avalonia.Native.Interop.IAvnMacOptions(__result__native); - else - __result__ = null; - return __result__; - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// No documentation. - /// HRESULT IAvaloniaNativeFactory::CreateWindow([In] IAvnWindowEvents* cb,[In] IAvnGlContext* gl,[In] IAvnWindow** ppv) - /// IAvaloniaNativeFactory::CreateWindow - public unsafe Avalonia.Native.Interop.IAvnWindow CreateWindow(Avalonia.Native.Interop.IAvnWindowEvents cb, Avalonia.Native.Interop.IAvnGlContext gl) - { - System.IntPtr cb_ = System.IntPtr.Zero; - System.IntPtr gl_ = System.IntPtr.Zero; - Avalonia.Native.Interop.IAvnWindow vOut; - System.IntPtr vOut_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - cb_ = SharpGen.Runtime.CppObject.ToCallbackPtr(cb); - gl_ = SharpGen.Runtime.CppObject.ToCallbackPtr(gl); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)cb_, (void *)gl_, &vOut_, (*(void ***)this._nativePointer)[5]); - if (vOut_ != System.IntPtr.Zero) - vOut = new Avalonia.Native.Interop.IAvnWindow(vOut_); - else - vOut = null; - System.GC.KeepAlive(cb); - System.GC.KeepAlive(gl); - __result__.CheckError(); - return vOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// No documentation. - /// HRESULT IAvaloniaNativeFactory::CreatePopup([In] IAvnWindowEvents* cb,[In] IAvnGlContext* gl,[In] IAvnPopup** ppv) - /// IAvaloniaNativeFactory::CreatePopup - public unsafe Avalonia.Native.Interop.IAvnPopup CreatePopup(Avalonia.Native.Interop.IAvnWindowEvents cb, Avalonia.Native.Interop.IAvnGlContext gl) - { - System.IntPtr cb_ = System.IntPtr.Zero; - System.IntPtr gl_ = System.IntPtr.Zero; - Avalonia.Native.Interop.IAvnPopup vOut; - System.IntPtr vOut_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - cb_ = SharpGen.Runtime.CppObject.ToCallbackPtr(cb); - gl_ = SharpGen.Runtime.CppObject.ToCallbackPtr(gl); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)cb_, (void *)gl_, &vOut_, (*(void ***)this._nativePointer)[6]); - if (vOut_ != System.IntPtr.Zero) - vOut = new Avalonia.Native.Interop.IAvnPopup(vOut_); - else - vOut = null; - System.GC.KeepAlive(cb); - System.GC.KeepAlive(gl); - __result__.CheckError(); - return vOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvaloniaNativeFactory::CreatePlatformThreadingInterface([In] IAvnPlatformThreadingInterface** ppv) - /// IAvaloniaNativeFactory::CreatePlatformThreadingInterface - public unsafe Avalonia.Native.Interop.IAvnPlatformThreadingInterface CreatePlatformThreadingInterface() - { - Avalonia.Native.Interop.IAvnPlatformThreadingInterface vOut; - System.IntPtr vOut_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &vOut_, (*(void ***)this._nativePointer)[7]); - if (vOut_ != System.IntPtr.Zero) - vOut = new Avalonia.Native.Interop.IAvnPlatformThreadingInterface(vOut_); - else - vOut = null; - __result__.CheckError(); - return vOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvaloniaNativeFactory::CreateSystemDialogs([In] IAvnSystemDialogs** ppv) - /// IAvaloniaNativeFactory::CreateSystemDialogs - public unsafe Avalonia.Native.Interop.IAvnSystemDialogs CreateSystemDialogs() - { - Avalonia.Native.Interop.IAvnSystemDialogs vOut; - System.IntPtr vOut_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &vOut_, (*(void ***)this._nativePointer)[8]); - if (vOut_ != System.IntPtr.Zero) - vOut = new Avalonia.Native.Interop.IAvnSystemDialogs(vOut_); - else - vOut = null; - __result__.CheckError(); - return vOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvaloniaNativeFactory::CreateScreens([In] IAvnScreens** ppv) - /// IAvaloniaNativeFactory::CreateScreens - public unsafe Avalonia.Native.Interop.IAvnScreens CreateScreens() - { - Avalonia.Native.Interop.IAvnScreens vOut; - System.IntPtr vOut_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &vOut_, (*(void ***)this._nativePointer)[9]); - if (vOut_ != System.IntPtr.Zero) - vOut = new Avalonia.Native.Interop.IAvnScreens(vOut_); - else - vOut = null; - __result__.CheckError(); - return vOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvaloniaNativeFactory::CreateClipboard([In] IAvnClipboard** ppv) - /// IAvaloniaNativeFactory::CreateClipboard - public unsafe Avalonia.Native.Interop.IAvnClipboard CreateClipboard() - { - Avalonia.Native.Interop.IAvnClipboard vOut; - System.IntPtr vOut_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &vOut_, (*(void ***)this._nativePointer)[10]); - if (vOut_ != System.IntPtr.Zero) - vOut = new Avalonia.Native.Interop.IAvnClipboard(vOut_); - else - vOut = null; - __result__.CheckError(); - return vOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvaloniaNativeFactory::CreateDndClipboard([In] IAvnClipboard** ppv) - /// IAvaloniaNativeFactory::CreateDndClipboard - public unsafe Avalonia.Native.Interop.IAvnClipboard CreateDndClipboard() - { - Avalonia.Native.Interop.IAvnClipboard vOut; - System.IntPtr vOut_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &vOut_, (*(void ***)this._nativePointer)[11]); - if (vOut_ != System.IntPtr.Zero) - vOut = new Avalonia.Native.Interop.IAvnClipboard(vOut_); - else - vOut = null; - __result__.CheckError(); - return vOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvaloniaNativeFactory::CreateCursorFactory([In] IAvnCursorFactory** ppv) - /// IAvaloniaNativeFactory::CreateCursorFactory - public unsafe Avalonia.Native.Interop.IAvnCursorFactory CreateCursorFactory() - { - Avalonia.Native.Interop.IAvnCursorFactory vOut; - System.IntPtr vOut_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &vOut_, (*(void ***)this._nativePointer)[12]); - if (vOut_ != System.IntPtr.Zero) - vOut = new Avalonia.Native.Interop.IAvnCursorFactory(vOut_); - else - vOut = null; - __result__.CheckError(); - return vOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvaloniaNativeFactory::ObtainGlDisplay([In] IAvnGlDisplay** ppv) - /// IAvaloniaNativeFactory::ObtainGlDisplay - public unsafe Avalonia.Native.Interop.IAvnGlDisplay ObtainGlDisplay() - { - Avalonia.Native.Interop.IAvnGlDisplay vOut; - System.IntPtr vOut_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &vOut_, (*(void ***)this._nativePointer)[13]); - if (vOut_ != System.IntPtr.Zero) - vOut = new Avalonia.Native.Interop.IAvnGlDisplay(vOut_); - else - vOut = null; - __result__.CheckError(); - return vOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvaloniaNativeFactory::SetAppMenu([In] IAvnMenu* menu) - /// IAvaloniaNativeFactory::SetAppMenu - internal unsafe void SetAppMenu(Avalonia.Native.Interop.IAvnMenu menu) - { - System.IntPtr menu_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - menu_ = SharpGen.Runtime.CppObject.ToCallbackPtr(menu); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)menu_, (*(void ***)this._nativePointer)[14]); - System.GC.KeepAlive(menu); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvaloniaNativeFactory::CreateMenu([In] IAvnMenuEvents* cb,[In] IAvnMenu** ppv) - /// IAvaloniaNativeFactory::CreateMenu - public unsafe Avalonia.Native.Interop.IAvnMenu CreateMenu(Avalonia.Native.Interop.IAvnMenuEvents cb) - { - System.IntPtr cb_ = System.IntPtr.Zero; - Avalonia.Native.Interop.IAvnMenu vOut; - System.IntPtr vOut_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - cb_ = SharpGen.Runtime.CppObject.ToCallbackPtr(cb); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)cb_, &vOut_, (*(void ***)this._nativePointer)[15]); - if (vOut_ != System.IntPtr.Zero) - vOut = new Avalonia.Native.Interop.IAvnMenu(vOut_); - else - vOut = null; - System.GC.KeepAlive(cb); - __result__.CheckError(); - return vOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvaloniaNativeFactory::CreateMenuItem([In] IAvnMenuItem** ppv) - /// IAvaloniaNativeFactory::CreateMenuItem - public unsafe Avalonia.Native.Interop.IAvnMenuItem CreateMenuItem() - { - Avalonia.Native.Interop.IAvnMenuItem vOut; - System.IntPtr vOut_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &vOut_, (*(void ***)this._nativePointer)[16]); - if (vOut_ != System.IntPtr.Zero) - vOut = new Avalonia.Native.Interop.IAvnMenuItem(vOut_); - else - vOut = null; - __result__.CheckError(); - return vOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvaloniaNativeFactory::CreateMenuItemSeperator([In] IAvnMenuItem** ppv) - /// IAvaloniaNativeFactory::CreateMenuItemSeperator - public unsafe Avalonia.Native.Interop.IAvnMenuItem CreateMenuItemSeperator() - { - Avalonia.Native.Interop.IAvnMenuItem vOut; - System.IntPtr vOut_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &vOut_, (*(void ***)this._nativePointer)[17]); - if (vOut_ != System.IntPtr.Zero) - vOut = new Avalonia.Native.Interop.IAvnMenuItem(vOut_); - else - vOut = null; - __result__.CheckError(); - return vOut; - } - } - - class IAvnActionCallbackShadow : SharpGen.Runtime.ComObjectShadow - { - protected unsafe class IAvnActionCallbackVtbl : SharpGen.Runtime.ComObjectShadow.ComObjectVtbl - { - public IAvnActionCallbackVtbl(int numberOfCallbackMethods): base (numberOfCallbackMethods + 1) - { - AddMethod(new RunDelegate(Run)); - } - - [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)] - private delegate void RunDelegate(System.IntPtr thisObject); - private static unsafe void Run(System.IntPtr thisObject) - { - try - { - IAvnActionCallback @this = (IAvnActionCallback)ToShadow(thisObject).Callback; - @this.Run(); - } - catch (System.Exception __exception__) - { - IAvnActionCallback @this = (IAvnActionCallback)ToShadow(thisObject).Callback; - (@this as SharpGen.Runtime.IExceptionCallback)?.RaiseException(__exception__); - } - } - } - - protected override SharpGen.Runtime.CppObjectVtbl Vtbl - { - get; - } - - = new Avalonia.Native.Interop.IAvnActionCallbackShadow.IAvnActionCallbackVtbl(0); - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f08"), SharpGen.Runtime.ShadowAttribute(typeof (Avalonia.Native.Interop.IAvnActionCallbackShadow))] - public partial interface IAvnActionCallback : SharpGen.Runtime.IUnknown - { - void Run(); - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f0f")] - public partial class IAvnClipboard : SharpGen.Runtime.ComObject - { - public IAvnClipboard(System.IntPtr nativePtr): base (nativePtr) - { - } - - public static explicit operator IAvnClipboard(System.IntPtr nativePtr) => nativePtr == System.IntPtr.Zero ? null : new IAvnClipboard(nativePtr); - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnClipboard::GetText([In] char* type,[In] IAvnString** ppv) - /// IAvnClipboard::GetText - public unsafe Avalonia.Native.Interop.IAvnString GetText(System.String type) - { - System.IntPtr type_; - Avalonia.Native.Interop.IAvnString vOut; - System.IntPtr vOut_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - type_ = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(type); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)type_, &vOut_, (*(void ***)this._nativePointer)[3]); - if (vOut_ != System.IntPtr.Zero) - vOut = new Avalonia.Native.Interop.IAvnString(vOut_); - else - vOut = null; - System.Runtime.InteropServices.Marshal.FreeHGlobal(type_); - __result__.CheckError(); - return vOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// No documentation. - /// HRESULT IAvnClipboard::SetText([In] char* type,[In] void* utf8Text) - /// IAvnClipboard::SetText - public unsafe void SetText(System.String type, System.IntPtr utf8Text) - { - System.IntPtr type_; - SharpGen.Runtime.Result __result__; - type_ = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(type); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)type_, (void *)utf8Text, (*(void ***)this._nativePointer)[4]); - System.Runtime.InteropServices.Marshal.FreeHGlobal(type_); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnClipboard::ObtainFormats([In] IAvnStringArray** ppv) - /// IAvnClipboard::ObtainFormats - public unsafe Avalonia.Native.Interop.IAvnStringArray ObtainFormats() - { - Avalonia.Native.Interop.IAvnStringArray vOut; - System.IntPtr vOut_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &vOut_, (*(void ***)this._nativePointer)[5]); - if (vOut_ != System.IntPtr.Zero) - vOut = new Avalonia.Native.Interop.IAvnStringArray(vOut_); - else - vOut = null; - __result__.CheckError(); - return vOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnClipboard::GetStrings([In] char* type,[In] IAvnStringArray** ppv) - /// IAvnClipboard::GetStrings - public unsafe Avalonia.Native.Interop.IAvnStringArray GetStrings(System.String type) - { - System.IntPtr type_; - Avalonia.Native.Interop.IAvnStringArray vOut; - System.IntPtr vOut_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - type_ = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(type); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)type_, &vOut_, (*(void ***)this._nativePointer)[6]); - if (vOut_ != System.IntPtr.Zero) - vOut = new Avalonia.Native.Interop.IAvnStringArray(vOut_); - else - vOut = null; - System.Runtime.InteropServices.Marshal.FreeHGlobal(type_); - __result__.CheckError(); - return vOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// No documentation. - /// No documentation. - /// HRESULT IAvnClipboard::SetBytes([In] char* type,[In] void* utf8Text,[In] int len) - /// IAvnClipboard::SetBytes - public unsafe void SetBytes(System.String type, System.IntPtr utf8Text, System.Int32 len) - { - System.IntPtr type_; - SharpGen.Runtime.Result __result__; - type_ = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(type); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)type_, (void *)utf8Text, len, (*(void ***)this._nativePointer)[7]); - System.Runtime.InteropServices.Marshal.FreeHGlobal(type_); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnClipboard::GetBytes([In] char* type,[In] IAvnString** ppv) - /// IAvnClipboard::GetBytes - public unsafe Avalonia.Native.Interop.IAvnString GetBytes(System.String type) - { - System.IntPtr type_; - Avalonia.Native.Interop.IAvnString vOut; - System.IntPtr vOut_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - type_ = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(type); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)type_, &vOut_, (*(void ***)this._nativePointer)[8]); - if (vOut_ != System.IntPtr.Zero) - vOut = new Avalonia.Native.Interop.IAvnString(vOut_); - else - vOut = null; - System.Runtime.InteropServices.Marshal.FreeHGlobal(type_); - __result__.CheckError(); - return vOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnClipboard::Clear() - /// IAvnClipboard::Clear - public unsafe void Clear() - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (*(void ***)this._nativePointer)[9]); - __result__.CheckError(); - } - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f10")] - public partial class IAvnCursor : SharpGen.Runtime.ComObject - { - public IAvnCursor(System.IntPtr nativePtr): base (nativePtr) - { - } - - public static explicit operator IAvnCursor(System.IntPtr nativePtr) => nativePtr == System.IntPtr.Zero ? null : new IAvnCursor(nativePtr); - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f11")] - public partial class IAvnCursorFactory : SharpGen.Runtime.ComObject - { - public IAvnCursorFactory(System.IntPtr nativePtr): base (nativePtr) - { - } - - public static explicit operator IAvnCursorFactory(System.IntPtr nativePtr) => nativePtr == System.IntPtr.Zero ? null : new IAvnCursorFactory(nativePtr); - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnCursorFactory::GetCursor([In] AvnStandardCursorType cursorType,[Out] IAvnCursor** retOut) - /// IAvnCursorFactory::GetCursor - public unsafe Avalonia.Native.Interop.IAvnCursor GetCursor(Avalonia.Native.Interop.AvnStandardCursorType cursorType) - { - Avalonia.Native.Interop.IAvnCursor retOut; - System.IntPtr retOut_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, unchecked ((System.Int32)cursorType), &retOut_, (*(void ***)this._nativePointer)[3]); - if (retOut_ != System.IntPtr.Zero) - retOut = new Avalonia.Native.Interop.IAvnCursor(retOut_); - else - retOut = null; - __result__.CheckError(); - return retOut; - } - } - - class IAvnDndResultCallbackShadow : SharpGen.Runtime.ComObjectShadow - { - protected unsafe class IAvnDndResultCallbackVtbl : SharpGen.Runtime.ComObjectShadow.ComObjectVtbl - { - public IAvnDndResultCallbackVtbl(int numberOfCallbackMethods): base (numberOfCallbackMethods + 1) - { - AddMethod(new OnDragAndDropCompleteDelegate(OnDragAndDropComplete)); - } - - [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)] - private delegate void OnDragAndDropCompleteDelegate(System.IntPtr thisObject, int arg0); - private static unsafe void OnDragAndDropComplete(System.IntPtr thisObject, int param0) - { - try - { - Avalonia.Native.Interop.AvnDragDropEffects effecct = default (Avalonia.Native.Interop.AvnDragDropEffects); - effecct = (Avalonia.Native.Interop.AvnDragDropEffects)param0; - IAvnDndResultCallback @this = (IAvnDndResultCallback)ToShadow(thisObject).Callback; - @this.OnDragAndDropComplete(effecct); - } - catch (System.Exception __exception__) - { - IAvnDndResultCallback @this = (IAvnDndResultCallback)ToShadow(thisObject).Callback; - (@this as SharpGen.Runtime.IExceptionCallback)?.RaiseException(__exception__); - } - } - } - - protected override SharpGen.Runtime.CppObjectVtbl Vtbl - { - get; - } - - = new Avalonia.Native.Interop.IAvnDndResultCallbackShadow.IAvnDndResultCallbackVtbl(0); - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f21"), SharpGen.Runtime.ShadowAttribute(typeof (Avalonia.Native.Interop.IAvnDndResultCallbackShadow))] - public partial interface IAvnDndResultCallback : SharpGen.Runtime.IUnknown - { - void OnDragAndDropComplete(Avalonia.Native.Interop.AvnDragDropEffects effecct); - } - - class IAvnGCHandleDeallocatorCallbackShadow : SharpGen.Runtime.ComObjectShadow - { - protected unsafe class IAvnGCHandleDeallocatorCallbackVtbl : SharpGen.Runtime.ComObjectShadow.ComObjectVtbl - { - public IAvnGCHandleDeallocatorCallbackVtbl(int numberOfCallbackMethods): base (numberOfCallbackMethods + 1) - { - AddMethod(new FreeGCHandleDelegate(FreeGCHandle)); - } - - [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)] - private delegate void FreeGCHandleDelegate(System.IntPtr thisObject, void *arg0); - private static unsafe void FreeGCHandle(System.IntPtr thisObject, void *param0) - { - try - { - System.IntPtr handle = default (System.IntPtr); - handle = (System.IntPtr)param0; - IAvnGCHandleDeallocatorCallback @this = (IAvnGCHandleDeallocatorCallback)ToShadow(thisObject).Callback; - @this.FreeGCHandle(handle); - } - catch (System.Exception __exception__) - { - IAvnGCHandleDeallocatorCallback @this = (IAvnGCHandleDeallocatorCallback)ToShadow(thisObject).Callback; - (@this as SharpGen.Runtime.IExceptionCallback)?.RaiseException(__exception__); - } - } - } - - protected override SharpGen.Runtime.CppObjectVtbl Vtbl - { - get; - } - - = new Avalonia.Native.Interop.IAvnGCHandleDeallocatorCallbackShadow.IAvnGCHandleDeallocatorCallbackVtbl(0); - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f22"), SharpGen.Runtime.ShadowAttribute(typeof (Avalonia.Native.Interop.IAvnGCHandleDeallocatorCallbackShadow))] - public partial interface IAvnGCHandleDeallocatorCallback : SharpGen.Runtime.IUnknown - { - void FreeGCHandle(System.IntPtr handle); - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f14")] - public partial class IAvnGlContext : SharpGen.Runtime.ComObject - { - public IAvnGlContext(System.IntPtr nativePtr): base (nativePtr) - { - } - - public static explicit operator IAvnGlContext(System.IntPtr nativePtr) => nativePtr == System.IntPtr.Zero ? null : new IAvnGlContext(nativePtr); - /// - /// No documentation. - /// - /// GetSampleCount - /// GetSampleCount - public System.Int32 SampleCount - { - get => GetSampleCount(); - } - - /// - /// No documentation. - /// - /// GetStencilSize - /// GetStencilSize - public System.Int32 StencilSize - { - get => GetStencilSize(); - } - - /// - /// No documentation. - /// - /// GetNativeHandle - /// GetNativeHandle - public System.IntPtr NativeHandle - { - get => GetNativeHandle(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnGlContext::MakeCurrent([In] IUnknown** ppv) - /// IAvnGlContext::MakeCurrent - public unsafe SharpGen.Runtime.IUnknown MakeCurrent() - { - SharpGen.Runtime.IUnknown vOut; - System.IntPtr vOut_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &vOut_, (*(void ***)this._nativePointer)[3]); - if (vOut_ != System.IntPtr.Zero) - vOut = new SharpGen.Runtime.ComObject(vOut_); - else - vOut = null; - __result__.CheckError(); - return vOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnGlContext::LegacyMakeCurrent() - /// IAvnGlContext::LegacyMakeCurrent - public unsafe void LegacyMakeCurrent() - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (*(void ***)this._nativePointer)[4]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// int IAvnGlContext::GetSampleCount() - /// IAvnGlContext::GetSampleCount - internal unsafe System.Int32 GetSampleCount() - { - System.Int32 __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (*(void ***)this._nativePointer)[5]); - return __result__; - } - - /// - /// No documentation. - /// - /// No documentation. - /// int IAvnGlContext::GetStencilSize() - /// IAvnGlContext::GetStencilSize - internal unsafe System.Int32 GetStencilSize() - { - System.Int32 __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (*(void ***)this._nativePointer)[6]); - return __result__; - } - - /// - /// No documentation. - /// - /// No documentation. - /// void* IAvnGlContext::GetNativeHandle() - /// IAvnGlContext::GetNativeHandle - internal unsafe System.IntPtr GetNativeHandle() - { - System.IntPtr __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallSystemIntPtr(this._nativePointer, (*(void ***)this._nativePointer)[7]); - return __result__; - } - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f13")] - public partial class IAvnGlDisplay : SharpGen.Runtime.ComObject - { - public IAvnGlDisplay(System.IntPtr nativePtr): base (nativePtr) - { - } - - public static explicit operator IAvnGlDisplay(System.IntPtr nativePtr) => nativePtr == System.IntPtr.Zero ? null : new IAvnGlDisplay(nativePtr); - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnGlDisplay::CreateContext([In] IAvnGlContext* share,[In] IAvnGlContext** ppv) - /// IAvnGlDisplay::CreateContext - public unsafe Avalonia.Native.Interop.IAvnGlContext CreateContext(Avalonia.Native.Interop.IAvnGlContext share) - { - System.IntPtr share_ = System.IntPtr.Zero; - Avalonia.Native.Interop.IAvnGlContext vOut; - System.IntPtr vOut_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - share_ = SharpGen.Runtime.CppObject.ToCallbackPtr(share); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)share_, &vOut_, (*(void ***)this._nativePointer)[3]); - if (vOut_ != System.IntPtr.Zero) - vOut = new Avalonia.Native.Interop.IAvnGlContext(vOut_); - else - vOut = null; - System.GC.KeepAlive(share); - __result__.CheckError(); - return vOut; - } - - /// - /// No documentation. - /// - /// void IAvnGlDisplay::LegacyClearCurrentContext() - /// IAvnGlDisplay::LegacyClearCurrentContext - public unsafe void LegacyClearCurrentContext() - { - Avalonia.Native.LocalInterop.CalliThisCallvoid(this._nativePointer, (*(void ***)this._nativePointer)[4]); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnGlDisplay::WrapContext([In] void* native,[In] IAvnGlContext** ppv) - /// IAvnGlDisplay::WrapContext - public unsafe Avalonia.Native.Interop.IAvnGlContext WrapContext(System.IntPtr native) - { - Avalonia.Native.Interop.IAvnGlContext vOut; - System.IntPtr vOut_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)native, &vOut_, (*(void ***)this._nativePointer)[5]); - if (vOut_ != System.IntPtr.Zero) - vOut = new Avalonia.Native.Interop.IAvnGlContext(vOut_); - else - vOut = null; - __result__.CheckError(); - return vOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// void* IAvnGlDisplay::GetProcAddress([In] char* proc) - /// IAvnGlDisplay::GetProcAddress - public unsafe System.IntPtr GetProcAddress(System.String rocRef) - { - System.IntPtr rocRef_; - System.IntPtr __result__; - rocRef_ = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(rocRef); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallSystemIntPtr(this._nativePointer, (void *)rocRef_, (*(void ***)this._nativePointer)[6]); - System.Runtime.InteropServices.Marshal.FreeHGlobal(rocRef_); - return __result__; - } - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f16")] - public partial class IAvnGlSurfaceRenderingSession : SharpGen.Runtime.ComObject - { - public IAvnGlSurfaceRenderingSession(System.IntPtr nativePtr): base (nativePtr) - { - } - - public static explicit operator IAvnGlSurfaceRenderingSession(System.IntPtr nativePtr) => nativePtr == System.IntPtr.Zero ? null : new IAvnGlSurfaceRenderingSession(nativePtr); - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnGlSurfaceRenderingSession::GetPixelSize([In] AvnPixelSize* ret) - /// IAvnGlSurfaceRenderingSession::GetPixelSize - public unsafe Avalonia.Native.Interop.AvnPixelSize GetPixelSize() - { - Avalonia.Native.Interop.AvnPixelSize ret; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &ret, (*(void ***)this._nativePointer)[3]); - __result__.CheckError(); - return ret; - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnGlSurfaceRenderingSession::GetScaling([In] double* ret) - /// IAvnGlSurfaceRenderingSession::GetScaling - public unsafe System.Double GetScaling() - { - System.Double ret; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &ret, (*(void ***)this._nativePointer)[4]); - __result__.CheckError(); - return ret; - } - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f15")] - public partial class IAvnGlSurfaceRenderTarget : SharpGen.Runtime.ComObject - { - public IAvnGlSurfaceRenderTarget(System.IntPtr nativePtr): base (nativePtr) - { - } - - public static explicit operator IAvnGlSurfaceRenderTarget(System.IntPtr nativePtr) => nativePtr == System.IntPtr.Zero ? null : new IAvnGlSurfaceRenderTarget(nativePtr); - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnGlSurfaceRenderTarget::BeginDrawing([In] IAvnGlSurfaceRenderingSession** ret) - /// IAvnGlSurfaceRenderTarget::BeginDrawing - public unsafe Avalonia.Native.Interop.IAvnGlSurfaceRenderingSession BeginDrawing() - { - Avalonia.Native.Interop.IAvnGlSurfaceRenderingSession ret; - System.IntPtr ret_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &ret_, (*(void ***)this._nativePointer)[3]); - if (ret_ != System.IntPtr.Zero) - ret = new Avalonia.Native.Interop.IAvnGlSurfaceRenderingSession(ret_); - else - ret = null; - __result__.CheckError(); - return ret; - } - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f0a")] - public partial class IAvnLoopCancellation : SharpGen.Runtime.ComObject - { - public IAvnLoopCancellation(System.IntPtr nativePtr): base (nativePtr) - { - } - - public static explicit operator IAvnLoopCancellation(System.IntPtr nativePtr) => nativePtr == System.IntPtr.Zero ? null : new IAvnLoopCancellation(nativePtr); - /// - /// No documentation. - /// - /// void IAvnLoopCancellation::Cancel() - /// IAvnLoopCancellation::Cancel - public unsafe void Cancel() - { - Avalonia.Native.LocalInterop.CalliThisCallvoid(this._nativePointer, (*(void ***)this._nativePointer)[3]); - } - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f07")] - public partial class IAvnMacOptions : SharpGen.Runtime.ComObject - { - public IAvnMacOptions(System.IntPtr nativePtr): base (nativePtr) - { - } - - public static explicit operator IAvnMacOptions(System.IntPtr nativePtr) => nativePtr == System.IntPtr.Zero ? null : new IAvnMacOptions(nativePtr); - /// - /// No documentation. - /// - /// SetShowInDock - /// SetShowInDock - public System.Int32 ShowInDock - { - set => SetShowInDock(value); - } - - /// - /// No documentation. - /// - /// SetApplicationTitle - /// SetApplicationTitle - public System.IntPtr ApplicationTitle - { - set => SetApplicationTitle(value); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnMacOptions::SetShowInDock([In] int show) - /// IAvnMacOptions::SetShowInDock - internal unsafe void SetShowInDock(System.Int32 show) - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, show, (*(void ***)this._nativePointer)[3]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnMacOptions::SetApplicationTitle([In] void* utf8string) - /// IAvnMacOptions::SetApplicationTitle - internal unsafe void SetApplicationTitle(System.IntPtr utf8string) - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)utf8string, (*(void ***)this._nativePointer)[4]); - __result__.CheckError(); - } - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f17")] - public partial class IAvnMenu : SharpGen.Runtime.ComObject - { - public IAvnMenu(System.IntPtr nativePtr): base (nativePtr) - { - } - - public static explicit operator IAvnMenu(System.IntPtr nativePtr) => nativePtr == System.IntPtr.Zero ? null : new IAvnMenu(nativePtr); - /// - /// No documentation. - /// - /// SetTitle - /// SetTitle - public System.IntPtr Title - { - set => SetTitle(value); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// No documentation. - /// HRESULT IAvnMenu::InsertItem([In] int index,[In] IAvnMenuItem* item) - /// IAvnMenu::InsertItem - public unsafe void InsertItem(System.Int32 index, Avalonia.Native.Interop.IAvnMenuItem item) - { - System.IntPtr item_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - item_ = SharpGen.Runtime.CppObject.ToCallbackPtr(item); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, index, (void *)item_, (*(void ***)this._nativePointer)[3]); - System.GC.KeepAlive(item); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnMenu::RemoveItem([In] IAvnMenuItem* item) - /// IAvnMenu::RemoveItem - public unsafe void RemoveItem(Avalonia.Native.Interop.IAvnMenuItem item) - { - System.IntPtr item_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - item_ = SharpGen.Runtime.CppObject.ToCallbackPtr(item); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)item_, (*(void ***)this._nativePointer)[4]); - System.GC.KeepAlive(item); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnMenu::SetTitle([In] void* utf8String) - /// IAvnMenu::SetTitle - internal unsafe void SetTitle(System.IntPtr utf8String) - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)utf8String, (*(void ***)this._nativePointer)[5]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnMenu::Clear() - /// IAvnMenu::Clear - public unsafe void Clear() - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (*(void ***)this._nativePointer)[6]); - __result__.CheckError(); - } - } - - class IAvnMenuEventsShadow : SharpGen.Runtime.ComObjectShadow - { - protected unsafe class IAvnMenuEventsVtbl : SharpGen.Runtime.ComObjectShadow.ComObjectVtbl - { - public IAvnMenuEventsVtbl(int numberOfCallbackMethods): base (numberOfCallbackMethods + 1) - { - AddMethod(new NeedsUpdateDelegate(NeedsUpdate)); - } - - [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)] - private delegate void NeedsUpdateDelegate(System.IntPtr thisObject); - private static unsafe void NeedsUpdate(System.IntPtr thisObject) - { - try - { - IAvnMenuEvents @this = (IAvnMenuEvents)ToShadow(thisObject).Callback; - @this.NeedsUpdate(); - } - catch (System.Exception __exception__) - { - IAvnMenuEvents @this = (IAvnMenuEvents)ToShadow(thisObject).Callback; - (@this as SharpGen.Runtime.IExceptionCallback)?.RaiseException(__exception__); - } - } - } - - protected override SharpGen.Runtime.CppObjectVtbl Vtbl - { - get; - } - - = new Avalonia.Native.Interop.IAvnMenuEventsShadow.IAvnMenuEventsVtbl(0); - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f1A"), SharpGen.Runtime.ShadowAttribute(typeof (Avalonia.Native.Interop.IAvnMenuEventsShadow))] - public partial interface IAvnMenuEvents : SharpGen.Runtime.IUnknown - { - void NeedsUpdate(); - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f19")] - public partial class IAvnMenuItem : SharpGen.Runtime.ComObject - { - public IAvnMenuItem(System.IntPtr nativePtr): base (nativePtr) - { - } - - public static explicit operator IAvnMenuItem(System.IntPtr nativePtr) => nativePtr == System.IntPtr.Zero ? null : new IAvnMenuItem(nativePtr); - /// - /// No documentation. - /// - /// SetSubMenu - /// SetSubMenu - public Avalonia.Native.Interop.IAvnMenu SubMenu - { - set => SetSubMenu(value); - } - - /// - /// No documentation. - /// - /// SetTitle - /// SetTitle - public System.IntPtr Title - { - set => SetTitle(value); - } - - /// - /// No documentation. - /// - /// SetIsChecked - /// SetIsChecked - public System.Boolean IsChecked - { - set => SetIsChecked(value); - } - - /// - /// No documentation. - /// - /// SetToggleType - /// SetToggleType - public Avalonia.Native.Interop.AvnMenuItemToggleType ToggleType - { - set => SetToggleType(value); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnMenuItem::SetSubMenu([In] IAvnMenu* menu) - /// IAvnMenuItem::SetSubMenu - internal unsafe void SetSubMenu(Avalonia.Native.Interop.IAvnMenu menu) - { - System.IntPtr menu_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - menu_ = SharpGen.Runtime.CppObject.ToCallbackPtr(menu); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)menu_, (*(void ***)this._nativePointer)[3]); - System.GC.KeepAlive(menu); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnMenuItem::SetTitle([In] void* utf8String) - /// IAvnMenuItem::SetTitle - internal unsafe void SetTitle(System.IntPtr utf8String) - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)utf8String, (*(void ***)this._nativePointer)[4]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// No documentation. - /// HRESULT IAvnMenuItem::SetGesture([In] void* utf8String,[In] AvnInputModifiers modifiers) - /// IAvnMenuItem::SetGesture - public unsafe void SetGesture(System.IntPtr utf8String, Avalonia.Native.Interop.AvnInputModifiers modifiers) - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)utf8String, unchecked ((System.Int32)modifiers), (*(void ***)this._nativePointer)[5]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// No documentation. - /// HRESULT IAvnMenuItem::SetAction([In] IAvnPredicateCallback* predicate,[In] IAvnActionCallback* callback) - /// IAvnMenuItem::SetAction - public unsafe void SetAction(Avalonia.Native.Interop.IAvnPredicateCallback redicateRef, Avalonia.Native.Interop.IAvnActionCallback callback) - { - System.IntPtr redicateRef_ = System.IntPtr.Zero; - System.IntPtr callback_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - redicateRef_ = SharpGen.Runtime.CppObject.ToCallbackPtr(redicateRef); - callback_ = SharpGen.Runtime.CppObject.ToCallbackPtr(callback); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)redicateRef_, (void *)callback_, (*(void ***)this._nativePointer)[6]); - System.GC.KeepAlive(redicateRef); - System.GC.KeepAlive(callback); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnMenuItem::SetIsChecked([In] bool isChecked) - /// IAvnMenuItem::SetIsChecked - internal unsafe void SetIsChecked(System.Boolean isChecked) - { - System.Byte isChecked_; - SharpGen.Runtime.Result __result__; - isChecked_ = (System.Byte)(isChecked ? 1 : 0); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, isChecked_, (*(void ***)this._nativePointer)[7]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnMenuItem::SetToggleType([In] AvnMenuItemToggleType toggleType) - /// IAvnMenuItem::SetToggleType - internal unsafe void SetToggleType(Avalonia.Native.Interop.AvnMenuItemToggleType toggleType) - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, unchecked ((System.Int32)toggleType), (*(void ***)this._nativePointer)[8]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// No documentation. - /// HRESULT IAvnMenuItem::SetIcon([In] void* data,[In] size_t length) - /// IAvnMenuItem::SetIcon - public unsafe void SetIcon(System.IntPtr data, SharpGen.Runtime.PointerSize length) - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)data, (void *)length, (*(void ***)this._nativePointer)[9]); - __result__.CheckError(); - } - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f20")] - public partial class IAvnNativeControlHost : SharpGen.Runtime.ComObject - { - public IAvnNativeControlHost(System.IntPtr nativePtr): base (nativePtr) - { - } - - public static explicit operator IAvnNativeControlHost(System.IntPtr nativePtr) => nativePtr == System.IntPtr.Zero ? null : new IAvnNativeControlHost(nativePtr); - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnNativeControlHost::CreateDefaultChild([In] void* parent,[Out] void** retOut) - /// IAvnNativeControlHost::CreateDefaultChild - public unsafe System.IntPtr CreateDefaultChild(System.IntPtr arentRef) - { - System.IntPtr retOut; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)arentRef, &retOut, (*(void ***)this._nativePointer)[3]); - __result__.CheckError(); - return retOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// IAvnNativeControlHostTopLevelAttachment* IAvnNativeControlHost::CreateAttachment() - /// IAvnNativeControlHost::CreateAttachment - public unsafe Avalonia.Native.Interop.IAvnNativeControlHostTopLevelAttachment CreateAttachment() - { - Avalonia.Native.Interop.IAvnNativeControlHostTopLevelAttachment __result__; - System.IntPtr __result__native = System.IntPtr.Zero; - __result__native = Avalonia.Native.LocalInterop.CalliThisCallSystemIntPtr(this._nativePointer, (*(void ***)this._nativePointer)[4]); - if (__result__native != System.IntPtr.Zero) - __result__ = new Avalonia.Native.Interop.IAvnNativeControlHostTopLevelAttachment(__result__native); - else - __result__ = null; - return __result__; - } - - /// - /// No documentation. - /// - /// No documentation. - /// void IAvnNativeControlHost::DestroyDefaultChild([In] void* child) - /// IAvnNativeControlHost::DestroyDefaultChild - public unsafe void DestroyDefaultChild(System.IntPtr child) - { - Avalonia.Native.LocalInterop.CalliThisCallvoid(this._nativePointer, (void *)child, (*(void ***)this._nativePointer)[5]); - } - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f21")] - public partial class IAvnNativeControlHostTopLevelAttachment : SharpGen.Runtime.ComObject - { - public IAvnNativeControlHostTopLevelAttachment(System.IntPtr nativePtr): base (nativePtr) - { - } - - public static explicit operator IAvnNativeControlHostTopLevelAttachment(System.IntPtr nativePtr) => nativePtr == System.IntPtr.Zero ? null : new IAvnNativeControlHostTopLevelAttachment(nativePtr); - /// - /// No documentation. - /// - /// GetParentHandle - /// GetParentHandle - public System.IntPtr ParentHandle - { - get => GetParentHandle(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// void* IAvnNativeControlHostTopLevelAttachment::GetParentHandle() - /// IAvnNativeControlHostTopLevelAttachment::GetParentHandle - internal unsafe System.IntPtr GetParentHandle() - { - System.IntPtr __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallSystemIntPtr(this._nativePointer, (*(void ***)this._nativePointer)[3]); - return __result__; - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnNativeControlHostTopLevelAttachment::InitializeWithChildHandle([In] void* child) - /// IAvnNativeControlHostTopLevelAttachment::InitializeWithChildHandle - public unsafe void InitializeWithChildHandle(System.IntPtr child) - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)child, (*(void ***)this._nativePointer)[4]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnNativeControlHostTopLevelAttachment::AttachTo([In] IAvnNativeControlHost* host) - /// IAvnNativeControlHostTopLevelAttachment::AttachTo - public unsafe void AttachTo(Avalonia.Native.Interop.IAvnNativeControlHost host) - { - System.IntPtr host_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - host_ = SharpGen.Runtime.CppObject.ToCallbackPtr(host); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)host_, (*(void ***)this._nativePointer)[5]); - System.GC.KeepAlive(host); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// No documentation. - /// No documentation. - /// void IAvnNativeControlHostTopLevelAttachment::ShowInBounds([In] float x,[In] float y,[In] float width,[In] float height) - /// IAvnNativeControlHostTopLevelAttachment::ShowInBounds - public unsafe void ShowInBounds(System.Single x, System.Single y, System.Single width, System.Single height) - { - Avalonia.Native.LocalInterop.CalliThisCallvoid(this._nativePointer, x, y, width, height, (*(void ***)this._nativePointer)[6]); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// void IAvnNativeControlHostTopLevelAttachment::HideWithSize([In] float width,[In] float height) - /// IAvnNativeControlHostTopLevelAttachment::HideWithSize - public unsafe void HideWithSize(System.Single width, System.Single height) - { - Avalonia.Native.LocalInterop.CalliThisCallvoid(this._nativePointer, width, height, (*(void ***)this._nativePointer)[7]); - } - - /// - /// No documentation. - /// - /// void IAvnNativeControlHostTopLevelAttachment::ReleaseChild() - /// IAvnNativeControlHostTopLevelAttachment::ReleaseChild - public unsafe void ReleaseChild() - { - Avalonia.Native.LocalInterop.CalliThisCallvoid(this._nativePointer, (*(void ***)this._nativePointer)[8]); - } - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f0b")] - public partial class IAvnPlatformThreadingInterface : SharpGen.Runtime.ComObject - { - public IAvnPlatformThreadingInterface(System.IntPtr nativePtr): base (nativePtr) - { - } - - public static explicit operator IAvnPlatformThreadingInterface(System.IntPtr nativePtr) => nativePtr == System.IntPtr.Zero ? null : new IAvnPlatformThreadingInterface(nativePtr); - /// - /// No documentation. - /// - /// GetCurrentThreadIsLoopThread - /// GetCurrentThreadIsLoopThread - public System.Boolean CurrentThreadIsLoopThread - { - get => GetCurrentThreadIsLoopThread(); - } - - /// - /// No documentation. - /// - /// SetSignaledCallback - /// SetSignaledCallback - public Avalonia.Native.Interop.IAvnSignaledCallback SignaledCallback - { - set => SetSignaledCallback(value); - } - - /// - /// No documentation. - /// - /// No documentation. - /// bool IAvnPlatformThreadingInterface::GetCurrentThreadIsLoopThread() - /// IAvnPlatformThreadingInterface::GetCurrentThreadIsLoopThread - internal unsafe System.Boolean GetCurrentThreadIsLoopThread() - { - System.Boolean __result__; - System.Byte __result__native; - __result__native = Avalonia.Native.LocalInterop.CalliThisCallSystemByte(this._nativePointer, (*(void ***)this._nativePointer)[3]); - __result__ = __result__native != 0; - return __result__; - } - - /// - /// No documentation. - /// - /// No documentation. - /// void IAvnPlatformThreadingInterface::SetSignaledCallback([In] IAvnSignaledCallback* cb) - /// IAvnPlatformThreadingInterface::SetSignaledCallback - internal unsafe void SetSignaledCallback(Avalonia.Native.Interop.IAvnSignaledCallback cb) - { - System.IntPtr cb_ = System.IntPtr.Zero; - cb_ = SharpGen.Runtime.CppObject.ToCallbackPtr(cb); - Avalonia.Native.LocalInterop.CalliThisCallvoid(this._nativePointer, (void *)cb_, (*(void ***)this._nativePointer)[4]); - System.GC.KeepAlive(cb); - } - - /// - /// No documentation. - /// - /// No documentation. - /// IAvnLoopCancellation* IAvnPlatformThreadingInterface::CreateLoopCancellation() - /// IAvnPlatformThreadingInterface::CreateLoopCancellation - public unsafe Avalonia.Native.Interop.IAvnLoopCancellation CreateLoopCancellation() - { - Avalonia.Native.Interop.IAvnLoopCancellation __result__; - System.IntPtr __result__native = System.IntPtr.Zero; - __result__native = Avalonia.Native.LocalInterop.CalliThisCallSystemIntPtr(this._nativePointer, (*(void ***)this._nativePointer)[5]); - if (__result__native != System.IntPtr.Zero) - __result__ = new Avalonia.Native.Interop.IAvnLoopCancellation(__result__native); - else - __result__ = null; - return __result__; - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnPlatformThreadingInterface::RunLoop([In] IAvnLoopCancellation* cancel) - /// IAvnPlatformThreadingInterface::RunLoop - public unsafe void RunLoop(Avalonia.Native.Interop.IAvnLoopCancellation cancel) - { - System.IntPtr cancel_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - cancel_ = SharpGen.Runtime.CppObject.ToCallbackPtr(cancel); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)cancel_, (*(void ***)this._nativePointer)[6]); - System.GC.KeepAlive(cancel); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// void IAvnPlatformThreadingInterface::Signal([In] int priority) - /// IAvnPlatformThreadingInterface::Signal - public unsafe void Signal(System.Int32 priority) - { - Avalonia.Native.LocalInterop.CalliThisCallvoid(this._nativePointer, priority, (*(void ***)this._nativePointer)[7]); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// No documentation. - /// No documentation. - /// IUnknown* IAvnPlatformThreadingInterface::StartTimer([In] int priority,[In] int ms,[In] IAvnActionCallback* callback) - /// IAvnPlatformThreadingInterface::StartTimer - public unsafe SharpGen.Runtime.ComObject StartTimer(System.Int32 priority, System.Int32 ms, Avalonia.Native.Interop.IAvnActionCallback callback) - { - System.IntPtr callback_ = System.IntPtr.Zero; - SharpGen.Runtime.ComObject __result__; - System.IntPtr __result__native = System.IntPtr.Zero; - callback_ = SharpGen.Runtime.CppObject.ToCallbackPtr(callback); - __result__native = Avalonia.Native.LocalInterop.CalliThisCallSystemIntPtr(this._nativePointer, priority, ms, (void *)callback_, (*(void ***)this._nativePointer)[8]); - if (__result__native != System.IntPtr.Zero) - __result__ = new SharpGen.Runtime.ComObject(__result__native); - else - __result__ = null; - System.GC.KeepAlive(callback); - return __result__; - } - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f03")] - public partial class IAvnPopup : Avalonia.Native.Interop.IAvnWindowBase - { - public IAvnPopup(System.IntPtr nativePtr): base (nativePtr) - { - } - - public static explicit operator IAvnPopup(System.IntPtr nativePtr) => nativePtr == System.IntPtr.Zero ? null : new IAvnPopup(nativePtr); - } - - class IAvnPredicateCallbackShadow : SharpGen.Runtime.ComObjectShadow - { - protected unsafe class IAvnPredicateCallbackVtbl : SharpGen.Runtime.ComObjectShadow.ComObjectVtbl - { - public IAvnPredicateCallbackVtbl(int numberOfCallbackMethods): base (numberOfCallbackMethods + 1) - { - AddMethod(new EvaluateDelegate(Evaluate)); - } - - [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)] - private delegate System.Byte EvaluateDelegate(System.IntPtr thisObject); - private static unsafe System.Byte Evaluate(System.IntPtr thisObject) - { - try - { - System.Boolean __result__ = default (System.Boolean); - System.Byte __result__native; - IAvnPredicateCallback @this = (IAvnPredicateCallback)ToShadow(thisObject).Callback; - __result__ = @this.Evaluate(); - __result__native = (System.Byte)(__result__ ? 1 : 0); - return __result__native; - } - catch (System.Exception __exception__) - { - IAvnPredicateCallback @this = (IAvnPredicateCallback)ToShadow(thisObject).Callback; - (@this as SharpGen.Runtime.IExceptionCallback)?.RaiseException(__exception__); - return default (System.Byte); - } - } - } - - protected override SharpGen.Runtime.CppObjectVtbl Vtbl - { - get; - } - - = new Avalonia.Native.Interop.IAvnPredicateCallbackShadow.IAvnPredicateCallbackVtbl(0); - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f18"), SharpGen.Runtime.ShadowAttribute(typeof (Avalonia.Native.Interop.IAvnPredicateCallbackShadow))] - public partial interface IAvnPredicateCallback : SharpGen.Runtime.IUnknown - { - System.Boolean Evaluate(); - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f0e")] - public partial class IAvnScreens : SharpGen.Runtime.ComObject - { - public IAvnScreens(System.IntPtr nativePtr): base (nativePtr) - { - } - - public static explicit operator IAvnScreens(System.IntPtr nativePtr) => nativePtr == System.IntPtr.Zero ? null : new IAvnScreens(nativePtr); - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnScreens::GetScreenCount([In] int* ret) - /// IAvnScreens::GetScreenCount - public unsafe System.Int32 GetScreenCount() - { - System.Int32 ret; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &ret, (*(void ***)this._nativePointer)[3]); - __result__.CheckError(); - return ret; - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnScreens::GetScreen([In] int index,[In] AvnScreen* ret) - /// IAvnScreens::GetScreen - public unsafe Avalonia.Native.Interop.AvnScreen GetScreen(System.Int32 index) - { - Avalonia.Native.Interop.AvnScreen ret; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, index, &ret, (*(void ***)this._nativePointer)[4]); - __result__.CheckError(); - return ret; - } - } - - class IAvnSignaledCallbackShadow : SharpGen.Runtime.ComObjectShadow - { - protected unsafe class IAvnSignaledCallbackVtbl : SharpGen.Runtime.ComObjectShadow.ComObjectVtbl - { - public IAvnSignaledCallbackVtbl(int numberOfCallbackMethods): base (numberOfCallbackMethods + 1) - { - AddMethod(new SignaledDelegate(Signaled)); - } - - [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)] - private delegate void SignaledDelegate(System.IntPtr thisObject, int arg0, System.Byte arg1); - private static unsafe void Signaled(System.IntPtr thisObject, int param0, System.Byte param1) - { - try - { - System.Int32 priority = default (System.Int32); - priority = (System.Int32)param0; - System.Boolean priorityContainsMeaningfulValue = default (System.Boolean); - System.Byte priorityContainsMeaningfulValue_ = (System.Byte)param1; - IAvnSignaledCallback @this = (IAvnSignaledCallback)ToShadow(thisObject).Callback; - priorityContainsMeaningfulValue = priorityContainsMeaningfulValue_ != 0; - @this.Signaled(priority, priorityContainsMeaningfulValue); - } - catch (System.Exception __exception__) - { - IAvnSignaledCallback @this = (IAvnSignaledCallback)ToShadow(thisObject).Callback; - (@this as SharpGen.Runtime.IExceptionCallback)?.RaiseException(__exception__); - } - } - } - - protected override SharpGen.Runtime.CppObjectVtbl Vtbl - { - get; - } - - = new Avalonia.Native.Interop.IAvnSignaledCallbackShadow.IAvnSignaledCallbackVtbl(0); - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f09"), SharpGen.Runtime.ShadowAttribute(typeof (Avalonia.Native.Interop.IAvnSignaledCallbackShadow))] - public partial interface IAvnSignaledCallback : SharpGen.Runtime.IUnknown - { - void Signaled(System.Int32 priority, System.Boolean priorityContainsMeaningfulValue); - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f17")] - public partial class IAvnString : SharpGen.Runtime.ComObject - { - public IAvnString(System.IntPtr nativePtr): base (nativePtr) - { - } - - public static explicit operator IAvnString(System.IntPtr nativePtr) => nativePtr == System.IntPtr.Zero ? null : new IAvnString(nativePtr); - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnString::Pointer([Out] void** retOut) - /// IAvnString::Pointer - public unsafe System.IntPtr Pointer() - { - System.IntPtr retOut; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &retOut, (*(void ***)this._nativePointer)[3]); - __result__.CheckError(); - return retOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnString::Length([In] int* ret) - /// IAvnString::Length - public unsafe System.Int32 Length() - { - System.Int32 ret; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &ret, (*(void ***)this._nativePointer)[4]); - __result__.CheckError(); - return ret; - } - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f20")] - public partial class IAvnStringArray : SharpGen.Runtime.ComObject - { - public IAvnStringArray(System.IntPtr nativePtr): base (nativePtr) - { - } - - public static explicit operator IAvnStringArray(System.IntPtr nativePtr) => nativePtr == System.IntPtr.Zero ? null : new IAvnStringArray(nativePtr); - /// - /// No documentation. - /// - /// GetCount - /// GetCount - public System.UInt32 Count - { - get => GetCount(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// unsigned int IAvnStringArray::GetCount() - /// IAvnStringArray::GetCount - internal unsafe System.UInt32 GetCount() - { - System.UInt32 __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallSystemUInt32(this._nativePointer, (*(void ***)this._nativePointer)[3]); - return __result__; - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnStringArray::Get([In] unsigned int index,[In] IAvnString** ppv) - /// IAvnStringArray::Get - public unsafe Avalonia.Native.Interop.IAvnString Get(System.UInt32 index) - { - Avalonia.Native.Interop.IAvnString vOut; - System.IntPtr vOut_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, index, &vOut_, (*(void ***)this._nativePointer)[4]); - if (vOut_ != System.IntPtr.Zero) - vOut = new Avalonia.Native.Interop.IAvnString(vOut_); - else - vOut = null; - __result__.CheckError(); - return vOut; - } - } - - class IAvnSystemDialogEventsShadow : SharpGen.Runtime.ComObjectShadow - { - protected unsafe class IAvnSystemDialogEventsVtbl : SharpGen.Runtime.ComObjectShadow.ComObjectVtbl - { - public IAvnSystemDialogEventsVtbl(int numberOfCallbackMethods): base (numberOfCallbackMethods + 1) - { - AddMethod(new OnCompletedDelegate(OnCompleted)); - } - - [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)] - private delegate void OnCompletedDelegate(System.IntPtr thisObject, int arg0, void *arg1); - private static unsafe void OnCompleted(System.IntPtr thisObject, int param0, void *param1) - { - try - { - System.Int32 numResults = default (System.Int32); - numResults = (System.Int32)param0; - System.IntPtr trFirstResultRef = default (System.IntPtr); - trFirstResultRef = (System.IntPtr)param1; - IAvnSystemDialogEvents @this = (IAvnSystemDialogEvents)ToShadow(thisObject).Callback; - @this.OnCompleted(numResults, trFirstResultRef); - } - catch (System.Exception __exception__) - { - IAvnSystemDialogEvents @this = (IAvnSystemDialogEvents)ToShadow(thisObject).Callback; - (@this as SharpGen.Runtime.IExceptionCallback)?.RaiseException(__exception__); - } - } - } - - protected override SharpGen.Runtime.CppObjectVtbl Vtbl - { - get; - } - - = new Avalonia.Native.Interop.IAvnSystemDialogEventsShadow.IAvnSystemDialogEventsVtbl(0); - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f0c"), SharpGen.Runtime.ShadowAttribute(typeof (Avalonia.Native.Interop.IAvnSystemDialogEventsShadow))] - public partial interface IAvnSystemDialogEvents : SharpGen.Runtime.IUnknown - { - void OnCompleted(System.Int32 numResults, System.IntPtr trFirstResultRef); - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f0d")] - public partial class IAvnSystemDialogs : SharpGen.Runtime.ComObject - { - public IAvnSystemDialogs(System.IntPtr nativePtr): base (nativePtr) - { - } - - public static explicit operator IAvnSystemDialogs(System.IntPtr nativePtr) => nativePtr == System.IntPtr.Zero ? null : new IAvnSystemDialogs(nativePtr); - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// No documentation. - /// No documentation. - /// void IAvnSystemDialogs::SelectFolderDialog([In] IAvnWindow* parentWindowHandle,[In] IAvnSystemDialogEvents* events,[In] const char* title,[In] const char* initialPath) - /// IAvnSystemDialogs::SelectFolderDialog - public unsafe void SelectFolderDialog(Avalonia.Native.Interop.IAvnWindow arentWindowHandleRef, Avalonia.Native.Interop.IAvnSystemDialogEvents events, System.String title, System.String initialPath) - { - System.IntPtr arentWindowHandleRef_ = System.IntPtr.Zero; - System.IntPtr events_ = System.IntPtr.Zero; - System.IntPtr title_; - System.IntPtr initialPath_; - arentWindowHandleRef_ = SharpGen.Runtime.CppObject.ToCallbackPtr(arentWindowHandleRef); - events_ = SharpGen.Runtime.CppObject.ToCallbackPtr(events); - title_ = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(title); - initialPath_ = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(initialPath); - Avalonia.Native.LocalInterop.CalliThisCallvoid(this._nativePointer, (void *)arentWindowHandleRef_, (void *)events_, (void *)title_, (void *)initialPath_, (*(void ***)this._nativePointer)[3]); - System.GC.KeepAlive(arentWindowHandleRef); - System.GC.KeepAlive(events); - System.Runtime.InteropServices.Marshal.FreeHGlobal(title_); - System.Runtime.InteropServices.Marshal.FreeHGlobal(initialPath_); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// No documentation. - /// No documentation. - /// No documentation. - /// No documentation. - /// No documentation. - /// void IAvnSystemDialogs::OpenFileDialog([In] IAvnWindow* parentWindowHandle,[In] IAvnSystemDialogEvents* events,[In] bool allowMultiple,[In] const char* title,[In] const char* initialDirectory,[In] const char* initialFile,[In] const char* filters) - /// IAvnSystemDialogs::OpenFileDialog - public unsafe void OpenFileDialog(Avalonia.Native.Interop.IAvnWindow arentWindowHandleRef, Avalonia.Native.Interop.IAvnSystemDialogEvents events, System.Boolean allowMultiple, System.String title, System.String initialDirectory, System.String initialFile, System.String filters) - { - System.IntPtr arentWindowHandleRef_ = System.IntPtr.Zero; - System.IntPtr events_ = System.IntPtr.Zero; - System.Byte allowMultiple_; - System.IntPtr title_; - System.IntPtr initialDirectory_; - System.IntPtr initialFile_; - System.IntPtr filters_; - arentWindowHandleRef_ = SharpGen.Runtime.CppObject.ToCallbackPtr(arentWindowHandleRef); - events_ = SharpGen.Runtime.CppObject.ToCallbackPtr(events); - allowMultiple_ = (System.Byte)(allowMultiple ? 1 : 0); - title_ = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(title); - initialDirectory_ = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(initialDirectory); - initialFile_ = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(initialFile); - filters_ = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(filters); - Avalonia.Native.LocalInterop.CalliThisCallvoid(this._nativePointer, (void *)arentWindowHandleRef_, (void *)events_, allowMultiple_, (void *)title_, (void *)initialDirectory_, (void *)initialFile_, (void *)filters_, (*(void ***)this._nativePointer)[4]); - System.GC.KeepAlive(arentWindowHandleRef); - System.GC.KeepAlive(events); - System.Runtime.InteropServices.Marshal.FreeHGlobal(title_); - System.Runtime.InteropServices.Marshal.FreeHGlobal(initialDirectory_); - System.Runtime.InteropServices.Marshal.FreeHGlobal(initialFile_); - System.Runtime.InteropServices.Marshal.FreeHGlobal(filters_); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// No documentation. - /// No documentation. - /// No documentation. - /// No documentation. - /// void IAvnSystemDialogs::SaveFileDialog([In] IAvnWindow* parentWindowHandle,[In] IAvnSystemDialogEvents* events,[In] const char* title,[In] const char* initialDirectory,[In] const char* initialFile,[In] const char* filters) - /// IAvnSystemDialogs::SaveFileDialog - public unsafe void SaveFileDialog(Avalonia.Native.Interop.IAvnWindow arentWindowHandleRef, Avalonia.Native.Interop.IAvnSystemDialogEvents events, System.String title, System.String initialDirectory, System.String initialFile, System.String filters) - { - System.IntPtr arentWindowHandleRef_ = System.IntPtr.Zero; - System.IntPtr events_ = System.IntPtr.Zero; - System.IntPtr title_; - System.IntPtr initialDirectory_; - System.IntPtr initialFile_; - System.IntPtr filters_; - arentWindowHandleRef_ = SharpGen.Runtime.CppObject.ToCallbackPtr(arentWindowHandleRef); - events_ = SharpGen.Runtime.CppObject.ToCallbackPtr(events); - title_ = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(title); - initialDirectory_ = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(initialDirectory); - initialFile_ = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(initialFile); - filters_ = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(filters); - Avalonia.Native.LocalInterop.CalliThisCallvoid(this._nativePointer, (void *)arentWindowHandleRef_, (void *)events_, (void *)title_, (void *)initialDirectory_, (void *)initialFile_, (void *)filters_, (*(void ***)this._nativePointer)[5]); - System.GC.KeepAlive(arentWindowHandleRef); - System.GC.KeepAlive(events); - System.Runtime.InteropServices.Marshal.FreeHGlobal(title_); - System.Runtime.InteropServices.Marshal.FreeHGlobal(initialDirectory_); - System.Runtime.InteropServices.Marshal.FreeHGlobal(initialFile_); - System.Runtime.InteropServices.Marshal.FreeHGlobal(filters_); - } - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f04")] - public partial class IAvnWindow : Avalonia.Native.Interop.IAvnWindowBase - { - public IAvnWindow(System.IntPtr nativePtr): base (nativePtr) - { - } - - public static explicit operator IAvnWindow(System.IntPtr nativePtr) => nativePtr == System.IntPtr.Zero ? null : new IAvnWindow(nativePtr); - /// - /// No documentation. - /// - /// SetEnabled - /// SetEnabled - public System.Boolean Enabled - { - set => SetEnabled(value); - } - - /// - /// No documentation. - /// - /// SetParent - /// SetParent - public Avalonia.Native.Interop.IAvnWindow Parent - { - set => SetParent(value); - } - - /// - /// No documentation. - /// - /// SetCanResize - /// SetCanResize - public System.Boolean CanResize - { - set => SetCanResize(value); - } - - /// - /// No documentation. - /// - /// SetDecorations - /// SetDecorations - public Avalonia.Native.Interop.SystemDecorations Decorations - { - set => SetDecorations(value); - } - - /// - /// No documentation. - /// - /// SetTitle - /// SetTitle - public System.IntPtr Title - { - set => SetTitle(value); - } - - /// - /// No documentation. - /// - /// SetTitleBarColor - /// SetTitleBarColor - public Avalonia.Native.Interop.AvnColor TitleBarColor - { - set => SetTitleBarColor(value); - } - - /// - /// No documentation. - /// - /// SetExtendClientArea - /// SetExtendClientArea - public System.Boolean ExtendClientArea - { - set => SetExtendClientArea(value); - } - - /// - /// No documentation. - /// - /// SetExtendClientAreaHints - /// SetExtendClientAreaHints - public Avalonia.Native.Interop.AvnExtendClientAreaChromeHints ExtendClientAreaHints - { - set => SetExtendClientAreaHints(value); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnWindow::SetEnabled([In] bool enable) - /// IAvnWindow::SetEnabled - internal unsafe void SetEnabled(System.Boolean enable) - { - System.Byte enable_; - SharpGen.Runtime.Result __result__; - enable_ = (System.Byte)(enable ? 1 : 0); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, enable_, (*(void ***)this._nativePointer)[30]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnWindow::SetParent([In] IAvnWindow* parent) - /// IAvnWindow::SetParent - internal unsafe void SetParent(Avalonia.Native.Interop.IAvnWindow arentRef) - { - System.IntPtr arentRef_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - arentRef_ = SharpGen.Runtime.CppObject.ToCallbackPtr(arentRef); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)arentRef_, (*(void ***)this._nativePointer)[31]); - System.GC.KeepAlive(arentRef); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnWindow::SetCanResize([In] bool value) - /// IAvnWindow::SetCanResize - internal unsafe void SetCanResize(System.Boolean value) - { - System.Byte value_; - SharpGen.Runtime.Result __result__; - value_ = (System.Byte)(value ? 1 : 0); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, value_, (*(void ***)this._nativePointer)[32]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnWindow::SetDecorations([In] SystemDecorations value) - /// IAvnWindow::SetDecorations - internal unsafe void SetDecorations(Avalonia.Native.Interop.SystemDecorations value) - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, unchecked ((System.Int32)value), (*(void ***)this._nativePointer)[33]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnWindow::SetTitle([In] void* utf8Title) - /// IAvnWindow::SetTitle - internal unsafe void SetTitle(System.IntPtr utf8Title) - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)utf8Title, (*(void ***)this._nativePointer)[34]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnWindow::SetTitleBarColor([In] AvnColor color) - /// IAvnWindow::SetTitleBarColor - internal unsafe void SetTitleBarColor(Avalonia.Native.Interop.AvnColor color) - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint0(this._nativePointer, color, (*(void ***)this._nativePointer)[35]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnWindow::SetWindowState([In] AvnWindowState state) - /// IAvnWindow::SetWindowState - public unsafe void SetWindowState(Avalonia.Native.Interop.AvnWindowState state) - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, unchecked ((System.Int32)state), (*(void ***)this._nativePointer)[36]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnWindow::GetWindowState([In] AvnWindowState* ret) - /// IAvnWindow::GetWindowState - public unsafe Avalonia.Native.Interop.AvnWindowState GetWindowState() - { - Avalonia.Native.Interop.AvnWindowState ret; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &ret, (*(void ***)this._nativePointer)[37]); - __result__.CheckError(); - return ret; - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnWindow::TakeFocusFromChildren() - /// IAvnWindow::TakeFocusFromChildren - public unsafe void TakeFocusFromChildren() - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (*(void ***)this._nativePointer)[38]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnWindow::SetExtendClientArea([In] bool enable) - /// IAvnWindow::SetExtendClientArea - internal unsafe void SetExtendClientArea(System.Boolean enable) - { - System.Byte enable_; - SharpGen.Runtime.Result __result__; - enable_ = (System.Byte)(enable ? 1 : 0); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, enable_, (*(void ***)this._nativePointer)[39]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnWindow::SetExtendClientAreaHints([In] AvnExtendClientAreaChromeHints hints) - /// IAvnWindow::SetExtendClientAreaHints - internal unsafe void SetExtendClientAreaHints(Avalonia.Native.Interop.AvnExtendClientAreaChromeHints hints) - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, unchecked ((System.Int32)hints), (*(void ***)this._nativePointer)[40]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnWindow::GetExtendTitleBarHeight([In] double* ret) - /// IAvnWindow::GetExtendTitleBarHeight - public unsafe System.Double GetExtendTitleBarHeight() - { - System.Double ret; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &ret, (*(void ***)this._nativePointer)[41]); - __result__.CheckError(); - return ret; - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnWindow::SetExtendTitleBarHeight([In] double value) - /// IAvnWindow::SetExtendTitleBarHeight - public unsafe void SetExtendTitleBarHeight(System.Double value) - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, value, (*(void ***)this._nativePointer)[42]); - __result__.CheckError(); - } - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f02")] - public partial class IAvnWindowBase : SharpGen.Runtime.ComObject - { - public IAvnWindowBase(System.IntPtr nativePtr): base (nativePtr) - { - } - - public static explicit operator IAvnWindowBase(System.IntPtr nativePtr) => nativePtr == System.IntPtr.Zero ? null : new IAvnWindowBase(nativePtr); - /// - /// No documentation. - /// - /// SetTopMost - /// SetTopMost - public System.Boolean TopMost - { - set => SetTopMost(value); - } - - /// - /// No documentation. - /// - /// SetCursor - /// SetCursor - public Avalonia.Native.Interop.IAvnCursor Cursor - { - set => SetCursor(value); - } - - /// - /// No documentation. - /// - /// SetMainMenu - /// SetMainMenu - public Avalonia.Native.Interop.IAvnMenu MainMenu - { - set => SetMainMenu(value); - } - - /// - /// No documentation. - /// - /// SetBlurEnabled - /// SetBlurEnabled - public System.Boolean BlurEnabled - { - set => SetBlurEnabled(value); - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnWindowBase::Show() - /// IAvnWindowBase::Show - public unsafe void Show() - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (*(void ***)this._nativePointer)[3]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnWindowBase::Hide() - /// IAvnWindowBase::Hide - public unsafe void Hide() - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (*(void ***)this._nativePointer)[4]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnWindowBase::Close() - /// IAvnWindowBase::Close - public unsafe void Close() - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (*(void ***)this._nativePointer)[5]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnWindowBase::Activate() - /// IAvnWindowBase::Activate - public unsafe void Activate() - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (*(void ***)this._nativePointer)[6]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnWindowBase::GetClientSize([In] AvnSize* ret) - /// IAvnWindowBase::GetClientSize - public unsafe Avalonia.Native.Interop.AvnSize GetClientSize() - { - Avalonia.Native.Interop.AvnSize ret; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &ret, (*(void ***)this._nativePointer)[7]); - __result__.CheckError(); - return ret; - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnWindowBase::GetScaling([In] double* ret) - /// IAvnWindowBase::GetScaling - public unsafe System.Double GetScaling() - { - System.Double ret; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &ret, (*(void ***)this._nativePointer)[8]); - __result__.CheckError(); - return ret; - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// No documentation. - /// HRESULT IAvnWindowBase::SetMinMaxSize([In] AvnSize minSize,[In] AvnSize maxSize) - /// IAvnWindowBase::SetMinMaxSize - public unsafe void SetMinMaxSize(Avalonia.Native.Interop.AvnSize minSize, Avalonia.Native.Interop.AvnSize maxSize) - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint0(this._nativePointer, minSize, maxSize, (*(void ***)this._nativePointer)[9]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// No documentation. - /// HRESULT IAvnWindowBase::Resize([In] double width,[In] double height) - /// IAvnWindowBase::Resize - public unsafe void Resize(System.Double width, System.Double height) - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, width, height, (*(void ***)this._nativePointer)[10]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnWindowBase::Invalidate([In] AvnRect rect) - /// IAvnWindowBase::Invalidate - public unsafe void Invalidate(Avalonia.Native.Interop.AvnRect rect) - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint0(this._nativePointer, rect, (*(void ***)this._nativePointer)[11]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnWindowBase::BeginMoveDrag() - /// IAvnWindowBase::BeginMoveDrag - public unsafe void BeginMoveDrag() - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (*(void ***)this._nativePointer)[12]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnWindowBase::BeginResizeDrag([In] AvnWindowEdge edge) - /// IAvnWindowBase::BeginResizeDrag - public unsafe void BeginResizeDrag(Avalonia.Native.Interop.AvnWindowEdge edge) - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, unchecked ((System.Int32)edge), (*(void ***)this._nativePointer)[13]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnWindowBase::GetPosition([In] AvnPoint* ret) - /// IAvnWindowBase::GetPosition - public unsafe Avalonia.Native.Interop.AvnPoint GetPosition() - { - Avalonia.Native.Interop.AvnPoint ret; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &ret, (*(void ***)this._nativePointer)[14]); - __result__.CheckError(); - return ret; - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnWindowBase::SetPosition([In] AvnPoint point) - /// IAvnWindowBase::SetPosition - public unsafe void SetPosition(Avalonia.Native.Interop.AvnPoint point) - { - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint0(this._nativePointer, point, (*(void ***)this._nativePointer)[15]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnWindowBase::PointToClient([In] AvnPoint point,[In] AvnPoint* ret) - /// IAvnWindowBase::PointToClient - public unsafe Avalonia.Native.Interop.AvnPoint PointToClient(Avalonia.Native.Interop.AvnPoint point) - { - Avalonia.Native.Interop.AvnPoint ret; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint0(this._nativePointer, point, &ret, (*(void ***)this._nativePointer)[16]); - __result__.CheckError(); - return ret; - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnWindowBase::PointToScreen([In] AvnPoint point,[In] AvnPoint* ret) - /// IAvnWindowBase::PointToScreen - public unsafe Avalonia.Native.Interop.AvnPoint PointToScreen(Avalonia.Native.Interop.AvnPoint point) - { - Avalonia.Native.Interop.AvnPoint ret; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint0(this._nativePointer, point, &ret, (*(void ***)this._nativePointer)[17]); - __result__.CheckError(); - return ret; - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// No documentation. - /// HRESULT IAvnWindowBase::ThreadSafeSetSwRenderedFrame([In] AvnFramebuffer* fb,[In] IUnknown* dispose) - /// IAvnWindowBase::ThreadSafeSetSwRenderedFrame - public unsafe void ThreadSafeSetSwRenderedFrame(ref Avalonia.Native.Interop.AvnFramebuffer fb, SharpGen.Runtime.IUnknown dispose) - { - System.IntPtr dispose_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - dispose_ = SharpGen.Runtime.CppObject.ToCallbackPtr(dispose); - fixed (void *fb_ = &fb) - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, fb_, (void *)dispose_, (*(void ***)this._nativePointer)[18]); - System.GC.KeepAlive(dispose); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnWindowBase::SetTopMost([In] bool value) - /// IAvnWindowBase::SetTopMost - internal unsafe void SetTopMost(System.Boolean value) - { - System.Byte value_; - SharpGen.Runtime.Result __result__; - value_ = (System.Byte)(value ? 1 : 0); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, value_, (*(void ***)this._nativePointer)[19]); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnWindowBase::SetCursor([In] IAvnCursor* cursor) - /// IAvnWindowBase::SetCursor - internal unsafe void SetCursor(Avalonia.Native.Interop.IAvnCursor cursor) - { - System.IntPtr cursor_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - cursor_ = SharpGen.Runtime.CppObject.ToCallbackPtr(cursor); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)cursor_, (*(void ***)this._nativePointer)[20]); - System.GC.KeepAlive(cursor); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnWindowBase::CreateGlRenderTarget([In] IAvnGlSurfaceRenderTarget** ret) - /// IAvnWindowBase::CreateGlRenderTarget - public unsafe Avalonia.Native.Interop.IAvnGlSurfaceRenderTarget CreateGlRenderTarget() - { - Avalonia.Native.Interop.IAvnGlSurfaceRenderTarget ret; - System.IntPtr ret_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &ret_, (*(void ***)this._nativePointer)[21]); - if (ret_ != System.IntPtr.Zero) - ret = new Avalonia.Native.Interop.IAvnGlSurfaceRenderTarget(ret_); - else - ret = null; - __result__.CheckError(); - return ret; - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnWindowBase::SetMainMenu([In] IAvnMenu* menu) - /// IAvnWindowBase::SetMainMenu - internal unsafe void SetMainMenu(Avalonia.Native.Interop.IAvnMenu menu) - { - System.IntPtr menu_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - menu_ = SharpGen.Runtime.CppObject.ToCallbackPtr(menu); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, (void *)menu_, (*(void ***)this._nativePointer)[22]); - System.GC.KeepAlive(menu); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnWindowBase::ObtainNSWindowHandle([Out] void** retOut) - /// IAvnWindowBase::ObtainNSWindowHandle - public unsafe System.IntPtr ObtainNSWindowHandle() - { - System.IntPtr retOut; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &retOut, (*(void ***)this._nativePointer)[23]); - __result__.CheckError(); - return retOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnWindowBase::ObtainNSWindowHandleRetained([Out] void** retOut) - /// IAvnWindowBase::ObtainNSWindowHandleRetained - public unsafe System.IntPtr ObtainNSWindowHandleRetained() - { - System.IntPtr retOut; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &retOut, (*(void ***)this._nativePointer)[24]); - __result__.CheckError(); - return retOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnWindowBase::ObtainNSViewHandle([Out] void** retOut) - /// IAvnWindowBase::ObtainNSViewHandle - public unsafe System.IntPtr ObtainNSViewHandle() - { - System.IntPtr retOut; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &retOut, (*(void ***)this._nativePointer)[25]); - __result__.CheckError(); - return retOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnWindowBase::ObtainNSViewHandleRetained([Out] void** retOut) - /// IAvnWindowBase::ObtainNSViewHandleRetained - public unsafe System.IntPtr ObtainNSViewHandleRetained() - { - System.IntPtr retOut; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &retOut, (*(void ***)this._nativePointer)[26]); - __result__.CheckError(); - return retOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// HRESULT IAvnWindowBase::CreateNativeControlHost([Out] IAvnNativeControlHost** retOut) - /// IAvnWindowBase::CreateNativeControlHost - public unsafe Avalonia.Native.Interop.IAvnNativeControlHost CreateNativeControlHost() - { - Avalonia.Native.Interop.IAvnNativeControlHost retOut; - System.IntPtr retOut_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, &retOut_, (*(void ***)this._nativePointer)[27]); - if (retOut_ != System.IntPtr.Zero) - retOut = new Avalonia.Native.Interop.IAvnNativeControlHost(retOut_); - else - retOut = null; - __result__.CheckError(); - return retOut; - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// No documentation. - /// No documentation. - /// No documentation. - /// No documentation. - /// HRESULT IAvnWindowBase::BeginDragAndDropOperation([In] AvnDragDropEffects effects,[In] AvnPoint point,[In] IAvnClipboard* clipboard,[In] IAvnDndResultCallback* cb,[In] void* sourceHandle) - /// IAvnWindowBase::BeginDragAndDropOperation - public unsafe void BeginDragAndDropOperation(Avalonia.Native.Interop.AvnDragDropEffects effects, Avalonia.Native.Interop.AvnPoint point, Avalonia.Native.Interop.IAvnClipboard clipboard, Avalonia.Native.Interop.IAvnDndResultCallback cb, System.IntPtr sourceHandle) - { - System.IntPtr clipboard_ = System.IntPtr.Zero; - System.IntPtr cb_ = System.IntPtr.Zero; - SharpGen.Runtime.Result __result__; - clipboard_ = SharpGen.Runtime.CppObject.ToCallbackPtr(clipboard); - cb_ = SharpGen.Runtime.CppObject.ToCallbackPtr(cb); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint0(this._nativePointer, unchecked ((System.Int32)effects), point, (void *)clipboard_, (void *)cb_, (void *)sourceHandle, (*(void ***)this._nativePointer)[28]); - System.GC.KeepAlive(clipboard); - System.GC.KeepAlive(cb); - __result__.CheckError(); - } - - /// - /// No documentation. - /// - /// No documentation. - /// No documentation. - /// HRESULT IAvnWindowBase::SetBlurEnabled([In] bool enable) - /// IAvnWindowBase::SetBlurEnabled - internal unsafe void SetBlurEnabled(System.Boolean enable) - { - System.Byte enable_; - SharpGen.Runtime.Result __result__; - enable_ = (System.Byte)(enable ? 1 : 0); - __result__ = Avalonia.Native.LocalInterop.CalliThisCallint(this._nativePointer, enable_, (*(void ***)this._nativePointer)[29]); - __result__.CheckError(); - } - } - - class IAvnWindowBaseEventsShadow : SharpGen.Runtime.ComObjectShadow - { - protected unsafe class IAvnWindowBaseEventsVtbl : SharpGen.Runtime.ComObjectShadow.ComObjectVtbl - { - public IAvnWindowBaseEventsVtbl(int numberOfCallbackMethods): base (numberOfCallbackMethods + 13) - { - AddMethod(new PaintDelegate(Paint)); - AddMethod(new ClosedDelegate(Closed)); - AddMethod(new ActivatedDelegate(Activated)); - AddMethod(new DeactivatedDelegate(Deactivated)); - AddMethod(new ResizedDelegate(Resized)); - AddMethod(new PositionChangedDelegate(PositionChanged)); - AddMethod(new RawMouseEventDelegate(RawMouseEvent)); - AddMethod(new RawKeyEventDelegate(RawKeyEvent)); - AddMethod(new RawTextInputEventDelegate(RawTextInputEvent)); - AddMethod(new ScalingChangedDelegate(ScalingChanged)); - AddMethod(new RunRenderPriorityJobsDelegate(RunRenderPriorityJobs)); - AddMethod(new LostFocusDelegate(LostFocus)); - AddMethod(new DragEventDelegate(DragEvent)); - } - - [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)] - private delegate int PaintDelegate(System.IntPtr thisObject); - private static unsafe int Paint(System.IntPtr thisObject) - { - try - { - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - @this.Paint(); - return SharpGen.Runtime.Result.Ok.Code; - } - catch (System.Exception __exception__) - { - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - (@this as SharpGen.Runtime.IExceptionCallback)?.RaiseException(__exception__); - return SharpGen.Runtime.Result.GetResultFromException(__exception__).Code; - } - } - - [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)] - private delegate void ClosedDelegate(System.IntPtr thisObject); - private static unsafe void Closed(System.IntPtr thisObject) - { - try - { - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - @this.Closed(); - } - catch (System.Exception __exception__) - { - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - (@this as SharpGen.Runtime.IExceptionCallback)?.RaiseException(__exception__); - } - } - - [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)] - private delegate void ActivatedDelegate(System.IntPtr thisObject); - private static unsafe void Activated(System.IntPtr thisObject) - { - try - { - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - @this.Activated(); - } - catch (System.Exception __exception__) - { - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - (@this as SharpGen.Runtime.IExceptionCallback)?.RaiseException(__exception__); - } - } - - [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)] - private delegate void DeactivatedDelegate(System.IntPtr thisObject); - private static unsafe void Deactivated(System.IntPtr thisObject) - { - try - { - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - @this.Deactivated(); - } - catch (System.Exception __exception__) - { - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - (@this as SharpGen.Runtime.IExceptionCallback)?.RaiseException(__exception__); - } - } - - [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)] - private delegate void ResizedDelegate(System.IntPtr thisObject, void *arg0); - private static unsafe void Resized(System.IntPtr thisObject, void *param0) - { - try - { - Avalonia.Native.Interop.AvnSize size = System.Runtime.CompilerServices.Unsafe.AsRef(param0); - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - @this.Resized(size); - } - catch (System.Exception __exception__) - { - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - (@this as SharpGen.Runtime.IExceptionCallback)?.RaiseException(__exception__); - } - } - - [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)] - private delegate void PositionChangedDelegate(System.IntPtr thisObject, Avalonia.Native.Interop.AvnPoint arg0); - private static unsafe void PositionChanged(System.IntPtr thisObject, Avalonia.Native.Interop.AvnPoint param0) - { - try - { - Avalonia.Native.Interop.AvnPoint position = default (Avalonia.Native.Interop.AvnPoint); - position = (Avalonia.Native.Interop.AvnPoint)param0; - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - @this.PositionChanged(position); - } - catch (System.Exception __exception__) - { - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - (@this as SharpGen.Runtime.IExceptionCallback)?.RaiseException(__exception__); - } - } - - [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)] - private delegate void RawMouseEventDelegate(System.IntPtr thisObject, int arg0, System.UInt32 arg1, int arg2, Avalonia.Native.Interop.AvnPoint arg3, Avalonia.Native.Interop.AvnVector arg4); - private static unsafe void RawMouseEvent(System.IntPtr thisObject, int param0, System.UInt32 param1, int param2, Avalonia.Native.Interop.AvnPoint param3, Avalonia.Native.Interop.AvnVector param4) - { - try - { - Avalonia.Native.Interop.AvnRawMouseEventType type = default (Avalonia.Native.Interop.AvnRawMouseEventType); - type = (Avalonia.Native.Interop.AvnRawMouseEventType)param0; - System.UInt32 timeStamp = default (System.UInt32); - timeStamp = (System.UInt32)param1; - Avalonia.Native.Interop.AvnInputModifiers modifiers = default (Avalonia.Native.Interop.AvnInputModifiers); - modifiers = (Avalonia.Native.Interop.AvnInputModifiers)param2; - Avalonia.Native.Interop.AvnPoint point = default (Avalonia.Native.Interop.AvnPoint); - point = (Avalonia.Native.Interop.AvnPoint)param3; - Avalonia.Native.Interop.AvnVector delta = default (Avalonia.Native.Interop.AvnVector); - delta = (Avalonia.Native.Interop.AvnVector)param4; - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - @this.RawMouseEvent(type, timeStamp, modifiers, point, delta); - } - catch (System.Exception __exception__) - { - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - (@this as SharpGen.Runtime.IExceptionCallback)?.RaiseException(__exception__); - } - } - - [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)] - private delegate System.Byte RawKeyEventDelegate(System.IntPtr thisObject, int arg0, System.UInt32 arg1, int arg2, System.UInt32 arg3); - private static unsafe System.Byte RawKeyEvent(System.IntPtr thisObject, int param0, System.UInt32 param1, int param2, System.UInt32 param3) - { - try - { - System.Boolean __result__ = default (System.Boolean); - System.Byte __result__native; - Avalonia.Native.Interop.AvnRawKeyEventType type = default (Avalonia.Native.Interop.AvnRawKeyEventType); - type = (Avalonia.Native.Interop.AvnRawKeyEventType)param0; - System.UInt32 timeStamp = default (System.UInt32); - timeStamp = (System.UInt32)param1; - Avalonia.Native.Interop.AvnInputModifiers modifiers = default (Avalonia.Native.Interop.AvnInputModifiers); - modifiers = (Avalonia.Native.Interop.AvnInputModifiers)param2; - System.UInt32 key = default (System.UInt32); - key = (System.UInt32)param3; - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - __result__ = @this.RawKeyEvent(type, timeStamp, modifiers, key); - __result__native = (System.Byte)(__result__ ? 1 : 0); - return __result__native; - } - catch (System.Exception __exception__) - { - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - (@this as SharpGen.Runtime.IExceptionCallback)?.RaiseException(__exception__); - return default (System.Byte); - } - } - - [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)] - private delegate System.Byte RawTextInputEventDelegate(System.IntPtr thisObject, System.UInt32 arg0, void *arg1); - private static unsafe System.Byte RawTextInputEvent(System.IntPtr thisObject, System.UInt32 param0, void *param1) - { - try - { - System.Boolean __result__ = default (System.Boolean); - System.Byte __result__native; - System.UInt32 timeStamp = default (System.UInt32); - timeStamp = (System.UInt32)param0; - System.String text = default (System.String); - System.IntPtr text_ = (System.IntPtr)param1; - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - text = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(text_); - __result__ = @this.RawTextInputEvent(timeStamp, text); - __result__native = (System.Byte)(__result__ ? 1 : 0); - return __result__native; - } - catch (System.Exception __exception__) - { - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - (@this as SharpGen.Runtime.IExceptionCallback)?.RaiseException(__exception__); - return default (System.Byte); - } - } - - [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)] - private delegate void ScalingChangedDelegate(System.IntPtr thisObject, double arg0); - private static unsafe void ScalingChanged(System.IntPtr thisObject, double param0) - { - try - { - System.Double scaling = default (System.Double); - scaling = (System.Double)param0; - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - @this.ScalingChanged(scaling); - } - catch (System.Exception __exception__) - { - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - (@this as SharpGen.Runtime.IExceptionCallback)?.RaiseException(__exception__); - } - } - - [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)] - private delegate void RunRenderPriorityJobsDelegate(System.IntPtr thisObject); - private static unsafe void RunRenderPriorityJobs(System.IntPtr thisObject) - { - try - { - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - @this.RunRenderPriorityJobs(); - } - catch (System.Exception __exception__) - { - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - (@this as SharpGen.Runtime.IExceptionCallback)?.RaiseException(__exception__); - } - } - - [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)] - private delegate void LostFocusDelegate(System.IntPtr thisObject); - private static unsafe void LostFocus(System.IntPtr thisObject) - { - try - { - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - @this.LostFocus(); - } - catch (System.Exception __exception__) - { - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - (@this as SharpGen.Runtime.IExceptionCallback)?.RaiseException(__exception__); - } - } - - [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)] - private delegate Avalonia.Native.Interop.AvnDragDropEffects DragEventDelegate(System.IntPtr thisObject, int arg0, Avalonia.Native.Interop.AvnPoint arg1, int arg2, int arg3, void *arg4, void *arg5); - private static unsafe Avalonia.Native.Interop.AvnDragDropEffects DragEvent(System.IntPtr thisObject, int param0, Avalonia.Native.Interop.AvnPoint param1, int param2, int param3, void *param4, void *param5) - { - try - { - Avalonia.Native.Interop.AvnDragDropEffects __result__ = default (Avalonia.Native.Interop.AvnDragDropEffects); - Avalonia.Native.Interop.AvnDragEventType type = default (Avalonia.Native.Interop.AvnDragEventType); - type = (Avalonia.Native.Interop.AvnDragEventType)param0; - Avalonia.Native.Interop.AvnPoint position = default (Avalonia.Native.Interop.AvnPoint); - position = (Avalonia.Native.Interop.AvnPoint)param1; - Avalonia.Native.Interop.AvnInputModifiers modifiers = default (Avalonia.Native.Interop.AvnInputModifiers); - modifiers = (Avalonia.Native.Interop.AvnInputModifiers)param2; - Avalonia.Native.Interop.AvnDragDropEffects effects = default (Avalonia.Native.Interop.AvnDragDropEffects); - effects = (Avalonia.Native.Interop.AvnDragDropEffects)param3; - Avalonia.Native.Interop.IAvnClipboard clipboard = default (Avalonia.Native.Interop.IAvnClipboard); - System.IntPtr clipboard_ = (System.IntPtr)param4; - System.IntPtr dataObjectHandle = default (System.IntPtr); - dataObjectHandle = (System.IntPtr)param5; - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - if (clipboard_ != System.IntPtr.Zero) - clipboard = new Avalonia.Native.Interop.IAvnClipboard(clipboard_); - else - clipboard = null; - __result__ = @this.DragEvent(type, position, modifiers, effects, clipboard, dataObjectHandle); - return __result__; - } - catch (System.Exception __exception__) - { - IAvnWindowBaseEvents @this = (IAvnWindowBaseEvents)ToShadow(thisObject).Callback; - (@this as SharpGen.Runtime.IExceptionCallback)?.RaiseException(__exception__); - return default (Avalonia.Native.Interop.AvnDragDropEffects); - } - } - } - - protected override SharpGen.Runtime.CppObjectVtbl Vtbl - { - get; - } - - = new Avalonia.Native.Interop.IAvnWindowBaseEventsShadow.IAvnWindowBaseEventsVtbl(0); - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f05"), SharpGen.Runtime.ShadowAttribute(typeof (Avalonia.Native.Interop.IAvnWindowBaseEventsShadow))] - public partial interface IAvnWindowBaseEvents : SharpGen.Runtime.IUnknown - { - void Paint(); - void Closed(); - void Activated(); - void Deactivated(); - void Resized(Avalonia.Native.Interop.AvnSize size); - void PositionChanged(Avalonia.Native.Interop.AvnPoint position); - void RawMouseEvent(Avalonia.Native.Interop.AvnRawMouseEventType type, System.UInt32 timeStamp, Avalonia.Native.Interop.AvnInputModifiers modifiers, Avalonia.Native.Interop.AvnPoint point, Avalonia.Native.Interop.AvnVector delta); - System.Boolean RawKeyEvent(Avalonia.Native.Interop.AvnRawKeyEventType type, System.UInt32 timeStamp, Avalonia.Native.Interop.AvnInputModifiers modifiers, System.UInt32 key); - System.Boolean RawTextInputEvent(System.UInt32 timeStamp, System.String text); - void ScalingChanged(System.Double scaling); - void RunRenderPriorityJobs(); - void LostFocus(); - Avalonia.Native.Interop.AvnDragDropEffects DragEvent(Avalonia.Native.Interop.AvnDragEventType type, Avalonia.Native.Interop.AvnPoint position, Avalonia.Native.Interop.AvnInputModifiers modifiers, Avalonia.Native.Interop.AvnDragDropEffects effects, Avalonia.Native.Interop.IAvnClipboard clipboard, System.IntPtr dataObjectHandle); - } - - class IAvnWindowEventsShadow : Avalonia.Native.Interop.IAvnWindowBaseEventsShadow - { - protected unsafe class IAvnWindowEventsVtbl : Avalonia.Native.Interop.IAvnWindowBaseEventsShadow.IAvnWindowBaseEventsVtbl - { - public IAvnWindowEventsVtbl(int numberOfCallbackMethods): base (numberOfCallbackMethods + 3) - { - AddMethod(new ClosingDelegate(Closing)); - AddMethod(new WindowStateChangedDelegate(WindowStateChanged)); - AddMethod(new GotInputWhenDisabledDelegate(GotInputWhenDisabled)); - } - - [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)] - private delegate System.Byte ClosingDelegate(System.IntPtr thisObject); - private static unsafe System.Byte Closing(System.IntPtr thisObject) - { - try - { - System.Boolean __result__ = default (System.Boolean); - System.Byte __result__native; - IAvnWindowEvents @this = (IAvnWindowEvents)ToShadow(thisObject).Callback; - __result__ = @this.Closing(); - __result__native = (System.Byte)(__result__ ? 1 : 0); - return __result__native; - } - catch (System.Exception __exception__) - { - IAvnWindowEvents @this = (IAvnWindowEvents)ToShadow(thisObject).Callback; - (@this as SharpGen.Runtime.IExceptionCallback)?.RaiseException(__exception__); - return default (System.Byte); - } - } - - [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)] - private delegate void WindowStateChangedDelegate(System.IntPtr thisObject, int arg0); - private static unsafe void WindowStateChanged(System.IntPtr thisObject, int param0) - { - try - { - Avalonia.Native.Interop.AvnWindowState state = default (Avalonia.Native.Interop.AvnWindowState); - state = (Avalonia.Native.Interop.AvnWindowState)param0; - IAvnWindowEvents @this = (IAvnWindowEvents)ToShadow(thisObject).Callback; - @this.WindowStateChanged(state); - } - catch (System.Exception __exception__) - { - IAvnWindowEvents @this = (IAvnWindowEvents)ToShadow(thisObject).Callback; - (@this as SharpGen.Runtime.IExceptionCallback)?.RaiseException(__exception__); - } - } - - [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)] - private delegate void GotInputWhenDisabledDelegate(System.IntPtr thisObject); - private static unsafe void GotInputWhenDisabled(System.IntPtr thisObject) - { - try - { - IAvnWindowEvents @this = (IAvnWindowEvents)ToShadow(thisObject).Callback; - @this.GotInputWhenDisabled(); - } - catch (System.Exception __exception__) - { - IAvnWindowEvents @this = (IAvnWindowEvents)ToShadow(thisObject).Callback; - (@this as SharpGen.Runtime.IExceptionCallback)?.RaiseException(__exception__); - } - } - } - - protected override SharpGen.Runtime.CppObjectVtbl Vtbl - { - get; - } - - = new Avalonia.Native.Interop.IAvnWindowEventsShadow.IAvnWindowEventsVtbl(0); - } - - [System.Runtime.InteropServices.GuidAttribute("2e2cda0a-9ae5-4f1b-8e20-081a04279f06"), SharpGen.Runtime.ShadowAttribute(typeof (Avalonia.Native.Interop.IAvnWindowEventsShadow))] - public partial interface IAvnWindowEvents : Avalonia.Native.Interop.IAvnWindowBaseEvents - { - System.Boolean Closing(); - void WindowStateChanged(Avalonia.Native.Interop.AvnWindowState state); - void GotInputWhenDisabled(); - } -} \ No newline at end of file diff --git a/src/Avalonia.Native/Generated/LocalInterop.cs b/src/Avalonia.Native/Generated/LocalInterop.cs deleted file mode 100644 index 41e69a6bdc..0000000000 --- a/src/Avalonia.Native/Generated/LocalInterop.cs +++ /dev/null @@ -1,202 +0,0 @@ -// - -namespace Avalonia.Native -{ - internal static partial class LocalInterop - { - public static unsafe int CalliThisCallint(void *thisObject, void *methodPtr) - { - throw null; - } - - public static unsafe void CalliThisCallvoid(void *thisObject, void *methodPtr) - { - throw null; - } - - public static unsafe void CalliThisCallvoid(void *thisObject, void *param0, void *methodPtr) - { - throw null; - } - - public static unsafe void CalliThisCallvoid0(void *thisObject, Avalonia.Native.Interop.AvnPoint param0, void *methodPtr) - { - throw null; - } - - public static unsafe void CalliThisCallvoid0(void *thisObject, int param0, System.UInt32 param1, int param2, Avalonia.Native.Interop.AvnPoint param3, Avalonia.Native.Interop.AvnVector param4, void *methodPtr) - { - throw null; - } - - public static unsafe System.Byte CalliThisCallSystemByte(void *thisObject, int param0, System.UInt32 param1, int param2, System.UInt32 param3, void *methodPtr) - { - throw null; - } - - public static unsafe System.Byte CalliThisCallSystemByte(void *thisObject, System.UInt32 param0, void *param1, void *methodPtr) - { - throw null; - } - - public static unsafe void CalliThisCallvoid(void *thisObject, double param0, void *methodPtr) - { - throw null; - } - - public static unsafe Avalonia.Native.Interop.AvnDragDropEffects CalliThisCallAvaloniaNativeInteropAvnDragDropEffects0(void *thisObject, int param0, Avalonia.Native.Interop.AvnPoint param1, int param2, int param3, void *param4, void *param5, void *methodPtr) - { - throw null; - } - - public static unsafe System.Byte CalliThisCallSystemByte(void *thisObject, void *methodPtr) - { - throw null; - } - - public static unsafe void CalliThisCallvoid(void *thisObject, int param0, void *methodPtr) - { - throw null; - } - - public static unsafe int CalliThisCallint(void *thisObject, void *param0, void *methodPtr) - { - throw null; - } - - public static unsafe int CalliThisCallint0(void *thisObject, Avalonia.Native.Interop.AvnSize param0, Avalonia.Native.Interop.AvnSize param1, void *methodPtr) - { - throw null; - } - - public static unsafe int CalliThisCallint(void *thisObject, double param0, double param1, void *methodPtr) - { - throw null; - } - - public static unsafe int CalliThisCallint0(void *thisObject, Avalonia.Native.Interop.AvnRect param0, void *methodPtr) - { - throw null; - } - - public static unsafe int CalliThisCallint(void *thisObject, int param0, void *methodPtr) - { - throw null; - } - - public static unsafe int CalliThisCallint0(void *thisObject, Avalonia.Native.Interop.AvnPoint param0, void *methodPtr) - { - throw null; - } - - public static unsafe int CalliThisCallint0(void *thisObject, Avalonia.Native.Interop.AvnPoint param0, void *param1, void *methodPtr) - { - throw null; - } - - public static unsafe int CalliThisCallint(void *thisObject, void *param0, void *param1, void *methodPtr) - { - throw null; - } - - public static unsafe int CalliThisCallint(void *thisObject, System.Byte param0, void *methodPtr) - { - throw null; - } - - public static unsafe int CalliThisCallint0(void *thisObject, int param0, Avalonia.Native.Interop.AvnPoint param1, void *param2, void *param3, void *param4, void *methodPtr) - { - throw null; - } - - public static unsafe int CalliThisCallint0(void *thisObject, Avalonia.Native.Interop.AvnColor param0, void *methodPtr) - { - throw null; - } - - public static unsafe int CalliThisCallint(void *thisObject, double param0, void *methodPtr) - { - throw null; - } - - public static unsafe System.IntPtr CalliThisCallSystemIntPtr(void *thisObject, void *methodPtr) - { - throw null; - } - - public static unsafe System.IntPtr CalliThisCallSystemIntPtr(void *thisObject, int param0, int param1, void *param2, void *methodPtr) - { - throw null; - } - - public static unsafe void CalliThisCallvoid(void *thisObject, int param0, void *param1, void *methodPtr) - { - throw null; - } - - public static unsafe void CalliThisCallvoid(void *thisObject, void *param0, void *param1, void *param2, void *param3, void *methodPtr) - { - throw null; - } - - public static unsafe void CalliThisCallvoid(void *thisObject, void *param0, void *param1, System.Byte param2, void *param3, void *param4, void *param5, void *param6, void *methodPtr) - { - throw null; - } - - public static unsafe void CalliThisCallvoid(void *thisObject, void *param0, void *param1, void *param2, void *param3, void *param4, void *param5, void *methodPtr) - { - throw null; - } - - public static unsafe int CalliThisCallint(void *thisObject, int param0, void *param1, void *methodPtr) - { - throw null; - } - - public static unsafe int CalliThisCallint(void *thisObject, void *param0, void *param1, int param2, void *methodPtr) - { - throw null; - } - - public static unsafe System.IntPtr CalliThisCallSystemIntPtr(void *thisObject, void *param0, void *methodPtr) - { - throw null; - } - - public static unsafe int CalliThisCallint(void *thisObject, void *param0, int param1, void *methodPtr) - { - throw null; - } - - public static unsafe System.UInt32 CalliThisCallSystemUInt32(void *thisObject, void *methodPtr) - { - throw null; - } - - public static unsafe int CalliThisCallint(void *thisObject, System.UInt32 param0, void *param1, void *methodPtr) - { - throw null; - } - - public static unsafe void CalliThisCallvoid(void *thisObject, float param0, float param1, float param2, float param3, void *methodPtr) - { - throw null; - } - - public static unsafe void CalliThisCallvoid(void *thisObject, float param0, float param1, void *methodPtr) - { - throw null; - } - - public static unsafe int CalliThisCallint(void *thisObject, void *param0, void *param1, void *param2, void *methodPtr) - { - throw null; - } - - public static unsafe void CalliThisCallvoid(void *thisObject, int param0, System.Byte param1, void *methodPtr) - { - throw null; - } - } -} \ No newline at end of file diff --git a/src/Avalonia.Native/Generated/Structures.cs b/src/Avalonia.Native/Generated/Structures.cs deleted file mode 100644 index fc871a2516..0000000000 --- a/src/Avalonia.Native/Generated/Structures.cs +++ /dev/null @@ -1,246 +0,0 @@ -// - -namespace Avalonia.Native.Interop -{ - /// - /// No documentation. - /// - /// AvnColor - /// AvnColor - [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, Pack = 0, CharSet = System.Runtime.InteropServices.CharSet.Unicode)] - public partial struct AvnColor - { - /// - /// No documentation. - /// - /// Alpha - /// Alpha - public System.Byte Alpha; - /// - /// No documentation. - /// - /// Red - /// Red - public System.Byte Red; - /// - /// No documentation. - /// - /// Green - /// Green - public System.Byte Green; - /// - /// No documentation. - /// - /// Blue - /// Blue - public System.Byte Blue; - } - - /// - /// No documentation. - /// - /// AvnFramebuffer - /// AvnFramebuffer - [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, Pack = 0, CharSet = System.Runtime.InteropServices.CharSet.Unicode)] - public partial struct AvnFramebuffer - { - /// - /// No documentation. - /// - /// Data - /// Data - public System.IntPtr Data; - /// - /// No documentation. - /// - /// Width - /// Width - public System.Int32 Width; - /// - /// No documentation. - /// - /// Height - /// Height - public System.Int32 Height; - /// - /// No documentation. - /// - /// Stride - /// Stride - public System.Int32 Stride; - /// - /// No documentation. - /// - /// Dpi - /// Dpi - public Avalonia.Native.Interop.AvnVector Dpi; - /// - /// No documentation. - /// - /// PixelFormat - /// PixelFormat - public Avalonia.Native.Interop.AvnPixelFormat PixelFormat; - } - - /// - /// No documentation. - /// - /// AvnPixelSize - /// AvnPixelSize - [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, Pack = 0, CharSet = System.Runtime.InteropServices.CharSet.Unicode)] - public partial struct AvnPixelSize - { - /// - /// No documentation. - /// - /// Width - /// Width - public System.Int32 Width; - /// - /// No documentation. - /// - /// Height - /// Height - public System.Int32 Height; - } - - /// - /// No documentation. - /// - /// AvnPoint - /// AvnPoint - [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, Pack = 0, CharSet = System.Runtime.InteropServices.CharSet.Unicode)] - public partial struct AvnPoint - { - /// - /// No documentation. - /// - /// X - /// X - public System.Double X; - /// - /// No documentation. - /// - /// Y - /// Y - public System.Double Y; - } - - /// - /// No documentation. - /// - /// AvnRect - /// AvnRect - [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, Pack = 0, CharSet = System.Runtime.InteropServices.CharSet.Unicode)] - public partial struct AvnRect - { - /// - /// No documentation. - /// - /// X - /// X - public System.Double X; - /// - /// No documentation. - /// - /// Y - /// Y - public System.Double Y; - /// - /// No documentation. - /// - /// Width - /// Width - public System.Double Width; - /// - /// No documentation. - /// - /// Height - /// Height - public System.Double Height; - } - - /// - /// No documentation. - /// - /// AvnScreen - /// AvnScreen - [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, Pack = 0, CharSet = System.Runtime.InteropServices.CharSet.Unicode)] - public partial struct AvnScreen - { - /// - /// No documentation. - /// - /// Bounds - /// Bounds - public Avalonia.Native.Interop.AvnRect Bounds; - /// - /// No documentation. - /// - /// WorkingArea - /// WorkingArea - public Avalonia.Native.Interop.AvnRect WorkingArea; - /// - /// No documentation. - /// - /// PixelDensity - /// PixelDensity - public System.Single PixelDensity; - /// - /// No documentation. - /// - /// Primary - /// Primary - public bool Primary - { - get => 0 != _Primary; - set => _Primary = (System.Byte)(value ? 1 : 0); - } - - internal System.Byte _Primary; - } - - /// - /// No documentation. - /// - /// AvnSize - /// AvnSize - [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, Pack = 0, CharSet = System.Runtime.InteropServices.CharSet.Unicode)] - public partial struct AvnSize - { - /// - /// No documentation. - /// - /// Width - /// Width - public System.Double Width; - /// - /// No documentation. - /// - /// Height - /// Height - public System.Double Height; - } - - /// - /// No documentation. - /// - /// AvnVector - /// AvnVector - [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, Pack = 0, CharSet = System.Runtime.InteropServices.CharSet.Unicode)] - public partial struct AvnVector - { - /// - /// No documentation. - /// - /// X - /// X - public System.Double X; - /// - /// No documentation. - /// - /// Y - /// Y - public System.Double Y; - } -} \ No newline at end of file diff --git a/src/Avalonia.Native/Helpers.cs b/src/Avalonia.Native/Helpers.cs index 25e8250232..564434a04c 100644 --- a/src/Avalonia.Native/Helpers.cs +++ b/src/Avalonia.Native/Helpers.cs @@ -2,7 +2,7 @@ namespace Avalonia.Native { - public static class Helpers + internal static class Helpers { public static Point ToAvaloniaPoint (this AvnPoint pt) { diff --git a/src/Avalonia.Native/IAvnMenu.cs b/src/Avalonia.Native/IAvnMenu.cs index 8a49559a02..dd9464284f 100644 --- a/src/Avalonia.Native/IAvnMenu.cs +++ b/src/Avalonia.Native/IAvnMenu.cs @@ -22,15 +22,23 @@ namespace Avalonia.Native.Interop } } - public partial class IAvnMenu + partial interface IAvnMenu + { + void RaiseNeedsUpdate(); + void Deinitialise(); + } +} +namespace Avalonia.Native.Interop.Impl +{ + partial class __MicroComIAvnMenuProxy { private MenuEvents _events; private AvaloniaNativeMenuExporter _exporter; - private List _menuItems = new List(); - private Dictionary _menuItemLookup = new Dictionary(); + private List<__MicroComIAvnMenuItemProxy> _menuItems = new List<__MicroComIAvnMenuItemProxy>(); + private Dictionary _menuItemLookup = new Dictionary(); private CompositeDisposable _propertyDisposables = new CompositeDisposable(); - internal void RaiseNeedsUpdate() + public void RaiseNeedsUpdate() { (ManagedMenu as INativeMenuExporterEventsImplBridge).RaiseNeedsUpdate(); @@ -39,11 +47,11 @@ namespace Avalonia.Native.Interop internal NativeMenu ManagedMenu { get; private set; } - public static IAvnMenu Create(IAvaloniaNativeFactory factory) + public static __MicroComIAvnMenuProxy Create(IAvaloniaNativeFactory factory) { var events = new MenuEvents(); - var menu = factory.CreateMenu(events); + var menu = (__MicroComIAvnMenuProxy)factory.CreateMenu(events); events.Initialise(menu); @@ -60,7 +68,7 @@ namespace Avalonia.Native.Interop } } - private void RemoveAndDispose(IAvnMenuItem item) + private void RemoveAndDispose(__MicroComIAvnMenuItemProxy item) { _menuItemLookup.Remove(item.ManagedMenuItem); _menuItems.Remove(item); @@ -70,7 +78,7 @@ namespace Avalonia.Native.Interop item.Dispose(); } - private void MoveExistingTo(int index, IAvnMenuItem item) + private void MoveExistingTo(int index, __MicroComIAvnMenuItemProxy item) { _menuItems.Remove(item); _menuItems.Insert(index, item); @@ -79,7 +87,7 @@ namespace Avalonia.Native.Interop InsertItem(index, item); } - private IAvnMenuItem CreateNewAt(IAvaloniaNativeFactory factory, int index, NativeMenuItemBase item) + private __MicroComIAvnMenuItemProxy CreateNewAt(IAvaloniaNativeFactory factory, int index, NativeMenuItemBase item) { var result = CreateNew(factory, item); @@ -93,9 +101,11 @@ namespace Avalonia.Native.Interop return result; } - private IAvnMenuItem CreateNew(IAvaloniaNativeFactory factory, NativeMenuItemBase item) + private __MicroComIAvnMenuItemProxy CreateNew(IAvaloniaNativeFactory factory, NativeMenuItemBase item) { - var nativeItem = item is NativeMenuItemSeperator ? factory.CreateMenuItemSeperator() : factory.CreateMenuItem(); + var nativeItem = (__MicroComIAvnMenuItemProxy)(item is NativeMenuItemSeperator ? + factory.CreateMenuItemSeperator() : + factory.CreateMenuItem()); nativeItem.ManagedMenuItem = item; return nativeItem; @@ -108,16 +118,11 @@ namespace Avalonia.Native.Interop ((INotifyCollectionChanged)ManagedMenu.Items).CollectionChanged += OnMenuItemsChanged; - if (!string.IsNullOrWhiteSpace(title)) - { - using (var buffer = new Utf8Buffer(title)) - { - Title = buffer.DangerousGetHandle(); - } - } + if (!string.IsNullOrWhiteSpace(title)) + SetTitle(title); } - internal void Deinitialise() + public void Deinitialise() { ((INotifyCollectionChanged)ManagedMenu.Items).CollectionChanged -= OnMenuItemsChanged; @@ -137,7 +142,7 @@ namespace Avalonia.Native.Interop for (int i = 0; i < menu.Items.Count; i++) { - IAvnMenuItem nativeItem; + __MicroComIAvnMenuItemProxy nativeItem; if (i >= _menuItems.Count) { diff --git a/src/Avalonia.Native/IAvnMenuItem.cs b/src/Avalonia.Native/IAvnMenuItem.cs index c8819d1994..97838f8dea 100644 --- a/src/Avalonia.Native/IAvnMenuItem.cs +++ b/src/Avalonia.Native/IAvnMenuItem.cs @@ -7,37 +7,35 @@ using Avalonia.Platform.Interop; namespace Avalonia.Native.Interop { - public partial class IAvnMenuItem + partial interface IAvnMenuItem { - private IAvnMenu _subMenu; + + } +} +namespace Avalonia.Native.Interop.Impl +{ + partial class __MicroComIAvnMenuItemProxy + { + private __MicroComIAvnMenuProxy _subMenu; private CompositeDisposable _propertyDisposables = new CompositeDisposable(); private IDisposable _currentActionDisposable; public NativeMenuItemBase ManagedMenuItem { get; set; } - private void UpdateTitle(string title) - { - using (var buffer = new Utf8Buffer(string.IsNullOrWhiteSpace(title) ? "" : title)) - { - Title = buffer.DangerousGetHandle(); - } - } + private void UpdateTitle(string title) => SetTitle(title ?? ""); - private void UpdateIsChecked(bool isChecked) - { - IsChecked = isChecked; - } + private void UpdateIsChecked(bool isChecked) => SetIsChecked(isChecked.AsComBool()); private void UpdateToggleType(NativeMenuItemToggleType toggleType) { - ToggleType = (AvnMenuItemToggleType)toggleType; + SetToggleType((AvnMenuItemToggleType)toggleType); } private unsafe void UpdateIcon (IBitmap icon) { if(icon is null) { - SetIcon(IntPtr.Zero, 0); + SetIcon(null, IntPtr.Zero); } else { @@ -49,7 +47,7 @@ namespace Avalonia.Native.Interop fixed(void* ptr = imageData) { - SetIcon(new IntPtr(ptr), imageData.Length); + SetIcon(ptr, new IntPtr(imageData.Length)); } } } @@ -57,12 +55,9 @@ namespace Avalonia.Native.Interop private void UpdateGesture(Input.KeyGesture gesture) { - // todo ensure backend can cope with setting null gesture. - using (var buffer = new Utf8Buffer(gesture == null ? "" : OsxUnicodeKeys.ConvertOSXSpecialKeyCodes(gesture.Key))) - { - var modifiers = gesture == null ? AvnInputModifiers.AvnInputModifiersNone : (AvnInputModifiers)gesture.KeyModifiers; - SetGesture(buffer.DangerousGetHandle(), modifiers); - } + var modifiers = gesture == null ? AvnInputModifiers.AvnInputModifiersNone : (AvnInputModifiers)gesture.KeyModifiers; + var key = gesture == null ? AvnKey.AvnKeyNone : (AvnKey)gesture.Key; + SetGesture(key, modifiers); } private void UpdateAction(NativeMenuItem item) @@ -153,7 +148,7 @@ namespace Avalonia.Native.Interop { if (_subMenu == null) { - _subMenu = IAvnMenu.Create(factory); + _subMenu = __MicroComIAvnMenuProxy.Create(factory); _subMenu.Initialise(exporter, item.Menu, item.Header); diff --git a/src/Avalonia.Native/NativeControlHostImpl.cs b/src/Avalonia.Native/NativeControlHostImpl.cs index a46528dc48..2c9c1728d3 100644 --- a/src/Avalonia.Native/NativeControlHostImpl.cs +++ b/src/Avalonia.Native/NativeControlHostImpl.cs @@ -1,5 +1,6 @@ using System; using Avalonia.Controls.Platform; +using Avalonia.MicroCom; using Avalonia.Native.Interop; using Avalonia.Platform; using Avalonia.VisualTree; @@ -28,8 +29,7 @@ namespace Avalonia.Native public DestroyableNSView(IAvnNativeControlHost impl) { - _impl = new IAvnNativeControlHost(impl.NativePointer); - _impl.AddRef(); + _impl = MicroComRuntime.CloneReference(impl); _nsView = _impl.CreateDefaultChild(IntPtr.Zero); } diff --git a/src/Avalonia.Native/OsxUnicodeKeys.cs b/src/Avalonia.Native/OsxUnicodeKeys.cs deleted file mode 100644 index fd9acfa714..0000000000 --- a/src/Avalonia.Native/OsxUnicodeKeys.cs +++ /dev/null @@ -1,152 +0,0 @@ -using System.Collections.Generic; -using Avalonia.Input; - -namespace Avalonia.Native.Interop -{ - internal static class OsxUnicodeKeys - { - enum OsxUnicodeSpecialKey - { - NSUpArrowFunctionKey = 0xF700, - NSDownArrowFunctionKey = 0xF701, - NSLeftArrowFunctionKey = 0xF702, - NSRightArrowFunctionKey = 0xF703, - NSF1FunctionKey = 0xF704, - NSF2FunctionKey = 0xF705, - NSF3FunctionKey = 0xF706, - NSF4FunctionKey = 0xF707, - NSF5FunctionKey = 0xF708, - NSF6FunctionKey = 0xF709, - NSF7FunctionKey = 0xF70A, - NSF8FunctionKey = 0xF70B, - NSF9FunctionKey = 0xF70C, - NSF10FunctionKey = 0xF70D, - NSF11FunctionKey = 0xF70E, - NSF12FunctionKey = 0xF70F, - NSF13FunctionKey = 0xF710, - NSF14FunctionKey = 0xF711, - NSF15FunctionKey = 0xF712, - NSF16FunctionKey = 0xF713, - NSF17FunctionKey = 0xF714, - NSF18FunctionKey = 0xF715, - NSF19FunctionKey = 0xF716, - NSF20FunctionKey = 0xF717, - NSF21FunctionKey = 0xF718, - NSF22FunctionKey = 0xF719, - NSF23FunctionKey = 0xF71A, - NSF24FunctionKey = 0xF71B, - NSF25FunctionKey = 0xF71C, - NSF26FunctionKey = 0xF71D, - NSF27FunctionKey = 0xF71E, - NSF28FunctionKey = 0xF71F, - NSF29FunctionKey = 0xF720, - NSF30FunctionKey = 0xF721, - NSF31FunctionKey = 0xF722, - NSF32FunctionKey = 0xF723, - NSF33FunctionKey = 0xF724, - NSF34FunctionKey = 0xF725, - NSF35FunctionKey = 0xF726, - NSInsertFunctionKey = 0xF727, - NSDeleteFunctionKey = 0xF728, - NSHomeFunctionKey = 0xF729, - NSBeginFunctionKey = 0xF72A, - NSEndFunctionKey = 0xF72B, - NSPageUpFunctionKey = 0xF72C, - NSPageDownFunctionKey = 0xF72D, - NSPrintScreenFunctionKey = 0xF72E, - NSScrollLockFunctionKey = 0xF72F, - NSPauseFunctionKey = 0xF730, - NSSysReqFunctionKey = 0xF731, - NSBreakFunctionKey = 0xF732, - NSResetFunctionKey = 0xF733, - NSStopFunctionKey = 0xF734, - NSMenuFunctionKey = 0xF735, - NSUserFunctionKey = 0xF736, - NSSystemFunctionKey = 0xF737, - NSPrintFunctionKey = 0xF738, - NSClearLineFunctionKey = 0xF739, - NSClearDisplayFunctionKey = 0xF73A, - NSInsertLineFunctionKey = 0xF73B, - NSDeleteLineFunctionKey = 0xF73C, - NSInsertCharFunctionKey = 0xF73D, - NSDeleteCharFunctionKey = 0xF73E, - NSPrevFunctionKey = 0xF73F, - NSNextFunctionKey = 0xF740, - NSSelectFunctionKey = 0xF741, - NSExecuteFunctionKey = 0xF742, - NSUndoFunctionKey = 0xF743, - NSRedoFunctionKey = 0xF744, - NSFindFunctionKey = 0xF745, - NSHelpFunctionKey = 0xF746, - NSModeSwitchFunctionKey = 0xF747 - } - - private static Dictionary s_osxKeys = new Dictionary - { - {Key.Up, OsxUnicodeSpecialKey.NSUpArrowFunctionKey }, - {Key.Down, OsxUnicodeSpecialKey.NSDownArrowFunctionKey }, - {Key.Left, OsxUnicodeSpecialKey.NSLeftArrowFunctionKey }, - {Key.Right, OsxUnicodeSpecialKey.NSRightArrowFunctionKey }, - { Key.F1, OsxUnicodeSpecialKey.NSF1FunctionKey }, - { Key.F2, OsxUnicodeSpecialKey.NSF2FunctionKey }, - { Key.F3, OsxUnicodeSpecialKey.NSF3FunctionKey }, - { Key.F4, OsxUnicodeSpecialKey.NSF4FunctionKey }, - { Key.F5, OsxUnicodeSpecialKey.NSF5FunctionKey }, - { Key.F6, OsxUnicodeSpecialKey.NSF6FunctionKey }, - { Key.F7, OsxUnicodeSpecialKey.NSF7FunctionKey }, - { Key.F8, OsxUnicodeSpecialKey.NSF8FunctionKey }, - { Key.F9, OsxUnicodeSpecialKey.NSF9FunctionKey }, - { Key.F10, OsxUnicodeSpecialKey.NSF10FunctionKey }, - { Key.F11, OsxUnicodeSpecialKey.NSF11FunctionKey }, - { Key.F12, OsxUnicodeSpecialKey.NSF12FunctionKey }, - { Key.F13, OsxUnicodeSpecialKey.NSF13FunctionKey }, - { Key.F14, OsxUnicodeSpecialKey.NSF14FunctionKey }, - { Key.F15, OsxUnicodeSpecialKey.NSF15FunctionKey }, - { Key.F16, OsxUnicodeSpecialKey.NSF16FunctionKey }, - { Key.F17, OsxUnicodeSpecialKey.NSF17FunctionKey }, - { Key.F18, OsxUnicodeSpecialKey.NSF18FunctionKey }, - { Key.F19, OsxUnicodeSpecialKey.NSF19FunctionKey }, - { Key.F20, OsxUnicodeSpecialKey.NSF20FunctionKey }, - { Key.F21, OsxUnicodeSpecialKey.NSF21FunctionKey }, - { Key.F22, OsxUnicodeSpecialKey.NSF22FunctionKey }, - { Key.F23, OsxUnicodeSpecialKey.NSF23FunctionKey }, - { Key.F24, OsxUnicodeSpecialKey.NSF24FunctionKey }, - { Key.Insert, OsxUnicodeSpecialKey.NSInsertFunctionKey }, - { Key.Delete, OsxUnicodeSpecialKey.NSDeleteFunctionKey }, - { Key.Home, OsxUnicodeSpecialKey.NSHomeFunctionKey }, - //{ Key.Begin, OsxUnicodeSpecialKey.NSBeginFunctionKey }, - { Key.End, OsxUnicodeSpecialKey.NSEndFunctionKey }, - { Key.PageUp, OsxUnicodeSpecialKey.NSPageUpFunctionKey }, - { Key.PageDown, OsxUnicodeSpecialKey.NSPageDownFunctionKey }, - { Key.PrintScreen, OsxUnicodeSpecialKey.NSPrintScreenFunctionKey }, - { Key.Scroll, OsxUnicodeSpecialKey.NSScrollLockFunctionKey }, - //{ Key.SysReq, OsxUnicodeSpecialKey.NSSysReqFunctionKey }, - //{ Key.Break, OsxUnicodeSpecialKey.NSBreakFunctionKey }, - //{ Key.Reset, OsxUnicodeSpecialKey.NSResetFunctionKey }, - //{ Key.Stop, OsxUnicodeSpecialKey.NSStopFunctionKey }, - //{ Key.Menu, OsxUnicodeSpecialKey.NSMenuFunctionKey }, - //{ Key.UserFunction, OsxUnicodeSpecialKey.NSUserFunctionKey }, - //{ Key.SystemFunction, OsxUnicodeSpecialKey.NSSystemFunctionKey }, - { Key.Print, OsxUnicodeSpecialKey.NSPrintFunctionKey }, - //{ Key.ClearLine, OsxUnicodeSpecialKey.NSClearLineFunctionKey }, - //{ Key.ClearDisplay, OsxUnicodeSpecialKey.NSClearDisplayFunctionKey }, - }; - - public static string ConvertOSXSpecialKeyCodes(Key key) - { - if (s_osxKeys.ContainsKey(key)) - { - return ((char)s_osxKeys[key]).ToString(); - } - else - { - if (key >= Key.D0 && key <= Key.D9) - { - return key.ToString().Replace("D", ""); - } - - return key.ToString().ToLower(); - } - } - } -} diff --git a/src/Avalonia.Native/PlatformThreadingInterface.cs b/src/Avalonia.Native/PlatformThreadingInterface.cs index 5a81f6a3bf..882d5a2ed3 100644 --- a/src/Avalonia.Native/PlatformThreadingInterface.cs +++ b/src/Avalonia.Native/PlatformThreadingInterface.cs @@ -4,11 +4,10 @@ using System.Threading; using Avalonia.Native.Interop; using Avalonia.Platform; using Avalonia.Threading; -using SharpGen.Runtime; namespace Avalonia.Native { - public class PlatformThreadingInterface : IPlatformThreadingInterface + internal class PlatformThreadingInterface : IPlatformThreadingInterface { class TimerCallback : CallbackBase, IAvnActionCallback { @@ -34,9 +33,9 @@ namespace Avalonia.Native _parent = parent; } - public void Signaled(int priority, bool priorityContainsMeaningfulValue) + public void Signaled(int priority, int priorityContainsMeaningfulValue) { - _parent.Signaled?.Invoke(priorityContainsMeaningfulValue ? (DispatcherPriority?)priority : null); + _parent.Signaled?.Invoke(priorityContainsMeaningfulValue.FromComBool() ? (DispatcherPriority?)priority : null); } } @@ -48,10 +47,10 @@ namespace Avalonia.Native { _native = native; using (var cb = new SignaledCallback(this)) - _native.SignaledCallback = cb; + _native.SetSignaledCallback(cb); } - public bool CurrentThreadIsLoopThread => _native.CurrentThreadIsLoopThread; + public bool CurrentThreadIsLoopThread => _native.CurrentThreadIsLoopThread.FromComBool(); public event Action Signaled; diff --git a/src/Avalonia.Native/PopupImpl.cs b/src/Avalonia.Native/PopupImpl.cs index 2f98385038..c36675afcd 100644 --- a/src/Avalonia.Native/PopupImpl.cs +++ b/src/Avalonia.Native/PopupImpl.cs @@ -50,9 +50,9 @@ namespace Avalonia.Native // NOP on Popup } - bool IAvnWindowEvents.Closing() + int IAvnWindowEvents.Closing() { - return true; + return true.AsComBool(); } void IAvnWindowEvents.WindowStateChanged(AvnWindowState state) @@ -60,14 +60,14 @@ namespace Avalonia.Native } } - public override void Show() + public override void Show(bool activate) { var parent = _parent; while (parent is PopupImpl p) parent = p._parent; if (parent is WindowImpl w) w.Native.TakeFocusFromChildren(); - base.Show(); + base.Show(false); } public override IPopupImpl CreatePopup() => new PopupImpl(_factory, _opts, _glFeature, this); diff --git a/src/Avalonia.Native/PredicateCallback.cs b/src/Avalonia.Native/PredicateCallback.cs index 1ed2ae36af..19c470bcb3 100644 --- a/src/Avalonia.Native/PredicateCallback.cs +++ b/src/Avalonia.Native/PredicateCallback.cs @@ -12,9 +12,9 @@ namespace Avalonia.Native _predicate = predicate; } - bool IAvnPredicateCallback.Evaluate() + int IAvnPredicateCallback.Evaluate() { - return _predicate(); + return _predicate().AsComBool(); } } } diff --git a/src/Avalonia.Native/ScreenImpl.cs b/src/Avalonia.Native/ScreenImpl.cs index f28be52dd5..7b4a001486 100644 --- a/src/Avalonia.Native/ScreenImpl.cs +++ b/src/Avalonia.Native/ScreenImpl.cs @@ -14,7 +14,7 @@ namespace Avalonia.Native _native = native; } - public int ScreenCount => _native.GetScreenCount(); + public int ScreenCount => _native.ScreenCount; public IReadOnlyList AllScreens { @@ -33,7 +33,7 @@ namespace Avalonia.Native screen.PixelDensity, screen.Bounds.ToAvaloniaPixelRect(), screen.WorkingArea.ToAvaloniaPixelRect(), - screen.Primary); + screen.Primary.FromComBool()); } return result; diff --git a/src/Avalonia.Native/SystemDialogs.cs b/src/Avalonia.Native/SystemDialogs.cs index 98e3e383dc..8012813644 100644 --- a/src/Avalonia.Native/SystemDialogs.cs +++ b/src/Avalonia.Native/SystemDialogs.cs @@ -8,7 +8,7 @@ using Avalonia.Native.Interop; namespace Avalonia.Native { - public class SystemDialogs : ISystemDialogImpl + internal class SystemDialogs : ISystemDialogImpl { IAvnSystemDialogs _native; @@ -26,7 +26,7 @@ namespace Avalonia.Native if (dialog is OpenFileDialog ofd) { _native.OpenFileDialog(nativeParent, - events, ofd.AllowMultiple, + events, ofd.AllowMultiple.AsComBool(), ofd.Title ?? "", ofd.Directory ?? "", ofd.InitialFileName ?? "", @@ -62,7 +62,7 @@ namespace Avalonia.Native } } - public class SystemDialogEvents : CallbackBase, IAvnSystemDialogEvents + internal unsafe class SystemDialogEvents : CallbackBase, IAvnSystemDialogEvents { private TaskCompletionSource _tcs; @@ -73,13 +73,13 @@ namespace Avalonia.Native public Task Task => _tcs.Task; - public void OnCompleted(int numResults, IntPtr trFirstResultRef) + public void OnCompleted(int numResults, void* trFirstResultRef) { string[] results = new string[numResults]; unsafe { - var ptr = (IntPtr*)trFirstResultRef.ToPointer(); + var ptr = (IntPtr*)trFirstResultRef; for (int i = 0; i < numResults; i++) { diff --git a/src/Avalonia.Native/WindowImpl.cs b/src/Avalonia.Native/WindowImpl.cs index 11a0ebce61..f3b60f07be 100644 --- a/src/Avalonia.Native/WindowImpl.cs +++ b/src/Avalonia.Native/WindowImpl.cs @@ -1,4 +1,5 @@ using System; +using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Platform; using Avalonia.Input; @@ -10,13 +11,15 @@ using Avalonia.Platform.Interop; namespace Avalonia.Native { - public class WindowImpl : WindowBaseImpl, IWindowImpl, ITopLevelImplWithNativeMenuExporter + internal class WindowImpl : WindowBaseImpl, IWindowImpl, ITopLevelImplWithNativeMenuExporter { private readonly IAvaloniaNativeFactory _factory; private readonly AvaloniaNativePlatformOptions _opts; private readonly AvaloniaNativePlatformOpenGlInterface _glFeature; IAvnWindow _native; private double _extendTitleBarHeight = -1; + private DoubleClickHelper _doubleClickHelper; + internal WindowImpl(IAvaloniaNativeFactory factory, AvaloniaNativePlatformOptions opts, AvaloniaNativePlatformOpenGlInterface glFeature) : base(opts, glFeature) @@ -24,6 +27,8 @@ namespace Avalonia.Native _factory = factory; _opts = opts; _glFeature = glFeature; + _doubleClickHelper = new DoubleClickHelper(); + using (var e = new WindowEvents(this)) { var context = _opts.UseGpu ? glFeature?.MainContext : null; @@ -42,14 +47,14 @@ namespace Avalonia.Native _parent = parent; } - bool IAvnWindowEvents.Closing() + int IAvnWindowEvents.Closing() { if (_parent.Closing != null) { - return _parent.Closing(); + return _parent.Closing().AsComBool(); } - return true; + return true.AsComBool(); } void IAvnWindowEvents.WindowStateChanged(AvnWindowState state) @@ -69,12 +74,12 @@ namespace Avalonia.Native public void CanResize(bool value) { - _native.CanResize = value; + _native.SetCanResize(value.AsComBool()); } public void SetSystemDecorations(Controls.SystemDecorations enabled) { - _native.Decorations = (Interop.SystemDecorations)enabled; + _native.SetDecorations((Interop.SystemDecorations)enabled); } public void SetTitleBarColor(Avalonia.Media.Color color) @@ -82,24 +87,12 @@ namespace Avalonia.Native _native.SetTitleBarColor(new AvnColor { Alpha = color.A, Red = color.R, Green = color.G, Blue = color.B }); } - public void SetTitle(string title) - { - using (var buffer = new Utf8Buffer(title)) - { - _native.SetTitle(buffer.DangerousGetHandle()); - } - } + public void SetTitle(string title) => _native.SetTitle(title); public WindowState WindowState { - get - { - return (WindowState)_native.GetWindowState(); - } - set - { - _native.SetWindowState((AvnWindowState)value); - } + get => (WindowState)_native.WindowState; + set => _native.SetWindowState((AvnWindowState)value); } public Action WindowStateChanged { get; set; } @@ -130,7 +123,22 @@ namespace Avalonia.Native if(visual == null) { - _native.BeginMoveDrag(); + if (_doubleClickHelper.IsDoubleClick(e.Timestamp, e.Position)) + { + // TOGGLE WINDOW STATE. + if (WindowState == WindowState.Maximized || WindowState == WindowState.FullScreen) + { + WindowState = WindowState.Normal; + } + else + { + WindowState = WindowState.Maximized; + } + } + else + { + _native.BeginMoveDrag(); + } } } } @@ -146,7 +154,7 @@ namespace Avalonia.Native } else { - ExtendedMargins = _isExtended ? new Thickness(0, _extendTitleBarHeight == -1 ? _native.GetExtendTitleBarHeight() : _extendTitleBarHeight, 0, 0) : new Thickness(); + ExtendedMargins = _isExtended ? new Thickness(0, _extendTitleBarHeight == -1 ? _native.ExtendTitleBarHeight : _extendTitleBarHeight, 0, 0) : new Thickness(); } ExtendClientAreaToDecorationsChanged?.Invoke(_isExtended); @@ -157,7 +165,7 @@ namespace Avalonia.Native { _isExtended = extendIntoClientAreaHint; - _native.SetExtendClientArea(extendIntoClientAreaHint); + _native.SetExtendClientArea(extendIntoClientAreaHint.AsComBool()); InvalidateExtendedMargins(); } @@ -174,7 +182,7 @@ namespace Avalonia.Native _extendTitleBarHeight = titleBarHeight; _native.SetExtendTitleBarHeight(titleBarHeight); - ExtendedMargins = _isExtended ? new Thickness(0, titleBarHeight == -1 ? _native.GetExtendTitleBarHeight() : titleBarHeight, 0, 0) : new Thickness(); + ExtendedMargins = _isExtended ? new Thickness(0, titleBarHeight == -1 ? _native.ExtendTitleBarHeight : titleBarHeight, 0, 0) : new Thickness(); ExtendClientAreaToDecorationsChanged?.Invoke(_isExtended); } @@ -210,7 +218,7 @@ namespace Avalonia.Native public void SetEnabled(bool enable) { - _native.SetEnabled(enable); + _native.SetEnabled(enable.AsComBool()); } } } diff --git a/src/Avalonia.Native/WindowImplBase.cs b/src/Avalonia.Native/WindowImplBase.cs index ad2b7411eb..41e2851bd9 100644 --- a/src/Avalonia.Native/WindowImplBase.cs +++ b/src/Avalonia.Native/WindowImplBase.cs @@ -15,7 +15,7 @@ using Avalonia.Threading; namespace Avalonia.Native { - public class MacOSTopLevelWindowHandle : IPlatformHandle, IMacOSTopLevelPlatformHandle + internal class MacOSTopLevelWindowHandle : IPlatformHandle, IMacOSTopLevelPlatformHandle { IAvnWindowBase _native; @@ -43,7 +43,7 @@ namespace Avalonia.Native } } - public abstract class WindowBaseImpl : IWindowBaseImpl, + internal abstract class WindowBaseImpl : IWindowBaseImpl, IFramebufferPlatformSurface, ITopLevelImplWithNativeControlHost { protected IInputRoot _inputRoot; @@ -96,7 +96,7 @@ namespace Avalonia.Native { if (_native != null) { - var s = _native.GetClientSize(); + var s = _native.ClientSize; return new Size(s.Width, s.Height); } @@ -137,7 +137,7 @@ namespace Avalonia.Native public IMouseDevice MouseDevice => _mouse; public abstract IPopupImpl CreatePopup(); - protected class WindowBaseEvents : CallbackBase, IAvnWindowBaseEvents + protected unsafe class WindowBaseEvents : CallbackBase, IAvnWindowBaseEvents { private readonly WindowBaseImpl _parent; @@ -155,10 +155,10 @@ namespace Avalonia.Native } finally { + + _parent?.Dispose(); n?.Dispose(); } - - _parent._mouse.Dispose(); } void IAvnWindowBaseEvents.Activated() => _parent.Activated?.Invoke(); @@ -172,11 +172,11 @@ namespace Avalonia.Native _parent.Paint?.Invoke(new Rect(0, 0, s.Width, s.Height)); } - void IAvnWindowBaseEvents.Resized(AvnSize size) + void IAvnWindowBaseEvents.Resized(AvnSize* size) { - if (_parent._native != null) + if (_parent?._native != null) { - var s = new Size(size.Width, size.Height); + var s = new Size(size->Width, size->Height); _parent._savedLogicalSize = s; _parent.Resized?.Invoke(s); } @@ -192,14 +192,14 @@ namespace Avalonia.Native _parent.RawMouseEvent(type, timeStamp, modifiers, point, delta); } - bool IAvnWindowBaseEvents.RawKeyEvent(AvnRawKeyEventType type, uint timeStamp, AvnInputModifiers modifiers, uint key) + int IAvnWindowBaseEvents.RawKeyEvent(AvnRawKeyEventType type, uint timeStamp, AvnInputModifiers modifiers, uint key) { - return _parent.RawKeyEvent(type, timeStamp, modifiers, key); + return _parent.RawKeyEvent(type, timeStamp, modifiers, key).AsComBool(); } - bool IAvnWindowBaseEvents.RawTextInputEvent(uint timeStamp, string text) + int IAvnWindowBaseEvents.RawTextInputEvent(uint timeStamp, string text) { - return _parent.RawTextInputEvent(timeStamp, text); + return _parent.RawTextInputEvent(timeStamp, text).AsComBool(); } @@ -251,6 +251,9 @@ namespace Avalonia.Native public bool RawTextInputEvent(uint timeStamp, string text) { + if (_inputRoot is null) + return false; + Dispatcher.UIThread.RunJobs(DispatcherPriority.Input + 1); var args = new RawTextInputEventArgs(_keyboard, timeStamp, _inputRoot, text); @@ -262,6 +265,9 @@ namespace Avalonia.Native public bool RawKeyEvent(AvnRawKeyEventType type, uint timeStamp, AvnInputModifiers modifiers, uint key) { + if (_inputRoot is null) + return false; + Dispatcher.UIThread.RunJobs(DispatcherPriority.Input + 1); var args = new RawKeyEventArgs(_keyboard, timeStamp, _inputRoot, (RawKeyEventType)type, (Key)key, (RawInputModifiers)modifiers); @@ -278,6 +284,9 @@ namespace Avalonia.Native public void RawMouseEvent(AvnRawMouseEventType type, uint timeStamp, AvnInputModifiers modifiers, AvnPoint point, AvnVector delta) { + if (_inputRoot is null) + return; + Dispatcher.UIThread.RunJobs(DispatcherPriority.Input + 1); switch (type) @@ -327,13 +336,13 @@ namespace Avalonia.Native _nativeControlHost = null; (Screen as ScreenImpl)?.Dispose(); + _mouse.Dispose(); } public void Invalidate(Rect rect) { - if (!_deferredRendering && _native != null) - _native.Invalidate(new AvnRect { Height = rect.Height, Width = rect.Width, X = rect.X, Y = rect.Y }); + _native?.Invalidate(new AvnRect { Height = rect.Height, Width = rect.Width, X = rect.X, Y = rect.Y }); } public void SetInputRoot(IInputRoot inputRoot) @@ -342,15 +351,15 @@ namespace Avalonia.Native } - public virtual void Show() + public virtual void Show(bool activate) { - _native.Show(); + _native.Show(activate.AsComBool()); } public PixelPoint Position { - get => _native.GetPosition().ToAvaloniaPixelPoint(); + get => _native.Position.ToAvaloniaPixelPoint(); set => _native.SetPosition(value.ToAvnPoint()); } @@ -379,10 +388,10 @@ namespace Avalonia.Native public void SetTopmost(bool value) { - _native.SetTopMost(value); + _native.SetTopMost(value.AsComBool()); } - public double RenderScaling => _native?.GetScaling() ?? 1; + public double RenderScaling => _native?.Scaling ?? 1; public double DesktopScaling => 1; @@ -398,7 +407,7 @@ namespace Avalonia.Native var newCursor = cursor as AvaloniaNativeCursor; newCursor = newCursor ?? (_cursorFactory.GetCursor(StandardCursorType.Arrow) as AvaloniaNativeCursor); - _native.Cursor = newCursor.Cursor; + _native.SetCursor(newCursor.Cursor); } public Action PositionChanged { get; set; } @@ -447,7 +456,7 @@ namespace Avalonia.Native TransparencyLevel = transparencyLevel; - _native?.SetBlurEnabled(TransparencyLevel >= WindowTransparencyLevel.Blur); + _native?.SetBlurEnabled((TransparencyLevel >= WindowTransparencyLevel.Blur).AsComBool()); TransparencyLevelChanged?.Invoke(TransparencyLevel); } } diff --git a/src/Avalonia.Native/avn.idl b/src/Avalonia.Native/avn.idl new file mode 100644 index 0000000000..166046ca24 --- /dev/null +++ b/src/Avalonia.Native/avn.idl @@ -0,0 +1,728 @@ +@clr-namespace Avalonia.Native.Interop +@clr-access internal +@clr-map bool int +@cpp-preamble @@ +#include "com.h" +#include "stddef.h" +@@ + +enum AvnKey +{ + AvnKeyNone = 0, + AvnKeyCancel = 1, + AvnKeyBack = 2, + AvnKeyTab = 3, + AvnKeyLineFeed = 4, + AvnKeyClear = 5, + AvnKeyReturn = 6, + AvnKeyEnter = 6, + AvnKeyPause = 7, + AvnKeyCapsLock = 8, + AvnKeyCapital = 8, + AvnKeyHangulMode = 9, + AvnKeyKanaMode = 9, + AvnKeyJunjaMode = 10, + AvnKeyFinalMode = 11, + AvnKeyKanjiMode = 12, + HanjaMode = 12, + Escape = 13, + ImeConvert = 14, + ImeNonConvert = 15, + ImeAccept = 16, + ImeModeChange = 17, + Space = 18, + PageUp = 19, + Prior = 19, + PageDown = 20, + Next = 20, + End = 21, + Home = 22, + Left = 23, + Up = 24, + Right = 25, + Down = 26, + Select = 27, + Print = 28, + Execute = 29, + Snapshot = 30, + PrintScreen = 30, + Insert = 31, + Delete = 32, + Help = 33, + D0 = 34, + D1 = 35, + D2 = 36, + D3 = 37, + D4 = 38, + D5 = 39, + D6 = 40, + D7 = 41, + D8 = 42, + D9 = 43, + A = 44, + B = 45, + C = 46, + D = 47, + E = 48, + F = 49, + G = 50, + H = 51, + I = 52, + J = 53, + AvnKeyK = 54, + L = 55, + M = 56, + N = 57, + O = 58, + P = 59, + Q = 60, + R = 61, + S = 62, + T = 63, + U = 64, + V = 65, + W = 66, + X = 67, + Y = 68, + Z = 69, + LWin = 70, + RWin = 71, + Apps = 72, + Sleep = 73, + NumPad0 = 74, + NumPad1 = 75, + NumPad2 = 76, + NumPad3 = 77, + NumPad4 = 78, + NumPad5 = 79, + NumPad6 = 80, + NumPad7 = 81, + NumPad8 = 82, + NumPad9 = 83, + Multiply = 84, + Add = 85, + Separator = 86, + Subtract = 87, + Decimal = 88, + Divide = 89, + F1 = 90, + F2 = 91, + F3 = 92, + F4 = 93, + F5 = 94, + F6 = 95, + F7 = 96, + F8 = 97, + F9 = 98, + F10 = 99, + F11 = 100, + F12 = 101, + F13 = 102, + F14 = 103, + F15 = 104, + F16 = 105, + F17 = 106, + F18 = 107, + F19 = 108, + F20 = 109, + F21 = 110, + F22 = 111, + F23 = 112, + F24 = 113, + NumLock = 114, + Scroll = 115, + LeftShift = 116, + RightShift = 117, + LeftCtrl = 118, + RightCtrl = 119, + LeftAlt = 120, + RightAlt = 121, + BrowserBack = 122, + BrowserForward = 123, + BrowserRefresh = 124, + BrowserStop = 125, + BrowserSearch = 126, + BrowserFavorites = 127, + BrowserHome = 128, + VolumeMute = 129, + VolumeDown = 130, + VolumeUp = 131, + MediaNextTrack = 132, + MediaPreviousTrack = 133, + MediaStop = 134, + MediaPlayPause = 135, + LaunchMail = 136, + SelectMedia = 137, + LaunchApplication1 = 138, + LaunchApplication2 = 139, + OemSemicolon = 140, + Oem1 = 140, + OemPlus = 141, + OemComma = 142, + OemMinus = 143, + OemPeriod = 144, + OemQuestion = 145, + Oem2 = 145, + OemTilde = 146, + Oem3 = 146, + AbntC1 = 147, + AbntC2 = 148, + OemOpenBrackets = 149, + Oem4 = 149, + OemPipe = 150, + Oem5 = 150, + OemCloseBrackets = 151, + Oem6 = 151, + OemQuotes = 152, + Oem7 = 152, + Oem8 = 153, + OemBackslash = 154, + Oem102 = 154, + ImeProcessed = 155, + System = 156, + OemAttn = 157, + DbeAlphanumeric = 157, + OemFinish = 158, + DbeKatakana = 158, + DbeHiragana = 159, + OemCopy = 159, + DbeSbcsChar = 160, + OemAuto = 160, + DbeDbcsChar = 161, + OemEnlw = 161, + OemBackTab = 162, + DbeRoman = 162, + DbeNoRoman = 163, + Attn = 163, + CrSel = 164, + DbeEnterWordRegisterMode = 164, + ExSel = 165, + DbeEnterImeConfigureMode = 165, + EraseEof = 166, + DbeFlushString = 166, + Play = 167, + DbeCodeInput = 167, + DbeNoCodeInput = 168, + Zoom = 168, + NoName = 169, + DbeDetermineString = 169, + DbeEnterDialogConversionMode = 170, + Pa1 = 170, + OemClear = 171, + DeadCharProcessed = 172, +}; + +enum SystemDecorations { + SystemDecorationsNone = 0, + SystemDecorationsBorderOnly = 1, + SystemDecorationsFull = 2, +} + +struct AvnSize +{ + double Width, Height; +} + +struct AvnPixelSize +{ + int Width, Height; +} + +struct AvnRect +{ + double X, Y, Width, Height; +} + +struct AvnVector +{ + double X, Y; +} + +struct AvnPoint +{ + double X, Y; +} + +struct AvnScreen +{ + AvnRect Bounds; + AvnRect WorkingArea; + float PixelDensity; + bool Primary; +} + +enum AvnPixelFormat +{ + kAvnRgb565, + kAvnRgba8888, + kAvnBgra8888 +} + +struct AvnFramebuffer +{ + void* Data; + int Width; + int Height; + int Stride; + AvnVector Dpi; + AvnPixelFormat PixelFormat; +} + +struct AvnColor +{ + byte Alpha; + byte Red; + byte Green; + byte Blue; +} + +enum AvnRawMouseEventType +{ + LeaveWindow, + LeftButtonDown, + LeftButtonUp, + RightButtonDown, + RightButtonUp, + MiddleButtonDown, + MiddleButtonUp, + XButton1Down, + XButton1Up, + XButton2Down, + XButton2Up, + Move, + Wheel, + NonClientLeftButtonDown, + TouchBegin, + TouchUpdate, + TouchEnd, + TouchCancel +} + +enum AvnRawKeyEventType +{ + KeyDown, + KeyUp +} + +enum AvnInputModifiers +{ + AvnInputModifiersNone = 0, + Alt = 1, + Control = 2, + Shift = 4, + Windows = 8, + LeftMouseButton = 16, + RightMouseButton = 32, + MiddleMouseButton = 64, + XButton1MouseButton = 128, + XButton2MouseButton = 256 +} + +[class-enum] +enum AvnDragDropEffects +{ + None = 0, + Copy = 1, + Move = 2, + Link = 4, +} + +[class-enum] +enum AvnDragEventType +{ + Enter, + Over, + Leave, + Drop +} + +enum AvnWindowState +{ + Normal, + Minimized, + Maximized, + FullScreen, +} + +enum AvnStandardCursorType +{ + CursorArrow, + CursorIbeam, + CursorWait, + CursorCross, + CursorUpArrow, + CursorSizeWestEast, + CursorSizeNorthSouth, + CursorSizeAll, + CursorNo, + CursorHand, + CursorAppStarting, + CursorHelp, + CursorTopSide, + CursorBottomSize, + CursorLeftSide, + CursorRightSide, + CursorTopLeftCorner, + CursorTopRightCorner, + CursorBottomLeftCorner, + CursorBottomRightCorner, + CursorDragMove, + CursorDragCopy, + CursorDragLink, + CursorNone +} + +enum AvnWindowEdge +{ + WindowEdgeNorthWest, + WindowEdgeNorth, + WindowEdgeNorthEast, + WindowEdgeWest, + WindowEdgeEast, + WindowEdgeSouthWest, + WindowEdgeSouth, + WindowEdgeSouthEast +} + +enum AvnMenuItemToggleType +{ + None, + CheckMark, + Radio +} + +enum AvnExtendClientAreaChromeHints +{ + AvnNoChrome = 0, + AvnSystemChrome = 0x01, + AvnPreferSystemChrome = 0x02, + AvnOSXThickTitleBar = 0x08, + AvnDefaultChrome = AvnSystemChrome, +} + +[uuid(809c652e-7396-11d2-9771-00a0c9b4d50c)] +interface IAvaloniaNativeFactory : IUnknown +{ + HRESULT Initialize(IAvnGCHandleDeallocatorCallback* deallocator); + IAvnMacOptions* GetMacOptions(); + HRESULT CreateWindow(IAvnWindowEvents* cb, IAvnGlContext* gl, IAvnWindow** ppv); + HRESULT CreatePopup(IAvnWindowEvents* cb, IAvnGlContext* gl, IAvnPopup** ppv); + HRESULT CreatePlatformThreadingInterface(IAvnPlatformThreadingInterface** ppv); + HRESULT CreateSystemDialogs(IAvnSystemDialogs** ppv); + HRESULT CreateScreens(IAvnScreens** ppv); + HRESULT CreateClipboard(IAvnClipboard** ppv); + HRESULT CreateDndClipboard(IAvnClipboard** ppv); + HRESULT CreateCursorFactory(IAvnCursorFactory** ppv); + HRESULT ObtainGlDisplay(IAvnGlDisplay** ppv); + HRESULT SetAppMenu(IAvnMenu* menu); + HRESULT CreateMenu(IAvnMenuEvents* cb, IAvnMenu** ppv); + HRESULT CreateMenuItem(IAvnMenuItem** ppv); + HRESULT CreateMenuItemSeperator(IAvnMenuItem** ppv); +} + +[uuid(233e094f-9b9f-44a3-9a6e-6948bbdd9fb1)] +interface IAvnString : IUnknown +{ + HRESULT Pointer(void**retOut); + HRESULT Length(int*ret); +} + +[uuid(e5aca675-02b7-4129-aa79-d6e417210bda)] +interface IAvnWindowBase : IUnknown +{ + HRESULT Show(bool activate); + HRESULT Hide(); + HRESULT Close(); + HRESULT Activate(); + HRESULT GetClientSize(AvnSize*ret); + HRESULT GetScaling(double*ret); + HRESULT SetMinMaxSize(AvnSize minSize, AvnSize maxSize); + HRESULT Resize(double width, double height); + HRESULT Invalidate(AvnRect rect); + HRESULT BeginMoveDrag(); + HRESULT BeginResizeDrag(AvnWindowEdge edge); + HRESULT GetPosition(AvnPoint*ret); + HRESULT SetPosition(AvnPoint point); + HRESULT PointToClient(AvnPoint point, AvnPoint*ret); + HRESULT PointToScreen(AvnPoint point, AvnPoint*ret); + HRESULT ThreadSafeSetSwRenderedFrame(AvnFramebuffer* fb, IUnknown* dispose); + HRESULT SetTopMost(bool value); + HRESULT SetCursor(IAvnCursor* cursor); + HRESULT CreateGlRenderTarget(IAvnGlSurfaceRenderTarget** ret); + HRESULT SetMainMenu(IAvnMenu* menu); + HRESULT ObtainNSWindowHandle([intptr]void** retOut); + HRESULT ObtainNSWindowHandleRetained([intptr]void** retOut); + HRESULT ObtainNSViewHandle([intptr]void** retOut); + HRESULT ObtainNSViewHandleRetained([intptr]void** retOut); + HRESULT CreateNativeControlHost(IAvnNativeControlHost** retOut); + HRESULT BeginDragAndDropOperation(AvnDragDropEffects effects, AvnPoint point, + IAvnClipboard* clipboard, IAvnDndResultCallback* cb, [intptr]void* sourceHandle); + HRESULT SetBlurEnabled(bool enable); +} + +[uuid(83e588f3-6981-4e48-9ea0-e1e569f79a91), cpp-virtual-inherits] +interface IAvnPopup : IAvnWindowBase +{ + +} + +[uuid(cab661de-49d6-4ead-b59c-eac9b2b6c28d), cpp-virtual-inherits] +interface IAvnWindow : IAvnWindowBase +{ + HRESULT SetEnabled(bool enable); + HRESULT SetParent(IAvnWindow* parent); + HRESULT SetCanResize(bool value); + HRESULT SetDecorations(SystemDecorations value); + HRESULT SetTitle(char* utf8Title); + HRESULT SetTitleBarColor(AvnColor color); + HRESULT SetWindowState(AvnWindowState state); + HRESULT GetWindowState(AvnWindowState*ret); + HRESULT TakeFocusFromChildren(); + HRESULT SetExtendClientArea(bool enable); + HRESULT SetExtendClientAreaHints(AvnExtendClientAreaChromeHints hints); + HRESULT GetExtendTitleBarHeight(double*ret); + HRESULT SetExtendTitleBarHeight(double value); +} + +[uuid(939b6599-40a8-4710-a4c8-5d72d8f174fb)] +interface IAvnWindowBaseEvents : IUnknown +{ + HRESULT Paint(); + void Closed(); + void Activated(); + void Deactivated(); + void Resized([const] AvnSize& size); + void PositionChanged(AvnPoint position); + void RawMouseEvent(AvnRawMouseEventType type, + uint timeStamp, + AvnInputModifiers modifiers, + AvnPoint point, + AvnVector delta); + bool RawKeyEvent(AvnRawKeyEventType type, uint timeStamp, AvnInputModifiers modifiers, uint key); + bool RawTextInputEvent(uint timeStamp, [const] char* text); + void ScalingChanged(double scaling); + void RunRenderPriorityJobs(); + void LostFocus(); + AvnDragDropEffects DragEvent(AvnDragEventType type, AvnPoint position, + AvnInputModifiers modifiers, AvnDragDropEffects effects, + IAvnClipboard* clipboard, [intptr]void* dataObjectHandle); +} + +[uuid(1ae178ee-1fcc-447f-b6dd-b7bb727f934c)] +interface IAvnWindowEvents : IAvnWindowBaseEvents +{ + /** + * Closing Event + * Called when the user presses the OS window close button. + * return true to allow the close, return false to prevent close. + */ + bool Closing(); + + void WindowStateChanged(AvnWindowState state); + + void GotInputWhenDisabled(); +} + +[uuid(e34ae0f8-18b4-48a3-b09d-2e6b19a3cf5e)] +interface IAvnMacOptions : IUnknown +{ + HRESULT SetShowInDock(int show); + HRESULT SetApplicationTitle(char* utf8string); +} + +[uuid(04c1b049-1f43-418a-9159-cae627ec1367)] +interface IAvnActionCallback : IUnknown +{ + void Run(); +} + +[uuid(6df4d2db-0b80-4f59-ad88-0baa5e21eb14)] +interface IAvnSignaledCallback : IUnknown +{ + void Signaled(int priority, bool priorityContainsMeaningfulValue); +} + +[uuid(97330f88-c22b-4a8e-a130-201520091b01)] +interface IAvnLoopCancellation : IUnknown +{ + void Cancel(); +} + +[uuid(fbc06f3d-7860-42df-83fd-53c4b02dd9c3)] +interface IAvnPlatformThreadingInterface : IUnknown +{ + bool GetCurrentThreadIsLoopThread(); + void SetSignaledCallback(IAvnSignaledCallback* cb); + IAvnLoopCancellation* CreateLoopCancellation(); + HRESULT RunLoop(IAvnLoopCancellation* cancel); + // Can't pass int* to sharpgentools for some reason + void Signal(int priority); + IUnknown* StartTimer(int priority, int ms, IAvnActionCallback* callback); +} + +[uuid(6c621a6e-e4c1-4ae3-9749-83eeeffa09b6)] +interface IAvnSystemDialogEvents : IUnknown +{ + void OnCompleted(int numResults, void* ptrFirstResult); +} + +[uuid(4d7a47db-a944-4061-abe7-62cb6aa0ffd5)] +interface IAvnSystemDialogs : IUnknown +{ + void SelectFolderDialog(IAvnWindow* parentWindowHandle, + IAvnSystemDialogEvents* events, + [const] char* title, + [const] char* initialPath); + + void OpenFileDialog(IAvnWindow* parentWindowHandle, + IAvnSystemDialogEvents* events, + bool allowMultiple, + [const] char* title, + [const] char* initialDirectory, + [const] char* initialFile, + [const] char* filters); + + void SaveFileDialog(IAvnWindow* parentWindowHandle, + IAvnSystemDialogEvents* events, + [const] char* title, + [const] char* initialDirectory, + [const] char* initialFile, + [const] char* filters); +} + +[uuid(9a52bc7a-d8c7-4230-8d34-704a0b70a933)] +interface IAvnScreens : IUnknown +{ + HRESULT GetScreenCount(int* ret); + HRESULT GetScreen(int index, AvnScreen* ret); +} + +[uuid(792b1bd4-76cc-46ea-bfd0-9d642154b1b3)] +interface IAvnClipboard : IUnknown +{ + HRESULT GetText(char* type, IAvnString**ppv); + HRESULT SetText(char* type, char* utf8Text); + HRESULT ObtainFormats(IAvnStringArray**ppv); + HRESULT GetStrings(char* type, IAvnStringArray**ppv); + HRESULT SetBytes(char* type, void* utf8Text, int len); + HRESULT GetBytes(char* type, IAvnString**ppv); + + HRESULT Clear(); +} + +[uuid(3f998545-f027-4d4d-bd2a-1a80926d984e)] +interface IAvnCursor : IUnknown +{ +} + +[uuid(51ecfb12-c427-4757-a2c9-1596bfce53ef)] +interface IAvnCursorFactory : IUnknown +{ + HRESULT GetCursor(AvnStandardCursorType cursorType, IAvnCursor** retOut); +} + +[uuid(60452465-8616-40af-bc00-042e69828ce7)] +interface IAvnGlDisplay : IUnknown +{ + HRESULT CreateContext(IAvnGlContext* share, IAvnGlContext**ppv); + void LegacyClearCurrentContext(); + HRESULT WrapContext([intptr]void* native, IAvnGlContext**ppv); + [intptr]void* GetProcAddress(char* proc); +} + +[uuid(78c5711e-2a98-40d2-bac4-0cc9a49dc4f3)] +interface IAvnGlContext : IUnknown +{ + HRESULT MakeCurrent(IUnknown** ppv); + HRESULT LegacyMakeCurrent(); + int GetSampleCount(); + int GetStencilSize(); + [intptr]void* GetNativeHandle(); +} + +[uuid(931062d2-5bc8-4062-8588-83dd8deb99c2)] +interface IAvnGlSurfaceRenderTarget : IUnknown +{ + HRESULT BeginDrawing(IAvnGlSurfaceRenderingSession** ret); +} + +[uuid(e625b406-f04c-484e-946a-4abd2c6015ad)] +interface IAvnGlSurfaceRenderingSession : IUnknown +{ + HRESULT GetPixelSize(AvnPixelSize* ret); + HRESULT GetScaling(double* ret); +} + +[uuid(a7724dc1-cf6b-4fa8-9d23-228bf2593edc)] +interface IAvnMenu : IUnknown +{ + HRESULT InsertItem(int index, IAvnMenuItem* item); + HRESULT RemoveItem(IAvnMenuItem* item); + HRESULT SetTitle(char* utf8String); + HRESULT Clear(); +} + +[uuid(59e0586d-bd1c-4b85-9882-80d448b0fed9)] +interface IAvnPredicateCallback : IUnknown +{ + bool Evaluate(); +} + +[uuid(f890219a-1720-4cd5-9a26-cd95fccbf53c)] +interface IAvnMenuItem : IUnknown +{ + HRESULT SetSubMenu(IAvnMenu* menu); + HRESULT SetTitle(char* utf8String); + HRESULT SetGesture(AvnKey key, AvnInputModifiers modifiers); + HRESULT SetAction(IAvnPredicateCallback* predicate, IAvnActionCallback* callback); + HRESULT SetIsChecked(bool isChecked); + HRESULT SetToggleType(AvnMenuItemToggleType toggleType); + HRESULT SetIcon(void* data, size_t length); +} + +[uuid(0af7df53-7632-42f4-a650-0992c361b477)] +interface IAvnMenuEvents : IUnknown +{ + /** + * NeedsUpdate + */ + void NeedsUpdate(); +} + +[uuid(5142bb41-66ab-49e7-bb37-cd079c000f27)] +interface IAvnStringArray : IUnknown +{ + uint GetCount(); + HRESULT Get(uint index, IAvnString**ppv); +} + +[uuid(a13d2382-3b3a-4d1c-9b27-8f34653d3f01)] +interface IAvnDndResultCallback : IUnknown +{ + void OnDragAndDropComplete(AvnDragDropEffects effecct); +} + +[uuid(f07c608e-52e9-422d-836e-c70f6e9b80f5)] +interface IAvnGCHandleDeallocatorCallback : IUnknown +{ + void FreeGCHandle([intptr]void* handle); +} + +[uuid(91c7f677-f26b-4ff3-93cc-cf15aa966ffa)] +interface IAvnNativeControlHost : IUnknown +{ + HRESULT CreateDefaultChild([intptr]void* parent, [intptr]void** retOut); + IAvnNativeControlHostTopLevelAttachment* CreateAttachment(); + void DestroyDefaultChild([intptr]void* child); +} + +[uuid(14a9e164-1aae-4271-bb78-7b5230999b52)] +interface IAvnNativeControlHostTopLevelAttachment : IUnknown +{ + [intptr]void* GetParentHandle(); + HRESULT InitializeWithChildHandle([intptr]void* child); + HRESULT AttachTo(IAvnNativeControlHost* host); + void ShowInBounds(float x, float y, float width, float height); + void HideWithSize(float width, float height); + void ReleaseChild(); +} diff --git a/src/Avalonia.OpenGL/Angle/AngleEglInterface.cs b/src/Avalonia.OpenGL/Angle/AngleEglInterface.cs index 8c9b028164..3a332f37ad 100644 --- a/src/Avalonia.OpenGL/Angle/AngleEglInterface.cs +++ b/src/Avalonia.OpenGL/Angle/AngleEglInterface.cs @@ -1,15 +1,13 @@ using System; using System.Runtime.InteropServices; using Avalonia.OpenGL.Egl; -using Avalonia.Platform; -using Avalonia.Platform.Interop; namespace Avalonia.OpenGL.Angle { public class AngleEglInterface : EglInterface { - [DllImport("libegl.dll", CharSet = CharSet.Ansi)] - static extern IntPtr eglGetProcAddress(string proc); + [DllImport("av_libGLESv2.dll", CharSet = CharSet.Ansi)] + static extern IntPtr EGL_GetProcAddress(string proc); public AngleEglInterface() : base(LoadAngle()) { @@ -20,14 +18,14 @@ namespace Avalonia.OpenGL.Angle { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - var disp = eglGetProcAddress("eglGetPlatformDisplayEXT"); + var disp = EGL_GetProcAddress("eglGetPlatformDisplayEXT"); if (disp == IntPtr.Zero) { throw new OpenGlException("libegl.dll doesn't have eglGetPlatformDisplayEXT entry point"); } - return eglGetProcAddress; + return EGL_GetProcAddress; } throw new PlatformNotSupportedException(); diff --git a/src/Avalonia.OpenGL/Angle/AngleWin32EglDisplay.cs b/src/Avalonia.OpenGL/Angle/AngleWin32EglDisplay.cs index 191fb53204..94e7728d68 100644 --- a/src/Avalonia.OpenGL/Angle/AngleWin32EglDisplay.cs +++ b/src/Avalonia.OpenGL/Angle/AngleWin32EglDisplay.cs @@ -82,7 +82,14 @@ namespace Avalonia.OpenGL.Angle { if (PlatformApi != AngleOptions.PlatformApi.DirectX11) throw new InvalidOperationException("Current platform API is " + PlatformApi); - return egl.CreatePBufferFromClientBuffer(EGL_D3D_TEXTURE_ANGLE, handle, new[] { EGL_NONE, EGL_NONE }); + return egl.CreatePBufferFromClientBuffer(EGL_D3D_TEXTURE_ANGLE, handle, new[] { EGL_NONE, EGL_NONE }); + } + + public EglSurface WrapDirect3D11Texture(EglPlatformOpenGlInterface egl, IntPtr handle, int offsetX, int offsetY, int width, int height) + { + if (PlatformApi != AngleOptions.PlatformApi.DirectX11) + throw new InvalidOperationException("Current platform API is " + PlatformApi); + return egl.CreatePBufferFromClientBuffer(EGL_D3D_TEXTURE_ANGLE, handle, new[] { EGL_WIDTH, width, EGL_HEIGHT, height, EGL_FLEXIBLE_SURFACE_COMPATIBILITY_SUPPORTED_ANGLE, EGL_TRUE, EGL_TEXTURE_OFFSET_X_ANGLE, offsetX, EGL_TEXTURE_OFFSET_Y_ANGLE, offsetY, EGL_NONE }); } } } diff --git a/src/Avalonia.OpenGL/Egl/EglConsts.cs b/src/Avalonia.OpenGL/Egl/EglConsts.cs index 58f5f1cef5..530d3401f6 100644 --- a/src/Avalonia.OpenGL/Egl/EglConsts.cs +++ b/src/Avalonia.OpenGL/Egl/EglConsts.cs @@ -205,5 +205,11 @@ namespace Avalonia.OpenGL.Egl public const int EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE = 0x3200; public const int EGL_D3D_TEXTURE_ANGLE = 0x33A3; + + + public const int EGL_TEXTURE_OFFSET_X_ANGLE = 0x3490; + public const int EGL_TEXTURE_OFFSET_Y_ANGLE = 0x3491; + + public const int EGL_FLEXIBLE_SURFACE_COMPATIBILITY_SUPPORTED_ANGLE = 0x33A6; } } diff --git a/src/Avalonia.OpenGL/Egl/EglContext.cs b/src/Avalonia.OpenGL/Egl/EglContext.cs index 249b4d547f..58137dfff0 100644 --- a/src/Avalonia.OpenGL/Egl/EglContext.cs +++ b/src/Avalonia.OpenGL/Egl/EglContext.cs @@ -93,6 +93,14 @@ namespace Avalonia.OpenGL.Egl return MakeCurrent(); } + public IDisposable EnsureLocked() + { + if (IsCurrent) + return Disposable.Empty; + Monitor.Enter(_lock); + return Disposable.Create(() => Monitor.Exit(_lock)); + } + public bool IsSharedWith(IGlContext context) { var c = (EglContext)context; diff --git a/src/Avalonia.ReactiveUI.Events/Avalonia.ReactiveUI.Events.csproj b/src/Avalonia.ReactiveUI.Events/Avalonia.ReactiveUI.Events.csproj index 75eeb92f42..7f58e455f9 100644 --- a/src/Avalonia.ReactiveUI.Events/Avalonia.ReactiveUI.Events.csproj +++ b/src/Avalonia.ReactiveUI.Events/Avalonia.ReactiveUI.Events.csproj @@ -2,6 +2,7 @@ netstandard2.0 Avalonia.ReactiveUI.Events + false diff --git a/src/Avalonia.ReactiveUI/Avalonia.ReactiveUI.csproj b/src/Avalonia.ReactiveUI/Avalonia.ReactiveUI.csproj index d01a495108..624c5772a9 100644 --- a/src/Avalonia.ReactiveUI/Avalonia.ReactiveUI.csproj +++ b/src/Avalonia.ReactiveUI/Avalonia.ReactiveUI.csproj @@ -2,6 +2,7 @@ netstandard2.0 Avalonia.ReactiveUI + false diff --git a/src/Avalonia.ReactiveUI/ReactiveUserControl.cs b/src/Avalonia.ReactiveUI/ReactiveUserControl.cs index fc48a8853d..f4824ade0a 100644 --- a/src/Avalonia.ReactiveUI/ReactiveUserControl.cs +++ b/src/Avalonia.ReactiveUI/ReactiveUserControl.cs @@ -1,3 +1,6 @@ +using System; +using System.Reactive.Disposables; +using System.Reactive.Linq; using Avalonia; using Avalonia.VisualTree; using Avalonia.Controls; @@ -6,8 +9,10 @@ using ReactiveUI; namespace Avalonia.ReactiveUI { /// - /// A ReactiveUI UserControl that implements - /// and will activate your ViewModel automatically if it supports activation. + /// A ReactiveUI that implements the interface and + /// will activate your ViewModel automatically if the view model implements . + /// When the DataContext property changes, this class will update the ViewModel property with the new DataContext + /// value, and vice versa. /// /// ViewModel type. public class ReactiveUserControl : UserControl, IViewFor where TViewModel : class @@ -20,7 +25,10 @@ namespace Avalonia.ReactiveUI /// public ReactiveUserControl() { - DataContextChanged += (sender, args) => ViewModel = DataContext as TViewModel; + // This WhenActivated block calls ViewModel's WhenActivated + // block if the ViewModel implements IActivatableViewModel. + this.WhenActivated(disposables => { }); + this.GetObservable(ViewModelProperty).Subscribe(OnViewModelChanged); } /// @@ -37,5 +45,22 @@ namespace Avalonia.ReactiveUI get => ViewModel; set => ViewModel = (TViewModel)value; } + + protected override void OnDataContextChanged(EventArgs e) + { + ViewModel = DataContext as TViewModel; + } + + private void OnViewModelChanged(object value) + { + if (value == null) + { + ClearValue(DataContextProperty); + } + else if (DataContext != value) + { + DataContext = value; + } + } } } diff --git a/src/Avalonia.ReactiveUI/ReactiveWindow.cs b/src/Avalonia.ReactiveUI/ReactiveWindow.cs index 5695a727af..758a807bfc 100644 --- a/src/Avalonia.ReactiveUI/ReactiveWindow.cs +++ b/src/Avalonia.ReactiveUI/ReactiveWindow.cs @@ -1,3 +1,6 @@ +using System; +using System.Reactive.Disposables; +using System.Reactive.Linq; using Avalonia; using Avalonia.VisualTree; using Avalonia.Controls; @@ -6,8 +9,10 @@ using ReactiveUI; namespace Avalonia.ReactiveUI { /// - /// A ReactiveUI Window that implements - /// and will activate your ViewModel automatically if it supports activation. + /// A ReactiveUI that implements the interface and will + /// activate your ViewModel automatically if the view model implements . When + /// the DataContext property changes, this class will update the ViewModel property with the new DataContext value, + /// and vice versa. /// /// ViewModel type. public class ReactiveWindow : Window, IViewFor where TViewModel : class @@ -20,7 +25,11 @@ namespace Avalonia.ReactiveUI /// public ReactiveWindow() { - DataContextChanged += (sender, args) => ViewModel = DataContext as TViewModel; + // This WhenActivated block calls ViewModel's WhenActivated + // block if the ViewModel implements IActivatableViewModel. + this.WhenActivated(disposables => { }); + this.GetObservable(DataContextProperty).Subscribe(OnDataContextChanged); + this.GetObservable(ViewModelProperty).Subscribe(OnViewModelChanged); } /// @@ -37,5 +46,29 @@ namespace Avalonia.ReactiveUI get => ViewModel; set => ViewModel = (TViewModel)value; } + + private void OnDataContextChanged(object value) + { + if (value is TViewModel viewModel) + { + ViewModel = viewModel; + } + else + { + ViewModel = null; + } + } + + private void OnViewModelChanged(object value) + { + if (value == null) + { + ClearValue(DataContextProperty); + } + else if (DataContext != value) + { + DataContext = value; + } + } } } diff --git a/src/Avalonia.Styling/Controls/ResourceNodeExtensions.cs b/src/Avalonia.Styling/Controls/ResourceNodeExtensions.cs index 250274c39b..be1069a4da 100644 --- a/src/Avalonia.Styling/Controls/ResourceNodeExtensions.cs +++ b/src/Avalonia.Styling/Controls/ResourceNodeExtensions.cs @@ -60,7 +60,7 @@ namespace Avalonia.Controls } public static IObservable GetResourceObservable( - this IStyledElement control, + this IResourceHost control, object key, Func? converter = null) { @@ -83,11 +83,11 @@ namespace Avalonia.Controls private class ResourceObservable : LightweightObservableBase { - private readonly IStyledElement _target; + private readonly IResourceHost _target; private readonly object _key; private readonly Func? _converter; - public ResourceObservable(IStyledElement target, object key, Func? converter) + public ResourceObservable(IResourceHost target, object key, Func? converter) { _target = target; _key = key; @@ -147,13 +147,16 @@ namespace Avalonia.Controls { if (_target.Owner is object) { - observer.OnNext(Convert(_target.Owner?.FindResource(_key))); + observer.OnNext(Convert(_target.Owner.FindResource(_key))); } } private void PublishNext() { - PublishNext(Convert(_target.Owner?.FindResource(_key))); + if (_target.Owner is object) + { + PublishNext(Convert(_target.Owner.FindResource(_key))); + } } private void OwnerChanged(object sender, EventArgs e) diff --git a/src/Avalonia.Styling/Properties/AssemblyInfo.cs b/src/Avalonia.Styling/Properties/AssemblyInfo.cs index f6b69d8150..34c71fffe3 100644 --- a/src/Avalonia.Styling/Properties/AssemblyInfo.cs +++ b/src/Avalonia.Styling/Properties/AssemblyInfo.cs @@ -5,4 +5,8 @@ using Avalonia.Metadata; [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Controls")] [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.LogicalTree")] [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Styling")] +#if SIGNED_BUILD [assembly: InternalsVisibleTo("Avalonia.Styling.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] +#else +[assembly: InternalsVisibleTo("Avalonia.Styling.UnitTests")] +#endif diff --git a/src/Avalonia.Styling/StyledElement.cs b/src/Avalonia.Styling/StyledElement.cs index 65885ddebe..cc8d91462d 100644 --- a/src/Avalonia.Styling/StyledElement.cs +++ b/src/Avalonia.Styling/StyledElement.cs @@ -1,8 +1,8 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.ComponentModel; -using System.Linq; using Avalonia.Animation; using Avalonia.Collections; using Avalonia.Controls; @@ -479,16 +479,16 @@ namespace Avalonia switch (e.Action) { case NotifyCollectionChangedAction.Add: - SetLogicalParent(e.NewItems.Cast()); + SetLogicalParent(e.NewItems); break; case NotifyCollectionChangedAction.Remove: - ClearLogicalParent(e.OldItems.Cast()); + ClearLogicalParent(e.OldItems); break; case NotifyCollectionChangedAction.Replace: - ClearLogicalParent(e.OldItems.Cast()); - SetLogicalParent(e.NewItems.Cast()); + ClearLogicalParent(e.OldItems); + SetLogicalParent(e.NewItems); break; case NotifyCollectionChangedAction.Reset: @@ -702,13 +702,32 @@ namespace Avalonia OnDataContextChanged(EventArgs.Empty); } - private void SetLogicalParent(IEnumerable children) + private void SetLogicalParent(IList children) { - foreach (var i in children) + var count = children.Count; + + for (var i = 0; i < count; i++) + { + var logical = (ILogical) children[i]; + + if (logical.LogicalParent is null) + { + ((ISetLogicalParent)logical).SetParent(this); + } + } + } + + private void ClearLogicalParent(IList children) + { + var count = children.Count; + + for (var i = 0; i < count; i++) { - if (i.LogicalParent == null) + var logical = (ILogical) children[i]; + + if (logical.LogicalParent == this) { - ((ISetLogicalParent)i).SetParent(this); + ((ISetLogicalParent)logical).SetParent(null); } } } @@ -784,17 +803,6 @@ namespace Avalonia } } - private void ClearLogicalParent(IEnumerable children) - { - foreach (var i in children) - { - if (i.LogicalParent == this) - { - ((ISetLogicalParent)i).SetParent(null); - } - } - } - private void NotifyResourcesChanged( ResourcesChangedEventArgs? e = null, bool propagate = true) diff --git a/src/Avalonia.Themes.Default/CalendarDatePicker.xaml b/src/Avalonia.Themes.Default/CalendarDatePicker.xaml index bc1aba1a03..aab7d06c46 100644 --- a/src/Avalonia.Themes.Default/CalendarDatePicker.xaml +++ b/src/Avalonia.Themes.Default/CalendarDatePicker.xaml @@ -93,6 +93,8 @@ Watermark="{TemplateBinding Watermark}" UseFloatingWatermark="{TemplateBinding UseFloatingWatermark}" DataValidationErrors.Errors="{TemplateBinding (DataValidationErrors.Errors)}" + VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" + HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Grid.Column="0"/> + - - - + + + - + + @@ -228,6 +230,11 @@ + + + diff --git a/src/Avalonia.Themes.Fluent/ListBox.xaml b/src/Avalonia.Themes.Fluent/Controls/ListBox.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/ListBox.xaml rename to src/Avalonia.Themes.Fluent/Controls/ListBox.xaml diff --git a/src/Avalonia.Themes.Fluent/ListBoxItem.xaml b/src/Avalonia.Themes.Fluent/Controls/ListBoxItem.xaml similarity index 98% rename from src/Avalonia.Themes.Fluent/ListBoxItem.xaml rename to src/Avalonia.Themes.Fluent/Controls/ListBoxItem.xaml index 7715ddf1f1..627ffa2b19 100644 --- a/src/Avalonia.Themes.Fluent/ListBoxItem.xaml +++ b/src/Avalonia.Themes.Fluent/Controls/ListBoxItem.xaml @@ -17,7 +17,7 @@ diff --git a/src/Avalonia.Themes.Fluent/PopupRoot.xaml b/src/Avalonia.Themes.Fluent/Controls/PopupRoot.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/PopupRoot.xaml rename to src/Avalonia.Themes.Fluent/Controls/PopupRoot.xaml diff --git a/src/Avalonia.Themes.Fluent/ProgressBar.xaml b/src/Avalonia.Themes.Fluent/Controls/ProgressBar.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/ProgressBar.xaml rename to src/Avalonia.Themes.Fluent/Controls/ProgressBar.xaml diff --git a/src/Avalonia.Themes.Fluent/RadioButton.xaml b/src/Avalonia.Themes.Fluent/Controls/RadioButton.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/RadioButton.xaml rename to src/Avalonia.Themes.Fluent/Controls/RadioButton.xaml diff --git a/src/Avalonia.Themes.Fluent/RepeatButton.xaml b/src/Avalonia.Themes.Fluent/Controls/RepeatButton.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/RepeatButton.xaml rename to src/Avalonia.Themes.Fluent/Controls/RepeatButton.xaml diff --git a/src/Avalonia.Themes.Fluent/ScrollBar.xaml b/src/Avalonia.Themes.Fluent/Controls/ScrollBar.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/ScrollBar.xaml rename to src/Avalonia.Themes.Fluent/Controls/ScrollBar.xaml diff --git a/src/Avalonia.Themes.Fluent/ScrollViewer.xaml b/src/Avalonia.Themes.Fluent/Controls/ScrollViewer.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/ScrollViewer.xaml rename to src/Avalonia.Themes.Fluent/Controls/ScrollViewer.xaml diff --git a/src/Avalonia.Themes.Fluent/Separator.xaml b/src/Avalonia.Themes.Fluent/Controls/Separator.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/Separator.xaml rename to src/Avalonia.Themes.Fluent/Controls/Separator.xaml diff --git a/src/Avalonia.Themes.Fluent/Controls/Slider.xaml b/src/Avalonia.Themes.Fluent/Controls/Slider.xaml new file mode 100644 index 0000000000..d70eb1abe3 --- /dev/null +++ b/src/Avalonia.Themes.Fluent/Controls/Slider.xaml @@ -0,0 +1,275 @@ + + + + + + + + + + + + + + + + + 0,0,0,4 + 15 + 15 + 32 + 32 + 10 + 20 + 20 + 20 + 20 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Avalonia.Themes.Fluent/SplitView.xaml b/src/Avalonia.Themes.Fluent/Controls/SplitView.xaml similarity index 94% rename from src/Avalonia.Themes.Fluent/SplitView.xaml rename to src/Avalonia.Themes.Fluent/Controls/SplitView.xaml index 71e92459f1..7d6f7a9b9a 100644 --- a/src/Avalonia.Themes.Fluent/SplitView.xaml +++ b/src/Avalonia.Themes.Fluent/Controls/SplitView.xaml @@ -32,12 +32,12 @@ ClipToBounds="True" HorizontalAlignment="Left" ZIndex="100"> - + - + @@ -106,14 +106,14 @@ ClipToBounds="True" HorizontalAlignment="Right" ZIndex="100"> - + - + diff --git a/src/Avalonia.Themes.Fluent/TabControl.xaml b/src/Avalonia.Themes.Fluent/Controls/TabControl.xaml similarity index 96% rename from src/Avalonia.Themes.Fluent/TabControl.xaml rename to src/Avalonia.Themes.Fluent/Controls/TabControl.xaml index c38ecb0452..120b2986c3 100644 --- a/src/Avalonia.Themes.Fluent/TabControl.xaml +++ b/src/Avalonia.Themes.Fluent/Controls/TabControl.xaml @@ -60,6 +60,6 @@ diff --git a/src/Avalonia.Themes.Fluent/TabItem.xaml b/src/Avalonia.Themes.Fluent/Controls/TabItem.xaml similarity index 94% rename from src/Avalonia.Themes.Fluent/TabItem.xaml rename to src/Avalonia.Themes.Fluent/Controls/TabItem.xaml index 1c9574f169..508473796c 100644 --- a/src/Avalonia.Themes.Fluent/TabItem.xaml +++ b/src/Avalonia.Themes.Fluent/Controls/TabItem.xaml @@ -97,8 +97,8 @@ diff --git a/src/Avalonia.Themes.Fluent/TimePicker.xaml b/src/Avalonia.Themes.Fluent/Controls/TimePicker.xaml similarity index 67% rename from src/Avalonia.Themes.Fluent/TimePicker.xaml rename to src/Avalonia.Themes.Fluent/Controls/TimePicker.xaml index 84352213e1..1c52c6272c 100644 --- a/src/Avalonia.Themes.Fluent/TimePicker.xaml +++ b/src/Avalonia.Themes.Fluent/Controls/TimePicker.xaml @@ -41,94 +41,96 @@ - - + + + - + Width="{DynamicResource TimePickerSpacerThemeWidth}" + Grid.Column="3" /> + + + + + + - - - + + + - + + @@ -161,6 +163,10 @@ + + - - - - - - - - - - diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentDark.xaml b/src/Avalonia.Themes.Fluent/FluentDark.xaml similarity index 85% rename from src/Avalonia.Themes.Fluent/Accents/FluentDark.xaml rename to src/Avalonia.Themes.Fluent/FluentDark.xaml index 9ef92a44d5..74b583a240 100644 --- a/src/Avalonia.Themes.Fluent/Accents/FluentDark.xaml +++ b/src/Avalonia.Themes.Fluent/FluentDark.xaml @@ -5,5 +5,5 @@ - + diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentLight.xaml b/src/Avalonia.Themes.Fluent/FluentLight.xaml similarity index 85% rename from src/Avalonia.Themes.Fluent/Accents/FluentLight.xaml rename to src/Avalonia.Themes.Fluent/FluentLight.xaml index 8c92040122..1bc51f655e 100644 --- a/src/Avalonia.Themes.Fluent/Accents/FluentLight.xaml +++ b/src/Avalonia.Themes.Fluent/FluentLight.xaml @@ -5,5 +5,5 @@ - + diff --git a/src/Avalonia.Themes.Fluent/FluentTheme.cs b/src/Avalonia.Themes.Fluent/FluentTheme.cs new file mode 100644 index 0000000000..43b71567fa --- /dev/null +++ b/src/Avalonia.Themes.Fluent/FluentTheme.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; +using Avalonia.Styling; + +#nullable enable + +namespace Avalonia.Themes.Fluent +{ + public enum FluentThemeMode + { + Light, + Dark, + } + + /// + /// Includes the fluent theme in an application. + /// + public class FluentTheme : IStyle, IResourceProvider + { + private readonly Uri _baseUri; + private IStyle[]? _loaded; + private bool _isLoading; + + /// + /// Initializes a new instance of the class. + /// + /// The base URL for the XAML context. + public FluentTheme(Uri baseUri) + { + _baseUri = baseUri; + } + + /// + /// Initializes a new instance of the class. + /// + /// The XAML service provider. + public FluentTheme(IServiceProvider serviceProvider) + { + _baseUri = ((IUriContext)serviceProvider.GetService(typeof(IUriContext))).BaseUri; + } + + /// + /// Gets or sets the mode of the fluent theme (light, dark). + /// + public FluentThemeMode Mode { get; set; } + + public IResourceHost? Owner => (Loaded as IResourceProvider)?.Owner; + + /// + /// Gets the loaded style. + /// + public IStyle Loaded + { + get + { + if (_loaded == null) + { + _isLoading = true; + var loaded = (IStyle)AvaloniaXamlLoader.Load(GetUri(), _baseUri); + _loaded = new[] { loaded }; + _isLoading = false; + } + + return _loaded?[0]!; + } + } + + bool IResourceNode.HasResources => (Loaded as IResourceProvider)?.HasResources ?? false; + + IReadOnlyList IStyle.Children => _loaded ?? Array.Empty(); + + public event EventHandler OwnerChanged + { + add + { + if (Loaded is IResourceProvider rp) + { + rp.OwnerChanged += value; + } + } + remove + { + if (Loaded is IResourceProvider rp) + { + rp.OwnerChanged -= value; + } + } + } + + public SelectorMatchResult TryAttach(IStyleable target, IStyleHost? host) => Loaded.TryAttach(target, host); + + public bool TryGetResource(object key, out object? value) + { + if (!_isLoading && Loaded is IResourceProvider p) + { + return p.TryGetResource(key, out value); + } + + value = null; + return false; + } + + void IResourceProvider.AddOwner(IResourceHost owner) => (Loaded as IResourceProvider)?.AddOwner(owner); + void IResourceProvider.RemoveOwner(IResourceHost owner) => (Loaded as IResourceProvider)?.RemoveOwner(owner); + + private Uri GetUri() => Mode switch + { + FluentThemeMode.Dark => new Uri("avares://Avalonia.Themes.Fluent/FluentDark.xaml", UriKind.Absolute), + _ => new Uri("avares://Avalonia.Themes.Fluent/FluentLight.xaml", UriKind.Absolute), + }; + } +} diff --git a/src/Avalonia.Themes.Fluent/FluentTheme.xaml b/src/Avalonia.Themes.Fluent/FluentTheme.xaml deleted file mode 100644 index 90c0f55b68..0000000000 --- a/src/Avalonia.Themes.Fluent/FluentTheme.xaml +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Avalonia.Themes.Fluent/Properties/AssemblyInfo.cs b/src/Avalonia.Themes.Fluent/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..0bad226ba7 --- /dev/null +++ b/src/Avalonia.Themes.Fluent/Properties/AssemblyInfo.cs @@ -0,0 +1,3 @@ +using Avalonia.Metadata; + +[assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Themes.Fluent")] diff --git a/src/Avalonia.Themes.Fluent/Slider.xaml b/src/Avalonia.Themes.Fluent/Slider.xaml deleted file mode 100644 index 8abf78cc81..0000000000 --- a/src/Avalonia.Themes.Fluent/Slider.xaml +++ /dev/null @@ -1,263 +0,0 @@ - - - - - - - - - - - - - - - - - 0,0,0,4 - 15 - 15 - 32 - 32 - 10 - 20 - 20 - 20 - 20 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Avalonia.Visuals/ApiCompatBaseline.txt b/src/Avalonia.Visuals/ApiCompatBaseline.txt deleted file mode 100644 index 7fb44152c9..0000000000 --- a/src/Avalonia.Visuals/ApiCompatBaseline.txt +++ /dev/null @@ -1,37 +0,0 @@ -Compat issues with assembly Avalonia.Visuals: -MembersMustExist : Member 'public void Avalonia.Media.DrawingContext.DrawGlyphRun(Avalonia.Media.IBrush, Avalonia.Media.GlyphRun, Avalonia.Point)' does not exist in the implementation but it does exist in the contract. -MembersMustExist : Member 'public Avalonia.Media.Typeface Avalonia.Media.FontManager.GetOrAddTypeface(Avalonia.Media.FontFamily, Avalonia.Media.FontStyle, Avalonia.Media.FontWeight)' does not exist in the implementation but it does exist in the contract. -MembersMustExist : Member 'public Avalonia.Media.Typeface Avalonia.Media.FontManager.MatchCharacter(System.Int32, Avalonia.Media.FontStyle, Avalonia.Media.FontWeight, Avalonia.Media.FontFamily, System.Globalization.CultureInfo)' does not exist in the implementation but it does exist in the contract. -MembersMustExist : Member 'public Avalonia.Rect Avalonia.Media.GlyphRun.Bounds.get()' does not exist in the implementation but it does exist in the contract. -MembersMustExist : Member 'public Avalonia.StyledProperty Avalonia.StyledProperty Avalonia.Media.GlyphRunDrawing.BaselineOriginProperty' does not exist in the implementation but it does exist in the contract. -MembersMustExist : Member 'public Avalonia.Point Avalonia.Media.GlyphRunDrawing.BaselineOrigin.get()' does not exist in the implementation but it does exist in the contract. -MembersMustExist : Member 'public void Avalonia.Media.GlyphRunDrawing.BaselineOrigin.set(Avalonia.Point)' does not exist in the implementation but it does exist in the contract. -CannotSealType : Type 'Avalonia.Media.Typeface' is actually (has the sealed modifier) sealed in the implementation but not sealed in the contract. -TypeCannotChangeClassification : Type 'Avalonia.Media.Typeface' is a 'struct' in the implementation but is a 'class' in the contract. -CannotMakeMemberNonVirtual : Member 'public System.Boolean Avalonia.Media.Typeface.Equals(System.Object)' is non-virtual in the implementation but is virtual in the contract. -CannotMakeMemberNonVirtual : Member 'public System.Int32 Avalonia.Media.Typeface.GetHashCode()' is non-virtual in the implementation but is virtual in the contract. -TypesMustExist : Type 'Avalonia.Media.Fonts.FontKey' does not exist in the implementation but it does exist in the contract. -CannotAddAbstractMembers : Member 'public Avalonia.Size Avalonia.Media.TextFormatting.DrawableTextRun.Size' is abstract in the implementation but is missing in the contract. -MembersMustExist : Member 'public Avalonia.Rect Avalonia.Media.TextFormatting.DrawableTextRun.Bounds.get()' does not exist in the implementation but it does exist in the contract. -CannotAddAbstractMembers : Member 'public void Avalonia.Media.TextFormatting.DrawableTextRun.Draw(Avalonia.Media.DrawingContext)' is abstract in the implementation but is missing in the contract. -MembersMustExist : Member 'public void Avalonia.Media.TextFormatting.DrawableTextRun.Draw(Avalonia.Media.DrawingContext, Avalonia.Point)' does not exist in the implementation but it does exist in the contract. -CannotAddAbstractMembers : Member 'public Avalonia.Size Avalonia.Media.TextFormatting.DrawableTextRun.Size.get()' is abstract in the implementation but is missing in the contract. -MembersMustExist : Member 'public Avalonia.Rect Avalonia.Media.TextFormatting.ShapedTextCharacters.Bounds.get()' does not exist in the implementation but it does exist in the contract. -MembersMustExist : Member 'public void Avalonia.Media.TextFormatting.ShapedTextCharacters.Draw(Avalonia.Media.DrawingContext, Avalonia.Point)' does not exist in the implementation but it does exist in the contract. -MembersMustExist : Member 'public void Avalonia.Media.TextFormatting.TextLayout.Draw(Avalonia.Media.DrawingContext, Avalonia.Point)' does not exist in the implementation but it does exist in the contract. -CannotAddAbstractMembers : Member 'public Avalonia.Media.TextFormatting.TextLineBreak Avalonia.Media.TextFormatting.TextLine.TextLineBreak' is abstract in the implementation but is missing in the contract. -CannotAddAbstractMembers : Member 'public void Avalonia.Media.TextFormatting.TextLine.Draw(Avalonia.Media.DrawingContext)' is abstract in the implementation but is missing in the contract. -MembersMustExist : Member 'public void Avalonia.Media.TextFormatting.TextLine.Draw(Avalonia.Media.DrawingContext, Avalonia.Point)' does not exist in the implementation but it does exist in the contract. -MembersMustExist : Member 'public Avalonia.Media.TextFormatting.TextLineBreak Avalonia.Media.TextFormatting.TextLine.LineBreak.get()' does not exist in the implementation but it does exist in the contract. -CannotAddAbstractMembers : Member 'public Avalonia.Media.TextFormatting.TextLineBreak Avalonia.Media.TextFormatting.TextLine.TextLineBreak.get()' is abstract in the implementation but is missing in the contract. -InterfacesShouldHaveSameMembers : Interface member 'public Avalonia.Platform.IDrawingContextLayerImpl Avalonia.Platform.IDrawingContextImpl.CreateLayer(Avalonia.Size)' is present in the implementation but not in the contract. -InterfacesShouldHaveSameMembers : Interface member 'public Avalonia.Platform.IRenderTargetBitmapImpl Avalonia.Platform.IDrawingContextImpl.CreateLayer(Avalonia.Size)' is present in the contract but not in the implementation. -MembersMustExist : Member 'public Avalonia.Platform.IRenderTargetBitmapImpl Avalonia.Platform.IDrawingContextImpl.CreateLayer(Avalonia.Size)' does not exist in the implementation but it does exist in the contract. -InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Platform.IDrawingContextImpl.DrawGlyphRun(Avalonia.Media.IBrush, Avalonia.Media.GlyphRun)' is present in the implementation but not in the contract. -InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Platform.IDrawingContextImpl.DrawGlyphRun(Avalonia.Media.IBrush, Avalonia.Media.GlyphRun, Avalonia.Point)' is present in the contract but not in the implementation. -MembersMustExist : Member 'public void Avalonia.Platform.IDrawingContextImpl.DrawGlyphRun(Avalonia.Media.IBrush, Avalonia.Media.GlyphRun, Avalonia.Point)' does not exist in the implementation but it does exist in the contract. -InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalonia.Platform.IFontManagerImpl.TryMatchCharacter(System.Int32, Avalonia.Media.FontStyle, Avalonia.Media.FontWeight, Avalonia.Media.FontFamily, System.Globalization.CultureInfo, Avalonia.Media.Fonts.FontKey)' is present in the contract but not in the implementation. -MembersMustExist : Member 'public System.Boolean Avalonia.Platform.IFontManagerImpl.TryMatchCharacter(System.Int32, Avalonia.Media.FontStyle, Avalonia.Media.FontWeight, Avalonia.Media.FontFamily, System.Globalization.CultureInfo, Avalonia.Media.Fonts.FontKey)' does not exist in the implementation but it does exist in the contract. -InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalonia.Platform.IFontManagerImpl.TryMatchCharacter(System.Int32, Avalonia.Media.FontStyle, Avalonia.Media.FontWeight, Avalonia.Media.FontFamily, System.Globalization.CultureInfo, Avalonia.Media.Typeface)' is present in the implementation but not in the contract. -MembersMustExist : Member 'public Avalonia.Utilities.IRef Avalonia.Rendering.RenderLayer.Bitmap.get()' does not exist in the implementation but it does exist in the contract. -Total Issues: 35 diff --git a/src/Avalonia.Visuals/CornerRadius.cs b/src/Avalonia.Visuals/CornerRadius.cs index c02aacfb4d..037bb16e31 100644 --- a/src/Avalonia.Visuals/CornerRadius.cs +++ b/src/Avalonia.Visuals/CornerRadius.cs @@ -1,6 +1,8 @@ using System; using System.Globalization; +#if !BUILDTASK using Avalonia.Animation.Animators; +#endif using Avalonia.Utilities; namespace Avalonia @@ -8,11 +10,16 @@ namespace Avalonia /// /// Represents the radii of a rectangle's corners. /// - public readonly struct CornerRadius : IEquatable +#if !BUILDTASK + public +#endif + readonly struct CornerRadius : IEquatable { static CornerRadius() { +#if !BUILDTASK Animation.Animation.RegisterAnimator(prop => typeof(CornerRadius).IsAssignableFrom(prop.PropertyType)); +#endif } public CornerRadius(double uniformRadius) diff --git a/src/Avalonia.Visuals/Matrix.cs b/src/Avalonia.Visuals/Matrix.cs index 206b842220..8136f843df 100644 --- a/src/Avalonia.Visuals/Matrix.cs +++ b/src/Avalonia.Visuals/Matrix.cs @@ -7,7 +7,10 @@ namespace Avalonia /// /// A 2x3 matrix. /// - public readonly struct Matrix : IEquatable +#if !BUILDTASK + public +#endif + readonly struct Matrix : IEquatable { private readonly double _m11; private readonly double _m12; @@ -279,25 +282,44 @@ namespace Avalonia } /// - /// Inverts the Matrix. + /// Attempts to invert the Matrix. /// - /// The inverted matrix. - public Matrix Invert() + /// The inverted matrix or when matrix is not invertible. + public bool TryInvert(out Matrix inverted) { double d = GetDeterminant(); if (MathUtilities.IsZero(d)) { - throw new InvalidOperationException("Transform is not invertible."); + inverted = default; + + return false; } - return new Matrix( + inverted = new Matrix( _m22 / d, -_m12 / d, -_m21 / d, _m11 / d, ((_m21 * _m32) - (_m22 * _m31)) / d, ((_m12 * _m31) - (_m11 * _m32)) / d); + + return true; + } + + /// + /// Inverts the Matrix. + /// + /// Matrix is not invertible. + /// The inverted matrix. + public Matrix Invert() + { + if (!TryInvert(out Matrix inverted)) + { + throw new InvalidOperationException("Transform is not invertible."); + } + + return inverted; } /// diff --git a/src/Avalonia.Visuals/Media/Color.cs b/src/Avalonia.Visuals/Media/Color.cs index 16b4f90d57..a57a962db4 100644 --- a/src/Avalonia.Visuals/Media/Color.cs +++ b/src/Avalonia.Visuals/Media/Color.cs @@ -1,17 +1,24 @@ using System; using System.Globalization; +#if !BUILDTASK using Avalonia.Animation.Animators; +#endif namespace Avalonia.Media { /// /// An ARGB color. /// - public readonly struct Color : IEquatable +#if !BUILDTASK + public +#endif + readonly struct Color : IEquatable { static Color() { +#if !BUILDTASK Animation.Animation.RegisterAnimator(prop => typeof(Color).IsAssignableFrom(prop.PropertyType)); +#endif } /// @@ -223,7 +230,12 @@ namespace Avalonia.Media if (input.Length == 3 || input.Length == 4) { var extendedLength = 2 * input.Length; + +#if !BUILDTASK Span extended = stackalloc char[extendedLength]; +#else + char[] extended = new char[extendedLength]; +#endif for (int i = 0; i < input.Length; i++) { diff --git a/src/Avalonia.Visuals/Media/ConicGradientBrush.cs b/src/Avalonia.Visuals/Media/ConicGradientBrush.cs new file mode 100644 index 0000000000..7c1266fa17 --- /dev/null +++ b/src/Avalonia.Visuals/Media/ConicGradientBrush.cs @@ -0,0 +1,55 @@ +using Avalonia.Media.Immutable; + +namespace Avalonia.Media +{ + /// + /// Paints an area with a swept circular gradient. + /// + public sealed class ConicGradientBrush : GradientBrush, IConicGradientBrush + { + /// + /// Defines the property. + /// + public static readonly StyledProperty CenterProperty = + AvaloniaProperty.Register( + nameof(Center), + RelativePoint.Center); + + /// + /// Defines the property. + /// + public static readonly StyledProperty AngleProperty = + AvaloniaProperty.Register( + nameof(Angle), + 0); + + static ConicGradientBrush() + { + AffectsRender(CenterProperty, AngleProperty); + } + + /// + /// Gets or sets the center point of the gradient. + /// + public RelativePoint Center + { + get { return GetValue(CenterProperty); } + set { SetValue(CenterProperty, value); } + } + + /// + /// Gets or sets the angle of the start and end of the sweep, measured from above the center point. + /// + public double Angle + { + get { return GetValue(AngleProperty); } + set { SetValue(AngleProperty, value); } + } + + /// + public override IBrush ToImmutable() + { + return new ImmutableConicGradientBrush(this); + } + } +} diff --git a/src/Avalonia.Visuals/Media/DashStyle.cs b/src/Avalonia.Visuals/Media/DashStyle.cs index 1e813edc13..acba2d3615 100644 --- a/src/Avalonia.Visuals/Media/DashStyle.cs +++ b/src/Avalonia.Visuals/Media/DashStyle.cs @@ -1,11 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using Avalonia.Animation; +using Avalonia.Collections; +using Avalonia.Media.Immutable; + +#nullable enable + namespace Avalonia.Media { - using System; - using System.Collections.Generic; - using System.Linq; - using Avalonia.Animation; - using Avalonia.Media.Immutable; - /// /// Represents the sequence of dashes and gaps that will be applied by a . /// @@ -14,8 +17,8 @@ namespace Avalonia.Media /// /// Defines the property. /// - public static readonly StyledProperty> DashesProperty = - AvaloniaProperty.Register>(nameof(Dashes)); + public static readonly StyledProperty> DashesProperty = + AvaloniaProperty.Register>(nameof(Dashes)); /// /// Defines the property. @@ -23,10 +26,10 @@ namespace Avalonia.Media public static readonly StyledProperty OffsetProperty = AvaloniaProperty.Register(nameof(Offset)); - private static ImmutableDashStyle s_dash; - private static ImmutableDashStyle s_dot; - private static ImmutableDashStyle s_dashDot; - private static ImmutableDashStyle s_dashDotDot; + private static ImmutableDashStyle? s_dash; + private static ImmutableDashStyle? s_dot; + private static ImmutableDashStyle? s_dashDot; + private static ImmutableDashStyle? s_dashDotDot; /// /// Initializes a new instance of the class. @@ -41,9 +44,9 @@ namespace Avalonia.Media /// /// The dashes collection. /// The dash sequence offset. - public DashStyle(IEnumerable dashes, double offset) + public DashStyle(IEnumerable? dashes, double offset) { - Dashes = (IReadOnlyList)dashes?.ToList() ?? Array.Empty(); + Dashes = (dashes as AvaloniaList) ?? new AvaloniaList(dashes ?? Array.Empty()); Offset = offset; } @@ -61,31 +64,27 @@ namespace Avalonia.Media /// /// Represents a dashed . /// - public static IDashStyle Dash => - s_dash ?? (s_dash = new ImmutableDashStyle(new double[] { 2, 2 }, 1)); + public static IDashStyle Dash => s_dash ??= new ImmutableDashStyle(new double[] { 2, 2 }, 1); /// /// Represents a dotted . /// - public static IDashStyle Dot => - s_dot ?? (s_dot = new ImmutableDashStyle(new double[] { 0, 2 }, 0)); + public static IDashStyle Dot => s_dot ??= new ImmutableDashStyle(new double[] { 0, 2 }, 0); /// /// Represents a dashed dotted . /// - public static IDashStyle DashDot => - s_dashDot ?? (s_dashDot = new ImmutableDashStyle(new double[] { 2, 2, 0, 2 }, 1)); + public static IDashStyle DashDot => s_dashDot ??= new ImmutableDashStyle(new double[] { 2, 2, 0, 2 }, 1); /// /// Represents a dashed double dotted . /// - public static IDashStyle DashDotDot => - s_dashDotDot ?? (s_dashDotDot = new ImmutableDashStyle(new double[] { 2, 2, 0, 2, 0, 2 }, 1)); + public static IDashStyle DashDotDot => s_dashDotDot ??= new ImmutableDashStyle(new double[] { 2, 2, 0, 2, 0, 2 }, 1); /// /// Gets or sets the length of alternating dashes and gaps. /// - public IReadOnlyList Dashes + public AvaloniaList Dashes { get => GetValue(DashesProperty); set => SetValue(DashesProperty, value); @@ -100,15 +99,43 @@ namespace Avalonia.Media set => SetValue(OffsetProperty, value); } + IReadOnlyList IDashStyle.Dashes => Dashes; + /// /// Raised when the dash style changes. /// - public event EventHandler Invalidated; + public event EventHandler? Invalidated; /// /// Returns an immutable clone of the . /// /// public ImmutableDashStyle ToImmutable() => new ImmutableDashStyle(Dashes, Offset); + + protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) + { + base.OnPropertyChanged(change); + + if (change.Property == DashesProperty) + { + var oldValue = change.OldValue.GetValueOrDefault>(); + var newValue = change.NewValue.GetValueOrDefault>(); + + if (oldValue is object) + { + oldValue.CollectionChanged -= DashesChanged; + } + + if (newValue is object) + { + newValue.CollectionChanged += DashesChanged; + } + } + } + + private void DashesChanged(object sender, NotifyCollectionChangedEventArgs e) + { + Invalidated?.Invoke(this, e); + } } } diff --git a/src/Avalonia.Visuals/Media/Drawing.cs b/src/Avalonia.Visuals/Media/Drawing.cs index 6bc808e407..66d05e7e48 100644 --- a/src/Avalonia.Visuals/Media/Drawing.cs +++ b/src/Avalonia.Visuals/Media/Drawing.cs @@ -1,11 +1,19 @@ -using Avalonia.Platform; - -namespace Avalonia.Media +namespace Avalonia.Media { + /// + /// Abstract class that describes a 2-D drawing. + /// public abstract class Drawing : AvaloniaObject { + /// + /// Draws this drawing to the given . + /// + /// The drawing context. public abstract void Draw(DrawingContext context); + /// + /// Gets the drawing's bounding rectangle. + /// public abstract Rect GetBounds(); } } diff --git a/src/Avalonia.Visuals/Media/EllipseGeometry.cs b/src/Avalonia.Visuals/Media/EllipseGeometry.cs index fd73eee69a..bae6dc3d8c 100644 --- a/src/Avalonia.Visuals/Media/EllipseGeometry.cs +++ b/src/Avalonia.Visuals/Media/EllipseGeometry.cs @@ -12,10 +12,28 @@ namespace Avalonia.Media /// public static readonly StyledProperty RectProperty = AvaloniaProperty.Register(nameof(Rect)); + + /// + /// Defines the property. + /// + public static readonly StyledProperty RadiusXProperty = + AvaloniaProperty.Register(nameof(RadiusX)); + + /// + /// Defines the property. + /// + public static readonly StyledProperty RadiusYProperty = + AvaloniaProperty.Register(nameof(RadiusY)); + + /// + /// Defines the property. + /// + public static readonly StyledProperty CenterProperty = + AvaloniaProperty.Register(nameof(Center)); static EllipseGeometry() { - AffectsGeometry(RectProperty); + AffectsGeometry(RectProperty, RadiusXProperty, RadiusYProperty, CenterProperty); } /// @@ -43,6 +61,33 @@ namespace Avalonia.Media set => SetValue(RectProperty, value); } + /// + /// Gets or sets a double that defines the radius in the X-axis of the ellipse. + /// + public double RadiusX + { + get => GetValue(RadiusXProperty); + set => SetValue(RadiusXProperty, value); + } + + /// + /// Gets or sets a double that defines the radius in the Y-axis of the ellipse. + /// + public double RadiusY + { + get => GetValue(RadiusYProperty); + set => SetValue(RadiusYProperty, value); + } + + /// + /// Gets or sets a point that defines the center of the ellipse. + /// + public Point Center + { + get => GetValue(CenterProperty); + set => SetValue(CenterProperty, value); + } + /// public override Geometry Clone() { @@ -54,7 +99,14 @@ namespace Avalonia.Media { var factory = AvaloniaLocator.Current.GetService(); - return factory.CreateEllipseGeometry(Rect); + if (Rect != default) return factory.CreateEllipseGeometry(Rect); + + var originX = Center.X - RadiusX; + var originY = Center.Y - RadiusY; + var width = RadiusX * 2; + var height = RadiusY * 2; + + return factory.CreateEllipseGeometry(new Rect(originX, originY, width, height)); } } } diff --git a/src/Avalonia.Visuals/Media/FontFamily.cs b/src/Avalonia.Visuals/Media/FontFamily.cs index 9db49200cd..f018733235 100644 --- a/src/Avalonia.Visuals/Media/FontFamily.cs +++ b/src/Avalonia.Visuals/Media/FontFamily.cs @@ -133,6 +133,16 @@ namespace Avalonia.Media } } + /// + /// Parses a string. + /// + /// The string. + /// + /// + /// Specified family is not supported. + /// + public static FontFamily Parse(string s) => Parse(s, null); + /// /// Parses a string. /// @@ -142,7 +152,7 @@ namespace Avalonia.Media /// /// Specified family is not supported. /// - public static FontFamily Parse(string s, Uri baseUri = null) + public static FontFamily Parse(string s, Uri baseUri) { if (string.IsNullOrEmpty(s)) { diff --git a/src/Avalonia.Visuals/Media/Geometry.cs b/src/Avalonia.Visuals/Media/Geometry.cs index 33aafb58fc..ccef6665a9 100644 --- a/src/Avalonia.Visuals/Media/Geometry.cs +++ b/src/Avalonia.Visuals/Media/Geometry.cs @@ -84,7 +84,7 @@ namespace Avalonia.Media /// /// The stroke thickness. /// The bounding rectangle. - public Rect GetRenderBounds(Pen pen) => PlatformImpl?.GetRenderBounds(pen) ?? Rect.Empty; + public Rect GetRenderBounds(IPen pen) => PlatformImpl?.GetRenderBounds(pen) ?? Rect.Empty; /// /// Indicates whether the geometry's fill contains the specified point. @@ -102,7 +102,7 @@ namespace Avalonia.Media /// The pen to use. /// The point. /// true if the geometry contains the point; otherwise, false. - public bool StrokeContains(Pen pen, Point point) + public bool StrokeContains(IPen pen, Point point) { return PlatformImpl?.StrokeContains(pen, point) == true; } diff --git a/src/Avalonia.Visuals/Media/GeometryDrawing.cs b/src/Avalonia.Visuals/Media/GeometryDrawing.cs index 4df3aa8ae2..e46e3a7d5f 100644 --- a/src/Avalonia.Visuals/Media/GeometryDrawing.cs +++ b/src/Avalonia.Visuals/Media/GeometryDrawing.cs @@ -1,12 +1,38 @@ -using Avalonia.Metadata; +using Avalonia.Media.Immutable; +using Avalonia.Metadata; namespace Avalonia.Media { + /// + /// Represents a drawing operation that combines + /// a geometry with and brush and/or pen to produce rendered content. + /// public class GeometryDrawing : Drawing { + // Adding the Pen's stroke thickness here could yield wrong results due to transforms. + private static readonly IPen s_boundsPen = new ImmutablePen(Colors.Black.ToUint32(), 0); + + /// + /// Defines the property. + /// public static readonly StyledProperty GeometryProperty = AvaloniaProperty.Register(nameof(Geometry)); + /// + /// Defines the property. + /// + public static readonly StyledProperty BrushProperty = + AvaloniaProperty.Register(nameof(Brush), Brushes.Transparent); + + /// + /// Defines the property. + /// + public static readonly StyledProperty PenProperty = + AvaloniaProperty.Register(nameof(Pen)); + + /// + /// Gets or sets the that describes the shape of this . + /// [Content] public Geometry Geometry { @@ -14,18 +40,18 @@ namespace Avalonia.Media set => SetValue(GeometryProperty, value); } - public static readonly StyledProperty BrushProperty = - AvaloniaProperty.Register(nameof(Brush), Brushes.Transparent); - + /// + /// Gets or sets the used to fill the interior of the shape described by this . + /// public IBrush Brush { get => GetValue(BrushProperty); set => SetValue(BrushProperty, value); } - public static readonly StyledProperty PenProperty = - AvaloniaProperty.Register(nameof(Pen)); - + /// + /// Gets or sets the used to stroke this . + /// public IPen Pen { get => GetValue(PenProperty); @@ -42,9 +68,7 @@ namespace Avalonia.Media public override Rect GetBounds() { - // adding the Pen's stroke thickness here could yield wrong results due to transforms - var pen = new Pen(Brushes.Black, 0); - return Geometry?.GetRenderBounds(pen) ?? new Rect(); + return Geometry?.GetRenderBounds(s_boundsPen) ?? Rect.Empty; } } } diff --git a/src/Avalonia.Visuals/Media/IConicGradientBrush.cs b/src/Avalonia.Visuals/Media/IConicGradientBrush.cs new file mode 100644 index 0000000000..5368dd1851 --- /dev/null +++ b/src/Avalonia.Visuals/Media/IConicGradientBrush.cs @@ -0,0 +1,19 @@ +namespace Avalonia.Media +{ + /// + /// Paints an area with a conic gradient. + /// + public interface IConicGradientBrush : IGradientBrush + { + /// + /// Gets the center point for the gradient. + /// + RelativePoint Center { get; } + + /// + /// Gets the starting angle for the gradient in degrees, measured from + /// the point above the center point. + /// + double Angle { get; } + } +} diff --git a/src/Avalonia.Visuals/Media/Immutable/ImmutableConicGradientBrush.cs b/src/Avalonia.Visuals/Media/Immutable/ImmutableConicGradientBrush.cs new file mode 100644 index 0000000000..d3c80dfcad --- /dev/null +++ b/src/Avalonia.Visuals/Media/Immutable/ImmutableConicGradientBrush.cs @@ -0,0 +1,47 @@ +using System.Collections.Generic; + +namespace Avalonia.Media.Immutable +{ + /// + /// A brush that draws with a sweep gradient. + /// + public class ImmutableConicGradientBrush : ImmutableGradientBrush, IConicGradientBrush + { + /// + /// Initializes a new instance of the class. + /// + /// The gradient stops. + /// The opacity of the brush. + /// The spread method. + /// The center point for the gradient. + /// The starting angle for the gradient. + public ImmutableConicGradientBrush( + IReadOnlyList gradientStops, + double opacity = 1, + GradientSpreadMethod spreadMethod = GradientSpreadMethod.Pad, + RelativePoint? center = null, + double angle = 0) + : base(gradientStops, opacity, spreadMethod) + { + Center = center ?? RelativePoint.Center; + Angle = angle; + } + + /// + /// Initializes a new instance of the class. + /// + /// The brush from which this brush's properties should be copied. + public ImmutableConicGradientBrush(ConicGradientBrush source) + : base(source) + { + Center = source.Center; + Angle = source.Angle; + } + + /// + public RelativePoint Center { get; } + + /// + public double Angle { get; } + } +} diff --git a/src/Avalonia.Visuals/Media/KnownColors.cs b/src/Avalonia.Visuals/Media/KnownColors.cs index 0887d2c913..fe09f5f538 100644 --- a/src/Avalonia.Visuals/Media/KnownColors.cs +++ b/src/Avalonia.Visuals/Media/KnownColors.cs @@ -8,7 +8,9 @@ namespace Avalonia.Media { private static readonly IReadOnlyDictionary _knownColorNames; private static readonly IReadOnlyDictionary _knownColors; +#if !BUILDTASK private static readonly Dictionary _knownBrushes; +#endif static KnownColors() { @@ -32,14 +34,19 @@ namespace Avalonia.Media _knownColorNames = knownColorNames; _knownColors = knownColors; + +#if !BUILDTASK _knownBrushes = new Dictionary(); +#endif } +#if !BUILDTASK public static ISolidColorBrush GetKnownBrush(string s) { var color = GetKnownColor(s); return color != KnownColor.None ? color.ToBrush() : null; } +#endif public static KnownColor GetKnownColor(string s) { @@ -61,6 +68,7 @@ namespace Avalonia.Media return Color.FromUInt32((uint)color); } +#if !BUILDTASK public static ISolidColorBrush ToBrush(this KnownColor color) { lock (_knownBrushes) @@ -74,6 +82,7 @@ namespace Avalonia.Media return brush; } } +#endif } internal enum KnownColor : uint diff --git a/src/Avalonia.Visuals/Media/PathFigure.cs b/src/Avalonia.Visuals/Media/PathFigure.cs index d0eb67ba39..caf86cb234 100644 --- a/src/Avalonia.Visuals/Media/PathFigure.cs +++ b/src/Avalonia.Visuals/Media/PathFigure.cs @@ -1,3 +1,7 @@ +#nullable enable +using System; +using System.Linq; +using Avalonia.Collections; using Avalonia.Metadata; namespace Avalonia.Media @@ -8,22 +12,36 @@ namespace Avalonia.Media /// Defines the property. /// public static readonly StyledProperty IsClosedProperty - = AvaloniaProperty.Register(nameof(IsClosed), true); + = AvaloniaProperty.Register(nameof(IsClosed), true); + /// /// Defines the property. /// public static readonly StyledProperty IsFilledProperty - = AvaloniaProperty.Register(nameof(IsFilled), true); + = AvaloniaProperty.Register(nameof(IsFilled), true); + /// /// Defines the property. /// - public static readonly DirectProperty SegmentsProperty - = AvaloniaProperty.RegisterDirect(nameof(Segments), f => f.Segments, (f, s) => f.Segments = s); + public static readonly DirectProperty SegmentsProperty + = AvaloniaProperty.RegisterDirect( + nameof(Segments), + f => f.Segments, + (f, s) => f.Segments = s); + /// /// Defines the property. /// public static readonly StyledProperty StartPointProperty - = AvaloniaProperty.Register(nameof(StartPoint)); + = AvaloniaProperty.Register(nameof(StartPoint)); + + internal event EventHandler? SegmentsInvalidated; + + private PathSegments? _segments; + + private IDisposable? _segmentsDisposable; + + private IDisposable? _segmentsPropertiesDisposable; /// /// Initializes a new instance of the class. @@ -33,6 +51,31 @@ namespace Avalonia.Media Segments = new PathSegments(); } + static PathFigure() + { + SegmentsProperty.Changed.AddClassHandler( + (s, e) => + s.OnSegmentsChanged()); + } + + private void OnSegmentsChanged() + { + _segmentsDisposable?.Dispose(); + _segmentsPropertiesDisposable?.Dispose(); + + _segmentsDisposable = _segments?.ForEachItem( + _ => InvalidateSegments(), + _ => InvalidateSegments(), + InvalidateSegments); + + _segmentsPropertiesDisposable = _segments?.TrackItemPropertyChanged(_ => InvalidateSegments()); + } + + private void InvalidateSegments() + { + SegmentsInvalidated?.Invoke(this, EventArgs.Empty); + } + /// /// Gets or sets a value indicating whether this instance is closed. /// @@ -64,7 +107,7 @@ namespace Avalonia.Media /// The segments. /// [Content] - public PathSegments Segments + public PathSegments? Segments { get { return _segments; } set { SetAndRaise(SegmentsProperty, ref _segments, value); } @@ -81,22 +124,23 @@ namespace Avalonia.Media get { return GetValue(StartPointProperty); } set { SetValue(StartPointProperty, value); } } + + public override string ToString() + => $"M {StartPoint} {string.Join(" ", _segments ?? Enumerable.Empty())}{(IsClosed ? "Z" : "")}"; internal void ApplyTo(StreamGeometryContext ctx) { ctx.BeginFigure(StartPoint, IsFilled); - foreach (var segment in Segments) + if (Segments != null) { - segment.ApplyTo(ctx); + foreach (var segment in Segments) + { + segment.ApplyTo(ctx); + } } ctx.EndFigure(IsClosed); } - - private PathSegments _segments; - - public override string ToString() - => $"M {StartPoint} {string.Join(" ", _segments)}{(IsClosed ? "Z" : "")}"; } -} \ No newline at end of file +} diff --git a/src/Avalonia.Visuals/Media/PathGeometry.cs b/src/Avalonia.Visuals/Media/PathGeometry.cs index fbc29aedc8..3d11c19b7d 100644 --- a/src/Avalonia.Visuals/Media/PathGeometry.cs +++ b/src/Avalonia.Visuals/Media/PathGeometry.cs @@ -104,12 +104,26 @@ namespace Avalonia.Media _figuresPropertiesObserver?.Dispose(); _figuresObserver = figures?.ForEachItem( - _ => InvalidateGeometry(), - _ => InvalidateGeometry(), - () => InvalidateGeometry()); + s => + { + s.SegmentsInvalidated += InvalidateGeometryFromSegments; + InvalidateGeometry(); + }, + s => + { + s.SegmentsInvalidated -= InvalidateGeometryFromSegments; + InvalidateGeometry(); + }, + InvalidateGeometry); + _figuresPropertiesObserver = figures?.TrackItemPropertyChanged(_ => InvalidateGeometry()); + } + private void InvalidateGeometryFromSegments(object _, EventArgs __) + { + InvalidateGeometry(); + } public override string ToString() => $"{(FillRule != FillRule.EvenOdd ? "F1 " : "")}{(string.Join(" ", Figures))}"; diff --git a/src/Avalonia.Visuals/Media/TextDecoration.cs b/src/Avalonia.Visuals/Media/TextDecoration.cs index d9b3f664ce..57936426f3 100644 --- a/src/Avalonia.Visuals/Media/TextDecoration.cs +++ b/src/Avalonia.Visuals/Media/TextDecoration.cs @@ -189,11 +189,11 @@ namespace Avalonia.Media break; case TextDecorationLocation.Strikethrough: origin += new Point(shapedTextCharacters.GlyphRun.BaselineOrigin.X, - shapedTextCharacters.GlyphRun.BaselineOrigin.Y - fontMetrics.StrikethroughPosition); + shapedTextCharacters.GlyphRun.BaselineOrigin.Y + fontMetrics.StrikethroughPosition); break; case TextDecorationLocation.Underline: origin += new Point(shapedTextCharacters.GlyphRun.BaselineOrigin.X, - shapedTextCharacters.GlyphRun.BaselineOrigin.Y - fontMetrics.UnderlinePosition); + shapedTextCharacters.GlyphRun.BaselineOrigin.Y + fontMetrics.UnderlinePosition); break; } diff --git a/src/Avalonia.Visuals/Point.cs b/src/Avalonia.Visuals/Point.cs index 7324f5fbd0..6febe9c802 100644 --- a/src/Avalonia.Visuals/Point.cs +++ b/src/Avalonia.Visuals/Point.cs @@ -1,6 +1,8 @@ using System; using System.Globalization; +#if !BUILDTASK using Avalonia.Animation.Animators; +#endif using Avalonia.Utilities; namespace Avalonia @@ -8,11 +10,16 @@ namespace Avalonia /// /// Defines a point. /// - public readonly struct Point : IEquatable +#if !BUILDTASK + public +#endif + readonly struct Point : IEquatable { static Point() { +#if !BUILDTASK Animation.Animation.RegisterAnimator(prop => typeof(Point).IsAssignableFrom(prop.PropertyType)); +#endif } /// diff --git a/src/Avalonia.Visuals/Properties/AssemblyInfo.cs b/src/Avalonia.Visuals/Properties/AssemblyInfo.cs index 5bb9ae78b0..48107a31f8 100644 --- a/src/Avalonia.Visuals/Properties/AssemblyInfo.cs +++ b/src/Avalonia.Visuals/Properties/AssemblyInfo.cs @@ -2,13 +2,20 @@ using System.Reflection; using System.Runtime.CompilerServices; using Avalonia.Metadata; -[assembly: InternalsVisibleTo("Avalonia.Visuals.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Animation")] [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Media")] [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Media.Imaging")] [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Media.Transformation")] [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia")] +#if SIGNED_BUILD +[assembly: InternalsVisibleTo("Avalonia.Visuals.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] [assembly: InternalsVisibleTo("Avalonia.Direct2D1.RenderTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] [assembly: InternalsVisibleTo("Avalonia.Skia.RenderTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] [assembly: InternalsVisibleTo("Avalonia.Skia.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] +#else +[assembly: InternalsVisibleTo("Avalonia.Visuals.UnitTests")] +[assembly: InternalsVisibleTo("Avalonia.Direct2D1.RenderTests")] +[assembly: InternalsVisibleTo("Avalonia.Skia.RenderTests")] +[assembly: InternalsVisibleTo("Avalonia.Skia.UnitTests")] +#endif diff --git a/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs b/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs index 15e14935ca..3bd8e05ee2 100644 --- a/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs +++ b/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs @@ -99,6 +99,11 @@ namespace Avalonia.Rendering /// public string DebugFramesPath { get; set; } + /// + /// Forces the renderer to only draw frames on the render thread. Makes Paint to wait until frame is rendered + /// + public bool RenderOnlyOnRenderThread { get; set; } + /// public event EventHandler SceneInvalidated; @@ -180,11 +185,44 @@ namespace Avalonia.Rendering /// public void Paint(Rect rect) { - var t = (IRenderLoopTask)this; - if(t.NeedsUpdate) - UpdateScene(); - if(_scene?.Item != null) - Render(true); + if (RenderOnlyOnRenderThread) + { + // Renderer is stopped and doesn't tick on the render thread + // This indicates a bug somewhere in our code + // (currently happens when a window gets minimized with Show desktop on Windows 10) + if(!_running) + return; + + while (true) + { + Scene scene; + bool? updated; + lock (_sceneLock) + { + updated = UpdateScene(); + scene = _scene?.Item; + } + + // Renderer is in invalid state, skip drawing + if(updated == null) + return; + + // Wait for the scene to be rendered or disposed + scene?.Rendered.Wait(); + + // That was an up-to-date scene, we can return immediately + if (updated == true) + return; + } + } + else + { + var t = (IRenderLoopTask)this; + if (t.NeedsUpdate) + UpdateScene(); + if (_scene?.Item != null) + Render(true); + } } /// @@ -270,13 +308,20 @@ namespace Avalonia.Rendering { if (scene?.Item != null) { - var overlay = DrawDirtyRects || DrawFps; - if (DrawDirtyRects) - _dirtyRectsDisplay.Tick(); - if (overlay) - RenderOverlay(scene.Item, ref context); - if (updated || forceComposite || overlay) - RenderComposite(scene.Item, ref context); + try + { + var overlay = DrawDirtyRects || DrawFps; + if (DrawDirtyRects) + _dirtyRectsDisplay.Tick(); + if (overlay) + RenderOverlay(scene.Item, ref context); + if (updated || forceComposite || overlay) + RenderComposite(scene.Item, ref context); + } + finally + { + scene.Item.MarkAsRendered(); + } } } } @@ -559,15 +604,16 @@ namespace Avalonia.Rendering UpdateScene(); } - private void UpdateScene() + private bool? UpdateScene() { Dispatcher.UIThread.VerifyAccess(); + using var noPump = NonPumpingLockHelper.Use(); lock (_sceneLock) { if (_disposed) - return; + return null; if (_scene?.Item.Generation > _lastSceneId) - return; + return false; } if (_root.IsVisible) { @@ -619,6 +665,8 @@ namespace Avalonia.Rendering SceneInvalidated(this, new SceneInvalidatedEventArgs((IRenderRoot)_root, rect)); } + + return true; } else { @@ -628,6 +676,8 @@ namespace Avalonia.Rendering _scene = null; oldScene?.Dispose(); } + + return null; } } diff --git a/src/Avalonia.Visuals/Rendering/RenderLayer.cs b/src/Avalonia.Visuals/Rendering/RenderLayer.cs index 7a79e45716..768e832fe5 100644 --- a/src/Avalonia.Visuals/Rendering/RenderLayer.cs +++ b/src/Avalonia.Visuals/Rendering/RenderLayer.cs @@ -30,12 +30,12 @@ namespace Avalonia.Rendering { if (Size != size || Scaling != scaling) { - Bitmap.Dispose(); var resized = RefCountable.Create(drawingContext.CreateLayer(size)); using (var context = resized.Item.CreateDrawingContext(null)) { - context.Clear(Colors.Transparent); + Bitmap.Dispose(); + context.Clear(default); Bitmap = resized; Scaling = scaling; diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/Scene.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/Scene.cs index 4f5c97cdff..6a4c532d4a 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/Scene.cs +++ b/src/Avalonia.Visuals/Rendering/SceneGraph/Scene.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Avalonia.Collections.Pooled; using Avalonia.VisualTree; @@ -13,6 +14,7 @@ namespace Avalonia.Rendering.SceneGraph public class Scene : IDisposable { private readonly Dictionary _index; + private readonly TaskCompletionSource _rendered = new TaskCompletionSource(); /// /// Initializes a new instance of the class. @@ -41,6 +43,8 @@ namespace Avalonia.Rendering.SceneGraph root.LayerRoot = root.Visual; } + public Task Rendered => _rendered.Task; + /// /// Gets a value identifying the scene's generation. This is incremented each time the scene is cloned. /// @@ -97,6 +101,7 @@ namespace Avalonia.Rendering.SceneGraph public void Dispose() { + _rendered.TrySetResult(false); foreach (var node in _index.Values) { node.Dispose(); @@ -340,5 +345,7 @@ namespace Avalonia.Rendering.SceneGraph } } } + + public void MarkAsRendered() => _rendered.TrySetResult(true); } } diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/SceneBuilder.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/SceneBuilder.cs index 872f69c884..7d5d62a091 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/SceneBuilder.cs +++ b/src/Avalonia.Visuals/Rendering/SceneGraph/SceneBuilder.cs @@ -24,7 +24,8 @@ namespace Avalonia.Rendering.SceneGraph using (var impl = new DeferredDrawingContextImpl(this, scene.Layers)) using (var context = new DrawingContext(impl)) { - Update(context, scene, (VisualNode)scene.Root, scene.Root.Visual.Bounds, true); + var clip = new Rect(scene.Root.Visual.Bounds.Size); + Update(context, scene, (VisualNode)scene.Root, clip, true); } } @@ -77,7 +78,7 @@ namespace Avalonia.Rendering.SceneGraph using (var impl = new DeferredDrawingContextImpl(this, scene.Layers)) using (var context = new DrawingContext(impl)) { - var clip = scene.Root.Visual.Bounds; + var clip = new Rect(scene.Root.Visual.Bounds.Size); if (node.Parent != null) { @@ -174,7 +175,9 @@ namespace Avalonia.Rendering.SceneGraph if (visual.IsVisible) { - var m = Matrix.CreateTranslation(visual.Bounds.Position); + var m = node != scene.Root ? + Matrix.CreateTranslation(visual.Bounds.Position) : + Matrix.Identity; var renderTransform = Matrix.Identity; diff --git a/src/Avalonia.Visuals/Size.cs b/src/Avalonia.Visuals/Size.cs index d87d2c5fc2..8a805dc6c5 100644 --- a/src/Avalonia.Visuals/Size.cs +++ b/src/Avalonia.Visuals/Size.cs @@ -1,6 +1,8 @@ using System; using System.Globalization; +#if !BUILDTASK using Avalonia.Animation.Animators; +#endif using Avalonia.Utilities; namespace Avalonia @@ -8,11 +10,16 @@ namespace Avalonia /// /// Defines a size. /// - public readonly struct Size : IEquatable +#if !BUILDTASK + public +#endif + readonly struct Size : IEquatable { static Size() { +#if !BUILDTASK Animation.Animation.RegisterAnimator(prop => typeof(Size).IsAssignableFrom(prop.PropertyType)); +#endif } /// diff --git a/src/Avalonia.Visuals/Thickness.cs b/src/Avalonia.Visuals/Thickness.cs index 6d69c4d9a9..06ebc9bfe7 100644 --- a/src/Avalonia.Visuals/Thickness.cs +++ b/src/Avalonia.Visuals/Thickness.cs @@ -1,6 +1,8 @@ using System; using System.Globalization; +#if !BUILDTASK using Avalonia.Animation.Animators; +#endif using Avalonia.Utilities; namespace Avalonia @@ -8,11 +10,16 @@ namespace Avalonia /// /// Describes the thickness of a frame around a rectangle. /// - public readonly struct Thickness : IEquatable +#if !BUILDTASK + public +#endif + readonly struct Thickness : IEquatable { static Thickness() { +#if !BUILDTASK Animation.Animation.RegisterAnimator(prop => typeof(Thickness).IsAssignableFrom(prop.PropertyType)); +#endif } /// diff --git a/src/Avalonia.Visuals/Vector.cs b/src/Avalonia.Visuals/Vector.cs index 2fcf804f14..1b9f5c67d5 100644 --- a/src/Avalonia.Visuals/Vector.cs +++ b/src/Avalonia.Visuals/Vector.cs @@ -1,6 +1,8 @@ using System; using System.Globalization; +#if !BUILDTASK using Avalonia.Animation.Animators; +#endif using Avalonia.Utilities; #nullable enable @@ -10,11 +12,16 @@ namespace Avalonia /// /// Defines a vector. /// - public readonly struct Vector : IEquatable +#if !BUILDTASK + public +#endif + readonly struct Vector : IEquatable { static Vector() { +#if !BUILDTASK Animation.Animation.RegisterAnimator(prop => typeof(Vector).IsAssignableFrom(prop.PropertyType)); +#endif } /// diff --git a/src/Avalonia.Visuals/Visual.cs b/src/Avalonia.Visuals/Visual.cs index 283d9deb52..9327531b46 100644 --- a/src/Avalonia.Visuals/Visual.cs +++ b/src/Avalonia.Visuals/Visual.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Specialized; using Avalonia.Collections; using Avalonia.Data; @@ -484,7 +485,7 @@ namespace Avalonia BindingPriority.LocalValue); } - protected override sealed void LogBindingError(AvaloniaProperty property, Exception e) + protected internal sealed override void LogBindingError(AvaloniaProperty property, Exception e) { // Don't log a binding error unless the control is attached to a logical or visual tree. // In theory this should only need to check for logical tree attachment, but in practise @@ -619,34 +620,30 @@ namespace Avalonia switch (e.Action) { case NotifyCollectionChangedAction.Add: - foreach (Visual v in e.NewItems) - { - v.SetVisualParent(this); - } - + SetVisualParent(e.NewItems, this); break; case NotifyCollectionChangedAction.Remove: - foreach (Visual v in e.OldItems) - { - v.SetVisualParent(null); - } - + SetVisualParent(e.OldItems, null); break; case NotifyCollectionChangedAction.Replace: - foreach (Visual v in e.OldItems) - { - v.SetVisualParent(null); - } - - foreach (Visual v in e.NewItems) - { - v.SetVisualParent(this); - } - + SetVisualParent(e.OldItems, null); + SetVisualParent(e.NewItems, this); break; } } + + private static void SetVisualParent(IList children, Visual parent) + { + var count = children.Count; + + for (var i = 0; i < count; i++) + { + var visual = (Visual) children[i]; + + visual.SetVisualParent(parent); + } + } } } diff --git a/src/Avalonia.Visuals/VisualExtensions.cs b/src/Avalonia.Visuals/VisualExtensions.cs index 6079e5941f..e6523a1469 100644 --- a/src/Avalonia.Visuals/VisualExtensions.cs +++ b/src/Avalonia.Visuals/VisualExtensions.cs @@ -50,7 +50,13 @@ namespace Avalonia { var thisOffset = GetOffsetFrom(common, from); var thatOffset = GetOffsetFrom(common, to); - return -thatOffset * thisOffset; + + if (!thatOffset.TryInvert(out var thatOffsetInverted)) + { + return null; + } + + return thatOffsetInverted * thisOffset; } return null; diff --git a/src/Avalonia.X11/X11Atoms.cs b/src/Avalonia.X11/X11Atoms.cs index 32f1822e51..137757b9cf 100644 --- a/src/Avalonia.X11/X11Atoms.cs +++ b/src/Avalonia.X11/X11Atoms.cs @@ -114,6 +114,8 @@ namespace Avalonia.X11 public readonly IntPtr XA_WM_CLASS = (IntPtr)67; public readonly IntPtr XA_WM_TRANSIENT_FOR = (IntPtr)68; + public readonly IntPtr RR_PROPERTY_RANDR_EDID = (IntPtr)82; + public readonly IntPtr WM_PROTOCOLS; public readonly IntPtr WM_DELETE_WINDOW; public readonly IntPtr WM_TAKE_FOCUS; diff --git a/src/Avalonia.X11/X11Clipboard.cs b/src/Avalonia.X11/X11Clipboard.cs index 7023bb3ef3..d428d82744 100644 --- a/src/Avalonia.X11/X11Clipboard.cs +++ b/src/Avalonia.X11/X11Clipboard.cs @@ -52,7 +52,7 @@ namespace Avalonia.X11 : null; } - private unsafe void OnEvent(XEvent ev) + private unsafe void OnEvent(ref XEvent ev) { if (ev.type == XEventName.SelectionRequest) { @@ -62,7 +62,7 @@ namespace Avalonia.X11 SelectionEvent = { type = XEventName.SelectionNotify, - send_event = true, + send_event = 1, display = _x11.Display, selection = sel.selection, target = sel.target, diff --git a/src/Avalonia.X11/X11Globals.cs b/src/Avalonia.X11/X11Globals.cs index afde15b808..057693f810 100644 --- a/src/Avalonia.X11/X11Globals.cs +++ b/src/Avalonia.X11/X11Globals.cs @@ -123,7 +123,7 @@ namespace Avalonia.X11 } } - private void HandleCompositionAtomOwnerEvents(XEvent ev) + private void HandleCompositionAtomOwnerEvents(ref XEvent ev) { if(ev.type == XEventName.DestroyNotify) UpdateCompositingAtomOwner(); @@ -154,7 +154,7 @@ namespace Avalonia.X11 } } - private void OnRootWindowEvent(XEvent ev) + private void OnRootWindowEvent(ref XEvent ev) { if (ev.type == XEventName.PropertyNotify) { diff --git a/src/Avalonia.X11/X11Info.cs b/src/Avalonia.X11/X11Info.cs index 8cfcbb9836..3bded4cce1 100644 --- a/src/Avalonia.X11/X11Info.cs +++ b/src/Avalonia.X11/X11Info.cs @@ -32,8 +32,10 @@ namespace Avalonia.X11 public IntPtr LastActivityTimestamp { get; set; } public XVisualInfo? TransparentVisualInfo { get; set; } + public bool HasXim { get; set; } + public IntPtr DefaultFontSet { get; set; } - public unsafe X11Info(IntPtr display, IntPtr deferredDisplay) + public unsafe X11Info(IntPtr display, IntPtr deferredDisplay, bool useXim) { Display = display; DeferredDisplay = deferredDisplay; @@ -43,9 +45,24 @@ namespace Avalonia.X11 DefaultCursor = XCreateFontCursor(display, CursorFontShape.XC_top_left_arrow); DefaultRootWindow = XDefaultRootWindow(display); Atoms = new X11Atoms(display); - //TODO: Open an actual XIM once we get support for preedit in our textbox - XSetLocaleModifiers("@im=none"); - Xim = XOpenIM(display, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); + + DefaultFontSet = XCreateFontSet(Display, "-*-*-*-*-*-*-*-*-*-*-*-*-*-*", + out var _, out var _, IntPtr.Zero); + + if (useXim) + { + XSetLocaleModifiers(""); + Xim = XOpenIM(display, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); + if (Xim != IntPtr.Zero) + HasXim = true; + } + + if (Xim == IntPtr.Zero) + { + XSetLocaleModifiers("@im=none"); + Xim = XOpenIM(display, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); + } + XMatchVisualInfo(Display, DefaultScreen, 32, 4, out var visual); if (visual.depth == 32) TransparentVisualInfo = visual; diff --git a/src/Avalonia.X11/X11Platform.cs b/src/Avalonia.X11/X11Platform.cs index ffd7c75608..a57bdbdf87 100644 --- a/src/Avalonia.X11/X11Platform.cs +++ b/src/Avalonia.X11/X11Platform.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; using System.Reflection; +using System.Runtime.InteropServices; using Avalonia.Controls; using Avalonia.Controls.Platform; using Avalonia.FreeDesktop; +using Avalonia.FreeDesktop.DBusIme; using Avalonia.Input; using Avalonia.Input.Platform; using Avalonia.OpenGL; @@ -21,7 +23,8 @@ namespace Avalonia.X11 { private Lazy _keyboardDevice = new Lazy(() => new KeyboardDevice()); public KeyboardDevice KeyboardDevice => _keyboardDevice.Value; - public Dictionary> Windows = new Dictionary>(); + public Dictionary Windows = + new Dictionary(); public XI2Manager XI2; public X11Info Info { get; private set; } public IX11Screens X11Screens { get; private set; } @@ -29,9 +32,24 @@ namespace Avalonia.X11 public X11PlatformOptions Options { get; private set; } public IntPtr OrphanedWindow { get; private set; } public X11Globals Globals { get; private set; } + [DllImport("libc")] + static extern void setlocale(int type, string s); public void Initialize(X11PlatformOptions options) { Options = options; + + bool useXim = false; + if (EnableIme(options)) + { + // Attempt to configure DBus-based input method and check if we can fall back to XIM + if (!X11DBusImeHelper.DetectAndRegister() && ShouldUseXim()) + useXim = true; + } + + // XIM doesn't work at all otherwise + if (useXim) + setlocale(0, ""); + XInitThreads(); Display = XOpenDisplay(IntPtr.Zero); DeferredDisplay = XOpenDisplay(IntPtr.Zero); @@ -40,7 +58,8 @@ namespace Avalonia.X11 if (Display == IntPtr.Zero) throw new Exception("XOpenDisplay failed"); XError.Init(); - Info = new X11Info(Display, DeferredDisplay); + + Info = new X11Info(Display, DeferredDisplay, useXim); Globals = new X11Globals(this); //TODO: log if (options.UseDBusMenu) @@ -90,6 +109,54 @@ namespace Avalonia.X11 { throw new NotSupportedException(); } + + bool EnableIme(X11PlatformOptions options) + { + // Disable if explicitly asked by user + var avaloniaImModule = Environment.GetEnvironmentVariable("AVALONIA_IM_MODULE"); + if (avaloniaImModule == "none") + return false; + + // Use value from options when specified + if (options.EnableIme.HasValue) + return options.EnableIme.Value; + + // Automatically enable for CJK locales + var lang = Environment.GetEnvironmentVariable("LANG"); + var isCjkLocale = lang != null && + (lang.Contains("zh") + || lang.Contains("ja") + || lang.Contains("vi") + || lang.Contains("ko")); + + return isCjkLocale; + } + + bool ShouldUseXim() + { + // Check if we are forbidden from using IME + if (Environment.GetEnvironmentVariable("AVALONIA_IM_MODULE") == "none" + || Environment.GetEnvironmentVariable("GTK_IM_MODULE") == "none" + || Environment.GetEnvironmentVariable("QT_IM_MODULE") == "none") + return true; + + // Check if XIM is configured + var modifiers = Environment.GetEnvironmentVariable("XMODIFIERS"); + if (modifiers == null) + return false; + if (modifiers.Contains("@im=none") || modifiers.Contains("@im=null")) + return false; + if (!modifiers.Contains("@im=")) + return false; + + // Check if we are configured to use it + if (Environment.GetEnvironmentVariable("GTK_IM_MODULE") == "xim" + || Environment.GetEnvironmentVariable("QT_IM_MODULE") == "xim" + || Environment.GetEnvironmentVariable("AVALONIA_IM_MODULE") == "xim") + return true; + + return false; + } } } @@ -103,6 +170,7 @@ namespace Avalonia public bool OverlayPopups { get; set; } public bool UseDBusMenu { get; set; } public bool UseDeferredRendering { get; set; } = true; + public bool? EnableIme { get; set; } public IList GlProfiles { get; set; } = new List { diff --git a/src/Avalonia.X11/X11PlatformThreading.cs b/src/Avalonia.X11/X11PlatformThreading.cs index 0215e43d98..d724cd2aed 100644 --- a/src/Avalonia.X11/X11PlatformThreading.cs +++ b/src/Avalonia.X11/X11PlatformThreading.cs @@ -13,7 +13,9 @@ namespace Avalonia.X11 { private readonly AvaloniaX11Platform _platform; private readonly IntPtr _display; - private readonly Dictionary> _eventHandlers; + + public delegate void EventHandler(ref XEvent xev); + private readonly Dictionary _eventHandlers; private Thread _mainThread; [StructLayout(LayoutKind.Explicit)] @@ -162,13 +164,16 @@ namespace Avalonia.X11 Signaled?.Invoke(prio); } - void HandleX11(CancellationToken cancellationToken) + unsafe void HandleX11(CancellationToken cancellationToken) { while (XPending(_display) != 0) { if (cancellationToken.IsCancellationRequested) return; XNextEvent(_display, out var xev); + if(XFilterEvent(ref xev, IntPtr.Zero)) + continue; + if (xev.type == XEventName.GenericEvent) XGetEventData(_display, &xev.GenericEventCookie); try @@ -182,7 +187,7 @@ namespace Avalonia.X11 } } else if (_eventHandlers.TryGetValue(xev.AnyEvent.window, out var handler)) - handler(xev); + handler(ref xev); } finally { diff --git a/src/Avalonia.X11/X11Screens.cs b/src/Avalonia.X11/X11Screens.cs index af6d2674b6..2900c9edb6 100644 --- a/src/Avalonia.X11/X11Screens.cs +++ b/src/Avalonia.X11/X11Screens.cs @@ -66,7 +66,8 @@ namespace Avalonia.X11 private X11Screen[] _cache; private X11Info _x11; private IntPtr _window; - + const int EDIDStructureLength = 32; // Length of a EDID-Block-Length(128 bytes), XRRGetOutputProperty multiplies offset and length by 4 + public Randr15ScreensImpl(AvaloniaX11Platform platform, X11ScreensUserSettings settings) { _settings = settings; @@ -75,13 +76,45 @@ namespace Avalonia.X11 XRRSelectInput(_x11.Display, _window, RandrEventMask.RRScreenChangeNotify); } - private void OnEvent(XEvent ev) + private void OnEvent(ref XEvent ev) { // Invalidate cache on RRScreenChangeNotify if ((int)ev.type == _x11.RandrEventBase + (int)RandrEvent.RRScreenChangeNotify) _cache = null; } + private unsafe Size? GetPhysicalMonitorSizeFromEDID(IntPtr rrOutput) + { + if(rrOutput == IntPtr.Zero) + return null; + var properties = XRRListOutputProperties(_x11.Display,rrOutput, out int propertyCount); + var hasEDID = false; + for(var pc = 0; pc < propertyCount; pc++) + { + if(properties[pc] == _x11.Atoms.RR_PROPERTY_RANDR_EDID) + hasEDID = true; + } + if(!hasEDID) + return null; + XRRGetOutputProperty(_x11.Display, rrOutput, _x11.Atoms.RR_PROPERTY_RANDR_EDID, 0, EDIDStructureLength, false, false, _x11.Atoms.AnyPropertyType, out IntPtr actualType, out int actualFormat, out int bytesAfter, out _, out IntPtr prop); + if(actualType != _x11.Atoms.XA_INTEGER) + return null; + if(actualFormat != 8) // Expecting an byte array + return null; + + var edid = new byte[bytesAfter]; + Marshal.Copy(prop,edid,0,bytesAfter); + XFree(prop); + XFree(new IntPtr(properties)); + if(edid.Length < 22) + return null; + var width = edid[21]; // 0x15 1 Max. Horizontal Image Size cm. + var height = edid[22]; // 0x16 1 Max. Vertical Image Size cm. + if(width == 0 && height == 0) + return null; + return new Size(width * 10, height * 10); + } + public unsafe X11Screen[] Screens { get @@ -97,24 +130,28 @@ namespace Avalonia.X11 var namePtr = XGetAtomName(_x11.Display, mon.Name); var name = Marshal.PtrToStringAnsi(namePtr); XFree(namePtr); - - var density = 1d; + var bounds = new PixelRect(mon.X, mon.Y, mon.Width, mon.Height); + Size? pSize = null; + double density = 0; if (_settings.NamedScaleFactors?.TryGetValue(name, out density) != true) { - if (mon.MWidth == 0) - density = 1; - else - density = X11Screen.GuessPixelDensity(mon.Width, mon.MWidth); + for(int o = 0; o < mon.NOutput; o++) + { + var outputSize = GetPhysicalMonitorSizeFromEDID(mon.Outputs[o]); + var outputDensity = 1d; + if(outputSize != null) + outputDensity = X11Screen.GuessPixelDensity(bounds, outputSize.Value); + if(density == 0 || density > outputDensity) + { + density = outputDensity; + pSize = outputSize; + } + } } - + if(density == 0) + density = 1; density *= _settings.GlobalScaleFactor; - - var bounds = new PixelRect(mon.X, mon.Y, mon.Width, mon.Height); - screens[c] = new X11Screen(bounds, - mon.Primary != 0, - name, - (mon.MWidth == 0 || mon.MHeight == 0) ? (Size?)null : new Size(mon.MWidth, mon.MHeight), - density); + screens[c] = new X11Screen(bounds, mon.Primary != 0, name, pSize, density); } XFree(new IntPtr(monitors)); @@ -163,7 +200,6 @@ namespace Avalonia.X11 } - public int ScreenCount => _impl.Screens.Length; public IReadOnlyList AllScreens => @@ -229,6 +265,7 @@ namespace Avalonia.X11 class X11Screen { private const int FullHDWidth = 1920; + private const int FullHDHeight = 1080; public bool Primary { get; } public string Name { get; set; } public PixelRect Bounds { get; set; } @@ -248,7 +285,7 @@ namespace Avalonia.X11 } else if (pixelDensity == null) { - PixelDensity = GuessPixelDensity(bounds.Width, physicalSize.Value.Width); + PixelDensity = GuessPixelDensity(bounds, physicalSize.Value); } else { @@ -257,7 +294,26 @@ namespace Avalonia.X11 } } - public static double GuessPixelDensity(double pixelWidth, double mmWidth) - => pixelWidth <= FullHDWidth ? 1 : Math.Max(1, Math.Round(pixelWidth / mmWidth * 25.4 / 96)); + public static double GuessPixelDensity(PixelRect pixel, Size physical) + { + var calculatedDensity = 1d; + if(physical.Width > 0) + calculatedDensity = pixel.Width <= FullHDWidth ? 1 : Math.Max(1, pixel.Width / physical.Width * 25.4 / 96); + else if(physical.Height > 0) + calculatedDensity = pixel.Height <= FullHDHeight ? 1 : Math.Max(1, pixel.Height / physical.Height * 25.4 / 96); + + if(calculatedDensity > 3) + return 1; + else + { + var sanePixelDensities = new double[] { 1, 1.25, 1.50, 1.75, 2 }; + foreach(var saneDensity in sanePixelDensities) + { + if(calculatedDensity <= saneDensity + 0.20) + return saneDensity; + } + return sanePixelDensities.Last(); + } + } } } diff --git a/src/Avalonia.X11/X11Structs.cs b/src/Avalonia.X11/X11Structs.cs index 7ee764e8a3..b1006b43ee 100644 --- a/src/Avalonia.X11/X11Structs.cs +++ b/src/Avalonia.X11/X11Structs.cs @@ -53,7 +53,7 @@ namespace Avalonia.X11 { internal struct XAnyEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr window; } @@ -62,7 +62,7 @@ namespace Avalonia.X11 { internal struct XKeyEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr window; internal IntPtr root; @@ -74,14 +74,14 @@ namespace Avalonia.X11 { internal int y_root; internal XModifierMask state; internal int keycode; - internal bool same_screen; + internal int same_screen; } [StructLayout(LayoutKind.Sequential)] internal struct XButtonEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr window; internal IntPtr root; @@ -93,14 +93,14 @@ namespace Avalonia.X11 { internal int y_root; internal XModifierMask state; internal int button; - internal bool same_screen; + internal int same_screen; } [StructLayout(LayoutKind.Sequential)] internal struct XMotionEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr window; internal IntPtr root; @@ -112,14 +112,14 @@ namespace Avalonia.X11 { internal int y_root; internal XModifierMask state; internal byte is_hint; - internal bool same_screen; + internal int same_screen; } [StructLayout(LayoutKind.Sequential)] internal struct XCrossingEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr window; internal IntPtr root; @@ -131,8 +131,8 @@ namespace Avalonia.X11 { internal int y_root; internal NotifyMode mode; internal NotifyDetail detail; - internal bool same_screen; - internal bool focus; + internal int same_screen; + internal int focus; internal XModifierMask state; } @@ -140,7 +140,7 @@ namespace Avalonia.X11 { internal struct XFocusChangeEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr window; internal int mode; @@ -151,7 +151,7 @@ namespace Avalonia.X11 { internal struct XKeymapEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr window; internal byte key_vector0; @@ -192,7 +192,7 @@ namespace Avalonia.X11 { internal struct XExposeEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr window; internal int x; @@ -206,7 +206,7 @@ namespace Avalonia.X11 { internal struct XGraphicsExposeEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr drawable; internal int x; @@ -222,7 +222,7 @@ namespace Avalonia.X11 { internal struct XNoExposeEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr drawable; internal int major_code; @@ -233,7 +233,7 @@ namespace Avalonia.X11 { internal struct XVisibilityEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr window; internal int state; @@ -243,7 +243,7 @@ namespace Avalonia.X11 { internal struct XCreateWindowEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr parent; internal IntPtr window; @@ -252,14 +252,14 @@ namespace Avalonia.X11 { internal int width; internal int height; internal int border_width; - internal bool override_redirect; + internal int override_redirect; } [StructLayout(LayoutKind.Sequential)] internal struct XDestroyWindowEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr xevent; internal IntPtr window; @@ -269,29 +269,29 @@ namespace Avalonia.X11 { internal struct XUnmapEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr xevent; internal IntPtr window; - internal bool from_configure; + internal int from_configure; } [StructLayout(LayoutKind.Sequential)] internal struct XMapEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr xevent; internal IntPtr window; - internal bool override_redirect; + internal int override_redirect; } [StructLayout(LayoutKind.Sequential)] internal struct XMapRequestEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr parent; internal IntPtr window; @@ -301,21 +301,21 @@ namespace Avalonia.X11 { internal struct XReparentEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr xevent; internal IntPtr window; internal IntPtr parent; internal int x; internal int y; - internal bool override_redirect; + internal int override_redirect; } [StructLayout(LayoutKind.Sequential)] internal struct XConfigureEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr xevent; internal IntPtr window; @@ -325,14 +325,14 @@ namespace Avalonia.X11 { internal int height; internal int border_width; internal IntPtr above; - internal bool override_redirect; + internal int override_redirect; } [StructLayout(LayoutKind.Sequential)] internal struct XGravityEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr xevent; internal IntPtr window; @@ -344,7 +344,7 @@ namespace Avalonia.X11 { internal struct XResizeRequestEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr window; internal int width; @@ -355,7 +355,7 @@ namespace Avalonia.X11 { internal struct XConfigureRequestEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr parent; internal IntPtr window; @@ -373,7 +373,7 @@ namespace Avalonia.X11 { internal struct XCirculateEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr xevent; internal IntPtr window; @@ -384,7 +384,7 @@ namespace Avalonia.X11 { internal struct XCirculateRequestEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr parent; internal IntPtr window; @@ -395,7 +395,7 @@ namespace Avalonia.X11 { internal struct XPropertyEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr window; internal IntPtr atom; @@ -407,7 +407,7 @@ namespace Avalonia.X11 { internal struct XSelectionClearEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr window; internal IntPtr selection; @@ -418,7 +418,7 @@ namespace Avalonia.X11 { internal struct XSelectionRequestEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr owner; internal IntPtr requestor; @@ -432,7 +432,7 @@ namespace Avalonia.X11 { internal struct XSelectionEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr requestor; internal IntPtr selection; @@ -445,11 +445,11 @@ namespace Avalonia.X11 { internal struct XColormapEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr window; internal IntPtr colormap; - internal bool c_new; + internal int c_new; internal int state; } @@ -457,7 +457,7 @@ namespace Avalonia.X11 { internal struct XClientMessageEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr window; internal IntPtr message_type; @@ -473,7 +473,7 @@ namespace Avalonia.X11 { internal struct XMappingEvent { internal XEventName type; internal IntPtr serial; - internal bool send_event; + internal int send_event; internal IntPtr display; internal IntPtr window; internal int request; @@ -518,6 +518,15 @@ namespace Avalonia.X11 { internal IntPtr pad21; internal IntPtr pad22; internal IntPtr pad23; + internal IntPtr pad24; + internal IntPtr pad25; + internal IntPtr pad26; + internal IntPtr pad27; + internal IntPtr pad28; + internal IntPtr pad29; + internal IntPtr pad30; + internal IntPtr pad31; + internal IntPtr pad32; } [StructLayout(LayoutKind.Sequential)] @@ -525,7 +534,7 @@ namespace Avalonia.X11 { { internal int type; /* of event. Always GenericEvent */ internal IntPtr serial; /* # of last request processed */ - internal bool send_event; /* true if from SendEvent request */ + internal int send_event; /* true if from SendEvent request */ internal IntPtr display; /* Display the event was read from */ internal int extension; /* major opcode of extension that caused the event */ internal int evtype; /* actual event type. */ @@ -672,10 +681,10 @@ namespace Avalonia.X11 { internal int backing_store; internal IntPtr backing_planes; internal IntPtr backing_pixel; - internal bool save_under; + internal int save_under; internal IntPtr event_mask; internal IntPtr do_not_propagate_mask; - internal bool override_redirect; + internal int override_redirect; internal IntPtr colormap; internal IntPtr cursor; } @@ -696,14 +705,14 @@ namespace Avalonia.X11 { internal int backing_store; internal IntPtr backing_planes; internal IntPtr backing_pixel; - internal bool save_under; + internal int save_under; internal IntPtr colormap; - internal bool map_installed; + internal int map_installed; internal MapState map_state; internal IntPtr all_event_masks; internal IntPtr your_event_mask; internal IntPtr do_not_propagate_mask; - internal bool override_direct; + internal int override_direct; internal IntPtr screen; public override string ToString () @@ -1029,7 +1038,7 @@ namespace Avalonia.X11 { internal int max_maps; internal int min_maps; internal int backing_store; - internal bool save_unders; + internal int save_unders; internal IntPtr root_input_mask; } @@ -1280,7 +1289,7 @@ namespace Avalonia.X11 { internal int ts_y_origin; internal IntPtr font; internal GCSubwindowMode subwindow_mode; - internal bool graphics_exposures; + internal int graphics_exposures; internal int clip_x_origin; internal int clib_y_origin; internal IntPtr clip_mask; @@ -1499,7 +1508,7 @@ namespace Avalonia.X11 { [StructLayout(LayoutKind.Sequential)] internal struct XWMHints { internal IntPtr flags; - internal bool input; + internal int input; internal XInitialState initial_state; internal IntPtr icon_pixmap; internal IntPtr icon_window; @@ -1708,19 +1717,30 @@ namespace Avalonia.X11 { } [StructLayout (LayoutKind.Sequential)] - internal struct XIMStyles + internal unsafe struct XIMStyles { public ushort count_styles; - public IntPtr supported_styles; + public IntPtr* supported_styles; } [StructLayout (LayoutKind.Sequential)] [Serializable] - internal class XPoint + internal struct XPoint { public short X; public short Y; } + + [StructLayout (LayoutKind.Sequential)] + [Serializable] + internal struct XRectangle + { + public short X; + public short Y; + public short W; + public short H; + } + [StructLayout (LayoutKind.Sequential)] [Serializable] @@ -1798,7 +1818,7 @@ namespace Avalonia.X11 { { public ushort Length; public IntPtr Feedback; // to XIMFeedbackStruct - public bool EncodingIsWChar; + public int EncodingIsWChar; public IntPtr String; // it could be either char* or wchar_t* } @@ -1850,6 +1870,8 @@ namespace Avalonia.X11 { public const string XNClientWindow = "clientWindow"; public const string XNInputStyle = "inputStyle"; public const string XNFocusWindow = "focusWindow"; + public const string XNResourceName = "resourceName"; + public const string XNResourceClass = "resourceClass"; // XIMPreeditCallbacks delegate names. public const string XNPreeditStartCallback = "preeditStartCallback"; @@ -1870,7 +1892,7 @@ namespace Avalonia.X11 { public const string XNFontSet = "fontSet"; } - struct XRRMonitorInfo { + unsafe struct XRRMonitorInfo { public IntPtr Name; public int Primary; public int Automatic; @@ -1881,6 +1903,6 @@ namespace Avalonia.X11 { public int Height; public int MWidth; public int MHeight; - public IntPtr Outputs; + public IntPtr* Outputs; } } diff --git a/src/Avalonia.X11/X11Window.Ime.cs b/src/Avalonia.X11/X11Window.Ime.cs new file mode 100644 index 0000000000..f469ff7455 --- /dev/null +++ b/src/Avalonia.X11/X11Window.Ime.cs @@ -0,0 +1,208 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using Avalonia.FreeDesktop; +using Avalonia.Input; +using Avalonia.Input.Raw; +using Avalonia.Input.TextInput; +using Avalonia.Platform.Interop; +using static Avalonia.X11.XLib; + +namespace Avalonia.X11 +{ + partial class X11Window + { + private ITextInputMethodImpl _ime; + private IX11InputMethodControl _imeControl; + private bool _processingIme; + + private Queue<(RawKeyEventArgs args, XEvent xev, int keyval, int keycode)> _imeQueue = + new Queue<(RawKeyEventArgs args, XEvent xev, int keyVal, int keyCode)>(); + + unsafe void CreateIC() + { + if (_x11.HasXim) + { + XGetIMValues(_x11.Xim, XNames.XNQueryInputStyle, out var supported_styles, IntPtr.Zero); + for (var c = 0; c < supported_styles->count_styles; c++) + { + var style = (XIMProperties)supported_styles->supported_styles[c]; + if ((int)(style & XIMProperties.XIMPreeditPosition) != 0 + && ((int)(style & XIMProperties.XIMStatusNothing) != 0)) + { + XPoint spot = default; + XRectangle area = default; + + + //using var areaS = new Utf8Buffer("area"); + using var spotS = new Utf8Buffer("spotLocation"); + using var fontS = new Utf8Buffer("fontSet"); + + var list = XVaCreateNestedList(0, + //areaS, &area, + spotS, &spot, + fontS, _x11.DefaultFontSet, + IntPtr.Zero); + _xic = XCreateIC(_x11.Xim, + XNames.XNClientWindow, _handle, + XNames.XNFocusWindow, _handle, + XNames.XNInputStyle, new IntPtr((int)style), + XNames.XNResourceName, _platform.Options.WmClass, + XNames.XNResourceClass, _platform.Options.WmClass, + XNames.XNPreeditAttributes, list, + IntPtr.Zero); + + XFree(list); + + break; + } + } + + XFree(new IntPtr(supported_styles)); + } + + if (_xic == IntPtr.Zero) + _xic = XCreateIC(_x11.Xim, XNames.XNInputStyle, + new IntPtr((int)(XIMProperties.XIMPreeditNothing | XIMProperties.XIMStatusNothing)), + XNames.XNClientWindow, _handle, XNames.XNFocusWindow, _handle, IntPtr.Zero); + } + + void InitializeIme() + { + var ime = AvaloniaLocator.Current.GetService()?.CreateClient(_handle); + if (ime == null && _x11.HasXim) + { + var xim = new XimInputMethod(this); + ime = (xim, xim); + } + if (ime != null) + { + (_ime, _imeControl) = ime.Value; + _imeControl.Commit += s => + ScheduleInput(new RawTextInputEventArgs(_keyboard, (ulong)_x11.LastActivityTimestamp.ToInt64(), + _inputRoot, s)); + _imeControl.ForwardKey += ev => + { + ScheduleInput(new RawKeyEventArgs(_keyboard, (ulong)_x11.LastActivityTimestamp.ToInt64(), + _inputRoot, ev.Type, X11KeyTransform.ConvertKey((X11Key)ev.KeyVal), + (RawInputModifiers)ev.Modifiers)); + }; + } + } + + void UpdateImePosition() => _imeControl?.UpdateWindowInfo(Position, RenderScaling); + + void HandleKeyEvent(ref XEvent ev) + { + var index = ev.KeyEvent.state.HasFlag(XModifierMask.ShiftMask); + + // We need the latin key, since it's mainly used for hotkeys, we use a different API for text anyway + var key = (X11Key)XKeycodeToKeysym(_x11.Display, ev.KeyEvent.keycode, index ? 1 : 0).ToInt32(); + + // Manually switch the Shift index for the keypad, + // there should be a proper way to do this + if (ev.KeyEvent.state.HasFlag(XModifierMask.Mod2Mask) + && key > X11Key.Num_Lock && key <= X11Key.KP_9) + key = (X11Key)XKeycodeToKeysym(_x11.Display, ev.KeyEvent.keycode, index ? 0 : 1).ToInt32(); + + var filtered = ScheduleKeyInput(new RawKeyEventArgs(_keyboard, (ulong)ev.KeyEvent.time.ToInt64(), _inputRoot, + ev.type == XEventName.KeyPress ? RawKeyEventType.KeyDown : RawKeyEventType.KeyUp, + X11KeyTransform.ConvertKey(key), TranslateModifiers(ev.KeyEvent.state)), ref ev, (int)key, ev.KeyEvent.keycode); + + if (ev.type == XEventName.KeyPress && !filtered) + TriggerClassicTextInputEvent(ref ev); + } + + void TriggerClassicTextInputEvent(ref XEvent ev) + { + var text = TranslateEventToString(ref ev); + if (text != null) + ScheduleInput( + new RawTextInputEventArgs(_keyboard, (ulong)ev.KeyEvent.time.ToInt64(), _inputRoot, text), + ref ev); + } + + private const int ImeBufferSize = 64 * 1024; + [ThreadStatic] private static IntPtr ImeBuffer; + + unsafe string TranslateEventToString(ref XEvent ev) + { + if (ImeBuffer == IntPtr.Zero) + ImeBuffer = Marshal.AllocHGlobal(ImeBufferSize); + + var len = Xutf8LookupString(_xic, ref ev, ImeBuffer.ToPointer(), ImeBufferSize, + out _, out var istatus); + var status = (XLookupStatus)istatus; + + if (len == 0) + return null; + + string text; + if (status == XLookupStatus.XBufferOverflow) + return null; + else + text = Encoding.UTF8.GetString((byte*)ImeBuffer.ToPointer(), len); + + if (text == null) + return null; + + if (text.Length == 1) + { + if (text[0] < ' ' || text[0] == 0x7f) //Control codes or DEL + return null; + } + + return text; + } + + + bool ScheduleKeyInput(RawKeyEventArgs args, ref XEvent xev, int keyval, int keycode) + { + _x11.LastActivityTimestamp = xev.ButtonEvent.time; + if (_imeControl != null && _imeControl.IsEnabled) + { + if (FilterIme(args, xev, keyval, keycode)) + return true; + } + ScheduleInput(args); + return false; + } + + bool FilterIme(RawKeyEventArgs args, XEvent xev, int keyval, int keycode) + { + if (_ime == null) + return false; + _imeQueue.Enqueue((args, xev, keyval, keycode)); + if (!_processingIme) + ProcessNextImeEvent(); + + return true; + } + + async void ProcessNextImeEvent() + { + if(_processingIme) + return; + _processingIme = true; + try + { + while (_imeQueue.Count != 0) + { + var ev = _imeQueue.Dequeue(); + if (_imeControl == null || !await _imeControl.HandleEventAsync(ev.args, ev.keyval, ev.keycode)) + { + ScheduleInput(ev.args); + if (ev.args.Type == RawKeyEventType.KeyDown) + TriggerClassicTextInputEvent(ref ev.xev); + } + } + } + finally + { + _processingIme = false; + } + } + } +} diff --git a/src/Avalonia.X11/X11Window.Xim.cs b/src/Avalonia.X11/X11Window.Xim.cs new file mode 100644 index 0000000000..444c82fd22 --- /dev/null +++ b/src/Avalonia.X11/X11Window.Xim.cs @@ -0,0 +1,121 @@ +using System; +using System.Threading.Tasks; +using Avalonia.FreeDesktop; +using Avalonia.Input.Raw; +using Avalonia.Input.TextInput; +using Avalonia.Platform.Interop; +using Avalonia.Threading; +using static Avalonia.X11.XLib; +namespace Avalonia.X11 +{ + partial class X11Window + { + + class XimInputMethod : ITextInputMethodImpl, IX11InputMethodControl + { + private readonly X11Window _parent; + private bool _controlActive, _windowActive, _imeActive; + private Rect? _queuedCursorRect; + + public XimInputMethod(X11Window parent) + { + _parent = parent; + } + + public void SetCursorRect(Rect rect) + { + var needEnqueue = _queuedCursorRect == null; + _queuedCursorRect = rect; + if(needEnqueue) + Dispatcher.UIThread.Post(() => + { + if(_queuedCursorRect == null) + return; + var rc = _queuedCursorRect.Value; + _queuedCursorRect = null; + + if (_parent._xic == IntPtr.Zero) + return; + + rect *= _parent._scaling; + + var pt = new XPoint + { + X = (short)Math.Min(Math.Max(rect.X, short.MinValue), short.MaxValue), + Y = (short)Math.Min(Math.Max(rect.Y + rect.Height, short.MinValue), short.MaxValue) + }; + + using var spotLoc = new Utf8Buffer(XNames.XNSpotLocation); + var list = XVaCreateNestedList(0, spotLoc, ref pt, IntPtr.Zero); + XSetICValues(_parent._xic, XNames.XNPreeditAttributes, list, IntPtr.Zero); + XFree(list); + }, DispatcherPriority.Background); + } + + public void SetWindowActive(bool active) + { + _windowActive = active; + UpdateActive(); + } + + public void SetActive(bool active) + { + _controlActive = active; + UpdateActive(); + } + + private void UpdateActive() + { + var active = _windowActive && _controlActive; + if(_parent._xic == IntPtr.Zero) + return; + if (active != _imeActive) + { + _imeActive = active; + if (active) + { + Reset(); + XSetICFocus(_parent._xic); + } + else + XUnsetICFocus(_parent._xic); + } + } + + public void UpdateWindowInfo(PixelPoint position, double scaling) + { + // No-op + } + + public void SetOptions(TextInputOptionsQueryEventArgs options) + { + // No-op + } + + public void Reset() + { + if(_parent._xic == IntPtr.Zero) + return; + + var data = XmbResetIC(_parent._xic); + if (data != IntPtr.Zero) + XFree(data); + } + + public void Dispose() + { + // No-op + } + + public bool IsEnabled => false; + + public ValueTask HandleEventAsync(RawKeyEventArgs args, int keyVal, int keyCode) => + new ValueTask(false); + + public event Action Commit; + public event Action ForwardKey; + + } + + } +} diff --git a/src/Avalonia.X11/X11Window.cs b/src/Avalonia.X11/X11Window.cs index 32c455571f..92d1e37efe 100644 --- a/src/Avalonia.X11/X11Window.cs +++ b/src/Avalonia.X11/X11Window.cs @@ -5,12 +5,14 @@ using System.Diagnostics; using System.Linq; using System.Reactive.Disposables; using System.Text; +using System.Threading.Tasks; using Avalonia.Controls; using Avalonia.Controls.Platform; using Avalonia.Controls.Primitives.PopupPositioning; using Avalonia.FreeDesktop; using Avalonia.Input; using Avalonia.Input.Raw; +using Avalonia.Input.TextInput; using Avalonia.OpenGL; using Avalonia.OpenGL.Egl; using Avalonia.Platform; @@ -22,9 +24,10 @@ using static Avalonia.X11.XLib; // ReSharper disable StringLiteralTypo namespace Avalonia.X11 { - unsafe class X11Window : IWindowImpl, IPopupImpl, IXI2Client, + unsafe partial class X11Window : IWindowImpl, IPopupImpl, IXI2Client, ITopLevelImplWithNativeMenuExporter, - ITopLevelImplWithNativeControlHost + ITopLevelImplWithNativeControlHost, + ITopLevelImplWithTextInputMethod { private readonly AvaloniaX11Platform _platform; private readonly IWindowImpl _popupParent; @@ -79,7 +82,7 @@ namespace Avalonia.X11 if (_popup) { - attr.override_redirect = true; + attr.override_redirect = 1; valueMask |= SetWindowValuemask.OverrideRedirect; } @@ -178,17 +181,24 @@ namespace Avalonia.X11 Surfaces = surfaces.ToArray(); UpdateMotifHints(); UpdateSizeHints(null); - _xic = XCreateIC(_x11.Xim, XNames.XNInputStyle, XIMProperties.XIMPreeditNothing | XIMProperties.XIMStatusNothing, - XNames.XNClientWindow, _handle, IntPtr.Zero); + _transparencyHelper = new TransparencyHelper(_x11, _handle, platform.Globals); _transparencyHelper.SetTransparencyRequest(WindowTransparencyLevel.None); + CreateIC(); + XFlush(_x11.Display); if(_popup) PopupPositioner = new ManagedPopupPositioner(new ManagedPopupPositionerPopupImplHelper(popupParent, MoveResize)); if (platform.Options.UseDBusMenu) NativeMenuExporter = DBusMenuExporter.TryCreate(_handle); NativeControlHost = new X11NativeControlHost(_platform, this); + DispatcherTimer.Run(() => + { + Paint?.Invoke(default); + return _handle != IntPtr.Zero; + }, TimeSpan.FromMilliseconds(100)); + InitializeIme(); } class SurfaceInfo : EglGlPlatformSurface.IEglWindowGlPlatformSurfaceInfo @@ -338,19 +348,20 @@ namespace Avalonia.X11 return customRendererFactory.Create(root, loop); return _platform.Options.UseDeferredRendering ? - new DeferredRenderer(root, loop) : + new DeferredRenderer(root, loop) + { + RenderOnlyOnRenderThread = true + } : (IRenderer)new X11ImmediateRendererProxy(root, loop); } - void OnEvent(XEvent ev) + void OnEvent(ref XEvent ev) { lock (SyncRoot) - OnEventSync(ev); + OnEventSync(ref ev); } - void OnEventSync(XEvent ev) + void OnEventSync(ref XEvent ev) { - if(XFilterEvent(ref ev, _handle)) - return; if (ev.type == XEventName.MapNotify) { _mapped = true; @@ -378,9 +389,13 @@ namespace Avalonia.X11 if (ActivateTransientChildIfNeeded()) return; Activated?.Invoke(); + _imeControl?.SetWindowActive(true); } else if (ev.type == XEventName.FocusOut) + { + _imeControl?.SetWindowActive(false); Deactivated?.Invoke(); + } else if (ev.type == XEventName.MotionNotify) MouseEvent(RawPointerEventType.Move, ref ev, ev.MotionEvent.state); else if (ev.type == XEventName.LeaveNotify) @@ -439,7 +454,7 @@ namespace Avalonia.X11 return; var needEnqueue = (_configure == null); _configure = ev.ConfigureEvent; - if (ev.ConfigureEvent.override_redirect || ev.ConfigureEvent.send_event) + if (ev.ConfigureEvent.override_redirect != 0 || ev.ConfigureEvent.send_event != 0) _configurePoint = new PixelPoint(ev.ConfigureEvent.x, ev.ConfigureEvent.y); else { @@ -469,6 +484,7 @@ namespace Avalonia.X11 PositionChanged?.Invoke(npos); updatedSizeViaScaling = UpdateScaling(); } + UpdateImePosition(); if (changedSize && !updatedSizeViaScaling && !_popup) Resized?.Invoke(ClientSize); @@ -479,7 +495,8 @@ namespace Avalonia.X11 XConfigureResizeWindow(_x11.Display, _renderHandle, ev.ConfigureEvent.width, ev.ConfigureEvent.height); } - else if (ev.type == XEventName.DestroyNotify && ev.AnyEvent.window == _handle) + else if (ev.type == XEventName.DestroyNotify + && ev.DestroyWindowEvent.window == _handle) { Cleanup(); } @@ -499,39 +516,7 @@ namespace Avalonia.X11 { if (ActivateTransientChildIfNeeded()) return; - var buffer = stackalloc byte[40]; - - var index = ev.KeyEvent.state.HasFlag(XModifierMask.ShiftMask); - - // We need the latin key, since it's mainly used for hotkeys, we use a different API for text anyway - var key = (X11Key)XKeycodeToKeysym(_x11.Display, ev.KeyEvent.keycode, index ? 1 : 0).ToInt32(); - - // Manually switch the Shift index for the keypad, - // there should be a proper way to do this - if (ev.KeyEvent.state.HasFlag(XModifierMask.Mod2Mask) - && key > X11Key.Num_Lock && key <= X11Key.KP_9) - key = (X11Key)XKeycodeToKeysym(_x11.Display, ev.KeyEvent.keycode, index ? 0 : 1).ToInt32(); - - - ScheduleInput(new RawKeyEventArgs(_keyboard, (ulong)ev.KeyEvent.time.ToInt64(), _inputRoot, - ev.type == XEventName.KeyPress ? RawKeyEventType.KeyDown : RawKeyEventType.KeyUp, - X11KeyTransform.ConvertKey(key), TranslateModifiers(ev.KeyEvent.state)), ref ev); - - if (ev.type == XEventName.KeyPress) - { - var len = Xutf8LookupString(_xic, ref ev, buffer, 40, out _, out _); - if (len != 0) - { - var text = Encoding.UTF8.GetString(buffer, len); - if (text.Length == 1) - { - if (text[0] < ' ' || text[0] == 0x7f) //Control codes or DEL - return; - } - ScheduleInput(new RawTextInputEventArgs(_keyboard, (ulong)ev.KeyEvent.time.ToInt64(), _inputRoot, text), - ref ev); - } - } + HandleKeyEvent(ref ev); } } @@ -554,6 +539,7 @@ namespace Avalonia.X11 var oldScaledSize = ClientSize; RenderScaling = newScaling; ScalingChanged?.Invoke(RenderScaling); + UpdateImePosition(); SetMinMaxSize(_scaledMinMaxSize.minSize, _scaledMinMaxSize.maxSize); if(!skipResize) Resize(oldScaledSize, true); @@ -691,6 +677,7 @@ namespace Avalonia.X11 _x11.LastActivityTimestamp = xev.ButtonEvent.time; ScheduleInput(args); } + public void ScheduleXI2Input(RawInputEventArgs args) { @@ -773,6 +760,13 @@ namespace Avalonia.X11 void Cleanup() { + if (_imeControl != null) + { + _imeControl.Dispose(); + _imeControl = null; + _ime = null; + } + if (_xic != IntPtr.Zero) { XDestroyIC(_xic); @@ -815,7 +809,7 @@ namespace Avalonia.X11 XSetTransientForHint(_x11.Display, _handle, parent.Handle.Handle); } - public void Show() + public void Show(bool activate) { _wasMappedAtLeastOnce = true; XMapWindow(_x11.Display, _handle); @@ -947,7 +941,7 @@ namespace Avalonia.X11 ClientMessageEvent = { type = XEventName.ClientMessage, - send_event = true, + send_event = 1, window = _handle, message_type = message_type, format = 32, @@ -1120,6 +1114,8 @@ namespace Avalonia.X11 public IPopupPositioner PopupPositioner { get; } public ITopLevelNativeMenuExporter NativeMenuExporter { get; } public INativeControlHostImpl NativeControlHost { get; } + public ITextInputMethodImpl TextInputMethod => _ime; + public void SetTransparencyLevelHint(WindowTransparencyLevel transparencyLevel) => _transparencyHelper.SetTransparencyRequest(transparencyLevel); diff --git a/src/Avalonia.X11/XI2Manager.cs b/src/Avalonia.X11/XI2Manager.cs index 742973e0da..8cdf24cc7b 100644 --- a/src/Avalonia.X11/XI2Manager.cs +++ b/src/Avalonia.X11/XI2Manager.cs @@ -13,7 +13,10 @@ namespace Avalonia.X11 { XiEventType.XI_Motion, XiEventType.XI_ButtonPress, - XiEventType.XI_ButtonRelease + XiEventType.XI_ButtonRelease, + XiEventType.XI_Leave, + XiEventType.XI_Enter, + }; private static readonly XiEventType[] MultiTouchEventTypes = new XiEventType[] @@ -162,7 +165,9 @@ namespace Avalonia.X11 | XEventMask.Button4MotionMask | XEventMask.Button5MotionMask | XEventMask.ButtonPressMask - | XEventMask.ButtonReleaseMask; + | XEventMask.ButtonReleaseMask + | XEventMask.LeaveWindowMask + | XEventMask.EnterWindowMask; } public void OnWindowDestroyed(IntPtr xid) => _clients.Remove(xid); @@ -175,14 +180,39 @@ namespace Avalonia.X11 _pointerDevice.Update(changed->Classes, changed->NumClasses); } - + if ((xev->evtype >= XiEventType.XI_ButtonPress && xev->evtype <= XiEventType.XI_Motion) - || (xev->evtype>=XiEventType.XI_TouchBegin&&xev->evtype<=XiEventType.XI_TouchEnd)) + || (xev->evtype >= XiEventType.XI_TouchBegin && xev->evtype <= XiEventType.XI_TouchEnd)) { var dev = (XIDeviceEvent*)xev; if (_clients.TryGetValue(dev->EventWindow, out var client)) OnDeviceEvent(client, new ParsedDeviceEvent(dev)); } + + if (xev->evtype == XiEventType.XI_Leave || xev->evtype == XiEventType.XI_Enter) + { + var rev = (XIEnterLeaveEvent*)xev; + if (_clients.TryGetValue(rev->EventWindow, out var client)) + OnEnterLeaveEvent(client, ref *rev); + } + } + + void OnEnterLeaveEvent(IXI2Client client, ref XIEnterLeaveEvent ev) + { + if (ev.evtype == XiEventType.XI_Leave) + { + var buttons = ParsedDeviceEvent.ParseButtonState(ev.buttons.MaskLen, ev.buttons.Mask); + var detail = ev.detail; + if ((detail == XiEnterLeaveDetail.XINotifyNonlinearVirtual || + detail == XiEnterLeaveDetail.XINotifyNonlinear || + detail == XiEnterLeaveDetail.XINotifyVirtual) + && buttons == default) + { + client.ScheduleXI2Input(new RawPointerEventArgs(client.MouseDevice, (ulong)ev.time.ToInt64(), + client.InputRoot, + RawPointerEventType.LeaveWindow, new Point(ev.event_x, ev.event_y), buttons)); + } + } } void OnDeviceEvent(IXI2Client client, ParsedDeviceEvent ev) @@ -284,6 +314,29 @@ namespace Avalonia.X11 public int Detail { get; set; } public bool Emulated { get; set; } public Dictionary Valuators { get; } + + public static RawInputModifiers ParseButtonState(int len, byte* buttons) + { + RawInputModifiers rv = default; + if (len > 0) + { + if (XIMaskIsSet(buttons, 1)) + rv |= RawInputModifiers.LeftMouseButton; + if (XIMaskIsSet(buttons, 2)) + rv |= RawInputModifiers.MiddleMouseButton; + if (XIMaskIsSet(buttons, 3)) + rv |= RawInputModifiers.RightMouseButton; + if (len > 1) + { + if (XIMaskIsSet(buttons, 8)) + rv |= RawInputModifiers.XButton1MouseButton; + if (XIMaskIsSet(buttons, 9)) + rv |= RawInputModifiers.XButton2MouseButton; + } + } + return rv; + } + public ParsedDeviceEvent(XIDeviceEvent* ev) { Type = ev->evtype; @@ -298,27 +351,16 @@ namespace Avalonia.X11 if (state.HasFlag(XModifierMask.Mod4Mask)) Modifiers |= RawInputModifiers.Meta; - if (ev->buttons.MaskLen > 0) - { - var buttons = ev->buttons.Mask; - if (XIMaskIsSet(buttons, 1)) - Modifiers |= RawInputModifiers.LeftMouseButton; - if (XIMaskIsSet(buttons, 2)) - Modifiers |= RawInputModifiers.MiddleMouseButton; - if (XIMaskIsSet(buttons, 3)) - Modifiers |= RawInputModifiers.RightMouseButton; - if (XIMaskIsSet(buttons, 8)) - Modifiers |= RawInputModifiers.XButton1MouseButton; - if (XIMaskIsSet(buttons, 9)) - Modifiers |= RawInputModifiers.XButton2MouseButton; - } + Modifiers |= ParseButtonState(ev->buttons.MaskLen, ev->buttons.Mask); Valuators = new Dictionary(); Position = new Point(ev->event_x, ev->event_y); var values = ev->valuators.Values; - for (var c = 0; c < ev->valuators.MaskLen * 8; c++) - if (XIMaskIsSet(ev->valuators.Mask, c)) - Valuators[c] = *values++; + if(ev->valuators.Mask != null) + for (var c = 0; c < ev->valuators.MaskLen * 8; c++) + if (XIMaskIsSet(ev->valuators.Mask, c)) + Valuators[c] = *values++; + if (Type == XiEventType.XI_ButtonPress || Type == XiEventType.XI_ButtonRelease) Button = ev->detail; Detail = ev->detail; diff --git a/src/Avalonia.X11/XIStructs.cs b/src/Avalonia.X11/XIStructs.cs index 4675ef47f2..f4581a99ba 100644 --- a/src/Avalonia.X11/XIStructs.cs +++ b/src/Avalonia.X11/XIStructs.cs @@ -236,6 +236,34 @@ namespace Avalonia.X11 public XIModifierState mods; public XIModifierState group; } + + [StructLayout(LayoutKind.Sequential)] + unsafe struct XIEnterLeaveEvent + { + public XEventName type; /* GenericEvent */ + public UIntPtr serial; /* # of last request processed by server */ + public Bool send_event; /* true if this came from a SendEvent request */ + public IntPtr display; /* Display the event was read from */ + public int extension; /* XI extension offset */ + public XiEventType evtype; + public IntPtr time; + public int deviceid; + public int sourceid; + public XiEnterLeaveDetail detail; + public IntPtr RootWindow; + public IntPtr EventWindow; + public IntPtr ChildWindow; + public double root_x; + public double root_y; + public double event_x; + public double event_y; + public int mode; + public int focus; + public int same_screen; + public XIButtonState buttons; + public XIModifierState mods; + public XIModifierState group; + } [Flags] public enum XiDeviceEventFlags : int @@ -286,5 +314,18 @@ namespace Avalonia.X11 XI_BarrierLeave = 26, XI_LASTEVENT = XI_BarrierLeave, } - + + enum XiEnterLeaveDetail + { + XINotifyAncestor = 0, + XINotifyVirtual = 1, + XINotifyInferior = 2, + XINotifyNonlinear = 3, + XINotifyNonlinearVirtual = 4, + XINotifyPointer = 5, + XINotifyPointerRoot = 6, + XINotifyDetailNone = 7 + + } + } diff --git a/src/Avalonia.X11/XLib.cs b/src/Avalonia.X11/XLib.cs index f5da691caa..e2b370821f 100644 --- a/src/Avalonia.X11/XLib.cs +++ b/src/Avalonia.X11/XLib.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; +using Avalonia.Platform.Interop; // ReSharper disable MemberCanBePrivate.Global // ReSharper disable FieldCanBeMadeReadOnly.Global @@ -58,6 +59,9 @@ namespace Avalonia.X11 [DllImport(libX11)] public static extern IntPtr XNextEvent(IntPtr display, out XEvent xevent); + + [DllImport(libX11)] + public static extern IntPtr XNextEvent(IntPtr display, XEvent* xevent); [DllImport(libX11)] public static extern int XConnectionNumber(IntPtr diplay); @@ -408,6 +412,9 @@ namespace Avalonia.X11 [DllImport(libX11)] public static extern bool XFilterEvent(ref XEvent xevent, IntPtr window); + + [DllImport(libX11)] + public static extern bool XFilterEvent(XEvent* xevent, IntPtr window); [DllImport(libX11)] public static extern void XkbSetDetectableAutoRepeat(IntPtr display, bool detectable, IntPtr supported); @@ -442,9 +449,9 @@ namespace Avalonia.X11 [DllImport(libX11)] public static extern IntPtr XCreateColormap(IntPtr display, IntPtr window, IntPtr visual, int create); - public enum XLookupStatus + public enum XLookupStatus : uint { - XBufferOverflow = -1, + XBufferOverflow = 0xffffffffu, XLookupNone = 1, XLookupChars = 2, XLookupKeySym = 3, @@ -455,7 +462,10 @@ namespace Avalonia.X11 public static extern unsafe int XLookupString(ref XEvent xevent, void* buffer, int num_bytes, out IntPtr keysym, out IntPtr status); [DllImport (libX11)] - public static extern unsafe int Xutf8LookupString(IntPtr xic, ref XEvent xevent, void* buffer, int num_bytes, out IntPtr keysym, out IntPtr status); + public static extern unsafe int Xutf8LookupString(IntPtr xic, ref XEvent xevent, void* buffer, int num_bytes, out IntPtr keysym, out UIntPtr status); + + [DllImport (libX11)] + public static extern unsafe int Xutf8LookupString(IntPtr xic, XEvent* xevent, void* buffer, int num_bytes, out IntPtr keysym, out IntPtr status); [DllImport (libX11)] public static extern unsafe IntPtr XKeycodeToKeysym(IntPtr display, int keycode, int index); @@ -465,12 +475,52 @@ namespace Avalonia.X11 [DllImport (libX11)] public static extern IntPtr XOpenIM (IntPtr display, IntPtr rdb, IntPtr res_name, IntPtr res_class); - + + [DllImport (libX11)] + public static extern IntPtr XGetIMValues (IntPtr xim, string name, out XIMStyles* value, IntPtr terminator); + [DllImport (libX11)] - public static extern IntPtr XCreateIC (IntPtr xim, string name, XIMProperties im_style, string name2, IntPtr value2, IntPtr terminator); + public static extern IntPtr XCreateIC (IntPtr xim, string name, IntPtr value, string name2, IntPtr value2, string name3, IntPtr value3, IntPtr terminator); + + [DllImport(libX11)] + public static extern IntPtr XCreateIC(IntPtr xim, string name, IntPtr value, string name2, IntPtr value2, + string name3, IntPtr value3, string name4, IntPtr value4, IntPtr terminator); + + [DllImport(libX11)] + public static extern IntPtr XCreateIC(IntPtr xim, string xnClientWindow, IntPtr handle, + string xnInputStyle, IntPtr value3, string xnResourceName, string optionsWmClass, + string xnResourceClass, string wmClass, string xnPreeditAttributes, IntPtr list, IntPtr zero); + + [DllImport(libX11)] + public static extern IntPtr XCreateIC(IntPtr xim, string xnClientWindow, IntPtr handle, string xnFocusWindow, + IntPtr value2, string xnInputStyle, IntPtr value3, string xnResourceName, string optionsWmClass, + string xnResourceClass, string wmClass, string xnPreeditAttributes, IntPtr list, IntPtr zero); + + [DllImport(libX11)] + public static extern void XSetICFocus(IntPtr xic); + + [DllImport(libX11)] + public static extern void XUnsetICFocus(IntPtr xic); + + [DllImport(libX11)] + public static extern IntPtr XmbResetIC(IntPtr xic); + + [DllImport(libX11)] + public static extern IntPtr XVaCreateNestedList(int unused, Utf8Buffer name, ref XPoint point, IntPtr terminator); + + [DllImport(libX11)] + public static extern IntPtr XVaCreateNestedList(int unused, Utf8Buffer xnArea, XRectangle* point, + Utf8Buffer xnSpotLocation, XPoint* value2, Utf8Buffer xnFontSet, IntPtr fs, IntPtr zero); + + [DllImport(libX11)] + public static extern IntPtr XVaCreateNestedList(int unused, + Utf8Buffer xnSpotLocation, XPoint* value2, Utf8Buffer xnFontSet, IntPtr fs, IntPtr zero); [DllImport (libX11)] - public static extern IntPtr XCreateIC (IntPtr xim, string name, XIMProperties im_style, string name2, IntPtr value2, string name3, IntPtr value3, IntPtr terminator); + public static extern IntPtr XCreateFontSet (IntPtr display, string name, out IntPtr list, out int count, IntPtr unused); + + [DllImport(libX11)] + public static extern IntPtr XSetICValues(IntPtr ic, string name, IntPtr data, IntPtr terminator); [DllImport (libX11)] public static extern void XCloseIM (IntPtr xim); @@ -501,6 +551,13 @@ namespace Avalonia.X11 [DllImport(libX11Randr)] public static extern XRRMonitorInfo* XRRGetMonitors(IntPtr dpy, IntPtr window, bool get_active, out int nmonitors); + + [DllImport(libX11Randr)] + public static extern IntPtr* XRRListOutputProperties(IntPtr dpy, IntPtr output, out int count); + + [DllImport(libX11Randr)] + public static extern int XRRGetOutputProperty(IntPtr dpy, IntPtr output, IntPtr atom, int offset, int length, bool _delete, bool pending, IntPtr req_type, out IntPtr actual_type, out int actual_format, out int nitems, out long bytes_after, out IntPtr prop); + [DllImport(libX11Randr)] public static extern void XRRSelectInput(IntPtr dpy, IntPtr window, RandrEventMask mask); @@ -633,14 +690,12 @@ namespace Avalonia.X11 } } - public static IntPtr CreateEventWindow(AvaloniaX11Platform plat, Action handler) + public static IntPtr CreateEventWindow(AvaloniaX11Platform plat, X11PlatformThreading.EventHandler handler) { var win = XCreateSimpleWindow(plat.Display, plat.Info.DefaultRootWindow, 0, 0, 1, 1, 0, IntPtr.Zero, IntPtr.Zero); plat.Windows[win] = handler; return win; } - - } } diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/Avalonia.Markup.Xaml.Loader.csproj b/src/Markup/Avalonia.Markup.Xaml.Loader/Avalonia.Markup.Xaml.Loader.csproj index 514556d0b9..db9c414840 100644 --- a/src/Markup/Avalonia.Markup.Xaml.Loader/Avalonia.Markup.Xaml.Loader.csproj +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/Avalonia.Markup.Xaml.Loader.csproj @@ -4,6 +4,7 @@ netstandard2.0 true Avalonia.Markup.Xaml.Loader + $(DefineConstants);XAMLX_INTERNAL diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/AvaloniaXamlIlRuntimeCompiler.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/AvaloniaXamlIlRuntimeCompiler.cs index d9b4cd70da..ece90762cb 100644 --- a/src/Markup/Avalonia.Markup.Xaml.Loader/AvaloniaXamlIlRuntimeCompiler.cs +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/AvaloniaXamlIlRuntimeCompiler.cs @@ -26,6 +26,7 @@ namespace Avalonia.Markup.Xaml.XamlIl { #if !RUNTIME_XAML_CECIL private static SreTypeSystem _sreTypeSystem; + private static Type _ignoresAccessChecksFromAttribute; private static ModuleBuilder _sreBuilder; private static IXamlType _sreContextType; private static XamlLanguageTypeMappings _sreMappings; @@ -94,8 +95,60 @@ namespace Avalonia.Markup.Xaml.XamlIl _sreTypeSystem.CreateTypeBuilder( _sreBuilder.DefineType("XamlIlContext")), _sreTypeSystem, _sreMappings, _sreEmitMappings); + if (_ignoresAccessChecksFromAttribute == null) + _ignoresAccessChecksFromAttribute = EmitIgnoresAccessCheckAttributeDefinition(_sreBuilder); } + static Type EmitIgnoresAccessCheckAttributeDefinition(ModuleBuilder builder) + { + var tb = builder.DefineType("System.Runtime.CompilerServices.IgnoresAccessChecksToAttribute", + TypeAttributes.Class | TypeAttributes.Public, typeof(Attribute)); + var field = tb.DefineField("_name", typeof(string), FieldAttributes.Private); + var propGet = tb.DefineMethod("get_AssemblyName", MethodAttributes.Public, typeof(string), + Array.Empty()); + var propGetIl = propGet.GetILGenerator(); + propGetIl.Emit(OpCodes.Ldarg_0); + propGetIl.Emit(OpCodes.Ldfld, field); + propGetIl.Emit(OpCodes.Ret); + var prop = tb.DefineProperty("AssemblyName", PropertyAttributes.None, typeof(string), Array.Empty()); + prop.SetGetMethod(propGet); + + + var ctor = tb.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, + new[] { typeof(string) }); + var ctorIl = ctor.GetILGenerator(); + ctorIl.Emit(OpCodes.Ldarg_0); + ctorIl.Emit(OpCodes.Ldarg_1); + ctorIl.Emit(OpCodes.Stfld, field); + ctorIl.Emit(OpCodes.Ldarg_0); + ctorIl.Emit(OpCodes.Call, typeof(Attribute) + .GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) + .First(x => x.GetParameters().Length == 0)); + + ctorIl.Emit(OpCodes.Ret); + + tb.SetCustomAttribute(new CustomAttributeBuilder( + typeof(AttributeUsageAttribute).GetConstructor(new[] { typeof(AttributeTargets) }), + new object[] { AttributeTargets.Assembly }, + new[] { typeof(AttributeUsageAttribute).GetProperty("AllowMultiple") }, + new object[] { true })); + + return tb.CreateTypeInfo(); + } + + static void EmitIgnoresAccessCheckToAttribute(AssemblyName assemblyName) + { + var name = assemblyName.Name; + if(string.IsNullOrWhiteSpace(name)) + return; + var key = assemblyName.GetPublicKey(); + if (key != null && key.Length != 0) + name += ", PublicKey=" + BitConverter.ToString(key).Replace("-", "").ToUpperInvariant(); + _sreAsm.SetCustomAttribute(new CustomAttributeBuilder( + _ignoresAccessChecksFromAttribute.GetConstructors()[0], + new object[] { name })); + } + static object LoadSre(string xaml, Assembly localAssembly, object rootInstance, Uri uri, bool isDesignMode) { @@ -118,6 +171,8 @@ namespace Avalonia.Markup.Xaml.XamlIl { InitializeSre(); + if (localAssembly?.GetName() != null) + EmitIgnoresAccessCheckToAttribute(localAssembly.GetName()); var asm = localAssembly == null ? null : _sreTypeSystem.GetAssembly(localAssembly); var tb = _sreBuilder.DefineType("Builder_" + Guid.NewGuid().ToString("N") + "_" + uri); var clrPropertyBuilder = tb.DefineNestedType("ClrProperties_" + Guid.NewGuid().ToString("N")); diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AstNodes/AvaloniaXamlIlAvaloniaListConstantAstNode.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AstNodes/AvaloniaXamlIlAvaloniaListConstantAstNode.cs new file mode 100644 index 0000000000..0f4efc9f65 --- /dev/null +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AstNodes/AvaloniaXamlIlAvaloniaListConstantAstNode.cs @@ -0,0 +1,54 @@ +using System.Collections.Generic; +using Avalonia.Controls; +using Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers; +using XamlX.Ast; +using XamlX.Emit; +using XamlX.IL; +using XamlX.TypeSystem; + +namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.AstNodes +{ + class AvaloniaXamlIlAvaloniaListConstantAstNode : XamlAstNode, IXamlAstValueNode, IXamlAstILEmitableNode + { + private readonly IXamlType _elementType; + private readonly IReadOnlyList _values; + private readonly IXamlConstructor _constructor; + private readonly IXamlMethod _listAddMethod; + private readonly IXamlMethod _listSetCapacityMethod; + + public AvaloniaXamlIlAvaloniaListConstantAstNode(IXamlLineInfo lineInfo, AvaloniaXamlIlWellKnownTypes types, IXamlType listType, IXamlType elementType, IReadOnlyList values) : base(lineInfo) + { + _constructor = listType.GetConstructor(); + _listAddMethod = listType.GetMethod(new FindMethodMethodSignature("Add", types.XamlIlTypes.Void, elementType)); + _listSetCapacityMethod = listType.GetMethod(new FindMethodMethodSignature("set_Capacity", types.XamlIlTypes.Void, types.Int)); + + _elementType = elementType; + _values = values; + + Type = new XamlAstClrTypeReference(lineInfo, listType, false); + } + + public IXamlAstTypeReference Type { get; } + + public XamlILNodeEmitResult Emit(XamlEmitContext context, IXamlILEmitter codeGen) + { + codeGen.Newobj(_constructor); + + codeGen + .Dup() + .Ldc_I4(_values.Count) + .EmitCall(_listSetCapacityMethod); + + foreach (var value in _values) + { + codeGen.Dup(); + + context.Emit(value, codeGen, _elementType); + + codeGen.EmitCall(_listAddMethod); + } + + return XamlILNodeEmitResult.Type(0, Type.GetClrType()); + } + } +} diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AstNodes/AvaloniaXamlIlFontFamilyAstNode.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AstNodes/AvaloniaXamlIlFontFamilyAstNode.cs new file mode 100644 index 0000000000..1f50e661d8 --- /dev/null +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AstNodes/AvaloniaXamlIlFontFamilyAstNode.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers; +using XamlX.Ast; +using XamlX.Emit; +using XamlX.IL; +using XamlX.TypeSystem; + +namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.AstNodes +{ + class AvaloniaXamlIlFontFamilyAstNode: XamlAstNode, IXamlAstValueNode, IXamlAstILEmitableNode + { + private readonly AvaloniaXamlIlWellKnownTypes _types; + private readonly string _text; + + public IXamlAstTypeReference Type { get; } + + public AvaloniaXamlIlFontFamilyAstNode(AvaloniaXamlIlWellKnownTypes types, + string text, + IXamlLineInfo lineInfo) : base(lineInfo) + { + _types = types; + _text = text; + Type = new XamlAstClrTypeReference(lineInfo, types.FontFamily, false); + } + + public XamlILNodeEmitResult Emit(XamlEmitContext context, IXamlILEmitter codeGen) + { + codeGen + .Ldloc(context.ContextLocal) + .Castclass(context.Configuration.TypeMappings.UriContextProvider) + .EmitCall(context.Configuration.TypeMappings.UriContextProvider.FindMethod( + "get_BaseUri", _types.Uri, false)) + .Ldstr(_text) + .Newobj(_types.FontFamilyConstructorUriName); + return XamlILNodeEmitResult.Type(0, _types.FontFamily); + } + } +} diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AstNodes/AvaloniaXamlIlGridLengthAstNode.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AstNodes/AvaloniaXamlIlGridLengthAstNode.cs new file mode 100644 index 0000000000..218c49512c --- /dev/null +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AstNodes/AvaloniaXamlIlGridLengthAstNode.cs @@ -0,0 +1,34 @@ +using Avalonia.Controls; +using Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers; +using XamlX.Ast; +using XamlX.Emit; +using XamlX.IL; + +namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.AstNodes +{ + class AvaloniaXamlIlGridLengthAstNode : XamlAstNode, IXamlAstValueNode, IXamlAstILEmitableNode + { + private readonly AvaloniaXamlIlWellKnownTypes _types; + private readonly GridLength _gridLength; + + public AvaloniaXamlIlGridLengthAstNode(IXamlLineInfo lineInfo, AvaloniaXamlIlWellKnownTypes types, GridLength gridLength) : base(lineInfo) + { + _types = types; + _gridLength = gridLength; + + Type = new XamlAstClrTypeReference(lineInfo, types.GridLength, false); + } + + public IXamlAstTypeReference Type { get; } + + public XamlILNodeEmitResult Emit(XamlEmitContext context, IXamlILEmitter codeGen) + { + codeGen + .Ldc_R8(_gridLength.Value) + .Ldc_I4((int)_gridLength.GridUnitType) + .Newobj(_types.GridLengthConstructorValueType); + + return XamlILNodeEmitResult.Type(0, Type.GetClrType()); + } + } +} diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AstNodes/AvaloniaXamlIlVectorLikeConstantAstNode.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AstNodes/AvaloniaXamlIlVectorLikeConstantAstNode.cs new file mode 100644 index 0000000000..35cc9b3cf2 --- /dev/null +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AstNodes/AvaloniaXamlIlVectorLikeConstantAstNode.cs @@ -0,0 +1,54 @@ +using Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers; +using XamlX; +using XamlX.Ast; +using XamlX.Emit; +using XamlX.IL; +using XamlX.TypeSystem; + +namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.AstNodes +{ + class AvaloniaXamlIlVectorLikeConstantAstNode : XamlAstNode, IXamlAstValueNode, IXamlAstILEmitableNode + { + private readonly IXamlConstructor _constructor; + private readonly double[] _values; + + public AvaloniaXamlIlVectorLikeConstantAstNode(IXamlLineInfo lineInfo, AvaloniaXamlIlWellKnownTypes types, IXamlType type, IXamlConstructor constructor, double[] values) : base(lineInfo) + { + var parameters = constructor.Parameters; + + if (parameters.Count != values.Length) + { + throw new XamlTypeSystemException($"Constructor that takes {values.Length} parameters is expected, got {parameters.Count} instead."); + } + + var elementType = types.XamlIlTypes.Double; + + foreach (var parameter in parameters) + { + if (parameter != elementType) + { + throw new XamlTypeSystemException($"Expected parameter of type {elementType}, got {parameter} instead."); + } + } + + _constructor = constructor; + _values = values; + + Type = new XamlAstClrTypeReference(lineInfo, type, false); + } + + public IXamlAstTypeReference Type { get; } + + public XamlILNodeEmitResult Emit(XamlEmitContext context, IXamlILEmitter codeGen) + { + foreach (var value in _values) + { + codeGen.Ldc_R8(value); + } + + codeGen.Newobj(_constructor); + + return XamlILNodeEmitResult.Type(0, Type.GetClrType()); + } + } +} diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlLanguage.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlLanguage.cs index 99ec3744bf..a82f5b9e60 100644 --- a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlLanguage.cs +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlLanguage.cs @@ -1,7 +1,11 @@ +using System; using System.Collections.Generic; using System.Globalization; using System.Linq; +using Avalonia.Controls; +using Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.AstNodes; using Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers; +using Avalonia.Media; using XamlX; using XamlX.Ast; using XamlX.Emit; @@ -166,28 +170,27 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions public static bool CustomValueConverter(AstTransformationContext context, IXamlAstValueNode node, IXamlType type, out IXamlAstValueNode result) { - if (type.FullName == "System.TimeSpan" - && node is XamlAstTextNode tn - && !tn.Text.Contains(":")) + if (!(node is XamlAstTextNode textNode)) { - var seconds = double.Parse(tn.Text, CultureInfo.InvariantCulture); - result = new XamlStaticOrTargetedReturnMethodCallNode(tn, - type.FindMethod("FromSeconds", type, false, context.Configuration.WellKnownTypes.Double), - new[] - { - new XamlConstantNode(tn, context.Configuration.WellKnownTypes.Double, seconds) - }); - return true; + result = null; + return false; } + var text = textNode.Text; + var types = context.GetAvaloniaTypes(); + + if (AvaloniaXamlIlLanguageParseIntrinsics.TryConvert(context, node, text, type, types, out result)) + { + return true; + } + if (type.FullName == "Avalonia.AvaloniaProperty") { var scope = context.ParentNodes().OfType().FirstOrDefault(); if (scope == null) throw new XamlX.XamlLoadException("Unable to find the parent scope for AvaloniaProperty lookup", node); - if (!(node is XamlAstTextNode text)) - throw new XamlX.XamlLoadException("Property should be a text node", node); - result = XamlIlAvaloniaPropertyHelper.CreateNode(context, text.Text, scope.TargetType, text); + + result = XamlIlAvaloniaPropertyHelper.CreateNode(context, text, scope.TargetType, node ); return true; } diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlLanguageParseIntrinsics.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlLanguageParseIntrinsics.cs new file mode 100644 index 0000000000..7c4cc8d28b --- /dev/null +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlLanguageParseIntrinsics.cs @@ -0,0 +1,243 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using Avalonia.Controls; +using Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.AstNodes; +using Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers; +using Avalonia.Media; +using XamlX.Ast; +using XamlX.Transform; +using XamlX.TypeSystem; + +namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions +{ + class AvaloniaXamlIlLanguageParseIntrinsics + { + public static bool TryConvert(AstTransformationContext context, IXamlAstValueNode node, string text, IXamlType type, AvaloniaXamlIlWellKnownTypes types, out IXamlAstValueNode result) + { + if (type.FullName == "System.TimeSpan") + { + var tsText = text.Trim(); + + if (!TimeSpan.TryParse(tsText, CultureInfo.InvariantCulture, out var timeSpan)) + { + // // shorthand seconds format (ie. "0.25") + if (!tsText.Contains(":") && double.TryParse(tsText, + NumberStyles.Float | NumberStyles.AllowThousands, + CultureInfo.InvariantCulture, out var seconds)) + timeSpan = TimeSpan.FromSeconds(seconds); + else + throw new XamlX.XamlLoadException($"Unable to parse {text} as a time span", node); + } + + result = new XamlStaticOrTargetedReturnMethodCallNode(node, + type.FindMethod("FromTicks", type, false, types.Long), + new[] { new XamlConstantNode(node, types.Long, timeSpan.Ticks) }); + return true; + } + + if (type.Equals(types.FontFamily)) + { + result = new AvaloniaXamlIlFontFamilyAstNode(types, text, node); + return true; + } + + if (type.Equals(types.Thickness)) + { + try + { + var thickness = Thickness.Parse(text); + + result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Thickness, types.ThicknessFullConstructor, + new[] { thickness.Left, thickness.Top, thickness.Right, thickness.Bottom }); + + return true; + } + catch + { + throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a thickness", node); + } + } + + if (type.Equals(types.Point)) + { + try + { + var point = Point.Parse(text); + + result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Point, types.PointFullConstructor, + new[] { point.X, point.Y }); + + return true; + } + catch + { + throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a point", node); + } + } + + if (type.Equals(types.Vector)) + { + try + { + var vector = Vector.Parse(text); + + result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Vector, types.VectorFullConstructor, + new[] { vector.X, vector.Y }); + + return true; + } + catch + { + throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a vector", node); + } + } + + if (type.Equals(types.Size)) + { + try + { + var size = Size.Parse(text); + + result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Size, types.SizeFullConstructor, + new[] { size.Width, size.Height }); + + return true; + } + catch + { + throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a size", node); + } + } + + if (type.Equals(types.Matrix)) + { + try + { + var matrix = Matrix.Parse(text); + + result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Matrix, types.MatrixFullConstructor, + new[] { matrix.M11, matrix.M12, matrix.M21, matrix.M22, matrix.M31, matrix.M32 }); + + return true; + } + catch + { + throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a matrix", node); + } + } + + if (type.Equals(types.CornerRadius)) + { + try + { + var cornerRadius = CornerRadius.Parse(text); + + result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.CornerRadius, types.CornerRadiusFullConstructor, + new[] { cornerRadius.TopLeft, cornerRadius.TopRight, cornerRadius.BottomRight, cornerRadius.BottomLeft }); + + return true; + } + catch + { + throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a corner radius", node); + } + } + + if (type.Equals(types.Color)) + { + if (!Color.TryParse(text, out Color color)) + { + throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a color", node); + } + + result = new XamlStaticOrTargetedReturnMethodCallNode(node, + type.GetMethod( + new FindMethodMethodSignature("FromUInt32", type, types.UInt) { IsStatic = true }), + new[] { new XamlConstantNode(node, types.UInt, color.ToUint32()) }); + + return true; + } + + if (type.Equals(types.GridLength)) + { + try + { + var gridLength = GridLength.Parse(text); + + result = new AvaloniaXamlIlGridLengthAstNode(node, types, gridLength); + + return true; + } + catch + { + throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a grid length", node); + } + } + + if (type.Equals(types.Cursor)) + { + if (TypeSystemHelpers.TryGetEnumValueNode(types.StandardCursorType, text, node, out var enumConstantNode)) + { + var cursorTypeRef = new XamlAstClrTypeReference(node, types.Cursor, false); + + result = new XamlAstNewClrObjectNode(node, cursorTypeRef, types.CursorTypeConstructor, new List { enumConstantNode }); + + return true; + } + } + + if (type.Equals(types.ColumnDefinitions)) + { + return ConvertDefinitionList(node, text, types, types.ColumnDefinitions, types.ColumnDefinition, "column definitions", out result); + } + + if (type.Equals(types.RowDefinitions)) + { + return ConvertDefinitionList(node, text, types, types.RowDefinitions, types.RowDefinition, "row definitions", out result); + } + + result = null; + return false; + } + + private static bool ConvertDefinitionList( + IXamlAstValueNode node, + string text, + AvaloniaXamlIlWellKnownTypes types, + IXamlType listType, + IXamlType elementType, + string errorDisplayName, + out IXamlAstValueNode result) + { + try + { + var lengths = GridLength.ParseLengths(text); + + var definitionTypeRef = new XamlAstClrTypeReference(node, elementType, false); + + var definitionConstructorGridLength = elementType.GetConstructor(new List {types.GridLength}); + + IXamlAstValueNode CreateDefinitionNode(GridLength length) + { + var lengthNode = new AvaloniaXamlIlGridLengthAstNode(node, types, length); + + return new XamlAstNewClrObjectNode(node, definitionTypeRef, + definitionConstructorGridLength, new List {lengthNode}); + } + + var definitionNodes = + new List(lengths.Select(CreateDefinitionNode)); + + result = new AvaloniaXamlIlAvaloniaListConstantAstNode(node, types, listType, elementType, definitionNodes); + + return true; + } + catch + { + throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a {errorDisplayName}", node); + } + } + } +} diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlBindingPathParser.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlBindingPathParser.cs index 7944d8b569..24cded1d22 100644 --- a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlBindingPathParser.cs +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlBindingPathParser.cs @@ -72,16 +72,16 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers v.Property is AvaloniaSyntheticCompiledBindingProperty prop && prop.Name == SyntheticCompiledBindingPropertyName.ElementName); - var sourceProperty = syntheticCompiledBindingProperties - .FirstOrDefault(v => - v.Property is AvaloniaSyntheticCompiledBindingProperty prop - && prop.Name == SyntheticCompiledBindingPropertyName.Source); - var relativeSourceProperty = syntheticCompiledBindingProperties .FirstOrDefault(v => v.Property is AvaloniaSyntheticCompiledBindingProperty prop && prop.Name == SyntheticCompiledBindingPropertyName.RelativeSource); + var sourceProperty = binding.Children.OfType() + .FirstOrDefault(v => + v.Property is XamlAstClrProperty prop + && prop.Name == "Source"); + if (elementNameProperty?.Values[0] is XamlAstTextNode elementName) { convertedNode = new BindingExpressionGrammar.NameNode { Name = elementName.Text }; @@ -91,14 +91,9 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers throw new XamlParseException($"Invalid ElementName '{elementNameProperty.Values[0]}'.", elementNameProperty.Values[0]); } - if (sourceProperty?.Values[0] != null) + if (sourceProperty != null && convertedNode != null) { - if (convertedNode != null) - { - throw new XamlParseException("Only one of ElementName, Source, or RelativeSource specified as a binding source. Only one property is allowed.", binding); - } - - convertedNode = new RawSourceBindingExpressionNode(sourceProperty?.Values[0]); + throw new XamlParseException("Only one of ElementName, Source, or RelativeSource specified as a binding source. Only one property is allowed.", binding); } if (GetRelativeSourceObjectFromAssignment( @@ -223,10 +218,6 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers { binding.Children.Remove(elementNameProperty); } - if (sourceProperty != null) - { - binding.Children.Remove(sourceProperty); - } if (relativeSourceProperty != null) { binding.Children.Remove(relativeSourceProperty); diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlBindingPathTransformer.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlBindingPathTransformer.cs index fc32084687..4d8c940bbc 100644 --- a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlBindingPathTransformer.cs +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlBindingPathTransformer.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using XamlX; using XamlX.Ast; using XamlX.Transform; using XamlX.TypeSystem; @@ -15,14 +13,102 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers { if (node is XamlAstConstructableObjectNode binding && binding.Type.GetClrType().Equals(context.GetAvaloniaTypes().CompiledBindingExtension)) { - IXamlType startType; - var parentDataContextNode = context.ParentNodes().OfType().FirstOrDefault(); - if (parentDataContextNode is null) + IXamlType startType = null; + var sourceProperty = binding.Children.OfType().FirstOrDefault(c => c.Property.Name == "Source"); + if ((sourceProperty?.Values.Count ?? 0) == 1) { - throw new XamlX.XamlParseException("Cannot parse a compiled binding without an explicit x:DataType directive to give a starting data type for bindings.", binding); + var sourceValue = sourceProperty.Values[0]; + switch (sourceValue) + { + case XamlAstTextNode textNode: + startType = textNode.Type?.GetClrType(); + break; + + case XamlMarkupExtensionNode extension: + startType = extension.Type?.GetClrType(); + + //let's try to infer StaticResource type from parent resources in xaml + if (extension.Value.Type.GetClrType().FullName == "Avalonia.Markup.Xaml.MarkupExtensions.StaticResourceExtension" && + extension.Value is XamlAstConstructableObjectNode cn && + cn.Arguments.Count == 1 && cn.Arguments[0] is XamlAstTextNode keyNode) + { + bool matchProperty(IXamlAstNode node, IXamlType styledElementType, string propertyName) + { + return (node is XamlPropertyAssignmentNode p && + p.Property.DeclaringType == styledElementType && p.Property.Name == propertyName) + || + (node is XamlManipulationGroupNode m && m.Children.Count > 0 && + m.Children[0] is XamlPropertyAssignmentNode pm && + pm.Property.DeclaringType == styledElementType && pm.Property.Name == propertyName); + } + + string getResourceValue_xKey(XamlPropertyAssignmentNode node) + => node.Values.Count == 2 && node.Values[0] is XamlAstTextNode t ? t.Text : ""; + + IXamlType getResourceValue_Type(XamlPropertyAssignmentNode node, IXamlType xamlType) + => node.Values.Count == 2 ? node.Values[1].Type.GetClrType() : xamlType; + + IEnumerable getResourceValues(IXamlAstNode node) + { + if (node is XamlPropertyAssignmentNode propertyNode) + { + if (propertyNode.Values.Count == 1 && + propertyNode.Values[0] is XamlAstConstructableObjectNode obj && + obj.Type.GetClrType().FullName == "Avalonia.Controls.ResourceDictionary") + { + foreach (var r in obj.Children.SelectMany(c => getResourceValues(c))) + { + yield return r; + } + } + else + { + yield return propertyNode; + } + } + else if (node is XamlManipulationGroupNode m) + { + foreach (var r in m.Children.OfType()) + { + yield return r; + } + } + } + + string key = keyNode.Text; + + var styledElement = context.GetAvaloniaTypes().StyledElement; + var resource = context.ParentNodes() + .OfType() + .Where(o => styledElement.IsAssignableFrom(o.Type.GetClrType())) + .Select(o => o.Children.FirstOrDefault(p => matchProperty(p, styledElement, "Resources"))) + .Where(r => r != null) + .SelectMany(r => getResourceValues(r)) + .FirstOrDefault(r => getResourceValue_xKey(r) == key); + + if (resource != null) + { + startType = getResourceValue_Type(resource, startType); + } + } + break; + + case XamlStaticExtensionNode staticExtension: + startType = staticExtension.Type?.GetClrType(); + break; + } } - startType = parentDataContextNode.DataContextType; + if (startType == null) + { + var parentDataContextNode = context.ParentNodes().OfType().FirstOrDefault(); + if (parentDataContextNode is null) + { + throw new XamlX.XamlParseException("Cannot parse a compiled binding without an explicit x:DataType directive to give a starting data type for bindings.", binding); + } + + startType = parentDataContextNode.DataContextType; + } XamlIlBindingPathHelper.UpdateCompiledBindingExtension(context, binding, startType); } diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlTransformInstanceAttachedProperties.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlTransformInstanceAttachedProperties.cs index d78ceeb918..f87e73a783 100644 --- a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlTransformInstanceAttachedProperties.cs +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlTransformInstanceAttachedProperties.cs @@ -22,7 +22,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers var avaloniaObject = context.Configuration.TypeSystem.FindType("Avalonia.AvaloniaObject"); if (avaloniaObject.IsAssignableFrom(targetRef.Type) && avaloniaObject.IsAssignableFrom(declaringRef.Type) - && !targetRef.Type.IsAssignableFrom(declaringRef.Type)) + && !declaringRef.Type.IsAssignableFrom(targetRef.Type)) { // Instance property var clrProp = declaringRef.Type.GetAllProperties().FirstOrDefault(p => p.Name == prop.Name); diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlTransformSyntheticCompiledBindingMembers.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlTransformSyntheticCompiledBindingMembers.cs index 154c6a235c..ba05347a52 100644 --- a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlTransformSyntheticCompiledBindingMembers.cs +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlTransformSyntheticCompiledBindingMembers.cs @@ -25,11 +25,6 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers return new AvaloniaSyntheticCompiledBindingProperty(node, SyntheticCompiledBindingPropertyName.RelativeSource); } - else if (prop.Name == "Source") - { - return new AvaloniaSyntheticCompiledBindingProperty(node, - SyntheticCompiledBindingPropertyName.Source); - } } return node; @@ -39,8 +34,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers enum SyntheticCompiledBindingPropertyName { ElementName, - RelativeSource, - Source + RelativeSource } class AvaloniaSyntheticCompiledBindingProperty : XamlAstNode, IXamlAstPropertyReference diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlWellKnownTypes.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlWellKnownTypes.cs index 3dec96dc43..125701ca9e 100644 --- a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlWellKnownTypes.cs +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlWellKnownTypes.cs @@ -1,3 +1,5 @@ +using System.Collections.Generic; +using System.Linq; using XamlX.Emit; using XamlX.IL; using XamlX.Transform; @@ -47,6 +49,34 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers public IXamlType ReflectionBindingExtension { get; } public IXamlType RelativeSource { get; } + public IXamlType UInt { get; } + public IXamlType Int { get; } + public IXamlType Long { get; } + public IXamlType Uri { get; } + public IXamlType FontFamily { get; } + public IXamlConstructor FontFamilyConstructorUriName { get; } + public IXamlType Thickness { get; } + public IXamlConstructor ThicknessFullConstructor { get; } + public IXamlType Point { get; } + public IXamlConstructor PointFullConstructor { get; } + public IXamlType Vector { get; } + public IXamlConstructor VectorFullConstructor { get; } + public IXamlType Size { get; } + public IXamlConstructor SizeFullConstructor { get; } + public IXamlType Matrix { get; } + public IXamlConstructor MatrixFullConstructor { get; } + public IXamlType CornerRadius { get; } + public IXamlConstructor CornerRadiusFullConstructor { get; } + public IXamlType GridLength { get; } + public IXamlConstructor GridLengthConstructorValueType { get; } + public IXamlType Color { get; } + public IXamlType StandardCursorType { get; } + public IXamlType Cursor { get; } + public IXamlConstructor CursorTypeConstructor { get; } + public IXamlType RowDefinition { get; } + public IXamlType RowDefinitions { get; } + public IXamlType ColumnDefinition { get; } + public IXamlType ColumnDefinitions { get; } public AvaloniaXamlIlWellKnownTypes(TransformerConfiguration cfg) { @@ -104,6 +134,38 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers ItemsRepeater = cfg.TypeSystem.GetType("Avalonia.Controls.ItemsRepeater"); ReflectionBindingExtension = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.ReflectionBindingExtension"); RelativeSource = cfg.TypeSystem.GetType("Avalonia.Data.RelativeSource"); + UInt = cfg.TypeSystem.GetType("System.UInt32"); + Int = cfg.TypeSystem.GetType("System.Int32"); + Long = cfg.TypeSystem.GetType("System.Int64"); + Uri = cfg.TypeSystem.GetType("System.Uri"); + FontFamily = cfg.TypeSystem.GetType("Avalonia.Media.FontFamily"); + FontFamilyConstructorUriName = FontFamily.GetConstructor(new List { Uri, XamlIlTypes.String }); + + (IXamlType, IXamlConstructor) GetNumericTypeInfo(string name, IXamlType componentType, int componentCount) + { + var type = cfg.TypeSystem.GetType(name); + var ctor = type.GetConstructor(Enumerable.Range(0, componentCount).Select(_ => componentType).ToList()); + + return (type, ctor); + } + + (Thickness, ThicknessFullConstructor) = GetNumericTypeInfo("Avalonia.Thickness", XamlIlTypes.Double, 4); + (Point, PointFullConstructor) = GetNumericTypeInfo("Avalonia.Point", XamlIlTypes.Double, 2); + (Vector, VectorFullConstructor) = GetNumericTypeInfo("Avalonia.Vector", XamlIlTypes.Double, 2); + (Size, SizeFullConstructor) = GetNumericTypeInfo("Avalonia.Size", XamlIlTypes.Double, 2); + (Matrix, MatrixFullConstructor) = GetNumericTypeInfo("Avalonia.Matrix", XamlIlTypes.Double, 6); + (CornerRadius, CornerRadiusFullConstructor) = GetNumericTypeInfo("Avalonia.CornerRadius", XamlIlTypes.Double, 4); + + GridLength = cfg.TypeSystem.GetType("Avalonia.Controls.GridLength"); + GridLengthConstructorValueType = GridLength.GetConstructor(new List { XamlIlTypes.Double, cfg.TypeSystem.GetType("Avalonia.Controls.GridUnitType") }); + Color = cfg.TypeSystem.GetType("Avalonia.Media.Color"); + StandardCursorType = cfg.TypeSystem.GetType("Avalonia.Input.StandardCursorType"); + Cursor = cfg.TypeSystem.GetType("Avalonia.Input.Cursor"); + CursorTypeConstructor = Cursor.GetConstructor(new List { StandardCursorType }); + ColumnDefinition = cfg.TypeSystem.GetType("Avalonia.Controls.ColumnDefinition"); + ColumnDefinitions = cfg.TypeSystem.GetType("Avalonia.Controls.ColumnDefinitions"); + RowDefinition = cfg.TypeSystem.GetType("Avalonia.Controls.RowDefinition"); + RowDefinitions = cfg.TypeSystem.GetType("Avalonia.Controls.RowDefinitions"); } } diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/XamlIlBindingPathHelper.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/XamlIlBindingPathHelper.cs index 03ec32b9cf..1974dfe3bc 100644 --- a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/XamlIlBindingPathHelper.cs +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/XamlIlBindingPathHelper.cs @@ -203,6 +203,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions .ParentNodes() .OfType() .Where(x => styledElementType.IsAssignableFrom(x.Type.GetClrType())) + .Skip(1) .ElementAtOrDefault(ancestor.Level) ?.Type.GetClrType(); @@ -242,6 +243,16 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions case RawSourceBindingExpressionNode rawSource: nodes.Add(new RawSourcePathElementNode(rawSource.RawSource)); break; + case BindingExpressionGrammar.TypeCastNode typeCastNode: + var castType = GetType(typeCastNode.Namespace, typeCastNode.TypeName); + + if (castType is null) + { + throw new XamlX.XamlParseException($"Unable to resolve cast to type {typeCastNode.Namespace}:{typeCastNode.TypeName} based on XAML tree.", lineInfo); + } + + nodes.Add(new TypeCastPathElementNode(castType)); + break; } } @@ -422,7 +433,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions { codeGen.Ldtype(Type) .Ldc_I4(_level) - .EmitCall(context.GetAvaloniaTypes().CompiledBindingPathBuilder.FindMethod(m => m.Name == "FindAncestor")); + .EmitCall(context.GetAvaloniaTypes().CompiledBindingPathBuilder.FindMethod(m => m.Name == "Ancestor")); } } @@ -608,10 +619,10 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions private readonly IXamlAstValueNode _rawSource; public RawSourcePathElementNode(IXamlAstValueNode rawSource) - :base(rawSource) + : base(rawSource) { _rawSource = rawSource; - + } public IXamlType Type => _rawSource.Type.GetClrType(); @@ -625,6 +636,21 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions } } + class TypeCastPathElementNode : IXamlIlBindingPathElementNode + { + public TypeCastPathElementNode(IXamlType ancestorType) + { + Type = ancestorType; + } + + public IXamlType Type { get; } + + public void Emit(XamlIlEmitContext context, IXamlILEmitter codeGen) + { + codeGen.EmitCall(context.GetAvaloniaTypes().CompiledBindingPathBuilder.FindMethod(m => m.Name == "TypeCast").MakeGenericMethod(new[] { Type })); + } + } + class XamlIlBindingPathNode : XamlAstNode, IXamlIlBindingPathNode, IXamlAstEmitableNode { private readonly List _transformElements; diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/xamlil.github b/src/Markup/Avalonia.Markup.Xaml.Loader/xamlil.github index 7d15a92274..ea80a607c5 160000 --- a/src/Markup/Avalonia.Markup.Xaml.Loader/xamlil.github +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/xamlil.github @@ -1 +1 @@ -Subproject commit 7d15a9227461cf4d62bc2ed251fcc25c96b28aaf +Subproject commit ea80a607c5e9d8f000160dbbb48c27ed4cfafbc9 diff --git a/src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt b/src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt deleted file mode 100644 index c87dcacda4..0000000000 --- a/src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt +++ /dev/null @@ -1,4 +0,0 @@ -Compat issues with assembly Avalonia.Markup.Xaml: -MembersMustExist : Member 'public Avalonia.Data.Binding Avalonia.Markup.Xaml.Templates.TreeDataTemplate.ItemsSource.get()' does not exist in the implementation but it does exist in the contract. -MembersMustExist : Member 'public void Avalonia.Markup.Xaml.Templates.TreeDataTemplate.ItemsSource.set(Avalonia.Data.Binding)' does not exist in the implementation but it does exist in the contract. -Total Issues: 2 diff --git a/src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj b/src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj index 44a082e2df..217da2d50d 100644 --- a/src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj +++ b/src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj @@ -1,7 +1,7 @@  netstandard2.0 - PCL;NETSTANDARD;NETSTANDARD2_0;HAS_TYPE_CONVERTER;HAS_CUSTOM_ATTRIBUTE_PROVIDER;XAMLX_INTERNAL + $(DefineConstants);PCL;NETSTANDARD;NETSTANDARD2_0;HAS_TYPE_CONVERTER;HAS_CUSTOM_ATTRIBUTE_PROVIDER;XAMLX_INTERNAL false $(DefineConstants);RUNTIME_XAML_CECIL False @@ -23,6 +23,7 @@ + diff --git a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/CompiledBindingExtension.cs b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/CompiledBindingExtension.cs index aab733cb43..17d2ea7ae9 100644 --- a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/CompiledBindingExtension.cs +++ b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/CompiledBindingExtension.cs @@ -26,10 +26,13 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions { Path = Path, Converter = Converter, + ConverterParameter = ConverterParameter, + TargetNullValue = TargetNullValue, FallbackValue = FallbackValue, Mode = Mode, Priority = Priority, StringFormat = StringFormat, + Source = Source, DefaultAnchor = new WeakReference(GetDefaultAnchor(provider)) }; } @@ -50,6 +53,13 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions protected override ExpressionObserver CreateExpressionObserver(IAvaloniaObject target, AvaloniaProperty targetProperty, object anchor, bool enableDataValidation) { + if (Source != null) + { + return CreateSourceObserver( + Source, + Path.BuildExpression(enableDataValidation)); + } + if (Path.RawSource != null) { return CreateSourceObserver( @@ -75,5 +85,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions [ConstructorArgument("path")] public CompiledBindingPath Path { get; set; } + + public object Source { get; set; } } } diff --git a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/CompiledBindings/CompiledBindingPath.cs b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/CompiledBindings/CompiledBindingPath.cs index d627fe3cd3..f6636664c1 100644 --- a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/CompiledBindings/CompiledBindingPath.cs +++ b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/CompiledBindings/CompiledBindingPath.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Avalonia.Controls; using Avalonia.Data.Core; using Avalonia.Data.Core.Plugins; @@ -53,6 +54,9 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings case IStronglyTypedStreamElement stream: node = new StreamNode(stream.CreatePlugin()); break; + case ITypeCastElement typeCast: + node = new StrongTypeCastNode(typeCast.Type, typeCast.Cast); + break; default: throw new InvalidOperationException($"Unknown binding path element type {element.GetType().FullName}"); } @@ -66,6 +70,9 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings internal SourceMode SourceMode => _elements.Count > 0 && _elements[0] is IControlSourceBindingPathElement ? SourceMode.Control : SourceMode.Data; internal object RawSource { get; } + + public override string ToString() + => string.Concat(_elements.Select(e => e.ToString())); } public class CompiledBindingPathBuilder @@ -126,6 +133,12 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings return this; } + public CompiledBindingPathBuilder TypeCast() + { + _elements.Add(new TypeCastPathElement()); + return this; + } + public CompiledBindingPathBuilder SetRawSource(object rawSource) { _rawSource = rawSource; @@ -157,6 +170,9 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings public IPropertyInfo Property { get; } public Func, IPropertyInfo, IPropertyAccessor> AccessorFactory { get; } + + public override string ToString() + => $".{Property.Name}"; } internal interface IStronglyTypedStreamElement : ICompiledBindingPathElement @@ -164,6 +180,13 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings IStreamPlugin CreatePlugin(); } + internal interface ITypeCastElement : ICompiledBindingPathElement + { + Type Type { get; } + + Func Cast { get; } + } + internal class TaskStreamPathElement : IStronglyTypedStreamElement { public static readonly TaskStreamPathElement Instance = new TaskStreamPathElement(); @@ -181,6 +204,9 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings internal class SelfPathElement : ICompiledBindingPathElement, IControlSourceBindingPathElement { public static readonly SelfPathElement Instance = new SelfPathElement(); + + public override string ToString() + => "$self"; } internal class AncestorPathElement : ICompiledBindingPathElement, IControlSourceBindingPathElement @@ -193,6 +219,9 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings public Type AncestorType { get; } public int Level { get; } + + public override string ToString() + => $"$parent[{AncestorType?.Name},{Level}]"; } internal class VisualAncestorPathElement : ICompiledBindingPathElement, IControlSourceBindingPathElement @@ -217,6 +246,9 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings public INameScope NameScope { get; } public string Name { get; } + + public override string ToString() + => $"#{Name}"; } internal class ArrayElementPathElement : ICompiledBindingPathElement @@ -229,5 +261,24 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings public int[] Indices { get; } public Type ElementType { get; } + public override string ToString() + => $"[{string.Join(",", Indices)}]"; + } + + internal class TypeCastPathElement : ITypeCastElement + { + private static object TryCast(object obj) + { + if (obj is T result) + return result; + return null; + } + + public Type Type => typeof(T); + + public Func Cast => TryCast; + + public override string ToString() + => $"({Type.FullName})"; } } diff --git a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/CompiledBindings/StrongTypeCastNode.cs b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/CompiledBindings/StrongTypeCastNode.cs new file mode 100644 index 0000000000..1252ec7eca --- /dev/null +++ b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/CompiledBindings/StrongTypeCastNode.cs @@ -0,0 +1,18 @@ +using System; +using Avalonia.Data.Core; + +namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings +{ + public class StrongTypeCastNode : TypeCastNode + { + private Func _cast; + + public StrongTypeCastNode(Type type, Func cast) : base(type) + { + _cast = cast; + } + + protected override object Cast(object value) + => _cast(value); + } +} diff --git a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/DynamicResourceExtension.cs b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/DynamicResourceExtension.cs index 03fd2e60dd..95380be65f 100644 --- a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/DynamicResourceExtension.cs +++ b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/DynamicResourceExtension.cs @@ -10,8 +10,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions { public class DynamicResourceExtension : IBinding { - private IStyledElement? _anchor; - private IResourceProvider? _resourceProvider; + private object? _anchor; public DynamicResourceExtension() { @@ -30,12 +29,9 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions if (!(provideTarget.TargetObject is IStyledElement)) { - _anchor = serviceProvider.GetFirstParent(); - - if (_anchor is null) - { - _resourceProvider = serviceProvider.GetFirstParent(); - } + _anchor = serviceProvider.GetFirstParent() ?? + serviceProvider.GetFirstParent() ?? + (object?)serviceProvider.GetFirstParent(); } return this; @@ -52,16 +48,16 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions return null; } - var control = target as IStyledElement ?? _anchor as IStyledElement; + var control = target as IResourceHost ?? _anchor as IResourceHost; if (control != null) { var source = control.GetResourceObservable(ResourceKey, GetConverter(targetProperty)); return InstancedBinding.OneWay(source); } - else if (_resourceProvider is object) + else if (_anchor is IResourceProvider resourceProvider) { - var source = _resourceProvider.GetResourceObservable(ResourceKey, GetConverter(targetProperty)); + var source = resourceProvider.GetResourceObservable(ResourceKey, GetConverter(targetProperty)); return InstancedBinding.OneWay(source); } diff --git a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/ResolveByNameExtension.cs b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/ResolveByNameExtension.cs index 8561aa898b..909462392c 100644 --- a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/ResolveByNameExtension.cs +++ b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/ResolveByNameExtension.cs @@ -30,7 +30,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions if (provideValueTarget.TargetProperty is IPropertyInfo property) value.OnCompleted(() => property.Set(target, value.GetResult())); - return null; + return AvaloniaProperty.UnsetValue; } } } diff --git a/src/Markup/Avalonia.Markup.Xaml/Properties/AssemblyInfo.cs b/src/Markup/Avalonia.Markup.Xaml/Properties/AssemblyInfo.cs index cee2b8a484..706729a5ac 100644 --- a/src/Markup/Avalonia.Markup.Xaml/Properties/AssemblyInfo.cs +++ b/src/Markup/Avalonia.Markup.Xaml/Properties/AssemblyInfo.cs @@ -5,5 +5,8 @@ using System.Runtime.CompilerServices; [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Markup.Xaml.MarkupExtensions")] [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Markup.Xaml.Styling")] [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Markup.Xaml.Templates")] +#if SIGNED_BUILD [assembly: InternalsVisibleTo("Avalonia.Markup.Xaml.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] - +#else +[assembly: InternalsVisibleTo("Avalonia.Markup.Xaml.UnitTests")] +#endif diff --git a/src/Markup/Avalonia.Markup/Data/MultiBinding.cs b/src/Markup/Avalonia.Markup/Data/MultiBinding.cs index 7aa1eed890..cbc5f414f2 100644 --- a/src/Markup/Avalonia.Markup/Data/MultiBinding.cs +++ b/src/Markup/Avalonia.Markup/Data/MultiBinding.cs @@ -48,7 +48,7 @@ namespace Avalonia.Data /// Gets or sets the binding priority. /// public BindingPriority Priority { get; set; } - + /// /// Gets or sets the relative source for the binding. /// @@ -77,12 +77,12 @@ namespace Avalonia.Data // We only respect `StringFormat` if the type of the property we're assigning to will // accept a string. Note that this is slightly different to WPF in that WPF only applies // `StringFormat` for target type `string` (not `object`). - if (!string.IsNullOrWhiteSpace(StringFormat) && + if (!string.IsNullOrWhiteSpace(StringFormat) && (targetType == typeof(string) || targetType == typeof(object))) { converter = new StringFormatMultiValueConverter(StringFormat, converter); } - + var children = Bindings.Select(x => x.Initiate(target, null)); var input = children.Select(x => x.Observable) @@ -116,7 +116,16 @@ namespace Avalonia.Data } var culture = CultureInfo.CurrentCulture; - var converted = converter.Convert(values, targetType, ConverterParameter, culture); + values = new System.Collections.ObjectModel.ReadOnlyCollection(values); + object converted; + if (converter != null) + { + converted = converter.Convert(values, targetType, ConverterParameter, culture); + } + else + { + converted = values; + } if (converted == null) { diff --git a/src/Markup/Avalonia.Markup/Markup/Parsers/BindingExpressionGrammar.cs b/src/Markup/Avalonia.Markup/Markup/Parsers/BindingExpressionGrammar.cs index 8de64e56ff..7c362e24cc 100644 --- a/src/Markup/Avalonia.Markup/Markup/Parsers/BindingExpressionGrammar.cs +++ b/src/Markup/Avalonia.Markup/Markup/Parsers/BindingExpressionGrammar.cs @@ -16,7 +16,7 @@ namespace Avalonia.Markup.Parsers internal static class BindingExpressionGrammar { - public static (IList Nodes, SourceMode Mode) Parse(ref CharacterReader r) + public static (List Nodes, SourceMode Mode) Parse(ref CharacterReader r) { var nodes = new List(); var state = State.Start; @@ -46,6 +46,10 @@ namespace Avalonia.Markup.Parsers state = ParseIndexer(ref r, nodes); break; + case State.TypeCast: + state = ParseTypeCast(ref r, nodes); + break; + case State.ElementName: state = ParseElementName(ref r, nodes); mode = SourceMode.Control; @@ -84,6 +88,11 @@ namespace Avalonia.Markup.Parsers } else if (ParseOpenBrace(ref r)) { + if (PeekOpenBrace(ref r)) + { + return State.TypeCast; + } + return State.AttachedProperty; } else if (PeekOpenBracket(ref r)) @@ -124,6 +133,10 @@ namespace Avalonia.Markup.Parsers { return State.Indexer; } + else if (ParseOpenBrace(ref r)) + { + return State.TypeCast; + } return State.End; } @@ -132,6 +145,11 @@ namespace Avalonia.Markup.Parsers { if (ParseOpenBrace(ref r)) { + if (PeekOpenBrace(ref r)) + { + return State.TypeCast; + } + return State.AttachedProperty; } else @@ -152,6 +170,12 @@ namespace Avalonia.Markup.Parsers { var (ns, owner) = ParseTypeName(ref r); + if(!r.End && r.TakeIf(')')) + { + nodes.Add(new TypeCastNode() { Namespace = ns, TypeName = owner }); + return State.AfterMember; + } + if (r.End || !r.TakeIf('.')) { throw new ExpressionParseException(r.Position, "Invalid attached property name."); @@ -159,6 +183,11 @@ namespace Avalonia.Markup.Parsers var name = r.ParseIdentifier(); + if (name.Length == 0) + { + throw new ExpressionParseException(r.Position, "Attached Property name expected after '.'."); + } + if (r.End || !r.TakeIf(')')) { throw new ExpressionParseException(r.Position, "Expected ')'."); @@ -186,6 +215,39 @@ namespace Avalonia.Markup.Parsers return State.AfterMember; } + private static State ParseTypeCast(ref CharacterReader r, List nodes) + { + bool parseMemberBeforeAddCast = ParseOpenBrace(ref r); + + var (ns, typeName) = ParseTypeName(ref r); + + var result = State.AfterMember; + + if (parseMemberBeforeAddCast) + { + if (!ParseCloseBrace(ref r)) + { + throw new ExpressionParseException(r.Position, "Expected ')'."); + } + + result = ParseBeforeMember(ref r, nodes); + + if(r.Peek == '[') + { + result = ParseIndexer(ref r, nodes); + } + } + + nodes.Add(new TypeCastNode { Namespace = ns, TypeName = typeName }); + + if (r.End || !r.TakeIf(')')) + { + throw new ExpressionParseException(r.Position, "Expected ')'."); + } + + return result; + } + private static State ParseElementName(ref CharacterReader r, List nodes) { var name = r.ParseIdentifier(); @@ -288,11 +350,21 @@ namespace Avalonia.Markup.Parsers return !r.End && r.TakeIf('('); } + private static bool ParseCloseBrace(ref CharacterReader r) + { + return !r.End && r.TakeIf(')'); + } + private static bool PeekOpenBracket(ref CharacterReader r) { return !r.End && r.Peek == '['; } + private static bool PeekOpenBrace(ref CharacterReader r) + { + return !r.End && r.Peek == '('; + } + private static bool ParseStreamOperator(ref CharacterReader r) { return !r.End && r.TakeIf('^'); @@ -322,6 +394,7 @@ namespace Avalonia.Markup.Parsers BeforeMember, AttachedProperty, Indexer, + TypeCast, End, } @@ -343,9 +416,9 @@ namespace Avalonia.Markup.Parsers } } - public interface INode {} + public interface INode { } - public interface ITransformNode {} + public interface ITransformNode { } public class EmptyExpressionNode : INode { } @@ -366,11 +439,11 @@ namespace Avalonia.Markup.Parsers public IList Arguments { get; set; } } - public class NotNode : INode, ITransformNode {} + public class NotNode : INode, ITransformNode { } - public class StreamNode : INode {} + public class StreamNode : INode { } - public class SelfNode : INode {} + public class SelfNode : INode { } public class NameNode : INode { @@ -383,5 +456,11 @@ namespace Avalonia.Markup.Parsers public string TypeName { get; set; } public int Level { get; set; } } + + public class TypeCastNode : INode + { + public string Namespace { get; set; } + public string TypeName { get; set; } + } } } diff --git a/src/Markup/Avalonia.Markup/Markup/Parsers/ExpressionParser.cs b/src/Markup/Avalonia.Markup/Markup/Parsers/ExpressionParser.cs index 1048148c1f..558130e23f 100644 --- a/src/Markup/Avalonia.Markup/Markup/Parsers/ExpressionParser.cs +++ b/src/Markup/Avalonia.Markup/Markup/Parsers/ExpressionParser.cs @@ -59,6 +59,9 @@ namespace Avalonia.Markup.Parsers case BindingExpressionGrammar.NameNode elementName: nextNode = new ElementNameNode(_nameScope, elementName.Name); break; + case BindingExpressionGrammar.TypeCastNode typeCast: + nextNode = ParseTypeCastNode(typeCast); + break; } if (rootNode is null) { @@ -92,6 +95,22 @@ namespace Avalonia.Markup.Parsers return new FindAncestorNode(ancestorType, ancestorLevel); } + private TypeCastNode ParseTypeCastNode(BindingExpressionGrammar.TypeCastNode node) + { + Type castType = null; + if (!(node.Namespace is null) && !(node.TypeName is null)) + { + if (_typeResolver == null) + { + throw new InvalidOperationException("Cannot parse a binding path with a typed Cast without a type resolver. Maybe you can use a LINQ Expression binding path instead?"); + } + + castType = _typeResolver(node.Namespace, node.TypeName); + } + + return new TypeCastNode(castType); + } + private AvaloniaPropertyAccessorNode ParseAttachedProperty(BindingExpressionGrammar.AttachedPropertyNameNode node) { if (_typeResolver == null) diff --git a/src/Markup/Avalonia.Markup/Markup/Parsers/Nodes/StringIndexerNode.cs b/src/Markup/Avalonia.Markup/Markup/Parsers/Nodes/StringIndexerNode.cs index 76fbc9a982..f3abd6a5c5 100644 --- a/src/Markup/Avalonia.Markup/Markup/Parsers/Nodes/StringIndexerNode.cs +++ b/src/Markup/Avalonia.Markup/Markup/Parsers/Nodes/StringIndexerNode.cs @@ -129,7 +129,10 @@ namespace Avalonia.Markup.Parsers.Nodes { get { - Target.TryGetTarget(out object target); + if (!Target.TryGetTarget(out object target)) + { + return null; + } return GetIndexer(target.GetType().GetTypeInfo())?.PropertyType; } diff --git a/src/Markup/Avalonia.Markup/Properties/AssemblyInfo.cs b/src/Markup/Avalonia.Markup/Properties/AssemblyInfo.cs index 3da708bc9c..ac055af98b 100644 --- a/src/Markup/Avalonia.Markup/Properties/AssemblyInfo.cs +++ b/src/Markup/Avalonia.Markup/Properties/AssemblyInfo.cs @@ -4,4 +4,8 @@ using System.Runtime.CompilerServices; [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Data")] [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Markup.Data")] +#if SIGNED_BUILD [assembly: InternalsVisibleTo("Avalonia.Markup.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] +#else +[assembly: InternalsVisibleTo("Avalonia.Markup.UnitTests")] +#endif diff --git a/src/Shared/PlatformSupport/StandardRuntimePlatform.cs b/src/Shared/PlatformSupport/StandardRuntimePlatform.cs index d574732e3d..8521a50087 100644 --- a/src/Shared/PlatformSupport/StandardRuntimePlatform.cs +++ b/src/Shared/PlatformSupport/StandardRuntimePlatform.cs @@ -49,12 +49,20 @@ namespace Avalonia.Shared.PlatformSupport public UnmanagedBlob(StandardRuntimePlatform plat, int size) { - if (size <= 0) - throw new ArgumentException("Positive number required", nameof(size)); - _plat = plat; - _address = plat.Alloc(size); - GC.AddMemoryPressure(size); - Size = size; + try + { + if (size <= 0) + throw new ArgumentException("Positive number required", nameof(size)); + _plat = plat; + _address = plat.Alloc(size); + GC.AddMemoryPressure(size); + Size = size; + } + catch + { + GC.SuppressFinalize(this); + throw; + } #if DEBUG _backtrace = Environment.StackTrace; lock (_btlock) diff --git a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs index cbc896813f..2a79a4bb50 100644 --- a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs +++ b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs @@ -36,6 +36,7 @@ namespace Avalonia.Skia private readonly SKPaint _fillPaint = new SKPaint(); private readonly SKPaint _boxShadowPaint = new SKPaint(); private static SKShader s_acrylicNoiseShader; + private readonly ISkiaGpuRenderSession _session; /// /// Context create info. @@ -76,6 +77,8 @@ namespace Avalonia.Skia /// Skia GPU provider context (optional) /// public ISkiaGpu Gpu; + + public ISkiaGpuRenderSession CurrentSession; } /// @@ -96,6 +99,8 @@ namespace Avalonia.Skia Surface = createInfo.Surface; Canvas = createInfo.Canvas ?? createInfo.Surface?.Canvas; + _session = createInfo.CurrentSession; + if (Canvas == null) { throw new ArgumentException("Invalid create info - no Canvas provided", nameof(createInfo)); @@ -429,7 +434,7 @@ namespace Avalonia.Skia /// public IDrawingContextLayerImpl CreateLayer(Size size) { - return CreateRenderTarget( size); + return CreateRenderTarget(size, true); } /// @@ -636,6 +641,23 @@ namespace Avalonia.Skia } } + break; + } + case IConicGradientBrush conicGradient: + { + var center = conicGradient.Center.ToPixels(targetSize).ToSKPoint(); + + // Skia's default is that angle 0 is from the right hand side of the center point + // but we are matching CSS where the vertical point above the center is 0. + var angle = (float)(conicGradient.Angle - 90); + var rotation = SKMatrix.CreateRotationDegrees(angle, center.X, center.Y); + + using (var shader = + SKShader.CreateSweepGradient(center, stopColors, stopOffsets, rotation)) + { + paintWrapper.Paint.Shader = shader; + } + break; } } @@ -651,7 +673,7 @@ namespace Avalonia.Skia private void ConfigureTileBrush(ref PaintWrapper paintWrapper, Size targetSize, ITileBrush tileBrush, IDrawableBitmapImpl tileBrushImage) { var calc = new TileBrushCalculator(tileBrush, tileBrushImage.PixelSize.ToSizeWithDpi(_dpi), targetSize); - var intermediate = CreateRenderTarget(calc.IntermediateSize); + var intermediate = CreateRenderTarget(calc.IntermediateSize, false); paintWrapper.AddDisposable(intermediate); @@ -726,7 +748,7 @@ namespace Avalonia.Skia if (intermediateSize.Width >= 1 && intermediateSize.Height >= 1) { - var intermediate = CreateRenderTarget(intermediateSize); + var intermediate = CreateRenderTarget(intermediateSize, false); using (var ctx = intermediate.CreateDrawingContext(visualBrushRenderer)) { @@ -956,9 +978,10 @@ namespace Avalonia.Skia /// Create new render target compatible with this drawing context. /// /// The size of the render target in DIPs. + /// Whether the render target is being created for a layer. /// Pixel format. /// - private SurfaceRenderTarget CreateRenderTarget(Size size, PixelFormat? format = null) + private SurfaceRenderTarget CreateRenderTarget(Size size, bool isLayer, PixelFormat? format = null) { var pixelSize = PixelSize.FromSizeWithDpi(size, _dpi); var createInfo = new SurfaceRenderTarget.CreateInfo @@ -969,7 +992,9 @@ namespace Avalonia.Skia Format = format, DisableTextLcdRendering = !_canTextUseLcdRendering, GrContext = _grContext, - Gpu = _gpu + Gpu = _gpu, + Session = _session, + DisableManualFbo = !isLayer, }; return new SurfaceRenderTarget(createInfo); diff --git a/src/Skia/Avalonia.Skia/FontManagerImpl.cs b/src/Skia/Avalonia.Skia/FontManagerImpl.cs index 62ec39346a..178ee8c544 100644 --- a/src/Skia/Avalonia.Skia/FontManagerImpl.cs +++ b/src/Skia/Avalonia.Skia/FontManagerImpl.cs @@ -109,20 +109,23 @@ namespace Avalonia.Skia if (typeface.FontFamily.Key == null) { var defaultName = SKTypeface.Default.FamilyName; + var fontStyle = new SKFontStyle((SKFontStyleWeight)typeface.Weight, SKFontStyleWidth.Normal, (SKFontStyleSlant)typeface.Style); foreach (var familyName in typeface.FontFamily.FamilyNames) { - skTypeface = SKTypeface.FromFamilyName(familyName, (SKFontStyleWeight)typeface.Weight, - SKFontStyleWidth.Normal, (SKFontStyleSlant)typeface.Style); + skTypeface = _skFontManager.MatchFamily(familyName, fontStyle); - if (!skTypeface.FamilyName.Equals(familyName, StringComparison.Ordinal) && - defaultName.Equals(skTypeface.FamilyName, StringComparison.Ordinal)) + if (skTypeface is null + || (!skTypeface.FamilyName.Equals(familyName, StringComparison.Ordinal) + && defaultName.Equals(skTypeface.FamilyName, StringComparison.Ordinal))) { continue; } break; } + + skTypeface ??= _skFontManager.MatchTypeface(SKTypeface.Default, fontStyle); } else { diff --git a/src/Skia/Avalonia.Skia/Gpu/ISkiaGpu.cs b/src/Skia/Avalonia.Skia/Gpu/ISkiaGpu.cs index 869c261f1b..aa86df7c23 100644 --- a/src/Skia/Avalonia.Skia/Gpu/ISkiaGpu.cs +++ b/src/Skia/Avalonia.Skia/Gpu/ISkiaGpu.cs @@ -21,7 +21,7 @@ namespace Avalonia.Skia /// Creates an offscreen render target surface /// /// size in pixels - ISkiaSurface TryCreateSurface(PixelSize size); + ISkiaSurface TryCreateSurface(PixelSize size, ISkiaGpuRenderSession session); } public interface ISkiaSurface : IDisposable diff --git a/src/Skia/Avalonia.Skia/Gpu/ISkiaGpuRenderSession.cs b/src/Skia/Avalonia.Skia/Gpu/ISkiaGpuRenderSession.cs index a4e2bfed52..5faa6a41ec 100644 --- a/src/Skia/Avalonia.Skia/Gpu/ISkiaGpuRenderSession.cs +++ b/src/Skia/Avalonia.Skia/Gpu/ISkiaGpuRenderSession.cs @@ -22,5 +22,7 @@ namespace Avalonia.Skia /// Scaling factor. /// double ScaleFactor { get; } + + GRSurfaceOrigin SurfaceOrigin { get; } } } diff --git a/src/Skia/Avalonia.Skia/Gpu/OpenGl/FboSkiaSurface.cs b/src/Skia/Avalonia.Skia/Gpu/OpenGl/FboSkiaSurface.cs index 9ee8d698ba..8ab275df63 100644 --- a/src/Skia/Avalonia.Skia/Gpu/OpenGl/FboSkiaSurface.cs +++ b/src/Skia/Avalonia.Skia/Gpu/OpenGl/FboSkiaSurface.cs @@ -14,7 +14,7 @@ namespace Avalonia.Skia private int _texture; private static readonly bool[] TrueFalse = new[] { true, false }; - public FboSkiaSurface(GRContext grContext, IGlContext glContext, PixelSize pixelSize) + public FboSkiaSurface(GRContext grContext, IGlContext glContext, PixelSize pixelSize, GRSurfaceOrigin surfaceOrigin) { _grContext = grContext; _glContext = glContext; @@ -93,7 +93,7 @@ namespace Avalonia.Skia var target = new GRBackendRenderTarget(pixelSize.Width, pixelSize.Height, 0, 8, new GRGlFramebufferInfo((uint)_fbo, SKColorType.Rgba8888.ToGlSizedFormat())); Surface = SKSurface.Create(_grContext, target, - GRSurfaceOrigin.BottomLeft, SKColorType.Rgba8888); + surfaceOrigin, SKColorType.Rgba8888); CanBlit = gl.BlitFramebuffer != null; } diff --git a/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlRenderTarget.cs b/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlRenderTarget.cs index 6df8df9a4c..b4c5619c85 100644 --- a/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlRenderTarget.cs +++ b/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlRenderTarget.cs @@ -39,6 +39,8 @@ namespace Avalonia.Skia _backendRenderTarget = backendRenderTarget; _surface = surface; _glSession = glSession; + + SurfaceOrigin = glSession.IsYFlipped ? GRSurfaceOrigin.TopLeft : GRSurfaceOrigin.BottomLeft; } public void Dispose() { @@ -48,6 +50,8 @@ namespace Avalonia.Skia GrContext.Flush(); _glSession.Dispose(); } + + public GRSurfaceOrigin SurfaceOrigin { get; } public GRContext GrContext { get; } public SKSurface SkSurface => _surface; @@ -73,10 +77,6 @@ namespace Avalonia.Skia $"Can't create drawing context for surface with {size} size and {scaling} scaling"); } - gl.Viewport(0, 0, size.Width, size.Height); - gl.ClearStencil(0); - gl.ClearColor(0, 0, 0, 0); - gl.Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); lock (_grContext) { _grContext.ResetContext(); @@ -89,6 +89,7 @@ namespace Avalonia.Skia SKColorType.Rgba8888); success = true; + return new GlGpuSession(_grContext, renderTarget, surface, glSession); } } diff --git a/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlSkiaGpu.cs b/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlSkiaGpu.cs index c02d813e24..a393f0b64d 100644 --- a/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlSkiaGpu.cs +++ b/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlSkiaGpu.cs @@ -47,7 +47,7 @@ namespace Avalonia.Skia return null; } - public ISkiaSurface TryCreateSurface(PixelSize size) + public ISkiaSurface TryCreateSurface(PixelSize size, ISkiaGpuRenderSession session) { // Only windows platform needs our FBO trickery if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -62,7 +62,7 @@ namespace Avalonia.Skia return null; try { - var surface = new FboSkiaSurface(_grContext, _glContext, size); + var surface = new FboSkiaSurface(_grContext, _glContext, size, session?.SurfaceOrigin ?? GRSurfaceOrigin.TopLeft); _canCreateSurfaces = true; return surface; } diff --git a/src/Skia/Avalonia.Skia/Gpu/SkiaGpuRenderTarget.cs b/src/Skia/Avalonia.Skia/Gpu/SkiaGpuRenderTarget.cs index 9992c9ba8c..6626546c0c 100644 --- a/src/Skia/Avalonia.Skia/Gpu/SkiaGpuRenderTarget.cs +++ b/src/Skia/Avalonia.Skia/Gpu/SkiaGpuRenderTarget.cs @@ -33,7 +33,8 @@ namespace Avalonia.Skia Dpi = SkiaPlatform.DefaultDpi * session.ScaleFactor, VisualBrushRenderer = visualBrushRenderer, DisableTextLcdRendering = true, - Gpu = _skiaGpu + Gpu = _skiaGpu, + CurrentSession = session }; return new DrawingContextImpl(nfo, session); diff --git a/src/Skia/Avalonia.Skia/PlatformRenderInterface.cs b/src/Skia/Avalonia.Skia/PlatformRenderInterface.cs index d6f76a2c20..6d0be9f64d 100644 --- a/src/Skia/Avalonia.Skia/PlatformRenderInterface.cs +++ b/src/Skia/Avalonia.Skia/PlatformRenderInterface.cs @@ -3,6 +3,8 @@ using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Threading; + using Avalonia.Controls.Platform.Surfaces; using Avalonia.Media; using Avalonia.OpenGL; @@ -124,7 +126,8 @@ namespace Avalonia.Skia Width = size.Width, Height = size.Height, Dpi = dpi, - DisableTextLcdRendering = false + DisableTextLcdRendering = false, + DisableManualFbo = true, }; return new SurfaceRenderTarget(createInfo); @@ -165,12 +168,13 @@ namespace Avalonia.Skia LinearMetrics = true }; - private static readonly SKTextBlobBuilder s_textBlobBuilder = new SKTextBlobBuilder(); + private static readonly ThreadLocal s_textBlobBuilderThreadLocal = new ThreadLocal(() => new SKTextBlobBuilder()); /// public IGlyphRunImpl CreateGlyphRun(GlyphRun glyphRun, out double width) { var count = glyphRun.GlyphIndices.Length; + var textBlobBuilder = s_textBlobBuilderThreadLocal.Value; var glyphTypeface = (GlyphTypefaceImpl)glyphRun.GlyphTypeface.PlatformImpl; @@ -190,15 +194,15 @@ namespace Avalonia.Skia { if (glyphTypeface.IsFixedPitch) { - s_textBlobBuilder.AddRun(glyphRun.GlyphIndices.Buffer.Span, s_font); + textBlobBuilder.AddRun(glyphRun.GlyphIndices.Buffer.Span, s_font); - textBlob = s_textBlobBuilder.Build(); + textBlob = textBlobBuilder.Build(); width = glyphTypeface.GetGlyphAdvance(glyphRun.GlyphIndices[0]) * scale * glyphRun.GlyphIndices.Length; } else { - var buffer = s_textBlobBuilder.AllocateHorizontalRun(s_font, count, 0); + var buffer = textBlobBuilder.AllocateHorizontalRun(s_font, count, 0); var positions = buffer.GetPositionSpan(); @@ -218,12 +222,12 @@ namespace Avalonia.Skia buffer.SetGlyphs(glyphRun.GlyphIndices.Buffer.Span); - textBlob = s_textBlobBuilder.Build(); + textBlob = textBlobBuilder.Build(); } } else { - var buffer = s_textBlobBuilder.AllocatePositionedRun(s_font, count); + var buffer = textBlobBuilder.AllocatePositionedRun(s_font, count); var glyphPositions = buffer.GetPositionSpan(); @@ -249,7 +253,7 @@ namespace Avalonia.Skia width = currentX; - textBlob = s_textBlobBuilder.Build(); + textBlob = textBlobBuilder.Build(); } return new GlyphRunImpl(textBlob); diff --git a/src/Skia/Avalonia.Skia/Properties/AssemblyInfo.cs b/src/Skia/Avalonia.Skia/Properties/AssemblyInfo.cs index b923e3a9f6..309129ccd9 100644 --- a/src/Skia/Avalonia.Skia/Properties/AssemblyInfo.cs +++ b/src/Skia/Avalonia.Skia/Properties/AssemblyInfo.cs @@ -1,4 +1,8 @@ using System.Runtime.CompilerServices; - +#if SIGNED_BUILD [assembly: InternalsVisibleTo("Avalonia.Skia.RenderTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] [assembly: InternalsVisibleTo("Avalonia.Skia.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] +#else +[assembly: InternalsVisibleTo("Avalonia.Skia.RenderTests")] +[assembly: InternalsVisibleTo("Avalonia.Skia.UnitTests")] +#endif diff --git a/src/Skia/Avalonia.Skia/SurfaceRenderTarget.cs b/src/Skia/Avalonia.Skia/SurfaceRenderTarget.cs index 61b599a731..01b7449b64 100644 --- a/src/Skia/Avalonia.Skia/SurfaceRenderTarget.cs +++ b/src/Skia/Avalonia.Skia/SurfaceRenderTarget.cs @@ -51,7 +51,8 @@ namespace Avalonia.Skia _grContext = createInfo.GrContext; _gpu = createInfo.Gpu; - _surface = _gpu?.TryCreateSurface(PixelSize); + if (!createInfo.DisableManualFbo) + _surface = _gpu?.TryCreateSurface(PixelSize, createInfo.Session); if (_surface == null) _surface = new SkiaSurfaceWrapper(CreateSurface(createInfo.GrContext, PixelSize.Width, PixelSize.Height, createInfo.Format)); @@ -100,7 +101,7 @@ namespace Avalonia.Skia VisualBrushRenderer = visualBrushRenderer, DisableTextLcdRendering = _disableLcdRendering, GrContext = _grContext, - Gpu = _gpu + Gpu = _gpu, }; return new DrawingContextImpl(createInfo, Disposable.Create(() => Version++)); @@ -218,6 +219,10 @@ namespace Avalonia.Skia public GRContext GrContext; public ISkiaGpu Gpu; + + public ISkiaGpuRenderSession Session; + + public bool DisableManualFbo; } } } diff --git a/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs b/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs index ace658654d..136ff63f3d 100644 --- a/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs +++ b/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs @@ -423,6 +423,7 @@ namespace Avalonia.Direct2D1.Media var solidColorBrush = brush as ISolidColorBrush; var linearGradientBrush = brush as ILinearGradientBrush; var radialGradientBrush = brush as IRadialGradientBrush; + var conicGradientBrush = brush as IConicGradientBrush; var imageBrush = brush as IImageBrush; var visualBrush = brush as IVisualBrush; @@ -438,6 +439,11 @@ namespace Avalonia.Direct2D1.Media { return new RadialGradientBrushImpl(radialGradientBrush, _deviceContext, destinationSize); } + else if (conicGradientBrush != null) + { + // there is no Direct2D implementation of Conic Gradients so use Radial as a stand-in + return new SolidColorBrushImpl(conicGradientBrush, _deviceContext); + } else if (imageBrush?.Source != null) { return new ImageBrushImpl( diff --git a/src/Windows/Avalonia.Direct2D1/Media/SolidColorBrushImpl.cs b/src/Windows/Avalonia.Direct2D1/Media/SolidColorBrushImpl.cs index f93b4a2e08..fea1ca9157 100644 --- a/src/Windows/Avalonia.Direct2D1/Media/SolidColorBrushImpl.cs +++ b/src/Windows/Avalonia.Direct2D1/Media/SolidColorBrushImpl.cs @@ -16,5 +16,22 @@ namespace Avalonia.Direct2D1.Media } ); } + + /// + /// Direct2D has no ConicGradient implementation so fall back to a solid colour brush based on + /// the first gradient stop. + /// + public SolidColorBrushImpl(IConicGradientBrush brush, SharpDX.Direct2D1.DeviceContext target) + { + PlatformBrush = new SharpDX.Direct2D1.SolidColorBrush( + target, + brush?.GradientStops[0].Color.ToDirect2D() ?? new SharpDX.Mathematics.Interop.RawColor4(), + new SharpDX.Direct2D1.BrushProperties + { + Opacity = brush != null ? (float)brush.Opacity : 1.0f, + Transform = target.Transform + } + ); + } } } diff --git a/src/Windows/Avalonia.Direct2D1/Properties/AssemblyInfo.cs b/src/Windows/Avalonia.Direct2D1/Properties/AssemblyInfo.cs index 78e7b4aad6..6cc8b793c0 100644 --- a/src/Windows/Avalonia.Direct2D1/Properties/AssemblyInfo.cs +++ b/src/Windows/Avalonia.Direct2D1/Properties/AssemblyInfo.cs @@ -6,6 +6,10 @@ using Avalonia.Direct2D1; [assembly: ExportRenderingSubsystem(OperatingSystemType.WinNT, 1, "Direct2D1", typeof(Direct2D1Platform), nameof(Direct2D1Platform.Initialize), typeof(Direct2DChecker))] +#if SIGNED_BUILD [assembly: InternalsVisibleTo("Avalonia.Direct2D1.RenderTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] [assembly: InternalsVisibleTo("Avalonia.Direct2D1.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] - +#else +[assembly: InternalsVisibleTo("Avalonia.Direct2D1.RenderTests")] +[assembly: InternalsVisibleTo("Avalonia.Direct2D1.UnitTests")] +#endif diff --git a/src/Windows/Avalonia.Win32/.gitignore b/src/Windows/Avalonia.Win32/.gitignore new file mode 100644 index 0000000000..7882fa6540 --- /dev/null +++ b/src/Windows/Avalonia.Win32/.gitignore @@ -0,0 +1 @@ +*.Generated.cs diff --git a/src/Windows/Avalonia.Win32/Avalonia.Win32.csproj b/src/Windows/Avalonia.Win32/Avalonia.Win32.csproj index 7fc24d4d3d..fe5f806fbe 100644 --- a/src/Windows/Avalonia.Win32/Avalonia.Win32.csproj +++ b/src/Windows/Avalonia.Win32/Avalonia.Win32.csproj @@ -5,8 +5,11 @@ Avalonia.Win32 + - + + + diff --git a/src/Windows/Avalonia.Win32/ClipboardImpl.cs b/src/Windows/Avalonia.Win32/ClipboardImpl.cs index 7d9e0a8bd2..047b7c361f 100644 --- a/src/Windows/Avalonia.Win32/ClipboardImpl.cs +++ b/src/Windows/Avalonia.Win32/ClipboardImpl.cs @@ -12,10 +12,17 @@ namespace Avalonia.Win32 { internal class ClipboardImpl : IClipboard { + private const int OleRetryCount = 10; + private const int OleRetryDelay = 100; + private async Task OpenClipboard() { + var i = OleRetryCount; + while (!UnmanagedMethods.OpenClipboard(IntPtr.Zero)) { + if (--i == 0) + throw new TimeoutException("Timeout opening clipboard."); await Task.Delay(100); } @@ -72,20 +79,32 @@ namespace Avalonia.Win32 { Dispatcher.UIThread.VerifyAccess(); var wrapper = new DataObject(data); + var i = OleRetryCount; + while (true) { - if (UnmanagedMethods.OleSetClipboard(wrapper) == 0) + var hr = UnmanagedMethods.OleSetClipboard(wrapper); + + if (hr == 0) break; - await Task.Delay(100); + + if (--i == 0) + Marshal.ThrowExceptionForHR(hr); + + await Task.Delay(OleRetryDelay); } } public async Task GetFormatsAsync() { Dispatcher.UIThread.VerifyAccess(); + var i = OleRetryCount; + while (true) { - if (UnmanagedMethods.OleGetClipboard(out var dataObject) == 0) + var hr = UnmanagedMethods.OleGetClipboard(out var dataObject); + + if (hr == 0) { var wrapper = new OleDataObject(dataObject); var formats = wrapper.GetDataFormats().ToArray(); @@ -93,16 +112,23 @@ namespace Avalonia.Win32 return formats; } - await Task.Delay(100); + if (--i == 0) + Marshal.ThrowExceptionForHR(hr); + + await Task.Delay(OleRetryDelay); } } public async Task GetDataAsync(string format) { Dispatcher.UIThread.VerifyAccess(); + var i = OleRetryCount; + while (true) { - if (UnmanagedMethods.OleGetClipboard(out var dataObject) == 0) + var hr = UnmanagedMethods.OleGetClipboard(out var dataObject); + + if (hr == 0) { var wrapper = new OleDataObject(dataObject); var rv = wrapper.Get(format); @@ -110,7 +136,10 @@ namespace Avalonia.Win32 return rv; } - await Task.Delay(100); + if (--i == 0) + Marshal.ThrowExceptionForHR(hr); + + await Task.Delay(OleRetryDelay); } } } diff --git a/src/Windows/Avalonia.Win32/FramebufferManager.cs b/src/Windows/Avalonia.Win32/FramebufferManager.cs index 6969a49dad..699dc7c25d 100644 --- a/src/Windows/Avalonia.Win32/FramebufferManager.cs +++ b/src/Windows/Avalonia.Win32/FramebufferManager.cs @@ -1,41 +1,191 @@ using System; +using System.Threading; using Avalonia.Controls.Platform.Surfaces; using Avalonia.Platform; using Avalonia.Win32.Interop; +#nullable enable + namespace Avalonia.Win32 { - class FramebufferManager : IFramebufferPlatformSurface, IDisposable + internal class FramebufferManager : IFramebufferPlatformSurface, IDisposable { + private const int _bytesPerPixel = 4; + private const PixelFormat _format = PixelFormat.Bgra8888; + private readonly IntPtr _hwnd; - private WindowFramebuffer _fb; + private readonly object _lock; + private readonly Action _onDisposeAction; + + private FramebufferData? _framebufferData; public FramebufferManager(IntPtr hwnd) { _hwnd = hwnd; + _lock = new object(); + _onDisposeAction = DrawAndUnlock; } public ILockedFramebuffer Lock() { - UnmanagedMethods.GetClientRect(_hwnd, out var rc); + Monitor.Enter(_lock); - var width = Math.Max(1, rc.right - rc.left); - var height = Math.Max(1, rc.bottom - rc.top); + LockedFramebuffer? fb = null; - if ((_fb == null || _fb.Size.Width != width || _fb.Size.Height != height)) + try { - _fb?.Deallocate(); - _fb = null; - _fb = new WindowFramebuffer(_hwnd, new PixelSize(width, height)); - } + UnmanagedMethods.GetClientRect(_hwnd, out var rc); + + var width = Math.Max(1, rc.right - rc.left); + var height = Math.Max(1, rc.bottom - rc.top); + + if (_framebufferData is null || _framebufferData?.Size.Width != width || _framebufferData?.Size.Height != height) + { + _framebufferData?.Dispose(); + + _framebufferData = AllocateFramebufferData(width, height); + } + + var framebufferData = _framebufferData.Value; - return _fb; + return fb = new LockedFramebuffer( + framebufferData.Data.Address, framebufferData.Size, framebufferData.RowBytes, + GetCurrentDpi(), _format, _onDisposeAction); + } + finally + { + // We free the lock when for whatever reason framebuffer was not created. + // This allows for a potential retry later. + if (fb is null) + { + Monitor.Exit(_lock); + } + } } public void Dispose() { - _fb?.Deallocate(); - _fb = null; + lock (_lock) + { + _framebufferData?.Dispose(); + _framebufferData = null; + } + } + + private void DrawAndUnlock() + { + try + { + if (_framebufferData.HasValue) + DrawToWindow(_hwnd, _framebufferData.Value); + } + finally + { + Monitor.Exit(_lock); + } + } + + private Vector GetCurrentDpi() + { + if (UnmanagedMethods.ShCoreAvailable) + { + var monitor = + UnmanagedMethods.MonitorFromWindow(_hwnd, UnmanagedMethods.MONITOR.MONITOR_DEFAULTTONEAREST); + + if (UnmanagedMethods.GetDpiForMonitor( + monitor, + UnmanagedMethods.MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI, + out var dpix, + out var dpiy) == 0) + { + return new Vector(dpix, dpiy); + } + } + + return new Vector(96, 96); + } + + private static FramebufferData AllocateFramebufferData(int width, int height) + { + var bitmapBlob = AvaloniaLocator.Current.GetService().AllocBlob(width * height * _bytesPerPixel); + + return new FramebufferData(bitmapBlob, width, height); + } + + private static void DrawToDevice(FramebufferData framebufferData, IntPtr hDC, int destX = 0, int destY = 0, int srcX = 0, + int srcY = 0, int width = -1, + int height = -1) + { + if (width == -1) + width = framebufferData.Size.Width; + if (height == -1) + height = framebufferData.Size.Height; + + var bmpInfo = framebufferData.Header; + + UnmanagedMethods.SetDIBitsToDevice(hDC, destX, destY, (uint)width, (uint)height, srcX, srcY, + 0, (uint)framebufferData.Size.Height, framebufferData.Data.Address, ref bmpInfo, 0); + } + + private static bool DrawToWindow(IntPtr hWnd, FramebufferData framebufferData, int destX = 0, int destY = 0, int srcX = 0, + int srcY = 0, int width = -1, + int height = -1) + { + if (framebufferData.Data.IsDisposed) + throw new ObjectDisposedException("Framebuffer"); + + if (hWnd == IntPtr.Zero) + return false; + + var hDC = UnmanagedMethods.GetDC(hWnd); + + if (hDC == IntPtr.Zero) + return false; + + try + { + DrawToDevice(framebufferData, hDC, destX, destY, srcX, srcY, width, height); + } + finally + { + UnmanagedMethods.ReleaseDC(hWnd, hDC); + } + + return true; + } + + private readonly struct FramebufferData + { + public IUnmanagedBlob Data { get; } + + public PixelSize Size { get; } + + public int RowBytes => Size.Width * _bytesPerPixel; + + public UnmanagedMethods.BITMAPINFOHEADER Header { get; } + + public FramebufferData(IUnmanagedBlob data, int width, int height) + { + Data = data; + Size = new PixelSize(width, height); + + var header = new UnmanagedMethods.BITMAPINFOHEADER(); + header.Init(); + + header.biPlanes = 1; + header.biBitCount = _bytesPerPixel * 8; + header.Init(); + + header.biWidth = width; + header.biHeight = -height; + + Header = header; + } + + public void Dispose() + { + Data.Dispose(); + } } } } diff --git a/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs b/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs index 3b11aecc2d..287d2c49a5 100644 --- a/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs +++ b/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs @@ -466,6 +466,7 @@ namespace Avalonia.Win32.Interop WS_VSCROLL = 0x200000, WS_EX_DLGMODALFRAME = 0x00000001, WS_EX_NOPARENTNOTIFY = 0x00000004, + WS_EX_NOREDIRECTIONBITMAP = 0x00200000, WS_EX_TOPMOST = 0x00000008, WS_EX_ACCEPTFILES = 0x00000010, WS_EX_TRANSPARENT = 0x00000020, @@ -930,8 +931,8 @@ namespace Avalonia.Win32.Interop [DllImport("user32.dll", EntryPoint = "MapVirtualKeyW")] public static extern uint MapVirtualKey(uint uCode, uint uMapType); - [DllImport("user32.dll", EntryPoint = "GetMessageW")] - public static extern sbyte GetMessage(out MSG lpMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax); + [DllImport("user32.dll", EntryPoint = "GetMessageW", SetLastError = true)] + public static extern int GetMessage(out MSG lpMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax); [DllImport("user32.dll")] public static extern int GetMessageTime(); @@ -1016,6 +1017,9 @@ namespace Avalonia.Win32.Interop [DllImport("user32.dll")] public static extern bool ValidateRect(IntPtr hWnd, IntPtr lpRect); + [DllImport("user32.dll")] + public static extern bool IsWindow(IntPtr hWnd); + [DllImport("user32.dll")] public static extern bool IsWindowEnabled(IntPtr hWnd); @@ -1055,6 +1059,9 @@ namespace Avalonia.Win32.Interop [DllImport("user32.dll")] public static extern bool ScreenToClient(IntPtr hWnd, ref POINT lpPoint); + [DllImport("user32.dll", SetLastError = true)] + public static extern IntPtr GetActiveWindow(); + [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr SetActiveWindow(IntPtr hWnd); @@ -1224,6 +1231,9 @@ namespace Avalonia.Win32.Interop [DllImport("kernel32.dll", SetLastError = true)] public static extern IntPtr LoadLibrary(string fileName); + + [DllImport("kernel32.dll", SetLastError = true)] + public static extern IntPtr LoadLibraryEx(string fileName, IntPtr hFile, int flags); [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Ansi)] public static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName); @@ -1381,6 +1391,9 @@ namespace Avalonia.Win32.Interop [DllImport("dwmapi.dll")] public static extern int DwmIsCompositionEnabled(out bool enabled); + [DllImport("dwmapi.dll")] + public static extern void DwmFlush(); + [DllImport("dwmapi.dll")] public static extern bool DwmDefWindowProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam, ref IntPtr plResult); @@ -1612,6 +1625,12 @@ namespace Avalonia.Win32.Interop public int X; public int Y; } + + public struct SIZE + { + public int X; + public int Y; + } public struct RECT { diff --git a/src/Windows/Avalonia.Win32/NonPumpingSyncContext.cs b/src/Windows/Avalonia.Win32/NonPumpingSyncContext.cs new file mode 100644 index 0000000000..5577664cc4 --- /dev/null +++ b/src/Windows/Avalonia.Win32/NonPumpingSyncContext.cs @@ -0,0 +1,52 @@ +using System; +using System.Runtime.ConstrainedExecution; +using System.Threading; +using Avalonia.Threading; +using Avalonia.Utilities; +using Avalonia.Win32.Interop; + +namespace Avalonia.Win32 +{ + internal class NonPumpingSyncContext : SynchronizationContext, IDisposable + { + private readonly SynchronizationContext _inner; + + private NonPumpingSyncContext(SynchronizationContext inner) + { + _inner = inner; + SetWaitNotificationRequired(); + SetSynchronizationContext(this); + } + + public override void Post(SendOrPostCallback d, object state) => _inner.Post(d, state); + public override void Send(SendOrPostCallback d, object state) => _inner.Send(d, state); + + [PrePrepareMethod] + public override int Wait(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout) + { + return UnmanagedMethods.WaitForMultipleObjectsEx(waitHandles.Length, waitHandles, waitAll, + millisecondsTimeout, false); + } + + public void Dispose() => SetSynchronizationContext(_inner); + + public static IDisposable Use() + { + var current = Current; + if (current == null) + { + if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA) + return null; + } + if (current is NonPumpingSyncContext) + return null; + + return new NonPumpingSyncContext(current); + } + + internal class HelperImpl : NonPumpingLockHelper.IHelperImpl + { + IDisposable NonPumpingLockHelper.IHelperImpl.Use() => NonPumpingSyncContext.Use(); + } + } +} diff --git a/src/Windows/Avalonia.Win32/NonPumpingWaitProvider.cs b/src/Windows/Avalonia.Win32/NonPumpingWaitProvider.cs deleted file mode 100644 index a0160fcfbd..0000000000 --- a/src/Windows/Avalonia.Win32/NonPumpingWaitProvider.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using Avalonia.Threading; -using Avalonia.Win32.Interop; - -namespace Avalonia.Win32 -{ - internal class NonPumpingWaitProvider : AvaloniaSynchronizationContext.INonPumpingPlatformWaitProvider - { - public int Wait(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout) - { - return UnmanagedMethods.WaitForMultipleObjectsEx(waitHandles.Length, waitHandles, waitAll, - millisecondsTimeout, false); - } - } -} diff --git a/src/Windows/Avalonia.Win32/PopupImpl.cs b/src/Windows/Avalonia.Win32/PopupImpl.cs index 57da1c4d66..dd3fd1342c 100644 --- a/src/Windows/Avalonia.Win32/PopupImpl.cs +++ b/src/Windows/Avalonia.Win32/PopupImpl.cs @@ -17,8 +17,9 @@ namespace Avalonia.Win32 [ThreadStatic] private static IntPtr s_parentHandle; - public override void Show() + public override void Show(bool activate) { + // Popups are always shown non-activated. UnmanagedMethods.ShowWindow(Handle.Handle, UnmanagedMethods.ShowWindowCommand.ShowNoActivate); // We need to steal focus if it's held by a child window of our toplevel window @@ -69,7 +70,8 @@ namespace Avalonia.Win32 { UnmanagedMethods.WindowStyles style = UnmanagedMethods.WindowStyles.WS_POPUP | - UnmanagedMethods.WindowStyles.WS_CLIPSIBLINGS; + UnmanagedMethods.WindowStyles.WS_CLIPSIBLINGS | + UnmanagedMethods.WindowStyles.WS_CLIPCHILDREN; UnmanagedMethods.WindowStyles exStyle = UnmanagedMethods.WindowStyles.WS_EX_TOOLWINDOW | diff --git a/src/Windows/Avalonia.Win32/Win32GlManager.cs b/src/Windows/Avalonia.Win32/Win32GlManager.cs index 523a059e0e..e159ba3b78 100644 --- a/src/Windows/Avalonia.Win32/Win32GlManager.cs +++ b/src/Windows/Avalonia.Win32/Win32GlManager.cs @@ -1,13 +1,15 @@ +using System; using Avalonia.OpenGL; using Avalonia.OpenGL.Angle; using Avalonia.OpenGL.Egl; using Avalonia.Win32.OpenGl; +using Avalonia.Win32.WinRT.Composition; namespace Avalonia.Win32 { static class Win32GlManager { - private static bool s_attemptedToInitialize; + private static readonly Version Windows7 = new Version(6, 1); public static void Initialize() { @@ -19,9 +21,19 @@ namespace Avalonia.Win32 var wgl = WglPlatformOpenGlInterface.TryCreate(); return wgl; } - - if (opts?.AllowEglInitialization == true) - return EglPlatformOpenGlInterface.TryCreate(() => new AngleWin32EglDisplay()); + + if (opts?.AllowEglInitialization ?? Win32Platform.WindowsVersion > Windows7) + { + var egl = EglPlatformOpenGlInterface.TryCreate(() => new AngleWin32EglDisplay()); + + if (egl != null && + opts?.UseWindowsUIComposition == true) + { + WinUICompositorConnection.TryCreateAndRegister(egl); + } + + return egl; + } return null; }); diff --git a/src/Windows/Avalonia.Win32/Win32Platform.cs b/src/Windows/Avalonia.Win32/Win32Platform.cs index ebc69072fc..d92bd08d01 100644 --- a/src/Windows/Avalonia.Win32/Win32Platform.cs +++ b/src/Windows/Avalonia.Win32/Win32Platform.cs @@ -12,9 +12,12 @@ using Avalonia.Controls.Platform; using Avalonia.Input; using Avalonia.Input.Platform; using Avalonia.OpenGL; +using Avalonia.OpenGL.Egl; using Avalonia.Platform; using Avalonia.Rendering; using Avalonia.Threading; +using Avalonia.Utilities; +using Avalonia.Win32; using Avalonia.Win32.Input; using Avalonia.Win32.Interop; using static Avalonia.Win32.Interop.UnmanagedMethods; @@ -37,7 +40,9 @@ namespace Avalonia public class Win32PlatformOptions { public bool UseDeferredRendering { get; set; } = true; - public bool AllowEglInitialization { get; set; } = true; + + public bool? AllowEglInitialization { get; set; } + public bool? EnableMultitouch { get; set; } public bool OverlayPopups { get; set; } public bool UseWgl { get; set; } @@ -46,6 +51,15 @@ namespace Avalonia new GlVersion(GlProfileType.OpenGL, 4, 0), new GlVersion(GlProfileType.OpenGL, 3, 2), }; + + /// + /// Render Avalonia to a Texture inside the Windows.UI.Composition tree. + /// + /// + /// Supported on Windows 10 build 16299 and above. Ignored on other versions. + /// This is recommended if you need to use AcrylicBlur or acrylic in your applications. + /// + public bool UseWindowsUIComposition { get; set; } = true; } } @@ -100,11 +114,11 @@ namespace Avalonia.Win32 .Bind().ToConstant(s_instance) .Bind().ToSingleton() .Bind().ToConstant(s_instance) - .Bind().ToConstant(new NonPumpingWaitProvider()) + .Bind().ToConstant(new NonPumpingSyncContext.HelperImpl()) .Bind().ToConstant(new WindowsMountedVolumeInfoProvider()); Win32GlManager.Initialize(); - + _uiThread = Thread.CurrentThread; if (OleContext.Current != null) @@ -119,21 +133,34 @@ namespace Avalonia.Win32 public void ProcessMessage() { - UnmanagedMethods.MSG msg; - UnmanagedMethods.GetMessage(out msg, IntPtr.Zero, 0, 0); - UnmanagedMethods.TranslateMessage(ref msg); - UnmanagedMethods.DispatchMessage(ref msg); + + if (UnmanagedMethods.GetMessage(out var msg, IntPtr.Zero, 0, 0) > -1) + { + UnmanagedMethods.TranslateMessage(ref msg); + UnmanagedMethods.DispatchMessage(ref msg); + } + else + { + Logging.Logger.TryGet(Logging.LogEventLevel.Error, Logging.LogArea.Win32Platform) + ?.Log(this, "Unmanaged error in {0}. Error Code: {1}", nameof(ProcessMessage), Marshal.GetLastWin32Error()); + + } } public void RunLoop(CancellationToken cancellationToken) { - while (!cancellationToken.IsCancellationRequested) + var result = 0; + while (!cancellationToken.IsCancellationRequested + && (result = UnmanagedMethods.GetMessage(out var msg, IntPtr.Zero, 0, 0)) > 0) { - UnmanagedMethods.MSG msg; - UnmanagedMethods.GetMessage(out msg, IntPtr.Zero, 0, 0); UnmanagedMethods.TranslateMessage(ref msg); UnmanagedMethods.DispatchMessage(ref msg); } + if (result < 0) + { + Logging.Logger.TryGet(Logging.LogEventLevel.Error, Logging.LogArea.Win32Platform) + ?.Log(this, "Unmanaged error in {0}. Error Code: {1}", nameof(RunLoop), Marshal.GetLastWin32Error()); + } } public IDisposable StartTimer(DispatcherPriority priority, TimeSpan interval, Action callback) @@ -219,7 +246,7 @@ namespace Avalonia.Win32 public IWindowImpl CreateEmbeddableWindow() { var embedded = new EmbeddedWindowImpl(); - embedded.Show(); + embedded.Show(true); return embedded; } diff --git a/src/Windows/Avalonia.Win32/WinRT/Composition/D2DEffects.cs b/src/Windows/Avalonia.Win32/WinRT/Composition/D2DEffects.cs new file mode 100644 index 0000000000..bef5a55b06 --- /dev/null +++ b/src/Windows/Avalonia.Win32/WinRT/Composition/D2DEffects.cs @@ -0,0 +1,130 @@ +using System; + +namespace Avalonia.Win32.WinRT.Composition +{ + class D2DEffects + { + public static readonly Guid CLSID_D2D12DAffineTransform = + new Guid(0x6AA97485, 0x6354, 0x4CFC, 0x90, 0x8C, 0xE4, 0xA7, 0x4F, 0x62, 0xC9, 0x6C); + + public static readonly Guid CLSID_D2D13DPerspectiveTransform = + new Guid(0xC2844D0B, 0x3D86, 0x46E7, 0x85, 0xBA, 0x52, 0x6C, 0x92, 0x40, 0xF3, 0xFB); + + public static readonly Guid CLSID_D2D13DTransform = + new Guid(0xE8467B04, 0xEC61, 0x4B8A, 0xB5, 0xDE, 0xD4, 0xD7, 0x3D, 0xEB, 0xEA, 0x5A); + + public static readonly Guid CLSID_D2D1ArithmeticComposite = + new Guid(0xFC151437, 0x049A, 0x4784, 0xA2, 0x4A, 0xF1, 0xC4, 0xDA, 0xF2, 0x09, 0x87); + + public static readonly Guid CLSID_D2D1Atlas = + new Guid(0x913E2BE4, 0xFDCF, 0x4FE2, 0xA5, 0xF0, 0x24, 0x54, 0xF1, 0x4F, 0xF4, 0x08); + + public static readonly Guid CLSID_D2D1BitmapSource = + new Guid(0x5FB6C24D, 0xC6DD, 0x4231, 0x94, 0x4, 0x50, 0xF4, 0xD5, 0xC3, 0x25, 0x2D); + + public static readonly Guid CLSID_D2D1Blend = + new Guid(0x81C5B77B, 0x13F8, 0x4CDD, 0xAD, 0x20, 0xC8, 0x90, 0x54, 0x7A, 0xC6, 0x5D); + + public static readonly Guid CLSID_D2D1Border = + new Guid(0x2A2D49C0, 0x4ACF, 0x43C7, 0x8C, 0x6A, 0x7C, 0x4A, 0x27, 0x87, 0x4D, 0x27); + + public static readonly Guid CLSID_D2D1Brightness = + new Guid(0x8CEA8D1E, 0x77B0, 0x4986, 0xB3, 0xB9, 0x2F, 0x0C, 0x0E, 0xAE, 0x78, 0x87); + + public static readonly Guid CLSID_D2D1ColorManagement = + new Guid(0x1A28524C, 0xFDD6, 0x4AA4, 0xAE, 0x8F, 0x83, 0x7E, 0xB8, 0x26, 0x7B, 0x37); + + public static readonly Guid CLSID_D2D1ColorMatrix = + new Guid(0x921F03D6, 0x641C, 0x47DF, 0x85, 0x2D, 0xB4, 0xBB, 0x61, 0x53, 0xAE, 0x11); + + public static readonly Guid CLSID_D2D1Composite = + new Guid(0x48FC9F51, 0xF6AC, 0x48F1, 0x8B, 0x58, 0x3B, 0x28, 0xAC, 0x46, 0xF7, 0x6D); + + public static readonly Guid CLSID_D2D1ConvolveMatrix = + new Guid(0x407F8C08, 0x5533, 0x4331, 0xA3, 0x41, 0x23, 0xCC, 0x38, 0x77, 0x84, 0x3E); + + public static readonly Guid CLSID_D2D1Crop = + new Guid(0xE23F7110, 0x0E9A, 0x4324, 0xAF, 0x47, 0x6A, 0x2C, 0x0C, 0x46, 0xF3, 0x5B); + + public static readonly Guid CLSID_D2D1DirectionalBlur = + new Guid(0x174319A6, 0x58E9, 0x49B2, 0xBB, 0x63, 0xCA, 0xF2, 0xC8, 0x11, 0xA3, 0xDB); + + public static readonly Guid CLSID_D2D1DiscreteTransfer = + new Guid(0x90866FCD, 0x488E, 0x454B, 0xAF, 0x06, 0xE5, 0x04, 0x1B, 0x66, 0xC3, 0x6C); + + public static readonly Guid CLSID_D2D1DisplacementMap = + new Guid(0xEDC48364, 0x417, 0x4111, 0x94, 0x50, 0x43, 0x84, 0x5F, 0xA9, 0xF8, 0x90); + + public static readonly Guid CLSID_D2D1DistantDiffuse = + new Guid(0x3E7EFD62, 0xA32D, 0x46D4, 0xA8, 0x3C, 0x52, 0x78, 0x88, 0x9A, 0xC9, 0x54); + + public static readonly Guid CLSID_D2D1DistantSpecular = + new Guid(0x428C1EE5, 0x77B8, 0x4450, 0x8A, 0xB5, 0x72, 0x21, 0x9C, 0x21, 0xAB, 0xDA); + + public static readonly Guid CLSID_D2D1DpiCompensation = + new Guid(0x6C26C5C7, 0x34E0, 0x46FC, 0x9C, 0xFD, 0xE5, 0x82, 0x37, 0x6, 0xE2, 0x28); + + public static readonly Guid CLSID_D2D1Flood = + new Guid(0x61C23C20, 0xAE69, 0x4D8E, 0x94, 0xCF, 0x50, 0x07, 0x8D, 0xF6, 0x38, 0xF2); + + public static readonly Guid CLSID_D2D1GammaTransfer = + new Guid(0x409444C4, 0xC419, 0x41A0, 0xB0, 0xC1, 0x8C, 0xD0, 0xC0, 0xA1, 0x8E, 0x42); + + public static readonly Guid CLSID_D2D1GaussianBlur = + new Guid(0x1FEB6D69, 0x2FE6, 0x4AC9, 0x8C, 0x58, 0x1D, 0x7F, 0x93, 0xE7, 0xA6, 0xA5); + + public static readonly Guid CLSID_D2D1Scale = + new Guid(0x9DAF9369, 0x3846, 0x4D0E, 0xA4, 0x4E, 0xC, 0x60, 0x79, 0x34, 0xA5, 0xD7); + + public static readonly Guid CLSID_D2D1Histogram = + new Guid(0x881DB7D0, 0xF7EE, 0x4D4D, 0xA6, 0xD2, 0x46, 0x97, 0xAC, 0xC6, 0x6E, 0xE8); + + public static readonly Guid CLSID_D2D1HueRotation = + new Guid(0x0F4458EC, 0x4B32, 0x491B, 0x9E, 0x85, 0xBD, 0x73, 0xF4, 0x4D, 0x3E, 0xB6); + + public static readonly Guid CLSID_D2D1LinearTransfer = + new Guid(0xAD47C8FD, 0x63EF, 0x4ACC, 0x9B, 0x51, 0x67, 0x97, 0x9C, 0x03, 0x6C, 0x06); + + public static readonly Guid CLSID_D2D1LuminanceToAlpha = + new Guid(0x41251AB7, 0x0BEB, 0x46F8, 0x9D, 0xA7, 0x59, 0xE9, 0x3F, 0xCC, 0xE5, 0xDE); + + public static readonly Guid CLSID_D2D1Morphology = + new Guid(0xEAE6C40D, 0x626A, 0x4C2D, 0xBF, 0xCB, 0x39, 0x10, 0x01, 0xAB, 0xE2, 0x02); + + public static readonly Guid CLSID_D2D1OpacityMetadata = + new Guid(0x6C53006A, 0x4450, 0x4199, 0xAA, 0x5B, 0xAD, 0x16, 0x56, 0xFE, 0xCE, 0x5E); + + public static readonly Guid CLSID_D2D1PointDiffuse = + new Guid(0xB9E303C3, 0xC08C, 0x4F91, 0x8B, 0x7B, 0x38, 0x65, 0x6B, 0xC4, 0x8C, 0x20); + + public static readonly Guid CLSID_D2D1PointSpecular = + new Guid(0x09C3CA26, 0x3AE2, 0x4F09, 0x9E, 0xBC, 0xED, 0x38, 0x65, 0xD5, 0x3F, 0x22); + + public static readonly Guid CLSID_D2D1Premultiply = + new Guid(0x06EAB419, 0xDEED, 0x4018, 0x80, 0xD2, 0x3E, 0x1D, 0x47, 0x1A, 0xDE, 0xB2); + + public static readonly Guid CLSID_D2D1Saturation = + new Guid(0x5CB2D9CF, 0x327D, 0x459F, 0xA0, 0xCE, 0x40, 0xC0, 0xB2, 0x08, 0x6B, 0xF7); + + public static readonly Guid CLSID_D2D1Shadow = + new Guid(0xC67EA361, 0x1863, 0x4E69, 0x89, 0xDB, 0x69, 0x5D, 0x3E, 0x9A, 0x5B, 0x6B); + + public static readonly Guid CLSID_D2D1SpotDiffuse = + new Guid(0x818A1105, 0x7932, 0x44F4, 0xAA, 0x86, 0x08, 0xAE, 0x7B, 0x2F, 0x2C, 0x93); + + public static readonly Guid CLSID_D2D1SpotSpecular = + new Guid(0xEDAE421E, 0x7654, 0x4A37, 0x9D, 0xB8, 0x71, 0xAC, 0xC1, 0xBE, 0xB3, 0xC1); + + public static readonly Guid CLSID_D2D1TableTransfer = + new Guid(0x5BF818C3, 0x5E43, 0x48CB, 0xB6, 0x31, 0x86, 0x83, 0x96, 0xD6, 0xA1, 0xD4); + + public static readonly Guid CLSID_D2D1Tile = + new Guid(0xB0784138, 0x3B76, 0x4BC5, 0xB1, 0x3B, 0x0F, 0xA2, 0xAD, 0x02, 0x65, 0x9F); + + public static readonly Guid CLSID_D2D1Turbulence = + new Guid(0xCF2BB6AE, 0x889A, 0x4AD7, 0xBA, 0x29, 0xA2, 0xFD, 0x73, 0x2C, 0x9F, 0xC9); + + public static readonly Guid CLSID_D2D1UnPremultiply = + new Guid(0xFB9AC489, 0xAD8D, 0x41ED, 0x99, 0x99, 0xBB, 0x63, 0x47, 0xD1, 0x10, 0xF7); + } +} diff --git a/src/Windows/Avalonia.Win32/WinRT/Composition/WinUICompositedWindow.cs b/src/Windows/Avalonia.Win32/WinRT/Composition/WinUICompositedWindow.cs new file mode 100644 index 0000000000..4ae9c08410 --- /dev/null +++ b/src/Windows/Avalonia.Win32/WinRT/Composition/WinUICompositedWindow.cs @@ -0,0 +1,99 @@ +using System; +using System.Numerics; +using System.Reactive.Disposables; +using System.Threading; +using Avalonia.MicroCom; +using Avalonia.OpenGL; +using Avalonia.OpenGL.Egl; +using Avalonia.Win32.Interop; + +namespace Avalonia.Win32.WinRT.Composition +{ + public class WinUICompositedWindow : IDisposable + { + private EglContext _syncContext; + private readonly object _pumpLock; + private readonly IVisual _blurVisual; + private ICompositionTarget _compositionTarget; + private IVisual _contentVisual; + private ICompositionDrawingSurfaceInterop _surfaceInterop; + private PixelSize _size; + + private static Guid IID_ID3D11Texture2D = Guid.Parse("6f15aaf2-d208-4e89-9ab4-489535d34f9c"); + private ICompositor _compositor; + + + internal WinUICompositedWindow(EglContext syncContext, + ICompositor compositor, + object pumpLock, + ICompositionTarget compositionTarget, + ICompositionDrawingSurfaceInterop surfaceInterop, + IVisual contentVisual, IVisual blurVisual) + { + _compositor = compositor.CloneReference(); + _syncContext = syncContext; + _pumpLock = pumpLock; + _blurVisual = blurVisual.CloneReference(); + _compositionTarget = compositionTarget.CloneReference(); + _contentVisual = contentVisual.CloneReference(); + _surfaceInterop = surfaceInterop.CloneReference(); + } + + + public void ResizeIfNeeded(PixelSize size) + { + using (_syncContext.EnsureLocked()) + { + if (_size != size) + { + _surfaceInterop.Resize(new UnmanagedMethods.POINT { X = size.Width, Y = size.Height }); + _contentVisual.SetSize(new Vector2(size.Width, size.Height)); + _size = size; + } + } + } + + public unsafe IUnknown BeginDrawToTexture(out PixelPoint offset) + { + if (!_syncContext.IsCurrent) + throw new InvalidOperationException(); + + var iid = IID_ID3D11Texture2D; + void* pTexture; + var off = _surfaceInterop.BeginDraw(null, &iid, &pTexture); + offset = new PixelPoint(off.X, off.Y); + return MicroComRuntime.CreateProxyFor(pTexture, true); + } + + public void EndDraw() + { + if (!_syncContext.IsCurrent) + throw new InvalidOperationException(); + _surfaceInterop.EndDraw(); + } + + public void SetBlur(bool enable) + { + using (_syncContext.EnsureLocked()) + _blurVisual.SetIsVisible(enable ? 1 : 0); + } + + public IDisposable BeginTransaction() + { + Monitor.Enter(_pumpLock); + return Disposable.Create(() => Monitor.Exit(_pumpLock)); + } + + public void Dispose() + { + if (_syncContext == null) + { + _compositor.Dispose(); + _blurVisual.Dispose(); + _contentVisual.Dispose(); + _surfaceInterop.Dispose(); + _compositionTarget.Dispose(); + } + } + } +} diff --git a/src/Windows/Avalonia.Win32/WinRT/Composition/WinUICompositorConnection.cs b/src/Windows/Avalonia.Win32/WinRT/Composition/WinUICompositorConnection.cs new file mode 100644 index 0000000000..2aa82436f6 --- /dev/null +++ b/src/Windows/Avalonia.Win32/WinRT/Composition/WinUICompositorConnection.cs @@ -0,0 +1,238 @@ +using System; +using System.Diagnostics; +using System.Numerics; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; +using Avalonia.Logging; +using Avalonia.MicroCom; +using Avalonia.OpenGL; +using Avalonia.OpenGL.Angle; +using Avalonia.OpenGL.Egl; +using Avalonia.Rendering; +using Avalonia.Win32.Interop; + +namespace Avalonia.Win32.WinRT.Composition +{ + class WinUICompositorConnection : IRenderTimer + { + private readonly EglContext _syncContext; + private IntPtr _queue; + private ICompositor _compositor; + private ICompositor2 _compositor2; + private ICompositor5 _compositor5; + private ICompositorInterop _compositorInterop; + private AngleWin32EglDisplay _angle; + private ICompositionGraphicsDevice _device; + private EglPlatformOpenGlInterface _gl; + private ICompositorDesktopInterop _compositorDesktopInterop; + private ICompositionBrush _blurBrush; + private object _pumpLock = new object(); + + public WinUICompositorConnection(EglPlatformOpenGlInterface gl, object pumpLock) + { + _gl = gl; + _pumpLock = pumpLock; + _syncContext = _gl.PrimaryEglContext; + _angle = (AngleWin32EglDisplay)_gl.Display; + _compositor = NativeWinRTMethods.CreateInstance("Windows.UI.Composition.Compositor"); + _compositor2 = _compositor.QueryInterface(); + _compositor5 = _compositor.QueryInterface(); + _compositorInterop = _compositor.QueryInterface(); + _compositorDesktopInterop = _compositor.QueryInterface(); + using var device = MicroComRuntime.CreateProxyFor(_angle.GetDirect3DDevice(), true); + + _device = _compositorInterop.CreateGraphicsDevice(device); + _blurBrush = CreateBlurBrush(); + + } + + public EglPlatformOpenGlInterface Egl => _gl; + + static bool TryCreateAndRegisterCore(EglPlatformOpenGlInterface angle) + { + var tcs = new TaskCompletionSource(); + var pumpLock = new object(); + var th = new Thread(() => + { + WinUICompositorConnection connect; + try + { + NativeWinRTMethods.CreateDispatcherQueueController(new NativeWinRTMethods.DispatcherQueueOptions + { + apartmentType = NativeWinRTMethods.DISPATCHERQUEUE_THREAD_APARTMENTTYPE.DQTAT_COM_NONE, + dwSize = Marshal.SizeOf(), + threadType = NativeWinRTMethods.DISPATCHERQUEUE_THREAD_TYPE.DQTYPE_THREAD_CURRENT + }); + connect = new WinUICompositorConnection(angle, pumpLock); + AvaloniaLocator.CurrentMutable.BindToSelf(connect); + AvaloniaLocator.CurrentMutable.Bind().ToConstant(connect); + tcs.SetResult(true); + + } + catch (Exception e) + { + tcs.SetException(e); + return; + } + connect.RunLoop(); + }) + { + IsBackground = true + }; + th.SetApartmentState(ApartmentState.STA); + th.Start(); + return tcs.Task.Result; + } + + class RunLoopHandler : IAsyncActionCompletedHandler, IMicroComShadowContainer + { + private readonly WinUICompositorConnection _parent; + private Stopwatch _st = Stopwatch.StartNew(); + + public RunLoopHandler(WinUICompositorConnection parent) + { + _parent = parent; + } + public void Dispose() + { + + } + + public void Invoke(IAsyncAction asyncInfo, AsyncStatus asyncStatus) + { + _parent.Tick?.Invoke(_st.Elapsed); + using var act = _parent._compositor5.RequestCommitAsync(); + act.SetCompleted(this); + } + + public MicroComShadow Shadow { get; set; } + public void OnReferencedFromNative() + { + } + + public void OnUnreferencedFromNative() + { + } + } + + private void RunLoop() + { + { + var st = Stopwatch.StartNew(); + using (var act = _compositor5.RequestCommitAsync()) + act.SetCompleted(new RunLoopHandler(this)); + while (true) + { + UnmanagedMethods.GetMessage(out var msg, IntPtr.Zero, 0, 0); + lock (_pumpLock) + UnmanagedMethods.DispatchMessage(ref msg); + } + } + } + + public static void TryCreateAndRegister(EglPlatformOpenGlInterface angle) + { + const int majorRequired = 10; + const int buildRequired = 17134; + + var majorInstalled = Win32Platform.WindowsVersion.Major; + var buildInstalled = Win32Platform.WindowsVersion.Build; + + if (majorInstalled >= majorRequired && + buildInstalled >= buildRequired) + { + try + { + TryCreateAndRegisterCore(angle); + } + catch (Exception e) + { + Logger.TryGet(LogEventLevel.Error, "WinUIComposition") + ?.Log(null, "Unable to initialize WinUI compositor: {0}", e); + + } + } + + var osVersionNotice = + $"Windows {majorRequired} Build {buildRequired} is required. Your machine has Windows {majorInstalled} Build {buildInstalled} installed."; + + Logger.TryGet(LogEventLevel.Warning, "WinUIComposition")?.Log(null, + $"Unable to initialize WinUI compositor: {osVersionNotice}"); + } + + + public WinUICompositedWindow CreateWindow(IntPtr hWnd) + { + using var sc = _syncContext.EnsureLocked(); + using var desktopTarget = _compositorDesktopInterop.CreateDesktopWindowTarget(hWnd, 0); + using var target = desktopTarget.QueryInterface(); + + using var drawingSurface = _device.CreateDrawingSurface(new UnmanagedMethods.SIZE(), DirectXPixelFormat.B8G8R8A8UIntNormalized, + DirectXAlphaMode.Premultiplied); + using var surface = drawingSurface.QueryInterface(); + using var surfaceInterop = drawingSurface.QueryInterface(); + + using var surfaceBrush = _compositor.CreateSurfaceBrushWithSurface(surface); + using var brush = surfaceBrush.QueryInterface(); + + using var spriteVisual = _compositor.CreateSpriteVisual(); + spriteVisual.SetBrush(brush); + using var visual = spriteVisual.QueryInterface(); + using var visual2 = spriteVisual.QueryInterface(); + using var container = _compositor.CreateContainerVisual(); + using var containerVisual = container.QueryInterface(); + using var containerVisual2 = container.QueryInterface(); + containerVisual2.SetRelativeSizeAdjustment(new Vector2(1, 1)); + using var containerChildren = container.Children; + + target.SetRoot(containerVisual); + + using var blur = CreateBlurVisual(); + + containerChildren.InsertAtTop(blur); + containerChildren.InsertAtTop(visual); + + return new WinUICompositedWindow(_syncContext, _compositor, _pumpLock, target, surfaceInterop, visual, blur); + } + + + private unsafe ICompositionBrush CreateBlurBrush() + { + using var backDropParameterFactory = NativeWinRTMethods.CreateActivationFactory( + "Windows.UI.Composition.CompositionEffectSourceParameter"); + using var backdropString = new HStringInterop("backdrop"); + using var backDropParameter = + backDropParameterFactory.Create(backdropString.Handle); + using var backDropParameterAsSource = backDropParameter.QueryInterface(); + var blurEffect = new WinUIGaussianBlurEffect(backDropParameterAsSource); + using var blurEffectFactory = _compositor.CreateEffectFactory(blurEffect); + using var backdrop = _compositor2.CreateBackdropBrush(); + using var backdropBrush = backdrop.QueryInterface(); + + + var saturateEffect = new SaturationEffect(blurEffect); + using var satEffectFactory = _compositor.CreateEffectFactory(saturateEffect); + using var sat = satEffectFactory.CreateBrush(); + sat.SetSourceParameter(backdropString.Handle, backdropBrush); + return sat.QueryInterface(); + } + + private unsafe IVisual CreateBlurVisual() + { + using var spriteVisual = _compositor.CreateSpriteVisual(); + using var visual = spriteVisual.QueryInterface(); + using var visual2 = spriteVisual.QueryInterface(); + + + spriteVisual.SetBrush(_blurBrush); + visual.SetIsVisible(0); + visual2.SetRelativeSizeAdjustment(new Vector2(1.0f, 1.0f)); + + return visual.CloneReference(); + } + + + public event Action Tick; + } +} diff --git a/src/Windows/Avalonia.Win32/WinRT/Composition/WinUIEffectBase.cs b/src/Windows/Avalonia.Win32/WinRT/Composition/WinUIEffectBase.cs new file mode 100644 index 0000000000..ea75a2f311 --- /dev/null +++ b/src/Windows/Avalonia.Win32/WinRT/Composition/WinUIEffectBase.cs @@ -0,0 +1,135 @@ +using System; +using System.Linq; +using System.Runtime.InteropServices; +using Avalonia.MicroCom; + +namespace Avalonia.Win32.WinRT.Composition +{ + abstract class WinUIEffectBase : WinRTInspectable, IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private IGraphicsEffectSource[] _sources; + + public WinUIEffectBase(params IGraphicsEffectSource[] _sources) + { + this._sources = _sources.Select(e => + { + if (e is WinUIEffectBase) + return e; + return e.CloneReference(); + }).ToArray(); + } + + public IntPtr Name => IntPtr.Zero; + + public void SetName(IntPtr name) + { + + } + + public abstract Guid EffectId { get; } + public unsafe void GetNamedPropertyMapping(IntPtr name, uint* index, GRAPHICS_EFFECT_PROPERTY_MAPPING* mapping) => + throw new COMException("Not supported", unchecked((int)0x80004001)); + + public abstract uint PropertyCount { get; } + public abstract IPropertyValue GetProperty(uint index); + + public IGraphicsEffectSource GetSource(uint index) + { + if (_sources == null || index> _sources.Length) + throw new COMException("Invalid index", unchecked((int)0x80070057)); + return _sources[index]; + } + + public uint SourceCount => (uint)(_sources?.Length ?? 0); + + public override void OnUnreferencedFromNative() + { + if (_sources == null) + return; + + /*foreach(var s in _sources) + s.Dispose();*/ + _sources = null; + } + } + + class WinUIGaussianBlurEffect : WinUIEffectBase + { + public WinUIGaussianBlurEffect(IGraphicsEffectSource source) : base(source) + { + } + + enum D2D1_GAUSSIANBLUR_OPTIMIZATION + { + D2D1_GAUSSIANBLUR_OPTIMIZATION_SPEED, + D2D1_GAUSSIANBLUR_OPTIMIZATION_BALANCED, + D2D1_GAUSSIANBLUR_OPTIMIZATION_QUALITY, + D2D1_GAUSSIANBLUR_OPTIMIZATION_FORCE_DWORD + }; + + enum D2D1_BORDER_MODE + { + D2D1_BORDER_MODE_SOFT, + D2D1_BORDER_MODE_HARD, + D2D1_BORDER_MODE_FORCE_DWORD + }; + + enum D2D1GaussianBlurProp + { + D2D1_GAUSSIANBLUR_PROP_STANDARD_DEVIATION, + D2D1_GAUSSIANBLUR_PROP_OPTIMIZATION, + D2D1_GAUSSIANBLUR_PROP_BORDER_MODE, + D2D1_GAUSSIANBLUR_PROP_FORCE_DWORD + }; + + public override Guid EffectId => D2DEffects.CLSID_D2D1GaussianBlur; + + public override uint PropertyCount => 3; + + public override IPropertyValue GetProperty(uint index) + { + switch ((D2D1GaussianBlurProp)index) + { + case D2D1GaussianBlurProp.D2D1_GAUSSIANBLUR_PROP_STANDARD_DEVIATION: + return new WinRTPropertyValue(30.0f); + + case D2D1GaussianBlurProp.D2D1_GAUSSIANBLUR_PROP_OPTIMIZATION: + return new WinRTPropertyValue((uint)D2D1_GAUSSIANBLUR_OPTIMIZATION + .D2D1_GAUSSIANBLUR_OPTIMIZATION_BALANCED); + + case D2D1GaussianBlurProp.D2D1_GAUSSIANBLUR_PROP_BORDER_MODE: + return new WinRTPropertyValue((uint)D2D1_BORDER_MODE.D2D1_BORDER_MODE_HARD); + } + + return null; + } + } + + class SaturationEffect : WinUIEffectBase + { + public SaturationEffect(IGraphicsEffectSource source) : base(source) + { + } + + enum D2D1_SATURATION_PROP + { + D2D1_SATURATION_PROP_SATURATION, + D2D1_SATURATION_PROP_FORCE_DWORD + }; + + public override Guid EffectId => D2DEffects.CLSID_D2D1Saturation; + + public override uint PropertyCount => 1; + + public override IPropertyValue GetProperty(uint index) + { + switch ((D2D1_SATURATION_PROP)index) + { + case D2D1_SATURATION_PROP.D2D1_SATURATION_PROP_SATURATION: + return new WinRTPropertyValue(2.0f); + } + + return null; + } + } +} diff --git a/src/Windows/Avalonia.Win32/WinRT/Composition/WinUiCompositedWindowSurface.cs b/src/Windows/Avalonia.Win32/WinRT/Composition/WinUiCompositedWindowSurface.cs new file mode 100644 index 0000000000..f59d50860a --- /dev/null +++ b/src/Windows/Avalonia.Win32/WinRT/Composition/WinUiCompositedWindowSurface.cs @@ -0,0 +1,118 @@ +using System; +using System.Runtime.InteropServices; +using Avalonia.MicroCom; +using Avalonia.OpenGL.Angle; +using Avalonia.OpenGL.Egl; +using Avalonia.OpenGL.Surfaces; +using Avalonia.Utilities; +using Avalonia.Win32.Interop; + +namespace Avalonia.Win32.WinRT.Composition +{ + internal class WinUiCompositedWindowSurface : EglGlPlatformSurfaceBase, IBlurHost, IDisposable + { + private readonly WinUICompositorConnection _connection; + private EglPlatformOpenGlInterface _egl; + private readonly EglGlPlatformSurfaceBase.IEglWindowGlPlatformSurfaceInfo _info; + private IRef _window; + private bool _enableBlur; + + public WinUiCompositedWindowSurface(WinUICompositorConnection connection, IEglWindowGlPlatformSurfaceInfo info) : base() + { + _connection = connection; + _egl = connection.Egl; + _info = info; + } + + public override IGlPlatformSurfaceRenderTarget CreateGlRenderTarget() + { + using (_egl.PrimaryContext.EnsureCurrent()) + { + if (_window?.Item == null) + { + _window = RefCountable.Create(_connection.CreateWindow(_info.Handle)); + _window.Item.SetBlur(_enableBlur); + } + + return new CompositionRenderTarget(_egl, _window, _info); + } + } + + class CompositionRenderTarget : EglPlatformSurfaceRenderTargetBase + { + private readonly EglPlatformOpenGlInterface _egl; + private readonly IRef _window; + private readonly IEglWindowGlPlatformSurfaceInfo _info; + + public CompositionRenderTarget(EglPlatformOpenGlInterface egl, + IRef window, + IEglWindowGlPlatformSurfaceInfo info) + : base(egl) + { + _egl = egl; + _window = window.Clone(); + _info = info; + _window.Item.ResizeIfNeeded(_info.Size); + } + + public override IGlPlatformSurfaceRenderingSession BeginDraw() + { + var contextLock = _egl.PrimaryEglContext.EnsureCurrent(); + IUnknown texture = null; + EglSurface surface = null; + IDisposable transaction = null; + var success = false; + try + { + if (_window?.Item == null) + throw new ObjectDisposedException(GetType().FullName); + + var size = _info.Size; + transaction = _window.Item.BeginTransaction(); + _window.Item.ResizeIfNeeded(size); + texture = _window.Item.BeginDrawToTexture(out var offset); + + surface = ((AngleWin32EglDisplay) _egl.Display).WrapDirect3D11Texture(_egl, + texture.GetNativeIntPtr(), + offset.X, offset.Y, size.Width, size.Height); + + var res = base.BeginDraw(surface, _info, () => + { + surface?.Dispose(); + texture?.Dispose(); + _window.Item.EndDraw(); + transaction?.Dispose(); + contextLock?.Dispose(); + }, true); + success = true; + return res; + } + finally + { + if (!success) + { + surface?.Dispose(); + texture?.Dispose(); + transaction?.Dispose(); + contextLock.Dispose(); + } + } + } + } + + public void SetBlur(bool enable) + { + _enableBlur = enable; + _window?.Item?.SetBlur(enable); + } + + public void Dispose() + { + using (_egl.PrimaryEglContext.EnsureLocked()) + { + _window?.Dispose(); + _window = null; + } + } + } +} diff --git a/src/Windows/Avalonia.Win32/WinRT/IBlurHost.cs b/src/Windows/Avalonia.Win32/WinRT/IBlurHost.cs new file mode 100644 index 0000000000..81c0e3e185 --- /dev/null +++ b/src/Windows/Avalonia.Win32/WinRT/IBlurHost.cs @@ -0,0 +1,7 @@ +namespace Avalonia.Win32.WinRT +{ + public interface IBlurHost + { + void SetBlur(bool enable); + } +} diff --git a/src/Windows/Avalonia.Win32/WinRT/NativeWinRTMethods.cs b/src/Windows/Avalonia.Win32/WinRT/NativeWinRTMethods.cs new file mode 100644 index 0000000000..087bd2fd43 --- /dev/null +++ b/src/Windows/Avalonia.Win32/WinRT/NativeWinRTMethods.cs @@ -0,0 +1,140 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Reflection; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.WindowsRuntime; +using System.Threading; +using Avalonia.MicroCom; +using Avalonia.Win32.Interop; + +namespace Avalonia.Win32.WinRT +{ + internal static class NativeWinRTMethods + { + [DllImport("api-ms-win-core-winrt-string-l1-1-0.dll", CallingConvention = CallingConvention.StdCall, + PreserveSig = false)] + internal static extern unsafe IntPtr WindowsCreateString( + [MarshalAs(UnmanagedType.LPWStr)] string sourceString, + int length); + + internal static IntPtr WindowsCreateString(string sourceString) + => WindowsCreateString(sourceString, sourceString.Length); + + [DllImport("api-ms-win-core-winrt-string-l1-1-0.dll", + CallingConvention = CallingConvention.StdCall, PreserveSig = false)] + internal static extern unsafe IntPtr WindowsDeleteString(IntPtr hString); + + [DllImport("Windows.UI.Composition", EntryPoint = "DllGetActivationFactory", + CallingConvention = CallingConvention.StdCall, PreserveSig = false)] + private extern static IntPtr GetWindowsUICompositionActivationFactory( + IntPtr activatableClassId); + + internal static IActivationFactory GetWindowsUICompositionActivationFactory(string className) + {//"Windows.UI.Composition.Compositor" + var s = WindowsCreateString(className); + var factory = GetWindowsUICompositionActivationFactory(s); + return MicroComRuntime.CreateProxyFor(factory, true); + } + + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + delegate int GetActivationFactoryDelegate(IntPtr classId, out IntPtr ppv); + + internal static T CreateInstance(string fullName) where T : IUnknown + { + var s = WindowsCreateString(fullName); + EnsureRoInitialized(); + var pUnk = RoActivateInstance(s); + using var unk = MicroComRuntime.CreateProxyFor(pUnk, true); + WindowsDeleteString(s); + return MicroComRuntime.QueryInterface(unk); + } + + internal static TFactory CreateActivationFactory(string fullName) where TFactory : IUnknown + { + var s = WindowsCreateString(fullName); + EnsureRoInitialized(); + var guid = MicroComRuntime.GetGuidFor(typeof(TFactory)); + var pUnk = RoGetActivationFactory(s, ref guid); + using var unk = MicroComRuntime.CreateProxyFor(pUnk, true); + WindowsDeleteString(s); + return MicroComRuntime.QueryInterface(unk); + } + + internal enum DISPATCHERQUEUE_THREAD_APARTMENTTYPE + { + DQTAT_COM_NONE = 0, + DQTAT_COM_ASTA = 1, + DQTAT_COM_STA = 2 + }; + + internal enum DISPATCHERQUEUE_THREAD_TYPE + { + DQTYPE_THREAD_DEDICATED = 1, + DQTYPE_THREAD_CURRENT = 2, + }; + + [StructLayout(LayoutKind.Sequential)] + internal struct DispatcherQueueOptions + { + public int dwSize; + + [MarshalAs(UnmanagedType.I4)] + public DISPATCHERQUEUE_THREAD_TYPE threadType; + + [MarshalAs(UnmanagedType.I4)] + public DISPATCHERQUEUE_THREAD_APARTMENTTYPE apartmentType; + }; + + [DllImport("coremessaging.dll", PreserveSig = false)] + internal static extern IntPtr CreateDispatcherQueueController(DispatcherQueueOptions options); + + internal enum RO_INIT_TYPE + { + RO_INIT_SINGLETHREADED = 0, // Single-threaded application + RO_INIT_MULTITHREADED = 1, // COM calls objects on any thread. + } + + [DllImport("combase.dll", PreserveSig = false)] + private static extern void RoInitialize(RO_INIT_TYPE initType); + + [DllImport("combase.dll", PreserveSig = false)] + private static extern IntPtr RoActivateInstance(IntPtr activatableClassId); + + [DllImport("combase.dll", PreserveSig = false)] + private static extern IntPtr RoGetActivationFactory(IntPtr activatableClassId, ref Guid iid); + + private static bool _initialized; + private static void EnsureRoInitialized() + { + if (_initialized) + return; + RoInitialize(Thread.CurrentThread.GetApartmentState() == ApartmentState.STA ? + RO_INIT_TYPE.RO_INIT_SINGLETHREADED : + RO_INIT_TYPE.RO_INIT_MULTITHREADED); + _initialized = true; + } + } + + class HStringInterop : IDisposable + { + private IntPtr _s; + + public HStringInterop(string s) + { + _s = s == null ? IntPtr.Zero : NativeWinRTMethods.WindowsCreateString(s); + } + + public IntPtr Handle => _s; + + public void Dispose() + { + if (_s != IntPtr.Zero) + { + NativeWinRTMethods.WindowsDeleteString(_s); + _s = IntPtr.Zero; + } + } + } +} diff --git a/src/Windows/Avalonia.Win32/WinRT/WinRTColor.cs b/src/Windows/Avalonia.Win32/WinRT/WinRTColor.cs new file mode 100644 index 0000000000..786d698daa --- /dev/null +++ b/src/Windows/Avalonia.Win32/WinRT/WinRTColor.cs @@ -0,0 +1,18 @@ +using System.Runtime.InteropServices; + +namespace Avalonia.Win32.WinRT +{ + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct WinRTColor + { + public byte A; + public byte R; + public byte G; + public byte B; + + public static WinRTColor FromArgb(byte a, byte r, byte g, byte b) => new WinRTColor() + { + A = a, R = r, G = g, B = b + }; + } +} diff --git a/src/Windows/Avalonia.Win32/WinRT/WinRTInspectable.cs b/src/Windows/Avalonia.Win32/WinRT/WinRTInspectable.cs new file mode 100644 index 0000000000..d2ec957b8e --- /dev/null +++ b/src/Windows/Avalonia.Win32/WinRT/WinRTInspectable.cs @@ -0,0 +1,38 @@ +using System; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using Avalonia.MicroCom; + +namespace Avalonia.Win32.WinRT +{ + class WinRTInspectable : IInspectable, IMicroComShadowContainer + { + public virtual void Dispose() + { + + } + + public unsafe void GetIids(ulong* iidCount, Guid** iids) + { + var interfaces = GetType().GetInterfaces().Where(typeof(IUnknown).IsAssignableFrom) + .Select(MicroComRuntime.GetGuidFor).ToArray(); + var mem = (Guid*)Marshal.AllocCoTaskMem(Unsafe.SizeOf() * interfaces.Length); + for (var c = 0; c < interfaces.Length; c++) + mem[c] = interfaces[c]; + *iids = mem; + *iidCount = (ulong) interfaces.Length; + } + + public IntPtr RuntimeClassName => NativeWinRTMethods.WindowsCreateString(GetType().FullName); + public TrustLevel TrustLevel => TrustLevel.BaseTrust; + public MicroComShadow Shadow { get; set; } + public virtual void OnReferencedFromNative() + { + } + + public virtual void OnUnreferencedFromNative() + { + } + } +} diff --git a/src/Windows/Avalonia.Win32/WinRT/WinRTPropertyValue.cs b/src/Windows/Avalonia.Win32/WinRT/WinRTPropertyValue.cs new file mode 100644 index 0000000000..684e7ff7b5 --- /dev/null +++ b/src/Windows/Avalonia.Win32/WinRT/WinRTPropertyValue.cs @@ -0,0 +1,89 @@ +using System; +using System.Runtime.InteropServices; + +namespace Avalonia.Win32.WinRT +{ + class WinRTPropertyValue : WinRTInspectable, IPropertyValue + { + public WinRTPropertyValue(float f) + { + Type = PropertyType.Single; + Single = f; + } + + public WinRTPropertyValue(uint u) + { + UInt32 = u; + Type = PropertyType.UInt32; + } + + public PropertyType Type { get; } + public int IsNumericScalar { get; } + public byte UInt8 { get; } + public short Int16 { get; } + public ushort UInt16 { get; } + public int Int32 { get; } + public uint UInt32 { get; } + public long Int64 { get; } + public ulong UInt64 { get; } + public float Single { get; } + public double Double { get; } + public char Char16 { get; } + public int Boolean { get; } + public IntPtr String { get; } + public Guid Guid { get; } + + private static COMException NotImplemented => new COMException("Not supported", unchecked((int)0x80004001)); + + public unsafe void GetDateTime(void* value) => throw NotImplemented; + + public unsafe void GetTimeSpan(void* value) => throw NotImplemented; + + public unsafe void GetPoint(void* value) => throw NotImplemented; + + public unsafe void GetSize(void* value) => throw NotImplemented; + + public unsafe void GetRect(void* value) => throw NotImplemented; + + public unsafe byte* GetUInt8Array(uint* __valueSize) => throw NotImplemented; + + public unsafe short* GetInt16Array(uint* __valueSize) => throw NotImplemented; + + public unsafe ushort* GetUInt16Array(uint* __valueSize) => throw NotImplemented; + + public unsafe int* GetInt32Array(uint* __valueSize) + { + throw NotImplemented; + } + + public unsafe uint* GetUInt32Array(uint* __valueSize) => throw NotImplemented; + + public unsafe long* GetInt64Array(uint* __valueSize) => throw NotImplemented; + + public unsafe ulong* GetUInt64Array(uint* __valueSize) => throw NotImplemented; + + public unsafe float* GetSingleArray(uint* __valueSize) => throw NotImplemented; + + public unsafe double* GetDoubleArray(uint* __valueSize) => throw NotImplemented; + + public unsafe char* GetChar16Array(uint* __valueSize) => throw NotImplemented; + + public unsafe int* GetBooleanArray(uint* __valueSize) => throw NotImplemented; + + public unsafe IntPtr* GetStringArray(uint* __valueSize) => throw NotImplemented; + + public unsafe void** GetInspectableArray(uint* __valueSize) => throw NotImplemented; + + public unsafe Guid* GetGuidArray(uint* __valueSize) => throw NotImplemented; + + public unsafe void* GetDateTimeArray(uint* __valueSize) => throw NotImplemented; + + public unsafe void* GetTimeSpanArray(uint* __valueSize) => throw NotImplemented; + + public unsafe void* GetPointArray(uint* __valueSize) => throw NotImplemented; + + public unsafe void* GetSizeArray(uint* __valueSize) => throw NotImplemented; + + public unsafe void* GetRectArray(uint* __valueSize) => throw NotImplemented; + } +} diff --git a/src/Windows/Avalonia.Win32/WinRT/winrt.idl b/src/Windows/Avalonia.Win32/WinRT/winrt.idl new file mode 100644 index 0000000000..929377999c --- /dev/null +++ b/src/Windows/Avalonia.Win32/WinRT/winrt.idl @@ -0,0 +1,718 @@ +@clr-namespace Avalonia.Win32.WinRT +@clr-access internal +@clr-map FLOAT float +@clr-map HSTRING IntPtr +@clr-map Vector2 System.Numerics.Vector2 +@clr-map Vector3 System.Numerics.Vector3 +@clr-map Quaternion System.Numerics.Quaternion +@clr-map Matrix4x4 System.Numerics.Matrix4x4 +@clr-map RECT Avalonia.Win32.Interop.UnmanagedMethods.RECT +@clr-map SIZE Avalonia.Win32.Interop.UnmanagedMethods.SIZE +@clr-map POINT Avalonia.Win32.Interop.UnmanagedMethods.POINT +@clr-map HWND IntPtr +@clr-map BOOL int +@clr-map DWORD int +@clr-map boolean int +@clr-map BYTE byte +@clr-map INT16 short +@clr-map INT32 int +@clr-map INT64 long +@clr-map UINT16 ushort +@clr-map UINT32 uint +@clr-map UINT64 ulong +@clr-map DOUBLE double +@clr-map GUID System.Guid +@clr-map WCHAR System.Char +@clr-map Color Avalonia.Win32.WinRT.WinRTColor + +enum TrustLevel +{ + BaseTrust, + PartialTrust, + FullTrust +} + +enum DirectXAlphaMode +{ + Unspecified, + Premultiplied, + Straight, + Ignore +} + +enum DirectXPixelFormat +{ + Unknown = 0, + R32G32B32A32Typeless = 1, + R32G32B32A32Float = 2, + R32G32B32A32UInt = 3, + R32G32B32A32Int = 4, + R32G32B32Typeless = 5, + R32G32B32Float = 6, + R32G32B32UInt = 7, + R32G32B32Int = 8, + R16G16B16A16Typeless = 9, + R16G16B16A16Float = 10, + R16G16B16A16UIntNormalized = 11, + R16G16B16A16UInt = 12, + R16G16B16A16IntNormalized = 13, + R16G16B16A16Int = 14, + R32G32Typeless = 15, + R32G32Float = 16, + R32G32UInt = 17, + R32G32Int = 18, + R32G8X24Typeless = 19, + D32FloatS8X24UInt = 20, + R32FloatX8X24Typeless = 21, + X32TypelessG8X24UInt = 22, + R10G10B10A2Typeless = 23, + R10G10B10A2UIntNormalized = 24, + R10G10B10A2UInt = 25, + R11G11B10Float = 26, + R8G8B8A8Typeless = 27, + R8G8B8A8UIntNormalized = 28, + R8G8B8A8UIntNormalizedSrgb = 29, + R8G8B8A8UInt = 30, + R8G8B8A8IntNormalized = 31, + R8G8B8A8Int = 32, + R16G16Typeless = 33, + R16G16Float = 34, + R16G16UIntNormalized = 35, + R16G16UInt = 36, + R16G16IntNormalized = 37, + R16G16Int = 38, + R32Typeless = 39, + D32Float = 40, + R32Float = 41, + R32UInt = 42, + R32Int = 43, + R24G8Typeless = 44, + D24UIntNormalizedS8UInt = 45, + R24UIntNormalizedX8Typeless = 46, + X24TypelessG8UInt = 47, + R8G8Typeless = 48, + R8G8UIntNormalized = 49, + R8G8UInt = 50, + R8G8IntNormalized = 51, + R8G8Int = 52, + R16Typeless = 53, + R16Float = 54, + D16UIntNormalized = 55, + R16UIntNormalized = 56, + R16UInt = 57, + R16IntNormalized = 58, + R16Int = 59, + R8Typeless = 60, + R8UIntNormalized = 61, + R8UInt = 62, + R8IntNormalized = 63, + R8Int = 64, + A8UIntNormalized = 65, + R1UIntNormalized = 66, + R9G9B9E5SharedExponent = 67, + R8G8B8G8UIntNormalized = 68, + G8R8G8B8UIntNormalized = 69, + BC1Typeless = 70, + BC1UIntNormalized = 71, + BC1UIntNormalizedSrgb = 72, + BC2Typeless = 73, + BC2UIntNormalized = 74, + BC2UIntNormalizedSrgb = 75, + BC3Typeless = 76, + BC3UIntNormalized = 77, + BC3UIntNormalizedSrgb = 78, + BC4Typeless = 79, + BC4UIntNormalized = 80, + BC4IntNormalized = 81, + BC5Typeless = 82, + BC5UIntNormalized = 83, + BC5IntNormalized = 84, + B5G6R5UIntNormalized = 85, + B5G5R5A1UIntNormalized = 86, + B8G8R8A8UIntNormalized = 87, + B8G8R8X8UIntNormalized = 88, + R10G10B10XRBiasA2UIntNormalized = 89, + B8G8R8A8Typeless = 90, + B8G8R8A8UIntNormalizedSrgb = 91, + B8G8R8X8Typeless = 92, + B8G8R8X8UIntNormalizedSrgb = 93, + BC6HTypeless = 94, + BC6H16UnsignedFloat = 95, + BC6H16Float = 96, + BC7Typeless = 97, + BC7UIntNormalized = 98, + BC7UIntNormalizedSrgb = 99, + Ayuv = 100, + Y410 = 101, + Y416 = 102, + NV12 = 103, + P010 = 104, + P016 = 105, + Opaque420 = 106, + Yuy2 = 107, + Y210 = 108, + Y216 = 109, + NV11 = 110, + AI44 = 111, + IA44 = 112, + P8 = 113, + A8P8 = 114, + B4G4R4A4UIntNormalized = 115, + P208 = 130, + V208 = 131, + V408 = 132, +} + +[uuid(AF86E2E0-B12D-4c6a-9C5A-D7AA65101E90)] +interface IInspectable : IUnknown +{ + HRESULT GetIids(ulong * iidCount, Guid ** iids); + HRESULT GetRuntimeClassName( [out] IntPtr* className); + HRESULT GetTrustLevel([out] TrustLevel * trustLevel); +} + +enum PropertyType +{ + Empty = 0, + UInt8 = 1, + Int16 = 2, + UInt16 = 3, + Int32 = 4, + UInt32 = 5, + Int64 = 6, + UInt64 = 7, + Single = 8, + Double = 9, + Char16 = 10, + Boolean = 11, + String = 12, + Inspectable = 13, + DateTime = 14, + TimeSpan = 15, + Guid = 16, + Point = 17, + Size = 18, + Rect = 19, + OtherType = 20, + UInt8Array = 1025, + Int16Array = 1026, + UInt16Array = 1027, + Int32Array = 1028, + UInt32Array = 1029, + Int64Array = 1030, + UInt64Array = 1031, + SingleArray = 1032, + DoubleArray = 1033, + Char16Array = 1034, + BooleanArray = 1035, + StringArray = 1036, + InspectableArray = 1037, + DateTimeArray = 1038, + TimeSpanArray = 1039, + GuidArray = 1040, + PointArray = 1041, + SizeArray = 1042, + RectArray = 1043, + OtherTypeArray = 1044 +} + +[uuid(4BD682DD-7554-40E9-9A9B-82654EDE7E62)] +interface IPropertyValue : IInspectable +{ + [propget] HRESULT Type([out] [retval] PropertyType* value); + [propget] HRESULT IsNumericScalar([out] [retval] boolean* value); + HRESULT GetUInt8([out] [retval] BYTE* value); + HRESULT GetInt16([out] [retval] INT16* value); + HRESULT GetUInt16([out] [retval] UINT16* value); + HRESULT GetInt32([out] [retval] INT32* value); + HRESULT GetUInt32([out] [retval] UINT32* value); + HRESULT GetInt64([out] [retval] INT64* value); + HRESULT GetUInt64([out] [retval] UINT64* value); + HRESULT GetSingle([out] [retval] FLOAT* value); + HRESULT GetDouble([out] [retval] DOUBLE* value); + HRESULT GetChar16([out] [retval] WCHAR* value); + HRESULT GetBoolean([out] [retval] boolean* value); + HRESULT GetString([out] [retval] HSTRING* value); + HRESULT GetGuid([out] [retval] GUID* value); + HRESULT GetDateTime( void* value); + HRESULT GetTimeSpan(void* value); + HRESULT GetPoint(void* value); + HRESULT GetSize(void* value); + HRESULT GetRect(void* value); + HRESULT GetUInt8Array([out] UINT32* __valueSize, [out] [size_is(, *__valueSize)] BYTE** value); + HRESULT GetInt16Array([out] UINT32* __valueSize, [out] [size_is(, *__valueSize)] INT16** value); + HRESULT GetUInt16Array([out] UINT32* __valueSize, [out] [size_is(, *__valueSize)] UINT16** value); + HRESULT GetInt32Array([out] UINT32* __valueSize, [out] [size_is(, *__valueSize)] INT32** value); + HRESULT GetUInt32Array([out] UINT32* __valueSize, [out] [size_is(, *__valueSize)] UINT32** value); + HRESULT GetInt64Array([out] UINT32* __valueSize, [out] [size_is(, *__valueSize)] INT64** value); + HRESULT GetUInt64Array([out] UINT32* __valueSize, [out] [size_is(, *__valueSize)] UINT64** value); + HRESULT GetSingleArray([out] UINT32* __valueSize, [out] [size_is(, *__valueSize)] FLOAT** value); + HRESULT GetDoubleArray([out] UINT32* __valueSize, [out] [size_is(, *__valueSize)] DOUBLE** value); + HRESULT GetChar16Array([out] UINT32* __valueSize, [out] [size_is(, *__valueSize)] WCHAR** value); + HRESULT GetBooleanArray([out] UINT32* __valueSize, [out] [size_is(, *__valueSize)] boolean** value); + HRESULT GetStringArray([out] UINT32* __valueSize, [out] [size_is(, *__valueSize)] HSTRING** value); + HRESULT GetInspectableArray([out] UINT32* __valueSize, [out] [size_is(, *__valueSize)] void*** value); + HRESULT GetGuidArray([out] UINT32* __valueSize, [out] [size_is(, *__valueSize)] GUID** value); + HRESULT GetDateTimeArray([out] UINT32* __valueSize, [out] [size_is(, *__valueSize)] void** value); + HRESULT GetTimeSpanArray([out] UINT32* __valueSize, [out] [size_is(, *__valueSize)] void** value); + HRESULT GetPointArray([out] UINT32* __valueSize, [out] [size_is(, *__valueSize)] void** value); + HRESULT GetSizeArray([out] UINT32* __valueSize, [out] [size_is(, *__valueSize)] void** value); + HRESULT GetRectArray([out] UINT32* __valueSize, [out] [size_is(, *__valueSize)] void** value); +} + +enum AsyncStatus { + Started = 0, + Completed, + Canceled, + Error, +} + +[uuid(A4ED5C81-76C9-40BD-8BE6-B1D90FB20AE7)] +interface IAsyncActionCompletedHandler : IUnknown +{ + HRESULT Invoke([in] IAsyncAction* asyncInfo, [in] AsyncStatus asyncStatus); +} + +[uuid(5A648006-843A-4DA9-865B-9D26E5DFAD7B)] +interface IAsyncAction : IInspectable +{ + HRESULT SetCompleted([in] IAsyncActionCompletedHandler* handler); + HRESULT GetCompleted([out] [retval] IAsyncActionCompletedHandler** ppv); + HRESULT GetResults(); +} + +[uuid(603E88E4-A338-4FFE-A457-A5CFB9CEB899)] +interface IDispatcherQueue : IInspectable +{ + //TODO +} + +[uuid(22F34E66-50DB-4E36-A98D-61C01B384D20)] +interface IDispatcherQueueController : IInspectable +{ + [propget] HRESULT DispatcherQueue([out] [retval] IDispatcherQueue** value); + HRESULT ShutdownQueueAsync([out] [retval] IAsyncAction** operation); +} + +[uuid(00000035-0000-0000-C000-000000000046)] +interface IActivationFactory : IInspectable +{ + HRESULT ActivateInstance([out, retval] IntPtr* instance); +} + +[flags] +enum CompositionBatchTypes +{ + None = 0x0, + Animation = 0x1, + Effect = 0x2, + InfiniteAnimation = 0x4, + AllAnimations = 0x5 +} + +[uuid(B403CA50-7F8C-4E83-985F-CC45060036D8)] +interface ICompositor : IInspectable +{ + HRESULT CreateColorKeyFrameAnimation([out] [retval] void** result); + [overload("CreateColorBrush")] HRESULT CreateColorBrush([out] [retval]void** result); + [overload("CreateColorBrush")] HRESULT CreateColorBrushWithColor([in] Color* color, [out] [retval] ICompositionColorBrush** result); + HRESULT CreateContainerVisual([out] [retval] IContainerVisual** result); + HRESULT CreateCubicBezierEasingFunction([in] Vector2 controlPoint1, [in] Vector2 controlPoint2, [out] [retval] void** result); + [overload("CreateEffectFactory")] HRESULT CreateEffectFactory([in] IGraphicsEffect* graphicsEffect, [out] [retval] ICompositionEffectFactory** result); + [overload("CreateEffectFactory")] HRESULT CreateEffectFactoryWithProperties([in] void* graphicsEffect, [in] void* animatableProperties, [out] [retval] void** result); + [overload("CreateExpressionAnimation")] HRESULT CreateExpressionAnimation([out] [retval] void** result); + [overload("CreateExpressionAnimation")] HRESULT CreateExpressionAnimationWithExpression([in] HSTRING expression, [out] [retval] void** result); + [overload("CreateInsetClip")] HRESULT CreateInsetClip([out] [retval] void** result); + [overload("CreateInsetClip")] HRESULT CreateInsetClipWithInsets([in] FLOAT leftInset, [in] FLOAT topInset, [in] FLOAT rightInset, [in] FLOAT bottomInset, [out] [retval] void** result); + HRESULT CreateLinearEasingFunction([out] [retval] void** result); + HRESULT CreatePropertySet([out] [retval] void** result); + HRESULT CreateQuaternionKeyFrameAnimation([out] [retval] void** result); + HRESULT CreateScalarKeyFrameAnimation([out] [retval] void** result); + HRESULT CreateScopedBatch([in] CompositionBatchTypes batchType, [out] [retval] ICompositionScopedBatch** result); + HRESULT CreateSpriteVisual([out] [retval] ISpriteVisual** result); + HRESULT CreateSurfaceBrush([out] [retval] ICompositionSurfaceBrush** result); + HRESULT CreateSurfaceBrushWithSurface([in] ICompositionSurface* surface, + [out] [retval] ICompositionSurfaceBrush** result); + HRESULT CreateTargetForCurrentView([out] [retval] void** result); + HRESULT CreateVector2KeyFrameAnimation([out] [retval] void** result); + HRESULT CreateVector3KeyFrameAnimation([out] [retval] void** result); + HRESULT CreateVector4KeyFrameAnimation([out] [retval] void** result); + HRESULT GetCommitBatch([in] CompositionBatchTypes batchType, [out] [retval] void** result); +} + +[uuid(735081DC-5E24-45DA-A38F-E32CC349A9A0)] +interface ICompositor2 : IInspectable +{ + HRESULT CreateAmbientLight([out] [retval] void** result); + HRESULT CreateAnimationGroup([out] [retval] void** result); + HRESULT CreateBackdropBrush([out] [retval] ICompositionBackdropBrush** result); + HRESULT CreateDistantLight([out] [retval] void** result); + HRESULT CreateDropShadow([out] [retval] void** result); + HRESULT CreateImplicitAnimationCollection([out] [retval] void** result); + HRESULT CreateLayerVisual([out] [retval] void** result); + HRESULT CreateMaskBrush([out] [retval] void** result); + HRESULT CreateNineGridBrush([out] [retval] void** result); + HRESULT CreatePointLight([out] [retval] void** result); + HRESULT CreateSpotLight([out] [retval] void** result); + [overload("CreateStepEasingFunction")] HRESULT CreateStepEasingFunction([out] [retval] void** result); + [overload("CreateStepEasingFunction")] HRESULT CreateStepEasingFunctionWithStepCount([in] INT32 stepCount, [out] [retval] void** result); +} + +[uuid(08E05581-1AD1-4F97-9757-402D76E4233B)] +interface ISpriteVisual : IInspectable +{ + [propget] HRESULT GetBrush([out] [retval] ICompositionBrush** value); + [propput] HRESULT SetBrush([in] ICompositionBrush* value); +} + +[uuid(FD04E6E3-FE0C-4C3C-AB19-A07601A576EE)] +interface ICompositionDrawingSurfaceInterop : IUnknown +{ + HRESULT BeginDraw(RECT* updateRect, Guid* iid, void** updateObject, [out, retval]POINT* updateOffset); + HRESULT EndDraw(); + HRESULT Resize(POINT sizePixels); + HRESULT Scroll(RECT * scrollRect, RECT * clipRect, int offsetX, int offsetY); + HRESULT ResumeDraw(); + HRESULT SuspendDraw(); +}; + +[uuid(A116FF71-F8BF-4C8A-9C98-70779A32A9C8)] +interface ICompositionGraphicsDeviceInterop : IUnknown +{ + HRESULT GetRenderingDevice([out] IUnknown ** value); + HRESULT SetRenderingDevice([out] IUnknown * value); +}; + +[uuid(25297D5C-3AD4-4C9C-B5CF-E36A38512330)] +interface ICompositorInterop : IUnknown +{ + HRESULT CreateCompositionSurfaceForHandle(IntPtr swapChain, [out] ICompositionSurface ** res); + HRESULT CreateCompositionSurfaceForSwapChain(IUnknown* swapChain, [out] ICompositionSurface ** result); + HRESULT CreateGraphicsDevice(IUnknown * renderingDevice, [out] ICompositionGraphicsDevice ** result); +}; + +[uuid(26f496a0-7f38-45fb-88f7-faaabe67dd59)] +interface ISwapChainInterop : IUnknown +{ + HRESULT SetSwapChain(IUnknown * swapChain); +}; + +/* +[uuid(2C9DB356-E70D-4642-8298-BC4AA5B4865C)] +interface ICompositionCapabilitiesInteropFactory : IInspectable +{ + HRESULT GetForWindow(IntPtr hwnd, [out] ICompositionCapabilities ** result); +}*/ + +[uuid(29E691FA-4567-4DCA-B319-D0F207EB6807)] +interface ICompositorDesktopInterop : IUnknown +{ + HRESULT CreateDesktopWindowTarget(HWND hwndTarget, BOOL isTopmost, [out] IDesktopWindowTarget ** result); + HRESULT EnsureOnThread(DWORD threadId); +}; + + +[uuid(35DBF59E-E3F9-45B0-81E7-FE75F4145DC9)] +interface IDesktopWindowTargetInterop : IUnknown +{ + HRESULT GetHWnd([out] IntPtr* value); +}; + +[uuid(37642806-F421-4FD0-9F82-23AE7C776182)] +interface IDesktopWindowContentBridgeInterop : IUnknown +{ + HRESULT Initialize(ICompositor* compositor, HWND parentHwnd); + HRESULT GetHWnd([out] IntPtr* value); + + HRESULT GetAppliedScaleFactor([out] float* value); +}; + +[uuid(FB22C6E1-80A2-4667-9936-DBEAF6EEFE95)] +interface ICompositionGraphicsDevice : IInspectable +{ + HRESULT CreateDrawingSurface([in] SIZE sizePixels, [in] DirectXPixelFormat pixelFormat, + [in] DirectXAlphaMode alphaMode, [out] [retval] ICompositionDrawingSurface** result); + HRESULT AddRenderingDeviceReplaced(void* handler, void* token); + HRESULT RemoveRenderingDeviceReplaced([in] int token); +} + +[uuid(1527540D-42C7-47A6-A408-668F79A90DFB)] +interface ICompositionSurface : IInspectable +{ +} + +[uuid(6329D6CA-3366-490E-9DB3-25312929AC51)] +interface IDesktopWindowTarget : IInspectable +{ + [propget] HRESULT IsTopmost([out] [retval] int* value); +} + + +[uuid(A166C300-FAD0-4D11-9E67-E433162FF49E)] +interface ICompositionDrawingSurface : IInspectable +{ + [propget] HRESULT GetAlphaMode([out] [retval] DirectXAlphaMode* value); + [propget] HRESULT GetPixelFormat([out] [retval] DirectXPixelFormat* value); + [propget] HRESULT GetSize([out] [retval] POINT* value); +} + +enum CompositionBitmapInterpolationMode +{ + NearestNeighbor, + Linear, + MagLinearMinLinearMipLinear, + MagLinearMinLinearMipNearest, + MagLinearMinNearestMipLinear, + MagLinearMinNearestMipNearest, + MagNearestMinLinearMipLinear, + MagNearestMinLinearMipNearest, + MagNearestMinNearestMipLinear, + MagNearestMinNearestMipNearest, +} + +enum CompositionStretch +{ + None, + Fill, + Uniform, + UniformToFill, +} + +[uuid(AD016D79-1E4C-4C0D-9C29-83338C87C162)] +interface ICompositionSurfaceBrush : IInspectable +{ + [propget] HRESULT BitmapInterpolationMode([out] [retval] CompositionBitmapInterpolationMode* value); + [propput] HRESULT BitmapInterpolationMode([in] CompositionBitmapInterpolationMode value); + [propget] HRESULT HorizontalAlignmentRatio([out] [retval] FLOAT* value); + [propput] HRESULT HorizontalAlignmentRatio([in] FLOAT value); + [propget] HRESULT Stretch([out] [retval] CompositionStretch* value); + [propput] HRESULT Stretch([in] CompositionStretch value); + [propget] HRESULT Surface([out] [retval] ICompositionSurface** value); + [propput] HRESULT Surface([in] ICompositionSurface* value); + [propget] HRESULT VerticalAlignmentRatio([out] [retval] FLOAT* value); + [propput] HRESULT VerticalAlignmentRatio([in] FLOAT value); +} + +[uuid(AB0D7608-30C0-40E9-B568-B60A6BD1FB46)] +interface ICompositionBrush : IInspectable +{ +} + +enum CompositionBackfaceVisibility +{ + Inherit, + Visible, + Hidden +} + +enum CompositionBorderMode +{ + Inherit, + Soft, + Hard +} + +enum CompositionCompositeMode +{ + Inherit, + SourceOver, + DestinationInvert, + MinBlend, +} + +[uuid(117E202D-A859-4C89-873B-C2AA566788E3)] +interface IVisual : IInspectable +{ + [propget] HRESULT AnchorPoint([out] [retval] Vector2* value); + [propput] HRESULT AnchorPoint([in] Vector2 value); + [propget] HRESULT BackfaceVisibility([out] [retval] CompositionBackfaceVisibility* value); + [propput] HRESULT BackfaceVisibility([in] CompositionBackfaceVisibility value); + [propget] HRESULT BorderMode([out] [retval] CompositionBorderMode* value); + [propput] HRESULT BorderMode([in] CompositionBorderMode value); + [propget] HRESULT CenterPoint([out] [retval] Vector3* value); + [propput] HRESULT CenterPoint([in] Vector3 value); + [propget] HRESULT Clip([out] [retval]void** value); + [propput] HRESULT Clip([in] void* value); + [propget] HRESULT CompositeMode([out] [retval] CompositionCompositeMode* value); + [propput] HRESULT CompositeMode([in] CompositionCompositeMode value); + [propget] HRESULT IsVisible([out] [retval] boolean* value); + [propput] HRESULT IsVisible([in] boolean value); + [propget] HRESULT Offset([out] [retval] Vector3* value); + [propput] HRESULT Offset([in] Vector3 value); + [propget] HRESULT Opacity([out] [retval] FLOAT* value); + [propput] HRESULT Opacity([in] FLOAT value); + [propget] HRESULT Orientation([out] [retval] Quaternion* value); + [propput] HRESULT Orientation([in] Quaternion value); + [propget] HRESULT Parent([out] [retval] IContainerVisual** value); + [propget] HRESULT RotationAngle([out] [retval] FLOAT* value); + [propput] HRESULT RotationAngle([in] FLOAT value); + [propget] HRESULT RotationAngleInDegrees([out] [retval] FLOAT* value); + [propput] HRESULT RotationAngleInDegrees([in] FLOAT value); + [propget] HRESULT RotationAxis([out] [retval] Vector3* value); + [propput] HRESULT RotationAxis([in] Vector3 value); + [propget] HRESULT Scale([out] [retval] Vector3* value); + [propput] HRESULT Scale([in] Vector3 value); + [propget] HRESULT Size([out] [retval] Vector2* value); + [propput] HRESULT Size([in] Vector2 value); + [propget] HRESULT TransformMatrix([out] [retval] Matrix4x4* value); + [propput] HRESULT TransformMatrix([in] Matrix4x4 value); +} + +[uuid(3052B611-56C3-4C3E-8BF3-F6E1AD473F06)] +interface IVisual2 : IInspectable +{ + [propget] HRESULT ParentForTransform([out] [retval] IVisual** value); + [propput] HRESULT ParentForTransform([in] IVisual* value); + [propget] HRESULT RelativeOffsetAdjustment([out] [retval] Vector3* value); + [propput] HRESULT RelativeOffsetAdjustment([in] Vector3 value); + [propget] HRESULT RelativeSizeAdjustment([out] [retval] Vector2* value); + [propput] HRESULT RelativeSizeAdjustment([in] Vector2 value); +} + +[uuid(02F6BC74-ED20-4773-AFE6-D49B4A93DB32)] +interface IContainerVisual : IInspectable +{ + [propget] HRESULT GetChildren([out] [retval] IVisualCollection** value); +} + +[uuid(8B745505-FD3E-4A98-84A8-E949468C6BCB)] +interface IVisualCollection : IInspectable +{ + [propget] HRESULT GetCount([out] [retval] INT32* value); + HRESULT InsertAbove([in] IVisual* newChild, [in] IVisual* sibling); + HRESULT InsertAtBottom([in] IVisual* newChild); + HRESULT InsertAtTop([in] IVisual* newChild); + HRESULT InsertBelow([in] IVisual* newChild, [in] IVisual* sibling); + HRESULT Remove([in] IVisual* child); + HRESULT RemoveAll(); +} + +[uuid(A1BEA8BA-D726-4663-8129-6B5E7927FFA6)] +interface ICompositionTarget : IInspectable +{ + [propget] HRESULT Root([out] [retval] IVisual** value); + [propput] HRESULT Root([in] IVisual* value); +} + + +[uuid(CB51C0CE-8FE6-4636-B202-861FAA07D8F3)] +interface IGraphicsEffect : IInspectable +{ + [propget] HRESULT Name([out] [retval] HSTRING* name); + [propput] HRESULT Name([in] HSTRING name); +} + +[uuid(2D8F9DDC-4339-4EB9-9216-F9DEB75658A2)] +interface IGraphicsEffectSource : IInspectable +{ +} + +enum GRAPHICS_EFFECT_PROPERTY_MAPPING +{ + GRAPHICS_EFFECT_PROPERTY_MAPPING_UNKNOWN, + GRAPHICS_EFFECT_PROPERTY_MAPPING_DIRECT, + GRAPHICS_EFFECT_PROPERTY_MAPPING_VECTORX, + GRAPHICS_EFFECT_PROPERTY_MAPPING_VECTORY, + GRAPHICS_EFFECT_PROPERTY_MAPPING_VECTORZ, + GRAPHICS_EFFECT_PROPERTY_MAPPING_VECTORW, + GRAPHICS_EFFECT_PROPERTY_MAPPING_RECT_TO_VECTOR4, + GRAPHICS_EFFECT_PROPERTY_MAPPING_RADIANS_TO_DEGREES, + GRAPHICS_EFFECT_PROPERTY_MAPPING_COLORMATRIX_ALPHA_MODE, + GRAPHICS_EFFECT_PROPERTY_MAPPING_COLOR_TO_VECTOR3, + GRAPHICS_EFFECT_PROPERTY_MAPPING_COLOR_TO_VECTOR4 +} + +[uuid(2FC57384-A068-44D7-A331-30982FCF7177)] +interface IGraphicsEffectD2D1Interop : IUnknown +{ + HRESULT GetEffectId([out] Guid* id); + HRESULT GetNamedPropertyMapping(IntPtr name, uint* index, GRAPHICS_EFFECT_PROPERTY_MAPPING* mapping); + HRESULT GetPropertyCount([out] uint* count); + HRESULT GetProperty(uint index, [out]IPropertyValue** value); + HRESULT GetSource(uint index, [out, retval] IGraphicsEffectSource** source); + HRESULT GetSourceCount([retval]uint *count); +}; + +[uuid(858AB13A-3292-4E4E-B3BB-2B6C6544A6EE)] +interface ICompositionEffectSourceParameter : IInspectable +{ + [propget] HRESULT Name([out] [retval] HSTRING* value); +} + +[uuid(B3D9F276-ABA3-4724-ACF3-D0397464DB1C)] +interface ICompositionEffectSourceParameterFactory : IInspectable +{ + HRESULT Create([in] HSTRING name, [out] [retval] ICompositionEffectSourceParameter** instance); +} + +enum CompositionEffectFactoryLoadStatus +{ + Success = 0, + EffectTooComplex = 1, + Pending = 2, + Other = -1 +} + +[uuid(BE5624AF-BA7E-4510-9850-41C0B4FF74DF)] +interface ICompositionEffectFactory : IInspectable +{ + HRESULT CreateBrush([out] [retval] ICompositionEffectBrush** result); + [propget] HRESULT ExtendedError([out] [retval] int* value); + [propget] HRESULT LoadStatus([out] [retval] CompositionEffectFactoryLoadStatus* value); +} + +[uuid(BF7F795E-83CC-44BF-A447-3E3C071789EC)] +interface ICompositionEffectBrush : IInspectable +{ + HRESULT GetSourceParameter([in] HSTRING name, [out] [retval] ICompositionBrush** result); + HRESULT SetSourceParameter([in] HSTRING name, [in] ICompositionBrush* source); +} + +[uuid(C5ACAE58-3898-499E-8D7F-224E91286A5D)] +interface ICompositionBackdropBrush : IInspectable +{ +} + +[uuid(2B264C5E-BF35-4831-8642-CF70C20FFF2F)] +interface ICompositionColorBrush : IInspectable +{ + [propget] HRESULT Color([out] [retval] Color* value); + [propput] HRESULT Color([in] Color value); +} + +[uuid(0D00DAD0-FB07-46FD-8C72-6280D1A3D1DD)] +interface ICompositionScopedBatch : IInspectable +{ + [propget] HRESULT IsActive([out] [retval] boolean* value); + [propget] HRESULT IsEnded([out] [retval] boolean* value); + HRESULT End(); + HRESULT Resume(); + HRESULT Suspend(); + [eventadd] HRESULT AddCompleted([in] void* handler, [out] [retval] int* token); + [eventremove] HRESULT RemoveCompleted([in] int token); +} + +[uuid(48EA31AD-7FCD-4076-A79C-90CC4B852C9B)] +interface ICompositor5 : IInspectable +{ + [propget] HRESULT GetComment([out] [retval] HSTRING* value); + [propput] HRESULT SetComment([in] HSTRING value); + [propget] HRESULT GetGlobalPlaybackRate([out] [retval] FLOAT* value); + [propput] HRESULT SetGlobalPlaybackRate([in] FLOAT value); + HRESULT CreateBounceScalarAnimation([out] [retval] void** result); + HRESULT CreateBounceVector2Animation([out] [retval] void** result); + HRESULT CreateBounceVector3Animation([out] [retval] void** result); + HRESULT CreateContainerShape([out] [retval] void** result); + HRESULT CreateEllipseGeometry([out] [retval] void** result); + HRESULT CreateLineGeometry([out] [retval] void** result); + [overload("CreatePathGeometry")] HRESULT CreatePathGeometry([out] [retval] void** result); + [overload("CreatePathGeometry")] HRESULT CreatePathGeometryWithPath([in] void* path, [out] [retval] void** result); + HRESULT CreatePathKeyFrameAnimation([out] [retval] void** result); + HRESULT CreateRectangleGeometry([out] [retval] void** result); + HRESULT CreateRoundedRectangleGeometry([out] [retval] void** result); + HRESULT CreateShapeVisual([out] [retval] void** result); + [overload("CreateSpriteShape")] HRESULT CreateSpriteShape([out] [retval] void** result); + [overload("CreateSpriteShape")] HRESULT CreateSpriteShapeWithGeometry([in] void* geometry, [out] [retval] void** result); + HRESULT CreateViewBox([out] [retval] void** result); + HRESULT RequestCommitAsync([out] [retval] IAsyncAction** operation); +} diff --git a/src/Windows/Avalonia.Win32/WindowFramebuffer.cs b/src/Windows/Avalonia.Win32/WindowFramebuffer.cs deleted file mode 100644 index 19b90685bf..0000000000 --- a/src/Windows/Avalonia.Win32/WindowFramebuffer.cs +++ /dev/null @@ -1,100 +0,0 @@ -using System; -using Avalonia.Platform; -using Avalonia.Win32.Interop; -using PixelFormat = Avalonia.Platform.PixelFormat; - -namespace Avalonia.Win32 -{ - public class WindowFramebuffer : ILockedFramebuffer - { - private readonly IntPtr _handle; - private IUnmanagedBlob _bitmapBlob; - private UnmanagedMethods.BITMAPINFOHEADER _bmpInfo; - - public WindowFramebuffer(IntPtr handle, PixelSize size) - { - - if (size.Width <= 0) - throw new ArgumentException("Width is less than zero"); - if (size.Height <= 0) - throw new ArgumentException("Height is less than zero"); - _handle = handle; - _bmpInfo.Init(); - _bmpInfo.biPlanes = 1; - _bmpInfo.biBitCount = 32; - _bmpInfo.Init(); - _bmpInfo.biWidth = size.Width; - _bmpInfo.biHeight = -size.Height; - _bitmapBlob = AvaloniaLocator.Current.GetService().AllocBlob(size.Width * size.Height * 4); - } - - ~WindowFramebuffer() - { - Deallocate(); - } - - public IntPtr Address => _bitmapBlob.Address; - public int RowBytes => Size.Width * 4; - public PixelFormat Format => PixelFormat.Bgra8888; - - public Vector Dpi - { - get - { - if (UnmanagedMethods.ShCoreAvailable) - { - uint dpix, dpiy; - - var monitor = UnmanagedMethods.MonitorFromWindow(_handle, - UnmanagedMethods.MONITOR.MONITOR_DEFAULTTONEAREST); - - if (UnmanagedMethods.GetDpiForMonitor( - monitor, - UnmanagedMethods.MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI, - out dpix, - out dpiy) == 0) - { - return new Vector(dpix, dpiy); - } - } - return new Vector(96, 96); - } - } - - public PixelSize Size => new PixelSize(_bmpInfo.biWidth, -_bmpInfo.biHeight); - - public void DrawToDevice(IntPtr hDC, int destX = 0, int destY = 0, int srcX = 0, int srcY = 0, int width = -1, - int height = -1) - { - if (width == -1) - width = Size.Width; - if (height == -1) - height = Size.Height; - UnmanagedMethods.SetDIBitsToDevice(hDC, destX, destY, (uint) width, (uint) height, srcX, srcY, - 0, (uint)Size.Height, _bitmapBlob.Address, ref _bmpInfo, 0); - } - - public bool DrawToWindow(IntPtr hWnd, int destX = 0, int destY = 0, int srcX = 0, int srcY = 0, int width = -1, - int height = -1) - { - if (_bitmapBlob.IsDisposed) - throw new ObjectDisposedException("Framebuffer"); - if (hWnd == IntPtr.Zero) - return false; - IntPtr hDC = UnmanagedMethods.GetDC(hWnd); - if (hDC == IntPtr.Zero) - return false; - DrawToDevice(hDC, destX, destY, srcX, srcY, width, height); - UnmanagedMethods.ReleaseDC(hWnd, hDC); - return true; - } - - public void Dispose() - { - //It's not an *actual* dispose. This call means "We are done drawing" - DrawToWindow(_handle); - } - - public void Deallocate() => _bitmapBlob.Dispose(); - } -} diff --git a/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs b/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs index 370e2a2a4b..e7d16f731c 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs @@ -65,6 +65,11 @@ namespace Avalonia.Win32 return IntPtr.Zero; } + BeforeCloseCleanup(false); + + // Used to distinguish between programmatic and regular close requests. + _isCloseRequested = true; + break; } @@ -343,6 +348,7 @@ namespace Avalonia.Win32 case WindowsMessage.WM_PAINT: { + using(NonPumpingSyncContext.Use()) using (_rendererLock.Lock()) { if (BeginPaint(_hwnd, out PAINTSTRUCT ps) != IntPtr.Zero) @@ -360,6 +366,7 @@ namespace Avalonia.Win32 case WindowsMessage.WM_SIZE: { + using(NonPumpingSyncContext.Use()) using (_rendererLock.Lock()) { // Do nothing here, just block until the pending frame render is completed on the render thread diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index 755570bff1..5e67c0d7f3 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.cs @@ -7,6 +7,7 @@ using Avalonia.Controls.Platform; using Avalonia.Input; using Avalonia.Input.Raw; using Avalonia.OpenGL; +using Avalonia.OpenGL.Angle; using Avalonia.OpenGL.Egl; using Avalonia.OpenGL.Surfaces; using Avalonia.Platform; @@ -14,6 +15,8 @@ using Avalonia.Rendering; using Avalonia.Win32.Input; using Avalonia.Win32.Interop; using Avalonia.Win32.OpenGl; +using Avalonia.Win32.WinRT; +using Avalonia.Win32.WinRT.Composition; using static Avalonia.Win32.Interop.UnmanagedMethods; namespace Avalonia.Win32 @@ -48,6 +51,8 @@ namespace Avalonia.Win32 private Thickness _extendedMargins; private Thickness _offScreenMargin; private double _extendTitleBarHint = -1; + private bool _isUsingComposition; + private IBlurHost _blurHost; #if USE_MANAGED_DRAG private readonly ManagedWindowResizeDragHelper _managedDrag; @@ -78,6 +83,7 @@ namespace Avalonia.Win32 private POINT _maxTrackSize; private WindowImpl _parent; private ExtendClientAreaChromeHints _extendChromeHints = ExtendClientAreaChromeHints.Default; + private bool _isCloseRequested; public WindowImpl() { @@ -102,16 +108,37 @@ namespace Avalonia.Win32 }; _rendererLock = new ManagedDeferredRendererLock(); + var glPlatform = AvaloniaLocator.Current.GetService(); + + var compositionConnector = AvaloniaLocator.Current.GetService(); + + _isUsingComposition = compositionConnector is { } && + glPlatform is EglPlatformOpenGlInterface egl && + egl.Display is AngleWin32EglDisplay angleDisplay && + angleDisplay.PlatformApi == AngleOptions.PlatformApi.DirectX11; CreateWindow(); _framebuffer = new FramebufferManager(_hwnd); - - var glPlatform = AvaloniaLocator.Current.GetService(); - if(glPlatform is EglPlatformOpenGlInterface egl) - _gl = new EglGlPlatformSurface(egl, this); - else if (glPlatform is WglPlatformOpenGlInterface wgl) - _gl = new WglGlPlatformSurface(wgl.PrimaryContext, this); + if (glPlatform != null) + { + if (_isUsingComposition) + { + var cgl = new WinUiCompositedWindowSurface(compositionConnector, this); + _blurHost = cgl; + + _gl = cgl; + + _isUsingComposition = true; + } + else + { + if (glPlatform is EglPlatformOpenGlInterface egl2) + _gl = new EglGlPlatformSurface(egl2, this); + else if (glPlatform is WglPlatformOpenGlInterface wgl) + _gl = new WglGlPlatformSurface(wgl.PrimaryContext, this); + } + } Screen = new ScreenImpl(); @@ -216,7 +243,7 @@ namespace Avalonia.Win32 { if (IsWindowVisible(_hwnd)) { - ShowWindow(value); + ShowWindow(value, true); } else { @@ -328,54 +355,63 @@ namespace Avalonia.Win32 private WindowTransparencyLevel Win10EnableBlur(WindowTransparencyLevel transparencyLevel) { - bool canUseAcrylic = Win32Platform.WindowsVersion.Major > 10 || Win32Platform.WindowsVersion.Build >= 19628; - - var accent = new AccentPolicy(); - var accentStructSize = Marshal.SizeOf(accent); - - if (transparencyLevel == WindowTransparencyLevel.AcrylicBlur && !canUseAcrylic) + if (_isUsingComposition) { - transparencyLevel = WindowTransparencyLevel.Blur; - } + _blurHost?.SetBlur(transparencyLevel >= WindowTransparencyLevel.Blur); - switch (transparencyLevel) + return transparencyLevel; + } + else { - default: - case WindowTransparencyLevel.None: - accent.AccentState = AccentState.ACCENT_DISABLED; - break; + bool canUseAcrylic = Win32Platform.WindowsVersion.Major > 10 || Win32Platform.WindowsVersion.Build >= 19628; - case WindowTransparencyLevel.Transparent: - accent.AccentState = AccentState.ACCENT_ENABLE_TRANSPARENTGRADIENT; - break; + var accent = new AccentPolicy(); + var accentStructSize = Marshal.SizeOf(accent); - case WindowTransparencyLevel.Blur: - accent.AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND; - break; + if (transparencyLevel == WindowTransparencyLevel.AcrylicBlur && !canUseAcrylic) + { + transparencyLevel = WindowTransparencyLevel.Blur; + } - case WindowTransparencyLevel.AcrylicBlur: - case (WindowTransparencyLevel.AcrylicBlur + 1): // hack-force acrylic. - accent.AccentState = AccentState.ACCENT_ENABLE_ACRYLIC; - transparencyLevel = WindowTransparencyLevel.AcrylicBlur; - break; - } + switch (transparencyLevel) + { + default: + case WindowTransparencyLevel.None: + accent.AccentState = AccentState.ACCENT_DISABLED; + break; + + case WindowTransparencyLevel.Transparent: + accent.AccentState = AccentState.ACCENT_ENABLE_TRANSPARENTGRADIENT; + break; + + case WindowTransparencyLevel.Blur: + accent.AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND; + break; + + case WindowTransparencyLevel.AcrylicBlur: + case (WindowTransparencyLevel.AcrylicBlur + 1): // hack-force acrylic. + accent.AccentState = AccentState.ACCENT_ENABLE_ACRYLIC; + transparencyLevel = WindowTransparencyLevel.AcrylicBlur; + break; + } - accent.AccentFlags = 2; - accent.GradientColor = 0x01000000; + accent.AccentFlags = 2; + accent.GradientColor = 0x01000000; - var accentPtr = Marshal.AllocHGlobal(accentStructSize); - Marshal.StructureToPtr(accent, accentPtr, false); + var accentPtr = Marshal.AllocHGlobal(accentStructSize); + Marshal.StructureToPtr(accent, accentPtr, false); - var data = new WindowCompositionAttributeData(); - data.Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY; - data.SizeOfData = accentStructSize; - data.Data = accentPtr; + var data = new WindowCompositionAttributeData(); + data.Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY; + data.SizeOfData = accentStructSize; + data.Data = accentPtr; - SetWindowCompositionAttribute(_hwnd, ref data); + SetWindowCompositionAttribute(_hwnd, ref data); - Marshal.FreeHGlobal(accentPtr); + Marshal.FreeHGlobal(accentPtr); - return transparencyLevel; + return transparencyLevel; + } } public IEnumerable Surfaces => new object[] { Handle, _gl, _framebuffer }; @@ -419,9 +455,14 @@ namespace Avalonia.Win32 if (customRendererFactory != null) return customRendererFactory.Create(root, loop); - return Win32Platform.UseDeferredRendering ? - (IRenderer)new DeferredRenderer(root, loop, rendererLock: _rendererLock) : - new ImmediateRenderer(root); + return Win32Platform.UseDeferredRendering + ? _isUsingComposition + ? new DeferredRenderer(root, loop) + { + RenderOnlyOnRenderThread = true + } + : (IRenderer)new DeferredRenderer(root, loop, rendererLock: _rendererLock) + : new ImmediateRenderer(root); } public void Resize(Size value) @@ -456,6 +497,8 @@ namespace Avalonia.Win32 public void Dispose() { + (_gl as IDisposable)?.Dispose(); + if (_dropTarget != null) { OleContext.Current?.UnregisterDragDrop(Handle); @@ -464,6 +507,13 @@ namespace Avalonia.Win32 if (_hwnd != IntPtr.Zero) { + // Detect if we are being closed programmatically - this would mean that WM_CLOSE was not called + // and we didn't prepare this window for destruction. + if (!_isCloseRequested) + { + BeforeCloseCleanup(true); + } + DestroyWindow(_hwnd); _hwnd = IntPtr.Zero; } @@ -517,10 +567,11 @@ namespace Avalonia.Win32 UnmanagedMethods.ShowWindow(_hwnd, ShowWindowCommand.Hide); } - public virtual void Show() + public virtual void Show(bool activate) { SetWindowLongPtr(_hwnd, (int)WindowLongParam.GWL_HWNDPARENT, _parent != null ? _parent._hwnd : IntPtr.Zero); - ShowWindow(_showWindowState); + + ShowWindow(_showWindowState, activate); } public Action GotInputWhenDisabled { get; set; } @@ -627,7 +678,7 @@ namespace Avalonia.Win32 protected virtual IntPtr CreateWindowOverride(ushort atom) { return CreateWindowEx( - 0, + _isUsingComposition ? (int)WindowStyles.WS_EX_NOREDIRECTIONBITMAP : 0, atom, null, (int)WindowStyles.WS_OVERLAPPEDWINDOW | (int) WindowStyles.WS_CLIPCHILDREN, @@ -863,7 +914,7 @@ namespace Avalonia.Win32 ExtendClientAreaToDecorationsChanged?.Invoke(_isClientAreaExtended); } - private void ShowWindow(WindowState state) + private void ShowWindow(WindowState state, bool activate) { ShowWindowCommand? command; @@ -873,7 +924,7 @@ namespace Avalonia.Win32 { case WindowState.Minimized: newWindowProperties.IsFullScreen = false; - command = ShowWindowCommand.Minimize; + command = activate ? ShowWindowCommand.Minimize : ShowWindowCommand.ShowMinNoActive; break; case WindowState.Maximized: newWindowProperties.IsFullScreen = false; @@ -882,7 +933,8 @@ namespace Avalonia.Win32 case WindowState.Normal: newWindowProperties.IsFullScreen = false; - command = ShowWindowCommand.Restore; + command = IsWindowVisible(_hwnd) ? ShowWindowCommand.Restore : + activate ? ShowWindowCommand.Normal : ShowWindowCommand.ShowNoActivate; break; case WindowState.FullScreen: @@ -911,6 +963,32 @@ namespace Avalonia.Win32 SetFocus(_hwnd); } } + + private void BeforeCloseCleanup(bool isDisposing) + { + // Based on https://github.com/dotnet/wpf/blob/master/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs#L4270-L4337 + // We need to enable parent window before destroying child window to prevent OS from activating a random window behind us (or last active window). + // This is described here: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enablewindow#remarks + // We need to verify if parent is still alive (perhaps it got destroyed somehow). + if (_parent != null && IsWindow(_parent._hwnd)) + { + var wasActive = GetActiveWindow() == _hwnd; + + // We can only set enabled state if we are not disposing - generally Dispose happens after enabled state has been set. + // Ignoring this would cause us to enable a window that might be disabled. + if (!isDisposing) + { + // Our window closed callback will set enabled state to a correct value after child window gets destroyed. + _parent.SetEnabled(true); + } + + // We also need to activate our parent window since again OS might try to activate a window behind if it is not set. + if (wasActive) + { + SetActiveWindow(_parent._hwnd); + } + } + } private void MaximizeWithoutCoveringTaskbar() { diff --git a/src/tools/Avalonia.Designer.HostApp/Avalonia.Designer.HostApp.csproj b/src/tools/Avalonia.Designer.HostApp/Avalonia.Designer.HostApp.csproj index 51d18e55d1..a2d27fd579 100644 --- a/src/tools/Avalonia.Designer.HostApp/Avalonia.Designer.HostApp.csproj +++ b/src/tools/Avalonia.Designer.HostApp/Avalonia.Designer.HostApp.csproj @@ -23,5 +23,8 @@ + + + diff --git a/src/tools/MicroComGenerator/Ast.cs b/src/tools/MicroComGenerator/Ast.cs new file mode 100644 index 0000000000..e9a55308be --- /dev/null +++ b/src/tools/MicroComGenerator/Ast.cs @@ -0,0 +1,241 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace MicroComGenerator.Ast +{ + public class AstAttributeNode + { + public string Name { get; set; } + public string Value { get; set; } + + public AstAttributeNode(string name, string value) + { + Name = name; + Value = value; + } + + public override string ToString() => $"{Name} = {Value}"; + public AstAttributeNode Clone() => new AstAttributeNode(Name, Value); + } + + public class AstAttributes : List + { + public bool HasAttribute(string a) => this.Any(x => x.Name == a); + + public AstAttributes Clone() + { + var rv= new AstAttributes(); + rv.AddRange(this.Select(x => x.Clone())); + return rv; + } + } + + public interface IAstNodeWithAttributes + { + public AstAttributes Attributes { get; set; } + } + + public class AstEnumNode : List, IAstNodeWithAttributes + { + public AstAttributes Attributes { get; set; } = new AstAttributes(); + public string Name { get; set; } + public override string ToString() => "Enum " + Name; + + public AstEnumNode Clone() + { + var rv = new AstEnumNode { Name = Name, Attributes = Attributes.Clone() }; + rv.AddRange(this.Select(x => x.Clone())); + return rv; + } + } + + public class AstEnumMemberNode + { + public string Name { get; set; } + public string Value { get; set; } + + public AstEnumMemberNode(string name, string value) + { + Name = name; + Value = value; + } + + public override string ToString() => $"Enum member {Name} = {Value}"; + public AstEnumMemberNode Clone() => new AstEnumMemberNode(Name, Value); + } + + public class AstStructNode : List, IAstNodeWithAttributes + { + public AstAttributes Attributes { get; set; } = new AstAttributes(); + public string Name { get; set; } + public override string ToString() => "Struct " + Name; + + public AstStructNode Clone() + { + var rv = new AstStructNode { Name = Name, Attributes = Attributes.Clone() }; + rv.AddRange(this.Select(x => x.Clone())); + return rv; + } + } + + public class AstTypeNode + { + public string Name { get; set; } + public int PointerLevel { get; set; } + public bool IsLink { get; set; } + + public string Format() => Name + new string('*', PointerLevel) + + (IsLink ? "&" : ""); + public override string ToString() => Format(); + public AstTypeNode Clone() => new AstTypeNode() { + Name = Name, + PointerLevel = PointerLevel, + IsLink = IsLink + }; + } + + public class AstStructMemberNode : IAstNodeWithAttributes + { + public string Name { get; set; } + public AstTypeNode Type { get; set; } + + public override string ToString() => $"Struct member {Type.Format()} {Name}"; + public AstStructMemberNode Clone() => new AstStructMemberNode() { Name = Name, Type = Type.Clone() }; + public AstAttributes Attributes { get; set; } = new AstAttributes(); + } + + public class AstInterfaceNode : List, IAstNodeWithAttributes + { + public AstAttributes Attributes { get; set; } = new AstAttributes(); + public string Name { get; set; } + public string Inherits { get; set; } + + public override string ToString() + { + if (Inherits == null) + return Name; + return $"Interface {Name} : {Inherits}"; + } + public AstInterfaceNode Clone() + { + var rv = new AstInterfaceNode { Name = Name, Inherits = Inherits, Attributes = Attributes.Clone() }; + rv.AddRange(this.Select(x => x.Clone())); + return rv; + } + } + + public class AstInterfaceMemberNode : List, IAstNodeWithAttributes + { + public string Name { get; set; } + public AstTypeNode ReturnType { get; set; } + public AstAttributes Attributes { get; set; } = new AstAttributes(); + + public AstInterfaceMemberNode Clone() + { + var rv = new AstInterfaceMemberNode() + { + Name = Name, Attributes = Attributes.Clone(), ReturnType = ReturnType + }; + rv.AddRange(this.Select(x => x.Clone())); + return rv; + } + + public override string ToString() => + $"Interface member {ReturnType.Format()} {Name} ({string.Join(", ", this.Select(x => x.Format()))})"; + } + + public class AstInterfaceMemberArgumentNode : IAstNodeWithAttributes + { + public string Name { get; set; } + public AstTypeNode Type { get; set; } + public AstAttributes Attributes { get; set; } = new AstAttributes(); + + + public string Format() => $"{Type.Format()} {Name}"; + public override string ToString() => "Argument " + Format(); + + public AstInterfaceMemberArgumentNode Clone() => new AstInterfaceMemberArgumentNode + { + Name = Name, Type = Type.Clone(), Attributes = Attributes.Clone() + }; + } + + public static class AstExtensions + { + public static bool HasAttribute(this IAstNodeWithAttributes node, string s) => node.Attributes.HasAttribute(s); + + public static string GetAttribute(this IAstNodeWithAttributes node, string s) + { + var value = node.Attributes.FirstOrDefault(a => a.Name == s)?.Value; + if (value == null) + throw new CodeGenException("Expected attribute " + s + " for node " + node); + return value; + } + + public static string GetAttributeOrDefault(this IAstNodeWithAttributes node, string s) + => node.Attributes.FirstOrDefault(a => a.Name == s)?.Value; + } + + class AstVisitor + { + protected virtual void VisitType(AstTypeNode type) + { + } + + protected virtual void VisitArgument(AstInterfaceMemberArgumentNode argument) + { + VisitType(argument.Type); + } + + protected virtual void VisitInterfaceMember(AstInterfaceMemberNode member) + { + foreach(var a in member) + VisitArgument(a); + VisitType(member.ReturnType); + } + + protected virtual void VisitInterface(AstInterfaceNode iface) + { + foreach(var m in iface) + VisitInterfaceMember(m); + } + + protected virtual void VisitStructMember(AstStructMemberNode member) + { + VisitType(member.Type); + } + + protected virtual void VisitStruct(AstStructNode node) + { + foreach(var m in node) + VisitStructMember(m); + } + + public virtual void VisitAst(AstIdlNode ast) + { + foreach(var iface in ast.Interfaces) + VisitInterface(iface); + foreach (var s in ast.Structs) + VisitStruct(s); + } + + + } + + public class AstIdlNode : IAstNodeWithAttributes + { + public AstAttributes Attributes { get; set; } = new AstAttributes(); + public List Enums { get; set; } = new List(); + public List Structs { get; set; } = new List(); + public List Interfaces { get; set; } = new List(); + + public AstIdlNode Clone() => new AstIdlNode() + { + Attributes = Attributes.Clone(), + Enums = Enums.Select(x => x.Clone()).ToList(), + Structs = Structs.Select(x => x.Clone()).ToList(), + Interfaces = Interfaces.Select(x => x.Clone()).ToList() + }; + } +} diff --git a/src/tools/MicroComGenerator/AstParser.cs b/src/tools/MicroComGenerator/AstParser.cs new file mode 100644 index 0000000000..388a8eb018 --- /dev/null +++ b/src/tools/MicroComGenerator/AstParser.cs @@ -0,0 +1,232 @@ +using System.Collections.Generic; +using MicroComGenerator.Ast; + +namespace MicroComGenerator +{ + public class AstParser + { + public static AstIdlNode Parse(string source) + { + var parser = new TokenParser(source); + var idl = new AstIdlNode { Attributes = ParseGlobalAttributes(ref parser) }; + + while (!parser.Eof) + { + var attrs = ParseLocalAttributes(ref parser); + if (parser.TryConsume(";")) + continue; + if (parser.TryParseKeyword("enum")) + idl.Enums.Add(ParseEnum(attrs, ref parser)); + else if (parser.TryParseKeyword("struct")) + idl.Structs.Add(ParseStruct(attrs, ref parser)); + else if (parser.TryParseKeyword("interface")) + idl.Interfaces.Add(ParseInterface(attrs, ref parser)); + else + throw new ParseException("Unexpected character", ref parser); + } + + return idl; + } + + static AstAttributes ParseGlobalAttributes(ref TokenParser parser) + { + var rv = new AstAttributes(); + while (!parser.Eof) + { + parser.SkipWhitespace(); + if (parser.TryConsume('@')) + { + var ident = parser.ParseIdentifier("-"); + var value = parser.ReadToEol().Trim(); + if (value == "@@") + { + parser.Advance(1); + value = ""; + while (true) + { + var l = parser.ReadToEol(); + if (l == "@@") + break; + else + value = value.Length == 0 ? l : (value + "\n" + l); + parser.Advance(1); + } + + } + rv.Add(new AstAttributeNode(ident, value)); + } + else + return rv; + } + + return rv; + } + + static AstAttributes ParseLocalAttributes(ref TokenParser parser) + { + var rv = new AstAttributes(); + while (parser.TryConsume("[")) + { + while (!parser.TryConsume("]") && !parser.Eof) + { + if (parser.TryConsume(',')) + continue; + + // Get identifier + var ident = parser.ParseIdentifier("-"); + + // No value, end of attribute list + if (parser.TryConsume(']')) + { + rv.Add(new AstAttributeNode(ident, null)); + break; + } + // No value, next attribute + else if (parser.TryConsume(',')) + rv.Add(new AstAttributeNode(ident, null)); + // Has value + else if (parser.TryConsume('(')) + { + var value = parser.ReadTo(')'); + parser.Consume(')'); + rv.Add(new AstAttributeNode(ident, value)); + } + else + throw new ParseException("Unexpected character", ref parser); + } + + if (parser.Eof) + throw new ParseException("Unexpected EOF", ref parser); + } + + return rv; + } + + static void EnsureOpenBracket(ref TokenParser parser) + { + if (!parser.TryConsume('{')) + throw new ParseException("{ expected", ref parser); + } + + static AstEnumNode ParseEnum(AstAttributes attrs, ref TokenParser parser) + { + var name = parser.ParseIdentifier(); + EnsureOpenBracket(ref parser); + var rv = new AstEnumNode { Name = name, Attributes = attrs }; + while (!parser.TryConsume('}') && !parser.Eof) + { + if (parser.TryConsume(',')) + continue; + + var ident = parser.ParseIdentifier(); + + // Automatic value + if (parser.TryConsume(',') || parser.Peek == '}') + { + rv.Add(new AstEnumMemberNode(ident, null)); + continue; + } + + if (!parser.TryConsume('=')) + throw new ParseException("Unexpected character", ref parser); + + var value = parser.ReadToAny(",}").Trim(); + rv.Add(new AstEnumMemberNode(ident, value)); + + if (parser.Eof) + throw new ParseException("Unexpected EOF", ref parser); + } + + + return rv; + } + + static AstTypeNode ParseType(ref TokenParser parser) + { + var ident = parser.ParseIdentifier(); + var t = new AstTypeNode { Name = ident }; + while (parser.TryConsume('*')) + t.PointerLevel++; + if (parser.TryConsume("&")) + t.IsLink = true; + return t; + } + + static AstStructNode ParseStruct(AstAttributes attrs, ref TokenParser parser) + { + var name = parser.ParseIdentifier(); + EnsureOpenBracket(ref parser); + var rv = new AstStructNode { Name = name, Attributes = attrs }; + while (!parser.TryConsume('}') && !parser.Eof) + { + var memberAttrs = ParseLocalAttributes(ref parser); + var t = ParseType(ref parser); + bool parsedAtLeastOneMember = false; + while (!parser.TryConsume(';')) + { + // Skip any , + while (parser.TryConsume(',')) { } + + var ident = parser.ParseIdentifier(); + parsedAtLeastOneMember = true; + rv.Add(new AstStructMemberNode { Name = ident, Type = t, Attributes = memberAttrs}); + } + + if (!parsedAtLeastOneMember) + throw new ParseException("Expected at least one enum member with declared type " + t, ref parser); + } + + return rv; + } + + static AstInterfaceNode ParseInterface(AstAttributes interfaceAttrs, ref TokenParser parser) + { + var interfaceName = parser.ParseIdentifier(); + string inheritsFrom = null; + if (parser.TryConsume(":")) + inheritsFrom = parser.ParseIdentifier(); + + EnsureOpenBracket(ref parser); + var rv = new AstInterfaceNode + { + Name = interfaceName, Attributes = interfaceAttrs, Inherits = inheritsFrom + }; + while (!parser.TryConsume('}') && !parser.Eof) + { + var memberAttrs = ParseLocalAttributes(ref parser); + var returnType = ParseType(ref parser); + var name = parser.ParseIdentifier(); + var member = new AstInterfaceMemberNode + { + Name = name, ReturnType = returnType, Attributes = memberAttrs + }; + rv.Add(member); + + parser.Consume('('); + while (true) + { + if (parser.TryConsume(')')) + break; + + var argumentAttrs = ParseLocalAttributes(ref parser); + var type = ParseType(ref parser); + var argName = parser.ParseIdentifier(); + member.Add(new AstInterfaceMemberArgumentNode + { + Name = argName, Type = type, Attributes = argumentAttrs + }); + + if (parser.TryConsume(')')) + break; + if (parser.TryConsume(',')) + continue; + throw new ParseException("Unexpected character", ref parser); + } + + parser.Consume(';'); + } + + return rv; + } + } +} diff --git a/src/tools/MicroComGenerator/CSharpGen.InterfaceGen.cs b/src/tools/MicroComGenerator/CSharpGen.InterfaceGen.cs new file mode 100644 index 0000000000..adb8faf938 --- /dev/null +++ b/src/tools/MicroComGenerator/CSharpGen.InterfaceGen.cs @@ -0,0 +1,484 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using MicroComGenerator.Ast; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; + +// ReSharper disable CoVariantArrayConversion + +// HERE BE DRAGONS + +namespace MicroComGenerator +{ + public partial class CSharpGen + { + abstract class Arg + { + public string Name; + public string NativeType; + public AstAttributes Attributes { get; set; } + public virtual StatementSyntax CreateFixed(StatementSyntax inner) => inner; + + public virtual void PreMarshal(List body) + { + } + + public virtual void PreMarshalForReturn(List body) => + throw new InvalidOperationException("Don't know how to use " + NativeType + " as HRESULT-return"); + + public virtual ExpressionSyntax Value(bool isHresultReturn) => ParseExpression(Name); + public abstract string ManagedType { get; } + public virtual string ReturnManagedType => ManagedType; + + public virtual StatementSyntax[] ReturnMarshalResult() => new[] { ParseStatement("return " + Name + ";") }; + + + public virtual void BackPreMarshal(List body) + { + } + + public virtual ExpressionSyntax BackMarshalValue() => ParseExpression(Name); + public virtual ExpressionSyntax BackMarshalReturn(string resultVar) => ParseExpression(resultVar); + + } + + class InterfaceReturnArg : Arg + { + public string InterfaceType; + public override ExpressionSyntax Value(bool isHresultReturn) => ParseExpression("&" + PName); + public override string ManagedType => InterfaceType; + + private string PName => "__marshal_" + Name; + + public override void PreMarshalForReturn(List body) + { + body.Add(ParseStatement("void* " + PName + " = null;")); + } + + public override StatementSyntax[] ReturnMarshalResult() => new[] + { + ParseStatement("return Avalonia.MicroCom.MicroComRuntime.CreateProxyFor<" + InterfaceType + ">(" + + PName + ", true);") + }; + + public override ExpressionSyntax BackMarshalValue() + { + return ParseExpression("INVALID"); + } + + public override ExpressionSyntax BackMarshalReturn(string resultVar) + { + return ParseExpression($"Avalonia.MicroCom.MicroComRuntime.GetNativePointer({resultVar}, true)"); + } + } + + class InterfaceArg : Arg + { + public string InterfaceType; + + public override ExpressionSyntax Value(bool isHresultReturn) => + ParseExpression("Avalonia.MicroCom.MicroComRuntime.GetNativePointer(" + Name + ")"); + + public override string ManagedType => InterfaceType; + + public override StatementSyntax[] ReturnMarshalResult() => new[] + { + ParseStatement("return Avalonia.MicroCom.MicroComRuntime.CreateProxyFor<" + InterfaceType + ">(" + + Name + ", true);") + }; + + public override ExpressionSyntax BackMarshalValue() + { + return ParseExpression("Avalonia.MicroCom.MicroComRuntime.CreateProxyFor<" + InterfaceType + ">(" + + Name + ", false)"); + } + + public override ExpressionSyntax BackMarshalReturn(string resultVar) + { + return ParseExpression($"Avalonia.MicroCom.MicroComRuntime.GetNativePointer({resultVar}, true)"); + } + } + + class BypassArg : Arg + { + public string Type { get; set; } + public int PointerLevel; + public override string ManagedType => Type + new string('*', PointerLevel); + public override string ReturnManagedType => Type + new string('*', PointerLevel - 1); + + public override ExpressionSyntax Value(bool isHresultReturn) + { + if (isHresultReturn) + return ParseExpression("&" + Name); + return base.Value(false); + } + + public override void PreMarshalForReturn(List body) + { + if (PointerLevel == 0) + base.PreMarshalForReturn(body); + else + body.Add(ParseStatement(Type + new string('*', PointerLevel - 1) + " " + Name + "=default;")); + } + } + + class StringArg : Arg + { + private string BName => "__bytemarshal_" + Name; + private string FName => "__fixedmarshal_" + Name; + + public override void PreMarshal(List body) + { + body.Add(ParseStatement($"var {BName} = new byte[System.Text.Encoding.UTF8.GetByteCount({Name})+1];")); + body.Add(ParseStatement($"System.Text.Encoding.UTF8.GetBytes({Name}, 0, {Name}.Length, {BName}, 0);")); + } + + public override StatementSyntax CreateFixed(StatementSyntax inner) + { + return FixedStatement(DeclareVar("byte*", FName, ParseExpression(BName)), inner); + } + + public override ExpressionSyntax Value(bool isHresultReturn) => ParseExpression(FName); + public override string ManagedType => "string"; + public override ExpressionSyntax BackMarshalValue() + { + return ParseExpression( + $"({Name} == null ? null : System.Runtime.InteropServices.Marshal.PtrToStringAnsi(new IntPtr(" + Name + ")))"); + } + } + + string ConvertNativeType(string type) + { + if (type == "size_t") + return "System.IntPtr"; + if (type == "HRESULT") + return "int"; + return type; + } + + Arg ConvertArg(AstInterfaceMemberArgumentNode node) + { + var arg = ConvertArg(node.Name, node.Type); + arg.Attributes = node.Attributes.Clone(); + return arg; + } + + Arg ConvertArg(string name, AstTypeNode type) + { + type = new AstTypeNode { Name = ConvertNativeType(type.Name), PointerLevel = type.PointerLevel }; + + if (type.PointerLevel == 2) + { + if (IsInterface(type)) + return new InterfaceReturnArg { Name = name, InterfaceType = type.Name, NativeType = "void**" }; + } + else if (type.PointerLevel == 1) + { + if (IsInterface(type)) + return new InterfaceArg { Name = name, InterfaceType = type.Name, NativeType = "void*" }; + if (type.Name == "char") + return new StringArg { Name = name, NativeType = "byte*" }; + } + + return new BypassArg + { + Name = name, Type = type.Name, PointerLevel = type.PointerLevel, NativeType = type.ToString() + }; + } + + + void GenerateInterfaceMember(AstInterfaceMemberNode member, ref InterfaceDeclarationSyntax iface, + ref ClassDeclarationSyntax proxy, ref ClassDeclarationSyntax vtbl, + List vtblCtor, int num) + { + // Prepare method information + if (member.Name == "GetRenderingDevice") + Console.WriteLine(); + var args = member.Select(ConvertArg).ToList(); + var returnArg = ConvertArg("__result", member.ReturnType); + bool isHresult = member.ReturnType.Name == "HRESULT"; + bool isHresultLastArgumentReturn = isHresult + && args.Count > 0 + && (args.Last().Name == "ppv" + || args.Last().Name == "retOut" + || args.Last().Name == "ret" + || args.Last().Attributes.HasAttribute("out") + || args.Last().Attributes.HasAttribute("retval") + ) + && ((member.Last().Type.PointerLevel > 0 + && !IsInterface(member.Last().Type)) + || member.Last().Type.PointerLevel == 2); + + bool isVoidReturn = member.ReturnType.Name == "void" && member.ReturnType.PointerLevel == 0; + + + // Generate method signature + MethodDeclarationSyntax GenerateManagedSig(string returnType, string name, + IEnumerable<(string n, string t)> args) + => MethodDeclaration(ParseTypeName(returnType), name).WithParameterList( + ParameterList( + SeparatedList(args.Select(x => Parameter(Identifier(x.n)).WithType(ParseTypeName(x.t)))))); + + var managedSig = + isHresult ? + GenerateManagedSig(isHresultLastArgumentReturn ? args.Last().ReturnManagedType : "void", + member.Name, + (isHresultLastArgumentReturn ? args.SkipLast(1) : args).Select(a => (a.Name, a.ManagedType))) : + GenerateManagedSig(returnArg.ManagedType, member.Name, args.Select(a => (a.Name, a.ManagedType))); + + iface = iface.AddMembers(managedSig.WithSemicolonToken(Semicolon())); + + // Prepare args for marshaling + var preMarshal = new List(); + if (!isVoidReturn) + preMarshal.Add(ParseStatement(returnArg.NativeType + " __result;")); + + for (var idx = 0; idx < args.Count; idx++) + { + if (isHresultLastArgumentReturn && idx == args.Count - 1) + args[idx].PreMarshalForReturn(preMarshal); + else + args[idx].PreMarshal(preMarshal); + } + + // Generate call expression + ExpressionSyntax callExpr = InvocationExpression(_localInterop.GetCaller(returnArg.NativeType, + args.Select(x => x.NativeType).ToList())) + .AddArgumentListArguments(Argument(ParseExpression("PPV"))) + .AddArgumentListArguments(args + .Select((a, i) => Argument(a.Value(isHresultLastArgumentReturn && i == args.Count - 1))).ToArray()) + .AddArgumentListArguments(Argument(ParseExpression("(*PPV)[base.VTableSize + " + num + "]"))); + + if (!isVoidReturn) + callExpr = CastExpression(ParseTypeName(returnArg.NativeType), callExpr); + + // Save call result if needed + if (!isVoidReturn) + callExpr = AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, ParseExpression("__result"), + callExpr); + + + // Wrap call into fixed() blocks + StatementSyntax callStatement = ExpressionStatement(callExpr); + foreach (var arg in args) + callStatement = arg.CreateFixed(callStatement); + + // Build proxy body + var proxyBody = Block() + .AddStatements(preMarshal.ToArray()) + .AddStatements(callStatement); + + // Process return value + if (!isVoidReturn) + { + if (isHresult) + { + proxyBody = proxyBody.AddStatements( + ParseStatement( + $"if(__result != 0) throw new System.Runtime.InteropServices.COMException(\"{member.Name} failed\", __result);")); + + if (isHresultLastArgumentReturn) + proxyBody = proxyBody.AddStatements(args.Last().ReturnMarshalResult()); + } + else + proxyBody = proxyBody.AddStatements(returnArg.ReturnMarshalResult()); + } + + // Add the proxy method + proxy = proxy.AddMembers(managedSig.AddModifiers(SyntaxKind.PublicKeyword) + .WithBody(proxyBody)); + + + // Generate VTable method + var shadowDelegate = DelegateDeclaration(ParseTypeName(returnArg.NativeType), member.Name + "Delegate") + .AddParameterListParameters(Parameter(Identifier("@this")).WithType(ParseTypeName("IntPtr"))) + .AddParameterListParameters(args.Select(x => + Parameter(Identifier(x.Name)).WithType(ParseTypeName(x.NativeType))).ToArray()) + .AddAttribute("System.Runtime.InteropServices.UnmanagedFunctionPointer", + "System.Runtime.InteropServices.CallingConvention.StdCall"); + + var shadowMethod = MethodDeclaration(shadowDelegate.ReturnType, member.Name) + .WithParameterList(shadowDelegate.ParameterList) + .AddModifiers(Token(SyntaxKind.StaticKeyword)); + + var backPreMarshal = new List(); + foreach (var arg in args) + arg.BackPreMarshal(backPreMarshal); + + backPreMarshal.Add( + ParseStatement($"__target = ({iface.Identifier.Text})Avalonia.MicroCom.MicroComRuntime.GetObjectFromCcw(@this);")); + + var isBackVoidReturn = isVoidReturn || (isHresult && !isHresultLastArgumentReturn); + + StatementSyntax backCallStatement; + + var backCallExpr = + IsPropertyRewriteCandidate(managedSig) ? + ParseExpression("__target." + member.Name.Substring(3)) : + InvocationExpression(ParseExpression("__target." + member.Name)) + .WithArgumentList(ArgumentList(SeparatedList( + (isHresultLastArgumentReturn ? args.SkipLast(1) : args) + .Select(a => + Argument(a.BackMarshalValue()))))); + + if (isBackVoidReturn) + backCallStatement = ExpressionStatement(backCallExpr); + else + { + backCallStatement = LocalDeclarationStatement(DeclareVar("var", "__result", backCallExpr)); + if (isHresultLastArgumentReturn) + { + backCallStatement = Block(backCallStatement, + ExpressionStatement(AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, + ParseExpression("*" + args.Last().Name), + args.Last().BackMarshalReturn("__result") + ))); + + } + else + backCallStatement = Block(backCallStatement, + ReturnStatement(returnArg.BackMarshalReturn("__result"))); + } + + BlockSyntax backBodyBlock = Block().AddStatements(backPreMarshal.ToArray()).AddStatements(backCallStatement); + + + var exceptions = new List() + { + CatchClause( + CatchDeclaration(ParseTypeName("System.Exception"), Identifier("__exception__")), null, + Block( + ParseStatement( + "Avalonia.MicroCom.MicroComRuntime.UnhandledException(__target, __exception__);"), + isHresult ? ParseStatement("return unchecked((int)0x80004005u);") + : isVoidReturn ? EmptyStatement() : ParseStatement("return default;") + )) + }; + + if (isHresult) + exceptions.Insert(0, CatchClause( + CatchDeclaration(ParseTypeName("System.Runtime.InteropServices.COMException"), + Identifier("__com_exception__")), + null, Block(ParseStatement("return __com_exception__.ErrorCode;")))); + + backBodyBlock = Block( + TryStatement( + List(exceptions)) + .WithBlock(Block(backBodyBlock)) + ); + if (isHresult) + backBodyBlock = backBodyBlock.AddStatements(ParseStatement("return 0;")); + + + backBodyBlock = Block() + .AddStatements(ParseStatement($"{iface.Identifier.Text} __target = null;")) + .AddStatements(backBodyBlock.Statements.ToArray()); + + shadowMethod = shadowMethod.WithBody(backBodyBlock); + + vtbl = vtbl.AddMembers(shadowDelegate).AddMembers(shadowMethod); + vtblCtor.Add(ParseStatement("base.AddMethod((" + shadowDelegate.Identifier.Text + ")" + + shadowMethod.Identifier.Text + ");")); + + + + + } + + class LocalInteropHelper + { + public ClassDeclarationSyntax Class { get; private set; } = ClassDeclaration("LocalInterop"); + private HashSet _existing = new HashSet(); + + public ExpressionSyntax GetCaller(string returnType, List args) + { + string ConvertType(string t) => t.EndsWith("*") ? "void*" : t; + returnType = ConvertType(returnType); + args = args.Select(ConvertType).ToList(); + + var name = "CalliStdCall" + returnType.Replace("*", "_ptr"); + var signature = returnType + "::" + name + "::" + string.Join("::", args); + if (_existing.Add(signature)) + { + Class = Class.AddMembers(MethodDeclaration(ParseTypeName(returnType), name) + .AddModifiers(SyntaxKind.StaticKeyword, SyntaxKind.UnsafeKeyword, SyntaxKind.PublicKeyword) + .AddParameterListParameters(Parameter(Identifier("thisObj")).WithType(ParseTypeName("void*"))) + .AddParameterListParameters(args.Select((x, i) => + Parameter(Identifier("arg" + i)).WithType(ParseTypeName(x))).ToArray()) + .AddParameterListParameters(Parameter(Identifier("methodPtr")).WithType(ParseTypeName("void*"))) + .WithBody(Block(ExpressionStatement(ThrowExpression(ParseExpression("null")))))); + } + + return ParseExpression("LocalInterop." + name); + } + } + + + void GenerateInterface(ref NamespaceDeclarationSyntax ns, ref NamespaceDeclarationSyntax implNs, + AstInterfaceNode iface) + { + var guidString = iface.GetAttribute("uuid"); + var inheritsUnknown = iface.Inherits == null || iface.Inherits == "IUnknown"; + + var ifaceDec = InterfaceDeclaration(iface.Name) + .WithBaseType(inheritsUnknown ? "Avalonia.MicroCom.IUnknown" : iface.Inherits) + .AddModifiers(Token(_visibility), Token(SyntaxKind.UnsafeKeyword), Token(SyntaxKind.PartialKeyword)); + + var proxyClassName = "__MicroCom" + iface.Name + "Proxy"; + var proxy = ClassDeclaration(proxyClassName) + .AddModifiers(Token(SyntaxKind.UnsafeKeyword), Token(_visibility), Token(SyntaxKind.PartialKeyword)) + .WithBaseType(inheritsUnknown ? + "Avalonia.MicroCom.MicroComProxyBase" : + ("__MicroCom" + iface.Inherits + "Proxy")) + .AddBaseListTypes(SimpleBaseType(ParseTypeName(iface.Name))); + + + // Generate vtable + var vtbl = ClassDeclaration("__MicroCom" + iface.Name + "VTable") + .AddModifiers(Token(SyntaxKind.UnsafeKeyword)); + + vtbl = vtbl.WithBaseType(inheritsUnknown ? + "Avalonia.MicroCom.MicroComVtblBase" : + "__MicroCom" + iface.Inherits + "VTable"); + + var vtblCtor = new List(); + for (var idx = 0; idx < iface.Count; idx++) + GenerateInterfaceMember(iface[idx], ref ifaceDec, ref proxy, ref vtbl, vtblCtor, idx); + + vtbl = vtbl.AddMembers( + ConstructorDeclaration(vtbl.Identifier.Text) + .AddModifiers(Token(SyntaxKind.PublicKeyword)) + .WithBody(Block(vtblCtor)) + ) + .AddMembers(MethodDeclaration(ParseTypeName("void"), "__MicroComModuleInit") + .AddModifiers(Token(SyntaxKind.StaticKeyword), Token(SyntaxKind.InternalKeyword)) + .WithExpressionBody(ArrowExpressionClause( + ParseExpression("Avalonia.MicroCom.MicroComRuntime.RegisterVTable(typeof(" + + iface.Name + "), new " + vtbl.Identifier.Text + "().CreateVTable())"))) + .WithSemicolonToken(Semicolon())); + + + // Finalize proxy code + proxy = proxy.AddMembers( + MethodDeclaration(ParseTypeName("void"), "__MicroComModuleInit") + .AddModifiers(Token(SyntaxKind.StaticKeyword), Token(SyntaxKind.InternalKeyword)) + .WithBody(Block( + ParseStatement("Avalonia.MicroCom.MicroComRuntime.Register(typeof(" + + iface.Name + "), new Guid(\"" + guidString + "\"), (p, owns) => new " + + proxyClassName + "(p, owns));") + ))) + .AddMembers(ParseMemberDeclaration("public " + proxyClassName + + "(IntPtr nativePointer, bool ownsHandle) : base(nativePointer, ownsHandle) {}")) + .AddMembers(ParseMemberDeclaration("protected override int VTableSize => base.VTableSize + " + + iface.Count + ";")); + + ns = ns.AddMembers(RewriteMethodsToProperties(ifaceDec)); + implNs = implNs.AddMembers(RewriteMethodsToProperties(proxy), RewriteMethodsToProperties(vtbl)); + } + } +} diff --git a/src/tools/MicroComGenerator/CSharpGen.Utils.cs b/src/tools/MicroComGenerator/CSharpGen.Utils.cs new file mode 100644 index 0000000000..da845b0ecd --- /dev/null +++ b/src/tools/MicroComGenerator/CSharpGen.Utils.cs @@ -0,0 +1,111 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using MicroComGenerator.Ast; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Formatting; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; +namespace MicroComGenerator +{ + public partial class CSharpGen + { + + CompilationUnitSyntax Unit() + => CompilationUnit().WithUsings(List(new[] + { + "System", "System.Text", "System.Collections", "System.Collections.Generic", "Avalonia.MicroCom" + } + .Concat(_extraUsings).Select(u => UsingDirective(IdentifierName(u))))); + + string Format(CompilationUnitSyntax unit) + { + var cw = new AdhocWorkspace(); + return + "#pragma warning disable 108\n" + + Microsoft.CodeAnalysis.Formatting.Formatter.Format(unit.NormalizeWhitespace(), cw, cw.Options + .WithChangedOption(CSharpFormattingOptions.NewLineForMembersInObjectInit, true) + .WithChangedOption(CSharpFormattingOptions.NewLinesForBracesInObjectCollectionArrayInitializers, + true) + .WithChangedOption(CSharpFormattingOptions.NewLineForMembersInAnonymousTypes, true) + .WithChangedOption(CSharpFormattingOptions.NewLinesForBracesInMethods, true) + + ).ToFullString(); + } + + + SyntaxToken Semicolon() => Token(SyntaxKind.SemicolonToken); + + static VariableDeclarationSyntax DeclareVar(string type, string name, + ExpressionSyntax? initializer = null) + => VariableDeclaration(ParseTypeName(type), + SingletonSeparatedList(VariableDeclarator(name) + .WithInitializer(initializer == null ? null : EqualsValueClause(initializer)))); + + FieldDeclarationSyntax DeclareConstant(string type, string name, LiteralExpressionSyntax value) + => FieldDeclaration( + VariableDeclaration(ParseTypeName(type), + SingletonSeparatedList( + VariableDeclarator(name).WithInitializer(EqualsValueClause(value)) + )) + ).WithSemicolonToken(Semicolon()) + .WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.ConstKeyword))); + + FieldDeclarationSyntax DeclareField(string type, string name, params SyntaxKind[] modifiers) => + DeclareField(type, name, null, modifiers); + + FieldDeclarationSyntax DeclareField(string type, string name, EqualsValueClauseSyntax initializer, + params SyntaxKind[] modifiers) => + FieldDeclaration( + VariableDeclaration(ParseTypeName(type), + SingletonSeparatedList( + VariableDeclarator(name).WithInitializer(initializer)))) + .WithSemicolonToken(Semicolon()) + .WithModifiers(TokenList(modifiers.Select(x => Token(x)))); + + bool IsPropertyRewriteCandidate(MethodDeclarationSyntax method) + { + + return + method.ReturnType.ToFullString() != "void" + && method.Identifier.Text.StartsWith("Get") + && method.ParameterList.Parameters.Count == 0; + } + + TypeDeclarationSyntax RewriteMethodsToProperties(T decl) where T : TypeDeclarationSyntax + { + var replace = new Dictionary(); + foreach (var method in decl.Members.OfType().ToList()) + { + if (IsPropertyRewriteCandidate(method)) + { + var getter = AccessorDeclaration(SyntaxKind.GetAccessorDeclaration); + if (method.Body != null) + getter = getter.WithBody(method.Body); + else + getter = getter.WithSemicolonToken(Semicolon()); + + replace[method] = PropertyDeclaration(method.ReturnType, + method.Identifier.Text.Substring(3)) + .WithModifiers(method.Modifiers).AddAccessorListAccessors(getter); + + } + } + + return decl.ReplaceNodes(replace.Keys, (m, m2) => replace[m]); + } + + bool IsInterface(string name) + { + if (name == "IUnknown") + return true; + return _idl.Interfaces.Any(i => i.Name == name); + } + + private bool IsInterface(AstTypeNode type) => IsInterface(type.Name); + + } +} diff --git a/src/tools/MicroComGenerator/CSharpGen.cs b/src/tools/MicroComGenerator/CSharpGen.cs new file mode 100644 index 0000000000..ff4c351fd9 --- /dev/null +++ b/src/tools/MicroComGenerator/CSharpGen.cs @@ -0,0 +1,155 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using MicroComGenerator.Ast; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; +// ReSharper disable CoVariantArrayConversion + +namespace MicroComGenerator +{ + public partial class CSharpGen + { + private readonly AstIdlNode _idl; + private List _extraUsings; + private string _namespace; + private SyntaxKind _visibility; + private LocalInteropHelper _localInterop = new LocalInteropHelper(); + + public CSharpGen(AstIdlNode idl) + { + _idl = idl.Clone(); + new AstRewriter(_idl.Attributes.Where(a => a.Name == "clr-map") + .Select(x => x.Value.Trim().Split(' ')) + .ToDictionary(x => x[0], x => x[1]) + ).VisitAst(_idl); + + _extraUsings = _idl.Attributes.Where(u => u.Name == "clr-using").Select(u => u.Value).ToList(); + _namespace = _idl.GetAttribute("clr-namespace"); + var visibilityString = _idl.GetAttribute("clr-access"); + + if (visibilityString == "internal") + _visibility = SyntaxKind.InternalKeyword; + else if (visibilityString == "public") + _visibility = SyntaxKind.PublicKeyword; + else + throw new CodeGenException("Invalid clr-access attribute"); + } + + class AstRewriter : AstVisitor + { + private readonly Dictionary _typeMap = new Dictionary(); + + public AstRewriter(Dictionary typeMap) + { + _typeMap = typeMap; + } + + void ConvertIntPtr(AstTypeNode type) + { + if (type.Name == "void" && type.PointerLevel > 0) + { + type.Name = "IntPtr"; + type.PointerLevel--; + } + } + + protected override void VisitStructMember(AstStructMemberNode member) + { + if (member.HasAttribute("intptr")) + ConvertIntPtr(member.Type); + base.VisitStructMember(member); + } + + protected override void VisitType(AstTypeNode type) + { + if (type.IsLink) + { + type.PointerLevel++; + type.IsLink = false; + } + + if (_typeMap.TryGetValue(type.Name, out var mapped)) + type.Name = mapped; + + base.VisitType(type); + } + + protected override void VisitArgument(AstInterfaceMemberArgumentNode argument) + { + if (argument.HasAttribute("intptr")) + { + if(argument.Name == "retOut") + Console.WriteLine(); + ConvertIntPtr(argument.Type); + } + + base.VisitArgument(argument); + } + + protected override void VisitInterfaceMember(AstInterfaceMemberNode member) + { + if (member.HasAttribute("intptr")) + ConvertIntPtr(member.ReturnType); + if (member.HasAttribute("propget") && !member.Name.StartsWith("Get")) + member.Name = "Get" + member.Name; + if (member.HasAttribute("propput") && !member.Name.StartsWith("Set")) + member.Name = "Set" + member.Name; + base.VisitInterfaceMember(member); + } + } + + + public string Generate() + { + var ns = NamespaceDeclaration(ParseName(_namespace)); + var implNs = NamespaceDeclaration(ParseName(_namespace + ".Impl")); + ns = GenerateEnums(ns); + ns = GenerateStructs(ns); + foreach (var i in _idl.Interfaces) + GenerateInterface(ref ns, ref implNs, i); + + implNs = implNs.AddMembers(_localInterop.Class); + var unit = Unit().AddMembers(ns, implNs); + + return Format(unit); + } + + NamespaceDeclarationSyntax GenerateEnums(NamespaceDeclarationSyntax ns) + { + return ns.AddMembers(_idl.Enums.Select(e => + { + var dec = EnumDeclaration(e.Name) + .WithModifiers(TokenList(Token(_visibility))) + .WithMembers(SeparatedList(e.Select(m => + { + var member = EnumMemberDeclaration(m.Name); + if (m.Value != null) + return member.WithEqualsValue(EqualsValueClause(ParseExpression(m.Value))); + return member; + }))); + if (e.HasAttribute("flags")) + dec = dec.AddAttribute("System.Flags"); + return dec; + }).ToArray()); + } + + NamespaceDeclarationSyntax GenerateStructs(NamespaceDeclarationSyntax ns) + { + return ns.AddMembers(_idl.Structs.Select(e => + StructDeclaration(e.Name) + .WithModifiers(TokenList(Token(_visibility))) + .AddAttribute("System.Runtime.InteropServices.StructLayout", "System.Runtime.InteropServices.LayoutKind.Sequential") + .AddModifiers(Token(SyntaxKind.UnsafeKeyword)) + .WithMembers(new SyntaxList(SeparatedList(e.Select(m => + DeclareField(m.Type.ToString(), m.Name, SyntaxKind.PublicKeyword))))) + ).ToArray()); + } + + + + } +} diff --git a/src/tools/MicroComGenerator/CppGen.cs b/src/tools/MicroComGenerator/CppGen.cs new file mode 100644 index 0000000000..b053088ca9 --- /dev/null +++ b/src/tools/MicroComGenerator/CppGen.cs @@ -0,0 +1,119 @@ +using System; +using System.Linq; +using System.Text; +using MicroComGenerator.Ast; + +namespace MicroComGenerator +{ + public class CppGen + { + static string ConvertType(AstTypeNode type) + { + var name = type.Name; + if (name == "byte") + name = "unsigned char"; + else if(name == "uint") + name = "unsigned int"; + + type = type.Clone(); + type.Name = name; + return type.Format(); + } + + public static string GenerateCpp(AstIdlNode idl) + { + var sb = new StringBuilder(); + var preamble = idl.GetAttributeOrDefault("cpp-preamble"); + if (preamble != null) + sb.AppendLine(preamble); + + foreach (var s in idl.Structs) + sb.AppendLine("struct " + s.Name + ";"); + + foreach (var s in idl.Interfaces) + sb.AppendLine("struct " + s.Name + ";"); + + foreach (var en in idl.Enums) + { + sb.Append("enum "); + if (en.Attributes.Any(a => a.Name == "class-enum")) + sb.Append("class "); + sb.AppendLine(en.Name).AppendLine("{"); + + foreach (var m in en) + { + sb.Append(" ").Append(m.Name); + if (m.Value != null) + sb.Append(" = ").Append(m.Value); + sb.AppendLine(","); + } + + sb.AppendLine("};"); + } + + foreach (var s in idl.Structs) + { + sb.Append("struct ").AppendLine(s.Name).AppendLine("{"); + foreach (var m in s) + sb.Append(" ").Append(ConvertType(m.Type)).Append(" ").Append(m.Name).AppendLine(";"); + + sb.AppendLine("};"); + } + + foreach (var i in idl.Interfaces) + { + var guidString = i.GetAttribute("uuid"); + var guid = Guid.Parse(guidString).ToString().Replace("-", ""); + + + sb.Append("COMINTERFACE(").Append(i.Name).Append(", ") + .Append(guid.Substring(0, 8)).Append(", ") + .Append(guid.Substring(8, 4)).Append(", ") + .Append(guid.Substring(12, 4)); + for (var c = 0; c < 8; c++) + { + sb.Append(", ").Append(guid.Substring(16 + c * 2, 2)); + } + + sb.Append(") : "); + if (i.HasAttribute("cpp-virtual-inherits")) + sb.Append("virtual "); + sb.AppendLine(i.Inherits ?? "IUnknown") + .AppendLine("{"); + + foreach (var m in i) + { + sb.Append(" ") + .Append("virtual ") + .Append(ConvertType(m.ReturnType)) + .Append(" ").Append(m.Name).Append(" ("); + if (m.Count == 0) + sb.AppendLine(") = 0;"); + else + { + sb.AppendLine(); + for (var c = 0; c < m.Count; c++) + { + var arg = m[c]; + sb.Append(" "); + if (arg.Attributes.Any(a => a.Name == "const")) + sb.Append("const "); + sb.Append(ConvertType(arg.Type)) + .Append(" ") + .Append(arg.Name); + if (c != m.Count - 1) + sb.Append(", "); + sb.AppendLine(); + } + + sb.AppendLine(" ) = 0;"); + } + } + + sb.AppendLine("};"); + } + + return sb.ToString(); + } + } +} diff --git a/src/tools/MicroComGenerator/Extensions.cs b/src/tools/MicroComGenerator/Extensions.cs new file mode 100644 index 0000000000..c8a4c8f45c --- /dev/null +++ b/src/tools/MicroComGenerator/Extensions.cs @@ -0,0 +1,97 @@ + +using System; +using System.Linq; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; +namespace MicroComGenerator +{ + public static class Extensions + { + public static ClassDeclarationSyntax AddModifiers(this ClassDeclarationSyntax cl, params SyntaxKind[] modifiers) + { + if (modifiers == null) + return cl; + return cl.AddModifiers(modifiers.Select(x => SyntaxFactory.Token(x)).ToArray()); + } + + public static MethodDeclarationSyntax AddModifiers(this MethodDeclarationSyntax cl, params SyntaxKind[] modifiers) + { + if (modifiers == null) + return cl; + return cl.AddModifiers(modifiers.Select(x => SyntaxFactory.Token(x)).ToArray()); + } + + public static PropertyDeclarationSyntax AddModifiers(this PropertyDeclarationSyntax cl, params SyntaxKind[] modifiers) + { + if (modifiers == null) + return cl; + return cl.AddModifiers(modifiers.Select(x => SyntaxFactory.Token(x)).ToArray()); + } + + public static ConstructorDeclarationSyntax AddModifiers(this ConstructorDeclarationSyntax cl, params SyntaxKind[] modifiers) + { + if (modifiers == null) + return cl; + return cl.AddModifiers(modifiers.Select(x => SyntaxFactory.Token(x)).ToArray()); + } + + public static AccessorDeclarationSyntax AddModifiers(this AccessorDeclarationSyntax cl, params SyntaxKind[] modifiers) + { + if (modifiers == null) + return cl; + return cl.AddModifiers(modifiers.Select(x => SyntaxFactory.Token(x)).ToArray()); + } + + public static string WithLowerFirst(this string s) + { + if (string.IsNullOrEmpty(s)) + return s; + return char.ToLowerInvariant(s[0]) + s.Substring(1); + } + + public static ExpressionSyntax MemberAccess(params string[] identifiers) + { + if (identifiers == null || identifiers.Length == 0) + throw new ArgumentException(); + var expr = (ExpressionSyntax)IdentifierName(identifiers[0]); + for (var c = 1; c < identifiers.Length; c++) + expr = MemberAccess(expr, identifiers[c]); + return expr; + } + + public static ExpressionSyntax MemberAccess(ExpressionSyntax expr, params string[] identifiers) + { + foreach (var i in identifiers) + expr = MemberAccess(expr, i); + return expr; + } + + public static MemberAccessExpressionSyntax MemberAccess(ExpressionSyntax expr, string identifier) => + MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, expr, IdentifierName(identifier)); + + public static ClassDeclarationSyntax WithBaseType(this ClassDeclarationSyntax cl, string bt) + { + return cl.AddBaseListTypes(SimpleBaseType(SyntaxFactory.ParseTypeName(bt))); + } + + public static InterfaceDeclarationSyntax WithBaseType(this InterfaceDeclarationSyntax cl, string bt) + { + return cl.AddBaseListTypes(SimpleBaseType(SyntaxFactory.ParseTypeName(bt))); + } + + public static T AddAttribute(this T member, string attribute, params string[] args) where T : MemberDeclarationSyntax + { + return (T)member.AddAttributeLists(AttributeList(SingletonSeparatedList( + Attribute(ParseName(attribute), AttributeArgumentList( + SeparatedList(args.Select(a => AttributeArgument(ParseExpression(a))))))))); + } + + public static string StripPrefix(this string s, string prefix) => string.IsNullOrEmpty(s) + ? s + : s.StartsWith(prefix) + ? s.Substring(prefix.Length) + : s; + } +} diff --git a/src/tools/MicroComGenerator/MicroComGenerator.csproj b/src/tools/MicroComGenerator/MicroComGenerator.csproj new file mode 100644 index 0000000000..5ae431b4b9 --- /dev/null +++ b/src/tools/MicroComGenerator/MicroComGenerator.csproj @@ -0,0 +1,10 @@ + + + Exe + netcoreapp3.1 + + + + + + diff --git a/src/tools/MicroComGenerator/ParseException.cs b/src/tools/MicroComGenerator/ParseException.cs new file mode 100644 index 0000000000..dfa8dcfe54 --- /dev/null +++ b/src/tools/MicroComGenerator/ParseException.cs @@ -0,0 +1,27 @@ +using System; + +namespace MicroComGenerator +{ + class ParseException : Exception + { + public int Line { get; } + public int Position { get; } + + public ParseException(string message, int line, int position) : base(message) + { + Line = line; + Position = position; + } + + public ParseException(string message, ref TokenParser parser) : this(message, parser.Line, parser.Position) + { + } + } + + class CodeGenException : Exception + { + public CodeGenException(string message) : base(message) + { + } + } +} diff --git a/src/tools/MicroComGenerator/Program.cs b/src/tools/MicroComGenerator/Program.cs new file mode 100644 index 0000000000..578ba1465d --- /dev/null +++ b/src/tools/MicroComGenerator/Program.cs @@ -0,0 +1,44 @@ +using System; +using System.IO; +using System.Linq; +using CommandLine; + +namespace MicroComGenerator +{ + class Program + { + public class Options + { + [Option('i', "input", Required = true, HelpText = "Input IDL file")] + public string Input { get; set; } + + [Option("cpp", Required = false, HelpText = "C++ output file")] + public string CppOutput { get; set; } + + [Option("cs", Required = false, HelpText = "C# output file")] + public string CSharpOutput { get; set; } + + } + + static int Main(string[] args) + { + var p = Parser.Default.ParseArguments(args); + if (p is NotParsed) + { + return 1; + } + + var opts = ((Parsed)p).Value; + + var text = File.ReadAllText(opts.Input); + var ast = AstParser.Parse(text); + + if (opts.CppOutput != null) + File.WriteAllText(opts.CppOutput, CppGen.GenerateCpp(ast)); + if (opts.CSharpOutput != null) + File.WriteAllText(opts.CSharpOutput, new CSharpGen(ast).Generate()); + + return 0; + } + } +} diff --git a/src/tools/MicroComGenerator/TokenParser.cs b/src/tools/MicroComGenerator/TokenParser.cs new file mode 100644 index 0000000000..ea8850b8e4 --- /dev/null +++ b/src/tools/MicroComGenerator/TokenParser.cs @@ -0,0 +1,417 @@ +using System; +using System.Globalization; +using System.IO; + +namespace MicroComGenerator +{ + internal ref struct TokenParser + { + private ReadOnlySpan _s; + public int Position { get; private set; } + public int Line { get; private set; } + public TokenParser(ReadOnlySpan s) + { + _s = s; + Position = 0; + Line = 0; + } + + public void SkipWhitespace() + { + while (true) + { + if(_s.Length == 0) + return; + if (char.IsWhiteSpace(_s[0])) + Advance(1); + else if (_s[0] == '/' && _s.Length>1) + { + if (_s[1] == '/') + SkipOneLineComment(); + else if (_s[1] == '*') + SkipMultiLineComment(); + else + return; + } + else + return; + } + } + + void SkipOneLineComment() + { + while (true) + { + if (_s.Length > 0 && _s[0] != '\n' && _s[0] != '\r') + Advance(1); + else + return; + } + } + + void SkipMultiLineComment() + { + var l = Line; + var p = Position; + while (true) + { + if (_s.Length == 0) + throw new ParseException("No matched */ found for /*", l, p); + + if (_s[0] == '*' && _s.Length > 1 && _s[1] == '/') + { + Advance(2); + return; + } + + Advance(1); + } + } + + static bool IsAlphaNumeric(char ch) => (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') || + (ch >= 'A' && ch <= 'Z'); + + public void Consume(char c) + { + if (!TryConsume(c)) + throw new ParseException("Expected " + c, Line, Position); + } + public bool TryConsume(char c) + { + SkipWhitespace(); + if (_s.Length == 0 || _s[0] != c) + return false; + + Advance(1); + return true; + } + + public bool TryConsume(string s) + { + SkipWhitespace(); + if (_s.Length < s.Length) + return false; + for (var c = 0; c < s.Length; c++) + { + if (_s[c] != s[c]) + return false; + } + + Advance(s.Length); + return true; + } + + public bool TryConsumeAny(ReadOnlySpan chars, out char token) + { + SkipWhitespace(); + token = default; + if (_s.Length == 0) + return false; + + foreach (var c in chars) + { + if (c == _s[0]) + { + token = c; + Advance(1); + return true; + } + } + + return false; + } + + + public bool TryParseKeyword(string keyword) + { + SkipWhitespace(); + if (keyword.Length > _s.Length) + return false; + for(var c=0; c keyword.Length && IsAlphaNumeric(_s[keyword.Length])) + return false; + + Advance(keyword.Length); + return true; + } + + public bool TryParseKeywordLowerCase(string keywordInLowerCase) + { + SkipWhitespace(); + if (keywordInLowerCase.Length > _s.Length) + return false; + for(var c=0; c keywordInLowerCase.Length && IsAlphaNumeric(_s[keywordInLowerCase.Length])) + return false; + + Advance(keywordInLowerCase.Length); + return true; + } + + public void Advance(int c) + { + while (c > 0) + { + if (_s[0] == '\n') + { + Line++; + Position = 0; + } + else + Position++; + + _s = _s.Slice(1); + c--; + } + } + + public int Length => _s.Length; + public bool Eof + { + get + { + SkipWhitespace(); + return Length == 0; + } + } + + public char Peek + { + get + { + if (_s.Length == 0) + throw new ParseException("Unexpected EOF", Line, Position); + return _s[0]; + } + } + + public string ParseIdentifier(ReadOnlySpan extraValidChars) + { + if (!TryParseIdentifier(extraValidChars, out var ident)) + throw new ParseException("Identifier expected", Line, Position); + return ident.ToString(); + } + + public string ParseIdentifier() + { + if (!TryParseIdentifier(out var ident)) + throw new ParseException("Identifier expected", Line, Position); + return ident.ToString(); + } + + public bool TryParseIdentifier(ReadOnlySpan extraValidChars, out ReadOnlySpan res) + { + res = ReadOnlySpan.Empty; + SkipWhitespace(); + if (_s.Length == 0) + return false; + var first = _s[0]; + if (!((first >= 'a' && first <= 'z') || (first >= 'A' && first <= 'Z') || first == '_')) + return false; + int len = 1; + for (var c = 1; c < _s.Length; c++) + { + var ch = _s[c]; + if (IsAlphaNumeric(ch) || ch == '_') + len++; + else + { + var found = false; + foreach(var vc in extraValidChars) + if (vc == ch) + { + found = true; + break; + } + + if (found) + len++; + else + break; + } + } + + res = _s.Slice(0, len); + Advance(len); + return true; + } + + public bool TryParseIdentifier(out ReadOnlySpan res) + { + res = ReadOnlySpan.Empty; + SkipWhitespace(); + if (_s.Length == 0) + return false; + var first = _s[0]; + if (!((first >= 'a' && first <= 'z') || (first >= 'A' && first <= 'Z') || first == '_')) + return false; + int len = 1; + for (var c = 1; c < _s.Length; c++) + { + var ch = _s[c]; + if (IsAlphaNumeric(ch) || ch == '_') + len++; + else + break; + } + + res = _s.Slice(0, len); + Advance(len); + return true; + } + + public string ReadToEol() + { + var initial = _s; + var len = 0; + while (true) + { + if (_s.Length > 0 && _s[0] != '\n' && _s[0] != '\r') + { + len++; + Advance(1); + } + else + return initial.Slice(0, len).ToString(); + } + } + + public string ReadTo(char c) + { + var initial = _s; + var len = 0; + var l = Line; + var p = Position; + while (true) + { + if (_s.Length == 0) + throw new ParseException("Expected " + c + " before EOF", l, p); + + if (_s[0] != c) + { + len++; + Advance(1); + } + else + return initial.Slice(0, len).ToString(); + } + } + + public string ReadToAny(ReadOnlySpan chars) + { + var initial = _s; + var len = 0; + var l = Line; + var p = Position; + while (true) + { + if (_s.Length == 0) + throw new ParseException("Expected any of '" + chars.ToString() + "' before EOF", l, p); + + var foundTerminator = false; + foreach (var term in chars) + { + if (_s[0] == term) + { + foundTerminator = true; + break; + } + } + + if (!foundTerminator) + { + len++; + Advance(1); + } + else + return initial.Slice(0, len).ToString(); + } + } + + public bool TryParseCall(out ReadOnlySpan res) + { + res = ReadOnlySpan.Empty; + SkipWhitespace(); + if (_s.Length == 0) + return false; + var first = _s[0]; + if (!((first >= 'a' && first <= 'z') || (first >= 'A' && first <= 'Z'))) + return false; + int len = 1; + for (var c = 1; c < _s.Length; c++) + { + var ch = _s[c]; + if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch<= 'Z') || ch == '.') + len++; + else + break; + } + + res = _s.Slice(0, len); + + // Find '(' + for (var c = len; c < _s.Length; c++) + { + if(char.IsWhiteSpace(_s[c])) + continue; + if(_s[c]=='(') + { + Advance(c + 1); + return true; + } + + return false; + + } + + return false; + + } + + + public bool TryParseFloat(out float res) + { + res = 0; + SkipWhitespace(); + if (_s.Length == 0) + return false; + + var len = 0; + var dotCount = 0; + for (var c = 0; c < _s.Length; c++) + { + var ch = _s[c]; + if (ch >= '0' && ch <= '9') + len = c + 1; + else if (ch == '.' && dotCount == 0) + { + len = c + 1; + dotCount++; + } + else + break; + } + + var span = _s.Slice(0, len); + +#if NETSTANDARD2_0 + if (!float.TryParse(span.ToString(), NumberStyles.Number, CultureInfo.InvariantCulture, out res)) + return false; +#else + if (!float.TryParse(span, NumberStyles.Number, CultureInfo.InvariantCulture, out res)) + return false; +#endif + Advance(len); + return true; + } + + public override string ToString() => _s.ToString(); + + } +} diff --git a/tests/Avalonia.Animation.UnitTests/Avalonia.Animation.UnitTests.csproj b/tests/Avalonia.Animation.UnitTests/Avalonia.Animation.UnitTests.csproj index dd50eff2b6..5b686dea4c 100644 --- a/tests/Avalonia.Animation.UnitTests/Avalonia.Animation.UnitTests.csproj +++ b/tests/Avalonia.Animation.UnitTests/Avalonia.Animation.UnitTests.csproj @@ -10,6 +10,7 @@ + diff --git a/tests/Avalonia.Base.UnitTests/Avalonia.Base.UnitTests.csproj b/tests/Avalonia.Base.UnitTests/Avalonia.Base.UnitTests.csproj index 0d87f0eb03..badfd09430 100644 --- a/tests/Avalonia.Base.UnitTests/Avalonia.Base.UnitTests.csproj +++ b/tests/Avalonia.Base.UnitTests/Avalonia.Base.UnitTests.csproj @@ -10,6 +10,7 @@ + @@ -17,4 +18,4 @@ - \ No newline at end of file + diff --git a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Binding.cs b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Binding.cs index 7fc0d52be6..7c4c5c96a5 100644 --- a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Binding.cs +++ b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Binding.cs @@ -4,6 +4,8 @@ using System.Reactive.Linq; using System.Reactive.Subjects; using System.Threading; using System.Threading.Tasks; + +using Avalonia.Controls; using Avalonia.Data; using Avalonia.Logging; using Avalonia.Platform; @@ -797,6 +799,24 @@ namespace Avalonia.Base.UnitTests Assert.False(source.SetterCalled); } + [Fact] + public void TwoWay_Binding_Should_Not_Fail_With_Null_DataContext() + { + var target = new TextBlock(); + target.DataContext = null; + + target.Bind(TextBlock.TextProperty, new Binding("Missing", BindingMode.TwoWay)); + } + + [Fact] + public void TwoWay_Binding_Should_Not_Fail_With_Null_DataContext_Indexer() + { + var target = new TextBlock(); + target.DataContext = null; + + target.Bind(TextBlock.TextProperty, new Binding("[0]", BindingMode.TwoWay)); + } + [Fact] public void Disposing_Completed_Binding_Does_Not_Throw() { diff --git a/tests/Avalonia.Base.UnitTests/AvaloniaPropertyTests.cs b/tests/Avalonia.Base.UnitTests/AvaloniaPropertyTests.cs index 8e5d8b7be2..1adb6988a2 100644 --- a/tests/Avalonia.Base.UnitTests/AvaloniaPropertyTests.cs +++ b/tests/Avalonia.Base.UnitTests/AvaloniaPropertyTests.cs @@ -27,7 +27,7 @@ namespace Avalonia.Base.UnitTests [Fact] public void GetMetadata_Returns_Supplied_Value() { - var metadata = new PropertyMetadata(); + var metadata = new AvaloniaPropertyMetadata(); var target = new TestProperty("test", typeof(Class1), metadata); Assert.Same(metadata, target.GetMetadata()); @@ -36,7 +36,7 @@ namespace Avalonia.Base.UnitTests [Fact] public void GetMetadata_Returns_Supplied_Value_For_Derived_Class() { - var metadata = new PropertyMetadata(); + var metadata = new AvaloniaPropertyMetadata(); var target = new TestProperty("test", typeof(Class1), metadata); Assert.Same(metadata, target.GetMetadata()); @@ -45,7 +45,7 @@ namespace Avalonia.Base.UnitTests [Fact] public void GetMetadata_Returns_Supplied_Value_For_Unrelated_Class() { - var metadata = new PropertyMetadata(); + var metadata = new AvaloniaPropertyMetadata(); var target = new TestProperty("test", typeof(Class3), metadata); Assert.Same(metadata, target.GetMetadata()); @@ -54,8 +54,8 @@ namespace Avalonia.Base.UnitTests [Fact] public void GetMetadata_Returns_Overridden_Value() { - var metadata = new PropertyMetadata(); - var overridden = new PropertyMetadata(); + var metadata = new AvaloniaPropertyMetadata(); + var overridden = new AvaloniaPropertyMetadata(); var target = new TestProperty("test", typeof(Class1), metadata); target.OverrideMetadata(overridden); @@ -66,9 +66,9 @@ namespace Avalonia.Base.UnitTests [Fact] public void OverrideMetadata_Should_Merge_Values() { - var metadata = new PropertyMetadata(BindingMode.TwoWay); + var metadata = new AvaloniaPropertyMetadata(BindingMode.TwoWay); var notify = (Action)((a, b) => { }); - var overridden = new PropertyMetadata(); + var overridden = new AvaloniaPropertyMetadata(); var target = new TestProperty("test", typeof(Class1), metadata); target.OverrideMetadata(overridden); @@ -129,19 +129,19 @@ namespace Avalonia.Base.UnitTests [Fact] public void PropertyMetadata_BindingMode_Default_Returns_OneWay() { - var data = new PropertyMetadata(defaultBindingMode: BindingMode.Default); + var data = new AvaloniaPropertyMetadata(defaultBindingMode: BindingMode.Default); Assert.Equal(BindingMode.OneWay, data.DefaultBindingMode); } private class TestProperty : AvaloniaProperty { - public TestProperty(string name, Type ownerType, PropertyMetadata metadata = null) - : base(name, ownerType, metadata ?? new PropertyMetadata()) + public TestProperty(string name, Type ownerType, AvaloniaPropertyMetadata metadata = null) + : base(name, ownerType, metadata ?? new AvaloniaPropertyMetadata()) { } - public void OverrideMetadata(PropertyMetadata metadata) + public void OverrideMetadata(AvaloniaPropertyMetadata metadata) { OverrideMetadata(typeof(T), metadata); } diff --git a/tests/Avalonia.Benchmarks/Layout/ControlsBenchmark.cs b/tests/Avalonia.Benchmarks/Layout/ControlsBenchmark.cs index 7170f6d7d4..3493dd0f53 100644 --- a/tests/Avalonia.Benchmarks/Layout/ControlsBenchmark.cs +++ b/tests/Avalonia.Benchmarks/Layout/ControlsBenchmark.cs @@ -17,7 +17,8 @@ namespace Avalonia.Benchmarks.Layout _app = UnitTestApplication.Start( TestServices.StyledWindow.With( renderInterface: new NullRenderingPlatform(), - threadingInterface: new NullThreadingPlatform())); + threadingInterface: new NullThreadingPlatform(), + standardCursorFactory: new NullCursorFactory())); _root = new TestRoot(true, null) { diff --git a/tests/Avalonia.Benchmarks/NullCursorFactory.cs b/tests/Avalonia.Benchmarks/NullCursorFactory.cs new file mode 100644 index 0000000000..012adce0f2 --- /dev/null +++ b/tests/Avalonia.Benchmarks/NullCursorFactory.cs @@ -0,0 +1,14 @@ +using System; +using Avalonia.Input; +using Avalonia.Platform; + +namespace Avalonia.Benchmarks +{ + internal class NullCursorFactory : IStandardCursorFactory + { + public IPlatformHandle GetCursor(StandardCursorType cursorType) + { + return new PlatformHandle(IntPtr.Zero, "null"); + } + } +} diff --git a/tests/Avalonia.Benchmarks/NullRenderingPlatform.cs b/tests/Avalonia.Benchmarks/NullRenderingPlatform.cs index f632d85c26..1570205456 100644 --- a/tests/Avalonia.Benchmarks/NullRenderingPlatform.cs +++ b/tests/Avalonia.Benchmarks/NullRenderingPlatform.cs @@ -28,7 +28,7 @@ namespace Avalonia.Benchmarks public IGeometryImpl CreateRectangleGeometry(Rect rect) { - throw new NotImplementedException(); + return new MockStreamGeometryImpl(); } public IStreamGeometryImpl CreateStreamGeometry() diff --git a/tests/Avalonia.Controls.DataGrid.UnitTests/Avalonia.Controls.DataGrid.UnitTests.csproj b/tests/Avalonia.Controls.DataGrid.UnitTests/Avalonia.Controls.DataGrid.UnitTests.csproj index 396dfee691..c0c9303767 100644 --- a/tests/Avalonia.Controls.DataGrid.UnitTests/Avalonia.Controls.DataGrid.UnitTests.csproj +++ b/tests/Avalonia.Controls.DataGrid.UnitTests/Avalonia.Controls.DataGrid.UnitTests.csproj @@ -12,6 +12,7 @@ + diff --git a/tests/Avalonia.Controls.UnitTests/Avalonia.Controls.UnitTests.csproj b/tests/Avalonia.Controls.UnitTests/Avalonia.Controls.UnitTests.csproj index 7a6d77ef46..6b17427eda 100644 --- a/tests/Avalonia.Controls.UnitTests/Avalonia.Controls.UnitTests.csproj +++ b/tests/Avalonia.Controls.UnitTests/Avalonia.Controls.UnitTests.csproj @@ -12,6 +12,7 @@ + diff --git a/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs b/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs index 783215fb5d..c8a30a42e9 100644 --- a/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs +++ b/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs @@ -40,6 +40,7 @@ namespace Avalonia.Controls.UnitTests Items = items, SelectedIndex = 0, }; + var root = new TestRoot(target); var rectangle = target.GetValue(ComboBox.SelectionBoxItemProperty) as Rectangle; Assert.NotNull(rectangle); diff --git a/tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs b/tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs index c179aef9ac..f3a1316c7d 100644 --- a/tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs +++ b/tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs @@ -44,6 +44,55 @@ namespace Avalonia.Controls.UnitTests } } + [Fact] + public void Open_Should_Use_Default_Control() + { + using (Application()) + { + var sut = new ContextMenu(); + var target = new Panel + { + ContextMenu = sut + }; + + var window = new Window { Content = target }; + window.ApplyTemplate(); + window.Presenter.ApplyTemplate(); + + bool opened = false; + + sut.MenuOpened += (sender, args) => + { + opened = true; + }; + + sut.Open(); + + Assert.True(opened); + } + } + + [Fact] + public void Open_Should_Raise_Exception_If_AlreadyDetached() + { + using (Application()) + { + var sut = new ContextMenu(); + var target = new Panel + { + ContextMenu = sut + }; + + var window = new Window { Content = target }; + window.ApplyTemplate(); + window.Presenter.ApplyTemplate(); + + target.ContextMenu = null; + + Assert.ThrowsAny(()=> sut.Open()); + } + } + [Fact] public void Closing_Raises_Single_Closed_Event() { @@ -79,7 +128,7 @@ namespace Avalonia.Controls.UnitTests { using (Application()) { - popupImpl.Setup(x => x.Show()).Verifiable(); + popupImpl.Setup(x => x.Show(true)).Verifiable(); popupImpl.Setup(x => x.Hide()).Verifiable(); var sut = new ContextMenu(); @@ -99,7 +148,7 @@ namespace Avalonia.Controls.UnitTests _mouse.Click(target); Assert.False(sut.IsOpen); - popupImpl.Verify(x => x.Show(), Times.Once); + popupImpl.Verify(x => x.Show(true), Times.Once); popupImpl.Verify(x => x.Hide(), Times.Once); } } @@ -109,7 +158,7 @@ namespace Avalonia.Controls.UnitTests { using (Application()) { - popupImpl.Setup(x => x.Show()).Verifiable(); + popupImpl.Setup(x => x.Show(true)).Verifiable(); popupImpl.Setup(x => x.Hide()).Verifiable(); var sut = new ContextMenu(); @@ -130,7 +179,7 @@ namespace Avalonia.Controls.UnitTests Assert.True(sut.IsOpen); popupImpl.Verify(x => x.Hide(), Times.Once); - popupImpl.Verify(x => x.Show(), Times.Exactly(2)); + popupImpl.Verify(x => x.Show(true), Times.Exactly(2)); } } @@ -177,7 +226,7 @@ namespace Avalonia.Controls.UnitTests { using (Application()) { - popupImpl.Setup(x => x.Show()).Verifiable(); + popupImpl.Setup(x => x.Show(true)).Verifiable(); bool eventCalled = false; var sut = new ContextMenu(); @@ -193,7 +242,7 @@ namespace Avalonia.Controls.UnitTests Assert.True(eventCalled); Assert.False(sut.IsOpen); - popupImpl.Verify(x => x.Show(), Times.Never); + popupImpl.Verify(x => x.Show(true), Times.Never); } } @@ -297,7 +346,7 @@ namespace Avalonia.Controls.UnitTests { using (Application()) { - popupImpl.Setup(x => x.Show()).Verifiable(); + popupImpl.Setup(x => x.Show(true)).Verifiable(); popupImpl.Setup(x => x.Hide()).Verifiable(); bool eventCalled = false; @@ -321,7 +370,7 @@ namespace Avalonia.Controls.UnitTests Assert.True(eventCalled); Assert.True(sut.IsOpen); - popupImpl.Verify(x => x.Show(), Times.Once()); + popupImpl.Verify(x => x.Show(true), Times.Once()); popupImpl.Verify(x => x.Hide(), Times.Never); } } diff --git a/tests/Avalonia.Controls.UnitTests/Selection/InternalSelectionModelTests.cs b/tests/Avalonia.Controls.UnitTests/Selection/InternalSelectionModelTests.cs index b64812e290..ce3e698cf3 100644 --- a/tests/Avalonia.Controls.UnitTests/Selection/InternalSelectionModelTests.cs +++ b/tests/Avalonia.Controls.UnitTests/Selection/InternalSelectionModelTests.cs @@ -205,6 +205,49 @@ namespace Avalonia.Controls.UnitTests.Selection Assert.Equal(2, target.SelectedIndex); } + [Fact] + public void Raises_Selection_Changed_On_Items_Reset() + { + var items = new ResettingCollection(new[] { "foo", "bar", "baz" }); + var target = CreateTarget(source: items); + + target.SelectedIndex = 1; + + var changed = new List(); + + target.PropertyChanged += (s, e) => changed.Add(e.PropertyName); + + var oldSelectedIndex = target.SelectedIndex; + var oldSelectedItem = target.SelectedItem; + + items.Reset(new string[0]); + + Assert.NotEqual(oldSelectedIndex, target.SelectedIndex); + Assert.NotEqual(oldSelectedItem, target.SelectedItem); + + Assert.Equal(-1, target.SelectedIndex); + Assert.Equal(null, target.SelectedItem); + + Assert.Contains(nameof(target.SelectedIndex), changed); + Assert.Contains(nameof(target.SelectedItem), changed); + } + + [Fact] + public void Preserves_SelectedItem_On_Items_Reset() + { + var items = new ResettingCollection(new[] { "foo", "bar", "baz" }); + var target = CreateTarget(source: items); + + target.SelectedItem = "foo"; + + Assert.Equal(0, target.SelectedIndex); + + items.Reset(new string[] { "baz", "foo", "bar" }); + + Assert.Equal("foo", target.SelectedItem); + Assert.Equal(1, target.SelectedIndex); + } + [Fact] public void Preserves_Selection_On_Source_Changed() { @@ -222,7 +265,7 @@ namespace Avalonia.Controls.UnitTests.Selection bool nullSource = false) { source ??= !nullSource ? new[] { "foo", "bar", "baz" } : null; - + var result = new InternalSelectionModel { SingleSelect = singleSelect, diff --git a/tests/Avalonia.Controls.UnitTests/Selection/SelectionModelTests_Multiple.cs b/tests/Avalonia.Controls.UnitTests/Selection/SelectionModelTests_Multiple.cs index 5d0c6d31e1..68bdbe51e8 100644 --- a/tests/Avalonia.Controls.UnitTests/Selection/SelectionModelTests_Multiple.cs +++ b/tests/Avalonia.Controls.UnitTests/Selection/SelectionModelTests_Multiple.cs @@ -1216,6 +1216,7 @@ namespace Avalonia.Controls.UnitTests.Selection var data = (AvaloniaList)target.Source!; var selectionChangedRaised = 0; var selectedIndexRaised = 0; + var selectedItemRaised = 0; var indexesChangedRaised = 0; target.Source = data; @@ -1227,6 +1228,11 @@ namespace Avalonia.Controls.UnitTests.Selection { ++selectedIndexRaised; } + + if (e.PropertyName == nameof(target.SelectedItem)) + { + ++selectedItemRaised; + } }; target.IndexesChanged += (s, e) => ++indexesChangedRaised; @@ -1249,6 +1255,7 @@ namespace Avalonia.Controls.UnitTests.Selection Assert.Equal(2, target.AnchorIndex); Assert.Equal(1, selectionChangedRaised); Assert.Equal(1, selectedIndexRaised); + Assert.Equal(1, selectedItemRaised); Assert.Equal(0, indexesChangedRaised); } diff --git a/tests/Avalonia.Controls.UnitTests/Selection/SelectionModelTests_Single.cs b/tests/Avalonia.Controls.UnitTests/Selection/SelectionModelTests_Single.cs index 66a2cef921..668af3b5d7 100644 --- a/tests/Avalonia.Controls.UnitTests/Selection/SelectionModelTests_Single.cs +++ b/tests/Avalonia.Controls.UnitTests/Selection/SelectionModelTests_Single.cs @@ -1040,6 +1040,7 @@ namespace Avalonia.Controls.UnitTests.Selection var data = (AvaloniaList)target.Source!; var selectionChangedRaised = 0; var selectedIndexRaised = 0; + var selectedItemRaised = 0; target.Source = data; target.Select(1); @@ -1050,6 +1051,11 @@ namespace Avalonia.Controls.UnitTests.Selection { ++selectedIndexRaised; } + + if (e.PropertyName == nameof(target.SelectedItem)) + { + ++selectedItemRaised; + } }; target.SelectionChanged += (s, e) => @@ -1070,6 +1076,7 @@ namespace Avalonia.Controls.UnitTests.Selection Assert.Equal(-1, target.AnchorIndex); Assert.Equal(1, selectionChangedRaised); Assert.Equal(1, selectedIndexRaised); + Assert.Equal(1, selectedItemRaised); } [Fact] diff --git a/tests/Avalonia.Controls.UnitTests/TreeViewTests.cs b/tests/Avalonia.Controls.UnitTests/TreeViewTests.cs index b805683393..cea77bb7c9 100644 --- a/tests/Avalonia.Controls.UnitTests/TreeViewTests.cs +++ b/tests/Avalonia.Controls.UnitTests/TreeViewTests.cs @@ -675,6 +675,50 @@ namespace Avalonia.Controls.UnitTests Assert.Same(node, focus.Current); } } + + [Fact] + public void Keyboard_Navigation_Should_Not_Crash_If_Selected_Item_Is_not_In_Tree() + { + using (Application()) + { + var focus = FocusManager.Instance; + var navigation = AvaloniaLocator.Current.GetService(); + var data = CreateTestTreeData(); + + var selectedNode = new Node { Value = "Out of Tree Selected Item" }; + + var target = new TreeView + { + Template = CreateTreeViewTemplate(), + Items = data, + SelectedItem = selectedNode + }; + + var button = new Button(); + + var root = new TestRoot + { + Child = new StackPanel + { + Children = { target, button }, + } + }; + + CreateNodeDataTemplate(target); + ApplyTemplates(target); + ExpandAll(target); + + var item = data[0].Children[0]; + var node = target.ItemContainerGenerator.Index.ContainerFromItem(item); + Assert.NotNull(node); + + target.SelectedItem = selectedNode; + node.Focus(); + Assert.Same(node, focus.Current); + + var next = KeyboardNavigationHandler.GetNext(node, NavigationDirection.Previous); + } + } [Fact] public void Pressing_SelectAll_Gesture_Should_Select_All_Nodes() diff --git a/tests/Avalonia.Controls.UnitTests/Utils/HotKeyManagerTests.cs b/tests/Avalonia.Controls.UnitTests/Utils/HotKeyManagerTests.cs index 9f2712c93c..151c3070f4 100644 --- a/tests/Avalonia.Controls.UnitTests/Utils/HotKeyManagerTests.cs +++ b/tests/Avalonia.Controls.UnitTests/Utils/HotKeyManagerTests.cs @@ -5,6 +5,9 @@ using Avalonia.Input; using Avalonia.Platform; using Avalonia.Styling; using Xunit; +using System; +using Avalonia.Input.Raw; +using Factory = System.Func, Avalonia.Controls.Window, Avalonia.AvaloniaObject>; namespace Avalonia.Controls.UnitTests.Utils { @@ -54,6 +57,127 @@ namespace Avalonia.Controls.UnitTests.Utils } } + [Theory] + [MemberData(nameof(ElementsFactory))] + public void HotKeyManager_Should_Use_CommandParameter(string factoryName, Factory factory) + { + using (AvaloniaLocator.EnterScope()) + { + var styler = new Mock(); + var target = new KeyboardDevice(); + var commandResult = 0; + var expectedParameter = 1; + AvaloniaLocator.CurrentMutable + .Bind().ToConstant(new WindowingPlatformMock()) + .Bind().ToConstant(styler.Object); + + var gesture = new KeyGesture(Key.A, KeyModifiers.Control); + + var action = new Action(parameter => + { + if (parameter is int value) + { + commandResult = value; + } + }); + + var root = new Window(); + var element = factory(expectedParameter, action, root); + + root.Template = CreateWindowTemplate(); + root.ApplyTemplate(); + root.Presenter.ApplyTemplate(); + + HotKeyManager.SetHotKey(element, gesture); + + target.ProcessRawEvent(new RawKeyEventArgs(target, + 0, + root, + RawKeyEventType.KeyDown, + Key.A, + RawInputModifiers.Control)); + + Assert.True(expectedParameter == commandResult, $"{factoryName} HotKey did not carry the CommandParameter."); + } + } + + + [Theory] + [MemberData(nameof(ElementsFactory))] + public void HotKeyManager_Should_Do_Not_Executed_When_IsEnabled_False(string factoryName, Factory factory) + { + using (AvaloniaLocator.EnterScope()) + { + var styler = new Mock(); + var target = new KeyboardDevice(); + var isExecuted = false; + AvaloniaLocator.CurrentMutable + .Bind().ToConstant(new WindowingPlatformMock()) + .Bind().ToConstant(styler.Object); + + var gesture = new KeyGesture(Key.A, KeyModifiers.Control); + + var action = new Action(parameter => + { + isExecuted = true; + }); + + var root = new Window(); + var element = factory(0, action, root) as InputElement; + + element.IsEnabled = false; + + root.Template = CreateWindowTemplate(); + root.ApplyTemplate(); + root.Presenter.ApplyTemplate(); + + HotKeyManager.SetHotKey(element, gesture); + + target.ProcessRawEvent(new RawKeyEventArgs(target, + 0, + root, + RawKeyEventType.KeyDown, + Key.A, + RawInputModifiers.Control)); + + Assert.True(isExecuted == false, $"{factoryName} Execution raised when IsEnabled is false."); + } + } + + public static TheoryData ElementsFactory => + new TheoryData() + { + {nameof(Button), MakeButton}, + {nameof(MenuItem),MakeMenu}, + }; + + private static AvaloniaObject MakeMenu(int expectedParameter, Action action, Window root) + { + var menuitem = new MenuItem() + { + Command = new Command(action), + CommandParameter = expectedParameter, + }; + var rootMenu = new Menu(); + + rootMenu.Items = new[] { menuitem }; + + root.Content = rootMenu; + return menuitem; + } + + private static AvaloniaObject MakeButton(int expectedParameter, Action action, Window root) + { + var button = new Button() + { + Command = new Command(action), + CommandParameter = expectedParameter, + }; + + root.Content = button; + return button; + } + private FuncControlTemplate CreateWindowTemplate() { return new FuncControlTemplate((parent, scope) => @@ -65,5 +189,22 @@ namespace Avalonia.Controls.UnitTests.Utils }.RegisterInNameScope(scope); }); } + + class Command : System.Windows.Input.ICommand + { + private readonly Action _execeute; + +#pragma warning disable 67 // Event not used + public event EventHandler CanExecuteChanged; +#pragma warning restore 67 // Event not used + + public Command(Action execeute) + { + _execeute = execeute; + } + public bool CanExecute(object parameter) => true; + + public void Execute(object parameter) => _execeute?.Invoke(parameter); + } } } diff --git a/tests/Avalonia.Controls.UnitTests/WindowBaseTests.cs b/tests/Avalonia.Controls.UnitTests/WindowBaseTests.cs index 84f212d1b3..8109b037c5 100644 --- a/tests/Avalonia.Controls.UnitTests/WindowBaseTests.cs +++ b/tests/Avalonia.Controls.UnitTests/WindowBaseTests.cs @@ -137,7 +137,7 @@ namespace Avalonia.Controls.UnitTests var target = new TestWindowBase(windowImpl.Object); target.IsVisible = true; - windowImpl.Verify(x => x.Show()); + windowImpl.Verify(x => x.Show(true)); } } diff --git a/tests/Avalonia.DesignerSupport.Tests/DesignerSupportTests.cs b/tests/Avalonia.DesignerSupport.Tests/DesignerSupportTests.cs index dd704bc775..d76ed9042f 100644 --- a/tests/Avalonia.DesignerSupport.Tests/DesignerSupportTests.cs +++ b/tests/Avalonia.DesignerSupport.Tests/DesignerSupportTests.cs @@ -11,6 +11,7 @@ using System.Threading; using System.Threading.Tasks; using Avalonia.Remote.Protocol; using Avalonia.Remote.Protocol.Designer; +using Avalonia.Remote.Protocol.Viewport; using Xunit; using Xunit.Extensions; @@ -31,19 +32,38 @@ namespace Avalonia.DesignerSupport.Tests @"..\..\..\..\..\tests/Avalonia.DesignerSupport.TestApp/bin/$BUILD/netcoreapp3.1/", "Avalonia.DesignerSupport.TestApp", "Avalonia.DesignerSupport.TestApp.dll", - @"..\..\..\..\..\tests\Avalonia.DesignerSupport.TestApp\MainWindow.xaml"), + @"..\..\..\..\..\tests\Avalonia.DesignerSupport.TestApp\MainWindow.xaml", + "win32"), InlineData( @"..\..\..\..\..\samples\ControlCatalog.NetCore\bin\$BUILD\netcoreapp3.1\", "ControlCatalog.NetCore", "ControlCatalog.dll", - @"..\..\..\..\..\samples\ControlCatalog\MainWindow.xaml")] + @"..\..\..\..\..\samples\ControlCatalog\MainWindow.xaml", + "win32"), + InlineData( + @"..\..\..\..\..\tests/Avalonia.DesignerSupport.TestApp/bin/$BUILD/netcoreapp3.1/", + "Avalonia.DesignerSupport.TestApp", + "Avalonia.DesignerSupport.TestApp.dll", + @"..\..\..\..\..\tests\Avalonia.DesignerSupport.TestApp\MainWindow.xaml", + "avalonia-remote"), + InlineData( + @"..\..\..\..\..\samples\ControlCatalog.NetCore\bin\$BUILD\netcoreapp3.1\", + "ControlCatalog.NetCore", + "ControlCatalog.dll", + @"..\..\..\..\..\samples\ControlCatalog\MainWindow.xaml", + "avalonia-remote")] public async Task Designer_In_Win32_Mode_Should_Provide_Valid_Hwnd( string outputDir, string executableName, string assemblyName, - string xamlFile) + string xamlFile, + string method) { - Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + outputDir = Path.GetFullPath(outputDir.Replace('\\', Path.DirectorySeparatorChar)); + xamlFile = Path.GetFullPath(xamlFile.Replace('\\', Path.DirectorySeparatorChar)); + + if (method == "win32") + Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); var xaml = File.ReadAllText(xamlFile); string buildType; @@ -56,6 +76,8 @@ namespace Avalonia.DesignerSupport.Tests var sessionId = Guid.NewGuid(); long handle = 0; + bool success = false; + string error = null; var resultMessageReceivedToken = new CancellationTokenSource(); @@ -71,6 +93,18 @@ namespace Avalonia.DesignerSupport.Tests if (msg is StartDesignerSessionMessage start) { Assert.Equal(sessionId, Guid.Parse(start.SessionId)); + if (method == "avalonia-remote") + { + await conn.Send(new ClientSupportedPixelFormatsMessage + { + Formats = new[] { PixelFormat.Rgba8888 } + }); + await conn.Send(new ClientViewportAllocatedMessage + { + DpiX = 96, DpiY = 96, Width = 1024, Height = 768 + }); + } + await conn.Send(new UpdateXamlMessage { AssemblyPath = Path.Combine(outputDir, assemblyName), @@ -80,8 +114,14 @@ namespace Avalonia.DesignerSupport.Tests else if (msg is UpdateXamlResultMessage result) { if (result.Error != null) + { + error = result.Error; outputHelper.WriteLine(result.Error); - handle = result.Handle != null ? long.Parse(result.Handle) : 0; + } + else + success = true; + if (method == "win32") + handle = result.Handle != null ? long.Parse(result.Handle) : 0; resultMessageReceivedToken.Cancel(); conn.Dispose(); } @@ -91,7 +131,7 @@ namespace Avalonia.DesignerSupport.Tests var cmdline = $"exec --runtimeconfig \"{outputDir}{executableName}.runtimeconfig.json\" --depsfile \"{outputDir}{executableName}.deps.json\" " + $" \"{DesignerAppPath.Replace("$BUILD", buildType)}\" " - + $"--transport tcp-bson://127.0.0.1:{port}/ --session-id {sessionId} --method win32 \"{outputDir}{executableName}.dll\""; + + $"--transport tcp-bson://127.0.0.1:{port}/ --session-id {sessionId} --method {method} \"{outputDir}{executableName}.dll\""; using (var proc = new Process { @@ -128,10 +168,15 @@ namespace Avalonia.DesignerSupport.Tests } proc.WaitForExit(); + var stdout = proc.StandardOutput.ReadToEnd(); + var stderr = proc.StandardError.ReadToEnd(); Assert.True(cancelled, $"Message Not Received.\n" + proc.StandardOutput.ReadToEnd() + "\n" + - proc.StandardError.ReadToEnd()); - Assert.NotEqual(0, handle); + stderr + "\n" + stdout); + Assert.True(success, error); + if (method == "win32") + Assert.NotEqual(0, handle); + } } diff --git a/tests/Avalonia.DesignerSupport.Tests/Remote/HtmlTransport/webapp/.gitignore b/tests/Avalonia.DesignerSupport.Tests/Remote/HtmlTransport/webapp/.gitignore new file mode 100644 index 0000000000..dc33b94747 --- /dev/null +++ b/tests/Avalonia.DesignerSupport.Tests/Remote/HtmlTransport/webapp/.gitignore @@ -0,0 +1,3 @@ +build +node_modules +.nyc_output \ No newline at end of file diff --git a/tests/Avalonia.DesignerSupport.Tests/Remote/HtmlTransport/webapp/Models/InputEventTests.ts b/tests/Avalonia.DesignerSupport.Tests/Remote/HtmlTransport/webapp/Models/InputEventTests.ts new file mode 100644 index 0000000000..e96c4d4731 --- /dev/null +++ b/tests/Avalonia.DesignerSupport.Tests/Remote/HtmlTransport/webapp/Models/InputEventTests.ts @@ -0,0 +1,94 @@ +import { describe } from 'mocha'; +import { expect } from 'chai'; +import { Mock } from "moq.ts"; +import { MouseEvent, WheelEvent } from "react"; +import { InputModifiers } from "../../../../../../src/Avalonia.DesignerSupport/Remote/HtmlTransport/webapp/src/Models/Input/InputModifiers"; +import { MouseButton } from "../../../../../../src/Avalonia.DesignerSupport/Remote/HtmlTransport/webapp/src/Models/Input/MouseButton"; +import { PointerMovedEventMessage } from "../../../../../../src/Avalonia.DesignerSupport/Remote/HtmlTransport/webapp/src/Models/Input/PointerMovedEventMessage"; +import { PointerPressedEventMessage } from "../../../../../../src/Avalonia.DesignerSupport/Remote/HtmlTransport/webapp/src/Models/Input/PointerPressedEventMessage"; +import { PointerReleasedEventMessage } from "../../../../../../src/Avalonia.DesignerSupport/Remote/HtmlTransport/webapp/src/Models/Input/PointerReleasedEventMessage"; +import { ScrollEventMessage } from "../../../../../../src/Avalonia.DesignerSupport/Remote/HtmlTransport/webapp/src/Models/Input/ScrollEventMessage"; +import { getModifiers, getMouseButton } from '../../../../../../src/Avalonia.DesignerSupport/Remote/HtmlTransport/webapp/src/Models/Input/MouseEventHelpers'; + +describe("Input event tests", () => { + describe("Helpers", () => { + it("getModifiers", () => { + const event = new Mock() + .setup(x => x.altKey).returns(false) + .setup(x => x.ctrlKey).returns(true) + .setup(x => x.shiftKey).returns(false) + .setup(x => x.metaKey).returns(false) + .setup(x => x.buttons).returns(1) + .object() + var actual = getModifiers(event) + + expect(actual) + .eql([InputModifiers.Control, InputModifiers.LeftMouseButton]) + }) + it("getMouseButton", () => { + const event = new Mock() + .setup(x => x.button).returns(1) + .object() + var actual = getMouseButton(event) + + expect(actual) + .equal(MouseButton.Middle) + }) + }) + + describe("Messages", () => { + const x = .3 + const y = .42 + const modifiers = "0,1,2,3,4,5,6" + + const button = "1" + + const deltaX = -3. + const deltaY = -3. + + const mouseEvent = new Mock() + .setup(x => x.altKey).returns(true) + .setup(x => x.ctrlKey).returns(true) + .setup(x => x.shiftKey).returns(true) + .setup(x => x.metaKey).returns(true) + .setup(x => x.buttons).returns(7) + .setup(x => x.button).returns(0) + .setup(x => x.clientX).returns(x) + .setup(x => x.clientY).returns(y) + .object() + + it("PointerMovedEventMessage", () => { + const message = new PointerMovedEventMessage(mouseEvent) + expect(message.toString()) + .equal(`pointer-moved:${modifiers}:${x}:${y}`) + }) + it("PointerPressedEventMessage", () => { + const message = new PointerPressedEventMessage(mouseEvent) + expect(message.toString()) + .equal(`pointer-pressed:${modifiers}:${x}:${y}:${button}`) + }) + it("PointerReleasedEventMessage", () => { + const message = new PointerReleasedEventMessage(mouseEvent) + expect(message.toString()) + .equal(`pointer-released:${modifiers}:${x}:${y}:${button}`) + }) + + it("ScrollEventMessage", () => { + const wheelEvent = new Mock() + .setup(x => x.altKey).returns(true) + .setup(x => x.ctrlKey).returns(true) + .setup(x => x.shiftKey).returns(true) + .setup(x => x.metaKey).returns(true) + .setup(x => x.buttons).returns(7) + .setup(x => x.clientX).returns(x) + .setup(x => x.clientY).returns(y) + .setup(x => x.deltaX).returns(-deltaX) + .setup(x => x.deltaY).returns(-deltaY) + .object() + const message = new ScrollEventMessage(wheelEvent) + + expect(message.toString()) + .equal(`scroll:${modifiers}:${x}:${y}:${deltaX}:${deltaY}`) + }) + }) +}) diff --git a/tests/Avalonia.DesignerSupport.Tests/Remote/HtmlTransport/webapp/package-lock.json b/tests/Avalonia.DesignerSupport.Tests/Remote/HtmlTransport/webapp/package-lock.json new file mode 100644 index 0000000000..eb707cb73f --- /dev/null +++ b/tests/Avalonia.DesignerSupport.Tests/Remote/HtmlTransport/webapp/package-lock.json @@ -0,0 +1,2414 @@ +{ + "name": "simple-test", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@babel/code-frame": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.10.4.tgz", + "integrity": "sha512-vG6SvB6oYEhvgisZNFRmRCUkLz11c7rp+tbNTynGqc6mS1d5ATd/sGyV6W0KZZnXRKMTzZDRgQT3Ou9jhpAfUg==", + "dev": true, + "requires": { + "@babel/highlight": "^7.10.4" + } + }, + "@babel/core": { + "version": "7.11.6", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.11.6.tgz", + "integrity": "sha512-Wpcv03AGnmkgm6uS6k8iwhIwTrcP0m17TL1n1sy7qD0qelDu4XNeW0dN0mHfa+Gei211yDaLoEe/VlbXQzM4Bg==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.10.4", + "@babel/generator": "^7.11.6", + "@babel/helper-module-transforms": "^7.11.0", + "@babel/helpers": "^7.10.4", + "@babel/parser": "^7.11.5", + "@babel/template": "^7.10.4", + "@babel/traverse": "^7.11.5", + "@babel/types": "^7.11.5", + "convert-source-map": "^1.7.0", + "debug": "^4.1.0", + "gensync": "^1.0.0-beta.1", + "json5": "^2.1.2", + "lodash": "^4.17.19", + "resolve": "^1.3.2", + "semver": "^5.4.1", + "source-map": "^0.5.0" + }, + "dependencies": { + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true + } + } + }, + "@babel/generator": { + "version": "7.11.6", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.11.6.tgz", + "integrity": "sha512-DWtQ1PV3r+cLbySoHrwn9RWEgKMBLLma4OBQloPRyDYvc5msJM9kvTLo1YnlJd1P/ZuKbdli3ijr5q3FvAF3uA==", + "dev": true, + "requires": { + "@babel/types": "^7.11.5", + "jsesc": "^2.5.1", + "source-map": "^0.5.0" + } + }, + "@babel/helper-function-name": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.10.4.tgz", + "integrity": "sha512-YdaSyz1n8gY44EmN7x44zBn9zQ1Ry2Y+3GTA+3vH6Mizke1Vw0aWDM66FOYEPw8//qKkmqOckrGgTYa+6sceqQ==", + "dev": true, + "requires": { + "@babel/helper-get-function-arity": "^7.10.4", + "@babel/template": "^7.10.4", + "@babel/types": "^7.10.4" + } + }, + "@babel/helper-get-function-arity": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/helper-get-function-arity/-/helper-get-function-arity-7.10.4.tgz", + "integrity": "sha512-EkN3YDB+SRDgiIUnNgcmiD361ti+AVbL3f3Henf6dqqUyr5dMsorno0lJWJuLhDhkI5sYEpgj6y9kB8AOU1I2A==", + "dev": true, + "requires": { + "@babel/types": "^7.10.4" + } + }, + "@babel/helper-member-expression-to-functions": { + "version": "7.11.0", + "resolved": "https://registry.npmjs.org/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.11.0.tgz", + "integrity": "sha512-JbFlKHFntRV5qKw3YC0CvQnDZ4XMwgzzBbld7Ly4Mj4cbFy3KywcR8NtNctRToMWJOVvLINJv525Gd6wwVEx/Q==", + "dev": true, + "requires": { + "@babel/types": "^7.11.0" + } + }, + "@babel/helper-module-imports": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.10.4.tgz", + "integrity": "sha512-nEQJHqYavI217oD9+s5MUBzk6x1IlvoS9WTPfgG43CbMEeStE0v+r+TucWdx8KFGowPGvyOkDT9+7DHedIDnVw==", + "dev": true, + "requires": { + "@babel/types": "^7.10.4" + } + }, + "@babel/helper-module-transforms": { + "version": "7.11.0", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.11.0.tgz", + "integrity": "sha512-02EVu8COMuTRO1TAzdMtpBPbe6aQ1w/8fePD2YgQmxZU4gpNWaL9gK3Jp7dxlkUlUCJOTaSeA+Hrm1BRQwqIhg==", + "dev": true, + "requires": { + "@babel/helper-module-imports": "^7.10.4", + "@babel/helper-replace-supers": "^7.10.4", + "@babel/helper-simple-access": "^7.10.4", + "@babel/helper-split-export-declaration": "^7.11.0", + "@babel/template": "^7.10.4", + "@babel/types": "^7.11.0", + "lodash": "^4.17.19" + } + }, + "@babel/helper-optimise-call-expression": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/helper-optimise-call-expression/-/helper-optimise-call-expression-7.10.4.tgz", + "integrity": "sha512-n3UGKY4VXwXThEiKrgRAoVPBMqeoPgHVqiHZOanAJCG9nQUL2pLRQirUzl0ioKclHGpGqRgIOkgcIJaIWLpygg==", + "dev": true, + "requires": { + "@babel/types": "^7.10.4" + } + }, + "@babel/helper-replace-supers": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.10.4.tgz", + "integrity": "sha512-sPxZfFXocEymYTdVK1UNmFPBN+Hv5mJkLPsYWwGBxZAxaWfFu+xqp7b6qWD0yjNuNL2VKc6L5M18tOXUP7NU0A==", + "dev": true, + "requires": { + "@babel/helper-member-expression-to-functions": "^7.10.4", + "@babel/helper-optimise-call-expression": "^7.10.4", + "@babel/traverse": "^7.10.4", + "@babel/types": "^7.10.4" + } + }, + "@babel/helper-simple-access": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.10.4.tgz", + "integrity": "sha512-0fMy72ej/VEvF8ULmX6yb5MtHG4uH4Dbd6I/aHDb/JVg0bbivwt9Wg+h3uMvX+QSFtwr5MeItvazbrc4jtRAXw==", + "dev": true, + "requires": { + "@babel/template": "^7.10.4", + "@babel/types": "^7.10.4" + } + }, + "@babel/helper-split-export-declaration": { + "version": "7.11.0", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.11.0.tgz", + "integrity": "sha512-74Vejvp6mHkGE+m+k5vHY93FX2cAtrw1zXrZXRlG4l410Nm9PxfEiVTn1PjDPV5SnmieiueY4AFg2xqhNFuuZg==", + "dev": true, + "requires": { + "@babel/types": "^7.11.0" + } + }, + "@babel/helper-validator-identifier": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.10.4.tgz", + "integrity": "sha512-3U9y+43hz7ZM+rzG24Qe2mufW5KhvFg/NhnNph+i9mgCtdTCtMJuI1TMkrIUiK7Ix4PYlRF9I5dhqaLYA/ADXw==", + "dev": true + }, + "@babel/helpers": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.10.4.tgz", + "integrity": "sha512-L2gX/XeUONeEbI78dXSrJzGdz4GQ+ZTA/aazfUsFaWjSe95kiCuOZ5HsXvkiw3iwF+mFHSRUfJU8t6YavocdXA==", + "dev": true, + "requires": { + "@babel/template": "^7.10.4", + "@babel/traverse": "^7.10.4", + "@babel/types": "^7.10.4" + } + }, + "@babel/highlight": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.10.4.tgz", + "integrity": "sha512-i6rgnR/YgPEQzZZnbTHHuZdlE8qyoBNalD6F+q4vAFlcMEcqmkoG+mPqJYJCo63qPf74+Y1UZsl3l6f7/RIkmA==", + "dev": true, + "requires": { + "@babel/helper-validator-identifier": "^7.10.4", + "chalk": "^2.0.0", + "js-tokens": "^4.0.0" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "dev": true + }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "dev": true + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "dev": true + }, + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, + "@babel/parser": { + "version": "7.11.5", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.11.5.tgz", + "integrity": "sha512-X9rD8qqm695vgmeaQ4fvz/o3+Wk4ZzQvSHkDBgpYKxpD4qTAUm88ZKtHkVqIOsYFFbIQ6wQYhC6q7pjqVK0E0Q==", + "dev": true + }, + "@babel/template": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.10.4.tgz", + "integrity": "sha512-ZCjD27cGJFUB6nmCB1Enki3r+L5kJveX9pq1SvAUKoICy6CZ9yD8xO086YXdYhvNjBdnekm4ZnaP5yC8Cs/1tA==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.10.4", + "@babel/parser": "^7.10.4", + "@babel/types": "^7.10.4" + } + }, + "@babel/traverse": { + "version": "7.11.5", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.11.5.tgz", + "integrity": "sha512-EjiPXt+r7LiCZXEfRpSJd+jUMnBd4/9OUv7Nx3+0u9+eimMwJmG0Q98lw4/289JCoxSE8OolDMNZaaF/JZ69WQ==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.10.4", + "@babel/generator": "^7.11.5", + "@babel/helper-function-name": "^7.10.4", + "@babel/helper-split-export-declaration": "^7.11.0", + "@babel/parser": "^7.11.5", + "@babel/types": "^7.11.5", + "debug": "^4.1.0", + "globals": "^11.1.0", + "lodash": "^4.17.19" + } + }, + "@babel/types": { + "version": "7.11.5", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.11.5.tgz", + "integrity": "sha512-bvM7Qz6eKnJVFIn+1LPtjlBFPVN5jNDc1XmN15vWe7Q3DPBufWWsLiIvUu7xW87uTG6QoggpIDnUgLQvPheU+Q==", + "dev": true, + "requires": { + "@babel/helper-validator-identifier": "^7.10.4", + "lodash": "^4.17.19", + "to-fast-properties": "^2.0.0" + } + }, + "@istanbuljs/load-nyc-config": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", + "integrity": "sha512-VjeHSlIzpv/NyD3N0YuHfXOPDIixcA1q2ZV98wsMqcYlPmv2n3Yb2lYP9XMElnaFVXg5A7YLTeLu6V84uQDjmQ==", + "dev": true, + "requires": { + "camelcase": "^5.3.1", + "find-up": "^4.1.0", + "get-package-type": "^0.1.0", + "js-yaml": "^3.13.1", + "resolve-from": "^5.0.0" + }, + "dependencies": { + "find-up": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", + "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", + "dev": true, + "requires": { + "locate-path": "^5.0.0", + "path-exists": "^4.0.0" + } + }, + "locate-path": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", + "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", + "dev": true, + "requires": { + "p-locate": "^4.1.0" + } + }, + "p-limit": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "dev": true, + "requires": { + "p-try": "^2.0.0" + } + }, + "p-locate": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", + "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", + "dev": true, + "requires": { + "p-limit": "^2.2.0" + } + } + } + }, + "@istanbuljs/schema": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.2.tgz", + "integrity": "sha512-tsAQNx32a8CoFhjhijUIhI4kccIAgmGhy8LZMZgGfmXcpMbPRUqn5LWmgRttILi6yeGmBJd2xsPkFMs0PzgPCw==", + "dev": true + }, + "@types/chai": { + "version": "4.2.12", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.2.12.tgz", + "integrity": "sha512-aN5IAC8QNtSUdQzxu7lGBgYAOuU1tmRU4c9dIq5OKGf/SBVjXo+ffM2wEjudAWbgpOhy60nLoAGH1xm8fpCKFQ==", + "dev": true + }, + "@types/color-name": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", + "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==", + "dev": true + }, + "@types/mocha": { + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-8.0.3.tgz", + "integrity": "sha512-vyxR57nv8NfcU0GZu8EUXZLTbCMupIUwy95LJ6lllN+JRPG25CwMHoB1q5xKh8YKhQnHYRAn4yW2yuHbf/5xgg==", + "dev": true + }, + "@types/prop-types": { + "version": "15.7.3", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.3.tgz", + "integrity": "sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw==", + "dev": true + }, + "@types/react": { + "version": "16.9.49", + "resolved": "https://registry.npmjs.org/@types/react/-/react-16.9.49.tgz", + "integrity": "sha512-DtLFjSj0OYAdVLBbyjhuV9CdGVHCkHn2R+xr3XkBvK2rS1Y1tkc14XSGjYgm5Fjjr90AxH9tiSzc1pCFMGO06g==", + "dev": true, + "requires": { + "@types/prop-types": "*", + "csstype": "^3.0.2" + } + }, + "aggregate-error": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.1.0.tgz", + "integrity": "sha512-4I7Td01quW/RpocfNayFdFVk1qSuoh0E7JrbRJ16nH01HhKFQ88INq9Sd+nd72zqRySlr9BmDA8xlEJ6vJMrYA==", + "dev": true, + "requires": { + "clean-stack": "^2.0.0", + "indent-string": "^4.0.0" + } + }, + "ansi-colors": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", + "integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==", + "dev": true + }, + "ansi-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", + "dev": true + }, + "ansi-styles": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", + "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", + "dev": true, + "requires": { + "@types/color-name": "^1.1.1", + "color-convert": "^2.0.1" + } + }, + "anymatch": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.1.tgz", + "integrity": "sha512-mM8522psRCqzV+6LhomX5wgp25YVibjh8Wj23I5RPkPppSVSjyKD2A2mBJmWGa+KN7f2D6LNh9jkBCeyLktzjg==", + "dev": true, + "requires": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + } + }, + "append-transform": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/append-transform/-/append-transform-2.0.0.tgz", + "integrity": "sha512-7yeyCEurROLQJFv5Xj4lEGTy0borxepjFv1g22oAdqFu//SrAlDl1O1Nxx15SH1RoliUml6p8dwJW9jvZughhg==", + "dev": true, + "requires": { + "default-require-extensions": "^3.0.0" + } + }, + "archy": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/archy/-/archy-1.0.0.tgz", + "integrity": "sha1-+cjBN1fMHde8N5rHeyxipcKGjEA=", + "dev": true + }, + "arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true + }, + "argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "dev": true, + "requires": { + "sprintf-js": "~1.0.2" + } + }, + "array.prototype.map": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/array.prototype.map/-/array.prototype.map-1.0.2.tgz", + "integrity": "sha512-Az3OYxgsa1g7xDYp86l0nnN4bcmuEITGe1rbdEBVkrqkzMgDcbdQ2R7r41pNzti+4NMces3H8gMmuioZUilLgw==", + "dev": true, + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.17.0-next.1", + "es-array-method-boxes-properly": "^1.0.0", + "is-string": "^1.0.4" + } + }, + "assertion-error": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", + "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", + "dev": true + }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true + }, + "binary-extensions": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.1.0.tgz", + "integrity": "sha512-1Yj8h9Q+QDF5FzhMs/c9+6UntbD5MkRfRwac8DoEm9ZfUBZ7tZ55YcGVAzEe4bXsdQHEk+s9S5wsOKVdZrw0tQ==", + "dev": true + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "requires": { + "fill-range": "^7.0.1" + } + }, + "browser-stdout": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", + "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", + "dev": true + }, + "buffer-from": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", + "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", + "dev": true + }, + "caching-transform": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/caching-transform/-/caching-transform-4.0.0.tgz", + "integrity": "sha512-kpqOvwXnjjN44D89K5ccQC+RUrsy7jB/XLlRrx0D7/2HNcTPqzsb6XgYoErwko6QsV184CA2YgS1fxDiiDZMWA==", + "dev": true, + "requires": { + "hasha": "^5.0.0", + "make-dir": "^3.0.0", + "package-hash": "^4.0.0", + "write-file-atomic": "^3.0.0" + } + }, + "camelcase": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", + "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", + "dev": true + }, + "chai": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz", + "integrity": "sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw==", + "dev": true, + "requires": { + "assertion-error": "^1.1.0", + "check-error": "^1.0.2", + "deep-eql": "^3.0.1", + "get-func-name": "^2.0.0", + "pathval": "^1.1.0", + "type-detect": "^4.0.5" + } + }, + "chalk": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz", + "integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "check-error": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", + "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=", + "dev": true + }, + "chokidar": { + "version": "3.4.2", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.4.2.tgz", + "integrity": "sha512-IZHaDeBeI+sZJRX7lGcXsdzgvZqKv6sECqsbErJA4mHWfpRrD8B97kSFN4cQz6nGBGiuFia1MKR4d6c1o8Cv7A==", + "dev": true, + "requires": { + "anymatch": "~3.1.1", + "braces": "~3.0.2", + "fsevents": "~2.1.2", + "glob-parent": "~5.1.0", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.4.0" + } + }, + "clean-stack": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz", + "integrity": "sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==", + "dev": true + }, + "cliui": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-5.0.0.tgz", + "integrity": "sha512-PYeGSEmmHM6zvoef2w8TPzlrnNpXIjTipYK780YswmIP9vjxmd6Y2a3CB2Ks6/AU8NHjZugXvo8w3oWM2qnwXA==", + "dev": true, + "requires": { + "string-width": "^3.1.0", + "strip-ansi": "^5.2.0", + "wrap-ansi": "^5.1.0" + }, + "dependencies": { + "ansi-regex": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", + "dev": true + }, + "string-width": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "dev": true, + "requires": { + "emoji-regex": "^7.0.1", + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^5.1.0" + } + }, + "strip-ansi": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "dev": true, + "requires": { + "ansi-regex": "^4.1.0" + } + } + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "commondir": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", + "integrity": "sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=", + "dev": true + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true + }, + "convert-source-map": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.7.0.tgz", + "integrity": "sha512-4FJkXzKXEDB1snCFZlLP4gpC3JILicCpGbzG9f9G7tGqGCzETQ2hWPrcinA9oU4wtf2biUaEH5065UnMeR33oA==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.1" + }, + "dependencies": { + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "dev": true + } + } + }, + "cross-spawn": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "dev": true, + "requires": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + } + }, + "csstype": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.0.3.tgz", + "integrity": "sha512-jPl+wbWPOWJ7SXsWyqGRk3lGecbar0Cb0OvZF/r/ZU011R4YqiRehgkQ9p4eQfo9DSDLqLL3wHwfxeJiuIsNag==", + "dev": true + }, + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", + "dev": true + }, + "deep-eql": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz", + "integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==", + "dev": true, + "requires": { + "type-detect": "^4.0.0" + } + }, + "default-require-extensions": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/default-require-extensions/-/default-require-extensions-3.0.0.tgz", + "integrity": "sha512-ek6DpXq/SCpvjhpFsLFRVtIxJCRw6fUR42lYMVZuUMK7n8eMz4Uh5clckdBjEpLhn/gEBZo7hDJnJcwdKLKQjg==", + "dev": true, + "requires": { + "strip-bom": "^4.0.0" + } + }, + "define-properties": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", + "integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==", + "dev": true, + "requires": { + "object-keys": "^1.0.12" + } + }, + "diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true + }, + "emoji-regex": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", + "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==", + "dev": true + }, + "es-abstract": { + "version": "1.17.6", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.6.tgz", + "integrity": "sha512-Fr89bON3WFyUi5EvAeI48QTWX0AyekGgLA8H+c+7fbfCkJwRWRMLd8CQedNEyJuoYYhmtEqY92pgte1FAhBlhw==", + "dev": true, + "requires": { + "es-to-primitive": "^1.2.1", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1", + "is-callable": "^1.2.0", + "is-regex": "^1.1.0", + "object-inspect": "^1.7.0", + "object-keys": "^1.1.1", + "object.assign": "^4.1.0", + "string.prototype.trimend": "^1.0.1", + "string.prototype.trimstart": "^1.0.1" + } + }, + "es-array-method-boxes-properly": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/es-array-method-boxes-properly/-/es-array-method-boxes-properly-1.0.0.tgz", + "integrity": "sha512-wd6JXUmyHmt8T5a2xreUwKcGPq6f1f+WwIJkijUqiGcJz1qqnZgP6XIK+QyIWU5lT7imeNxUll48bziG+TSYcA==", + "dev": true + }, + "es-get-iterator": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/es-get-iterator/-/es-get-iterator-1.1.0.tgz", + "integrity": "sha512-UfrmHuWQlNMTs35e1ypnvikg6jCz3SK8v8ImvmDsh36fCVUR1MqoFDiyn0/k52C8NqO3YsO8Oe0azeesNuqSsQ==", + "dev": true, + "requires": { + "es-abstract": "^1.17.4", + "has-symbols": "^1.0.1", + "is-arguments": "^1.0.4", + "is-map": "^2.0.1", + "is-set": "^2.0.1", + "is-string": "^1.0.5", + "isarray": "^2.0.5" + } + }, + "es-to-primitive": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz", + "integrity": "sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==", + "dev": true, + "requires": { + "is-callable": "^1.1.4", + "is-date-object": "^1.0.1", + "is-symbol": "^1.0.2" + } + }, + "es6-error": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/es6-error/-/es6-error-4.1.1.tgz", + "integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==", + "dev": true + }, + "escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true + }, + "esprima": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", + "dev": true + }, + "fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dev": true, + "requires": { + "to-regex-range": "^5.0.1" + } + }, + "find-cache-dir": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-3.3.1.tgz", + "integrity": "sha512-t2GDMt3oGC/v+BMwzmllWDuJF/xcDtE5j/fCGbqDD7OLuJkj0cfh1YSA5VKPvwMeLFLNDBkwOKZ2X85jGLVftQ==", + "dev": true, + "requires": { + "commondir": "^1.0.1", + "make-dir": "^3.0.2", + "pkg-dir": "^4.1.0" + } + }, + "find-up": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", + "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", + "dev": true, + "requires": { + "locate-path": "^6.0.0", + "path-exists": "^4.0.0" + } + }, + "flat": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/flat/-/flat-4.1.0.tgz", + "integrity": "sha512-Px/TiLIznH7gEDlPXcUD4KnBusa6kR6ayRUVcnEAbreRIuhkqow/mun59BuRXwoYk7ZQOLW1ZM05ilIvK38hFw==", + "dev": true, + "requires": { + "is-buffer": "~2.0.3" + } + }, + "foreground-child": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-2.0.0.tgz", + "integrity": "sha512-dCIq9FpEcyQyXKCkyzmlPTFNgrCzPudOe+mhvJU5zAtlBnGVy2yKxtfsxK2tQBThwq225jcvBjpw1Gr40uzZCA==", + "dev": true, + "requires": { + "cross-spawn": "^7.0.0", + "signal-exit": "^3.0.2" + } + }, + "fromentries": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/fromentries/-/fromentries-1.2.1.tgz", + "integrity": "sha512-Xu2Qh8yqYuDhQGOhD5iJGninErSfI9A3FrriD3tjUgV5VbJFeH8vfgZ9HnC6jWN80QDVNQK5vmxRAmEAp7Mevw==", + "dev": true + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true + }, + "fsevents": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.3.tgz", + "integrity": "sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==", + "dev": true, + "optional": true + }, + "function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", + "dev": true + }, + "gensync": { + "version": "1.0.0-beta.1", + "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.1.tgz", + "integrity": "sha512-r8EC6NO1sngH/zdD9fiRDLdcgnbayXah+mLgManTaIZJqEC1MZstmnox8KpnI2/fxQwrp5OpCOYWLp4rBl4Jcg==", + "dev": true + }, + "get-caller-file": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", + "dev": true + }, + "get-func-name": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", + "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", + "dev": true + }, + "get-package-type": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/get-package-type/-/get-package-type-0.1.0.tgz", + "integrity": "sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==", + "dev": true + }, + "glob": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "glob-parent": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz", + "integrity": "sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==", + "dev": true, + "requires": { + "is-glob": "^4.0.1" + } + }, + "globals": { + "version": "11.12.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", + "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", + "dev": true + }, + "graceful-fs": { + "version": "4.2.4", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz", + "integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==", + "dev": true + }, + "growl": { + "version": "1.10.5", + "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz", + "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==", + "dev": true + }, + "has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dev": true, + "requires": { + "function-bind": "^1.1.1" + } + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true + }, + "has-symbols": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz", + "integrity": "sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg==", + "dev": true + }, + "hasha": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/hasha/-/hasha-5.2.0.tgz", + "integrity": "sha512-2W+jKdQbAdSIrggA8Q35Br8qKadTrqCTC8+XZvBWepKDK6m9XkX6Iz1a2yh2KP01kzAR/dpuMeUnocoLYDcskw==", + "dev": true, + "requires": { + "is-stream": "^2.0.0", + "type-fest": "^0.8.0" + } + }, + "he": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", + "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", + "dev": true + }, + "html-escaper": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", + "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", + "dev": true + }, + "imurmurhash": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", + "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", + "dev": true + }, + "indent-string": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", + "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==", + "dev": true + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true + }, + "is-arguments": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.0.4.tgz", + "integrity": "sha512-xPh0Rmt8NE65sNzvyUmWgI1tz3mKq74lGA0mL8LYZcoIzKOzDh6HmrYm3d18k60nHerC8A9Km8kYu87zfSFnLA==", + "dev": true + }, + "is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "requires": { + "binary-extensions": "^2.0.0" + } + }, + "is-buffer": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz", + "integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A==", + "dev": true + }, + "is-callable": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.1.tgz", + "integrity": "sha512-wliAfSzx6V+6WfMOmus1xy0XvSgf/dlStkvTfq7F0g4bOIW0PSUbnyse3NhDwdyYS1ozfUtAAySqTws3z9Eqgg==", + "dev": true + }, + "is-date-object": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.2.tgz", + "integrity": "sha512-USlDT524woQ08aoZFzh3/Z6ch9Y/EWXEHQ/AaRN0SkKq4t2Jw2R2339tSXmwuVoY7LLlBCbOIlx2myP/L5zk0g==", + "dev": true + }, + "is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=", + "dev": true + }, + "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", + "dev": true + }, + "is-glob": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz", + "integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==", + "dev": true, + "requires": { + "is-extglob": "^2.1.1" + } + }, + "is-map": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-map/-/is-map-2.0.1.tgz", + "integrity": "sha512-T/S49scO8plUiAOA2DBTBG3JHpn1yiw0kRp6dgiZ0v2/6twi5eiB0rHtHFH9ZIrvlWc6+4O+m4zg5+Z833aXgw==", + "dev": true + }, + "is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true + }, + "is-plain-obj": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz", + "integrity": "sha1-caUMhCnfync8kqOQpKA7OfzVHT4=", + "dev": true + }, + "is-regex": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.1.tgz", + "integrity": "sha512-1+QkEcxiLlB7VEyFtyBg94e08OAsvq7FUBgApTq/w2ymCLyKJgDPsybBENVtA7XCQEgEXxKPonG+mvYRxh/LIg==", + "dev": true, + "requires": { + "has-symbols": "^1.0.1" + } + }, + "is-set": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-set/-/is-set-2.0.1.tgz", + "integrity": "sha512-eJEzOtVyenDs1TMzSQ3kU3K+E0GUS9sno+F0OBT97xsgcJsF9nXMBtkT9/kut5JEpM7oL7X/0qxR17K3mcwIAA==", + "dev": true + }, + "is-stream": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.0.tgz", + "integrity": "sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw==", + "dev": true + }, + "is-string": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/is-string/-/is-string-1.0.5.tgz", + "integrity": "sha512-buY6VNRjhQMiF1qWDouloZlQbRhDPCebwxSjxMjxgemYT46YMd2NR0/H+fBhEfWX4A/w9TBJ+ol+okqJKFE6vQ==", + "dev": true + }, + "is-symbol": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.3.tgz", + "integrity": "sha512-OwijhaRSgqvhm/0ZdAcXNZt9lYdKFpcRDT5ULUuYXPoT794UNOdU+gpT6Rzo7b4V2HUl/op6GqY894AZwv9faQ==", + "dev": true, + "requires": { + "has-symbols": "^1.0.1" + } + }, + "is-typedarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", + "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=", + "dev": true + }, + "is-windows": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-windows/-/is-windows-1.0.2.tgz", + "integrity": "sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==", + "dev": true + }, + "isarray": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", + "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==", + "dev": true + }, + "isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", + "dev": true + }, + "istanbul-lib-coverage": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.0.0.tgz", + "integrity": "sha512-UiUIqxMgRDET6eR+o5HbfRYP1l0hqkWOs7vNxC/mggutCMUIhWMm8gAHb8tHlyfD3/l6rlgNA5cKdDzEAf6hEg==", + "dev": true + }, + "istanbul-lib-hook": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/istanbul-lib-hook/-/istanbul-lib-hook-3.0.0.tgz", + "integrity": "sha512-Pt/uge1Q9s+5VAZ+pCo16TYMWPBIl+oaNIjgLQxcX0itS6ueeaA+pEfThZpH8WxhFgCiEb8sAJY6MdUKgiIWaQ==", + "dev": true, + "requires": { + "append-transform": "^2.0.0" + } + }, + "istanbul-lib-instrument": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/istanbul-lib-instrument/-/istanbul-lib-instrument-4.0.3.tgz", + "integrity": "sha512-BXgQl9kf4WTCPCCpmFGoJkz/+uhvm7h7PFKUYxh7qarQd3ER33vHG//qaE8eN25l07YqZPpHXU9I09l/RD5aGQ==", + "dev": true, + "requires": { + "@babel/core": "^7.7.5", + "@istanbuljs/schema": "^0.1.2", + "istanbul-lib-coverage": "^3.0.0", + "semver": "^6.3.0" + } + }, + "istanbul-lib-processinfo": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/istanbul-lib-processinfo/-/istanbul-lib-processinfo-2.0.2.tgz", + "integrity": "sha512-kOwpa7z9hme+IBPZMzQ5vdQj8srYgAtaRqeI48NGmAQ+/5yKiHLV0QbYqQpxsdEF0+w14SoB8YbnHKcXE2KnYw==", + "dev": true, + "requires": { + "archy": "^1.0.0", + "cross-spawn": "^7.0.0", + "istanbul-lib-coverage": "^3.0.0-alpha.1", + "make-dir": "^3.0.0", + "p-map": "^3.0.0", + "rimraf": "^3.0.0", + "uuid": "^3.3.3" + } + }, + "istanbul-lib-report": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/istanbul-lib-report/-/istanbul-lib-report-3.0.0.tgz", + "integrity": "sha512-wcdi+uAKzfiGT2abPpKZ0hSU1rGQjUQnLvtY5MpQ7QCTahD3VODhcu4wcfY1YtkGaDD5yuydOLINXsfbus9ROw==", + "dev": true, + "requires": { + "istanbul-lib-coverage": "^3.0.0", + "make-dir": "^3.0.0", + "supports-color": "^7.1.0" + } + }, + "istanbul-lib-source-maps": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/istanbul-lib-source-maps/-/istanbul-lib-source-maps-4.0.0.tgz", + "integrity": "sha512-c16LpFRkR8vQXyHZ5nLpY35JZtzj1PQY1iZmesUbf1FZHbIupcWfjgOXBY9YHkLEQ6puz1u4Dgj6qmU/DisrZg==", + "dev": true, + "requires": { + "debug": "^4.1.1", + "istanbul-lib-coverage": "^3.0.0", + "source-map": "^0.6.1" + }, + "dependencies": { + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + } + } + }, + "istanbul-reports": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-3.0.2.tgz", + "integrity": "sha512-9tZvz7AiR3PEDNGiV9vIouQ/EAcqMXFmkcA1CDFTwOB98OZVDL0PH9glHotf5Ugp6GCOTypfzGWI/OqjWNCRUw==", + "dev": true, + "requires": { + "html-escaper": "^2.0.0", + "istanbul-lib-report": "^3.0.0" + } + }, + "iterate-iterator": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/iterate-iterator/-/iterate-iterator-1.0.1.tgz", + "integrity": "sha512-3Q6tudGN05kbkDQDI4CqjaBf4qf85w6W6GnuZDtUVYwKgtC1q8yxYX7CZed7N+tLzQqS6roujWvszf13T+n9aw==", + "dev": true + }, + "iterate-value": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/iterate-value/-/iterate-value-1.0.2.tgz", + "integrity": "sha512-A6fMAio4D2ot2r/TYzr4yUWrmwNdsN5xL7+HUiyACE4DXm+q8HtPcnFTp+NnW3k4N05tZ7FVYFFb2CR13NxyHQ==", + "dev": true, + "requires": { + "es-get-iterator": "^1.0.2", + "iterate-iterator": "^1.0.1" + } + }, + "js-tokens": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", + "dev": true + }, + "js-yaml": { + "version": "3.14.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.0.tgz", + "integrity": "sha512-/4IbIeHcD9VMHFqDR/gQ7EdZdLimOvW2DdcxFjdyyZ9NsbS+ccrXqVWDtab/lRl5AlUqmpBx8EhPaWR+OtY17A==", + "dev": true, + "requires": { + "argparse": "^1.0.7", + "esprima": "^4.0.0" + } + }, + "jsesc": { + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", + "integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==", + "dev": true + }, + "json5": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.1.3.tgz", + "integrity": "sha512-KXPvOm8K9IJKFM0bmdn8QXh7udDh1g/giieX0NLCaMnb4hEiVFqnop2ImTXCc5e0/oHz3LTqmHGtExn5hfMkOA==", + "dev": true, + "requires": { + "minimist": "^1.2.5" + } + }, + "locate-path": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", + "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", + "dev": true, + "requires": { + "p-locate": "^5.0.0" + } + }, + "lodash": { + "version": "4.17.20", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", + "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==", + "dev": true + }, + "lodash.flattendeep": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz", + "integrity": "sha1-+wMJF/hqMTTlvJvsDWngAT3f7bI=", + "dev": true + }, + "log-symbols": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.0.0.tgz", + "integrity": "sha512-FN8JBzLx6CzeMrB0tg6pqlGU1wCrXW+ZXGH481kfsBqer0hToTIiHdjH4Mq8xJUbvATujKCvaREGWpGUionraA==", + "dev": true, + "requires": { + "chalk": "^4.0.0" + } + }, + "loose-envify": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", + "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", + "dev": true, + "requires": { + "js-tokens": "^3.0.0 || ^4.0.0" + } + }, + "make-dir": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", + "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", + "dev": true, + "requires": { + "semver": "^6.0.0" + } + }, + "make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "minimist": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "dev": true + }, + "mocha": { + "version": "8.1.3", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-8.1.3.tgz", + "integrity": "sha512-ZbaYib4hT4PpF4bdSO2DohooKXIn4lDeiYqB+vTmCdr6l2woW0b6H3pf5x4sM5nwQMru9RvjjHYWVGltR50ZBw==", + "dev": true, + "requires": { + "ansi-colors": "4.1.1", + "browser-stdout": "1.3.1", + "chokidar": "3.4.2", + "debug": "4.1.1", + "diff": "4.0.2", + "escape-string-regexp": "4.0.0", + "find-up": "5.0.0", + "glob": "7.1.6", + "growl": "1.10.5", + "he": "1.2.0", + "js-yaml": "3.14.0", + "log-symbols": "4.0.0", + "minimatch": "3.0.4", + "ms": "2.1.2", + "object.assign": "4.1.0", + "promise.allsettled": "1.0.2", + "serialize-javascript": "4.0.0", + "strip-json-comments": "3.0.1", + "supports-color": "7.1.0", + "which": "2.0.2", + "wide-align": "1.1.3", + "workerpool": "6.0.0", + "yargs": "13.3.2", + "yargs-parser": "13.1.2", + "yargs-unparser": "1.6.1" + } + }, + "moq.ts": { + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/moq.ts/-/moq.ts-6.4.0.tgz", + "integrity": "sha512-g9siyKOvYGVhfDCl9mpLptch93egRC3yXIbPLssxukOROl368XBB+6M7YjLTkjVRHbKbpJBD6P7od+Ky/0xWIw==", + "dev": true, + "requires": { + "tslib": "^2.0.0" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + }, + "node-preload": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/node-preload/-/node-preload-0.2.1.tgz", + "integrity": "sha512-RM5oyBy45cLEoHqCeh+MNuFAxO0vTFBLskvQbOKnEE7YTTSN4tbN8QWDIPQ6L+WvKsB/qLEGpYe2ZZ9d4W9OIQ==", + "dev": true, + "requires": { + "process-on-spawn": "^1.0.0" + } + }, + "normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "dev": true + }, + "nyc": { + "version": "15.1.0", + "resolved": "https://registry.npmjs.org/nyc/-/nyc-15.1.0.tgz", + "integrity": "sha512-jMW04n9SxKdKi1ZMGhvUTHBN0EICCRkHemEoE5jm6mTYcqcdas0ATzgUgejlQUHMvpnOZqGB5Xxsv9KxJW1j8A==", + "dev": true, + "requires": { + "@istanbuljs/load-nyc-config": "^1.0.0", + "@istanbuljs/schema": "^0.1.2", + "caching-transform": "^4.0.0", + "convert-source-map": "^1.7.0", + "decamelize": "^1.2.0", + "find-cache-dir": "^3.2.0", + "find-up": "^4.1.0", + "foreground-child": "^2.0.0", + "get-package-type": "^0.1.0", + "glob": "^7.1.6", + "istanbul-lib-coverage": "^3.0.0", + "istanbul-lib-hook": "^3.0.0", + "istanbul-lib-instrument": "^4.0.0", + "istanbul-lib-processinfo": "^2.0.2", + "istanbul-lib-report": "^3.0.0", + "istanbul-lib-source-maps": "^4.0.0", + "istanbul-reports": "^3.0.2", + "make-dir": "^3.0.0", + "node-preload": "^0.2.1", + "p-map": "^3.0.0", + "process-on-spawn": "^1.0.0", + "resolve-from": "^5.0.0", + "rimraf": "^3.0.0", + "signal-exit": "^3.0.2", + "spawn-wrap": "^2.0.0", + "test-exclude": "^6.0.0", + "yargs": "^15.0.2" + }, + "dependencies": { + "ansi-regex": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "dev": true + }, + "cliui": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", + "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", + "dev": true, + "requires": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^6.2.0" + } + }, + "emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true + }, + "find-up": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", + "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", + "dev": true, + "requires": { + "locate-path": "^5.0.0", + "path-exists": "^4.0.0" + } + }, + "is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true + }, + "locate-path": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", + "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", + "dev": true, + "requires": { + "p-locate": "^4.1.0" + } + }, + "p-limit": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "dev": true, + "requires": { + "p-try": "^2.0.0" + } + }, + "p-locate": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", + "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", + "dev": true, + "requires": { + "p-limit": "^2.2.0" + } + }, + "string-width": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz", + "integrity": "sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg==", + "dev": true, + "requires": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.0" + } + }, + "strip-ansi": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", + "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", + "dev": true, + "requires": { + "ansi-regex": "^5.0.0" + } + }, + "wrap-ansi": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", + "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", + "dev": true, + "requires": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + } + }, + "yargs": { + "version": "15.4.1", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz", + "integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==", + "dev": true, + "requires": { + "cliui": "^6.0.0", + "decamelize": "^1.2.0", + "find-up": "^4.1.0", + "get-caller-file": "^2.0.1", + "require-directory": "^2.1.1", + "require-main-filename": "^2.0.0", + "set-blocking": "^2.0.0", + "string-width": "^4.2.0", + "which-module": "^2.0.0", + "y18n": "^4.0.0", + "yargs-parser": "^18.1.2" + } + }, + "yargs-parser": { + "version": "18.1.3", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz", + "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", + "dev": true, + "requires": { + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" + } + } + } + }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", + "dev": true + }, + "object-inspect": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.8.0.tgz", + "integrity": "sha512-jLdtEOB112fORuypAyl/50VRVIBIdVQOSUUGQHzJ4xBSbit81zRarz7GThkEFZy1RceYrWYcPcBFPQwHyAc1gA==", + "dev": true + }, + "object-keys": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", + "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", + "dev": true + }, + "object.assign": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.0.tgz", + "integrity": "sha512-exHJeq6kBKj58mqGyTQ9DFvrZC/eR6OwxzoM9YRoGBqrXYonaFyGiFMuc9VZrXf7DarreEwMpurG3dd+CNyW5w==", + "dev": true, + "requires": { + "define-properties": "^1.1.2", + "function-bind": "^1.1.1", + "has-symbols": "^1.0.0", + "object-keys": "^1.0.11" + } + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, + "requires": { + "wrappy": "1" + } + }, + "p-limit": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.0.2.tgz", + "integrity": "sha512-iwqZSOoWIW+Ew4kAGUlN16J4M7OB3ysMLSZtnhmqx7njIHFPlxWBX8xo3lVTyFVq6mI/lL9qt2IsN1sHwaxJkg==", + "dev": true, + "requires": { + "p-try": "^2.0.0" + } + }, + "p-locate": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", + "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", + "dev": true, + "requires": { + "p-limit": "^3.0.2" + } + }, + "p-map": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/p-map/-/p-map-3.0.0.tgz", + "integrity": "sha512-d3qXVTF/s+W+CdJ5A29wywV2n8CQQYahlgz2bFiA+4eVNJbHJodPZ+/gXwPGh0bOqA+j8S+6+ckmvLGPk1QpxQ==", + "dev": true, + "requires": { + "aggregate-error": "^3.0.0" + } + }, + "p-try": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", + "dev": true + }, + "package-hash": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/package-hash/-/package-hash-4.0.0.tgz", + "integrity": "sha512-whdkPIooSu/bASggZ96BWVvZTRMOFxnyUG5PnTSGKoJE2gd5mbVNmR2Nj20QFzxYYgAXpoqC+AiXzl+UMRh7zQ==", + "dev": true, + "requires": { + "graceful-fs": "^4.1.15", + "hasha": "^5.0.0", + "lodash.flattendeep": "^4.4.0", + "release-zalgo": "^1.0.0" + } + }, + "path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "dev": true + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true + }, + "path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true + }, + "path-parse": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", + "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", + "dev": true + }, + "pathval": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", + "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=", + "dev": true + }, + "picomatch": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.2.tgz", + "integrity": "sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==", + "dev": true + }, + "pkg-dir": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-4.2.0.tgz", + "integrity": "sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==", + "dev": true, + "requires": { + "find-up": "^4.0.0" + }, + "dependencies": { + "find-up": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", + "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", + "dev": true, + "requires": { + "locate-path": "^5.0.0", + "path-exists": "^4.0.0" + } + }, + "locate-path": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", + "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", + "dev": true, + "requires": { + "p-locate": "^4.1.0" + } + }, + "p-limit": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "dev": true, + "requires": { + "p-try": "^2.0.0" + } + }, + "p-locate": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", + "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", + "dev": true, + "requires": { + "p-limit": "^2.2.0" + } + } + } + }, + "process-on-spawn": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/process-on-spawn/-/process-on-spawn-1.0.0.tgz", + "integrity": "sha512-1WsPDsUSMmZH5LeMLegqkPDrsGgsWwk1Exipy2hvB0o/F0ASzbpIctSCcZIK1ykJvtTJULEH+20WOFjMvGnCTg==", + "dev": true, + "requires": { + "fromentries": "^1.2.0" + } + }, + "promise.allsettled": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/promise.allsettled/-/promise.allsettled-1.0.2.tgz", + "integrity": "sha512-UpcYW5S1RaNKT6pd+s9jp9K9rlQge1UXKskec0j6Mmuq7UJCvlS2J2/s/yuPN8ehftf9HXMxWlKiPbGGUzpoRg==", + "dev": true, + "requires": { + "array.prototype.map": "^1.0.1", + "define-properties": "^1.1.3", + "es-abstract": "^1.17.0-next.1", + "function-bind": "^1.1.1", + "iterate-value": "^1.0.0" + } + }, + "prop-types": { + "version": "15.7.2", + "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.7.2.tgz", + "integrity": "sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==", + "dev": true, + "requires": { + "loose-envify": "^1.4.0", + "object-assign": "^4.1.1", + "react-is": "^16.8.1" + } + }, + "randombytes": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", + "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", + "dev": true, + "requires": { + "safe-buffer": "^5.1.0" + } + }, + "react": { + "version": "16.13.1", + "resolved": "https://registry.npmjs.org/react/-/react-16.13.1.tgz", + "integrity": "sha512-YMZQQq32xHLX0bz5Mnibv1/LHb3Sqzngu7xstSM+vrkE5Kzr9xE0yMByK5kMoTK30YVJE61WfbxIFFvfeDKT1w==", + "dev": true, + "requires": { + "loose-envify": "^1.1.0", + "object-assign": "^4.1.1", + "prop-types": "^15.6.2" + } + }, + "react-is": { + "version": "16.13.1", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", + "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", + "dev": true + }, + "readdirp": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.4.0.tgz", + "integrity": "sha512-0xe001vZBnJEK+uKcj8qOhyAKPzIT+gStxWr3LCB0DwcXR5NZJ3IaC+yGnHCYzB/S7ov3m3EEbZI2zeNvX+hGQ==", + "dev": true, + "requires": { + "picomatch": "^2.2.1" + } + }, + "release-zalgo": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/release-zalgo/-/release-zalgo-1.0.0.tgz", + "integrity": "sha1-CXALflB0Mpc5Mw5TXFqQ+2eFFzA=", + "dev": true, + "requires": { + "es6-error": "^4.0.1" + } + }, + "require-directory": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=", + "dev": true + }, + "require-main-filename": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", + "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", + "dev": true + }, + "resolve": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz", + "integrity": "sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==", + "dev": true, + "requires": { + "path-parse": "^1.0.6" + } + }, + "resolve-from": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz", + "integrity": "sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==", + "dev": true + }, + "rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + }, + "safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "dev": true + }, + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + }, + "serialize-javascript": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-4.0.0.tgz", + "integrity": "sha512-GaNA54380uFefWghODBWEGisLZFj00nS5ACs6yHa9nLqlLpVLO8ChDGeKRjZnV4Nh4n0Qi7nhYZD/9fCPzEqkw==", + "dev": true, + "requires": { + "randombytes": "^2.1.0" + } + }, + "set-blocking": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", + "dev": true + }, + "shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "requires": { + "shebang-regex": "^3.0.0" + } + }, + "shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true + }, + "signal-exit": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz", + "integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==", + "dev": true + }, + "source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", + "dev": true + }, + "source-map-support": { + "version": "0.5.19", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz", + "integrity": "sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==", + "dev": true, + "requires": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + }, + "dependencies": { + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + } + } + }, + "spawn-wrap": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/spawn-wrap/-/spawn-wrap-2.0.0.tgz", + "integrity": "sha512-EeajNjfN9zMnULLwhZZQU3GWBoFNkbngTUPfaawT4RkMiviTxcX0qfhVbGey39mfctfDHkWtuecgQ8NJcyQWHg==", + "dev": true, + "requires": { + "foreground-child": "^2.0.0", + "is-windows": "^1.0.2", + "make-dir": "^3.0.0", + "rimraf": "^3.0.0", + "signal-exit": "^3.0.2", + "which": "^2.0.1" + } + }, + "sprintf-js": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", + "dev": true + }, + "string-width": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", + "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "dev": true, + "requires": { + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^4.0.0" + } + }, + "string.prototype.trimend": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/string.prototype.trimend/-/string.prototype.trimend-1.0.1.tgz", + "integrity": "sha512-LRPxFUaTtpqYsTeNKaFOw3R4bxIzWOnbQ837QfBylo8jIxtcbK/A/sMV7Q+OAV/vWo+7s25pOE10KYSjaSO06g==", + "dev": true, + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.17.5" + } + }, + "string.prototype.trimstart": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/string.prototype.trimstart/-/string.prototype.trimstart-1.0.1.tgz", + "integrity": "sha512-XxZn+QpvrBI1FOcg6dIpxUPgWCPuNXvMD72aaRaUQv1eD4e/Qy8i/hFTe0BUmD60p/QA6bh1avmuPTfNjqVWRw==", + "dev": true, + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.17.5" + } + }, + "strip-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "dev": true, + "requires": { + "ansi-regex": "^3.0.0" + } + }, + "strip-bom": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-4.0.0.tgz", + "integrity": "sha512-3xurFv5tEgii33Zi8Jtp55wEIILR9eh34FAW00PZf+JnSsTmV/ioewSgQl97JHvgjoRGwPShsWm+IdrxB35d0w==", + "dev": true + }, + "strip-json-comments": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.0.1.tgz", + "integrity": "sha512-VTyMAUfdm047mwKl+u79WIdrZxtFtn+nBxHeb844XBQ9uMNTuTHdx2hc5RiAJYqwTj3wc/xe5HLSdJSkJ+WfZw==", + "dev": true + }, + "supports-color": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz", + "integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==", + "dev": true, + "requires": { + "has-flag": "^4.0.0" + } + }, + "test-exclude": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", + "integrity": "sha512-cAGWPIyOHU6zlmg88jwm7VRyXnMN7iV68OGAbYDk/Mh/xC/pzVPlQtY6ngoIH/5/tciuhGfvESU8GrHrcxD56w==", + "dev": true, + "requires": { + "@istanbuljs/schema": "^0.1.2", + "glob": "^7.1.4", + "minimatch": "^3.0.4" + } + }, + "to-fast-properties": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", + "integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=", + "dev": true + }, + "to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "requires": { + "is-number": "^7.0.0" + } + }, + "ts-node": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-9.0.0.tgz", + "integrity": "sha512-/TqB4SnererCDR/vb4S/QvSZvzQMJN8daAslg7MeaiHvD8rDZsSfXmNeNumyZZzMned72Xoq/isQljYSt8Ynfg==", + "dev": true, + "requires": { + "arg": "^4.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "source-map-support": "^0.5.17", + "yn": "3.1.1" + } + }, + "tslib": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.0.1.tgz", + "integrity": "sha512-SgIkNheinmEBgx1IUNirK0TUD4X9yjjBRTqqjggWCU3pUEqIk3/Uwl3yRixYKT6WjQuGiwDv4NomL3wqRCj+CQ==", + "dev": true + }, + "type-detect": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "dev": true + }, + "type-fest": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", + "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==", + "dev": true + }, + "typedarray-to-buffer": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz", + "integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==", + "dev": true, + "requires": { + "is-typedarray": "^1.0.0" + } + }, + "typescript": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.0.2.tgz", + "integrity": "sha512-e4ERvRV2wb+rRZ/IQeb3jm2VxBsirQLpQhdxplZ2MEzGvDkkMmPglecnNDfSUBivMjP93vRbngYYDQqQ/78bcQ==", + "dev": true + }, + "uuid": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", + "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==", + "dev": true + }, + "which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "requires": { + "isexe": "^2.0.0" + } + }, + "which-module": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", + "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", + "dev": true + }, + "wide-align": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz", + "integrity": "sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA==", + "dev": true, + "requires": { + "string-width": "^1.0.2 || 2" + } + }, + "workerpool": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.0.0.tgz", + "integrity": "sha512-fU2OcNA/GVAJLLyKUoHkAgIhKb0JoCpSjLC/G2vYKxUjVmQwGbRVeoPJ1a8U4pnVofz4AQV5Y/NEw8oKqxEBtA==", + "dev": true + }, + "wrap-ansi": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-5.1.0.tgz", + "integrity": "sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.0", + "string-width": "^3.0.0", + "strip-ansi": "^5.0.0" + }, + "dependencies": { + "ansi-regex": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", + "dev": true + }, + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "dev": true + }, + "string-width": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "dev": true, + "requires": { + "emoji-regex": "^7.0.1", + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^5.1.0" + } + }, + "strip-ansi": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "dev": true, + "requires": { + "ansi-regex": "^4.1.0" + } + } + } + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true + }, + "write-file-atomic": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-3.0.3.tgz", + "integrity": "sha512-AvHcyZ5JnSfq3ioSyjrBkH9yW4m7Ayk8/9My/DD9onKeu/94fwrMocemO2QAJFAlnnDN+ZDS+ZjAR5ua1/PV/Q==", + "dev": true, + "requires": { + "imurmurhash": "^0.1.4", + "is-typedarray": "^1.0.0", + "signal-exit": "^3.0.2", + "typedarray-to-buffer": "^3.1.5" + } + }, + "y18n": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", + "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", + "dev": true + }, + "yargs": { + "version": "13.3.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-13.3.2.tgz", + "integrity": "sha512-AX3Zw5iPruN5ie6xGRIDgqkT+ZhnRlZMLMHAs8tg7nRruy2Nb+i5o9bwghAogtM08q1dpr2LVoS8KSTMYpWXUw==", + "dev": true, + "requires": { + "cliui": "^5.0.0", + "find-up": "^3.0.0", + "get-caller-file": "^2.0.1", + "require-directory": "^2.1.1", + "require-main-filename": "^2.0.0", + "set-blocking": "^2.0.0", + "string-width": "^3.0.0", + "which-module": "^2.0.0", + "y18n": "^4.0.0", + "yargs-parser": "^13.1.2" + }, + "dependencies": { + "ansi-regex": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", + "dev": true + }, + "find-up": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", + "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", + "dev": true, + "requires": { + "locate-path": "^3.0.0" + } + }, + "locate-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", + "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", + "dev": true, + "requires": { + "p-locate": "^3.0.0", + "path-exists": "^3.0.0" + } + }, + "p-limit": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "dev": true, + "requires": { + "p-try": "^2.0.0" + } + }, + "p-locate": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", + "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", + "dev": true, + "requires": { + "p-limit": "^2.0.0" + } + }, + "path-exists": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", + "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", + "dev": true + }, + "string-width": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "dev": true, + "requires": { + "emoji-regex": "^7.0.1", + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^5.1.0" + } + }, + "strip-ansi": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "dev": true, + "requires": { + "ansi-regex": "^4.1.0" + } + } + } + }, + "yargs-parser": { + "version": "13.1.2", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.1.2.tgz", + "integrity": "sha512-3lbsNRf/j+A4QuSZfDRA7HRSfWrzO0YjqTJd5kjAq37Zep1CEgaYmrH9Q3GwPiB9cHyd1Y1UwggGhJGoxipbzg==", + "dev": true, + "requires": { + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" + } + }, + "yargs-unparser": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-1.6.1.tgz", + "integrity": "sha512-qZV14lK9MWsGCmcr7u5oXGH0dbGqZAIxTDrWXZDo5zUr6b6iUmelNKO6x6R1dQT24AH3LgRxJpr8meWy2unolA==", + "dev": true, + "requires": { + "camelcase": "^5.3.1", + "decamelize": "^1.2.0", + "flat": "^4.1.0", + "is-plain-obj": "^1.1.0", + "yargs": "^14.2.3" + }, + "dependencies": { + "ansi-regex": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", + "dev": true + }, + "find-up": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", + "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", + "dev": true, + "requires": { + "locate-path": "^3.0.0" + } + }, + "locate-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", + "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", + "dev": true, + "requires": { + "p-locate": "^3.0.0", + "path-exists": "^3.0.0" + } + }, + "p-limit": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "dev": true, + "requires": { + "p-try": "^2.0.0" + } + }, + "p-locate": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", + "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", + "dev": true, + "requires": { + "p-limit": "^2.0.0" + } + }, + "path-exists": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", + "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", + "dev": true + }, + "string-width": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "dev": true, + "requires": { + "emoji-regex": "^7.0.1", + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^5.1.0" + } + }, + "strip-ansi": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "dev": true, + "requires": { + "ansi-regex": "^4.1.0" + } + }, + "yargs": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-14.2.3.tgz", + "integrity": "sha512-ZbotRWhF+lkjijC/VhmOT9wSgyBQ7+zr13+YLkhfsSiTriYsMzkTUFP18pFhWwBeMa5gUc1MzbhrO6/VB7c9Xg==", + "dev": true, + "requires": { + "cliui": "^5.0.0", + "decamelize": "^1.2.0", + "find-up": "^3.0.0", + "get-caller-file": "^2.0.1", + "require-directory": "^2.1.1", + "require-main-filename": "^2.0.0", + "set-blocking": "^2.0.0", + "string-width": "^3.0.0", + "which-module": "^2.0.0", + "y18n": "^4.0.0", + "yargs-parser": "^15.0.1" + } + }, + "yargs-parser": { + "version": "15.0.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-15.0.1.tgz", + "integrity": "sha512-0OAMV2mAZQrs3FkNpDQcBk1x5HXb8X4twADss4S0Iuk+2dGnLOE/fRHrsYm542GduMveyA77OF4wrNJuanRCWw==", + "dev": true, + "requires": { + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" + } + } + } + }, + "yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true + } + } +} diff --git a/tests/Avalonia.DesignerSupport.Tests/Remote/HtmlTransport/webapp/package.json b/tests/Avalonia.DesignerSupport.Tests/Remote/HtmlTransport/webapp/package.json new file mode 100644 index 0000000000..dbb12e192a --- /dev/null +++ b/tests/Avalonia.DesignerSupport.Tests/Remote/HtmlTransport/webapp/package.json @@ -0,0 +1,26 @@ +{ + "name": "simple-test", + "version": "1.0.0", + "main": "index.js", + "scripts": { + "test": "mocha -r ts-node/register ./**/*Tests.ts", + "coverage": "nyc -r text -e .ts -x \"./*Tests.ts\" npm run test" + }, + "type": "module", + "keywords": [], + "author": "", + "license": "MIT", + "dependencies": {}, + "devDependencies": { + "@types/chai": "4.2.12", + "@types/mocha": "8.0.3", + "@types/react": "^16.3.14", + "chai": "^4.2.0", + "mocha": "^8.1.3", + "moq.ts": "^6.4.0", + "nyc": "^15.1.0", + "react": "^16.3.2", + "ts-node": "^9.0.0", + "typescript": "^4.0.2" + } +} diff --git a/tests/Avalonia.DesignerSupport.Tests/Remote/HtmlTransport/webapp/tsconfig.json b/tests/Avalonia.DesignerSupport.Tests/Remote/HtmlTransport/webapp/tsconfig.json new file mode 100644 index 0000000000..fdb82879fc --- /dev/null +++ b/tests/Avalonia.DesignerSupport.Tests/Remote/HtmlTransport/webapp/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "sourceMap": true, + "strict": true, + "esModuleInterop": true + }, + "exclude": [ + "node_modules" + ] +} diff --git a/tests/Avalonia.Direct2D1.RenderTests/Avalonia.Direct2D1.RenderTests.csproj b/tests/Avalonia.Direct2D1.RenderTests/Avalonia.Direct2D1.RenderTests.csproj index 1cfc1a6ab8..c59e59be63 100644 --- a/tests/Avalonia.Direct2D1.RenderTests/Avalonia.Direct2D1.RenderTests.csproj +++ b/tests/Avalonia.Direct2D1.RenderTests/Avalonia.Direct2D1.RenderTests.csproj @@ -27,4 +27,5 @@ + diff --git a/tests/Avalonia.Direct2D1.UnitTests/Avalonia.Direct2D1.UnitTests.csproj b/tests/Avalonia.Direct2D1.UnitTests/Avalonia.Direct2D1.UnitTests.csproj index e346ce944d..42229ba456 100644 --- a/tests/Avalonia.Direct2D1.UnitTests/Avalonia.Direct2D1.UnitTests.csproj +++ b/tests/Avalonia.Direct2D1.UnitTests/Avalonia.Direct2D1.UnitTests.csproj @@ -7,6 +7,7 @@ + @@ -22,4 +23,4 @@ - \ No newline at end of file + diff --git a/tests/Avalonia.Input.UnitTests/InputElement_Focus.cs b/tests/Avalonia.Input.UnitTests/InputElement_Focus.cs index 09fae7207f..8b8f2fa775 100644 --- a/tests/Avalonia.Input.UnitTests/InputElement_Focus.cs +++ b/tests/Avalonia.Input.UnitTests/InputElement_Focus.cs @@ -121,5 +121,202 @@ namespace Avalonia.Input.UnitTests Assert.False(target2.Classes.Contains(":focus-visible")); } } + + [Fact] + public void Control_FocusWithin_PseudoClass_Should_Be_Applied() + { + using (UnitTestApplication.Start(TestServices.RealFocus)) + { + var target1 = new Decorator(); + var target2 = new Decorator(); + var root = new TestRoot + { + Child = new StackPanel + { + Children = + { + target1, + target2 + } + } + }; + + target1.ApplyTemplate(); + target2.ApplyTemplate(); + + FocusManager.Instance?.Focus(target1); + Assert.True(target1.IsFocused); + Assert.True(target1.Classes.Contains(":focus-within")); + Assert.True(target1.IsKeyboardFocusWithin); + Assert.True(root.Child.Classes.Contains(":focus-within")); + Assert.True(root.Child.IsKeyboardFocusWithin); + Assert.True(root.Classes.Contains(":focus-within")); + Assert.True(root.IsKeyboardFocusWithin); + } + } + + [Fact] + public void Control_FocusWithin_PseudoClass_Should_Be_Applied_and_Removed() + { + using (UnitTestApplication.Start(TestServices.RealFocus)) + { + var target1 = new Decorator(); + var target2 = new Decorator(); + var panel1 = new Panel { Children = { target1 } }; + var panel2 = new Panel { Children = { target2 } }; + var root = new TestRoot + { + Child = new StackPanel + { + Children = + { + panel1, + panel2 + } + } + }; + + target1.ApplyTemplate(); + target2.ApplyTemplate(); + + FocusManager.Instance?.Focus(target1); + Assert.True(target1.IsFocused); + Assert.True(target1.Classes.Contains(":focus-within")); + Assert.True(target1.IsKeyboardFocusWithin); + Assert.True(panel1.Classes.Contains(":focus-within")); + Assert.True(panel1.IsKeyboardFocusWithin); + Assert.True(root.Child.Classes.Contains(":focus-within")); + Assert.True(root.Child.IsKeyboardFocusWithin); + Assert.True(root.Classes.Contains(":focus-within")); + Assert.True(root.IsKeyboardFocusWithin); + + FocusManager.Instance?.Focus(target2); + + Assert.False(target1.IsFocused); + Assert.False(target1.Classes.Contains(":focus-within")); + Assert.False(target1.IsKeyboardFocusWithin); + Assert.False(panel1.Classes.Contains(":focus-within")); + Assert.False(panel1.IsKeyboardFocusWithin); + Assert.True(root.Child.Classes.Contains(":focus-within")); + Assert.True(root.Child.IsKeyboardFocusWithin); + Assert.True(root.Classes.Contains(":focus-within")); + Assert.True(root.IsKeyboardFocusWithin); + + Assert.True(target2.IsFocused); + Assert.True(target2.Classes.Contains(":focus-within")); + Assert.True(target2.IsKeyboardFocusWithin); + Assert.True(panel2.Classes.Contains(":focus-within")); + Assert.True(panel2.IsKeyboardFocusWithin); + } + } + + [Fact] + public void Control_FocusWithin_Pseudoclass_Should_Be_Removed_When_Removed_From_Tree() + { + using (UnitTestApplication.Start(TestServices.RealFocus)) + { + var target1 = new Decorator(); + var target2 = new Decorator(); + var root = new TestRoot + { + Child = new StackPanel + { + Children = + { + target1, + target2 + } + } + }; + + target1.ApplyTemplate(); + target2.ApplyTemplate(); + + FocusManager.Instance?.Focus(target1); + Assert.True(target1.IsFocused); + Assert.True(target1.Classes.Contains(":focus-within")); + Assert.True(target1.IsKeyboardFocusWithin); + Assert.True(root.Child.Classes.Contains(":focus-within")); + Assert.True(root.Child.IsKeyboardFocusWithin); + Assert.True(root.Classes.Contains(":focus-within")); + Assert.True(root.IsKeyboardFocusWithin); + + Assert.Equal(KeyboardDevice.Instance.FocusedElement, target1); + + root.Child = null; + + Assert.Null(KeyboardDevice.Instance.FocusedElement); + + Assert.False(target1.IsFocused); + Assert.False(target1.Classes.Contains(":focus-within")); + Assert.False(target1.IsKeyboardFocusWithin); + Assert.False(root.Classes.Contains(":focus-within")); + Assert.False(root.IsKeyboardFocusWithin); + } + } + + [Fact] + public void Control_FocusWithin_Pseudoclass_Should_Be_Removed_Focus_Moves_To_Different_Root() + { + using (UnitTestApplication.Start(TestServices.RealFocus)) + { + var target1 = new Decorator(); + var target2 = new Decorator(); + + var root1 = new TestRoot + { + Child = new StackPanel + { + Children = + { + target1, + } + } + }; + + var root2 = new TestRoot + { + Child = new StackPanel + { + Children = + { + target2, + } + } + }; + + target1.ApplyTemplate(); + target2.ApplyTemplate(); + + FocusManager.Instance?.Focus(target1); + Assert.True(target1.IsFocused); + Assert.True(target1.Classes.Contains(":focus-within")); + Assert.True(target1.IsKeyboardFocusWithin); + Assert.True(root1.Child.Classes.Contains(":focus-within")); + Assert.True(root1.Child.IsKeyboardFocusWithin); + Assert.True(root1.Classes.Contains(":focus-within")); + Assert.True(root1.IsKeyboardFocusWithin); + + Assert.Equal(KeyboardDevice.Instance.FocusedElement, target1); + + FocusManager.Instance?.Focus(target2); + + Assert.False(target1.IsFocused); + Assert.False(target1.Classes.Contains(":focus-within")); + Assert.False(target1.IsKeyboardFocusWithin); + Assert.False(root1.Child.Classes.Contains(":focus-within")); + Assert.False(root1.Child.IsKeyboardFocusWithin); + Assert.False(root1.Classes.Contains(":focus-within")); + Assert.False(root1.IsKeyboardFocusWithin); + + Assert.True(target2.IsFocused); + Assert.True(target2.Classes.Contains(":focus-within")); + Assert.True(target2.IsKeyboardFocusWithin); + Assert.True(root2.Child.Classes.Contains(":focus-within")); + Assert.True(root2.Child.IsKeyboardFocusWithin); + Assert.True(root2.Classes.Contains(":focus-within")); + Assert.True(root2.IsKeyboardFocusWithin); + } + } } } diff --git a/tests/Avalonia.Layout.UnitTests/Avalonia.Layout.UnitTests.csproj b/tests/Avalonia.Layout.UnitTests/Avalonia.Layout.UnitTests.csproj index 463bc50008..74cc6e292b 100644 --- a/tests/Avalonia.Layout.UnitTests/Avalonia.Layout.UnitTests.csproj +++ b/tests/Avalonia.Layout.UnitTests/Avalonia.Layout.UnitTests.csproj @@ -8,6 +8,7 @@ + diff --git a/tests/Avalonia.LeakTests/Avalonia.LeakTests.csproj b/tests/Avalonia.LeakTests/Avalonia.LeakTests.csproj index 27f3223c6c..d49a859b89 100644 --- a/tests/Avalonia.LeakTests/Avalonia.LeakTests.csproj +++ b/tests/Avalonia.LeakTests/Avalonia.LeakTests.csproj @@ -7,6 +7,7 @@ + @@ -25,4 +26,4 @@ - \ No newline at end of file + diff --git a/tests/Avalonia.Markup.UnitTests/Avalonia.Markup.UnitTests.csproj b/tests/Avalonia.Markup.UnitTests/Avalonia.Markup.UnitTests.csproj index ec5b2f0ed1..7d1285c025 100644 --- a/tests/Avalonia.Markup.UnitTests/Avalonia.Markup.UnitTests.csproj +++ b/tests/Avalonia.Markup.UnitTests/Avalonia.Markup.UnitTests.csproj @@ -10,6 +10,7 @@ + diff --git a/tests/Avalonia.Markup.UnitTests/Data/MultiBindingTests.cs b/tests/Avalonia.Markup.UnitTests/Data/MultiBindingTests.cs index 64f5eb2a0e..b87922aa1e 100644 --- a/tests/Avalonia.Markup.UnitTests/Data/MultiBindingTests.cs +++ b/tests/Avalonia.Markup.UnitTests/Data/MultiBindingTests.cs @@ -157,6 +157,29 @@ namespace Avalonia.Markup.UnitTests.Data Assert.Equal("1,2,Fallback", target.Text); } + [Fact] + public void MultiBinding_Without_StringFormat_And_Converter() + { + var source = new { A = 1, B = 2, C = 3 }; + var target = new ItemsControl { }; + + var binding = new MultiBinding + { + Bindings = new[] + { + new Binding { Path = "A", Source = source }, + new Binding { Path = "B", Source = source }, + new Binding { Path = "C", Source = source }, + }, + }; + + target.Bind(ItemsControl.ItemsProperty, binding); + Assert.Equal(target.ItemCount, 3); + Assert.Equal(target.Items.ElementAt(0), source.A); + Assert.Equal(target.Items.ElementAt(1), source.B); + Assert.Equal(target.Items.ElementAt(2), source.C); + } + private class ConcatConverter : IMultiValueConverter { public object Convert(IList values, Type targetType, object parameter, CultureInfo culture) diff --git a/tests/Avalonia.Markup.UnitTests/Extensions/IEnummerableExtension.cs b/tests/Avalonia.Markup.UnitTests/Extensions/IEnummerableExtension.cs new file mode 100644 index 0000000000..0d9e2969e1 --- /dev/null +++ b/tests/Avalonia.Markup.UnitTests/Extensions/IEnummerableExtension.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections; + +namespace Avalonia.Markup.UnitTests +{ + internal static class IEnumerableExtensions + { + public static object ElementAt(this IEnumerable source, int index) + { + var i = -1; + var enumerator = source.GetEnumerator(); + + while (enumerator.MoveNext() && ++i < index); + if (i == index) + { + return enumerator.Current; + } + throw new ArgumentOutOfRangeException(nameof(index)); + } + } +} diff --git a/tests/Avalonia.Markup.UnitTests/Parsers/ExpressionObserverBuilderTests_AttachedProperty.cs b/tests/Avalonia.Markup.UnitTests/Parsers/ExpressionObserverBuilderTests_AttachedProperty.cs index 45cf28773f..7c48a975ef 100644 --- a/tests/Avalonia.Markup.UnitTests/Parsers/ExpressionObserverBuilderTests_AttachedProperty.cs +++ b/tests/Avalonia.Markup.UnitTests/Parsers/ExpressionObserverBuilderTests_AttachedProperty.cs @@ -129,7 +129,7 @@ namespace Avalonia.Markup.UnitTests.Parsers { var data = new Class1(); - Assert.Throws(() => ExpressionObserverBuilder.Build(data, "(Owner)", typeResolver: _typeResolver)); + Assert.Throws(() => ExpressionObserverBuilder.Build(data, "(Owner.)", typeResolver: _typeResolver)); } [Fact] diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Avalonia.Markup.Xaml.UnitTests.csproj b/tests/Avalonia.Markup.Xaml.UnitTests/Avalonia.Markup.Xaml.UnitTests.csproj index ad3592294d..44b604197d 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/Avalonia.Markup.Xaml.UnitTests.csproj +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Avalonia.Markup.Xaml.UnitTests.csproj @@ -10,6 +10,7 @@ + diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/BindingExtensionTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/BindingExtensionTests.cs index 9ea2cd643a..20ed22e84f 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/BindingExtensionTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/BindingExtensionTests.cs @@ -84,6 +84,54 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions } } + [Fact] + public void SupportCastToTypeInExpression() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var xaml = @" + + +"; + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); + var contentControl = window.FindControl("contentControl"); + + var dataContext = new TestDataContext + { + StringProperty = "foobar" + }; + + window.DataContext = dataContext; + + Assert.Equal(dataContext.StringProperty, contentControl.Content); + } + } + + [Fact] + public void SupportCastToTypeInExpression_DifferentTypeEvaluatesToNull() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var xaml = @" + + +"; + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); + var contentControl = window.FindControl("contentControl"); + + var dataContext = "foo"; + + window.DataContext = dataContext; + + Assert.Equal(null, contentControl.Content); + } + } private class FooBar { public object Foo { get; } = null; diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/CompiledBindingExtensionTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/CompiledBindingExtensionTests.cs index 8a82ad048b..6f549a4ffa 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/CompiledBindingExtensionTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/CompiledBindingExtensionTests.cs @@ -1,13 +1,16 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Globalization; using System.Reactive.Subjects; using System.Text; using System.Threading.Tasks; using Avalonia.Controls; using Avalonia.Controls.Presenters; +using Avalonia.Data.Converters; using Avalonia.Data.Core; using Avalonia.Markup.Data; +using Avalonia.Media; using Avalonia.UnitTests; using XamlX; using Xunit; @@ -372,7 +375,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions "; - Assert.Throws(() => AvaloniaRuntimeXamlLoader.Load(xaml)); + ThrowsXamlTransformException(() => AvaloniaRuntimeXamlLoader.Load(xaml)); } } @@ -390,7 +393,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions "; - Assert.Throws(() => AvaloniaRuntimeXamlLoader.Load(xaml)); + ThrowsXamlTransformException(() => AvaloniaRuntimeXamlLoader.Load(xaml)); } } @@ -447,7 +450,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions "; - Assert.Throws(() => AvaloniaRuntimeXamlLoader.Load(xaml)); + ThrowsXamlTransformException(() => AvaloniaRuntimeXamlLoader.Load(xaml)); } } @@ -534,7 +537,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions } [Fact] - public void ResolvesSourceBindingLongForm() + public void Binds_To_Source() { using (UnitTestApplication.Start(TestServices.StyledWindow)) { @@ -557,6 +560,124 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions } } + [Fact] + public void Binds_To_Source_StaticResource() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var xaml = @" + + + + + +"; + + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); + var textBlock = window.FindControl("textBlock"); + + Assert.Equal("foobar", textBlock.Text); + } + } + + [Fact] + public void Binds_To_Source_StaticResource1() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var xaml = @" + + + + test + + +"; + + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); + var textBlock = window.FindControl("textBlock"); + + Assert.Equal("foobar", textBlock.Text); + } + } + + [Fact] + public void Binds_To_Source_StaticResource_In_ResourceDictionary() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var xaml = @" + + + + + + + +"; + + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); + var textBlock = window.FindControl("textBlock"); + + Assert.Equal("foobar", textBlock.Text); + } + } + + [Fact] + public void Binds_To_Source_StaticResource_In_ResourceDictionary1() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var xaml = @" + + + + + test + + + +"; + + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); + var textBlock = window.FindControl("textBlock"); + + Assert.Equal("foobar", textBlock.Text); + } + } + + [Fact] + public void Binds_To_Source_xStatic() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var xaml = @" + + +"; + + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); + var contentControl = window.FindControl("contentControl"); + + Assert.Equal(Brushes.Red.Color, contentControl.Content); + } + } + [Fact] public void CompilesBindingWhenRequested() { @@ -597,7 +718,49 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions x:CompileBindings='true'> "; - Assert.Throws(() => AvaloniaRuntimeXamlLoader.Load(xaml)); + ThrowsXamlParseException(() => AvaloniaRuntimeXamlLoader.Load(xaml)); + } + } + + [Fact] + public void SupportParentInPath() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var xaml = @" + + +"; + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); + var contentControl = window.FindControl("contentControl"); + + Assert.Equal("foo", contentControl.Content); + } + } + + [Fact] + public void SupportConverterWithParameter() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var xaml = @" + + +"; + + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); + var textBlock = window.FindControl("textBlock"); + + window.DataContext = new TestDataContext() { StringProperty = "Foo" }; + + Assert.Equal("Foo+Bar", textBlock.Text); } } @@ -613,26 +776,218 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions x:DataType='local:TestDataContext' x:CompileBindings='notabool'> "; - Assert.Throws(() => AvaloniaRuntimeXamlLoader.Load(xaml)); + ThrowsXamlParseException(() => AvaloniaRuntimeXamlLoader.Load(xaml)); + } + } + + [Fact] + public void SupportCastToTypeInExpression() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var xaml = @" + + +"; + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); + var contentControl = window.FindControl("contentControl"); + + var dataContext = new TestDataContext(); + + window.DataContext = dataContext; + + Assert.Equal(dataContext, contentControl.Content); } } - } + [Fact] + public void SupportCastToTypeInExpression_DifferentTypeEvaluatesToNull() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var xaml = @" + + +"; + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); + var contentControl = window.FindControl("contentControl"); + + var dataContext = "foo"; + + window.DataContext = dataContext; + + Assert.Equal(null, contentControl.Content); + } + } + + [Fact] + public void SupportCastToTypeInExpressionWithProperty() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var xaml = @" + + +"; + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); + var contentControl = window.FindControl("contentControl"); + + var dataContext = new TestDataContext + { + StringProperty = "foobar" + }; + + window.DataContext = dataContext; + + Assert.Equal(dataContext.StringProperty, contentControl.Content); + } + } + + [Fact] + public void SupportCastToTypeInExpressionWithProperty1() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var xaml = @" + + +"; + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); + var contentControl = window.FindControl("contentControl"); + + var dataContext = new TestDataContext + { + StringProperty = "foobar" + }; + + window.DataContext = dataContext; + + Assert.Equal(dataContext.StringProperty, contentControl.Content); + } + } + + [Fact] + public void SupportCastToTypeInExpressionWithPropertyIndexer() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var xaml = @" + + +"; + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); + var contentControl = window.FindControl("contentControl"); + + var data = new TestData() + { + StringProperty = "Foo" + }; + var dataContext = new TestDataContext + { + ObjectsArrayProperty = new object[] { data } + }; + + window.DataContext = dataContext; + + Assert.Equal(data.StringProperty, contentControl.Content); + } + } + + [Fact] + public void SupportCastToTypeInExpressionWithProperty_DifferentTypeEvaluatesToNull() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var xaml = @" + + +"; + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); + var contentControl = window.FindControl("contentControl"); + + var dataContext = new TestDataContext + { + StringProperty = "foobar" + }; + + window.DataContext = dataContext; + + Assert.Equal(dataContext.StringProperty, contentControl.Content); + + window.DataContext = "foo"; + + Assert.Equal(null, contentControl.Content); + } + } + + void Throws(string type, Action cb) + { + try + { + cb(); + } + catch (Exception e) when (e.GetType().Name == type) + { + return; + } + + throw new Exception("Expected " + type); + } + + void ThrowsXamlParseException(Action cb) => Throws("XamlParseException", cb); + void ThrowsXamlTransformException(Action cb) => Throws("XamlTransformException", cb); + } + public interface INonIntegerIndexer { - string this[string key] {get; set;} + string this[string key] { get; set; } } public interface INonIntegerIndexerDerived : INonIntegerIndexer - {} + { } public interface IHasProperty { - string StringProperty {get; set; } + string StringProperty { get; set; } } public interface IHasPropertyDerived : IHasProperty - {} + { } + + public class AppendConverter : IValueConverter + { + public static IValueConverter Instance { get; } = new AppendConverter(); + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + => string.Format("{0}+{1}", value, parameter); + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + => throw new NotImplementedException(); + + } + + public class TestData + { + public string StringProperty { get; set; } + } public class TestDataContext : IHasPropertyDerived { @@ -646,6 +1001,8 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions public string[] ArrayProperty { get; set; } + public object[] ObjectsArrayProperty { get; set; } + public List ListProperty { get; set; } = new List(); public NonIntegerIndexer NonIntegerIndexerProperty { get; set; } = new NonIntegerIndexer(); diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/DynamicResourceExtensionTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/DynamicResourceExtensionTests.cs index 47a73cb360..9152131ab3 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/DynamicResourceExtensionTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/DynamicResourceExtensionTests.cs @@ -345,6 +345,23 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions Assert.Equal(0xff506070, brush.Color.ToUint32()); } + [Fact] + public void DynamicResource_Can_Be_Assigned_To_Resource_Property_In_Application() + { + var xaml = @" + + + #ff506070 + + +"; + + var application = (Application)AvaloniaRuntimeXamlLoader.Load(xaml); + var brush = (SolidColorBrush)application.Resources["brush"]; + + Assert.Equal(0xff506070, brush.Color.ToUint32()); + } [Fact] public void DynamicResource_Can_Be_Assigned_To_ItemTemplate_Property() diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/ResourceIncludeTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/ResourceIncludeTests.cs index 54e89ae37e..b70d53e038 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/ResourceIncludeTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/ResourceIncludeTests.cs @@ -5,7 +5,7 @@ using Avalonia.Media; using Avalonia.UnitTests; using Xunit; -namespace Avalonia.Markup.Xaml.UnitTests.MakrupExtensions +namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions { public class ResourceIncludeTests : XamlTestBase { diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/StyleIncludeTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/StyleIncludeTests.cs index d35a7e6107..239a109193 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/StyleIncludeTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/StyleIncludeTests.cs @@ -12,7 +12,7 @@ namespace Avalonia.Markup.Xaml.UnitTests { var styleXaml = @"