]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/pen.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/pen.cpp
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
27 #include "wx/msw/private.h"
29 static int wx2msPenStyle(int wx_style
);
31 IMPLEMENT_DYNAMIC_CLASS(wxPen
, wxGDIObject
)
33 wxPenRefData::wxPenRefData()
37 m_join
= wxJOIN_ROUND
;
40 m_dash
= (wxDash
*)NULL
;
44 wxPenRefData::wxPenRefData(const wxPenRefData
& data
)
47 m_style
= data
.m_style
;
48 m_width
= data
.m_width
;
51 m_nbDash
= data
.m_nbDash
;
53 m_colour
= data
.m_colour
;
57 wxPenRefData::~wxPenRefData()
60 ::DeleteObject((HPEN
) m_hPen
);
73 // Should implement Create
74 wxPen::wxPen(const wxColour
& col
, int Width
, int Style
)
76 m_refData
= new wxPenRefData
;
78 M_PENDATA
->m_colour
= col
;
79 // M_PENDATA->m_stipple = NULL;
80 M_PENDATA
->m_width
= Width
;
81 M_PENDATA
->m_style
= Style
;
82 M_PENDATA
->m_join
= wxJOIN_ROUND
;
83 M_PENDATA
->m_cap
= wxCAP_ROUND
;
84 M_PENDATA
->m_nbDash
= 0 ;
85 M_PENDATA
->m_dash
= (wxDash
*)NULL
;
86 M_PENDATA
->m_hPen
= 0 ;
91 wxPen::wxPen(const wxBitmap
& stipple
, int Width
)
93 m_refData
= new wxPenRefData
;
95 // M_PENDATA->m_colour = col;
96 M_PENDATA
->m_stipple
= stipple
;
97 M_PENDATA
->m_width
= Width
;
98 M_PENDATA
->m_style
= wxSTIPPLE
;
99 M_PENDATA
->m_join
= wxJOIN_ROUND
;
100 M_PENDATA
->m_cap
= wxCAP_ROUND
;
101 M_PENDATA
->m_nbDash
= 0 ;
102 M_PENDATA
->m_dash
= (wxDash
*)NULL
;
103 M_PENDATA
->m_hPen
= 0 ;
108 bool wxPen::RealizeResource()
110 if ( !M_PENDATA
|| M_PENDATA
->m_hPen
)
113 if (M_PENDATA
->m_style
==wxTRANSPARENT
)
115 M_PENDATA
->m_hPen
= (WXHPEN
) ::GetStockObject(NULL_PEN
);
119 static const int os
= wxGetOsVersion();
120 COLORREF ms_colour
= M_PENDATA
->m_colour
.GetPixel();
122 // Join style, Cap style, Pen Stippling
123 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
124 // Only NT can display dashed or dotted lines with width > 1
125 if ( os
!= wxWINDOWS_NT
&&
126 (M_PENDATA
->m_style
== wxDOT
||
127 M_PENDATA
->m_style
== wxLONG_DASH
||
128 M_PENDATA
->m_style
== wxSHORT_DASH
||
129 M_PENDATA
->m_style
== wxDOT_DASH
||
130 M_PENDATA
->m_style
== wxUSER_DASH
) &&
131 M_PENDATA
->m_width
> 1 )
133 M_PENDATA
->m_width
= 1;
136 if (M_PENDATA
->m_join
==wxJOIN_ROUND
&&
137 M_PENDATA
->m_cap
==wxCAP_ROUND
&&
138 M_PENDATA
->m_style
!=wxUSER_DASH
&&
139 M_PENDATA
->m_style
!=wxSTIPPLE
&&
140 M_PENDATA
->m_width
<= 1)
143 (WXHPEN
) CreatePen( wx2msPenStyle(M_PENDATA
->m_style
),
149 DWORD ms_style
= PS_GEOMETRIC
| wx2msPenStyle(M_PENDATA
->m_style
);
151 switch(M_PENDATA
->m_join
)
153 case wxJOIN_BEVEL
: ms_style
|= PS_JOIN_BEVEL
; break;
154 case wxJOIN_MITER
: ms_style
|= PS_JOIN_MITER
; break;
156 case wxJOIN_ROUND
: ms_style
|= PS_JOIN_ROUND
; break;
159 switch(M_PENDATA
->m_cap
)
161 case wxCAP_PROJECTING
: ms_style
|= PS_ENDCAP_SQUARE
; break;
162 case wxCAP_BUTT
: ms_style
|= PS_ENDCAP_FLAT
; break;
164 case wxCAP_ROUND
: ms_style
|= PS_ENDCAP_ROUND
; break;
169 switch(M_PENDATA
->m_style
)
172 logb
.lbStyle
= BS_PATTERN
;
173 if (M_PENDATA
->m_stipple
.Ok())
174 logb
.lbHatch
= (LONG
)M_PENDATA
->m_stipple
.GetHBITMAP();
176 logb
.lbHatch
= (LONG
)0;
178 case wxBDIAGONAL_HATCH
:
179 logb
.lbStyle
= BS_HATCHED
;
180 logb
.lbHatch
= HS_BDIAGONAL
;
182 case wxCROSSDIAG_HATCH
:
183 logb
.lbStyle
= BS_HATCHED
;
184 logb
.lbHatch
= HS_DIAGCROSS
;
186 case wxFDIAGONAL_HATCH
:
187 logb
.lbStyle
= BS_HATCHED
;
188 logb
.lbHatch
= HS_FDIAGONAL
;
191 logb
.lbStyle
= BS_HATCHED
;
192 logb
.lbHatch
= HS_CROSS
;
194 case wxHORIZONTAL_HATCH
:
195 logb
.lbStyle
= BS_HATCHED
;
196 logb
.lbHatch
= HS_HORIZONTAL
;
198 case wxVERTICAL_HATCH
:
199 logb
.lbStyle
= BS_HATCHED
;
200 logb
.lbHatch
= HS_VERTICAL
;
203 logb
.lbStyle
= BS_SOLID
;
205 // this should be unnecessary (it's unused) but suppresses the Purify
206 // messages about uninitialized memory read
212 logb
.lbColor
= ms_colour
;
214 wxMSWDash
*real_dash
;
215 if (M_PENDATA
->m_style
==wxUSER_DASH
&& M_PENDATA
->m_nbDash
&& M_PENDATA
->m_dash
)
217 real_dash
= new wxMSWDash
[M_PENDATA
->m_nbDash
];
218 int rw
= M_PENDATA
->m_width
> 1 ? M_PENDATA
->m_width
: 1;
219 for ( int i
= 0; i
< M_PENDATA
->m_nbDash
; i
++ )
220 real_dash
[i
] = M_PENDATA
->m_dash
[i
] * rw
;
224 real_dash
= (wxMSWDash
*)NULL
;
227 // Win32s doesn't have ExtCreatePen function...
228 if (os
==wxWINDOWS_NT
|| os
==wxWIN95
)
231 (WXHPEN
) ExtCreatePen( ms_style
,
234 M_PENDATA
->m_style
== wxUSER_DASH
235 ? M_PENDATA
->m_nbDash
237 (LPDWORD
)real_dash
);
242 (WXHPEN
) CreatePen( wx2msPenStyle(M_PENDATA
->m_style
),
251 (WXHPEN
) CreatePen( wx2msPenStyle(M_PENDATA
->m_style
),
254 #endif // !WinCE/WinCE
259 WXHANDLE
wxPen::GetResourceHandle() const
264 return (WXHANDLE
)M_PENDATA
->m_hPen
;
267 bool wxPen::FreeResource(bool WXUNUSED(force
))
269 if (M_PENDATA
&& (M_PENDATA
->m_hPen
!= 0))
271 DeleteObject((HPEN
) M_PENDATA
->m_hPen
);
272 M_PENDATA
->m_hPen
= 0;
278 bool wxPen::IsFree() const
280 return (M_PENDATA
&& M_PENDATA
->m_hPen
== 0);
283 void wxPen::Unshare()
285 // Don't change shared data
288 m_refData
= new wxPenRefData();
292 wxPenRefData
* ref
= new wxPenRefData(*(wxPenRefData
*)m_refData
);
298 void wxPen::SetColour(const wxColour
& col
)
302 M_PENDATA
->m_colour
= col
;
307 void wxPen::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
311 M_PENDATA
->m_colour
.Set(r
, g
, b
);
316 void wxPen::SetWidth(int Width
)
320 M_PENDATA
->m_width
= Width
;
325 void wxPen::SetStyle(int Style
)
329 M_PENDATA
->m_style
= Style
;
334 void wxPen::SetStipple(const wxBitmap
& Stipple
)
338 M_PENDATA
->m_stipple
= Stipple
;
339 M_PENDATA
->m_style
= wxSTIPPLE
;
344 void wxPen::SetDashes(int nb_dashes
, const wxDash
*Dash
)
348 M_PENDATA
->m_nbDash
= nb_dashes
;
349 M_PENDATA
->m_dash
= (wxDash
*)Dash
;
354 void wxPen::SetJoin(int Join
)
358 M_PENDATA
->m_join
= Join
;
363 void wxPen::SetCap(int Cap
)
367 M_PENDATA
->m_cap
= Cap
;
372 int wx2msPenStyle(int wx_style
)
374 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
391 // if (wxGetOsVersion()==wxWINDOWS_NT || wxGetOsVersion()==wxWIN95)
395 wxUnusedVar(wx_style
);