]>
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"
31 #if !USE_SHARED_LIBRARY
32 IMPLEMENT_DYNAMIC_CLASS ( wxMemoryDC
, wxDC
)
40 wxMemoryDC :: wxMemoryDC ( void )
42 m_hDC
= ( WXHDC
) :: CreateCompatibleDC (( HDC
) NULL
);
46 SetBrush (* wxWHITE_BRUSH
);
50 wxMemoryDC :: wxMemoryDC ( wxDC
* old_dc
)
52 old_dc
-> BeginDrawing ();
54 m_hDC
= ( WXHDC
) :: CreateCompatibleDC (( HDC
) old_dc
-> GetHDC ());
59 SetBrush (* wxWHITE_BRUSH
);
63 wxMemoryDC ::~ wxMemoryDC ( void )
67 void wxMemoryDC :: SelectObject ( const wxBitmap
& bitmap
)
69 // Select old bitmap out of the device context
72 :: SelectObject (( HDC
) m_hDC
, ( HBITMAP
) m_oldBitmap
);
73 if ( m_selectedBitmap
. Ok ())
75 m_selectedBitmap
. SetSelectedInto ( NULL
);
76 m_selectedBitmap
= wxNullBitmap
;
80 // Do own check for whether the bitmap is already selected into
82 if ( bitmap
. GetSelectedInto () && ( bitmap
. GetSelectedInto () != this ))
84 wxFatalError ( "Error in wxMemoryDC::SelectObject \n Bitmap is selected in another wxMemoryDC. \n Delete the first wxMemoryDC or use SelectObject(NULL)" );
88 // Check if the bitmap has the correct depth for this device context
89 // if (bitmap.Ok() && (bitmap.GetDepth() != GetDepth()))
90 // JACS 11/12/98: disabling this since the Forty Thieves sample
91 // shows this not working properly. In fact, if loading from a resource,
92 // the depth should become the screen depth, so why was it being called?
95 // // Make a new bitmap that has the correct depth.
96 // wxBitmap newBitmap = bitmap.GetBitmapForDC(* this);
98 // m_selectedBitmap = newBitmap ;
102 m_selectedBitmap
= bitmap
;
105 if (! m_selectedBitmap
. Ok ())
108 m_selectedBitmap
. SetSelectedInto ( this );
109 HBITMAP bm
= ( HBITMAP
) :: SelectObject (( HDC
) m_hDC
, ( HBITMAP
) m_selectedBitmap
. GetHBITMAP ());
113 wxFatalError ( "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." );
115 else if (! m_oldBitmap
)
116 m_oldBitmap
= ( WXHBITMAP
) bm
;
119 void wxMemoryDC :: GetSize ( int * width
, int * height
) const
121 if (! m_selectedBitmap
. Ok ())
123 * width
= 0 ; * height
= 0 ;
126 * width
= m_selectedBitmap
. GetWidth ();
127 * height
= m_selectedBitmap
. GetHeight ();