]>
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 | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "dc.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include "wx/frame.h" | |
25 | #include "wx/dc.h" | |
26 | #include "wx/utils.h" | |
27 | #include "wx/dialog.h" | |
28 | #include "wx/app.h" | |
29 | #endif | |
30 | ||
31 | #include "wx/dcprint.h" | |
32 | #include "wx/msw/private.h" | |
33 | ||
34 | #include <string.h> | |
35 | #include <math.h> | |
36 | #include <fstream.h> | |
37 | ||
38 | #if USE_COMMON_DIALOGS | |
39 | #include <commdlg.h> | |
40 | #endif | |
41 | ||
42 | #ifndef __WIN32__ | |
43 | #include <print.h> | |
44 | #endif | |
45 | ||
46 | #ifdef DrawText | |
47 | #undef DrawText | |
48 | #endif | |
49 | ||
50 | #ifdef GetCharWidth | |
51 | #undef GetCharWidth | |
52 | #endif | |
53 | ||
54 | #ifdef StartDoc | |
55 | #undef StartDoc | |
56 | #endif | |
57 | ||
58 | #if !USE_SHARED_LIBRARY | |
59 | IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject) | |
60 | #endif | |
61 | ||
62 | // Declarations local to this file | |
63 | ||
64 | #define YSCALE(y) (yorigin - (y)) | |
65 | ||
66 | // #define wx_round(a) (int)((a)+.5) | |
67 | ||
68 | // Default constructor | |
69 | wxDC::wxDC(void) | |
70 | { | |
2bda0e17 KB |
71 | m_minX = 0; m_minY = 0; m_maxX = 0; m_maxY = 0; |
72 | m_clipping = FALSE; | |
2bda0e17 KB |
73 | |
74 | m_filename = ""; | |
2bda0e17 | 75 | m_canvas = NULL; |
2bda0e17 KB |
76 | m_oldBitmap = 0; |
77 | m_oldPen = 0; | |
78 | m_oldBrush = 0; | |
79 | m_oldFont = 0; | |
80 | m_oldPalette = 0; | |
81 | m_minX = 0; m_minY = 0; m_maxX = 0; m_maxY = 0; | |
2bda0e17 KB |
82 | m_logicalOriginX = 0; |
83 | m_logicalOriginY = 0; | |
84 | m_deviceOriginX = 0; | |
85 | m_deviceOriginY = 0; | |
86 | m_logicalScaleX = 1.0; | |
87 | m_logicalScaleY = 1.0; | |
88 | m_userScaleX = 1.0; | |
89 | m_userScaleY = 1.0; | |
6f65e337 JS |
90 | m_signX = 1; |
91 | m_signY = 1; | |
2bda0e17 KB |
92 | m_systemScaleX = 1.0; |
93 | m_systemScaleY = 1.0; | |
94 | m_mappingMode = MM_TEXT; | |
2bda0e17 KB |
95 | m_bOwnsDC = FALSE; |
96 | m_hDC = 0; | |
97 | m_clipping = FALSE; | |
98 | m_ok = TRUE; | |
99 | m_windowExtX = VIEWPORT_EXTENT; | |
100 | m_windowExtY = VIEWPORT_EXTENT; | |
101 | m_logicalFunction = -1; | |
102 | ||
103 | m_backgroundBrush = *wxWHITE_BRUSH; | |
2bda0e17 KB |
104 | |
105 | m_textForegroundColour = *wxBLACK; | |
106 | m_textBackgroundColour = *wxWHITE; | |
107 | ||
108 | m_colour = wxColourDisplay(); | |
109 | ||
110 | m_hDCCount = 0; | |
111 | } | |
112 | ||
113 | ||
114 | wxDC::~wxDC(void) | |
115 | { | |
116 | if ( m_hDC != 0 ) { | |
117 | SelectOldObjects(m_hDC); | |
118 | if ( m_bOwnsDC ) { | |
119 | if ( m_canvas == NULL ) | |
120 | ::DeleteDC((HDC)m_hDC); | |
121 | else | |
122 | ::ReleaseDC((HWND)m_canvas->GetHWND(), (HDC)m_hDC); | |
123 | } | |
124 | } | |
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 | { | |
b2aef89b | 133 | #if WXDEBUG > 1 |
2bda0e17 KB |
134 | wxDebugMsg("wxDC::SelectOldObjects %X\n", this); |
135 | #endif | |
136 | if (dc) | |
137 | { | |
138 | if (m_oldBitmap) | |
139 | { | |
b2aef89b | 140 | #if WXDEBUG > 1 |
2bda0e17 KB |
141 | wxDebugMsg("wxDC::SelectOldObjects: Selecting old HBITMAP %X\n", m_oldBitmap); |
142 | #endif | |
143 | ::SelectObject((HDC) dc, (HBITMAP) m_oldBitmap); | |
144 | if (m_selectedBitmap.Ok()) | |
145 | { | |
146 | m_selectedBitmap.SetSelectedInto(NULL); | |
147 | } | |
148 | } | |
149 | m_oldBitmap = 0 ; | |
150 | if (m_oldPen) | |
151 | { | |
b2aef89b | 152 | #if WXDEBUG > 1 |
2bda0e17 KB |
153 | wxDebugMsg("wxDC::SelectOldObjects: Selecting old HPEN %X\n", m_oldPen); |
154 | #endif | |
155 | ::SelectObject((HDC) dc, (HPEN) m_oldPen); | |
156 | } | |
157 | m_oldPen = 0 ; | |
158 | if (m_oldBrush) | |
159 | { | |
b2aef89b | 160 | #if WXDEBUG > 1 |
2bda0e17 KB |
161 | wxDebugMsg("wxDC::SelectOldObjects: Selecting old HBRUSH %X\n", m_oldBrush); |
162 | #endif | |
163 | ::SelectObject((HDC) dc, (HBRUSH) m_oldBrush); | |
164 | } | |
165 | m_oldBrush = 0 ; | |
166 | if (m_oldFont) | |
167 | { | |
b2aef89b | 168 | #if WXDEBUG > 1 |
2bda0e17 KB |
169 | wxDebugMsg("wxDC::SelectOldObjects: Selecting old HFONT %X\n", m_oldFont); |
170 | #endif | |
171 | ::SelectObject((HDC) dc, (HFONT) m_oldFont); | |
172 | } | |
173 | m_oldFont = 0 ; | |
174 | if (m_oldPalette) | |
175 | { | |
b2aef89b | 176 | #if WXDEBUG > 1 |
2bda0e17 KB |
177 | wxDebugMsg("wxDC::SelectOldObjects: Selecting old HPALETTE %X\n", m_oldPalette); |
178 | #endif | |
179 | ::SelectPalette((HDC) dc, (HPALETTE) m_oldPalette, TRUE); | |
180 | } | |
b2aef89b | 181 | #if WXDEBUG > 1 |
2bda0e17 KB |
182 | wxDebugMsg("wxDC::SelectOldObjects: Done.\n"); |
183 | #endif | |
184 | m_oldPalette = 0 ; | |
185 | } | |
2bda0e17 KB |
186 | |
187 | m_brush = wxNullBrush ; | |
188 | m_pen = wxNullPen; | |
189 | m_palette = wxNullPalette; | |
190 | m_font = wxNullFont; | |
191 | m_backgroundBrush = wxNullBrush; | |
192 | m_selectedBitmap = wxNullBitmap; | |
193 | } | |
194 | ||
195 | void wxDC::SetClippingRegion(long cx, long cy, long cw, long ch) | |
196 | { | |
197 | m_clipping = TRUE; | |
198 | m_clipX1 = (int)cx; | |
199 | m_clipY1 = (int)cy; | |
200 | m_clipX2 = (int)(cx + cw); | |
201 | m_clipY2 = (int)(cy + ch); | |
202 | ||
2bda0e17 | 203 | DoClipping((WXHDC) m_hDC); |
2bda0e17 KB |
204 | } |
205 | ||
206 | void wxDC::DoClipping(WXHDC dc) | |
207 | { | |
208 | if (m_clipping && dc) | |
209 | { | |
210 | IntersectClipRect((HDC) dc, XLOG2DEV(m_clipX1), YLOG2DEV(m_clipY1), | |
211 | XLOG2DEV(m_clipX2), YLOG2DEV(m_clipY2)); | |
2bda0e17 KB |
212 | } |
213 | } | |
214 | ||
215 | void wxDC::DestroyClippingRegion(void) | |
216 | { | |
2bda0e17 KB |
217 | if (m_clipping && m_hDC) |
218 | { | |
2bda0e17 | 219 | HRGN rgn = CreateRectRgn(0, 0, 32000, 32000); |
b2aef89b | 220 | #if WXDEBUG > 1 |
2bda0e17 KB |
221 | wxDebugMsg("wxDC::DestroyClippingRegion: Selecting HRGN %X\n", rgn); |
222 | #endif | |
223 | SelectClipRgn((HDC) m_hDC, rgn); | |
b2aef89b | 224 | #if WXDEBUG > 1 |
2bda0e17 KB |
225 | wxDebugMsg("wxDC::DestroyClippingRegion: Deleting HRGN %X\n", rgn); |
226 | #endif | |
227 | DeleteObject(rgn); | |
228 | } | |
229 | m_clipping = FALSE; | |
2bda0e17 KB |
230 | } |
231 | ||
232 | bool wxDC::CanDrawBitmap(void) const | |
233 | { | |
234 | return TRUE; | |
235 | } | |
236 | ||
237 | bool wxDC::CanGetTextExtent(void) const | |
238 | { | |
239 | // What sort of display is it? | |
240 | int technology = ::GetDeviceCaps((HDC) m_hDC, TECHNOLOGY); | |
241 | ||
242 | bool ok; | |
243 | ||
244 | if (technology != DT_RASDISPLAY && technology != DT_RASPRINTER) | |
245 | ok = FALSE; | |
246 | else ok = TRUE; | |
247 | ||
248 | return ok; | |
249 | } | |
250 | ||
251 | void wxDC::SetPalette(const wxPalette& palette) | |
252 | { | |
dabeb021 JS |
253 | // Set the old object temporarily, in case the assignment deletes an object |
254 | // that's not yet selected out. | |
255 | if (m_oldPalette) | |
256 | { | |
257 | ::SelectPalette((HDC) m_hDC, (HPALETTE) m_oldPalette, TRUE); | |
258 | m_oldPalette = 0; | |
259 | } | |
2bda0e17 KB |
260 | |
261 | m_palette = m_palette; | |
262 | ||
263 | if (!m_palette.Ok()) | |
264 | { | |
265 | // Setting a NULL colourmap is a way of restoring | |
266 | // the original colourmap | |
267 | if (m_oldPalette) | |
268 | { | |
269 | ::SelectPalette((HDC) m_hDC, (HPALETTE) m_oldPalette, TRUE); | |
b2aef89b | 270 | #if WXDEBUG > 1 |
2bda0e17 KB |
271 | wxDebugMsg("wxDC::SetPalette: set old palette %X\n", m_oldPalette); |
272 | #endif | |
273 | m_oldPalette = 0; | |
274 | } | |
275 | ||
276 | return; | |
277 | } | |
278 | ||
279 | if (m_palette.Ok() && m_palette.GetHPALETTE()) | |
280 | { | |
281 | HPALETTE oldPal = ::SelectPalette((HDC) m_hDC, (HPALETTE) m_palette.GetHPALETTE(), TRUE); | |
282 | if (!m_oldPalette) | |
283 | m_oldPalette = (WXHPALETTE) oldPal; | |
284 | ||
b2aef89b | 285 | #if WXDEBUG > 1 |
2bda0e17 KB |
286 | wxDebugMsg("wxDC::SetPalette %X: selected palette %X\n", this, m_palette.GetHPALETTE()); |
287 | if (oldPal) | |
288 | wxDebugMsg("wxDC::SetPalette: oldPal was palette %X\n", oldPal); | |
289 | if (m_oldPalette) | |
290 | wxDebugMsg("wxDC::SetPalette: m_oldPalette is palette %X\n", m_oldPalette); | |
291 | #endif | |
292 | ::RealizePalette((HDC) m_hDC); | |
293 | } | |
2bda0e17 KB |
294 | } |
295 | ||
296 | void wxDC::Clear(void) | |
297 | { | |
2bda0e17 KB |
298 | RECT rect; |
299 | if (m_canvas) | |
300 | GetClientRect((HWND) m_canvas->GetHWND(), &rect); | |
301 | else if (m_selectedBitmap.Ok()) | |
302 | { | |
303 | rect.left = 0; rect.top = 0; | |
304 | rect.right = m_selectedBitmap.GetWidth(); | |
305 | rect.bottom = m_selectedBitmap.GetHeight(); | |
306 | } | |
307 | (void) ::SetMapMode((HDC) m_hDC, MM_TEXT); | |
308 | ||
309 | DWORD colour = GetBkColor((HDC) m_hDC); | |
310 | HBRUSH brush = CreateSolidBrush(colour); | |
311 | FillRect((HDC) m_hDC, &rect, brush); | |
312 | DeleteObject(brush); | |
313 | ||
314 | ::SetMapMode((HDC) m_hDC, MM_ANISOTROPIC); | |
315 | ::SetViewportExtEx((HDC) m_hDC, VIEWPORT_EXTENT, VIEWPORT_EXTENT, NULL); | |
316 | ::SetWindowExtEx((HDC) m_hDC, m_windowExtX, m_windowExtY, NULL); | |
317 | ::SetViewportOrgEx((HDC) m_hDC, (int)m_deviceOriginX, (int)m_deviceOriginY, NULL); | |
318 | ::SetWindowOrgEx((HDC) m_hDC, (int)m_logicalOriginX, (int)m_logicalOriginY, NULL); | |
2bda0e17 KB |
319 | } |
320 | ||
6a6c0a8b | 321 | void wxDC::FloodFill(long x, long y, const wxColour& col, int style) |
2bda0e17 | 322 | { |
2bda0e17 | 323 | (void)ExtFloodFill((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), |
6a6c0a8b | 324 | col.GetPixel(), |
2bda0e17 KB |
325 | style==wxFLOOD_SURFACE? |
326 | FLOODFILLSURFACE:FLOODFILLBORDER | |
327 | ); | |
328 | ||
2bda0e17 KB |
329 | CalcBoundingBox(x, y); |
330 | } | |
331 | ||
332 | bool wxDC::GetPixel(long x, long y, wxColour *col) const | |
333 | { | |
334 | // added by steve 29.12.94 (copied from DrawPoint) | |
335 | // returns TRUE for pixels in the color of the current pen | |
336 | // and FALSE for all other pixels colors | |
337 | // if col is non-NULL return the color of the pixel | |
2bda0e17 KB |
338 | |
339 | // get the color of the pixel | |
340 | COLORREF pixelcolor = ::GetPixel((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y)); | |
341 | // get the color of the pen | |
342 | COLORREF pencolor = 0x00ffffff; | |
343 | if (m_pen.Ok()) | |
344 | { | |
345 | pencolor = m_pen.GetColour().GetPixel() ; | |
346 | } | |
347 | ||
348 | // return the color of the pixel | |
349 | if(col) | |
350 | col->Set(GetRValue(pixelcolor),GetGValue(pixelcolor),GetBValue(pixelcolor)); | |
351 | ||
352 | // check, if color of the pixels is the same as the color | |
353 | // of the current pen | |
354 | return(pixelcolor==pencolor); | |
355 | } | |
356 | ||
357 | void wxDC::CrossHair(long x, long y) | |
358 | { | |
2bda0e17 KB |
359 | // We suppose that our screen is 2000x2000 max. |
360 | long x1 = x-2000; | |
361 | long y1 = y-2000; | |
362 | long x2 = x+2000; | |
363 | long y2 = y+2000; | |
2bda0e17 | 364 | |
2bda0e17 KB |
365 | (void)MoveToEx((HDC) m_hDC, XLOG2DEV(x1), YLOG2DEV(y), NULL); |
366 | (void)LineTo((HDC) m_hDC, XLOG2DEV(x2), YLOG2DEV(y)); | |
367 | ||
368 | (void)MoveToEx((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y1), NULL); | |
369 | (void)LineTo((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y2)); | |
370 | ||
2bda0e17 KB |
371 | CalcBoundingBox(x1, y1); |
372 | CalcBoundingBox(x2, y2); | |
373 | } | |
374 | ||
375 | void wxDC::DrawLine(long x1, long y1, long x2, long y2) | |
376 | { | |
2bda0e17 KB |
377 | (void)MoveToEx((HDC) m_hDC, XLOG2DEV(x1), YLOG2DEV(y1), NULL); |
378 | (void)LineTo((HDC) m_hDC, XLOG2DEV(x2), YLOG2DEV(y2)); | |
379 | ||
380 | /* MATTHEW: [6] New normalization */ | |
381 | #if WX_STANDARD_GRAPHICS | |
382 | (void)LineTo((HDC) m_hDC, XLOG2DEV(x2) + 1, YLOG2DEV(y2)); | |
383 | #endif | |
384 | ||
2bda0e17 KB |
385 | CalcBoundingBox(x1, y1); |
386 | CalcBoundingBox(x2, y2); | |
387 | } | |
388 | ||
34138703 | 389 | void wxDC::DrawArc(long x1,long y1,long x2,long y2, long xc, long yc) |
2bda0e17 | 390 | { |
2bda0e17 KB |
391 | double dx = xc-x1 ; |
392 | double dy = yc-y1 ; | |
393 | double radius = (double)sqrt(dx*dx+dy*dy) ;; | |
394 | if (x1==x2 && x2==y2) | |
395 | { | |
396 | DrawEllipse(xc,yc,(double)(radius*2.0),(double)(radius*2)) ; | |
397 | return ; | |
398 | } | |
399 | ||
2bda0e17 KB |
400 | long xx1 = XLOG2DEV(x1) ; |
401 | long yy1 = YLOG2DEV(y1) ; | |
402 | long xx2 = XLOG2DEV(x2) ; | |
403 | long yy2 = YLOG2DEV(y2) ; | |
404 | long xxc = XLOG2DEV(xc) ; | |
405 | long yyc = YLOG2DEV(yc) ; | |
406 | long ray = (long) sqrt(double((xxc-xx1)*(xxc-xx1)+(yyc-yy1)*(yyc-yy1))) ; | |
407 | ||
408 | (void)MoveToEx((HDC) m_hDC, (int) xx1, (int) yy1, NULL); | |
409 | long xxx1 = (long) (xxc-ray); | |
410 | long yyy1 = (long) (yyc-ray); | |
411 | long xxx2 = (long) (xxc+ray); | |
412 | long yyy2 = (long) (yyc+ray); | |
413 | if (m_brush.Ok() && m_brush.GetStyle() !=wxTRANSPARENT) | |
414 | { | |
4c444f19 JS |
415 | // Have to add 1 to bottom-right corner of rectangle |
416 | // to make semi-circles look right (crooked line otherwise). | |
417 | // Unfortunately this is not a reliable method, depends | |
418 | // on the size of shape. | |
419 | // TODO: figure out why this happens! | |
420 | Pie((HDC) m_hDC,xxx1,yyy1,xxx2+1,yyy2+1, | |
2bda0e17 KB |
421 | xx1,yy1,xx2,yy2) ; |
422 | } | |
423 | else | |
424 | Arc((HDC) m_hDC,xxx1,yyy1,xxx2,yyy2, | |
425 | xx1,yy1,xx2,yy2) ; | |
426 | ||
2bda0e17 KB |
427 | CalcBoundingBox((xc-radius), (yc-radius)); |
428 | CalcBoundingBox((xc+radius), (yc+radius)); | |
429 | } | |
430 | ||
2bda0e17 KB |
431 | void wxDC::DrawPoint(long x, long y) |
432 | { | |
2bda0e17 KB |
433 | COLORREF color = 0x00ffffff; |
434 | if (m_pen.Ok()) | |
435 | { | |
2bda0e17 KB |
436 | color = m_pen.GetColour().GetPixel() ; |
437 | } | |
438 | ||
2bda0e17 KB |
439 | SetPixel((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), color); |
440 | ||
2bda0e17 KB |
441 | CalcBoundingBox(x, y); |
442 | } | |
443 | ||
444 | void wxDC::DrawPolygon(int n, wxPoint points[], long xoffset, long yoffset,int fillStyle) | |
445 | { | |
6a6c0a8b JS |
446 | // Do things less efficiently if we have offsets |
447 | if (xoffset != 0 || yoffset != 0) | |
2bda0e17 | 448 | { |
6a6c0a8b JS |
449 | POINT *cpoints = new POINT[n]; |
450 | int i; | |
451 | for (i = 0; i < n; i++) | |
452 | { | |
453 | cpoints[i].x = (int)(points[i].x + xoffset); | |
454 | cpoints[i].y = (int)(points[i].y + yoffset); | |
2bda0e17 | 455 | |
6a6c0a8b JS |
456 | CalcBoundingBox(cpoints[i].x, cpoints[i].y); |
457 | } | |
458 | int prev = SetPolyFillMode((HDC) m_hDC,fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING) ; | |
459 | (void)Polygon((HDC) m_hDC, cpoints, n); | |
460 | SetPolyFillMode((HDC) m_hDC,prev) ; | |
461 | delete[] cpoints; | |
2bda0e17 | 462 | } |
6a6c0a8b JS |
463 | else |
464 | { | |
465 | int i; | |
466 | for (i = 0; i < n; i++) | |
467 | CalcBoundingBox(points[i].x, points[i].y); | |
2bda0e17 | 468 | |
6a6c0a8b JS |
469 | int prev = SetPolyFillMode((HDC) m_hDC,fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING) ; |
470 | (void)Polygon((HDC) m_hDC, (POINT*) points, n); | |
471 | SetPolyFillMode((HDC) m_hDC,prev) ; | |
472 | } | |
2bda0e17 KB |
473 | } |
474 | ||
475 | void wxDC::DrawLines(int n, wxPoint points[], long xoffset, long yoffset) | |
476 | { | |
6a6c0a8b JS |
477 | // Do things less efficiently if we have offsets |
478 | if (xoffset != 0 || yoffset != 0) | |
2bda0e17 | 479 | { |
6a6c0a8b JS |
480 | POINT *cpoints = new POINT[n]; |
481 | int i; | |
482 | for (i = 0; i < n; i++) | |
483 | { | |
484 | cpoints[i].x = (int)(points[i].x + xoffset); | |
485 | cpoints[i].y = (int)(points[i].y + yoffset); | |
2bda0e17 | 486 | |
6a6c0a8b JS |
487 | CalcBoundingBox(cpoints[i].x, cpoints[i].y); |
488 | } | |
489 | (void)Polyline((HDC) m_hDC, cpoints, n); | |
490 | delete[] cpoints; | |
2bda0e17 | 491 | } |
6a6c0a8b JS |
492 | else |
493 | { | |
494 | int i; | |
495 | for (i = 0; i < n; i++) | |
496 | CalcBoundingBox(points[i].x, points[i].y); | |
2bda0e17 | 497 | |
6a6c0a8b JS |
498 | (void)Polyline((HDC) m_hDC, (POINT*) points, n); |
499 | } | |
2bda0e17 KB |
500 | } |
501 | ||
502 | void wxDC::DrawRectangle(long x, long y, long width, long height) | |
503 | { | |
2bda0e17 KB |
504 | long x2 = x + width; |
505 | long y2 = y + height; | |
506 | ||
2bda0e17 KB |
507 | /* MATTHEW: [6] new normalization */ |
508 | #if WX_STANDARD_GRAPHICS | |
509 | bool do_brush, do_pen; | |
510 | ||
511 | do_brush = m_brush.Ok() && m_brush.GetStyle() != wxTRANSPARENT; | |
512 | do_pen = m_pen.Ok() && m_pen.GetStyle() != wxTRANSPARENT; | |
513 | ||
514 | if (do_brush) { | |
515 | HPEN orig_pen = NULL; | |
516 | ||
517 | if (do_pen || !m_pen.Ok()) | |
8b9518ee | 518 | orig_pen = (HPEN) ::SelectObject((HDC) m_hDC, (HPEN) ::GetStockObject(NULL_PEN)); |
2bda0e17 KB |
519 | |
520 | (void)Rectangle((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), | |
521 | XLOG2DEV(x2) + 1, YLOG2DEV(y2) + 1); | |
522 | ||
523 | if (do_pen || !m_pen.Ok()) | |
524 | ::SelectObject((HDC) m_hDC , orig_pen); | |
525 | } | |
526 | if (do_pen) { | |
527 | HBRUSH orig_brush = NULL; | |
528 | ||
529 | if (do_brush || !m_brush.Ok()) | |
8b9518ee | 530 | orig_brush = (HBRUSH) ::SelectObject((HDC) m_hDC, (HBRUSH) ::GetStockObject(NULL_BRUSH)); |
2bda0e17 KB |
531 | |
532 | (void)Rectangle((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), | |
533 | XLOG2DEV(x2), YLOG2DEV(y2)); | |
534 | ||
535 | if (do_brush || !m_brush.Ok()) | |
536 | ::SelectObject((HDC) m_hDC, orig_brush); | |
537 | } | |
538 | #else | |
539 | (void)Rectangle((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2)); | |
540 | #endif | |
541 | ||
542 | CalcBoundingBox(x, y); | |
543 | CalcBoundingBox(x2, y2); | |
2bda0e17 KB |
544 | } |
545 | ||
546 | void wxDC::DrawRoundedRectangle(long x, long y, long width, long height, double radius) | |
547 | { | |
2bda0e17 KB |
548 | // Now, a negative radius value is interpreted to mean |
549 | // 'the proportion of the smallest X or Y dimension' | |
550 | ||
551 | if (radius < 0.0) | |
552 | { | |
553 | double smallest = 0.0; | |
554 | if (width < height) | |
555 | smallest = width; | |
556 | else | |
557 | smallest = height; | |
558 | radius = (- radius * smallest); | |
559 | } | |
560 | ||
2bda0e17 KB |
561 | long x2 = (x+width); |
562 | long y2 = (y+height); | |
563 | ||
2bda0e17 KB |
564 | (void)RoundRect((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), |
565 | YLOG2DEV(y2), 2*XLOG2DEV(radius), 2*YLOG2DEV(radius)); | |
566 | ||
567 | CalcBoundingBox(x, y); | |
568 | CalcBoundingBox(x2, y2); | |
2bda0e17 KB |
569 | } |
570 | ||
571 | void wxDC::DrawEllipse(long x, long y, long width, long height) | |
572 | { | |
2bda0e17 KB |
573 | long x2 = (x+width); |
574 | long y2 = (y+height); | |
575 | ||
2bda0e17 KB |
576 | (void)Ellipse((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2)); |
577 | ||
2bda0e17 KB |
578 | CalcBoundingBox(x, y); |
579 | CalcBoundingBox(x2, y2); | |
580 | } | |
581 | ||
6f65e337 JS |
582 | // Chris Breeze 20/5/98: first implementation of DrawEllipticArc on Windows |
583 | void wxDC::DrawEllipticArc(long x,long y,long w,long h,double sa,double ea) | |
584 | { | |
6f65e337 JS |
585 | long x2 = (x+w); |
586 | long y2 = (y+h); | |
587 | ||
6f65e337 JS |
588 | const double deg2rad = 3.14159265359 / 180.0; |
589 | int rx1 = XLOG2DEV(x+w/2); | |
590 | int ry1 = YLOG2DEV(y+h/2); | |
591 | int rx2 = rx1; | |
592 | int ry2 = ry1; | |
593 | rx1 += (int)(100.0 * abs(w) * cos(sa * deg2rad)); | |
594 | ry1 -= (int)(100.0 * abs(h) * m_signY * sin(sa * deg2rad)); | |
595 | rx2 += (int)(100.0 * abs(w) * cos(ea * deg2rad)); | |
596 | ry2 -= (int)(100.0 * abs(h) * m_signY * sin(ea * deg2rad)); | |
597 | ||
598 | // draw pie with NULL_PEN first and then outline otherwise a line is | |
599 | // drawn from the start and end points to the centre | |
8b9518ee | 600 | HPEN orig_pen = (HPEN) ::SelectObject((HDC) m_hDC, (HPEN) ::GetStockObject(NULL_PEN)); |
6f65e337 JS |
601 | if (m_signY > 0) |
602 | { | |
603 | (void)Pie((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2)+1, YLOG2DEV(y2)+1, | |
604 | rx1, ry1, rx2, ry2); | |
605 | } | |
606 | else | |
607 | { | |
608 | (void)Pie((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y)-1, XLOG2DEV(x2)+1, YLOG2DEV(y2), | |
609 | rx1, ry1-1, rx2, ry2-1); | |
610 | } | |
611 | ::SelectObject((HDC) m_hDC, orig_pen); | |
612 | (void)Arc((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2), | |
613 | rx1, ry1, rx2, ry2); | |
614 | ||
6f65e337 JS |
615 | CalcBoundingBox(x, y); |
616 | CalcBoundingBox(x2, y2); | |
617 | } | |
618 | ||
2bda0e17 KB |
619 | void wxDC::DrawIcon(const wxIcon& icon, long x, long y) |
620 | { | |
2bda0e17 KB |
621 | ::DrawIcon((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), (HICON) icon.GetHICON()); |
622 | CalcBoundingBox(x, y); | |
623 | CalcBoundingBox(x+icon.GetWidth(), y+icon.GetHeight()); | |
2bda0e17 KB |
624 | } |
625 | ||
626 | void wxDC::SetFont(const wxFont& the_font) | |
627 | { | |
dabeb021 JS |
628 | // Set the old object temporarily, in case the assignment deletes an object |
629 | // that's not yet selected out. | |
630 | if (m_oldFont) | |
631 | { | |
632 | ::SelectObject((HDC) m_hDC, (HFONT) m_oldFont); | |
633 | m_oldFont = 0; | |
634 | } | |
2bda0e17 KB |
635 | |
636 | m_font = the_font; | |
637 | ||
638 | if (!the_font.Ok()) | |
639 | { | |
640 | if (m_oldFont) | |
641 | ::SelectObject((HDC) m_hDC, (HFONT) m_oldFont); | |
642 | m_oldFont = 0 ; | |
643 | } | |
644 | ||
645 | if (m_font.Ok() && m_font.GetResourceHandle()) | |
646 | { | |
b2aef89b | 647 | #if WXDEBUG > 1 |
2bda0e17 KB |
648 | wxDebugMsg("wxDC::SetFont: Selecting HFONT %X\n", m_font.GetResourceHandle()); |
649 | #endif | |
650 | HFONT f = (HFONT) ::SelectObject((HDC) m_hDC, (HFONT) m_font.GetResourceHandle()); | |
34da0970 JS |
651 | if (f == NULL) |
652 | { | |
653 | wxDebugMsg("::SelectObject failed in wxDC::SetFont."); | |
654 | } | |
2bda0e17 KB |
655 | if (!m_oldFont) |
656 | m_oldFont = (WXHFONT) f; | |
657 | } | |
2bda0e17 KB |
658 | } |
659 | ||
660 | void wxDC::SetPen(const wxPen& pen) | |
661 | { | |
dabeb021 JS |
662 | // Set the old object temporarily, in case the assignment deletes an object |
663 | // that's not yet selected out. | |
664 | if (m_oldPen) | |
665 | { | |
666 | ::SelectObject((HDC) m_hDC, (HPEN) m_oldPen); | |
667 | m_oldPen = 0; | |
668 | } | |
2bda0e17 KB |
669 | |
670 | m_pen = pen; | |
671 | ||
672 | if (!m_pen.Ok()) | |
673 | { | |
674 | if (m_oldPen) | |
675 | ::SelectObject((HDC) m_hDC, (HPEN) m_oldPen); | |
676 | m_oldPen = 0 ; | |
677 | } | |
678 | ||
679 | if (m_pen.Ok()) | |
680 | { | |
2bda0e17 KB |
681 | if (m_pen.GetResourceHandle()) |
682 | { | |
683 | HPEN p = (HPEN) ::SelectObject((HDC) m_hDC, (HPEN)m_pen.GetResourceHandle()) ; | |
684 | if (!m_oldPen) | |
685 | m_oldPen = (WXHPEN) p; | |
686 | } | |
687 | } | |
2bda0e17 KB |
688 | } |
689 | ||
690 | void wxDC::SetBrush(const wxBrush& brush) | |
691 | { | |
dabeb021 JS |
692 | // Set the old object temporarily, in case the assignment deletes an object |
693 | // that's not yet selected out. | |
694 | if (m_oldBrush) | |
695 | { | |
696 | ::SelectObject((HDC) m_hDC, (HBRUSH) m_oldBrush); | |
697 | m_oldBrush = 0; | |
698 | } | |
2bda0e17 KB |
699 | |
700 | m_brush = brush; | |
701 | ||
702 | if (!m_brush.Ok()) | |
703 | { | |
704 | if (m_oldBrush) | |
705 | ::SelectObject((HDC) m_hDC, (HBRUSH) m_oldBrush); | |
706 | m_oldBrush = 0 ; | |
707 | } | |
708 | ||
709 | if (m_brush.Ok()) | |
710 | { | |
2bda0e17 KB |
711 | if (m_brush.GetResourceHandle()) |
712 | { | |
713 | HBRUSH b = 0; | |
8b9518ee | 714 | b = (HBRUSH) ::SelectObject((HDC) m_hDC, (HBRUSH)m_brush.GetResourceHandle()) ; |
2bda0e17 KB |
715 | if (!m_oldBrush) |
716 | m_oldBrush = (WXHBRUSH) b; | |
717 | } | |
718 | } | |
2bda0e17 KB |
719 | } |
720 | ||
721 | void wxDC::DrawText(const wxString& text, long x, long y, bool use16bit) | |
722 | { | |
34da0970 JS |
723 | // Should be unnecessary: SetFont should have done this already. |
724 | #if 0 | |
2bda0e17 KB |
725 | if (m_font.Ok() && m_font.GetResourceHandle()) |
726 | { | |
b2aef89b | 727 | #if WXDEBUG > 1 |
2bda0e17 KB |
728 | wxDebugMsg("wxDC::DrawText: Selecting HFONT %X\n", m_font.GetResourceHandle()); |
729 | #endif | |
8b9518ee | 730 | HFONT f = (HFONT) ::SelectObject((HDC) m_hDC, (HFONT) m_font.GetResourceHandle()); |
2bda0e17 KB |
731 | if (!m_oldFont) |
732 | m_oldFont = (WXHFONT) f; | |
733 | } | |
34da0970 | 734 | #endif |
2bda0e17 KB |
735 | |
736 | if (m_textForegroundColour.Ok()) | |
737 | SetTextColor((HDC) m_hDC, m_textForegroundColour.GetPixel() ) ; | |
738 | ||
739 | DWORD old_background; | |
740 | if (m_textBackgroundColour.Ok()) | |
741 | { | |
742 | old_background = SetBkColor((HDC) m_hDC, m_textBackgroundColour.GetPixel() ) ; | |
743 | } | |
744 | ||
745 | if (m_backgroundMode == wxTRANSPARENT) | |
746 | SetBkMode((HDC) m_hDC, TRANSPARENT); | |
747 | else | |
748 | SetBkMode((HDC) m_hDC, OPAQUE); | |
749 | ||
750 | (void)TextOut((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), (char *) (const char *)text, strlen((const char *)text)); | |
751 | ||
752 | if (m_textBackgroundColour.Ok()) | |
753 | (void)SetBkColor((HDC) m_hDC, old_background); | |
754 | ||
755 | CalcBoundingBox(x, y); | |
756 | ||
757 | long w, h; | |
758 | GetTextExtent(text, &w, &h); | |
759 | CalcBoundingBox((x + w), (y + h)); | |
2bda0e17 KB |
760 | } |
761 | ||
762 | void wxDC::SetBackground(const wxBrush& brush) | |
763 | { | |
2bda0e17 KB |
764 | m_backgroundBrush = brush; |
765 | ||
766 | if (!m_backgroundBrush.Ok()) | |
767 | return; | |
768 | ||
2bda0e17 KB |
769 | if (m_canvas) |
770 | { | |
771 | bool customColours = TRUE; | |
772 | // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to | |
773 | // change background colours from the control-panel specified colours. | |
774 | if (m_canvas->IsKindOf(CLASSINFO(wxWindow)) && ((m_canvas->GetWindowStyleFlag() & wxUSER_COLOURS) != wxUSER_COLOURS)) | |
775 | customColours = FALSE; | |
776 | ||
777 | if (customColours) | |
778 | { | |
2bda0e17 KB |
779 | if (m_backgroundBrush.GetStyle()==wxTRANSPARENT) |
780 | { | |
781 | m_canvas->m_backgroundTransparent = TRUE; | |
782 | } | |
783 | else | |
784 | { | |
785 | m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour()); | |
786 | m_canvas->m_backgroundTransparent = FALSE; | |
787 | } | |
788 | } | |
789 | } | |
2bda0e17 KB |
790 | COLORREF new_color = m_backgroundBrush.GetColour().GetPixel() ; |
791 | { | |
792 | (void)SetBkColor((HDC) m_hDC, new_color); | |
793 | } | |
2bda0e17 KB |
794 | } |
795 | ||
796 | void wxDC::SetBackgroundMode(int mode) | |
797 | { | |
798 | m_backgroundMode = mode; | |
799 | ||
2bda0e17 KB |
800 | if (m_backgroundMode == wxTRANSPARENT) |
801 | ::SetBkMode((HDC) m_hDC, TRANSPARENT); | |
802 | else | |
803 | ::SetBkMode((HDC) m_hDC, OPAQUE); | |
2bda0e17 KB |
804 | } |
805 | ||
806 | void wxDC::SetLogicalFunction(int function) | |
807 | { | |
808 | m_logicalFunction = function; | |
809 | ||
2bda0e17 | 810 | SetRop((WXHDC) m_hDC); |
2bda0e17 KB |
811 | } |
812 | ||
813 | void wxDC::SetRop(WXHDC dc) | |
814 | { | |
815 | if (!dc || m_logicalFunction < 0) | |
816 | return; | |
817 | ||
818 | int c_rop; | |
819 | // These may be wrong | |
820 | switch (m_logicalFunction) | |
821 | { | |
822 | // case wxXOR: c_rop = R2_XORPEN; break; | |
823 | case wxXOR: c_rop = R2_NOTXORPEN; break; | |
824 | case wxINVERT: c_rop = R2_NOT; break; | |
825 | case wxOR_REVERSE: c_rop = R2_MERGEPENNOT; break; | |
826 | case wxAND_REVERSE: c_rop = R2_MASKPENNOT; break; | |
827 | case wxCLEAR: c_rop = R2_WHITE; break; | |
828 | case wxSET: c_rop = R2_BLACK; break; | |
829 | case wxSRC_INVERT: c_rop = R2_NOTCOPYPEN; break; | |
830 | case wxOR_INVERT: c_rop = R2_MERGENOTPEN; break; | |
831 | case wxAND: c_rop = R2_MASKPEN; break; | |
832 | case wxOR: c_rop = R2_MERGEPEN; break; | |
833 | case wxAND_INVERT: c_rop = R2_MASKNOTPEN; break; | |
834 | case wxEQUIV: | |
835 | case wxNAND: | |
836 | case wxCOPY: | |
837 | default: | |
838 | c_rop = R2_COPYPEN; break; | |
839 | } | |
840 | SetROP2((HDC) dc, c_rop); | |
841 | } | |
842 | ||
843 | bool wxDC::StartDoc(const wxString& message) | |
844 | { | |
845 | if (!this->IsKindOf(CLASSINFO(wxPrinterDC))) | |
846 | return TRUE; | |
847 | ||
2bda0e17 KB |
848 | DOCINFO docinfo; |
849 | docinfo.cbSize = sizeof(DOCINFO); | |
850 | docinfo.lpszDocName = (const char *)message; | |
34da0970 JS |
851 | |
852 | if (m_filename.IsEmpty()) | |
853 | docinfo.lpszOutput = NULL; | |
854 | else | |
855 | docinfo.lpszOutput = (const char *)m_filename; | |
856 | ||
2bda0e17 KB |
857 | #if defined(__WIN95__) |
858 | docinfo.lpszDatatype = NULL; | |
859 | docinfo.fwType = 0; | |
860 | #endif | |
861 | ||
34da0970 JS |
862 | if (!m_hDC) |
863 | return FALSE; | |
864 | ||
865 | int ret = | |
2bda0e17 | 866 | #ifndef __WIN32__ |
34da0970 | 867 | ::StartDoc((HDC) m_hDC, &docinfo); |
2bda0e17 KB |
868 | #else |
869 | #ifdef UNICODE | |
34da0970 | 870 | ::StartDocW((HDC) m_hDC, &docinfo); |
2bda0e17 | 871 | #else |
34da0970 | 872 | ::StartDocA((HDC) m_hDC, &docinfo); |
2bda0e17 KB |
873 | #endif |
874 | #endif | |
875 | ||
34da0970 JS |
876 | if (ret <= 0) |
877 | { | |
878 | DWORD lastError = GetLastError(); | |
879 | wxDebugMsg("wxDC::StartDoc failed with error: %d\n", lastError); | |
880 | } | |
881 | return (ret > 0); | |
2bda0e17 KB |
882 | } |
883 | ||
884 | void wxDC::EndDoc(void) | |
885 | { | |
886 | if (!this->IsKindOf(CLASSINFO(wxPrinterDC))) | |
887 | return; | |
888 | if (m_hDC) ::EndDoc((HDC) m_hDC); | |
889 | } | |
890 | ||
891 | void wxDC::StartPage(void) | |
892 | { | |
893 | if (!this->IsKindOf(CLASSINFO(wxPrinterDC))) | |
894 | return; | |
895 | if (m_hDC) | |
896 | ::StartPage((HDC) m_hDC); | |
897 | } | |
898 | ||
899 | void wxDC::EndPage(void) | |
900 | { | |
901 | if (!this->IsKindOf(CLASSINFO(wxPrinterDC))) | |
902 | return; | |
903 | if (m_hDC) | |
904 | ::EndPage((HDC) m_hDC); | |
905 | } | |
906 | ||
907 | long wxDC::GetCharHeight(void) const | |
908 | { | |
909 | TEXTMETRIC lpTextMetric; | |
910 | ||
911 | GetTextMetrics((HDC) m_hDC, &lpTextMetric); | |
912 | ||
913 | return YDEV2LOGREL(lpTextMetric.tmHeight); | |
914 | } | |
915 | ||
916 | long wxDC::GetCharWidth(void) const | |
917 | { | |
918 | TEXTMETRIC lpTextMetric; | |
919 | ||
920 | GetTextMetrics((HDC) m_hDC, &lpTextMetric); | |
921 | ||
922 | return XDEV2LOGREL(lpTextMetric.tmAveCharWidth); | |
923 | } | |
924 | ||
925 | void wxDC::GetTextExtent(const wxString& string, long *x, long *y, | |
926 | long *descent, long *externalLeading, wxFont *theFont, bool use16bit) const | |
927 | { | |
928 | wxFont *fontToUse = (wxFont*) theFont; | |
929 | if (!fontToUse) | |
930 | fontToUse = (wxFont*) &m_font; | |
931 | ||
932 | SIZE sizeRect; | |
933 | TEXTMETRIC tm; | |
934 | ||
935 | GetTextExtentPoint((HDC) m_hDC, (char *)(const char *) string, strlen((char *)(const char *) string), &sizeRect); | |
936 | GetTextMetrics((HDC) m_hDC, &tm); | |
937 | ||
7d7fb17e VZ |
938 | if (x) *x = XDEV2LOGREL(sizeRect.cx); |
939 | if (y) *y = YDEV2LOGREL(sizeRect.cy); | |
2bda0e17 KB |
940 | if (descent) *descent = tm.tmDescent; |
941 | if (externalLeading) *externalLeading = tm.tmExternalLeading; | |
942 | } | |
943 | ||
944 | void wxDC::SetMapMode(int mode) | |
945 | { | |
946 | m_mappingMode = mode; | |
947 | ||
948 | int pixel_width = 0; | |
949 | int pixel_height = 0; | |
950 | int mm_width = 0; | |
951 | int mm_height = 0; | |
952 | ||
2bda0e17 KB |
953 | pixel_width = GetDeviceCaps((HDC) m_hDC, HORZRES); |
954 | pixel_height = GetDeviceCaps((HDC) m_hDC, VERTRES); | |
955 | mm_width = GetDeviceCaps((HDC) m_hDC, HORZSIZE); | |
956 | mm_height = GetDeviceCaps((HDC) m_hDC, VERTSIZE); | |
957 | ||
958 | if ((pixel_width == 0) || (pixel_height == 0) || (mm_width == 0) || (mm_height == 0)) | |
959 | { | |
2bda0e17 KB |
960 | return; |
961 | } | |
962 | ||
963 | double mm2pixelsX = pixel_width/mm_width; | |
964 | double mm2pixelsY = pixel_height/mm_height; | |
965 | ||
966 | switch (mode) | |
967 | { | |
968 | case MM_TWIPS: | |
969 | { | |
970 | m_logicalScaleX = (twips2mm * mm2pixelsX); | |
971 | m_logicalScaleY = (twips2mm * mm2pixelsY); | |
972 | break; | |
973 | } | |
974 | case MM_POINTS: | |
975 | { | |
976 | m_logicalScaleX = (pt2mm * mm2pixelsX); | |
977 | m_logicalScaleY = (pt2mm * mm2pixelsY); | |
978 | break; | |
979 | } | |
980 | case MM_METRIC: | |
981 | { | |
982 | m_logicalScaleX = mm2pixelsX; | |
983 | m_logicalScaleY = mm2pixelsY; | |
984 | break; | |
985 | } | |
986 | case MM_LOMETRIC: | |
987 | { | |
988 | m_logicalScaleX = (mm2pixelsX/10.0); | |
989 | m_logicalScaleY = (mm2pixelsY/10.0); | |
990 | break; | |
991 | } | |
992 | default: | |
993 | case MM_TEXT: | |
994 | { | |
995 | m_logicalScaleX = 1.0; | |
996 | m_logicalScaleY = 1.0; | |
997 | break; | |
998 | } | |
999 | } | |
1000 | ||
1001 | if (::GetMapMode((HDC) m_hDC) != MM_ANISOTROPIC) | |
1002 | ::SetMapMode((HDC) m_hDC, MM_ANISOTROPIC); | |
1003 | ||
1004 | SetViewportExtEx((HDC) m_hDC, VIEWPORT_EXTENT, VIEWPORT_EXTENT, NULL); | |
1005 | m_windowExtX = (int)MS_XDEV2LOGREL(VIEWPORT_EXTENT); | |
1006 | m_windowExtY = (int)MS_YDEV2LOGREL(VIEWPORT_EXTENT); | |
1007 | ::SetWindowExtEx((HDC) m_hDC, m_windowExtX, m_windowExtY, NULL); | |
1008 | ::SetViewportOrgEx((HDC) m_hDC, (int)m_deviceOriginX, (int)m_deviceOriginY, NULL); | |
1009 | ::SetWindowOrgEx((HDC) m_hDC, (int)m_logicalOriginX, (int)m_logicalOriginY, NULL); | |
2bda0e17 KB |
1010 | } |
1011 | ||
1012 | void wxDC::SetUserScale(double x, double y) | |
1013 | { | |
1014 | m_userScaleX = x; | |
1015 | m_userScaleY = y; | |
1016 | ||
1017 | SetMapMode(m_mappingMode); | |
1018 | } | |
1019 | ||
6f65e337 JS |
1020 | void wxDC::SetAxisOrientation(bool xLeftRight, bool yBottomUp) |
1021 | { | |
1022 | m_signX = xLeftRight ? 1 : -1; | |
1023 | m_signY = yBottomUp ? -1 : 1; | |
1024 | ||
1025 | SetMapMode(m_mappingMode); | |
1026 | } | |
1027 | ||
2bda0e17 KB |
1028 | void wxDC::SetSystemScale(double x, double y) |
1029 | { | |
1030 | m_systemScaleX = x; | |
1031 | m_systemScaleY = y; | |
1032 | ||
1033 | SetMapMode(m_mappingMode); | |
1034 | } | |
1035 | ||
1036 | void wxDC::SetLogicalOrigin(long x, long y) | |
1037 | { | |
1038 | m_logicalOriginX = x; | |
1039 | m_logicalOriginY = y; | |
1040 | ||
2bda0e17 | 1041 | ::SetWindowOrgEx((HDC) m_hDC, (int)m_logicalOriginX, (int)m_logicalOriginY, NULL); |
2bda0e17 KB |
1042 | } |
1043 | ||
1044 | void wxDC::SetDeviceOrigin(long x, long y) | |
1045 | { | |
1046 | m_deviceOriginX = x; | |
1047 | m_deviceOriginY = y; | |
1048 | ||
2bda0e17 | 1049 | ::SetViewportOrgEx((HDC) m_hDC, (int)m_deviceOriginX, (int)m_deviceOriginY, NULL); |
2bda0e17 KB |
1050 | } |
1051 | ||
1052 | long wxDC::DeviceToLogicalX(long x) const | |
1053 | { | |
6f65e337 | 1054 | return (long) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_signX*m_systemScaleX) - m_logicalOriginX) ; |
2bda0e17 KB |
1055 | } |
1056 | ||
1057 | long wxDC::DeviceToLogicalXRel(long x) const | |
1058 | { | |
6f65e337 | 1059 | return (long) ((x)/(m_logicalScaleX*m_userScaleX*m_signX*m_systemScaleX)) ; |
2bda0e17 KB |
1060 | } |
1061 | ||
1062 | long wxDC::DeviceToLogicalY(long y) const | |
1063 | { | |
6f65e337 | 1064 | return (long) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_signY*m_systemScaleY) - m_logicalOriginY) ; |
2bda0e17 KB |
1065 | } |
1066 | ||
1067 | long wxDC::DeviceToLogicalYRel(long y) const | |
1068 | { | |
6f65e337 | 1069 | return (long) ((y)/(m_logicalScaleY*m_userScaleY*m_signY*m_systemScaleY)) ; |
2bda0e17 KB |
1070 | } |
1071 | ||
1072 | long wxDC::LogicalToDeviceX(long x) const | |
1073 | { | |
6f65e337 | 1074 | return (long) (floor((x) - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_signX*m_systemScaleX + m_deviceOriginX) ; |
2bda0e17 KB |
1075 | } |
1076 | ||
1077 | long wxDC::LogicalToDeviceXRel(long x) const | |
1078 | { | |
6f65e337 | 1079 | return (long) (floor(x)*m_logicalScaleX*m_userScaleX*m_signX*m_systemScaleX) ; |
2bda0e17 KB |
1080 | } |
1081 | ||
1082 | long wxDC::LogicalToDeviceY(long y) const | |
1083 | { | |
6f65e337 | 1084 | return (long) (floor((y) - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_signY*m_systemScaleY + m_deviceOriginY); |
2bda0e17 KB |
1085 | } |
1086 | ||
1087 | long wxDC::LogicalToDeviceYRel(long y) const | |
1088 | { | |
6f65e337 | 1089 | return (long) (floor(y)*m_logicalScaleY*m_userScaleY*m_signY*m_systemScaleY) ; |
2bda0e17 KB |
1090 | } |
1091 | ||
1092 | // This group of functions may not do any conversion | |
1093 | // if m_scaleGDI is TRUE, since the HDC does the | |
1094 | // conversion automatically. | |
1095 | ||
1096 | long wxDC::ImplDeviceToLogicalX(long x) const | |
1097 | { | |
1098 | // return (m_scaleGDI ? x : DeviceToLogicalX(x)); | |
1099 | return x; | |
1100 | } | |
1101 | ||
1102 | long wxDC::ImplDeviceToLogicalY(long y) const | |
1103 | { | |
1104 | // return (m_scaleGDI ? y : DeviceToLogicalY(y)); | |
1105 | return y; | |
1106 | } | |
1107 | ||
1108 | long wxDC::ImplDeviceToLogicalXRel(long x) const | |
1109 | { | |
1110 | // return (m_scaleGDI ? x : DeviceToLogicalXRel(x)); | |
1111 | return x; | |
1112 | } | |
1113 | ||
1114 | long wxDC::ImplDeviceToLogicalYRel(long y) const | |
1115 | { | |
1116 | // return (m_scaleGDI ? y : DeviceToLogicalYRel(y)); | |
1117 | return y; | |
1118 | } | |
1119 | ||
1120 | long wxDC::ImplLogicalToDeviceX(long x) const | |
1121 | { | |
1122 | // return (m_scaleGDI ? (floor(double(x))) : LogicalToDeviceX(x)); | |
1123 | return x; | |
1124 | } | |
1125 | ||
1126 | long wxDC::ImplLogicalToDeviceY(long y) const | |
1127 | { | |
1128 | // return (m_scaleGDI ? (floor(double(y))) : LogicalToDeviceY(y)); | |
1129 | return y; | |
1130 | } | |
1131 | ||
1132 | long wxDC::ImplLogicalToDeviceXRel(long x) const | |
1133 | { | |
1134 | // return (m_scaleGDI ? (floor(double(x))) : LogicalToDeviceXRel(x)); | |
1135 | return x; | |
1136 | } | |
1137 | ||
1138 | long wxDC::ImplLogicalToDeviceYRel(long y) const | |
1139 | { | |
1140 | // return (m_scaleGDI ? (floor(double(y))) : LogicalToDeviceYRel(y)); | |
1141 | return y; | |
1142 | } | |
1143 | ||
1144 | bool wxDC::Blit(long xdest, long ydest, long width, long height, | |
1145 | wxDC *source, long xsrc, long ysrc, int rop, bool useMask) | |
1146 | { | |
2bda0e17 KB |
1147 | long xdest1 = xdest; |
1148 | long ydest1 = ydest; | |
1149 | long xsrc1 = xsrc; | |
1150 | long ysrc1 = ysrc; | |
1151 | ||
6f65e337 JS |
1152 | // Chris Breeze 18/5/98: use text foreground/background colours |
1153 | // when blitting from 1-bit bitmaps | |
1154 | COLORREF old_textground = ::GetTextColor((HDC)m_hDC); | |
1155 | COLORREF old_background = ::GetBkColor((HDC)m_hDC); | |
1156 | if (m_textForegroundColour.Ok()) | |
1157 | { | |
1158 | ::SetTextColor((HDC) m_hDC, m_textForegroundColour.GetPixel() ) ; | |
1159 | } | |
1160 | if (m_textBackgroundColour.Ok()) | |
1161 | { | |
1162 | ::SetBkColor((HDC) m_hDC, m_textBackgroundColour.GetPixel() ) ; | |
1163 | } | |
1164 | ||
2bda0e17 KB |
1165 | DWORD dwRop = rop == wxCOPY ? SRCCOPY : |
1166 | rop == wxCLEAR ? WHITENESS : | |
1167 | rop == wxSET ? BLACKNESS : | |
1168 | rop == wxINVERT ? DSTINVERT : | |
1169 | rop == wxAND ? MERGECOPY : | |
1170 | rop == wxOR ? MERGEPAINT : | |
1171 | rop == wxSRC_INVERT ? NOTSRCCOPY : | |
1172 | rop == wxXOR ? SRCINVERT : | |
1173 | rop == wxOR_REVERSE ? MERGEPAINT : | |
1174 | rop == wxAND_REVERSE ? SRCERASE : | |
1175 | rop == wxSRC_OR ? SRCPAINT : | |
1176 | rop == wxSRC_AND ? SRCAND : | |
1177 | SRCCOPY; | |
1178 | ||
1179 | bool success; | |
1180 | if (useMask && source->m_selectedBitmap.Ok() && source->m_selectedBitmap.GetMask()) | |
1181 | { | |
1182 | ||
1183 | #if 0 // __WIN32__ | |
1184 | // Not implemented under Win95 (or maybe a specific device?) | |
1185 | if (MaskBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, | |
1186 | (HDC) source->m_hDC, xsrc1, ysrc1, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap(), | |
1187 | 0, 0, 0xAACC0020)) | |
1188 | { | |
1189 | // Success | |
1190 | } | |
1191 | else | |
1192 | #endif | |
1193 | { | |
1194 | // Old code | |
1195 | #if 0 | |
1196 | HDC dc_mask = CreateCompatibleDC((HDC) source->m_hDC); | |
1197 | ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap()); | |
1198 | success = (BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, | |
1199 | dc_mask, xsrc1, ysrc1, 0x00220326 /* NOTSRCAND */) != 0); | |
1200 | success = (BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, | |
1201 | (HDC) source->m_hDC, xsrc1, ysrc1, SRCPAINT) != 0); | |
1202 | ::SelectObject(dc_mask, 0); | |
1203 | ::DeleteDC(dc_mask); | |
1204 | #endif | |
400735a8 JS |
1205 | // New code from Chris Breeze, 15/7/98 |
1206 | // Blit bitmap with mask | |
1207 | ||
1208 | if (IsKindOf(CLASSINFO(wxPrinterDC))) | |
1209 | { | |
1210 | // If we are printing source colours are screen colours | |
1211 | // not printer colours and so we need copy the bitmap | |
1212 | // pixel by pixel. | |
1213 | RECT rect; | |
1214 | HDC dc_mask = ::CreateCompatibleDC((HDC) source->m_hDC); | |
1215 | HDC dc_src = (HDC) source->m_hDC; | |
1216 | ||
1217 | ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap()); | |
1218 | for (int x = 0; x < width; x++) | |
1219 | { | |
1220 | for (int y = 0; y < height; y++) | |
1221 | { | |
1222 | COLORREF cref = ::GetPixel(dc_mask, x, y); | |
1223 | if (cref) | |
1224 | { | |
1225 | HBRUSH brush = ::CreateSolidBrush(::GetPixel(dc_src, x, y)); | |
1226 | rect.left = xdest1 + x; rect.right = rect.left + 1; | |
1227 | rect.top = ydest1 + y; rect.bottom = rect.top + 1; | |
1228 | ::FillRect((HDC) m_hDC, &rect, brush); | |
1229 | ::DeleteObject(brush); | |
1230 | } | |
1231 | } | |
1232 | } | |
1233 | ::SelectObject(dc_mask, 0); | |
1234 | ::DeleteDC(dc_mask); | |
1235 | } | |
1236 | else | |
1237 | { | |
1238 | // create a temp buffer bitmap and DCs to access it and the mask | |
1239 | HDC dc_mask = ::CreateCompatibleDC((HDC) source->m_hDC); | |
1240 | HDC dc_buffer = ::CreateCompatibleDC((HDC) m_hDC); | |
1241 | HBITMAP buffer_bmap = ::CreateCompatibleBitmap((HDC) m_hDC, width, height); | |
1242 | ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap()); | |
1243 | ::SelectObject(dc_buffer, buffer_bmap); | |
1244 | ||
1245 | // copy dest to buffer | |
1246 | ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height, | |
1247 | (HDC) m_hDC, xdest1, ydest1, SRCCOPY); | |
1248 | ||
1249 | // copy src to buffer using selected raster op | |
1250 | ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height, | |
1251 | (HDC) source->m_hDC, xsrc1, ysrc1, dwRop); | |
1252 | ||
1253 | // set masked area in buffer to BLACK (pixel value 0) | |
1254 | COLORREF prevBkCol = ::SetBkColor((HDC) m_hDC, RGB(255, 255, 255)); | |
1255 | COLORREF prevCol = ::SetTextColor((HDC) m_hDC, RGB(0, 0, 0)); | |
1256 | ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height, | |
1257 | dc_mask, xsrc1, ysrc1, SRCAND); | |
1258 | ||
1259 | // set unmasked area in dest to BLACK | |
1260 | ::SetBkColor((HDC) m_hDC, RGB(0, 0, 0)); | |
1261 | ::SetTextColor((HDC) m_hDC, RGB(255, 255, 255)); | |
1262 | ::BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, | |
1263 | dc_mask, xsrc1, ysrc1, SRCAND); | |
1264 | ::SetBkColor((HDC) m_hDC, prevBkCol); // restore colours to original values | |
1265 | ::SetTextColor((HDC) m_hDC, prevCol); | |
1266 | ||
1267 | // OR buffer to dest | |
1268 | success = (::BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, | |
1269 | dc_buffer, 0, 0, SRCPAINT) != 0); | |
1270 | ||
1271 | // tidy up temporary DCs and bitmap | |
1272 | ::SelectObject(dc_mask, 0); | |
1273 | ::DeleteDC(dc_mask); | |
1274 | ::SelectObject(dc_buffer, 0); | |
1275 | ::DeleteDC(dc_buffer); | |
1276 | ::DeleteObject(buffer_bmap); | |
1277 | } | |
1278 | } | |
2bda0e17 KB |
1279 | } |
1280 | else | |
1281 | { | |
400735a8 JS |
1282 | if (IsKindOf(CLASSINFO(wxPrinterDC))) |
1283 | { | |
1284 | // If we are printing source colours are screen colours | |
1285 | // not printer colours and so we need copy the bitmap | |
1286 | // pixel by pixel. | |
1287 | HDC dc_src = (HDC) source->m_hDC; | |
1288 | RECT rect; | |
1289 | for (int x = 0; x < width; x++) | |
1290 | { | |
1291 | for (int y = 0; y < height; y++) | |
1292 | { | |
1293 | HBRUSH brush = ::CreateSolidBrush(::GetPixel(dc_src, x, y)); | |
1294 | rect.left = xdest1 + x; rect.right = rect.left + 1; | |
1295 | rect.top = ydest1 + y; rect.bottom = rect.top + 1; | |
1296 | ::FillRect((HDC) m_hDC, &rect, brush); | |
1297 | ::DeleteObject(brush); | |
1298 | } | |
1299 | } | |
1300 | } | |
1301 | else | |
1302 | { | |
2bda0e17 KB |
1303 | success = (BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, (HDC) source->m_hDC, |
1304 | xsrc1, ysrc1, dwRop) != 0); | |
400735a8 | 1305 | } |
2bda0e17 | 1306 | } |
6f65e337 JS |
1307 | ::SetTextColor((HDC)m_hDC, old_textground); |
1308 | ::SetBkColor((HDC)m_hDC, old_background); | |
2bda0e17 KB |
1309 | |
1310 | return success; | |
1311 | } | |
1312 | ||
1313 | void wxDC::GetSize(int* width, int* height) const | |
1314 | { | |
1315 | long w=::GetDeviceCaps((HDC) m_hDC,HORZRES); | |
1316 | long h=::GetDeviceCaps((HDC) m_hDC,VERTRES); | |
1317 | *width = w; | |
1318 | *height = h; | |
1319 | } | |
1320 | ||
1321 | void wxDC::GetSizeMM(long *width, long *height) const | |
1322 | { | |
1323 | long w=::GetDeviceCaps((HDC) m_hDC,HORZSIZE); | |
1324 | long h=::GetDeviceCaps((HDC) m_hDC,VERTSIZE); | |
1325 | *width = w; | |
1326 | *height = h; | |
1327 | } | |
1328 | ||
10b959e3 JS |
1329 | #if USE_SPLINES |
1330 | #include "xfspline.inc" | |
1331 | #endif // USE_SPLINES | |
2bda0e17 KB |
1332 | |
1333 | void wxDC::DrawPolygon(wxList *list, long xoffset, long yoffset,int fillStyle) | |
1334 | { | |
1335 | int n = list->Number(); | |
1336 | wxPoint *points = new wxPoint[n]; | |
1337 | ||
1338 | int i = 0; | |
1339 | for(wxNode *node = list->First(); node; node = node->Next()) { | |
1340 | wxPoint *point = (wxPoint *)node->Data(); | |
1341 | points[i].x = point->x; | |
1342 | points[i++].y = point->y; | |
1343 | } | |
1344 | DrawPolygon(n, points, xoffset, yoffset,fillStyle); | |
1345 | delete[] points; | |
1346 | } | |
1347 | ||
1348 | void wxDC::DrawLines(wxList *list, long xoffset, long yoffset) | |
1349 | { | |
1350 | int n = list->Number(); | |
1351 | wxPoint *points = new wxPoint[n]; | |
1352 | ||
1353 | int i = 0; | |
1354 | for(wxNode *node = list->First(); node; node = node->Next()) { | |
1355 | wxPoint *point = (wxPoint *)node->Data(); | |
1356 | points[i].x = point->x; | |
1357 | points[i++].y = point->y; | |
1358 | } | |
1359 | DrawLines(n, points, xoffset, yoffset); | |
1360 | delete []points; | |
1361 | } | |
1362 | ||
1363 | void wxDC::SetTextForeground(const wxColour& colour) | |
1364 | { | |
1365 | m_textForegroundColour = colour; | |
1366 | } | |
1367 | ||
1368 | void wxDC::SetTextBackground(const wxColour& colour) | |
1369 | { | |
1370 | m_textBackgroundColour = colour; | |
1371 | } | |
1372 | ||
1373 | #if USE_SPLINES | |
1374 | // Make a 3-point spline | |
1375 | void wxDC::DrawSpline(long x1, long y1, long x2, long y2, long x3, long y3) | |
1376 | { | |
1377 | wxList *point_list = new wxList; | |
1378 | ||
1379 | wxPoint *point1 = new wxPoint; | |
1380 | point1->x = x1; point1->y = y1; | |
1381 | point_list->Append((wxObject*)point1); | |
1382 | ||
1383 | wxPoint *point2 = new wxPoint; | |
1384 | point2->x = x2; point2->y = y2; | |
1385 | point_list->Append((wxObject*)point2); | |
1386 | ||
1387 | wxPoint *point3 = new wxPoint; | |
1388 | point3->x = x3; point3->y = y3; | |
1389 | point_list->Append((wxObject*)point3); | |
1390 | ||
1391 | DrawSpline(point_list); | |
1392 | ||
1393 | for(wxNode *node = point_list->First(); node; node = node->Next()) { | |
1394 | wxPoint *p = (wxPoint *)node->Data(); | |
1395 | delete p; | |
1396 | } | |
1397 | delete point_list; | |
2bda0e17 KB |
1398 | } |
1399 | #endif | |
1400 | ||
1401 | // For use by wxWindows only, unless custom units are required. | |
1402 | void wxDC::SetLogicalScale(double x, double y) | |
1403 | { | |
1404 | m_logicalScaleX = x; | |
1405 | m_logicalScaleY = y; | |
1406 | } | |
1407 | ||
1408 | void wxDC::CalcBoundingBox(long x, long y) | |
1409 | { | |
1410 | if (x < m_minX) m_minX = x; | |
1411 | if (y < m_minY) m_minY = y; | |
1412 | if (x > m_maxX) m_maxX = x; | |
1413 | if (y > m_maxY) m_maxY = y; | |
1414 | } | |
1415 | ||
1416 | void wxDC::GetClippingBox(long *x,long *y,long *w,long *h) const | |
1417 | { | |
1418 | if (m_clipping) | |
1419 | { | |
1420 | *x = m_clipX1 ; | |
1421 | *y = m_clipY1 ; | |
1422 | *w = (m_clipX2 - m_clipX1) ; | |
1423 | *h = (m_clipY2 - m_clipY1) ; | |
1424 | } | |
1425 | else | |
1426 | *x = *y = *w = *h = 0 ; | |
1427 | } | |
1428 | ||
1429 | #if WXWIN_COMPATIBILITY | |
1430 | void wxDC::GetTextExtent(const wxString& string, float *x, float *y, | |
1431 | float *descent, float *externalLeading, | |
1432 | wxFont *theFont, bool use16bit) const | |
1433 | { | |
1434 | long x1, y1, descent1, externalLeading1; | |
1435 | GetTextExtent(string, & x1, & y1, & descent1, & externalLeading1, theFont, use16bit); | |
1436 | *x = x1; *y = y1; | |
1437 | if (descent) | |
1438 | *descent = descent1; | |
1439 | if (externalLeading) | |
1440 | *externalLeading = externalLeading1; | |
1441 | } | |
1442 | #endif | |
8b9518ee | 1443 | |
7b46ecac JS |
1444 | int wxDC::GetDepth(void) const |
1445 | { | |
1446 | return (int) ::GetDeviceCaps((HDC) m_hDC,BITSPIXEL); | |
1447 | } | |
1448 | ||
1449 |