]>
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 #if !USE_SHARED_LIBRARY
45 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC
, wxDC
)
48 // ============================================================================
50 // ============================================================================
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 wxMemoryDC::wxMemoryDC()
58 m_hDC
= (WXHDC
) ::CreateCompatibleDC((HDC
) NULL
);
62 SetBrush(*wxWHITE_BRUSH
);
65 // the background mode is only used for text background and is set in
66 // DrawText() to OPAQUE as required, otherwise always TRANSPARENT
67 ::SetBkMode( GetHdc(), TRANSPARENT
);
70 wxMemoryDC::wxMemoryDC(wxDC
*old_dc
)
72 old_dc
->BeginDrawing();
74 m_hDC
= (WXHDC
) ::CreateCompatibleDC(GetHdcOf(*old_dc
));
79 SetBrush(*wxWHITE_BRUSH
);
82 // the background mode is only used for text background and is set in
83 // DrawText() to OPAQUE as required, otherwise always TRANSPARENT
84 ::SetBkMode( GetHdc(), TRANSPARENT
);
87 wxMemoryDC::~wxMemoryDC()
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() )
99 m_selectedBitmap
.SetSelectedInto(NULL
);
100 m_selectedBitmap
= wxNullBitmap
;
104 // check for whether the bitmap is already selected into a device context
105 wxCHECK_RET( !bitmap
.GetSelectedInto() ||
106 (bitmap
.GetSelectedInto() == this),
107 wxT("Bitmap is selected in another wxMemoryDC, delete the "
108 "first wxMemoryDC or use SelectObject(NULL)") );
110 m_selectedBitmap
= bitmap
;
111 WXHBITMAP hBmp
= m_selectedBitmap
.GetHBITMAP();
115 m_selectedBitmap
.SetSelectedInto(this);
116 hBmp
= (WXHBITMAP
)::SelectObject(GetHdc(), (HBITMAP
)hBmp
);
120 wxLogLastError("SelectObject(memDC, bitmap)");
122 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
124 else if ( !m_oldBitmap
)
130 void wxMemoryDC::DoGetSize(int *width
, int *height
) const
132 if ( m_selectedBitmap
.Ok() )
134 *width
= m_selectedBitmap
.GetWidth();
135 *height
= m_selectedBitmap
.GetHeight();