]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/pen.cpp
no changes but more comments in DoSetClientSize() (explains the change of rev 1.624...
[wxWidgets.git] / src / gtk1 / pen.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
3cbab641 2// Name: src/gtk1/pen.cpp
c801d85f
KB
3// Purpose:
4// Author: Robert Roebling
a81258be
RR
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
65571936 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
c801d85f 13#include "wx/pen.h"
ed39ff57 14#include "wx/colour.h"
c801d85f 15
5e7e9e1b 16#include <gdk/gdk.h>
83624f79 17
c801d85f
KB
18//-----------------------------------------------------------------------------
19// wxPen
20//-----------------------------------------------------------------------------
21
22class wxPenRefData: public wxObjectRefData
23{
907789a0 24public:
c89f5c02
RR
25 wxPenRefData()
26 {
27 m_width = 1;
28 m_style = wxSOLID;
29 m_joinStyle = wxJOIN_ROUND;
30 m_capStyle = wxCAP_ROUND;
31 m_dash = (wxGTKDash*) NULL;
32 m_countDashes = 0;
33 }
46562151 34
c89f5c02 35 wxPenRefData( const wxPenRefData& data )
d84afea9 36 : wxObjectRefData()
c89f5c02
RR
37 {
38 m_style = data.m_style;
39 m_width = data.m_width;
40 m_joinStyle = data.m_joinStyle;
41 m_capStyle = data.m_capStyle;
42 m_colour = data.m_colour;
43 m_countDashes = data.m_countDashes;
c89f5c02
RR
44 m_dash = data.m_dash;
45 }
46
47 bool operator == (const wxPenRefData& data) const
48 {
17be8531 49 if ( m_countDashes != data.m_countDashes )
46562151 50 return false;
17be8531
VZ
51
52 if ( m_dash )
53 {
54 if ( !data.m_dash ||
55 memcmp(m_dash, data.m_dash, m_countDashes*sizeof(wxGTKDash)) )
56 {
46562151 57 return false;
17be8531
VZ
58 }
59 }
60 else if ( data.m_dash )
61 {
46562151 62 return false;
17be8531
VZ
63 }
64
65
66 return m_style == data.m_style &&
67 m_width == data.m_width &&
68 m_joinStyle == data.m_joinStyle &&
69 m_capStyle == data.m_capStyle &&
70 m_colour == data.m_colour;
c89f5c02 71 }
46562151 72
c89f5c02
RR
73 int m_width;
74 int m_style;
75 int m_joinStyle;
76 int m_capStyle;
77 wxColour m_colour;
78 int m_countDashes;
79 wxGTKDash *m_dash;
80};
e55ad60e 81
c801d85f
KB
82//-----------------------------------------------------------------------------
83
84#define M_PENDATA ((wxPenRefData *)m_refData)
85
86IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
87
c801d85f
KB
88wxPen::wxPen( const wxColour &colour, int width, int style )
89{
907789a0
RR
90 m_refData = new wxPenRefData();
91 M_PENDATA->m_width = width;
92 M_PENDATA->m_style = style;
93 M_PENDATA->m_colour = colour;
ff7b1510 94}
c801d85f 95
907789a0 96wxPen::~wxPen()
c801d85f 97{
c89f5c02 98 // m_refData unrefed in ~wxObject
ff7b1510 99}
c801d85f 100
c89f5c02 101wxObjectRefData *wxPen::CreateRefData() const
c801d85f 102{
c89f5c02 103 return new wxPenRefData;
ff7b1510 104}
c801d85f 105
c89f5c02 106wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const
c801d85f 107{
c89f5c02 108 return new wxPenRefData(*(wxPenRefData *)data);
ff7b1510 109}
c801d85f 110
c89f5c02 111bool wxPen::operator == ( const wxPen& pen ) const
c801d85f 112{
46562151
WS
113 if (m_refData == pen.m_refData) return true;
114
115 if (!m_refData || !pen.m_refData) return false;
116
c89f5c02 117 return ( *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData );
ff7b1510 118}
c801d85f
KB
119
120void wxPen::SetColour( const wxColour &colour )
121{
c89f5c02 122 AllocExclusive();
46562151 123
907789a0 124 M_PENDATA->m_colour = colour;
ff7b1510 125}
c801d85f 126
112c5086
RR
127void wxPen::SetDashes( int number_of_dashes, const wxDash *dash )
128{
c89f5c02 129 AllocExclusive();
46562151 130
112c5086 131 M_PENDATA->m_countDashes = number_of_dashes;
17be8531 132 M_PENDATA->m_dash = (wxGTKDash *)dash;
112c5086
RR
133}
134
1a1498c0 135void wxPen::SetColour( unsigned char red, unsigned char green, unsigned char blue )
c801d85f 136{
c89f5c02 137 AllocExclusive();
46562151 138
907789a0 139 M_PENDATA->m_colour.Set( red, green, blue );
ff7b1510 140}
c801d85f
KB
141
142void wxPen::SetCap( int capStyle )
143{
c89f5c02 144 AllocExclusive();
46562151 145
907789a0 146 M_PENDATA->m_capStyle = capStyle;
ff7b1510 147}
c801d85f
KB
148
149void wxPen::SetJoin( int joinStyle )
150{
c89f5c02 151 AllocExclusive();
46562151 152
907789a0 153 M_PENDATA->m_joinStyle = joinStyle;
ff7b1510 154}
c801d85f
KB
155
156void wxPen::SetStyle( int style )
157{
c89f5c02 158 AllocExclusive();
46562151 159
907789a0 160 M_PENDATA->m_style = style;
ff7b1510 161}
c801d85f
KB
162
163void wxPen::SetWidth( int width )
164{
c89f5c02 165 AllocExclusive();
46562151 166
907789a0 167 M_PENDATA->m_width = width;
ff7b1510 168}
c801d85f 169
7ecb8b06 170int wxPen::GetDashes( wxDash **ptr ) const
112c5086 171{
7ecb8b06 172 *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL);
112c5086
RR
173 return (M_PENDATA ? M_PENDATA->m_countDashes : 0);
174}
175
7ecb8b06
VZ
176int wxPen::GetDashCount() const
177{
178 return (M_PENDATA->m_countDashes);
112c5086
RR
179}
180
7ecb8b06
VZ
181wxDash* wxPen::GetDash() const
182{
183 return (wxDash*)M_PENDATA->m_dash;
112c5086
RR
184}
185
907789a0 186int wxPen::GetCap() const
c801d85f 187{
223d09f6 188 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
8bbe427f 189
907789a0 190 return M_PENDATA->m_capStyle;
ff7b1510 191}
c801d85f 192
907789a0 193int wxPen::GetJoin() const
c801d85f 194{
223d09f6 195 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
8bbe427f 196
907789a0 197 return M_PENDATA->m_joinStyle;
ff7b1510 198}
c801d85f 199
907789a0 200int wxPen::GetStyle() const
c801d85f 201{
223d09f6 202 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
8bbe427f 203
907789a0 204 return M_PENDATA->m_style;
ff7b1510 205}
c801d85f 206
907789a0 207int wxPen::GetWidth() const
c801d85f 208{
223d09f6 209 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
8bbe427f 210
907789a0 211 return M_PENDATA->m_width;
ff7b1510 212}
c801d85f 213
907789a0 214wxColour &wxPen::GetColour() const
c801d85f 215{
223d09f6 216 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
8bbe427f 217
907789a0 218 return M_PENDATA->m_colour;
ff7b1510 219}