LCOV - code coverage report
Current view: top level - vcl/source/control - imgctrl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 28 93 30.1 %
Date: 2012-08-25 Functions: 5 11 45.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 14 112 12.5 %

           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 <vcl/event.hxx>
      31                 :            : #include <vcl/imgctrl.hxx>
      32                 :            : #include <tools/rcid.h>
      33                 :            : 
      34                 :            : #include <com/sun/star/awt/ImageScaleMode.hpp>
      35                 :            : 
      36                 :            : namespace ImageScaleMode = ::com::sun::star::awt::ImageScaleMode;
      37                 :            : 
      38                 :            : // -----------------------------------------------------------------------
      39                 :            : 
      40                 :         22 : ImageControl::ImageControl( Window* pParent, WinBits nStyle )
      41                 :            :     :FixedImage( pParent, nStyle )
      42                 :         22 :     ,mnScaleMode( ImageScaleMode::Anisotropic )
      43                 :            : {
      44                 :         22 : }
      45                 :            : 
      46                 :            : // -----------------------------------------------------------------------
      47                 :            : 
      48                 :          0 : ImageControl::ImageControl( Window* pParent, const ResId& rResId )
      49                 :            :     :FixedImage( pParent, rResId )
      50                 :          0 :     ,mnScaleMode( ImageScaleMode::Anisotropic )
      51                 :            : {
      52                 :          0 : }
      53                 :            : 
      54                 :            : // -----------------------------------------------------------------------
      55                 :            : 
      56                 :        108 : void ImageControl::SetScaleMode( const ::sal_Int16 _nMode )
      57                 :            : {
      58         [ +  + ]:        108 :     if ( _nMode != mnScaleMode )
      59                 :            :     {
      60                 :         50 :         mnScaleMode = _nMode;
      61                 :         50 :         Invalidate();
      62                 :            :     }
      63                 :        108 : }
      64                 :            : 
      65                 :            : // -----------------------------------------------------------------------
      66                 :            : 
      67                 :         28 : void ImageControl::Resize()
      68                 :            : {
      69                 :         28 :     Invalidate();
      70                 :         28 : }
      71                 :            : 
      72                 :            : // -----------------------------------------------------------------------
      73                 :            : namespace
      74                 :            : {
      75                 :          0 :     static Size lcl_calcPaintSize( const Rectangle& _rPaintRect, const Size& _rBitmapSize )
      76                 :            :     {
      77         [ #  # ]:          0 :         const Size aPaintSize = _rPaintRect.GetSize();
      78                 :            : 
      79                 :          0 :         const double nRatioX = 1.0 * aPaintSize.Width() / _rBitmapSize.Width();
      80                 :          0 :         const double nRatioY = 1.0 * aPaintSize.Height() / _rBitmapSize.Height();
      81         [ #  # ]:          0 :         const double nRatioMin = ::std::min( nRatioX, nRatioY );
      82                 :            : 
      83                 :          0 :         return Size( long( _rBitmapSize.Width() * nRatioMin ), long( _rBitmapSize.Height() * nRatioMin ) );
      84                 :            :     }
      85                 :            : 
      86                 :          0 :     static Point lcl_centerWithin( const Rectangle& _rArea, const Size& _rObjectSize )
      87                 :            :     {
      88                 :          0 :         Point aPos( _rArea.TopLeft() );
      89                 :          0 :         aPos.X() += ( _rArea.GetWidth() - _rObjectSize.Width() ) / 2;
      90                 :          0 :         aPos.Y() += ( _rArea.GetHeight() - _rObjectSize.Height() ) / 2;
      91                 :          0 :         return aPos;
      92                 :            :     }
      93                 :            : }
      94                 :            : 
      95                 :            : // -----------------------------------------------------------------------
      96                 :            : 
      97                 :        239 : void ImageControl::ImplDraw( OutputDevice& rDev, sal_uLong nDrawFlags, const Point& rPos, const Size& rSize ) const
      98                 :            : {
      99                 :        239 :     sal_uInt16 nStyle = 0;
     100         [ +  - ]:        239 :     if ( !(nDrawFlags & WINDOW_DRAW_NODISABLE) )
     101                 :            :     {
     102 [ +  - ][ +  + ]:        239 :         if ( !IsEnabled() )
     103                 :         34 :             nStyle |= IMAGE_DRAW_DISABLE;
     104                 :            :     }
     105                 :            : 
     106         [ +  - ]:        239 :     const Image& rImage( GetModeImage() );
     107                 :        239 :     const Image* pImage = &rImage;
     108         [ +  - ]:        239 :     const Rectangle aDrawRect( rPos, rSize );
     109         [ +  - ]:        239 :     if ( !*pImage )
     110                 :            :     {
     111         [ +  - ]:        239 :         String  sText( GetText() );
     112         [ -  + ]:        239 :         if ( !sText.Len() )
     113                 :            :             return;
     114                 :            : 
     115         [ #  # ]:          0 :         WinBits nWinStyle = GetStyle();
     116         [ #  # ]:          0 :         sal_uInt16 nTextStyle = FixedText::ImplGetTextStyle( nWinStyle );
     117         [ #  # ]:          0 :         if ( !(nDrawFlags & WINDOW_DRAW_NODISABLE) )
     118 [ #  # ][ #  # ]:          0 :             if ( !IsEnabled() )
     119                 :          0 :                 nTextStyle |= TEXT_DRAW_DISABLE;
     120                 :            : 
     121         [ #  # ]:          0 :         rDev.DrawText( aDrawRect, sText, nTextStyle );
     122         [ +  - ]:        239 :         return;
     123                 :            :     }
     124                 :            : 
     125         [ #  # ]:          0 :     const Size&      rBitmapSize = pImage->GetSizePixel();
     126                 :            : 
     127   [ #  #  #  # ]:          0 :     switch ( mnScaleMode )
     128                 :            :     {
     129                 :            :     case ImageScaleMode::None:
     130                 :            :     {
     131 [ #  # ][ #  # ]:          0 :         rDev.DrawImage( lcl_centerWithin( aDrawRect, rBitmapSize ), *pImage, nStyle );
     132                 :            :     }
     133                 :          0 :     break;
     134                 :            : 
     135                 :            :     case ImageScaleMode::Isotropic:
     136                 :            :     {
     137         [ #  # ]:          0 :         const Size aPaintSize = lcl_calcPaintSize( aDrawRect, rBitmapSize );
     138                 :            :         rDev.DrawImage(
     139                 :            :             lcl_centerWithin( aDrawRect, aPaintSize ),
     140                 :            :             aPaintSize,
     141 [ #  # ][ #  # ]:          0 :             *pImage, nStyle );
     142                 :            :     }
     143                 :          0 :     break;
     144                 :            : 
     145                 :            :     case ImageScaleMode::Anisotropic:
     146                 :            :     {
     147                 :            :         rDev.DrawImage(
     148                 :            :             aDrawRect.TopLeft(),
     149                 :            :             aDrawRect.GetSize(),
     150 [ #  # ][ #  # ]:          0 :             *pImage, nStyle );
     151                 :            :     }
     152                 :          0 :     break;
     153                 :            : 
     154                 :            :     default:
     155                 :            :         OSL_ENSURE( false, "ImageControl::ImplDraw: unhandled scale mode!" );
     156                 :        239 :         break;
     157                 :            : 
     158                 :            :     }   // switch ( mnScaleMode )
     159                 :            : }
     160                 :            : 
     161                 :            : // -----------------------------------------------------------------------
     162                 :            : 
     163                 :        239 : void ImageControl::Paint( const Rectangle& /*rRect*/ )
     164                 :            : {
     165         [ +  - ]:        239 :     ImplDraw( *this, 0, Point(), GetOutputSizePixel() );
     166                 :            : 
     167         [ -  + ]:        239 :     if( HasFocus() )
     168                 :            :     {
     169         [ #  # ]:          0 :         Window *pWin = GetWindow( WINDOW_BORDER );
     170                 :            : 
     171         [ #  # ]:          0 :         sal_Bool bFlat = (GetBorderStyle() == 2);
     172         [ #  # ]:          0 :         Rectangle aRect( Point(0,0), pWin->GetOutputSizePixel() );
     173                 :          0 :         Color oldLineCol = pWin->GetLineColor();
     174                 :          0 :         Color oldFillCol = pWin->GetFillColor();
     175         [ #  # ]:          0 :         pWin->SetFillColor();
     176 [ #  # ][ #  # ]:          0 :         pWin->SetLineColor( bFlat ? COL_WHITE : COL_BLACK );
     177         [ #  # ]:          0 :         pWin->DrawRect( aRect );
     178                 :          0 :         aRect.nLeft++;
     179                 :          0 :         aRect.nRight--;
     180                 :          0 :         aRect.nTop++;
     181                 :          0 :         aRect.nBottom--;
     182 [ #  # ][ #  # ]:          0 :         pWin->SetLineColor( bFlat ? COL_BLACK : COL_WHITE );
     183         [ #  # ]:          0 :         pWin->DrawRect( aRect );
     184         [ #  # ]:          0 :         pWin->SetLineColor( oldLineCol );
     185         [ #  # ]:          0 :         pWin->SetFillColor( oldFillCol );
     186                 :            :     }
     187                 :        239 : }
     188                 :            : 
     189                 :            : // -----------------------------------------------------------------------
     190                 :          0 : void ImageControl::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags )
     191                 :            : {
     192         [ #  # ]:          0 :     const Point     aPos  = pDev->LogicToPixel( rPos );
     193         [ #  # ]:          0 :     const Size      aSize = pDev->LogicToPixel( rSize );
     194         [ #  # ]:          0 :           Rectangle aRect( aPos, aSize );
     195                 :            : 
     196         [ #  # ]:          0 :     pDev->Push();
     197         [ #  # ]:          0 :     pDev->SetMapMode();
     198                 :            : 
     199                 :            :     // Border
     200 [ #  # ][ #  # ]:          0 :     if ( !(nFlags & WINDOW_DRAW_NOBORDER) && (GetStyle() & WB_BORDER) )
         [ #  # ][ #  # ]
     201                 :            :     {
     202         [ #  # ]:          0 :         ImplDrawFrame( pDev, aRect );
     203                 :            :     }
     204         [ #  # ]:          0 :     pDev->IntersectClipRegion( aRect );
     205 [ #  # ][ #  # ]:          0 :     ImplDraw( *pDev, nFlags, aRect.TopLeft(), aRect.GetSize() );
     206                 :            : 
     207         [ #  # ]:          0 :     pDev->Pop();
     208                 :          0 : }
     209                 :            : 
     210                 :            : // -----------------------------------------------------------------------
     211                 :            : 
     212                 :          0 : void ImageControl::GetFocus()
     213                 :            : {
     214                 :          0 :     FixedImage::GetFocus();
     215                 :          0 :     GetWindow( WINDOW_BORDER )->Invalidate();
     216                 :          0 : }
     217                 :            : 
     218                 :            : // -----------------------------------------------------------------------
     219                 :            : 
     220                 :          0 : void ImageControl::LoseFocus()
     221                 :            : {
     222                 :          0 :     FixedImage::GetFocus();
     223                 :          0 :     GetWindow( WINDOW_BORDER )->Invalidate();
     224                 :          0 : }
     225                 :            : 
     226                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10