+ // +1 below makes the ellipse more similar to other platforms.
+ // In particular, DoDrawEllipse(x,y,1,1) should draw one point.
+ wxCoord x2 = x + width + 1;
+ wxCoord y2 = y + height + 1;
+
+ // Problem: Windows GDI Ellipse() with x2-x == y2-y == 3 and transparent
+ // pen doesn't draw anything. Should we provide a workaround?
+
+ ::Ellipse(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2));
+
+ CalcBoundingBox(x, y);
+ CalcBoundingBox(x2, y2);
+}
+
+#if wxUSE_SPLINES && !defined(__WXWINCE__)
+void wxMSWDCImpl::DoDrawSpline(const wxPointList *points)
+{
+ // quadratic b-spline to cubic bezier spline conversion
+ //
+ // quadratic spline with control points P0,P1,P2
+ // P(s) = P0*(1-s)^2 + P1*2*(1-s)*s + P2*s^2
+ //
+ // bezier spline with control points B0,B1,B2,B3
+ // B(s) = B0*(1-s)^3 + B1*3*(1-s)^2*s + B2*3*(1-s)*s^2 + B3*s^3
+ //
+ // control points of bezier spline calculated from b-spline
+ // B0 = P0
+ // B1 = (2*P1 + P0)/3
+ // B2 = (2*P1 + P2)/3
+ // B3 = P2
+
+ WXMICROWIN_CHECK_HDC
+
+ wxASSERT_MSG( points, wxT("NULL pointer to spline points?") );
+
+ const size_t n_points = points->GetCount();
+ wxASSERT_MSG( n_points > 2 , wxT("incomplete list of spline points?") );
+
+ const size_t n_bezier_points = n_points * 3 + 1;
+ POINT *lppt = (POINT *)malloc(n_bezier_points*sizeof(POINT));
+ size_t bezier_pos = 0;
+ wxCoord x1, y1, x2, y2, cx1, cy1, cx4, cy4;
+
+ wxPointList::compatibility_iterator node = points->GetFirst();
+ wxPoint *p = node->GetData();
+ lppt[ bezier_pos ].x = x1 = p->x;
+ lppt[ bezier_pos ].y = y1 = p->y;
+ bezier_pos++;
+ lppt[ bezier_pos ] = lppt[ bezier_pos-1 ];
+ bezier_pos++;
+
+ node = node->GetNext();
+ p = node->GetData();
+
+ x2 = p->x;
+ y2 = p->y;
+ cx1 = ( x1 + x2 ) / 2;
+ cy1 = ( y1 + y2 ) / 2;
+ lppt[ bezier_pos ].x = XLOG2DEV(cx1);
+ lppt[ bezier_pos ].y = YLOG2DEV(cy1);
+ bezier_pos++;
+ lppt[ bezier_pos ] = lppt[ bezier_pos-1 ];
+ bezier_pos++;
+
+#if !wxUSE_STD_CONTAINERS
+ while ((node = node->GetNext()) != NULL)
+#else
+ while ((node = node->GetNext()))
+#endif // !wxUSE_STD_CONTAINERS
+ {
+ p = (wxPoint *)node->GetData();
+ x1 = x2;
+ y1 = y2;
+ x2 = p->x;
+ y2 = p->y;
+ cx4 = (x1 + x2) / 2;
+ cy4 = (y1 + y2) / 2;
+ // B0 is B3 of previous segment
+ // B1:
+ lppt[ bezier_pos ].x = XLOG2DEV((x1*2+cx1)/3);
+ lppt[ bezier_pos ].y = YLOG2DEV((y1*2+cy1)/3);
+ bezier_pos++;
+ // B2:
+ lppt[ bezier_pos ].x = XLOG2DEV((x1*2+cx4)/3);
+ lppt[ bezier_pos ].y = YLOG2DEV((y1*2+cy4)/3);
+ bezier_pos++;
+ // B3:
+ lppt[ bezier_pos ].x = XLOG2DEV(cx4);
+ lppt[ bezier_pos ].y = YLOG2DEV(cy4);
+ bezier_pos++;
+ cx1 = cx4;
+ cy1 = cy4;
+ }
+
+ lppt[ bezier_pos ] = lppt[ bezier_pos-1 ];
+ bezier_pos++;
+ lppt[ bezier_pos ].x = XLOG2DEV(x2);
+ lppt[ bezier_pos ].y = YLOG2DEV(y2);
+ bezier_pos++;
+ lppt[ bezier_pos ] = lppt[ bezier_pos-1 ];
+ bezier_pos++;
+
+ ::PolyBezier( GetHdc(), lppt, bezier_pos );
+
+ free(lppt);
+}
+#endif // wxUSE_SPLINES
+
+// Chris Breeze 20/5/98: first implementation of DrawEllipticArc on Windows
+void wxMSWDCImpl::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)
+{
+#ifdef __WXWINCE__
+ DoDrawEllipticArcRot( x, y, w, h, sa, ea );
+#else
+
+ WXMICROWIN_CHECK_HDC
+
+ wxBrushAttrsSetter cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
+
+ wxCoord x2 = x + w;
+ wxCoord y2 = y + h;
+
+ int rx1 = XLOG2DEV(x+w/2);
+ int ry1 = YLOG2DEV(y+h/2);
+ int rx2 = rx1;
+ int ry2 = ry1;
+
+ sa = DegToRad(sa);
+ ea = DegToRad(ea);
+
+ rx1 += (int)(100.0 * abs(w) * cos(sa));
+ ry1 -= (int)(100.0 * abs(h) * m_signY * sin(sa));
+ rx2 += (int)(100.0 * abs(w) * cos(ea));
+ ry2 -= (int)(100.0 * abs(h) * m_signY * sin(ea));
+
+ // Swap start and end positions if the end angle is less than the start angle.
+ if (ea < sa) {
+ int temp;
+ temp = rx2;
+ rx2 = rx1;
+ rx1 = temp;
+ temp = ry2;
+ ry2 = ry1;
+ ry1 = temp;
+ }
+
+ // draw pie with NULL_PEN first and then outline otherwise a line is
+ // drawn from the start and end points to the centre
+ HPEN hpenOld = (HPEN) ::SelectObject(GetHdc(), (HPEN) ::GetStockObject(NULL_PEN));
+ if (m_signY > 0)
+ {
+ (void)Pie(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2)+1, YLOG2DEV(y2)+1,
+ rx1, ry1, rx2, ry2);
+ }
+ else
+ {
+ (void)Pie(GetHdc(), XLOG2DEV(x), YLOG2DEV(y)-1, XLOG2DEV(x2)+1, YLOG2DEV(y2),
+ rx1, ry1-1, rx2, ry2-1);
+ }
+
+ ::SelectObject(GetHdc(), hpenOld);
+
+ (void)Arc(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2),
+ rx1, ry1, rx2, ry2);
+
+ CalcBoundingBox(x, y);
+ CalcBoundingBox(x2, y2);
+#endif
+}
+
+void wxMSWDCImpl::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
+{
+ WXMICROWIN_CHECK_HDC
+
+ wxCHECK_RET( icon.IsOk(), wxT("invalid icon in DrawIcon") );
+
+#ifdef __WIN32__
+ ::DrawIconEx(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), GetHiconOf(icon), icon.GetWidth(), icon.GetHeight(), 0, NULL, DI_NORMAL);
+#else
+ ::DrawIcon(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), GetHiconOf(icon));
+#endif
+
+ CalcBoundingBox(x, y);
+ CalcBoundingBox(x + icon.GetWidth(), y + icon.GetHeight());
+}
+
+void wxMSWDCImpl::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask )
+{
+ WXMICROWIN_CHECK_HDC
+
+ wxCHECK_RET( bmp.IsOk(), wxT("invalid bitmap in wxMSWDCImpl::DrawBitmap") );
+
+ int width = bmp.GetWidth(),
+ height = bmp.GetHeight();
+
+ HBITMAP hbmpMask = 0;
+
+#if wxUSE_PALETTE
+ HPALETTE oldPal = 0;
+#endif // wxUSE_PALETTE
+
+ if ( bmp.HasAlpha() )
+ {
+ MemoryHDC hdcMem;
+ SelectInHDC select(hdcMem, GetHbitmapOf(bmp));
+
+ if ( AlphaBlt(GetHdc(), x, y, width, height, 0, 0, width, height, hdcMem, bmp) )
+ return;
+ }
+
+ SET_STRETCH_BLT_MODE(GetHdc());
+
+ if ( useMask )
+ {
+ wxMask *mask = bmp.GetMask();
+ if ( mask )
+ hbmpMask = (HBITMAP)mask->GetMaskBitmap();
+
+ if ( !hbmpMask )
+ {
+ // don't give assert here because this would break existing
+ // programs - just silently ignore useMask parameter
+ useMask = false;
+ }
+ }
+ if ( useMask )
+ {
+#ifdef __WIN32__
+ // use MaskBlt() with ROP which doesn't do anything to dst in the mask
+ // points
+ bool ok = false;
+
+#if wxUSE_SYSTEM_OPTIONS
+ // On some systems, MaskBlt succeeds yet is much much slower
+ // than the wxWidgets fall-back implementation. So we need
+ // to be able to switch this on and off at runtime.
+ //
+ // NB: don't query the value of the option every time but do it only
+ // once as otherwise it can have real (and bad) performance
+ // implications (see #11172)
+ static bool
+ s_maskBltAllowed = wxSystemOptions::GetOptionInt("no-maskblt") == 0;
+ if ( s_maskBltAllowed )
+#endif // wxUSE_SYSTEM_OPTIONS
+ {
+ HDC cdc = GetHdc();
+ HDC hdcMem = ::CreateCompatibleDC(GetHdc());
+ HGDIOBJ hOldBitmap = ::SelectObject(hdcMem, GetHbitmapOf(bmp));
+#if wxUSE_PALETTE
+ wxPalette *pal = bmp.GetPalette();
+ if ( pal && ::GetDeviceCaps(cdc,BITSPIXEL) <= 8 )
+ {
+ oldPal = ::SelectPalette(hdcMem, GetHpaletteOf(*pal), FALSE);
+ ::RealizePalette(hdcMem);
+ }
+#endif // wxUSE_PALETTE
+
+ ok = ::MaskBlt(cdc, x, y, width, height,
+ hdcMem, 0, 0,
+ hbmpMask, 0, 0,
+ MAKEROP4(SRCCOPY, DSTCOPY)) != 0;
+
+#if wxUSE_PALETTE
+ if (oldPal)
+ ::SelectPalette(hdcMem, oldPal, FALSE);
+#endif // wxUSE_PALETTE
+
+ ::SelectObject(hdcMem, hOldBitmap);
+ ::DeleteDC(hdcMem);
+ }
+
+ if ( !ok )
+#endif // Win32
+ {
+ // Rather than reproduce wxMSWDCImpl::Blit, let's do it at the wxWin API
+ // level
+ wxMemoryDC memDC;
+
+ memDC.SelectObjectAsSource(bmp);
+
+ GetOwner()->Blit(x, y, width, height, &memDC, 0, 0, wxCOPY, useMask);
+
+ memDC.SelectObject(wxNullBitmap);
+ }
+ }
+ else // no mask, just use BitBlt()
+ {
+ HDC cdc = GetHdc();
+ HDC memdc = ::CreateCompatibleDC( cdc );
+ HBITMAP hbitmap = (HBITMAP) bmp.GetHBITMAP( );
+
+ wxASSERT_MSG( hbitmap, wxT("bitmap is ok but HBITMAP is NULL?") );
+
+ wxTextColoursChanger textCol(GetHdc(), *this);
+
+#if wxUSE_PALETTE
+ wxPalette *pal = bmp.GetPalette();
+ if ( pal && ::GetDeviceCaps(cdc,BITSPIXEL) <= 8 )
+ {
+ oldPal = ::SelectPalette(memdc, GetHpaletteOf(*pal), FALSE);
+ ::RealizePalette(memdc);
+ }
+#endif // wxUSE_PALETTE
+
+ HGDIOBJ hOldBitmap = ::SelectObject( memdc, hbitmap );
+ ::BitBlt( cdc, x, y, width, height, memdc, 0, 0, SRCCOPY);
+
+#if wxUSE_PALETTE
+ if (oldPal)
+ ::SelectPalette(memdc, oldPal, FALSE);
+#endif // wxUSE_PALETTE
+
+ ::SelectObject( memdc, hOldBitmap );
+ ::DeleteDC( memdc );
+ }
+}
+
+void wxMSWDCImpl::DoDrawText(const wxString& text, wxCoord x, wxCoord y)
+{
+ // For compatibility with other ports (notably wxGTK) and because it's
+ // genuinely useful, we allow passing multiline strings to DrawText().
+ // However there is no native MSW function to draw them directly so we
+ // instead reuse the generic DrawLabel() method to render them. Of course,
+ // DrawLabel() itself will call back to us but with single line strings
+ // only so there won't be any infinite recursion here.
+ if ( text.find('\n') != wxString::npos )
+ {
+ GetOwner()->DrawLabel(text, wxRect(x, y, 0, 0));
+ return;
+ }
+
+ WXMICROWIN_CHECK_HDC
+
+ DrawAnyText(text, x, y);
+
+ // update the bounding box
+ CalcBoundingBox(x, y);
+
+ wxCoord w, h;
+ GetOwner()->GetTextExtent(text, &w, &h);
+ CalcBoundingBox(x + w, y + h);
+}
+
+void wxMSWDCImpl::DrawAnyText(const wxString& text, wxCoord x, wxCoord y)
+{
+ WXMICROWIN_CHECK_HDC
+
+ // prepare for drawing the text
+ wxTextColoursChanger textCol(GetHdc(), *this);
+
+ wxBkModeChanger bkMode(GetHdc(), m_backgroundMode);
+
+ if ( ::ExtTextOut(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), 0, NULL,
+ text.c_str(), text.length(), NULL) == 0 )
+ {
+ wxLogLastError(wxT("TextOut"));
+ }
+}
+
+void wxMSWDCImpl::DoDrawRotatedText(const wxString& text,
+ wxCoord x, wxCoord y,
+ double angle)
+{
+ WXMICROWIN_CHECK_HDC
+
+ // 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
+ // font for drawing rotated fonts unfortunately)
+ if ( (angle == 0.0) && m_font.IsOk() )
+ {
+ DoDrawText(text, x, y);
+ }
+#ifndef __WXMICROWIN__
+ else
+ {
+ // 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.IsOk() ? m_font : *wxSWISS_FONT;
+ HFONT hfont = (HFONT)font.GetResourceHandle();
+ LOGFONT lf;
+ if ( ::GetObject(hfont, sizeof(lf), &lf) == 0 )
+ {
+ wxLogLastError(wxT("GetObject(hfont)"));
+ }
+
+ // GDI wants the angle in tenth of degree
+ long angle10 = (long)(angle * 10);
+ lf.lfEscapement = angle10;
+ lf. lfOrientation = angle10;
+
+ hfont = ::CreateFontIndirect(&lf);
+ if ( !hfont )
+ {
+ wxLogLastError(wxT("CreateFont"));
+ }
+ else
+ {
+ HFONT hfontOld = (HFONT)::SelectObject(GetHdc(), hfont);
+
+ DrawAnyText(text, x, y);
+
+ (void)::SelectObject(GetHdc(), hfontOld);
+ (void)::DeleteObject(hfont);
+ }
+
+ // call the bounding box by adding all four vertices of the rectangle
+ // containing the text to it (simpler and probably not slower than
+ // determining which of them is really topmost/leftmost/...)
+ wxCoord w, h;
+ GetOwner()->GetTextExtent(text, &w, &h);
+
+ double rad = DegToRad(angle);
+
+ // "upper left" and "upper right"
+ CalcBoundingBox(x, y);
+ CalcBoundingBox(x + wxCoord(w*cos(rad)), y - wxCoord(w*sin(rad)));
+
+ // "bottom left" and "bottom right"
+ x += (wxCoord)(h*sin(rad));
+ y += (wxCoord)(h*cos(rad));
+ CalcBoundingBox(x, y);
+ CalcBoundingBox(x + wxCoord(w*cos(rad)), y - wxCoord(w*sin(rad)));
+ }
+#endif
+}
+
+// ---------------------------------------------------------------------------
+// set GDI objects
+// ---------------------------------------------------------------------------
+
+#if wxUSE_PALETTE
+
+void wxMSWDCImpl::DoSelectPalette(bool realize)
+{
+ WXMICROWIN_CHECK_HDC
+
+ // 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, FALSE);
+ m_oldPalette = 0;
+ }
+
+ if ( m_palette.IsOk() )
+ {
+ HPALETTE oldPal = ::SelectPalette(GetHdc(),
+ GetHpaletteOf(m_palette),
+ false);
+ if (!m_oldPalette)
+ m_oldPalette = (WXHPALETTE) oldPal;
+
+ if (realize)
+ ::RealizePalette(GetHdc());
+ }
+}
+
+void wxMSWDCImpl::SetPalette(const wxPalette& palette)
+{
+ if ( palette.IsOk() )
+ {
+ m_palette = palette;
+ DoSelectPalette(true);
+ }
+}
+
+void wxMSWDCImpl::InitializePalette()