fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svtools / source / misc / imap.cxx
blob597d90a34a3bd2271cfb7bc12c622a8c75ca700b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <tools/urlobj.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/mapmod.hxx>
24 #include <vcl/window.hxx>
26 #include "svl/urihelper.hxx"
27 #include <svtools/imap.hxx>
28 #include <svtools/imapobj.hxx>
29 #include <svtools/imapcirc.hxx>
30 #include <svtools/imaprect.hxx>
31 #include <svtools/imappoly.hxx>
33 #include <string.h>
34 #include <math.h>
36 DBG_NAME( ImageMap )
39 #define SCALEPOINT(aPT,aFracX,aFracY) (aPT).X()=((aPT).X()*(aFracX).GetNumerator())/(aFracX).GetDenominator(); \
40 (aPT).Y()=((aPT).Y()*(aFracY).GetNumerator())/(aFracY).GetDenominator();
43 /******************************************************************************/
45 sal_uInt16 IMapObject::nActualTextEncoding = (sal_uInt16) RTL_TEXTENCODING_DONTKNOW;
47 /******************************************************************************/
50 IMapObject::IMapObject()
51 : bActive( false )
52 , nReadVersion( 0 )
56 IMapObject::IMapObject( const String& rURL, const String& rAltText, const String& rDesc,
57 const String& rTarget, const String& rName, sal_Bool bURLActive )
58 : aURL( rURL )
59 , aAltText( rAltText )
60 , aDesc( rDesc )
61 , aTarget( rTarget )
62 , aName( rName )
63 , bActive( bURLActive )
64 , nReadVersion( 0 )
69 /******************************************************************************
71 |* Freigabe des internen Speichers
73 \******************************************************************************/
75 sal_uInt16 IMapObject::GetVersion() const
77 return IMAP_OBJ_VERSION;
80 void IMapObject::Write( SvStream& rOStm, const String& rBaseURL ) const
82 IMapCompat* pCompat;
83 const rtl_TextEncoding eEncoding = osl_getThreadTextEncoding();
85 rOStm << GetType();
86 rOStm << GetVersion();
87 rOStm << ( (sal_uInt16) eEncoding );
89 const OString aRelURL = OUStringToOString(
90 URIHelper::simpleNormalizedMakeRelative(rBaseURL, aURL), eEncoding);
91 write_lenPrefixed_uInt8s_FromOString<sal_uInt16>(rOStm, aRelURL);
92 write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOStm, aAltText, eEncoding);
93 rOStm << bActive;
94 write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOStm, aTarget, eEncoding);
96 pCompat = new IMapCompat( rOStm, STREAM_WRITE );
98 WriteIMapObject( rOStm );
99 aEventList.Write( rOStm ); // V4
100 write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOStm, aName, eEncoding); // V5
102 delete pCompat;
106 /******************************************************************************
108 |* Binaer-Import
110 \******************************************************************************/
112 void IMapObject::Read( SvStream& rIStm, const String& rBaseURL )
114 IMapCompat* pCompat;
115 rtl_TextEncoding nTextEncoding;
117 // Typ und Version ueberlesen wir
118 rIStm.SeekRel( 2 );
119 rIStm >> nReadVersion;
120 rIStm >> nTextEncoding;
121 aURL = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rIStm, nTextEncoding);
122 aAltText = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rIStm, nTextEncoding);
123 rIStm >> bActive;
124 aTarget = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rIStm, nTextEncoding);
126 // URL absolut machen
127 aURL = URIHelper::SmartRel2Abs( INetURLObject(rBaseURL), aURL, URIHelper::GetMaybeFileHdl(), true, false, INetURLObject::WAS_ENCODED, INetURLObject::DECODE_UNAMBIGUOUS );
128 pCompat = new IMapCompat( rIStm, STREAM_READ );
130 ReadIMapObject( rIStm );
132 // ab Version 4 lesen wir eine EventListe
133 if ( nReadVersion >= 0x0004 )
135 aEventList.Read(rIStm);
137 // ab Version 5 kann ein Objektname vorhanden sein
138 if ( nReadVersion >= 0x0005 )
139 aName = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rIStm, nTextEncoding);
142 delete pCompat;
145 sal_Bool IMapObject::IsEqual( const IMapObject& rEqObj )
147 return ( ( aURL == rEqObj.aURL ) &&
148 ( aAltText == rEqObj.aAltText ) &&
149 ( aDesc == rEqObj.aDesc ) &&
150 ( aTarget == rEqObj.aTarget ) &&
151 ( aName == rEqObj.aName ) &&
152 ( bActive == rEqObj.bActive ) );
155 IMapRectangleObject::IMapRectangleObject( const Rectangle& rRect,
156 const String& rURL,
157 const String& rAltText,
158 const String& rDesc,
159 const String& rTarget,
160 const String& rName,
161 sal_Bool bURLActive,
162 sal_Bool bPixelCoords ) :
163 IMapObject ( rURL, rAltText, rDesc, rTarget, rName, bURLActive )
165 ImpConstruct( rRect, bPixelCoords );
168 void IMapRectangleObject::ImpConstruct( const Rectangle& rRect, sal_Bool bPixel )
170 if ( bPixel )
171 aRect = Application::GetDefaultDevice()->PixelToLogic( rRect, MapMode( MAP_100TH_MM ) );
172 else
173 aRect = rRect;
177 /******************************************************************************
179 |* Binaer-Export
181 \******************************************************************************/
183 void IMapRectangleObject::WriteIMapObject( SvStream& rOStm ) const
185 rOStm << aRect;
189 /******************************************************************************
191 |* Binaer-Import
193 \******************************************************************************/
195 void IMapRectangleObject::ReadIMapObject( SvStream& rIStm )
197 rIStm >> aRect;
201 /******************************************************************************
203 |* Typ-Rueckgabe
205 \******************************************************************************/
207 sal_uInt16 IMapRectangleObject::GetType() const
209 return IMAP_OBJ_RECTANGLE;
213 /******************************************************************************
215 |* Hit-Test
217 \******************************************************************************/
219 sal_Bool IMapRectangleObject::IsHit( const Point& rPoint ) const
221 return aRect.IsInside( rPoint );
224 Rectangle IMapRectangleObject::GetRectangle( sal_Bool bPixelCoords ) const
226 Rectangle aNewRect;
228 if ( bPixelCoords )
229 aNewRect = Application::GetDefaultDevice()->LogicToPixel( aRect, MapMode( MAP_100TH_MM ) );
230 else
231 aNewRect = aRect;
233 return aNewRect;
236 void IMapRectangleObject::Scale( const Fraction& rFracX, const Fraction& rFracY )
238 Point aTL( aRect.TopLeft() );
239 Point aBR( aRect.BottomRight() );
241 if ( rFracX.GetDenominator() && rFracY.GetDenominator() )
243 SCALEPOINT( aTL, rFracX, rFracY );
244 SCALEPOINT( aBR, rFracX, rFracY );
247 aRect = Rectangle( aTL, aBR );
250 sal_Bool IMapRectangleObject::IsEqual( const IMapRectangleObject& rEqObj )
252 return ( IMapObject::IsEqual( rEqObj ) && ( aRect == rEqObj.aRect ) );
255 IMapCircleObject::IMapCircleObject( const Point& rCenter, sal_uLong nCircleRadius,
256 const String& rURL,
257 const String& rAltText,
258 const String& rDesc,
259 const String& rTarget,
260 const String& rName,
261 sal_Bool bURLActive,
262 sal_Bool bPixelCoords ) :
263 IMapObject ( rURL, rAltText, rDesc, rTarget, rName, bURLActive )
265 ImpConstruct( rCenter, nCircleRadius, bPixelCoords );
268 void IMapCircleObject::ImpConstruct( const Point& rCenter, sal_uLong nRad, sal_Bool bPixel )
270 if ( bPixel )
272 MapMode aMap100( MAP_100TH_MM );
274 aCenter = Application::GetDefaultDevice()->PixelToLogic( rCenter, aMap100 );
275 nRadius = Application::GetDefaultDevice()->PixelToLogic( Size( nRad, 0 ), aMap100 ).Width();
277 else
279 aCenter = rCenter;
280 nRadius = nRad;
285 /******************************************************************************
287 |* Binaer-Export
289 \******************************************************************************/
291 void IMapCircleObject::WriteIMapObject( SvStream& rOStm ) const
293 sal_uInt32 nTmp = nRadius;
295 rOStm << aCenter;
296 rOStm << nTmp;
300 /******************************************************************************
302 |* Binaer-Import
304 \******************************************************************************/
306 void IMapCircleObject::ReadIMapObject( SvStream& rIStm )
308 sal_uInt32 nTmp;
310 rIStm >> aCenter;
311 rIStm >> nTmp;
313 nRadius = nTmp;
317 /******************************************************************************
319 |* Typ-Rueckgabe
321 \******************************************************************************/
323 sal_uInt16 IMapCircleObject::GetType() const
325 return IMAP_OBJ_CIRCLE;
329 /******************************************************************************
331 |* Hit-Test
333 \******************************************************************************/
335 sal_Bool IMapCircleObject::IsHit( const Point& rPoint ) const
337 const Point aPoint( aCenter - rPoint );
338 sal_Bool bRet = sal_False;
340 if ( (sal_Int32) sqrt( (double) aPoint.X() * aPoint.X() +
341 aPoint.Y() * aPoint.Y() ) <= nRadius )
343 bRet = sal_True;
346 return bRet;
349 Point IMapCircleObject::GetCenter( sal_Bool bPixelCoords ) const
351 Point aNewPoint;
353 if ( bPixelCoords )
354 aNewPoint = Application::GetDefaultDevice()->LogicToPixel( aCenter, MapMode( MAP_100TH_MM ) );
355 else
356 aNewPoint = aCenter;
358 return aNewPoint;
361 sal_uLong IMapCircleObject::GetRadius( sal_Bool bPixelCoords ) const
363 sal_uLong nNewRadius;
365 if ( bPixelCoords )
366 nNewRadius = Application::GetDefaultDevice()->LogicToPixel( Size( nRadius, 0 ), MapMode( MAP_100TH_MM ) ).Width();
367 else
368 nNewRadius = nRadius;
370 return nNewRadius;
373 Rectangle IMapCircleObject::GetBoundRect() const
375 long nWidth = nRadius << 1;
377 return Rectangle( Point( aCenter.X() - nRadius, aCenter.Y() - nRadius ),
378 Size( nWidth, nWidth ) );
381 void IMapCircleObject::Scale( const Fraction& rFracX, const Fraction& rFracY )
383 Fraction aAverage( rFracX );
385 aAverage += rFracY;
386 aAverage *= Fraction( 1, 2 );
388 if ( rFracX.GetDenominator() && rFracY.GetDenominator() )
390 SCALEPOINT( aCenter, rFracX, rFracY );
393 nRadius = ( nRadius * aAverage.GetNumerator() ) / aAverage.GetDenominator();
396 sal_Bool IMapCircleObject::IsEqual( const IMapCircleObject& rEqObj )
398 return ( IMapObject::IsEqual( rEqObj ) &&
399 ( aCenter == rEqObj.aCenter ) &&
400 ( nRadius == rEqObj.nRadius ) );
403 IMapPolygonObject::IMapPolygonObject( const Polygon& rPoly,
404 const String& rURL,
405 const String& rAltText,
406 const String& rDesc,
407 const String& rTarget,
408 const String& rName,
409 sal_Bool bURLActive,
410 sal_Bool bPixelCoords ) :
411 IMapObject ( rURL, rAltText, rDesc, rTarget, rName, bURLActive ),
412 bEllipse ( sal_False )
414 ImpConstruct( rPoly, bPixelCoords );
417 void IMapPolygonObject::ImpConstruct( const Polygon& rPoly, sal_Bool bPixel )
419 if ( bPixel )
420 aPoly = Application::GetDefaultDevice()->PixelToLogic( rPoly, MapMode( MAP_100TH_MM ) );
421 else
422 aPoly = rPoly;
426 /******************************************************************************
428 |* Binaer-Export
430 \******************************************************************************/
432 void IMapPolygonObject::WriteIMapObject( SvStream& rOStm ) const
434 rOStm << aPoly;
435 rOStm << bEllipse; // >= Version 2
436 rOStm << aEllipse; // >= Version 2
440 /******************************************************************************
442 |* Binaer-Import
444 \******************************************************************************/
446 void IMapPolygonObject::ReadIMapObject( SvStream& rIStm )
448 rIStm >> aPoly;
450 // Version >= 2 hat zusaetzlich Ellipsen-Information
451 if ( nReadVersion >= 2 )
453 rIStm >> bEllipse;
454 rIStm >> aEllipse;
459 /******************************************************************************
461 |* Typ-Rueckgabe
463 \******************************************************************************/
465 sal_uInt16 IMapPolygonObject::GetType() const
467 return IMAP_OBJ_POLYGON;
471 /******************************************************************************
473 |* Hit-Test
475 \******************************************************************************/
477 sal_Bool IMapPolygonObject::IsHit( const Point& rPoint ) const
479 return aPoly.IsInside( rPoint );
482 Polygon IMapPolygonObject::GetPolygon( sal_Bool bPixelCoords ) const
484 Polygon aNewPoly;
486 if ( bPixelCoords )
487 aNewPoly = Application::GetDefaultDevice()->LogicToPixel( aPoly, MapMode( MAP_100TH_MM ) );
488 else
489 aNewPoly = aPoly;
491 return aNewPoly;
494 void IMapPolygonObject::SetExtraEllipse( const Rectangle& rEllipse )
496 if ( aPoly.GetSize() )
498 bEllipse = sal_True;
499 aEllipse = rEllipse;
503 void IMapPolygonObject::Scale( const Fraction& rFracX, const Fraction& rFracY )
505 sal_uInt16 nCount = aPoly.GetSize();
507 for ( sal_uInt16 i = 0; i < nCount; i++ )
509 Point aScaledPt( aPoly[ i ] );
511 if ( rFracX.GetDenominator() && rFracY.GetDenominator() )
513 SCALEPOINT( aScaledPt, rFracX, rFracY );
516 aPoly[ i ] = aScaledPt;
519 if ( bEllipse )
521 Point aTL( aEllipse.TopLeft() );
522 Point aBR( aEllipse.BottomRight() );
524 if ( rFracX.GetDenominator() && rFracY.GetDenominator() )
526 SCALEPOINT( aTL, rFracX, rFracY );
527 SCALEPOINT( aBR, rFracX, rFracY );
530 aEllipse = Rectangle( aTL, aBR );
534 sal_Bool IMapPolygonObject::IsEqual( const IMapPolygonObject& rEqObj )
536 sal_Bool bRet = sal_False;
538 if ( IMapObject::IsEqual( rEqObj ) )
540 const Polygon& rEqPoly = rEqObj.aPoly;
541 const sal_uInt16 nCount = aPoly.GetSize();
542 const sal_uInt16 nEqCount = rEqPoly.GetSize();
543 sal_Bool bDifferent = sal_False;
545 if ( nCount == nEqCount )
547 for ( sal_uInt16 i = 0; i < nCount; i++ )
549 if ( aPoly[ i ] != rEqPoly[ i ] )
551 bDifferent = sal_True;
552 break;
556 if ( !bDifferent )
557 bRet = sal_True;
561 return bRet;
564 /******************************************************************************
566 |* Ctor
568 \******************************************************************************/
570 ImageMap::ImageMap( const String& rName )
571 : aName( rName )
576 /******************************************************************************
578 |* Copy-Ctor
580 \******************************************************************************/
582 ImageMap::ImageMap( const ImageMap& rImageMap )
584 DBG_CTOR( ImageMap, NULL );
586 size_t nCount = rImageMap.GetIMapObjectCount();
588 for ( size_t i = 0; i < nCount; i++ )
590 IMapObject* pCopyObj = rImageMap.GetIMapObject( i );
592 switch( pCopyObj->GetType() )
594 case( IMAP_OBJ_RECTANGLE ):
595 maList.push_back( new IMapRectangleObject( *(IMapRectangleObject*) pCopyObj ) );
596 break;
598 case( IMAP_OBJ_CIRCLE ):
599 maList.push_back( new IMapCircleObject( *(IMapCircleObject*) pCopyObj ) );
600 break;
602 case( IMAP_OBJ_POLYGON ):
603 maList.push_back( new IMapPolygonObject( *(IMapPolygonObject*) pCopyObj ) );
604 break;
606 default:
607 break;
611 aName = rImageMap.aName;
615 /******************************************************************************
617 |* Dtor
619 \******************************************************************************/
621 ImageMap::~ImageMap()
623 DBG_DTOR( ImageMap, NULL );
625 ClearImageMap();
629 /******************************************************************************
631 |* Freigabe des internen Speichers
633 \******************************************************************************/
635 void ImageMap::ClearImageMap()
637 for( size_t i = 0, n = maList.size(); i < n; ++i )
638 delete maList[ i ];
639 maList.clear();
641 aName = String();
645 /******************************************************************************
647 |* Zuweisungsoperator
649 \******************************************************************************/
651 ImageMap& ImageMap::operator=( const ImageMap& rImageMap )
653 size_t nCount = rImageMap.GetIMapObjectCount();
655 ClearImageMap();
657 for ( size_t i = 0; i < nCount; i++ )
659 IMapObject* pCopyObj = rImageMap.GetIMapObject( i );
661 switch( pCopyObj->GetType() )
663 case( IMAP_OBJ_RECTANGLE ):
664 maList.push_back( new IMapRectangleObject( *(IMapRectangleObject*) pCopyObj ) );
665 break;
667 case( IMAP_OBJ_CIRCLE ):
668 maList.push_back( new IMapCircleObject( *(IMapCircleObject*) pCopyObj ) );
669 break;
671 case( IMAP_OBJ_POLYGON ):
672 maList.push_back( new IMapPolygonObject( *(IMapPolygonObject*) pCopyObj ) );
673 break;
675 default:
676 break;
680 aName = rImageMap.aName;
682 return *this;
686 /******************************************************************************
688 |* Vergleichsoperator I
690 \******************************************************************************/
692 sal_Bool ImageMap::operator==( const ImageMap& rImageMap )
694 const size_t nCount = maList.size();
695 const size_t nEqCount = rImageMap.GetIMapObjectCount();
696 sal_Bool bRet = sal_False;
698 if ( nCount == nEqCount )
700 sal_Bool bDifferent = ( aName != rImageMap.aName );
702 for ( size_t i = 0; ( i < nCount ) && !bDifferent; i++ )
704 IMapObject* pObj = maList[ i ];
705 IMapObject* pEqObj = rImageMap.GetIMapObject( i );
707 if ( pObj->GetType() == pEqObj->GetType() )
709 switch( pObj->GetType() )
711 case( IMAP_OBJ_RECTANGLE ):
713 if ( !( (IMapRectangleObject*) pObj )->IsEqual( *(IMapRectangleObject*) pEqObj ) )
714 bDifferent = sal_True;
716 break;
718 case( IMAP_OBJ_CIRCLE ):
720 if ( !( (IMapCircleObject*) pObj )->IsEqual( *(IMapCircleObject*) pEqObj ) )
721 bDifferent = sal_True;
723 break;
725 case( IMAP_OBJ_POLYGON ):
727 if ( !( (IMapPolygonObject*) pObj )->IsEqual( *(IMapPolygonObject*) pEqObj ) )
728 bDifferent = sal_True;
730 break;
732 default:
733 break;
736 else
737 bDifferent = sal_True;
740 if ( !bDifferent )
741 bRet = sal_True;
744 return bRet;
748 /******************************************************************************
750 |* Vergleichsoperator II
752 \******************************************************************************/
754 sal_Bool ImageMap::operator!=( const ImageMap& rImageMap )
756 return !( *this == rImageMap );
760 /******************************************************************************
762 |* Freigabe des internen Speichers
764 \******************************************************************************/
766 sal_uInt16 ImageMap::GetVersion() const
768 return IMAGE_MAP_VERSION;
772 /******************************************************************************
774 |* Einfuegen eines neuen Objekts
776 \******************************************************************************/
778 void ImageMap::InsertIMapObject( const IMapObject& rIMapObject )
780 switch( rIMapObject.GetType() )
782 case( IMAP_OBJ_RECTANGLE ):
783 maList.push_back( new IMapRectangleObject( (IMapRectangleObject&) rIMapObject ) );
784 break;
786 case( IMAP_OBJ_CIRCLE ):
787 maList.push_back( new IMapCircleObject( (IMapCircleObject&) rIMapObject ) );
788 break;
790 case( IMAP_OBJ_POLYGON ):
791 maList.push_back( new IMapPolygonObject( (IMapPolygonObject&) rIMapObject ) );
792 break;
794 default:
795 break;
800 /******************************************************************************
802 |* Hit-Test
804 \******************************************************************************/
806 IMapObject* ImageMap::GetHitIMapObject( const Size& rTotalSize,
807 const Size& rDisplaySize,
808 const Point& rRelHitPoint,
809 sal_uLong nFlags )
811 Point aRelPoint( rTotalSize.Width() * rRelHitPoint.X() / rDisplaySize.Width(),
812 rTotalSize.Height() * rRelHitPoint.Y() / rDisplaySize.Height() );
814 // Falls Flags zur Spiegelung etc. angegeben sind, wird
815 // der zu pruefende Punkt vor der Pruefung entspr. transformiert
816 if ( nFlags )
818 if ( nFlags & IMAP_MIRROR_HORZ )
819 aRelPoint.X() = rTotalSize.Width() - aRelPoint.X();
821 if ( nFlags & IMAP_MIRROR_VERT )
822 aRelPoint.Y() = rTotalSize.Height() - aRelPoint.Y();
825 // Alle Objekte durchlaufen und HitTest ausfuehren
826 IMapObject* pObj = NULL;
827 for( size_t i = 0, n = maList.size(); i < n; ++i ) {
828 if ( maList[ i ]->IsHit( aRelPoint ) ) {
829 pObj = maList[ i ];
830 break;
834 return( pObj ? ( pObj->IsActive() ? pObj : NULL ) : NULL );
837 void ImageMap::Scale( const Fraction& rFracX, const Fraction& rFracY )
839 size_t nCount = maList.size();
841 for ( size_t i = 0; i < nCount; i++ )
843 IMapObject* pObj = maList[ i ];
845 switch( pObj->GetType() )
847 case( IMAP_OBJ_RECTANGLE ):
848 ( (IMapRectangleObject*) pObj )->Scale( rFracX, rFracY );
849 break;
851 case( IMAP_OBJ_CIRCLE ):
852 ( (IMapCircleObject*) pObj )->Scale( rFracX, rFracY );
853 break;
855 case( IMAP_OBJ_POLYGON ):
856 ( (IMapPolygonObject*) pObj )->Scale( rFracX, rFracY );
857 break;
859 default:
860 break;
866 /******************************************************************************
868 |* Objekte nacheinander wegschreiben
870 \******************************************************************************/
872 void ImageMap::ImpWriteImageMap( SvStream& rOStm, const String& rBaseURL ) const
874 IMapObject* pObj;
875 size_t nCount = maList.size();
877 for ( size_t i = 0; i < nCount; i++ )
879 pObj = maList[ i ];
880 pObj->Write( rOStm, rBaseURL );
885 /******************************************************************************
887 |* Objekte nacheinander lesen
889 \******************************************************************************/
891 void ImageMap::ImpReadImageMap( SvStream& rIStm, size_t nCount, const String& rBaseURL )
893 // neue Objekte einlesen
894 for ( size_t i = 0; i < nCount; i++ )
896 sal_uInt16 nType;
898 rIStm >> nType;
899 rIStm.SeekRel( -2 );
901 switch( nType )
903 case ( IMAP_OBJ_RECTANGLE ):
905 IMapRectangleObject* pObj = new IMapRectangleObject;
906 pObj->Read( rIStm, rBaseURL );
907 maList.push_back( pObj );
909 break;
911 case ( IMAP_OBJ_CIRCLE ):
913 IMapCircleObject* pObj = new IMapCircleObject;
914 pObj->Read( rIStm, rBaseURL );
915 maList.push_back( pObj );
917 break;
919 case ( IMAP_OBJ_POLYGON ):
921 IMapPolygonObject* pObj = new IMapPolygonObject;
922 pObj->Read( rIStm, rBaseURL );
923 maList.push_back( pObj );
925 break;
927 default:
928 break;
934 /******************************************************************************
936 |* Binaer speichern
938 \******************************************************************************/
940 void ImageMap::Write( SvStream& rOStm, const String& rBaseURL ) const
942 IMapCompat* pCompat;
943 String aImageName( GetName() );
944 sal_uInt16 nOldFormat = rOStm.GetNumberFormatInt();
945 sal_uInt16 nCount = (sal_uInt16) GetIMapObjectCount();
946 const rtl_TextEncoding eEncoding = osl_getThreadTextEncoding(); //vomit!
948 rOStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
950 // MagicCode schreiben
951 rOStm << IMAPMAGIC;
952 rOStm << GetVersion();
953 write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOStm, aImageName, eEncoding);
954 write_lenPrefixed_uInt8s_FromOString<sal_uInt16>(rOStm, OString()); //dummy
955 rOStm << nCount;
956 write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOStm, aImageName, eEncoding);
958 pCompat = new IMapCompat( rOStm, STREAM_WRITE );
960 // hier kann in neueren Versionen eingefuegt werden
962 delete pCompat;
964 ImpWriteImageMap( rOStm, rBaseURL );
966 rOStm.SetNumberFormatInt( nOldFormat );
970 /******************************************************************************
972 |* Binaer laden
974 \******************************************************************************/
976 void ImageMap::Read( SvStream& rIStm, const String& rBaseURL )
978 char cMagic[6];
979 sal_uInt16 nOldFormat = rIStm.GetNumberFormatInt();
980 sal_uInt16 nCount;
982 rIStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
983 rIStm.Read( cMagic, sizeof( cMagic ) );
985 if ( !memcmp( cMagic, IMAPMAGIC, sizeof( cMagic ) ) )
987 IMapCompat* pCompat;
989 // alten Inhalt loeschen
990 ClearImageMap();
992 // Version ueberlesen wir
993 rIStm.SeekRel( 2 );
995 aName = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rIStm, osl_getThreadTextEncoding());
996 read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(rIStm); // Dummy
997 rIStm >> nCount;
998 read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(rIStm); // Dummy
1000 pCompat = new IMapCompat( rIStm, STREAM_READ );
1002 // hier kann in neueren Versionen gelesen werden
1004 delete pCompat;
1005 ImpReadImageMap( rIStm, nCount, rBaseURL );
1008 else
1009 rIStm.SetError( SVSTREAM_GENERALERROR );
1011 rIStm.SetNumberFormatInt( nOldFormat );
1015 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */