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