]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/pen.cpp
hack to implement right aligned checkboxes
[wxWidgets.git] / src / gtk1 / 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
83624f79
RR
17#include "gdk/gdk.h"
18
c801d85f
KB
19//-----------------------------------------------------------------------------
20// wxPen
21//-----------------------------------------------------------------------------
22
23class wxPenRefData: public wxObjectRefData
24{
907789a0 25public:
8bbe427f 26
907789a0
RR
27 wxPenRefData(void);
28 wxPenRefData(const wxPenRefData& data);
8bbe427f 29
907789a0
RR
30 int m_width;
31 int m_style;
32 int m_joinStyle;
33 int m_capStyle;
34 wxColour m_colour;
c801d85f
KB
35};
36
907789a0 37wxPenRefData::wxPenRefData()
c801d85f 38{
907789a0
RR
39 m_width = 1;
40 m_style = wxSOLID;
41 m_joinStyle = wxJOIN_ROUND;
42 m_capStyle = wxCAP_ROUND;
ff7b1510 43}
c801d85f 44
e55ad60e
RR
45wxPenRefData::wxPenRefData( const wxPenRefData& data )
46{
907789a0
RR
47 m_style = data.m_style;
48 m_width = data.m_width;
49 m_joinStyle = data.m_joinStyle;
50 m_capStyle = data.m_capStyle;
51 m_colour = data.m_colour;
e55ad60e
RR
52}
53
c801d85f
KB
54//-----------------------------------------------------------------------------
55
56#define M_PENDATA ((wxPenRefData *)m_refData)
57
58IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
59
8bbe427f 60wxPen::wxPen()
c801d85f 61{
907789a0 62 if (wxThePenList) wxThePenList->AddPen( this );
ff7b1510 63}
c801d85f
KB
64
65wxPen::wxPen( const wxColour &colour, int width, int style )
66{
907789a0
RR
67 m_refData = new wxPenRefData();
68 M_PENDATA->m_width = width;
69 M_PENDATA->m_style = style;
70 M_PENDATA->m_colour = colour;
8bbe427f 71
907789a0 72 if (wxThePenList) wxThePenList->AddPen( this );
ff7b1510 73}
c801d85f 74
c801d85f
KB
75wxPen::wxPen( const wxPen& pen )
76{
907789a0
RR
77 Ref( pen );
78 if (wxThePenList) wxThePenList->AddPen( this );
ff7b1510 79}
c801d85f 80
907789a0 81wxPen::~wxPen()
c801d85f 82{
907789a0 83 if (wxThePenList) wxThePenList->RemovePen( this );
ff7b1510 84}
c801d85f
KB
85
86wxPen& wxPen::operator = ( const wxPen& pen )
87{
8bbe427f
VZ
88 if (*this == pen) return (*this);
89 Ref( pen );
90 return *this;
ff7b1510 91}
c801d85f
KB
92
93bool wxPen::operator == ( const wxPen& pen )
94{
8bbe427f 95 return m_refData == pen.m_refData;
ff7b1510 96}
c801d85f
KB
97
98bool wxPen::operator != ( const wxPen& pen )
99{
8bbe427f 100 return m_refData != pen.m_refData;
ff7b1510 101}
c801d85f
KB
102
103void wxPen::SetColour( const wxColour &colour )
104{
907789a0
RR
105 Unshare();
106 M_PENDATA->m_colour = colour;
ff7b1510 107}
c801d85f 108
debe6624 109void wxPen::SetColour( int red, int green, int blue )
c801d85f 110{
907789a0
RR
111 Unshare();
112 M_PENDATA->m_colour.Set( red, green, blue );
ff7b1510 113}
c801d85f
KB
114
115void wxPen::SetCap( int capStyle )
116{
907789a0
RR
117 Unshare();
118 M_PENDATA->m_capStyle = capStyle;
ff7b1510 119}
c801d85f
KB
120
121void wxPen::SetJoin( int joinStyle )
122{
907789a0
RR
123 Unshare();
124 M_PENDATA->m_joinStyle = joinStyle;
ff7b1510 125}
c801d85f
KB
126
127void wxPen::SetStyle( int style )
128{
907789a0
RR
129 Unshare();
130 M_PENDATA->m_style = style;
ff7b1510 131}
c801d85f
KB
132
133void wxPen::SetWidth( int width )
134{
907789a0
RR
135 Unshare();
136 M_PENDATA->m_width = width;
ff7b1510 137}
c801d85f 138
907789a0 139int wxPen::GetCap() const
c801d85f 140{
907789a0 141 wxCHECK_MSG( Ok(), -1, "invalid pen" );
8bbe427f 142
907789a0 143 return M_PENDATA->m_capStyle;
ff7b1510 144}
c801d85f 145
907789a0 146int wxPen::GetJoin() const
c801d85f 147{
907789a0 148 wxCHECK_MSG( Ok(), -1, "invalid pen" );
8bbe427f 149
907789a0 150 return M_PENDATA->m_joinStyle;
ff7b1510 151}
c801d85f 152
907789a0 153int wxPen::GetStyle() const
c801d85f 154{
907789a0 155 wxCHECK_MSG( Ok(), -1, "invalid pen" );
8bbe427f 156
907789a0 157 return M_PENDATA->m_style;
ff7b1510 158}
c801d85f 159
907789a0 160int wxPen::GetWidth() const
c801d85f 161{
907789a0 162 wxCHECK_MSG( Ok(), -1, "invalid pen" );
8bbe427f 163
907789a0 164 return M_PENDATA->m_width;
ff7b1510 165}
c801d85f 166
907789a0 167wxColour &wxPen::GetColour() const
c801d85f 168{
907789a0 169 wxCHECK_MSG( Ok(), wxNullColour, "invalid pen" );
8bbe427f 170
907789a0 171 return M_PENDATA->m_colour;
ff7b1510 172}
c801d85f 173
907789a0 174bool wxPen::Ok() const
c801d85f 175{
907789a0 176 return (m_refData != NULL);
e55ad60e
RR
177}
178
907789a0 179void wxPen::Unshare()
e55ad60e 180{
907789a0
RR
181 if (!m_refData)
182 {
183 m_refData = new wxPenRefData();
184 }
185 else
186 {
187 wxPenRefData* ref = new wxPenRefData( *(wxPenRefData*)m_refData );
188 UnRef();
189 m_refData = ref;
190 }
ff7b1510 191}
c801d85f 192