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