]>
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
203 // this is not supposed to happen as we can't free the HDC then
204 wxCHECK_RET( m_canvas
, _T("no canvas in not owning ~wxDC?") );
206 ::ReleaseDC(GetHwndOf(m_canvas
), GetHdc());
211 // This will select current objects out of the DC,
212 // which is what you have to do before deleting the
214 void wxDC::SelectOldObjects(WXHDC dc
)
220 ::SelectObject((HDC
) dc
, (HBITMAP
) m_oldBitmap
);
221 if (m_selectedBitmap
.Ok())
223 m_selectedBitmap
.SetSelectedInto(NULL
);
229 ::SelectObject((HDC
) dc
, (HPEN
) m_oldPen
);
234 ::SelectObject((HDC
) dc
, (HBRUSH
) m_oldBrush
);
239 ::SelectObject((HDC
) dc
, (HFONT
) m_oldFont
);
244 ::SelectPalette((HDC
) dc
, (HPALETTE
) m_oldPalette
, TRUE
);
249 m_brush
= wxNullBrush
;
251 m_palette
= wxNullPalette
;
253 m_backgroundBrush
= wxNullBrush
;
254 m_selectedBitmap
= wxNullBitmap
;
257 // ---------------------------------------------------------------------------
259 // ---------------------------------------------------------------------------
261 #define DO_SET_CLIPPING_BOX() \
265 GetClipBox(GetHdc(), &rect); \
267 m_clipX1 = (wxCoord) XDEV2LOG(rect.left); \
268 m_clipY1 = (wxCoord) YDEV2LOG(rect.top); \
269 m_clipX2 = (wxCoord) XDEV2LOG(rect.right); \
270 m_clipY2 = (wxCoord) YDEV2LOG(rect.bottom); \
273 void wxDC::DoSetClippingRegion(wxCoord cx
, wxCoord cy
, wxCoord cw
, wxCoord ch
)
276 IntersectClipRect(GetHdc(), XLOG2DEV(cx
), YLOG2DEV(cy
),
277 XLOG2DEV(cx
+ cw
), YLOG2DEV(cy
+ ch
));
278 DO_SET_CLIPPING_BOX()
281 void wxDC::DoSetClippingRegionAsRegion(const wxRegion
& region
)
283 wxCHECK_RET( region
.GetHRGN(), wxT("invalid clipping region") );
288 SelectClipRgn(GetHdc(), (HRGN
) region
.GetHRGN());
290 ExtSelectClipRgn(GetHdc(), (HRGN
) region
.GetHRGN(), RGN_AND
);
293 DO_SET_CLIPPING_BOX()
296 void wxDC::DestroyClippingRegion()
298 if (m_clipping
&& m_hDC
)
300 // TODO: this should restore the previous clipping region,
301 // so that OnPaint processing works correctly, and the update clipping region
302 // doesn't get destroyed after the first DestroyClippingRegion.
303 HRGN rgn
= CreateRectRgn(0, 0, 32000, 32000);
304 SelectClipRgn(GetHdc(), rgn
);
310 // ---------------------------------------------------------------------------
311 // query capabilities
312 // ---------------------------------------------------------------------------
314 bool wxDC::CanDrawBitmap() const
319 bool wxDC::CanGetTextExtent() const
321 // What sort of display is it?
322 int technology
= ::GetDeviceCaps(GetHdc(), TECHNOLOGY
);
324 return (technology
== DT_RASDISPLAY
) || (technology
== DT_RASPRINTER
);
327 int wxDC::GetDepth() const
329 return (int)::GetDeviceCaps(GetHdc(), BITSPIXEL
);
332 // ---------------------------------------------------------------------------
334 // ---------------------------------------------------------------------------
341 GetClientRect((HWND
) m_canvas
->GetHWND(), &rect
);
345 // No, I think we should simply ignore this if printing on e.g.
347 // wxCHECK_RET( m_selectedBitmap.Ok(), wxT("this DC can't be cleared") );
348 if (!m_selectedBitmap
.Ok())
351 rect
.left
= 0; rect
.top
= 0;
352 rect
.right
= m_selectedBitmap
.GetWidth();
353 rect
.bottom
= m_selectedBitmap
.GetHeight();
356 (void) ::SetMapMode(GetHdc(), MM_TEXT
);
358 DWORD colour
= GetBkColor(GetHdc());
359 HBRUSH brush
= CreateSolidBrush(colour
);
360 FillRect(GetHdc(), &rect
, brush
);
363 ::SetMapMode(GetHdc(), MM_ANISOTROPIC
);
364 ::SetViewportExtEx(GetHdc(), VIEWPORT_EXTENT
, VIEWPORT_EXTENT
, NULL
);
365 ::SetWindowExtEx(GetHdc(), m_windowExtX
, m_windowExtY
, NULL
);
366 ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX
, (int)m_deviceOriginY
, NULL
);
367 ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX
, (int)m_logicalOriginY
, NULL
);
370 void wxDC::DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
, int style
)
372 if ( !::ExtFloodFill(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
),
374 style
== wxFLOOD_SURFACE
? FLOODFILLSURFACE
377 // quoting from the MSDN docs:
379 // Following are some of the reasons this function might fail:
381 // * The filling could not be completed.
382 // * The specified point has the boundary color specified by the
383 // crColor parameter (if FLOODFILLBORDER was requested).
384 // * The specified point does not have the color specified by
385 // crColor (if FLOODFILLSURFACE was requested)
386 // * The point is outside the clipping region that is, it is not
387 // visible on the device.
389 wxLogLastError(wxT("ExtFloodFill"));
392 CalcBoundingBox(x
, y
);
395 bool wxDC::DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const
397 wxCHECK_MSG( col
, FALSE
, _T("NULL colour parameter in wxDC::GetPixel") );
399 // get the color of the pixel
400 COLORREF pixelcolor
= ::GetPixel(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
));
402 wxRGBToColour(*col
, pixelcolor
);
407 void wxDC::DoCrossHair(wxCoord x
, wxCoord y
)
409 wxCoord x1
= x
-VIEWPORT_EXTENT
;
410 wxCoord y1
= y
-VIEWPORT_EXTENT
;
411 wxCoord x2
= x
+VIEWPORT_EXTENT
;
412 wxCoord y2
= y
+VIEWPORT_EXTENT
;
414 (void)MoveToEx(GetHdc(), XLOG2DEV(x1
), YLOG2DEV(y
), NULL
);
415 (void)LineTo(GetHdc(), XLOG2DEV(x2
), YLOG2DEV(y
));
417 (void)MoveToEx(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y1
), NULL
);
418 (void)LineTo(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y2
));
420 CalcBoundingBox(x1
, y1
);
421 CalcBoundingBox(x2
, y2
);
424 void wxDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
426 (void)MoveToEx(GetHdc(), XLOG2DEV(x1
), YLOG2DEV(y1
), NULL
);
427 (void)LineTo(GetHdc(), XLOG2DEV(x2
), YLOG2DEV(y2
));
429 // Normalization: Windows doesn't draw the last point of the line.
430 // But apparently neither does GTK+, so we take it out again.
431 // (void)LineTo(GetHdc(), XLOG2DEV(x2) + 1, YLOG2DEV(y2));
433 CalcBoundingBox(x1
, y1
);
434 CalcBoundingBox(x2
, y2
);
437 // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
438 // and ending at (x2, y2)
439 void wxDC::DoDrawArc(wxCoord x1
, wxCoord y1
,
440 wxCoord x2
, wxCoord y2
,
441 wxCoord xc
, wxCoord yc
)
443 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
447 double radius
= (double)sqrt(dx
*dx
+dy
*dy
);
448 wxCoord r
= (wxCoord
)radius
;
450 // treat the special case of full circle separately
451 if ( x1
== x2
&& y1
== y2
)
453 DrawEllipse(xc
- r
, yc
- r
, 2*r
, 2*r
);
457 wxCoord xx1
= XLOG2DEV(x1
);
458 wxCoord yy1
= YLOG2DEV(y1
);
459 wxCoord xx2
= XLOG2DEV(x2
);
460 wxCoord yy2
= YLOG2DEV(y2
);
461 wxCoord xxc
= XLOG2DEV(xc
);
462 wxCoord yyc
= YLOG2DEV(yc
);
463 wxCoord ray
= (wxCoord
) sqrt(double((xxc
-xx1
)*(xxc
-xx1
)+(yyc
-yy1
)*(yyc
-yy1
)));
465 wxCoord xxx1
= (wxCoord
) (xxc
-ray
);
466 wxCoord yyy1
= (wxCoord
) (yyc
-ray
);
467 wxCoord xxx2
= (wxCoord
) (xxc
+ray
);
468 wxCoord yyy2
= (wxCoord
) (yyc
+ray
);
470 if ( m_brush
.Ok() && m_brush
.GetStyle() != wxTRANSPARENT
)
472 // Have to add 1 to bottom-right corner of rectangle
473 // to make semi-circles look right (crooked line otherwise).
474 // Unfortunately this is not a reliable method, depends
475 // on the size of shape.
476 // TODO: figure out why this happens!
477 Pie(GetHdc(),xxx1
,yyy1
,xxx2
+1,yyy2
+1, xx1
,yy1
,xx2
,yy2
);
481 Arc(GetHdc(),xxx1
,yyy1
,xxx2
,yyy2
, xx1
,yy1
,xx2
,yy2
);
484 CalcBoundingBox(xc
- r
, yc
- r
);
485 CalcBoundingBox(xc
+ r
, yc
+ r
);
488 void wxDC::DoDrawCheckMark(wxCoord x1
, wxCoord y1
,
489 wxCoord width
, wxCoord height
)
491 wxCoord x2
= x1
+ width
,
494 #if defined(__WIN32__) && !defined(__SC__)
501 DrawFrameControl(GetHdc(), &rect
, DFC_MENU
, DFCS_MENUCHECK
);
503 // In WIN16, draw a cross
504 HPEN blackPen
= ::CreatePen(PS_SOLID
, 1, RGB(0, 0, 0));
505 HPEN whiteBrush
= (HPEN
)::GetStockObject(WHITE_BRUSH
);
506 HPEN hPenOld
= (HPEN
)::SelectObject(GetHdc(), blackPen
);
507 HPEN hBrushOld
= (HPEN
)::SelectObject(GetHdc(), whiteBrush
);
508 ::SetROP2(GetHdc(), R2_COPYPEN
);
509 Rectangle(GetHdc(), x1
, y1
, x2
, y2
);
510 MoveTo(GetHdc(), x1
, y1
);
511 LineTo(GetHdc(), x2
, y2
);
512 MoveTo(GetHdc(), x2
, y1
);
513 LineTo(GetHdc(), x1
, y2
);
514 ::SelectObject(GetHdc(), hPenOld
);
515 ::SelectObject(GetHdc(), hBrushOld
);
516 ::DeleteObject(blackPen
);
519 CalcBoundingBox(x1
, y1
);
520 CalcBoundingBox(x2
, y2
);
523 void wxDC::DoDrawPoint(wxCoord x
, wxCoord y
)
525 COLORREF color
= 0x00ffffff;
528 color
= m_pen
.GetColour().GetPixel();
531 SetPixel(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), color
);
533 CalcBoundingBox(x
, y
);
536 void wxDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
,int fillStyle
)
538 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
540 // Do things less efficiently if we have offsets
541 if (xoffset
!= 0 || yoffset
!= 0)
543 POINT
*cpoints
= new POINT
[n
];
545 for (i
= 0; i
< n
; i
++)
547 cpoints
[i
].x
= (int)(points
[i
].x
+ xoffset
);
548 cpoints
[i
].y
= (int)(points
[i
].y
+ yoffset
);
550 CalcBoundingBox(cpoints
[i
].x
, cpoints
[i
].y
);
552 int prev
= SetPolyFillMode(GetHdc(),fillStyle
==wxODDEVEN_RULE
?ALTERNATE
:WINDING
);
553 (void)Polygon(GetHdc(), cpoints
, n
);
554 SetPolyFillMode(GetHdc(),prev
);
560 for (i
= 0; i
< n
; i
++)
561 CalcBoundingBox(points
[i
].x
, points
[i
].y
);
563 int prev
= SetPolyFillMode(GetHdc(),fillStyle
==wxODDEVEN_RULE
?ALTERNATE
:WINDING
);
564 (void)Polygon(GetHdc(), (POINT
*) points
, n
);
565 SetPolyFillMode(GetHdc(),prev
);
569 void wxDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
571 // Do things less efficiently if we have offsets
572 if (xoffset
!= 0 || yoffset
!= 0)
574 POINT
*cpoints
= new POINT
[n
];
576 for (i
= 0; i
< n
; i
++)
578 cpoints
[i
].x
= (int)(points
[i
].x
+ xoffset
);
579 cpoints
[i
].y
= (int)(points
[i
].y
+ yoffset
);
581 CalcBoundingBox(cpoints
[i
].x
, cpoints
[i
].y
);
583 (void)Polyline(GetHdc(), cpoints
, n
);
589 for (i
= 0; i
< n
; i
++)
590 CalcBoundingBox(points
[i
].x
, points
[i
].y
);
592 (void)Polyline(GetHdc(), (POINT
*) points
, n
);
596 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
598 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
600 wxCoord x2
= x
+ width
;
601 wxCoord y2
= y
+ height
;
603 if ((m_logicalFunction
== wxCOPY
) && (m_pen
.GetStyle() == wxTRANSPARENT
))
606 rect
.left
= XLOG2DEV(x
);
607 rect
.top
= YLOG2DEV(y
);
608 rect
.right
= XLOG2DEV(x2
);
609 rect
.bottom
= YLOG2DEV(y2
);
610 (void)FillRect(GetHdc(), &rect
, (HBRUSH
)m_brush
.GetResourceHandle() );
614 // Windows draws the filled rectangles without outline (i.e. drawn with a
615 // transparent pen) one pixel smaller in both directions and we want them
616 // to have the same size regardless of which pen is used - adjust
618 // I wonder if this shouldn´t be done after the LOG2DEV() conversions. RR.
619 if ( m_pen
.GetStyle() == wxTRANSPARENT
)
625 (void)Rectangle(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
));
629 CalcBoundingBox(x
, y
);
630 CalcBoundingBox(x2
, y2
);
633 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
635 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
637 // Now, a negative radius value is interpreted to mean
638 // 'the proportion of the smallest X or Y dimension'
642 double smallest
= 0.0;
647 radius
= (- radius
* smallest
);
650 wxCoord x2
= (x
+width
);
651 wxCoord y2
= (y
+height
);
653 // Windows draws the filled rectangles without outline (i.e. drawn with a
654 // transparent pen) one pixel smaller in both directions and we want them
655 // to have the same size regardless of which pen is used - adjust
656 if ( m_pen
.GetStyle() == wxTRANSPARENT
)
662 (void)RoundRect(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
),
663 YLOG2DEV(y2
), (int) (2*XLOG2DEV(radius
)), (int)( 2*YLOG2DEV(radius
)));
665 CalcBoundingBox(x
, y
);
666 CalcBoundingBox(x2
, y2
);
669 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
671 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
673 wxCoord x2
= (x
+width
);
674 wxCoord y2
= (y
+height
);
676 (void)Ellipse(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
));
678 CalcBoundingBox(x
, y
);
679 CalcBoundingBox(x2
, y2
);
682 // Chris Breeze 20/5/98: first implementation of DrawEllipticArc on Windows
683 void wxDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
685 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
690 int rx1
= XLOG2DEV(x
+w
/2);
691 int ry1
= YLOG2DEV(y
+h
/2);
698 rx1
+= (int)(100.0 * abs(w
) * cos(sa
));
699 ry1
-= (int)(100.0 * abs(h
) * m_signY
* sin(sa
));
700 rx2
+= (int)(100.0 * abs(w
) * cos(ea
));
701 ry2
-= (int)(100.0 * abs(h
) * m_signY
* sin(ea
));
703 // draw pie with NULL_PEN first and then outline otherwise a line is
704 // drawn from the start and end points to the centre
705 HPEN hpenOld
= (HPEN
) ::SelectObject(GetHdc(), (HPEN
) ::GetStockObject(NULL_PEN
));
708 (void)Pie(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
)+1, YLOG2DEV(y2
)+1,
713 (void)Pie(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
)-1, XLOG2DEV(x2
)+1, YLOG2DEV(y2
),
714 rx1
, ry1
-1, rx2
, ry2
-1);
717 ::SelectObject(GetHdc(), hpenOld
);
719 (void)Arc(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
),
722 CalcBoundingBox(x
, y
);
723 CalcBoundingBox(x2
, y2
);
726 void wxDC::DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
)
728 wxCHECK_RET( icon
.Ok(), wxT("invalid icon in DrawIcon") );
731 ::DrawIconEx(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), GetHiconOf(icon
), icon
.GetWidth(), icon
.GetHeight(), 0, NULL
, DI_NORMAL
);
733 ::DrawIcon(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), GetHiconOf(icon
));
736 CalcBoundingBox(x
, y
);
737 CalcBoundingBox(x
+ icon
.GetWidth(), y
+ icon
.GetHeight());
740 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
742 wxCHECK_RET( bmp
.Ok(), _T("invalid bitmap in wxDC::DrawBitmap") );
744 int width
= bmp
.GetWidth(),
745 height
= bmp
.GetHeight();
747 HBITMAP hbmpMask
= 0;
751 wxMask
*mask
= bmp
.GetMask();
753 hbmpMask
= (HBITMAP
)mask
->GetMaskBitmap();
757 // don't give assert here because this would break existing
758 // programs - just silently ignore useMask parameter
766 HDC hdcMem
= ::CreateCompatibleDC(GetHdc());
767 ::SelectObject(hdcMem
, GetHbitmapOf(bmp
));
769 // use MaskBlt() with ROP which doesn't do anything to dst in the mask
771 bool ok
= ::MaskBlt(GetHdc(), x
, y
, width
, height
,
774 MAKEROP4(SRCCOPY
, DSTCOPY
)) != 0;
780 // Rather than reproduce wxDC::Blit, let's do it at the wxWin API
783 memDC
.SelectObject(bmp
);
785 Blit(x
, y
, width
, height
, &memDC
, 0, 0, wxCOPY
, useMask
);
787 memDC
.SelectObject(wxNullBitmap
);
790 else // no mask, just use BitBlt()
793 HDC memdc
= ::CreateCompatibleDC( cdc
);
794 HBITMAP hbitmap
= (HBITMAP
) bmp
.GetHBITMAP( );
796 wxASSERT_MSG( hbitmap
, wxT("bitmap is ok but HBITMAP is NULL?") );
798 COLORREF old_textground
= ::GetTextColor(GetHdc());
799 COLORREF old_background
= ::GetBkColor(GetHdc());
800 if (m_textForegroundColour
.Ok())
802 ::SetTextColor(GetHdc(), m_textForegroundColour
.GetPixel() );
804 if (m_textBackgroundColour
.Ok())
806 ::SetBkColor(GetHdc(), m_textBackgroundColour
.GetPixel() );
809 ::SelectObject( memdc
, hbitmap
);
810 ::BitBlt( cdc
, x
, y
, width
, height
, memdc
, 0, 0, SRCCOPY
);
813 ::SetTextColor(GetHdc(), old_textground
);
814 ::SetBkColor(GetHdc(), old_background
);
818 void wxDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
820 DrawAnyText(text
, x
, y
);
822 // update the bounding box
823 CalcBoundingBox(x
, y
);
826 GetTextExtent(text
, &w
, &h
);
827 CalcBoundingBox(x
+ w
, y
+ h
);
830 void wxDC::DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
)
832 // prepare for drawing the text
833 if ( m_textForegroundColour
.Ok() )
834 SetTextColor(GetHdc(), m_textForegroundColour
.GetPixel());
836 DWORD old_background
= 0;
837 if ( m_textBackgroundColour
.Ok() )
839 old_background
= SetBkColor(GetHdc(), m_textBackgroundColour
.GetPixel() );
842 SetBkMode(GetHdc(), m_backgroundMode
== wxTRANSPARENT
? TRANSPARENT
845 if ( ::TextOut(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
),
846 text
.c_str(), text
.length()) == 0 )
848 wxLogLastError(wxT("TextOut"));
851 // restore the old parameters (text foreground colour may be left because
852 // it never is set to anything else, but background should remain
853 // transparent even if we just drew an opaque string)
854 if ( m_textBackgroundColour
.Ok() )
855 (void)SetBkColor(GetHdc(), old_background
);
857 SetBkMode(GetHdc(), TRANSPARENT
);
860 void wxDC::DoDrawRotatedText(const wxString
& text
,
861 wxCoord x
, wxCoord y
,
864 // we test that we have some font because otherwise we should still use the
865 // "else" part below to avoid that DrawRotatedText(angle = 180) and
866 // DrawRotatedText(angle = 0) use different fonts (we can't use the default
867 // font for drawing rotated fonts unfortunately)
868 if ( (angle
== 0.0) && m_font
.Ok() )
870 DoDrawText(text
, x
, y
);
874 // NB: don't take DEFAULT_GUI_FONT because it's not TrueType and so
875 // can't have non zero orientation/escapement
876 wxFont font
= m_font
.Ok() ? m_font
: *wxNORMAL_FONT
;
877 HFONT hfont
= (HFONT
)font
.GetResourceHandle();
879 if ( ::GetObject(hfont
, sizeof(lf
), &lf
) == 0 )
881 wxLogLastError(wxT("GetObject(hfont)"));
884 // GDI wants the angle in tenth of degree
885 long angle10
= (long)(angle
* 10);
886 lf
.lfEscapement
= angle10
;
887 lf
. lfOrientation
= angle10
;
889 hfont
= ::CreateFontIndirect(&lf
);
892 wxLogLastError(wxT("CreateFont"));
896 HFONT hfontOld
= (HFONT
)::SelectObject(GetHdc(), hfont
);
898 DrawAnyText(text
, x
, y
);
900 (void)::SelectObject(GetHdc(), hfontOld
);
901 (void)::DeleteObject(hfont
);
904 // call the bounding box by adding all four vertices of the rectangle
905 // containing the text to it (simpler and probably not slower than
906 // determining which of them is really topmost/leftmost/...)
908 GetTextExtent(text
, &w
, &h
);
910 double rad
= DegToRad(angle
);
912 // "upper left" and "upper right"
913 CalcBoundingBox(x
, y
);
914 CalcBoundingBox(x
+ w
*cos(rad
), y
- h
*sin(rad
));
916 // "bottom left" and "bottom right"
917 x
+= (wxCoord
)(h
*sin(rad
));
918 y
+= (wxCoord
)(h
*cos(rad
));
919 CalcBoundingBox(x
, y
);
920 CalcBoundingBox(x
+ h
*sin(rad
), y
+ h
*cos(rad
));
924 // ---------------------------------------------------------------------------
926 // ---------------------------------------------------------------------------
928 void wxDC::SetPalette(const wxPalette
& palette
)
930 // Set the old object temporarily, in case the assignment deletes an object
931 // that's not yet selected out.
934 ::SelectPalette(GetHdc(), (HPALETTE
) m_oldPalette
, TRUE
);
942 // Setting a NULL colourmap is a way of restoring
943 // the original colourmap
946 ::SelectPalette(GetHdc(), (HPALETTE
) m_oldPalette
, TRUE
);
953 if (m_palette
.Ok() && m_palette
.GetHPALETTE())
955 HPALETTE oldPal
= ::SelectPalette(GetHdc(), (HPALETTE
) m_palette
.GetHPALETTE(), TRUE
);
957 m_oldPalette
= (WXHPALETTE
) oldPal
;
959 ::RealizePalette(GetHdc());
963 void wxDC::SetFont(const wxFont
& the_font
)
965 // Set the old object temporarily, in case the assignment deletes an object
966 // that's not yet selected out.
969 ::SelectObject(GetHdc(), (HFONT
) m_oldFont
);
978 ::SelectObject(GetHdc(), (HFONT
) m_oldFont
);
982 if (m_font
.Ok() && m_font
.GetResourceHandle())
984 HFONT f
= (HFONT
) ::SelectObject(GetHdc(), (HFONT
) m_font
.GetResourceHandle());
985 if (f
== (HFONT
) NULL
)
987 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
990 m_oldFont
= (WXHFONT
) f
;
994 void wxDC::SetPen(const wxPen
& pen
)
996 // Set the old object temporarily, in case the assignment deletes an object
997 // that's not yet selected out.
1000 ::SelectObject(GetHdc(), (HPEN
) m_oldPen
);
1009 ::SelectObject(GetHdc(), (HPEN
) m_oldPen
);
1015 if (m_pen
.GetResourceHandle())
1017 HPEN p
= (HPEN
) ::SelectObject(GetHdc(), (HPEN
)m_pen
.GetResourceHandle());
1019 m_oldPen
= (WXHPEN
) p
;
1024 void wxDC::SetBrush(const wxBrush
& brush
)
1026 // Set the old object temporarily, in case the assignment deletes an object
1027 // that's not yet selected out.
1030 ::SelectObject(GetHdc(), (HBRUSH
) m_oldBrush
);
1039 ::SelectObject(GetHdc(), (HBRUSH
) m_oldBrush
);
1045 // to make sure the brush is alligned with the logical coordinates
1046 wxBitmap
*stipple
= m_brush
.GetStipple();
1047 if ( stipple
&& stipple
->Ok() )
1050 ::SetBrushOrgEx(GetHdc(),
1051 m_deviceOriginX
% stipple
->GetWidth(),
1052 m_deviceOriginY
% stipple
->GetHeight(),
1053 NULL
); // don't need previous brush origin
1055 ::SetBrushOrg(GetHdc(),
1056 m_deviceOriginX
% stipple
->GetWidth(),
1057 m_deviceOriginY
% stipple
->GetHeight());
1061 if ( m_brush
.GetResourceHandle() )
1064 b
= (HBRUSH
) ::SelectObject(GetHdc(), (HBRUSH
)m_brush
.GetResourceHandle());
1066 m_oldBrush
= (WXHBRUSH
) b
;
1071 void wxDC::SetBackground(const wxBrush
& brush
)
1073 m_backgroundBrush
= brush
;
1075 if (!m_backgroundBrush
.Ok())
1080 bool customColours
= TRUE
;
1081 // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
1082 // change background colours from the control-panel specified colours.
1083 if (m_canvas
->IsKindOf(CLASSINFO(wxWindow
)) && ((m_canvas
->GetWindowStyleFlag() & wxUSER_COLOURS
) != wxUSER_COLOURS
))
1084 customColours
= FALSE
;
1088 if (m_backgroundBrush
.GetStyle()==wxTRANSPARENT
)
1090 m_canvas
->SetTransparent(TRUE
);
1094 // New behaviour, 10/2/99: setting the background brush of a DC
1095 // doesn't affect the window background colour. However,
1096 // I'm leaving in the transparency setting because it's needed by
1097 // various controls (e.g. wxStaticText) to determine whether to draw
1098 // transparently or not. TODO: maybe this should be a new function
1099 // wxWindow::SetTransparency(). Should that apply to the child itself, or the
1101 // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour());
1102 m_canvas
->SetTransparent(FALSE
);
1106 COLORREF new_color
= m_backgroundBrush
.GetColour().GetPixel();
1108 (void)SetBkColor(GetHdc(), new_color
);
1112 void wxDC::SetBackgroundMode(int mode
)
1114 m_backgroundMode
= mode
;
1116 // SetBackgroundColour now only refers to text background
1117 // and m_backgroundMode is used there
1120 if (m_backgroundMode == wxTRANSPARENT)
1121 ::SetBkMode(GetHdc(), TRANSPARENT);
1123 ::SetBkMode(GetHdc(), OPAQUE);
1124 Last change: AC 29 Jan 101 8:54 pm
1128 void wxDC::SetLogicalFunction(int function
)
1130 m_logicalFunction
= function
;
1135 void wxDC::SetRop(WXHDC dc
)
1137 if ( !dc
|| m_logicalFunction
< 0 )
1142 switch (m_logicalFunction
)
1144 case wxCLEAR
: rop
= R2_BLACK
; break;
1145 case wxXOR
: rop
= R2_XORPEN
; break;
1146 case wxINVERT
: rop
= R2_NOT
; break;
1147 case wxOR_REVERSE
: rop
= R2_MERGEPENNOT
; break;
1148 case wxAND_REVERSE
: rop
= R2_MASKPENNOT
; break;
1149 case wxCOPY
: rop
= R2_COPYPEN
; break;
1150 case wxAND
: rop
= R2_MASKPEN
; break;
1151 case wxAND_INVERT
: rop
= R2_MASKNOTPEN
; break;
1152 case wxNO_OP
: rop
= R2_NOP
; break;
1153 case wxNOR
: rop
= R2_NOTMERGEPEN
; break;
1154 case wxEQUIV
: rop
= R2_NOTXORPEN
; break;
1155 case wxSRC_INVERT
: rop
= R2_NOTCOPYPEN
; break;
1156 case wxOR_INVERT
: rop
= R2_MERGENOTPEN
; break;
1157 case wxNAND
: rop
= R2_NOTMASKPEN
; break;
1158 case wxOR
: rop
= R2_MERGEPEN
; break;
1159 case wxSET
: rop
= R2_WHITE
; break;
1162 wxFAIL_MSG( wxT("unsupported logical function") );
1166 SetROP2(GetHdc(), rop
);
1169 bool wxDC::StartDoc(const wxString
& message
)
1171 // We might be previewing, so return TRUE to let it continue.
1179 void wxDC::StartPage()
1183 void wxDC::EndPage()
1187 // ---------------------------------------------------------------------------
1189 // ---------------------------------------------------------------------------
1191 wxCoord
wxDC::GetCharHeight() const
1193 TEXTMETRIC lpTextMetric
;
1195 GetTextMetrics(GetHdc(), &lpTextMetric
);
1197 return YDEV2LOGREL(lpTextMetric
.tmHeight
);
1200 wxCoord
wxDC::GetCharWidth() const
1202 TEXTMETRIC lpTextMetric
;
1204 GetTextMetrics(GetHdc(), &lpTextMetric
);
1206 return XDEV2LOGREL(lpTextMetric
.tmAveCharWidth
);
1209 void wxDC::DoGetTextExtent(const wxString
& string
, wxCoord
*x
, wxCoord
*y
,
1210 wxCoord
*descent
, wxCoord
*externalLeading
,
1211 wxFont
*theFont
) const
1213 wxFont
*fontToUse
= (wxFont
*) theFont
;
1215 fontToUse
= (wxFont
*) &m_font
;
1220 GetTextExtentPoint(GetHdc(), WXSTRINGCAST string
, wxStrlen(WXSTRINGCAST string
), &sizeRect
);
1221 GetTextMetrics(GetHdc(), &tm
);
1223 if (x
) *x
= XDEV2LOGREL(sizeRect
.cx
);
1224 if (y
) *y
= YDEV2LOGREL(sizeRect
.cy
);
1225 if (descent
) *descent
= tm
.tmDescent
;
1226 if (externalLeading
) *externalLeading
= tm
.tmExternalLeading
;
1229 void wxDC::SetMapMode(int mode
)
1231 m_mappingMode
= mode
;
1233 int pixel_width
= 0;
1234 int pixel_height
= 0;
1238 pixel_width
= GetDeviceCaps(GetHdc(), HORZRES
);
1239 pixel_height
= GetDeviceCaps(GetHdc(), VERTRES
);
1240 mm_width
= GetDeviceCaps(GetHdc(), HORZSIZE
);
1241 mm_height
= GetDeviceCaps(GetHdc(), VERTSIZE
);
1243 if ((pixel_width
== 0) || (pixel_height
== 0) || (mm_width
== 0) || (mm_height
== 0))
1248 double mm2pixelsX
= pixel_width
/mm_width
;
1249 double mm2pixelsY
= pixel_height
/mm_height
;
1255 m_logicalScaleX
= (twips2mm
* mm2pixelsX
);
1256 m_logicalScaleY
= (twips2mm
* mm2pixelsY
);
1261 m_logicalScaleX
= (pt2mm
* mm2pixelsX
);
1262 m_logicalScaleY
= (pt2mm
* mm2pixelsY
);
1267 m_logicalScaleX
= mm2pixelsX
;
1268 m_logicalScaleY
= mm2pixelsY
;
1273 m_logicalScaleX
= (mm2pixelsX
/10.0);
1274 m_logicalScaleY
= (mm2pixelsY
/10.0);
1280 m_logicalScaleX
= 1.0;
1281 m_logicalScaleY
= 1.0;
1286 if (::GetMapMode(GetHdc()) != MM_ANISOTROPIC
)
1287 ::SetMapMode(GetHdc(), MM_ANISOTROPIC
);
1289 SetViewportExtEx(GetHdc(), VIEWPORT_EXTENT
, VIEWPORT_EXTENT
, NULL
);
1290 m_windowExtX
= (int)MS_XDEV2LOGREL(VIEWPORT_EXTENT
);
1291 m_windowExtY
= (int)MS_YDEV2LOGREL(VIEWPORT_EXTENT
);
1292 ::SetWindowExtEx(GetHdc(), m_windowExtX
, m_windowExtY
, NULL
);
1293 ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX
, (int)m_deviceOriginY
, NULL
);
1294 ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX
, (int)m_logicalOriginY
, NULL
);
1297 void wxDC::SetUserScale(double x
, double y
)
1302 SetMapMode(m_mappingMode
);
1305 void wxDC::SetAxisOrientation(bool xLeftRight
, bool yBottomUp
)
1307 m_signX
= xLeftRight
? 1 : -1;
1308 m_signY
= yBottomUp
? -1 : 1;
1310 SetMapMode(m_mappingMode
);
1313 void wxDC::SetSystemScale(double x
, double y
)
1318 SetMapMode(m_mappingMode
);
1321 void wxDC::SetLogicalOrigin(wxCoord x
, wxCoord y
)
1323 m_logicalOriginX
= x
;
1324 m_logicalOriginY
= y
;
1326 ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX
, (int)m_logicalOriginY
, NULL
);
1329 void wxDC::SetDeviceOrigin(wxCoord x
, wxCoord y
)
1331 m_deviceOriginX
= x
;
1332 m_deviceOriginY
= y
;
1334 ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX
, (int)m_deviceOriginY
, NULL
);
1337 // ---------------------------------------------------------------------------
1338 // coordinates transformations
1339 // ---------------------------------------------------------------------------
1341 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
1343 double xRel
= x
- m_deviceOriginX
;
1344 xRel
/= m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
;
1345 return (wxCoord
)(xRel
+ m_logicalOriginX
);
1348 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
1350 return (wxCoord
) ((x
)/(m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
));
1353 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
1355 double yRel
= y
- m_deviceOriginY
;
1356 yRel
/= m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
;
1357 return (wxCoord
)(yRel
+ m_logicalOriginY
);
1360 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
1362 return (wxCoord
) ((y
)/(m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
));
1365 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
1367 return (wxCoord
) ((x
- m_logicalOriginX
)*m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
+ m_deviceOriginX
);
1370 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
1372 return (wxCoord
) (x
*m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
);
1375 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
1377 return (wxCoord
) ((y
- m_logicalOriginY
)*m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
+ m_deviceOriginY
);
1380 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
1382 return (wxCoord
) (y
*m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
);
1385 // ---------------------------------------------------------------------------
1387 // ---------------------------------------------------------------------------
1389 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
,
1390 wxCoord width
, wxCoord height
,
1391 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
1392 int rop
, bool useMask
)
1394 wxMask
*mask
= NULL
;
1397 const wxBitmap
& bmp
= source
->m_selectedBitmap
;
1398 mask
= bmp
.GetMask();
1400 if ( !(bmp
.Ok() && mask
&& mask
->GetMaskBitmap()) )
1402 // don't give assert here because this would break existing
1403 // programs - just silently ignore useMask parameter
1408 COLORREF old_textground
= ::GetTextColor(GetHdc());
1409 COLORREF old_background
= ::GetBkColor(GetHdc());
1410 if (m_textForegroundColour
.Ok())
1412 ::SetTextColor(GetHdc(), m_textForegroundColour
.GetPixel() );
1414 if (m_textBackgroundColour
.Ok())
1416 ::SetBkColor(GetHdc(), m_textBackgroundColour
.GetPixel() );
1419 DWORD dwRop
= SRCCOPY
;
1422 case wxXOR
: dwRop
= SRCINVERT
; break;
1423 case wxINVERT
: dwRop
= DSTINVERT
; break;
1424 case wxOR_REVERSE
: dwRop
= 0x00DD0228; break;
1425 case wxAND_REVERSE
: dwRop
= SRCERASE
; break;
1426 case wxCLEAR
: dwRop
= BLACKNESS
; break;
1427 case wxSET
: dwRop
= WHITENESS
; break;
1428 case wxOR_INVERT
: dwRop
= MERGEPAINT
; break;
1429 case wxAND
: dwRop
= SRCAND
; break;
1430 case wxOR
: dwRop
= SRCPAINT
; break;
1431 case wxEQUIV
: dwRop
= 0x00990066; break;
1432 case wxNAND
: dwRop
= 0x007700E6; break;
1433 case wxAND_INVERT
: dwRop
= 0x00220326; break;
1434 case wxCOPY
: dwRop
= SRCCOPY
; break;
1435 case wxNO_OP
: dwRop
= DSTCOPY
; break;
1436 case wxSRC_INVERT
: dwRop
= NOTSRCCOPY
; break;
1437 case wxNOR
: dwRop
= NOTSRCCOPY
; break;
1439 wxFAIL_MSG( wxT("unsupported logical function") );
1448 // we want the part of the image corresponding to the mask to be
1449 // transparent, so use "DSTCOPY" ROP for the mask points (the usual
1450 // meaning of fg and bg is inverted which corresponds to wxWin notion
1451 // of the mask which is also contrary to the Windows one)
1452 success
= ::MaskBlt(GetHdc(), xdest
, ydest
, width
, height
,
1453 GetHdcOf(*source
), xsrc
, ysrc
,
1454 (HBITMAP
)mask
->GetMaskBitmap(), xsrc
, ysrc
,
1455 MAKEROP4(dwRop
, DSTCOPY
)) != 0;
1460 // Blit bitmap with mask
1462 // create a temp buffer bitmap and DCs to access it and the mask
1463 HDC dc_mask
= ::CreateCompatibleDC(GetHdcOf(*source
));
1464 HDC dc_buffer
= ::CreateCompatibleDC(GetHdc());
1465 HBITMAP buffer_bmap
= ::CreateCompatibleBitmap(GetHdc(), width
, height
);
1466 ::SelectObject(dc_mask
, (HBITMAP
) mask
->GetMaskBitmap());
1467 ::SelectObject(dc_buffer
, buffer_bmap
);
1469 // copy dest to buffer
1470 if ( !::BitBlt(dc_buffer
, 0, 0, (int)width
, (int)height
,
1471 GetHdc(), xdest
, ydest
, SRCCOPY
) )
1473 wxLogLastError(wxT("BitBlt"));
1476 // copy src to buffer using selected raster op
1477 if ( !::BitBlt(dc_buffer
, 0, 0, (int)width
, (int)height
,
1478 GetHdcOf(*source
), xsrc
, ysrc
, dwRop
) )
1480 wxLogLastError(wxT("BitBlt"));
1483 // set masked area in buffer to BLACK (pixel value 0)
1484 COLORREF prevBkCol
= ::SetBkColor(GetHdc(), RGB(255, 255, 255));
1485 COLORREF prevCol
= ::SetTextColor(GetHdc(), RGB(0, 0, 0));
1486 if ( !::BitBlt(dc_buffer
, 0, 0, (int)width
, (int)height
,
1487 dc_mask
, xsrc
, ysrc
, SRCAND
) )
1489 wxLogLastError(wxT("BitBlt"));
1492 // set unmasked area in dest to BLACK
1493 ::SetBkColor(GetHdc(), RGB(0, 0, 0));
1494 ::SetTextColor(GetHdc(), RGB(255, 255, 255));
1495 if ( !::BitBlt(GetHdc(), xdest
, ydest
, (int)width
, (int)height
,
1496 dc_mask
, xsrc
, ysrc
, SRCAND
) )
1498 wxLogLastError(wxT("BitBlt"));
1500 ::SetBkColor(GetHdc(), prevBkCol
); // restore colours to original values
1501 ::SetTextColor(GetHdc(), prevCol
);
1503 // OR buffer to dest
1504 success
= ::BitBlt(GetHdc(), xdest
, ydest
,
1505 (int)width
, (int)height
,
1506 dc_buffer
, 0, 0, SRCPAINT
) != 0;
1509 wxLogLastError(wxT("BitBlt"));
1512 // tidy up temporary DCs and bitmap
1513 ::SelectObject(dc_mask
, 0);
1514 ::DeleteDC(dc_mask
);
1515 ::SelectObject(dc_buffer
, 0);
1516 ::DeleteDC(dc_buffer
);
1517 ::DeleteObject(buffer_bmap
);
1520 else // no mask, just BitBlt() it
1522 success
= ::BitBlt(GetHdc(), xdest
, ydest
,
1523 (int)width
, (int)height
,
1524 GetHdcOf(*source
), xsrc
, ysrc
, dwRop
) != 0;
1527 wxLogLastError(wxT("BitBlt"));
1530 ::SetTextColor(GetHdc(), old_textground
);
1531 ::SetBkColor(GetHdc(), old_background
);
1536 void wxDC::DoGetSize(int *w
, int *h
) const
1538 if ( w
) *w
= ::GetDeviceCaps(GetHdc(), HORZRES
);
1539 if ( h
) *h
= ::GetDeviceCaps(GetHdc(), VERTRES
);
1542 void wxDC::DoGetSizeMM(int *w
, int *h
) const
1544 if ( w
) *w
= ::GetDeviceCaps(GetHdc(), HORZSIZE
);
1545 if ( h
) *h
= ::GetDeviceCaps(GetHdc(), VERTSIZE
);
1548 wxSize
wxDC::GetPPI() const
1550 int x
= ::GetDeviceCaps(GetHdc(), LOGPIXELSX
);
1551 int y
= ::GetDeviceCaps(GetHdc(), LOGPIXELSY
);
1553 return wxSize(x
, y
);
1556 // For use by wxWindows only, unless custom units are required.
1557 void wxDC::SetLogicalScale(double x
, double y
)
1559 m_logicalScaleX
= x
;
1560 m_logicalScaleY
= y
;
1563 #if WXWIN_COMPATIBILITY
1564 void wxDC::DoGetTextExtent(const wxString
& string
, float *x
, float *y
,
1565 float *descent
, float *externalLeading
,
1566 wxFont
*theFont
, bool use16bit
) const
1568 wxCoord x1
, y1
, descent1
, externalLeading1
;
1569 GetTextExtent(string
, & x1
, & y1
, & descent1
, & externalLeading1
, theFont
, use16bit
);
1572 *descent
= descent1
;
1573 if (externalLeading
)
1574 *externalLeading
= externalLeading1
;