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