]>
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 | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
2bda0e17 KB |
13 | #pragma implementation "dcmemory.h" |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
2432b92d | 24 | #include "wx/utils.h" |
2bda0e17 KB |
25 | #endif |
26 | ||
c45a644e | 27 | #include "wx/msw/private.h" |
2bda0e17 | 28 | |
c45a644e | 29 | #include "wx/dcmemory.h" |
2bda0e17 KB |
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 | { | |
57c208c5 | 42 | m_hDC = (WXHDC) ::CreateCompatibleDC((HDC) NULL); |
2bda0e17 | 43 | m_ok = (m_hDC != 0); |
1c089c47 | 44 | m_bOwnsDC = TRUE; |
2bda0e17 KB |
45 | |
46 | SetBrush(*wxWHITE_BRUSH); | |
47 | SetPen(*wxBLACK_PEN); | |
c45a644e RR |
48 | |
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 ); | |
53 | ||
2bda0e17 KB |
54 | } |
55 | ||
56 | wxMemoryDC::wxMemoryDC(wxDC *old_dc) | |
57 | { | |
58 | old_dc->BeginDrawing(); | |
59 | ||
60 | m_hDC = (WXHDC) ::CreateCompatibleDC((HDC) old_dc->GetHDC()); | |
61 | m_ok = (m_hDC != 0); | |
62 | ||
63 | old_dc->EndDrawing(); | |
64 | ||
65 | SetBrush(*wxWHITE_BRUSH); | |
66 | SetPen(*wxBLACK_PEN); | |
c45a644e RR |
67 | |
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 ); | |
72 | ||
2bda0e17 KB |
73 | } |
74 | ||
75 | wxMemoryDC::~wxMemoryDC(void) | |
76 | { | |
77 | } | |
78 | ||
79 | void wxMemoryDC::SelectObject(const wxBitmap& bitmap) | |
80 | { | |
81 | // Select old bitmap out of the device context | |
82 | if (m_oldBitmap) | |
83 | { | |
84 | ::SelectObject((HDC) m_hDC, (HBITMAP) m_oldBitmap); | |
85 | if (m_selectedBitmap.Ok()) | |
86 | { | |
87 | m_selectedBitmap.SetSelectedInto(NULL); | |
88 | m_selectedBitmap = wxNullBitmap; | |
89 | } | |
90 | } | |
91 | ||
92 | // Do own check for whether the bitmap is already selected into | |
93 | // a device context | |
94 | if (bitmap.GetSelectedInto() && (bitmap.GetSelectedInto() != this)) | |
95 | { | |
223d09f6 | 96 | wxFatalError(wxT("Error in wxMemoryDC::SelectObject\nBitmap is selected in another wxMemoryDC.\nDelete the first wxMemoryDC or use SelectObject(NULL)")); |
2bda0e17 KB |
97 | return; |
98 | } | |
7b46ecac JS |
99 | |
100 | // Check if the bitmap has the correct depth for this device context | |
16553659 JS |
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? | |
2917e920 BM |
105 | // if (0) |
106 | // { | |
107 | // // Make a new bitmap that has the correct depth. | |
108 | // wxBitmap newBitmap = bitmap.GetBitmapForDC(* this); | |
109 | // | |
110 | // m_selectedBitmap = newBitmap ; | |
111 | // } | |
112 | // else | |
113 | // { | |
7b46ecac | 114 | m_selectedBitmap = bitmap; |
2917e920 | 115 | // } |
2bda0e17 KB |
116 | |
117 | if (!m_selectedBitmap.Ok()) | |
118 | return; | |
119 | ||
120 | m_selectedBitmap.SetSelectedInto(this); | |
c4e7c2aa | 121 | HBITMAP bm = (HBITMAP) ::SelectObject((HDC) m_hDC, (HBITMAP) m_selectedBitmap.GetHBITMAP()); |
2bda0e17 KB |
122 | |
123 | if (bm == ERROR) | |
124 | { | |
223d09f6 | 125 | wxFatalError(wxT("Error in wxMemoryDC::SelectObject\nBitmap may not be loaded, or may be selected in another wxMemoryDC.\nDelete the first wxMemoryDC to deselect bitmap.")); |
2bda0e17 KB |
126 | } |
127 | else if (!m_oldBitmap) | |
128 | m_oldBitmap = (WXHBITMAP) bm; | |
129 | } | |
130 | ||
953ccd3d | 131 | void wxMemoryDC::DoGetSize(int *width, int *height) const |
2bda0e17 KB |
132 | { |
133 | if (!m_selectedBitmap.Ok()) | |
134 | { | |
135 | *width = 0; *height = 0; | |
136 | return; | |
137 | } | |
138 | *width = m_selectedBitmap.GetWidth(); | |
139 | *height = m_selectedBitmap.GetHeight(); | |
140 | } | |
141 |