Index: svx/source/tbxctrls/tbcontrl.cxx =================================================================== RCS file: /cvs/graphics/svx/source/tbxctrls/tbcontrl.cxx,v retrieving revision 1.42 diff -u -p -u -r1.42 tbcontrl.cxx --- svx/source/tbxctrls/tbcontrl.cxx 6 Jun 2003 10:44:32 -0000 1.42 +++ svx/source/tbxctrls/tbcontrl.cxx 1 Oct 2003 23:06:27 -0000 @@ -78,6 +78,9 @@ #ifndef _SV_SYSTEM_HXX //autogen wg. System #include #endif +#ifndef _SV_BMPACC_HXX +#include +#endif #ifndef _VALUESET_HXX #include #endif @@ -426,10 +429,9 @@ private: USHORT nDrawMode; USHORT nBtnId; ToolBox* pTbx; - Bitmap* pBtnBmp; + BitmapEx aOrigBitmap; Color aCurColor; Rectangle theUpdRect; - Size theBmpSize; BOOL bWasHiContrastMode; }; @@ -1788,7 +1794,6 @@ SvxTbxButtonColorUpdater_Impl::SvxTbxBut nDrawMode ( nMode ), nBtnId ( nTbxBtnId ), pTbx ( ptrTbx ), - pBtnBmp ( NULL ), aCurColor ( COL_TRANSPARENT ) { if (nTbxBtnId == SID_BACKGROUND_COLOR) @@ -1803,106 +1808,82 @@ SvxTbxButtonColorUpdater_Impl::SvxTbxBut SvxTbxButtonColorUpdater_Impl::~SvxTbxButtonColorUpdater_Impl() { - delete pBtnBmp; } // ----------------------------------------------------------------------- -void SvxTbxButtonColorUpdater_Impl::Update( const Color& rColor ) +// This sucks - but so does VirtualDevice for rendering on AlphaMasks +static void +BitmapDrawRect( Bitmap &rBitmap, const Rectangle &rRect, const Color& rColor ) { - Image aImage( pTbx->GetItemImage( nBtnId ) ); - BOOL bSizeChanged = ( theBmpSize != aImage.GetSizePixel() ); - BOOL bDisplayModeChanged = ( bWasHiContrastMode != pTbx->GetBackground().GetColor().IsDark() ); - - Color aColor( rColor ); - - // #109290# Workaround for SetFillColor with COL_AUTO - if ( aColor.GetColor() == COL_AUTO ) - aColor = Color( IMAGE_COL_TRANSPARENT ); + BitmapWriteAccess *pUpd = rBitmap.AcquireWriteAccess(); - if ( aCurColor == aColor && !bSizeChanged && !bDisplayModeChanged ) - return; + for( long nY = rRect.Top(); nY < rRect.Bottom(); nY++ ) + for( long nX = rRect.Left(); nX < rRect.Right(); nX ++ ) + pUpd->SetPixel( nY, nX, rColor ); - VirtualDevice aVirDev( *pTbx ); - Point aNullPnt; + rBitmap.ReleaseAccess( pUpd ); +} - if ( bSizeChanged || bDisplayModeChanged ) - { - bWasHiContrastMode = pTbx->GetBackground().GetColor().IsDark(); - theBmpSize = aImage.GetSizePixel(); +void SvxTbxButtonColorUpdater_Impl::Update( const Color& rColor ) +{ + Image aImage( pTbx->GetItemImage( nBtnId ) ); - if ( theBmpSize.Width() <= 16 ) - theUpdRect = Rectangle( Point(7,7), Size(8,8) ); - else - theUpdRect = Rectangle( Point(14,14), Size(11,11) ); + BOOL bIconChanged = ( aOrigBitmap.IsEmpty() && !aImage.GetBitmap().IsEmpty() ) || + ( aOrigBitmap.GetSizePixel() != aImage.GetSizePixel() ) || + ( bWasHiContrastMode != pTbx->GetBackground().GetColor().IsDark() ); + + if ( aCurColor == rColor && !bIconChanged ) + return; + aCurColor = rColor; - aVirDev.SetPen( Pen( PEN_NULL ) ); - aVirDev.SetOutputSizePixel( theBmpSize ); - aVirDev.SetFillColor( Color( IMAGE_COL_TRANSPARENT ) ); - aVirDev.DrawRect( Rectangle( aNullPnt, theBmpSize ) ); - aVirDev.DrawImage( aNullPnt, aImage ); - delete pBtnBmp; - pBtnBmp = new Bitmap( aVirDev.GetBitmap( aNullPnt, theBmpSize ) ); - if ( nDrawMode != TBX_UPDATER_MODE_CHAR_COLOR_NEW ) - aVirDev.DrawRect( theUpdRect ); - } - else if ( !pBtnBmp ) - pBtnBmp = new Bitmap( aVirDev.GetBitmap( aNullPnt, theBmpSize ) ); - - aVirDev.SetOutputSizePixel( theBmpSize ); - aVirDev.DrawBitmap( aNullPnt, *pBtnBmp ); - - // Choose line color according to background color - if ( pTbx->GetBackground().GetColor().IsDark() ) - aVirDev.SetLineColor( COL_WHITE ); + Rectangle aUpdRect; + if ( aImage.GetSizePixel().Width() <= 16 ) + aUpdRect = Rectangle( Point( 0,12 ), Size( aImage.GetSizePixel().Width(), 4 ) ); else - aVirDev.SetLineColor( COL_BLACK ); + aUpdRect = Rectangle( Point( 1,19 ), Size( 24,6 ) ); - if ( nDrawMode == TBX_UPDATER_MODE_CHAR_COLOR_NEW && - ( aColor.GetColor() != COL_AUTO && - aColor.GetColor() != IMAGE_COL_TRANSPARENT )) + if ( bIconChanged ) { - // Draw border only if COLOR_AUTO is the new color! - aVirDev.SetLineColor( aColor ); + aOrigBitmap = BitmapEx( aImage.GetBitmap(), aImage.GetMaskBitmap() ); + bWasHiContrastMode = pTbx->GetBackground().GetColor().IsDark(); } - aVirDev.SetFillColor( aColor ); - if ( nDrawMode == TBX_UPDATER_MODE_CHAR_COLOR_NEW ) + Bitmap aNewBitmap( aOrigBitmap.GetBitmap() ); + Bitmap aNewMask( aOrigBitmap.GetMask() ); + + BitmapDrawRect( aNewMask, aUpdRect, COL_BLACK ); + if( rColor.GetColor() == COL_AUTO ) { - // New mode for our new high contrast enabled bitmaps - if ( theBmpSize.Width() <= 16 ) - theUpdRect = Rectangle( Point( 0,12 ), Size(theBmpSize.Width(), 4 ) ); + Rectangle aInnerRect( aUpdRect.Left() + 1, + aUpdRect.Top() + 1, + aUpdRect.Right() - 1, + aUpdRect.Bottom() - 1 ); + BitmapDrawRect( aNewMask, aInnerRect, COL_WHITE ); + + Color aLineColor; + if ( pTbx->GetBackground().GetColor().IsDark() ) + aLineColor = COL_WHITE; else - theUpdRect = Rectangle( Point( 1,19 ), Size( 24,6 ) ); - aVirDev.DrawRect( theUpdRect ); - } - else if ( nDrawMode != TBX_UPDATER_MODE_NONE ) - { - DrawChar( aVirDev, aColor ); - } - else - aVirDev.DrawRect( theUpdRect ); + aLineColor = COL_BLACK; - aCurColor = aColor; - - // The following code asumes that we cannot change the display color depth - // during Office runtime. Which is at least NOT true for newer Windows versions! - const Bitmap aBmp( aVirDev.GetBitmap( aNullPnt, theBmpSize ) ); - static Color aTransparentColor; - static sal_Bool bTransparentColorInitialized = sal_False; - - if( !bTransparentColorInitialized ) - { - aVirDev.DrawPixel( aNullPnt, IMAGE_COL_TRANSPARENT ); - aTransparentColor = aVirDev.GetPixel( aNullPnt ); - bTransparentColorInitialized = sal_True; + Rectangle aHoriz( aUpdRect.Left(), aUpdRect.Top(), + aUpdRect.Right(), aUpdRect.Top() + 1 ); + Rectangle aVert ( aUpdRect.Left(), aUpdRect.Top(), + aUpdRect.Left() + 1, aUpdRect.Bottom() ); + BitmapDrawRect( aNewBitmap, aHoriz, aLineColor ); + aHoriz.Move( 0, aUpdRect.Bottom() - aUpdRect.Top() - 1 ); + BitmapDrawRect( aNewBitmap, aHoriz, aLineColor ); + BitmapDrawRect( aNewBitmap, aVert, aLineColor ); + aVert.Move( aUpdRect.Right() - aUpdRect.Left() - 1, 0 ); + BitmapDrawRect( aNewBitmap, aVert, aLineColor ); } + else + BitmapDrawRect( aNewBitmap, aUpdRect, rColor ); - Bitmap aMaskBitmap = aBmp.CreateMask( aTransparentColor ); - Image aNewImage( aBmp, aMaskBitmap ); - pTbx->SetItemImage( nBtnId, aNewImage ); + pTbx->SetItemImage( nBtnId, Image( aNewBitmap, aNewMask ) ); } - +#if 0 // ----------------------------------------------------------------------- void SvxTbxButtonColorUpdater_Impl::DrawChar( VirtualDevice& rVirDev, const Color& rCol ) @@ -1935,6 +1916,7 @@ void SvxTbxButtonColorUpdater_Impl::Draw rVirDev.DrawText( aPos, 'A' ); rVirDev.SetFont( aOldFont ); } +#endif //======================================================================== // class SfxStyleControllerItem_Impl ------------------------------------------ //========================================================================