X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/574c939ef1c1b835a8bc65c0fe724548fa04ec49..c6e2af4570ee868c93fc504b02f321efe5d5acee:/src/msw/dc.cpp diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index 05445fae71..8a05efa95c 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -57,6 +57,11 @@ #include #endif +/* Quaternary raster codes */ +#ifndef MAKEROP4 +#define MAKEROP4(fore,back) (DWORD)((((back) << 8) & 0xFF000000) | (fore)) +#endif + IMPLEMENT_ABSTRACT_CLASS(wxDC, wxDCBase) // --------------------------------------------------------------------------- @@ -127,6 +132,30 @@ private: bool m_changed; }; +// this class saves the old stretch blit mode during its life time +class StretchBltModeChanger +{ +public: + StretchBltModeChanger(HDC hdc, int mode) + : m_hdc(hdc) + { + m_modeOld = ::SetStretchBltMode(m_hdc, mode); + if ( !m_modeOld ) + wxLogLastError(_T("SetStretchBltMode")); + } + + ~StretchBltModeChanger() + { + if ( !::SetStretchBltMode(m_hdc, m_modeOld) ) + wxLogLastError(_T("SetStretchBltMode")); + } + +private: + const HDC m_hdc; + + int m_modeOld; +}; + // =========================================================================== // implementation // =========================================================================== @@ -468,16 +497,17 @@ void wxDC::Clear() ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX, (int)m_logicalOriginY, NULL); } -void wxDC::DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, int style) +bool wxDC::DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, int style) { #ifdef __WXMICROWIN__ - if (!GetHDC()) return; + if (!GetHDC()) return FALSE; #endif - if ( !::ExtFloodFill(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), + bool success = (0 != ::ExtFloodFill(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), col.GetPixel(), style == wxFLOOD_SURFACE ? FLOODFILLSURFACE - : FLOODFILLBORDER) ) + : FLOODFILLBORDER) ) ; + if (!success) { // quoting from the MSDN docs: // @@ -495,6 +525,8 @@ void wxDC::DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, int style) } CalcBoundingBox(x, y); + + return success; } bool wxDC::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const @@ -940,7 +972,7 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask wxPalette *pal = bmp.GetPalette(); if ( pal && ::GetDeviceCaps(cdc,BITSPIXEL) <= 8 ) { - oldPal = ::SelectPalette(hdcMem, GetHpaletteOf(pal), FALSE); + oldPal = ::SelectPalette(hdcMem, GetHpaletteOf(*pal), FALSE); ::RealizePalette(hdcMem); } #endif // wxUSE_PALETTE @@ -995,7 +1027,7 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask wxPalette *pal = bmp.GetPalette(); if ( pal && ::GetDeviceCaps(cdc,BITSPIXEL) <= 8 ) { - oldPal = ::SelectPalette(memdc, GetHpaletteOf(pal), FALSE); + oldPal = ::SelectPalette(memdc, GetHpaletteOf(*pal), FALSE); ::RealizePalette(memdc); } #endif // wxUSE_PALETTE @@ -1126,13 +1158,13 @@ void wxDC::DoDrawRotatedText(const wxString& text, // "upper left" and "upper right" CalcBoundingBox(x, y); - CalcBoundingBox(x + w*cos(rad), y - h*sin(rad)); + CalcBoundingBox(x + wxCoord(w*cos(rad)), y - wxCoord(h*sin(rad))); // "bottom left" and "bottom right" x += (wxCoord)(h*sin(rad)); y += (wxCoord)(h*cos(rad)); CalcBoundingBox(x, y); - CalcBoundingBox(x + h*sin(rad), y + h*cos(rad)); + CalcBoundingBox(x + wxCoord(h*sin(rad)), y + wxCoord(h*cos(rad))); } #endif } @@ -1157,44 +1189,47 @@ void wxDC::DoSelectPalette(bool realize) m_oldPalette = 0; } - if (m_palette.Ok() && m_palette.GetHPALETTE()) + if ( m_palette.Ok() ) { - HPALETTE oldPal = ::SelectPalette(GetHdc(), (HPALETTE) m_palette.GetHPALETTE(), FALSE); + HPALETTE oldPal = ::SelectPalette(GetHdc(), + GetHpaletteOf(m_palette), + FALSE); if (!m_oldPalette) m_oldPalette = (WXHPALETTE) oldPal; if (realize) ::RealizePalette(GetHdc()); } - - } void wxDC::SetPalette(const wxPalette& palette) { - if (palette.Ok()) { + if ( palette.Ok() ) + { m_palette = palette; - DoSelectPalette(true); - } + DoSelectPalette(TRUE); + } } void wxDC::InitializePalette() { - if (wxDisplayDepth() <= 8) { + if ( wxDisplayDepth() <= 8 ) + { // look for any window or parent that has a custom palette. If any has // one then we need to use it in drawing operations - wxWindow *win = m_canvas; - while (!win->HasCustomPalette() && win->GetParent()) win = win->GetParent(); - if (win->HasCustomPalette()) { + wxWindow *win = m_canvas->GetAncestorWithCustomPalette(); + + m_hasCustomPalette = win && win->HasCustomPalette(); + if ( m_hasCustomPalette ) + { m_palette = win->GetPalette(); - m_custompalette = true; + // turn on MSW translation for this palette DoSelectPalette(); - } - else - m_custompalette = false; } + } } + #endif // wxUSE_PALETTE void wxDC::SetFont(const wxFont& the_font) @@ -1797,10 +1832,16 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, if (wxSystemOptions::GetOptionInt(wxT("no-maskblt")) == 0) #endif { - success = ::MaskBlt(GetHdc(), xdest, ydest, width, height, - GetHdcOf(*source), xsrc, ysrc, - (HBITMAP)mask->GetMaskBitmap(), xsrcMask, ysrcMask, - MAKEROP4(dwRop, DSTCOPY)) != 0; + success = ::MaskBlt + ( + GetHdc(), + xdest, ydest, width, height, + GetHdcOf(*source), + xsrc, ysrc, + (HBITMAP)mask->GetMaskBitmap(), + xsrcMask, ysrcMask, + MAKEROP4(dwRop, DSTCOPY) + ) != 0; } if ( !success ) @@ -1890,14 +1931,39 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, } else // no mask, just BitBlt() it { - success = ::BitBlt(GetHdc(), xdest, ydest, - (int)width, (int)height, - GetHdcOf(*source), xsrc, ysrc, dwRop) != 0; + // use StretchBlt() if available + if ( ::GetDeviceCaps(GetHdc(), RASTERCAPS) & RC_STRETCHBLT ) + { + StretchBltModeChanger changeMode(GetHdc(), COLORONCOLOR); + + success = ::StretchBlt + ( + GetHdc(), + xdest, ydest, width, height, + GetHdcOf(*source), + xsrc, ysrc, width, height, + dwRop + ) != 0; + } + else + { + success = ::BitBlt + ( + GetHdc(), + xdest, ydest, + (int)width, (int)height, + GetHdcOf(*source), + xsrc, ysrc, + dwRop + ) != 0; + } + if ( !success ) { - wxLogLastError(wxT("BitBlt")); + wxLogLastError(wxT("BitBlt/StretchBlt")); } } + ::SetTextColor(GetHdc(), old_textground); ::SetBkColor(GetHdc(), old_background); @@ -1920,8 +1986,30 @@ void wxDC::DoGetSizeMM(int *w, int *h) const if (!GetHDC()) return; #endif - if ( w ) *w = ::GetDeviceCaps(GetHdc(), HORZSIZE); - if ( h ) *h = ::GetDeviceCaps(GetHdc(), VERTSIZE); + // if we implement it in terms of DoGetSize() instead of directly using the + // results returned by GetDeviceCaps(HORZ/VERTSIZE) as was done before, it + // will also work for wxWindowDC and wxClientDC even though their size is + // not the same as the total size of the screen + int wPixels, hPixels; + DoGetSize(&wPixels, &hPixels); + + if ( w ) + { + int wTotal = ::GetDeviceCaps(GetHdc(), HORZRES); + + wxCHECK_RET( wTotal, _T("0 width device?") ); + + *w = (wPixels * ::GetDeviceCaps(GetHdc(), HORZSIZE)) / wTotal; + } + + if ( h ) + { + int hTotal = ::GetDeviceCaps(GetHdc(), VERTRES); + + wxCHECK_RET( hTotal, _T("0 height device?") ); + + *h = (hPixels * ::GetDeviceCaps(GetHdc(), VERTSIZE)) / hTotal; + } } wxSize wxDC::GetPPI() const @@ -1947,25 +2035,6 @@ void wxDC::SetLogicalScale(double x, double y) m_logicalScaleY = y; } -#if WXWIN_COMPATIBILITY -void wxDC::DoGetTextExtent(const wxString& string, float *x, float *y, - float *descent, float *externalLeading, - wxFont *theFont, bool use16bit) const -{ -#ifdef __WXMICROWIN__ - if (!GetHDC()) return; -#endif - - wxCoord x1, y1, descent1, externalLeading1; - GetTextExtent(string, & x1, & y1, & descent1, & externalLeading1, theFont, use16bit); - *x = x1; *y = y1; - if (descent) - *descent = descent1; - if (externalLeading) - *externalLeading = externalLeading1; -} -#endif - #if wxUSE_DC_CACHEING /* @@ -2080,12 +2149,12 @@ void wxDC::AddToDCCache(wxDCCacheEntry* entry) void wxDC::ClearCache() { - sm_bitmapCache.DeleteContents(TRUE); - sm_bitmapCache.Clear(); - sm_bitmapCache.DeleteContents(FALSE); sm_dcCache.DeleteContents(TRUE); sm_dcCache.Clear(); sm_dcCache.DeleteContents(FALSE); + sm_bitmapCache.DeleteContents(TRUE); + sm_bitmapCache.Clear(); + sm_bitmapCache.DeleteContents(FALSE); } // Clean up cache at app exit