]> git.saurik.com Git - wxWidgets.git/blame - src/os2/brush.cpp
rtti api mods added
[wxWidgets.git] / src / os2 / brush.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: brush.cpp
3// Purpose: wxBrush
37f214d5 4// Author: David Webster
0e320a79 5// Modified by:
37f214d5 6// Created: 10/13/99
0e320a79 7// RCS-ID: $Id$
37f214d5
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
37f214d5
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
0e320a79 14
37f214d5
DW
15#ifndef WX_PRECOMP
16#include <stdio.h>
0e320a79 17#include "wx/setup.h"
37f214d5 18#include "wx/list.h"
0e320a79 19#include "wx/utils.h"
37f214d5 20#include "wx/app.h"
0e320a79 21#include "wx/brush.h"
6eb280e9 22#include "wx/log.h"
37f214d5
DW
23#endif
24
25#include "wx/os2/private.h"
26
27#include "assert.h"
0e320a79 28
0e320a79 29IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject)
0e320a79
DW
30
31wxBrushRefData::wxBrushRefData()
32{
15f03b25 33 m_nStyle = wxSOLID;
37f214d5 34 m_hBrush = 0;
15f03b25
DW
35 memset(&m_vBundle, '\0', sizeof(AREABUNDLE));
36} // end of wxBrushRefData::wxBrushRefData
0e320a79 37
15f03b25
DW
38wxBrushRefData::wxBrushRefData(
39 const wxBrushRefData& rData
40)
0e320a79 41{
15f03b25
DW
42 m_nStyle = rData.m_nStyle;
43 m_vStipple = rData.m_vStipple;
44 m_vColour = rData.m_vColour;
45 m_hBrush = 0;
46 memcpy(&m_vBundle, &rData.m_vBundle, sizeof(AREABUNDLE));
47} // end of wxBrushRefData::wxBrushRefData
0e320a79
DW
48
49wxBrushRefData::~wxBrushRefData()
50{
15f03b25 51} // end of wxBrushRefData::~wxBrushRefData
0e320a79 52
15f03b25 53//
0e320a79 54// Brushes
15f03b25 55//
0e320a79
DW
56wxBrush::wxBrush()
57{
58 if ( wxTheBrushList )
59 wxTheBrushList->AddBrush(this);
15f03b25 60} // end of wxBrush::wxBrush
0e320a79
DW
61
62wxBrush::~wxBrush()
63{
64 if ( wxTheBrushList )
65 wxTheBrushList->RemoveBrush(this);
15f03b25 66} // end of wxBrush::~wxBrush
0e320a79 67
15f03b25
DW
68wxBrush::wxBrush(
69 const wxColour& rColour
70, int nStyle
71)
0e320a79
DW
72{
73 m_refData = new wxBrushRefData;
74
15f03b25
DW
75 M_BRUSHDATA->m_vColour = rColour;
76 M_BRUSHDATA->m_nStyle = nStyle;
77 M_BRUSHDATA->m_hBrush = 0;
78 memset(&M_BRUSHDATA->m_vBundle, '\0', sizeof(AREABUNDLE));
0e320a79
DW
79
80 RealizeResource();
81
82 if ( wxTheBrushList )
83 wxTheBrushList->AddBrush(this);
15f03b25 84} // end of wxBrush::wxBrush
0e320a79 85
15f03b25
DW
86wxBrush::wxBrush(
87 const wxBitmap& rStipple
88)
0e320a79
DW
89{
90 m_refData = new wxBrushRefData;
91
15f03b25
DW
92 M_BRUSHDATA->m_nStyle = wxSTIPPLE;
93 M_BRUSHDATA->m_vStipple = rStipple;
94 M_BRUSHDATA->m_hBrush = 0;
95 memset(&M_BRUSHDATA->m_vBundle, '\0', sizeof(AREABUNDLE));
0e320a79
DW
96
97 RealizeResource();
98
99 if ( wxTheBrushList )
100 wxTheBrushList->AddBrush(this);
15f03b25 101} // end of wxBrush::wxBrush
0e320a79 102
15f03b25 103bool wxBrush::RealizeResource()
37f214d5 104{
15f03b25
DW
105 BOOL bOk;
106 ERRORID vError;
107 wxString sError;
108
109 if (M_BRUSHDATA && M_BRUSHDATA->m_hBrush == 0L)
37f214d5 110 {
15f03b25
DW
111 SIZEL vSize = {0, 0};
112 DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
113 HDC hDC = ::DevOpenDC( vHabmain
114 ,OD_MEMORY
115 ,"*"
116 ,5L
117 ,(PDEVOPENDATA)&vDop
118 ,NULLHANDLE
119 );
120 M_BRUSHDATA->m_hBrush = (WXHPEN)::GpiCreatePS( vHabmain
121 ,hDC
122 ,&vSize
123 ,PU_PELS | GPIT_MICRO | GPIA_ASSOC
124 );
125 }
126 if (M_BRUSHDATA)
127 {
128 //
129 // Set the color table to RGB mode
130 //
131 if (!::GpiCreateLogColorTable( (HPS)M_BRUSHDATA->m_hBrush
132 ,0L
133 ,LCOLF_RGB
134 ,0L
135 ,0L
136 ,NULL
137 ))
138 {
139 vError = ::WinGetLastError(vHabmain);
140 sError = wxPMErrorToStr(vError);
141 wxLogError("Unable to set current color table to RGB mode. Error: %s\n", sError);
142 return FALSE;
143 }
144
145 if (M_BRUSHDATA->m_nStyle==wxTRANSPARENT)
37f214d5 146 {
37f214d5
DW
147 return TRUE;
148 }
15f03b25 149 COLORREF vPmColour = 0L;
37f214d5 150
15f03b25 151 vPmColour = M_BRUSHDATA->m_vColour.GetPixel() ;
37f214d5 152
15f03b25
DW
153 M_BRUSHDATA->m_vBundle.usSet = LCID_DEFAULT;
154 switch (M_BRUSHDATA->m_nStyle)
37f214d5 155 {
15f03b25
DW
156 case wxTRANSPARENT:
157 M_BRUSHDATA->m_hBrush = NULL; // Must always select a suitable background brush
158 break; // - could choose white always for a quick solution
159
37f214d5 160 case wxBDIAGONAL_HATCH:
15f03b25
DW
161 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_DIAG3;
162 break;
37f214d5
DW
163
164 case wxCROSSDIAG_HATCH:
15f03b25
DW
165 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_DIAGHATCH;
166 break;
37f214d5
DW
167
168 case wxFDIAGONAL_HATCH:
15f03b25
DW
169 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_DIAG1;
170 break;
37f214d5
DW
171
172 case wxCROSS_HATCH:
15f03b25
DW
173 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_HATCH;
174 break;
37f214d5
DW
175
176 case wxHORIZONTAL_HATCH:
15f03b25
DW
177 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_HORIZ;
178 break;
37f214d5
DW
179
180 case wxVERTICAL_HATCH:
15f03b25
DW
181 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_VERT;
182 break;
37f214d5
DW
183
184 case wxSTIPPLE:
15f03b25
DW
185 if (M_BRUSHDATA->m_vStipple.Ok())
186 {
187 ::GpiSetBitmapId( M_BRUSHDATA->m_hBrush
188 ,(USHORT)M_BRUSHDATA->m_vStipple.GetHBITMAP()
189 ,(USHORT)M_BRUSHDATA->m_vStipple.GetId()
190 );
191 ::GpiSetPatternSet( M_BRUSHDATA->m_hBrush
192 ,(USHORT)M_BRUSHDATA->m_vStipple.GetId()
193 );
194 }
37f214d5 195 else
15f03b25 196 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_SOLID;
37f214d5
DW
197 break ;
198
199 case wxSOLID:
200 default:
15f03b25 201 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_SOLID;
37f214d5
DW
202 break;
203 }
204#ifdef WXDEBUG_CREATE
205 if (M_BRUSHDATA->m_hBrush==NULL) wxError("Cannot create brush","Internal error") ;
206#endif
15f03b25 207 M_BRUSHDATA->m_vBundle.lColor = vPmColour;
8d854fa9 208 M_BRUSHDATA->m_vBundle.lBackColor = RGB_WHITE;
15f03b25
DW
209 M_BRUSHDATA->m_vBundle.usMixMode = FM_OVERPAINT;
210 M_BRUSHDATA->m_vBundle.usBackMixMode = BM_OVERPAINT;
211
212 bOk = ::GpiSetAttrs( M_BRUSHDATA->m_hBrush
213 ,PRIM_AREA
214 ,ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE |
215 ABB_SET | ABB_SYMBOL
216 ,ABB_REF_POINT
217 ,&M_BRUSHDATA->m_vBundle
218 );
219 if (!bOk)
220 {
221 vError = ::WinGetLastError(vHabmain);
222 sError = wxPMErrorToStr(vError);
223 wxLogError("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n", sError);
224 }
225 return bOk;
37f214d5 226 }
37f214d5 227 return FALSE;
15f03b25 228} // end of wxBrush::RealizeResource
37f214d5 229
15f03b25 230WXHANDLE wxBrush::GetResourceHandle()
37f214d5 231{
15f03b25
DW
232 if (!M_BRUSHDATA)
233 return 0;
234 return (WXHANDLE)M_BRUSHDATA->m_hBrush;
235} // end of wxBrush::GetResourceHandle
236
237bool wxBrush::FreeResource(
238 bool WXUNUSED(bForce)
239)
37f214d5
DW
240{
241 if (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush != 0))
242 {
37f214d5
DW
243 M_BRUSHDATA->m_hBrush = 0;
244 return TRUE;
245 }
246 else return FALSE;
15f03b25 247} // end of wxBrush::FreeResource
37f214d5
DW
248
249bool wxBrush::IsFree() const
250{
251 return (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush == 0));
15f03b25 252} // end of wxBrush::IsFree
37f214d5
DW
253
254void wxBrush::Unshare()
255{
15f03b25 256 //
37f214d5 257 // Don't change shared data
15f03b25 258 //
37f214d5
DW
259 if (!m_refData)
260 {
261 m_refData = new wxBrushRefData();
262 }
263 else
264 {
265 wxBrushRefData* ref = new wxBrushRefData(*(wxBrushRefData*)m_refData);
266 UnRef();
267 m_refData = ref;
268 }
15f03b25 269} // end of wxBrush::Unshare
0e320a79 270
15f03b25
DW
271void wxBrush::SetColour(
272 const wxColour& rColour
273)
0e320a79
DW
274{
275 Unshare();
15f03b25 276 M_BRUSHDATA->m_vColour = rColour;
0e320a79
DW
277 RealizeResource();
278}
279
15f03b25
DW
280void wxBrush::SetColour(
281 unsigned char cRed
282, unsigned char cGreen
283, unsigned char cBlue
284)
0e320a79
DW
285{
286 Unshare();
15f03b25
DW
287 M_BRUSHDATA->m_vColour.Set( cRed
288 ,cGreen
289 ,cBlue
290 );
0e320a79 291 RealizeResource();
15f03b25 292} // end of wxBrush::SetColour
0e320a79 293
15f03b25
DW
294void wxBrush::SetStyle(
295 int nStyle
296)
0e320a79
DW
297{
298 Unshare();
15f03b25 299 M_BRUSHDATA->m_nStyle = nStyle;
0e320a79 300 RealizeResource();
15f03b25 301} // end of wxBrush::SetStyle
0e320a79 302
15f03b25
DW
303void wxBrush::SetStipple(
304 const wxBitmap& rStipple
305)
0e320a79
DW
306{
307 Unshare();
15f03b25
DW
308 M_BRUSHDATA->m_vStipple = rStipple;
309 RealizeResource();
310} // end of wxBrush::SetStipple
0e320a79 311
15f03b25
DW
312void wxBrush::SetPS(
313 HPS hPS
314)
315{
316 Unshare();
317 if (M_BRUSHDATA->m_hBrush)
318 ::GpiDestroyPS(M_BRUSHDATA->m_hBrush);
319 M_BRUSHDATA->m_hBrush = hPS;
0e320a79 320 RealizeResource();
15f03b25 321} // end of WxWinGdi_CPen::SetPS
0e320a79 322