]> git.saurik.com Git - wxWidgets.git/blame - src/x11/brush.cpp
Add a section about STL containers-related incompatible changes.
[wxWidgets.git] / src / x11 / brush.cpp
CommitLineData
83df96d6 1/////////////////////////////////////////////////////////////////////////////
7266b672 2// Name: src/x11/brush.cpp
83df96d6
JS
3// Purpose: wxBrush
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
83df96d6
JS
10/////////////////////////////////////////////////////////////////////////////
11
55034339
WS
12// for compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
83df96d6 15#include "wx/brush.h"
de6185e2
WS
16
17#ifndef WX_PRECOMP
18 #include "wx/utils.h"
0bca0373 19 #include "wx/bitmap.h"
7cf41a5d 20 #include "wx/colour.h"
de6185e2
WS
21#endif
22
74dc5eb6
RR
23//-----------------------------------------------------------------------------
24// wxBrush
25//-----------------------------------------------------------------------------
83df96d6 26
8f884a0d 27class wxBrushRefData : public wxGDIRefData
83df96d6 28{
74dc5eb6
RR
29public:
30 wxBrushRefData()
31 {
2051c39f 32 m_style = wxBRUSHSTYLE_INVALID;
74dc5eb6 33 }
55034339 34
74dc5eb6
RR
35 wxBrushRefData( const wxBrushRefData& data )
36 {
37 m_style = data.m_style;
38 m_stipple = data.m_stipple;
39 m_colour = data.m_colour;
40 }
55034339 41
74dc5eb6
RR
42 bool operator == (const wxBrushRefData& data) const
43 {
44 return (m_style == data.m_style &&
4de63828 45 m_stipple.IsSameAs(data.m_stipple) &&
74dc5eb6
RR
46 m_colour == data.m_colour);
47 }
55034339 48
3e6858cd
FM
49 wxBrushStyle m_style;
50 wxColour m_colour;
51 wxBitmap m_stipple;
74dc5eb6 52};
83df96d6 53
74dc5eb6 54//-----------------------------------------------------------------------------
83df96d6 55
74dc5eb6
RR
56#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
57
58IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
59
3e6858cd 60wxBrush::wxBrush( const wxColour &colour, wxBrushStyle style )
83df96d6 61{
74dc5eb6
RR
62 m_refData = new wxBrushRefData();
63 M_BRUSHDATA->m_style = style;
64 M_BRUSHDATA->m_colour = colour;
83df96d6
JS
65}
66
ac3688c0
FM
67#if FUTURE_WXWIN_COMPATIBILITY_3_0
68wxBrush::wxBrush(const wxColour& col, int style)
69{
70 m_refData = new wxBrushRefData;
71 M_BRUSHDATA->m_style = (wxBrushStyle)style;
2051c39f 72 M_BRUSHDATA->m_colour = col;
ac3688c0
FM
73}
74#endif
75
74dc5eb6 76wxBrush::wxBrush( const wxBitmap &stippleBitmap )
83df96d6 77{
74dc5eb6
RR
78 m_refData = new wxBrushRefData();
79 M_BRUSHDATA->m_colour = *wxBLACK;
80
81 M_BRUSHDATA->m_stipple = stippleBitmap;
82
83 if (M_BRUSHDATA->m_stipple.GetMask())
2051c39f 84 M_BRUSHDATA->m_style = wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE;
74dc5eb6 85 else
2051c39f 86 M_BRUSHDATA->m_style = wxBRUSHSTYLE_STIPPLE_MASK;
83df96d6
JS
87}
88
89wxBrush::~wxBrush()
90{
74dc5eb6 91 // m_refData unrefed in ~wxObject
83df96d6
JS
92}
93
8f884a0d 94wxGDIRefData *wxBrush::CreateGDIRefData() const
83df96d6 95{
74dc5eb6 96 return new wxBrushRefData;
83df96d6
JS
97}
98
8f884a0d 99wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const
83df96d6 100{
74dc5eb6
RR
101 return new wxBrushRefData(*(wxBrushRefData *)data);
102}
83df96d6 103
74dc5eb6
RR
104bool wxBrush::operator == ( const wxBrush& brush ) const
105{
55034339
WS
106 if (m_refData == brush.m_refData) return true;
107
108 if (!m_refData || !brush.m_refData) return false;
109
74dc5eb6 110 return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData );
83df96d6
JS
111}
112
3e6858cd 113wxBrushStyle wxBrush::GetStyle() const
83df96d6 114{
9a83f860 115 wxCHECK_MSG( Ok(), wxBRUSHSTYLE_INVALID, wxT("invalid brush") );
74dc5eb6
RR
116
117 return M_BRUSHDATA->m_style;
83df96d6
JS
118}
119
231b9591 120wxColour wxBrush::GetColour() const
83df96d6 121{
9a83f860 122 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid brush") );
83df96d6 123
74dc5eb6 124 return M_BRUSHDATA->m_colour;
83df96d6
JS
125}
126
74dc5eb6 127wxBitmap *wxBrush::GetStipple() const
83df96d6 128{
9a83f860 129 wxCHECK_MSG( Ok(), NULL, wxT("invalid brush") );
83df96d6 130
74dc5eb6 131 return &M_BRUSHDATA->m_stipple;
83df96d6
JS
132}
133
74dc5eb6 134void wxBrush::SetColour( const wxColour& col )
83df96d6 135{
74dc5eb6 136 AllocExclusive();
55034339 137
74dc5eb6 138 M_BRUSHDATA->m_colour = col;
83df96d6
JS
139}
140
1a1498c0 141void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
83df96d6 142{
74dc5eb6 143 AllocExclusive();
55034339 144
74dc5eb6 145 M_BRUSHDATA->m_colour.Set( r, g, b );
83df96d6
JS
146}
147
3e6858cd 148void wxBrush::SetStyle( wxBrushStyle style )
83df96d6 149{
74dc5eb6 150 AllocExclusive();
55034339 151
74dc5eb6 152 M_BRUSHDATA->m_style = style;
83df96d6
JS
153}
154
74dc5eb6
RR
155void wxBrush::SetStipple( const wxBitmap& stipple )
156{
157 AllocExclusive();
55034339 158
74dc5eb6
RR
159 M_BRUSHDATA->m_stipple = stipple;
160 if (M_BRUSHDATA->m_stipple.GetMask())
2051c39f 161 M_BRUSHDATA->m_style = wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE;
74dc5eb6 162 else
2051c39f 163 M_BRUSHDATA->m_style = wxBRUSHSTYLE_STIPPLE_MASK;
74dc5eb6 164}