]> git.saurik.com Git - wxWidgets.git/blame - src/x11/pen.cpp
fixed line endings
[wxWidgets.git] / src / x11 / pen.cpp
CommitLineData
83df96d6 1/////////////////////////////////////////////////////////////////////////////
7266b672 2// Name: src/x11/pen.cpp
83df96d6
JS
3// Purpose: wxPen
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
83df96d6
JS
10/////////////////////////////////////////////////////////////////////////////
11
55034339
WS
12// for compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
83df96d6 15#include "wx/pen.h"
de6185e2
WS
16
17#ifndef WX_PRECOMP
18 #include "wx/utils.h"
19#endif
20
69c44812
MB
21#include "wx/colour.h"
22#include "wx/bitmap.h"
83df96d6 23
74dc5eb6
RR
24//-----------------------------------------------------------------------------
25// wxPen
26//-----------------------------------------------------------------------------
83df96d6 27
74dc5eb6 28class wxPenRefData: public wxObjectRefData
83df96d6 29{
74dc5eb6
RR
30public:
31 wxPenRefData()
32 {
33 m_width = 1;
34 m_style = wxSOLID;
35 m_joinStyle = wxJOIN_ROUND;
36 m_capStyle = wxCAP_ROUND;
37 m_dash = (wxX11Dash*) NULL;
38 m_countDashes = 0;
39 }
55034339 40
74dc5eb6
RR
41 wxPenRefData( const wxPenRefData& data )
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;
49/*
50 if (data.m_dash) TODO
51 m_dash = new
52*/
53 m_dash = data.m_dash;
69c44812 54 m_stipple = data.m_stipple;
74dc5eb6 55 }
83df96d6 56
74dc5eb6
RR
57 bool operator == (const wxPenRefData& data) const
58 {
59 return (m_style == data.m_style &&
60 m_width == data.m_width &&
61 m_joinStyle == data.m_joinStyle &&
62 m_capStyle == data.m_capStyle &&
63 m_colour == data.m_colour);
64 }
55034339 65
74dc5eb6
RR
66 int m_width;
67 int m_style;
68 int m_joinStyle;
69 int m_capStyle;
70 wxColour m_colour;
71 int m_countDashes;
69c44812 72 wxBitmap m_stipple;
74dc5eb6
RR
73 wxX11Dash *m_dash;
74};
83df96d6 75
74dc5eb6
RR
76//-----------------------------------------------------------------------------
77
78#define M_PENDATA ((wxPenRefData *)m_refData)
83df96d6 79
74dc5eb6 80IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
83df96d6 81
74dc5eb6 82wxPen::wxPen( const wxColour &colour, int width, int style )
83df96d6 83{
74dc5eb6
RR
84 m_refData = new wxPenRefData();
85 M_PENDATA->m_width = width;
86 M_PENDATA->m_style = style;
87 M_PENDATA->m_colour = colour;
83df96d6
JS
88}
89
90wxPen::~wxPen()
91{
74dc5eb6 92 // m_refData unrefed in ~wxObject
83df96d6
JS
93}
94
74dc5eb6 95wxObjectRefData *wxPen::CreateRefData() const
83df96d6 96{
74dc5eb6 97 return new wxPenRefData;
83df96d6
JS
98}
99
74dc5eb6 100wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const
83df96d6 101{
74dc5eb6 102 return new wxPenRefData(*(wxPenRefData *)data);
83df96d6
JS
103}
104
74dc5eb6 105bool wxPen::operator == ( const wxPen& pen ) const
83df96d6 106{
55034339
WS
107 if (m_refData == pen.m_refData) return true;
108
109 if (!m_refData || !pen.m_refData) return false;
110
74dc5eb6 111 return ( *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData );
83df96d6
JS
112}
113
74dc5eb6 114void wxPen::SetColour( const wxColour &colour )
83df96d6 115{
74dc5eb6 116 AllocExclusive();
55034339 117
74dc5eb6 118 M_PENDATA->m_colour = colour;
83df96d6
JS
119}
120
74dc5eb6 121void wxPen::SetDashes( int number_of_dashes, const wxDash *dash )
83df96d6 122{
74dc5eb6 123 AllocExclusive();
55034339 124
74dc5eb6
RR
125 M_PENDATA->m_countDashes = number_of_dashes;
126 M_PENDATA->m_dash = (wxX11Dash *)dash; // TODO
127}
83df96d6 128
1a1498c0 129void wxPen::SetColour( unsigned char red, unsigned char green, unsigned char blue )
74dc5eb6
RR
130{
131 AllocExclusive();
55034339 132
74dc5eb6 133 M_PENDATA->m_colour.Set( red, green, blue );
83df96d6
JS
134}
135
74dc5eb6 136void wxPen::SetCap( int capStyle )
83df96d6 137{
74dc5eb6 138 AllocExclusive();
55034339 139
74dc5eb6
RR
140 M_PENDATA->m_capStyle = capStyle;
141}
83df96d6 142
74dc5eb6
RR
143void wxPen::SetJoin( int joinStyle )
144{
145 AllocExclusive();
55034339 146
74dc5eb6
RR
147 M_PENDATA->m_joinStyle = joinStyle;
148}
83df96d6 149
69c44812
MB
150void wxPen::SetStipple( wxBitmap *stipple )
151{
152 AllocExclusive();
55034339 153
1c4cd9e0 154 M_PENDATA->m_stipple = *stipple;
69c44812
MB
155}
156
74dc5eb6
RR
157void wxPen::SetStyle( int style )
158{
159 AllocExclusive();
55034339 160
74dc5eb6 161 M_PENDATA->m_style = style;
83df96d6
JS
162}
163
74dc5eb6 164void wxPen::SetWidth( int width )
83df96d6 165{
74dc5eb6 166 AllocExclusive();
55034339 167
74dc5eb6
RR
168 M_PENDATA->m_width = width;
169}
83df96d6 170
74dc5eb6
RR
171int wxPen::GetDashes( wxDash **ptr ) const
172{
173 *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL);
174 return (M_PENDATA ? M_PENDATA->m_countDashes : 0);
175}
83df96d6 176
74dc5eb6
RR
177int wxPen::GetDashCount() const
178{
179 return (M_PENDATA->m_countDashes);
83df96d6
JS
180}
181
74dc5eb6 182wxDash* wxPen::GetDash() const
83df96d6 183{
74dc5eb6
RR
184 return (wxDash*)M_PENDATA->m_dash;
185}
83df96d6 186
74dc5eb6
RR
187int wxPen::GetCap() const
188{
189 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
83df96d6 190
74dc5eb6 191 return M_PENDATA->m_capStyle;
83df96d6
JS
192}
193
74dc5eb6 194int wxPen::GetJoin() const
83df96d6 195{
74dc5eb6 196 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
83df96d6 197
74dc5eb6 198 return M_PENDATA->m_joinStyle;
83df96d6
JS
199}
200
74dc5eb6 201int wxPen::GetStyle() const
83df96d6 202{
74dc5eb6 203 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
83df96d6 204
74dc5eb6 205 return M_PENDATA->m_style;
83df96d6
JS
206}
207
74dc5eb6 208int wxPen::GetWidth() const
83df96d6 209{
74dc5eb6 210 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
83df96d6 211
74dc5eb6 212 return M_PENDATA->m_width;
83df96d6
JS
213}
214
74dc5eb6 215wxColour &wxPen::GetColour() const
83df96d6 216{
74dc5eb6 217 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
83df96d6 218
74dc5eb6
RR
219 return M_PENDATA->m_colour;
220}
69c44812
MB
221
222wxBitmap *wxPen::GetStipple() const
223{
224 wxCHECK_MSG( Ok(), &wxNullBitmap, wxT("invalid pen") );
225
226 return &M_PENDATA->m_stipple;
227}