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