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