]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/dcmemory.cpp
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"
34 #include "wx/msw/private.h"
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
40 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC
, wxDC
)
42 // ============================================================================
44 // ============================================================================
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 wxMemoryDC::wxMemoryDC( const wxBitmap
& bitmap
)
52 CreateCompatible(NULL
);
60 wxMemoryDC::wxMemoryDC(wxDC
*dc
)
62 wxCHECK_RET( dc
, _T("NULL dc in wxMemoryDC ctor") );
69 void wxMemoryDC::Init()
73 SetBrush(*wxWHITE_BRUSH
);
76 // the background mode is only used for text background and is set in
77 // DrawText() to OPAQUE as required, otherwise always TRANSPARENT
78 ::SetBkMode( GetHdc(), TRANSPARENT
);
82 bool wxMemoryDC::CreateCompatible(wxDC
*dc
)
84 m_hDC
= (WXHDC
)::CreateCompatibleDC(dc
? GetHdcOf(*dc
) : NULL
);
86 // as we created the DC, we must delete it in the dtor
94 void wxMemoryDC::SelectObject(const wxBitmap
& bitmap
)
96 // select old bitmap out of the device context
99 ::SelectObject(GetHdc(), (HBITMAP
) m_oldBitmap
);
100 if ( m_selectedBitmap
.Ok() )
103 m_selectedBitmap
.SetSelectedInto(NULL
);
105 m_selectedBitmap
= wxNullBitmap
;
109 // check for whether the bitmap is already selected into a device context
110 wxASSERT_MSG( !bitmap
.GetSelectedInto() ||
111 (bitmap
.GetSelectedInto() == this),
112 wxT("Bitmap is selected in another wxMemoryDC, delete the first wxMemoryDC or use SelectObject(NULL)") );
114 m_selectedBitmap
= bitmap
;
115 WXHBITMAP hBmp
= m_selectedBitmap
.GetHBITMAP();
120 m_selectedBitmap
.SetSelectedInto(this);
122 hBmp
= (WXHBITMAP
)::SelectObject(GetHdc(), (HBITMAP
)hBmp
);
126 wxLogLastError(wxT("SelectObject(memDC, bitmap)"));
128 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
130 else if ( !m_oldBitmap
)
136 void wxMemoryDC::DoGetSize(int *width
, int *height
) const
138 if ( m_selectedBitmap
.Ok() )
140 *width
= m_selectedBitmap
.GetWidth();
141 *height
= m_selectedBitmap
.GetHeight();
150 // the rest of this file deals with drawing rectangles workaround, disabled by
153 #define wxUSE_MEMORY_DC_DRAW_RECTANGLE 0
155 #if wxUSE_MEMORY_DC_DRAW_RECTANGLE
157 // For some reason, drawing a rectangle on a memory DC has problems.
158 // Use this substitute if we can.
159 static void wxDrawRectangle(wxDC
& dc
, wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
161 wxBrush
brush(dc
.GetBrush());
162 wxPen
pen(dc
.GetPen());
163 if (brush
.Ok() && brush
.GetStyle() != wxTRANSPARENT
)
165 HBRUSH hBrush
= (HBRUSH
) brush
.GetResourceHandle() ;
169 rect
.left
= x
; rect
.top
= y
;
170 rect
.right
= x
+ width
- 1;
171 rect
.bottom
= y
+ height
- 1;
172 ::FillRect((HDC
) dc
.GetHDC(), &rect
, hBrush
);
176 if (pen
.Ok() && pen
.GetStyle() != wxTRANSPARENT
)
178 dc
.DrawLine(x
, y
, x
+ width
, y
);
179 dc
.DrawLine(x
, y
, x
, y
+ height
);
180 dc
.DrawLine(x
, y
+height
, x
+width
, y
+ height
);
181 dc
.DrawLine(x
+width
, y
+height
, x
+width
, y
);
185 #endif // wxUSE_MEMORY_DC_DRAW_RECTANGLE
187 void wxMemoryDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
189 // Set this to 1 to work around an apparent video driver bug
190 // (visible with e.g. 70x70 rectangle on a memory DC; see Drawing sample)
191 #if wxUSE_MEMORY_DC_DRAW_RECTANGLE
192 if (m_brush
.Ok() && m_pen
.Ok() &&
193 (m_brush
.GetStyle() == wxSOLID
|| m_brush
.GetStyle() == wxTRANSPARENT
) &&
194 (m_pen
.GetStyle() == wxSOLID
|| m_pen
.GetStyle() == wxTRANSPARENT
) &&
195 (GetLogicalFunction() == wxCOPY
))
197 wxDrawRectangle(* this, x
, y
, width
, height
);
200 #endif // wxUSE_MEMORY_DC_DRAW_RECTANGLE
202 wxDC::DoDrawRectangle(x
, y
, width
, height
);