mib19: #i163287# handle the dialog size in the way VBA does it
This commit is contained in:
parent
af733eacab
commit
6e9b786ff6
2 changed files with 115 additions and 214 deletions
|
@ -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 );
|
||||
|
|
|
@ -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();
|
||||
throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No control is provided!" ) ),
|
||||
uno::Reference< uno::XInterface >() );
|
||||
|
||||
mxControlUnits.set( xControl->getPeer(), uno::UNO_QUERY_THROW );
|
||||
mxModel.set( xControl->getModel(), uno::UNO_QUERY_THROW );
|
||||
mxWindow.set( xControl->getPeer(), 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 );
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
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
|
||||
if ( mbDialog )
|
||||
{
|
||||
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& )
|
||||
{
|
||||
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
|
||||
sal_Int64 nNewLeft = nLeft;
|
||||
if ( mbDialog )
|
||||
{
|
||||
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& )
|
||||
{
|
||||
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
|
||||
sal_Int64 nNewTop = nTop;
|
||||
if ( mbDialog )
|
||||
{
|
||||
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& )
|
||||
{
|
||||
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
|
||||
sal_Int64 nNewWidth = nWidth;
|
||||
|
||||
if ( mbDialog )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
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
|
||||
if ( mbDialog )
|
||||
{
|
||||
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& )
|
||||
{
|
||||
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
|
||||
sal_Int64 nNewHeight = nHeight;
|
||||
if ( mbDialog )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
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 );
|
||||
}
|
||||
|
||||
// ============
|
||||
|
|
Loading…
Reference in a new issue