]> git.saurik.com Git - wxWidgets.git/blob - src/os2/dcmemory.cpp
Add missing c_str() call to fix wxGTK ANSI+STL build.
[wxWidgets.git] / src / os2 / dcmemory.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/dcmemory.cpp
3 // Purpose: wxMemoryDC class
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/14/99
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #include "wx/dcmemory.h"
15 #include "wx/os2/dcmemory.h"
16
17 #ifndef WX_PRECOMP
18 #include "wx/utils.h"
19 #include "wx/app.h"
20 #include "wx/log.h"
21 #endif
22
23 #include "wx/os2/private.h"
24
25 IMPLEMENT_ABSTRACT_CLASS(wxMemoryDCImpl, wxPMDCImpl)
26
27 /////////////////////////////////////////////////////////////////////////////
28 // Memory DC
29 /////////////////////////////////////////////////////////////////////////////
30
31 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner )
32 : wxPMDCImpl( owner )
33 {
34 CreateCompatible(NULL);
35 Init();
36 }
37
38 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxBitmap& bitmap )
39 : wxPMDCImpl( owner )
40 {
41 CreateCompatible(NULL);
42 Init();
43 DoSelect(bitmap);
44 }
45
46 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxDC *pOldDC)
47 : wxPMDCImpl( owner )
48 {
49 wxCHECK_RET( pOldDC, wxT("NULL dc in wxMemoryDC ctor") );
50
51 CreateCompatible(pOldDC);
52 Init();
53 } // end of wxMemoryDC::wxMemoryDC
54
55 void wxMemoryDCImpl::Init()
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 }
66 memset(&m_vRclPaint, 0, sizeof(m_vRclPaint));
67 } // end of wxMemoryDC::Init
68
69 bool wxMemoryDCImpl::CreateCompatible( wxDC* WXUNUSED(pDC) )
70 {
71 HDC hDC;
72 HPS hPS;
73 DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
74 SIZEL vSize = {0, 0};
75
76 //
77 // Create a memory device context
78 //
79 hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
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;
87 m_ok = true;
88 m_bOwnsDC = true;
89 //
90 // Set the wxWidgets color table
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 );
106 }
107 else
108 {
109 m_hPS = NULLHANDLE;
110 m_hDC = NULLHANDLE;
111 m_ok = false;
112 m_bOwnsDC = false;
113 }
114 }
115 else
116 {
117 m_hPS = NULLHANDLE;
118 m_hDC = NULLHANDLE;
119 m_ok = false;
120 m_bOwnsDC = false;
121 }
122
123 //
124 // As we created the DC, we must delete it in the dtor
125 //
126 m_bOwnsDC = true;
127 m_ok = m_hDC != 0;
128 return m_ok;
129 } // end of wxMemoryDC::CreateCompatible
130
131 void wxMemoryDCImpl::DoSelect(
132 const wxBitmap& rBitmap
133 )
134 {
135 //
136 // Select old bitmap out of the device context
137 //
138 if (m_hOldBitmap)
139 {
140 ::GpiSetBitmap(m_hPS, NULLHANDLE);
141 if (m_vSelectedBitmap.IsOk())
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() ||
152 (rBitmap.GetSelectedInto() == GetOwner()),
153 wxT("Bitmap is selected in another wxMemoryDC, delete the first wxMemoryDC or use SelectObject(NULL)") );
154
155 WXHBITMAP hBmp = rBitmap.GetHBITMAP();
156
157 if (!hBmp)
158 {
159 //
160 // Bmps drawn to are upside down, so flip it before committing
161 //
162 POINTL vPoint[4] = { {0, m_vSelectedBitmap.GetHeight()}
163 ,{m_vSelectedBitmap.GetWidth(), 0}
164 ,{0, 0}
165 ,{m_vSelectedBitmap.GetWidth(), m_vSelectedBitmap.GetHeight()}
166 };
167
168
169 ::GpiBitBlt( m_hPS
170 ,m_hPS
171 ,4
172 ,vPoint
173 ,ROP_SRCCOPY
174 ,BBO_IGNORE
175 );
176 m_vSelectedBitmap.SetSelectedInto(NULL);
177 }
178
179 m_vSelectedBitmap = rBitmap;
180
181
182 if (!hBmp)
183 {
184
185 m_hOldBitmap = (WXHBITMAP)::GpiSetBitmap(m_hPS, NULLHANDLE);
186 return;
187 }
188 m_vSelectedBitmap.SetSelectedInto(GetOwner());
189 m_hOldBitmap = (WXHBITMAP)::GpiSetBitmap(m_hPS, (HBITMAP)hBmp);
190
191 if (m_hOldBitmap == HBM_ERROR)
192 {
193 wxLogLastError(wxT("SelectObject(memDC, bitmap)"));
194 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
195 }
196 } // end of wxMemoryDC::SelectObject
197
198 void wxMemoryDCImpl::DoGetSize(
199 int* pWidth
200 , int* pHeight
201 ) const
202 {
203 if (!m_vSelectedBitmap.IsOk())
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