diff --git a/Avalonia.sln b/Avalonia.sln index 74a2dbb94b..75f1dd8407 100644 --- a/Avalonia.sln +++ b/Avalonia.sln @@ -230,6 +230,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MicroComGenerator", "src\to 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 @@ -2116,6 +2118,30 @@ Global {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 @@ -2176,6 +2202,7 @@ Global {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/Documentation/build.md b/Documentation/build.md index 2f59146a48..5f75290424 100644 --- a/Documentation/build.md +++ b/Documentation/build.md @@ -60,15 +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: -- (for revisions after 2 Nov 2020) Run `./build.sh GenerateCppHeaders` to generate `avalonia-native.h` from `avn.idl` -- 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/build/ApiDiff.props b/build/ApiDiff.props index 3d322f56d5..fb65ef6e87 100644 --- a/build/ApiDiff.props +++ b/build/ApiDiff.props @@ -1,6 +1,6 @@  - 0.10.0-preview3 + 0.10.0-preview6 $(PackageId) Avalonia 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/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 a5c0aa1bea..43ec995ed9 100644 --- a/build/SharedVersion.props +++ b/build/SharedVersion.props @@ -16,7 +16,7 @@ https://github.com/AvaloniaUI/Avalonia/releases git $(MSBuildThisFileDirectory)\avalonia.snk - false + true $(DefineConstants);SIGNED_BUILD 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/menu.h b/native/Avalonia.Native/src/OSX/menu.h index 0e43b22846..564fdc132b 100644 --- a/native/Avalonia.Native/src/OSX/menu.h +++ b/native/Avalonia.Native/src/OSX/menu.h @@ -45,7 +45,7 @@ public: virtual HRESULT SetTitle (char* utf8String) override; - virtual HRESULT SetGesture (char* key, AvnInputModifiers modifiers) override; + virtual HRESULT SetGesture (AvnKey key, AvnInputModifiers modifiers) override; virtual HRESULT SetAction (IAvnPredicateCallback* predicate, IAvnActionCallback* callback) override; diff --git a/native/Avalonia.Native/src/OSX/menu.mm b/native/Avalonia.Native/src/OSX/menu.mm index 1356388b85..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 { @@ -122,23 +125,57 @@ HRESULT AvnAppMenuItem::SetTitle (char* utf8String) } } -HRESULT AvnAppMenuItem::SetGesture (char* 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; - - [_native setKeyEquivalent:[NSString stringWithUTF8String:(const char*)key]]; - [_native setKeyEquivalentModifierMask:flags]; + 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; + } + } + } + } + + // Nothing matched... clear. + [_native setKeyEquivalent: @""]; + [_native setKeyEquivalentModifierMask: 0]; return S_OK; } 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..00b6dab219 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 @@ -143,13 +144,17 @@ static IAvnGlSurfaceRenderTarget* CreateGlRenderTarget(IOSurfaceRenderTarget* ta return _layer; } -- (void)resize:(AvnPixelSize)size withScale: (float) scale;{ +- (void)resize:(AvnPixelSize)size withScale: (float) scale{ @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 +164,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 e3996a1fae..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(); diff --git a/nukebuild/Build.cs b/nukebuild/Build.cs index 97647a1c59..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,10 +132,10 @@ 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")); }); @@ -157,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") ); @@ -194,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 @@ -242,10 +242,10 @@ partial class Build : NukeBuild var webappTestDir = RootDirectory / "tests" / "Avalonia.DesignerSupport.Tests" / "Remote" / "HtmlTransport" / "webapp"; NpmTasks.NpmInstall(c => c - .SetWorkingDirectory(webappTestDir) - .SetArgumentConfigurator(a => a.Add("--silent"))); + .SetProcessWorkingDirectory(webappTestDir) + .SetProcessArgumentConfigurator(a => a.Add("--silent"))); NpmTasks.NpmRun(c => c - .SetWorkingDirectory(webappTestDir) + .SetProcessWorkingDirectory(webappTestDir) .SetCommand("test")); }); diff --git a/nukebuild/_build.csproj b/nukebuild/_build.csproj index 745c727be2..b0380cc92b 100644 --- a/nukebuild/_build.csproj +++ b/nukebuild/_build.csproj @@ -10,7 +10,7 @@ - + diff --git a/samples/BindingDemo/App.xaml.cs b/samples/BindingDemo/App.xaml.cs index eb2da03a7e..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() .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.Desktop/Program.cs b/samples/ControlCatalog.Desktop/Program.cs index 5af646b180..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 { @@ -19,8 +18,7 @@ namespace ControlCatalog public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure() .LogToTrace() - .UsePlatformDetect() - .UseReactiveUI(); + .UsePlatformDetect(); private static void ConfigureAssetAssembly(AppBuilder builder) { diff --git a/samples/ControlCatalog.NetCore/Program.cs b/samples/ControlCatalog.NetCore/Program.cs index 675ea2e10f..1dc8c09c0e 100644 --- a/samples/ControlCatalog.NetCore/Program.cs +++ b/samples/ControlCatalog.NetCore/Program.cs @@ -10,7 +10,6 @@ using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Dialogs; using Avalonia.Headless; using Avalonia.LogicalTree; -using Avalonia.ReactiveUI; using Avalonia.Threading; namespace ControlCatalog.NetCore @@ -118,7 +117,6 @@ namespace ControlCatalog.NetCore AllowEglInitialization = true }) .UseSkia() - .UseReactiveUI() .UseManagedSystemDialogs() .LogToTrace(); 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/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/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/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.cs b/samples/ControlCatalog/Pages/LabelsPage.axaml.cs index b8503d6ae6..a14978fd2c 100644 --- a/samples/ControlCatalog/Pages/LabelsPage.axaml.cs +++ b/samples/ControlCatalog/Pages/LabelsPage.axaml.cs @@ -2,7 +2,6 @@ using Avalonia.Controls; using Avalonia.Markup.Xaml; using ControlCatalog.Models; -using ReactiveUI; namespace ControlCatalog.Pages { 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.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/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/TabControlPage.xaml.cs b/samples/ControlCatalog/Pages/TabControlPage.xaml.cs index a38a3ab4cb..f49b13091b 100644 --- a/samples/ControlCatalog/Pages/TabControlPage.xaml.cs +++ b/samples/ControlCatalog/Pages/TabControlPage.xaml.cs @@ -6,7 +6,7 @@ using Avalonia.Markup.Xaml; using Avalonia.Media.Imaging; using Avalonia.Platform; -using ReactiveUI; +using MiniMvvm; namespace ControlCatalog.Pages { @@ -56,7 +56,7 @@ namespace ControlCatalog.Pages return new Bitmap(assets.Open(new Uri(uri))); } - private class PageViewModel : ReactiveObject + private class PageViewModel : ViewModelBase { private Dock _tabPlacement; 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 e6ec963d75..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() .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/Program.cs b/samples/Sandbox/Program.cs index 7d41a8b8c0..1e74105196 100644 --- a/samples/Sandbox/Program.cs +++ b/samples/Sandbox/Program.cs @@ -1,5 +1,4 @@ using Avalonia; -using Avalonia.ReactiveUI; namespace Sandbox { @@ -9,7 +8,6 @@ namespace Sandbox { AppBuilder.Configure() .UsePlatformDetect() - .UseReactiveUI() .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 46c05f74b2..febda46450 100644 --- a/samples/VirtualizationDemo/Program.cs +++ b/samples/VirtualizationDemo/Program.cs @@ -1,5 +1,4 @@ using Avalonia; -using Avalonia.ReactiveUI; namespace VirtualizationDemo { @@ -8,7 +7,6 @@ namespace VirtualizationDemo public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure() .UsePlatformDetect() - .UseReactiveUI() .LogToTrace(); public static int Main(string[] 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/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.AndroidTestApplication/Avalonia.AndroidTestApplication.csproj b/src/Android/Avalonia.AndroidTestApplication/Avalonia.AndroidTestApplication.csproj index b8697e0ca2..f880e48282 100644 --- a/src/Android/Avalonia.AndroidTestApplication/Avalonia.AndroidTestApplication.csproj +++ b/src/Android/Avalonia.AndroidTestApplication/Avalonia.AndroidTestApplication.csproj @@ -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 diff --git a/src/Avalonia.Base/ApiCompatBaseline.txt b/src/Avalonia.Base/ApiCompatBaseline.txt index 5d19373a92..d17f25ec49 100644 --- a/src/Avalonia.Base/ApiCompatBaseline.txt +++ b/src/Avalonia.Base/ApiCompatBaseline.txt @@ -1,4 +1,4 @@ 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. -TypesMustExist : Type 'Avalonia.Logging.DebugLogSink' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public void Avalonia.Threading.AvaloniaSynchronizationContext..ctor(Avalonia.Threading.AvaloniaSynchronizationContext.INonPumpingPlatformWaitProvider)' does not exist in the implementation but it does exist in the contract. +TypesMustExist : Type 'Avalonia.Threading.AvaloniaSynchronizationContext.INonPumpingPlatformWaitProvider' does not exist in the implementation but it does exist in the contract. Total Issues: 2 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/Properties/AssemblyInfo.cs b/src/Avalonia.Base/Properties/AssemblyInfo.cs index e06cb75a4d..b054c186ae 100644 --- a/src/Avalonia.Base/Properties/AssemblyInfo.cs +++ b/src/Avalonia.Base/Properties/AssemblyInfo.cs @@ -11,10 +11,12 @@ using Avalonia.Metadata; [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/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/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 0b9b50e771..6ef8a98fae 100644 --- a/src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs +++ b/src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs @@ -46,7 +46,9 @@ namespace Avalonia.Build.Tasks string output, bool verifyIl, MessageImportance logImportance, string strongNameKey, bool patchCom, bool skipXamlCompilation) { - var typeSystem = new CecilTypeSystem(references.Concat(new[] { input }), input); + var typeSystem = new CecilTypeSystem(references + .Where(r => !r.ToLowerInvariant().EndsWith("avalonia.build.tasks.dll")) + .Concat(new[] { input }), input); var asm = typeSystem.TargetAssemblyDefinition; diff --git a/src/Avalonia.Controls.DataGrid/ApiCompatBaseline.txt b/src/Avalonia.Controls.DataGrid/ApiCompatBaseline.txt index 82472c505a..fcc74cf864 100644 --- a/src/Avalonia.Controls.DataGrid/ApiCompatBaseline.txt +++ b/src/Avalonia.Controls.DataGrid/ApiCompatBaseline.txt @@ -1,5 +1 @@ -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 +Total Issues: 0 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.Themes.Default/ToggleSwitch.xaml b/src/Avalonia.Themes.Default/ToggleSwitch.xaml index 9d1c024eb9..f11f77df5a 100644 --- a/src/Avalonia.Themes.Default/ToggleSwitch.xaml +++ b/src/Avalonia.Themes.Default/ToggleSwitch.xaml @@ -5,7 +5,7 @@ 0,0,0,6 6 6 - 154 + 0 0 1 diff --git a/src/Avalonia.Themes.Fluent/ApiCompatBaseline.txt b/src/Avalonia.Themes.Fluent/ApiCompatBaseline.txt new file mode 100644 index 0000000000..44e250b889 --- /dev/null +++ b/src/Avalonia.Themes.Fluent/ApiCompatBaseline.txt @@ -0,0 +1,4 @@ +Compat issues with assembly Avalonia.Themes.Fluent: +CannotRemoveBaseTypeOrInterface : Type 'Avalonia.Themes.Fluent.FluentTheme' does not inherit from base type 'Avalonia.Styling.Styles' in the implementation but it does in the contract. +MembersMustExist : Member 'public void Avalonia.Themes.Fluent.FluentTheme..ctor()' does not exist in the implementation but it does exist in the contract. +Total Issues: 2 diff --git a/src/Avalonia.Themes.Fluent/AutoCompleteBox.xaml b/src/Avalonia.Themes.Fluent/Controls/AutoCompleteBox.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/AutoCompleteBox.xaml rename to src/Avalonia.Themes.Fluent/Controls/AutoCompleteBox.xaml diff --git a/src/Avalonia.Themes.Fluent/Button.xaml b/src/Avalonia.Themes.Fluent/Controls/Button.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/Button.xaml rename to src/Avalonia.Themes.Fluent/Controls/Button.xaml diff --git a/src/Avalonia.Themes.Fluent/ButtonSpinner.xaml b/src/Avalonia.Themes.Fluent/Controls/ButtonSpinner.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/ButtonSpinner.xaml rename to src/Avalonia.Themes.Fluent/Controls/ButtonSpinner.xaml diff --git a/src/Avalonia.Themes.Fluent/Calendar.xaml b/src/Avalonia.Themes.Fluent/Controls/Calendar.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/Calendar.xaml rename to src/Avalonia.Themes.Fluent/Controls/Calendar.xaml diff --git a/src/Avalonia.Themes.Fluent/CalendarButton.xaml b/src/Avalonia.Themes.Fluent/Controls/CalendarButton.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/CalendarButton.xaml rename to src/Avalonia.Themes.Fluent/Controls/CalendarButton.xaml diff --git a/src/Avalonia.Themes.Fluent/CalendarDatePicker.xaml b/src/Avalonia.Themes.Fluent/Controls/CalendarDatePicker.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/CalendarDatePicker.xaml rename to src/Avalonia.Themes.Fluent/Controls/CalendarDatePicker.xaml diff --git a/src/Avalonia.Themes.Fluent/CalendarDayButton.xaml b/src/Avalonia.Themes.Fluent/Controls/CalendarDayButton.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/CalendarDayButton.xaml rename to src/Avalonia.Themes.Fluent/Controls/CalendarDayButton.xaml diff --git a/src/Avalonia.Themes.Fluent/CalendarItem.xaml b/src/Avalonia.Themes.Fluent/Controls/CalendarItem.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/CalendarItem.xaml rename to src/Avalonia.Themes.Fluent/Controls/CalendarItem.xaml diff --git a/src/Avalonia.Themes.Fluent/CaptionButtons.xaml b/src/Avalonia.Themes.Fluent/Controls/CaptionButtons.xaml similarity index 91% rename from src/Avalonia.Themes.Fluent/CaptionButtons.xaml rename to src/Avalonia.Themes.Fluent/Controls/CaptionButtons.xaml index f288372b77..1f8887c283 100644 --- a/src/Avalonia.Themes.Fluent/CaptionButtons.xaml +++ b/src/Avalonia.Themes.Fluent/Controls/CaptionButtons.xaml @@ -3,7 +3,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/Slider.xaml b/src/Avalonia.Themes.Fluent/Controls/Slider.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/Slider.xaml rename to src/Avalonia.Themes.Fluent/Controls/Slider.xaml diff --git a/src/Avalonia.Themes.Fluent/SplitView.xaml b/src/Avalonia.Themes.Fluent/Controls/SplitView.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/SplitView.xaml rename to src/Avalonia.Themes.Fluent/Controls/SplitView.xaml diff --git a/src/Avalonia.Themes.Fluent/TabControl.xaml b/src/Avalonia.Themes.Fluent/Controls/TabControl.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/TabControl.xaml rename to src/Avalonia.Themes.Fluent/Controls/TabControl.xaml diff --git a/src/Avalonia.Themes.Fluent/TabItem.xaml b/src/Avalonia.Themes.Fluent/Controls/TabItem.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/TabItem.xaml rename to src/Avalonia.Themes.Fluent/Controls/TabItem.xaml diff --git a/src/Avalonia.Themes.Fluent/TabStrip.xaml b/src/Avalonia.Themes.Fluent/Controls/TabStrip.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/TabStrip.xaml rename to src/Avalonia.Themes.Fluent/Controls/TabStrip.xaml diff --git a/src/Avalonia.Themes.Fluent/TabStripItem.xaml b/src/Avalonia.Themes.Fluent/Controls/TabStripItem.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/TabStripItem.xaml rename to src/Avalonia.Themes.Fluent/Controls/TabStripItem.xaml diff --git a/src/Avalonia.Themes.Fluent/TextBox.xaml b/src/Avalonia.Themes.Fluent/Controls/TextBox.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/TextBox.xaml rename to src/Avalonia.Themes.Fluent/Controls/TextBox.xaml diff --git a/src/Avalonia.Themes.Fluent/TimePicker.xaml b/src/Avalonia.Themes.Fluent/Controls/TimePicker.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/TimePicker.xaml rename to src/Avalonia.Themes.Fluent/Controls/TimePicker.xaml diff --git a/src/Avalonia.Themes.Fluent/TitleBar.xaml b/src/Avalonia.Themes.Fluent/Controls/TitleBar.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/TitleBar.xaml rename to src/Avalonia.Themes.Fluent/Controls/TitleBar.xaml diff --git a/src/Avalonia.Themes.Fluent/ToggleButton.xaml b/src/Avalonia.Themes.Fluent/Controls/ToggleButton.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/ToggleButton.xaml rename to src/Avalonia.Themes.Fluent/Controls/ToggleButton.xaml diff --git a/src/Avalonia.Themes.Fluent/ToggleSwitch.xaml b/src/Avalonia.Themes.Fluent/Controls/ToggleSwitch.xaml similarity index 99% rename from src/Avalonia.Themes.Fluent/ToggleSwitch.xaml rename to src/Avalonia.Themes.Fluent/Controls/ToggleSwitch.xaml index 2491225a44..45537e41ad 100644 --- a/src/Avalonia.Themes.Fluent/ToggleSwitch.xaml +++ b/src/Avalonia.Themes.Fluent/Controls/ToggleSwitch.xaml @@ -5,7 +5,7 @@ 0,0,0,6 6 6 - 154 + 0 diff --git a/src/Avalonia.Themes.Fluent/ToolTip.xaml b/src/Avalonia.Themes.Fluent/Controls/ToolTip.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/ToolTip.xaml rename to src/Avalonia.Themes.Fluent/Controls/ToolTip.xaml diff --git a/src/Avalonia.Themes.Fluent/TreeView.xaml b/src/Avalonia.Themes.Fluent/Controls/TreeView.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/TreeView.xaml rename to src/Avalonia.Themes.Fluent/Controls/TreeView.xaml diff --git a/src/Avalonia.Themes.Fluent/TreeViewItem.xaml b/src/Avalonia.Themes.Fluent/Controls/TreeViewItem.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/TreeViewItem.xaml rename to src/Avalonia.Themes.Fluent/Controls/TreeViewItem.xaml diff --git a/src/Avalonia.Themes.Fluent/UserControl.xaml b/src/Avalonia.Themes.Fluent/Controls/UserControl.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/UserControl.xaml rename to src/Avalonia.Themes.Fluent/Controls/UserControl.xaml diff --git a/src/Avalonia.Themes.Fluent/Window.xaml b/src/Avalonia.Themes.Fluent/Controls/Window.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/Window.xaml rename to src/Avalonia.Themes.Fluent/Controls/Window.xaml diff --git a/src/Avalonia.Themes.Fluent/WindowNotificationManager.xaml b/src/Avalonia.Themes.Fluent/Controls/WindowNotificationManager.xaml similarity index 100% rename from src/Avalonia.Themes.Fluent/WindowNotificationManager.xaml rename to src/Avalonia.Themes.Fluent/Controls/WindowNotificationManager.xaml 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 4e0e4fe862..0000000000 --- a/src/Avalonia.Themes.Fluent/FluentTheme.xaml +++ /dev/null @@ -1,62 +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.Visuals/ApiCompatBaseline.txt b/src/Avalonia.Visuals/ApiCompatBaseline.txt index 2d00d82a46..62f4def701 100644 --- a/src/Avalonia.Visuals/ApiCompatBaseline.txt +++ b/src/Avalonia.Visuals/ApiCompatBaseline.txt @@ -1,39 +1,5 @@ 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.Geometry.GetRenderBounds(Avalonia.Media.Pen)' does not exist in the implementation but it does exist in the contract. -MembersMustExist : Member 'public System.Boolean Avalonia.Media.Geometry.StrokeContains(Avalonia.Media.Pen, Avalonia.Point)' 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: 37 +MembersMustExist : Member 'public Avalonia.StyledProperty> Avalonia.StyledProperty> Avalonia.Media.DashStyle.DashesProperty' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Collections.Generic.IReadOnlyList Avalonia.Media.DashStyle.Dashes.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public void Avalonia.Media.DashStyle.Dashes.set(System.Collections.Generic.IReadOnlyList)' does not exist in the implementation but it does exist in the contract. +Total Issues: 3 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/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/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/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/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/Rendering/DeferredRenderer.cs b/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs index 1c8a47c4b7..3bd8e05ee2 100644 --- a/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs +++ b/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs @@ -607,6 +607,7 @@ namespace Avalonia.Rendering private bool? UpdateScene() { Dispatcher.UIThread.VerifyAccess(); + using var noPump = NonPumpingLockHelper.Use(); lock (_sceneLock) { if (_disposed) 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/X11Window.cs b/src/Avalonia.X11/X11Window.cs index 41c061613d..b061920d6a 100644 --- a/src/Avalonia.X11/X11Window.cs +++ b/src/Avalonia.X11/X11Window.cs @@ -823,7 +823,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); diff --git a/src/Avalonia.X11/XI2Manager.cs b/src/Avalonia.X11/XI2Manager.cs index b3a24e6c37..8cdf24cc7b 100644 --- a/src/Avalonia.X11/XI2Manager.cs +++ b/src/Avalonia.X11/XI2Manager.cs @@ -351,7 +351,7 @@ namespace Avalonia.X11 if (state.HasFlag(XModifierMask.Mod4Mask)) Modifiers |= RawInputModifiers.Meta; - Modifiers = ParseButtonState(ev->buttons.MaskLen, ev->buttons.Mask); + Modifiers |= ParseButtonState(ev->buttons.MaskLen, ev->buttons.Mask); Valuators = new Dictionary(); Position = new Point(ev->event_x, ev->event_y); 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/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/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 15413689f8..a82f5b9e60 100644 --- a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlLanguage.cs +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlLanguage.cs @@ -2,8 +2,10 @@ 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; @@ -175,37 +177,13 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions } var text = textNode.Text; - var types = context.GetAvaloniaTypes(); - 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)) + if (AvaloniaXamlIlLanguageParseIntrinsics.TryConvert(context, node, text, type, types, out result)) { - result = new AvaloniaXamlIlFontFamilyAstNode(types, text, node); return true; } - + if (type.FullName == "Avalonia.AvaloniaProperty") { var scope = context.ParentNodes().OfType().FirstOrDefault(); 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/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/AvaloniaXamlIlWellKnownTypes.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlWellKnownTypes.cs index 58f4ddfe31..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,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using XamlX.Emit; using XamlX.IL; using XamlX.Transform; @@ -48,11 +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) { @@ -110,10 +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.FindConstructor(new List { Uri, XamlIlTypes.String }); + 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/xamlil.github b/src/Markup/Avalonia.Markup.Xaml.Loader/xamlil.github index 5420df861c..ea80a607c5 160000 --- a/src/Markup/Avalonia.Markup.Xaml.Loader/xamlil.github +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/xamlil.github @@ -1 +1 @@ -Subproject commit 5420df861ce6f2be5ead9efa078fe7242ce88f18 +Subproject commit ea80a607c5e9d8f000160dbbb48c27ed4cfafbc9 diff --git a/src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt b/src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt index c87dcacda4..fcc74cf864 100644 --- a/src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt +++ b/src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt @@ -1,4 +1 @@ -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 +Total Issues: 0 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/Skia/Avalonia.Skia/DrawingContextImpl.cs b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs index 44e0c82110..2a79a4bb50 100644 --- a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs +++ b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs @@ -434,7 +434,7 @@ namespace Avalonia.Skia /// public IDrawingContextLayerImpl CreateLayer(Size size) { - return CreateRenderTarget( size); + return CreateRenderTarget(size, true); } /// @@ -673,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); @@ -748,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)) { @@ -978,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 @@ -992,7 +993,8 @@ namespace Avalonia.Skia DisableTextLcdRendering = !_canTextUseLcdRendering, GrContext = _grContext, Gpu = _gpu, - Session = _session + Session = _session, + DisableManualFbo = !isLayer, }; return new SurfaceRenderTarget(createInfo); 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/SurfaceRenderTarget.cs b/src/Skia/Avalonia.Skia/SurfaceRenderTarget.cs index 6347c64aed..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, createInfo.Session); + if (!createInfo.DisableManualFbo) + _surface = _gpu?.TryCreateSurface(PixelSize, createInfo.Session); if (_surface == null) _surface = new SkiaSurfaceWrapper(CreateSurface(createInfo.GrContext, PixelSize.Width, PixelSize.Height, createInfo.Format)); @@ -220,6 +221,8 @@ namespace Avalonia.Skia public ISkiaGpu Gpu; public ISkiaGpuRenderSession Session; + + public bool DisableManualFbo; } } } 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/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 7fb146899b..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 diff --git a/src/Windows/Avalonia.Win32/Win32Platform.cs b/src/Windows/Avalonia.Win32/Win32Platform.cs index 5b16cae26e..1c519f10e7 100644 --- a/src/Windows/Avalonia.Win32/Win32Platform.cs +++ b/src/Windows/Avalonia.Win32/Win32Platform.cs @@ -16,6 +16,7 @@ using Avalonia.OpenGL.Egl; using Avalonia.Platform; using Avalonia.Rendering; using Avalonia.Threading; +using Avalonia.Utilities; using Avalonia.Win32.Input; using Avalonia.Win32.Interop; using static Avalonia.Win32.Interop.UnmanagedMethods; @@ -110,7 +111,7 @@ 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(); @@ -229,7 +230,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/WinUICompositorConnection.cs b/src/Windows/Avalonia.Win32/WinRT/Composition/WinUICompositorConnection.cs index 7e1f97ab84..2aa82436f6 100644 --- a/src/Windows/Avalonia.Win32/WinRT/Composition/WinUICompositorConnection.cs +++ b/src/Windows/Avalonia.Win32/WinRT/Composition/WinUICompositorConnection.cs @@ -134,7 +134,7 @@ namespace Avalonia.Win32.WinRT.Composition public static void TryCreateAndRegister(EglPlatformOpenGlInterface angle) { const int majorRequired = 10; - const int buildRequired = 16299; + const int buildRequired = 17134; var majorInstalled = Win32Platform.WindowsVersion.Major; var buildInstalled = Win32Platform.WindowsVersion.Build; diff --git a/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs b/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs index d770f4b211..e7d16f731c 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs @@ -65,23 +65,10 @@ namespace Avalonia.Win32 return IntPtr.Zero; } - // 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. - // This is described here: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enablewindow#remarks - // Our window closed callback will set enabled state to a correct value after child window gets destroyed. - // We need to verify if parent is still alive (perhaps it got destroyed somehow). - if (_parent != null && IsWindow(_parent._hwnd)) - { - var wasActive = GetActiveWindow() == _hwnd; - - _parent.SetEnabled(true); + BeforeCloseCleanup(false); - // 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); - } - } + // Used to distinguish between programmatic and regular close requests. + _isCloseRequested = true; break; } @@ -361,6 +348,7 @@ namespace Avalonia.Win32 case WindowsMessage.WM_PAINT: { + using(NonPumpingSyncContext.Use()) using (_rendererLock.Lock()) { if (BeginPaint(_hwnd, out PAINTSTRUCT ps) != IntPtr.Zero) @@ -378,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 c603128a18..3c09d2b7a0 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.cs @@ -83,6 +83,7 @@ namespace Avalonia.Win32 private POINT _maxTrackSize; private WindowImpl _parent; private ExtendClientAreaChromeHints _extendChromeHints = ExtendClientAreaChromeHints.Default; + private bool _isCloseRequested; public WindowImpl() { @@ -242,7 +243,7 @@ namespace Avalonia.Win32 { if (IsWindowVisible(_hwnd)) { - ShowWindow(value); + ShowWindow(value, true); } else { @@ -506,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; } @@ -559,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; } @@ -900,7 +909,7 @@ namespace Avalonia.Win32 ExtendClientAreaToDecorationsChanged?.Invoke(_isClientAreaExtended); } - private void ShowWindow(WindowState state) + private void ShowWindow(WindowState state, bool activate) { ShowWindowCommand? command; @@ -910,7 +919,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; @@ -919,7 +928,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: @@ -948,6 +958,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/MicroComGenerator/CppGen.cs b/src/tools/MicroComGenerator/CppGen.cs index 68192ebffe..b053088ca9 100644 --- a/src/tools/MicroComGenerator/CppGen.cs +++ b/src/tools/MicroComGenerator/CppGen.cs @@ -14,7 +14,10 @@ namespace MicroComGenerator name = "unsigned char"; else if(name == "uint") name = "unsigned int"; - return name + new string('*', type.PointerLevel); + + type = type.Clone(); + type.Name = name; + return type.Format(); } public static string GenerateCpp(AstIdlNode idl) 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.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..39a3250686 100644 --- a/tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs +++ b/tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs @@ -79,7 +79,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 +99,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 +109,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 +130,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 +177,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 +193,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 +297,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 +321,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/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.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.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.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/CompiledBindingExtensionTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/CompiledBindingExtensionTests.cs index de9ecc8bb0..6f549a4ffa 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/CompiledBindingExtensionTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/CompiledBindingExtensionTests.cs @@ -375,7 +375,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions "; - Assert.Throws(() => AvaloniaRuntimeXamlLoader.Load(xaml)); + ThrowsXamlTransformException(() => AvaloniaRuntimeXamlLoader.Load(xaml)); } } @@ -393,7 +393,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions "; - Assert.Throws(() => AvaloniaRuntimeXamlLoader.Load(xaml)); + ThrowsXamlTransformException(() => AvaloniaRuntimeXamlLoader.Load(xaml)); } } @@ -450,7 +450,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions "; - Assert.Throws(() => AvaloniaRuntimeXamlLoader.Load(xaml)); + ThrowsXamlTransformException(() => AvaloniaRuntimeXamlLoader.Load(xaml)); } } @@ -718,7 +718,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions x:CompileBindings='true'> "; - Assert.Throws(() => AvaloniaRuntimeXamlLoader.Load(xaml)); + ThrowsXamlParseException(() => AvaloniaRuntimeXamlLoader.Load(xaml)); } } @@ -776,7 +776,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions x:DataType='local:TestDataContext' x:CompileBindings='notabool'> "; - Assert.Throws(() => AvaloniaRuntimeXamlLoader.Load(xaml)); + ThrowsXamlParseException(() => AvaloniaRuntimeXamlLoader.Load(xaml)); } } @@ -937,8 +937,25 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions 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; } 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/Xaml/ShapeTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/ShapeTests.cs new file mode 100644 index 0000000000..bd577e84f8 --- /dev/null +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/ShapeTests.cs @@ -0,0 +1,24 @@ +using Avalonia.Controls; +using Avalonia.Media; +using Xunit; + +namespace Avalonia.Markup.Xaml.UnitTests.Xaml +{ + public class ShapeTests : XamlTestBase + { + [Fact] + public void Can_Specify_DashStyle_In_XAML() + { + var xaml = @" + + + + +"; + + var target = AvaloniaRuntimeXamlLoader.Parse(xaml); + + Assert.NotNull(target); + } + } +} diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/XamlIlTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/XamlIlTests.cs index 67e46d25c3..77a4932ccc 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/XamlIlTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/XamlIlTests.cs @@ -295,8 +295,27 @@ namespace Avalonia.Markup.Xaml.UnitTests Assert.Equal("Test", templated.Text); } } + + [Fact] + public void Should_Work_With_Base_Property() + { + var parsed = (ListBox)AvaloniaRuntimeXamlLoader.Load(@" + + + + + + +"); + + Assert.NotNull(parsed.ItemTemplate); + } } - + public class XamlIlBugTestsEventHandlerCodeBehind : Window { public object SavedContext; diff --git a/tests/Avalonia.Skia.RenderTests/Avalonia.Skia.RenderTests.csproj b/tests/Avalonia.Skia.RenderTests/Avalonia.Skia.RenderTests.csproj index 65df5e7cb0..14d0f4debf 100644 --- a/tests/Avalonia.Skia.RenderTests/Avalonia.Skia.RenderTests.csproj +++ b/tests/Avalonia.Skia.RenderTests/Avalonia.Skia.RenderTests.csproj @@ -29,4 +29,5 @@ + diff --git a/tests/Avalonia.Skia.UnitTests/Avalonia.Skia.UnitTests.csproj b/tests/Avalonia.Skia.UnitTests/Avalonia.Skia.UnitTests.csproj index 584eaf6fa9..ef69865e32 100644 --- a/tests/Avalonia.Skia.UnitTests/Avalonia.Skia.UnitTests.csproj +++ b/tests/Avalonia.Skia.UnitTests/Avalonia.Skia.UnitTests.csproj @@ -8,6 +8,7 @@ + @@ -23,4 +24,4 @@ - \ No newline at end of file + diff --git a/tests/Avalonia.Styling.UnitTests/Avalonia.Styling.UnitTests.csproj b/tests/Avalonia.Styling.UnitTests/Avalonia.Styling.UnitTests.csproj index 2b7f6263a7..a07ec050a6 100644 --- a/tests/Avalonia.Styling.UnitTests/Avalonia.Styling.UnitTests.csproj +++ b/tests/Avalonia.Styling.UnitTests/Avalonia.Styling.UnitTests.csproj @@ -11,6 +11,7 @@ + diff --git a/tests/Avalonia.UnitTests/Avalonia.UnitTests.csproj b/tests/Avalonia.UnitTests/Avalonia.UnitTests.csproj index 6b5c7a66ff..d4abf9416a 100644 --- a/tests/Avalonia.UnitTests/Avalonia.UnitTests.csproj +++ b/tests/Avalonia.UnitTests/Avalonia.UnitTests.csproj @@ -28,4 +28,5 @@ + diff --git a/tests/Avalonia.UnitTests/MockWindowingPlatform.cs b/tests/Avalonia.UnitTests/MockWindowingPlatform.cs index 9ec8ca2d36..8a24a8366f 100644 --- a/tests/Avalonia.UnitTests/MockWindowingPlatform.cs +++ b/tests/Avalonia.UnitTests/MockWindowingPlatform.cs @@ -58,7 +58,7 @@ namespace Avalonia.UnitTests windowImpl.Object.Resized?.Invoke(clientSize); }); - windowImpl.Setup(x => x.Show()).Callback(() => + windowImpl.Setup(x => x.Show(true)).Callback(() => { windowImpl.Object.Activated?.Invoke(); }); diff --git a/tests/Avalonia.Visuals.UnitTests/Avalonia.Visuals.UnitTests.csproj b/tests/Avalonia.Visuals.UnitTests/Avalonia.Visuals.UnitTests.csproj index aee54e87a9..13a04be5db 100644 --- a/tests/Avalonia.Visuals.UnitTests/Avalonia.Visuals.UnitTests.csproj +++ b/tests/Avalonia.Visuals.UnitTests/Avalonia.Visuals.UnitTests.csproj @@ -13,6 +13,7 @@ + diff --git a/tests/Avalonia.Visuals.UnitTests/Media/PathSegmentTests.cs b/tests/Avalonia.Visuals.UnitTests/Media/PathSegmentTests.cs new file mode 100644 index 0000000000..0737b4dc88 --- /dev/null +++ b/tests/Avalonia.Visuals.UnitTests/Media/PathSegmentTests.cs @@ -0,0 +1,34 @@ +using Avalonia.Media; +using Xunit; + +namespace Avalonia.Visuals.UnitTests.Media +{ + public class PathSegmentTests + { + [Fact] + public void PathSegment_Triggers_Invalidation_On_Property_Change() + { + var targetSegment = new ArcSegment() + { + Size = new Size(10, 10), + Point = new Point(5, 5) + }; + + var target = new PathGeometry + { + Figures = new PathFigures + { + new PathFigure { IsClosed = false, Segments = new PathSegments { targetSegment } } + } + }; + + var changed = false; + + target.Changed += (s, e) => changed = true; + + targetSegment.Size = new Size(20, 20); + + Assert.True(changed); + } + } +} diff --git a/tests/Avalonia.Visuals.UnitTests/Media/PenTests.cs b/tests/Avalonia.Visuals.UnitTests/Media/PenTests.cs index 418ac7576b..c2a1a5f9e4 100644 --- a/tests/Avalonia.Visuals.UnitTests/Media/PenTests.cs +++ b/tests/Avalonia.Visuals.UnitTests/Media/PenTests.cs @@ -1,4 +1,5 @@ -using Avalonia.Media; +using Avalonia.Collections; +using Avalonia.Media; using Avalonia.Media.Immutable; using Xunit; @@ -39,7 +40,20 @@ namespace Avalonia.Visuals.UnitTests.Media var raised = false; target.Invalidated += (s, e) => raised = true; - dashes.Dashes = new[] { 0.1, 0.2 }; + dashes.Dashes = new AvaloniaList { 0.1, 0.2 }; + + Assert.True(raised); + } + + [Fact] + public void Adding_DashStyle_Dashes_Raises_Invalidated() + { + var dashes = new DashStyle(); + var target = new Pen { DashStyle = dashes }; + var raised = false; + + target.Invalidated += (s, e) => raised = true; + dashes.Dashes.Add(0.3); Assert.True(raised); } diff --git a/tests/Avalonia.Visuals.UnitTests/VisualTests.cs b/tests/Avalonia.Visuals.UnitTests/VisualTests.cs index 447a68aa69..38131fbfca 100644 --- a/tests/Avalonia.Visuals.UnitTests/VisualTests.cs +++ b/tests/Avalonia.Visuals.UnitTests/VisualTests.cs @@ -235,6 +235,25 @@ namespace Avalonia.Visuals.UnitTests Assert.Equal(new Point(100, 100), point); } + [Fact] + public void TransformToVisual_With_NonInvertible_RenderTransform_Should_Work() + { + var child = new Decorator + { + Width = 100, + Height = 100, + RenderTransform = new ScaleTransform() { ScaleX = 0, ScaleY = 0 } + }; + var root = new TestRoot() { Child = child, Width = 400, Height = 400 }; + + root.Measure(Size.Infinity); + root.Arrange(new Rect(new Point(), root.DesiredSize)); + + var tr = root.TransformToVisual(child); + + Assert.Null(tr); + } + [Fact] public void Should_Not_Log_Binding_Error_When_Not_Attached_To_Logical_Tree() {