]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/pen.cpp
avoiding nesting dcs on the same window concurrently
[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
25class wxPenRefData: public wxObjectRefData
26{
907789a0 27public:
c89f5c02
RR
28 wxPenRefData()
29 {
30 m_width = 1;
31 m_style = wxSOLID;
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 )
d84afea9 39 : wxObjectRefData()
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
RR
76 int m_width;
77 int m_style;
78 int m_joinStyle;
79 int m_capStyle;
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
c801d85f
KB
91wxPen::wxPen( const wxColour &colour, int width, int style )
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
907789a0 99wxPen::~wxPen()
c801d85f 100{
c89f5c02 101 // m_refData unrefed in ~wxObject
ff7b1510 102}
c801d85f 103
c89f5c02 104wxObjectRefData *wxPen::CreateRefData() const
c801d85f 105{
c89f5c02 106 return new wxPenRefData;
ff7b1510 107}
c801d85f 108
c89f5c02 109wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const
c801d85f 110{
c89f5c02 111 return new wxPenRefData(*(wxPenRefData *)data);
ff7b1510 112}
c801d85f 113
c89f5c02 114bool wxPen::operator == ( const wxPen& pen ) const
c801d85f 115{
46562151
WS
116 if (m_refData == pen.m_refData) return true;
117
118 if (!m_refData || !pen.m_refData) return false;
119
c89f5c02 120 return ( *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData );
ff7b1510 121}
c801d85f
KB
122
123void wxPen::SetColour( const wxColour &colour )
124{
c89f5c02 125 AllocExclusive();
46562151 126
907789a0 127 M_PENDATA->m_colour = colour;
ff7b1510 128}
c801d85f 129
112c5086
RR
130void wxPen::SetDashes( int number_of_dashes, const wxDash *dash )
131{
c89f5c02 132 AllocExclusive();
46562151 133
112c5086 134 M_PENDATA->m_countDashes = number_of_dashes;
17be8531 135 M_PENDATA->m_dash = (wxGTKDash *)dash;
112c5086
RR
136}
137
1a1498c0 138void wxPen::SetColour( unsigned char red, unsigned char green, unsigned char blue )
c801d85f 139{
c89f5c02 140 AllocExclusive();
46562151 141
907789a0 142 M_PENDATA->m_colour.Set( red, green, blue );
ff7b1510 143}
c801d85f
KB
144
145void wxPen::SetCap( int capStyle )
146{
c89f5c02 147 AllocExclusive();
46562151 148
907789a0 149 M_PENDATA->m_capStyle = capStyle;
ff7b1510 150}
c801d85f
KB
151
152void wxPen::SetJoin( int joinStyle )
153{
c89f5c02 154 AllocExclusive();
46562151 155
907789a0 156 M_PENDATA->m_joinStyle = joinStyle;
ff7b1510 157}
c801d85f
KB
158
159void wxPen::SetStyle( int style )
160{
c89f5c02 161 AllocExclusive();
46562151 162
907789a0 163 M_PENDATA->m_style = style;
ff7b1510 164}
c801d85f
KB
165
166void wxPen::SetWidth( int width )
167{
c89f5c02 168 AllocExclusive();
46562151 169
907789a0 170 M_PENDATA->m_width = width;
ff7b1510 171}
c801d85f 172
7ecb8b06 173int wxPen::GetDashes( wxDash **ptr ) const
112c5086 174{
7ecb8b06 175 *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL);
112c5086
RR
176 return (M_PENDATA ? M_PENDATA->m_countDashes : 0);
177}
178
7ecb8b06
VZ
179int wxPen::GetDashCount() const
180{
181 return (M_PENDATA->m_countDashes);
112c5086
RR
182}
183
7ecb8b06
VZ
184wxDash* wxPen::GetDash() const
185{
186 return (wxDash*)M_PENDATA->m_dash;
112c5086
RR
187}
188
907789a0 189int wxPen::GetCap() const
c801d85f 190{
223d09f6 191 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
8bbe427f 192
907789a0 193 return M_PENDATA->m_capStyle;
ff7b1510 194}
c801d85f 195
907789a0 196int wxPen::GetJoin() const
c801d85f 197{
223d09f6 198 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
8bbe427f 199
907789a0 200 return M_PENDATA->m_joinStyle;
ff7b1510 201}
c801d85f 202
907789a0 203int wxPen::GetStyle() const
c801d85f 204{
223d09f6 205 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
8bbe427f 206
907789a0 207 return M_PENDATA->m_style;
ff7b1510 208}
c801d85f 209
907789a0 210int wxPen::GetWidth() const
c801d85f 211{
223d09f6 212 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
8bbe427f 213
907789a0 214 return M_PENDATA->m_width;
ff7b1510 215}
c801d85f 216
907789a0 217wxColour &wxPen::GetColour() const
c801d85f 218{
223d09f6 219 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
8bbe427f 220
907789a0 221 return M_PENDATA->m_colour;
ff7b1510 222}