]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/dfb/pen.cpp | |
3 | // Purpose: wxPen class implementation | |
4 | // Author: Vaclav Slavik | |
5 | // Created: 2006-08-04 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) 2006 REA Elektronik GmbH | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | // For compilers that support precompilation, includes "wx.h". | |
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #ifdef __BORLANDC__ | |
15 | #pragma hdrstop | |
16 | #endif | |
17 | ||
18 | #include "wx/pen.h" | |
19 | ||
20 | #ifndef WX_PRECOMP | |
21 | #include "wx/bitmap.h" | |
22 | #include "wx/colour.h" | |
23 | #endif | |
24 | ||
25 | //----------------------------------------------------------------------------- | |
26 | // wxPen | |
27 | //----------------------------------------------------------------------------- | |
28 | ||
29 | class wxPenRefData: public wxObjectRefData | |
30 | { | |
31 | public: | |
32 | wxPenRefData(const wxColour& clr = wxNullColour, int style = wxSOLID) | |
33 | { | |
34 | m_colour = clr; | |
35 | SetStyle(style); | |
36 | } | |
37 | ||
38 | wxPenRefData(const wxPenRefData& data) | |
39 | : m_style(data.m_style), m_colour(data.m_colour) {} | |
40 | ||
41 | void SetStyle(int style) | |
42 | { | |
43 | if ( style != wxSOLID && style != wxTRANSPARENT ) | |
44 | { | |
45 | wxFAIL_MSG( "only wxSOLID and wxTRANSPARENT styles are supported" ); | |
46 | style = wxSOLID; | |
47 | } | |
48 | ||
49 | m_style = style; | |
50 | } | |
51 | ||
52 | int m_style; | |
53 | wxColour m_colour; | |
54 | }; | |
55 | ||
56 | //----------------------------------------------------------------------------- | |
57 | ||
58 | #define M_PENDATA ((wxPenRefData *)m_refData) | |
59 | ||
60 | IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject) | |
61 | ||
62 | wxPen::wxPen(const wxColour &colour, int width, int style) | |
63 | { | |
64 | wxASSERT_MSG( width <= 1, "only width=0,1 are supported" ); | |
65 | ||
66 | m_refData = new wxPenRefData(colour, style); | |
67 | } | |
68 | ||
69 | wxPen::wxPen(const wxBitmap& WXUNUSED(stipple), int WXUNUSED(width)) | |
70 | { | |
71 | wxFAIL_MSG( "stipple pens not supported" ); | |
72 | ||
73 | m_refData = new wxPenRefData(); | |
74 | } | |
75 | ||
76 | bool wxPen::operator==(const wxPen& pen) const | |
77 | { | |
78 | #warning "this is incorrect (MGL too)" | |
79 | return m_refData == pen.m_refData; | |
80 | } | |
81 | ||
82 | void wxPen::SetColour(const wxColour &colour) | |
83 | { | |
84 | AllocExclusive(); | |
85 | M_PENDATA->m_colour = colour; | |
86 | } | |
87 | ||
88 | void wxPen::SetDashes(int WXUNUSED(number_of_dashes), const wxDash *WXUNUSED(dash)) | |
89 | { | |
90 | wxFAIL_MSG( "SetDashes not implemented" ); | |
91 | } | |
92 | ||
93 | void wxPen::SetColour(unsigned char red, unsigned char green, unsigned char blue) | |
94 | { | |
95 | AllocExclusive(); | |
96 | M_PENDATA->m_colour.Set(red, green, blue); | |
97 | } | |
98 | ||
99 | void wxPen::SetCap(int WXUNUSED(capStyle)) | |
100 | { | |
101 | wxFAIL_MSG( "SetCap not implemented" ); | |
102 | } | |
103 | ||
104 | void wxPen::SetJoin(int WXUNUSED(joinStyle)) | |
105 | { | |
106 | wxFAIL_MSG( "SetJoin not implemented" ); | |
107 | } | |
108 | ||
109 | void wxPen::SetStyle(int style) | |
110 | { | |
111 | AllocExclusive(); | |
112 | M_PENDATA->SetStyle(style); | |
113 | } | |
114 | ||
115 | void wxPen::SetStipple(const wxBitmap& WXUNUSED(stipple)) | |
116 | { | |
117 | wxFAIL_MSG( "SetStipple not implemented" ); | |
118 | } | |
119 | ||
120 | void wxPen::SetWidth(int width) | |
121 | { | |
122 | wxASSERT_MSG( width <= 1, "only width=0,1 are implemented" ); | |
123 | } | |
124 | ||
125 | int wxPen::GetDashes(wxDash **ptr) const | |
126 | { | |
127 | wxFAIL_MSG( "GetDashes not implemented" ); | |
128 | ||
129 | *ptr = NULL; | |
130 | return 0; | |
131 | } | |
132 | ||
133 | int wxPen::GetDashCount() const | |
134 | { | |
135 | wxFAIL_MSG( "GetDashCount not implemented" ); | |
136 | ||
137 | return 0; | |
138 | } | |
139 | ||
140 | wxDash* wxPen::GetDash() const | |
141 | { | |
142 | wxFAIL_MSG( "GetDash not implemented" ); | |
143 | ||
144 | return NULL; | |
145 | } | |
146 | ||
147 | int wxPen::GetCap() const | |
148 | { | |
149 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); | |
150 | ||
151 | wxFAIL_MSG( "GetCap not implemented" ); | |
152 | return -1; | |
153 | } | |
154 | ||
155 | int wxPen::GetJoin() const | |
156 | { | |
157 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); | |
158 | ||
159 | wxFAIL_MSG( "GetJoin not implemented" ); | |
160 | return -1; | |
161 | } | |
162 | ||
163 | int wxPen::GetStyle() const | |
164 | { | |
165 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); | |
166 | ||
167 | return M_PENDATA->m_style; | |
168 | } | |
169 | ||
170 | int wxPen::GetWidth() const | |
171 | { | |
172 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); | |
173 | ||
174 | return 1; | |
175 | } | |
176 | ||
177 | wxColour &wxPen::GetColour() const | |
178 | { | |
179 | wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") ); | |
180 | ||
181 | return M_PENDATA->m_colour; | |
182 | } | |
183 | ||
184 | wxBitmap *wxPen::GetStipple() const | |
185 | { | |
186 | wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") ); | |
187 | ||
188 | wxFAIL_MSG( "GetStipple not implemented" ); | |
189 | return NULL; | |
190 | } | |
191 | ||
192 | bool wxPen::IsOk() const | |
193 | { | |
194 | return ((m_refData) && M_PENDATA->m_colour.Ok()); | |
195 | } | |
196 | ||
197 | wxObjectRefData *wxPen::CreateRefData() const | |
198 | { | |
199 | return new wxPenRefData; | |
200 | } | |
201 | ||
202 | wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const | |
203 | { | |
204 | return new wxPenRefData(*(wxPenRefData *)data); | |
205 | } |