]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dcmemory.cpp | |
3 | // Purpose: wxMemoryDC class | |
fb46a9a6 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
fb46a9a6 | 6 | // Created: 10/14/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
fb46a9a6 DW |
8 | // Copyright: (c) David Webster |
9 | // Licence: wxWindows licence | |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
fb46a9a6 DW |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifndef WX_PRECOMP | |
16 | #include "wx/utils.h" | |
3417f661 SN |
17 | #include "wx/app.h" |
18 | #include "wx/log.h" | |
0e320a79 DW |
19 | #endif |
20 | ||
fb46a9a6 DW |
21 | #include "wx/os2/private.h" |
22 | ||
0e320a79 DW |
23 | #include "wx/dcmemory.h" |
24 | ||
fb46a9a6 | 25 | IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC, wxDC) |
0e320a79 | 26 | |
23122f8c DW |
27 | ///////////////////////////////////////////////////////////////////////////// |
28 | // Memory DC | |
29 | ///////////////////////////////////////////////////////////////////////////// | |
0e320a79 DW |
30 | |
31 | wxMemoryDC::wxMemoryDC(void) | |
32 | { | |
e1a688e4 DW |
33 | CreateCompatible(NULL); |
34 | Init(); | |
23122f8c DW |
35 | } // end of wxMemoryDC::wxMemoryDC |
36 | ||
37 | wxMemoryDC::wxMemoryDC( | |
38 | wxDC* pOldDC | |
39 | ) | |
e1a688e4 DW |
40 | { |
41 | pOldDC->BeginDrawing(); | |
42 | CreateCompatible(pOldDC); | |
43 | pOldDC->EndDrawing(); | |
44 | Init(); | |
45 | } // end of wxMemoryDC::wxMemoryDC | |
46 | ||
47 | void wxMemoryDC::Init() | |
48 | { | |
49 | if (m_ok) | |
50 | { | |
51 | SetBrush(*wxWHITE_BRUSH); | |
52 | SetPen(*wxBLACK_PEN); | |
53 | ||
54 | // the background mode is only used for text background and is set in | |
55 | // DrawText() to OPAQUE as required, otherwise always TRANSPARENT | |
56 | ::GpiSetBackMix( GetHPS(), BM_LEAVEALONE ); | |
57 | } | |
1d0edc0f | 58 | memset(&m_vRclPaint, 0, sizeof(m_vRclPaint)); |
e1a688e4 DW |
59 | } // end of wxMemoryDC::Init |
60 | ||
61 | bool wxMemoryDC::CreateCompatible( | |
62 | wxDC* pDC | |
63 | ) | |
0e320a79 | 64 | { |
23122f8c DW |
65 | HDC hDC; |
66 | HPS hPS; | |
67 | DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L}; | |
68 | SIZEL vSize = {0, 0}; | |
69 | ||
23122f8c DW |
70 | // |
71 | // Create a memory device context | |
72 | // | |
e1a688e4 | 73 | hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE); |
23122f8c DW |
74 | if (hDC != DEV_ERROR) |
75 | { | |
76 | hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC); | |
77 | if (hPS != GPI_ERROR) | |
78 | { | |
79 | m_hPS = hPS; | |
80 | m_hDC = hDC; | |
81 | m_ok = TRUE; | |
82 | m_bOwnsDC = TRUE; | |
e1a688e4 DW |
83 | // |
84 | // Set the wxWindows color table | |
85 | // | |
86 | ::GpiCreateLogColorTable( m_hPS | |
87 | ,0L | |
88 | ,LCOLF_CONSECRGB | |
89 | ,0L | |
90 | ,(LONG)wxTheColourDatabase->m_nSize | |
91 | ,(PLONG)wxTheColourDatabase->m_palTable | |
92 | ); | |
93 | ::GpiCreateLogColorTable( m_hPS | |
94 | ,0L | |
95 | ,LCOLF_RGB | |
96 | ,0L | |
97 | ,0L | |
98 | ,NULL | |
99 | ); | |
23122f8c DW |
100 | } |
101 | else | |
102 | { | |
23122f8c DW |
103 | m_hPS = NULLHANDLE; |
104 | m_hDC = NULLHANDLE; | |
105 | m_ok = FALSE; | |
106 | m_bOwnsDC = FALSE; | |
107 | } | |
108 | } | |
109 | else | |
110 | { | |
23122f8c DW |
111 | m_hPS = NULLHANDLE; |
112 | m_hDC = NULLHANDLE; | |
113 | m_ok = FALSE; | |
114 | m_bOwnsDC = FALSE; | |
115 | } | |
23122f8c | 116 | |
e1a688e4 DW |
117 | // |
118 | // As we created the DC, we must delete it in the dtor | |
119 | // | |
120 | m_bOwnsDC = TRUE; | |
121 | m_ok = m_hDC != 0; | |
122 | return m_ok; | |
123 | } // end of wxMemoryDC::CreateCompatible | |
23122f8c DW |
124 | |
125 | void wxMemoryDC::SelectObject( | |
126 | const wxBitmap& rBitmap | |
127 | ) | |
0e320a79 | 128 | { |
23122f8c DW |
129 | // |
130 | // Select old bitmap out of the device context | |
131 | // | |
132 | if (m_hOldBitmap) | |
133 | { | |
134 | ::GpiSetBitmap(m_hPS, NULLHANDLE); | |
135 | if (m_vSelectedBitmap.Ok()) | |
136 | { | |
137 | m_vSelectedBitmap.SetSelectedInto(NULL); | |
138 | m_vSelectedBitmap = wxNullBitmap; | |
139 | } | |
140 | } | |
141 | ||
142 | // | |
143 | // Check for whether the bitmap is already selected into a device context | |
144 | // | |
145 | wxCHECK_RET( !rBitmap.GetSelectedInto() || | |
146 | (rBitmap.GetSelectedInto() == this), | |
147 | wxT("Bitmap is selected in another wxMemoryDC, delete the first wxMemoryDC or use SelectObject(NULL)") ); | |
148 | ||
1c9a789e DW |
149 | WXHBITMAP hBmp = rBitmap.GetHBITMAP(); |
150 | ||
151 | if (!hBmp) | |
152 | { | |
ad6bd870 DW |
153 | // |
154 | // Bmps drawn to are upside down, so flip it before committing | |
155 | // | |
9923c37d DW |
156 | POINTL vPoint[4] = { {0, m_vSelectedBitmap.GetHeight()} |
157 | ,{m_vSelectedBitmap.GetWidth(), 0} | |
158 | ,{0, 0} | |
159 | ,{m_vSelectedBitmap.GetWidth(), m_vSelectedBitmap.GetHeight()} | |
ad6bd870 DW |
160 | }; |
161 | ||
162 | ||
163 | ::GpiBitBlt( m_hPS | |
164 | ,m_hPS | |
165 | ,4 | |
166 | ,vPoint | |
167 | ,ROP_SRCCOPY | |
168 | ,BBO_IGNORE | |
169 | ); | |
1c9a789e DW |
170 | m_vSelectedBitmap.SetSelectedInto(NULL); |
171 | } | |
23122f8c DW |
172 | m_vSelectedBitmap = rBitmap; |
173 | ||
23122f8c DW |
174 | |
175 | if (!hBmp) | |
29172908 | 176 | { |
ad6bd870 | 177 | |
29172908 | 178 | m_hOldBitmap = (WXHBITMAP)::GpiSetBitmap(m_hPS, NULLHANDLE); |
23122f8c | 179 | return; |
29172908 | 180 | } |
23122f8c | 181 | m_vSelectedBitmap.SetSelectedInto(this); |
29172908 | 182 | m_hOldBitmap = (WXHBITMAP)::GpiSetBitmap(m_hPS, (HBITMAP)hBmp); |
23122f8c | 183 | |
29172908 | 184 | if (m_hOldBitmap == HBM_ERROR) |
23122f8c DW |
185 | { |
186 | wxLogLastError(wxT("SelectObject(memDC, bitmap)")); | |
187 | wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC")); | |
188 | } | |
23122f8c DW |
189 | } // end of wxMemoryDC::SelectObject |
190 | ||
191 | void wxMemoryDC::DoGetSize( | |
192 | int* pWidth | |
193 | , int* pHeight | |
194 | ) const | |
0e320a79 | 195 | { |
23122f8c DW |
196 | if (!m_vSelectedBitmap.Ok()) |
197 | { | |
198 | *pWidth = 0; | |
199 | *pHeight = 0; | |
200 | return; | |
201 | } | |
202 | *pWidth = m_vSelectedBitmap.GetWidth(); | |
203 | *pHeight = m_vSelectedBitmap.GetHeight(); | |
204 | } // end of wxMemoryDC::DoGetSize | |
0e320a79 | 205 |