1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <comphelper/sequence.hxx>
23 #include <svtools/unoevent.hxx>
24 #include <svtools/unoimap.hxx>
25 #include <svx/svdobj.hxx>
26 #include <vcl/svapp.hxx>
27 #include <svx/unoshape.hxx>
28 #include <editeng/unofield.hxx>
29 #include <svx/shapepropertynotifier.hxx>
30 #include <toolkit/helper/convert.hxx>
31 #include <cppuhelper/implbase2.hxx>
32 #include <cppuhelper/supportsservice.hxx>
34 #include <com/sun/star/drawing/XShape.hpp>
35 #include <com/sun/star/beans/PropertyAttribute.hpp>
37 #include "shapeuno.hxx"
38 #include "miscuno.hxx"
39 #include "cellsuno.hxx"
40 #include "textuno.hxx"
41 #include "fielduno.hxx"
43 #include "drwlayer.hxx"
44 #include "userdat.hxx"
45 #include "unonames.hxx"
47 using namespace ::com::sun::star
;
49 static const SfxItemPropertyMapEntry
* lcl_GetShapeMap()
51 static const SfxItemPropertyMapEntry aShapeMap_Impl
[] =
53 {OUString(SC_UNONAME_ANCHOR
), 0, cppu::UnoType
<uno::XInterface
>::get(), 0, 0 },
54 {OUString(SC_UNONAME_HORIPOS
), 0, cppu::UnoType
<sal_Int32
>::get(), 0, 0 },
55 {OUString(SC_UNONAME_IMAGEMAP
), 0, cppu::UnoType
<container::XIndexContainer
>::get(), 0, 0 },
56 {OUString(SC_UNONAME_VERTPOS
), 0, cppu::UnoType
<sal_Int32
>::get(), 0, 0 },
57 {OUString(SC_UNONAME_MOVEPROTECT
), 0, cppu::UnoType
<sal_Bool
>::get(), 0, 0 },
58 // #i66550 HLINK_FOR_SHAPES
59 {OUString(SC_UNONAME_HYPERLINK
), 0, cppu::UnoType
<OUString
>::get(), 0, 0 },
60 {OUString(SC_UNONAME_URL
), 0, cppu::UnoType
<OUString
>::get(), 0, 0 },
61 { OUString(), 0, css::uno::Type(), 0, 0 }
63 return aShapeMap_Impl
;
66 const SvEventDescription
* ScShapeObj::GetSupportedMacroItems()
68 static const SvEventDescription aMacroDescriptionsImpl
[] =
72 return aMacroDescriptionsImpl
;
74 // #i66550 HLINK_FOR_SHAPES
75 ScMacroInfo
* ScShapeObj_getShapeHyperMacroInfo( ScShapeObj
* pShape
, bool bCreate
= false )
78 if( SdrObject
* pObj
= pShape
->GetSdrObject() )
79 return ScDrawLayer::GetMacroInfo( pObj
, bCreate
);
85 void lcl_initializeNotifier( SdrObject
& _rSdrObj
, ::cppu::OWeakObject
& _rShape
)
87 svx::PPropertyValueProvider
pProvider( new svx::PropertyValueProvider( _rShape
, "Anchor" ) );
88 _rSdrObj
.getShapePropertyChangeNotifier().registerProvider( svx::eSpreadsheetAnchor
, pProvider
);
92 ScShapeObj::ScShapeObj( uno::Reference
<drawing::XShape
>& xShape
) :
93 pShapePropertySet(NULL
),
94 pShapePropertyState(NULL
),
96 bIsNoteCaption(false),
97 bInitializedNotifier(false)
99 osl_atomic_increment( &m_refCount
);
102 mxShapeAgg
= uno::Reference
<uno::XAggregation
>( xShape
, uno::UNO_QUERY
);
103 // extra block to force deletion of the temporary before setDelegator
108 xShape
= NULL
; // during setDelegator, mxShapeAgg must be the only ref
110 mxShapeAgg
->setDelegator( (cppu::OWeakObject
*)this );
112 xShape
.set(uno::Reference
<drawing::XShape
>( mxShapeAgg
, uno::UNO_QUERY
));
114 bIsTextShape
= ( SvxUnoTextBase::getImplementation( mxShapeAgg
) != NULL
);
118 SdrObject
* pObj
= GetSdrObject();
121 bIsNoteCaption
= ScDrawLayer::IsNoteCaption( pObj
);
122 lcl_initializeNotifier( *pObj
, *this );
123 bInitializedNotifier
= true;
127 osl_atomic_decrement( &m_refCount
);
130 ScShapeObj::~ScShapeObj()
132 // if (mxShapeAgg.is())
133 // mxShapeAgg->setDelegator(uno::Reference<uno::XInterface>());
138 uno::Any SAL_CALL
ScShapeObj::queryInterface( const uno::Type
& rType
)
139 throw(uno::RuntimeException
, std::exception
)
141 uno::Any aRet
= ScShapeObj_Base::queryInterface( rType
);
143 if ( !aRet
.hasValue() && bIsTextShape
)
144 aRet
= ScShapeObj_TextBase::queryInterface( rType
);
146 if ( !aRet
.hasValue() && bIsNoteCaption
)
147 aRet
= ScShapeObj_ChildBase::queryInterface( rType
);
149 if ( !aRet
.hasValue() && mxShapeAgg
.is() )
150 aRet
= mxShapeAgg
->queryAggregation( rType
);
155 void SAL_CALL
ScShapeObj::acquire() throw()
157 OWeakObject::acquire();
160 void SAL_CALL
ScShapeObj::release() throw()
162 OWeakObject::release();
165 void ScShapeObj::GetShapePropertySet()
167 // #i61908# Store the result of queryAggregation in a member.
168 // The reference in mxShapeAgg is kept for this object's lifetime, so the pointer is always valid.
170 if (!pShapePropertySet
)
172 uno::Reference
<beans::XPropertySet
> xProp
;
173 if ( mxShapeAgg
.is() )
174 mxShapeAgg
->queryAggregation( cppu::UnoType
<beans::XPropertySet
>::get()) >>= xProp
;
175 pShapePropertySet
= xProp
.get();
179 void ScShapeObj::GetShapePropertyState()
181 // #i61908# Store the result of queryAggregation in a member.
182 // The reference in mxShapeAgg is kept for this object's lifetime, so the pointer is always valid.
184 if (!pShapePropertyState
)
186 uno::Reference
<beans::XPropertyState
> xState
;
187 if ( mxShapeAgg
.is() )
188 mxShapeAgg
->queryAggregation( cppu::UnoType
<beans::XPropertyState
>::get()) >>= xState
;
189 pShapePropertyState
= xState
.get();
193 static uno::Reference
<lang::XComponent
> lcl_GetComponent( const uno::Reference
<uno::XAggregation
>& xAgg
)
195 uno::Reference
<lang::XComponent
> xRet
;
197 xAgg
->queryAggregation( cppu::UnoType
<lang::XComponent
>::get()) >>= xRet
;
201 static uno::Reference
<text::XText
> lcl_GetText( const uno::Reference
<uno::XAggregation
>& xAgg
)
203 uno::Reference
<text::XText
> xRet
;
205 xAgg
->queryAggregation( cppu::UnoType
<text::XText
>::get()) >>= xRet
;
209 static uno::Reference
<text::XSimpleText
> lcl_GetSimpleText( const uno::Reference
<uno::XAggregation
>& xAgg
)
211 uno::Reference
<text::XSimpleText
> xRet
;
213 xAgg
->queryAggregation( cppu::UnoType
<text::XSimpleText
>::get()) >>= xRet
;
217 static uno::Reference
<text::XTextRange
> lcl_GetTextRange( const uno::Reference
<uno::XAggregation
>& xAgg
)
219 uno::Reference
<text::XTextRange
> xRet
;
221 xAgg
->queryAggregation( cppu::UnoType
<text::XTextRange
>::get()) >>= xRet
;
227 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
ScShapeObj::getPropertySetInfo()
228 throw(uno::RuntimeException
, std::exception
)
230 SolarMutexGuard aGuard
;
232 // #i61527# cache property set info for this object
233 if ( !mxPropSetInfo
.is() )
235 // mix own and aggregated properties:
236 GetShapePropertySet();
237 if (pShapePropertySet
)
239 uno::Reference
<beans::XPropertySetInfo
> xAggInfo(pShapePropertySet
->getPropertySetInfo());
240 const uno::Sequence
<beans::Property
> aPropSeq(xAggInfo
->getProperties());
241 mxPropSetInfo
.set(new SfxExtItemPropertySetInfo( lcl_GetShapeMap(), aPropSeq
));
244 return mxPropSetInfo
;
247 static bool lcl_GetPageNum( SdrPage
* pPage
, SdrModel
& rModel
, SCTAB
& rNum
)
249 sal_uInt16 nCount
= rModel
.GetPageCount();
250 for (sal_uInt16 i
=0; i
<nCount
; i
++)
251 if ( rModel
.GetPage(i
) == pPage
)
253 rNum
= static_cast<SCTAB
>(i
);
260 static bool lcl_GetCaptionPoint( uno::Reference
< drawing::XShape
>& xShape
, awt::Point
& rCaptionPoint
)
262 bool bReturn
= false;
263 OUString
sType(xShape
->getShapeType());
264 bool bCaptionShape( sType
== "com.sun.star.drawing.CaptionShape" );
267 uno::Reference
< beans::XPropertySet
> xShapeProp (xShape
, uno::UNO_QUERY
);
270 xShapeProp
->getPropertyValue("CaptionPoint") >>= rCaptionPoint
;
277 static ScRange
lcl_GetAnchorCell( uno::Reference
< drawing::XShape
>& xShape
, ScDocument
* pDoc
, SCTAB nTab
,
278 awt::Point
& rUnoPoint
, awt::Size
& rUnoSize
, awt::Point
& rCaptionPoint
)
281 rUnoPoint
= xShape
->getPosition();
282 bool bCaptionShape(lcl_GetCaptionPoint(xShape
, rCaptionPoint
));
283 if (pDoc
->IsNegativePage(nTab
))
285 rUnoSize
= xShape
->getSize();
286 rUnoPoint
.X
+= rUnoSize
.Width
; // the right top point is base
289 if (rCaptionPoint
.X
> 0 && rCaptionPoint
.X
> rUnoSize
.Width
)
290 rUnoPoint
.X
+= rCaptionPoint
.X
- rUnoSize
.Width
;
291 if (rCaptionPoint
.Y
< 0)
292 rUnoPoint
.Y
+= rCaptionPoint
.Y
;
294 aReturn
= pDoc
->GetRange( nTab
, Rectangle( VCLPoint(rUnoPoint
), VCLPoint(rUnoPoint
) ));
300 if (rCaptionPoint
.X
< 0)
301 rUnoPoint
.X
+= rCaptionPoint
.X
;
302 if (rCaptionPoint
.Y
< 0)
303 rUnoPoint
.Y
+= rCaptionPoint
.Y
;
305 aReturn
= pDoc
->GetRange( nTab
, Rectangle( VCLPoint(rUnoPoint
), VCLPoint(rUnoPoint
) ));
311 static awt::Point
lcl_GetRelativePos( uno::Reference
< drawing::XShape
>& xShape
, ScDocument
* pDoc
, SCTAB nTab
, ScRange
& rRange
,
312 awt::Size
& rUnoSize
, awt::Point
& rCaptionPoint
)
314 awt::Point aUnoPoint
;
315 rRange
= lcl_GetAnchorCell(xShape
, pDoc
, nTab
, aUnoPoint
, rUnoSize
, rCaptionPoint
);
316 Rectangle
aRect(pDoc
->GetMMRect( rRange
.aStart
.Col(), rRange
.aStart
.Row(), rRange
.aEnd
.Col(), rRange
.aEnd
.Row(), rRange
.aStart
.Tab() ));
317 Point aPoint
= pDoc
->IsNegativePage(nTab
) ? aRect
.TopRight() : aRect
.TopLeft();
318 aUnoPoint
.X
-= aPoint
.X();
319 aUnoPoint
.Y
-= aPoint
.Y();
323 void SAL_CALL
ScShapeObj::setPropertyValue(const OUString
& aPropertyName
, const uno::Any
& aValue
)
324 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
325 lang::IllegalArgumentException
, lang::WrappedTargetException
,
326 uno::RuntimeException
, std::exception
)
328 SolarMutexGuard aGuard
;
329 OUString
aNameString(aPropertyName
);
331 if ( aNameString
== SC_UNONAME_ANCHOR
)
333 uno::Reference
<sheet::XCellRangeAddressable
> xRangeAdd(aValue
, uno::UNO_QUERY
);
336 SdrObject
*pObj
= GetSdrObject();
339 ScDrawLayer
* pModel
= static_cast<ScDrawLayer
*>(pObj
->GetModel());
340 SdrPage
* pPage
= pObj
->GetPage();
341 if ( pModel
&& pPage
)
343 ScDocument
* pDoc
= pModel
->GetDocument();
346 SfxObjectShell
* pObjSh
= pDoc
->GetDocumentShell();
347 if ( pObjSh
&& pObjSh
->ISA(ScDocShell
) )
349 ScDocShell
* pDocSh
= static_cast<ScDocShell
*>(pObjSh
);
352 if ( lcl_GetPageNum( pPage
, *pModel
, nTab
) )
354 table::CellRangeAddress aAddress
= xRangeAdd
->getRangeAddress();
355 if (nTab
== aAddress
.Sheet
)
357 Rectangle
aRect(pDoc
->GetMMRect( static_cast<SCCOL
>(aAddress
.StartColumn
), static_cast<SCROW
>(aAddress
.StartRow
),
358 static_cast<SCCOL
>(aAddress
.EndColumn
), static_cast<SCROW
>(aAddress
.EndRow
), aAddress
.Sheet
));
359 awt::Point aRelPoint
;
360 uno::Reference
<drawing::XShape
> xShape( mxShapeAgg
, uno::UNO_QUERY
);
365 if (pDoc
->IsNegativePage(nTab
))
367 aPoint
= aRect
.TopRight();
368 aEndPoint
= aRect
.BottomLeft();
372 aPoint
= aRect
.TopLeft();
373 aEndPoint
= aRect
.BottomRight();
376 awt::Point aCaptionPoint
;
378 aRelPoint
= lcl_GetRelativePos( xShape
, pDoc
, nTab
, aRange
, aUnoSize
, aCaptionPoint
);
379 awt::Point
aUnoPoint(aRelPoint
);
381 aUnoPoint
.X
+= aPoint
.X();
382 aUnoPoint
.Y
+= aPoint
.Y();
384 if ( aUnoPoint
.Y
> aEndPoint
.Y() )
385 aUnoPoint
.Y
= aEndPoint
.Y() - 2;
386 if (pDoc
->IsNegativePage(nTab
))
388 if ( aUnoPoint
.X
< aEndPoint
.X() )
389 aUnoPoint
.X
= aEndPoint
.X() + 2;
390 aUnoPoint
.X
-= aUnoSize
.Width
;
391 // remove difference to caption point
392 if (aCaptionPoint
.X
> 0 && aCaptionPoint
.X
> aUnoSize
.Width
)
393 aUnoPoint
.X
-= aCaptionPoint
.X
- aUnoSize
.Width
;
397 if ( aUnoPoint
.X
> aEndPoint
.X() )
398 aUnoPoint
.X
= aEndPoint
.X() - 2;
399 if (aCaptionPoint
.X
< 0)
400 aUnoPoint
.X
-= aCaptionPoint
.X
;
402 if (aCaptionPoint
.Y
< 0)
403 aUnoPoint
.Y
-= aCaptionPoint
.Y
;
405 xShape
->setPosition(aUnoPoint
);
406 pDocSh
->SetModified();
409 if (aAddress
.StartRow
!= aAddress
.EndRow
) //should be a Spreadsheet
411 OSL_ENSURE(aAddress
.StartRow
== 0 && aAddress
.EndRow
== MAXROW
&&
412 aAddress
.StartColumn
== 0 && aAddress
.EndColumn
== MAXCOL
, "here should be a XSpreadsheet");
413 ScDrawLayer::SetPageAnchored(*pObj
);
417 OSL_ENSURE(aAddress
.StartRow
== aAddress
.EndRow
&&
418 aAddress
.StartColumn
== aAddress
.EndColumn
, "here should be a XCell");
419 ScDrawObjData aAnchor
;
420 aAnchor
.maStart
= ScAddress(aAddress
.StartColumn
, aAddress
.StartRow
, aAddress
.Sheet
);
421 aAnchor
.maStartOffset
= Point(aRelPoint
.X
, aRelPoint
.Y
);
422 //Uno sets the Anchor in terms of the unorotated shape, not much we can do
423 //about that since uno also displays the shape geometry in terms of the unrotated
424 //shape. #TODO think about changing the anchoring behaviour here too
425 //Currently we've only got a start anchor, not an end-anchor, so generate that now
426 ScDrawLayer::UpdateCellAnchorFromPositionEnd(*pObj
, aAnchor
, *pDoc
, aAddress
.Sheet
);
427 ScDrawLayer::SetCellAnchored(*pObj
, aAnchor
);
437 throw lang::IllegalArgumentException("only XCell or XSpreadsheet objects allowed", static_cast<cppu::OWeakObject
*>(this), 0);
439 else if ( aNameString
== SC_UNONAME_IMAGEMAP
)
441 SdrObject
* pObj
= GetSdrObject();
445 uno::Reference
< uno::XInterface
> xImageMapInt(aValue
, uno::UNO_QUERY
);
447 if( !xImageMapInt
.is() || !SvUnoImageMap_fillImageMap( xImageMapInt
, aImageMap
) )
448 throw lang::IllegalArgumentException();
450 ScIMapInfo
* pIMapInfo
= ScDrawLayer::GetIMapInfo(pObj
);
453 // replace existing image map
454 pIMapInfo
->SetImageMap( aImageMap
);
458 // insert new user data with image map
459 pObj
->AppendUserData(new ScIMapInfo(aImageMap
) );
463 else if ( aNameString
== SC_UNONAME_HORIPOS
)
468 SdrObject
*pObj
= GetSdrObject();
471 ScDrawLayer
* pModel
= static_cast<ScDrawLayer
*>(pObj
->GetModel());
472 SdrPage
* pPage
= pObj
->GetPage();
473 if ( pModel
&& pPage
)
476 if ( lcl_GetPageNum( pPage
, *pModel
, nTab
) )
478 ScDocument
* pDoc
= pModel
->GetDocument();
481 SfxObjectShell
* pObjSh
= pDoc
->GetDocumentShell();
482 if ( pObjSh
&& pObjSh
->ISA(ScDocShell
) )
484 ScDocShell
* pDocSh
= static_cast<ScDocShell
*>(pObjSh
);
485 uno::Reference
<drawing::XShape
> xShape( mxShapeAgg
, uno::UNO_QUERY
);
488 if (ScDrawLayer::GetAnchorType(*pObj
) == SCA_PAGE
)
490 awt::Point
aPoint(xShape
->getPosition());
491 awt::Size
aSize(xShape
->getSize());
492 awt::Point aCaptionPoint
;
493 if (pDoc
->IsNegativePage(nTab
))
498 if (lcl_GetCaptionPoint(xShape
, aCaptionPoint
))
500 if (pDoc
->IsNegativePage(nTab
))
502 if (aCaptionPoint
.X
> 0 && aCaptionPoint
.X
> aSize
.Width
)
503 nPos
-= aCaptionPoint
.X
- aSize
.Width
;
507 if (aCaptionPoint
.X
< 0)
508 nPos
-= aCaptionPoint
.X
;
512 xShape
->setPosition(aPoint
);
513 pDocSh
->SetModified();
515 else if (ScDrawLayer::GetAnchorType(*pObj
) == SCA_CELL
)
518 awt::Point aCaptionPoint
;
520 awt::Point
aUnoPoint(lcl_GetRelativePos( xShape
, pDoc
, nTab
, aRange
, aUnoSize
, aCaptionPoint
));
521 Rectangle
aRect(pDoc
->GetMMRect( aRange
.aStart
.Col(), aRange
.aStart
.Row(), aRange
.aEnd
.Col(), aRange
.aEnd
.Row(), aRange
.aStart
.Tab() ));
522 if (pDoc
->IsNegativePage(nTab
))
525 Point
aPoint(aRect
.TopRight());
526 Point
aEndPoint(aRect
.BottomLeft());
527 aUnoPoint
.X
+= aPoint
.X();
528 if (aUnoPoint
.X
< aEndPoint
.X())
529 aUnoPoint
.X
= aEndPoint
.X() + 2;
530 aUnoPoint
.X
-= aUnoSize
.Width
;
531 if (aCaptionPoint
.X
> 0 && aCaptionPoint
.X
> aUnoSize
.Width
)
532 aUnoPoint
.X
-= aCaptionPoint
.X
- aUnoSize
.Width
;
537 Point
aPoint(aRect
.TopLeft());
538 Point
aEndPoint(aRect
.BottomRight());
539 aUnoPoint
.X
+= aPoint
.X();
540 if (aUnoPoint
.X
> aEndPoint
.X())
541 aUnoPoint
.X
= aEndPoint
.X() - 2;
542 if (aCaptionPoint
.X
< 0)
543 aUnoPoint
.X
-= aCaptionPoint
.X
;
545 aUnoPoint
.Y
= xShape
->getPosition().Y
;
546 xShape
->setPosition(aUnoPoint
);
547 pDocSh
->SetModified();
551 OSL_FAIL("unknown anchor type");
561 else if ( aNameString
== SC_UNONAME_VERTPOS
)
566 SdrObject
*pObj
= GetSdrObject();
569 ScDrawLayer
* pModel
= static_cast<ScDrawLayer
*>(pObj
->GetModel());
570 SdrPage
* pPage
= pObj
->GetPage();
571 if ( pModel
&& pPage
)
574 if ( lcl_GetPageNum( pPage
, *pModel
, nTab
) )
576 ScDocument
* pDoc
= pModel
->GetDocument();
579 SfxObjectShell
* pObjSh
= pDoc
->GetDocumentShell();
580 if ( pObjSh
&& pObjSh
->ISA(ScDocShell
) )
582 ScDocShell
* pDocSh
= static_cast<ScDocShell
*>(pObjSh
);
583 uno::Reference
<drawing::XShape
> xShape( mxShapeAgg
, uno::UNO_QUERY
);
586 if (ScDrawLayer::GetAnchorType(*pObj
) == SCA_PAGE
)
588 awt::Point aPoint
= xShape
->getPosition();
589 awt::Point aCaptionPoint
;
590 if (lcl_GetCaptionPoint(xShape
, aCaptionPoint
))
592 if (aCaptionPoint
.Y
< 0)
593 nPos
-= aCaptionPoint
.Y
;
596 xShape
->setPosition(aPoint
);
597 pDocSh
->SetModified();
599 else if (ScDrawLayer::GetAnchorType(*pObj
) == SCA_CELL
)
602 awt::Point aCaptionPoint
;
604 awt::Point
aUnoPoint(lcl_GetRelativePos( xShape
, pDoc
, nTab
, aRange
, aUnoSize
, aCaptionPoint
));
605 Rectangle
aRect(pDoc
->GetMMRect( aRange
.aStart
.Col(), aRange
.aStart
.Row(), aRange
.aEnd
.Col(), aRange
.aEnd
.Row(), aRange
.aStart
.Tab() ));
606 Point
aPoint(aRect
.TopRight());
607 Point
aEndPoint(aRect
.BottomLeft());
609 aUnoPoint
.Y
+= aPoint
.Y();
610 if (aUnoPoint
.Y
> aEndPoint
.Y())
611 aUnoPoint
.Y
= aEndPoint
.Y() - 2;
612 if (aCaptionPoint
.Y
< 0)
613 aUnoPoint
.Y
-= aCaptionPoint
.Y
;
614 aUnoPoint
.X
= xShape
->getPosition().X
;
615 xShape
->setPosition(aUnoPoint
);
616 pDocSh
->SetModified();
620 OSL_FAIL("unknown anchor type");
630 else if ( aNameString
== SC_UNONAME_HYPERLINK
||
631 aNameString
== SC_UNONAME_URL
)
634 ScMacroInfo
* pInfo
= ScShapeObj_getShapeHyperMacroInfo(this, true);
635 if ( ( aValue
>>= sHlink
) && pInfo
)
636 pInfo
->SetHlink( sHlink
);
638 else if ( aNameString
== SC_UNONAME_MOVEPROTECT
)
640 if( SdrObject
* pObj
= this->GetSdrObject() )
643 if( aValue
>>= aProt
)
644 pObj
->SetMoveProtect( aProt
);
649 GetShapePropertySet();
650 if (pShapePropertySet
)
651 pShapePropertySet
->setPropertyValue( aPropertyName
, aValue
);
655 uno::Any SAL_CALL
ScShapeObj::getPropertyValue( const OUString
& aPropertyName
)
656 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
657 uno::RuntimeException
, std::exception
)
659 SolarMutexGuard aGuard
;
660 OUString aNameString
= aPropertyName
;
663 if ( aNameString
== SC_UNONAME_ANCHOR
)
665 SdrObject
*pObj
= GetSdrObject();
668 ScDrawLayer
* pModel
= static_cast<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
= static_cast<ScDocShell
*>(pObjSh
);
682 uno::Reference
< uno::XInterface
> xAnchor
;
683 if (ScDrawObjData
*pAnchor
= ScDrawLayer::GetObjDataTab(pObj
, nTab
))
684 xAnchor
.set(static_cast<cppu::OWeakObject
*>(new ScCellObj( pDocSh
, pAnchor
->maStart
)));
686 xAnchor
.set(static_cast<cppu::OWeakObject
*>(new ScTableSheetObj( pDocSh
, nTab
)));
694 else if ( aNameString
== SC_UNONAME_IMAGEMAP
)
696 uno::Reference
< uno::XInterface
> xImageMap
;
697 SdrObject
* pObj
= GetSdrObject();
700 ScIMapInfo
* pIMapInfo
= ScDrawLayer::GetIMapInfo(GetSdrObject());
703 const ImageMap
& rIMap
= pIMapInfo
->GetImageMap();
704 xImageMap
.set(SvUnoImageMap_createInstance( rIMap
, GetSupportedMacroItems() ));
707 xImageMap
= SvUnoImageMap_createInstance( GetSupportedMacroItems() );
709 aAny
<<= uno::Reference
< container::XIndexContainer
>::query( xImageMap
);
711 else if ( aNameString
== SC_UNONAME_HORIPOS
)
713 SdrObject
*pObj
= GetSdrObject();
716 ScDrawLayer
* pModel
= static_cast<ScDrawLayer
*>(pObj
->GetModel());
717 SdrPage
* pPage
= pObj
->GetPage();
718 if ( pModel
&& pPage
)
720 ScDocument
* pDoc
= pModel
->GetDocument();
724 if ( lcl_GetPageNum( pPage
, *pModel
, nTab
) )
726 uno::Reference
<drawing::XShape
> xShape( mxShapeAgg
, uno::UNO_QUERY
);
729 if (ScDrawLayer::GetAnchorType(*pObj
) == SCA_CELL
)
732 awt::Point aCaptionPoint
;
734 awt::Point
aUnoPoint(lcl_GetRelativePos( xShape
, pDoc
, nTab
, aRange
, aUnoSize
, aCaptionPoint
));
735 if (pDoc
->IsNegativePage(nTab
))
737 aAny
<<= aUnoPoint
.X
;
741 awt::Point aCaptionPoint
;
742 awt::Point
aUnoPoint(xShape
->getPosition());
743 awt::Size
aUnoSize(xShape
->getSize());
744 if (pDoc
->IsNegativePage(nTab
))
747 aUnoPoint
.X
-= aUnoSize
.Width
;
749 if (lcl_GetCaptionPoint(xShape
, aCaptionPoint
))
751 if (pDoc
->IsNegativePage(nTab
))
753 if (aCaptionPoint
.X
> 0 && aCaptionPoint
.X
> aUnoSize
.Width
)
754 aUnoPoint
.X
-= aCaptionPoint
.X
- aUnoSize
.Width
;
758 if (aCaptionPoint
.X
< 0)
759 aUnoPoint
.X
+= aCaptionPoint
.X
;
762 aAny
<<= aUnoPoint
.X
;
770 else if ( aNameString
== SC_UNONAME_VERTPOS
)
772 SdrObject
*pObj
= GetSdrObject();
775 ScDrawLayer
* pModel
= static_cast<ScDrawLayer
*>(pObj
->GetModel());
776 SdrPage
* pPage
= pObj
->GetPage();
777 if ( pModel
&& pPage
)
779 ScDocument
* pDoc
= pModel
->GetDocument();
783 if ( lcl_GetPageNum( pPage
, *pModel
, nTab
) )
785 uno::Reference
<drawing::XShape
> xShape( mxShapeAgg
, uno::UNO_QUERY
);
788 uno::Reference
< uno::XInterface
> xAnchor
;
789 if (ScDrawLayer::GetAnchorType(*pObj
) == SCA_CELL
)
792 awt::Point aCaptionPoint
;
794 awt::Point
aUnoPoint(lcl_GetRelativePos( xShape
, pDoc
, nTab
, aRange
, aUnoSize
, aCaptionPoint
));
796 aAny
<<= aUnoPoint
.Y
;
800 awt::Point
aUnoPoint(xShape
->getPosition());
801 awt::Point aCaptionPoint
;
802 if (lcl_GetCaptionPoint(xShape
, aCaptionPoint
))
804 if (aCaptionPoint
.Y
< 0)
805 aUnoPoint
.Y
+= aCaptionPoint
.Y
;
807 aAny
<<= aUnoPoint
.Y
;
815 else if ( aNameString
== SC_UNONAME_HYPERLINK
||
816 aNameString
== SC_UNONAME_URL
)
819 if ( ScMacroInfo
* pInfo
= ScShapeObj_getShapeHyperMacroInfo(this) )
820 sHlink
= pInfo
->GetHlink();
823 else if ( aNameString
== SC_UNONAME_MOVEPROTECT
)
826 if ( SdrObject
* pObj
= this->GetSdrObject() )
827 aProt
= pObj
->IsMoveProtect();
832 if(!pShapePropertySet
) //performance consideration
833 GetShapePropertySet();
834 if (pShapePropertySet
)
835 aAny
= pShapePropertySet
->getPropertyValue( aPropertyName
);
841 void SAL_CALL
ScShapeObj::addPropertyChangeListener( const OUString
& aPropertyName
,
842 const uno::Reference
<beans::XPropertyChangeListener
>& aListener
)
843 throw(beans::UnknownPropertyException
,
844 lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
846 SolarMutexGuard aGuard
;
848 GetShapePropertySet();
849 if (pShapePropertySet
)
850 pShapePropertySet
->addPropertyChangeListener( aPropertyName
, aListener
);
852 if ( !bInitializedNotifier
)
854 // here's the latest chance to initialize the property notification at the SdrObject
855 // (in the ctor, where we also attempt to do this, we do not necessarily have
856 // and SdrObject, yet)
857 SdrObject
* pObj
= GetSdrObject();
858 OSL_ENSURE( pObj
, "ScShapeObj::addPropertyChangeListener: no SdrObject -> no property change notification!" );
860 lcl_initializeNotifier( *pObj
, *this );
861 bInitializedNotifier
= true;
865 void SAL_CALL
ScShapeObj::removePropertyChangeListener( const OUString
& aPropertyName
,
866 const uno::Reference
<beans::XPropertyChangeListener
>& aListener
)
867 throw(beans::UnknownPropertyException
,
868 lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
870 SolarMutexGuard aGuard
;
872 GetShapePropertySet();
873 if (pShapePropertySet
)
874 pShapePropertySet
->removePropertyChangeListener( aPropertyName
, aListener
);
877 void SAL_CALL
ScShapeObj::addVetoableChangeListener( const OUString
& aPropertyName
,
878 const uno::Reference
<beans::XVetoableChangeListener
>& aListener
)
879 throw(beans::UnknownPropertyException
,
880 lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
882 SolarMutexGuard aGuard
;
884 GetShapePropertySet();
885 if (pShapePropertySet
)
886 pShapePropertySet
->addVetoableChangeListener( aPropertyName
, aListener
);
889 void SAL_CALL
ScShapeObj::removeVetoableChangeListener( const OUString
& aPropertyName
,
890 const uno::Reference
<beans::XVetoableChangeListener
>& aListener
)
891 throw(beans::UnknownPropertyException
,
892 lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
894 SolarMutexGuard aGuard
;
896 GetShapePropertySet();
897 if (pShapePropertySet
)
898 pShapePropertySet
->removeVetoableChangeListener( aPropertyName
, aListener
);
903 beans::PropertyState SAL_CALL
ScShapeObj::getPropertyState( const OUString
& aPropertyName
)
904 throw(beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
906 SolarMutexGuard aGuard
;
907 OUString
aNameString(aPropertyName
);
909 beans::PropertyState eRet
= beans::PropertyState_DIRECT_VALUE
;
910 if ( aNameString
== SC_UNONAME_IMAGEMAP
)
912 // ImageMap is always "direct"
914 else if ( aNameString
== SC_UNONAME_ANCHOR
)
916 // Anchor is always "direct"
918 else if ( aNameString
== SC_UNONAME_HORIPOS
)
920 // HoriPos is always "direct"
922 else if ( aNameString
== SC_UNONAME_VERTPOS
)
924 // VertPos is always "direct"
928 GetShapePropertyState();
929 if (pShapePropertyState
)
930 eRet
= pShapePropertyState
->getPropertyState( aPropertyName
);
936 uno::Sequence
<beans::PropertyState
> SAL_CALL
ScShapeObj::getPropertyStates(
937 const uno::Sequence
<OUString
>& aPropertyNames
)
938 throw(beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
940 SolarMutexGuard aGuard
;
942 // simple loop to get own and aggregated states
944 const OUString
* pNames
= aPropertyNames
.getConstArray();
945 uno::Sequence
<beans::PropertyState
> aRet(aPropertyNames
.getLength());
946 beans::PropertyState
* pStates
= aRet
.getArray();
947 for(sal_Int32 i
= 0; i
< aPropertyNames
.getLength(); i
++)
948 pStates
[i
] = getPropertyState(pNames
[i
]);
952 void SAL_CALL
ScShapeObj::setPropertyToDefault( const OUString
& aPropertyName
)
953 throw (beans::UnknownPropertyException
, uno::RuntimeException
,
956 SolarMutexGuard aGuard
;
957 OUString
aNameString(aPropertyName
);
959 if ( aNameString
== SC_UNONAME_IMAGEMAP
)
961 SdrObject
* pObj
= GetSdrObject();
964 ScIMapInfo
* pIMapInfo
= ScDrawLayer::GetIMapInfo(pObj
);
968 pIMapInfo
->SetImageMap( aEmpty
); // replace with empty image map
972 // nothing to do (no need to insert user data for an empty map)
978 GetShapePropertyState();
979 if (pShapePropertyState
)
980 pShapePropertyState
->setPropertyToDefault( aPropertyName
);
984 uno::Any SAL_CALL
ScShapeObj::getPropertyDefault( const OUString
& aPropertyName
)
985 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
986 uno::RuntimeException
, std::exception
)
988 SolarMutexGuard aGuard
;
989 OUString aNameString
= aPropertyName
;
992 if ( aNameString
== SC_UNONAME_IMAGEMAP
)
994 // default: empty ImageMap
995 uno::Reference
< uno::XInterface
> xImageMap(SvUnoImageMap_createInstance( GetSupportedMacroItems() ));
996 aAny
<<= uno::Reference
< container::XIndexContainer
>::query( xImageMap
);
1000 GetShapePropertyState();
1001 if (pShapePropertyState
)
1002 aAny
= pShapePropertyState
->getPropertyDefault( aPropertyName
);
1010 void SAL_CALL
ScShapeObj::attach( const uno::Reference
<text::XTextRange
>& /* xTextRange */ )
1011 throw(lang::IllegalArgumentException
, uno::RuntimeException
, std::exception
)
1013 SolarMutexGuard aGuard
;
1015 throw lang::IllegalArgumentException(); // anchor cannot be changed
1018 uno::Reference
<text::XTextRange
> SAL_CALL
ScShapeObj::getAnchor()
1019 throw(uno::RuntimeException
, std::exception
)
1021 SolarMutexGuard aGuard
;
1023 uno::Reference
<text::XTextRange
> xRet
;
1025 SdrObject
* pObj
= GetSdrObject();
1028 ScDrawLayer
* pModel
= static_cast<ScDrawLayer
*>(pObj
->GetModel());
1029 SdrPage
* pPage
= pObj
->GetPage();
1032 ScDocument
* pDoc
= pModel
->GetDocument();
1035 SfxObjectShell
* pObjSh
= pDoc
->GetDocumentShell();
1036 if ( pObjSh
&& pObjSh
->ISA(ScDocShell
) )
1038 ScDocShell
* pDocSh
= static_cast<ScDocShell
*>(pObjSh
);
1041 if ( lcl_GetPageNum( pPage
, *pModel
, nTab
) )
1043 Point
aPos(pObj
->GetCurrentBoundRect().TopLeft());
1044 ScRange
aRange(pDoc
->GetRange( nTab
, Rectangle( aPos
, aPos
) ));
1046 // anchor is always the cell
1048 xRet
.set(new ScCellObj( pDocSh
, aRange
.aStart
));
1060 void SAL_CALL
ScShapeObj::dispose() throw(uno::RuntimeException
, std::exception
)
1062 SolarMutexGuard aGuard
;
1064 uno::Reference
<lang::XComponent
> xAggComp(lcl_GetComponent(mxShapeAgg
));
1065 if ( xAggComp
.is() )
1066 xAggComp
->dispose();
1069 void SAL_CALL
ScShapeObj::addEventListener(
1070 const uno::Reference
<lang::XEventListener
>& xListener
)
1071 throw(uno::RuntimeException
, std::exception
)
1073 SolarMutexGuard aGuard
;
1075 uno::Reference
<lang::XComponent
> xAggComp(lcl_GetComponent(mxShapeAgg
));
1076 if ( xAggComp
.is() )
1077 xAggComp
->addEventListener(xListener
);
1080 void SAL_CALL
ScShapeObj::removeEventListener(
1081 const uno::Reference
<lang::XEventListener
>& xListener
)
1082 throw(uno::RuntimeException
, std::exception
)
1084 SolarMutexGuard aGuard
;
1086 uno::Reference
<lang::XComponent
> xAggComp(lcl_GetComponent(mxShapeAgg
));
1087 if ( xAggComp
.is() )
1088 xAggComp
->removeEventListener(xListener
);
1092 // (special handling for ScCellFieldObj)
1094 static void lcl_CopyOneProperty( beans::XPropertySet
& rDest
, beans::XPropertySet
& rSource
, const sal_Char
* pName
)
1096 OUString
aNameStr(OUString::createFromAscii(pName
));
1099 rDest
.setPropertyValue( aNameStr
, rSource
.getPropertyValue( aNameStr
) );
1101 catch (uno::Exception
&)
1103 OSL_FAIL("Exception in text field");
1107 void SAL_CALL
ScShapeObj::insertTextContent( const uno::Reference
<text::XTextRange
>& xRange
,
1108 const uno::Reference
<text::XTextContent
>& xContent
,
1110 throw(lang::IllegalArgumentException
, uno::RuntimeException
, std::exception
)
1112 SolarMutexGuard aGuard
;
1114 uno::Reference
<text::XTextContent
> xEffContent
;
1116 ScEditFieldObj
* pCellField
= ScEditFieldObj::getImplementation( xContent
);
1119 // createInstance("TextField.URL") from the document creates a ScCellFieldObj.
1120 // To insert it into drawing text, a SvxUnoTextField is needed instead.
1121 // The ScCellFieldObj object is left in non-inserted state.
1123 SvxUnoTextField
* pDrawField
= new SvxUnoTextField( text::textfield::Type::URL
);
1124 xEffContent
.set(pDrawField
);
1125 lcl_CopyOneProperty( *pDrawField
, *pCellField
, SC_UNONAME_URL
);
1126 lcl_CopyOneProperty( *pDrawField
, *pCellField
, SC_UNONAME_REPR
);
1127 lcl_CopyOneProperty( *pDrawField
, *pCellField
, SC_UNONAME_TARGET
);
1130 xEffContent
.set(xContent
);
1132 uno::Reference
<text::XText
> xAggText(lcl_GetText(mxShapeAgg
));
1133 if ( xAggText
.is() )
1134 xAggText
->insertTextContent( xRange
, xEffContent
, bAbsorb
);
1137 void SAL_CALL
ScShapeObj::removeTextContent( const uno::Reference
<text::XTextContent
>& xContent
)
1138 throw(container::NoSuchElementException
, uno::RuntimeException
, std::exception
)
1140 SolarMutexGuard aGuard
;
1142 // ScCellFieldObj can't be used here.
1144 uno::Reference
<text::XText
> xAggText(lcl_GetText(mxShapeAgg
));
1145 if ( xAggText
.is() )
1146 xAggText
->removeTextContent( xContent
);
1149 // XSimpleText (parent of XText)
1150 // Use own SvxUnoTextCursor subclass - everything is just passed to aggregated object
1152 uno::Reference
<text::XTextCursor
> SAL_CALL
ScShapeObj::createTextCursor()
1153 throw(uno::RuntimeException
, std::exception
)
1155 SolarMutexGuard aGuard
;
1157 if ( mxShapeAgg
.is() )
1159 // ScDrawTextCursor must be used to ensure the ScShapeObj is returned by getText
1161 SvxUnoTextBase
* pText
= SvxUnoTextBase::getImplementation( mxShapeAgg
);
1163 return new ScDrawTextCursor( this, *pText
);
1166 return uno::Reference
<text::XTextCursor
>();
1169 uno::Reference
<text::XTextCursor
> SAL_CALL
ScShapeObj::createTextCursorByRange(
1170 const uno::Reference
<text::XTextRange
>& aTextPosition
)
1171 throw(uno::RuntimeException
, std::exception
)
1173 SolarMutexGuard aGuard
;
1175 if ( mxShapeAgg
.is() && aTextPosition
.is() )
1177 // ScDrawTextCursor must be used to ensure the ScShapeObj is returned by getText
1179 SvxUnoTextBase
* pText
= SvxUnoTextBase::getImplementation( mxShapeAgg
);
1180 SvxUnoTextRangeBase
* pRange
= SvxUnoTextRangeBase::getImplementation( aTextPosition
);
1181 if ( pText
&& pRange
)
1183 SvxUnoTextCursor
* pCursor
= new ScDrawTextCursor( this, *pText
);
1184 uno::Reference
<text::XTextCursor
> xCursor( pCursor
);
1185 pCursor
->SetSelection( pRange
->GetSelection() );
1190 return uno::Reference
<text::XTextCursor
>();
1193 void SAL_CALL
ScShapeObj::insertString( const uno::Reference
<text::XTextRange
>& xRange
,
1194 const OUString
& aString
, sal_Bool bAbsorb
)
1195 throw(uno::RuntimeException
, std::exception
)
1197 SolarMutexGuard aGuard
;
1199 uno::Reference
<text::XSimpleText
> xAggSimpleText(lcl_GetSimpleText(mxShapeAgg
));
1200 if ( xAggSimpleText
.is() )
1201 xAggSimpleText
->insertString( xRange
, aString
, bAbsorb
);
1203 throw uno::RuntimeException();
1206 void SAL_CALL
ScShapeObj::insertControlCharacter( const uno::Reference
<text::XTextRange
>& xRange
,
1207 sal_Int16 nControlCharacter
, sal_Bool bAbsorb
)
1208 throw(lang::IllegalArgumentException
, uno::RuntimeException
, std::exception
)
1210 SolarMutexGuard aGuard
;
1212 uno::Reference
<text::XSimpleText
> xAggSimpleText(lcl_GetSimpleText(mxShapeAgg
));
1213 if ( xAggSimpleText
.is() )
1214 xAggSimpleText
->insertControlCharacter( xRange
, nControlCharacter
, bAbsorb
);
1216 throw uno::RuntimeException();
1220 // (parent of XSimpleText)
1222 uno::Reference
<text::XText
> SAL_CALL
ScShapeObj::getText() throw(uno::RuntimeException
, std::exception
)
1224 SolarMutexGuard aGuard
;
1228 uno::Reference
<text::XTextRange
> SAL_CALL
ScShapeObj::getStart() throw(uno::RuntimeException
, std::exception
)
1230 SolarMutexGuard aGuard
;
1232 uno::Reference
<text::XTextRange
> xAggTextRange(lcl_GetTextRange(mxShapeAgg
));
1233 if ( xAggTextRange
.is() )
1234 return xAggTextRange
->getStart();
1236 throw uno::RuntimeException();
1238 // return uno::Reference<text::XTextRange>();
1241 uno::Reference
<text::XTextRange
> SAL_CALL
ScShapeObj::getEnd() throw(uno::RuntimeException
, std::exception
)
1243 SolarMutexGuard aGuard
;
1245 uno::Reference
<text::XTextRange
> xAggTextRange(lcl_GetTextRange(mxShapeAgg
));
1246 if ( xAggTextRange
.is() )
1247 return xAggTextRange
->getEnd();
1249 throw uno::RuntimeException();
1251 // return uno::Reference<text::XTextRange>();
1254 OUString SAL_CALL
ScShapeObj::getString() throw(uno::RuntimeException
, std::exception
)
1256 SolarMutexGuard aGuard
;
1258 uno::Reference
<text::XTextRange
> xAggTextRange(lcl_GetTextRange(mxShapeAgg
));
1259 if ( xAggTextRange
.is() )
1260 return xAggTextRange
->getString();
1262 throw uno::RuntimeException();
1264 // return OUString();
1267 void SAL_CALL
ScShapeObj::setString( const OUString
& aText
) throw(uno::RuntimeException
, std::exception
)
1269 SolarMutexGuard aGuard
;
1271 uno::Reference
<text::XTextRange
> xAggTextRange(lcl_GetTextRange(mxShapeAgg
));
1272 if ( xAggTextRange
.is() )
1273 xAggTextRange
->setString( aText
);
1275 throw uno::RuntimeException();
1280 uno::Reference
< uno::XInterface
> SAL_CALL
ScShapeObj::getParent() throw (uno::RuntimeException
, std::exception
)
1282 SolarMutexGuard aGuard
;
1284 // receive cell position from caption object (parent of a note caption is the note cell)
1285 SdrObject
* pObj
= GetSdrObject();
1288 ScDrawLayer
* pModel
= static_cast<ScDrawLayer
*>(pObj
->GetModel());
1289 SdrPage
* pPage
= pObj
->GetPage();
1292 ScDocument
* pDoc
= pModel
->GetDocument();
1295 SfxObjectShell
* pObjSh
= pDoc
->GetDocumentShell();
1296 if ( pObjSh
&& pObjSh
->ISA(ScDocShell
) )
1298 ScDocShell
* pDocSh
= static_cast<ScDocShell
*>(pObjSh
);
1301 if ( lcl_GetPageNum( pPage
, *pModel
, nTab
) )
1303 const ScDrawObjData
* pCaptData
= ScDrawLayer::GetNoteCaptionData( pObj
, nTab
);
1305 return static_cast< ::cppu::OWeakObject
* >( new ScCellObj( pDocSh
, pCaptData
->maStart
) );
1315 void SAL_CALL
ScShapeObj::setParent( const uno::Reference
< uno::XInterface
>& ) throw (lang::NoSupportException
, uno::RuntimeException
, std::exception
)
1317 throw lang::NoSupportException();
1322 uno::Sequence
<uno::Type
> SAL_CALL
ScShapeObj::getTypes() throw(uno::RuntimeException
, std::exception
)
1324 uno::Sequence
< uno::Type
> aBaseTypes( ScShapeObj_Base::getTypes() );
1326 uno::Sequence
< uno::Type
> aTextTypes
;
1328 aTextTypes
= ScShapeObj_TextBase::getTypes();
1330 uno::Reference
<lang::XTypeProvider
> xBaseProvider
;
1331 if ( mxShapeAgg
.is() )
1332 mxShapeAgg
->queryAggregation( cppu::UnoType
<lang::XTypeProvider
>::get()) >>= xBaseProvider
;
1333 OSL_ENSURE( xBaseProvider
.is(), "ScShapeObj: No XTypeProvider from aggregated shape!" );
1335 uno::Sequence
< uno::Type
> aAggTypes
;
1336 if( xBaseProvider
.is() )
1337 aAggTypes
= xBaseProvider
->getTypes();
1339 return ::comphelper::concatSequences( aBaseTypes
, aTextTypes
, aAggTypes
);
1342 uno::Sequence
<sal_Int8
> SAL_CALL
ScShapeObj::getImplementationId()
1343 throw(uno::RuntimeException
, std::exception
)
1345 return css::uno::Sequence
<sal_Int8
>();
1348 SdrObject
* ScShapeObj::GetSdrObject() const throw()
1352 SvxShape
* pShape
= SvxShape::getImplementation( mxShapeAgg
);
1354 return pShape
->GetSdrObject();
1360 #define SC_EVENTACC_ONCLICK "OnClick"
1361 #define SC_EVENTACC_SCRIPT "Script"
1362 #define SC_EVENTACC_EVENTTYPE "EventType"
1364 typedef ::cppu::WeakImplHelper1
< container::XNameReplace
> ShapeUnoEventAcess_BASE
;
1365 class ShapeUnoEventAccessImpl
: public ShapeUnoEventAcess_BASE
1368 ScShapeObj
* mpShape
;
1370 ScMacroInfo
* getInfo( bool bCreate
= false )
1372 return ScShapeObj_getShapeHyperMacroInfo( mpShape
, bCreate
);
1376 ShapeUnoEventAccessImpl( ScShapeObj
* pShape
): mpShape( pShape
)
1381 virtual void SAL_CALL
replaceByName( const OUString
& aName
, const uno::Any
& aElement
)
1382 throw (lang::IllegalArgumentException
, container::NoSuchElementException
,
1383 lang::WrappedTargetException
, uno::RuntimeException
,
1384 std::exception
) SAL_OVERRIDE
1386 if ( !hasByName( aName
) )
1387 throw container::NoSuchElementException();
1388 uno::Sequence
< beans::PropertyValue
> aProperties
;
1389 aElement
>>= aProperties
;
1390 const beans::PropertyValue
* pProperties
= aProperties
.getConstArray();
1391 const sal_Int32 nCount
= aProperties
.getLength();
1393 bool isEventType
= false;
1394 for( nIndex
= 0; nIndex
< nCount
; nIndex
++, pProperties
++ )
1396 if ( pProperties
->Name
== SC_EVENTACC_EVENTTYPE
)
1401 if ( isEventType
&& (pProperties
->Name
== SC_EVENTACC_SCRIPT
) )
1404 if ( pProperties
->Value
>>= sValue
)
1406 ScMacroInfo
* pInfo
= getInfo( true );
1407 OSL_ENSURE( pInfo
, "shape macro info could not be created!" );
1410 if ( pProperties
->Name
== SC_EVENTACC_SCRIPT
)
1411 pInfo
->SetMacro( sValue
);
1413 pInfo
->SetHlink( sValue
);
1420 virtual uno::Any SAL_CALL
getByName( const OUString
& aName
)
1421 throw (container::NoSuchElementException
, lang::WrappedTargetException
,
1422 uno::RuntimeException
, std::exception
) SAL_OVERRIDE
1424 uno::Sequence
< beans::PropertyValue
> aProperties
;
1425 ScMacroInfo
* pInfo
= getInfo();
1427 if ( aName
== SC_EVENTACC_ONCLICK
)
1429 if ( pInfo
&& !pInfo
->GetMacro().isEmpty() )
1431 aProperties
.realloc( 2 );
1432 aProperties
[ 0 ].Name
= SC_EVENTACC_EVENTTYPE
;
1433 aProperties
[ 0 ].Value
<<= OUString(SC_EVENTACC_SCRIPT
);
1434 aProperties
[ 1 ].Name
= SC_EVENTACC_SCRIPT
;
1435 aProperties
[ 1 ].Value
<<= pInfo
->GetMacro();
1440 throw container::NoSuchElementException();
1443 return uno::Any( aProperties
);
1446 virtual uno::Sequence
< OUString
> SAL_CALL
getElementNames() throw(uno::RuntimeException
, std::exception
) SAL_OVERRIDE
1448 uno::Sequence
< OUString
> aSeq( 1 );
1449 aSeq
[ 0 ] = SC_EVENTACC_ONCLICK
;
1453 virtual sal_Bool SAL_CALL
hasByName( const OUString
& aName
) throw(uno::RuntimeException
, std::exception
) SAL_OVERRIDE
1455 return aName
== SC_EVENTACC_ONCLICK
;
1459 virtual uno::Type SAL_CALL
getElementType() throw(uno::RuntimeException
, std::exception
) SAL_OVERRIDE
1461 return cppu::UnoType
<uno::Sequence
< beans::PropertyValue
>>::get();
1464 virtual sal_Bool SAL_CALL
hasElements() throw(uno::RuntimeException
, std::exception
) SAL_OVERRIDE
1466 // elements are always present (but contained property sequences may be empty)
1471 ::uno::Reference
< container::XNameReplace
> SAL_CALL
1472 ScShapeObj::getEvents( ) throw(uno::RuntimeException
, std::exception
)
1474 return new ShapeUnoEventAccessImpl( this );
1477 OUString SAL_CALL
ScShapeObj::getImplementationName( ) throw (uno::RuntimeException
, std::exception
)
1479 return OUString( "com.sun.star.comp.sc.ScShapeObj" );
1482 sal_Bool SAL_CALL
ScShapeObj::supportsService( const OUString
& _ServiceName
) throw (uno::RuntimeException
, std::exception
)
1484 return cppu::supportsService(this, _ServiceName
);
1487 uno::Sequence
< OUString
> SAL_CALL
ScShapeObj::getSupportedServiceNames( ) throw (uno::RuntimeException
, std::exception
)
1489 uno::Reference
<lang::XServiceInfo
> xSI
;
1490 if ( mxShapeAgg
.is() )
1491 mxShapeAgg
->queryAggregation( cppu::UnoType
<lang::XServiceInfo
>::get() ) >>= xSI
;
1493 uno::Sequence
< OUString
> aSupported
;
1495 aSupported
= xSI
->getSupportedServiceNames();
1497 aSupported
.realloc( aSupported
.getLength() + 1 );
1498 aSupported
[ aSupported
.getLength() - 1 ] = "com.sun.star.sheet.Shape";
1500 if( bIsNoteCaption
)
1502 aSupported
.realloc( aSupported
.getLength() + 1 );
1503 aSupported
[ aSupported
.getLength() - 1 ] = "com.sun.star.sheet.CellAnnotationShape";
1509 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */