From 59431015cd5a0b66d06083397dbf40f61156b2a3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 29 Jan 2014 22:24:38 +0000 Subject: [PATCH] Fix wxPrinterDC::DrawIcon() in wxMSW. Make DrawIcon() work when printing: it previously didn't, as we used ::DrawIconEx() Windows function which wasn't supported when printing. Work around this by using DrawBitmap() if necessary. Closes #379. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@75729 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/msw/dc.cpp | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index d40b58855c..b471bee95c 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -617,6 +617,7 @@ wxMSW: - Fix coordinates of EVT_MOUSEWHEEL in frames with toolbars (LtJax). - Support "show" verb as well as "open" in wxFileType (Eric Jensen). - Fix display of bitmaps with alpha in wxStaticBitmap (Artur Wieczorek). +- Make wxPrinterDC::DrawIcon() actually work (Artur Wieczorek). wxOSX: diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index 97a4da07fc..2db8a6065c 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -1271,11 +1271,26 @@ void wxMSWDCImpl::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) wxCHECK_RET( icon.IsOk(), wxT("invalid icon in DrawIcon") ); + // Check if we are printing: notice that it's not enough to just check for + // DT_RASPRINTER as this is also the kind of print preview HDC, but its + // type is OBJ_ENHMETADC while the type of the "real" printer DC is OBJ_DC. + if ( ::GetDeviceCaps(GetHdc(), TECHNOLOGY) == DT_RASPRINTER && + ::GetObjectType(GetHdc()) == OBJ_DC ) + { + // DrawIcon API doesn't work for printer DCs (printer DC is write-only + // and DrawIcon requires DC supporting SRCINVERT ROP). + // We need to convert icon to bitmap and use alternative API calls. + wxBitmap bmp(icon); + DoDrawBitmap(bmp, x, y, !bmp.HasAlpha() /* use mask */); + } + else + { #ifdef __WIN32__ - ::DrawIconEx(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), GetHiconOf(icon), icon.GetWidth(), icon.GetHeight(), 0, NULL, DI_NORMAL); + ::DrawIconEx(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), GetHiconOf(icon), icon.GetWidth(), icon.GetHeight(), 0, NULL, DI_NORMAL); #else - ::DrawIcon(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), GetHiconOf(icon)); + ::DrawIcon(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), GetHiconOf(icon)); #endif + } CalcBoundingBox(x, y); CalcBoundingBox(x + icon.GetWidth(), y + icon.GetHeight());