]> git.saurik.com Git - wxWidgets.git/blame - src/msw/brush.cpp
wxLogDebug/Trace in release mode now don't give compiler warnings
[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
36#if !USE_SHARED_LIBRARIES
37IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject)
38#endif
39
40wxBrushRefData::wxBrushRefData(void)
41{
42 m_style = wxSOLID;
43// m_stipple = NULL ;
44 m_hBrush = 0;
45}
46
47wxBrushRefData::~wxBrushRefData(void)
48{
49 if ( m_hBrush )
50 ::DeleteObject((HBRUSH) m_hBrush);
51}
52
53// Brushes
54wxBrush::wxBrush(void)
55{
56 if ( wxTheBrushList )
57 wxTheBrushList->AddBrush(this);
58}
59
60wxBrush::~wxBrush()
61{
62 if (wxTheBrushList)
63 wxTheBrushList->RemoveBrush(this);
64}
65
debe6624 66wxBrush::wxBrush(const wxColour& col, int Style)
2bda0e17
KB
67{
68 m_refData = new wxBrushRefData;
69
70 M_BRUSHDATA->m_colour = col;
71 M_BRUSHDATA->m_style = Style;
72 M_BRUSHDATA->m_hBrush = 0;
73
74 RealizeResource();
75
76 if ( wxTheBrushList )
77 wxTheBrushList->AddBrush(this);
78}
79
debe6624 80wxBrush::wxBrush(const wxString& col, int Style)
2bda0e17
KB
81{
82 m_refData = new wxBrushRefData;
83
84 M_BRUSHDATA->m_colour = col;
85 M_BRUSHDATA->m_style = Style;
86 M_BRUSHDATA->m_hBrush = 0;
87
88 RealizeResource();
89
90 if ( wxTheBrushList )
91 wxTheBrushList->AddBrush(this);
92}
93
94wxBrush::wxBrush(const wxBitmap& stipple)
95{
96 m_refData = new wxBrushRefData;
97
98 M_BRUSHDATA->m_style = wxSTIPPLE;
99 M_BRUSHDATA->m_stipple = stipple;
100 M_BRUSHDATA->m_hBrush = 0;
101
102 RealizeResource();
103
104 if ( wxTheBrushList )
105 wxTheBrushList->AddBrush(this);
106}
107
108bool wxBrush::RealizeResource(void)
109{
110 if (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush == 0))
111 {
112 if (M_BRUSHDATA->m_style==wxTRANSPARENT)
113 {
114 M_BRUSHDATA->m_hBrush = (WXHBRUSH) ::GetStockObject(NULL_BRUSH);
115 return TRUE;
116 }
117 COLORREF ms_colour = 0 ;
118
119 ms_colour = M_BRUSHDATA->m_colour.GetPixel() ;
120
121 switch (M_BRUSHDATA->m_style)
122 {
123/****
124 // Don't reset cbrush, wxTRANSPARENT is handled by wxBrush::SelectBrush()
125 // this could save (many) time if frequently switching from
126 // wxSOLID to wxTRANSPARENT, because Create... is not always called!!
127 //
128 // NB August 95: now create and select a Null brush instead.
129 // This could be optimized as above.
130 case wxTRANSPARENT:
131 M_BRUSHDATA->m_hBrush = NULL; // Must always select a suitable background brush
132 // - could choose white always for a quick solution
133 break;
134***/
135 case wxBDIAGONAL_HATCH:
136 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_BDIAGONAL,ms_colour) ;
137 break ;
138 case wxCROSSDIAG_HATCH:
139 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_DIAGCROSS,ms_colour) ;
140 break ;
141 case wxFDIAGONAL_HATCH:
142 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_FDIAGONAL,ms_colour) ;
143 break ;
144 case wxCROSS_HATCH:
145 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_CROSS,ms_colour) ;
146 break ;
147 case wxHORIZONTAL_HATCH:
148 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_HORIZONTAL,ms_colour) ;
149 break ;
150 case wxVERTICAL_HATCH:
151 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_VERTICAL,ms_colour) ;
152 break ;
153 case wxSTIPPLE:
154 if (M_BRUSHDATA->m_stipple.Ok())
155 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreatePatternBrush((HBITMAP) M_BRUSHDATA->m_stipple.GetHBITMAP()) ;
156 else
157 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateSolidBrush(ms_colour) ;
158 break ;
159 case wxSOLID:
160 default:
161 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateSolidBrush(ms_colour) ;
162 break;
163 }
b2aef89b 164#ifdef WXDEBUG_CREATE
2bda0e17
KB
165 if (M_BRUSHDATA->m_hBrush==NULL) wxError("Cannot create brush","Internal error") ;
166#endif
167 return TRUE;
168 }
169 else
170 return FALSE;
171}
172
173WXHANDLE wxBrush::GetResourceHandle(void)
174{
175 return (WXHANDLE) M_BRUSHDATA->m_hBrush;
176}
177
178bool wxBrush::FreeResource(bool force)
179{
180 if (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush != 0))
181 {
182 DeleteObject((HBRUSH) M_BRUSHDATA->m_hBrush);
183 M_BRUSHDATA->m_hBrush = 0;
184 return TRUE;
185 }
186 else return FALSE;
187}
188
189/*
190bool wxBrush::UseResource(void)
191{
192 IncrementResourceUsage();
193 return TRUE;
194}
195
196bool wxBrush::ReleaseResource(void)
197{
198 DecrementResourceUsage();
199 return TRUE;
200}
201*/
202
203bool wxBrush::IsFree(void)
204{
205 return (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush == 0));
206}
207
208void wxBrush::SetColour(const wxColour& col)
209{
210 if ( !M_BRUSHDATA )
211 m_refData = new wxBrushRefData;
212
213 M_BRUSHDATA->m_colour = col;
214
215 if (FreeResource())
216 RealizeResource();
217}
218
219void wxBrush::SetColour(const wxString& col)
220{
221 if ( !M_BRUSHDATA )
222 m_refData = new wxBrushRefData;
223
224 M_BRUSHDATA->m_colour = col;
225
226 if (FreeResource())
227 RealizeResource();
228}
229
230void wxBrush::SetColour(const unsigned char r, const unsigned char g, const unsigned char b)
231{
232 if ( !M_BRUSHDATA )
233 m_refData = new wxBrushRefData;
234
235 M_BRUSHDATA->m_colour.Set(r, g, b);
236
237 if (FreeResource())
238 RealizeResource();
239}
240
debe6624 241void wxBrush::SetStyle(int Style)
2bda0e17
KB
242{
243 if ( !M_BRUSHDATA )
244 m_refData = new wxBrushRefData;
245
246 M_BRUSHDATA->m_style = Style;
247
248 if (FreeResource())
249 RealizeResource();
250}
251
252void wxBrush::SetStipple(const wxBitmap& Stipple)
253{
254 if ( !M_BRUSHDATA )
255 m_refData = new wxBrushRefData;
256
257 M_BRUSHDATA->m_stipple = Stipple;
258
259 if (FreeResource())
260 RealizeResource();
261}
262
263