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