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