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