]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk1/pen.cpp
Added Mac OS X resource file handling:
[wxWidgets.git] / src / gtk1 / pen.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: pen.cpp
3// Purpose:
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10
11#ifdef __GNUG__
12#pragma implementation "pen.h"
13#endif
14
15#include "wx/pen.h"
16
17#include <gdk/gdk.h>
18
19//-----------------------------------------------------------------------------
20// wxPen
21//-----------------------------------------------------------------------------
22
23class wxPenRefData: public wxObjectRefData
24{
25public:
26
27 wxPenRefData();
28 wxPenRefData( const wxPenRefData& data );
29
30 int m_width;
31 int m_style;
32 int m_joinStyle;
33 int m_capStyle;
34 wxColour m_colour;
35 int m_countDashes;
36 wxGTKDash *m_dash;
37};
38
39wxPenRefData::wxPenRefData()
40{
41 m_width = 1;
42 m_style = wxSOLID;
43 m_joinStyle = wxJOIN_ROUND;
44 m_capStyle = wxCAP_ROUND;
45 m_dash = (wxGTKDash*) NULL;
46 m_countDashes = 0;
47}
48
49wxPenRefData::wxPenRefData( const wxPenRefData& data )
50{
51 m_style = data.m_style;
52 m_width = data.m_width;
53 m_joinStyle = data.m_joinStyle;
54 m_capStyle = data.m_capStyle;
55 m_colour = data.m_colour;
56 m_countDashes = data.m_countDashes;
57/*
58 if (data.m_dash) TODO
59 m_dash = new
60*/
61 m_dash = data.m_dash;
62}
63
64//-----------------------------------------------------------------------------
65
66#define M_PENDATA ((wxPenRefData *)m_refData)
67
68IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
69
70wxPen::wxPen()
71{
72 if (wxThePenList) wxThePenList->AddPen( this );
73}
74
75wxPen::wxPen( const wxColour &colour, int width, int style )
76{
77 m_refData = new wxPenRefData();
78 M_PENDATA->m_width = width;
79 M_PENDATA->m_style = style;
80 M_PENDATA->m_colour = colour;
81
82 if (wxThePenList) wxThePenList->AddPen( this );
83}
84
85wxPen::wxPen( const wxPen& pen )
86{
87 Ref( pen );
88 if (wxThePenList) wxThePenList->AddPen( this );
89}
90
91wxPen::~wxPen()
92{
93 if (wxThePenList) wxThePenList->RemovePen( this );
94}
95
96wxPen& wxPen::operator = ( const wxPen& pen )
97{
98 if (*this == pen) return (*this);
99 Ref( pen );
100 return *this;
101}
102
103bool wxPen::operator == ( const wxPen& pen ) const
104{
105 return m_refData == pen.m_refData;
106}
107
108bool wxPen::operator != ( const wxPen& pen ) const
109{
110 return m_refData != pen.m_refData;
111}
112
113void wxPen::SetColour( const wxColour &colour )
114{
115 Unshare();
116 M_PENDATA->m_colour = colour;
117}
118
119void wxPen::SetDashes( int number_of_dashes, const wxDash *dash )
120{
121 Unshare();
122 M_PENDATA->m_countDashes = number_of_dashes;
123 M_PENDATA->m_dash = (wxGTKDash *)dash; /* TODO */
124}
125
126void wxPen::SetColour( int red, int green, int blue )
127{
128 Unshare();
129 M_PENDATA->m_colour.Set( red, green, blue );
130}
131
132void wxPen::SetCap( int capStyle )
133{
134 Unshare();
135 M_PENDATA->m_capStyle = capStyle;
136}
137
138void wxPen::SetJoin( int joinStyle )
139{
140 Unshare();
141 M_PENDATA->m_joinStyle = joinStyle;
142}
143
144void wxPen::SetStyle( int style )
145{
146 Unshare();
147 M_PENDATA->m_style = style;
148}
149
150void wxPen::SetWidth( int width )
151{
152 Unshare();
153 M_PENDATA->m_width = width;
154}
155
156int wxPen::GetDashes( wxDash **ptr ) const
157{
158 *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL);
159 return (M_PENDATA ? M_PENDATA->m_countDashes : 0);
160}
161
162int wxPen::GetDashCount() const
163{
164 return (M_PENDATA->m_countDashes);
165}
166
167wxDash* wxPen::GetDash() const
168{
169 return (wxDash*)M_PENDATA->m_dash;
170}
171
172int wxPen::GetCap() const
173{
174 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
175
176 return M_PENDATA->m_capStyle;
177}
178
179int wxPen::GetJoin() const
180{
181 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
182
183 return M_PENDATA->m_joinStyle;
184}
185
186int wxPen::GetStyle() const
187{
188 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
189
190 return M_PENDATA->m_style;
191}
192
193int wxPen::GetWidth() const
194{
195 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
196
197 return M_PENDATA->m_width;
198}
199
200wxColour &wxPen::GetColour() const
201{
202 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
203
204 return M_PENDATA->m_colour;
205}
206
207bool wxPen::Ok() const
208{
209 return (m_refData != NULL);
210}
211
212void wxPen::Unshare()
213{
214 if (!m_refData)
215 {
216 m_refData = new wxPenRefData();
217 }
218 else
219 {
220 wxPenRefData* ref = new wxPenRefData( *(wxPenRefData*)m_refData );
221 UnRef();
222 m_refData = ref;
223 }
224}
225