1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <svx/tbxcolorupdate.hxx>
22 #include <svx/svxids.hrc>
24 #include <vcl/toolbox.hxx>
25 #include <vcl/bmpacc.hxx>
26 #include <tools/debug.hxx>
28 //........................................................................
31 //........................................................................
33 //====================================================================
34 //= ToolboxButtonColorUpdater
35 //====================================================================
37 The initial color shown on the button is set in /core/svx/source/tbxctrls/tbxcolorupdate.cxx
38 (ToolboxButtonColorUpdater::ToolboxButtonColorUpdater()) .
39 The initial color used by the button is set in /core/svx/source/tbxcntrls/tbcontrl.cxx
40 (SvxColorExtToolBoxControl::SvxColorExtToolBoxControl())
41 and in case of writer for text(background)color also in /core/sw/source/ui/docvw/edtwin.cxx
42 (SwEditWin::aTextBackColor and SwEditWin::aTextBackColor)
45 ToolboxButtonColorUpdater::ToolboxButtonColorUpdater(
51 mnBtnId ( nTbxBtnId
),
54 maCurColor ( COL_TRANSPARENT
)
56 if (mnSlotId
== SID_BACKGROUND_COLOR
)
57 mnDrawMode
= TBX_UPDATER_MODE_CHAR_COLOR_NEW
;
58 DBG_ASSERT( ptrTbx
, "ToolBox not found :-(" );
59 mbWasHiContrastMode
= ptrTbx
? ( ptrTbx
->GetSettings().GetStyleSettings().GetHighContrastMode() ) : sal_False
;
62 case SID_ATTR_CHAR_COLOR
:
63 case SID_ATTR_CHAR_COLOR2
:
66 case SID_FRAME_LINECOLOR
:
69 case SID_ATTR_CHAR_COLOR_BACKGROUND
:
70 case SID_BACKGROUND_COLOR
:
74 Update( COL_TRANSPARENT
);
78 // -----------------------------------------------------------------------
80 ToolboxButtonColorUpdater::~ToolboxButtonColorUpdater()
84 // -----------------------------------------------------------------------
86 void ToolboxButtonColorUpdater::Update( const Color
& rColor
)
88 Image
aImage( mpTbx
->GetItemImage( mnBtnId
) );
89 const bool bSizeChanged
= ( maBmpSize
!= aImage
.GetSizePixel() );
90 const bool bDisplayModeChanged
= ( mbWasHiContrastMode
!= mpTbx
->GetSettings().GetStyleSettings().GetHighContrastMode() );
91 Color
aColor( rColor
);
93 // !!! #109290# Workaround for SetFillColor with COL_AUTO
94 if( aColor
.GetColor() == COL_AUTO
)
95 aColor
= Color( COL_TRANSPARENT
);
97 if( ( maCurColor
!= aColor
) || bSizeChanged
|| bDisplayModeChanged
)
99 BitmapEx
aBmpEx( aImage
.GetBitmapEx() );
100 Bitmap
aBmp( aBmpEx
.GetBitmap() );
101 BitmapWriteAccess
* pBmpAcc
= aBmp
.IsEmpty() ? NULL
: aBmp
.AcquireWriteAccess();
103 maBmpSize
= aBmp
.GetSizePixel();
108 BitmapWriteAccess
* pMskAcc
;
110 if( aBmpEx
.IsAlpha() )
111 pMskAcc
= ( aMsk
= aBmpEx
.GetAlpha().GetBitmap() ).AcquireWriteAccess();
112 else if( aBmpEx
.IsTransparent() )
113 pMskAcc
= ( aMsk
= aBmpEx
.GetMask() ).AcquireWriteAccess();
117 mbWasHiContrastMode
= mpTbx
->GetSettings().GetStyleSettings().GetHighContrastMode();
119 if( mnDrawMode
== TBX_UPDATER_MODE_CHAR_COLOR_NEW
&& ( COL_TRANSPARENT
!= aColor
.GetColor() ) )
120 pBmpAcc
->SetLineColor( aColor
);
121 else if( mpTbx
->GetBackground().GetColor().IsDark() )
122 pBmpAcc
->SetLineColor( Color( COL_WHITE
) );
124 pBmpAcc
->SetLineColor( Color( COL_BLACK
) );
126 pBmpAcc
->SetFillColor( maCurColor
= aColor
);
128 if( TBX_UPDATER_MODE_CHAR_COLOR_NEW
== mnDrawMode
|| TBX_UPDATER_MODE_NONE
== mnDrawMode
)
130 if( TBX_UPDATER_MODE_CHAR_COLOR_NEW
== mnDrawMode
)
132 if( maBmpSize
.Width() <= 16 )
133 maUpdRect
= Rectangle( Point( 0,12 ), Size( maBmpSize
.Width(), 4 ) );
134 else if(76 == maBmpSize
.Width() && 12 == maBmpSize
.Height())
136 maUpdRect
.Left() = 22;
138 maUpdRect
.Right() = 73;
139 maUpdRect
.Bottom() = 9;
141 else if(30 == maBmpSize
.Width() && 16 == maBmpSize
.Height())
143 maUpdRect
.Left() = 17;
145 maUpdRect
.Right() = 27;
146 maUpdRect
.Bottom() = 13;
149 maUpdRect
= Rectangle( Point( 1, maBmpSize
.Height() - 7 ), Size( maBmpSize
.Width() - 2 ,6 ) );
153 if( maBmpSize
.Width() <= 16 )
154 maUpdRect
= Rectangle( Point( 7, 7 ), Size( 8, 8 ) );
156 maUpdRect
= Rectangle( Point( maBmpSize
.Width() - 12, maBmpSize
.Height() - 12 ), Size( 11, 11 ) );
159 pBmpAcc
->DrawRect( maUpdRect
);
163 if( COL_TRANSPARENT
== aColor
.GetColor() )
165 pMskAcc
->SetLineColor( COL_BLACK
);
166 pMskAcc
->SetFillColor( COL_WHITE
);
169 pMskAcc
->SetFillColor( COL_BLACK
);
171 pMskAcc
->DrawRect( maUpdRect
);
176 OSL_FAIL( "ToolboxButtonColorUpdater::Update: TBX_UPDATER_MODE_CHAR_COLOR / TBX_UPDATER_MODE_CHAR_BACKGROUND" );
177 // !!! DrawChar( aVirDev, aColor );
180 aBmp
.ReleaseAccess( pBmpAcc
);
183 aMsk
.ReleaseAccess( pMskAcc
);
185 if( aBmpEx
.IsAlpha() )
186 aBmpEx
= BitmapEx( aBmp
, AlphaMask( aMsk
) );
187 else if( aBmpEx
.IsTransparent() )
188 aBmpEx
= BitmapEx( aBmp
, aMsk
);
192 mpTbx
->SetItemImage( mnBtnId
, Image( aBmpEx
) );
197 //........................................................................
199 //........................................................................
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */