xref: /aoo41x/main/svx/source/xoutdev/xattrbmp.cxx (revision f6e50924)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 #include <com/sun/star/awt/XBitmap.hpp>
27 #include <com/sun/star/graphic/XGraphic.hpp>
28 #include <tools/stream.hxx>
29 #include <vcl/window.hxx>
30 #include <vcl/virdev.hxx>
31 #include <vcl/bitmapex.hxx>
32 #include <toolkit/unohlp.hxx>
33 #include <svl/style.hxx>
34 #include <editeng/memberids.hrc>
35 
36 #include <svx/dialogs.hrc>
37 #include "svx/xattr.hxx"
38 #include <svx/xtable.hxx>
39 #include <svx/xdef.hxx>
40 #include <svx/unomid.hxx>
41 #include <editeng/unoprnms.hxx>
42 
43 #include "svx/unoapi.hxx"
44 #include <svx/svdmodel.hxx>
45 #include <com/sun/star/beans/PropertyValue.hpp>
46 
47 #define GLOBALOVERFLOW
48 
49 using namespace ::com::sun::star;
50 
51 // ---------------
52 // class XOBitmap
53 // ---------------
54 
55 /*************************************************************************
56 |*
57 |*    XOBitmap::XOBitmap()
58 |*
59 |*    Beschreibung
60 |*    Ersterstellung    27.07.95
61 |*    Letzte Aenderung  27.07.95
62 |*
63 *************************************************************************/
64 
65 XOBitmap::XOBitmap() :
66 	eType			( XBITMAP_NONE ),
67 	eStyle			( XBITMAP_STRETCH ),
68 	pPixelArray		( NULL ),
69 	bGraphicDirty	( sal_False )
70 {
71 }
72 
73 /*************************************************************************
74 |*
75 |*    XOBitmap::XOBitmap( Bitmap aBitmap, XBitmapStyle eStyle = XBITMAP_TILE )
76 |*
77 |*    Beschreibung
78 |*    Ersterstellung    26.07.95
79 |*    Letzte Aenderung  26.07.95
80 |*
81 *************************************************************************/
82 
83 XOBitmap::XOBitmap( const Bitmap& rBmp, XBitmapStyle eInStyle ) :
84 	eType			( XBITMAP_IMPORT ),
85 	eStyle			( eInStyle ),
86 	aGraphicObject	( rBmp ),
87 	pPixelArray		( NULL ),
88 	bGraphicDirty	( sal_False )
89 {
90 }
91 
92 /*************************************************************************
93 |*
94 |*    XOBitmap::XOBitmap( Bitmap aBitmap, XBitmapStyle eStyle = XBITMAP_TILE )
95 |*
96 |*    Beschreibung
97 |*    Ersterstellung    26.07.95
98 |*    Letzte Aenderung  26.07.95
99 |*
100 *************************************************************************/
101 
102 XOBitmap::XOBitmap( const GraphicObject& rGraphicObject, XBitmapStyle eInStyle ) :
103 	eType			( XBITMAP_IMPORT ),
104 	eStyle			( eInStyle ),
105 	aGraphicObject	( rGraphicObject ),
106 	pPixelArray		( NULL ),
107 	bGraphicDirty	( sal_False )
108 {
109 }
110 
111 /*************************************************************************
112 |*
113 |*    XOBitmap::XOBitmap( sal_uInt16* pArray, const Color& aPixelColor,
114 |*          const Color& aBckgrColor, const Size& rSize = Size( 8, 8 ),
115 |*          XBitmapStyle eStyle = XBITMAP_TILE )
116 |*
117 |*    Beschreibung
118 |*    Ersterstellung    26.07.95
119 |*    Letzte Aenderung  26.07.95
120 |*
121 *************************************************************************/
122 
123 XOBitmap::XOBitmap( const sal_uInt16* pArray, const Color& rPixelColor,
124 			const Color& rBckgrColor, const Size& rSize,
125 			XBitmapStyle eInStyle ) :
126 	eStyle			( eInStyle ),
127 	pPixelArray		( NULL ),
128 	aArraySize		( rSize ),
129 	aPixelColor		( rPixelColor ),
130 	aBckgrColor		( rBckgrColor ),
131 	bGraphicDirty	( sal_True )
132 
133 {
134 	if( aArraySize.Width() == 8 && aArraySize.Height() == 8 )
135 	{
136 		eType = XBITMAP_8X8;
137 		pPixelArray = new sal_uInt16[ 64 ];
138 
139 		for( sal_uInt16 i = 0; i < 64; i++ )
140 			*( pPixelArray + i ) = *( pArray + i );
141 	}
142 	else
143 	{
144 		DBG_ASSERT( 0, "Nicht unterstuetzte Bitmapgroesse" );
145 	}
146 }
147 
148 /*************************************************************************
149 |*
150 |*    XOBitmap::XOBitmap( const XOBitmap& rXBmp )
151 |*
152 |*    Beschreibung
153 |*    Ersterstellung    27.07.95
154 |*    Letzte Aenderung  27.07.95
155 |*
156 *************************************************************************/
157 
158 XOBitmap::XOBitmap( const XOBitmap& rXBmp ) :
159 	pPixelArray ( NULL )
160 {
161 	eType = rXBmp.eType;
162 	eStyle = rXBmp.eStyle;
163 	aGraphicObject = rXBmp.aGraphicObject;
164 	aArraySize = rXBmp.aArraySize;
165 	aPixelColor = rXBmp.aPixelColor;
166 	aBckgrColor = rXBmp.aBckgrColor;
167 	bGraphicDirty = rXBmp.bGraphicDirty;
168 
169 	if( rXBmp.pPixelArray )
170 	{
171 		if( eType == XBITMAP_8X8 )
172 		{
173 			pPixelArray = new sal_uInt16[ 64 ];
174 
175 			for( sal_uInt16 i = 0; i < 64; i++ )
176 				*( pPixelArray + i ) = *( rXBmp.pPixelArray + i );
177 		}
178 	}
179 }
180 
181 /*************************************************************************
182 |*
183 |*    XOBitmap::XOBitmap( Bitmap aBitmap, XBitmapStyle eStyle = XBITMAP_TILE )
184 |*
185 |*    Beschreibung
186 |*    Ersterstellung    26.07.95
187 |*    Letzte Aenderung  26.07.95
188 |*
189 *************************************************************************/
190 
191 XOBitmap::~XOBitmap()
192 {
193 	if( pPixelArray )
194 		delete []pPixelArray;
195 }
196 
197 /*************************************************************************
198 |*
199 |*    XOBitmap& XOBitmap::operator=( const XOBitmap& rXBmp )
200 |*
201 |*    Beschreibung
202 |*    Ersterstellung    27.07.95
203 |*    Letzte Aenderung  27.07.95
204 |*
205 *************************************************************************/
206 
207 XOBitmap& XOBitmap::operator=( const XOBitmap& rXBmp )
208 {
209 	eType = rXBmp.eType;
210 	eStyle = rXBmp.eStyle;
211 	aGraphicObject = rXBmp.aGraphicObject;
212 	aArraySize = rXBmp.aArraySize;
213 	aPixelColor = rXBmp.aPixelColor;
214 	aBckgrColor = rXBmp.aBckgrColor;
215 	bGraphicDirty = rXBmp.bGraphicDirty;
216 
217 	if( rXBmp.pPixelArray )
218 	{
219 		if( eType == XBITMAP_8X8 )
220 		{
221 			pPixelArray = new sal_uInt16[ 64 ];
222 
223 			for( sal_uInt16 i = 0; i < 64; i++ )
224 				*( pPixelArray + i ) = *( rXBmp.pPixelArray + i );
225 		}
226 	}
227 	return( *this );
228 }
229 
230 /*************************************************************************
231 |*
232 |*    int XOBitmap::operator==( const XOBitmap& rXOBitmap ) const
233 |*
234 |*    Beschreibung
235 |*    Ersterstellung    26.07.95
236 |*    Letzte Aenderung  26.07.95
237 |*
238 *************************************************************************/
239 
240 int XOBitmap::operator==( const XOBitmap& rXOBitmap ) const
241 {
242 	if( eType != rXOBitmap.eType      ||
243 		eStyle != rXOBitmap.eStyle         ||
244 		aGraphicObject != rXOBitmap.aGraphicObject ||
245 		aArraySize != rXOBitmap.aArraySize     ||
246 		aPixelColor != rXOBitmap.aPixelColor ||
247 		aBckgrColor != rXOBitmap.aBckgrColor ||
248 		bGraphicDirty != rXOBitmap.bGraphicDirty )
249 	{
250 		return( sal_False );
251 	}
252 
253 	if( pPixelArray && rXOBitmap.pPixelArray )
254 	{
255 		sal_uInt16 nCount = (sal_uInt16) ( aArraySize.Width() * aArraySize.Height() );
256 		for( sal_uInt16 i = 0; i < nCount; i++ )
257 		{
258 			if( *( pPixelArray + i ) != *( rXOBitmap.pPixelArray + i ) )
259 				return( sal_False );
260 		}
261 	}
262 	return( sal_True );
263 }
264 
265 /*************************************************************************
266 |*
267 |*    void SetPixelArray( const sal_uInt16* pArray )
268 |*
269 |*    Beschreibung
270 |*    Ersterstellung    27.07.95
271 |*    Letzte Aenderung  27.07.95
272 |*
273 *************************************************************************/
274 
275 void XOBitmap::SetPixelArray( const sal_uInt16* pArray )
276 {
277 	if( eType == XBITMAP_8X8 )
278 	{
279 		if( pPixelArray )
280 			delete []pPixelArray;
281 
282 		pPixelArray = new sal_uInt16[ 64 ];
283 
284 		for( sal_uInt16 i = 0; i < 64; i++ )
285 			*( pPixelArray + i ) = *( pArray + i );
286 
287 		bGraphicDirty = sal_True;
288 	}
289 	else
290 	{
291 		DBG_ASSERT( 0, "Nicht unterstuetzter Bitmaptyp" );
292 	}
293 }
294 
295 /*************************************************************************
296 |*
297 |*    Bitmap XOBitmap::GetBitmap()
298 |*
299 |*    Beschreibung
300 |*    Ersterstellung    26.07.95
301 |*    Letzte Aenderung  26.07.95
302 |*
303 *************************************************************************/
304 
305 Bitmap XOBitmap::GetBitmap() const
306 {
307 	return GetGraphicObject().GetGraphic().GetBitmap();
308 }
309 
310 /*************************************************************************
311 |*
312 |*    Bitmap XOBitmap::GetGraphicObject()
313 |*
314 |*    Beschreibung
315 |*    Ersterstellung
316 |*    Letzte Aenderung
317 |*
318 *************************************************************************/
319 
320 const GraphicObject& XOBitmap::GetGraphicObject() const
321 {
322 	if( bGraphicDirty )
323 		( (XOBitmap*) this )->Array2Bitmap();
324 
325 	return aGraphicObject;
326 }
327 
328 /*************************************************************************
329 |*
330 |*    void XOBitmap::Bitmap2Array()
331 |*
332 |*    Beschreibung      Umwandlung der Bitmap in Array, Hinter- u.
333 |*                      Vordergrundfarbe
334 |*    Ersterstellung    27.07.95
335 |*    Letzte Aenderung  27.07.95
336 |*
337 *************************************************************************/
338 
339 void XOBitmap::Bitmap2Array()
340 {
341 	VirtualDevice   aVD;
342 	sal_Bool            bPixelColor = sal_False;
343 	const Bitmap	aBitmap( GetBitmap() );
344 	const sal_uInt16	nLines = 8; // von Type abhaengig
345 
346 	if( !pPixelArray )
347 		pPixelArray = new sal_uInt16[ nLines * nLines ];
348 
349 	aVD.SetOutputSizePixel( aBitmap.GetSizePixel() );
350 	aVD.DrawBitmap( Point(), aBitmap );
351 	aPixelColor = aBckgrColor = aVD.GetPixel( Point() );
352 
353 	// Aufbau des Arrays und Ermittlung der Vorder-, bzw.
354 	// Hintergrundfarbe
355 	for( sal_uInt16 i = 0; i < nLines; i++ )
356 	{
357 		for( sal_uInt16 j = 0; j < nLines; j++ )
358 		{
359 			if ( aVD.GetPixel( Point( j, i ) ) == aBckgrColor )
360 				*( pPixelArray + j + i * nLines ) = 0;
361 			else
362 			{
363 				*( pPixelArray + j + i * nLines ) = 1;
364 				if( !bPixelColor )
365 				{
366 					aPixelColor = aVD.GetPixel( Point( j, i ) );
367 					bPixelColor = sal_True;
368 				}
369 			}
370 		}
371 	}
372 }
373 
374 /*************************************************************************
375 |*
376 |*    void XOBitmap::Array2Bitmap()
377 |*
378 |*    Beschreibung      Umwandlung des Arrays, Hinter- u.
379 |*                      Vordergrundfarbe in eine Bitmap
380 |*    Ersterstellung    27.07.95
381 |*    Letzte Aenderung  27.07.95
382 |*
383 *************************************************************************/
384 
385 void XOBitmap::Array2Bitmap()
386 {
387 	VirtualDevice   aVD;
388 	sal_uInt16          nLines = 8; // von Type abhaengig
389 
390 	if( !pPixelArray )
391 		return;
392 
393 	aVD.SetOutputSizePixel( Size( nLines, nLines ) );
394 
395 	// Aufbau der Bitmap
396 	for( sal_uInt16 i = 0; i < nLines; i++ )
397 	{
398 		for( sal_uInt16 j = 0; j < nLines; j++ )
399 		{
400 			if( *( pPixelArray + j + i * nLines ) == 0 )
401 				aVD.DrawPixel( Point( j, i ), aBckgrColor );
402 			else
403 				aVD.DrawPixel( Point( j, i ), aPixelColor );
404 		}
405 	}
406 
407 	aGraphicObject = GraphicObject( aVD.GetBitmap( Point(), Size( nLines, nLines ) ) );
408 	bGraphicDirty = sal_False;
409 }
410 
411 // -----------------------
412 // class XFillBitmapItem
413 // -----------------------
414 TYPEINIT1_AUTOFACTORY(XFillBitmapItem, NameOrIndex);
415 
416 /*************************************************************************
417 |*
418 |*    XFillBitmapItem::XFillBitmapItem(long nIndex,
419 |*                                   const Bitmap& rTheBitmap)
420 |*
421 |*    Beschreibung
422 |*    Ersterstellung    17.11.94
423 |*    Letzte Aenderung  17.11.94
424 |*
425 *************************************************************************/
426 
427 XFillBitmapItem::XFillBitmapItem(long nIndex,
428 							   const XOBitmap& rTheBitmap) :
429 	NameOrIndex( XATTR_FILLBITMAP, nIndex ),
430 	aXOBitmap( rTheBitmap )
431 {
432 }
433 
434 /*************************************************************************
435 |*
436 |*    XFillBitmapItem::XFillBitmapItem(const XubString& rName,
437 |*                                 const Bitmap& rTheBitmap)
438 |*
439 |*    Beschreibung
440 |*    Ersterstellung    17.11.94
441 |*    Letzte Aenderung  17.11.94
442 |*
443 *************************************************************************/
444 
445 XFillBitmapItem::XFillBitmapItem(const XubString& rName,
446 							   const XOBitmap& rTheBitmap) :
447 	NameOrIndex( XATTR_FILLBITMAP, rName ),
448 	aXOBitmap( rTheBitmap )
449 {
450 }
451 
452 /*************************************************************************
453 |*
454 |*    XFillBitmapItem::XFillBitmapItem(const XFillBitmapItem& rItem)
455 |*
456 |*    Beschreibung
457 |*    Ersterstellung    17.11.94
458 |*    Letzte Aenderung  17.11.94
459 |*
460 *************************************************************************/
461 
462 XFillBitmapItem::XFillBitmapItem(const XFillBitmapItem& rItem) :
463 	NameOrIndex( rItem ),
464 	aXOBitmap( rItem.aXOBitmap )
465 {
466 }
467 
468 /*************************************************************************
469 |*
470 |*    XFillBitmapItem::XFillBitmapItem(SvStream& rIn)
471 |*
472 |*    Beschreibung
473 |*    Ersterstellung    17.11.94
474 |*    Letzte Aenderung  26.07.94
475 |*
476 *************************************************************************/
477 
478 XFillBitmapItem::XFillBitmapItem( SvStream& rIn, sal_uInt16 nVer ) :
479 	NameOrIndex( XATTR_FILLBITMAP, rIn )
480 {
481 	if( nVer == 0 )
482 	{
483 		if (!IsIndex())
484 		{
485 			// Behandlung der alten Bitmaps
486 			Bitmap aBmp;
487 
488 			rIn >> aBmp;
489 
490 			aXOBitmap.SetBitmap( aBmp );
491 			aXOBitmap.SetBitmapStyle( XBITMAP_TILE );
492 
493 			if( aBmp.GetSizePixel().Width() == 8 &&
494 				aBmp.GetSizePixel().Height() == 8 )
495 			{
496 				aXOBitmap.SetBitmapType( XBITMAP_8X8 );
497 				aXOBitmap.Bitmap2Array();
498 			}
499 			else
500 				aXOBitmap.SetBitmapType( XBITMAP_IMPORT );
501 		}
502 	}
503 	else if( nVer == 1 )
504 	{
505 		if (!IsIndex())
506 		{
507 			sal_Int16 iTmp;
508 			rIn >> iTmp;
509 			aXOBitmap.SetBitmapStyle( (XBitmapStyle) iTmp );
510 			rIn >> iTmp;
511 			aXOBitmap.SetBitmapType( (XBitmapType) iTmp );
512 
513 			if( aXOBitmap.GetBitmapType() == XBITMAP_IMPORT )
514 			{
515 				Bitmap aBmp;
516 				rIn >> aBmp;
517 				aXOBitmap.SetBitmap( aBmp );
518 			}
519 			else if( aXOBitmap.GetBitmapType() == XBITMAP_8X8 )
520 			{
521 				sal_uInt16* pArray = new sal_uInt16[ 64 ];
522 				Color   aColor;
523 
524 				for( sal_uInt16 i = 0; i < 64; i++ )
525 					rIn >> *( pArray + i );
526 				aXOBitmap.SetPixelArray( pArray );
527 
528 				rIn >> aColor;
529 				aXOBitmap.SetPixelColor( aColor );
530 				rIn >> aColor;
531 				aXOBitmap.SetBackgroundColor( aColor );
532 
533 				delete []pArray;
534 			}
535 		}
536 	}
537 
538 	// #81908# force bitmap to exist
539 	aXOBitmap.GetBitmap();
540 }
541 
542 //*************************************************************************
543 
544 XFillBitmapItem::XFillBitmapItem( SfxItemPool* /*pPool*/, const XOBitmap& rTheBitmap )
545 : 	NameOrIndex( XATTR_FILLBITMAP, -1 ),
546 	aXOBitmap( rTheBitmap )
547 {
548 }
549 
550 //*************************************************************************
551 
552 XFillBitmapItem::XFillBitmapItem( SfxItemPool* /*pPool*/)
553 : NameOrIndex(XATTR_FILLBITMAP, -1 )
554 {
555 }
556 
557 /*************************************************************************
558 |*
559 |*    XFillBitmapItem::Clone(SfxItemPool* pPool) const
560 |*
561 |*    Beschreibung
562 |*    Ersterstellung    17.11.94
563 |*    Letzte Aenderung  17.11.94
564 |*
565 *************************************************************************/
566 
567 SfxPoolItem* XFillBitmapItem::Clone(SfxItemPool* /*pPool*/) const
568 {
569 	return new XFillBitmapItem(*this);
570 }
571 
572 /*************************************************************************
573 |*
574 |*    int XFillBitmapItem::operator==(const SfxPoolItem& rItem) const
575 |*
576 |*    Beschreibung
577 |*    Ersterstellung    17.11.94
578 |*    Letzte Aenderung  26.07.95
579 |*
580 *************************************************************************/
581 
582 int XFillBitmapItem::operator==(const SfxPoolItem& rItem) const
583 {
584 	return ( NameOrIndex::operator==(rItem) &&
585 			 aXOBitmap == ((const XFillBitmapItem&) rItem).aXOBitmap );
586 }
587 
588 /*************************************************************************
589 |*
590 |*    SfxPoolItem* XFillBitmapItem::Create(SvStream& rIn, sal_uInt16 nVer) const
591 |*
592 |*    Beschreibung
593 |*    Ersterstellung    17.11.94
594 |*    Letzte Aenderung  17.11.94
595 |*
596 *************************************************************************/
597 
598 SfxPoolItem* XFillBitmapItem::Create(SvStream& rIn, sal_uInt16 nVer) const
599 {
600 	return new XFillBitmapItem( rIn, nVer );
601 }
602 
603 /*************************************************************************
604 |*
605 |*    SfxPoolItem* XFillBitmapItem::Store(SvStream& rOut) const
606 |*
607 |*    Beschreibung
608 |*    Ersterstellung    17.11.94
609 |*    Letzte Aenderung  26.07.94
610 |*
611 *************************************************************************/
612 
613 SvStream& XFillBitmapItem::Store( SvStream& rOut, sal_uInt16 nItemVersion ) const
614 {
615 	NameOrIndex::Store( rOut, nItemVersion );
616 
617 	if (!IsIndex())
618 	{
619 		rOut << (sal_Int16) aXOBitmap.GetBitmapStyle();
620 		if( !aXOBitmap.GetBitmap() )
621 			rOut << (sal_Int16) XBITMAP_NONE;
622 		else
623 		{
624 			rOut << (sal_Int16) aXOBitmap.GetBitmapType();
625 			if( aXOBitmap.GetBitmapType() == XBITMAP_IMPORT )
626 			{
627 				const sal_uInt16    nOldComprMode = rOut.GetCompressMode();
628 				sal_uInt16          nNewComprMode = nOldComprMode;
629 
630 				if( rOut.GetVersion() >= SOFFICE_FILEFORMAT_50 )
631 					nNewComprMode |= COMPRESSMODE_ZBITMAP;
632 				else
633 					nNewComprMode &= ~COMPRESSMODE_ZBITMAP;
634 
635 				rOut.SetCompressMode( nNewComprMode );
636 				rOut << aXOBitmap.GetBitmap();
637 				rOut.SetCompressMode( nOldComprMode );
638 			}
639 			else if( aXOBitmap.GetBitmapType() == XBITMAP_8X8 )
640 			{
641 				sal_uInt16* pArray = aXOBitmap.GetPixelArray();
642 				for( sal_uInt16 i = 0; i < 64; i++ )
643 					rOut << (sal_uInt16) *( pArray + i );
644 
645 				rOut << aXOBitmap.GetPixelColor();
646 				rOut << aXOBitmap.GetBackgroundColor();
647 			}
648 		}
649 	}
650 
651 	return rOut;
652 }
653 
654 /*************************************************************************
655 |*
656 |*    const Bitmap& XFillBitmapItem::GetValue(const XBitmapTable* pTable) const
657 |*
658 |*    Beschreibung
659 |*    Ersterstellung    15.11.94
660 |*    Letzte Aenderung  26.07.94
661 |*
662 *************************************************************************/
663 
664 const XOBitmap& XFillBitmapItem::GetBitmapValue(const XBitmapTable* pTable) const // GetValue -> GetBitmapValue
665 {
666 	if (!IsIndex())
667 		return aXOBitmap;
668 	else
669 		return pTable->GetBitmap(GetIndex())->GetXBitmap();
670 }
671 
672 
673 /*************************************************************************
674 |*
675 |*    sal_uInt16 XFillBitmapItem::GetVersion() const
676 |*
677 |*    Beschreibung
678 |*    Ersterstellung    26.07.95
679 |*    Letzte Aenderung  26.07.95
680 |*
681 *************************************************************************/
682 
683 sal_uInt16 XFillBitmapItem::GetVersion( sal_uInt16 /*nFileFormatVersion*/) const
684 {
685 	// 2. Version
686 	return( 1 );
687 }
688 
689 //------------------------------------------------------------------------
690 
691 SfxItemPresentation XFillBitmapItem::GetPresentation
692 (
693 	SfxItemPresentation ePres,
694 	SfxMapUnit          /*eCoreUnit*/,
695 	SfxMapUnit          /*ePresUnit*/,
696     XubString&           rText, const IntlWrapper *
697 )   const
698 {
699 	switch ( ePres )
700 	{
701 		case SFX_ITEM_PRESENTATION_NONE:
702 			rText.Erase();
703 			return ePres;
704 		case SFX_ITEM_PRESENTATION_NAMELESS:
705 		case SFX_ITEM_PRESENTATION_COMPLETE:
706 			rText += GetName();
707 			return ePres;
708 		default:
709 			return SFX_ITEM_PRESENTATION_NONE;
710 	}
711 }
712 
713 //------------------------------------------------------------------------
714 
715 sal_Bool XFillBitmapItem::QueryValue( ::com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const
716 {
717 //    sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
718     nMemberId &= ~CONVERT_TWIPS;
719 
720     // needed for MID_NAME
721     ::rtl::OUString aApiName;
722     // needed for complete item (MID 0)
723     ::rtl::OUString aInternalName;
724 
725     ::rtl::OUString aURL;
726     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap > xBmp;
727 
728 	if( nMemberId == MID_NAME )
729 	{
730  		SvxUnogetApiNameForItem( Which(), GetName(), aApiName );
731 	}
732     else if( nMemberId == 0  )
733     {
734         aInternalName = GetName();
735     }
736 
737     if( nMemberId == MID_GRAFURL ||
738         nMemberId == 0 )
739 	{
740 		XOBitmap aLocalXOBitmap( GetBitmapValue() );
741 		aURL = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_GRAPHOBJ_URLPREFIX));
742 		aURL += ::rtl::OUString::createFromAscii( aLocalXOBitmap.GetGraphicObject().GetUniqueID().GetBuffer() );
743 	}
744     if( nMemberId == MID_BITMAP ||
745         nMemberId == 0  )
746 	{
747 		XOBitmap aLocalXOBitmap( GetBitmapValue() );
748 		Bitmap aBmp( aLocalXOBitmap.GetBitmap() );
749 		BitmapEx aBmpEx( aBmp );
750 
751 		xBmp.set( VCLUnoHelper::CreateBitmap( aBmpEx ) );
752 	}
753 
754     if( nMemberId == MID_NAME )
755 		rVal <<= aApiName;
756 	else if( nMemberId == MID_GRAFURL )
757 		rVal <<= aURL;
758 	else if( nMemberId == MID_BITMAP )
759 		rVal <<= xBmp;
760     else
761     {
762         // member-id 0 => complete item (e.g. for toolbars)
763         DBG_ASSERT( nMemberId == 0, "invalid member-id" );
764         uno::Sequence< beans::PropertyValue > aPropSeq( 3 );
765 
766         aPropSeq[0].Name  = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ));
767         aPropSeq[0].Value = uno::makeAny( aInternalName );
768         aPropSeq[1].Name  = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FillBitmapURL" ));
769         aPropSeq[1].Value = uno::makeAny( aURL );
770         aPropSeq[2].Name  = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Bitmap" ));
771         aPropSeq[2].Value = uno::makeAny( xBmp );
772 
773         rVal <<= aPropSeq;
774     }
775 
776 	return sal_True;
777 }
778 
779 //------------------------------------------------------------------------
780 
781 sal_Bool XFillBitmapItem::PutValue( const ::com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
782 {
783 //    sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
784     nMemberId &= ~CONVERT_TWIPS;
785 
786     ::rtl::OUString aName;
787     ::rtl::OUString aURL;
788     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap > xBmp;
789     ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > xGraphic;
790 
791     bool bSetName   = false;
792     bool bSetURL    = false;
793     bool bSetBitmap = false;
794 
795     if( nMemberId == MID_NAME )
796 		bSetName = (rVal >>= aName);
797     else if( nMemberId == MID_GRAFURL )
798 		bSetURL = (rVal >>= aURL);
799 	else if( nMemberId == MID_BITMAP )
800 	{
801         bSetBitmap = (rVal >>= xBmp);
802 		if ( !bSetBitmap )
803 			bSetBitmap = (rVal >>= xGraphic );
804 	}
805     else
806     {
807         DBG_ASSERT( nMemberId == 0, "invalid member-id" );
808         uno::Sequence< beans::PropertyValue >   aPropSeq;
809         if( rVal >>= aPropSeq )
810         {
811             for ( sal_Int32 n = 0; n < aPropSeq.getLength(); n++ )
812             {
813                 if( aPropSeq[n].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Name" )))
814                     bSetName = (aPropSeq[n].Value >>= aName);
815                 else if( aPropSeq[n].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "FillBitmapURL" )))
816                     bSetURL = (aPropSeq[n].Value >>= aURL);
817                 else if( aPropSeq[n].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Bitmap" )))
818                     bSetBitmap = (aPropSeq[n].Value >>= xBmp);
819             }
820         }
821     }
822 
823     if( bSetName )
824     {
825         SetName( aName );
826     }
827     if( bSetURL )
828     {
829         GraphicObject aGrafObj( GraphicObject::CreateGraphicObjectFromURL( aURL ) );
830         XOBitmap aBMP( aGrafObj );
831         SetBitmapValue( aBMP );
832     }
833     if( bSetBitmap )
834     {
835 		Bitmap aInput;
836 		if ( xBmp.is() )
837 		{
838 	        BitmapEx aInputEx( VCLUnoHelper::GetBitmap( xBmp ) );
839 		    aInput = aInputEx.GetBitmap();
840 		}
841 		else if ( xGraphic.is() )
842 		{
843 			Graphic aGraphic( xGraphic );
844 		    aInput = aGraphic.GetBitmap();
845 		}
846 
847         // note: aXOBitmap is the member bitmap
848         aXOBitmap.SetBitmap( aInput );
849         aXOBitmap.SetBitmapType(XBITMAP_IMPORT);
850 
851         if(aInput.GetSizePixel().Width() == 8
852            && aInput.GetSizePixel().Height() == 8
853            && aInput.GetColorCount() == 2)
854         {
855             aXOBitmap.Bitmap2Array();
856             aXOBitmap.SetBitmapType(XBITMAP_8X8);
857             aXOBitmap.SetPixelSize(aInput.GetSizePixel());
858         }
859     }
860 
861 	return (bSetName || bSetURL || bSetBitmap);
862 }
863 
864 sal_Bool XFillBitmapItem::CompareValueFunc( const NameOrIndex* p1, const NameOrIndex* p2 )
865 {
866 	return ((XFillBitmapItem*)p1)->GetBitmapValue().GetGraphicObject().GetUniqueID() ==
867 		   ((XFillBitmapItem*)p2)->GetBitmapValue().GetGraphicObject().GetUniqueID();
868 }
869 
870 XFillBitmapItem* XFillBitmapItem::checkForUniqueItem( SdrModel* pModel ) const
871 {
872 	if( pModel )
873 	{
874 		const String aUniqueName = NameOrIndex::CheckNamedItem(	this,
875 																XATTR_FILLBITMAP,
876 																&pModel->GetItemPool(),
877 																pModel->GetStyleSheetPool() ? &pModel->GetStyleSheetPool()->GetPool() : NULL,
878 																XFillBitmapItem::CompareValueFunc,
879 																RID_SVXSTR_BMP21,
880 																pModel->GetBitmapList() );
881 
882 		// if the given name is not valid, replace it!
883 		if( aUniqueName != GetName() )
884 		{
885 			return new XFillBitmapItem( aUniqueName, aXOBitmap );
886 		}
887 	}
888 
889 	return (XFillBitmapItem*)this;
890 }
891