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