X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4770df95a0ace5e4e8f67e8ea85392e464fbaad2..50d0b061eeeb4f87594ccea7508a7c5975fb36dd:/src/msw/dc.cpp?ds=sidebyside diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index 7606a64098..dcf230b0b6 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -178,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; @@ -246,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; @@ -270,7 +277,7 @@ void wxDC::UpdateClipBox() #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + RECT rect; GetClipBox(GetHdc(), &rect); @@ -285,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 @@ -317,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; @@ -336,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, @@ -377,7 +384,7 @@ int wxDC::GetDepth() const #ifdef __WXMICROWIN__ if (!GetHDC()) return 16; #endif - + return (int)::GetDeviceCaps(GetHdc(), BITSPIXEL); } @@ -390,7 +397,7 @@ void wxDC::Clear() #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + RECT rect; if ( m_canvas ) { @@ -428,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 @@ -457,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 @@ -473,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; @@ -494,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)); @@ -515,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; @@ -567,7 +574,7 @@ void wxDC::DoDrawCheckMark(wxCoord x1, wxCoord y1, #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxCoord x2 = x1 + width, y2 = y1 + height; @@ -605,7 +612,7 @@ void wxDC::DoDrawPoint(wxCoord x, wxCoord y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + COLORREF color = 0x00ffffff; if (m_pen.Ok()) { @@ -622,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 @@ -659,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) { @@ -690,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; @@ -731,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 @@ -771,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); @@ -789,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; @@ -836,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__ @@ -854,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 ) { @@ -889,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); } @@ -931,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); @@ -945,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 @@ -961,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()); @@ -997,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 @@ -1065,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; } @@ -1087,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; } @@ -1096,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; @@ -1104,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) @@ -1144,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) @@ -1178,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) @@ -1229,7 +1253,7 @@ void wxDC::SetBackground(const wxBrush& brush) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_backgroundBrush = brush; if (!m_backgroundBrush.Ok()) @@ -1274,7 +1298,7 @@ void wxDC::SetBackgroundMode(int mode) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_backgroundMode = mode; // SetBackgroundColour now only refers to text background @@ -1294,7 +1318,7 @@ void wxDC::SetLogicalFunction(int function) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_logicalFunction = function; SetRop(m_hDC); @@ -1361,7 +1385,7 @@ wxCoord wxDC::GetCharHeight() const #ifdef __WXMICROWIN__ if (!GetHDC()) return 0; #endif - + TEXTMETRIC lpTextMetric; GetTextMetrics(GetHdc(), &lpTextMetric); @@ -1374,7 +1398,7 @@ wxCoord wxDC::GetCharWidth() const #ifdef __WXMICROWIN__ if (!GetHDC()) return 0; #endif - + TEXTMETRIC lpTextMetric; GetTextMetrics(GetHdc(), &lpTextMetric); @@ -1396,7 +1420,7 @@ void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y, return; } #endif - + HFONT hfontOld; if ( font ) { @@ -1431,7 +1455,7 @@ void wxDC::SetMapMode(int mode) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_mappingMode = mode; int pixel_width = 0; @@ -1503,7 +1527,7 @@ void wxDC::SetUserScale(double x, double y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_userScaleX = x; m_userScaleY = y; @@ -1515,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; @@ -1527,7 +1551,7 @@ void wxDC::SetSystemScale(double x, double y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_scaleX = x; m_scaleY = y; @@ -1539,7 +1563,7 @@ void wxDC::SetLogicalOrigin(wxCoord x, wxCoord y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_logicalOriginX = x; m_logicalOriginY = y; @@ -1551,7 +1575,7 @@ void wxDC::SetDeviceOrigin(wxCoord x, wxCoord y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_deviceOriginX = x; m_deviceOriginY = y; @@ -1619,7 +1643,7 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, #ifdef __WXMICROWIN__ if (!GetHDC()) return FALSE; #endif - + wxMask *mask = NULL; if ( useMask ) { @@ -1722,9 +1746,9 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, 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); -#endif // wxUSE_DC_CACHEING/!wxUSE_DC_CACHEING // copy dest to buffer if ( !::BitBlt(dc_buffer, 0, 0, (int)width, (int)height, @@ -1803,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); } @@ -1813,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); } @@ -1823,7 +1847,7 @@ wxSize wxDC::GetPPI() const #ifdef __WXMICROWIN__ if (!GetHDC()) return wxSize(); #endif - + int x = ::GetDeviceCaps(GetHdc(), LOGPIXELSX); int y = ::GetDeviceCaps(GetHdc(), LOGPIXELSY); @@ -1836,7 +1860,7 @@ void wxDC::SetLogicalScale(double x, double y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_logicalScaleX = x; m_logicalScaleY = y; } @@ -1849,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;