X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/277480474552707c27c7466bb5e5d1738a16372b..31a06b07cce898a22d0ca3992501e85da9c22f13:/src/msw/dc.cpp diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index a9cfabdf12..596a748cf3 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); } 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,7 +861,7 @@ 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(), @@ -944,7 +952,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 +968,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 +1004,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 +1016,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,12 +1072,14 @@ 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) @@ -1102,12 +1113,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 +1155,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 +1189,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 +1240,7 @@ void wxDC::SetBackground(const wxBrush& brush) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_backgroundBrush = brush; if (!m_backgroundBrush.Ok()) @@ -1272,7 +1285,7 @@ void wxDC::SetBackgroundMode(int mode) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_backgroundMode = mode; // SetBackgroundColour now only refers to text background @@ -1292,7 +1305,7 @@ void wxDC::SetLogicalFunction(int function) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_logicalFunction = function; SetRop(m_hDC); @@ -1359,7 +1372,7 @@ wxCoord wxDC::GetCharHeight() const #ifdef __WXMICROWIN__ if (!GetHDC()) return 0; #endif - + TEXTMETRIC lpTextMetric; GetTextMetrics(GetHdc(), &lpTextMetric); @@ -1372,7 +1385,7 @@ wxCoord wxDC::GetCharWidth() const #ifdef __WXMICROWIN__ if (!GetHDC()) return 0; #endif - + TEXTMETRIC lpTextMetric; GetTextMetrics(GetHdc(), &lpTextMetric); @@ -1394,7 +1407,7 @@ void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y, return; } #endif - + HFONT hfontOld; if ( font ) { @@ -1429,7 +1442,7 @@ void wxDC::SetMapMode(int mode) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_mappingMode = mode; int pixel_width = 0; @@ -1501,7 +1514,7 @@ void wxDC::SetUserScale(double x, double y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_userScaleX = x; m_userScaleY = y; @@ -1513,7 +1526,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 +1538,7 @@ void wxDC::SetSystemScale(double x, double y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_scaleX = x; m_scaleY = y; @@ -1537,7 +1550,7 @@ void wxDC::SetLogicalOrigin(wxCoord x, wxCoord y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_logicalOriginX = x; m_logicalOriginY = y; @@ -1549,7 +1562,7 @@ void wxDC::SetDeviceOrigin(wxCoord x, wxCoord y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_deviceOriginX = x; m_deviceOriginY = y; @@ -1617,7 +1630,7 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, #ifdef __WXMICROWIN__ if (!GetHDC()) return FALSE; #endif - + wxMask *mask = NULL; if ( useMask ) { @@ -1704,30 +1717,25 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, HBITMAP buffer_bmap ; #if wxUSE_DC_CACHEING - if (TRUE) - { - // 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, @@ -1806,7 +1814,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); } @@ -1816,7 +1824,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); } @@ -1826,7 +1834,7 @@ wxSize wxDC::GetPPI() const #ifdef __WXMICROWIN__ if (!GetHDC()) return wxSize(); #endif - + int x = ::GetDeviceCaps(GetHdc(), LOGPIXELSX); int y = ::GetDeviceCaps(GetHdc(), LOGPIXELSY); @@ -1839,7 +1847,7 @@ void wxDC::SetLogicalScale(double x, double y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_logicalScaleX = x; m_logicalScaleY = y; } @@ -1852,7 +1860,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; @@ -1985,6 +1993,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