1*5900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*5900e8ecSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*5900e8ecSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*5900e8ecSAndrew Rist * distributed with this work for additional information
6*5900e8ecSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*5900e8ecSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*5900e8ecSAndrew Rist * "License"); you may not use this file except in compliance
9*5900e8ecSAndrew Rist * with the License. You may obtain a copy of the License at
10*5900e8ecSAndrew Rist *
11*5900e8ecSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*5900e8ecSAndrew Rist *
13*5900e8ecSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*5900e8ecSAndrew Rist * software distributed under the License is distributed on an
15*5900e8ecSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5900e8ecSAndrew Rist * KIND, either express or implied. See the License for the
17*5900e8ecSAndrew Rist * specific language governing permissions and limitations
18*5900e8ecSAndrew Rist * under the License.
19*5900e8ecSAndrew Rist *
20*5900e8ecSAndrew Rist *************************************************************/
21*5900e8ecSAndrew Rist
22*5900e8ecSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <tools/urlobj.hxx>
28cdf0e10cSrcweir #include <vcl/svapp.hxx>
29cdf0e10cSrcweir #include <vcl/mapmod.hxx>
30cdf0e10cSrcweir #include <vcl/window.hxx>
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include "svl/urihelper.hxx"
33cdf0e10cSrcweir #include <svtools/imap.hxx>
34cdf0e10cSrcweir #include <svtools/imapobj.hxx>
35cdf0e10cSrcweir #include <svtools/imapcirc.hxx>
36cdf0e10cSrcweir #include <svtools/imaprect.hxx>
37cdf0e10cSrcweir #include <svtools/imappoly.hxx>
38cdf0e10cSrcweir
39cdf0e10cSrcweir #include <string.h>
40cdf0e10cSrcweir #include <math.h>
41cdf0e10cSrcweir
42cdf0e10cSrcweir DBG_NAME( ImageMap )
43cdf0e10cSrcweir
44cdf0e10cSrcweir
45cdf0e10cSrcweir #define SCALEPOINT(aPT,aFracX,aFracY) (aPT).X()=((aPT).X()*(aFracX).GetNumerator())/(aFracX).GetDenominator(); \
46cdf0e10cSrcweir (aPT).Y()=((aPT).Y()*(aFracY).GetNumerator())/(aFracY).GetDenominator();
47cdf0e10cSrcweir
48cdf0e10cSrcweir
49cdf0e10cSrcweir /******************************************************************************/
50cdf0e10cSrcweir
51cdf0e10cSrcweir sal_uInt16 IMapObject::nActualTextEncoding = (sal_uInt16) RTL_TEXTENCODING_DONTKNOW;
52cdf0e10cSrcweir
53cdf0e10cSrcweir /******************************************************************************/
54cdf0e10cSrcweir
55cdf0e10cSrcweir
IMapObject()56cdf0e10cSrcweir IMapObject::IMapObject()
57cdf0e10cSrcweir : bActive( false )
58cdf0e10cSrcweir , nReadVersion( 0 )
59cdf0e10cSrcweir {
60cdf0e10cSrcweir }
61cdf0e10cSrcweir
IMapObject(const String & rURL,const String & rAltText,const String & rDesc,const String & rTarget,const String & rName,sal_Bool bURLActive)62cdf0e10cSrcweir IMapObject::IMapObject( const String& rURL, const String& rAltText, const String& rDesc,
63cdf0e10cSrcweir const String& rTarget, const String& rName, sal_Bool bURLActive )
64cdf0e10cSrcweir : aURL( rURL )
65cdf0e10cSrcweir , aAltText( rAltText )
66cdf0e10cSrcweir , aDesc( rDesc )
67cdf0e10cSrcweir , aTarget( rTarget )
68cdf0e10cSrcweir , aName( rName )
69cdf0e10cSrcweir , bActive( bURLActive )
70cdf0e10cSrcweir , nReadVersion( 0 )
71cdf0e10cSrcweir {
72cdf0e10cSrcweir }
73cdf0e10cSrcweir
74cdf0e10cSrcweir
75cdf0e10cSrcweir /******************************************************************************
76cdf0e10cSrcweir |*
77cdf0e10cSrcweir |* Freigabe des internen Speichers
78cdf0e10cSrcweir |*
79cdf0e10cSrcweir \******************************************************************************/
80cdf0e10cSrcweir
GetVersion() const81cdf0e10cSrcweir sal_uInt16 IMapObject::GetVersion() const
82cdf0e10cSrcweir {
83cdf0e10cSrcweir return IMAP_OBJ_VERSION;
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
86cdf0e10cSrcweir
87cdf0e10cSrcweir /******************************************************************************
88cdf0e10cSrcweir |*
89cdf0e10cSrcweir |*
90cdf0e10cSrcweir |*
91cdf0e10cSrcweir \******************************************************************************/
92cdf0e10cSrcweir
Write(SvStream & rOStm,const String & rBaseURL) const93cdf0e10cSrcweir void IMapObject::Write( SvStream& rOStm, const String& rBaseURL ) const
94cdf0e10cSrcweir {
95cdf0e10cSrcweir IMapCompat* pCompat;
96cdf0e10cSrcweir const rtl_TextEncoding eEncoding = gsl_getSystemTextEncoding();
97cdf0e10cSrcweir
98cdf0e10cSrcweir rOStm << GetType();
99cdf0e10cSrcweir rOStm << GetVersion();
100cdf0e10cSrcweir rOStm << ( (sal_uInt16) eEncoding );
101cdf0e10cSrcweir
102cdf0e10cSrcweir const ByteString aRelURL = ByteString( String(URIHelper::simpleNormalizedMakeRelative( rBaseURL, aURL )), eEncoding );
103cdf0e10cSrcweir rOStm.WriteByteString( aRelURL );
104cdf0e10cSrcweir rOStm.WriteByteString( ByteString( aAltText, eEncoding ) );
105cdf0e10cSrcweir rOStm << bActive;
106cdf0e10cSrcweir rOStm.WriteByteString( ByteString( aTarget, eEncoding ) );
107cdf0e10cSrcweir
108cdf0e10cSrcweir pCompat = new IMapCompat( rOStm, STREAM_WRITE );
109cdf0e10cSrcweir
110cdf0e10cSrcweir WriteIMapObject( rOStm );
111cdf0e10cSrcweir aEventList.Write( rOStm ); // V4
112cdf0e10cSrcweir rOStm.WriteByteString( ByteString( aName, eEncoding ) ); // V5
113cdf0e10cSrcweir
114cdf0e10cSrcweir delete pCompat;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir
117cdf0e10cSrcweir
118cdf0e10cSrcweir /******************************************************************************
119cdf0e10cSrcweir |*
120cdf0e10cSrcweir |* Binaer-Import
121cdf0e10cSrcweir |*
122cdf0e10cSrcweir \******************************************************************************/
123cdf0e10cSrcweir
Read(SvStream & rIStm,const String & rBaseURL)124cdf0e10cSrcweir void IMapObject::Read( SvStream& rIStm, const String& rBaseURL )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir IMapCompat* pCompat;
127cdf0e10cSrcweir rtl_TextEncoding nTextEncoding;
128cdf0e10cSrcweir ByteString aString;
129cdf0e10cSrcweir
130cdf0e10cSrcweir // Typ und Version ueberlesen wir
131cdf0e10cSrcweir rIStm.SeekRel( 2 );
132cdf0e10cSrcweir rIStm >> nReadVersion;
133cdf0e10cSrcweir rIStm >> nTextEncoding;
134cdf0e10cSrcweir rIStm.ReadByteString( aString ); aURL = String( aString.GetBuffer(), nTextEncoding );
135cdf0e10cSrcweir rIStm.ReadByteString( aString ); aAltText = String( aString.GetBuffer(), nTextEncoding );
136cdf0e10cSrcweir rIStm >> bActive;
137cdf0e10cSrcweir rIStm.ReadByteString( aString ); aTarget = String( aString.GetBuffer(), nTextEncoding );
138cdf0e10cSrcweir
139cdf0e10cSrcweir // URL absolut machen
140cdf0e10cSrcweir aURL = URIHelper::SmartRel2Abs( INetURLObject(rBaseURL), aURL, URIHelper::GetMaybeFileHdl(), true, false, INetURLObject::WAS_ENCODED, INetURLObject::DECODE_UNAMBIGUOUS );
141cdf0e10cSrcweir pCompat = new IMapCompat( rIStm, STREAM_READ );
142cdf0e10cSrcweir
143cdf0e10cSrcweir ReadIMapObject( rIStm );
144cdf0e10cSrcweir
145cdf0e10cSrcweir // ab Version 4 lesen wir eine EventListe
146cdf0e10cSrcweir if ( nReadVersion >= 0x0004 )
147cdf0e10cSrcweir {
148cdf0e10cSrcweir aEventList.Read(rIStm);
149cdf0e10cSrcweir
150cdf0e10cSrcweir // ab Version 5 kann ein Objektname vorhanden sein
151cdf0e10cSrcweir if ( nReadVersion >= 0x0005 )
152cdf0e10cSrcweir {
153cdf0e10cSrcweir rIStm.ReadByteString( aString ); aName = String( aString.GetBuffer(), nTextEncoding );
154cdf0e10cSrcweir }
155cdf0e10cSrcweir }
156cdf0e10cSrcweir
157cdf0e10cSrcweir delete pCompat;
158cdf0e10cSrcweir }
159cdf0e10cSrcweir
160cdf0e10cSrcweir
161cdf0e10cSrcweir /******************************************************************************
162cdf0e10cSrcweir |*
163cdf0e10cSrcweir |* Konvertierung der logischen Koordianten in Pixel
164cdf0e10cSrcweir |*
165cdf0e10cSrcweir \******************************************************************************/
166cdf0e10cSrcweir
GetPixelPoint(const Point & rLogPoint)167cdf0e10cSrcweir Point IMapObject::GetPixelPoint( const Point& rLogPoint )
168cdf0e10cSrcweir {
169cdf0e10cSrcweir return Application::GetDefaultDevice()->LogicToPixel( rLogPoint, MapMode( MAP_100TH_MM ) );
170cdf0e10cSrcweir }
171cdf0e10cSrcweir
172cdf0e10cSrcweir
173cdf0e10cSrcweir /******************************************************************************
174cdf0e10cSrcweir |*
175cdf0e10cSrcweir |* Konvertierung der logischen Koordianten in Pixel
176cdf0e10cSrcweir |*
177cdf0e10cSrcweir \******************************************************************************/
178cdf0e10cSrcweir
GetLogPoint(const Point & rPixelPoint)179cdf0e10cSrcweir Point IMapObject::GetLogPoint( const Point& rPixelPoint )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir return Application::GetDefaultDevice()->PixelToLogic( rPixelPoint, MapMode( MAP_100TH_MM ) );
182cdf0e10cSrcweir }
183cdf0e10cSrcweir
184cdf0e10cSrcweir
185cdf0e10cSrcweir /******************************************************************************
186cdf0e10cSrcweir |*
187cdf0e10cSrcweir |*
188cdf0e10cSrcweir |*
189cdf0e10cSrcweir \******************************************************************************/
190cdf0e10cSrcweir
IsEqual(const IMapObject & rEqObj)191cdf0e10cSrcweir sal_Bool IMapObject::IsEqual( const IMapObject& rEqObj )
192cdf0e10cSrcweir {
193cdf0e10cSrcweir return ( ( aURL == rEqObj.aURL ) &&
194cdf0e10cSrcweir ( aAltText == rEqObj.aAltText ) &&
195cdf0e10cSrcweir ( aDesc == rEqObj.aDesc ) &&
196cdf0e10cSrcweir ( aTarget == rEqObj.aTarget ) &&
197cdf0e10cSrcweir ( aName == rEqObj.aName ) &&
198cdf0e10cSrcweir ( bActive == rEqObj.bActive ) );
199cdf0e10cSrcweir }
200cdf0e10cSrcweir
201cdf0e10cSrcweir
202cdf0e10cSrcweir /******************************************************************************/
203cdf0e10cSrcweir /******************************************************************************/
204cdf0e10cSrcweir /******************************************************************************/
205cdf0e10cSrcweir
IMapRectangleObject(const Rectangle & rRect,const String & rURL,const String & rAltText,const String & rDesc,const String & rTarget,const String & rName,sal_Bool bURLActive,sal_Bool bPixelCoords)206cdf0e10cSrcweir IMapRectangleObject::IMapRectangleObject( const Rectangle& rRect,
207cdf0e10cSrcweir const String& rURL,
208cdf0e10cSrcweir const String& rAltText,
209cdf0e10cSrcweir const String& rDesc,
210cdf0e10cSrcweir const String& rTarget,
211cdf0e10cSrcweir const String& rName,
212cdf0e10cSrcweir sal_Bool bURLActive,
213cdf0e10cSrcweir sal_Bool bPixelCoords ) :
214cdf0e10cSrcweir IMapObject ( rURL, rAltText, rDesc, rTarget, rName, bURLActive )
215cdf0e10cSrcweir {
216cdf0e10cSrcweir ImpConstruct( rRect, bPixelCoords );
217cdf0e10cSrcweir }
218cdf0e10cSrcweir
219cdf0e10cSrcweir
220cdf0e10cSrcweir /******************************************************************************
221cdf0e10cSrcweir |*
222cdf0e10cSrcweir |*
223cdf0e10cSrcweir |*
224cdf0e10cSrcweir \******************************************************************************/
225cdf0e10cSrcweir
ImpConstruct(const Rectangle & rRect,sal_Bool bPixel)226cdf0e10cSrcweir void IMapRectangleObject::ImpConstruct( const Rectangle& rRect, sal_Bool bPixel )
227cdf0e10cSrcweir {
228cdf0e10cSrcweir if ( bPixel )
229cdf0e10cSrcweir aRect = Application::GetDefaultDevice()->PixelToLogic( rRect, MapMode( MAP_100TH_MM ) );
230cdf0e10cSrcweir else
231cdf0e10cSrcweir aRect = rRect;
232cdf0e10cSrcweir }
233cdf0e10cSrcweir
234cdf0e10cSrcweir
235cdf0e10cSrcweir /******************************************************************************
236cdf0e10cSrcweir |*
237cdf0e10cSrcweir |* Binaer-Export
238cdf0e10cSrcweir |*
239cdf0e10cSrcweir \******************************************************************************/
240cdf0e10cSrcweir
WriteIMapObject(SvStream & rOStm) const241cdf0e10cSrcweir void IMapRectangleObject::WriteIMapObject( SvStream& rOStm ) const
242cdf0e10cSrcweir {
243cdf0e10cSrcweir rOStm << aRect;
244cdf0e10cSrcweir }
245cdf0e10cSrcweir
246cdf0e10cSrcweir
247cdf0e10cSrcweir /******************************************************************************
248cdf0e10cSrcweir |*
249cdf0e10cSrcweir |* Binaer-Import
250cdf0e10cSrcweir |*
251cdf0e10cSrcweir \******************************************************************************/
252cdf0e10cSrcweir
ReadIMapObject(SvStream & rIStm)253cdf0e10cSrcweir void IMapRectangleObject::ReadIMapObject( SvStream& rIStm )
254cdf0e10cSrcweir {
255cdf0e10cSrcweir rIStm >> aRect;
256cdf0e10cSrcweir }
257cdf0e10cSrcweir
258cdf0e10cSrcweir
259cdf0e10cSrcweir /******************************************************************************
260cdf0e10cSrcweir |*
261cdf0e10cSrcweir |* Typ-Rueckgabe
262cdf0e10cSrcweir |*
263cdf0e10cSrcweir \******************************************************************************/
264cdf0e10cSrcweir
GetType() const265cdf0e10cSrcweir sal_uInt16 IMapRectangleObject::GetType() const
266cdf0e10cSrcweir {
267cdf0e10cSrcweir return IMAP_OBJ_RECTANGLE;
268cdf0e10cSrcweir }
269cdf0e10cSrcweir
270cdf0e10cSrcweir
271cdf0e10cSrcweir /******************************************************************************
272cdf0e10cSrcweir |*
273cdf0e10cSrcweir |* Hit-Test
274cdf0e10cSrcweir |*
275cdf0e10cSrcweir \******************************************************************************/
276cdf0e10cSrcweir
IsHit(const Point & rPoint) const277cdf0e10cSrcweir sal_Bool IMapRectangleObject::IsHit( const Point& rPoint ) const
278cdf0e10cSrcweir {
279cdf0e10cSrcweir return aRect.IsInside( rPoint );
280cdf0e10cSrcweir }
281cdf0e10cSrcweir
282cdf0e10cSrcweir
283cdf0e10cSrcweir /******************************************************************************
284cdf0e10cSrcweir |*
285cdf0e10cSrcweir |*
286cdf0e10cSrcweir |*
287cdf0e10cSrcweir \******************************************************************************/
288cdf0e10cSrcweir
GetRectangle(sal_Bool bPixelCoords) const289cdf0e10cSrcweir Rectangle IMapRectangleObject::GetRectangle( sal_Bool bPixelCoords ) const
290cdf0e10cSrcweir {
291cdf0e10cSrcweir Rectangle aNewRect;
292cdf0e10cSrcweir
293cdf0e10cSrcweir if ( bPixelCoords )
294cdf0e10cSrcweir aNewRect = Application::GetDefaultDevice()->LogicToPixel( aRect, MapMode( MAP_100TH_MM ) );
295cdf0e10cSrcweir else
296cdf0e10cSrcweir aNewRect = aRect;
297cdf0e10cSrcweir
298cdf0e10cSrcweir return aNewRect;
299cdf0e10cSrcweir }
300cdf0e10cSrcweir
301cdf0e10cSrcweir
302cdf0e10cSrcweir /******************************************************************************
303cdf0e10cSrcweir |*
304cdf0e10cSrcweir |*
305cdf0e10cSrcweir |*
306cdf0e10cSrcweir \******************************************************************************/
307cdf0e10cSrcweir
Scale(const Fraction & rFracX,const Fraction & rFracY)308cdf0e10cSrcweir void IMapRectangleObject::Scale( const Fraction& rFracX, const Fraction& rFracY )
309cdf0e10cSrcweir {
310cdf0e10cSrcweir Point aTL( aRect.TopLeft() );
311cdf0e10cSrcweir Point aBR( aRect.BottomRight() );
312cdf0e10cSrcweir
313cdf0e10cSrcweir if ( rFracX.GetDenominator() && rFracY.GetDenominator() )
314cdf0e10cSrcweir {
315cdf0e10cSrcweir SCALEPOINT( aTL, rFracX, rFracY );
316cdf0e10cSrcweir SCALEPOINT( aBR, rFracX, rFracY );
317cdf0e10cSrcweir }
318cdf0e10cSrcweir
319cdf0e10cSrcweir aRect = Rectangle( aTL, aBR );
320cdf0e10cSrcweir }
321cdf0e10cSrcweir
322cdf0e10cSrcweir
323cdf0e10cSrcweir /******************************************************************************
324cdf0e10cSrcweir |*
325cdf0e10cSrcweir |*
326cdf0e10cSrcweir |*
327cdf0e10cSrcweir \******************************************************************************/
328cdf0e10cSrcweir
IsEqual(const IMapRectangleObject & rEqObj)329cdf0e10cSrcweir sal_Bool IMapRectangleObject::IsEqual( const IMapRectangleObject& rEqObj )
330cdf0e10cSrcweir {
331cdf0e10cSrcweir return ( IMapObject::IsEqual( rEqObj ) && ( aRect == rEqObj.aRect ) );
332cdf0e10cSrcweir }
333cdf0e10cSrcweir
334cdf0e10cSrcweir
335cdf0e10cSrcweir /******************************************************************************/
336cdf0e10cSrcweir /******************************************************************************/
337cdf0e10cSrcweir /******************************************************************************/
338cdf0e10cSrcweir
IMapCircleObject(const Point & rCenter,sal_uLong nCircleRadius,const String & rURL,const String & rAltText,const String & rDesc,const String & rTarget,const String & rName,sal_Bool bURLActive,sal_Bool bPixelCoords)339cdf0e10cSrcweir IMapCircleObject::IMapCircleObject( const Point& rCenter, sal_uLong nCircleRadius,
340cdf0e10cSrcweir const String& rURL,
341cdf0e10cSrcweir const String& rAltText,
342cdf0e10cSrcweir const String& rDesc,
343cdf0e10cSrcweir const String& rTarget,
344cdf0e10cSrcweir const String& rName,
345cdf0e10cSrcweir sal_Bool bURLActive,
346cdf0e10cSrcweir sal_Bool bPixelCoords ) :
347cdf0e10cSrcweir IMapObject ( rURL, rAltText, rDesc, rTarget, rName, bURLActive )
348cdf0e10cSrcweir {
349cdf0e10cSrcweir ImpConstruct( rCenter, nCircleRadius, bPixelCoords );
350cdf0e10cSrcweir }
351cdf0e10cSrcweir
352cdf0e10cSrcweir
353cdf0e10cSrcweir /******************************************************************************
354cdf0e10cSrcweir |*
355cdf0e10cSrcweir |*
356cdf0e10cSrcweir |*
357cdf0e10cSrcweir \******************************************************************************/
358cdf0e10cSrcweir
ImpConstruct(const Point & rCenter,sal_uLong nRad,sal_Bool bPixel)359cdf0e10cSrcweir void IMapCircleObject::ImpConstruct( const Point& rCenter, sal_uLong nRad, sal_Bool bPixel )
360cdf0e10cSrcweir {
361cdf0e10cSrcweir if ( bPixel )
362cdf0e10cSrcweir {
363cdf0e10cSrcweir MapMode aMap100( MAP_100TH_MM );
364cdf0e10cSrcweir
365cdf0e10cSrcweir aCenter = Application::GetDefaultDevice()->PixelToLogic( rCenter, aMap100 );
366cdf0e10cSrcweir nRadius = Application::GetDefaultDevice()->PixelToLogic( Size( nRad, 0 ), aMap100 ).Width();
367cdf0e10cSrcweir }
368cdf0e10cSrcweir else
369cdf0e10cSrcweir {
370cdf0e10cSrcweir aCenter = rCenter;
371cdf0e10cSrcweir nRadius = nRad;
372cdf0e10cSrcweir }
373cdf0e10cSrcweir }
374cdf0e10cSrcweir
375cdf0e10cSrcweir
376cdf0e10cSrcweir /******************************************************************************
377cdf0e10cSrcweir |*
378cdf0e10cSrcweir |* Binaer-Export
379cdf0e10cSrcweir |*
380cdf0e10cSrcweir \******************************************************************************/
381cdf0e10cSrcweir
WriteIMapObject(SvStream & rOStm) const382cdf0e10cSrcweir void IMapCircleObject::WriteIMapObject( SvStream& rOStm ) const
383cdf0e10cSrcweir {
384cdf0e10cSrcweir sal_uInt32 nTmp = nRadius;
385cdf0e10cSrcweir
386cdf0e10cSrcweir rOStm << aCenter;
387cdf0e10cSrcweir rOStm << nTmp;
388cdf0e10cSrcweir }
389cdf0e10cSrcweir
390cdf0e10cSrcweir
391cdf0e10cSrcweir /******************************************************************************
392cdf0e10cSrcweir |*
393cdf0e10cSrcweir |* Binaer-Import
394cdf0e10cSrcweir |*
395cdf0e10cSrcweir \******************************************************************************/
396cdf0e10cSrcweir
ReadIMapObject(SvStream & rIStm)397cdf0e10cSrcweir void IMapCircleObject::ReadIMapObject( SvStream& rIStm )
398cdf0e10cSrcweir {
399cdf0e10cSrcweir sal_uInt32 nTmp;
400cdf0e10cSrcweir
401cdf0e10cSrcweir rIStm >> aCenter;
402cdf0e10cSrcweir rIStm >> nTmp;
403cdf0e10cSrcweir
404cdf0e10cSrcweir nRadius = nTmp;
405cdf0e10cSrcweir }
406cdf0e10cSrcweir
407cdf0e10cSrcweir
408cdf0e10cSrcweir /******************************************************************************
409cdf0e10cSrcweir |*
410cdf0e10cSrcweir |* Typ-Rueckgabe
411cdf0e10cSrcweir |*
412cdf0e10cSrcweir \******************************************************************************/
413cdf0e10cSrcweir
GetType() const414cdf0e10cSrcweir sal_uInt16 IMapCircleObject::GetType() const
415cdf0e10cSrcweir {
416cdf0e10cSrcweir return IMAP_OBJ_CIRCLE;
417cdf0e10cSrcweir }
418cdf0e10cSrcweir
419cdf0e10cSrcweir
420cdf0e10cSrcweir /******************************************************************************
421cdf0e10cSrcweir |*
422cdf0e10cSrcweir |* Hit-Test
423cdf0e10cSrcweir |*
424cdf0e10cSrcweir \******************************************************************************/
425cdf0e10cSrcweir
IsHit(const Point & rPoint) const426cdf0e10cSrcweir sal_Bool IMapCircleObject::IsHit( const Point& rPoint ) const
427cdf0e10cSrcweir {
428cdf0e10cSrcweir const Point aPoint( aCenter - rPoint );
429cdf0e10cSrcweir sal_Bool bRet = sal_False;
430cdf0e10cSrcweir
431cdf0e10cSrcweir if ( (sal_uLong) sqrt( (double) aPoint.X() * aPoint.X() +
432cdf0e10cSrcweir aPoint.Y() * aPoint.Y() ) <= nRadius )
433cdf0e10cSrcweir {
434cdf0e10cSrcweir bRet = sal_True;
435cdf0e10cSrcweir }
436cdf0e10cSrcweir
437cdf0e10cSrcweir return bRet;
438cdf0e10cSrcweir }
439cdf0e10cSrcweir
440cdf0e10cSrcweir
441cdf0e10cSrcweir /******************************************************************************
442cdf0e10cSrcweir |*
443cdf0e10cSrcweir |*
444cdf0e10cSrcweir |*
445cdf0e10cSrcweir \******************************************************************************/
446cdf0e10cSrcweir
GetCenter(sal_Bool bPixelCoords) const447cdf0e10cSrcweir Point IMapCircleObject::GetCenter( sal_Bool bPixelCoords ) const
448cdf0e10cSrcweir {
449cdf0e10cSrcweir Point aNewPoint;
450cdf0e10cSrcweir
451cdf0e10cSrcweir if ( bPixelCoords )
452cdf0e10cSrcweir aNewPoint = Application::GetDefaultDevice()->LogicToPixel( aCenter, MapMode( MAP_100TH_MM ) );
453cdf0e10cSrcweir else
454cdf0e10cSrcweir aNewPoint = aCenter;
455cdf0e10cSrcweir
456cdf0e10cSrcweir return aNewPoint;
457cdf0e10cSrcweir }
458cdf0e10cSrcweir
459cdf0e10cSrcweir
460cdf0e10cSrcweir /******************************************************************************
461cdf0e10cSrcweir |*
462cdf0e10cSrcweir |*
463cdf0e10cSrcweir |*
464cdf0e10cSrcweir \******************************************************************************/
465cdf0e10cSrcweir
GetRadius(sal_Bool bPixelCoords) const466cdf0e10cSrcweir sal_uLong IMapCircleObject::GetRadius( sal_Bool bPixelCoords ) const
467cdf0e10cSrcweir {
468cdf0e10cSrcweir sal_uLong nNewRadius;
469cdf0e10cSrcweir
470cdf0e10cSrcweir if ( bPixelCoords )
471cdf0e10cSrcweir nNewRadius = Application::GetDefaultDevice()->LogicToPixel( Size( nRadius, 0 ), MapMode( MAP_100TH_MM ) ).Width();
472cdf0e10cSrcweir else
473cdf0e10cSrcweir nNewRadius = nRadius;
474cdf0e10cSrcweir
475cdf0e10cSrcweir return nNewRadius;
476cdf0e10cSrcweir }
477cdf0e10cSrcweir
478cdf0e10cSrcweir
479cdf0e10cSrcweir /******************************************************************************
480cdf0e10cSrcweir |*
481cdf0e10cSrcweir |*
482cdf0e10cSrcweir |*
483cdf0e10cSrcweir \******************************************************************************/
484cdf0e10cSrcweir
GetBoundRect() const485cdf0e10cSrcweir Rectangle IMapCircleObject::GetBoundRect() const
486cdf0e10cSrcweir {
487cdf0e10cSrcweir long nWidth = nRadius << 1;
488cdf0e10cSrcweir
489cdf0e10cSrcweir return Rectangle( Point( aCenter.X() - nRadius, aCenter.Y() - nRadius ),
490cdf0e10cSrcweir Size( nWidth, nWidth ) );
491cdf0e10cSrcweir }
492cdf0e10cSrcweir
493cdf0e10cSrcweir
494cdf0e10cSrcweir /******************************************************************************
495cdf0e10cSrcweir |*
496cdf0e10cSrcweir |*
497cdf0e10cSrcweir |*
498cdf0e10cSrcweir \******************************************************************************/
499cdf0e10cSrcweir
Scale(const Fraction & rFracX,const Fraction & rFracY)500cdf0e10cSrcweir void IMapCircleObject::Scale( const Fraction& rFracX, const Fraction& rFracY )
501cdf0e10cSrcweir {
502cdf0e10cSrcweir Fraction aAverage( rFracX );
503cdf0e10cSrcweir
504cdf0e10cSrcweir aAverage += rFracY;
505cdf0e10cSrcweir aAverage *= Fraction( 1, 2 );
506cdf0e10cSrcweir
507cdf0e10cSrcweir if ( rFracX.GetDenominator() && rFracY.GetDenominator() )
508cdf0e10cSrcweir {
509cdf0e10cSrcweir SCALEPOINT( aCenter, rFracX, rFracY );
510cdf0e10cSrcweir }
511cdf0e10cSrcweir
512cdf0e10cSrcweir nRadius = ( nRadius * aAverage.GetNumerator() ) / aAverage.GetDenominator();
513cdf0e10cSrcweir }
514cdf0e10cSrcweir
515cdf0e10cSrcweir
516cdf0e10cSrcweir /******************************************************************************
517cdf0e10cSrcweir |*
518cdf0e10cSrcweir |*
519cdf0e10cSrcweir |*
520cdf0e10cSrcweir \******************************************************************************/
521cdf0e10cSrcweir
IsEqual(const IMapCircleObject & rEqObj)522cdf0e10cSrcweir sal_Bool IMapCircleObject::IsEqual( const IMapCircleObject& rEqObj )
523cdf0e10cSrcweir {
524cdf0e10cSrcweir return ( IMapObject::IsEqual( rEqObj ) &&
525cdf0e10cSrcweir ( aCenter == rEqObj.aCenter ) &&
526cdf0e10cSrcweir ( nRadius == rEqObj.nRadius ) );
527cdf0e10cSrcweir }
528cdf0e10cSrcweir
529cdf0e10cSrcweir
530cdf0e10cSrcweir /******************************************************************************/
531cdf0e10cSrcweir /******************************************************************************/
532cdf0e10cSrcweir /******************************************************************************/
IMapPolygonObject(const Polygon & rPoly,const String & rURL,const String & rAltText,const String & rDesc,const String & rTarget,const String & rName,sal_Bool bURLActive,sal_Bool bPixelCoords)533cdf0e10cSrcweir IMapPolygonObject::IMapPolygonObject( const Polygon& rPoly,
534cdf0e10cSrcweir const String& rURL,
535cdf0e10cSrcweir const String& rAltText,
536cdf0e10cSrcweir const String& rDesc,
537cdf0e10cSrcweir const String& rTarget,
538cdf0e10cSrcweir const String& rName,
539cdf0e10cSrcweir sal_Bool bURLActive,
540cdf0e10cSrcweir sal_Bool bPixelCoords ) :
541cdf0e10cSrcweir IMapObject ( rURL, rAltText, rDesc, rTarget, rName, bURLActive ),
542cdf0e10cSrcweir bEllipse ( sal_False )
543cdf0e10cSrcweir {
544cdf0e10cSrcweir ImpConstruct( rPoly, bPixelCoords );
545cdf0e10cSrcweir }
546cdf0e10cSrcweir
547cdf0e10cSrcweir
548cdf0e10cSrcweir /******************************************************************************
549cdf0e10cSrcweir |*
550cdf0e10cSrcweir |*
551cdf0e10cSrcweir |*
552cdf0e10cSrcweir \******************************************************************************/
553cdf0e10cSrcweir
ImpConstruct(const Polygon & rPoly,sal_Bool bPixel)554cdf0e10cSrcweir void IMapPolygonObject::ImpConstruct( const Polygon& rPoly, sal_Bool bPixel )
555cdf0e10cSrcweir {
556cdf0e10cSrcweir if ( bPixel )
557cdf0e10cSrcweir aPoly = Application::GetDefaultDevice()->PixelToLogic( rPoly, MapMode( MAP_100TH_MM ) );
558cdf0e10cSrcweir else
559cdf0e10cSrcweir aPoly = rPoly;
560cdf0e10cSrcweir }
561cdf0e10cSrcweir
562cdf0e10cSrcweir
563cdf0e10cSrcweir /******************************************************************************
564cdf0e10cSrcweir |*
565cdf0e10cSrcweir |* Binaer-Export
566cdf0e10cSrcweir |*
567cdf0e10cSrcweir \******************************************************************************/
568cdf0e10cSrcweir
WriteIMapObject(SvStream & rOStm) const569cdf0e10cSrcweir void IMapPolygonObject::WriteIMapObject( SvStream& rOStm ) const
570cdf0e10cSrcweir {
571cdf0e10cSrcweir rOStm << aPoly;
572cdf0e10cSrcweir rOStm << bEllipse; // >= Version 2
573cdf0e10cSrcweir rOStm << aEllipse; // >= Version 2
574cdf0e10cSrcweir }
575cdf0e10cSrcweir
576cdf0e10cSrcweir
577cdf0e10cSrcweir /******************************************************************************
578cdf0e10cSrcweir |*
579cdf0e10cSrcweir |* Binaer-Import
580cdf0e10cSrcweir |*
581cdf0e10cSrcweir \******************************************************************************/
582cdf0e10cSrcweir
ReadIMapObject(SvStream & rIStm)583cdf0e10cSrcweir void IMapPolygonObject::ReadIMapObject( SvStream& rIStm )
584cdf0e10cSrcweir {
585cdf0e10cSrcweir rIStm >> aPoly;
586cdf0e10cSrcweir
587cdf0e10cSrcweir // Version >= 2 hat zusaetzlich Ellipsen-Information
588cdf0e10cSrcweir if ( nReadVersion >= 2 )
589cdf0e10cSrcweir {
590cdf0e10cSrcweir rIStm >> bEllipse;
591cdf0e10cSrcweir rIStm >> aEllipse;
592cdf0e10cSrcweir }
593cdf0e10cSrcweir }
594cdf0e10cSrcweir
595cdf0e10cSrcweir
596cdf0e10cSrcweir /******************************************************************************
597cdf0e10cSrcweir |*
598cdf0e10cSrcweir |* Typ-Rueckgabe
599cdf0e10cSrcweir |*
600cdf0e10cSrcweir \******************************************************************************/
601cdf0e10cSrcweir
GetType() const602cdf0e10cSrcweir sal_uInt16 IMapPolygonObject::GetType() const
603cdf0e10cSrcweir {
604cdf0e10cSrcweir return IMAP_OBJ_POLYGON;
605cdf0e10cSrcweir }
606cdf0e10cSrcweir
607cdf0e10cSrcweir
608cdf0e10cSrcweir /******************************************************************************
609cdf0e10cSrcweir |*
610cdf0e10cSrcweir |* Hit-Test
611cdf0e10cSrcweir |*
612cdf0e10cSrcweir \******************************************************************************/
613cdf0e10cSrcweir
IsHit(const Point & rPoint) const614cdf0e10cSrcweir sal_Bool IMapPolygonObject::IsHit( const Point& rPoint ) const
615cdf0e10cSrcweir {
616cdf0e10cSrcweir return aPoly.IsInside( rPoint );
617cdf0e10cSrcweir }
618cdf0e10cSrcweir
619cdf0e10cSrcweir
620cdf0e10cSrcweir /******************************************************************************
621cdf0e10cSrcweir |*
622cdf0e10cSrcweir |*
623cdf0e10cSrcweir |*
624cdf0e10cSrcweir \******************************************************************************/
625cdf0e10cSrcweir
GetPolygon(sal_Bool bPixelCoords) const626cdf0e10cSrcweir Polygon IMapPolygonObject::GetPolygon( sal_Bool bPixelCoords ) const
627cdf0e10cSrcweir {
628cdf0e10cSrcweir Polygon aNewPoly;
629cdf0e10cSrcweir
630cdf0e10cSrcweir if ( bPixelCoords )
631cdf0e10cSrcweir aNewPoly = Application::GetDefaultDevice()->LogicToPixel( aPoly, MapMode( MAP_100TH_MM ) );
632cdf0e10cSrcweir else
633cdf0e10cSrcweir aNewPoly = aPoly;
634cdf0e10cSrcweir
635cdf0e10cSrcweir return aNewPoly;
636cdf0e10cSrcweir }
637cdf0e10cSrcweir
638cdf0e10cSrcweir
639cdf0e10cSrcweir /******************************************************************************
640cdf0e10cSrcweir |*
641cdf0e10cSrcweir |*
642cdf0e10cSrcweir |*
643cdf0e10cSrcweir \******************************************************************************/
644cdf0e10cSrcweir
SetExtraEllipse(const Rectangle & rEllipse)645cdf0e10cSrcweir void IMapPolygonObject::SetExtraEllipse( const Rectangle& rEllipse )
646cdf0e10cSrcweir {
647cdf0e10cSrcweir if ( aPoly.GetSize() )
648cdf0e10cSrcweir {
649cdf0e10cSrcweir bEllipse = sal_True;
650cdf0e10cSrcweir aEllipse = rEllipse;
651cdf0e10cSrcweir }
652cdf0e10cSrcweir }
653cdf0e10cSrcweir
654cdf0e10cSrcweir
655cdf0e10cSrcweir /******************************************************************************
656cdf0e10cSrcweir |*
657cdf0e10cSrcweir |*
658cdf0e10cSrcweir |*
659cdf0e10cSrcweir \******************************************************************************/
660cdf0e10cSrcweir
Scale(const Fraction & rFracX,const Fraction & rFracY)661cdf0e10cSrcweir void IMapPolygonObject::Scale( const Fraction& rFracX, const Fraction& rFracY )
662cdf0e10cSrcweir {
663cdf0e10cSrcweir sal_uInt16 nCount = aPoly.GetSize();
664cdf0e10cSrcweir
665cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < nCount; i++ )
666cdf0e10cSrcweir {
667cdf0e10cSrcweir Point aScaledPt( aPoly[ i ] );
668cdf0e10cSrcweir
669cdf0e10cSrcweir if ( rFracX.GetDenominator() && rFracY.GetDenominator() )
670cdf0e10cSrcweir {
671cdf0e10cSrcweir SCALEPOINT( aScaledPt, rFracX, rFracY );
672cdf0e10cSrcweir }
673cdf0e10cSrcweir
674cdf0e10cSrcweir aPoly[ i ] = aScaledPt;
675cdf0e10cSrcweir }
676cdf0e10cSrcweir
677cdf0e10cSrcweir if ( bEllipse )
678cdf0e10cSrcweir {
679cdf0e10cSrcweir Point aTL( aEllipse.TopLeft() );
680cdf0e10cSrcweir Point aBR( aEllipse.BottomRight() );
681cdf0e10cSrcweir
682cdf0e10cSrcweir if ( rFracX.GetDenominator() && rFracY.GetDenominator() )
683cdf0e10cSrcweir {
684cdf0e10cSrcweir SCALEPOINT( aTL, rFracX, rFracY );
685cdf0e10cSrcweir SCALEPOINT( aBR, rFracX, rFracY );
686cdf0e10cSrcweir }
687cdf0e10cSrcweir
688cdf0e10cSrcweir aEllipse = Rectangle( aTL, aBR );
689cdf0e10cSrcweir }
690cdf0e10cSrcweir }
691cdf0e10cSrcweir
692cdf0e10cSrcweir
693cdf0e10cSrcweir /******************************************************************************
694cdf0e10cSrcweir |*
695cdf0e10cSrcweir |*
696cdf0e10cSrcweir |*
697cdf0e10cSrcweir \******************************************************************************/
698cdf0e10cSrcweir
IsEqual(const IMapPolygonObject & rEqObj)699cdf0e10cSrcweir sal_Bool IMapPolygonObject::IsEqual( const IMapPolygonObject& rEqObj )
700cdf0e10cSrcweir {
701cdf0e10cSrcweir sal_Bool bRet = sal_False;
702cdf0e10cSrcweir
703cdf0e10cSrcweir if ( IMapObject::IsEqual( rEqObj ) )
704cdf0e10cSrcweir {
705cdf0e10cSrcweir const Polygon& rEqPoly = rEqObj.aPoly;
706cdf0e10cSrcweir const sal_uInt16 nCount = aPoly.GetSize();
707cdf0e10cSrcweir const sal_uInt16 nEqCount = rEqPoly.GetSize();
708cdf0e10cSrcweir sal_Bool bDifferent = sal_False;
709cdf0e10cSrcweir
710cdf0e10cSrcweir if ( nCount == nEqCount )
711cdf0e10cSrcweir {
712cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < nCount; i++ )
713cdf0e10cSrcweir {
714cdf0e10cSrcweir if ( aPoly[ i ] != rEqPoly[ i ] )
715cdf0e10cSrcweir {
716cdf0e10cSrcweir bDifferent = sal_True;
717cdf0e10cSrcweir break;
718cdf0e10cSrcweir }
719cdf0e10cSrcweir }
720cdf0e10cSrcweir
721cdf0e10cSrcweir if ( !bDifferent )
722cdf0e10cSrcweir bRet = sal_True;
723cdf0e10cSrcweir }
724cdf0e10cSrcweir }
725cdf0e10cSrcweir
726cdf0e10cSrcweir return bRet;
727cdf0e10cSrcweir }
728cdf0e10cSrcweir
729cdf0e10cSrcweir
730cdf0e10cSrcweir /******************************************************************************/
731cdf0e10cSrcweir /******************************************************************************/
732cdf0e10cSrcweir /******************************************************************************/
733cdf0e10cSrcweir
734cdf0e10cSrcweir
735cdf0e10cSrcweir /******************************************************************************
736cdf0e10cSrcweir |*
737cdf0e10cSrcweir |* Ctor
738cdf0e10cSrcweir |*
739cdf0e10cSrcweir \******************************************************************************/
740cdf0e10cSrcweir
ImageMap(const String & rName)741cdf0e10cSrcweir ImageMap::ImageMap( const String& rName ) :
742cdf0e10cSrcweir aName ( rName )
743cdf0e10cSrcweir {
744cdf0e10cSrcweir }
745cdf0e10cSrcweir
746cdf0e10cSrcweir
747cdf0e10cSrcweir /******************************************************************************
748cdf0e10cSrcweir |*
749cdf0e10cSrcweir |* Copy-Ctor
750cdf0e10cSrcweir |*
751cdf0e10cSrcweir \******************************************************************************/
752cdf0e10cSrcweir
ImageMap(const ImageMap & rImageMap)753cdf0e10cSrcweir ImageMap::ImageMap( const ImageMap& rImageMap )
754cdf0e10cSrcweir {
755cdf0e10cSrcweir DBG_CTOR( ImageMap, NULL );
756cdf0e10cSrcweir
757cdf0e10cSrcweir sal_uInt16 nCount = rImageMap.GetIMapObjectCount();
758cdf0e10cSrcweir
759cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < nCount; i++ )
760cdf0e10cSrcweir {
761cdf0e10cSrcweir IMapObject* pCopyObj = rImageMap.GetIMapObject( i );
762cdf0e10cSrcweir
763cdf0e10cSrcweir switch( pCopyObj->GetType() )
764cdf0e10cSrcweir {
765cdf0e10cSrcweir case( IMAP_OBJ_RECTANGLE ):
766cdf0e10cSrcweir maList.Insert( new IMapRectangleObject( *(IMapRectangleObject*) pCopyObj ), LIST_APPEND );
767cdf0e10cSrcweir break;
768cdf0e10cSrcweir
769cdf0e10cSrcweir case( IMAP_OBJ_CIRCLE ):
770cdf0e10cSrcweir maList.Insert( new IMapCircleObject( *(IMapCircleObject*) pCopyObj ), LIST_APPEND );
771cdf0e10cSrcweir break;
772cdf0e10cSrcweir
773cdf0e10cSrcweir case( IMAP_OBJ_POLYGON ):
774cdf0e10cSrcweir maList.Insert( new IMapPolygonObject( *(IMapPolygonObject*) pCopyObj ), LIST_APPEND );
775cdf0e10cSrcweir break;
776cdf0e10cSrcweir
777cdf0e10cSrcweir default:
778cdf0e10cSrcweir break;
779cdf0e10cSrcweir }
780cdf0e10cSrcweir }
781cdf0e10cSrcweir
782cdf0e10cSrcweir aName = rImageMap.aName;
783cdf0e10cSrcweir }
784cdf0e10cSrcweir
785cdf0e10cSrcweir
786cdf0e10cSrcweir /******************************************************************************
787cdf0e10cSrcweir |*
788cdf0e10cSrcweir |* Dtor
789cdf0e10cSrcweir |*
790cdf0e10cSrcweir \******************************************************************************/
791cdf0e10cSrcweir
~ImageMap()792cdf0e10cSrcweir ImageMap::~ImageMap()
793cdf0e10cSrcweir {
794cdf0e10cSrcweir DBG_DTOR( ImageMap, NULL );
795cdf0e10cSrcweir
796cdf0e10cSrcweir ClearImageMap();
797cdf0e10cSrcweir }
798cdf0e10cSrcweir
799cdf0e10cSrcweir
800cdf0e10cSrcweir /******************************************************************************
801cdf0e10cSrcweir |*
802cdf0e10cSrcweir |* Freigabe des internen Speichers
803cdf0e10cSrcweir |*
804cdf0e10cSrcweir \******************************************************************************/
805cdf0e10cSrcweir
ClearImageMap()806cdf0e10cSrcweir void ImageMap::ClearImageMap()
807cdf0e10cSrcweir {
808cdf0e10cSrcweir IMapObject* pObj = (IMapObject*) maList.First();
809cdf0e10cSrcweir
810cdf0e10cSrcweir while ( pObj )
811cdf0e10cSrcweir {
812cdf0e10cSrcweir delete pObj;
813cdf0e10cSrcweir pObj = (IMapObject*) maList.Next();
814cdf0e10cSrcweir }
815cdf0e10cSrcweir
816cdf0e10cSrcweir maList.Clear();
817cdf0e10cSrcweir
818cdf0e10cSrcweir aName = String();
819cdf0e10cSrcweir }
820cdf0e10cSrcweir
821cdf0e10cSrcweir
822cdf0e10cSrcweir /******************************************************************************
823cdf0e10cSrcweir |*
824cdf0e10cSrcweir |* Zuweisungsoperator
825cdf0e10cSrcweir |*
826cdf0e10cSrcweir \******************************************************************************/
827cdf0e10cSrcweir
operator =(const ImageMap & rImageMap)828cdf0e10cSrcweir ImageMap& ImageMap::operator=( const ImageMap& rImageMap )
829cdf0e10cSrcweir {
830cdf0e10cSrcweir sal_uInt16 nCount = rImageMap.GetIMapObjectCount();
831cdf0e10cSrcweir
832cdf0e10cSrcweir ClearImageMap();
833cdf0e10cSrcweir
834cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < nCount; i++ )
835cdf0e10cSrcweir {
836cdf0e10cSrcweir IMapObject* pCopyObj = rImageMap.GetIMapObject( i );
837cdf0e10cSrcweir
838cdf0e10cSrcweir switch( pCopyObj->GetType() )
839cdf0e10cSrcweir {
840cdf0e10cSrcweir case( IMAP_OBJ_RECTANGLE ):
841cdf0e10cSrcweir maList.Insert( new IMapRectangleObject( *(IMapRectangleObject*) pCopyObj ), LIST_APPEND );
842cdf0e10cSrcweir break;
843cdf0e10cSrcweir
844cdf0e10cSrcweir case( IMAP_OBJ_CIRCLE ):
845cdf0e10cSrcweir maList.Insert( new IMapCircleObject( *(IMapCircleObject*) pCopyObj ), LIST_APPEND );
846cdf0e10cSrcweir break;
847cdf0e10cSrcweir
848cdf0e10cSrcweir case( IMAP_OBJ_POLYGON ):
849cdf0e10cSrcweir maList.Insert( new IMapPolygonObject( *(IMapPolygonObject*) pCopyObj ), LIST_APPEND );
850cdf0e10cSrcweir break;
851cdf0e10cSrcweir
852cdf0e10cSrcweir default:
853cdf0e10cSrcweir break;
854cdf0e10cSrcweir }
855cdf0e10cSrcweir }
856cdf0e10cSrcweir
857cdf0e10cSrcweir aName = rImageMap.aName;
858cdf0e10cSrcweir
859cdf0e10cSrcweir return *this;
860cdf0e10cSrcweir }
861cdf0e10cSrcweir
862cdf0e10cSrcweir
863cdf0e10cSrcweir /******************************************************************************
864cdf0e10cSrcweir |*
865cdf0e10cSrcweir |* Vergleichsoperator I
866cdf0e10cSrcweir |*
867cdf0e10cSrcweir \******************************************************************************/
868cdf0e10cSrcweir
operator ==(const ImageMap & rImageMap)869cdf0e10cSrcweir sal_Bool ImageMap::operator==( const ImageMap& rImageMap )
870cdf0e10cSrcweir {
871cdf0e10cSrcweir const sal_uInt16 nCount = (sal_uInt16) maList.Count();
872cdf0e10cSrcweir const sal_uInt16 nEqCount = rImageMap.GetIMapObjectCount();
873cdf0e10cSrcweir sal_Bool bRet = sal_False;
874cdf0e10cSrcweir
875cdf0e10cSrcweir if ( nCount == nEqCount )
876cdf0e10cSrcweir {
877cdf0e10cSrcweir sal_Bool bDifferent = ( aName != rImageMap.aName );
878cdf0e10cSrcweir
879cdf0e10cSrcweir for ( sal_uInt16 i = 0; ( i < nCount ) && !bDifferent; i++ )
880cdf0e10cSrcweir {
881cdf0e10cSrcweir IMapObject* pObj = (IMapObject*) maList.GetObject( i );
882cdf0e10cSrcweir IMapObject* pEqObj = rImageMap.GetIMapObject( i );
883cdf0e10cSrcweir
884cdf0e10cSrcweir if ( pObj->GetType() == pEqObj->GetType() )
885cdf0e10cSrcweir {
886cdf0e10cSrcweir switch( pObj->GetType() )
887cdf0e10cSrcweir {
888cdf0e10cSrcweir case( IMAP_OBJ_RECTANGLE ):
889cdf0e10cSrcweir {
890cdf0e10cSrcweir if ( !( (IMapRectangleObject*) pObj )->IsEqual( *(IMapRectangleObject*) pEqObj ) )
891cdf0e10cSrcweir bDifferent = sal_True;
892cdf0e10cSrcweir }
893cdf0e10cSrcweir break;
894cdf0e10cSrcweir
895cdf0e10cSrcweir case( IMAP_OBJ_CIRCLE ):
896cdf0e10cSrcweir {
897cdf0e10cSrcweir if ( !( (IMapCircleObject*) pObj )->IsEqual( *(IMapCircleObject*) pEqObj ) )
898cdf0e10cSrcweir bDifferent = sal_True;
899cdf0e10cSrcweir }
900cdf0e10cSrcweir break;
901cdf0e10cSrcweir
902cdf0e10cSrcweir case( IMAP_OBJ_POLYGON ):
903cdf0e10cSrcweir {
904cdf0e10cSrcweir if ( !( (IMapPolygonObject*) pObj )->IsEqual( *(IMapPolygonObject*) pEqObj ) )
905cdf0e10cSrcweir bDifferent = sal_True;
906cdf0e10cSrcweir }
907cdf0e10cSrcweir break;
908cdf0e10cSrcweir
909cdf0e10cSrcweir default:
910cdf0e10cSrcweir break;
911cdf0e10cSrcweir }
912cdf0e10cSrcweir }
913cdf0e10cSrcweir else
914cdf0e10cSrcweir bDifferent = sal_True;
915cdf0e10cSrcweir }
916cdf0e10cSrcweir
917cdf0e10cSrcweir if ( !bDifferent )
918cdf0e10cSrcweir bRet = sal_True;
919cdf0e10cSrcweir }
920cdf0e10cSrcweir
921cdf0e10cSrcweir return bRet;
922cdf0e10cSrcweir }
923cdf0e10cSrcweir
924cdf0e10cSrcweir
925cdf0e10cSrcweir /******************************************************************************
926cdf0e10cSrcweir |*
927cdf0e10cSrcweir |* Vergleichsoperator II
928cdf0e10cSrcweir |*
929cdf0e10cSrcweir \******************************************************************************/
930cdf0e10cSrcweir
operator !=(const ImageMap & rImageMap)931cdf0e10cSrcweir sal_Bool ImageMap::operator!=( const ImageMap& rImageMap )
932cdf0e10cSrcweir {
933cdf0e10cSrcweir return !( *this == rImageMap );
934cdf0e10cSrcweir }
935cdf0e10cSrcweir
936cdf0e10cSrcweir
937cdf0e10cSrcweir /******************************************************************************
938cdf0e10cSrcweir |*
939cdf0e10cSrcweir |* Freigabe des internen Speichers
940cdf0e10cSrcweir |*
941cdf0e10cSrcweir \******************************************************************************/
942cdf0e10cSrcweir
GetVersion() const943cdf0e10cSrcweir sal_uInt16 ImageMap::GetVersion() const
944cdf0e10cSrcweir {
945cdf0e10cSrcweir return IMAGE_MAP_VERSION;
946cdf0e10cSrcweir }
947cdf0e10cSrcweir
948cdf0e10cSrcweir
949cdf0e10cSrcweir /******************************************************************************
950cdf0e10cSrcweir |*
951cdf0e10cSrcweir |* Einfuegen eines neuen Objekts
952cdf0e10cSrcweir |*
953cdf0e10cSrcweir \******************************************************************************/
954cdf0e10cSrcweir
InsertIMapObject(const IMapObject & rIMapObject)955cdf0e10cSrcweir void ImageMap::InsertIMapObject( const IMapObject& rIMapObject )
956cdf0e10cSrcweir {
957cdf0e10cSrcweir switch( rIMapObject.GetType() )
958cdf0e10cSrcweir {
959cdf0e10cSrcweir case( IMAP_OBJ_RECTANGLE ):
960cdf0e10cSrcweir maList.Insert( new IMapRectangleObject( (IMapRectangleObject&) rIMapObject ), LIST_APPEND );
961cdf0e10cSrcweir break;
962cdf0e10cSrcweir
963cdf0e10cSrcweir case( IMAP_OBJ_CIRCLE ):
964cdf0e10cSrcweir maList.Insert( new IMapCircleObject( (IMapCircleObject&) rIMapObject ), LIST_APPEND );
965cdf0e10cSrcweir break;
966cdf0e10cSrcweir
967cdf0e10cSrcweir case( IMAP_OBJ_POLYGON ):
968cdf0e10cSrcweir maList.Insert( new IMapPolygonObject( (IMapPolygonObject&) rIMapObject ), LIST_APPEND );
969cdf0e10cSrcweir break;
970cdf0e10cSrcweir
971cdf0e10cSrcweir default:
972cdf0e10cSrcweir break;
973cdf0e10cSrcweir }
974cdf0e10cSrcweir }
975cdf0e10cSrcweir
976cdf0e10cSrcweir
977cdf0e10cSrcweir /******************************************************************************
978cdf0e10cSrcweir |*
979cdf0e10cSrcweir |* Hit-Test
980cdf0e10cSrcweir |*
981cdf0e10cSrcweir \******************************************************************************/
982cdf0e10cSrcweir
GetHitIMapObject(const Size & rTotalSize,const Size & rDisplaySize,const Point & rRelHitPoint,sal_uLong nFlags)983cdf0e10cSrcweir IMapObject* ImageMap::GetHitIMapObject( const Size& rTotalSize,
984cdf0e10cSrcweir const Size& rDisplaySize,
985cdf0e10cSrcweir const Point& rRelHitPoint,
986cdf0e10cSrcweir sal_uLong nFlags )
987cdf0e10cSrcweir {
988cdf0e10cSrcweir Point aRelPoint( rTotalSize.Width() * rRelHitPoint.X() / rDisplaySize.Width(),
989cdf0e10cSrcweir rTotalSize.Height() * rRelHitPoint.Y() / rDisplaySize.Height() );
990cdf0e10cSrcweir
991cdf0e10cSrcweir // Falls Flags zur Spiegelung etc. angegeben sind, wird
992cdf0e10cSrcweir // der zu pruefende Punkt vor der Pruefung entspr. transformiert
993cdf0e10cSrcweir if ( nFlags )
994cdf0e10cSrcweir {
995cdf0e10cSrcweir if ( nFlags & IMAP_MIRROR_HORZ )
996cdf0e10cSrcweir aRelPoint.X() = rTotalSize.Width() - aRelPoint.X();
997cdf0e10cSrcweir
998cdf0e10cSrcweir if ( nFlags & IMAP_MIRROR_VERT )
999cdf0e10cSrcweir aRelPoint.Y() = rTotalSize.Height() - aRelPoint.Y();
1000cdf0e10cSrcweir }
1001cdf0e10cSrcweir
1002cdf0e10cSrcweir // Alle Objekte durchlaufen und HitTest ausfuehren
1003cdf0e10cSrcweir IMapObject* pObj = (IMapObject*) maList.First();
1004cdf0e10cSrcweir while ( pObj )
1005cdf0e10cSrcweir {
1006cdf0e10cSrcweir if ( pObj->IsHit( aRelPoint ) )
1007cdf0e10cSrcweir break;
1008cdf0e10cSrcweir
1009cdf0e10cSrcweir pObj = (IMapObject*) maList.Next();
1010cdf0e10cSrcweir }
1011cdf0e10cSrcweir
1012cdf0e10cSrcweir return( pObj ? ( pObj->IsActive() ? pObj : NULL ) : NULL );
1013cdf0e10cSrcweir }
1014cdf0e10cSrcweir
1015cdf0e10cSrcweir
1016cdf0e10cSrcweir /******************************************************************************
1017cdf0e10cSrcweir |*
1018cdf0e10cSrcweir |*
1019cdf0e10cSrcweir |*
1020cdf0e10cSrcweir \******************************************************************************/
1021cdf0e10cSrcweir
GetBoundRect() const1022cdf0e10cSrcweir Rectangle ImageMap::GetBoundRect() const
1023cdf0e10cSrcweir {
1024cdf0e10cSrcweir Rectangle aBoundRect;
1025cdf0e10cSrcweir sal_uLong nCount = maList.Count();
1026cdf0e10cSrcweir
1027cdf0e10cSrcweir for ( sal_uLong i = 0; i < nCount; i++ )
1028cdf0e10cSrcweir aBoundRect.Union( ( (IMapObject*) maList.GetObject( i ) )->GetBoundRect() );
1029cdf0e10cSrcweir
1030cdf0e10cSrcweir return aBoundRect;
1031cdf0e10cSrcweir }
1032cdf0e10cSrcweir
1033cdf0e10cSrcweir
1034cdf0e10cSrcweir /******************************************************************************
1035cdf0e10cSrcweir |*
1036cdf0e10cSrcweir |*
1037cdf0e10cSrcweir |*
1038cdf0e10cSrcweir \******************************************************************************/
1039cdf0e10cSrcweir
Scale(const Fraction & rFracX,const Fraction & rFracY)1040cdf0e10cSrcweir void ImageMap::Scale( const Fraction& rFracX, const Fraction& rFracY )
1041cdf0e10cSrcweir {
1042cdf0e10cSrcweir sal_uInt16 nCount = (sal_uInt16) maList.Count();
1043cdf0e10cSrcweir
1044cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < nCount; i++ )
1045cdf0e10cSrcweir {
1046cdf0e10cSrcweir IMapObject* pObj = GetIMapObject( i );
1047cdf0e10cSrcweir
1048cdf0e10cSrcweir switch( pObj->GetType() )
1049cdf0e10cSrcweir {
1050cdf0e10cSrcweir case( IMAP_OBJ_RECTANGLE ):
1051cdf0e10cSrcweir ( (IMapRectangleObject*) pObj )->Scale( rFracX, rFracY );
1052cdf0e10cSrcweir break;
1053cdf0e10cSrcweir
1054cdf0e10cSrcweir case( IMAP_OBJ_CIRCLE ):
1055cdf0e10cSrcweir ( (IMapCircleObject*) pObj )->Scale( rFracX, rFracY );
1056cdf0e10cSrcweir break;
1057cdf0e10cSrcweir
1058cdf0e10cSrcweir case( IMAP_OBJ_POLYGON ):
1059cdf0e10cSrcweir ( (IMapPolygonObject*) pObj )->Scale( rFracX, rFracY );
1060cdf0e10cSrcweir break;
1061cdf0e10cSrcweir
1062cdf0e10cSrcweir default:
1063cdf0e10cSrcweir break;
1064cdf0e10cSrcweir }
1065cdf0e10cSrcweir }
1066cdf0e10cSrcweir }
1067cdf0e10cSrcweir
1068cdf0e10cSrcweir
1069cdf0e10cSrcweir /******************************************************************************
1070cdf0e10cSrcweir |*
1071cdf0e10cSrcweir |* Objekte nacheinander wegschreiben
1072cdf0e10cSrcweir |*
1073cdf0e10cSrcweir \******************************************************************************/
1074cdf0e10cSrcweir
ImpWriteImageMap(SvStream & rOStm,const String & rBaseURL) const1075cdf0e10cSrcweir void ImageMap::ImpWriteImageMap( SvStream& rOStm, const String& rBaseURL ) const
1076cdf0e10cSrcweir {
1077cdf0e10cSrcweir IMapObject* pObj;
1078cdf0e10cSrcweir sal_uInt16 nCount = (sal_uInt16) maList.Count();
1079cdf0e10cSrcweir
1080cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < nCount; i++ )
1081cdf0e10cSrcweir {
1082cdf0e10cSrcweir pObj = (IMapObject*) maList.GetObject( i );
1083cdf0e10cSrcweir pObj->Write( rOStm, rBaseURL );
1084cdf0e10cSrcweir }
1085cdf0e10cSrcweir }
1086cdf0e10cSrcweir
1087cdf0e10cSrcweir
1088cdf0e10cSrcweir /******************************************************************************
1089cdf0e10cSrcweir |*
1090cdf0e10cSrcweir |* Objekte nacheinander lesen
1091cdf0e10cSrcweir |*
1092cdf0e10cSrcweir \******************************************************************************/
1093cdf0e10cSrcweir
ImpReadImageMap(SvStream & rIStm,sal_uInt16 nCount,const String & rBaseURL)1094cdf0e10cSrcweir void ImageMap::ImpReadImageMap( SvStream& rIStm, sal_uInt16 nCount, const String& rBaseURL )
1095cdf0e10cSrcweir {
1096cdf0e10cSrcweir // neue Objekte einlesen
1097cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < nCount; i++ )
1098cdf0e10cSrcweir {
1099cdf0e10cSrcweir sal_uInt16 nType;
1100cdf0e10cSrcweir
1101cdf0e10cSrcweir rIStm >> nType;
1102cdf0e10cSrcweir rIStm.SeekRel( -2 );
1103cdf0e10cSrcweir
1104cdf0e10cSrcweir switch( nType )
1105cdf0e10cSrcweir {
1106cdf0e10cSrcweir case ( IMAP_OBJ_RECTANGLE ):
1107cdf0e10cSrcweir {
1108cdf0e10cSrcweir IMapRectangleObject* pObj = new IMapRectangleObject;
1109cdf0e10cSrcweir pObj->Read( rIStm, rBaseURL );
1110cdf0e10cSrcweir maList.Insert( pObj, LIST_APPEND );
1111cdf0e10cSrcweir }
1112cdf0e10cSrcweir break;
1113cdf0e10cSrcweir
1114cdf0e10cSrcweir case ( IMAP_OBJ_CIRCLE ):
1115cdf0e10cSrcweir {
1116cdf0e10cSrcweir IMapCircleObject* pObj = new IMapCircleObject;
1117cdf0e10cSrcweir pObj->Read( rIStm, rBaseURL );
1118cdf0e10cSrcweir maList.Insert( pObj, LIST_APPEND );
1119cdf0e10cSrcweir }
1120cdf0e10cSrcweir break;
1121cdf0e10cSrcweir
1122cdf0e10cSrcweir case ( IMAP_OBJ_POLYGON ):
1123cdf0e10cSrcweir {
1124cdf0e10cSrcweir IMapPolygonObject* pObj = new IMapPolygonObject;
1125cdf0e10cSrcweir pObj->Read( rIStm, rBaseURL );
1126cdf0e10cSrcweir maList.Insert( pObj, LIST_APPEND );
1127cdf0e10cSrcweir }
1128cdf0e10cSrcweir break;
1129cdf0e10cSrcweir
1130cdf0e10cSrcweir default:
1131cdf0e10cSrcweir break;
1132cdf0e10cSrcweir }
1133cdf0e10cSrcweir }
1134cdf0e10cSrcweir }
1135cdf0e10cSrcweir
1136cdf0e10cSrcweir
1137cdf0e10cSrcweir /******************************************************************************
1138cdf0e10cSrcweir |*
1139cdf0e10cSrcweir |* Binaer speichern
1140cdf0e10cSrcweir |*
1141cdf0e10cSrcweir \******************************************************************************/
1142cdf0e10cSrcweir
Write(SvStream & rOStm,const String & rBaseURL) const1143cdf0e10cSrcweir void ImageMap::Write( SvStream& rOStm, const String& rBaseURL ) const
1144cdf0e10cSrcweir {
1145cdf0e10cSrcweir IMapCompat* pCompat;
1146cdf0e10cSrcweir String aImageName( GetName() );
1147cdf0e10cSrcweir String aDummy;
1148cdf0e10cSrcweir sal_uInt16 nOldFormat = rOStm.GetNumberFormatInt();
1149cdf0e10cSrcweir sal_uInt16 nCount = (sal_uInt16) GetIMapObjectCount();
1150cdf0e10cSrcweir const rtl_TextEncoding eEncoding = gsl_getSystemTextEncoding();
1151cdf0e10cSrcweir
1152cdf0e10cSrcweir rOStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
1153cdf0e10cSrcweir
1154cdf0e10cSrcweir // MagicCode schreiben
1155cdf0e10cSrcweir rOStm << IMAPMAGIC;
1156cdf0e10cSrcweir rOStm << GetVersion();
1157cdf0e10cSrcweir rOStm.WriteByteString( ByteString( aImageName, eEncoding ) );
1158cdf0e10cSrcweir rOStm.WriteByteString( ByteString( aDummy, eEncoding ) );
1159cdf0e10cSrcweir rOStm << nCount;
1160cdf0e10cSrcweir rOStm.WriteByteString( ByteString( aImageName, eEncoding ) );
1161cdf0e10cSrcweir
1162cdf0e10cSrcweir pCompat = new IMapCompat( rOStm, STREAM_WRITE );
1163cdf0e10cSrcweir
1164cdf0e10cSrcweir // hier kann in neueren Versionen eingefuegt werden
1165cdf0e10cSrcweir
1166cdf0e10cSrcweir delete pCompat;
1167cdf0e10cSrcweir
1168cdf0e10cSrcweir ImpWriteImageMap( rOStm, rBaseURL );
1169cdf0e10cSrcweir
1170cdf0e10cSrcweir rOStm.SetNumberFormatInt( nOldFormat );
1171cdf0e10cSrcweir }
1172cdf0e10cSrcweir
1173cdf0e10cSrcweir
1174cdf0e10cSrcweir /******************************************************************************
1175cdf0e10cSrcweir |*
1176cdf0e10cSrcweir |* Binaer laden
1177cdf0e10cSrcweir |*
1178cdf0e10cSrcweir \******************************************************************************/
1179cdf0e10cSrcweir
Read(SvStream & rIStm,const String & rBaseURL)1180cdf0e10cSrcweir void ImageMap::Read( SvStream& rIStm, const String& rBaseURL )
1181cdf0e10cSrcweir {
1182cdf0e10cSrcweir ByteString aString;
1183cdf0e10cSrcweir char cMagic[6];
1184cdf0e10cSrcweir sal_uInt16 nOldFormat = rIStm.GetNumberFormatInt();
1185cdf0e10cSrcweir sal_uInt16 nCount;
1186cdf0e10cSrcweir
1187cdf0e10cSrcweir rIStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
1188cdf0e10cSrcweir rIStm.Read( cMagic, sizeof( cMagic ) );
1189cdf0e10cSrcweir
1190cdf0e10cSrcweir if ( !memcmp( cMagic, IMAPMAGIC, sizeof( cMagic ) ) )
1191cdf0e10cSrcweir {
1192cdf0e10cSrcweir IMapCompat* pCompat;
1193cdf0e10cSrcweir
1194cdf0e10cSrcweir // alten Inhalt loeschen
1195cdf0e10cSrcweir ClearImageMap();
1196cdf0e10cSrcweir
1197cdf0e10cSrcweir // Version ueberlesen wir
1198cdf0e10cSrcweir rIStm.SeekRel( 2 );
1199cdf0e10cSrcweir
1200cdf0e10cSrcweir rIStm.ReadByteString( aString ); aName = String( aString, gsl_getSystemTextEncoding() );
1201cdf0e10cSrcweir rIStm.ReadByteString( aString ); // Dummy
1202cdf0e10cSrcweir rIStm >> nCount;
1203cdf0e10cSrcweir rIStm.ReadByteString( aString ); // Dummy
1204cdf0e10cSrcweir
1205cdf0e10cSrcweir pCompat = new IMapCompat( rIStm, STREAM_READ );
1206cdf0e10cSrcweir
1207cdf0e10cSrcweir // hier kann in neueren Versionen gelesen werden
1208cdf0e10cSrcweir
1209cdf0e10cSrcweir delete pCompat;
1210cdf0e10cSrcweir ImpReadImageMap( rIStm, nCount, rBaseURL );
1211cdf0e10cSrcweir
1212cdf0e10cSrcweir }
1213cdf0e10cSrcweir else
1214cdf0e10cSrcweir rIStm.SetError( SVSTREAM_GENERALERROR );
1215cdf0e10cSrcweir
1216cdf0e10cSrcweir rIStm.SetNumberFormatInt( nOldFormat );
1217cdf0e10cSrcweir }
1218cdf0e10cSrcweir
1219