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