]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/dc.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
21 #pragma implementation "dc.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/window.h"
35 #include "wx/dialog.h"
37 #include "wx/bitmap.h"
38 #include "wx/dcmemory.h"
43 #include "wx/dcprint.h"
48 #include "wx/msw/private.h" // needs to be before #include <commdlg.h>
50 #if wxUSE_COMMON_DIALOGS
58 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxDCBase
)
60 // ---------------------------------------------------------------------------
62 // ---------------------------------------------------------------------------
64 static const int VIEWPORT_EXTENT
= 1000;
66 static const int MM_POINTS
= 9;
67 static const int MM_METRIC
= 10;
69 // usually this is defined in math.h
71 static const double M_PI
= 3.14159265358979323846;
74 // ROPs which don't have standard names (see "Ternary Raster Operations" in the
75 // MSDN docs for how this and other numbers in wxDC::Blit() are obtained)
76 #define DSTCOPY 0x00AA0029 // a.k.a. NOP operation
78 // ---------------------------------------------------------------------------
80 // ---------------------------------------------------------------------------
82 // convert degrees to radians
83 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 // instead of duplicating the same code which sets and then restores text
90 // colours in each wxDC method working with wxSTIPPLE_MASK_OPAQUE brushes,
91 // encapsulate this in a small helper class
93 // wxColourChanger: changes the text colours in the ctor if required and
94 // restores them in the dtor
98 wxColourChanger(wxDC
& dc
);
104 COLORREF m_colFgOld
, m_colBgOld
;
109 // ===========================================================================
111 // ===========================================================================
113 // ----------------------------------------------------------------------------
115 // ----------------------------------------------------------------------------
117 wxColourChanger::wxColourChanger(wxDC
& dc
) : m_dc(dc
)
119 if ( dc
.GetBrush().GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
121 HDC hdc
= GetHdcOf(dc
);
122 m_colFgOld
= ::GetTextColor(hdc
);
123 m_colBgOld
= ::GetBkColor(hdc
);
125 // note that Windows convention is opposite to wxWindows one, this is
126 // why text colour becomes the background one and vice versa
127 const wxColour
& colFg
= dc
.GetTextForeground();
130 ::SetBkColor(hdc
, colFg
.GetPixel());
133 const wxColour
& colBg
= dc
.GetTextBackground();
136 ::SetTextColor(hdc
, colBg
.GetPixel());
140 dc
.GetBackgroundMode() == wxTRANSPARENT
? TRANSPARENT
143 // flag which telsl us to undo changes in the dtor
148 // nothing done, nothing to undo
153 wxColourChanger::~wxColourChanger()
157 // restore the colours we changed
158 HDC hdc
= GetHdcOf(m_dc
);
160 ::SetBkMode(hdc
, TRANSPARENT
);
161 ::SetTextColor(hdc
, m_colFgOld
);
162 ::SetBkColor(hdc
, m_colBgOld
);
166 // ---------------------------------------------------------------------------
168 // ---------------------------------------------------------------------------
170 // Default constructor
184 m_windowExtX
= VIEWPORT_EXTENT
;
185 m_windowExtY
= VIEWPORT_EXTENT
;
193 SelectOldObjects(m_hDC
);
195 // if we own the HDC, we delete it, otherwise we just release it
199 ::DeleteDC(GetHdc());
201 else // we don't own our HDC
205 ::ReleaseDC(GetHwndOf(m_canvas
), GetHdc());
209 // Must have been a wxScreenDC
210 ::ReleaseDC((HWND
) NULL
, GetHdc());
216 // This will select current objects out of the DC,
217 // which is what you have to do before deleting the
219 void wxDC::SelectOldObjects(WXHDC dc
)
225 ::SelectObject((HDC
) dc
, (HBITMAP
) m_oldBitmap
);
226 if (m_selectedBitmap
.Ok())
228 m_selectedBitmap
.SetSelectedInto(NULL
);
234 ::SelectObject((HDC
) dc
, (HPEN
) m_oldPen
);
239 ::SelectObject((HDC
) dc
, (HBRUSH
) m_oldBrush
);
244 ::SelectObject((HDC
) dc
, (HFONT
) m_oldFont
);
249 ::SelectPalette((HDC
) dc
, (HPALETTE
) m_oldPalette
, TRUE
);
254 m_brush
= wxNullBrush
;
256 m_palette
= wxNullPalette
;
258 m_backgroundBrush
= wxNullBrush
;
259 m_selectedBitmap
= wxNullBitmap
;
262 // ---------------------------------------------------------------------------
264 // ---------------------------------------------------------------------------
266 #define DO_SET_CLIPPING_BOX() \
270 GetClipBox(GetHdc(), &rect); \
272 m_clipX1 = (wxCoord) XDEV2LOG(rect.left); \
273 m_clipY1 = (wxCoord) YDEV2LOG(rect.top); \
274 m_clipX2 = (wxCoord) XDEV2LOG(rect.right); \
275 m_clipY2 = (wxCoord) YDEV2LOG(rect.bottom); \
278 void wxDC::DoSetClippingRegion(wxCoord cx
, wxCoord cy
, wxCoord cw
, wxCoord ch
)
282 HRGN hrgn
= ::CreateRectRgn(XLOG2DEV(cx
), YLOG2DEV(cy
),
283 XLOG2DEV(cx
+ cw
), YLOG2DEV(cy
+ ch
));
286 wxLogLastError(_T("CreateRectRgn"));
290 if ( ::SelectClipRgn(GetHdc(), hrgn
) == ERROR
)
292 wxLogLastError(_T("SelectClipRgn"));
295 DO_SET_CLIPPING_BOX()
299 void wxDC::DoSetClippingRegionAsRegion(const wxRegion
& region
)
301 wxCHECK_RET( region
.GetHRGN(), wxT("invalid clipping region") );
306 SelectClipRgn(GetHdc(), (HRGN
) region
.GetHRGN());
308 ExtSelectClipRgn(GetHdc(), (HRGN
) region
.GetHRGN(), RGN_AND
);
311 DO_SET_CLIPPING_BOX()
314 void wxDC::DestroyClippingRegion()
316 if (m_clipping
&& m_hDC
)
318 // TODO: this should restore the previous clipping region,
319 // so that OnPaint processing works correctly, and the update clipping region
320 // doesn't get destroyed after the first DestroyClippingRegion.
321 HRGN rgn
= CreateRectRgn(0, 0, 32000, 32000);
322 SelectClipRgn(GetHdc(), rgn
);
328 // ---------------------------------------------------------------------------
329 // query capabilities
330 // ---------------------------------------------------------------------------
332 bool wxDC::CanDrawBitmap() const
337 bool wxDC::CanGetTextExtent() const
339 // What sort of display is it?
340 int technology
= ::GetDeviceCaps(GetHdc(), TECHNOLOGY
);
342 return (technology
== DT_RASDISPLAY
) || (technology
== DT_RASPRINTER
);
345 int wxDC::GetDepth() const
347 return (int)::GetDeviceCaps(GetHdc(), BITSPIXEL
);
350 // ---------------------------------------------------------------------------
352 // ---------------------------------------------------------------------------
359 GetClientRect((HWND
) m_canvas
->GetHWND(), &rect
);
363 // No, I think we should simply ignore this if printing on e.g.
365 // wxCHECK_RET( m_selectedBitmap.Ok(), wxT("this DC can't be cleared") );
366 if (!m_selectedBitmap
.Ok())
369 rect
.left
= 0; rect
.top
= 0;
370 rect
.right
= m_selectedBitmap
.GetWidth();
371 rect
.bottom
= m_selectedBitmap
.GetHeight();
374 (void) ::SetMapMode(GetHdc(), MM_TEXT
);
376 DWORD colour
= GetBkColor(GetHdc());
377 HBRUSH brush
= CreateSolidBrush(colour
);
378 FillRect(GetHdc(), &rect
, brush
);
381 ::SetMapMode(GetHdc(), MM_ANISOTROPIC
);
382 ::SetViewportExtEx(GetHdc(), VIEWPORT_EXTENT
, VIEWPORT_EXTENT
, NULL
);
383 ::SetWindowExtEx(GetHdc(), m_windowExtX
, m_windowExtY
, NULL
);
384 ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX
, (int)m_deviceOriginY
, NULL
);
385 ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX
, (int)m_logicalOriginY
, NULL
);
388 void wxDC::DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
, int style
)
390 if ( !::ExtFloodFill(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
),
392 style
== wxFLOOD_SURFACE
? FLOODFILLSURFACE
395 // quoting from the MSDN docs:
397 // Following are some of the reasons this function might fail:
399 // * The filling could not be completed.
400 // * The specified point has the boundary color specified by the
401 // crColor parameter (if FLOODFILLBORDER was requested).
402 // * The specified point does not have the color specified by
403 // crColor (if FLOODFILLSURFACE was requested)
404 // * The point is outside the clipping region that is, it is not
405 // visible on the device.
407 wxLogLastError(wxT("ExtFloodFill"));
410 CalcBoundingBox(x
, y
);
413 bool wxDC::DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const
415 wxCHECK_MSG( col
, FALSE
, _T("NULL colour parameter in wxDC::GetPixel") );
417 // get the color of the pixel
418 COLORREF pixelcolor
= ::GetPixel(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
));
420 wxRGBToColour(*col
, pixelcolor
);
425 void wxDC::DoCrossHair(wxCoord x
, wxCoord y
)
427 wxCoord x1
= x
-VIEWPORT_EXTENT
;
428 wxCoord y1
= y
-VIEWPORT_EXTENT
;
429 wxCoord x2
= x
+VIEWPORT_EXTENT
;
430 wxCoord y2
= y
+VIEWPORT_EXTENT
;
432 (void)MoveToEx(GetHdc(), XLOG2DEV(x1
), YLOG2DEV(y
), NULL
);
433 (void)LineTo(GetHdc(), XLOG2DEV(x2
), YLOG2DEV(y
));
435 (void)MoveToEx(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y1
), NULL
);
436 (void)LineTo(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y2
));
438 CalcBoundingBox(x1
, y1
);
439 CalcBoundingBox(x2
, y2
);
442 void wxDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
444 (void)MoveToEx(GetHdc(), XLOG2DEV(x1
), YLOG2DEV(y1
), NULL
);
445 (void)LineTo(GetHdc(), XLOG2DEV(x2
), YLOG2DEV(y2
));
447 // Normalization: Windows doesn't draw the last point of the line.
448 // But apparently neither does GTK+, so we take it out again.
449 // (void)LineTo(GetHdc(), XLOG2DEV(x2) + 1, YLOG2DEV(y2));
451 CalcBoundingBox(x1
, y1
);
452 CalcBoundingBox(x2
, y2
);
455 // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
456 // and ending at (x2, y2)
457 void wxDC::DoDrawArc(wxCoord x1
, wxCoord y1
,
458 wxCoord x2
, wxCoord y2
,
459 wxCoord xc
, wxCoord yc
)
461 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
465 double radius
= (double)sqrt(dx
*dx
+dy
*dy
);
466 wxCoord r
= (wxCoord
)radius
;
468 // treat the special case of full circle separately
469 if ( x1
== x2
&& y1
== y2
)
471 DrawEllipse(xc
- r
, yc
- r
, 2*r
, 2*r
);
475 wxCoord xx1
= XLOG2DEV(x1
);
476 wxCoord yy1
= YLOG2DEV(y1
);
477 wxCoord xx2
= XLOG2DEV(x2
);
478 wxCoord yy2
= YLOG2DEV(y2
);
479 wxCoord xxc
= XLOG2DEV(xc
);
480 wxCoord yyc
= YLOG2DEV(yc
);
481 wxCoord ray
= (wxCoord
) sqrt(double((xxc
-xx1
)*(xxc
-xx1
)+(yyc
-yy1
)*(yyc
-yy1
)));
483 wxCoord xxx1
= (wxCoord
) (xxc
-ray
);
484 wxCoord yyy1
= (wxCoord
) (yyc
-ray
);
485 wxCoord xxx2
= (wxCoord
) (xxc
+ray
);
486 wxCoord yyy2
= (wxCoord
) (yyc
+ray
);
488 if ( m_brush
.Ok() && m_brush
.GetStyle() != wxTRANSPARENT
)
490 // Have to add 1 to bottom-right corner of rectangle
491 // to make semi-circles look right (crooked line otherwise).
492 // Unfortunately this is not a reliable method, depends
493 // on the size of shape.
494 // TODO: figure out why this happens!
495 Pie(GetHdc(),xxx1
,yyy1
,xxx2
+1,yyy2
+1, xx1
,yy1
,xx2
,yy2
);
499 Arc(GetHdc(),xxx1
,yyy1
,xxx2
,yyy2
, xx1
,yy1
,xx2
,yy2
);
502 CalcBoundingBox(xc
- r
, yc
- r
);
503 CalcBoundingBox(xc
+ r
, yc
+ r
);
506 void wxDC::DoDrawCheckMark(wxCoord x1
, wxCoord y1
,
507 wxCoord width
, wxCoord height
)
509 wxCoord x2
= x1
+ width
,
512 #if defined(__WIN32__) && !defined(__SC__)
519 DrawFrameControl(GetHdc(), &rect
, DFC_MENU
, DFCS_MENUCHECK
);
521 // In WIN16, draw a cross
522 HPEN blackPen
= ::CreatePen(PS_SOLID
, 1, RGB(0, 0, 0));
523 HPEN whiteBrush
= (HPEN
)::GetStockObject(WHITE_BRUSH
);
524 HPEN hPenOld
= (HPEN
)::SelectObject(GetHdc(), blackPen
);
525 HPEN hBrushOld
= (HPEN
)::SelectObject(GetHdc(), whiteBrush
);
526 ::SetROP2(GetHdc(), R2_COPYPEN
);
527 Rectangle(GetHdc(), x1
, y1
, x2
, y2
);
528 MoveTo(GetHdc(), x1
, y1
);
529 LineTo(GetHdc(), x2
, y2
);
530 MoveTo(GetHdc(), x2
, y1
);
531 LineTo(GetHdc(), x1
, y2
);
532 ::SelectObject(GetHdc(), hPenOld
);
533 ::SelectObject(GetHdc(), hBrushOld
);
534 ::DeleteObject(blackPen
);
537 CalcBoundingBox(x1
, y1
);
538 CalcBoundingBox(x2
, y2
);
541 void wxDC::DoDrawPoint(wxCoord x
, wxCoord y
)
543 COLORREF color
= 0x00ffffff;
546 color
= m_pen
.GetColour().GetPixel();
549 SetPixel(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), color
);
551 CalcBoundingBox(x
, y
);
554 void wxDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
,int fillStyle
)
556 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
558 // Do things less efficiently if we have offsets
559 if (xoffset
!= 0 || yoffset
!= 0)
561 POINT
*cpoints
= new POINT
[n
];
563 for (i
= 0; i
< n
; i
++)
565 cpoints
[i
].x
= (int)(points
[i
].x
+ xoffset
);
566 cpoints
[i
].y
= (int)(points
[i
].y
+ yoffset
);
568 CalcBoundingBox(cpoints
[i
].x
, cpoints
[i
].y
);
570 int prev
= SetPolyFillMode(GetHdc(),fillStyle
==wxODDEVEN_RULE
?ALTERNATE
:WINDING
);
571 (void)Polygon(GetHdc(), cpoints
, n
);
572 SetPolyFillMode(GetHdc(),prev
);
578 for (i
= 0; i
< n
; i
++)
579 CalcBoundingBox(points
[i
].x
, points
[i
].y
);
581 int prev
= SetPolyFillMode(GetHdc(),fillStyle
==wxODDEVEN_RULE
?ALTERNATE
:WINDING
);
582 (void)Polygon(GetHdc(), (POINT
*) points
, n
);
583 SetPolyFillMode(GetHdc(),prev
);
587 void wxDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
589 // Do things less efficiently if we have offsets
590 if (xoffset
!= 0 || yoffset
!= 0)
592 POINT
*cpoints
= new POINT
[n
];
594 for (i
= 0; i
< n
; i
++)
596 cpoints
[i
].x
= (int)(points
[i
].x
+ xoffset
);
597 cpoints
[i
].y
= (int)(points
[i
].y
+ yoffset
);
599 CalcBoundingBox(cpoints
[i
].x
, cpoints
[i
].y
);
601 (void)Polyline(GetHdc(), cpoints
, n
);
607 for (i
= 0; i
< n
; i
++)
608 CalcBoundingBox(points
[i
].x
, points
[i
].y
);
610 (void)Polyline(GetHdc(), (POINT
*) points
, n
);
614 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
616 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
618 wxCoord x2
= x
+ width
;
619 wxCoord y2
= y
+ height
;
621 if ((m_logicalFunction
== wxCOPY
) && (m_pen
.GetStyle() == wxTRANSPARENT
))
624 rect
.left
= XLOG2DEV(x
);
625 rect
.top
= YLOG2DEV(y
);
626 rect
.right
= XLOG2DEV(x2
);
627 rect
.bottom
= YLOG2DEV(y2
);
628 (void)FillRect(GetHdc(), &rect
, (HBRUSH
)m_brush
.GetResourceHandle() );
632 // Windows draws the filled rectangles without outline (i.e. drawn with a
633 // transparent pen) one pixel smaller in both directions and we want them
634 // to have the same size regardless of which pen is used - adjust
636 // I wonder if this shouldn´t be done after the LOG2DEV() conversions. RR.
637 if ( m_pen
.GetStyle() == wxTRANSPARENT
)
643 (void)Rectangle(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
));
647 CalcBoundingBox(x
, y
);
648 CalcBoundingBox(x2
, y2
);
651 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
653 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
655 // Now, a negative radius value is interpreted to mean
656 // 'the proportion of the smallest X or Y dimension'
660 double smallest
= 0.0;
665 radius
= (- radius
* smallest
);
668 wxCoord x2
= (x
+width
);
669 wxCoord y2
= (y
+height
);
671 // Windows draws the filled rectangles without outline (i.e. drawn with a
672 // transparent pen) one pixel smaller in both directions and we want them
673 // to have the same size regardless of which pen is used - adjust
674 if ( m_pen
.GetStyle() == wxTRANSPARENT
)
680 (void)RoundRect(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
),
681 YLOG2DEV(y2
), (int) (2*XLOG2DEV(radius
)), (int)( 2*YLOG2DEV(radius
)));
683 CalcBoundingBox(x
, y
);
684 CalcBoundingBox(x2
, y2
);
687 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
689 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
691 wxCoord x2
= (x
+width
);
692 wxCoord y2
= (y
+height
);
694 (void)Ellipse(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
));
696 CalcBoundingBox(x
, y
);
697 CalcBoundingBox(x2
, y2
);
700 // Chris Breeze 20/5/98: first implementation of DrawEllipticArc on Windows
701 void wxDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
703 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
708 int rx1
= XLOG2DEV(x
+w
/2);
709 int ry1
= YLOG2DEV(y
+h
/2);
716 rx1
+= (int)(100.0 * abs(w
) * cos(sa
));
717 ry1
-= (int)(100.0 * abs(h
) * m_signY
* sin(sa
));
718 rx2
+= (int)(100.0 * abs(w
) * cos(ea
));
719 ry2
-= (int)(100.0 * abs(h
) * m_signY
* sin(ea
));
721 // draw pie with NULL_PEN first and then outline otherwise a line is
722 // drawn from the start and end points to the centre
723 HPEN hpenOld
= (HPEN
) ::SelectObject(GetHdc(), (HPEN
) ::GetStockObject(NULL_PEN
));
726 (void)Pie(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
)+1, YLOG2DEV(y2
)+1,
731 (void)Pie(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
)-1, XLOG2DEV(x2
)+1, YLOG2DEV(y2
),
732 rx1
, ry1
-1, rx2
, ry2
-1);
735 ::SelectObject(GetHdc(), hpenOld
);
737 (void)Arc(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
),
740 CalcBoundingBox(x
, y
);
741 CalcBoundingBox(x2
, y2
);
744 void wxDC::DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
)
746 wxCHECK_RET( icon
.Ok(), wxT("invalid icon in DrawIcon") );
749 ::DrawIconEx(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), GetHiconOf(icon
), icon
.GetWidth(), icon
.GetHeight(), 0, NULL
, DI_NORMAL
);
751 ::DrawIcon(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), GetHiconOf(icon
));
754 CalcBoundingBox(x
, y
);
755 CalcBoundingBox(x
+ icon
.GetWidth(), y
+ icon
.GetHeight());
758 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
760 wxCHECK_RET( bmp
.Ok(), _T("invalid bitmap in wxDC::DrawBitmap") );
762 int width
= bmp
.GetWidth(),
763 height
= bmp
.GetHeight();
765 HBITMAP hbmpMask
= 0;
769 wxMask
*mask
= bmp
.GetMask();
771 hbmpMask
= (HBITMAP
)mask
->GetMaskBitmap();
775 // don't give assert here because this would break existing
776 // programs - just silently ignore useMask parameter
784 // use MaskBlt() with ROP which doesn't do anything to dst in the mask
786 // On some systems, MaskBlt succeeds yet is much much slower
787 // than the wxWindows fall-back implementation. So we need
788 // to be able to switch this on and off at runtime.
790 if (wxSystemSettings::GetOptionInt(wxT("no-maskblt")) == 0)
792 HDC hdcMem
= ::CreateCompatibleDC(GetHdc());
793 ::SelectObject(hdcMem
, GetHbitmapOf(bmp
));
795 ok
= ::MaskBlt(GetHdc(), x
, y
, width
, height
,
798 MAKEROP4(SRCCOPY
, DSTCOPY
)) != 0;
805 // Rather than reproduce wxDC::Blit, let's do it at the wxWin API
808 memDC
.SelectObject(bmp
);
810 Blit(x
, y
, width
, height
, &memDC
, 0, 0, wxCOPY
, useMask
);
812 memDC
.SelectObject(wxNullBitmap
);
815 else // no mask, just use BitBlt()
818 HDC memdc
= ::CreateCompatibleDC( cdc
);
819 HBITMAP hbitmap
= (HBITMAP
) bmp
.GetHBITMAP( );
821 wxASSERT_MSG( hbitmap
, wxT("bitmap is ok but HBITMAP is NULL?") );
823 COLORREF old_textground
= ::GetTextColor(GetHdc());
824 COLORREF old_background
= ::GetBkColor(GetHdc());
825 if (m_textForegroundColour
.Ok())
827 ::SetTextColor(GetHdc(), m_textForegroundColour
.GetPixel() );
829 if (m_textBackgroundColour
.Ok())
831 ::SetBkColor(GetHdc(), m_textBackgroundColour
.GetPixel() );
834 ::SelectObject( memdc
, hbitmap
);
835 ::BitBlt( cdc
, x
, y
, width
, height
, memdc
, 0, 0, SRCCOPY
);
838 ::SetTextColor(GetHdc(), old_textground
);
839 ::SetBkColor(GetHdc(), old_background
);
843 void wxDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
845 DrawAnyText(text
, x
, y
);
847 // update the bounding box
848 CalcBoundingBox(x
, y
);
851 GetTextExtent(text
, &w
, &h
);
852 CalcBoundingBox(x
+ w
, y
+ h
);
855 void wxDC::DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
)
857 // prepare for drawing the text
858 if ( m_textForegroundColour
.Ok() )
859 SetTextColor(GetHdc(), m_textForegroundColour
.GetPixel());
861 DWORD old_background
= 0;
862 if ( m_textBackgroundColour
.Ok() )
864 old_background
= SetBkColor(GetHdc(), m_textBackgroundColour
.GetPixel() );
867 SetBkMode(GetHdc(), m_backgroundMode
== wxTRANSPARENT
? TRANSPARENT
870 if ( ::TextOut(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
),
871 text
.c_str(), text
.length()) == 0 )
873 wxLogLastError(wxT("TextOut"));
876 // restore the old parameters (text foreground colour may be left because
877 // it never is set to anything else, but background should remain
878 // transparent even if we just drew an opaque string)
879 if ( m_textBackgroundColour
.Ok() )
880 (void)SetBkColor(GetHdc(), old_background
);
882 SetBkMode(GetHdc(), TRANSPARENT
);
885 void wxDC::DoDrawRotatedText(const wxString
& text
,
886 wxCoord x
, wxCoord y
,
889 // we test that we have some font because otherwise we should still use the
890 // "else" part below to avoid that DrawRotatedText(angle = 180) and
891 // DrawRotatedText(angle = 0) use different fonts (we can't use the default
892 // font for drawing rotated fonts unfortunately)
893 if ( (angle
== 0.0) && m_font
.Ok() )
895 DoDrawText(text
, x
, y
);
899 // NB: don't take DEFAULT_GUI_FONT because it's not TrueType and so
900 // can't have non zero orientation/escapement
901 wxFont font
= m_font
.Ok() ? m_font
: *wxNORMAL_FONT
;
902 HFONT hfont
= (HFONT
)font
.GetResourceHandle();
904 if ( ::GetObject(hfont
, sizeof(lf
), &lf
) == 0 )
906 wxLogLastError(wxT("GetObject(hfont)"));
909 // GDI wants the angle in tenth of degree
910 long angle10
= (long)(angle
* 10);
911 lf
.lfEscapement
= angle10
;
912 lf
. lfOrientation
= angle10
;
914 hfont
= ::CreateFontIndirect(&lf
);
917 wxLogLastError(wxT("CreateFont"));
921 HFONT hfontOld
= (HFONT
)::SelectObject(GetHdc(), hfont
);
923 DrawAnyText(text
, x
, y
);
925 (void)::SelectObject(GetHdc(), hfontOld
);
926 (void)::DeleteObject(hfont
);
929 // call the bounding box by adding all four vertices of the rectangle
930 // containing the text to it (simpler and probably not slower than
931 // determining which of them is really topmost/leftmost/...)
933 GetTextExtent(text
, &w
, &h
);
935 double rad
= DegToRad(angle
);
937 // "upper left" and "upper right"
938 CalcBoundingBox(x
, y
);
939 CalcBoundingBox(x
+ w
*cos(rad
), y
- h
*sin(rad
));
941 // "bottom left" and "bottom right"
942 x
+= (wxCoord
)(h
*sin(rad
));
943 y
+= (wxCoord
)(h
*cos(rad
));
944 CalcBoundingBox(x
, y
);
945 CalcBoundingBox(x
+ h
*sin(rad
), y
+ h
*cos(rad
));
949 // ---------------------------------------------------------------------------
951 // ---------------------------------------------------------------------------
953 void wxDC::SetPalette(const wxPalette
& palette
)
955 // Set the old object temporarily, in case the assignment deletes an object
956 // that's not yet selected out.
959 ::SelectPalette(GetHdc(), (HPALETTE
) m_oldPalette
, TRUE
);
967 // Setting a NULL colourmap is a way of restoring
968 // the original colourmap
971 ::SelectPalette(GetHdc(), (HPALETTE
) m_oldPalette
, TRUE
);
978 if (m_palette
.Ok() && m_palette
.GetHPALETTE())
980 HPALETTE oldPal
= ::SelectPalette(GetHdc(), (HPALETTE
) m_palette
.GetHPALETTE(), TRUE
);
982 m_oldPalette
= (WXHPALETTE
) oldPal
;
984 ::RealizePalette(GetHdc());
988 void wxDC::SetFont(const wxFont
& the_font
)
990 // Set the old object temporarily, in case the assignment deletes an object
991 // that's not yet selected out.
994 ::SelectObject(GetHdc(), (HFONT
) m_oldFont
);
1003 ::SelectObject(GetHdc(), (HFONT
) m_oldFont
);
1007 if (m_font
.Ok() && m_font
.GetResourceHandle())
1009 HFONT f
= (HFONT
) ::SelectObject(GetHdc(), (HFONT
) m_font
.GetResourceHandle());
1010 if (f
== (HFONT
) NULL
)
1012 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
1015 m_oldFont
= (WXHFONT
) f
;
1019 void wxDC::SetPen(const wxPen
& pen
)
1021 // Set the old object temporarily, in case the assignment deletes an object
1022 // that's not yet selected out.
1025 ::SelectObject(GetHdc(), (HPEN
) m_oldPen
);
1034 ::SelectObject(GetHdc(), (HPEN
) m_oldPen
);
1040 if (m_pen
.GetResourceHandle())
1042 HPEN p
= (HPEN
) ::SelectObject(GetHdc(), (HPEN
)m_pen
.GetResourceHandle());
1044 m_oldPen
= (WXHPEN
) p
;
1049 void wxDC::SetBrush(const wxBrush
& brush
)
1051 // Set the old object temporarily, in case the assignment deletes an object
1052 // that's not yet selected out.
1055 ::SelectObject(GetHdc(), (HBRUSH
) m_oldBrush
);
1064 ::SelectObject(GetHdc(), (HBRUSH
) m_oldBrush
);
1070 // to make sure the brush is alligned with the logical coordinates
1071 wxBitmap
*stipple
= m_brush
.GetStipple();
1072 if ( stipple
&& stipple
->Ok() )
1075 ::SetBrushOrgEx(GetHdc(),
1076 m_deviceOriginX
% stipple
->GetWidth(),
1077 m_deviceOriginY
% stipple
->GetHeight(),
1078 NULL
); // don't need previous brush origin
1080 ::SetBrushOrg(GetHdc(),
1081 m_deviceOriginX
% stipple
->GetWidth(),
1082 m_deviceOriginY
% stipple
->GetHeight());
1086 if ( m_brush
.GetResourceHandle() )
1089 b
= (HBRUSH
) ::SelectObject(GetHdc(), (HBRUSH
)m_brush
.GetResourceHandle());
1091 m_oldBrush
= (WXHBRUSH
) b
;
1096 void wxDC::SetBackground(const wxBrush
& brush
)
1098 m_backgroundBrush
= brush
;
1100 if (!m_backgroundBrush
.Ok())
1105 bool customColours
= TRUE
;
1106 // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
1107 // change background colours from the control-panel specified colours.
1108 if (m_canvas
->IsKindOf(CLASSINFO(wxWindow
)) && ((m_canvas
->GetWindowStyleFlag() & wxUSER_COLOURS
) != wxUSER_COLOURS
))
1109 customColours
= FALSE
;
1113 if (m_backgroundBrush
.GetStyle()==wxTRANSPARENT
)
1115 m_canvas
->SetTransparent(TRUE
);
1119 // New behaviour, 10/2/99: setting the background brush of a DC
1120 // doesn't affect the window background colour. However,
1121 // I'm leaving in the transparency setting because it's needed by
1122 // various controls (e.g. wxStaticText) to determine whether to draw
1123 // transparently or not. TODO: maybe this should be a new function
1124 // wxWindow::SetTransparency(). Should that apply to the child itself, or the
1126 // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour());
1127 m_canvas
->SetTransparent(FALSE
);
1131 COLORREF new_color
= m_backgroundBrush
.GetColour().GetPixel();
1133 (void)SetBkColor(GetHdc(), new_color
);
1137 void wxDC::SetBackgroundMode(int mode
)
1139 m_backgroundMode
= mode
;
1141 // SetBackgroundColour now only refers to text background
1142 // and m_backgroundMode is used there
1145 if (m_backgroundMode == wxTRANSPARENT)
1146 ::SetBkMode(GetHdc(), TRANSPARENT);
1148 ::SetBkMode(GetHdc(), OPAQUE);
1149 Last change: AC 29 Jan 101 8:54 pm
1153 void wxDC::SetLogicalFunction(int function
)
1155 m_logicalFunction
= function
;
1160 void wxDC::SetRop(WXHDC dc
)
1162 if ( !dc
|| m_logicalFunction
< 0 )
1167 switch (m_logicalFunction
)
1169 case wxCLEAR
: rop
= R2_BLACK
; break;
1170 case wxXOR
: rop
= R2_XORPEN
; break;
1171 case wxINVERT
: rop
= R2_NOT
; break;
1172 case wxOR_REVERSE
: rop
= R2_MERGEPENNOT
; break;
1173 case wxAND_REVERSE
: rop
= R2_MASKPENNOT
; break;
1174 case wxCOPY
: rop
= R2_COPYPEN
; break;
1175 case wxAND
: rop
= R2_MASKPEN
; break;
1176 case wxAND_INVERT
: rop
= R2_MASKNOTPEN
; break;
1177 case wxNO_OP
: rop
= R2_NOP
; break;
1178 case wxNOR
: rop
= R2_NOTMERGEPEN
; break;
1179 case wxEQUIV
: rop
= R2_NOTXORPEN
; break;
1180 case wxSRC_INVERT
: rop
= R2_NOTCOPYPEN
; break;
1181 case wxOR_INVERT
: rop
= R2_MERGENOTPEN
; break;
1182 case wxNAND
: rop
= R2_NOTMASKPEN
; break;
1183 case wxOR
: rop
= R2_MERGEPEN
; break;
1184 case wxSET
: rop
= R2_WHITE
; break;
1187 wxFAIL_MSG( wxT("unsupported logical function") );
1191 SetROP2(GetHdc(), rop
);
1194 bool wxDC::StartDoc(const wxString
& WXUNUSED(message
))
1196 // We might be previewing, so return TRUE to let it continue.
1204 void wxDC::StartPage()
1208 void wxDC::EndPage()
1212 // ---------------------------------------------------------------------------
1214 // ---------------------------------------------------------------------------
1216 wxCoord
wxDC::GetCharHeight() const
1218 TEXTMETRIC lpTextMetric
;
1220 GetTextMetrics(GetHdc(), &lpTextMetric
);
1222 return YDEV2LOGREL(lpTextMetric
.tmHeight
);
1225 wxCoord
wxDC::GetCharWidth() const
1227 TEXTMETRIC lpTextMetric
;
1229 GetTextMetrics(GetHdc(), &lpTextMetric
);
1231 return XDEV2LOGREL(lpTextMetric
.tmAveCharWidth
);
1234 void wxDC::DoGetTextExtent(const wxString
& string
, wxCoord
*x
, wxCoord
*y
,
1235 wxCoord
*descent
, wxCoord
*externalLeading
,
1241 wxASSERT_MSG( font
->Ok(), _T("invalid font in wxDC::GetTextExtent") );
1243 hfontOld
= (HFONT
)::SelectObject(GetHdc(), GetHfontOf(*font
));
1245 else // don't change the font
1253 GetTextExtentPoint(GetHdc(), string
, string
.length(), &sizeRect
);
1254 GetTextMetrics(GetHdc(), &tm
);
1256 if (x
) *x
= XDEV2LOGREL(sizeRect
.cx
);
1257 if (y
) *y
= YDEV2LOGREL(sizeRect
.cy
);
1258 if (descent
) *descent
= tm
.tmDescent
;
1259 if (externalLeading
) *externalLeading
= tm
.tmExternalLeading
;
1263 ::SelectObject(GetHdc(), hfontOld
);
1267 void wxDC::SetMapMode(int mode
)
1269 m_mappingMode
= mode
;
1271 int pixel_width
= 0;
1272 int pixel_height
= 0;
1276 pixel_width
= GetDeviceCaps(GetHdc(), HORZRES
);
1277 pixel_height
= GetDeviceCaps(GetHdc(), VERTRES
);
1278 mm_width
= GetDeviceCaps(GetHdc(), HORZSIZE
);
1279 mm_height
= GetDeviceCaps(GetHdc(), VERTSIZE
);
1281 if ((pixel_width
== 0) || (pixel_height
== 0) || (mm_width
== 0) || (mm_height
== 0))
1286 double mm2pixelsX
= pixel_width
/mm_width
;
1287 double mm2pixelsY
= pixel_height
/mm_height
;
1293 m_logicalScaleX
= (twips2mm
* mm2pixelsX
);
1294 m_logicalScaleY
= (twips2mm
* mm2pixelsY
);
1299 m_logicalScaleX
= (pt2mm
* mm2pixelsX
);
1300 m_logicalScaleY
= (pt2mm
* mm2pixelsY
);
1305 m_logicalScaleX
= mm2pixelsX
;
1306 m_logicalScaleY
= mm2pixelsY
;
1311 m_logicalScaleX
= (mm2pixelsX
/10.0);
1312 m_logicalScaleY
= (mm2pixelsY
/10.0);
1318 m_logicalScaleX
= 1.0;
1319 m_logicalScaleY
= 1.0;
1324 if (::GetMapMode(GetHdc()) != MM_ANISOTROPIC
)
1325 ::SetMapMode(GetHdc(), MM_ANISOTROPIC
);
1327 SetViewportExtEx(GetHdc(), VIEWPORT_EXTENT
, VIEWPORT_EXTENT
, NULL
);
1328 m_windowExtX
= (int)MS_XDEV2LOGREL(VIEWPORT_EXTENT
);
1329 m_windowExtY
= (int)MS_YDEV2LOGREL(VIEWPORT_EXTENT
);
1330 ::SetWindowExtEx(GetHdc(), m_windowExtX
, m_windowExtY
, NULL
);
1331 ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX
, (int)m_deviceOriginY
, NULL
);
1332 ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX
, (int)m_logicalOriginY
, NULL
);
1335 void wxDC::SetUserScale(double x
, double y
)
1340 SetMapMode(m_mappingMode
);
1343 void wxDC::SetAxisOrientation(bool xLeftRight
, bool yBottomUp
)
1345 m_signX
= xLeftRight
? 1 : -1;
1346 m_signY
= yBottomUp
? -1 : 1;
1348 SetMapMode(m_mappingMode
);
1351 void wxDC::SetSystemScale(double x
, double y
)
1356 SetMapMode(m_mappingMode
);
1359 void wxDC::SetLogicalOrigin(wxCoord x
, wxCoord y
)
1361 m_logicalOriginX
= x
;
1362 m_logicalOriginY
= y
;
1364 ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX
, (int)m_logicalOriginY
, NULL
);
1367 void wxDC::SetDeviceOrigin(wxCoord x
, wxCoord y
)
1369 m_deviceOriginX
= x
;
1370 m_deviceOriginY
= y
;
1372 ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX
, (int)m_deviceOriginY
, NULL
);
1375 // ---------------------------------------------------------------------------
1376 // coordinates transformations
1377 // ---------------------------------------------------------------------------
1379 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
1381 double xRel
= x
- m_deviceOriginX
;
1382 xRel
/= m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
;
1383 return (wxCoord
)(xRel
+ m_logicalOriginX
);
1386 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
1388 return (wxCoord
) ((x
)/(m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
));
1391 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
1393 double yRel
= y
- m_deviceOriginY
;
1394 yRel
/= m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
;
1395 return (wxCoord
)(yRel
+ m_logicalOriginY
);
1398 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
1400 return (wxCoord
) ((y
)/(m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
));
1403 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
1405 return (wxCoord
) ((x
- m_logicalOriginX
)*m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
+ m_deviceOriginX
);
1408 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
1410 return (wxCoord
) (x
*m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
);
1413 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
1415 return (wxCoord
) ((y
- m_logicalOriginY
)*m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
+ m_deviceOriginY
);
1418 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
1420 return (wxCoord
) (y
*m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
);
1423 // ---------------------------------------------------------------------------
1425 // ---------------------------------------------------------------------------
1427 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
,
1428 wxCoord width
, wxCoord height
,
1429 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
1430 int rop
, bool useMask
)
1432 wxMask
*mask
= NULL
;
1435 const wxBitmap
& bmp
= source
->m_selectedBitmap
;
1436 mask
= bmp
.GetMask();
1438 if ( !(bmp
.Ok() && mask
&& mask
->GetMaskBitmap()) )
1440 // don't give assert here because this would break existing
1441 // programs - just silently ignore useMask parameter
1446 COLORREF old_textground
= ::GetTextColor(GetHdc());
1447 COLORREF old_background
= ::GetBkColor(GetHdc());
1448 if (m_textForegroundColour
.Ok())
1450 ::SetTextColor(GetHdc(), m_textForegroundColour
.GetPixel() );
1452 if (m_textBackgroundColour
.Ok())
1454 ::SetBkColor(GetHdc(), m_textBackgroundColour
.GetPixel() );
1457 DWORD dwRop
= SRCCOPY
;
1460 case wxXOR
: dwRop
= SRCINVERT
; break;
1461 case wxINVERT
: dwRop
= DSTINVERT
; break;
1462 case wxOR_REVERSE
: dwRop
= 0x00DD0228; break;
1463 case wxAND_REVERSE
: dwRop
= SRCERASE
; break;
1464 case wxCLEAR
: dwRop
= BLACKNESS
; break;
1465 case wxSET
: dwRop
= WHITENESS
; break;
1466 case wxOR_INVERT
: dwRop
= MERGEPAINT
; break;
1467 case wxAND
: dwRop
= SRCAND
; break;
1468 case wxOR
: dwRop
= SRCPAINT
; break;
1469 case wxEQUIV
: dwRop
= 0x00990066; break;
1470 case wxNAND
: dwRop
= 0x007700E6; break;
1471 case wxAND_INVERT
: dwRop
= 0x00220326; break;
1472 case wxCOPY
: dwRop
= SRCCOPY
; break;
1473 case wxNO_OP
: dwRop
= DSTCOPY
; break;
1474 case wxSRC_INVERT
: dwRop
= NOTSRCCOPY
; break;
1475 case wxNOR
: dwRop
= NOTSRCCOPY
; break;
1477 wxFAIL_MSG( wxT("unsupported logical function") );
1481 bool success
= FALSE
;
1486 // we want the part of the image corresponding to the mask to be
1487 // transparent, so use "DSTCOPY" ROP for the mask points (the usual
1488 // meaning of fg and bg is inverted which corresponds to wxWin notion
1489 // of the mask which is also contrary to the Windows one)
1491 // On some systems, MaskBlt succeeds yet is much much slower
1492 // than the wxWindows fall-back implementation. So we need
1493 // to be able to switch this on and off at runtime.
1494 if (wxSystemSettings::GetOptionInt(wxT("no-maskblt")) == 0)
1496 success
= ::MaskBlt(GetHdc(), xdest
, ydest
, width
, height
,
1497 GetHdcOf(*source
), xsrc
, ysrc
,
1498 (HBITMAP
)mask
->GetMaskBitmap(), xsrc
, ysrc
,
1499 MAKEROP4(dwRop
, DSTCOPY
)) != 0;
1505 // Blit bitmap with mask
1507 // create a temp buffer bitmap and DCs to access it and the mask
1508 HDC dc_mask
= ::CreateCompatibleDC(GetHdcOf(*source
));
1509 HDC dc_buffer
= ::CreateCompatibleDC(GetHdc());
1510 HBITMAP buffer_bmap
= ::CreateCompatibleBitmap(GetHdc(), width
, height
);
1511 ::SelectObject(dc_mask
, (HBITMAP
) mask
->GetMaskBitmap());
1512 ::SelectObject(dc_buffer
, buffer_bmap
);
1514 // copy dest to buffer
1515 if ( !::BitBlt(dc_buffer
, 0, 0, (int)width
, (int)height
,
1516 GetHdc(), xdest
, ydest
, SRCCOPY
) )
1518 wxLogLastError(wxT("BitBlt"));
1521 // copy src to buffer using selected raster op
1522 if ( !::BitBlt(dc_buffer
, 0, 0, (int)width
, (int)height
,
1523 GetHdcOf(*source
), xsrc
, ysrc
, dwRop
) )
1525 wxLogLastError(wxT("BitBlt"));
1528 // set masked area in buffer to BLACK (pixel value 0)
1529 COLORREF prevBkCol
= ::SetBkColor(GetHdc(), RGB(255, 255, 255));
1530 COLORREF prevCol
= ::SetTextColor(GetHdc(), RGB(0, 0, 0));
1531 if ( !::BitBlt(dc_buffer
, 0, 0, (int)width
, (int)height
,
1532 dc_mask
, xsrc
, ysrc
, SRCAND
) )
1534 wxLogLastError(wxT("BitBlt"));
1537 // set unmasked area in dest to BLACK
1538 ::SetBkColor(GetHdc(), RGB(0, 0, 0));
1539 ::SetTextColor(GetHdc(), RGB(255, 255, 255));
1540 if ( !::BitBlt(GetHdc(), xdest
, ydest
, (int)width
, (int)height
,
1541 dc_mask
, xsrc
, ysrc
, SRCAND
) )
1543 wxLogLastError(wxT("BitBlt"));
1545 ::SetBkColor(GetHdc(), prevBkCol
); // restore colours to original values
1546 ::SetTextColor(GetHdc(), prevCol
);
1548 // OR buffer to dest
1549 success
= ::BitBlt(GetHdc(), xdest
, ydest
,
1550 (int)width
, (int)height
,
1551 dc_buffer
, 0, 0, SRCPAINT
) != 0;
1554 wxLogLastError(wxT("BitBlt"));
1557 // tidy up temporary DCs and bitmap
1558 ::SelectObject(dc_mask
, 0);
1559 ::DeleteDC(dc_mask
);
1560 ::SelectObject(dc_buffer
, 0);
1561 ::DeleteDC(dc_buffer
);
1562 ::DeleteObject(buffer_bmap
);
1565 else // no mask, just BitBlt() it
1567 success
= ::BitBlt(GetHdc(), xdest
, ydest
,
1568 (int)width
, (int)height
,
1569 GetHdcOf(*source
), xsrc
, ysrc
, dwRop
) != 0;
1572 wxLogLastError(wxT("BitBlt"));
1575 ::SetTextColor(GetHdc(), old_textground
);
1576 ::SetBkColor(GetHdc(), old_background
);
1581 void wxDC::DoGetSize(int *w
, int *h
) const
1583 if ( w
) *w
= ::GetDeviceCaps(GetHdc(), HORZRES
);
1584 if ( h
) *h
= ::GetDeviceCaps(GetHdc(), VERTRES
);
1587 void wxDC::DoGetSizeMM(int *w
, int *h
) const
1589 if ( w
) *w
= ::GetDeviceCaps(GetHdc(), HORZSIZE
);
1590 if ( h
) *h
= ::GetDeviceCaps(GetHdc(), VERTSIZE
);
1593 wxSize
wxDC::GetPPI() const
1595 int x
= ::GetDeviceCaps(GetHdc(), LOGPIXELSX
);
1596 int y
= ::GetDeviceCaps(GetHdc(), LOGPIXELSY
);
1598 return wxSize(x
, y
);
1601 // For use by wxWindows only, unless custom units are required.
1602 void wxDC::SetLogicalScale(double x
, double y
)
1604 m_logicalScaleX
= x
;
1605 m_logicalScaleY
= y
;
1608 #if WXWIN_COMPATIBILITY
1609 void wxDC::DoGetTextExtent(const wxString
& string
, float *x
, float *y
,
1610 float *descent
, float *externalLeading
,
1611 wxFont
*theFont
, bool use16bit
) const
1613 wxCoord x1
, y1
, descent1
, externalLeading1
;
1614 GetTextExtent(string
, & x1
, & y1
, & descent1
, & externalLeading1
, theFont
, use16bit
);
1617 *descent
= descent1
;
1618 if (externalLeading
)
1619 *externalLeading
= externalLeading1
;