Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : : #include<ooo/vba/office/MsoZOrderCmd.hpp>
20 : : #include<ooo/vba/office/MsoScaleFrom.hpp>
21 : : #include<com/sun/star/container/XNamed.hpp>
22 : : #include<com/sun/star/drawing/ConnectorType.hpp>
23 : : #include <com/sun/star/lang/XEventListener.hpp>
24 : : #include<com/sun/star/drawing/XDrawPagesSupplier.hpp>
25 : : #include<com/sun/star/drawing/XDrawPages.hpp>
26 : : #include<com/sun/star/view/XSelectionSupplier.hpp>
27 : : #include <com/sun/star/lang/XServiceInfo.hpp>
28 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 : : #include <com/sun/star/text/TextContentAnchorType.hpp>
30 : : #include <com/sun/star/text/RelOrientation.hpp>
31 : : #include <ooo/vba/word/WdRelativeHorizontalPosition.hpp>
32 : : #include <ooo/vba/word/WdRelativeVerticalPosition.hpp>
33 : :
34 : : #include <comphelper/processfactory.hxx>
35 : : #include <osl/mutex.hxx>
36 : : #include <vcl/svapp.hxx>
37 : : #include <svx/unopage.hxx>
38 : : #include <svx/unoshape.hxx>
39 : :
40 : : #include <vbahelper/vbashape.hxx>
41 : : #include <vbahelper/vbatextframe.hxx>
42 : : #include "vbalineformat.hxx"
43 : : #include "vbafillformat.hxx"
44 : : #include "vbapictureformat.hxx"
45 : : #include <vbahelper/vbashaperange.hxx>
46 : :
47 : : using namespace ::ooo::vba;
48 : : using namespace ::com::sun::star;
49 : :
50 : 0 : ScVbaShape::ScVbaShape( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< drawing::XShape >& xShape, const uno::Reference< drawing::XShapes >& xShapes, const uno::Reference< frame::XModel >& xModel, sal_Int32 nType ) throw( lang::IllegalArgumentException ) : ScVbaShape_BASE( xParent, xContext ), m_xShape( xShape ), m_xShapes( xShapes ), m_nType( nType ), m_xModel( xModel )
51 : : {
52 [ # # ]: 0 : m_xPropertySet.set( m_xShape, uno::UNO_QUERY_THROW );
53 [ # # ][ # # ]: 0 : m_pShapeHelper.reset( new ShapeHelper( m_xShape ) );
54 [ # # ]: 0 : addListeners();
55 : 0 : }
56 : :
57 [ # # ]: 0 : ScVbaShape::~ScVbaShape()
58 : : {
59 : : // dtor must never ever throw
60 : : /*try
61 : : {
62 : : removeShapeListener();
63 : : removeShapesListener();
64 : : }
65 : : catch( uno::Exception& )
66 : : {
67 : : }*/
68 [ # # ]: 0 : }
69 : :
70 : : void SAL_CALL
71 : 0 : ScVbaShape::disposing( const lang::EventObject& rEventObject ) throw( uno::RuntimeException )
72 : : {
73 : : try
74 : : {
75 [ # # ]: 0 : uno::Reference< drawing::XShapes > xShapes( rEventObject.Source, uno::UNO_QUERY );
76 [ # # ]: 0 : uno::Reference< drawing::XShape > xShape( rEventObject.Source, uno::UNO_QUERY );
77 [ # # ]: 0 : if ( xShapes.is() )
78 [ # # ]: 0 : removeShapesListener();
79 [ # # ]: 0 : if ( xShape.is() )
80 [ # # ][ # # ]: 0 : removeShapeListener();
81 : : }
82 : 0 : catch( uno::Exception& )
83 : : {
84 : : }
85 : 0 : }
86 : :
87 : :
88 : 0 : void ScVbaShape::addListeners()
89 : : {
90 [ # # ]: 0 : uno::Reference< lang::XComponent > xComponent( m_xShape, uno::UNO_QUERY );
91 [ # # ]: 0 : if ( xComponent.is() )
92 [ # # ][ # # ]: 0 : xComponent->addEventListener( this );
[ # # ]
93 : :
94 [ # # ]: 0 : xComponent.set( m_xShapes, uno::UNO_QUERY );
95 [ # # ]: 0 : if ( xComponent.is() )
96 [ # # ][ # # ]: 0 : xComponent->addEventListener( this );
[ # # ]
97 : 0 : }
98 : :
99 : : void
100 : 0 : ScVbaShape::removeShapeListener() throw( uno::RuntimeException )
101 : : {
102 [ # # ]: 0 : if( m_xShape.is() )
103 : : {
104 [ # # ]: 0 : uno::Reference< lang::XComponent > xComponent( m_xShape, uno::UNO_QUERY_THROW );
105 [ # # ][ # # ]: 0 : xComponent->removeEventListener( this );
[ # # ]
106 : : }
107 : 0 : m_xShape = NULL;
108 : 0 : m_xPropertySet = NULL;
109 : 0 : }
110 : :
111 : : void
112 : 0 : ScVbaShape::removeShapesListener() throw( uno::RuntimeException )
113 : : {
114 [ # # ]: 0 : if( m_xShapes.is() )
115 : : {
116 [ # # ]: 0 : uno::Reference< lang::XComponent > xComponent( m_xShapes, uno::UNO_QUERY_THROW );
117 [ # # ][ # # ]: 0 : xComponent->removeEventListener( this );
[ # # ]
118 : : }
119 : 0 : m_xShapes = NULL;
120 : 0 : }
121 : :
122 : : sal_Int32
123 : 0 : ScVbaShape::getType( const css::uno::Reference< drawing::XShape > xShape ) throw (uno::RuntimeException)
124 : : {
125 : 0 : rtl::OUString sShapeType;
126 [ # # ]: 0 : uno::Reference< drawing::XShapeDescriptor > xShapeDescriptor( xShape, uno::UNO_QUERY_THROW );
127 [ # # ][ # # ]: 0 : sShapeType = xShapeDescriptor->getShapeType();
128 : : OSL_TRACE("ScVbaShape::getType: %s", rtl::OUStringToOString( sShapeType, RTL_TEXTENCODING_UTF8 ).getStr() );
129 : : // office::MsoShapeType::msoDiagram to "com.sun.star.drawing.GroupShape"
130 [ # # ]: 0 : if( sShapeType == "com.sun.star.drawing.GroupShape" )
131 : 0 : return office::MsoShapeType::msoGroup;
132 [ # # ]: 0 : else if( sShapeType == "com.sun.star.drawing.GraphicObjectShape" )
133 : 0 : return office::MsoShapeType::msoPicture;
134 [ # # ][ # # ]: 0 : else if( sShapeType == "com.sun.star.drawing.ControlShape" || sShapeType == "FrameShape" )
[ # # ]
135 : 0 : return office::MsoShapeType::msoOLEControlObject;
136 : : // OOo don't support office::MsoShapeType::msoComment as a Shape.
137 [ # # ]: 0 : else if( sShapeType == "com.sun.star.drawing.OLE2Shape" )
138 : 0 : return office::MsoShapeType::msoChart;
139 : : // Art characters office::MsoShapeType::msoTextEffect, in OOo corresponding to "com.sun.star.drawing.CustomShape"
140 [ # # ]: 0 : else if( sShapeType == "com.sun.star.drawing.ConnectorShape" )
141 : : {
142 : : enum drawing::ConnectorType connectorType;
143 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xPropertySet( xShape, uno::UNO_QUERY_THROW );
144 [ # # ][ # # ]: 0 : xPropertySet->getPropertyValue( rtl::OUString("EdgeKind")) >>= connectorType;
[ # # ]
145 [ # # ]: 0 : if( connectorType == drawing::ConnectorType_CURVE )
146 : 0 : return office::MsoShapeType::msoFreeform;
147 [ # # ]: 0 : else if( connectorType == drawing::ConnectorType_LINE )
148 : 0 : return office::MsoShapeType::msoLine;
149 : : else
150 : 0 : return office::MsoShapeType::msoAutoShape;
151 : : }
152 [ # # ]: 0 : else if( sShapeType == "com.sun.star.drawing.LineShape" )
153 : 0 : return office::MsoShapeType::msoLine;
154 [ # # ][ # # ]: 0 : else if( sShapeType == "com.sun.star.drawing.CustomShape" || sShapeType == "com.sun.star.drawing.RectangleShape" )
[ # # ]
155 : 0 : return office::MsoShapeType::msoAutoShape;
156 [ # # ]: 0 : else if( sShapeType == "com.sun.star.drawing.TextShape" )
157 : 0 : return office::MsoShapeType::msoTextBox;
158 : : else
159 [ # # ]: 0 : throw uno::RuntimeException( rtl::OUString("the shape type do not be supported: ") + sShapeType, uno::Reference< uno::XInterface >() );
160 : : }
161 : :
162 : : // Attributes
163 : : rtl::OUString SAL_CALL
164 : 0 : ScVbaShape::getName() throw (uno::RuntimeException)
165 : : {
166 : 0 : rtl::OUString sName;
167 [ # # ]: 0 : uno::Reference< container::XNamed > xNamed( m_xShape, uno::UNO_QUERY_THROW );
168 [ # # ][ # # ]: 0 : sName = xNamed->getName();
169 : 0 : return sName;
170 : : }
171 : :
172 : : void SAL_CALL
173 : 0 : ScVbaShape::setName( const rtl::OUString& _name ) throw (uno::RuntimeException)
174 : : {
175 [ # # ]: 0 : uno::Reference< container::XNamed > xNamed( m_xShape, uno::UNO_QUERY_THROW );
176 [ # # ][ # # ]: 0 : xNamed->setName( _name );
177 : 0 : }
178 : :
179 : : double SAL_CALL
180 : 0 : ScVbaShape::getHeight() throw (uno::RuntimeException)
181 : : {
182 : 0 : return m_pShapeHelper->getHeight();
183 : : }
184 : :
185 : : void SAL_CALL
186 : 0 : ScVbaShape::setHeight( double _height ) throw (uno::RuntimeException)
187 : : {
188 : 0 : m_pShapeHelper->setHeight( _height );
189 : 0 : }
190 : :
191 : : double SAL_CALL
192 : 0 : ScVbaShape::getWidth() throw (uno::RuntimeException)
193 : : {
194 : 0 : return m_pShapeHelper->getWidth();
195 : : }
196 : :
197 : : void SAL_CALL
198 : 0 : ScVbaShape::setWidth( double _width ) throw (uno::RuntimeException)
199 : : {
200 : 0 : m_pShapeHelper->setWidth( _width );
201 : 0 : }
202 : :
203 : : double SAL_CALL
204 : 0 : ScVbaShape::getLeft() throw (uno::RuntimeException)
205 : : {
206 : 0 : double left = 0;
207 : : try
208 : : {
209 [ # # ]: 0 : left = m_pShapeHelper->getLeft();
210 : : }
211 [ # # ]: 0 : catch( uno::Exception& )
212 : : {
213 : : // fail to get position by using XShape::getPosition()
214 : 0 : sal_Int32 nLeft = 0;
215 [ # # # # ]: 0 : m_xPropertySet->getPropertyValue( rtl::OUString( "HoriOrientPosition" ) ) >>= nLeft;
216 [ # # ]: 0 : left = Millimeter::getInPoints( nLeft );
217 : : }
218 : 0 : return left;
219 : : }
220 : :
221 : : void SAL_CALL
222 : 0 : ScVbaShape::setLeft( double _left ) throw (uno::RuntimeException)
223 : : {
224 : : try
225 : : {
226 [ # # ]: 0 : m_pShapeHelper->setLeft( _left );
227 : : }
228 [ # # ]: 0 : catch( uno::Exception& )
229 : : {
230 : 0 : sal_Int32 nLeft = 0;
231 [ # # ]: 0 : nLeft = Millimeter::getInHundredthsOfOneMillimeter( _left );
232 [ # # # # : 0 : m_xPropertySet->setPropertyValue( rtl::OUString("HoriOrientPosition"), uno::makeAny( nLeft ) );
# # ]
233 : : }
234 : 0 : }
235 : :
236 : : double SAL_CALL
237 : 0 : ScVbaShape::getTop() throw (uno::RuntimeException)
238 : : {
239 : 0 : double top = 0;
240 : : try
241 : : {
242 [ # # ]: 0 : top = m_pShapeHelper->getTop();
243 : : }
244 [ # # ]: 0 : catch( uno::Exception& )
245 : : {
246 : 0 : sal_Int32 nTop = 0;
247 [ # # # # ]: 0 : m_xPropertySet->getPropertyValue( rtl::OUString( "VertOrientPosition" ) ) >>= nTop;
248 [ # # ]: 0 : top = Millimeter::getInPoints( nTop );
249 : : }
250 : 0 : return top;
251 : : }
252 : :
253 : : void SAL_CALL
254 : 0 : ScVbaShape::setTop( double _top ) throw (uno::RuntimeException)
255 : : {
256 : : try
257 : : {
258 [ # # ]: 0 : m_pShapeHelper->setTop( _top );
259 : : }
260 [ # # ]: 0 : catch( uno::Exception& )
261 : : {
262 : 0 : sal_Int32 nTop = 0;
263 [ # # ]: 0 : nTop = Millimeter::getInHundredthsOfOneMillimeter( _top );
264 [ # # # # : 0 : m_xPropertySet->setPropertyValue( rtl::OUString("VertOrientPosition"), uno::makeAny( nTop ) );
# # ]
265 : : }
266 : 0 : }
267 : :
268 : : sal_Bool SAL_CALL
269 : 0 : ScVbaShape::getVisible() throw (uno::RuntimeException)
270 : : {
271 : : //UNO Shapes are always visible
272 : 0 : return sal_True;
273 : : }
274 : :
275 : : void SAL_CALL
276 : 0 : ScVbaShape::setVisible( sal_Bool /*_visible*/ ) throw (uno::RuntimeException)
277 : : {
278 : : //UNO Shapes are always visible
279 : 0 : }
280 : :
281 : : sal_Int32 SAL_CALL
282 : 0 : ScVbaShape::getZOrderPosition() throw (uno::RuntimeException)
283 : : {
284 : 0 : sal_Int32 nZOrderPosition = 0;
285 [ # # ][ # # ]: 0 : uno::Any aZOrderPosition = m_xPropertySet->getPropertyValue( rtl::OUString("ZOrder") );
286 : 0 : aZOrderPosition >>= nZOrderPosition;
287 : 0 : return nZOrderPosition + 1;
288 : : }
289 : :
290 : : sal_Int32 SAL_CALL
291 : 0 : ScVbaShape::getType() throw (uno::RuntimeException)
292 : : {
293 : 0 : return m_nType;
294 : : }
295 : :
296 : : double SAL_CALL
297 : 0 : ScVbaShape::getRotation() throw (uno::RuntimeException)
298 : : {
299 : 0 : double dRotation = 0;
300 : 0 : sal_Int32 nRotation = 0;
301 [ # # ][ # # ]: 0 : m_xPropertySet->getPropertyValue( rtl::OUString("RotateAngle") ) >>= nRotation;
302 : 0 : dRotation = static_cast< double >( nRotation /100 );
303 : 0 : return dRotation;
304 : : }
305 : :
306 : : void SAL_CALL
307 : 0 : ScVbaShape::setRotation( double _rotation ) throw (uno::RuntimeException)
308 : : {
309 : 0 : sal_Int32 nRotation = static_cast < sal_Int32 > ( _rotation * 100 );
310 [ # # ][ # # ]: 0 : m_xPropertySet->setPropertyValue( rtl::OUString("RotateAngle"), uno::makeAny( nRotation ) );
[ # # ]
311 : 0 : }
312 : :
313 : : uno::Reference< msforms::XLineFormat > SAL_CALL
314 : 0 : ScVbaShape::getLine() throw (uno::RuntimeException)
315 : : {
316 : : // TODO should ongly return line
317 [ # # ][ # # ]: 0 : return uno::Reference< msforms::XLineFormat >( new ScVbaLineFormat( this, mxContext, m_xShape ) );
[ # # ]
318 : : }
319 : :
320 : : uno::Reference< msforms::XFillFormat > SAL_CALL
321 : 0 : ScVbaShape::getFill() throw (uno::RuntimeException)
322 : : {
323 [ # # ][ # # ]: 0 : return uno::Reference< msforms::XFillFormat >( new ScVbaFillFormat( this, mxContext, m_xShape ) );
[ # # ]
324 : : }
325 : :
326 : : uno::Reference< msforms::XPictureFormat > SAL_CALL
327 : 0 : ScVbaShape::getPictureFormat() throw (uno::RuntimeException)
328 : : {
329 [ # # ][ # # ]: 0 : return uno::Reference< msforms::XPictureFormat >( new ScVbaPictureFormat( this, mxContext, m_xShape ) );
[ # # ]
330 : : }
331 : :
332 : : // Methods
333 : : uno::Any SAL_CALL
334 : 0 : ScVbaShape::TextFrame() throw (uno::RuntimeException)
335 : : {
336 [ # # ]: 0 : uno::Reference< lang::XServiceInfo > xServiceInfo( m_xModel, uno::UNO_QUERY_THROW );
337 [ # # ][ # # ]: 0 : if( xServiceInfo->supportsService( ::rtl::OUString( "com.sun.star.sheet.SpreadsheetDocument" ) ) )
[ # # ]
338 : : {
339 [ # # ][ # # ]: 0 : uno::Reference< lang::XMultiServiceFactory > xSF( comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
340 [ # # ]: 0 : uno::Sequence< uno::Any > aArgs(2);
341 [ # # ][ # # ]: 0 : aArgs[0] = uno::makeAny( getParent() );
[ # # ]
342 [ # # ][ # # ]: 0 : aArgs[1] <<= m_xShape;
343 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface > xTextFrame( xSF->createInstanceWithArguments( rtl::OUString( "ooo.vba.excel.TextFrame" ) , aArgs ) , uno::UNO_QUERY_THROW );
[ # # ]
344 [ # # ][ # # ]: 0 : return uno::makeAny( xTextFrame );
345 : : }
346 : :
347 [ # # ][ # # ]: 0 : return uno::makeAny( uno::Reference< msforms::XTextFrame >( new VbaTextFrame( this, mxContext, m_xShape ) ) );
[ # # ][ # # ]
[ # # ]
348 : : }
349 : :
350 : : void SAL_CALL
351 : 0 : ScVbaShape::Delete() throw (uno::RuntimeException)
352 : : {
353 [ # # ]: 0 : SolarMutexGuard aGuard;
354 [ # # ][ # # ]: 0 : m_xShapes->remove( m_xShape );
[ # # ]
355 : 0 : }
356 : :
357 : : void SAL_CALL
358 : 0 : ScVbaShape::ZOrder( sal_Int32 ZOrderCmd ) throw (uno::RuntimeException)
359 : : {
360 : : sal_Int32 nOrderPositon;
361 [ # # ][ # # ]: 0 : uno::Any aOrderPostion = m_xPropertySet->getPropertyValue( rtl::OUString("ZOrder") );
362 : 0 : aOrderPostion >>= nOrderPositon;
363 [ # # # # : 0 : switch( ZOrderCmd )
# # ]
364 : : {
365 : : case office::MsoZOrderCmd::msoBringToFront:
366 [ # # ][ # # ]: 0 : m_xPropertySet->setPropertyValue( rtl::OUString("ZOrder"), uno::makeAny( SAL_MAX_INT32 ) );
[ # # ]
367 : 0 : break;
368 : : case office::MsoZOrderCmd::msoSendToBack:
369 [ # # ][ # # ]: 0 : m_xPropertySet->setPropertyValue( rtl::OUString("ZOrder"), uno::makeAny( (sal_Int32)0 ) );
[ # # ]
370 : 0 : break;
371 : : case office::MsoZOrderCmd::msoBringForward:
372 : 0 : nOrderPositon += 1;
373 [ # # ][ # # ]: 0 : m_xPropertySet->setPropertyValue( rtl::OUString("ZOrder"), uno::makeAny( nOrderPositon ) );
[ # # ]
374 : 0 : break;
375 : : case office::MsoZOrderCmd::msoSendBackward:
376 [ # # ]: 0 : if( nOrderPositon > 0 )
377 : : {
378 : 0 : nOrderPositon -= 1;
379 [ # # ][ # # ]: 0 : m_xPropertySet->setPropertyValue( rtl::OUString("ZOrder"), uno::makeAny( nOrderPositon ) );
[ # # ]
380 : : }
381 : 0 : break;
382 : : // below two commands use with Writer for text and image object.
383 : : case office::MsoZOrderCmd::msoBringInFrontOfText:
384 : : case office::MsoZOrderCmd::msoSendBehindText:
385 [ # # ]: 0 : throw uno::RuntimeException( rtl::OUString("This ZOrderCmd is not implemented, it is use with writer."), uno::Reference< uno::XInterface >() );
386 : : default:
387 [ # # ]: 0 : throw uno::RuntimeException( rtl::OUString("Invalid Parameter."), uno::Reference< uno::XInterface >() );
388 : 0 : }
389 : 0 : }
390 : :
391 : : void SAL_CALL
392 : 0 : ScVbaShape::IncrementRotation( double Increment ) throw (uno::RuntimeException)
393 : : {
394 : 0 : double nCurrentRotation = getRotation();
395 : 0 : nCurrentRotation += Increment;
396 : 0 : setRotation(nCurrentRotation);
397 : 0 : }
398 : :
399 : : void SAL_CALL
400 : 0 : ScVbaShape::IncrementLeft( double Increment ) throw (uno::RuntimeException)
401 : : {
402 : 0 : double nCurrentLeft = getLeft();
403 : 0 : nCurrentLeft += Increment;
404 : 0 : setLeft(nCurrentLeft);
405 : 0 : }
406 : :
407 : : void SAL_CALL
408 : 0 : ScVbaShape::IncrementTop( double Increment ) throw (uno::RuntimeException)
409 : : {
410 : 0 : double nCurrentTop = getTop();
411 : 0 : nCurrentTop += Increment;
412 : 0 : setTop(nCurrentTop);
413 : 0 : }
414 : :
415 : : void SAL_CALL
416 : 0 : ScVbaShape::ScaleHeight( double Factor, sal_Bool /*RelativeToOriginalSize*/, sal_Int32 Scale ) throw (uno::RuntimeException)
417 : : {
418 : 0 : double nHeight = getHeight();
419 : 0 : double nNewHeight = nHeight * Factor;
420 [ # # ]: 0 : if( Scale == office::MsoScaleFrom::msoScaleFromTopLeft )
421 : : {
422 : 0 : setHeight(nNewHeight);
423 : : }
424 [ # # ]: 0 : else if( Scale == office::MsoScaleFrom::msoScaleFromBottomRight )
425 : : {
426 : 0 : double nDeltaHeight = nNewHeight - nHeight;
427 : 0 : double nNewTop = getTop() - nDeltaHeight;
428 : 0 : setTop(nNewTop);
429 : 0 : setHeight(nNewHeight);
430 : : }
431 [ # # ]: 0 : else if( Scale == office::MsoScaleFrom::msoScaleFromMiddle )
432 : : {
433 : 0 : double nDeltaHeight = (nNewHeight - nHeight) / 2;
434 : 0 : double nNewTop = getTop() - nDeltaHeight;
435 : 0 : setTop(nNewTop);
436 : 0 : setHeight(nNewHeight);
437 : : }
438 : : else
439 : : {
440 [ # # ]: 0 : throw uno::RuntimeException( rtl::OUString("ScaleHeight.Scale wrong value is given.") , uno::Reference< uno::XInterface >() );
441 : : }
442 : 0 : }
443 : :
444 : : void SAL_CALL
445 : 0 : ScVbaShape::ScaleWidth( double Factor, sal_Bool /*RelativeToOriginalSize*/, sal_Int32 Scale ) throw (uno::RuntimeException)
446 : : {
447 : 0 : double nWidth = getWidth();
448 : 0 : double nNewWidth = nWidth * Factor;
449 [ # # ]: 0 : if( Scale == office::MsoScaleFrom::msoScaleFromTopLeft )
450 : : {
451 : 0 : setWidth(nNewWidth);
452 : : }
453 [ # # ]: 0 : else if( Scale == office::MsoScaleFrom::msoScaleFromBottomRight )
454 : : {
455 : 0 : double nDeltaWidth = nNewWidth - nWidth;
456 : 0 : double nNewLeft = getLeft() - nDeltaWidth;
457 : 0 : setLeft(nNewLeft);
458 : 0 : setWidth(nNewWidth);
459 : : }
460 [ # # ]: 0 : else if( Scale == office::MsoScaleFrom::msoScaleFromMiddle )
461 : : {
462 : 0 : double nDeltaWidth = (nNewWidth - nWidth) / 2;
463 : 0 : double nNewLeft = getLeft() - nDeltaWidth;
464 : 0 : setLeft(nNewLeft);
465 : 0 : setWidth(nNewWidth);
466 : : }
467 : : else
468 : : {
469 [ # # ]: 0 : throw uno::RuntimeException( rtl::OUString("ScaleHeight.Scale wrong value is given.") , uno::Reference< uno::XInterface >() );
470 : : }
471 : 0 : }
472 : :
473 : : void SAL_CALL
474 : 0 : ScVbaShape::Select( const uno::Any& /*Replace*/ ) throw ( uno::RuntimeException )
475 : : {
476 [ # # ][ # # ]: 0 : uno::Reference< view::XSelectionSupplier > xSelectSupp( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
[ # # ]
477 [ # # ][ # # ]: 0 : xSelectSupp->select( uno::makeAny( m_xShape ) );
[ # # ]
478 : 0 : }
479 : :
480 : : // This method should not be part of Shape, what we reall need to do is...
481 : : // dynamically create the appropriate objects e.g. TextBox, Oval, Picture etc.
482 : : // ( e.g. the ones that really do have ShapeRange as an attribute )
483 : : uno::Any SAL_CALL
484 : 0 : ScVbaShape::ShapeRange( const uno::Any& index ) throw ( uno::RuntimeException )
485 : : {
486 : : // perhaps we should store a reference to the Shapes Collection
487 : : // in this class
488 : : // but anyway this method should not even be in this class
489 : : // #TODO not sure what the parent of the Shapes collection should be
490 : :
491 [ # # ]: 0 : XNamedObjectCollectionHelper< drawing::XShape >::XNamedVec aVec;
492 [ # # ]: 0 : aVec.push_back( m_xShape );
493 [ # # ][ # # ]: 0 : uno::Reference< container::XIndexAccess > xIndexAccess( new XNamedObjectCollectionHelper< drawing::XShape >( aVec ) );
[ # # ]
494 [ # # ]: 0 : uno::Reference< container::XChild > xChild( m_xShape, uno::UNO_QUERY_THROW );
495 : : // #FIXME for want of a better parent, setting this
496 [ # # ][ # # ]: 0 : uno::Reference< msforms::XShapeRange > xShapeRange( new ScVbaShapeRange( mxParent, mxContext, xIndexAccess, uno::Reference< drawing::XDrawPage >( xChild->getParent(), uno::UNO_QUERY_THROW ), m_xModel ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
497 [ # # ]: 0 : if ( index.hasValue() )
498 [ # # ][ # # ]: 0 : return xShapeRange->Item( index, uno::Any() );
499 [ # # ]: 0 : return uno::makeAny( xShapeRange );
500 : : }
501 : :
502 : 0 : void SAL_CALL ScVbaShape::Copy() throw (uno::RuntimeException)
503 : : {
504 [ # # ]: 0 : if ( m_xModel.is() )
505 : : {
506 [ # # ]: 0 : Select( uno::Any() );
507 : : // Copy this Shape.
508 : 0 : rtl::OUString sUrl = rtl::OUString( ".uno:Copy" );
509 [ # # ]: 0 : dispatchRequests( m_xModel, sUrl );
510 : : }
511 : 0 : }
512 : :
513 : : sal_Bool SAL_CALL
514 : 0 : ScVbaShape::getLockAspectRatio() throw (uno::RuntimeException)
515 : : {
516 : : // FIXME:
517 : 0 : return sal_False;
518 : : }
519 : :
520 : : void SAL_CALL
521 : 0 : ScVbaShape::setLockAspectRatio( sal_Bool /*_lockaspectratio*/ ) throw (uno::RuntimeException)
522 : : {
523 : : // FIXME:
524 : 0 : }
525 : :
526 : : sal_Bool SAL_CALL
527 : 0 : ScVbaShape::getLockAnchor() throw (uno::RuntimeException)
528 : : {
529 : : // FIXME:
530 : 0 : return sal_True;
531 : : }
532 : :
533 : : void SAL_CALL
534 : 0 : ScVbaShape::setLockAnchor( sal_Bool /*_lockanchor*/ ) throw (uno::RuntimeException)
535 : : {
536 : : // FIXME:
537 : 0 : }
538 : :
539 : : sal_Int32 SAL_CALL
540 : 0 : ScVbaShape::getRelativeHorizontalPosition() throw (uno::RuntimeException)
541 : : {
542 : 0 : sal_Int32 nRelativeHorizontalPosition = word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionMargin;
543 : 0 : sal_Int16 nType = text::RelOrientation::PAGE_LEFT;
544 [ # # ][ # # ]: 0 : m_xPropertySet->getPropertyValue( rtl::OUString( "HoriOrientRelation" ) ) >>= nType;
545 : :
546 [ # # # # : 0 : switch( nType )
# ]
547 : : {
548 : : case text::RelOrientation::FRAME:
549 : : {
550 : 0 : nRelativeHorizontalPosition = word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionColumn;
551 : 0 : break;
552 : : }
553 : : case text::RelOrientation::PAGE_FRAME:
554 : : {
555 : 0 : nRelativeHorizontalPosition = word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionPage;
556 : 0 : break;
557 : : }
558 : : case text::RelOrientation::CHAR:
559 : : {
560 : 0 : nRelativeHorizontalPosition = word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionCharacter;
561 : 0 : break;
562 : : }
563 : : case text::RelOrientation::PAGE_PRINT_AREA:
564 : : {
565 : 0 : nRelativeHorizontalPosition = word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionMargin;
566 : 0 : break;
567 : : }
568 : : default:
569 : : {
570 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Shape::RelativeHorizontalPosition: not implemented" ) ), uno::Reference< uno::XInterface >() );
571 : : }
572 : : }
573 : 0 : return nRelativeHorizontalPosition;
574 : : }
575 : :
576 : : void SAL_CALL
577 : 0 : ScVbaShape::setRelativeHorizontalPosition( ::sal_Int32 _relativehorizontalposition ) throw (uno::RuntimeException)
578 : : {
579 : 0 : sal_Int16 nType = text::RelOrientation::PAGE_FRAME;
580 [ # # # # : 0 : switch( _relativehorizontalposition )
# ]
581 : : {
582 : : case word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionCharacter:
583 : : {
584 : 0 : nType = text::RelOrientation::CHAR;
585 : 0 : break;
586 : : }
587 : : case word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionColumn:
588 : : {
589 : 0 : nType = text::RelOrientation::PAGE_FRAME;
590 : 0 : break;
591 : : }
592 : : case word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionMargin:
593 : : {
594 : 0 : nType = text::RelOrientation::PAGE_PRINT_AREA;
595 : 0 : break;
596 : : }
597 : : case word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionPage:
598 : : {
599 : 0 : nType = text::RelOrientation::PAGE_FRAME;
600 : 0 : break;
601 : : }
602 : : default:
603 : : {
604 [ # # ]: 0 : DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString());
605 : : }
606 : : }
607 [ # # ][ # # ]: 0 : m_xPropertySet->setPropertyValue( rtl::OUString( "HoriOrientRelation" ), uno::makeAny( nType ) );
[ # # ]
608 : 0 : }
609 : :
610 : : sal_Int32 SAL_CALL
611 : 0 : ScVbaShape::getRelativeVerticalPosition() throw (uno::RuntimeException)
612 : : {
613 : 0 : sal_Int32 nRelativeVerticalPosition = word::WdRelativeVerticalPosition::wdRelativeVerticalPositionMargin;
614 : 0 : sal_Int16 nType = text::RelOrientation::PAGE_FRAME;
615 [ # # ][ # # ]: 0 : m_xPropertySet->getPropertyValue( rtl::OUString( "VertOrientRelation" ) ) >>= nType;
616 : :
617 [ # # # # : 0 : switch( nType )
# ]
618 : : {
619 : : case text::RelOrientation::FRAME:
620 : : {
621 : 0 : nRelativeVerticalPosition = word::WdRelativeVerticalPosition::wdRelativeVerticalPositionParagraph;
622 : 0 : break;
623 : : }
624 : : case text::RelOrientation::PAGE_FRAME:
625 : : {
626 : 0 : nRelativeVerticalPosition = word::WdRelativeVerticalPosition::wdRelativeVerticalPositionPage;
627 : 0 : break;
628 : : }
629 : : case text::RelOrientation::TEXT_LINE:
630 : : {
631 : 0 : nRelativeVerticalPosition = word::WdRelativeVerticalPosition::wdRelativeVerticalPositionLine;
632 : 0 : break;
633 : : }
634 : : case text::RelOrientation::PAGE_PRINT_AREA:
635 : : {
636 : 0 : nRelativeVerticalPosition = word::WdRelativeVerticalPosition::wdRelativeVerticalPositionMargin;
637 : 0 : break;
638 : : }
639 : : default:
640 : : {
641 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Shape::RelativeVerticalPosition: not implemented" ) ), uno::Reference< uno::XInterface >() );
642 : : }
643 : : }
644 : 0 : return nRelativeVerticalPosition;
645 : : }
646 : :
647 : : void SAL_CALL
648 : 0 : ScVbaShape::setRelativeVerticalPosition( ::sal_Int32 _relativeverticalposition ) throw (uno::RuntimeException)
649 : : {
650 : 0 : sal_Int16 nType = text::RelOrientation::PAGE_FRAME;
651 [ # # # # : 0 : switch( _relativeverticalposition )
# ]
652 : : {
653 : : case word::WdRelativeVerticalPosition::wdRelativeVerticalPositionLine:
654 : : {
655 : 0 : nType = text::RelOrientation::TEXT_LINE;
656 : 0 : break;
657 : : }
658 : : case word::WdRelativeVerticalPosition::wdRelativeVerticalPositionParagraph:
659 : : {
660 : 0 : nType = text::RelOrientation::FRAME;
661 : 0 : break;
662 : : }
663 : : case word::WdRelativeVerticalPosition::wdRelativeVerticalPositionMargin:
664 : : {
665 : 0 : nType = text::RelOrientation::PAGE_PRINT_AREA;
666 : 0 : break;
667 : : }
668 : : case word::WdRelativeVerticalPosition::wdRelativeVerticalPositionPage:
669 : : {
670 : 0 : nType = text::RelOrientation::PAGE_FRAME;
671 : 0 : break;
672 : : }
673 : : default:
674 : : {
675 [ # # ]: 0 : DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString());
676 : : }
677 : : }
678 [ # # ][ # # ]: 0 : m_xPropertySet->setPropertyValue( rtl::OUString( "VertOrientRelation" ), uno::makeAny( nType ) );
[ # # ]
679 : 0 : }
680 : :
681 : : uno::Any SAL_CALL
682 : 0 : ScVbaShape::WrapFormat() throw (uno::RuntimeException)
683 : : {
684 [ # # ]: 0 : uno::Reference< lang::XServiceInfo > xServiceInfo( m_xModel, uno::UNO_QUERY_THROW );
685 [ # # ][ # # ]: 0 : if( xServiceInfo->supportsService( ::rtl::OUString( "com.sun.star.text.TextDocument" ) ) )
[ # # ]
686 : : {
687 [ # # ][ # # ]: 0 : uno::Reference< lang::XMultiServiceFactory > xSF( comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
688 [ # # ]: 0 : uno::Sequence< uno::Any > aArgs(2);
689 [ # # ][ # # ]: 0 : aArgs[0] = uno::makeAny( getParent() );
[ # # ]
690 [ # # ][ # # ]: 0 : aArgs[1] <<= m_xShape;
691 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface > xWrapFormat( xSF->createInstanceWithArguments( rtl::OUString( "ooo.vba.word.WrapFormat" ) , aArgs ) , uno::UNO_QUERY_THROW );
[ # # ]
692 [ # # ][ # # ]: 0 : return uno::makeAny( xWrapFormat );
693 : : }
694 [ # # ]: 0 : throw uno::RuntimeException( rtl::OUString( "Not implemented" ), uno::Reference< uno::XInterface >() );
695 : : }
696 : :
697 : : rtl::OUString
698 : 0 : ScVbaShape::getServiceImplName()
699 : : {
700 : 0 : return rtl::OUString("ScVbaShape");
701 : : }
702 : :
703 : : uno::Sequence< rtl::OUString >
704 : 0 : ScVbaShape::getServiceNames()
705 : : {
706 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > aServiceNames;
[ # # ][ # # ]
707 [ # # ]: 0 : if ( aServiceNames.getLength() == 0 )
708 : : {
709 : 0 : aServiceNames.realloc( 1 );
710 [ # # ]: 0 : aServiceNames[ 0 ] = rtl::OUString( "ooo.vba.msform.Shape" );
711 : : }
712 : 0 : return aServiceNames;
713 : : }
714 : :
715 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|