]> git.saurik.com Git - wxWidgets.git/blame - src/os2/dcmemory.cpp
more non-const string literal warnings correction
[wxWidgets.git] / src / os2 / dcmemory.cpp
CommitLineData
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 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
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 25IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC, wxDC)
0e320a79 26
23122f8c
DW
27/////////////////////////////////////////////////////////////////////////////
28// Memory DC
29/////////////////////////////////////////////////////////////////////////////
0e320a79
DW
30
31wxMemoryDC::wxMemoryDC(void)
32{
e1a688e4
DW
33 CreateCompatible(NULL);
34 Init();
23122f8c
DW
35} // end of wxMemoryDC::wxMemoryDC
36
37wxMemoryDC::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
47void 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
6670f564 61bool wxMemoryDC::CreateCompatible( wxDC* WXUNUSED(pDC) )
0e320a79 62{
6670f564
WS
63 HDC hDC;
64 HPS hPS;
65 DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
66 SIZEL vSize = {0, 0};
23122f8c 67
23122f8c
DW
68 //
69 // Create a memory device context
70 //
e1a688e4 71 hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
23122f8c
DW
72 if (hDC != DEV_ERROR)
73 {
74 hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
75 if (hPS != GPI_ERROR)
76 {
77 m_hPS = hPS;
78 m_hDC = hDC;
6670f564
WS
79 m_ok = true;
80 m_bOwnsDC = true;
e1a688e4 81 //
77ffb593 82 // Set the wxWidgets color table
e1a688e4
DW
83 //
84 ::GpiCreateLogColorTable( m_hPS
85 ,0L
86 ,LCOLF_CONSECRGB
87 ,0L
88 ,(LONG)wxTheColourDatabase->m_nSize
89 ,(PLONG)wxTheColourDatabase->m_palTable
90 );
91 ::GpiCreateLogColorTable( m_hPS
92 ,0L
93 ,LCOLF_RGB
94 ,0L
95 ,0L
96 ,NULL
97 );
23122f8c
DW
98 }
99 else
100 {
23122f8c
DW
101 m_hPS = NULLHANDLE;
102 m_hDC = NULLHANDLE;
103 m_ok = FALSE;
104 m_bOwnsDC = FALSE;
105 }
106 }
107 else
108 {
23122f8c
DW
109 m_hPS = NULLHANDLE;
110 m_hDC = NULLHANDLE;
111 m_ok = FALSE;
112 m_bOwnsDC = FALSE;
113 }
23122f8c 114
e1a688e4
DW
115 //
116 // As we created the DC, we must delete it in the dtor
117 //
6670f564 118 m_bOwnsDC = true;
e1a688e4
DW
119 m_ok = m_hDC != 0;
120 return m_ok;
121} // end of wxMemoryDC::CreateCompatible
23122f8c
DW
122
123void wxMemoryDC::SelectObject(
124 const wxBitmap& rBitmap
125)
0e320a79 126{
23122f8c
DW
127 //
128 // Select old bitmap out of the device context
129 //
130 if (m_hOldBitmap)
131 {
132 ::GpiSetBitmap(m_hPS, NULLHANDLE);
133 if (m_vSelectedBitmap.Ok())
134 {
135 m_vSelectedBitmap.SetSelectedInto(NULL);
136 m_vSelectedBitmap = wxNullBitmap;
137 }
138 }
139
140 //
141 // Check for whether the bitmap is already selected into a device context
142 //
143 wxCHECK_RET( !rBitmap.GetSelectedInto() ||
144 (rBitmap.GetSelectedInto() == this),
145 wxT("Bitmap is selected in another wxMemoryDC, delete the first wxMemoryDC or use SelectObject(NULL)") );
146
1c9a789e
DW
147 WXHBITMAP hBmp = rBitmap.GetHBITMAP();
148
149 if (!hBmp)
150 {
ad6bd870
DW
151 //
152 // Bmps drawn to are upside down, so flip it before committing
153 //
9923c37d
DW
154 POINTL vPoint[4] = { {0, m_vSelectedBitmap.GetHeight()}
155 ,{m_vSelectedBitmap.GetWidth(), 0}
156 ,{0, 0}
157 ,{m_vSelectedBitmap.GetWidth(), m_vSelectedBitmap.GetHeight()}
ad6bd870
DW
158 };
159
160
161 ::GpiBitBlt( m_hPS
162 ,m_hPS
163 ,4
164 ,vPoint
165 ,ROP_SRCCOPY
166 ,BBO_IGNORE
167 );
1c9a789e
DW
168 m_vSelectedBitmap.SetSelectedInto(NULL);
169 }
23122f8c
DW
170 m_vSelectedBitmap = rBitmap;
171
23122f8c
DW
172
173 if (!hBmp)
29172908 174 {
ad6bd870 175
29172908 176 m_hOldBitmap = (WXHBITMAP)::GpiSetBitmap(m_hPS, NULLHANDLE);
23122f8c 177 return;
29172908 178 }
23122f8c 179 m_vSelectedBitmap.SetSelectedInto(this);
29172908 180 m_hOldBitmap = (WXHBITMAP)::GpiSetBitmap(m_hPS, (HBITMAP)hBmp);
23122f8c 181
29172908 182 if (m_hOldBitmap == HBM_ERROR)
23122f8c
DW
183 {
184 wxLogLastError(wxT("SelectObject(memDC, bitmap)"));
185 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
186 }
23122f8c
DW
187} // end of wxMemoryDC::SelectObject
188
189void wxMemoryDC::DoGetSize(
190 int* pWidth
191, int* pHeight
192) const
0e320a79 193{
23122f8c
DW
194 if (!m_vSelectedBitmap.Ok())
195 {
196 *pWidth = 0;
197 *pHeight = 0;
198 return;
199 }
200 *pWidth = m_vSelectedBitmap.GetWidth();
201 *pHeight = m_vSelectedBitmap.GetHeight();
202} // end of wxMemoryDC::DoGetSize