]>
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 | ||
058939fc JS |
363 | // Normalization: Windows doesn't draw the last point of the line. |
364 | // But apparently neither does GTK+, so we take it out again. | |
365 | // (void)LineTo(GetHdc(), XLOG2DEV(x2) + 1, YLOG2DEV(y2)); | |
a23fd0e1 | 366 | |
7bcb11d3 JS |
367 | CalcBoundingBox(x1, y1); |
368 | CalcBoundingBox(x2, y2); | |
2bda0e17 KB |
369 | } |
370 | ||
72cdf4c9 | 371 | void wxDC::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2, wxCoord xc, wxCoord yc) |
2bda0e17 | 372 | { |
a23fd0e1 VZ |
373 | double dx = xc-x1; |
374 | double dy = yc-y1; | |
7bcb11d3 JS |
375 | double radius = (double)sqrt(dx*dx+dy*dy) ;; |
376 | if (x1==x2 && x2==y2) | |
377 | { | |
72cdf4c9 | 378 | DrawEllipse(xc,yc,(wxCoord)(radius*2.0),(wxCoord)(radius*2.0)); |
a23fd0e1 | 379 | return; |
7bcb11d3 | 380 | } |
a23fd0e1 | 381 | |
72cdf4c9 VZ |
382 | wxCoord xx1 = XLOG2DEV(x1); |
383 | wxCoord yy1 = YLOG2DEV(y1); | |
384 | wxCoord xx2 = XLOG2DEV(x2); | |
385 | wxCoord yy2 = YLOG2DEV(y2); | |
386 | wxCoord xxc = XLOG2DEV(xc); | |
387 | wxCoord yyc = YLOG2DEV(yc); | |
388 | wxCoord ray = (wxCoord) sqrt(double((xxc-xx1)*(xxc-xx1)+(yyc-yy1)*(yyc-yy1))); | |
a23fd0e1 VZ |
389 | |
390 | (void)MoveToEx(GetHdc(), (int) xx1, (int) yy1, NULL); | |
72cdf4c9 VZ |
391 | wxCoord xxx1 = (wxCoord) (xxc-ray); |
392 | wxCoord yyy1 = (wxCoord) (yyc-ray); | |
393 | wxCoord xxx2 = (wxCoord) (xxc+ray); | |
394 | wxCoord yyy2 = (wxCoord) (yyc+ray); | |
7bcb11d3 JS |
395 | if (m_brush.Ok() && m_brush.GetStyle() !=wxTRANSPARENT) |
396 | { | |
397 | // Have to add 1 to bottom-right corner of rectangle | |
398 | // to make semi-circles look right (crooked line otherwise). | |
399 | // Unfortunately this is not a reliable method, depends | |
400 | // on the size of shape. | |
401 | // TODO: figure out why this happens! | |
a23fd0e1 VZ |
402 | Pie(GetHdc(),xxx1,yyy1,xxx2+1,yyy2+1, |
403 | xx1,yy1,xx2,yy2); | |
7bcb11d3 JS |
404 | } |
405 | else | |
a23fd0e1 VZ |
406 | Arc(GetHdc(),xxx1,yyy1,xxx2,yyy2, |
407 | xx1,yy1,xx2,yy2); | |
408 | ||
72cdf4c9 VZ |
409 | CalcBoundingBox((wxCoord)(xc-radius), (wxCoord)(yc-radius)); |
410 | CalcBoundingBox((wxCoord)(xc+radius), (wxCoord)(yc+radius)); | |
2bda0e17 KB |
411 | } |
412 | ||
cd9da200 VZ |
413 | void wxDC::DoDrawCheckMark(wxCoord x1, wxCoord y1, |
414 | wxCoord width, wxCoord height) | |
415 | { | |
416 | wxCoord x2 = x1 + width, | |
417 | y2 = y1 + height; | |
418 | ||
419 | #if defined(__WIN32__) && !defined(__SC__) | |
420 | RECT rect; | |
421 | rect.left = x1; | |
422 | rect.top = y1; | |
423 | rect.right = x2; | |
424 | rect.bottom = y2; | |
425 | ||
426 | DrawFrameControl(GetHdc(), &rect, DFC_MENU, DFCS_MENUCHECK); | |
427 | #else // Win16 | |
428 | // In WIN16, draw a cross | |
429 | HPEN blackPen = ::CreatePen(PS_SOLID, 1, RGB(0, 0, 0)); | |
430 | HPEN whiteBrush = (HPEN)::GetStockObject(WHITE_BRUSH); | |
431 | HPEN hPenOld = (HPEN)::SelectObject(hdcMem, blackPen); | |
432 | HPEN hBrushOld = (HPEN)::SelectObject(hdcMem, whiteBrush); | |
433 | ::SetROP2(GetHdc(), R2_COPYPEN); | |
434 | Rectangle(GetHdc(), x1, y1, x2, y2); | |
435 | MoveTo(GetHdc(), x1, y1); | |
436 | LineTo(GetHdc(), x2, y2); | |
437 | MoveTo(GetHdc(), x2, y1); | |
438 | LineTo(GetHdc(), x1, y2); | |
439 | ::SelectObject(GetHdc(), hPenOld); | |
440 | ::SelectObject(GetHdc(), hBrushOld); | |
441 | ::DeleteObject(blackPen); | |
442 | #endif // Win32/16 | |
443 | ||
444 | CalcBoundingBox(x1, y1); | |
445 | CalcBoundingBox(x2, y2); | |
446 | } | |
447 | ||
72cdf4c9 | 448 | void wxDC::DoDrawPoint(wxCoord x, wxCoord y) |
2bda0e17 | 449 | { |
7bcb11d3 JS |
450 | COLORREF color = 0x00ffffff; |
451 | if (m_pen.Ok()) | |
452 | { | |
a23fd0e1 | 453 | color = m_pen.GetColour().GetPixel(); |
7bcb11d3 | 454 | } |
a23fd0e1 VZ |
455 | |
456 | SetPixel(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), color); | |
457 | ||
7bcb11d3 | 458 | CalcBoundingBox(x, y); |
2bda0e17 KB |
459 | } |
460 | ||
72cdf4c9 | 461 | void wxDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset,int fillStyle) |
2bda0e17 | 462 | { |
de2d2cdc VZ |
463 | COLORREF old_textground = ::GetTextColor(GetHdc()); |
464 | COLORREF old_background = ::GetBkColor(GetHdc()); | |
465 | if (m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) | |
466 | { | |
467 | ||
468 | if (m_textForegroundColour.Ok()) | |
469 | { //just the oposite from what is expected see help on pattern brush | |
470 | // 1 in mask becomes bk color | |
471 | ::SetBkColor(GetHdc(), m_textForegroundColour.GetPixel() ); | |
472 | } | |
473 | if (m_textBackgroundColour.Ok()) | |
474 | { //just the oposite from what is expected | |
475 | // 0 in mask becomes text color | |
476 | ::SetTextColor(GetHdc(), m_textBackgroundColour.GetPixel() ); | |
477 | } | |
478 | ||
479 | if (m_backgroundMode == wxTRANSPARENT) | |
480 | SetBkMode(GetHdc(), TRANSPARENT); | |
481 | else | |
482 | SetBkMode(GetHdc(), OPAQUE); | |
483 | } | |
484 | ||
7bcb11d3 JS |
485 | // Do things less efficiently if we have offsets |
486 | if (xoffset != 0 || yoffset != 0) | |
6a6c0a8b | 487 | { |
7bcb11d3 JS |
488 | POINT *cpoints = new POINT[n]; |
489 | int i; | |
490 | for (i = 0; i < n; i++) | |
491 | { | |
492 | cpoints[i].x = (int)(points[i].x + xoffset); | |
493 | cpoints[i].y = (int)(points[i].y + yoffset); | |
a23fd0e1 | 494 | |
7bcb11d3 JS |
495 | CalcBoundingBox(cpoints[i].x, cpoints[i].y); |
496 | } | |
a23fd0e1 VZ |
497 | int prev = SetPolyFillMode(GetHdc(),fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING); |
498 | (void)Polygon(GetHdc(), cpoints, n); | |
499 | SetPolyFillMode(GetHdc(),prev); | |
7bcb11d3 JS |
500 | delete[] cpoints; |
501 | } | |
502 | else | |
503 | { | |
504 | int i; | |
505 | for (i = 0; i < n; i++) | |
506 | CalcBoundingBox(points[i].x, points[i].y); | |
a23fd0e1 VZ |
507 | |
508 | int prev = SetPolyFillMode(GetHdc(),fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING); | |
509 | (void)Polygon(GetHdc(), (POINT*) points, n); | |
510 | SetPolyFillMode(GetHdc(),prev); | |
6a6c0a8b | 511 | } |
de2d2cdc VZ |
512 | |
513 | if (m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) | |
514 | { | |
515 | ::SetBkMode(GetHdc(), TRANSPARENT); | |
516 | ::SetTextColor(GetHdc(), old_textground); | |
517 | ::SetBkColor(GetHdc(), old_background); | |
518 | } | |
2bda0e17 KB |
519 | } |
520 | ||
72cdf4c9 | 521 | void wxDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset) |
2bda0e17 | 522 | { |
7bcb11d3 JS |
523 | // Do things less efficiently if we have offsets |
524 | if (xoffset != 0 || yoffset != 0) | |
6a6c0a8b | 525 | { |
7bcb11d3 JS |
526 | POINT *cpoints = new POINT[n]; |
527 | int i; | |
528 | for (i = 0; i < n; i++) | |
529 | { | |
530 | cpoints[i].x = (int)(points[i].x + xoffset); | |
531 | cpoints[i].y = (int)(points[i].y + yoffset); | |
a23fd0e1 | 532 | |
7bcb11d3 JS |
533 | CalcBoundingBox(cpoints[i].x, cpoints[i].y); |
534 | } | |
a23fd0e1 | 535 | (void)Polyline(GetHdc(), cpoints, n); |
7bcb11d3 JS |
536 | delete[] cpoints; |
537 | } | |
538 | else | |
539 | { | |
540 | int i; | |
541 | for (i = 0; i < n; i++) | |
542 | CalcBoundingBox(points[i].x, points[i].y); | |
a23fd0e1 VZ |
543 | |
544 | (void)Polyline(GetHdc(), (POINT*) points, n); | |
6a6c0a8b | 545 | } |
2bda0e17 KB |
546 | } |
547 | ||
72cdf4c9 | 548 | void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
2bda0e17 | 549 | { |
0bafad0c VZ |
550 | COLORREF colFgOld = 0, |
551 | colBgOld = 0; | |
552 | ||
553 | if ( m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE ) | |
de2d2cdc | 554 | { |
0bafad0c VZ |
555 | colFgOld = ::GetTextColor(GetHdc()); |
556 | colBgOld = ::GetBkColor(GetHdc()); | |
de2d2cdc | 557 | |
0bafad0c VZ |
558 | if ( m_textForegroundColour.Ok() ) |
559 | { | |
560 | // just the oposite from what is expected see help on pattern brush | |
561 | // 1 in mask becomes bk color | |
562 | ::SetBkColor(GetHdc(), m_textForegroundColour.GetPixel()); | |
563 | } | |
de2d2cdc | 564 | |
0bafad0c VZ |
565 | if ( m_textBackgroundColour.Ok() ) |
566 | { | |
567 | // 0 in mask becomes text color | |
568 | ::SetTextColor(GetHdc(), m_textBackgroundColour.GetPixel()); | |
569 | } | |
570 | ||
571 | // VZ: IMHO this does strictly nothing here | |
572 | SetBkMode(GetHdc(), m_backgroundMode == wxTRANSPARENT ? TRANSPARENT | |
573 | : OPAQUE); | |
de2d2cdc VZ |
574 | } |
575 | ||
72cdf4c9 VZ |
576 | wxCoord x2 = x + width; |
577 | wxCoord y2 = y + height; | |
a23fd0e1 | 578 | |
5456b916 | 579 | if ((m_logicalFunction == wxCOPY) && (m_pen.GetStyle() == wxTRANSPARENT)) |
0bafad0c | 580 | { |
7299b1b2 | 581 | RECT rect; |
5456b916 RR |
582 | rect.left = XLOG2DEV(x); |
583 | rect.top = YLOG2DEV(y); | |
584 | rect.right = XLOG2DEV(x2); | |
7299b1b2 RD |
585 | rect.bottom = YLOG2DEV(y2); |
586 | (void)FillRect(GetHdc(), &rect, (HBRUSH)m_brush.GetResourceHandle() ); | |
5456b916 RR |
587 | } |
588 | else | |
589 | { | |
590 | // Windows draws the filled rectangles without outline (i.e. drawn with a | |
591 | // transparent pen) one pixel smaller in both directions and we want them | |
592 | // to have the same size regardless of which pen is used - adjust | |
593 | ||
594 |