X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fd3f686c274a264e89ea97505350a82c1134f307..0a240683ed2ed0ad7efe733d451dd36740607605:/src/msw/dc.cpp diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index 5b4e8fddcd..73f3390952 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -26,6 +26,8 @@ #include "wx/utils.h" #include "wx/dialog.h" #include "wx/app.h" +#include "wx/bitmap.h" +#include "wx/dcmemory.h" #endif #include "wx/dcprint.h" @@ -181,6 +183,26 @@ void wxDC::SetClippingRegion(long cx, long cy, long cw, long ch) DoClipping((WXHDC) m_hDC); } +void wxDC::SetClippingRegion(const wxRegion& region) +{ + if (!region.GetHRGN()) + return; + + wxRect box = region.GetBox(); + + m_clipping = TRUE; + m_clipX1 = box.x; + m_clipY1 = box.y; + m_clipX2 = box.x + box.width; + m_clipY2 = box.y + box.height; + +#ifdef __WIN16__ + SelectClipRgn((HDC) m_hDC, (HRGN) region.GetHRGN()); +#else + ExtSelectClipRgn((HDC) m_hDC, (HRGN) region.GetHRGN(), RGN_AND); +#endif +} + void wxDC::DoClipping(WXHDC dc) { if (m_clipping && dc) @@ -194,11 +216,14 @@ void wxDC::DestroyClippingRegion(void) { if (m_clipping && m_hDC) { + // TODO: this should restore the previous clipping region, + // so that OnPaint processing works correctly, and the update clipping region + // doesn't get destroyed after the first DestroyClippingRegion. HRGN rgn = CreateRectRgn(0, 0, 32000, 32000); SelectClipRgn((HDC) m_hDC, rgn); DeleteObject(rgn); - } - m_clipping = FALSE; + } + m_clipping = FALSE; } bool wxDC::CanDrawBitmap(void) const @@ -230,7 +255,7 @@ void wxDC::SetPalette(const wxPalette& palette) m_oldPalette = 0; } - m_palette = m_palette; + m_palette = palette; if (!m_palette.Ok()) { @@ -355,7 +380,7 @@ void wxDC::DrawArc(long x1,long y1,long x2,long y2, long xc, long yc) double radius = (double)sqrt(dx*dx+dy*dy) ;; if (x1==x2 && x2==y2) { - DrawEllipse(xc,yc,(double)(radius*2.0),(double)(radius*2)) ; + DrawEllipse(xc,yc,(long)(radius*2.0),(long)(radius*2.0)) ; return ; } @@ -580,11 +605,56 @@ void wxDC::DrawEllipticArc(long x,long y,long w,long h,double sa,double ea) void wxDC::DrawIcon(const wxIcon& icon, long x, long y) { +#if defined(__WIN32__) && !defined(__SC__) && !defined(__TWIN32__) + ::DrawIconEx((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), (HICON) icon.GetHICON(), + icon.GetWidth(), icon.GetHeight(), 0, 0, DI_NORMAL); +#else ::DrawIcon((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), (HICON) icon.GetHICON()); +#endif + CalcBoundingBox(x, y); CalcBoundingBox(x+icon.GetWidth(), y+icon.GetHeight()); } +void wxDC::DrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask ) +{ + if (!bmp.Ok()) + return; + + // If we're not drawing transparently, and not drawing to a printer, + // optimize this function to use Windows functions. + if (!useMask && !IsKindOf(CLASSINFO(wxPrinterDC))) + { + HDC cdc = (HDC)m_hDC; + HDC memdc = ::CreateCompatibleDC( cdc ); + HBITMAP hbitmap = (HBITMAP) bmp.GetHBITMAP( ); + ::SelectObject( memdc, hbitmap ); + ::BitBlt( cdc, x, y, bmp.GetWidth(), bmp.GetHeight(), memdc, 0, 0, SRCCOPY); + ::SelectObject( memdc, 0 ); + ::DeleteDC( memdc ); + } + else + { + // Rather than reproduce wxDC::Blit, let's do it at the wxWin API level + wxMemoryDC memDC; + memDC.SelectObject(bmp); + + /* Not sure if we need this. The mask should leave the + * masked areas as per the original background of this DC. + */ +/* + // There might be transparent areas, so make these + // the same colour as this DC + memDC.SetBackground(* GetBackground()); + memDC.Clear(); +*/ + + Blit(x, y, bmp.GetWidth(), bmp.GetHeight(), & memDC, 0, 0, wxCOPY, useMask); + + memDC.SelectObject(wxNullBitmap); + } +} + void wxDC::SetFont(const wxFont& the_font) { // Set the old object temporarily, in case the assignment deletes an object @@ -607,7 +677,7 @@ void wxDC::SetFont(const wxFont& the_font) if (m_font.Ok() && m_font.GetResourceHandle()) { HFONT f = (HFONT) ::SelectObject((HDC) m_hDC, (HFONT) m_font.GetResourceHandle()); - if (f == NULL) + if (f == (HFONT) NULL) { wxDebugMsg("::SelectObject failed in wxDC::SetFont."); } @@ -824,16 +894,23 @@ bool wxDC::StartDoc(const wxString& message) #else #ifdef UNICODE ::StartDocW((HDC) m_hDC, &docinfo); +#else +#ifdef __TWIN32__ + ::StartDoc((HDC) m_hDC, &docinfo); #else ::StartDocA((HDC) m_hDC, &docinfo); #endif #endif +#endif +#ifndef __WIN16__ if (ret <= 0) { DWORD lastError = GetLastError(); wxDebugMsg("wxDC::StartDoc failed with error: %d\n", lastError); } +#endif + return (ret > 0); } @@ -1237,7 +1314,7 @@ bool wxDC::Blit(long xdest, long ydest, long width, long height, { if (IsKindOf(CLASSINFO(wxPrinterDC))) { - // If we are printing source colours are screen colours + // If we are printing, source colours are screen colours // not printer colours and so we need copy the bitmap // pixel by pixel. HDC dc_src = (HDC) source->m_hDC; @@ -1607,7 +1684,7 @@ static bool wx_spline_add_point(double x, double y) static void wx_spline_draw_point_array(wxDC *dc) { - dc->DrawLines(&wx_spline_point_list, (double)0.0, (double)0.0); + dc->DrawLines(&wx_spline_point_list, 0, 0); wxNode *node = wx_spline_point_list.First(); while (node) {