]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/brush.cpp
reverted Chris' MSW additions patch (we should use IPC, not Windows-only functions...
[wxWidgets.git] / src / gtk / brush.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
7ecb8b06 2// Name: src/gtk/brush.cpp
c801d85f
KB
3// Purpose:
4// Author: Robert Roebling
f96aa4d9 5// Id: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling
7ecb8b06 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
11#pragma implementation "brush.h"
12#endif
13
14#include "wx/brush.h"
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 }
29
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 }
37
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 }
44
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{
c89f5c02
RR
93 if (m_refData == brush.m_refData) return TRUE;
94
95 if (!m_refData || !brush.m_refData) return FALSE;
96
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
RR
135 AllocExclusive();
136
58c837a4 137 M_BRUSHDATA->m_colour = col;
e55ad60e
RR
138}
139
e55ad60e
RR
140void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
141{
c89f5c02
RR
142 AllocExclusive();
143
58c837a4 144 M_BRUSHDATA->m_colour.Set( r, g, b );
e55ad60e
RR
145}
146
147void wxBrush::SetStyle( int style )
148{
c89f5c02
RR
149 AllocExclusive();
150
58c837a4 151 M_BRUSHDATA->m_style = style;
e55ad60e
RR
152}
153
154void wxBrush::SetStipple( const wxBitmap& stipple )
155{
c89f5c02
RR
156 AllocExclusive();
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
RR
167}
168