]>
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
)
51 m_style
= data
.m_style
;
52 m_width
= data
.m_width
;
55 m_nbDash
= data
.m_nbDash
;
57 m_colour
= data
.m_colour
;
61 wxPenRefData::~wxPenRefData()
64 ::DeleteObject((HPEN
) m_hPen
);
77 // Should implement Create
78 wxPen::wxPen(const wxColour
& col
, int Width
, int Style
)
80 m_refData
= new wxPenRefData
;
82 M_PENDATA
->m_colour
= col
;
83 // M_PENDATA->m_stipple = NULL;
84 M_PENDATA
->m_width
= Width
;
85 M_PENDATA
->m_style
= Style
;
86 M_PENDATA
->m_join
= wxJOIN_ROUND
;
87 M_PENDATA
->m_cap
= wxCAP_ROUND
;
88 M_PENDATA
->m_nbDash
= 0 ;
89 M_PENDATA
->m_dash
= (wxDash
*)NULL
;
90 M_PENDATA
->m_hPen
= 0 ;
95 wxPen::wxPen(const wxBitmap
& stipple
, int Width
)
97 m_refData
= new wxPenRefData
;
99 // M_PENDATA->m_colour = col;
100 M_PENDATA
->m_stipple
= stipple
;
101 M_PENDATA
->m_width
= Width
;
102 M_PENDATA
->m_style
= wxSTIPPLE
;
103 M_PENDATA
->m_join
= wxJOIN_ROUND
;
104 M_PENDATA
->m_cap
= wxCAP_ROUND
;
105 M_PENDATA
->m_nbDash
= 0 ;
106 M_PENDATA
->m_dash
= (wxDash
*)NULL
;
107 M_PENDATA
->m_hPen
= 0 ;
112 bool wxPen::RealizeResource()
114 if ( !M_PENDATA
|| M_PENDATA
->m_hPen
)
117 if (M_PENDATA
->m_style
==wxTRANSPARENT
)
119 M_PENDATA
->m_hPen
= (WXHPEN
) ::GetStockObject(NULL_PEN
);
123 static const int os
= wxGetOsVersion();
124 COLORREF ms_colour
= M_PENDATA
->m_colour
.GetPixel();
126 // Join style, Cap style, Pen Stippling
127 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
128 // Only NT can display dashed or dotted lines with width > 1
129 if ( os
!= wxWINDOWS_NT
&&
130 (M_PENDATA
->m_style
& (wxDOT
|
135 M_PENDATA
->m_width
> 1 )
137 M_PENDATA
->m_width
= 1;
140 if (M_PENDATA
->m_join
==wxJOIN_ROUND
&&
141 M_PENDATA
->m_cap
==wxCAP_ROUND
&&
142 M_PENDATA
->m_style
!=wxUSER_DASH
&&
143 M_PENDATA
->m_style
!=wxSTIPPLE
&&
144 M_PENDATA
->m_width
<= 1)
147 (WXHPEN
) CreatePen( wx2msPenStyle(M_PENDATA
->m_style
),
153 DWORD ms_style
= PS_GEOMETRIC
| wx2msPenStyle(M_PENDATA
->m_style
);
155 switch(M_PENDATA
->m_join
)
157 case wxJOIN_BEVEL
: ms_style
|= PS_JOIN_BEVEL
; break;
158 case wxJOIN_MITER
: ms_style
|= PS_JOIN_MITER
; break;
160 case wxJOIN_ROUND
: ms_style
|= PS_JOIN_ROUND
; break;
163 switch(M_PENDATA
->m_cap
)
165 case wxCAP_PROJECTING
: ms_style
|= PS_ENDCAP_SQUARE
; break;
166 case wxCAP_BUTT
: ms_style
|= PS_ENDCAP_FLAT
; break;
168 case wxCAP_ROUND
: ms_style
|= PS_ENDCAP_ROUND
; break;
173 switch(M_PENDATA
->m_style
)
176 logb
.lbStyle
= BS_PATTERN
;
177 if (M_PENDATA
->m_stipple
.Ok())
178 logb
.lbHatch
= (LONG
)M_PENDATA
->m_stipple
.GetHBITMAP();
180 logb
.lbHatch
= (LONG
)0;
182 case wxBDIAGONAL_HATCH
:
183 logb
.lbStyle
= BS_HATCHED
;
184 logb
.lbHatch
= HS_BDIAGONAL
;
186 case wxCROSSDIAG_HATCH
:
187 logb
.lbStyle
= BS_HATCHED
;
188 logb
.lbHatch
= HS_DIAGCROSS
;
190 case wxFDIAGONAL_HATCH
:
191 logb
.lbStyle
= BS_HATCHED
;
192 logb
.lbHatch
= HS_FDIAGONAL
;
195 logb
.lbStyle
= BS_HATCHED
;
196 logb
.lbHatch
= HS_CROSS
;
198 case wxHORIZONTAL_HATCH
:
199 logb
.lbStyle
= BS_HATCHED
;
200 logb
.lbHatch
= HS_HORIZONTAL
;
202 case wxVERTICAL_HATCH
:
203 logb
.lbStyle
= BS_HATCHED
;
204 logb
.lbHatch
= HS_VERTICAL
;
207 logb
.lbStyle
= BS_SOLID
;
209 // this should be unnecessary (it's unused) but suppresses the Purify
210 // messages about uninitialized memory read
216 logb
.lbColor
= ms_colour
;
218 wxMSWDash
*real_dash
;
219 if (M_PENDATA
->m_style
==wxUSER_DASH
&& M_PENDATA
->m_nbDash
&& M_PENDATA
->m_dash
)
221 real_dash
= new wxMSWDash
[M_PENDATA
->m_nbDash
];
222 int rw
= M_PENDATA
->m_width
> 1 ? M_PENDATA
->m_width
: 1;
223 for ( int i
= 0; i
< M_PENDATA
->m_nbDash
; i
++ )
224 real_dash
[i
] = M_PENDATA
->m_dash
[i
] * rw
;
228 real_dash
= (wxMSWDash
*)NULL
;
231 // Win32s doesn't have ExtCreatePen function...
232 if (os
==wxWINDOWS_NT
|| os
==wxWIN95
)
235 (WXHPEN
) ExtCreatePen( ms_style
,
238 M_PENDATA
->m_style
== wxUSER_DASH
239 ? M_PENDATA
->m_nbDash
241 (LPDWORD
)real_dash
);
246 (WXHPEN
) CreatePen( wx2msPenStyle(M_PENDATA
->m_style
),
255 (WXHPEN
) CreatePen( wx2msPenStyle(M_PENDATA
->m_style
),
258 #endif // !WinCE/WinCE
263 WXHANDLE
wxPen::GetResourceHandle() const
268 return (WXHANDLE
)M_PENDATA
->m_hPen
;
271 bool wxPen::FreeResource(bool WXUNUSED(force
))
273 if (M_PENDATA
&& (M_PENDATA
->m_hPen
!= 0))
275 DeleteObject((HPEN
) M_PENDATA
->m_hPen
);
276 M_PENDATA
->m_hPen
= 0;
282 bool wxPen::IsFree() const
284 return (M_PENDATA
&& M_PENDATA
->m_hPen
== 0);
287 void wxPen::Unshare()
289 // Don't change shared data
292 m_refData
= new wxPenRefData();
296 wxPenRefData
* ref
= new wxPenRefData(*(wxPenRefData
*)m_refData
);
302 void wxPen::SetColour(const wxColour
& col
)
306 M_PENDATA
->m_colour
= col
;
311 void wxPen::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
315 M_PENDATA
->m_colour
.Set(r
, g
, b
);
320 void wxPen::SetWidth(int Width
)
324 M_PENDATA
->m_width
= Width
;
329 void wxPen::SetStyle(int Style
)
333 M_PENDATA
->m_style
= Style
;
338 void wxPen::SetStipple(const wxBitmap
& Stipple
)
342 M_PENDATA
->m_stipple
= Stipple
;
343 M_PENDATA
->m_style
= wxSTIPPLE
;
348 void wxPen::SetDashes(int nb_dashes
, const wxDash
*Dash
)
352 M_PENDATA
->m_nbDash
= nb_dashes
;
353 M_PENDATA
->m_dash
= (wxDash
*)Dash
;
358 void wxPen::SetJoin(int Join
)
362 M_PENDATA
->m_join
= Join
;
367 void wxPen::SetCap(int Cap
)
371 M_PENDATA
->m_cap
= Cap
;
376 int wx2msPenStyle(int wx_style
)
378 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
395 // if (wxGetOsVersion()==wxWINDOWS_NT || wxGetOsVersion()==wxWIN95)
399 wxUnusedVar(wx_style
);