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
)
110 if (!(brushPtr
= GDI_AllocObject( sizeof(BRUSHOBJ
), BRUSH_MAGIC
, &hbrush
))) return 0;
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
);
117 GDI_FreeObject( hbrush
, brushPtr
);
120 else GDI_ReleaseObj( hbrush
);
121 TRACE("%04x\n", hbrush
);
126 /***********************************************************************
127 * CreateBrushIndirect (GDI32.@)
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
)
140 if (!(brushPtr
= GDI_AllocObject( sizeof(BRUSHOBJ
), BRUSH_MAGIC
, &hbrush
))) return 0;
141 brushPtr
->logbrush
.lbStyle
= brush
->lbStyle
;
142 brushPtr
->logbrush
.lbColor
= brush
->lbColor
;
143 brushPtr
->logbrush
.lbHatch
= brush
->lbHatch
;
144 success
= create_brush_indirect(brushPtr
, FALSE
);
147 GDI_FreeObject( hbrush
, brushPtr
);
150 else GDI_ReleaseObj( hbrush
);
151 TRACE("%08x\n", hbrush
);
156 /***********************************************************************
157 * CreateHatchBrush16 (GDI.58)
159 HBRUSH16 WINAPI
CreateHatchBrush16( INT16 style
, COLORREF color
)
161 return CreateHatchBrush( style
, color
);
165 /***********************************************************************
166 * CreateHatchBrush (GDI32.@)
168 HBRUSH WINAPI
CreateHatchBrush( INT style
, COLORREF color
)
172 TRACE("%d %06lx\n", style
, color
);
174 logbrush
.lbStyle
= BS_HATCHED
;
175 logbrush
.lbColor
= color
;
176 logbrush
.lbHatch
= style
;
178 return CreateBrushIndirect( &logbrush
);
182 /***********************************************************************
183 * CreatePatternBrush16 (GDI.60)
185 HBRUSH16 WINAPI
CreatePatternBrush16( HBITMAP16 hbitmap
)
187 return (HBRUSH16
)CreatePatternBrush( hbitmap
);
191 /***********************************************************************
192 * CreatePatternBrush (GDI32.@)
194 HBRUSH WINAPI
CreatePatternBrush( HBITMAP hbitmap
)
196 LOGBRUSH logbrush
= { BS_PATTERN
, 0, 0 };
197 TRACE("%04x\n", hbitmap
);
199 logbrush
.lbHatch
= hbitmap
;
200 return CreateBrushIndirect( &logbrush
);
204 /***********************************************************************
205 * CreateDIBPatternBrush16 (GDI.445)
207 HBRUSH16 WINAPI
CreateDIBPatternBrush16( HGLOBAL16 hbitmap
, UINT16 coloruse
)
211 TRACE("%04x\n", hbitmap
);
213 logbrush
.lbStyle
= BS_DIBPATTERN
;
214 logbrush
.lbColor
= coloruse
;
215 logbrush
.lbHatch
= hbitmap
;
217 return CreateBrushIndirect16( &logbrush
);
221 /***********************************************************************
222 * CreateDIBPatternBrush (GDI32.@)
224 * Create a logical brush which has the pattern specified by the DIB
226 * Function call is for compatibility only. CreateDIBPatternBrushPt should be used.
230 * Handle to a logical brush on success, NULL on failure.
235 HBRUSH WINAPI
CreateDIBPatternBrush(
236 HGLOBAL hbitmap
, /* [in] Global object containg BITMAPINFO structure */
237 UINT coloruse
/* [in] Specifies color format, if provided */
242 TRACE("%04x\n", hbitmap
);
244 logbrush
.lbStyle
= BS_DIBPATTERN
;
245 logbrush
.lbColor
= coloruse
;
247 logbrush
.lbHatch
= (LONG
)hbitmap
;
249 return CreateBrushIndirect( &logbrush
);
253 /***********************************************************************
254 * CreateDIBPatternBrushPt (GDI32.@)
256 * Create a logical brush which has the pattern specified by the DIB
260 * Handle to a logical brush on success, NULL on failure.
265 HBRUSH WINAPI
CreateDIBPatternBrushPt(
266 const void* data
, /* [in] Pointer to a BITMAPINFO structure followed by more data */
267 UINT coloruse
/* [in] Specifies color format, if provided */
270 BITMAPINFO
*info
=(BITMAPINFO
*)data
;
273 TRACE("%p %ldx%ld %dbpp\n", info
, info
->bmiHeader
.biWidth
,
274 info
->bmiHeader
.biHeight
, info
->bmiHeader
.biBitCount
);
276 logbrush
.lbStyle
= BS_DIBPATTERNPT
;
277 logbrush
.lbColor
= coloruse
;
278 logbrush
.lbHatch
= (LONG
) data
;
280 return CreateBrushIndirect( &logbrush
);
284 /***********************************************************************
285 * CreateSolidBrush (GDI.66)
287 HBRUSH16 WINAPI
CreateSolidBrush16( COLORREF color
)
289 return CreateSolidBrush( color
);
293 /***********************************************************************
294 * CreateSolidBrush (GDI32.@)
296 HBRUSH WINAPI
CreateSolidBrush( COLORREF color
)
300 TRACE("%06lx\n", color
);
302 logbrush
.lbStyle
= BS_SOLID
;
303 logbrush
.lbColor
= color
;
304 logbrush
.lbHatch
= 0;
306 return CreateBrushIndirect( &logbrush
);
310 /***********************************************************************
311 * SetBrushOrg (GDI.148)
313 DWORD WINAPI
SetBrushOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
316 DC
*dc
= DC_GetDCPtr( hdc
);
317 if (!dc
) return FALSE
;
318 retval
= dc
->brushOrgX
| (dc
->brushOrgY
<< 16);
321 GDI_ReleaseObj( hdc
);
326 /***********************************************************************
327 * SetBrushOrgEx (GDI32.@)
329 BOOL WINAPI
SetBrushOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT oldorg
)
331 DC
*dc
= DC_GetDCPtr( hdc
);
333 if (!dc
) return FALSE
;
336 oldorg
->x
= dc
->brushOrgX
;
337 oldorg
->y
= dc
->brushOrgY
;
341 GDI_ReleaseObj( hdc
);
345 /***********************************************************************
346 * FixBrushOrgEx (GDI32.@)
347 * SDK says discontinued, but in Win95 GDI32 this is the same as SetBrushOrgEx
349 BOOL WINAPI
FixBrushOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT oldorg
)
351 return SetBrushOrgEx(hdc
,x
,y
,oldorg
);
355 /***********************************************************************
358 BOOL
BRUSH_DeleteObject( HBRUSH16 hbrush
, BRUSHOBJ
* brush
)
360 switch(brush
->logbrush
.lbStyle
)
363 DeleteObject( (HGDIOBJ
)brush
->logbrush
.lbHatch
);
366 GlobalFree16( (HGLOBAL16
)brush
->logbrush
.lbHatch
);
369 return GDI_FreeObject( hbrush
, brush
);
373 /***********************************************************************
376 INT16
BRUSH_GetObject16( BRUSHOBJ
* brush
, INT16 count
, LPSTR buffer
)
380 logbrush
.lbStyle
= brush
->logbrush
.lbStyle
;
381 logbrush
.lbColor
= brush
->logbrush
.lbColor
;
382 logbrush
.lbHatch
= brush
->logbrush
.lbHatch
;
383 if (count
> sizeof(logbrush
)) count
= sizeof(logbrush
);
384 memcpy( buffer
, &logbrush
, count
);
389 /***********************************************************************
392 INT
BRUSH_GetObject( BRUSHOBJ
* brush
, INT count
, LPSTR buffer
)
394 if (count
> sizeof(brush
->logbrush
)) count
= sizeof(brush
->logbrush
);
395 memcpy( buffer
, &brush
->logbrush
, count
);
400 /***********************************************************************
401 * SetSolidBrush16 (GDI.604)
403 * If hBrush is a solid brush, change its color to newColor.
406 * TRUE on success, FALSE on failure.
408 * FIXME: untested, not sure if correct.
410 BOOL16 WINAPI
SetSolidBrush16(HBRUSH16 hBrush
, COLORREF newColor
)
415 TRACE("(hBrush %04x, newColor %08lx)\n", hBrush
, (DWORD
)newColor
);
416 if (!(brushPtr
= (BRUSHOBJ
*) GDI_GetObjPtr( hBrush
, BRUSH_MAGIC
)))
419 if (brushPtr
->logbrush
.lbStyle
== BS_SOLID
)
421 brushPtr
->logbrush
.lbColor
= newColor
;
425 GDI_ReleaseObj( hBrush
);