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