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