]> git.saurik.com Git - wxWidgets.git/blob - src/msw/dcmemory.cpp
1. more drag and drop and clipboard changes:
[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 #endif
34
35 #include "wx/msw/private.h"
36
37 #include "wx/dcmemory.h"
38
39 // ----------------------------------------------------------------------------
40 // wxWin macros
41 // ----------------------------------------------------------------------------
42
43 #if !USE_SHARED_LIBRARY
44 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC, wxDC)
45 #endif
46
47 // ============================================================================
48 // implementation
49 // ============================================================================
50
51 // ----------------------------------------------------------------------------
52 // wxMemoryDC
53 // ----------------------------------------------------------------------------
54
55 wxMemoryDC::wxMemoryDC()
56 {
57 m_hDC = (WXHDC) ::CreateCompatibleDC((HDC) NULL);
58 m_ok = (m_hDC != 0);
59 m_bOwnsDC = TRUE;
60
61 SetBrush(*wxWHITE_BRUSH);
62 SetPen(*wxBLACK_PEN);
63
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 );
67 }
68
69 wxMemoryDC::wxMemoryDC(wxDC *old_dc)
70 {
71 old_dc->BeginDrawing();
72
73 m_hDC = (WXHDC) ::CreateCompatibleDC(GetHdcOf(*old_dc));
74 m_ok = (m_hDC != 0);
75
76 old_dc->EndDrawing();
77
78 SetBrush(*wxWHITE_BRUSH);
79 SetPen(*wxBLACK_PEN);
80
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 );
84 }
85
86 wxMemoryDC::~wxMemoryDC()
87 {
88 }
89
90 void wxMemoryDC::SelectObject(const wxBitmap& bitmap)
91 {
92 // select old bitmap out of the device context
93 if ( m_oldBitmap )
94 {
95 ::SelectObject(GetHdc(), (HBITMAP) m_oldBitmap);
96 if ( m_selectedBitmap.Ok() )
97 {
98 m_selectedBitmap.SetSelectedInto(NULL);
99 m_selectedBitmap = wxNullBitmap;
100 }
101 }
102
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)") );
108
109 m_selectedBitmap = bitmap;
110 WXHBITMAP hBmp = m_selectedBitmap.GetHBITMAP();
111 if ( !hBmp )
112 return;
113
114 m_selectedBitmap.SetSelectedInto(this);
115 hBmp = (WXHBITMAP)::SelectObject(GetHdc(), (HBITMAP)hBmp);
116
117 if ( !hBmp )
118 {
119 wxLogLastError("SelectObject(memDC, bitmap)");
120
121 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
122 }
123 else if ( !m_oldBitmap )
124 {
125 m_oldBitmap = hBmp;
126 }
127 }
128
129 void wxMemoryDC::DoGetSize(int *width, int *height) const
130 {
131 if ( m_selectedBitmap.Ok() )
132 {
133 *width = m_selectedBitmap.GetWidth();
134 *height = m_selectedBitmap.GetHeight();
135 }
136 else
137 {
138 *width = 0;
139 *height = 0;
140 }
141 }
142