diff options
author | Jan Holesovsky <kendy@suse.cz> | 2011-05-27 20:46:20 +0200 |
---|---|---|
committer | Jan Holesovsky <kendy@suse.cz> | 2011-05-27 20:46:20 +0200 |
commit | 9aad9cf77f93f6a689731972d97f2acc04527422 (patch) | |
tree | cf79102596e03d339b8429fd5545410b16292870 /vbahelper/source/vbahelper/vbahelper.cxx | |
parent | fde37c1a38273e7a90bb6d26cd1c948e8fe63783 (diff) | |
parent | a019d3e3c180b0ec41e2725e7cfe442afccf9cb0 (diff) |
Merge remote-tracking branch 'origin/integration/dev300_m106'
Conflicts:
basic/source/classes/sbunoobj.cxx
basic/source/inc/runtime.hxx
basic/source/runtime/step1.cxx
desktop/source/deployment/dp_services.cxx
drawinglayer/prj/d.lst
drawinglayer/source/primitive2d/makefile.mk
sfx2/source/appl/appinit.cxx
sfx2/source/appl/appquit.cxx
sfx2/source/inc/appdata.hxx
sfx2/source/view/viewfrm.cxx
svx/source/fmcomp/gridctrl.cxx
vbahelper/source/vbahelper/vbahelper.cxx
Diffstat (limited to 'vbahelper/source/vbahelper/vbahelper.cxx')
-rw-r--r-- | vbahelper/source/vbahelper/vbahelper.cxx | 687 |
1 files changed, 375 insertions, 312 deletions
diff --git a/vbahelper/source/vbahelper/vbahelper.cxx b/vbahelper/source/vbahelper/vbahelper.cxx index 35a75470e5..9b19012af0 100644 --- a/vbahelper/source/vbahelper/vbahelper.cxx +++ b/vbahelper/source/vbahelper/vbahelper.cxx @@ -485,82 +485,87 @@ void PrintOutHelper( SfxViewShell* pViewShell, const uno::Any& From, const uno:: dispatchExecute( pViewShell, SID_VIEWSHELL1 ); } -bool extractBoolFromAny( bool& rbValue, const uno::Any& rAny ) +sal_Int32 extractIntFromAny( const uno::Any& rAny ) throw (uno::RuntimeException) { - if( rAny >>= rbValue ) return true; - - sal_Int64 nSigned = 0; - if( rAny >>= nSigned ) { rbValue = nSigned != 0; return true; } - - sal_uInt64 nUnsigned = 0; - if( rAny >>= nUnsigned ) { rbValue = nUnsigned > 0; return true; } - - double fDouble = 0.0; - if( rAny >>= fDouble ) { rbValue = fDouble != 0.0; return true; } + switch( rAny.getValueType().getTypeClass() ) + { + case uno::TypeClass_FLOAT: + return static_cast< sal_Int32 >( rAny.get< float >() ); + case uno::TypeClass_DOUBLE: + return static_cast< sal_Int32 >( rAny.get< double >() ); + case uno::TypeClass_BYTE: + case uno::TypeClass_SHORT: + case uno::TypeClass_LONG: + return rAny.get< sal_Int32 >(); + default:; + } + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid type, cannot convert to integer." ) ), 0 ); +} - return false; +sal_Int32 extractIntFromAny( const uno::Any& rAny, sal_Int32 nDefault ) throw (uno::RuntimeException) +{ + return rAny.hasValue() ? extractIntFromAny( rAny ) : nDefault; } bool extractBoolFromAny( const uno::Any& rAny ) throw (uno::RuntimeException) { - bool bValue = false; - if( extractBoolFromAny( bValue, rAny ) ) - return bValue; - throw uno::RuntimeException(); + switch( rAny.getValueType().getTypeClass() ) + { + case uno::TypeClass_BOOLEAN: + return rAny.get< bool >(); + case uno::TypeClass_FLOAT: + return rAny.get< float >() != 0.0; + case uno::TypeClass_DOUBLE: + return rAny.get< double >() != 0.0; + case uno::TypeClass_BYTE: + case uno::TypeClass_SHORT: + case uno::TypeClass_LONG: + return rAny.get< sal_Int32 >() != 0; + case uno::TypeClass_HYPER: + return rAny.get< sal_Int64 >() != 0; + default:; + } + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid type, cannot convert to boolean." ) ), 0 ); +} + +bool extractBoolFromAny( const uno::Any& rAny, bool bDefault ) throw (uno::RuntimeException) +{ + return rAny.hasValue() ? extractBoolFromAny( rAny ) : bDefault; } -rtl::OUString getAnyAsString( const uno::Any& pvargItem ) throw ( uno::RuntimeException ) +::rtl::OUString extractStringFromAny( const uno::Any& rAny, bool bUppercaseBool ) throw (uno::RuntimeException) { - uno::Type aType = pvargItem.getValueType(); - uno::TypeClass eTypeClass = aType.getTypeClass(); - rtl::OUString sString; - switch ( eTypeClass ) + switch( rAny.getValueType().getTypeClass() ) { - case uno::TypeClass_BOOLEAN: - { - sal_Bool bBool = sal_False; - pvargItem >>= bBool; - sString = rtl::OUString::valueOf( bBool ); - break; - } case uno::TypeClass_STRING: - pvargItem >>= sString; - break; + return rAny.get< ::rtl::OUString >(); + case uno::TypeClass_BOOLEAN: + return bUppercaseBool ? + (rAny.get< bool >() ? ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TRUE" ) ) : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FALSE" ) )) : + ::rtl::OUString::valueOf( (sal_Bool)rAny.get< bool >() ); case uno::TypeClass_FLOAT: - { - float aFloat = 0; - pvargItem >>= aFloat; - sString = rtl::OUString::valueOf( aFloat ); - break; - } + return ::rtl::OUString::valueOf( rAny.get< float >() ); case uno::TypeClass_DOUBLE: - { - double aDouble = 0; - pvargItem >>= aDouble; - sString = rtl::OUString::valueOf( aDouble ); - break; - } + return ::rtl::OUString::valueOf( rAny.get< double >() ); + case uno::TypeClass_BYTE: case uno::TypeClass_SHORT: case uno::TypeClass_LONG: - case uno::TypeClass_BYTE: - { - sal_Int32 aNum = 0; - pvargItem >>= aNum; - sString = rtl::OUString::valueOf( aNum ); - break; - } - + return ::rtl::OUString::valueOf( rAny.get< sal_Int32 >() ); case uno::TypeClass_HYPER: - { - sal_Int64 aHyper = 0; - pvargItem >>= aHyper; - sString = rtl::OUString::valueOf( aHyper ); - break; - } - default: - throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Invalid type, can't convert")), uno::Reference< uno::XInterface >() ); + return ::rtl::OUString::valueOf( rAny.get< sal_Int64 >() ); + default:; } - return sString; + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid type, cannot convert to string." ) ), 0 ); +} + +::rtl::OUString extractStringFromAny( const uno::Any& rAny, const ::rtl::OUString& rDefault, bool bUppercaseBool ) throw (uno::RuntimeException) +{ + return rAny.hasValue() ? extractStringFromAny( rAny, bUppercaseBool ) : rDefault; +} + +rtl::OUString getAnyAsString( const uno::Any& pvargItem ) throw ( uno::RuntimeException ) +{ + return extractStringFromAny( pvargItem ); } @@ -697,7 +702,7 @@ rtl::OUString VBAToRegexp(const rtl::OUString &rIn, bool bForLike ) return sResult.makeStringAndClear( ); } -double getPixelTo100thMillimeterConversionFactor( css::uno::Reference< css::awt::XDevice >& xDevice, sal_Bool bVertical) +double getPixelTo100thMillimeterConversionFactor( const css::uno::Reference< css::awt::XDevice >& xDevice, sal_Bool bVertical) { double fConvertFactor = 1.0; if( bVertical ) @@ -711,12 +716,12 @@ double getPixelTo100thMillimeterConversionFactor( css::uno::Reference< css::awt: return fConvertFactor; } -double PointsToPixels( css::uno::Reference< css::awt::XDevice >& xDevice, double fPoints, sal_Bool bVertical) +double PointsToPixels( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPoints, sal_Bool bVertical) { double fConvertFactor = getPixelTo100thMillimeterConversionFactor( xDevice, bVertical ); return PointsToHmm( fPoints ) * fConvertFactor; } -double PixelsToPoints( css::uno::Reference< css::awt::XDevice >& xDevice, double fPixels, sal_Bool bVertical) +double PixelsToPoints( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPixels, sal_Bool bVertical) { double fConvertFactor = getPixelTo100thMillimeterConversionFactor( xDevice, bVertical ); return HmmToPoints(static_cast<sal_Int32>(fPixels/fConvertFactor)); @@ -880,345 +885,403 @@ void setOrAppendPropertyValue( uno::Sequence< beans::PropertyValue >& aProp, con // ====UserFormGeomentryHelper==== //--------------------------------------------- -UserFormGeometryHelper::UserFormGeometryHelper( const uno::Reference< uno::XComponentContext >& /*xContext*/, const uno::Reference< awt::XControl >& xControl ) -: mbDialog( uno::Reference< awt::XDialog >( xControl, uno::UNO_QUERY ).is() ) +UserFormGeometryHelper::UserFormGeometryHelper( + const uno::Reference< uno::XComponentContext >& /*xContext*/, + const uno::Reference< awt::XControl >& xControl, + double fOffsetX, double fOffsetY ) : + mfOffsetX( fOffsetX ), + mfOffsetY( fOffsetY ), + mbDialog( uno::Reference< awt::XDialog >( xControl, uno::UNO_QUERY ).is() ) { if ( !xControl.is() ) throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No control is provided!" ) ), uno::Reference< uno::XInterface >() ); mxWindow.set( xControl->getPeer(), uno::UNO_QUERY_THROW ); + mxModelProps.set( xControl->getModel(), uno::UNO_QUERY_THROW ); + mxUnitConv.set( mxWindow, uno::UNO_QUERY_THROW ); } -//--------------------------------------------- -double UserFormGeometryHelper::getLeft() +double UserFormGeometryHelper::getLeft() const { - return mxWindow->getPosSize().X; + return implGetPos( false ); } -//--------------------------------------------- -void UserFormGeometryHelper::setLeft( double nLeft ) +void UserFormGeometryHelper::setLeft( double fLeft ) { - mxWindow->setPosSize(static_cast<sal_Int32>(nLeft), mxWindow->getPosSize().Y, 0, 0, awt::PosSize::POS ); + implSetPos( fLeft, false ); } -//--------------------------------------------- -double UserFormGeometryHelper::getTop() +double UserFormGeometryHelper::getTop() const { - return mxWindow->getPosSize().Y; + return implGetPos( true ); } -//--------------------------------------------- -void UserFormGeometryHelper::setTop( double nTop ) +void UserFormGeometryHelper::setTop( double fTop ) { - mxWindow->setPosSize( mxWindow->getPosSize().X, static_cast<sal_Int32>(nTop), 0, 0, awt::PosSize::POS ); + implSetPos( fTop, true ); } -//--------------------------------------------- -double UserFormGeometryHelper::getWidth() +double UserFormGeometryHelper::getWidth() const { - if ( mbDialog ) - { - const Window* pWindow = VCLUnoHelper::GetWindow( mxWindow ); - if ( pWindow ) - { - // get the size with decoration - Rectangle aResult = pWindow->GetWindowExtentsRelative( NULL ); - return aResult.getWidth(); - } - } - - return mxWindow->getPosSize().Width; + return implGetSize( false, true ); } -//--------------------------------------------- -void UserFormGeometryHelper::setWidth( double nWidth ) +void UserFormGeometryHelper::setWidth( double fWidth ) { - sal_Int64 nNewWidth = static_cast<sal_Int64>(nWidth); + implSetSize( fWidth, false, true ); +} - if ( mbDialog ) - { - const Window* pWindow = VCLUnoHelper::GetWindow( mxWindow ); - if ( pWindow ) - { - // set the size with decoration - Rectangle aRDecor = pWindow->GetWindowExtentsRelative( NULL ); - if ( !aRDecor.IsEmpty() ) - { - sal_Int64 nDecor = aRDecor.getWidth(); - sal_Int64 nUnDecor = mxWindow->getPosSize().Width; - if ( nWidth < nDecor - nUnDecor ) - nUnDecor = static_cast<sal_Int64>(nDecor - nWidth); // avoid negative size - nNewWidth = static_cast<sal_Int64>(nWidth + nUnDecor - nDecor); - } - } - } +double UserFormGeometryHelper::getHeight() const +{ + return implGetSize( true, true ); +} - mxWindow->setPosSize( 0, 0, nNewWidth, 0, awt::PosSize::WIDTH ); +void UserFormGeometryHelper::setHeight( double fHeight ) +{ + implSetSize( fHeight, true, true ); } -//--------------------------------------------- -double UserFormGeometryHelper::getHeight() +double UserFormGeometryHelper::getInnerWidth() const { - if ( mbDialog ) - { - const Window* pWindow = VCLUnoHelper::GetWindow( mxWindow ); - if ( pWindow ) - { - // get the size with decoration - Rectangle aResult = pWindow->GetWindowExtentsRelative( NULL ); - return aResult.getHeight(); - } - } + return implGetSize( false, false ); +} - return mxWindow->getPosSize().Height; +void UserFormGeometryHelper::setInnerWidth( double fWidth ) +{ + implSetSize( fWidth, false, false ); } -//--------------------------------------------- -void UserFormGeometryHelper::setHeight( double nHeight ) +double UserFormGeometryHelper::getInnerHeight() const { - sal_Int64 nNewHeight = static_cast<sal_Int64>(nHeight); - if ( mbDialog ) - { - const Window* pWindow = VCLUnoHelper::GetWindow( mxWindow ); - if ( pWindow ) - { - // set the size with decoration - Rectangle aRDecor = pWindow->GetWindowExtentsRelative( NULL ); - if ( !aRDecor.IsEmpty() ) - { - sal_Int64 nDecor = aRDecor.getHeight(); - sal_Int64 nUnDecor = mxWindow->getPosSize().Height; - if ( nHeight < nDecor - nUnDecor ) - nUnDecor = static_cast<sal_Int64>(nDecor - nHeight); // avoid negative size - nNewHeight = static_cast<sal_Int64>(nHeight + nUnDecor - nDecor); - } - } - } + return implGetSize( true, false ); +} - mxWindow->setPosSize( 0, 0, 0, nNewHeight, awt::PosSize::HEIGHT ); +void UserFormGeometryHelper::setInnerHeight( double fHeight ) +{ + implSetSize( fHeight, true, false ); } -// ============ +double UserFormGeometryHelper::getOffsetX() const +{ + return mfOffsetX; +} - double ConcreteXShapeGeometryAttributes::getLeft() - { - return m_pShapeHelper->getLeft(); - } - void ConcreteXShapeGeometryAttributes::setLeft( double nLeft ) - { - m_pShapeHelper->setLeft( nLeft ); - } - double ConcreteXShapeGeometryAttributes::getTop() - { - return m_pShapeHelper->getTop(); - } - void ConcreteXShapeGeometryAttributes::setTop( double nTop ) - { - m_pShapeHelper->setTop( nTop ); - } +double UserFormGeometryHelper::getOffsetY() const +{ + return mfOffsetY; +} - double ConcreteXShapeGeometryAttributes::getHeight() - { - return m_pShapeHelper->getHeight(); - } - void ConcreteXShapeGeometryAttributes::setHeight( double nHeight ) - { - m_pShapeHelper->setHeight( nHeight ); - } - double ConcreteXShapeGeometryAttributes::getWidth() - { - return m_pShapeHelper->getWidth(); - } - void ConcreteXShapeGeometryAttributes::setWidth( double nWidth) - { - m_pShapeHelper->setWidth( nWidth ); - } +// ---------------------------------------------------------------------------- +static const ::rtl::OUString saPosXName( RTL_CONSTASCII_USTRINGPARAM( "PositionX" ) ); +static const ::rtl::OUString saPosYName( RTL_CONSTASCII_USTRINGPARAM( "PositionY" ) ); +static const ::rtl::OUString saWidthName( RTL_CONSTASCII_USTRINGPARAM( "Width" ) ); +static const ::rtl::OUString saHeightName( RTL_CONSTASCII_USTRINGPARAM( "Height" ) ); - ShapeHelper::ShapeHelper( const css::uno::Reference< css::drawing::XShape >& _xShape) throw (css::script::BasicErrorException ) : xShape( _xShape ) - { - if( !xShape.is() ) - throw css::uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("No valid shape for helper")), css::uno::Reference< css::uno::XInterface >() ); - } +double UserFormGeometryHelper::implGetPos( bool bPosY ) const +{ + sal_Int32 nPosAppFont = mxModelProps->getPropertyValue( bPosY ? saPosYName : saPosXName ).get< sal_Int32 >(); + // appfont to pixel + awt::Point aPosPixel = mxUnitConv->convertPointToPixel( awt::Point( nPosAppFont, nPosAppFont ), util::MeasureUnit::APPFONT ); + // pixel to VBA points + awt::Point aPosPoint = mxUnitConv->convertPointToLogic( aPosPixel, util::MeasureUnit::POINT ); + return bPosY ? (aPosPoint.Y - mfOffsetY) : (aPosPoint.X - mfOffsetX); +} - double ShapeHelper::getHeight() - { - return Millimeter::getInPoints(xShape->getSize().Height); - } +void UserFormGeometryHelper::implSetPos( double fPos, bool bPosY ) +{ + // convert passed VBA points to pixels + sal_Int32 nPosPixel = static_cast< sal_Int32 >( fPos + (bPosY ? mfOffsetY : mfOffsetX) ); + awt::Point aPosPixel = mxUnitConv->convertPointToPixel( awt::Point( nPosPixel, nPosPixel ), util::MeasureUnit::POINT ); + // pixel to appfont + awt::Point aPosAppFont = mxUnitConv->convertPointToLogic( aPosPixel, util::MeasureUnit::APPFONT ); + mxModelProps->setPropertyValue( bPosY ? saPosYName : saPosXName, uno::Any( bPosY ? aPosAppFont.Y : aPosAppFont.X ) ); +} +double UserFormGeometryHelper::implGetSize( bool bHeight, bool bOuter ) const +{ + sal_Int32 nSizeAppFont = mxModelProps->getPropertyValue( bHeight ? saHeightName : saWidthName ).get< sal_Int32 >(); + // appfont to pixel + awt::Size aSizePixel = mxUnitConv->convertSizeToPixel( awt::Size( nSizeAppFont, nSizeAppFont ), util::MeasureUnit::APPFONT ); - void ShapeHelper::setHeight(double _fheight) throw ( css::script::BasicErrorException ) + /* The VBA symbols 'Width' and 'Height' return the outer size including + window decoration (in difference to the symbols 'InnerWidth' and + 'InnerHeight'), but the window API returns the inner size. */ + if( mbDialog && bOuter ) { - try + if( const Window* pWindow = VCLUnoHelper::GetWindow( mxWindow ) ) { - css::awt::Size aSize = xShape->getSize(); - aSize.Height = Millimeter::getInHundredthsOfOneMillimeter(_fheight); - xShape->setSize(aSize); + Rectangle aOuterRect = pWindow->GetWindowExtentsRelative( NULL ); + aSizePixel = awt::Size( aOuterRect.getWidth(), aOuterRect.getHeight() ); } - catch ( css::uno::Exception& /*e*/) - { - throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); - } } + // pixel to VBA points + awt::Size aSizePoint = mxUnitConv->convertSizeToLogic( aSizePixel, util::MeasureUnit::POINT ); + return bHeight ? aSizePoint.Height : aSizePoint.Width; +} - double ShapeHelper::getWidth() - { - return Millimeter::getInPoints(xShape->getSize().Width); - } +void UserFormGeometryHelper::implSetSize( double fSize, bool bHeight, bool bOuter ) +{ + // convert passed VBA points to pixels + sal_Int32 nSize = static_cast< sal_Int32 >( fSize ); + awt::Size aSizePixel = mxUnitConv->convertSizeToPixel( awt::Size( nSize, nSize ), util::MeasureUnit::POINT ); - void ShapeHelper::setWidth(double _fWidth) throw ( css::script::BasicErrorException ) + /* The VBA symbols 'Width' and 'Height' set the outer size (in difference + to the symbols 'InnerWidth' and 'InnerHeight'), but the dialog model + expects the inner size. We have to remove the window extents from the + pixel height to get the same result. */ + if ( mbDialog && bOuter ) { - try - { - css::awt::Size aSize = xShape->getSize(); - aSize.Width = Millimeter::getInHundredthsOfOneMillimeter(_fWidth); - xShape->setSize(aSize); - } - catch (css::uno::Exception& /*e*/) + if( const Window* pWindow = VCLUnoHelper::GetWindow( mxWindow ) ) { - throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + Rectangle aOuterRect = pWindow->GetWindowExtentsRelative( NULL ); + if( !aOuterRect.IsEmpty() ) + { + awt::Rectangle aInnerRect = mxWindow->getPosSize(); + sal_Int32 nDecorWidth = aOuterRect.getWidth() - aInnerRect.Width; + sal_Int32 nDecorHeight = aOuterRect.getHeight() - aInnerRect.Height; + aSizePixel.Width = ::std::max< sal_Int32 >( aSizePixel.Width - nDecorWidth, 1 ); + aSizePixel.Height = ::std::max< sal_Int32 >( aSizePixel.Height - nDecorHeight, 1 ); + } } } + awt::Size aSizeAppFont = mxUnitConv->convertSizeToLogic( aSizePixel, util::MeasureUnit::APPFONT ); + mxModelProps->setPropertyValue( bHeight ? saHeightName : saWidthName, uno::Any( bHeight ? aSizeAppFont.Height : aSizeAppFont.Width ) ); +} + +// ============================================================================ - double ShapeHelper::getLeft() - { - return Millimeter::getInPoints(xShape->getPosition().X); - } +double ConcreteXShapeGeometryAttributes::getLeft() const +{ + return m_pShapeHelper->getLeft(); +} +void ConcreteXShapeGeometryAttributes::setLeft( double nLeft ) +{ + m_pShapeHelper->setLeft( nLeft ); +} +double ConcreteXShapeGeometryAttributes::getTop() const +{ + return m_pShapeHelper->getTop(); +} +void ConcreteXShapeGeometryAttributes::setTop( double nTop ) +{ + m_pShapeHelper->setTop( nTop ); +} +double ConcreteXShapeGeometryAttributes::getHeight() const +{ + return m_pShapeHelper->getHeight(); +} +void ConcreteXShapeGeometryAttributes::setHeight( double nHeight ) +{ + m_pShapeHelper->setHeight( nHeight ); +} +double ConcreteXShapeGeometryAttributes::getWidth() const +{ + return m_pShapeHelper->getWidth(); +} +void ConcreteXShapeGeometryAttributes::setWidth( double nWidth) +{ + m_pShapeHelper->setWidth( nWidth ); +} - void ShapeHelper::setLeft(double _fLeft) - { - css::awt::Point aPoint = xShape->getPosition(); - aPoint.X = Millimeter::getInHundredthsOfOneMillimeter(_fLeft); - xShape->setPosition(aPoint); - } +ShapeHelper::ShapeHelper( const css::uno::Reference< css::drawing::XShape >& _xShape) throw (css::script::BasicErrorException ) : xShape( _xShape ) +{ + if( !xShape.is() ) + throw css::uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("No valid shape for helper")), css::uno::Reference< css::uno::XInterface >() ); +} - double ShapeHelper::getTop() - { - return Millimeter::getInPoints(xShape->getPosition().Y); +double ShapeHelper::getHeight() const +{ + return Millimeter::getInPoints(xShape->getSize().Height); } - void ShapeHelper::setTop(double _fTop) + void ShapeHelper::setHeight(double _fheight) throw ( css::script::BasicErrorException ) +{ + try { - css::awt::Point aPoint = xShape->getPosition(); - aPoint.Y = Millimeter::getInHundredthsOfOneMillimeter(_fTop); - xShape->setPosition(aPoint); + css::awt::Size aSize = xShape->getSize(); + aSize.Height = Millimeter::getInHundredthsOfOneMillimeter(_fheight); + xShape->setSize(aSize); } - - void DebugHelper::exception( const rtl::OUString& DetailedMessage, const css::uno::Exception& ex, int err, const rtl::OUString& /*additionalArgument*/ ) throw( css::script::BasicErrorException ) + catch ( css::uno::Exception& /*e*/) { - // #TODO #FIXME ( do we want to support additionalArg here ) - throw css::script::BasicErrorException( DetailedMessage.concat( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ")) ).concat( ex.Message ), css::uno::Reference< css::uno::XInterface >(), err, rtl::OUString() ); + throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } +} +double ShapeHelper::getWidth() const +{ + return Millimeter::getInPoints(xShape->getSize().Width); } - void DebugHelper::exception( int err, const rtl::OUString& additionalArgument ) throw( css::script::BasicErrorException ) +void ShapeHelper::setWidth(double _fWidth) throw ( css::script::BasicErrorException ) +{ + try { - exception( rtl::OUString(), css::uno::Exception(), err, additionalArgument ); + css::awt::Size aSize = xShape->getSize(); + aSize.Width = Millimeter::getInHundredthsOfOneMillimeter(_fWidth); + xShape->setSize(aSize); } - void DebugHelper::exception( const css::uno::Exception& ex ) throw( css::script::BasicErrorException ) + catch (css::uno::Exception& /*e*/) { - exception( rtl::OUString(), ex, SbERR_INTERNAL_ERROR, rtl::OUString() ); + throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); } +} - Millimeter::Millimeter():m_nMillimeter(0) {} - Millimeter::Millimeter(double mm):m_nMillimeter(mm) {} +double ShapeHelper::getLeft() const +{ + return Millimeter::getInPoints(xShape->getPosition().X); +} - void Millimeter::set(double mm) { m_nMillimeter = mm; } - void Millimeter::setInPoints(double points) - { - m_nMillimeter = points * factor / 100.0; - } - void Millimeter::setInHundredthsOfOneMillimeter(double hmm) - { - m_nMillimeter = hmm / 100; - } +void ShapeHelper::setLeft(double _fLeft) +{ + css::awt::Point aPoint = xShape->getPosition(); + aPoint.X = Millimeter::getInHundredthsOfOneMillimeter(_fLeft); + xShape->setPosition(aPoint); +} - double Millimeter::get() - { - return m_nMillimeter; - } - double Millimeter::getInHundredthsOfOneMillimeter() - { - return m_nMillimeter * 100; - } - double Millimeter::getInPoints() - { - return m_nMillimeter / factor * 100.0; - } - sal_Int32 Millimeter::getInHundredthsOfOneMillimeter(double points) - { - sal_Int32 mm = static_cast<sal_Int32>(points * factor); - return mm; - } +double ShapeHelper::getTop() const +{ + return Millimeter::getInPoints(xShape->getPosition().Y); +} - double Millimeter::getInPoints(int _hmm) - { - double points = double( static_cast<double>(_hmm) / factor); - return points; - } - uno::Reference< uno::XInterface > getUnoDocModule( const String& aModName, SfxObjectShell* pShell ) - { - uno::Reference< uno::XInterface > xIf; - if ( pShell ) - { - rtl::OUString sProj( RTL_CONSTASCII_USTRINGPARAM("Standard") ); - BasicManager* pBasMgr = pShell->GetBasicManager(); - if ( pBasMgr && pBasMgr->GetName().Len() ) - sProj = pShell->GetBasicManager()->GetName(); - StarBASIC* pBasic = pShell->GetBasicManager()->GetLib( sProj ); - if ( pBasic ) - { - SbModule* pMod = pBasic->FindModule( aModName ); - if ( pMod ) - xIf = pMod->GetUnoModule(); - } - } - return xIf; - } +void ShapeHelper::setTop(double _fTop) +{ + css::awt::Point aPoint = xShape->getPosition(); + aPoint.Y = Millimeter::getInHundredthsOfOneMillimeter(_fTop); + xShape->setPosition(aPoint); +} - // Listener for XNotifyingDispatch - VBADispatchListener::VBADispatchListener() : m_State( sal_False ) - { - } +void DebugHelper::exception( const rtl::OUString& DetailedMessage, const css::uno::Exception& ex, int err, const rtl::OUString& /*additionalArgument*/ ) throw( css::script::BasicErrorException ) +{ + // #TODO #FIXME ( do we want to support additionalArg here ) + throw css::script::BasicErrorException( DetailedMessage.concat( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ")) ).concat( ex.Message ), css::uno::Reference< css::uno::XInterface >(), err, rtl::OUString() ); +} + +void DebugHelper::exception( int err, const rtl::OUString& additionalArgument ) throw( css::script::BasicErrorException ) +{ + exception( rtl::OUString(), css::uno::Exception(), err, additionalArgument ); +} +void DebugHelper::exception( const css::uno::Exception& ex ) throw( css::script::BasicErrorException ) +{ + exception( rtl::OUString(), ex, SbERR_INTERNAL_ERROR, rtl::OUString() ); +} + +Millimeter::Millimeter():m_nMillimeter(0) {} - // Listener for XNotifyingDispatch - VBADispatchListener::~VBADispatchListener() +Millimeter::Millimeter(double mm):m_nMillimeter(mm) {} + +void Millimeter::set(double mm) { m_nMillimeter = mm; } +void Millimeter::setInPoints(double points) +{ + m_nMillimeter = points * factor / 100.0; +} + +void Millimeter::setInHundredthsOfOneMillimeter(double hmm) +{ + m_nMillimeter = hmm / 100; +} + +double Millimeter::get() +{ + return m_nMillimeter; +} +double Millimeter::getInHundredthsOfOneMillimeter() +{ + return m_nMillimeter * 100; +} +double Millimeter::getInPoints() +{ + return m_nMillimeter / factor * 100.0; +} + +sal_Int32 Millimeter::getInHundredthsOfOneMillimeter(double points) +{ + sal_Int32 mm = static_cast<sal_Int32>(points * factor); + return mm; +} + +double Millimeter::getInPoints(int _hmm) +{ + double points = double( static_cast<double>(_hmm) / factor); + return points; +} + +// Listener for XNotifyingDispatch +VBADispatchListener::VBADispatchListener() : m_State( sal_False ) +{ +} + +// Listener for XNotifyingDispatch +VBADispatchListener::~VBADispatchListener() +{ +} + +// Listener for XNotifyingDispatch +void SAL_CALL VBADispatchListener::dispatchFinished( const frame::DispatchResultEvent& aEvent ) throw ( uno::RuntimeException ) +{ + m_Result = aEvent.Result; + m_State = ( aEvent.State == frame::DispatchResultState::SUCCESS ) ? sal_True : sal_False; +} + +// Listener for XNotifyingDispatch +void SAL_CALL VBADispatchListener::disposing( const lang::EventObject& /*aEvent*/ ) throw( uno::RuntimeException ) +{ +} + +uno::Reference< XHelperInterface > getVBADocument( const uno::Reference< frame::XModel >& xModel ) +{ + uno::Reference< XHelperInterface > xIf; + try { + uno::Reference< beans::XPropertySet > xDocProps( xModel, uno::UNO_QUERY_THROW ); + ::rtl::OUString aCodeName; + xDocProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CodeName" ) ) ) >>= aCodeName; + xIf = getUnoDocModule( aCodeName, getSfxObjShell( xModel ) ); } - - // Listener for XNotifyingDispatch - void SAL_CALL VBADispatchListener::dispatchFinished( const frame::DispatchResultEvent& aEvent ) throw ( uno::RuntimeException ) + catch( uno::Exception& ) { - m_Result = aEvent.Result; - m_State = ( aEvent.State == frame::DispatchResultState::SUCCESS ) ? sal_True : sal_False; } + return xIf; +} - // Listener for XNotifyingDispatch - void SAL_CALL VBADispatchListener::disposing( const lang::EventObject& /*aEvent*/ ) throw( uno::RuntimeException ) +uno::Reference< XHelperInterface > getUnoDocModule( const String& aModName, SfxObjectShell* pShell ) +{ + uno::Reference< XHelperInterface > xIf; + if ( pShell ) + { + rtl::OUString sProj( RTL_CONSTASCII_USTRINGPARAM("Standard") ); + BasicManager* pBasMgr = pShell->GetBasicManager(); + if ( pBasMgr && pBasMgr->GetName().Len() ) + sProj = pBasMgr->GetName(); + if( StarBASIC* pBasic = pShell->GetBasicManager()->GetLib( sProj ) ) + if( SbModule* pMod = pBasic->FindModule( aModName ) ) + xIf.set( pMod->GetUnoModule(), uno::UNO_QUERY ); + } + return xIf; +} + +SfxObjectShell* getSfxObjShell( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) +{ + SfxObjectShell* pFoundShell = NULL; + if ( xModel.is() ) { + uno::Reference< lang::XUnoTunnel > xObjShellTunnel( xModel, uno::UNO_QUERY_THROW ); + pFoundShell = reinterpret_cast<SfxObjectShell*>( xObjShellTunnel->getSomething(SfxObjectShell::getUnoTunnelId())); } - - SfxObjectShell* getSfxObjShell( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) - { - SfxObjectShell* pFoundShell = NULL; - if ( xModel.is() ) - { - uno::Reference< lang::XUnoTunnel > xObjShellTunnel( xModel, uno::UNO_QUERY_THROW ); - pFoundShell = reinterpret_cast<SfxObjectShell*>( xObjShellTunnel->getSomething(SfxObjectShell::getUnoTunnelId())); - } - if ( !pFoundShell ) - throw uno::RuntimeException(); - return pFoundShell; - } + if ( !pFoundShell ) + throw uno::RuntimeException(); + return pFoundShell; +} } // openoffice } //org |