]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
46562151 | 2 | // Name: src/gtk/pen.cpp |
c801d85f KB |
3 | // Purpose: |
4 | // Author: Robert Roebling | |
a81258be | 5 | // Copyright: (c) 1998 Robert Roebling |
65571936 | 6 | // Licence: wxWindows licence |
c801d85f KB |
7 | ///////////////////////////////////////////////////////////////////////////// |
8 | ||
14f355c2 VS |
9 | // For compilers that support precompilation, includes "wx.h". |
10 | #include "wx/wxprec.h" | |
11 | ||
c801d85f | 12 | #include "wx/pen.h" |
7cf41a5d WS |
13 | |
14 | #ifndef WX_PRECOMP | |
15 | #include "wx/colour.h" | |
16 | #endif | |
c801d85f | 17 | |
5e7e9e1b | 18 | #include <gdk/gdk.h> |
83624f79 | 19 | |
c801d85f KB |
20 | //----------------------------------------------------------------------------- |
21 | // wxPen | |
22 | //----------------------------------------------------------------------------- | |
23 | ||
8f884a0d | 24 | class wxPenRefData: public wxGDIRefData |
c801d85f | 25 | { |
907789a0 | 26 | public: |
c89f5c02 RR |
27 | wxPenRefData() |
28 | { | |
29 | m_width = 1; | |
82cddbd9 | 30 | m_style = wxPENSTYLE_SOLID; |
c89f5c02 RR |
31 | m_joinStyle = wxJOIN_ROUND; |
32 | m_capStyle = wxCAP_ROUND; | |
d3b9f782 | 33 | m_dash = NULL; |
c89f5c02 RR |
34 | m_countDashes = 0; |
35 | } | |
46562151 | 36 | |
c89f5c02 | 37 | wxPenRefData( const wxPenRefData& data ) |
8f884a0d | 38 | : wxGDIRefData() |
c89f5c02 RR |
39 | { |
40 | m_style = data.m_style; | |
41 | m_width = data.m_width; | |
42 | m_joinStyle = data.m_joinStyle; | |
43 | m_capStyle = data.m_capStyle; | |
44 | m_colour = data.m_colour; | |
45 | m_countDashes = data.m_countDashes; | |
c89f5c02 RR |
46 | m_dash = data.m_dash; |
47 | } | |
48 | ||
49 | bool operator == (const wxPenRefData& data) const | |
50 | { | |
17be8531 | 51 | if ( m_countDashes != data.m_countDashes ) |
46562151 | 52 | return false; |
17be8531 VZ |
53 | |
54 | if ( m_dash ) | |
55 | { | |
56 | if ( !data.m_dash || | |
57 | memcmp(m_dash, data.m_dash, m_countDashes*sizeof(wxGTKDash)) ) | |
58 | { | |
46562151 | 59 | return false; |
17be8531 VZ |
60 | } |
61 | } | |
62 | else if ( data.m_dash ) | |
63 | { | |
46562151 | 64 | return false; |
17be8531 VZ |
65 | } |
66 | ||
67 | ||
68 | return m_style == data.m_style && | |
69 | m_width == data.m_width && | |
70 | m_joinStyle == data.m_joinStyle && | |
71 | m_capStyle == data.m_capStyle && | |
72 | m_colour == data.m_colour; | |
c89f5c02 | 73 | } |
46562151 | 74 | |
c89f5c02 | 75 | int m_width; |
82cddbd9 FM |
76 | wxPenStyle m_style; |
77 | wxPenJoin m_joinStyle; | |
78 | wxPenCap m_capStyle; | |
c89f5c02 RR |
79 | wxColour m_colour; |
80 | int m_countDashes; | |
81 | wxGTKDash *m_dash; | |
82 | }; | |
e55ad60e | 83 | |
c801d85f KB |
84 | //----------------------------------------------------------------------------- |
85 | ||
86 | #define M_PENDATA ((wxPenRefData *)m_refData) | |
87 | ||
88 | IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject) | |
89 | ||
82cddbd9 | 90 | wxPen::wxPen( const wxColour &colour, int width, wxPenStyle style ) |
c801d85f | 91 | { |
907789a0 RR |
92 | m_refData = new wxPenRefData(); |
93 | M_PENDATA->m_width = width; | |
94 | M_PENDATA->m_style = style; | |
95 | M_PENDATA->m_colour = colour; | |
ff7b1510 | 96 | } |
c801d85f | 97 | |
ac3688c0 FM |
98 | #if FUTURE_WXWIN_COMPATIBILITY_3_0 |
99 | wxPen::wxPen(const wxColour& colour, int width, int style) | |
82cddbd9 FM |
100 | { |
101 | m_refData = new wxPenRefData(); | |
102 | M_PENDATA->m_width = width; | |
103 | M_PENDATA->m_style = (wxPenStyle)style; | |
104 | M_PENDATA->m_colour = colour; | |
105 | } | |
04ee05f9 | 106 | #endif |
82cddbd9 | 107 | |
907789a0 | 108 | wxPen::~wxPen() |
c801d85f | 109 | { |
c89f5c02 | 110 | // m_refData unrefed in ~wxObject |
ff7b1510 | 111 | } |
c801d85f | 112 | |
8f884a0d | 113 | wxGDIRefData *wxPen::CreateGDIRefData() const |
c801d85f | 114 | { |
c89f5c02 | 115 | return new wxPenRefData; |
ff7b1510 | 116 | } |
c801d85f | 117 | |
8f884a0d | 118 | wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const |
c801d85f | 119 | { |
c89f5c02 | 120 | return new wxPenRefData(*(wxPenRefData *)data); |
ff7b1510 | 121 | } |
c801d85f | 122 | |
c89f5c02 | 123 | bool wxPen::operator == ( const wxPen& pen ) const |
c801d85f | 124 | { |
46562151 WS |
125 | if (m_refData == pen.m_refData) return true; |
126 | ||
127 | if (!m_refData || !pen.m_refData) return false; | |
128 | ||
c89f5c02 | 129 | return ( *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData ); |
ff7b1510 | 130 | } |
c801d85f KB |
131 | |
132 | void wxPen::SetColour( const wxColour &colour ) | |
133 | { | |
c89f5c02 | 134 | AllocExclusive(); |
46562151 | 135 | |
907789a0 | 136 | M_PENDATA->m_colour = colour; |
ff7b1510 | 137 | } |
c801d85f | 138 | |
112c5086 RR |
139 | void wxPen::SetDashes( int number_of_dashes, const wxDash *dash ) |
140 | { | |
c89f5c02 | 141 | AllocExclusive(); |
46562151 | 142 | |
112c5086 | 143 | M_PENDATA->m_countDashes = number_of_dashes; |
17be8531 | 144 | M_PENDATA->m_dash = (wxGTKDash *)dash; |
112c5086 RR |
145 | } |
146 | ||
1a1498c0 | 147 | void wxPen::SetColour( unsigned char red, unsigned char green, unsigned char blue ) |
c801d85f | 148 | { |
c89f5c02 | 149 | AllocExclusive(); |
46562151 | 150 | |
907789a0 | 151 | M_PENDATA->m_colour.Set( red, green, blue ); |
ff7b1510 | 152 | } |
c801d85f | 153 | |
82cddbd9 | 154 | void wxPen::SetCap( wxPenCap capStyle ) |
c801d85f | 155 | { |
c89f5c02 | 156 | AllocExclusive(); |
46562151 | 157 | |
907789a0 | 158 | M_PENDATA->m_capStyle = capStyle; |
ff7b1510 | 159 | } |
c801d85f | 160 | |
82cddbd9 | 161 | void wxPen::SetJoin( wxPenJoin joinStyle ) |
c801d85f | 162 | { |
c89f5c02 | 163 | AllocExclusive(); |
46562151 | 164 | |
907789a0 | 165 | M_PENDATA->m_joinStyle = joinStyle; |
ff7b1510 | 166 | } |
c801d85f | 167 | |
82cddbd9 | 168 | void wxPen::SetStyle( wxPenStyle style ) |
c801d85f | 169 | { |
c89f5c02 | 170 | AllocExclusive(); |
46562151 | 171 | |
907789a0 | 172 | M_PENDATA->m_style = style; |
ff7b1510 | 173 | } |
c801d85f KB |
174 | |
175 | void wxPen::SetWidth( int width ) | |
176 | { | |
c89f5c02 | 177 | AllocExclusive(); |
46562151 | 178 | |
907789a0 | 179 | M_PENDATA->m_width = width; |
ff7b1510 | 180 | } |
c801d85f | 181 | |
7ecb8b06 | 182 | int wxPen::GetDashes( wxDash **ptr ) const |
112c5086 | 183 | { |
a1b806b9 | 184 | wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") ); |
ac3688c0 FM |
185 | |
186 | *ptr = (wxDash*)M_PENDATA->m_dash; | |
187 | return M_PENDATA->m_countDashes; | |
112c5086 RR |
188 | } |
189 | ||
7ecb8b06 VZ |
190 | int wxPen::GetDashCount() const |
191 | { | |
a1b806b9 | 192 | wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") ); |
ac3688c0 | 193 | |
7ecb8b06 | 194 | return (M_PENDATA->m_countDashes); |
112c5086 RR |
195 | } |
196 | ||
7ecb8b06 VZ |
197 | wxDash* wxPen::GetDash() const |
198 | { | |
a1b806b9 | 199 | wxCHECK_MSG( IsOk(), NULL, wxT("invalid pen") ); |
ac3688c0 | 200 | |
7ecb8b06 | 201 | return (wxDash*)M_PENDATA->m_dash; |
112c5086 RR |
202 | } |
203 | ||
82cddbd9 | 204 | wxPenCap wxPen::GetCap() const |
c801d85f | 205 | { |
a1b806b9 | 206 | wxCHECK_MSG( IsOk(), wxCAP_INVALID, wxT("invalid pen") ); |
8bbe427f | 207 | |
907789a0 | 208 | return M_PENDATA->m_capStyle; |
ff7b1510 | 209 | } |
c801d85f | 210 | |
82cddbd9 | 211 | wxPenJoin wxPen::GetJoin() const |
c801d85f | 212 | { |
a1b806b9 | 213 | wxCHECK_MSG( IsOk(), wxJOIN_INVALID, wxT("invalid pen") ); |
8bbe427f | 214 | |
907789a0 | 215 | return M_PENDATA->m_joinStyle; |
ff7b1510 | 216 | } |
c801d85f | 217 | |
82cddbd9 | 218 | wxPenStyle wxPen::GetStyle() const |
c801d85f | 219 | { |
a1b806b9 | 220 | wxCHECK_MSG( IsOk(), wxPENSTYLE_INVALID, wxT("invalid pen") ); |
8bbe427f | 221 | |
907789a0 | 222 | return M_PENDATA->m_style; |
ff7b1510 | 223 | } |
c801d85f | 224 | |
907789a0 | 225 | int wxPen::GetWidth() const |
c801d85f | 226 | { |
a1b806b9 | 227 | wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") ); |
8bbe427f | 228 | |
907789a0 | 229 | return M_PENDATA->m_width; |
ff7b1510 | 230 | } |
c801d85f | 231 | |
231b9591 | 232 | wxColour wxPen::GetColour() const |
c801d85f | 233 | { |
a1b806b9 | 234 | wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid pen") ); |
8bbe427f | 235 | |
907789a0 | 236 | return M_PENDATA->m_colour; |
ff7b1510 | 237 | } |
04edbb23 VZ |
238 | |
239 | // stippled pens are not supported by wxGTK | |
240 | void wxPen::SetStipple(const wxBitmap& WXUNUSED(stipple)) | |
241 | { | |
242 | wxFAIL_MSG( "stippled pens not supported" ); | |
243 | } | |
244 | ||
245 | wxBitmap *wxPen::GetStipple() const | |
246 | { | |
247 | return NULL; | |
248 | } | |
249 |