4 * Copyright 1993, 1994 Alexandre Julliard
11 #include "debugtools.h"
13 DEFAULT_DEBUG_CHANNEL(gdi
)
16 /***********************************************************************
17 * CreateBrushIndirect16 (GDI.50)
19 HBRUSH16 WINAPI
CreateBrushIndirect16( const LOGBRUSH16
* brush
)
22 HBRUSH16 hbrush
= GDI_AllocObject( sizeof(BRUSHOBJ
), BRUSH_MAGIC
);
23 if (!hbrush
) return 0;
24 brushPtr
= (BRUSHOBJ
*) GDI_HEAP_LOCK( hbrush
);
25 brushPtr
->logbrush
.lbStyle
= brush
->lbStyle
;
26 brushPtr
->logbrush
.lbColor
= brush
->lbColor
;
27 brushPtr
->logbrush
.lbHatch
= brush
->lbHatch
;
28 GDI_HEAP_UNLOCK( hbrush
);
29 TRACE("%04x\n", hbrush
);
34 /***********************************************************************
35 * CreateBrushIndirect32 (GDI32.27)
37 HBRUSH WINAPI
CreateBrushIndirect( const LOGBRUSH
* brush
)
40 HBRUSH hbrush
= GDI_AllocObject( sizeof(BRUSHOBJ
), BRUSH_MAGIC
);
41 if (!hbrush
) return 0;
42 brushPtr
= (BRUSHOBJ
*) GDI_HEAP_LOCK( hbrush
);
43 brushPtr
->logbrush
.lbStyle
= brush
->lbStyle
;
44 brushPtr
->logbrush
.lbColor
= brush
->lbColor
;
45 brushPtr
->logbrush
.lbHatch
= brush
->lbHatch
;
46 GDI_HEAP_UNLOCK( hbrush
);
47 TRACE("%08x\n", hbrush
);
52 /***********************************************************************
53 * CreateHatchBrush16 (GDI.58)
55 HBRUSH16 WINAPI
CreateHatchBrush16( INT16 style
, COLORREF color
)
59 TRACE("%d %06lx\n", style
, color
);
61 logbrush
.lbStyle
= BS_HATCHED
;
62 logbrush
.lbColor
= color
;
63 logbrush
.lbHatch
= style
;
65 if ((style
< 0) || (style
>= NB_HATCH_STYLES
)) return 0;
66 return CreateBrushIndirect( &logbrush
);
70 /***********************************************************************
71 * CreateHatchBrush32 (GDI32.48)
73 HBRUSH WINAPI
CreateHatchBrush( INT style
, COLORREF color
)
77 TRACE("%d %06lx\n", style
, color
);
79 logbrush
.lbStyle
= BS_HATCHED
;
80 logbrush
.lbColor
= color
;
81 logbrush
.lbHatch
= style
;
83 if ((style
< 0) || (style
>= NB_HATCH_STYLES
)) return 0;
84 return CreateBrushIndirect( &logbrush
);
88 /***********************************************************************
89 * CreatePatternBrush16 (GDI.60)
91 HBRUSH16 WINAPI
CreatePatternBrush16( HBITMAP16 hbitmap
)
93 return (HBRUSH16
)CreatePatternBrush( hbitmap
);
97 /***********************************************************************
98 * CreatePatternBrush32 (GDI32.54)
100 HBRUSH WINAPI
CreatePatternBrush( HBITMAP hbitmap
)
102 LOGBRUSH logbrush
= { BS_PATTERN
, 0, 0 };
103 TRACE("%04x\n", hbitmap
);
105 logbrush
.lbHatch
= (INT
)BITMAP_CopyBitmap( hbitmap
);
106 if(!logbrush
.lbHatch
)
109 return CreateBrushIndirect( &logbrush
);
113 /***********************************************************************
114 * CreateDIBPatternBrush16 (GDI.445)
116 HBRUSH16 WINAPI
CreateDIBPatternBrush16( HGLOBAL16 hbitmap
, UINT16 coloruse
)
119 BITMAPINFO
*info
, *newInfo
;
122 TRACE("%04x\n", hbitmap
);
124 logbrush
.lbStyle
= BS_DIBPATTERN
;
125 logbrush
.lbColor
= coloruse
;
126 logbrush
.lbHatch
= 0;
128 /* Make a copy of the bitmap */
130 if (!(info
= (BITMAPINFO
*)GlobalLock16( hbitmap
))) return 0;
132 if (info
->bmiHeader
.biCompression
)
133 size
= info
->bmiHeader
.biSizeImage
;
135 size
= DIB_GetDIBImageBytes(info
->bmiHeader
.biWidth
,
136 info
->bmiHeader
.biHeight
,
137 info
->bmiHeader
.biBitCount
);
138 size
+= DIB_BitmapInfoSize( info
, coloruse
);
140 if (!(logbrush
.lbHatch
= (INT16
)GlobalAlloc16( GMEM_MOVEABLE
, size
)))
142 GlobalUnlock16( hbitmap
);
145 newInfo
= (BITMAPINFO
*) GlobalLock16( (HGLOBAL16
)logbrush
.lbHatch
);
146 memcpy( newInfo
, info
, size
);
147 GlobalUnlock16( (HGLOBAL16
)logbrush
.lbHatch
);
148 GlobalUnlock16( hbitmap
);
149 return CreateBrushIndirect( &logbrush
);
153 /***********************************************************************
154 * CreateDIBPatternBrush32 (GDI32.34)
156 * Create a logical brush which has the pattern specified by the DIB
158 * Function call is for compatability only. CreateDIBPatternBrushPt should be used.
162 * Handle to a logical brush on success, NULL on failure.
167 HBRUSH WINAPI
CreateDIBPatternBrush(
168 HGLOBAL hbitmap
, /* Global object containg BITMAPINFO structure */
169 UINT coloruse
/* Specifies color format, if provided */
173 BITMAPINFO
*info
, *newInfo
;
176 TRACE("%04x\n", hbitmap
);
178 logbrush
.lbStyle
= BS_DIBPATTERN
;
179 logbrush
.lbColor
= coloruse
;
180 logbrush
.lbHatch
= 0;
182 /* Make a copy of the bitmap */
184 if (!(info
= (BITMAPINFO
*)GlobalLock( hbitmap
))) return 0;
186 if (info
->bmiHeader
.biCompression
)
187 size
= info
->bmiHeader
.biSizeImage
;
189 size
= DIB_GetDIBImageBytes(info
->bmiHeader
.biWidth
,
190 info
->bmiHeader
.biHeight
,
191 info
->bmiHeader
.biBitCount
);
192 size
+= DIB_BitmapInfoSize( info
, coloruse
);
194 if (!(logbrush
.lbHatch
= (INT
)GlobalAlloc16( GMEM_MOVEABLE
, size
)))
196 GlobalUnlock16( hbitmap
);
199 newInfo
= (BITMAPINFO
*) GlobalLock16( (HGLOBAL16
)logbrush
.lbHatch
);
200 memcpy( newInfo
, info
, size
);
201 GlobalUnlock16( (HGLOBAL16
)logbrush
.lbHatch
);
202 GlobalUnlock( hbitmap
);
203 return CreateBrushIndirect( &logbrush
);
207 /***********************************************************************
208 * CreateDIBPatternBrushPt (GDI32.35)
210 * Create a logical brush which has the pattern specified by the DIB
214 * Handle to a logical brush on success, NULL on failure.
219 HBRUSH WINAPI
CreateDIBPatternBrushPt(
220 const void* data
, /* Pointer to a BITMAPINFO structure followed by more data */
221 UINT coloruse
/* Specifies color format, if provided */
224 BITMAPINFO
*info
=(BITMAPINFO
*)data
;
229 TRACE("%p %ldx%ld %dbpp\n", info
, info
->bmiHeader
.biWidth
,
230 info
->bmiHeader
.biHeight
, info
->bmiHeader
.biBitCount
);
232 logbrush
.lbStyle
= BS_DIBPATTERN
;
233 logbrush
.lbColor
= coloruse
;
234 logbrush
.lbHatch
= 0;
236 /* Make a copy of the bitmap */
239 if (info
->bmiHeader
.biCompression
)
240 size
= info
->bmiHeader
.biSizeImage
;
242 size
= DIB_GetDIBImageBytes(info
->bmiHeader
.biWidth
,
243 info
->bmiHeader
.biHeight
,
244 info
->bmiHeader
.biBitCount
);
245 size
+= DIB_BitmapInfoSize( info
, coloruse
);
247 if (!(logbrush
.lbHatch
= (INT
)GlobalAlloc16( GMEM_MOVEABLE
, size
)))
251 newInfo
= (BITMAPINFO
*) GlobalLock16( (HGLOBAL16
)logbrush
.lbHatch
);
252 memcpy( newInfo
, info
, size
);
253 GlobalUnlock16( (HGLOBAL16
)logbrush
.lbHatch
);
254 return CreateBrushIndirect( &logbrush
);
258 /***********************************************************************
259 * CreateSolidBrush (GDI.66)
261 HBRUSH16 WINAPI
CreateSolidBrush16( COLORREF color
)
265 TRACE("%06lx\n", color
);
267 logbrush
.lbStyle
= BS_SOLID
;
268 logbrush
.lbColor
= color
;
269 logbrush
.lbHatch
= 0;
271 return CreateBrushIndirect( &logbrush
);
275 /***********************************************************************
276 * CreateSolidBrush32 (GDI32.64)
278 HBRUSH WINAPI
CreateSolidBrush( COLORREF color
)
282 TRACE("%06lx\n", color
);
284 logbrush
.lbStyle
= BS_SOLID
;
285 logbrush
.lbColor
= color
;
286 logbrush
.lbHatch
= 0;
288 return CreateBrushIndirect( &logbrush
);
292 /***********************************************************************
293 * SetBrushOrg (GDI.148)
295 DWORD WINAPI
SetBrushOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
298 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
299 if (!dc
) return FALSE
;
300 retval
= dc
->w
.brushOrgX
| (dc
->w
.brushOrgY
<< 16);
307 /***********************************************************************
308 * SetBrushOrgEx (GDI32.308)
310 BOOL WINAPI
SetBrushOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT oldorg
)
312 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
314 if (!dc
) return FALSE
;
317 oldorg
->x
= dc
->w
.brushOrgX
;
318 oldorg
->y
= dc
->w
.brushOrgY
;
325 /***********************************************************************
326 * FixBrushOrgEx (GDI32.102)
327 * SDK says discontinued, but in Win95 GDI32 this is the same as SetBrushOrgEx
329 BOOL WINAPI
FixBrushOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT oldorg
)
331 return SetBrushOrgEx(hdc
,x
,y
,oldorg
);
335 /***********************************************************************
338 BOOL
BRUSH_DeleteObject( HBRUSH16 hbrush
, BRUSHOBJ
* brush
)
340 switch(brush
->logbrush
.lbStyle
)
343 DeleteObject( (HGDIOBJ
)brush
->logbrush
.lbHatch
);
346 GlobalFree16( (HGLOBAL16
)brush
->logbrush
.lbHatch
);
349 return GDI_FreeObject( hbrush
);
353 /***********************************************************************
356 INT16
BRUSH_GetObject16( BRUSHOBJ
* brush
, INT16 count
, LPSTR buffer
)
360 logbrush
.lbStyle
= brush
->logbrush
.lbStyle
;
361 logbrush
.lbColor
= brush
->logbrush
.lbColor
;
362 logbrush
.lbHatch
= brush
->logbrush
.lbHatch
;
363 if (count
> sizeof(logbrush
)) count
= sizeof(logbrush
);
364 memcpy( buffer
, &logbrush
, count
);
369 /***********************************************************************
372 INT
BRUSH_GetObject( BRUSHOBJ
* brush
, INT count
, LPSTR buffer
)
374 if (count
> sizeof(brush
->logbrush
)) count
= sizeof(brush
->logbrush
);
375 memcpy( buffer
, &brush
->logbrush
, count
);
380 /***********************************************************************
381 * SetSolidBrush16 (GDI.604)
383 * If hBrush is a solid brush, change it's color to newColor.
386 * TRUE on success, FALSE on failure.
387 * FIXME: not yet implemented!
389 BOOL16 WINAPI
SetSolidBrush16(HBRUSH16 hBrush
, COLORREF newColor
)
391 FIXME("(hBrush %04x, newColor %04x): stub!\n", hBrush
, (int)newColor
);