]> git.saurik.com Git - wxWidgets.git/blob - src/msw/dcmemory.cpp
New configure
[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 #ifdef __GNUG__
13 #pragma implementation
14 #pragma implementation "dcmemory.h"
15 #endif
16
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
19
20 #ifdef __BORLANDC__
21 #pragma hdrstop
22 #endif
23
24 #ifndef WX_PRECOMP
25 #endif
26
27 #include "wx/dcmemory.h"
28
29 #include <windows.h>
30
31 #if !USE_SHARED_LIBRARY
32 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC, wxDC)
33 #endif
34
35 /*
36 * Memory DC
37 *
38 */
39
40 wxMemoryDC::wxMemoryDC(void)
41 {
42 m_hDC = (WXHDC) ::CreateCompatibleDC(NULL);
43 m_ok = (m_hDC != 0);
44 m_bOwnsDC = TRUE;
45
46 SetBrush(*wxWHITE_BRUSH);
47 SetPen(*wxBLACK_PEN);
48 }
49
50 wxMemoryDC::wxMemoryDC(wxDC *old_dc)
51 {
52 old_dc->BeginDrawing();
53
54 m_hDC = (WXHDC) ::CreateCompatibleDC((HDC) old_dc->GetHDC());
55 m_ok = (m_hDC != 0);
56
57 old_dc->EndDrawing();
58
59 SetBrush(*wxWHITE_BRUSH);
60 SetPen(*wxBLACK_PEN);
61 }
62
63 wxMemoryDC::~wxMemoryDC(void)
64 {
65 }
66
67 void wxMemoryDC::SelectObject(const wxBitmap& bitmap)
68 {
69 // Select old bitmap out of the device context
70 if (m_oldBitmap)
71 {
72 ::SelectObject((HDC) m_hDC, (HBITMAP) m_oldBitmap);
73 if (m_selectedBitmap.Ok())
74 {
75 m_selectedBitmap.SetSelectedInto(NULL);
76 m_selectedBitmap = wxNullBitmap;
77 }
78 }
79
80 // Do own check for whether the bitmap is already selected into
81 // a device context
82 if (bitmap.GetSelectedInto() && (bitmap.GetSelectedInto() != this))
83 {
84 wxFatalError("Error in wxMemoryDC::SelectObject\nBitmap is selected in another wxMemoryDC.\nDelete the first wxMemoryDC or use SelectObject(NULL)");
85 return;
86 }
87
88 m_selectedBitmap = bitmap;
89
90 if (!m_selectedBitmap.Ok())
91 return;
92
93 m_selectedBitmap.SetSelectedInto(this);
94 #if WXDEBUG > 1
95 wxDebugMsg("wxMemoryDC::SelectObject: Selecting HBITMAP %X\n", m_selectedBitmap.GetHBITMAP());
96 #endif
97 HBITMAP bm = (HBITMAP) ::SelectObject((HDC) m_hDC, (HBITMAP) m_selectedBitmap.GetHBITMAP());
98
99 if (bm == ERROR)
100 {
101 wxFatalError("Error in wxMemoryDC::SelectObject\nBitmap may not be loaded, or may be selected in another wxMemoryDC.\nDelete the first wxMemoryDC to deselect bitmap.");
102 }
103 else if (!m_oldBitmap)
104 m_oldBitmap = (WXHBITMAP) bm;
105 }
106
107 void wxMemoryDC::GetSize(int *width, int *height) const
108 {
109 if (!m_selectedBitmap.Ok())
110 {
111 *width = 0; *height = 0;
112 return;
113 }
114 *width = m_selectedBitmap.GetWidth();
115 *height = m_selectedBitmap.GetHeight();
116 }
117