]>
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 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() )
107 m_selectedBitmap
.SetSelectedInto(NULL
);
108 m_selectedBitmap
= wxNullBitmap
;
112 // check for whether the bitmap is already selected into a device context
113 wxASSERT_MSG( !bitmap
.GetSelectedInto() ||
114 (bitmap
.GetSelectedInto() == this),
115 wxT("Bitmap is selected in another wxMemoryDC, delete the first wxMemoryDC or use SelectObject(NULL)") );
117 m_selectedBitmap
= bitmap
;
118 WXHBITMAP hBmp
= m_selectedBitmap
.GetHBITMAP();
122 m_selectedBitmap
.SetSelectedInto(this);
123 hBmp
= (WXHBITMAP
)::SelectObject(GetHdc(), (HBITMAP
)hBmp
);
127 wxLogLastError(wxT("SelectObject(memDC, bitmap)"));
129 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
131 else if ( !m_oldBitmap
)
137 void wxMemoryDC::DoGetSize(int *width
, int *height
) const
139 if ( m_selectedBitmap
.Ok() )
141 *width
= m_selectedBitmap
.GetWidth();
142 *height
= m_selectedBitmap
.GetHeight();
151 // the rest of this file deals with drawing rectangles workaround, disabled by
154 #define wxUSE_MEMORY_DC_DRAW_RECTANGLE 0
156 #if wxUSE_MEMORY_DC_DRAW_RECTANGLE
158 // For some reason, drawing a rectangle on a memory DC has problems.
159 // Use this substitute if we can.
160 static void wxDrawRectangle(wxDC
& dc
, wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
162 wxBrush
brush(dc
.GetBrush());
163 wxPen
pen(dc
.GetPen());
164 if (brush
.Ok() && brush
.GetStyle() != wxTRANSPARENT
)
166 HBRUSH hBrush
= (HBRUSH
) brush
.GetResourceHandle() ;
170 rect
.left
= x
; rect
.top
= y
;
171 rect
.right
= x
+ width
- 1;
172 rect
.bottom
= y
+ height
- 1;
173 ::FillRect((HDC
) dc
.GetHDC(), &rect
, hBrush
);
177 if (pen
.Ok() && pen
.GetStyle() != wxTRANSPARENT
)
179 dc
.DrawLine(x
, y
, x
+ width
, y
);
180 dc
.DrawLine(x
, y
, x
, y
+ height
);
181 dc
.DrawLine(x
, y
+height
, x
+width
, y
+ height
);
182 dc
.DrawLine(x
+width
, y
+height
, x
+width
, y
);
186 #endif // wxUSE_MEMORY_DC_DRAW_RECTANGLE
188 void wxMemoryDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
190 // Set this to 1 to work around an apparent video driver bug
191 // (visible with e.g. 70x70 rectangle on a memory DC; see Drawing sample)
192 #if wxUSE_MEMORY_DC_DRAW_RECTANGLE
193 if (m_brush
.Ok() && m_pen
.Ok() &&
194 (m_brush
.GetStyle() == wxSOLID
|| m_brush
.GetStyle() == wxTRANSPARENT
) &&
195 (m_pen
.GetStyle() == wxSOLID
|| m_pen
.GetStyle() == wxTRANSPARENT
) &&
196 (GetLogicalFunction() == wxCOPY
))
198 wxDrawRectangle(* this, x
, y
, width
, height
);
201 #endif // wxUSE_MEMORY_DC_DRAW_RECTANGLE
203 wxDC::DoDrawRectangle(x
, y
, width
, height
);