]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/brush.cpp
don't use negative sizes for row/column labels subwindows to avoid GTK warnings ...
[wxWidgets.git] / src / gtk1 / brush.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/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/colour.h"
17 #endif
18
19 #include <gdk/gdk.h>
20
21 //-----------------------------------------------------------------------------
22 // wxBrush
23 //-----------------------------------------------------------------------------
24
25 class wxBrushRefData: public wxGDIRefData
26 {
27 public:
28 wxBrushRefData()
29 {
30 m_style = 0;
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 int 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, int style )
60 {
61 m_refData = new wxBrushRefData();
62 M_BRUSHDATA->m_style = style;
63 M_BRUSHDATA->m_colour = colour;
64 }
65
66 wxBrush::wxBrush( const wxBitmap &stippleBitmap )
67 {
68 m_refData = new wxBrushRefData();
69 M_BRUSHDATA->m_colour = *wxBLACK;
70
71 M_BRUSHDATA->m_stipple = stippleBitmap;
72
73 if (M_BRUSHDATA->m_stipple.GetMask())
74 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
75 else
76 M_BRUSHDATA->m_style = wxSTIPPLE;
77 }
78
79 wxBrush::~wxBrush()
80 {
81 // m_refData unrefed in ~wxObject
82 }
83
84 wxGDIRefData *wxBrush::CreateGDIRefData() const
85 {
86 return new wxBrushRefData;
87 }
88
89 wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const
90 {
91 return new wxBrushRefData(*(wxBrushRefData *)data);
92 }
93
94 bool wxBrush::operator == ( const wxBrush& brush ) const
95 {
96 if (m_refData == brush.m_refData) return true;
97
98 if (!m_refData || !brush.m_refData) return false;
99
100 return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData );
101 }
102
103 int wxBrush::GetStyle() const
104 {
105 if (m_refData == NULL)
106 {
107 wxFAIL_MSG( wxT("invalid brush") );
108 return 0;
109 }
110
111 return M_BRUSHDATA->m_style;
112 }
113
114 wxColour &wxBrush::GetColour() const
115 {
116 if (m_refData == NULL)
117 {
118 wxFAIL_MSG( wxT("invalid brush") );
119 return wxNullColour;
120 }
121
122 return M_BRUSHDATA->m_colour;
123 }
124
125 wxBitmap *wxBrush::GetStipple() const
126 {
127 if (m_refData == NULL)
128 {
129 wxFAIL_MSG( wxT("invalid brush") );
130 return &wxNullBitmap;
131 }
132
133 return &M_BRUSHDATA->m_stipple;
134 }
135
136 void wxBrush::SetColour( const wxColour& col )
137 {
138 AllocExclusive();
139
140 M_BRUSHDATA->m_colour = col;
141 }
142
143 void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
144 {
145 AllocExclusive();
146
147 M_BRUSHDATA->m_colour.Set( r, g, b );
148 }
149
150 void wxBrush::SetStyle( int style )
151 {
152 AllocExclusive();
153
154 M_BRUSHDATA->m_style = style;
155 }
156
157 void wxBrush::SetStipple( const wxBitmap& stipple )
158 {
159 AllocExclusive();
160
161 M_BRUSHDATA->m_stipple = stipple;
162 if (M_BRUSHDATA->m_stipple.GetMask())
163 {
164 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
165 }
166 else
167 {
168 M_BRUSHDATA->m_style = wxSTIPPLE;
169 }
170 }