]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/dcmemory.cpp
1ad90bbb837e0b5da9dea832b1484548d0bcbb82
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/dcmemory.cpp
3 // Purpose: wxMemoryDC class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/dcmemory.h"
28 #include "wx/msw/dcmemory.h"
35 #include "wx/msw/private.h"
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 IMPLEMENT_ABSTRACT_CLASS(wxMemoryDCImpl
, wxMSWDCImpl
)
43 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC
*owner
)
44 : wxMSWDCImpl( owner
)
46 CreateCompatible(NULL
);
50 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC
*owner
, wxBitmap
& bitmap
)
51 : wxMSWDCImpl( owner
)
53 CreateCompatible(NULL
);
58 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC
*owner
, wxDC
*dc
)
59 : wxMSWDCImpl( owner
)
61 wxCHECK_RET( dc
, _T("NULL dc in wxMemoryDC ctor") );
68 void wxMemoryDCImpl::Init()
72 SetBrush(*wxWHITE_BRUSH
);
75 // the background mode is only used for text background and is set in
76 // DrawText() to OPAQUE as required, otherwise always TRANSPARENT
77 ::SetBkMode( GetHdc(), TRANSPARENT
);
81 bool wxMemoryDCImpl::CreateCompatible(wxDC
*dc
)
83 wxDCImpl
*impl
= dc
->GetImpl();
84 wxMSWDCImpl
*msw_impl
= wxDynamicCast( impl
, wxMSWDCImpl
);
91 m_hDC
= (WXHDC
)::CreateCompatibleDC(dc
? GetHdcOf(*msw_impl
) : NULL
);
93 // as we created the DC, we must delete it in the dtor
101 void wxMemoryDCImpl::DoSelect( const wxBitmap
& bitmap
)
103 // select old bitmap out of the device context
106 ::SelectObject(GetHdc(), (HBITMAP
) m_oldBitmap
);
107 if ( m_selectedBitmap
.Ok() )
110 m_selectedBitmap
.SetSelectedInto(NULL
);
112 m_selectedBitmap
= wxNullBitmap
;
116 // check for whether the bitmap is already selected into a device context
117 wxASSERT_MSG( !bitmap
.GetSelectedInto() ||
118 (bitmap
.GetSelectedInto() == GetOwner()),
119 wxT("Bitmap is selected in another wxMemoryDC, delete the first wxMemoryDC or use SelectObject(NULL)") );
121 m_selectedBitmap
= bitmap
;
122 WXHBITMAP hBmp
= m_selectedBitmap
.GetHBITMAP();
127 m_selectedBitmap
.SetSelectedInto(GetOwner());
129 hBmp
= (WXHBITMAP
)::SelectObject(GetHdc(), (HBITMAP
)hBmp
);
133 wxLogLastError(wxT("SelectObject(memDC, bitmap)"));
135 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
137 else if ( !m_oldBitmap
)
143 void wxMemoryDCImpl::DoGetSize(int *width
, int *height
) const
145 if ( m_selectedBitmap
.Ok() )
147 *width
= m_selectedBitmap
.GetWidth();
148 *height
= m_selectedBitmap
.GetHeight();
157 // the rest of this file deals with drawing rectangles workaround, disabled by
160 #define wxUSE_MEMORY_DC_DRAW_RECTANGLE 0
162 #if wxUSE_MEMORY_DC_DRAW_RECTANGLE
164 // For some reason, drawing a rectangle on a memory DC has problems.
165 // Use this substitute if we can.
166 static void wxDrawRectangle(wxDC
& dc
, wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
168 wxBrush
brush(dc
.GetBrush());
169 wxPen
pen(dc
.GetPen());
170 if (brush
.Ok() && brush
.GetStyle() != wxTRANSPARENT
)
172 HBRUSH hBrush
= (HBRUSH
) brush
.GetResourceHandle() ;
176 rect
.left
= x
; rect
.top
= y
;
177 rect
.right
= x
+ width
- 1;
178 rect
.bottom
= y
+ height
- 1;
179 ::FillRect((HDC
) dc
.GetHDC(), &rect
, hBrush
);
183 if (pen
.Ok() && pen
.GetStyle() != wxTRANSPARENT
)
185 dc
.DrawLine(x
, y
, x
+ width
, y
);
186 dc
.DrawLine(x
, y
, x
, y
+ height
);
187 dc
.DrawLine(x
, y
+height
, x
+width
, y
+ height
);
188 dc
.DrawLine(x
+width
, y
+height
, x
+width
, y
);
192 #endif // wxUSE_MEMORY_DC_DRAW_RECTANGLE
194 void wxMemoryDCImpl::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
196 // Set this to 1 to work around an apparent video driver bug
197 // (visible with e.g. 70x70 rectangle on a memory DC; see Drawing sample)
198 #if wxUSE_MEMORY_DC_DRAW_RECTANGLE
199 if (m_brush
.Ok() && m_pen
.Ok() &&
200 (m_brush
.GetStyle() == wxSOLID
|| m_brush
.GetStyle() == wxTRANSPARENT
) &&
201 (m_pen
.GetStyle() == wxSOLID
|| m_pen
.GetStyle() == wxTRANSPARENT
) &&
202 (GetLogicalFunction() == wxCOPY
))
204 wxDrawRectangle(* this, x
, y
, width
, height
);
207 #endif // wxUSE_MEMORY_DC_DRAW_RECTANGLE
209 wxMSWDCImpl::DoDrawRectangle(x
, y
, width
, height
);