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