LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/vcl/source/gdi - image.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 213 333 64.0 %
Date: 2013-07-09 Functions: 30 44 68.2 %
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 <boost/scoped_ptr.hpp>
      21             : #include <boost/scoped_array.hpp>
      22             : 
      23             : #include <rtl/logfile.hxx>
      24             : 
      25             : #include <tools/debug.hxx>
      26             : #include <tools/stream.hxx>
      27             : #include <tools/rc.h>
      28             : #include <tools/rc.hxx>
      29             : #include <tools/resmgr.hxx>
      30             : #include <vcl/settings.hxx>
      31             : #include <vcl/outdev.hxx>
      32             : #include <vcl/graph.hxx>
      33             : #include <vcl/svapp.hxx>
      34             : #include <vcl/image.hxx>
      35             : #include <vcl/imagerepository.hxx>
      36             : #include <impimagetree.hxx>
      37             : #include <image.h>
      38             : 
      39             : #if OSL_DEBUG_LEVEL > 0
      40             : #include <rtl/strbuf.hxx>
      41             : #endif
      42             : 
      43             : DBG_NAME( Image )
      44             : DBG_NAME( ImageList )
      45             : 
      46             : using namespace ::com::sun::star;
      47             : 
      48     1199198 : Image::Image() :
      49     1199198 :     mpImplData( NULL )
      50             : {
      51             :     DBG_CTOR( Image, NULL );
      52     1199198 : }
      53             : 
      54       11276 : Image::Image( const ResId& rResId ) :
      55       11276 :     mpImplData( NULL )
      56             : {
      57             :     DBG_CTOR( Image, NULL );
      58             : 
      59       11276 :     rResId.SetRT( RSC_IMAGE );
      60             : 
      61       11276 :     ResMgr* pResMgr = rResId.GetResMgr();
      62       11276 :     if( pResMgr && pResMgr->GetResource( rResId ) )
      63             :     {
      64       11276 :         pResMgr->Increment( sizeof( RSHEADER_TYPE ) );
      65             : 
      66       11276 :         BitmapEx    aBmpEx;
      67       11276 :         sal_uLong       nObjMask = pResMgr->ReadLong();
      68             : 
      69       11276 :         if( nObjMask & RSC_IMAGE_IMAGEBITMAP )
      70             :         {
      71       11276 :             aBmpEx = BitmapEx( ResId( (RSHEADER_TYPE*)pResMgr->GetClass(), *pResMgr ) );
      72       11276 :             pResMgr->Increment( pResMgr->GetObjSize( (RSHEADER_TYPE*)pResMgr->GetClass() ) );
      73             :         }
      74             : 
      75       11276 :         if( nObjMask & RSC_IMAGE_MASKBITMAP )
      76             :         {
      77           0 :             if( !aBmpEx.IsEmpty() && aBmpEx.GetTransparentType() == TRANSPARENT_NONE )
      78             :             {
      79           0 :                 const Bitmap aMaskBitmap( ResId( (RSHEADER_TYPE*)pResMgr->GetClass(), *pResMgr ) );
      80           0 :                 aBmpEx = BitmapEx( aBmpEx.GetBitmap(), aMaskBitmap );
      81             :             }
      82             : 
      83           0 :             pResMgr->Increment( pResMgr->GetObjSize( (RSHEADER_TYPE*)pResMgr->GetClass() ) );
      84             :         }
      85             : 
      86       11276 :         if( nObjMask & RSC_IMAGE_MASKCOLOR )
      87             :         {
      88       10245 :             if( !aBmpEx.IsEmpty() && aBmpEx.GetTransparentType() == TRANSPARENT_NONE )
      89             :             {
      90         114 :                 const Color aMaskColor( ResId( (RSHEADER_TYPE*)pResMgr->GetClass(), *pResMgr ) );
      91         114 :                 aBmpEx = BitmapEx( aBmpEx.GetBitmap(), aMaskColor );
      92             :             }
      93             : 
      94       10245 :             pResMgr->Increment( pResMgr->GetObjSize( (RSHEADER_TYPE*)pResMgr->GetClass() ) );
      95             :         }
      96       11276 :         if( ! aBmpEx.IsEmpty() )
      97       10843 :             ImplInit( aBmpEx );
      98             :     }
      99       11276 : }
     100             : 
     101      866948 : Image::Image( const Image& rImage ) :
     102      866948 :     mpImplData( rImage.mpImplData )
     103             : {
     104             :     DBG_CTOR( Image, NULL );
     105             : 
     106      866948 :     if( mpImplData )
     107      257623 :         ++mpImplData->mnRefCount;
     108      866948 : }
     109             : 
     110       68883 : Image::Image( const BitmapEx& rBitmapEx ) :
     111       68883 :     mpImplData( NULL )
     112             : {
     113             :     DBG_CTOR( Image, NULL );
     114             : 
     115       68883 :     ImplInit( rBitmapEx );
     116       68883 : }
     117             : 
     118        2327 : Image::Image( const Bitmap& rBitmap ) :
     119        2327 :     mpImplData( NULL )
     120             : {
     121             :     DBG_CTOR( Image, NULL );
     122             : 
     123        2327 :     ImplInit( rBitmap );
     124        2327 : }
     125             : 
     126           0 : Image::Image( const Bitmap& rBitmap, const Bitmap& rMaskBitmap ) :
     127           0 :     mpImplData( NULL )
     128             : {
     129             :     DBG_CTOR( Image, NULL );
     130             : 
     131           0 :     const BitmapEx aBmpEx( rBitmap, rMaskBitmap );
     132             : 
     133           0 :     ImplInit( aBmpEx );
     134           0 : }
     135             : 
     136           0 : Image::Image( const Bitmap& rBitmap, const Color& rColor ) :
     137           0 :     mpImplData( NULL )
     138             : {
     139             :     DBG_CTOR( Image, NULL );
     140             : 
     141           0 :     const BitmapEx aBmpEx( rBitmap, rColor );
     142             : 
     143           0 :     ImplInit( aBmpEx );
     144           0 : }
     145             : 
     146      114195 : Image::Image( const uno::Reference< graphic::XGraphic >& rxGraphic ) :
     147      114195 :     mpImplData( NULL )
     148             : {
     149             :     DBG_CTOR( Image, NULL );
     150             : 
     151      114195 :     const Graphic aGraphic( rxGraphic );
     152      114195 :     ImplInit( aGraphic.GetBitmapEx() );
     153      114195 : }
     154             : 
     155     2262632 : Image::~Image()
     156             : {
     157             :     DBG_DTOR( Image, NULL );
     158             : 
     159     2262632 :     if( mpImplData && ( 0 == --mpImplData->mnRefCount ) )
     160      119245 :         delete mpImplData;
     161     2262632 : }
     162             : 
     163      196248 : void Image::ImplInit( const BitmapEx& rBmpEx )
     164             : {
     165      196248 :     if( !rBmpEx.IsEmpty() )
     166             :     {
     167      123249 :         mpImplData = new ImplImage;
     168      123249 :         mpImplData->mnRefCount = 1;
     169             : 
     170      123249 :         if( rBmpEx.GetTransparentType() == TRANSPARENT_NONE )
     171             :         {
     172        5176 :             mpImplData->meType = IMAGETYPE_BITMAP;
     173        5176 :             mpImplData->mpData = new Bitmap( rBmpEx.GetBitmap() );
     174             :         }
     175             :         else
     176             :         {
     177      118073 :             mpImplData->meType = IMAGETYPE_IMAGE;
     178      118073 :             mpImplData->mpData = new ImplImageData( rBmpEx );
     179             :         }
     180             :     }
     181      196248 : }
     182             : 
     183      238046 : Size Image::GetSizePixel() const
     184             : {
     185             :     DBG_CHKTHIS( Image, NULL );
     186             : 
     187      238046 :     Size aRet;
     188             : 
     189      238046 :     if( mpImplData )
     190             :     {
     191      160550 :         switch( mpImplData->meType )
     192             :         {
     193             :             case IMAGETYPE_BITMAP:
     194        5557 :                 aRet = static_cast< Bitmap* >( mpImplData->mpData )->GetSizePixel();
     195        5557 :             break;
     196             : 
     197             :             case IMAGETYPE_IMAGE:
     198      154993 :                 aRet = static_cast< ImplImageData* >( mpImplData->mpData )->maBmpEx.GetSizePixel();
     199      154993 :             break;
     200             :         }
     201             :     }
     202             : 
     203      238046 :     return aRet;
     204             : }
     205             : 
     206      117999 : BitmapEx Image::GetBitmapEx() const
     207             : {
     208             :     DBG_CHKTHIS( Image, NULL );
     209             : 
     210      117999 :     BitmapEx aRet;
     211             : 
     212      117999 :     if( mpImplData )
     213             :     {
     214       45603 :         switch( mpImplData->meType )
     215             :         {
     216             :             case IMAGETYPE_BITMAP:
     217        2415 :                 aRet = *static_cast< Bitmap* >( mpImplData->mpData );
     218        2415 :             break;
     219             : 
     220             :             case IMAGETYPE_IMAGE:
     221       43188 :                 aRet = static_cast< ImplImageData* >( mpImplData->mpData )->maBmpEx;
     222       43188 :             break;
     223             :         }
     224             :     }
     225             : 
     226      117999 :     return aRet;
     227             : }
     228             : 
     229      114953 : uno::Reference< graphic::XGraphic > Image::GetXGraphic() const
     230             : {
     231      114953 :     const Graphic aGraphic( GetBitmapEx() );
     232             : 
     233      114953 :     return aGraphic.GetXGraphic();
     234             : }
     235             : 
     236      713920 : Image& Image::operator=( const Image& rImage )
     237             : {
     238             :     DBG_CHKTHIS( Image, NULL );
     239             :     DBG_CHKOBJ( &rImage, Image, NULL );
     240             : 
     241      713920 :     if( rImage.mpImplData )
     242      198518 :         ++rImage.mpImplData->mnRefCount;
     243             : 
     244      713920 :     if( mpImplData && ( 0 == --mpImplData->mnRefCount ) )
     245        4003 :         delete mpImplData;
     246             : 
     247      713920 :     mpImplData = rImage.mpImplData;
     248             : 
     249      713920 :     return *this;
     250             : }
     251             : 
     252       44289 : sal_Bool Image::operator==( const Image& rImage ) const
     253             : {
     254             :     DBG_CHKTHIS( Image, NULL );
     255             :     DBG_CHKOBJ( &rImage, Image, NULL );
     256             : 
     257       44289 :     bool bRet = false;
     258             : 
     259       44289 :     if( rImage.mpImplData == mpImplData )
     260       43861 :         bRet = true;
     261         428 :     else if( !rImage.mpImplData || !mpImplData )
     262         426 :         bRet = false;
     263           2 :     else if( rImage.mpImplData->mpData == mpImplData->mpData )
     264           0 :         bRet = true;
     265           2 :     else if( rImage.mpImplData->meType == mpImplData->meType )
     266             :     {
     267           2 :         switch( mpImplData->meType )
     268             :         {
     269             :             case IMAGETYPE_BITMAP:
     270           0 :                 bRet = ( *static_cast< Bitmap* >( rImage.mpImplData->mpData ) == *static_cast< Bitmap* >( mpImplData->mpData ) );
     271           0 :             break;
     272             : 
     273             :             case IMAGETYPE_IMAGE:
     274           2 :                 bRet = static_cast< ImplImageData* >( rImage.mpImplData->mpData )->IsEqual( *static_cast< ImplImageData* >( mpImplData->mpData ) );
     275           2 :             break;
     276             : 
     277             :             default:
     278           0 :                 bRet = false;
     279           0 :             break;
     280             :         }
     281             :     }
     282             : 
     283       44289 :     return bRet;
     284             : }
     285             : 
     286        5984 : ImageList::ImageList( sal_uInt16 nInit, sal_uInt16 nGrow ) :
     287             :     mpImplData( NULL ),
     288             :     mnInitSize( nInit ),
     289        5984 :     mnGrowSize( nGrow )
     290             : {
     291             :     DBG_CTOR( ImageList, NULL );
     292        5984 : }
     293             : 
     294         354 : ImageList::ImageList( const ResId& rResId ) :
     295             :     mpImplData( NULL ),
     296             :     mnInitSize( 1 ),
     297         354 :     mnGrowSize( 4 )
     298             : {
     299             :     RTL_LOGFILE_CONTEXT( aLog, "vcl: ImageList::ImageList( const ResId& rResId )" );
     300             : 
     301             :     DBG_CTOR( ImageList, NULL );
     302             : 
     303         354 :     rResId.SetRT( RSC_IMAGELIST );
     304             : 
     305         354 :     ResMgr* pResMgr = rResId.GetResMgr();
     306             : 
     307         354 :     if( pResMgr && pResMgr->GetResource( rResId ) )
     308             :     {
     309         354 :         pResMgr->Increment( sizeof( RSHEADER_TYPE ) );
     310             : 
     311         354 :         sal_uLong                               nObjMask = pResMgr->ReadLong();
     312         354 :         pResMgr->ReadString(); //skip string
     313         354 :         ::boost::scoped_ptr< Color >        spMaskColor;
     314             : 
     315         354 :         if( nObjMask & RSC_IMAGE_MASKCOLOR )
     316         354 :             spMaskColor.reset( new Color( ResId( (RSHEADER_TYPE*)pResMgr->GetClass(), *pResMgr ) ) );
     317             : 
     318         354 :         pResMgr->Increment( pResMgr->GetObjSize( (RSHEADER_TYPE*)pResMgr->GetClass() ) );
     319             : 
     320         354 :         if( nObjMask & RSC_IMAGELIST_IDLIST )
     321             :         {
     322           0 :             for( sal_Int32 i = 0, nCount = pResMgr->ReadLong(); i < nCount; ++i )
     323           0 :                 pResMgr->ReadLong();
     324             :         }
     325             : 
     326         354 :         sal_Int32 nCount = pResMgr->ReadLong();
     327         354 :         ImplInit( static_cast< sal_uInt16 >( nCount ), Size() );
     328             : 
     329         708 :         BitmapEx aEmpty;
     330        3858 :         for( sal_Int32 i = 0; i < nCount; ++i )
     331             :         {
     332        3504 :             OUString aName = pResMgr->ReadString();
     333        3504 :             sal_uInt16 nId = static_cast< sal_uInt16 >( pResMgr->ReadLong() );
     334        3504 :             mpImplData->AddImage( aName, nId, aEmpty );
     335        3504 :         }
     336             : 
     337         354 :         if( nObjMask & RSC_IMAGELIST_IDCOUNT )
     338         708 :             pResMgr->ReadShort();
     339             :     }
     340         354 : }
     341             : 
     342          77 : ImageList::ImageList( const ::std::vector< OUString >& rNameVector,
     343             :                       const OUString& rPrefix,
     344             :                       const Color* ) :
     345             :     mpImplData( NULL ),
     346             :     mnInitSize( 1 ),
     347          77 :     mnGrowSize( 4 )
     348             : {
     349             :     RTL_LOGFILE_CONTEXT( aLog, "vcl: ImageList::ImageList(const vector< OUString >& ..." );
     350             : 
     351             :     DBG_CTOR( ImageList, NULL );
     352             : 
     353          77 :     ImplInit( sal::static_int_cast< sal_uInt16 >( rNameVector.size() ), Size() );
     354             : 
     355          77 :     mpImplData->maPrefix = rPrefix;
     356       21420 :     for( sal_uInt32 i = 0; i < rNameVector.size(); ++i )
     357             :     {
     358       21343 :         mpImplData->AddImage( rNameVector[ i ], static_cast< sal_uInt16 >( i ) + 1, BitmapEx() );
     359             :     }
     360          77 : }
     361             : 
     362           0 : ImageList::ImageList( const ImageList& rImageList ) :
     363             :     mpImplData( rImageList.mpImplData ),
     364             :     mnInitSize( rImageList.mnInitSize ),
     365           0 :     mnGrowSize( rImageList.mnGrowSize )
     366             : {
     367             :     DBG_CTOR( ImageList, NULL );
     368             : 
     369           0 :     if( mpImplData )
     370           0 :         ++mpImplData->mnRefCount;
     371           0 : }
     372             : 
     373        6386 : ImageList::~ImageList()
     374             : {
     375             :     DBG_DTOR( ImageList, NULL );
     376             : 
     377        6386 :     if( mpImplData && ( 0 == --mpImplData->mnRefCount ) )
     378         372 :         delete mpImplData;
     379        6386 : }
     380             : 
     381         453 : void ImageList::ImplInit( sal_uInt16 nItems, const Size &rSize )
     382             : {
     383         453 :     mpImplData = new ImplImageList;
     384         453 :     mpImplData->mnRefCount = 1;
     385         453 :     mpImplData->maImages.reserve( nItems );
     386         453 :     mpImplData->maImageSize = rSize;
     387         453 : }
     388             : 
     389        4317 : void ImageAryData::Load(const OUString &rPrefix)
     390             : {
     391        4317 :     static ImplImageTreeSingletonRef aImageTree;
     392             : 
     393        4317 :     OUString aSymbolsStyle = Application::GetSettings().GetStyleSettings().GetCurrentSymbolsStyleName();
     394             : 
     395        8634 :     BitmapEx aBmpEx;
     396             : 
     397        8634 :     OUString aFileName = rPrefix;
     398        4317 :     aFileName += maName;
     399             : #if OSL_DEBUG_LEVEL > 0
     400             :     bool bSuccess =
     401             : #endif
     402        8634 :         aImageTree->loadImage( aFileName, aSymbolsStyle, maBitmapEx, true );
     403             : #if OSL_DEBUG_LEVEL > 0
     404             :     if ( !bSuccess )
     405             :     {
     406             :         OStringBuffer aMessage;
     407             :         aMessage.append( "ImageAryData::Load: failed to load image '" );
     408             :         aMessage.append( OUStringToOString( aFileName, RTL_TEXTENCODING_UTF8 ).getStr() );
     409             :         aMessage.append( "'" );
     410             :         OSL_FAIL( aMessage.makeStringAndClear().getStr() );
     411             :     }
     412             : #endif
     413        4317 : }
     414             : 
     415             : // FIXME: Rather a performance hazard
     416           0 : BitmapEx ImageList::GetAsHorizontalStrip() const
     417             : {
     418           0 :     Size aSize( mpImplData->maImageSize );
     419           0 :     sal_uInt16 nCount = GetImageCount();
     420           0 :     if( !nCount )
     421           0 :         return BitmapEx();
     422           0 :     aSize.Width() *= nCount;
     423             : 
     424             :     // Load any stragglers
     425           0 :     for (sal_uInt16 nIdx = 0; nIdx < nCount; nIdx++)
     426             :     {
     427           0 :         ImageAryData *pData = mpImplData->maImages[ nIdx ];
     428           0 :         if( pData->IsLoadable() )
     429           0 :             pData->Load( mpImplData->maPrefix );
     430             :     }
     431             : 
     432           0 :     BitmapEx aTempl = mpImplData->maImages[ 0 ]->maBitmapEx;
     433           0 :     BitmapEx aResult;
     434           0 :     Bitmap aPixels( aSize, aTempl.GetBitmap().GetBitCount() );
     435           0 :     if( aTempl.IsAlpha() )
     436           0 :         aResult = BitmapEx( aPixels, AlphaMask( aSize ) );
     437           0 :     else if( aTempl.IsTransparent() )
     438           0 :         aResult = BitmapEx( aPixels, Bitmap( aSize, aTempl.GetMask().GetBitCount() ) );
     439             :     else
     440           0 :         aResult = BitmapEx( aPixels );
     441             : 
     442           0 :     Rectangle aSrcRect( Point( 0, 0 ), mpImplData->maImageSize );
     443           0 :     for (sal_uInt16 nIdx = 0; nIdx < nCount; nIdx++)
     444             :     {
     445           0 :         Rectangle aDestRect( Point( nIdx * mpImplData->maImageSize.Width(), 0 ),
     446           0 :                              mpImplData->maImageSize );
     447           0 :         ImageAryData *pData = mpImplData->maImages[ nIdx ];
     448           0 :         aResult.CopyPixel( aDestRect, aSrcRect, &pData->maBitmapEx);
     449             :     }
     450             : 
     451           0 :     return aResult;
     452             : }
     453             : 
     454          22 : void ImageList::InsertFromHorizontalStrip( const BitmapEx &rBitmapEx,
     455             :                                            const std::vector< OUString > &rNameVector )
     456             : {
     457          22 :     sal_uInt16 nItems = sal::static_int_cast< sal_uInt16 >( rNameVector.size() );
     458             : 
     459          22 :     if (!nItems)
     460          22 :             return;
     461             : 
     462          22 :     Size aSize( rBitmapEx.GetSizePixel() );
     463             :     DBG_ASSERT (rBitmapEx.GetSizePixel().Width() % nItems == 0,
     464             :                 "ImageList::InsertFromHorizontalStrip - very odd size");
     465          22 :     aSize.Width() /= nItems;
     466          22 :     ImplInit( nItems, aSize );
     467             : 
     468         193 :     for (sal_uInt16 nIdx = 0; nIdx < nItems; nIdx++)
     469             :     {
     470         171 :         BitmapEx aBitmap( rBitmapEx, Point( nIdx * aSize.Width(), 0 ), aSize );
     471         171 :         mpImplData->AddImage( rNameVector[ nIdx ], nIdx + 1, aBitmap );
     472         171 :     }
     473             : }
     474             : 
     475          22 : void ImageList::InsertFromHorizontalBitmap( const ResId& rResId,
     476             :                                             sal_uInt16       nCount,
     477             :                                             const Color *pMaskColor,
     478             :                                             const Color *pSearchColors,
     479             :                                             const Color *pReplaceColors,
     480             :                                             sal_uLong        nColorCount)
     481             : {
     482          22 :     BitmapEx aBmpEx( rResId );
     483          22 :     if (!aBmpEx.IsTransparent())
     484             :     {
     485          22 :         if( pMaskColor )
     486          22 :             aBmpEx = BitmapEx( aBmpEx.GetBitmap(), *pMaskColor );
     487             :         else
     488           0 :             aBmpEx = BitmapEx( aBmpEx.GetBitmap() );
     489             :     }
     490          22 :     if ( nColorCount && pSearchColors && pReplaceColors )
     491          22 :         aBmpEx.Replace( pSearchColors, pReplaceColors, nColorCount );
     492             : 
     493          44 :     std::vector< OUString > aNames( nCount );
     494          44 :     InsertFromHorizontalStrip( aBmpEx, aNames );
     495          22 : }
     496             : 
     497           0 : sal_uInt16 ImageList::ImplGetImageId( const OUString& rImageName ) const
     498             : {
     499             :     DBG_CHKTHIS( ImageList, NULL );
     500             : 
     501           0 :     ImageAryData *pImg = mpImplData->maNameHash[ rImageName ];
     502           0 :     if( pImg )
     503           0 :         return pImg->mnId;
     504             :     else
     505           0 :         return 0;
     506             : }
     507             : 
     508           0 : void ImageList::AddImage( sal_uInt16 nId, const Image& rImage )
     509             : {
     510             :     DBG_CHKTHIS( ImageList, NULL );
     511             :     DBG_CHKOBJ( &rImage, Image, NULL );
     512             :     DBG_ASSERT( nId, "ImageList::AddImage(): ImageId == 0" );
     513             :     DBG_ASSERT( GetImagePos( nId ) == IMAGELIST_IMAGE_NOTFOUND, "ImageList::AddImage() - ImageId already exists" );
     514             :     DBG_ASSERT( rImage.mpImplData, "ImageList::AddImage(): Wrong Size" );
     515             :     DBG_ASSERT( !mpImplData || (rImage.GetSizePixel() == mpImplData->maImageSize), "ImageList::AddImage(): Wrong Size" );
     516             : 
     517           0 :     if( !mpImplData )
     518           0 :         ImplInit( 0, rImage.GetSizePixel() );
     519             : 
     520           0 :     mpImplData->AddImage( rtl::OUString(), nId, rImage.GetBitmapEx());
     521           0 : }
     522             : 
     523           0 : void ImageList::AddImage( const OUString& rImageName, const Image& rImage )
     524             : {
     525             :     DBG_ASSERT( GetImagePos( rImageName ) == IMAGELIST_IMAGE_NOTFOUND, "ImageList::AddImage() - ImageName already exists" );
     526             : 
     527           0 :     if( !mpImplData )
     528           0 :         ImplInit( 0, rImage.GetSizePixel() );
     529             : 
     530           0 :     mpImplData->AddImage( rImageName, GetImageCount() + 1,
     531           0 :                           rImage.GetBitmapEx() );
     532           0 : }
     533             : 
     534           0 : void ImageList::ReplaceImage( const OUString& rImageName, const Image& rImage )
     535             : {
     536           0 :     const sal_uInt16 nId = ImplGetImageId( rImageName );
     537             : 
     538           0 :     if( nId )
     539             :     {
     540           0 :         RemoveImage( nId );
     541             : 
     542           0 :         if( !mpImplData )
     543           0 :             ImplInit( 0, rImage.GetSizePixel() );
     544           0 :         mpImplData->AddImage( rImageName, nId, rImage.GetBitmapEx());
     545             :     }
     546           0 : }
     547             : 
     548           0 : void ImageList::RemoveImage( sal_uInt16 nId )
     549             : {
     550             :     DBG_CHKTHIS( ImageList, NULL );
     551             : 
     552           0 :     for( sal_uInt32 i = 0; i < mpImplData->maImages.size(); ++i )
     553             :     {
     554           0 :         if( mpImplData->maImages[ i ]->mnId == nId )
     555             :         {
     556           0 :             mpImplData->RemoveImage( static_cast< sal_uInt16 >( i ) );
     557           0 :             break;
     558             :         }
     559             :     }
     560           0 : }
     561             : 
     562       21643 : Image ImageList::GetImage( sal_uInt16 nId ) const
     563             : {
     564             :     DBG_CHKTHIS( ImageList, NULL );
     565             : 
     566       21643 :     Image aRet;
     567             : 
     568       21643 :     if( mpImplData )
     569             :     {
     570       17648 :         std::vector<ImageAryData *>::iterator aIter;
     571     2768715 :         for( aIter = mpImplData->maImages.begin();
     572     1845810 :              aIter != mpImplData->maImages.end(); ++aIter)
     573             :         {
     574      905257 :             if ((*aIter)->mnId == nId)
     575             :             {
     576       18930 :                 if( (*aIter)->IsLoadable() )
     577        1888 :                     (*aIter)->Load( mpImplData->maPrefix );
     578             : 
     579       18930 :                 aRet = Image( (*aIter)->maBitmapEx );
     580             :             }
     581             :         }
     582             :     }
     583             : 
     584       21643 :     if (!aRet)
     585             :     {
     586        4161 :         BitmapEx rBitmap;
     587        4161 :         bool res = ::vcl::ImageRepository::loadDefaultImage(rBitmap);
     588        4161 :         if (res)
     589        3995 :             aRet =  Image(rBitmap);
     590             :     }
     591             : 
     592       21643 :     return aRet;
     593             : }
     594             : 
     595      155933 : Image ImageList::GetImage( const OUString& rImageName ) const
     596             : {
     597      155933 :     if( mpImplData )
     598             :     {
     599       41992 :         ImageAryData *pImg = mpImplData->maNameHash[ rImageName ];
     600             : 
     601       41992 :         if( pImg )
     602             :         {
     603       41992 :             if( pImg->IsLoadable() )
     604        2429 :                 pImg->Load( mpImplData->maPrefix );
     605       41992 :             return Image( pImg->maBitmapEx );
     606             :         }
     607             :     }
     608             : 
     609      113941 :     return Image();
     610             : }
     611             : 
     612         736 : sal_uInt16 ImageList::GetImageCount() const
     613             : {
     614             :     DBG_CHKTHIS( ImageList, NULL );
     615             : 
     616         736 :     return mpImplData ? static_cast< sal_uInt16 >( mpImplData->maImages.size() ) : 0;
     617             : }
     618             : 
     619       16932 : sal_uInt16 ImageList::GetImagePos( sal_uInt16 nId ) const
     620             : {
     621             :     DBG_CHKTHIS( ImageList, NULL );
     622             : 
     623       16932 :     if( mpImplData && nId )
     624             :     {
     625      642058 :         for( sal_uInt32 i = 0; i < mpImplData->maImages.size(); ++i )
     626             :         {
     627      640778 :             if (mpImplData->maImages[ i ]->mnId == nId)
     628       15652 :                 return static_cast< sal_uInt16 >( i );
     629             :         }
     630             :     }
     631             : 
     632        1280 :     return IMAGELIST_IMAGE_NOTFOUND;
     633             : }
     634             : 
     635       16932 : bool ImageList::HasImageAtPos( sal_uInt16 nId ) const
     636             : {
     637       16932 :     return GetImagePos( nId ) != IMAGELIST_IMAGE_NOTFOUND;
     638             : }
     639             : 
     640           0 : sal_uInt16 ImageList::GetImagePos( const OUString& rImageName ) const
     641             : {
     642             :     DBG_CHKTHIS( ImageList, NULL );
     643             : 
     644           0 :     if( mpImplData && !rImageName.isEmpty() )
     645             :     {
     646           0 :         for( sal_uInt32 i = 0; i < mpImplData->maImages.size(); i++ )
     647             :         {
     648           0 :             if (mpImplData->maImages[i]->maName == rImageName)
     649           0 :                 return static_cast< sal_uInt16 >( i );
     650             :         }
     651             :     }
     652             : 
     653           0 :     return IMAGELIST_IMAGE_NOTFOUND;
     654             : }
     655             : 
     656         594 : sal_uInt16 ImageList::GetImageId( sal_uInt16 nPos ) const
     657             : {
     658             :     DBG_CHKTHIS( ImageList, NULL );
     659             : 
     660         594 :     if( mpImplData && (nPos < GetImageCount()) )
     661         594 :         return mpImplData->maImages[ nPos ]->mnId;
     662             : 
     663           0 :     return 0;
     664             : }
     665             : 
     666           0 : OUString ImageList::GetImageName( sal_uInt16 nPos ) const
     667             : {
     668             :     DBG_CHKTHIS( ImageList, NULL );
     669             : 
     670           0 :     if( mpImplData && (nPos < GetImageCount()) )
     671           0 :         return mpImplData->maImages[ nPos ]->maName;
     672             : 
     673           0 :     return OUString();
     674             : }
     675             : 
     676           0 : void ImageList::GetImageNames( ::std::vector< OUString >& rNames ) const
     677             : {
     678             :     RTL_LOGFILE_CONTEXT( aLog, "vcl: ImageList::GetImageNames" );
     679             : 
     680             :     DBG_CHKTHIS( ImageList, NULL );
     681             : 
     682           0 :     rNames = ::std::vector< OUString >();
     683             : 
     684           0 :     if( mpImplData )
     685             :     {
     686           0 :         for( sal_uInt32 i = 0; i < mpImplData->maImages.size(); i++ )
     687             :         {
     688           0 :             const OUString& rName( mpImplData->maImages[ i ]->maName );
     689           0 :             if( !rName.isEmpty())
     690           0 :                 rNames.push_back( rName );
     691             :         }
     692             :     }
     693           0 : }
     694             : 
     695           0 : Size ImageList::GetImageSize() const
     696             : {
     697             :     DBG_CHKTHIS( ImageList, NULL );
     698             : 
     699           0 :     Size aRet;
     700             : 
     701           0 :     if( mpImplData )
     702             :     {
     703           0 :         aRet = mpImplData->maImageSize;
     704             : 
     705             :         // force load of 1st image to see - uncommon case.
     706           0 :         if( aRet.Width() == 0 && aRet.Height() == 0 &&
     707           0 :             !mpImplData->maImages.empty() )
     708             :         {
     709           0 :             Image aTmp = GetImage( mpImplData->maImages[ 0 ]->mnId );
     710           0 :             aRet = mpImplData->maImageSize = aTmp.GetSizePixel();
     711             :         }
     712             :     }
     713           0 :     return aRet;
     714             : }
     715             : 
     716         175 : ImageList& ImageList::operator=( const ImageList& rImageList )
     717             : {
     718             :     DBG_CHKTHIS( ImageList, NULL );
     719             :     DBG_CHKOBJ( &rImageList, ImageList, NULL );
     720             : 
     721         175 :     if( rImageList.mpImplData )
     722         175 :         ++rImageList.mpImplData->mnRefCount;
     723             : 
     724         175 :     if( mpImplData && ( 0 == --mpImplData->mnRefCount ) )
     725          60 :         delete mpImplData;
     726             : 
     727         175 :     mpImplData = rImageList.mpImplData;
     728             : 
     729         175 :     return *this;
     730             : }
     731             : 
     732           0 : sal_Bool ImageList::operator==( const ImageList& rImageList ) const
     733             : {
     734             :     DBG_CHKTHIS( ImageList, NULL );
     735             :     DBG_CHKOBJ( &rImageList, ImageList, NULL );
     736             : 
     737           0 :     bool bRet = false;
     738             : 
     739           0 :     if( rImageList.mpImplData == mpImplData )
     740           0 :         bRet = true;
     741           0 :     else if( !rImageList.mpImplData || !mpImplData )
     742           0 :         bRet = false;
     743           0 :     else if( rImageList.GetImageCount() == GetImageCount() &&
     744           0 :               rImageList.mpImplData->maImageSize == mpImplData->maImageSize )
     745           0 :         bRet = true; // strange semantic
     746             : 
     747           0 :     return bRet;
     748         465 : }
     749             : 
     750             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10