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