]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/pen.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
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"
35 #if !USE_SHARED_LIBRARIES
36 IMPLEMENT_DYNAMIC_CLASS(wxPen
, wxGDIObject
)
39 wxPenRefData::wxPenRefData(void)
44 m_join
= wxJOIN_ROUND
;
51 wxPenRefData::~wxPenRefData(void)
54 ::DeleteObject((HPEN
) m_hPen
);
62 wxThePenList
->AddPen(this);
68 wxThePenList
->RemovePen(this);
71 // Should implement Create
72 wxPen::wxPen(const wxColour
& col
, const int Width
, const int Style
)
74 m_refData
= new wxPenRefData
;
76 M_PENDATA
->m_colour
= col
;
77 // M_PENDATA->m_stipple = NULL;
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 ;
84 M_PENDATA
->m_hPen
= 0 ;
87 // In Windows, only a pen of width = 1 can be dotted or dashed!
88 if ((Style
== wxDOT
) || (Style
== wxLONG_DASH
) ||
89 (Style
== wxSHORT_DASH
) || (Style
== wxDOT_DASH
) ||
90 (Style
== wxUSER_DASH
))
91 M_PENDATA
->m_width
= 1;
94 DWORD vers = GetVersion() ;
95 WORD high = HIWORD(vers) ; // high bit=0 for NT, 1 for Win32s
96 // Win32s doesn't support wide dashed pens
100 if (wxGetOsVersion()==wxWIN32S
)
102 // In Windows, only a pen of width = 1 can be dotted or dashed!
103 if ((Style
== wxDOT
) || (Style
== wxLONG_DASH
) ||
104 (Style
== wxSHORT_DASH
) || (Style
== wxDOT_DASH
) ||
105 (Style
== wxUSER_DASH
))
106 M_PENDATA
->m_width
= 1;
112 wxThePenList
->AddPen(this);
115 wxPen::wxPen(const wxBitmap
& stipple
, const int Width
)
117 m_refData
= new wxPenRefData
;
119 // M_PENDATA->m_colour = col;
120 M_PENDATA
->m_stipple
= stipple
;
121 M_PENDATA
->m_width
= Width
;
122 M_PENDATA
->m_style
= wxSTIPPLE
;
123 M_PENDATA
->m_join
= wxJOIN_ROUND
;
124 M_PENDATA
->m_cap
= wxCAP_ROUND
;
125 M_PENDATA
->m_nbDash
= 0 ;
126 M_PENDATA
->m_dash
= 0 ;
127 M_PENDATA
->m_hPen
= 0 ;
132 wxThePenList
->AddPen(this);
135 wxPen::wxPen(const wxString
& col
, const int Width
, const int Style
)
137 m_refData
= new wxPenRefData
;
139 M_PENDATA
->m_colour
= col
;
140 // M_PENDATA->m_stipple = NULL ;
141 M_PENDATA
->m_width
= Width
;
142 M_PENDATA
->m_style
= Style
;
143 M_PENDATA
->m_join
= wxJOIN_ROUND
;
144 M_PENDATA
->m_cap
= wxCAP_ROUND
;
145 M_PENDATA
->m_nbDash
= 0 ;
146 M_PENDATA
->m_dash
= 0 ;
147 M_PENDATA
->m_hPen
= 0 ;
152 wxThePenList
->AddPen(this);
155 bool wxPen::RealizeResource(void)
157 if (M_PENDATA
&& (M_PENDATA
->m_hPen
== 0))
159 if (M_PENDATA
->m_style
==wxTRANSPARENT
)
161 M_PENDATA
->m_hPen
= (WXHPEN
) ::GetStockObject(NULL_PEN
);
165 COLORREF ms_colour
= 0 ;
166 ms_colour
= M_PENDATA
->m_colour
.GetPixel() ;
168 // Join style, Cap style, Pen Stippling only on Win32.
169 // Currently no time to find equivalent on Win3.1, sorry
170 // [if such equiv exist!!]
172 if (M_PENDATA
->m_join
==wxJOIN_ROUND
&&
173 M_PENDATA
->m_cap
==wxCAP_ROUND
&&
174 M_PENDATA
->m_style
!=wxUSER_DASH
&&
175 M_PENDATA
->m_style
!=wxSTIPPLE
&&
176 M_PENDATA
->m_width
<= 1
178 M_PENDATA
->m_hPen
= (WXHPEN
) CreatePen(wx2msPenStyle(M_PENDATA
->m_style
), M_PENDATA
->m_width
, ms_colour
);
181 DWORD ms_style
= PS_GEOMETRIC
|wx2msPenStyle(M_PENDATA
->m_style
) ;
185 switch(M_PENDATA
->m_join
)
187 case wxJOIN_BEVEL
: ms_style
|= PS_JOIN_BEVEL
; break ;
188 case wxJOIN_MITER
: ms_style
|= PS_JOIN_MITER
; break ;
190 case wxJOIN_ROUND
: ms_style
|= PS_JOIN_ROUND
; break ;
193 switch(M_PENDATA
->m_cap
)
195 case wxCAP_PROJECTING
: ms_style
|= PS_ENDCAP_SQUARE
; break ;
196 case wxCAP_BUTT
: ms_style
|= PS_ENDCAP_FLAT
; break ;
198 case wxCAP_ROUND
: ms_style
|= PS_ENDCAP_ROUND
; break ;
201 switch(M_PENDATA
->m_style
)
204 logb
.lbStyle
= BS_PATTERN
;
205 if (M_PENDATA
->m_stipple
.Ok())
206 logb
.lbHatch
= (LONG
)M_PENDATA
->m_stipple
.GetHBITMAP() ;
208 logb
.lbHatch
= (LONG
)0 ;
210 case wxBDIAGONAL_HATCH
:
211 logb
.lbStyle
= BS_HATCHED
;
212 logb
.lbHatch
= HS_BDIAGONAL
;
214 case wxCROSSDIAG_HATCH
:
215 logb
.lbStyle
= BS_HATCHED
;
216 logb
.lbHatch
= HS_DIAGCROSS
;
218 case wxFDIAGONAL_HATCH
:
219 logb
.lbStyle
= BS_HATCHED
;
220 logb
.lbHatch
= HS_FDIAGONAL
;
223 logb
.lbStyle
= BS_HATCHED
;
224 logb
.lbHatch
= HS_CROSS
;
226 case wxHORIZONTAL_HATCH
:
227 logb
.lbStyle
= BS_HATCHED
;
228 logb
.lbHatch
= HS_HORIZONTAL
;
230 case wxVERTICAL_HATCH
:
231 logb
.lbStyle
= BS_HATCHED
;
232 logb
.lbHatch
= HS_VERTICAL
;
235 logb
.lbStyle
= BS_SOLID
;
238 logb
.lbColor
= ms_colour
;
240 if (M_PENDATA
->m_style
==wxUSER_DASH
&& M_PENDATA
->m_nbDash
&& M_PENDATA
->m_dash
)
242 real_dash
= new wxDash
[M_PENDATA
->m_nbDash
] ;
244 for (i
=0;i
<M_PENDATA
->m_nbDash
;i
++)
245 real_dash
[i
] = M_PENDATA
->m_dash
[i
] * M_PENDATA
->m_width
;
250 // Win32s doesn't have ExtCreatePen function...
251 if (wxGetOsVersion()==wxWINDOWS_NT
|| wxGetOsVersion()==wxWIN95
)
252 M_PENDATA
->m_hPen
= (WXHPEN
) ExtCreatePen(ms_style
,M_PENDATA
->m_width
,&logb
,
253 M_PENDATA
->m_style
==wxUSER_DASH
? M_PENDATA
->m_nbDash
:0, (const DWORD
*)real_dash
);
255 M_PENDATA
->m_hPen
= (WXHPEN
) CreatePen(wx2msPenStyle(M_PENDATA
->m_style
), M_PENDATA
->m_width
, ms_colour
);
258 delete [] real_dash
;
261 M_PENDATA
->m_hPen
= (WXHPEN
) CreatePen(wx2msPenStyle(M_PENDATA
->m_style
), M_PENDATA
->m_width
, ms_colour
);
264 if (M_PENDATA
->m_hPen
==0)
265 wxError("Cannot create pen","Internal error") ;
272 WXHANDLE
wxPen::GetResourceHandle(void)
277 return (WXHANDLE
)M_PENDATA
->m_hPen
;
280 bool wxPen::FreeResource(bool force
)
282 if (M_PENDATA
&& (M_PENDATA
->m_hPen
!= 0))
284 DeleteObject((HPEN
) M_PENDATA
->m_hPen
);
285 M_PENDATA
->m_hPen
= 0;
292 bool wxPen::UseResource(void)
294 IncrementResourceUsage();
298 bool wxPen::ReleaseResource(void)
300 DecrementResourceUsage();
305 bool wxPen::IsFree(void)
307 return (M_PENDATA
&& M_PENDATA
->m_hPen
== 0);
310 void wxPen::SetColour(const wxColour
& col
)
313 m_refData
= new wxPenRefData
;
315 M_PENDATA
->m_colour
= col
;
321 void wxPen::SetColour(const wxString
& col
)
324 m_refData
= new wxPenRefData
;
326 M_PENDATA
->m_colour
= col
;
332 void wxPen::SetColour(const unsigned char r
, const unsigned char g
, const unsigned char b
)
335 m_refData
= new wxPenRefData
;
337 M_PENDATA
->m_colour
.Set(r
, g
, b
);
343 void wxPen::SetWidth(const int Width
)
346 m_refData
= new wxPenRefData
;
348 M_PENDATA
->m_width
= Width
;
354 void wxPen::SetStyle(const int Style
)
357 m_refData
= new wxPenRefData
;
359 M_PENDATA
->m_style
= Style
;
365 void wxPen::SetStipple(const wxBitmap
& Stipple
)
368 m_refData
= new wxPenRefData
;
370 M_PENDATA
->m_stipple
= Stipple
;
371 M_PENDATA
->m_style
= wxSTIPPLE
;
377 void wxPen::SetDashes(const int nb_dashes
, const wxDash
*Dash
)
380 m_refData
= new wxPenRefData
;
382 M_PENDATA
->m_nbDash
= nb_dashes
;
383 M_PENDATA
->m_dash
= (wxDash
*)Dash
;
389 void wxPen::SetJoin(const int Join
)
392 m_refData
= new wxPenRefData
;
394 M_PENDATA
->m_join
= Join
;
400 void wxPen::SetCap(const int Cap
)
403 m_refData
= new wxPenRefData
;
405 M_PENDATA
->m_cap
= Cap
;
411 int wx2msPenStyle(int wx_style
)
416 DWORD vers = GetVersion() ;
417 WORD high = HIWORD(vers) ; // high bit=0 for NT, 1 for Win32s
433 // User dash style not supported on Win3.1, sorry...
435 // Win32s doesn't have PS_USERSTYLE
437 if ((high&0x8000)==0)
439 if (wxGetOsVersion()==wxWINDOWS_NT
)
440 cstyle
= PS_USERSTYLE
;
442 cstyle
= PS_DOT
; // We must make a choice... This is mine!