xref: /aoo41x/main/sw/source/core/unocore/unodraw.cxx (revision 5222b95b)
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 <list>
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:
SwShapeDescriptor_Impl()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 
~SwShapeDescriptor_Impl()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 	}
GetAnchor(sal_Bool bCreate=sal_False)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 		}
GetHOrient(sal_Bool bCreate=sal_False)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 		}
GetVOrient(sal_Bool bCreate=sal_False)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 
GetSurround(sal_Bool bCreate=sal_False)179 	SwFmtSurround*	GetSurround(sal_Bool bCreate = sal_False)
180 		{
181 			if(bCreate && !pSurround)
182 				pSurround = new SwFmtSurround();
183 			return pSurround;
184 		}
GetLRSpace(sal_Bool bCreate=sal_False)185 	SvxLRSpaceItem*	GetLRSpace(sal_Bool bCreate = sal_False)
186 		{
187 			if(bCreate && !pLRSpace)
188                 pLRSpace = new SvxLRSpaceItem(RES_LR_SPACE);
189 			return pLRSpace;
190 		}
GetULSpace(sal_Bool bCreate=sal_False)191 	SvxULSpaceItem*	GetULSpace(sal_Bool bCreate = sal_False)
192 		{
193 			if(bCreate && !pULSpace)
194                 pULSpace = new SvxULSpaceItem(RES_UL_SPACE);
195 			return pULSpace;
196 		}
GetTextRange()197     uno::Reference< text::XTextRange > &    GetTextRange()
198 	{
199 		return xTextRange;
200 	}
IsOpaque()201     sal_Bool    IsOpaque()
202 		{
203             return bOpaque;
204 		}
GetOpaque()205     const sal_Bool&    GetOpaque()
206 		{
207             return bOpaque;
208 		}
RemoveHOrient()209     void RemoveHOrient(){DELETEZ(pHOrient);}
RemoveVOrient()210 	void RemoveVOrient(){DELETEZ(pVOrient);}
RemoveAnchor()211 	void RemoveAnchor(){DELETEZ(pAnchor);}
RemoveSurround()212 	void RemoveSurround(){DELETEZ(pSurround);}
RemoveULSpace()213 	void RemoveULSpace(){DELETEZ(pULSpace);}
RemoveLRSpace()214 	void RemoveLRSpace(){DELETEZ(pLRSpace);}
SetOpaque(sal_Bool bSet)215     void SetOpaque(sal_Bool bSet){bOpaque = bSet;}
216 
217     // OD 2004-04-21 #i26791#
GetFollowTextFlow(sal_Bool _bCreate=sal_False)218     SwFmtFollowTextFlow* GetFollowTextFlow( sal_Bool _bCreate = sal_False )
219     {
220         if ( _bCreate && !mpFollowTextFlow )
221             mpFollowTextFlow = new SwFmtFollowTextFlow( sal_False );
222         return mpFollowTextFlow;
223     }
RemoveFollowTextFlow()224     void RemoveFollowTextFlow()
225     {
226         DELETEZ(mpFollowTextFlow);
227     }
228 
229     // --> OD 2004-08-06 #i28749#
GetPositionLayoutDir() const230     sal_Int16 GetPositionLayoutDir() const
231     {
232         return mnPositionLayoutDir;
233     }
SetPositionLayoutDir(sal_Int16 _nPositionLayoutDir)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     }
RemovePositionLayoutDir()251     void RemovePositionLayoutDir()
252     {
253         mnPositionLayoutDir = text::PositionLayoutDir::PositionInLayoutDirOfAnchor;
254     }
255     // <--
256 
257     // OD 2004-05-05 #i28701#
GetWrapInfluenceOnObjPos(const sal_Bool _bCreate=sal_False)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     }
RemoveWrapInfluenceOnObjPos()270     inline void RemoveWrapInfluenceOnObjPos()
271     {
272         DELETEZ(pWrapInfluenceOnObjPos);
273     }
274 };
275 /****************************************************************************
276 	class SwFmDrawPage
277 ****************************************************************************/
278 
SwFmDrawPage(SdrPage * pPage)279 SwFmDrawPage::SwFmDrawPage( SdrPage* pPage ) :
280 	SvxFmDrawPage( pPage ), pPageView(0)
281 {
282 }
283 
~SwFmDrawPage()284 SwFmDrawPage::~SwFmDrawPage() throw ()
285 {
286 	RemovePageView();
287 }
288 
PreGroup(const uno::Reference<drawing::XShapes> & xShapes)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 
PreUnGroup(const uno::Reference<drawing::XShapeGroup> xShapeGroup)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 
GetPageView()302 SdrPageView*	SwFmDrawPage::GetPageView()
303 {
304 	if(!pPageView)
305 		pPageView = mpView->ShowSdrPage( mpPage );
306 	return pPageView;
307 }
308 
RemovePageView()309 void	SwFmDrawPage::RemovePageView()
310 {
311 	if(pPageView && mpView)
312 		mpView->HideSdrPage();
313 	pPageView = 0;
314 }
315 
GetInterface(SdrObject * pObj)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 
_CreateSdrObject(const uno::Reference<drawing::XShape> & xShape)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 
_CreateShape(SdrObject * pObj) const339 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::list< ::com::sun::star::uno::Any > shapescontainer_t;
413             shapescontainer_t m_aShapes;
414         protected:
~SwXShapesEnumeration()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 
SwXShapesEnumeration(SwXDrawPage * const pDrawPage)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 
hasMoreElements(void)443 sal_Bool SwXShapesEnumeration::hasMoreElements(void) throw(uno::RuntimeException)
444 {
445 	vos::OGuard aGuard(Application::GetSolarMutex());
446     return !m_aShapes.empty();
447 }
448 
nextElement(void)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 
getImplementationName(void)459 OUString SwXShapesEnumeration::getImplementationName(void) throw(uno::RuntimeException)
460 {
461     return C2U("SwXShapeEnumeration");
462 }
463 
supportsService(const OUString & ServiceName)464 sal_Bool SwXShapesEnumeration::supportsService(const OUString& ServiceName) throw(uno::RuntimeException)
465 {
466     return C2U("com.sun.star.container.XEnumeration") == ServiceName;
467 }
468 
getSupportedServiceNames(void)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 ****************************************************************************/
createEnumeration(void)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 
getImplementationName(void)483 rtl::OUString SwXDrawPage::getImplementationName(void) throw( uno::RuntimeException )
484 {
485 	return C2U("SwXDrawPage");
486 }
487 
supportsService(const rtl::OUString & rServiceName)488 sal_Bool SwXDrawPage::supportsService(const rtl::OUString& rServiceName) throw( uno::RuntimeException )
489 {
490     return C2U("com.sun.star.drawing.GenericDrawPage") == rServiceName;
491 }
492 
getSupportedServiceNames(void)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 
SwXDrawPage(SwDoc * pDc)501 SwXDrawPage::SwXDrawPage(SwDoc* pDc) :
502 	pDoc(pDc),
503 	pDrawPage(0)
504 {
505 }
506 
~SwXDrawPage()507 SwXDrawPage::~SwXDrawPage()
508 {
509 	if(xPageAgg.is())
510 	{
511 		uno::Reference< uno::XInterface >  xInt;
512 		xPageAgg->setDelegator(xInt);
513 	}
514 }
515 
queryInterface(const uno::Type & aType)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 
getTypes()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 
getCount(void)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 
getByIndex(sal_Int32 nIndex)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 
getElementType(void)583 uno::Type  SwXDrawPage::getElementType(void) throw( uno::RuntimeException )
584 {
585 	return ::getCppuType((const uno::Reference<drawing::XShape>*)0);
586 }
587 
hasElements(void)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 
add(const uno::Reference<drawing::XShape> & xShape)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->InsertDrawObj( *pTemp, *pObj, aSet );
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 
remove(const uno::Reference<drawing::XShape> & xShape)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 
group(const uno::Reference<drawing::XShapes> & xShapes)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 
ungroup(const uno::Reference<drawing::XShapeGroup> & xShapeGroup)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 
GetSvxPage()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
InvalidateSwDoc()885 void SwXDrawPage::InvalidateSwDoc()
886 {
887     pDoc = 0;
888 }
889 
890 /****************************************************************************
891 
892 ****************************************************************************/
893 TYPEINIT1(SwXShape, SwClient);
894 
getUnoTunnelId()895 const uno::Sequence< sal_Int8 > & SwXShape::getUnoTunnelId()
896 {
897     static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
898 	return aSeq;
899 }
900 
getSomething(const uno::Sequence<sal_Int8> & rId)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 {
lcl_addShapePropertyEventFactories(SdrObject & _rObj,SwXShape & _rShape)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 
SwXShape(uno::Reference<uno::XInterface> & xShape)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 
AddExistingShapeToFmt(SdrObject & _rObj)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 
~SwXShape()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 
queryInterface(const uno::Type & aType)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 
getTypes()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 
getImplementationId()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 
getPropertySetInfo(void)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 
setPropertyValue(const rtl::OUString & rPropertyName,const uno::Any & aValue)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( RES_TXTATR_FLYCNT, nIdx );
1247                                 //create a new one
1248                                 SwTxtNode *pNd = pInternalPam->GetNode()->GetTxtNode();
1249                                 DBG_ASSERT( pNd, "Cursor not at TxtNode." );
1250                                 SwFmtFlyCnt aFmt( pFmt );
1251                                 pNd->InsertItem(aFmt, pInternalPam->GetPoint()
1252                                         ->nContent.GetIndex(), 0 );
1253                             }
1254                             else
1255                             {
1256                                 aAnchor.SetAnchor( pInternalPam->GetPoint() );
1257                                 aSet.Put(aAnchor);
1258                                 pFmt->SetFmtAttr(aSet);
1259                             }
1260                         }
1261                         else
1262                         {
1263                             throw uno::RuntimeException();
1264                         }
1265                         delete pInternalPam;
1266                     }
1267                 }
1268                 // --> OD 2004-08-06 #i28749#
1269                 else if ( FN_SHAPE_POSITION_LAYOUT_DIR == pEntry->nWID )
1270                 {
1271                     sal_Int16 nPositionLayoutDir = 0;
1272                     aValue >>= nPositionLayoutDir;
1273                     pFmt->SetPositionLayoutDir( nPositionLayoutDir );
1274                 }
1275                 // <--
1276                 else if( pDoc->GetCurrentLayout())	//swmod 080218
1277 				{
1278                     UnoActionContext aCtx(pDoc);
1279                     if(RES_ANCHOR == pEntry->nWID && MID_ANCHOR_ANCHORTYPE == pEntry->nMemberId)
1280                     {
1281                         SdrObject* pObj = pFmt->FindSdrObject();
1282                         SdrMarkList aList;
1283                         SdrMark aMark(pObj);
1284                         aList.InsertEntry(aMark);
1285                         sal_Int32 nAnchor = 0;
1286                         cppu::enum2int( nAnchor, aValue );
1287                         pDoc->ChgAnchor( aList, (RndStdIds)nAnchor,
1288                                                 sal_False, sal_True );
1289                     }
1290                     else
1291 					{
1292                         m_pPropSet->setPropertyValue(*pEntry, aValue, aSet);
1293                         pFmt->SetFmtAttr(aSet);
1294 					}
1295 				}
1296                 else
1297 				{
1298                     m_pPropSet->setPropertyValue( *pEntry, aValue, aSet );
1299 
1300                     if(RES_ANCHOR == pEntry->nWID && MID_ANCHOR_ANCHORTYPE == pEntry->nMemberId)
1301                     {
1302                         bool bSetAttr = true;
1303                         sal_Int32 eNewAnchor = SWUnoHelper::GetEnumAsInt32( aValue );
1304 
1305                         //if old anchor was in_cntnt the related text attribute has to be removed
1306                         const SwFmtAnchor& rOldAnchor = pFmt->GetAnchor();
1307                         RndStdIds eOldAnchorId = rOldAnchor.GetAnchorId();
1308                         SdrObject* pObj = pFmt->FindSdrObject();
1309                         SwFrmFmt *pFlyFmt = FindFrmFmt( pObj );
1310                         pFlyFmt->DelFrms();
1311                         if( text::TextContentAnchorType_AS_CHARACTER != eNewAnchor &&
1312                             (FLY_AS_CHAR == eOldAnchorId))
1313                         {
1314                             //With AnchorAsCharacter the current TxtAttribute has to be deleted.
1315                             //Tbis removes the frame format too.
1316                             //To prevent this the connection between format and attribute has to be broken before.
1317                             const SwPosition *pPos = rOldAnchor.GetCntntAnchor();
1318                             SwTxtNode *pTxtNode = pPos->nNode.GetNode().GetTxtNode();
1319                             ASSERT( pTxtNode->HasHints(), "Missing FlyInCnt-Hint." );
1320                             const xub_StrLen nIdx = pPos->nContent.GetIndex();
1321                             SwTxtAttr * const pHnt =
1322                                 pTxtNode->GetTxtAttrForCharAt(
1323                                     nIdx, RES_TXTATR_FLYCNT );
1324                             DBG_ASSERT( pHnt && pHnt->Which() == RES_TXTATR_FLYCNT,
1325                                         "Missing FlyInCnt-Hint." );
1326                             DBG_ASSERT( pHnt && pHnt->GetFlyCnt().GetFrmFmt() == pFlyFmt,
1327                                         "Wrong TxtFlyCnt-Hint." );
1328                             const_cast<SwFmtFlyCnt&>(pHnt->GetFlyCnt())
1329                                 .SetFlyFmt();
1330 
1331                             //The connection is removed now the attribute can be deleted.
1332                             pTxtNode->DeleteAttributes(RES_TXTATR_FLYCNT, nIdx);
1333                         }
1334                         else if( text::TextContentAnchorType_AT_PAGE != eNewAnchor &&
1335                                 (FLY_AT_PAGE == eOldAnchorId))
1336                         {
1337                             SwFmtAnchor aNewAnchor( dynamic_cast< const SwFmtAnchor& >( aSet.Get( RES_ANCHOR ) ) );
1338                             //if the fly has been anchored at page then it needs to be connected
1339                             //to the content position
1340                             SwPaM aPam(pDoc->GetNodes().GetEndOfContent());
1341                             if( pDoc->GetCurrentLayout() )
1342                             {
1343                                 SwCrsrMoveState aState( MV_SETONLYTEXT );
1344                                 Point aTmp( pObj->GetSnapRect().TopLeft() );
1345                                 pDoc->GetCurrentLayout()->GetCrsrOfst( aPam.GetPoint(), aTmp, &aState );
1346                             }
1347                             else
1348                             {
1349                                 //without access to the layout the last node of the body will be used as anchor position
1350                                 aPam.Move( fnMoveBackward, fnGoDoc );
1351                             }
1352                             //anchor position has to be inserted after the text attribute has been inserted
1353                             aNewAnchor.SetAnchor( aPam.GetPoint() );
1354                             aSet.Put( aNewAnchor );
1355                             pFmt->SetFmtAttr(aSet);
1356                             bSetAttr = false;
1357                             if( text::TextContentAnchorType_AS_CHARACTER == eNewAnchor &&
1358                                 (FLY_AS_CHAR != eOldAnchorId))
1359                             {
1360                                 //the RES_TXTATR_FLYCNT needs to be added now
1361                                 SwTxtNode *pNd = aPam.GetNode()->GetTxtNode();
1362                                 DBG_ASSERT( pNd, "Crsr is not in a TxtNode." );
1363                                 SwFmtFlyCnt aFmt( pFlyFmt );
1364                                 pNd->InsertItem(aFmt,
1365                                     aPam.GetPoint()->nContent.GetIndex(), 0 );
1366                                 //aPam.GetPoint()->nContent--;
1367 
1368                             }
1369                         }
1370                         if( bSetAttr )
1371                             pFmt->SetFmtAttr(aSet);
1372                     }
1373                     else
1374                         pFmt->SetFmtAttr(aSet);
1375 				}
1376 			}
1377 			else
1378 			{
1379 				SfxPoolItem* pItem = 0;
1380                 switch(pEntry->nWID)
1381 				{
1382 					case RES_ANCHOR:
1383 						pItem = pImpl->GetAnchor(sal_True);
1384 					break;
1385 					case RES_HORI_ORIENT:
1386 						pItem = pImpl->GetHOrient(sal_True);
1387 					break;
1388 					case RES_VERT_ORIENT:
1389 						pItem = pImpl->GetVOrient(sal_True);
1390 					break;
1391 					case  RES_LR_SPACE:
1392 						pItem = pImpl->GetLRSpace(sal_True);
1393 					break;
1394 					case  RES_UL_SPACE:
1395 						pItem = pImpl->GetULSpace(sal_True);
1396 					break;
1397 					case  RES_SURROUND:
1398 						pItem = pImpl->GetSurround(sal_True);
1399 					break;
1400 					case  FN_TEXT_RANGE:
1401 					{
1402                         const uno::Type rTextRangeType =
1403                             ::getCppuType((uno::Reference< text::XTextRange>*)0);
1404 						if(aValue.getValueType() == rTextRangeType)
1405 						{
1406                             uno::Reference< text::XTextRange > & rRange = pImpl->GetTextRange();
1407                             rRange = *(uno::Reference< text::XTextRange > *)aValue.getValue();
1408 						}
1409 					}
1410 					break;
1411                     case RES_OPAQUE :
1412                         pImpl->SetOpaque(*(sal_Bool*)aValue.getValue());
1413                     break;
1414                     // OD 2004-04-22 #i26791#
1415                     case RES_FOLLOW_TEXT_FLOW:
1416                     {
1417                         pItem = pImpl->GetFollowTextFlow( sal_True );
1418                     }
1419                     break;
1420                     // OD 2004-05-05 #i28701#
1421                     case RES_WRAP_INFLUENCE_ON_OBJPOS:
1422                     {
1423                         pItem = pImpl->GetWrapInfluenceOnObjPos( sal_True );
1424                     }
1425                     break;
1426                     // --> OD 2004-08-06 #i28749#
1427                     case FN_SHAPE_POSITION_LAYOUT_DIR :
1428                     {
1429                         sal_Int16 nPositionLayoutDir = 0;
1430                         aValue >>= nPositionLayoutDir;
1431                         pImpl->SetPositionLayoutDir( nPositionLayoutDir );
1432                     }
1433                     break;
1434                     // <--
1435                 }
1436                 if(pItem)
1437                     ((SfxPoolItem*)pItem)->PutValue(aValue, pEntry->nMemberId);
1438             }
1439         }
1440         else
1441         {
1442             uno::Reference< beans::XPropertySet >  xPrSet;
1443             const uno::Type& rPSetType =
1444                 ::getCppuType((const uno::Reference< beans::XPropertySet >*)0);
1445 			uno::Any aPSet = xShapeAgg->queryAggregation(rPSetType);
1446 			if(aPSet.getValueType() != rPSetType || !aPSet.getValue())
1447 				throw uno::RuntimeException();
1448             xPrSet = *(uno::Reference< beans::XPropertySet >*)aPSet.getValue();
1449             // --> OD 2004-08-05 #i31698# - setting the caption point of a
1450             // caption object doesn't have to change the object position.
1451             // Thus, keep the position, before the caption point is set and
1452             // restore it afterwards.
1453             awt::Point aKeepedPosition( 0, 0 );
1454             if ( rPropertyName.equals(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CaptionPoint"))) &&
1455                  getShapeType().equals(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.CaptionShape"))) )
1456             {
1457                     aKeepedPosition = getPosition();
1458             }
1459             // <--
1460             if( pFmt && pFmt->GetDoc()->GetCurrentViewShell() )	//swmod 071108//swmod 071225
1461 			{
1462 				UnoActionContext aCtx(pFmt->GetDoc());
1463                 xPrSet->setPropertyValue(rPropertyName, aValue);
1464 			}
1465 			else
1466                 xPrSet->setPropertyValue(rPropertyName, aValue);
1467             // --> OD 2004-11-11 #i35007# - adjustment of the position
1468             // attributes, if the transformation is set, causes wrong alignments
1469             // and is no longer needed.
1470             // The position attributes are set, if the drawing object is added
1471             // to the draw page - see <SwXDrawPage::add(..)> -  and on its first
1472             // positioning - see <SwAnchoredDrawObject::MakeObjPos().
1473 //            // --> OD 2004-07-28 #i31698# - additionally adjust the position
1474 //            // properties of the shape, if the transformation is set and
1475 //            // the shape isn't a group member.
1476 //            if ( rPropertyName.equals(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Transformation"))) &&
1477 //                 !_GetTopGroupObj() )
1478 //            {
1479 //                drawing::HomogenMatrix3 aMatrix;
1480 //                aValue >>= aMatrix;
1481 //                awt::Point aNewPos( basegfx::fround( aMatrix.Line1.Column3 ),
1482 //                                    basegfx::fround( aMatrix.Line2.Column3 ) );
1483 //                _AdjustPositionProperties( aNewPos );
1484 //            }
1485             // --> OD 2004-08-05 #i31698# - restore object position, if caption
1486             // point is set.
1487             if ( rPropertyName.equals(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CaptionPoint"))) &&
1488                  getShapeType().equals(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.CaptionShape"))) )
1489             {
1490                 setPosition( aKeepedPosition );
1491             }
1492 		}
1493 	}
1494 }
1495 
getPropertyValue(const rtl::OUString & rPropertyName)1496 uno::Any SwXShape::getPropertyValue(const rtl::OUString& rPropertyName)
1497     throw( beans::UnknownPropertyException, lang::WrappedTargetException,
1498            uno::RuntimeException )
1499 {
1500 	vos::OGuard  aGuard(Application::GetSolarMutex());
1501 	uno::Any aRet;
1502 	SwFrmFmt* 	pFmt = GetFrmFmt();
1503 	if(xShapeAgg.is())
1504 	{
1505         const SfxItemPropertySimpleEntry*  pEntry = m_pPropSet->getPropertyMap()->getByName( rPropertyName );
1506         if(pEntry)
1507 		{
1508 			if(pFmt)
1509 			{
1510                 if(RES_OPAQUE == pEntry->nWID)
1511                 {
1512                     SvxShape* pSvxShape = GetSvxShape();
1513                     DBG_ASSERT(pSvxShape, "No SvxShape found!");
1514                     if(pSvxShape)
1515                     {
1516                         SdrObject* pObj = pSvxShape->GetSdrObject();
1517                         // OD 02.07.2003 #108784# - consider invisible layers
1518                         sal_Bool bOpaque =
1519                             ( pObj->GetLayer() != pFmt->GetDoc()->GetHellId() &&
1520                               pObj->GetLayer() != pFmt->GetDoc()->GetInvisibleHellId() );
1521                         aRet.setValue(&bOpaque, ::getBooleanCppuType());
1522                     }
1523                 }
1524                 else if(FN_ANCHOR_POSITION == pEntry->nWID)
1525                 {
1526                     SvxShape* pSvxShape = GetSvxShape();
1527                     DBG_ASSERT(pSvxShape, "No SvxShape found!");
1528                     if(pSvxShape)
1529                     {
1530                         SdrObject* pObj = pSvxShape->GetSdrObject();
1531                         Point aPt = pObj->GetAnchorPos();
1532                         awt::Point aPoint( TWIP_TO_MM100( aPt.X() ),
1533                                            TWIP_TO_MM100( aPt.Y() ) );
1534                         aRet.setValue(&aPoint, ::getCppuType( (awt::Point*)0 ));
1535                     }
1536                 }
1537                 // OD 2004-04-22 #i26791# - special handling for FN_TEXT_RANGE
1538                 else if ( FN_TEXT_RANGE == pEntry->nWID )
1539                 {
1540                     const SwFmtAnchor aAnchor = pFmt->GetAnchor();
1541                     if (aAnchor.GetAnchorId() == FLY_AT_PAGE)
1542                     {
1543                         // return nothing, because property <TextRange> isn't
1544                         // valid for to-page anchored shapes
1545                         uno::Any aAny;
1546                         aRet = aAny;
1547                     }
1548                     else
1549                     {
1550                         if ( aAnchor.GetCntntAnchor() )
1551                         {
1552                             const uno::Reference< text::XTextRange > xTextRange
1553                                 = SwXTextRange::CreateXTextRange(
1554                                                     *pFmt->GetDoc(),
1555                                                     *aAnchor.GetCntntAnchor(),
1556                                                     0L );
1557                             aRet.setValue(&xTextRange, ::getCppuType((uno::Reference<text::XTextRange>*)0));
1558                         }
1559                         else
1560                         {
1561                             // return nothing
1562                             uno::Any aAny;
1563                             aRet = aAny;
1564                         }
1565                     }
1566                 }
1567                 // --> OD 2004-08-06 #i28749#
1568                 else if ( FN_SHAPE_TRANSFORMATION_IN_HORI_L2R == pEntry->nWID )
1569                 {
1570                     // get property <::drawing::Shape::Transformation>
1571                     // without conversion to layout direction as below
1572                     aRet = _getPropAtAggrObj( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Transformation")) );
1573                 }
1574                 else if ( FN_SHAPE_POSITION_LAYOUT_DIR == pEntry->nWID )
1575                 {
1576                     aRet <<= pFmt->GetPositionLayoutDir();
1577                 }
1578                 // <--
1579                 // --> OD 2004-10-28 #i36248#
1580                 else if ( FN_SHAPE_STARTPOSITION_IN_HORI_L2R == pEntry->nWID )
1581                 {
1582                     // get property <::drawing::Shape::StartPosition>
1583                     // without conversion to layout direction as below
1584                     aRet = _getPropAtAggrObj( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StartPosition")) );
1585                 }
1586                 else if ( FN_SHAPE_ENDPOSITION_IN_HORI_L2R == pEntry->nWID )
1587                 {
1588                     // get property <::drawing::Shape::EndPosition>
1589                     // without conversion to layout direction as below
1590                     aRet = _getPropAtAggrObj( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EndPosition")) );
1591                 }
1592                 // <--
1593                 else
1594                 {
1595                     const SwAttrSet& rSet = pFmt->GetAttrSet();
1596                     m_pPropSet->getPropertyValue(*pEntry, rSet, aRet);
1597                 }
1598 			}
1599 			else
1600 			{
1601 				SfxPoolItem* pItem = 0;
1602                 switch(pEntry->nWID)
1603 				{
1604 					case RES_ANCHOR:
1605 						pItem = pImpl->GetAnchor();
1606 					break;
1607 					case RES_HORI_ORIENT:
1608 						pItem = pImpl->GetHOrient();
1609 					break;
1610 					case RES_VERT_ORIENT:
1611 						pItem = pImpl->GetVOrient();
1612 					break;
1613 					case  RES_LR_SPACE:
1614 						pItem = pImpl->GetLRSpace();
1615 					break;
1616 					case  RES_UL_SPACE:
1617 						pItem = pImpl->GetULSpace();
1618 					break;
1619 					case  RES_SURROUND:
1620 						pItem = pImpl->GetSurround();
1621 					break;
1622 					case FN_TEXT_RANGE :
1623                         aRet.setValue(&pImpl->GetTextRange(), ::getCppuType((uno::Reference<text::XTextRange>*)0));
1624 					break;
1625                     case RES_OPAQUE :
1626                         aRet.setValue(&pImpl->GetOpaque(), ::getBooleanCppuType());
1627                     break;
1628                     case FN_ANCHOR_POSITION :
1629                     {
1630                         awt::Point aPoint;
1631                         aRet.setValue(&aPoint, ::getCppuType( (awt::Point*)0 ));
1632                     }
1633                     break;
1634                     // OD 2004-04-22 #i26791#
1635                     case RES_FOLLOW_TEXT_FLOW :
1636                     {
1637                         pItem = pImpl->GetFollowTextFlow();
1638                     }
1639                     break;
1640                     // OD 2004-05-05 #i28701#
1641                     case RES_WRAP_INFLUENCE_ON_OBJPOS:
1642                     {
1643                         pItem = pImpl->GetWrapInfluenceOnObjPos();
1644                     }
1645                     break;
1646                     // --> OD 2004-08-06 #i28749#
1647                     case FN_SHAPE_TRANSFORMATION_IN_HORI_L2R:
1648                     {
1649                         // get property <::drawing::Shape::Transformation>
1650                         // without conversion to layout direction as below
1651                         aRet = _getPropAtAggrObj( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Transformation")) );
1652                     }
1653                     break;
1654                     case FN_SHAPE_POSITION_LAYOUT_DIR:
1655                     {
1656                         aRet <<= pImpl->GetPositionLayoutDir();
1657                     }
1658                     break;
1659                     // <--
1660                     // --> OD 2004-08-06 #i36248#
1661                     case FN_SHAPE_STARTPOSITION_IN_HORI_L2R:
1662                     {
1663                         // get property <::drawing::Shape::StartPosition>
1664                         // without conversion to layout direction as below
1665                         aRet = _getPropAtAggrObj( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StartPosition")) );
1666                     }
1667                     break;
1668                     case FN_SHAPE_ENDPOSITION_IN_HORI_L2R:
1669                     {
1670                         // get property <::drawing::Shape::StartPosition>
1671                         // without conversion to layout direction as below
1672                         aRet = _getPropAtAggrObj( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EndPosition")) );
1673                     }
1674                     break;
1675                     // <--
1676                 }
1677                 if(pItem)
1678                     pItem->QueryValue(aRet, pEntry->nMemberId);
1679             }
1680         }
1681         else
1682         {
1683             aRet = _getPropAtAggrObj( rPropertyName );
1684 
1685             // --> OD 2004-07-28 #i31698# - convert the position (translation)
1686             // of the drawing object in the transformation
1687             if ( rPropertyName.equals(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Transformation"))) )
1688             {
1689                 drawing::HomogenMatrix3 aMatrix;
1690                 aRet >>= aMatrix;
1691                 aRet <<= _ConvertTransformationToLayoutDir( aMatrix );
1692             }
1693             // <--
1694             // --> OD 2004-10-28 #i36248#
1695             else if ( rPropertyName.equals(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StartPosition"))) )
1696             {
1697                 awt::Point aStartPos;
1698                 aRet >>= aStartPos;
1699                 // --> OD 2009-01-12 #i59051#
1700                 aRet <<= _ConvertStartOrEndPosToLayoutDir( aStartPos );
1701                 // <--
1702             }
1703             else if ( rPropertyName.equals(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EndPosition"))) )
1704             {
1705                 awt::Point aEndPos;
1706                 aRet >>= aEndPos;
1707                 // --> OD 2009-01-12 #i59051#
1708                 aRet <<= _ConvertStartOrEndPosToLayoutDir( aEndPos );
1709                 // <--
1710             }
1711             // --> OD 2009-01-16 #i59051#
1712             else if ( rPropertyName.equals(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PolyPolygonBezier"))) )
1713             {
1714                 drawing::PolyPolygonBezierCoords aPath;
1715                 aRet >>= aPath;
1716                 aRet <<= _ConvertPolyPolygonBezierToLayoutDir( aPath );
1717                 // <--
1718             }
1719             // <--
1720         }
1721 	}
1722 	return aRet;
1723 }
1724 
_getPropAtAggrObj(const::rtl::OUString & _rPropertyName)1725 uno::Any SwXShape::_getPropAtAggrObj( const ::rtl::OUString& _rPropertyName )
1726     throw( beans::UnknownPropertyException, lang::WrappedTargetException,
1727            uno::RuntimeException )
1728 {
1729     uno::Any aRet;
1730 
1731     uno::Reference< beans::XPropertySet >  xPrSet;
1732     const uno::Type& rPSetType =
1733                 ::getCppuType((const uno::Reference< beans::XPropertySet >*)0);
1734     uno::Any aPSet = xShapeAgg->queryAggregation(rPSetType);
1735     if ( aPSet.getValueType() != rPSetType || !aPSet.getValue() )
1736     {
1737         throw uno::RuntimeException();
1738     }
1739     xPrSet = *(uno::Reference< beans::XPropertySet >*)aPSet.getValue();
1740     aRet = xPrSet->getPropertyValue( _rPropertyName );
1741 
1742     return aRet;
1743 }
1744 
1745 
getPropertyState(const rtl::OUString & rPropertyName)1746 beans::PropertyState SwXShape::getPropertyState( const rtl::OUString& rPropertyName )
1747     throw(beans::UnknownPropertyException, uno::RuntimeException)
1748 {
1749 	vos::OGuard  aGuard(Application::GetSolarMutex());
1750     uno::Sequence< rtl::OUString > aNames(1);
1751     rtl::OUString* pStrings = aNames.getArray();
1752 	pStrings[0] = rPropertyName;
1753     uno::Sequence< beans::PropertyState > aStates = getPropertyStates(aNames);
1754 	return aStates.getConstArray()[0];
1755 }
1756 
getPropertyStates(const uno::Sequence<rtl::OUString> & aPropertyNames)1757 uno::Sequence< beans::PropertyState > SwXShape::getPropertyStates(
1758     const uno::Sequence< rtl::OUString >& aPropertyNames )
1759         throw(beans::UnknownPropertyException, uno::RuntimeException)
1760 {
1761 	vos::OGuard  aGuard(Application::GetSolarMutex());
1762 	SwFrmFmt* 	pFmt = GetFrmFmt();
1763     uno::Sequence< beans::PropertyState > aRet(aPropertyNames.getLength());
1764 	if(xShapeAgg.is())
1765 	{
1766         SvxShape* pSvxShape = GetSvxShape();
1767         sal_Bool bGroupMember = sal_False;
1768         sal_Bool bFormControl = sal_False;
1769         SdrObject* pObject = pSvxShape->GetSdrObject();
1770         if(pObject)
1771         {
1772             bGroupMember = pObject->GetUpGroup() != 0;
1773             bFormControl = pObject->GetObjInventor() == FmFormInventor;
1774         }
1775         const rtl::OUString* pNames = aPropertyNames.getConstArray();
1776         beans::PropertyState* pRet = aRet.getArray();
1777         uno::Reference< XPropertyState >  xShapePrState;
1778 		for(sal_Int32 nProperty = 0; nProperty < aPropertyNames.getLength(); nProperty++)
1779 		{
1780             const SfxItemPropertySimpleEntry*  pEntry = m_pPropSet->getPropertyMap()->getByName( pNames[nProperty] );
1781             if(pEntry)
1782 			{
1783                 if(RES_OPAQUE == pEntry->nWID)
1784                     pRet[nProperty] = bFormControl ?
1785                         beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
1786                 else if(FN_ANCHOR_POSITION == pEntry->nWID)
1787                     pRet[nProperty] = beans::PropertyState_DIRECT_VALUE;
1788                 else if(FN_TEXT_RANGE == pEntry->nWID)
1789                     pRet[nProperty] = beans::PropertyState_DIRECT_VALUE;
1790                 else if(bGroupMember)
1791                     pRet[nProperty] = beans::PropertyState_DEFAULT_VALUE;
1792                 else if(pFmt)
1793 				{
1794                     const SwAttrSet& rSet = pFmt->GetAttrSet();
1795                     SfxItemState eItemState = rSet.GetItemState(pEntry->nWID, sal_False);
1796 
1797                     if(SFX_ITEM_SET == eItemState)
1798                         pRet[nProperty] = beans::PropertyState_DIRECT_VALUE;
1799                     else if(SFX_ITEM_DEFAULT == eItemState)
1800                         pRet[nProperty] = beans::PropertyState_DEFAULT_VALUE;
1801                     else
1802                         pRet[nProperty] = beans::PropertyState_AMBIGUOUS_VALUE;
1803 				}
1804 				else
1805 				{
1806 					SfxPoolItem* pItem = 0;
1807                     switch(pEntry->nWID)
1808 					{
1809 						case RES_ANCHOR:
1810 							pItem = pImpl->GetAnchor();
1811 						break;
1812 						case RES_HORI_ORIENT:
1813 							pItem = pImpl->GetHOrient();
1814 						break;
1815 						case RES_VERT_ORIENT:
1816 							pItem = pImpl->GetVOrient();
1817 						break;
1818 						case  RES_LR_SPACE:
1819 							pItem = pImpl->GetLRSpace();
1820 						break;
1821 						case  RES_UL_SPACE:
1822 							pItem = pImpl->GetULSpace();
1823 						break;
1824 						case  RES_SURROUND:
1825 							pItem = pImpl->GetSurround();
1826 						break;
1827                         // OD 2004-05-05 #i28701#
1828                         case RES_WRAP_INFLUENCE_ON_OBJPOS:
1829                         {
1830                             pItem = pImpl->GetWrapInfluenceOnObjPos();
1831                         }
1832                         break;
1833                     }
1834 					if(pItem)
1835                         pRet[nProperty] = beans::PropertyState_DIRECT_VALUE;
1836 					else
1837                         pRet[nProperty] = beans::PropertyState_DEFAULT_VALUE;
1838 				}
1839 			}
1840 			else
1841 			{
1842 				if(!xShapePrState.is())
1843 				{
1844                     const uno::Type& rPStateType = ::getCppuType((uno::Reference< XPropertyState >*)0);
1845 					uno::Any aPState = xShapeAgg->queryAggregation(rPStateType);
1846 					if(aPState.getValueType() != rPStateType || !aPState.getValue())
1847 						throw uno::RuntimeException();
1848                     xShapePrState = *(uno::Reference< XPropertyState >*)aPState.getValue();
1849 				}
1850 				pRet[nProperty] = xShapePrState->getPropertyState(pNames[nProperty]);
1851 			}
1852 		}
1853 	}
1854 	else
1855         throw uno::RuntimeException();
1856 	return aRet;
1857 }
1858 
setPropertyToDefault(const rtl::OUString & rPropertyName)1859 void SwXShape::setPropertyToDefault( const rtl::OUString& rPropertyName )
1860     throw(beans::UnknownPropertyException, uno::RuntimeException)
1861 {
1862 	vos::OGuard  aGuard(Application::GetSolarMutex());
1863 	SwFrmFmt* 	pFmt = GetFrmFmt();
1864 	if(xShapeAgg.is())
1865 	{
1866         const SfxItemPropertySimpleEntry*  pEntry = m_pPropSet->getPropertyMap()->getByName( rPropertyName );
1867         if(pEntry)
1868 		{
1869             if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
1870                 throw uno::RuntimeException( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
1871 			if(pFmt)
1872 			{
1873 				const SfxItemSet& rSet = pFmt->GetAttrSet();
1874                 SfxItemSet aSet(pFmt->GetDoc()->GetAttrPool(), pEntry->nWID, pEntry->nWID);
1875 				aSet.SetParent(&rSet);
1876                 aSet.ClearItem(pEntry->nWID);
1877 				pFmt->GetDoc()->SetAttr(aSet, *pFmt);
1878 			}
1879 			else
1880 			{
1881                 switch(pEntry->nWID)
1882 				{
1883 					case RES_ANCHOR:		pImpl->RemoveAnchor(); 	break;
1884 					case RES_HORI_ORIENT: 	pImpl->RemoveHOrient(); break;
1885 					case RES_VERT_ORIENT:	pImpl->RemoveVOrient();	break;
1886 					case  RES_LR_SPACE:		pImpl->RemoveLRSpace();	break;
1887 					case  RES_UL_SPACE:		pImpl->RemoveULSpace();	break;
1888 					case  RES_SURROUND:		pImpl->RemoveSurround();break;
1889                     case RES_OPAQUE :       pImpl->SetOpaque(sal_False);  break;
1890                     case FN_TEXT_RANGE :
1891 					break;
1892                     // OD 2004-04-22 #i26791#
1893                     case RES_FOLLOW_TEXT_FLOW:
1894                     {
1895                         pImpl->RemoveFollowTextFlow();
1896                     }
1897                     break;
1898                     // OD 2004-05-05 #i28701#
1899                     case RES_WRAP_INFLUENCE_ON_OBJPOS:
1900                     {
1901                         pImpl->RemoveWrapInfluenceOnObjPos();
1902                     }
1903                     break;
1904 				}
1905 			}
1906 		}
1907 		else
1908 		{
1909             const uno::Type& rPStateType = ::getCppuType((uno::Reference< XPropertyState >*)0);
1910 			uno::Any aPState = xShapeAgg->queryAggregation(rPStateType);
1911 			if(aPState.getValueType() != rPStateType || !aPState.getValue())
1912 				throw uno::RuntimeException();
1913             uno::Reference< XPropertyState > xShapePrState = *(uno::Reference< XPropertyState >*)aPState.getValue();
1914 			xShapePrState->setPropertyToDefault( rPropertyName );
1915 		}
1916 	}
1917 	else
1918         throw uno::RuntimeException();
1919 }
1920 
getPropertyDefault(const rtl::OUString & rPropertyName)1921 uno::Any SwXShape::getPropertyDefault( const rtl::OUString& rPropertyName )
1922     throw( beans::UnknownPropertyException, lang::WrappedTargetException,
1923            uno::RuntimeException )
1924 {
1925 	vos::OGuard  aGuard(Application::GetSolarMutex());
1926 	SwFrmFmt* 	pFmt = GetFrmFmt();
1927     uno::Any aRet;
1928 	if(xShapeAgg.is())
1929 	{
1930         const SfxItemPropertySimpleEntry*  pEntry = m_pPropSet->getPropertyMap()->getByName( rPropertyName );
1931         if(pEntry)
1932 		{
1933             if(pEntry->nWID < RES_FRMATR_END && pFmt)
1934 			{
1935 				const SfxPoolItem& rDefItem =
1936                     pFmt->GetDoc()->GetAttrPool().GetDefaultItem(pEntry->nWID);
1937                 rDefItem.QueryValue(aRet, pEntry->nMemberId);
1938 			}
1939 			else
1940                 throw uno::RuntimeException();
1941 		}
1942 		else
1943 		{
1944             const uno::Type& rPStateType = ::getCppuType((uno::Reference< XPropertyState >*)0);
1945 			uno::Any aPState = xShapeAgg->queryAggregation(rPStateType);
1946 			if(aPState.getValueType() != rPStateType || !aPState.getValue())
1947 				throw uno::RuntimeException();
1948             uno::Reference< XPropertyState > xShapePrState = *(uno::Reference< XPropertyState >*)aPState.getValue();
1949 			xShapePrState->getPropertyDefault( rPropertyName );
1950 		}
1951 	}
1952 	else
1953         throw uno::RuntimeException();
1954 	return aRet;
1955 }
1956 
addPropertyChangeListener(const rtl::OUString & _propertyName,const uno::Reference<beans::XPropertyChangeListener> & _listener)1957 void SwXShape::addPropertyChangeListener(
1958     const rtl::OUString& _propertyName,
1959     const uno::Reference< beans::XPropertyChangeListener > & _listener )
1960     throw( beans::UnknownPropertyException, lang::WrappedTargetException,
1961            uno::RuntimeException )
1962 {
1963     if ( !xShapeAgg.is() )
1964         throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "no shape aggregate" ) ), *this );
1965 
1966     // must be handled by the aggregate
1967     uno::Reference< beans::XPropertySet > xShapeProps;
1968     if ( xShapeAgg->queryAggregation( beans::XPropertySet::static_type() ) >>= xShapeProps )
1969         xShapeProps->addPropertyChangeListener( _propertyName, _listener );
1970 }
1971 
removePropertyChangeListener(const rtl::OUString & _propertyName,const uno::Reference<beans::XPropertyChangeListener> & _listener)1972 void SwXShape::removePropertyChangeListener(
1973     const rtl::OUString& _propertyName,
1974     const uno::Reference< beans::XPropertyChangeListener > & _listener)
1975     throw( beans::UnknownPropertyException, lang::WrappedTargetException,
1976            uno::RuntimeException )
1977 {
1978     if ( !xShapeAgg.is() )
1979         throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "no shape aggregate" ) ), *this );
1980 
1981     // must be handled by the aggregate
1982     uno::Reference< beans::XPropertySet > xShapeProps;
1983     if ( xShapeAgg->queryAggregation( beans::XPropertySet::static_type() ) >>= xShapeProps )
1984         xShapeProps->removePropertyChangeListener( _propertyName, _listener );
1985 }
1986 
addVetoableChangeListener(const rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)1987 void SwXShape::addVetoableChangeListener(
1988     const rtl::OUString& /*PropertyName*/,
1989     const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/ )
1990     throw( beans::UnknownPropertyException, lang::WrappedTargetException,
1991            uno::RuntimeException )
1992 {
1993 	DBG_WARNING("not implemented");
1994 }
1995 
removeVetoableChangeListener(const rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)1996 void SwXShape::removeVetoableChangeListener(
1997     const rtl::OUString& /*PropertyName*/,
1998     const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/)
1999     throw( beans::UnknownPropertyException, lang::WrappedTargetException,
2000            uno::RuntimeException )
2001 {
2002 	DBG_WARNING("not implemented");
2003 }
2004 
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)2005 void SwXShape::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
2006 {
2007 	ClientModify(this, pOld, pNew);
2008 }
2009 
attach(const uno::Reference<text::XTextRange> & xTextRange)2010 void SwXShape::attach(const uno::Reference< text::XTextRange > & xTextRange)
2011     throw( lang::IllegalArgumentException, uno::RuntimeException )
2012 {
2013 	vos::OGuard  aGuard(Application::GetSolarMutex());
2014 
2015     // get access to SwDoc
2016     // (see also SwXTextRange::XTextRangeToSwPaM)
2017     SwDoc*      pDoc = 0;
2018     uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
2019     if(xRangeTunnel.is())
2020 	{
2021         SwXTextRange* pRange = 0;
2022         OTextCursorHelper* pCursor = 0;
2023         SwXTextPortion* pPortion = 0;
2024         SwXText* pText = 0;
2025         SwXParagraph* pParagraph = 0;
2026 
2027 		pRange 	= reinterpret_cast< SwXTextRange * >(
2028 				sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXTextRange::getUnoTunnelId()) ));
2029         pText 	= reinterpret_cast< SwXText * >(
2030 				sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXText::getUnoTunnelId()) ));
2031         pCursor = reinterpret_cast< OTextCursorHelper * >(
2032 				sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( OTextCursorHelper::getUnoTunnelId()) ));
2033         pPortion = reinterpret_cast< SwXTextPortion * >(
2034 				sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXTextPortion::getUnoTunnelId()) ));
2035         pParagraph = reinterpret_cast< SwXParagraph * >(
2036                 sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXParagraph::getUnoTunnelId( ) ) ) );
2037 
2038         if (pRange)
2039             pDoc = pRange->GetDoc();
2040         else if (!pDoc && pText)
2041             pDoc = pText->GetDoc();
2042         else if (!pDoc && pCursor)
2043             pDoc = pCursor->GetDoc();
2044         else if ( !pDoc && pPortion && pPortion->GetCursor() )
2045         {
2046             pDoc = pPortion->GetCursor()->GetDoc();
2047         }
2048         else if ( !pDoc && pParagraph && pParagraph->GetTxtNode( ) )
2049         {
2050             pDoc = const_cast<SwDoc*>(pParagraph->GetTxtNode()->GetDoc());
2051         }
2052 
2053     }
2054 
2055     if(!pDoc)
2056 		throw uno::RuntimeException();
2057     SwDocShell *pDocSh = pDoc->GetDocShell();
2058     if (pDocSh)
2059     {
2060         uno::Reference< frame::XModel > xModel;
2061         xModel = pDocSh->GetModel();
2062         uno::Reference< drawing::XDrawPageSupplier > xDPS(xModel, uno::UNO_QUERY);
2063         if (xDPS.is())
2064         {
2065             uno::Reference< drawing::XDrawPage > xDP( xDPS->getDrawPage() );
2066             if (xDP.is())
2067             {
2068                 uno::Any aPos;
2069                 aPos <<= xTextRange;
2070                 setPropertyValue( C2U("TextRange"), aPos);
2071                 uno::Reference< drawing::XShape > xTemp( (cppu::OWeakObject*) this, uno::UNO_QUERY );
2072                 xDP->add( xTemp );
2073             }
2074         }
2075     }
2076 }
2077 
getAnchor(void)2078 uno::Reference< text::XTextRange >  SwXShape::getAnchor(void) throw( uno::RuntimeException )
2079 {
2080 	vos::OGuard  aGuard(Application::GetSolarMutex());
2081     uno::Reference< text::XTextRange >  aRef;
2082 	SwFrmFmt* pFmt = GetFrmFmt();
2083 	if(pFmt)
2084 	{
2085         const SwFmtAnchor& rAnchor = pFmt->GetAnchor();
2086         // return an anchor for non-page bound frames
2087         // and for page bound frames that have a page no == NULL and a content position
2088         if ((rAnchor.GetAnchorId() != FLY_AT_PAGE) ||
2089             (rAnchor.GetCntntAnchor() && !rAnchor.GetPageNum()))
2090 		{
2091 			const SwPosition &rPos = *(pFmt->GetAnchor().GetCntntAnchor());
2092             aRef = SwXTextRange::CreateXTextRange(*pFmt->GetDoc(), rPos, 0);
2093 		}
2094 	}
2095 	else
2096 		aRef = pImpl->GetTextRange();
2097 	return aRef;
2098 }
2099 
dispose(void)2100 void SwXShape::dispose(void) throw( uno::RuntimeException )
2101 {
2102 	vos::OGuard  aGuard(Application::GetSolarMutex());
2103 	SwFrmFmt* pFmt = GetFrmFmt();
2104 	if(pFmt)
2105 	{
2106         // OD 10.07.2003 #110742# - determine correct <SdrObject>
2107         //SdrObject* pObj = pFmt->FindSdrObject();
2108         SdrObject* pObj = GetSvxShape()->GetSdrObject();
2109         // OD 10.07.2003 #110742# - safety assertion:
2110         // <pObj> must be the same as <pFmt->FindSdrObject()>, if <pObj> isn't
2111         // a 'virtual' drawing object.
2112         // OD 25.08.2003 #111713# - refine assertion for safety reason.
2113         // --> OD 2005-02-02 #119236# - correct assertion and refine it.
2114         ASSERT( !pObj ||
2115                 pObj->ISA(SwDrawVirtObj) ||
2116                 pObj->GetUpGroup() ||
2117                 pObj == pFmt->FindSdrObject(),
2118                 "<SwXShape::dispose(..) - different 'master' drawing objects!!" );
2119         // <--
2120         // OD 10.07.2003 #110742# - perform delete of draw frame format *not*
2121         // for 'virtual' drawing objects.
2122         // --> OD 2005-02-02 #119236# - no delete of draw format for members
2123         // of a group
2124         if ( pObj &&
2125              !pObj->ISA(SwDrawVirtObj) &&
2126              !pObj->GetUpGroup() &&
2127              pObj->IsInserted() )
2128         // <--
2129         {
2130             if (pFmt->GetAnchor().GetAnchorId() == FLY_AS_CHAR)
2131             {
2132                 const SwPosition &rPos = *(pFmt->GetAnchor().GetCntntAnchor());
2133                 SwTxtNode *pTxtNode = rPos.nNode.GetNode().GetTxtNode();
2134                 const xub_StrLen nIdx = rPos.nContent.GetIndex();
2135                 pTxtNode->DeleteAttributes( RES_TXTATR_FLYCNT, nIdx );
2136             }
2137             else
2138                 pFmt->GetDoc()->DelLayoutFmt( pFmt );
2139         }
2140     }
2141     if(xShapeAgg.is())
2142     {
2143         uno::Any aAgg(xShapeAgg->queryAggregation( ::getCppuType((uno::Reference<XComponent>*)0)));
2144         uno::Reference<XComponent> xComp;
2145         aAgg >>= xComp;
2146         if(xComp.is())
2147             xComp->dispose();
2148     }
2149 }
2150 
addEventListener(const uno::Reference<lang::XEventListener> & aListener)2151 void SwXShape::addEventListener(
2152                     const uno::Reference< lang::XEventListener > & aListener)
2153                     throw( uno::RuntimeException )
2154 {
2155     uno::Reference< lang::XUnoTunnel > xShapeTunnel(xShapeAgg, uno::UNO_QUERY);
2156 	SvxShape* pSvxShape = GetSvxShape();
2157 	if(pSvxShape)
2158  		pSvxShape->addEventListener(aListener);
2159 }
2160 
removeEventListener(const uno::Reference<lang::XEventListener> & aListener)2161 void SwXShape::removeEventListener(
2162                     const uno::Reference< lang::XEventListener > & aListener)
2163                     throw( uno::RuntimeException )
2164 {
2165 	SvxShape* pSvxShape = GetSvxShape();
2166 	if(pSvxShape)
2167 		pSvxShape->removeEventListener(aListener);
2168 }
2169 
getImplementationName(void)2170 rtl::OUString SwXShape::getImplementationName(void) throw( uno::RuntimeException )
2171 {
2172 	return C2U("SwXShape");
2173 }
2174 
supportsService(const rtl::OUString & rServiceName)2175 sal_Bool SwXShape::supportsService(const rtl::OUString& rServiceName) throw( uno::RuntimeException )
2176 {
2177 	sal_Bool bRet = sal_False;
2178 	if(COMPARE_EQUAL == rServiceName.compareToAscii("com.sun.star.drawing.Shape"))
2179 		bRet = sal_True;
2180 	else if(xShapeAgg.is())
2181 	{
2182         uno::Reference< lang::XUnoTunnel > xShapeTunnel(xShapeAgg, uno::UNO_QUERY);
2183 		SvxShape* pSvxShape = GetSvxShape();
2184 		bRet = pSvxShape->supportsService(rServiceName);
2185 	}
2186 	return bRet;
2187 }
2188 
getSupportedServiceNames(void)2189 uno::Sequence< rtl::OUString > SwXShape::getSupportedServiceNames(void) throw( uno::RuntimeException )
2190 {
2191     uno::Sequence< rtl::OUString > aSeq;
2192 	if(xShapeAgg.is())
2193 	{
2194         uno::Reference< lang::XUnoTunnel > xShapeTunnel(xShapeAgg, uno::UNO_QUERY);
2195 		SvxShape* pSvxShape = GetSvxShape();
2196 		if(pSvxShape)
2197 			aSeq = pSvxShape->getSupportedServiceNames();
2198 	}
2199 	else
2200 	{
2201 		aSeq.realloc(1);
2202 		aSeq.getArray()[0] = C2U("com.sun.star.drawing.Shape");
2203 	}
2204 	return aSeq;
2205 }
2206 
GetSvxShape()2207 SvxShape*	SwXShape::GetSvxShape()
2208 {
2209 	SvxShape* pSvxShape = 0;
2210 	if(xShapeAgg.is())
2211 	{
2212         uno::Reference< lang::XUnoTunnel > xShapeTunnel(xShapeAgg, uno::UNO_QUERY);
2213 		if(xShapeTunnel.is())
2214 			pSvxShape = reinterpret_cast< SvxShape * >(
2215 					sal::static_int_cast< sal_IntPtr >( xShapeTunnel->getSomething(SvxShape::getUnoTunnelId()) ));
2216 	}
2217 	return pSvxShape;
2218 }
2219 
2220 // --> OD 2004-07-22 #i31698# -
2221 // implementation of virtual methods from drawing::XShape
getPosition()2222 awt::Point SAL_CALL SwXShape::getPosition() throw ( uno::RuntimeException )
2223 {
2224     awt::Point aPos( _GetAttrPosition() );
2225 
2226     // handle group members
2227     SvxShape* pSvxShape = GetSvxShape();
2228     if ( pSvxShape )
2229     {
2230         SdrObject* pTopGroupObj = _GetTopGroupObj( pSvxShape );
2231         if ( pTopGroupObj )
2232         {
2233             // --> OD 2004-10-01 #i34750# - get attribute position of top group
2234             // shape and add offset between top group object and group member
2235             uno::Reference< drawing::XShape > xGroupShape =
2236                     uno::Reference< drawing::XShape >( pTopGroupObj->getUnoShape(),
2237                                                        uno::UNO_QUERY );
2238             aPos = xGroupShape->getPosition();
2239             // add offset between top group object and group member
2240             // to the determined attribute position
2241             // --> OD 2004-10-01 #i34750# - correction:
2242             // consider the layout direction
2243             const Rectangle aMemberObjRect = GetSvxShape()->GetSdrObject()->GetSnapRect();
2244             const Rectangle aGroupObjRect = pTopGroupObj->GetSnapRect();
2245             // --> OD 2005-08-16 #i53320# - relative position of group member and
2246             // top group object is always given in horizontal left-to-right layout.
2247 //            const SwFrmFmt::tLayoutDir eLayoutDir = GetFrmFmt()
2248 //                                                    ? GetFrmFmt()->GetLayoutDir()
2249 //                                                    : SwFrmFmt::HORI_L2R;
2250             awt::Point aOffset( 0, 0 );
2251 //            switch ( eLayoutDir )
2252 //            {
2253 //                case SwFrmFmt::HORI_L2R:
2254                 {
2255                     aOffset.X = ( aMemberObjRect.Left() - aGroupObjRect.Left() );
2256                     aOffset.Y = ( aMemberObjRect.Top() - aGroupObjRect.Top() );
2257                 }
2258 //                break;
2259 //                case SwFrmFmt::HORI_R2L:
2260 //                {
2261 //                    aOffset.X = ( aGroupObjRect.Right() - aMemberObjRect.Right() );
2262 //                    aOffset.Y = ( aMemberObjRect.Top() - aGroupObjRect.Top() );
2263 //                }
2264 //                break;
2265 //                case SwFrmFmt::VERT_R2L:
2266 //                {
2267 //                    aOffset.X = ( aMemberObjRect.Top() - aGroupObjRect.Top() );
2268 //                    aOffset.Y = ( aGroupObjRect.Right() - aMemberObjRect.Right() );
2269 //                }
2270 //                break;
2271 //                default:
2272 //                {
2273 //                    ASSERT( false,
2274 //                            "<SwXShape::getPosition()> - unsupported layout direction" );
2275 //                }
2276 //            }
2277             // <--
2278             aOffset.X = TWIP_TO_MM100(aOffset.X);
2279             aOffset.Y = TWIP_TO_MM100(aOffset.Y);
2280             aPos.X += aOffset.X;
2281             aPos.Y += aOffset.Y;
2282             // <--
2283         }
2284     }
2285 
2286     return aPos;
2287 }
setPosition(const awt::Point & aPosition)2288 void SAL_CALL SwXShape::setPosition( const awt::Point& aPosition )
2289                                                 throw ( uno::RuntimeException )
2290 {
2291     SdrObject* pTopGroupObj = _GetTopGroupObj();
2292     if ( !pTopGroupObj )
2293     {
2294         // --> OD 2005-02-10 #i37877# - no adjustment of position attributes,
2295         // if the position also has to be applied at the drawing object and
2296         // a contact object is already registered at the drawing object.
2297         bool bApplyPosAtDrawObj(false);
2298         bool bNoAdjustOfPosProp(false);
2299         // --> OD 2004-10-19 #i35798# - apply position also to drawing object,
2300         // if drawing object has no anchor position set.
2301         if ( mxShape.is() )
2302         {
2303             SvxShape* pSvxShape = GetSvxShape();
2304             if ( pSvxShape )
2305             {
2306                 const SdrObject* pObj = pSvxShape->GetSdrObject();
2307                 if ( pObj &&
2308                      pObj->GetAnchorPos().X() == 0 &&
2309                      pObj->GetAnchorPos().Y() == 0 )
2310                 {
2311                     bApplyPosAtDrawObj = true;
2312                     if ( pObj->GetUserCall() &&
2313                          pObj->GetUserCall()->ISA(SwDrawContact) )
2314                     {
2315                         bNoAdjustOfPosProp = true;
2316                     }
2317                 }
2318             }
2319         }
2320         // <--
2321         // shape isn't a group member. Thus, set positioning attributes
2322         if ( !bNoAdjustOfPosProp )
2323         {
2324             _AdjustPositionProperties( aPosition );
2325         }
2326         if ( bApplyPosAtDrawObj )
2327         {
2328             mxShape->setPosition( aPosition );
2329         }
2330         // <--
2331     }
2332     else if ( mxShape.is() )
2333     {
2334         // shape is a member of a group. Thus, set its position.
2335         awt::Point aNewPos( aPosition );
2336         // The given position is given in the according layout direction. Thus,
2337         // it has to be converted to a position in horizontal left-to-right
2338         // layout.
2339         // convert given absolute attribute position in layout direction into
2340         // position in horizontal left-to-right layout.
2341         {
2342             aNewPos = _ConvertPositionToHoriL2R( aNewPos, getSize() );
2343         }
2344         // Convert given absolute position in horizontal left-to-right
2345         // layout into relative position in horizontal left-to-right layout.
2346         uno::Reference< drawing::XShape > xGroupShape =
2347                 uno::Reference< drawing::XShape >( pTopGroupObj->getUnoShape(),
2348                                                    uno::UNO_QUERY );
2349         {
2350             // --> OD 2004-09-29 #i34750# - correction:
2351             // use method <xGroupShape->getPosition()> to get the correct
2352             // position of the top group object.
2353             awt::Point aAttrPosInHoriL2R(
2354                     _ConvertPositionToHoriL2R( xGroupShape->getPosition(),
2355                                                xGroupShape->getSize() ) );
2356             // <--
2357             aNewPos.X -= aAttrPosInHoriL2R.X;
2358             aNewPos.Y -= aAttrPosInHoriL2R.Y;
2359         }
2360         // convert relative position in horizontal left-to-right layout into
2361         // absolute position in horizontal left-to-right layout
2362         {
2363             // --> OD 2004-10-01 #i34750# - correction:
2364             // use method <SvxShape->getPosition()> to get the correct
2365             // 'Drawing layer' position of the top group shape.
2366             uno::Reference< lang::XUnoTunnel > xGrpShapeTunnel(
2367                                                     pTopGroupObj->getUnoShape(),
2368                                                     uno::UNO_QUERY );
2369             SvxShape* pSvxGroupShape = reinterpret_cast< SvxShape * >(
2370 					sal::static_int_cast< sal_IntPtr >( xGrpShapeTunnel->getSomething(SvxShape::getUnoTunnelId()) ));
2371             const awt::Point aGroupPos = pSvxGroupShape->getPosition();
2372             aNewPos.X += aGroupPos.X;
2373             aNewPos.Y += aGroupPos.Y;
2374             // <--
2375         }
2376         // set position
2377         mxShape->setPosition( aNewPos );
2378     }
2379 }
getSize()2380 awt::Size SAL_CALL SwXShape::getSize() throw ( uno::RuntimeException )
2381 {
2382     awt::Size aSize;
2383     if ( mxShape.is() )
2384     {
2385         aSize = mxShape->getSize();
2386     }
2387     return aSize;
2388 }
setSize(const awt::Size & aSize)2389 void SAL_CALL SwXShape::setSize( const awt::Size& aSize )
2390                                         throw ( beans::PropertyVetoException,
2391                                                 uno::RuntimeException )
2392 {
2393     if ( mxShape.is() )
2394     {
2395         mxShape->setSize( aSize );
2396     }
2397 }
2398 // <--
2399 // --> OD 2004-07-22 #i31698# -
2400 // implementation of virtual methods from drawing::XShapeDescriptor
getShapeType()2401 ::rtl::OUString SAL_CALL SwXShape::getShapeType() throw ( uno::RuntimeException )
2402 {
2403     ::rtl::OUString aType;
2404     if ( mxShape.is() )
2405     {
2406         aType = mxShape->getShapeType();
2407     }
2408     return aType;
2409 }
2410 // <--
2411 /** method to determine top group object
2412 
2413     OD 2004-08-03 #i31698#
2414 
2415     @author OD
2416 */
_GetTopGroupObj(SvxShape * _pSvxShape)2417 SdrObject* SwXShape::_GetTopGroupObj( SvxShape* _pSvxShape )
2418 {
2419     SdrObject* pTopGroupObj( 0L );
2420 
2421     SvxShape* pSvxShape = _pSvxShape ? _pSvxShape : GetSvxShape();
2422     if ( pSvxShape )
2423     {
2424         SdrObject* pSdrObj = pSvxShape->GetSdrObject();
2425         if ( pSdrObj && pSdrObj->GetUpGroup() )
2426         {
2427             pTopGroupObj = pSdrObj->GetUpGroup();
2428             while ( pTopGroupObj->GetUpGroup() )
2429             {
2430                 pTopGroupObj = pTopGroupObj->GetUpGroup();
2431             }
2432         }
2433     }
2434 
2435     return pTopGroupObj;
2436 }
2437 
2438 /** method to determine position according to the positioning attributes
2439 
2440     OD 2004-08-03 #i31698#
2441 
2442     @author OD
2443 */
_GetAttrPosition()2444 awt::Point SwXShape::_GetAttrPosition()
2445 {
2446     awt::Point aAttrPos;
2447 
2448     uno::Any aHoriPos( getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HoriOrientPosition")) ) );
2449     aHoriPos >>= aAttrPos.X;
2450     uno::Any aVertPos( getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VertOrientPosition")) ) );
2451     aVertPos >>= aAttrPos.Y;
2452     // --> OD 2004-10-19 #i35798# - fallback, if attribute position is (0,0)
2453     // and no anchor position is applied to the drawing object
2454     SvxShape* pSvxShape = GetSvxShape();
2455     if ( pSvxShape )
2456     {
2457         const SdrObject* pObj = pSvxShape->GetSdrObject();
2458         if ( pObj &&
2459              pObj->GetAnchorPos().X() == 0 &&
2460              pObj->GetAnchorPos().Y() == 0 &&
2461              aAttrPos.X == 0 && aAttrPos.Y == 0 )
2462         {
2463             const Rectangle aObjRect = pObj->GetSnapRect();
2464             aAttrPos.X = TWIP_TO_MM100(aObjRect.Left());
2465             aAttrPos.Y = TWIP_TO_MM100(aObjRect.Top());
2466         }
2467     }
2468     // <--
2469     // --> OD 2004-11-10 #i35007# - If drawing object is anchored as-character,
2470     // it's x-position isn't sensible. Thus, return the x-position as zero in this case.
2471     text::TextContentAnchorType eTextAnchorType =
2472                             text::TextContentAnchorType_AT_PARAGRAPH;
2473     {
2474         rtl::OUString sAnchorType( RTL_CONSTASCII_USTRINGPARAM( "AnchorType" ) );
2475         uno::Any aAny = getPropertyValue( sAnchorType );
2476         aAny >>= eTextAnchorType;
2477     }
2478     if ( eTextAnchorType == text::TextContentAnchorType_AS_CHARACTER )
2479     {
2480         aAttrPos.X = 0;
2481     }
2482     // <--
2483 
2484     return aAttrPos;
2485 }
2486 
2487 /** method to convert the position (translation) of the drawing object to
2488     the layout direction horizontal left-to-right.
2489 
2490     OD 2004-07-27 #i31698#
2491 
2492     @author OD
2493 */
_ConvertPositionToHoriL2R(const awt::Point _aObjPos,const awt::Size _aObjSize)2494 awt::Point SwXShape::_ConvertPositionToHoriL2R( const awt::Point _aObjPos,
2495                                                 const awt::Size _aObjSize )
2496 {
2497     awt::Point aObjPosInHoriL2R( _aObjPos );
2498 
2499     SwFrmFmt* pFrmFmt = GetFrmFmt();
2500     if ( pFrmFmt )
2501     {
2502         SwFrmFmt::tLayoutDir eLayoutDir = pFrmFmt->GetLayoutDir();
2503         switch ( eLayoutDir )
2504         {
2505             case SwFrmFmt::HORI_L2R:
2506             {
2507                 // nothing to do
2508             }
2509             break;
2510             case SwFrmFmt::HORI_R2L:
2511             {
2512                 aObjPosInHoriL2R.X = -_aObjPos.X - _aObjSize.Width;
2513             }
2514             break;
2515             case SwFrmFmt::VERT_R2L:
2516             {
2517                 aObjPosInHoriL2R.X = -_aObjPos.Y - _aObjSize.Width;
2518                 aObjPosInHoriL2R.Y = _aObjPos.X;
2519             }
2520             break;
2521             default:
2522             {
2523                 ASSERT( false,
2524                         "<SwXShape::_ConvertPositionToHoriL2R(..)> - unsupported layout direction" );
2525             }
2526         }
2527     }
2528 
2529     return aObjPosInHoriL2R;
2530 }
2531 /** method to convert the transformation of the drawing object to the layout
2532     direction, the drawing object is in
2533 
2534     OD 2004-07-27 #i31698#
2535 
2536     @author OD
2537 */
_ConvertTransformationToLayoutDir(drawing::HomogenMatrix3 _aMatrixInHoriL2R)2538 drawing::HomogenMatrix3 SwXShape::_ConvertTransformationToLayoutDir(
2539                                     drawing::HomogenMatrix3 _aMatrixInHoriL2R )
2540 {
2541     drawing::HomogenMatrix3 aMatrix( _aMatrixInHoriL2R );
2542 
2543     // --> OD 2005-03-10 #i44334#, #i44681# - direct manipulation of the
2544     // tranformation structure isn't valid, if it contains rotation.
2545     SvxShape* pSvxShape = GetSvxShape();
2546     ASSERT( pSvxShape,
2547             "<SwXShape::_ConvertTransformationToLayoutDir(..)> - no SvxShape found!")
2548     if ( pSvxShape )
2549     {
2550         const SdrObject* pObj = pSvxShape->GetSdrObject();
2551         ASSERT( pObj,
2552                 "<SwXShape::_ConvertTransformationToLayoutDir(..)> - no SdrObject found!")
2553         if ( pObj )
2554         {
2555             // get position of object in Writer coordinate system.
2556             awt::Point aPos( getPosition() );
2557             // get position of object in Drawing layer coordinate system
2558             const Point aTmpObjPos( pObj->GetSnapRect().TopLeft() );
2559             const awt::Point aObjPos(
2560                     TWIP_TO_MM100( aTmpObjPos.X() - pObj->GetAnchorPos().X() ),
2561                     TWIP_TO_MM100( aTmpObjPos.Y() - pObj->GetAnchorPos().Y() ) );
2562             // determine difference between these positions according to the
2563             // Writer coordinate system
2564             const awt::Point aTranslateDiff( aPos.X - aObjPos.X,
2565                                              aPos.Y - aObjPos.Y );
2566             // apply translation difference to transformation matrix.
2567             if ( aTranslateDiff.X != 0 || aTranslateDiff.Y != 0 )
2568             {
2569                 // --> OD 2007-01-03 #i73079# - use correct matrix type
2570                 ::basegfx::B2DHomMatrix aTempMatrix;
2571                 // <--
2572 
2573 				aTempMatrix.set(0, 0, aMatrix.Line1.Column1 );
2574                 aTempMatrix.set(0, 1, aMatrix.Line1.Column2 );
2575                 aTempMatrix.set(0, 2, aMatrix.Line1.Column3 );
2576                 aTempMatrix.set(1, 0, aMatrix.Line2.Column1 );
2577                 aTempMatrix.set(1, 1, aMatrix.Line2.Column2 );
2578                 aTempMatrix.set(1, 2, aMatrix.Line2.Column3 );
2579                 aTempMatrix.set(2, 0, aMatrix.Line3.Column1 );
2580                 aTempMatrix.set(2, 1, aMatrix.Line3.Column2 );
2581                 aTempMatrix.set(2, 2, aMatrix.Line3.Column3 );
2582 
2583                 // --> OD 2007-01-03 #i73079#
2584                 aTempMatrix.translate( aTranslateDiff.X, aTranslateDiff.Y );
2585                 // <--
2586 
2587                 aMatrix.Line1.Column1 = aTempMatrix.get(0, 0);
2588                 aMatrix.Line1.Column2 = aTempMatrix.get(0, 1);
2589                 aMatrix.Line1.Column3 = aTempMatrix.get(0, 2);
2590                 aMatrix.Line2.Column1 = aTempMatrix.get(1, 0);
2591                 aMatrix.Line2.Column2 = aTempMatrix.get(1, 1);
2592                 aMatrix.Line2.Column3 = aTempMatrix.get(1, 2);
2593                 aMatrix.Line3.Column1 = aTempMatrix.get(2, 0);
2594                 aMatrix.Line3.Column2 = aTempMatrix.get(2, 1);
2595                 aMatrix.Line3.Column3 = aTempMatrix.get(2, 2);
2596             }
2597         }
2598     }
2599     // <--
2600 
2601     return aMatrix;
2602 }
2603 
2604 /** method to adjust the positioning properties
2605 
2606     OD 2004-08-02 #i31698#
2607 
2608     @author OD
2609 */
_AdjustPositionProperties(const awt::Point _aPosition)2610 void SwXShape::_AdjustPositionProperties( const awt::Point _aPosition )
2611 {
2612     // handle x-position
2613     // --> OD 2004-11-10 #i35007# - no handling of x-position, if drawing
2614     // object is anchored as-character, because it doesn't make sense.
2615     text::TextContentAnchorType eTextAnchorType =
2616                             text::TextContentAnchorType_AT_PARAGRAPH;
2617     {
2618         rtl::OUString sAnchorType( RTL_CONSTASCII_USTRINGPARAM( "AnchorType" ) );
2619         uno::Any aAny = getPropertyValue( sAnchorType );
2620         aAny >>= eTextAnchorType;
2621     }
2622     if ( eTextAnchorType != text::TextContentAnchorType_AS_CHARACTER )
2623     // <--
2624     {
2625         // determine current x-postion
2626         rtl::OUString aHoriPosPropStr( RTL_CONSTASCII_USTRINGPARAM("HoriOrientPosition") );
2627         uno::Any aHoriPos( getPropertyValue( aHoriPosPropStr ) );
2628         sal_Int32 dCurrX = 0;
2629         aHoriPos >>= dCurrX;
2630         // change x-position attribute, if needed
2631         if ( dCurrX != _aPosition.X )
2632         {
2633             // adjust x-position orientation to text::HoriOrientation::NONE, if needed
2634             // Note: has to be done before setting x-position attribute
2635             rtl::OUString aHoriOrientPropStr( RTL_CONSTASCII_USTRINGPARAM("HoriOrient") );
2636             uno::Any aHoriOrient( getPropertyValue( aHoriOrientPropStr ) );
2637             sal_Int16 eHoriOrient;
2638             if (aHoriOrient >>= eHoriOrient) // may be void
2639             {
2640                 if ( eHoriOrient != text::HoriOrientation::NONE )
2641                 {
2642                     eHoriOrient = text::HoriOrientation::NONE;
2643                     aHoriOrient <<= eHoriOrient;
2644                     setPropertyValue( aHoriOrientPropStr, aHoriOrient );
2645                 }
2646             }
2647             // set x-position attribute
2648             aHoriPos <<= _aPosition.X;
2649             setPropertyValue( aHoriPosPropStr, aHoriPos );
2650         }
2651     }
2652 
2653     // handle y-position
2654     {
2655         // determine current y-postion
2656         rtl::OUString aVertPosPropStr( RTL_CONSTASCII_USTRINGPARAM("VertOrientPosition") );
2657         uno::Any aVertPos( getPropertyValue( aVertPosPropStr ) );
2658         sal_Int32 dCurrY = 0;
2659         aVertPos >>= dCurrY;
2660         // change y-position attribute, if needed
2661         if ( dCurrY != _aPosition.Y )
2662         {
2663             // adjust y-position orientation to text::VertOrientation::NONE, if needed
2664             // Note: has to be done before setting y-position attribute
2665             rtl::OUString aVertOrientPropStr( RTL_CONSTASCII_USTRINGPARAM("VertOrient") );
2666             uno::Any aVertOrient( getPropertyValue( aVertOrientPropStr ) );
2667             sal_Int16 eVertOrient;
2668             if (aVertOrient >>= eVertOrient) // may be void
2669             {
2670                 if ( eVertOrient != text::VertOrientation::NONE )
2671                 {
2672                     eVertOrient = text::VertOrientation::NONE;
2673                     aVertOrient <<= eVertOrient;
2674                     setPropertyValue( aVertOrientPropStr, aVertOrient );
2675                 }
2676             }
2677             // set y-position attribute
2678             aVertPos <<= _aPosition.Y;
2679             setPropertyValue( aVertPosPropStr, aVertPos );
2680         }
2681     }
2682 }
2683 
2684 /** method to convert start or end position of the drawing object to the
2685     Writer specific position, which is the attribute position in layout direction
2686 
2687     OD 2009-01-12 #i59051#
2688 
2689     @author OD
2690 */
_ConvertStartOrEndPosToLayoutDir(const::com::sun::star::awt::Point & aStartOrEndPos)2691 ::com::sun::star::awt::Point SwXShape::_ConvertStartOrEndPosToLayoutDir(
2692                             const ::com::sun::star::awt::Point& aStartOrEndPos )
2693 {
2694     awt::Point aConvertedPos( aStartOrEndPos );
2695 
2696     SvxShape* pSvxShape = GetSvxShape();
2697     ASSERT( pSvxShape,
2698             "<SwXShape::_ConvertStartOrEndPosToLayoutDir(..)> - no SvxShape found!")
2699     if ( pSvxShape )
2700     {
2701         const SdrObject* pObj = pSvxShape->GetSdrObject();
2702         ASSERT( pObj,
2703                 "<SwXShape::_ConvertStartOrEndPosToLayoutDir(..)> - no SdrObject found!")
2704         if ( pObj )
2705         {
2706             // get position of object in Writer coordinate system.
2707             awt::Point aPos( getPosition() );
2708             // get position of object in Drawing layer coordinate system
2709             const Point aTmpObjPos( pObj->GetSnapRect().TopLeft() );
2710             const awt::Point aObjPos(
2711                     TWIP_TO_MM100( aTmpObjPos.X() - pObj->GetAnchorPos().X() ),
2712                     TWIP_TO_MM100( aTmpObjPos.Y() - pObj->GetAnchorPos().Y() ) );
2713             // determine difference between these positions according to the
2714             // Writer coordinate system
2715             const awt::Point aTranslateDiff( aPos.X - aObjPos.X,
2716                                              aPos.Y - aObjPos.Y );
2717             // apply translation difference to transformation matrix.
2718             if ( aTranslateDiff.X != 0 || aTranslateDiff.Y != 0 )
2719             {
2720                 aConvertedPos.X = aConvertedPos.X + aTranslateDiff.X;
2721                 aConvertedPos.Y = aConvertedPos.Y + aTranslateDiff.Y;
2722             }
2723         }
2724     }
2725 
2726     return aConvertedPos;
2727 }
2728 
_ConvertPolyPolygonBezierToLayoutDir(const::com::sun::star::drawing::PolyPolygonBezierCoords & aPath)2729 ::com::sun::star::drawing::PolyPolygonBezierCoords SwXShape::_ConvertPolyPolygonBezierToLayoutDir(
2730                     const ::com::sun::star::drawing::PolyPolygonBezierCoords& aPath )
2731 {
2732     drawing::PolyPolygonBezierCoords aConvertedPath( aPath );
2733 
2734     SvxShape* pSvxShape = GetSvxShape();
2735     ASSERT( pSvxShape,
2736             "<SwXShape::_ConvertStartOrEndPosToLayoutDir(..)> - no SvxShape found!")
2737     if ( pSvxShape )
2738     {
2739         const SdrObject* pObj = pSvxShape->GetSdrObject();
2740         ASSERT( pObj,
2741                 "<SwXShape::_ConvertStartOrEndPosToLayoutDir(..)> - no SdrObject found!")
2742         if ( pObj )
2743         {
2744             // get position of object in Writer coordinate system.
2745             awt::Point aPos( getPosition() );
2746             // get position of object in Drawing layer coordinate system
2747             const Point aTmpObjPos( pObj->GetSnapRect().TopLeft() );
2748             const awt::Point aObjPos(
2749                     TWIP_TO_MM100( aTmpObjPos.X() - pObj->GetAnchorPos().X() ),
2750                     TWIP_TO_MM100( aTmpObjPos.Y() - pObj->GetAnchorPos().Y() ) );
2751             // determine difference between these positions according to the
2752             // Writer coordinate system
2753             const awt::Point aTranslateDiff( aPos.X - aObjPos.X,
2754                                              aPos.Y - aObjPos.Y );
2755             // apply translation difference to PolyPolygonBezier.
2756             if ( aTranslateDiff.X != 0 || aTranslateDiff.Y != 0 )
2757             {
2758                 const basegfx::B2DHomMatrix aMatrix(basegfx::tools::createTranslateB2DHomMatrix(
2759                     aTranslateDiff.X, aTranslateDiff.Y));
2760 
2761                 const sal_Int32 nOuterSequenceCount(aConvertedPath.Coordinates.getLength());
2762                 drawing::PointSequence* pInnerSequence = aConvertedPath.Coordinates.getArray();
2763                 for(sal_Int32 a(0); a < nOuterSequenceCount; a++)
2764                 {
2765                     const sal_Int32 nInnerSequenceCount(pInnerSequence->getLength());
2766                     awt::Point* pArray = pInnerSequence->getArray();
2767 
2768                     for(sal_Int32 b(0); b < nInnerSequenceCount; b++)
2769                     {
2770                         basegfx::B2DPoint aNewCoordinatePair(pArray->X, pArray->Y);
2771                         aNewCoordinatePair *= aMatrix;
2772                         pArray->X = basegfx::fround(aNewCoordinatePair.getX());
2773                         pArray->Y = basegfx::fround(aNewCoordinatePair.getY());
2774                         pArray++;
2775                     }
2776                 }
2777             }
2778         }
2779     }
2780 
2781     return aConvertedPath;
2782 }
2783 
2784 
SwXGroupShape(uno::Reference<XInterface> & xShape)2785 SwXGroupShape::SwXGroupShape(uno::Reference< XInterface > & xShape) :
2786         SwXShape(xShape)
2787 {
2788 #ifdef DBG_UTIL
2789     uno::Reference<XShapes> xShapes(xShapeAgg, uno::UNO_QUERY);
2790     DBG_ASSERT(xShapes.is(), "no SvxShape found or shape is not a group shape");
2791 #endif
2792 }
2793 
2794 
~SwXGroupShape()2795 SwXGroupShape::~SwXGroupShape()
2796 {
2797 }
2798 
queryInterface(const uno::Type & rType)2799 uno::Any SwXGroupShape::queryInterface( const uno::Type& rType ) throw(uno::RuntimeException)
2800 {
2801     uno::Any aRet;
2802     if(rType == ::getCppuType((uno::Reference<XShapes>*)0))
2803         aRet <<= uno::Reference<XShapes>(this);
2804     else
2805         aRet = SwXShape::queryInterface(rType);
2806     return aRet;
2807 }
2808 
acquire()2809 void SwXGroupShape::acquire(  ) throw()
2810 {
2811     SwXShape::acquire();
2812 }
2813 
release()2814 void SwXGroupShape::release(  ) throw()
2815 {
2816     SwXShape::release();
2817 }
2818 
add(const uno::Reference<XShape> & xShape)2819 void SwXGroupShape::add( const uno::Reference< XShape >& xShape ) throw (uno::RuntimeException)
2820 {
2821     vos::OGuard  aGuard(Application::GetSolarMutex());
2822     SvxShape* pSvxShape = GetSvxShape();
2823     SwFrmFmt* pFmt = GetFrmFmt();
2824     if(pSvxShape && pFmt)
2825     {
2826         uno::Reference<XShapes> xShapes;
2827         if( xShapeAgg.is() )
2828         {
2829             const uno::Type& rType = ::getCppuType((uno::Reference<XShapes>*)0 );
2830             uno::Any aAgg = xShapeAgg->queryAggregation( rType );
2831             aAgg >>= xShapes;
2832         }
2833         if(xShapes.is())
2834             xShapes->add(xShape);
2835         else
2836             throw uno::RuntimeException();
2837 
2838         uno::Reference<lang::XUnoTunnel> xTunnel(xShape, uno::UNO_QUERY);
2839         SwXShape* pSwShape = 0;
2840         if(xShape.is())
2841             pSwShape = reinterpret_cast< SwXShape * >(
2842 					sal::static_int_cast< sal_IntPtr >( xTunnel->getSomething(SwXShape::getUnoTunnelId()) ));
2843         if(pSwShape && pSwShape->m_bDescriptor)
2844         {
2845             SvxShape* pAddShape = reinterpret_cast< SvxShape * >(
2846 					sal::static_int_cast< sal_IntPtr >( xTunnel->getSomething(SvxShape::getUnoTunnelId()) ));
2847             if(pAddShape)
2848             {
2849                 SdrObject* pObj = pAddShape->GetSdrObject();
2850                 if(pObj)
2851                 {
2852                     SwDoc* pDoc = pFmt->GetDoc();
2853                     // OD 25.06.2003 #108784# - set layer of new drawing
2854                     // object to corresponding invisible layer.
2855                     if( FmFormInventor != pObj->GetObjInventor())
2856                     {
2857                         pObj->SetLayer( pSwShape->pImpl->GetOpaque()
2858                                         ? pDoc->GetInvisibleHeavenId()
2859                                         : pDoc->GetInvisibleHellId() );
2860                     }
2861                     else
2862                     {
2863                         pObj->SetLayer(pDoc->GetInvisibleControlsId());
2864                     }
2865                 }
2866             }
2867             pSwShape->m_bDescriptor = sal_False;
2868             //add the group member to the format of the group
2869             SwFrmFmt* pShapeFmt = ::FindFrmFmt( pSvxShape->GetSdrObject() );
2870             if(pShapeFmt)
2871                 pFmt->Add(pSwShape);
2872         }
2873     }
2874     else
2875         throw uno::RuntimeException();
2876 }
2877 
remove(const uno::Reference<XShape> & xShape)2878 void SwXGroupShape::remove( const uno::Reference< XShape >& xShape ) throw (uno::RuntimeException)
2879 {
2880     vos::OGuard  aGuard(Application::GetSolarMutex());
2881     uno::Reference<XShapes> xShapes;
2882     if( xShapeAgg.is() )
2883 	{
2884         const uno::Type& rType = ::getCppuType((uno::Reference<XShapes>*)0 );
2885         uno::Any aAgg = xShapeAgg->queryAggregation( rType );
2886         aAgg >>= xShapes;
2887     }
2888     if(!xShapes.is())
2889         throw uno::RuntimeException();
2890     xShapes->remove(xShape);
2891 }
2892 
getCount(void)2893 sal_Int32 SwXGroupShape::getCount(void) throw( uno::RuntimeException )
2894 {
2895     vos::OGuard  aGuard(Application::GetSolarMutex());
2896     uno::Reference<XIndexAccess> xAcc;
2897     if( xShapeAgg.is() )
2898 	{
2899         const uno::Type& rType = ::getCppuType((uno::Reference<XIndexAccess>*)0 );
2900         uno::Any aAgg = xShapeAgg->queryAggregation( rType );
2901         aAgg >>= xAcc;
2902     }
2903     if(!xAcc.is())
2904         throw uno::RuntimeException();
2905     return xAcc->getCount();
2906 }
2907 
getByIndex(sal_Int32 nIndex)2908 uno::Any SwXGroupShape::getByIndex(sal_Int32 nIndex)
2909         throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException,
2910                uno::RuntimeException )
2911 {
2912     vos::OGuard  aGuard(Application::GetSolarMutex());
2913     uno::Reference<XIndexAccess> xAcc;
2914     if( xShapeAgg.is() )
2915 	{
2916         const uno::Type& rType = ::getCppuType((uno::Reference<XIndexAccess>*)0 );
2917         uno::Any aAgg = xShapeAgg->queryAggregation( rType );
2918         aAgg >>= xAcc;
2919     }
2920     if(!xAcc.is())
2921         throw uno::RuntimeException();
2922     return xAcc->getByIndex(nIndex);
2923 }
2924 
getElementType()2925 uno::Type SwXGroupShape::getElementType(  ) throw(uno::RuntimeException)
2926 {
2927     vos::OGuard  aGuard(Application::GetSolarMutex());
2928     uno::Reference<XIndexAccess> xAcc;
2929     if( xShapeAgg.is() )
2930 	{
2931         const uno::Type& rType = ::getCppuType((uno::Reference<XIndexAccess>*)0 );
2932         uno::Any aAgg = xShapeAgg->queryAggregation( rType );
2933         aAgg >>= xAcc;
2934     }
2935     if(!xAcc.is())
2936         throw uno::RuntimeException();
2937     return xAcc->getElementType();
2938 }
2939 
hasElements()2940 sal_Bool SwXGroupShape::hasElements(  ) throw(uno::RuntimeException)
2941 {
2942     vos::OGuard  aGuard(Application::GetSolarMutex());
2943     uno::Reference<XIndexAccess> xAcc;
2944     if( xShapeAgg.is() )
2945 	{
2946         const uno::Type& rType = ::getCppuType((uno::Reference<XIndexAccess>*)0 );
2947         uno::Any aAgg = xShapeAgg->queryAggregation( rType );
2948         aAgg >>= xAcc;
2949     }
2950     if(!xAcc.is())
2951         throw uno::RuntimeException();
2952     return xAcc->hasElements();
2953 }
2954 
2955 
2956