]>
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/msw/private.h"
29 #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
);
49 // the background mode is only used for text background
50 // and is set in DrawText() to OPAQUE as required, other-
51 // wise always TRANSPARENT, RR
52 :: SetBkMode ( GetHdc (), TRANSPARENT
);
56 wxMemoryDC :: wxMemoryDC ( wxDC
* old_dc
)
58 old_dc
-> BeginDrawing ();
60 m_hDC
= ( WXHDC
) :: CreateCompatibleDC (( HDC
) old_dc
-> GetHDC ());
65 SetBrush (* wxWHITE_BRUSH
);
68 // the background mode is only used for text background
69 // and is set in DrawText() to OPAQUE as required, other-
70 // wise always TRANSPARENT, RR
71 :: SetBkMode ( GetHdc (), TRANSPARENT
);
75 wxMemoryDC ::~ wxMemoryDC ( void )
79 void wxMemoryDC :: SelectObject ( const wxBitmap
& bitmap
)
81 // Select old bitmap out of the device context
84 :: SelectObject (( HDC
) m_hDC
, ( HBITMAP
) m_oldBitmap
);
85 if ( m_selectedBitmap
. Ok ())
87 m_selectedBitmap
. SetSelectedInto ( NULL
);
88 m_selectedBitmap
= wxNullBitmap
;
92 // Do own check for whether the bitmap is already selected into
94 if ( bitmap
. GetSelectedInto () && ( bitmap
. GetSelectedInto () != this ))
96 wxFatalError ( wxT ( "Error in wxMemoryDC::SelectObject \n Bitmap is selected in another wxMemoryDC. \n Delete the first wxMemoryDC or use SelectObject(NULL)" ));
100 // Check if the bitmap has the correct depth for this device context
101 // if (bitmap.Ok() && (bitmap.GetDepth() != GetDepth()))
102 // JACS 11/12/98: disabling this since the Forty Thieves sample
103 // shows this not working properly. In fact, if loading from a resource,
104 // the depth should become the screen depth, so why was it being called?
107 // // Make a new bitmap that has the correct depth.
108 // wxBitmap newBitmap = bitmap.GetBitmapForDC(* this);
110 // m_selectedBitmap = newBitmap ;
114 m_selectedBitmap
= bitmap
;
117 if (! m_selectedBitmap
. Ok ())
120 m_selectedBitmap
. SetSelectedInto ( this );
121 HBITMAP bm
= ( HBITMAP
) :: SelectObject (( HDC
) m_hDC
, ( HBITMAP
) m_selectedBitmap
. GetHBITMAP ());
125 wxFatalError ( wxT ( "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." ));
127 else if (! m_oldBitmap
)
128 m_oldBitmap
= ( WXHBITMAP
) bm
;
131 void wxMemoryDC :: DoGetSize ( int * width
, int * height
) const
133 if (! m_selectedBitmap
. Ok ())
135 * width
= 0 ; * height
= 0 ;
138 * width
= m_selectedBitmap
. GetWidth ();
139 * height
= m_selectedBitmap
. GetHeight ();