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