1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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"
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 },
79 return aShapeMap_Impl
;
83 const SvEventDescription
* ScShapeObj::GetSupportedMacroItems()
85 static const SvEventDescription aMacroDescriptionsImpl
[] =
89 return aMacroDescriptionsImpl
;
91 // #i66550 HLINK_FOR_SHAPES
92 ScMacroInfo
* lcl_getShapeHyperMacroInfo( ScShapeObj
* pShape
, BOOL bCreate
= FALSE
)
95 if( SdrObject
* pObj
= pShape
->GetSdrObject() )
96 return ScDrawLayer::GetMacroInfo( pObj
, bCreate
);
100 //------------------------------------------------------------------------
102 ScShapeObj::ScShapeObj( uno::Reference
<drawing::XShape
>& xShape
) :
103 pShapePropertySet(NULL
),
104 pShapePropertyState(NULL
),
105 pImplementationId(NULL
),
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
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>());
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
)
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
);
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
;
204 xAgg
->queryAggregation( getCppuType((uno::Reference
<lang::XComponent
>*) 0) ) >>= xRet
;
208 uno::Reference
<text::XText
> lcl_GetText( const uno::Reference
<uno::XAggregation
>& xAgg
)
210 uno::Reference
<text::XText
> xRet
;
212 xAgg
->queryAggregation( getCppuType((uno::Reference
<text::XText
>*) 0) ) >>= xRet
;
216 uno::Reference
<text::XSimpleText
> lcl_GetSimpleText( const uno::Reference
<uno::XAggregation
>& xAgg
)
218 uno::Reference
<text::XSimpleText
> xRet
;
220 xAgg
->queryAggregation( getCppuType((uno::Reference
<text::XSimpleText
>*) 0) ) >>= xRet
;
224 uno::Reference
<text::XTextRange
> lcl_GetTextRange( const uno::Reference
<uno::XAggregation
>& xAgg
)
226 uno::Reference
<text::XTextRange
> xRet
;
228 xAgg
->queryAggregation( getCppuType((uno::Reference
<text::XTextRange
>*) 0) ) >>= xRet
;
234 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
ScShapeObj::getPropertySetInfo()
235 throw(uno::RuntimeException
)
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
);
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"));
274 uno::Reference
< beans::XPropertySet
> xShapeProp (xShape
, uno::UNO_QUERY
);
277 xShapeProp
->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "CaptionPoint" )) ) >>= rCaptionPoint
;
284 ScRange
lcl_GetAnchorCell( uno::Reference
< drawing::XShape
>& xShape
, ScDocument
* pDoc
, SCTAB nTab
,
285 awt::Point
& rUnoPoint
, awt::Size
& rUnoSize
, awt::Point
& rCaptionPoint
)
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
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
) ));
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
) ));
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();
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();
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
)
350 String
aNameString(aPropertyName
);
352 if ( aNameString
.EqualsAscii( SC_UNONAME_ANCHOR
) )
354 uno::Reference
<sheet::XCellRangeAddressable
> xRangeAdd(aValue
, uno::UNO_QUERY
);
357 SdrObject
*pObj
= GetSdrObject();
360 ScDrawLayer
* pModel
= (ScDrawLayer
*)pObj
->GetModel();
361 SdrPage
* pPage
= pObj
->GetPage();
362 if ( pModel
&& pPage
)
364 ScDocument
* pDoc
= pModel
->GetDocument();
367 SfxObjectShell
* pObjSh
= pDoc
->GetDocumentShell();
368 if ( pObjSh
&& pObjSh
->ISA(ScDocShell
) )
370 ScDocShell
* pDocSh
= (ScDocShell
*)pObjSh
;
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
);
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
);
397 if (pDoc
->IsNegativePage(nTab
))
399 aPoint
= aRect
.TopRight();
400 aEndPoint
= aRect
.BottomLeft();
404 aPoint
= aRect
.TopLeft();
405 aEndPoint
= aRect
.BottomRight();
408 awt::Point aCaptionPoint
;
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
;
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();
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();
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
);
463 // replace existing image map
464 pIMapInfo
->SetImageMap( aImageMap
);
468 // insert new user data with image map
469 pObj
->InsertUserData(new ScIMapInfo(aImageMap
) );
473 else if ( aNameString
.EqualsAscii( SC_UNONAME_HORIPOS
) )
478 SdrObject
*pObj
= GetSdrObject();
481 ScDrawLayer
* pModel
= (ScDrawLayer
*)pObj
->GetModel();
482 SdrPage
* pPage
= pObj
->GetPage();
483 if ( pModel
&& pPage
)
486 if ( lcl_GetPageNum( pPage
, *pModel
, nTab
) )
488 ScDocument
* pDoc
= pModel
->GetDocument();
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
);
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
))
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
;
517 if (aCaptionPoint
.X
< 0)
518 nPos
-= aCaptionPoint
.X
;
522 xShape
->setPosition(aPoint
);
523 pDocSh
->SetModified();
525 else if (ScDrawLayer::GetAnchor(pObj
) == SCA_CELL
)
528 awt::Point aCaptionPoint
;
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
))
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
;
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();
561 DBG_ERROR("unknown anchor type");
571 else if ( aNameString
.EqualsAscii( SC_UNONAME_VERTPOS
) )
576 SdrObject
*pObj
= GetSdrObject();
579 ScDrawLayer
* pModel
= (ScDrawLayer
*)pObj
->GetModel();
580 SdrPage
* pPage
= pObj
->GetPage();
581 if ( pModel
&& pPage
)
584 if ( lcl_GetPageNum( pPage
, *pModel
, nTab
) )
586 ScDocument
* pDoc
= pModel
->GetDocument();
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
);
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
;
606 xShape
->setPosition(aPoint
);
607 pDocSh
->SetModified();
609 else if (ScDrawLayer::GetAnchor(pObj
) == SCA_CELL
)
612 awt::Point aCaptionPoint
;
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());
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();
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
);
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
)
660 String aNameString
= aPropertyName
;
663 if ( aNameString
.EqualsAscii( SC_UNONAME_ANCHOR
) )
665 SdrObject
*pObj
= GetSdrObject();
668 ScDrawLayer
* pModel
= (ScDrawLayer
*)pObj
->GetModel();
669 SdrPage
* pPage
= pObj
->GetPage();
670 if ( pModel
&& pPage
)
672 ScDocument
* pDoc
= pModel
->GetDocument();
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
);
689 awt::Point aCaptionPoint
;
691 awt::Point
aUnoPoint(lcl_GetRelativePos( xShape
, pDoc
, nTab
, aRange
, aUnoSize
, aCaptionPoint
));
693 xAnchor
.set(static_cast<cppu::OWeakObject
*>(new ScCellObj( pDocSh
, aRange
.aStart
)));
698 xAnchor
.set(static_cast<cppu::OWeakObject
*>(new ScTableSheetObj( pDocSh
, nTab
)));
707 else if ( aNameString
.EqualsAscii( SC_UNONAME_IMAGEMAP
) )
709 uno::Reference
< uno::XInterface
> xImageMap
;
710 SdrObject
* pObj
= GetSdrObject();
713 ScIMapInfo
* pIMapInfo
= ScDrawLayer::GetIMapInfo(GetSdrObject());
716 const ImageMap
& rIMap
= pIMapInfo
->GetImageMap();
717 xImageMap
.set(SvUnoImageMap_createInstance( rIMap
, GetSupportedMacroItems() ));
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();
729 ScDrawLayer
* pModel
= (ScDrawLayer
*)pObj
->GetModel();
730 SdrPage
* pPage
= pObj
->GetPage();
731 if ( pModel
&& pPage
)
733 ScDocument
* pDoc
= pModel
->GetDocument();
737 if ( lcl_GetPageNum( pPage
, *pModel
, nTab
) )
739 uno::Reference
<drawing::XShape
> xShape( mxShapeAgg
, uno::UNO_QUERY
);
742 if (ScDrawLayer::GetAnchor(pObj
) == SCA_CELL
)
745 awt::Point aCaptionPoint
;
747 awt::Point
aUnoPoint(lcl_GetRelativePos( xShape
, pDoc
, nTab
, aRange
, aUnoSize
, aCaptionPoint
));
748 if (pDoc
->IsNegativePage(nTab
))
750 aAny
<<= aUnoPoint
.X
;
754 awt::Point aCaptionPoint
;
755 awt::Point
aUnoPoint(xShape
->getPosition());
756 awt::Size
aUnoSize(xShape
->getSize());
757 if (pDoc
->IsNegativePage(nTab
))
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
;
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();
788 ScDrawLayer
* pModel
= (ScDrawLayer
*)pObj
->GetModel();
789 SdrPage
* pPage
= pObj
->GetPage();
790 if ( pModel
&& pPage
)
792 ScDocument
* pDoc
= pModel
->GetDocument();
796 if ( lcl_GetPageNum( pPage
, *pModel
, nTab
) )
798 uno::Reference
<drawing::XShape
> xShape( mxShapeAgg
, uno::UNO_QUERY
);
801 uno::Reference
< uno::XInterface
> xAnchor
;
802 if (ScDrawLayer::GetAnchor(pObj
) == SCA_CELL
)
805 awt::Point aCaptionPoint
;
807 awt::Point
aUnoPoint(lcl_GetRelativePos( xShape
, pDoc
, nTab
, aRange
, aUnoSize
, aCaptionPoint
));
809 aAny
<<= aUnoPoint
.Y
;
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();
837 GetShapePropertySet();
838 if (pShapePropertySet
)
839 aAny
= pShapePropertySet
->getPropertyValue( aPropertyName
);
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
)
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
)
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
)
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
)
888 GetShapePropertySet();
889 if (pShapePropertySet
)
890 pShapePropertySet
->removeVetoableChangeListener( aPropertyName
, aListener
);
895 beans::PropertyState SAL_CALL
ScShapeObj::getPropertyState( const rtl::OUString
& aPropertyName
)
896 throw(beans::UnknownPropertyException
, uno::RuntimeException
)
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"
920 GetShapePropertyState();
921 if (pShapePropertyState
)
922 eRet
= pShapePropertyState
->getPropertyState( aPropertyName
);
928 uno::Sequence
<beans::PropertyState
> SAL_CALL
ScShapeObj::getPropertyStates(
929 const uno::Sequence
<rtl::OUString
>& aPropertyNames
)
930 throw(beans::UnknownPropertyException
, uno::RuntimeException
)
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
]);
944 void SAL_CALL
ScShapeObj::setPropertyToDefault( const rtl::OUString
& aPropertyName
)
945 throw(beans::UnknownPropertyException
, uno::RuntimeException
)
948 String
aNameString(aPropertyName
);
950 if ( aNameString
.EqualsAscii( SC_UNONAME_IMAGEMAP
) )
952 SdrObject
* pObj
= GetSdrObject();
955 ScIMapInfo
* pIMapInfo
= ScDrawLayer::GetIMapInfo(pObj
);
959 pIMapInfo
->SetImageMap( aEmpty
); // replace with empty image map
963 // nothing to do (no need to insert user data for an empty map)
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
)
980 String aNameString
= aPropertyName
;
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
);
991 GetShapePropertyState();
992 if (pShapePropertyState
)
993 aAny
= pShapePropertyState
->getPropertyDefault( aPropertyName
);
1001 void SAL_CALL
ScShapeObj::attach( const uno::Reference
<text::XTextRange
>& /* xTextRange */ )
1002 throw(lang::IllegalArgumentException
, uno::RuntimeException
)
1006 throw lang::IllegalArgumentException(); // anchor cannot be changed
1009 uno::Reference
<text::XTextRange
> SAL_CALL
ScShapeObj::getAnchor() throw(uno::RuntimeException
)
1013 uno::Reference
<text::XTextRange
> xRet
;
1015 SdrObject
* pObj
= GetSdrObject();
1018 ScDrawLayer
* pModel
= (ScDrawLayer
*)pObj
->GetModel();
1019 SdrPage
* pPage
= pObj
->GetPage();
1022 ScDocument
* pDoc
= pModel
->GetDocument();
1025 SfxObjectShell
* pObjSh
= pDoc
->GetDocumentShell();
1026 if ( pObjSh
&& pObjSh
->ISA(ScDocShell
) )
1028 ScDocShell
* pDocSh
= (ScDocShell
*)pObjSh
;
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
));
1050 void SAL_CALL
ScShapeObj::dispose() throw(uno::RuntimeException
)
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
)
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
)
1076 uno::Reference
<lang::XComponent
> xAggComp(lcl_GetComponent(mxShapeAgg
));
1077 if ( xAggComp
.is() )
1078 xAggComp
->removeEventListener(xListener
);
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
,
1100 throw(lang::IllegalArgumentException
, uno::RuntimeException
)
1104 uno::Reference
<text::XTextContent
> xEffContent
;
1106 ScCellFieldObj
* pCellField
= ScCellFieldObj::getImplementation( xContent
);
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
);
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
)
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
)
1147 if ( mxShapeAgg
.is() )
1149 // ScDrawTextCursor must be used to ensure the ScShapeObj is returned by getText
1151 SvxUnoTextBase
* pText
= SvxUnoTextBase::getImplementation( mxShapeAgg
);
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
)
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() );
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
)
1189 uno::Reference
<text::XSimpleText
> xAggSimpleText(lcl_GetSimpleText(mxShapeAgg
));
1190 if ( xAggSimpleText
.is() )
1191 xAggSimpleText
->insertString( xRange
, aString
, bAbsorb
);
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
)
1202 uno::Reference
<text::XSimpleText
> xAggSimpleText(lcl_GetSimpleText(mxShapeAgg
));
1203 if ( xAggSimpleText
.is() )
1204 xAggSimpleText
->insertControlCharacter( xRange
, nControlCharacter
, bAbsorb
);
1206 throw uno::RuntimeException();
1210 // (parent of XSimpleText)
1212 uno::Reference
<text::XText
> SAL_CALL
ScShapeObj::getText() throw(uno::RuntimeException
)
1218 uno::Reference
<text::XTextRange
> SAL_CALL
ScShapeObj::getStart() throw(uno::RuntimeException
)
1222 uno::Reference
<text::XTextRange
> xAggTextRange(lcl_GetTextRange(mxShapeAgg
));
1223 if ( xAggTextRange
.is() )
1224 return xAggTextRange
->getStart();
1226 throw uno::RuntimeException();
1228 // return uno::Reference<text::XTextRange>();
1231 uno::Reference
<text::XTextRange
> SAL_CALL
ScShapeObj::getEnd() throw(uno::RuntimeException
)
1235 uno::Reference
<text::XTextRange
> xAggTextRange(lcl_GetTextRange(mxShapeAgg
));
1236 if ( xAggTextRange
.is() )
1237 return xAggTextRange
->getEnd();
1239 throw uno::RuntimeException();
1241 // return uno::Reference<text::XTextRange>();
1244 rtl::OUString SAL_CALL
ScShapeObj::getString() throw(uno::RuntimeException
)
1248 uno::Reference
<text::XTextRange
> xAggTextRange(lcl_GetTextRange(mxShapeAgg
));
1249 if ( xAggTextRange
.is() )
1250 return xAggTextRange
->getString();
1252 throw uno::RuntimeException();
1254 // return rtl::OUString();
1257 void SAL_CALL
ScShapeObj::setString( const rtl::OUString
& aText
) throw(uno::RuntimeException
)
1261 uno::Reference
<text::XTextRange
> xAggTextRange(lcl_GetTextRange(mxShapeAgg
));
1262 if ( xAggTextRange
.is() )
1263 xAggTextRange
->setString( aText
);
1265 throw uno::RuntimeException();
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
)
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
;
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
> ();
1330 return *pImplementationId
;
1334 SdrObject
* ScShapeObj::GetSdrObject() const throw()
1338 SvxShape
* pShape
= SvxShape::getImplementation( mxShapeAgg
);
1340 return pShape
->GetSdrObject();
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
1354 ScShapeObj
* mpShape
;
1356 ScMacroInfo
* getInfo( BOOL bCreate
= FALSE
)
1358 return lcl_getShapeHyperMacroInfo( mpShape
, bCreate
);
1362 ShapeUnoEventAccessImpl( ScShapeObj
* pShape
): mpShape( pShape
)
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();
1376 bool isEventType
= false;
1377 for( nIndex
= 0; nIndex
< nCount
; nIndex
++, pProperties
++ )
1379 if ( pProperties
->Name
.equals( SC_EVENTACC_EVENTTYPE
) )
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!" );
1393 if ( pProperties
->Name
== SC_EVENTACC_SCRIPT
)
1394 pInfo
->SetMacro( sValue
);
1396 pInfo
->SetHlink( sValue
);
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();
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
;
1434 virtual sal_Bool SAL_CALL
hasByName( const rtl::OUString
& aName
) throw(uno::RuntimeException
)
1436 return aName
== SC_EVENTACC_ONCLICK
;
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)
1452 ::uno::Reference
< container::XNameReplace
> SAL_CALL
1453 ScShapeObj::getEvents( ) throw(uno::RuntimeException
)
1455 return new ShapeUnoEventAccessImpl( this );