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

Generated by: LCOV version 1.10