Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include <svx/tbxcolorupdate.hxx>
22 : #include <svx/svxids.hrc>
23 :
24 : #include <vcl/toolbox.hxx>
25 : #include <vcl/bmpacc.hxx>
26 : #include <tools/debug.hxx>
27 :
28 : //........................................................................
29 : namespace svx
30 : {
31 : //........................................................................
32 :
33 : //====================================================================
34 : //= ToolboxButtonColorUpdater
35 : //====================================================================
36 : /* Note:
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)
43 : */
44 :
45 0 : ToolboxButtonColorUpdater::ToolboxButtonColorUpdater(
46 : sal_uInt16 nId,
47 : sal_uInt16 nTbxBtnId,
48 : ToolBox* ptrTbx,
49 : sal_uInt16 nMode ) :
50 : mnDrawMode ( nMode ),
51 : mnBtnId ( nTbxBtnId ),
52 : mnSlotId ( nId ),
53 : mpTbx ( ptrTbx ),
54 0 : maCurColor ( COL_TRANSPARENT )
55 : {
56 0 : if (mnSlotId == SID_BACKGROUND_COLOR)
57 0 : mnDrawMode = TBX_UPDATER_MODE_CHAR_COLOR_NEW;
58 : DBG_ASSERT( ptrTbx, "ToolBox not found :-(" );
59 0 : mbWasHiContrastMode = ptrTbx ? ( ptrTbx->GetSettings().GetStyleSettings().GetHighContrastMode() ) : sal_False;
60 0 : switch( mnSlotId )
61 : {
62 : case SID_ATTR_CHAR_COLOR :
63 : case SID_ATTR_CHAR_COLOR2 :
64 0 : Update( COL_RED );
65 0 : break;
66 : case SID_FRAME_LINECOLOR :
67 0 : Update( COL_BLUE );
68 0 : break;
69 : case SID_ATTR_CHAR_COLOR_BACKGROUND :
70 : case SID_BACKGROUND_COLOR :
71 0 : Update( COL_YELLOW );
72 0 : break;
73 : default :
74 0 : Update( COL_TRANSPARENT );
75 : }
76 0 : }
77 :
78 : // -----------------------------------------------------------------------
79 :
80 0 : ToolboxButtonColorUpdater::~ToolboxButtonColorUpdater()
81 : {
82 0 : }
83 :
84 : // -----------------------------------------------------------------------
85 :
86 0 : void ToolboxButtonColorUpdater::Update( const Color& rColor )
87 : {
88 0 : Image aImage( mpTbx->GetItemImage( mnBtnId ) );
89 0 : const bool bSizeChanged = ( maBmpSize != aImage.GetSizePixel() );
90 0 : const bool bDisplayModeChanged = ( mbWasHiContrastMode != mpTbx->GetSettings().GetStyleSettings().GetHighContrastMode() );
91 0 : Color aColor( rColor );
92 :
93 : // !!! #109290# Workaround for SetFillColor with COL_AUTO
94 0 : if( aColor.GetColor() == COL_AUTO )
95 0 : aColor = Color( COL_TRANSPARENT );
96 :
97 0 : if( ( maCurColor != aColor ) || bSizeChanged || bDisplayModeChanged )
98 : {
99 0 : BitmapEx aBmpEx( aImage.GetBitmapEx() );
100 0 : Bitmap aBmp( aBmpEx.GetBitmap() );
101 0 : BitmapWriteAccess* pBmpAcc = aBmp.AcquireWriteAccess();
102 :
103 0 : maBmpSize = aBmp.GetSizePixel();
104 :
105 0 : if( pBmpAcc )
106 : {
107 0 : Bitmap aMsk;
108 : BitmapWriteAccess* pMskAcc;
109 0 : const Point aNullPnt;
110 :
111 0 : if( aBmpEx.IsAlpha() )
112 0 : pMskAcc = ( aMsk = aBmpEx.GetAlpha().GetBitmap() ).AcquireWriteAccess();
113 0 : else if( aBmpEx.IsTransparent() )
114 0 : pMskAcc = ( aMsk = aBmpEx.GetMask() ).AcquireWriteAccess();
115 : else
116 0 : pMskAcc = NULL;
117 :
118 0 : mbWasHiContrastMode = mpTbx->GetSettings().GetStyleSettings().GetHighContrastMode();
119 :
120 0 : if( mnDrawMode == TBX_UPDATER_MODE_CHAR_COLOR_NEW && ( COL_TRANSPARENT != aColor.GetColor() ) )
121 0 : pBmpAcc->SetLineColor( aColor );
122 0 : else if( mpTbx->GetBackground().GetColor().IsDark() )
123 0 : pBmpAcc->SetLineColor( Color( COL_WHITE ) );
124 : else
125 0 : pBmpAcc->SetLineColor( Color( COL_BLACK ) );
126 :
127 0 : pBmpAcc->SetFillColor( maCurColor = aColor );
128 :
129 0 : if( TBX_UPDATER_MODE_CHAR_COLOR_NEW == mnDrawMode || TBX_UPDATER_MODE_NONE == mnDrawMode )
130 : {
131 0 : if( TBX_UPDATER_MODE_CHAR_COLOR_NEW == mnDrawMode )
132 : {
133 0 : if( maBmpSize.Width() <= 16 )
134 0 : maUpdRect = Rectangle( Point( 0,12 ), Size( maBmpSize.Width(), 4 ) );
135 : else
136 0 : maUpdRect = Rectangle( Point( 1, maBmpSize.Height() - 7 ), Size( maBmpSize.Width() - 2 ,6 ) );
137 : }
138 : else
139 : {
140 0 : if( maBmpSize.Width() <= 16 )
141 0 : maUpdRect = Rectangle( Point( 7, 7 ), Size( 8, 8 ) );
142 : else
143 0 : maUpdRect = Rectangle( Point( maBmpSize.Width() - 12, maBmpSize.Height() - 12 ), Size( 11, 11 ) );
144 : }
145 :
146 0 : pBmpAcc->DrawRect( maUpdRect );
147 :
148 0 : if( pMskAcc )
149 : {
150 0 : if( COL_TRANSPARENT == aColor.GetColor() )
151 : {
152 0 : pMskAcc->SetLineColor( COL_BLACK );
153 0 : pMskAcc->SetFillColor( COL_WHITE );
154 : }
155 : else
156 0 : pMskAcc->SetFillColor( COL_BLACK );
157 :
158 0 : pMskAcc->DrawRect( maUpdRect );
159 : }
160 : }
161 : else
162 : {
163 : OSL_FAIL( "ToolboxButtonColorUpdater::Update: TBX_UPDATER_MODE_CHAR_COLOR / TBX_UPDATER_MODE_CHAR_BACKGROUND" );
164 : // !!! DrawChar( aVirDev, aColor );
165 : }
166 :
167 0 : aBmp.ReleaseAccess( pBmpAcc );
168 :
169 0 : if( pMskAcc )
170 0 : aMsk.ReleaseAccess( pMskAcc );
171 :
172 0 : if( aBmpEx.IsAlpha() )
173 0 : aBmpEx = BitmapEx( aBmp, AlphaMask( aMsk ) );
174 0 : else if( aBmpEx.IsTransparent() )
175 0 : aBmpEx = BitmapEx( aBmp, aMsk );
176 : else
177 0 : aBmpEx = aBmp;
178 :
179 0 : mpTbx->SetItemImage( mnBtnId, Image( aBmpEx ) );
180 0 : }
181 0 : }
182 0 : }
183 :
184 : //........................................................................
185 : } // namespace svx
186 : //........................................................................
187 :
188 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|