]>
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"
35 #include "wx/msw/private.h"
37 #include "wx/dcmemory.h"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 #if !USE_SHARED_LIBRARY
44 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC
, wxDC
)
47 // ============================================================================
49 // ============================================================================
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 wxMemoryDC::wxMemoryDC()
57 m_hDC
= (WXHDC
) ::CreateCompatibleDC((HDC
) NULL
);
61 SetBrush(*wxWHITE_BRUSH
);
64 // the background mode is only used for text background and is set in
65 // DrawText() to OPAQUE as required, otherwise always TRANSPARENT
66 ::SetBkMode( GetHdc(), TRANSPARENT
);
69 wxMemoryDC::wxMemoryDC(wxDC
*old_dc
)
71 old_dc
->BeginDrawing();
73 m_hDC
= (WXHDC
) ::CreateCompatibleDC(GetHdcOf(*old_dc
));
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
);
86 wxMemoryDC::~wxMemoryDC()
90 void wxMemoryDC::SelectObject(const wxBitmap
& bitmap
)
92 // select old bitmap out of the device context
95 ::SelectObject(GetHdc(), (HBITMAP
) m_oldBitmap
);
96 if ( m_selectedBitmap
.Ok() )
98 m_selectedBitmap
.SetSelectedInto(NULL
);
99 m_selectedBitmap
= wxNullBitmap
;
103 // check for whether the bitmap is already selected into a device context
104 wxCHECK_RET( !bitmap
.GetSelectedInto() ||
105 (bitmap
.GetSelectedInto() == this),
106 wxT("Bitmap is selected in another wxMemoryDC, delete the "
107 "first wxMemoryDC or use SelectObject(NULL)") );
109 m_selectedBitmap
= bitmap
;
110 WXHBITMAP hBmp
= m_selectedBitmap
.GetHBITMAP();
114 m_selectedBitmap
.SetSelectedInto(this);
115 hBmp
= (WXHBITMAP
)::SelectObject(GetHdc(), (HBITMAP
)hBmp
);
119 wxLogLastError("SelectObject(memDC, bitmap)");
121 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
123 else if ( !m_oldBitmap
)
129 void wxMemoryDC::DoGetSize(int *width
, int *height
) const
131 if ( m_selectedBitmap
.Ok() )
133 *width
= m_selectedBitmap
.GetWidth();
134 *height
= m_selectedBitmap
.GetHeight();