4 * Copyright 1993 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/wingdi16.h"
33 #include "gdi_private.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(gdi
);
38 /* GDI logical pen object */
46 static HGDIOBJ
PEN_SelectObject( HGDIOBJ handle
, void *obj
, HDC hdc
);
47 static INT
PEN_GetObject16( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
);
48 static INT
PEN_GetObject( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
);
50 static const struct gdi_obj_funcs pen_funcs
=
52 PEN_SelectObject
, /* pSelectObject */
53 PEN_GetObject16
, /* pGetObject16 */
54 PEN_GetObject
, /* pGetObjectA */
55 PEN_GetObject
, /* pGetObjectW */
56 NULL
, /* pUnrealizeObject */
57 GDI_FreeObject
/* pDeleteObject */
61 /***********************************************************************
64 HPEN WINAPI
CreatePen( INT style
, INT width
, COLORREF color
)
68 TRACE("%d %d %06lx\n", style
, width
, color
);
70 logpen
.lopnStyle
= style
;
71 logpen
.lopnWidth
.x
= width
;
72 logpen
.lopnWidth
.y
= 0;
73 logpen
.lopnColor
= color
;
75 return CreatePenIndirect( &logpen
);
79 /***********************************************************************
80 * CreatePenIndirect (GDI32.@)
82 HPEN WINAPI
CreatePenIndirect( const LOGPEN
* pen
)
87 if (!(penPtr
= GDI_AllocObject( sizeof(PENOBJ
), PEN_MAGIC
, (HGDIOBJ
*)&hpen
,
88 &pen_funcs
))) return 0;
89 if (pen
->lopnStyle
== PS_USERSTYLE
|| pen
->lopnStyle
== PS_ALTERNATE
)
90 penPtr
->logpen
.elpPenStyle
= PS_SOLID
;
92 penPtr
->logpen
.elpPenStyle
= pen
->lopnStyle
;
93 if (pen
->lopnStyle
== PS_NULL
)
95 penPtr
->logpen
.elpWidth
= 1;
96 penPtr
->logpen
.elpColor
= RGB(0, 0, 0);
100 penPtr
->logpen
.elpWidth
= abs(pen
->lopnWidth
.x
);
101 penPtr
->logpen
.elpColor
= pen
->lopnColor
;
103 penPtr
->logpen
.elpBrushStyle
= BS_SOLID
;
104 penPtr
->logpen
.elpHatch
= 0;
105 penPtr
->logpen
.elpNumEntries
= 0;
106 penPtr
->logpen
.elpStyleEntry
[0] = 0;
108 GDI_ReleaseObj( hpen
);
112 /***********************************************************************
113 * ExtCreatePen (GDI32.@)
115 * FIXME: PS_USERSTYLE not handled
118 HPEN WINAPI
ExtCreatePen( DWORD style
, DWORD width
,
119 const LOGBRUSH
* brush
, DWORD style_count
,
120 const DWORD
*style_bits
)
125 if ((style
& PS_STYLE_MASK
) == PS_USERSTYLE
)
127 if (!style_count
|| !style_bits
)
129 SetLastError(ERROR_INVALID_PARAMETER
);
132 /* FIXME: PS_USERSTYLE workaround */
133 FIXME("PS_USERSTYLE not handled\n");
134 style
= (style
& ~PS_STYLE_MASK
) | PS_SOLID
;
138 if (style_count
|| style_bits
)
140 SetLastError(ERROR_INVALID_PARAMETER
);
145 if ((style
& PS_STYLE_MASK
) == PS_NULL
)
146 return CreatePen( PS_NULL
, 0, brush
->lbColor
);
148 if ((style
& PS_TYPE_MASK
) == PS_GEOMETRIC
)
150 /* PS_ALTERNATE is applicable only for cosmetic pens */
151 if ((style
& PS_STYLE_MASK
) == PS_ALTERNATE
)
153 SetLastError(ERROR_INVALID_PARAMETER
);
157 if (brush
->lbHatch
&& ((brush
->lbStyle
== BS_SOLID
) || (brush
->lbStyle
== BS_HOLLOW
)))
159 static int fixme_hatches_shown
;
160 if (!fixme_hatches_shown
++) FIXME("Hatches not implemented\n");
165 /* PS_INSIDEFRAME is applicable only for gemetric pens */
166 if ((style
& PS_STYLE_MASK
) == PS_INSIDEFRAME
|| width
!= 1)
168 SetLastError(ERROR_INVALID_PARAMETER
);
173 if (!(penPtr
= GDI_AllocObject( sizeof(PENOBJ
) +
174 style_count
* sizeof(DWORD
) - sizeof(penPtr
->logpen
.elpStyleEntry
),
175 EXT_PEN_MAGIC
, (HGDIOBJ
*)&hpen
,
176 &pen_funcs
))) return 0;
178 penPtr
->logpen
.elpPenStyle
= style
;
179 penPtr
->logpen
.elpWidth
= abs(width
);
180 penPtr
->logpen
.elpBrushStyle
= brush
->lbStyle
;
181 penPtr
->logpen
.elpColor
= brush
->lbColor
;
182 penPtr
->logpen
.elpHatch
= brush
->lbHatch
;
183 penPtr
->logpen
.elpNumEntries
= style_count
;
184 memcpy(penPtr
->logpen
.elpStyleEntry
, style_bits
, style_count
* sizeof(DWORD
));
186 GDI_ReleaseObj( hpen
);
192 /***********************************************************************
195 static HGDIOBJ
PEN_SelectObject( HGDIOBJ handle
, void *obj
, HDC hdc
)
198 DC
*dc
= DC_GetDCPtr( hdc
);
202 if (dc
->funcs
->pSelectPen
) handle
= dc
->funcs
->pSelectPen( dc
->physDev
, handle
);
203 if (handle
) dc
->hPen
= handle
;
205 GDI_ReleaseObj( hdc
);
210 /***********************************************************************
213 static INT
PEN_GetObject16( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
)
218 if (!buffer
) return sizeof(LOGPEN16
);
220 if (count
< sizeof(LOGPEN16
)) return 0;
223 logpen
->lopnStyle
= pen
->logpen
.elpPenStyle
;
224 logpen
->lopnColor
= pen
->logpen
.elpColor
;
225 logpen
->lopnWidth
.x
= pen
->logpen
.elpWidth
;
226 logpen
->lopnWidth
.y
= 0;
228 return sizeof(LOGPEN16
);
232 /***********************************************************************
235 static INT
PEN_GetObject( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
)
239 switch (GDIMAGIC(pen
->header
.wMagic
))
245 if (!buffer
) return sizeof(LOGPEN
);
247 if (count
< sizeof(LOGPEN
)) return 0;
249 if ((pen
->logpen
.elpPenStyle
& PS_STYLE_MASK
) == PS_NULL
&&
250 count
== sizeof(EXTLOGPEN
))
252 EXTLOGPEN
*elp
= buffer
;
253 memcpy(elp
, &pen
->logpen
, sizeof(EXTLOGPEN
));
255 return sizeof(EXTLOGPEN
);
259 lp
->lopnStyle
= pen
->logpen
.elpPenStyle
;
260 lp
->lopnColor
= pen
->logpen
.elpColor
;
261 lp
->lopnWidth
.x
= pen
->logpen
.elpWidth
;
263 return sizeof(LOGPEN
);
268 INT size
= sizeof(EXTLOGPEN
) + pen
->logpen
.elpNumEntries
* sizeof(DWORD
) - sizeof(pen
->logpen
.elpStyleEntry
);
270 if (!buffer
) return size
;
272 if (count
< size
) return 0;
273 memcpy(buffer
, &pen
->logpen
, size
);