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 "gdi_private.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
36 /* GDI logical pen object */
44 static HGDIOBJ PEN_SelectObject( HGDIOBJ handle, HDC hdc );
45 static INT PEN_GetObject( HGDIOBJ handle, INT count, LPVOID buffer );
46 static BOOL PEN_DeleteObject( HGDIOBJ handle );
48 static const struct gdi_obj_funcs pen_funcs =
50 PEN_SelectObject, /* pSelectObject */
51 PEN_GetObject, /* pGetObjectA */
52 PEN_GetObject, /* pGetObjectW */
53 NULL, /* pUnrealizeObject */
54 PEN_DeleteObject /* pDeleteObject */
58 /***********************************************************************
61 HPEN WINAPI CreatePen( INT style, INT width, COLORREF color )
65 TRACE("%d %d %06x\n", style, width, color );
67 logpen.lopnStyle = style;
68 logpen.lopnWidth.x = width;
69 logpen.lopnWidth.y = 0;
70 logpen.lopnColor = color;
72 return CreatePenIndirect( &logpen );
76 /***********************************************************************
77 * CreatePenIndirect (GDI32.@)
79 HPEN WINAPI CreatePenIndirect( const LOGPEN * pen )
84 if (pen->lopnStyle == PS_NULL)
86 hpen = GetStockObject(NULL_PEN);
87 if (hpen) return hpen;
90 if (!(penPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(*penPtr) ))) return 0;
92 penPtr->logpen.elpPenStyle = pen->lopnStyle;
93 penPtr->logpen.elpWidth = abs(pen->lopnWidth.x);
94 penPtr->logpen.elpColor = pen->lopnColor;
95 penPtr->logpen.elpBrushStyle = BS_SOLID;
96 penPtr->logpen.elpHatch = 0;
97 penPtr->logpen.elpNumEntries = 0;
98 penPtr->logpen.elpStyleEntry[0] = 0;
100 switch (pen->lopnStyle)
110 penPtr->logpen.elpWidth = 1;
111 penPtr->logpen.elpColor = 0;
114 penPtr->logpen.elpPenStyle = PS_SOLID;
118 if (!(hpen = alloc_gdi_handle( &penPtr->header, OBJ_PEN, &pen_funcs )))
119 HeapFree( GetProcessHeap(), 0, penPtr );
123 /***********************************************************************
124 * ExtCreatePen (GDI32.@)
127 HPEN WINAPI ExtCreatePen( DWORD style, DWORD width,
128 const LOGBRUSH * brush, DWORD style_count,
129 const DWORD *style_bits )
134 if ((style_count || style_bits) && (style & PS_STYLE_MASK) != PS_USERSTYLE)
136 SetLastError(ERROR_INVALID_PARAMETER);
140 switch (style & PS_STYLE_MASK)
143 return CreatePen( PS_NULL, 0, brush->lbColor );
153 if (((INT)style_count) <= 0) return 0;
155 if ((style_count > 16) || !style_bits)
157 SetLastError(ERROR_INVALID_PARAMETER);
161 if ((style & PS_TYPE_MASK) == PS_GEOMETRIC)
164 BOOL has_neg = FALSE, all_zero = TRUE;
166 for(i = 0; (i < style_count) && !has_neg; i++)
168 has_neg = has_neg || (((INT)(style_bits[i])) < 0);
169 all_zero = all_zero && (style_bits[i] == 0);
172 if(all_zero || has_neg)
174 SetLastError(ERROR_INVALID_PARAMETER);
180 case PS_INSIDEFRAME: /* applicable only for geometric pens */
181 if ((style & PS_TYPE_MASK) != PS_GEOMETRIC)
183 SetLastError(ERROR_INVALID_PARAMETER);
188 case PS_ALTERNATE: /* applicable only for cosmetic pens */
189 if ((style & PS_TYPE_MASK) == PS_GEOMETRIC)
191 SetLastError(ERROR_INVALID_PARAMETER);
197 SetLastError(ERROR_INVALID_PARAMETER);
201 if ((style & PS_TYPE_MASK) == PS_GEOMETRIC)
203 if (brush->lbHatch && ((brush->lbStyle != BS_SOLID) && (brush->lbStyle != BS_HOLLOW)))
205 static int fixme_hatches_shown;
206 if (!fixme_hatches_shown++) FIXME("Hatches not implemented\n");
213 SetLastError(ERROR_INVALID_PARAMETER);
218 if (!(penPtr = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(PENOBJ,logpen.elpStyleEntry[style_count]))))
221 penPtr->logpen.elpPenStyle = style;
222 penPtr->logpen.elpWidth = abs(width);
223 penPtr->logpen.elpBrushStyle = brush->lbStyle;
224 penPtr->logpen.elpColor = brush->lbColor;
225 penPtr->logpen.elpHatch = brush->lbHatch;
226 penPtr->logpen.elpNumEntries = style_count;
227 memcpy(penPtr->logpen.elpStyleEntry, style_bits, style_count * sizeof(DWORD));
229 if (!(hpen = alloc_gdi_handle( &penPtr->header, OBJ_EXTPEN, &pen_funcs )))
230 HeapFree( GetProcessHeap(), 0, penPtr );
234 /***********************************************************************
237 static HGDIOBJ PEN_SelectObject( HGDIOBJ handle, HDC hdc )
241 DC *dc = get_dc_ptr( hdc );
245 SetLastError( ERROR_INVALID_HANDLE );
249 if (!GDI_inc_ref_count( handle ))
251 release_dc_ptr( dc );
255 physdev = GET_DC_PHYSDEV( dc, pSelectPen );
256 if (!physdev->funcs->pSelectPen( physdev, handle ))
258 GDI_dec_ref_count( handle );
264 GDI_dec_ref_count( ret );
266 release_dc_ptr( dc );
271 /***********************************************************************
274 static BOOL PEN_DeleteObject( HGDIOBJ handle )
276 PENOBJ *pen = free_gdi_handle( handle );
278 if (!pen) return FALSE;
279 return HeapFree( GetProcessHeap(), 0, pen );
283 /***********************************************************************
286 static INT PEN_GetObject( HGDIOBJ handle, INT count, LPVOID buffer )
288 PENOBJ *pen = GDI_GetObjPtr( handle, 0 );
293 switch (pen->header.type)
299 if (!buffer) ret = sizeof(LOGPEN);
300 else if (count < sizeof(LOGPEN)) ret = 0;
301 else if ((pen->logpen.elpPenStyle & PS_STYLE_MASK) == PS_NULL && count == sizeof(EXTLOGPEN))
303 EXTLOGPEN *elp = buffer;
306 ret = sizeof(EXTLOGPEN);
311 lp->lopnStyle = pen->logpen.elpPenStyle;
312 lp->lopnColor = pen->logpen.elpColor;
313 lp->lopnWidth.x = pen->logpen.elpWidth;
315 ret = sizeof(LOGPEN);
321 ret = sizeof(EXTLOGPEN) + pen->logpen.elpNumEntries * sizeof(DWORD) - sizeof(pen->logpen.elpStyleEntry);
324 if (count < ret) ret = 0;
325 else memcpy(buffer, &pen->logpen, ret);
329 GDI_ReleaseObj( handle );