]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/brush.cpp
Applied patch [ 1435340 ] Add support of wxToggleButton to wxGenericValidator
[wxWidgets.git] / src / gtk1 / brush.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
3cbab641 2// Name: src/gtk1/brush.cpp
c801d85f
KB
3// Purpose:
4// Author: Robert Roebling
f96aa4d9 5// Id: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling
65571936 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
c801d85f 13#include "wx/brush.h"
ed39ff57 14#include "wx/colour.h"
c801d85f 15
20e05ffb 16#include <gdk/gdk.h>
83624f79 17
c801d85f
KB
18//-----------------------------------------------------------------------------
19// wxBrush
20//-----------------------------------------------------------------------------
21
22class wxBrushRefData: public wxObjectRefData
23{
58c837a4 24public:
c89f5c02
RR
25 wxBrushRefData()
26 {
27 m_style = 0;
28 }
46562151 29
c89f5c02 30 wxBrushRefData( const wxBrushRefData& data )
d84afea9 31 : wxObjectRefData()
c89f5c02
RR
32 {
33 m_style = data.m_style;
34 m_stipple = data.m_stipple;
35 m_colour = data.m_colour;
36 }
46562151 37
c89f5c02
RR
38 bool operator == (const wxBrushRefData& data) const
39 {
40 return (m_style == data.m_style &&
41 m_stipple == data.m_stipple &&
42 m_colour == data.m_colour);
43 }
46562151 44
c89f5c02
RR
45 int m_style;
46 wxColour m_colour;
47 wxBitmap m_stipple;
c801d85f
KB
48};
49
c801d85f
KB
50//-----------------------------------------------------------------------------
51
52#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
53
54IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
55
debe6624 56wxBrush::wxBrush( const wxColour &colour, int style )
c801d85f 57{
58c837a4
RR
58 m_refData = new wxBrushRefData();
59 M_BRUSHDATA->m_style = style;
60 M_BRUSHDATA->m_colour = colour;
ff7b1510 61}
c801d85f 62
c801d85f
KB
63wxBrush::wxBrush( const wxBitmap &stippleBitmap )
64{
58c837a4 65 m_refData = new wxBrushRefData();
58c837a4 66 M_BRUSHDATA->m_colour = *wxBLACK;
7ecb8b06 67
58c837a4 68 M_BRUSHDATA->m_stipple = stippleBitmap;
e1208c31 69
de2d2cdc 70 if (M_BRUSHDATA->m_stipple.GetMask())
7ecb8b06
VZ
71 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
72 else
73 M_BRUSHDATA->m_style = wxSTIPPLE;
ff7b1510 74}
c801d85f 75
8bbe427f 76wxBrush::~wxBrush()
c801d85f 77{
c89f5c02 78 // m_refData unrefed in ~wxObject
ff7b1510 79}
c801d85f 80
c89f5c02 81wxObjectRefData *wxBrush::CreateRefData() const
c801d85f 82{
c89f5c02 83 return new wxBrushRefData;
ff7b1510 84}
c801d85f 85
c89f5c02 86wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const
c801d85f 87{
c89f5c02 88 return new wxBrushRefData(*(wxBrushRefData *)data);
ff7b1510 89}
c801d85f 90
c89f5c02 91bool wxBrush::operator == ( const wxBrush& brush ) const
c801d85f 92{
46562151
WS
93 if (m_refData == brush.m_refData) return true;
94
95 if (!m_refData || !brush.m_refData) return false;
96
c89f5c02 97 return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData );
ff7b1510 98}
c801d85f 99
8bbe427f 100int wxBrush::GetStyle() const
c801d85f 101{
58c837a4
RR
102 if (m_refData == NULL)
103 {
104 wxFAIL_MSG( wxT("invalid brush") );
105 return 0;
106 }
e55ad60e 107
58c837a4 108 return M_BRUSHDATA->m_style;
ff7b1510 109}
c801d85f 110
8bbe427f 111wxColour &wxBrush::GetColour() const
c801d85f 112{
58c837a4
RR
113 if (m_refData == NULL)
114 {
115 wxFAIL_MSG( wxT("invalid brush") );
116 return wxNullColour;
117 }
8bbe427f 118
58c837a4 119 return M_BRUSHDATA->m_colour;
ff7b1510 120}
c801d85f 121
8bbe427f 122wxBitmap *wxBrush::GetStipple() const
c801d85f 123{
58c837a4
RR
124 if (m_refData == NULL)
125 {
126 wxFAIL_MSG( wxT("invalid brush") );
127 return &wxNullBitmap;
128 }
8bbe427f 129
58c837a4 130 return &M_BRUSHDATA->m_stipple;
ff7b1510 131}
c801d85f 132
e55ad60e
RR
133void wxBrush::SetColour( const wxColour& col )
134{
c89f5c02 135 AllocExclusive();
46562151 136
58c837a4 137 M_BRUSHDATA->m_colour = col;
e55ad60e
RR
138}
139
1a1498c0 140void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
e55ad60e 141{
c89f5c02 142 AllocExclusive();
46562151 143
58c837a4 144 M_BRUSHDATA->m_colour.Set( r, g, b );
e55ad60e
RR
145}
146
147void wxBrush::SetStyle( int style )
148{
c89f5c02 149 AllocExclusive();
46562151 150
58c837a4 151 M_BRUSHDATA->m_style = style;
e55ad60e
RR
152}
153
154void wxBrush::SetStipple( const wxBitmap& stipple )
155{
c89f5c02 156 AllocExclusive();
46562151 157
58c837a4 158 M_BRUSHDATA->m_stipple = stipple;
de2d2cdc
VZ
159 if (M_BRUSHDATA->m_stipple.GetMask())
160 {
7ecb8b06
VZ
161 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
162 }
163 else
164 {
165 M_BRUSHDATA->m_style = wxSTIPPLE;
166 }
e55ad60e 167}