]>
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 ;
93 // In Windows, only a pen of width = 1 can be dotted or dashed!
94 if ((Style
== wxDOT
) || (Style
== wxLONG_DASH
) ||
95 (Style
== wxSHORT_DASH
) || (Style
== wxDOT_DASH
) ||
96 (Style
== wxUSER_DASH
))
97 M_PENDATA
->m_width
= 1;
100 DWORD vers = GetVersion() ;
101 WORD high = HIWORD(vers) ; // high bit=0 for NT, 1 for Win32s
102 // Win32s doesn't support wide dashed pens
104 if ((high&0x8000)!=0)
106 if (wxGetOsVersion()==wxWIN32S
)
108 // In Windows, only a pen of width = 1 can be dotted or dashed!
109 if ((Style
== wxDOT
) || (Style
== wxLONG_DASH
) ||
110 (Style
== wxSHORT_DASH
) || (Style
== wxDOT_DASH
) ||
111 (Style
== wxUSER_DASH
))
112 M_PENDATA
->m_width
= 1;
119 wxPen::wxPen(const wxBitmap
& stipple
, int Width
)
121 m_refData
= new wxPenRefData
;
123 // M_PENDATA->m_colour = col;
124 M_PENDATA
->m_stipple
= stipple
;
125 M_PENDATA
->m_width
= Width
;
126 M_PENDATA
->m_style
= wxSTIPPLE
;
127 M_PENDATA
->m_join
= wxJOIN_ROUND
;
128 M_PENDATA
->m_cap
= wxCAP_ROUND
;
129 M_PENDATA
->m_nbDash
= 0 ;
130 M_PENDATA
->m_dash
= (wxDash
*)NULL
;
131 M_PENDATA
->m_hPen
= 0 ;
137 bool wxPen::RealizeResource()
139 if (M_PENDATA
&& (M_PENDATA
->m_hPen
== 0))
141 if (M_PENDATA
->m_style
==wxTRANSPARENT
)
143 M_PENDATA
->m_hPen
= (WXHPEN
) ::GetStockObject(NULL_PEN
);
147 COLORREF ms_colour
= M_PENDATA
->m_colour
.GetPixel();
149 // Join style, Cap style, Pen Stippling only on Win32.
150 // Currently no time to find equivalent on Win3.1, sorry
151 // [if such equiv exist!!]
152 #if defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
153 if (M_PENDATA
->m_join
==wxJOIN_ROUND
&&
154 M_PENDATA
->m_cap
==wxCAP_ROUND
&&
155 M_PENDATA
->m_style
!=wxUSER_DASH
&&
156 M_PENDATA
->m_style
!=wxSTIPPLE
&&
157 M_PENDATA
->m_width
<= 1)
160 (WXHPEN
) CreatePen( wx2msPenStyle(M_PENDATA
->m_style
),
166 DWORD ms_style
= PS_GEOMETRIC
| wx2msPenStyle(M_PENDATA
->m_style
);
168 switch(M_PENDATA
->m_join
)
170 case wxJOIN_BEVEL
: ms_style
|= PS_JOIN_BEVEL
; break;
171 case wxJOIN_MITER
: ms_style
|= PS_JOIN_MITER
; break;
173 case wxJOIN_ROUND
: ms_style
|= PS_JOIN_ROUND
; break;
176 switch(M_PENDATA
->m_cap
)
178 case wxCAP_PROJECTING
: ms_style
|= PS_ENDCAP_SQUARE
; break;
179 case wxCAP_BUTT
: ms_style
|= PS_ENDCAP_FLAT
; break;
181 case wxCAP_ROUND
: ms_style
|= PS_ENDCAP_ROUND
; break;
186 switch(M_PENDATA
->m_style
)
189 logb
.lbStyle
= BS_PATTERN
;
190 if (M_PENDATA
->m_stipple
.Ok())
191 logb
.lbHatch
= (LONG
)M_PENDATA
->m_stipple
.GetHBITMAP();
193 logb
.lbHatch
= (LONG
)0;
195 case wxBDIAGONAL_HATCH
:
196 logb
.lbStyle
= BS_HATCHED
;
197 logb
.lbHatch
= HS_BDIAGONAL
;
199 case wxCROSSDIAG_HATCH
:
200 logb
.lbStyle
= BS_HATCHED
;
201 logb
.lbHatch
= HS_DIAGCROSS
;
203 case wxFDIAGONAL_HATCH
:
204 logb
.lbStyle
= BS_HATCHED
;
205 logb
.lbHatch
= HS_FDIAGONAL
;
208 logb
.lbStyle
= BS_HATCHED
;
209 logb
.lbHatch
= HS_CROSS
;
211 case wxHORIZONTAL_HATCH
:
212 logb
.lbStyle
= BS_HATCHED
;
213 logb
.lbHatch
= HS_HORIZONTAL
;
215 case wxVERTICAL_HATCH
:
216 logb
.lbStyle
= BS_HATCHED
;
217 logb
.lbHatch
= HS_VERTICAL
;
220 logb
.lbStyle
= BS_SOLID
;
222 // this should be unnecessary (it's unused) but suppresses the Purigy
223 // messages about uninitialized memory read
229 logb
.lbColor
= ms_colour
;
231 wxMSWDash
*real_dash
;
232 if (M_PENDATA
->m_style
==wxUSER_DASH
&& M_PENDATA
->m_nbDash
&& M_PENDATA
->m_dash
)
234 real_dash
= new wxMSWDash
[M_PENDATA
->m_nbDash
];
235 int rw
= M_PENDATA
->m_width
> 1 ? M_PENDATA
->m_width
: 1;
236 for ( int i
= 0; i
< M_PENDATA
->m_nbDash
; i
++ )
237 real_dash
[i
] = M_PENDATA
->m_dash
[i
] * rw
;
241 real_dash
= (wxMSWDash
*)NULL
;
244 // Win32s doesn't have ExtCreatePen function...
245 if (wxGetOsVersion()==wxWINDOWS_NT
|| wxGetOsVersion()==wxWIN95
)
248 (WXHPEN
) ExtCreatePen( ms_style
,
251 M_PENDATA
->m_style
== wxUSER_DASH
252 ? M_PENDATA
->m_nbDash
254 (LPDWORD
)real_dash
);
259 (WXHPEN
) CreatePen( wx2msPenStyle(M_PENDATA
->m_style
),
269 (WXHPEN
) CreatePen( wx2msPenStyle(M_PENDATA
->m_style
),
273 #ifdef WXDEBUG_CREATE
274 if (M_PENDATA
->m_hPen
==0)
275 wxError("Cannot create pen","Internal error") ;
282 WXHANDLE
wxPen::GetResourceHandle() const
287 return (WXHANDLE
)M_PENDATA
->m_hPen
;
290 bool wxPen::FreeResource(bool WXUNUSED(force
))
292 if (M_PENDATA
&& (M_PENDATA
->m_hPen
!= 0))
294 DeleteObject((HPEN
) M_PENDATA
->m_hPen
);
295 M_PENDATA
->m_hPen
= 0;
301 bool wxPen::IsFree() const
303 return (M_PENDATA
&& M_PENDATA
->m_hPen
== 0);
306 void wxPen::Unshare()
308 // Don't change shared data
311 m_refData
= new wxPenRefData();
315 wxPenRefData
* ref
= new wxPenRefData(*(wxPenRefData
*)m_refData
);
321 void wxPen::SetColour(const wxColour
& col
)
325 M_PENDATA
->m_colour
= col
;
330 void wxPen::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
334 M_PENDATA
->m_colour
.Set(r
, g
, b
);
339 void wxPen::SetWidth(int Width
)
343 M_PENDATA
->m_width
= Width
;
348 void wxPen::SetStyle(int Style
)
352 M_PENDATA
->m_style
= Style
;
357 void wxPen::SetStipple(const wxBitmap
& Stipple
)
361 M_PENDATA
->m_stipple
= Stipple
;
362 M_PENDATA
->m_style
= wxSTIPPLE
;
367 void wxPen::SetDashes(int nb_dashes
, const wxDash
*Dash
)
371 M_PENDATA
->m_nbDash
= nb_dashes
;
372 M_PENDATA
->m_dash
= (wxDash
*)Dash
;
377 void wxPen::SetJoin(int Join
)
381 M_PENDATA
->m_join
= Join
;
386 void wxPen::SetCap(int Cap
)
390 M_PENDATA
->m_cap
= Cap
;
395 int wx2msPenStyle(int wx_style
)
397 int cstyle
= PS_SOLID
;
400 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
420 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
422 // Win32s doesn't have PS_USERSTYLE
423 if (wxGetOsVersion()==wxWINDOWS_NT
|| wxGetOsVersion()==wxWIN95
)
424 cstyle
= PS_USERSTYLE
;
426 cstyle
= PS_DOT
; // We must make a choice... This is mine!