]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/pen.cpp
ddded9fc633a7032460666cc55081b8f41d4737a
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
!= wxWINDOWS_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
;
228 // Win32s doesn't have ExtCreatePen function...
229 if (os
==wxWINDOWS_NT
|| os
==wxWIN95
)
232 (WXHPEN
) ExtCreatePen( ms_style
,
235 M_PENDATA
->m_style
== wxUSER_DASH
236 ? M_PENDATA
->m_nbDash
238 (LPDWORD
)real_dash
);
243 (WXHPEN
) CreatePen( wx2msPenStyle(M_PENDATA
->m_style
),
252 (WXHPEN
) CreatePen( wx2msPenStyle(M_PENDATA
->m_style
),
255 #endif // !WinCE/WinCE
260 WXHANDLE
wxPen::GetResourceHandle() const
265 return (WXHANDLE
)M_PENDATA
->m_hPen
;
268 bool wxPen::FreeResource(bool WXUNUSED(force
))
270 if (M_PENDATA
&& (M_PENDATA
->m_hPen
!= 0))
272 DeleteObject((HPEN
) M_PENDATA
->m_hPen
);
273 M_PENDATA
->m_hPen
= 0;
279 bool wxPen::IsFree() const
281 return (M_PENDATA
&& M_PENDATA
->m_hPen
== 0);
284 void wxPen::Unshare()
286 // Don't change shared data
289 m_refData
= new wxPenRefData();
293 wxPenRefData
* ref
= new wxPenRefData(*(wxPenRefData
*)m_refData
);
299 void wxPen::SetColour(const wxColour
& col
)
303 M_PENDATA
->m_colour
= col
;
308 void wxPen::SetColour(const unsigned char r
, const unsigned char g
, const unsigned char b
)
312 M_PENDATA
->m_colour
.Set(r
, g
, b
);
317 void wxPen::SetWidth(int Width
)
321 M_PENDATA
->m_width
= Width
;
326 void wxPen::SetStyle(int Style
)
330 M_PENDATA
->m_style
= Style
;
335 void wxPen::SetStipple(const wxBitmap
& Stipple
)
339 M_PENDATA
->m_stipple
= Stipple
;
340 M_PENDATA
->m_style
= wxSTIPPLE
;
345 void wxPen::SetDashes(int nb_dashes
, const wxDash
*Dash
)
349 M_PENDATA
->m_nbDash
= nb_dashes
;
350 M_PENDATA
->m_dash
= (wxDash
*)Dash
;
355 void wxPen::SetJoin(int Join
)
359 M_PENDATA
->m_join
= Join
;
364 void wxPen::SetCap(int Cap
)
368 M_PENDATA
->m_cap
= Cap
;
373 int wx2msPenStyle(int wx_style
)
375 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
392 // if (wxGetOsVersion()==wxWINDOWS_NT || wxGetOsVersion()==wxWIN95)
396 wxUnusedVar(wx_style
);