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