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