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