4 * Copyright 1993, 1994 Alexandre Julliard
11 #include "debugtools.h"
13 DEFAULT_DEBUG_CHANNEL(gdi
)
15 static HGLOBAL16
dib_copy(BITMAPINFO
*info
, UINT coloruse
)
21 if (info
->bmiHeader
.biCompression
)
22 size
= info
->bmiHeader
.biSizeImage
;
24 size
= DIB_GetDIBImageBytes(info
->bmiHeader
.biWidth
,
25 info
->bmiHeader
.biHeight
,
26 info
->bmiHeader
.biBitCount
);
27 size
+= DIB_BitmapInfoSize( info
, coloruse
);
29 if (!(hmem
= GlobalAlloc16( GMEM_MOVEABLE
, size
)))
33 newInfo
= (BITMAPINFO
*) GlobalLock16( hmem
);
34 memcpy( newInfo
, info
, size
);
35 GlobalUnlock16( hmem
);
41 static BOOL
create_brush_indirect(BRUSHOBJ
*brushPtr
, BOOL v16
)
43 LOGBRUSH
*brush
= &brushPtr
->logbrush
;
45 switch (brush
->lbStyle
)
48 brush
->lbStyle
= BS_PATTERN
;
50 brush
->lbHatch
= (LONG
)BITMAP_CopyBitmap( (HBITMAP
) brush
->lbHatch
);
56 brush
->lbStyle
= BS_DIBPATTERN
;
57 brush
->lbHatch
= (LONG
)dib_copy( (BITMAPINFO
*) brush
->lbHatch
,
63 case BS_DIBPATTERN8X8
:
67 HGLOBAL h
= brush
->lbHatch
;
69 brush
->lbStyle
= BS_DIBPATTERN
;
72 if (!(bmi
= (BITMAPINFO
*)GlobalLock16( h
)))
77 if (!(bmi
= (BITMAPINFO
*)GlobalLock( h
)))
81 brush
->lbHatch
= dib_copy( bmi
, brush
->lbColor
);
83 if (v16
) GlobalUnlock16( h
);
84 else GlobalUnlock( h
);
93 if( brush
->lbStyle
<= BS_MONOPATTERN
)
101 /***********************************************************************
102 * CreateBrushIndirect16 (GDI.50)
104 HBRUSH16 WINAPI
CreateBrushIndirect16( const LOGBRUSH16
* brush
)
108 HBRUSH16 hbrush
= GDI_AllocObject( sizeof(BRUSHOBJ
), BRUSH_MAGIC
);
109 if (!hbrush
) return 0;
110 brushPtr
= (BRUSHOBJ
*) GDI_HEAP_LOCK( hbrush
);
111 brushPtr
->logbrush
.lbStyle
= brush
->lbStyle
;
112 brushPtr
->logbrush
.lbColor
= brush
->lbColor
;
113 brushPtr
->logbrush
.lbHatch
= brush
->lbHatch
;
114 success
= create_brush_indirect(brushPtr
, TRUE
);
115 GDI_HEAP_UNLOCK( hbrush
);
118 GDI_FreeObject(hbrush
);
121 TRACE("%04x\n", hbrush
);
126 /***********************************************************************
127 * CreateBrushIndirect32 (GDI32.27)
130 * As for Windows 95 and Windows 98:
131 * Creating brushes from bitmaps or DIBs larger than 8x8 pixels
132 * is not supported. If a larger bitmap is given, only a portion
133 * of the bitmap is used.
135 HBRUSH WINAPI
CreateBrushIndirect( const LOGBRUSH
* brush
)
139 HBRUSH hbrush
= GDI_AllocObject( sizeof(BRUSHOBJ
), BRUSH_MAGIC
);
140 if (!hbrush
) return 0;
141 brushPtr
= (BRUSHOBJ
*) GDI_HEAP_LOCK( hbrush
);
142 brushPtr
->logbrush
.lbStyle
= brush
->lbStyle
;
143 brushPtr
->logbrush
.lbColor
= brush
->lbColor
;
144 brushPtr
->logbrush
.lbHatch
= brush
->lbHatch
;
145 success
= create_brush_indirect(brushPtr
, FALSE
);
146 GDI_HEAP_UNLOCK( hbrush
);
149 GDI_FreeObject(hbrush
);
152 TRACE("%08x\n", hbrush
);
157 /***********************************************************************
158 * CreateHatchBrush16 (GDI.58)
160 HBRUSH16 WINAPI
CreateHatchBrush16( INT16 style
, COLORREF color
)
162 return CreateHatchBrush( style
, color
);
166 /***********************************************************************
167 * CreateHatchBrush32 (GDI32.48)
169 HBRUSH WINAPI
CreateHatchBrush( INT style
, COLORREF color
)
173 TRACE("%d %06lx\n", style
, color
);
175 logbrush
.lbStyle
= BS_HATCHED
;
176 logbrush
.lbColor
= color
;
177 logbrush
.lbHatch
= style
;
179 return CreateBrushIndirect( &logbrush
);
183 /***********************************************************************
184 * CreatePatternBrush16 (GDI.60)
186 HBRUSH16 WINAPI
CreatePatternBrush16( HBITMAP16 hbitmap
)
188 return (HBRUSH16
)CreatePatternBrush( hbitmap
);
192 /***********************************************************************
193 * CreatePatternBrush32 (GDI32.54)
195 HBRUSH WINAPI
CreatePatternBrush( HBITMAP hbitmap
)
197 LOGBRUSH logbrush
= { BS_PATTERN
, 0, 0 };
198 TRACE("%04x\n", hbitmap
);
200 logbrush
.lbHatch
= hbitmap
;
201 return CreateBrushIndirect( &logbrush
);
205 /***********************************************************************
206 * CreateDIBPatternBrush16 (GDI.445)
208 HBRUSH16 WINAPI
CreateDIBPatternBrush16( HGLOBAL16 hbitmap
, UINT16 coloruse
)
212 TRACE("%04x\n", hbitmap
);
214 logbrush
.lbStyle
= BS_DIBPATTERN
;
215 logbrush
.lbColor
= coloruse
;
216 logbrush
.lbHatch
= hbitmap
;
218 return CreateBrushIndirect16( &logbrush
);
222 /***********************************************************************
223 * CreateDIBPatternBrush32 (GDI32.34)
225 * Create a logical brush which has the pattern specified by the DIB
227 * Function call is for compatability only. CreateDIBPatternBrushPt should be used.
231 * Handle to a logical brush on success, NULL on failure.
236 HBRUSH WINAPI
CreateDIBPatternBrush(
237 HGLOBAL hbitmap
, /* Global object containg BITMAPINFO structure */
238 UINT coloruse
/* Specifies color format, if provided */
243 TRACE("%04x\n", hbitmap
);
245 logbrush
.lbStyle
= BS_DIBPATTERN
;
246 logbrush
.lbColor
= coloruse
;
248 logbrush
.lbHatch
= (LONG
)hbitmap
;
250 return CreateBrushIndirect( &logbrush
);
254 /***********************************************************************
255 * CreateDIBPatternBrushPt (GDI32.35)
257 * Create a logical brush which has the pattern specified by the DIB
261 * Handle to a logical brush on success, NULL on failure.
266 HBRUSH WINAPI
CreateDIBPatternBrushPt(
267 const void* data
, /* Pointer to a BITMAPINFO structure followed by more data */
268 UINT coloruse
/* Specifies color format, if provided */
271 BITMAPINFO
*info
=(BITMAPINFO
*)data
;
274 TRACE("%p %ldx%ld %dbpp\n", info
, info
->bmiHeader
.biWidth
,
275 info
->bmiHeader
.biHeight
, info
->bmiHeader
.biBitCount
);
277 logbrush
.lbStyle
= BS_DIBPATTERNPT
;
278 logbrush
.lbColor
= coloruse
;
279 logbrush
.lbHatch
= (LONG
) data
;
281 return CreateBrushIndirect( &logbrush
);
285 /***********************************************************************
286 * CreateSolidBrush (GDI.66)
288 HBRUSH16 WINAPI
CreateSolidBrush16( COLORREF color
)
290 return CreateSolidBrush( color
);
294 /***********************************************************************
295 * CreateSolidBrush32 (GDI32.64)
297 HBRUSH WINAPI
CreateSolidBrush( COLORREF color
)
301 TRACE("%06lx\n", color
);
303 logbrush
.lbStyle
= BS_SOLID
;
304 logbrush
.lbColor
= color
;
305 logbrush
.lbHatch
= 0;
307 return CreateBrushIndirect( &logbrush
);
311 /***********************************************************************
312 * SetBrushOrg (GDI.148)
314 DWORD WINAPI
SetBrushOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
317 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
318 if (!dc
) return FALSE
;
319 retval
= dc
->w
.brushOrgX
| (dc
->w
.brushOrgY
<< 16);
326 /***********************************************************************
327 * SetBrushOrgEx (GDI32.308)
329 BOOL WINAPI
SetBrushOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT oldorg
)
331 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
333 if (!dc
) return FALSE
;
336 oldorg
->x
= dc
->w
.brushOrgX
;
337 oldorg
->y
= dc
->w
.brushOrgY
;
344 /***********************************************************************
345 * FixBrushOrgEx (GDI32.102)
346 * SDK says discontinued, but in Win95 GDI32 this is the same as SetBrushOrgEx
348 BOOL WINAPI
FixBrushOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT oldorg
)
350 return SetBrushOrgEx(hdc
,x
,y
,oldorg
);
354 /***********************************************************************
357 BOOL
BRUSH_DeleteObject( HBRUSH16 hbrush
, BRUSHOBJ
* brush
)
359 switch(brush
->logbrush
.lbStyle
)
362 DeleteObject( (HGDIOBJ
)brush
->logbrush
.lbHatch
);
365 GlobalFree16( (HGLOBAL16
)brush
->logbrush
.lbHatch
);
368 return GDI_FreeObject( hbrush
);
372 /***********************************************************************
375 INT16
BRUSH_GetObject16( BRUSHOBJ
* brush
, INT16 count
, LPSTR buffer
)
379 logbrush
.lbStyle
= brush
->logbrush
.lbStyle
;
380 logbrush
.lbColor
= brush
->logbrush
.lbColor
;
381 logbrush
.lbHatch
= brush
->logbrush
.lbHatch
;
382 if (count
> sizeof(logbrush
)) count
= sizeof(logbrush
);
383 memcpy( buffer
, &logbrush
, count
);
388 /***********************************************************************
391 INT
BRUSH_GetObject( BRUSHOBJ
* brush
, INT count
, LPSTR buffer
)
393 if (count
> sizeof(brush
->logbrush
)) count
= sizeof(brush
->logbrush
);
394 memcpy( buffer
, &brush
->logbrush
, count
);
399 /***********************************************************************
400 * SetSolidBrush16 (GDI.604)
402 * If hBrush is a solid brush, change it's color to newColor.
405 * TRUE on success, FALSE on failure.
406 * FIXME: not yet implemented!
408 BOOL16 WINAPI
SetSolidBrush16(HBRUSH16 hBrush
, COLORREF newColor
)
410 FIXME("(hBrush %04x, newColor %04x): stub!\n", hBrush
, (int)newColor
);