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