]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/brush.cpp
added support for <bg> tag for toolbars in XRC
[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 #include "wx/colour.h"
15
16 #include <gdk/gdk.h>
17
18 //-----------------------------------------------------------------------------
19 // wxBrush
20 //-----------------------------------------------------------------------------
21
22 class wxBrushRefData: public wxObjectRefData
23 {
24 public:
25 wxBrushRefData()
26 {
27 m_style = 0;
28 }
29
30 wxBrushRefData( const wxBrushRefData& data )
31 : wxObjectRefData()
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;
48 };
49
50 //-----------------------------------------------------------------------------
51
52 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
53
54 IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
55
56 wxBrush::wxBrush( const wxColour &colour, int style )
57 {
58 m_refData = new wxBrushRefData();
59 M_BRUSHDATA->m_style = style;
60 M_BRUSHDATA->m_colour = colour;
61 }
62
63 wxBrush::wxBrush( const wxBitmap &stippleBitmap )
64 {
65 m_refData = new wxBrushRefData();
66 M_BRUSHDATA->m_colour = *wxBLACK;
67
68 M_BRUSHDATA->m_stipple = stippleBitmap;
69
70 if (M_BRUSHDATA->m_stipple.GetMask())
71 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
72 else
73 M_BRUSHDATA->m_style = wxSTIPPLE;
74 }
75
76 wxBrush::~wxBrush()
77 {
78 // m_refData unrefed in ~wxObject
79 }
80
81 wxObjectRefData *wxBrush::CreateRefData() const
82 {
83 return new wxBrushRefData;
84 }
85
86 wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const
87 {
88 return new wxBrushRefData(*(wxBrushRefData *)data);
89 }
90
91 bool wxBrush::operator == ( const wxBrush& brush ) const
92 {
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 );
98 }
99
100 int wxBrush::GetStyle() const
101 {
102 if (m_refData == NULL)
103 {
104 wxFAIL_MSG( wxT("invalid brush") );
105 return 0;
106 }
107
108 return M_BRUSHDATA->m_style;
109 }
110
111 wxColour &wxBrush::GetColour() const
112 {
113 if (m_refData == NULL)
114 {
115 wxFAIL_MSG( wxT("invalid brush") );
116 return wxNullColour;
117 }
118
119 return M_BRUSHDATA->m_colour;
120 }
121
122 wxBitmap *wxBrush::GetStipple() const
123 {
124 if (m_refData == NULL)
125 {
126 wxFAIL_MSG( wxT("invalid brush") );
127 return &wxNullBitmap;
128 }
129
130 return &M_BRUSHDATA->m_stipple;
131 }
132
133 void wxBrush::SetColour( const wxColour& col )
134 {
135 AllocExclusive();
136
137 M_BRUSHDATA->m_colour = col;
138 }
139
140 void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
141 {
142 AllocExclusive();
143
144 M_BRUSHDATA->m_colour.Set( r, g, b );
145 }
146
147 void wxBrush::SetStyle( int style )
148 {
149 AllocExclusive();
150
151 M_BRUSHDATA->m_style = style;
152 }
153
154 void wxBrush::SetStipple( const wxBitmap& stipple )
155 {
156 AllocExclusive();
157
158 M_BRUSHDATA->m_stipple = stipple;
159 if (M_BRUSHDATA->m_stipple.GetMask())
160 {
161 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
162 }
163 else
164 {
165 M_BRUSHDATA->m_style = wxSTIPPLE;
166 }
167 }