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