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