]>
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 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dcmemory.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/dcmemory.h"
30 #include "wx/msw/winundef.h"
32 #if !USE_SHARED_LIBRARY
33 IMPLEMENT_DYNAMIC_CLASS ( wxMemoryDC
, wxDC
)
41 wxMemoryDC :: wxMemoryDC ( void )
43 m_hDC
= ( WXHDC
) :: CreateCompatibleDC (( HDC
) NULL
);
47 SetBrush (* wxWHITE_BRUSH
);
51 wxMemoryDC :: wxMemoryDC ( wxDC
* old_dc
)
53 old_dc
-> BeginDrawing ();
55 m_hDC
= ( WXHDC
) :: CreateCompatibleDC (( HDC
) old_dc
-> GetHDC ());
60 SetBrush (* wxWHITE_BRUSH
);
64 wxMemoryDC ::~ wxMemoryDC ( void )
68 void wxMemoryDC :: SelectObject ( const wxBitmap
& bitmap
)
70 // Select old bitmap out of the device context
73 :: SelectObject (( HDC
) m_hDC
, ( HBITMAP
) m_oldBitmap
);
74 if ( m_selectedBitmap
. Ok ())
76 m_selectedBitmap
. SetSelectedInto ( NULL
);
77 m_selectedBitmap
= wxNullBitmap
;
81 // Do own check for whether the bitmap is already selected into
83 if ( bitmap
. GetSelectedInto () && ( bitmap
. GetSelectedInto () != this ))
85 wxFatalError ( _T ( "Error in wxMemoryDC::SelectObject \n Bitmap is selected in another wxMemoryDC. \n Delete the first wxMemoryDC or use SelectObject(NULL)" ));
89 // Check if the bitmap has the correct depth for this device context
90 // if (bitmap.Ok() && (bitmap.GetDepth() != GetDepth()))
91 // JACS 11/12/98: disabling this since the Forty Thieves sample
92 // shows this not working properly. In fact, if loading from a resource,
93 // the depth should become the screen depth, so why was it being called?
96 // // Make a new bitmap that has the correct depth.
97 // wxBitmap newBitmap = bitmap.GetBitmapForDC(* this);
99 // m_selectedBitmap = newBitmap ;
103 m_selectedBitmap
= bitmap
;
106 if (! m_selectedBitmap
. Ok ())
109 m_selectedBitmap
. SetSelectedInto ( this );
110 HBITMAP bm
= ( HBITMAP
) :: SelectObject (( HDC
) m_hDC
, ( HBITMAP
) m_selectedBitmap
. GetHBITMAP ());
114 wxFatalError ( _T ( "Error in wxMemoryDC::SelectObject \n Bitmap may not be loaded, or may be selected in another wxMemoryDC. \n Delete the first wxMemoryDC to deselect bitmap." ));
116 else if (! m_oldBitmap
)
117 m_oldBitmap
= ( WXHBITMAP
) bm
;
120 void wxMemoryDC :: DoGetSize ( int * width
, int * height
) const
122 if (! m_selectedBitmap
. Ok ())
124 * width
= 0 ; * height
= 0 ;
127 * width
= m_selectedBitmap
. GetWidth ();
128 * height
= m_selectedBitmap
. GetHeight ();