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