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