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