xref: /AOO41X/main/sc/source/ui/unoobj/shapeuno.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sc.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <tools/debug.hxx>
32*cdf0e10cSrcweir #include <comphelper/uno3.hxx>
33*cdf0e10cSrcweir #include <comphelper/stl_types.hxx>
34*cdf0e10cSrcweir #include <svtools/unoevent.hxx>
35*cdf0e10cSrcweir #include <svtools/unoimap.hxx>
36*cdf0e10cSrcweir #include <svx/svdobj.hxx>
37*cdf0e10cSrcweir #include <svx/unoshape.hxx>
38*cdf0e10cSrcweir #include <editeng/unofield.hxx>
39*cdf0e10cSrcweir #include <svx/shapepropertynotifier.hxx>
40*cdf0e10cSrcweir #include <toolkit/helper/convert.hxx>
41*cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #include <com/sun/star/drawing/XShape.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #include "shapeuno.hxx"
47*cdf0e10cSrcweir #include "miscuno.hxx"
48*cdf0e10cSrcweir #include "cellsuno.hxx"
49*cdf0e10cSrcweir #include "textuno.hxx"
50*cdf0e10cSrcweir #include "fielduno.hxx"
51*cdf0e10cSrcweir #include "docsh.hxx"
52*cdf0e10cSrcweir #include "drwlayer.hxx"
53*cdf0e10cSrcweir #include "userdat.hxx"
54*cdf0e10cSrcweir #include "unonames.hxx"
55*cdf0e10cSrcweir #include "unoguard.hxx"
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir using namespace ::com::sun::star;
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir //------------------------------------------------------------------------
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir DECLARE_STL_USTRINGACCESS_MAP( uno::Sequence< sal_Int8 > *,  ScShapeImplementationIdMap );
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir static ScShapeImplementationIdMap aImplementationIdMap;
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir const SfxItemPropertyMapEntry* lcl_GetShapeMap()
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir     static SfxItemPropertyMapEntry aShapeMap_Impl[] =
68*cdf0e10cSrcweir 	{
69*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_ANCHOR), 0, &getCppuType((uno::Reference<uno::XInterface>*)0), 0, 0 },
70*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_HORIPOS), 0, &getCppuType((sal_Int32*)0), 0, 0 },
71*cdf0e10cSrcweir 		{MAP_CHAR_LEN(SC_UNONAME_IMAGEMAP),	0, &getCppuType((uno::Reference<container::XIndexContainer>*)0), 0, 0 },
72*cdf0e10cSrcweir 		{MAP_CHAR_LEN(SC_UNONAME_VERTPOS), 0, &getCppuType((sal_Int32*)0), 0, 0 },
73*cdf0e10cSrcweir         {0,0,0,0,0,0}
74*cdf0e10cSrcweir 	};
75*cdf0e10cSrcweir 	return aShapeMap_Impl;
76*cdf0e10cSrcweir }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir // static
79*cdf0e10cSrcweir const SvEventDescription* ScShapeObj::GetSupportedMacroItems()
80*cdf0e10cSrcweir {
81*cdf0e10cSrcweir 	static const SvEventDescription aMacroDescriptionsImpl[] =
82*cdf0e10cSrcweir 	{
83*cdf0e10cSrcweir 		{ 0, NULL }
84*cdf0e10cSrcweir 	};
85*cdf0e10cSrcweir 	return aMacroDescriptionsImpl;
86*cdf0e10cSrcweir }
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir //------------------------------------------------------------------------
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir namespace
91*cdf0e10cSrcweir {
92*cdf0e10cSrcweir     void lcl_initializeNotifier( SdrObject& _rSdrObj, ::cppu::OWeakObject& _rShape )
93*cdf0e10cSrcweir     {
94*cdf0e10cSrcweir         ::svx::PPropertyValueProvider pProvider( new ::svx::PropertyValueProvider( _rShape, "Anchor" ) );
95*cdf0e10cSrcweir         _rSdrObj.getShapePropertyChangeNotifier().registerProvider( ::svx::eSpreadsheetAnchor, pProvider );
96*cdf0e10cSrcweir     }
97*cdf0e10cSrcweir }
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir //------------------------------------------------------------------------
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir ScShapeObj::ScShapeObj( uno::Reference<drawing::XShape>& xShape ) :
102*cdf0e10cSrcweir       pShapePropertySet(NULL),
103*cdf0e10cSrcweir       pShapePropertyState(NULL),
104*cdf0e10cSrcweir       pImplementationId(NULL),
105*cdf0e10cSrcweir       bIsTextShape(false),
106*cdf0e10cSrcweir       bIsNoteCaption(false),
107*cdf0e10cSrcweir       bInitializedNotifier(false)
108*cdf0e10cSrcweir {
109*cdf0e10cSrcweir 	comphelper::increment( m_refCount );
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir 	{
112*cdf0e10cSrcweir 		mxShapeAgg = uno::Reference<uno::XAggregation>( xShape, uno::UNO_QUERY );
113*cdf0e10cSrcweir 		// extra block to force deletion of the temporary before setDelegator
114*cdf0e10cSrcweir 	}
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir 	if (mxShapeAgg.is())
117*cdf0e10cSrcweir 	{
118*cdf0e10cSrcweir 		xShape = NULL;		// during setDelegator, mxShapeAgg must be the only ref
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir 		mxShapeAgg->setDelegator( (cppu::OWeakObject*)this );
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 		xShape.set(uno::Reference<drawing::XShape>( mxShapeAgg, uno::UNO_QUERY ));
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 		bIsTextShape = ( SvxUnoTextBase::getImplementation( mxShapeAgg ) != NULL );
125*cdf0e10cSrcweir 	}
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir     {
128*cdf0e10cSrcweir         SdrObject* pObj = GetSdrObject();
129*cdf0e10cSrcweir         if ( pObj )
130*cdf0e10cSrcweir         {
131*cdf0e10cSrcweir             bIsNoteCaption = ScDrawLayer::IsNoteCaption( pObj );
132*cdf0e10cSrcweir             lcl_initializeNotifier( *pObj, *this );
133*cdf0e10cSrcweir             bInitializedNotifier = true;
134*cdf0e10cSrcweir         }
135*cdf0e10cSrcweir     }
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 	comphelper::decrement( m_refCount );
138*cdf0e10cSrcweir }
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir ScShapeObj::~ScShapeObj()
141*cdf0e10cSrcweir {
142*cdf0e10cSrcweir //	if (mxShapeAgg.is())
143*cdf0e10cSrcweir //		mxShapeAgg->setDelegator(uno::Reference<uno::XInterface>());
144*cdf0e10cSrcweir }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir // XInterface
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir uno::Any SAL_CALL ScShapeObj::queryInterface( const uno::Type& rType )
149*cdf0e10cSrcweir 												throw(uno::RuntimeException)
150*cdf0e10cSrcweir {
151*cdf0e10cSrcweir     uno::Any aRet = ScShapeObj_Base::queryInterface( rType );
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir     if ( !aRet.hasValue() && bIsTextShape )
154*cdf0e10cSrcweir         aRet = ScShapeObj_TextBase::queryInterface( rType );
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir     if ( !aRet.hasValue() && bIsNoteCaption )
157*cdf0e10cSrcweir         aRet = ScShapeObj_ChildBase::queryInterface( rType );
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 	if ( !aRet.hasValue() && mxShapeAgg.is() )
160*cdf0e10cSrcweir 		aRet = mxShapeAgg->queryAggregation( rType );
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 	return aRet;
163*cdf0e10cSrcweir }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir void SAL_CALL ScShapeObj::acquire() throw()
166*cdf0e10cSrcweir {
167*cdf0e10cSrcweir         OWeakObject::acquire();
168*cdf0e10cSrcweir }
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir void SAL_CALL ScShapeObj::release() throw()
171*cdf0e10cSrcweir {
172*cdf0e10cSrcweir         OWeakObject::release();
173*cdf0e10cSrcweir }
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir void ScShapeObj::GetShapePropertySet()
176*cdf0e10cSrcweir {
177*cdf0e10cSrcweir     // #i61908# Store the result of queryAggregation in a member.
178*cdf0e10cSrcweir     // The reference in mxShapeAgg is kept for this object's lifetime, so the pointer is always valid.
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir     if (!pShapePropertySet)
181*cdf0e10cSrcweir     {
182*cdf0e10cSrcweir         uno::Reference<beans::XPropertySet> xProp;
183*cdf0e10cSrcweir         if ( mxShapeAgg.is() )
184*cdf0e10cSrcweir             mxShapeAgg->queryAggregation( getCppuType((uno::Reference<beans::XPropertySet>*) 0) ) >>= xProp;
185*cdf0e10cSrcweir         pShapePropertySet = xProp.get();
186*cdf0e10cSrcweir     }
187*cdf0e10cSrcweir }
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir void ScShapeObj::GetShapePropertyState()
190*cdf0e10cSrcweir {
191*cdf0e10cSrcweir     // #i61908# Store the result of queryAggregation in a member.
192*cdf0e10cSrcweir     // The reference in mxShapeAgg is kept for this object's lifetime, so the pointer is always valid.
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir     if (!pShapePropertyState)
195*cdf0e10cSrcweir     {
196*cdf0e10cSrcweir         uno::Reference<beans::XPropertyState> xState;
197*cdf0e10cSrcweir         if ( mxShapeAgg.is() )
198*cdf0e10cSrcweir             mxShapeAgg->queryAggregation( getCppuType((uno::Reference<beans::XPropertyState>*) 0) ) >>= xState;
199*cdf0e10cSrcweir         pShapePropertyState = xState.get();
200*cdf0e10cSrcweir     }
201*cdf0e10cSrcweir }
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir uno::Reference<lang::XComponent> lcl_GetComponent( const uno::Reference<uno::XAggregation>& xAgg )
204*cdf0e10cSrcweir {
205*cdf0e10cSrcweir 	uno::Reference<lang::XComponent> xRet;
206*cdf0e10cSrcweir 	if ( xAgg.is() )
207*cdf0e10cSrcweir 		xAgg->queryAggregation( getCppuType((uno::Reference<lang::XComponent>*) 0) ) >>= xRet;
208*cdf0e10cSrcweir 	return xRet;
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir uno::Reference<text::XText> lcl_GetText( const uno::Reference<uno::XAggregation>& xAgg )
212*cdf0e10cSrcweir {
213*cdf0e10cSrcweir 	uno::Reference<text::XText> xRet;
214*cdf0e10cSrcweir 	if ( xAgg.is() )
215*cdf0e10cSrcweir 		xAgg->queryAggregation( getCppuType((uno::Reference<text::XText>*) 0) ) >>= xRet;
216*cdf0e10cSrcweir 	return xRet;
217*cdf0e10cSrcweir }
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir uno::Reference<text::XSimpleText> lcl_GetSimpleText( const uno::Reference<uno::XAggregation>& xAgg )
220*cdf0e10cSrcweir {
221*cdf0e10cSrcweir 	uno::Reference<text::XSimpleText> xRet;
222*cdf0e10cSrcweir 	if ( xAgg.is() )
223*cdf0e10cSrcweir 		xAgg->queryAggregation( getCppuType((uno::Reference<text::XSimpleText>*) 0) ) >>= xRet;
224*cdf0e10cSrcweir 	return xRet;
225*cdf0e10cSrcweir }
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir uno::Reference<text::XTextRange> lcl_GetTextRange( const uno::Reference<uno::XAggregation>& xAgg )
228*cdf0e10cSrcweir {
229*cdf0e10cSrcweir 	uno::Reference<text::XTextRange> xRet;
230*cdf0e10cSrcweir 	if ( xAgg.is() )
231*cdf0e10cSrcweir 		xAgg->queryAggregation( getCppuType((uno::Reference<text::XTextRange>*) 0) ) >>= xRet;
232*cdf0e10cSrcweir 	return xRet;
233*cdf0e10cSrcweir }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir //	XPropertySet
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir uno::Reference<beans::XPropertySetInfo> SAL_CALL ScShapeObj::getPropertySetInfo()
238*cdf0e10cSrcweir 														throw(uno::RuntimeException)
239*cdf0e10cSrcweir {
240*cdf0e10cSrcweir 	ScUnoGuard aGuard;
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir     // #i61527# cache property set info for this object
243*cdf0e10cSrcweir     if ( !mxPropSetInfo.is() )
244*cdf0e10cSrcweir     {
245*cdf0e10cSrcweir         //	mix own and aggregated properties:
246*cdf0e10cSrcweir         GetShapePropertySet();
247*cdf0e10cSrcweir         if (pShapePropertySet)
248*cdf0e10cSrcweir         {
249*cdf0e10cSrcweir             uno::Reference<beans::XPropertySetInfo> xAggInfo(pShapePropertySet->getPropertySetInfo());
250*cdf0e10cSrcweir             const uno::Sequence<beans::Property> aPropSeq(xAggInfo->getProperties());
251*cdf0e10cSrcweir             mxPropSetInfo.set(new SfxExtItemPropertySetInfo( lcl_GetShapeMap(), aPropSeq ));
252*cdf0e10cSrcweir         }
253*cdf0e10cSrcweir     }
254*cdf0e10cSrcweir 	return mxPropSetInfo;
255*cdf0e10cSrcweir }
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir sal_Bool lcl_GetPageNum( SdrPage* pPage, SdrModel& rModel, SCTAB& rNum )
258*cdf0e10cSrcweir {
259*cdf0e10cSrcweir 	sal_uInt16 nCount = rModel.GetPageCount();
260*cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<nCount; i++)
261*cdf0e10cSrcweir 		if ( rModel.GetPage(i) == pPage )
262*cdf0e10cSrcweir 		{
263*cdf0e10cSrcweir 			rNum = static_cast<SCTAB>(i);
264*cdf0e10cSrcweir 			return sal_True;
265*cdf0e10cSrcweir 		}
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir 	return sal_False;
268*cdf0e10cSrcweir }
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir sal_Bool lcl_GetCaptionPoint( uno::Reference< drawing::XShape >& xShape, awt::Point& rCaptionPoint )
271*cdf0e10cSrcweir {
272*cdf0e10cSrcweir     sal_Bool bReturn = sal_False;
273*cdf0e10cSrcweir     rtl::OUString sType(xShape->getShapeType());
274*cdf0e10cSrcweir     sal_Bool bCaptionShape(sType.equalsAscii("com.sun.star.drawing.CaptionShape"));
275*cdf0e10cSrcweir     if (bCaptionShape)
276*cdf0e10cSrcweir     {
277*cdf0e10cSrcweir         uno::Reference < beans::XPropertySet > xShapeProp (xShape, uno::UNO_QUERY);
278*cdf0e10cSrcweir         if (xShapeProp.is())
279*cdf0e10cSrcweir         {
280*cdf0e10cSrcweir             xShapeProp->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "CaptionPoint" )) ) >>= rCaptionPoint;
281*cdf0e10cSrcweir             bReturn = sal_True;
282*cdf0e10cSrcweir         }
283*cdf0e10cSrcweir     }
284*cdf0e10cSrcweir     return bReturn;
285*cdf0e10cSrcweir }
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir ScRange lcl_GetAnchorCell( uno::Reference< drawing::XShape >& xShape, ScDocument* pDoc, SCTAB nTab,
288*cdf0e10cSrcweir                           awt::Point& rUnoPoint, awt::Size& rUnoSize, awt::Point& rCaptionPoint )
289*cdf0e10cSrcweir {
290*cdf0e10cSrcweir     ScRange aReturn;
291*cdf0e10cSrcweir     rUnoPoint = xShape->getPosition();
292*cdf0e10cSrcweir     rtl::OUString sType(xShape->getShapeType());
293*cdf0e10cSrcweir     sal_Bool bCaptionShape(lcl_GetCaptionPoint(xShape, rCaptionPoint));
294*cdf0e10cSrcweir     if (pDoc->IsNegativePage(nTab))
295*cdf0e10cSrcweir     {
296*cdf0e10cSrcweir         rUnoSize = xShape->getSize();
297*cdf0e10cSrcweir         rUnoPoint.X += rUnoSize.Width; // the right top point is base
298*cdf0e10cSrcweir         if (bCaptionShape)
299*cdf0e10cSrcweir         {
300*cdf0e10cSrcweir             if (rCaptionPoint.X > 0 && rCaptionPoint.X > rUnoSize.Width)
301*cdf0e10cSrcweir                 rUnoPoint.X += rCaptionPoint.X - rUnoSize.Width;
302*cdf0e10cSrcweir             if (rCaptionPoint.Y < 0)
303*cdf0e10cSrcweir                 rUnoPoint.Y += rCaptionPoint.Y;
304*cdf0e10cSrcweir         }
305*cdf0e10cSrcweir         aReturn = pDoc->GetRange( nTab, Rectangle( VCLPoint(rUnoPoint), VCLPoint(rUnoPoint) ));
306*cdf0e10cSrcweir     }
307*cdf0e10cSrcweir     else
308*cdf0e10cSrcweir     {
309*cdf0e10cSrcweir         if (bCaptionShape)
310*cdf0e10cSrcweir         {
311*cdf0e10cSrcweir             if (rCaptionPoint.X < 0)
312*cdf0e10cSrcweir                 rUnoPoint.X += rCaptionPoint.X;
313*cdf0e10cSrcweir             if (rCaptionPoint.Y < 0)
314*cdf0e10cSrcweir                 rUnoPoint.Y += rCaptionPoint.Y;
315*cdf0e10cSrcweir         }
316*cdf0e10cSrcweir         aReturn = pDoc->GetRange( nTab, Rectangle( VCLPoint(rUnoPoint), VCLPoint(rUnoPoint) ));
317*cdf0e10cSrcweir     }
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir     return aReturn;
320*cdf0e10cSrcweir }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir awt::Point lcl_GetRelativePos( uno::Reference< drawing::XShape >& xShape, ScDocument* pDoc, SCTAB nTab, ScRange& rRange,
323*cdf0e10cSrcweir                               awt::Size& rUnoSize, awt::Point& rCaptionPoint)
324*cdf0e10cSrcweir {
325*cdf0e10cSrcweir     awt::Point aUnoPoint;
326*cdf0e10cSrcweir     rRange = lcl_GetAnchorCell(xShape, pDoc, nTab, aUnoPoint, rUnoSize, rCaptionPoint);
327*cdf0e10cSrcweir     if (pDoc->IsNegativePage(nTab))
328*cdf0e10cSrcweir     {
329*cdf0e10cSrcweir         Rectangle aRect(pDoc->GetMMRect( rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row(), rRange.aStart.Tab() ));
330*cdf0e10cSrcweir         Point aPoint(aRect.TopRight());
331*cdf0e10cSrcweir         aUnoPoint.X -= aPoint.X();
332*cdf0e10cSrcweir         aUnoPoint.Y -= aPoint.Y();
333*cdf0e10cSrcweir     }
334*cdf0e10cSrcweir     else
335*cdf0e10cSrcweir     {
336*cdf0e10cSrcweir         ScRange aRange = pDoc->GetRange( nTab, Rectangle( VCLPoint(aUnoPoint), VCLPoint(aUnoPoint) ));
337*cdf0e10cSrcweir         Rectangle aRect(pDoc->GetMMRect( rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row(), rRange.aStart.Tab() ));
338*cdf0e10cSrcweir         Point aPoint(aRect.TopLeft());
339*cdf0e10cSrcweir         aUnoPoint.X -= aPoint.X();
340*cdf0e10cSrcweir         aUnoPoint.Y -= aPoint.Y();
341*cdf0e10cSrcweir     }
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir     return aUnoPoint;
344*cdf0e10cSrcweir }
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir void SAL_CALL ScShapeObj::setPropertyValue(
347*cdf0e10cSrcweir 						const rtl::OUString& aPropertyName, const uno::Any& aValue )
348*cdf0e10cSrcweir 				throw(beans::UnknownPropertyException, beans::PropertyVetoException,
349*cdf0e10cSrcweir 						lang::IllegalArgumentException, lang::WrappedTargetException,
350*cdf0e10cSrcweir 						uno::RuntimeException)
351*cdf0e10cSrcweir {
352*cdf0e10cSrcweir 	ScUnoGuard aGuard;
353*cdf0e10cSrcweir 	String aNameString(aPropertyName);
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir 	if ( aNameString.EqualsAscii( SC_UNONAME_ANCHOR ) )
356*cdf0e10cSrcweir     {
357*cdf0e10cSrcweir         uno::Reference<sheet::XCellRangeAddressable> xRangeAdd(aValue, uno::UNO_QUERY);
358*cdf0e10cSrcweir         if (xRangeAdd.is())
359*cdf0e10cSrcweir         {
360*cdf0e10cSrcweir             SdrObject *pObj = GetSdrObject();
361*cdf0e10cSrcweir 		    if (pObj)
362*cdf0e10cSrcweir 		    {
363*cdf0e10cSrcweir 		        ScDrawLayer* pModel = (ScDrawLayer*)pObj->GetModel();
364*cdf0e10cSrcweir 		        SdrPage* pPage = pObj->GetPage();
365*cdf0e10cSrcweir 		        if ( pModel && pPage )
366*cdf0e10cSrcweir 		        {
367*cdf0e10cSrcweir 			        ScDocument* pDoc = pModel->GetDocument();
368*cdf0e10cSrcweir 			        if ( pDoc )
369*cdf0e10cSrcweir 			        {
370*cdf0e10cSrcweir 				        SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
371*cdf0e10cSrcweir 				        if ( pObjSh && pObjSh->ISA(ScDocShell) )
372*cdf0e10cSrcweir 				        {
373*cdf0e10cSrcweir 					        ScDocShell* pDocSh = (ScDocShell*)pObjSh;
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir 					        SCTAB nTab = 0;
376*cdf0e10cSrcweir 					        if ( lcl_GetPageNum( pPage, *pModel, nTab ) )
377*cdf0e10cSrcweir 					        {
378*cdf0e10cSrcweir                                 table::CellRangeAddress aAddress = xRangeAdd->getRangeAddress();
379*cdf0e10cSrcweir                                 if (nTab == aAddress.Sheet)
380*cdf0e10cSrcweir                                 {
381*cdf0e10cSrcweir                                     if (aAddress.StartRow != aAddress.EndRow) //should be a Spreadsheet
382*cdf0e10cSrcweir                                     {
383*cdf0e10cSrcweir                                         DBG_ASSERT(aAddress.StartRow == 0 && aAddress.EndRow == MAXROW &&
384*cdf0e10cSrcweir                                             aAddress.StartColumn == 0 && aAddress.EndColumn == MAXCOL, "here should be a XSpreadsheet");
385*cdf0e10cSrcweir 			                            ScDrawLayer::SetAnchor(pObj, SCA_PAGE);
386*cdf0e10cSrcweir                                     }
387*cdf0e10cSrcweir                                     else
388*cdf0e10cSrcweir                                     {
389*cdf0e10cSrcweir                                         DBG_ASSERT(aAddress.StartRow == aAddress.EndRow &&
390*cdf0e10cSrcweir                                             aAddress.StartColumn == aAddress.EndColumn, "here should be a XCell");
391*cdf0e10cSrcweir 			                            ScDrawLayer::SetAnchor(pObj, SCA_CELL);
392*cdf0e10cSrcweir                                     }
393*cdf0e10cSrcweir                                     Rectangle aRect(pDoc->GetMMRect( static_cast<SCCOL>(aAddress.StartColumn), static_cast<SCROW>(aAddress.StartRow),
394*cdf0e10cSrcweir                                         static_cast<SCCOL>(aAddress.EndColumn), static_cast<SCROW>(aAddress.EndRow), aAddress.Sheet ));
395*cdf0e10cSrcweir                                     uno::Reference<drawing::XShape> xShape( mxShapeAgg, uno::UNO_QUERY );
396*cdf0e10cSrcweir                                     if (xShape.is())
397*cdf0e10cSrcweir                                     {
398*cdf0e10cSrcweir                                         Point aPoint;
399*cdf0e10cSrcweir                                         Point aEndPoint;
400*cdf0e10cSrcweir                                         if (pDoc->IsNegativePage(nTab))
401*cdf0e10cSrcweir                                         {
402*cdf0e10cSrcweir                                             aPoint = aRect.TopRight();
403*cdf0e10cSrcweir                                             aEndPoint = aRect.BottomLeft();
404*cdf0e10cSrcweir                                         }
405*cdf0e10cSrcweir                                         else
406*cdf0e10cSrcweir                                         {
407*cdf0e10cSrcweir                                             aPoint = aRect.TopLeft();
408*cdf0e10cSrcweir                                             aEndPoint = aRect.BottomRight();
409*cdf0e10cSrcweir                                         }
410*cdf0e10cSrcweir                                         awt::Size aUnoSize;
411*cdf0e10cSrcweir                                         awt::Point aCaptionPoint;
412*cdf0e10cSrcweir                                         ScRange aRange;
413*cdf0e10cSrcweir                                         awt::Point aUnoPoint(lcl_GetRelativePos( xShape, pDoc, nTab, aRange, aUnoSize, aCaptionPoint ));
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir                                         aUnoPoint.X += aPoint.X();
416*cdf0e10cSrcweir                                         aUnoPoint.Y += aPoint.Y();
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir                                         if ( aUnoPoint.Y > aEndPoint.Y() )
419*cdf0e10cSrcweir                                             aUnoPoint.Y = aEndPoint.Y() - 2;
420*cdf0e10cSrcweir                                         if (pDoc->IsNegativePage(nTab))
421*cdf0e10cSrcweir                                         {
422*cdf0e10cSrcweir                                             if ( aUnoPoint.X < aEndPoint.X() )
423*cdf0e10cSrcweir                                                 aUnoPoint.X = aEndPoint.X() + 2;
424*cdf0e10cSrcweir                                             aUnoPoint.X -= aUnoSize.Width;
425*cdf0e10cSrcweir                                             // remove difference to caption point
426*cdf0e10cSrcweir                                             if (aCaptionPoint.X > 0 && aCaptionPoint.X > aUnoSize.Width)
427*cdf0e10cSrcweir                                                 aUnoPoint.X -= aCaptionPoint.X - aUnoSize.Width;
428*cdf0e10cSrcweir                                         }
429*cdf0e10cSrcweir                                         else
430*cdf0e10cSrcweir                                         {
431*cdf0e10cSrcweir                                             if ( aUnoPoint.X > aEndPoint.X() )
432*cdf0e10cSrcweir                                                 aUnoPoint.X = aEndPoint.X() - 2;
433*cdf0e10cSrcweir                                             if (aCaptionPoint.X < 0)
434*cdf0e10cSrcweir                                                 aUnoPoint.X -= aCaptionPoint.X;
435*cdf0e10cSrcweir                                         }
436*cdf0e10cSrcweir                                         if (aCaptionPoint.Y < 0)
437*cdf0e10cSrcweir                                             aUnoPoint.Y -= aCaptionPoint.Y;
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir                                         xShape->setPosition(aUnoPoint);
440*cdf0e10cSrcweir                                         pDocSh->SetModified();
441*cdf0e10cSrcweir                                     }
442*cdf0e10cSrcweir                                 }
443*cdf0e10cSrcweir 					        }
444*cdf0e10cSrcweir 				        }
445*cdf0e10cSrcweir                     }
446*cdf0e10cSrcweir                 }
447*cdf0e10cSrcweir             }
448*cdf0e10cSrcweir         }
449*cdf0e10cSrcweir         else
450*cdf0e10cSrcweir             throw lang::IllegalArgumentException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("only XCell or XSpreadsheet objects allowed")), static_cast<cppu::OWeakObject*>(this), 0);
451*cdf0e10cSrcweir     }
452*cdf0e10cSrcweir     else if ( aNameString.EqualsAscii( SC_UNONAME_IMAGEMAP ) )
453*cdf0e10cSrcweir 	{
454*cdf0e10cSrcweir 		SdrObject* pObj = GetSdrObject();
455*cdf0e10cSrcweir 		if ( pObj )
456*cdf0e10cSrcweir 		{
457*cdf0e10cSrcweir 			ImageMap aImageMap;
458*cdf0e10cSrcweir             uno::Reference< uno::XInterface > xImageMapInt(aValue, uno::UNO_QUERY);
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir 			if( !xImageMapInt.is() || !SvUnoImageMap_fillImageMap( xImageMapInt, aImageMap ) )
461*cdf0e10cSrcweir 				throw lang::IllegalArgumentException();
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir 			ScIMapInfo* pIMapInfo = ScDrawLayer::GetIMapInfo(pObj);
464*cdf0e10cSrcweir 			if( pIMapInfo )
465*cdf0e10cSrcweir 			{
466*cdf0e10cSrcweir 				// replace existing image map
467*cdf0e10cSrcweir 				pIMapInfo->SetImageMap( aImageMap );
468*cdf0e10cSrcweir 			}
469*cdf0e10cSrcweir 			else
470*cdf0e10cSrcweir 			{
471*cdf0e10cSrcweir 				// insert new user data with image map
472*cdf0e10cSrcweir 				pObj->InsertUserData(new ScIMapInfo(aImageMap) );
473*cdf0e10cSrcweir 			}
474*cdf0e10cSrcweir 		}
475*cdf0e10cSrcweir 	}
476*cdf0e10cSrcweir     else if ( aNameString.EqualsAscii( SC_UNONAME_HORIPOS ) )
477*cdf0e10cSrcweir     {
478*cdf0e10cSrcweir         sal_Int32 nPos = 0;
479*cdf0e10cSrcweir         if (aValue >>= nPos)
480*cdf0e10cSrcweir         {
481*cdf0e10cSrcweir             SdrObject *pObj = GetSdrObject();
482*cdf0e10cSrcweir 		    if (pObj)
483*cdf0e10cSrcweir 		    {
484*cdf0e10cSrcweir 		        ScDrawLayer* pModel = (ScDrawLayer*)pObj->GetModel();
485*cdf0e10cSrcweir 		        SdrPage* pPage = pObj->GetPage();
486*cdf0e10cSrcweir 		        if ( pModel && pPage )
487*cdf0e10cSrcweir 		        {
488*cdf0e10cSrcweir 					SCTAB nTab = 0;
489*cdf0e10cSrcweir 					if ( lcl_GetPageNum( pPage, *pModel, nTab ) )
490*cdf0e10cSrcweir 					{
491*cdf0e10cSrcweir 			            ScDocument* pDoc = pModel->GetDocument();
492*cdf0e10cSrcweir 			            if ( pDoc )
493*cdf0e10cSrcweir 			            {
494*cdf0e10cSrcweir 				            SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
495*cdf0e10cSrcweir 				            if ( pObjSh && pObjSh->ISA(ScDocShell) )
496*cdf0e10cSrcweir 				            {
497*cdf0e10cSrcweir 					            ScDocShell* pDocSh = (ScDocShell*)pObjSh;
498*cdf0e10cSrcweir                                 uno::Reference<drawing::XShape> xShape( mxShapeAgg, uno::UNO_QUERY );
499*cdf0e10cSrcweir                                 if (xShape.is())
500*cdf0e10cSrcweir                                 {
501*cdf0e10cSrcweir                                     if (ScDrawLayer::GetAnchor(pObj) == SCA_PAGE)
502*cdf0e10cSrcweir                                     {
503*cdf0e10cSrcweir                                         awt::Point aPoint(xShape->getPosition());
504*cdf0e10cSrcweir                                         awt::Size aSize(xShape->getSize());
505*cdf0e10cSrcweir                                         awt::Point aCaptionPoint;
506*cdf0e10cSrcweir                                         if (pDoc->IsNegativePage(nTab))
507*cdf0e10cSrcweir                                         {
508*cdf0e10cSrcweir                                             nPos *= -1;
509*cdf0e10cSrcweir                                             nPos -= aSize.Width;
510*cdf0e10cSrcweir                                         }
511*cdf0e10cSrcweir                                         if (lcl_GetCaptionPoint(xShape, aCaptionPoint))
512*cdf0e10cSrcweir                                         {
513*cdf0e10cSrcweir                                             if (pDoc->IsNegativePage(nTab))
514*cdf0e10cSrcweir                                             {
515*cdf0e10cSrcweir                                                 if (aCaptionPoint.X > 0 && aCaptionPoint.X > aSize.Width)
516*cdf0e10cSrcweir                                                     nPos -= aCaptionPoint.X - aSize.Width;
517*cdf0e10cSrcweir                                             }
518*cdf0e10cSrcweir                                             else
519*cdf0e10cSrcweir                                             {
520*cdf0e10cSrcweir                                                 if (aCaptionPoint.X < 0)
521*cdf0e10cSrcweir                                                     nPos -= aCaptionPoint.X;
522*cdf0e10cSrcweir                                             }
523*cdf0e10cSrcweir                                         }
524*cdf0e10cSrcweir                                         aPoint.X = nPos;
525*cdf0e10cSrcweir                                         xShape->setPosition(aPoint);
526*cdf0e10cSrcweir                                         pDocSh->SetModified();
527*cdf0e10cSrcweir                                     }
528*cdf0e10cSrcweir                                     else if (ScDrawLayer::GetAnchor(pObj) == SCA_CELL)
529*cdf0e10cSrcweir                                     {
530*cdf0e10cSrcweir                                         awt::Size aUnoSize;
531*cdf0e10cSrcweir                                         awt::Point aCaptionPoint;
532*cdf0e10cSrcweir                                         ScRange aRange;
533*cdf0e10cSrcweir                                         awt::Point aUnoPoint(lcl_GetRelativePos( xShape, pDoc, nTab, aRange, aUnoSize, aCaptionPoint ));
534*cdf0e10cSrcweir                                         Rectangle aRect(pDoc->GetMMRect( aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row(), aRange.aStart.Tab() ));
535*cdf0e10cSrcweir                                         if (pDoc->IsNegativePage(nTab))
536*cdf0e10cSrcweir                                         {
537*cdf0e10cSrcweir                                             aUnoPoint.X = -nPos;
538*cdf0e10cSrcweir                                             Point aPoint(aRect.TopRight());
539*cdf0e10cSrcweir                                             Point aEndPoint(aRect.BottomLeft());
540*cdf0e10cSrcweir                                             aUnoPoint.X += aPoint.X();
541*cdf0e10cSrcweir                                             if (aUnoPoint.X < aEndPoint.X())
542*cdf0e10cSrcweir                                                 aUnoPoint.X = aEndPoint.X() + 2;
543*cdf0e10cSrcweir                                             aUnoPoint.X -= aUnoSize.Width;
544*cdf0e10cSrcweir                                             if (aCaptionPoint.X > 0 && aCaptionPoint.X > aUnoSize.Width)
545*cdf0e10cSrcweir                                                 aUnoPoint.X -= aCaptionPoint.X - aUnoSize.Width;
546*cdf0e10cSrcweir                                         }
547*cdf0e10cSrcweir                                         else
548*cdf0e10cSrcweir                                         {
549*cdf0e10cSrcweir                                             aUnoPoint.X = nPos;
550*cdf0e10cSrcweir                                             Point aPoint(aRect.TopLeft());
551*cdf0e10cSrcweir                                             Point aEndPoint(aRect.BottomRight());
552*cdf0e10cSrcweir                                             aUnoPoint.X += aPoint.X();
553*cdf0e10cSrcweir                                             if (aUnoPoint.X > aEndPoint.X())
554*cdf0e10cSrcweir                                                 aUnoPoint.X = aEndPoint.X() - 2;
555*cdf0e10cSrcweir                                             if (aCaptionPoint.X < 0)
556*cdf0e10cSrcweir                                                 aUnoPoint.X -= aCaptionPoint.X;
557*cdf0e10cSrcweir                                         }
558*cdf0e10cSrcweir                                         aUnoPoint.Y = xShape->getPosition().Y;
559*cdf0e10cSrcweir                                         xShape->setPosition(aUnoPoint);
560*cdf0e10cSrcweir                                         pDocSh->SetModified();
561*cdf0e10cSrcweir                                     }
562*cdf0e10cSrcweir                                     else
563*cdf0e10cSrcweir                                     {
564*cdf0e10cSrcweir                                         DBG_ERROR("unknown anchor type");
565*cdf0e10cSrcweir                                     }
566*cdf0e10cSrcweir                                 }
567*cdf0e10cSrcweir                             }
568*cdf0e10cSrcweir                         }
569*cdf0e10cSrcweir                     }
570*cdf0e10cSrcweir                 }
571*cdf0e10cSrcweir             }
572*cdf0e10cSrcweir         }
573*cdf0e10cSrcweir     }
574*cdf0e10cSrcweir     else if ( aNameString.EqualsAscii( SC_UNONAME_VERTPOS ) )
575*cdf0e10cSrcweir     {
576*cdf0e10cSrcweir         sal_Int32 nPos = 0;
577*cdf0e10cSrcweir         if (aValue >>= nPos)
578*cdf0e10cSrcweir         {
579*cdf0e10cSrcweir             SdrObject *pObj = GetSdrObject();
580*cdf0e10cSrcweir 		    if (pObj)
581*cdf0e10cSrcweir 		    {
582*cdf0e10cSrcweir 		        ScDrawLayer* pModel = (ScDrawLayer*)pObj->GetModel();
583*cdf0e10cSrcweir 		        SdrPage* pPage = pObj->GetPage();
584*cdf0e10cSrcweir 		        if ( pModel && pPage )
585*cdf0e10cSrcweir 		        {
586*cdf0e10cSrcweir 					SCTAB nTab = 0;
587*cdf0e10cSrcweir 					if ( lcl_GetPageNum( pPage, *pModel, nTab ) )
588*cdf0e10cSrcweir 					{
589*cdf0e10cSrcweir 			            ScDocument* pDoc = pModel->GetDocument();
590*cdf0e10cSrcweir 			            if ( pDoc )
591*cdf0e10cSrcweir 			            {
592*cdf0e10cSrcweir 				            SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
593*cdf0e10cSrcweir 				            if ( pObjSh && pObjSh->ISA(ScDocShell) )
594*cdf0e10cSrcweir 				            {
595*cdf0e10cSrcweir 					            ScDocShell* pDocSh = (ScDocShell*)pObjSh;
596*cdf0e10cSrcweir                                 uno::Reference<drawing::XShape> xShape( mxShapeAgg, uno::UNO_QUERY );
597*cdf0e10cSrcweir                                 if (xShape.is())
598*cdf0e10cSrcweir                                 {
599*cdf0e10cSrcweir                                     if (ScDrawLayer::GetAnchor(pObj) == SCA_PAGE)
600*cdf0e10cSrcweir                                     {
601*cdf0e10cSrcweir                                         awt::Point aPoint = xShape->getPosition();
602*cdf0e10cSrcweir                                         awt::Point aCaptionPoint;
603*cdf0e10cSrcweir                                         if (lcl_GetCaptionPoint(xShape, aCaptionPoint))
604*cdf0e10cSrcweir                                         {
605*cdf0e10cSrcweir                                             if (aCaptionPoint.Y < 0)
606*cdf0e10cSrcweir                                                 nPos -= aCaptionPoint.Y;
607*cdf0e10cSrcweir                                         }
608*cdf0e10cSrcweir                                         aPoint.Y = nPos;
609*cdf0e10cSrcweir                                         xShape->setPosition(aPoint);
610*cdf0e10cSrcweir                                         pDocSh->SetModified();
611*cdf0e10cSrcweir                                     }
612*cdf0e10cSrcweir                                     else if (ScDrawLayer::GetAnchor(pObj) == SCA_CELL)
613*cdf0e10cSrcweir                                     {
614*cdf0e10cSrcweir                                         awt::Size aUnoSize;
615*cdf0e10cSrcweir                                         awt::Point aCaptionPoint;
616*cdf0e10cSrcweir                                         ScRange aRange;
617*cdf0e10cSrcweir                                         awt::Point aUnoPoint(lcl_GetRelativePos( xShape, pDoc, nTab, aRange, aUnoSize, aCaptionPoint ));
618*cdf0e10cSrcweir                                         Rectangle aRect(pDoc->GetMMRect( aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row(), aRange.aStart.Tab() ));
619*cdf0e10cSrcweir                                         Point aPoint(aRect.TopRight());
620*cdf0e10cSrcweir                                         Point aEndPoint(aRect.BottomLeft());
621*cdf0e10cSrcweir                                         aUnoPoint.Y = nPos;
622*cdf0e10cSrcweir                                         aUnoPoint.Y += aPoint.Y();
623*cdf0e10cSrcweir                                         if (aUnoPoint.Y > aEndPoint.Y())
624*cdf0e10cSrcweir                                             aUnoPoint.Y = aEndPoint.Y() - 2;
625*cdf0e10cSrcweir                                         if (aCaptionPoint.Y < 0)
626*cdf0e10cSrcweir                                             aUnoPoint.Y -= aCaptionPoint.Y;
627*cdf0e10cSrcweir                                         aUnoPoint.X = xShape->getPosition().X;
628*cdf0e10cSrcweir                                         xShape->setPosition(aUnoPoint);
629*cdf0e10cSrcweir                                         pDocSh->SetModified();
630*cdf0e10cSrcweir                                     }
631*cdf0e10cSrcweir                                     else
632*cdf0e10cSrcweir                                     {
633*cdf0e10cSrcweir                                         DBG_ERROR("unknown anchor type");
634*cdf0e10cSrcweir                                     }
635*cdf0e10cSrcweir                                 }
636*cdf0e10cSrcweir                             }
637*cdf0e10cSrcweir                         }
638*cdf0e10cSrcweir                     }
639*cdf0e10cSrcweir                 }
640*cdf0e10cSrcweir             }
641*cdf0e10cSrcweir         }
642*cdf0e10cSrcweir     }
643*cdf0e10cSrcweir 	else
644*cdf0e10cSrcweir 	{
645*cdf0e10cSrcweir         GetShapePropertySet();
646*cdf0e10cSrcweir         if (pShapePropertySet)
647*cdf0e10cSrcweir             pShapePropertySet->setPropertyValue( aPropertyName, aValue );
648*cdf0e10cSrcweir 	}
649*cdf0e10cSrcweir }
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir uno::Any SAL_CALL ScShapeObj::getPropertyValue( const rtl::OUString& aPropertyName )
652*cdf0e10cSrcweir 				throw(beans::UnknownPropertyException, lang::WrappedTargetException,
653*cdf0e10cSrcweir 						uno::RuntimeException)
654*cdf0e10cSrcweir {
655*cdf0e10cSrcweir 	ScUnoGuard aGuard;
656*cdf0e10cSrcweir 	String aNameString = aPropertyName;
657*cdf0e10cSrcweir 
658*cdf0e10cSrcweir 	uno::Any aAny;
659*cdf0e10cSrcweir 	if ( aNameString.EqualsAscii( SC_UNONAME_ANCHOR ) )
660*cdf0e10cSrcweir     {
661*cdf0e10cSrcweir 		SdrObject *pObj = GetSdrObject();
662*cdf0e10cSrcweir 		if (pObj)
663*cdf0e10cSrcweir 		{
664*cdf0e10cSrcweir 		    ScDrawLayer* pModel = (ScDrawLayer*)pObj->GetModel();
665*cdf0e10cSrcweir 		    SdrPage* pPage = pObj->GetPage();
666*cdf0e10cSrcweir 		    if ( pModel && pPage )
667*cdf0e10cSrcweir 		    {
668*cdf0e10cSrcweir 			    ScDocument* pDoc = pModel->GetDocument();
669*cdf0e10cSrcweir 			    if ( pDoc )
670*cdf0e10cSrcweir 			    {
671*cdf0e10cSrcweir 					SCTAB nTab = 0;
672*cdf0e10cSrcweir 					if ( lcl_GetPageNum( pPage, *pModel, nTab ) )
673*cdf0e10cSrcweir 					{
674*cdf0e10cSrcweir 				        SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
675*cdf0e10cSrcweir 				        if ( pObjSh && pObjSh->ISA(ScDocShell) )
676*cdf0e10cSrcweir 				        {
677*cdf0e10cSrcweir 					        ScDocShell* pDocSh = (ScDocShell*)pObjSh;
678*cdf0e10cSrcweir                 		    uno::Reference< uno::XInterface > xAnchor;
679*cdf0e10cSrcweir 			                if (ScDrawLayer::GetAnchor(pObj) == SCA_CELL)
680*cdf0e10cSrcweir                             {
681*cdf0e10cSrcweir                                 uno::Reference<drawing::XShape> xShape( mxShapeAgg, uno::UNO_QUERY );
682*cdf0e10cSrcweir                                 if (xShape.is())
683*cdf0e10cSrcweir                                 {
684*cdf0e10cSrcweir                                     awt::Size aUnoSize;
685*cdf0e10cSrcweir                                     awt::Point aCaptionPoint;
686*cdf0e10cSrcweir                                     ScRange aRange;
687*cdf0e10cSrcweir                                     awt::Point aUnoPoint(lcl_GetRelativePos( xShape, pDoc, nTab, aRange, aUnoSize, aCaptionPoint ));
688*cdf0e10cSrcweir 
689*cdf0e10cSrcweir     						        xAnchor.set(static_cast<cppu::OWeakObject*>(new ScCellObj( pDocSh, aRange.aStart )));
690*cdf0e10cSrcweir                                 }
691*cdf0e10cSrcweir                             }
692*cdf0e10cSrcweir                             else
693*cdf0e10cSrcweir                             {
694*cdf0e10cSrcweir     						    xAnchor.set(static_cast<cppu::OWeakObject*>(new ScTableSheetObj( pDocSh, nTab )));
695*cdf0e10cSrcweir                             }
696*cdf0e10cSrcweir                             aAny <<= xAnchor;
697*cdf0e10cSrcweir                         }
698*cdf0e10cSrcweir 					}
699*cdf0e10cSrcweir                 }
700*cdf0e10cSrcweir             }
701*cdf0e10cSrcweir         }
702*cdf0e10cSrcweir     }
703*cdf0e10cSrcweir     else if ( aNameString.EqualsAscii( SC_UNONAME_IMAGEMAP ) )
704*cdf0e10cSrcweir 	{
705*cdf0e10cSrcweir 		uno::Reference< uno::XInterface > xImageMap;
706*cdf0e10cSrcweir 		SdrObject* pObj = GetSdrObject();
707*cdf0e10cSrcweir 		if ( pObj )
708*cdf0e10cSrcweir 		{
709*cdf0e10cSrcweir 			ScIMapInfo* pIMapInfo = ScDrawLayer::GetIMapInfo(GetSdrObject());
710*cdf0e10cSrcweir 			if( pIMapInfo )
711*cdf0e10cSrcweir 			{
712*cdf0e10cSrcweir 				const ImageMap& rIMap = pIMapInfo->GetImageMap();
713*cdf0e10cSrcweir 				xImageMap.set(SvUnoImageMap_createInstance( rIMap, GetSupportedMacroItems() ));
714*cdf0e10cSrcweir 			}
715*cdf0e10cSrcweir 			else
716*cdf0e10cSrcweir 				xImageMap = SvUnoImageMap_createInstance( GetSupportedMacroItems() );
717*cdf0e10cSrcweir 		}
718*cdf0e10cSrcweir 		aAny <<= uno::Reference< container::XIndexContainer >::query( xImageMap );
719*cdf0e10cSrcweir 	}
720*cdf0e10cSrcweir     else if ( aNameString.EqualsAscii( SC_UNONAME_HORIPOS ) )
721*cdf0e10cSrcweir     {
722*cdf0e10cSrcweir 		SdrObject *pObj = GetSdrObject();
723*cdf0e10cSrcweir 		if (pObj)
724*cdf0e10cSrcweir 		{
725*cdf0e10cSrcweir 		    ScDrawLayer* pModel = (ScDrawLayer*)pObj->GetModel();
726*cdf0e10cSrcweir 		    SdrPage* pPage = pObj->GetPage();
727*cdf0e10cSrcweir 		    if ( pModel && pPage )
728*cdf0e10cSrcweir 		    {
729*cdf0e10cSrcweir 			    ScDocument* pDoc = pModel->GetDocument();
730*cdf0e10cSrcweir 			    if ( pDoc )
731*cdf0e10cSrcweir 			    {
732*cdf0e10cSrcweir 					SCTAB nTab = 0;
733*cdf0e10cSrcweir 					if ( lcl_GetPageNum( pPage, *pModel, nTab ) )
734*cdf0e10cSrcweir 					{
735*cdf0e10cSrcweir                         uno::Reference<drawing::XShape> xShape( mxShapeAgg, uno::UNO_QUERY );
736*cdf0e10cSrcweir                         if (xShape.is())
737*cdf0e10cSrcweir                         {
738*cdf0e10cSrcweir 			                if (ScDrawLayer::GetAnchor(pObj) == SCA_CELL)
739*cdf0e10cSrcweir                             {
740*cdf0e10cSrcweir                                 awt::Size aUnoSize;
741*cdf0e10cSrcweir                                 awt::Point aCaptionPoint;
742*cdf0e10cSrcweir                                 ScRange aRange;
743*cdf0e10cSrcweir                                 awt::Point aUnoPoint(lcl_GetRelativePos( xShape, pDoc, nTab, aRange, aUnoSize, aCaptionPoint ));
744*cdf0e10cSrcweir                                 if (pDoc->IsNegativePage(nTab))
745*cdf0e10cSrcweir                                     aUnoPoint.X *= -1;
746*cdf0e10cSrcweir                                 aAny <<= aUnoPoint.X;
747*cdf0e10cSrcweir                             }
748*cdf0e10cSrcweir                             else
749*cdf0e10cSrcweir                             {
750*cdf0e10cSrcweir                                 awt::Point aCaptionPoint;
751*cdf0e10cSrcweir                                 awt::Point aUnoPoint(xShape->getPosition());
752*cdf0e10cSrcweir                                 awt::Size aUnoSize(xShape->getSize());
753*cdf0e10cSrcweir                                 if (pDoc->IsNegativePage(nTab))
754*cdf0e10cSrcweir                                 {
755*cdf0e10cSrcweir                                     aUnoPoint.X *= -1;
756*cdf0e10cSrcweir                                     aUnoPoint.X -= aUnoSize.Width;
757*cdf0e10cSrcweir                                 }
758*cdf0e10cSrcweir                                 if (lcl_GetCaptionPoint(xShape, aCaptionPoint))
759*cdf0e10cSrcweir                                 {
760*cdf0e10cSrcweir                                     if (pDoc->IsNegativePage(nTab))
761*cdf0e10cSrcweir                                     {
762*cdf0e10cSrcweir                                         if (aCaptionPoint.X > 0 && aCaptionPoint.X > aUnoSize.Width)
763*cdf0e10cSrcweir                                             aUnoPoint.X -= aCaptionPoint.X - aUnoSize.Width;
764*cdf0e10cSrcweir                                     }
765*cdf0e10cSrcweir                                     else
766*cdf0e10cSrcweir                                     {
767*cdf0e10cSrcweir                                         if (aCaptionPoint.X < 0)
768*cdf0e10cSrcweir                                             aUnoPoint.X += aCaptionPoint.X;
769*cdf0e10cSrcweir                                     }
770*cdf0e10cSrcweir                                 }
771*cdf0e10cSrcweir                                 aAny <<= aUnoPoint.X;
772*cdf0e10cSrcweir                             }
773*cdf0e10cSrcweir                         }
774*cdf0e10cSrcweir 					}
775*cdf0e10cSrcweir                 }
776*cdf0e10cSrcweir             }
777*cdf0e10cSrcweir         }
778*cdf0e10cSrcweir     }
779*cdf0e10cSrcweir     else if ( aNameString.EqualsAscii( SC_UNONAME_VERTPOS ) )
780*cdf0e10cSrcweir     {
781*cdf0e10cSrcweir 		SdrObject *pObj = GetSdrObject();
782*cdf0e10cSrcweir 		if (pObj)
783*cdf0e10cSrcweir 		{
784*cdf0e10cSrcweir 		    ScDrawLayer* pModel = (ScDrawLayer*)pObj->GetModel();
785*cdf0e10cSrcweir 		    SdrPage* pPage = pObj->GetPage();
786*cdf0e10cSrcweir 		    if ( pModel && pPage )
787*cdf0e10cSrcweir 		    {
788*cdf0e10cSrcweir 			    ScDocument* pDoc = pModel->GetDocument();
789*cdf0e10cSrcweir 			    if ( pDoc )
790*cdf0e10cSrcweir 			    {
791*cdf0e10cSrcweir 					SCTAB nTab = 0;
792*cdf0e10cSrcweir 					if ( lcl_GetPageNum( pPage, *pModel, nTab ) )
793*cdf0e10cSrcweir 					{
794*cdf0e10cSrcweir                         uno::Reference<drawing::XShape> xShape( mxShapeAgg, uno::UNO_QUERY );
795*cdf0e10cSrcweir                         if (xShape.is())
796*cdf0e10cSrcweir                         {
797*cdf0e10cSrcweir                 		    uno::Reference< uno::XInterface > xAnchor;
798*cdf0e10cSrcweir 			                if (ScDrawLayer::GetAnchor(pObj) == SCA_CELL)
799*cdf0e10cSrcweir                             {
800*cdf0e10cSrcweir                                 awt::Size aUnoSize;
801*cdf0e10cSrcweir                                 awt::Point aCaptionPoint;
802*cdf0e10cSrcweir                                 ScRange aRange;
803*cdf0e10cSrcweir                                 awt::Point aUnoPoint(lcl_GetRelativePos( xShape, pDoc, nTab, aRange, aUnoSize, aCaptionPoint ));
804*cdf0e10cSrcweir 
805*cdf0e10cSrcweir                                 aAny <<= aUnoPoint.Y;
806*cdf0e10cSrcweir                             }
807*cdf0e10cSrcweir                             else
808*cdf0e10cSrcweir                             {
809*cdf0e10cSrcweir                                 awt::Point aUnoPoint(xShape->getPosition());
810*cdf0e10cSrcweir                                 awt::Point aCaptionPoint;
811*cdf0e10cSrcweir                                 if (lcl_GetCaptionPoint(xShape, aCaptionPoint))
812*cdf0e10cSrcweir                                 {
813*cdf0e10cSrcweir                                     if (aCaptionPoint.Y < 0)
814*cdf0e10cSrcweir                                         aUnoPoint.Y += aCaptionPoint.Y;
815*cdf0e10cSrcweir                                 }
816*cdf0e10cSrcweir                                 aAny <<= aUnoPoint.Y;
817*cdf0e10cSrcweir                             }
818*cdf0e10cSrcweir                         }
819*cdf0e10cSrcweir 					}
820*cdf0e10cSrcweir                 }
821*cdf0e10cSrcweir             }
822*cdf0e10cSrcweir         }
823*cdf0e10cSrcweir     }
824*cdf0e10cSrcweir 	else
825*cdf0e10cSrcweir 	{
826*cdf0e10cSrcweir         GetShapePropertySet();
827*cdf0e10cSrcweir         if (pShapePropertySet)
828*cdf0e10cSrcweir             aAny = pShapePropertySet->getPropertyValue( aPropertyName );
829*cdf0e10cSrcweir 	}
830*cdf0e10cSrcweir 
831*cdf0e10cSrcweir 	return aAny;
832*cdf0e10cSrcweir }
833*cdf0e10cSrcweir 
834*cdf0e10cSrcweir void SAL_CALL ScShapeObj::addPropertyChangeListener( const rtl::OUString& aPropertyName,
835*cdf0e10cSrcweir 							const uno::Reference<beans::XPropertyChangeListener>& aListener)
836*cdf0e10cSrcweir 							throw(beans::UnknownPropertyException,
837*cdf0e10cSrcweir 									lang::WrappedTargetException, uno::RuntimeException)
838*cdf0e10cSrcweir {
839*cdf0e10cSrcweir 	ScUnoGuard aGuard;
840*cdf0e10cSrcweir 
841*cdf0e10cSrcweir     GetShapePropertySet();
842*cdf0e10cSrcweir     if (pShapePropertySet)
843*cdf0e10cSrcweir         pShapePropertySet->addPropertyChangeListener( aPropertyName, aListener );
844*cdf0e10cSrcweir 
845*cdf0e10cSrcweir     if ( !bInitializedNotifier )
846*cdf0e10cSrcweir     {
847*cdf0e10cSrcweir         // here's the latest chance to initialize the property notification at the SdrObject
848*cdf0e10cSrcweir         // (in the ctor, where we also attempt to do this, we do not necessarily have
849*cdf0e10cSrcweir         // and SdrObject, yet)
850*cdf0e10cSrcweir         SdrObject* pObj = GetSdrObject();
851*cdf0e10cSrcweir         OSL_ENSURE( pObj, "ScShapeObj::addPropertyChangeListener: no SdrObject -> no property change notification!" );
852*cdf0e10cSrcweir         if ( pObj )
853*cdf0e10cSrcweir             lcl_initializeNotifier( *pObj, *this );
854*cdf0e10cSrcweir         bInitializedNotifier = true;
855*cdf0e10cSrcweir     }
856*cdf0e10cSrcweir }
857*cdf0e10cSrcweir 
858*cdf0e10cSrcweir void SAL_CALL ScShapeObj::removePropertyChangeListener( const rtl::OUString& aPropertyName,
859*cdf0e10cSrcweir 							const uno::Reference<beans::XPropertyChangeListener>& aListener)
860*cdf0e10cSrcweir 							throw(beans::UnknownPropertyException,
861*cdf0e10cSrcweir 									lang::WrappedTargetException, uno::RuntimeException)
862*cdf0e10cSrcweir {
863*cdf0e10cSrcweir 	ScUnoGuard aGuard;
864*cdf0e10cSrcweir 
865*cdf0e10cSrcweir     GetShapePropertySet();
866*cdf0e10cSrcweir     if (pShapePropertySet)
867*cdf0e10cSrcweir         pShapePropertySet->removePropertyChangeListener( aPropertyName, aListener );
868*cdf0e10cSrcweir }
869*cdf0e10cSrcweir 
870*cdf0e10cSrcweir void SAL_CALL ScShapeObj::addVetoableChangeListener( const rtl::OUString& aPropertyName,
871*cdf0e10cSrcweir 							const uno::Reference<beans::XVetoableChangeListener>& aListener)
872*cdf0e10cSrcweir 							throw(beans::UnknownPropertyException,
873*cdf0e10cSrcweir 								lang::WrappedTargetException, uno::RuntimeException)
874*cdf0e10cSrcweir {
875*cdf0e10cSrcweir 	ScUnoGuard aGuard;
876*cdf0e10cSrcweir 
877*cdf0e10cSrcweir     GetShapePropertySet();
878*cdf0e10cSrcweir     if (pShapePropertySet)
879*cdf0e10cSrcweir         pShapePropertySet->addVetoableChangeListener( aPropertyName, aListener );
880*cdf0e10cSrcweir }
881*cdf0e10cSrcweir 
882*cdf0e10cSrcweir void SAL_CALL ScShapeObj::removeVetoableChangeListener( const rtl::OUString& aPropertyName,
883*cdf0e10cSrcweir 							const uno::Reference<beans::XVetoableChangeListener>& aListener)
884*cdf0e10cSrcweir 							throw(beans::UnknownPropertyException,
885*cdf0e10cSrcweir 								lang::WrappedTargetException, uno::RuntimeException)
886*cdf0e10cSrcweir {
887*cdf0e10cSrcweir 	ScUnoGuard aGuard;
888*cdf0e10cSrcweir 
889*cdf0e10cSrcweir     GetShapePropertySet();
890*cdf0e10cSrcweir     if (pShapePropertySet)
891*cdf0e10cSrcweir         pShapePropertySet->removeVetoableChangeListener( aPropertyName, aListener );
892*cdf0e10cSrcweir }
893*cdf0e10cSrcweir 
894*cdf0e10cSrcweir //	XPropertyState
895*cdf0e10cSrcweir 
896*cdf0e10cSrcweir beans::PropertyState SAL_CALL ScShapeObj::getPropertyState( const rtl::OUString& aPropertyName )
897*cdf0e10cSrcweir 								throw(beans::UnknownPropertyException, uno::RuntimeException)
898*cdf0e10cSrcweir {
899*cdf0e10cSrcweir 	ScUnoGuard aGuard;
900*cdf0e10cSrcweir 	String aNameString(aPropertyName);
901*cdf0e10cSrcweir 
902*cdf0e10cSrcweir 	beans::PropertyState eRet = beans::PropertyState_DIRECT_VALUE;
903*cdf0e10cSrcweir 	if ( aNameString.EqualsAscii( SC_UNONAME_IMAGEMAP ) )
904*cdf0e10cSrcweir 	{
905*cdf0e10cSrcweir 		// ImageMap is always "direct"
906*cdf0e10cSrcweir 	}
907*cdf0e10cSrcweir     else if ( aNameString.EqualsAscii( SC_UNONAME_ANCHOR ) )
908*cdf0e10cSrcweir 	{
909*cdf0e10cSrcweir 		// Anchor is always "direct"
910*cdf0e10cSrcweir 	}
911*cdf0e10cSrcweir     else if ( aNameString.EqualsAscii( SC_UNONAME_HORIPOS ) )
912*cdf0e10cSrcweir 	{
913*cdf0e10cSrcweir 		// HoriPos is always "direct"
914*cdf0e10cSrcweir 	}
915*cdf0e10cSrcweir     else if ( aNameString.EqualsAscii( SC_UNONAME_VERTPOS ) )
916*cdf0e10cSrcweir 	{
917*cdf0e10cSrcweir 		// VertPos is always "direct"
918*cdf0e10cSrcweir 	}
919*cdf0e10cSrcweir 	else
920*cdf0e10cSrcweir 	{
921*cdf0e10cSrcweir         GetShapePropertyState();
922*cdf0e10cSrcweir         if (pShapePropertyState)
923*cdf0e10cSrcweir             eRet = pShapePropertyState->getPropertyState( aPropertyName );
924*cdf0e10cSrcweir 	}
925*cdf0e10cSrcweir 
926*cdf0e10cSrcweir 	return eRet;
927*cdf0e10cSrcweir }
928*cdf0e10cSrcweir 
929*cdf0e10cSrcweir uno::Sequence<beans::PropertyState> SAL_CALL ScShapeObj::getPropertyStates(
930*cdf0e10cSrcweir 								const uno::Sequence<rtl::OUString>& aPropertyNames )
931*cdf0e10cSrcweir 							throw(beans::UnknownPropertyException, uno::RuntimeException)
932*cdf0e10cSrcweir {
933*cdf0e10cSrcweir 	ScUnoGuard aGuard;
934*cdf0e10cSrcweir 
935*cdf0e10cSrcweir 	//	simple loop to get own and aggregated states
936*cdf0e10cSrcweir 
937*cdf0e10cSrcweir 	const rtl::OUString* pNames = aPropertyNames.getConstArray();
938*cdf0e10cSrcweir 	uno::Sequence<beans::PropertyState> aRet(aPropertyNames.getLength());
939*cdf0e10cSrcweir 	beans::PropertyState* pStates = aRet.getArray();
940*cdf0e10cSrcweir 	for(sal_Int32 i = 0; i < aPropertyNames.getLength(); i++)
941*cdf0e10cSrcweir 		pStates[i] = getPropertyState(pNames[i]);
942*cdf0e10cSrcweir 	return aRet;
943*cdf0e10cSrcweir }
944*cdf0e10cSrcweir 
945*cdf0e10cSrcweir void SAL_CALL ScShapeObj::setPropertyToDefault( const rtl::OUString& aPropertyName )
946*cdf0e10cSrcweir 							throw(beans::UnknownPropertyException, uno::RuntimeException)
947*cdf0e10cSrcweir {
948*cdf0e10cSrcweir 	ScUnoGuard aGuard;
949*cdf0e10cSrcweir 	String aNameString(aPropertyName);
950*cdf0e10cSrcweir 
951*cdf0e10cSrcweir 	if ( aNameString.EqualsAscii( SC_UNONAME_IMAGEMAP ) )
952*cdf0e10cSrcweir 	{
953*cdf0e10cSrcweir 		SdrObject* pObj = GetSdrObject();
954*cdf0e10cSrcweir 		if ( pObj )
955*cdf0e10cSrcweir 		{
956*cdf0e10cSrcweir 			ScIMapInfo* pIMapInfo = ScDrawLayer::GetIMapInfo(pObj);
957*cdf0e10cSrcweir 			if( pIMapInfo )
958*cdf0e10cSrcweir 			{
959*cdf0e10cSrcweir 				ImageMap aEmpty;
960*cdf0e10cSrcweir 				pIMapInfo->SetImageMap( aEmpty );	// replace with empty image map
961*cdf0e10cSrcweir 			}
962*cdf0e10cSrcweir 			else
963*cdf0e10cSrcweir 			{
964*cdf0e10cSrcweir 				// nothing to do (no need to insert user data for an empty map)
965*cdf0e10cSrcweir 			}
966*cdf0e10cSrcweir 		}
967*cdf0e10cSrcweir 	}
968*cdf0e10cSrcweir 	else
969*cdf0e10cSrcweir 	{
970*cdf0e10cSrcweir         GetShapePropertyState();
971*cdf0e10cSrcweir         if (pShapePropertyState)
972*cdf0e10cSrcweir             pShapePropertyState->setPropertyToDefault( aPropertyName );
973*cdf0e10cSrcweir 	}
974*cdf0e10cSrcweir }
975*cdf0e10cSrcweir 
976*cdf0e10cSrcweir uno::Any SAL_CALL ScShapeObj::getPropertyDefault( const rtl::OUString& aPropertyName )
977*cdf0e10cSrcweir 								throw(beans::UnknownPropertyException, lang::WrappedTargetException,
978*cdf0e10cSrcweir 										uno::RuntimeException)
979*cdf0e10cSrcweir {
980*cdf0e10cSrcweir 	ScUnoGuard aGuard;
981*cdf0e10cSrcweir 	String aNameString = aPropertyName;
982*cdf0e10cSrcweir 
983*cdf0e10cSrcweir 	uno::Any aAny;
984*cdf0e10cSrcweir 	if ( aNameString.EqualsAscii( SC_UNONAME_IMAGEMAP ) )
985*cdf0e10cSrcweir 	{
986*cdf0e10cSrcweir 		//	default: empty ImageMap
987*cdf0e10cSrcweir 		uno::Reference< uno::XInterface > xImageMap(SvUnoImageMap_createInstance( GetSupportedMacroItems() ));
988*cdf0e10cSrcweir 		aAny <<= uno::Reference< container::XIndexContainer >::query( xImageMap );
989*cdf0e10cSrcweir 	}
990*cdf0e10cSrcweir 	else
991*cdf0e10cSrcweir 	{
992*cdf0e10cSrcweir         GetShapePropertyState();
993*cdf0e10cSrcweir         if (pShapePropertyState)
994*cdf0e10cSrcweir             aAny = pShapePropertyState->getPropertyDefault( aPropertyName );
995*cdf0e10cSrcweir 	}
996*cdf0e10cSrcweir 
997*cdf0e10cSrcweir 	return aAny;
998*cdf0e10cSrcweir }
999*cdf0e10cSrcweir 
1000*cdf0e10cSrcweir // XTextContent
1001*cdf0e10cSrcweir 
1002*cdf0e10cSrcweir void SAL_CALL ScShapeObj::attach( const uno::Reference<text::XTextRange>& /* xTextRange */ )
1003*cdf0e10cSrcweir 								throw(lang::IllegalArgumentException, uno::RuntimeException)
1004*cdf0e10cSrcweir {
1005*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1006*cdf0e10cSrcweir 
1007*cdf0e10cSrcweir 	throw lang::IllegalArgumentException();		// anchor cannot be changed
1008*cdf0e10cSrcweir }
1009*cdf0e10cSrcweir 
1010*cdf0e10cSrcweir uno::Reference<text::XTextRange> SAL_CALL ScShapeObj::getAnchor() throw(uno::RuntimeException)
1011*cdf0e10cSrcweir {
1012*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1013*cdf0e10cSrcweir 
1014*cdf0e10cSrcweir 	uno::Reference<text::XTextRange> xRet;
1015*cdf0e10cSrcweir 
1016*cdf0e10cSrcweir 	SdrObject* pObj = GetSdrObject();
1017*cdf0e10cSrcweir 	if( pObj )
1018*cdf0e10cSrcweir 	{
1019*cdf0e10cSrcweir 		ScDrawLayer* pModel = (ScDrawLayer*)pObj->GetModel();
1020*cdf0e10cSrcweir 		SdrPage* pPage = pObj->GetPage();
1021*cdf0e10cSrcweir 		if ( pModel )
1022*cdf0e10cSrcweir 		{
1023*cdf0e10cSrcweir 			ScDocument* pDoc = pModel->GetDocument();
1024*cdf0e10cSrcweir 			if ( pDoc )
1025*cdf0e10cSrcweir 			{
1026*cdf0e10cSrcweir 				SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
1027*cdf0e10cSrcweir 				if ( pObjSh && pObjSh->ISA(ScDocShell) )
1028*cdf0e10cSrcweir 				{
1029*cdf0e10cSrcweir 					ScDocShell* pDocSh = (ScDocShell*)pObjSh;
1030*cdf0e10cSrcweir 
1031*cdf0e10cSrcweir 					SCTAB nTab = 0;
1032*cdf0e10cSrcweir 					if ( lcl_GetPageNum( pPage, *pModel, nTab ) )
1033*cdf0e10cSrcweir 					{
1034*cdf0e10cSrcweir 						Point aPos(pObj->GetCurrentBoundRect().TopLeft());
1035*cdf0e10cSrcweir 						ScRange aRange(pDoc->GetRange( nTab, Rectangle( aPos, aPos ) ));
1036*cdf0e10cSrcweir 
1037*cdf0e10cSrcweir 						//	anchor is always the cell
1038*cdf0e10cSrcweir 
1039*cdf0e10cSrcweir 						xRet.set(new ScCellObj( pDocSh, aRange.aStart ));
1040*cdf0e10cSrcweir 					}
1041*cdf0e10cSrcweir 				}
1042*cdf0e10cSrcweir 			}
1043*cdf0e10cSrcweir 		}
1044*cdf0e10cSrcweir 	}
1045*cdf0e10cSrcweir 
1046*cdf0e10cSrcweir 	return xRet;
1047*cdf0e10cSrcweir }
1048*cdf0e10cSrcweir 
1049*cdf0e10cSrcweir // XComponent
1050*cdf0e10cSrcweir 
1051*cdf0e10cSrcweir void SAL_CALL ScShapeObj::dispose() throw(uno::RuntimeException)
1052*cdf0e10cSrcweir {
1053*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1054*cdf0e10cSrcweir 
1055*cdf0e10cSrcweir 	uno::Reference<lang::XComponent> xAggComp(lcl_GetComponent(mxShapeAgg));
1056*cdf0e10cSrcweir 	if ( xAggComp.is() )
1057*cdf0e10cSrcweir 		xAggComp->dispose();
1058*cdf0e10cSrcweir }
1059*cdf0e10cSrcweir 
1060*cdf0e10cSrcweir void SAL_CALL ScShapeObj::addEventListener(
1061*cdf0e10cSrcweir 						const uno::Reference<lang::XEventListener>& xListener )
1062*cdf0e10cSrcweir 													throw(uno::RuntimeException)
1063*cdf0e10cSrcweir {
1064*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1065*cdf0e10cSrcweir 
1066*cdf0e10cSrcweir 	uno::Reference<lang::XComponent> xAggComp(lcl_GetComponent(mxShapeAgg));
1067*cdf0e10cSrcweir 	if ( xAggComp.is() )
1068*cdf0e10cSrcweir 		xAggComp->addEventListener(xListener);
1069*cdf0e10cSrcweir }
1070*cdf0e10cSrcweir 
1071*cdf0e10cSrcweir void SAL_CALL ScShapeObj::removeEventListener(
1072*cdf0e10cSrcweir 						const uno::Reference<lang::XEventListener>& xListener )
1073*cdf0e10cSrcweir 													throw(uno::RuntimeException)
1074*cdf0e10cSrcweir {
1075*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1076*cdf0e10cSrcweir 
1077*cdf0e10cSrcweir 	uno::Reference<lang::XComponent> xAggComp(lcl_GetComponent(mxShapeAgg));
1078*cdf0e10cSrcweir 	if ( xAggComp.is() )
1079*cdf0e10cSrcweir 		xAggComp->removeEventListener(xListener);
1080*cdf0e10cSrcweir }
1081*cdf0e10cSrcweir 
1082*cdf0e10cSrcweir // XText
1083*cdf0e10cSrcweir // (special handling for ScCellFieldObj)
1084*cdf0e10cSrcweir 
1085*cdf0e10cSrcweir void lcl_CopyOneProperty( beans::XPropertySet& rDest, beans::XPropertySet& rSource, const sal_Char* pName )
1086*cdf0e10cSrcweir {
1087*cdf0e10cSrcweir 	rtl::OUString aNameStr(rtl::OUString::createFromAscii(pName));
1088*cdf0e10cSrcweir 	try
1089*cdf0e10cSrcweir 	{
1090*cdf0e10cSrcweir 		rDest.setPropertyValue( aNameStr, rSource.getPropertyValue( aNameStr ) );
1091*cdf0e10cSrcweir 	}
1092*cdf0e10cSrcweir 	catch (uno::Exception&)
1093*cdf0e10cSrcweir 	{
1094*cdf0e10cSrcweir 		DBG_ERROR("Exception in text field");
1095*cdf0e10cSrcweir 	}
1096*cdf0e10cSrcweir }
1097*cdf0e10cSrcweir 
1098*cdf0e10cSrcweir void SAL_CALL ScShapeObj::insertTextContent( const uno::Reference<text::XTextRange>& xRange,
1099*cdf0e10cSrcweir 												const uno::Reference<text::XTextContent>& xContent,
1100*cdf0e10cSrcweir 												sal_Bool bAbsorb )
1101*cdf0e10cSrcweir 									throw(lang::IllegalArgumentException, uno::RuntimeException)
1102*cdf0e10cSrcweir {
1103*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1104*cdf0e10cSrcweir 
1105*cdf0e10cSrcweir 	uno::Reference<text::XTextContent> xEffContent;
1106*cdf0e10cSrcweir 
1107*cdf0e10cSrcweir 	ScCellFieldObj* pCellField = ScCellFieldObj::getImplementation( xContent );
1108*cdf0e10cSrcweir 	if ( pCellField )
1109*cdf0e10cSrcweir 	{
1110*cdf0e10cSrcweir 		//	#105585# createInstance("TextField.URL") from the document creates a ScCellFieldObj.
1111*cdf0e10cSrcweir 		//	To insert it into drawing text, a SvxUnoTextField is needed instead.
1112*cdf0e10cSrcweir 		//	The ScCellFieldObj object is left in non-inserted state.
1113*cdf0e10cSrcweir 
1114*cdf0e10cSrcweir 		SvxUnoTextField* pDrawField = new SvxUnoTextField( ID_URLFIELD );
1115*cdf0e10cSrcweir 		xEffContent.set(pDrawField);
1116*cdf0e10cSrcweir 		lcl_CopyOneProperty( *pDrawField, *pCellField, SC_UNONAME_URL );
1117*cdf0e10cSrcweir 		lcl_CopyOneProperty( *pDrawField, *pCellField, SC_UNONAME_REPR );
1118*cdf0e10cSrcweir 		lcl_CopyOneProperty( *pDrawField, *pCellField, SC_UNONAME_TARGET );
1119*cdf0e10cSrcweir 	}
1120*cdf0e10cSrcweir 	else
1121*cdf0e10cSrcweir 		xEffContent.set(xContent);
1122*cdf0e10cSrcweir 
1123*cdf0e10cSrcweir 	uno::Reference<text::XText> xAggText(lcl_GetText(mxShapeAgg));
1124*cdf0e10cSrcweir 	if ( xAggText.is() )
1125*cdf0e10cSrcweir 		xAggText->insertTextContent( xRange, xEffContent, bAbsorb );
1126*cdf0e10cSrcweir }
1127*cdf0e10cSrcweir 
1128*cdf0e10cSrcweir void SAL_CALL ScShapeObj::removeTextContent( const uno::Reference<text::XTextContent>& xContent )
1129*cdf0e10cSrcweir 								throw(container::NoSuchElementException, uno::RuntimeException)
1130*cdf0e10cSrcweir {
1131*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1132*cdf0e10cSrcweir 
1133*cdf0e10cSrcweir 	//	ScCellFieldObj can't be used here.
1134*cdf0e10cSrcweir 
1135*cdf0e10cSrcweir 	uno::Reference<text::XText> xAggText(lcl_GetText(mxShapeAgg));
1136*cdf0e10cSrcweir 	if ( xAggText.is() )
1137*cdf0e10cSrcweir 		xAggText->removeTextContent( xContent );
1138*cdf0e10cSrcweir }
1139*cdf0e10cSrcweir 
1140*cdf0e10cSrcweir // XSimpleText (parent of XText)
1141*cdf0e10cSrcweir // Use own SvxUnoTextCursor subclass - everything is just passed to aggregated object
1142*cdf0e10cSrcweir 
1143*cdf0e10cSrcweir uno::Reference<text::XTextCursor> SAL_CALL ScShapeObj::createTextCursor()
1144*cdf0e10cSrcweir 													throw(uno::RuntimeException)
1145*cdf0e10cSrcweir {
1146*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1147*cdf0e10cSrcweir 
1148*cdf0e10cSrcweir 	if ( mxShapeAgg.is() )
1149*cdf0e10cSrcweir 	{
1150*cdf0e10cSrcweir 		//	ScDrawTextCursor must be used to ensure the ScShapeObj is returned by getText
1151*cdf0e10cSrcweir 
1152*cdf0e10cSrcweir 		SvxUnoTextBase* pText = SvxUnoTextBase::getImplementation( mxShapeAgg );
1153*cdf0e10cSrcweir 		if (pText)
1154*cdf0e10cSrcweir 			return new ScDrawTextCursor( this, *pText );
1155*cdf0e10cSrcweir 	}
1156*cdf0e10cSrcweir 
1157*cdf0e10cSrcweir 	return uno::Reference<text::XTextCursor>();
1158*cdf0e10cSrcweir }
1159*cdf0e10cSrcweir 
1160*cdf0e10cSrcweir uno::Reference<text::XTextCursor> SAL_CALL ScShapeObj::createTextCursorByRange(
1161*cdf0e10cSrcweir 									const uno::Reference<text::XTextRange>& aTextPosition )
1162*cdf0e10cSrcweir 													throw(uno::RuntimeException)
1163*cdf0e10cSrcweir {
1164*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1165*cdf0e10cSrcweir 
1166*cdf0e10cSrcweir 	if ( mxShapeAgg.is() && aTextPosition.is() )
1167*cdf0e10cSrcweir 	{
1168*cdf0e10cSrcweir 		//	ScDrawTextCursor must be used to ensure the ScShapeObj is returned by getText
1169*cdf0e10cSrcweir 
1170*cdf0e10cSrcweir 		SvxUnoTextBase* pText = SvxUnoTextBase::getImplementation( mxShapeAgg );
1171*cdf0e10cSrcweir 		SvxUnoTextRangeBase* pRange = SvxUnoTextRangeBase::getImplementation( aTextPosition );
1172*cdf0e10cSrcweir 		if ( pText && pRange )
1173*cdf0e10cSrcweir 		{
1174*cdf0e10cSrcweir 			SvxUnoTextCursor* pCursor = new ScDrawTextCursor( this, *pText );
1175*cdf0e10cSrcweir 			uno::Reference<text::XTextCursor> xCursor( pCursor );
1176*cdf0e10cSrcweir 			pCursor->SetSelection( pRange->GetSelection() );
1177*cdf0e10cSrcweir 			return xCursor;
1178*cdf0e10cSrcweir 		}
1179*cdf0e10cSrcweir 	}
1180*cdf0e10cSrcweir 
1181*cdf0e10cSrcweir 	return uno::Reference<text::XTextCursor>();
1182*cdf0e10cSrcweir }
1183*cdf0e10cSrcweir 
1184*cdf0e10cSrcweir void SAL_CALL ScShapeObj::insertString( const uno::Reference<text::XTextRange>& xRange,
1185*cdf0e10cSrcweir 										const rtl::OUString& aString, sal_Bool bAbsorb )
1186*cdf0e10cSrcweir 									throw(uno::RuntimeException)
1187*cdf0e10cSrcweir {
1188*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1189*cdf0e10cSrcweir 
1190*cdf0e10cSrcweir 	uno::Reference<text::XSimpleText> xAggSimpleText(lcl_GetSimpleText(mxShapeAgg));
1191*cdf0e10cSrcweir 	if ( xAggSimpleText.is() )
1192*cdf0e10cSrcweir 		xAggSimpleText->insertString( xRange, aString, bAbsorb );
1193*cdf0e10cSrcweir 	else
1194*cdf0e10cSrcweir 		throw uno::RuntimeException();
1195*cdf0e10cSrcweir }
1196*cdf0e10cSrcweir 
1197*cdf0e10cSrcweir void SAL_CALL ScShapeObj::insertControlCharacter( const uno::Reference<text::XTextRange>& xRange,
1198*cdf0e10cSrcweir 												sal_Int16 nControlCharacter, sal_Bool bAbsorb )
1199*cdf0e10cSrcweir 									throw(lang::IllegalArgumentException, uno::RuntimeException)
1200*cdf0e10cSrcweir {
1201*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1202*cdf0e10cSrcweir 
1203*cdf0e10cSrcweir 	uno::Reference<text::XSimpleText> xAggSimpleText(lcl_GetSimpleText(mxShapeAgg));
1204*cdf0e10cSrcweir 	if ( xAggSimpleText.is() )
1205*cdf0e10cSrcweir 		xAggSimpleText->insertControlCharacter( xRange, nControlCharacter, bAbsorb );
1206*cdf0e10cSrcweir 	else
1207*cdf0e10cSrcweir 		throw uno::RuntimeException();
1208*cdf0e10cSrcweir }
1209*cdf0e10cSrcweir 
1210*cdf0e10cSrcweir // XTextRange
1211*cdf0e10cSrcweir // (parent of XSimpleText)
1212*cdf0e10cSrcweir 
1213*cdf0e10cSrcweir uno::Reference<text::XText> SAL_CALL ScShapeObj::getText() throw(uno::RuntimeException)
1214*cdf0e10cSrcweir {
1215*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1216*cdf0e10cSrcweir 	return this;
1217*cdf0e10cSrcweir }
1218*cdf0e10cSrcweir 
1219*cdf0e10cSrcweir uno::Reference<text::XTextRange> SAL_CALL ScShapeObj::getStart() throw(uno::RuntimeException)
1220*cdf0e10cSrcweir {
1221*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1222*cdf0e10cSrcweir 
1223*cdf0e10cSrcweir 	uno::Reference<text::XTextRange> xAggTextRange(lcl_GetTextRange(mxShapeAgg));
1224*cdf0e10cSrcweir 	if ( xAggTextRange.is() )
1225*cdf0e10cSrcweir 		return xAggTextRange->getStart();
1226*cdf0e10cSrcweir 	else
1227*cdf0e10cSrcweir 		throw uno::RuntimeException();
1228*cdf0e10cSrcweir 
1229*cdf0e10cSrcweir //    return uno::Reference<text::XTextRange>();
1230*cdf0e10cSrcweir }
1231*cdf0e10cSrcweir 
1232*cdf0e10cSrcweir uno::Reference<text::XTextRange> SAL_CALL ScShapeObj::getEnd() throw(uno::RuntimeException)
1233*cdf0e10cSrcweir {
1234*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1235*cdf0e10cSrcweir 
1236*cdf0e10cSrcweir 	uno::Reference<text::XTextRange> xAggTextRange(lcl_GetTextRange(mxShapeAgg));
1237*cdf0e10cSrcweir 	if ( xAggTextRange.is() )
1238*cdf0e10cSrcweir 		return xAggTextRange->getEnd();
1239*cdf0e10cSrcweir 	else
1240*cdf0e10cSrcweir 		throw uno::RuntimeException();
1241*cdf0e10cSrcweir 
1242*cdf0e10cSrcweir //    return uno::Reference<text::XTextRange>();
1243*cdf0e10cSrcweir }
1244*cdf0e10cSrcweir 
1245*cdf0e10cSrcweir rtl::OUString SAL_CALL ScShapeObj::getString() throw(uno::RuntimeException)
1246*cdf0e10cSrcweir {
1247*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1248*cdf0e10cSrcweir 
1249*cdf0e10cSrcweir 	uno::Reference<text::XTextRange> xAggTextRange(lcl_GetTextRange(mxShapeAgg));
1250*cdf0e10cSrcweir 	if ( xAggTextRange.is() )
1251*cdf0e10cSrcweir 		return xAggTextRange->getString();
1252*cdf0e10cSrcweir 	else
1253*cdf0e10cSrcweir 		throw uno::RuntimeException();
1254*cdf0e10cSrcweir 
1255*cdf0e10cSrcweir //    return rtl::OUString();
1256*cdf0e10cSrcweir }
1257*cdf0e10cSrcweir 
1258*cdf0e10cSrcweir void SAL_CALL ScShapeObj::setString( const rtl::OUString& aText ) throw(uno::RuntimeException)
1259*cdf0e10cSrcweir {
1260*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1261*cdf0e10cSrcweir 
1262*cdf0e10cSrcweir 	uno::Reference<text::XTextRange> xAggTextRange(lcl_GetTextRange(mxShapeAgg));
1263*cdf0e10cSrcweir 	if ( xAggTextRange.is() )
1264*cdf0e10cSrcweir 		xAggTextRange->setString( aText );
1265*cdf0e10cSrcweir 	else
1266*cdf0e10cSrcweir 		throw uno::RuntimeException();
1267*cdf0e10cSrcweir }
1268*cdf0e10cSrcweir 
1269*cdf0e10cSrcweir // XChild
1270*cdf0e10cSrcweir 
1271*cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL ScShapeObj::getParent() throw (uno::RuntimeException)
1272*cdf0e10cSrcweir {
1273*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1274*cdf0e10cSrcweir 
1275*cdf0e10cSrcweir     // receive cell position from caption object (parent of a note caption is the note cell)
1276*cdf0e10cSrcweir 	SdrObject* pObj = GetSdrObject();
1277*cdf0e10cSrcweir 	if( pObj )
1278*cdf0e10cSrcweir 	{
1279*cdf0e10cSrcweir 		ScDrawLayer* pModel = (ScDrawLayer*)pObj->GetModel();
1280*cdf0e10cSrcweir 		SdrPage* pPage = pObj->GetPage();
1281*cdf0e10cSrcweir 		if ( pModel )
1282*cdf0e10cSrcweir 		{
1283*cdf0e10cSrcweir 			ScDocument* pDoc = pModel->GetDocument();
1284*cdf0e10cSrcweir 			if ( pDoc )
1285*cdf0e10cSrcweir 			{
1286*cdf0e10cSrcweir 				SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
1287*cdf0e10cSrcweir 				if ( pObjSh && pObjSh->ISA(ScDocShell) )
1288*cdf0e10cSrcweir 				{
1289*cdf0e10cSrcweir 					ScDocShell* pDocSh = (ScDocShell*)pObjSh;
1290*cdf0e10cSrcweir 
1291*cdf0e10cSrcweir 					SCTAB nTab = 0;
1292*cdf0e10cSrcweir 					if ( lcl_GetPageNum( pPage, *pModel, nTab ) )
1293*cdf0e10cSrcweir 					{
1294*cdf0e10cSrcweir                         const ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObj, nTab );
1295*cdf0e10cSrcweir                         if( pCaptData )
1296*cdf0e10cSrcweir                             return static_cast< ::cppu::OWeakObject* >( new ScCellObj( pDocSh, pCaptData->maStart ) );
1297*cdf0e10cSrcweir                     }
1298*cdf0e10cSrcweir                 }
1299*cdf0e10cSrcweir             }
1300*cdf0e10cSrcweir         }
1301*cdf0e10cSrcweir     }
1302*cdf0e10cSrcweir 
1303*cdf0e10cSrcweir 	return 0;
1304*cdf0e10cSrcweir }
1305*cdf0e10cSrcweir 
1306*cdf0e10cSrcweir void SAL_CALL ScShapeObj::setParent( const uno::Reference< uno::XInterface >& ) throw (lang::NoSupportException, uno::RuntimeException)
1307*cdf0e10cSrcweir {
1308*cdf0e10cSrcweir     throw lang::NoSupportException();
1309*cdf0e10cSrcweir }
1310*cdf0e10cSrcweir 
1311*cdf0e10cSrcweir // XTypeProvider
1312*cdf0e10cSrcweir 
1313*cdf0e10cSrcweir uno::Sequence<uno::Type> SAL_CALL ScShapeObj::getTypes() throw(uno::RuntimeException)
1314*cdf0e10cSrcweir {
1315*cdf0e10cSrcweir     uno::Sequence< uno::Type > aBaseTypes( ScShapeObj_Base::getTypes() );
1316*cdf0e10cSrcweir 
1317*cdf0e10cSrcweir     uno::Sequence< uno::Type > aTextTypes;
1318*cdf0e10cSrcweir     if ( bIsTextShape )
1319*cdf0e10cSrcweir         aTextTypes = ScShapeObj_TextBase::getTypes();
1320*cdf0e10cSrcweir 
1321*cdf0e10cSrcweir 	uno::Reference<lang::XTypeProvider> xBaseProvider;
1322*cdf0e10cSrcweir 	if ( mxShapeAgg.is() )
1323*cdf0e10cSrcweir 		mxShapeAgg->queryAggregation( getCppuType((uno::Reference<lang::XTypeProvider>*) 0) ) >>= xBaseProvider;
1324*cdf0e10cSrcweir 	DBG_ASSERT( xBaseProvider.is(), "ScShapeObj: No XTypeProvider from aggregated shape!" );
1325*cdf0e10cSrcweir 
1326*cdf0e10cSrcweir     uno::Sequence< uno::Type > aAggTypes;
1327*cdf0e10cSrcweir 	if( xBaseProvider.is() )
1328*cdf0e10cSrcweir 		aAggTypes = xBaseProvider->getTypes();
1329*cdf0e10cSrcweir 
1330*cdf0e10cSrcweir     return ::comphelper::concatSequences( aBaseTypes, aTextTypes, aAggTypes );
1331*cdf0e10cSrcweir }
1332*cdf0e10cSrcweir 
1333*cdf0e10cSrcweir uno::Sequence<sal_Int8> SAL_CALL ScShapeObj::getImplementationId()
1334*cdf0e10cSrcweir 													throw(uno::RuntimeException)
1335*cdf0e10cSrcweir {
1336*cdf0e10cSrcweir     ScUnoGuard aGuard;
1337*cdf0e10cSrcweir 	// do we need to compute the implementation id for this instance?
1338*cdf0e10cSrcweir     if( !pImplementationId && mxShapeAgg.is())
1339*cdf0e10cSrcweir 	{
1340*cdf0e10cSrcweir         uno::Reference< drawing::XShape > xAggShape;
1341*cdf0e10cSrcweir         mxShapeAgg->queryAggregation( ::getCppuType((uno::Reference< drawing::XShape >*)0) ) >>= xAggShape;
1342*cdf0e10cSrcweir 
1343*cdf0e10cSrcweir         if( xAggShape.is() )
1344*cdf0e10cSrcweir 		{
1345*cdf0e10cSrcweir             const rtl::OUString aShapeType( xAggShape->getShapeType() );
1346*cdf0e10cSrcweir             // did we already compute an implementation id for the agregated shape type?
1347*cdf0e10cSrcweir             ScShapeImplementationIdMap::iterator aIter( aImplementationIdMap.find(aShapeType ) );
1348*cdf0e10cSrcweir 			if( aIter == aImplementationIdMap.end() )
1349*cdf0e10cSrcweir 			{
1350*cdf0e10cSrcweir 				// we need to create a new implementation id for this
1351*cdf0e10cSrcweir 				// note: this memory is not free'd until application exists
1352*cdf0e10cSrcweir 				//		 but since we have a fixed set of shapetypes and the
1353*cdf0e10cSrcweir 				//		 memory will be reused this is ok.
1354*cdf0e10cSrcweir                 pImplementationId = new uno::Sequence< sal_Int8 >( 16 );
1355*cdf0e10cSrcweir                 rtl_createUuid( (sal_uInt8 *) pImplementationId->getArray(), 0, sal_True );
1356*cdf0e10cSrcweir                 aImplementationIdMap[ aShapeType ] = pImplementationId;
1357*cdf0e10cSrcweir 			}
1358*cdf0e10cSrcweir 			else
1359*cdf0e10cSrcweir 			{
1360*cdf0e10cSrcweir 				// use the already computed implementation id
1361*cdf0e10cSrcweir                 pImplementationId = (*aIter).second;
1362*cdf0e10cSrcweir 			}
1363*cdf0e10cSrcweir 		}
1364*cdf0e10cSrcweir 	}
1365*cdf0e10cSrcweir     if( NULL == pImplementationId )
1366*cdf0e10cSrcweir 	{
1367*cdf0e10cSrcweir         DBG_ERROR( "Could not create an implementation id for a ScXShape!" );
1368*cdf0e10cSrcweir         return uno::Sequence< sal_Int8 > ();
1369*cdf0e10cSrcweir 	}
1370*cdf0e10cSrcweir 	else
1371*cdf0e10cSrcweir 	{
1372*cdf0e10cSrcweir         return *pImplementationId;
1373*cdf0e10cSrcweir 	}
1374*cdf0e10cSrcweir }
1375*cdf0e10cSrcweir 
1376*cdf0e10cSrcweir SdrObject* ScShapeObj::GetSdrObject() const throw()
1377*cdf0e10cSrcweir {
1378*cdf0e10cSrcweir 	if(mxShapeAgg.is())
1379*cdf0e10cSrcweir 	{
1380*cdf0e10cSrcweir 		SvxShape* pShape = SvxShape::getImplementation( mxShapeAgg );
1381*cdf0e10cSrcweir 		if(pShape)
1382*cdf0e10cSrcweir 			return pShape->GetSdrObject();
1383*cdf0e10cSrcweir 	}
1384*cdf0e10cSrcweir 
1385*cdf0e10cSrcweir 	return NULL;
1386*cdf0e10cSrcweir }
1387*cdf0e10cSrcweir 
1388*cdf0e10cSrcweir #define SC_EVENTACC_ONCLICK     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnClick" ) )
1389*cdf0e10cSrcweir #ifdef ISSUE66550_HLINK_FOR_SHAPES
1390*cdf0e10cSrcweir #define SC_EVENTACC_ONACTION    ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnAction" ) )
1391*cdf0e10cSrcweir #define SC_EVENTACC_URL         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) )
1392*cdf0e10cSrcweir #define SC_EVENTACC_ACTION      ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Action" ) )
1393*cdf0e10cSrcweir #endif
1394*cdf0e10cSrcweir #define SC_EVENTACC_SCRIPT      ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Script" ) )
1395*cdf0e10cSrcweir #define SC_EVENTACC_EVENTTYPE   ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EventType" ) )
1396*cdf0e10cSrcweir 
1397*cdf0e10cSrcweir typedef ::cppu::WeakImplHelper1< container::XNameReplace > ShapeUnoEventAcess_BASE;
1398*cdf0e10cSrcweir class ShapeUnoEventAccessImpl : public ShapeUnoEventAcess_BASE
1399*cdf0e10cSrcweir {
1400*cdf0e10cSrcweir private:
1401*cdf0e10cSrcweir 	ScShapeObj* mpShape;
1402*cdf0e10cSrcweir 
1403*cdf0e10cSrcweir     ScMacroInfo* getInfo( sal_Bool bCreate = sal_False )
1404*cdf0e10cSrcweir 	{
1405*cdf0e10cSrcweir         if( mpShape )
1406*cdf0e10cSrcweir             if( SdrObject* pObj = mpShape->GetSdrObject() )
1407*cdf0e10cSrcweir                 return ScDrawLayer::GetMacroInfo( pObj, bCreate );
1408*cdf0e10cSrcweir         return 0;
1409*cdf0e10cSrcweir 	}
1410*cdf0e10cSrcweir 
1411*cdf0e10cSrcweir public:
1412*cdf0e10cSrcweir 	ShapeUnoEventAccessImpl( ScShapeObj* pShape ): mpShape( pShape )
1413*cdf0e10cSrcweir 	{
1414*cdf0e10cSrcweir 	}
1415*cdf0e10cSrcweir 
1416*cdf0e10cSrcweir 	// XNameReplace
1417*cdf0e10cSrcweir 	virtual void SAL_CALL replaceByName( const rtl::OUString& aName, const uno::Any& aElement ) throw(lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
1418*cdf0e10cSrcweir 	{
1419*cdf0e10cSrcweir         if ( !hasByName( aName ) )
1420*cdf0e10cSrcweir 			throw container::NoSuchElementException();
1421*cdf0e10cSrcweir 		uno::Sequence< beans::PropertyValue > aProperties;
1422*cdf0e10cSrcweir 		aElement >>= aProperties;
1423*cdf0e10cSrcweir 		const beans::PropertyValue* pProperties = aProperties.getConstArray();
1424*cdf0e10cSrcweir 		const sal_Int32 nCount = aProperties.getLength();
1425*cdf0e10cSrcweir 		sal_Int32 nIndex;
1426*cdf0e10cSrcweir 		bool isEventType = false;
1427*cdf0e10cSrcweir 		for( nIndex = 0; nIndex < nCount; nIndex++, pProperties++ )
1428*cdf0e10cSrcweir 		{
1429*cdf0e10cSrcweir             if ( pProperties->Name.equals( SC_EVENTACC_EVENTTYPE ) )
1430*cdf0e10cSrcweir 			{
1431*cdf0e10cSrcweir 				isEventType = true;
1432*cdf0e10cSrcweir 				continue;
1433*cdf0e10cSrcweir 			}
1434*cdf0e10cSrcweir #ifdef ISSUE66550_HLINK_FOR_SHAPES
1435*cdf0e10cSrcweir             if ( isEventType && ((pProperties->Name == SC_EVENTACC_SCRIPT) || (pProperties->Name == SC_EVENTACC_URL)) )
1436*cdf0e10cSrcweir #else
1437*cdf0e10cSrcweir             if ( isEventType && (pProperties->Name == SC_EVENTACC_SCRIPT) )
1438*cdf0e10cSrcweir #endif
1439*cdf0e10cSrcweir 			{
1440*cdf0e10cSrcweir                 rtl::OUString sValue;
1441*cdf0e10cSrcweir                 if ( pProperties->Value >>= sValue )
1442*cdf0e10cSrcweir                 {
1443*cdf0e10cSrcweir                     ScMacroInfo* pInfo = getInfo( sal_True );
1444*cdf0e10cSrcweir                     DBG_ASSERT( pInfo, "shape macro info could not be created!" );
1445*cdf0e10cSrcweir                     if ( !pInfo )
1446*cdf0e10cSrcweir                         break;
1447*cdf0e10cSrcweir                     if ( pProperties->Name == SC_EVENTACC_SCRIPT )
1448*cdf0e10cSrcweir                         pInfo->SetMacro( sValue );
1449*cdf0e10cSrcweir #ifdef ISSUE66550_HLINK_FOR_SHAPES
1450*cdf0e10cSrcweir                     else
1451*cdf0e10cSrcweir                         pInfo->SetHlink( sValue );
1452*cdf0e10cSrcweir #endif
1453*cdf0e10cSrcweir                 }
1454*cdf0e10cSrcweir 			}
1455*cdf0e10cSrcweir 		}
1456*cdf0e10cSrcweir 	}
1457*cdf0e10cSrcweir 
1458*cdf0e10cSrcweir 	// XNameAccess
1459*cdf0e10cSrcweir 	virtual uno::Any SAL_CALL getByName( const rtl::OUString& aName ) throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
1460*cdf0e10cSrcweir 	{
1461*cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aProperties;
1462*cdf0e10cSrcweir         ScMacroInfo* pInfo = getInfo();
1463*cdf0e10cSrcweir 
1464*cdf0e10cSrcweir         if ( aName == SC_EVENTACC_ONCLICK )
1465*cdf0e10cSrcweir         {
1466*cdf0e10cSrcweir             if ( pInfo && (pInfo->GetMacro().getLength() > 0) )
1467*cdf0e10cSrcweir             {
1468*cdf0e10cSrcweir                 aProperties.realloc( 2 );
1469*cdf0e10cSrcweir                 aProperties[ 0 ].Name = SC_EVENTACC_EVENTTYPE;
1470*cdf0e10cSrcweir                 aProperties[ 0 ].Value <<= SC_EVENTACC_SCRIPT;
1471*cdf0e10cSrcweir                 aProperties[ 1 ].Name = SC_EVENTACC_SCRIPT;
1472*cdf0e10cSrcweir                 aProperties[ 1 ].Value <<= pInfo->GetMacro();
1473*cdf0e10cSrcweir             }
1474*cdf0e10cSrcweir         }
1475*cdf0e10cSrcweir #ifdef ISSUE66550_HLINK_FOR_SHAPES
1476*cdf0e10cSrcweir         else if( aName == SC_EVENTACC_ONACTION )
1477*cdf0e10cSrcweir         {
1478*cdf0e10cSrcweir             if ( pInfo && (pInfo->GetHlink().getLength() > 0) )
1479*cdf0e10cSrcweir             {
1480*cdf0e10cSrcweir                 aProperties.realloc( 2 );
1481*cdf0e10cSrcweir                 aProperties[ 0 ].Name = SC_EVENTACC_EVENTTYPE;
1482*cdf0e10cSrcweir                 aProperties[ 0 ].Value <<= SC_EVENTACC_ACTION;
1483*cdf0e10cSrcweir                 aProperties[ 1 ].Name = SC_EVENTACC_URL;
1484*cdf0e10cSrcweir                 aProperties[ 1 ].Value <<= pInfo->GetHlink();
1485*cdf0e10cSrcweir             }
1486*cdf0e10cSrcweir         }
1487*cdf0e10cSrcweir #endif
1488*cdf0e10cSrcweir         else
1489*cdf0e10cSrcweir         {
1490*cdf0e10cSrcweir             throw container::NoSuchElementException();
1491*cdf0e10cSrcweir         }
1492*cdf0e10cSrcweir 
1493*cdf0e10cSrcweir         return uno::Any( aProperties );
1494*cdf0e10cSrcweir 	}
1495*cdf0e10cSrcweir 
1496*cdf0e10cSrcweir     virtual uno::Sequence< rtl::OUString > SAL_CALL getElementNames() throw(uno::RuntimeException)
1497*cdf0e10cSrcweir 	{
1498*cdf0e10cSrcweir #ifdef ISSUE66550_HLINK_FOR_SHAPES
1499*cdf0e10cSrcweir         uno::Sequence< rtl::OUString > aSeq( 2 );
1500*cdf0e10cSrcweir #else
1501*cdf0e10cSrcweir         uno::Sequence< rtl::OUString > aSeq( 1 );
1502*cdf0e10cSrcweir #endif
1503*cdf0e10cSrcweir         aSeq[ 0 ] = SC_EVENTACC_ONCLICK;
1504*cdf0e10cSrcweir #ifdef ISSUE66550_HLINK_FOR_SHAPES
1505*cdf0e10cSrcweir         aSeq[ 1 ] = SC_EVENTACC_ONACTION;
1506*cdf0e10cSrcweir #endif
1507*cdf0e10cSrcweir         return aSeq;
1508*cdf0e10cSrcweir 	}
1509*cdf0e10cSrcweir 
1510*cdf0e10cSrcweir 	virtual sal_Bool SAL_CALL hasByName( const rtl::OUString& aName ) throw(uno::RuntimeException)
1511*cdf0e10cSrcweir 	{
1512*cdf0e10cSrcweir #ifdef ISSUE66550_HLINK_FOR_SHAPES
1513*cdf0e10cSrcweir         return (aName == SC_EVENTACC_ONCLICK) || (aName == SC_EVENTACC_ONACTION);
1514*cdf0e10cSrcweir #else
1515*cdf0e10cSrcweir         return aName == SC_EVENTACC_ONCLICK;
1516*cdf0e10cSrcweir #endif
1517*cdf0e10cSrcweir 	}
1518*cdf0e10cSrcweir 
1519*cdf0e10cSrcweir 	// XElementAccess
1520*cdf0e10cSrcweir     virtual uno::Type SAL_CALL getElementType() throw(uno::RuntimeException)
1521*cdf0e10cSrcweir 	{
1522*cdf0e10cSrcweir 		return *SEQTYPE(::getCppuType((const uno::Sequence< beans::PropertyValue >*)0));
1523*cdf0e10cSrcweir 	}
1524*cdf0e10cSrcweir 
1525*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasElements() throw(uno::RuntimeException)
1526*cdf0e10cSrcweir 	{
1527*cdf0e10cSrcweir         // elements are always present (but contained property sequences may be empty)
1528*cdf0e10cSrcweir         return sal_True;
1529*cdf0e10cSrcweir 	}
1530*cdf0e10cSrcweir };
1531*cdf0e10cSrcweir 
1532*cdf0e10cSrcweir ::uno::Reference< container::XNameReplace > SAL_CALL
1533*cdf0e10cSrcweir ScShapeObj::getEvents(  ) throw(uno::RuntimeException)
1534*cdf0e10cSrcweir {
1535*cdf0e10cSrcweir 	return new ShapeUnoEventAccessImpl( this );
1536*cdf0e10cSrcweir }
1537*cdf0e10cSrcweir 
1538*cdf0e10cSrcweir ::rtl::OUString SAL_CALL ScShapeObj::getImplementationName(  ) throw (uno::RuntimeException)
1539*cdf0e10cSrcweir {
1540*cdf0e10cSrcweir     return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.sc.ScShapeObj" ) );
1541*cdf0e10cSrcweir }
1542*cdf0e10cSrcweir 
1543*cdf0e10cSrcweir ::sal_Bool SAL_CALL ScShapeObj::supportsService( const ::rtl::OUString& _ServiceName ) throw (uno::RuntimeException)
1544*cdf0e10cSrcweir {
1545*cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > aSupported( getSupportedServiceNames() );
1546*cdf0e10cSrcweir     for ( const ::rtl::OUString* pSupported = aSupported.getConstArray();
1547*cdf0e10cSrcweir           pSupported != aSupported.getConstArray() + aSupported.getLength();
1548*cdf0e10cSrcweir           ++pSupported
1549*cdf0e10cSrcweir         )
1550*cdf0e10cSrcweir         if ( _ServiceName == *pSupported )
1551*cdf0e10cSrcweir             return sal_True;
1552*cdf0e10cSrcweir     return sal_False;
1553*cdf0e10cSrcweir }
1554*cdf0e10cSrcweir 
1555*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL ScShapeObj::getSupportedServiceNames(  ) throw (uno::RuntimeException)
1556*cdf0e10cSrcweir {
1557*cdf0e10cSrcweir     uno::Reference<lang::XServiceInfo> xSI;
1558*cdf0e10cSrcweir     if ( mxShapeAgg.is() )
1559*cdf0e10cSrcweir         mxShapeAgg->queryAggregation( lang::XServiceInfo::static_type() ) >>= xSI;
1560*cdf0e10cSrcweir 
1561*cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > aSupported;
1562*cdf0e10cSrcweir     if ( xSI.is() )
1563*cdf0e10cSrcweir         aSupported = xSI->getSupportedServiceNames();
1564*cdf0e10cSrcweir 
1565*cdf0e10cSrcweir     aSupported.realloc( aSupported.getLength() + 1 );
1566*cdf0e10cSrcweir     aSupported[ aSupported.getLength() - 1 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.Shape" ) );
1567*cdf0e10cSrcweir 
1568*cdf0e10cSrcweir     if( bIsNoteCaption )
1569*cdf0e10cSrcweir     {
1570*cdf0e10cSrcweir         aSupported.realloc( aSupported.getLength() + 1 );
1571*cdf0e10cSrcweir         aSupported[ aSupported.getLength() - 1 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.CellAnnotationShape" ) );
1572*cdf0e10cSrcweir     }
1573*cdf0e10cSrcweir 
1574*cdf0e10cSrcweir     return aSupported;
1575*cdf0e10cSrcweir }
1576