]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/pen.cpp
Put braces around all calls to wxLogFunctions() inside an if statement.
[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"
7cf41a5d
WS
14
15#ifndef WX_PRECOMP
16 #include "wx/colour.h"
17#endif
c801d85f 18
5e7e9e1b 19#include <gdk/gdk.h>
83624f79 20
c801d85f
KB
21//-----------------------------------------------------------------------------
22// wxPen
23//-----------------------------------------------------------------------------
24
10d30222 25class wxPenRefData : public wxGDIRefData
c801d85f 26{
907789a0 27public:
c89f5c02
RR
28 wxPenRefData()
29 {
30 m_width = 1;
ed7ec76d 31 m_style = wxPENSTYLE_SOLID;
c89f5c02
RR
32 m_joinStyle = wxJOIN_ROUND;
33 m_capStyle = wxCAP_ROUND;
d3b9f782 34 m_dash = NULL;
c89f5c02
RR
35 m_countDashes = 0;
36 }
46562151 37
c89f5c02 38 wxPenRefData( const wxPenRefData& data )
10d30222 39 : wxGDIRefData()
c89f5c02
RR
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;
c89f5c02
RR
47 m_dash = data.m_dash;
48 }
49
50 bool operator == (const wxPenRefData& data) const
51 {
17be8531 52 if ( m_countDashes != data.m_countDashes )
46562151 53 return false;
17be8531
VZ
54
55 if ( m_dash )
56 {
57 if ( !data.m_dash ||
58 memcmp(m_dash, data.m_dash, m_countDashes*sizeof(wxGTKDash)) )
59 {
46562151 60 return false;
17be8531
VZ
61 }
62 }
63 else if ( data.m_dash )
64 {
46562151 65 return false;
17be8531
VZ
66 }
67
68
69 return m_style == data.m_style &&
70 m_width == data.m_width &&
71 m_joinStyle == data.m_joinStyle &&
72 m_capStyle == data.m_capStyle &&
73 m_colour == data.m_colour;
c89f5c02 74 }
46562151 75
c89f5c02 76 int m_width;
82cddbd9
FM
77 wxPenStyle m_style;
78 wxPenJoin m_joinStyle;
79 wxPenCap m_capStyle;
c89f5c02
RR
80 wxColour m_colour;
81 int m_countDashes;
82 wxGTKDash *m_dash;
83};
e55ad60e 84
c801d85f
KB
85//-----------------------------------------------------------------------------
86
87#define M_PENDATA ((wxPenRefData *)m_refData)
88
89IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
90
82cddbd9 91wxPen::wxPen( const wxColour &colour, int width, wxPenStyle style )
c801d85f 92{
907789a0
RR
93 m_refData = new wxPenRefData();
94 M_PENDATA->m_width = width;
95 M_PENDATA->m_style = style;
96 M_PENDATA->m_colour = colour;
ff7b1510 97}
c801d85f 98
ac3688c0
FM
99#if FUTURE_WXWIN_COMPATIBILITY_3_0
100wxPen::wxPen(const wxColour& colour, int width, int style)
82cddbd9
FM
101{
102 m_refData = new wxPenRefData();
103 M_PENDATA->m_width = width;
104 M_PENDATA->m_style = (wxPenStyle)style;
105 M_PENDATA->m_colour = colour;
106}
ac3688c0 107#endif
82cddbd9 108
8f884a0d 109wxGDIRefData *wxPen::CreateGDIRefData() const
c801d85f 110{
c89f5c02 111 return new wxPenRefData;
ff7b1510 112}
c801d85f 113
8f884a0d 114wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const
c801d85f 115{
c89f5c02 116 return new wxPenRefData(*(wxPenRefData *)data);
ff7b1510 117}
c801d85f 118
c89f5c02 119bool wxPen::operator == ( const wxPen& pen ) const
c801d85f 120{
46562151
WS
121 if (m_refData == pen.m_refData) return true;
122
123 if (!m_refData || !pen.m_refData) return false;
124
1d57de48 125 return *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData;
ff7b1510 126}
c801d85f
KB
127
128void wxPen::SetColour( const wxColour &colour )
129{
c89f5c02 130 AllocExclusive();
46562151 131
907789a0 132 M_PENDATA->m_colour = colour;
ff7b1510 133}
c801d85f 134
112c5086
RR
135void wxPen::SetDashes( int number_of_dashes, const wxDash *dash )
136{
c89f5c02 137 AllocExclusive();
46562151 138
112c5086 139 M_PENDATA->m_countDashes = number_of_dashes;
17be8531 140 M_PENDATA->m_dash = (wxGTKDash *)dash;
112c5086
RR
141}
142
1a1498c0 143void wxPen::SetColour( unsigned char red, unsigned char green, unsigned char blue )
c801d85f 144{
c89f5c02 145 AllocExclusive();
46562151 146
907789a0 147 M_PENDATA->m_colour.Set( red, green, blue );
ff7b1510 148}
c801d85f 149
82cddbd9 150void wxPen::SetCap( wxPenCap capStyle )
c801d85f 151{
c89f5c02 152 AllocExclusive();
46562151 153
907789a0 154 M_PENDATA->m_capStyle = capStyle;
ff7b1510 155}
c801d85f 156
82cddbd9 157void wxPen::SetJoin( wxPenJoin joinStyle )
c801d85f 158{
c89f5c02 159 AllocExclusive();
46562151 160
907789a0 161 M_PENDATA->m_joinStyle = joinStyle;
ff7b1510 162}
c801d85f 163
82cddbd9 164void wxPen::SetStyle( wxPenStyle style )
c801d85f 165{
c89f5c02 166 AllocExclusive();
46562151 167
907789a0 168 M_PENDATA->m_style = style;
ff7b1510 169}
c801d85f
KB
170
171void wxPen::SetWidth( int width )
172{
c89f5c02 173 AllocExclusive();
46562151 174
907789a0 175 M_PENDATA->m_width = width;
ff7b1510 176}
c801d85f 177
1d57de48
VZ
178void wxPen::SetStipple(const wxBitmap& WXUNUSED(stipple))
179{
180 wxFAIL_MSG( "stippled pens not supported" );
181}
182
7ecb8b06 183int wxPen::GetDashes( wxDash **ptr ) const
112c5086 184{
ac3688c0
FM
185 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
186
187 *ptr = (wxDash*)M_PENDATA->m_dash;
188 return M_PENDATA->m_countDashes;
112c5086
RR
189}
190
7ecb8b06
VZ
191int wxPen::GetDashCount() const
192{
ac3688c0
FM
193 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
194
7ecb8b06 195 return (M_PENDATA->m_countDashes);
112c5086
RR
196}
197
7ecb8b06
VZ
198wxDash* wxPen::GetDash() const
199{
ac3688c0
FM
200 wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") );
201
7ecb8b06 202 return (wxDash*)M_PENDATA->m_dash;
112c5086
RR
203}
204
82cddbd9 205wxPenCap wxPen::GetCap() const
c801d85f 206{
1d57de48 207 wxCHECK_MSG( Ok(), wxCAP_INVALID, wxT("invalid pen") );
8bbe427f 208
907789a0 209 return M_PENDATA->m_capStyle;
ff7b1510 210}
c801d85f 211
82cddbd9 212wxPenJoin wxPen::GetJoin() const
c801d85f 213{
1d57de48 214 wxCHECK_MSG( Ok(), wxJOIN_INVALID, wxT("invalid pen") );
8bbe427f 215
907789a0 216 return M_PENDATA->m_joinStyle;
ff7b1510 217}
c801d85f 218
82cddbd9 219wxPenStyle wxPen::GetStyle() const
c801d85f 220{
1d57de48 221 wxCHECK_MSG( Ok(), wxPENSTYLE_INVALID, wxT("invalid pen") );
8bbe427f 222
907789a0 223 return M_PENDATA->m_style;
ff7b1510 224}
c801d85f 225
907789a0 226int wxPen::GetWidth() const
c801d85f 227{
223d09f6 228 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
8bbe427f 229
907789a0 230 return M_PENDATA->m_width;
ff7b1510 231}
c801d85f 232
231b9591 233wxColour wxPen::GetColour() const
c801d85f 234{
223d09f6 235 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
8bbe427f 236
907789a0 237 return M_PENDATA->m_colour;
ff7b1510 238}
1d57de48
VZ
239
240wxBitmap *wxPen::GetStipple() const
241{
242 return NULL;
243}
244