]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: pen.cpp | |
3 | // Purpose: wxPen | |
cdf1e714 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
cdf1e714 | 6 | // Created: 10/10/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
cdf1e714 DW |
8 | // Copyright: (c) David Webster |
9 | // Licence: wxWindows licence | |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
cdf1e714 DW |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
0e320a79 | 14 | |
cdf1e714 DW |
15 | #ifndef WX_PRECOMP |
16 | #include <stdio.h> | |
0e320a79 | 17 | #include "wx/setup.h" |
cdf1e714 | 18 | #include "wx/list.h" |
0e320a79 | 19 | #include "wx/utils.h" |
cdf1e714 | 20 | #include "wx/app.h" |
0e320a79 | 21 | #include "wx/pen.h" |
0e320a79 DW |
22 | #endif |
23 | ||
cdf1e714 DW |
24 | #include "wx/os2/private.h" |
25 | #include "assert.h" | |
26 | ||
0e320a79 DW |
27 | wxPenRefData::wxPenRefData() |
28 | { | |
29 | m_style = wxSOLID; | |
30 | m_width = 1; | |
31 | m_join = wxJOIN_ROUND ; | |
32 | m_cap = wxCAP_ROUND ; | |
33 | m_nbDash = 0 ; | |
34 | m_dash = 0 ; | |
0e320a79 | 35 | m_hPen = 0; |
0e320a79 DW |
36 | } |
37 | ||
38 | wxPenRefData::wxPenRefData(const wxPenRefData& data) | |
39 | { | |
40 | m_style = data.m_style; | |
41 | m_width = data.m_width; | |
42 | m_join = data.m_join; | |
43 | m_cap = data.m_cap; | |
44 | m_nbDash = data.m_nbDash; | |
45 | m_dash = data.m_dash; | |
46 | m_colour = data.m_colour; | |
47 | /* TODO: null data | |
48 | m_hPen = 0; | |
49 | */ | |
50 | } | |
51 | ||
52 | wxPenRefData::~wxPenRefData() | |
53 | { | |
54 | // TODO: delete data | |
55 | } | |
56 | ||
57 | // Pens | |
58 | ||
59 | wxPen::wxPen() | |
60 | { | |
61 | if ( wxThePenList ) | |
62 | wxThePenList->AddPen(this); | |
63 | } | |
64 | ||
65 | wxPen::~wxPen() | |
66 | { | |
67 | if (wxThePenList) | |
68 | wxThePenList->RemovePen(this); | |
69 | } | |
70 | ||
71 | // Should implement Create | |
72 | wxPen::wxPen(const wxColour& col, int Width, int Style) | |
73 | { | |
74 | m_refData = new wxPenRefData; | |
75 | ||
76 | M_PENDATA->m_colour = col; | |
cdf1e714 | 77 | // M_PENDATA->m_stipple = NULL; |
0e320a79 DW |
78 | M_PENDATA->m_width = Width; |
79 | M_PENDATA->m_style = Style; | |
80 | M_PENDATA->m_join = wxJOIN_ROUND ; | |
81 | M_PENDATA->m_cap = wxCAP_ROUND ; | |
82 | M_PENDATA->m_nbDash = 0 ; | |
83 | M_PENDATA->m_dash = 0 ; | |
cdf1e714 DW |
84 | M_PENDATA->m_hPen = 0 ; |
85 | ||
86 | // TODO: | |
87 | /* | |
88 | if ((Style == wxDOT) || (Style == wxLONG_DASH) || | |
89 | (Style == wxSHORT_DASH) || (Style == wxDOT_DASH) || | |
90 | (Style == wxUSER_DASH)) | |
91 | M_PENDATA->m_width = 1; | |
92 | */ | |
0e320a79 DW |
93 | RealizeResource(); |
94 | ||
95 | if ( wxThePenList ) | |
96 | wxThePenList->AddPen(this); | |
97 | } | |
98 | ||
99 | wxPen::wxPen(const wxBitmap& stipple, int Width) | |
100 | { | |
101 | m_refData = new wxPenRefData; | |
102 | ||
103 | M_PENDATA->m_stipple = stipple; | |
104 | M_PENDATA->m_width = Width; | |
105 | M_PENDATA->m_style = wxSTIPPLE; | |
106 | M_PENDATA->m_join = wxJOIN_ROUND ; | |
107 | M_PENDATA->m_cap = wxCAP_ROUND ; | |
108 | M_PENDATA->m_nbDash = 0 ; | |
109 | M_PENDATA->m_dash = 0 ; | |
cdf1e714 | 110 | M_PENDATA->m_hPen = 0 ; |
0e320a79 DW |
111 | |
112 | RealizeResource(); | |
113 | ||
114 | if ( wxThePenList ) | |
115 | wxThePenList->AddPen(this); | |
116 | } | |
117 | ||
cdf1e714 DW |
118 | bool wxPen::RealizeResource() |
119 | { | |
120 | // TODO: create actual pen | |
121 | return FALSE; | |
122 | } | |
123 | ||
124 | WXHANDLE wxPen::GetResourceHandle() | |
125 | { | |
126 | if ( !M_PENDATA ) | |
127 | return 0; | |
128 | else | |
129 | return (WXHANDLE)M_PENDATA->m_hPen; | |
130 | } | |
131 | ||
132 | bool wxPen::FreeResource(bool force) | |
133 | { | |
134 | if (M_PENDATA && (M_PENDATA->m_hPen != 0)) | |
135 | { | |
136 | DeleteObject((HPEN) M_PENDATA->m_hPen); | |
137 | M_PENDATA->m_hPen = 0; | |
138 | return TRUE; | |
139 | } | |
140 | else return FALSE; | |
141 | } | |
142 | ||
0e320a79 DW |
143 | void wxPen::Unshare() |
144 | { | |
cdf1e714 DW |
145 | // Don't change shared data |
146 | if (!m_refData) | |
0e320a79 | 147 | { |
cdf1e714 DW |
148 | m_refData = new wxPenRefData(); |
149 | } | |
0e320a79 DW |
150 | else |
151 | { | |
cdf1e714 DW |
152 | wxPenRefData* ref = new wxPenRefData(*(wxPenRefData*)m_refData); |
153 | UnRef(); | |
154 | m_refData = ref; | |
155 | } | |
0e320a79 DW |
156 | } |
157 | ||
158 | void wxPen::SetColour(const wxColour& col) | |
159 | { | |
160 | Unshare(); | |
161 | ||
162 | M_PENDATA->m_colour = col; | |
163 | ||
164 | RealizeResource(); | |
165 | } | |
166 | ||
167 | void wxPen::SetColour(unsigned char r, unsigned char g, unsigned char b) | |
168 | { | |
169 | Unshare(); | |
170 | ||
171 | M_PENDATA->m_colour.Set(r, g, b); | |
172 | ||
173 | RealizeResource(); | |
174 | } | |
175 | ||
176 | void wxPen::SetWidth(int Width) | |
177 | { | |
178 | Unshare(); | |
179 | ||
180 | M_PENDATA->m_width = Width; | |
181 | ||
182 | RealizeResource(); | |
183 | } | |
184 | ||
185 | void wxPen::SetStyle(int Style) | |
186 | { | |
187 | Unshare(); | |
188 | ||
189 | M_PENDATA->m_style = Style; | |
190 | ||
191 | RealizeResource(); | |
192 | } | |
193 | ||
194 | void wxPen::SetStipple(const wxBitmap& Stipple) | |
195 | { | |
196 | Unshare(); | |
197 | ||
198 | M_PENDATA->m_stipple = Stipple; | |
199 | M_PENDATA->m_style = wxSTIPPLE; | |
200 | ||
201 | RealizeResource(); | |
202 | } | |
203 | ||
204 | void wxPen::SetDashes(int nb_dashes, const wxDash *Dash) | |
205 | { | |
206 | Unshare(); | |
207 | ||
208 | M_PENDATA->m_nbDash = nb_dashes; | |
209 | M_PENDATA->m_dash = (wxDash *)Dash; | |
210 | ||
211 | RealizeResource(); | |
212 | } | |
213 | ||
214 | void wxPen::SetJoin(int Join) | |
215 | { | |
216 | Unshare(); | |
217 | ||
218 | M_PENDATA->m_join = Join; | |
219 | ||
220 | RealizeResource(); | |
221 | } | |
222 | ||
223 | void wxPen::SetCap(int Cap) | |
224 | { | |
225 | Unshare(); | |
226 | ||
227 | M_PENDATA->m_cap = Cap; | |
228 | ||
229 | RealizeResource(); | |
230 | } | |
231 | ||
cdf1e714 | 232 | void wxPen::SetCap(int Cap) |
0e320a79 | 233 | { |
cdf1e714 DW |
234 | Unshare(); |
235 | ||
236 | M_PENDATA->m_cap = Cap; | |
237 | ||
238 | RealizeResource(); | |
239 | } | |
240 | ||
241 | int wx2os2PenStyle(int wx_style) | |
242 | { | |
243 | int cstyle; | |
244 | // TODO: | |
245 | /* | |
246 | switch (wx_style) | |
247 | { | |
248 | case wxDOT: | |
249 | cstyle = PS_DOT; | |
250 | break; | |
251 | ||
252 | case wxDOT_DASH: | |
253 | cstyle = PS_DASHDOT; | |
254 | break; | |
255 | ||
256 | case wxSHORT_DASH: | |
257 | case wxLONG_DASH: | |
258 | cstyle = PS_DASH; | |
259 | break; | |
260 | ||
261 | case wxTRANSPARENT: | |
262 | cstyle = PS_NULL; | |
263 | break; | |
264 | ||
265 | case wxUSER_DASH: | |
266 | #ifdef __WIN32__ | |
267 | // Win32s doesn't have PS_USERSTYLE | |
268 | if (wxGetOsVersion()==wxWINDOWS_NT || wxGetOsVersion()==wxWIN95) | |
269 | cstyle = PS_USERSTYLE; | |
270 | else | |
271 | cstyle = PS_DOT; // We must make a choice... This is mine! | |
272 | #else | |
273 | cstyle = PS_DASH; | |
274 | #endif | |
275 | break; | |
276 | case wxSOLID: | |
277 | default: | |
278 | cstyle = PS_SOLID; | |
279 | break; | |
280 | } | |
281 | */ | |
282 | return cstyle; | |
0e320a79 DW |
283 | } |
284 | ||
285 |