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