LCOV - code coverage report
Current view: top level - svx/source/tbxctrls - tbxcolorupdate.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 67 0.0 %
Date: 2014-04-14 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          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 <vcl/settings.hxx>
      27             : #include <tools/debug.hxx>
      28             : 
      29             : 
      30             : namespace svx
      31             : {
      32             : 
      33             : 
      34             : 
      35             :     //= ToolboxButtonColorUpdater
      36             : 
      37             :     /* Note:
      38             :        The initial color shown on the button is set in /core/svx/source/tbxctrls/tbxcolorupdate.cxx
      39             :        (ToolboxButtonColorUpdater::ToolboxButtonColorUpdater()) .
      40             :        The initial color used by the button is set in /core/svx/source/tbxctrls/tbcontrl.cxx
      41             :        (SvxColorExtToolBoxControl::SvxColorExtToolBoxControl())
      42             :        and in case of writer for text(background)color also in /core/sw/source/ui/docvw/edtwin.cxx
      43             :        (SwEditWin::aTextBackColor and SwEditWin::aTextBackColor)
      44             :      */
      45             : 
      46           0 :     ToolboxButtonColorUpdater::ToolboxButtonColorUpdater(
      47             :         sal_uInt16 nId,
      48             :         sal_uInt16 nTbxBtnId,
      49             :         ToolBox* ptrTbx) :
      50             :         mnBtnId           ( nTbxBtnId ),
      51             :         mnSlotId           ( nId ),
      52             :         mpTbx             ( ptrTbx ),
      53           0 :         maCurColor        ( COL_TRANSPARENT )
      54             :     {
      55             :         DBG_ASSERT( ptrTbx, "ToolBox not found :-(" );
      56           0 :         mbWasHiContrastMode = ptrTbx ? ( ptrTbx->GetSettings().GetStyleSettings().GetHighContrastMode() ) : sal_False;
      57           0 :         switch( mnSlotId )
      58             :         {
      59             :             case SID_ATTR_CHAR_COLOR  :
      60             :             case SID_ATTR_CHAR_COLOR2 :
      61           0 :                 Update( COL_RED );
      62           0 :                 break;
      63             :             case SID_FRAME_LINECOLOR  :
      64           0 :                 Update( COL_BLUE );
      65           0 :                 break;
      66             :             case SID_ATTR_CHAR_COLOR_BACKGROUND :
      67             :             case SID_BACKGROUND_COLOR :
      68           0 :                 Update( COL_YELLOW );
      69           0 :                 break;
      70             :             default :
      71           0 :                 Update( COL_TRANSPARENT );
      72             :         }
      73           0 :     }
      74             : 
      75             : 
      76             : 
      77           0 :     ToolboxButtonColorUpdater::~ToolboxButtonColorUpdater()
      78             :     {
      79           0 :     }
      80             : 
      81             : 
      82             : 
      83           0 :     void ToolboxButtonColorUpdater::Update( const Color& rColor )
      84             :     {
      85           0 :         Image       aImage( mpTbx->GetItemImage( mnBtnId ) );
      86           0 :         Size        aItemSize( mpTbx->GetItemContentSize( mnBtnId ) );
      87             : 
      88           0 :         const bool  bSizeChanged = ( maBmpSize != aItemSize );
      89           0 :         const bool  bDisplayModeChanged = ( mbWasHiContrastMode != mpTbx->GetSettings().GetStyleSettings().GetHighContrastMode() );
      90           0 :         Color       aColor( rColor );
      91             : 
      92             :         // !!! #109290# Workaround for SetFillColor with COL_AUTO
      93           0 :         if( aColor.GetColor() == COL_AUTO )
      94           0 :             aColor = Color( COL_TRANSPARENT );
      95             : 
      96             :         // For a shape selected in 'Draw', when color selected in Sidebar > Line > Color
      97             :         // is COL_BLACK, then (maCurColor != aColor) becomes 'false', therefore we take
      98             :         // explicit care of COL_BLACK from the last argument in the condition so that the
      99             :         // Update() does its routine job appropriately !
     100           0 :         if( ( maCurColor != aColor ) || bSizeChanged || bDisplayModeChanged || ( aColor == COL_BLACK ) )
     101             :         {
     102             :             // create an empty bitmap, and copy the original bitmap inside
     103             :             // (so that it grows in case the original bitmap was smaller)
     104           0 :             sal_uInt8 nAlpha = 255;
     105           0 :             BitmapEx aBmpEx( Bitmap( aItemSize, 24 ), AlphaMask( aItemSize, &nAlpha ) );
     106           0 :             BitmapEx aSource( aImage.GetBitmapEx() );
     107             :             Rectangle aRect( Point( 0, 0 ),
     108           0 :                     Size( std::min( aItemSize.Width(), aSource.GetSizePixel().Width() ), std::min( aItemSize.Height(), aSource.GetSizePixel().Height() ) ) );
     109           0 :             aBmpEx.CopyPixel( aRect, aRect, &aSource );
     110             : 
     111           0 :             Bitmap              aBmp( aBmpEx.GetBitmap() );
     112           0 :             BitmapWriteAccess*  pBmpAcc = aBmp.IsEmpty() ? NULL : aBmp.AcquireWriteAccess();
     113             : 
     114           0 :             maBmpSize = aBmp.GetSizePixel();
     115             : 
     116           0 :             if( pBmpAcc )
     117             :             {
     118           0 :                 Bitmap              aMsk;
     119             :                 BitmapWriteAccess*  pMskAcc;
     120             : 
     121           0 :                 if( aBmpEx.IsAlpha() )
     122           0 :                     pMskAcc = ( aMsk = aBmpEx.GetAlpha().GetBitmap() ).AcquireWriteAccess();
     123           0 :                 else if( aBmpEx.IsTransparent() )
     124           0 :                     pMskAcc = ( aMsk = aBmpEx.GetMask() ).AcquireWriteAccess();
     125             :                 else
     126           0 :                     pMskAcc = NULL;
     127             : 
     128           0 :                 mbWasHiContrastMode = mpTbx->GetSettings().GetStyleSettings().GetHighContrastMode();
     129             : 
     130           0 :                 if( ( COL_TRANSPARENT != aColor.GetColor() ) && ( maBmpSize.Width() == maBmpSize.Height() ) )
     131           0 :                     pBmpAcc->SetLineColor( aColor );
     132           0 :                 else if( mpTbx->GetBackground().GetColor().IsDark() )
     133           0 :                     pBmpAcc->SetLineColor( Color( COL_WHITE ) );
     134             :                 else
     135           0 :                     pBmpAcc->SetLineColor( Color( COL_BLACK ) );
     136             : 
     137           0 :                 pBmpAcc->SetFillColor( maCurColor = aColor );
     138             : 
     139           0 :                 if( maBmpSize.Width() == maBmpSize.Height() )
     140           0 :                     maUpdRect = Rectangle( Point( 0, maBmpSize.Height() * 3 / 4 ), Size( maBmpSize.Width(), maBmpSize.Height() / 4 ) );
     141             :                 else
     142           0 :                     maUpdRect = Rectangle( Point( maBmpSize.Height() + 2, 2 ), Point( maBmpSize.Width() - 3, maBmpSize.Height() - 3 ) );
     143             : 
     144           0 :                 pBmpAcc->DrawRect( maUpdRect );
     145             : 
     146           0 :                 if( pMskAcc )
     147             :                 {
     148           0 :                     if( COL_TRANSPARENT == aColor.GetColor() )
     149             :                     {
     150           0 :                         pMskAcc->SetLineColor( COL_BLACK );
     151           0 :                         pMskAcc->SetFillColor( COL_WHITE );
     152             :                     }
     153             :                     else
     154           0 :                         pMskAcc->SetFillColor( COL_BLACK );
     155             : 
     156           0 :                     pMskAcc->DrawRect( maUpdRect );
     157             :                 }
     158             : 
     159           0 :                 aBmp.ReleaseAccess( pBmpAcc );
     160             : 
     161           0 :                 if( pMskAcc )
     162           0 :                     aMsk.ReleaseAccess( pMskAcc );
     163             : 
     164           0 :                 if( aBmpEx.IsAlpha() )
     165           0 :                     aBmpEx = BitmapEx( aBmp, AlphaMask( aMsk ) );
     166           0 :                 else if( aBmpEx.IsTransparent() )
     167           0 :                     aBmpEx = BitmapEx( aBmp, aMsk );
     168             :                 else
     169           0 :                     aBmpEx = aBmp;
     170             : 
     171           0 :                 mpTbx->SetItemImage( mnBtnId, Image( aBmpEx ) );
     172           0 :             }
     173           0 :         }
     174           0 :     }
     175             : 
     176             : 
     177             : } // namespace svx
     178             : 
     179             : 
     180             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10