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