Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <svx/tbxcolorupdate.hxx>
31 : : #include <svx/svxids.hrc>
32 : :
33 : : #include <vcl/toolbox.hxx>
34 : : #include <vcl/bmpacc.hxx>
35 : : #include <tools/debug.hxx>
36 : :
37 : : //........................................................................
38 : : namespace svx
39 : : {
40 : : //........................................................................
41 : :
42 : : //====================================================================
43 : : //= ToolboxButtonColorUpdater
44 : : //====================================================================
45 : : /* Note:
46 : : The initial color shown on the button is set in /core/svx/source/tbxctrls/tbxcolorupdate.cxx
47 : : (ToolboxButtonColorUpdater::ToolboxButtonColorUpdater()) .
48 : : The initial color used by the button is set in /core/svx/source/tbxcntrls/tbcontrl.cxx
49 : : (SvxColorExtToolBoxControl::SvxColorExtToolBoxControl())
50 : : and in case of writer for text(background)color also in /core/sw/source/ui/docvw/edtwin.cxx
51 : : (SwEditWin::aTextBackColor and SwEditWin::aTextBackColor)
52 : : */
53 : :
54 : 2891 : ToolboxButtonColorUpdater::ToolboxButtonColorUpdater(
55 : : sal_uInt16 nId,
56 : : sal_uInt16 nTbxBtnId,
57 : : ToolBox* ptrTbx,
58 : : sal_uInt16 nMode ) :
59 : : mnDrawMode ( nMode ),
60 : : mnBtnId ( nTbxBtnId ),
61 : : mnSlotId ( nId ),
62 : : mpTbx ( ptrTbx ),
63 : 2891 : maCurColor ( COL_TRANSPARENT )
64 : : {
65 [ + + ]: 2891 : if (mnSlotId == SID_BACKGROUND_COLOR)
66 : 965 : mnDrawMode = TBX_UPDATER_MODE_CHAR_COLOR_NEW;
67 : : DBG_ASSERT( ptrTbx, "ToolBox not found :-(" );
68 [ + - ]: 2891 : mbWasHiContrastMode = ptrTbx ? ( ptrTbx->GetSettings().GetStyleSettings().GetHighContrastMode() ) : sal_False;
69 [ + + + - ]: 2891 : switch( mnSlotId )
70 : : {
71 : : case SID_ATTR_CHAR_COLOR :
72 : : case SID_ATTR_CHAR_COLOR2 :
73 [ + - ]: 961 : Update( COL_RED );
74 : 961 : break;
75 : : case SID_FRAME_LINECOLOR :
76 [ + - ]: 203 : Update( COL_BLUE );
77 : 203 : break;
78 : : case SID_ATTR_CHAR_COLOR_BACKGROUND :
79 : : case SID_BACKGROUND_COLOR :
80 [ + - ]: 1727 : Update( COL_YELLOW );
81 : 1727 : break;
82 : : default :
83 [ # # ]: 0 : Update( COL_TRANSPARENT );
84 : : }
85 : 2891 : }
86 : :
87 : : // -----------------------------------------------------------------------
88 : :
89 : 2891 : ToolboxButtonColorUpdater::~ToolboxButtonColorUpdater()
90 : : {
91 : 2891 : }
92 : :
93 : : // -----------------------------------------------------------------------
94 : :
95 : 2891 : void ToolboxButtonColorUpdater::Update( const Color& rColor )
96 : : {
97 [ + - ]: 2891 : Image aImage( mpTbx->GetItemImage( mnBtnId ) );
98 [ + - ]: 2891 : const bool bSizeChanged = ( maBmpSize != aImage.GetSizePixel() );
99 : 2891 : const bool bDisplayModeChanged = ( mbWasHiContrastMode != mpTbx->GetSettings().GetStyleSettings().GetHighContrastMode() );
100 : 2891 : Color aColor( rColor );
101 : :
102 : : // !!! #109290# Workaround for SetFillColor with COL_AUTO
103 [ - + ]: 2891 : if( aColor.GetColor() == COL_AUTO )
104 : 0 : aColor = Color( COL_TRANSPARENT );
105 : :
106 [ - + ][ # # ]: 2891 : if( ( maCurColor != aColor ) || bSizeChanged || bDisplayModeChanged )
[ # # ][ + - ]
107 : : {
108 [ + - ]: 2891 : BitmapEx aBmpEx( aImage.GetBitmapEx() );
109 [ + - ]: 2891 : Bitmap aBmp( aBmpEx.GetBitmap() );
110 [ + - ]: 2891 : BitmapWriteAccess* pBmpAcc = aBmp.AcquireWriteAccess();
111 : :
112 [ + - ]: 2891 : maBmpSize = aBmp.GetSizePixel();
113 : :
114 [ + - ]: 2891 : if( pBmpAcc )
115 : : {
116 [ + - ]: 2891 : Bitmap aMsk;
117 : : BitmapWriteAccess* pMskAcc;
118 : 2891 : const Point aNullPnt;
119 : :
120 [ + + ][ + - ]: 2891 : if( aBmpEx.IsAlpha() )
121 [ + - ][ + - ]: 1926 : pMskAcc = ( aMsk = aBmpEx.GetAlpha().GetBitmap() ).AcquireWriteAccess();
[ + - ][ + - ]
[ + - ][ + - ]
122 [ + - ][ - + ]: 965 : else if( aBmpEx.IsTransparent() )
123 [ # # ][ # # ]: 0 : pMskAcc = ( aMsk = aBmpEx.GetMask() ).AcquireWriteAccess();
[ # # ][ # # ]
124 : : else
125 : 965 : pMskAcc = NULL;
126 : :
127 : 2891 : mbWasHiContrastMode = mpTbx->GetSettings().GetStyleSettings().GetHighContrastMode();
128 : :
129 [ + - ][ + + ]: 2891 : if( mnDrawMode == TBX_UPDATER_MODE_CHAR_COLOR_NEW && ( COL_TRANSPARENT != aColor.GetColor() ) )
[ + + ]
130 [ + - ]: 2688 : pBmpAcc->SetLineColor( aColor );
131 [ + - ][ + - ]: 203 : else if( mpTbx->GetBackground().GetColor().IsDark() )
[ - + ]
132 [ # # ]: 0 : pBmpAcc->SetLineColor( Color( COL_WHITE ) );
133 : : else
134 [ + - ]: 203 : pBmpAcc->SetLineColor( Color( COL_BLACK ) );
135 : :
136 [ + - ]: 2891 : pBmpAcc->SetFillColor( maCurColor = aColor );
137 : :
138 [ + + ][ + - ]: 2891 : if( TBX_UPDATER_MODE_CHAR_COLOR_NEW == mnDrawMode || TBX_UPDATER_MODE_NONE == mnDrawMode )
139 : : {
140 [ + + ]: 2891 : if( TBX_UPDATER_MODE_CHAR_COLOR_NEW == mnDrawMode )
141 : : {
142 [ + - ]: 2688 : if( maBmpSize.Width() <= 16 )
143 [ + - ]: 2688 : maUpdRect = Rectangle( Point( 0,12 ), Size( maBmpSize.Width(), 4 ) );
144 : : else
145 [ # # ]: 0 : maUpdRect = Rectangle( Point( 1, maBmpSize.Height() - 7 ), Size( maBmpSize.Width() - 2 ,6 ) );
146 : : }
147 : : else
148 : : {
149 [ + - ]: 203 : if( maBmpSize.Width() <= 16 )
150 [ + - ]: 203 : maUpdRect = Rectangle( Point( 7, 7 ), Size( 8, 8 ) );
151 : : else
152 [ # # ]: 0 : maUpdRect = Rectangle( Point( maBmpSize.Width() - 12, maBmpSize.Height() - 12 ), Size( 11, 11 ) );
153 : : }
154 : :
155 [ + - ]: 2891 : pBmpAcc->DrawRect( maUpdRect );
156 : :
157 [ + + ]: 2891 : if( pMskAcc )
158 : : {
159 [ - + ]: 1926 : if( COL_TRANSPARENT == aColor.GetColor() )
160 : : {
161 [ # # ]: 0 : pMskAcc->SetLineColor( COL_BLACK );
162 [ # # ]: 0 : pMskAcc->SetFillColor( COL_WHITE );
163 : : }
164 : : else
165 [ + - ]: 1926 : pMskAcc->SetFillColor( COL_BLACK );
166 : :
167 [ + - ]: 1926 : pMskAcc->DrawRect( maUpdRect );
168 : : }
169 : : }
170 : : else
171 : : {
172 : : OSL_FAIL( "ToolboxButtonColorUpdater::Update: TBX_UPDATER_MODE_CHAR_COLOR / TBX_UPDATER_MODE_CHAR_BACKGROUND" );
173 : : // !!! DrawChar( aVirDev, aColor );
174 : : }
175 : :
176 [ + - ]: 2891 : aBmp.ReleaseAccess( pBmpAcc );
177 : :
178 [ + + ]: 2891 : if( pMskAcc )
179 [ + - ]: 1926 : aMsk.ReleaseAccess( pMskAcc );
180 : :
181 [ + - ][ + + ]: 2891 : if( aBmpEx.IsAlpha() )
182 [ + - ][ + - ]: 1926 : aBmpEx = BitmapEx( aBmp, AlphaMask( aMsk ) );
[ + - ][ + - ]
[ + - ]
183 [ + - ][ - + ]: 965 : else if( aBmpEx.IsTransparent() )
184 [ # # ][ # # ]: 0 : aBmpEx = BitmapEx( aBmp, aMsk );
[ # # ]
185 : : else
186 [ + - ][ + - ]: 965 : aBmpEx = aBmp;
[ + - ]
187 : :
188 [ + - ][ + - ]: 2891 : mpTbx->SetItemImage( mnBtnId, Image( aBmpEx ) );
[ + - ][ + - ]
189 [ + - ][ + - ]: 2891 : }
190 [ + - ]: 2891 : }
191 : 2891 : }
192 : :
193 : : //........................................................................
194 : : } // namespace svx
195 : : //........................................................................
196 : :
197 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|