Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <tools/urlobj.hxx>
31 : : #include <vcl/svapp.hxx>
32 : : #include <vcl/mapmod.hxx>
33 : : #include <vcl/window.hxx>
34 : :
35 : : #include "svl/urihelper.hxx"
36 : : #include <svtools/imap.hxx>
37 : : #include <svtools/imapobj.hxx>
38 : : #include <svtools/imapcirc.hxx>
39 : : #include <svtools/imaprect.hxx>
40 : : #include <svtools/imappoly.hxx>
41 : :
42 : : #include <string.h>
43 : : #include <math.h>
44 : :
45 : : DBG_NAME( ImageMap )
46 : :
47 : :
48 : : #define SCALEPOINT(aPT,aFracX,aFracY) (aPT).X()=((aPT).X()*(aFracX).GetNumerator())/(aFracX).GetDenominator(); \
49 : : (aPT).Y()=((aPT).Y()*(aFracY).GetNumerator())/(aFracY).GetDenominator();
50 : :
51 : :
52 : : /******************************************************************************/
53 : :
54 : : sal_uInt16 IMapObject::nActualTextEncoding = (sal_uInt16) RTL_TEXTENCODING_DONTKNOW;
55 : :
56 : : /******************************************************************************/
57 : :
58 : :
59 : 0 : IMapObject::IMapObject()
60 : : : bActive( false )
61 [ # # ][ # # ]: 0 : , nReadVersion( 0 )
[ # # ][ # # ]
[ # # ]
62 : : {
63 : 0 : }
64 : :
65 : 2 : IMapObject::IMapObject( const String& rURL, const String& rAltText, const String& rDesc,
66 : : const String& rTarget, const String& rName, sal_Bool bURLActive )
67 : : : aURL( rURL )
68 : : , aAltText( rAltText )
69 : : , aDesc( rDesc )
70 : : , aTarget( rTarget )
71 : : , aName( rName )
72 : : , bActive( bURLActive )
73 [ + - ][ + - ]: 2 : , nReadVersion( 0 )
[ + - ][ + - ]
[ + - ]
74 : : {
75 : 2 : }
76 : :
77 : :
78 : : /******************************************************************************
79 : : |*
80 : : |* Freigabe des internen Speichers
81 : : |*
82 : : \******************************************************************************/
83 : :
84 : 0 : sal_uInt16 IMapObject::GetVersion() const
85 : : {
86 : 0 : return IMAP_OBJ_VERSION;
87 : : }
88 : :
89 : 0 : void IMapObject::Write( SvStream& rOStm, const String& rBaseURL ) const
90 : : {
91 : : IMapCompat* pCompat;
92 [ # # ]: 0 : const rtl_TextEncoding eEncoding = osl_getThreadTextEncoding();
93 : :
94 [ # # ][ # # ]: 0 : rOStm << GetType();
95 [ # # ][ # # ]: 0 : rOStm << GetVersion();
96 [ # # ]: 0 : rOStm << ( (sal_uInt16) eEncoding );
97 : :
98 : : const rtl::OString aRelURL = rtl::OUStringToOString(
99 [ # # ][ # # ]: 0 : URIHelper::simpleNormalizedMakeRelative(rBaseURL, aURL), eEncoding);
[ # # ][ # # ]
100 [ # # ]: 0 : write_lenPrefixed_uInt8s_FromOString<sal_uInt16>(rOStm, aRelURL);
101 [ # # ][ # # ]: 0 : write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOStm, aAltText, eEncoding);
102 [ # # ]: 0 : rOStm << bActive;
103 [ # # ][ # # ]: 0 : write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOStm, aTarget, eEncoding);
104 : :
105 [ # # ][ # # ]: 0 : pCompat = new IMapCompat( rOStm, STREAM_WRITE );
106 : :
107 [ # # ]: 0 : WriteIMapObject( rOStm );
108 [ # # ]: 0 : aEventList.Write( rOStm ); // V4
109 [ # # ][ # # ]: 0 : write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOStm, aName, eEncoding); // V5
110 : :
111 [ # # ][ # # ]: 0 : delete pCompat;
112 : 0 : }
113 : :
114 : :
115 : : /******************************************************************************
116 : : |*
117 : : |* Binaer-Import
118 : : |*
119 : : \******************************************************************************/
120 : :
121 : 0 : void IMapObject::Read( SvStream& rIStm, const String& rBaseURL )
122 : : {
123 : : IMapCompat* pCompat;
124 : : rtl_TextEncoding nTextEncoding;
125 : :
126 : : // Typ und Version ueberlesen wir
127 [ # # ]: 0 : rIStm.SeekRel( 2 );
128 [ # # ]: 0 : rIStm >> nReadVersion;
129 [ # # ]: 0 : rIStm >> nTextEncoding;
130 [ # # ][ # # ]: 0 : aURL = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rIStm, nTextEncoding);
131 [ # # ][ # # ]: 0 : aAltText = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rIStm, nTextEncoding);
132 [ # # ]: 0 : rIStm >> bActive;
133 [ # # ][ # # ]: 0 : aTarget = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rIStm, nTextEncoding);
134 : :
135 : : // URL absolut machen
136 [ # # ][ # # ]: 0 : aURL = URIHelper::SmartRel2Abs( INetURLObject(rBaseURL), aURL, URIHelper::GetMaybeFileHdl(), true, false, INetURLObject::WAS_ENCODED, INetURLObject::DECODE_UNAMBIGUOUS );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
137 [ # # ][ # # ]: 0 : pCompat = new IMapCompat( rIStm, STREAM_READ );
138 : :
139 [ # # ]: 0 : ReadIMapObject( rIStm );
140 : :
141 : : // ab Version 4 lesen wir eine EventListe
142 [ # # ]: 0 : if ( nReadVersion >= 0x0004 )
143 : : {
144 [ # # ]: 0 : aEventList.Read(rIStm);
145 : :
146 : : // ab Version 5 kann ein Objektname vorhanden sein
147 [ # # ]: 0 : if ( nReadVersion >= 0x0005 )
148 [ # # ][ # # ]: 0 : aName = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rIStm, nTextEncoding);
149 : : }
150 : :
151 [ # # ][ # # ]: 0 : delete pCompat;
152 : 0 : }
153 : :
154 : 2 : sal_Bool IMapObject::IsEqual( const IMapObject& rEqObj )
155 : : {
156 : 2 : return ( ( aURL == rEqObj.aURL ) &&
157 : 2 : ( aAltText == rEqObj.aAltText ) &&
158 : 2 : ( aDesc == rEqObj.aDesc ) &&
159 : 2 : ( aTarget == rEqObj.aTarget ) &&
160 : 2 : ( aName == rEqObj.aName ) &&
161 [ + - ][ + - : 10 : ( bActive == rEqObj.bActive ) );
+ - + - +
- + - ]
162 : : }
163 : :
164 : 2 : IMapRectangleObject::IMapRectangleObject( const Rectangle& rRect,
165 : : const String& rURL,
166 : : const String& rAltText,
167 : : const String& rDesc,
168 : : const String& rTarget,
169 : : const String& rName,
170 : : sal_Bool bURLActive,
171 : : sal_Bool bPixelCoords ) :
172 [ + - ]: 2 : IMapObject ( rURL, rAltText, rDesc, rTarget, rName, bURLActive )
173 : : {
174 [ + - ]: 2 : ImpConstruct( rRect, bPixelCoords );
175 : 2 : }
176 : :
177 : 2 : void IMapRectangleObject::ImpConstruct( const Rectangle& rRect, sal_Bool bPixel )
178 : : {
179 [ - + ]: 2 : if ( bPixel )
180 [ # # ][ # # ]: 0 : aRect = Application::GetDefaultDevice()->PixelToLogic( rRect, MapMode( MAP_100TH_MM ) );
181 : : else
182 : 2 : aRect = rRect;
183 : 2 : }
184 : :
185 : :
186 : : /******************************************************************************
187 : : |*
188 : : |* Binaer-Export
189 : : |*
190 : : \******************************************************************************/
191 : :
192 : 0 : void IMapRectangleObject::WriteIMapObject( SvStream& rOStm ) const
193 : : {
194 : 0 : rOStm << aRect;
195 : 0 : }
196 : :
197 : :
198 : : /******************************************************************************
199 : : |*
200 : : |* Binaer-Import
201 : : |*
202 : : \******************************************************************************/
203 : :
204 : 0 : void IMapRectangleObject::ReadIMapObject( SvStream& rIStm )
205 : : {
206 : 0 : rIStm >> aRect;
207 : 0 : }
208 : :
209 : :
210 : : /******************************************************************************
211 : : |*
212 : : |* Typ-Rueckgabe
213 : : |*
214 : : \******************************************************************************/
215 : :
216 : 18 : sal_uInt16 IMapRectangleObject::GetType() const
217 : : {
218 : 18 : return IMAP_OBJ_RECTANGLE;
219 : : }
220 : :
221 : :
222 : : /******************************************************************************
223 : : |*
224 : : |* Hit-Test
225 : : |*
226 : : \******************************************************************************/
227 : :
228 : 0 : sal_Bool IMapRectangleObject::IsHit( const Point& rPoint ) const
229 : : {
230 : 0 : return aRect.IsInside( rPoint );
231 : : }
232 : :
233 : 2 : Rectangle IMapRectangleObject::GetRectangle( sal_Bool bPixelCoords ) const
234 : : {
235 : 2 : Rectangle aNewRect;
236 : :
237 [ - + ]: 2 : if ( bPixelCoords )
238 [ # # ][ # # ]: 0 : aNewRect = Application::GetDefaultDevice()->LogicToPixel( aRect, MapMode( MAP_100TH_MM ) );
239 : : else
240 : 2 : aNewRect = aRect;
241 : :
242 : 2 : return aNewRect;
243 : : }
244 : :
245 : 2 : void IMapRectangleObject::Scale( const Fraction& rFracX, const Fraction& rFracY )
246 : : {
247 : 2 : Point aTL( aRect.TopLeft() );
248 [ + - ]: 2 : Point aBR( aRect.BottomRight() );
249 : :
250 [ + - ][ + - ]: 2 : if ( rFracX.GetDenominator() && rFracY.GetDenominator() )
[ + - ]
251 : : {
252 : 2 : SCALEPOINT( aTL, rFracX, rFracY );
253 : 2 : SCALEPOINT( aBR, rFracX, rFracY );
254 : : }
255 : :
256 [ + - ]: 2 : aRect = Rectangle( aTL, aBR );
257 : 2 : }
258 : :
259 : 2 : sal_Bool IMapRectangleObject::IsEqual( const IMapRectangleObject& rEqObj )
260 : : {
261 [ + - ][ + - ]: 2 : return ( IMapObject::IsEqual( rEqObj ) && ( aRect == rEqObj.aRect ) );
262 : : }
263 : :
264 : 0 : IMapCircleObject::IMapCircleObject( const Point& rCenter, sal_uLong nCircleRadius,
265 : : const String& rURL,
266 : : const String& rAltText,
267 : : const String& rDesc,
268 : : const String& rTarget,
269 : : const String& rName,
270 : : sal_Bool bURLActive,
271 : : sal_Bool bPixelCoords ) :
272 : 0 : IMapObject ( rURL, rAltText, rDesc, rTarget, rName, bURLActive )
273 : : {
274 [ # # ]: 0 : ImpConstruct( rCenter, nCircleRadius, bPixelCoords );
275 : 0 : }
276 : :
277 : 0 : void IMapCircleObject::ImpConstruct( const Point& rCenter, sal_uLong nRad, sal_Bool bPixel )
278 : : {
279 [ # # ]: 0 : if ( bPixel )
280 : : {
281 [ # # ]: 0 : MapMode aMap100( MAP_100TH_MM );
282 : :
283 [ # # ][ # # ]: 0 : aCenter = Application::GetDefaultDevice()->PixelToLogic( rCenter, aMap100 );
284 [ # # ][ # # ]: 0 : nRadius = Application::GetDefaultDevice()->PixelToLogic( Size( nRad, 0 ), aMap100 ).Width();
[ # # ]
285 : : }
286 : : else
287 : : {
288 : 0 : aCenter = rCenter;
289 : 0 : nRadius = nRad;
290 : : }
291 : 0 : }
292 : :
293 : :
294 : : /******************************************************************************
295 : : |*
296 : : |* Binaer-Export
297 : : |*
298 : : \******************************************************************************/
299 : :
300 : 0 : void IMapCircleObject::WriteIMapObject( SvStream& rOStm ) const
301 : : {
302 : 0 : sal_uInt32 nTmp = nRadius;
303 : :
304 : 0 : rOStm << aCenter;
305 : 0 : rOStm << nTmp;
306 : 0 : }
307 : :
308 : :
309 : : /******************************************************************************
310 : : |*
311 : : |* Binaer-Import
312 : : |*
313 : : \******************************************************************************/
314 : :
315 : 0 : void IMapCircleObject::ReadIMapObject( SvStream& rIStm )
316 : : {
317 : : sal_uInt32 nTmp;
318 : :
319 [ # # ]: 0 : rIStm >> aCenter;
320 [ # # ]: 0 : rIStm >> nTmp;
321 : :
322 : 0 : nRadius = nTmp;
323 : 0 : }
324 : :
325 : :
326 : : /******************************************************************************
327 : : |*
328 : : |* Typ-Rueckgabe
329 : : |*
330 : : \******************************************************************************/
331 : :
332 : 0 : sal_uInt16 IMapCircleObject::GetType() const
333 : : {
334 : 0 : return IMAP_OBJ_CIRCLE;
335 : : }
336 : :
337 : :
338 : : /******************************************************************************
339 : : |*
340 : : |* Hit-Test
341 : : |*
342 : : \******************************************************************************/
343 : :
344 : 0 : sal_Bool IMapCircleObject::IsHit( const Point& rPoint ) const
345 : : {
346 : 0 : const Point aPoint( aCenter - rPoint );
347 : 0 : sal_Bool bRet = sal_False;
348 : :
349 [ # # ]: 0 : if ( (sal_Int32) sqrt( (double) aPoint.X() * aPoint.X() +
350 : 0 : aPoint.Y() * aPoint.Y() ) <= nRadius )
351 : : {
352 : 0 : bRet = sal_True;
353 : : }
354 : :
355 : 0 : return bRet;
356 : : }
357 : :
358 : 0 : Point IMapCircleObject::GetCenter( sal_Bool bPixelCoords ) const
359 : : {
360 : 0 : Point aNewPoint;
361 : :
362 [ # # ]: 0 : if ( bPixelCoords )
363 [ # # ][ # # ]: 0 : aNewPoint = Application::GetDefaultDevice()->LogicToPixel( aCenter, MapMode( MAP_100TH_MM ) );
364 : : else
365 : 0 : aNewPoint = aCenter;
366 : :
367 : 0 : return aNewPoint;
368 : : }
369 : :
370 : 0 : sal_uLong IMapCircleObject::GetRadius( sal_Bool bPixelCoords ) const
371 : : {
372 : : sal_uLong nNewRadius;
373 : :
374 [ # # ]: 0 : if ( bPixelCoords )
375 [ # # ][ # # ]: 0 : nNewRadius = Application::GetDefaultDevice()->LogicToPixel( Size( nRadius, 0 ), MapMode( MAP_100TH_MM ) ).Width();
376 : : else
377 : 0 : nNewRadius = nRadius;
378 : :
379 : 0 : return nNewRadius;
380 : : }
381 : :
382 : 0 : Rectangle IMapCircleObject::GetBoundRect() const
383 : : {
384 : 0 : long nWidth = nRadius << 1;
385 : :
386 : 0 : return Rectangle( Point( aCenter.X() - nRadius, aCenter.Y() - nRadius ),
387 [ # # ]: 0 : Size( nWidth, nWidth ) );
388 : : }
389 : :
390 : 0 : void IMapCircleObject::Scale( const Fraction& rFracX, const Fraction& rFracY )
391 : : {
392 [ # # ]: 0 : Fraction aAverage( rFracX );
393 : :
394 [ # # ]: 0 : aAverage += rFracY;
395 [ # # ][ # # ]: 0 : aAverage *= Fraction( 1, 2 );
396 : :
397 [ # # ][ # # ]: 0 : if ( rFracX.GetDenominator() && rFracY.GetDenominator() )
[ # # ]
398 : : {
399 : 0 : SCALEPOINT( aCenter, rFracX, rFracY );
400 : : }
401 : :
402 : 0 : nRadius = ( nRadius * aAverage.GetNumerator() ) / aAverage.GetDenominator();
403 : 0 : }
404 : :
405 : 0 : sal_Bool IMapCircleObject::IsEqual( const IMapCircleObject& rEqObj )
406 : : {
407 : 0 : return ( IMapObject::IsEqual( rEqObj ) &&
408 : 0 : ( aCenter == rEqObj.aCenter ) &&
409 [ # # ]: 0 : ( nRadius == rEqObj.nRadius ) );
[ # # # # ]
410 : : }
411 : :
412 : 0 : IMapPolygonObject::IMapPolygonObject( const Polygon& rPoly,
413 : : const String& rURL,
414 : : const String& rAltText,
415 : : const String& rDesc,
416 : : const String& rTarget,
417 : : const String& rName,
418 : : sal_Bool bURLActive,
419 : : sal_Bool bPixelCoords ) :
420 : : IMapObject ( rURL, rAltText, rDesc, rTarget, rName, bURLActive ),
421 [ # # ][ # # ]: 0 : bEllipse ( sal_False )
422 : : {
423 [ # # ]: 0 : ImpConstruct( rPoly, bPixelCoords );
424 : 0 : }
425 : :
426 : 0 : void IMapPolygonObject::ImpConstruct( const Polygon& rPoly, sal_Bool bPixel )
427 : : {
428 [ # # ]: 0 : if ( bPixel )
429 [ # # ][ # # ]: 0 : aPoly = Application::GetDefaultDevice()->PixelToLogic( rPoly, MapMode( MAP_100TH_MM ) );
[ # # ][ # # ]
430 : : else
431 : 0 : aPoly = rPoly;
432 : 0 : }
433 : :
434 : :
435 : : /******************************************************************************
436 : : |*
437 : : |* Binaer-Export
438 : : |*
439 : : \******************************************************************************/
440 : :
441 : 0 : void IMapPolygonObject::WriteIMapObject( SvStream& rOStm ) const
442 : : {
443 : 0 : rOStm << aPoly;
444 : 0 : rOStm << bEllipse; // >= Version 2
445 : 0 : rOStm << aEllipse; // >= Version 2
446 : 0 : }
447 : :
448 : :
449 : : /******************************************************************************
450 : : |*
451 : : |* Binaer-Import
452 : : |*
453 : : \******************************************************************************/
454 : :
455 : 0 : void IMapPolygonObject::ReadIMapObject( SvStream& rIStm )
456 : : {
457 : 0 : rIStm >> aPoly;
458 : :
459 : : // Version >= 2 hat zusaetzlich Ellipsen-Information
460 [ # # ]: 0 : if ( nReadVersion >= 2 )
461 : : {
462 : 0 : rIStm >> bEllipse;
463 : 0 : rIStm >> aEllipse;
464 : : }
465 : 0 : }
466 : :
467 : :
468 : : /******************************************************************************
469 : : |*
470 : : |* Typ-Rueckgabe
471 : : |*
472 : : \******************************************************************************/
473 : :
474 : 0 : sal_uInt16 IMapPolygonObject::GetType() const
475 : : {
476 : 0 : return IMAP_OBJ_POLYGON;
477 : : }
478 : :
479 : :
480 : : /******************************************************************************
481 : : |*
482 : : |* Hit-Test
483 : : |*
484 : : \******************************************************************************/
485 : :
486 : 0 : sal_Bool IMapPolygonObject::IsHit( const Point& rPoint ) const
487 : : {
488 : 0 : return aPoly.IsInside( rPoint );
489 : : }
490 : :
491 : 0 : Polygon IMapPolygonObject::GetPolygon( sal_Bool bPixelCoords ) const
492 : : {
493 : 0 : Polygon aNewPoly;
494 : :
495 [ # # ]: 0 : if ( bPixelCoords )
496 [ # # ][ # # ]: 0 : aNewPoly = Application::GetDefaultDevice()->LogicToPixel( aPoly, MapMode( MAP_100TH_MM ) );
[ # # ][ # # ]
[ # # ][ # # ]
497 : : else
498 [ # # ]: 0 : aNewPoly = aPoly;
499 : :
500 : 0 : return aNewPoly;
501 : : }
502 : :
503 : 0 : void IMapPolygonObject::SetExtraEllipse( const Rectangle& rEllipse )
504 : : {
505 [ # # ]: 0 : if ( aPoly.GetSize() )
506 : : {
507 : 0 : bEllipse = sal_True;
508 : 0 : aEllipse = rEllipse;
509 : : }
510 : 0 : }
511 : :
512 : 0 : void IMapPolygonObject::Scale( const Fraction& rFracX, const Fraction& rFracY )
513 : : {
514 : 0 : sal_uInt16 nCount = aPoly.GetSize();
515 : :
516 [ # # ]: 0 : for ( sal_uInt16 i = 0; i < nCount; i++ )
517 : : {
518 [ # # ]: 0 : Point aScaledPt( aPoly[ i ] );
519 : :
520 [ # # ][ # # ]: 0 : if ( rFracX.GetDenominator() && rFracY.GetDenominator() )
[ # # ]
521 : : {
522 : 0 : SCALEPOINT( aScaledPt, rFracX, rFracY );
523 : : }
524 : :
525 [ # # ]: 0 : aPoly[ i ] = aScaledPt;
526 : : }
527 : :
528 [ # # ]: 0 : if ( bEllipse )
529 : : {
530 : 0 : Point aTL( aEllipse.TopLeft() );
531 [ # # ]: 0 : Point aBR( aEllipse.BottomRight() );
532 : :
533 [ # # ][ # # ]: 0 : if ( rFracX.GetDenominator() && rFracY.GetDenominator() )
[ # # ]
534 : : {
535 : 0 : SCALEPOINT( aTL, rFracX, rFracY );
536 : 0 : SCALEPOINT( aBR, rFracX, rFracY );
537 : : }
538 : :
539 [ # # ]: 0 : aEllipse = Rectangle( aTL, aBR );
540 : : }
541 : 0 : }
542 : :
543 : 0 : sal_Bool IMapPolygonObject::IsEqual( const IMapPolygonObject& rEqObj )
544 : : {
545 : 0 : sal_Bool bRet = sal_False;
546 : :
547 [ # # ]: 0 : if ( IMapObject::IsEqual( rEqObj ) )
548 : : {
549 : 0 : const Polygon& rEqPoly = rEqObj.aPoly;
550 : 0 : const sal_uInt16 nCount = aPoly.GetSize();
551 : 0 : const sal_uInt16 nEqCount = rEqPoly.GetSize();
552 : 0 : sal_Bool bDifferent = sal_False;
553 : :
554 [ # # ]: 0 : if ( nCount == nEqCount )
555 : : {
556 [ # # ]: 0 : for ( sal_uInt16 i = 0; i < nCount; i++ )
557 : : {
558 [ # # ]: 0 : if ( aPoly[ i ] != rEqPoly[ i ] )
559 : : {
560 : 0 : bDifferent = sal_True;
561 : 0 : break;
562 : : }
563 : : }
564 : :
565 [ # # ]: 0 : if ( !bDifferent )
566 : 0 : bRet = sal_True;
567 : : }
568 : : }
569 : :
570 : 0 : return bRet;
571 : : }
572 : :
573 : : /******************************************************************************
574 : : |*
575 : : |* Ctor
576 : : |*
577 : : \******************************************************************************/
578 : :
579 : 0 : ImageMap::ImageMap( const String& rName )
580 [ # # ]: 0 : : aName( rName )
581 : : {
582 : 0 : }
583 : :
584 : :
585 : : /******************************************************************************
586 : : |*
587 : : |* Copy-Ctor
588 : : |*
589 : : \******************************************************************************/
590 : :
591 [ + - ]: 4 : ImageMap::ImageMap( const ImageMap& rImageMap )
592 : : {
593 : : DBG_CTOR( ImageMap, NULL );
594 : :
595 : 4 : size_t nCount = rImageMap.GetIMapObjectCount();
596 : :
597 [ + + ]: 8 : for ( size_t i = 0; i < nCount; i++ )
598 : : {
599 [ + - ]: 4 : IMapObject* pCopyObj = rImageMap.GetIMapObject( i );
600 : :
601 [ + - ]: 4 : switch( pCopyObj->GetType() )
[ + - - - ]
602 : : {
603 : : case( IMAP_OBJ_RECTANGLE ):
604 [ + - ][ + - ]: 4 : maList.push_back( new IMapRectangleObject( *(IMapRectangleObject*) pCopyObj ) );
[ + - ]
605 : 4 : break;
606 : :
607 : : case( IMAP_OBJ_CIRCLE ):
608 [ # # ][ # # ]: 0 : maList.push_back( new IMapCircleObject( *(IMapCircleObject*) pCopyObj ) );
[ # # ]
609 : 0 : break;
610 : :
611 : : case( IMAP_OBJ_POLYGON ):
612 [ # # ][ # # ]: 0 : maList.push_back( new IMapPolygonObject( *(IMapPolygonObject*) pCopyObj ) );
[ # # ]
613 : 0 : break;
614 : :
615 : : default:
616 : 0 : break;
617 : : }
618 : : }
619 : :
620 [ + - ]: 4 : aName = rImageMap.aName;
621 : 4 : }
622 : :
623 : :
624 : : /******************************************************************************
625 : : |*
626 : : |* Dtor
627 : : |*
628 : : \******************************************************************************/
629 : :
630 [ + - ]: 8 : ImageMap::~ImageMap()
631 : : {
632 : : DBG_DTOR( ImageMap, NULL );
633 : :
634 [ + - ]: 8 : ClearImageMap();
635 [ - + ]: 14 : }
636 : :
637 : :
638 : : /******************************************************************************
639 : : |*
640 : : |* Freigabe des internen Speichers
641 : : |*
642 : : \******************************************************************************/
643 : :
644 : 10 : void ImageMap::ClearImageMap()
645 : : {
646 [ + + ]: 16 : for( size_t i = 0, n = maList.size(); i < n; ++i )
647 [ + - ]: 6 : delete maList[ i ];
648 : 10 : maList.clear();
649 : :
650 [ + - ]: 10 : aName = String();
651 : 10 : }
652 : :
653 : :
654 : : /******************************************************************************
655 : : |*
656 : : |* Zuweisungsoperator
657 : : |*
658 : : \******************************************************************************/
659 : :
660 : 0 : ImageMap& ImageMap::operator=( const ImageMap& rImageMap )
661 : : {
662 : 0 : size_t nCount = rImageMap.GetIMapObjectCount();
663 : :
664 : 0 : ClearImageMap();
665 : :
666 [ # # ]: 0 : for ( size_t i = 0; i < nCount; i++ )
667 : : {
668 : 0 : IMapObject* pCopyObj = rImageMap.GetIMapObject( i );
669 : :
670 [ # # # # ]: 0 : switch( pCopyObj->GetType() )
671 : : {
672 : : case( IMAP_OBJ_RECTANGLE ):
673 [ # # ][ # # ]: 0 : maList.push_back( new IMapRectangleObject( *(IMapRectangleObject*) pCopyObj ) );
674 : 0 : break;
675 : :
676 : : case( IMAP_OBJ_CIRCLE ):
677 [ # # ][ # # ]: 0 : maList.push_back( new IMapCircleObject( *(IMapCircleObject*) pCopyObj ) );
678 : 0 : break;
679 : :
680 : : case( IMAP_OBJ_POLYGON ):
681 [ # # ][ # # ]: 0 : maList.push_back( new IMapPolygonObject( *(IMapPolygonObject*) pCopyObj ) );
682 : 0 : break;
683 : :
684 : : default:
685 : 0 : break;
686 : : }
687 : : }
688 : :
689 : 0 : aName = rImageMap.aName;
690 : :
691 : 0 : return *this;
692 : : }
693 : :
694 : :
695 : : /******************************************************************************
696 : : |*
697 : : |* Vergleichsoperator I
698 : : |*
699 : : \******************************************************************************/
700 : :
701 : 2 : sal_Bool ImageMap::operator==( const ImageMap& rImageMap )
702 : : {
703 : 2 : const size_t nCount = maList.size();
704 : 2 : const size_t nEqCount = rImageMap.GetIMapObjectCount();
705 : 2 : sal_Bool bRet = sal_False;
706 : :
707 [ + - ]: 2 : if ( nCount == nEqCount )
708 : : {
709 : 2 : sal_Bool bDifferent = ( aName != rImageMap.aName );
710 : :
711 [ + + ][ + - ]: 4 : for ( size_t i = 0; ( i < nCount ) && !bDifferent; i++ )
[ + + ]
712 : : {
713 : 2 : IMapObject* pObj = maList[ i ];
714 : 2 : IMapObject* pEqObj = rImageMap.GetIMapObject( i );
715 : :
716 [ + - ]: 2 : if ( pObj->GetType() == pEqObj->GetType() )
717 : : {
718 [ + - - - ]: 2 : switch( pObj->GetType() )
719 : : {
720 : : case( IMAP_OBJ_RECTANGLE ):
721 : : {
722 [ - + ]: 2 : if ( !( (IMapRectangleObject*) pObj )->IsEqual( *(IMapRectangleObject*) pEqObj ) )
723 : 0 : bDifferent = sal_True;
724 : : }
725 : 2 : break;
726 : :
727 : : case( IMAP_OBJ_CIRCLE ):
728 : : {
729 [ # # ]: 0 : if ( !( (IMapCircleObject*) pObj )->IsEqual( *(IMapCircleObject*) pEqObj ) )
730 : 0 : bDifferent = sal_True;
731 : : }
732 : 0 : break;
733 : :
734 : : case( IMAP_OBJ_POLYGON ):
735 : : {
736 [ # # ]: 0 : if ( !( (IMapPolygonObject*) pObj )->IsEqual( *(IMapPolygonObject*) pEqObj ) )
737 : 0 : bDifferent = sal_True;
738 : : }
739 : 0 : break;
740 : :
741 : : default:
742 : 2 : break;
743 : : }
744 : : }
745 : : else
746 : 0 : bDifferent = sal_True;
747 : : }
748 : :
749 [ + - ]: 2 : if ( !bDifferent )
750 : 2 : bRet = sal_True;
751 : : }
752 : :
753 : 2 : return bRet;
754 : : }
755 : :
756 : :
757 : : /******************************************************************************
758 : : |*
759 : : |* Vergleichsoperator II
760 : : |*
761 : : \******************************************************************************/
762 : :
763 : 0 : sal_Bool ImageMap::operator!=( const ImageMap& rImageMap )
764 : : {
765 : 0 : return !( *this == rImageMap );
766 : : }
767 : :
768 : :
769 : : /******************************************************************************
770 : : |*
771 : : |* Freigabe des internen Speichers
772 : : |*
773 : : \******************************************************************************/
774 : :
775 : 0 : sal_uInt16 ImageMap::GetVersion() const
776 : : {
777 : 0 : return IMAGE_MAP_VERSION;
778 : : }
779 : :
780 : :
781 : : /******************************************************************************
782 : : |*
783 : : |* Einfuegen eines neuen Objekts
784 : : |*
785 : : \******************************************************************************/
786 : :
787 : 2 : void ImageMap::InsertIMapObject( const IMapObject& rIMapObject )
788 : : {
789 [ + - - - ]: 2 : switch( rIMapObject.GetType() )
790 : : {
791 : : case( IMAP_OBJ_RECTANGLE ):
792 [ + - ][ + - ]: 2 : maList.push_back( new IMapRectangleObject( (IMapRectangleObject&) rIMapObject ) );
793 : 2 : break;
794 : :
795 : : case( IMAP_OBJ_CIRCLE ):
796 [ # # ][ # # ]: 0 : maList.push_back( new IMapCircleObject( (IMapCircleObject&) rIMapObject ) );
797 : 0 : break;
798 : :
799 : : case( IMAP_OBJ_POLYGON ):
800 [ # # ][ # # ]: 0 : maList.push_back( new IMapPolygonObject( (IMapPolygonObject&) rIMapObject ) );
801 : 0 : break;
802 : :
803 : : default:
804 : 0 : break;
805 : : }
806 : 2 : }
807 : :
808 : :
809 : : /******************************************************************************
810 : : |*
811 : : |* Hit-Test
812 : : |*
813 : : \******************************************************************************/
814 : :
815 : 0 : IMapObject* ImageMap::GetHitIMapObject( const Size& rTotalSize,
816 : : const Size& rDisplaySize,
817 : : const Point& rRelHitPoint,
818 : : sal_uLong nFlags )
819 : : {
820 : 0 : Point aRelPoint( rTotalSize.Width() * rRelHitPoint.X() / rDisplaySize.Width(),
821 : 0 : rTotalSize.Height() * rRelHitPoint.Y() / rDisplaySize.Height() );
822 : :
823 : : // Falls Flags zur Spiegelung etc. angegeben sind, wird
824 : : // der zu pruefende Punkt vor der Pruefung entspr. transformiert
825 [ # # ]: 0 : if ( nFlags )
826 : : {
827 [ # # ]: 0 : if ( nFlags & IMAP_MIRROR_HORZ )
828 : 0 : aRelPoint.X() = rTotalSize.Width() - aRelPoint.X();
829 : :
830 [ # # ]: 0 : if ( nFlags & IMAP_MIRROR_VERT )
831 : 0 : aRelPoint.Y() = rTotalSize.Height() - aRelPoint.Y();
832 : : }
833 : :
834 : : // Alle Objekte durchlaufen und HitTest ausfuehren
835 : 0 : IMapObject* pObj = NULL;
836 [ # # ]: 0 : for( size_t i = 0, n = maList.size(); i < n; ++i ) {
837 [ # # ][ # # ]: 0 : if ( maList[ i ]->IsHit( aRelPoint ) ) {
838 : 0 : pObj = maList[ i ];
839 : 0 : break;
840 : : }
841 : : }
842 : :
843 [ # # ][ # # ]: 0 : return( pObj ? ( pObj->IsActive() ? pObj : NULL ) : NULL );
844 : : }
845 : :
846 : 2 : void ImageMap::Scale( const Fraction& rFracX, const Fraction& rFracY )
847 : : {
848 : 2 : size_t nCount = maList.size();
849 : :
850 [ + + ]: 4 : for ( size_t i = 0; i < nCount; i++ )
851 : : {
852 : 2 : IMapObject* pObj = maList[ i ];
853 : :
854 [ + - - - ]: 2 : switch( pObj->GetType() )
855 : : {
856 : : case( IMAP_OBJ_RECTANGLE ):
857 : 2 : ( (IMapRectangleObject*) pObj )->Scale( rFracX, rFracY );
858 : 2 : break;
859 : :
860 : : case( IMAP_OBJ_CIRCLE ):
861 : 0 : ( (IMapCircleObject*) pObj )->Scale( rFracX, rFracY );
862 : 0 : break;
863 : :
864 : : case( IMAP_OBJ_POLYGON ):
865 : 0 : ( (IMapPolygonObject*) pObj )->Scale( rFracX, rFracY );
866 : 0 : break;
867 : :
868 : : default:
869 : 0 : break;
870 : : }
871 : : }
872 : 2 : }
873 : :
874 : :
875 : : /******************************************************************************
876 : : |*
877 : : |* Objekte nacheinander wegschreiben
878 : : |*
879 : : \******************************************************************************/
880 : :
881 : 0 : void ImageMap::ImpWriteImageMap( SvStream& rOStm, const String& rBaseURL ) const
882 : : {
883 : : IMapObject* pObj;
884 : 0 : size_t nCount = maList.size();
885 : :
886 [ # # ]: 0 : for ( size_t i = 0; i < nCount; i++ )
887 : : {
888 : 0 : pObj = maList[ i ];
889 : 0 : pObj->Write( rOStm, rBaseURL );
890 : : }
891 : 0 : }
892 : :
893 : :
894 : : /******************************************************************************
895 : : |*
896 : : |* Objekte nacheinander lesen
897 : : |*
898 : : \******************************************************************************/
899 : :
900 : 0 : void ImageMap::ImpReadImageMap( SvStream& rIStm, size_t nCount, const String& rBaseURL )
901 : : {
902 : : // neue Objekte einlesen
903 [ # # ]: 0 : for ( size_t i = 0; i < nCount; i++ )
904 : : {
905 : : sal_uInt16 nType;
906 : :
907 [ # # ]: 0 : rIStm >> nType;
908 [ # # ]: 0 : rIStm.SeekRel( -2 );
909 : :
910 [ # # # # ]: 0 : switch( nType )
911 : : {
912 : : case ( IMAP_OBJ_RECTANGLE ):
913 : : {
914 [ # # ][ # # ]: 0 : IMapRectangleObject* pObj = new IMapRectangleObject;
915 [ # # ]: 0 : pObj->Read( rIStm, rBaseURL );
916 [ # # ]: 0 : maList.push_back( pObj );
917 : : }
918 : 0 : break;
919 : :
920 : : case ( IMAP_OBJ_CIRCLE ):
921 : : {
922 [ # # ][ # # ]: 0 : IMapCircleObject* pObj = new IMapCircleObject;
923 [ # # ]: 0 : pObj->Read( rIStm, rBaseURL );
924 [ # # ]: 0 : maList.push_back( pObj );
925 : : }
926 : 0 : break;
927 : :
928 : : case ( IMAP_OBJ_POLYGON ):
929 : : {
930 [ # # ][ # # ]: 0 : IMapPolygonObject* pObj = new IMapPolygonObject;
931 [ # # ]: 0 : pObj->Read( rIStm, rBaseURL );
932 [ # # ]: 0 : maList.push_back( pObj );
933 : : }
934 : 0 : break;
935 : :
936 : : default:
937 : 0 : break;
938 : : }
939 : : }
940 : 0 : }
941 : :
942 : :
943 : : /******************************************************************************
944 : : |*
945 : : |* Binaer speichern
946 : : |*
947 : : \******************************************************************************/
948 : :
949 : 0 : void ImageMap::Write( SvStream& rOStm, const String& rBaseURL ) const
950 : : {
951 : : IMapCompat* pCompat;
952 [ # # ]: 0 : String aImageName( GetName() );
953 : 0 : sal_uInt16 nOldFormat = rOStm.GetNumberFormatInt();
954 : 0 : sal_uInt16 nCount = (sal_uInt16) GetIMapObjectCount();
955 [ # # ]: 0 : const rtl_TextEncoding eEncoding = osl_getThreadTextEncoding(); //vomit!
956 : :
957 [ # # ]: 0 : rOStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
958 : :
959 : : // MagicCode schreiben
960 [ # # ]: 0 : rOStm << IMAPMAGIC;
961 [ # # ][ # # ]: 0 : rOStm << GetVersion();
962 [ # # ][ # # ]: 0 : write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOStm, aImageName, eEncoding);
963 [ # # ]: 0 : write_lenPrefixed_uInt8s_FromOString<sal_uInt16>(rOStm, rtl::OString()); //dummy
964 [ # # ]: 0 : rOStm << nCount;
965 [ # # ][ # # ]: 0 : write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOStm, aImageName, eEncoding);
966 : :
967 [ # # ][ # # ]: 0 : pCompat = new IMapCompat( rOStm, STREAM_WRITE );
968 : :
969 : : // hier kann in neueren Versionen eingefuegt werden
970 : :
971 [ # # ][ # # ]: 0 : delete pCompat;
972 : :
973 [ # # ]: 0 : ImpWriteImageMap( rOStm, rBaseURL );
974 : :
975 [ # # ][ # # ]: 0 : rOStm.SetNumberFormatInt( nOldFormat );
976 : 0 : }
977 : :
978 : :
979 : : /******************************************************************************
980 : : |*
981 : : |* Binaer laden
982 : : |*
983 : : \******************************************************************************/
984 : :
985 : 0 : void ImageMap::Read( SvStream& rIStm, const String& rBaseURL )
986 : : {
987 : : char cMagic[6];
988 : 0 : sal_uInt16 nOldFormat = rIStm.GetNumberFormatInt();
989 : : sal_uInt16 nCount;
990 : :
991 [ # # ]: 0 : rIStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
992 [ # # ]: 0 : rIStm.Read( cMagic, sizeof( cMagic ) );
993 : :
994 [ # # ]: 0 : if ( !memcmp( cMagic, IMAPMAGIC, sizeof( cMagic ) ) )
995 : : {
996 : : IMapCompat* pCompat;
997 : :
998 : : // alten Inhalt loeschen
999 [ # # ]: 0 : ClearImageMap();
1000 : :
1001 : : // Version ueberlesen wir
1002 [ # # ]: 0 : rIStm.SeekRel( 2 );
1003 : :
1004 [ # # ][ # # ]: 0 : aName = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rIStm, osl_getThreadTextEncoding());
[ # # ]
1005 [ # # ]: 0 : read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(rIStm); // Dummy
1006 [ # # ]: 0 : rIStm >> nCount;
1007 [ # # ]: 0 : read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(rIStm); // Dummy
1008 : :
1009 [ # # ][ # # ]: 0 : pCompat = new IMapCompat( rIStm, STREAM_READ );
1010 : :
1011 : : // hier kann in neueren Versionen gelesen werden
1012 : :
1013 [ # # ][ # # ]: 0 : delete pCompat;
1014 [ # # ]: 0 : ImpReadImageMap( rIStm, nCount, rBaseURL );
1015 : :
1016 : : }
1017 : : else
1018 [ # # ]: 0 : rIStm.SetError( SVSTREAM_GENERALERROR );
1019 : :
1020 [ # # ]: 0 : rIStm.SetNumberFormatInt( nOldFormat );
1021 : 0 : }
1022 : :
1023 : :
1024 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|