]>
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 | |
24 | #endif | |
25 | ||
26 | #include "wx/dcmemory.h" | |
27 | ||
28 | #include <windows.h> | |
29 | ||
30 | #if !USE_SHARED_LIBRARY | |
31 | IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC, wxDC) | |
32 | #endif | |
33 | ||
34 | /* | |
35 | * Memory DC | |
36 | * | |
37 | */ | |
38 | ||
39 | wxMemoryDC::wxMemoryDC(void) | |
40 | { | |
41 | m_hDC = (WXHDC) ::CreateCompatibleDC(NULL); | |
42 | m_ok = (m_hDC != 0); | |
1c089c47 | 43 | m_bOwnsDC = TRUE; |
2bda0e17 KB |
44 | |
45 | SetBrush(*wxWHITE_BRUSH); | |
46 | SetPen(*wxBLACK_PEN); | |
47 | } | |
48 | ||
49 | wxMemoryDC::wxMemoryDC(wxDC *old_dc) | |
50 | { | |
51 | old_dc->BeginDrawing(); | |
52 | ||
53 | m_hDC = (WXHDC) ::CreateCompatibleDC((HDC) old_dc->GetHDC()); | |
54 | m_ok = (m_hDC != 0); | |
55 | ||
56 | old_dc->EndDrawing(); | |
57 | ||
58 | SetBrush(*wxWHITE_BRUSH); | |
59 | SetPen(*wxBLACK_PEN); | |
60 | } | |
61 | ||
62 | wxMemoryDC::~wxMemoryDC(void) | |
63 | { | |
64 | } | |
65 | ||
66 | void wxMemoryDC::SelectObject(const wxBitmap& bitmap) | |
67 | { | |
68 | // Select old bitmap out of the device context | |
69 | if (m_oldBitmap) | |
70 | { | |
71 | ::SelectObject((HDC) m_hDC, (HBITMAP) m_oldBitmap); | |
72 | if (m_selectedBitmap.Ok()) | |
73 | { | |
74 | m_selectedBitmap.SetSelectedInto(NULL); | |
75 | m_selectedBitmap = wxNullBitmap; | |
76 | } | |
77 | } | |
78 | ||
79 | // Do own check for whether the bitmap is already selected into | |
80 | // a device context | |
81 | if (bitmap.GetSelectedInto() && (bitmap.GetSelectedInto() != this)) | |
82 | { | |
83 | wxFatalError("Error in wxMemoryDC::SelectObject\nBitmap is selected in another wxMemoryDC.\nDelete the first wxMemoryDC or use SelectObject(NULL)"); | |
84 | return; | |
85 | } | |
7b46ecac JS |
86 | |
87 | // Check if the bitmap has the correct depth for this device context | |
16553659 JS |
88 | // if (bitmap.Ok() && (bitmap.GetDepth() != GetDepth())) |
89 | // JACS 11/12/98: disabling this since the Forty Thieves sample | |
90 | // shows this not working properly. In fact, if loading from a resource, | |
91 | // the depth should become the screen depth, so why was it being called? | |
92 | if (0) | |
7b46ecac JS |
93 | { |
94 | // Make a new bitmap that has the correct depth. | |
95 | wxBitmap newBitmap = bitmap.GetBitmapForDC(* this); | |
96 | ||
97 | m_selectedBitmap = newBitmap ; | |
98 | } | |
99 | else | |
100 | { | |
101 | m_selectedBitmap = bitmap; | |
102 | } | |
2bda0e17 KB |
103 | |
104 | if (!m_selectedBitmap.Ok()) | |
105 | return; | |
106 | ||
107 | m_selectedBitmap.SetSelectedInto(this); | |
c4e7c2aa | 108 | HBITMAP bm = (HBITMAP) ::SelectObject((HDC) m_hDC, (HBITMAP) m_selectedBitmap.GetHBITMAP()); |
2bda0e17 KB |
109 | |
110 | if (bm == ERROR) | |
111 | { | |
112 | wxFatalError("Error in wxMemoryDC::SelectObject\nBitmap may not be loaded, or may be selected in another wxMemoryDC.\nDelete the first wxMemoryDC to deselect bitmap."); | |
113 | } | |
114 | else if (!m_oldBitmap) | |
115 | m_oldBitmap = (WXHBITMAP) bm; | |
116 | } | |
117 | ||
118 | void wxMemoryDC::GetSize(int *width, int *height) const | |
119 | { | |
120 | if (!m_selectedBitmap.Ok()) | |
121 | { | |
122 | *width = 0; *height = 0; | |
123 | return; | |
124 | } | |
125 | *width = m_selectedBitmap.GetWidth(); | |
126 | *height = m_selectedBitmap.GetHeight(); | |
127 | } | |
128 |