update dev300-m58
[ooovba.git] / svx / source / tbxctrls / tbxcolorupdate.cxx
blobd19acf5a9fad693464ed2bbe779733770a05abdd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tbxcolorupdate.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <svx/tbxcolorupdate.hxx>
35 #include <svx/svxids.hrc>
37 #include <vcl/toolbox.hxx>
38 #include <vcl/bmpacc.hxx>
39 #include <tools/debug.hxx>
41 #define IMAGE_COL_TRANSPARENT COL_LIGHTMAGENTA
43 //........................................................................
44 namespace svx
46 //........................................................................
48 //====================================================================
49 //= ToolboxButtonColorUpdater
50 //====================================================================
52 ToolboxButtonColorUpdater::ToolboxButtonColorUpdater(
53 USHORT nId,
54 USHORT nTbxBtnId,
55 ToolBox* ptrTbx,
56 USHORT nMode ) :
57 mnDrawMode ( nMode ),
58 mnBtnId ( nTbxBtnId ),
59 mnSlotId ( nId ),
60 mpTbx ( ptrTbx ),
61 maCurColor ( COL_TRANSPARENT )
63 if (mnSlotId == SID_BACKGROUND_COLOR)
64 mnDrawMode = TBX_UPDATER_MODE_CHAR_COLOR_NEW;
65 DBG_ASSERT( ptrTbx, "ToolBox not found :-(" );
66 mbWasHiContrastMode = ptrTbx ? ( ptrTbx->GetBackground().GetColor().IsDark() ) : FALSE;
67 Update(mnSlotId == SID_ATTR_CHAR_COLOR2 ? COL_BLACK : COL_GRAY);
70 // -----------------------------------------------------------------------
72 ToolboxButtonColorUpdater::~ToolboxButtonColorUpdater()
76 // -----------------------------------------------------------------------
78 void ToolboxButtonColorUpdater::Update( const Color& rColor )
80 Image aImage( mpTbx->GetItemImage( mnBtnId ) );
81 const bool bSizeChanged = ( maBmpSize != aImage.GetSizePixel() );
82 const bool bDisplayModeChanged = ( mbWasHiContrastMode != mpTbx->GetBackground().GetColor().IsDark() );
83 Color aColor( rColor );
85 // !!! #109290# Workaround for SetFillColor with COL_AUTO
86 if( aColor.GetColor() == COL_AUTO )
87 aColor = Color( COL_TRANSPARENT );
89 if( ( maCurColor != aColor ) || bSizeChanged || bDisplayModeChanged )
91 BitmapEx aBmpEx( aImage.GetBitmapEx() );
92 Bitmap aBmp( aBmpEx.GetBitmap() );
93 BitmapWriteAccess* pBmpAcc = aBmp.AcquireWriteAccess();
95 maBmpSize = aBmp.GetSizePixel();
97 if( pBmpAcc )
99 Bitmap aMsk;
100 BitmapWriteAccess* pMskAcc;
101 const Point aNullPnt;
103 if( aBmpEx.IsAlpha() )
104 pMskAcc = ( aMsk = aBmpEx.GetAlpha().GetBitmap() ).AcquireWriteAccess();
105 else if( aBmpEx.IsTransparent() )
106 pMskAcc = ( aMsk = aBmpEx.GetMask() ).AcquireWriteAccess();
107 else
108 pMskAcc = NULL;
110 mbWasHiContrastMode = mpTbx->GetBackground().GetColor().IsDark();
112 if( mnDrawMode == TBX_UPDATER_MODE_CHAR_COLOR_NEW && ( COL_TRANSPARENT != aColor.GetColor() ) )
113 pBmpAcc->SetLineColor( aColor );
114 else if( mpTbx->GetBackground().GetColor().IsDark() )
115 pBmpAcc->SetLineColor( Color( COL_WHITE ) );
116 else
117 pBmpAcc->SetLineColor( Color( COL_BLACK ) );
119 pBmpAcc->SetFillColor( maCurColor = aColor );
121 if( TBX_UPDATER_MODE_CHAR_COLOR_NEW == mnDrawMode || TBX_UPDATER_MODE_NONE == mnDrawMode )
123 if( TBX_UPDATER_MODE_CHAR_COLOR_NEW == mnDrawMode )
125 if( maBmpSize.Width() <= 16 )
126 maUpdRect = Rectangle( Point( 0,12 ), Size( maBmpSize.Width(), 4 ) );
127 else
128 maUpdRect = Rectangle( Point( 1, maBmpSize.Height() - 7 ), Size( maBmpSize.Width() - 2 ,6 ) );
130 else
132 if( maBmpSize.Width() <= 16 )
133 maUpdRect = Rectangle( Point( 7, 7 ), Size( 8, 8 ) );
134 else
135 maUpdRect = Rectangle( Point( maBmpSize.Width() - 12, maBmpSize.Height() - 12 ), Size( 11, 11 ) );
138 pBmpAcc->DrawRect( maUpdRect );
140 if( pMskAcc )
142 if( COL_TRANSPARENT == aColor.GetColor() )
144 pMskAcc->SetLineColor( COL_BLACK );
145 pMskAcc->SetFillColor( COL_WHITE );
147 else
148 pMskAcc->SetFillColor( COL_BLACK );
150 pMskAcc->DrawRect( maUpdRect );
153 else
155 DBG_ERROR( "ToolboxButtonColorUpdater::Update: TBX_UPDATER_MODE_CHAR_COLOR / TBX_UPDATER_MODE_CHAR_BACKGROUND" );
156 // !!! DrawChar( aVirDev, aColor );
159 aBmp.ReleaseAccess( pBmpAcc );
161 if( pMskAcc )
162 aMsk.ReleaseAccess( pMskAcc );
164 if( aBmpEx.IsAlpha() )
165 aBmpEx = BitmapEx( aBmp, AlphaMask( aMsk ) );
166 else if( aBmpEx.IsTransparent() )
167 aBmpEx = BitmapEx( aBmp, aMsk );
168 else
169 aBmpEx = aBmp;
171 mpTbx->SetItemImage( mnBtnId, Image( aBmpEx ) );
176 // -----------------------------------------------------------------------
178 void ToolboxButtonColorUpdater::DrawChar( VirtualDevice& rVirDev, const Color& rCol )
180 Font aOldFont = rVirDev.GetFont();
181 Font aFont = aOldFont;
182 Size aSz = aFont.GetSize();
183 aSz.Height() = maBmpSize.Height();
184 aFont.SetSize( aSz );
185 aFont.SetWeight( WEIGHT_BOLD );
187 if ( mnDrawMode == TBX_UPDATER_MODE_CHAR_COLOR )
189 aFont.SetColor( rCol );
190 aFont.SetFillColor( Color( IMAGE_COL_TRANSPARENT ) );
192 else
194 rVirDev.SetLineColor();
195 rVirDev.SetFillColor( rCol );
196 Rectangle aRect( Point(0,0), maBmpSize );
197 rVirDev.DrawRect( aRect );
198 aFont.SetFillColor( rCol );
200 rVirDev.SetFont( aFont );
201 Size aTxtSize(rVirDev.GetTextWidth( 'A' ), rVirDev.GetTextHeight());
202 Point aPos( ( maBmpSize.Width() - aTxtSize.Width() ) / 2,
203 ( maBmpSize.Height() - aTxtSize.Height() ) / 2 );
205 rVirDev.DrawText( aPos, 'A' );
206 rVirDev.SetFont( aOldFont );
209 //........................................................................
210 } // namespace svx
211 //........................................................................