]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/pen.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "pen.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
32 #include "wx/msw/private.h"
34 static int wx2msPenStyle(int wx_style
);
36 IMPLEMENT_DYNAMIC_CLASS(wxPen
, wxGDIObject
)
38 wxPenRefData::wxPenRefData()
42 m_join
= wxJOIN_ROUND
;
45 m_dash
= (wxDash
*)NULL
;
49 wxPenRefData::wxPenRefData(const wxPenRefData
& data
)
52 m_style
= data
.m_style
;
53 m_width
= data
.m_width
;
56 m_nbDash
= data
.m_nbDash
;
58 m_colour
= data
.m_colour
;
62 wxPenRefData::~wxPenRefData()
65 ::DeleteObject((HPEN
) m_hPen
);
78 // Should implement Create
79 wxPen::wxPen(const wxColour
& col
, int Width
, int Style
)
81 m_refData
= new wxPenRefData
;
83 M_PENDATA
->m_colour
= col
;
84 // M_PENDATA->m_stipple = NULL;
85 M_PENDATA
->m_width
= Width
;
86 M_PENDATA
->m_style
= Style
;
87 M_PENDATA
->m_join
= wxJOIN_ROUND
;
88 M_PENDATA
->m_cap
= wxCAP_ROUND
;
89 M_PENDATA
->m_nbDash
= 0 ;
90 M_PENDATA
->m_dash
= (wxDash
*)NULL
;
91 M_PENDATA
->m_hPen
= 0 ;
96 wxPen::wxPen(const wxBitmap
& stipple
, int Width
)
98 m_refData
= new wxPenRefData
;
100 // M_PENDATA->m_colour = col;
101 M_PENDATA
->m_stipple
= stipple
;
102 M_PENDATA
->m_width
= Width
;
103 M_PENDATA
->m_style
= wxSTIPPLE
;
104 M_PENDATA
->m_join
= wxJOIN_ROUND
;
105 M_PENDATA
->m_cap
= wxCAP_ROUND
;
106 M_PENDATA
->m_nbDash
= 0 ;
107 M_PENDATA
->m_dash
= (wxDash
*)NULL
;
108 M_PENDATA
->m_hPen
= 0 ;
113 bool wxPen::RealizeResource()
115 if ( !M_PENDATA
|| M_PENDATA
->m_hPen
)
118 if (M_PENDATA
->m_style
==wxTRANSPARENT
)
120 M_PENDATA
->m_hPen
= (WXHPEN
) ::GetStockObject(NULL_PEN
);
124 static const int os
= wxGetOsVersion();
125 COLORREF ms_colour
= M_PENDATA
->m_colour
.GetPixel();
127 // Join style, Cap style, Pen Stippling
128 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
129 // Only NT can display dashed or dotted lines with width > 1
130 if ( os
!= wxWINDOWS_NT
&&
131 (M_PENDATA
->m_style
== wxDOT
||
132 M_PENDATA
->m_style
== wxLONG_DASH
||
133 M_PENDATA
->m_style
== wxSHORT_DASH
||
134 M_PENDATA
->m_style
== wxDOT_DASH
||
135 M_PENDATA
->m_style
== wxUSER_DASH
) &&
136 M_PENDATA
->m_width
> 1 )
138 M_PENDATA
->m_width
= 1;
141 if (M_PENDATA
->m_join
==wxJOIN_ROUND
&&
142 M_PENDATA
->m_cap
==wxCAP_ROUND
&&
143 M_PENDATA
->m_style
!=wxUSER_DASH
&&
144 M_PENDATA
->m_style
!=wxSTIPPLE
&&
145 M_PENDATA
->m_width
<= 1)
148 (WXHPEN
) CreatePen( wx2msPenStyle(M_PENDATA
->m_style
),
154 DWORD ms_style
= PS_GEOMETRIC
| wx2msPenStyle(M_PENDATA
->m_style
);
156 switch(M_PENDATA
->m_join
)
158 case wxJOIN_BEVEL
: ms_style
|= PS_JOIN_BEVEL
; break;
159 case wxJOIN_MITER
: ms_style
|= PS_JOIN_MITER
; break;
161 case wxJOIN_ROUND
: ms_style
|= PS_JOIN_ROUND
; break;
164 switch(M_PENDATA
->m_cap
)
166 case wxCAP_PROJECTING
: ms_style
|= PS_ENDCAP_SQUARE
; break;
167 case wxCAP_BUTT
: ms_style
|= PS_ENDCAP_FLAT
; break;
169 case wxCAP_ROUND
: ms_style
|= PS_ENDCAP_ROUND
; break;
174 switch(M_PENDATA
->m_style
)
177 logb
.lbStyle
= BS_PATTERN
;
178 if (M_PENDATA
->m_stipple
.Ok())
179 logb
.lbHatch
= (LONG
)M_PENDATA
->m_stipple
.GetHBITMAP();
181 logb
.lbHatch
= (LONG
)0;
183 case wxBDIAGONAL_HATCH
:
184 logb
.lbStyle
= BS_HATCHED
;
185 logb
.lbHatch
= HS_BDIAGONAL
;
187 case wxCROSSDIAG_HATCH
:
188 logb
.lbStyle
= BS_HATCHED
;
189 logb
.lbHatch
= HS_DIAGCROSS
;
191 case wxFDIAGONAL_HATCH
:
192 logb
.lbStyle
= BS_HATCHED
;
193 logb
.lbHatch
= HS_FDIAGONAL
;
196 logb
.lbStyle
= BS_HATCHED
;
197 logb
.lbHatch
= HS_CROSS
;
199 case wxHORIZONTAL_HATCH
:
200 logb
.lbStyle
= BS_HATCHED
;
201 logb
.lbHatch
= HS_HORIZONTAL
;
203 case wxVERTICAL_HATCH
:
204 logb
.lbStyle
= BS_HATCHED
;
205 logb
.lbHatch
= HS_VERTICAL
;
208 logb
.lbStyle
= BS_SOLID
;
210 // this should be unnecessary (it's unused) but suppresses the Purify
211 // messages about uninitialized memory read
217 logb
.lbColor
= ms_colour
;
219 wxMSWDash
*real_dash
;
220 if (M_PENDATA
->m_style
==wxUSER_DASH
&& M_PENDATA
->m_nbDash
&& M_PENDATA
->m_dash
)
222 real_dash
= new wxMSWDash
[M_PENDATA
->m_nbDash
];
223 int rw
= M_PENDATA
->m_width
> 1 ? M_PENDATA
->m_width
: 1;
224 for ( int i
= 0; i
< M_PENDATA
->m_nbDash
; i
++ )
225 real_dash
[i
] = M_PENDATA
->m_dash
[i
] * rw
;
229 real_dash
= (wxMSWDash
*)NULL
;
232 // Win32s doesn't have ExtCreatePen function...
233 if (os
==wxWINDOWS_NT
|| os
==wxWIN95
)
236 (WXHPEN
) ExtCreatePen( ms_style
,
239 M_PENDATA
->m_style
== wxUSER_DASH
240 ? M_PENDATA
->m_nbDash
242 (LPDWORD
)real_dash
);
247 (WXHPEN
) CreatePen( wx2msPenStyle(M_PENDATA
->m_style
),
256 (WXHPEN
) CreatePen( wx2msPenStyle(M_PENDATA
->m_style
),
259 #endif // !WinCE/WinCE
264 WXHANDLE
wxPen::GetResourceHandle() const
269 return (WXHANDLE
)M_PENDATA
->m_hPen
;
272 bool wxPen::FreeResource(bool WXUNUSED(force
))
274 if (M_PENDATA
&& (M_PENDATA
->m_hPen
!= 0))
276 DeleteObject((HPEN
) M_PENDATA
->m_hPen
);
277 M_PENDATA
->m_hPen
= 0;
283 bool wxPen::IsFree() const
285 return (M_PENDATA
&& M_PENDATA
->m_hPen
== 0);
288 void wxPen::Unshare()
290 // Don't change shared data
293 m_refData
= new wxPenRefData();
297 wxPenRefData
* ref
= new wxPenRefData(*(wxPenRefData
*)m_refData
);
303 void wxPen::SetColour(const wxColour
& col
)
307 M_PENDATA
->m_colour
= col
;
312 void wxPen::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
316 M_PENDATA
->m_colour
.Set(r
, g
, b
);
321 void wxPen::SetWidth(int Width
)
325 M_PENDATA
->m_width
= Width
;
330 void wxPen::SetStyle(int Style
)
334 M_PENDATA
->m_style
= Style
;
339 void wxPen::SetStipple(const wxBitmap
& Stipple
)
343 M_PENDATA
->m_stipple
= Stipple
;
344 M_PENDATA
->m_style
= wxSTIPPLE
;
349 void wxPen::SetDashes(int nb_dashes
, const wxDash
*Dash
)
353 M_PENDATA
->m_nbDash
= nb_dashes
;
354 M_PENDATA
->m_dash
= (wxDash
*)Dash
;
359 void wxPen::SetJoin(int Join
)
363 M_PENDATA
->m_join
= Join
;
368 void wxPen::SetCap(int Cap
)
372 M_PENDATA
->m_cap
= Cap
;
377 int wx2msPenStyle(int wx_style
)
379 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
396 // if (wxGetOsVersion()==wxWINDOWS_NT || wxGetOsVersion()==wxWIN95)
400 wxUnusedVar(wx_style
);