]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/dcmemory.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMemoryDC class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "dcmemory.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
36 #include "wx/msw/private.h"
38 #include "wx/dcmemory.h"
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC
, wxDC
)
46 // ============================================================================
48 // ============================================================================
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 wxMemoryDC::wxMemoryDC()
56 m_hDC
= (WXHDC
) ::CreateCompatibleDC((HDC
) NULL
);
60 SetBrush(*wxWHITE_BRUSH
);
63 // the background mode is only used for text background and is set in
64 // DrawText() to OPAQUE as required, otherwise always TRANSPARENT
65 ::SetBkMode( GetHdc(), TRANSPARENT
);
68 wxMemoryDC::wxMemoryDC(wxDC
*old_dc
)
70 old_dc
->BeginDrawing();
72 m_hDC
= (WXHDC
) ::CreateCompatibleDC(GetHdcOf(*old_dc
));
77 SetBrush(*wxWHITE_BRUSH
);
80 // the background mode is only used for text background and is set in
81 // DrawText() to OPAQUE as required, otherwise always TRANSPARENT
82 ::SetBkMode( GetHdc(), TRANSPARENT
);
85 wxMemoryDC::~wxMemoryDC()
89 void wxMemoryDC::SelectObject(const wxBitmap
& bitmap
)
91 // select old bitmap out of the device context
94 ::SelectObject(GetHdc(), (HBITMAP
) m_oldBitmap
);
95 if ( m_selectedBitmap
.Ok() )
97 m_selectedBitmap
.SetSelectedInto(NULL
);
98 m_selectedBitmap
= wxNullBitmap
;
102 // check for whether the bitmap is already selected into a device context
103 wxCHECK_RET( !bitmap
.GetSelectedInto() ||
104 (bitmap
.GetSelectedInto() == this),
105 wxT("Bitmap is selected in another wxMemoryDC, delete the "
106 "first wxMemoryDC or use SelectObject(NULL)") );
108 m_selectedBitmap
= bitmap
;
109 WXHBITMAP hBmp
= m_selectedBitmap
.GetHBITMAP();
113 m_selectedBitmap
.SetSelectedInto(this);
114 hBmp
= (WXHBITMAP
)::SelectObject(GetHdc(), (HBITMAP
)hBmp
);
118 wxLogLastError("SelectObject(memDC, bitmap)");
120 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
122 else if ( !m_oldBitmap
)
128 void wxMemoryDC::DoGetSize(int *width
, int *height
) const
130 if ( m_selectedBitmap
.Ok() )
132 *width
= m_selectedBitmap
.GetWidth();
133 *height
= m_selectedBitmap
.GetHeight();
142 // the rest of this file deals with drawing rectangles workaround, disabled by
145 #define wxUSE_MEMORY_DC_DRAW_RECTANGLE 0
147 #if wxUSE_MEMORY_DC_DRAW_RECTANGLE
149 // For some reason, drawing a rectangle on a memory DC has problems.
150 // Use this substitute if we can.
151 static void wxDrawRectangle(wxDC
& dc
, wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
153 wxBrush
brush(dc
.GetBrush());
154 wxPen
pen(dc
.GetPen());
155 if (brush
.Ok() && brush
.GetStyle() != wxTRANSPARENT
)
157 HBRUSH hBrush
= (HBRUSH
) brush
.GetResourceHandle() ;
161 rect
.left
= x
; rect
.top
= y
;
162 rect
.right
= x
+ width
- 1;
163 rect
.bottom
= y
+ height
- 1;
164 ::FillRect((HDC
) dc
.GetHDC(), &rect
, hBrush
);
168 if (pen
.Ok() && pen
.GetStyle() != wxTRANSPARENT
)
170 dc
.DrawLine(x
, y
, x
+ width
, y
);
171 dc
.DrawLine(x
, y
, x
, y
+ height
);
172 dc
.DrawLine(x
, y
+height
, x
+width
, y
+ height
);
173 dc
.DrawLine(x
+width
, y
+height
, x
+width
, y
);
177 #endif // wxUSE_MEMORY_DC_DRAW_RECTANGLE
179 void wxMemoryDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
181 // Set this to 1 to work around an apparent video driver bug
182 // (visible with e.g. 70x70 rectangle on a memory DC; see Drawing sample)
183 #if wxUSE_MEMORY_DC_DRAW_RECTANGLE
184 if (m_brush
.Ok() && m_pen
.Ok() &&
185 (m_brush
.GetStyle() == wxSOLID
|| m_brush
.GetStyle() == wxTRANSPARENT
) &&
186 (m_pen
.GetStyle() == wxSOLID
|| m_pen
.GetStyle() == wxTRANSPARENT
) &&
187 (GetLogicalFunction() == wxCOPY
))
189 wxDrawRectangle(* this, x
, y
, width
, height
);
192 #endif // wxUSE_MEMORY_DC_DRAW_RECTANGLE
194 wxDC::DoDrawRectangle(x
, y
, width
, height
);