ReactOS 0.4.15-dev-8102-g108db8f
brush.c File Reference
#include <precomp.h>
#include <debug.h>
Include dependency graph for brush.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

HPEN APIENTRY ExtCreatePen (DWORD dwPenStyle, DWORD dwWidth, CONST LOGBRUSH *lplb, DWORD dwStyleCount, CONST DWORD *lpStyle)
 
HBRUSH WINAPI CreateDIBPatternBrush (HGLOBAL hglbDIBPacked, UINT fuColorSpec)
 
HBRUSH WINAPI CreateDIBPatternBrushPt (CONST VOID *lpPackedDIB, UINT fuColorSpec)
 
HBRUSH WINAPI CreateHatchBrush (INT fnStyle, COLORREF clrref)
 
HBRUSH WINAPI CreatePatternBrush (HBITMAP hbmp)
 
HBRUSH WINAPI CreateSolidBrush (IN COLORREF crColor)
 
HBRUSH WINAPI CreateBrushIndirect (CONST LOGBRUSH *LogBrush)
 
BOOL WINAPI GetBrushOrgEx (HDC hdc, LPPOINT pt)
 
BOOL WINAPI SetBrushOrgEx (HDC hdc, int nXOrg, int nYOrg, LPPOINT lppt)
 
DWORD WINAPI GetBrushAttributes (HBRUSH hbr)
 
HBRUSH WINAPI SetBrushAttributes (HBRUSH hbm, DWORD dwFlags)
 
HBRUSH WINAPI ClearBrushAttributes (HBRUSH hbm, DWORD dwFlags)
 
BOOL WINAPI UnrealizeObject (HGDIOBJ hgdiobj)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 3 of file brush.c.

Function Documentation

◆ ClearBrushAttributes()

HBRUSH WINAPI ClearBrushAttributes ( HBRUSH  hbm,
DWORD  dwFlags 
)

Definition at line 375 of file brush.c.

376{
377 if ( dwFlags & ~SC_BB_STOCKOBJ )
378 {
379 return NULL;
380 }
382}
#define NULL
Definition: types.h:112
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
__kernel_entry W32KAPI HBRUSH APIENTRY NtGdiClearBrushAttributes(_In_ HBRUSH hbm, _In_ DWORD dwFlags)
Definition: brush.cpp:579
#define SC_BB_STOCKOBJ
Definition: ntgdihdl.h:199
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176

◆ CreateBrushIndirect()

HBRUSH WINAPI CreateBrushIndirect ( CONST LOGBRUSH LogBrush)

Definition at line 206 of file brush.c.

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}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
static HBITMAP
Definition: button.c:44
__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 HBRUSH APIENTRY NtGdiCreatePatternBrushInternal(_In_ HBITMAP hbm, _In_ BOOL bPen, _In_ BOOL b8X8)
Definition: brush.cpp:391
HBRUSH WINAPI CreateDIBPatternBrush(HGLOBAL hglbDIBPacked, UINT fuColorSpec)
Definition: brush.c:114
#define BS_PATTERN8X8
Definition: wingdi.h:1094
#define BS_HATCHED
Definition: wingdi.h:1089
#define BS_PATTERN
Definition: wingdi.h:1090
#define BS_DIBPATTERNPT
Definition: wingdi.h:1093
#define BS_DIBPATTERN
Definition: wingdi.h:1092
#define NULL_BRUSH
Definition: wingdi.h:901
#define BS_NULL
Definition: wingdi.h:1087
HBRUSH WINAPI CreateDIBPatternBrushPt(_In_ const VOID *pvPackedDIB, _In_ UINT uUsage)
#define BS_SOLID
Definition: wingdi.h:1086

◆ CreateDIBPatternBrush()

HBRUSH WINAPI CreateDIBPatternBrush ( HGLOBAL  hglbDIBPacked,
UINT  fuColorSpec 
)

Definition at line 114 of file brush.c.

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}
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
LPBITMAPINFO WINAPI ConvertBitmapInfo(CONST BITMAPINFO *BitmapInfo, UINT ColorSpec, UINT *BitmapInfoSize, BOOL FollowedByData)
Definition: utils.c:178
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
unsigned int UINT
Definition: ndis.h:50
__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

Referenced by CreateBrushIndirect().

◆ CreateDIBPatternBrushPt()

HBRUSH WINAPI CreateDIBPatternBrushPt ( CONST VOID lpPackedDIB,
UINT  fuColorSpec 
)

Definition at line 146 of file brush.c.

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}

◆ CreateHatchBrush()

HBRUSH WINAPI CreateHatchBrush ( INT  fnStyle,
COLORREF  clrref 
)

