]>
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 x
, wxCoord y
, wxCoord w
, wxCoord h
)
283 // the region coords are always the device ones, so do the translation
285 HRGN hrgn
= ::CreateRectRgn(LogicalToDeviceX(x
),
287 LogicalToDeviceX(x
+ w
),
288 LogicalToDeviceY(y
+ h
));
291 wxLogLastError(_T("CreateRectRgn"));
295 if ( ::SelectClipRgn(GetHdc(), hrgn
) == ERROR
)
297 wxLogLastError(_T("SelectClipRgn"));
300 DO_SET_CLIPPING_BOX()
304 void wxDC::DoSetClippingRegionAsRegion(const wxRegion
& region
)
306 wxCHECK_RET( region
.GetHRGN(), wxT("invalid clipping region") );
311 SelectClipRgn(GetHdc(), (HRGN
) region
.GetHRGN());
313 ExtSelectClipRgn(GetHdc(), (HRGN
) region
.GetHRGN(), RGN_AND
);
316 DO_SET_CLIPPING_BOX()
319 void wxDC::DestroyClippingRegion()
321 if (m_clipping
&& m_hDC
)
323 // TODO: this should restore the previous clipping region,
324 // so that OnPaint processing works correctly, and the update clipping region
325 // doesn't get destroyed after the first DestroyClippingRegion.
326 HRGN rgn
= CreateRectRgn(0, 0, 32000, 32000);
327 SelectClipRgn(GetHdc(), rgn
);
333 // ---------------------------------------------------------------------------
334 // query capabilities
335 // ---------------------------------------------------------------------------
337 bool wxDC::CanDrawBitmap() const
342 bool wxDC::CanGetTextExtent() const
344 // What sort of display is it?
345 int technology
= ::GetDeviceCaps(GetHdc(), TECHNOLOGY
);
347 return (technology
== DT_RASDISPLAY
) || (technology
== DT_RASPRINTER
);
350 int wxDC::GetDepth() const
352 return (int)::GetDeviceCaps(GetHdc(), BITSPIXEL
);
355 // ---------------------------------------------------------------------------
357 // ---------------------------------------------------------------------------
364 GetClientRect((HWND
) m_canvas
->GetHWND(), &rect
);
368 // No, I think we should simply ignore this if printing on e.g.
370 // wxCHECK_RET( m_selectedBitmap.Ok(), wxT("this DC can't be cleared") );
371 if (!m_selectedBitmap
.Ok())
374 rect
.left
= 0; rect
.top
= 0;
375 rect
.right
= m_selectedBitmap
.GetWidth();
376 rect
.bottom
= m_selectedBitmap
.GetHeight();
379 (void) ::SetMapMode(GetHdc(), MM_TEXT
);
381 DWORD colour
= GetBkColor(GetHdc());
382 HBRUSH brush
= CreateSolidBrush(colour
);
383 FillRect(GetHdc(), &rect
, brush
);
386 ::SetMapMode(GetHdc(), MM_ANISOTROPIC
);
387 ::SetViewportExtEx(GetHdc(), VIEWPORT_EXTENT
, VIEWPORT_EXTENT
, NULL
);
388 ::SetWindowExtEx(GetHdc(), m_windowExtX
, m_windowExtY
, NULL
);
389 ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX
, (int)m_deviceOriginY
, NULL
);
390 ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX
, (int)m_logicalOriginY
, NULL
);
393 void wxDC::DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
, int style
)
395 if ( !::ExtFloodFill(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
),
397 style
== wxFLOOD_SURFACE
? FLOODFILLSURFACE
400 // quoting from the MSDN docs:
402 // Following are some of the reasons this function might fail:
404 // * The filling could not be completed.
405 // * The specified point has the boundary color specified by the
406 // crColor parameter (if FLOODFILLBORDER was requested).
407 // * The specified point does not have the color specified by
408 // crColor (if FLOODFILLSURFACE was requested)
409 // * The point is outside the clipping region that is, it is not
410 // visible on the device.
412 wxLogLastError(wxT("ExtFloodFill"));
415 CalcBoundingBox(x
, y
);
418 bool wxDC::DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const
420 wxCHECK_MSG( col
, FALSE
, _T("NULL colour parameter in wxDC::GetPixel") );
422 // get the color of the pixel
423 COLORREF pixelcolor
= ::GetPixel(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
));
425 wxRGBToColour(*col
, pixelcolor
);
430 void wxDC::DoCrossHair(wxCoord x
, wxCoord y
)
432 wxCoord x1
= x
-VIEWPORT_EXTENT
;
433 wxCoord y1
= y
-VIEWPORT_EXTENT
;
434 wxCoord x2
= x
+VIEWPORT_EXTENT
;
435 wxCoord y2
= y
+VIEWPORT_EXTENT
;
437 (void)MoveToEx(GetHdc(), XLOG2DEV(x1
), YLOG2DEV(y
), NULL
);
438 (void)LineTo(GetHdc(), XLOG2DEV(x2
), YLOG2DEV(y
));
440 (void)MoveToEx(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y1
), NULL
);
441 (void)LineTo(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y2
));
443 CalcBoundingBox(x1
, y1
);
444 CalcBoundingBox(x2
, y2
);
447 void wxDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
449 (void)MoveToEx(GetHdc(), XLOG2DEV(x1
), YLOG2DEV(y1
), NULL
);
450 (void)LineTo(GetHdc(), XLOG2DEV(x2
), YLOG2DEV(y2
));
452 // Normalization: Windows doesn't draw the last point of the line.
453 // But apparently neither does GTK+, so we take it out again.
454 // (void)LineTo(GetHdc(), XLOG2DEV(x2) + 1, YLOG2DEV(y2));
456 CalcBoundingBox(x1
, y1
);
457 CalcBoundingBox(x2
, y2
);
460 // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
461 // and ending at (x2, y2)
462 void wxDC::DoDrawArc(wxCoord x1
, wxCoord y1
,
463 wxCoord x2
, wxCoord y2
,
464 wxCoord xc
, wxCoord yc
)
466 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
470 double radius
= (double)sqrt(dx
*dx
+dy
*dy
);
471 wxCoord r
= (wxCoord
)radius
;
473 // treat the special case of full circle separately
474 if ( x1
== x2
&& y1
== y2
)
476 DrawEllipse(xc
- r
, yc
- r
, 2*r
, 2*r
);
480 wxCoord xx1
= XLOG2DEV(x1
);
481 wxCoord yy1
= YLOG2DEV(y1
);
482 wxCoord xx2
= XLOG2DEV(x2
);
483 wxCoord yy2
= YLOG2DEV(y2
);
484 wxCoord xxc
= XLOG2DEV(xc
);
485 wxCoord yyc
= YLOG2DEV(yc
);
486 wxCoord ray
= (wxCoord
) sqrt(double((xxc
-xx1
)*(xxc
-xx1
)+(yyc
-yy1
)*(yyc
-yy1
)));
488 wxCoord xxx1
= (wxCoord
) (xxc
-ray
);
489 wxCoord yyy1
= (wxCoord
) (yyc
-ray
);
490 wxCoord xxx2
= (wxCoord
) (xxc
+ray
);
491 wxCoord yyy2
= (wxCoord
) (yyc
+ray
);
493 if ( m_brush
.Ok() && m_brush
.GetStyle() != wxTRANSPARENT
)
495 // Have to add 1 to bottom-right corner of rectangle
496 // to make semi-circles look right (crooked line otherwise).
497 // Unfortunately this is not a reliable method, depends
498 // on the size of shape.
499 // TODO: figure out why this happens!
500 Pie(GetHdc(),xxx1
,yyy1
,xxx2
+1,yyy2
+1, xx1
,yy1
,xx2
,yy2
);
504 Arc(GetHdc(),xxx1
,yyy1
,xxx2
,yyy2
, xx1
,yy1
,xx2
,yy2
);
507 CalcBoundingBox(xc
- r
, yc
- r
);
508 CalcBoundingBox(xc
+ r
, yc
+ r
);
511 void wxDC::DoDrawCheckMark(wxCoord x1
, wxCoord y1
,
512 wxCoord width
, wxCoord height
)
514 wxCoord x2
= x1
+ width
,
517 #if defined(__WIN32__) && !defined(__SC__)
524 DrawFrameControl(GetHdc(), &rect
, DFC_MENU
, DFCS_MENUCHECK
);
526 // In WIN16, draw a cross
527 HPEN blackPen
= ::CreatePen(PS_SOLID
, 1, RGB(0, 0, 0));
528 HPEN whiteBrush
= (HPEN
)::GetStockObject(WHITE_BRUSH
);
529 HPEN hPenOld
= (HPEN
)::SelectObject(GetHdc(), blackPen
);
530 HPEN hBrushOld
= (HPEN
)::SelectObject(GetHdc(), whiteBrush
);
531 ::SetROP2(GetHdc(), R2_COPYPEN
);
532 Rectangle(GetHdc(), x1
, y1
, x2
, y2
);
533 MoveTo(GetHdc(), x1
, y1
);
534 LineTo(GetHdc(), x2
, y2
);
535 MoveTo(GetHdc(), x2
, y1
);
536 LineTo(GetHdc(), x1
, y2
);
537 ::SelectObject(GetHdc(), hPenOld
);
538 ::SelectObject(GetHdc(), hBrushOld
);
539 ::DeleteObject(blackPen
);
542 CalcBoundingBox(x1
, y1
);
543 CalcBoundingBox(x2
, y2
);
546 void wxDC::DoDrawPoint(wxCoord x
, wxCoord y
)
548 COLORREF color
= 0x00ffffff;
551 color
= m_pen
.GetColour().GetPixel();
554 SetPixel(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), color
);
556 CalcBoundingBox(x
, y
);
559 void wxDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
,int fillStyle
)
561 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
563 // Do things less efficiently if we have offsets
564 if (xoffset
!= 0 || yoffset
!= 0)
566 POINT
*cpoints
= new POINT
[n
];
568 for (i
= 0; i
< n
; i
++)
570 cpoints
[i
].x
= (int)(points
[i
].x
+ xoffset
);
571 cpoints
[i
].y
= (int)(points
[i
].y
+ yoffset
);
573 CalcBoundingBox(cpoints
[i
].x
, cpoints
[i
].y
);
575 int prev
= SetPolyFillMode(GetHdc(),fillStyle
==wxODDEVEN_RULE
?ALTERNATE
:WINDING
);
576 (void)Polygon(GetHdc(), cpoints
, n
);
577 SetPolyFillMode(GetHdc(),prev
);
583 for (i
= 0; i
< n
; i
++)
584 CalcBoundingBox(points
[i
].x
, points
[i
].y
);
586 int prev
= SetPolyFillMode(GetHdc(),fillStyle
==wxODDEVEN_RULE
?ALTERNATE
:WINDING
);
587 (void)Polygon(GetHdc(), (POINT
*) points
, n
);
588 SetPolyFillMode(GetHdc(),prev
);
592 void wxDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
594 // Do things less efficiently if we have offsets
595 if (xoffset
!= 0 || yoffset
!= 0)
597 POINT
*cpoints
= new POINT
[n
];
599 for (i
= 0; i
< n
; i
++)
601 cpoints
[i
].x
= (int)(points
[i
].x
+ xoffset
);
602 cpoints
[i
].y
= (int)(points
[i
].y
+ yoffset
);
604 CalcBoundingBox(cpoints
[i
].x
, cpoints
[i
].y
);
606 (void)Polyline(GetHdc(), cpoints
, n
);
612 for (i
= 0; i
< n
; i
++)
613 CalcBoundingBox(points
[i
].x
, points
[i
].y
);
615 (void)Polyline(GetHdc(), (POINT
*) points
, n
);
619 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
621 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
623 wxCoord x2
= x
+ width
;
624 wxCoord y2
= y
+ height
;
626 if ((m_logicalFunction
== wxCOPY
) && (m_pen
.GetStyle() == wxTRANSPARENT
))
629 rect
.left
= XLOG2DEV(x
);
630 rect
.top
= YLOG2DEV(y
);
631 rect
.right
= XLOG2DEV(x2
);
632 rect
.bottom
= YLOG2DEV(y2
);
633 (void)FillRect(GetHdc(), &rect
, (HBRUSH
)m_brush
.GetResourceHandle() );
637 // Windows draws the filled rectangles without outline (i.e. drawn with a
638 // transparent pen) one pixel smaller in both directions and we want them
639 // to have the same size regardless of which pen is used - adjust
641 // I wonder if this shouldn´t be done after the LOG2DEV() conversions. RR.
642 if ( m_pen
.GetStyle() == wxTRANSPARENT
)
648 (void)Rectangle(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
));
652 CalcBoundingBox(x
, y
);
653 CalcBoundingBox(x2
, y2
);
656 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
658 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
660 // Now, a negative radius value is interpreted to mean
661 // 'the proportion of the smallest X or Y dimension'
665 double smallest
= 0.0;
670 radius
= (- radius
* smallest
);
673 wxCoord x2
= (x
+width
);
674 wxCoord y2
= (y
+height
);
676 // Windows draws the filled rectangles without outline (i.e. drawn with a
677 // transparent pen) one pixel smaller in both directions and we want them
678 // to have the same size regardless of which pen is used - adjust
679 if ( m_pen
.GetStyle() == wxTRANSPARENT
)
685 (void)RoundRect(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
),
686 YLOG2DEV(y2
), (int) (2*XLOG2DEV(radius
)), (int)( 2*YLOG2DEV(radius
)));
688 CalcBoundingBox(x
, y
);
689 CalcBoundingBox(x2
, y2
);
692 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
694 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
696 wxCoord x2
= (x
+width
);
697 wxCoord y2
= (y
+height
);
699 (void)Ellipse(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
));
701 CalcBoundingBox(x
, y
);
702 CalcBoundingBox(x2
, y2
);
705 // Chris Breeze 20/5/98: first implementation of DrawEllipticArc on Windows
706 void wxDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
708 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
713 int rx1
= XLOG2DEV(x
+w
/2);
714 int ry1
= YLOG2DEV(y
+h
/2);
721 rx1
+= (int)(100.0 * abs(w
) * cos(sa
));
722 ry1
-= (int)(100.0 * abs(h
) * m_signY
* sin(sa
));
723 rx2
+= (int)(100.0 * abs(w
) * cos(ea
));
724 ry2
-= (int)(100.0 * abs(h
) * m_signY
* sin(ea
));
726 // draw pie with NULL_PEN first and then outline otherwise a line is
727 // drawn from the start and end points to the centre
728 HPEN hpenOld
= (HPEN
) ::SelectObject(GetHdc(), (HPEN
) ::GetStockObject(NULL_PEN
));
731 (void)Pie(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
)+1, YLOG2DEV(y2
)+1,
736 (void)Pie(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
)-1, XLOG2DEV(x2
)+1, YLOG2DEV(y2
),
737 rx1
, ry1
-1, rx2
, ry2
-1);
740 ::SelectObject(GetHdc(), hpenOld
);
742 (void)Arc(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
),
745 CalcBoundingBox(x
, y
);
746 CalcBoundingBox(x2
, y2
);
749 void wxDC::DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
)
751 wxCHECK_RET( icon
.Ok(), wxT("invalid icon in DrawIcon") );
754 ::DrawIconEx(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), GetHiconOf(icon
), icon
.GetWidth(), icon
.GetHeight(), 0, NULL
, DI_NORMAL
);
756 ::DrawIcon(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), GetHiconOf(icon
));
759 CalcBoundingBox(x
, y
);
760 CalcBoundingBox(x
+ icon
.GetWidth(), y
+ icon
.GetHeight());
763 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
765 wxCHECK_RET( bmp
.Ok(), _T("invalid bitmap in wxDC::DrawBitmap") );
767 int width
= bmp
.GetWidth(),
768 height
= bmp
.GetHeight();
770 HBITMAP hbmpMask
= 0;
774 wxMask
*mask
= bmp
.GetMask();
776 hbmpMask
= (HBITMAP
)mask
->GetMaskBitmap();
780 // don't give assert here because this would break existing
781 // programs - just silently ignore useMask parameter
789 // use MaskBlt() with ROP which doesn't do anything to dst in the mask
791 // On some systems, MaskBlt succeeds yet is much much slower
792 // than the wxWindows fall-back implementation. So we need
793 // to be able to switch this on and off at runtime.
795 if (wxSystemSettings::GetOptionInt(wxT("no-maskblt")) == 0)
797 HDC hdcMem
= ::CreateCompatibleDC(GetHdc());
798 ::SelectObject(hdcMem
, GetHbitmapOf(bmp
));
800 ok
= ::MaskBlt(GetHdc(), x
, y
, width
, height
,
803 MAKEROP4(SRCCOPY
, DSTCOPY
)) != 0;
810 // Rather than reproduce wxDC::Blit, let's do it at the wxWin API
813 memDC
.SelectObject(bmp
);
815 Blit(x
, y
, width
, height
, &memDC
, 0, 0, wxCOPY
, useMask
);
817 memDC
.SelectObject(wxNullBitmap
);
820 else // no mask, just use BitBlt()
823 HDC memdc
= ::CreateCompatibleDC( cdc
);
824 HBITMAP hbitmap
= (HBITMAP
) bmp
.GetHBITMAP( );
826 wxASSERT_MSG( hbitmap
, wxT("bitmap is ok but HBITMAP is NULL?") );
828 COLORREF old_textground
= ::GetTextColor(GetHdc());
829 COLORREF old_background
= ::GetBkColor(GetHdc());
830 if (m_textForegroundColour
.Ok())
832 ::SetTextColor(GetHdc(), m_textForegroundColour
.GetPixel() );
834 if (m_textBackgroundColour
.Ok())
836 ::SetBkColor(GetHdc(), m_textBackgroundColour
.GetPixel() );
839 ::SelectObject( memdc
, hbitmap
);
840 ::BitBlt( cdc
, x
, y
, width
, height
, memdc
, 0, 0, SRCCOPY
);
843 ::SetTextColor(GetHdc(), old_textground
);
844 ::SetBkColor(GetHdc(), old_background
);
848 void wxDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
850 DrawAnyText(text
, x
, y
);
852 // update the bounding box
853 CalcBoundingBox(x
, y
);
856 GetTextExtent(text
, &w
, &h
);
857 CalcBoundingBox(x
+ w
, y
+ h
);
860 void wxDC::DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
)
862 // prepare for drawing the text
863 if ( m_textForegroundColour
.Ok() )
864 SetTextColor(GetHdc(), m_textForegroundColour
.GetPixel());
866 DWORD old_background
= 0;
867 if ( m_textBackgroundColour
.Ok() )
869 old_background
= SetBkColor(GetHdc(), m_textBackgroundColour
.GetPixel() );
872 SetBkMode(GetHdc(), m_backgroundMode
== wxTRANSPARENT
? TRANSPARENT
875 if ( ::TextOut(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
),
876 text
.c_str(), text
.length()) == 0 )
878 wxLogLastError(wxT("TextOut"));
881 // restore the old parameters (text foreground colour may be left because
882 // it never is set to anything else, but background should remain
883 // transparent even if we just drew an opaque string)
884 if ( m_textBackgroundColour
.Ok() )
885 (void)SetBkColor(GetHdc(), old_background
);
887 SetBkMode(GetHdc(), TRANSPARENT
);
890 void wxDC::DoDrawRotatedText(const wxString
& text
,
891 wxCoord x
, wxCoord y
,
894 // we test that we have some font because otherwise we should still use the
895 // "else" part below to avoid that DrawRotatedText(angle = 180) and
896 // DrawRotatedText(angle = 0) use different fonts (we can't use the default
897 // font for drawing rotated fonts unfortunately)
898 if ( (angle
== 0.0) && m_font
.Ok() )
900 DoDrawText(text
, x
, y
);
904 // NB: don't take DEFAULT_GUI_FONT because it's not TrueType and so
905 // can't have non zero orientation/escapement
906 wxFont font
= m_font
.Ok() ? m_font
: *wxNORMAL_FONT
;
907 HFONT hfont
= (HFONT
)font
.GetResourceHandle();
909 if ( ::GetObject(hfont
, sizeof(lf
), &lf
) == 0 )
911 wxLogLastError(wxT("GetObject(hfont)"));
914 // GDI wants the angle in tenth of degree
915 long angle10
= (long)(angle
* 10);
916 lf
.lfEscapement
= angle10
;
917 lf
. lfOrientation
= angle10
;
919 hfont
= ::CreateFontIndirect(&lf
);
922 wxLogLastError(wxT("CreateFont"));
926 HFONT hfontOld
= (HFONT
)::SelectObject(GetHdc(), hfont
);
928 DrawAnyText(text
, x
, y
);
930 (void)::SelectObject(GetHdc(), hfontOld
);
931 (void)::DeleteObject(hfont
);
934 // call the bounding box by adding all four vertices of the rectangle
935 // containing the text to it (simpler and probably not slower than
936 // determining which of them is really topmost/leftmost/...)
938 GetTextExtent(text
, &w
, &h
);
940 double rad
= DegToRad(angle
);
942 // "upper left" and "upper right"
943 CalcBoundingBox(x
, y
);
944 CalcBoundingBox(x
+ w
*cos(rad
), y
- h
*sin(rad
));
946 // "bottom left" and "bottom right"
947 x
+= (wxCoord
)(h
*sin(rad
));
948 y
+= (wxCoord
)(h
*cos(rad
));
949 CalcBoundingBox(x
, y
);
950 CalcBoundingBox(x
+ h
*sin(rad
), y
+ h
*cos(rad
));
954 // ---------------------------------------------------------------------------
956 // ---------------------------------------------------------------------------
958 void wxDC::SetPalette(const wxPalette
& palette
)
960 // Set the old object temporarily, in case the assignment deletes an object
961 // that's not yet selected out.
964 ::SelectPalette(GetHdc(), (HPALETTE
) m_oldPalette
, TRUE
);
972 // Setting a NULL colourmap is a way of restoring
973 // the original colourmap
976 ::SelectPalette(GetHdc(), (HPALETTE
) m_oldPalette
, TRUE
);
983 if (m_palette
.Ok() && m_palette
.GetHPALETTE())
985 HPALETTE oldPal
= ::SelectPalette(GetHdc(), (HPALETTE
) m_palette
.GetHPALETTE(), TRUE
);
987 m_oldPalette
= (WXHPALETTE
) oldPal
;
989 ::RealizePalette(GetHdc());
993 void wxDC::SetFont(const wxFont
& the_font
)
995 // Set the old object temporarily, in case the assignment deletes an object
996 // that's not yet selected out.
999 ::SelectObject(GetHdc(), (HFONT
) m_oldFont
);
1008 ::SelectObject(GetHdc(), (HFONT
) m_oldFont
);
1012 if (m_font
.Ok() && m_font
.GetResourceHandle())
1014 HFONT f
= (HFONT
) ::SelectObject(GetHdc(), (HFONT
) m_font
.GetResourceHandle());
1015 if (f
== (HFONT
) NULL
)
1017 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
1020 m_oldFont
= (WXHFONT
) f
;
1024 void wxDC::SetPen(const wxPen
& pen
)
1026 // Set the old object temporarily, in case the assignment deletes an object
1027 // that's not yet selected out.
1030 ::SelectObject(GetHdc(), (HPEN
) m_oldPen
);
1039 ::SelectObject(GetHdc(), (HPEN
) m_oldPen
);
1045 if (m_pen
.GetResourceHandle())
1047 HPEN p
= (HPEN
) ::SelectObject(GetHdc(), (HPEN
)m_pen
.GetResourceHandle());
1049 m_oldPen
= (WXHPEN
) p
;
1054 void wxDC::SetBrush(const wxBrush
& brush
)
1056 // Set the old object temporarily, in case the assignment deletes an object
1057 // that's not yet selected out.
1060 ::SelectObject(GetHdc(), (HBRUSH
) m_oldBrush
);
1069 ::SelectObject(GetHdc(), (HBRUSH
) m_oldBrush
);
1075 // to make sure the brush is alligned with the logical coordinates
1076 wxBitmap
*stipple
= m_brush
.GetStipple();
1077 if ( stipple
&& stipple
->Ok() )
1080 ::SetBrushOrgEx(GetHdc(),
1081 m_deviceOriginX
% stipple
->GetWidth(),
1082 m_deviceOriginY
% stipple
->GetHeight(),
1083 NULL
); // don't need previous brush origin
1085 ::SetBrushOrg(GetHdc(),
1086 m_deviceOriginX
% stipple
->GetWidth(),
1087 m_deviceOriginY
% stipple
->GetHeight());
1091 if ( m_brush
.GetResourceHandle() )
1094 b
= (HBRUSH
) ::SelectObject(GetHdc(), (HBRUSH
)m_brush
.GetResourceHandle());
1096 m_oldBrush
= (WXHBRUSH
) b
;
1101 void wxDC::SetBackground(const wxBrush
& brush
)
1103 m_backgroundBrush
= brush
;
1105 if (!m_backgroundBrush
.Ok())
1110 bool customColours
= TRUE
;
1111 // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
1112 // change background colours from the control-panel specified colours.
1113 if (m_canvas
->IsKindOf(CLASSINFO(wxWindow
)) && ((m_canvas
->GetWindowStyleFlag() & wxUSER_COLOURS
) != wxUSER_COLOURS
))
1114 customColours
= FALSE
;
1118 if (m_backgroundBrush
.GetStyle()==wxTRANSPARENT
)
1120 m_canvas
->SetTransparent(TRUE
);
1124 // New behaviour, 10/2/99: setting the background brush of a DC
1125 // doesn't affect the window background colour. However,
1126 // I'm leaving in the transparency setting because it's needed by
1127 // various controls (e.g. wxStaticText) to determine whether to draw
1128 // transparently or not. TODO: maybe this should be a new function
1129 // wxWindow::SetTransparency(). Should that apply to the child itself, or the
1131 // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour());
1132 m_canvas
->SetTransparent(FALSE
);
1136 COLORREF new_color
= m_backgroundBrush
.GetColour().GetPixel();
1138 (void)SetBkColor(GetHdc(), new_color
);
1142 void wxDC::SetBackgroundMode(int mode
)
1144 m_backgroundMode
= mode
;
1146 // SetBackgroundColour now only refers to text background
1147 // and m_backgroundMode is used there
1150 if (m_backgroundMode == wxTRANSPARENT)
1151 ::SetBkMode(GetHdc(), TRANSPARENT);
1153 ::SetBkMode(GetHdc(), OPAQUE);
1154 Last change: AC 29 Jan 101 8:54 pm
1158 void wxDC::SetLogicalFunction(int function
)
1160 m_logicalFunction
= function
;
1165 void wxDC::SetRop(WXHDC dc
)
1167 if ( !dc
|| m_logicalFunction
< 0 )
1172 switch (m_logicalFunction
)
1174 case wxCLEAR
: rop
= R2_BLACK
; break;
1175 case wxXOR
: rop
= R2_XORPEN
; break;
1176 case wxINVERT
: rop
= R2_NOT
; break;
1177 case wxOR_REVERSE
: rop
= R2_MERGEPENNOT
; break;
1178 case wxAND_REVERSE
: rop
= R2_MASKPENNOT
; break;
1179 case wxCOPY
: rop
= R2_COPYPEN
; break;
1180 case wxAND
: rop
= R2_MASKPEN
; break;
1181 case wxAND_INVERT
: rop
= R2_MASKNOTPEN
; break;
1182 case wxNO_OP
: rop
= R2_NOP
; break;
1183 case wxNOR
: rop
= R2_NOTMERGEPEN
; break;
1184 case wxEQUIV
: rop
= R2_NOTXORPEN
; break;
1185 case wxSRC_INVERT
: rop
= R2_NOTCOPYPEN
; break;
1186 case wxOR_INVERT
: rop
= R2_MERGENOTPEN
; break;
1187 case wxNAND
: rop
= R2_NOTMASKPEN
; break;
1188 case wxOR
: rop
= R2_MERGEPEN
; break;
1189 case wxSET
: rop
= R2_WHITE
; break;
1192 wxFAIL_MSG( wxT("unsupported logical function") );
1196 SetROP2(GetHdc(), rop
);
1199 bool wxDC::StartDoc(const wxString
& WXUNUSED(message
))
1201 // We might be previewing, so return TRUE to let it continue.
1209 void wxDC::StartPage()
1213 void wxDC::EndPage()
1217 // ---------------------------------------------------------------------------
1219 // ---------------------------------------------------------------------------
1221 wxCoord
wxDC::GetCharHeight() const
1223 TEXTMETRIC lpTextMetric
;
1225 GetTextMetrics(GetHdc(), &lpTextMetric
);
1227 return YDEV2LOGREL(lpTextMetric
.tmHeight
);
1230 wxCoord
wxDC::GetCharWidth() const
1232 TEXTMETRIC lpTextMetric
;
1234 GetTextMetrics(GetHdc(), &lpTextMetric
);
1236 return XDEV2LOGREL(lpTextMetric
.tmAveCharWidth
);
1239 void wxDC::DoGetTextExtent(const wxString
& string
, wxCoord
*x
, wxCoord
*y
,
1240 wxCoord
*descent
, wxCoord
*externalLeading
,
1246 wxASSERT_MSG( font
->Ok(), _T("invalid font in wxDC::GetTextExtent") );
1248 hfontOld
= (HFONT
)::SelectObject(GetHdc(), GetHfontOf(*font
));
1250 else // don't change the font
1258 GetTextExtentPoint(GetHdc(), string
, string
.length(), &sizeRect
);
1259 GetTextMetrics(GetHdc(), &tm
);
1261 if (x
) *x
= XDEV2LOGREL(sizeRect
.cx
);
1262 if (y
) *y
= YDEV2LOGREL(sizeRect
.cy
);
1263 if (descent
) *descent
= tm
.tmDescent
;
1264 if (externalLeading
) *externalLeading
= tm
.tmExternalLeading
;
1268 ::SelectObject(GetHdc(), hfontOld
);
1272 void wxDC::SetMapMode(int mode
)
1274 m_mappingMode
= mode
;
1276 int pixel_width
= 0;
1277 int pixel_height
= 0;
1281 pixel_width
= GetDeviceCaps(GetHdc(), HORZRES
);
1282 pixel_height
= GetDeviceCaps(GetHdc(), VERTRES
);
1283 mm_width
= GetDeviceCaps(GetHdc(), HORZSIZE
);
1284 mm_height
= GetDeviceCaps(GetHdc(), VERTSIZE
);
1286 if ((pixel_width
== 0) || (pixel_height
== 0) || (mm_width
== 0) || (mm_height
== 0))
1291 double mm2pixelsX
= pixel_width
/mm_width
;
1292 double mm2pixelsY
= pixel_height
/mm_height
;
1298 m_logicalScaleX
= (twips2mm
* mm2pixelsX
);
1299 m_logicalScaleY
= (twips2mm
* mm2pixelsY
);
1304 m_logicalScaleX
= (pt2mm
* mm2pixelsX
);
1305 m_logicalScaleY
= (pt2mm
* mm2pixelsY
);
1310 m_logicalScaleX
= mm2pixelsX
;
1311 m_logicalScaleY
= mm2pixelsY
;
1316 m_logicalScaleX
= (mm2pixelsX
/10.0);
1317 m_logicalScaleY
= (mm2pixelsY
/10.0);
1323 m_logicalScaleX
= 1.0;
1324 m_logicalScaleY
= 1.0;
1329 if (::GetMapMode(GetHdc()) != MM_ANISOTROPIC
)
1330 ::SetMapMode(GetHdc(), MM_ANISOTROPIC
);
1332 SetViewportExtEx(GetHdc(), VIEWPORT_EXTENT
, VIEWPORT_EXTENT
, NULL
);
1333 m_windowExtX
= (int)MS_XDEV2LOGREL(VIEWPORT_EXTENT
);
1334 m_windowExtY
= (int)MS_YDEV2LOGREL(VIEWPORT_EXTENT
);
1335 ::SetWindowExtEx(GetHdc(), m_windowExtX
, m_windowExtY
, NULL
);
1336 ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX
, (int)m_deviceOriginY
, NULL
);
1337 ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX
, (int)m_logicalOriginY
, NULL
);
1340 void wxDC::SetUserScale(double x
, double y
)
1345 SetMapMode(m_mappingMode
);
1348 void wxDC::SetAxisOrientation(bool xLeftRight
, bool yBottomUp
)
1350 m_signX
= xLeftRight
? 1 : -1;
1351 m_signY
= yBottomUp
? -1 : 1;
1353 SetMapMode(m_mappingMode
);
1356 void wxDC::SetSystemScale(double x
, double y
)
1361 SetMapMode(m_mappingMode
);
1364 void wxDC::SetLogicalOrigin(wxCoord x
, wxCoord y
)
1366 m_logicalOriginX
= x
;
1367 m_logicalOriginY
= y
;
1369 ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX
, (int)m_logicalOriginY
, NULL
);
1372 void wxDC::SetDeviceOrigin(wxCoord x
, wxCoord y
)
1374 m_deviceOriginX
= x
;
1375 m_deviceOriginY
= y
;
1377 ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX
, (int)m_deviceOriginY
, NULL
);
1380 // ---------------------------------------------------------------------------
1381 // coordinates transformations
1382 // ---------------------------------------------------------------------------
1384 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
1386 double xRel
= x
- m_deviceOriginX
;
1387 xRel
/= m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
;
1388 return (wxCoord
)(xRel
+ m_logicalOriginX
);
1391 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
1393 return (wxCoord
) ((x
)/(m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
));
1396 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
1398 double yRel
= y
- m_deviceOriginY
;
1399 yRel
/= m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
;
1400 return (wxCoord
)(yRel
+ m_logicalOriginY
);
1403 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
1405 return (wxCoord
) ((y
)/(m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
));
1408 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
1410 return (wxCoord
) ((x
- m_logicalOriginX
)*m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
+ m_deviceOriginX
);
1413 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
1415 return (wxCoord
) (x
*m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
);
1418 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
1420 return (wxCoord
) ((y
- m_logicalOriginY
)*m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
+ m_deviceOriginY
);
1423 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
1425 return (wxCoord
) (y
*m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
);
1428 // ---------------------------------------------------------------------------
1430 // ---------------------------------------------------------------------------
1432 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
,
1433 wxCoord width
, wxCoord height
,
1434 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
1435 int rop
, bool useMask
)
1437 wxMask
*mask
= NULL
;
1440 const wxBitmap
& bmp
= source
->m_selectedBitmap
;
1441 mask
= bmp
.GetMask();
1443 if ( !(bmp
.Ok() && mask
&& mask
->GetMaskBitmap()) )
1445 // don't give assert here because this would break existing
1446 // programs - just silently ignore useMask parameter
1451 COLORREF old_textground
= ::GetTextColor(GetHdc());
1452 COLORREF old_background
= ::GetBkColor(GetHdc());
1453 if (m_textForegroundColour
.Ok())
1455 ::SetTextColor(GetHdc(), m_textForegroundColour
.GetPixel() );
1457 if (m_textBackgroundColour
.Ok())
1459 ::SetBkColor(GetHdc(), m_textBackgroundColour
.GetPixel() );
1462 DWORD dwRop
= SRCCOPY
;
1465 case wxXOR
: dwRop
= SRCINVERT
; break;
1466 case wxINVERT
: dwRop
= DSTINVERT
; break;
1467 case wxOR_REVERSE
: dwRop
= 0x00DD0228; break;
1468 case wxAND_REVERSE
: dwRop
= SRCERASE
; break;
1469 case wxCLEAR
: dwRop
= BLACKNESS
; break;
1470 case wxSET
: dwRop
= WHITENESS
; break;
1471 case wxOR_INVERT
: dwRop
= MERGEPAINT
; break;
1472 case wxAND
: dwRop
= SRCAND
; break;
1473 case wxOR
: dwRop
= SRCPAINT
; break;
1474 case wxEQUIV
: dwRop
= 0x00990066; break;
1475 case wxNAND
: dwRop
= 0x007700E6; break;
1476 case wxAND_INVERT
: dwRop
= 0x00220326; break;
1477 case wxCOPY
: dwRop
= SRCCOPY
; break;
1478 case wxNO_OP
: dwRop
= DSTCOPY
; break;
1479 case wxSRC_INVERT
: dwRop
= NOTSRCCOPY
; break;
1480 case wxNOR
: dwRop
= NOTSRCCOPY
; break;
1482 wxFAIL_MSG( wxT("unsupported logical function") );
1486 bool success
= FALSE
;
1491 // we want the part of the image corresponding to the mask to be
1492 // transparent, so use "DSTCOPY" ROP for the mask points (the usual
1493 // meaning of fg and bg is inverted which corresponds to wxWin notion
1494 // of the mask which is also contrary to the Windows one)
1496 // On some systems, MaskBlt succeeds yet is much much slower
1497 // than the wxWindows fall-back implementation. So we need
1498 // to be able to switch this on and off at runtime.
1499 if (wxSystemSettings::GetOptionInt(wxT("no-maskblt")) == 0)
1501 success
= ::MaskBlt(GetHdc(), xdest
, ydest
, width
, height
,
1502 GetHdcOf(*source
), xsrc
, ysrc
,
1503 (HBITMAP
)mask
->GetMaskBitmap(), xsrc
, ysrc
,
1504 MAKEROP4(dwRop
, DSTCOPY
)) != 0;
1510 // Blit bitmap with mask
1512 // create a temp buffer bitmap and DCs to access it and the mask
1513 HDC dc_mask
= ::CreateCompatibleDC(GetHdcOf(*source
));
1514 HDC dc_buffer
= ::CreateCompatibleDC(GetHdc());
1515 HBITMAP buffer_bmap
= ::CreateCompatibleBitmap(GetHdc(), width
, height
);
1516 ::SelectObject(dc_mask
, (HBITMAP
) mask
->GetMaskBitmap());
1517 ::SelectObject(dc_buffer
, buffer_bmap
);
1519 // copy dest to buffer
1520 if ( !::BitBlt(dc_buffer
, 0, 0, (int)width
, (int)height
,
1521 GetHdc(), xdest
, ydest
, SRCCOPY
) )
1523 wxLogLastError(wxT("BitBlt"));
1526 // copy src to buffer using selected raster op
1527 if ( !::BitBlt(dc_buffer
, 0, 0, (int)width
, (int)height
,
1528 GetHdcOf(*source
), xsrc
, ysrc
, dwRop
) )
1530 wxLogLastError(wxT("BitBlt"));
1533 // set masked area in buffer to BLACK (pixel value 0)
1534 COLORREF prevBkCol
= ::SetBkColor(GetHdc(), RGB(255, 255, 255));
1535 COLORREF prevCol
= ::SetTextColor(GetHdc(), RGB(0, 0, 0));
1536 if ( !::BitBlt(dc_buffer
, 0, 0, (int)width
, (int)height
,
1537 dc_mask
, xsrc
, ysrc
, SRCAND
) )
1539 wxLogLastError(wxT("BitBlt"));
1542 // set unmasked area in dest to BLACK
1543 ::SetBkColor(GetHdc(), RGB(0, 0, 0));
1544 ::SetTextColor(GetHdc(), RGB(255, 255, 255));
1545 if ( !::BitBlt(GetHdc(), xdest
, ydest
, (int)width
, (int)height
,
1546 dc_mask
, xsrc
, ysrc
, SRCAND
) )
1548 wxLogLastError(wxT("BitBlt"));
1550 ::SetBkColor(GetHdc(), prevBkCol
); // restore colours to original values
1551 ::SetTextColor(GetHdc(), prevCol
);
1553 // OR buffer to dest
1554 success
= ::BitBlt(GetHdc(), xdest
, ydest
,
1555 (int)width
, (int)height
,
1556 dc_buffer
, 0, 0, SRCPAINT
) != 0;
1559 wxLogLastError(wxT("BitBlt"));
1562 // tidy up temporary DCs and bitmap
1563 ::SelectObject(dc_mask
, 0);
1564 ::DeleteDC(dc_mask
);
1565 ::SelectObject(dc_buffer
, 0);
1566 ::DeleteDC(dc_buffer
);
1567 ::DeleteObject(buffer_bmap
);
1570 else // no mask, just BitBlt() it
1572 success
= ::BitBlt(GetHdc(), xdest
, ydest
,
1573 (int)width
, (int)height
,
1574 GetHdcOf(*source
), xsrc
, ysrc
, dwRop
) != 0;
1577 wxLogLastError(wxT("BitBlt"));
1580 ::SetTextColor(GetHdc(), old_textground
);
1581 ::SetBkColor(GetHdc(), old_background
);
1586 void wxDC::DoGetSize(int *w
, int *h
) const
1588 if ( w
) *w
= ::GetDeviceCaps(GetHdc(), HORZRES
);
1589 if ( h
) *h
= ::GetDeviceCaps(GetHdc(), VERTRES
);
1592 void wxDC::DoGetSizeMM(int *w
, int *h
) const
1594 if ( w
) *w
= ::GetDeviceCaps(GetHdc(), HORZSIZE
);
1595 if ( h
) *h
= ::GetDeviceCaps(GetHdc(), VERTSIZE
);
1598 wxSize
wxDC::GetPPI() const
1600 int x
= ::GetDeviceCaps(GetHdc(), LOGPIXELSX
);
1601 int y
= ::GetDeviceCaps(GetHdc(), LOGPIXELSY
);
1603 return wxSize(x
, y
);
1606 // For use by wxWindows only, unless custom units are required.
1607 void wxDC::SetLogicalScale(double x
, double y
)
1609 m_logicalScaleX
= x
;
1610 m_logicalScaleY
= y
;
1613 #if WXWIN_COMPATIBILITY
1614 void wxDC::DoGetTextExtent(const wxString
& string
, float *x
, float *y
,
1615 float *descent
, float *externalLeading
,
1616 wxFont
*theFont
, bool use16bit
) const
1618 wxCoord x1
, y1
, descent1
, externalLeading1
;
1619 GetTextExtent(string
, & x1
, & y1
, & descent1
, & externalLeading1
, theFont
, use16bit
);
1622 *descent
= descent1
;
1623 if (externalLeading
)
1624 *externalLeading
= externalLeading1
;