2 * ReactOS Win32 Subsystem
4 * Copyright (C) 1998 - 2004 ReactOS Team
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 /* PRIVATE FUNCTIONS **********************************************************/
32 PEN_ShareLockPen(HGDIOBJ hobj
)
34 if (GDI_HANDLE_GET_TYPE(hobj
) != GDILoObjType_LO_PEN_TYPE
&&
35 GDI_HANDLE_GET_TYPE(hobj
) != GDILoObjType_LO_EXTPEN_TYPE
)
40 return (PBRUSH
)GDIOBJ_ReferenceObjectByHandle(hobj
, GDIObjType_BRUSH_TYPE
);
47 IN ULONG ulBrushStyle
,
49 IN ULONG_PTR ulClientHatch
,
55 IN OPTIONAL HBRUSH hbrush
)
59 static const BYTE PatternAlternate
[] = {0x55, 0x55, 0x55, 0};
60 static const BYTE PatternDash
[] = {0xFF, 0xFF, 0xC0, 0};
61 static const BYTE PatternDot
[] = {0xE3, 0x8E, 0x38, 0};
62 static const BYTE PatternDashDot
[] = {0xFF, 0x81, 0xC0, 0};
63 static const BYTE PatternDashDotDot
[] = {0xFF, 0x8E, 0x38, 0};
65 dwWidth
= abs(dwWidth
);
67 if ( (dwPenStyle
& PS_STYLE_MASK
) == PS_NULL
)
69 return StockObjects
[NULL_PEN
];
74 pbrushPen
= PEN_AllocPenWithHandle();
78 pbrushPen
= PEN_AllocExtPenWithHandle();
83 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
84 DPRINT("Can't allocate pen\n");
87 hPen
= pbrushPen
->BaseObject
.hHmgr
;
89 // If nWidth is zero, the pen is a single pixel wide, regardless of the current transformation.
90 if ((bOldStylePen
) && (!dwWidth
) && (dwPenStyle
& PS_STYLE_MASK
) != PS_SOLID
)
93 pbrushPen
->ptPenWidth
.x
= dwWidth
;
94 pbrushPen
->ptPenWidth
.y
= 0;
95 pbrushPen
->ulPenStyle
= dwPenStyle
;
96 pbrushPen
->BrushAttr
.lbColor
= ulColor
;
97 pbrushPen
->ulStyle
= ulBrushStyle
;
98 // FIXME: copy the bitmap first ?
99 pbrushPen
->hbmClient
= (HANDLE
)ulClientHatch
;
100 pbrushPen
->dwStyleCount
= dwStyleCount
;
101 pbrushPen
->pStyle
= pStyle
;
103 pbrushPen
->flAttrs
= bOldStylePen
? GDIBRUSH_IS_OLDSTYLEPEN
: GDIBRUSH_IS_PEN
;
105 // If dwPenStyle is PS_COSMETIC, the width must be set to 1.
106 if ( !(bOldStylePen
) && ((dwPenStyle
& PS_TYPE_MASK
) == PS_COSMETIC
) && ( dwWidth
!= 1) )
109 switch (dwPenStyle
& PS_STYLE_MASK
)
112 pbrushPen
->flAttrs
|= GDIBRUSH_IS_NULL
;
116 pbrushPen
->flAttrs
|= GDIBRUSH_IS_SOLID
;
120 pbrushPen
->flAttrs
|= GDIBRUSH_IS_BITMAP
;
121 pbrushPen
->hbmPattern
= GreCreateBitmap(24, 1, 1, 1, (LPBYTE
)PatternAlternate
);
125 pbrushPen
->flAttrs
|= GDIBRUSH_IS_BITMAP
;
126 pbrushPen
->hbmPattern
= GreCreateBitmap(24, 1, 1, 1, (LPBYTE
)PatternDot
);
130 pbrushPen
->flAttrs
|= GDIBRUSH_IS_BITMAP
;
131 pbrushPen
->hbmPattern
= GreCreateBitmap(24, 1, 1, 1, (LPBYTE
)PatternDash
);
135 pbrushPen
->flAttrs
|= GDIBRUSH_IS_BITMAP
;
136 pbrushPen
->hbmPattern
= GreCreateBitmap(24, 1, 1, 1, (LPBYTE
)PatternDashDot
);
140 pbrushPen
->flAttrs
|= GDIBRUSH_IS_BITMAP
;
141 pbrushPen
->hbmPattern
= GreCreateBitmap(24, 1, 1, 1, (LPBYTE
)PatternDashDotDot
);
145 pbrushPen
->flAttrs
|= (GDIBRUSH_IS_SOLID
|GDIBRUSH_IS_INSIDEFRAME
);
149 if ((dwPenStyle
& PS_TYPE_MASK
) == PS_COSMETIC
)
151 /* FIXME: PS_USERSTYLE workaround */
152 DPRINT1("PS_COSMETIC | PS_USERSTYLE not handled\n");
153 pbrushPen
->flAttrs
|= GDIBRUSH_IS_SOLID
;
159 BOOL has_neg
= FALSE
, all_zero
= TRUE
;
161 for(i
= 0; (i
< dwStyleCount
) && !has_neg
; i
++)
163 has_neg
= has_neg
|| (((INT
)(pStyle
[i
])) < 0);
164 all_zero
= all_zero
&& (pStyle
[i
] == 0);
167 if(all_zero
|| has_neg
)
172 /* FIXME: what style here? */
173 pbrushPen
->flAttrs
|= 0;
177 DPRINT1("IntGdiExtCreatePen unknown penstyle %x\n", dwPenStyle
);
179 PEN_UnlockPen(pbrushPen
);
183 EngSetLastError(ERROR_INVALID_PARAMETER
);
184 pbrushPen
->pStyle
= NULL
;
185 GDIOBJ_vDeleteObject(&pbrushPen
->BaseObject
);
190 IntGdiSetSolidPenColor(HPEN hPen
, COLORREF Color
)
194 pbrPen
= PEN_ShareLockPen(hPen
);
197 if (pbrPen
->flAttrs
& GDIBRUSH_IS_SOLID
)
199 pbrPen
->BrushAttr
.lbColor
= Color
& 0xFFFFFF;
201 PEN_ShareUnlockPen(pbrPen
);
206 PEN_GetObject(PBRUSH pbrushPen
, INT cbCount
, PLOGPEN pBuffer
)
209 PEXTLOGPEN pExtLogPen
;
212 if (pbrushPen
->flAttrs
& GDIBRUSH_IS_OLDSTYLEPEN
)
214 cbRetCount
= sizeof(LOGPEN
);
218 if (cbCount
< cbRetCount
) return 0;
220 if ( (pbrushPen
->ulPenStyle
& PS_STYLE_MASK
) == PS_NULL
&&
221 cbCount
== sizeof(EXTLOGPEN
))
223 pExtLogPen
= (PEXTLOGPEN
)pBuffer
;
224 pExtLogPen
->elpPenStyle
= pbrushPen
->ulPenStyle
;
225 pExtLogPen
->elpWidth
= 0;
226 pExtLogPen
->elpBrushStyle
= pbrushPen
->ulStyle
;
227 pExtLogPen
->elpColor
= pbrushPen
->BrushAttr
.lbColor
;
228 pExtLogPen
->elpHatch
= 0;
229 pExtLogPen
->elpNumEntries
= 0;
230 cbRetCount
= sizeof(EXTLOGPEN
);
234 pLogPen
= (PLOGPEN
)pBuffer
;
235 pLogPen
->lopnWidth
= pbrushPen
->ptPenWidth
;
236 pLogPen
->lopnStyle
= pbrushPen
->ulPenStyle
;
237 pLogPen
->lopnColor
= pbrushPen
->BrushAttr
.lbColor
;
243 // FIXME: Can we trust in dwStyleCount being <= 16?
244 cbRetCount
= sizeof(EXTLOGPEN
) - sizeof(DWORD
) + pbrushPen
->dwStyleCount
* sizeof(DWORD
);
249 if (cbCount
< cbRetCount
) return 0;
250 pExtLogPen
= (PEXTLOGPEN
)pBuffer
;
251 pExtLogPen
->elpPenStyle
= pbrushPen
->ulPenStyle
;
252 pExtLogPen
->elpWidth
= pbrushPen
->ptPenWidth
.x
;
253 pExtLogPen
->elpBrushStyle
= pbrushPen
->ulStyle
;
254 pExtLogPen
->elpColor
= pbrushPen
->BrushAttr
.lbColor
;
255 pExtLogPen
->elpHatch
= (ULONG_PTR
)pbrushPen
->hbmClient
;
256 pExtLogPen
->elpNumEntries
= pbrushPen
->dwStyleCount
;
257 for (i
= 0; i
< pExtLogPen
->elpNumEntries
; i
++)
259 pExtLogPen
->elpStyleEntry
[i
] = pbrushPen
->pStyle
[i
];
268 /* PUBLIC FUNCTIONS ***********************************************************/
277 if ( PenStyle
< PS_SOLID
|| PenStyle
> PS_INSIDEFRAME
)
279 EngSetLastError(ERROR_INVALID_PARAMETER
);
283 return IntGdiExtCreatePen(PenStyle
,
300 IN ULONG ulBrushStyle
,
302 IN ULONG_PTR ulClientHatch
,
303 IN ULONG_PTR ulHatch
,
307 IN BOOL bOldStylePen
,
308 IN OPTIONAL HBRUSH hBrush
)
310 NTSTATUS Status
= STATUS_SUCCESS
;
311 DWORD
* pSafeStyle
= NULL
;
314 if ((int)dwStyleCount
< 0) return 0;
315 if (dwStyleCount
> 16)
317 EngSetLastError(ERROR_INVALID_PARAMETER
);
321 if (dwStyleCount
> 0)
323 pSafeStyle
= ExAllocatePoolWithTag(NonPagedPool
, dwStyleCount
* sizeof(DWORD
), GDITAG_PENSTYLE
);
326 SetLastNtError(ERROR_NOT_ENOUGH_MEMORY
);
331 ProbeForRead(pUnsafeStyle
, dwStyleCount
* sizeof(DWORD
), 1);
332 RtlCopyMemory(pSafeStyle
,
334 dwStyleCount
* sizeof(DWORD
));
336 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
338 Status
= _SEH2_GetExceptionCode();
341 if(!NT_SUCCESS(Status
))
343 SetLastNtError(Status
);
344 ExFreePoolWithTag(pSafeStyle
, GDITAG_PENSTYLE
);
349 if (ulBrushStyle
== BS_PATTERN
)
353 ProbeForRead((PVOID
)ulHatch
, cjDIB
, 1);
355 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
357 Status
= _SEH2_GetExceptionCode();
360 if(!NT_SUCCESS(Status
))
362 SetLastNtError(Status
);
363 if (pSafeStyle
) ExFreePoolWithTag(pSafeStyle
, GDITAG_PENSTYLE
);
368 hPen
= IntGdiExtCreatePen(dwPenStyle
,
380 if (!hPen
&& pSafeStyle
)
382 ExFreePoolWithTag(pSafeStyle
, GDITAG_PENSTYLE
);