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
, wxObject
)
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
;
194 SelectOldObjects(m_hDC
);
196 if ( m_canvas
== NULL
)
197 ::DeleteDC(GetHdc());
199 ::ReleaseDC((HWND
)m_canvas
->GetHWND(), GetHdc());
205 // This will select current objects out of the DC,
206 // which is what you have to do before deleting the
208 void wxDC::SelectOldObjects(WXHDC dc
)
214 ::SelectObject((HDC
) dc
, (HBITMAP
) m_oldBitmap
);
215 if (m_selectedBitmap
.Ok())
217 m_selectedBitmap
.SetSelectedInto(NULL
);
223 ::SelectObject((HDC
) dc
, (HPEN
) m_oldPen
);
228 ::SelectObject((HDC
) dc
, (HBRUSH
) m_oldBrush
);
233 ::SelectObject((HDC
) dc
, (HFONT
) m_oldFont
);
238 ::SelectPalette((HDC
) dc
, (HPALETTE
) m_oldPalette
, TRUE
);
243 m_brush
= wxNullBrush
;
245 m_palette
= wxNullPalette
;
247 m_backgroundBrush
= wxNullBrush
;
248 m_selectedBitmap
= wxNullBitmap
;
251 // ---------------------------------------------------------------------------
253 // ---------------------------------------------------------------------------
255 #define DO_SET_CLIPPING_BOX() \
259 GetClipBox(GetHdc(), &rect); \
261 m_clipX1 = (wxCoord) XDEV2LOG(rect.left); \
262 m_clipY1 = (wxCoord) YDEV2LOG(rect.top); \
263 m_clipX2 = (wxCoord) XDEV2LOG(rect.right); \
264 m_clipY2 = (wxCoord) YDEV2LOG(rect.bottom); \
267 void wxDC::DoSetClippingRegion(wxCoord cx
, wxCoord cy
, wxCoord cw
, wxCoord ch
)
270 IntersectClipRect(GetHdc(), XLOG2DEV(cx
), YLOG2DEV(cy
),
271 XLOG2DEV(cx
+ cw
), YLOG2DEV(cy
+ ch
));
272 DO_SET_CLIPPING_BOX()
275 void wxDC::DoSetClippingRegionAsRegion(const wxRegion
& region
)
277 wxCHECK_RET( region
.GetHRGN(), wxT("invalid clipping region") );
282 SelectClipRgn(GetHdc(), (HRGN
) region
.GetHRGN());
284 ExtSelectClipRgn(GetHdc(), (HRGN
) region
.GetHRGN(), RGN_AND
);
287 DO_SET_CLIPPING_BOX()
290 void wxDC::DestroyClippingRegion()
292 if (m_clipping
&& m_hDC
)
294 // TODO: this should restore the previous clipping region,
295 // so that OnPaint processing works correctly, and the update clipping region
296 // doesn't get destroyed after the first DestroyClippingRegion.
297 HRGN rgn
= CreateRectRgn(0, 0, 32000, 32000);
298 SelectClipRgn(GetHdc(), rgn
);
304 // ---------------------------------------------------------------------------
305 // query capabilities
306 // ---------------------------------------------------------------------------
308 bool wxDC::CanDrawBitmap() const
313 bool wxDC::CanGetTextExtent() const
315 // What sort of display is it?
316 int technology
= ::GetDeviceCaps(GetHdc(), TECHNOLOGY
);
318 return (technology
== DT_RASDISPLAY
) || (technology
== DT_RASPRINTER
);
321 int wxDC::GetDepth() const
323 return (int)::GetDeviceCaps(GetHdc(), BITSPIXEL
);
326 // ---------------------------------------------------------------------------
328 // ---------------------------------------------------------------------------
335 GetClientRect((HWND
) m_canvas
->GetHWND(), &rect
);
339 // No, I think we should simply ignore this if printing on e.g.
341 // wxCHECK_RET( m_selectedBitmap.Ok(), wxT("this DC can't be cleared") );
342 if (!m_selectedBitmap
.Ok())
345 rect
.left
= 0; rect
.top
= 0;
346 rect
.right
= m_selectedBitmap
.GetWidth();
347 rect
.bottom
= m_selectedBitmap
.GetHeight();
350 (void) ::SetMapMode(GetHdc(), MM_TEXT
);
352 DWORD colour
= GetBkColor(GetHdc());
353 HBRUSH brush
= CreateSolidBrush(colour
);
354 FillRect(GetHdc(), &rect
, brush
);
357 ::SetMapMode(GetHdc(), MM_ANISOTROPIC
);
358 ::SetViewportExtEx(GetHdc(), VIEWPORT_EXTENT
, VIEWPORT_EXTENT
, NULL
);
359 ::SetWindowExtEx(GetHdc(), m_windowExtX
, m_windowExtY
, NULL
);
360 ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX
, (int)m_deviceOriginY
, NULL
);
361 ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX
, (int)m_logicalOriginY
, NULL
);
364 void wxDC::DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
, int style
)
366 if ( !::ExtFloodFill(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
),
368 style
== wxFLOOD_SURFACE
? FLOODFILLSURFACE
371 // quoting from the MSDN docs:
373 // Following are some of the reasons this function might fail:
375 // * The filling could not be completed.
376 // * The specified point has the boundary color specified by the
377 // crColor parameter (if FLOODFILLBORDER was requested).
378 // * The specified point does not have the color specified by
379 // crColor (if FLOODFILLSURFACE was requested)
380 // * The point is outside the clipping region that is, it is not
381 // visible on the device.
383 wxLogLastError(wxT("ExtFloodFill"));
386 CalcBoundingBox(x
, y
);
389 bool wxDC::DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const
391 wxCHECK_MSG( col
, FALSE
, _T("NULL colour parameter in wxDC::GetPixel") );
393 // get the color of the pixel
394 COLORREF pixelcolor
= ::GetPixel(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
));
396 wxRGBToColour(*col
, pixelcolor
);
401 void wxDC::DoCrossHair(wxCoord x
, wxCoord y
)
403 wxCoord x1
= x
-VIEWPORT_EXTENT
;
404 wxCoord y1
= y
-VIEWPORT_EXTENT
;
405 wxCoord x2
= x
+VIEWPORT_EXTENT
;
406 wxCoord y2
= y
+VIEWPORT_EXTENT
;
408 (void)MoveToEx(GetHdc(), XLOG2DEV(x1
), YLOG2DEV(y
), NULL
);
409 (void)LineTo(GetHdc(), XLOG2DEV(x2
), YLOG2DEV(y
));
411 (void)MoveToEx(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y1
), NULL
);
412 (void)LineTo(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y2
));
414 CalcBoundingBox(x1
, y1
);
415 CalcBoundingBox(x2
, y2
);
418 void wxDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
420 (void)MoveToEx(GetHdc(), XLOG2DEV(x1
), YLOG2DEV(y1
), NULL
);
421 (void)LineTo(GetHdc(), XLOG2DEV(x2
), YLOG2DEV(y2
));
423 // Normalization: Windows doesn't draw the last point of the line.
424 // But apparently neither does GTK+, so we take it out again.
425 // (void)LineTo(GetHdc(), XLOG2DEV(x2) + 1, YLOG2DEV(y2));
427 CalcBoundingBox(x1
, y1
);
428 CalcBoundingBox(x2
, y2
);
431 // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
432 // and ending at (x2, y2)
433 void wxDC::DoDrawArc(wxCoord x1
, wxCoord y1
,
434 wxCoord x2
, wxCoord y2
,
435 wxCoord xc
, wxCoord yc
)
437 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
441 double radius
= (double)sqrt(dx
*dx
+dy
*dy
);
442 wxCoord r
= (wxCoord
)radius
;
444 // treat the special case of full circle separately
445 if ( x1
== x2
&& y1
== y2
)
447 DrawEllipse(xc
- r
, yc
- r
, 2*r
, 2*r
);
451 wxCoord xx1
= XLOG2DEV(x1
);
452 wxCoord yy1
= YLOG2DEV(y1
);
453 wxCoord xx2
= XLOG2DEV(x2
);
454 wxCoord yy2
= YLOG2DEV(y2
);
455 wxCoord xxc
= XLOG2DEV(xc
);
456 wxCoord yyc
= YLOG2DEV(yc
);
457 wxCoord ray
= (wxCoord
) sqrt(double((xxc
-xx1
)*(xxc
-xx1
)+(yyc
-yy1
)*(yyc
-yy1
)));
459 wxCoord xxx1
= (wxCoord
) (xxc
-ray
);
460 wxCoord yyy1
= (wxCoord
) (yyc
-ray
);
461 wxCoord xxx2
= (wxCoord
) (xxc
+ray
);
462 wxCoord yyy2
= (wxCoord
) (yyc
+ray
);
464 if ( m_brush
.Ok() && m_brush
.GetStyle() != wxTRANSPARENT
)
466 // Have to add 1 to bottom-right corner of rectangle
467 // to make semi-circles look right (crooked line otherwise).
468 // Unfortunately this is not a reliable method, depends
469 // on the size of shape.
470 // TODO: figure out why this happens!
471 Pie(GetHdc(),xxx1
,yyy1
,xxx2
+1,yyy2
+1, xx1
,yy1
,xx2
,yy2
);
475 Arc(GetHdc(),xxx1
,yyy1
,xxx2
,yyy2
, xx1
,yy1
,xx2
,yy2
);
478 CalcBoundingBox(xc
- r
, yc
- r
);
479 CalcBoundingBox(xc
+ r
, yc
+ r
);
482 void wxDC::DoDrawCheckMark(wxCoord x1
, wxCoord y1
,
483 wxCoord width
, wxCoord height
)
485 wxCoord x2
= x1
+ width
,
488 #if defined(__WIN32__) && !defined(__SC__)
495 DrawFrameControl(GetHdc(), &rect
, DFC_MENU
, DFCS_MENUCHECK
);
497 // In WIN16, draw a cross
498 HPEN blackPen
= ::CreatePen(PS_SOLID
, 1, RGB(0, 0, 0));
499 HPEN whiteBrush
= (HPEN
)::GetStockObject(WHITE_BRUSH
);
500 HPEN hPenOld
= (HPEN
)::SelectObject(GetHdc(), blackPen
);
501 HPEN hBrushOld
= (HPEN
)::SelectObject(GetHdc(), whiteBrush
);
502 ::SetROP2(GetHdc(), R2_COPYPEN
);
503 Rectangle(GetHdc(), x1
, y1
, x2
, y2
);
504 MoveTo(GetHdc(), x1
, y1
);
505 LineTo(GetHdc(), x2
, y2
);
506 MoveTo(GetHdc(), x2
, y1
);
507 LineTo(GetHdc(), x1
, y2
);
508 ::SelectObject(GetHdc(), hPenOld
);
509 ::SelectObject(GetHdc(), hBrushOld
);
510 ::DeleteObject(blackPen
);
513 CalcBoundingBox(x1
, y1
);
514 CalcBoundingBox(x2
, y2
);
517 void wxDC::DoDrawPoint(wxCoord x
, wxCoord y
)
519 COLORREF color
= 0x00ffffff;
522 color
= m_pen
.GetColour().GetPixel();
525 SetPixel(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), color
);
527 CalcBoundingBox(x
, y
);
530 void wxDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
,int fillStyle
)
532 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
534 // Do things less efficiently if we have offsets
535 if (xoffset
!= 0 || yoffset
!= 0)
537 POINT
*cpoints
= new POINT
[n
];
539 for (i
= 0; i
< n
; i
++)
541 cpoints
[i
].x
= (int)(points
[i
].x
+ xoffset
);
542 cpoints
[i
].y
= (int)(points
[i
].y
+ yoffset
);
544 CalcBoundingBox(cpoints
[i
].x
, cpoints
[i
].y
);
546 int prev
= SetPolyFillMode(GetHdc(),fillStyle
==wxODDEVEN_RULE
?ALTERNATE
:WINDING
);
547 (void)Polygon(GetHdc(), cpoints
, n
);
548 SetPolyFillMode(GetHdc(),prev
);
554 for (i
= 0; i
< n
; i
++)
555 CalcBoundingBox(points
[i
].x
, points
[i
].y
);
557 int prev
= SetPolyFillMode(GetHdc(),fillStyle
==wxODDEVEN_RULE
?ALTERNATE
:WINDING
);
558 (void)Polygon(GetHdc(), (POINT
*) points
, n
);
559 SetPolyFillMode(GetHdc(),prev
);
563 void wxDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
565 // Do things less efficiently if we have offsets
566 if (xoffset
!= 0 || yoffset
!= 0)
568 POINT
*cpoints
= new POINT
[n
];
570 for (i
= 0; i
< n
; i
++)
572 cpoints
[i
].x
= (int)(points
[i
].x
+ xoffset
);
573 cpoints
[i
].y
= (int)(points
[i
].y
+ yoffset
);
575 CalcBoundingBox(cpoints
[i
].x
, cpoints
[i
].y
);
577 (void)Polyline(GetHdc(), cpoints
, n
);
583 for (i
= 0; i
< n
; i
++)
584 CalcBoundingBox(points
[i
].x
, points
[i
].y
);
586 (void)Polyline(GetHdc(), (POINT
*) points
, n
);
590 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
592 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
594 wxCoord x2
= x
+ width
;
595 wxCoord y2
= y
+ height
;
597 if ((m_logicalFunction
== wxCOPY
) && (m_pen
.GetStyle() == wxTRANSPARENT
))
600 rect
.left
= XLOG2DEV(x
);
601 rect
.top
= YLOG2DEV(y
);
602 rect
.right
= XLOG2DEV(x2
);
603 rect
.bottom
= YLOG2DEV(y2
);
604 (void)FillRect(GetHdc(), &rect
, (HBRUSH
)m_brush
.GetResourceHandle() );
608 // Windows draws the filled rectangles without outline (i.e. drawn with a
609 // transparent pen) one pixel smaller in both directions and we want them
610 // to have the same size regardless of which pen is used - adjust
612 // I wonder if this shouldn´t be done after the LOG2DEV() conversions. RR.
613 if ( m_pen
.GetStyle() == wxTRANSPARENT
)
619 (void)Rectangle(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
));
623 CalcBoundingBox(x
, y
);
624 CalcBoundingBox(x2
, y2
);
627 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
629 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
631 // Now, a negative radius value is interpreted to mean
632 // 'the proportion of the smallest X or Y dimension'
636 double smallest
= 0.0;
641 radius
= (- radius
* smallest
);
644 wxCoord x2
= (x
+width
);
645 wxCoord y2
= (y
+height
);
647 // Windows draws the filled rectangles without outline (i.e. drawn with a
648 // transparent pen) one pixel smaller in both directions and we want them
649 // to have the same size regardless of which pen is used - adjust
650 if ( m_pen
.GetStyle() == wxTRANSPARENT
)
656 (void)RoundRect(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
),
657 YLOG2DEV(y2
), (int) (2*XLOG2DEV(radius
)), (int)( 2*YLOG2DEV(radius
)));
659 CalcBoundingBox(x
, y
);
660 CalcBoundingBox(x2
, y2
);
663 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
665 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
667 wxCoord x2
= (x
+width
);
668 wxCoord y2
= (y
+height
);
670 (void)Ellipse(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
));
672 CalcBoundingBox(x
, y
);
673 CalcBoundingBox(x2
, y2
);
676 // Chris Breeze 20/5/98: first implementation of DrawEllipticArc on Windows
677 void wxDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
679 wxColourChanger
cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
684 int rx1
= XLOG2DEV(x
+w
/2);
685 int ry1
= YLOG2DEV(y
+h
/2);
692 rx1
+= (int)(100.0 * abs(w
) * cos(sa
));
693 ry1
-= (int)(100.0 * abs(h
) * m_signY
* sin(sa
));
694 rx2
+= (int)(100.0 * abs(w
) * cos(ea
));
695 ry2
-= (int)(100.0 * abs(h
) * m_signY
* sin(ea
));
697 // draw pie with NULL_PEN first and then outline otherwise a line is
698 // drawn from the start and end points to the centre
699 HPEN hpenOld
= (HPEN
) ::SelectObject(GetHdc(), (HPEN
) ::GetStockObject(NULL_PEN
));
702 (void)Pie(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
)+1, YLOG2DEV(y2
)+1,
707 (void)Pie(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
)-1, XLOG2DEV(x2
)+1, YLOG2DEV(y2
),
708 rx1
, ry1
-1, rx2
, ry2
-1);
711 ::SelectObject(GetHdc(), hpenOld
);
713 (void)Arc(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
),
716 CalcBoundingBox(x
, y
);
717 CalcBoundingBox(x2
, y2
);
720 void wxDC::DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
)
722 wxCHECK_RET( icon
.Ok(), wxT("invalid icon in DrawIcon") );
725 ::DrawIconEx(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), GetHiconOf(icon
), icon
.GetWidth(), icon
.GetHeight(), 0, NULL
, DI_NORMAL
);
727 ::DrawIcon(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
), GetHiconOf(icon
));
730 CalcBoundingBox(x
, y
);
731 CalcBoundingBox(x
+ icon
.GetWidth(), y
+ icon
.GetHeight());
734 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
736 wxCHECK_RET( bmp
.Ok(), _T("invalid bitmap in wxDC::DrawBitmap") );
738 int width
= bmp
.GetWidth(),
739 height
= bmp
.GetHeight();
741 HBITMAP hbmpMask
= 0;
745 wxMask
*mask
= bmp
.GetMask();
747 hbmpMask
= (HBITMAP
)mask
->GetMaskBitmap();
751 // don't give assert here because this would break existing
752 // programs - just silently ignore useMask parameter
760 HDC hdcMem
= ::CreateCompatibleDC(GetHdc());
761 ::SelectObject(hdcMem
, GetHbitmapOf(bmp
));
763 // use MaskBlt() with ROP which doesn't do anything to dst in the mask
765 bool ok
= ::MaskBlt(GetHdc(), x
, y
, width
, height
,
768 MAKEROP4(SRCCOPY
, DSTCOPY
)) != 0;
774 // Rather than reproduce wxDC::Blit, let's do it at the wxWin API
777 memDC
.SelectObject(bmp
);
779 Blit(x
, y
, width
, height
, &memDC
, 0, 0, wxCOPY
, useMask
);
781 memDC
.SelectObject(wxNullBitmap
);
784 else // no mask, just use BitBlt()
787 HDC memdc
= ::CreateCompatibleDC( cdc
);
788 HBITMAP hbitmap
= (HBITMAP
) bmp
.GetHBITMAP( );
790 wxASSERT_MSG( hbitmap
, wxT("bitmap is ok but HBITMAP is NULL?") );
792 COLORREF old_textground
= ::GetTextColor(GetHdc());
793 COLORREF old_background
= ::GetBkColor(GetHdc());
794 if (m_textForegroundColour
.Ok())
796 ::SetTextColor(GetHdc(), m_textForegroundColour
.GetPixel() );
798 if (m_textBackgroundColour
.Ok())
800 ::SetBkColor(GetHdc(), m_textBackgroundColour
.GetPixel() );
803 ::SelectObject( memdc
, hbitmap
);
804 ::BitBlt( cdc
, x
, y
, width
, height
, memdc
, 0, 0, SRCCOPY
);
807 ::SetTextColor(GetHdc(), old_textground
);
808 ::SetBkColor(GetHdc(), old_background
);
812 void wxDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
814 DrawAnyText(text
, x
, y
);
816 // update the bounding box
817 CalcBoundingBox(x
, y
);
820 GetTextExtent(text
, &w
, &h
);
821 CalcBoundingBox(x
+ w
, y
+ h
);
824 void wxDC::DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
)
826 // prepare for drawing the text
827 if ( m_textForegroundColour
.Ok() )
828 SetTextColor(GetHdc(), m_textForegroundColour
.GetPixel());
830 DWORD old_background
= 0;
831 if ( m_textBackgroundColour
.Ok() )
833 old_background
= SetBkColor(GetHdc(), m_textBackgroundColour
.GetPixel() );
836 SetBkMode(GetHdc(), m_backgroundMode
== wxTRANSPARENT
? TRANSPARENT
839 if ( ::TextOut(GetHdc(), XLOG2DEV(x
), YLOG2DEV(y
),
840 text
.c_str(), text
.length()) == 0 )
842 wxLogLastError(wxT("TextOut"));
845 // restore the old parameters (text foreground colour may be left because
846 // it never is set to anything else, but background should remain
847 // transparent even if we just drew an opaque string)
848 if ( m_textBackgroundColour
.Ok() )
849 (void)SetBkColor(GetHdc(), old_background
);
851 SetBkMode(GetHdc(), TRANSPARENT
);
854 void wxDC::DoDrawRotatedText(const wxString
& text
,
855 wxCoord x
, wxCoord y
,
858 // we test that we have some font because otherwise we should still use the
859 // "else" part below to avoid that DrawRotatedText(angle = 180) and
860 // DrawRotatedText(angle = 0) use different fonts (we can't use the default
861 // font for drawing rotated fonts unfortunately)
862 if ( (angle
== 0.0) && m_font
.Ok() )
864 DoDrawText(text
, x
, y
);
868 // NB: don't take DEFAULT_GUI_FONT because it's not TrueType and so
869 // can't have non zero orientation/escapement
870 wxFont font
= m_font
.Ok() ? m_font
: *wxNORMAL_FONT
;
871 HFONT hfont
= (HFONT
)font
.GetResourceHandle();
873 if ( ::GetObject(hfont
, sizeof(lf
), &lf
) == 0 )
875 wxLogLastError(wxT("GetObject(hfont)"));
878 // GDI wants the angle in tenth of degree
879 long angle10
= (long)(angle
* 10);
880 lf
.lfEscapement
= angle10
;
881 lf
. lfOrientation
= angle10
;
883 hfont
= ::CreateFontIndirect(&lf
);
886 wxLogLastError(wxT("CreateFont"));
890 HFONT hfontOld
= (HFONT
)::SelectObject(GetHdc(), hfont
);
892 DrawAnyText(text
, x
, y
);
894 (void)::SelectObject(GetHdc(), hfontOld
);
895 (void)::DeleteObject(hfont
);
898 // call the bounding box by adding all four vertices of the rectangle
899 // containing the text to it (simpler and probably not slower than
900 // determining which of them is really topmost/leftmost/...)
902 GetTextExtent(text
, &w
, &h
);
904 double rad
= DegToRad(angle
);
906 // "upper left" and "upper right"
907 CalcBoundingBox(x
, y
);
908 CalcBoundingBox(x
+ w
*cos(rad
), y
- h
*sin(rad
));
910 // "bottom left" and "bottom right"
911 x
+= (wxCoord
)(h
*sin(rad
));
912 y
+= (wxCoord
)(h
*cos(rad
));
913 CalcBoundingBox(x
, y
);
914 CalcBoundingBox(x
+ h
*sin(rad
), y
+ h
*cos(rad
));
918 // ---------------------------------------------------------------------------
920 // ---------------------------------------------------------------------------
922 void wxDC::SetPalette(const wxPalette
& palette
)
924 // Set the old object temporarily, in case the assignment deletes an object
925 // that's not yet selected out.
928 ::SelectPalette(GetHdc(), (HPALETTE
) m_oldPalette
, TRUE
);
936 // Setting a NULL colourmap is a way of restoring
937 // the original colourmap
940 ::SelectPalette(GetHdc(), (HPALETTE
) m_oldPalette
, TRUE
);
947 if (m_palette
.Ok() && m_palette
.GetHPALETTE())
949 HPALETTE oldPal
= ::SelectPalette(GetHdc(), (HPALETTE
) m_palette
.GetHPALETTE(), TRUE
);
951 m_oldPalette
= (WXHPALETTE
) oldPal
;
953 ::RealizePalette(GetHdc());
957 void wxDC::SetFont(const wxFont
& the_font
)
959 // Set the old object temporarily, in case the assignment deletes an object
960 // that's not yet selected out.
963 ::SelectObject(GetHdc(), (HFONT
) m_oldFont
);
972 ::SelectObject(GetHdc(), (HFONT
) m_oldFont
);
976 if (m_font
.Ok() && m_font
.GetResourceHandle())
978 HFONT f
= (HFONT
) ::SelectObject(GetHdc(), (HFONT
) m_font
.GetResourceHandle());
979 if (f
== (HFONT
) NULL
)
981 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
984 m_oldFont
= (WXHFONT
) f
;
988 void wxDC::SetPen(const wxPen
& pen
)
990 // Set the old object temporarily, in case the assignment deletes an object
991 // that's not yet selected out.
994 ::SelectObject(GetHdc(), (HPEN
) m_oldPen
);
1003 ::SelectObject(GetHdc(), (HPEN
) m_oldPen
);
1009 if (m_pen
.GetResourceHandle())
1011 HPEN p
= (HPEN
) ::SelectObject(GetHdc(), (HPEN
)m_pen
.GetResourceHandle());
1013 m_oldPen
= (WXHPEN
) p
;
1018 void wxDC::SetBrush(const wxBrush
& brush
)
1020 // Set the old object temporarily, in case the assignment deletes an object
1021 // that's not yet selected out.
1024 ::SelectObject(GetHdc(), (HBRUSH
) m_oldBrush
);
1033 ::SelectObject(GetHdc(), (HBRUSH
) m_oldBrush
);
1039 // to make sure the brush is alligned with the logical coordinates
1040 wxBitmap
*stipple
= m_brush
.GetStipple();
1041 if ( stipple
&& stipple
->Ok() )
1044 ::SetBrushOrgEx(GetHdc(),
1045 m_deviceOriginX
% stipple
->GetWidth(),
1046 m_deviceOriginY
% stipple
->GetHeight(),
1047 NULL
); // don't need previous brush origin
1049 ::SetBrushOrg(GetHdc(),
1050 m_deviceOriginX
% stipple
->GetWidth(),
1051 m_deviceOriginY
% stipple
->GetHeight());
1055 if ( m_brush
.GetResourceHandle() )
1058 b
= (HBRUSH
) ::SelectObject(GetHdc(), (HBRUSH
)m_brush
.GetResourceHandle());
1060 m_oldBrush
= (WXHBRUSH
) b
;
1065 void wxDC::SetBackground(const wxBrush
& brush
)
1067 m_backgroundBrush
= brush
;
1069 if (!m_backgroundBrush
.Ok())
1074 bool customColours
= TRUE
;
1075 // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
1076 // change background colours from the control-panel specified colours.
1077 if (m_canvas
->IsKindOf(CLASSINFO(wxWindow
)) && ((m_canvas
->GetWindowStyleFlag() & wxUSER_COLOURS
) != wxUSER_COLOURS
))
1078 customColours
= FALSE
;
1082 if (m_backgroundBrush
.GetStyle()==wxTRANSPARENT
)
1084 m_canvas
->SetTransparent(TRUE
);
1088 // New behaviour, 10/2/99: setting the background brush of a DC
1089 // doesn't affect the window background colour. However,
1090 // I'm leaving in the transparency setting because it's needed by
1091 // various controls (e.g. wxStaticText) to determine whether to draw
1092 // transparently or not. TODO: maybe this should be a new function
1093 // wxWindow::SetTransparency(). Should that apply to the child itself, or the
1095 // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour());
1096 m_canvas
->SetTransparent(FALSE
);
1100 COLORREF new_color
= m_backgroundBrush
.GetColour().GetPixel();
1102 (void)SetBkColor(GetHdc(), new_color
);
1106 void wxDC::SetBackgroundMode(int mode
)
1108 m_backgroundMode
= mode
;
1110 // SetBackgroundColour now only refers to text background
1111 // and m_backgroundMode is used there
1114 if (m_backgroundMode == wxTRANSPARENT)
1115 ::SetBkMode(GetHdc(), TRANSPARENT);
1117 ::SetBkMode(GetHdc(), OPAQUE);
1121 void wxDC::SetLogicalFunction(int function
)
1123 m_logicalFunction
= function
;
1128 void wxDC::SetRop(WXHDC dc
)
1130 if ( !dc
|| m_logicalFunction
< 0 )
1135 switch (m_logicalFunction
)
1137 case wxCLEAR
: rop
= R2_BLACK
; break;
1138 case wxXOR
: rop
= R2_XORPEN
; break;
1139 case wxINVERT
: rop
= R2_NOT
; break;
1140 case wxOR_REVERSE
: rop
= R2_MERGEPENNOT
; break;
1141 case wxAND_REVERSE
: rop
= R2_MASKPENNOT
; break;
1142 case wxCOPY
: rop
= R2_COPYPEN
; break;
1143 case wxAND
: rop
= R2_MASKPEN
; break;
1144 case wxAND_INVERT
: rop
= R2_MASKNOTPEN
; break;
1145 case wxNO_OP
: rop
= R2_NOP
; break;
1146 case wxNOR
: rop
= R2_NOTMERGEPEN
; break;
1147 case wxEQUIV
: rop
= R2_NOTXORPEN
; break;
1148 case wxSRC_INVERT
: rop
= R2_NOTCOPYPEN
; break;
1149 case wxOR_INVERT
: rop
= R2_MERGENOTPEN
; break;
1150 case wxNAND
: rop
= R2_NOTMASKPEN
; break;
1151 case wxOR
: rop
= R2_MERGEPEN
; break;
1152 case wxSET
: rop
= R2_WHITE
; break;
1155 wxFAIL_MSG( wxT("unsupported logical function") );
1159 SetROP2(GetHdc(), rop
);
1162 bool wxDC::StartDoc(const wxString
& message
)
1164 // We might be previewing, so return TRUE to let it continue.
1172 void wxDC::StartPage()
1176 void wxDC::EndPage()
1180 // ---------------------------------------------------------------------------
1182 // ---------------------------------------------------------------------------
1184 wxCoord
wxDC::GetCharHeight() const
1186 TEXTMETRIC lpTextMetric
;
1188 GetTextMetrics(GetHdc(), &lpTextMetric
);
1190 return YDEV2LOGREL(lpTextMetric
.tmHeight
);
1193 wxCoord
wxDC::GetCharWidth() const
1195 TEXTMETRIC lpTextMetric
;
1197 GetTextMetrics(GetHdc(), &lpTextMetric
);
1199 return XDEV2LOGREL(lpTextMetric
.tmAveCharWidth
);
1202 void wxDC::DoGetTextExtent(const wxString
& string
, wxCoord
*x
, wxCoord
*y
,
1203 wxCoord
*descent
, wxCoord
*externalLeading
,
1204 wxFont
*theFont
) const
1206 wxFont
*fontToUse
= (wxFont
*) theFont
;
1208 fontToUse
= (wxFont
*) &m_font
;
1213 GetTextExtentPoint(GetHdc(), WXSTRINGCAST string
, wxStrlen(WXSTRINGCAST string
), &sizeRect
);
1214 GetTextMetrics(GetHdc(), &tm
);
1216 if (x
) *x
= XDEV2LOGREL(sizeRect
.cx
);
1217 if (y
) *y
= YDEV2LOGREL(sizeRect
.cy
);
1218 if (descent
) *descent
= tm
.tmDescent
;
1219 if (externalLeading
) *externalLeading
= tm
.tmExternalLeading
;
1222 void wxDC::SetMapMode(int mode
)
1224 m_mappingMode
= mode
;
1226 int pixel_width
= 0;
1227 int pixel_height
= 0;
1231 pixel_width
= GetDeviceCaps(GetHdc(), HORZRES
);
1232 pixel_height
= GetDeviceCaps(GetHdc(), VERTRES
);
1233 mm_width
= GetDeviceCaps(GetHdc(), HORZSIZE
);
1234 mm_height
= GetDeviceCaps(GetHdc(), VERTSIZE
);
1236 if ((pixel_width
== 0) || (pixel_height
== 0) || (mm_width
== 0) || (mm_height
== 0))
1241 double mm2pixelsX
= pixel_width
/mm_width
;
1242 double mm2pixelsY
= pixel_height
/mm_height
;
1248 m_logicalScaleX
= (twips2mm
* mm2pixelsX
);
1249 m_logicalScaleY
= (twips2mm
* mm2pixelsY
);
1254 m_logicalScaleX
= (pt2mm
* mm2pixelsX
);
1255 m_logicalScaleY
= (pt2mm
* mm2pixelsY
);
1260 m_logicalScaleX
= mm2pixelsX
;
1261 m_logicalScaleY
= mm2pixelsY
;
1266 m_logicalScaleX
= (mm2pixelsX
/10.0);
1267 m_logicalScaleY
= (mm2pixelsY
/10.0);
1273 m_logicalScaleX
= 1.0;
1274 m_logicalScaleY
= 1.0;
1279 if (::GetMapMode(GetHdc()) != MM_ANISOTROPIC
)
1280 ::SetMapMode(GetHdc(), MM_ANISOTROPIC
);
1282 SetViewportExtEx(GetHdc(), VIEWPORT_EXTENT
, VIEWPORT_EXTENT
, NULL
);
1283 m_windowExtX
= (int)MS_XDEV2LOGREL(VIEWPORT_EXTENT
);
1284 m_windowExtY
= (int)MS_YDEV2LOGREL(VIEWPORT_EXTENT
);
1285 ::SetWindowExtEx(GetHdc(), m_windowExtX
, m_windowExtY
, NULL
);
1286 ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX
, (int)m_deviceOriginY
, NULL
);
1287 ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX
, (int)m_logicalOriginY
, NULL
);
1290 void wxDC::SetUserScale(double x
, double y
)
1295 SetMapMode(m_mappingMode
);
1298 void wxDC::SetAxisOrientation(bool xLeftRight
, bool yBottomUp
)
1300 m_signX
= xLeftRight
? 1 : -1;
1301 m_signY
= yBottomUp
? -1 : 1;
1303 SetMapMode(m_mappingMode
);
1306 void wxDC::SetSystemScale(double x
, double y
)
1311 SetMapMode(m_mappingMode
);
1314 void wxDC::SetLogicalOrigin(wxCoord x
, wxCoord y
)
1316 m_logicalOriginX
= x
;
1317 m_logicalOriginY
= y
;
1319 ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX
, (int)m_logicalOriginY
, NULL
);
1322 void wxDC::SetDeviceOrigin(wxCoord x
, wxCoord y
)
1324 m_deviceOriginX
= x
;
1325 m_deviceOriginY
= y
;
1327 ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX
, (int)m_deviceOriginY
, NULL
);
1330 // ---------------------------------------------------------------------------
1331 // coordinates transformations
1332 // ---------------------------------------------------------------------------
1334 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
1336 return (wxCoord
) (((x
) - m_deviceOriginX
)/(m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
) - m_logicalOriginX
);
1339 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
1341 return (wxCoord
) ((x
)/(m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
));
1344 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
1346 return (wxCoord
) (((y
) - m_deviceOriginY
)/(m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
) - m_logicalOriginY
);
1349 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
1351 return (wxCoord
) ((y
)/(m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
));
1354 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
1356 return (wxCoord
) ((x
- m_logicalOriginX
)*m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
+ m_deviceOriginX
);
1359 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
1361 return (wxCoord
) (x
*m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
);
1364 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
1366 return (wxCoord
) ((y
- m_logicalOriginY
)*m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
+ m_deviceOriginY
);
1369 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
1371 return (wxCoord
) (y
*m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
);
1374 // ---------------------------------------------------------------------------
1376 // ---------------------------------------------------------------------------
1378 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
,
1379 wxCoord width
, wxCoord height
,
1380 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
1381 int rop
, bool useMask
)
1383 wxMask
*mask
= NULL
;
1386 const wxBitmap
& bmp
= source
->m_selectedBitmap
;
1387 mask
= bmp
.GetMask();
1389 if ( !(bmp
.Ok() && mask
&& mask
->GetMaskBitmap()) )
1391 // don't give assert here because this would break existing
1392 // programs - just silently ignore useMask parameter
1397 COLORREF old_textground
= ::GetTextColor(GetHdc());
1398 COLORREF old_background
= ::GetBkColor(GetHdc());
1399 if (m_textForegroundColour
.Ok())
1401 ::SetTextColor(GetHdc(), m_textForegroundColour
.GetPixel() );
1403 if (m_textBackgroundColour
.Ok())
1405 ::SetBkColor(GetHdc(), m_textBackgroundColour
.GetPixel() );
1408 DWORD dwRop
= SRCCOPY
;
1411 case wxXOR
: dwRop
= SRCINVERT
; break;
1412 case wxINVERT
: dwRop
= DSTINVERT
; break;
1413 case wxOR_REVERSE
: dwRop
= 0x00DD0228; break;
1414 case wxAND_REVERSE
: dwRop
= SRCERASE
; break;
1415 case wxCLEAR
: dwRop
= BLACKNESS
; break;
1416 case wxSET
: dwRop
= WHITENESS
; break;
1417 case wxOR_INVERT
: dwRop
= MERGEPAINT
; break;
1418 case wxAND
: dwRop
= SRCAND
; break;
1419 case wxOR
: dwRop
= SRCPAINT
; break;
1420 case wxEQUIV
: dwRop
= 0x00990066; break;
1421 case wxNAND
: dwRop
= 0x007700E6; break;
1422 case wxAND_INVERT
: dwRop
= 0x00220326; break;
1423 case wxCOPY
: dwRop
= SRCCOPY
; break;
1424 case wxNO_OP
: dwRop
= DSTCOPY
; break;
1425 case wxSRC_INVERT
: dwRop
= NOTSRCCOPY
; break;
1426 case wxNOR
: dwRop
= NOTSRCCOPY
; break;
1428 wxFAIL_MSG( wxT("unsupported logical function") );
1437 // we want the part of the image corresponding to the mask to be
1438 // transparent, so use "DSTCOPY" ROP for the mask points (the usual
1439 // meaning of fg and bg is inverted which corresponds to wxWin notion
1440 // of the mask which is also contrary to the Windows one)
1441 success
= ::MaskBlt(GetHdc(), xdest
, ydest
, width
, height
,
1442 GetHdcOf(*source
), xsrc
, ysrc
,
1443 (HBITMAP
)mask
->GetMaskBitmap(), 0, 0,
1444 MAKEROP4(dwRop
, DSTCOPY
)) != 0;
1449 // Blit bitmap with mask
1451 // create a temp buffer bitmap and DCs to access it and the mask
1452 HDC dc_mask
= ::CreateCompatibleDC(GetHdcOf(*source
));
1453 HDC dc_buffer
= ::CreateCompatibleDC(GetHdc());
1454 HBITMAP buffer_bmap
= ::CreateCompatibleBitmap(GetHdc(), width
, height
);
1455 ::SelectObject(dc_mask
, (HBITMAP
) mask
->GetMaskBitmap());
1456 ::SelectObject(dc_buffer
, buffer_bmap
);
1458 // copy dest to buffer
1459 if ( !::BitBlt(dc_buffer
, 0, 0, (int)width
, (int)height
,
1460 GetHdc(), xdest
, ydest
, SRCCOPY
) )
1462 wxLogLastError(wxT("BitBlt"));
1465 // copy src to buffer using selected raster op
1466 if ( !::BitBlt(dc_buffer
, 0, 0, (int)width
, (int)height
,
1467 GetHdcOf(*source
), xsrc
, ysrc
, dwRop
) )
1469 wxLogLastError(wxT("BitBlt"));
1472 // set masked area in buffer to BLACK (pixel value 0)
1473 COLORREF prevBkCol
= ::SetBkColor(GetHdc(), RGB(255, 255, 255));
1474 COLORREF prevCol
= ::SetTextColor(GetHdc(), RGB(0, 0, 0));
1475 if ( !::BitBlt(dc_buffer
, 0, 0, (int)width
, (int)height
,
1476 dc_mask
, xsrc
, ysrc
, SRCAND
) )
1478 wxLogLastError(wxT("BitBlt"));
1481 // set unmasked area in dest to BLACK
1482 ::SetBkColor(GetHdc(), RGB(0, 0, 0));
1483 ::SetTextColor(GetHdc(), RGB(255, 255, 255));
1484 if ( !::BitBlt(GetHdc(), xdest
, ydest
, (int)width
, (int)height
,
1485 dc_mask
, xsrc
, ysrc
, SRCAND
) )
1487 wxLogLastError(wxT("BitBlt"));
1489 ::SetBkColor(GetHdc(), prevBkCol
); // restore colours to original values
1490 ::SetTextColor(GetHdc(), prevCol
);
1492 // OR buffer to dest
1493 success
= ::BitBlt(GetHdc(), xdest
, ydest
,
1494 (int)width
, (int)height
,
1495 dc_buffer
, 0, 0, SRCPAINT
) != 0;
1498 wxLogLastError(wxT("BitBlt"));
1501 // tidy up temporary DCs and bitmap
1502 ::SelectObject(dc_mask
, 0);
1503 ::DeleteDC(dc_mask
);
1504 ::SelectObject(dc_buffer
, 0);
1505 ::DeleteDC(dc_buffer
);
1506 ::DeleteObject(buffer_bmap
);
1509 else // no mask, just BitBlt() it
1511 success
= ::BitBlt(GetHdc(), xdest
, ydest
,
1512 (int)width
, (int)height
,
1513 GetHdcOf(*source
), xsrc
, ysrc
, dwRop
) != 0;
1516 wxLogLastError(wxT("BitBlt"));
1519 ::SetTextColor(GetHdc(), old_textground
);
1520 ::SetBkColor(GetHdc(), old_background
);
1525 void wxDC::DoGetSize(int *w
, int *h
) const
1527 if ( w
) *w
= ::GetDeviceCaps(GetHdc(), HORZRES
);
1528 if ( h
) *h
= ::GetDeviceCaps(GetHdc(), VERTRES
);
1531 void wxDC::DoGetSizeMM(int *w
, int *h
) const
1533 if ( w
) *w
= ::GetDeviceCaps(GetHdc(), HORZSIZE
);
1534 if ( h
) *h
= ::GetDeviceCaps(GetHdc(), VERTSIZE
);
1537 wxSize
wxDC::GetPPI() const
1539 int x
= ::GetDeviceCaps(GetHdc(), LOGPIXELSX
);
1540 int y
= ::GetDeviceCaps(GetHdc(), LOGPIXELSY
);
1542 return wxSize(x
, y
);
1545 // For use by wxWindows only, unless custom units are required.
1546 void wxDC::SetLogicalScale(double x
, double y
)
1548 m_logicalScaleX
= x
;
1549 m_logicalScaleY
= y
;
1552 #if WXWIN_COMPATIBILITY
1553 void wxDC::DoGetTextExtent(const wxString
& string
, float *x
, float *y
,
1554 float *descent
, float *externalLeading
,
1555 wxFont
*theFont
, bool use16bit
) const
1557 wxCoord x1
, y1
, descent1
, externalLeading1
;
1558 GetTextExtent(string
, & x1
, & y1
, & descent1
, & externalLeading1
, theFont
, use16bit
);
1561 *descent
= descent1
;
1562 if (externalLeading
)
1563 *externalLeading
= externalLeading1
;
1567 // ---------------------------------------------------------------------------
1568 // spline drawing code
1569 // ---------------------------------------------------------------------------
1573 class wxSpline
: public wxObject
1579 wxSpline(wxList
*list
);
1580 void DeletePoints();
1582 // Doesn't delete points
1586 void wx_draw_open_spline(wxDC
*dc
, wxSpline
*spline
);
1588 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
,
1589 double a3
, double b3
, double a4
, double b4
);
1590 void wx_clear_stack();
1591 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
, double *x3
,
1592 double *y3
, double *x4
, double *y4
);
1593 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
,
1594 double x4
, double y4
);
1595 static bool wx_spline_add_point(double x
, double y
);
1596 static void wx_spline_draw_point_array(wxDC
*dc
);
1597 wxSpline
*wx_make_spline(int x1
, int y1
, int x2
, int y2
, int x3
, int y3
);
1599 void wxDC::DoDrawSpline(wxList
*list
)
1601 wxSpline
spline(list
);
1603 wx_draw_open_spline(this, &spline
);
1606 wxList wx_spline_point_list
;
1608 void wx_draw_open_spline(wxDC
*dc
, wxSpline
*spline
)
1611 double cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
;
1612 double x1
, y1
, x2
, y2
;
1614 wxNode
*node
= spline
->points
->First();
1615 p
= (wxPoint
*)node
->Data();
1620 node
= node
->Next();
1621 p
= (wxPoint
*)node
->Data();
1625 cx1
= (double)((x1
+ x2
) / 2);
1626 cy1
= (double)((y1
+ y2
) / 2);
1627 cx2
= (double)((cx1
+ x2
) / 2);
1628 cy2
= (double)((cy1
+ y2
) / 2);
1630 wx_spline_add_point(x1
, y1
);
1632 while ((node
= node
->Next()) != NULL
)
1634 p
= (wxPoint
*)node
->Data();
1639 cx4
= (double)(x1
+ x2
) / 2;
1640 cy4
= (double)(y1
+ y2
) / 2;
1641 cx3
= (double)(x1
+ cx4
) / 2;
1642 cy3
= (double)(y1
+ cy4
) / 2;
1644 wx_quadratic_spline(cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
);
1648 cx2
= (double)(cx1
+ x2
) / 2;
1649 cy2
= (double)(cy1
+ y2
) / 2;
1652 wx_spline_add_point((double)wx_round(cx1
), (double)wx_round(cy1
));
1653 wx_spline_add_point(x2
, y2
);
1655 wx_spline_draw_point_array(dc
);
1659 /********************* CURVES FOR SPLINES *****************************
1661 The following spline drawing routine is from
1663 "An Algorithm for High-Speed Curve Generation"
1664 by George Merrill Chaikin,
1665 Computer Graphics and Image Processing, 3, Academic Press,
1670 "On Chaikin's Algorithm" by R. F. Riesenfeld,
1671 Computer Graphics and Image Processing, 4, Academic Press,
1674 ***********************************************************************/
1676 #define half(z1, z2) ((z1+z2)/2.0)
1679 /* iterative version */
1681 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
, double a3
, double b3
, double a4
,
1684 register double xmid
, ymid
;
1685 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
1688 wx_spline_push(a1
, b1
, a2
, b2
, a3
, b3
, a4
, b4
);
1690 while (wx_spline_pop(&x1
, &y1
, &x2
, &y2
, &x3
, &y3
, &x4
, &y4
)) {
1691 xmid
= (double)half(x2
, x3
);
1692 ymid
= (double)half(y2
, y3
);
1693 if (fabs(x1
- xmid
) < THRESHOLD
&& fabs(y1
- ymid
) < THRESHOLD
&&
1694 fabs(xmid
- x4
) < THRESHOLD
&& fabs(ymid
- y4
) < THRESHOLD
) {
1695 wx_spline_add_point((double)wx_round(x1
), (double)wx_round(y1
));
1696 wx_spline_add_point((double)wx_round(xmid
), (double)wx_round(ymid
));
1698 wx_spline_push(xmid
, ymid
, (double)half(xmid
, x3
), (double)half(ymid
, y3
),
1699 (double)half(x3
, x4
), (double)half(y3
, y4
), x4
, y4
);
1700 wx_spline_push(x1
, y1
, (double)half(x1
, x2
), (double)half(y1
, y2
),
1701 (double)half(x2
, xmid
), (double)half(y2
, ymid
), xmid
, ymid
);
1707 /* utilities used by spline drawing routines */
1710 typedef struct wx_spline_stack_struct
{
1711 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
1715 #define SPLINE_STACK_DEPTH 20
1716 static Stack wx_spline_stack
[SPLINE_STACK_DEPTH
];
1717 static Stack
*wx_stack_top
;
1718 static int wx_stack_count
;
1720 void wx_clear_stack()
1722 wx_stack_top
= wx_spline_stack
;
1726 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
, double x4
, double y4
)
1728 wx_stack_top
->x1
= x1
;
1729 wx_stack_top
->y1
= y1
;
1730 wx_stack_top
->x2
= x2
;
1731 wx_stack_top
->y2
= y2
;
1732 wx_stack_top
->x3
= x3
;
1733 wx_stack_top
->y3
= y3
;
1734 wx_stack_top
->x4
= x4
;
1735 wx_stack_top
->y4
= y4
;
1740 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
,
1741 double *x3
, double *y3
, double *x4
, double *y4
)
1743 if (wx_stack_count
== 0)
1747 *x1
= wx_stack_top
->x1
;
1748 *y1
= wx_stack_top
->y1
;
1749 *x2
= wx_stack_top
->x2
;
1750 *y2
= wx_stack_top
->y2
;
1751 *x3
= wx_stack_top
->x3
;
1752 *y3
= wx_stack_top
->y3
;
1753 *x4
= wx_stack_top
->x4
;
1754 *y4
= wx_stack_top
->y4
;
1758 static bool wx_spline_add_point(double x
, double y
)
1760 wxPoint
*point
= new wxPoint
;
1763 wx_spline_point_list
.Append((wxObject
*)point
);
1767 static void wx_spline_draw_point_array(wxDC
*dc
)
1769 dc
->DrawLines(&wx_spline_point_list
, 0, 0);
1770 wxNode
*node
= wx_spline_point_list
.First();
1773 wxPoint
*point
= (wxPoint
*)node
->Data();
1776 node
= wx_spline_point_list
.First();
1780 wxSpline::wxSpline(wxList
*list
)
1785 wxSpline::~wxSpline()
1789 void wxSpline::DeletePoints()
1791 for(wxNode
*node
= points
->First(); node
; node
= points
->First())
1793 wxPoint
*point
= (wxPoint
*)node
->Data();
1801 #endif // wxUSE_SPLINES