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