ReactOS 0.4.15-dev-7660-g0086d05
brush.c
Go to the documentation of this file.
1#include <precomp.h>
2
3#define NDEBUG
4#include <debug.h>
5
6
7
8/*
9 * @implemented
10 */
11HPEN
15 CONST LOGBRUSH *lplb,
16 DWORD dwStyleCount,
17 CONST DWORD *lpStyle)
18{
19 PVOID lpPackedDIB = NULL;
20 HPEN hPen = NULL;
21 PBITMAPINFO pConvertedInfo = NULL;
22 UINT ConvertedInfoSize = 0, lbStyle;
23 BOOL Hit = FALSE;
24
25 if ((dwPenStyle & PS_STYLE_MASK) == PS_USERSTYLE)
26 {
27 if(!lpStyle)
28 {
30 return 0;
31 }
32 } // This is an enhancement and prevents a call to kernel space.
33 else if ((dwPenStyle & PS_STYLE_MASK) == PS_INSIDEFRAME &&
34 (dwPenStyle & PS_TYPE_MASK) != PS_GEOMETRIC)
35 {
37 return 0;
38 }
39 else if ((dwPenStyle & PS_STYLE_MASK) == PS_ALTERNATE &&
40 (dwPenStyle & PS_TYPE_MASK) != PS_COSMETIC)
41 {
43 return 0;
44 }
45 else
46 {
47 if (dwStyleCount || lpStyle)
48 {
50 return 0;
51 }
52 }
53
54 lbStyle = lplb->lbStyle;
55
56 if (lplb->lbStyle > BS_HATCHED)
57 {
58 if (lplb->lbStyle == BS_PATTERN)
59 {
60 pConvertedInfo = (PBITMAPINFO)lplb->lbHatch;
61 if (!pConvertedInfo) return 0;
62 }
63 else
64 {
65 if ((lplb->lbStyle == BS_DIBPATTERN) || (lplb->lbStyle == BS_DIBPATTERNPT))
66 {
67 if (lplb->lbStyle == BS_DIBPATTERN)
68 {
69 lbStyle = BS_DIBPATTERNPT;
70 lpPackedDIB = GlobalLock((HGLOBAL)lplb->lbHatch);
71 if (lpPackedDIB == NULL) return 0;
72 }
73 pConvertedInfo = ConvertBitmapInfo((PBITMAPINFO)lpPackedDIB,
74 lplb->lbColor,
75 &ConvertedInfoSize,
76 TRUE);
77 Hit = TRUE; // We converted DIB.
78 }
79 else
80 pConvertedInfo = (PBITMAPINFO)lpStyle;
81 }
82 }
83 else
84 pConvertedInfo = (PBITMAPINFO)lplb->lbHatch;
85
86
87 hPen = NtGdiExtCreatePen(dwPenStyle,
88 dwWidth,
89 lbStyle,
90 lplb->lbColor,
91 lplb->lbHatch,
92 (ULONG_PTR)pConvertedInfo,
93 dwStyleCount,
94 (PULONG)lpStyle,
95 ConvertedInfoSize,
96 FALSE,
97 NULL);
98
99
100 if (lplb->lbStyle == BS_DIBPATTERN) GlobalUnlock((HGLOBAL)lplb->lbHatch);
101
102 if (Hit)
103 {
104 if ((PBITMAPINFO)lpPackedDIB != pConvertedInfo)
105 RtlFreeHeap(RtlGetProcessHeap(), 0, pConvertedInfo);
106 }
107 return hPen;
108}
109
110/*
111 * @implemented
112 */
113HBRUSH WINAPI
115 HGLOBAL hglbDIBPacked,
116 UINT fuColorSpec)
117{
118 PVOID lpPackedDIB;
119 HBRUSH hBrush = NULL;
120 PBITMAPINFO pConvertedInfo;
121 UINT ConvertedInfoSize;
122
123 lpPackedDIB = GlobalLock(hglbDIBPacked);
124 if (lpPackedDIB == NULL)
125 return 0;
126
127 pConvertedInfo = ConvertBitmapInfo((PBITMAPINFO)lpPackedDIB, fuColorSpec,
128 &ConvertedInfoSize, TRUE);
129 if (pConvertedInfo)
130 {
131 hBrush = NtGdiCreateDIBBrush(pConvertedInfo, fuColorSpec,
132 ConvertedInfoSize, FALSE, FALSE, lpPackedDIB);
133 if ((PBITMAPINFO)lpPackedDIB != pConvertedInfo)
134 RtlFreeHeap(RtlGetProcessHeap(), 0, pConvertedInfo);
135 }
136
137 GlobalUnlock(hglbDIBPacked);
138
139 return hBrush;
140}
141
142/*
143 * @implemented
144 */
145HBRUSH WINAPI
147 CONST VOID *lpPackedDIB,
148 UINT fuColorSpec)
149{
150 HBRUSH hBrush = NULL;
151 PBITMAPINFO pConvertedInfo;
152 UINT ConvertedInfoSize;
153
154 if (lpPackedDIB == NULL)
155 return 0;
156
157 pConvertedInfo = ConvertBitmapInfo((PBITMAPINFO)lpPackedDIB, fuColorSpec,
158 &ConvertedInfoSize, TRUE);
159 if (pConvertedInfo)
160 {
161 hBrush = NtGdiCreateDIBBrush(pConvertedInfo, fuColorSpec,
162 ConvertedInfoSize, FALSE, FALSE, (PVOID)lpPackedDIB);
163 if ((PBITMAPINFO)lpPackedDIB != pConvertedInfo)
164 RtlFreeHeap(RtlGetProcessHeap(), 0, pConvertedInfo);
165 }
166
167 return hBrush;
168}
169
170/*
171 * @implemented
172 */
173HBRUSH
174WINAPI
176 COLORREF clrref)
177{
178 return NtGdiCreateHatchBrushInternal(fnStyle, clrref, FALSE);
179}
180
181/*
182 * @implemented
183 */
184HBRUSH
185WINAPI
187{
189}
190
191/*
192 * @implemented
193 */
194HBRUSH
195WINAPI
197{
198 /* Call Server-Side API */
199 return NtGdiCreateSolidBrush(crColor, NULL);
200}
201
202/*
203 * @implemented
204 */
205HBRUSH WINAPI
207 CONST LOGBRUSH *LogBrush)
208{
209 HBRUSH hBrush;
210
211 switch (LogBrush->lbStyle)
212 {
213 case BS_DIBPATTERN:
214 hBrush = CreateDIBPatternBrush((HGLOBAL)LogBrush->lbHatch,
215 LogBrush->lbColor);
216 break;
217
218 case BS_DIBPATTERNPT:
219 hBrush = CreateDIBPatternBrushPt((PVOID)LogBrush->lbHatch,
220 LogBrush->lbColor);
221 break;
222
223 case BS_PATTERN:
224 hBrush = NtGdiCreatePatternBrushInternal((HBITMAP)LogBrush->lbHatch,
225 FALSE,
226 FALSE);
227 break;
228
229 case BS_PATTERN8X8:
230 hBrush = NtGdiCreatePatternBrushInternal((HBITMAP)LogBrush->lbHatch,
231 FALSE,
232 TRUE);
233 break;
234
235 case BS_SOLID:
236/* hBrush = hGetPEBHandle(hctBrushHandle, LogBrush->lbColor);
237 if (!hBrush)*/
238 hBrush = NtGdiCreateSolidBrush(LogBrush->lbColor, 0);
239 break;
240
241 case BS_HATCHED:
242 hBrush = NtGdiCreateHatchBrushInternal(LogBrush->lbHatch,
243 LogBrush->lbColor,
244 FALSE);
245 break;
246
247 case BS_NULL:
249 break;
250
251 default:
253 hBrush = NULL;
254 break;
255 }
256
257 return hBrush;
258}
259
260/*
261 * @implemented
262 *
263 */
264BOOL
265WINAPI
267{
268 PDC_ATTR Dc_Attr;
269
270 if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return FALSE;
271 if (pt)
272 {
273 pt->x = Dc_Attr->ptlBrushOrigin.x;
274 pt->y = Dc_Attr->ptlBrushOrigin.y;
275 }
276 return TRUE;
277}
278
279/*
280 * @implemented
281 */
282BOOL
283WINAPI
285 int nXOrg,
286 int nYOrg,
287 LPPOINT lppt)
288{
289 PDC_ATTR Dc_Attr;
290#if 0
291// Handle something other than a normal dc object.
293 {
294 PLDC pLDC = GdiGetLDC(hdc);
295 if ( (pLDC == NULL) || (GDI_HANDLE_GET_TYPE(hdc) == GDI_OBJECT_TYPE_METADC))
296 {
298 return FALSE;
299 }
300 if (pLDC->iType == LDC_EMFLDC)
301 {
302 return EMFDRV_SetBrushOrg(hdc, nXOrg, nYOrg); // ReactOS only.
303 }
304 return FALSE;
305 }
306#endif
308 {
309 PGDIBSSETBRHORG pgSBO;
310
311 /* Does the caller want the current brush origin to be returned? */
312 if (lppt)
313 {
314 lppt->x = Dc_Attr->ptlBrushOrigin.x;
315 lppt->y = Dc_Attr->ptlBrushOrigin.y;
316 }
317
318 /* Check if we have nothing to do */
319 if ((nXOrg == Dc_Attr->ptlBrushOrigin.x) &&
320 (nYOrg == Dc_Attr->ptlBrushOrigin.y))
321 return TRUE;
322
323 /* Allocate a batch command buffer */
325 if (pgSBO != NULL)
326 {
327 /* Set current brush origin in the DC attribute */
328 Dc_Attr->ptlBrushOrigin.x = nXOrg;
329 Dc_Attr->ptlBrushOrigin.y = nYOrg;
330
331 /* Setup the GDI batch command */
332 pgSBO->ptlBrushOrigin = Dc_Attr->ptlBrushOrigin;
333
334 return TRUE;
335 }
336 }
337
338 /* Fall back to the slower kernel path */
339 return NtGdiSetBrushOrg(hdc, nXOrg, nYOrg, lppt);
340}
341
342/*
343 * @implemented
344 */
345DWORD
346WINAPI
348{
349 if ( GDI_HANDLE_IS_STOCKOBJ(hbr) )
350 {
351 return SC_BB_STOCKOBJ;
352 }
353 return 0;
354}
355
356/*
357 * @implemented
358 */
359HBRUSH
360WINAPI
362{
363 if ( dwFlags & ~SC_BB_STOCKOBJ )
364 {
365 return NULL;
366 }
368}
369
370/*
371 * @implemented
372 */
373HBRUSH
374WINAPI
376{
377 if ( dwFlags & ~SC_BB_STOCKOBJ )
378 {
379 return NULL;
380 }
382}
383
384/*
385 * @implemented
386 */
387BOOL
388WINAPI
390{
391 BOOL retValue = TRUE;
392 /*
393 Win 2k Graphics API, Black Book. by coriolis.com
394 Page 62, Note that Steps 3, 5, and 6 are not required for Windows NT(tm)
395 and Windows 2000(tm).
396
397 Step 5. UnrealizeObject(hTrackBrush);
398 */
399 /*
400 msdn.microsoft.com,
401 "Windows 2000/XP: If hgdiobj is a brush, UnrealizeObject does nothing,
402 and the function returns TRUE. Use SetBrushOrgEx to set the origin of
403 a brush."
404 */
406 {
407 retValue = NtGdiUnrealizeObject(hgdiobj);
408 }
409
410 return retValue;
411}
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
HBITMAP hbmp
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static const WCHAR dwWidth[]
Definition: provider.c:62
#define APIENTRY
Definition: api.h:79
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
#define pt(x, y)
Definition: drawing.c:79
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
FORCEINLINE PVOID GdiAllocBatchCommand(HDC hdc, USHORT Cmd)
Definition: gdi32p.h:381
LPBITMAPINFO WINAPI ConvertBitmapInfo(CONST BITMAPINFO *BitmapInfo, UINT ColorSpec, UINT *BitmapInfoSize, BOOL FollowedByData)
Definition: utils.c:178
PLDC FASTCALL GdiGetLDC(HDC hDC)
Definition: misc.c:785
#define GDI_OBJECT_TYPE_DC
Definition: gdi.h:46
#define GDI_OBJECT_TYPE_BRUSH
Definition: gdi.h:52
#define GDI_HANDLE_GET_TYPE(h)
Definition: gdi.h:31
#define GDI_OBJECT_TYPE_METADC
Definition: gdi.h:57
#define GDI_HANDLE_IS_STOCKOBJ(h)
Definition: gdi.h:37
#define LDC_EMFLDC
Definition: gdi_private.h:105
PVOID GdiGetHandleUserData(_In_ HGDIOBJ hobj)
Definition: gditools.c:68
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
if(dx< 0)
Definition: linetemp.h:194
HDC hdc
Definition: main.c:9
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:92
unsigned int UINT
Definition: ndis.h:50
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
__kernel_entry W32KAPI HBRUSH APIENTRY NtGdiClearBrushAttributes(_In_ HBRUSH hbm, _In_ DWORD dwFlags)
Definition: brush.cpp:579
__kernel_entry W32KAPI HBRUSH APIENTRY NtGdiCreateDIBBrush(_In_reads_bytes_(cj) PVOID pv, _In_ FLONG fl, _In_ UINT cj, _In_ BOOL b8X8, _In_ BOOL bPen, _In_ PVOID pClient)
Definition: brush.cpp:423
__kernel_entry W32KAPI BOOL APIENTRY NtGdiUnrealizeObject(_In_ HANDLE h)
__kernel_entry W32KAPI HANDLE APIENTRY NtGdiGetStockObject(_In_ INT iObject)
__kernel_entry W32KAPI HBRUSH APIENTRY NtGdiCreateHatchBrushInternal(_In_ ULONG ulStyle, _In_ COLORREF clrr, _In_ BOOL bPen)
Definition: brush.cpp:357
__kernel_entry W32KAPI HBRUSH APIENTRY NtGdiCreateSolidBrush(_In_ COLORREF cr, _In_opt_ HBRUSH hbr)
Definition: brush.cpp:341
__kernel_entry W32KAPI HPEN APIENTRY NtGdiExtCreatePen(_In_ ULONG flPenStyle, _In_ ULONG ulWidth, _In_ ULONG iBrushStyle, _In_ ULONG ulColor, _In_ ULONG_PTR lClientHatch, _In_ ULONG_PTR lHatch, _In_ ULONG cstyle, _In_reads_opt_(cstyle) PULONG pulStyle, _In_ ULONG cjDIB, _In_ BOOL bOldStylePen, _In_opt_ HBRUSH hbrush)
__kernel_entry W32KAPI HBRUSH APIENTRY NtGdiSetBrushAttributes(_In_ HBRUSH hbm, _In_ DWORD dwFlags)
Definition: brush.cpp:553
__kernel_entry W32KAPI HBRUSH APIENTRY NtGdiCreatePatternBrushInternal(_In_ HBITMAP hbm, _In_ BOOL bPen, _In_ BOOL b8X8)
Definition: brush.cpp:391
#define SC_BB_STOCKOBJ
Definition: ntgdihdl.h:199
@ GdiBCSetBrushOrg
Definition: ntgdityp.h:90
#define CONST
Definition: pedump.c:81
POINTL ptlBrushOrigin
Definition: ntgdihdl.h:349
POINTL ptlBrushOrigin
Definition: ntgdityp.h:546
Definition: ntgdihdl.h:263
INT iType
Definition: ntgdihdl.h:266
LONG y
Definition: windef.h:330
LONG x
Definition: windef.h:329
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
uint32_t * PULONG
Definition: typedefs.h:59
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
BOOL WINAPI GetBrushOrgEx(HDC hdc, LPPOINT pt)
Definition: brush.c:266
HBRUSH WINAPI SetBrushAttributes(HBRUSH hbm, DWORD dwFlags)
Definition: brush.c:361
BOOL WINAPI UnrealizeObject(HGDIOBJ hgdiobj)
Definition: brush.c:389
HBRUSH WINAPI ClearBrushAttributes(HBRUSH hbm, DWORD dwFlags)
Definition: brush.c:375
HBRUSH WINAPI CreateDIBPatternBrush(HGLOBAL hglbDIBPacked, UINT fuColorSpec)
Definition: brush.c:114
DWORD WINAPI GetBrushAttributes(HBRUSH hbr)
Definition: brush.c:347
HPEN APIENTRY ExtCreatePen(DWORD dwPenStyle, DWORD dwWidth, CONST LOGBRUSH *lplb, DWORD dwStyleCount, CONST DWORD *lpStyle)
Definition: brush.c:13
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
DWORD COLORREF
Definition: windef.h:300
#define WINAPI
Definition: msvc.h:6
HBRUSH WINAPI CreateBrushIndirect(_In_ const LOGBRUSH *plb)
#define BS_PATTERN8X8
Definition: wingdi.h:1094
#define PS_ALTERNATE
Definition: wingdi.h:585
#define BS_HATCHED
Definition: wingdi.h:1089
BOOL WINAPI SetBrushOrgEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPPOINT)
HBRUSH WINAPI CreateHatchBrush(_In_ int, _In_ COLORREF)
#define BS_PATTERN
Definition: wingdi.h:1090
#define PS_COSMETIC
Definition: wingdi.h:584
#define BS_DIBPATTERNPT
Definition: wingdi.h:1093
#define PS_STYLE_MASK
Definition: wingdi.h:601
#define PS_GEOMETRIC
Definition: wingdi.h:583
#define BS_DIBPATTERN
Definition: wingdi.h:1092
#define PS_USERSTYLE
Definition: wingdi.h:592
#define NULL_BRUSH
Definition: wingdi.h:901
#define BS_NULL
Definition: wingdi.h:1087
struct tagBITMAPINFO * PBITMAPINFO
HBRUSH WINAPI CreateDIBPatternBrushPt(_In_ const VOID *pvPackedDIB, _In_ UINT uUsage)
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
#define PS_INSIDEFRAME
Definition: wingdi.h:593
#define BS_SOLID
Definition: wingdi.h:1086
#define PS_TYPE_MASK
Definition: wingdi.h:603
HBRUSH WINAPI CreatePatternBrush(_In_ HBITMAP)