]>
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(wxDC
*dc
)
52 wxCHECK_RET( dc
, _T("NULL dc in wxMemoryDC ctor") );
59 void wxMemoryDC::Init()
63 SetBrush(*wxWHITE_BRUSH
);
66 // the background mode is only used for text background and is set in
67 // DrawText() to OPAQUE as required, otherwise always TRANSPARENT
68 ::SetBkMode( GetHdc(), TRANSPARENT
);
72 bool wxMemoryDC::CreateCompatible(wxDC
*dc
)
74 m_hDC
= (WXHDC
)::CreateCompatibleDC(dc
? GetHdcOf(*dc
) : NULL
);
76 // as we created the DC, we must delete it in the dtor
84 void wxMemoryDC::DoSelect( const wxBitmap
& bitmap
)
86 // select old bitmap out of the device context
89 ::SelectObject(GetHdc(), (HBITMAP
) m_oldBitmap
);
90 if ( m_selectedBitmap
.Ok() )
93 m_selectedBitmap
.SetSelectedInto(NULL
);
95 m_selectedBitmap
= wxNullBitmap
;
99 // check for whether the bitmap is already selected into a device context
100 wxASSERT_MSG( !bitmap
.GetSelectedInto() ||
101 (bitmap
.GetSelectedInto() == this),
102 wxT("Bitmap is selected in another wxMemoryDC, delete the first wxMemoryDC or use SelectObject(NULL)") );
104 m_selectedBitmap
= bitmap
;
105 WXHBITMAP hBmp
= m_selectedBitmap
.GetHBITMAP();
110 m_selectedBitmap
.SetSelectedInto(this);
112 hBmp
= (WXHBITMAP
)::SelectObject(GetHdc(), (HBITMAP
)hBmp
);
116 wxLogLastError(wxT("SelectObject(memDC, bitmap)"));
118 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
120 else if ( !m_oldBitmap
)
126 void wxMemoryDC::DoGetSize(int *width
, int *height
) const
128 if ( m_selectedBitmap
.Ok() )
130 *width
= m_selectedBitmap
.GetWidth();
131 *height
= m_selectedBitmap
.GetHeight();
140 // the rest of this file deals with drawing rectangles workaround, disabled by
143 #define wxUSE_MEMORY_DC_DRAW_RECTANGLE 0
145 #if wxUSE_MEMORY_DC_DRAW_RECTANGLE
147 // For some reason, drawing a rectangle on a memory DC has problems.
148 // Use this substitute if we can.
149 static void wxDrawRectangle(wxDC
& dc
, wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
151 wxBrush
brush(dc
.GetBrush());
152 wxPen
pen(dc
.GetPen());
153 if (brush
.Ok() && brush
.GetStyle() != wxTRANSPARENT
)
155 HBRUSH hBrush
= (HBRUSH
) brush
.GetResourceHandle() ;
159 rect
.left
= x
; rect
.top
= y
;
160 rect
.right
= x
+ width
- 1;
161 rect
.bottom
= y
+ height
- 1;
162 ::FillRect((HDC
) dc
.GetHDC(), &rect
, hBrush
);
166 if (pen
.Ok() && pen
.GetStyle() != wxTRANSPARENT
)
168 dc
.DrawLine(x
, y
, x
+ width
, y
);
169 dc
.DrawLine(x
, y
, x
, y
+ height
);
170 dc
.DrawLine(x
, y
+height
, x
+width
, y
+ height
);
171 dc
.DrawLine(x
+width
, y
+height
, x
+width
, y
);
175 #endif // wxUSE_MEMORY_DC_DRAW_RECTANGLE
177 void wxMemoryDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
179 // Set this to 1 to work around an apparent video driver bug
180 // (visible with e.g. 70x70 rectangle on a memory DC; see Drawing sample)
181 #if wxUSE_MEMORY_DC_DRAW_RECTANGLE
182 if (m_brush
.Ok() && m_pen
.Ok() &&
183 (m_brush
.GetStyle() == wxSOLID
|| m_brush
.GetStyle() == wxTRANSPARENT
) &&
184 (m_pen
.GetStyle() == wxSOLID
|| m_pen
.GetStyle() == wxTRANSPARENT
) &&
185 (GetLogicalFunction() == wxCOPY
))
187 wxDrawRectangle(* this, x
, y
, width
, height
);
190 #endif // wxUSE_MEMORY_DC_DRAW_RECTANGLE
192 wxDC::DoDrawRectangle(x
, y
, width
, height
);