diff options
author | Mikhail Voytenko <mav@openoffice.org> | 2010-08-26 19:24:07 +0200 |
---|---|---|
committer | Mikhail Voytenko <mav@openoffice.org> | 2010-08-26 19:24:07 +0200 |
commit | 6e9b786ff6a7f2efca0b8ff4db9215202878a8ca (patch) | |
tree | 5b5b2217c5fcceb5f11a3ac90ea67bdb7405fcbc /vbahelper | |
parent | af733eacab845b986a0ba235fb5a52b9a0e80be1 (diff) |
mib19: #i163287# handle the dialog size in the way VBA does it
Diffstat (limited to 'vbahelper')
-rw-r--r-- | vbahelper/inc/vbahelper/vbahelper.hxx | 7 | ||||
-rw-r--r-- | vbahelper/source/vbahelper/vbahelper.cxx | 322 |
2 files changed, 115 insertions, 214 deletions
diff --git a/vbahelper/inc/vbahelper/vbahelper.hxx b/vbahelper/inc/vbahelper/vbahelper.hxx index ccabb9114f2d..4c4a9f5d7204 100644 --- a/vbahelper/inc/vbahelper/vbahelper.hxx +++ b/vbahelper/inc/vbahelper/vbahelper.hxx @@ -194,11 +194,8 @@ public: #define VBA_WIDTH "Width" class VBAHELPER_DLLPUBLIC UserFormGeometryHelper : public AbstractGeometryAttributes { - css::uno::Reference< css::awt::XUnitConversion > mxControlUnits; - css::uno::Reference< css::beans::XPropertySet > mxModel; - - sal_Int32 ConvertLogicToPixel( sal_Int32 nValue, sal_Bool bIsPoint, sal_Bool bIsX, sal_Int16 nSourceUnit ); - sal_Int32 ConvertPixelToLogic( sal_Int32 nValue, sal_Bool bIsPoint, sal_Bool bIsX, sal_Int16 nTargetUnit ); + css::uno::Reference< css::awt::XWindow > mxWindow; + sal_Bool mbDialog; public: UserFormGeometryHelper( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::awt::XControl >& xControl ); diff --git a/vbahelper/source/vbahelper/vbahelper.cxx b/vbahelper/source/vbahelper/vbahelper.cxx index 14f4e3ff1363..fa80e8dc9234 100644 --- a/vbahelper/source/vbahelper/vbahelper.cxx +++ b/vbahelper/source/vbahelper/vbahelper.cxx @@ -39,6 +39,9 @@ #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XIntrospection.hpp> #include <com/sun/star/util/MeasureUnit.hpp> +#include <com/sun/star/awt/XWindow.hpp> +#include <com/sun/star/awt/XDialog.hpp> +#include <com/sun/star/awt/PosSize.hpp> #include <ooo/vba/msforms/XShape.hpp> @@ -989,277 +992,178 @@ sal_Bool setPropertyValue( uno::Sequence< beans::PropertyValue >& aProp, const r // ====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() ) { if ( !xControl.is() ) - throw uno::RuntimeException(); - - mxControlUnits.set( xControl->getPeer(), uno::UNO_QUERY_THROW ); - mxModel.set( xControl->getModel(), uno::UNO_QUERY_THROW ); -} - -//--------------------------------------------- -sal_Int32 UserFormGeometryHelper::ConvertPixelToLogic( sal_Int32 nValue, sal_Bool bIsPoint, sal_Bool bIsX, sal_Int16 nTargetUnit ) -{ - sal_Int32 nResult = 0; - if ( bIsPoint ) - { - // conversion for a point - awt::Point aPixelPoint( 0, 0 ); - ( bIsX ? aPixelPoint.X : aPixelPoint.Y ) = nValue; - awt::Point aTargetPoint( 0, 0 ); - aTargetPoint = mxControlUnits->convertPointToLogic( aPixelPoint, nTargetUnit ); + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No control is provided!" ) ), + uno::Reference< uno::XInterface >() ); - nResult = bIsX ? aTargetPoint.X : aTargetPoint.Y; - } - else - { - // conversion for a size - awt::Size aPixelSize( 0, 0 ); - ( bIsX ? aPixelSize.Width : aPixelSize.Height ) = nValue; - awt::Size aTargetSize( 0, 0 ); - aTargetSize = mxControlUnits->convertSizeToLogic( aPixelSize, nTargetUnit ); - - nResult = bIsX ? aTargetSize.Width : aTargetSize.Height; - } - - return nResult; + mxWindow.set( xControl->getPeer(), uno::UNO_QUERY_THROW ); } //--------------------------------------------- -sal_Int32 UserFormGeometryHelper::ConvertLogicToPixel( sal_Int32 nValue, sal_Bool bIsPoint, sal_Bool bIsX, sal_Int16 nSourceUnit ) -{ - sal_Int32 nResult = 0; - if ( bIsPoint ) - { - // conversion for a point - awt::Point aSourcePoint( 0, 0 ); - ( bIsX ? aSourcePoint.X : aSourcePoint.Y ) = nValue; - - awt::Point aPixelPoint( 0, 0 ); - aPixelPoint = mxControlUnits->convertPointToPixel( aSourcePoint, nSourceUnit ); - - nResult = bIsX ? aPixelPoint.X : aPixelPoint.Y; - } - else - { - // conversion for a size - awt::Size aSourceSize( 0, 0 ); - ( bIsX ? aSourceSize.Width : aSourceSize.Height ) = nValue; - - awt::Size aPixelSize( 0, 0 ); - aPixelSize = mxControlUnits->convertSizeToPixel( aSourceSize, nSourceUnit ); - - nResult = bIsX ? aPixelSize.Width : aPixelSize.Height; - } - - return nResult; -} -//--------------------------------------------- double UserFormGeometryHelper::getLeft() { - double nResult = 0; - - try - { - sal_Int32 nLeft = 0; - mxModel->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( VBA_LEFT ) ) ) >>= nLeft; - nResult = ConvertLogicToPixel( nLeft, - sal_True, // Point - sal_True, // X - util::MeasureUnit::APPFONT ); - } - catch ( uno::RuntimeException& ) + if ( mbDialog ) { - throw; - } - catch ( uno::Exception& e ) - { - throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can not get position X!" ) ), - uno::Reference< uno::XInterface >(), - uno::makeAny( e ) ); + const Window* pWindow = VCLUnoHelper::GetWindow( mxWindow ); + if ( pWindow ) + { + // get the size with decoration + Rectangle aResult = pWindow->GetWindowExtentsRelative( NULL ); + return aResult.getX(); + } } - return nResult; + return mxWindow->getPosSize().X; } //--------------------------------------------- void UserFormGeometryHelper::setLeft( double nLeft ) { - try - { - mxModel->setPropertyValue( - rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( VBA_LEFT ) ), - uno::makeAny( ConvertPixelToLogic( nLeft, - sal_True, // Point - sal_True, // X - util::MeasureUnit::APPFONT ) ) ); - } - catch ( uno::RuntimeException& ) + sal_Int64 nNewLeft = nLeft; + if ( mbDialog ) { - throw; - } - catch ( uno::Exception& e ) - { - throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can not set position X!" ) ), - uno::Reference< uno::XInterface >(), - uno::makeAny( e ) ); + 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.getX(); + sal_Int64 nUnDecor = mxWindow->getPosSize().X; + nNewLeft = nLeft + nUnDecor - nDecor; + } + } } + + mxWindow->setPosSize( nNewLeft, 0, 0, 0, awt::PosSize::X ); } //--------------------------------------------- double UserFormGeometryHelper::getTop() { - double nResult = 0; - - try + if ( mbDialog ) { - sal_Int32 nTop = 0; - mxModel->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( VBA_TOP ) ) ) >>= nTop; - nResult = ConvertLogicToPixel( nTop, - sal_True, // Point - sal_False, // Y - util::MeasureUnit::APPFONT ); - } - catch ( uno::RuntimeException& ) - { - throw; - } - catch ( uno::Exception& e ) - { - throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can not get position Y!" ) ), - uno::Reference< uno::XInterface >(), - uno::makeAny( e ) ); + const Window* pWindow = VCLUnoHelper::GetWindow( mxWindow ); + if ( pWindow ) + { + // get the size with decoration + Rectangle aResult = pWindow->GetWindowExtentsRelative( NULL ); + return aResult.getY(); + } } - return nResult; + return mxWindow->getPosSize().Y; } //--------------------------------------------- void UserFormGeometryHelper::setTop( double nTop ) { - try - { - mxModel->setPropertyValue( - rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( VBA_TOP ) ), - uno::makeAny( ConvertPixelToLogic( nTop, - sal_True, // Point - sal_False, // Y - util::MeasureUnit::APPFONT ) ) ); - } - catch ( uno::RuntimeException& ) + sal_Int64 nNewTop = nTop; + if ( mbDialog ) { - throw; - } - catch ( uno::Exception& e ) - { - throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can not set position X!" ) ), - uno::Reference< uno::XInterface >(), - uno::makeAny( e ) ); + 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.getY(); + sal_Int64 nUnDecor = mxWindow->getPosSize().Y; + nNewTop = nTop + nUnDecor - nDecor; + } + } } + + mxWindow->setPosSize( 0, nNewTop, 0, 0, awt::PosSize::Y ); } //--------------------------------------------- double UserFormGeometryHelper::getWidth() { - double nResult = 0; - - try + if ( mbDialog ) { - sal_Int32 nWidth = 0; - mxModel->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( VBA_WIDTH ) ) ) >>= nWidth; - nResult = ConvertLogicToPixel( nWidth, - sal_False, // Size - sal_True, // X - util::MeasureUnit::APPFONT ); - } - catch ( uno::RuntimeException& ) - { - throw; - } - catch ( uno::Exception& e ) - { - throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can not get width!" ) ), - uno::Reference< uno::XInterface >(), - uno::makeAny( e ) ); + const Window* pWindow = VCLUnoHelper::GetWindow( mxWindow ); + if ( pWindow ) + { + // get the size with decoration + Rectangle aResult = pWindow->GetWindowExtentsRelative( NULL ); + return aResult.getWidth(); + } } - return nResult; + return mxWindow->getPosSize().Width; } //--------------------------------------------- -void UserFormGeometryHelper::setWidth( double nWidth) +void UserFormGeometryHelper::setWidth( double nWidth ) { - try - { - mxModel->setPropertyValue( - rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( VBA_WIDTH ) ), - uno::makeAny( ConvertPixelToLogic( nWidth, - sal_False, // Size - sal_True, // X - util::MeasureUnit::APPFONT ) ) ); - } - catch ( uno::RuntimeException& ) - { - throw; - } - catch ( uno::Exception& e ) + sal_Int64 nNewWidth = nWidth; + + if ( mbDialog ) { - throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can not set width!" ) ), - uno::Reference< uno::XInterface >(), - uno::makeAny( e ) ); + 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 = nDecor - nWidth; // avoid negative size + nNewWidth = nWidth + nUnDecor - nDecor; + } + } } + + mxWindow->setPosSize( 0, 0, nNewWidth, 0, awt::PosSize::WIDTH ); } //--------------------------------------------- double UserFormGeometryHelper::getHeight() { - double nResult = 0; - - try - { - sal_Int32 nHeight = 0; - mxModel->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( VBA_HEIGHT ) ) ) >>= nHeight; - nResult = ConvertLogicToPixel( nHeight, - sal_False, // Size - sal_False, // Y - util::MeasureUnit::APPFONT ); - } - catch ( uno::RuntimeException& ) + if ( mbDialog ) { - throw; - } - catch ( uno::Exception& e ) - { - throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can not get height!" ) ), - uno::Reference< uno::XInterface >(), - uno::makeAny( e ) ); + const Window* pWindow = VCLUnoHelper::GetWindow( mxWindow ); + if ( pWindow ) + { + // get the size with decoration + Rectangle aResult = pWindow->GetWindowExtentsRelative( NULL ); + return aResult.getHeight(); + } } - return nResult; + return mxWindow->getPosSize().Height; } //--------------------------------------------- void UserFormGeometryHelper::setHeight( double nHeight ) { - try - { - mxModel->setPropertyValue( - rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( VBA_HEIGHT ) ), - uno::makeAny( ConvertPixelToLogic( nHeight, - sal_False, // Size - sal_False, // Y - util::MeasureUnit::APPFONT ) ) ); - } - catch ( uno::RuntimeException& ) - { - throw; - } - catch ( uno::Exception& e ) + sal_Int64 nNewHeight = nHeight; + if ( mbDialog ) { - throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can not set height!" ) ), - uno::Reference< uno::XInterface >(), - uno::makeAny( e ) ); + 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 = nDecor - nHeight; // avoid negative size + nNewHeight = nHeight + nUnDecor - nDecor; + } + } } + + mxWindow->setPosSize( 0, 0, 0, nNewHeight, awt::PosSize::HEIGHT ); } // ============ |