]>
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 /////////////////////////////////////////////////////////////////////////////
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 IMPLEMENT_DYNAMIC_CLASS(wxPen
, wxGDIObject
)
36 wxPenRefData::wxPenRefData()
40 m_join
= wxJOIN_ROUND
;
43 m_dash
= (wxDash
*)NULL
;
47 wxPenRefData::wxPenRefData(const wxPenRefData
& data
)
49 m_style
= data
.m_style
;
50 m_width
= data
.m_width
;
53 m_nbDash
= data
.m_nbDash
;
55 m_colour
= data
.m_colour
;
59 wxPenRefData::~wxPenRefData()
62 ::DeleteObject((HPEN
) m_hPen
);
75 // Should implement Create
76 wxPen::wxPen(const wxColour
& col
, int Width
, int Style
)
78 m_refData
= new wxPenRefData
;
80 M_PENDATA
->m_colour
= col
;
81 // M_PENDATA->m_stipple = NULL;
82 M_PENDATA
->m_width
= Width
;
83 M_PENDATA
->m_style
= Style
;
84 M_PENDATA
->m_join
= wxJOIN_ROUND
;
85 M_PENDATA
->m_cap
= wxCAP_ROUND
;
86 M_PENDATA
->m_nbDash
= 0 ;
87 M_PENDATA
->m_dash
= (wxDash
*)NULL
;
88 M_PENDATA
->m_hPen
= 0 ;
91 // In Windows, only a pen of width = 1 can be dotted or dashed!
92 if ((Style
== wxDOT
) || (Style
== wxLONG_DASH
) ||
93 (Style
== wxSHORT_DASH
) || (Style
== wxDOT_DASH
) ||
94 (Style
== wxUSER_DASH
))
95 M_PENDATA
->m_width
= 1;
98 DWORD vers = GetVersion() ;
99 WORD high = HIWORD(vers) ; // high bit=0 for NT, 1 for Win32s
100 // Win32s doesn't support wide dashed pens
102 if ((high&0x8000)!=0)
104 if (wxGetOsVersion()==wxWIN32S
)
106 // In Windows, only a pen of width = 1 can be dotted or dashed!
107 if ((Style
== wxDOT
) || (Style
== wxLONG_DASH
) ||
108 (Style
== wxSHORT_DASH
) || (Style
== wxDOT_DASH
) ||
109 (Style
== wxUSER_DASH
))
110 M_PENDATA
->m_width
= 1;
117 wxPen::wxPen(const wxBitmap
& stipple
, int Width
)
119 m_refData
= new wxPenRefData
;
121 // M_PENDATA->m_colour = col;
122 M_PENDATA
->m_stipple
= stipple
;
123 M_PENDATA
->m_width
= Width
;
124 M_PENDATA
->m_style
= wxSTIPPLE
;
125 M_PENDATA
->m_join
= wxJOIN_ROUND
;
126 M_PENDATA
->m_cap
= wxCAP_ROUND
;
127 M_PENDATA
->m_nbDash
= 0 ;
128 M_PENDATA
->m_dash
= (wxDash
*)NULL
;
129 M_PENDATA
->m_hPen
= 0 ;
135 bool wxPen::RealizeResource()
137 if (M_PENDATA
&& (M_PENDATA
->m_hPen
== 0))
139 if (M_PENDATA
->m_style
==wxTRANSPARENT
)
141 M_PENDATA
->m_hPen
= (WXHPEN
) ::GetStockObject(NULL_PEN
);
145 COLORREF ms_colour
= 0;
146 ms_colour
= M_PENDATA
->m_colour
.GetPixel();
148 // Join style, Cap style, Pen Stippling only on Win32.
149 // Currently no time to find equivalent on Win3.1, sorry
150 // [if such equiv exist!!]
151 #if defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
152 if (M_PENDATA
->m_join
==wxJOIN_ROUND
&&
153 M_PENDATA
->m_cap
==wxCAP_ROUND
&&
154 M_PENDATA
->m_style
!=wxUSER_DASH
&&
155 M_PENDATA
->m_style
!=wxSTIPPLE
&&
156 M_PENDATA
->m_width
<= 1)
159 (WXHPEN
) CreatePen( wx2msPenStyle(M_PENDATA
->m_style
),
165 DWORD ms_style
= PS_GEOMETRIC
| wx2msPenStyle(M_PENDATA
->m_style
);
167 switch(M_PENDATA
->m_join
)
169 case wxJOIN_BEVEL
: ms_style
|= PS_JOIN_BEVEL
; break;
170 case wxJOIN_MITER
: ms_style
|= PS_JOIN_MITER
; break;
172 case wxJOIN_ROUND
: ms_style
|= PS_JOIN_ROUND
; break;
175 switch(M_PENDATA
->m_cap
)
177 case wxCAP_PROJECTING
: ms_style
|= PS_ENDCAP_SQUARE
; break;
178 case wxCAP_BUTT
: ms_style
|= PS_ENDCAP_FLAT
; break;
180 case wxCAP_ROUND
: ms_style
|= PS_ENDCAP_ROUND
; break;
185 switch(M_PENDATA
->m_style
)
188 logb
.lbStyle
= BS_PATTERN
;
189 if (M_PENDATA
->m_stipple
.Ok())
190 logb
.lbHatch
= (LONG
)M_PENDATA
->m_stipple
.GetHBITMAP();
192 logb
.lbHatch
= (LONG
)0;
194 case wxBDIAGONAL_HATCH
:
195 logb
.lbStyle
= BS_HATCHED
;
196 logb
.lbHatch
= HS_BDIAGONAL
;
198 case wxCROSSDIAG_HATCH
:
199 logb
.lbStyle
= BS_HATCHED
;
200 logb
.lbHatch
= HS_DIAGCROSS
;
202 case wxFDIAGONAL_HATCH
:
203 logb
.lbStyle
= BS_HATCHED
;
204 logb
.lbHatch
= HS_FDIAGONAL
;
207 logb
.lbStyle
= BS_HATCHED
;
208 logb
.lbHatch
= HS_CROSS
;
210 case wxHORIZONTAL_HATCH
:
211 logb
.lbStyle
= BS_HATCHED
;
212 logb
.lbHatch
= HS_HORIZONTAL
;
214 case wxVERTICAL_HATCH
:
215 logb
.lbStyle
= BS_HATCHED
;
216 logb
.lbHatch
= HS_VERTICAL
;
219 logb
.lbStyle
= BS_SOLID
;
221 // this should be unnecessary (it's unused) but suppresses the Purigy
222 // messages about uninitialized memory read
228 logb
.lbColor
= ms_colour
;
230 wxMSWDash
*real_dash
;
231 if (M_PENDATA
->m_style
==wxUSER_DASH
&& M_PENDATA
->m_nbDash
&& M_PENDATA
->m_dash
)
233 real_dash
= new wxMSWDash
[M_PENDATA
->m_nbDash
];
234 int rw
= M_PENDATA
->m_width
> 1 ? M_PENDATA
->m_width
: 1;
235 for ( int i
= 0; i
< M_PENDATA
->m_nbDash
; i
++ )
236 real_dash
[i
] = M_PENDATA
->m_dash
[i
] * rw
;
240 real_dash
= (wxMSWDash
*)NULL
;
243 // Win32s doesn't have ExtCreatePen function...
244 if (wxGetOsVersion()==wxWINDOWS_NT
|| wxGetOsVersion()==wxWIN95
)
247 (WXHPEN
) ExtCreatePen( ms_style
,
250 M_PENDATA
->m_style
== wxUSER_DASH
251 ? M_PENDATA
->m_nbDash
253 (LPDWORD
)real_dash
);
258 (WXHPEN
) CreatePen( wx2msPenStyle(M_PENDATA
->m_style
),
268 (WXHPEN
) CreatePen( wx2msPenStyle(M_PENDATA
->m_style
),
272 #ifdef WXDEBUG_CREATE
273 if (M_PENDATA
->m_hPen
==0)
274 wxError("Cannot create pen","Internal error") ;
281 WXHANDLE
wxPen::GetResourceHandle() const
286 return (WXHANDLE
)M_PENDATA
->m_hPen
;
289 bool wxPen::FreeResource(bool WXUNUSED(force
))
291 if (M_PENDATA
&& (M_PENDATA
->m_hPen
!= 0))
293 DeleteObject((HPEN
) M_PENDATA
->m_hPen
);
294 M_PENDATA
->m_hPen
= 0;
300 bool wxPen::IsFree() const
302 return (M_PENDATA
&& M_PENDATA
->m_hPen
== 0);
305 void wxPen::Unshare()
307 // Don't change shared data
310 m_refData
= new wxPenRefData();
314 wxPenRefData
* ref
= new wxPenRefData(*(wxPenRefData
*)m_refData
);
320 void wxPen::SetColour(const wxColour
& col
)
324 M_PENDATA
->m_colour
= col
;
329 void wxPen::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
333 M_PENDATA
->m_colour
.Set(r
, g
, b
);
338 void wxPen::SetWidth(int Width
)
342 M_PENDATA
->m_width
= Width
;
347 void wxPen::SetStyle(int Style
)
351 M_PENDATA
->m_style
= Style
;
356 void wxPen::SetStipple(const wxBitmap
& Stipple
)
360 M_PENDATA
->m_stipple
= Stipple
;
361 M_PENDATA
->m_style
= wxSTIPPLE
;
366 void wxPen::SetDashes(int nb_dashes
, const wxDash
*Dash
)
370 M_PENDATA
->m_nbDash
= nb_dashes
;
371 M_PENDATA
->m_dash
= (wxDash
*)Dash
;
376 void wxPen::SetJoin(int Join
)
380 M_PENDATA
->m_join
= Join
;
385 void wxPen::SetCap(int Cap
)
389 M_PENDATA
->m_cap
= Cap
;
394 int wx2msPenStyle(int wx_style
)
399 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
419 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
421 // Win32s doesn't have PS_USERSTYLE
422 if (wxGetOsVersion()==wxWINDOWS_NT
|| wxGetOsVersion()==wxWIN95
)
423 cstyle
= PS_USERSTYLE
;
425 cstyle
= PS_DOT
; // We must make a choice... This is mine!