Line data Source code
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 <cmdid.h>
23 :
24 : #include <drawdoc.hxx>
25 : #include <unodraw.hxx>
26 : #include <unocoll.hxx>
27 : #include <unoframe.hxx>
28 : #include <unoparagraph.hxx>
29 : #include <unotextrange.hxx>
30 : #include <svx/svditer.hxx>
31 : #include <swunohelper.hxx>
32 : #include <textboxhelper.hxx>
33 : #include <doc.hxx>
34 : #include <docary.hxx>
35 : #include <IDocumentUndoRedo.hxx>
36 : #include <IDocumentDrawModelAccess.hxx>
37 : #include <IDocumentLayoutAccess.hxx>
38 : #include <fmtcntnt.hxx>
39 : #include <fmtflcnt.hxx>
40 : #include <txtatr.hxx>
41 : #include <docsh.hxx>
42 : #include <unomap.hxx>
43 : #include <unoport.hxx>
44 : #include <TextCursorHelper.hxx>
45 : #include <dflyobj.hxx>
46 : #include <ndtxt.hxx>
47 : #include <svx/svdview.hxx>
48 : #include <svx/unoshape.hxx>
49 : #include <dcontact.hxx>
50 : #include <svx/fmglob.hxx>
51 : #include <fmtornt.hxx>
52 : #include <fmtsrnd.hxx>
53 : #include <fmtfollowtextflow.hxx>
54 : #include <rootfrm.hxx>
55 : #include <editeng/lrspitem.hxx>
56 : #include <editeng/ulspitem.hxx>
57 : #include <svx/shapepropertynotifier.hxx>
58 : #include <crstate.hxx>
59 : #include <comphelper/extract.hxx>
60 : #include <comphelper/makesequence.hxx>
61 : #include <cppuhelper/supportsservice.hxx>
62 : #include <svx/scene3d.hxx>
63 : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
64 : #include <fmtwrapinfluenceonobjpos.hxx>
65 : #include <com/sun/star/text/TextContentAnchorType.hpp>
66 : #include <basegfx/matrix/b2dhommatrixtools.hxx>
67 : #include <com/sun/star/drawing/PointSequence.hpp>
68 : #include <calbck.hxx>
69 :
70 : using namespace ::com::sun::star;
71 :
72 : class SwShapeDescriptor_Impl
73 : {
74 : SwFormatHoriOrient* pHOrient;
75 : SwFormatVertOrient* pVOrient;
76 : SwFormatAnchor* pAnchor;
77 : SwFormatSurround* pSurround;
78 : SvxULSpaceItem* pULSpace;
79 : SvxLRSpaceItem* pLRSpace;
80 : bool bOpaque;
81 : uno::Reference< text::XTextRange > xTextRange;
82 : // #i26791#
83 : SwFormatFollowTextFlow* mpFollowTextFlow;
84 : // #i28701#
85 : SwFormatWrapInfluenceOnObjPos* pWrapInfluenceOnObjPos;
86 : // #i28749#
87 : sal_Int16 mnPositionLayoutDir;
88 :
89 : public:
90 : bool bInitializedPropertyNotifier;
91 :
92 : public:
93 8410 : SwShapeDescriptor_Impl() :
94 : // #i32349# - no defaults, in order to determine on
95 : // adding a shape, if positioning attributes are set or not.
96 : pHOrient( 0L ),
97 : pVOrient( 0L ),
98 : pAnchor(0),
99 : pSurround(0),
100 : pULSpace(0),
101 : pLRSpace(0),
102 : bOpaque(false),
103 : // #i26791#
104 8410 : mpFollowTextFlow( new SwFormatFollowTextFlow( false ) ),
105 : // #i28701# #i35017#
106 : pWrapInfluenceOnObjPos( new SwFormatWrapInfluenceOnObjPos(
107 8410 : text::WrapInfluenceOnPosition::ONCE_CONCURRENT ) ),
108 : // #i28749#
109 : mnPositionLayoutDir( text::PositionLayoutDir::PositionInLayoutDirOfAnchor ),
110 25230 : bInitializedPropertyNotifier(false)
111 8410 : {}
112 :
113 8410 : ~SwShapeDescriptor_Impl()
114 8410 : {
115 8410 : delete pHOrient;
116 8410 : delete pVOrient;
117 8410 : delete pAnchor;
118 8410 : delete pSurround;
119 8410 : delete pULSpace;
120 8410 : delete pLRSpace;
121 : // #i26791#
122 8410 : delete mpFollowTextFlow;
123 : // #i28701#
124 8410 : delete pWrapInfluenceOnObjPos;
125 8410 : }
126 5852 : SwFormatAnchor* GetAnchor(bool bCreate = false)
127 : {
128 5852 : if(bCreate && !pAnchor)
129 : {
130 208 : pAnchor = new SwFormatAnchor(FLY_AS_CHAR);
131 : }
132 5852 : return pAnchor;
133 : }
134 13857 : SwFormatHoriOrient* GetHOrient(bool bCreate = false)
135 : {
136 13857 : if (bCreate && !pHOrient)
137 : {
138 : // #i26791#
139 2082 : pHOrient = new SwFormatHoriOrient( 0, text::HoriOrientation::NONE, text::RelOrientation::FRAME );
140 : }
141 13857 : return pHOrient;
142 : }
143 13826 : SwFormatVertOrient* GetVOrient(bool bCreate = false)
144 : {
145 13826 : if(bCreate && !pVOrient)
146 : {
147 : // #i26791#
148 2087 : pVOrient = new SwFormatVertOrient( 0, text::VertOrientation::NONE, text::RelOrientation::FRAME );
149 : }
150 13826 : return pVOrient;
151 : }
152 :
153 4162 : SwFormatSurround* GetSurround(bool bCreate = false)
154 : {
155 4162 : if(bCreate && !pSurround)
156 0 : pSurround = new SwFormatSurround();
157 4162 : return pSurround;
158 : }
159 2087 : SvxLRSpaceItem* GetLRSpace(bool bCreate = false)
160 : {
161 2087 : if(bCreate && !pLRSpace)
162 2 : pLRSpace = new SvxLRSpaceItem(RES_LR_SPACE);
163 2087 : return pLRSpace;
164 : }
165 2084 : SvxULSpaceItem* GetULSpace(bool bCreate = false)
166 : {
167 2084 : if(bCreate && !pULSpace)
168 1 : pULSpace = new SvxULSpaceItem(RES_UL_SPACE);
169 2084 : return pULSpace;
170 : }
171 2408 : uno::Reference< text::XTextRange > & GetTextRange()
172 : {
173 2408 : return xTextRange;
174 : }
175 2081 : bool IsOpaque() const
176 : {
177 2081 : return bOpaque;
178 : }
179 1627 : const bool& GetOpaque() const
180 : {
181 1627 : return bOpaque;
182 : }
183 0 : void RemoveHOrient(){DELETEZ(pHOrient);}
184 0 : void RemoveVOrient(){DELETEZ(pVOrient);}
185 0 : void RemoveAnchor(){DELETEZ(pAnchor);}
186 0 : void RemoveSurround(){DELETEZ(pSurround);}
187 0 : void RemoveULSpace(){DELETEZ(pULSpace);}
188 0 : void RemoveLRSpace(){DELETEZ(pLRSpace);}
189 86 : void SetOpaque(bool bSet){bOpaque = bSet;}
190 :
191 : // #i26791#
192 4162 : SwFormatFollowTextFlow* GetFollowTextFlow( bool _bCreate = false )
193 : {
194 4162 : if ( _bCreate && !mpFollowTextFlow )
195 0 : mpFollowTextFlow = new SwFormatFollowTextFlow( false );
196 4162 : return mpFollowTextFlow;
197 : }
198 0 : void RemoveFollowTextFlow()
199 : {
200 0 : DELETEZ(mpFollowTextFlow);
201 0 : }
202 :
203 : // #i28749#
204 0 : sal_Int16 GetPositionLayoutDir() const
205 : {
206 0 : return mnPositionLayoutDir;
207 : }
208 0 : void SetPositionLayoutDir( sal_Int16 _nPositionLayoutDir )
209 : {
210 0 : switch ( _nPositionLayoutDir )
211 : {
212 : case text::PositionLayoutDir::PositionInHoriL2R:
213 : case text::PositionLayoutDir::PositionInLayoutDirOfAnchor:
214 : {
215 0 : mnPositionLayoutDir = _nPositionLayoutDir;
216 : }
217 0 : break;
218 : default:
219 : {
220 : OSL_FAIL( "<SwShapeDescriptor_Impl::SetPositionLayoutDir(..)> - invalid attribute value." );
221 : }
222 : }
223 0 : }
224 :
225 : // #i28701#
226 4162 : inline SwFormatWrapInfluenceOnObjPos* GetWrapInfluenceOnObjPos(
227 : const bool _bCreate = false )
228 : {
229 4162 : if ( _bCreate && !pWrapInfluenceOnObjPos )
230 : {
231 : pWrapInfluenceOnObjPos = new SwFormatWrapInfluenceOnObjPos(
232 : // #i35017#
233 0 : text::WrapInfluenceOnPosition::ONCE_CONCURRENT );
234 : }
235 4162 : return pWrapInfluenceOnObjPos;
236 : }
237 0 : inline void RemoveWrapInfluenceOnObjPos()
238 : {
239 0 : DELETEZ(pWrapInfluenceOnObjPos);
240 0 : }
241 : };
242 :
243 2699 : SwFmDrawPage::SwFmDrawPage( SdrPage* pPage ) :
244 2699 : SvxFmDrawPage( pPage ), pPageView(0)
245 : {
246 2699 : }
247 :
248 8085 : SwFmDrawPage::~SwFmDrawPage() throw ()
249 : {
250 2695 : RemovePageView();
251 5390 : }
252 :
253 0 : const SdrMarkList& SwFmDrawPage::PreGroup(const uno::Reference< drawing::XShapes > & xShapes)
254 : {
255 0 : _SelectObjectsInView( xShapes, GetPageView() );
256 0 : const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
257 0 : return rMarkList;
258 : }
259 :
260 0 : void SwFmDrawPage::PreUnGroup(const uno::Reference< drawing::XShapeGroup >& rShapeGroup)
261 : {
262 0 : uno::Reference< drawing::XShape > xShape( rShapeGroup, uno::UNO_QUERY);
263 0 : _SelectObjectInView( xShape, GetPageView() );
264 0 : }
265 :
266 0 : SdrPageView* SwFmDrawPage::GetPageView()
267 : {
268 0 : if(!pPageView)
269 0 : pPageView = mpView->ShowSdrPage( mpPage );
270 0 : return pPageView;
271 : }
272 :
273 2695 : void SwFmDrawPage::RemovePageView()
274 : {
275 2695 : if(pPageView && mpView)
276 0 : mpView->HideSdrPage();
277 2695 : pPageView = 0;
278 2695 : }
279 :
280 0 : uno::Reference< uno::XInterface > SwFmDrawPage::GetInterface( SdrObject* pObj )
281 : {
282 0 : uno::Reference< XInterface > xShape;
283 0 : if( pObj )
284 : {
285 0 : SwFrameFormat* pFormat = ::FindFrameFormat( pObj );
286 0 : SwXShape* pxShape = SwIterator<SwXShape,SwFormat>( *pFormat ).First();
287 0 : if(pxShape)
288 : {
289 0 : xShape = *static_cast<cppu::OWeakObject*>(pxShape);
290 : }
291 : else
292 0 : xShape = pObj->getUnoShape();
293 : }
294 0 : return xShape;
295 : }
296 :
297 3440 : SdrObject* SwFmDrawPage::_CreateSdrObject( const uno::Reference< drawing::XShape > & xShape )
298 : throw (uno::RuntimeException, std::exception)
299 : {
300 : //FIXME: just a redirect call - can this method be deleted?
301 3440 : return SvxFmDrawPage::_CreateSdrObject( xShape );
302 : }
303 :
304 6001 : uno::Reference< drawing::XShape > SwFmDrawPage::_CreateShape( SdrObject *pObj ) const
305 : throw (uno::RuntimeException, std::exception)
306 : {
307 6001 : uno::Reference< drawing::XShape > xRet;
308 6001 : if(pObj->ISA(SwVirtFlyDrawObj) || pObj->GetObjInventor() == SWGInventor)
309 : {
310 1305 : SwFlyDrawContact* pFlyContact = static_cast<SwFlyDrawContact*>(pObj->GetUserCall());
311 1305 : if(pFlyContact)
312 : {
313 1305 : SwFrameFormat* pFlyFormat = pFlyContact->GetFormat();
314 1305 : SwDoc* pDoc = pFlyFormat->GetDoc();
315 : const SwNodeIndex* pIdx;
316 2610 : if( RES_FLYFRMFMT == pFlyFormat->Which()
317 1305 : && 0 != ( pIdx = pFlyFormat->GetContent().GetContentIdx() )
318 2610 : && pIdx->GetNodes().IsDocNodes()
319 : )
320 : {
321 1305 : const SwNode* pNd = pDoc->GetNodes()[ pIdx->GetIndex() + 1 ];
322 1305 : if(!pNd->IsNoTextNode())
323 : {
324 : xRet.set(SwXTextFrame::CreateXTextFrame(*pDoc, pFlyFormat),
325 743 : uno::UNO_QUERY);
326 : }
327 562 : else if( pNd->IsGrfNode() )
328 : {
329 : xRet.set(SwXTextGraphicObject::CreateXTextGraphicObject(
330 353 : *pDoc, pFlyFormat), uno::UNO_QUERY);
331 : }
332 209 : else if( pNd->IsOLENode() )
333 : {
334 : xRet.set(SwXTextEmbeddedObject::CreateXTextEmbeddedObject(
335 209 : *pDoc, pFlyFormat), uno::UNO_QUERY);
336 : }
337 : }
338 : else
339 : {
340 : OSL_FAIL( "<SwFmDrawPage::_CreateShape(..)> - could not retrieve type. Thus, no shape created." );
341 0 : return xRet;
342 : }
343 : }
344 : }
345 : else
346 : {
347 : // own block - temporary object has to be destroyed before
348 : // the delegator is set #81670#
349 : {
350 4696 : xRet = SvxFmDrawPage::_CreateShape( pObj );
351 : }
352 4696 : uno::Reference< XUnoTunnel > xShapeTunnel(xRet, uno::UNO_QUERY);
353 : //don't create an SwXShape if it already exists
354 4696 : SwXShape* pShape = 0;
355 4696 : if(xShapeTunnel.is())
356 : pShape = reinterpret_cast< SwXShape * >(
357 4696 : sal::static_int_cast< sal_IntPtr >( xShapeTunnel->getSomething(SwXShape::getUnoTunnelId()) ));
358 4696 : if(!pShape)
359 : {
360 4696 : xShapeTunnel = 0;
361 4696 : uno::Reference< uno::XInterface > xCreate(xRet, uno::UNO_QUERY);
362 4696 : xRet = 0;
363 9392 : uno::Reference< beans::XPropertySet > xPrSet;
364 4696 : if ( pObj->IsGroupObject() && (!pObj->Is3DObj() || (pObj->ISA(E3dScene))) )
365 209 : xPrSet = new SwXGroupShape( xCreate );
366 : else
367 4487 : xPrSet = new SwXShape( xCreate );
368 9392 : xRet = uno::Reference< drawing::XShape >(xPrSet, uno::UNO_QUERY);
369 4696 : }
370 : }
371 6001 : return xRet;
372 : }
373 :
374 : namespace
375 : {
376 : class SwXShapesEnumeration
377 : : public SwSimpleEnumeration_Base
378 : {
379 : private:
380 : typedef ::std::list< ::com::sun::star::uno::Any > shapescontainer_t;
381 : shapescontainer_t m_aShapes;
382 : protected:
383 580 : virtual ~SwXShapesEnumeration() {};
384 : public:
385 : explicit SwXShapesEnumeration(SwXDrawPage* const pDrawPage);
386 :
387 : //XEnumeration
388 : virtual sal_Bool SAL_CALL hasMoreElements() throw(uno::RuntimeException, std::exception) SAL_OVERRIDE;
389 : virtual uno::Any SAL_CALL nextElement() throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE;
390 :
391 : //XServiceInfo
392 : virtual OUString SAL_CALL getImplementationName() throw(uno::RuntimeException, std::exception) SAL_OVERRIDE;
393 : virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw(uno::RuntimeException, std::exception) SAL_OVERRIDE;
394 : virtual uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() throw(uno::RuntimeException, std::exception) SAL_OVERRIDE;
395 : };
396 : }
397 :
398 290 : SwXShapesEnumeration::SwXShapesEnumeration(SwXDrawPage* const pDrawPage)
399 290 : : m_aShapes()
400 : {
401 290 : SolarMutexGuard aGuard;
402 290 : ::std::insert_iterator<shapescontainer_t> pInserter = ::std::insert_iterator<shapescontainer_t>(m_aShapes, m_aShapes.begin());
403 290 : sal_Int32 nCount = pDrawPage->getCount();
404 580 : std::set<const SwFrameFormat*> aTextBoxes = SwTextBoxHelper::findTextBoxes(pDrawPage->GetDoc());
405 686 : for(sal_Int32 nIdx = 0; nIdx < nCount; nIdx++)
406 : {
407 396 : uno::Reference<drawing::XShape> xShape = uno::Reference<drawing::XShape>(pDrawPage->getByIndex(nIdx, &aTextBoxes), uno::UNO_QUERY);
408 396 : *pInserter++ = uno::makeAny(xShape);
409 686 : }
410 290 : }
411 :
412 686 : sal_Bool SwXShapesEnumeration::hasMoreElements() throw(uno::RuntimeException, std::exception)
413 : {
414 686 : SolarMutexGuard aGuard;
415 686 : return !m_aShapes.empty();
416 : }
417 :
418 396 : uno::Any SwXShapesEnumeration::nextElement() throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
419 : {
420 396 : SolarMutexGuard aGuard;
421 396 : if(m_aShapes.empty())
422 0 : throw container::NoSuchElementException();
423 396 : uno::Any aResult = *m_aShapes.begin();
424 396 : m_aShapes.pop_front();
425 396 : return aResult;
426 : }
427 :
428 0 : OUString SwXShapesEnumeration::getImplementationName() throw(uno::RuntimeException, std::exception)
429 : {
430 0 : return OUString("SwXShapeEnumeration");
431 : }
432 :
433 0 : sal_Bool SwXShapesEnumeration::supportsService(const OUString& ServiceName) throw(uno::RuntimeException, std::exception)
434 : {
435 0 : return cppu::supportsService(this, ServiceName);
436 : }
437 :
438 0 : uno::Sequence< OUString > SwXShapesEnumeration::getSupportedServiceNames() throw(uno::RuntimeException, std::exception)
439 : {
440 0 : return ::comphelper::makeSequence(OUString("com.sun.star.container.XEnumeration"));
441 : }
442 :
443 290 : uno::Reference< container::XEnumeration > SwXDrawPage::createEnumeration() throw( uno::RuntimeException, std::exception )
444 : {
445 290 : SolarMutexGuard aGuard;
446 : return uno::Reference< container::XEnumeration >(
447 290 : new SwXShapesEnumeration(this));
448 : }
449 :
450 1 : OUString SwXDrawPage::getImplementationName() throw( uno::RuntimeException, std::exception )
451 : {
452 1 : return OUString("SwXDrawPage");
453 : }
454 :
455 65 : sal_Bool SwXDrawPage::supportsService(const OUString& rServiceName) throw( uno::RuntimeException, std::exception )
456 : {
457 65 : return cppu::supportsService(this, rServiceName);
458 : }
459 :
460 67 : uno::Sequence< OUString > SwXDrawPage::getSupportedServiceNames() throw( uno::RuntimeException, std::exception )
461 : {
462 67 : uno::Sequence< OUString > aRet(1);
463 67 : OUString* pArray = aRet.getArray();
464 67 : pArray[0] = "com.sun.star.drawing.GenericDrawPage";
465 67 : return aRet;
466 : }
467 :
468 2699 : SwXDrawPage::SwXDrawPage(SwDoc* pDc) :
469 : pDoc(pDc),
470 2699 : pDrawPage(0)
471 : {
472 2699 : }
473 :
474 8085 : SwXDrawPage::~SwXDrawPage()
475 : {
476 2695 : if(xPageAgg.is())
477 : {
478 2695 : uno::Reference< uno::XInterface > xInt;
479 2695 : xPageAgg->setDelegator(xInt);
480 : }
481 5390 : }
482 :
483 79843 : uno::Any SwXDrawPage::queryInterface( const uno::Type& aType )
484 : throw( uno::RuntimeException, std::exception )
485 : {
486 79843 : uno::Any aRet = SwXDrawPageBaseClass::queryInterface(aType);
487 79843 : if(!aRet.hasValue())
488 : {
489 : // secure with checking if page exists. This may not be the case
490 : // either for new SW docs with no yet graphics usage or when
491 : // the doc is closed and someone else still holds a UNO reference
492 : // to the XDrawPage (in that case, pDoc is set to 0)
493 13996 : SwFmDrawPage* pPage = GetSvxPage();
494 :
495 13996 : if(pPage)
496 : {
497 13996 : aRet = pPage->queryAggregation(aType);
498 : }
499 : }
500 79843 : return aRet;
501 : }
502 :
503 0 : uno::Sequence< uno::Type > SwXDrawPage::getTypes() throw( uno::RuntimeException, std::exception )
504 : {
505 0 : uno::Sequence< uno::Type > aPageTypes = SwXDrawPageBaseClass::getTypes();
506 0 : uno::Sequence< uno::Type > aSvxTypes = GetSvxPage()->getTypes();
507 :
508 0 : long nIndex = aPageTypes.getLength();
509 0 : aPageTypes.realloc(aPageTypes.getLength() + aSvxTypes.getLength() + 1);
510 :
511 0 : uno::Type* pPageTypes = aPageTypes.getArray();
512 0 : const uno::Type* pSvxTypes = aSvxTypes.getConstArray();
513 : long nPos;
514 0 : for(nPos = 0; nPos < aSvxTypes.getLength(); nPos++)
515 : {
516 0 : pPageTypes[nIndex++] = pSvxTypes[nPos];
517 : }
518 0 : pPageTypes[nIndex] = cppu::UnoType<form::XFormsSupplier2>::get();
519 0 : return aPageTypes;
520 : }
521 :
522 681 : sal_Int32 SwXDrawPage::getCount() throw( uno::RuntimeException, std::exception )
523 : {
524 681 : SolarMutexGuard aGuard;
525 681 : if(!pDoc)
526 0 : throw uno::RuntimeException();
527 681 : if(!pDoc->getIDocumentDrawModelAccess().GetDrawModel())
528 0 : return 0;
529 : else
530 : {
531 681 : static_cast<SwXDrawPage*>(this)->GetSvxPage();
532 :
533 681 : std::set<const SwFrameFormat*> aTextBoxes = SwTextBoxHelper::findTextBoxes(pDoc);
534 :
535 681 : if (aTextBoxes.empty())
536 613 : return pDrawPage->getCount();
537 : else
538 68 : return SwTextBoxHelper::getCount(pDrawPage->GetSdrPage(), aTextBoxes);
539 681 : }
540 : }
541 :
542 583 : uno::Any SwXDrawPage::getByIndex(sal_Int32 nIndex)
543 : throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException,
544 : uno::RuntimeException, std::exception )
545 : {
546 583 : return getByIndex(nIndex, 0);
547 : }
548 :
549 979 : uno::Any SwXDrawPage::getByIndex(sal_Int32 nIndex, std::set<const SwFrameFormat*>* pTextBoxes)
550 : throw(lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
551 : {
552 979 : SolarMutexGuard aGuard;
553 979 : if(!pDoc)
554 0 : throw uno::RuntimeException();
555 979 : if(!pDoc->getIDocumentDrawModelAccess().GetDrawModel())
556 0 : throw lang::IndexOutOfBoundsException();
557 :
558 979 : static_cast<SwXDrawPage*>(this)->GetSvxPage();
559 1958 : std::set<const SwFrameFormat*> aTextBoxes;
560 979 : if (!pTextBoxes)
561 : {
562 : // We got no set, so let's generate one.
563 583 : aTextBoxes = SwTextBoxHelper::findTextBoxes(pDoc);
564 583 : pTextBoxes = &aTextBoxes;
565 : }
566 979 : if (pTextBoxes->empty())
567 841 : return pDrawPage->getByIndex( nIndex );
568 : else
569 1117 : return SwTextBoxHelper::getByIndex(pDrawPage->GetSdrPage(), nIndex, *pTextBoxes);
570 : }
571 :
572 1 : uno::Type SwXDrawPage::getElementType() throw( uno::RuntimeException, std::exception )
573 : {
574 1 : return cppu::UnoType<drawing::XShape>::get();
575 : }
576 :
577 1 : sal_Bool SwXDrawPage::hasElements() throw( uno::RuntimeException, std::exception )
578 : {
579 1 : SolarMutexGuard aGuard;
580 1 : if(!pDoc)
581 0 : throw uno::RuntimeException();
582 1 : if(!pDoc->getIDocumentDrawModelAccess().GetDrawModel())
583 0 : return sal_False;
584 : else
585 1 : return static_cast<SwXDrawPage*>(this)->GetSvxPage()->hasElements();
586 : }
587 :
588 3414 : void SwXDrawPage::add(const uno::Reference< drawing::XShape > & xShape)
589 : throw( uno::RuntimeException, std::exception )
590 : {
591 3414 : SolarMutexGuard aGuard;
592 3414 : if(!pDoc)
593 0 : throw uno::RuntimeException();
594 6828 : uno::Reference< lang::XUnoTunnel > xShapeTunnel(xShape, uno::UNO_QUERY);
595 3414 : SwXShape* pShape = 0;
596 3414 : SvxShape* pSvxShape = 0;
597 3414 : if(xShapeTunnel.is())
598 : {
599 : pShape = reinterpret_cast< SwXShape * >(
600 3414 : sal::static_int_cast< sal_IntPtr >( xShapeTunnel->getSomething(SwXShape::getUnoTunnelId()) ));
601 : pSvxShape = reinterpret_cast< SvxShape * >(
602 3414 : sal::static_int_cast< sal_IntPtr >( xShapeTunnel->getSomething(SvxShape::getUnoTunnelId()) ));
603 : }
604 :
605 3414 : if(!pShape || pShape->GetRegisteredIn() || !pShape->m_bDescriptor )
606 : {
607 1333 : uno::RuntimeException aExcept;
608 1333 : if(pShape)
609 1333 : aExcept.Message = "object already inserted";
610 : else
611 0 : aExcept.Message = "illegal object";
612 1333 : throw aExcept;
613 : }
614 :
615 2081 : if ( pSvxShape->GetSdrObject() )
616 : {
617 266 : if ( pSvxShape->GetSdrObject()->IsInserted() )
618 : {
619 2081 : return;
620 : }
621 : }
622 2081 : GetSvxPage()->add(xShape);
623 :
624 4162 : uno::Reference< uno::XAggregation > xAgg = pShape->GetAggregationInterface();
625 :
626 : OSL_ENSURE(pSvxShape, "Why is here no SvxShape?");
627 : // this position is definitely in 1/100 mm
628 2081 : awt::Point aMM100Pos(pSvxShape->getPosition());
629 :
630 : // now evaluate the properties of SwShapeDescriptor_Impl
631 2081 : SwShapeDescriptor_Impl* pDesc = pShape->GetDescImpl();
632 :
633 2081 : SfxItemSet aSet( pDoc->GetAttrPool(), RES_FRMATR_BEGIN,
634 4162 : RES_FRMATR_END-1 );
635 4162 : SwFormatAnchor aAnchor( FLY_AS_CHAR );
636 2081 : bool bOpaque = false;
637 2081 : if( pDesc )
638 : {
639 2081 : if(pDesc->GetSurround())
640 0 : aSet.Put( *pDesc->GetSurround());
641 : // all items are already in Twip
642 2081 : if(pDesc->GetLRSpace())
643 : {
644 2 : aSet.Put(*pDesc->GetLRSpace());
645 : }
646 2081 : if(pDesc->GetULSpace())
647 : {
648 1 : aSet.Put(*pDesc->GetULSpace());
649 : }
650 2081 : if(pDesc->GetAnchor())
651 117 : aAnchor = *pDesc->GetAnchor();
652 :
653 : // #i32349# - if no horizontal position exists, create one
654 2081 : if ( !pDesc->GetHOrient() )
655 : {
656 2075 : SwFormatHoriOrient* pHori = pDesc->GetHOrient( true );
657 2075 : SwTwips nHoriPos = convertMm100ToTwip(aMM100Pos.X);
658 2075 : pHori->SetPos( nHoriPos );
659 : }
660 : {
661 2081 : if(pDesc->GetHOrient()->GetHoriOrient() == text::HoriOrientation::NONE)
662 2080 : aMM100Pos.X = convertTwipToMm100(pDesc->GetHOrient()->GetPos());
663 2081 : aSet.Put( *pDesc->GetHOrient() );
664 : }
665 : // #i32349# - if no vertical position exists, create one
666 2081 : if ( !pDesc->GetVOrient() )
667 : {
668 2039 : SwFormatVertOrient* pVert = pDesc->GetVOrient( true );
669 2039 : SwTwips nVertPos = convertMm100ToTwip(aMM100Pos.Y);
670 2039 : pVert->SetPos( nVertPos );
671 : }
672 : {
673 2081 : if(pDesc->GetVOrient()->GetVertOrient() == text::VertOrientation::NONE)
674 2044 : aMM100Pos.Y = convertTwipToMm100(pDesc->GetVOrient()->GetPos());
675 2081 : aSet.Put( *pDesc->GetVOrient() );
676 : }
677 :
678 2081 : if(pDesc->GetSurround())
679 0 : aSet.Put( *pDesc->GetSurround());
680 2081 : bOpaque = pDesc->IsOpaque();
681 :
682 : // #i26791#
683 2081 : if ( pDesc->GetFollowTextFlow() )
684 : {
685 2081 : aSet.Put( *pDesc->GetFollowTextFlow() );
686 : }
687 :
688 : // #i28701#
689 2081 : if ( pDesc->GetWrapInfluenceOnObjPos() )
690 : {
691 2081 : aSet.Put( *pDesc->GetWrapInfluenceOnObjPos() );
692 : }
693 : }
694 :
695 2081 : pSvxShape->setPosition(aMM100Pos);
696 2081 : SdrObject* pObj = pSvxShape->GetSdrObject();
697 : // #108784# - set layer of new drawing object to corresponding
698 : // invisible layer.
699 2081 : if(FmFormInventor != pObj->GetObjInventor())
700 1815 : pObj->SetLayer( bOpaque ? pDoc->getIDocumentDrawModelAccess().GetInvisibleHeavenId() : pDoc->getIDocumentDrawModelAccess().GetInvisibleHellId() );
701 : else
702 266 : pObj->SetLayer(pDoc->getIDocumentDrawModelAccess().GetInvisibleControlsId());
703 :
704 2081 : SwPaM* pPam = new SwPaM(pDoc->GetNodes().GetEndOfContent());
705 2081 : SwUnoInternalPaM* pInternalPam = 0;
706 4162 : uno::Reference< text::XTextRange > xRg;
707 2081 : if( pDesc && (xRg = pDesc->GetTextRange()).is() )
708 : {
709 150 : pInternalPam = new SwUnoInternalPaM(*pDoc);
710 150 : if (::sw::XTextRangeToSwPaM(*pInternalPam, xRg))
711 : {
712 159 : if(FLY_AT_FLY == aAnchor.GetAnchorId() &&
713 9 : !pInternalPam->GetNode().FindFlyStartNode())
714 : {
715 0 : aAnchor.SetType(FLY_AS_CHAR);
716 : }
717 150 : else if (FLY_AT_PAGE == aAnchor.GetAnchorId())
718 : {
719 23 : aAnchor.SetAnchor(pInternalPam->Start());
720 : }
721 : }
722 : else
723 0 : throw uno::RuntimeException();
724 : }
725 1931 : else if ((aAnchor.GetAnchorId() != FLY_AT_PAGE) && pDoc->getIDocumentLayoutAccess().GetCurrentLayout())
726 : {
727 220 : SwCrsrMoveState aState( MV_SETONLYTEXT );
728 220 : Point aTmp(convertMm100ToTwip(aMM100Pos.X), convertMm100ToTwip(aMM100Pos.Y));
729 220 : pDoc->getIDocumentLayoutAccess().GetCurrentLayout()->GetCrsrOfst( pPam->GetPoint(), aTmp, &aState );
730 220 : aAnchor.SetAnchor( pPam->GetPoint() );
731 :
732 : // #i32349# - adjustment of vertical positioning
733 : // attributes no longer needed, because its already got a default.
734 : }
735 : else
736 : {
737 1711 : aAnchor.SetType(FLY_AT_PAGE);
738 :
739 : // #i32349# - adjustment of vertical positioning
740 : // attributes no longer needed, because its already got a default.
741 : }
742 2081 : aSet.Put(aAnchor);
743 2081 : SwPaM* pTemp = pInternalPam;
744 2081 : if ( !pTemp )
745 1931 : pTemp = pPam;
746 4162 : UnoActionContext aAction(pDoc);
747 2081 : pDoc->getIDocumentContentOperations().InsertDrawObj( *pTemp, *pObj, aSet );
748 2081 : SwFrameFormat* pFormat = ::FindFrameFormat( pObj );
749 2081 : if(pFormat)
750 2081 : pFormat->Add(pShape);
751 2081 : pShape->m_bDescriptor = false;
752 :
753 2081 : delete pPam;
754 5495 : delete pInternalPam;
755 : }
756 :
757 153 : void SwXDrawPage::remove(const uno::Reference< drawing::XShape > & xShape) throw( uno::RuntimeException, std::exception )
758 : {
759 153 : SolarMutexGuard aGuard;
760 153 : if(!pDoc)
761 0 : throw uno::RuntimeException();
762 306 : uno::Reference<lang::XComponent> xComp(xShape, uno::UNO_QUERY);
763 306 : xComp->dispose();
764 153 : }
765 :
766 0 : uno::Reference< drawing::XShapeGroup > SwXDrawPage::group(const uno::Reference< drawing::XShapes > & xShapes)
767 : throw (uno::RuntimeException, std::exception)
768 : {
769 0 : SolarMutexGuard aGuard;
770 0 : if(!pDoc || !xShapes.is())
771 0 : throw uno::RuntimeException();
772 0 : uno::Reference< drawing::XShapeGroup > xRet;
773 0 : if(xPageAgg.is())
774 : {
775 :
776 0 : SwFmDrawPage* pPage = GetSvxPage();
777 0 : if(pPage) //TODO: can this be Null?
778 : {
779 : // mark and return MarkList
780 0 : const SdrMarkList& rMarkList = pPage->PreGroup(xShapes);
781 0 : if ( rMarkList.GetMarkCount() > 1 )
782 : {
783 0 : bool bFlyInCnt = false;
784 0 : for ( size_t i = 0; !bFlyInCnt && i < rMarkList.GetMarkCount(); ++i )
785 : {
786 0 : const SdrObject *pObj = rMarkList.GetMark( i )->GetMarkedSdrObj();
787 0 : if (FLY_AS_CHAR == ::FindFrameFormat(const_cast<SdrObject*>(
788 0 : pObj))->GetAnchor().GetAnchorId())
789 : {
790 0 : bFlyInCnt = true;
791 : }
792 : }
793 0 : if( bFlyInCnt )
794 0 : throw uno::RuntimeException();
795 0 : if( !bFlyInCnt )
796 : {
797 0 : UnoActionContext aContext(pDoc);
798 0 : pDoc->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
799 :
800 0 : SwDrawContact* pContact = pDoc->GroupSelection( *pPage->GetDrawView() );
801 : pDoc->ChgAnchor(
802 0 : pPage->GetDrawView()->GetMarkedObjectList(),
803 : FLY_AT_PARA,
804 0 : true, false );
805 :
806 0 : pPage->GetDrawView()->UnmarkAll();
807 0 : if(pContact)
808 : {
809 0 : uno::Reference< uno::XInterface > xInt = SwFmDrawPage::GetInterface( pContact->GetMaster() );
810 0 : xRet = uno::Reference< drawing::XShapeGroup >(xInt, uno::UNO_QUERY);
811 : }
812 0 : pDoc->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
813 : }
814 : }
815 0 : pPage->RemovePageView();
816 : }
817 : }
818 0 : return xRet;
819 : }
820 :
821 0 : void SwXDrawPage::ungroup(const uno::Reference< drawing::XShapeGroup > & rShapeGroup) throw( uno::RuntimeException, std::exception )
822 : {
823 0 : SolarMutexGuard aGuard;
824 0 : if(!pDoc)
825 0 : throw uno::RuntimeException();
826 0 : if(xPageAgg.is())
827 : {
828 0 : SwFmDrawPage* pPage = GetSvxPage();
829 0 : if(pPage) //TODO: can this be Null?
830 : {
831 0 : pPage->PreUnGroup(rShapeGroup);
832 0 : UnoActionContext aContext(pDoc);
833 0 : pDoc->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
834 :
835 0 : pDoc->UnGroupSelection( *pPage->GetDrawView() );
836 0 : pDoc->ChgAnchor( pPage->GetDrawView()->GetMarkedObjectList(),
837 : FLY_AT_PARA,
838 0 : true, false );
839 0 : pDoc->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
840 0 : pPage->RemovePageView();
841 : }
842 0 : }
843 0 : }
844 :
845 17738 : SwFmDrawPage* SwXDrawPage::GetSvxPage()
846 : {
847 17738 : if(!xPageAgg.is() && pDoc)
848 : {
849 2699 : SolarMutexGuard aGuard;
850 : // #i52858#
851 2699 : SwDrawModel* pModel = pDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel();
852 2699 : SdrPage* pPage = pModel->GetPage( 0 );
853 :
854 : {
855 : // We need a Ref to the object during queryInterface or else
856 : // it will be deleted
857 2699 : pDrawPage = new SwFmDrawPage(pPage);
858 2699 : uno::Reference< drawing::XDrawPage > xPage = pDrawPage;
859 5398 : uno::Any aAgg = xPage->queryInterface(cppu::UnoType<uno::XAggregation>::get());
860 2699 : if(aAgg.getValueType() == cppu::UnoType<uno::XAggregation>::get())
861 5398 : xPageAgg = *static_cast<uno::Reference< uno::XAggregation > const *>(aAgg.getValue());
862 : }
863 2699 : if( xPageAgg.is() )
864 2699 : xPageAgg->setDelegator( static_cast<cppu::OWeakObject*>(this) );
865 : }
866 17738 : return pDrawPage;
867 : }
868 :
869 : /**
870 : * Renamed and outlined to detect where it's called
871 : */
872 2695 : void SwXDrawPage::InvalidateSwDoc()
873 : {
874 2695 : pDoc = 0;
875 2695 : }
876 :
877 290 : SwDoc* SwXDrawPage::GetDoc()
878 : {
879 290 : return pDoc;
880 : }
881 :
882 0 : TYPEINIT1(SwXShape, SwClient);
883 :
884 : namespace
885 : {
886 : class theSwXShapeUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXShapeUnoTunnelId > {};
887 : }
888 :
889 124993 : const uno::Sequence< sal_Int8 > & SwXShape::getUnoTunnelId()
890 : {
891 124993 : return theSwXShapeUnoTunnelId::get().getSeq();
892 : }
893 :
894 113120 : sal_Int64 SAL_CALL SwXShape::getSomething( const uno::Sequence< sal_Int8 >& rId )
895 : throw(uno::RuntimeException, std::exception)
896 : {
897 226240 : if( rId.getLength() == 16
898 339360 : && 0 == memcmp( getUnoTunnelId().getConstArray(),
899 226240 : rId.getConstArray(), 16 ) )
900 : {
901 7169 : return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
902 : }
903 :
904 105951 : if( xShapeAgg.is() )
905 : {
906 105951 : const uno::Type& rTunnelType = cppu::UnoType<lang::XUnoTunnel>::get();
907 105951 : uno::Any aAgg = xShapeAgg->queryAggregation( rTunnelType );
908 105951 : if(aAgg.getValueType() == rTunnelType)
909 : {
910 : uno::Reference<lang::XUnoTunnel> xAggTunnel =
911 105951 : *static_cast<uno::Reference<lang::XUnoTunnel> const *>(aAgg.getValue());
912 105951 : if(xAggTunnel.is())
913 105951 : return xAggTunnel->getSomething(rId);
914 0 : }
915 : }
916 0 : return 0;
917 : }
918 : namespace
919 : {
920 6626 : static void lcl_addShapePropertyEventFactories( SdrObject& _rObj, SwXShape& _rShape )
921 : {
922 6626 : svx::PPropertyValueProvider pProvider( new svx::PropertyValueProvider( _rShape, "AnchorType" ) );
923 6626 : _rObj.getShapePropertyChangeNotifier().registerProvider( svx::eTextShapeAnchorType, pProvider );
924 6626 : }
925 : }
926 :
927 8410 : SwXShape::SwXShape(uno::Reference< uno::XInterface > & xShape) :
928 8410 : m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_SHAPE)),
929 8410 : m_pPropertyMapEntries(aSwMapProvider.GetPropertyMapEntries(PROPERTY_MAP_TEXT_SHAPE)),
930 0 : pImpl(new SwShapeDescriptor_Impl()),
931 25230 : m_bDescriptor(true)
932 : {
933 8410 : if(xShape.is()) // default Ctor
934 : {
935 8410 : const uno::Type& rAggType = cppu::UnoType<uno::XAggregation>::get();
936 : //aAgg contains a reference of the SvxShape!
937 : {
938 8410 : uno::Any aAgg = xShape->queryInterface(rAggType);
939 8410 : if(aAgg.getValueType() == rAggType)
940 8410 : xShapeAgg = *static_cast<uno::Reference< uno::XAggregation > const *>(aAgg.getValue());
941 : // #i31698#
942 8410 : if ( xShapeAgg.is() )
943 : {
944 8410 : xShapeAgg->queryAggregation( cppu::UnoType<drawing::XShape>::get()) >>= mxShape;
945 : OSL_ENSURE( mxShape.is(),
946 : "<SwXShape::SwXShape(..)> - no XShape found at <xShapeAgg>" );
947 8410 : }
948 : }
949 8410 : xShape = 0;
950 8410 : m_refCount++;
951 8410 : if( xShapeAgg.is() )
952 8410 : xShapeAgg->setDelegator( static_cast<cppu::OWeakObject*>(this) );
953 8410 : m_refCount--;
954 :
955 8410 : uno::Reference< lang::XUnoTunnel > xShapeTunnel(xShapeAgg, uno::UNO_QUERY);
956 8410 : SvxShape* pShape = 0;
957 8410 : if(xShapeTunnel.is())
958 : pShape = reinterpret_cast< SvxShape * >(
959 8410 : sal::static_int_cast< sal_IntPtr >( xShapeTunnel->getSomething(SvxShape::getUnoTunnelId()) ));
960 :
961 8410 : SdrObject* pObj = pShape ? pShape->GetSdrObject() : 0;
962 8410 : if(pObj)
963 : {
964 4969 : SwFrameFormat* pFormat = ::FindFrameFormat( pObj );
965 4969 : if(pFormat)
966 2726 : pFormat->Add(this);
967 :
968 4969 : lcl_addShapePropertyEventFactories( *pObj, *this );
969 4969 : pImpl->bInitializedPropertyNotifier = true;
970 8410 : }
971 : }
972 8410 : }
973 :
974 2444 : void SwXShape::AddExistingShapeToFormat( SdrObject& _rObj )
975 : {
976 2444 : SdrObjListIter aIter( _rObj, IM_DEEPNOGROUPS );
977 7744 : while ( aIter.IsMore() )
978 : {
979 2856 : SdrObject* pCurrent = aIter.Next();
980 : OSL_ENSURE( pCurrent, "SwXShape::AddExistingShapeToFormat: invalid object list element!" );
981 2856 : if ( !pCurrent )
982 0 : continue;
983 :
984 2856 : SwXShape* pSwShape = NULL;
985 2856 : uno::Reference< lang::XUnoTunnel > xShapeTunnel( pCurrent->getWeakUnoShape(), uno::UNO_QUERY );
986 2856 : if ( xShapeTunnel.is() )
987 : pSwShape = reinterpret_cast< SwXShape * >(
988 2128 : sal::static_int_cast< sal_IntPtr >( xShapeTunnel->getSomething( SwXShape::getUnoTunnelId() ) ) );
989 2856 : if ( pSwShape )
990 : {
991 2128 : if ( pSwShape->m_bDescriptor )
992 : {
993 2128 : SwFrameFormat* pFormat = ::FindFrameFormat( pCurrent );
994 2128 : if ( pFormat )
995 2128 : pFormat->Add( pSwShape );
996 2128 : pSwShape->m_bDescriptor = false;
997 : }
998 :
999 2128 : if ( !pSwShape->pImpl->bInitializedPropertyNotifier )
1000 : {
1001 1657 : lcl_addShapePropertyEventFactories( *pCurrent, *pSwShape );
1002 1657 : pSwShape->pImpl->bInitializedPropertyNotifier = true;
1003 : }
1004 : }
1005 5300 : }
1006 2444 : }
1007 :
1008 24736 : SwXShape::~SwXShape()
1009 : {
1010 8410 : if (xShapeAgg.is())
1011 : {
1012 8410 : uno::Reference< uno::XInterface > xRef;
1013 8410 : xShapeAgg->setDelegator(xRef);
1014 : }
1015 8410 : delete pImpl;
1016 16326 : }
1017 :
1018 457616 : uno::Any SwXShape::queryInterface( const uno::Type& aType ) throw( uno::RuntimeException, std::exception )
1019 : {
1020 457616 : uno::Any aRet = SwTextBoxHelper::queryInterface(GetFrameFormat(), aType);
1021 457616 : if (aRet.hasValue())
1022 1546 : return aRet;
1023 :
1024 456070 : aRet = SwXShapeBaseClass::queryInterface(aType);
1025 : // #i53320# - follow-up of #i31698#
1026 : // interface drawing::XShape is overloaded. Thus, provide
1027 : // correct object instance.
1028 456070 : if(!aRet.hasValue() && xShapeAgg.is())
1029 : {
1030 43077 : if(aType == cppu::UnoType<XShape>::get())
1031 0 : aRet <<= uno::Reference<XShape>(this);
1032 : else
1033 43077 : aRet = xShapeAgg->queryAggregation(aType);
1034 : }
1035 456070 : return aRet;
1036 : }
1037 :
1038 0 : uno::Sequence< uno::Type > SwXShape::getTypes( ) throw(uno::RuntimeException, std::exception)
1039 : {
1040 0 : uno::Sequence< uno::Type > aRet = SwXShapeBaseClass::getTypes();
1041 0 : if(xShapeAgg.is())
1042 : {
1043 0 : uno::Any aProv = xShapeAgg->queryAggregation(cppu::UnoType<XTypeProvider>::get());
1044 0 : if(aProv.hasValue())
1045 : {
1046 0 : uno::Reference< XTypeProvider > xAggProv;
1047 0 : aProv >>= xAggProv;
1048 0 : uno::Sequence< uno::Type > aAggTypes = xAggProv->getTypes();
1049 0 : const uno::Type* pAggTypes = aAggTypes.getConstArray();
1050 0 : long nIndex = aRet.getLength();
1051 :
1052 0 : aRet.realloc(nIndex + aAggTypes.getLength());
1053 0 : uno::Type* pBaseTypes = aRet.getArray();
1054 :
1055 0 : for(long i = 0; i < aAggTypes.getLength(); i++)
1056 0 : pBaseTypes[nIndex++] = pAggTypes[i];
1057 0 : }
1058 : }
1059 0 : return aRet;
1060 : }
1061 :
1062 0 : uno::Sequence< sal_Int8 > SwXShape::getImplementationId( ) throw(uno::RuntimeException, std::exception)
1063 : {
1064 0 : return css::uno::Sequence<sal_Int8>();
1065 : }
1066 :
1067 36589 : uno::Reference< beans::XPropertySetInfo > SwXShape::getPropertySetInfo() throw( uno::RuntimeException, std::exception )
1068 : {
1069 36589 : SolarMutexGuard aGuard;
1070 36589 : uno::Reference< beans::XPropertySetInfo > aRet;
1071 36589 : if(xShapeAgg.is())
1072 : {
1073 36589 : const uno::Type& rPropSetType = cppu::UnoType<beans::XPropertySet>::get();
1074 36589 : uno::Any aPSet = xShapeAgg->queryAggregation( rPropSetType );
1075 36589 : if(aPSet.getValueType() == rPropSetType && aPSet.getValue())
1076 : {
1077 : uno::Reference< beans::XPropertySet > xPrSet =
1078 36589 : *static_cast<uno::Reference< beans::XPropertySet > const *>(aPSet.getValue());
1079 73178 : uno::Reference< beans::XPropertySetInfo > xInfo = xPrSet->getPropertySetInfo();
1080 : // Expand PropertySetInfo!
1081 73178 : const uno::Sequence<beans::Property> aPropSeq = xInfo->getProperties();
1082 73178 : aRet = new SfxExtItemPropertySetInfo( m_pPropertyMapEntries, aPropSeq );
1083 36589 : }
1084 : }
1085 36589 : if(!aRet.is())
1086 0 : aRet = m_pPropSet->getPropertySetInfo();
1087 36589 : return aRet;
1088 : }
1089 :
1090 87906 : void SwXShape::setPropertyValue(const OUString& rPropertyName, const uno::Any& aValue)
1091 : throw( beans::UnknownPropertyException, beans::PropertyVetoException,
1092 : lang::IllegalArgumentException, lang::WrappedTargetException,
1093 : uno::RuntimeException, std::exception)
1094 : {
1095 87906 : SolarMutexGuard aGuard;
1096 87906 : SwFrameFormat* pFormat = GetFrameFormat();
1097 87906 : const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName );
1098 87906 : if(xShapeAgg.is())
1099 : {
1100 87906 : if(pEntry)
1101 : {
1102 26895 : if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
1103 0 : throw beans::PropertyVetoException ("Property is read-only: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
1104 : // with the layout it is possible to move the anchor without changing the position
1105 26895 : if(pFormat)
1106 : {
1107 26213 : SwAttrSet aSet(pFormat->GetAttrSet());
1108 26213 : SwDoc* pDoc = pFormat->GetDoc();
1109 26213 : if(RES_ANCHOR == pEntry->nWID && MID_ANCHOR_ANCHORFRAME == pEntry->nMemberId)
1110 : {
1111 0 : bool bDone = false;
1112 0 : uno::Reference<text::XTextFrame> xFrame;
1113 0 : if(aValue >>= xFrame)
1114 : {
1115 0 : uno::Reference<lang::XUnoTunnel> xTunnel(xFrame, uno::UNO_QUERY);
1116 0 : SwXFrame* pFrame = xTunnel.is() ?
1117 : reinterpret_cast< SwXFrame * >(
1118 0 : sal::static_int_cast< sal_IntPtr >( xTunnel->getSomething(SwXFrame::getUnoTunnelId()) ))
1119 0 : : 0;
1120 0 : if(pFrame && pFrame->GetFrameFormat() &&
1121 0 : pFrame->GetFrameFormat()->GetDoc() == pDoc)
1122 : {
1123 0 : UnoActionContext aCtx(pDoc);
1124 0 : SfxItemSet aItemSet( pDoc->GetAttrPool(),
1125 0 : RES_FRMATR_BEGIN, RES_FRMATR_END - 1 );
1126 0 : aItemSet.SetParent(&pFormat->GetAttrSet());
1127 0 : SwFormatAnchor aAnchor = static_cast<const SwFormatAnchor&>(aItemSet.Get(pEntry->nWID));
1128 0 : SwPosition aPos(*pFrame->GetFrameFormat()->GetContent().GetContentIdx());
1129 0 : aAnchor.SetAnchor(&aPos);
1130 0 : aAnchor.SetType(FLY_AT_FLY);
1131 0 : aItemSet.Put(aAnchor);
1132 0 : pFormat->SetFormatAttr(aItemSet);
1133 0 : bDone = true;
1134 0 : }
1135 : }
1136 0 : if(!bDone)
1137 0 : throw lang::IllegalArgumentException();
1138 : }
1139 26213 : else if(RES_OPAQUE == pEntry->nWID)
1140 : {
1141 3194 : SvxShape* pSvxShape = GetSvxShape();
1142 : SAL_WARN_IF(!pSvxShape, "sw.uno", "No SvxShape found!");
1143 3194 : if(pSvxShape)
1144 : {
1145 3194 : SdrObject* pObj = pSvxShape->GetSdrObject();
1146 : // set layer of new drawing
1147 : // object to corresponding invisible layer.
1148 3194 : bool bIsVisible = pDoc->getIDocumentDrawModelAccess().IsVisibleLayerId( pObj->GetLayer() );
1149 3194 : if(FmFormInventor != pObj->GetObjInventor())
1150 : {
1151 3194 : pObj->SetLayer( *static_cast<sal_Bool const *>(aValue.getValue())
1152 2875 : ? ( bIsVisible ? pDoc->getIDocumentDrawModelAccess().GetHeavenId() : pDoc->getIDocumentDrawModelAccess().GetInvisibleHeavenId() )
1153 9263 : : ( bIsVisible ? pDoc->getIDocumentDrawModelAccess().GetHellId() : pDoc->getIDocumentDrawModelAccess().GetInvisibleHellId() ));
1154 : }
1155 : else
1156 : {
1157 0 : pObj->SetLayer( bIsVisible ? pDoc->getIDocumentDrawModelAccess().GetControlsId() : pDoc->getIDocumentDrawModelAccess().GetInvisibleControlsId());
1158 : }
1159 :
1160 : }
1161 :
1162 : }
1163 : // #i26791# - special handling for property FN_TEXT_RANGE
1164 23019 : else if ( FN_TEXT_RANGE == pEntry->nWID )
1165 : {
1166 3301 : SwFormatAnchor aAnchor( static_cast<const SwFormatAnchor&>(aSet.Get( RES_ANCHOR )) );
1167 3301 : if (aAnchor.GetAnchorId() == FLY_AT_PAGE)
1168 : {
1169 : // set property <TextRange> not valid for to-page anchored shapes
1170 1046 : throw lang::IllegalArgumentException();
1171 : }
1172 : else
1173 : {
1174 : SwUnoInternalPaM* pInternalPam =
1175 2255 : new SwUnoInternalPaM( *(pFormat->GetDoc()) );
1176 2255 : uno::Reference< text::XTextRange > xRg;
1177 2255 : aValue >>= xRg;
1178 2255 : if (::sw::XTextRangeToSwPaM(*pInternalPam, xRg) )
1179 : {
1180 2255 : if (aAnchor.GetAnchorId() == FLY_AS_CHAR)
1181 : {
1182 : //delete old SwFormatFlyCnt
1183 : //With AnchorAsCharacter the current TextAttribute has to be deleted.
1184 : //Tbis removes the frame format too.
1185 : //To prevent this the connection between format and attribute has to be broken before.
1186 1271 : const SwPosition *pPos = aAnchor.GetContentAnchor();
1187 1271 : SwTextNode *pTextNode = pPos->nNode.GetNode().GetTextNode();
1188 : SAL_WARN_IF( !pTextNode->HasHints(), "sw.uno", "Missing FlyInCnt-Hint." );
1189 1271 : const sal_Int32 nIdx = pPos->nContent.GetIndex();
1190 : SwTextAttr * const pHint =
1191 : pTextNode->GetTextAttrForCharAt(
1192 1271 : nIdx, RES_TXTATR_FLYCNT );
1193 : SAL_WARN_IF( !pHint || pHint->Which() != RES_TXTATR_FLYCNT,
1194 : "sw.uno", "Missing FlyInCnt-Hint." );
1195 : SAL_WARN_IF( !pHint || pHint->GetFlyCnt().GetFrameFormat() != pFormat,
1196 : "sw.uno", "Wrong TextFlyCnt-Hint." );
1197 1271 : const_cast<SwFormatFlyCnt&>(pHint->GetFlyCnt())
1198 1271 : .SetFlyFormat();
1199 :
1200 : //The connection is removed now the attribute can be deleted.
1201 1271 : pTextNode->DeleteAttributes( RES_TXTATR_FLYCNT, nIdx );
1202 : //create a new one
1203 1271 : SwTextNode *pNd = pInternalPam->GetNode().GetTextNode();
1204 : SAL_WARN_IF( !pNd, "sw.uno", "Cursor not at TextNode." );
1205 1271 : SwFormatFlyCnt aFormat( pFormat );
1206 1271 : pNd->InsertItem(aFormat, pInternalPam->GetPoint()
1207 1271 : ->nContent.GetIndex(), 0 );
1208 : }
1209 : else
1210 : {
1211 984 : aAnchor.SetAnchor( pInternalPam->GetPoint() );
1212 984 : aSet.Put(aAnchor);
1213 984 : pFormat->SetFormatAttr(aSet);
1214 : }
1215 : }
1216 : else
1217 : {
1218 0 : throw uno::RuntimeException();
1219 : }
1220 2255 : delete pInternalPam;
1221 3301 : }
1222 : }
1223 19718 : else if (pEntry->nWID == FN_TEXT_BOX)
1224 : {
1225 702 : bool bValue(false);
1226 702 : aValue >>= bValue;
1227 702 : if (bValue)
1228 452 : SwTextBoxHelper::create(pFormat);
1229 : else
1230 250 : SwTextBoxHelper::destroy(pFormat);
1231 :
1232 : }
1233 19016 : else if (pEntry->nWID == RES_CHAIN)
1234 : {
1235 6 : if (pEntry->nMemberId == MID_CHAIN_NEXTNAME || pEntry->nMemberId == MID_CHAIN_PREVNAME)
1236 6 : SwTextBoxHelper::syncProperty(pFormat, pEntry->nWID, pEntry->nMemberId, aValue);
1237 : }
1238 : // #i28749#
1239 19010 : else if ( FN_SHAPE_POSITION_LAYOUT_DIR == pEntry->nWID )
1240 : {
1241 3 : sal_Int16 nPositionLayoutDir = 0;
1242 3 : aValue >>= nPositionLayoutDir;
1243 3 : pFormat->SetPositionLayoutDir( nPositionLayoutDir );
1244 : }
1245 19007 : else if( pDoc->getIDocumentLayoutAccess().GetCurrentLayout())
1246 : {
1247 37 : UnoActionContext aCtx(pDoc);
1248 37 : if(RES_ANCHOR == pEntry->nWID && MID_ANCHOR_ANCHORTYPE == pEntry->nMemberId)
1249 : {
1250 0 : SdrObject* pObj = pFormat->FindSdrObject();
1251 0 : SdrMarkList aList;
1252 0 : SdrMark aMark(pObj);
1253 0 : aList.InsertEntry(aMark);
1254 0 : sal_Int32 nAnchor = 0;
1255 0 : cppu::enum2int( nAnchor, aValue );
1256 : pDoc->ChgAnchor( aList, (RndStdIds)nAnchor,
1257 0 : false, true );
1258 : }
1259 : else
1260 : {
1261 37 : m_pPropSet->setPropertyValue(*pEntry, aValue, aSet);
1262 37 : pFormat->SetFormatAttr(aSet);
1263 37 : }
1264 : }
1265 19896 : else if( RES_FRM_SIZE == pEntry->nWID &&
1266 1791 : ( pEntry->nMemberId == MID_FRMSIZE_REL_HEIGHT || pEntry->nMemberId == MID_FRMSIZE_REL_WIDTH
1267 800 : || pEntry->nMemberId == MID_FRMSIZE_REL_HEIGHT_RELATION
1268 401 : || pEntry->nMemberId == MID_FRMSIZE_REL_WIDTH_RELATION ) )
1269 : {
1270 926 : SvxShape* pSvxShape = GetSvxShape();
1271 : SAL_WARN_IF(!pSvxShape, "sw.uno", "No SvxShape found!");
1272 926 : if(pSvxShape)
1273 : {
1274 926 : SdrObject* pObj = pSvxShape->GetSdrObject();
1275 926 : sal_Int16 nPercent(100);
1276 926 : aValue >>= nPercent;
1277 926 : switch (pEntry->nMemberId)
1278 : {
1279 : case MID_FRMSIZE_REL_WIDTH:
1280 65 : pObj->SetRelativeWidth( nPercent / 100.0 );
1281 65 : break;
1282 : case MID_FRMSIZE_REL_HEIGHT:
1283 61 : pObj->SetRelativeHeight( nPercent / 100.0 );
1284 61 : break;
1285 : case MID_FRMSIZE_REL_WIDTH_RELATION:
1286 401 : pObj->SetRelativeWidthRelation(nPercent);
1287 401 : break;
1288 : case MID_FRMSIZE_REL_HEIGHT_RELATION:
1289 399 : pObj->SetRelativeHeightRelation(nPercent);
1290 399 : break;
1291 : }
1292 926 : }
1293 : }
1294 : else
1295 : {
1296 18044 : m_pPropSet->setPropertyValue( *pEntry, aValue, aSet );
1297 :
1298 18044 : if(RES_ANCHOR == pEntry->nWID && MID_ANCHOR_ANCHORTYPE == pEntry->nMemberId)
1299 : {
1300 2818 : bool bSetAttr = true;
1301 2818 : sal_Int32 eNewAnchor = SWUnoHelper::GetEnumAsInt32( aValue );
1302 :
1303 : //if old anchor was in_cntnt the related text attribute has to be removed
1304 2818 : const SwFormatAnchor& rOldAnchor = pFormat->GetAnchor();
1305 2818 : RndStdIds eOldAnchorId = rOldAnchor.GetAnchorId();
1306 2818 : SdrObject* pObj = pFormat->FindSdrObject();
1307 2818 : SwFrameFormat *pFlyFormat = FindFrameFormat( pObj );
1308 2818 : pFlyFormat->DelFrms();
1309 2818 : if( text::TextContentAnchorType_AS_CHARACTER != eNewAnchor &&
1310 : (FLY_AS_CHAR == eOldAnchorId))
1311 : {
1312 : //With AnchorAsCharacter the current TextAttribute has to be deleted.
1313 : //Tbis removes the frame format too.
1314 : //To prevent this the connection between format and attribute has to be broken before.
1315 867 : const SwPosition *pPos = rOldAnchor.GetContentAnchor();
1316 867 : SwTextNode *pTextNode = pPos->nNode.GetNode().GetTextNode();
1317 : SAL_WARN_IF( !pTextNode->HasHints(), "sw.uno", "Missing FlyInCnt-Hint." );
1318 867 : const sal_Int32 nIdx = pPos->nContent.GetIndex();
1319 : SwTextAttr * const pHint =
1320 : pTextNode->GetTextAttrForCharAt(
1321 867 : nIdx, RES_TXTATR_FLYCNT );
1322 : SAL_WARN_IF( !pHint || pHint->Which() != RES_TXTATR_FLYCNT,
1323 : "sw.uno", "Missing FlyInCnt-Hint." );
1324 : SAL_WARN_IF( !pHint || pHint->GetFlyCnt().GetFrameFormat() != pFlyFormat,
1325 : "sw.uno", "Wrong TextFlyCnt-Hint." );
1326 867 : const_cast<SwFormatFlyCnt&>(pHint->GetFlyCnt())
1327 867 : .SetFlyFormat();
1328 :
1329 : //The connection is removed now the attribute can be deleted.
1330 867 : pTextNode->DeleteAttributes(RES_TXTATR_FLYCNT, nIdx);
1331 : }
1332 1951 : else if( text::TextContentAnchorType_AT_PAGE != eNewAnchor &&
1333 : (FLY_AT_PAGE == eOldAnchorId))
1334 : {
1335 1345 : SwFormatAnchor aNewAnchor( dynamic_cast< const SwFormatAnchor& >( aSet.Get( RES_ANCHOR ) ) );
1336 : //if the fly has been anchored at page then it needs to be connected
1337 : //to the content position
1338 2690 : SwPaM aPam(pDoc->GetNodes().GetEndOfContent());
1339 1345 : if( pDoc->getIDocumentLayoutAccess().GetCurrentLayout() )
1340 : {
1341 0 : SwCrsrMoveState aState( MV_SETONLYTEXT );
1342 0 : Point aTmp( pObj->GetSnapRect().TopLeft() );
1343 0 : pDoc->getIDocumentLayoutAccess().GetCurrentLayout()->GetCrsrOfst( aPam.GetPoint(), aTmp, &aState );
1344 : }
1345 : else
1346 : {
1347 : //without access to the layout the last node of the body will be used as anchor position
1348 1345 : aPam.Move( fnMoveBackward, fnGoDoc );
1349 : }
1350 : //anchor position has to be inserted after the text attribute has been inserted
1351 1345 : aNewAnchor.SetAnchor( aPam.GetPoint() );
1352 1345 : aSet.Put( aNewAnchor );
1353 1345 : pFormat->SetFormatAttr(aSet);
1354 2690 : bSetAttr = false;
1355 : }
1356 2818 : if( text::TextContentAnchorType_AS_CHARACTER == eNewAnchor &&
1357 : (FLY_AS_CHAR != eOldAnchorId))
1358 : {
1359 1201 : SwPaM aPam(pDoc->GetNodes().GetEndOfContent());
1360 1201 : if( pDoc->getIDocumentLayoutAccess().GetCurrentLayout() )
1361 : {
1362 0 : SwCrsrMoveState aState( MV_SETONLYTEXT );
1363 0 : Point aTmp( pObj->GetSnapRect().TopLeft() );
1364 0 : pDoc->getIDocumentLayoutAccess().GetCurrentLayout()->GetCrsrOfst( aPam.GetPoint(), aTmp, &aState );
1365 : }
1366 : else
1367 : {
1368 : //without access to the layout the last node of the body will be used as anchor position
1369 1201 : aPam.Move( fnMoveBackward, fnGoDoc );
1370 : }
1371 : //the RES_TXTATR_FLYCNT needs to be added now
1372 1201 : SwTextNode *pNd = aPam.GetNode().GetTextNode();
1373 : SAL_WARN_IF( !pNd, "sw.uno", "Crsr is not in a TextNode." );
1374 2402 : SwFormatFlyCnt aFormat( pFlyFormat );
1375 : pNd->InsertItem(aFormat,
1376 1201 : aPam.GetPoint()->nContent.GetIndex(), 0 );
1377 1201 : --aPam.GetPoint()->nContent; // InsertItem moved it
1378 : SwFormatAnchor aNewAnchor(
1379 : dynamic_cast<const SwFormatAnchor&>(
1380 2402 : aSet.Get(RES_ANCHOR)));
1381 1201 : aNewAnchor.SetAnchor( aPam.GetPoint() );
1382 2402 : aSet.Put( aNewAnchor );
1383 : }
1384 2818 : if( bSetAttr )
1385 1473 : pFormat->SetFormatAttr(aSet);
1386 : }
1387 : else
1388 15226 : pFormat->SetFormatAttr(aSet);
1389 : }
1390 : // We have a pFormat and a pEntry as well: try to sync TextBox property.
1391 26213 : SwTextBoxHelper::syncProperty(pFormat, pEntry->nWID, pEntry->nMemberId, aValue);
1392 : }
1393 : else
1394 : {
1395 682 : SfxPoolItem* pItem = 0;
1396 682 : switch(pEntry->nWID)
1397 : {
1398 : case RES_ANCHOR:
1399 208 : pItem = pImpl->GetAnchor(true);
1400 208 : break;
1401 : case RES_HORI_ORIENT:
1402 7 : pItem = pImpl->GetHOrient(true);
1403 7 : break;
1404 : case RES_VERT_ORIENT:
1405 48 : pItem = pImpl->GetVOrient(true);
1406 48 : break;
1407 : case RES_LR_SPACE:
1408 4 : pItem = pImpl->GetLRSpace(true);
1409 4 : break;
1410 : case RES_UL_SPACE:
1411 2 : pItem = pImpl->GetULSpace(true);
1412 2 : break;
1413 : case RES_SURROUND:
1414 0 : pItem = pImpl->GetSurround(true);
1415 0 : break;
1416 : case FN_TEXT_RANGE:
1417 : {
1418 : const uno::Type rTextRangeType =
1419 327 : cppu::UnoType<text::XTextRange>::get();
1420 327 : if(aValue.getValueType() == rTextRangeType)
1421 : {
1422 327 : uno::Reference< text::XTextRange > & rRange = pImpl->GetTextRange();
1423 327 : rRange = *static_cast<uno::Reference< text::XTextRange > const *>(aValue.getValue());
1424 327 : }
1425 : }
1426 327 : break;
1427 : case RES_OPAQUE :
1428 86 : pImpl->SetOpaque(*static_cast<sal_Bool const *>(aValue.getValue()));
1429 86 : break;
1430 : // #i26791#
1431 : case RES_FOLLOW_TEXT_FLOW:
1432 : {
1433 0 : pItem = pImpl->GetFollowTextFlow( true );
1434 : }
1435 0 : break;
1436 : // #i28701#
1437 : case RES_WRAP_INFLUENCE_ON_OBJPOS:
1438 : {
1439 0 : pItem = pImpl->GetWrapInfluenceOnObjPos( true );
1440 : }
1441 0 : break;
1442 : // #i28749#
1443 : case FN_SHAPE_POSITION_LAYOUT_DIR :
1444 : {
1445 0 : sal_Int16 nPositionLayoutDir = 0;
1446 0 : aValue >>= nPositionLayoutDir;
1447 0 : pImpl->SetPositionLayoutDir( nPositionLayoutDir );
1448 : }
1449 0 : break;
1450 : }
1451 682 : if(pItem)
1452 269 : static_cast<SfxPoolItem*>(pItem)->PutValue(aValue, pEntry->nMemberId);
1453 : }
1454 : }
1455 : else
1456 : {
1457 61011 : uno::Reference< beans::XPropertySet > xPrSet;
1458 : const uno::Type& rPSetType =
1459 61011 : cppu::UnoType<beans::XPropertySet>::get();
1460 122022 : uno::Any aPSet = xShapeAgg->queryAggregation(rPSetType);
1461 61011 : if(aPSet.getValueType() != rPSetType || !aPSet.getValue())
1462 0 : throw uno::RuntimeException();
1463 61011 : xPrSet = *static_cast<uno::Reference< beans::XPropertySet > const *>(aPSet.getValue());
1464 : // #i31698# - setting the caption point of a
1465 : // caption object doesn't have to change the object position.
1466 : // Thus, keep the position, before the caption point is set and
1467 : // restore it afterwards.
1468 61011 : awt::Point aKeepedPosition( 0, 0 );
1469 61011 : if ( rPropertyName == "CaptionPoint" && getShapeType() == "com.sun.star.drawing.CaptionShape" )
1470 : {
1471 0 : aKeepedPosition = getPosition();
1472 : }
1473 61011 : if( pFormat && pFormat->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell() )
1474 : {
1475 202 : UnoActionContext aCtx(pFormat->GetDoc());
1476 225 : xPrSet->setPropertyValue(rPropertyName, aValue);
1477 : }
1478 : else
1479 60809 : xPrSet->setPropertyValue(rPropertyName, aValue);
1480 :
1481 60984 : if (pFormat)
1482 : {
1483 : // We have a pFormat (but no pEntry): try to sync TextBox property.
1484 60252 : SwTextBoxHelper::syncProperty(pFormat, rPropertyName, aValue);
1485 : }
1486 :
1487 : // #i31698# - restore object position, if caption point is set.
1488 60972 : if ( rPropertyName == "CaptionPoint" && getShapeType() == "com.sun.star.drawing.CaptionShape" )
1489 : {
1490 0 : setPosition( aKeepedPosition );
1491 61011 : }
1492 : }
1493 87906 : }
1494 86821 : }
1495 :
1496 95764 : uno::Any SwXShape::getPropertyValue(const OUString& rPropertyName)
1497 : throw( beans::UnknownPropertyException, lang::WrappedTargetException,
1498 : uno::RuntimeException, std::exception )
1499 : {
1500 95764 : SolarMutexGuard aGuard;
1501 95764 : uno::Any aRet;
1502 95764 : SwFrameFormat* pFormat = GetFrameFormat();
1503 95764 : if(xShapeAgg.is())
1504 : {
1505 95764 : const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName );
1506 95764 : if(pEntry)
1507 : {
1508 43794 : if(pFormat)
1509 : {
1510 33439 : if(RES_OPAQUE == pEntry->nWID)
1511 : {
1512 37 : SvxShape* pSvxShape = GetSvxShape();
1513 : OSL_ENSURE(pSvxShape, "No SvxShape found!");
1514 37 : if(pSvxShape)
1515 : {
1516 37 : SdrObject* pObj = pSvxShape->GetSdrObject();
1517 : // consider invisible layers
1518 74 : aRet <<=
1519 62 : ( pObj->GetLayer() != pFormat->GetDoc()->getIDocumentDrawModelAccess().GetHellId() &&
1520 62 : pObj->GetLayer() != pFormat->GetDoc()->getIDocumentDrawModelAccess().GetInvisibleHellId() );
1521 : }
1522 : }
1523 33402 : else if(FN_ANCHOR_POSITION == pEntry->nWID)
1524 : {
1525 1 : SvxShape* pSvxShape = GetSvxShape();
1526 : OSL_ENSURE(pSvxShape, "No SvxShape found!");
1527 1 : if(pSvxShape)
1528 : {
1529 1 : SdrObject* pObj = pSvxShape->GetSdrObject();
1530 1 : Point aPt = pObj->GetAnchorPos();
1531 1 : awt::Point aPoint( convertTwipToMm100( aPt.X() ),
1532 2 : convertTwipToMm100( aPt.Y() ) );
1533 1 : aRet.setValue(&aPoint, cppu::UnoType<awt::Point>::get());
1534 : }
1535 : }
1536 : // #i26791# - special handling for FN_TEXT_RANGE
1537 33401 : else if ( FN_TEXT_RANGE == pEntry->nWID )
1538 : {
1539 0 : const SwFormatAnchor aAnchor = pFormat->GetAnchor();
1540 0 : if (aAnchor.GetAnchorId() == FLY_AT_PAGE)
1541 : {
1542 : // return nothing, because property <TextRange> isn't
1543 : // valid for to-page anchored shapes
1544 0 : uno::Any aAny;
1545 0 : aRet = aAny;
1546 : }
1547 : else
1548 : {
1549 0 : if ( aAnchor.GetContentAnchor() )
1550 : {
1551 : const uno::Reference< text::XTextRange > xTextRange
1552 : = SwXTextRange::CreateXTextRange(
1553 0 : *pFormat->GetDoc(),
1554 0 : *aAnchor.GetContentAnchor(),
1555 0 : 0L );
1556 0 : aRet.setValue(&xTextRange, cppu::UnoType<text::XTextRange>::get());
1557 : }
1558 : else
1559 : {
1560 : // return nothing
1561 0 : uno::Any aAny;
1562 0 : aRet = aAny;
1563 : }
1564 0 : }
1565 : }
1566 33401 : else if (pEntry->nWID == FN_TEXT_BOX)
1567 : {
1568 2664 : bool bValue = SwTextBoxHelper::findTextBox(pFormat);
1569 2664 : aRet <<= bValue;
1570 : }
1571 30737 : else if (pEntry->nWID == RES_CHAIN)
1572 : {
1573 9 : switch (pEntry->nMemberId)
1574 : {
1575 : case MID_CHAIN_PREVNAME:
1576 : case MID_CHAIN_NEXTNAME:
1577 : case MID_CHAIN_NAME:
1578 9 : SwTextBoxHelper::getProperty(pFormat, pEntry->nWID, pEntry->nMemberId, aRet);
1579 9 : break;
1580 : }
1581 : }
1582 : // #i28749#
1583 30728 : else if ( FN_SHAPE_TRANSFORMATION_IN_HORI_L2R == pEntry->nWID )
1584 : {
1585 : // get property <::drawing::Shape::Transformation>
1586 : // without conversion to layout direction as below
1587 0 : aRet = _getPropAtAggrObj( "Transformation" );
1588 : }
1589 30728 : else if ( FN_SHAPE_POSITION_LAYOUT_DIR == pEntry->nWID )
1590 : {
1591 0 : aRet <<= pFormat->GetPositionLayoutDir();
1592 : }
1593 : // #i36248#
1594 30728 : else if ( FN_SHAPE_STARTPOSITION_IN_HORI_L2R == pEntry->nWID )
1595 : {
1596 : // get property <::drawing::Shape::StartPosition>
1597 : // without conversion to layout direction as below
1598 0 : aRet = _getPropAtAggrObj( "StartPosition" );
1599 : }
1600 30728 : else if ( FN_SHAPE_ENDPOSITION_IN_HORI_L2R == pEntry->nWID )
1601 : {
1602 : // get property <::drawing::Shape::EndPosition>
1603 : // without conversion to layout direction as below
1604 0 : aRet = _getPropAtAggrObj( "EndPosition" );
1605 : }
1606 30891 : else if (pEntry->nWID == RES_FRM_SIZE &&
1607 276 : (pEntry->nMemberId == MID_FRMSIZE_REL_HEIGHT ||
1608 177 : pEntry->nMemberId == MID_FRMSIZE_REL_WIDTH ||
1609 96 : pEntry->nMemberId == MID_FRMSIZE_REL_HEIGHT_RELATION ||
1610 32 : pEntry->nMemberId == MID_FRMSIZE_REL_WIDTH_RELATION))
1611 : {
1612 163 : SvxShape* pSvxShape = GetSvxShape();
1613 : SAL_WARN_IF(!pSvxShape, "sw.uno", "No SvxShape found!");
1614 163 : sal_Int16 nRet = 0;
1615 163 : if (pSvxShape)
1616 : {
1617 163 : SdrObject* pObj = pSvxShape->GetSdrObject();
1618 163 : switch (pEntry->nMemberId)
1619 : {
1620 : case MID_FRMSIZE_REL_WIDTH:
1621 49 : if (pObj->GetRelativeWidth())
1622 6 : nRet = *pObj->GetRelativeWidth() * 100;
1623 49 : break;
1624 : case MID_FRMSIZE_REL_HEIGHT:
1625 50 : if (pObj->GetRelativeHeight())
1626 7 : nRet = *pObj->GetRelativeHeight() * 100;
1627 50 : break;
1628 : case MID_FRMSIZE_REL_WIDTH_RELATION:
1629 32 : nRet = pObj->GetRelativeWidthRelation();
1630 32 : break;
1631 : case MID_FRMSIZE_REL_HEIGHT_RELATION:
1632 32 : nRet = pObj->GetRelativeHeightRelation();
1633 32 : break;
1634 : }
1635 : }
1636 163 : aRet = uno::makeAny(nRet);
1637 : }
1638 : else
1639 : {
1640 30565 : const SwAttrSet& rSet = pFormat->GetAttrSet();
1641 30565 : m_pPropSet->getPropertyValue(*pEntry, rSet, aRet);
1642 : }
1643 : }
1644 : else
1645 : {
1646 10355 : SfxPoolItem* pItem = 0;
1647 10355 : switch(pEntry->nWID)
1648 : {
1649 : case RES_ANCHOR:
1650 3446 : pItem = pImpl->GetAnchor();
1651 3446 : break;
1652 : case RES_HORI_ORIENT:
1653 3452 : pItem = pImpl->GetHOrient();
1654 3452 : break;
1655 : case RES_VERT_ORIENT:
1656 3452 : pItem = pImpl->GetVOrient();
1657 3452 : break;
1658 : case RES_LR_SPACE:
1659 0 : pItem = pImpl->GetLRSpace();
1660 0 : break;
1661 : case RES_UL_SPACE:
1662 0 : pItem = pImpl->GetULSpace();
1663 0 : break;
1664 : case RES_SURROUND:
1665 0 : pItem = pImpl->GetSurround();
1666 0 : break;
1667 : case FN_TEXT_RANGE :
1668 0 : aRet.setValue(&pImpl->GetTextRange(), cppu::UnoType<text::XTextRange>::get());
1669 0 : break;
1670 : case RES_OPAQUE :
1671 2 : aRet <<= pImpl->GetOpaque();
1672 2 : break;
1673 : case FN_ANCHOR_POSITION :
1674 : {
1675 0 : awt::Point aPoint;
1676 0 : aRet.setValue(&aPoint, cppu::UnoType<awt::Point>::get());
1677 : }
1678 0 : break;
1679 : // #i26791#
1680 : case RES_FOLLOW_TEXT_FLOW :
1681 : {
1682 0 : pItem = pImpl->GetFollowTextFlow();
1683 : }
1684 0 : break;
1685 : // #i28701#
1686 : case RES_WRAP_INFLUENCE_ON_OBJPOS:
1687 : {
1688 0 : pItem = pImpl->GetWrapInfluenceOnObjPos();
1689 : }
1690 0 : break;
1691 : // #i28749#
1692 : case FN_SHAPE_TRANSFORMATION_IN_HORI_L2R:
1693 : {
1694 : // get property <::drawing::Shape::Transformation>
1695 : // without conversion to layout direction as below
1696 1 : aRet = _getPropAtAggrObj( "Transformation" );
1697 : }
1698 1 : break;
1699 : case FN_SHAPE_POSITION_LAYOUT_DIR:
1700 : {
1701 0 : aRet <<= pImpl->GetPositionLayoutDir();
1702 : }
1703 0 : break;
1704 : // #i36248#
1705 : case FN_SHAPE_STARTPOSITION_IN_HORI_L2R:
1706 : {
1707 : // get property <::drawing::Shape::StartPosition>
1708 : // without conversion to layout direction as below
1709 0 : aRet = _getPropAtAggrObj( "StartPosition" );
1710 : }
1711 0 : break;
1712 : case FN_SHAPE_ENDPOSITION_IN_HORI_L2R:
1713 : {
1714 : // get property <::drawing::Shape::StartPosition>
1715 : // without conversion to layout direction as below
1716 0 : aRet = _getPropAtAggrObj( "EndPosition" );
1717 : }
1718 0 : break;
1719 : }
1720 10355 : if(pItem)
1721 112 : pItem->QueryValue(aRet, pEntry->nMemberId);
1722 : }
1723 : }
1724 : else
1725 : {
1726 51970 : aRet = _getPropAtAggrObj( rPropertyName );
1727 :
1728 : // #i31698# - convert the position (translation)
1729 : // of the drawing object in the transformation
1730 50342 : if ( rPropertyName == "Transformation" )
1731 : {
1732 690 : drawing::HomogenMatrix3 aMatrix;
1733 690 : aRet >>= aMatrix;
1734 690 : aRet <<= _ConvertTransformationToLayoutDir( aMatrix );
1735 : }
1736 : // #i36248#
1737 49652 : else if ( rPropertyName == "StartPosition" )
1738 : {
1739 0 : awt::Point aStartPos;
1740 0 : aRet >>= aStartPos;
1741 : // #i59051#
1742 0 : aRet <<= _ConvertStartOrEndPosToLayoutDir( aStartPos );
1743 : }
1744 49652 : else if ( rPropertyName == "EndPosition" )
1745 : {
1746 0 : awt::Point aEndPos;
1747 0 : aRet >>= aEndPos;
1748 : // #i59051#
1749 0 : aRet <<= _ConvertStartOrEndPosToLayoutDir( aEndPos );
1750 : }
1751 : // #i59051#
1752 49652 : else if ( rPropertyName == "PolyPolygonBezier" )
1753 : {
1754 140 : drawing::PolyPolygonBezierCoords aPath;
1755 140 : aRet >>= aPath;
1756 140 : aRet <<= _ConvertPolyPolygonBezierToLayoutDir( aPath );
1757 : }
1758 49512 : else if (rPropertyName == "ZOrder")
1759 : {
1760 : // Convert the real draw page position to the logical one that ignores textboxes.
1761 661 : if (pFormat)
1762 : {
1763 642 : const SdrObject* pObj = pFormat->FindRealSdrObject();
1764 642 : if (pObj)
1765 : {
1766 642 : bool bConvert = true;
1767 642 : if (SvxShape* pSvxShape = GetSvxShape())
1768 : // In case of group shapes, pSvxShape points to the child shape, while pObj points to the outermost group shape.
1769 642 : if (pSvxShape->GetSdrObject() != pObj)
1770 : // Textboxes are not expected inside group shapes, so no conversion is necessary there.
1771 17 : bConvert = false;
1772 642 : if (bConvert)
1773 : {
1774 625 : std::set<const SwFrameFormat*> aTextBoxes = SwTextBoxHelper::findTextBoxes(pFormat->GetDoc());
1775 625 : aRet <<= SwTextBoxHelper::getOrdNum(pObj, aTextBoxes);
1776 : }
1777 : }
1778 : }
1779 : }
1780 : }
1781 : }
1782 95764 : return aRet;
1783 : }
1784 :
1785 51971 : uno::Any SwXShape::_getPropAtAggrObj( const OUString& _rPropertyName )
1786 : throw( beans::UnknownPropertyException, lang::WrappedTargetException,
1787 : uno::RuntimeException )
1788 : {
1789 51971 : uno::Any aRet;
1790 :
1791 103942 : uno::Reference< beans::XPropertySet > xPrSet;
1792 : const uno::Type& rPSetType =
1793 51971 : cppu::UnoType<beans::XPropertySet>::get();
1794 103942 : uno::Any aPSet = xShapeAgg->queryAggregation(rPSetType);
1795 51971 : if ( aPSet.getValueType() != rPSetType || !aPSet.getValue() )
1796 : {
1797 0 : throw uno::RuntimeException();
1798 : }
1799 51971 : xPrSet = *static_cast<uno::Reference< beans::XPropertySet > const *>(aPSet.getValue());
1800 51971 : aRet = xPrSet->getPropertyValue( _rPropertyName );
1801 :
1802 100686 : return aRet;
1803 : }
1804 :
1805 533 : beans::PropertyState SwXShape::getPropertyState( const OUString& rPropertyName )
1806 : throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception)
1807 : {
1808 533 : SolarMutexGuard aGuard;
1809 1066 : uno::Sequence< OUString > aNames(1);
1810 533 : OUString* pStrings = aNames.getArray();
1811 533 : pStrings[0] = rPropertyName;
1812 1066 : uno::Sequence< beans::PropertyState > aStates = getPropertyStates(aNames);
1813 1066 : return aStates.getConstArray()[0];
1814 : }
1815 :
1816 593 : uno::Sequence< beans::PropertyState > SwXShape::getPropertyStates(
1817 : const uno::Sequence< OUString >& aPropertyNames )
1818 : throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception)
1819 : {
1820 593 : SolarMutexGuard aGuard;
1821 593 : SwFrameFormat* pFormat = GetFrameFormat();
1822 593 : uno::Sequence< beans::PropertyState > aRet(aPropertyNames.getLength());
1823 593 : if(xShapeAgg.is())
1824 : {
1825 593 : SvxShape* pSvxShape = GetSvxShape();
1826 593 : bool bGroupMember = false;
1827 593 : bool bFormControl = false;
1828 593 : SdrObject* pObject = pSvxShape ? pSvxShape->GetSdrObject() : NULL;
1829 593 : if(pObject)
1830 : {
1831 593 : bGroupMember = pObject->GetUpGroup() != 0;
1832 593 : bFormControl = pObject->GetObjInventor() == FmFormInventor;
1833 : }
1834 593 : const OUString* pNames = aPropertyNames.getConstArray();
1835 593 : beans::PropertyState* pRet = aRet.getArray();
1836 593 : uno::Reference< XPropertyState > xShapePrState;
1837 6223 : for(sal_Int32 nProperty = 0; nProperty < aPropertyNames.getLength(); nProperty++)
1838 : {
1839 5630 : const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap().getByName( pNames[nProperty] );
1840 5630 : if(pEntry)
1841 : {
1842 558 : if(RES_OPAQUE == pEntry->nWID)
1843 31 : pRet[nProperty] = bFormControl ?
1844 31 : beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
1845 527 : else if(FN_ANCHOR_POSITION == pEntry->nWID)
1846 0 : pRet[nProperty] = beans::PropertyState_DIRECT_VALUE;
1847 527 : else if(FN_TEXT_RANGE == pEntry->nWID)
1848 0 : pRet[nProperty] = beans::PropertyState_DIRECT_VALUE;
1849 527 : else if(bGroupMember)
1850 85 : pRet[nProperty] = beans::PropertyState_DEFAULT_VALUE;
1851 494 : else if (pEntry->nWID == RES_FRM_SIZE &&
1852 78 : (pEntry->nMemberId == MID_FRMSIZE_REL_HEIGHT_RELATION ||
1853 26 : pEntry->nMemberId == MID_FRMSIZE_REL_WIDTH_RELATION))
1854 52 : pRet[nProperty] = beans::PropertyState_DIRECT_VALUE;
1855 390 : else if (pEntry->nWID == FN_TEXT_BOX)
1856 : {
1857 : // The TextBox property is set, if we can find a textbox for this shape.
1858 0 : if (pFormat && SwTextBoxHelper::findTextBox(pFormat))
1859 0 : pRet[nProperty] = beans::PropertyState_DIRECT_VALUE;
1860 : else
1861 0 : pRet[nProperty] = beans::PropertyState_DEFAULT_VALUE;
1862 : }
1863 390 : else if(pFormat)
1864 : {
1865 390 : const SwAttrSet& rSet = pFormat->GetAttrSet();
1866 390 : SfxItemState eItemState = rSet.GetItemState(pEntry->nWID, false);
1867 :
1868 390 : if(SfxItemState::SET == eItemState)
1869 326 : pRet[nProperty] = beans::PropertyState_DIRECT_VALUE;
1870 64 : else if(SfxItemState::DEFAULT == eItemState)
1871 64 : pRet[nProperty] = beans::PropertyState_DEFAULT_VALUE;
1872 : else
1873 0 : pRet[nProperty] = beans::PropertyState_AMBIGUOUS_VALUE;
1874 : }
1875 : else
1876 : {
1877 0 : SfxPoolItem* pItem = 0;
1878 0 : switch(pEntry->nWID)
1879 : {
1880 : case RES_ANCHOR:
1881 0 : pItem = pImpl->GetAnchor();
1882 0 : break;
1883 : case RES_HORI_ORIENT:
1884 0 : pItem = pImpl->GetHOrient();
1885 0 : break;
1886 : case RES_VERT_ORIENT:
1887 0 : pItem = pImpl->GetVOrient();
1888 0 : break;
1889 : case RES_LR_SPACE:
1890 0 : pItem = pImpl->GetLRSpace();
1891 0 : break;
1892 : case RES_UL_SPACE:
1893 0 : pItem = pImpl->GetULSpace();
1894 0 : break;
1895 : case RES_SURROUND:
1896 0 : pItem = pImpl->GetSurround();
1897 0 : break;
1898 : // #i28701#
1899 : case RES_WRAP_INFLUENCE_ON_OBJPOS:
1900 : {
1901 0 : pItem = pImpl->GetWrapInfluenceOnObjPos();
1902 : }
1903 0 : break;
1904 : }
1905 0 : if(pItem)
1906 0 : pRet[nProperty] = beans::PropertyState_DIRECT_VALUE;
1907 : else
1908 0 : pRet[nProperty] = beans::PropertyState_DEFAULT_VALUE;
1909 : }
1910 : }
1911 : else
1912 : {
1913 5072 : if(!xShapePrState.is())
1914 : {
1915 593 : const uno::Type& rPStateType = cppu::UnoType<XPropertyState>::get();
1916 593 : uno::Any aPState = xShapeAgg->queryAggregation(rPStateType);
1917 593 : if(aPState.getValueType() != rPStateType || !aPState.getValue())
1918 0 : throw uno::RuntimeException();
1919 593 : xShapePrState = *static_cast<uno::Reference< XPropertyState > const *>(aPState.getValue());
1920 : }
1921 5072 : pRet[nProperty] = xShapePrState->getPropertyState(pNames[nProperty]);
1922 : }
1923 593 : }
1924 : }
1925 : else
1926 0 : throw uno::RuntimeException();
1927 593 : return aRet;
1928 : }
1929 :
1930 0 : void SwXShape::setPropertyToDefault( const OUString& rPropertyName )
1931 : throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception)
1932 : {
1933 0 : SolarMutexGuard aGuard;
1934 0 : SwFrameFormat* pFormat = GetFrameFormat();
1935 0 : if(xShapeAgg.is())
1936 : {
1937 0 : const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName );
1938 0 : if(pEntry)
1939 : {
1940 0 : if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
1941 0 : throw uno::RuntimeException("Property is read-only: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
1942 0 : if(pFormat)
1943 : {
1944 0 : const SfxItemSet& rSet = pFormat->GetAttrSet();
1945 0 : SfxItemSet aSet(pFormat->GetDoc()->GetAttrPool(), pEntry->nWID, pEntry->nWID);
1946 0 : aSet.SetParent(&rSet);
1947 0 : aSet.ClearItem(pEntry->nWID);
1948 0 : pFormat->GetDoc()->SetAttr(aSet, *pFormat);
1949 : }
1950 : else
1951 : {
1952 0 : switch(pEntry->nWID)
1953 : {
1954 0 : case RES_ANCHOR: pImpl->RemoveAnchor(); break;
1955 0 : case RES_HORI_ORIENT: pImpl->RemoveHOrient(); break;
1956 0 : case RES_VERT_ORIENT: pImpl->RemoveVOrient(); break;
1957 0 : case RES_LR_SPACE: pImpl->RemoveLRSpace(); break;
1958 0 : case RES_UL_SPACE: pImpl->RemoveULSpace(); break;
1959 0 : case RES_SURROUND: pImpl->RemoveSurround();break;
1960 0 : case RES_OPAQUE : pImpl->SetOpaque(false); break;
1961 : case FN_TEXT_RANGE :
1962 0 : break;
1963 : // #i26791#
1964 : case RES_FOLLOW_TEXT_FLOW:
1965 : {
1966 0 : pImpl->RemoveFollowTextFlow();
1967 : }
1968 0 : break;
1969 : // #i28701#
1970 : case RES_WRAP_INFLUENCE_ON_OBJPOS:
1971 : {
1972 0 : pImpl->RemoveWrapInfluenceOnObjPos();
1973 : }
1974 0 : break;
1975 : }
1976 : }
1977 : }
1978 : else
1979 : {
1980 0 : const uno::Type& rPStateType = cppu::UnoType<XPropertyState>::get();
1981 0 : uno::Any aPState = xShapeAgg->queryAggregation(rPStateType);
1982 0 : if(aPState.getValueType() != rPStateType || !aPState.getValue())
1983 0 : throw uno::RuntimeException();
1984 0 : uno::Reference< XPropertyState > xShapePrState = *static_cast<uno::Reference< XPropertyState > const *>(aPState.getValue());
1985 0 : xShapePrState->setPropertyToDefault( rPropertyName );
1986 : }
1987 : }
1988 : else
1989 0 : throw uno::RuntimeException();
1990 0 : }
1991 :
1992 0 : uno::Any SwXShape::getPropertyDefault( const OUString& rPropertyName )
1993 : throw( beans::UnknownPropertyException, lang::WrappedTargetException,
1994 : uno::RuntimeException, std::exception )
1995 : {
1996 0 : SolarMutexGuard aGuard;
1997 0 : SwFrameFormat* pFormat = GetFrameFormat();
1998 0 : uno::Any aRet;
1999 0 : if(xShapeAgg.is())
2000 : {
2001 0 : const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName );
2002 0 : if(pEntry)
2003 : {
2004 0 : if(pEntry->nWID < RES_FRMATR_END && pFormat)
2005 : {
2006 : const SfxPoolItem& rDefItem =
2007 0 : pFormat->GetDoc()->GetAttrPool().GetDefaultItem(pEntry->nWID);
2008 0 : rDefItem.QueryValue(aRet, pEntry->nMemberId);
2009 : }
2010 : else
2011 0 : throw uno::RuntimeException();
2012 : }
2013 : else
2014 : {
2015 0 : const uno::Type& rPStateType = cppu::UnoType<XPropertyState>::get();
2016 0 : uno::Any aPState = xShapeAgg->queryAggregation(rPStateType);
2017 0 : if(aPState.getValueType() != rPStateType || !aPState.getValue())
2018 0 : throw uno::RuntimeException();
2019 0 : uno::Reference< XPropertyState > xShapePrState = *static_cast<uno::Reference< XPropertyState > const *>(aPState.getValue());
2020 0 : xShapePrState->getPropertyDefault( rPropertyName );
2021 : }
2022 : }
2023 : else
2024 0 : throw uno::RuntimeException();
2025 0 : return aRet;
2026 : }
2027 :
2028 0 : void SwXShape::addPropertyChangeListener(
2029 : const OUString& _propertyName,
2030 : const uno::Reference< beans::XPropertyChangeListener > & _listener )
2031 : throw( beans::UnknownPropertyException, lang::WrappedTargetException,
2032 : uno::RuntimeException, std::exception )
2033 : {
2034 0 : if ( !xShapeAgg.is() )
2035 0 : throw uno::RuntimeException("no shape aggregate", *this );
2036 :
2037 : // must be handled by the aggregate
2038 0 : uno::Reference< beans::XPropertySet > xShapeProps;
2039 0 : if ( xShapeAgg->queryAggregation( cppu::UnoType<beans::XPropertySet>::get() ) >>= xShapeProps )
2040 0 : xShapeProps->addPropertyChangeListener( _propertyName, _listener );
2041 0 : }
2042 :
2043 0 : void SwXShape::removePropertyChangeListener(
2044 : const OUString& _propertyName,
2045 : const uno::Reference< beans::XPropertyChangeListener > & _listener)
2046 : throw( beans::UnknownPropertyException, lang::WrappedTargetException,
2047 : uno::RuntimeException, std::exception )
2048 : {
2049 0 : if ( !xShapeAgg.is() )
2050 0 : throw uno::RuntimeException("no shape aggregate", *this );
2051 :
2052 : // must be handled by the aggregate
2053 0 : uno::Reference< beans::XPropertySet > xShapeProps;
2054 0 : if ( xShapeAgg->queryAggregation( cppu::UnoType<beans::XPropertySet>::get() ) >>= xShapeProps )
2055 0 : xShapeProps->removePropertyChangeListener( _propertyName, _listener );
2056 0 : }
2057 :
2058 0 : void SwXShape::addVetoableChangeListener(
2059 : const OUString& /*PropertyName*/,
2060 : const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/ )
2061 : throw( beans::UnknownPropertyException, lang::WrappedTargetException,
2062 : uno::RuntimeException, std::exception )
2063 : {
2064 : OSL_FAIL("not implemented");
2065 0 : }
2066 :
2067 0 : void SwXShape::removeVetoableChangeListener(
2068 : const OUString& /*PropertyName*/,
2069 : const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/)
2070 : throw( beans::UnknownPropertyException, lang::WrappedTargetException,
2071 : uno::RuntimeException, std::exception )
2072 : {
2073 : OSL_FAIL("not implemented");
2074 0 : }
2075 :
2076 20038 : void SwXShape::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
2077 : {
2078 20038 : ClientModify(this, pOld, pNew);
2079 20038 : }
2080 :
2081 2528 : void SwXShape::attach(const uno::Reference< text::XTextRange > & xTextRange)
2082 : throw( lang::IllegalArgumentException, uno::RuntimeException, std::exception )
2083 : {
2084 2528 : SolarMutexGuard aGuard;
2085 :
2086 : // get access to SwDoc
2087 : // (see also SwXTextRange::XTextRangeToSwPaM)
2088 2528 : SwDoc* pDoc = 0;
2089 5056 : uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
2090 2528 : if(xRangeTunnel.is())
2091 : {
2092 2528 : SwXTextRange* pRange = 0;
2093 2528 : OTextCursorHelper* pCursor = 0;
2094 2528 : SwXTextPortion* pPortion = 0;
2095 2528 : SwXText* pText = 0;
2096 2528 : SwXParagraph* pParagraph = 0;
2097 :
2098 : pRange = reinterpret_cast< SwXTextRange * >(
2099 2528 : sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXTextRange::getUnoTunnelId()) ));
2100 : pText = reinterpret_cast< SwXText * >(
2101 2528 : sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXText::getUnoTunnelId()) ));
2102 : pCursor = reinterpret_cast< OTextCursorHelper * >(
2103 2528 : sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( OTextCursorHelper::getUnoTunnelId()) ));
2104 : pPortion = reinterpret_cast< SwXTextPortion * >(
2105 2528 : sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXTextPortion::getUnoTunnelId()) ));
2106 : pParagraph = reinterpret_cast< SwXParagraph * >(
2107 2528 : sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXParagraph::getUnoTunnelId( ) ) ) );
2108 :
2109 2528 : if (pRange)
2110 2527 : pDoc = pRange->GetDoc();
2111 1 : else if (!pDoc && pText)
2112 0 : pDoc = pText->GetDoc();
2113 1 : else if (!pDoc && pCursor)
2114 1 : pDoc = pCursor->GetDoc();
2115 0 : else if ( !pDoc && pPortion && pPortion->GetCursor() )
2116 : {
2117 0 : pDoc = pPortion->GetCursor()->GetDoc();
2118 : }
2119 0 : else if ( !pDoc && pParagraph && pParagraph->GetTextNode( ) )
2120 : {
2121 0 : pDoc = const_cast<SwDoc*>(pParagraph->GetTextNode()->GetDoc());
2122 : }
2123 :
2124 : }
2125 :
2126 2528 : if(!pDoc)
2127 0 : throw uno::RuntimeException();
2128 2528 : SwDocShell *pDocSh = pDoc->GetDocShell();
2129 2528 : if (pDocSh)
2130 : {
2131 2527 : uno::Reference< frame::XModel > xModel;
2132 2527 : xModel = pDocSh->GetModel();
2133 5054 : uno::Reference< drawing::XDrawPageSupplier > xDPS(xModel, uno::UNO_QUERY);
2134 2527 : if (xDPS.is())
2135 : {
2136 2527 : uno::Reference< drawing::XDrawPage > xDP( xDPS->getDrawPage() );
2137 2527 : if (xDP.is())
2138 : {
2139 2527 : uno::Any aPos;
2140 2527 : aPos <<= xTextRange;
2141 3573 : setPropertyValue("TextRange", aPos);
2142 2962 : uno::Reference< drawing::XShape > xTemp( static_cast<cppu::OWeakObject*>(this), uno::UNO_QUERY );
2143 4008 : xDP->add( xTemp );
2144 2527 : }
2145 2527 : }
2146 2528 : }
2147 149 : }
2148 :
2149 8 : uno::Reference< text::XTextRange > SwXShape::getAnchor() throw( uno::RuntimeException, std::exception )
2150 : {
2151 8 : SolarMutexGuard aGuard;
2152 8 : uno::Reference< text::XTextRange > aRef;
2153 8 : SwFrameFormat* pFormat = GetFrameFormat();
2154 8 : if(pFormat)
2155 : {
2156 8 : const SwFormatAnchor& rAnchor = pFormat->GetAnchor();
2157 : // return an anchor for non-page bound frames
2158 : // and for page bound frames that have a page no == NULL and a content position
2159 16 : if ((rAnchor.GetAnchorId() != FLY_AT_PAGE) ||
2160 0 : (rAnchor.GetContentAnchor() && !rAnchor.GetPageNum()))
2161 : {
2162 8 : const SwPosition &rPos = *(pFormat->GetAnchor().GetContentAnchor());
2163 8 : aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), rPos, 0);
2164 : }
2165 : }
2166 : else
2167 0 : aRef = pImpl->GetTextRange();
2168 8 : return aRef;
2169 : }
2170 :
2171 556 : void SwXShape::dispose() throw( uno::RuntimeException, std::exception )
2172 : {
2173 556 : SolarMutexGuard aGuard;
2174 556 : SwFrameFormat* pFormat = GetFrameFormat();
2175 556 : if(pFormat)
2176 : {
2177 : // determine correct <SdrObject>
2178 499 : SvxShape* pSvxShape = GetSvxShape();
2179 499 : SdrObject* pObj = pSvxShape ? pSvxShape->GetSdrObject() : NULL;
2180 : // safety assertion:
2181 : // <pObj> must be the same as <pFormat->FindSdrObject()>, if <pObj> isn't
2182 : // a 'virtual' drawing object.
2183 : // correct assertion and refine it for safety reason.
2184 : OSL_ENSURE( !pObj ||
2185 : pObj->ISA(SwDrawVirtObj) ||
2186 : pObj->GetUpGroup() ||
2187 : pObj == pFormat->FindSdrObject(),
2188 : "<SwXShape::dispose(..) - different 'master' drawing objects!!" );
2189 : // perform delete of draw frame format *not*
2190 : // for 'virtual' drawing objects.
2191 : // no delete of draw format for members
2192 : // of a group
2193 998 : if ( pObj &&
2194 998 : !pObj->ISA(SwDrawVirtObj) &&
2195 1496 : !pObj->GetUpGroup() &&
2196 498 : pObj->IsInserted() )
2197 : {
2198 498 : if (pFormat->GetAnchor().GetAnchorId() == FLY_AS_CHAR)
2199 : {
2200 123 : const SwPosition &rPos = *(pFormat->GetAnchor().GetContentAnchor());
2201 123 : SwTextNode *pTextNode = rPos.nNode.GetNode().GetTextNode();
2202 123 : const sal_Int32 nIdx = rPos.nContent.GetIndex();
2203 123 : pTextNode->DeleteAttributes( RES_TXTATR_FLYCNT, nIdx );
2204 : }
2205 : else
2206 375 : pFormat->GetDoc()->getIDocumentLayoutAccess().DelLayoutFormat( pFormat );
2207 : }
2208 : }
2209 556 : if(xShapeAgg.is())
2210 : {
2211 556 : uno::Any aAgg(xShapeAgg->queryAggregation( cppu::UnoType<XComponent>::get()));
2212 1112 : uno::Reference<XComponent> xComp;
2213 556 : aAgg >>= xComp;
2214 556 : if(xComp.is())
2215 1112 : xComp->dispose();
2216 556 : }
2217 556 : }
2218 :
2219 0 : void SwXShape::addEventListener(
2220 : const uno::Reference< lang::XEventListener > & aListener)
2221 : throw( uno::RuntimeException, std::exception )
2222 : {
2223 0 : uno::Reference< lang::XUnoTunnel > xShapeTunnel(xShapeAgg, uno::UNO_QUERY);
2224 0 : SvxShape* pSvxShape = GetSvxShape();
2225 0 : if(pSvxShape)
2226 0 : pSvxShape->addEventListener(aListener);
2227 0 : }
2228 :
2229 0 : void SwXShape::removeEventListener(
2230 : const uno::Reference< lang::XEventListener > & aListener)
2231 : throw( uno::RuntimeException, std::exception )
2232 : {
2233 0 : SvxShape* pSvxShape = GetSvxShape();
2234 0 : if(pSvxShape)
2235 0 : pSvxShape->removeEventListener(aListener);
2236 0 : }
2237 :
2238 0 : OUString SwXShape::getImplementationName() throw( uno::RuntimeException, std::exception )
2239 : {
2240 0 : return OUString("SwXShape");
2241 : }
2242 :
2243 14826 : sal_Bool SwXShape::supportsService(const OUString& rServiceName) throw( uno::RuntimeException, std::exception )
2244 : {
2245 14826 : return cppu::supportsService(this, rServiceName);
2246 : }
2247 :
2248 14826 : uno::Sequence< OUString > SwXShape::getSupportedServiceNames() throw( uno::RuntimeException, std::exception )
2249 : {
2250 14826 : uno::Sequence< OUString > aSeq;
2251 14826 : if(xShapeAgg.is())
2252 : {
2253 14826 : uno::Reference< lang::XUnoTunnel > xShapeTunnel(xShapeAgg, uno::UNO_QUERY);
2254 14826 : SvxShape* pSvxShape = GetSvxShape();
2255 14826 : if(pSvxShape)
2256 14826 : aSeq = pSvxShape->getSupportedServiceNames();
2257 : }
2258 : else
2259 : {
2260 0 : aSeq.realloc(1);
2261 0 : aSeq.getArray()[0] = "com.sun.star.drawing.Shape";
2262 : }
2263 14826 : return aSeq;
2264 : }
2265 :
2266 52210 : SvxShape* SwXShape::GetSvxShape()
2267 : {
2268 52210 : SvxShape* pSvxShape = 0;
2269 52210 : if(xShapeAgg.is())
2270 : {
2271 52210 : uno::Reference< lang::XUnoTunnel > xShapeTunnel(xShapeAgg, uno::UNO_QUERY);
2272 52210 : if(xShapeTunnel.is())
2273 : pSvxShape = reinterpret_cast< SvxShape * >(
2274 52210 : sal::static_int_cast< sal_IntPtr >( xShapeTunnel->getSomething(SvxShape::getUnoTunnelId()) ));
2275 : }
2276 52210 : return pSvxShape;
2277 : }
2278 :
2279 : // #i31698#
2280 : // implementation of virtual methods from drawing::XShape
2281 12073 : awt::Point SAL_CALL SwXShape::getPosition() throw ( uno::RuntimeException, std::exception )
2282 : {
2283 12073 : awt::Point aPos( _GetAttrPosition() );
2284 :
2285 : // handle group members
2286 12073 : SvxShape* pSvxShape = GetSvxShape();
2287 12073 : if ( pSvxShape )
2288 : {
2289 12073 : SdrObject* pTopGroupObj = _GetTopGroupObj( pSvxShape );
2290 12073 : if ( pTopGroupObj )
2291 : {
2292 : // #i34750# - get attribute position of top group
2293 : // shape and add offset between top group object and group member
2294 : uno::Reference< drawing::XShape > xGroupShape =
2295 2881 : uno::Reference< drawing::XShape >( pTopGroupObj->getUnoShape(),
2296 2881 : uno::UNO_QUERY );
2297 2881 : aPos = xGroupShape->getPosition();
2298 : // add offset between top group object and group member
2299 : // to the determined attribute position
2300 : // #i34750#:
2301 : // consider the layout direction
2302 2881 : const Rectangle aMemberObjRect = GetSvxShape()->GetSdrObject()->GetSnapRect();
2303 2881 : const Rectangle aGroupObjRect = pTopGroupObj->GetSnapRect();
2304 : // #i53320# - relative position of group member and
2305 : // top group object is always given in horizontal left-to-right layout.
2306 2881 : awt::Point aOffset( 0, 0 );
2307 : {
2308 2881 : aOffset.X = ( aMemberObjRect.Left() - aGroupObjRect.Left() );
2309 2881 : aOffset.Y = ( aMemberObjRect.Top() - aGroupObjRect.Top() );
2310 : }
2311 2881 : aOffset.X = convertTwipToMm100(aOffset.X);
2312 2881 : aOffset.Y = convertTwipToMm100(aOffset.Y);
2313 2881 : aPos.X += aOffset.X;
2314 2881 : aPos.Y += aOffset.Y;
2315 : }
2316 : }
2317 :
2318 12073 : return aPos;
2319 : }
2320 :
2321 1394 : void SAL_CALL SwXShape::setPosition( const awt::Point& aPosition )
2322 : throw ( uno::RuntimeException, std::exception )
2323 : {
2324 1394 : SdrObject* pTopGroupObj = _GetTopGroupObj();
2325 1394 : if ( !pTopGroupObj )
2326 : {
2327 : // #i37877# - no adjustment of position attributes,
2328 : // if the position also has to be applied at the drawing object and
2329 : // a contact object is already registered at the drawing object.
2330 446 : bool bApplyPosAtDrawObj(false);
2331 446 : bool bNoAdjustOfPosProp(false);
2332 : // #i35798# - apply position also to drawing object,
2333 : // if drawing object has no anchor position set.
2334 446 : if ( mxShape.is() )
2335 : {
2336 446 : SvxShape* pSvxShape = GetSvxShape();
2337 446 : if ( pSvxShape )
2338 : {
2339 446 : const SdrObject* pObj = pSvxShape->GetSdrObject();
2340 886 : if ( pObj &&
2341 886 : pObj->GetAnchorPos().X() == 0 &&
2342 440 : pObj->GetAnchorPos().Y() == 0 )
2343 : {
2344 440 : bApplyPosAtDrawObj = true;
2345 880 : if ( pObj->GetUserCall() &&
2346 440 : pObj->GetUserCall()->ISA(SwDrawContact) )
2347 : {
2348 440 : bNoAdjustOfPosProp = true;
2349 : }
2350 : }
2351 : }
2352 : }
2353 : // shape isn't a group member. Thus, set positioning attributes
2354 446 : if ( !bNoAdjustOfPosProp )
2355 : {
2356 6 : _AdjustPositionProperties( aPosition );
2357 : }
2358 446 : if ( bApplyPosAtDrawObj )
2359 : {
2360 440 : mxShape->setPosition( aPosition );
2361 : }
2362 : }
2363 948 : else if ( mxShape.is() )
2364 : {
2365 : // shape is a member of a group. Thus, set its position.
2366 948 : awt::Point aNewPos( aPosition );
2367 : // The given position is given in the according layout direction. Thus,
2368 : // it has to be converted to a position in horizontal left-to-right
2369 : // layout.
2370 : // convert given absolute attribute position in layout direction into
2371 : // position in horizontal left-to-right layout.
2372 : {
2373 948 : aNewPos = _ConvertPositionToHoriL2R( aNewPos, getSize() );
2374 : }
2375 : // Convert given absolute position in horizontal left-to-right
2376 : // layout into relative position in horizontal left-to-right layout.
2377 : uno::Reference< drawing::XShape > xGroupShape =
2378 948 : uno::Reference< drawing::XShape >( pTopGroupObj->getUnoShape(),
2379 948 : uno::UNO_QUERY );
2380 : {
2381 : // #i34750#
2382 : // use method <xGroupShape->getPosition()> to get the correct
2383 : // position of the top group object.
2384 : awt::Point aAttrPosInHoriL2R(
2385 948 : _ConvertPositionToHoriL2R( xGroupShape->getPosition(),
2386 1896 : xGroupShape->getSize() ) );
2387 948 : aNewPos.X -= aAttrPosInHoriL2R.X;
2388 948 : aNewPos.Y -= aAttrPosInHoriL2R.Y;
2389 : }
2390 : // convert relative position in horizontal left-to-right layout into
2391 : // absolute position in horizontal left-to-right layout
2392 : {
2393 : // #i34750#
2394 : // use method <SvxShape->getPosition()> to get the correct
2395 : // 'Drawing layer' position of the top group shape.
2396 : uno::Reference< lang::XUnoTunnel > xGrpShapeTunnel(
2397 948 : pTopGroupObj->getUnoShape(),
2398 948 : uno::UNO_QUERY );
2399 : SvxShape* pSvxGroupShape = reinterpret_cast< SvxShape * >(
2400 948 : sal::static_int_cast< sal_IntPtr >( xGrpShapeTunnel->getSomething(SvxShape::getUnoTunnelId()) ));
2401 948 : const awt::Point aGroupPos = pSvxGroupShape->getPosition();
2402 948 : aNewPos.X += aGroupPos.X;
2403 948 : aNewPos.Y += aGroupPos.Y;
2404 : }
2405 : // set position
2406 948 : mxShape->setPosition( aNewPos );
2407 : }
2408 1394 : }
2409 :
2410 11137 : awt::Size SAL_CALL SwXShape::getSize() throw ( uno::RuntimeException, std::exception )
2411 : {
2412 11137 : awt::Size aSize;
2413 11137 : if ( mxShape.is() )
2414 : {
2415 11137 : aSize = mxShape->getSize();
2416 : }
2417 11137 : return aSize;
2418 : }
2419 :
2420 2573 : void SAL_CALL SwXShape::setSize( const awt::Size& aSize )
2421 : throw ( beans::PropertyVetoException,
2422 : uno::RuntimeException, std::exception )
2423 : {
2424 2573 : if ( mxShape.is() )
2425 : {
2426 2573 : mxShape->setSize( aSize );
2427 : }
2428 2573 : SwTextBoxHelper::syncProperty(GetFrameFormat(), RES_FRM_SIZE, MID_FRMSIZE_SIZE, uno::makeAny(aSize));
2429 2573 : }
2430 : // #i31698#
2431 : // implementation of virtual methods from drawing::XShapeDescriptor
2432 9526 : OUString SAL_CALL SwXShape::getShapeType() throw ( uno::RuntimeException, std::exception )
2433 : {
2434 9526 : if ( mxShape.is() )
2435 : {
2436 9526 : return mxShape->getShapeType();
2437 : }
2438 0 : return OUString();
2439 : }
2440 : /** method to determine top group object
2441 : #i31698#
2442 : */
2443 13467 : SdrObject* SwXShape::_GetTopGroupObj( SvxShape* _pSvxShape )
2444 : {
2445 13467 : SdrObject* pTopGroupObj( 0L );
2446 :
2447 13467 : SvxShape* pSvxShape = _pSvxShape ? _pSvxShape : GetSvxShape();
2448 13467 : if ( pSvxShape )
2449 : {
2450 13467 : SdrObject* pSdrObj = pSvxShape->GetSdrObject();
2451 13467 : if ( pSdrObj && pSdrObj->GetUpGroup() )
2452 : {
2453 3829 : pTopGroupObj = pSdrObj->GetUpGroup();
2454 8295 : while ( pTopGroupObj->GetUpGroup() )
2455 : {
2456 637 : pTopGroupObj = pTopGroupObj->GetUpGroup();
2457 : }
2458 : }
2459 : }
2460 :
2461 13467 : return pTopGroupObj;
2462 : }
2463 :
2464 : /** method to determine position according to the positioning attributes
2465 : #i31698#
2466 : */
2467 12073 : awt::Point SwXShape::_GetAttrPosition()
2468 : {
2469 12073 : awt::Point aAttrPos;
2470 :
2471 12073 : uno::Any aHoriPos( getPropertyValue("HoriOrientPosition") );
2472 12073 : aHoriPos >>= aAttrPos.X;
2473 24146 : uno::Any aVertPos( getPropertyValue("VertOrientPosition") );
2474 12073 : aVertPos >>= aAttrPos.Y;
2475 : // #i35798# - fallback, if attribute position is (0,0)
2476 : // and no anchor position is applied to the drawing object
2477 12073 : SvxShape* pSvxShape = GetSvxShape();
2478 12073 : if ( pSvxShape )
2479 : {
2480 12073 : const SdrObject* pObj = pSvxShape->GetSdrObject();
2481 20706 : if ( pObj &&
2482 10951 : pObj->GetAnchorPos().X() == 0 &&
2483 4636 : pObj->GetAnchorPos().Y() == 0 &&
2484 16262 : aAttrPos.X == 0 && aAttrPos.Y == 0 )
2485 : {
2486 1871 : const Rectangle aObjRect = pObj->GetSnapRect();
2487 1871 : aAttrPos.X = convertTwipToMm100(aObjRect.Left());
2488 1871 : aAttrPos.Y = convertTwipToMm100(aObjRect.Top());
2489 : }
2490 : }
2491 : // #i35007# - If drawing object is anchored as-character,
2492 : // it's x-position isn't sensible. Thus, return the x-position as zero in this case.
2493 : text::TextContentAnchorType eTextAnchorType =
2494 12073 : text::TextContentAnchorType_AT_PARAGRAPH;
2495 : {
2496 12073 : uno::Any aAny = getPropertyValue( "AnchorType" );
2497 12073 : aAny >>= eTextAnchorType;
2498 : }
2499 12073 : if ( eTextAnchorType == text::TextContentAnchorType_AS_CHARACTER )
2500 : {
2501 4144 : aAttrPos.X = 0;
2502 : }
2503 :
2504 24146 : return aAttrPos;
2505 : }
2506 :
2507 : /** method to convert the position (translation) of the drawing object to
2508 : the layout direction horizontal left-to-right.
2509 : #i31698#
2510 : */
2511 1896 : awt::Point SwXShape::_ConvertPositionToHoriL2R( const awt::Point& rObjPos,
2512 : const awt::Size& rObjSize )
2513 : {
2514 1896 : awt::Point aObjPosInHoriL2R( rObjPos );
2515 :
2516 1896 : SwFrameFormat* pFrameFormat = GetFrameFormat();
2517 1896 : if ( pFrameFormat )
2518 : {
2519 1896 : SwFrameFormat::tLayoutDir eLayoutDir = pFrameFormat->GetLayoutDir();
2520 1896 : switch ( eLayoutDir )
2521 : {
2522 : case SwFrameFormat::HORI_L2R:
2523 : {
2524 : // nothing to do
2525 : }
2526 1896 : break;
2527 : case SwFrameFormat::HORI_R2L:
2528 : {
2529 0 : aObjPosInHoriL2R.X = -rObjPos.X - rObjSize.Width;
2530 : }
2531 0 : break;
2532 : case SwFrameFormat::VERT_R2L:
2533 : {
2534 0 : aObjPosInHoriL2R.X = -rObjPos.Y - rObjSize.Width;
2535 0 : aObjPosInHoriL2R.Y = rObjPos.X;
2536 : }
2537 0 : break;
2538 : default:
2539 : {
2540 : OSL_FAIL( "<SwXShape::_ConvertPositionToHoriL2R(..)> - unsupported layout direction" );
2541 : }
2542 : }
2543 : }
2544 :
2545 1896 : return aObjPosInHoriL2R;
2546 : }
2547 :
2548 : /** method to convert the transformation of the drawing object to the layout
2549 : direction, the drawing object is in
2550 : #i31698#
2551 : */
2552 690 : drawing::HomogenMatrix3 SwXShape::_ConvertTransformationToLayoutDir(
2553 : const drawing::HomogenMatrix3& rMatrixInHoriL2R )
2554 : {
2555 690 : drawing::HomogenMatrix3 aMatrix(rMatrixInHoriL2R);
2556 :
2557 : // #i44334#, #i44681# - direct manipulation of the
2558 : // tranformation structure isn't valid, if it contains rotation.
2559 690 : SvxShape* pSvxShape = GetSvxShape();
2560 : OSL_ENSURE( pSvxShape,
2561 : "<SwXShape::_ConvertTransformationToLayoutDir(..)> - no SvxShape found!");
2562 690 : if ( pSvxShape )
2563 : {
2564 690 : const SdrObject* pObj = pSvxShape->GetSdrObject();
2565 : OSL_ENSURE( pObj,
2566 : "<SwXShape::_ConvertTransformationToLayoutDir(..)> - no SdrObject found!");
2567 690 : if ( pObj )
2568 : {
2569 : // get position of object in Writer coordinate system.
2570 690 : awt::Point aPos( getPosition() );
2571 : // get position of object in Drawing layer coordinate system
2572 690 : const Point aTmpObjPos( pObj->GetSnapRect().TopLeft() );
2573 : const awt::Point aObjPos(
2574 690 : convertTwipToMm100( aTmpObjPos.X() - pObj->GetAnchorPos().X() ),
2575 1380 : convertTwipToMm100( aTmpObjPos.Y() - pObj->GetAnchorPos().Y() ) );
2576 : // determine difference between these positions according to the
2577 : // Writer coordinate system
2578 690 : const awt::Point aTranslateDiff( aPos.X - aObjPos.X,
2579 1380 : aPos.Y - aObjPos.Y );
2580 : // apply translation difference to transformation matrix.
2581 690 : if ( aTranslateDiff.X != 0 || aTranslateDiff.Y != 0 )
2582 : {
2583 : // #i73079# - use correct matrix type
2584 124 : ::basegfx::B2DHomMatrix aTempMatrix;
2585 :
2586 124 : aTempMatrix.set(0, 0, aMatrix.Line1.Column1 );
2587 124 : aTempMatrix.set(0, 1, aMatrix.Line1.Column2 );
2588 124 : aTempMatrix.set(0, 2, aMatrix.Line1.Column3 );
2589 124 : aTempMatrix.set(1, 0, aMatrix.Line2.Column1 );
2590 124 : aTempMatrix.set(1, 1, aMatrix.Line2.Column2 );
2591 124 : aTempMatrix.set(1, 2, aMatrix.Line2.Column3 );
2592 124 : aTempMatrix.set(2, 0, aMatrix.Line3.Column1 );
2593 124 : aTempMatrix.set(2, 1, aMatrix.Line3.Column2 );
2594 124 : aTempMatrix.set(2, 2, aMatrix.Line3.Column3 );
2595 : // #i73079#
2596 124 : aTempMatrix.translate( aTranslateDiff.X, aTranslateDiff.Y );
2597 124 : aMatrix.Line1.Column1 = aTempMatrix.get(0, 0);
2598 124 : aMatrix.Line1.Column2 = aTempMatrix.get(0, 1);
2599 124 : aMatrix.Line1.Column3 = aTempMatrix.get(0, 2);
2600 124 : aMatrix.Line2.Column1 = aTempMatrix.get(1, 0);
2601 124 : aMatrix.Line2.Column2 = aTempMatrix.get(1, 1);
2602 124 : aMatrix.Line2.Column3 = aTempMatrix.get(1, 2);
2603 124 : aMatrix.Line3.Column1 = aTempMatrix.get(2, 0);
2604 124 : aMatrix.Line3.Column2 = aTempMatrix.get(2, 1);
2605 124 : aMatrix.Line3.Column3 = aTempMatrix.get(2, 2);
2606 : }
2607 : }
2608 : }
2609 :
2610 690 : return aMatrix;
2611 : }
2612 :
2613 : /** method to adjust the positioning properties
2614 : #i31698#
2615 : */
2616 6 : void SwXShape::_AdjustPositionProperties( const awt::Point& rPosition )
2617 : {
2618 : // handle x-position
2619 : // #i35007# - no handling of x-position, if drawing
2620 : // object is anchored as-character, because it doesn't make sense.
2621 : text::TextContentAnchorType eTextAnchorType =
2622 6 : text::TextContentAnchorType_AT_PARAGRAPH;
2623 : {
2624 6 : uno::Any aAny = getPropertyValue( "AnchorType" );
2625 6 : aAny >>= eTextAnchorType;
2626 : }
2627 6 : if ( eTextAnchorType != text::TextContentAnchorType_AS_CHARACTER )
2628 : {
2629 : // determine current x-position
2630 6 : const OUString aHoriPosPropStr("HoriOrientPosition");
2631 12 : uno::Any aHoriPos( getPropertyValue( aHoriPosPropStr ) );
2632 6 : sal_Int32 dCurrX = 0;
2633 6 : aHoriPos >>= dCurrX;
2634 : // change x-position attribute, if needed
2635 6 : if ( dCurrX != rPosition.X )
2636 : {
2637 : // adjust x-position orientation to text::HoriOrientation::NONE, if needed
2638 : // Note: has to be done before setting x-position attribute
2639 6 : const OUString aHoriOrientPropStr("HoriOrient");
2640 12 : uno::Any aHoriOrient( getPropertyValue( aHoriOrientPropStr ) );
2641 : sal_Int16 eHoriOrient;
2642 6 : if (aHoriOrient >>= eHoriOrient) // may be void
2643 : {
2644 0 : if ( eHoriOrient != text::HoriOrientation::NONE )
2645 : {
2646 0 : eHoriOrient = text::HoriOrientation::NONE;
2647 0 : aHoriOrient <<= eHoriOrient;
2648 0 : setPropertyValue( aHoriOrientPropStr, aHoriOrient );
2649 : }
2650 : }
2651 : // set x-position attribute
2652 6 : aHoriPos <<= rPosition.X;
2653 12 : setPropertyValue( aHoriPosPropStr, aHoriPos );
2654 6 : }
2655 : }
2656 :
2657 : // handle y-position
2658 : {
2659 : // determine current y-position
2660 6 : const OUString aVertPosPropStr("VertOrientPosition");
2661 12 : uno::Any aVertPos( getPropertyValue( aVertPosPropStr ) );
2662 6 : sal_Int32 dCurrY = 0;
2663 6 : aVertPos >>= dCurrY;
2664 : // change y-position attribute, if needed
2665 6 : if ( dCurrY != rPosition.Y )
2666 : {
2667 : // adjust y-position orientation to text::VertOrientation::NONE, if needed
2668 : // Note: has to be done before setting y-position attribute
2669 6 : const OUString aVertOrientPropStr("VertOrient");
2670 12 : uno::Any aVertOrient( getPropertyValue( aVertOrientPropStr ) );
2671 : sal_Int16 eVertOrient;
2672 6 : if (aVertOrient >>= eVertOrient) // may be void
2673 : {
2674 0 : if ( eVertOrient != text::VertOrientation::NONE )
2675 : {
2676 0 : eVertOrient = text::VertOrientation::NONE;
2677 0 : aVertOrient <<= eVertOrient;
2678 0 : setPropertyValue( aVertOrientPropStr, aVertOrient );
2679 : }
2680 : }
2681 : // set y-position attribute
2682 6 : aVertPos <<= rPosition.Y;
2683 12 : setPropertyValue( aVertPosPropStr, aVertPos );
2684 6 : }
2685 : }
2686 6 : }
2687 :
2688 : /** method to convert start or end position of the drawing object to the
2689 : Writer specific position, which is the attribute position in layout direction
2690 : #i59051#
2691 : */
2692 0 : ::com::sun::star::awt::Point SwXShape::_ConvertStartOrEndPosToLayoutDir(
2693 : const ::com::sun::star::awt::Point& aStartOrEndPos )
2694 : {
2695 0 : awt::Point aConvertedPos( aStartOrEndPos );
2696 :
2697 0 : SvxShape* pSvxShape = GetSvxShape();
2698 : OSL_ENSURE( pSvxShape,
2699 : "<SwXShape::_ConvertStartOrEndPosToLayoutDir(..)> - no SvxShape found!");
2700 0 : if ( pSvxShape )
2701 : {
2702 0 : const SdrObject* pObj = pSvxShape->GetSdrObject();
2703 : OSL_ENSURE( pObj,
2704 : "<SwXShape::_ConvertStartOrEndPosToLayoutDir(..)> - no SdrObject found!");
2705 0 : if ( pObj )
2706 : {
2707 : // get position of object in Writer coordinate system.
2708 0 : awt::Point aPos( getPosition() );
2709 : // get position of object in Drawing layer coordinate system
2710 0 : const Point aTmpObjPos( pObj->GetSnapRect().TopLeft() );
2711 : const awt::Point aObjPos(
2712 0 : convertTwipToMm100( aTmpObjPos.X() - pObj->GetAnchorPos().X() ),
2713 0 : convertTwipToMm100( aTmpObjPos.Y() - pObj->GetAnchorPos().Y() ) );
2714 : // determine difference between these positions according to the
2715 : // Writer coordinate system
2716 0 : const awt::Point aTranslateDiff( aPos.X - aObjPos.X,
2717 0 : aPos.Y - aObjPos.Y );
2718 : // apply translation difference to transformation matrix.
2719 0 : if ( aTranslateDiff.X != 0 || aTranslateDiff.Y != 0 )
2720 : {
2721 0 : aConvertedPos.X = aConvertedPos.X + aTranslateDiff.X;
2722 0 : aConvertedPos.Y = aConvertedPos.Y + aTranslateDiff.Y;
2723 : }
2724 : }
2725 : }
2726 :
2727 0 : return aConvertedPos;
2728 : }
2729 :
2730 140 : ::com::sun::star::drawing::PolyPolygonBezierCoords SwXShape::_ConvertPolyPolygonBezierToLayoutDir(
2731 : const ::com::sun::star::drawing::PolyPolygonBezierCoords& aPath )
2732 : {
2733 140 : drawing::PolyPolygonBezierCoords aConvertedPath( aPath );
2734 :
2735 140 : SvxShape* pSvxShape = GetSvxShape();
2736 : OSL_ENSURE( pSvxShape,
2737 : "<SwXShape::_ConvertStartOrEndPosToLayoutDir(..)> - no SvxShape found!");
2738 140 : if ( pSvxShape )
2739 : {
2740 140 : const SdrObject* pObj = pSvxShape->GetSdrObject();
2741 : OSL_ENSURE( pObj,
2742 : "<SwXShape::_ConvertStartOrEndPosToLayoutDir(..)> - no SdrObject found!");
2743 140 : if ( pObj )
2744 : {
2745 : // get position of object in Writer coordinate system.
2746 140 : awt::Point aPos( getPosition() );
2747 : // get position of object in Drawing layer coordinate system
2748 140 : const Point aTmpObjPos( pObj->GetSnapRect().TopLeft() );
2749 : const awt::Point aObjPos(
2750 140 : convertTwipToMm100( aTmpObjPos.X() - pObj->GetAnchorPos().X() ),
2751 280 : convertTwipToMm100( aTmpObjPos.Y() - pObj->GetAnchorPos().Y() ) );
2752 : // determine difference between these positions according to the
2753 : // Writer coordinate system
2754 140 : const awt::Point aTranslateDiff( aPos.X - aObjPos.X,
2755 280 : aPos.Y - aObjPos.Y );
2756 : // apply translation difference to PolyPolygonBezier.
2757 140 : if ( aTranslateDiff.X != 0 || aTranslateDiff.Y != 0 )
2758 : {
2759 : const basegfx::B2DHomMatrix aMatrix(basegfx::tools::createTranslateB2DHomMatrix(
2760 5 : aTranslateDiff.X, aTranslateDiff.Y));
2761 :
2762 5 : const sal_Int32 nOuterSequenceCount(aConvertedPath.Coordinates.getLength());
2763 5 : drawing::PointSequence* pInnerSequence = aConvertedPath.Coordinates.getArray();
2764 10 : for(sal_Int32 a(0); a < nOuterSequenceCount; a++)
2765 : {
2766 5 : const sal_Int32 nInnerSequenceCount(pInnerSequence->getLength());
2767 5 : awt::Point* pArray = pInnerSequence->getArray();
2768 :
2769 59 : for(sal_Int32 b(0); b < nInnerSequenceCount; b++)
2770 : {
2771 54 : basegfx::B2DPoint aNewCoordinatePair(pArray->X, pArray->Y);
2772 54 : aNewCoordinatePair *= aMatrix;
2773 54 : pArray->X = basegfx::fround(aNewCoordinatePair.getX());
2774 54 : pArray->Y = basegfx::fround(aNewCoordinatePair.getY());
2775 54 : pArray++;
2776 54 : }
2777 5 : }
2778 : }
2779 : }
2780 : }
2781 :
2782 140 : return aConvertedPath;
2783 : }
2784 :
2785 494 : SwXGroupShape::SwXGroupShape(uno::Reference< XInterface > & xShape) :
2786 494 : SwXShape(xShape)
2787 : {
2788 : #if OSL_DEBUG_LEVEL > 0
2789 : uno::Reference<XShapes> xShapes(xShapeAgg, uno::UNO_QUERY);
2790 : OSL_ENSURE(xShapes.is(), "no SvxShape found or shape is not a group shape");
2791 : #endif
2792 494 : }
2793 :
2794 988 : SwXGroupShape::~SwXGroupShape()
2795 : {
2796 988 : }
2797 :
2798 40430 : uno::Any SwXGroupShape::queryInterface( const uno::Type& rType ) throw(uno::RuntimeException, std::exception)
2799 : {
2800 40430 : uno::Any aRet;
2801 40430 : if(rType == cppu::UnoType<XShapes>::get())
2802 418 : aRet <<= uno::Reference<XShapes>(this);
2803 : else
2804 40012 : aRet = SwXShape::queryInterface(rType);
2805 40430 : return aRet;
2806 : }
2807 :
2808 474304 : void SwXGroupShape::acquire( ) throw()
2809 : {
2810 474304 : SwXShape::acquire();
2811 474304 : }
2812 :
2813 474304 : void SwXGroupShape::release( ) throw()
2814 : {
2815 474304 : SwXShape::release();
2816 474304 : }
2817 :
2818 1632 : void SwXGroupShape::add( const uno::Reference< XShape >& xShape ) throw (uno::RuntimeException, std::exception)
2819 : {
2820 1632 : SolarMutexGuard aGuard;
2821 1632 : SvxShape* pSvxShape = GetSvxShape();
2822 1632 : SwFrameFormat* pFormat = GetFrameFormat();
2823 1632 : if(pSvxShape && pFormat)
2824 : {
2825 1632 : uno::Reference<XShapes> xShapes;
2826 1632 : if( xShapeAgg.is() )
2827 : {
2828 1632 : const uno::Type& rType = cppu::UnoType<XShapes>::get();
2829 1632 : uno::Any aAgg = xShapeAgg->queryAggregation( rType );
2830 1632 : aAgg >>= xShapes;
2831 : }
2832 1632 : if(xShapes.is())
2833 1632 : xShapes->add(xShape);
2834 : else
2835 0 : throw uno::RuntimeException();
2836 :
2837 3264 : uno::Reference<lang::XUnoTunnel> xTunnel(xShape, uno::UNO_QUERY);
2838 1632 : SwXShape* pSwShape = 0;
2839 1632 : if(xShape.is())
2840 : pSwShape = reinterpret_cast< SwXShape * >(
2841 1625 : sal::static_int_cast< sal_IntPtr >( xTunnel->getSomething(SwXShape::getUnoTunnelId()) ));
2842 1632 : if(pSwShape && pSwShape->m_bDescriptor)
2843 : {
2844 : SvxShape* pAddShape = reinterpret_cast< SvxShape * >(
2845 1625 : sal::static_int_cast< sal_IntPtr >( xTunnel->getSomething(SvxShape::getUnoTunnelId()) ));
2846 1625 : if(pAddShape)
2847 : {
2848 1625 : SdrObject* pObj = pAddShape->GetSdrObject();
2849 1625 : if(pObj)
2850 : {
2851 1625 : SwDoc* pDoc = pFormat->GetDoc();
2852 : // set layer of new drawing
2853 : // object to corresponding invisible layer.
2854 1625 : if( FmFormInventor != pObj->GetObjInventor())
2855 : {
2856 1625 : pObj->SetLayer( pSwShape->pImpl->GetOpaque()
2857 0 : ? pDoc->getIDocumentDrawModelAccess().GetInvisibleHeavenId()
2858 3250 : : pDoc->getIDocumentDrawModelAccess().GetInvisibleHellId() );
2859 : }
2860 : else
2861 : {
2862 0 : pObj->SetLayer(pDoc->getIDocumentDrawModelAccess().GetInvisibleControlsId());
2863 : }
2864 : }
2865 : }
2866 1625 : pSwShape->m_bDescriptor = false;
2867 : //add the group member to the format of the group
2868 1625 : SwFrameFormat* pShapeFormat = ::FindFrameFormat( pSvxShape->GetSdrObject() );
2869 1625 : if(pShapeFormat)
2870 1625 : pFormat->Add(pSwShape);
2871 1632 : }
2872 : }
2873 : else
2874 0 : throw uno::RuntimeException();
2875 1632 : }
2876 :
2877 210 : void SwXGroupShape::remove( const uno::Reference< XShape >& xShape ) throw (uno::RuntimeException, std::exception)
2878 : {
2879 210 : SolarMutexGuard aGuard;
2880 420 : uno::Reference<XShapes> xShapes;
2881 210 : if( xShapeAgg.is() )
2882 : {
2883 210 : const uno::Type& rType = cppu::UnoType<XShapes>::get();
2884 210 : uno::Any aAgg = xShapeAgg->queryAggregation( rType );
2885 210 : aAgg >>= xShapes;
2886 : }
2887 210 : if(!xShapes.is())
2888 0 : throw uno::RuntimeException();
2889 420 : xShapes->remove(xShape);
2890 210 : }
2891 :
2892 509 : sal_Int32 SwXGroupShape::getCount() throw( uno::RuntimeException, std::exception )
2893 : {
2894 509 : SolarMutexGuard aGuard;
2895 1018 : uno::Reference<XIndexAccess> xAcc;
2896 509 : if( xShapeAgg.is() )
2897 : {
2898 509 : const uno::Type& rType = cppu::UnoType<XIndexAccess>::get();
2899 509 : uno::Any aAgg = xShapeAgg->queryAggregation( rType );
2900 509 : aAgg >>= xAcc;
2901 : }
2902 509 : if(!xAcc.is())
2903 0 : throw uno::RuntimeException();
2904 1018 : return xAcc->getCount();
2905 : }
2906 :
2907 708 : uno::Any SwXGroupShape::getByIndex(sal_Int32 nIndex)
2908 : throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException,
2909 : uno::RuntimeException, std::exception )
2910 : {
2911 708 : SolarMutexGuard aGuard;
2912 1416 : uno::Reference<XIndexAccess> xAcc;
2913 708 : if( xShapeAgg.is() )
2914 : {
2915 708 : const uno::Type& rType = cppu::UnoType<XIndexAccess>::get();
2916 708 : uno::Any aAgg = xShapeAgg->queryAggregation( rType );
2917 708 : aAgg >>= xAcc;
2918 : }
2919 708 : if(!xAcc.is())
2920 0 : throw uno::RuntimeException();
2921 1416 : return xAcc->getByIndex(nIndex);
2922 : }
2923 :
2924 0 : uno::Type SwXGroupShape::getElementType( ) throw(uno::RuntimeException, std::exception)
2925 : {
2926 0 : SolarMutexGuard aGuard;
2927 0 : uno::Reference<XIndexAccess> xAcc;
2928 0 : if( xShapeAgg.is() )
2929 : {
2930 0 : const uno::Type& rType = cppu::UnoType<XIndexAccess>::get();
2931 0 : uno::Any aAgg = xShapeAgg->queryAggregation( rType );
2932 0 : aAgg >>= xAcc;
2933 : }
2934 0 : if(!xAcc.is())
2935 0 : throw uno::RuntimeException();
2936 0 : return xAcc->getElementType();
2937 : }
2938 :
2939 278 : sal_Bool SwXGroupShape::hasElements( ) throw(uno::RuntimeException, std::exception)
2940 : {
2941 278 : SolarMutexGuard aGuard;
2942 556 : uno::Reference<XIndexAccess> xAcc;
2943 278 : if( xShapeAgg.is() )
2944 : {
2945 278 : const uno::Type& rType = cppu::UnoType<XIndexAccess>::get();
2946 278 : uno::Any aAgg = xShapeAgg->queryAggregation( rType );
2947 278 : aAgg >>= xAcc;
2948 : }
2949 278 : if(!xAcc.is())
2950 0 : throw uno::RuntimeException();
2951 556 : return xAcc->hasElements();
2952 177 : }
2953 :
2954 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|