From add676efab0f904b6200824c567ac6d238462419 Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 13 Jul 2023 13:08:47 +0300 Subject: [PATCH 01/80] Add failing tests --- .../TransitioningContentControlTests.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/Avalonia.Controls.UnitTests/TransitioningContentControlTests.cs b/tests/Avalonia.Controls.UnitTests/TransitioningContentControlTests.cs index 02dd4e6c03..0e817b1887 100644 --- a/tests/Avalonia.Controls.UnitTests/TransitioningContentControlTests.cs +++ b/tests/Avalonia.Controls.UnitTests/TransitioningContentControlTests.cs @@ -183,6 +183,31 @@ namespace Avalonia.Controls.UnitTests Assert.Equal("bar", presenter2.Content); } + [Fact] + public void Logical_Children_Dont_Duplicated() + { + using var app = Start(); + var (target, transition) = CreateTarget(""); + + var childControl = new Control(); + target.Content = childControl; + + // There should be two, One the initial content and one the new content. + Assert.Equal(2, target.LogicalChildren.Count); + } + + [Fact] + public void First_Presenter_Register_TCC_As_Host() + { + using var app = Start(); + var (target, transition) = CreateTarget(""); + + var childControl = new Control(); + target.Presenter!.Content = childControl; + + Assert.Contains(childControl, target.LogicalChildren); + } + private static IDisposable Start() { return UnitTestApplication.Start( From f7a584e86e0db552cd5509bd827361360ff8211c Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 13 Jul 2023 13:14:11 +0300 Subject: [PATCH 02/80] Return true when first presenter register and fix logical children duplicated --- src/Avalonia.Controls/ContentControl.cs | 16 ++++++++++++++++ .../TransitioningContentControl.cs | 11 +++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls/ContentControl.cs b/src/Avalonia.Controls/ContentControl.cs index 867dca2be1..176157001e 100644 --- a/src/Avalonia.Controls/ContentControl.cs +++ b/src/Avalonia.Controls/ContentControl.cs @@ -95,6 +95,17 @@ namespace Avalonia.Controls /// IAvaloniaList IContentPresenterHost.LogicalChildren => LogicalChildren; + /// + /// Determine whether manage his LogicalChildren + ///(default behavior) himself, or leaves the management to the inherited control. + /// + /// + /// The default value is false, So the manages itself, + /// if you want to bypass this behavior and manage LogicalChildren yourself, set + /// the to true. + /// + protected virtual bool BypassLogicalChildrenManangment => false; + /// bool IContentPresenterHost.RegisterContentPresenter(ContentPresenter presenter) { @@ -118,6 +129,11 @@ namespace Avalonia.Controls private void ContentChanged(AvaloniaPropertyChangedEventArgs e) { + if (BypassLogicalChildrenManangment) + { + return; + } + if (e.OldValue is ILogical oldChild) { LogicalChildren.Remove(oldChild); diff --git a/src/Avalonia.Controls/TransitioningContentControl.cs b/src/Avalonia.Controls/TransitioningContentControl.cs index bf540698f1..75f95d1d68 100644 --- a/src/Avalonia.Controls/TransitioningContentControl.cs +++ b/src/Avalonia.Controls/TransitioningContentControl.cs @@ -36,6 +36,9 @@ public class TransitioningContentControl : ContentControl set => SetValue(PageTransitionProperty, value); } + /// + protected override bool BypassLogicalChildrenManangment => true; + protected override Size ArrangeOverride(Size finalSize) { var result = base.ArrangeOverride(finalSize); @@ -79,8 +82,12 @@ public class TransitioningContentControl : ContentControl protected override bool RegisterContentPresenter(ContentPresenter presenter) { - if (!base.RegisterContentPresenter(presenter) && - presenter is ContentPresenter p && + if (base.RegisterContentPresenter(presenter)) + { + return true; + } + + if (presenter is ContentPresenter p && p.Name == "PART_ContentPresenter2") { _presenter2 = p; From abc7eea3369642162617c9a20a91b27e0d7b87dc Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 13 Jul 2023 15:33:42 +0300 Subject: [PATCH 03/80] simplifies the first test --- .../TransitioningContentControlTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Avalonia.Controls.UnitTests/TransitioningContentControlTests.cs b/tests/Avalonia.Controls.UnitTests/TransitioningContentControlTests.cs index 0e817b1887..210b24b3ad 100644 --- a/tests/Avalonia.Controls.UnitTests/TransitioningContentControlTests.cs +++ b/tests/Avalonia.Controls.UnitTests/TransitioningContentControlTests.cs @@ -188,12 +188,12 @@ namespace Avalonia.Controls.UnitTests { using var app = Start(); var (target, transition) = CreateTarget(""); + target.PageTransition = null; var childControl = new Control(); target.Content = childControl; - // There should be two, One the initial content and one the new content. - Assert.Equal(2, target.LogicalChildren.Count); + Assert.Equal(1, target.LogicalChildren.Count); } [Fact] From 35be25ee2e99f03ca0dfa6f96f0c6dd47edf8d05 Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 13 Jul 2023 16:38:11 +0300 Subject: [PATCH 04/80] typo --- src/Avalonia.Controls/ContentControl.cs | 4 ++-- src/Avalonia.Controls/TransitioningContentControl.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.Controls/ContentControl.cs b/src/Avalonia.Controls/ContentControl.cs index 176157001e..362931eafa 100644 --- a/src/Avalonia.Controls/ContentControl.cs +++ b/src/Avalonia.Controls/ContentControl.cs @@ -102,9 +102,9 @@ namespace Avalonia.Controls /// /// The default value is false, So the manages itself, /// if you want to bypass this behavior and manage LogicalChildren yourself, set - /// the to true. + /// the to true. /// - protected virtual bool BypassLogicalChildrenManangment => false; + protected virtual bool BypassLogicalChildrenManagement => false; /// bool IContentPresenterHost.RegisterContentPresenter(ContentPresenter presenter) diff --git a/src/Avalonia.Controls/TransitioningContentControl.cs b/src/Avalonia.Controls/TransitioningContentControl.cs index 75f95d1d68..c113afde17 100644 --- a/src/Avalonia.Controls/TransitioningContentControl.cs +++ b/src/Avalonia.Controls/TransitioningContentControl.cs @@ -37,7 +37,7 @@ public class TransitioningContentControl : ContentControl } /// - protected override bool BypassLogicalChildrenManangment => true; + protected override bool BypassLogicalChildrenManagement => true; protected override Size ArrangeOverride(Size finalSize) { From 007800357865a37db308512ff4731b42ee9bcf15 Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 13 Jul 2023 21:02:45 +0300 Subject: [PATCH 05/80] typo --- src/Avalonia.Controls/ContentControl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/ContentControl.cs b/src/Avalonia.Controls/ContentControl.cs index 362931eafa..47f7598900 100644 --- a/src/Avalonia.Controls/ContentControl.cs +++ b/src/Avalonia.Controls/ContentControl.cs @@ -129,7 +129,7 @@ namespace Avalonia.Controls private void ContentChanged(AvaloniaPropertyChangedEventArgs e) { - if (BypassLogicalChildrenManangment) + if (BypassLogicalChildrenManagement) { return; } From 45b592c8b102f3a2ac23fb83559a0470dac36eef Mon Sep 17 00:00:00 2001 From: Vitaliy Orazov Date: Mon, 17 Jul 2023 15:27:05 +0300 Subject: [PATCH 06/80] fix CF_DIB value (https://learn.microsoft.com/en-us/windows/win32/dataxchg/standard-clipboard-formats says that CF_DIB is equal to 8) --- src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs b/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs index 68f3e3c670..9c1e68453c 100644 --- a/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs +++ b/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs @@ -2137,7 +2137,7 @@ namespace Avalonia.Win32.Interop /// /// A memory object containing a BITMAPINFO structure followed by the bitmap bits. /// - CF_DIB = 3, + CF_DIB = 8, /// /// Unicode text format. Each line ends with a carriage return/linefeed (CR-LF) combination. A null character signals the end of the data. /// From e02476f88c7cc19dd754e207e5e4cbef84e85484 Mon Sep 17 00:00:00 2001 From: Vitaliy Orazov Date: Mon, 17 Jul 2023 15:36:48 +0300 Subject: [PATCH 07/80] add predefined image clipboard formats because GetClipboardFormatName cannot get a name for predefined. The Unknown_Format_ template is poor for system formats --- src/Windows/Avalonia.Win32/ClipboardFormats.cs | 7 +++++++ .../Avalonia.Win32/Interop/UnmanagedMethods.cs | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Windows/Avalonia.Win32/ClipboardFormats.cs b/src/Windows/Avalonia.Win32/ClipboardFormats.cs index 00fdeb2a1d..b1b1a67ba0 100644 --- a/src/Windows/Avalonia.Win32/ClipboardFormats.cs +++ b/src/Windows/Avalonia.Win32/ClipboardFormats.cs @@ -33,6 +33,13 @@ namespace Avalonia.Win32 #pragma warning disable CS0618 // Type or member is obsolete new ClipboardFormat(DataFormats.FileNames, (ushort)UnmanagedMethods.ClipboardFormat.CF_HDROP), #pragma warning restore CS0618 // Type or member is obsolete + + new ClipboardFormat("Bitmap", (ushort)UnmanagedMethods.ClipboardFormat.CF_BITMAP), + new ClipboardFormat("MetafilePict", (ushort)UnmanagedMethods.ClipboardFormat.CF_METAFILEPICT), + new ClipboardFormat("Dib", (ushort)UnmanagedMethods.ClipboardFormat.CF_DIB), + new ClipboardFormat("EnhancedMetafile", (ushort)UnmanagedMethods.ClipboardFormat.CF_ENHMETAFILE), + new ClipboardFormat("Palette", (ushort)UnmanagedMethods.ClipboardFormat.CF_PALETTE), + new ClipboardFormat("PenData", (ushort)UnmanagedMethods.ClipboardFormat.CF_PENDATA), }; diff --git a/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs b/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs index 9c1e68453c..f2987f50d5 100644 --- a/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs +++ b/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs @@ -2135,14 +2135,30 @@ namespace Avalonia.Win32.Interop /// CF_BITMAP = 2, /// + /// Handle to a metafile picture format as defined by the METAFILEPICT structure. When passing a CF_METAFILEPICT handle by means of DDE, the application responsible for deleting hMem should also free the metafile referred to by the CF_METAFILEPICT handle. + /// + CF_METAFILEPICT = 3, + /// /// A memory object containing a BITMAPINFO structure followed by the bitmap bits. /// CF_DIB = 8, /// + /// Handle to a color palette. + /// + CF_PALETTE = 9, + /// + /// Data for the pen extensions to the Microsoft Windows for Pen Computing. + /// + CF_PENDATA = 10, + /// /// Unicode text format. Each line ends with a carriage return/linefeed (CR-LF) combination. A null character signals the end of the data. /// CF_UNICODETEXT = 13, /// + /// A handle to an enhanced metafile (HENHMETAFILE). + /// + CF_ENHMETAFILE = 14, + /// /// A handle to type HDROP that identifies a list of files. /// CF_HDROP = 15, From 2b7dbdb9707dc3521411bfb94683bfc5c6940525 Mon Sep 17 00:00:00 2001 From: Vitaliy Orazov Date: Mon, 17 Jul 2023 19:52:36 +0300 Subject: [PATCH 08/80] add predefined image clipboard formats because GetClipboardFormatName cannot get a name for predefined. The Unknown_Format_ template is poor for system formats --- src/Windows/Avalonia.Win32/ClipboardFormats.cs | 2 +- src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Windows/Avalonia.Win32/ClipboardFormats.cs b/src/Windows/Avalonia.Win32/ClipboardFormats.cs index b1b1a67ba0..5d5bad5ffd 100644 --- a/src/Windows/Avalonia.Win32/ClipboardFormats.cs +++ b/src/Windows/Avalonia.Win32/ClipboardFormats.cs @@ -36,7 +36,7 @@ namespace Avalonia.Win32 new ClipboardFormat("Bitmap", (ushort)UnmanagedMethods.ClipboardFormat.CF_BITMAP), new ClipboardFormat("MetafilePict", (ushort)UnmanagedMethods.ClipboardFormat.CF_METAFILEPICT), - new ClipboardFormat("Dib", (ushort)UnmanagedMethods.ClipboardFormat.CF_DIB), + new ClipboardFormat("Dib", (ushort)UnmanagedMethods.ClipboardFormat.CF_DIB, (ushort)UnmanagedMethods.ClipboardFormat.CF_DIBV5), new ClipboardFormat("EnhancedMetafile", (ushort)UnmanagedMethods.ClipboardFormat.CF_ENHMETAFILE), new ClipboardFormat("Palette", (ushort)UnmanagedMethods.ClipboardFormat.CF_PALETTE), new ClipboardFormat("PenData", (ushort)UnmanagedMethods.ClipboardFormat.CF_PENDATA), diff --git a/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs b/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs index f2987f50d5..a1e9165117 100644 --- a/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs +++ b/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs @@ -2162,6 +2162,10 @@ namespace Avalonia.Win32.Interop /// A handle to type HDROP that identifies a list of files. /// CF_HDROP = 15, + /// + /// A memory object containing a BITMAPV5HEADER structure followed by the bitmap color space information and the bitmap bits. + /// + CF_DIBV5 = 17, } public struct MSG From 2f51fec236b41a0643023379426cbce749ec2f9e Mon Sep 17 00:00:00 2001 From: Vitaliy Orazov Date: Mon, 17 Jul 2023 19:54:08 +0300 Subject: [PATCH 09/80] wip. ControlCatalog. handling of bitmap formats in clipboard --- .../ControlCatalog/Pages/ClipboardPage.xaml | 8 +++-- .../Pages/ClipboardPage.xaml.cs | 31 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/samples/ControlCatalog/Pages/ClipboardPage.xaml b/samples/ControlCatalog/Pages/ClipboardPage.xaml index 4199a9780f..664e0036e5 100644 --- a/samples/ControlCatalog/Pages/ClipboardPage.xaml +++ b/samples/ControlCatalog/Pages/ClipboardPage.xaml @@ -12,12 +12,16 @@