sync master with lastest vba changes
[ooovba.git] / sc / source / ui / unoobj / shapeuno.cxx
blob1d8a9445519e8394b846acdd0d91a77a6c56bf90
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: shapeuno.cxx,v $
10 * $Revision: 1.21.32.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include <tools/debug.hxx>
35 #include <comphelper/uno3.hxx>
36 #include <comphelper/stl_types.hxx>
37 #include <svtools/unoevent.hxx>
38 #include <svtools/unoimap.hxx>
39 #include <svx/svdobj.hxx>
40 #include <svx/unoshape.hxx>
41 #include <svx/unofield.hxx>
42 #include <toolkit/helper/convert.hxx>
43 #include <cppuhelper/implbase2.hxx>
45 #include <com/sun/star/drawing/XShape.hpp>
46 #include <com/sun/star/beans/PropertyAttribute.hpp>
48 #include "shapeuno.hxx"
49 #include "miscuno.hxx"
50 #include "cellsuno.hxx"
51 #include "textuno.hxx"
52 #include "fielduno.hxx"
53 #include "docsh.hxx"
54 #include "drwlayer.hxx"
55 #include "userdat.hxx"
56 #include "unonames.hxx"
57 #include "unoguard.hxx"
59 using namespace ::com::sun::star;
61 //------------------------------------------------------------------------
63 DECLARE_STL_USTRINGACCESS_MAP( uno::Sequence< sal_Int8 > *, ScShapeImplementationIdMap );
65 static ScShapeImplementationIdMap aImplementationIdMap;
67 const SfxItemPropertyMap* lcl_GetShapeMap()
69 static SfxItemPropertyMap aShapeMap_Impl[] =
71 {MAP_CHAR_LEN(SC_UNONAME_ANCHOR), 0, &getCppuType((uno::Reference<uno::XInterface>*)0), 0, 0 },
72 {MAP_CHAR_LEN(SC_UNONAME_HORIPOS), 0, &getCppuType((sal_Int32*)0), 0, 0 },
73 {MAP_CHAR_LEN(SC_UNONAME_IMAGEMAP), 0, &getCppuType((uno::Reference<container::XIndexContainer>*)0), 0, 0 },
74 {MAP_CHAR_LEN(SC_UNONAME_VERTPOS), 0, &getCppuType((sal_Int32*)0), 0, 0 },
75 // #i66550 HLINK_FOR_SHAPES
76 {MAP_CHAR_LEN(SC_UNONAME_HYPERLINK), 0, &getCppuType((rtl::OUString*)0), 0, 0 },
77 {0,0,0,0,0,0}
79 return aShapeMap_Impl;
82 // static
83 const SvEventDescription* ScShapeObj::GetSupportedMacroItems()
85 static const SvEventDescription aMacroDescriptionsImpl[] =
87 { 0, NULL }
89 return aMacroDescriptionsImpl;
91 // #i66550 HLINK_FOR_SHAPES
92 ScMacroInfo* lcl_getShapeHyperMacroInfo( ScShapeObj* pShape, BOOL bCreate = FALSE )
94 if( pShape )
95 if( SdrObject* pObj = pShape->GetSdrObject() )
96 return ScDrawLayer::GetMacroInfo( pObj, bCreate );
97 return 0;
100 //------------------------------------------------------------------------
102 ScShapeObj::ScShapeObj( uno::Reference<drawing::XShape>& xShape ) :
103 pShapePropertySet(NULL),
104 pShapePropertyState(NULL),
105 pImplementationId(NULL),
106 bIsTextShape(FALSE)
108 comphelper::increment( m_refCount );
111 mxShapeAgg = uno::Reference<uno::XAggregation>( xShape, uno::UNO_QUERY );
112 // extra block to force deletion of the temporary before setDelegator
115 if (mxShapeAgg.is())
117 xShape = NULL; // during setDelegator, mxShapeAgg must be the only ref
119 mxShapeAgg->setDelegator( (cppu::OWeakObject*)this );
121 xShape.set(uno::Reference<drawing::XShape>( mxShapeAgg, uno::UNO_QUERY ));
123 bIsTextShape = ( SvxUnoTextBase::getImplementation( mxShapeAgg ) != NULL );
126 comphelper::decrement( m_refCount );
129 ScShapeObj::~ScShapeObj()
131 // if (mxShapeAgg.is())
132 // mxShapeAgg->setDelegator(uno::Reference<uno::XInterface>());
135 // XInterface
137 uno::Any SAL_CALL ScShapeObj::queryInterface( const uno::Type& rType )
138 throw(uno::RuntimeException)
140 SC_QUERYINTERFACE( beans::XPropertySet )
141 SC_QUERYINTERFACE( beans::XPropertyState )
142 SC_QUERYINTERFACE( text::XTextContent )
143 SC_QUERYINTERFACE( lang::XComponent )
144 SC_QUERYINTERFACE( document::XEventsSupplier )
145 if ( bIsTextShape )
147 // #105585# for text shapes, XText (and parent interfaces) must
148 // be handled here, too (for ScCellFieldObj handling):
149 SC_QUERYINTERFACE( text::XText )
150 SC_QUERYINTERFACE( text::XSimpleText )
151 SC_QUERYINTERFACE( text::XTextRange )
153 SC_QUERYINTERFACE( lang::XTypeProvider )
155 uno::Any aRet(OWeakObject::queryInterface( rType ));
156 if ( !aRet.hasValue() && mxShapeAgg.is() )
157 aRet = mxShapeAgg->queryAggregation( rType );
159 return aRet;
162 void SAL_CALL ScShapeObj::acquire() throw()
164 OWeakObject::acquire();
167 void SAL_CALL ScShapeObj::release() throw()
169 OWeakObject::release();
172 void ScShapeObj::GetShapePropertySet()
174 // #i61908# Store the result of queryAggregation in a member.
175 // The reference in mxShapeAgg is kept for this object's lifetime, so the pointer is always valid.
177 if (!pShapePropertySet)
179 uno::Reference<beans::XPropertySet> xProp;
180 if ( mxShapeAgg.is() )
181 mxShapeAgg->queryAggregation( getCppuType((uno::Reference<beans::XPropertySet>*) 0) ) >>= xProp;
182 pShapePropertySet = xProp.get();
186 void ScShapeObj::GetShapePropertyState()
188 // #i61908# Store the result of queryAggregation in a member.
189 // The reference in mxShapeAgg is kept for this object's lifetime, so the pointer is always valid.
191 if (!pShapePropertyState)
193 uno::Reference<beans::XPropertyState> xState;
194 if ( mxShapeAgg.is() )
195 mxShapeAgg->queryAggregation( getCppuType((uno::Reference<beans::XPropertyState>*) 0) ) >>= xState;
196 pShapePropertyState = xState.get();
200 uno::Reference<lang::XComponent> lcl_GetComponent( const uno::Reference<uno::XAggregation>& xAgg )
202 uno::Reference<lang::XComponent> xRet;
203 if ( xAgg.is() )
204 xAgg->queryAggregation( getCppuType((uno::Reference<lang::XComponent>*) 0) ) >>= xRet;
205 return xRet;
208 uno::Reference<text::XText> lcl_GetText( const uno::Reference<uno::XAggregation>& xAgg )
210 uno::Reference<text::XText> xRet;
211 if ( xAgg.is() )
212 xAgg->queryAggregation( getCppuType((uno::Reference<text::XText>*) 0) ) >>= xRet;
213 return xRet;
216 uno::Reference<text::XSimpleText> lcl_GetSimpleText( const uno::Reference<uno::XAggregation>& xAgg )
218 uno::Reference<text::XSimpleText> xRet;
219 if ( xAgg.is() )
220 xAgg->queryAggregation( getCppuType((uno::Reference<text::XSimpleText>*) 0) ) >>= xRet;
221 return xRet;
224 uno::Reference<text::XTextRange> lcl_GetTextRange( const uno::Reference<uno::XAggregation>& xAgg )
226 uno::Reference<text::XTextRange> xRet;
227 if ( xAgg.is() )
228 xAgg->queryAggregation( getCppuType((uno::Reference<text::XTextRange>*) 0) ) >>= xRet;
229 return xRet;
232 // XPropertySet
234 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScShapeObj::getPropertySetInfo()
235 throw(uno::RuntimeException)
237 ScUnoGuard aGuard;
239 // #i61527# cache property set info for this object
240 if ( !mxPropSetInfo.is() )
242 // mix own and aggregated properties:
243 GetShapePropertySet();
244 if (pShapePropertySet)
246 uno::Reference<beans::XPropertySetInfo> xAggInfo(pShapePropertySet->getPropertySetInfo());
247 const uno::Sequence<beans::Property> aPropSeq(xAggInfo->getProperties());
248 mxPropSetInfo.set(new SfxExtItemPropertySetInfo( lcl_GetShapeMap(), aPropSeq ));
251 return mxPropSetInfo;
254 BOOL lcl_GetPageNum( SdrPage* pPage, SdrModel& rModel, SCTAB& rNum )
256 USHORT nCount = rModel.GetPageCount();
257 for (USHORT i=0; i<nCount; i++)
258 if ( rModel.GetPage(i) == pPage )
260 rNum = static_cast<SCTAB>(i);
261 return TRUE;
264 return FALSE;
267 BOOL lcl_GetCaptionPoint( uno::Reference< drawing::XShape >& xShape, awt::Point& rCaptionPoint )
269 BOOL bReturn = FALSE;
270 rtl::OUString sType(xShape->getShapeType());
271 sal_Bool bCaptionShape(sType.equalsAscii("com.sun.star.drawing.CaptionShape"));
272 if (bCaptionShape)
274 uno::Reference < beans::XPropertySet > xShapeProp (xShape, uno::UNO_QUERY);
275 if (xShapeProp.is())
277 xShapeProp->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "CaptionPoint" )) ) >>= rCaptionPoint;
278 bReturn = TRUE;
281 return bReturn;
284 ScRange lcl_GetAnchorCell( uno::Reference< drawing::XShape >& xShape, ScDocument* pDoc, SCTAB nTab,
285 awt::Point& rUnoPoint, awt::Size& rUnoSize, awt::Point& rCaptionPoint )
287 ScRange aReturn;
288 rUnoPoint = xShape->getPosition();
289 rtl::OUString sType(xShape->getShapeType());
290 sal_Bool bCaptionShape(lcl_GetCaptionPoint(xShape, rCaptionPoint));
291 if (pDoc->IsNegativePage(nTab))
293 rUnoSize = xShape->getSize();
294 rUnoPoint.X += rUnoSize.Width; // the right top point is base
295 if (bCaptionShape)
297 if (rCaptionPoint.X > 0 && rCaptionPoint.X > rUnoSize.Width)
298 rUnoPoint.X += rCaptionPoint.X - rUnoSize.Width;
299 if (rCaptionPoint.Y < 0)
300 rUnoPoint.Y += rCaptionPoint.Y;
302 aReturn = pDoc->GetRange( nTab, Rectangle( VCLPoint(rUnoPoint), VCLPoint(rUnoPoint) ));
304 else
306 if (bCaptionShape)
308 if (rCaptionPoint.X < 0)
309 rUnoPoint.X += rCaptionPoint.X;
310 if (rCaptionPoint.Y < 0)
311 rUnoPoint.Y += rCaptionPoint.Y;
313 aReturn = pDoc->GetRange( nTab, Rectangle( VCLPoint(rUnoPoint), VCLPoint(rUnoPoint) ));
316 return aReturn;
319 awt::Point lcl_GetRelativePos( uno::Reference< drawing::XShape >& xShape, ScDocument* pDoc, SCTAB nTab, ScRange& rRange,
320 awt::Size& rUnoSize, awt::Point& rCaptionPoint)
322 awt::Point aUnoPoint;
323 rRange = lcl_GetAnchorCell(xShape, pDoc, nTab, aUnoPoint, rUnoSize, rCaptionPoint);
324 if (pDoc->IsNegativePage(nTab))
326 Rectangle aRect(pDoc->GetMMRect( rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row(), rRange.aStart.Tab() ));
327 Point aPoint(aRect.TopRight());
328 aUnoPoint.X -= aPoint.X();
329 aUnoPoint.Y -= aPoint.Y();
331 else
333 ScRange aRange = pDoc->GetRange( nTab, Rectangle( VCLPoint(aUnoPoint), VCLPoint(aUnoPoint) ));
334 Rectangle aRect(pDoc->GetMMRect( rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row(), rRange.aStart.Tab() ));
335 Point aPoint(aRect.TopLeft());
336 aUnoPoint.X -= aPoint.X();
337 aUnoPoint.Y -= aPoint.Y();
340 return aUnoPoint;
343 void SAL_CALL ScShapeObj::setPropertyValue(
344 const rtl::OUString& aPropertyName, const uno::Any& aValue )
345 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
346 lang::IllegalArgumentException, lang::WrappedTargetException,
347 uno::RuntimeException)
349 ScUnoGuard aGuard;
350 String aNameString(aPropertyName);
352 if ( aNameString.EqualsAscii( SC_UNONAME_ANCHOR ) )
354 uno::Reference<sheet::XCellRangeAddressable> xRangeAdd(aValue, uno::UNO_QUERY);
355 if (xRangeAdd.is())
357 SdrObject *pObj = GetSdrObject();
358 if (pObj)
360 ScDrawLayer* pModel = (ScDrawLayer*)pObj->GetModel();
361 SdrPage* pPage = pObj->GetPage();
362 if ( pModel && pPage )
364 ScDocument* pDoc = pModel->GetDocument();
365 if ( pDoc )
367 SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
368 if ( pObjSh && pObjSh->ISA(ScDocShell) )
370 ScDocShell* pDocSh = (ScDocShell*)pObjSh;
372 SCTAB nTab = 0;
373 if ( lcl_GetPageNum( pPage, *pModel, nTab ) )
375 table::CellRangeAddress aAddress = xRangeAdd->getRangeAddress();
376 if (nTab == aAddress.Sheet)
378 if (aAddress.StartRow != aAddress.EndRow) //should be a Spreadsheet
380 DBG_ASSERT(aAddress.StartRow == 0 && aAddress.EndRow == MAXROW &&
381 aAddress.StartColumn == 0 && aAddress.EndColumn == MAXCOL, "here should be a XSpreadsheet");
382 ScDrawLayer::SetAnchor(pObj, SCA_PAGE);
384 else
386 DBG_ASSERT(aAddress.StartRow == aAddress.EndRow &&
387 aAddress.StartColumn == aAddress.EndColumn, "here should be a XCell");
388 ScDrawLayer::SetAnchor(pObj, SCA_CELL);
390 Rectangle aRect(pDoc->GetMMRect( static_cast<SCCOL>(aAddress.StartColumn), static_cast<SCROW>(aAddress.StartRow),
391 static_cast<SCCOL>(aAddress.EndColumn), static_cast<SCROW>(aAddress.EndRow), aAddress.Sheet ));
392 uno::Reference<drawing::XShape> xShape( mxShapeAgg, uno::UNO_QUERY );
393 if (xShape.is())
395 Point aPoint;
396 Point aEndPoint;
397 if (pDoc->IsNegativePage(nTab))
399 aPoint = aRect.TopRight();
400 aEndPoint = aRect.BottomLeft();
402 else
404 aPoint = aRect.TopLeft();
405 aEndPoint = aRect.BottomRight();
407 awt::Size aUnoSize;
408 awt::Point aCaptionPoint;
409 ScRange aRange;
410 awt::Point aUnoPoint(lcl_GetRelativePos( xShape, pDoc, nTab, aRange, aUnoSize, aCaptionPoint ));
412 aUnoPoint.X += aPoint.X();
413 aUnoPoint.Y += aPoint.Y();
415 if ( aUnoPoint.Y > aEndPoint.Y() )
416 aUnoPoint.Y = aEndPoint.Y() - 2;
417 if (pDoc->IsNegativePage(nTab))
419 if ( aUnoPoint.X < aEndPoint.X() )
420 aUnoPoint.X = aEndPoint.X() + 2;
421 aUnoPoint.X -= aUnoSize.Width;
422 // remove difference to caption point
423 if (aCaptionPoint.X > 0 && aCaptionPoint.X > aUnoSize.Width)
424 aUnoPoint.X -= aCaptionPoint.X - aUnoSize.Width;
426 else
428 if ( aUnoPoint.X > aEndPoint.X() )
429 aUnoPoint.X = aEndPoint.X() - 2;
430 if (aCaptionPoint.X < 0)
431 aUnoPoint.X -= aCaptionPoint.X;
433 if (aCaptionPoint.Y < 0)
434 aUnoPoint.Y -= aCaptionPoint.Y;
436 xShape->setPosition(aUnoPoint);
437 pDocSh->SetModified();
446 else
447 throw lang::IllegalArgumentException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("only XCell or XSpreadsheet objects allowed")), static_cast<cppu::OWeakObject*>(this), 0);
449 else if ( aNameString.EqualsAscii( SC_UNONAME_IMAGEMAP ) )
451 SdrObject* pObj = GetSdrObject();
452 if ( pObj )
454 ImageMap aImageMap;
455 uno::Reference< uno::XInterface > xImageMapInt(aValue, uno::UNO_QUERY);
457 if( !xImageMapInt.is() || !SvUnoImageMap_fillImageMap( xImageMapInt, aImageMap ) )
458 throw lang::IllegalArgumentException();
460 ScIMapInfo* pIMapInfo = ScDrawLayer::GetIMapInfo(pObj);
461 if( pIMapInfo )
463 // replace existing image map
464 pIMapInfo->SetImageMap( aImageMap );
466 else
468 // insert new user data with image map
469 pObj->InsertUserData(new ScIMapInfo(aImageMap) );
473 else if ( aNameString.EqualsAscii( SC_UNONAME_HORIPOS ) )
475 sal_Int32 nPos = 0;
476 if (aValue >>= nPos)
478 SdrObject *pObj = GetSdrObject();
479 if (pObj)
481 ScDrawLayer* pModel = (ScDrawLayer*)pObj->GetModel();
482 SdrPage* pPage = pObj->GetPage();
483 if ( pModel && pPage )
485 SCTAB nTab = 0;
486 if ( lcl_GetPageNum( pPage, *pModel, nTab ) )
488 ScDocument* pDoc = pModel->GetDocument();
489 if ( pDoc )
491 SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
492 if ( pObjSh && pObjSh->ISA(ScDocShell) )
494 ScDocShell* pDocSh = (ScDocShell*)pObjSh;
495 uno::Reference<drawing::XShape> xShape( mxShapeAgg, uno::UNO_QUERY );
496 if (xShape.is())
498 if (ScDrawLayer::GetAnchor(pObj) == SCA_PAGE)
500 awt::Point aPoint(xShape->getPosition());
501 awt::Size aSize(xShape->getSize());
502 awt::Point aCaptionPoint;
503 if (pDoc->IsNegativePage(nTab))
505 nPos *= -1;
506 nPos -= aSize.Width;
508 if (lcl_GetCaptionPoint(xShape, aCaptionPoint))
510 if (pDoc->IsNegativePage(nTab))
512 if (aCaptionPoint.X > 0 && aCaptionPoint.X > aSize.Width)
513 nPos -= aCaptionPoint.X - aSize.Width;
515 else
517 if (aCaptionPoint.X < 0)
518 nPos -= aCaptionPoint.X;
521 aPoint.X = nPos;
522 xShape->setPosition(aPoint);
523 pDocSh->SetModified();
525 else if (ScDrawLayer::GetAnchor(pObj) == SCA_CELL)
527 awt::Size aUnoSize;
528 awt::Point aCaptionPoint;
529 ScRange aRange;
530 awt::Point aUnoPoint(lcl_GetRelativePos( xShape, pDoc, nTab, aRange, aUnoSize, aCaptionPoint ));
531 Rectangle aRect(pDoc->GetMMRect( aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row(), aRange.aStart.Tab() ));
532 if (pDoc->IsNegativePage(nTab))
534 aUnoPoint.X = -nPos;
535 Point aPoint(aRect.TopRight());
536 Point aEndPoint(aRect.BottomLeft());
537 aUnoPoint.X += aPoint.X();
538 if (aUnoPoint.X < aEndPoint.X())
539 aUnoPoint.X = aEndPoint.X() + 2;
540 aUnoPoint.X -= aUnoSize.Width;
541 if (aCaptionPoint.X > 0 && aCaptionPoint.X > aUnoSize.Width)
542 aUnoPoint.X -= aCaptionPoint.X - aUnoSize.Width;
544 else
546 aUnoPoint.X = nPos;
547 Point aPoint(aRect.TopLeft());
548 Point aEndPoint(aRect.BottomRight());
549 aUnoPoint.X += aPoint.X();
550 if (aUnoPoint.X > aEndPoint.X())
551 aUnoPoint.X = aEndPoint.X() - 2;
552 if (aCaptionPoint.X < 0)
553 aUnoPoint.X -= aCaptionPoint.X;
555 aUnoPoint.Y = xShape->getPosition().Y;
556 xShape->setPosition(aUnoPoint);
557 pDocSh->SetModified();
559 else
561 DBG_ERROR("unknown anchor type");
571 else if ( aNameString.EqualsAscii( SC_UNONAME_VERTPOS ) )
573 sal_Int32 nPos = 0;
574 if (aValue >>= nPos)
576 SdrObject *pObj = GetSdrObject();
577 if (pObj)
579 ScDrawLayer* pModel = (ScDrawLayer*)pObj->GetModel();
580 SdrPage* pPage = pObj->GetPage();
581 if ( pModel && pPage )
583 SCTAB nTab = 0;
584 if ( lcl_GetPageNum( pPage, *pModel, nTab ) )
586 ScDocument* pDoc = pModel->GetDocument();
587 if ( pDoc )
589 SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
590 if ( pObjSh && pObjSh->ISA(ScDocShell) )
592 ScDocShell* pDocSh = (ScDocShell*)pObjSh;
593 uno::Reference<drawing::XShape> xShape( mxShapeAgg, uno::UNO_QUERY );
594 if (xShape.is())
596 if (ScDrawLayer::GetAnchor(pObj) == SCA_PAGE)
598 awt::Point aPoint = xShape->getPosition();
599 awt::Point aCaptionPoint;
600 if (lcl_GetCaptionPoint(xShape, aCaptionPoint))
602 if (aCaptionPoint.Y < 0)
603 nPos -= aCaptionPoint.Y;
605 aPoint.Y = nPos;
606 xShape->setPosition(aPoint);
607 pDocSh->SetModified();
609 else if (ScDrawLayer::GetAnchor(pObj) == SCA_CELL)
611 awt::Size aUnoSize;
612 awt::Point aCaptionPoint;
613 ScRange aRange;
614 awt::Point aUnoPoint(lcl_GetRelativePos( xShape, pDoc, nTab, aRange, aUnoSize, aCaptionPoint ));
615 Rectangle aRect(pDoc->GetMMRect( aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row(), aRange.aStart.Tab() ));
616 Point aPoint(aRect.TopRight());
617 Point aEndPoint(aRect.BottomLeft());
618 aUnoPoint.Y = nPos;
619 aUnoPoint.Y += aPoint.Y();
620 if (aUnoPoint.Y > aEndPoint.Y())
621 aUnoPoint.Y = aEndPoint.Y() - 2;
622 if (aCaptionPoint.Y < 0)
623 aUnoPoint.Y -= aCaptionPoint.Y;
624 aUnoPoint.X = xShape->getPosition().X;
625 xShape->setPosition(aUnoPoint);
626 pDocSh->SetModified();
628 else
630 DBG_ERROR("unknown anchor type");
640 else if ( aNameString.EqualsAscii( SC_UNONAME_HYPERLINK ) )
642 rtl::OUString sHlink;
643 ScMacroInfo* pInfo = lcl_getShapeHyperMacroInfo(this, TRUE);
644 if ( ( aValue >>= sHlink ) && pInfo )
645 pInfo->SetHlink( sHlink );
647 else
649 GetShapePropertySet();
650 if (pShapePropertySet)
651 pShapePropertySet->setPropertyValue( aPropertyName, aValue );
655 uno::Any SAL_CALL ScShapeObj::getPropertyValue( const rtl::OUString& aPropertyName )
656 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
657 uno::RuntimeException)
659 ScUnoGuard aGuard;
660 String aNameString = aPropertyName;
662 uno::Any aAny;
663 if ( aNameString.EqualsAscii( SC_UNONAME_ANCHOR ) )
665 SdrObject *pObj = GetSdrObject();
666 if (pObj)
668 ScDrawLayer* pModel = (ScDrawLayer*)pObj->GetModel();
669 SdrPage* pPage = pObj->GetPage();
670 if ( pModel && pPage )
672 ScDocument* pDoc = pModel->GetDocument();
673 if ( pDoc )
675 SCTAB nTab = 0;
676 if ( lcl_GetPageNum( pPage, *pModel, nTab ) )
678 SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
679 if ( pObjSh && pObjSh->ISA(ScDocShell) )
681 ScDocShell* pDocSh = (ScDocShell*)pObjSh;
682 uno::Reference< uno::XInterface > xAnchor;
683 if (ScDrawLayer::GetAnchor(pObj) == SCA_CELL)
685 uno::Reference<drawing::XShape> xShape( mxShapeAgg, uno::UNO_QUERY );
686 if (xShape.is())
688 awt::Size aUnoSize;
689 awt::Point aCaptionPoint;
690 ScRange aRange;
691 awt::Point aUnoPoint(lcl_GetRelativePos( xShape, pDoc, nTab, aRange, aUnoSize, aCaptionPoint ));
693 xAnchor.set(static_cast<cppu::OWeakObject*>(new ScCellObj( pDocSh, aRange.aStart )));
696 else
698 xAnchor.set(static_cast<cppu::OWeakObject*>(new ScTableSheetObj( pDocSh, nTab )));
700 aAny <<= xAnchor;
707 else if ( aNameString.EqualsAscii( SC_UNONAME_IMAGEMAP ) )
709 uno::Reference< uno::XInterface > xImageMap;
710 SdrObject* pObj = GetSdrObject();
711 if ( pObj )
713 ScIMapInfo* pIMapInfo = ScDrawLayer::GetIMapInfo(GetSdrObject());
714 if( pIMapInfo )
716 const ImageMap& rIMap = pIMapInfo->GetImageMap();
717 xImageMap.set(SvUnoImageMap_createInstance( rIMap, GetSupportedMacroItems() ));
719 else
720 xImageMap = SvUnoImageMap_createInstance( GetSupportedMacroItems() );
722 aAny <<= uno::Reference< container::XIndexContainer >::query( xImageMap );
724 else if ( aNameString.EqualsAscii( SC_UNONAME_HORIPOS ) )
726 SdrObject *pObj = GetSdrObject();
727 if (pObj)
729 ScDrawLayer* pModel = (ScDrawLayer*)pObj->GetModel();
730 SdrPage* pPage = pObj->GetPage();
731 if ( pModel && pPage )
733 ScDocument* pDoc = pModel->GetDocument();
734 if ( pDoc )
736 SCTAB nTab = 0;
737 if ( lcl_GetPageNum( pPage, *pModel, nTab ) )
739 uno::Reference<drawing::XShape> xShape( mxShapeAgg, uno::UNO_QUERY );
740 if (xShape.is())
742 if (ScDrawLayer::GetAnchor(pObj) == SCA_CELL)
744 awt::Size aUnoSize;
745 awt::Point aCaptionPoint;
746 ScRange aRange;
747 awt::Point aUnoPoint(lcl_GetRelativePos( xShape, pDoc, nTab, aRange, aUnoSize, aCaptionPoint ));
748 if (pDoc->IsNegativePage(nTab))
749 aUnoPoint.X *= -1;
750 aAny <<= aUnoPoint.X;
752 else
754 awt::Point aCaptionPoint;
755 awt::Point aUnoPoint(xShape->getPosition());
756 awt::Size aUnoSize(xShape->getSize());
757 if (pDoc->IsNegativePage(nTab))
759 aUnoPoint.X *= -1;
760 aUnoPoint.X -= aUnoSize.Width;
762 if (lcl_GetCaptionPoint(xShape, aCaptionPoint))
764 if (pDoc->IsNegativePage(nTab))
766 if (aCaptionPoint.X > 0 && aCaptionPoint.X > aUnoSize.Width)
767 aUnoPoint.X -= aCaptionPoint.X - aUnoSize.Width;
769 else
771 if (aCaptionPoint.X < 0)
772 aUnoPoint.X += aCaptionPoint.X;
775 aAny <<= aUnoPoint.X;
783 else if ( aNameString.EqualsAscii( SC_UNONAME_VERTPOS ) )
785 SdrObject *pObj = GetSdrObject();
786 if (pObj)
788 ScDrawLayer* pModel = (ScDrawLayer*)pObj->GetModel();
789 SdrPage* pPage = pObj->GetPage();
790 if ( pModel && pPage )
792 ScDocument* pDoc = pModel->GetDocument();
793 if ( pDoc )
795 SCTAB nTab = 0;
796 if ( lcl_GetPageNum( pPage, *pModel, nTab ) )
798 uno::Reference<drawing::XShape> xShape( mxShapeAgg, uno::UNO_QUERY );
799 if (xShape.is())
801 uno::Reference< uno::XInterface > xAnchor;
802 if (ScDrawLayer::GetAnchor(pObj) == SCA_CELL)
804 awt::Size aUnoSize;
805 awt::Point aCaptionPoint;
806 ScRange aRange;
807 awt::Point aUnoPoint(lcl_GetRelativePos( xShape, pDoc, nTab, aRange, aUnoSize, aCaptionPoint ));
809 aAny <<= aUnoPoint.Y;
811 else
813 awt::Point aUnoPoint(xShape->getPosition());
814 awt::Point aCaptionPoint;
815 if (lcl_GetCaptionPoint(xShape, aCaptionPoint))
817 if (aCaptionPoint.Y < 0)
818 aUnoPoint.Y += aCaptionPoint.Y;
820 aAny <<= aUnoPoint.Y;
828 else if ( aNameString.EqualsAscii( SC_UNONAME_HYPERLINK ) )
830 rtl::OUString sHlink;
831 if ( ScMacroInfo* pInfo = lcl_getShapeHyperMacroInfo(this) )
832 sHlink = pInfo->GetHlink();
833 aAny <<= sHlink;
835 else
837 GetShapePropertySet();
838 if (pShapePropertySet)
839 aAny = pShapePropertySet->getPropertyValue( aPropertyName );
842 return aAny;
845 void SAL_CALL ScShapeObj::addPropertyChangeListener( const rtl::OUString& aPropertyName,
846 const uno::Reference<beans::XPropertyChangeListener>& aListener)
847 throw(beans::UnknownPropertyException,
848 lang::WrappedTargetException, uno::RuntimeException)
850 ScUnoGuard aGuard;
852 GetShapePropertySet();
853 if (pShapePropertySet)
854 pShapePropertySet->addPropertyChangeListener( aPropertyName, aListener );
857 void SAL_CALL ScShapeObj::removePropertyChangeListener( const rtl::OUString& aPropertyName,
858 const uno::Reference<beans::XPropertyChangeListener>& aListener)
859 throw(beans::UnknownPropertyException,
860 lang::WrappedTargetException, uno::RuntimeException)
862 ScUnoGuard aGuard;
864 GetShapePropertySet();
865 if (pShapePropertySet)
866 pShapePropertySet->removePropertyChangeListener( aPropertyName, aListener );
869 void SAL_CALL ScShapeObj::addVetoableChangeListener( const rtl::OUString& aPropertyName,
870 const uno::Reference<beans::XVetoableChangeListener>& aListener)
871 throw(beans::UnknownPropertyException,
872 lang::WrappedTargetException, uno::RuntimeException)
874 ScUnoGuard aGuard;
876 GetShapePropertySet();
877 if (pShapePropertySet)
878 pShapePropertySet->addVetoableChangeListener( aPropertyName, aListener );
881 void SAL_CALL ScShapeObj::removeVetoableChangeListener( const rtl::OUString& aPropertyName,
882 const uno::Reference<beans::XVetoableChangeListener>& aListener)
883 throw(beans::UnknownPropertyException,
884 lang::WrappedTargetException, uno::RuntimeException)
886 ScUnoGuard aGuard;
888 GetShapePropertySet();
889 if (pShapePropertySet)
890 pShapePropertySet->removeVetoableChangeListener( aPropertyName, aListener );
893 // XPropertyState
895 beans::PropertyState SAL_CALL ScShapeObj::getPropertyState( const rtl::OUString& aPropertyName )
896 throw(beans::UnknownPropertyException, uno::RuntimeException)
898 ScUnoGuard aGuard;
899 String aNameString(aPropertyName);
901 beans::PropertyState eRet = beans::PropertyState_DIRECT_VALUE;
902 if ( aNameString.EqualsAscii( SC_UNONAME_IMAGEMAP ) )
904 // ImageMap is always "direct"
906 else if ( aNameString.EqualsAscii( SC_UNONAME_ANCHOR ) )
908 // Anchor is always "direct"
910 else if ( aNameString.EqualsAscii( SC_UNONAME_HORIPOS ) )
912 // HoriPos is always "direct"
914 else if ( aNameString.EqualsAscii( SC_UNONAME_VERTPOS ) )
916 // VertPos is always "direct"
918 else
920 GetShapePropertyState();
921 if (pShapePropertyState)
922 eRet = pShapePropertyState->getPropertyState( aPropertyName );
925 return eRet;
928 uno::Sequence<beans::PropertyState> SAL_CALL ScShapeObj::getPropertyStates(
929 const uno::Sequence<rtl::OUString>& aPropertyNames )
930 throw(beans::UnknownPropertyException, uno::RuntimeException)
932 ScUnoGuard aGuard;
934 // simple loop to get own and aggregated states
936 const rtl::OUString* pNames = aPropertyNames.getConstArray();
937 uno::Sequence<beans::PropertyState> aRet(aPropertyNames.getLength());
938 beans::PropertyState* pStates = aRet.getArray();
939 for(sal_Int32 i = 0; i < aPropertyNames.getLength(); i++)
940 pStates[i] = getPropertyState(pNames[i]);
941 return aRet;
944 void SAL_CALL ScShapeObj::setPropertyToDefault( const rtl::OUString& aPropertyName )
945 throw(beans::UnknownPropertyException, uno::RuntimeException)
947 ScUnoGuard aGuard;
948 String aNameString(aPropertyName);
950 if ( aNameString.EqualsAscii( SC_UNONAME_IMAGEMAP ) )
952 SdrObject* pObj = GetSdrObject();
953 if ( pObj )
955 ScIMapInfo* pIMapInfo = ScDrawLayer::GetIMapInfo(pObj);
956 if( pIMapInfo )
958 ImageMap aEmpty;
959 pIMapInfo->SetImageMap( aEmpty ); // replace with empty image map
961 else
963 // nothing to do (no need to insert user data for an empty map)
967 else
969 GetShapePropertyState();
970 if (pShapePropertyState)
971 pShapePropertyState->setPropertyToDefault( aPropertyName );
975 uno::Any SAL_CALL ScShapeObj::getPropertyDefault( const rtl::OUString& aPropertyName )
976 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
977 uno::RuntimeException)
979 ScUnoGuard aGuard;
980 String aNameString = aPropertyName;
982 uno::Any aAny;
983 if ( aNameString.EqualsAscii( SC_UNONAME_IMAGEMAP ) )
985 // default: empty ImageMap
986 uno::Reference< uno::XInterface > xImageMap(SvUnoImageMap_createInstance( GetSupportedMacroItems() ));
987 aAny <<= uno::Reference< container::XIndexContainer >::query( xImageMap );
989 else
991 GetShapePropertyState();
992 if (pShapePropertyState)
993 aAny = pShapePropertyState->getPropertyDefault( aPropertyName );
996 return aAny;
999 // XTextContent
1001 void SAL_CALL ScShapeObj::attach( const uno::Reference<text::XTextRange>& /* xTextRange */ )
1002 throw(lang::IllegalArgumentException, uno::RuntimeException)
1004 ScUnoGuard aGuard;
1006 throw lang::IllegalArgumentException(); // anchor cannot be changed
1009 uno::Reference<text::XTextRange> SAL_CALL ScShapeObj::getAnchor() throw(uno::RuntimeException)
1011 ScUnoGuard aGuard;
1013 uno::Reference<text::XTextRange> xRet;
1015 SdrObject* pObj = GetSdrObject();
1016 if( pObj )
1018 ScDrawLayer* pModel = (ScDrawLayer*)pObj->GetModel();
1019 SdrPage* pPage = pObj->GetPage();
1020 if ( pModel )
1022 ScDocument* pDoc = pModel->GetDocument();
1023 if ( pDoc )
1025 SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
1026 if ( pObjSh && pObjSh->ISA(ScDocShell) )
1028 ScDocShell* pDocSh = (ScDocShell*)pObjSh;
1030 SCTAB nTab = 0;
1031 if ( lcl_GetPageNum( pPage, *pModel, nTab ) )
1033 Point aPos(pObj->GetCurrentBoundRect().TopLeft());
1034 ScRange aRange(pDoc->GetRange( nTab, Rectangle( aPos, aPos ) ));
1036 // anchor is always the cell
1038 xRet.set(new ScCellObj( pDocSh, aRange.aStart ));
1045 return xRet;
1048 // XComponent
1050 void SAL_CALL ScShapeObj::dispose() throw(uno::RuntimeException)
1052 ScUnoGuard aGuard;
1054 uno::Reference<lang::XComponent> xAggComp(lcl_GetComponent(mxShapeAgg));
1055 if ( xAggComp.is() )
1056 xAggComp->dispose();
1059 void SAL_CALL ScShapeObj::addEventListener(
1060 const uno::Reference<lang::XEventListener>& xListener )
1061 throw(uno::RuntimeException)
1063 ScUnoGuard aGuard;
1065 uno::Reference<lang::XComponent> xAggComp(lcl_GetComponent(mxShapeAgg));
1066 if ( xAggComp.is() )
1067 xAggComp->addEventListener(xListener);
1070 void SAL_CALL ScShapeObj::removeEventListener(
1071 const uno::Reference<lang::XEventListener>& xListener )
1072 throw(uno::RuntimeException)
1074 ScUnoGuard aGuard;
1076 uno::Reference<lang::XComponent> xAggComp(lcl_GetComponent(mxShapeAgg));
1077 if ( xAggComp.is() )
1078 xAggComp->removeEventListener(xListener);
1081 // XText
1082 // (special handling for ScCellFieldObj)
1084 void lcl_CopyOneProperty( beans::XPropertySet& rDest, beans::XPropertySet& rSource, const sal_Char* pName )
1086 rtl::OUString aNameStr(rtl::OUString::createFromAscii(pName));
1089 rDest.setPropertyValue( aNameStr, rSource.getPropertyValue( aNameStr ) );
1091 catch (uno::Exception&)
1093 DBG_ERROR("Exception in text field");
1097 void SAL_CALL ScShapeObj::insertTextContent( const uno::Reference<text::XTextRange>& xRange,
1098 const uno::Reference<text::XTextContent>& xContent,
1099 sal_Bool bAbsorb )
1100 throw(lang::IllegalArgumentException, uno::RuntimeException)
1102 ScUnoGuard aGuard;
1104 uno::Reference<text::XTextContent> xEffContent;
1106 ScCellFieldObj* pCellField = ScCellFieldObj::getImplementation( xContent );
1107 if ( pCellField )
1109 // #105585# createInstance("TextField.URL") from the document creates a ScCellFieldObj.
1110 // To insert it into drawing text, a SvxUnoTextField is needed instead.
1111 // The ScCellFieldObj object is left in non-inserted state.
1113 SvxUnoTextField* pDrawField = new SvxUnoTextField( ID_URLFIELD );
1114 xEffContent.set(pDrawField);
1115 lcl_CopyOneProperty( *pDrawField, *pCellField, SC_UNONAME_URL );
1116 lcl_CopyOneProperty( *pDrawField, *pCellField, SC_UNONAME_REPR );
1117 lcl_CopyOneProperty( *pDrawField, *pCellField, SC_UNONAME_TARGET );
1119 else
1120 xEffContent.set(xContent);
1122 uno::Reference<text::XText> xAggText(lcl_GetText(mxShapeAgg));
1123 if ( xAggText.is() )
1124 xAggText->insertTextContent( xRange, xEffContent, bAbsorb );
1127 void SAL_CALL ScShapeObj::removeTextContent( const uno::Reference<text::XTextContent>& xContent )
1128 throw(container::NoSuchElementException, uno::RuntimeException)
1130 ScUnoGuard aGuard;
1132 // ScCellFieldObj can't be used here.
1134 uno::Reference<text::XText> xAggText(lcl_GetText(mxShapeAgg));
1135 if ( xAggText.is() )
1136 xAggText->removeTextContent( xContent );
1139 // XSimpleText (parent of XText)
1140 // Use own SvxUnoTextCursor subclass - everything is just passed to aggregated object
1142 uno::Reference<text::XTextCursor> SAL_CALL ScShapeObj::createTextCursor()
1143 throw(uno::RuntimeException)
1145 ScUnoGuard aGuard;
1147 if ( mxShapeAgg.is() )
1149 // ScDrawTextCursor must be used to ensure the ScShapeObj is returned by getText
1151 SvxUnoTextBase* pText = SvxUnoTextBase::getImplementation( mxShapeAgg );
1152 if (pText)
1153 return new ScDrawTextCursor( this, *pText );
1156 return uno::Reference<text::XTextCursor>();
1159 uno::Reference<text::XTextCursor> SAL_CALL ScShapeObj::createTextCursorByRange(
1160 const uno::Reference<text::XTextRange>& aTextPosition )
1161 throw(uno::RuntimeException)
1163 ScUnoGuard aGuard;
1165 if ( mxShapeAgg.is() && aTextPosition.is() )
1167 // ScDrawTextCursor must be used to ensure the ScShapeObj is returned by getText
1169 SvxUnoTextBase* pText = SvxUnoTextBase::getImplementation( mxShapeAgg );
1170 SvxUnoTextRangeBase* pRange = SvxUnoTextRangeBase::getImplementation( aTextPosition );
1171 if ( pText && pRange )
1173 SvxUnoTextCursor* pCursor = new ScDrawTextCursor( this, *pText );
1174 uno::Reference<text::XTextCursor> xCursor( pCursor );
1175 pCursor->SetSelection( pRange->GetSelection() );
1176 return xCursor;
1180 return uno::Reference<text::XTextCursor>();
1183 void SAL_CALL ScShapeObj::insertString( const uno::Reference<text::XTextRange>& xRange,
1184 const rtl::OUString& aString, sal_Bool bAbsorb )
1185 throw(uno::RuntimeException)
1187 ScUnoGuard aGuard;
1189 uno::Reference<text::XSimpleText> xAggSimpleText(lcl_GetSimpleText(mxShapeAgg));
1190 if ( xAggSimpleText.is() )
1191 xAggSimpleText->insertString( xRange, aString, bAbsorb );
1192 else
1193 throw uno::RuntimeException();
1196 void SAL_CALL ScShapeObj::insertControlCharacter( const uno::Reference<text::XTextRange>& xRange,
1197 sal_Int16 nControlCharacter, sal_Bool bAbsorb )
1198 throw(lang::IllegalArgumentException, uno::RuntimeException)
1200 ScUnoGuard aGuard;
1202 uno::Reference<text::XSimpleText> xAggSimpleText(lcl_GetSimpleText(mxShapeAgg));
1203 if ( xAggSimpleText.is() )
1204 xAggSimpleText->insertControlCharacter( xRange, nControlCharacter, bAbsorb );
1205 else
1206 throw uno::RuntimeException();
1209 // XTextRange
1210 // (parent of XSimpleText)
1212 uno::Reference<text::XText> SAL_CALL ScShapeObj::getText() throw(uno::RuntimeException)
1214 ScUnoGuard aGuard;
1215 return this;
1218 uno::Reference<text::XTextRange> SAL_CALL ScShapeObj::getStart() throw(uno::RuntimeException)
1220 ScUnoGuard aGuard;
1222 uno::Reference<text::XTextRange> xAggTextRange(lcl_GetTextRange(mxShapeAgg));
1223 if ( xAggTextRange.is() )
1224 return xAggTextRange->getStart();
1225 else
1226 throw uno::RuntimeException();
1228 // return uno::Reference<text::XTextRange>();
1231 uno::Reference<text::XTextRange> SAL_CALL ScShapeObj::getEnd() throw(uno::RuntimeException)
1233 ScUnoGuard aGuard;
1235 uno::Reference<text::XTextRange> xAggTextRange(lcl_GetTextRange(mxShapeAgg));
1236 if ( xAggTextRange.is() )
1237 return xAggTextRange->getEnd();
1238 else
1239 throw uno::RuntimeException();
1241 // return uno::Reference<text::XTextRange>();
1244 rtl::OUString SAL_CALL ScShapeObj::getString() throw(uno::RuntimeException)
1246 ScUnoGuard aGuard;
1248 uno::Reference<text::XTextRange> xAggTextRange(lcl_GetTextRange(mxShapeAgg));
1249 if ( xAggTextRange.is() )
1250 return xAggTextRange->getString();
1251 else
1252 throw uno::RuntimeException();
1254 // return rtl::OUString();
1257 void SAL_CALL ScShapeObj::setString( const rtl::OUString& aText ) throw(uno::RuntimeException)
1259 ScUnoGuard aGuard;
1261 uno::Reference<text::XTextRange> xAggTextRange(lcl_GetTextRange(mxShapeAgg));
1262 if ( xAggTextRange.is() )
1263 xAggTextRange->setString( aText );
1264 else
1265 throw uno::RuntimeException();
1268 // XTypeProvider
1270 uno::Sequence<uno::Type> SAL_CALL ScShapeObj::getTypes() throw(uno::RuntimeException)
1272 uno::Sequence< uno::Type > aTypeSequence;
1274 uno::Reference<lang::XTypeProvider> xBaseProvider;
1275 if ( mxShapeAgg.is() )
1276 mxShapeAgg->queryAggregation( getCppuType((uno::Reference<lang::XTypeProvider>*) 0) ) >>= xBaseProvider;
1278 DBG_ASSERT( xBaseProvider.is(), "ScShapeObj: No XTypeProvider from aggregated shape!" );
1279 if( xBaseProvider.is() )
1281 aTypeSequence = xBaseProvider->getTypes();
1282 long nBaseLen = aTypeSequence.getLength();
1284 aTypeSequence.realloc( nBaseLen + 1 );
1285 uno::Type* pPtr = aTypeSequence.getArray();
1286 pPtr[nBaseLen + 0] = getCppuType((const uno::Reference<text::XTextContent>*)0);
1288 return aTypeSequence;
1291 uno::Sequence<sal_Int8> SAL_CALL ScShapeObj::getImplementationId()
1292 throw(uno::RuntimeException)
1294 ScUnoGuard aGuard;
1295 // do we need to compute the implementation id for this instance?
1296 if( !pImplementationId && mxShapeAgg.is())
1298 uno::Reference< drawing::XShape > xAggShape;
1299 mxShapeAgg->queryAggregation( ::getCppuType((uno::Reference< drawing::XShape >*)0) ) >>= xAggShape;
1301 if( xAggShape.is() )
1303 const rtl::OUString aShapeType( xAggShape->getShapeType() );
1304 // did we already compute an implementation id for the agregated shape type?
1305 ScShapeImplementationIdMap::iterator aIter( aImplementationIdMap.find(aShapeType ) );
1306 if( aIter == aImplementationIdMap.end() )
1308 // we need to create a new implementation id for this
1309 // note: this memory is not free'd until application exists
1310 // but since we have a fixed set of shapetypes and the
1311 // memory will be reused this is ok.
1312 pImplementationId = new uno::Sequence< sal_Int8 >( 16 );
1313 rtl_createUuid( (sal_uInt8 *) pImplementationId->getArray(), 0, sal_True );
1314 aImplementationIdMap[ aShapeType ] = pImplementationId;
1316 else
1318 // use the already computed implementation id
1319 pImplementationId = (*aIter).second;
1323 if( NULL == pImplementationId )
1325 DBG_ERROR( "Could not create an implementation id for a ScXShape!" );
1326 return uno::Sequence< sal_Int8 > ();
1328 else
1330 return *pImplementationId;
1334 SdrObject* ScShapeObj::GetSdrObject() const throw()
1336 if(mxShapeAgg.is())
1338 SvxShape* pShape = SvxShape::getImplementation( mxShapeAgg );
1339 if(pShape)
1340 return pShape->GetSdrObject();
1343 return NULL;
1346 #define SC_EVENTACC_ONCLICK ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnClick" ) )
1347 #define SC_EVENTACC_SCRIPT ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Script" ) )
1348 #define SC_EVENTACC_EVENTTYPE ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EventType" ) )
1350 typedef ::cppu::WeakImplHelper1< container::XNameReplace > ShapeUnoEventAcess_BASE;
1351 class ShapeUnoEventAccessImpl : public ShapeUnoEventAcess_BASE
1353 private:
1354 ScShapeObj* mpShape;
1356 ScMacroInfo* getInfo( BOOL bCreate = FALSE )
1358 return lcl_getShapeHyperMacroInfo( mpShape, bCreate );
1361 public:
1362 ShapeUnoEventAccessImpl( ScShapeObj* pShape ): mpShape( pShape )
1366 // XNameReplace
1367 virtual void SAL_CALL replaceByName( const rtl::OUString& aName, const uno::Any& aElement ) throw(lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
1369 if ( !hasByName( aName ) )
1370 throw container::NoSuchElementException();
1371 uno::Sequence< beans::PropertyValue > aProperties;
1372 aElement >>= aProperties;
1373 const beans::PropertyValue* pProperties = aProperties.getConstArray();
1374 const sal_Int32 nCount = aProperties.getLength();
1375 sal_Int32 nIndex;
1376 bool isEventType = false;
1377 for( nIndex = 0; nIndex < nCount; nIndex++, pProperties++ )
1379 if ( pProperties->Name.equals( SC_EVENTACC_EVENTTYPE ) )
1381 isEventType = true;
1382 continue;
1384 if ( isEventType && (pProperties->Name == SC_EVENTACC_SCRIPT) )
1386 rtl::OUString sValue;
1387 if ( pProperties->Value >>= sValue )
1389 ScMacroInfo* pInfo = getInfo( TRUE );
1390 DBG_ASSERT( pInfo, "shape macro info could not be created!" );
1391 if ( !pInfo )
1392 break;
1393 if ( pProperties->Name == SC_EVENTACC_SCRIPT )
1394 pInfo->SetMacro( sValue );
1395 else
1396 pInfo->SetHlink( sValue );
1402 // XNameAccess
1403 virtual uno::Any SAL_CALL getByName( const rtl::OUString& aName ) throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
1405 uno::Sequence< beans::PropertyValue > aProperties;
1406 ScMacroInfo* pInfo = getInfo();
1408 if ( aName == SC_EVENTACC_ONCLICK )
1410 if ( pInfo && (pInfo->GetMacro().getLength() > 0) )
1412 aProperties.realloc( 2 );
1413 aProperties[ 0 ].Name = SC_EVENTACC_EVENTTYPE;
1414 aProperties[ 0 ].Value <<= SC_EVENTACC_SCRIPT;
1415 aProperties[ 1 ].Name = SC_EVENTACC_SCRIPT;
1416 aProperties[ 1 ].Value <<= pInfo->GetMacro();
1419 else
1421 throw container::NoSuchElementException();
1424 return uno::Any( aProperties );
1427 virtual uno::Sequence< rtl::OUString > SAL_CALL getElementNames() throw(uno::RuntimeException)
1429 uno::Sequence< rtl::OUString > aSeq( 1 );
1430 aSeq[ 0 ] = SC_EVENTACC_ONCLICK;
1431 return aSeq;
1434 virtual sal_Bool SAL_CALL hasByName( const rtl::OUString& aName ) throw(uno::RuntimeException)
1436 return aName == SC_EVENTACC_ONCLICK;
1439 // XElementAccess
1440 virtual uno::Type SAL_CALL getElementType() throw(uno::RuntimeException)
1442 return *SEQTYPE(::getCppuType((const uno::Sequence< beans::PropertyValue >*)0));
1445 virtual sal_Bool SAL_CALL hasElements() throw(uno::RuntimeException)
1447 // elements are always present (but contained property sequences may be empty)
1448 return sal_True;
1452 ::uno::Reference< container::XNameReplace > SAL_CALL
1453 ScShapeObj::getEvents( ) throw(uno::RuntimeException)
1455 return new ShapeUnoEventAccessImpl( this );