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