gdi32: Reimplement CreateBrushIndirect on top of other brush constructors.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2021-08-25 13:39:48 +01:00 committed by Alexandre Julliard
parent 1c1ff37390
commit 2c467a2d1e
5 changed files with 51 additions and 97 deletions

View file

@ -167,26 +167,7 @@ BOOL get_brush_bitmap_info( HBRUSH handle, BITMAPINFO *info, void **bits, UINT *
}
/***********************************************************************
* CreateBrushIndirect (GDI32.@)
*
* Create a logical brush with a given style, color or pattern.
*
* PARAMS
* brush [I] Pointer to a LOGBRUSH structure describing the desired brush.
*
* RETURNS
* A handle to the created brush, or a NULL handle if the brush cannot be
* created.
*
* NOTES
* - The brush returned should be freed by the caller using DeleteObject()
* when it is no longer required.
* - Windows 95 and earlier cannot create brushes from bitmaps or DIBs larger
* than 8x8 pixels. If a larger bitmap is given, only a portion of the bitmap
* is used.
*/
HBRUSH WINAPI CreateBrushIndirect( const LOGBRUSH * brush )
HBRUSH create_brush( const LOGBRUSH *brush )
{
BRUSHOBJ * ptr;
HBRUSH hbrush;
@ -212,19 +193,6 @@ HBRUSH WINAPI CreateBrushIndirect( const LOGBRUSH * brush )
* CreateHatchBrush (GDI32.@)
*
* Create a logical brush with a hatched pattern.
*
* PARAMS
* style [I] Direction of lines for the hatch pattern (HS_* values from "wingdi.h")
* color [I] Colour of the hatched pattern
*
* RETURNS
* A handle to the created brush, or a NULL handle if the brush cannot
* be created.
*
* NOTES
* - This function uses CreateBrushIndirect() to create the brush.
* - The brush returned should be freed by the caller using DeleteObject()
* when it is no longer required.
*/
HBRUSH WINAPI CreateHatchBrush( INT style, COLORREF color )
{
@ -236,7 +204,7 @@ HBRUSH WINAPI CreateHatchBrush( INT style, COLORREF color )
logbrush.lbColor = color;
logbrush.lbHatch = style;
return CreateBrushIndirect( &logbrush );
return create_brush( &logbrush );
}
@ -244,18 +212,6 @@ HBRUSH WINAPI CreateHatchBrush( INT style, COLORREF color )
* CreatePatternBrush (GDI32.@)
*
* Create a logical brush with a pattern from a bitmap.
*
* PARAMS
* hbitmap [I] Bitmap containing pattern for the brush
*
* RETURNS
* A handle to the created brush, or a NULL handle if the brush cannot
* be created.
*
* NOTES
* - This function uses CreateBrushIndirect() to create the brush.
* - The brush returned should be freed by the caller using DeleteObject()
* when it is no longer required.
*/
HBRUSH WINAPI CreatePatternBrush( HBITMAP hbitmap )
{
@ -263,7 +219,7 @@ HBRUSH WINAPI CreatePatternBrush( HBITMAP hbitmap )
TRACE("%p\n", hbitmap );
logbrush.lbHatch = (ULONG_PTR)hbitmap;
return CreateBrushIndirect( &logbrush );
return create_brush( &logbrush );
}
@ -271,21 +227,6 @@ HBRUSH WINAPI CreatePatternBrush( HBITMAP hbitmap )
* CreateDIBPatternBrush (GDI32.@)
*
* Create a logical brush with a pattern from a DIB.
*
* PARAMS
* hbitmap [I] Global object containing BITMAPINFO structure for the pattern
* coloruse [I] Specifies color format, if provided
*
* RETURNS
* A handle to the created brush, or a NULL handle if the brush cannot
* be created.
*
* NOTES
* - This function uses CreateBrushIndirect() to create the brush.
* - The brush returned should be freed by the caller using DeleteObject()
* when it is no longer required.
* - This function is for compatibility only. CreateDIBPatternBrushPt() should
* be used instead.
*/
HBRUSH WINAPI CreateDIBPatternBrush( HGLOBAL hbitmap, UINT coloruse )
{
@ -298,7 +239,7 @@ HBRUSH WINAPI CreateDIBPatternBrush( HGLOBAL hbitmap, UINT coloruse )
logbrush.lbHatch = (ULONG_PTR)hbitmap;
return CreateBrushIndirect( &logbrush );
return create_brush( &logbrush );
}
@ -306,19 +247,6 @@ HBRUSH WINAPI CreateDIBPatternBrush( HGLOBAL hbitmap, UINT coloruse )
* CreateDIBPatternBrushPt (GDI32.@)
*
* Create a logical brush with a pattern from a DIB.
*
* PARAMS
* data [I] Pointer to a BITMAPINFO structure and image data for the pattern
* coloruse [I] Specifies color format, if provided
*
* RETURNS
* A handle to the created brush, or a NULL handle if the brush cannot
* be created.
*
* NOTES
* - This function uses CreateBrushIndirect() to create the brush.
* - The brush returned should be freed by the caller using DeleteObject()
* when it is no longer required.
*/
HBRUSH WINAPI CreateDIBPatternBrushPt( const void* data, UINT coloruse )
{
@ -335,7 +263,7 @@ HBRUSH WINAPI CreateDIBPatternBrushPt( const void* data, UINT coloruse )
logbrush.lbColor = coloruse;
logbrush.lbHatch = (ULONG_PTR)data;
return CreateBrushIndirect( &logbrush );
return create_brush( &logbrush );
}
@ -343,18 +271,6 @@ HBRUSH WINAPI CreateDIBPatternBrushPt( const void* data, UINT coloruse )
* CreateSolidBrush (GDI32.@)
*
* Create a logical brush consisting of a single colour.
*
* PARAMS
* color [I] Colour to make the solid brush
*
* RETURNS
* A handle to the newly created brush, or a NULL handle if the brush cannot
* be created.
*
* NOTES
* - This function uses CreateBrushIndirect() to create the brush.
* - The brush returned should be freed by the caller using DeleteObject()
* when it is no longer required.
*/
HBRUSH WINAPI CreateSolidBrush( COLORREF color )
{
@ -366,7 +282,7 @@ HBRUSH WINAPI CreateSolidBrush( COLORREF color )
logbrush.lbColor = color;
logbrush.lbHatch = 0;
return CreateBrushIndirect( &logbrush );
return create_brush( &logbrush );
}

View file

@ -641,12 +641,12 @@ BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
font_init();
/* create stock objects */
stock_objects[WHITE_BRUSH] = CreateBrushIndirect( &WhiteBrush );
stock_objects[LTGRAY_BRUSH] = CreateBrushIndirect( &LtGrayBrush );
stock_objects[GRAY_BRUSH] = CreateBrushIndirect( &GrayBrush );
stock_objects[DKGRAY_BRUSH] = CreateBrushIndirect( &DkGrayBrush );
stock_objects[BLACK_BRUSH] = CreateBrushIndirect( &BlackBrush );
stock_objects[NULL_BRUSH] = CreateBrushIndirect( &NullBrush );
stock_objects[WHITE_BRUSH] = create_brush( &WhiteBrush );
stock_objects[LTGRAY_BRUSH] = create_brush( &LtGrayBrush );
stock_objects[GRAY_BRUSH] = create_brush( &GrayBrush );
stock_objects[DKGRAY_BRUSH] = create_brush( &DkGrayBrush );
stock_objects[BLACK_BRUSH] = create_brush( &BlackBrush );
stock_objects[NULL_BRUSH] = create_brush( &NullBrush );
stock_objects[WHITE_PEN] = CreatePenIndirect( &WhitePen );
stock_objects[BLACK_PEN] = CreatePenIndirect( &BlackPen );
@ -672,7 +672,7 @@ BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
scaled_stock_objects[SYSTEM_FIXED_FONT] = create_scaled_font( &deffonts->SystemFixedFont );
scaled_stock_objects[DEFAULT_GUI_FONT] = create_scaled_font( &deffonts->DefaultGuiFont );
stock_objects[DC_BRUSH] = CreateBrushIndirect( &DCBrush );
stock_objects[DC_BRUSH] = create_brush( &DCBrush );
stock_objects[DC_PEN] = CreatePenIndirect( &DCPen );
/* clear the NOSYSTEM bit on all stock objects*/

View file

@ -168,6 +168,7 @@ extern DWORD stretch_bits( const BITMAPINFO *src_info, struct bitblt_coords *src
extern void get_mono_dc_colors( DC *dc, int color_table_size, BITMAPINFO *info, int count ) DECLSPEC_HIDDEN;
/* brush.c */
extern HBRUSH create_brush( const LOGBRUSH *brush );
extern BOOL store_brush_pattern( LOGBRUSH *brush, struct brush_pattern *pattern ) DECLSPEC_HIDDEN;
extern void free_brush_pattern( struct brush_pattern *pattern ) DECLSPEC_HIDDEN;
extern BOOL get_brush_bitmap_info( HBRUSH handle, BITMAPINFO *info, void **bits, UINT *usage ) DECLSPEC_HIDDEN;

View file

@ -398,6 +398,32 @@ HPEN WINAPI CreatePen( INT style, INT width, COLORREF color )
return NtGdiCreatePen( style, width, color, NULL );
}
/***********************************************************************
* CreateBrushIndirect (GDI32.@)
*/
HBRUSH WINAPI CreateBrushIndirect( const LOGBRUSH *brush )
{
switch (brush->lbStyle)
{
case BS_NULL:
return GetStockObject( NULL_BRUSH );
case BS_SOLID:
return CreateSolidBrush( brush->lbColor );
case BS_HATCHED:
return CreateHatchBrush( brush->lbHatch, brush->lbColor );
case BS_PATTERN:
case BS_PATTERN8X8:
return CreatePatternBrush( (HBITMAP)brush->lbHatch );
case BS_DIBPATTERN:
return CreateDIBPatternBrush( (HGLOBAL)brush->lbHatch, brush->lbColor );
case BS_DIBPATTERNPT:
return CreateDIBPatternBrushPt( (void *)brush->lbHatch, brush->lbColor );
default:
WARN( "invalid brush style %u\n", brush->lbStyle );
return 0;
}
}
/***********************************************************************
* CreateBitmapIndirect (GDI32.@)
*/

View file

@ -361,6 +361,16 @@ static void test_brush_org( void )
ReleaseDC( 0, hdc );
}
static void test_null_brush(void)
{
LOGBRUSH lb;
HBRUSH brush;
lb.lbStyle = BS_NULL;
brush = CreateBrushIndirect(&lb);
ok(brush == GetStockObject(NULL_BRUSH), "brush is not NULL_BRUSH\n");
}
START_TEST(brush)
{
test_solidbrush();
@ -368,4 +378,5 @@ START_TEST(brush)
test_pattern_brush();
test_palette_brush();
test_brush_org();
test_null_brush();
}