]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/brush.cpp
added wxWindow::HandleAsNavigationKey() helper for handling (not only) TAB key in...
[wxWidgets.git] / src / gtk / brush.cpp
... / ...
CommitLineData
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
24class wxBrushRefData: public wxGDIRefData
25{
26public:
27 wxBrushRefData()
28 {
29 m_style = 0;
30 }
31
32 wxBrushRefData( const wxBrushRefData& data )
33 : wxGDIRefData()
34 {
35 m_style = data.m_style;
36 m_stipple = data.m_stipple;
37 m_colour = data.m_colour;
38 }
39
40 bool operator == (const wxBrushRefData& data) const
41 {
42 return (m_style == data.m_style &&
43 m_stipple.IsSameAs(data.m_stipple) &&
44 m_colour == data.m_colour);
45 }
46
47 int m_style;
48 wxColour m_colour;
49 wxBitmap m_stipple;
50};
51
52//-----------------------------------------------------------------------------
53
54#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
55
56IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
57
58wxBrush::wxBrush( const wxColour &colour, int style )
59{
60 m_refData = new wxBrushRefData();
61 M_BRUSHDATA->m_style = style;
62 M_BRUSHDATA->m_colour = colour;
63}
64
65wxBrush::wxBrush( const wxBitmap &stippleBitmap )
66{
67 m_refData = new wxBrushRefData();
68 M_BRUSHDATA->m_colour = *wxBLACK;
69
70 M_BRUSHDATA->m_stipple = stippleBitmap;
71
72 if (M_BRUSHDATA->m_stipple.GetMask())
73 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
74 else
75 M_BRUSHDATA->m_style = wxSTIPPLE;
76}
77
78wxBrush::~wxBrush()
79{
80 // m_refData unrefed in ~wxObject
81}
82
83wxGDIRefData *wxBrush::CreateGDIRefData() const
84{
85 return new wxBrushRefData;
86}
87
88wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const
89{
90 return new wxBrushRefData(*(wxBrushRefData *)data);
91}
92
93bool wxBrush::operator==(const wxBrush& brush) const
94{
95 if (m_refData == brush.m_refData) return true;
96
97 if (!m_refData || !brush.m_refData) return false;
98
99 return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData );
100}
101
102int wxBrush::GetStyle() const
103{
104 if (m_refData == NULL)
105 {
106 wxFAIL_MSG( wxT("invalid brush") );
107 return 0;
108 }
109
110 return M_BRUSHDATA->m_style;
111}
112
113wxColour &wxBrush::GetColour() const
114{
115 if (m_refData == NULL)
116 {
117 wxFAIL_MSG( wxT("invalid brush") );
118 return wxNullColour;
119 }
120
121 return M_BRUSHDATA->m_colour;
122}
123
124wxBitmap *wxBrush::GetStipple() const
125{
126 if (m_refData == NULL)
127 {
128 wxFAIL_MSG( wxT("invalid brush") );
129 return &wxNullBitmap;
130 }
131
132 return &M_BRUSHDATA->m_stipple;
133}
134
135void wxBrush::SetColour( const wxColour& col )
136{
137 AllocExclusive();
138
139 M_BRUSHDATA->m_colour = col;
140}
141
142void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
143{
144 AllocExclusive();
145
146 M_BRUSHDATA->m_colour.Set( r, g, b );
147}
148
149void wxBrush::SetStyle( int style )
150{
151 AllocExclusive();
152
153 M_BRUSHDATA->m_style = style;
154}
155
156void wxBrush::SetStipple( const wxBitmap& stipple )
157{
158 AllocExclusive();
159
160 M_BRUSHDATA->m_stipple = stipple;
161 if (M_BRUSHDATA->m_stipple.GetMask())
162 {
163 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
164 }
165 else
166 {
167 M_BRUSHDATA->m_style = wxSTIPPLE;
168 }
169}