X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0cbff1201aa47e2b73ec90a97886f18e88270ea6..abfcca57dd0d805ceec9e19c4be207614d79252a:/src/msw/dc.cpp diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index cae9668ac8..dcf230b0b6 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -42,6 +42,7 @@ #include "wx/sysopt.h" #include "wx/dcprint.h" +#include "wx/module.h" #include #include @@ -177,7 +178,9 @@ wxDC::wxDC() m_oldPen = 0; m_oldBrush = 0; m_oldFont = 0; +#if wxUSE_PALETTE m_oldPalette = 0; +#endif // wxUSE_PALETTE m_bOwnsDC = FALSE; m_hDC = 0; @@ -245,16 +248,21 @@ void wxDC::SelectOldObjects(WXHDC dc) ::SelectObject((HDC) dc, (HFONT) m_oldFont); } m_oldFont = 0; + +#if wxUSE_PALETTE if (m_oldPalette) { - ::SelectPalette((HDC) dc, (HPALETTE) m_oldPalette, TRUE); + ::SelectPalette((HDC) dc, (HPALETTE) m_oldPalette, FALSE); } m_oldPalette = 0; +#endif // wxUSE_PALETTE } m_brush = wxNullBrush; m_pen = wxNullPen; +#if wxUSE_PALETTE m_palette = wxNullPalette; +#endif // wxUSE_PALETTE m_font = wxNullFont; m_backgroundBrush = wxNullBrush; m_selectedBitmap = wxNullBitmap; @@ -269,7 +277,7 @@ void wxDC::UpdateClipBox() #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + RECT rect; GetClipBox(GetHdc(), &rect); @@ -284,7 +292,7 @@ void wxDC::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_clipping = TRUE; // the region coords are always the device ones, so do the translation @@ -316,7 +324,7 @@ void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxCHECK_RET( GetHrgnOf(region), wxT("invalid clipping region") ); m_clipping = TRUE; @@ -335,7 +343,7 @@ void wxDC::DestroyClippingRegion() #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + if (m_clipping && m_hDC) { // TODO: this should restore the previous clipping region, @@ -376,7 +384,7 @@ int wxDC::GetDepth() const #ifdef __WXMICROWIN__ if (!GetHDC()) return 16; #endif - + return (int)::GetDeviceCaps(GetHdc(), BITSPIXEL); } @@ -389,7 +397,7 @@ void wxDC::Clear() #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + RECT rect; if ( m_canvas ) { @@ -427,7 +435,7 @@ void wxDC::DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, int style) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + if ( !::ExtFloodFill(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), col.GetPixel(), style == wxFLOOD_SURFACE ? FLOODFILLSURFACE @@ -456,7 +464,7 @@ bool wxDC::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const #ifdef __WXMICROWIN__ if (!GetHDC()) return FALSE; #endif - + wxCHECK_MSG( col, FALSE, _T("NULL colour parameter in wxDC::GetPixel") ); // get the color of the pixel @@ -472,7 +480,7 @@ void wxDC::DoCrossHair(wxCoord x, wxCoord y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxCoord x1 = x-VIEWPORT_EXTENT; wxCoord y1 = y-VIEWPORT_EXTENT; wxCoord x2 = x+VIEWPORT_EXTENT; @@ -493,7 +501,7 @@ void wxDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + (void)MoveToEx(GetHdc(), XLOG2DEV(x1), YLOG2DEV(y1), NULL); (void)LineTo(GetHdc(), XLOG2DEV(x2), YLOG2DEV(y2)); @@ -514,7 +522,7 @@ void wxDC::DoDrawArc(wxCoord x1, wxCoord y1, #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling double dx = xc - x1; @@ -566,7 +574,7 @@ void wxDC::DoDrawCheckMark(wxCoord x1, wxCoord y1, #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxCoord x2 = x1 + width, y2 = y1 + height; @@ -604,7 +612,7 @@ void wxDC::DoDrawPoint(wxCoord x, wxCoord y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + COLORREF color = 0x00ffffff; if (m_pen.Ok()) { @@ -621,7 +629,7 @@ void wxDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffs #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling // Do things less efficiently if we have offsets @@ -658,7 +666,7 @@ void wxDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + // Do things less efficiently if we have offsets if (xoffset != 0 || yoffset != 0) { @@ -689,7 +697,7 @@ void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling wxCoord x2 = x + width; @@ -730,7 +738,7 @@ void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord h #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling // Now, a negative radius value is interpreted to mean @@ -770,7 +778,7 @@ void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling wxCoord x2 = (x+width); @@ -788,7 +796,7 @@ void wxDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,d #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling wxCoord x2 = x + w; @@ -835,7 +843,7 @@ void wxDC::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxCHECK_RET( icon.Ok(), wxT("invalid icon in DrawIcon") ); #ifdef __WIN32__ @@ -853,13 +861,14 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxCHECK_RET( bmp.Ok(), _T("invalid bitmap in wxDC::DrawBitmap") ); int width = bmp.GetWidth(), height = bmp.GetHeight(); HBITMAP hbmpMask = 0; + HPALETTE oldPal = 0; if ( useMask ) { @@ -888,13 +897,19 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask if (wxSystemOptions::GetOptionInt(wxT("no-maskblt")) == 0) #endif { + HDC cdc = GetHdc(); HDC hdcMem = ::CreateCompatibleDC(GetHdc()); ::SelectObject(hdcMem, GetHbitmapOf(bmp)); - - ok = ::MaskBlt(GetHdc(), x, y, width, height, + if (bmp.GetPalette() && (::GetDeviceCaps(cdc,BITSPIXEL) <= 8)) { + oldPal = ::SelectPalette( hdcMem, (HPALETTE)bmp.GetPalette()->GetHPALETTE(), FALSE); + ::RealizePalette(hdcMem); + } + ok = ::MaskBlt(cdc, x, y, width, height, hdcMem, 0, 0, hbmpMask, 0, 0, MAKEROP4(SRCCOPY, DSTCOPY)) != 0; + if (oldPal) + ::SelectPalette(hdcMem, oldPal, FALSE); ::DeleteDC(hdcMem); } @@ -930,8 +945,14 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask ::SetBkColor(GetHdc(), m_textBackgroundColour.GetPixel() ); } + if (bmp.GetPalette() && (::GetDeviceCaps(cdc,BITSPIXEL) <= 8)) { + oldPal = ::SelectPalette( memdc, (HPALETTE)bmp.GetPalette()->GetHPALETTE(), FALSE); + ::RealizePalette(memdc); + } ::SelectObject( memdc, hbitmap ); ::BitBlt( cdc, x, y, width, height, memdc, 0, 0, SRCCOPY); + if (oldPal) + ::SelectPalette(memdc, oldPal, FALSE); ::DeleteDC( memdc ); ::SetTextColor(GetHdc(), old_textground); @@ -944,7 +965,7 @@ void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + DrawAnyText(text, x, y); // update the bounding box @@ -960,7 +981,7 @@ void wxDC::DrawAnyText(const wxString& text, wxCoord x, wxCoord y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + // prepare for drawing the text if ( m_textForegroundColour.Ok() ) SetTextColor(GetHdc(), m_textForegroundColour.GetPixel()); @@ -996,7 +1017,7 @@ void wxDC::DoDrawRotatedText(const wxString& text, #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + // we test that we have some font because otherwise we should still use the // "else" part below to avoid that DrawRotatedText(angle = 180) and // DrawRotatedText(angle = 0) use different fonts (we can't use the default @@ -1008,9 +1029,10 @@ void wxDC::DoDrawRotatedText(const wxString& text, #ifndef __WXMICROWIN__ else { - // NB: don't take DEFAULT_GUI_FONT because it's not TrueType and so - // can't have non zero orientation/escapement - wxFont font = m_font.Ok() ? m_font : *wxNORMAL_FONT; + // NB: don't take DEFAULT_GUI_FONT (a.k.a. wxSYS_DEFAULT_GUI_FONT) + // because it's not TrueType and so can't have non zero + // orientation/escapement under Win9x + wxFont font = m_font.Ok() ? m_font : *wxSWISS_FONT; HFONT hfont = (HFONT)font.GetResourceHandle(); LOGFONT lf; if ( ::GetObject(hfont, sizeof(lf), &lf) == 0 ) @@ -1063,17 +1085,19 @@ void wxDC::DoDrawRotatedText(const wxString& text, // set GDI objects // --------------------------------------------------------------------------- +#if wxUSE_PALETTE + void wxDC::SetPalette(const wxPalette& palette) { #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + // Set the old object temporarily, in case the assignment deletes an object // that's not yet selected out. if (m_oldPalette) { - ::SelectPalette(GetHdc(), (HPALETTE) m_oldPalette, TRUE); + ::SelectPalette(GetHdc(), (HPALETTE) m_oldPalette, FALSE); m_oldPalette = 0; } @@ -1085,7 +1109,7 @@ void wxDC::SetPalette(const wxPalette& palette) // the original colourmap if (m_oldPalette) { - ::SelectPalette(GetHdc(), (HPALETTE) m_oldPalette, TRUE); + ::SelectPalette(GetHdc(), (HPALETTE) m_oldPalette, FALSE); m_oldPalette = 0; } @@ -1094,7 +1118,7 @@ void wxDC::SetPalette(const wxPalette& palette) if (m_palette.Ok() && m_palette.GetHPALETTE()) { - HPALETTE oldPal = ::SelectPalette(GetHdc(), (HPALETTE) m_palette.GetHPALETTE(), TRUE); + HPALETTE oldPal = ::SelectPalette(GetHdc(), (HPALETTE) m_palette.GetHPALETTE(), FALSE); if (!m_oldPalette) m_oldPalette = (WXHPALETTE) oldPal; @@ -1102,12 +1126,14 @@ void wxDC::SetPalette(const wxPalette& palette) } } +#endif // wxUSE_PALETTE + void wxDC::SetFont(const wxFont& the_font) { #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + // Set the old object temporarily, in case the assignment deletes an object // that's not yet selected out. if (m_oldFont) @@ -1142,7 +1168,7 @@ void wxDC::SetPen(const wxPen& pen) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + // Set the old object temporarily, in case the assignment deletes an object // that's not yet selected out. if (m_oldPen) @@ -1176,7 +1202,7 @@ void wxDC::SetBrush(const wxBrush& brush) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + // Set the old object temporarily, in case the assignment deletes an object // that's not yet selected out. if (m_oldBrush) @@ -1227,7 +1253,7 @@ void wxDC::SetBackground(const wxBrush& brush) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_backgroundBrush = brush; if (!m_backgroundBrush.Ok()) @@ -1272,7 +1298,7 @@ void wxDC::SetBackgroundMode(int mode) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_backgroundMode = mode; // SetBackgroundColour now only refers to text background @@ -1292,7 +1318,7 @@ void wxDC::SetLogicalFunction(int function) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_logicalFunction = function; SetRop(m_hDC); @@ -1359,7 +1385,7 @@ wxCoord wxDC::GetCharHeight() const #ifdef __WXMICROWIN__ if (!GetHDC()) return 0; #endif - + TEXTMETRIC lpTextMetric; GetTextMetrics(GetHdc(), &lpTextMetric); @@ -1372,7 +1398,7 @@ wxCoord wxDC::GetCharWidth() const #ifdef __WXMICROWIN__ if (!GetHDC()) return 0; #endif - + TEXTMETRIC lpTextMetric; GetTextMetrics(GetHdc(), &lpTextMetric); @@ -1394,7 +1420,7 @@ void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y, return; } #endif - + HFONT hfontOld; if ( font ) { @@ -1429,7 +1455,7 @@ void wxDC::SetMapMode(int mode) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_mappingMode = mode; int pixel_width = 0; @@ -1501,7 +1527,7 @@ void wxDC::SetUserScale(double x, double y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_userScaleX = x; m_userScaleY = y; @@ -1513,7 +1539,7 @@ void wxDC::SetAxisOrientation(bool xLeftRight, bool yBottomUp) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_signX = xLeftRight ? 1 : -1; m_signY = yBottomUp ? -1 : 1; @@ -1525,7 +1551,7 @@ void wxDC::SetSystemScale(double x, double y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_scaleX = x; m_scaleY = y; @@ -1537,7 +1563,7 @@ void wxDC::SetLogicalOrigin(wxCoord x, wxCoord y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_logicalOriginX = x; m_logicalOriginY = y; @@ -1549,7 +1575,7 @@ void wxDC::SetDeviceOrigin(wxCoord x, wxCoord y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_deviceOriginX = x; m_deviceOriginY = y; @@ -1617,7 +1643,7 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, #ifdef __WXMICROWIN__ if (!GetHDC()) return FALSE; #endif - + wxMask *mask = NULL; if ( useMask ) { @@ -1704,30 +1730,25 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, HBITMAP buffer_bmap ; #if wxUSE_DC_CACHEING - if (CacheEnabled()) - { - // create a temp buffer bitmap and DCs to access it and the mask - wxDCCacheEntry* dcCacheEntry1 = FindDCInCache(NULL, source->GetHDC()); - dc_mask = (HDC) dcCacheEntry1->m_dc; - - wxDCCacheEntry* dcCacheEntry2 = FindDCInCache(dcCacheEntry1, dest->GetHDC()); - dc_buffer = (HDC) dcCacheEntry2->m_dc; - - wxDCCacheEntry* bitmapCacheEntry = FindBitmapInCache(dest->GetHDC(), - width, height); - - buffer_bmap = (HBITMAP) bitmapCacheEntry->m_bitmap; - } - else -#endif - { - // create a temp buffer bitmap and DCs to access it and the mask - dc_mask = ::CreateCompatibleDC(GetHdcOf(*source)); - dc_buffer = ::CreateCompatibleDC(GetHdc()); - buffer_bmap = ::CreateCompatibleBitmap(GetHdc(), width, height); - ::SelectObject(dc_mask, (HBITMAP) mask->GetMaskBitmap()); - ::SelectObject(dc_buffer, buffer_bmap); - } + // create a temp buffer bitmap and DCs to access it and the mask + wxDCCacheEntry* dcCacheEntry1 = FindDCInCache(NULL, source->GetHDC()); + dc_mask = (HDC) dcCacheEntry1->m_dc; + + wxDCCacheEntry* dcCacheEntry2 = FindDCInCache(dcCacheEntry1, GetHDC()); + dc_buffer = (HDC) dcCacheEntry2->m_dc; + + wxDCCacheEntry* bitmapCacheEntry = FindBitmapInCache(GetHDC(), + width, height); + + buffer_bmap = (HBITMAP) bitmapCacheEntry->m_bitmap; +#else // !wxUSE_DC_CACHEING + // create a temp buffer bitmap and DCs to access it and the mask + dc_mask = ::CreateCompatibleDC(GetHdcOf(*source)); + dc_buffer = ::CreateCompatibleDC(GetHdc()); + buffer_bmap = ::CreateCompatibleBitmap(GetHdc(), width, height); +#endif // wxUSE_DC_CACHEING/!wxUSE_DC_CACHEING + ::SelectObject(dc_mask, (HBITMAP) mask->GetMaskBitmap()); + ::SelectObject(dc_buffer, buffer_bmap); // copy dest to buffer if ( !::BitBlt(dc_buffer, 0, 0, (int)width, (int)height, @@ -1776,14 +1797,13 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, ::SelectObject(dc_mask, 0); ::SelectObject(dc_buffer, 0); -#if wxUSE_DC_CACHEING - if (!CacheEnabled()) -#endif +#if !wxUSE_DC_CACHEING { ::DeleteDC(dc_mask); ::DeleteDC(dc_buffer); ::DeleteObject(buffer_bmap); } +#endif } } else // no mask, just BitBlt() it @@ -1807,7 +1827,7 @@ void wxDC::DoGetSize(int *w, int *h) const #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + if ( w ) *w = ::GetDeviceCaps(GetHdc(), HORZRES); if ( h ) *h = ::GetDeviceCaps(GetHdc(), VERTRES); } @@ -1817,7 +1837,7 @@ void wxDC::DoGetSizeMM(int *w, int *h) const #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + if ( w ) *w = ::GetDeviceCaps(GetHdc(), HORZSIZE); if ( h ) *h = ::GetDeviceCaps(GetHdc(), VERTSIZE); } @@ -1827,7 +1847,7 @@ wxSize wxDC::GetPPI() const #ifdef __WXMICROWIN__ if (!GetHDC()) return wxSize(); #endif - + int x = ::GetDeviceCaps(GetHdc(), LOGPIXELSX); int y = ::GetDeviceCaps(GetHdc(), LOGPIXELSY); @@ -1840,7 +1860,7 @@ void wxDC::SetLogicalScale(double x, double y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_logicalScaleX = x; m_logicalScaleY = y; } @@ -1853,7 +1873,7 @@ void wxDC::DoGetTextExtent(const wxString& string, float *x, float *y, #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxCoord x1, y1, descent1, externalLeading1; GetTextExtent(string, & x1, & y1, & descent1, & externalLeading1, theFont, use16bit); *x = x1; *y = y1; @@ -1986,6 +2006,19 @@ void wxDC::ClearCache() sm_dcCache.DeleteContents(FALSE); } +// Clean up cache at app exit +class wxDCModule : public wxModule +{ +public: + virtual bool OnInit() { return TRUE; } + virtual void OnExit() { wxDC::ClearCache(); } + +private: + DECLARE_DYNAMIC_CLASS(wxDCModule) +}; + +IMPLEMENT_DYNAMIC_CLASS(wxDCModule, wxModule) + #endif // wxUSE_DC_CACHEING