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