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