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

Generated by: LCOV version 1.10