]> git.saurik.com Git - wxWidgets.git/blob - src/msw/dc.cpp
Removed warnings mesgs
[wxWidgets.git] / src / msw / dc.cpp
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 {
71 m_minX = 0; m_minY = 0; m_maxX = 0; m_maxY = 0;
72 m_clipping = FALSE;
73
74 m_filename = "";
75 m_canvas = NULL;
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;
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;
90 m_signX = 1;
91 m_signY = 1;
92 m_systemScaleX = 1.0;
93 m_systemScaleY = 1.0;
94 m_mappingMode = MM_TEXT;
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;
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
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 {
133 #if WXDEBUG > 1
134 wxDebugMsg("wxDC::SelectOldObjects %X\n", this);
135 #endif
136 if (dc)
137 {
138 if (m_oldBitmap)
139 {
140 #if WXDEBUG > 1
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 {
152 #if WXDEBUG > 1
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 {
160 #if WXDEBUG > 1
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 {
168 #if WXDEBUG > 1
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 {
176 #if WXDEBUG > 1
177 wxDebugMsg("wxDC::SelectOldObjects: Selecting old HPALETTE %X\n", m_oldPalette);
178 #endif
179 ::SelectPalette((HDC) dc, (HPALETTE) m_oldPalette, TRUE);
180 }
181 #if WXDEBUG > 1
182 wxDebugMsg("wxDC::SelectOldObjects: Done.\n");
183 #endif
184 m_oldPalette = 0 ;
185 }
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
203 DoClipping((WXHDC) m_hDC);
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));
212 }
213 }
214
215 void wxDC::DestroyClippingRegion(void)
216 {
217 if (m_clipping && m_hDC)
218 {
219 HRGN rgn = CreateRectRgn(0, 0, 32000, 32000);
220 #if WXDEBUG > 1
221 wxDebugMsg("wxDC::DestroyClippingRegion: Selecting HRGN %X\n", rgn);
222 #endif
223 SelectClipRgn((HDC) m_hDC, rgn);
224 #if WXDEBUG > 1
225 wxDebugMsg("wxDC::DestroyClippingRegion: Deleting HRGN %X\n", rgn);
226 #endif
227 DeleteObject(rgn);
228 }
229 m_clipping = FALSE;
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 {
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 }
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);
270 #if WXDEBUG > 1
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
285 #if WXDEBUG > 1
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 }
294 }
295
296 void wxDC::Clear(void)
297 {
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);
319 }
320
321 void wxDC::FloodFill(long x, long y, const wxColour& col, int style)
322 {
323 (void)ExtFloodFill((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y),
324 col.GetPixel(),
325 style==wxFLOOD_SURFACE?
326 FLOODFILLSURFACE:FLOODFILLBORDER
327 );
328
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
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 {
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;
364
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
371 CalcBoundingBox(x1, y1);
372 CalcBoundingBox(x2, y2);
373 }
374
375 void wxDC::DrawLine(long x1, long y1, long x2, long y2)
376 {
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
385 CalcBoundingBox(x1, y1);
386 CalcBoundingBox(x2, y2);
387 }
388
389 void wxDC::DrawArc(long x1,long y1,long x2,long y2,double xc,double yc)
390 {
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
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 {
415 Pie((HDC) m_hDC,xxx1,yyy1,xxx2,yyy2,
416 xx1,yy1,xx2,yy2) ;
417 }
418 else
419 Arc((HDC) m_hDC,xxx1,yyy1,xxx2,yyy2,
420 xx1,yy1,xx2,yy2) ;
421
422 CalcBoundingBox((xc-radius), (yc-radius));
423 CalcBoundingBox((xc+radius), (yc+radius));
424 }
425
426 void wxDC::DrawPoint(long x, long y)
427 {
428 COLORREF color = 0x00ffffff;
429 if (m_pen.Ok())
430 {
431 color = m_pen.GetColour().GetPixel() ;
432 }
433
434 SetPixel((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), color);
435
436 CalcBoundingBox(x, y);
437 }
438
439 void wxDC::DrawPolygon(int n, wxPoint points[], long xoffset, long yoffset,int fillStyle)
440 {
441 // Do things less efficiently if we have offsets
442 if (xoffset != 0 || yoffset != 0)
443 {
444 POINT *cpoints = new POINT[n];
445 int i;
446 for (i = 0; i < n; i++)
447 {
448 cpoints[i].x = (int)(points[i].x + xoffset);
449 cpoints[i].y = (int)(points[i].y + yoffset);
450
451 CalcBoundingBox(cpoints[i].x, cpoints[i].y);
452 }
453 int prev = SetPolyFillMode((HDC) m_hDC,fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING) ;
454 (void)Polygon((HDC) m_hDC, cpoints, n);
455 SetPolyFillMode((HDC) m_hDC,prev) ;
456 delete[] cpoints;
457 }
458 else
459 {
460 int i;
461 for (i = 0; i < n; i++)
462 CalcBoundingBox(points[i].x, points[i].y);
463
464 int prev = SetPolyFillMode((HDC) m_hDC,fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING) ;
465 (void)Polygon((HDC) m_hDC, (POINT*) points, n);
466 SetPolyFillMode((HDC) m_hDC,prev) ;
467 }
468 }
469
470 void wxDC::DrawLines(int n, wxPoint points[], long xoffset, long yoffset)
471 {
472 // Do things less efficiently if we have offsets
473 if (xoffset != 0 || yoffset != 0)
474 {
475 POINT *cpoints = new POINT[n];
476 int i;
477 for (i = 0; i < n; i++)
478 {
479 cpoints[i].x = (int)(points[i].x + xoffset);
480 cpoints[i].y = (int)(points[i].y + yoffset);
481
482 CalcBoundingBox(cpoints[i].x, cpoints[i].y);
483 }
484 (void)Polyline((HDC) m_hDC, cpoints, n);
485 delete[] cpoints;
486 }
487 else
488 {
489 int i;
490 for (i = 0; i < n; i++)
491 CalcBoundingBox(points[i].x, points[i].y);
492
493 (void)Polyline((HDC) m_hDC, (POINT*) points, n);
494 }
495 }
496
497 void wxDC::DrawRectangle(long x, long y, long width, long height)
498 {
499 long x2 = x + width;
500 long y2 = y + height;
501
502 /* MATTHEW: [6] new normalization */
503 #if WX_STANDARD_GRAPHICS
504 bool do_brush, do_pen;
505
506 do_brush = m_brush.Ok() && m_brush.GetStyle() != wxTRANSPARENT;
507 do_pen = m_pen.Ok() && m_pen.GetStyle() != wxTRANSPARENT;
508
509 if (do_brush) {
510 HPEN orig_pen = NULL;
511
512 if (do_pen || !m_pen.Ok())
513 orig_pen = (HPEN) ::SelectObject((HDC) m_hDC, (HPEN) ::GetStockObject(NULL_PEN));
514
515 (void)Rectangle((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y),
516 XLOG2DEV(x2) + 1, YLOG2DEV(y2) + 1);
517
518 if (do_pen || !m_pen.Ok())
519 ::SelectObject((HDC) m_hDC , orig_pen);
520 }
521 if (do_pen) {
522 HBRUSH orig_brush = NULL;
523
524 if (do_brush || !m_brush.Ok())
525 orig_brush = (HBRUSH) ::SelectObject((HDC) m_hDC, (HBRUSH) ::GetStockObject(NULL_BRUSH));
526
527 (void)Rectangle((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y),
528 XLOG2DEV(x2), YLOG2DEV(y2));
529
530 if (do_brush || !m_brush.Ok())
531 ::SelectObject((HDC) m_hDC, orig_brush);
532 }
533 #else
534 (void)Rectangle((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2));
535 #endif
536
537 CalcBoundingBox(x, y);
538 CalcBoundingBox(x2, y2);
539 }
540
541 void wxDC::DrawRoundedRectangle(long x, long y, long width, long height, double radius)
542 {
543 // Now, a negative radius value is interpreted to mean
544 // 'the proportion of the smallest X or Y dimension'
545
546 if (radius < 0.0)
547 {
548 double smallest = 0.0;
549 if (width < height)
550 smallest = width;
551 else
552 smallest = height;
553 radius = (- radius * smallest);
554 }
555
556 long x2 = (x+width);
557 long y2 = (y+height);
558
559 (void)RoundRect((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2),
560 YLOG2DEV(y2), 2*XLOG2DEV(radius), 2*YLOG2DEV(radius));
561
562 CalcBoundingBox(x, y);
563 CalcBoundingBox(x2, y2);
564 }
565
566 void wxDC::DrawEllipse(long x, long y, long width, long height)
567 {
568 long x2 = (x+width);
569 long y2 = (y+height);
570
571 (void)Ellipse((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2));
572
573 CalcBoundingBox(x, y);
574 CalcBoundingBox(x2, y2);
575 }
576
577 // Chris Breeze 20/5/98: first implementation of DrawEllipticArc on Windows
578 void wxDC::DrawEllipticArc(long x,long y,long w,long h,double sa,double ea)
579 {
580 long x2 = (x+w);
581 long y2 = (y+h);
582
583 const double deg2rad = 3.14159265359 / 180.0;
584 int rx1 = XLOG2DEV(x+w/2);
585 int ry1 = YLOG2DEV(y+h/2);
586 int rx2 = rx1;
587 int ry2 = ry1;
588 rx1 += (int)(100.0 * abs(w) * cos(sa * deg2rad));
589 ry1 -= (int)(100.0 * abs(h) * m_signY * sin(sa * deg2rad));
590 rx2 += (int)(100.0 * abs(w) * cos(ea * deg2rad));
591 ry2 -= (int)(100.0 * abs(h) * m_signY * sin(ea * deg2rad));
592
593 // draw pie with NULL_PEN first and then outline otherwise a line is
594 // drawn from the start and end points to the centre
595 HPEN orig_pen = (HPEN) ::SelectObject((HDC) m_hDC, (HPEN) ::GetStockObject(NULL_PEN));
596 if (m_signY > 0)
597 {
598 (void)Pie((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2)+1, YLOG2DEV(y2)+1,
599 rx1, ry1, rx2, ry2);
600 }
601 else
602 {
603 (void)Pie((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y)-1, XLOG2DEV(x2)+1, YLOG2DEV(y2),
604 rx1, ry1-1, rx2, ry2-1);
605 }
606 ::SelectObject((HDC) m_hDC, orig_pen);
607 (void)Arc((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2),
608 rx1, ry1, rx2, ry2);
609
610 CalcBoundingBox(x, y);
611 CalcBoundingBox(x2, y2);
612 }
613
614 void wxDC::DrawIcon(const wxIcon& icon, long x, long y)
615 {
616 ::DrawIcon((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), (HICON) icon.GetHICON());
617 CalcBoundingBox(x, y);
618 CalcBoundingBox(x+icon.GetWidth(), y+icon.GetHeight());
619 }
620
621 void wxDC::SetFont(const wxFont& the_font)
622 {
623 // Set the old object temporarily, in case the assignment deletes an object
624 // that's not yet selected out.
625 if (m_oldFont)
626 {
627 ::SelectObject((HDC) m_hDC, (HFONT) m_oldFont);
628 m_oldFont = 0;
629 }
630
631 m_font = the_font;
632
633 if (!the_font.Ok())
634 {
635 if (m_oldFont)
636 ::SelectObject((HDC) m_hDC, (HFONT) m_oldFont);
637 m_oldFont = 0 ;
638 }
639
640 if (m_font.Ok() && m_font.GetResourceHandle())
641 {
642 #if WXDEBUG > 1
643 wxDebugMsg("wxDC::SetFont: Selecting HFONT %X\n", m_font.GetResourceHandle());
644 #endif
645 HFONT f = (HFONT) ::SelectObject((HDC) m_hDC, (HFONT) m_font.GetResourceHandle());
646 if (!m_oldFont)
647 m_oldFont = (WXHFONT) f;
648 }
649 }
650
651 void wxDC::SetPen(const wxPen& pen)
652 {
653 // Set the old object temporarily, in case the assignment deletes an object
654 // that's not yet selected out.
655 if (m_oldPen)
656 {
657 ::SelectObject((HDC) m_hDC, (HPEN) m_oldPen);
658 m_oldPen = 0;
659 }
660
661 m_pen = pen;
662
663 if (!m_pen.Ok())
664 {
665 if (m_oldPen)
666 ::SelectObject((HDC) m_hDC, (HPEN) m_oldPen);
667 m_oldPen = 0 ;
668 }
669
670 if (m_pen.Ok())
671 {
672 if (m_pen.GetResourceHandle())
673 {
674 HPEN p = (HPEN) ::SelectObject((HDC) m_hDC, (HPEN)m_pen.GetResourceHandle()) ;
675 if (!m_oldPen)
676 m_oldPen = (WXHPEN) p;
677 }
678 }
679 }
680
681 void wxDC::SetBrush(const wxBrush& brush)
682 {
683 // Set the old object temporarily, in case the assignment deletes an object
684 // that's not yet selected out.
685 if (m_oldBrush)
686 {
687 ::SelectObject((HDC) m_hDC, (HBRUSH) m_oldBrush);
688 m_oldBrush = 0;
689 }
690
691 m_brush = brush;
692
693 if (!m_brush.Ok())
694 {
695 if (m_oldBrush)
696 ::SelectObject((HDC) m_hDC, (HBRUSH) m_oldBrush);
697 m_oldBrush = 0 ;
698 }
699
700 if (m_brush.Ok())
701 {
702 if (m_brush.GetResourceHandle())
703 {
704 HBRUSH b = 0;
705 b = (HBRUSH) ::SelectObject((HDC) m_hDC, (HBRUSH)m_brush.GetResourceHandle()) ;
706 if (!m_oldBrush)
707 m_oldBrush = (WXHBRUSH) b;
708 }
709 }
710 }
711
712 void wxDC::DrawText(const wxString& text, long x, long y, bool use16bit)
713 {
714 if (m_font.Ok() && m_font.GetResourceHandle())
715 {
716 #if WXDEBUG > 1
717 wxDebugMsg("wxDC::DrawText: Selecting HFONT %X\n", m_font.GetResourceHandle());
718 #endif
719 HFONT f = (HFONT) ::SelectObject((HDC) m_hDC, (HFONT) m_font.GetResourceHandle());
720 if (!m_oldFont)
721 m_oldFont = (WXHFONT) f;
722 }
723
724 if (m_textForegroundColour.Ok())
725 SetTextColor((HDC) m_hDC, m_textForegroundColour.GetPixel() ) ;
726
727 DWORD old_background;
728 if (m_textBackgroundColour.Ok())
729 {
730 old_background = SetBkColor((HDC) m_hDC, m_textBackgroundColour.GetPixel() ) ;
731 }
732
733 if (m_backgroundMode == wxTRANSPARENT)
734 SetBkMode((HDC) m_hDC, TRANSPARENT);
735 else
736 SetBkMode((HDC) m_hDC, OPAQUE);
737
738 (void)TextOut((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), (char *) (const char *)text, strlen((const char *)text));
739
740 if (m_textBackgroundColour.Ok())
741 (void)SetBkColor((HDC) m_hDC, old_background);
742
743 CalcBoundingBox(x, y);
744
745 long w, h;
746 GetTextExtent(text, &w, &h);
747 CalcBoundingBox((x + w), (y + h));
748 }
749
750 void wxDC::SetBackground(const wxBrush& brush)
751 {
752 m_backgroundBrush = brush;
753
754 if (!m_backgroundBrush.Ok())
755 return;
756
757 if (m_canvas)
758 {
759 bool customColours = TRUE;
760 // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
761 // change background colours from the control-panel specified colours.
762 if (m_canvas->IsKindOf(CLASSINFO(wxWindow)) && ((m_canvas->GetWindowStyleFlag() & wxUSER_COLOURS) != wxUSER_COLOURS))
763 customColours = FALSE;
764
765 if (customColours)
766 {
767 if (m_backgroundBrush.GetStyle()==wxTRANSPARENT)
768 {
769 m_canvas->m_backgroundTransparent = TRUE;
770 }
771 else
772 {
773 m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour());
774 m_canvas->m_backgroundTransparent = FALSE;
775 }
776 }
777 }
778 COLORREF new_color = m_backgroundBrush.GetColour().GetPixel() ;
779 {
780 (void)SetBkColor((HDC) m_hDC, new_color);
781 }
782 }
783
784 void wxDC::SetBackgroundMode(int mode)
785 {
786 m_backgroundMode = mode;
787
788 if (m_backgroundMode == wxTRANSPARENT)
789 ::SetBkMode((HDC) m_hDC, TRANSPARENT);
790 else
791 ::SetBkMode((HDC) m_hDC, OPAQUE);
792 }
793
794 void wxDC::SetLogicalFunction(int function)
795 {
796 m_logicalFunction = function;
797
798 SetRop((WXHDC) m_hDC);
799 }
800
801 void wxDC::SetRop(WXHDC dc)
802 {
803 if (!dc || m_logicalFunction < 0)
804 return;
805
806 int c_rop;
807 // These may be wrong
808 switch (m_logicalFunction)
809 {
810 // case wxXOR: c_rop = R2_XORPEN; break;
811 case wxXOR: c_rop = R2_NOTXORPEN; break;
812 case wxINVERT: c_rop = R2_NOT; break;
813 case wxOR_REVERSE: c_rop = R2_MERGEPENNOT; break;
814 case wxAND_REVERSE: c_rop = R2_MASKPENNOT; break;
815 case wxCLEAR: c_rop = R2_WHITE; break;
816 case wxSET: c_rop = R2_BLACK; break;
817 case wxSRC_INVERT: c_rop = R2_NOTCOPYPEN; break;
818 case wxOR_INVERT: c_rop = R2_MERGENOTPEN; break;
819 case wxAND: c_rop = R2_MASKPEN; break;
820 case wxOR: c_rop = R2_MERGEPEN; break;
821 case wxAND_INVERT: c_rop = R2_MASKNOTPEN; break;
822 case wxEQUIV:
823 case wxNAND:
824 case wxCOPY:
825 default:
826 c_rop = R2_COPYPEN; break;
827 }
828 SetROP2((HDC) dc, c_rop);
829 }
830
831 bool wxDC::StartDoc(const wxString& message)
832 {
833 if (!this->IsKindOf(CLASSINFO(wxPrinterDC)))
834 return TRUE;
835
836 bool flag = FALSE;
837
838 DOCINFO docinfo;
839 docinfo.cbSize = sizeof(DOCINFO);
840 docinfo.lpszDocName = (const char *)message;
841 docinfo.lpszOutput = (const char *)m_filename;
842 #if defined(__WIN95__)
843 docinfo.lpszDatatype = NULL;
844 docinfo.fwType = 0;
845 #endif
846
847 if (m_hDC) flag = (SP_ERROR !=
848 #ifndef __WIN32__
849 ::StartDoc((HDC) m_hDC, &docinfo));
850 #else
851 #ifdef UNICODE
852 ::StartDocW((HDC) m_hDC, &docinfo));
853 #else
854 ::StartDocA((HDC) m_hDC, &docinfo));
855 #endif
856 #endif
857
858 else flag = FALSE;
859
860 return flag;
861 }
862
863 void wxDC::EndDoc(void)
864 {
865 if (!this->IsKindOf(CLASSINFO(wxPrinterDC)))
866 return;
867 if (m_hDC) ::EndDoc((HDC) m_hDC);
868 }
869
870 void wxDC::StartPage(void)
871 {
872 if (!this->IsKindOf(CLASSINFO(wxPrinterDC)))
873 return;
874 if (m_hDC)
875 ::StartPage((HDC) m_hDC);
876 }
877
878 void wxDC::EndPage(void)
879 {
880 if (!this->IsKindOf(CLASSINFO(wxPrinterDC)))
881 return;
882 if (m_hDC)
883 ::EndPage((HDC) m_hDC);
884 }
885
886 long wxDC::GetCharHeight(void) const
887 {
888 TEXTMETRIC lpTextMetric;
889
890 GetTextMetrics((HDC) m_hDC, &lpTextMetric);
891
892 return YDEV2LOGREL(lpTextMetric.tmHeight);
893 }
894
895 long wxDC::GetCharWidth(void) const
896 {
897 TEXTMETRIC lpTextMetric;
898
899 GetTextMetrics((HDC) m_hDC, &lpTextMetric);
900
901 return XDEV2LOGREL(lpTextMetric.tmAveCharWidth);
902 }
903
904 void wxDC::GetTextExtent(const wxString& string, long *x, long *y,
905 long *descent, long *externalLeading, wxFont *theFont, bool use16bit) const
906 {
907 wxFont *fontToUse = (wxFont*) theFont;
908 if (!fontToUse)
909 fontToUse = (wxFont*) &m_font;
910
911 SIZE sizeRect;
912 TEXTMETRIC tm;
913
914 GetTextExtentPoint((HDC) m_hDC, (char *)(const char *) string, strlen((char *)(const char *) string), &sizeRect);
915 GetTextMetrics((HDC) m_hDC, &tm);
916
917 if (x) *x = XDEV2LOGREL(sizeRect.cx);
918 if (y) *y = YDEV2LOGREL(sizeRect.cy);
919 if (descent) *descent = tm.tmDescent;
920 if (externalLeading) *externalLeading = tm.tmExternalLeading;
921 }
922
923 void wxDC::SetMapMode(int mode)
924 {
925 m_mappingMode = mode;
926
927 int pixel_width = 0;
928 int pixel_height = 0;
929 int mm_width = 0;
930 int mm_height = 0;
931
932 pixel_width = GetDeviceCaps((HDC) m_hDC, HORZRES);
933 pixel_height = GetDeviceCaps((HDC) m_hDC, VERTRES);
934 mm_width = GetDeviceCaps((HDC) m_hDC, HORZSIZE);
935 mm_height = GetDeviceCaps((HDC) m_hDC, VERTSIZE);
936
937 if ((pixel_width == 0) || (pixel_height == 0) || (mm_width == 0) || (mm_height == 0))
938 {
939 return;
940 }
941
942 double mm2pixelsX = pixel_width/mm_width;
943 double mm2pixelsY = pixel_height/mm_height;
944
945 switch (mode)
946 {
947 case MM_TWIPS:
948 {
949 m_logicalScaleX = (twips2mm * mm2pixelsX);
950 m_logicalScaleY = (twips2mm * mm2pixelsY);
951 break;
952 }
953 case MM_POINTS:
954 {
955 m_logicalScaleX = (pt2mm * mm2pixelsX);
956 m_logicalScaleY = (pt2mm * mm2pixelsY);
957 break;
958 }
959 case MM_METRIC:
960 {
961 m_logicalScaleX = mm2pixelsX;
962 m_logicalScaleY = mm2pixelsY;
963 break;
964 }
965 case MM_LOMETRIC:
966 {
967 m_logicalScaleX = (mm2pixelsX/10.0);
968 m_logicalScaleY = (mm2pixelsY/10.0);
969 break;
970 }
971 default:
972 case MM_TEXT:
973 {
974 m_logicalScaleX = 1.0;
975 m_logicalScaleY = 1.0;
976 break;
977 }
978 }
979
980 if (::GetMapMode((HDC) m_hDC) != MM_ANISOTROPIC)
981 ::SetMapMode((HDC) m_hDC, MM_ANISOTROPIC);
982
983 SetViewportExtEx((HDC) m_hDC, VIEWPORT_EXTENT, VIEWPORT_EXTENT, NULL);
984 m_windowExtX = (int)MS_XDEV2LOGREL(VIEWPORT_EXTENT);
985 m_windowExtY = (int)MS_YDEV2LOGREL(VIEWPORT_EXTENT);
986 ::SetWindowExtEx((HDC) m_hDC, m_windowExtX, m_windowExtY, NULL);
987 ::SetViewportOrgEx((HDC) m_hDC, (int)m_deviceOriginX, (int)m_deviceOriginY, NULL);
988 ::SetWindowOrgEx((HDC) m_hDC, (int)m_logicalOriginX, (int)m_logicalOriginY, NULL);
989 }
990
991 void wxDC::SetUserScale(double x, double y)
992 {
993 m_userScaleX = x;
994 m_userScaleY = y;
995
996 SetMapMode(m_mappingMode);
997 }
998
999 void wxDC::SetAxisOrientation(bool xLeftRight, bool yBottomUp)
1000 {
1001 m_signX = xLeftRight ? 1 : -1;
1002 m_signY = yBottomUp ? -1 : 1;
1003
1004 SetMapMode(m_mappingMode);
1005 }
1006
1007 void wxDC::SetSystemScale(double x, double y)
1008 {
1009 m_systemScaleX = x;
1010 m_systemScaleY = y;
1011
1012 SetMapMode(m_mappingMode);
1013 }
1014
1015 void wxDC::SetLogicalOrigin(long x, long y)
1016 {
1017 m_logicalOriginX = x;
1018 m_logicalOriginY = y;
1019
1020 ::SetWindowOrgEx((HDC) m_hDC, (int)m_logicalOriginX, (int)m_logicalOriginY, NULL);
1021 }
1022
1023 void wxDC::SetDeviceOrigin(long x, long y)
1024 {
1025 m_deviceOriginX = x;
1026 m_deviceOriginY = y;
1027
1028 ::SetViewportOrgEx((HDC) m_hDC, (int)m_deviceOriginX, (int)m_deviceOriginY, NULL);
1029 }
1030
1031 long wxDC::DeviceToLogicalX(long x) const
1032 {
1033 return (long) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_signX*m_systemScaleX) - m_logicalOriginX) ;
1034 }
1035
1036 long wxDC::DeviceToLogicalXRel(long x) const
1037 {
1038 return (long) ((x)/(m_logicalScaleX*m_userScaleX*m_signX*m_systemScaleX)) ;
1039 }
1040
1041 long wxDC::DeviceToLogicalY(long y) const
1042 {
1043 return (long) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_signY*m_systemScaleY) - m_logicalOriginY) ;
1044 }
1045
1046 long wxDC::DeviceToLogicalYRel(long y) const
1047 {
1048 return (long) ((y)/(m_logicalScaleY*m_userScaleY*m_signY*m_systemScaleY)) ;
1049 }
1050
1051 long wxDC::LogicalToDeviceX(long x) const
1052 {
1053 return (long) (floor((x) - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_signX*m_systemScaleX + m_deviceOriginX) ;
1054 }
1055
1056 long wxDC::LogicalToDeviceXRel(long x) const
1057 {
1058 return (long) (floor(x)*m_logicalScaleX*m_userScaleX*m_signX*m_systemScaleX) ;
1059 }
1060
1061 long wxDC::LogicalToDeviceY(long y) const
1062 {
1063 return (long) (floor((y) - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_signY*m_systemScaleY + m_deviceOriginY);
1064 }
1065
1066 long wxDC::LogicalToDeviceYRel(long y) const
1067 {
1068 return (long) (floor(y)*m_logicalScaleY*m_userScaleY*m_signY*m_systemScaleY) ;
1069 }
1070
1071 // This group of functions may not do any conversion
1072 // if m_scaleGDI is TRUE, since the HDC does the
1073 // conversion automatically.
1074
1075 long wxDC::ImplDeviceToLogicalX(long x) const
1076 {
1077 // return (m_scaleGDI ? x : DeviceToLogicalX(x));
1078 return x;
1079 }
1080
1081 long wxDC::ImplDeviceToLogicalY(long y) const
1082 {
1083 // return (m_scaleGDI ? y : DeviceToLogicalY(y));
1084 return y;
1085 }
1086
1087 long wxDC::ImplDeviceToLogicalXRel(long x) const
1088 {
1089 // return (m_scaleGDI ? x : DeviceToLogicalXRel(x));
1090 return x;
1091 }
1092
1093 long wxDC::ImplDeviceToLogicalYRel(long y) const
1094 {
1095 // return (m_scaleGDI ? y : DeviceToLogicalYRel(y));
1096 return y;
1097 }
1098
1099 long wxDC::ImplLogicalToDeviceX(long x) const
1100 {
1101 // return (m_scaleGDI ? (floor(double(x))) : LogicalToDeviceX(x));
1102 return x;
1103 }
1104
1105 long wxDC::ImplLogicalToDeviceY(long y) const
1106 {
1107 // return (m_scaleGDI ? (floor(double(y))) : LogicalToDeviceY(y));
1108 return y;
1109 }
1110
1111 long wxDC::ImplLogicalToDeviceXRel(long x) const
1112 {
1113 // return (m_scaleGDI ? (floor(double(x))) : LogicalToDeviceXRel(x));
1114 return x;
1115 }
1116
1117 long wxDC::ImplLogicalToDeviceYRel(long y) const
1118 {
1119 // return (m_scaleGDI ? (floor(double(y))) : LogicalToDeviceYRel(y));
1120 return y;
1121 }
1122
1123 bool wxDC::Blit(long xdest, long ydest, long width, long height,
1124 wxDC *source, long xsrc, long ysrc, int rop, bool useMask)
1125 {
1126 long xdest1 = xdest;
1127 long ydest1 = ydest;
1128 long xsrc1 = xsrc;
1129 long ysrc1 = ysrc;
1130
1131 // Chris Breeze 18/5/98: use text foreground/background colours
1132 // when blitting from 1-bit bitmaps
1133 COLORREF old_textground = ::GetTextColor((HDC)m_hDC);
1134 COLORREF old_background = ::GetBkColor((HDC)m_hDC);
1135 if (m_textForegroundColour.Ok())
1136 {
1137 ::SetTextColor((HDC) m_hDC, m_textForegroundColour.GetPixel() ) ;
1138 }
1139 if (m_textBackgroundColour.Ok())
1140 {
1141 ::SetBkColor((HDC) m_hDC, m_textBackgroundColour.GetPixel() ) ;
1142 }
1143
1144 DWORD dwRop = rop == wxCOPY ? SRCCOPY :
1145 rop == wxCLEAR ? WHITENESS :
1146 rop == wxSET ? BLACKNESS :
1147 rop == wxINVERT ? DSTINVERT :
1148 rop == wxAND ? MERGECOPY :
1149 rop == wxOR ? MERGEPAINT :
1150 rop == wxSRC_INVERT ? NOTSRCCOPY :
1151 rop == wxXOR ? SRCINVERT :
1152 rop == wxOR_REVERSE ? MERGEPAINT :
1153 rop == wxAND_REVERSE ? SRCERASE :
1154 rop == wxSRC_OR ? SRCPAINT :
1155 rop == wxSRC_AND ? SRCAND :
1156 SRCCOPY;
1157
1158 bool success;
1159 if (useMask && source->m_selectedBitmap.Ok() && source->m_selectedBitmap.GetMask())
1160 {
1161
1162 #if 0 // __WIN32__
1163 // Not implemented under Win95 (or maybe a specific device?)
1164 if (MaskBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height,
1165 (HDC) source->m_hDC, xsrc1, ysrc1, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap(),
1166 0, 0, 0xAACC0020))
1167 {
1168 // Success
1169 }
1170 else
1171 #endif
1172 {
1173 // Old code
1174 #if 0
1175 HDC dc_mask = CreateCompatibleDC((HDC) source->m_hDC);
1176 ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap());
1177 success = (BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height,
1178 dc_mask, xsrc1, ysrc1, 0x00220326 /* NOTSRCAND */) != 0);
1179 success = (BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height,
1180 (HDC) source->m_hDC, xsrc1, ysrc1, SRCPAINT) != 0);
1181 ::SelectObject(dc_mask, 0);
1182 ::DeleteDC(dc_mask);
1183 #endif
1184 // New code from Chris Breeze, 15/7/98
1185 // Blit bitmap with mask
1186
1187 if (IsKindOf(CLASSINFO(wxPrinterDC)))
1188 {
1189 // If we are printing source colours are screen colours
1190 // not printer colours and so we need copy the bitmap
1191 // pixel by pixel.
1192 RECT rect;
1193 HDC dc_mask = ::CreateCompatibleDC((HDC) source->m_hDC);
1194 HDC dc_src = (HDC) source->m_hDC;
1195
1196 ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap());
1197 for (int x = 0; x < width; x++)
1198 {
1199 for (int y = 0; y < height; y++)
1200 {
1201 COLORREF cref = ::GetPixel(dc_mask, x, y);
1202 if (cref)
1203 {
1204 HBRUSH brush = ::CreateSolidBrush(::GetPixel(dc_src, x, y));
1205 rect.left = xdest1 + x; rect.right = rect.left + 1;
1206 rect.top = ydest1 + y; rect.bottom = rect.top + 1;
1207 ::FillRect((HDC) m_hDC, &rect, brush);
1208 ::DeleteObject(brush);
1209 }
1210 }
1211 }
1212 ::SelectObject(dc_mask, 0);
1213 ::DeleteDC(dc_mask);
1214 }
1215 else
1216 {
1217 // create a temp buffer bitmap and DCs to access it and the mask
1218 HDC dc_mask = ::CreateCompatibleDC((HDC) source->m_hDC);
1219 HDC dc_buffer = ::CreateCompatibleDC((HDC) m_hDC);
1220 HBITMAP buffer_bmap = ::CreateCompatibleBitmap((HDC) m_hDC, width, height);
1221 ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap());
1222 ::SelectObject(dc_buffer, buffer_bmap);
1223
1224 // copy dest to buffer
1225 ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height,
1226 (HDC) m_hDC, xdest1, ydest1, SRCCOPY);
1227
1228 // copy src to buffer using selected raster op
1229 ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height,
1230 (HDC) source->m_hDC, xsrc1, ysrc1, dwRop);
1231
1232 // set masked area in buffer to BLACK (pixel value 0)
1233 COLORREF prevBkCol = ::SetBkColor((HDC) m_hDC, RGB(255, 255, 255));
1234 COLORREF prevCol = ::SetTextColor((HDC) m_hDC, RGB(0, 0, 0));
1235 ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height,
1236 dc_mask, xsrc1, ysrc1, SRCAND);
1237
1238 // set unmasked area in dest to BLACK
1239 ::SetBkColor((HDC) m_hDC, RGB(0, 0, 0));
1240 ::SetTextColor((HDC) m_hDC, RGB(255, 255, 255));
1241 ::BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height,
1242 dc_mask, xsrc1, ysrc1, SRCAND);
1243 ::SetBkColor((HDC) m_hDC, prevBkCol); // restore colours to original values
1244 ::SetTextColor((HDC) m_hDC, prevCol);
1245
1246 // OR buffer to dest
1247 success = (::BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height,
1248 dc_buffer, 0, 0, SRCPAINT) != 0);
1249
1250 // tidy up temporary DCs and bitmap
1251 ::SelectObject(dc_mask, 0);
1252 ::DeleteDC(dc_mask);
1253 ::SelectObject(dc_buffer, 0);
1254 ::DeleteDC(dc_buffer);
1255 ::DeleteObject(buffer_bmap);
1256 }
1257 }
1258 }
1259 else
1260 {
1261 if (IsKindOf(CLASSINFO(wxPrinterDC)))
1262 {
1263 // If we are printing source colours are screen colours
1264 // not printer colours and so we need copy the bitmap
1265 // pixel by pixel.
1266 HDC dc_src = (HDC) source->m_hDC;
1267 RECT rect;
1268 for (int x = 0; x < width; x++)
1269 {
1270 for (int y = 0; y < height; y++)
1271 {
1272 HBRUSH brush = ::CreateSolidBrush(::GetPixel(dc_src, x, y));
1273 rect.left = xdest1 + x; rect.right = rect.left + 1;
1274 rect.top = ydest1 + y; rect.bottom = rect.top + 1;
1275 ::FillRect((HDC) m_hDC, &rect, brush);
1276 ::DeleteObject(brush);
1277 }
1278 }
1279 }
1280 else
1281 {
1282 success = (BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, (HDC) source->m_hDC,
1283 xsrc1, ysrc1, dwRop) != 0);
1284 }
1285 }
1286 ::SetTextColor((HDC)m_hDC, old_textground);
1287 ::SetBkColor((HDC)m_hDC, old_background);
1288
1289 return success;
1290 }
1291
1292 void wxDC::GetSize(int* width, int* height) const
1293 {
1294 long w=::GetDeviceCaps((HDC) m_hDC,HORZRES);
1295 long h=::GetDeviceCaps((HDC) m_hDC,VERTRES);
1296 *width = w;
1297 *height = h;
1298 }
1299
1300 void wxDC::GetSizeMM(long *width, long *height) const
1301 {
1302 long w=::GetDeviceCaps((HDC) m_hDC,HORZSIZE);
1303 long h=::GetDeviceCaps((HDC) m_hDC,VERTSIZE);
1304 *width = w;
1305 *height = h;
1306 }
1307
1308 #if USE_SPLINES
1309 #include "xfspline.inc"
1310 #endif // USE_SPLINES
1311
1312 void wxDC::DrawPolygon(wxList *list, long xoffset, long yoffset,int fillStyle)
1313 {
1314 int n = list->Number();
1315 wxPoint *points = new wxPoint[n];
1316
1317 int i = 0;
1318 for(wxNode *node = list->First(); node; node = node->Next()) {
1319 wxPoint *point = (wxPoint *)node->Data();
1320 points[i].x = point->x;
1321 points[i++].y = point->y;
1322 }
1323 DrawPolygon(n, points, xoffset, yoffset,fillStyle);
1324 delete[] points;
1325 }
1326
1327 void wxDC::DrawLines(wxList *list, long xoffset, long yoffset)
1328 {
1329 int n = list->Number();
1330 wxPoint *points = new wxPoint[n];
1331
1332 int i = 0;
1333 for(wxNode *node = list->First(); node; node = node->Next()) {
1334 wxPoint *point = (wxPoint *)node->Data();
1335 points[i].x = point->x;
1336 points[i++].y = point->y;
1337 }
1338 DrawLines(n, points, xoffset, yoffset);
1339 delete []points;
1340 }
1341
1342 void wxDC::SetTextForeground(const wxColour& colour)
1343 {
1344 m_textForegroundColour = colour;
1345 }
1346
1347 void wxDC::SetTextBackground(const wxColour& colour)
1348 {
1349 m_textBackgroundColour = colour;
1350 }
1351
1352 #if USE_SPLINES
1353 // Make a 3-point spline
1354 void wxDC::DrawSpline(long x1, long y1, long x2, long y2, long x3, long y3)
1355 {
1356 wxList *point_list = new wxList;
1357
1358 wxPoint *point1 = new wxPoint;
1359 point1->x = x1; point1->y = y1;
1360 point_list->Append((wxObject*)point1);
1361
1362 wxPoint *point2 = new wxPoint;
1363 point2->x = x2; point2->y = y2;
1364 point_list->Append((wxObject*)point2);
1365
1366 wxPoint *point3 = new wxPoint;
1367 point3->x = x3; point3->y = y3;
1368 point_list->Append((wxObject*)point3);
1369
1370 DrawSpline(point_list);
1371
1372 for(wxNode *node = point_list->First(); node; node = node->Next()) {
1373 wxPoint *p = (wxPoint *)node->Data();
1374 delete p;
1375 }
1376 delete point_list;
1377 }
1378 #endif
1379
1380 // For use by wxWindows only, unless custom units are required.
1381 void wxDC::SetLogicalScale(double x, double y)
1382 {
1383 m_logicalScaleX = x;
1384 m_logicalScaleY = y;
1385 }
1386
1387 void wxDC::CalcBoundingBox(long x, long y)
1388 {
1389 if (x < m_minX) m_minX = x;
1390 if (y < m_minY) m_minY = y;
1391 if (x > m_maxX) m_maxX = x;
1392 if (y > m_maxY) m_maxY = y;
1393 }
1394
1395 void wxDC::GetClippingBox(long *x,long *y,long *w,long *h) const
1396 {
1397 if (m_clipping)
1398 {
1399 *x = m_clipX1 ;
1400 *y = m_clipY1 ;
1401 *w = (m_clipX2 - m_clipX1) ;
1402 *h = (m_clipY2 - m_clipY1) ;
1403 }
1404 else
1405 *x = *y = *w = *h = 0 ;
1406 }
1407
1408 #if WXWIN_COMPATIBILITY
1409 void wxDC::GetTextExtent(const wxString& string, float *x, float *y,
1410 float *descent, float *externalLeading,
1411 wxFont *theFont, bool use16bit) const
1412 {
1413 long x1, y1, descent1, externalLeading1;
1414 GetTextExtent(string, & x1, & y1, & descent1, & externalLeading1, theFont, use16bit);
1415 *x = x1; *y = y1;
1416 if (descent)
1417 *descent = descent1;
1418 if (externalLeading)
1419 *externalLeading = externalLeading1;
1420 }
1421 #endif
1422