]>
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
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 CreateCompatible(NULL
);
61 wxMemoryDC::wxMemoryDC(wxDC
*dc
)
63 wxCHECK_RET( dc
, _T("NULL dc in wxMemoryDC ctor") );
74 void wxMemoryDC::Init()
78 SetBrush(*wxWHITE_BRUSH
);
81 // the background mode is only used for text background and is set in
82 // DrawText() to OPAQUE as required, otherwise always TRANSPARENT
83 ::SetBkMode( GetHdc(), TRANSPARENT
);
87 bool wxMemoryDC::CreateCompatible(wxDC
*dc
)
89 m_hDC
= (WXHDC
)::CreateCompatibleDC(dc
? GetHdcOf(*dc
) : NULL
);
91 // as we created the DC, we must delete it in the dtor
99 void wxMemoryDC::SelectObject(const wxBitmap
& bitmap
)
101 // select old bitmap out of the device context
104 ::SelectObject(GetHdc(), (HBITMAP
) m_oldBitmap
);
105 if ( m_selectedBitmap
.Ok() )
108 m_selectedBitmap
.SetSelectedInto(NULL
);
110 m_selectedBitmap
= wxNullBitmap
;
114 // check for whether the bitmap is already selected into a device context
115 wxASSERT_MSG( !bitmap
.GetSelectedInto() ||
116 (bitmap
.GetSelectedInto() == this),
117 wxT("Bitmap is selected in another wxMemoryDC, delete the first wxMemoryDC or use SelectObject(NULL)") );
119 m_selectedBitmap
= bitmap
;
120 WXHBITMAP hBmp
= m_selectedBitmap
.GetHBITMAP();
125 m_selectedBitmap
.SetSelectedInto(this);
127 hBmp
= (WXHBITMAP
)::SelectObject(GetHdc(), (HBITMAP
)hBmp
);
131 wxLogLastError(wxT("SelectObject(memDC, bitmap)"));
133 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
135 else if ( !m_oldBitmap
)
141 void wxMemoryDC::DoGetSize(int *width
, int *height
) const
143 if ( m_selectedBitmap
.Ok() )
145 *width
= m_selectedBitmap
.GetWidth();
146 *height
= m_selectedBitmap
.GetHeight();
155 // the rest of this file deals with drawing rectangles workaround, disabled by
158 #define wxUSE_MEMORY_DC_DRAW_RECTANGLE 0
160 #if wxUSE_MEMORY_DC_DRAW_RECTANGLE
162 // For some reason, drawing a rectangle on a memory DC has problems.
163 // Use this substitute if we can.
164 static void wxDrawRectangle(wxDC
& dc
, wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
166 wxBrush
brush(dc
.GetBrush());
167 wxPen
pen(dc
.GetPen());
168 if (brush
.Ok() && brush
.GetStyle() != wxTRANSPARENT
)
170 HBRUSH hBrush
= (HBRUSH
) brush
.GetResourceHandle() ;
174 rect
.left
= x
; rect
.top
= y
;
175 rect
.right
= x
+ width
- 1;
176 rect
.bottom
= y
+ height
- 1;
177 ::FillRect((HDC
) dc
.GetHDC(), &rect
, hBrush
);
181 if (pen
.Ok() && pen
.GetStyle() != wxTRANSPARENT
)
183 dc
.DrawLine(x
, y
, x
+ width
, y
);
184 dc
.DrawLine(x
, y
, x
, y
+ height
);
185 dc
.DrawLine(x
, y
+height
, x
+width
, y
+ height
);
186 dc
.DrawLine(x
+width
, y
+height
, x
+width
, y
);
190 #endif // wxUSE_MEMORY_DC_DRAW_RECTANGLE
192 void wxMemoryDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
194 // Set this to 1 to work around an apparent video driver bug
195 // (visible with e.g. 70x70 rectangle on a memory DC; see Drawing sample)
196 #if wxUSE_MEMORY_DC_DRAW_RECTANGLE
197 if (m_brush
.Ok() && m_pen
.Ok() &&
198 (m_brush
.GetStyle() == wxSOLID
|| m_brush
.GetStyle() == wxTRANSPARENT
) &&
199 (m_pen
.GetStyle() == wxSOLID
|| m_pen
.GetStyle() == wxTRANSPARENT
) &&
200 (GetLogicalFunction() == wxCOPY
))
202 wxDrawRectangle(* this, x
, y
, width
, height
);
205 #endif // wxUSE_MEMORY_DC_DRAW_RECTANGLE
207 wxDC::DoDrawRectangle(x
, y
, width
, height
);