1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 28*cdf0e10cSrcweir #include "precompiled_vcl.hxx" 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include <boost/scoped_ptr.hpp> 31*cdf0e10cSrcweir #include <boost/scoped_array.hpp> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <rtl/logfile.hxx> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <tools/debug.hxx> 36*cdf0e10cSrcweir #include <tools/stream.hxx> 37*cdf0e10cSrcweir #include <tools/rc.h> 38*cdf0e10cSrcweir #include <tools/rc.hxx> 39*cdf0e10cSrcweir #include <tools/resmgr.hxx> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir #include <vcl/settings.hxx> 42*cdf0e10cSrcweir #include <vcl/outdev.hxx> 43*cdf0e10cSrcweir #include <vcl/graph.hxx> 44*cdf0e10cSrcweir #include <vcl/svapp.hxx> 45*cdf0e10cSrcweir #include <vcl/image.hxx> 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir #include <impimagetree.hxx> 48*cdf0e10cSrcweir #include <image.h> 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 51*cdf0e10cSrcweir #include <rtl/strbuf.hxx> 52*cdf0e10cSrcweir #endif 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir DBG_NAME( Image ) 55*cdf0e10cSrcweir DBG_NAME( ImageList ) 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir #define IMAGE_FILE_VERSION 100 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir using namespace ::com::sun::star; 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir // --------- 62*cdf0e10cSrcweir // - Image - 63*cdf0e10cSrcweir // --------- 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir Image::Image() : 66*cdf0e10cSrcweir mpImplData( NULL ) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir DBG_CTOR( Image, NULL ); 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir // ----------------------------------------------------------------------- 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir Image::Image( const ResId& rResId ) : 74*cdf0e10cSrcweir mpImplData( NULL ) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir DBG_CTOR( Image, NULL ); 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir rResId.SetRT( RSC_IMAGE ); 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir ResMgr* pResMgr = rResId.GetResMgr(); 81*cdf0e10cSrcweir if( pResMgr && pResMgr->GetResource( rResId ) ) 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir pResMgr->Increment( sizeof( RSHEADER_TYPE ) ); 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir BitmapEx aBmpEx; 86*cdf0e10cSrcweir sal_uLong nObjMask = pResMgr->ReadLong(); 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir if( nObjMask & RSC_IMAGE_IMAGEBITMAP ) 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir aBmpEx = BitmapEx( ResId( (RSHEADER_TYPE*)pResMgr->GetClass(), *pResMgr ) ); 91*cdf0e10cSrcweir pResMgr->Increment( pResMgr->GetObjSize( (RSHEADER_TYPE*)pResMgr->GetClass() ) ); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir if( nObjMask & RSC_IMAGE_MASKBITMAP ) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir if( !aBmpEx.IsEmpty() && aBmpEx.GetTransparentType() == TRANSPARENT_NONE ) 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir const Bitmap aMaskBitmap( ResId( (RSHEADER_TYPE*)pResMgr->GetClass(), *pResMgr ) ); 99*cdf0e10cSrcweir aBmpEx = BitmapEx( aBmpEx.GetBitmap(), aMaskBitmap ); 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir pResMgr->Increment( pResMgr->GetObjSize( (RSHEADER_TYPE*)pResMgr->GetClass() ) ); 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir if( nObjMask & RSC_IMAGE_MASKCOLOR ) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir if( !aBmpEx.IsEmpty() && aBmpEx.GetTransparentType() == TRANSPARENT_NONE ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir const Color aMaskColor( ResId( (RSHEADER_TYPE*)pResMgr->GetClass(), *pResMgr ) ); 110*cdf0e10cSrcweir aBmpEx = BitmapEx( aBmpEx.GetBitmap(), aMaskColor ); 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir pResMgr->Increment( pResMgr->GetObjSize( (RSHEADER_TYPE*)pResMgr->GetClass() ) ); 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir if( ! aBmpEx.IsEmpty() ) 116*cdf0e10cSrcweir ImplInit( aBmpEx ); 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir // ----------------------------------------------------------------------- 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir Image::Image( const Image& rImage ) : 123*cdf0e10cSrcweir mpImplData( rImage.mpImplData ) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir DBG_CTOR( Image, NULL ); 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir if( mpImplData ) 128*cdf0e10cSrcweir ++mpImplData->mnRefCount; 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir // ----------------------------------------------------------------------- 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir Image::Image( const BitmapEx& rBitmapEx ) : 134*cdf0e10cSrcweir mpImplData( NULL ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir DBG_CTOR( Image, NULL ); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir ImplInit( rBitmapEx ); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir // ----------------------------------------------------------------------- 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir Image::Image( const Bitmap& rBitmap ) : 144*cdf0e10cSrcweir mpImplData( NULL ) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir DBG_CTOR( Image, NULL ); 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir ImplInit( rBitmap ); 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir // ----------------------------------------------------------------------- 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir Image::Image( const Bitmap& rBitmap, const Bitmap& rMaskBitmap ) : 154*cdf0e10cSrcweir mpImplData( NULL ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir DBG_CTOR( Image, NULL ); 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir const BitmapEx aBmpEx( rBitmap, rMaskBitmap ); 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir ImplInit( aBmpEx ); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir // ----------------------------------------------------------------------- 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir Image::Image( const Bitmap& rBitmap, const Color& rColor ) : 166*cdf0e10cSrcweir mpImplData( NULL ) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir DBG_CTOR( Image, NULL ); 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir const BitmapEx aBmpEx( rBitmap, rColor ); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir ImplInit( aBmpEx ); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir // ----------------------------------------------------------------------- 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir Image::Image( const uno::Reference< graphic::XGraphic >& rxGraphic ) : 178*cdf0e10cSrcweir mpImplData( NULL ) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir DBG_CTOR( Image, NULL ); 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir const Graphic aGraphic( rxGraphic ); 183*cdf0e10cSrcweir ImplInit( aGraphic.GetBitmapEx() ); 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir // ----------------------------------------------------------------------- 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir Image::~Image() 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir DBG_DTOR( Image, NULL ); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir if( mpImplData && ( 0 == --mpImplData->mnRefCount ) ) 193*cdf0e10cSrcweir delete mpImplData; 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir // ----------------------------------------------------------------------- 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir void Image::ImplInit( const BitmapEx& rBmpEx ) 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir if( !rBmpEx.IsEmpty() ) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir mpImplData = new ImplImage; 203*cdf0e10cSrcweir mpImplData->mnRefCount = 1; 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir if( rBmpEx.GetTransparentType() == TRANSPARENT_NONE ) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir mpImplData->meType = IMAGETYPE_BITMAP; 208*cdf0e10cSrcweir mpImplData->mpData = new Bitmap( rBmpEx.GetBitmap() ); 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir else 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir mpImplData->meType = IMAGETYPE_IMAGE; 213*cdf0e10cSrcweir mpImplData->mpData = new ImplImageData( rBmpEx ); 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir // ----------------------------------------------------------------------- 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir Size Image::GetSizePixel() const 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir DBG_CHKTHIS( Image, NULL ); 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir Size aRet; 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir if( mpImplData ) 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir switch( mpImplData->meType ) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir case IMAGETYPE_BITMAP: 231*cdf0e10cSrcweir aRet = static_cast< Bitmap* >( mpImplData->mpData )->GetSizePixel(); 232*cdf0e10cSrcweir break; 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir case IMAGETYPE_IMAGE: 235*cdf0e10cSrcweir aRet = static_cast< ImplImageData* >( mpImplData->mpData )->maBmpEx.GetSizePixel(); 236*cdf0e10cSrcweir break; 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir return aRet; 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir // ----------------------------------------------------------------------- 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir BitmapEx Image::GetBitmapEx() const 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir DBG_CHKTHIS( Image, NULL ); 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir BitmapEx aRet; 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir if( mpImplData ) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir switch( mpImplData->meType ) 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir case IMAGETYPE_BITMAP: 256*cdf0e10cSrcweir aRet = *static_cast< Bitmap* >( mpImplData->mpData ); 257*cdf0e10cSrcweir break; 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir case IMAGETYPE_IMAGE: 260*cdf0e10cSrcweir aRet = static_cast< ImplImageData* >( mpImplData->mpData )->maBmpEx; 261*cdf0e10cSrcweir break; 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir return aRet; 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir // ----------------------------------------------------------------------- 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir uno::Reference< graphic::XGraphic > Image::GetXGraphic() const 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir const Graphic aGraphic( GetBitmapEx() ); 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir return aGraphic.GetXGraphic(); 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir // ----------------------------------------------------------------------- 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir Image Image::GetColorTransformedImage( ImageColorTransform eColorTransform ) const 280*cdf0e10cSrcweir { 281*cdf0e10cSrcweir DBG_CHKTHIS( Image, NULL ); 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir Image aRet; 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir if( IMAGECOLORTRANSFORM_HIGHCONTRAST == eColorTransform ) 286*cdf0e10cSrcweir { 287*cdf0e10cSrcweir BitmapEx aBmpEx( GetBitmapEx() ); 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir if( !aBmpEx.IsEmpty() ) 290*cdf0e10cSrcweir { 291*cdf0e10cSrcweir Color* pSrcColors = NULL; 292*cdf0e10cSrcweir Color* pDstColors = NULL; 293*cdf0e10cSrcweir sal_uLong nColorCount = 0; 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir Image::GetColorTransformArrays( eColorTransform, pSrcColors, pDstColors, nColorCount ); 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir if( nColorCount && pSrcColors && pDstColors ) 298*cdf0e10cSrcweir { 299*cdf0e10cSrcweir aBmpEx.Replace( pSrcColors, pDstColors, nColorCount ); 300*cdf0e10cSrcweir aRet = Image( aBmpEx ); 301*cdf0e10cSrcweir } 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir delete[] pSrcColors; 304*cdf0e10cSrcweir delete[] pDstColors; 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir else if( IMAGECOLORTRANSFORM_MONOCHROME_BLACK == eColorTransform || 308*cdf0e10cSrcweir IMAGECOLORTRANSFORM_MONOCHROME_WHITE == eColorTransform ) 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir BitmapEx aBmpEx( GetBitmapEx() ); 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir if( !aBmpEx.IsEmpty() ) 313*cdf0e10cSrcweir aRet = Image( aBmpEx.GetColorTransformedBitmapEx( ( BmpColorMode )( eColorTransform ) ) ); 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir if( !aRet ) 317*cdf0e10cSrcweir aRet = *this; 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir return aRet; 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir // ----------------------------------------------------------------------- 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir void Image::Invert() 325*cdf0e10cSrcweir { 326*cdf0e10cSrcweir BitmapEx aInvertedBmp( GetBitmapEx() ); 327*cdf0e10cSrcweir aInvertedBmp.Invert(); 328*cdf0e10cSrcweir *this = aInvertedBmp; 329*cdf0e10cSrcweir } 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir // ----------------------------------------------------------------------- 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir void Image::GetColorTransformArrays( ImageColorTransform eColorTransform, 334*cdf0e10cSrcweir Color*& rpSrcColor, Color*& rpDstColor, sal_uLong& rColorCount ) 335*cdf0e10cSrcweir { 336*cdf0e10cSrcweir if( IMAGECOLORTRANSFORM_HIGHCONTRAST == eColorTransform ) 337*cdf0e10cSrcweir { 338*cdf0e10cSrcweir rpSrcColor = new Color[ 4 ]; 339*cdf0e10cSrcweir rpDstColor = new Color[ 4 ]; 340*cdf0e10cSrcweir rColorCount = 4; 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir rpSrcColor[ 0 ] = Color( COL_BLACK ); 343*cdf0e10cSrcweir rpDstColor[ 0 ] = Color( COL_WHITE ); 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir rpSrcColor[ 1 ] = Color( COL_WHITE ); 346*cdf0e10cSrcweir rpDstColor[ 1 ] = Color( COL_BLACK ); 347*cdf0e10cSrcweir 348*cdf0e10cSrcweir rpSrcColor[ 2 ] = Color( COL_BLUE ); 349*cdf0e10cSrcweir rpDstColor[ 2 ] = Color( COL_WHITE ); 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir rpSrcColor[ 3 ] = Color( COL_LIGHTBLUE ); 352*cdf0e10cSrcweir rpDstColor[ 3 ] = Color( COL_WHITE ); 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir else 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir rpSrcColor = rpDstColor = NULL; 357*cdf0e10cSrcweir rColorCount = 0; 358*cdf0e10cSrcweir } 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir // ----------------------------------------------------------------------- 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir Image& Image::operator=( const Image& rImage ) 364*cdf0e10cSrcweir { 365*cdf0e10cSrcweir DBG_CHKTHIS( Image, NULL ); 366*cdf0e10cSrcweir DBG_CHKOBJ( &rImage, Image, NULL ); 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir if( rImage.mpImplData ) 369*cdf0e10cSrcweir ++rImage.mpImplData->mnRefCount; 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir if( mpImplData && ( 0 == --mpImplData->mnRefCount ) ) 372*cdf0e10cSrcweir delete mpImplData; 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir mpImplData = rImage.mpImplData; 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir return *this; 377*cdf0e10cSrcweir } 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir // ----------------------------------------------------------------------- 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir sal_Bool Image::operator==( const Image& rImage ) const 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir DBG_CHKTHIS( Image, NULL ); 384*cdf0e10cSrcweir DBG_CHKOBJ( &rImage, Image, NULL ); 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir bool bRet = false; 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir if( rImage.mpImplData == mpImplData ) 389*cdf0e10cSrcweir bRet = true; 390*cdf0e10cSrcweir else if( !rImage.mpImplData || !mpImplData ) 391*cdf0e10cSrcweir bRet = false; 392*cdf0e10cSrcweir else if( rImage.mpImplData->mpData == mpImplData->mpData ) 393*cdf0e10cSrcweir bRet = true; 394*cdf0e10cSrcweir else if( rImage.mpImplData->meType == mpImplData->meType ) 395*cdf0e10cSrcweir { 396*cdf0e10cSrcweir switch( mpImplData->meType ) 397*cdf0e10cSrcweir { 398*cdf0e10cSrcweir case IMAGETYPE_BITMAP: 399*cdf0e10cSrcweir bRet = ( *static_cast< Bitmap* >( rImage.mpImplData->mpData ) == *static_cast< Bitmap* >( mpImplData->mpData ) ); 400*cdf0e10cSrcweir break; 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir case IMAGETYPE_IMAGE: 403*cdf0e10cSrcweir bRet = static_cast< ImplImageData* >( rImage.mpImplData->mpData )->IsEqual( *static_cast< ImplImageData* >( mpImplData->mpData ) ); 404*cdf0e10cSrcweir break; 405*cdf0e10cSrcweir 406*cdf0e10cSrcweir default: 407*cdf0e10cSrcweir bRet = false; 408*cdf0e10cSrcweir break; 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir return bRet; 413*cdf0e10cSrcweir } 414*cdf0e10cSrcweir 415*cdf0e10cSrcweir // ------------- 416*cdf0e10cSrcweir // - ImageList - 417*cdf0e10cSrcweir // ------------- 418*cdf0e10cSrcweir 419*cdf0e10cSrcweir ImageList::ImageList( sal_uInt16 nInit, sal_uInt16 nGrow ) : 420*cdf0e10cSrcweir mpImplData( NULL ), 421*cdf0e10cSrcweir mnInitSize( nInit ), 422*cdf0e10cSrcweir mnGrowSize( nGrow ) 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir DBG_CTOR( ImageList, NULL ); 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir // ----------------------------------------------------------------------- 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir ImageList::ImageList( const ResId& rResId ) : 430*cdf0e10cSrcweir mpImplData( NULL ), 431*cdf0e10cSrcweir mnInitSize( 1 ), 432*cdf0e10cSrcweir mnGrowSize( 4 ) 433*cdf0e10cSrcweir { 434*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "vcl: ImageList::ImageList( const ResId& rResId )" ); 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir DBG_CTOR( ImageList, NULL ); 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir rResId.SetRT( RSC_IMAGELIST ); 439*cdf0e10cSrcweir 440*cdf0e10cSrcweir ResMgr* pResMgr = rResId.GetResMgr(); 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir if( pResMgr && pResMgr->GetResource( rResId ) ) 443*cdf0e10cSrcweir { 444*cdf0e10cSrcweir pResMgr->Increment( sizeof( RSHEADER_TYPE ) ); 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir sal_uLong nObjMask = pResMgr->ReadLong(); 447*cdf0e10cSrcweir const String aPrefix( pResMgr->ReadString() ); 448*cdf0e10cSrcweir ::boost::scoped_ptr< Color > spMaskColor; 449*cdf0e10cSrcweir 450*cdf0e10cSrcweir if( nObjMask & RSC_IMAGE_MASKCOLOR ) 451*cdf0e10cSrcweir spMaskColor.reset( new Color( ResId( (RSHEADER_TYPE*)pResMgr->GetClass(), *pResMgr ) ) ); 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir pResMgr->Increment( pResMgr->GetObjSize( (RSHEADER_TYPE*)pResMgr->GetClass() ) ); 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir if( nObjMask & RSC_IMAGELIST_IDLIST ) 456*cdf0e10cSrcweir { 457*cdf0e10cSrcweir for( sal_Int32 i = 0, nCount = pResMgr->ReadLong(); i < nCount; ++i ) 458*cdf0e10cSrcweir pResMgr->ReadLong(); 459*cdf0e10cSrcweir } 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir sal_Int32 nCount = pResMgr->ReadLong(); 462*cdf0e10cSrcweir ImplInit( static_cast< sal_uInt16 >( nCount ), Size() ); 463*cdf0e10cSrcweir 464*cdf0e10cSrcweir BitmapEx aEmpty; 465*cdf0e10cSrcweir for( sal_Int32 i = 0; i < nCount; ++i ) 466*cdf0e10cSrcweir { 467*cdf0e10cSrcweir rtl::OUString aName = pResMgr->ReadString(); 468*cdf0e10cSrcweir sal_uInt16 nId = static_cast< sal_uInt16 >( pResMgr->ReadLong() ); 469*cdf0e10cSrcweir mpImplData->AddImage( aName, nId, aEmpty ); 470*cdf0e10cSrcweir } 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir if( nObjMask & RSC_IMAGELIST_IDCOUNT ) 473*cdf0e10cSrcweir pResMgr->ReadShort(); 474*cdf0e10cSrcweir } 475*cdf0e10cSrcweir } 476*cdf0e10cSrcweir 477*cdf0e10cSrcweir // ----------------------------------------------------------------------- 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir ImageList::ImageList( const ::std::vector< ::rtl::OUString >& rNameVector, 480*cdf0e10cSrcweir const ::rtl::OUString& rPrefix, 481*cdf0e10cSrcweir const Color* ) : 482*cdf0e10cSrcweir mpImplData( NULL ), 483*cdf0e10cSrcweir mnInitSize( 1 ), 484*cdf0e10cSrcweir mnGrowSize( 4 ) 485*cdf0e10cSrcweir { 486*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "vcl: ImageList::ImageList(const vector< OUString >& ..." ); 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir DBG_CTOR( ImageList, NULL ); 489*cdf0e10cSrcweir 490*cdf0e10cSrcweir ImplInit( sal::static_int_cast< sal_uInt16 >( rNameVector.size() ), Size() ); 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir mpImplData->maPrefix = rPrefix; 493*cdf0e10cSrcweir for( sal_uInt32 i = 0; i < rNameVector.size(); ++i ) 494*cdf0e10cSrcweir { 495*cdf0e10cSrcweir // fprintf (stderr, "List %p [%d]: '%s'\n", 496*cdf0e10cSrcweir // this, i, rtl::OUStringToOString( rNameVector[i], RTL_TEXTENCODING_UTF8 ).getStr() ); 497*cdf0e10cSrcweir mpImplData->AddImage( rNameVector[ i ], static_cast< sal_uInt16 >( i ) + 1, BitmapEx() ); 498*cdf0e10cSrcweir } 499*cdf0e10cSrcweir } 500*cdf0e10cSrcweir 501*cdf0e10cSrcweir // ----------------------------------------------------------------------- 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir ImageList::ImageList( const ImageList& rImageList ) : 504*cdf0e10cSrcweir mpImplData( rImageList.mpImplData ), 505*cdf0e10cSrcweir mnInitSize( rImageList.mnInitSize ), 506*cdf0e10cSrcweir mnGrowSize( rImageList.mnGrowSize ) 507*cdf0e10cSrcweir { 508*cdf0e10cSrcweir DBG_CTOR( ImageList, NULL ); 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir if( mpImplData ) 511*cdf0e10cSrcweir ++mpImplData->mnRefCount; 512*cdf0e10cSrcweir } 513*cdf0e10cSrcweir 514*cdf0e10cSrcweir // ----------------------------------------------------------------------- 515*cdf0e10cSrcweir 516*cdf0e10cSrcweir ImageList::~ImageList() 517*cdf0e10cSrcweir { 518*cdf0e10cSrcweir DBG_DTOR( ImageList, NULL ); 519*cdf0e10cSrcweir 520*cdf0e10cSrcweir if( mpImplData && ( 0 == --mpImplData->mnRefCount ) ) 521*cdf0e10cSrcweir delete mpImplData; 522*cdf0e10cSrcweir } 523*cdf0e10cSrcweir 524*cdf0e10cSrcweir void ImageList::ImplInit( sal_uInt16 nItems, const Size &rSize ) 525*cdf0e10cSrcweir { 526*cdf0e10cSrcweir mpImplData = new ImplImageList; 527*cdf0e10cSrcweir mpImplData->mnRefCount = 1; 528*cdf0e10cSrcweir mpImplData->maImages.reserve( nItems ); 529*cdf0e10cSrcweir mpImplData->maImageSize = rSize; 530*cdf0e10cSrcweir } 531*cdf0e10cSrcweir 532*cdf0e10cSrcweir // ----------------------------------------------------------------------- 533*cdf0e10cSrcweir 534*cdf0e10cSrcweir void ImageAryData::Load(const rtl::OUString &rPrefix) 535*cdf0e10cSrcweir { 536*cdf0e10cSrcweir static ImplImageTreeSingletonRef aImageTree; 537*cdf0e10cSrcweir 538*cdf0e10cSrcweir ::rtl::OUString aSymbolsStyle = Application::GetSettings().GetStyleSettings().GetCurrentSymbolsStyleName(); 539*cdf0e10cSrcweir 540*cdf0e10cSrcweir BitmapEx aBmpEx; 541*cdf0e10cSrcweir 542*cdf0e10cSrcweir // fprintf (stderr, "Attempt load of '%s'\n", 543*cdf0e10cSrcweir // rtl::OUStringToOString( maName, RTL_TEXTENCODING_UTF8 ).getStr() ); 544*cdf0e10cSrcweir 545*cdf0e10cSrcweir rtl::OUString aFileName = rPrefix; 546*cdf0e10cSrcweir aFileName += maName; 547*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 548*cdf0e10cSrcweir bool bSuccess = 549*cdf0e10cSrcweir #endif 550*cdf0e10cSrcweir aImageTree->loadImage( aFileName, aSymbolsStyle, maBitmapEx, true ); 551*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 552*cdf0e10cSrcweir if ( !bSuccess ) 553*cdf0e10cSrcweir { 554*cdf0e10cSrcweir ::rtl::OStringBuffer aMessage; 555*cdf0e10cSrcweir aMessage.append( "ImageAryData::Load: failed to load image '" ); 556*cdf0e10cSrcweir aMessage.append( ::rtl::OUStringToOString( aFileName, RTL_TEXTENCODING_UTF8 ).getStr() ); 557*cdf0e10cSrcweir aMessage.append( "'" ); 558*cdf0e10cSrcweir OSL_ENSURE( false, aMessage.makeStringAndClear().getStr() ); 559*cdf0e10cSrcweir } 560*cdf0e10cSrcweir #endif 561*cdf0e10cSrcweir } 562*cdf0e10cSrcweir 563*cdf0e10cSrcweir // ----------------------------------------------------------------------- 564*cdf0e10cSrcweir 565*cdf0e10cSrcweir void ImageList::ImplMakeUnique() 566*cdf0e10cSrcweir { 567*cdf0e10cSrcweir if( mpImplData && mpImplData->mnRefCount > 1 ) 568*cdf0e10cSrcweir { 569*cdf0e10cSrcweir --mpImplData->mnRefCount; 570*cdf0e10cSrcweir mpImplData = new ImplImageList( *mpImplData ) ; 571*cdf0e10cSrcweir } 572*cdf0e10cSrcweir } 573*cdf0e10cSrcweir 574*cdf0e10cSrcweir // ----------------------------------------------------------------------- 575*cdf0e10cSrcweir // Rather a performance hazard: 576*cdf0e10cSrcweir BitmapEx ImageList::GetAsHorizontalStrip() const 577*cdf0e10cSrcweir { 578*cdf0e10cSrcweir Size aSize( mpImplData->maImageSize ); 579*cdf0e10cSrcweir sal_uInt16 nCount = GetImageCount(); 580*cdf0e10cSrcweir if( !nCount ) 581*cdf0e10cSrcweir return BitmapEx(); 582*cdf0e10cSrcweir aSize.Width() *= nCount; 583*cdf0e10cSrcweir 584*cdf0e10cSrcweir // Load any stragglers 585*cdf0e10cSrcweir for (sal_uInt16 nIdx = 0; nIdx < nCount; nIdx++) 586*cdf0e10cSrcweir { 587*cdf0e10cSrcweir ImageAryData *pData = mpImplData->maImages[ nIdx ]; 588*cdf0e10cSrcweir if( pData->IsLoadable() ) 589*cdf0e10cSrcweir pData->Load( mpImplData->maPrefix ); 590*cdf0e10cSrcweir } 591*cdf0e10cSrcweir 592*cdf0e10cSrcweir BitmapEx aTempl = mpImplData->maImages[ 0 ]->maBitmapEx; 593*cdf0e10cSrcweir BitmapEx aResult; 594*cdf0e10cSrcweir Bitmap aPixels( aSize, aTempl.GetBitmap().GetBitCount() ); 595*cdf0e10cSrcweir if( aTempl.IsAlpha() ) 596*cdf0e10cSrcweir aResult = BitmapEx( aPixels, AlphaMask( aSize ) ); 597*cdf0e10cSrcweir else if( aTempl.IsTransparent() ) 598*cdf0e10cSrcweir aResult = BitmapEx( aPixels, Bitmap( aSize, aTempl.GetMask().GetBitCount() ) ); 599*cdf0e10cSrcweir else 600*cdf0e10cSrcweir aResult = BitmapEx( aPixels ); 601*cdf0e10cSrcweir 602*cdf0e10cSrcweir Rectangle aSrcRect( Point( 0, 0 ), mpImplData->maImageSize ); 603*cdf0e10cSrcweir for (sal_uInt16 nIdx = 0; nIdx < nCount; nIdx++) 604*cdf0e10cSrcweir { 605*cdf0e10cSrcweir Rectangle aDestRect( Point( nIdx * mpImplData->maImageSize.Width(), 0 ), 606*cdf0e10cSrcweir mpImplData->maImageSize ); 607*cdf0e10cSrcweir ImageAryData *pData = mpImplData->maImages[ nIdx ]; 608*cdf0e10cSrcweir aResult.CopyPixel( aDestRect, aSrcRect, &pData->maBitmapEx); 609*cdf0e10cSrcweir } 610*cdf0e10cSrcweir 611*cdf0e10cSrcweir return aResult; 612*cdf0e10cSrcweir } 613*cdf0e10cSrcweir 614*cdf0e10cSrcweir // ----------------------------------------------------------------------- 615*cdf0e10cSrcweir 616*cdf0e10cSrcweir void ImageList::InsertFromHorizontalStrip( const BitmapEx &rBitmapEx, 617*cdf0e10cSrcweir const std::vector< rtl::OUString > &rNameVector ) 618*cdf0e10cSrcweir { 619*cdf0e10cSrcweir sal_uInt16 nItems = sal::static_int_cast< sal_uInt16 >( rNameVector.size() ); 620*cdf0e10cSrcweir 621*cdf0e10cSrcweir // fprintf (stderr, "InsertFromHorizontalStrip (1) [%d items]\n", nItems); 622*cdf0e10cSrcweir 623*cdf0e10cSrcweir if (!nItems) 624*cdf0e10cSrcweir return; 625*cdf0e10cSrcweir 626*cdf0e10cSrcweir Size aSize( rBitmapEx.GetSizePixel() ); 627*cdf0e10cSrcweir DBG_ASSERT (rBitmapEx.GetSizePixel().Width() % nItems == 0, 628*cdf0e10cSrcweir "ImageList::InsertFromHorizontalStrip - very odd size"); 629*cdf0e10cSrcweir aSize.Width() /= nItems; 630*cdf0e10cSrcweir ImplInit( nItems, aSize ); 631*cdf0e10cSrcweir 632*cdf0e10cSrcweir for (sal_uInt16 nIdx = 0; nIdx < nItems; nIdx++) 633*cdf0e10cSrcweir { 634*cdf0e10cSrcweir BitmapEx aBitmap( rBitmapEx, Point( nIdx * aSize.Width(), 0 ), aSize ); 635*cdf0e10cSrcweir mpImplData->AddImage( rNameVector[ nIdx ], nIdx + 1, aBitmap ); 636*cdf0e10cSrcweir } 637*cdf0e10cSrcweir } 638*cdf0e10cSrcweir 639*cdf0e10cSrcweir // ----------------------------------------------------------------------- 640*cdf0e10cSrcweir 641*cdf0e10cSrcweir void ImageList::InsertFromHorizontalBitmap( const ResId& rResId, 642*cdf0e10cSrcweir sal_uInt16 nCount, 643*cdf0e10cSrcweir const Color *pMaskColor, 644*cdf0e10cSrcweir const Color *pSearchColors, 645*cdf0e10cSrcweir const Color *pReplaceColors, 646*cdf0e10cSrcweir sal_uLong nColorCount) 647*cdf0e10cSrcweir { 648*cdf0e10cSrcweir BitmapEx aBmpEx( rResId ); 649*cdf0e10cSrcweir if (!aBmpEx.IsTransparent()) 650*cdf0e10cSrcweir { 651*cdf0e10cSrcweir if( pMaskColor ) 652*cdf0e10cSrcweir aBmpEx = BitmapEx( aBmpEx.GetBitmap(), *pMaskColor ); 653*cdf0e10cSrcweir else 654*cdf0e10cSrcweir aBmpEx = BitmapEx( aBmpEx.GetBitmap() ); 655*cdf0e10cSrcweir } 656*cdf0e10cSrcweir if ( nColorCount && pSearchColors && pReplaceColors ) 657*cdf0e10cSrcweir aBmpEx.Replace( pSearchColors, pReplaceColors, nColorCount ); 658*cdf0e10cSrcweir 659*cdf0e10cSrcweir std::vector< rtl::OUString > aNames( nCount ); 660*cdf0e10cSrcweir InsertFromHorizontalStrip( aBmpEx, aNames ); 661*cdf0e10cSrcweir } 662*cdf0e10cSrcweir 663*cdf0e10cSrcweir // ----------------------------------------------------------------------- 664*cdf0e10cSrcweir 665*cdf0e10cSrcweir sal_uInt16 ImageList::ImplGetImageId( const ::rtl::OUString& rImageName ) const 666*cdf0e10cSrcweir { 667*cdf0e10cSrcweir DBG_CHKTHIS( ImageList, NULL ); 668*cdf0e10cSrcweir 669*cdf0e10cSrcweir ImageAryData *pImg = mpImplData->maNameHash[ rImageName ]; 670*cdf0e10cSrcweir if( pImg ) 671*cdf0e10cSrcweir return pImg->mnId; 672*cdf0e10cSrcweir else 673*cdf0e10cSrcweir return 0; 674*cdf0e10cSrcweir } 675*cdf0e10cSrcweir 676*cdf0e10cSrcweir // ----------------------------------------------------------------------- 677*cdf0e10cSrcweir 678*cdf0e10cSrcweir void ImageList::AddImage( sal_uInt16 nId, const Image& rImage ) 679*cdf0e10cSrcweir { 680*cdf0e10cSrcweir DBG_CHKTHIS( ImageList, NULL ); 681*cdf0e10cSrcweir DBG_CHKOBJ( &rImage, Image, NULL ); 682*cdf0e10cSrcweir DBG_ASSERT( nId, "ImageList::AddImage(): ImageId == 0" ); 683*cdf0e10cSrcweir DBG_ASSERT( GetImagePos( nId ) == IMAGELIST_IMAGE_NOTFOUND, "ImageList::AddImage() - ImageId already exists" ); 684*cdf0e10cSrcweir DBG_ASSERT( rImage.mpImplData, "ImageList::AddImage(): Wrong Size" ); 685*cdf0e10cSrcweir DBG_ASSERT( !mpImplData || (rImage.GetSizePixel() == mpImplData->maImageSize), "ImageList::AddImage(): Wrong Size" ); 686*cdf0e10cSrcweir 687*cdf0e10cSrcweir if( !mpImplData ) 688*cdf0e10cSrcweir ImplInit( 0, rImage.GetSizePixel() ); 689*cdf0e10cSrcweir 690*cdf0e10cSrcweir mpImplData->AddImage( rtl::OUString(), nId, rImage.GetBitmapEx()); 691*cdf0e10cSrcweir } 692*cdf0e10cSrcweir 693*cdf0e10cSrcweir // ----------------------------------------------------------------------- 694*cdf0e10cSrcweir 695*cdf0e10cSrcweir void ImageList::AddImage( const ::rtl::OUString& rImageName, const Image& rImage ) 696*cdf0e10cSrcweir { 697*cdf0e10cSrcweir DBG_ASSERT( GetImagePos( rImageName ) == IMAGELIST_IMAGE_NOTFOUND, "ImageList::AddImage() - ImageName already exists" ); 698*cdf0e10cSrcweir 699*cdf0e10cSrcweir if( !mpImplData ) 700*cdf0e10cSrcweir ImplInit( 0, rImage.GetSizePixel() ); 701*cdf0e10cSrcweir 702*cdf0e10cSrcweir mpImplData->AddImage( rImageName, GetImageCount() + 1, 703*cdf0e10cSrcweir rImage.GetBitmapEx() ); 704*cdf0e10cSrcweir } 705*cdf0e10cSrcweir 706*cdf0e10cSrcweir // ----------------------------------------------------------------------- 707*cdf0e10cSrcweir 708*cdf0e10cSrcweir void ImageList::ReplaceImage( sal_uInt16 nId, const Image& rImage ) 709*cdf0e10cSrcweir { 710*cdf0e10cSrcweir DBG_CHKTHIS( ImageList, NULL ); 711*cdf0e10cSrcweir DBG_CHKOBJ( &rImage, Image, NULL ); 712*cdf0e10cSrcweir DBG_ASSERT( GetImagePos( nId ) != IMAGELIST_IMAGE_NOTFOUND, "ImageList::ReplaceImage(): Unknown nId" ); 713*cdf0e10cSrcweir 714*cdf0e10cSrcweir RemoveImage( nId ); 715*cdf0e10cSrcweir AddImage( nId, rImage ); 716*cdf0e10cSrcweir } 717*cdf0e10cSrcweir 718*cdf0e10cSrcweir // ----------------------------------------------------------------------- 719*cdf0e10cSrcweir 720*cdf0e10cSrcweir void ImageList::ReplaceImage( const ::rtl::OUString& rImageName, const Image& rImage ) 721*cdf0e10cSrcweir { 722*cdf0e10cSrcweir const sal_uInt16 nId = ImplGetImageId( rImageName ); 723*cdf0e10cSrcweir 724*cdf0e10cSrcweir if( nId ) 725*cdf0e10cSrcweir { 726*cdf0e10cSrcweir RemoveImage( nId ); 727*cdf0e10cSrcweir 728*cdf0e10cSrcweir if( !mpImplData ) 729*cdf0e10cSrcweir ImplInit( 0, rImage.GetSizePixel() ); 730*cdf0e10cSrcweir mpImplData->AddImage( rImageName, nId, rImage.GetBitmapEx()); 731*cdf0e10cSrcweir } 732*cdf0e10cSrcweir } 733*cdf0e10cSrcweir 734*cdf0e10cSrcweir // ----------------------------------------------------------------------- 735*cdf0e10cSrcweir 736*cdf0e10cSrcweir void ImageList::ReplaceImage( sal_uInt16 nId, sal_uInt16 nReplaceId ) 737*cdf0e10cSrcweir { 738*cdf0e10cSrcweir DBG_CHKTHIS( ImageList, NULL ); 739*cdf0e10cSrcweir DBG_ASSERT( GetImagePos( nId ) != IMAGELIST_IMAGE_NOTFOUND, "ImageList::ReplaceImage(): Unknown nId" ); 740*cdf0e10cSrcweir DBG_ASSERT( GetImagePos( nReplaceId ) != IMAGELIST_IMAGE_NOTFOUND, "ImageList::ReplaceImage(): Unknown nReplaceId" ); 741*cdf0e10cSrcweir 742*cdf0e10cSrcweir sal_uLong nPosDest = GetImagePos( nId ); 743*cdf0e10cSrcweir sal_uLong nPosSrc = GetImagePos( nReplaceId ); 744*cdf0e10cSrcweir if( nPosDest != IMAGELIST_IMAGE_NOTFOUND && 745*cdf0e10cSrcweir nPosSrc != IMAGELIST_IMAGE_NOTFOUND ) 746*cdf0e10cSrcweir { 747*cdf0e10cSrcweir ImplMakeUnique(); 748*cdf0e10cSrcweir mpImplData->maImages[nPosDest] = mpImplData->maImages[nPosSrc]; 749*cdf0e10cSrcweir } 750*cdf0e10cSrcweir } 751*cdf0e10cSrcweir 752*cdf0e10cSrcweir // ----------------------------------------------------------------------- 753*cdf0e10cSrcweir 754*cdf0e10cSrcweir void ImageList::ReplaceImage( const ::rtl::OUString& rImageName, const ::rtl::OUString& rReplaceName ) 755*cdf0e10cSrcweir { 756*cdf0e10cSrcweir const sal_uInt16 nId1 = ImplGetImageId( rImageName ), nId2 = ImplGetImageId( rReplaceName ); 757*cdf0e10cSrcweir 758*cdf0e10cSrcweir if( nId1 && nId2 ) 759*cdf0e10cSrcweir ReplaceImage( nId1, nId2 ); 760*cdf0e10cSrcweir } 761*cdf0e10cSrcweir 762*cdf0e10cSrcweir // ----------------------------------------------------------------------- 763*cdf0e10cSrcweir 764*cdf0e10cSrcweir void ImageList::RemoveImage( sal_uInt16 nId ) 765*cdf0e10cSrcweir { 766*cdf0e10cSrcweir DBG_CHKTHIS( ImageList, NULL ); 767*cdf0e10cSrcweir 768*cdf0e10cSrcweir for( sal_uInt32 i = 0; i < mpImplData->maImages.size(); ++i ) 769*cdf0e10cSrcweir { 770*cdf0e10cSrcweir if( mpImplData->maImages[ i ]->mnId == nId ) 771*cdf0e10cSrcweir { 772*cdf0e10cSrcweir mpImplData->RemoveImage( static_cast< sal_uInt16 >( i ) ); 773*cdf0e10cSrcweir break; 774*cdf0e10cSrcweir } 775*cdf0e10cSrcweir } 776*cdf0e10cSrcweir } 777*cdf0e10cSrcweir 778*cdf0e10cSrcweir // ----------------------------------------------------------------------- 779*cdf0e10cSrcweir 780*cdf0e10cSrcweir void ImageList::RemoveImage( const ::rtl::OUString& rImageName ) 781*cdf0e10cSrcweir { 782*cdf0e10cSrcweir const sal_uInt16 nId = ImplGetImageId( rImageName ); 783*cdf0e10cSrcweir 784*cdf0e10cSrcweir if( nId ) 785*cdf0e10cSrcweir RemoveImage( nId ); 786*cdf0e10cSrcweir } 787*cdf0e10cSrcweir 788*cdf0e10cSrcweir // ----------------------------------------------------------------------- 789*cdf0e10cSrcweir 790*cdf0e10cSrcweir Image ImageList::GetImage( sal_uInt16 nId ) const 791*cdf0e10cSrcweir { 792*cdf0e10cSrcweir DBG_CHKTHIS( ImageList, NULL ); 793*cdf0e10cSrcweir 794*cdf0e10cSrcweir // fprintf (stderr, "GetImage %d\n", nId); 795*cdf0e10cSrcweir 796*cdf0e10cSrcweir Image aRet; 797*cdf0e10cSrcweir 798*cdf0e10cSrcweir if( mpImplData ) 799*cdf0e10cSrcweir { 800*cdf0e10cSrcweir std::vector<ImageAryData *>::iterator aIter; 801*cdf0e10cSrcweir for( aIter = mpImplData->maImages.begin(); 802*cdf0e10cSrcweir aIter != mpImplData->maImages.end(); aIter++) 803*cdf0e10cSrcweir { 804*cdf0e10cSrcweir if ((*aIter)->mnId == nId) 805*cdf0e10cSrcweir { 806*cdf0e10cSrcweir if( (*aIter)->IsLoadable() ) 807*cdf0e10cSrcweir (*aIter)->Load( mpImplData->maPrefix ); 808*cdf0e10cSrcweir 809*cdf0e10cSrcweir aRet = Image( (*aIter)->maBitmapEx ); 810*cdf0e10cSrcweir } 811*cdf0e10cSrcweir } 812*cdf0e10cSrcweir } 813*cdf0e10cSrcweir 814*cdf0e10cSrcweir return aRet; 815*cdf0e10cSrcweir } 816*cdf0e10cSrcweir 817*cdf0e10cSrcweir // ----------------------------------------------------------------------- 818*cdf0e10cSrcweir 819*cdf0e10cSrcweir Image ImageList::GetImage( const ::rtl::OUString& rImageName ) const 820*cdf0e10cSrcweir { 821*cdf0e10cSrcweir // fprintf (stderr, "GetImage '%s'\n", 822*cdf0e10cSrcweir // rtl::OUStringToOString( rImageName, RTL_TEXTENCODING_UTF8 ).getStr() ); 823*cdf0e10cSrcweir 824*cdf0e10cSrcweir if( mpImplData ) 825*cdf0e10cSrcweir { 826*cdf0e10cSrcweir ImageAryData *pImg = mpImplData->maNameHash[ rImageName ]; 827*cdf0e10cSrcweir 828*cdf0e10cSrcweir if( pImg ) 829*cdf0e10cSrcweir { 830*cdf0e10cSrcweir if( pImg->IsLoadable() ) 831*cdf0e10cSrcweir pImg->Load( mpImplData->maPrefix ); 832*cdf0e10cSrcweir return Image( pImg->maBitmapEx ); 833*cdf0e10cSrcweir } 834*cdf0e10cSrcweir } 835*cdf0e10cSrcweir // fprintf (stderr, "no such image\n"); 836*cdf0e10cSrcweir 837*cdf0e10cSrcweir return Image(); 838*cdf0e10cSrcweir } 839*cdf0e10cSrcweir 840*cdf0e10cSrcweir // ----------------------------------------------------------------------- 841*cdf0e10cSrcweir 842*cdf0e10cSrcweir void ImageList::Clear() 843*cdf0e10cSrcweir { 844*cdf0e10cSrcweir DBG_CHKTHIS( ImageList, NULL ); 845*cdf0e10cSrcweir 846*cdf0e10cSrcweir if( mpImplData && ( 0 == --mpImplData->mnRefCount ) ) 847*cdf0e10cSrcweir delete mpImplData; 848*cdf0e10cSrcweir 849*cdf0e10cSrcweir mpImplData = NULL; 850*cdf0e10cSrcweir } 851*cdf0e10cSrcweir 852*cdf0e10cSrcweir // ----------------------------------------------------------------------- 853*cdf0e10cSrcweir 854*cdf0e10cSrcweir sal_uInt16 ImageList::GetImageCount() const 855*cdf0e10cSrcweir { 856*cdf0e10cSrcweir DBG_CHKTHIS( ImageList, NULL ); 857*cdf0e10cSrcweir 858*cdf0e10cSrcweir return mpImplData ? static_cast< sal_uInt16 >( mpImplData->maImages.size() ) : 0; 859*cdf0e10cSrcweir } 860*cdf0e10cSrcweir 861*cdf0e10cSrcweir // ----------------------------------------------------------------------- 862*cdf0e10cSrcweir 863*cdf0e10cSrcweir sal_uInt16 ImageList::GetImagePos( sal_uInt16 nId ) const 864*cdf0e10cSrcweir { 865*cdf0e10cSrcweir DBG_CHKTHIS( ImageList, NULL ); 866*cdf0e10cSrcweir 867*cdf0e10cSrcweir if( mpImplData && nId ) 868*cdf0e10cSrcweir { 869*cdf0e10cSrcweir for( sal_uInt32 i = 0; i < mpImplData->maImages.size(); ++i ) 870*cdf0e10cSrcweir { 871*cdf0e10cSrcweir if (mpImplData->maImages[ i ]->mnId == nId) 872*cdf0e10cSrcweir return static_cast< sal_uInt16 >( i ); 873*cdf0e10cSrcweir } 874*cdf0e10cSrcweir } 875*cdf0e10cSrcweir 876*cdf0e10cSrcweir return IMAGELIST_IMAGE_NOTFOUND; 877*cdf0e10cSrcweir } 878*cdf0e10cSrcweir 879*cdf0e10cSrcweir bool ImageList::HasImageAtPos( sal_uInt16 nId ) const 880*cdf0e10cSrcweir { 881*cdf0e10cSrcweir return GetImagePos( nId ) != IMAGELIST_IMAGE_NOTFOUND; 882*cdf0e10cSrcweir } 883*cdf0e10cSrcweir 884*cdf0e10cSrcweir // ----------------------------------------------------------------------- 885*cdf0e10cSrcweir 886*cdf0e10cSrcweir sal_uInt16 ImageList::GetImagePos( const ::rtl::OUString& rImageName ) const 887*cdf0e10cSrcweir { 888*cdf0e10cSrcweir DBG_CHKTHIS( ImageList, NULL ); 889*cdf0e10cSrcweir 890*cdf0e10cSrcweir if( mpImplData && rImageName.getLength() ) 891*cdf0e10cSrcweir { 892*cdf0e10cSrcweir for( sal_uInt32 i = 0; i < mpImplData->maImages.size(); i++ ) 893*cdf0e10cSrcweir { 894*cdf0e10cSrcweir if (mpImplData->maImages[i]->maName == rImageName) 895*cdf0e10cSrcweir return static_cast< sal_uInt16 >( i ); 896*cdf0e10cSrcweir } 897*cdf0e10cSrcweir } 898*cdf0e10cSrcweir 899*cdf0e10cSrcweir return IMAGELIST_IMAGE_NOTFOUND; 900*cdf0e10cSrcweir } 901*cdf0e10cSrcweir 902*cdf0e10cSrcweir // ----------------------------------------------------------------------- 903*cdf0e10cSrcweir 904*cdf0e10cSrcweir sal_uInt16 ImageList::GetImageId( sal_uInt16 nPos ) const 905*cdf0e10cSrcweir { 906*cdf0e10cSrcweir DBG_CHKTHIS( ImageList, NULL ); 907*cdf0e10cSrcweir 908*cdf0e10cSrcweir if( mpImplData && (nPos < GetImageCount()) ) 909*cdf0e10cSrcweir return mpImplData->maImages[ nPos ]->mnId; 910*cdf0e10cSrcweir 911*cdf0e10cSrcweir return 0; 912*cdf0e10cSrcweir } 913*cdf0e10cSrcweir 914*cdf0e10cSrcweir // ----------------------------------------------------------------------- 915*cdf0e10cSrcweir 916*cdf0e10cSrcweir void ImageList::GetImageIds( ::std::vector< sal_uInt16 >& rIds ) const 917*cdf0e10cSrcweir { 918*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "vcl: ImageList::GetImageIds" ); 919*cdf0e10cSrcweir 920*cdf0e10cSrcweir DBG_CHKTHIS( ImageList, NULL ); 921*cdf0e10cSrcweir 922*cdf0e10cSrcweir rIds = ::std::vector< sal_uInt16 >(); 923*cdf0e10cSrcweir 924*cdf0e10cSrcweir if( mpImplData ) 925*cdf0e10cSrcweir { 926*cdf0e10cSrcweir for( sal_uInt32 i = 0; i < mpImplData->maImages.size(); i++ ) 927*cdf0e10cSrcweir rIds.push_back( mpImplData->maImages[i]->mnId ); 928*cdf0e10cSrcweir } 929*cdf0e10cSrcweir } 930*cdf0e10cSrcweir 931*cdf0e10cSrcweir // ----------------------------------------------------------------------- 932*cdf0e10cSrcweir 933*cdf0e10cSrcweir ::rtl::OUString ImageList::GetImageName( sal_uInt16 nPos ) const 934*cdf0e10cSrcweir { 935*cdf0e10cSrcweir DBG_CHKTHIS( ImageList, NULL ); 936*cdf0e10cSrcweir 937*cdf0e10cSrcweir if( mpImplData && (nPos < GetImageCount()) ) 938*cdf0e10cSrcweir return mpImplData->maImages[ nPos ]->maName; 939*cdf0e10cSrcweir 940*cdf0e10cSrcweir return ::rtl::OUString(); 941*cdf0e10cSrcweir } 942*cdf0e10cSrcweir 943*cdf0e10cSrcweir // ----------------------------------------------------------------------- 944*cdf0e10cSrcweir 945*cdf0e10cSrcweir void ImageList::GetImageNames( ::std::vector< ::rtl::OUString >& rNames ) const 946*cdf0e10cSrcweir { 947*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "vcl: ImageList::GetImageNames" ); 948*cdf0e10cSrcweir 949*cdf0e10cSrcweir DBG_CHKTHIS( ImageList, NULL ); 950*cdf0e10cSrcweir 951*cdf0e10cSrcweir rNames = ::std::vector< ::rtl::OUString >(); 952*cdf0e10cSrcweir 953*cdf0e10cSrcweir if( mpImplData ) 954*cdf0e10cSrcweir { 955*cdf0e10cSrcweir for( sal_uInt32 i = 0; i < mpImplData->maImages.size(); i++ ) 956*cdf0e10cSrcweir { 957*cdf0e10cSrcweir const rtl::OUString& rName( mpImplData->maImages[ i ]->maName ); 958*cdf0e10cSrcweir if( rName.getLength() != 0 ) 959*cdf0e10cSrcweir rNames.push_back( rName ); 960*cdf0e10cSrcweir } 961*cdf0e10cSrcweir } 962*cdf0e10cSrcweir } 963*cdf0e10cSrcweir 964*cdf0e10cSrcweir // ----------------------------------------------------------------------- 965*cdf0e10cSrcweir 966*cdf0e10cSrcweir Size ImageList::GetImageSize() const 967*cdf0e10cSrcweir { 968*cdf0e10cSrcweir DBG_CHKTHIS( ImageList, NULL ); 969*cdf0e10cSrcweir 970*cdf0e10cSrcweir Size aRet; 971*cdf0e10cSrcweir 972*cdf0e10cSrcweir if( mpImplData ) 973*cdf0e10cSrcweir { 974*cdf0e10cSrcweir aRet = mpImplData->maImageSize; 975*cdf0e10cSrcweir 976*cdf0e10cSrcweir // force load of 1st image to see - uncommon case. 977*cdf0e10cSrcweir if( aRet.Width() == 0 && aRet.Height() == 0 && 978*cdf0e10cSrcweir !mpImplData->maImages.empty() ) 979*cdf0e10cSrcweir { 980*cdf0e10cSrcweir Image aTmp = GetImage( mpImplData->maImages[ 0 ]->mnId ); 981*cdf0e10cSrcweir aRet = mpImplData->maImageSize = aTmp.GetSizePixel(); 982*cdf0e10cSrcweir } 983*cdf0e10cSrcweir } 984*cdf0e10cSrcweir // fprintf (stderr, "GetImageSize returns %d, %d\n", 985*cdf0e10cSrcweir // aRet.Width(), aRet.Height()); 986*cdf0e10cSrcweir 987*cdf0e10cSrcweir return aRet; 988*cdf0e10cSrcweir } 989*cdf0e10cSrcweir 990*cdf0e10cSrcweir // ----------------------------------------------------------------------- 991*cdf0e10cSrcweir 992*cdf0e10cSrcweir ImageList& ImageList::operator=( const ImageList& rImageList ) 993*cdf0e10cSrcweir { 994*cdf0e10cSrcweir DBG_CHKTHIS( ImageList, NULL ); 995*cdf0e10cSrcweir DBG_CHKOBJ( &rImageList, ImageList, NULL ); 996*cdf0e10cSrcweir 997*cdf0e10cSrcweir if( rImageList.mpImplData ) 998*cdf0e10cSrcweir ++rImageList.mpImplData->mnRefCount; 999*cdf0e10cSrcweir 1000*cdf0e10cSrcweir if( mpImplData && ( 0 == --mpImplData->mnRefCount ) ) 1001*cdf0e10cSrcweir delete mpImplData; 1002*cdf0e10cSrcweir 1003*cdf0e10cSrcweir mpImplData = rImageList.mpImplData; 1004*cdf0e10cSrcweir 1005*cdf0e10cSrcweir return *this; 1006*cdf0e10cSrcweir } 1007*cdf0e10cSrcweir 1008*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1009*cdf0e10cSrcweir 1010*cdf0e10cSrcweir sal_Bool ImageList::operator==( const ImageList& rImageList ) const 1011*cdf0e10cSrcweir { 1012*cdf0e10cSrcweir DBG_CHKTHIS( ImageList, NULL ); 1013*cdf0e10cSrcweir DBG_CHKOBJ( &rImageList, ImageList, NULL ); 1014*cdf0e10cSrcweir 1015*cdf0e10cSrcweir bool bRet = false; 1016*cdf0e10cSrcweir 1017*cdf0e10cSrcweir if( rImageList.mpImplData == mpImplData ) 1018*cdf0e10cSrcweir bRet = true; 1019*cdf0e10cSrcweir else if( !rImageList.mpImplData || !mpImplData ) 1020*cdf0e10cSrcweir bRet = false; 1021*cdf0e10cSrcweir else if( rImageList.GetImageCount() == GetImageCount() && 1022*cdf0e10cSrcweir rImageList.mpImplData->maImageSize == mpImplData->maImageSize ) 1023*cdf0e10cSrcweir bRet = true; // strange semantic 1024*cdf0e10cSrcweir 1025*cdf0e10cSrcweir return bRet; 1026*cdf0e10cSrcweir } 1027