1*e6ed5fbcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*e6ed5fbcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*e6ed5fbcSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*e6ed5fbcSAndrew Rist * distributed with this work for additional information
6*e6ed5fbcSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*e6ed5fbcSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*e6ed5fbcSAndrew Rist * "License"); you may not use this file except in compliance
9*e6ed5fbcSAndrew Rist * with the License. You may obtain a copy of the License at
10*e6ed5fbcSAndrew Rist *
11*e6ed5fbcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*e6ed5fbcSAndrew Rist *
13*e6ed5fbcSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*e6ed5fbcSAndrew Rist * software distributed under the License is distributed on an
15*e6ed5fbcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*e6ed5fbcSAndrew Rist * KIND, either express or implied. See the License for the
17*e6ed5fbcSAndrew Rist * specific language governing permissions and limitations
18*e6ed5fbcSAndrew Rist * under the License.
19*e6ed5fbcSAndrew Rist *
20*e6ed5fbcSAndrew Rist *************************************************************/
21*e6ed5fbcSAndrew Rist
22*e6ed5fbcSAndrew Rist
23cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp>
24cdf0e10cSrcweir #include <com/sun/star/view/XSelectionSupplier.hpp>
25cdf0e10cSrcweir #include <com/sun/star/text/WrapTextMode.hpp>
26cdf0e10cSrcweir #include <ooo/vba/msforms/XShapeRange.hpp>
27cdf0e10cSrcweir #include <ooo/vba/office/MsoAutoShapeType.hpp>
28cdf0e10cSrcweir #include <ooo/vba/office/MsoTextOrientation.hpp>
29cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
30cdf0e10cSrcweir #include <com/sun/star/text/XText.hpp>
31cdf0e10cSrcweir #include <com/sun/star/text/XTextDocument.hpp>
32cdf0e10cSrcweir #include <com/sun/star/text/XTextContent.hpp>
33cdf0e10cSrcweir #include <com/sun/star/text/TextContentAnchorType.hpp>
34cdf0e10cSrcweir #include <com/sun/star/text/HoriOrientation.hpp>
35cdf0e10cSrcweir #include <com/sun/star/text/VertOrientation.hpp>
36cdf0e10cSrcweir #include <com/sun/star/text/RelOrientation.hpp>
37cdf0e10cSrcweir #include <com/sun/star/text/SizeType.hpp>
38cdf0e10cSrcweir #include <com/sun/star/text/WritingMode.hpp>
39cdf0e10cSrcweir #include <com/sun/star/drawing/LineStyle.hpp>
40cdf0e10cSrcweir
41cdf0e10cSrcweir #include <vbahelper/vbahelper.hxx>
42cdf0e10cSrcweir #include <vbahelper/vbashape.hxx>
43cdf0e10cSrcweir #include <vbahelper/vbashapes.hxx>
44cdf0e10cSrcweir #include <vbahelper/vbashaperange.hxx>
45cdf0e10cSrcweir
46cdf0e10cSrcweir using namespace ::ooo::vba;
47cdf0e10cSrcweir using namespace ::com::sun::star;
48cdf0e10cSrcweir
49cdf0e10cSrcweir class VbShapeEnumHelper : public EnumerationHelper_BASE
50cdf0e10cSrcweir {
51cdf0e10cSrcweir uno::Reference<msforms::XShapes > m_xParent;
52cdf0e10cSrcweir uno::Reference<container::XIndexAccess > m_xIndexAccess;
53cdf0e10cSrcweir sal_Int32 nIndex;
54cdf0e10cSrcweir public:
VbShapeEnumHelper(const uno::Reference<msforms::XShapes> & xParent,const uno::Reference<container::XIndexAccess> & xIndexAccess)55cdf0e10cSrcweir VbShapeEnumHelper( const uno::Reference< msforms::XShapes >& xParent, const uno::Reference< container::XIndexAccess >& xIndexAccess ) : m_xParent( xParent ), m_xIndexAccess( xIndexAccess ), nIndex( 0 ) {}
hasMoreElements()56cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException)
57cdf0e10cSrcweir {
58cdf0e10cSrcweir return ( nIndex < m_xIndexAccess->getCount() );
59cdf0e10cSrcweir }
nextElement()60cdf0e10cSrcweir virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
61cdf0e10cSrcweir {
62cdf0e10cSrcweir ScVbaShapes* pShapes = dynamic_cast< ScVbaShapes* >(m_xParent.get());
63cdf0e10cSrcweir if ( pShapes && hasMoreElements() )
64cdf0e10cSrcweir return pShapes->createCollectionObject( m_xIndexAccess->getByIndex( nIndex++ ) );
65cdf0e10cSrcweir throw container::NoSuchElementException();
66cdf0e10cSrcweir }
67cdf0e10cSrcweir
68cdf0e10cSrcweir };
69cdf0e10cSrcweir
initBaseCollection()70cdf0e10cSrcweir void ScVbaShapes::initBaseCollection()
71cdf0e10cSrcweir {
72cdf0e10cSrcweir if ( m_xNameAccess.is() ) // already has NameAccess
73cdf0e10cSrcweir return;
74cdf0e10cSrcweir // no NameAccess then use ShapeCollectionHelper
75cdf0e10cSrcweir XNamedObjectCollectionHelper< drawing::XShape >::XNamedVec mShapes;
76cdf0e10cSrcweir sal_Int32 nLen = m_xIndexAccess->getCount();
77cdf0e10cSrcweir mShapes.reserve( nLen );
78cdf0e10cSrcweir for ( sal_Int32 index=0; index<nLen; ++index )
79cdf0e10cSrcweir mShapes.push_back( uno::Reference< drawing::XShape >( m_xIndexAccess->getByIndex( index ) , uno::UNO_QUERY ) );
80cdf0e10cSrcweir uno::Reference< container::XIndexAccess > xShapes( new XNamedObjectCollectionHelper< drawing::XShape >( mShapes ) );
81cdf0e10cSrcweir m_xIndexAccess.set( xShapes, uno::UNO_QUERY );
82cdf0e10cSrcweir m_xNameAccess.set( xShapes, uno::UNO_QUERY );
83cdf0e10cSrcweir }
84cdf0e10cSrcweir
ScVbaShapes(const css::uno::Reference<ov::XHelperInterface> & xParent,const css::uno::Reference<css::uno::XComponentContext> & xContext,const css::uno::Reference<css::container::XIndexAccess> xShapes,const uno::Reference<frame::XModel> & xModel)85cdf0e10cSrcweir ScVbaShapes::ScVbaShapes( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess > xShapes, const uno::Reference< frame::XModel>& xModel ): ScVbaShapes_BASE( xParent, xContext, xShapes ), m_nNewShapeCount(0), m_xModel( xModel )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir m_xShapes.set( xShapes, uno::UNO_QUERY_THROW );
88cdf0e10cSrcweir m_xDrawPage.set( xShapes, uno::UNO_QUERY_THROW );
89cdf0e10cSrcweir initBaseCollection();
90cdf0e10cSrcweir }
91cdf0e10cSrcweir
92cdf0e10cSrcweir uno::Reference< container::XEnumeration >
createEnumeration()93cdf0e10cSrcweir ScVbaShapes::createEnumeration() throw (uno::RuntimeException)
94cdf0e10cSrcweir {
95cdf0e10cSrcweir return new VbShapeEnumHelper( this, m_xIndexAccess );
96cdf0e10cSrcweir }
97cdf0e10cSrcweir
98cdf0e10cSrcweir uno::Any
createCollectionObject(const css::uno::Any & aSource)99cdf0e10cSrcweir ScVbaShapes::createCollectionObject( const css::uno::Any& aSource ) throw (uno::RuntimeException)
100cdf0e10cSrcweir {
101cdf0e10cSrcweir if( aSource.hasValue() )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir uno::Reference< drawing::XShape > xShape( aSource, uno::UNO_QUERY_THROW );
104cdf0e10cSrcweir return uno::makeAny( uno::Reference< msforms::XShape >( new ScVbaShape( getParent(), mxContext, xShape, m_xShapes, m_xModel, ScVbaShape::getType( xShape ) ) ) );
105cdf0e10cSrcweir }
106cdf0e10cSrcweir return uno::Any();
107cdf0e10cSrcweir }
108cdf0e10cSrcweir
109cdf0e10cSrcweir uno::Type
getElementType()110cdf0e10cSrcweir ScVbaShapes::getElementType() throw (uno::RuntimeException)
111cdf0e10cSrcweir {
112cdf0e10cSrcweir return ooo::vba::msforms::XShape::static_type(0);
113cdf0e10cSrcweir }
114cdf0e10cSrcweir rtl::OUString&
getServiceImplName()115cdf0e10cSrcweir ScVbaShapes::getServiceImplName()
116cdf0e10cSrcweir {
117cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaShapes") );
118cdf0e10cSrcweir return sImplName;
119cdf0e10cSrcweir }
120cdf0e10cSrcweir
121cdf0e10cSrcweir uno::Sequence< rtl::OUString >
getServiceNames()122cdf0e10cSrcweir ScVbaShapes::getServiceNames()
123cdf0e10cSrcweir {
124cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames;
125cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 )
126cdf0e10cSrcweir {
127cdf0e10cSrcweir aServiceNames.realloc( 1 );
128cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msform.Shapes" ) );
129cdf0e10cSrcweir }
130cdf0e10cSrcweir return aServiceNames;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
133cdf0e10cSrcweir css::uno::Reference< css::container::XIndexAccess >
getShapesByArrayIndices(const uno::Any & Index)134cdf0e10cSrcweir ScVbaShapes::getShapesByArrayIndices( const uno::Any& Index ) throw (uno::RuntimeException)
135cdf0e10cSrcweir {
136cdf0e10cSrcweir if ( Index.getValueTypeClass() != uno::TypeClass_SEQUENCE )
137cdf0e10cSrcweir throw uno::RuntimeException();
138cdf0e10cSrcweir
139cdf0e10cSrcweir uno::Reference< script::XTypeConverter > xConverter = getTypeConverter(mxContext);
140cdf0e10cSrcweir uno::Any aConverted;
141cdf0e10cSrcweir aConverted = xConverter->convertTo( Index, getCppuType((uno::Sequence< uno::Any >*)0) );
142cdf0e10cSrcweir
143cdf0e10cSrcweir uno::Sequence< uno::Any > sIndices;
144cdf0e10cSrcweir aConverted >>= sIndices;
145cdf0e10cSrcweir XNamedObjectCollectionHelper< drawing::XShape >::XNamedVec mShapes;
146cdf0e10cSrcweir sal_Int32 nElems = sIndices.getLength();
147cdf0e10cSrcweir for( sal_Int32 index = 0; index < nElems; ++index )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir uno::Reference< drawing::XShape > xShape;
150cdf0e10cSrcweir if ( sIndices[ index ].getValueTypeClass() == uno::TypeClass_STRING )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir rtl::OUString sName;
153cdf0e10cSrcweir sIndices[ index ] >>= sName;
154cdf0e10cSrcweir xShape.set( m_xNameAccess->getByName( sName ), uno::UNO_QUERY );
155cdf0e10cSrcweir }
156cdf0e10cSrcweir else
157cdf0e10cSrcweir {
158cdf0e10cSrcweir sal_Int32 nIndex = 0;
159cdf0e10cSrcweir sIndices[ index ] >>= nIndex;
160cdf0e10cSrcweir // adjust for 1 based mso indexing
161cdf0e10cSrcweir xShape.set( m_xIndexAccess->getByIndex( nIndex - 1 ), uno::UNO_QUERY );
162cdf0e10cSrcweir
163cdf0e10cSrcweir }
164cdf0e10cSrcweir // populate map with drawing::XShapes
165cdf0e10cSrcweir if ( xShape.is() )
166cdf0e10cSrcweir mShapes.push_back( xShape );
167cdf0e10cSrcweir }
168cdf0e10cSrcweir uno::Reference< container::XIndexAccess > xIndexAccess( new XNamedObjectCollectionHelper< drawing::XShape >( mShapes ) );
169cdf0e10cSrcweir return xIndexAccess;
170cdf0e10cSrcweir }
171cdf0e10cSrcweir
172cdf0e10cSrcweir uno::Any SAL_CALL
Item(const uno::Any & Index,const uno::Any & Index2)173cdf0e10cSrcweir ScVbaShapes::Item( const uno::Any& Index, const uno::Any& Index2 ) throw (uno::RuntimeException)
174cdf0e10cSrcweir {
175cdf0e10cSrcweir // I don't think we need to support Array of indices for shapes
176cdf0e10cSrcweir /*
177cdf0e10cSrcweir if ( Index.getValueTypeClass() == uno::TypeClass_SEQUENCE )
178cdf0e10cSrcweir {
179cdf0e10cSrcweir uno::Reference< container::XIndexAccess > xIndexAccess( getShapesByArrayIndices( Index ) );
180cdf0e10cSrcweir // return new collection instance
181cdf0e10cSrcweir uno::Reference< XCollection > xShapesCollection( new ScVbaShapes( this->getParent(), mxContext, xIndexAccess ) );
182cdf0e10cSrcweir return uno::makeAny( xShapesCollection );
183cdf0e10cSrcweir }
184cdf0e10cSrcweir */
185cdf0e10cSrcweir return ScVbaShapes_BASE::Item( Index, Index2 );
186cdf0e10cSrcweir }
187cdf0e10cSrcweir
188cdf0e10cSrcweir uno::Reference< msforms::XShapeRange > SAL_CALL
Range(const uno::Any & shapes)189cdf0e10cSrcweir ScVbaShapes::Range( const uno::Any& shapes ) throw (css::uno::RuntimeException)
190cdf0e10cSrcweir {
191cdf0e10cSrcweir // shapes, can be an index or an array of indices
192cdf0e10cSrcweir uno::Reference< container::XIndexAccess > xShapes;
193cdf0e10cSrcweir if ( shapes.getValueTypeClass() == uno::TypeClass_SEQUENCE )
194cdf0e10cSrcweir xShapes = getShapesByArrayIndices( shapes );
195cdf0e10cSrcweir else
196cdf0e10cSrcweir {
197cdf0e10cSrcweir // wrap single index into a sequence
198cdf0e10cSrcweir uno::Sequence< uno::Any > sIndices(1);
199cdf0e10cSrcweir sIndices[ 0 ] = shapes;
200cdf0e10cSrcweir uno::Any aIndex;
201cdf0e10cSrcweir aIndex <<= sIndices;
202cdf0e10cSrcweir xShapes = getShapesByArrayIndices( aIndex );
203cdf0e10cSrcweir }
204cdf0e10cSrcweir return new ScVbaShapeRange( getParent(), mxContext, xShapes, m_xDrawPage, m_xModel );
205cdf0e10cSrcweir }
206cdf0e10cSrcweir
207cdf0e10cSrcweir void SAL_CALL
SelectAll()208cdf0e10cSrcweir ScVbaShapes::SelectAll() throw (uno::RuntimeException)
209cdf0e10cSrcweir {
210cdf0e10cSrcweir uno::Reference< view::XSelectionSupplier > xSelectSupp( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
211cdf0e10cSrcweir try
212cdf0e10cSrcweir {
213cdf0e10cSrcweir xSelectSupp->select( uno::makeAny( m_xShapes ) );
214cdf0e10cSrcweir }
215cdf0e10cSrcweir // viewuno.cxx ScTabViewObj::select will throw IllegalArgumentException
216cdf0e10cSrcweir // if one of the shapes is no 'markable' e.g. a button
217cdf0e10cSrcweir // the method still works
218cdf0e10cSrcweir catch( lang::IllegalArgumentException& )
219cdf0e10cSrcweir {
220cdf0e10cSrcweir }
221cdf0e10cSrcweir }
222cdf0e10cSrcweir
223cdf0e10cSrcweir uno::Reference< drawing::XShape >
createShape(rtl::OUString service)224cdf0e10cSrcweir ScVbaShapes::createShape( rtl::OUString service ) throw (css::uno::RuntimeException)
225cdf0e10cSrcweir {
226cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xMSF( m_xModel, uno::UNO_QUERY_THROW );
227cdf0e10cSrcweir uno::Reference< drawing::XShape > xShape( xMSF->createInstance( service ), uno::UNO_QUERY_THROW );
228cdf0e10cSrcweir return xShape;
229cdf0e10cSrcweir }
230cdf0e10cSrcweir
231cdf0e10cSrcweir uno::Any
AddRectangle(sal_Int32 startX,sal_Int32 startY,sal_Int32 nLineWidth,sal_Int32 nLineHeight,uno::Any aRange)232cdf0e10cSrcweir ScVbaShapes::AddRectangle( sal_Int32 startX, sal_Int32 startY, sal_Int32 nLineWidth, sal_Int32 nLineHeight, uno::Any aRange ) throw (css::uno::RuntimeException)
233cdf0e10cSrcweir {
234cdf0e10cSrcweir rtl::OUString sCreateShapeName( rtl::OUString::createFromAscii( "com.sun.star.drawing.RectangleShape" ) );
235cdf0e10cSrcweir sal_Int32 nXPos = Millimeter::getInHundredthsOfOneMillimeter( startX );
236cdf0e10cSrcweir sal_Int32 nYPos = Millimeter::getInHundredthsOfOneMillimeter( startY );
237cdf0e10cSrcweir sal_Int32 nWidth = Millimeter::getInHundredthsOfOneMillimeter( nLineWidth );
238cdf0e10cSrcweir sal_Int32 nHeight = Millimeter::getInHundredthsOfOneMillimeter( nLineHeight );
239cdf0e10cSrcweir
240cdf0e10cSrcweir uno::Reference< drawing::XShape > xShape( createShape( sCreateShapeName ), uno::UNO_QUERY_THROW );
241cdf0e10cSrcweir m_xShapes->add( xShape );
242cdf0e10cSrcweir
243cdf0e10cSrcweir rtl::OUString sName = createName( rtl::OUString::createFromAscii( "Rectangle" ) );
244cdf0e10cSrcweir setDefaultShapeProperties( xShape );
245cdf0e10cSrcweir setShape_NameProperty( xShape, sName );
246cdf0e10cSrcweir
247cdf0e10cSrcweir awt::Point aMovePositionIfRange(0, 0);
248cdf0e10cSrcweir awt::Point position;
249cdf0e10cSrcweir position.X = nXPos - aMovePositionIfRange.X;
250cdf0e10cSrcweir position.Y = nYPos - aMovePositionIfRange.Y;
251cdf0e10cSrcweir xShape->setPosition( position );
252cdf0e10cSrcweir
253cdf0e10cSrcweir awt::Size size;
254cdf0e10cSrcweir size.Height = nHeight;
255cdf0e10cSrcweir size.Width = nWidth;
256cdf0e10cSrcweir xShape->setSize( size );
257cdf0e10cSrcweir
258cdf0e10cSrcweir ScVbaShape *pScVbaShape = new ScVbaShape( getParent(), mxContext, xShape, m_xShapes, m_xModel, ScVbaShape::getType( xShape ) );
259cdf0e10cSrcweir pScVbaShape->setRange( aRange );
260cdf0e10cSrcweir return uno::makeAny( uno::Reference< msforms::XShape > ( pScVbaShape ) );
261cdf0e10cSrcweir }
262cdf0e10cSrcweir
263cdf0e10cSrcweir uno::Any
AddEllipse(sal_Int32 startX,sal_Int32 startY,sal_Int32 nLineWidth,sal_Int32 nLineHeight,uno::Any aRange)264cdf0e10cSrcweir ScVbaShapes::AddEllipse( sal_Int32 startX, sal_Int32 startY, sal_Int32 nLineWidth, sal_Int32 nLineHeight, uno::Any aRange ) throw (css::uno::RuntimeException)
265cdf0e10cSrcweir {
266cdf0e10cSrcweir rtl::OUString sCreateShapeName( rtl::OUString::createFromAscii( "com.sun.star.drawing.EllipseShape" ) );
267cdf0e10cSrcweir sal_Int32 nXPos = Millimeter::getInHundredthsOfOneMillimeter( startX );
268cdf0e10cSrcweir sal_Int32 nYPos = Millimeter::getInHundredthsOfOneMillimeter( startY );
269cdf0e10cSrcweir sal_Int32 nWidth = Millimeter::getInHundredthsOfOneMillimeter( nLineWidth );
270cdf0e10cSrcweir sal_Int32 nHeight = Millimeter::getInHundredthsOfOneMillimeter( nLineHeight );
271cdf0e10cSrcweir
272cdf0e10cSrcweir uno::Reference< drawing::XShape > xShape( createShape( sCreateShapeName ), uno::UNO_QUERY_THROW );
273cdf0e10cSrcweir m_xShapes->add( xShape );
274cdf0e10cSrcweir
275cdf0e10cSrcweir awt::Point aMovePositionIfRange( 0, 0 );
276cdf0e10cSrcweir //TODO helperapi using a writer document
277cdf0e10cSrcweir /*
278cdf0e10cSrcweir XDocument xDocument = (XDocument)getParent();
279cdf0e10cSrcweir if (AnyConverter.isVoid(_aRange))
280cdf0e10cSrcweir {
281cdf0e10cSrcweir _aRange = xDocument.Range(new Integer(0), new Integer(1));
282cdf0e10cSrcweir // Top&Left in Word is Top&Left of the paper and not the writeable area.
283cdf0e10cSrcweir aMovePositionIfRange = calculateTopLeftMargin((HelperInterfaceAdaptor)xDocument);
284cdf0e10cSrcweir }
285cdf0e10cSrcweir
286cdf0e10cSrcweir setShape_AnchorTypeAndRangeProperty(xShape, _aRange);
287cdf0e10cSrcweir */
288cdf0e10cSrcweir rtl::OUString name = createName( rtl::OUString::createFromAscii( "Oval" ));
289cdf0e10cSrcweir setDefaultShapeProperties(xShape);
290cdf0e10cSrcweir setShape_NameProperty(xShape, name);
291cdf0e10cSrcweir
292cdf0e10cSrcweir awt::Point position;
293cdf0e10cSrcweir position.X = nXPos - aMovePositionIfRange.X;
294cdf0e10cSrcweir position.Y = nYPos - aMovePositionIfRange.Y;
295cdf0e10cSrcweir xShape->setPosition(position);
296cdf0e10cSrcweir
297cdf0e10cSrcweir awt::Size size;
298cdf0e10cSrcweir size.Height = nHeight;
299cdf0e10cSrcweir size.Width = nWidth;
300cdf0e10cSrcweir xShape->setSize(size);
301cdf0e10cSrcweir
302cdf0e10cSrcweir ScVbaShape *pScVbaShape = new ScVbaShape( getParent(), mxContext, xShape, m_xShapes, m_xModel, ScVbaShape::getType( xShape ) );
303cdf0e10cSrcweir pScVbaShape->setRange( aRange );
304cdf0e10cSrcweir return uno::makeAny( uno::Reference< msforms::XShape > ( pScVbaShape ) );
305cdf0e10cSrcweir }
306cdf0e10cSrcweir
307cdf0e10cSrcweir //helpeapi calc
308cdf0e10cSrcweir uno::Any SAL_CALL
AddLine(sal_Int32 StartX,sal_Int32 StartY,sal_Int32 endX,sal_Int32 endY)309cdf0e10cSrcweir ScVbaShapes::AddLine( sal_Int32 StartX, sal_Int32 StartY, sal_Int32 endX, sal_Int32 endY ) throw (uno::RuntimeException)
310cdf0e10cSrcweir {
311cdf0e10cSrcweir sal_Int32 nLineWidth = endX - StartX;
312cdf0e10cSrcweir sal_Int32 nLineHeight = endY - StartY;
313cdf0e10cSrcweir
314cdf0e10cSrcweir sal_Int32 nHeight = Millimeter::getInHundredthsOfOneMillimeter( nLineHeight );
315cdf0e10cSrcweir sal_Int32 nWidth = Millimeter::getInHundredthsOfOneMillimeter( nLineWidth );
316cdf0e10cSrcweir sal_Int32 nXPos = Millimeter::getInHundredthsOfOneMillimeter( StartX );
317cdf0e10cSrcweir sal_Int32 nYPos = Millimeter::getInHundredthsOfOneMillimeter( StartY );
318cdf0e10cSrcweir
319cdf0e10cSrcweir uno::Reference< drawing::XShape > xShape( createShape( rtl::OUString::createFromAscii("com.sun.star.drawing.LineShape") ), uno::UNO_QUERY_THROW );
320cdf0e10cSrcweir m_xShapes->add( xShape );
321cdf0e10cSrcweir
322cdf0e10cSrcweir awt::Point aMovePositionIfRange( 0, 0 );
323cdf0e10cSrcweir
324cdf0e10cSrcweir rtl::OUString name = createName( rtl::OUString::createFromAscii( "Line" ) );
325cdf0e10cSrcweir setDefaultShapeProperties(xShape);
326cdf0e10cSrcweir setShape_NameProperty(xShape, name);
327cdf0e10cSrcweir
328cdf0e10cSrcweir awt::Point position;
329cdf0e10cSrcweir position.X = nXPos - aMovePositionIfRange.X;
330cdf0e10cSrcweir position.Y = nYPos - aMovePositionIfRange.Y;
331cdf0e10cSrcweir xShape->setPosition(position);
332cdf0e10cSrcweir
333cdf0e10cSrcweir awt::Size size;
334cdf0e10cSrcweir size.Height = nHeight;
335cdf0e10cSrcweir size.Width = nWidth;
336cdf0e10cSrcweir xShape->setSize(size);
337cdf0e10cSrcweir
338cdf0e10cSrcweir ScVbaShape *pScVbaShape = new ScVbaShape( getParent(), mxContext, xShape, m_xShapes, m_xModel, ScVbaShape::getType( xShape ) );
339cdf0e10cSrcweir return uno::makeAny( uno::Reference< msforms::XShape > ( pScVbaShape ) );
340cdf0e10cSrcweir }
341cdf0e10cSrcweir
342cdf0e10cSrcweir uno::Any SAL_CALL
AddShape(sal_Int32 _nType,sal_Int32 _nLeft,sal_Int32 _nTop,sal_Int32 _nWidth,sal_Int32 _nHeight)343cdf0e10cSrcweir ScVbaShapes::AddShape( sal_Int32 _nType, sal_Int32 _nLeft, sal_Int32 _nTop, sal_Int32 _nWidth, sal_Int32 _nHeight ) throw (uno::RuntimeException)
344cdf0e10cSrcweir {
345cdf0e10cSrcweir uno::Any _aAnchor;
346cdf0e10cSrcweir if (_nType == office::MsoAutoShapeType::msoShapeRectangle)
347cdf0e10cSrcweir {
348cdf0e10cSrcweir return AddRectangle(_nLeft, _nTop, _nWidth, _nHeight, _aAnchor);
349cdf0e10cSrcweir }
350cdf0e10cSrcweir else if (_nType == office::MsoAutoShapeType::msoShapeOval)
351cdf0e10cSrcweir {
352cdf0e10cSrcweir return AddEllipse(_nLeft, _nTop, _nWidth, _nHeight, _aAnchor);
353cdf0e10cSrcweir }
354cdf0e10cSrcweir return uno::Any();
355cdf0e10cSrcweir }
356cdf0e10cSrcweir
357cdf0e10cSrcweir uno::Any SAL_CALL
AddTextbox(sal_Int32 _nOrientation,sal_Int32 _nLeft,sal_Int32 _nTop,sal_Int32 _nWidth,sal_Int32 _nHeight)358cdf0e10cSrcweir ScVbaShapes::AddTextbox( sal_Int32 _nOrientation, sal_Int32 _nLeft, sal_Int32 _nTop, sal_Int32 _nWidth, sal_Int32 _nHeight ) throw (uno::RuntimeException)
359cdf0e10cSrcweir {
360cdf0e10cSrcweir uno::Reference< lang::XServiceInfo > xServiceInfo( m_xModel, uno::UNO_QUERY_THROW );
361cdf0e10cSrcweir if( xServiceInfo->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextDocument" ) ) ) )
362cdf0e10cSrcweir {
363cdf0e10cSrcweir return AddTextboxInWriter( _nOrientation, _nLeft, _nTop, _nWidth, _nHeight );
364cdf0e10cSrcweir }
365cdf0e10cSrcweir throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
366cdf0e10cSrcweir }
367cdf0e10cSrcweir
368cdf0e10cSrcweir uno::Any
AddTextboxInWriter(sal_Int32,sal_Int32 _nLeft,sal_Int32 _nTop,sal_Int32 _nWidth,sal_Int32 _nHeight)369cdf0e10cSrcweir ScVbaShapes::AddTextboxInWriter( sal_Int32 /*_nOrientation*/, sal_Int32 _nLeft, sal_Int32 _nTop, sal_Int32 _nWidth, sal_Int32 _nHeight ) throw (uno::RuntimeException)
370cdf0e10cSrcweir {
371cdf0e10cSrcweir rtl::OUString sCreateShapeName( rtl::OUString::createFromAscii( "com.sun.star.drawing.TextShape" ) );
372cdf0e10cSrcweir sal_Int32 nXPos = Millimeter::getInHundredthsOfOneMillimeter( _nLeft );
373cdf0e10cSrcweir sal_Int32 nYPos = Millimeter::getInHundredthsOfOneMillimeter( _nTop );
374cdf0e10cSrcweir sal_Int32 nWidth = Millimeter::getInHundredthsOfOneMillimeter( _nWidth );
375cdf0e10cSrcweir sal_Int32 nHeight = Millimeter::getInHundredthsOfOneMillimeter( _nHeight );
376cdf0e10cSrcweir
377cdf0e10cSrcweir uno::Reference< drawing::XShape > xShape( createShape( sCreateShapeName ), uno::UNO_QUERY_THROW );
378cdf0e10cSrcweir m_xShapes->add( xShape );
379cdf0e10cSrcweir
380cdf0e10cSrcweir setDefaultShapeProperties(xShape);
381cdf0e10cSrcweir
382cdf0e10cSrcweir rtl::OUString sName = createName( rtl::OUString::createFromAscii( "Text Box") );
383cdf0e10cSrcweir setShape_NameProperty( xShape, sName );
384cdf0e10cSrcweir
385cdf0e10cSrcweir awt::Size size;
386cdf0e10cSrcweir size.Height = nHeight;
387cdf0e10cSrcweir size.Width = nWidth;
388cdf0e10cSrcweir xShape->setSize(size);
389cdf0e10cSrcweir
390cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xShapeProps( xShape, uno::UNO_QUERY_THROW );
391cdf0e10cSrcweir xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "AnchorType" ), uno::makeAny( text::TextContentAnchorType_AT_PAGE ) );
392cdf0e10cSrcweir xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "HoriOrientRelation" ), uno::makeAny( text::RelOrientation::PAGE_LEFT ) );
393cdf0e10cSrcweir xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "HoriOrient" ), uno::makeAny( text::HoriOrientation::NONE ) );
394cdf0e10cSrcweir xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "HoriOrientPosition" ), uno::makeAny( nXPos ) );
395cdf0e10cSrcweir
396cdf0e10cSrcweir xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "VertOrientRelation" ), uno::makeAny( text::RelOrientation::PAGE_FRAME ) );
397cdf0e10cSrcweir xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "VertOrient" ), uno::makeAny( text::VertOrientation::NONE ) );
398cdf0e10cSrcweir xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "VertOrientPosition" ), uno::makeAny( nYPos ) );
399cdf0e10cSrcweir
400cdf0e10cSrcweir // set to visible
401cdf0e10cSrcweir drawing::LineStyle aLineStyle = drawing::LineStyle_SOLID;
402cdf0e10cSrcweir xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "LineStyle" ), uno::makeAny( aLineStyle ) );
403cdf0e10cSrcweir // set to font
404cdf0e10cSrcweir sal_Int16 nLayerId = 1;
405cdf0e10cSrcweir rtl::OUString sLayerName = rtl::OUString::createFromAscii("Heaven");
406cdf0e10cSrcweir xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "LayerID" ), uno::makeAny( nLayerId ) );
407cdf0e10cSrcweir xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "LayerName" ), uno::makeAny( sLayerName ) );
408cdf0e10cSrcweir
409cdf0e10cSrcweir
410cdf0e10cSrcweir ScVbaShape *pScVbaShape = new ScVbaShape( getParent(), mxContext, xShape, m_xShapes, m_xModel, ScVbaShape::getType( xShape ) );
411cdf0e10cSrcweir return uno::makeAny( uno::Reference< msforms::XShape > ( pScVbaShape ) );
412cdf0e10cSrcweir }
413cdf0e10cSrcweir
414cdf0e10cSrcweir uno::Any
AddShape(const rtl::OUString & sService,const rtl::OUString & sName,sal_Int32 _nLeft,sal_Int32 _nTop,sal_Int32 _nWidth,sal_Int32 _nHeight)415cdf0e10cSrcweir ScVbaShapes::AddShape( const rtl::OUString& sService, const rtl::OUString& sName, sal_Int32 _nLeft, sal_Int32 _nTop, sal_Int32 _nWidth, sal_Int32 _nHeight ) throw (uno::RuntimeException)
416cdf0e10cSrcweir {
417cdf0e10cSrcweir sal_Int32 nXPos = Millimeter::getInHundredthsOfOneMillimeter( _nLeft );
418cdf0e10cSrcweir sal_Int32 nYPos = Millimeter::getInHundredthsOfOneMillimeter( _nTop );
419cdf0e10cSrcweir sal_Int32 nWidth = Millimeter::getInHundredthsOfOneMillimeter( _nWidth );
420cdf0e10cSrcweir sal_Int32 nHeight = Millimeter::getInHundredthsOfOneMillimeter( _nHeight );
421cdf0e10cSrcweir
422cdf0e10cSrcweir uno::Reference< drawing::XShape > xShape( createShape( sService ), uno::UNO_QUERY_THROW );
423cdf0e10cSrcweir m_xShapes->add( xShape );
424cdf0e10cSrcweir
425cdf0e10cSrcweir setDefaultShapeProperties(xShape);
426cdf0e10cSrcweir setShape_NameProperty( xShape, sName );
427cdf0e10cSrcweir
428cdf0e10cSrcweir awt::Point aMovePositionIfRange( 0, 0 );
429cdf0e10cSrcweir awt::Point position;
430cdf0e10cSrcweir position.X = nXPos - aMovePositionIfRange.X;
431cdf0e10cSrcweir position.Y = nYPos - aMovePositionIfRange.Y;
432cdf0e10cSrcweir xShape->setPosition(position);
433cdf0e10cSrcweir
434cdf0e10cSrcweir awt::Size size;
435cdf0e10cSrcweir size.Height = nHeight;
436cdf0e10cSrcweir size.Width = nWidth;
437cdf0e10cSrcweir xShape->setSize(size);
438cdf0e10cSrcweir
439cdf0e10cSrcweir ScVbaShape *pScVbaShape = new ScVbaShape( getParent(), mxContext, xShape, m_xShapes, m_xModel, ScVbaShape::getType( xShape ) );
440cdf0e10cSrcweir return uno::makeAny( uno::Reference< msforms::XShape > ( pScVbaShape ) );
441cdf0e10cSrcweir }
442cdf0e10cSrcweir void
setDefaultShapeProperties(uno::Reference<drawing::XShape> xShape)443cdf0e10cSrcweir ScVbaShapes::setDefaultShapeProperties( uno::Reference< drawing::XShape > xShape ) throw (uno::RuntimeException)
444cdf0e10cSrcweir {
445cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropertySet( xShape, uno::UNO_QUERY_THROW );
446cdf0e10cSrcweir xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "FillStyle" ), uno::makeAny( rtl::OUString::createFromAscii( "SOLID" ) ) );
447cdf0e10cSrcweir xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "FillColor"), uno::makeAny( sal_Int32(0xFFFFFF) ) );
448cdf0e10cSrcweir xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "TextWordWrap"), uno::makeAny( text::WrapTextMode_THROUGHT ) );
449cdf0e10cSrcweir //not find in OOo2.3
450cdf0e10cSrcweir //xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "Opaque"), uno::makeAny( sal_True ) );
451cdf0e10cSrcweir }
452cdf0e10cSrcweir
453cdf0e10cSrcweir void
setShape_NameProperty(uno::Reference<css::drawing::XShape> xShape,rtl::OUString sName)454cdf0e10cSrcweir ScVbaShapes::setShape_NameProperty( uno::Reference< css::drawing::XShape > xShape, rtl::OUString sName )
455cdf0e10cSrcweir {
456cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropertySet( xShape, uno::UNO_QUERY_THROW );
457cdf0e10cSrcweir try
458cdf0e10cSrcweir {
459cdf0e10cSrcweir xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "Name" ), uno::makeAny( sName ) );
460cdf0e10cSrcweir }
461cdf0e10cSrcweir catch( script::BasicErrorException e )
462cdf0e10cSrcweir {
463cdf0e10cSrcweir }
464cdf0e10cSrcweir }
465cdf0e10cSrcweir
466cdf0e10cSrcweir rtl::OUString
createName(rtl::OUString sName)467cdf0e10cSrcweir ScVbaShapes::createName( rtl::OUString sName )
468cdf0e10cSrcweir {
469cdf0e10cSrcweir sal_Int32 nActNumber = 1 + m_nNewShapeCount;
470cdf0e10cSrcweir m_nNewShapeCount++;
471cdf0e10cSrcweir sName += rtl::OUString::valueOf( nActNumber );
472cdf0e10cSrcweir return sName;
473cdf0e10cSrcweir }
474cdf0e10cSrcweir
475cdf0e10cSrcweir #if 0
476cdf0e10cSrcweir //TODO helperapi using a writer document
477cdf0e10cSrcweir awt::Point
478cdf0e10cSrcweir calculateTopLeftMargin( uno::Reference< XHelperInterface > xDocument )
479cdf0e10cSrcweir {
480cdf0e10cSrcweir awt::Point aPoint( 0, 0 );
481cdf0e10cSrcweir uno::Reference< frame::XModel > xModel( xDocument, uno::UNO_QUERY_THROW );
482cdf0e10cSrcweir return awt::Point();
483cdf0e10cSrcweir }
484cdf0e10cSrcweir #endif
485