]>
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/settings.h"
44 #include "wx/dcprint.h"
49 #include "wx/msw/private.h" // needs to be before #include <commdlg.h>
51 #if wxUSE_COMMON_DIALOGS
59 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxDCBase
)
61 // ---------------------------------------------------------------------------
63 // ---------------------------------------------------------------------------
65 static const int VIEWPORT_EXTENT
= 1000;
67 static const int MM_POINTS
= 9;
68 static const int MM_METRIC
= 10;
70 // usually this is defined in math.h
72 static const double M_PI
= 3.14159265358979323846;
75 // ROPs which don't have standard names (see "Ternary Raster Operations" in the
76 // MSDN docs for how this and other numbers in wxDC::Blit() are obtained)
77 #define DSTCOPY 0x00AA0029 // a.k.a. NOP operation
79 // ---------------------------------------------------------------------------
81 // ---------------------------------------------------------------------------
83 // convert degrees to radians
84 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
86 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
90 // instead of duplicating the same code which sets and then restores text
91 // colours in each wxDC method working with wxSTIPPLE_MASK_OPAQUE brushes,
92 // encapsulate this in a small helper class
94 // wxColourChanger: changes the text colours in the ctor if required and
95 // restores them in the dtor
99 wxColourChanger(wxDC
& dc
);
105 COLORREF m_colFgOld
, m_colBgOld
;
110 // ===========================================================================
112 // ===========================================================================
114 // ----------------------------------------------------------------------------
116 // ----------------------------------------------------------------------------
118 wxColourChanger::wxColourChanger(wxDC
& dc
) : m_dc(dc
)
120 if ( dc
.GetBrush().GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
122 HDC hdc
= GetHdcOf(dc
);
123 m_colFgOld
= ::GetTextColor(hdc
);
124 m_colBgOld
= ::GetBkColor(hdc
);
126 // note that Windows convention is opposite to wxWindows one, this is
127 // why text colour becomes the background one and vice versa
128 const wxColour
& colFg
= dc
.GetTextForeground();
131 ::SetBkColor(hdc
, colFg
.GetPixel());
134 const wxColour
& colBg
= dc
.GetTextBackground();
137 ::SetTextColor(hdc
, colBg
.GetPixel());
141 dc
.GetBackgroundMode() == wxTRANSPARENT
? TRANSPARENT
144 // flag which telsl us to undo changes in the dtor
149 // nothing done, nothing to undo
154 wxColourChanger::~wxColourChanger()
158 // restore the colours we changed
159 HDC hdc
= GetHdcOf(m_dc
);
161 ::SetBkMode(hdc
, TRANSPARENT
);
162 ::SetTextColor(hdc
, m_colFgOld
);
163 ::SetBkColor(hdc
, m_colBgOld
);
167 // ---------------------------------------------------------------------------
169 // ---------------------------------------------------------------------------
171 // Default constructor
185 m_windowExtX
= VIEWPORT_EXTENT
;
186 m_windowExtY
= VIEWPORT_EXTENT
;
194 SelectOldObjects(m_hDC
);
196 // if we own the HDC, we delete it, otherwise we just release it
200 ::DeleteDC(GetHdc());
202 else // we don't own our HDC
206 ::ReleaseDC(GetHwndOf(m_canvas
), GetHdc());
210 // Must have been a wxScreenDC
211 ::ReleaseDC((HWND
) NULL
, GetHdc());
217 // This will select current objects out of the DC,
218 // which is what you have to do before deleting the
220 void wxDC::SelectOldObjects(WXHDC dc
)
226 ::SelectObject((HDC
) dc
, (HBITMAP
) m_oldBitmap
);
227 if (m_selectedBitmap
.Ok())
229 m_selectedBitmap
.SetSelectedInto(NULL
);
235 ::SelectObject((HDC
) dc
, (HPEN
) m_oldPen
);
240 ::SelectObject((HDC
) dc
, (HBRUSH
) m_oldBrush
);
245 ::SelectObject((HDC
) dc
, (HFONT
) m_oldFont
);
250 ::SelectPalette((HDC
) dc
, (HPALETTE
) m_oldPalette
, TRUE
);
255 m_brush
= wxNullBrush
;
257 m_palette
= wxNullPalette
;
259 m_backgroundBrush
= wxNullBrush
;
260 m_selectedBitmap
= wxNullBitmap
;
263 // ---------------------------------------------------------------------------
265 // ---------------------------------------------------------------------------
267 #define DO_SET_CLIPPING_BOX() \
271 GetClipBox(GetHdc(), &rect); \
273 m_clipX1 = (wxCoord) XDEV2LOG(rect.left); \
274 m_clipY1 = (wxCoord) YDEV2LOG(rect.top); \
275 m_clipX2 = (wxCoord) XDEV2LOG(rect.right); \
276 m_clipY2 = (wxCoord) YDEV2LOG(rect.bottom); \
279 void wxDC::DoSetClippingRegion(wxCoord cx
, wxCoord cy
, wxCoord cw
, wxCoord ch
)
283 HRGN hrgn
= ::CreateRectRgn(XLOG2DEV(cx
), YLOG2DEV(cy
),
284 XLOG2DEV(cx
+ cw
), YLOG2DEV(cy
+ ch
));
287 wxLogLastError(_T("CreateRectRgn"));
291 if ( ::SelectClipRgn(GetHdc(), hrgn
) == ERROR
)
293 wxLogLastError(_T("SelectClipRgn"));
296 DO_SET_CLIPPING_BOX()
300 void wxDC::DoSetClippingRegionAsRegion(const wxRegion
& region
)
302 wxCHECK_RET( region
.GetHRGN(), wxT("invalid clipping region") );
307 SelectClipRgn(GetHdc(), (HRGN
) region
.GetHRGN());
309 ExtSelectClipRgn(GetHdc(), (HRGN
) region
.GetHRGN(), RGN_AND
);
312 DO_SET_CLIPPING_BOX()
315 void wxDC::DestroyClippingRegion()
317 if (m_clipping
&& m_hDC
)
319 // TODO: this should restore the previous clipping region,
320 // so that OnPaint processing works correctly, and the update clipping region
321 // doesn't get destroyed after the first DestroyClippingRegion.
322 HRGN rgn
= CreateRectRgn(0, 0, 32000, 32000);
323 SelectClipRgn(GetHdc(), rgn
);
329 // ---------------------------------------------------------------------------
330 // query capabilities
331 // ---------------------------------------------------------------------------
333 bool wxDC::CanDrawBitmap() const
338 bool wxDC::CanGetTextExtent() const
340 // What sort of display is it?
341 int technology
= ::GetDeviceCaps(GetHdc(), TECHNOLOGY
);
343 return (technology
== DT_RASDISPLAY
) || (technology
== DT_RASPRINTER
);
346 int wxDC::GetDepth() const
348 return (int)::GetDeviceCaps(GetHdc(), BITSPIXEL
);
351 // ---------------------------------------------------------------------------
353 // ---------------------------------------------------------------------------
360 GetClientRect((HWND
) m_canvas
->GetHWND(), &rect
);
364 // No, I think we should simply ignore this if printing on e.g.
366 // wxCHECK_RET( m_selectedBitmap.Ok(), wxT("this DC can't be cleared") );
367 if (!m_selectedBitmap
.Ok())
370 rect
.left
= 0; rect
.top
= 0;
371 rect
.right
= m_selectedBitmap
.GetWidth();
372 rect
.bottom
= m_selectedBitmap
.GetHeight();
375 (void) ::SetMapMode(GetHdc(), MM_TEXT
);
377 DWORD colour
= GetBkColor(GetHdc());
378 HBRUSH brush
= CreateSolidBrush(colour
);
379 FillRect(GetHdc(), &rect
, brush
);
382 ::SetMapMode(GetHdc(), MM_ANISOTROPIC
);
383 ::SetViewportExtEx(GetHdc(), VIEWPORT_EXTENT
, VIEWPORT_EXTENT
, NULL
);
384 ::SetWindowExtEx(GetHdc(), m_windowExtX
, m_windowExtY
, NULL
);
385 ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX
, (int)m_deviceOriginY
, NULL
);
386 ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX
, (int)m_logicalOriginY
, NULL
);
389 void wxDC::DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
, int style
)
391 if ( !::ExtFloodFill(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
),
393 style
== wxFLOOD_SURFACE
? FLOODFILLSURFACE
396 // quoting from the MSDN docs:
398 // Following are some of the reasons this function might fail:
400 // * The filling could not be completed.
401 // * The specified point has the boundary color specified by the
402 // crColor parameter (if FLOODFILLBORDER was requested).
403 // * The specified point does not have the color specified by
404 // crColor (if FLOODFILLSURFACE was requested)
405 // * The point is outside the clipping region that is, it is not
406 // visible on the device.
408 wxLogLastError(wxT("ExtFloodFill"));
411 CalcBoundingBox(x
, y
);
414 bool wxDC::DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const
416 wxCHECK_MSG( col
, FALSE
, _T("NULL colour parameter in wxDC::GetPixel") );
418 // get the color of the pixel
419 COLORREF pixelcolor
= ::GetPixel(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
));
421 wxRGBToColour(*col
, pixelcolor
);
426 void wxDC::DoCrossHair(wxCoord x
, wxCoord y
)
428 wxCoord x1
= x
-VIEWPORT_EXTENT
;
429 wxCoord y1
= y
-VIEWPORT_EXTENT
;
430 wxCoord x2
= x
+VIEWPORT_EXTENT
;
431 wxCoord y2
= y
+VIEWPORT_EXTENT
;
433 (void)MoveToEx(GetHdc(), XLOG2DEV(x1
), YLOG2DEV(y
), NULL
);
434 (void)LineTo(GetHdc(), XLOG2DEV(x2
), YLOG2DEV(y
));
436 (void)MoveToEx(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y1
), NULL
);
437 (void)LineTo(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y2
));
439 CalcBoundingBox(x1
, y1
);
440 CalcBoundingBox(x2
, y2
);
443 void wxDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
445 (void)MoveToEx(GetHdc(), XLOG2DEV(x1
), YLOG2DEV(y1
), NULL
);
446 (void)LineTo(GetHdc(), XLOG2DEV(x2
), YLOG2DEV(y2
));
448 // Normalization: Windows doesn't draw the last point of the line.
449 // But apparently neither does GTK+, so we take it out again.
450 // (void)LineTo(GetHdc(), XLOG2DEV(x2) + 1, YLOG2DEV(y2));
452 CalcBoundingBox(x1
, y1
);
453 CalcBoundingBox(x2
, y2
);
456 // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
457 // and ending at (x2, y2)
458 void wxDC::DoDrawArc(wxCoord x1
, wxCoord y1
,
459 wxCoord x2
, wxCoord y2
,
460 wxCoord xc
, wxCoord yc
)
462 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
466 double radius
= (double)sqrt(dx
*dx
+dy
*dy
);
467 wxCoord r
= (wxCoord
)radius
;
469 // treat the special case of full circle separately
470 if ( x1
== x2
&& y1
== y2
)
472 DrawEllipse(xc
- r
, yc
- r
, 2*r
, 2*r
);
476 wxCoord xx1
= XLOG2DEV(x1
);
477 wxCoord yy1
= YLOG2DEV(y1
);
478 wxCoord xx2
= XLOG2DEV(x2
);
479 wxCoord yy2
= YLOG2DEV(y2
);
480 wxCoord xxc
= XLOG2DEV(xc
);
481 wxCoord yyc
= YLOG2DEV(yc
);
482 wxCoord ray
= (wxCoord
) sqrt(double((xxc
-xx1
)*(xxc
-xx1
)+(yyc
-yy1
)*(yyc
-yy1
)));
484 wxCoord xxx1
= (wxCoord
) (xxc
-ray
);
485 wxCoord yyy1
= (wxCoord
) (yyc
-ray
);
486 wxCoord xxx2
= (wxCoord
) (xxc
+ray
);
487 wxCoord yyy2
= (wxCoord
) (yyc
+ray
);
489 if ( m_brush
.Ok() && m_brush
.GetStyle() != wxTRANSPARENT
)
491 // Have to add 1 to bottom-right corner of rectangle
492 // to make semi-circles look right (crooked line otherwise).
493 // Unfortunately this is not a reliable method, depends
494 // on the size of shape.
495 // TODO: figure out why this happens!
496 Pie(GetHdc(),xxx1
,yyy1
,xxx2
+1,yyy2
+1, xx1
,yy1
,xx2
,yy2
);
500 Arc(GetHdc(),xxx1
,yyy1
,xxx2
,yyy2
, xx1
,yy1
,xx2
,yy2
);
503 CalcBoundingBox(xc
- r
, yc
- r
);
504 CalcBoundingBox(xc
+ r
, yc
+ r
);
507 void wxDC::DoDrawCheckMark(wxCoord x1
, wxCoord y1
,
508 wxCoord width
, wxCoord height
)
510 wxCoord x2
= x1
+ width
,
513 #if defined(__WIN32__) && !defined(__SC__)
520 DrawFrameControl(GetHdc(), &rect
, DFC_MENU
, DFCS_MENUCHECK
);
522 // In WIN16, draw a cross
523 HPEN blackPen
= ::CreatePen(PS_SOLID
, 1, RGB(0, 0, 0));
524 HPEN whiteBrush
= (HPEN
)::GetStockObject(WHITE_BRUSH
);
525 HPEN hPenOld
= (HPEN
)::SelectObject(GetHdc(), blackPen
);
526 HPEN hBrushOld
= (HPEN
)::SelectObject(GetHdc(), whiteBrush
);
527 ::SetROP2(GetHdc(), R2_COPYPEN
);
528 Rectangle(GetHdc(), x1
, y1
, x2
, y2
);
529 MoveTo(GetHdc(), x1
, y1
);
530 LineTo(GetHdc(), x2
, y2
);
531 MoveTo(GetHdc(), x2
, y1
);
532 LineTo(GetHdc(), x1
, y2
);
533 ::SelectObject(GetHdc(), hPenOld
);
534 ::SelectObject(GetHdc(), hBrushOld
);
535 ::DeleteObject(blackPen
);
538 CalcBoundingBox(x1
, y1
);
539 CalcBoundingBox(x2
, y2
);
542 void wxDC::DoDrawPoint(wxCoord x
, wxCoord y
)
544 COLORREF color
= 0x00ffffff;
547 color
= m_pen
.GetColour().GetPixel();
550 SetPixel(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), color
);
552 CalcBoundingBox(x
, y
);
555 void wxDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
,int fillStyle
)
557 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
559 // Do things less efficiently if we have offsets
560 if (xoffset
!= 0 || yoffset
!= 0)
562 POINT
*cpoints
= new POINT
[n
];
564 for (i
= 0; i
< n
; i
++)
566 cpoints
[i
].x
= (int)(points
[i
].x
+ xoffset
);
567 cpoints
[i
].y
= (int)(points
[i
].y
+ yoffset
);
569 CalcBoundingBox(cpoints
[i
].x
, cpoints
[i
].y
);
571 int prev
= SetPolyFillMode(GetHdc(),fillStyle
==wxODDEVEN_RULE
?ALTERNATE
:WINDING
);
572 (void)Polygon(GetHdc(), cpoints
, n
);
573 SetPolyFillMode(GetHdc(),prev
);
579 for (i
= 0; i
< n
; i
++)
580 CalcBoundingBox(points
[i
].x
, points
[i
].y
);
582 int prev
= SetPolyFillMode(GetHdc(),fillStyle
==wxODDEVEN_RULE
?ALTERNATE
:WINDING
);
583 (void)Polygon(GetHdc(), (POINT
*) points
, n
);
584 SetPolyFillMode(GetHdc(),prev
);
588 void wxDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
590 // Do things less efficiently if we have offsets
591 if (xoffset
!= 0 || yoffset
!= 0)
593 POINT
*cpoints
= new POINT
[n
];
595 for (i
= 0; i
< n
; i
++)
597 cpoints
[i
].x
= (int)(points
[i
].x
+ xoffset
);
598 cpoints
[i
].y
= (int)(points
[i
].y
+ yoffset
);
600 CalcBoundingBox(cpoints
[i
].x
, cpoints
[i
].y
);
602 (void)Polyline(GetHdc(), cpoints
, n
);
608 for (i
= 0; i
< n
; i
++)
609 CalcBoundingBox(points
[i
].x
, points
[i
].y
);
611 (void)Polyline(GetHdc(), (POINT
*) points
, n
);
615 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
617 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
619 wxCoord x2
= x
+ width
;
620 wxCoord y2
= y
+ height
;
622 if ((m_logicalFunction
== wxCOPY
) && (m_pen
.GetStyle() == wxTRANSPARENT
))
625 rect
.left
= XLOG2DEV(x
);
626 rect
.top
= YLOG2DEV(y
);
627 rect
.right
= XLOG2DEV(x2
);
628 rect
.bottom
= YLOG2DEV(y2
);
629 (void)FillRect(GetHdc(), &rect
, (HBRUSH
)m_brush
.GetResourceHandle() );
633 // Windows draws the filled rectangles without outline (i.e. drawn with a
634 // transparent pen) one pixel smaller in both directions and we want them
635 // to have the same size regardless of which pen is used - adjust
637 // I wonder if this shouldn´t be done after the LOG2DEV() conversions. RR.
638 if ( m_pen
.GetStyle() == wxTRANSPARENT
)
644 (void)Rectangle(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
));
648 CalcBoundingBox(x
, y
);
649 CalcBoundingBox(x2
, y2
);
652 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
654 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
656 // Now, a negative radius value is interpreted to mean
657 // 'the proportion of the smallest X or Y dimension'
661 double smallest
= 0.0;
666 radius
= (- radius
* smallest
);
669 wxCoord x2
= (x
+width
);
670 wxCoord y2
= (y
+height
);
672 // Windows draws the filled rectangles without outline (i.e. drawn with a
673 // transparent pen) one pixel smaller in both directions and we want them
674 // to have the same size regardless of which pen is used - adjust
675 if ( m_pen
.GetStyle() == wxTRANSPARENT
)
681 (void)RoundRect(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
),
682 YLOG2DEV(y2
), (int) (2*XLOG2DEV(radius
)), (int)( 2*YLOG2DEV(radius
)));
684 CalcBoundingBox(x
, y
);
685 CalcBoundingBox(x2
, y2
);
688 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
690 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
692 wxCoord x2
= (x
+width
);
693 wxCoord y2
= (y
+height
);
695 (void)Ellipse(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
));
697 CalcBoundingBox(x
, y
);
698 CalcBoundingBox(x2
, y2
);
701 // Chris Breeze 20/5/98: first implementation of DrawEllipticArc on Windows
702 void wxDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
704 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
709 int rx1
= XLOG2DEV(x
+w
/2);
710 int ry1
= YLOG2DEV(y
+h
/2);
717 rx1
+= (int)(100.0 * abs(w
) * cos(sa
));
718 ry1
-= (int)(100.0 * abs(h
) * m_signY
* sin(sa
));
719 rx2
+= (int)(100.0 * abs(w
) * cos(ea
));
720 ry2
-= (int)(100.0 * abs(h
) * m_signY
* sin(ea
));
722 // draw pie with NULL_PEN first and then outline otherwise a line is
723 // drawn from the start and end points to the centre
724 HPEN hpenOld
= (HPEN
) ::SelectObject(GetHdc(), (HPEN
) ::GetStockObject(NULL_PEN
));
727 (void)Pie(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
)+1, YLOG2DEV(y2
)+1,
732 (void)Pie(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
)-1, XLOG2DEV(x2
)+1, YLOG2DEV(y2
),
733 rx1
, ry1
-1, rx2
, ry2
-1);
736 ::SelectObject(GetHdc(), hpenOld
);
738 (void)Arc(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
),
741 CalcBoundingBox(x
, y
);
742 CalcBoundingBox(x2
, y2
);
745 void wxDC::DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
)
747 wxCHECK_RET( icon
.Ok(), wxT("invalid icon in DrawIcon") );
750 ::DrawIconEx(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), GetHiconOf(icon
), icon
.GetWidth(), icon
.GetHeight(), 0, NULL
, DI_NORMAL
);
752 ::DrawIcon(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), GetHiconOf(icon
));
755 CalcBoundingBox(x
, y
);
756 CalcBoundingBox(x
+ icon
.GetWidth(), y
+ icon
.GetHeight());
759 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
761 wxCHECK_RET( bmp
.Ok(), _T("invalid bitmap in wxDC::DrawBitmap") );
763 int width
= bmp
.GetWidth(),
764 height
= bmp
.GetHeight();
766 HBITMAP hbmpMask
= 0;
770 wxMask
*mask
= bmp
.GetMask();
772 hbmpMask
= (HBITMAP
)mask
->GetMaskBitmap();
776 // don't give assert here because this would break existing
777 // programs - just silently ignore useMask parameter
785 // use MaskBlt() with ROP which doesn't do anything to dst in the mask
787 // On some systems, MaskBlt succeeds yet is much much slower
788 // than the wxWindows fall-back implementation. So we need
789 // to be able to switch this on and off at runtime.
791 if (wxSystemSettings::GetOptionInt(wxT("no-maskblt")) == 0)
793 HDC hdcMem
= ::CreateCompatibleDC(GetHdc());
794 ::SelectObject(hdcMem
, GetHbitmapOf(bmp
));
796 ok
= ::MaskBlt(GetHdc(), x
, y
, width
, height
,
799 MAKEROP4(SRCCOPY
, DSTCOPY
)) != 0;
806 // Rather than reproduce wxDC::Blit, let's do it at the wxWin API
809 memDC
.SelectObject(bmp
);
811 Blit(x
, y
, width
, height
, &memDC
, 0, 0, wxCOPY
, useMask
);
813 memDC
.SelectObject(wxNullBitmap
);
816 else // no mask, just use BitBlt()
819 HDC memdc
= ::CreateCompatibleDC( cdc
);
820 HBITMAP hbitmap
= (HBITMAP
) bmp
.GetHBITMAP( );
822 wxASSERT_MSG( hbitmap
, wxT("bitmap is ok but HBITMAP is NULL?") );
824 COLORREF old_textground
= ::GetTextColor(GetHdc());
825 COLORREF old_background
= ::GetBkColor(GetHdc());
826 if (m_textForegroundColour
.Ok())
828 ::SetTextColor(GetHdc(), m_textForegroundColour
.GetPixel() );
830 if (m_textBackgroundColour
.Ok())
832 ::SetBkColor(GetHdc(), m_textBackgroundColour
.GetPixel() );
835 ::SelectObject( memdc
, hbitmap
);
836 ::BitBlt( cdc
, x
, y
, width
, height
, memdc
, 0, 0, SRCCOPY
);
839 ::SetTextColor(GetHdc(), old_textground
);
840 ::SetBkColor(GetHdc(), old_background
);
844 void wxDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
846 DrawAnyText(text
, x
, y
);
848 // update the bounding box
849 CalcBoundingBox(x
, y
);
852 GetTextExtent(text
, &w
, &h
);
853 CalcBoundingBox(x
+ w
, y
+ h
);
856 void wxDC::DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
)
858 // prepare for drawing the text
859 if ( m_textForegroundColour
.Ok() )
860 SetTextColor(GetHdc(), m_textForegroundColour
.GetPixel());
862 DWORD old_background
= 0;
863 if ( m_textBackgroundColour
.Ok() )
865 old_background
= SetBkColor(GetHdc(), m_textBackgroundColour
.GetPixel() );
868 SetBkMode(GetHdc(), m_backgroundMode
== wxTRANSPARENT
? TRANSPARENT
871 if ( ::TextOut(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
),
872 text
.c_str(), text
.length()) == 0 )
874 wxLogLastError(wxT("TextOut"));
877 // restore the old parameters (text foreground colour may be left because
878 // it never is set to anything else, but background should remain
879 // transparent even if we just drew an opaque string)
880 if ( m_textBackgroundColour
.Ok() )
881 (void)SetBkColor(GetHdc(), old_background
);
883 SetBkMode(GetHdc(), TRANSPARENT
);
886 void wxDC::DoDrawRotatedText(const wxString
& text
,
887 wxCoord x
, wxCoord y
,
890 // we test that we have some font because otherwise we should still use the
891 // "else" part below to avoid that DrawRotatedText(angle = 180) and
892 // DrawRotatedText(angle = 0) use different fonts (we can't use the default
893 // font for drawing rotated fonts unfortunately)
894 if ( (angle
== 0.0) && m_font
.Ok() )
896 DoDrawText(text
, x
, y
);
900 // NB: don't take DEFAULT_GUI_FONT because it's not TrueType and so
901 // can't have non zero orientation/escapement
902 wxFont font
= m_font
.Ok() ? m_font
: *wxNORMAL_FONT
;
903 HFONT hfont
= (HFONT
)font
.GetResourceHandle();
905 if ( ::GetObject(hfont
, sizeof(lf
), &lf
) == 0 )
907 wxLogLastError(wxT("GetObject(hfont)"));
910 // GDI wants the angle in tenth of degree
911 long angle10
= (long)(angle
* 10);
912 lf
.lfEscapement
= angle10
;
913 lf
. lfOrientation
= angle10
;
915 hfont
= ::CreateFontIndirect(&lf
);
918 wxLogLastError(wxT("CreateFont"));
922 HFONT hfontOld
= (HFONT
)::SelectObject(GetHdc(), hfont
);
924 DrawAnyText(text
, x
, y
);
926 (void)::SelectObject(GetHdc(), hfontOld
);
927 (void)::DeleteObject(hfont
);
930 // call the bounding box by adding all four vertices of the rectangle
931 // containing the text to it (simpler and probably not slower than
932 // determining which of them is really topmost/leftmost/...)
934 GetTextExtent(text
, &w
, &h
);
936 double rad
= DegToRad(angle
);
938 // "upper left" and "upper right"
939 CalcBoundingBox(x
, y
);
940 CalcBoundingBox(x
+ w
*cos(rad
), y
- h
*sin(rad
));
942 // "bottom left" and "bottom right"
943 x
+= (wxCoord
)(h
*sin(rad
));
944 y
+= (wxCoord
)(h
*cos(rad
));
945 CalcBoundingBox(x
, y
);
946 CalcBoundingBox(x
+ h
*sin(rad
), y
+ h
*cos(rad
));
950 // ---------------------------------------------------------------------------
952 // ---------------------------------------------------------------------------
954 void wxDC::SetPalette(const wxPalette
& palette
)
956 // Set the old object temporarily, in case the assignment deletes an object
957 // that's not yet selected out.
960 ::SelectPalette(GetHdc(), (HPALETTE
) m_oldPalette
, TRUE
);
968 // Setting a NULL colourmap is a way of restoring
969 // the original colourmap
972 ::SelectPalette(GetHdc(), (HPALETTE
) m_oldPalette
, TRUE
);
979 if (m_palette
.Ok() && m_palette
.GetHPALETTE())
981 HPALETTE oldPal
= ::SelectPalette(GetHdc(), (HPALETTE
) m_palette
.GetHPALETTE(), TRUE
);
983 m_oldPalette
= (WXHPALETTE
) oldPal
;
985 ::RealizePalette(GetHdc());
989 void wxDC::SetFont(const wxFont
& the_font
)
991 // Set the old object temporarily, in case the assignment deletes an object
992 // that's not yet selected out.
995 ::SelectObject(GetHdc(), (HFONT
) m_oldFont
);
1004 ::SelectObject(GetHdc(), (HFONT
) m_oldFont
);
1008 if (m_font
.Ok() && m_font
.GetResourceHandle())
1010 HFONT f
= (HFONT
) ::SelectObject(GetHdc(), (HFONT
) m_font
.GetResourceHandle());
1011 if (f
== (HFONT
) NULL
)
1013 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
1016 m_oldFont
= (WXHFONT
) f
;
1020 void wxDC::SetPen(const wxPen
& pen
)
1022 // Set the old object temporarily, in case the assignment deletes an object
1023 // that's not yet selected out.
1026 ::SelectObject(GetHdc(), (HPEN
) m_oldPen
);
1035 ::SelectObject(GetHdc(), (HPEN
) m_oldPen
);
1041 if (m_pen
.GetResourceHandle())
1043 HPEN p
= (HPEN
) ::SelectObject(GetHdc(), (HPEN
)m_pen
.GetResourceHandle());
1045 m_oldPen
= (WXHPEN
) p
;
1050 void wxDC::SetBrush(const wxBrush
& brush
)
1052 // Set the old object temporarily, in case the assignment deletes an object
1053 // that's not yet selected out.
1056 ::SelectObject(GetHdc(), (HBRUSH
) m_oldBrush
);
1065 ::SelectObject(GetHdc(), (HBRUSH
) m_oldBrush
);
1071 // to make sure the brush is alligned with the logical coordinates
1072 wxBitmap
*stipple
= m_brush
.GetStipple();
1073 if ( stipple
&& stipple
->Ok() )
1076 ::SetBrushOrgEx(GetHdc(),
1077 m_deviceOriginX
% stipple
->GetWidth(),
1078 m_deviceOriginY
% stipple
->GetHeight(),
1079 NULL
); // don't need previous brush origin
1081 ::SetBrushOrg(GetHdc(),
1082 m_deviceOriginX
% stipple
->GetWidth(),
1083 m_deviceOriginY
% stipple
->GetHeight());
1087 if ( m_brush
.GetResourceHandle() )
1090 b
= (HBRUSH
) ::SelectObject(GetHdc(), (HBRUSH
)m_brush
.GetResourceHandle());
1092 m_oldBrush
= (WXHBRUSH
) b
;
1097 void wxDC::SetBackground(const wxBrush
& brush
)
1099 m_backgroundBrush
= brush
;
1101 if (!m_backgroundBrush
.Ok())
1106 bool customColours
= TRUE
;
1107 // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
1108 // change background colours from the control-panel specified colours.
1109 if (m_canvas
->IsKindOf(CLASSINFO(wxWindow
)) && ((m_canvas
->GetWindowStyleFlag() & wxUSER_COLOURS
) != wxUSER_COLOURS
))
1110 customColours
= FALSE
;
1114 if (m_backgroundBrush
.GetStyle()==wxTRANSPARENT
)
1116 m_canvas
->SetTransparent(TRUE
);
1120 // New behaviour, 10/2/99: setting the background brush of a DC
1121 // doesn't affect the window background colour. However,
1122 // I'm leaving in the transparency setting because it's needed by
1123 // various controls (e.g. wxStaticText) to determine whether to draw
1124 // transparently or not. TODO: maybe this should be a new function
1125 // wxWindow::SetTransparency(). Should that apply to the child itself, or the
1127 // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour());
1128 m_canvas
->SetTransparent(FALSE
);
1132 COLORREF new_color
= m_backgroundBrush
.GetColour().GetPixel();
1134 (void)SetBkColor(GetHdc(), new_color
);
1138 void wxDC::SetBackgroundMode(int mode
)
1140 m_backgroundMode
= mode
;
1142 // SetBackgroundColour now only refers to text background
1143 // and m_backgroundMode is used there
1146 if (m_backgroundMode == wxTRANSPARENT)
1147 ::SetBkMode(GetHdc(), TRANSPARENT);
1149 ::SetBkMode(GetHdc(), OPAQUE);
1150 Last change: AC 29 Jan 101 8:54 pm
1154 void wxDC::SetLogicalFunction(int function
)
1156 m_logicalFunction
= function
;
1161 void wxDC::SetRop(WXHDC dc
)
1163 if ( !dc
|| m_logicalFunction
< 0 )
1168 switch (m_logicalFunction
)
1170 case wxCLEAR
: rop
= R2_BLACK
; break;
1171 case wxXOR
: rop
= R2_XORPEN
; break;
1172 case wxINVERT
: rop
= R2_NOT
; break;
1173 case wxOR_REVERSE
: rop
= R2_MERGEPENNOT
; break;
1174 case wxAND_REVERSE
: rop
= R2_MASKPENNOT
; break;
1175 case wxCOPY
: rop
= R2_COPYPEN
; break;
1176 case wxAND
: rop
= R2_MASKPEN
; break;
1177 case wxAND_INVERT
: rop
= R2_MASKNOTPEN
; break;
1178 case wxNO_OP
: rop
= R2_NOP
; break;
1179 case wxNOR
: rop
= R2_NOTMERGEPEN
; break;
1180 case wxEQUIV
: rop
= R2_NOTXORPEN
; break;
1181 case wxSRC_INVERT
: rop
= R2_NOTCOPYPEN
; break;
1182 case wxOR_INVERT
: rop
= R2_MERGENOTPEN
; break;
1183 case wxNAND
: rop
= R2_NOTMASKPEN
; break;
1184 case wxOR
: rop
= R2_MERGEPEN
; break;
1185 case wxSET
: rop
= R2_WHITE
; break;
1188 wxFAIL_MSG( wxT("unsupported logical function") );
1192 SetROP2(GetHdc(), rop
);
1195 bool wxDC::StartDoc(const wxString
& WXUNUSED(message
))
1197 // We might be previewing, so return TRUE to let it continue.
1205 void wxDC::StartPage()
1209 void wxDC::EndPage()
1213 // ---------------------------------------------------------------------------
1215 // ---------------------------------------------------------------------------
1217 wxCoord
wxDC::GetCharHeight() const
1219 TEXTMETRIC lpTextMetric
;
1221 GetTextMetrics(GetHdc(), &lpTextMetric
);
1223 return YDEV2LOGREL(lpTextMetric
.tmHeight
);
1226 wxCoord
wxDC::GetCharWidth() const
1228 TEXTMETRIC lpTextMetric
;
1230 GetTextMetrics(GetHdc(), &lpTextMetric
);
1232 return XDEV2LOGREL(lpTextMetric
.tmAveCharWidth
);
1235 void wxDC::DoGetTextExtent(const wxString
& string
, wxCoord
*x
, wxCoord
*y
,
1236 wxCoord
*descent
, wxCoord
*externalLeading
,
1242 wxASSERT_MSG( font
->Ok(), _T("invalid font in wxDC::GetTextExtent") );
1244 hfontOld
= (HFONT
)::SelectObject(GetHdc(), GetHfontOf(*font
));
1246 else // don't change the font
1254 GetTextExtentPoint(GetHdc(), string
, string
.length(), &sizeRect
);
1255 GetTextMetrics(GetHdc(), &tm
);
1257 if (x
) *x
= XDEV2LOGREL(sizeRect
.cx
);
1258 if (y
) *y
= YDEV2LOGREL(sizeRect
.cy
);
1259 if (descent
) *descent
= tm
.tmDescent
;
1260 if (externalLeading
) *externalLeading
= tm
.tmExternalLeading
;
1264 ::SelectObject(GetHdc(), hfontOld
);
1268 void wxDC::SetMapMode(int mode
)
1270 m_mappingMode
= mode
;
1272 int pixel_width
= 0;
1273 int pixel_height
= 0;
1277 pixel_width
= GetDeviceCaps(GetHdc(), HORZRES
);
1278 pixel_height
= GetDeviceCaps(GetHdc(), VERTRES
);
1279 mm_width
= GetDeviceCaps(GetHdc(), HORZSIZE
);
1280 mm_height
= GetDeviceCaps(GetHdc(), VERTSIZE
);
1282 if ((pixel_width
== 0) || (pixel_height
== 0) || (mm_width
== 0) || (mm_height
== 0))
1287 double mm2pixelsX
= pixel_width
/mm_width
;
1288 double mm2pixelsY
= pixel_height
/mm_height
;
1294 m_logicalScaleX
= (twips2mm
* mm2pixelsX
);
1295 m_logicalScaleY
= (twips2mm
* mm2pixelsY
);
1300 m_logicalScaleX
= (pt2mm
* mm2pixelsX
);
1301 m_logicalScaleY
= (pt2mm
* mm2pixelsY
);
1306 m_logicalScaleX
= mm2pixelsX
;
1307 m_logicalScaleY
= mm2pixelsY
;
1312 m_logicalScaleX
= (mm2pixelsX
/10.0);
1313 m_logicalScaleY
= (mm2pixelsY
/10.0);
1319 m_logicalScaleX
= 1.0;
1320 m_logicalScaleY
= 1.0;
1325 if (::GetMapMode(GetHdc()) != MM_ANISOTROPIC
)
1326 ::SetMapMode(GetHdc(), MM_ANISOTROPIC
);
1328 SetViewportExtEx(GetHdc(), VIEWPORT_EXTENT
, VIEWPORT_EXTENT
, NULL
);
1329 m_windowExtX
= (int)MS_XDEV2LOGREL(VIEWPORT_EXTENT
);
1330 m_windowExtY
= (int)MS_YDEV2LOGREL(VIEWPORT_EXTENT
);
1331 ::SetWindowExtEx(GetHdc(), m_windowExtX
, m_windowExtY
, NULL
);
1332 ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX
, (int)m_deviceOriginY
, NULL
);
1333 ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX
, (int)m_logicalOriginY
, NULL
);
1336 void wxDC::SetUserScale(double x
, double y
)
1341 SetMapMode(m_mappingMode
);
1344 void wxDC::SetAxisOrientation(bool xLeftRight
, bool yBottomUp
)
1346 m_signX
= xLeftRight
? 1 : -1;
1347 m_signY
= yBottomUp
? -1 : 1;
1349 SetMapMode(m_mappingMode
);
1352 void wxDC::SetSystemScale(double x
, double y
)
1357 SetMapMode(m_mappingMode
);
1360 void wxDC::SetLogicalOrigin(wxCoord x
, wxCoord y
)
1362 m_logicalOriginX
= x
;
1363 m_logicalOriginY
= y
;
1365 ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX
, (int)m_logicalOriginY
, NULL
);
1368 void wxDC::SetDeviceOrigin(wxCoord x
, wxCoord y
)
1370 m_deviceOriginX
= x
;
1371 m_deviceOriginY
= y
;
1373 ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX
, (int)m_deviceOriginY
, NULL
);
1376 // ---------------------------------------------------------------------------
1377 // coordinates transformations
1378 // ---------------------------------------------------------------------------
1380 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
1382 double xRel
= x
- m_deviceOriginX
;
1383 xRel
/= m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
;
1384 return (wxCoord
)(xRel
+ m_logicalOriginX
);
1387 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
1389 return (wxCoord
) ((x
)/(m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
));
1392 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
1394 double yRel
= y
- m_deviceOriginY
;
1395 yRel
/= m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
;
1396 return (wxCoord
)(yRel
+ m_logicalOriginY
);
1399 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
1401 return (wxCoord
) ((y
)/(m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
));
1404 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
1406 return (wxCoord
) ((x
- m_logicalOriginX
)*m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
+ m_deviceOriginX
);
1409 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
1411 return (wxCoord
) (x
*m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
);
1414 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
1416 return (wxCoord
) ((y
- m_logicalOriginY
)*m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
+ m_deviceOriginY
);
1419 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
1421 return (wxCoord
) (y
*m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
);
1424 // ---------------------------------------------------------------------------
1426 // ---------------------------------------------------------------------------
1428 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
,
1429 wxCoord width
, wxCoord height
,
1430 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
1431 int rop
, bool useMask
)
1433 wxMask
*mask
= NULL
;
1436 const wxBitmap
& bmp
= source
->m_selectedBitmap
;
1437 mask
= bmp
.GetMask();
1439 if ( !(bmp
.Ok() && mask
&& mask
->GetMaskBitmap()) )
1441 // don't give assert here because this would break existing
1442 // programs - just silently ignore useMask parameter
1447 COLORREF old_textground
= ::GetTextColor(GetHdc());
1448 COLORREF old_background
= ::GetBkColor(GetHdc());
1449 if (m_textForegroundColour
.Ok())
1451 ::SetTextColor(GetHdc(), m_textForegroundColour
.GetPixel() );
1453 if (m_textBackgroundColour
.Ok())
1455 ::SetBkColor(GetHdc(), m_textBackgroundColour
.GetPixel() );
1458 DWORD dwRop
= SRCCOPY
;
1461 case wxXOR
: dwRop
= SRCINVERT
; break;
1462 case wxINVERT
: dwRop
= DSTINVERT
; break;
1463 case wxOR_REVERSE
: dwRop
= 0x00DD0228; break;
1464 case wxAND_REVERSE
: dwRop
= SRCERASE
; break;
1465 case wxCLEAR
: dwRop
= BLACKNESS
; break;
1466 case wxSET
: dwRop
= WHITENESS
; break;
1467 case wxOR_INVERT
: dwRop
= MERGEPAINT
; break;
1468 case wxAND
: dwRop
= SRCAND
; break;
1469 case wxOR
: dwRop
= SRCPAINT
; break;
1470 case wxEQUIV
: dwRop
= 0x00990066; break;
1471 case wxNAND
: dwRop
= 0x007700E6; break;
1472 case wxAND_INVERT
: dwRop
= 0x00220326; break;
1473 case wxCOPY
: dwRop
= SRCCOPY
; break;
1474 case wxNO_OP
: dwRop
= DSTCOPY
; break;
1475 case wxSRC_INVERT
: dwRop
= NOTSRCCOPY
; break;
1476 case wxNOR
: dwRop
= NOTSRCCOPY
; break;
1478 wxFAIL_MSG( wxT("unsupported logical function") );
1482 bool success
= FALSE
;
1487 // we want the part of the image corresponding to the mask to be
1488 // transparent, so use "DSTCOPY" ROP for the mask points (the usual
1489 // meaning of fg and bg is inverted which corresponds to wxWin notion
1490 // of the mask which is also contrary to the Windows one)
1492 // On some systems, MaskBlt succeeds yet is much much slower
1493 // than the wxWindows fall-back implementation. So we need
1494 // to be able to switch this on and off at runtime.
1495 if (wxSystemSettings::GetOptionInt(wxT("no-maskblt")) == 0)
1497 success
= ::MaskBlt(GetHdc(), xdest
, ydest
, width
, height
,
1498 GetHdcOf(*source
), xsrc
, ysrc
,
1499 (HBITMAP
)mask
->GetMaskBitmap(), xsrc
, ysrc
,
1500 MAKEROP4(dwRop
, DSTCOPY
)) != 0;
1506 // Blit bitmap with mask
1508 // create a temp buffer bitmap and DCs to access it and the mask
1509 HDC dc_mask
= ::CreateCompatibleDC(GetHdcOf(*source
));
1510 HDC dc_buffer
= ::CreateCompatibleDC(GetHdc());
1511 HBITMAP buffer_bmap
= ::CreateCompatibleBitmap(GetHdc(), width
, height
);
1512 ::SelectObject(dc_mask
, (HBITMAP
) mask
->GetMaskBitmap());
1513 ::SelectObject(dc_buffer
, buffer_bmap
);
1515 // copy dest to buffer
1516 if ( !::BitBlt(dc_buffer
, 0, 0, (int)width
, (int)height
,
1517 GetHdc(), xdest
, ydest
, SRCCOPY
) )
1519 wxLogLastError(wxT("BitBlt"));
1522 // copy src to buffer using selected raster op
1523 if ( !::BitBlt(dc_buffer
, 0, 0, (int)width
, (int)height
,
1524 GetHdcOf(*source
), xsrc
, ysrc
, dwRop
) )
1526 wxLogLastError(wxT("BitBlt"));
1529 // set masked area in buffer to BLACK (pixel value 0)
1530 COLORREF prevBkCol
= ::SetBkColor(GetHdc(), RGB(255, 255, 255));
1531 COLORREF prevCol
= ::SetTextColor(GetHdc(), RGB(0, 0, 0));
1532 if ( !::BitBlt(dc_buffer
, 0, 0, (int)width
, (int)height
,
1533 dc_mask
, xsrc
, ysrc
, SRCAND
) )
1535 wxLogLastError(wxT("BitBlt"));
1538 // set unmasked area in dest to BLACK
1539 ::SetBkColor(GetHdc(), RGB(0, 0, 0));
1540 ::SetTextColor(GetHdc(), RGB(255, 255, 255));
1541 if ( !::BitBlt(GetHdc(), xdest
, ydest
, (int)width
, (int)height
,
1542 dc_mask
, xsrc
, ysrc
, SRCAND
) )
1544 wxLogLastError(wxT("BitBlt"));
1546 ::SetBkColor(GetHdc(), prevBkCol
); // restore colours to original values
1547 ::SetTextColor(GetHdc(), prevCol
);
1549 // OR buffer to dest
1550 success
= ::BitBlt(GetHdc(), xdest
, ydest
,
1551 (int)width
, (int)height
,
1552 dc_buffer
, 0, 0, SRCPAINT
) != 0;
1555 wxLogLastError(wxT("BitBlt"));
1558 // tidy up temporary DCs and bitmap
1559 ::SelectObject(dc_mask
, 0);
1560 ::DeleteDC(dc_mask
);
1561 ::SelectObject(dc_buffer
, 0);
1562 ::DeleteDC(dc_buffer
);
1563 ::DeleteObject(buffer_bmap
);
1566 else // no mask, just BitBlt() it
1568 success
= ::BitBlt(GetHdc(), xdest
, ydest
,
1569 (int)width
, (int)height
,
1570 GetHdcOf(*source
), xsrc
, ysrc
, dwRop
) != 0;
1573 wxLogLastError(wxT("BitBlt"));
1576 ::SetTextColor(GetHdc(), old_textground
);
1577 ::SetBkColor(GetHdc(), old_background
);
1582 void wxDC::DoGetSize(int *w
, int *h
) const
1584 if ( w
) *w
= ::GetDeviceCaps(GetHdc(), HORZRES
);
1585 if ( h
) *h
= ::GetDeviceCaps(GetHdc(), VERTRES
);
1588 void wxDC::DoGetSizeMM(int *w
, int *h
) const
1590 if ( w
) *w
= ::GetDeviceCaps(GetHdc(), HORZSIZE
);
1591 if ( h
) *h
= ::GetDeviceCaps(GetHdc(), VERTSIZE
);
1594 wxSize
wxDC::GetPPI() const
1596 int x
= ::GetDeviceCaps(GetHdc(), LOGPIXELSX
);
1597 int y
= ::GetDeviceCaps(GetHdc(), LOGPIXELSY
);
1599 return wxSize(x
, y
);
1602 // For use by wxWindows only, unless custom units are required.
1603 void wxDC::SetLogicalScale(double x
, double y
)
1605 m_logicalScaleX
= x
;
1606 m_logicalScaleY
= y
;
1609 #if WXWIN_COMPATIBILITY
1610 void wxDC::DoGetTextExtent(const wxString
& string
, float *x
, float *y
,
1611 float *descent
, float *externalLeading
,
1612 wxFont
*theFont
, bool use16bit
) const
1614 wxCoord x1
, y1
, descent1
, externalLeading1
;
1615 GetTextExtent(string
, & x1
, & y1
, & descent1
, & externalLeading1
, theFont
, use16bit
);
1618 *descent
= descent1
;
1619 if (externalLeading
)
1620 *externalLeading
= externalLeading1
;