Update ooo320-m1
[ooovba.git] / svx / source / xoutdev / xattrbmp.cxx
blobf34e9859aa88012cb47a1d4abd6c4b9498540215
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xattrbmp.cxx,v $
10 * $Revision: 1.20 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <com/sun/star/awt/XBitmap.hpp>
34 #include <com/sun/star/graphic/XGraphic.hpp>
35 #include <tools/stream.hxx>
36 #include <vcl/window.hxx>
37 #include <vcl/virdev.hxx>
38 #include <vcl/bitmapex.hxx>
39 #include <toolkit/unohlp.hxx>
40 #include <svtools/style.hxx>
42 #include <svx/dialogs.hrc>
43 #include "xattr.hxx"
44 #include <svx/xtable.hxx>
45 #include <svx/xdef.hxx>
46 #include <svx/unomid.hxx>
47 #include <svx/unoprnms.hxx>
49 #include "unoapi.hxx"
50 #include <svx/svdmodel.hxx>
51 #include <com/sun/star/beans/PropertyValue.hpp>
53 #define GLOBALOVERFLOW
55 using namespace ::com::sun::star;
57 // ---------------
58 // class XOBitmap
59 // ---------------
61 /*************************************************************************
63 |* XOBitmap::XOBitmap()
65 |* Beschreibung
66 |* Ersterstellung 27.07.95
67 |* Letzte Aenderung 27.07.95
69 *************************************************************************/
71 XOBitmap::XOBitmap() :
72 eType ( XBITMAP_NONE ),
73 eStyle ( XBITMAP_STRETCH ),
74 pPixelArray ( NULL ),
75 bGraphicDirty ( FALSE )
79 /*************************************************************************
81 |* XOBitmap::XOBitmap( Bitmap aBitmap, XBitmapStyle eStyle = XBITMAP_TILE )
83 |* Beschreibung
84 |* Ersterstellung 26.07.95
85 |* Letzte Aenderung 26.07.95
87 *************************************************************************/
89 XOBitmap::XOBitmap( const Bitmap& rBmp, XBitmapStyle eInStyle ) :
90 eType ( XBITMAP_IMPORT ),
91 eStyle ( eInStyle ),
92 aGraphicObject ( rBmp ),
93 pPixelArray ( NULL ),
94 bGraphicDirty ( FALSE )
98 /*************************************************************************
100 |* XOBitmap::XOBitmap( Bitmap aBitmap, XBitmapStyle eStyle = XBITMAP_TILE )
102 |* Beschreibung
103 |* Ersterstellung 26.07.95
104 |* Letzte Aenderung 26.07.95
106 *************************************************************************/
108 XOBitmap::XOBitmap( const GraphicObject& rGraphicObject, XBitmapStyle eInStyle ) :
109 eType ( XBITMAP_IMPORT ),
110 eStyle ( eInStyle ),
111 aGraphicObject ( rGraphicObject ),
112 pPixelArray ( NULL ),
113 bGraphicDirty ( FALSE )
117 /*************************************************************************
119 |* XOBitmap::XOBitmap( USHORT* pArray, const Color& aPixelColor,
120 |* const Color& aBckgrColor, const Size& rSize = Size( 8, 8 ),
121 |* XBitmapStyle eStyle = XBITMAP_TILE )
123 |* Beschreibung
124 |* Ersterstellung 26.07.95
125 |* Letzte Aenderung 26.07.95
127 *************************************************************************/
129 XOBitmap::XOBitmap( const USHORT* pArray, const Color& rPixelColor,
130 const Color& rBckgrColor, const Size& rSize,
131 XBitmapStyle eInStyle ) :
132 eStyle ( eInStyle ),
133 pPixelArray ( NULL ),
134 aArraySize ( rSize ),
135 aPixelColor ( rPixelColor ),
136 aBckgrColor ( rBckgrColor ),
137 bGraphicDirty ( TRUE )
140 if( aArraySize.Width() == 8 && aArraySize.Height() == 8 )
142 eType = XBITMAP_8X8;
143 pPixelArray = new USHORT[ 64 ];
145 for( USHORT i = 0; i < 64; i++ )
146 *( pPixelArray + i ) = *( pArray + i );
148 else
150 DBG_ASSERT( 0, "Nicht unterstuetzte Bitmapgroesse" );
154 /*************************************************************************
156 |* XOBitmap::XOBitmap( const XOBitmap& rXBmp )
158 |* Beschreibung
159 |* Ersterstellung 27.07.95
160 |* Letzte Aenderung 27.07.95
162 *************************************************************************/
164 XOBitmap::XOBitmap( const XOBitmap& rXBmp ) :
165 pPixelArray ( NULL )
167 eType = rXBmp.eType;
168 eStyle = rXBmp.eStyle;
169 aGraphicObject = rXBmp.aGraphicObject;
170 aArraySize = rXBmp.aArraySize;
171 aPixelColor = rXBmp.aPixelColor;
172 aBckgrColor = rXBmp.aBckgrColor;
173 bGraphicDirty = rXBmp.bGraphicDirty;
175 if( rXBmp.pPixelArray )
177 if( eType == XBITMAP_8X8 )
179 pPixelArray = new USHORT[ 64 ];
181 for( USHORT i = 0; i < 64; i++ )
182 *( pPixelArray + i ) = *( rXBmp.pPixelArray + i );
187 /*************************************************************************
189 |* XOBitmap::XOBitmap( Bitmap aBitmap, XBitmapStyle eStyle = XBITMAP_TILE )
191 |* Beschreibung
192 |* Ersterstellung 26.07.95
193 |* Letzte Aenderung 26.07.95
195 *************************************************************************/
197 XOBitmap::~XOBitmap()
199 if( pPixelArray )
200 delete []pPixelArray;
203 /*************************************************************************
205 |* XOBitmap& XOBitmap::operator=( const XOBitmap& rXBmp )
207 |* Beschreibung
208 |* Ersterstellung 27.07.95
209 |* Letzte Aenderung 27.07.95
211 *************************************************************************/
213 XOBitmap& XOBitmap::operator=( const XOBitmap& rXBmp )
215 eType = rXBmp.eType;
216 eStyle = rXBmp.eStyle;
217 aGraphicObject = rXBmp.aGraphicObject;
218 aArraySize = rXBmp.aArraySize;
219 aPixelColor = rXBmp.aPixelColor;
220 aBckgrColor = rXBmp.aBckgrColor;
221 bGraphicDirty = rXBmp.bGraphicDirty;
223 if( rXBmp.pPixelArray )
225 if( eType == XBITMAP_8X8 )
227 pPixelArray = new USHORT[ 64 ];
229 for( USHORT i = 0; i < 64; i++ )
230 *( pPixelArray + i ) = *( rXBmp.pPixelArray + i );
233 return( *this );
236 /*************************************************************************
238 |* int XOBitmap::operator==( const XOBitmap& rXOBitmap ) const
240 |* Beschreibung
241 |* Ersterstellung 26.07.95
242 |* Letzte Aenderung 26.07.95
244 *************************************************************************/
246 int XOBitmap::operator==( const XOBitmap& rXOBitmap ) const
248 if( eType != rXOBitmap.eType ||
249 eStyle != rXOBitmap.eStyle ||
250 aGraphicObject != rXOBitmap.aGraphicObject ||
251 aArraySize != rXOBitmap.aArraySize ||
252 aPixelColor != rXOBitmap.aPixelColor ||
253 aBckgrColor != rXOBitmap.aBckgrColor ||
254 bGraphicDirty != rXOBitmap.bGraphicDirty )
256 return( FALSE );
259 if( pPixelArray && rXOBitmap.pPixelArray )
261 USHORT nCount = (USHORT) ( aArraySize.Width() * aArraySize.Height() );
262 for( USHORT i = 0; i < nCount; i++ )
264 if( *( pPixelArray + i ) != *( rXOBitmap.pPixelArray + i ) )
265 return( FALSE );
268 return( TRUE );
271 /*************************************************************************
273 |* void SetPixelArray( const USHORT* pArray )
275 |* Beschreibung
276 |* Ersterstellung 27.07.95
277 |* Letzte Aenderung 27.07.95
279 *************************************************************************/
281 void XOBitmap::SetPixelArray( const USHORT* pArray )
283 if( eType == XBITMAP_8X8 )
285 if( pPixelArray )
286 delete []pPixelArray;
288 pPixelArray = new USHORT[ 64 ];
290 for( USHORT i = 0; i < 64; i++ )
291 *( pPixelArray + i ) = *( pArray + i );
293 bGraphicDirty = TRUE;
295 else
297 DBG_ASSERT( 0, "Nicht unterstuetzter Bitmaptyp" );
301 /*************************************************************************
303 |* Bitmap XOBitmap::GetBitmap()
305 |* Beschreibung
306 |* Ersterstellung 26.07.95
307 |* Letzte Aenderung 26.07.95
309 *************************************************************************/
311 Bitmap XOBitmap::GetBitmap() const
313 return GetGraphicObject().GetGraphic().GetBitmap();
316 /*************************************************************************
318 |* Bitmap XOBitmap::GetGraphicObject()
320 |* Beschreibung
321 |* Ersterstellung
322 |* Letzte Aenderung
324 *************************************************************************/
326 const GraphicObject& XOBitmap::GetGraphicObject() const
328 if( bGraphicDirty )
329 ( (XOBitmap*) this )->Array2Bitmap();
331 return aGraphicObject;
334 /*************************************************************************
336 |* void XOBitmap::Bitmap2Array()
338 |* Beschreibung Umwandlung der Bitmap in Array, Hinter- u.
339 |* Vordergrundfarbe
340 |* Ersterstellung 27.07.95
341 |* Letzte Aenderung 27.07.95
343 *************************************************************************/
345 void XOBitmap::Bitmap2Array()
347 VirtualDevice aVD;
348 BOOL bPixelColor = FALSE;
349 const Bitmap aBitmap( GetBitmap() );
350 const USHORT nLines = 8; // von Type abhaengig
352 if( !pPixelArray )
353 pPixelArray = new USHORT[ nLines * nLines ];
355 aVD.SetOutputSizePixel( aBitmap.GetSizePixel() );
356 aVD.DrawBitmap( Point(), aBitmap );
357 aPixelColor = aBckgrColor = aVD.GetPixel( Point() );
359 // Aufbau des Arrays und Ermittlung der Vorder-, bzw.
360 // Hintergrundfarbe
361 for( USHORT i = 0; i < nLines; i++ )
363 for( USHORT j = 0; j < nLines; j++ )
365 if ( aVD.GetPixel( Point( j, i ) ) == aBckgrColor )
366 *( pPixelArray + j + i * nLines ) = 0;
367 else
369 *( pPixelArray + j + i * nLines ) = 1;
370 if( !bPixelColor )
372 aPixelColor = aVD.GetPixel( Point( j, i ) );
373 bPixelColor = TRUE;
380 /*************************************************************************
382 |* void XOBitmap::Array2Bitmap()
384 |* Beschreibung Umwandlung des Arrays, Hinter- u.
385 |* Vordergrundfarbe in eine Bitmap
386 |* Ersterstellung 27.07.95
387 |* Letzte Aenderung 27.07.95
389 *************************************************************************/
391 void XOBitmap::Array2Bitmap()
393 VirtualDevice aVD;
394 USHORT nLines = 8; // von Type abhaengig
396 if( !pPixelArray )
397 return;
399 aVD.SetOutputSizePixel( Size( nLines, nLines ) );
401 // Aufbau der Bitmap
402 for( USHORT i = 0; i < nLines; i++ )
404 for( USHORT j = 0; j < nLines; j++ )
406 if( *( pPixelArray + j + i * nLines ) == 0 )
407 aVD.DrawPixel( Point( j, i ), aBckgrColor );
408 else
409 aVD.DrawPixel( Point( j, i ), aPixelColor );
413 aGraphicObject = GraphicObject( aVD.GetBitmap( Point(), Size( nLines, nLines ) ) );
414 bGraphicDirty = FALSE;
417 // -----------------------
418 // class XFillBitmapItem
419 // -----------------------
420 TYPEINIT1_AUTOFACTORY(XFillBitmapItem, NameOrIndex);
422 /*************************************************************************
424 |* XFillBitmapItem::XFillBitmapItem(long nIndex,
425 |* const Bitmap& rTheBitmap)
427 |* Beschreibung
428 |* Ersterstellung 17.11.94
429 |* Letzte Aenderung 17.11.94
431 *************************************************************************/
433 XFillBitmapItem::XFillBitmapItem(long nIndex,
434 const XOBitmap& rTheBitmap) :
435 NameOrIndex( XATTR_FILLBITMAP, nIndex ),
436 aXOBitmap( rTheBitmap )
440 /*************************************************************************
442 |* XFillBitmapItem::XFillBitmapItem(const XubString& rName,
443 |* const Bitmap& rTheBitmap)
445 |* Beschreibung
446 |* Ersterstellung 17.11.94
447 |* Letzte Aenderung 17.11.94
449 *************************************************************************/
451 XFillBitmapItem::XFillBitmapItem(const XubString& rName,
452 const XOBitmap& rTheBitmap) :
453 NameOrIndex( XATTR_FILLBITMAP, rName ),
454 aXOBitmap( rTheBitmap )
458 /*************************************************************************
460 |* XFillBitmapItem::XFillBitmapItem(const XFillBitmapItem& rItem)
462 |* Beschreibung
463 |* Ersterstellung 17.11.94
464 |* Letzte Aenderung 17.11.94
466 *************************************************************************/
468 XFillBitmapItem::XFillBitmapItem(const XFillBitmapItem& rItem) :
469 NameOrIndex( rItem ),
470 aXOBitmap( rItem.aXOBitmap )
474 /*************************************************************************
476 |* XFillBitmapItem::XFillBitmapItem(SvStream& rIn)
478 |* Beschreibung
479 |* Ersterstellung 17.11.94
480 |* Letzte Aenderung 26.07.94
482 *************************************************************************/
484 XFillBitmapItem::XFillBitmapItem( SvStream& rIn, USHORT nVer ) :
485 NameOrIndex( XATTR_FILLBITMAP, rIn )
487 if( nVer == 0 )
489 if (!IsIndex())
491 // Behandlung der alten Bitmaps
492 Bitmap aBmp;
494 rIn >> aBmp;
496 aXOBitmap.SetBitmap( aBmp );
497 aXOBitmap.SetBitmapStyle( XBITMAP_TILE );
499 if( aBmp.GetSizePixel().Width() == 8 &&
500 aBmp.GetSizePixel().Height() == 8 )
502 aXOBitmap.SetBitmapType( XBITMAP_8X8 );
503 aXOBitmap.Bitmap2Array();
505 else
506 aXOBitmap.SetBitmapType( XBITMAP_IMPORT );
509 else if( nVer == 1 )
511 if (!IsIndex())
513 INT16 iTmp;
514 rIn >> iTmp;
515 aXOBitmap.SetBitmapStyle( (XBitmapStyle) iTmp );
516 rIn >> iTmp;
517 aXOBitmap.SetBitmapType( (XBitmapType) iTmp );
519 if( aXOBitmap.GetBitmapType() == XBITMAP_IMPORT )
521 Bitmap aBmp;
522 rIn >> aBmp;
523 aXOBitmap.SetBitmap( aBmp );
525 else if( aXOBitmap.GetBitmapType() == XBITMAP_8X8 )
527 USHORT* pArray = new USHORT[ 64 ];
528 Color aColor;
530 for( USHORT i = 0; i < 64; i++ )
531 rIn >> *( pArray + i );
532 aXOBitmap.SetPixelArray( pArray );
534 rIn >> aColor;
535 aXOBitmap.SetPixelColor( aColor );
536 rIn >> aColor;
537 aXOBitmap.SetBackgroundColor( aColor );
539 delete []pArray;
544 // #81908# force bitmap to exist
545 aXOBitmap.GetBitmap();
548 //*************************************************************************
550 XFillBitmapItem::XFillBitmapItem( SfxItemPool* /*pPool*/, const XOBitmap& rTheBitmap )
551 : NameOrIndex( XATTR_FILLBITMAP, -1 ),
552 aXOBitmap( rTheBitmap )
556 //*************************************************************************
558 XFillBitmapItem::XFillBitmapItem( SfxItemPool* /*pPool*/)
559 : NameOrIndex(XATTR_FILLBITMAP, -1 )
563 /*************************************************************************
565 |* XFillBitmapItem::Clone(SfxItemPool* pPool) const
567 |* Beschreibung
568 |* Ersterstellung 17.11.94
569 |* Letzte Aenderung 17.11.94
571 *************************************************************************/
573 SfxPoolItem* XFillBitmapItem::Clone(SfxItemPool* /*pPool*/) const
575 return new XFillBitmapItem(*this);
578 /*************************************************************************
580 |* int XFillBitmapItem::operator==(const SfxPoolItem& rItem) const
582 |* Beschreibung
583 |* Ersterstellung 17.11.94
584 |* Letzte Aenderung 26.07.95
586 *************************************************************************/
588 int XFillBitmapItem::operator==(const SfxPoolItem& rItem) const
590 return ( NameOrIndex::operator==(rItem) &&
591 aXOBitmap == ((const XFillBitmapItem&) rItem).aXOBitmap );
594 /*************************************************************************
596 |* SfxPoolItem* XFillBitmapItem::Create(SvStream& rIn, USHORT nVer) const
598 |* Beschreibung
599 |* Ersterstellung 17.11.94
600 |* Letzte Aenderung 17.11.94
602 *************************************************************************/
604 SfxPoolItem* XFillBitmapItem::Create(SvStream& rIn, USHORT nVer) const
606 return new XFillBitmapItem( rIn, nVer );
609 /*************************************************************************
611 |* SfxPoolItem* XFillBitmapItem::Store(SvStream& rOut) const
613 |* Beschreibung
614 |* Ersterstellung 17.11.94
615 |* Letzte Aenderung 26.07.94
617 *************************************************************************/
619 SvStream& XFillBitmapItem::Store( SvStream& rOut, USHORT nItemVersion ) const
621 NameOrIndex::Store( rOut, nItemVersion );
623 if (!IsIndex())
625 rOut << (INT16) aXOBitmap.GetBitmapStyle();
626 if( !aXOBitmap.GetBitmap() )
627 rOut << (INT16) XBITMAP_NONE;
628 else
630 rOut << (INT16) aXOBitmap.GetBitmapType();
631 if( aXOBitmap.GetBitmapType() == XBITMAP_IMPORT )
633 const USHORT nOldComprMode = rOut.GetCompressMode();
634 USHORT nNewComprMode = nOldComprMode;
636 if( rOut.GetVersion() >= SOFFICE_FILEFORMAT_50 )
637 nNewComprMode |= COMPRESSMODE_ZBITMAP;
638 else
639 nNewComprMode &= ~COMPRESSMODE_ZBITMAP;
641 rOut.SetCompressMode( nNewComprMode );
642 rOut << aXOBitmap.GetBitmap();
643 rOut.SetCompressMode( nOldComprMode );
645 else if( aXOBitmap.GetBitmapType() == XBITMAP_8X8 )
647 USHORT* pArray = aXOBitmap.GetPixelArray();
648 for( USHORT i = 0; i < 64; i++ )
649 rOut << (USHORT) *( pArray + i );
651 rOut << aXOBitmap.GetPixelColor();
652 rOut << aXOBitmap.GetBackgroundColor();
657 return rOut;
660 /*************************************************************************
662 |* const Bitmap& XFillBitmapItem::GetValue(const XBitmapTable* pTable) const
664 |* Beschreibung
665 |* Ersterstellung 15.11.94
666 |* Letzte Aenderung 26.07.94
668 *************************************************************************/
670 const XOBitmap& XFillBitmapItem::GetBitmapValue(const XBitmapTable* pTable) const // GetValue -> GetBitmapValue
672 if (!IsIndex())
673 return aXOBitmap;
674 else
675 return pTable->GetBitmap(GetIndex())->GetXBitmap();
679 /*************************************************************************
681 |* USHORT XFillBitmapItem::GetVersion() const
683 |* Beschreibung
684 |* Ersterstellung 26.07.95
685 |* Letzte Aenderung 26.07.95
687 *************************************************************************/
689 USHORT XFillBitmapItem::GetVersion( USHORT /*nFileFormatVersion*/) const
691 // 2. Version
692 return( 1 );
695 //------------------------------------------------------------------------
697 SfxItemPresentation XFillBitmapItem::GetPresentation
699 SfxItemPresentation ePres,
700 SfxMapUnit /*eCoreUnit*/,
701 SfxMapUnit /*ePresUnit*/,
702 XubString& rText, const IntlWrapper *
703 ) const
705 switch ( ePres )
707 case SFX_ITEM_PRESENTATION_NONE:
708 rText.Erase();
709 return ePres;
710 case SFX_ITEM_PRESENTATION_NAMELESS:
711 case SFX_ITEM_PRESENTATION_COMPLETE:
712 rText += GetName();
713 return ePres;
714 default:
715 return SFX_ITEM_PRESENTATION_NONE;
719 //------------------------------------------------------------------------
721 sal_Bool XFillBitmapItem::QueryValue( ::com::sun::star::uno::Any& rVal, BYTE nMemberId ) const
723 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
724 nMemberId &= ~CONVERT_TWIPS;
726 // needed for MID_NAME
727 ::rtl::OUString aApiName;
728 // needed for complete item (MID 0)
729 ::rtl::OUString aInternalName;
731 ::rtl::OUString aURL;
732 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap > xBmp;
734 if( nMemberId == MID_NAME )
736 SvxUnogetApiNameForItem( Which(), GetName(), aApiName );
738 else if( nMemberId == 0 )
740 aInternalName = GetName();
743 if( nMemberId == MID_GRAFURL ||
744 nMemberId == 0 )
746 XOBitmap aLocalXOBitmap( GetBitmapValue() );
747 aURL = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_GRAPHOBJ_URLPREFIX));
748 aURL += ::rtl::OUString::createFromAscii( aLocalXOBitmap.GetGraphicObject().GetUniqueID().GetBuffer() );
750 if( nMemberId == MID_BITMAP ||
751 nMemberId == 0 )
753 XOBitmap aLocalXOBitmap( GetBitmapValue() );
754 Bitmap aBmp( aLocalXOBitmap.GetBitmap() );
755 BitmapEx aBmpEx( aBmp );
757 xBmp.set( VCLUnoHelper::CreateBitmap( aBmpEx ) );
760 if( nMemberId == MID_NAME )
761 rVal <<= aApiName;
762 else if( nMemberId == MID_GRAFURL )
763 rVal <<= aURL;
764 else if( nMemberId == MID_BITMAP )
765 rVal <<= xBmp;
766 else
768 // member-id 0 => complete item (e.g. for toolbars)
769 DBG_ASSERT( nMemberId == 0, "invalid member-id" );
770 uno::Sequence< beans::PropertyValue > aPropSeq( 3 );
772 aPropSeq[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ));
773 aPropSeq[0].Value = uno::makeAny( aInternalName );
774 aPropSeq[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FillBitmapURL" ));
775 aPropSeq[1].Value = uno::makeAny( aURL );
776 aPropSeq[2].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Bitmap" ));
777 aPropSeq[2].Value = uno::makeAny( xBmp );
779 rVal <<= aPropSeq;
782 return sal_True;
785 //------------------------------------------------------------------------
787 sal_Bool XFillBitmapItem::PutValue( const ::com::sun::star::uno::Any& rVal, BYTE nMemberId )
789 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
790 nMemberId &= ~CONVERT_TWIPS;
792 ::rtl::OUString aName;
793 ::rtl::OUString aURL;
794 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap > xBmp;
795 ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > xGraphic;
797 bool bSetName = false;
798 bool bSetURL = false;
799 bool bSetBitmap = false;
801 if( nMemberId == MID_NAME )
802 bSetName = (rVal >>= aName);
803 else if( nMemberId == MID_GRAFURL )
804 bSetURL = (rVal >>= aURL);
805 else if( nMemberId == MID_BITMAP )
807 bSetBitmap = (rVal >>= xBmp);
808 if ( !bSetBitmap )
809 bSetBitmap = (rVal >>= xGraphic );
811 else
813 DBG_ASSERT( nMemberId == 0, "invalid member-id" );
814 uno::Sequence< beans::PropertyValue > aPropSeq;
815 if( rVal >>= aPropSeq )
817 for ( sal_Int32 n = 0; n < aPropSeq.getLength(); n++ )
819 if( aPropSeq[n].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Name" )))
820 bSetName = (aPropSeq[n].Value >>= aName);
821 else if( aPropSeq[n].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "FillBitmapURL" )))
822 bSetURL = (aPropSeq[n].Value >>= aURL);
823 else if( aPropSeq[n].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Bitmap" )))
824 bSetBitmap = (aPropSeq[n].Value >>= xBmp);
829 if( bSetName )
831 SetName( aName );
833 if( bSetURL )
835 GraphicObject aGrafObj( CreateGraphicObjectFromURL( aURL ) );
836 XOBitmap aBMP( aGrafObj );
837 SetBitmapValue( aBMP );
839 if( bSetBitmap )
841 Bitmap aInput;
842 if ( xBmp.is() )
844 BitmapEx aInputEx( VCLUnoHelper::GetBitmap( xBmp ) );
845 aInput = aInputEx.GetBitmap();
847 else if ( xGraphic.is() )
849 Graphic aGraphic( xGraphic );
850 aInput = aGraphic.GetBitmap();
853 // note: aXOBitmap is the member bitmap
854 aXOBitmap.SetBitmap( aInput );
855 aXOBitmap.SetBitmapType(XBITMAP_IMPORT);
857 if(aInput.GetSizePixel().Width() == 8
858 && aInput.GetSizePixel().Height() == 8
859 && aInput.GetColorCount() == 2)
861 aXOBitmap.Bitmap2Array();
862 aXOBitmap.SetBitmapType(XBITMAP_8X8);
863 aXOBitmap.SetPixelSize(aInput.GetSizePixel());
867 return (bSetName || bSetURL || bSetBitmap);
870 BOOL XFillBitmapItem::CompareValueFunc( const NameOrIndex* p1, const NameOrIndex* p2 )
872 return ((XFillBitmapItem*)p1)->GetBitmapValue().GetGraphicObject().GetUniqueID() ==
873 ((XFillBitmapItem*)p2)->GetBitmapValue().GetGraphicObject().GetUniqueID();
876 XFillBitmapItem* XFillBitmapItem::checkForUniqueItem( SdrModel* pModel ) const
878 if( pModel )
880 const String aUniqueName = NameOrIndex::CheckNamedItem( this,
881 XATTR_FILLBITMAP,
882 &pModel->GetItemPool(),
883 pModel->GetStyleSheetPool() ? &pModel->GetStyleSheetPool()->GetPool() : NULL,
884 XFillBitmapItem::CompareValueFunc,
885 RID_SVXSTR_BMP21,
886 pModel->GetBitmapList() );
888 // if the given name is not valid, replace it!
889 if( aUniqueName != GetName() )
891 return new XFillBitmapItem( aUniqueName, aXOBitmap );
895 return (XFillBitmapItem*)this;