]> git.saurik.com Git - wxWidgets.git/blame - src/os2/brush.cpp
Weekly catch up and slider fixes.
[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"
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{
15f03b25
DW
104 BOOL bOk;
105 ERRORID vError;
106 wxString sError;
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);
140 wxLogError("Unable to set current color table to RGB mode. Error: %s\n", sError);
141 return FALSE;
142 }
143
144 if (M_BRUSHDATA->m_nStyle==wxTRANSPARENT)
37f214d5 145 {
37f214d5
DW
146 return TRUE;
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
211 bOk = ::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 );
218 if (!bOk)
219 {
220 vError = ::WinGetLastError(vHabmain);
221 sError = wxPMErrorToStr(vError);
222 wxLogError("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n", sError);
223 }
224 return bOk;
37f214d5 225 }
37f214d5 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
236bool wxBrush::FreeResource(
237 bool WXUNUSED(bForce)
238)
37f214d5
DW
239{
240 if (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush != 0))
241 {
37f214d5
DW
242 M_BRUSHDATA->m_hBrush = 0;
243 return TRUE;
244 }
245 else return FALSE;
15f03b25 246} // end of wxBrush::FreeResource
37f214d5
DW
247
248bool wxBrush::IsFree() const
249{
250 return (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush == 0));
15f03b25 251} // end of wxBrush::IsFree
37f214d5
DW
252
253void wxBrush::Unshare()
254{
15f03b25 255 //
37f214d5 256 // Don't change shared data
15f03b25 257 //
37f214d5
DW
258 if (!m_refData)
259 {
260 m_refData = new wxBrushRefData();
261 }
262 else
263 {
264 wxBrushRefData* ref = new wxBrushRefData(*(wxBrushRefData*)m_refData);
265 UnRef();
266 m_refData = ref;
267 }
15f03b25 268} // end of wxBrush::Unshare
0e320a79 269
15f03b25
DW
270void wxBrush::SetColour(
271 const wxColour& rColour
272)
0e320a79
DW
273{
274 Unshare();
15f03b25 275 M_BRUSHDATA->m_vColour = rColour;
0e320a79
DW
276 RealizeResource();
277}
278
15f03b25
DW
279void wxBrush::SetColour(
280 unsigned char cRed
281, unsigned char cGreen
282, unsigned char cBlue
283)
0e320a79
DW
284{
285 Unshare();
15f03b25
DW
286 M_BRUSHDATA->m_vColour.Set( cRed
287 ,cGreen
288 ,cBlue
289 );
0e320a79 290 RealizeResource();
15f03b25 291} // end of wxBrush::SetColour
0e320a79 292
15f03b25
DW
293void wxBrush::SetStyle(
294 int nStyle
295)
0e320a79
DW
296{
297 Unshare();
15f03b25 298 M_BRUSHDATA->m_nStyle = nStyle;
0e320a79 299 RealizeResource();
15f03b25 300} // end of wxBrush::SetStyle
0e320a79 301
15f03b25
DW
302void wxBrush::SetStipple(
303 const wxBitmap& rStipple
304)
0e320a79
DW
305{
306 Unshare();
15f03b25
DW
307 M_BRUSHDATA->m_vStipple = rStipple;
308 RealizeResource();
309} // end of wxBrush::SetStipple
0e320a79 310
15f03b25
DW
311void wxBrush::SetPS(
312 HPS hPS
313)
314{
315 Unshare();
316 if (M_BRUSHDATA->m_hBrush)
317 ::GpiDestroyPS(M_BRUSHDATA->m_hBrush);
318 M_BRUSHDATA->m_hBrush = hPS;
0e320a79 319 RealizeResource();
15f03b25 320} // end of WxWinGdi_CPen::SetPS
0e320a79 321