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