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