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