]>
Commit | Line | Data |
---|---|---|
83df96d6 | 1 | ///////////////////////////////////////////////////////////////////////////// |
7266b672 | 2 | // Name: src/x11/pen.cpp |
83df96d6 JS |
3 | // Purpose: wxPen |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
65571936 | 9 | // Licence: wxWindows licence |
83df96d6 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
55034339 WS |
12 | // for compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
83df96d6 JS |
15 | #include "wx/utils.h" |
16 | #include "wx/pen.h" | |
69c44812 MB |
17 | #include "wx/colour.h" |
18 | #include "wx/bitmap.h" | |
83df96d6 | 19 | |
74dc5eb6 RR |
20 | //----------------------------------------------------------------------------- |
21 | // wxPen | |
22 | //----------------------------------------------------------------------------- | |
83df96d6 | 23 | |
74dc5eb6 | 24 | class wxPenRefData: public wxObjectRefData |
83df96d6 | 25 | { |
74dc5eb6 RR |
26 | public: |
27 | wxPenRefData() | |
28 | { | |
29 | m_width = 1; | |
30 | m_style = wxSOLID; | |
31 | m_joinStyle = wxJOIN_ROUND; | |
32 | m_capStyle = wxCAP_ROUND; | |
33 | m_dash = (wxX11Dash*) NULL; | |
34 | m_countDashes = 0; | |
35 | } | |
55034339 | 36 | |
74dc5eb6 RR |
37 | wxPenRefData( const wxPenRefData& data ) |
38 | { | |
39 | m_style = data.m_style; | |
40 | m_width = data.m_width; | |
41 | m_joinStyle = data.m_joinStyle; | |
42 | m_capStyle = data.m_capStyle; | |
43 | m_colour = data.m_colour; | |
44 | m_countDashes = data.m_countDashes; | |
45 | /* | |
46 | if (data.m_dash) TODO | |
47 | m_dash = new | |
48 | */ | |
49 | m_dash = data.m_dash; | |
69c44812 | 50 | m_stipple = data.m_stipple; |
74dc5eb6 | 51 | } |
83df96d6 | 52 | |
74dc5eb6 RR |
53 | bool operator == (const wxPenRefData& data) const |
54 | { | |
55 | return (m_style == data.m_style && | |
56 | m_width == data.m_width && | |
57 | m_joinStyle == data.m_joinStyle && | |
58 | m_capStyle == data.m_capStyle && | |
59 | m_colour == data.m_colour); | |
60 | } | |
55034339 | 61 | |
74dc5eb6 RR |
62 | int m_width; |
63 | int m_style; | |
64 | int m_joinStyle; | |
65 | int m_capStyle; | |
66 | wxColour m_colour; | |
67 | int m_countDashes; | |
69c44812 | 68 | wxBitmap m_stipple; |
74dc5eb6 RR |
69 | wxX11Dash *m_dash; |
70 | }; | |
83df96d6 | 71 | |
74dc5eb6 RR |
72 | //----------------------------------------------------------------------------- |
73 | ||
74 | #define M_PENDATA ((wxPenRefData *)m_refData) | |
83df96d6 | 75 | |
74dc5eb6 | 76 | IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject) |
83df96d6 | 77 | |
74dc5eb6 | 78 | wxPen::wxPen( const wxColour &colour, int width, int style ) |
83df96d6 | 79 | { |
74dc5eb6 RR |
80 | m_refData = new wxPenRefData(); |
81 | M_PENDATA->m_width = width; | |
82 | M_PENDATA->m_style = style; | |
83 | M_PENDATA->m_colour = colour; | |
83df96d6 JS |
84 | } |
85 | ||
86 | wxPen::~wxPen() | |
87 | { | |
74dc5eb6 | 88 | // m_refData unrefed in ~wxObject |
83df96d6 JS |
89 | } |
90 | ||
74dc5eb6 | 91 | wxObjectRefData *wxPen::CreateRefData() const |
83df96d6 | 92 | { |
74dc5eb6 | 93 | return new wxPenRefData; |
83df96d6 JS |
94 | } |
95 | ||
74dc5eb6 | 96 | wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const |
83df96d6 | 97 | { |
74dc5eb6 | 98 | return new wxPenRefData(*(wxPenRefData *)data); |
83df96d6 JS |
99 | } |
100 | ||
74dc5eb6 | 101 | bool wxPen::operator == ( const wxPen& pen ) const |
83df96d6 | 102 | { |
55034339 WS |
103 | if (m_refData == pen.m_refData) return true; |
104 | ||
105 | if (!m_refData || !pen.m_refData) return false; | |
106 | ||
74dc5eb6 | 107 | return ( *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData ); |
83df96d6 JS |
108 | } |
109 | ||
74dc5eb6 | 110 | void wxPen::SetColour( const wxColour &colour ) |
83df96d6 | 111 | { |
74dc5eb6 | 112 | AllocExclusive(); |
55034339 | 113 | |
74dc5eb6 | 114 | M_PENDATA->m_colour = colour; |
83df96d6 JS |
115 | } |
116 | ||
74dc5eb6 | 117 | void wxPen::SetDashes( int number_of_dashes, const wxDash *dash ) |
83df96d6 | 118 | { |
74dc5eb6 | 119 | AllocExclusive(); |
55034339 | 120 | |
74dc5eb6 RR |
121 | M_PENDATA->m_countDashes = number_of_dashes; |
122 | M_PENDATA->m_dash = (wxX11Dash *)dash; // TODO | |
123 | } | |
83df96d6 | 124 | |
1a1498c0 | 125 | void wxPen::SetColour( unsigned char red, unsigned char green, unsigned char blue ) |
74dc5eb6 RR |
126 | { |
127 | AllocExclusive(); | |
55034339 | 128 | |
74dc5eb6 | 129 | M_PENDATA->m_colour.Set( red, green, blue ); |
83df96d6 JS |
130 | } |
131 | ||
74dc5eb6 | 132 | void wxPen::SetCap( int capStyle ) |
83df96d6 | 133 | { |
74dc5eb6 | 134 | AllocExclusive(); |
55034339 | 135 | |
74dc5eb6 RR |
136 | M_PENDATA->m_capStyle = capStyle; |
137 | } | |
83df96d6 | 138 | |
74dc5eb6 RR |
139 | void wxPen::SetJoin( int joinStyle ) |
140 | { | |
141 | AllocExclusive(); | |
55034339 | 142 | |
74dc5eb6 RR |
143 | M_PENDATA->m_joinStyle = joinStyle; |
144 | } | |
83df96d6 | 145 | |
69c44812 MB |
146 | void wxPen::SetStipple( wxBitmap *stipple ) |
147 | { | |
148 | AllocExclusive(); | |
55034339 | 149 | |
69c44812 MB |
150 | M_PENDATA->m_stipple = *stipple;; |
151 | } | |
152 | ||
74dc5eb6 RR |
153 | void wxPen::SetStyle( int style ) |
154 | { | |
155 | AllocExclusive(); | |
55034339 | 156 | |
74dc5eb6 | 157 | M_PENDATA->m_style = style; |
83df96d6 JS |
158 | } |
159 | ||
74dc5eb6 | 160 | void wxPen::SetWidth( int width ) |
83df96d6 | 161 | { |
74dc5eb6 | 162 | AllocExclusive(); |
55034339 | 163 | |
74dc5eb6 RR |
164 | M_PENDATA->m_width = width; |
165 | } | |
83df96d6 | 166 | |
74dc5eb6 RR |
167 | int wxPen::GetDashes( wxDash **ptr ) const |
168 | { | |
169 | *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL); | |
170 | return (M_PENDATA ? M_PENDATA->m_countDashes : 0); | |
171 | } | |
83df96d6 | 172 | |
74dc5eb6 RR |
173 | int wxPen::GetDashCount() const |
174 | { | |
175 | return (M_PENDATA->m_countDashes); | |
83df96d6 JS |
176 | } |
177 | ||
74dc5eb6 | 178 | wxDash* wxPen::GetDash() const |
83df96d6 | 179 | { |
74dc5eb6 RR |
180 | return (wxDash*)M_PENDATA->m_dash; |
181 | } | |
83df96d6 | 182 | |
74dc5eb6 RR |
183 | int wxPen::GetCap() const |
184 | { | |
185 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); | |
83df96d6 | 186 | |
74dc5eb6 | 187 | return M_PENDATA->m_capStyle; |
83df96d6 JS |
188 | } |
189 | ||
74dc5eb6 | 190 | int wxPen::GetJoin() const |
83df96d6 | 191 | { |
74dc5eb6 | 192 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); |
83df96d6 | 193 | |
74dc5eb6 | 194 | return M_PENDATA->m_joinStyle; |
83df96d6 JS |
195 | } |
196 | ||
74dc5eb6 | 197 | int wxPen::GetStyle() const |
83df96d6 | 198 | { |
74dc5eb6 | 199 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); |
83df96d6 | 200 | |
74dc5eb6 | 201 | return M_PENDATA->m_style; |
83df96d6 JS |
202 | } |
203 | ||
74dc5eb6 | 204 | int wxPen::GetWidth() const |
83df96d6 | 205 | { |
74dc5eb6 | 206 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); |
83df96d6 | 207 | |
74dc5eb6 | 208 | return M_PENDATA->m_width; |
83df96d6 JS |
209 | } |
210 | ||
74dc5eb6 | 211 | wxColour &wxPen::GetColour() const |
83df96d6 | 212 | { |
74dc5eb6 | 213 | wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") ); |
83df96d6 | 214 | |
74dc5eb6 RR |
215 | return M_PENDATA->m_colour; |
216 | } | |
69c44812 MB |
217 | |
218 | wxBitmap *wxPen::GetStipple() const | |
219 | { | |
220 | wxCHECK_MSG( Ok(), &wxNullBitmap, wxT("invalid pen") ); | |
221 | ||
222 | return &M_PENDATA->m_stipple; | |
223 | } |