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