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.
This commit is contained in:
@@ -178,6 +178,7 @@ wxMSW:
|
|||||||
- Use cairo_win32_surface_create_with_format() to create ARGB surface from
|
- Use cairo_win32_surface_create_with_format() to create ARGB surface from
|
||||||
wxMemoryDC (Cairo >= 1.15.4).
|
wxMemoryDC (Cairo >= 1.15.4).
|
||||||
- Fix updating bounding box in wxDC::DrawSpline().
|
- Fix updating bounding box in wxDC::DrawSpline().
|
||||||
|
- Fix placing 0RGB wxBitmaps on the clipboard.
|
||||||
|
|
||||||
wxOSX:
|
wxOSX:
|
||||||
|
|
||||||
|
@@ -636,6 +636,26 @@ bool wxClipboard::AddData( wxDataObject *data )
|
|||||||
|
|
||||||
wxCHECK_MSG( data, false, wxT("data is invalid") );
|
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
|
#if wxUSE_OLE_CLIPBOARD
|
||||||
HRESULT hr = OleSetClipboard(data->GetInterface());
|
HRESULT hr = OleSetClipboard(data->GetInterface());
|
||||||
if ( FAILED(hr) )
|
if ( FAILED(hr) )
|
||||||
@@ -664,8 +684,6 @@ bool wxClipboard::AddData( wxDataObject *data )
|
|||||||
#elif wxUSE_DATAOBJ
|
#elif wxUSE_DATAOBJ
|
||||||
wxCHECK_MSG( wxIsClipboardOpened(), false, wxT("clipboard not open") );
|
wxCHECK_MSG( wxIsClipboardOpened(), false, wxT("clipboard not open") );
|
||||||
|
|
||||||
wxDataFormat format = data->GetPreferredFormat();
|
|
||||||
|
|
||||||
switch ( format )
|
switch ( format )
|
||||||
{
|
{
|
||||||
case wxDF_TEXT:
|
case wxDF_TEXT:
|
||||||
@@ -681,7 +699,7 @@ bool wxClipboard::AddData( wxDataObject *data )
|
|||||||
{
|
{
|
||||||
wxBitmapDataObject* bitmapDataObject = (wxBitmapDataObject*) data;
|
wxBitmapDataObject* bitmapDataObject = (wxBitmapDataObject*) data;
|
||||||
wxBitmap bitmap(bitmapDataObject->GetBitmap());
|
wxBitmap bitmap(bitmapDataObject->GetBitmap());
|
||||||
return wxSetClipboardData(data->GetPreferredFormat(), &bitmap);
|
return wxSetClipboardData(format, &bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if wxUSE_METAFILE
|
#if wxUSE_METAFILE
|
||||||
|
Reference in New Issue
Block a user