LCOV - code coverage report
Current view: top level - vcl/source/control - imgctrl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 28 91 30.8 %
Date: 2014-11-03 Functions: 7 12 58.3 %
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             : #include <vcl/event.hxx>
      21             : #include <vcl/imgctrl.hxx>
      22             : #include <tools/rcid.h>
      23             : 
      24             : #include <com/sun/star/awt/ImageScaleMode.hpp>
      25             : 
      26             : namespace ImageScaleMode = ::com::sun::star::awt::ImageScaleMode;
      27             : 
      28          22 : ImageControl::ImageControl( vcl::Window* pParent, WinBits nStyle )
      29             :     :FixedImage( pParent, nStyle )
      30          22 :     ,mnScaleMode( ImageScaleMode::ANISOTROPIC )
      31             : {
      32          22 : }
      33             : 
      34         108 : void ImageControl::SetScaleMode( const ::sal_Int16 _nMode )
      35             : {
      36         108 :     if ( _nMode != mnScaleMode )
      37             :     {
      38          50 :         mnScaleMode = _nMode;
      39          50 :         Invalidate();
      40             :     }
      41         108 : }
      42             : 
      43          24 : void ImageControl::Resize()
      44             : {
      45          24 :     Invalidate();
      46          24 : }
      47             : 
      48             : namespace
      49             : {
      50           0 :     static Size lcl_calcPaintSize( const Rectangle& _rPaintRect, const Size& _rBitmapSize )
      51             :     {
      52           0 :         const Size aPaintSize = _rPaintRect.GetSize();
      53             : 
      54           0 :         const double nRatioX = 1.0 * aPaintSize.Width() / _rBitmapSize.Width();
      55           0 :         const double nRatioY = 1.0 * aPaintSize.Height() / _rBitmapSize.Height();
      56           0 :         const double nRatioMin = ::std::min( nRatioX, nRatioY );
      57             : 
      58           0 :         return Size( long( _rBitmapSize.Width() * nRatioMin ), long( _rBitmapSize.Height() * nRatioMin ) );
      59             :     }
      60             : 
      61           0 :     static Point lcl_centerWithin( const Rectangle& _rArea, const Size& _rObjectSize )
      62             :     {
      63           0 :         Point aPos( _rArea.TopLeft() );
      64           0 :         aPos.X() += ( _rArea.GetWidth() - _rObjectSize.Width() ) / 2;
      65           0 :         aPos.Y() += ( _rArea.GetHeight() - _rObjectSize.Height() ) / 2;
      66           0 :         return aPos;
      67             :     }
      68             : }
      69             : 
      70         166 : void ImageControl::ImplDraw( OutputDevice& rDev, sal_uLong nDrawFlags, const Point& rPos, const Size& rSize ) const
      71             : {
      72         166 :     sal_uInt16 nStyle = 0;
      73         166 :     if ( !(nDrawFlags & WINDOW_DRAW_NODISABLE) )
      74             :     {
      75         166 :         if ( !IsEnabled() )
      76          21 :             nStyle |= IMAGE_DRAW_DISABLE;
      77             :     }
      78             : 
      79         166 :     const Image& rImage( GetModeImage() );
      80         166 :     const Image* pImage = &rImage;
      81         166 :     const Rectangle aDrawRect( rPos, rSize );
      82         166 :     if ( !*pImage )
      83             :     {
      84         166 :         OUString  sText( GetText() );
      85         166 :         if ( sText.isEmpty() )
      86         166 :             return;
      87             : 
      88           0 :         WinBits nWinStyle = GetStyle();
      89           0 :         sal_uInt16 nTextStyle = FixedText::ImplGetTextStyle( nWinStyle );
      90           0 :         if ( !(nDrawFlags & WINDOW_DRAW_NODISABLE) )
      91           0 :             if ( !IsEnabled() )
      92           0 :                 nTextStyle |= TEXT_DRAW_DISABLE;
      93             : 
      94           0 :         rDev.DrawText( aDrawRect, sText, nTextStyle );
      95           0 :         return;
      96             :     }
      97             : 
      98           0 :     const Size&      rBitmapSize = pImage->GetSizePixel();
      99             : 
     100           0 :     switch ( mnScaleMode )
     101             :     {
     102             :     case ImageScaleMode::NONE:
     103             :     {
     104           0 :         rDev.DrawImage( lcl_centerWithin( aDrawRect, rBitmapSize ), *pImage, nStyle );
     105             :     }
     106           0 :     break;
     107             : 
     108             :     case ImageScaleMode::ISOTROPIC:
     109             :     {
     110           0 :         const Size aPaintSize = lcl_calcPaintSize( aDrawRect, rBitmapSize );
     111             :         rDev.DrawImage(
     112             :             lcl_centerWithin( aDrawRect, aPaintSize ),
     113             :             aPaintSize,
     114           0 :             *pImage, nStyle );
     115             :     }
     116           0 :     break;
     117             : 
     118             :     case ImageScaleMode::ANISOTROPIC:
     119             :     {
     120             :         rDev.DrawImage(
     121             :             aDrawRect.TopLeft(),
     122             :             aDrawRect.GetSize(),
     123           0 :             *pImage, nStyle );
     124             :     }
     125           0 :     break;
     126             : 
     127             :     default:
     128             :         OSL_ENSURE( false, "ImageControl::ImplDraw: unhandled scale mode!" );
     129           0 :         break;
     130             : 
     131             :     }   // switch ( mnScaleMode )
     132             : }
     133             : 
     134         166 : void ImageControl::Paint( const Rectangle& /*rRect*/ )
     135             : {
     136         166 :     ImplDraw( *this, 0, Point(), GetOutputSizePixel() );
     137             : 
     138         166 :     if( HasFocus() )
     139             :     {
     140           0 :         vcl::Window *pWin = GetWindow( WINDOW_BORDER );
     141             : 
     142           0 :         bool bFlat = (GetBorderStyle() == WindowBorderStyle::MONO);
     143           0 :         Rectangle aRect( Point(0,0), pWin->GetOutputSizePixel() );
     144           0 :         Color oldLineCol = pWin->GetLineColor();
     145           0 :         Color oldFillCol = pWin->GetFillColor();
     146           0 :         pWin->SetFillColor();
     147           0 :         pWin->SetLineColor( bFlat ? COL_WHITE : COL_BLACK );
     148           0 :         pWin->DrawRect( aRect );
     149           0 :         ++aRect.Left();
     150           0 :         --aRect.Right();
     151           0 :         ++aRect.Top();
     152           0 :         --aRect.Bottom();
     153           0 :         pWin->SetLineColor( bFlat ? COL_BLACK : COL_WHITE );
     154           0 :         pWin->DrawRect( aRect );
     155           0 :         pWin->SetLineColor( oldLineCol );
     156           0 :         pWin->SetFillColor( oldFillCol );
     157             :     }
     158         166 : }
     159             : 
     160           0 : void ImageControl::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags )
     161             : {
     162           0 :     const Point     aPos  = pDev->LogicToPixel( rPos );
     163           0 :     const Size      aSize = pDev->LogicToPixel( rSize );
     164           0 :           Rectangle aRect( aPos, aSize );
     165             : 
     166           0 :     pDev->Push();
     167           0 :     pDev->SetMapMode();
     168             : 
     169             :     // Border
     170           0 :     if ( !(nFlags & WINDOW_DRAW_NOBORDER) && (GetStyle() & WB_BORDER) )
     171             :     {
     172           0 :         ImplDrawFrame( pDev, aRect );
     173             :     }
     174           0 :     pDev->IntersectClipRegion( aRect );
     175           0 :     ImplDraw( *pDev, nFlags, aRect.TopLeft(), aRect.GetSize() );
     176             : 
     177           0 :     pDev->Pop();
     178           0 : }
     179             : 
     180           0 : void ImageControl::GetFocus()
     181             : {
     182           0 :     FixedImage::GetFocus();
     183           0 :     GetWindow( WINDOW_BORDER )->Invalidate();
     184           0 : }
     185             : 
     186           0 : void ImageControl::LoseFocus()
     187             : {
     188           0 :     FixedImage::GetFocus();
     189           0 :     GetWindow( WINDOW_BORDER )->Invalidate();
     190        1233 : }
     191             : 
     192             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10