]> git.saurik.com Git - wxWidgets.git/blame - src/msw/dc.cpp
Highly experimental, unstable code (for determining the
[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{
2d8a5cb1
VZ
375 COLORREF colFgOld = 0,
376 colBgOld = 0;
377
378 if (m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE)
379 {
a18db022
VZ
380 colFgOld = ::GetTextColor(GetHdc());
381 colBgOld = ::GetBkColor(GetHdc());
2d8a5cb1
VZ
382
383 if (m_textForegroundColour.Ok())
384 { //just the oposite from what is expected see help on pattern brush
385 // 1 in mask becomes bk color
386 ::SetBkColor(GetHdc(), m_textForegroundColour.GetPixel() );
387 }
388 if (m_textBackgroundColour.Ok())
389 { //just the oposite from what is expected
390 // 0 in mask becomes text color
391 ::SetTextColor(GetHdc(), m_textBackgroundColour.GetPixel() );
392 }
393
394 if (m_backgroundMode == wxTRANSPARENT)
395 SetBkMode(GetHdc(), TRANSPARENT);
396 else
397 SetBkMode(GetHdc(), OPAQUE);
398 }
399
a23fd0e1
VZ
400 double dx = xc-x1;
401 double dy = yc-y1;
7bcb11d3
JS
402 double radius = (double)sqrt(dx*dx+dy*dy) ;;
403 if (x1==x2 && x2==y2)
404 {
72cdf4c9 405 DrawEllipse(xc,yc,(wxCoord)(radius*2.0),(wxCoord)(radius*2.0));
a23fd0e1 406 return;
7bcb11d3 407 }
a23fd0e1 408
72cdf4c9
VZ
409 wxCoord xx1 = XLOG2DEV(x1);
410 wxCoord yy1 = YLOG2DEV(y1);
411 wxCoord xx2 = XLOG2DEV(x2);
412 wxCoord yy2 = YLOG2DEV(y2);
413 wxCoord xxc = XLOG2DEV(xc);
414 wxCoord yyc = YLOG2DEV(yc);
415 wxCoord ray = (wxCoord) sqrt(double((xxc-xx1)*(xxc-xx1)+(yyc-yy1)*(yyc-yy1)));
a23fd0e1
VZ
416
417 (void)MoveToEx(GetHdc(), (int) xx1, (int) yy1, NULL);
72cdf4c9
VZ
418 wxCoord xxx1 = (wxCoord) (xxc-ray);
419 wxCoord yyy1 = (wxCoord) (yyc-ray);
420 wxCoord xxx2 = (wxCoord) (xxc+ray);
421 wxCoord yyy2 = (wxCoord) (yyc+ray);
7bcb11d3
JS
422 if (m_brush.Ok() && m_brush.GetStyle() !=wxTRANSPARENT)
423 {
424 // Have to add 1 to bottom-right corner of rectangle
425 // to make semi-circles look right (crooked line otherwise).
426 // Unfortunately this is not a reliable method, depends
427 // on the size of shape.
428 // TODO: figure out why this happens!
a23fd0e1
VZ
429 Pie(GetHdc(),xxx1,yyy1,xxx2+1,yyy2+1,
430 xx1,yy1,xx2,yy2);
7bcb11d3
JS
431 }
432 else
a23fd0e1
VZ
433 Arc(GetHdc(),xxx1,yyy1,xxx2,yyy2,
434 xx1,yy1,xx2,yy2);
435
72cdf4c9
VZ
436 CalcBoundingBox((wxCoord)(xc-radius), (wxCoord)(yc-radius));
437 CalcBoundingBox((wxCoord)(xc+radius), (wxCoord)(yc+radius));
2d8a5cb1
VZ
438
439 if ( m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE )
440 {
441 // restore the colours we changed
442 ::SetBkMode(GetHdc(), TRANSPARENT);
443 ::SetTextColor(GetHdc(), colFgOld);
444 ::SetBkColor(GetHdc(), colBgOld);
445 }
2bda0e17
KB
446}
447
cd9da200
VZ
448void wxDC::DoDrawCheckMark(wxCoord x1, wxCoord y1,
449 wxCoord width, wxCoord height)
450{
451 wxCoord x2 = x1 + width,
452 y2 = y1 + height;
453
454#if defined(__WIN32__) && !defined(__SC__)
455 RECT rect;
456 rect.left = x1;
457 rect.top = y1;
458 rect.right = x2;
459 rect.bottom = y2;
460
461 DrawFrameControl(GetHdc(), &rect, DFC_MENU, DFCS_MENUCHECK);
462#else // Win16
463 // In WIN16, draw a cross
464 HPEN blackPen = ::CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
465 HPEN whiteBrush = (HPEN)::GetStockObject(WHITE_BRUSH);
e06b9569
JS
466 HPEN hPenOld = (HPEN)::SelectObject(GetHdc(), blackPen);
467 HPEN hBrushOld = (HPEN)::SelectObject(GetHdc(), whiteBrush);
cd9da200
VZ
468 ::SetROP2(GetHdc(), R2_COPYPEN);
469 Rectangle(GetHdc(), x1, y1, x2, y2);
470 MoveTo(GetHdc(), x1, y1);
471 LineTo(GetHdc(), x2, y2);
472 MoveTo(GetHdc(), x2, y1);
473 LineTo(GetHdc(), x1, y2);
474 ::SelectObject(GetHdc(), hPenOld);
475 ::SelectObject(GetHdc(), hBrushOld);
476 ::DeleteObject(blackPen);
477#endif // Win32/16
478
479 CalcBoundingBox(x1, y1);
480 CalcBoundingBox(x2, y2);
481}
482
72cdf4c9 483void wxDC::DoDrawPoint(wxCoord x, wxCoord y)
2bda0e17 484{
7bcb11d3
JS
485 COLORREF color = 0x00ffffff;
486 if (m_pen.Ok())
487 {
a23fd0e1 488 color = m_pen.GetColour().GetPixel();
7bcb11d3 489 }
a23fd0e1
VZ
490
491 SetPixel(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), color);
492
7bcb11d3 493 CalcBoundingBox(x, y);
2bda0e17
KB
494}
495
72cdf4c9 496void wxDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset,int fillStyle)
2bda0e17 497{
2d8a5cb1
VZ
498 COLORREF colFgOld = 0,
499 colBgOld = 0;
500
de2d2cdc
VZ
501 if (m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE)
502 {
a18db022
VZ
503 colFgOld = ::GetTextColor(GetHdc());
504 colBgOld = ::GetBkColor(GetHdc());
de2d2cdc
VZ
505
506 if (m_textForegroundColour.Ok())
507 { //just the oposite from what is expected see help on pattern brush
508 // 1 in mask becomes bk color
509 ::SetBkColor(GetHdc(), m_textForegroundColour.GetPixel() );
510 }
511 if (m_textBackgroundColour.Ok())
512 { //just the oposite from what is expected
513 // 0 in mask becomes text color
514 ::SetTextColor(GetHdc(), m_textBackgroundColour.GetPixel() );
515 }
516
517 if (m_backgroundMode == wxTRANSPARENT)
518 SetBkMode(GetHdc(), TRANSPARENT);
519 else
520 SetBkMode(GetHdc(), OPAQUE);
521 }
522
7bcb11d3
JS
523 // Do things less efficiently if we have offsets
524 if (xoffset != 0 || yoffset != 0)
6a6c0a8b 525 {
7bcb11d3
JS
526 POINT *cpoints = new POINT[n];
527 int i;
528 for (i = 0; i < n; i++)
529 {
530 cpoints[i].x = (int)(points[i].x + xoffset);
531 cpoints[i].y = (int)(points[i].y + yoffset);
a23fd0e1 532
7bcb11d3
JS
533 CalcBoundingBox(cpoints[i].x, cpoints[i].y);
534 }
a23fd0e1
VZ
535 int prev = SetPolyFillMode(GetHdc(),fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING);
536 (void)Polygon(GetHdc(), cpoints, n);
537 SetPolyFillMode(GetHdc(),prev);
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 int prev = SetPolyFillMode(GetHdc(),fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING);
547 (void)Polygon(GetHdc(), (POINT*) points, n);
548 SetPolyFillMode(GetHdc(),prev);
6a6c0a8b 549 }
de2d2cdc 550
2d8a5cb1 551 if ( m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE )
de2d2cdc 552 {
2d8a5cb1
VZ
553 // restore the colours we changed
554 ::SetBkMode(GetHdc(), TRANSPARENT);
555 ::SetTextColor(GetHdc(), colFgOld);
556 ::SetBkColor(GetHdc(), colBgOld);
de2d2cdc 557 }
2bda0e17
KB
558}
559
72cdf4c9 560void wxDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
2bda0e17 561{
7bcb11d3
JS
562 // Do things less efficiently if we have offsets
563 if (xoffset != 0 || yoffset != 0)
6a6c0a8b 564 {
7bcb11d3
JS
565 POINT *cpoints = new POINT[n];
566 int i;
567 for (i = 0; i < n; i++)
568 {
569 cpoints[i].x = (int)(points[i].x + xoffset);
570 cpoints[i].y = (int)(points[i].y + yoffset);
a23fd0e1 571
7bcb11d3
JS
572 CalcBoundingBox(cpoints[i].x, cpoints[i].y);
573 }
a23fd0e1 574 (void)Polyline(GetHdc(), cpoints, n);
7bcb11d3
JS
575 delete[] cpoints;
576 }
577 else
578 {
579 int i;
580 for (i = 0; i < n; i++)
581 CalcBoundingBox(points[i].x, points[i].y);
a23fd0e1
VZ
582
583 (void)Polyline(GetHdc(), (POINT*) points, n);
6a6c0a8b 584 }
2bda0e17
KB
585}
586
72cdf4c9 587void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
2bda0e17 588{
0bafad0c
VZ
589 COLORREF colFgOld = 0,
590 colBgOld = 0;
591
592 if ( m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE )
de2d2cdc 593 {
0bafad0c
VZ
594 colFgOld = ::GetTextColor(GetHdc());
595 colBgOld = ::GetBkColor(GetHdc());
de2d2cdc 596
0bafad0c
VZ
597 if ( m_textForegroundColour.Ok() )
598 {
599 // just the oposite from what is expected see help on pattern brush
600 // 1 in mask becomes bk color
601 ::SetBkColor(GetHdc(), m_textForegroundColour.GetPixel());
602 }
de2d2cdc 603
0bafad0c
VZ
604 if ( m_textBackgroundColour.Ok() )
605 {
606 // 0 in mask becomes text color
607 ::SetTextColor(GetHdc(), m_textBackgroundColour.GetPixel());
608 }
609
610 // VZ: IMHO this does strictly nothing here
611 SetBkMode(GetHdc(), m_backgroundMode == wxTRANSPARENT ? TRANSPARENT
612 : OPAQUE);
de2d2cdc
VZ
613 }
614
72cdf4c9
VZ
615 wxCoord x2 = x + width;
616 wxCoord y2 = y + height;
a23fd0e1 617
5456b916 618 if ((m_logicalFunction == wxCOPY) && (m_pen.GetStyle() == wxTRANSPARENT))
0bafad0c 619 {
7299b1b2 620 RECT rect;
5456b916
RR
621 rect.left = XLOG2DEV(x);
622 rect.top = YLOG2DEV(y);
623 rect.right = XLOG2DEV(x2);
7299b1b2
RD
624 rect.bottom = YLOG2DEV(y2);
625 (void)FillRect(GetHdc(), &rect, (HBRUSH)m_brush.GetResourceHandle() );
5456b916
RR
626 }
627 else
628 {
629 // Windows draws the filled rectangles without outline (i.e. drawn with a
630 // transparent pen) one pixel smaller in both directions and we want them
631 // to have the same size regardless of which pen is used - adjust
632
633