]> git.saurik.com Git - wxWidgets.git/blame - src/msw/dc.cpp
compilation fix for SIZEOF_WCHAR_T being undefined
[wxWidgets.git] / src / msw / dc.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: dc.cpp
3// Purpose: wxDC class
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
fd3f686c 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
a23fd0e1
VZ
12// ===========================================================================
13// declarations
14// ===========================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
2bda0e17 20#ifdef __GNUG__
a23fd0e1 21 #pragma implementation "dc.h"
2bda0e17
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
a23fd0e1 28 #pragma hdrstop
2bda0e17
KB
29#endif
30
31#ifndef WX_PRECOMP
4286a5b5 32 #include "wx/window.h"
a23fd0e1
VZ
33 #include "wx/dc.h"
34 #include "wx/utils.h"
35 #include "wx/dialog.h"
36 #include "wx/app.h"
37 #include "wx/bitmap.h"
38 #include "wx/dcmemory.h"
0c589ad0 39 #include "wx/log.h"
4286a5b5 40 #include "wx/icon.h"
2bda0e17
KB
41#endif
42
43#include "wx/dcprint.h"
2bda0e17
KB
44
45#include <string.h>
46#include <math.h>
2bda0e17 47
a58a12e9
VZ
48#include "wx/msw/private.h" // needs to be before #include <commdlg.h>
49
47d67540 50#if wxUSE_COMMON_DIALOGS
a23fd0e1 51 #include <commdlg.h>
2bda0e17
KB
52#endif
53
54#ifndef __WIN32__
a23fd0e1 55 #include <print.h>
2bda0e17
KB
56#endif
57
5acb7b3e 58IMPLEMENT_ABSTRACT_CLASS(wxDC, wxDCBase)
2bda0e17 59
a23fd0e1
VZ
60// ---------------------------------------------------------------------------
61// constants
62// ---------------------------------------------------------------------------
63
42e69d6b
VZ
64static const int VIEWPORT_EXTENT = 1000;
65
66static const int MM_POINTS = 9;
67static const int MM_METRIC = 10;
a23fd0e1 68
4314ec48
VZ
69// usually this is defined in math.h
70#ifndef M_PI
71 static const double M_PI = 3.14159265358979323846;
72#endif // M_PI
73
4aff28fc
VZ
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
77
4314ec48
VZ
78// ---------------------------------------------------------------------------
79// private functions
80// ---------------------------------------------------------------------------
81
82// convert degrees to radians
83static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
84
f6bcfd97
BP
85// ----------------------------------------------------------------------------
86// private classes
87// ----------------------------------------------------------------------------
88
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
92
93// wxColourChanger: changes the text colours in the ctor if required and
94// restores them in the dtor
95class wxColourChanger
96{
97public:
98 wxColourChanger(wxDC& dc);
99 ~wxColourChanger();
100
101private:
102 wxDC& m_dc;
103
104 COLORREF m_colFgOld, m_colBgOld;
105
106 bool m_changed;
107};
108
a23fd0e1
VZ
109// ===========================================================================
110// implementation
111// ===========================================================================
112
f6bcfd97
BP
113// ----------------------------------------------------------------------------
114// wxColourChanger
115// ----------------------------------------------------------------------------
116
117wxColourChanger::wxColourChanger(wxDC& dc) : m_dc(dc)
118{
119 if ( dc.GetBrush().GetStyle() == wxSTIPPLE_MASK_OPAQUE )
120 {
121 HDC hdc = GetHdcOf(dc);
122 m_colFgOld = ::GetTextColor(hdc);
123 m_colBgOld = ::GetBkColor(hdc);
124
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();
128 if ( colFg.Ok() )
129 {
130 ::SetBkColor(hdc, colFg.GetPixel());
131 }
132
133 const wxColour& colBg = dc.GetTextBackground();
134 if ( colBg.Ok() )
135 {
136 ::SetTextColor(hdc, colBg.GetPixel());
137 }
138
139 SetBkMode(hdc,
140 dc.GetBackgroundMode() == wxTRANSPARENT ? TRANSPARENT
141 : OPAQUE);
142
143 // flag which telsl us to undo changes in the dtor
144 m_changed = TRUE;
145 }
146 else
147 {
148 // nothing done, nothing to undo
149 m_changed = FALSE;
150 }
151}
152
153wxColourChanger::~wxColourChanger()
154{
155 if ( m_changed )
156 {
157 // restore the colours we changed
158 HDC hdc = GetHdcOf(m_dc);
159
160 ::SetBkMode(hdc, TRANSPARENT);
161 ::SetTextColor(hdc, m_colFgOld);
162 ::SetBkColor(hdc, m_colBgOld);
163 }
164}
165
a23fd0e1
VZ
166// ---------------------------------------------------------------------------
167// wxDC
168// ---------------------------------------------------------------------------
2bda0e17
KB
169
170// Default constructor
a23fd0e1 171wxDC::wxDC()
2bda0e17 172{
7bcb11d3 173 m_canvas = NULL;
a23fd0e1 174
7bcb11d3
JS
175 m_oldBitmap = 0;
176 m_oldPen = 0;
177 m_oldBrush = 0;
178 m_oldFont = 0;
179 m_oldPalette = 0;
a23fd0e1 180
7bcb11d3
JS
181 m_bOwnsDC = FALSE;
182 m_hDC = 0;
a23fd0e1 183
7bcb11d3
JS
184 m_windowExtX = VIEWPORT_EXTENT;
185 m_windowExtY = VIEWPORT_EXTENT;
2bda0e17
KB
186}
187
188
a23fd0e1 189wxDC::~wxDC()
2bda0e17 190{
7ba4fbeb
VZ
191 if ( m_hDC != 0 )
192 {
7bcb11d3 193 SelectOldObjects(m_hDC);
7ba4fbeb
VZ
194
195 // if we own the HDC, we delete it, otherwise we just release it
196
197 if ( m_bOwnsDC )
198 {
199 ::DeleteDC(GetHdc());
7bcb11d3 200 }
7ba4fbeb
VZ
201 else // we don't own our HDC
202 {
db400410
JS
203 if (m_canvas)
204 {
205 ::ReleaseDC(GetHwndOf(m_canvas), GetHdc());
206 }
207 else
208 {
209 // Must have been a wxScreenDC
210 ::ReleaseDC((HWND) NULL, GetHdc());
211 }
7ba4fbeb
VZ
212 }
213 }
2bda0e17
KB
214}
215
216// This will select current objects out of the DC,
217// which is what you have to do before deleting the
218// DC.
219void wxDC::SelectOldObjects(WXHDC dc)
220{
7bcb11d3 221 if (dc)
2bda0e17 222 {
7bcb11d3
JS
223 if (m_oldBitmap)
224 {
225 ::SelectObject((HDC) dc, (HBITMAP) m_oldBitmap);
226 if (m_selectedBitmap.Ok())
227 {
228 m_selectedBitmap.SetSelectedInto(NULL);
229 }
230 }
a23fd0e1 231 m_oldBitmap = 0;
7bcb11d3
JS
232 if (m_oldPen)
233 {
234 ::SelectObject((HDC) dc, (HPEN) m_oldPen);
235 }
a23fd0e1 236 m_oldPen = 0;
7bcb11d3
JS
237 if (m_oldBrush)
238 {
239 ::SelectObject((HDC) dc, (HBRUSH) m_oldBrush);
240 }
a23fd0e1 241 m_oldBrush = 0;
7bcb11d3
JS
242 if (m_oldFont)
243 {
244 ::SelectObject((HDC) dc, (HFONT) m_oldFont);
245 }
a23fd0e1 246 m_oldFont = 0;
7bcb11d3
JS
247 if (m_oldPalette)
248 {
249 ::SelectPalette((HDC) dc, (HPALETTE) m_oldPalette, TRUE);
250 }
a23fd0e1 251 m_oldPalette = 0;
2bda0e17 252 }
a23fd0e1
VZ
253
254 m_brush = wxNullBrush;
7bcb11d3
JS
255 m_pen = wxNullPen;
256 m_palette = wxNullPalette;
257 m_font = wxNullFont;
258 m_backgroundBrush = wxNullBrush;
259 m_selectedBitmap = wxNullBitmap;
2bda0e17
KB
260}
261
a23fd0e1
VZ
262// ---------------------------------------------------------------------------
263// clipping
264// ---------------------------------------------------------------------------
265
f547e9bb
RL
266#define DO_SET_CLIPPING_BOX() \
267{ \
268 RECT rect; \
269 \
270 GetClipBox(GetHdc(), &rect); \
271 \
272 m_clipX1 = (wxCoord) XDEV2LOG(rect.left); \
273 m_clipY1 = (wxCoord) YDEV2LOG(rect.top); \
274 m_clipX2 = (wxCoord) XDEV2LOG(rect.right); \
275 m_clipY2 = (wxCoord) YDEV2LOG(rect.bottom); \
276}
277
72cdf4c9 278void wxDC::DoSetClippingRegion(wxCoord cx, wxCoord cy, wxCoord cw, wxCoord ch)
2bda0e17 279{
7bcb11d3 280 m_clipping = TRUE;
40a89076
VZ
281
282 HRGN hrgn = ::CreateRectRgn(XLOG2DEV(cx), YLOG2DEV(cy),
f547e9bb 283 XLOG2DEV(cx + cw), YLOG2DEV(cy + ch));
40a89076
VZ
284 if ( !hrgn )
285 {
286 wxLogLastError(_T("CreateRectRgn"));
287 }
288 else
289 {
290 if ( ::SelectClipRgn(GetHdc(), hrgn) == ERROR )
291 {
292 wxLogLastError(_T("SelectClipRgn"));
293 }
294
295 DO_SET_CLIPPING_BOX()
296 }
2bda0e17
KB
297}
298
a23fd0e1 299void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region)
a724d789 300{
223d09f6 301 wxCHECK_RET( region.GetHRGN(), wxT("invalid clipping region") );
a23fd0e1 302
7bcb11d3 303 m_clipping = TRUE;
a23fd0e1 304
1e6d9499 305#ifdef __WIN16__
a23fd0e1 306 SelectClipRgn(GetHdc(), (HRGN) region.GetHRGN());
1e6d9499 307#else
a23fd0e1 308 ExtSelectClipRgn(GetHdc(), (HRGN) region.GetHRGN(), RGN_AND);
1e6d9499 309#endif
a724d789 310
f547e9bb 311 DO_SET_CLIPPING_BOX()
2bda0e17
KB
312}
313
a23fd0e1 314void wxDC::DestroyClippingRegion()
2bda0e17 315{
7bcb11d3
JS
316 if (m_clipping && m_hDC)
317 {
318 // TODO: this should restore the previous clipping region,
319 // so that OnPaint processing works correctly, and the update clipping region
320 // doesn't get destroyed after the first DestroyClippingRegion.
321 HRGN rgn = CreateRectRgn(0, 0, 32000, 32000);
a23fd0e1 322 SelectClipRgn(GetHdc(), rgn);
7bcb11d3
JS
323 DeleteObject(rgn);
324 }
325 m_clipping = FALSE;
2bda0e17
KB
326}
327
a23fd0e1
VZ
328// ---------------------------------------------------------------------------
329// query capabilities
330// ---------------------------------------------------------------------------
331
332bool wxDC::CanDrawBitmap() const
2bda0e17 333{
7bcb11d3 334 return TRUE;
2bda0e17
KB
335}
336
a23fd0e1 337bool wxDC::CanGetTextExtent() const
2bda0e17 338{
7bcb11d3 339 // What sort of display is it?
a23fd0e1
VZ
340 int technology = ::GetDeviceCaps(GetHdc(), TECHNOLOGY);
341
342 return (technology == DT_RASDISPLAY) || (technology == DT_RASPRINTER);
2bda0e17
KB
343}
344
a23fd0e1 345int wxDC::GetDepth() const
2bda0e17 346{
a23fd0e1 347 return (int)::GetDeviceCaps(GetHdc(), BITSPIXEL);
2bda0e17
KB
348}
349
a23fd0e1
VZ
350// ---------------------------------------------------------------------------
351// drawing
352// ---------------------------------------------------------------------------
353
354void wxDC::Clear()
2bda0e17 355{
7bcb11d3 356 RECT rect;
2506aab6
VZ
357 if ( m_canvas )
358 {
7bcb11d3 359 GetClientRect((HWND) m_canvas->GetHWND(), &rect);
2506aab6
VZ
360 }
361 else
7bcb11d3 362 {
eaeb6a3c
JS
363 // No, I think we should simply ignore this if printing on e.g.
364 // a printer DC.
365 // wxCHECK_RET( m_selectedBitmap.Ok(), wxT("this DC can't be cleared") );
366 if (!m_selectedBitmap.Ok())
367 return;
2506aab6 368
7bcb11d3
JS
369 rect.left = 0; rect.top = 0;
370 rect.right = m_selectedBitmap.GetWidth();
371 rect.bottom = m_selectedBitmap.GetHeight();
372 }
2506aab6 373
a23fd0e1
VZ
374 (void) ::SetMapMode(GetHdc(), MM_TEXT);
375
376 DWORD colour = GetBkColor(GetHdc());
7bcb11d3 377 HBRUSH brush = CreateSolidBrush(colour);
a23fd0e1 378 FillRect(GetHdc(), &rect, brush);
7bcb11d3 379 DeleteObject(brush);
a23fd0e1
VZ
380
381 ::SetMapMode(GetHdc(), MM_ANISOTROPIC);
382 ::SetViewportExtEx(GetHdc(), VIEWPORT_EXTENT, VIEWPORT_EXTENT, NULL);
383 ::SetWindowExtEx(GetHdc(), m_windowExtX, m_windowExtY, NULL);
384 ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX, (int)m_deviceOriginY, NULL);
385 ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX, (int)m_logicalOriginY, NULL);
386}
387
72cdf4c9 388void wxDC::DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, int style)
a23fd0e1 389{
0bafad0c
VZ
390 if ( !::ExtFloodFill(GetHdc(), XLOG2DEV(x), YLOG2DEV(y),
391 col.GetPixel(),
392 style == wxFLOOD_SURFACE ? FLOODFILLSURFACE
393 : FLOODFILLBORDER) )
394 {
395 // quoting from the MSDN docs:
396 //
397 // Following are some of the reasons this function might fail:
398 //
399 // * The filling could not be completed.
400 // * The specified point has the boundary color specified by the
401 // crColor parameter (if FLOODFILLBORDER was requested).
402 // * The specified point does not have the color specified by
403 // crColor (if FLOODFILLSURFACE was requested)
404 // * The point is outside the clipping region that is, it is not
405 // visible on the device.
406 //
f6bcfd97 407 wxLogLastError(wxT("ExtFloodFill"));
0bafad0c 408 }
a23fd0e1 409
7bcb11d3 410 CalcBoundingBox(x, y);
2bda0e17
KB
411}
412
72cdf4c9 413bool wxDC::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const
2bda0e17 414{
f6bcfd97
BP
415 wxCHECK_MSG( col, FALSE, _T("NULL colour parameter in wxDC::GetPixel") );
416
7bcb11d3 417 // get the color of the pixel
a23fd0e1 418 COLORREF pixelcolor = ::GetPixel(GetHdc(), XLOG2DEV(x), YLOG2DEV(y));
0bafad0c 419
f6bcfd97 420 wxRGBToColour(*col, pixelcolor);
dc1efb1d
JS
421
422 return TRUE;
2bda0e17
KB
423}
424
72cdf4c9 425void wxDC::DoCrossHair(wxCoord x, wxCoord y)
a23fd0e1 426{
72cdf4c9
VZ
427 wxCoord x1 = x-VIEWPORT_EXTENT;
428 wxCoord y1 = y-VIEWPORT_EXTENT;
429 wxCoord x2 = x+VIEWPORT_EXTENT;
430 wxCoord y2 = y+VIEWPORT_EXTENT;
a23fd0e1
VZ
431
432 (void)MoveToEx(GetHdc(), XLOG2DEV(x1), YLOG2DEV(y), NULL);
433 (void)LineTo(GetHdc(), XLOG2DEV(x2), YLOG2DEV(y));
434
435 (void)MoveToEx(GetHdc(), XLOG2DEV(x), YLOG2DEV(y1), NULL);
436 (void)LineTo(GetHdc(), XLOG2DEV(x), YLOG2DEV(y2));
437
7bcb11d3
JS
438 CalcBoundingBox(x1, y1);
439 CalcBoundingBox(x2, y2);
2bda0e17
KB
440}
441
72cdf4c9 442void wxDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
2bda0e17 443{
a23fd0e1
VZ
444 (void)MoveToEx(GetHdc(), XLOG2DEV(x1), YLOG2DEV(y1), NULL);
445 (void)LineTo(GetHdc(), XLOG2DEV(x2), YLOG2DEV(y2));
446
058939fc
JS
447 // Normalization: Windows doesn't draw the last point of the line.
448 // But apparently neither does GTK+, so we take it out again.
449// (void)LineTo(GetHdc(), XLOG2DEV(x2) + 1, YLOG2DEV(y2));
a23fd0e1 450
7bcb11d3
JS
451 CalcBoundingBox(x1, y1);
452 CalcBoundingBox(x2, y2);
2bda0e17
KB
453}
454
f6bcfd97
BP
455// Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
456// and ending at (x2, y2)
457void wxDC::DoDrawArc(wxCoord x1, wxCoord y1,
458 wxCoord x2, wxCoord y2,
459 wxCoord xc, wxCoord yc)
2bda0e17 460{
f6bcfd97 461 wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
2d8a5cb1 462
f6bcfd97
BP
463 double dx = xc - x1;
464 double dy = yc - y1;
465 double radius = (double)sqrt(dx*dx+dy*dy);
466 wxCoord r = (wxCoord)radius;
2d8a5cb1 467
f6bcfd97
BP
468 // treat the special case of full circle separately
469 if ( x1 == x2 && y1 == y2 )
7bcb11d3 470 {
f6bcfd97 471 DrawEllipse(xc - r, yc - r, 2*r, 2*r);
a23fd0e1 472 return;
7bcb11d3 473 }
a23fd0e1 474
72cdf4c9
VZ
475 wxCoord xx1 = XLOG2DEV(x1);
476 wxCoord yy1 = YLOG2DEV(y1);
477 wxCoord xx2 = XLOG2DEV(x2);
478 wxCoord yy2 = YLOG2DEV(y2);
479 wxCoord xxc = XLOG2DEV(xc);
480 wxCoord yyc = YLOG2DEV(yc);
481 wxCoord ray = (wxCoord) sqrt(double((xxc-xx1)*(xxc-xx1)+(yyc-yy1)*(yyc-yy1)));
a23fd0e1 482
72cdf4c9
VZ
483 wxCoord xxx1 = (wxCoord) (xxc-ray);
484 wxCoord yyy1 = (wxCoord) (yyc-ray);
485 wxCoord xxx2 = (wxCoord) (xxc+ray);
486 wxCoord yyy2 = (wxCoord) (yyc+ray);
f6bcfd97
BP
487
488 if ( m_brush.Ok() && m_brush.GetStyle() != wxTRANSPARENT )
7bcb11d3
JS
489 {
490 // Have to add 1 to bottom-right corner of rectangle
491 // to make semi-circles look right (crooked line otherwise).
492 // Unfortunately this is not a reliable method, depends
493 // on the size of shape.
494 // TODO: figure out why this happens!
f6bcfd97 495 Pie(GetHdc(),xxx1,yyy1,xxx2+1,yyy2+1, xx1,yy1,xx2,yy2);
7bcb11d3
JS
496 }
497 else
2d8a5cb1 498 {
f6bcfd97 499 Arc(GetHdc(),xxx1,yyy1,xxx2,yyy2, xx1,yy1,xx2,yy2);
2d8a5cb1 500 }
f6bcfd97
BP
501
502 CalcBoundingBox(xc - r, yc - r);
503 CalcBoundingBox(xc + r, yc + r);
2bda0e17
KB
504}
505
cd9da200
VZ
506void wxDC::DoDrawCheckMark(wxCoord x1, wxCoord y1,
507 wxCoord width, wxCoord height)
508{
509 wxCoord x2 = x1 + width,
510 y2 = y1 + height;
511
512#if defined(__WIN32__) && !defined(__SC__)
513 RECT rect;
514 rect.left = x1;
515 rect.top = y1;
516 rect.right = x2;
517 rect.bottom = y2;
518
519 DrawFrameControl(GetHdc(), &rect, DFC_MENU, DFCS_MENUCHECK);
520#else // Win16
521 // In WIN16, draw a cross
522 HPEN blackPen = ::CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
523 HPEN whiteBrush = (HPEN)::GetStockObject(WHITE_BRUSH);
e06b9569
JS
524 HPEN hPenOld = (HPEN)::SelectObject(GetHdc(), blackPen);
525 HPEN hBrushOld = (HPEN)::SelectObject(GetHdc(), whiteBrush);
cd9da200
VZ
526 ::SetROP2(GetHdc(), R2_COPYPEN);
527 Rectangle(GetHdc(), x1, y1, x2, y2);
528 MoveTo(GetHdc(), x1, y1);
529 LineTo(GetHdc(), x2, y2);
530 MoveTo(GetHdc(), x2, y1);
531 LineTo(GetHdc(), x1, y2);
532 ::SelectObject(GetHdc(), hPenOld);
533 ::SelectObject(GetHdc(), hBrushOld);
534 ::DeleteObject(blackPen);
535#endif // Win32/16
536
537 CalcBoundingBox(x1, y1);
538 CalcBoundingBox(x2, y2);
539}
540
72cdf4c9 541void wxDC::DoDrawPoint(wxCoord x, wxCoord y)
2bda0e17 542{
7bcb11d3
JS
543 COLORREF color = 0x00ffffff;
544 if (m_pen.Ok())
545 {
a23fd0e1 546 color = m_pen.GetColour().GetPixel();
7bcb11d3 547 }
a23fd0e1
VZ
548
549 SetPixel(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), color);
550
7bcb11d3 551 CalcBoundingBox(x, y);
2bda0e17
KB
552}
553
72cdf4c9 554void wxDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset,int fillStyle)
2bda0e17 555{
f6bcfd97 556 wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
de2d2cdc 557
7bcb11d3
JS
558 // Do things less efficiently if we have offsets
559 if (xoffset != 0 || yoffset != 0)
6a6c0a8b 560 {
7bcb11d3
JS
561 POINT *cpoints = new POINT[n];
562 int i;
563 for (i = 0; i < n; i++)
564 {
565 cpoints[i].x = (int)(points[i].x + xoffset);
566 cpoints[i].y = (int)(points[i].y + yoffset);
a23fd0e1 567
7bcb11d3
JS
568 CalcBoundingBox(cpoints[i].x, cpoints[i].y);
569 }
a23fd0e1
VZ
570 int prev = SetPolyFillMode(GetHdc(),fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING);
571 (void)Polygon(GetHdc(), cpoints, n);
572 SetPolyFillMode(GetHdc(),prev);
7bcb11d3
JS
573 delete[] cpoints;
574 }
575 else
576 {
577 int i;
578 for (i = 0; i < n; i++)
579 CalcBoundingBox(points[i].x, points[i].y);
a23fd0e1
VZ
580
581 int prev = SetPolyFillMode(GetHdc(),fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING);
582 (void)Polygon(GetHdc(), (POINT*) points, n);
583 SetPolyFillMode(GetHdc(),prev);
6a6c0a8b 584 }
2bda0e17
KB
585}
586
72cdf4c9 587void wxDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
2bda0e17 588{
7bcb11d3
JS
589 // Do things less efficiently if we have offsets
590 if (xoffset != 0 || yoffset != 0)
6a6c0a8b 591 {
7bcb11d3
JS
592 POINT *cpoints = new POINT[n];
593 int i;
594 for (i = 0; i < n; i++)
595 {
596 cpoints[i].x = (int)(points[i].x + xoffset);
597 cpoints[i].y = (int)(points[i].y + yoffset);
a23fd0e1 598
7bcb11d3
JS
599 CalcBoundingBox(cpoints[i].x, cpoints[i].y);
600 }
a23fd0e1 601 (void)Polyline(GetHdc(), cpoints, n);
7bcb11d3
JS
602 delete[] cpoints;
603 }
604 else
605 {
606 int i;
607 for (i = 0; i < n; i++)
608 CalcBoundingBox(points[i].x, points[i].y);
a23fd0e1
VZ
609
610 (void)Polyline(GetHdc(), (POINT*) points, n);
6a6c0a8b 611 }
2bda0e17
KB
612}
613
72cdf4c9 614void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
2bda0e17 615{
f6bcfd97 616 wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
de2d2cdc 617
72cdf4c9
VZ
618 wxCoord x2 = x + width;
619 wxCoord y2 = y + height;
a23fd0e1 620
5456b916 621 if ((m_logicalFunction == wxCOPY) && (m_pen.GetStyle() == wxTRANSPARENT))
0bafad0c 622 {
7299b1b2 623 RECT rect;
5456b916
RR
624 rect.left = XLOG2DEV(x);
625 rect.top = YLOG2DEV(y);
626 rect.right = XLOG2DEV(x2);
7299b1b2
RD
627 rect.bottom = YLOG2DEV(y2);
628 (void)FillRect(GetHdc(), &rect, (HBRUSH)m_brush.GetResourceHandle() );
5456b916
RR
629 }
630 else
631 {
632 // Windows draws the filled rectangles without outline (i.e. drawn with a
633 // transparent pen) one pixel smaller in both directions and we want them
f6bcfd97 634 // to have the same size regardless of which pen is used - adjust
5456b916
RR
635
636