]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/pen.cpp
derive wxSTC from wxTextEntryBase to provide even more wxTextCtrl-like methods (see...
[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
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}
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{
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{
82cddbd9 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{
82cddbd9 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{
ac3688c0 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}
04edbb23
VZ
239
240// stippled pens are not supported by wxGTK
241void wxPen::SetStipple(const wxBitmap& WXUNUSED(stipple))
242{
243 wxFAIL_MSG( "stippled pens not supported" );
244}
245
246wxBitmap *wxPen::GetStipple() const
247{
248 return NULL;
249}
250