]>
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()
52 CreateCompatible(NULL
);
57 wxMemoryDC::wxMemoryDC(wxDC
*dc
)
59 wxCHECK_RET( dc
, _T("NULL dc in wxMemoryDC ctor") );
66 void wxMemoryDC::Init()
70 SetBrush(*wxWHITE_BRUSH
);
73 // the background mode is only used for text background and is set in
74 // DrawText() to OPAQUE as required, otherwise always TRANSPARENT
75 ::SetBkMode( GetHdc(), TRANSPARENT
);
79 bool wxMemoryDC::CreateCompatible(wxDC
*dc
)
81 m_hDC
= (WXHDC
)::CreateCompatibleDC(dc
? GetHdcOf(*dc
) : NULL
);
83 // as we created the DC, we must delete it in the dtor
91 void wxMemoryDC::SelectObject(const wxBitmap
& bitmap
)
93 // select old bitmap out of the device context
96 ::SelectObject(GetHdc(), (HBITMAP
) m_oldBitmap
);
97 if ( m_selectedBitmap
.Ok() )
100 m_selectedBitmap
.SetSelectedInto(NULL
);
102 m_selectedBitmap
= wxNullBitmap
;
106 // check for whether the bitmap is already selected into a device context
107 wxASSERT_MSG( !bitmap
.GetSelectedInto() ||
108 (bitmap
.GetSelectedInto() == this),
109 wxT("Bitmap is selected in another wxMemoryDC, delete the first wxMemoryDC or use SelectObject(NULL)") );
111 m_selectedBitmap
= bitmap
;
112 WXHBITMAP hBmp
= m_selectedBitmap
.GetHBITMAP();
117 m_selectedBitmap
.SetSelectedInto(this);
119 hBmp
= (WXHBITMAP
)::SelectObject(GetHdc(), (HBITMAP
)hBmp
);
123 wxLogLastError(wxT("SelectObject(memDC, bitmap)"));
125 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
127 else if ( !m_oldBitmap
)
133 void wxMemoryDC::DoGetSize(int *width
, int *height
) const
135 if ( m_selectedBitmap
.Ok() )
137 *width
= m_selectedBitmap
.GetWidth();
138 *height
= m_selectedBitmap
.GetHeight();
147 // the rest of this file deals with drawing rectangles workaround, disabled by
150 #define wxUSE_MEMORY_DC_DRAW_RECTANGLE 0
152 #if wxUSE_MEMORY_DC_DRAW_RECTANGLE
154 // For some reason, drawing a rectangle on a memory DC has problems.
155 // Use this substitute if we can.
156 static void wxDrawRectangle(wxDC
& dc
, wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
158 wxBrush
brush(dc
.GetBrush());
159 wxPen
pen(dc
.GetPen());
160 if (brush
.Ok() && brush
.GetStyle() != wxTRANSPARENT
)
162 HBRUSH hBrush
= (HBRUSH
) brush
.GetResourceHandle() ;
166 rect
.left
= x
; rect
.top
= y
;
167 rect
.right
= x
+ width
- 1;
168 rect
.bottom
= y
+ height
- 1;
169 ::FillRect((HDC
) dc
.GetHDC(), &rect
, hBrush
);
173 if (pen
.Ok() && pen
.GetStyle() != wxTRANSPARENT
)
175 dc
.DrawLine(x
, y
, x
+ width
, y
);
176 dc
.DrawLine(x
, y
, x
, y
+ height
);
177 dc
.DrawLine(x
, y
+height
, x
+width
, y
+ height
);
178 dc
.DrawLine(x
+width
, y
+height
, x
+width
, y
);
182 #endif // wxUSE_MEMORY_DC_DRAW_RECTANGLE
184 void wxMemoryDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
186 // Set this to 1 to work around an apparent video driver bug
187 // (visible with e.g. 70x70 rectangle on a memory DC; see Drawing sample)
188 #if wxUSE_MEMORY_DC_DRAW_RECTANGLE
189 if (m_brush
.Ok() && m_pen
.Ok() &&
190 (m_brush
.GetStyle() == wxSOLID
|| m_brush
.GetStyle() == wxTRANSPARENT
) &&
191 (m_pen
.GetStyle() == wxSOLID
|| m_pen
.GetStyle() == wxTRANSPARENT
) &&
192 (GetLogicalFunction() == wxCOPY
))
194 wxDrawRectangle(* this, x
, y
, width
, height
);
197 #endif // wxUSE_MEMORY_DC_DRAW_RECTANGLE
199 wxDC::DoDrawRectangle(x
, y
, width
, height
);