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
33 #include "ntgdi_private.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(gdi
);
38 /* GDI logical pen object */
41 struct gdi_obj_header obj
;
42 struct brush_pattern pattern
;
47 static INT
PEN_GetObject( HGDIOBJ handle
, INT count
, LPVOID buffer
);
48 static BOOL
PEN_DeleteObject( HGDIOBJ handle
);
50 static const struct gdi_obj_funcs pen_funcs
=
52 PEN_GetObject
, /* pGetObjectW */
53 NULL
, /* pUnrealizeObject */
54 PEN_DeleteObject
/* pDeleteObject */
57 HPEN
create_pen( INT style
, INT width
, COLORREF color
)
62 TRACE( "%d %d %s\n", style
, width
, debugstr_color(color
) );
81 if (!(penPtr
= calloc( 1, sizeof(*penPtr
) ))) return 0;
83 penPtr
->logpen
.elpPenStyle
= style
;
84 penPtr
->logpen
.elpWidth
= abs(width
);
85 penPtr
->logpen
.elpColor
= color
;
86 penPtr
->logpen
.elpBrushStyle
= BS_SOLID
;
88 if (!(hpen
= alloc_gdi_handle( &penPtr
->obj
, NTGDI_OBJ_PEN
, &pen_funcs
)))
93 /***********************************************************************
94 * NtGdiCreatePen (win32u.@)
96 HPEN WINAPI
NtGdiCreatePen( INT style
, INT width
, COLORREF color
, HBRUSH brush
)
98 if (brush
) FIXME( "brush not supported\n" );
99 if (style
== PS_NULL
) return GetStockObject( NULL_PEN
);
100 return create_pen( style
, width
, color
);
103 /***********************************************************************
104 * NtGdiExtCreatePen (win32u.@)
106 HPEN WINAPI
NtGdiExtCreatePen( DWORD style
, DWORD width
, ULONG brush_style
, ULONG color
,
107 ULONG_PTR client_hatch
, ULONG_PTR hatch
, DWORD style_count
,
108 const DWORD
*style_bits
, ULONG dib_size
, BOOL old_style
,
111 PENOBJ
*penPtr
= NULL
;
115 if ((style_count
|| style_bits
) && (style
& PS_STYLE_MASK
) != PS_USERSTYLE
)
118 switch (style
& PS_STYLE_MASK
)
121 return NtGdiCreatePen( PS_NULL
, 0, color
, NULL
);
131 if (((INT
)style_count
) <= 0) return 0;
133 if ((style_count
> 16) || !style_bits
) goto invalid
;
135 if ((style
& PS_TYPE_MASK
) == PS_GEOMETRIC
)
138 BOOL has_neg
= FALSE
, all_zero
= TRUE
;
140 for(i
= 0; (i
< style_count
) && !has_neg
; i
++)
142 has_neg
= has_neg
|| (((INT
)(style_bits
[i
])) < 0);
143 all_zero
= all_zero
&& (style_bits
[i
] == 0);
146 if (all_zero
|| has_neg
) goto invalid
;
150 case PS_INSIDEFRAME
: /* applicable only for geometric pens */
151 if ((style
& PS_TYPE_MASK
) != PS_GEOMETRIC
) goto invalid
;
154 case PS_ALTERNATE
: /* applicable only for cosmetic pens */
155 if ((style
& PS_TYPE_MASK
) == PS_GEOMETRIC
) goto invalid
;
159 RtlSetLastWin32Error(ERROR_INVALID_PARAMETER
);
163 if ((style
& PS_TYPE_MASK
) == PS_GEOMETRIC
)
165 if (brush_style
== BS_NULL
) return NtGdiCreatePen( PS_NULL
, 0, 0, NULL
);
169 if (width
!= 1) goto invalid
;
170 if (brush_style
!= BS_SOLID
) goto invalid
;
173 if (!(penPtr
= malloc( FIELD_OFFSET(PENOBJ
,logpen
.elpStyleEntry
[style_count
]) )))
176 logbrush
.lbStyle
= brush_style
;
177 logbrush
.lbColor
= color
;
178 logbrush
.lbHatch
= hatch
;
179 if (!store_brush_pattern( &logbrush
, &penPtr
->pattern
)) goto invalid
;
180 if (logbrush
.lbStyle
== BS_DIBPATTERN
) logbrush
.lbStyle
= BS_DIBPATTERNPT
;
182 penPtr
->logpen
.elpPenStyle
= style
;
183 penPtr
->logpen
.elpWidth
= abs((int)width
);
184 penPtr
->logpen
.elpBrushStyle
= logbrush
.lbStyle
;
185 penPtr
->logpen
.elpColor
= logbrush
.lbColor
;
186 penPtr
->logpen
.elpHatch
= client_hatch
;
187 penPtr
->logpen
.elpNumEntries
= style_count
;
188 memcpy(penPtr
->logpen
.elpStyleEntry
, style_bits
, style_count
* sizeof(DWORD
));
190 if (!(hpen
= alloc_gdi_handle( &penPtr
->obj
, NTGDI_OBJ_EXTPEN
, &pen_funcs
)))
192 free_brush_pattern( &penPtr
->pattern
);
199 RtlSetLastWin32Error( ERROR_INVALID_PARAMETER
);
203 /***********************************************************************
204 * NtGdiSelectPen (win32u.@)
206 HGDIOBJ WINAPI
NtGdiSelectPen( HDC hdc
, HGDIOBJ handle
)
213 if (!(dc
= get_dc_ptr( hdc
))) return 0;
215 if ((pen
= get_any_obj_ptr( handle
, &type
)))
217 struct brush_pattern
*pattern
;
218 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSelectPen
);
225 case NTGDI_OBJ_EXTPEN
:
226 pattern
= &pen
->pattern
;
227 if (!pattern
->info
) pattern
= NULL
;
230 GDI_ReleaseObj( handle
);
231 release_dc_ptr( dc
);
235 GDI_inc_ref_count( handle
);
236 GDI_ReleaseObj( handle
);
238 if (!physdev
->funcs
->pSelectPen( physdev
, handle
, pattern
))
240 GDI_dec_ref_count( handle
);
246 GDI_dec_ref_count( ret
);
249 release_dc_ptr( dc
);
254 /***********************************************************************
257 static BOOL
PEN_DeleteObject( HGDIOBJ handle
)
259 PENOBJ
*pen
= free_gdi_handle( handle
);
261 if (!pen
) return FALSE
;
262 free_brush_pattern( &pen
->pattern
);
268 /***********************************************************************
271 static INT
PEN_GetObject( HGDIOBJ handle
, INT count
, LPVOID buffer
)
274 PENOBJ
*pen
= get_any_obj_ptr( handle
, &type
);
285 if (!buffer
) ret
= sizeof(LOGPEN
);
286 else if (count
< sizeof(LOGPEN
)) ret
= 0;
287 else if ((pen
->logpen
.elpPenStyle
& PS_STYLE_MASK
) == PS_NULL
&& count
== sizeof(EXTLOGPEN
))
289 EXTLOGPEN
*elp
= buffer
;
292 ret
= sizeof(EXTLOGPEN
);
297 lp
->lopnStyle
= pen
->logpen
.elpPenStyle
;
298 lp
->lopnColor
= pen
->logpen
.elpColor
;
299 lp
->lopnWidth
.x
= pen
->logpen
.elpWidth
;
301 ret
= sizeof(LOGPEN
);
306 case NTGDI_OBJ_EXTPEN
:
307 ret
= sizeof(EXTLOGPEN
) + pen
->logpen
.elpNumEntries
* sizeof(DWORD
) - sizeof(pen
->logpen
.elpStyleEntry
);
310 if (count
< ret
) ret
= 0;
311 else memcpy(buffer
, &pen
->logpen
, ret
);
315 GDI_ReleaseObj( handle
);