]>
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 void wxDC::UpdateClipBox()
269 #ifdef __WXMICROWIN__
270 if (!GetHDC()) return;
274 GetClipBox(GetHdc(), &rect
);
276 m_clipX1
= (wxCoord
) XDEV2LOG(rect
.left
);
277 m_clipY1
= (wxCoord
) YDEV2LOG(rect
.top
);
278 m_clipX2
= (wxCoord
) XDEV2LOG(rect
.right
);
279 m_clipY2
= (wxCoord
) YDEV2LOG(rect
.bottom
);
282 void wxDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
284 #ifdef __WXMICROWIN__
285 if (!GetHDC()) return;
290 // the region coords are always the device ones, so do the translation
293 // FIXME: possible +/-1 error here, to check!
294 HRGN hrgn
= ::CreateRectRgn(LogicalToDeviceX(x
),
296 LogicalToDeviceX(x
+ w
),
297 LogicalToDeviceY(y
+ h
));
300 wxLogLastError(_T("CreateRectRgn"));
304 if ( ::SelectClipRgn(GetHdc(), hrgn
) == ERROR
)
306 wxLogLastError(_T("SelectClipRgn"));
314 void wxDC::DoSetClippingRegionAsRegion(const wxRegion
& region
)
316 #ifdef __WXMICROWIN__
317 if (!GetHDC()) return;
320 wxCHECK_RET( GetHrgnOf(region
), wxT("invalid clipping region") );
325 SelectClipRgn(GetHdc(), GetHrgnOf(region
));
327 ExtSelectClipRgn(GetHdc(), GetHrgnOf(region
), RGN_AND
);
333 void wxDC::DestroyClippingRegion()
335 #ifdef __WXMICROWIN__
336 if (!GetHDC()) return;
339 if (m_clipping
&& m_hDC
)
341 // TODO: this should restore the previous clipping region,
342 // so that OnPaint processing works correctly, and the update clipping region
343 // doesn't get destroyed after the first DestroyClippingRegion.
344 HRGN rgn
= CreateRectRgn(0, 0, 32000, 32000);
345 SelectClipRgn(GetHdc(), rgn
);
352 // ---------------------------------------------------------------------------
353 // query capabilities
354 // ---------------------------------------------------------------------------
356 bool wxDC::CanDrawBitmap() const
361 bool wxDC::CanGetTextExtent() const
363 #ifdef __WXMICROWIN__
364 // TODO Extend MicroWindows' GetDeviceCaps function
367 // What sort of display is it?
368 int technology
= ::GetDeviceCaps(GetHdc(), TECHNOLOGY
);
370 return (technology
== DT_RASDISPLAY
) || (technology
== DT_RASPRINTER
);
374 int wxDC::GetDepth() const
376 #ifdef __WXMICROWIN__
377 if (!GetHDC()) return 16;
380 return (int)::GetDeviceCaps(GetHdc(), BITSPIXEL
);
383 // ---------------------------------------------------------------------------
385 // ---------------------------------------------------------------------------
389 #ifdef __WXMICROWIN__
390 if (!GetHDC()) return;
396 GetClientRect((HWND
) m_canvas
->GetHWND(), &rect
);
400 // No, I think we should simply ignore this if printing on e.g.
402 // wxCHECK_RET( m_selectedBitmap.Ok(), wxT("this DC can't be cleared") );
403 if (!m_selectedBitmap
.Ok())
406 rect
.left
= 0; rect
.top
= 0;
407 rect
.right
= m_selectedBitmap
.GetWidth();
408 rect
.bottom
= m_selectedBitmap
.GetHeight();
411 (void) ::SetMapMode(GetHdc(), MM_TEXT
);
413 DWORD colour
= GetBkColor(GetHdc());
414 HBRUSH brush
= CreateSolidBrush(colour
);
415 FillRect(GetHdc(), &rect
, brush
);
418 ::SetMapMode(GetHdc(), MM_ANISOTROPIC
);
419 ::SetViewportExtEx(GetHdc(), VIEWPORT_EXTENT
, VIEWPORT_EXTENT
, NULL
);
420 ::SetWindowExtEx(GetHdc(), m_windowExtX
, m_windowExtY
, NULL
);
421 ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX
, (int)m_deviceOriginY
, NULL
);
422 ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX
, (int)m_logicalOriginY
, NULL
);
425 void wxDC::DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
, int style
)
427 #ifdef __WXMICROWIN__
428 if (!GetHDC()) return;
431 if ( !::ExtFloodFill(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
),
433 style
== wxFLOOD_SURFACE
? FLOODFILLSURFACE
436 // quoting from the MSDN docs:
438 // Following are some of the reasons this function might fail:
440 // * The filling could not be completed.
441 // * The specified point has the boundary color specified by the
442 // crColor parameter (if FLOODFILLBORDER was requested).
443 // * The specified point does not have the color specified by
444 // crColor (if FLOODFILLSURFACE was requested)
445 // * The point is outside the clipping region that is, it is not
446 // visible on the device.
448 wxLogLastError(wxT("ExtFloodFill"));
451 CalcBoundingBox(x
, y
);
454 bool wxDC::DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const
456 #ifdef __WXMICROWIN__
457 if (!GetHDC()) return FALSE
;
460 wxCHECK_MSG( col
, FALSE
, _T("NULL colour parameter in wxDC::GetPixel") );
462 // get the color of the pixel
463 COLORREF pixelcolor
= ::GetPixel(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
));
465 wxRGBToColour(*col
, pixelcolor
);
470 void wxDC::DoCrossHair(wxCoord x
, wxCoord y
)
472 #ifdef __WXMICROWIN__
473 if (!GetHDC()) return;
476 wxCoord x1
= x
-VIEWPORT_EXTENT
;
477 wxCoord y1
= y
-VIEWPORT_EXTENT
;
478 wxCoord x2
= x
+VIEWPORT_EXTENT
;
479 wxCoord y2
= y
+VIEWPORT_EXTENT
;
481 (void)MoveToEx(GetHdc(), XLOG2DEV(x1
), YLOG2DEV(y
), NULL
);
482 (void)LineTo(GetHdc(), XLOG2DEV(x2
), YLOG2DEV(y
));
484 (void)MoveToEx(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y1
), NULL
);
485 (void)LineTo(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y2
));
487 CalcBoundingBox(x1
, y1
);
488 CalcBoundingBox(x2
, y2
);
491 void wxDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
493 #ifdef __WXMICROWIN__
494 if (!GetHDC()) return;
497 (void)MoveToEx(GetHdc(), XLOG2DEV(x1
), YLOG2DEV(y1
), NULL
);
498 (void)LineTo(GetHdc(), XLOG2DEV(x2
), YLOG2DEV(y2
));
500 // Normalization: Windows doesn't draw the last point of the line.
501 // But apparently neither does GTK+, so we take it out again.
502 // (void)LineTo(GetHdc(), XLOG2DEV(x2) + 1, YLOG2DEV(y2));
504 CalcBoundingBox(x1
, y1
);
505 CalcBoundingBox(x2
, y2
);
508 // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
509 // and ending at (x2, y2)
510 void wxDC::DoDrawArc(wxCoord x1
, wxCoord y1
,
511 wxCoord x2
, wxCoord y2
,
512 wxCoord xc
, wxCoord yc
)
514 #ifdef __WXMICROWIN__
515 if (!GetHDC()) return;
518 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
522 double radius
= (double)sqrt(dx
*dx
+dy
*dy
);
523 wxCoord r
= (wxCoord
)radius
;
525 // treat the special case of full circle separately
526 if ( x1
== x2
&& y1
== y2
)
528 DrawEllipse(xc
- r
, yc
- r
, 2*r
, 2*r
);
532 wxCoord xx1
= XLOG2DEV(x1
);
533 wxCoord yy1
= YLOG2DEV(y1
);
534 wxCoord xx2
= XLOG2DEV(x2
);
535 wxCoord yy2
= YLOG2DEV(y2
);
536 wxCoord xxc
= XLOG2DEV(xc
);
537 wxCoord yyc
= YLOG2DEV(yc
);
538 wxCoord ray
= (wxCoord
) sqrt(double((xxc
-xx1
)*(xxc
-xx1
)+(yyc
-yy1
)*(yyc
-yy1
)));
540 wxCoord xxx1
= (wxCoord
) (xxc
-ray
);
541 wxCoord yyy1
= (wxCoord
) (yyc
-ray
);
542 wxCoord xxx2
= (wxCoord
) (xxc
+ray
);
543 wxCoord yyy2
= (wxCoord
) (yyc
+ray
);
545 if ( m_brush
.Ok() && m_brush
.GetStyle() != wxTRANSPARENT
)
547 // Have to add 1 to bottom-right corner of rectangle
548 // to make semi-circles look right (crooked line otherwise).
549 // Unfortunately this is not a reliable method, depends
550 // on the size of shape.
551 // TODO: figure out why this happens!
552 Pie(GetHdc(),xxx1
,yyy1
,xxx2
+1,yyy2
+1, xx1
,yy1
,xx2
,yy2
);
556 Arc(GetHdc(),xxx1
,yyy1
,xxx2
,yyy2
, xx1
,yy1
,xx2
,yy2
);
559 CalcBoundingBox(xc
- r
, yc
- r
);
560 CalcBoundingBox(xc
+ r
, yc
+ r
);
563 void wxDC::DoDrawCheckMark(wxCoord x1
, wxCoord y1
,
564 wxCoord width
, wxCoord height
)
566 #ifdef __WXMICROWIN__
567 if (!GetHDC()) return;
570 wxCoord x2
= x1
+ width
,
573 #if defined(__WIN32__) && !defined(__SC__) && !defined(__WXMICROWIN__)
580 DrawFrameControl(GetHdc(), &rect
, DFC_MENU
, DFCS_MENUCHECK
);
582 // In WIN16, draw a cross
583 HPEN blackPen
= ::CreatePen(PS_SOLID
, 1, RGB(0, 0, 0));
584 HPEN whiteBrush
= (HPEN
)::GetStockObject(WHITE_BRUSH
);
585 HPEN hPenOld
= (HPEN
)::SelectObject(GetHdc(), blackPen
);
586 HPEN hBrushOld
= (HPEN
)::SelectObject(GetHdc(), whiteBrush
);
587 ::SetROP2(GetHdc(), R2_COPYPEN
);
588 Rectangle(GetHdc(), x1
, y1
, x2
, y2
);
589 MoveToEx(GetHdc(), x1
, y1
, NULL
);
590 LineTo(GetHdc(), x2
, y2
);
591 MoveToEx(GetHdc(), x2
, y1
, NULL
);
592 LineTo(GetHdc(), x1
, y2
);
593 ::SelectObject(GetHdc(), hPenOld
);
594 ::SelectObject(GetHdc(), hBrushOld
);
595 ::DeleteObject(blackPen
);
598 CalcBoundingBox(x1
, y1
);
599 CalcBoundingBox(x2
, y2
);
602 void wxDC::DoDrawPoint(wxCoord x
, wxCoord y
)
604 #ifdef __WXMICROWIN__
605 if (!GetHDC()) return;
608 COLORREF color
= 0x00ffffff;
611 color
= m_pen
.GetColour().GetPixel();
614 SetPixel(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), color
);
616 CalcBoundingBox(x
, y
);
619 void wxDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
,int fillStyle
)
621 #ifdef __WXMICROWIN__
622 if (!GetHDC()) return;
625 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
627 // Do things less efficiently if we have offsets
628 if (xoffset
!= 0 || yoffset
!= 0)
630 POINT
*cpoints
= new POINT
[n
];
632 for (i
= 0; i
< n
; i
++)
634 cpoints
[i
].x
= (int)(points
[i
].x
+ xoffset
);
635 cpoints
[i
].y
= (int)(points
[i
].y
+ yoffset
);
637 CalcBoundingBox(cpoints
[i
].x
, cpoints
[i
].y
);
639 int prev
= SetPolyFillMode(GetHdc(),fillStyle
==wxODDEVEN_RULE
?ALTERNATE
:WINDING
);
640 (void)Polygon(GetHdc(), cpoints
, n
);
641 SetPolyFillMode(GetHdc(),prev
);
647 for (i
= 0; i
< n
; i
++)
648 CalcBoundingBox(points
[i
].x
, points
[i
].y
);
650 int prev
= SetPolyFillMode(GetHdc(),fillStyle
==wxODDEVEN_RULE
?ALTERNATE
:WINDING
);
651 (void)Polygon(GetHdc(), (POINT
*) points
, n
);
652 SetPolyFillMode(GetHdc(),prev
);
656 void wxDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
658 #ifdef __WXMICROWIN__
659 if (!GetHDC()) return;
662 // Do things less efficiently if we have offsets
663 if (xoffset
!= 0 || yoffset
!= 0)
665 POINT
*cpoints
= new POINT
[n
];
667 for (i
= 0; i
< n
; i
++)
669 cpoints
[i
].x
= (int)(points
[i
].x
+ xoffset
);
670 cpoints
[i
].y
= (int)(points
[i
].y
+ yoffset
);
672 CalcBoundingBox(cpoints
[i
].x
, cpoints
[i
].y
);
674 (void)Polyline(GetHdc(), cpoints
, n
);
680 for (i
= 0; i
< n
; i
++)
681 CalcBoundingBox(points
[i
].x
, points
[i
].y
);
683 (void)Polyline(GetHdc(), (POINT
*) points
, n
);
687 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
689 #ifdef __WXMICROWIN__
690 if (!GetHDC()) return;
693 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
695 wxCoord x2
= x
+ width
;
696 wxCoord y2
= y
+ height
;
698 if ((m_logicalFunction
== wxCOPY
) && (m_pen
.GetStyle() == wxTRANSPARENT
))
701 rect
.left
= XLOG2DEV(x
);
702 rect
.top
= YLOG2DEV(y
);
703 rect
.right
= XLOG2DEV(x2
);
704 rect
.bottom
= YLOG2DEV(y2
);
705 (void)FillRect(GetHdc(), &rect
, (HBRUSH
)m_brush
.GetResourceHandle() );
709 // Windows draws the filled rectangles without outline (i.e. drawn with a
710 // transparent pen) one pixel smaller in both directions and we want them
711 // to have the same size regardless of which pen is used - adjust
713 // I wonder if this shouldn´t be done after the LOG2DEV() conversions. RR.
714 if ( m_pen
.GetStyle() == wxTRANSPARENT
)
720 (void)Rectangle(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
));
724 CalcBoundingBox(x
, y
);
725 CalcBoundingBox(x2
, y2
);
728 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
730 #ifdef __WXMICROWIN__
731 if (!GetHDC()) return;
734 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
736 // Now, a negative radius value is interpreted to mean
737 // 'the proportion of the smallest X or Y dimension'
741 double smallest
= 0.0;
746 radius
= (- radius
* smallest
);
749 wxCoord x2
= (x
+width
);
750 wxCoord y2
= (y
+height
);
752 // Windows draws the filled rectangles without outline (i.e. drawn with a
753 // transparent pen) one pixel smaller in both directions and we want them
754 // to have the same size regardless of which pen is used - adjust
755 if ( m_pen
.GetStyle() == wxTRANSPARENT
)
761 (void)RoundRect(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
),
762 YLOG2DEV(y2
), (int) (2*XLOG2DEV(radius
)), (int)( 2*YLOG2DEV(radius
)));
764 CalcBoundingBox(x
, y
);
765 CalcBoundingBox(x2
, y2
);
768 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
770 #ifdef __WXMICROWIN__
771 if (!GetHDC()) return;
774 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
776 wxCoord x2
= (x
+width
);
777 wxCoord y2
= (y
+height
);
779 (void)Ellipse(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
));
781 CalcBoundingBox(x
, y
);
782 CalcBoundingBox(x2
, y2
);
785 // Chris Breeze 20/5/98: first implementation of DrawEllipticArc on Windows
786 void wxDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
788 #ifdef __WXMICROWIN__
789 if (!GetHDC()) return;
792 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
797 int rx1
= XLOG2DEV(x
+w
/2);
798 int ry1
= YLOG2DEV(y
+h
/2);
805 rx1
+= (int)(100.0 * abs(w
) * cos(sa
));
806 ry1
-= (int)(100.0 * abs(h
) * m_signY
* sin(sa
));
807 rx2
+= (int)(100.0 * abs(w
) * cos(ea
));
808 ry2
-= (int)(100.0 * abs(h
) * m_signY
* sin(ea
));
810 // draw pie with NULL_PEN first and then outline otherwise a line is
811 // drawn from the start and end points to the centre
812 HPEN hpenOld
= (HPEN
) ::SelectObject(GetHdc(), (HPEN
) ::GetStockObject(NULL_PEN
));
815 (void)Pie(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
)+1, YLOG2DEV(y2
)+1,
820 (void)Pie(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
)-1, XLOG2DEV(x2
)+1, YLOG2DEV(y2
),
821 rx1
, ry1
-1, rx2
, ry2
-1);
824 ::SelectObject(GetHdc(), hpenOld
);
826 (void)Arc(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
),
829 CalcBoundingBox(x
, y
);
830 CalcBoundingBox(x2
, y2
);
833 void wxDC::DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
)
835 #ifdef __WXMICROWIN__
836 if (!GetHDC()) return;
839 wxCHECK_RET( icon
.Ok(), wxT("invalid icon in DrawIcon") );
842 ::DrawIconEx(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), GetHiconOf(icon
), icon
.GetWidth(), icon
.GetHeight(), 0, NULL
, DI_NORMAL
);
844 ::DrawIcon(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), GetHiconOf(icon
));
847 CalcBoundingBox(x
, y
);
848 CalcBoundingBox(x
+ icon
.GetWidth(), y
+ icon
.GetHeight());
851 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
853 #ifdef __WXMICROWIN__
854 if (!GetHDC()) return;
857 wxCHECK_RET( bmp
.Ok(), _T("invalid bitmap in wxDC::DrawBitmap") );
859 int width
= bmp
.GetWidth(),
860 height
= bmp
.GetHeight();
862 HBITMAP hbmpMask
= 0;
866 wxMask
*mask
= bmp
.GetMask();
868 hbmpMask
= (HBITMAP
)mask
->GetMaskBitmap();
872 // don't give assert here because this would break existing
873 // programs - just silently ignore useMask parameter
881 // use MaskBlt() with ROP which doesn't do anything to dst in the mask
883 // On some systems, MaskBlt succeeds yet is much much slower
884 // than the wxWindows fall-back implementation. So we need
885 // to be able to switch this on and off at runtime.
887 if (wxSystemSettings::GetOptionInt(wxT("no-maskblt")) == 0)
889 HDC hdcMem
= ::CreateCompatibleDC(GetHdc());
890 ::SelectObject(hdcMem
, GetHbitmapOf(bmp
));
892 ok
= ::MaskBlt(GetHdc(), x
, y
, width
, height
,
895 MAKEROP4(SRCCOPY
, DSTCOPY
)) != 0;
902 // Rather than reproduce wxDC::Blit, let's do it at the wxWin API
905 memDC
.SelectObject(bmp
);
907 Blit(x
, y
, width
, height
, &memDC
, 0, 0, wxCOPY
, useMask
);
909 memDC
.SelectObject(wxNullBitmap
);
912 else // no mask, just use BitBlt()
915 HDC memdc
= ::CreateCompatibleDC( cdc
);
916 HBITMAP hbitmap
= (HBITMAP
) bmp
.GetHBITMAP( );
918 wxASSERT_MSG( hbitmap
, wxT("bitmap is ok but HBITMAP is NULL?") );
920 COLORREF old_textground
= ::GetTextColor(GetHdc());
921 COLORREF old_background
= ::GetBkColor(GetHdc());
922 if (m_textForegroundColour
.Ok())
924 ::SetTextColor(GetHdc(), m_textForegroundColour
.GetPixel() );
926 if (m_textBackgroundColour
.Ok())
928 ::SetBkColor(GetHdc(), m_textBackgroundColour
.GetPixel() );
931 ::SelectObject( memdc
, hbitmap
);
932 ::BitBlt( cdc
, x
, y
, width
, height
, memdc
, 0, 0, SRCCOPY
);
935 ::SetTextColor(GetHdc(), old_textground
);
936 ::SetBkColor(GetHdc(), old_background
);
940 void wxDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
942 #ifdef __WXMICROWIN__
943 if (!GetHDC()) return;
946 DrawAnyText(text
, x
, y
);
948 // update the bounding box
949 CalcBoundingBox(x
, y
);
952 GetTextExtent(text
, &w
, &h
);
953 CalcBoundingBox(x
+ w
, y
+ h
);
956 void wxDC::DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
)
958 #ifdef __WXMICROWIN__
959 if (!GetHDC()) return;
962 // prepare for drawing the text
963 if ( m_textForegroundColour
.Ok() )
964 SetTextColor(GetHdc(), m_textForegroundColour
.GetPixel());
966 DWORD old_background
= 0;
967 if ( m_textBackgroundColour
.Ok() )
969 old_background
= SetBkColor(GetHdc(), m_textBackgroundColour
.GetPixel() );
972 SetBkMode(GetHdc(), m_backgroundMode
== wxTRANSPARENT
? TRANSPARENT
975 if ( ::TextOut(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
),
976 text
.c_str(), text
.length()) == 0 )
978 wxLogLastError(wxT("TextOut"));
981 // restore the old parameters (text foreground colour may be left because
982 // it never is set to anything else, but background should remain
983 // transparent even if we just drew an opaque string)
984 if ( m_textBackgroundColour
.Ok() )
985 (void)SetBkColor(GetHdc(), old_background
);
987 SetBkMode(GetHdc(), TRANSPARENT
);
990 void wxDC::DoDrawRotatedText(const wxString
& text
,
991 wxCoord x
, wxCoord y
,
994 #ifdef __WXMICROWIN__
995 if (!GetHDC()) return;
998 // we test that we have some font because otherwise we should still use the
999 // "else" part below to avoid that DrawRotatedText(angle = 180) and
1000 // DrawRotatedText(angle = 0) use different fonts (we can't use the default
1001 // font for drawing rotated fonts unfortunately)
1002 if ( (angle
== 0.0) && m_font
.Ok() )
1004 DoDrawText(text
, x
, y
);
1006 #ifndef __WXMICROWIN__
1009 // NB: don't take DEFAULT_GUI_FONT because it's not TrueType and so
1010 // can't have non zero orientation/escapement
1011 wxFont font
= m_font
.Ok() ? m_font
: *wxNORMAL_FONT
;
1012 HFONT hfont
= (HFONT
)font
.GetResourceHandle();
1014 if ( ::GetObject(hfont
, sizeof(lf
), &lf
) == 0 )
1016 wxLogLastError(wxT("GetObject(hfont)"));
1019 // GDI wants the angle in tenth of degree
1020 long angle10
= (long)(angle
* 10);
1021 lf
.lfEscapement
= angle10
;
1022 lf
. lfOrientation
= angle10
;
1024 hfont
= ::CreateFontIndirect(&lf
);
1027 wxLogLastError(wxT("CreateFont"));
1031 HFONT hfontOld
= (HFONT
)::SelectObject(GetHdc(), hfont
);
1033 DrawAnyText(text
, x
, y
);
1035 (void)::SelectObject(GetHdc(), hfontOld
);
1036 (void)::DeleteObject(hfont
);
1039 // call the bounding box by adding all four vertices of the rectangle
1040 // containing the text to it (simpler and probably not slower than
1041 // determining which of them is really topmost/leftmost/...)
1043 GetTextExtent(text
, &w
, &h
);
1045 double rad
= DegToRad(angle
);
1047 // "upper left" and "upper right"
1048 CalcBoundingBox(x
, y
);
1049 CalcBoundingBox(x
+ w
*cos(rad
), y
- h
*sin(rad
));
1051 // "bottom left" and "bottom right"
1052 x
+= (wxCoord
)(h
*sin(rad
));
1053 y
+= (wxCoord
)(h
*cos(rad
));
1054 CalcBoundingBox(x
, y
);
1055 CalcBoundingBox(x
+ h
*sin(rad
), y
+ h
*cos(rad
));
1060 // ---------------------------------------------------------------------------
1062 // ---------------------------------------------------------------------------
1064 void wxDC::SetPalette(const wxPalette
& palette
)
1066 #ifdef __WXMICROWIN__
1067 if (!GetHDC()) return;
1070 // Set the old object temporarily, in case the assignment deletes an object
1071 // that's not yet selected out.
1074 ::SelectPalette(GetHdc(), (HPALETTE
) m_oldPalette
, TRUE
);
1078 m_palette
= palette
;
1080 if (!m_palette
.Ok())
1082 // Setting a NULL colourmap is a way of restoring
1083 // the original colourmap
1086 ::SelectPalette(GetHdc(), (HPALETTE
) m_oldPalette
, TRUE
);
1093 if (m_palette
.Ok() && m_palette
.GetHPALETTE())
1095 HPALETTE oldPal
= ::SelectPalette(GetHdc(), (HPALETTE
) m_palette
.GetHPALETTE(), TRUE
);
1097 m_oldPalette
= (WXHPALETTE
) oldPal
;
1099 ::RealizePalette(GetHdc());
1103 void wxDC::SetFont(const wxFont
& the_font
)
1105 #ifdef __WXMICROWIN__
1106 if (!GetHDC()) return;
1109 // Set the old object temporarily, in case the assignment deletes an object
1110 // that's not yet selected out.
1113 ::SelectObject(GetHdc(), (HFONT
) m_oldFont
);
1122 ::SelectObject(GetHdc(), (HFONT
) m_oldFont
);
1126 if (m_font
.Ok() && m_font
.GetResourceHandle())
1128 HFONT f
= (HFONT
) ::SelectObject(GetHdc(), (HFONT
) m_font
.GetResourceHandle());
1129 if (f
== (HFONT
) NULL
)
1131 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
1134 m_oldFont
= (WXHFONT
) f
;
1138 void wxDC::SetPen(const wxPen
& pen
)
1140 #ifdef __WXMICROWIN__
1141 if (!GetHDC()) return;
1144 // Set the old object temporarily, in case the assignment deletes an object
1145 // that's not yet selected out.
1148 ::SelectObject(GetHdc(), (HPEN
) m_oldPen
);
1157 ::SelectObject(GetHdc(), (HPEN
) m_oldPen
);
1163 if (m_pen
.GetResourceHandle())
1165 HPEN p
= (HPEN
) ::SelectObject(GetHdc(), (HPEN
)m_pen
.GetResourceHandle());
1167 m_oldPen
= (WXHPEN
) p
;
1172 void wxDC::SetBrush(const wxBrush
& brush
)
1174 #ifdef __WXMICROWIN__
1175 if (!GetHDC()) return;
1178 // Set the old object temporarily, in case the assignment deletes an object
1179 // that's not yet selected out.
1182 ::SelectObject(GetHdc(), (HBRUSH
) m_oldBrush
);
1191 ::SelectObject(GetHdc(), (HBRUSH
) m_oldBrush
);
1197 // to make sure the brush is alligned with the logical coordinates
1198 wxBitmap
*stipple
= m_brush
.GetStipple();
1199 if ( stipple
&& stipple
->Ok() )
1202 ::SetBrushOrgEx(GetHdc(),
1203 m_deviceOriginX
% stipple
->GetWidth(),
1204 m_deviceOriginY
% stipple
->GetHeight(),
1205 NULL
); // don't need previous brush origin
1207 ::SetBrushOrg(GetHdc(),
1208 m_deviceOriginX
% stipple
->GetWidth(),
1209 m_deviceOriginY
% stipple
->GetHeight());
1213 if ( m_brush
.GetResourceHandle() )
1216 b
= (HBRUSH
) ::SelectObject(GetHdc(), (HBRUSH
)m_brush
.GetResourceHandle());
1218 m_oldBrush
= (WXHBRUSH
) b
;
1223 void wxDC::SetBackground(const wxBrush
& brush
)
1225 #ifdef __WXMICROWIN__
1226 if (!GetHDC()) return;
1229 m_backgroundBrush
= brush
;
1231 if (!m_backgroundBrush
.Ok())
1236 bool customColours
= TRUE
;
1237 // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
1238 // change background colours from the control-panel specified colours.
1239 if (m_canvas
->IsKindOf(CLASSINFO(wxWindow
)) && ((m_canvas
->GetWindowStyleFlag() & wxUSER_COLOURS
) != wxUSER_COLOURS
))
1240 customColours
= FALSE
;
1244 if (m_backgroundBrush
.GetStyle()==wxTRANSPARENT
)
1246 m_canvas
->SetTransparent(TRUE
);
1250 // New behaviour, 10/2/99: setting the background brush of a DC
1251 // doesn't affect the window background colour. However,
1252 // I'm leaving in the transparency setting because it's needed by
1253 // various controls (e.g. wxStaticText) to determine whether to draw
1254 // transparently or not. TODO: maybe this should be a new function
1255 // wxWindow::SetTransparency(). Should that apply to the child itself, or the
1257 // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour());
1258 m_canvas
->SetTransparent(FALSE
);
1262 COLORREF new_color
= m_backgroundBrush
.GetColour().GetPixel();
1264 (void)SetBkColor(GetHdc(), new_color
);
1268 void wxDC::SetBackgroundMode(int mode
)
1270 #ifdef __WXMICROWIN__
1271 if (!GetHDC()) return;
1274 m_backgroundMode
= mode
;
1276 // SetBackgroundColour now only refers to text background
1277 // and m_backgroundMode is used there
1280 if (m_backgroundMode == wxTRANSPARENT)
1281 ::SetBkMode(GetHdc(), TRANSPARENT);
1283 ::SetBkMode(GetHdc(), OPAQUE);
1284 Last change: AC 29 Jan 101 8:54 pm
1288 void wxDC::SetLogicalFunction(int function
)
1290 #ifdef __WXMICROWIN__
1291 if (!GetHDC()) return;
1294 m_logicalFunction
= function
;
1299 void wxDC::SetRop(WXHDC dc
)
1301 if ( !dc
|| m_logicalFunction
< 0 )
1306 switch (m_logicalFunction
)
1308 case wxCLEAR
: rop
= R2_BLACK
; break;
1309 case wxXOR
: rop
= R2_XORPEN
; break;
1310 case wxINVERT
: rop
= R2_NOT
; break;
1311 case wxOR_REVERSE
: rop
= R2_MERGEPENNOT
; break;
1312 case wxAND_REVERSE
: rop
= R2_MASKPENNOT
; break;
1313 case wxCOPY
: rop
= R2_COPYPEN
; break;
1314 case wxAND
: rop
= R2_MASKPEN
; break;
1315 case wxAND_INVERT
: rop
= R2_MASKNOTPEN
; break;
1316 case wxNO_OP
: rop
= R2_NOP
; break;
1317 case wxNOR
: rop
= R2_NOTMERGEPEN
; break;
1318 case wxEQUIV
: rop
= R2_NOTXORPEN
; break;
1319 case wxSRC_INVERT
: rop
= R2_NOTCOPYPEN
; break;
1320 case wxOR_INVERT
: rop
= R2_MERGENOTPEN
; break;
1321 case wxNAND
: rop
= R2_NOTMASKPEN
; break;
1322 case wxOR
: rop
= R2_MERGEPEN
; break;
1323 case wxSET
: rop
= R2_WHITE
; break;
1326 wxFAIL_MSG( wxT("unsupported logical function") );
1330 SetROP2(GetHdc(), rop
);
1333 bool wxDC::StartDoc(const wxString
& WXUNUSED(message
))
1335 // We might be previewing, so return TRUE to let it continue.
1343 void wxDC::StartPage()
1347 void wxDC::EndPage()
1351 // ---------------------------------------------------------------------------
1353 // ---------------------------------------------------------------------------
1355 wxCoord
wxDC::GetCharHeight() const
1357 #ifdef __WXMICROWIN__
1358 if (!GetHDC()) return 0;
1361 TEXTMETRIC lpTextMetric
;
1363 GetTextMetrics(GetHdc(), &lpTextMetric
);
1365 return YDEV2LOGREL(lpTextMetric
.tmHeight
);
1368 wxCoord
wxDC::GetCharWidth() const
1370 #ifdef __WXMICROWIN__
1371 if (!GetHDC()) return 0;
1374 TEXTMETRIC lpTextMetric
;
1376 GetTextMetrics(GetHdc(), &lpTextMetric
);
1378 return XDEV2LOGREL(lpTextMetric
.tmAveCharWidth
);
1381 void wxDC::DoGetTextExtent(const wxString
& string
, wxCoord
*x
, wxCoord
*y
,
1382 wxCoord
*descent
, wxCoord
*externalLeading
,
1385 #ifdef __WXMICROWIN__
1390 if (descent
) *descent
= 0;
1391 if (externalLeading
) *externalLeading
= 0;
1399 wxASSERT_MSG( font
->Ok(), _T("invalid font in wxDC::GetTextExtent") );
1401 hfontOld
= (HFONT
)::SelectObject(GetHdc(), GetHfontOf(*font
));
1403 else // don't change the font
1411 GetTextExtentPoint(GetHdc(), string
, string
.length(), &sizeRect
);
1412 GetTextMetrics(GetHdc(), &tm
);
1414 if (x
) *x
= XDEV2LOGREL(sizeRect
.cx
);
1415 if (y
) *y
= YDEV2LOGREL(sizeRect
.cy
);
1416 if (descent
) *descent
= tm
.tmDescent
;
1417 if (externalLeading
) *externalLeading
= tm
.tmExternalLeading
;
1421 ::SelectObject(GetHdc(), hfontOld
);
1425 void wxDC::SetMapMode(int mode
)
1427 #ifdef __WXMICROWIN__
1428 if (!GetHDC()) return;
1431 m_mappingMode
= mode
;
1433 int pixel_width
= 0;
1434 int pixel_height
= 0;
1438 pixel_width
= GetDeviceCaps(GetHdc(), HORZRES
);
1439 pixel_height
= GetDeviceCaps(GetHdc(), VERTRES
);
1440 mm_width
= GetDeviceCaps(GetHdc(), HORZSIZE
);
1441 mm_height
= GetDeviceCaps(GetHdc(), VERTSIZE
);
1443 if ((pixel_width
== 0) || (pixel_height
== 0) || (mm_width
== 0) || (mm_height
== 0))
1448 double mm2pixelsX
= pixel_width
/mm_width
;
1449 double mm2pixelsY
= pixel_height
/mm_height
;
1455 m_logicalScaleX
= (twips2mm
* mm2pixelsX
);
1456 m_logicalScaleY
= (twips2mm
* mm2pixelsY
);
1461 m_logicalScaleX
= (pt2mm
* mm2pixelsX
);
1462 m_logicalScaleY
= (pt2mm
* mm2pixelsY
);
1467 m_logicalScaleX
= mm2pixelsX
;
1468 m_logicalScaleY
= mm2pixelsY
;
1473 m_logicalScaleX
= (mm2pixelsX
/10.0);
1474 m_logicalScaleY
= (mm2pixelsY
/10.0);
1480 m_logicalScaleX
= 1.0;
1481 m_logicalScaleY
= 1.0;
1486 if (::GetMapMode(GetHdc()) != MM_ANISOTROPIC
)
1487 ::SetMapMode(GetHdc(), MM_ANISOTROPIC
);
1489 SetViewportExtEx(GetHdc(), VIEWPORT_EXTENT
, VIEWPORT_EXTENT
, NULL
);
1490 m_windowExtX
= (int)MS_XDEV2LOGREL(VIEWPORT_EXTENT
);
1491 m_windowExtY
= (int)MS_YDEV2LOGREL(VIEWPORT_EXTENT
);
1492 ::SetWindowExtEx(GetHdc(), m_windowExtX
, m_windowExtY
, NULL
);
1493 ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX
, (int)m_deviceOriginY
, NULL
);
1494 ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX
, (int)m_logicalOriginY
, NULL
);
1497 void wxDC::SetUserScale(double x
, double y
)
1499 #ifdef __WXMICROWIN__
1500 if (!GetHDC()) return;
1506 SetMapMode(m_mappingMode
);
1509 void wxDC::SetAxisOrientation(bool xLeftRight
, bool yBottomUp
)
1511 #ifdef __WXMICROWIN__
1512 if (!GetHDC()) return;
1515 m_signX
= xLeftRight
? 1 : -1;
1516 m_signY
= yBottomUp
? -1 : 1;
1518 SetMapMode(m_mappingMode
);
1521 void wxDC::SetSystemScale(double x
, double y
)
1523 #ifdef __WXMICROWIN__
1524 if (!GetHDC()) return;
1530 SetMapMode(m_mappingMode
);
1533 void wxDC::SetLogicalOrigin(wxCoord x
, wxCoord y
)
1535 #ifdef __WXMICROWIN__
1536 if (!GetHDC()) return;
1539 m_logicalOriginX
= x
;
1540 m_logicalOriginY
= y
;
1542 ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX
, (int)m_logicalOriginY
, NULL
);
1545 void wxDC::SetDeviceOrigin(wxCoord x
, wxCoord y
)
1547 #ifdef __WXMICROWIN__
1548 if (!GetHDC()) return;
1551 m_deviceOriginX
= x
;
1552 m_deviceOriginY
= y
;
1554 ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX
, (int)m_deviceOriginY
, NULL
);
1557 // ---------------------------------------------------------------------------
1558 // coordinates transformations
1559 // ---------------------------------------------------------------------------
1561 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
1563 double xRel
= x
- m_deviceOriginX
;
1564 xRel
/= m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
;
1565 return (wxCoord
)(xRel
+ m_logicalOriginX
);
1568 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
1570 return (wxCoord
) ((x
)/(m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
));
1573 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
1575 double yRel
= y
- m_deviceOriginY
;
1576 yRel
/= m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
;
1577 return (wxCoord
)(yRel
+ m_logicalOriginY
);
1580 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
1582 return (wxCoord
) ((y
)/(m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
));
1585 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
1587 return (wxCoord
) ((x
- m_logicalOriginX
)*m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
+ m_deviceOriginX
);
1590 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
1592 return (wxCoord
) (x
*m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
);
1595 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
1597 return (wxCoord
) ((y
- m_logicalOriginY
)*m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
+ m_deviceOriginY
);
1600 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
1602 return (wxCoord
) (y
*m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
);
1605 // ---------------------------------------------------------------------------
1607 // ---------------------------------------------------------------------------
1609 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
,
1610 wxCoord width
, wxCoord height
,
1611 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
1612 int rop
, bool useMask
)
1614 #ifdef __WXMICROWIN__
1615 if (!GetHDC()) return FALSE
;
1618 wxMask
*mask
= NULL
;
1621 const wxBitmap
& bmp
= source
->m_selectedBitmap
;
1622 mask
= bmp
.GetMask();
1624 if ( !(bmp
.Ok() && mask
&& mask
->GetMaskBitmap()) )
1626 // don't give assert here because this would break existing
1627 // programs - just silently ignore useMask parameter
1632 COLORREF old_textground
= ::GetTextColor(GetHdc());
1633 COLORREF old_background
= ::GetBkColor(GetHdc());
1634 if (m_textForegroundColour
.Ok())
1636 ::SetTextColor(GetHdc(), m_textForegroundColour
.GetPixel() );
1638 if (m_textBackgroundColour
.Ok())
1640 ::SetBkColor(GetHdc(), m_textBackgroundColour
.GetPixel() );
1643 DWORD dwRop
= SRCCOPY
;
1646 case wxXOR
: dwRop
= SRCINVERT
; break;
1647 case wxINVERT
: dwRop
= DSTINVERT
; break;
1648 case wxOR_REVERSE
: dwRop
= 0x00DD0228; break;
1649 case wxAND_REVERSE
: dwRop
= SRCERASE
; break;
1650 case wxCLEAR
: dwRop
= BLACKNESS
; break;
1651 case wxSET
: dwRop
= WHITENESS
; break;
1652 case wxOR_INVERT
: dwRop
= MERGEPAINT
; break;
1653 case wxAND
: dwRop
= SRCAND
; break;
1654 case wxOR
: dwRop
= SRCPAINT
; break;
1655 case wxEQUIV
: dwRop
= 0x00990066; break;
1656 case wxNAND
: dwRop
= 0x007700E6; break;
1657 case wxAND_INVERT
: dwRop
= 0x00220326; break;
1658 case wxCOPY
: dwRop
= SRCCOPY
; break;
1659 case wxNO_OP
: dwRop
= DSTCOPY
; break;
1660 case wxSRC_INVERT
: dwRop
= NOTSRCCOPY
; break;
1661 case wxNOR
: dwRop
= NOTSRCCOPY
; break;
1663 wxFAIL_MSG( wxT("unsupported logical function") );
1667 bool success
= FALSE
;
1672 // we want the part of the image corresponding to the mask to be
1673 // transparent, so use "DSTCOPY" ROP for the mask points (the usual
1674 // meaning of fg and bg is inverted which corresponds to wxWin notion
1675 // of the mask which is also contrary to the Windows one)
1677 // On some systems, MaskBlt succeeds yet is much much slower
1678 // than the wxWindows fall-back implementation. So we need
1679 // to be able to switch this on and off at runtime.
1680 if (wxSystemSettings::GetOptionInt(wxT("no-maskblt")) == 0)
1682 success
= ::MaskBlt(GetHdc(), xdest
, ydest
, width
, height
,
1683 GetHdcOf(*source
), xsrc
, ysrc
,
1684 (HBITMAP
)mask
->GetMaskBitmap(), xsrc
, ysrc
,
1685 MAKEROP4(dwRop
, DSTCOPY
)) != 0;
1691 // Blit bitmap with mask
1693 // create a temp buffer bitmap and DCs to access it and the mask
1694 HDC dc_mask
= ::CreateCompatibleDC(GetHdcOf(*source
));
1695 HDC dc_buffer
= ::CreateCompatibleDC(GetHdc());
1696 HBITMAP buffer_bmap
= ::CreateCompatibleBitmap(GetHdc(), width
, height
);
1697 ::SelectObject(dc_mask
, (HBITMAP
) mask
->GetMaskBitmap());
1698 ::SelectObject(dc_buffer
, buffer_bmap
);
1700 // copy dest to buffer
1701 if ( !::BitBlt(dc_buffer
, 0, 0, (int)width
, (int)height
,
1702 GetHdc(), xdest
, ydest
, SRCCOPY
) )
1704 wxLogLastError(wxT("BitBlt"));
1707 // copy src to buffer using selected raster op
1708 if ( !::BitBlt(dc_buffer
, 0, 0, (int)width
, (int)height
,
1709 GetHdcOf(*source
), xsrc
, ysrc
, dwRop
) )
1711 wxLogLastError(wxT("BitBlt"));
1714 // set masked area in buffer to BLACK (pixel value 0)
1715 COLORREF prevBkCol
= ::SetBkColor(GetHdc(), RGB(255, 255, 255));
1716 COLORREF prevCol
= ::SetTextColor(GetHdc(), RGB(0, 0, 0));
1717 if ( !::BitBlt(dc_buffer
, 0, 0, (int)width
, (int)height
,
1718 dc_mask
, xsrc
, ysrc
, SRCAND
) )
1720 wxLogLastError(wxT("BitBlt"));
1723 // set unmasked area in dest to BLACK
1724 ::SetBkColor(GetHdc(), RGB(0, 0, 0));
1725 ::SetTextColor(GetHdc(), RGB(255, 255, 255));
1726 if ( !::BitBlt(GetHdc(), xdest
, ydest
, (int)width
, (int)height
,
1727 dc_mask
, xsrc
, ysrc
, SRCAND
) )
1729 wxLogLastError(wxT("BitBlt"));
1731 ::SetBkColor(GetHdc(), prevBkCol
); // restore colours to original values
1732 ::SetTextColor(GetHdc(), prevCol
);
1734 // OR buffer to dest
1735 success
= ::BitBlt(GetHdc(), xdest
, ydest
,
1736 (int)width
, (int)height
,
1737 dc_buffer
, 0, 0, SRCPAINT
) != 0;
1740 wxLogLastError(wxT("BitBlt"));
1743 // tidy up temporary DCs and bitmap
1744 ::SelectObject(dc_mask
, 0);
1745 ::DeleteDC(dc_mask
);
1746 ::SelectObject(dc_buffer
, 0);
1747 ::DeleteDC(dc_buffer
);
1748 ::DeleteObject(buffer_bmap
);
1751 else // no mask, just BitBlt() it
1753 success
= ::BitBlt(GetHdc(), xdest
, ydest
,
1754 (int)width
, (int)height
,
1755 GetHdcOf(*source
), xsrc
, ysrc
, dwRop
) != 0;
1758 wxLogLastError(wxT("BitBlt"));
1761 ::SetTextColor(GetHdc(), old_textground
);
1762 ::SetBkColor(GetHdc(), old_background
);
1767 void wxDC::DoGetSize(int *w
, int *h
) const
1769 #ifdef __WXMICROWIN__
1770 if (!GetHDC()) return;
1773 if ( w
) *w
= ::GetDeviceCaps(GetHdc(), HORZRES
);
1774 if ( h
) *h
= ::GetDeviceCaps(GetHdc(), VERTRES
);
1777 void wxDC::DoGetSizeMM(int *w
, int *h
) const
1779 #ifdef __WXMICROWIN__
1780 if (!GetHDC()) return;
1783 if ( w
) *w
= ::GetDeviceCaps(GetHdc(), HORZSIZE
);
1784 if ( h
) *h
= ::GetDeviceCaps(GetHdc(), VERTSIZE
);
1787 wxSize
wxDC::GetPPI() const
1789 #ifdef __WXMICROWIN__
1790 if (!GetHDC()) return wxSize();
1793 int x
= ::GetDeviceCaps(GetHdc(), LOGPIXELSX
);
1794 int y
= ::GetDeviceCaps(GetHdc(), LOGPIXELSY
);
1796 return wxSize(x
, y
);
1799 // For use by wxWindows only, unless custom units are required.
1800 void wxDC::SetLogicalScale(double x
, double y
)
1802 #ifdef __WXMICROWIN__
1803 if (!GetHDC()) return;
1806 m_logicalScaleX
= x
;
1807 m_logicalScaleY
= y
;
1810 #if WXWIN_COMPATIBILITY
1811 void wxDC::DoGetTextExtent(const wxString
& string
, float *x
, float *y
,
1812 float *descent
, float *externalLeading
,
1813 wxFont
*theFont
, bool use16bit
) const
1815 #ifdef __WXMICROWIN__
1816 if (!GetHDC()) return;
1819 wxCoord x1
, y1
, descent1
, externalLeading1
;
1820 GetTextExtent(string
, & x1
, & y1
, & descent1
, & externalLeading1
, theFont
, use16bit
);
1823 *descent
= descent1
;
1824 if (externalLeading
)
1825 *externalLeading
= externalLeading1
;