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