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