]> git.saurik.com Git - wxWidgets.git/blame - src/msw/dc.cpp
No #if wxUSE_DRAG_AND_DROP around the wxMetafileDataObject class, so compilation...
[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
47d67540 48#if wxUSE_COMMON_DIALOGS
65fd5cb0
RS
49#if wxUSE_NORLANDER_HEADERS
50 #include <windows.h>
51#endif
a23fd0e1 52 #include <commdlg.h>
2bda0e17
KB
53#endif
54
55#ifndef __WIN32__
a23fd0e1 56 #include <print.h>
2bda0e17
KB
57#endif
58
4286a5b5
RR
59#include "wx/msw/private.h"
60
a23fd0e1 61 IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
2bda0e17 62
a23fd0e1
VZ
63// ---------------------------------------------------------------------------
64// constants
65// ---------------------------------------------------------------------------
66
42e69d6b
VZ
67static const int VIEWPORT_EXTENT = 1000;
68
69static const int MM_POINTS = 9;
70static const int MM_METRIC = 10;
a23fd0e1 71
4314ec48
VZ
72// usually this is defined in math.h
73#ifndef M_PI
74 static const double M_PI = 3.14159265358979323846;
75#endif // M_PI
76
77// ---------------------------------------------------------------------------
78// private functions
79// ---------------------------------------------------------------------------
80
81// convert degrees to radians
82static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
83
a23fd0e1
VZ
84// ===========================================================================
85// implementation
86// ===========================================================================
87
88// ---------------------------------------------------------------------------
89// wxDC
90// ---------------------------------------------------------------------------
2bda0e17
KB
91
92// Default constructor
a23fd0e1 93wxDC::wxDC()
2bda0e17 94{
7bcb11d3 95 m_canvas = NULL;
a23fd0e1 96
7bcb11d3
JS
97 m_oldBitmap = 0;
98 m_oldPen = 0;
99 m_oldBrush = 0;
100 m_oldFont = 0;
101 m_oldPalette = 0;
a23fd0e1 102
7bcb11d3
JS
103 m_bOwnsDC = FALSE;
104 m_hDC = 0;
a23fd0e1 105
7bcb11d3
JS
106 m_windowExtX = VIEWPORT_EXTENT;
107 m_windowExtY = VIEWPORT_EXTENT;
a23fd0e1 108
7bcb11d3 109 m_hDCCount = 0;
2bda0e17
KB
110}
111
112
a23fd0e1 113wxDC::~wxDC()
2bda0e17 114{
7bcb11d3
JS
115 if ( m_hDC != 0 ) {
116 SelectOldObjects(m_hDC);
117 if ( m_bOwnsDC ) {
118 if ( m_canvas == NULL )
a23fd0e1 119 ::DeleteDC(GetHdc());
7bcb11d3 120 else
a23fd0e1 121 ::ReleaseDC((HWND)m_canvas->GetHWND(), GetHdc());
7bcb11d3 122 }
2bda0e17 123 }
a23fd0e1 124
2bda0e17
KB
125}
126
127// This will select current objects out of the DC,
128// which is what you have to do before deleting the
129// DC.
130void wxDC::SelectOldObjects(WXHDC dc)
131{
7bcb11d3 132 if (dc)
2bda0e17 133 {
7bcb11d3
JS
134 if (m_oldBitmap)
135 {
136 ::SelectObject((HDC) dc, (HBITMAP) m_oldBitmap);
137 if (m_selectedBitmap.Ok())
138 {
139 m_selectedBitmap.SetSelectedInto(NULL);
140 }
141 }
a23fd0e1 142 m_oldBitmap = 0;
7bcb11d3
JS
143 if (m_oldPen)
144 {
145 ::SelectObject((HDC) dc, (HPEN) m_oldPen);
146 }
a23fd0e1 147 m_oldPen = 0;
7bcb11d3
JS
148 if (m_oldBrush)
149 {
150 ::SelectObject((HDC) dc, (HBRUSH) m_oldBrush);
151 }
a23fd0e1 152 m_oldBrush = 0;
7bcb11d3
JS
153 if (m_oldFont)
154 {
155 ::SelectObject((HDC) dc, (HFONT) m_oldFont);
156 }
a23fd0e1 157 m_oldFont = 0;
7bcb11d3
JS
158 if (m_oldPalette)
159 {
160 ::SelectPalette((HDC) dc, (HPALETTE) m_oldPalette, TRUE);
161 }
a23fd0e1 162 m_oldPalette = 0;
2bda0e17 163 }
a23fd0e1
VZ
164
165 m_brush = wxNullBrush;
7bcb11d3
JS
166 m_pen = wxNullPen;
167 m_palette = wxNullPalette;
168 m_font = wxNullFont;
169 m_backgroundBrush = wxNullBrush;
170 m_selectedBitmap = wxNullBitmap;
2bda0e17
KB
171}
172
a23fd0e1
VZ
173// ---------------------------------------------------------------------------
174// clipping
175// ---------------------------------------------------------------------------
176
72cdf4c9 177void wxDC::DoSetClippingRegion(wxCoord cx, wxCoord cy, wxCoord cw, wxCoord ch)
2bda0e17 178{
7bcb11d3
JS
179 m_clipping = TRUE;
180 m_clipX1 = (int)cx;
181 m_clipY1 = (int)cy;
182 m_clipX2 = (int)(cx + cw);
183 m_clipY2 = (int)(cy + ch);
a23fd0e1 184
7bcb11d3 185 DoClipping((WXHDC) m_hDC);
2bda0e17
KB
186}
187
a23fd0e1 188void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region)
a724d789 189{
223d09f6 190 wxCHECK_RET( region.GetHRGN(), wxT("invalid clipping region") );
a23fd0e1 191
7bcb11d3 192 wxRect box = region.GetBox();
a23fd0e1 193
7bcb11d3
JS
194 m_clipping = TRUE;
195 m_clipX1 = box.x;
196 m_clipY1 = box.y;
197 m_clipX2 = box.x + box.width;
198 m_clipY2 = box.y + box.height;
a23fd0e1 199
1e6d9499 200#ifdef __WIN16__
a23fd0e1 201 SelectClipRgn(GetHdc(), (HRGN) region.GetHRGN());
1e6d9499 202#else
a23fd0e1 203 ExtSelectClipRgn(GetHdc(), (HRGN) region.GetHRGN(), RGN_AND);
1e6d9499 204#endif
a724d789
JS
205}
206
2bda0e17
KB
207void wxDC::DoClipping(WXHDC dc)
208{
7bcb11d3
JS
209 if (m_clipping && dc)
210 {
211 IntersectClipRect((HDC) dc, XLOG2DEV(m_clipX1), YLOG2DEV(m_clipY1),
a23fd0e1 212 XLOG2DEV(m_clipX2), YLOG2DEV(m_clipY2));
7bcb11d3 213 }
2bda0e17
KB
214}
215
a23fd0e1 216void wxDC::DestroyClippingRegion()
2bda0e17 217{
7bcb11d3
JS
218 if (m_clipping && m_hDC)
219 {
220 // TODO: this should restore the previous clipping region,
221 // so that OnPaint processing works correctly, and the update clipping region
222 // doesn't get destroyed after the first DestroyClippingRegion.
223 HRGN rgn = CreateRectRgn(0, 0, 32000, 32000);
a23fd0e1 224 SelectClipRgn(GetHdc(), rgn);
7bcb11d3
JS
225 DeleteObject(rgn);
226 }
227 m_clipping = FALSE;
2bda0e17
KB
228}
229
a23fd0e1
VZ
230// ---------------------------------------------------------------------------
231// query capabilities
232// ---------------------------------------------------------------------------
233
234bool wxDC::CanDrawBitmap() const
2bda0e17 235{
7bcb11d3 236 return TRUE;
2bda0e17
KB
237}
238
a23fd0e1 239bool wxDC::CanGetTextExtent() const
2bda0e17 240{
7bcb11d3 241 // What sort of display is it?
a23fd0e1
VZ
242 int technology = ::GetDeviceCaps(GetHdc(), TECHNOLOGY);
243
244 return (technology == DT_RASDISPLAY) || (technology == DT_RASPRINTER);
2bda0e17
KB
245}
246
a23fd0e1 247int wxDC::GetDepth() const
2bda0e17 248{
a23fd0e1 249 return (int)::GetDeviceCaps(GetHdc(), BITSPIXEL);
2bda0e17
KB
250}
251
a23fd0e1
VZ
252// ---------------------------------------------------------------------------
253// drawing
254// ---------------------------------------------------------------------------
255
256void wxDC::Clear()
2bda0e17 257{
7bcb11d3 258 RECT rect;
2506aab6
VZ
259 if ( m_canvas )
260 {
7bcb11d3 261 GetClientRect((HWND) m_canvas->GetHWND(), &rect);
2506aab6
VZ
262 }
263 else
7bcb11d3 264 {
223d09f6 265 wxCHECK_RET( m_selectedBitmap.Ok(), wxT("this DC can't be cleared") );
2506aab6 266
7bcb11d3
JS
267 rect.left = 0; rect.top = 0;
268 rect.right = m_selectedBitmap.GetWidth();
269 rect.bottom = m_selectedBitmap.GetHeight();
270 }
2506aab6 271
a23fd0e1
VZ
272 (void) ::SetMapMode(GetHdc(), MM_TEXT);
273
274 DWORD colour = GetBkColor(GetHdc());
7bcb11d3 275 HBRUSH brush = CreateSolidBrush(colour);
a23fd0e1 276 FillRect(GetHdc(), &rect, brush);
7bcb11d3 277 DeleteObject(brush);
a23fd0e1
VZ
278
279 ::SetMapMode(GetHdc(), MM_ANISOTROPIC);
280 ::SetViewportExtEx(GetHdc(), VIEWPORT_EXTENT, VIEWPORT_EXTENT, NULL);
281 ::SetWindowExtEx(GetHdc(), m_windowExtX, m_windowExtY, NULL);
282 ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX, (int)m_deviceOriginY, NULL);
283 ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX, (int)m_logicalOriginY, NULL);
284}
285
72cdf4c9 286void wxDC::DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, int style)
a23fd0e1
VZ
287{
288 (void)ExtFloodFill(GetHdc(), XLOG2DEV(x), YLOG2DEV(y),
289 col.GetPixel(),
290 style == wxFLOOD_SURFACE ? FLOODFILLSURFACE
291 : FLOODFILLBORDER);
292
7bcb11d3 293 CalcBoundingBox(x, y);
2bda0e17
KB
294}
295
72cdf4c9 296bool wxDC::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const
2bda0e17 297{
7bcb11d3
JS
298 // added by steve 29.12.94 (copied from DrawPoint)
299 // returns TRUE for pixels in the color of the current pen
300 // and FALSE for all other pixels colors
301 // if col is non-NULL return the color of the pixel
a23fd0e1 302
7bcb11d3 303 // get the color of the pixel
a23fd0e1 304 COLORREF pixelcolor = ::GetPixel(GetHdc(), XLOG2DEV(x), YLOG2DEV(y));
7bcb11d3
JS
305 // get the color of the pen
306 COLORREF pencolor = 0x00ffffff;
307 if (m_pen.Ok())
308 {
a23fd0e1 309 pencolor = m_pen.GetColour().GetPixel();
7bcb11d3 310 }
a23fd0e1 311
7bcb11d3
JS
312 // return the color of the pixel
313 if(col)
314 col->Set(GetRValue(pixelcolor),GetGValue(pixelcolor),GetBValue(pixelcolor));
a23fd0e1 315
7bcb11d3
JS
316 // check, if color of the pixels is the same as the color
317 // of the current pen
318 return(pixelcolor==pencolor);
2bda0e17
KB
319}
320
72cdf4c9 321void wxDC::DoCrossHair(wxCoord x, wxCoord y)
a23fd0e1 322{
72cdf4c9
VZ
323 wxCoord x1 = x-VIEWPORT_EXTENT;
324 wxCoord y1 = y-VIEWPORT_EXTENT;
325 wxCoord x2 = x+VIEWPORT_EXTENT;
326 wxCoord y2 = y+VIEWPORT_EXTENT;
a23fd0e1
VZ
327
328 (void)MoveToEx(GetHdc(), XLOG2DEV(x1), YLOG2DEV(y), NULL);
329 (void)LineTo(GetHdc(), XLOG2DEV(x2), YLOG2DEV(y));
330
331 (void)MoveToEx(GetHdc(), XLOG2DEV(x), YLOG2DEV(y1), NULL);
332 (void)LineTo(GetHdc(), XLOG2DEV(x), YLOG2DEV(y2));
333
7bcb11d3
JS
334 CalcBoundingBox(x1, y1);
335 CalcBoundingBox(x2, y2);
2bda0e17
KB
336}
337
72cdf4c9 338void wxDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
2bda0e17 339{
a23fd0e1
VZ
340 (void)MoveToEx(GetHdc(), XLOG2DEV(x1), YLOG2DEV(y1), NULL);
341 (void)LineTo(GetHdc(), XLOG2DEV(x2), YLOG2DEV(y2));
342
7bcb11d3 343 /* MATTHEW: [6] New normalization */
2bda0e17 344#if WX_STANDARD_GRAPHICS
a23fd0e1 345 (void)LineTo(GetHdc(), XLOG2DEV(x2) + 1, YLOG2DEV(y2));
2bda0e17 346#endif
a23fd0e1 347
7bcb11d3
JS
348 CalcBoundingBox(x1, y1);
349 CalcBoundingBox(x2, y2);
2bda0e17
KB
350}
351
72cdf4c9 352void wxDC::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2, wxCoord xc, wxCoord yc)
2bda0e17 353{
a23fd0e1
VZ
354 double dx = xc-x1;
355 double dy = yc-y1;
7bcb11d3
JS
356 double radius = (double)sqrt(dx*dx+dy*dy) ;;
357 if (x1==x2 && x2==y2)
358 {
72cdf4c9 359 DrawEllipse(xc,yc,(wxCoord)(radius*2.0),(wxCoord)(radius*2.0));
a23fd0e1 360 return;
7bcb11d3 361 }
a23fd0e1 362
72cdf4c9
VZ
363 wxCoord xx1 = XLOG2DEV(x1);
364 wxCoord yy1 = YLOG2DEV(y1);
365 wxCoord xx2 = XLOG2DEV(x2);
366 wxCoord yy2 = YLOG2DEV(y2);
367 wxCoord xxc = XLOG2DEV(xc);
368 wxCoord yyc = YLOG2DEV(yc);
369 wxCoord ray = (wxCoord) sqrt(double((xxc-xx1)*(xxc-xx1)+(yyc-yy1)*(yyc-yy1)));
a23fd0e1
VZ
370
371 (void)MoveToEx(GetHdc(), (int) xx1, (int) yy1, NULL);
72cdf4c9
VZ
372 wxCoord xxx1 = (wxCoord) (xxc-ray);
373 wxCoord yyy1 = (wxCoord) (yyc-ray);
374 wxCoord xxx2 = (wxCoord) (xxc+ray);
375 wxCoord yyy2 = (wxCoord) (yyc+ray);
7bcb11d3
JS
376 if (m_brush.Ok() && m_brush.GetStyle() !=wxTRANSPARENT)
377 {
378 // Have to add 1 to bottom-right corner of rectangle
379 // to make semi-circles look right (crooked line otherwise).
380 // Unfortunately this is not a reliable method, depends
381 // on the size of shape.
382 // TODO: figure out why this happens!
a23fd0e1
VZ
383 Pie(GetHdc(),xxx1,yyy1,xxx2+1,yyy2+1,
384 xx1,yy1,xx2,yy2);
7bcb11d3
JS
385 }
386 else
a23fd0e1
VZ
387 Arc(GetHdc(),xxx1,yyy1,xxx2,yyy2,
388 xx1,yy1,xx2,yy2);
389
72cdf4c9
VZ
390 CalcBoundingBox((wxCoord)(xc-radius), (wxCoord)(yc-radius));
391 CalcBoundingBox((wxCoord)(xc+radius), (wxCoord)(yc+radius));
2bda0e17
KB
392}
393
72cdf4c9 394void wxDC::DoDrawPoint(wxCoord x, wxCoord y)
2bda0e17 395{
7bcb11d3
JS
396 COLORREF color = 0x00ffffff;
397 if (m_pen.Ok())
398 {
a23fd0e1 399 color = m_pen.GetColour().GetPixel();
7bcb11d3 400 }
a23fd0e1
VZ
401
402 SetPixel(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), color);
403
7bcb11d3 404 CalcBoundingBox(x, y);
2bda0e17
KB
405}
406
72cdf4c9 407void wxDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset,int fillStyle)
2bda0e17 408{
7bcb11d3
JS
409 // Do things less efficiently if we have offsets
410 if (xoffset != 0 || yoffset != 0)
6a6c0a8b 411 {
7bcb11d3
JS
412 POINT *cpoints = new POINT[n];
413 int i;
414 for (i = 0; i < n; i++)
415 {
416 cpoints[i].x = (int)(points[i].x + xoffset);
417 cpoints[i].y = (int)(points[i].y + yoffset);
a23fd0e1 418
7bcb11d3
JS
419 CalcBoundingBox(cpoints[i].x, cpoints[i].y);
420 }
a23fd0e1
VZ
421 int prev = SetPolyFillMode(GetHdc(),fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING);
422 (void)Polygon(GetHdc(), cpoints, n);
423 SetPolyFillMode(GetHdc(),prev);
7bcb11d3
JS
424 delete[] cpoints;
425 }
426 else
427 {
428 int i;
429 for (i = 0; i < n; i++)
430 CalcBoundingBox(points[i].x, points[i].y);
a23fd0e1
VZ
431
432 int prev = SetPolyFillMode(GetHdc(),fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING);
433 (void)Polygon(GetHdc(), (POINT*) points, n);
434 SetPolyFillMode(GetHdc(),prev);
6a6c0a8b 435 }
2bda0e17
KB
436}
437
72cdf4c9 438void wxDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
2bda0e17 439{
7bcb11d3
JS
440 // Do things less efficiently if we have offsets
441 if (xoffset != 0 || yoffset != 0)
6a6c0a8b 442 {
7bcb11d3
JS
443 POINT *cpoints = new POINT[n];
444 int i;
445 for (i = 0; i < n; i++)
446 {
447 cpoints[i].x = (int)(points[i].x + xoffset);
448 cpoints[i].y = (int)(points[i].y + yoffset);
a23fd0e1 449
7bcb11d3
JS
450 CalcBoundingBox(cpoints[i].x, cpoints[i].y);
451 }
a23fd0e1 452 (void)Polyline(GetHdc(), cpoints, n);
7bcb11d3
JS
453 delete[] cpoints;
454 }
455 else
456 {
457 int i;
458 for (i = 0; i < n; i++)
459 CalcBoundingBox(points[i].x, points[i].y);
a23fd0e1
VZ
460
461 (void)Polyline(GetHdc(), (POINT*) points, n);
6a6c0a8b 462 }
2bda0e17
KB
463}
464
72cdf4c9 465void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
2bda0e17 466{
72cdf4c9
VZ
467 wxCoord x2 = x + width;
468 wxCoord y2 = y + height;
a23fd0e1 469
7bcb11d3 470 /* MATTHEW: [6] new normalization */
2bda0e17 471#if WX_STANDARD_GRAPHICS
7bcb11d3 472 bool do_brush, do_pen;
a23fd0e1 473
7bcb11d3
JS
474 do_brush = m_brush.Ok() && m_brush.GetStyle() != wxTRANSPARENT;
475 do_pen = m_pen.Ok() && m_pen.GetStyle() != wxTRANSPARENT;
a23fd0e1 476
7bcb11d3
JS
477 if (do_brush) {
478 HPEN orig_pen = NULL;
a23fd0e1 479
7bcb11d3 480 if (do_pen || !m_pen.Ok())
a23fd0e1
VZ
481 orig_pen = (HPEN) ::SelectObject(GetHdc(), (HPEN) ::GetStockObject(NULL_PEN));
482
483 (void)Rectangle(GetHdc(), XLOG2DEV(x), YLOG2DEV(y),
7bcb11d3 484 XLOG2DEV(x2) + 1, YLOG2DEV(y2) + 1);
a23fd0e1 485
7bcb11d3 486 if (do_pen || !m_pen.Ok())
a23fd0e1 487 ::SelectObject(GetHdc() , orig_pen);
7bcb11d3
JS
488 }
489 if (do_pen) {
490 HBRUSH orig_brush = NULL;
a23fd0e1 491
7bcb11d3 492 if (do_brush || !m_brush.Ok())
a23fd0e1
VZ
493 orig_brush = (HBRUSH) ::SelectObject(GetHdc(), (HBRUSH) ::GetStockObject(NULL_BRUSH));
494
495 (void)Rectangle(GetHdc(), XLOG2DEV(x), YLOG2DEV(y),
7bcb11d3 496 XLOG2DEV(x2), YLOG2DEV(y2));
a23fd0e1 497
7bcb11d3 498 if (do_brush || !m_brush.Ok())
a23fd0e1 499 ::SelectObject(GetHdc(), orig_brush);
7bcb11d3 500 }
2bda0e17 501#else
a23fd0e1 502 (void)Rectangle(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2));
2bda0e17 503#endif
a23fd0e1 504
7bcb11d3
JS
505 CalcBoundingBox(x, y);
506 CalcBoundingBox(x2, y2);
2bda0e17
KB
507}
508
72cdf4c9 509void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius)
2bda0e17 510{
7bcb11d3
JS
511 // Now, a negative radius value is interpreted to mean
512 // 'the proportion of the smallest X or Y dimension'
a23fd0e1 513
7bcb11d3
JS
514 if (radius < 0.0)
515 {
516 double smallest = 0.0;
517 if (width < height)
518 smallest = width;
519 else
520 smallest = height;
521 radius = (- radius * smallest);
522 }
a23fd0e1 523
72cdf4c9
VZ
524 wxCoord x2 = (x+width);
525 wxCoord y2 = (y+height);
a23fd0e1
VZ
526
527 (void)RoundRect(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2),
25889d3c 528 YLOG2DEV(y2), (int) (2*XLOG2DEV(radius)), (int)( 2*YLOG2DEV(radius)));
a23fd0e1 529
7bcb11d3
JS
530 CalcBoundingBox(x, y);
531 CalcBoundingBox(x2, y2);
2bda0e17
KB
532}
533
72cdf4c9 534void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
2bda0e17 535{
72cdf4c9
VZ
536 wxCoord x2 = (x+width);
537 wxCoord y2 = (y+height);
a23fd0e1
VZ
538
539 (void)Ellipse(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2));
540
7bcb11d3
JS
541 CalcBoundingBox(x, y);
542 CalcBoundingBox(x2, y2);
2bda0e17
KB
543}
544
6f65e337 545// Chris Breeze 20/5/98: first implementation of DrawEllipticArc on Windows
72cdf4c9 546void wxDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)
6f65e337 547{
72cdf4c9
VZ
548 wxCoord x2 = (x+w);
549 wxCoord y2 = (y+h);
a23fd0e1 550
7bcb11d3
JS
551 int rx1 = XLOG2DEV(x+w/2);
552 int ry1 = YLOG2DEV(y+h/2);
553 int rx2 = rx1;
554 int ry2 = ry1;
4314ec48
VZ
555
556 sa = DegToRad(sa);
557 ea = DegToRad(ea);
558
559 rx1 += (int)(100.0 * abs(w) * cos(sa));
560 ry1 -= (int)(100.0 * abs(h) * m_signY * sin(sa));
561 rx2 += (int)(100.0 * abs(w) * cos(ea));
562 ry2 -= (int)(100.0 * abs(h) * m_signY * sin(ea));
a23fd0e1 563
7bcb11d3
JS
564 // draw pie with NULL_PEN first and then outline otherwise a line is
565 // drawn from the start and end points to the centre
a23fd0e1 566 HPEN orig_pen = (HPEN) ::SelectObject(GetHdc(), (HPEN) ::GetStockObject(NULL_PEN));
7bcb11d3
JS
567 if (m_signY > 0)
568 {
a23fd0e1 569 (void)Pie(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2)+1, YLOG2DEV(y2)+1,
7bcb11d3
JS
570 rx1, ry1, rx2, ry2);
571 }
572 else
573 {
a23fd0e1 574 (void)Pie(GetHdc(), XLOG2DEV(x), YLOG2DEV(y)-1, XLOG2DEV(x2)+1, YLOG2DEV(y2),
7bcb11d3
JS
575 rx1, ry1-1, rx2, ry2-1);
576 }
a23fd0e1
VZ
577 ::SelectObject(GetHdc(), orig_pen);
578 (void)Arc(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2),
fd3f686c 579 rx1, ry1, rx2, ry2);
a23fd0e1 580
7bcb11d3
JS
581 CalcBoundingBox(x, y);
582 CalcBoundingBox(x2, y2);
6f65e337
JS
583}
584
72cdf4c9 585void wxDC::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
2bda0e17 586{
57c208c5 587#if defined(__WIN32__) && !defined(__SC__) && !defined(__TWIN32__)
a23fd0e1 588 ::DrawIconEx(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), (HICON) icon.GetHICON(),
7bcb11d3 589 icon.GetWidth(), icon.GetHeight(), 0, 0, DI_NORMAL);
f60d0f94 590#else
a23fd0e1 591 ::DrawIcon(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), (HICON) icon.GetHICON());
f60d0f94 592#endif
a23fd0e1 593
7bcb11d3
JS
594 CalcBoundingBox(x, y);
595 CalcBoundingBox(x+icon.GetWidth(), y+icon.GetHeight());
2bda0e17
KB
596}
597
72cdf4c9 598void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask )
f5419957
JS
599{
600 if (!bmp.Ok())
601 return;
a23fd0e1 602
f5419957
JS
603 // If we're not drawing transparently, and not drawing to a printer,
604 // optimize this function to use Windows functions.
605 if (!useMask && !IsKindOf(CLASSINFO(wxPrinterDC)))
606 {
a23fd0e1 607 HDC cdc = GetHdc();
f5419957
JS
608 HDC memdc = ::CreateCompatibleDC( cdc );
609 HBITMAP hbitmap = (HBITMAP) bmp.GetHBITMAP( );
10fcf31a 610
223d09f6 611 wxASSERT_MSG( hbitmap, wxT("bitmap is ok but HBITMAP is NULL?") );
10fcf31a 612
f5419957
JS
613 ::SelectObject( memdc, hbitmap );
614 ::BitBlt( cdc, x, y, bmp.GetWidth(), bmp.GetHeight(), memdc, 0, 0, SRCCOPY);
f5419957
JS
615 ::DeleteDC( memdc );
616 }
617 else
618 {
619 // Rather than reproduce wxDC::Blit, let's do it at the wxWin API level
620 wxMemoryDC memDC;
621 memDC.SelectObject(bmp);
a23fd0e1 622
f5419957 623 /* Not sure if we need this. The mask should leave the
7bcb11d3
JS
624 * masked areas as per the original background of this DC.
625 */
626 /*
f5419957
JS
627 // There might be transparent areas, so make these
628 // the same colour as this DC
629 memDC.SetBackground(* GetBackground());
630 memDC.Clear();
7bcb11d3 631 */
a23fd0e1 632
f5419957 633 Blit(x, y, bmp.GetWidth(), bmp.GetHeight(), & memDC, 0, 0, wxCOPY, useMask);
a23fd0e1 634
f5419957
JS
635 memDC.SelectObject(wxNullBitmap);
636 }
637}
638
72cdf4c9 639void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y)
a23fd0e1 640{
4314ec48
VZ
641 DrawAnyText(text, x, y);
642
643 // update the bounding box
644 CalcBoundingBox(x, y);
645
646 wxCoord w, h;
647 GetTextExtent(text, &w, &h);
648 CalcBoundingBox(x + w, y + h);
649}
650
651void wxDC::DrawAnyText(const wxString& text, wxCoord x, wxCoord y)
652{
653 // prepare for drawing the text
654 if ( m_textForegroundColour.Ok() )
655 SetTextColor(GetHdc(), m_textForegroundColour.GetPixel());
a23fd0e1
VZ
656
657 DWORD old_background = 0;
4314ec48 658 if ( m_textBackgroundColour.Ok() )
a23fd0e1
VZ
659 {
660 old_background = SetBkColor(GetHdc(), m_textBackgroundColour.GetPixel() );
661 }
662
4314ec48
VZ
663 SetBkMode(GetHdc(), m_backgroundMode == wxTRANSPARENT ? TRANSPARENT
664 : OPAQUE);
a23fd0e1 665
4314ec48 666 if ( ::TextOut(GetHdc(), XLOG2DEV(x), YLOG2DEV(y),
696e1ea0 667 text.c_str(), text.length()) == 0 )
4314ec48
VZ
668 {
669 wxLogLastError("TextOut");
670 }
a23fd0e1 671
4314ec48
VZ
672 // restore the old parameters (text foreground colour may be left because
673 // it never is set to anything else, but background should remain
674 // transparent even if we just drew an opaque string)
675 if ( m_textBackgroundColour.Ok() )
a23fd0e1
VZ
676 (void)SetBkColor(GetHdc(), old_background);
677
c45a644e 678 SetBkMode(GetHdc(), TRANSPARENT);
a23fd0e1
VZ
679}
680
95724b1a
VZ
681void wxDC::DoDrawRotatedText(const wxString& text,
682 wxCoord x, wxCoord y,
683 double angle)
684{
696e1ea0
VZ
685 // we test that we have some font because otherwise we should still use the
686 // "else" part below to avoid that DrawRotatedText(angle = 180) and
687 // DrawRotatedText(angle = 0) use different fonts (we can't use the default
688 // font for drawing rotated fonts unfortunately)
689 if ( (angle == 0.0) && m_font.Ok() )
4314ec48
VZ
690 {
691 DoDrawText(text, x, y);
692 }
693 else
694 {
696e1ea0
VZ
695 // NB: don't take DEFAULT_GUI_FONT because it's not TrueType and so
696 // can't have non zero orientation/escapement
697 wxFont font = m_font.Ok() ? m_font : *wxNORMAL_FONT;
698 HFONT hfont = (HFONT)font.GetResourceHandle();
4314ec48 699 LOGFONT lf;
696e1ea0
VZ
700 if ( ::GetObject(hfont, sizeof(lf), &lf) == 0 )
701 {
702 wxLogLastError("GetObject(hfont)");
703 }
4314ec48
VZ
704
705 // GDI wants the angle in tenth of degree
706 long angle10 = (long)(angle * 10);
707 lf.lfEscapement = angle10;
708 lf. lfOrientation = angle10;
709
696e1ea0 710 hfont = ::CreateFontIndirect(&lf);
4314ec48
VZ
711 if ( !hfont )
712 {
713 wxLogLastError("CreateFont");
714 }
715 else
716 {
696e1ea0 717 HFONT hfontOld = (HFONT)::SelectObject(GetHdc(), hfont);
4314ec48
VZ
718
719 DrawAnyText(text, x, y);
720
721 (void)::SelectObject(GetHdc(), hfontOld);
722 }
723
724 // call the bounding box by adding all four vertices of the rectangle
725 // containing the text to it (simpler and probably not slower than
726 // determining which of them is really topmost/leftmost/...)
727 wxCoord w, h;
728 GetTextExtent(text, &w, &h);
729
730 double rad = DegToRad(angle);
731
732 // "upper left" and "upper right"
733 CalcBoundingBox(x, y);
734 CalcBoundingBox(x + w*cos(rad), y - h*sin(rad));
4314ec48
VZ
735
736 // "bottom left" and "bottom right"
737 x += (wxCoord)(h*sin(rad));
738 y += (wxCoord)(h*cos(rad));
739 CalcBoundingBox(x, y);
740 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
741 }
95724b1a
VZ
742}
743
a23fd0e1
VZ
744// ---------------------------------------------------------------------------
745// set GDI objects
746// ---------------------------------------------------------------------------
747
748void wxDC::SetPalette(const wxPalette& palette)
749{
750 // Set the old object temporarily, in case the assignment deletes an object
751 // that's not yet selected out.
752 if (m_oldPalette)
753 {
754 ::SelectPalette(GetHdc(), (HPALETTE) m_oldPalette, TRUE);
755 m_oldPalette = 0;
756 }
757
758 m_palette = palette;
759
760 if (!m_palette.Ok())
761 {
762 // Setting a NULL colourmap is a way of restoring
763 // the original colourmap
764 if (m_oldPalette)
765 {
766 ::SelectPalette(GetHdc(), (HPALETTE) m_oldPalette, TRUE);
767 m_oldPalette = 0;
768 }
769
770 return;
771 }
772
773 if (m_palette.Ok() && m_palette.GetHPALETTE())
774 {
775 HPALETTE oldPal = ::SelectPalette(GetHdc(), (HPALETTE) m_palette.GetHPALETTE(), TRUE);
776 if (!m_oldPalette)
777 m_oldPalette = (WXHPALETTE) oldPal;
778
779 ::RealizePalette(GetHdc());
780 }
781}
782
2bda0e17
KB
783void wxDC::SetFont(const wxFont& the_font)
784{
7bcb11d3
JS
785 // Set the old object temporarily, in case the assignment deletes an object
786 // that's not yet selected out.
2bda0e17 787 if (m_oldFont)
34da0970 788 {
a23fd0e1 789 ::SelectObject(GetHdc(), (HFONT) m_oldFont);
7bcb11d3
JS
790 m_oldFont = 0;
791 }
a23fd0e1 792
7bcb11d3 793 m_font = the_font;
a23fd0e1 794
7bcb11d3
JS
795 if (!the_font.Ok())
796 {
797 if (m_oldFont)
a23fd0e1
VZ
798 ::SelectObject(GetHdc(), (HFONT) m_oldFont);
799 m_oldFont = 0;
7bcb11d3 800 }
a23fd0e1 801
7bcb11d3
JS
802 if (m_font.Ok() && m_font.GetResourceHandle())
803 {
a23fd0e1 804 HFONT f = (HFONT) ::SelectObject(GetHdc(), (HFONT) m_font.GetResourceHandle());
7bcb11d3
JS
805 if (f == (HFONT) NULL)
806 {
223d09f6 807 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
7bcb11d3
JS
808 }
809 if (!m_oldFont)
810 m_oldFont = (WXHFONT) f;
34da0970 811 }
2bda0e17
KB
812}
813
814void wxDC::SetPen(const wxPen& pen)
815{
7bcb11d3
JS
816 // Set the old object temporarily, in case the assignment deletes an object
817 // that's not yet selected out.
2bda0e17 818 if (m_oldPen)
2bda0e17 819 {
a23fd0e1 820 ::SelectObject(GetHdc(), (HPEN) m_oldPen);
7bcb11d3
JS
821 m_oldPen = 0;
822 }
a23fd0e1 823
7bcb11d3 824 m_pen = pen;
a23fd0e1 825
7bcb11d3
JS
826 if (!m_pen.Ok())
827 {
828 if (m_oldPen)
a23fd0e1
VZ
829 ::SelectObject(GetHdc(), (HPEN) m_oldPen);
830 m_oldPen = 0;
7bcb11d3 831 }
a23fd0e1 832
7bcb11d3
JS
833 if (m_pen.Ok())
834 {
835 if (m_pen.GetResourceHandle())
836 {
a23fd0e1 837 HPEN p = (HPEN) ::SelectObject(GetHdc(), (HPEN)m_pen.GetResourceHandle());
7bcb11d3
JS
838 if (!m_oldPen)
839 m_oldPen = (WXHPEN) p;
840 }
2bda0e17 841 }
2bda0e17
KB
842}
843
844void wxDC::SetBrush(const wxBrush& brush)
845{
7bcb11d3
JS
846 // Set the old object temporarily, in case the assignment deletes an object
847 // that's not yet selected out.
2bda0e17 848 if (m_oldBrush)
2bda0e17 849 {
a23fd0e1 850 ::SelectObject(GetHdc(), (HBRUSH) m_oldBrush);
7bcb11d3
JS
851 m_oldBrush = 0;
852 }
a23fd0e1 853
7bcb11d3 854 m_brush = brush;
a23fd0e1 855
7bcb11d3
JS
856 if (!m_brush.Ok())
857 {
858 if (m_oldBrush)
a23fd0e1
VZ
859 ::SelectObject(GetHdc(), (HBRUSH) m_oldBrush);
860 m_oldBrush = 0;
7bcb11d3 861 }
a23fd0e1 862
7bcb11d3
JS
863 if (m_brush.Ok())
864 {
865 if (m_brush.GetResourceHandle())
866 {
867 HBRUSH b = 0;
a23fd0e1 868 b = (HBRUSH) ::SelectObject(GetHdc(), (HBRUSH)m_brush.GetResourceHandle());
7bcb11d3
JS
869 if (!m_oldBrush)
870 m_oldBrush = (WXHBRUSH) b;
871 }
2bda0e17 872 }
2bda0e17
KB
873}
874
2bda0e17
KB
875void wxDC::SetBackground(const wxBrush& brush)
876{
7bcb11d3 877 m_backgroundBrush = brush;
a23fd0e1 878
7bcb11d3
JS
879 if (!m_backgroundBrush.Ok())
880 return;
a23fd0e1 881
7bcb11d3 882 if (m_canvas)
2bda0e17 883 {
7bcb11d3
JS
884 bool customColours = TRUE;
885 // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
886 // change background colours from the control-panel specified colours.
887 if (m_canvas->IsKindOf(CLASSINFO(wxWindow)) && ((m_canvas->GetWindowStyleFlag() & wxUSER_COLOURS) != wxUSER_COLOURS))
888 customColours = FALSE;
a23fd0e1 889
7bcb11d3
JS
890 if (customColours)
891 {
892 if (m_backgroundBrush.GetStyle()==wxTRANSPARENT)
893 {
cc2b7472 894 m_canvas->SetTransparent(TRUE);
7bcb11d3
JS
895 }
896 else
897 {
898 // New behaviour, 10/2/99: setting the background brush of a DC
899 // doesn't affect the window background colour. However,
900 // I'm leaving in the transparency setting because it's needed by
901 // various controls (e.g. wxStaticText) to determine whether to draw
902 // transparently or not. TODO: maybe this should be a new function
903 // wxWindow::SetTransparency(). Should that apply to the child itself, or the
904 // parent?
905 // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour());
cc2b7472 906 m_canvas->SetTransparent(FALSE);
7bcb11d3
JS
907 }
908 }
909 }
a23fd0e1 910 COLORREF new_color = m_backgroundBrush.GetColour().GetPixel();
7bcb11d3 911 {
a23fd0e1 912 (void)SetBkColor(GetHdc(), new_color);
2bda0e17 913 }
2bda0e17
KB
914}
915
916void wxDC::SetBackgroundMode(int mode)
917{
7bcb11d3 918 m_backgroundMode = mode;
a23fd0e1 919
c45a644e
RR
920 // SetBackgroundColour now only refers to text background
921 // and m_backgroundMode is used there
922
923/*
7bcb11d3 924 if (m_backgroundMode == wxTRANSPARENT)
a23fd0e1 925 ::SetBkMode(GetHdc(), TRANSPARENT);
7bcb11d3 926 else
c45a644e
RR
927 ::SetBkMode(GetHdc(), OPAQUE);
928*/
2bda0e17
KB
929}
930
931void wxDC::SetLogicalFunction(int function)
932{
7bcb11d3 933 m_logicalFunction = function;
a23fd0e1 934
7bcb11d3 935 SetRop((WXHDC) m_hDC);
2bda0e17
KB
936}
937
938void wxDC::SetRop(WXHDC dc)
939{
7bcb11d3
JS
940 if (!dc || m_logicalFunction < 0)
941 return;
a23fd0e1 942
7bcb11d3
JS
943 int c_rop;
944 // These may be wrong
945 switch (m_logicalFunction)
946 {
947 // case wxXOR: c_rop = R2_XORPEN; break;
2bda0e17
KB
948 case wxXOR: c_rop = R2_NOTXORPEN; break;
949 case wxINVERT: c_rop = R2_NOT; break;
950 case wxOR_REVERSE: c_rop = R2_MERGEPENNOT; break;
951 case wxAND_REVERSE: c_rop = R2_MASKPENNOT; break;
952 case wxCLEAR: c_rop = R2_WHITE; break;
953 case wxSET: c_rop = R2_BLACK; break;
954 case wxSRC_INVERT: c_rop = R2_NOTCOPYPEN; break;
955 case wxOR_INVERT: c_rop = R2_MERGENOTPEN; break;
956 case wxAND: c_rop = R2_MASKPEN; break;
957 case wxOR: c_rop = R2_MERGEPEN; break;
958 case wxAND_INVERT: c_rop = R2_MASKNOTPEN; break;
959 case wxEQUIV:
960 case wxNAND:
961 case wxCOPY:
962 default:
7bcb11d3
JS
963 c_rop = R2_COPYPEN; break;
964 }
965 SetROP2((HDC) dc, c_rop);
2bda0e17
KB
966}
967
968bool wxDC::StartDoc(const wxString& message)
969{
7bcb11d3 970 // We might be previewing, so return TRUE to let it continue.
2bda0e17 971 return TRUE;
2bda0e17
KB
972}
973
a23fd0e1 974void wxDC::EndDoc()
2bda0e17 975{
2bda0e17
KB
976}
977
a23fd0e1 978void wxDC::StartPage()
2bda0e17 979{
2bda0e17
KB
980}
981
a23fd0e1 982void wxDC::EndPage()
2bda0e17 983{
2bda0e17
KB
984}
985
a23fd0e1
VZ
986// ---------------------------------------------------------------------------
987// text metrics
988// ---------------------------------------------------------------------------
989
72cdf4c9 990wxCoord wxDC::GetCharHeight() const
2bda0e17 991{
7bcb11d3 992 TEXTMETRIC lpTextMetric;
a23fd0e1
VZ
993
994 GetTextMetrics(GetHdc(), &lpTextMetric);
995
7bcb11d3 996 return YDEV2LOGREL(lpTextMetric.tmHeight);
2bda0e17
KB
997}
998
72cdf4c9 999wxCoord wxDC::GetCharWidth() const
2bda0e17 1000{
7bcb11d3 1001 TEXTMETRIC lpTextMetric;
a23fd0e1
VZ
1002
1003 GetTextMetrics(GetHdc(), &lpTextMetric);
1004
7bcb11d3 1005 return XDEV2LOGREL(lpTextMetric.tmAveCharWidth);
2bda0e17
KB
1006}
1007
72cdf4c9
VZ
1008void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
1009 wxCoord *descent, wxCoord *externalLeading,
1010 wxFont *theFont) const
2bda0e17 1011{
7bcb11d3
JS
1012 wxFont *fontToUse = (wxFont*) theFont;
1013 if (!fontToUse)
1014 fontToUse = (wxFont*) &m_font;
a23fd0e1 1015
7bcb11d3
JS
1016 SIZE sizeRect;
1017 TEXTMETRIC tm;
a23fd0e1 1018
837e5743 1019 GetTextExtentPoint(GetHdc(), WXSTRINGCAST string, wxStrlen(WXSTRINGCAST string), &sizeRect);
a23fd0e1
VZ
1020 GetTextMetrics(GetHdc(), &tm);
1021
7bcb11d3
JS
1022 if (x) *x = XDEV2LOGREL(sizeRect.cx);
1023 if (y) *y = YDEV2LOGREL(sizeRect.cy);
1024 if (descent) *descent = tm.tmDescent;
1025 if (externalLeading) *externalLeading = tm.tmExternalLeading;
2bda0e17
KB
1026}
1027
1028void wxDC::SetMapMode(int mode)
1029{
7bcb11d3 1030 m_mappingMode = mode;
a23fd0e1 1031
7bcb11d3
JS
1032 int pixel_width = 0;
1033 int pixel_height = 0;
1034 int mm_width = 0;
1035 int mm_height = 0;
a23fd0e1
VZ
1036
1037 pixel_width = GetDeviceCaps(GetHdc(), HORZRES);
1038 pixel_height = GetDeviceCaps(GetHdc(), VERTRES);
1039 mm_width = GetDeviceCaps(GetHdc(), HORZSIZE);
1040 mm_height = GetDeviceCaps(GetHdc(), VERTSIZE);
1041
7bcb11d3 1042 if ((pixel_width == 0) || (pixel_height == 0) || (mm_width == 0) || (mm_height == 0))
2bda0e17 1043 {
7bcb11d3 1044 return;
2bda0e17 1045 }
a23fd0e1 1046
7bcb11d3
JS
1047 double mm2pixelsX = pixel_width/mm_width;
1048 double mm2pixelsY = pixel_height/mm_height;
a23fd0e1 1049
7bcb11d3 1050 switch (mode)
2bda0e17 1051 {
7bcb11d3
JS
1052 case wxMM_TWIPS:
1053 {
1054 m_logicalScaleX = (twips2mm * mm2pixelsX);
1055 m_logicalScaleY = (twips2mm * mm2pixelsY);
1056 break;
1057 }
1058 case wxMM_POINTS:
1059 {
1060 m_logicalScaleX = (pt2mm * mm2pixelsX);
1061 m_logicalScaleY = (pt2mm * mm2pixelsY);
1062 break;
1063 }
e3065973 1064 case wxMM_METRIC:
7bcb11d3
JS
1065 {
1066 m_logicalScaleX = mm2pixelsX;
1067 m_logicalScaleY = mm2pixelsY;
1068 break;
1069 }
e3065973 1070 case wxMM_LOMETRIC:
7bcb11d3
JS
1071 {
1072 m_logicalScaleX = (mm2pixelsX/10.0);
1073 m_logicalScaleY = (mm2pixelsY/10.0);
1074 break;
1075 }
2bda0e17 1076 default:
e3065973 1077 case wxMM_TEXT:
7bcb11d3
JS
1078 {
1079 m_logicalScaleX = 1.0;
1080 m_logicalScaleY = 1.0;
1081 break;
1082 }
2bda0e17 1083 }
a23fd0e1
VZ
1084
1085 if (::GetMapMode(GetHdc()) != MM_ANISOTROPIC)
1086 ::SetMapMode(GetHdc(), MM_ANISOTROPIC);
1087
1088 SetViewportExtEx(GetHdc(), VIEWPORT_EXTENT, VIEWPORT_EXTENT, NULL);
7bcb11d3
JS
1089 m_windowExtX = (int)MS_XDEV2LOGREL(VIEWPORT_EXTENT);
1090 m_windowExtY = (int)MS_YDEV2LOGREL(VIEWPORT_EXTENT);
a23fd0e1
VZ
1091 ::SetWindowExtEx(GetHdc(), m_windowExtX, m_windowExtY, NULL);
1092 ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX, (int)m_deviceOriginY, NULL);
1093 ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX, (int)m_logicalOriginY, NULL);
2bda0e17
KB
1094}
1095
1096void wxDC::SetUserScale(double x, double y)
1097{
7bcb11d3
JS
1098 m_userScaleX = x;
1099 m_userScaleY = y;
a23fd0e1 1100
7bcb11d3 1101 SetMapMode(m_mappingMode);
2bda0e17
KB
1102}
1103
6f65e337
JS
1104void wxDC::SetAxisOrientation(bool xLeftRight, bool yBottomUp)
1105{
7bcb11d3
JS
1106 m_signX = xLeftRight ? 1 : -1;
1107 m_signY = yBottomUp ? -1 : 1;
a23fd0e1 1108
7bcb11d3 1109 SetMapMode(m_mappingMode);
6f65e337
JS
1110}
1111
2bda0e17
KB
1112void wxDC::SetSystemScale(double x, double y)
1113{
a23fd0e1
VZ
1114 m_scaleX = x;
1115 m_scaleY = y;
1116
7bcb11d3 1117 SetMapMode(m_mappingMode);
2bda0e17
KB
1118}
1119
72cdf4c9 1120void wxDC::SetLogicalOrigin(wxCoord x, wxCoord y)
2bda0e17 1121{
7bcb11d3
JS
1122 m_logicalOriginX = x;
1123 m_logicalOriginY = y;
a23fd0e1
VZ
1124
1125 ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX, (int)m_logicalOriginY, NULL);
2bda0e17
KB
1126}
1127
72cdf4c9 1128void wxDC::SetDeviceOrigin(wxCoord x, wxCoord y)
2bda0e17 1129{
7bcb11d3
JS
1130 m_deviceOriginX = x;
1131 m_deviceOriginY = y;
2bda0e17 1132
a23fd0e1 1133 ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX, (int)m_deviceOriginY, NULL);
2bda0e17
KB
1134}
1135
a23fd0e1
VZ
1136// ---------------------------------------------------------------------------
1137// coordinates transformations
1138// ---------------------------------------------------------------------------
2bda0e17 1139
72cdf4c9 1140wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
2bda0e17 1141{
72cdf4c9 1142 return (wxCoord) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX) - m_logicalOriginX);
2bda0e17
KB
1143}
1144
72cdf4c9 1145wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
2bda0e17 1146{
72cdf4c9 1147 return (wxCoord) ((x)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX));
2bda0e17
KB
1148}
1149
72cdf4c9 1150wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
2bda0e17 1151{
72cdf4c9 1152 return (wxCoord) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY) - m_logicalOriginY);
2bda0e17
KB
1153}
1154
72cdf4c9 1155wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
2bda0e17 1156{
72cdf4c9 1157 return (wxCoord) ((y)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY));
2bda0e17
KB
1158}
1159
72cdf4c9 1160wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
2bda0e17 1161{
72cdf4c9 1162 return (wxCoord) ((x - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX + m_deviceOriginX);
2bda0e17
KB
1163}
1164
72cdf4c9 1165wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
2bda0e17 1166{
72cdf4c9 1167 return (wxCoord) (x*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX);
2bda0e17
KB
1168}
1169
72cdf4c9 1170wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
2bda0e17 1171{
72cdf4c9 1172 return (wxCoord) ((y - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY + m_deviceOriginY);
2bda0e17
KB
1173}
1174
72cdf4c9 1175wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
2bda0e17 1176{
72cdf4c9 1177 return (wxCoord) (y*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY);
2bda0e17
KB
1178}
1179
a23fd0e1
VZ
1180// ---------------------------------------------------------------------------
1181// bit blit
1182// ---------------------------------------------------------------------------
72cdf4c9
VZ
1183bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
1184 wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop, bool useMask)
2bda0e17 1185{
72cdf4c9
VZ
1186 wxCoord xdest1 = xdest;
1187 wxCoord ydest1 = ydest;
1188 wxCoord xsrc1 = xsrc;
1189 wxCoord ysrc1 = ysrc;
a23fd0e1 1190
7bcb11d3
JS
1191 // Chris Breeze 18/5/98: use text foreground/background colours
1192 // when blitting from 1-bit bitmaps
a23fd0e1
VZ
1193 COLORREF old_textground = ::GetTextColor(GetHdc());
1194 COLORREF old_background = ::GetBkColor(GetHdc());
7bcb11d3
JS
1195 if (m_textForegroundColour.Ok())
1196 {
a23fd0e1 1197 ::SetTextColor(GetHdc(), m_textForegroundColour.GetPixel() );
7bcb11d3
JS
1198 }
1199 if (m_textBackgroundColour.Ok())
1200 {
a23fd0e1 1201 ::SetBkColor(GetHdc(), m_textBackgroundColour.GetPixel() );
7bcb11d3 1202 }
a23fd0e1 1203
7bcb11d3
JS
1204 DWORD dwRop = rop == wxCOPY ? SRCCOPY :
1205 rop == wxCLEAR ? WHITENESS :
1206 rop == wxSET ? BLACKNESS :
1207 rop == wxINVERT ? DSTINVERT :
1208 rop == wxAND ? MERGECOPY :
1209 rop == wxOR ? MERGEPAINT :
1210 rop == wxSRC_INVERT ? NOTSRCCOPY :
1211 rop == wxXOR ? SRCINVERT :
1212 rop == wxOR_REVERSE ? MERGEPAINT :
1213 rop == wxAND_REVERSE ? SRCERASE :
1214 rop == wxSRC_OR ? SRCPAINT :
1215 rop == wxSRC_AND ? SRCAND :
1216 SRCCOPY;
a23fd0e1 1217
7bcb11d3
JS
1218 bool success = TRUE;
1219 if (useMask && source->m_selectedBitmap.Ok() && source->m_selectedBitmap.GetMask())
1220 {
a23fd0e1 1221
2bda0e17 1222#if 0 // __WIN32__
7bcb11d3 1223 // Not implemented under Win95 (or maybe a specific device?)
a23fd0e1 1224 if (MaskBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height,
2bda0e17
KB
1225 (HDC) source->m_hDC, xsrc1, ysrc1, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap(),
1226 0, 0, 0xAACC0020))
7bcb11d3
JS
1227 {
1228 // Success
1229 }
1230 else
2bda0e17 1231#endif
7bcb11d3 1232 {
7bcb11d3
JS
1233 // New code from Chris Breeze, 15/7/98
1234 // Blit bitmap with mask
a23fd0e1 1235
7bcb11d3
JS
1236 if (IsKindOf(CLASSINFO(wxPrinterDC)))
1237 {
1238 // If we are printing source colours are screen colours
1239 // not printer colours and so we need copy the bitmap
1240 // pixel by pixel.
1241 RECT rect;
1242 HDC dc_mask = ::CreateCompatibleDC((HDC) source->m_hDC);
1243 HDC dc_src = (HDC) source->m_hDC;
a23fd0e1 1244
7bcb11d3
JS
1245 ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap());
1246 for (int x = 0; x < width; x++)
1247 {
1248 for (int y = 0; y < height; y++)
1249 {
1250 COLORREF cref = ::GetPixel(dc_mask, x, y);
1251 if (cref)
1252 {
1253 HBRUSH brush = ::CreateSolidBrush(::GetPixel(dc_src, x, y));
1254 rect.left = xdest1 + x; rect.right = rect.left + 1;
1255 rect.top = ydest1 + y; rect.bottom = rect.top + 1;
a23fd0e1 1256 ::FillRect(GetHdc(), &rect, brush);
7bcb11d3
JS
1257 ::DeleteObject(brush);
1258 }
1259 }
1260 }
1261 ::SelectObject(dc_mask, 0);
1262 ::DeleteDC(dc_mask);
1263 }
1264 else
1265 {
1266 // create a temp buffer bitmap and DCs to access it and the mask
1267 HDC dc_mask = ::CreateCompatibleDC((HDC) source->m_hDC);
a23fd0e1
VZ
1268 HDC dc_buffer = ::CreateCompatibleDC(GetHdc());
1269 HBITMAP buffer_bmap = ::CreateCompatibleBitmap(GetHdc(), width, height);
7bcb11d3
JS
1270 ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap());
1271 ::SelectObject(dc_buffer, buffer_bmap);
a23fd0e1 1272
7bcb11d3
JS
1273 // copy dest to buffer
1274 ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height,
a23fd0e1
VZ
1275 GetHdc(), xdest1, ydest1, SRCCOPY);
1276
7bcb11d3
JS
1277 // copy src to buffer using selected raster op
1278 ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height,
1279 (HDC) source->m_hDC, xsrc1, ysrc1, dwRop);
a23fd0e1 1280
7bcb11d3 1281 // set masked area in buffer to BLACK (pixel value 0)
a23fd0e1
VZ
1282 COLORREF prevBkCol = ::SetBkColor(GetHdc(), RGB(255, 255, 255));
1283 COLORREF prevCol = ::SetTextColor(GetHdc(), RGB(0, 0, 0));
7bcb11d3
JS
1284 ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height,
1285 dc_mask, xsrc1, ysrc1, SRCAND);
a23fd0e1 1286
7bcb11d3 1287 // set unmasked area in dest to BLACK
a23fd0e1
VZ
1288 ::SetBkColor(GetHdc(), RGB(0, 0, 0));
1289 ::SetTextColor(GetHdc(), RGB(255, 255, 255));
1290 ::BitBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height,
7bcb11d3 1291 dc_mask, xsrc1, ysrc1, SRCAND);
a23fd0e1
VZ
1292 ::SetBkColor(GetHdc(), prevBkCol); // restore colours to original values
1293 ::SetTextColor(GetHdc(), prevCol);
1294
7bcb11d3 1295 // OR buffer to dest
a23fd0e1 1296 success = (::BitBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height,
7bcb11d3 1297 dc_buffer, 0, 0, SRCPAINT) != 0);
a23fd0e1 1298
7bcb11d3
JS
1299 // tidy up temporary DCs and bitmap
1300 ::SelectObject(dc_mask, 0);
1301 ::DeleteDC(dc_mask);
1302 ::SelectObject(dc_buffer, 0);
1303 ::DeleteDC(dc_buffer);
1304 ::DeleteObject(buffer_bmap);
1305 }
1306 }
1307 }
1308 else
1309 {
e12be2f7
JS
1310 // If we are printing, source colours are screen colours
1311 // not printer colours and so we need copy the bitmap
1312 // pixel by pixel.
fd3f686c
VZ
1313 if (IsKindOf(CLASSINFO(wxPrinterDC)))
1314 {
e12be2f7
JS
1315 HDC dc_src = (HDC) source->m_hDC;
1316 RECT rect;
1317 for (int y = 0; y < height; y++)
1318 {
1319 // This is Stefan Csomor's optimisation, where
1320 // identical adjacent pixels are drawn together.
1321 // We still need a faster way of drawing bitmaps,
1322 // perhaps converting to a DIB first and using SetDIBitsToDevice.
1323 for (int x = 0; x < width; x++)
1324 {
1325 COLORREF col = ::GetPixel(dc_src, x, y) ;
1326 HBRUSH brush = ::CreateSolidBrush( col );
1327
1328 rect.left = xdest1 + x;
1329 rect.top = ydest1 + y;
1330 while( (x + 1 < width) && (::GetPixel(dc_src, x + 1, y) == col ) )
1331 {
1332 ++x ;
1333 }
1334 rect.right = xdest1 + x + 1;
1335 rect.bottom = rect.top + 1;
1336 ::FillRect((HDC) m_hDC, &rect, brush);
1337 ::DeleteObject(brush);
1338 }
1339 }
1340/*
fd3f686c 1341 HDC dc_src = (HDC) source->m_hDC;
7bcb11d3 1342 RECT rect;
fd3f686c
VZ
1343 for (int x = 0; x < width; x++)
1344 {
1345 for (int y = 0; y < height; y++)
1346 {
7bcb11d3
JS
1347 HBRUSH brush = ::CreateSolidBrush(::GetPixel(dc_src, x, y));
1348 rect.left = xdest1 + x; rect.right = rect.left + 1;
1349 rect.top = ydest1 + y; rect.bottom = rect.top + 1;
a23fd0e1 1350 ::FillRect(GetHdc(), &rect, brush);
7bcb11d3 1351 ::DeleteObject(brush);
fd3f686c
VZ
1352 }
1353 }
e12be2f7
JS
1354*/
1355 }
fd3f686c
VZ
1356 else
1357 {
a23fd0e1 1358 success = (BitBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height, (HDC) source->m_hDC,
7bcb11d3 1359 xsrc1, ysrc1, dwRop) != 0);
fd3f686c 1360 }
400735a8 1361 }
a23fd0e1
VZ
1362 ::SetTextColor(GetHdc(), old_textground);
1363 ::SetBkColor(GetHdc(), old_background);
2bda0e17 1364
a23fd0e1 1365 return success;
2bda0e17
KB
1366}
1367
a23fd0e1 1368void wxDC::DoGetSize(int *w, int *h) const
2bda0e17 1369{
a23fd0e1
VZ
1370 if ( w ) *w = ::GetDeviceCaps(GetHdc(), HORZRES);
1371 if ( h ) *h = ::GetDeviceCaps(GetHdc(), VERTRES);
2bda0e17
KB
1372}
1373
a23fd0e1 1374void wxDC::DoGetSizeMM(int *w, int *h) const
2bda0e17 1375{
a23fd0e1
VZ
1376 if ( w ) *w = ::GetDeviceCaps(GetHdc(), HORZSIZE);
1377 if ( h ) *h = ::GetDeviceCaps(GetHdc(), VERTSIZE);
7bcb11d3 1378}
2bda0e17 1379
a23fd0e1 1380wxSize wxDC::GetPPI() const
7bcb11d3 1381{
a23fd0e1
VZ
1382 int x = ::GetDeviceCaps(GetHdc(), LOGPIXELSX);
1383 int y = ::GetDeviceCaps(GetHdc(), LOGPIXELSY);
2bda0e17 1384
a23fd0e1 1385 return wxSize(x, y);
2bda0e17
KB
1386}
1387
2bda0e17
KB
1388// For use by wxWindows only, unless custom units are required.
1389void wxDC::SetLogicalScale(double x, double y)
1390{
7bcb11d3
JS
1391 m_logicalScaleX = x;
1392 m_logicalScaleY = y;
2bda0e17
KB
1393}
1394
2bda0e17 1395#if WXWIN_COMPATIBILITY
a23fd0e1 1396void wxDC::DoGetTextExtent(const wxString& string, float *x, float *y,
7bcb11d3
JS
1397 float *descent, float *externalLeading,
1398 wxFont *theFont, bool use16bit) const
2bda0e17 1399{
72cdf4c9 1400 wxCoord x1, y1, descent1, externalLeading1;
fd3f686c
VZ
1401 GetTextExtent(string, & x1, & y1, & descent1, & externalLeading1, theFont, use16bit);
1402 *x = x1; *y = y1;
2bda0e17
KB
1403 if (descent)
1404 *descent = descent1;
1405 if (externalLeading)
1406 *externalLeading = externalLeading1;
1407}
1408#endif
8b9518ee 1409
a23fd0e1
VZ
1410// ---------------------------------------------------------------------------
1411// spline drawing code
1412// ---------------------------------------------------------------------------
7b46ecac 1413
dfad0599
JS
1414#if wxUSE_SPLINES
1415
dfad0599
JS
1416class wxSpline: public wxObject
1417{
7bcb11d3
JS
1418public:
1419 int type;
1420 wxList *points;
a23fd0e1 1421
7bcb11d3 1422 wxSpline(wxList *list);
a23fd0e1
VZ
1423 void DeletePoints();
1424
7bcb11d3 1425 // Doesn't delete points
a23fd0e1 1426 ~wxSpline();
dfad0599
JS
1427};
1428
dfad0599
JS
1429void wx_draw_open_spline(wxDC *dc, wxSpline *spline);
1430
1431void wx_quadratic_spline(double a1, double b1, double a2, double b2,
1432 double a3, double b3, double a4, double b4);
a23fd0e1 1433void wx_clear_stack();
dfad0599 1434int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, double *x3,
7bcb11d3 1435 double *y3, double *x4, double *y4);
dfad0599 1436void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3,
7bcb11d3 1437 double x4, double y4);
dfad0599
JS
1438static bool wx_spline_add_point(double x, double y);
1439static void wx_spline_draw_point_array(wxDC *dc);
1440wxSpline *wx_make_spline(int x1, int y1, int x2, int y2, int x3, int y3);
1441
a23fd0e1 1442void wxDC::DoDrawSpline(wxList *list)
dfad0599 1443{
7bcb11d3 1444 wxSpline spline(list);
a23fd0e1 1445
7bcb11d3 1446 wx_draw_open_spline(this, &spline);
dfad0599
JS
1447}
1448
dfad0599
JS
1449wxList wx_spline_point_list;
1450
1451void wx_draw_open_spline(wxDC *dc, wxSpline *spline)
1452{
1453 wxPoint *p;
1454 double cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4;
1455 double x1, y1, x2, y2;
a23fd0e1 1456
dfad0599
JS
1457 wxNode *node = spline->points->First();
1458 p = (wxPoint *)node->Data();
a23fd0e1 1459
dfad0599
JS
1460 x1 = p->x;
1461 y1 = p->y;
a23fd0e1 1462
dfad0599
JS
1463 node = node->Next();
1464 p = (wxPoint *)node->Data();
a23fd0e1 1465
dfad0599
JS
1466 x2 = p->x;
1467 y2 = p->y;
1468 cx1 = (double)((x1 + x2) / 2);
1469 cy1 = (double)((y1 + y2) / 2);
1470 cx2 = (double)((cx1 + x2) / 2);
1471 cy2 = (double)((cy1 + y2) / 2);
a23fd0e1 1472
dfad0599 1473 wx_spline_add_point(x1, y1);
a23fd0e1 1474
dfad0599
JS
1475 while ((node = node->Next()) != NULL)
1476 {
1477 p = (wxPoint *)node->Data();
7bcb11d3
JS
1478 x1 = x2;
1479 y1 = y2;
1480 x2 = p->x;
1481 y2 = p->y;
dfad0599
JS
1482 cx4 = (double)(x1 + x2) / 2;
1483 cy4 = (double)(y1 + y2) / 2;
1484 cx3 = (double)(x1 + cx4) / 2;
1485 cy3 = (double)(y1 + cy4) / 2;
a23fd0e1 1486
dfad0599 1487 wx_quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4);
a23fd0e1 1488
7bcb11d3
JS
1489 cx1 = cx4;
1490 cy1 = cy4;
dfad0599
JS
1491 cx2 = (double)(cx1 + x2) / 2;
1492 cy2 = (double)(cy1 + y2) / 2;
1493 }
a23fd0e1 1494
dfad0599
JS
1495 wx_spline_add_point((double)wx_round(cx1), (double)wx_round(cy1));
1496 wx_spline_add_point(x2, y2);
a23fd0e1 1497
dfad0599 1498 wx_spline_draw_point_array(dc);
a23fd0e1 1499
dfad0599
JS
1500}
1501
1502/********************* CURVES FOR SPLINES *****************************
1503
7bcb11d3 1504 The following spline drawing routine is from
a23fd0e1 1505
fd3f686c
VZ
1506 "An Algorithm for High-Speed Curve Generation"
1507 by George Merrill Chaikin,
1508 Computer Graphics and Image Processing, 3, Academic Press,
1509 1974, 346-349.
a23fd0e1 1510
7bcb11d3 1511 and
a23fd0e1 1512
7bcb11d3
JS
1513 "On Chaikin's Algorithm" by R. F. Riesenfeld,
1514 Computer Graphics and Image Processing, 4, Academic Press,
1515 1975, 304-310.
a23fd0e1 1516
dfad0599
JS
1517***********************************************************************/
1518
fd3f686c
VZ
1519#define half(z1, z2) ((z1+z2)/2.0)
1520#define THRESHOLD 5
dfad0599
JS
1521
1522/* iterative version */
1523
1524void wx_quadratic_spline(double a1, double b1, double a2, double b2, double a3, double b3, double a4,
7bcb11d3 1525 double b4)
dfad0599
JS
1526{
1527 register double xmid, ymid;
1528 double x1, y1, x2, y2, x3, y3, x4, y4;
a23fd0e1 1529
dfad0599
JS
1530 wx_clear_stack();
1531 wx_spline_push(a1, b1, a2, b2, a3, b3, a4, b4);
a23fd0e1 1532
dfad0599
JS
1533 while (wx_spline_pop(&x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4)) {
1534 xmid = (double)half(x2, x3);
1535 ymid = (double)half(y2, y3);
7bcb11d3
JS
1536 if (fabs(x1 - xmid) < THRESHOLD && fabs(y1 - ymid) < THRESHOLD &&
1537 fabs(xmid - x4) < THRESHOLD && fabs(ymid - y4) < THRESHOLD) {
dfad0599
JS
1538 wx_spline_add_point((double)wx_round(x1), (double)wx_round(y1));
1539 wx_spline_add_point((double)wx_round(xmid), (double)wx_round(ymid));
7bcb11d3 1540 } else {
dfad0599 1541 wx_spline_push(xmid, ymid, (double)half(xmid, x3), (double)half(ymid, y3),
7bcb11d3 1542 (double)half(x3, x4), (double)half(y3, y4), x4, y4);
dfad0599 1543 wx_spline_push(x1, y1, (double)half(x1, x2), (double)half(y1, y2),
7bcb11d3
JS
1544 (double)half(x2, xmid), (double)half(y2, ymid), xmid, ymid);
1545 }
dfad0599
JS
1546 }
1547}
1548
1549
1550/* utilities used by spline drawing routines */
1551
1552
1553typedef struct wx_spline_stack_struct {
1554 double x1, y1, x2, y2, x3, y3, x4, y4;
1555}
7bcb11d3 1556Stack;
dfad0599
JS
1557
1558#define SPLINE_STACK_DEPTH 20
1559static Stack wx_spline_stack[SPLINE_STACK_DEPTH];
1560static Stack *wx_stack_top;
1561static int wx_stack_count;
1562
a23fd0e1 1563void wx_clear_stack()
dfad0599
JS
1564{
1565 wx_stack_top = wx_spline_stack;
1566 wx_stack_count = 0;
1567}
1568
1569void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
1570{
1571 wx_stack_top->x1 = x1;
1572 wx_stack_top->y1 = y1;
1573 wx_stack_top->x2 = x2;
1574 wx_stack_top->y2 = y2;
1575 wx_stack_top->x3 = x3;
1576 wx_stack_top->y3 = y3;
1577 wx_stack_top->x4 = x4;
1578 wx_stack_top->y4 = y4;
1579 wx_stack_top++;
1580 wx_stack_count++;
1581}
1582
1583int wx_spline_pop(double *x1, double *y1, double *x2, double *y2,
1584 double *x3, double *y3, double *x4, double *y4)
1585{
1586 if (wx_stack_count == 0)
7bcb11d3 1587 return (0);
dfad0599
JS
1588 wx_stack_top--;
1589 wx_stack_count--;
1590 *x1 = wx_stack_top->x1;
1591 *y1 = wx_stack_top->y1;
1592 *x2 = wx_stack_top->x2;
1593 *y2 = wx_stack_top->y2;
1594 *x3 = wx_stack_top->x3;
1595 *y3 = wx_stack_top->y3;
1596 *x4 = wx_stack_top->x4;
1597 *y4 = wx_stack_top->y4;
1598 return (1);
1599}
1600
1601static bool wx_spline_add_point(double x, double y)
1602{
a23fd0e1 1603 wxPoint *point = new wxPoint;
7bcb11d3
JS
1604 point->x = (int) x;
1605 point->y = (int) y;
1606 wx_spline_point_list.Append((wxObject*)point);
1607 return TRUE;
dfad0599
JS
1608}
1609
1610static void wx_spline_draw_point_array(wxDC *dc)
1611{
7bcb11d3
JS
1612 dc->DrawLines(&wx_spline_point_list, 0, 0);
1613 wxNode *node = wx_spline_point_list.First();
1614 while (node)
1615 {
1616 wxPoint *point = (wxPoint *)node->Data();
1617 delete point;
1618 delete node;
1619 node = wx_spline_point_list.First();
1620 }
dfad0599
JS
1621}
1622
1623wxSpline::wxSpline(wxList *list)
1624{
7bcb11d3 1625 points = list;
dfad0599
JS
1626}
1627
a23fd0e1 1628wxSpline::~wxSpline()
dfad0599
JS
1629{
1630}
1631
a23fd0e1 1632void wxSpline::DeletePoints()
dfad0599 1633{
7bcb11d3
JS
1634 for(wxNode *node = points->First(); node; node = points->First())
1635 {
1636 wxPoint *point = (wxPoint *)node->Data();
1637 delete point;
1638 delete node;
1639 }
1640 delete points;
dfad0599
JS
1641}
1642
1643
1644#endif // wxUSE_SPLINES
7b46ecac 1645