Definition at line 175 of file brush.c.

177{
178 return NtGdiCreateHatchBrushInternal(fnStyle, clrref, FALSE);
179}

◆ CreatePatternBrush()

HBRUSH WINAPI CreatePatternBrush ( HBITMAP  hbmp)

Definition at line 186 of file brush.c.

187{
189}
HBITMAP hbmp

◆ CreateSolidBrush()

HBRUSH WINAPI CreateSolidBrush ( IN COLORREF  crColor)

Definition at line 196 of file brush.c.

197{
198 /* Call Server-Side API */
199 return NtGdiCreateSolidBrush(crColor, NULL);
200}

◆ ExtCreatePen()

HPEN APIENTRY ExtCreatePen ( DWORD  dwPenStyle,
DWORD  dwWidth,
CONST LOGBRUSH lplb,
DWORD  dwStyleCount,
CONST DWORD lpStyle 
)

Definition at line 13 of file brush.c.

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}
static const WCHAR dwWidth[]
Definition: provider.c:62
unsigned int BOOL
Definition: ntddk_ex.h:94
if(dx< 0)
Definition: linetemp.h:194
__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)
uint32_t * PULONG
Definition: typedefs.h:59
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define PS_ALTERNATE
Definition: wingdi.h:585
#define PS_COSMETIC
Definition: wingdi.h:584
#define PS_STYLE_MASK
Definition: wingdi.h:601
#define PS_GEOMETRIC
Definition: wingdi.h:583
#define PS_USERSTYLE
Definition: wingdi.h:592
struct tagBITMAPINFO * PBITMAPINFO
#define PS_INSIDEFRAME
Definition: wingdi.h:593
#define PS_TYPE_MASK
Definition: wingdi.h:603

◆ GetBrushAttributes()

DWORD WINAPI GetBrushAttributes ( HBRUSH  hbr)

Definition at line 347 of file brush.c.

348{
349 if ( GDI_HANDLE_IS_STOCKOBJ(hbr) )
350 {
351 return SC_BB_STOCKOBJ;
352 }
353 return 0;
354}
#define GDI_HANDLE_IS_STOCKOBJ(h)
Definition: gdi.h:37

◆ GetBrushOrgEx()

BOOL WINAPI GetBrushOrgEx ( HDC  hdc,
LPPOINT  pt 
)

Definition at line 266 of file brush.c.

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}
#define pt(x, y)
Definition: drawing.c:79
#define GDI_OBJECT_TYPE_DC
Definition: gdi.h:46
PVOID GdiGetHandleUserData(_In_ HGDIOBJ hobj)
Definition: gditools.c:68
HDC hdc
Definition: main.c:9

◆ SetBrushAttributes()

HBRUSH WINAPI SetBrushAttributes ( HBRUSH  hbm,
DWORD  dwFlags 
)

Definition at line 361 of file brush.c.

362{
363 if ( dwFlags & ~SC_BB_STOCKOBJ )
364 {
365 return NULL;
366 }
368}
__kernel_entry W32KAPI HBRUSH APIENTRY NtGdiSetBrushAttributes(_In_ HBRUSH hbm, _In_ DWORD dwFlags)
Definition: brush.cpp:553

◆ SetBrushOrgEx()

BOOL WINAPI SetBrushOrgEx ( HDC  hdc,
int  nXOrg,
int  nYOrg,
LPPOINT  lppt 
)

Definition at line 284 of file brush.c.

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}
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
FORCEINLINE PVOID GdiAllocBatchCommand(HDC hdc, USHORT Cmd)
Definition: gdi32p.h:381
PLDC FASTCALL GdiGetLDC(HDC hDC)
Definition: misc.c:785
#define GDI_HANDLE_GET_TYPE(h)
Definition: gdi.h:31
#define GDI_OBJECT_TYPE_METADC
Definition: gdi.h:57
#define LDC_EMFLDC
Definition: gdi_private.h:105
@ GdiBCSetBrushOrg
Definition: ntgdityp.h:90
POINTL ptlBrushOrigin
Definition: ntgdityp.h:546
Definition: ntgdihdl.h:263
INT iType
Definition: ntgdihdl.h:266
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48

◆ UnrealizeObject()

BOOL WINAPI UnrealizeObject ( HGDIOBJ  hgdiobj)

Definition at line 389 of file brush.c.

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}
#define GDI_OBJECT_TYPE_BRUSH
Definition: gdi.h:52
__kernel_entry W32KAPI BOOL APIENTRY NtGdiUnrealizeObject(_In_ HANDLE h)