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