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