1f6e50924SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file 5f6e50924SAndrew Rist * distributed with this work for additional information 6f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the 8f6e50924SAndrew Rist * "License"); you may not use this file except in compliance 9f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing, 14f6e50924SAndrew Rist * software distributed under the License is distributed on an 15f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16f6e50924SAndrew Rist * KIND, either express or implied. See the License for the 17f6e50924SAndrew Rist * specific language governing permissions and limitations 18f6e50924SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20f6e50924SAndrew Rist *************************************************************/ 21f6e50924SAndrew Rist 22f6e50924SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svx.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <svx/tbxcolorupdate.hxx> 28cdf0e10cSrcweir #include <svx/svxids.hrc> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <vcl/toolbox.hxx> 31cdf0e10cSrcweir #include <vcl/bmpacc.hxx> 32cdf0e10cSrcweir #include <tools/debug.hxx> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #define IMAGE_COL_TRANSPARENT COL_LIGHTMAGENTA 35cdf0e10cSrcweir 36cdf0e10cSrcweir //........................................................................ 37cdf0e10cSrcweir namespace svx 38cdf0e10cSrcweir { 39cdf0e10cSrcweir //........................................................................ 40cdf0e10cSrcweir 41cdf0e10cSrcweir //==================================================================== 42cdf0e10cSrcweir //= ToolboxButtonColorUpdater 43cdf0e10cSrcweir //==================================================================== 44cdf0e10cSrcweir ToolboxButtonColorUpdater(sal_uInt16 nId,sal_uInt16 nTbxBtnId,ToolBox * ptrTbx,sal_uInt16 nMode)45cdf0e10cSrcweir ToolboxButtonColorUpdater::ToolboxButtonColorUpdater( 46cdf0e10cSrcweir sal_uInt16 nId, 47cdf0e10cSrcweir sal_uInt16 nTbxBtnId, 48cdf0e10cSrcweir ToolBox* ptrTbx, 49cdf0e10cSrcweir sal_uInt16 nMode ) : 50cdf0e10cSrcweir mnDrawMode ( nMode ), 51cdf0e10cSrcweir mnBtnId ( nTbxBtnId ), 52cdf0e10cSrcweir mnSlotId ( nId ), 53cdf0e10cSrcweir mpTbx ( ptrTbx ), 54cdf0e10cSrcweir maCurColor ( COL_TRANSPARENT ) 55cdf0e10cSrcweir { 56cdf0e10cSrcweir if (mnSlotId == SID_BACKGROUND_COLOR) 57cdf0e10cSrcweir mnDrawMode = TBX_UPDATER_MODE_CHAR_COLOR_NEW; 58cdf0e10cSrcweir DBG_ASSERT( ptrTbx, "ToolBox not found :-(" ); 59cdf0e10cSrcweir mbWasHiContrastMode = ptrTbx ? ( ptrTbx->GetSettings().GetStyleSettings().GetHighContrastMode() ) : sal_False; 60cdf0e10cSrcweir Update(mnSlotId == SID_ATTR_CHAR_COLOR2 ? COL_BLACK : COL_GRAY); 61cdf0e10cSrcweir } 62cdf0e10cSrcweir 63cdf0e10cSrcweir // ----------------------------------------------------------------------- 64cdf0e10cSrcweir ~ToolboxButtonColorUpdater()65cdf0e10cSrcweir ToolboxButtonColorUpdater::~ToolboxButtonColorUpdater() 66cdf0e10cSrcweir { 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir // ----------------------------------------------------------------------- 70cdf0e10cSrcweir Update(const Color & rColor)71cdf0e10cSrcweir void ToolboxButtonColorUpdater::Update( const Color& rColor ) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir Image aImage( mpTbx->GetItemImage( mnBtnId ) ); 74cdf0e10cSrcweir const bool bSizeChanged = ( maBmpSize != aImage.GetSizePixel() ); 75cdf0e10cSrcweir const bool bDisplayModeChanged = ( mbWasHiContrastMode != mpTbx->GetSettings().GetStyleSettings().GetHighContrastMode() ); 76cdf0e10cSrcweir Color aColor( rColor ); 77cdf0e10cSrcweir 78cdf0e10cSrcweir // !!! #109290# Workaround for SetFillColor with COL_AUTO 79cdf0e10cSrcweir if( aColor.GetColor() == COL_AUTO ) 80cdf0e10cSrcweir aColor = Color( COL_TRANSPARENT ); 81cdf0e10cSrcweir 82cdf0e10cSrcweir if( ( maCurColor != aColor ) || bSizeChanged || bDisplayModeChanged ) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir BitmapEx aBmpEx( aImage.GetBitmapEx() ); 85cdf0e10cSrcweir Bitmap aBmp( aBmpEx.GetBitmap() ); 868dcb2a10SAndre Fischer BitmapWriteAccess* pBmpAcc = aBmp.IsEmpty() ? NULL : aBmp.AcquireWriteAccess(); 87cdf0e10cSrcweir 88cdf0e10cSrcweir maBmpSize = aBmp.GetSizePixel(); 89cdf0e10cSrcweir 90cdf0e10cSrcweir if( pBmpAcc ) 91cdf0e10cSrcweir { 92cdf0e10cSrcweir Bitmap aMsk; 93cdf0e10cSrcweir BitmapWriteAccess* pMskAcc; 94cdf0e10cSrcweir const Point aNullPnt; 95cdf0e10cSrcweir 96cdf0e10cSrcweir if( aBmpEx.IsAlpha() ) 97cdf0e10cSrcweir pMskAcc = ( aMsk = aBmpEx.GetAlpha().GetBitmap() ).AcquireWriteAccess(); 98cdf0e10cSrcweir else if( aBmpEx.IsTransparent() ) 99cdf0e10cSrcweir pMskAcc = ( aMsk = aBmpEx.GetMask() ).AcquireWriteAccess(); 100cdf0e10cSrcweir else 101cdf0e10cSrcweir pMskAcc = NULL; 102cdf0e10cSrcweir 103cdf0e10cSrcweir mbWasHiContrastMode = mpTbx->GetSettings().GetStyleSettings().GetHighContrastMode(); 104cdf0e10cSrcweir 105cdf0e10cSrcweir if( mnDrawMode == TBX_UPDATER_MODE_CHAR_COLOR_NEW && ( COL_TRANSPARENT != aColor.GetColor() ) ) 106cdf0e10cSrcweir pBmpAcc->SetLineColor( aColor ); 107cdf0e10cSrcweir else if( mpTbx->GetBackground().GetColor().IsDark() ) 108cdf0e10cSrcweir pBmpAcc->SetLineColor( Color( COL_WHITE ) ); 109cdf0e10cSrcweir else 110cdf0e10cSrcweir pBmpAcc->SetLineColor( Color( COL_BLACK ) ); 111cdf0e10cSrcweir 112*56b35d86SArmin Le Grand // use not only COL_TRANSPARENT for detection of transparence, 113*56b35d86SArmin Le Grand // but the method/way which is designed to do that 114*56b35d86SArmin Le Grand const bool bIsTransparent(0xff == aColor.GetTransparency()); 115*56b35d86SArmin Le Grand maCurColor = aColor; 116*56b35d86SArmin Le Grand 117*56b35d86SArmin Le Grand if(bIsTransparent) 118*56b35d86SArmin Le Grand { 119*56b35d86SArmin Le Grand pBmpAcc->SetFillColor(); 120*56b35d86SArmin Le Grand } 121*56b35d86SArmin Le Grand else 122*56b35d86SArmin Le Grand { 123*56b35d86SArmin Le Grand pBmpAcc->SetFillColor(maCurColor); 124*56b35d86SArmin Le Grand } 125cdf0e10cSrcweir 126cdf0e10cSrcweir if( TBX_UPDATER_MODE_CHAR_COLOR_NEW == mnDrawMode || TBX_UPDATER_MODE_NONE == mnDrawMode ) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir if( TBX_UPDATER_MODE_CHAR_COLOR_NEW == mnDrawMode ) 129cdf0e10cSrcweir { 130cdf0e10cSrcweir if( maBmpSize.Width() <= 16 ) 131cdf0e10cSrcweir maUpdRect = Rectangle( Point( 0,12 ), Size( maBmpSize.Width(), 4 ) ); 13289729eb3SArmin Le Grand else if(76 == maBmpSize.Width() && 12 == maBmpSize.Height()) 13389729eb3SArmin Le Grand { 13489729eb3SArmin Le Grand maUpdRect.Left() = 22; 13589729eb3SArmin Le Grand maUpdRect.Top() = 2; 13689729eb3SArmin Le Grand maUpdRect.Right() = 73; 13789729eb3SArmin Le Grand maUpdRect.Bottom() = 9; 13889729eb3SArmin Le Grand } 13989729eb3SArmin Le Grand else if(30 == maBmpSize.Width() && 16 == maBmpSize.Height()) 14089729eb3SArmin Le Grand { 14189729eb3SArmin Le Grand maUpdRect.Left() = 17; 14289729eb3SArmin Le Grand maUpdRect.Top() = 2; 14389729eb3SArmin Le Grand maUpdRect.Right() = 27; 14489729eb3SArmin Le Grand maUpdRect.Bottom() = 13; 14589729eb3SArmin Le Grand } 146cdf0e10cSrcweir else 147cdf0e10cSrcweir maUpdRect = Rectangle( Point( 1, maBmpSize.Height() - 7 ), Size( maBmpSize.Width() - 2 ,6 ) ); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir else 150cdf0e10cSrcweir { 151cdf0e10cSrcweir if( maBmpSize.Width() <= 16 ) 152cdf0e10cSrcweir maUpdRect = Rectangle( Point( 7, 7 ), Size( 8, 8 ) ); 153cdf0e10cSrcweir else 154cdf0e10cSrcweir maUpdRect = Rectangle( Point( maBmpSize.Width() - 12, maBmpSize.Height() - 12 ), Size( 11, 11 ) ); 155cdf0e10cSrcweir } 156cdf0e10cSrcweir 157cdf0e10cSrcweir pBmpAcc->DrawRect( maUpdRect ); 158cdf0e10cSrcweir 159cdf0e10cSrcweir if( pMskAcc ) 160cdf0e10cSrcweir { 161*56b35d86SArmin Le Grand if( bIsTransparent ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir pMskAcc->SetLineColor( COL_BLACK ); 164cdf0e10cSrcweir pMskAcc->SetFillColor( COL_WHITE ); 165cdf0e10cSrcweir } 166cdf0e10cSrcweir else 167cdf0e10cSrcweir pMskAcc->SetFillColor( COL_BLACK ); 168cdf0e10cSrcweir 169cdf0e10cSrcweir pMskAcc->DrawRect( maUpdRect ); 170cdf0e10cSrcweir } 171cdf0e10cSrcweir } 172cdf0e10cSrcweir else 173cdf0e10cSrcweir { 174cdf0e10cSrcweir DBG_ERROR( "ToolboxButtonColorUpdater::Update: TBX_UPDATER_MODE_CHAR_COLOR / TBX_UPDATER_MODE_CHAR_BACKGROUND" ); 175cdf0e10cSrcweir // !!! DrawChar( aVirDev, aColor ); 176cdf0e10cSrcweir } 177cdf0e10cSrcweir 178cdf0e10cSrcweir aBmp.ReleaseAccess( pBmpAcc ); 179cdf0e10cSrcweir 180cdf0e10cSrcweir if( pMskAcc ) 181cdf0e10cSrcweir aMsk.ReleaseAccess( pMskAcc ); 182cdf0e10cSrcweir 183cdf0e10cSrcweir if( aBmpEx.IsAlpha() ) 184cdf0e10cSrcweir aBmpEx = BitmapEx( aBmp, AlphaMask( aMsk ) ); 185cdf0e10cSrcweir else if( aBmpEx.IsTransparent() ) 186cdf0e10cSrcweir aBmpEx = BitmapEx( aBmp, aMsk ); 187cdf0e10cSrcweir else 188cdf0e10cSrcweir aBmpEx = aBmp; 189cdf0e10cSrcweir 190cdf0e10cSrcweir mpTbx->SetItemImage( mnBtnId, Image( aBmpEx ) ); 191cdf0e10cSrcweir } 192cdf0e10cSrcweir } 193cdf0e10cSrcweir } 194cdf0e10cSrcweir 195cdf0e10cSrcweir // ----------------------------------------------------------------------- 196cdf0e10cSrcweir DrawChar(VirtualDevice & rVirDev,const Color & rCol)197cdf0e10cSrcweir void ToolboxButtonColorUpdater::DrawChar( VirtualDevice& rVirDev, const Color& rCol ) 198cdf0e10cSrcweir { 199cdf0e10cSrcweir Font aOldFont = rVirDev.GetFont(); 200cdf0e10cSrcweir Font aFont = aOldFont; 201cdf0e10cSrcweir Size aSz = aFont.GetSize(); 202cdf0e10cSrcweir aSz.Height() = maBmpSize.Height(); 203cdf0e10cSrcweir aFont.SetSize( aSz ); 204cdf0e10cSrcweir aFont.SetWeight( WEIGHT_BOLD ); 205cdf0e10cSrcweir 206cdf0e10cSrcweir if ( mnDrawMode == TBX_UPDATER_MODE_CHAR_COLOR ) 207cdf0e10cSrcweir { 208cdf0e10cSrcweir aFont.SetColor( rCol ); 209cdf0e10cSrcweir aFont.SetFillColor( Color( IMAGE_COL_TRANSPARENT ) ); 210cdf0e10cSrcweir } 211cdf0e10cSrcweir else 212cdf0e10cSrcweir { 213cdf0e10cSrcweir rVirDev.SetLineColor(); 214cdf0e10cSrcweir rVirDev.SetFillColor( rCol ); 215cdf0e10cSrcweir Rectangle aRect( Point(0,0), maBmpSize ); 216cdf0e10cSrcweir rVirDev.DrawRect( aRect ); 217cdf0e10cSrcweir aFont.SetFillColor( rCol ); 218cdf0e10cSrcweir } 219cdf0e10cSrcweir rVirDev.SetFont( aFont ); 220cdf0e10cSrcweir Size aTxtSize(rVirDev.GetTextWidth( 'A' ), rVirDev.GetTextHeight()); 221cdf0e10cSrcweir Point aPos( ( maBmpSize.Width() - aTxtSize.Width() ) / 2, 222cdf0e10cSrcweir ( maBmpSize.Height() - aTxtSize.Height() ) / 2 ); 223cdf0e10cSrcweir 224cdf0e10cSrcweir rVirDev.DrawText( aPos, 'A' ); 225cdf0e10cSrcweir rVirDev.SetFont( aOldFont ); 226cdf0e10cSrcweir } 227cdf0e10cSrcweir 228cdf0e10cSrcweir //........................................................................ 229cdf0e10cSrcweir } // namespace svx 230cdf0e10cSrcweir //........................................................................ 231