]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
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 | |
d59ceba5 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
d59ceba5 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
2bda0e17 | 20 | #ifdef __GNUG__ |
d59ceba5 | 21 | #pragma implementation "dcmemory.h" |
2bda0e17 KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
d59ceba5 | 28 | #pragma hdrstop |
2bda0e17 KB |
29 | #endif |
30 | ||
31 | #ifndef WX_PRECOMP | |
d59ceba5 | 32 | #include "wx/utils.h" |
3f1c6a14 | 33 | #include "wx/log.h" |
2bda0e17 KB |
34 | #endif |
35 | ||
c45a644e | 36 | #include "wx/msw/private.h" |
2bda0e17 | 37 | |
c45a644e | 38 | #include "wx/dcmemory.h" |
2bda0e17 | 39 | |
d59ceba5 VZ |
40 | // ---------------------------------------------------------------------------- |
41 | // wxWin macros | |
42 | // ---------------------------------------------------------------------------- | |
43 | ||
2bda0e17 | 44 | #if !USE_SHARED_LIBRARY |
d59ceba5 | 45 | IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC, wxDC) |
2bda0e17 KB |
46 | #endif |
47 | ||
d59ceba5 VZ |
48 | // ============================================================================ |
49 | // implementation | |
50 | // ============================================================================ | |
2bda0e17 | 51 | |
d59ceba5 VZ |
52 | // ---------------------------------------------------------------------------- |
53 | // wxMemoryDC | |
54 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 55 | |
d59ceba5 VZ |
56 | wxMemoryDC::wxMemoryDC() |
57 | { | |
58 | m_hDC = (WXHDC) ::CreateCompatibleDC((HDC) NULL); | |
59 | m_ok = (m_hDC != 0); | |
60 | m_bOwnsDC = TRUE; | |
c45a644e | 61 | |
d59ceba5 VZ |
62 | SetBrush(*wxWHITE_BRUSH); |
63 | SetPen(*wxBLACK_PEN); | |
c45a644e | 64 | |
d59ceba5 VZ |
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 ); | |
2bda0e17 KB |
68 | } |
69 | ||
70 | wxMemoryDC::wxMemoryDC(wxDC *old_dc) | |
71 | { | |
d59ceba5 | 72 | old_dc->BeginDrawing(); |
2bda0e17 | 73 | |
d59ceba5 VZ |
74 | m_hDC = (WXHDC) ::CreateCompatibleDC(GetHdcOf(*old_dc)); |
75 | m_ok = (m_hDC != 0); | |
2bda0e17 | 76 | |
d59ceba5 | 77 | old_dc->EndDrawing(); |
2bda0e17 | 78 | |
d59ceba5 VZ |
79 | SetBrush(*wxWHITE_BRUSH); |
80 | SetPen(*wxBLACK_PEN); | |
c45a644e | 81 | |
d59ceba5 VZ |
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 ); | |
2bda0e17 KB |
85 | } |
86 | ||
d59ceba5 | 87 | wxMemoryDC::~wxMemoryDC() |
2bda0e17 KB |
88 | { |
89 | } | |
90 | ||
91 | void wxMemoryDC::SelectObject(const wxBitmap& bitmap) | |
92 | { | |
d59ceba5 VZ |
93 | // select old bitmap out of the device context |
94 | if ( m_oldBitmap ) | |
2bda0e17 | 95 | { |
d59ceba5 VZ |
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; | |
2bda0e17 | 127 | } |
2bda0e17 KB |
128 | } |
129 | ||
953ccd3d | 130 | void wxMemoryDC::DoGetSize(int *width, int *height) const |
2bda0e17 | 131 | { |
d59ceba5 VZ |
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 | } | |
2bda0e17 KB |
142 | } |
143 |