]> git.saurik.com Git - wxWidgets.git/blob - src/msw/dcmemory.cpp
small corrections for dnd code and added wxFileDataObject demo to the sample
[wxWidgets.git] / src / msw / dcmemory.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dcmemory.cpp
3 // Purpose: wxMemoryDC class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "dcmemory.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/utils.h"
33 #include "wx/log.h"
34 #endif
35
36 #include "wx/msw/private.h"
37
38 #include "wx/dcmemory.h"
39
40 // ----------------------------------------------------------------------------
41 // wxWin macros
42 // ----------------------------------------------------------------------------
43
44 #if !USE_SHARED_LIBRARY
45 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC, wxDC)
46 #endif
47
48 // ============================================================================
49 // implementation
50 // ============================================================================
51
52 // ----------------------------------------------------------------------------
53 // wxMemoryDC
54 // ----------------------------------------------------------------------------
55
56 wxMemoryDC::wxMemoryDC()
57 {
58 m_hDC = (WXHDC) ::CreateCompatibleDC((HDC) NULL);
59 m_ok = (m_hDC != 0);
60 m_bOwnsDC = TRUE;
61
62 SetBrush(*wxWHITE_BRUSH);
63 SetPen(*wxBLACK_PEN);
64
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 );
68 }
69
70 wxMemoryDC::wxMemoryDC(wxDC *old_dc)
71 {
72 old_dc->BeginDrawing();
73
74 m_hDC = (WXHDC) ::CreateCompatibleDC(GetHdcOf(*old_dc));
75 m_ok = (m_hDC != 0);
76
77 old_dc->EndDrawing();
78
79 SetBrush(*wxWHITE_BRUSH);
80 SetPen(*wxBLACK_PEN);
81
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 );
85 }
86
87 wxMemoryDC::~wxMemoryDC()
88 {
89 }
90
91 void wxMemoryDC::SelectObject(const wxBitmap& bitmap)
92 {
93 // select old bitmap out of the device context
94 if ( m_oldBitmap )
95 {
96 ::SelectObject(GetHdc(), (HBITMAP) m_oldBitmap);
97 if ( m_selectedBitmap.Ok() )
98 {
99 m_selectedBitmap.SetSelectedInto(NULL);
100 m_selectedBitmap = wxNullBitmap;
101 }
102 }
103
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)") );
109
110 m_selectedBitmap = bitmap;
111 WXHBITMAP hBmp = m_selectedBitmap.GetHBITMAP();
112 if ( !hBmp )
113 return;
114
115 m_selectedBitmap.SetSelectedInto(this);
116 hBmp = (WXHBITMAP)::SelectObject(GetHdc(), (HBITMAP)hBmp);
117
118 if ( !hBmp )
119 {
120 wxLogLastError("SelectObject(memDC, bitmap)");
121
122 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
123 }
124 else if ( !m_oldBitmap )
125 {
126 m_oldBitmap = hBmp;
127 }
128 }
129
130 void wxMemoryDC::DoGetSize(int *width, int *height) const
131 {
132 if ( m_selectedBitmap.Ok() )
133 {
134 *width = m_selectedBitmap.GetWidth();
135 *height = m_selectedBitmap.GetHeight();
136 }
137 else
138 {
139 *width = 0;
140 *height = 0;
141 }
142 }
143