]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/dc.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dc.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/dialog.h"
31 #include "wx/dcprint.h"
32 #include "wx/msw/private.h"
38 #if USE_COMMON_DIALOGS
58 #if !USE_SHARED_LIBRARY
59 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
62 // Declarations local to this file
64 #define YSCALE(y) (yorigin - (y))
66 // #define wx_round(a) (int)((a)+.5)
68 // Default constructor
71 m_minX
= 0; m_minY
= 0; m_maxX
= 0; m_maxY
= 0;
73 m_autoSetting
= TRUE
;
82 m_minX
= 0; m_minY
= 0; m_maxX
= 0; m_maxY
= 0;
87 m_logicalScaleX
= 1.0;
88 m_logicalScaleY
= 1.0;
95 m_mappingMode
= MM_TEXT
;
100 m_windowExtX
= VIEWPORT_EXTENT
;
101 m_windowExtY
= VIEWPORT_EXTENT
;
102 m_logicalFunction
= -1;
104 m_backgroundBrush
= *wxWHITE_BRUSH
;
106 m_textForegroundColour
= *wxBLACK
;
107 m_textBackgroundColour
= *wxWHITE
;
109 m_colour
= wxColourDisplay();
118 SelectOldObjects(m_hDC
);
120 if ( m_canvas
== NULL
)
121 ::DeleteDC((HDC
)m_hDC
);
123 ::ReleaseDC((HWND
)m_canvas
->GetHWND(), (HDC
)m_hDC
);
129 // This will select current objects out of the DC,
130 // which is what you have to do before deleting the
132 void wxDC::SelectOldObjects(WXHDC dc
)
135 wxDebugMsg("wxDC::SelectOldObjects %X\n", this);
142 wxDebugMsg("wxDC::SelectOldObjects: Selecting old HBITMAP %X\n", m_oldBitmap
);
144 ::SelectObject((HDC
) dc
, (HBITMAP
) m_oldBitmap
);
145 if (m_selectedBitmap
.Ok())
147 m_selectedBitmap
.SetSelectedInto(NULL
);
154 wxDebugMsg("wxDC::SelectOldObjects: Selecting old HPEN %X\n", m_oldPen
);
156 ::SelectObject((HDC
) dc
, (HPEN
) m_oldPen
);
162 wxDebugMsg("wxDC::SelectOldObjects: Selecting old HBRUSH %X\n", m_oldBrush
);
164 ::SelectObject((HDC
) dc
, (HBRUSH
) m_oldBrush
);
170 wxDebugMsg("wxDC::SelectOldObjects: Selecting old HFONT %X\n", m_oldFont
);
172 ::SelectObject((HDC
) dc
, (HFONT
) m_oldFont
);
178 wxDebugMsg("wxDC::SelectOldObjects: Selecting old HPALETTE %X\n", m_oldPalette
);
180 ::SelectPalette((HDC
) dc
, (HPALETTE
) m_oldPalette
, TRUE
);
183 wxDebugMsg("wxDC::SelectOldObjects: Done.\n");
188 m_brush
= wxNullBrush
;
190 m_palette
= wxNullPalette
;
192 m_backgroundBrush
= wxNullBrush
;
193 m_selectedBitmap
= wxNullBitmap
;
196 void wxDC::SetClippingRegion(long cx
, long cy
, long cw
, long ch
)
201 m_clipX2
= (int)(cx
+ cw
);
202 m_clipY2
= (int)(cy
+ ch
);
204 DoClipping((WXHDC
) m_hDC
);
207 void wxDC::DoClipping(WXHDC dc
)
209 if (m_clipping
&& dc
)
211 IntersectClipRect((HDC
) dc
, XLOG2DEV(m_clipX1
), YLOG2DEV(m_clipY1
),
212 XLOG2DEV(m_clipX2
), YLOG2DEV(m_clipY2
));
216 void wxDC::DestroyClippingRegion(void)
218 if (m_clipping
&& m_hDC
)
220 HRGN rgn
= CreateRectRgn(0, 0, 32000, 32000);
222 wxDebugMsg("wxDC::DestroyClippingRegion: Selecting HRGN %X\n", rgn
);
224 SelectClipRgn((HDC
) m_hDC
, rgn
);
226 wxDebugMsg("wxDC::DestroyClippingRegion: Deleting HRGN %X\n", rgn
);
233 bool wxDC::CanDrawBitmap(void) const
238 bool wxDC::CanGetTextExtent(void) const
240 // What sort of display is it?
241 int technology
= ::GetDeviceCaps((HDC
) m_hDC
, TECHNOLOGY
);
245 if (technology
!= DT_RASDISPLAY
&& technology
!= DT_RASPRINTER
)
252 void wxDC::SetPalette(const wxPalette
& palette
)
254 // Set the old object temporarily, in case the assignment deletes an object
255 // that's not yet selected out.
258 ::SelectPalette((HDC
) m_hDC
, (HPALETTE
) m_oldPalette
, TRUE
);
262 m_palette
= m_palette
;
266 // Setting a NULL colourmap is a way of restoring
267 // the original colourmap
270 ::SelectPalette((HDC
) m_hDC
, (HPALETTE
) m_oldPalette
, TRUE
);
272 wxDebugMsg("wxDC::SetPalette: set old palette %X\n", m_oldPalette
);
280 if (m_palette
.Ok() && m_palette
.GetHPALETTE())
282 HPALETTE oldPal
= ::SelectPalette((HDC
) m_hDC
, (HPALETTE
) m_palette
.GetHPALETTE(), TRUE
);
284 m_oldPalette
= (WXHPALETTE
) oldPal
;
287 wxDebugMsg("wxDC::SetPalette %X: selected palette %X\n", this, m_palette
.GetHPALETTE());
289 wxDebugMsg("wxDC::SetPalette: oldPal was palette %X\n", oldPal
);
291 wxDebugMsg("wxDC::SetPalette: m_oldPalette is palette %X\n", m_oldPalette
);
293 ::RealizePalette((HDC
) m_hDC
);
297 void wxDC::Clear(void)
301 GetClientRect((HWND
) m_canvas
->GetHWND(), &rect
);
302 else if (m_selectedBitmap
.Ok())
304 rect
.left
= 0; rect
.top
= 0;
305 rect
.right
= m_selectedBitmap
.GetWidth();
306 rect
.bottom
= m_selectedBitmap
.GetHeight();
308 (void) ::SetMapMode((HDC
) m_hDC
, MM_TEXT
);
310 DWORD colour
= GetBkColor((HDC
) m_hDC
);
311 HBRUSH brush
= CreateSolidBrush(colour
);
312 FillRect((HDC
) m_hDC
, &rect
, brush
);
315 ::SetMapMode((HDC
) m_hDC
, MM_ANISOTROPIC
);
316 ::SetViewportExtEx((HDC
) m_hDC
, VIEWPORT_EXTENT
, VIEWPORT_EXTENT
, NULL
);
317 ::SetWindowExtEx((HDC
) m_hDC
, m_windowExtX
, m_windowExtY
, NULL
);
318 ::SetViewportOrgEx((HDC
) m_hDC
, (int)m_deviceOriginX
, (int)m_deviceOriginY
, NULL
);
319 ::SetWindowOrgEx((HDC
) m_hDC
, (int)m_logicalOriginX
, (int)m_logicalOriginY
, NULL
);
322 void wxDC::FloodFill(long x
, long y
, wxColour
*col
, int style
)
327 if (m_brush
.Ok() && m_autoSetting
)
330 (void)ExtFloodFill((HDC
) m_hDC
, XLOG2DEV(x
), YLOG2DEV(y
),
332 style
==wxFLOOD_SURFACE
?
333 FLOODFILLSURFACE
:FLOODFILLBORDER
336 CalcBoundingBox(x
, y
);
339 bool wxDC::GetPixel(long x
, long y
, wxColour
*col
) const
341 // added by steve 29.12.94 (copied from DrawPoint)
342 // returns TRUE for pixels in the color of the current pen
343 // and FALSE for all other pixels colors
344 // if col is non-NULL return the color of the pixel
346 // get the color of the pixel
347 COLORREF pixelcolor
= ::GetPixel((HDC
) m_hDC
, XLOG2DEV(x
), YLOG2DEV(y
));
348 // get the color of the pen
349 COLORREF pencolor
= 0x00ffffff;
352 pencolor
= m_pen
.GetColour().GetPixel() ;
355 // return the color of the pixel
357 col
->Set(GetRValue(pixelcolor
),GetGValue(pixelcolor
),GetBValue(pixelcolor
));
359 // check, if color of the pixels is the same as the color
360 // of the current pen
361 return(pixelcolor
==pencolor
);
364 void wxDC::CrossHair(long x
, long y
)
366 if (m_pen
.Ok() && m_autoSetting
)
369 // We suppose that our screen is 2000x2000 max.
375 (void)MoveToEx((HDC
) m_hDC
, XLOG2DEV(x1
), YLOG2DEV(y
), NULL
);
376 (void)LineTo((HDC
) m_hDC
, XLOG2DEV(x2
), YLOG2DEV(y
));
378 (void)MoveToEx((HDC
) m_hDC
, XLOG2DEV(x
), YLOG2DEV(y1
), NULL
);
379 (void)LineTo((HDC
) m_hDC
, XLOG2DEV(x
), YLOG2DEV(y2
));
381 CalcBoundingBox(x1
, y1
);
382 CalcBoundingBox(x2
, y2
);
385 void wxDC::DrawLine(long x1
, long y1
, long x2
, long y2
)
387 // BUGBUG - is this necessary? YES YES YES YEs Yes yes ye....
388 if (m_pen
.Ok() && m_autoSetting
)
391 (void)MoveToEx((HDC
) m_hDC
, XLOG2DEV(x1
), YLOG2DEV(y1
), NULL
);
392 (void)LineTo((HDC
) m_hDC
, XLOG2DEV(x2
), YLOG2DEV(y2
));
394 /* MATTHEW: [6] New normalization */
395 #if WX_STANDARD_GRAPHICS
396 (void)LineTo((HDC
) m_hDC
, XLOG2DEV(x2
) + 1, YLOG2DEV(y2
));
399 CalcBoundingBox(x1
, y1
);
400 CalcBoundingBox(x2
, y2
);
403 void wxDC::DrawArc(long x1
,long y1
,long x2
,long y2
,double xc
,double yc
)
407 double radius
= (double)sqrt(dx
*dx
+dy
*dy
) ;;
408 if (x1
==x2
&& x2
==y2
)
410 DrawEllipse(xc
,yc
,(double)(radius
*2.0),(double)(radius
*2)) ;
414 // BUGBUG - is this necessary?
415 if (m_pen
.Ok() && m_autoSetting
)
418 long xx1
= XLOG2DEV(x1
) ;
419 long yy1
= YLOG2DEV(y1
) ;
420 long xx2
= XLOG2DEV(x2
) ;
421 long yy2
= YLOG2DEV(y2
) ;
422 long xxc
= XLOG2DEV(xc
) ;
423 long yyc
= YLOG2DEV(yc
) ;
424 long ray
= (long) sqrt(double((xxc
-xx1
)*(xxc
-xx1
)+(yyc
-yy1
)*(yyc
-yy1
))) ;
426 (void)MoveToEx((HDC
) m_hDC
, (int) xx1
, (int) yy1
, NULL
);
427 long xxx1
= (long) (xxc
-ray
);
428 long yyy1
= (long) (yyc
-ray
);
429 long xxx2
= (long) (xxc
+ray
);
430 long yyy2
= (long) (yyc
+ray
);
431 if (m_brush
.Ok() && m_brush
.GetStyle() !=wxTRANSPARENT
)
433 // BUGBUG - is this necessary?
434 if (m_brush
.GetStyle()!=wxTRANSPARENT
&&m_autoSetting
)
436 Pie((HDC
) m_hDC
,xxx1
,yyy1
,xxx2
,yyy2
,
440 Arc((HDC
) m_hDC
,xxx1
,yyy1
,xxx2
,yyy2
,
443 CalcBoundingBox((xc
-radius
), (yc
-radius
));
444 CalcBoundingBox((xc
+radius
), (yc
+radius
));
447 void wxDC::DrawPoint(long x
, long y
)
449 // BUGBUG - is this necessary?
450 if (m_pen
.Ok() && m_autoSetting
)
453 COLORREF color
= 0x00ffffff;
456 color
= m_pen
.GetColour().GetPixel() ;
459 SetPixel((HDC
) m_hDC
, XLOG2DEV(x
), YLOG2DEV(y
), color
);
461 CalcBoundingBox(x
, y
);
464 void wxDC::DrawPolygon(int n
, wxPoint points
[], long xoffset
, long yoffset
,int fillStyle
)
466 // BUGBUG - is this necessary?
467 if (m_pen
.Ok() && m_autoSetting
)
470 POINT
*cpoints
= new POINT
[n
];
472 for (i
= 0; i
< n
; i
++)
474 cpoints
[i
].x
= (int)(XLOG2DEV(points
[i
].x
+ xoffset
));
475 cpoints
[i
].y
= (int)(YLOG2DEV(points
[i
].y
+ yoffset
));
477 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
480 int prev
= SetPolyFillMode((HDC
) m_hDC
,fillStyle
==wxODDEVEN_RULE
?ALTERNATE
:WINDING
) ;
481 (void)Polygon((HDC
) m_hDC
, cpoints
, n
);
482 SetPolyFillMode((HDC
) m_hDC
,prev
) ;
487 void wxDC::DrawLines(int n
, wxPoint points
[], long xoffset
, long yoffset
)
489 // BUGBUG - is this necessary?
490 if (m_pen
.Ok() && m_autoSetting
)
493 POINT
*cpoints
= new POINT
[n
];
495 for (i
= 0; i
< n
; i
++)
497 cpoints
[i
].x
= (int)(XLOG2DEV(points
[i
].x
+ xoffset
));
498 cpoints
[i
].y
= (int)(YLOG2DEV(points
[i
].y
+ yoffset
));
500 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
503 (void)Polyline((HDC
) m_hDC
, cpoints
, n
);
508 void wxDC::DrawRectangle(long x
, long y
, long width
, long height
)
510 // BUGBUG - is this necessary?
511 if (m_pen
.Ok() && m_autoSetting
)
515 long y2
= y
+ height
;
517 /* MATTHEW: [6] new normalization */
518 #if WX_STANDARD_GRAPHICS
519 bool do_brush
, do_pen
;
521 do_brush
= m_brush
.Ok() && m_brush
.GetStyle() != wxTRANSPARENT
;
522 do_pen
= m_pen
.Ok() && m_pen
.GetStyle() != wxTRANSPARENT
;
525 HPEN orig_pen
= NULL
;
527 if (do_pen
|| !m_pen
.Ok())
528 orig_pen
= ::SelectObject((HDC
) m_hDC
, ::GetStockObject(NULL_PEN
));
530 (void)Rectangle((HDC
) m_hDC
, XLOG2DEV(x
), YLOG2DEV(y
),
531 XLOG2DEV(x2
) + 1, YLOG2DEV(y2
) + 1);
533 if (do_pen
|| !m_pen
.Ok())
534 ::SelectObject((HDC
) m_hDC
, orig_pen
);
537 HBRUSH orig_brush
= NULL
;
539 if (do_brush
|| !m_brush
.Ok())
540 orig_brush
= ::SelectObject((HDC
) m_hDC
, ::GetStockObject(NULL_BRUSH
));
542 (void)Rectangle((HDC
) m_hDC
, XLOG2DEV(x
), YLOG2DEV(y
),
543 XLOG2DEV(x2
), YLOG2DEV(y2
));
545 if (do_brush
|| !m_brush
.Ok())
546 ::SelectObject((HDC
) m_hDC
, orig_brush
);
549 (void)Rectangle((HDC
) m_hDC
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
));
552 CalcBoundingBox(x
, y
);
553 CalcBoundingBox(x2
, y2
);
556 void wxDC::DrawRoundedRectangle(long x
, long y
, long width
, long height
, double radius
)
558 // BUGBUG - is this necessary?
559 if (m_pen
.Ok() && m_autoSetting
)
562 // Now, a negative radius value is interpreted to mean
563 // 'the proportion of the smallest X or Y dimension'
567 double smallest
= 0.0;
572 radius
= (- radius
* smallest
);
576 long y2
= (y
+height
);
578 (void)RoundRect((HDC
) m_hDC
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
),
579 YLOG2DEV(y2
), 2*XLOG2DEV(radius
), 2*YLOG2DEV(radius
));
581 CalcBoundingBox(x
, y
);
582 CalcBoundingBox(x2
, y2
);
585 void wxDC::DrawEllipse(long x
, long y
, long width
, long height
)
587 // BUGBUG - is this necessary?
588 if (m_pen
.Ok() && m_autoSetting
)
592 long y2
= (y
+height
);
594 (void)Ellipse((HDC
) m_hDC
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
));
596 CalcBoundingBox(x
, y
);
597 CalcBoundingBox(x2
, y2
);
600 // Chris Breeze 20/5/98: first implementation of DrawEllipticArc on Windows
601 void wxDC::DrawEllipticArc(long x
,long y
,long w
,long h
,double sa
,double ea
)
603 // BUGBUG - is this necessary?
604 if (m_pen
.Ok() && m_autoSetting
)
610 const double deg2rad
= 3.14159265359 / 180.0;
611 int rx1
= XLOG2DEV(x
+w
/2);
612 int ry1
= YLOG2DEV(y
+h
/2);
615 rx1
+= (int)(100.0 * abs(w
) * cos(sa
* deg2rad
));
616 ry1
-= (int)(100.0 * abs(h
) * m_signY
* sin(sa
* deg2rad
));
617 rx2
+= (int)(100.0 * abs(w
) * cos(ea
* deg2rad
));
618 ry2
-= (int)(100.0 * abs(h
) * m_signY
* sin(ea
* deg2rad
));
620 // draw pie with NULL_PEN first and then outline otherwise a line is
621 // drawn from the start and end points to the centre
622 HPEN orig_pen
= ::SelectObject((HDC
) m_hDC
, ::GetStockObject(NULL_PEN
));
625 (void)Pie((HDC
) m_hDC
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
)+1, YLOG2DEV(y2
)+1,
630 (void)Pie((HDC
) m_hDC
, XLOG2DEV(x
), YLOG2DEV(y
)-1, XLOG2DEV(x2
)+1, YLOG2DEV(y2
),
631 rx1
, ry1
-1, rx2
, ry2
-1);
633 ::SelectObject((HDC
) m_hDC
, orig_pen
);
634 (void)Arc((HDC
) m_hDC
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
),
637 CalcBoundingBox(x
, y
);
638 CalcBoundingBox(x2
, y2
);
641 void wxDC::DrawIcon(const wxIcon
& icon
, long x
, long y
)
643 ::DrawIcon((HDC
) m_hDC
, XLOG2DEV(x
), YLOG2DEV(y
), (HICON
) icon
.GetHICON());
644 CalcBoundingBox(x
, y
);
645 CalcBoundingBox(x
+icon
.GetWidth(), y
+icon
.GetHeight());
648 void wxDC::SetFont(const wxFont
& the_font
)
650 // Set the old object temporarily, in case the assignment deletes an object
651 // that's not yet selected out.
654 ::SelectObject((HDC
) m_hDC
, (HFONT
) m_oldFont
);
663 ::SelectObject((HDC
) m_hDC
, (HFONT
) m_oldFont
);
667 if (m_font
.Ok() && m_font
.GetResourceHandle())
670 wxDebugMsg("wxDC::SetFont: Selecting HFONT %X\n", m_font
.GetResourceHandle());
672 HFONT f
= (HFONT
) ::SelectObject((HDC
) m_hDC
, (HFONT
) m_font
.GetResourceHandle());
674 m_oldFont
= (WXHFONT
) f
;
678 void wxDC::SetPen(const wxPen
& pen
)
680 // Set the old object temporarily, in case the assignment deletes an object
681 // that's not yet selected out.
684 ::SelectObject((HDC
) m_hDC
, (HPEN
) m_oldPen
);
693 ::SelectObject((HDC
) m_hDC
, (HPEN
) m_oldPen
);
699 if (m_pen
.GetResourceHandle())
701 HPEN p
= (HPEN
) ::SelectObject((HDC
) m_hDC
, (HPEN
)m_pen
.GetResourceHandle()) ;
703 m_oldPen
= (WXHPEN
) p
;
708 void wxDC::SetBrush(const wxBrush
& brush
)
710 // Set the old object temporarily, in case the assignment deletes an object
711 // that's not yet selected out.
714 ::SelectObject((HDC
) m_hDC
, (HBRUSH
) m_oldBrush
);
723 ::SelectObject((HDC
) m_hDC
, (HBRUSH
) m_oldBrush
);
729 if (m_brush
.GetResourceHandle())
732 b
= ::SelectObject((HDC
) m_hDC
, (HBRUSH
)m_brush
.GetResourceHandle()) ;
734 m_oldBrush
= (WXHBRUSH
) b
;
739 void wxDC::DrawText(const wxString
& text
, long x
, long y
, bool use16bit
)
741 if (m_font
.Ok() && m_font
.GetResourceHandle())
744 wxDebugMsg("wxDC::DrawText: Selecting HFONT %X\n", m_font
.GetResourceHandle());
746 HFONT f
= ::SelectObject((HDC
) m_hDC
, (HFONT
) m_font
.GetResourceHandle());
748 m_oldFont
= (WXHFONT
) f
;
751 if (m_textForegroundColour
.Ok())
752 SetTextColor((HDC
) m_hDC
, m_textForegroundColour
.GetPixel() ) ;
754 DWORD old_background
;
755 if (m_textBackgroundColour
.Ok())
757 old_background
= SetBkColor((HDC
) m_hDC
, m_textBackgroundColour
.GetPixel() ) ;
760 if (m_backgroundMode
== wxTRANSPARENT
)
761 SetBkMode((HDC
) m_hDC
, TRANSPARENT
);
763 SetBkMode((HDC
) m_hDC
, OPAQUE
);
765 (void)TextOut((HDC
) m_hDC
, XLOG2DEV(x
), YLOG2DEV(y
), (char *) (const char *)text
, strlen((const char *)text
));
767 if (m_textBackgroundColour
.Ok())
768 (void)SetBkColor((HDC
) m_hDC
, old_background
);
770 CalcBoundingBox(x
, y
);
773 GetTextExtent(text
, &w
, &h
);
774 CalcBoundingBox((x
+ w
), (y
+ h
));
777 void wxDC::SetBackground(const wxBrush
& brush
)
779 m_backgroundBrush
= brush
;
781 if (!m_backgroundBrush
.Ok())
786 bool customColours
= TRUE
;
787 // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
788 // change background colours from the control-panel specified colours.
789 if (m_canvas
->IsKindOf(CLASSINFO(wxWindow
)) && ((m_canvas
->GetWindowStyleFlag() & wxUSER_COLOURS
) != wxUSER_COLOURS
))
790 customColours
= FALSE
;
794 if (m_backgroundBrush
.GetStyle()==wxTRANSPARENT
)
796 m_canvas
->m_backgroundTransparent
= TRUE
;
800 m_canvas
->SetBackgroundColour(m_backgroundBrush
.GetColour());
801 m_canvas
->m_backgroundTransparent
= FALSE
;
805 COLORREF new_color
= m_backgroundBrush
.GetColour().GetPixel() ;
807 (void)SetBkColor((HDC
) m_hDC
, new_color
);
811 void wxDC::SetBackgroundMode(int mode
)
813 m_backgroundMode
= mode
;
815 if (m_backgroundMode
== wxTRANSPARENT
)
816 ::SetBkMode((HDC
) m_hDC
, TRANSPARENT
);
818 ::SetBkMode((HDC
) m_hDC
, OPAQUE
);
821 void wxDC::SetLogicalFunction(int function
)
823 m_logicalFunction
= function
;
825 SetRop((WXHDC
) m_hDC
);
828 void wxDC::SetRop(WXHDC dc
)
830 if (!dc
|| m_logicalFunction
< 0)
834 // These may be wrong
835 switch (m_logicalFunction
)
837 // case wxXOR: c_rop = R2_XORPEN; break;
838 case wxXOR
: c_rop
= R2_NOTXORPEN
; break;
839 case wxINVERT
: c_rop
= R2_NOT
; break;
840 case wxOR_REVERSE
: c_rop
= R2_MERGEPENNOT
; break;
841 case wxAND_REVERSE
: c_rop
= R2_MASKPENNOT
; break;
842 case wxCLEAR
: c_rop
= R2_WHITE
; break;
843 case wxSET
: c_rop
= R2_BLACK
; break;
844 case wxSRC_INVERT
: c_rop
= R2_NOTCOPYPEN
; break;
845 case wxOR_INVERT
: c_rop
= R2_MERGENOTPEN
; break;
846 case wxAND
: c_rop
= R2_MASKPEN
; break;
847 case wxOR
: c_rop
= R2_MERGEPEN
; break;
848 case wxAND_INVERT
: c_rop
= R2_MASKNOTPEN
; break;
853 c_rop
= R2_COPYPEN
; break;
855 SetROP2((HDC
) dc
, c_rop
);
858 bool wxDC::StartDoc(const wxString
& message
)
860 if (!this->IsKindOf(CLASSINFO(wxPrinterDC
)))
866 docinfo
.cbSize
= sizeof(DOCINFO
);
867 docinfo
.lpszDocName
= (const char *)message
;
868 docinfo
.lpszOutput
= (const char *)m_filename
;
869 #if defined(__WIN95__)
870 docinfo
.lpszDatatype
= NULL
;
874 if (m_hDC
) flag
= (SP_ERROR
!=
876 ::StartDoc((HDC
) m_hDC
, &docinfo
));
879 ::StartDocW((HDC
) m_hDC
, &docinfo
));
881 ::StartDocA((HDC
) m_hDC
, &docinfo
));
890 void wxDC::EndDoc(void)
892 if (!this->IsKindOf(CLASSINFO(wxPrinterDC
)))
894 if (m_hDC
) ::EndDoc((HDC
) m_hDC
);
897 void wxDC::StartPage(void)
899 if (!this->IsKindOf(CLASSINFO(wxPrinterDC
)))
902 ::StartPage((HDC
) m_hDC
);
905 void wxDC::EndPage(void)
907 if (!this->IsKindOf(CLASSINFO(wxPrinterDC
)))
910 ::EndPage((HDC
) m_hDC
);
913 long wxDC::GetCharHeight(void) const
915 TEXTMETRIC lpTextMetric
;
917 GetTextMetrics((HDC
) m_hDC
, &lpTextMetric
);
919 return YDEV2LOGREL(lpTextMetric
.tmHeight
);
922 long wxDC::GetCharWidth(void) const
924 TEXTMETRIC lpTextMetric
;
926 GetTextMetrics((HDC
) m_hDC
, &lpTextMetric
);
928 return XDEV2LOGREL(lpTextMetric
.tmAveCharWidth
);
931 void wxDC::GetTextExtent(const wxString
& string
, long *x
, long *y
,
932 long *descent
, long *externalLeading
, wxFont
*theFont
, bool use16bit
) const
934 wxFont
*fontToUse
= (wxFont
*) theFont
;
936 fontToUse
= (wxFont
*) &m_font
;
941 GetTextExtentPoint((HDC
) m_hDC
, (char *)(const char *) string
, strlen((char *)(const char *) string
), &sizeRect
);
942 GetTextMetrics((HDC
) m_hDC
, &tm
);
944 *x
= XDEV2LOGREL(sizeRect
.cx
);
945 *y
= YDEV2LOGREL(sizeRect
.cy
);
946 if (descent
) *descent
= tm
.tmDescent
;
947 if (externalLeading
) *externalLeading
= tm
.tmExternalLeading
;
950 void wxDC::SetMapMode(int mode
)
952 m_mappingMode
= mode
;
955 int pixel_height
= 0;
959 pixel_width
= GetDeviceCaps((HDC
) m_hDC
, HORZRES
);
960 pixel_height
= GetDeviceCaps((HDC
) m_hDC
, VERTRES
);
961 mm_width
= GetDeviceCaps((HDC
) m_hDC
, HORZSIZE
);
962 mm_height
= GetDeviceCaps((HDC
) m_hDC
, VERTSIZE
);
964 if ((pixel_width
== 0) || (pixel_height
== 0) || (mm_width
== 0) || (mm_height
== 0))
969 double mm2pixelsX
= pixel_width
/mm_width
;
970 double mm2pixelsY
= pixel_height
/mm_height
;
976 m_logicalScaleX
= (twips2mm
* mm2pixelsX
);
977 m_logicalScaleY
= (twips2mm
* mm2pixelsY
);
982 m_logicalScaleX
= (pt2mm
* mm2pixelsX
);
983 m_logicalScaleY
= (pt2mm
* mm2pixelsY
);
988 m_logicalScaleX
= mm2pixelsX
;
989 m_logicalScaleY
= mm2pixelsY
;
994 m_logicalScaleX
= (mm2pixelsX
/10.0);
995 m_logicalScaleY
= (mm2pixelsY
/10.0);
1001 m_logicalScaleX
= 1.0;
1002 m_logicalScaleY
= 1.0;
1007 if (::GetMapMode((HDC
) m_hDC
) != MM_ANISOTROPIC
)
1008 ::SetMapMode((HDC
) m_hDC
, MM_ANISOTROPIC
);
1010 SetViewportExtEx((HDC
) m_hDC
, VIEWPORT_EXTENT
, VIEWPORT_EXTENT
, NULL
);
1011 m_windowExtX
= (int)MS_XDEV2LOGREL(VIEWPORT_EXTENT
);
1012 m_windowExtY
= (int)MS_YDEV2LOGREL(VIEWPORT_EXTENT
);
1013 ::SetWindowExtEx((HDC
) m_hDC
, m_windowExtX
, m_windowExtY
, NULL
);
1014 ::SetViewportOrgEx((HDC
) m_hDC
, (int)m_deviceOriginX
, (int)m_deviceOriginY
, NULL
);
1015 ::SetWindowOrgEx((HDC
) m_hDC
, (int)m_logicalOriginX
, (int)m_logicalOriginY
, NULL
);
1018 void wxDC::SetUserScale(double x
, double y
)
1023 SetMapMode(m_mappingMode
);
1026 void wxDC::SetAxisOrientation(bool xLeftRight
, bool yBottomUp
)
1028 m_signX
= xLeftRight
? 1 : -1;
1029 m_signY
= yBottomUp
? -1 : 1;
1031 SetMapMode(m_mappingMode
);
1034 void wxDC::SetSystemScale(double x
, double y
)
1039 SetMapMode(m_mappingMode
);
1042 void wxDC::SetLogicalOrigin(long x
, long y
)
1044 m_logicalOriginX
= x
;
1045 m_logicalOriginY
= y
;
1047 ::SetWindowOrgEx((HDC
) m_hDC
, (int)m_logicalOriginX
, (int)m_logicalOriginY
, NULL
);
1050 void wxDC::SetDeviceOrigin(long x
, long y
)
1052 m_deviceOriginX
= x
;
1053 m_deviceOriginY
= y
;
1055 ::SetViewportOrgEx((HDC
) m_hDC
, (int)m_deviceOriginX
, (int)m_deviceOriginY
, NULL
);
1058 long wxDC::DeviceToLogicalX(long x
) const
1060 return (long) (((x
) - m_deviceOriginX
)/(m_logicalScaleX
*m_userScaleX
*m_signX
*m_systemScaleX
) - m_logicalOriginX
) ;
1063 long wxDC::DeviceToLogicalXRel(long x
) const
1065 return (long) ((x
)/(m_logicalScaleX
*m_userScaleX
*m_signX
*m_systemScaleX
)) ;
1068 long wxDC::DeviceToLogicalY(long y
) const
1070 return (long) (((y
) - m_deviceOriginY
)/(m_logicalScaleY
*m_userScaleY
*m_signY
*m_systemScaleY
) - m_logicalOriginY
) ;
1073 long wxDC::DeviceToLogicalYRel(long y
) const
1075 return (long) ((y
)/(m_logicalScaleY
*m_userScaleY
*m_signY
*m_systemScaleY
)) ;
1078 long wxDC::LogicalToDeviceX(long x
) const
1080 return (long) (floor((x
) - m_logicalOriginX
)*m_logicalScaleX
*m_userScaleX
*m_signX
*m_systemScaleX
+ m_deviceOriginX
) ;
1083 long wxDC::LogicalToDeviceXRel(long x
) const
1085 return (long) (floor(x
)*m_logicalScaleX
*m_userScaleX
*m_signX
*m_systemScaleX
) ;
1088 long wxDC::LogicalToDeviceY(long y
) const
1090 return (long) (floor((y
) - m_logicalOriginY
)*m_logicalScaleY
*m_userScaleY
*m_signY
*m_systemScaleY
+ m_deviceOriginY
);
1093 long wxDC::LogicalToDeviceYRel(long y
) const
1095 return (long) (floor(y
)*m_logicalScaleY
*m_userScaleY
*m_signY
*m_systemScaleY
) ;
1098 // This group of functions may not do any conversion
1099 // if m_scaleGDI is TRUE, since the HDC does the
1100 // conversion automatically.
1102 long wxDC::ImplDeviceToLogicalX(long x
) const
1104 // return (m_scaleGDI ? x : DeviceToLogicalX(x));
1108 long wxDC::ImplDeviceToLogicalY(long y
) const
1110 // return (m_scaleGDI ? y : DeviceToLogicalY(y));
1114 long wxDC::ImplDeviceToLogicalXRel(long x
) const
1116 // return (m_scaleGDI ? x : DeviceToLogicalXRel(x));
1120 long wxDC::ImplDeviceToLogicalYRel(long y
) const
1122 // return (m_scaleGDI ? y : DeviceToLogicalYRel(y));
1126 long wxDC::ImplLogicalToDeviceX(long x
) const
1128 // return (m_scaleGDI ? (floor(double(x))) : LogicalToDeviceX(x));
1132 long wxDC::ImplLogicalToDeviceY(long y
) const
1134 // return (m_scaleGDI ? (floor(double(y))) : LogicalToDeviceY(y));
1138 long wxDC::ImplLogicalToDeviceXRel(long x
) const
1140 // return (m_scaleGDI ? (floor(double(x))) : LogicalToDeviceXRel(x));
1144 long wxDC::ImplLogicalToDeviceYRel(long y
) const
1146 // return (m_scaleGDI ? (floor(double(y))) : LogicalToDeviceYRel(y));
1150 bool wxDC::Blit(long xdest
, long ydest
, long width
, long height
,
1151 wxDC
*source
, long xsrc
, long ysrc
, int rop
, bool useMask
)
1153 long xdest1
= xdest
;
1154 long ydest1
= ydest
;
1158 // Chris Breeze 18/5/98: use text foreground/background colours
1159 // when blitting from 1-bit bitmaps
1160 COLORREF old_textground
= ::GetTextColor((HDC
)m_hDC
);
1161 COLORREF old_background
= ::GetBkColor((HDC
)m_hDC
);
1162 if (m_textForegroundColour
.Ok())
1164 ::SetTextColor((HDC
) m_hDC
, m_textForegroundColour
.GetPixel() ) ;
1166 if (m_textBackgroundColour
.Ok())
1168 ::SetBkColor((HDC
) m_hDC
, m_textBackgroundColour
.GetPixel() ) ;
1171 DWORD dwRop
= rop
== wxCOPY
? SRCCOPY
:
1172 rop
== wxCLEAR
? WHITENESS
:
1173 rop
== wxSET
? BLACKNESS
:
1174 rop
== wxINVERT
? DSTINVERT
:
1175 rop
== wxAND
? MERGECOPY
:
1176 rop
== wxOR
? MERGEPAINT
:
1177 rop
== wxSRC_INVERT
? NOTSRCCOPY
:
1178 rop
== wxXOR
? SRCINVERT
:
1179 rop
== wxOR_REVERSE
? MERGEPAINT
:
1180 rop
== wxAND_REVERSE
? SRCERASE
:
1181 rop
== wxSRC_OR
? SRCPAINT
:
1182 rop
== wxSRC_AND
? SRCAND
:
1186 if (useMask
&& source
->m_selectedBitmap
.Ok() && source
->m_selectedBitmap
.GetMask())
1190 // Not implemented under Win95 (or maybe a specific device?)
1191 if (MaskBlt((HDC
) m_hDC
, xdest1
, ydest1
, (int)width
, (int)height
,
1192 (HDC
) source
->m_hDC
, xsrc1
, ysrc1
, (HBITMAP
) source
->m_selectedBitmap
.GetMask()->GetMaskBitmap(),
1202 HDC dc_mask
= CreateCompatibleDC((HDC
) source
->m_hDC
);
1203 ::SelectObject(dc_mask
, (HBITMAP
) source
->m_selectedBitmap
.GetMask()->GetMaskBitmap());
1204 success
= (BitBlt((HDC
) m_hDC
, xdest1
, ydest1
, (int)width
, (int)height
,
1205 dc_mask
, xsrc1
, ysrc1
, 0x00220326 /* NOTSRCAND */) != 0);
1206 success
= (BitBlt((HDC
) m_hDC
, xdest1
, ydest1
, (int)width
, (int)height
,
1207 (HDC
) source
->m_hDC
, xsrc1
, ysrc1
, SRCPAINT
) != 0);
1208 ::SelectObject(dc_mask
, 0);
1209 ::DeleteDC(dc_mask
);
1211 // New code from Chris Breeze, 8/5/98
1213 // create a temp buffer bitmap and DCs to access it and the mask
1214 HDC dc_mask
= ::CreateCompatibleDC((HDC
) source
->m_hDC
);
1215 HDC dc_buffer
= ::CreateCompatibleDC((HDC
) m_hDC
);
1216 HBITMAP buffer_bmap
= ::CreateCompatibleBitmap((HDC
) m_hDC
, width
, height
);
1217 ::SelectObject(dc_mask
, (HBITMAP
) source
->m_selectedBitmap
.GetMask()->GetMaskBitmap());
1218 ::SelectObject(dc_buffer
, buffer_bmap
);
1220 // copy dest to buffer
1221 ::BitBlt(dc_buffer
, 0, 0, (int)width
, (int)height
,
1222 (HDC
) m_hDC
, xdest1
, ydest1
, SRCCOPY
);
1224 // copy src to buffer using selected raster op
1225 ::BitBlt(dc_buffer
, 0, 0, (int)width
, (int)height
,
1226 (HDC
) source
->m_hDC
, xsrc1
, ysrc1
, dwRop
);
1228 // set masked area in buffer to BLACK (pixel value 0)
1229 COLORREF prevBkCol
= ::SetBkColor((HDC
) m_hDC
, RGB(255, 255, 255));
1230 COLORREF prevCol
= ::SetTextColor((HDC
) m_hDC
, RGB(0, 0, 0));
1231 ::BitBlt(dc_buffer
, 0, 0, (int)width
, (int)height
,
1232 dc_mask
, xsrc1
, ysrc1
, SRCAND
);
1234 // set unmasked area in dest to BLACK
1235 ::SetBkColor((HDC
) m_hDC
, RGB(0, 0, 0));
1236 ::SetTextColor((HDC
) m_hDC
, RGB(255, 255, 255));
1237 ::BitBlt((HDC
) m_hDC
, xdest1
, ydest1
, (int)width
, (int)height
,
1238 dc_mask
, xsrc1
, ysrc1
, SRCAND
);
1239 ::SetBkColor((HDC
) m_hDC
, prevBkCol
); // restore colours to original values
1240 ::SetTextColor((HDC
) m_hDC
, prevCol
);
1242 // OR buffer to dest
1243 success
= (::BitBlt((HDC
) m_hDC
, xdest1
, ydest1
, (int)width
, (int)height
,
1244 dc_buffer
, 0, 0, SRCPAINT
) != 0);
1246 // tidy up temporary DCs and bitmap
1247 ::SelectObject(dc_mask
, 0);
1248 ::DeleteDC(dc_mask
);
1249 ::SelectObject(dc_buffer
, 0);
1250 ::DeleteDC(dc_buffer
);
1251 ::DeleteObject(buffer_bmap
);
1256 success
= (BitBlt((HDC
) m_hDC
, xdest1
, ydest1
, (int)width
, (int)height
, (HDC
) source
->m_hDC
,
1257 xsrc1
, ysrc1
, dwRop
) != 0);
1259 ::SetTextColor((HDC
)m_hDC
, old_textground
);
1260 ::SetBkColor((HDC
)m_hDC
, old_background
);
1265 void wxDC::GetSize(int* width
, int* height
) const
1267 long w
=::GetDeviceCaps((HDC
) m_hDC
,HORZRES
);
1268 long h
=::GetDeviceCaps((HDC
) m_hDC
,VERTRES
);
1273 void wxDC::GetSizeMM(long *width
, long *height
) const
1275 long w
=::GetDeviceCaps((HDC
) m_hDC
,HORZSIZE
);
1276 long h
=::GetDeviceCaps((HDC
) m_hDC
,VERTSIZE
);
1282 #include "xfspline.inc"
1283 #endif // USE_SPLINES
1285 void wxDC::DrawPolygon(wxList
*list
, long xoffset
, long yoffset
,int fillStyle
)
1287 int n
= list
->Number();
1288 wxPoint
*points
= new wxPoint
[n
];
1291 for(wxNode
*node
= list
->First(); node
; node
= node
->Next()) {
1292 wxPoint
*point
= (wxPoint
*)node
->Data();
1293 points
[i
].x
= point
->x
;
1294 points
[i
++].y
= point
->y
;
1296 DrawPolygon(n
, points
, xoffset
, yoffset
,fillStyle
);
1300 void wxDC::DrawLines(wxList
*list
, long xoffset
, long yoffset
)
1302 int n
= list
->Number();
1303 wxPoint
*points
= new wxPoint
[n
];
1306 for(wxNode
*node
= list
->First(); node
; node
= node
->Next()) {
1307 wxPoint
*point
= (wxPoint
*)node
->Data();
1308 points
[i
].x
= point
->x
;
1309 points
[i
++].y
= point
->y
;
1311 DrawLines(n
, points
, xoffset
, yoffset
);
1315 void wxDC::SetTextForeground(const wxColour
& colour
)
1317 m_textForegroundColour
= colour
;
1320 void wxDC::SetTextBackground(const wxColour
& colour
)
1322 m_textBackgroundColour
= colour
;
1326 // Make a 3-point spline
1327 void wxDC::DrawSpline(long x1
, long y1
, long x2
, long y2
, long x3
, long y3
)
1329 wxList
*point_list
= new wxList
;
1331 wxPoint
*point1
= new wxPoint
;
1332 point1
->x
= x1
; point1
->y
= y1
;
1333 point_list
->Append((wxObject
*)point1
);
1335 wxPoint
*point2
= new wxPoint
;
1336 point2
->x
= x2
; point2
->y
= y2
;
1337 point_list
->Append((wxObject
*)point2
);
1339 wxPoint
*point3
= new wxPoint
;
1340 point3
->x
= x3
; point3
->y
= y3
;
1341 point_list
->Append((wxObject
*)point3
);
1343 DrawSpline(point_list
);
1345 for(wxNode
*node
= point_list
->First(); node
; node
= node
->Next()) {
1346 wxPoint
*p
= (wxPoint
*)node
->Data();
1353 // For use by wxWindows only, unless custom units are required.
1354 void wxDC::SetLogicalScale(double x
, double y
)
1356 m_logicalScaleX
= x
;
1357 m_logicalScaleY
= y
;
1360 void wxDC::CalcBoundingBox(long x
, long y
)
1362 if (x
< m_minX
) m_minX
= x
;
1363 if (y
< m_minY
) m_minY
= y
;
1364 if (x
> m_maxX
) m_maxX
= x
;
1365 if (y
> m_maxY
) m_maxY
= y
;
1368 void wxDC::GetClippingBox(long *x
,long *y
,long *w
,long *h
) const
1374 *w
= (m_clipX2
- m_clipX1
) ;
1375 *h
= (m_clipY2
- m_clipY1
) ;
1378 *x
= *y
= *w
= *h
= 0 ;
1381 #if WXWIN_COMPATIBILITY
1382 void wxDC::GetTextExtent(const wxString
& string
, float *x
, float *y
,
1383 float *descent
, float *externalLeading
,
1384 wxFont
*theFont
, bool use16bit
) const
1386 long x1
, y1
, descent1
, externalLeading1
;
1387 GetTextExtent(string
, & x1
, & y1
, & descent1
, & externalLeading1
, theFont
, use16bit
);
1390 *descent
= descent1
;
1391 if (externalLeading
)
1392 *externalLeading
= externalLeading1
;