]>
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 | ||
840bb342 | 43 | #include "wx/settings.h" |
2bda0e17 | 44 | #include "wx/dcprint.h" |
2bda0e17 KB |
45 | |
46 | #include <string.h> | |
47 | #include <math.h> | |
2bda0e17 | 48 | |
a58a12e9 VZ |
49 | #include "wx/msw/private.h" // needs to be before #include <commdlg.h> |
50 | ||
47d67540 | 51 | #if wxUSE_COMMON_DIALOGS |
a23fd0e1 | 52 | #include <commdlg.h> |
2bda0e17 KB |
53 | #endif |
54 | ||
55 | #ifndef __WIN32__ | |
a23fd0e1 | 56 | #include <print.h> |
2bda0e17 KB |
57 | #endif |
58 | ||
5acb7b3e | 59 | IMPLEMENT_ABSTRACT_CLASS(wxDC, wxDCBase) |
2bda0e17 | 60 | |
a23fd0e1 VZ |
61 | // --------------------------------------------------------------------------- |
62 | // constants | |
63 | // --------------------------------------------------------------------------- | |
64 | ||
42e69d6b VZ |
65 | static const int VIEWPORT_EXTENT = 1000; |
66 | ||
67 | static const int MM_POINTS = 9; | |
68 | static const int MM_METRIC = 10; | |
a23fd0e1 | 69 | |
4314ec48 VZ |
70 | // usually this is defined in math.h |
71 | #ifndef M_PI | |
72 | static const double M_PI = 3.14159265358979323846; | |
73 | #endif // M_PI | |
74 | ||
4aff28fc VZ |
75 | // ROPs which don't have standard names (see "Ternary Raster Operations" in the |
76 | // MSDN docs for how this and other numbers in wxDC::Blit() are obtained) | |
77 | #define DSTCOPY 0x00AA0029 // a.k.a. NOP operation | |
78 | ||
4314ec48 VZ |
79 | // --------------------------------------------------------------------------- |
80 | // private functions | |
81 | // --------------------------------------------------------------------------- | |
82 | ||
83 | // convert degrees to radians | |
84 | static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; } | |
85 | ||
f6bcfd97 BP |
86 | // ---------------------------------------------------------------------------- |
87 | // private classes | |
88 | // ---------------------------------------------------------------------------- | |
89 | ||
90 | // instead of duplicating the same code which sets and then restores text | |
91 | // colours in each wxDC method working with wxSTIPPLE_MASK_OPAQUE brushes, | |
92 | // encapsulate this in a small helper class | |
93 | ||
94 | // wxColourChanger: changes the text colours in the ctor if required and | |
95 | // restores them in the dtor | |
96 | class wxColourChanger | |
97 | { | |
98 | public: | |
99 | wxColourChanger(wxDC& dc); | |
100 | ~wxColourChanger(); | |
101 | ||
102 | private: | |
103 | wxDC& m_dc; | |
104 | ||
105 | COLORREF m_colFgOld, m_colBgOld; | |
106 | ||
107 | bool m_changed; | |
108 | }; | |
109 | ||
a23fd0e1 VZ |
110 | // =========================================================================== |
111 | // implementation | |
112 | // =========================================================================== | |
113 | ||
f6bcfd97 BP |
114 | // ---------------------------------------------------------------------------- |
115 | // wxColourChanger | |
116 | // ---------------------------------------------------------------------------- | |
117 | ||
118 | wxColourChanger::wxColourChanger(wxDC& dc) : m_dc(dc) | |
119 | { | |
120 | if ( dc.GetBrush().GetStyle() == wxSTIPPLE_MASK_OPAQUE ) | |
121 | { | |
122 | HDC hdc = GetHdcOf(dc); | |
123 | m_colFgOld = ::GetTextColor(hdc); | |
124 | m_colBgOld = ::GetBkColor(hdc); | |
125 | ||
126 | // note that Windows convention is opposite to wxWindows one, this is | |
127 | // why text colour becomes the background one and vice versa | |
128 | const wxColour& colFg = dc.GetTextForeground(); | |
129 | if ( colFg.Ok() ) | |
130 | { | |
131 | ::SetBkColor(hdc, colFg.GetPixel()); | |
132 | } | |
133 | ||
134 | const wxColour& colBg = dc.GetTextBackground(); | |
135 | if ( colBg.Ok() ) | |
136 | { | |
137 | ::SetTextColor(hdc, colBg.GetPixel()); | |
138 | } | |
139 | ||
140 | SetBkMode(hdc, | |
141 | dc.GetBackgroundMode() == wxTRANSPARENT ? TRANSPARENT | |
142 | : OPAQUE); | |
143 | ||
144 | // flag which telsl us to undo changes in the dtor | |
145 | m_changed = TRUE; | |
146 | } | |
147 | else | |
148 | { | |
149 | // nothing done, nothing to undo | |
150 | m_changed = FALSE; | |
151 | } | |
152 | } | |
153 | ||
154 | wxColourChanger::~wxColourChanger() | |
155 | { | |
156 | if ( m_changed ) | |
157 | { | |
158 | // restore the colours we changed | |
159 | HDC hdc = GetHdcOf(m_dc); | |
160 | ||
161 | ::SetBkMode(hdc, TRANSPARENT); | |
162 | ::SetTextColor(hdc, m_colFgOld); | |
163 | ::SetBkColor(hdc, m_colBgOld); | |
164 | } | |
165 | } | |
166 | ||
a23fd0e1 VZ |
167 | // --------------------------------------------------------------------------- |
168 | // wxDC | |
169 | // --------------------------------------------------------------------------- | |
2bda0e17 KB |
170 | |
171 | // Default constructor | |
a23fd0e1 | 172 | wxDC::wxDC() |
2bda0e17 | 173 | { |
7bcb11d3 | 174 | m_canvas = NULL; |
a23fd0e1 | 175 | |
7bcb11d3 JS |
176 | m_oldBitmap = 0; |
177 | m_oldPen = 0; | |
178 | m_oldBrush = 0; | |
179 | m_oldFont = 0; | |
180 | m_oldPalette = 0; | |
a23fd0e1 | 181 | |
7bcb11d3 JS |
182 | m_bOwnsDC = FALSE; |
183 | m_hDC = 0; | |
a23fd0e1 | 184 | |
7bcb11d3 JS |
185 | m_windowExtX = VIEWPORT_EXTENT; |
186 | m_windowExtY = VIEWPORT_EXTENT; | |
2bda0e17 KB |
187 | } |
188 | ||
189 | ||
a23fd0e1 | 190 | wxDC::~wxDC() |
2bda0e17 | 191 | { |
7ba4fbeb VZ |
192 | if ( m_hDC != 0 ) |
193 | { | |
7bcb11d3 | 194 | SelectOldObjects(m_hDC); |
7ba4fbeb VZ |
195 | |
196 | // if we own the HDC, we delete it, otherwise we just release it | |
197 | ||
198 | if ( m_bOwnsDC ) | |
199 | { | |
200 | ::DeleteDC(GetHdc()); | |
7bcb11d3 | 201 | } |
7ba4fbeb VZ |
202 | else // we don't own our HDC |
203 | { | |
db400410 JS |
204 | if (m_canvas) |
205 | { | |
206 | ::ReleaseDC(GetHwndOf(m_canvas), GetHdc()); | |
207 | } | |
208 | else | |
209 | { | |
210 | // Must have been a wxScreenDC | |
211 | ::ReleaseDC((HWND) NULL, GetHdc()); | |
212 | } | |
7ba4fbeb VZ |
213 | } |
214 | } | |
2bda0e17 KB |
215 | } |
216 | ||
217 | // This will select current objects out of the DC, | |
218 | // which is what you have to do before deleting the | |
219 | // DC. | |
220 | void wxDC::SelectOldObjects(WXHDC dc) | |
221 | { | |
7bcb11d3 | 222 | if (dc) |
2bda0e17 | 223 | { |
7bcb11d3 JS |
224 | if (m_oldBitmap) |
225 | { | |
226 | ::SelectObject((HDC) dc, (HBITMAP) m_oldBitmap); | |
227 | if (m_selectedBitmap.Ok()) | |
228 | { | |
229 | m_selectedBitmap.SetSelectedInto(NULL); | |
230 | } | |
231 | } | |
a23fd0e1 | 232 | m_oldBitmap = 0; |
7bcb11d3 JS |
233 | if (m_oldPen) |
234 | { | |
235 | ::SelectObject((HDC) dc, (HPEN) m_oldPen); | |
236 | } | |
a23fd0e1 | 237 | m_oldPen = 0; |
7bcb11d3 JS |
238 | if (m_oldBrush) |
239 | { | |
240 | ::SelectObject((HDC) dc, (HBRUSH) m_oldBrush); | |
241 | } | |
a23fd0e1 | 242 | m_oldBrush = 0; |
7bcb11d3 JS |
243 | if (m_oldFont) |
244 | { | |
245 | ::SelectObject((HDC) dc, (HFONT) m_oldFont); | |
246 | } | |
a23fd0e1 | 247 | m_oldFont = 0; |
7bcb11d3 JS |
248 | if (m_oldPalette) |
249 | { | |
250 | ::SelectPalette((HDC) dc, (HPALETTE) m_oldPalette, TRUE); | |
251 | } | |
a23fd0e1 | 252 | m_oldPalette = 0; |
2bda0e17 | 253 | } |
a23fd0e1 VZ |
254 | |
255 | m_brush = wxNullBrush; | |
7bcb11d3 JS |
256 | m_pen = wxNullPen; |
257 | m_palette = wxNullPalette; | |
258 | m_font = wxNullFont; | |
259 | m_backgroundBrush = wxNullBrush; | |
260 | m_selectedBitmap = wxNullBitmap; | |
2bda0e17 KB |
261 | } |
262 | ||
a23fd0e1 VZ |
263 | // --------------------------------------------------------------------------- |
264 | // clipping | |
265 | // --------------------------------------------------------------------------- | |
266 | ||
1e6feb95 VZ |
267 | void wxDC::UpdateClipBox() |
268 | { | |
5adad466 JS |
269 | #ifdef __WXMICROWIN__ |
270 | if (!GetHDC()) return; | |
271 | #endif | |
272 | ||
1e6feb95 VZ |
273 | RECT rect; |
274 | GetClipBox(GetHdc(), &rect); | |
275 | ||
276 | m_clipX1 = (wxCoord) XDEV2LOG(rect.left); | |
277 | m_clipY1 = (wxCoord) YDEV2LOG(rect.top); | |
278 | m_clipX2 = (wxCoord) XDEV2LOG(rect.right); | |
279 | m_clipY2 = (wxCoord) YDEV2LOG(rect.bottom); | |
f547e9bb RL |
280 | } |
281 | ||
c4218a74 | 282 | void wxDC::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h) |
2bda0e17 | 283 | { |
5adad466 JS |
284 | #ifdef __WXMICROWIN__ |
285 | if (!GetHDC()) return; | |
286 | #endif | |
287 | ||
7bcb11d3 | 288 | m_clipping = TRUE; |
40a89076 | 289 | |
c4218a74 VZ |
290 | // the region coords are always the device ones, so do the translation |
291 | // manually | |
1e6feb95 VZ |
292 | // |
293 | // FIXME: possible +/-1 error here, to check! | |
c4218a74 VZ |
294 | HRGN hrgn = ::CreateRectRgn(LogicalToDeviceX(x), |
295 | LogicalToDeviceY(y), | |
296 | LogicalToDeviceX(x + w), | |
297 | LogicalToDeviceY(y + h)); | |
40a89076 VZ |
298 | if ( !hrgn ) |
299 | { | |
300 | wxLogLastError(_T("CreateRectRgn")); | |
301 | } | |
302 | else | |
303 | { | |
304 | if ( ::SelectClipRgn(GetHdc(), hrgn) == ERROR ) | |
305 | { | |
306 | wxLogLastError(_T("SelectClipRgn")); | |
307 | } | |
7ecf5ac7 | 308 | DeleteObject(hrgn); |
40a89076 | 309 | |
1e6feb95 | 310 | UpdateClipBox(); |
40a89076 | 311 | } |
2bda0e17 KB |
312 | } |
313 | ||
a23fd0e1 | 314 | void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region) |
a724d789 | 315 | { |
5adad466 JS |
316 | #ifdef __WXMICROWIN__ |
317 | if (!GetHDC()) return; | |
318 | #endif | |
319 | ||
1e6feb95 | 320 | wxCHECK_RET( GetHrgnOf(region), wxT("invalid clipping region") ); |
a23fd0e1 | 321 | |
7bcb11d3 | 322 | m_clipping = TRUE; |
a23fd0e1 | 323 | |
1e6d9499 | 324 | #ifdef __WIN16__ |
1e6feb95 VZ |
325 | SelectClipRgn(GetHdc(), GetHrgnOf(region)); |
326 | #else // Win32 | |
327 | ExtSelectClipRgn(GetHdc(), GetHrgnOf(region), RGN_AND); | |
328 | #endif // Win16/32 | |
a724d789 | 329 | |
1e6feb95 | 330 | UpdateClipBox(); |
2bda0e17 KB |
331 | } |
332 | ||
a23fd0e1 | 333 | void wxDC::DestroyClippingRegion() |
2bda0e17 | 334 | { |
5adad466 JS |
335 | #ifdef __WXMICROWIN__ |
336 | if (!GetHDC()) return; | |
337 | #endif | |
338 | ||
7bcb11d3 JS |
339 | if (m_clipping && m_hDC) |
340 | { | |
341 | // TODO: this should restore the previous clipping region, | |
342 | // so that OnPaint processing works correctly, and the update clipping region | |
343 | // doesn't get destroyed after the first DestroyClippingRegion. | |
344 | HRGN rgn = CreateRectRgn(0, 0, 32000, 32000); | |
a23fd0e1 | 345 | SelectClipRgn(GetHdc(), rgn); |
7bcb11d3 JS |
346 | DeleteObject(rgn); |
347 | } | |
1e6feb95 | 348 | |
7bcb11d3 | 349 | m_clipping = FALSE; |
2bda0e17 KB |
350 | } |
351 | ||
a23fd0e1 VZ |
352 | // --------------------------------------------------------------------------- |
353 | // query capabilities | |
354 | // --------------------------------------------------------------------------- | |
355 | ||
356 | bool wxDC::CanDrawBitmap() const | |
2bda0e17 | 357 | { |
7bcb11d3 | 358 | return TRUE; |
2bda0e17 KB |
359 | } |
360 | ||
a23fd0e1 | 361 | bool wxDC::CanGetTextExtent() const |
2bda0e17 | 362 | { |
04ef50df JS |
363 | #ifdef __WXMICROWIN__ |
364 | // TODO Extend MicroWindows' GetDeviceCaps function | |
365 | return TRUE; | |
366 | #else | |
7bcb11d3 | 367 | // What sort of display is it? |
a23fd0e1 VZ |
368 | int technology = ::GetDeviceCaps(GetHdc(), TECHNOLOGY); |
369 | ||
370 | return (technology == DT_RASDISPLAY) || (technology == DT_RASPRINTER); | |
04ef50df | 371 | #endif |
2bda0e17 KB |
372 | } |
373 | ||
a23fd0e1 | 374 | int wxDC::GetDepth() const |
2bda0e17 | 375 | { |
5adad466 JS |
376 | #ifdef __WXMICROWIN__ |
377 | if (!GetHDC()) return 16; | |
378 | #endif | |
379 | ||
a23fd0e1 | 380 | return (int)::GetDeviceCaps(GetHdc(), BITSPIXEL); |
2bda0e17 KB |
381 | } |
382 | ||
a23fd0e1 VZ |
383 | // --------------------------------------------------------------------------- |
384 | // drawing | |
385 | // --------------------------------------------------------------------------- | |
386 | ||
387 | void wxDC::Clear() | |
2bda0e17 | 388 | { |
5adad466 JS |
389 | #ifdef __WXMICROWIN__ |
390 | if (!GetHDC()) return; | |
391 | #endif | |
392 | ||
7bcb11d3 | 393 | RECT rect; |
2506aab6 VZ |
394 | if ( m_canvas ) |
395 | { | |
7bcb11d3 | 396 | GetClientRect((HWND) m_canvas->GetHWND(), &rect); |
2506aab6 VZ |
397 | } |
398 | else | |
7bcb11d3 | 399 | { |
eaeb6a3c JS |
400 | // No, I think we should simply ignore this if printing on e.g. |
401 | // a printer DC. | |
402 | // wxCHECK_RET( m_selectedBitmap.Ok(), wxT("this DC can't be cleared") ); | |
403 | if (!m_selectedBitmap.Ok()) | |
404 | return; | |
2506aab6 | 405 | |
7bcb11d3 JS |
406 | rect.left = 0; rect.top = 0; |
407 | rect.right = m_selectedBitmap.GetWidth(); | |
408 | rect.bottom = m_selectedBitmap.GetHeight(); | |
409 | } | |
2506aab6 | 410 | |
a23fd0e1 VZ |
411 | (void) ::SetMapMode(GetHdc(), MM_TEXT); |
412 | ||
413 | DWORD colour = GetBkColor(GetHdc()); | |
7bcb11d3 | 414 | HBRUSH brush = CreateSolidBrush(colour); |
a23fd0e1 | 415 | FillRect(GetHdc(), &rect, brush); |
7bcb11d3 | 416 | DeleteObject(brush); |
a23fd0e1 VZ |
417 | |
418 | ::SetMapMode(GetHdc(), MM_ANISOTROPIC); | |
419 | ::SetViewportExtEx(GetHdc(), VIEWPORT_EXTENT, VIEWPORT_EXTENT, NULL); | |
420 | ::SetWindowExtEx(GetHdc(), m_windowExtX, m_windowExtY, NULL); | |
421 | ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX, (int)m_deviceOriginY, NULL); | |
422 | ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX, (int)m_logicalOriginY, NULL); | |
423 | } | |
424 | ||
72cdf4c9 | 425 | void wxDC::DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, int style) |
a23fd0e1 | 426 | { |
5adad466 JS |
427 | #ifdef __WXMICROWIN__ |
428 | if (!GetHDC()) return; | |
429 | #endif | |
430 | ||
0bafad0c VZ |
431 | if ( !::ExtFloodFill(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), |
432 | col.GetPixel(), | |
433 | style == wxFLOOD_SURFACE ? FLOODFILLSURFACE | |
434 | : FLOODFILLBORDER) ) | |
435 | { | |
436 | // quoting from the MSDN docs: | |
437 | // | |
438 | // Following are some of the reasons this function might fail: | |
439 | // | |
440 | // * The filling could not be completed. | |
441 | // * The specified point has the boundary color specified by the | |
442 | // crColor parameter (if FLOODFILLBORDER was requested). | |
443 | // * The specified point does not have the color specified by | |
444 | // crColor (if FLOODFILLSURFACE was requested) | |
445 | // * The point is outside the clipping region that is, it is not | |
446 | // visible on the device. | |
447 | // | |
f6bcfd97 | 448 | wxLogLastError(wxT("ExtFloodFill")); |
0bafad0c | 449 | } |
a23fd0e1 | 450 | |
7bcb11d3 | 451 | CalcBoundingBox(x, y); |
2bda0e17 KB |
452 | } |
453 | ||
72cdf4c9 | 454 | bool wxDC::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const |
2bda0e17 | 455 | { |
5adad466 JS |
456 | #ifdef __WXMICROWIN__ |
457 | if (!GetHDC()) return FALSE; | |
458 | #endif | |
459 | ||
f6bcfd97 BP |
460 | wxCHECK_MSG( col, FALSE, _T("NULL colour parameter in wxDC::GetPixel") ); |
461 | ||
7bcb11d3 | 462 | // get the color of the pixel |
a23fd0e1 | 463 | COLORREF pixelcolor = ::GetPixel(GetHdc(), XLOG2DEV(x), YLOG2DEV(y)); |
0bafad0c | 464 | |
f6bcfd97 | 465 | wxRGBToColour(*col, pixelcolor); |
dc1efb1d JS |
466 | |
467 | return TRUE; | |
2bda0e17 KB |
468 | } |
469 | ||
72cdf4c9 | 470 | void wxDC::DoCrossHair(wxCoord x, wxCoord y) |
a23fd0e1 | 471 | { |
5adad466 JS |
472 | #ifdef __WXMICROWIN__ |
473 | if (!GetHDC()) return; | |
474 | #endif | |
475 | ||
72cdf4c9 VZ |
476 | wxCoord x1 = x-VIEWPORT_EXTENT; |
477 | wxCoord y1 = y-VIEWPORT_EXTENT; | |
478 | wxCoord x2 = x+VIEWPORT_EXTENT; | |
479 | wxCoord y2 = y+VIEWPORT_EXTENT; | |
a23fd0e1 VZ |
480 | |
481 | (void)MoveToEx(GetHdc(), XLOG2DEV(x1), YLOG2DEV(y), NULL); | |
482 | (void)LineTo(GetHdc(), XLOG2DEV(x2), YLOG2DEV(y)); | |
483 | ||
484 | (void)MoveToEx(GetHdc(), XLOG2DEV(x), YLOG2DEV(y1), NULL); | |
485 | (void)LineTo(GetHdc(), XLOG2DEV(x), YLOG2DEV(y2)); | |
486 | ||
7bcb11d3 JS |
487 | CalcBoundingBox(x1, y1); |
488 | CalcBoundingBox(x2, y2); | |
2bda0e17 KB |
489 | } |
490 | ||
72cdf4c9 | 491 | void wxDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) |
2bda0e17 | 492 | { |
5adad466 JS |
493 | #ifdef __WXMICROWIN__ |
494 | if (!GetHDC()) return; | |
495 | #endif | |
496 | ||
a23fd0e1 VZ |
497 | (void)MoveToEx(GetHdc(), XLOG2DEV(x1), YLOG2DEV(y1), NULL); |
498 | (void)LineTo(GetHdc(), XLOG2DEV(x2), YLOG2DEV(y2)); | |
499 | ||
058939fc JS |
500 | // Normalization: Windows doesn't draw the last point of the line. |
501 | // But apparently neither does GTK+, so we take it out again. | |
502 | // (void)LineTo(GetHdc(), XLOG2DEV(x2) + 1, YLOG2DEV(y2)); | |
a23fd0e1 | 503 | |
7bcb11d3 JS |
504 | CalcBoundingBox(x1, y1); |
505 | CalcBoundingBox(x2, y2); | |
2bda0e17 KB |
506 | } |
507 | ||
f6bcfd97 BP |
508 | // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1) |
509 | // and ending at (x2, y2) | |
510 | void wxDC::DoDrawArc(wxCoord x1, wxCoord y1, | |
511 | wxCoord x2, wxCoord y2, | |
512 | wxCoord xc, wxCoord yc) | |
2bda0e17 | 513 | { |
5adad466 JS |
514 | #ifdef __WXMICROWIN__ |
515 | if (!GetHDC()) return; | |
516 | #endif | |
517 | ||
f6bcfd97 | 518 | wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling |
2d8a5cb1 | 519 | |
f6bcfd97 BP |
520 | double dx = xc - x1; |
521 | double dy = yc - y1; | |
522 | double radius = (double)sqrt(dx*dx+dy*dy); | |
523 | wxCoord r = (wxCoord)radius; | |
2d8a5cb1 | 524 | |
f6bcfd97 BP |
525 | // treat the special case of full circle separately |
526 | if ( x1 == x2 && y1 == y2 ) | |
7bcb11d3 | 527 | { |
f6bcfd97 | 528 | DrawEllipse(xc - r, yc - r, 2*r, 2*r); |
a23fd0e1 | 529 | return; |
7bcb11d3 | 530 | } |
a23fd0e1 | 531 | |
72cdf4c9 VZ |
532 | wxCoord xx1 = XLOG2DEV(x1); |
533 | wxCoord yy1 = YLOG2DEV(y1); | |
534 | wxCoord xx2 = XLOG2DEV(x2); | |
535 | wxCoord yy2 = YLOG2DEV(y2); | |
536 | wxCoord xxc = XLOG2DEV(xc); | |
537 | wxCoord yyc = YLOG2DEV(yc); | |
538 | wxCoord ray = (wxCoord) sqrt(double((xxc-xx1)*(xxc-xx1)+(yyc-yy1)*(yyc-yy1))); | |
a23fd0e1 | 539 | |
72cdf4c9 VZ |
540 | wxCoord xxx1 = (wxCoord) (xxc-ray); |
541 | wxCoord yyy1 = (wxCoord) (yyc-ray); | |
542 | wxCoord xxx2 = (wxCoord) (xxc+ray); | |
543 | wxCoord yyy2 = (wxCoord) (yyc+ray); | |
f6bcfd97 BP |
544 | |
545 | if ( m_brush.Ok() && m_brush.GetStyle() != wxTRANSPARENT ) | |
7bcb11d3 JS |
546 | { |
547 | // Have to add 1 to bottom-right corner of rectangle | |
548 | // to make semi-circles look right (crooked line otherwise). | |
549 | // Unfortunately this is not a reliable method, depends | |
550 | // on the size of shape. | |
551 | // TODO: figure out why this happens! | |
f6bcfd97 | 552 | Pie(GetHdc(),xxx1,yyy1,xxx2+1,yyy2+1, xx1,yy1,xx2,yy2); |
7bcb11d3 JS |
553 | } |
554 | else | |
2d8a5cb1 | 555 | { |
f6bcfd97 | 556 | Arc(GetHdc(),xxx1,yyy1,xxx2,yyy2, xx1,yy1,xx2,yy2); |
2d8a5cb1 | 557 | } |
f6bcfd97 BP |
558 | |
559 | CalcBoundingBox(xc - r, yc - r); | |
560 | CalcBoundingBox(xc + r, yc + r); | |
2bda0e17 KB |
561 | } |
562 | ||
cd9da200 VZ |
563 | void wxDC::DoDrawCheckMark(wxCoord x1, wxCoord y1, |
564 | wxCoord width, wxCoord height) | |
565 | { | |
5adad466 JS |
566 | #ifdef __WXMICROWIN__ |
567 | if (!GetHDC()) return; | |
568 | #endif | |
569 | ||
cd9da200 VZ |
570 | wxCoord x2 = x1 + width, |
571 | y2 = y1 + height; | |
572 | ||
04ef50df | 573 | #if defined(__WIN32__) && !defined(__SC__) && !defined(__WXMICROWIN__) |
cd9da200 VZ |
574 | RECT rect; |
575 | rect.left = x1; | |
576 | rect.top = y1; | |
577 | rect.right = x2; | |
578 | rect.bottom = y2; | |
579 | ||
580 | DrawFrameControl(GetHdc(), &rect, DFC_MENU, DFCS_MENUCHECK); | |
581 | #else // Win16 | |
582 | // In WIN16, draw a cross | |
583 | HPEN blackPen = ::CreatePen(PS_SOLID, 1, RGB(0, 0, 0)); | |
584 | HPEN whiteBrush = (HPEN)::GetStockObject(WHITE_BRUSH); | |
e06b9569 JS |
585 | HPEN hPenOld = (HPEN)::SelectObject(GetHdc(), blackPen); |
586 | HPEN hBrushOld = (HPEN)::SelectObject(GetHdc(), whiteBrush); | |
cd9da200 VZ |
587 | ::SetROP2(GetHdc(), R2_COPYPEN); |
588 | Rectangle(GetHdc(), x1, y1, x2, y2); | |
8cb172b4 | 589 | MoveToEx(GetHdc(), x1, y1, NULL); |
cd9da200 | 590 | LineTo(GetHdc(), x2, y2); |
8cb172b4 | 591 | MoveToEx(GetHdc(), x2, y1, NULL); |
cd9da200 VZ |
592 | LineTo(GetHdc(), x1, y2); |
593 | ::SelectObject(GetHdc(), hPenOld); | |
594 | ::SelectObject(GetHdc(), hBrushOld); | |
595 | ::DeleteObject(blackPen); | |
596 | #endif // Win32/16 | |
597 | ||
598 | CalcBoundingBox(x1, y1); | |
599 | CalcBoundingBox(x2, y2); | |
600 | } | |
601 | ||
72cdf4c9 | 602 | void wxDC::DoDrawPoint(wxCoord x, wxCoord y) |
2bda0e17 | 603 | { |
5adad466 JS |
604 | #ifdef __WXMICROWIN__ |
605 | if (!GetHDC()) return; | |
606 | #endif | |
607 | ||
7bcb11d3 JS |
608 | COLORREF color = 0x00ffffff; |
609 | if (m_pen.Ok()) | |
610 | { | |
a23fd0e1 | 611 | color = m_pen.GetColour().GetPixel(); |
7bcb11d3 | 612 | } |
a23fd0e1 VZ |
613 | |
614 | SetPixel(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), color); | |
615 | ||
7bcb11d3 | 616 | CalcBoundingBox(x, y); |
2bda0e17 KB |
617 | } |
618 | ||
72cdf4c9 | 619 | void wxDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset,int fillStyle) |
2bda0e17 | 620 | { |
5adad466 JS |
621 | #ifdef __WXMICROWIN__ |
622 | if (!GetHDC()) return; | |
623 | #endif | |
624 | ||
f6bcfd97 | 625 | wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling |
de2d2cdc | 626 | |
7bcb11d3 JS |
627 | // Do things less efficiently if we have offsets |
628 | if (xoffset != 0 || yoffset != 0) | |
6a6c0a8b | 629 | { |
7bcb11d3 JS |
630 | POINT *cpoints = new POINT[n]; |
631 | int i; | |
632 | for (i = 0; i < n; i++) | |
633 | { | |
634 | cpoints[i].x = (int)(points[i].x + xoffset); | |
635 | cpoints[i].y = (int)(points[i].y + yoffset); | |
a23fd0e1 | 636 | |
7bcb11d3 JS |
637 | CalcBoundingBox(cpoints[i].x, cpoints[i].y); |
638 | } | |
a23fd0e1 VZ |
639 | int prev = SetPolyFillMode(GetHdc(),fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING); |
640 | (void)Polygon(GetHdc(), cpoints, n); | |
641 | SetPolyFillMode(GetHdc(),prev); | |
7bcb11d3 JS |
642 | delete[] cpoints; |
643 | } | |
644 | else | |
645 | { | |
646 | int i; | |
647 | for (i = 0; i < n; i++) | |
648 | CalcBoundingBox(points[i].x, points[i].y); | |
a23fd0e1 VZ |
649 | |
650 | int prev = SetPolyFillMode(GetHdc(),fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING); | |
651 | (void)Polygon(GetHdc(), (POINT*) points, n); | |
652 | SetPolyFillMode(GetHdc(),prev); | |
6a6c0a8b | 653 | } |
2bda0e17 KB |
654 | } |
655 | ||
72cdf4c9 | 656 | void wxDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset) |
2bda0e17 | 657 | { |
5adad466 JS |
658 | #ifdef __WXMICROWIN__ |
659 | if (!GetHDC()) return; | |
660 | #endif | |
661 | ||
7bcb11d3 JS |
662 | // Do things less efficiently if we have offsets |
663 | if (xoffset != 0 || yoffset != 0) | |
6a6c0a8b | 664 | { |
7bcb11d3 JS |
665 | POINT *cpoints = new POINT[n]; |
666 | int i; | |
667 | for (i = 0; i < n; i++) | |
668 | { | |
669 | cpoints[i].x = (int)(points[i].x + xoffset); | |
670 | cpoints[i].y = (int)(points[i].y + yoffset); | |
a23fd0e1 | 671 | |
7bcb11d3 JS |
672 | CalcBoundingBox(cpoints[i].x, cpoints[i].y); |
673 | } | |
a23fd0e1 | 674 | (void)Polyline(GetHdc(), cpoints, n); |
7bcb11d3 JS |
675 | delete[] cpoints; |
676 | } | |
677 | else | |
678 | { | |
679 | int i; | |
680 | for (i = 0; i < n; i++) | |
681 | CalcBoundingBox(points[i].x, points[i].y); | |
a23fd0e1 VZ |
682 | |
683 | (void)Polyline(GetHdc(), (POINT*) points, n); | |
6a6c0a8b | 684 | } |
2bda0e17 KB |
685 | } |
686 | ||
72cdf4c9 | 687 | void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
2bda0e17 | 688 | { |
5adad466 JS |
689 | #ifdef __WXMICROWIN__ |
690 | if (!GetHDC()) return; | |
691 | #endif | |
692 | ||
f6bcfd97 | 693 | wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling |
de2d2cdc | 694 | |
72cdf4c9 VZ |
695 | wxCoord x2 = x + width; |
696 | wxCoord y2 = y + height; | |
a23fd0e1 | 697 | |
5456b916 | 698 | if ((m_logicalFunction == wxCOPY) && (m_pen.GetStyle() == wxTRANSPARENT)) |
0bafad0c | 699 | { |
7299b1b2 | 700 | RECT rect; |
5456b916 RR |
701 | rect.left = XLOG2DEV(x); |
702 | rect.top = YLOG2DEV(y); | |
703 | rect.right = XLOG2DEV(x2); | |
7299b1b2 RD |
704 | rect.bottom = YLOG2DEV(y2); |
705 | (void)FillRect(GetHdc(), &rect, (HBRUSH)m_brush.GetResourceHandle() ); | |
5456b916 RR |
706 | } |
707 | else | |
708 | { | |
709 | // Windows draws the filled rectangles without outline (i.e. drawn with a | |
710 | // transparent pen) one pixel smaller in both directions and we want them | |
f6bcfd97 | 711 | // to have the same size regardless of which pen is used - adjust |
5456b916 RR |
712 | |
713 |