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