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