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