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