]> git.saurik.com Git - wxWidgets.git/blame - src/msw/brush.cpp
wrong directory
[wxWidgets.git] / src / msw / brush.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: brush.cpp
3// Purpose: wxBrush
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "brush.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#include <stdio.h>
25#include "wx/setup.h"
26#include "wx/list.h"
27#include "wx/utils.h"
28#include "wx/app.h"
29#include "wx/brush.h"
30#endif
31
32#include "wx/msw/private.h"
33
34#include "assert.h"
35
2bda0e17 36IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject)
2bda0e17
KB
37
38wxBrushRefData::wxBrushRefData(void)
39{
40 m_style = wxSOLID;
b823f5a1
JS
41 m_hBrush = 0;
42}
43
44wxBrushRefData::wxBrushRefData(const wxBrushRefData& data)
45{
46 m_style = data.m_style;
47 m_stipple = data.m_stipple;
48 m_colour = data.m_colour;
2bda0e17
KB
49 m_hBrush = 0;
50}
51
52wxBrushRefData::~wxBrushRefData(void)
53{
54 if ( m_hBrush )
55 ::DeleteObject((HBRUSH) m_hBrush);
56}
57
58// Brushes
59wxBrush::wxBrush(void)
60{
2bda0e17
KB
61}
62
63wxBrush::~wxBrush()
64{
2bda0e17
KB
65}
66
debe6624 67wxBrush::wxBrush(const wxColour& col, int Style)
2bda0e17
KB
68{
69 m_refData = new wxBrushRefData;
70
71 M_BRUSHDATA->m_colour = col;
72 M_BRUSHDATA->m_style = Style;
73 M_BRUSHDATA->m_hBrush = 0;
74
75 RealizeResource();
76
2bda0e17
KB
77}
78
2bda0e17
KB
79wxBrush::wxBrush(const wxBitmap& stipple)
80{
81 m_refData = new wxBrushRefData;
82
2bda0e17 83 M_BRUSHDATA->m_stipple = stipple;
de2d2cdc
VZ
84 if (M_BRUSHDATA->m_stipple.GetMask())
85 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
86 else
87 M_BRUSHDATA->m_style = wxSTIPPLE;
88
2bda0e17
KB
89 M_BRUSHDATA->m_hBrush = 0;
90
91 RealizeResource();
92
2bda0e17
KB
93}
94
de2d2cdc 95bool wxBrush::RealizeResource(void)
2bda0e17
KB
96{
97 if (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush == 0))
98 {
99 if (M_BRUSHDATA->m_style==wxTRANSPARENT)
100 {
101 M_BRUSHDATA->m_hBrush = (WXHBRUSH) ::GetStockObject(NULL_BRUSH);
102 return TRUE;
103 }
104 COLORREF ms_colour = 0 ;
105
106 ms_colour = M_BRUSHDATA->m_colour.GetPixel() ;
107
108 switch (M_BRUSHDATA->m_style)
109 {
110/****
111 // Don't reset cbrush, wxTRANSPARENT is handled by wxBrush::SelectBrush()
112 // this could save (many) time if frequently switching from
113 // wxSOLID to wxTRANSPARENT, because Create... is not always called!!
114 //
115 // NB August 95: now create and select a Null brush instead.
116 // This could be optimized as above.
117 case wxTRANSPARENT:
118 M_BRUSHDATA->m_hBrush = NULL; // Must always select a suitable background brush
119 // - could choose white always for a quick solution
120 break;
121***/
04ef50df 122#ifndef __WXMICROWIN__
2bda0e17
KB
123 case wxBDIAGONAL_HATCH:
124 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_BDIAGONAL,ms_colour) ;
125 break ;
126 case wxCROSSDIAG_HATCH:
127 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_DIAGCROSS,ms_colour) ;
128 break ;
129 case wxFDIAGONAL_HATCH:
130 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_FDIAGONAL,ms_colour) ;
131 break ;
132 case wxCROSS_HATCH:
133 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_CROSS,ms_colour) ;
134 break ;
135 case wxHORIZONTAL_HATCH:
136 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_HORIZONTAL,ms_colour) ;
137 break ;
138 case wxVERTICAL_HATCH:
139 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_VERTICAL,ms_colour) ;
140 break ;
141 case wxSTIPPLE:
142 if (M_BRUSHDATA->m_stipple.Ok())
143 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreatePatternBrush((HBITMAP) M_BRUSHDATA->m_stipple.GetHBITMAP()) ;
144 else
145 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateSolidBrush(ms_colour) ;
146 break ;
de2d2cdc
VZ
147 case wxSTIPPLE_MASK_OPAQUE:
148 if (M_BRUSHDATA->m_stipple.Ok() && M_BRUSHDATA->m_stipple.GetMask())
149 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreatePatternBrush((HBITMAP) M_BRUSHDATA->m_stipple.GetMask()->GetMaskBitmap());
150 else
151 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateSolidBrush(ms_colour) ;
152 break ;
04ef50df 153#endif
2bda0e17
KB
154 case wxSOLID:
155 default:
156 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateSolidBrush(ms_colour) ;
157 break;
158 }
b2aef89b 159#ifdef WXDEBUG_CREATE
2bda0e17
KB
160 if (M_BRUSHDATA->m_hBrush==NULL) wxError("Cannot create brush","Internal error") ;
161#endif
162 return TRUE;
163 }
164 else
165 return FALSE;
166}
167
168WXHANDLE wxBrush::GetResourceHandle(void)
169{
170 return (WXHANDLE) M_BRUSHDATA->m_hBrush;
171}
172
57c208c5 173bool wxBrush::FreeResource(bool WXUNUSED(force))
2bda0e17
KB
174{
175 if (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush != 0))
176 {
177 DeleteObject((HBRUSH) M_BRUSHDATA->m_hBrush);
178 M_BRUSHDATA->m_hBrush = 0;
179 return TRUE;
180 }
181 else return FALSE;
182}
183
e90babdf 184bool wxBrush::IsFree() const
2bda0e17 185{
b823f5a1 186 return (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush == 0));
2bda0e17
KB
187}
188
b823f5a1 189void wxBrush::Unshare()
2bda0e17 190{
b823f5a1
JS
191 // Don't change shared data
192 if (!m_refData)
193 {
194 m_refData = new wxBrushRefData();
195 }
196 else
197 {
198 wxBrushRefData* ref = new wxBrushRefData(*(wxBrushRefData*)m_refData);
199 UnRef();
200 m_refData = ref;
201 }
2bda0e17 202}
2bda0e17 203
2bda0e17
KB
204
205void wxBrush::SetColour(const wxColour& col)
206{
b823f5a1 207 Unshare();
2bda0e17 208
b823f5a1 209 M_BRUSHDATA->m_colour = col;
2bda0e17 210
2bda0e17
KB
211 RealizeResource();
212}
213
e4a81a2e 214void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b)
2bda0e17 215{
b823f5a1 216 Unshare();
2bda0e17 217
b823f5a1 218 M_BRUSHDATA->m_colour.Set(r, g, b);
2bda0e17 219
2bda0e17
KB
220 RealizeResource();
221}
222
debe6624 223void wxBrush::SetStyle(int Style)
2bda0e17 224{
b823f5a1 225 Unshare();
2bda0e17 226
b823f5a1 227 M_BRUSHDATA->m_style = Style;
2bda0e17 228
2bda0e17
KB
229 RealizeResource();
230}
231
232void wxBrush::SetStipple(const wxBitmap& Stipple)
233{
b823f5a1 234 Unshare();
2bda0e17 235
b823f5a1 236 M_BRUSHDATA->m_stipple = Stipple;
de2d2cdc
VZ
237 if (M_BRUSHDATA->m_stipple.GetMask())
238 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
239 else
240 M_BRUSHDATA->m_style = wxSTIPPLE;
2bda0e17 241
2bda0e17
KB
242 RealizeResource();
243}
244
245