]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
3cbab641 | 2 | // Name: src/gtk1/pen.cpp |
c801d85f KB |
3 | // Purpose: |
4 | // Author: Robert Roebling | |
a81258be RR |
5 | // Id: $Id$ |
6 | // Copyright: (c) 1998 Robert Roebling | |
65571936 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
14f355c2 VS |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
12 | ||
c801d85f | 13 | #include "wx/pen.h" |
7cf41a5d WS |
14 | |
15 | #ifndef WX_PRECOMP | |
16 | #include "wx/colour.h" | |
17 | #endif | |
c801d85f | 18 | |
5e7e9e1b | 19 | #include <gdk/gdk.h> |
83624f79 | 20 | |
c801d85f KB |
21 | //----------------------------------------------------------------------------- |
22 | // wxPen | |
23 | //----------------------------------------------------------------------------- | |
24 | ||
10d30222 | 25 | class wxPenRefData : public wxGDIRefData |
c801d85f | 26 | { |
907789a0 | 27 | public: |
c89f5c02 RR |
28 | wxPenRefData() |
29 | { | |
30 | m_width = 1; | |
31 | m_style = wxSOLID; | |
32 | m_joinStyle = wxJOIN_ROUND; | |
33 | m_capStyle = wxCAP_ROUND; | |
34 | m_dash = (wxGTKDash*) NULL; | |
35 | m_countDashes = 0; | |
36 | } | |
46562151 | 37 | |
c89f5c02 | 38 | wxPenRefData( const wxPenRefData& data ) |
10d30222 | 39 | : wxGDIRefData() |
c89f5c02 RR |
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; | |
c89f5c02 RR |
47 | m_dash = data.m_dash; |
48 | } | |
49 | ||
50 | bool operator == (const wxPenRefData& data) const | |
51 | { | |
17be8531 | 52 | if ( m_countDashes != data.m_countDashes ) |
46562151 | 53 | return false; |
17be8531 VZ |
54 | |
55 | if ( m_dash ) | |
56 | { | |
57 | if ( !data.m_dash || | |
58 | memcmp(m_dash, data.m_dash, m_countDashes*sizeof(wxGTKDash)) ) | |
59 | { | |
46562151 | 60 | return false; |
17be8531 VZ |
61 | } |
62 | } | |
63 | else if ( data.m_dash ) | |
64 | { | |
46562151 | 65 | return false; |
17be8531 VZ |
66 | } |
67 | ||
68 | ||
69 | return m_style == data.m_style && | |
70 | m_width == data.m_width && | |
71 | m_joinStyle == data.m_joinStyle && | |
72 | m_capStyle == data.m_capStyle && | |
73 | m_colour == data.m_colour; | |
c89f5c02 | 74 | } |
46562151 | 75 | |
c89f5c02 | 76 | int m_width; |
82cddbd9 FM |
77 | wxPenStyle m_style; |
78 | wxPenJoin m_joinStyle; | |
79 | wxPenCap m_capStyle; | |
c89f5c02 RR |
80 | wxColour m_colour; |
81 | int m_countDashes; | |
82 | wxGTKDash *m_dash; | |
83 | }; | |
e55ad60e | 84 | |
c801d85f KB |
85 | //----------------------------------------------------------------------------- |
86 | ||
87 | #define M_PENDATA ((wxPenRefData *)m_refData) | |
88 | ||
89 | IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject) | |
90 | ||
82cddbd9 | 91 | wxPen::wxPen( const wxColour &colour, int width, wxPenStyle style ) |
c801d85f | 92 | { |
907789a0 RR |
93 | m_refData = new wxPenRefData(); |
94 | M_PENDATA->m_width = width; | |
95 | M_PENDATA->m_style = style; | |
96 | M_PENDATA->m_colour = colour; | |
ff7b1510 | 97 | } |
c801d85f | 98 | |
82cddbd9 FM |
99 | wxPen::wxPen(const wxColour& colour, int width, wxBrushStyle style) |
100 | { | |
101 | m_refData = new wxPenRefData(); | |
102 | M_PENDATA->m_width = width; | |
103 | M_PENDATA->m_style = (wxPenStyle)style; | |
104 | M_PENDATA->m_colour = colour; | |
105 | } | |
106 | ||
907789a0 | 107 | wxPen::~wxPen() |
c801d85f | 108 | { |
c89f5c02 | 109 | // m_refData unrefed in ~wxObject |
ff7b1510 | 110 | } |
c801d85f | 111 | |
8f884a0d | 112 | wxGDIRefData *wxPen::CreateGDIRefData() const |
c801d85f | 113 | { |
c89f5c02 | 114 | return new wxPenRefData; |
ff7b1510 | 115 | } |
c801d85f | 116 | |
8f884a0d | 117 | wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const |
c801d85f | 118 | { |
c89f5c02 | 119 | return new wxPenRefData(*(wxPenRefData *)data); |
ff7b1510 | 120 | } |
c801d85f | 121 | |
c89f5c02 | 122 | bool wxPen::operator == ( const wxPen& pen ) const |
c801d85f | 123 | { |
46562151 WS |
124 | if (m_refData == pen.m_refData) return true; |
125 | ||
126 | if (!m_refData || !pen.m_refData) return false; | |
127 | ||
c89f5c02 | 128 | return ( *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData ); |
ff7b1510 | 129 | } |
c801d85f KB |
130 | |
131 | void wxPen::SetColour( const wxColour &colour ) | |
132 | { | |
c89f5c02 | 133 | AllocExclusive(); |
46562151 | 134 | |
907789a0 | 135 | M_PENDATA->m_colour = colour; |
ff7b1510 | 136 | } |
c801d85f | 137 | |
112c5086 RR |
138 | void wxPen::SetDashes( int number_of_dashes, const wxDash *dash ) |
139 | { | |
c89f5c02 | 140 | AllocExclusive(); |
46562151 | 141 | |
112c5086 | 142 | M_PENDATA->m_countDashes = number_of_dashes; |
17be8531 | 143 | M_PENDATA->m_dash = (wxGTKDash *)dash; |
112c5086 RR |
144 | } |
145 | ||
1a1498c0 | 146 | void wxPen::SetColour( unsigned char red, unsigned char green, unsigned char blue ) |
c801d85f | 147 | { |
c89f5c02 | 148 | AllocExclusive(); |
46562151 | 149 | |
907789a0 | 150 | M_PENDATA->m_colour.Set( red, green, blue ); |
ff7b1510 | 151 | } |
c801d85f | 152 | |
82cddbd9 | 153 | void wxPen::SetCap( wxPenCap capStyle ) |
c801d85f | 154 | { |
c89f5c02 | 155 | AllocExclusive(); |
46562151 | 156 | |
907789a0 | 157 | M_PENDATA->m_capStyle = capStyle; |
ff7b1510 | 158 | } |
c801d85f | 159 | |
82cddbd9 | 160 | void wxPen::SetJoin( wxPenJoin joinStyle ) |
c801d85f | 161 | { |
c89f5c02 | 162 | AllocExclusive(); |
46562151 | 163 | |
907789a0 | 164 | M_PENDATA->m_joinStyle = joinStyle; |
ff7b1510 | 165 | } |
c801d85f | 166 | |
82cddbd9 | 167 | void wxPen::SetStyle( wxPenStyle style ) |
c801d85f | 168 | { |
c89f5c02 | 169 | AllocExclusive(); |
46562151 | 170 | |
907789a0 | 171 | M_PENDATA->m_style = style; |
ff7b1510 | 172 | } |
c801d85f KB |
173 | |
174 | void wxPen::SetWidth( int width ) | |
175 | { | |
c89f5c02 | 176 | AllocExclusive(); |
46562151 | 177 | |
907789a0 | 178 | M_PENDATA->m_width = width; |
ff7b1510 | 179 | } |
c801d85f | 180 | |
7ecb8b06 | 181 | int wxPen::GetDashes( wxDash **ptr ) const |
112c5086 | 182 | { |
7ecb8b06 | 183 | *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL); |
112c5086 RR |
184 | return (M_PENDATA ? M_PENDATA->m_countDashes : 0); |
185 | } | |
186 | ||
7ecb8b06 VZ |
187 | int wxPen::GetDashCount() const |
188 | { | |
189 | return (M_PENDATA->m_countDashes); | |
112c5086 RR |
190 | } |
191 | ||
7ecb8b06 VZ |
192 | wxDash* wxPen::GetDash() const |
193 | { | |
194 | return (wxDash*)M_PENDATA->m_dash; | |
112c5086 RR |
195 | } |
196 | ||
82cddbd9 | 197 | wxPenCap wxPen::GetCap() const |
c801d85f | 198 | { |
223d09f6 | 199 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); |
8bbe427f | 200 | |
907789a0 | 201 | return M_PENDATA->m_capStyle; |
ff7b1510 | 202 | } |
c801d85f | 203 | |
82cddbd9 | 204 | wxPenJoin wxPen::GetJoin() const |
c801d85f | 205 | { |
223d09f6 | 206 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); |
8bbe427f | 207 | |
907789a0 | 208 | return M_PENDATA->m_joinStyle; |
ff7b1510 | 209 | } |
c801d85f | 210 | |
82cddbd9 | 211 | wxPenStyle wxPen::GetStyle() const |
c801d85f | 212 | { |
223d09f6 | 213 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); |
8bbe427f | 214 | |
907789a0 | 215 | return M_PENDATA->m_style; |
ff7b1510 | 216 | } |
c801d85f | 217 | |
907789a0 | 218 | int wxPen::GetWidth() const |
c801d85f | 219 | { |
223d09f6 | 220 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); |
8bbe427f | 221 | |
907789a0 | 222 | return M_PENDATA->m_width; |
ff7b1510 | 223 | } |
c801d85f | 224 | |
907789a0 | 225 | wxColour &wxPen::GetColour() const |
c801d85f | 226 | { |
223d09f6 | 227 | wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") ); |
8bbe427f | 228 | |
907789a0 | 229 | return M_PENDATA->m_colour; |
ff7b1510 | 230 | } |