LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/tbxctrls - tbxcolorupdate.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 54 78 69.2 %
Date: 2013-07-09 Functions: 5 5 100.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 <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        1600 :     ToolboxButtonColorUpdater::ToolboxButtonColorUpdater(
      46             :         sal_uInt16 nId,
      47             :         sal_uInt16 nTbxBtnId,
      48             :         ToolBox* ptrTbx) :
      49             :         mnBtnId           ( nTbxBtnId ),
      50             :         mnSlotId           ( nId ),
      51             :         mpTbx             ( ptrTbx ),
      52        1600 :         maCurColor        ( COL_TRANSPARENT )
      53             :     {
      54             :         DBG_ASSERT( ptrTbx, "ToolBox not found :-(" );
      55        1600 :         mbWasHiContrastMode = ptrTbx ? ( ptrTbx->GetSettings().GetStyleSettings().GetHighContrastMode() ) : sal_False;
      56        1600 :         switch( mnSlotId )
      57             :         {
      58             :             case SID_ATTR_CHAR_COLOR  :
      59             :             case SID_ATTR_CHAR_COLOR2 :
      60         532 :                 Update( COL_RED );
      61         532 :                 break;
      62             :             case SID_FRAME_LINECOLOR  :
      63         157 :                 Update( COL_BLUE );
      64         157 :                 break;
      65             :             case SID_ATTR_CHAR_COLOR_BACKGROUND :
      66             :             case SID_BACKGROUND_COLOR :
      67         911 :                 Update( COL_YELLOW );
      68         911 :                 break;
      69             :             default :
      70           0 :                 Update( COL_TRANSPARENT );
      71             :         }
      72        1600 :     }
      73             : 
      74             :     // -----------------------------------------------------------------------
      75             : 
      76        1600 :     ToolboxButtonColorUpdater::~ToolboxButtonColorUpdater()
      77             :     {
      78        1600 :     }
      79             : 
      80             :     // -----------------------------------------------------------------------
      81             : 
      82        1600 :     void ToolboxButtonColorUpdater::Update( const Color& rColor )
      83             :     {
      84        1600 :         Image       aImage( mpTbx->GetItemImage( mnBtnId ) );
      85        1600 :         Size        aItemSize( mpTbx->GetItemContentSize( mnBtnId ) );
      86             : 
      87        1600 :         const bool  bSizeChanged = ( maBmpSize != aItemSize );
      88        1600 :         const bool  bDisplayModeChanged = ( mbWasHiContrastMode != mpTbx->GetSettings().GetStyleSettings().GetHighContrastMode() );
      89        1600 :         Color       aColor( rColor );
      90             : 
      91             :         // !!! #109290# Workaround for SetFillColor with COL_AUTO
      92        1600 :         if( aColor.GetColor() == COL_AUTO )
      93           0 :             aColor = Color( COL_TRANSPARENT );
      94             : 
      95        1600 :         if( ( maCurColor != aColor ) || bSizeChanged || bDisplayModeChanged )
      96             :         {
      97             :             // create an empty bitmap, and copy the original bitmap inside
      98             :             // (so that it grows in case the original bitmap was smaller)
      99        1600 :             sal_uInt8 nAlpha = 255;
     100        1600 :             BitmapEx aBmpEx( Bitmap( aItemSize, 24 ), AlphaMask( aItemSize, &nAlpha ) );
     101        3200 :             BitmapEx aSource( aImage.GetBitmapEx() );
     102             :             Rectangle aRect( Point( 0, 0 ),
     103        1600 :                     Size( std::min( aItemSize.Width(), aSource.GetSizePixel().Width() ), std::min( aItemSize.Height(), aSource.GetSizePixel().Height() ) ) );
     104        1600 :             aBmpEx.CopyPixel( aRect, aRect, &aSource );
     105             : 
     106        3200 :             Bitmap              aBmp( aBmpEx.GetBitmap() );
     107        1600 :             BitmapWriteAccess*  pBmpAcc = aBmp.IsEmpty() ? NULL : aBmp.AcquireWriteAccess();
     108             : 
     109        1600 :             maBmpSize = aBmp.GetSizePixel();
     110             : 
     111        1600 :             if( pBmpAcc )
     112             :             {
     113        1600 :                 Bitmap              aMsk;
     114             :                 BitmapWriteAccess*  pMskAcc;
     115             : 
     116        1600 :                 if( aBmpEx.IsAlpha() )
     117        1600 :                     pMskAcc = ( aMsk = aBmpEx.GetAlpha().GetBitmap() ).AcquireWriteAccess();
     118           0 :                 else if( aBmpEx.IsTransparent() )
     119           0 :                     pMskAcc = ( aMsk = aBmpEx.GetMask() ).AcquireWriteAccess();
     120             :                 else
     121           0 :                     pMskAcc = NULL;
     122             : 
     123        1600 :                 mbWasHiContrastMode = mpTbx->GetSettings().GetStyleSettings().GetHighContrastMode();
     124             : 
     125        1600 :                 if( COL_TRANSPARENT != aColor.GetColor() )
     126        1600 :                     pBmpAcc->SetLineColor( aColor );
     127           0 :                 else if( mpTbx->GetBackground().GetColor().IsDark() )
     128           0 :                     pBmpAcc->SetLineColor( Color( COL_WHITE ) );
     129             :                 else
     130           0 :                     pBmpAcc->SetLineColor( Color( COL_BLACK ) );
     131             : 
     132        1600 :                 pBmpAcc->SetFillColor( maCurColor = aColor );
     133             : 
     134        1600 :                 if( maBmpSize.Width() <= 16 )
     135        1600 :                     maUpdRect = Rectangle( Point( 0,12 ), Size( maBmpSize.Width(), 4 ) );
     136           0 :                 else if(76 == maBmpSize.Width() && 12 == maBmpSize.Height())
     137             :                 {
     138           0 :                     maUpdRect.Left() = 22;
     139           0 :                     maUpdRect.Top() = 2;
     140           0 :                     maUpdRect.Right() = 73;
     141           0 :                     maUpdRect.Bottom() = 9;
     142             :                 }
     143           0 :                 else if(maBmpSize.Width() >= (2 * maBmpSize.Height() - 2) && maBmpSize.Height() >= 16)
     144             :                 {
     145           0 :                     maUpdRect.Left() = maBmpSize.Height() + 2;
     146           0 :                     maUpdRect.Top() = 2;
     147           0 :                     maUpdRect.Right() = maBmpSize.Width() - 3;
     148           0 :                     maUpdRect.Bottom() = maBmpSize.Height() - 3;
     149             :                 }
     150             :                 else
     151           0 :                     maUpdRect = Rectangle( Point( 1, maBmpSize.Height() - 7 ), Size( maBmpSize.Width() - 2 ,6 ) );
     152             : 
     153        1600 :                 pBmpAcc->DrawRect( maUpdRect );
     154             : 
     155        1600 :                 if( pMskAcc )
     156             :                 {
     157        1600 :                     if( COL_TRANSPARENT == aColor.GetColor() )
     158             :                     {
     159           0 :                         pMskAcc->SetLineColor( COL_BLACK );
     160           0 :                         pMskAcc->SetFillColor( COL_WHITE );
     161             :                     }
     162             :                     else
     163        1600 :                         pMskAcc->SetFillColor( COL_BLACK );
     164             : 
     165        1600 :                     pMskAcc->DrawRect( maUpdRect );
     166             :                 }
     167             : 
     168        1600 :                 aBmp.ReleaseAccess( pBmpAcc );
     169             : 
     170        1600 :                 if( pMskAcc )
     171        1600 :                     aMsk.ReleaseAccess( pMskAcc );
     172             : 
     173        1600 :                 if( aBmpEx.IsAlpha() )
     174        1600 :                     aBmpEx = BitmapEx( aBmp, AlphaMask( aMsk ) );
     175           0 :                 else if( aBmpEx.IsTransparent() )
     176           0 :                     aBmpEx = BitmapEx( aBmp, aMsk );
     177             :                 else
     178           0 :                     aBmpEx = aBmp;
     179             : 
     180        1600 :                 mpTbx->SetItemImage( mnBtnId, Image( aBmpEx ) );
     181        1600 :             }
     182        1600 :         }
     183        1600 :     }
     184             : 
     185             : //........................................................................
     186         258 : } // namespace svx
     187             : //........................................................................
     188             : 
     189             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10