]>
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"
28 #include "wx/msw/private.h"
30 static int wx2msPenStyle(int wx_style
);
32 IMPLEMENT_DYNAMIC_CLASS(wxPen
, wxGDIObject
)
34 wxPenRefData::wxPenRefData()
38 m_join
= wxJOIN_ROUND
;
41 m_dash
= (wxDash
*)NULL
;
45 wxPenRefData::wxPenRefData(const wxPenRefData
& data
)
48 m_style
= data
.m_style
;
49 m_width
= data
.m_width
;
52 m_nbDash
= data
.m_nbDash
;
54 m_colour
= data
.m_colour
;
58 wxPenRefData::~wxPenRefData()
61 ::DeleteObject((HPEN
) m_hPen
);
74 // Should implement Create
75 wxPen::wxPen(const wxColour
& col
, int Width
, int Style
)
77 m_refData
= new wxPenRefData
;
79 M_PENDATA
->m_colour
= col
;
80 // M_PENDATA->m_stipple = NULL;
81 M_PENDATA
->m_width
= Width
;
82 M_PENDATA
->m_style
= Style
;
83 M_PENDATA
->m_join
= wxJOIN_ROUND
;
84 M_PENDATA
->m_cap
= wxCAP_ROUND
;
85 M_PENDATA
->m_nbDash
= 0 ;
86 M_PENDATA
->m_dash
= (wxDash
*)NULL
;
87 M_PENDATA
->m_hPen
= 0 ;
92 wxPen::wxPen(const wxBitmap
& stipple
, int Width
)
94 m_refData
= new wxPenRefData
;
96 // M_PENDATA->m_colour = col;
97 M_PENDATA
->m_stipple
= stipple
;
98 M_PENDATA
->m_width
= Width
;
99 M_PENDATA
->m_style
= wxSTIPPLE
;
100 M_PENDATA
->m_join
= wxJOIN_ROUND
;
101 M_PENDATA
->m_cap
= wxCAP_ROUND
;
102 M_PENDATA
->m_nbDash
= 0 ;
103 M_PENDATA
->m_dash
= (wxDash
*)NULL
;
104 M_PENDATA
->m_hPen
= 0 ;
109 bool wxPen::RealizeResource()
111 if ( !M_PENDATA
|| M_PENDATA
->m_hPen
)
114 if (M_PENDATA
->m_style
==wxTRANSPARENT
)
116 M_PENDATA
->m_hPen
= (WXHPEN
) ::GetStockObject(NULL_PEN
);
120 static const int os
= wxGetOsVersion();
121 COLORREF ms_colour
= M_PENDATA
->m_colour
.GetPixel();
123 // Join style, Cap style, Pen Stippling
124 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
125 // Only NT can display dashed or dotted lines with width > 1
126 if ( os
!= wxOS_WINDOWS_NT
&&
127 (M_PENDATA
->m_style
== wxDOT
||
128 M_PENDATA
->m_style
== wxLONG_DASH
||
129 M_PENDATA
->m_style
== wxSHORT_DASH
||
130 M_PENDATA
->m_style
== wxDOT_DASH
||
131 M_PENDATA
->m_style
== wxUSER_DASH
) &&
132 M_PENDATA
->m_width
> 1 )
134 M_PENDATA
->m_width
= 1;
137 if (M_PENDATA
->m_join
==wxJOIN_ROUND
&&
138 M_PENDATA
->m_cap
==wxCAP_ROUND
&&
139 M_PENDATA
->m_style
!=wxUSER_DASH
&&
140 M_PENDATA
->m_style
!=wxSTIPPLE
&&
141 M_PENDATA
->m_width
<= 1)
144 (WXHPEN
) CreatePen( wx2msPenStyle(M_PENDATA
->m_style
),
150 DWORD ms_style
= PS_GEOMETRIC
| wx2msPenStyle(M_PENDATA
->m_style
);
152 switch(M_PENDATA
->m_join
)
154 case wxJOIN_BEVEL
: ms_style
|= PS_JOIN_BEVEL
; break;
155 case wxJOIN_MITER
: ms_style
|= PS_JOIN_MITER
; break;
157 case wxJOIN_ROUND
: ms_style
|= PS_JOIN_ROUND
; break;
160 switch(M_PENDATA
->m_cap
)
162 case wxCAP_PROJECTING
: ms_style
|= PS_ENDCAP_SQUARE
; break;
163 case wxCAP_BUTT
: ms_style
|= PS_ENDCAP_FLAT
; break;
165 case wxCAP_ROUND
: ms_style
|= PS_ENDCAP_ROUND
; break;
170 switch(M_PENDATA
->m_style
)
173 logb
.lbStyle
= BS_PATTERN
;
174 if (M_PENDATA
->m_stipple
.Ok())
175 logb
.lbHatch
= (LONG
)M_PENDATA
->m_stipple
.GetHBITMAP();
177 logb
.lbHatch
= (LONG
)0;
179 case wxBDIAGONAL_HATCH
:
180 logb
.lbStyle
= BS_HATCHED
;
181 logb
.lbHatch
= HS_BDIAGONAL
;
183 case wxCROSSDIAG_HATCH
:
184 logb
.lbStyle
= BS_HATCHED
;
185 logb
.lbHatch
= HS_DIAGCROSS
;
187 case wxFDIAGONAL_HATCH
:
188 logb
.lbStyle
= BS_HATCHED
;
189 logb
.lbHatch
= HS_FDIAGONAL
;
192 logb
.lbStyle
= BS_HATCHED
;
193 logb
.lbHatch
= HS_CROSS
;
195 case wxHORIZONTAL_HATCH
:
196 logb
.lbStyle
= BS_HATCHED
;
197 logb
.lbHatch
= HS_HORIZONTAL
;
199 case wxVERTICAL_HATCH
:
200 logb
.lbStyle
= BS_HATCHED
;
201 logb
.lbHatch
= HS_VERTICAL
;
204 logb
.lbStyle
= BS_SOLID
;
206 // this should be unnecessary (it's unused) but suppresses the Purify
207 // messages about uninitialized memory read
213 logb
.lbColor
= ms_colour
;
215 wxMSWDash
*real_dash
;
216 if (M_PENDATA
->m_style
==wxUSER_DASH
&& M_PENDATA
->m_nbDash
&& M_PENDATA
->m_dash
)
218 real_dash
= new wxMSWDash
[M_PENDATA
->m_nbDash
];
219 int rw
= M_PENDATA
->m_width
> 1 ? M_PENDATA
->m_width
: 1;
220 for ( int i
= 0; i
< M_PENDATA
->m_nbDash
; i
++ )
221 real_dash
[i
] = M_PENDATA
->m_dash
[i
] * rw
;
225 real_dash
= (wxMSWDash
*)NULL
;
229 (WXHPEN
) ExtCreatePen( ms_style
,
232 M_PENDATA
->m_style
== wxUSER_DASH
233 ? M_PENDATA
->m_nbDash
235 (LPDWORD
)real_dash
);
241 (WXHPEN
) CreatePen( wx2msPenStyle(M_PENDATA
->m_style
),
244 #endif // !WinCE/WinCE
249 WXHANDLE
wxPen::GetResourceHandle() const
254 return (WXHANDLE
)M_PENDATA
->m_hPen
;
257 bool wxPen::FreeResource(bool WXUNUSED(force
))
259 if (M_PENDATA
&& (M_PENDATA
->m_hPen
!= 0))
261 DeleteObject((HPEN
) M_PENDATA
->m_hPen
);
262 M_PENDATA
->m_hPen
= 0;
268 bool wxPen::IsFree() const
270 return (M_PENDATA
&& M_PENDATA
->m_hPen
== 0);
273 void wxPen::Unshare()
275 // Don't change shared data
278 m_refData
= new wxPenRefData();
282 wxPenRefData
* ref
= new wxPenRefData(*(wxPenRefData
*)m_refData
);
288 void wxPen::SetColour(const wxColour
& col
)
292 M_PENDATA
->m_colour
= col
;
297 void wxPen::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
301 M_PENDATA
->m_colour
.Set(r
, g
, b
);
306 void wxPen::SetWidth(int Width
)
310 M_PENDATA
->m_width
= Width
;
315 void wxPen::SetStyle(int Style
)
319 M_PENDATA
->m_style
= Style
;
324 void wxPen::SetStipple(const wxBitmap
& Stipple
)
328 M_PENDATA
->m_stipple
= Stipple
;
329 M_PENDATA
->m_style
= wxSTIPPLE
;
334 void wxPen::SetDashes(int nb_dashes
, const wxDash
*Dash
)
338 M_PENDATA
->m_nbDash
= nb_dashes
;
339 M_PENDATA
->m_dash
= (wxDash
*)Dash
;
344 void wxPen::SetJoin(int Join
)
348 M_PENDATA
->m_join
= Join
;
353 void wxPen::SetCap(int Cap
)
357 M_PENDATA
->m_cap
= Cap
;
362 int wx2msPenStyle(int wx_style
)
364 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
384 wxUnusedVar(wx_style
);