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