LibreOffice Module sc (master) 1
shapeuno.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21
24#include <svtools/unoevent.hxx>
25#include <svtools/unoimap.hxx>
26#include <svx/svdobj.hxx>
27#include <svx/ImageMapInfo.hxx>
28#include <vcl/svapp.hxx>
29#include <sfx2/event.hxx>
30#include <editeng/unofield.hxx>
35
36#include <com/sun/star/beans/PropertyAttribute.hpp>
37#include <com/sun/star/drawing/XShape.hpp>
38#include <com/sun/star/lang/NoSupportException.hpp>
39
40#include <shapeuno.hxx>
41#include <cellsuno.hxx>
42#include <textuno.hxx>
43#include <fielduno.hxx>
44#include <docsh.hxx>
45#include <drwlayer.hxx>
46#include <userdat.hxx>
47#include <unonames.hxx>
48#include <styleuno.hxx>
49
50using namespace ::com::sun::star;
51
53{
54 static const SfxItemPropertyMapEntry aShapeMap_Impl[] =
55 {
64 { SC_UNONAME_STYLE, 0, cppu::UnoType<style::XStyle>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0 },
65 };
66 return aShapeMap_Impl;
67}
68
70{
71 static const SvEventDescription aMacroDescriptionsImpl[] =
72 {
73 { SvMacroItemId::NONE, nullptr }
74 };
75 return aMacroDescriptionsImpl;
76}
77ScMacroInfo* ScShapeObj_getShapeHyperMacroInfo( const ScShapeObj* pShape, bool bCreate = false )
78{
79 if( pShape )
80 if( SdrObject* pObj = pShape->GetSdrObject() )
81 return ScDrawLayer::GetMacroInfo( pObj, bCreate );
82 return nullptr;
83}
84
85ScShapeObj::ScShapeObj( uno::Reference<drawing::XShape>& xShape ) :
86 pShapePropertySet(nullptr),
87 pShapePropertyState(nullptr),
88 bIsTextShape(false),
89 bIsNoteCaption(false)
90{
91 osl_atomic_increment( &m_refCount );
92
93 {
94 mxShapeAgg.set( xShape, uno::UNO_QUERY );
95 // extra block to force deletion of the temporary before setDelegator
96 }
97
98 if (mxShapeAgg.is())
99 {
100 xShape = nullptr; // during setDelegator, mxShapeAgg must be the only ref
101
102 mxShapeAgg->setDelegator( getXWeak() );
103
104 xShape.set(uno::Reference<drawing::XShape>( mxShapeAgg, uno::UNO_QUERY ));
105
106 bIsTextShape = ( comphelper::getFromUnoTunnel<SvxUnoTextBase>( mxShapeAgg ) != nullptr );
107 }
108
109 {
110 SdrObject* pObj = GetSdrObject();
111 if ( pObj )
112 {
114 }
115 }
116
117 osl_atomic_decrement( &m_refCount );
118}
119
121{
122// if (mxShapeAgg.is())
123// mxShapeAgg->setDelegator(uno::Reference<uno::XInterface>());
124}
125
126// XInterface
127
129{
130 uno::Any aRet = ScShapeObj_Base::queryInterface( rType );
131
132 if ( !aRet.hasValue() && bIsTextShape )
134
135 if ( !aRet.hasValue() && bIsNoteCaption )
137
138 if ( !aRet.hasValue() && mxShapeAgg.is() )
139 aRet = mxShapeAgg->queryAggregation( rType );
140
141 return aRet;
142}
143
144void SAL_CALL ScShapeObj::acquire() noexcept
145{
146 OWeakObject::acquire();
147}
148
149void SAL_CALL ScShapeObj::release() noexcept
150{
151 OWeakObject::release();
152}
153
155{
156 // #i61908# Store the result of queryAggregation in a member.
157 // The reference in mxShapeAgg is kept for this object's lifetime, so the pointer is always valid.
158
160 {
161 uno::Reference<beans::XPropertySet> xProp;
162 if ( mxShapeAgg.is() )
163 mxShapeAgg->queryAggregation( cppu::UnoType<beans::XPropertySet>::get()) >>= xProp;
164 pShapePropertySet = xProp.get();
165 }
166}
167
169{
170 // #i61908# Store the result of queryAggregation in a member.
171 // The reference in mxShapeAgg is kept for this object's lifetime, so the pointer is always valid.
172
174 {
175 uno::Reference<beans::XPropertyState> xState;
176 if ( mxShapeAgg.is() )
177 mxShapeAgg->queryAggregation( cppu::UnoType<beans::XPropertyState>::get()) >>= xState;
178 pShapePropertyState = xState.get();
179 }
180}
181
182static uno::Reference<lang::XComponent> lcl_GetComponent( const uno::Reference<uno::XAggregation>& xAgg )
183{
184 uno::Reference<lang::XComponent> xRet;
185 if ( xAgg.is() )
186 xAgg->queryAggregation( cppu::UnoType<lang::XComponent>::get()) >>= xRet;
187 return xRet;
188}
189
190static uno::Reference<text::XText> lcl_GetText( const uno::Reference<uno::XAggregation>& xAgg )
191{
192 uno::Reference<text::XText> xRet;
193 if ( xAgg.is() )
194 xAgg->queryAggregation( cppu::UnoType<text::XText>::get()) >>= xRet;
195 return xRet;
196}
197
198static uno::Reference<text::XSimpleText> lcl_GetSimpleText( const uno::Reference<uno::XAggregation>& xAgg )
199{
200 uno::Reference<text::XSimpleText> xRet;
201 if ( xAgg.is() )
202 xAgg->queryAggregation( cppu::UnoType<text::XSimpleText>::get()) >>= xRet;
203 return xRet;
204}
205
206static uno::Reference<text::XTextRange> lcl_GetTextRange( const uno::Reference<uno::XAggregation>& xAgg )
207{
208 uno::Reference<text::XTextRange> xRet;
209 if ( xAgg.is() )
210 xAgg->queryAggregation( cppu::UnoType<text::XTextRange>::get()) >>= xRet;
211 return xRet;
212}
213
214// XPropertySet
215
216uno::Reference<beans::XPropertySetInfo> SAL_CALL ScShapeObj::getPropertySetInfo()
217{
218 SolarMutexGuard aGuard;
219
220 // #i61527# cache property set info for this object
221 if ( !mxPropSetInfo.is() )
222 {
223 // mix own and aggregated properties:
226 {
227 uno::Reference<beans::XPropertySetInfo> xAggInfo(pShapePropertySet->getPropertySetInfo());
228 const uno::Sequence<beans::Property> aPropSeq(xAggInfo->getProperties());
230 }
231 }
232 return mxPropSetInfo;
233}
234
235static bool lcl_GetPageNum( const SdrPage* pPage, SdrModel& rModel, SCTAB& rNum )
236{
237 sal_uInt16 nCount = rModel.GetPageCount();
238 for (sal_uInt16 i=0; i<nCount; i++)
239 if ( rModel.GetPage(i) == pPage )
240 {
241 rNum = static_cast<SCTAB>(i);
242 return true;
243 }
244
245 return false;
246}
247
248static bool lcl_GetCaptionPoint( const uno::Reference< drawing::XShape >& xShape, awt::Point& rCaptionPoint )
249{
250 bool bReturn = false;
251 OUString sType(xShape->getShapeType());
252 bool bCaptionShape( sType == "com.sun.star.drawing.CaptionShape" );
253 if (bCaptionShape)
254 {
255 uno::Reference < beans::XPropertySet > xShapeProp (xShape, uno::UNO_QUERY);
256 if (xShapeProp.is())
257 {
258 xShapeProp->getPropertyValue("CaptionPoint") >>= rCaptionPoint;
259 bReturn = true;
260 }
261 }
262 return bReturn;
263}
264
265static ScRange lcl_GetAnchorCell( const uno::Reference< drawing::XShape >& xShape, const ScDocument* pDoc, SCTAB nTab,
266 awt::Point& rUnoPoint, awt::Size& rUnoSize, awt::Point& rCaptionPoint )
267{
268 ScRange aReturn;
269 rUnoPoint = xShape->getPosition();
270 bool bCaptionShape(lcl_GetCaptionPoint(xShape, rCaptionPoint));
271 if (pDoc->IsNegativePage(nTab))
272 {
273 rUnoSize = xShape->getSize();
274 rUnoPoint.X += rUnoSize.Width; // the right top point is base
275 if (bCaptionShape)
276 {
277 if (rCaptionPoint.X > 0 && rCaptionPoint.X > rUnoSize.Width)
278 rUnoPoint.X += rCaptionPoint.X - rUnoSize.Width;
279 if (rCaptionPoint.Y < 0)
280 rUnoPoint.Y += rCaptionPoint.Y;
281 }
282 aReturn = pDoc->GetRange( nTab, tools::Rectangle( VCLPoint(rUnoPoint), VCLPoint(rUnoPoint) ));
283 }
284 else
285 {
286 if (bCaptionShape)
287 {
288 if (rCaptionPoint.X < 0)
289 rUnoPoint.X += rCaptionPoint.X;
290 if (rCaptionPoint.Y < 0)
291 rUnoPoint.Y += rCaptionPoint.Y;
292 }
293 aReturn = pDoc->GetRange( nTab, tools::Rectangle( VCLPoint(rUnoPoint), VCLPoint(rUnoPoint) ));
294 }
295
296 return aReturn;
297}
298
299static awt::Point lcl_GetRelativePos( const uno::Reference< drawing::XShape >& xShape, const ScDocument* pDoc, SCTAB nTab, ScRange& rRange,
300 awt::Size& rUnoSize, awt::Point& rCaptionPoint)
301{
302 awt::Point aUnoPoint;
303 rRange = lcl_GetAnchorCell(xShape, pDoc, nTab, aUnoPoint, rUnoSize, rCaptionPoint);
304 tools::Rectangle aRect(pDoc->GetMMRect( rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row(), rRange.aStart.Tab() ));
305 Point aPoint = pDoc->IsNegativePage(nTab) ? aRect.TopRight() : aRect.TopLeft();
306 aUnoPoint.X -= aPoint.X();
307 aUnoPoint.Y -= aPoint.Y();
308 return aUnoPoint;
309}
310
311void SAL_CALL ScShapeObj::setPropertyValue(const OUString& aPropertyName, const uno::Any& aValue)
312{
313 SolarMutexGuard aGuard;
314
315 if ( aPropertyName == SC_UNONAME_ANCHOR )
316 {
317 uno::Reference<sheet::XCellRangeAddressable> xRangeAdd(aValue, uno::UNO_QUERY);
318 if (!xRangeAdd.is())
319 throw lang::IllegalArgumentException("only XCell or XSpreadsheet objects allowed", getXWeak(), 0);
320
321 SdrObject *pObj = GetSdrObject();
322 if (pObj)
323 {
324 ScDrawLayer& rModel(static_cast< ScDrawLayer& >(pObj->getSdrModelFromSdrObject()));
325 SdrPage* pPage(pObj->getSdrPageFromSdrObject());
326
327 if ( pPage )
328 {
329 ScDocument* pDoc(rModel.GetDocument());
330
331 if ( pDoc )
332 {
333 SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
334 if ( auto pDocSh = dynamic_cast<ScDocShell*>( pObjSh) )
335 {
336 SCTAB nTab = 0;
337 if ( lcl_GetPageNum( pPage, rModel, nTab ) )
338 {
339 table::CellRangeAddress aAddress = xRangeAdd->getRangeAddress();
340 if (nTab == aAddress.Sheet)
341 {
342 tools::Rectangle aRect(pDoc->GetMMRect( static_cast<SCCOL>(aAddress.StartColumn), static_cast<SCROW>(aAddress.StartRow),
343 static_cast<SCCOL>(aAddress.EndColumn), static_cast<SCROW>(aAddress.EndRow), aAddress.Sheet ));
344 awt::Point aRelPoint;
345 uno::Reference<drawing::XShape> xShape( mxShapeAgg, uno::UNO_QUERY );
346 if (xShape.is())
347 {
348 Point aPoint;
349 Point aEndPoint;
350 if (pDoc->IsNegativePage(nTab))
351 {
352 aPoint = aRect.TopRight();
353 aEndPoint = aRect.BottomLeft();
354 }
355 else
356 {
357 aPoint = aRect.TopLeft();
358 aEndPoint = aRect.BottomRight();
359 }
360 awt::Size aUnoSize;
361 awt::Point aCaptionPoint;
362 ScRange aRange;
363 aRelPoint = lcl_GetRelativePos( xShape, pDoc, nTab, aRange, aUnoSize, aCaptionPoint );
364 awt::Point aUnoPoint(aRelPoint);
365
366 aUnoPoint.X += aPoint.X();
367 aUnoPoint.Y += aPoint.Y();
368
369 if ( aUnoPoint.Y > aEndPoint.Y() )
370 aUnoPoint.Y = aEndPoint.Y() - 2;
371 if (pDoc->IsNegativePage(nTab))
372 {
373 if ( aUnoPoint.X < aEndPoint.X() )
374 aUnoPoint.X = aEndPoint.X() + 2;
375 aUnoPoint.X -= aUnoSize.Width;
376 // remove difference to caption point
377 if (aCaptionPoint.X > 0 && aCaptionPoint.X > aUnoSize.Width)
378 aUnoPoint.X -= aCaptionPoint.X - aUnoSize.Width;
379 }
380 else
381 {
382 if ( aUnoPoint.X > aEndPoint.X() )
383 aUnoPoint.X = aEndPoint.X() - 2;
384 if (aCaptionPoint.X < 0)
385 aUnoPoint.X -= aCaptionPoint.X;
386 }
387 if (aCaptionPoint.Y < 0)
388 aUnoPoint.Y -= aCaptionPoint.Y;
389
390 xShape->setPosition(aUnoPoint);
391 pDocSh->SetModified();
392 }
393
394 if (aAddress.StartRow != aAddress.EndRow) //should be a Spreadsheet
395 {
396 OSL_ENSURE(aAddress.StartRow == 0 && aAddress.EndRow == pDoc->MaxRow() &&
397 aAddress.StartColumn == 0 && aAddress.EndColumn == pDoc->MaxCol(), "here should be a XSpreadsheet");
399 }
400 else
401 {
402 OSL_ENSURE(aAddress.StartRow == aAddress.EndRow &&
403 aAddress.StartColumn == aAddress.EndColumn, "here should be a XCell");
404 ScDrawObjData aAnchor;
405 aAnchor.maStart = ScAddress(aAddress.StartColumn, aAddress.StartRow, aAddress.Sheet);
406 aAnchor.maStartOffset = Point(aRelPoint.X, aRelPoint.Y);
407 ScDrawObjData* pDrawObjData = ScDrawLayer::GetObjData(pObj);
408 if (pDrawObjData)
409 aAnchor.mbResizeWithCell = pDrawObjData->mbResizeWithCell;
410 //Uno sets the Anchor in terms of the unrotated shape, not much we can do
411 //about that since uno also displays the shape geometry in terms of the unrotated
412 //shape. #TODO think about changing the anchoring behaviour here too
413 //Currently we've only got a start anchor, not an end-anchor, so generate that now
414 ScDrawLayer::UpdateCellAnchorFromPositionEnd(*pObj, aAnchor, *pDoc, aAddress.Sheet);
415 ScDrawLayer::SetCellAnchored(*pObj, aAnchor);
416 }
417 }
418 }
419 }
420 }
421 }
422 }
423
424 }
425 else if ( aPropertyName == SC_UNONAME_RESIZE_WITH_CELL )
426 {
427 SdrObject* pObj = GetSdrObject();
428 if (!pObj)
429 return;
430 ScAnchorType aAnchorType = ScDrawLayer::GetAnchorType(*pObj);
431
432 // Nothing to do if anchored to page
433 if (aAnchorType == SCA_PAGE)
434 return;
435
436 ScDrawObjData* pDrawObjData = ScDrawLayer::GetObjData(pObj);
437 if (!pDrawObjData)
438 return;
439
440 aValue >>= pDrawObjData->mbResizeWithCell;
441 ScDrawLayer::SetCellAnchored(*pObj, *pDrawObjData);
442 }
443 else if ( aPropertyName == SC_UNONAME_IMAGEMAP )
444 {
445 SdrObject* pObj = GetSdrObject();
446 if ( pObj )
447 {
448 ImageMap aImageMap;
449 uno::Reference< uno::XInterface > xImageMapInt(aValue, uno::UNO_QUERY);
450
451 if( !xImageMapInt.is() || !SvUnoImageMap_fillImageMap( xImageMapInt, aImageMap ) )
452 throw lang::IllegalArgumentException();
453
454 SvxIMapInfo* pIMapInfo = SvxIMapInfo::GetIMapInfo(pObj);
455 if( pIMapInfo )
456 {
457 // replace existing image map
458 pIMapInfo->SetImageMap( aImageMap );
459 }
460 else
461 {
462 // insert new user data with image map
463 pObj->AppendUserData(std::unique_ptr<SdrObjUserData>(new SvxIMapInfo(aImageMap) ));
464 }
465 }
466 }
467 else if ( aPropertyName == SC_UNONAME_HORIPOS )
468 {
469 sal_Int32 nPos = 0;
470 if (aValue >>= nPos)
471 {
472 SdrObject *pObj = GetSdrObject();
473 if (pObj)
474 {
475 ScDrawLayer& rModel(static_cast< ScDrawLayer& >(pObj->getSdrModelFromSdrObject()));
476 SdrPage* pPage(pObj->getSdrPageFromSdrObject());
477
478 if ( pPage )
479 {
480 SCTAB nTab = 0;
481 if ( lcl_GetPageNum( pPage, rModel, nTab ) )
482 {
483 ScDocument* pDoc = rModel.GetDocument();
484 if ( pDoc )
485 {
486 SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
487 if ( auto pDocSh = dynamic_cast<ScDocShell*>( pObjSh) )
488 {
489 uno::Reference<drawing::XShape> xShape( mxShapeAgg, uno::UNO_QUERY );
490 if (xShape.is())
491 {
493 {
494 awt::Point aPoint(xShape->getPosition());
495 awt::Size aSize(xShape->getSize());
496 awt::Point aCaptionPoint;
497 if (pDoc->IsNegativePage(nTab))
498 {
499 nPos *= -1;
500 nPos -= aSize.Width;
501 }
502 if (lcl_GetCaptionPoint(xShape, aCaptionPoint))
503 {
504 if (pDoc->IsNegativePage(nTab))
505 {
506 if (aCaptionPoint.X > 0 && aCaptionPoint.X > aSize.Width)
507 nPos -= aCaptionPoint.X - aSize.Width;
508 }
509 else
510 {
511 if (aCaptionPoint.X < 0)
512 nPos -= aCaptionPoint.X;
513 }
514 }
515 aPoint.X = nPos;
516 xShape->setPosition(aPoint);
517 pDocSh->SetModified();
518 }
519 else if (ScDrawLayer::GetAnchorType(*pObj) == SCA_CELL
522 {
523 awt::Size aUnoSize;
524 awt::Point aCaptionPoint;
525 ScRange aRange;
526 awt::Point aUnoPoint(lcl_GetRelativePos( xShape, pDoc, nTab, aRange, aUnoSize, aCaptionPoint ));
527 tools::Rectangle aRect(pDoc->GetMMRect( aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row(), aRange.aStart.Tab() ));
528 if (pDoc->IsNegativePage(nTab))
529 {
530 aUnoPoint.X = -nPos;
531 Point aPoint(aRect.TopRight());
532 Point aEndPoint(aRect.BottomLeft());
533 aUnoPoint.X += aPoint.X();
534 if (aUnoPoint.X < aEndPoint.X())
535 aUnoPoint.X = aEndPoint.X() + 2;
536 aUnoPoint.X -= aUnoSize.Width;
537 if (aCaptionPoint.X > 0 && aCaptionPoint.X > aUnoSize.Width)
538 aUnoPoint.X -= aCaptionPoint.X - aUnoSize.Width;
539 }
540 else
541 {
542 aUnoPoint.X = nPos;
543 Point aPoint(aRect.TopLeft());
544 Point aEndPoint(aRect.BottomRight());
545 aUnoPoint.X += aPoint.X();
546 if (aUnoPoint.X > aEndPoint.X())
547 aUnoPoint.X = aEndPoint.X() - 2;
548 if (aCaptionPoint.X < 0)
549 aUnoPoint.X -= aCaptionPoint.X;
550 }
551 aUnoPoint.Y = xShape->getPosition().Y;
552 xShape->setPosition(aUnoPoint);
553 pDocSh->SetModified();
554 }
555 else
556 {
557 OSL_FAIL("unknown anchor type");
558 }
559 }
560 }
561 }
562 }
563 }
564 }
565 }
566 }
567 else if ( aPropertyName == SC_UNONAME_VERTPOS )
568 {
569 sal_Int32 nPos = 0;
570 if (aValue >>= nPos)
571 {
572 SdrObject *pObj = GetSdrObject();
573 if (pObj)
574 {
575 ScDrawLayer& rModel(static_cast< ScDrawLayer& >(pObj->getSdrModelFromSdrObject()));
576 SdrPage* pPage(pObj->getSdrPageFromSdrObject());
577
578 if ( pPage )
579 {
580 SCTAB nTab = 0;
581 if ( lcl_GetPageNum( pPage, rModel, nTab ) )
582 {
583 ScDocument* pDoc = rModel.GetDocument();
584 if ( pDoc )
585 {
586 SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
587 if ( auto pDocSh = dynamic_cast<ScDocShell*>( pObjSh) )
588 {
589 uno::Reference<drawing::XShape> xShape( mxShapeAgg, uno::UNO_QUERY );
590 if (xShape.is())
591 {
593 {
594 awt::Point aPoint = xShape->getPosition();
595 awt::Point aCaptionPoint;
596 if (lcl_GetCaptionPoint(xShape, aCaptionPoint))
597 {
598 if (aCaptionPoint.Y < 0)
599 nPos -= aCaptionPoint.Y;
600 }
601 aPoint.Y = nPos;
602 xShape->setPosition(aPoint);
603 pDocSh->SetModified();
604 }
605 else if (ScDrawLayer::GetAnchorType(*pObj) == SCA_CELL
608 {
609 awt::Size aUnoSize;
610 awt::Point aCaptionPoint;
611 ScRange aRange;
612 awt::Point aUnoPoint(lcl_GetRelativePos( xShape, pDoc, nTab, aRange, aUnoSize, aCaptionPoint ));
613 tools::Rectangle aRect(pDoc->GetMMRect( aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row(), aRange.aStart.Tab() ));
614 Point aPoint(aRect.TopRight());
615 Point aEndPoint(aRect.BottomLeft());
616 aUnoPoint.Y = nPos;
617 aUnoPoint.Y += aPoint.Y();
618 if (aUnoPoint.Y > aEndPoint.Y())
619 aUnoPoint.Y = aEndPoint.Y() - 2;
620 if (aCaptionPoint.Y < 0)
621 aUnoPoint.Y -= aCaptionPoint.Y;
622 aUnoPoint.X = xShape->getPosition().X;
623 xShape->setPosition(aUnoPoint);
624 pDocSh->SetModified();
625 }
626 else
627 {
628 OSL_FAIL("unknown anchor type");
629 }
630 }
631 }
632 }
633 }
634 }
635 }
636 }
637 }
638 else if ( aPropertyName == SC_UNONAME_HYPERLINK ||
639 aPropertyName == SC_UNONAME_URL )
640 {
641 OUString sHyperlink;
642 SdrObject* pObj = GetSdrObject();
643 if (pObj && (aValue >>= sHyperlink))
644 pObj->setHyperlink(sHyperlink);
645 }
646 else if ( aPropertyName == SC_UNONAME_MOVEPROTECT )
647 {
648 if( SdrObject* pObj = GetSdrObject() )
649 {
650 bool aProt = false;
651 if( aValue >>= aProt )
652 pObj->SetMoveProtect( aProt );
653 }
654 }
655 else if ( aPropertyName == SC_UNONAME_STYLE )
656 {
657 if (SdrObject* pObj = GetSdrObject())
658 {
659 uno::Reference<style::XStyle> xStyle(aValue, uno::UNO_QUERY);
660 auto pStyleSheetObj = dynamic_cast<ScStyleObj*>(xStyle.get());
661 if (!pStyleSheetObj)
662 throw lang::IllegalArgumentException();
663
664 auto pStyleSheet = pStyleSheetObj->GetStyle_Impl();
665 auto pOldStyleSheet = pObj->GetStyleSheet();
666
667 if (pStyleSheet != pOldStyleSheet)
668 pObj->SetStyleSheet(static_cast<SfxStyleSheet*>(pStyleSheet), false);
669 }
670 }
671 else
672 {
675 pShapePropertySet->setPropertyValue( aPropertyName, aValue );
676 }
677}
678
679uno::Any SAL_CALL ScShapeObj::getPropertyValue( const OUString& aPropertyName )
680{
681 SolarMutexGuard aGuard;
682
683 uno::Any aAny;
684 if ( aPropertyName == SC_UNONAME_ANCHOR )
685 {
686 SdrObject *pObj = GetSdrObject();
687 if (pObj)
688 {
689 ScDrawLayer& rModel(static_cast< ScDrawLayer& >(pObj->getSdrModelFromSdrObject()));
690 SdrPage* pPage(pObj->getSdrPageFromSdrObject());
691
692 if ( pPage )
693 {
694 ScDocument* pDoc = rModel.GetDocument();
695 if ( pDoc )
696 {
697 SCTAB nTab = 0;
698 if ( lcl_GetPageNum( pPage, rModel, nTab ) )
699 {
700 SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
701 if ( auto pDocSh = dynamic_cast<ScDocShell*>( pObjSh) )
702 {
703 uno::Reference< uno::XInterface > xAnchor;
704 if (ScDrawObjData *pAnchor = ScDrawLayer::GetObjDataTab(pObj, nTab))
705 xAnchor.set(cppu::getXWeak(new ScCellObj( pDocSh, pAnchor->maStart)));
706 else
707 xAnchor.set(cppu::getXWeak(new ScTableSheetObj( pDocSh, nTab )));
708 aAny <<= xAnchor;
709 }
710 }
711 }
712 }
713 }
714 }
715 else if (aPropertyName == SC_UNONAME_RESIZE_WITH_CELL)
716 {
717 bool bIsResizeWithCell = false;
718 SdrObject* pObj = GetSdrObject();
719 if (pObj)
720 {
721 ScAnchorType anchorType = ScDrawLayer::GetAnchorType(*pObj);
722 bIsResizeWithCell = (anchorType == SCA_CELL_RESIZE);
723 }
724 aAny <<= bIsResizeWithCell;
725 }
726 else if ( aPropertyName == SC_UNONAME_IMAGEMAP )
727 {
728 uno::Reference< uno::XInterface > xImageMap;
729 SdrObject* pObj = GetSdrObject();
730 if ( pObj )
731 {
733 if( pIMapInfo )
734 {
735 const ImageMap& rIMap = pIMapInfo->GetImageMap();
736 xImageMap.set(SvUnoImageMap_createInstance( rIMap, GetSupportedMacroItems() ));
737 }
738 else
739 xImageMap = SvUnoImageMap_createInstance();
740 }
741 aAny <<= uno::Reference< container::XIndexContainer >::query( xImageMap );
742 }
743 else if ( aPropertyName == SC_UNONAME_HORIPOS )
744 {
745 SdrObject *pObj = GetSdrObject();
746 if (pObj)
747 {
748 ScDrawLayer& rModel(static_cast< ScDrawLayer& >(pObj->getSdrModelFromSdrObject()));
749 SdrPage* pPage(pObj->getSdrPageFromSdrObject());
750
751 if ( pPage )
752 {
753 ScDocument* pDoc = rModel.GetDocument();
754 if ( pDoc )
755 {
756 SCTAB nTab = 0;
757 if ( lcl_GetPageNum( pPage, rModel, nTab ) )
758 {
759 uno::Reference<drawing::XShape> xShape( mxShapeAgg, uno::UNO_QUERY );
760 if (xShape.is())
761 {
764 {
765 awt::Size aUnoSize;
766 awt::Point aCaptionPoint;
767 ScRange aRange;
768 awt::Point aUnoPoint(lcl_GetRelativePos( xShape, pDoc, nTab, aRange, aUnoSize, aCaptionPoint ));
769 if (pDoc->IsNegativePage(nTab))
770 aUnoPoint.X *= -1;
771 aAny <<= aUnoPoint.X;
772 }
773 else
774 {
775 awt::Point aCaptionPoint;
776 awt::Point aUnoPoint(xShape->getPosition());
777 awt::Size aUnoSize(xShape->getSize());
778 if (pDoc->IsNegativePage(nTab))
779 {
780 aUnoPoint.X *= -1;
781 aUnoPoint.X -= aUnoSize.Width;
782 }
783 if (lcl_GetCaptionPoint(xShape, aCaptionPoint))
784 {
785 if (pDoc->IsNegativePage(nTab))
786 {
787 if (aCaptionPoint.X > 0 && aCaptionPoint.X > aUnoSize.Width)
788 aUnoPoint.X -= aCaptionPoint.X - aUnoSize.Width;
789 }
790 else
791 {
792 if (aCaptionPoint.X < 0)
793 aUnoPoint.X += aCaptionPoint.X;
794 }
795 }
796 aAny <<= aUnoPoint.X;
797 }
798 }
799 }
800 }
801 }
802 }
803 }
804 else if ( aPropertyName == SC_UNONAME_VERTPOS )
805 {
806 SdrObject *pObj = GetSdrObject();
807 if (pObj)
808 {
809 ScDrawLayer& rModel(static_cast< ScDrawLayer& >(pObj->getSdrModelFromSdrObject()));
810 SdrPage* pPage(pObj->getSdrPageFromSdrObject());
811
812 if ( pPage )
813 {
814 ScDocument* pDoc = rModel.GetDocument();
815 if ( pDoc )
816 {
817 SCTAB nTab = 0;
818 if ( lcl_GetPageNum( pPage, rModel, nTab ) )
819 {
820 uno::Reference<drawing::XShape> xShape( mxShapeAgg, uno::UNO_QUERY );
821 if (xShape.is())
822 {
825 {
826 awt::Size aUnoSize;
827 awt::Point aCaptionPoint;
828 ScRange aRange;
829 awt::Point aUnoPoint(lcl_GetRelativePos( xShape, pDoc, nTab, aRange, aUnoSize, aCaptionPoint ));
830
831 aAny <<= aUnoPoint.Y;
832 }
833 else
834 {
835 awt::Point aUnoPoint(xShape->getPosition());
836 awt::Point aCaptionPoint;
837 if (lcl_GetCaptionPoint(xShape, aCaptionPoint))
838 {
839 if (aCaptionPoint.Y < 0)
840 aUnoPoint.Y += aCaptionPoint.Y;
841 }
842 aAny <<= aUnoPoint.Y;
843 }
844 }
845 }
846 }
847 }
848 }
849 }
850 else if ( aPropertyName == SC_UNONAME_HYPERLINK ||
851 aPropertyName == SC_UNONAME_URL )
852 {
853 OUString sHlink;
854 if (SdrObject* pObj = GetSdrObject())
855 sHlink = pObj->getHyperlink();
856 aAny <<= sHlink;
857 }
858 else if ( aPropertyName == SC_UNONAME_MOVEPROTECT )
859 {
860 bool aProt = false;
861 if ( SdrObject* pObj = GetSdrObject() )
862 aProt = pObj->IsMoveProtect();
863 aAny <<= aProt;
864 }
865 else if ( aPropertyName == SC_UNONAME_STYLE )
866 {
867 if (SdrObject* pObj = GetSdrObject())
868 {
869 if (auto pStyleSheet = pObj->GetStyleSheet())
870 {
871 ScDrawLayer& rModel(static_cast< ScDrawLayer& >(pObj->getSdrModelFromSdrObject()));
872 ScDocument* pDoc = rModel.GetDocument();
873 aAny <<= uno::Reference<style::XStyle>(new ScStyleObj(
874 static_cast<ScDocShell*>(pDoc ? pDoc->GetDocumentShell() : nullptr),
875 SfxStyleFamily::Frame, pStyleSheet->GetName()));
876 }
877 }
878 }
879 else
880 {
881 if(!pShapePropertySet) //performance consideration
884 aAny = pShapePropertySet->getPropertyValue( aPropertyName );
885 }
886
887 return aAny;
888}
889
890void SAL_CALL ScShapeObj::addPropertyChangeListener( const OUString& aPropertyName,
891 const uno::Reference<beans::XPropertyChangeListener>& aListener)
892{
893 SolarMutexGuard aGuard;
894
897 pShapePropertySet->addPropertyChangeListener( aPropertyName, aListener );
898}
899
900void SAL_CALL ScShapeObj::removePropertyChangeListener( const OUString& aPropertyName,
901 const uno::Reference<beans::XPropertyChangeListener>& aListener)
902{
903 SolarMutexGuard aGuard;
904
907 pShapePropertySet->removePropertyChangeListener( aPropertyName, aListener );
908}
909
910void SAL_CALL ScShapeObj::addVetoableChangeListener( const OUString& aPropertyName,
911 const uno::Reference<beans::XVetoableChangeListener>& aListener)
912{
913 SolarMutexGuard aGuard;
914
917 pShapePropertySet->addVetoableChangeListener( aPropertyName, aListener );
918}
919
920void SAL_CALL ScShapeObj::removeVetoableChangeListener( const OUString& aPropertyName,
921 const uno::Reference<beans::XVetoableChangeListener>& aListener)
922{
923 SolarMutexGuard aGuard;
924
927 pShapePropertySet->removeVetoableChangeListener( aPropertyName, aListener );
928}
929
930// XPropertyState
931
932beans::PropertyState SAL_CALL ScShapeObj::getPropertyState( const OUString& aPropertyName )
933{
934 SolarMutexGuard aGuard;
935
936 beans::PropertyState eRet = beans::PropertyState_DIRECT_VALUE;
937 if ( aPropertyName == SC_UNONAME_IMAGEMAP )
938 {
939 // ImageMap is always "direct"
940 }
941 else if ( aPropertyName == SC_UNONAME_ANCHOR )
942 {
943 // Anchor is always "direct"
944 }
945 else if ( aPropertyName == SC_UNONAME_HORIPOS )
946 {
947 // HoriPos is always "direct"
948 }
949 else if ( aPropertyName == SC_UNONAME_VERTPOS )
950 {
951 // VertPos is always "direct"
952 }
953 else
954 {
957 eRet = pShapePropertyState->getPropertyState( aPropertyName );
958 }
959
960 return eRet;
961}
962
963uno::Sequence<beans::PropertyState> SAL_CALL ScShapeObj::getPropertyStates(
964 const uno::Sequence<OUString>& aPropertyNames )
965{
966 SolarMutexGuard aGuard;
967
968 // simple loop to get own and aggregated states
969
970 uno::Sequence<beans::PropertyState> aRet(aPropertyNames.getLength());
971 std::transform(aPropertyNames.begin(), aPropertyNames.end(), aRet.getArray(),
972 [this](const OUString& rName) -> beans::PropertyState { return getPropertyState(rName); });
973 return aRet;
974}
975
976void SAL_CALL ScShapeObj::setPropertyToDefault( const OUString& aPropertyName )
977{
978 SolarMutexGuard aGuard;
979
980 if ( aPropertyName == SC_UNONAME_IMAGEMAP )
981 {
982 SdrObject* pObj = GetSdrObject();
983 if ( pObj )
984 {
985 SvxIMapInfo* pIMapInfo = SvxIMapInfo::GetIMapInfo(pObj);
986 if( pIMapInfo )
987 {
988 ImageMap aEmpty;
989 pIMapInfo->SetImageMap( aEmpty ); // replace with empty image map
990 }
991 else
992 {
993 // nothing to do (no need to insert user data for an empty map)
994 }
995 }
996 }
997 else
998 {
1001 pShapePropertyState->setPropertyToDefault( aPropertyName );
1002 }
1003}
1004
1005uno::Any SAL_CALL ScShapeObj::getPropertyDefault( const OUString& aPropertyName )
1006{
1007 SolarMutexGuard aGuard;
1008
1009 uno::Any aAny;
1010 if ( aPropertyName == SC_UNONAME_IMAGEMAP )
1011 {
1012 // default: empty ImageMap
1013 uno::Reference< uno::XInterface > xImageMap(SvUnoImageMap_createInstance());
1014 aAny <<= uno::Reference< container::XIndexContainer >::query( xImageMap );
1015 }
1016 else
1017 {
1020 aAny = pShapePropertyState->getPropertyDefault( aPropertyName );
1021 }
1022
1023 return aAny;
1024}
1025
1026// XTextContent
1027
1028void SAL_CALL ScShapeObj::attach( const uno::Reference<text::XTextRange>& /* xTextRange */ )
1029{
1030 throw lang::IllegalArgumentException(); // anchor cannot be changed
1031}
1032
1033uno::Reference<text::XTextRange> SAL_CALL ScShapeObj::getAnchor()
1034{
1035 SolarMutexGuard aGuard;
1036
1037 uno::Reference<text::XTextRange> xRet;
1038
1039 SdrObject* pObj = GetSdrObject();
1040 if( pObj )
1041 {
1042 ScDrawLayer& rModel(static_cast< ScDrawLayer& >(pObj->getSdrModelFromSdrObject()));
1043 SdrPage* pPage(pObj->getSdrPageFromSdrObject());
1044 ScDocument* pDoc = rModel.GetDocument();
1045
1046 if ( pPage && pDoc )
1047 {
1048 SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
1049 if ( auto pDocSh = dynamic_cast<ScDocShell*>( pObjSh) )
1050 {
1051 SCTAB nTab = 0;
1052 if ( lcl_GetPageNum( pPage, rModel, nTab ) )
1053 {
1054 Point aPos(pObj->GetCurrentBoundRect().TopLeft());
1055 ScRange aRange(pDoc->GetRange( nTab, tools::Rectangle( aPos, aPos ) ));
1056
1057 // anchor is always the cell
1058
1059 xRet.set(new ScCellObj( pDocSh, aRange.aStart ));
1060 }
1061 }
1062 }
1063 }
1064
1065 return xRet;
1066}
1067
1068// XComponent
1069
1070void SAL_CALL ScShapeObj::dispose()
1071{
1072 SolarMutexGuard aGuard;
1073
1074 uno::Reference<lang::XComponent> xAggComp(lcl_GetComponent(mxShapeAgg));
1075 if ( xAggComp.is() )
1076 xAggComp->dispose();
1077}
1078
1080 const uno::Reference<lang::XEventListener>& xListener )
1081{
1082 SolarMutexGuard aGuard;
1083
1084 uno::Reference<lang::XComponent> xAggComp(lcl_GetComponent(mxShapeAgg));
1085 if ( xAggComp.is() )
1086 xAggComp->addEventListener(xListener);
1087}
1088
1090 const uno::Reference<lang::XEventListener>& xListener )
1091{
1092 SolarMutexGuard aGuard;
1093
1094 uno::Reference<lang::XComponent> xAggComp(lcl_GetComponent(mxShapeAgg));
1095 if ( xAggComp.is() )
1096 xAggComp->removeEventListener(xListener);
1097}
1098
1099// XText
1100// (special handling for ScCellFieldObj)
1101
1102static void lcl_CopyOneProperty( beans::XPropertySet& rDest, beans::XPropertySet& rSource, const OUString& aNameStr )
1103{
1104 try
1105 {
1106 rDest.setPropertyValue( aNameStr, rSource.getPropertyValue( aNameStr ) );
1107 }
1108 catch (uno::Exception&)
1109 {
1110 TOOLS_WARN_EXCEPTION( "sc", "Exception in text field");
1111 }
1112}
1113
1114void SAL_CALL ScShapeObj::insertTextContent( const uno::Reference<text::XTextRange>& xRange,
1115 const uno::Reference<text::XTextContent>& xContent,
1116 sal_Bool bAbsorb )
1117{
1118 SolarMutexGuard aGuard;
1119
1120 uno::Reference<text::XTextContent> xEffContent;
1121
1122 ScEditFieldObj* pCellField = dynamic_cast<ScEditFieldObj*>( xContent.get() );
1123 if ( pCellField )
1124 {
1125 // createInstance("TextField.URL") from the document creates a ScCellFieldObj.
1126 // To insert it into drawing text, a SvxUnoTextField is needed instead.
1127 // The ScCellFieldObj object is left in non-inserted state.
1128
1129 rtl::Reference<SvxUnoTextField> pDrawField = new SvxUnoTextField( text::textfield::Type::URL );
1130 xEffContent.set(pDrawField);
1131 lcl_CopyOneProperty( *pDrawField, *pCellField, SC_UNONAME_URL );
1132 lcl_CopyOneProperty( *pDrawField, *pCellField, SC_UNONAME_REPR );
1133 lcl_CopyOneProperty( *pDrawField, *pCellField, SC_UNONAME_TARGET );
1134 }
1135 else
1136 xEffContent.set(xContent);
1137
1138 uno::Reference<text::XText> xAggText(lcl_GetText(mxShapeAgg));
1139 if ( xAggText.is() )
1140 xAggText->insertTextContent( xRange, xEffContent, bAbsorb );
1141}
1142
1143void SAL_CALL ScShapeObj::removeTextContent( const uno::Reference<text::XTextContent>& xContent )
1144{
1145 SolarMutexGuard aGuard;
1146
1147 // ScCellFieldObj can't be used here.
1148
1149 uno::Reference<text::XText> xAggText(lcl_GetText(mxShapeAgg));
1150 if ( xAggText.is() )
1151 xAggText->removeTextContent( xContent );
1152}
1153
1154// XSimpleText (parent of XText)
1155// Use own SvxUnoTextCursor subclass - everything is just passed to aggregated object
1156
1157uno::Reference<text::XTextCursor> SAL_CALL ScShapeObj::createTextCursor()
1158{
1159 SolarMutexGuard aGuard;
1160
1161 if ( mxShapeAgg.is() )
1162 {
1163 // ScDrawTextCursor must be used to ensure the ScShapeObj is returned by getText
1164
1165 SvxUnoTextBase* pText = comphelper::getFromUnoTunnel<SvxUnoTextBase>( mxShapeAgg );
1166 if (pText)
1167 return new ScDrawTextCursor( this, *pText );
1168 }
1169
1170 return uno::Reference<text::XTextCursor>();
1171}
1172
1173uno::Reference<text::XTextCursor> SAL_CALL ScShapeObj::createTextCursorByRange(
1174 const uno::Reference<text::XTextRange>& aTextPosition )
1175{
1176 SolarMutexGuard aGuard;
1177
1178 if ( mxShapeAgg.is() && aTextPosition.is() )
1179 {
1180 // ScDrawTextCursor must be used to ensure the ScShapeObj is returned by getText
1181
1182 SvxUnoTextBase* pText = comphelper::getFromUnoTunnel<SvxUnoTextBase>( mxShapeAgg );
1183 SvxUnoTextRangeBase* pRange = comphelper::getFromUnoTunnel<SvxUnoTextRangeBase>( aTextPosition );
1184 if ( pText && pRange )
1185 {
1186 rtl::Reference<SvxUnoTextCursor> pCursor = new ScDrawTextCursor( this, *pText );
1187 pCursor->SetSelection( pRange->GetSelection() );
1188 return pCursor;
1189 }
1190 }
1191
1192 return uno::Reference<text::XTextCursor>();
1193}
1194
1195void SAL_CALL ScShapeObj::insertString( const uno::Reference<text::XTextRange>& xRange,
1196 const OUString& aString, sal_Bool bAbsorb )
1197{
1198 SolarMutexGuard aGuard;
1199
1200 uno::Reference<text::XSimpleText> xAggSimpleText(lcl_GetSimpleText(mxShapeAgg));
1201 if ( !xAggSimpleText.is() )
1202 throw uno::RuntimeException();
1203
1204 xAggSimpleText->insertString( xRange, aString, bAbsorb );
1205}
1206
1207void SAL_CALL ScShapeObj::insertControlCharacter( const uno::Reference<text::XTextRange>& xRange,
1208 sal_Int16 nControlCharacter, sal_Bool bAbsorb )
1209{
1210 SolarMutexGuard aGuard;
1211
1212 uno::Reference<text::XSimpleText> xAggSimpleText(lcl_GetSimpleText(mxShapeAgg));
1213 if ( !xAggSimpleText.is() )
1214 throw uno::RuntimeException();
1215
1216 xAggSimpleText->insertControlCharacter( xRange, nControlCharacter, bAbsorb );
1217}
1218
1219// XTextRange
1220// (parent of XSimpleText)
1221
1222uno::Reference<text::XText> SAL_CALL ScShapeObj::getText()
1223{
1224 return this;
1225}
1226
1227uno::Reference<text::XTextRange> SAL_CALL ScShapeObj::getStart()
1228{
1229 SolarMutexGuard aGuard;
1230
1231 uno::Reference<text::XTextRange> xAggTextRange(lcl_GetTextRange(mxShapeAgg));
1232 if ( !xAggTextRange.is() )
1233 throw uno::RuntimeException();
1234
1235 return xAggTextRange->getStart();
1236}
1237
1238uno::Reference<text::XTextRange> SAL_CALL ScShapeObj::getEnd()
1239{
1240 SolarMutexGuard aGuard;
1241
1242 uno::Reference<text::XTextRange> xAggTextRange(lcl_GetTextRange(mxShapeAgg));
1243 if ( !xAggTextRange.is() )
1244 throw uno::RuntimeException();
1245
1246 return xAggTextRange->getEnd();
1247}
1248
1249OUString SAL_CALL ScShapeObj::getString()
1250{
1251 SolarMutexGuard aGuard;
1252
1253 uno::Reference<text::XTextRange> xAggTextRange(lcl_GetTextRange(mxShapeAgg));
1254 if ( !xAggTextRange.is() )
1255 throw uno::RuntimeException();
1256
1257 return xAggTextRange->getString();
1258}
1259
1260void SAL_CALL ScShapeObj::setString( const OUString& aText )
1261{
1262 SolarMutexGuard aGuard;
1263
1264 uno::Reference<text::XTextRange> xAggTextRange(lcl_GetTextRange(mxShapeAgg));
1265 if ( !xAggTextRange.is() )
1266 throw uno::RuntimeException();
1267
1268 xAggTextRange->setString( aText );
1269}
1270
1271// XChild
1272
1273uno::Reference< uno::XInterface > SAL_CALL ScShapeObj::getParent()
1274{
1275 SolarMutexGuard aGuard;
1276
1277 // receive cell position from caption object (parent of a note caption is the note cell)
1278 SdrObject* pObj = GetSdrObject();
1279 if( pObj )
1280 {
1281 ScDrawLayer& rModel(static_cast< ScDrawLayer& >(pObj->getSdrModelFromSdrObject()));
1282 SdrPage* pPage(pObj->getSdrPageFromSdrObject());
1283 ScDocument* pDoc = rModel.GetDocument();
1284
1285 if ( pPage && pDoc )
1286 {
1287 SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
1288 if ( auto pDocSh = dynamic_cast<ScDocShell*>( pObjSh) )
1289 {
1290 SCTAB nTab = 0;
1291 if ( lcl_GetPageNum( pPage, rModel, nTab ) )
1292 {
1293 const ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObj, nTab );
1294 if( pCaptData )
1295 return cppu::getXWeak( new ScCellObj( pDocSh, pCaptData->maStart ) );
1296 }
1297 }
1298 }
1299 }
1300
1301 return nullptr;
1302}
1303
1304void SAL_CALL ScShapeObj::setParent( const uno::Reference< uno::XInterface >& )
1305{
1306 throw lang::NoSupportException();
1307}
1308
1309// XTypeProvider
1310
1311uno::Sequence<uno::Type> SAL_CALL ScShapeObj::getTypes()
1312{
1313 uno::Sequence< uno::Type > aBaseTypes( ScShapeObj_Base::getTypes() );
1314
1315 uno::Sequence< uno::Type > aTextTypes;
1316 if ( bIsTextShape )
1317 aTextTypes = ScShapeObj_TextBase::getTypes();
1318
1319 uno::Reference<lang::XTypeProvider> xBaseProvider;
1320 if ( mxShapeAgg.is() )
1321 mxShapeAgg->queryAggregation( cppu::UnoType<lang::XTypeProvider>::get()) >>= xBaseProvider;
1322 OSL_ENSURE( xBaseProvider.is(), "ScShapeObj: No XTypeProvider from aggregated shape!" );
1323
1324 uno::Sequence< uno::Type > aAggTypes;
1325 if( xBaseProvider.is() )
1326 aAggTypes = xBaseProvider->getTypes();
1327
1328 return ::comphelper::concatSequences( aBaseTypes, aTextTypes, aAggTypes );
1329}
1330
1331uno::Sequence<sal_Int8> SAL_CALL ScShapeObj::getImplementationId()
1332{
1333 return css::uno::Sequence<sal_Int8>();
1334}
1335
1337{
1338 if(mxShapeAgg.is())
1340 return nullptr;
1341}
1342
1343constexpr OUStringLiteral SC_EVENTACC_ONCLICK = u"OnClick";
1344constexpr OUStringLiteral SC_EVENTACC_SCRIPT = u"Script";
1345constexpr OUStringLiteral SC_EVENTACC_EVENTTYPE = u"EventType";
1346
1347class ShapeUnoEventAccessImpl : public ::cppu::WeakImplHelper< container::XNameReplace >
1348{
1349private:
1351
1352 ScMacroInfo* getInfo( bool bCreate )
1353 {
1354 return ScShapeObj_getShapeHyperMacroInfo( mpShape, bCreate );
1355 }
1356
1357public:
1358 explicit ShapeUnoEventAccessImpl( ScShapeObj* pShape ): mpShape( pShape )
1359 {
1360 }
1361
1362 // XNameReplace
1363 virtual void SAL_CALL replaceByName( const OUString& aName, const uno::Any& aElement ) override
1364 {
1365 if ( !hasByName( aName ) )
1366 throw container::NoSuchElementException();
1367 uno::Sequence< beans::PropertyValue > aProperties;
1368 aElement >>= aProperties;
1369 bool isEventType = false;
1370 for( const beans::PropertyValue& rProperty : std::as_const(aProperties) )
1371 {
1372 if ( rProperty.Name == SC_EVENTACC_EVENTTYPE )
1373 {
1374 isEventType = true;
1375 continue;
1376 }
1377 if ( isEventType && (rProperty.Name == SC_EVENTACC_SCRIPT) )
1378 {
1379 OUString sValue;
1380 if ( rProperty.Value >>= sValue )
1381 {
1382 ScMacroInfo* pInfo = getInfo( true );
1383 OSL_ENSURE( pInfo, "shape macro info could not be created!" );
1384 if ( !pInfo )
1385 break;
1386 pInfo->SetMacro( sValue );
1387 }
1388 }
1389 }
1390 }
1391
1392 // XNameAccess
1393 virtual uno::Any SAL_CALL getByName( const OUString& aName ) override
1394 {
1395 uno::Sequence< beans::PropertyValue > aProperties;
1396 ScMacroInfo* pInfo = getInfo(false);
1397
1398 if ( aName != SC_EVENTACC_ONCLICK )
1399 {
1400 throw container::NoSuchElementException();
1401 }
1402
1403 if ( pInfo && !pInfo->GetMacro().isEmpty() )
1404 {
1406 OUString(SC_EVENTACC_SCRIPT)),
1408 }
1409
1410 return uno::Any( aProperties );
1411 }
1412
1413 virtual uno::Sequence< OUString > SAL_CALL getElementNames() override
1414 {
1415 uno::Sequence<OUString> aSeq { SC_EVENTACC_ONCLICK };
1416 return aSeq;
1417 }
1418
1419 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override
1420 {
1421 return aName == SC_EVENTACC_ONCLICK;
1422 }
1423
1424 // XElementAccess
1425 virtual uno::Type SAL_CALL getElementType() override
1426 {
1428 }
1429
1430 virtual sal_Bool SAL_CALL hasElements() override
1431 {
1432 // elements are always present (but contained property sequences may be empty)
1433 return true;
1434 }
1435};
1436
1437::uno::Reference< container::XNameReplace > SAL_CALL
1439{
1440 return new ShapeUnoEventAccessImpl( this );
1441}
1442
1444{
1445 return "com.sun.star.comp.sc.ScShapeObj";
1446}
1447
1448sal_Bool SAL_CALL ScShapeObj::supportsService( const OUString& ServiceName )
1449{
1450 return cppu::supportsService(this, ServiceName);
1451}
1452
1453uno::Sequence< OUString > SAL_CALL ScShapeObj::getSupportedServiceNames( )
1454{
1455 uno::Reference<lang::XServiceInfo> xSI;
1456 if ( mxShapeAgg.is() )
1457 mxShapeAgg->queryAggregation( cppu::UnoType<lang::XServiceInfo>::get() ) >>= xSI;
1458
1459 uno::Sequence< OUString > aSupported;
1460 if ( xSI.is() )
1461 aSupported = xSI->getSupportedServiceNames();
1462
1463 aSupported.realloc( aSupported.getLength() + 1 );
1464 aSupported.getArray()[ aSupported.getLength() - 1 ] = "com.sun.star.sheet.Shape";
1465
1466 if( bIsNoteCaption )
1467 {
1468 aSupported.realloc( aSupported.getLength() + 1 );
1469 aSupported.getArray()[ aSupported.getLength() - 1 ] = "com.sun.star.sheet.CellAnnotationShape";
1470 }
1471
1472 return aSupported;
1473}
1474
1475/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OptionalString sType
PropertiesInfo aProperties
constexpr tools::Long Y() const
constexpr tools::Long X() const
SCTAB Tab() const
Definition: address.hxx:283
SCROW Row() const
Definition: address.hxx:274
SCCOL Col() const
Definition: address.hxx:279
really derive cell from range?
Definition: cellsuno.hxx:640
SC_DLLPUBLIC ScRange GetRange(SCTAB nTab, const tools::Rectangle &rMMRect, bool bHiddenAsZero=true) const
Definition: documen3.cxx:1797
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:892
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:893
SC_DLLPUBLIC bool IsNegativePage(SCTAB nTab) const
Definition: document.cxx:982
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1083
SC_DLLPUBLIC tools::Rectangle GetMMRect(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: documen3.cxx:1986
static ScDrawObjData * GetObjDataTab(SdrObject *pObj, SCTAB nTab)
Definition: drwlayer.cxx:2888
static ScDrawObjData * GetObjData(SdrObject *pObj, bool bCreate=false)
Definition: drwlayer.cxx:2874
static bool IsNoteCaption(SdrObject *pObj)
Returns true, if the passed object is the caption of a cell note.
Definition: drwlayer.cxx:2901
ScDocument * GetDocument() const
Definition: drwlayer.hxx:131
static ScMacroInfo * GetMacroInfo(SdrObject *pObj, bool bCreate=false)
Definition: drwlayer.cxx:2913
static void SetPageAnchored(SdrObject &)
Definition: drwlayer.cxx:2718
static ScAnchorType GetAnchorType(const SdrObject &)
Definition: drwlayer.cxx:2724
static ScDrawObjData * GetNoteCaptionData(SdrObject *pObj, SCTAB nTab)
Returns the object data, if the passed object is a cell note caption.
Definition: drwlayer.cxx:2907
static void SetCellAnchored(SdrObject &, const ScDrawObjData &rAnchor)
Definition: drwlayer.cxx:2565
static void UpdateCellAnchorFromPositionEnd(const SdrObject &rObj, ScDrawObjData &rAnchor, const ScDocument &rDoc, SCTAB nTab, bool bUseLogicRect=true)
Definition: drwlayer.cxx:2683
ScAddress maStart
Definition: userdat.hxx:36
Point maStartOffset
Definition: userdat.hxx:38
bool mbResizeWithCell
Definition: userdat.hxx:41
const OUString & GetMacro() const
Definition: userdat.hxx:82
void SetMacro(const OUString &rMacro)
Definition: userdat.hxx:81
ScAddress aEnd
Definition: address.hxx:498
ScAddress aStart
Definition: address.hxx:497
virtual css::beans::PropertyState SAL_CALL getPropertyState(const OUString &PropertyName) override
Definition: shapeuno.cxx:932
css::beans::XPropertySet * pShapePropertySet
Definition: shapeuno.hxx:67
static const SvEventDescription * GetSupportedMacroItems()
Definition: shapeuno.cxx:69
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override
Definition: shapeuno.cxx:1227
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
Definition: shapeuno.cxx:311
virtual css::uno::Reference< css::container::XNameReplace > SAL_CALL getEvents() override
Definition: shapeuno.cxx:1438
SdrObject * GetSdrObject() const noexcept
Definition: shapeuno.cxx:1336
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
Definition: shapeuno.cxx:1089
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
Definition: shapeuno.cxx:1331
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: shapeuno.cxx:679
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getAnchor() override
Definition: shapeuno.cxx:1033
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
Definition: shapeuno.cxx:890
ScShapeObj(css::uno::Reference< css::drawing::XShape > &xShape)
Definition: shapeuno.cxx:85
virtual css::uno::Any SAL_CALL getPropertyDefault(const OUString &aPropertyName) override
Definition: shapeuno.cxx:1005
virtual void SAL_CALL setPropertyToDefault(const OUString &PropertyName) override
Definition: shapeuno.cxx:976
void GetShapePropertyState()
Definition: shapeuno.cxx:168
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: shapeuno.cxx:1453
virtual void SAL_CALL setParent(const css::uno::Reference< css::uno::XInterface > &xParent) override
Definition: shapeuno.cxx:1304
virtual void SAL_CALL release() noexcept override
Definition: shapeuno.cxx:149
virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursorByRange(const css::uno::Reference< css::text::XTextRange > &aTextPosition) override
Definition: shapeuno.cxx:1173
virtual void SAL_CALL acquire() noexcept override
Definition: shapeuno.cxx:144
virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override
Definition: shapeuno.cxx:1222
void GetShapePropertySet()
Definition: shapeuno.cxx:154
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
Definition: shapeuno.cxx:900
friend class ShapeUnoEventAccessImpl
Definition: shapeuno.hxx:78
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override
Definition: shapeuno.cxx:1238
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: shapeuno.cxx:910
virtual void SAL_CALL insertString(const css::uno::Reference< css::text::XTextRange > &xRange, const OUString &aString, sal_Bool bAbsorb) override
Definition: shapeuno.cxx:1195
virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursor() override
Definition: shapeuno.cxx:1157
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Definition: shapeuno.cxx:1311
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: shapeuno.cxx:920
virtual void SAL_CALL attach(const css::uno::Reference< css::text::XTextRange > &xTextRange) override
Definition: shapeuno.cxx:1028
virtual OUString SAL_CALL getImplementationName() override
Definition: shapeuno.cxx:1443
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getParent() override
Definition: shapeuno.cxx:1273
virtual void SAL_CALL removeTextContent(const css::uno::Reference< css::text::XTextContent > &xContent) override
Definition: shapeuno.cxx:1143
css::uno::Reference< css::beans::XPropertySetInfo > mxPropSetInfo
Definition: shapeuno.hxx:69
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: shapeuno.cxx:216
virtual void SAL_CALL dispose() override
Definition: shapeuno.cxx:1070
virtual void SAL_CALL insertTextContent(const css::uno::Reference< css::text::XTextRange > &xRange, const css::uno::Reference< css::text::XTextContent > &xContent, sal_Bool bAbsorb) override
Definition: shapeuno.cxx:1114
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
Definition: shapeuno.cxx:1079
virtual ~ScShapeObj() override
Definition: shapeuno.cxx:120
bool bIsNoteCaption
Definition: shapeuno.hxx:71
css::beans::XPropertyState * pShapePropertyState
Definition: shapeuno.hxx:68
virtual void SAL_CALL insertControlCharacter(const css::uno::Reference< css::text::XTextRange > &xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb) override
Definition: shapeuno.cxx:1207
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
Definition: shapeuno.cxx:128
virtual OUString SAL_CALL getString() override
Definition: shapeuno.cxx:1249
virtual void SAL_CALL setString(const OUString &aString) override
Definition: shapeuno.cxx:1260
css::uno::Reference< css::uno::XAggregation > mxShapeAgg
Definition: shapeuno.hxx:65
virtual css::uno::Sequence< css::beans::PropertyState > SAL_CALL getPropertyStates(const css::uno::Sequence< OUString > &aPropertyName) override
Definition: shapeuno.cxx:963
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: shapeuno.cxx:1448
bool bIsTextShape
Definition: shapeuno.hxx:70
const SdrPage * GetPage(sal_uInt16 nPgNum) const
sal_uInt16 GetPageCount() const
static SdrObject * getSdrObjectFromXShape(const css::uno::Reference< css::uno::XInterface > &xInt)
void AppendUserData(std::unique_ptr< SdrObjUserData > pData)
virtual const tools::Rectangle & GetCurrentBoundRect() const
SdrModel & getSdrModelFromSdrObject() const
SdrPage * getSdrPageFromSdrObject() const
void setHyperlink(const OUString &sHyperlink)
const OUString & GetName() const
virtual uno::Sequence< OUString > SAL_CALL getElementNames() override
Definition: shapeuno.cxx:1413
virtual sal_Bool SAL_CALL hasElements() override
Definition: shapeuno.cxx:1430
virtual uno::Type SAL_CALL getElementType() override
Definition: shapeuno.cxx:1425
virtual uno::Any SAL_CALL getByName(const OUString &aName) override
Definition: shapeuno.cxx:1393
ScMacroInfo * getInfo(bool bCreate)
Definition: shapeuno.cxx:1352
ShapeUnoEventAccessImpl(ScShapeObj *pShape)
Definition: shapeuno.cxx:1358
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
Definition: shapeuno.cxx:1419
virtual void SAL_CALL replaceByName(const OUString &aName, const uno::Any &aElement) override
Definition: shapeuno.cxx:1363
void SetImageMap(const ImageMap &rIMap)
static SvxIMapInfo * GetIMapInfo(const SdrObject *pObject)
const ImageMap & GetImageMap() const
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) SAL_OVERRIDE
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() SAL_OVERRIDE
css::uno::Type const & get()
constexpr Point TopLeft() const
constexpr Point BottomRight() const
constexpr Point TopRight() const
constexpr Point BottomLeft() const
inline ::Point VCLPoint(const css::awt::Point &rAWTPoint)
int nCount
#define TOOLS_WARN_EXCEPTION(area, stream)
ULONG m_refCount
float u
ScAnchorType
Definition: global.hxx:374
@ SCA_CELL_RESIZE
Definition: global.hxx:376
@ SCA_CELL
Definition: global.hxx:375
@ SCA_PAGE
Definition: global.hxx:377
OUString aName
sal_uInt16 nPos
Sequence< sal_Int8 > aSeq
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
static void lcl_CopyOneProperty(beans::XPropertySet &rDest, beans::XPropertySet &rSource, const OUString &aNameStr)
Definition: shapeuno.cxx:1102
static uno::Reference< text::XTextRange > lcl_GetTextRange(const uno::Reference< uno::XAggregation > &xAgg)
Definition: shapeuno.cxx:206
static uno::Reference< text::XSimpleText > lcl_GetSimpleText(const uno::Reference< uno::XAggregation > &xAgg)
Definition: shapeuno.cxx:198
constexpr OUStringLiteral SC_EVENTACC_ONCLICK
Definition: shapeuno.cxx:1343
constexpr OUStringLiteral SC_EVENTACC_EVENTTYPE
Definition: shapeuno.cxx:1345
static ScRange lcl_GetAnchorCell(const uno::Reference< drawing::XShape > &xShape, const ScDocument *pDoc, SCTAB nTab, awt::Point &rUnoPoint, awt::Size &rUnoSize, awt::Point &rCaptionPoint)
Definition: shapeuno.cxx:265
static uno::Reference< lang::XComponent > lcl_GetComponent(const uno::Reference< uno::XAggregation > &xAgg)
Definition: shapeuno.cxx:182
static bool lcl_GetCaptionPoint(const uno::Reference< drawing::XShape > &xShape, awt::Point &rCaptionPoint)
Definition: shapeuno.cxx:248
static uno::Reference< text::XText > lcl_GetText(const uno::Reference< uno::XAggregation > &xAgg)
Definition: shapeuno.cxx:190
constexpr OUStringLiteral SC_EVENTACC_SCRIPT
Definition: shapeuno.cxx:1344
ScMacroInfo * ScShapeObj_getShapeHyperMacroInfo(const ScShapeObj *pShape, bool bCreate=false)
Definition: shapeuno.cxx:77
static awt::Point lcl_GetRelativePos(const uno::Reference< drawing::XShape > &xShape, const ScDocument *pDoc, SCTAB nTab, ScRange &rRange, awt::Size &rUnoSize, awt::Point &rCaptionPoint)
Definition: shapeuno.cxx:299
static bool lcl_GetPageNum(const SdrPage *pPage, SdrModel &rModel, SCTAB &rNum)
Definition: shapeuno.cxx:235
static o3tl::span< const SfxItemPropertyMapEntry > lcl_GetShapeMap()
Definition: shapeuno.cxx:52
bool hasValue()
unsigned char sal_Bool
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17
SVT_DLLPUBLIC css::uno::Reference< css::uno::XInterface > SvUnoImageMap_createInstance()
SVT_DLLPUBLIC bool SvUnoImageMap_fillImageMap(const css::uno::Reference< css::uno::XInterface > &xImageMap, ImageMap &rMap)
constexpr OUStringLiteral SC_UNONAME_HYPERLINK
Definition: unonames.hxx:206
constexpr OUStringLiteral SC_UNONAME_HORIPOS
Definition: unonames.hxx:204
constexpr OUStringLiteral SC_UNONAME_MOVEPROTECT
Definition: unonames.hxx:207
constexpr OUStringLiteral SC_UNONAME_REPR
Definition: unonames.hxx:338
constexpr OUStringLiteral SC_UNONAME_ANCHOR
Definition: unonames.hxx:202
constexpr OUStringLiteral SC_UNONAME_VERTPOS
Definition: unonames.hxx:205
constexpr OUStringLiteral SC_UNONAME_URL
Definition: unonames.hxx:340
constexpr OUStringLiteral SC_UNONAME_IMAGEMAP
Definition: unonames.hxx:201
constexpr OUStringLiteral SC_UNONAME_TARGET
Definition: unonames.hxx:339
constexpr OUStringLiteral SC_UNONAME_RESIZE_WITH_CELL
Definition: unonames.hxx:203
constexpr OUStringLiteral SC_UNONAME_STYLE
Definition: unonames.hxx:208