From 16ff6689dfd8fead7e6da4b8bdc8373594feb9a0 Mon Sep 17 00:00:00 2001 From: Ulrich Czekalla Date: Wed, 5 Nov 2003 01:43:57 +0000 Subject: [PATCH] Implemented SetDCPenColor and SetDCBrushColor. --- dlls/gdi/driver.c | 2 + dlls/gdi/enhmfdrv/init.c | 2 + dlls/gdi/gdi32.spec | 1 + dlls/gdi/mfdrv/init.c | 2 + dlls/x11drv/x11drv.spec | 2 + graphics/x11drv/brush.c | 16 +++++++- graphics/x11drv/pen.c | 14 +++++++ include/gdi.h | 4 ++ include/wingdi.h | 4 +- objects/dc.c | 85 ++++++++++++++++++++++++++++++++++++++-- objects/gdiobj.c | 4 ++ 11 files changed, 130 insertions(+), 6 deletions(-) diff --git a/dlls/gdi/driver.c b/dlls/gdi/driver.c index 408cbddb2e0..a013c7c5e80 100644 --- a/dlls/gdi/driver.c +++ b/dlls/gdi/driver.c @@ -157,7 +157,9 @@ static struct graphics_driver *create_driver( HMODULE module ) GET_FUNC(SetBitmapBits); GET_FUNC(SetBkColor); GET_FUNC(SetBkMode); + GET_FUNC(SetDCBrushColor); GET_FUNC(SetDCOrg); + GET_FUNC(SetDCPenColor); GET_FUNC(SetDIBColorTable); GET_FUNC(SetDIBits); GET_FUNC(SetDIBitsToDevice); diff --git a/dlls/gdi/enhmfdrv/init.c b/dlls/gdi/enhmfdrv/init.c index cfc8b71b26b..af727f662c9 100644 --- a/dlls/gdi/enhmfdrv/init.c +++ b/dlls/gdi/enhmfdrv/init.c @@ -116,7 +116,9 @@ static const DC_FUNCTIONS EMFDRV_Funcs = NULL, /* pSetBitmapBits */ EMFDRV_SetBkColor, /* pSetBkColor */ EMFDRV_SetBkMode, /* pSetBkMode */ + NULL, /* pSetDCBrushColor */ NULL, /* pSetDCOrg */ + NULL, /* pSetDCPenColor */ NULL, /* pSetDIBColorTable */ NULL, /* pSetDIBits */ EMFDRV_SetDIBitsToDevice, /* pSetDIBitsToDevice */ diff --git a/dlls/gdi/gdi32.spec b/dlls/gdi/gdi32.spec index 5187f03ec26..3957402b200 100644 --- a/dlls/gdi/gdi32.spec +++ b/dlls/gdi/gdi32.spec @@ -350,6 +350,7 @@ @ stdcall SetColorAdjustment(long ptr) @ stdcall SetColorSpace(long long) @ stdcall SetDCBrushColor(long long) +@ stdcall SetDCPenColor(long long) @ stdcall SetDIBColorTable(long long long ptr) @ stdcall SetDIBits(long long long long ptr ptr long) @ stdcall SetDIBitsToDevice(long long long long long long long long long ptr ptr long) diff --git a/dlls/gdi/mfdrv/init.c b/dlls/gdi/mfdrv/init.c index 24a8947c8b4..2a0afbb1b83 100644 --- a/dlls/gdi/mfdrv/init.c +++ b/dlls/gdi/mfdrv/init.c @@ -117,7 +117,9 @@ static const DC_FUNCTIONS MFDRV_Funcs = NULL, /* pSetBitmapBits */ MFDRV_SetBkColor, /* pSetBkColor */ MFDRV_SetBkMode, /* pSetBkMode */ + NULL, /* pSetDCBrushColor*/ NULL, /* pSetDCOrg */ + NULL, /* pSetDCPenColor*/ NULL, /* pSetDIBColorTable */ NULL, /* pSetDIBits */ MFDRV_SetDIBitsToDevice, /* pSetDIBitsToDevice */ diff --git a/dlls/x11drv/x11drv.spec b/dlls/x11drv/x11drv.spec index 4e1451a3801..c24c67d4d4c 100644 --- a/dlls/x11drv/x11drv.spec +++ b/dlls/x11drv/x11drv.spec @@ -46,7 +46,9 @@ @ cdecl SelectPen(ptr long) X11DRV_SelectPen @ cdecl SetBitmapBits(long ptr long) X11DRV_SetBitmapBits @ cdecl SetBkColor(ptr long) X11DRV_SetBkColor +@ cdecl SetDCBrushColor(ptr long) X11DRV_SetDCBrushColor @ cdecl SetDCOrg(ptr long long) X11DRV_SetDCOrg +@ cdecl SetDCPenColor(ptr long) X11DRV_SetDCPenColor @ cdecl SetDIBColorTable(ptr long long ptr) X11DRV_SetDIBColorTable @ cdecl SetDIBits(ptr long long long ptr ptr long) X11DRV_SetDIBits @ cdecl SetDIBitsToDevice(ptr long long long long long long long long ptr ptr long) X11DRV_SetDIBitsToDevice diff --git a/graphics/x11drv/brush.c b/graphics/x11drv/brush.c index 95c18258fbe..c52fc7873ca 100644 --- a/graphics/x11drv/brush.c +++ b/graphics/x11drv/brush.c @@ -218,8 +218,6 @@ static BOOL BRUSH_SelectPatternBrush( X11DRV_PDEVICE *physDev, HBITMAP hbitmap ) } - - /*********************************************************************** * SelectBrush (X11DRV.@) */ @@ -239,6 +237,8 @@ HBRUSH X11DRV_SelectBrush( X11DRV_PDEVICE *physDev, HBRUSH hbrush ) physDev->brush.pixmap = 0; } physDev->brush.style = logbrush.lbStyle; + if (hbrush == GetStockObject( DC_BRUSH )) + logbrush.lbColor = physDev->dc->dcBrushColor; switch(logbrush.lbStyle) { @@ -282,3 +282,15 @@ HBRUSH X11DRV_SelectBrush( X11DRV_PDEVICE *physDev, HBRUSH hbrush ) } return hbrush; } + + +/*********************************************************************** + * SetDCBrushColor (X11DRV.@) + */ +COLORREF X11DRV_SetDCBrushColor( X11DRV_PDEVICE *physDev, COLORREF crColor ) +{ + if (GetCurrentObject(physDev->hdc, OBJ_BRUSH) == GetStockObject( DC_BRUSH )) + BRUSH_SelectSolidBrush( physDev, crColor ); + + return crColor; +} diff --git a/graphics/x11drv/pen.c b/graphics/x11drv/pen.c index 140d78f2112..3d798f75be2 100644 --- a/graphics/x11drv/pen.c +++ b/graphics/x11drv/pen.c @@ -50,6 +50,8 @@ HPEN X11DRV_SelectPen( X11DRV_PDEVICE *physDev, HPEN hpen ) dc->xformWorld2Vport.eM11); if (physDev->pen.width < 0) physDev->pen.width = -physDev->pen.width; if (physDev->pen.width == 1) physDev->pen.width = 0; /* Faster */ + if (hpen == GetStockObject( DC_PEN )) + logpen.lopnColor = dc->dcPenColor; physDev->pen.pixel = X11DRV_PALETTE_ToPhysical( physDev, logpen.lopnColor ); switch(logpen.lopnStyle & PS_STYLE_MASK) { @@ -79,3 +81,15 @@ HPEN X11DRV_SelectPen( X11DRV_PDEVICE *physDev, HPEN hpen ) } return hpen; } + + +/*********************************************************************** + * SetDCPenColor (X11DRV.@) + */ +COLORREF X11DRV_SetDCPenColor( X11DRV_PDEVICE *physDev, COLORREF crColor ) +{ + if (GetCurrentObject(physDev->hdc, OBJ_PEN) == GetStockObject( DC_PEN )) + physDev->pen.pixel = X11DRV_PALETTE_ToPhysical( physDev, crColor ); + + return crColor; +} diff --git a/include/gdi.h b/include/gdi.h index 70001484b4c..ac900f3df98 100644 --- a/include/gdi.h +++ b/include/gdi.h @@ -139,6 +139,8 @@ typedef struct tagDC WORD backgroundMode; COLORREF backgroundColor; COLORREF textColor; + COLORREF dcBrushColor; + COLORREF dcPenColor; short brushOrgX; short brushOrgY; @@ -256,7 +258,9 @@ typedef struct tagDC_FUNCS LONG (*pSetBitmapBits)(HBITMAP,const void*,LONG); COLORREF (*pSetBkColor)(PHYSDEV,COLORREF); INT (*pSetBkMode)(PHYSDEV,INT); + COLORREF (*pSetDCBrushColor)(PHYSDEV, COLORREF); DWORD (*pSetDCOrg)(PHYSDEV,INT,INT); + COLORREF (*pSetDCPenColor)(PHYSDEV, COLORREF); UINT (*pSetDIBColorTable)(PHYSDEV,UINT,UINT,const RGBQUAD*); INT (*pSetDIBits)(PHYSDEV,HBITMAP,UINT,UINT,LPCVOID,const BITMAPINFO*,UINT); INT (*pSetDIBitsToDevice)(PHYSDEV,INT,INT,DWORD,DWORD,INT,INT,UINT,UINT,LPCVOID, diff --git a/include/wingdi.h b/include/wingdi.h index 611e87cc988..0cfa642286f 100644 --- a/include/wingdi.h +++ b/include/wingdi.h @@ -1830,8 +1830,10 @@ typedef struct #define DEFAULT_PALETTE 15 #define SYSTEM_FIXED_FONT 16 #define DEFAULT_GUI_FONT 17 +#define DC_BRUSH 18 +#define DC_PEN 19 -#define STOCK_LAST 17 +#define STOCK_LAST 19 #define CLR_INVALID 0xffffffff /* Metafile header structure */ diff --git a/objects/dc.c b/objects/dc.c index d0aebe903b7..c9335fe6602 100644 --- a/objects/dc.c +++ b/objects/dc.c @@ -92,6 +92,8 @@ DC *DC_AllocDC( const DC_FUNCTIONS *funcs, WORD magic ) dc->relAbsMode = ABSOLUTE; dc->backgroundMode = OPAQUE; dc->backgroundColor = RGB( 255, 255, 255 ); + dc->dcBrushColor = RGB( 255, 255, 255 ); + dc->dcPenColor = RGB( 0, 0, 0 ); dc->textColor = RGB( 0, 0, 0 ); dc->brushOrgX = 0; dc->brushOrgY = 0; @@ -301,6 +303,8 @@ HDC WINAPI GetDCState( HDC hdc ) newdc->backgroundMode = dc->backgroundMode; newdc->backgroundColor = dc->backgroundColor; newdc->textColor = dc->textColor; + newdc->dcBrushColor = dc->dcBrushColor; + newdc->dcPenColor = dc->dcPenColor; newdc->brushOrgX = dc->brushOrgX; newdc->brushOrgY = dc->brushOrgY; newdc->textAlign = dc->textAlign; @@ -389,6 +393,8 @@ void WINAPI SetDCState( HDC hdc, HDC hdcs ) dc->backgroundMode = dcs->backgroundMode; dc->backgroundColor = dcs->backgroundColor; dc->textColor = dcs->textColor; + dc->dcBrushColor = dcs->dcBrushColor; + dc->dcPenColor = dcs->dcPenColor; dc->brushOrgX = dcs->brushOrgX; dc->brushOrgY = dcs->brushOrgY; dc->textAlign = dcs->textAlign; @@ -855,6 +861,8 @@ COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color ) COLORREF oldColor; DC * dc = DC_GetDCPtr( hdc ); + TRACE("hdc=%p color=0x%08lx\n", hdc, color); + if (!dc) return CLR_INVALID; oldColor = dc->backgroundColor; if (dc->funcs->pSetBkColor) @@ -880,6 +888,8 @@ COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color ) COLORREF oldColor; DC * dc = DC_GetDCPtr( hdc ); + TRACE(" hdc=%p color=0x%08lx\n", hdc, color); + if (!dc) return CLR_INVALID; oldColor = dc->textColor; if (dc->funcs->pSetTextColor) @@ -904,6 +914,9 @@ UINT WINAPI SetTextAlign( HDC hdc, UINT align ) { UINT prevAlign; DC *dc = DC_GetDCPtr( hdc ); + + TRACE("hdc=%p align=%d\n", hdc, align); + if (!dc) return 0x0; if (dc->funcs->pSetTextAlign) prevAlign = dc->funcs->pSetTextAlign(dc->physDev, align); @@ -1455,9 +1468,75 @@ DWORD WINAPI SetLayout(HDC hdc, DWORD layout) */ COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor) { - FIXME("(%p, %08lx): stub\n", hdc, crColor); - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return CLR_INVALID; + DC *dc; + COLORREF oldClr = CLR_INVALID; + + TRACE("hdc(%p) crColor(%08lx)\n", hdc, crColor); + + dc = DC_GetDCPtr( hdc ); + if (dc) + { + if (dc->funcs->pSetDCBrushColor) + crColor = dc->funcs->pSetDCBrushColor( dc->physDev, crColor ); + else if (dc->hBrush == GetStockObject( DC_BRUSH )) + { + /* If DC_BRUSH is selected, update driver pen color */ + HBRUSH hBrush = CreateSolidBrush( crColor ); + dc->funcs->pSelectBrush( dc->physDev, hBrush ); + DeleteObject( hBrush ); + } + + if (crColor != CLR_INVALID) + { + oldClr = dc->dcBrushColor; + dc->dcBrushColor = crColor; + } + + GDI_ReleaseObj( hdc ); + } + + return oldClr; +} + +/*********************************************************************** + * SetDCPenColor (GDI32.@) + * + * Sets the current device context (DC) pen color to the specified + * color value. If the device cannot represent the specified color + * value, the color is set to the nearest physical color. + * + */ +COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor) +{ + DC *dc; + COLORREF oldClr = CLR_INVALID; + + TRACE("hdc(%p) crColor(%08lx)\n", hdc, crColor); + + dc = DC_GetDCPtr( hdc ); + if (dc) + { + if (dc->funcs->pSetDCPenColor) + crColor = dc->funcs->pSetDCPenColor( dc->physDev, crColor ); + else if (dc->hPen == GetStockObject( DC_PEN )) + { + /* If DC_PEN is selected, update the driver pen color */ + LOGPEN logpen = { PS_SOLID, { 0, 0 }, crColor }; + HPEN hPen = CreatePenIndirect( &logpen ); + dc->funcs->pSelectPen( dc->physDev, hPen ); + DeleteObject( hPen ); + } + + if (crColor != CLR_INVALID) + { + oldClr = dc->dcPenColor; + dc->dcPenColor = crColor; + } + + GDI_ReleaseObj( hdc ); + } + + return oldClr; } /*********************************************************************** diff --git a/objects/gdiobj.c b/objects/gdiobj.c index 3e7a5ad2e48..5f03869d8d8 100644 --- a/objects/gdiobj.c +++ b/objects/gdiobj.c @@ -61,6 +61,8 @@ static const LOGPEN WhitePen = { PS_SOLID, { 0, 0 }, RGB(255,255,255) }; static const LOGPEN BlackPen = { PS_SOLID, { 0, 0 }, RGB(0,0,0) }; static const LOGPEN NullPen = { PS_NULL, { 0, 0 }, 0 }; +static const LOGBRUSH DCBrush = { BS_SOLID, RGB(255,255,255), 0 }; +static const LOGPEN DCPen = { PS_SOLID, { 0, 0 }, RGB(0,0,0) }; /* reserve one extra entry for the stock default bitmap */ /* this is what Windows does too */ @@ -619,6 +621,8 @@ BOOL GDI_Init(void) stock_objects[SYSTEM_FIXED_FONT] = create_stock_font( "SystemFixed", &deffonts->SystemFixedFont, hkey ); stock_objects[DEFAULT_GUI_FONT] = create_stock_font( "DefaultGui", &deffonts->DefaultGuiFont, hkey ); + stock_objects[DC_BRUSH] = CreateBrushIndirect( &DCBrush ); + stock_objects[DC_PEN] = CreatePenIndirect( &DCPen ); /* clear the NOSYSTEM bit on all stock objects*/ for (i = 0; i < NB_STOCK_OBJECTS; i++)