]> git.saurik.com Git - wxWidgets.git/blame - src/os2/dcmemory.cpp
Changed code to get rid of a compiler warning about statement always being FALSE
[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
DW
8// Copyright: (c) David Webster
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"
0e320a79
DW
17#endif
18
fb46a9a6
DW
19#include "wx/os2/private.h"
20
0e320a79
DW
21#include "wx/dcmemory.h"
22
fb46a9a6 23IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC, wxDC)
0e320a79 24
23122f8c
DW
25/////////////////////////////////////////////////////////////////////////////
26// Memory DC
27/////////////////////////////////////////////////////////////////////////////
0e320a79
DW
28
29wxMemoryDC::wxMemoryDC(void)
30{
e1a688e4
DW
31 CreateCompatible(NULL);
32 Init();
23122f8c
DW
33} // end of wxMemoryDC::wxMemoryDC
34
35wxMemoryDC::wxMemoryDC(
36 wxDC* pOldDC
37)
e1a688e4
DW
38{
39 pOldDC->BeginDrawing();
40 CreateCompatible(pOldDC);
41 pOldDC->EndDrawing();
42 Init();
43} // end of wxMemoryDC::wxMemoryDC
44
45void 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 }
56} // end of wxMemoryDC::Init
57
58bool wxMemoryDC::CreateCompatible(
59 wxDC* pDC
60)
0e320a79 61{
23122f8c
DW
62 HDC hDC;
63 HPS hPS;
64 DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
65 SIZEL vSize = {0, 0};
66
23122f8c
DW
67 //
68 // Create a memory device context
69 //
e1a688e4 70 hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
23122f8c
DW
71 if (hDC != DEV_ERROR)
72 {
73 hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
74 if (hPS != GPI_ERROR)
75 {
76 m_hPS = hPS;
77 m_hDC = hDC;
78 m_ok = TRUE;
79 m_bOwnsDC = TRUE;
e1a688e4
DW
80 //
81 // Set the wxWindows color table
82 //
83 ::GpiCreateLogColorTable( m_hPS
84 ,0L
85 ,LCOLF_CONSECRGB
86 ,0L
87 ,(LONG)wxTheColourDatabase->m_nSize
88 ,(PLONG)wxTheColourDatabase->m_palTable
89 );
90 ::GpiCreateLogColorTable( m_hPS
91 ,0L
92 ,LCOLF_RGB
93 ,0L
94 ,0L
95 ,NULL
96 );
23122f8c
DW
97 }
98 else
99 {
23122f8c
DW
100 m_hPS = NULLHANDLE;
101 m_hDC = NULLHANDLE;
102 m_ok = FALSE;
103 m_bOwnsDC = FALSE;
104 }
105 }
106 else
107 {
23122f8c
DW
108 m_hPS = NULLHANDLE;
109 m_hDC = NULLHANDLE;
110 m_ok = FALSE;
111 m_bOwnsDC = FALSE;
112 }
23122f8c 113
e1a688e4
DW
114 //
115 // As we created the DC, we must delete it in the dtor
116 //
117 m_bOwnsDC = TRUE;
118 m_ok = m_hDC != 0;
119 return m_ok;
120} // end of wxMemoryDC::CreateCompatible
23122f8c
DW
121
122void wxMemoryDC::SelectObject(
123 const wxBitmap& rBitmap
124)
0e320a79 125{
23122f8c
DW
126 //
127 // Select old bitmap out of the device context
128 //
129 if (m_hOldBitmap)
130 {
131 ::GpiSetBitmap(m_hPS, NULLHANDLE);
132 if (m_vSelectedBitmap.Ok())
133 {
134 m_vSelectedBitmap.SetSelectedInto(NULL);
135 m_vSelectedBitmap = wxNullBitmap;
136 }
137 }
138
139 //
140 // Check for whether the bitmap is already selected into a device context
141 //
142 wxCHECK_RET( !rBitmap.GetSelectedInto() ||
143 (rBitmap.GetSelectedInto() == this),
144 wxT("Bitmap is selected in another wxMemoryDC, delete the first wxMemoryDC or use SelectObject(NULL)") );
145
146 m_vSelectedBitmap = rBitmap;
147
148 WXHBITMAP hBmp = m_vSelectedBitmap.GetHBITMAP();
149
150 if (!hBmp)
151 return;
152
153 m_vSelectedBitmap.SetSelectedInto(this);
154 hBmp = (WXHBITMAP)::GpiSetBitmap(m_hPS, (HBITMAP)hBmp);
155
5afb9458 156 if (hBmp == HBM_ERROR)
23122f8c
DW
157 {
158 wxLogLastError(wxT("SelectObject(memDC, bitmap)"));
159 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
160 }
161 else if (!m_hOldBitmap)
162 {
163 m_hOldBitmap = hBmp;
164 }
165} // end of wxMemoryDC::SelectObject
166
167void wxMemoryDC::DoGetSize(
168 int* pWidth
169, int* pHeight
170) const
0e320a79 171{
23122f8c
DW
172 if (!m_vSelectedBitmap.Ok())
173 {
174 *pWidth = 0;
175 *pHeight = 0;
176 return;
177 }
178 *pWidth = m_vSelectedBitmap.GetWidth();
179 *pHeight = m_vSelectedBitmap.GetHeight();
180} // end of wxMemoryDC::DoGetSize
0e320a79 181
e1a688e4
DW
182void wxMemoryDC::DoDrawRectangle(
183 wxCoord vX
184, wxCoord vY
185, wxCoord vWidth
186, wxCoord vHeight
187)
188{
189 wxDC::DoDrawRectangle(vX, vY, vWidth, vHeight);
190} // end of wxMemoryDC::DoDrawRectangle