]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
7ecb8b06 | 2 | // Name: src/gtk/brush.cpp |
c801d85f KB |
3 | // Purpose: |
4 | // Author: Robert Roebling | |
f96aa4d9 | 5 | // Id: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling |
7ecb8b06 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "brush.h" | |
12 | #endif | |
13 | ||
14 | #include "wx/brush.h" | |
15 | ||
20e05ffb | 16 | #include <gdk/gdk.h> |
83624f79 | 17 | |
c801d85f KB |
18 | //----------------------------------------------------------------------------- |
19 | // wxBrush | |
20 | //----------------------------------------------------------------------------- | |
21 | ||
22 | class wxBrushRefData: public wxObjectRefData | |
23 | { | |
58c837a4 | 24 | public: |
8bbe427f | 25 | wxBrushRefData(); |
e55ad60e | 26 | wxBrushRefData( const wxBrushRefData& data ); |
8bbe427f | 27 | |
c801d85f KB |
28 | int m_style; |
29 | wxBitmap m_stipple; | |
30 | wxColour m_colour; | |
31 | }; | |
32 | ||
8bbe427f | 33 | wxBrushRefData::wxBrushRefData() |
c801d85f | 34 | { |
58c837a4 | 35 | m_style = 0; |
ff7b1510 | 36 | } |
c801d85f | 37 | |
e55ad60e RR |
38 | wxBrushRefData::wxBrushRefData( const wxBrushRefData& data ) |
39 | { | |
58c837a4 RR |
40 | m_style = data.m_style; |
41 | m_stipple = data.m_stipple; | |
42 | m_colour = data.m_colour; | |
e55ad60e RR |
43 | } |
44 | ||
c801d85f KB |
45 | //----------------------------------------------------------------------------- |
46 | ||
47 | #define M_BRUSHDATA ((wxBrushRefData *)m_refData) | |
48 | ||
49 | IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject) | |
50 | ||
8bbe427f | 51 | wxBrush::wxBrush() |
c801d85f | 52 | { |
ff7b1510 | 53 | } |
c801d85f | 54 | |
debe6624 | 55 | wxBrush::wxBrush( const wxColour &colour, int style ) |
c801d85f | 56 | { |
58c837a4 RR |
57 | m_refData = new wxBrushRefData(); |
58 | M_BRUSHDATA->m_style = style; | |
59 | M_BRUSHDATA->m_colour = colour; | |
ff7b1510 | 60 | } |
c801d85f | 61 | |
c801d85f KB |
62 | wxBrush::wxBrush( const wxBitmap &stippleBitmap ) |
63 | { | |
58c837a4 | 64 | m_refData = new wxBrushRefData(); |
58c837a4 | 65 | M_BRUSHDATA->m_colour = *wxBLACK; |
7ecb8b06 | 66 | |
58c837a4 | 67 | M_BRUSHDATA->m_stipple = stippleBitmap; |
e1208c31 | 68 | |
de2d2cdc | 69 | if (M_BRUSHDATA->m_stipple.GetMask()) |
7ecb8b06 VZ |
70 | M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE; |
71 | else | |
72 | M_BRUSHDATA->m_style = wxSTIPPLE; | |
ff7b1510 | 73 | } |
c801d85f KB |
74 | |
75 | wxBrush::wxBrush( const wxBrush &brush ) | |
76 | { | |
58c837a4 | 77 | Ref( brush ); |
ff7b1510 | 78 | } |
c801d85f | 79 | |
8bbe427f | 80 | wxBrush::~wxBrush() |
c801d85f | 81 | { |
ff7b1510 | 82 | } |
c801d85f KB |
83 | |
84 | wxBrush& wxBrush::operator = ( const wxBrush& brush ) | |
85 | { | |
7ecb8b06 VZ |
86 | if ( m_refData != brush.m_refData ) |
87 | Ref( brush ); | |
88 | ||
58c837a4 | 89 | return *this; |
ff7b1510 | 90 | } |
8bbe427f | 91 | |
f6bcfd97 | 92 | bool wxBrush::operator == ( const wxBrush& brush ) const |
c801d85f | 93 | { |
58c837a4 | 94 | return m_refData == brush.m_refData; |
ff7b1510 | 95 | } |
c801d85f | 96 | |
f6bcfd97 | 97 | bool wxBrush::operator != ( const wxBrush& brush ) const |
c801d85f | 98 | { |
58c837a4 | 99 | return m_refData != brush.m_refData; |
ff7b1510 | 100 | } |
c801d85f | 101 | |
8bbe427f | 102 | bool wxBrush::Ok() const |
c801d85f | 103 | { |
58c837a4 | 104 | return ((m_refData) && M_BRUSHDATA->m_colour.Ok()); |
ff7b1510 | 105 | } |
c801d85f | 106 | |
8bbe427f | 107 | int wxBrush::GetStyle() const |
c801d85f | 108 | { |
58c837a4 RR |
109 | if (m_refData == NULL) |
110 | { | |
111 | wxFAIL_MSG( wxT("invalid brush") ); | |
112 | return 0; | |
113 | } | |
e55ad60e | 114 | |
58c837a4 | 115 | return M_BRUSHDATA->m_style; |
ff7b1510 | 116 | } |
c801d85f | 117 | |
8bbe427f | 118 | wxColour &wxBrush::GetColour() const |
c801d85f | 119 | { |
58c837a4 RR |
120 | if (m_refData == NULL) |
121 | { | |
122 | wxFAIL_MSG( wxT("invalid brush") ); | |
123 | return wxNullColour; | |
124 | } | |
8bbe427f | 125 | |
58c837a4 | 126 | return M_BRUSHDATA->m_colour; |
ff7b1510 | 127 | } |
c801d85f | 128 | |
8bbe427f | 129 | wxBitmap *wxBrush::GetStipple() const |
c801d85f | 130 | { |
58c837a4 RR |
131 | if (m_refData == NULL) |
132 | { | |
133 | wxFAIL_MSG( wxT("invalid brush") ); | |
134 | return &wxNullBitmap; | |
135 | } | |
8bbe427f | 136 | |
58c837a4 | 137 | return &M_BRUSHDATA->m_stipple; |
ff7b1510 | 138 | } |
c801d85f | 139 | |
e55ad60e RR |
140 | void wxBrush::SetColour( const wxColour& col ) |
141 | { | |
58c837a4 RR |
142 | Unshare(); |
143 | M_BRUSHDATA->m_colour = col; | |
e55ad60e RR |
144 | } |
145 | ||
e55ad60e RR |
146 | void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b ) |
147 | { | |
58c837a4 RR |
148 | Unshare(); |
149 | M_BRUSHDATA->m_colour.Set( r, g, b ); | |
e55ad60e RR |
150 | } |
151 | ||
152 | void wxBrush::SetStyle( int style ) | |
153 | { | |
58c837a4 RR |
154 | Unshare(); |
155 | M_BRUSHDATA->m_style = style; | |
e55ad60e RR |
156 | } |
157 | ||
158 | void wxBrush::SetStipple( const wxBitmap& stipple ) | |
159 | { | |
58c837a4 RR |
160 | Unshare(); |
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 RR |
170 | } |
171 | ||
8bbe427f | 172 | void wxBrush::Unshare() |
e55ad60e | 173 | { |
58c837a4 RR |
174 | if (!m_refData) |
175 | { | |
176 | m_refData = new wxBrushRefData(); | |
177 | } | |
178 | else | |
179 | { | |
180 | wxBrushRefData* ref = new wxBrushRefData( *(wxBrushRefData*)m_refData ); | |
181 | UnRef(); | |
182 | m_refData = ref; | |
183 | } | |
e55ad60e | 184 | } |
c801d85f | 185 |