]> git.saurik.com Git - wxWidgets.git/blob - src/x11/pen.cpp
The reinit of the stock objects shoudl not happen when wxPython is
[wxWidgets.git] / src / x11 / pen.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/x11/pen.cpp
3 // Purpose: wxPen
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 17/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "pen.h"
14 #endif
15
16 #include "wx/setup.h"
17 #include "wx/utils.h"
18 #include "wx/pen.h"
19 #include "wx/colour.h"
20 #include "wx/bitmap.h"
21
22 //-----------------------------------------------------------------------------
23 // wxPen
24 //-----------------------------------------------------------------------------
25
26 class wxPenRefData: public wxObjectRefData
27 {
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;
52 m_stipple = data.m_stipple;
53 }
54
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;
70 wxBitmap m_stipple;
71 wxX11Dash *m_dash;
72 };
73
74 //-----------------------------------------------------------------------------
75
76 #define M_PENDATA ((wxPenRefData *)m_refData)
77
78 IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
79
80 wxPen::wxPen( const wxColour &colour, int width, int style )
81 {
82 m_refData = new wxPenRefData();
83 M_PENDATA->m_width = width;
84 M_PENDATA->m_style = style;
85 M_PENDATA->m_colour = colour;
86 }
87
88 wxPen::~wxPen()
89 {
90 // m_refData unrefed in ~wxObject
91 }
92
93 wxObjectRefData *wxPen::CreateRefData() const
94 {
95 return new wxPenRefData;
96 }
97
98 wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const
99 {
100 return new wxPenRefData(*(wxPenRefData *)data);
101 }
102
103 bool wxPen::operator == ( const wxPen& pen ) const
104 {
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 );
110 }
111
112 void wxPen::SetColour( const wxColour &colour )
113 {
114 AllocExclusive();
115
116 M_PENDATA->m_colour = colour;
117 }
118
119 void wxPen::SetDashes( int number_of_dashes, const wxDash *dash )
120 {
121 AllocExclusive();
122
123 M_PENDATA->m_countDashes = number_of_dashes;
124 M_PENDATA->m_dash = (wxX11Dash *)dash; // TODO
125 }
126
127 void wxPen::SetColour( int red, int green, int blue )
128 {
129 AllocExclusive();
130
131 M_PENDATA->m_colour.Set( red, green, blue );
132 }
133
134 void wxPen::SetCap( int capStyle )
135 {
136 AllocExclusive();
137
138 M_PENDATA->m_capStyle = capStyle;
139 }
140
141 void wxPen::SetJoin( int joinStyle )
142 {
143 AllocExclusive();
144
145 M_PENDATA->m_joinStyle = joinStyle;
146 }
147
148 void wxPen::SetStipple( wxBitmap *stipple )
149 {
150 AllocExclusive();
151
152 M_PENDATA->m_stipple = *stipple;;
153 }
154
155 void wxPen::SetStyle( int style )
156 {
157 AllocExclusive();
158
159 M_PENDATA->m_style = style;
160 }
161
162 void wxPen::SetWidth( int width )
163 {
164 AllocExclusive();
165
166 M_PENDATA->m_width = width;
167 }
168
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 }
174
175 int wxPen::GetDashCount() const
176 {
177 return (M_PENDATA->m_countDashes);
178 }
179
180 wxDash* wxPen::GetDash() const
181 {
182 return (wxDash*)M_PENDATA->m_dash;
183 }
184
185 int wxPen::GetCap() const
186 {
187 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
188
189 return M_PENDATA->m_capStyle;
190 }
191
192 int wxPen::GetJoin() const
193 {
194 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
195
196 return M_PENDATA->m_joinStyle;
197 }
198
199 int wxPen::GetStyle() const
200 {
201 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
202
203 return M_PENDATA->m_style;
204 }
205
206 int wxPen::GetWidth() const
207 {
208 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
209
210 return M_PENDATA->m_width;
211 }
212
213 wxColour &wxPen::GetColour() const
214 {
215 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
216
217 return M_PENDATA->m_colour;
218 }
219
220 wxBitmap *wxPen::GetStipple() const
221 {
222 wxCHECK_MSG( Ok(), &wxNullBitmap, wxT("invalid pen") );
223
224 return &M_PENDATA->m_stipple;
225 }