removed wxAcceleratorTable copy ctor docs, no port implements it
[wxWidgets.git] / src / gtk / pen.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
46562151 2// Name: src/gtk/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
8f884a0d 25class wxPenRefData: public wxGDIRefData
c801d85f 26{
907789a0 27public:
c89f5c02
RR
28 wxPenRefData()
29 {
30 m_width = 1;
82cddbd9 31 m_style = wxPENSTYLE_SOLID;
c89f5c02
RR
32 m_joinStyle = wxJOIN_ROUND;
33 m_capStyle = wxCAP_ROUND;
34 m_dash = (wxGTKDash*) NULL;
35 m_countDashes = 0;
36 }
46562151 37
c89f5c02 38 wxPenRefData( const wxPenRefData& data )
8f884a0d 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
04ee05f9 99#if WXWIN_COMPATIBILITY_2_8
82cddbd9
FM
100wxPen::wxPen(const wxColour& colour, int width, wxBrushStyle style)
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}
04ee05f9 107#endif
82cddbd9 108
907789a0 109wxPen::~wxPen()
c801d85f 110{
c89f5c02 111 // m_refData unrefed in ~wxObject
ff7b1510 112}
c801d85f 113
8f884a0d 114wxGDIRefData *wxPen::CreateGDIRefData() const
c801d85f 115{
c89f5c02 116 return new wxPenRefData;
ff7b1510 117}
c801d85f 118
8f884a0d 119wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const
c801d85f 120{
c89f5c02 121 return new wxPenRefData(*(wxPenRefData *)data);
ff7b1510 122}
c801d85f 123
c89f5c02 124bool wxPen::operator == ( const wxPen& pen ) const
c801d85f 125{
46562151
WS
126 if (m_refData == pen.m_refData) return true;
127
128 if (!m_refData || !pen.m_refData) return false;
129
c89f5c02 130 return ( *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData );
ff7b1510 131}
c801d85f
KB
132
133void wxPen::SetColour( const wxColour &colour )
134{
c89f5c02 135 AllocExclusive();
46562151 136
907789a0 137 M_PENDATA->m_colour = colour;
ff7b1510 138}
c801d85f 139
112c5086
RR
140void wxPen::SetDashes( int number_of_dashes, const wxDash *dash )
141{
c89f5c02 142 AllocExclusive();
46562151 143
112c5086 144 M_PENDATA->m_countDashes = number_of_dashes;
17be8531 145 M_PENDATA->m_dash = (wxGTKDash *)dash;
112c5086
RR
146}
147
1a1498c0 148void wxPen::SetColour( unsigned char red, unsigned char green, unsigned char blue )
c801d85f 149{
c89f5c02 150 AllocExclusive();
46562151 151
907789a0 152 M_PENDATA->m_colour.Set( red, green, blue );
ff7b1510 153}
c801d85f 154
82cddbd9 155void wxPen::SetCap( wxPenCap capStyle )
c801d85f 156{
c89f5c02 157 AllocExclusive();
46562151 158
907789a0 159 M_PENDATA->m_capStyle = capStyle;
ff7b1510 160}
c801d85f 161
82cddbd9 162void wxPen::SetJoin( wxPenJoin joinStyle )
c801d85f 163{
c89f5c02 164 AllocExclusive();
46562151 165
907789a0 166 M_PENDATA->m_joinStyle = joinStyle;
ff7b1510 167}
c801d85f 168
82cddbd9 169void wxPen::SetStyle( wxPenStyle style )
c801d85f 170{
c89f5c02 171 AllocExclusive();
46562151 172
907789a0 173 M_PENDATA->m_style = style;
ff7b1510 174}
c801d85f
KB
175
176void wxPen::SetWidth( int width )
177{
c89f5c02 178 AllocExclusive();
46562151 179
907789a0 180 M_PENDATA->m_width = width;
ff7b1510 181}
c801d85f 182
7ecb8b06 183int wxPen::GetDashes( wxDash **ptr ) const
112c5086 184{
7ecb8b06 185 *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL);
112c5086
RR
186 return (M_PENDATA ? M_PENDATA->m_countDashes : 0);
187}
188
7ecb8b06
VZ
189int wxPen::GetDashCount() const
190{
191 return (M_PENDATA->m_countDashes);
112c5086
RR
192}
193
7ecb8b06
VZ
194wxDash* wxPen::GetDash() const
195{
196 return (wxDash*)M_PENDATA->m_dash;
112c5086
RR
197}
198
82cddbd9 199wxPenCap wxPen::GetCap() const
c801d85f 200{
82cddbd9 201 wxCHECK_MSG( Ok(), wxCAP_INVALID, wxT("invalid pen") );
8bbe427f 202
907789a0 203 return M_PENDATA->m_capStyle;
ff7b1510 204}
c801d85f 205
82cddbd9 206wxPenJoin wxPen::GetJoin() const
c801d85f 207{
82cddbd9 208 wxCHECK_MSG( Ok(), wxJOIN_INVALID, wxT("invalid pen") );
8bbe427f 209
907789a0 210 return M_PENDATA->m_joinStyle;
ff7b1510 211}
c801d85f 212
82cddbd9 213wxPenStyle wxPen::GetStyle() const
c801d85f 214{
82cddbd9 215 wxCHECK_MSG( Ok(), wxPENSTYLE_MAX, wxT("invalid pen") );
8bbe427f 216
907789a0 217 return M_PENDATA->m_style;
ff7b1510 218}
c801d85f 219
907789a0 220int wxPen::GetWidth() const
c801d85f 221{
223d09f6 222 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
8bbe427f 223
907789a0 224 return M_PENDATA->m_width;
ff7b1510 225}
c801d85f 226
907789a0 227wxColour &wxPen::GetColour() const
c801d85f 228{
223d09f6 229 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
8bbe427f 230
907789a0 231 return M_PENDATA->m_colour;
ff7b1510 232}
04edbb23
VZ
233
234// stippled pens are not supported by wxGTK
235void wxPen::SetStipple(const wxBitmap& WXUNUSED(stipple))
236{
237 wxFAIL_MSG( "stippled pens not supported" );
238}
239
240wxBitmap *wxPen::GetStipple() const
241{
242 return NULL;
243}
244