From b1fad4da44b9d826d43181daccef3ab3e696a75f Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sun, 30 Apr 2017 21:35:01 +0200 Subject: [PATCH] Convert 0RGB wxBitmaps to RGB when copying them to clipboard Not all applications recognize properly 0RGB bitmap format so for the sake of interoperability bitmaps in such format should be converted to plain 24 bpp RGB format prior to being copied to the clipboard. Closes #17640. --- docs/changes.txt | 1 + src/msw/clipbrd.cpp | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index b018089c04..7279ef8c9c 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -178,6 +178,7 @@ wxMSW: - Use cairo_win32_surface_create_with_format() to create ARGB surface from wxMemoryDC (Cairo >= 1.15.4). - Fix updating bounding box in wxDC::DrawSpline(). +- Fix placing 0RGB wxBitmaps on the clipboard. wxOSX: diff --git a/src/msw/clipbrd.cpp b/src/msw/clipbrd.cpp index 0989172123..4174d34f4d 100644 --- a/src/msw/clipbrd.cpp +++ b/src/msw/clipbrd.cpp @@ -636,6 +636,26 @@ bool wxClipboard::AddData( wxDataObject *data ) wxCHECK_MSG( data, false, wxT("data is invalid") ); + const wxDataFormat format = data->GetPreferredFormat(); + if ( format == wxDF_BITMAP || format == wxDF_DIB ) + { + wxBitmapDataObject* bmpData = (wxBitmapDataObject*)data; + wxBitmap bmp = bmpData->GetBitmap(); + wxASSERT_MSG( bmp.IsOk(), wxS("Invalid bitmap") ); + // Replace 0RGB bitmap with its RGB copy + // to ensure compatibility with applications + // not recognizing bitmaps in 0RGB format. + if ( bmp.GetDepth() == 32 && !bmp.HasAlpha() ) + { + wxBitmap bmpRGB(bmp.GetSize(), 24); + wxMemoryDC dc(bmpRGB); + dc.DrawBitmap(bmp, 0, 0); + dc.SelectObject(wxNullBitmap); + + bmpData->SetBitmap(bmpRGB); + } + } + #if wxUSE_OLE_CLIPBOARD HRESULT hr = OleSetClipboard(data->GetInterface()); if ( FAILED(hr) ) @@ -664,8 +684,6 @@ bool wxClipboard::AddData( wxDataObject *data ) #elif wxUSE_DATAOBJ wxCHECK_MSG( wxIsClipboardOpened(), false, wxT("clipboard not open") ); - wxDataFormat format = data->GetPreferredFormat(); - switch ( format ) { case wxDF_TEXT: @@ -681,7 +699,7 @@ bool wxClipboard::AddData( wxDataObject *data ) { wxBitmapDataObject* bitmapDataObject = (wxBitmapDataObject*) data; wxBitmap bitmap(bitmapDataObject->GetBitmap()); - return wxSetClipboardData(data->GetPreferredFormat(), &bitmap); + return wxSetClipboardData(format, &bitmap); } #if wxUSE_METAFILE