]> git.saurik.com Git - wxWidgets.git/blame - src/os2/dcmemory.cpp
implemented menu drawing in the GTK theme
[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"
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 }
58} // end of wxMemoryDC::Init
59
60bool wxMemoryDC::CreateCompatible(
61 wxDC* pDC
62)
0e320a79 63{
23122f8c
DW
64 HDC hDC;
65 HPS hPS;
66 DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
67 SIZEL vSize = {0, 0};
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;
80 m_ok = TRUE;
81 m_bOwnsDC = TRUE;
e1a688e4
DW
82 //
83 // Set the wxWindows color table
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;
104 m_ok = FALSE;
105 m_bOwnsDC = FALSE;
106 }
107 }
108 else
109 {
23122f8c
DW
110 m_hPS = NULLHANDLE;
111 m_hDC = NULLHANDLE;
112 m_ok = FALSE;
113 m_bOwnsDC = FALSE;
114 }
23122f8c 115
e1a688e4
DW
116 //
117 // As we created the DC, we must delete it in the dtor
118 //
119 m_bOwnsDC = TRUE;
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
148 m_vSelectedBitmap = rBitmap;
149
150 WXHBITMAP hBmp = m_vSelectedBitmap.GetHBITMAP();
151
152 if (!hBmp)
153 return;
154
155 m_vSelectedBitmap.SetSelectedInto(this);
156 hBmp = (WXHBITMAP)::GpiSetBitmap(m_hPS, (HBITMAP)hBmp);
157
5afb9458 158 if (hBmp == HBM_ERROR)
23122f8c
DW
159 {
160 wxLogLastError(wxT("SelectObject(memDC, bitmap)"));
161 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
162 }
163 else if (!m_hOldBitmap)
164 {
165 m_hOldBitmap = hBmp;
166 }
167} // end of wxMemoryDC::SelectObject
168
169void wxMemoryDC::DoGetSize(
170 int* pWidth
171, int* pHeight
172) const
0e320a79 173{
23122f8c
DW
174 if (!m_vSelectedBitmap.Ok())
175 {
176 *pWidth = 0;
177 *pHeight = 0;
178 return;
179 }
180 *pWidth = m_vSelectedBitmap.GetWidth();
181 *pHeight = m_vSelectedBitmap.GetHeight();
182} // end of wxMemoryDC::DoGetSize
0e320a79 183
e1a688e4
DW
184void wxMemoryDC::DoDrawRectangle(
185 wxCoord vX
186, wxCoord vY
187, wxCoord vWidth
188, wxCoord vHeight
189)
190{
191 wxDC::DoDrawRectangle(vX, vY, vWidth, vHeight);
192} // end of wxMemoryDC::DoDrawRectangle