From 45b592c8b102f3a2ac23fb83559a0470dac36eef Mon Sep 17 00:00:00 2001 From: Vitaliy Orazov Date: Mon, 17 Jul 2023 15:27:05 +0300 Subject: [PATCH 01/12] 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 02/12] 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 03/12] 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 04/12] 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 @@