2010-10-27 13:11:31 +01:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2012-06-22 16:25:46 +01:00
/*
* This file is part of the LibreOffice project .
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License , v . 2.0 . If a copy of the MPL was not distributed with this
* file , You can obtain one at http : //mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice :
*
* Licensed to the Apache Software Foundation ( ASF ) under one or more
* contributor license agreements . See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership . The ASF licenses this file to you under the Apache
* License , Version 2.0 ( the " License " ) ; you may not use this file
* except in compliance with the License . You may obtain a copy of
* the License at http : //www.apache.org/licenses/LICENSE-2.0 .
*/
2013-10-23 19:18:54 +02:00
# ifndef INCLUDED_VBAHELPER_VBAHELPER_HXX
# define INCLUDED_VBAHELPER_VBAHELPER_HXX
2009-09-18 15:35:47 +00:00
# include <com/sun/star/drawing/XShape.hpp>
# include <com/sun/star/beans/XIntrospectionAccess.hpp>
# include <com/sun/star/beans/XPropertySet.hpp>
# include <com/sun/star/script/BasicErrorException.hpp>
# include <com/sun/star/script/XTypeConverter.hpp>
# include <com/sun/star/lang/IllegalArgumentException.hpp>
# include <com/sun/star/awt/XControl.hpp>
# include <com/sun/star/awt/XDevice.hpp>
2010-06-15 20:02:53 +02:00
# include <com/sun/star/awt/XUnitConversion.hpp>
2010-02-26 18:29:25 +00:00
# include <basic/basmgr.hxx>
2009-09-18 15:35:47 +00:00
# include <basic/sberrors.hxx>
# include <com/sun/star/frame/XModel.hpp>
# include <sfx2/dispatch.hxx>
2010-02-26 18:29:25 +00:00
# include <sfx2/objsh.hxx>
# include <sfx2/docfilt.hxx>
# include <sfx2/docfile.hxx>
2009-09-18 15:35:47 +00:00
# include <vcl/pointr.hxx>
# include <memory>
2013-11-09 15:33:26 -06:00
# include <vbahelper/vbaaccesshelper.hxx>
2009-09-18 15:35:47 +00:00
namespace ooo
{
namespace vba
{
template < class T >
css : : uno : : Reference < T > getXSomethingFromArgs ( css : : uno : : Sequence < css : : uno : : Any > const & args , sal_Int32 nPos , bool bCanBeNull = true ) throw ( css : : lang : : IllegalArgumentException )
{
if ( args . getLength ( ) < ( nPos + 1 ) )
throw css : : lang : : IllegalArgumentException ( ) ;
css : : uno : : Reference < T > aSomething ( args [ nPos ] , css : : uno : : UNO_QUERY ) ;
if ( ! bCanBeNull & & ! aSomething . is ( ) )
throw css : : lang : : IllegalArgumentException ( ) ;
return aSomething ;
}
2011-03-25 10:40:25 +01:00
class XHelperInterface ;
/** Returns the VBA document implementation object representing the passed UNO document model. */
VBAHELPER_DLLPUBLIC css : : uno : : Reference < XHelperInterface > getVBADocument ( const css : : uno : : Reference < css : : frame : : XModel > & xModel ) ;
2013-09-27 13:15:25 +02:00
VBAHELPER_DLLPUBLIC css : : uno : : Reference < XHelperInterface > getUnoDocModule ( const OUString & aModName , SfxObjectShell * pShell ) ;
2009-09-18 15:35:47 +00:00
VBAHELPER_DLLPUBLIC SfxObjectShell * getSfxObjShell ( const css : : uno : : Reference < css : : frame : : XModel > & xModel ) throw ( css : : uno : : RuntimeException ) ;
2010-02-26 18:29:25 +00:00
2013-04-07 12:06:47 +02:00
css : : uno : : Reference < css : : frame : : XModel > getCurrentDoc ( const OUString & sKey ) throw ( css : : uno : : RuntimeException ) ;
2010-04-07 17:02:52 +01:00
VBAHELPER_DLLPUBLIC css : : uno : : Reference < css : : frame : : XModel > getThisExcelDoc ( const css : : uno : : Reference < css : : uno : : XComponentContext > & xContext ) throw ( css : : uno : : RuntimeException ) ;
VBAHELPER_DLLPUBLIC css : : uno : : Reference < css : : frame : : XModel > getThisWordDoc ( const css : : uno : : Reference < css : : uno : : XComponentContext > & xContext ) throw ( css : : uno : : RuntimeException ) ;
2009-09-18 15:35:47 +00:00
VBAHELPER_DLLPUBLIC css : : uno : : Reference < css : : frame : : XModel > getCurrentExcelDoc ( const css : : uno : : Reference < css : : uno : : XComponentContext > & xContext ) throw ( css : : uno : : RuntimeException ) ;
VBAHELPER_DLLPUBLIC css : : uno : : Reference < css : : frame : : XModel > getCurrentWordDoc ( const css : : uno : : Reference < css : : uno : : XComponentContext > & xContext ) throw ( css : : uno : : RuntimeException ) ;
VBAHELPER_DLLPUBLIC css : : uno : : Reference < css : : beans : : XIntrospectionAccess > getIntrospectionAccess ( const css : : uno : : Any & aObject ) throw ( css : : uno : : RuntimeException ) ;
VBAHELPER_DLLPUBLIC css : : uno : : Reference < css : : script : : XTypeConverter > getTypeConverter ( const css : : uno : : Reference < css : : uno : : XComponentContext > & xContext ) throw ( css : : uno : : RuntimeException ) ;
2013-04-07 12:06:47 +02:00
VBAHELPER_DLLPUBLIC void dispatchRequests ( const css : : uno : : Reference < css : : frame : : XModel > & xModel , const OUString & aUrl ) ;
VBAHELPER_DLLPUBLIC void dispatchRequests ( const css : : uno : : Reference < css : : frame : : XModel > & xModel , const OUString & aUrl , const css : : uno : : Sequence < css : : beans : : PropertyValue > & sProps ) ;
2014-10-11 16:01:26 +02:00
VBAHELPER_DLLPUBLIC void dispatchExecute ( SfxViewShell * pView , sal_uInt16 nSlot , SfxCallMode nCall = SfxCallMode : : SYNCHRON ) ;
2009-09-18 15:35:47 +00:00
VBAHELPER_DLLPUBLIC sal_Int32 OORGBToXLRGB ( sal_Int32 ) ;
VBAHELPER_DLLPUBLIC sal_Int32 XLRGBToOORGB ( sal_Int32 ) ;
VBAHELPER_DLLPUBLIC css : : uno : : Any OORGBToXLRGB ( const css : : uno : : Any & ) ;
VBAHELPER_DLLPUBLIC css : : uno : : Any XLRGBToOORGB ( const css : : uno : : Any & ) ;
// provide a NULL object that can be passed as variant so that
// the object when passed to IsNull will return true. aNULL
// contains an empty object reference
VBAHELPER_DLLPUBLIC const css : : uno : : Any & aNULL ( ) ;
2014-04-01 14:35:59 +02:00
VBAHELPER_DLLPUBLIC void PrintOutHelper ( SfxViewShell * pViewShell , const css : : uno : : Any & From , const css : : uno : : Any & To , const css : : uno : : Any & Copies , const css : : uno : : Any & Preview , const css : : uno : : Any & ActivePrinter , const css : : uno : : Any & PrintToFile , const css : : uno : : Any & Collate , const css : : uno : : Any & PrToFileName , bool bSelection ) ;
2009-09-18 15:35:47 +00:00
VBAHELPER_DLLPUBLIC void PrintPreviewHelper ( const css : : uno : : Any & EnableChanges , SfxViewShell * ) ;
2012-04-24 11:23:46 +01:00
VBAHELPER_DLLPUBLIC void WaitUntilPreviewIsClosed ( SfxViewFrame * ) ;
2009-09-18 15:35:47 +00:00
2011-03-25 10:40:25 +01:00
/** Extracts a boolean value from the passed Any, which may contain a Boolean or an integer or floating-point value.
2010-08-04 09:56:54 +02:00
Throws , if the Any is empty or contains an incompatible type . */
VBAHELPER_DLLPUBLIC bool extractBoolFromAny ( const css : : uno : : Any & rAny ) throw ( css : : uno : : RuntimeException ) ;
2011-03-25 10:40:25 +01:00
/** Extracts a string from the passed Any, which may contain a Boolean, a value, or a string.
Throws , if the Any is empty or contains an incompatible type . */
2013-04-07 12:06:47 +02:00
VBAHELPER_DLLPUBLIC OUString extractStringFromAny ( const css : : uno : : Any & rAny , bool bUppercaseBool = false ) throw ( css : : uno : : RuntimeException ) ;
2011-03-25 10:40:25 +01:00
/** Extracts a string from the passed Any, which may contain a Boolean, a value, or a string.
Returns rDefault , if rAny is empty . Throws , if the Any contains an incompatible type . */
2013-04-07 12:06:47 +02:00
VBAHELPER_DLLPUBLIC OUString extractStringFromAny ( const css : : uno : : Any & rAny , const OUString & rDefault , bool bUppercaseBool = false ) throw ( css : : uno : : RuntimeException ) ;
2010-08-04 09:56:54 +02:00
2013-04-07 12:06:47 +02:00
VBAHELPER_DLLPUBLIC OUString getAnyAsString ( const css : : uno : : Any & pvargItem ) throw ( css : : uno : : RuntimeException ) ;
VBAHELPER_DLLPUBLIC OUString VBAToRegexp ( const OUString & rIn , bool bForLike = false ) ; // needs to be in an uno service ( already this code is duplicated in basic )
2014-04-01 14:35:59 +02:00
VBAHELPER_DLLPUBLIC double getPixelTo100thMillimeterConversionFactor ( const css : : uno : : Reference < css : : awt : : XDevice > & xDevice , bool bVertical ) ;
VBAHELPER_DLLPUBLIC double PointsToPixels ( const css : : uno : : Reference < css : : awt : : XDevice > & xDevice , double fPoints , bool bVertical ) ;
VBAHELPER_DLLPUBLIC double PixelsToPoints ( const css : : uno : : Reference < css : : awt : : XDevice > & xDevice , double fPixels , bool bVertical ) ;
2010-06-15 20:02:53 +02:00
VBAHELPER_DLLPUBLIC sal_Int32 PointsToHmm ( double fPoints ) ;
VBAHELPER_DLLPUBLIC double HmmToPoints ( sal_Int32 nHmm ) ;
2015-05-20 14:05:50 +02:00
VBAHELPER_DLLPUBLIC PointerStyle getPointerStyle ( const css : : uno : : Reference < css : : frame : : XModel > & ) ;
2014-04-01 14:35:59 +02:00
VBAHELPER_DLLPUBLIC void setCursorHelper ( const css : : uno : : Reference < css : : frame : : XModel > & xModel , const Pointer & rPointer , bool bOverWrite ) ;
2009-09-18 15:35:47 +00:00
VBAHELPER_DLLPUBLIC void setDefaultPropByIntrospection ( const css : : uno : : Any & aObj , const css : : uno : : Any & aValue ) throw ( css : : uno : : RuntimeException ) ;
2013-04-07 12:06:47 +02:00
VBAHELPER_DLLPUBLIC css : : uno : : Any getPropertyValue ( const css : : uno : : Sequence < css : : beans : : PropertyValue > & aProp , const OUString & aName ) ;
2014-04-01 14:35:59 +02:00
VBAHELPER_DLLPUBLIC bool setPropertyValue ( css : : uno : : Sequence < css : : beans : : PropertyValue > & aProp , const OUString & aName , const css : : uno : : Any & aValue ) ;
2013-04-07 12:06:47 +02:00
VBAHELPER_DLLPUBLIC void setOrAppendPropertyValue ( css : : uno : : Sequence < css : : beans : : PropertyValue > & aProp , const OUString & aName , const css : : uno : : Any & aValue ) ;
2009-09-18 15:35:47 +00:00
class VBAHELPER_DLLPUBLIC Millimeter
{
//Factor to translate between points and hundredths of millimeters:
private :
double m_nMillimeter ;
public :
Millimeter ( ) ;
Millimeter ( double mm ) ;
void setInPoints ( double points ) ;
double getInHundredthsOfOneMillimeter ( ) ;
static sal_Int32 getInHundredthsOfOneMillimeter ( double points ) ;
static double getInPoints ( int _hmm ) ;
} ;
class VBAHELPER_DLLPUBLIC AbstractGeometryAttributes // probably should replace the ShapeHelper below
{
public :
virtual ~ AbstractGeometryAttributes ( ) { }
2011-03-25 10:40:25 +01:00
virtual double getLeft ( ) const = 0 ;
2009-09-18 15:35:47 +00:00
virtual void setLeft ( double ) = 0 ;
2011-03-25 10:40:25 +01:00
virtual double getTop ( ) const = 0 ;
2009-09-18 15:35:47 +00:00
virtual void setTop ( double ) = 0 ;
2011-03-25 10:40:25 +01:00
virtual double getHeight ( ) const = 0 ;
2009-09-18 15:35:47 +00:00
virtual void setHeight ( double ) = 0 ;
2011-03-25 10:40:25 +01:00
virtual double getWidth ( ) const = 0 ;
2009-09-18 15:35:47 +00:00
virtual void setWidth ( double ) = 0 ;
2011-03-25 10:40:25 +01:00
virtual double getInnerHeight ( ) const { return 0.0 ; }
virtual void setInnerHeight ( double ) { }
virtual double getInnerWidth ( ) const { return 0.0 ; }
virtual void setInnerWidth ( double ) { }
virtual double getOffsetX ( ) const { return 0.0 ; }
virtual double getOffsetY ( ) const { return 0.0 ; }
2009-09-18 15:35:47 +00:00
} ;
namespace msforms {
class XShape ;
}
class VBAHELPER_DLLPUBLIC ShapeHelper
{
protected :
css : : uno : : Reference < css : : drawing : : XShape > xShape ;
public :
2014-04-24 11:48:33 +01:00
ShapeHelper ( const css : : uno : : Reference < css : : drawing : : XShape > & _xShape )
throw ( css : : script : : BasicErrorException , css : : uno : : RuntimeException ) ;
2009-09-18 15:35:47 +00:00
2011-03-25 10:40:25 +01:00
double getHeight ( ) const ;
2014-07-18 15:15:01 +01:00
void setHeight ( double _fheight ) ;
2011-03-25 10:40:25 +01:00
double getWidth ( ) const ;
2014-07-18 15:15:01 +01:00
void setWidth ( double _fWidth ) ;
2011-03-25 10:40:25 +01:00
double getLeft ( ) const ;
2009-09-18 15:35:47 +00:00
void setLeft ( double _fLeft ) ;
2011-03-25 10:40:25 +01:00
double getTop ( ) const ;
2009-09-18 15:35:47 +00:00
void setTop ( double _fTop ) ;
} ;
class VBAHELPER_DLLPUBLIC ConcreteXShapeGeometryAttributes : public AbstractGeometryAttributes
{
2014-09-29 17:39:16 +02:00
std : : unique_ptr < ShapeHelper > m_pShapeHelper ;
2009-09-18 15:35:47 +00:00
public :
ConcreteXShapeGeometryAttributes ( const css : : uno : : Reference < css : : uno : : XComponentContext > & xContext , const css : : uno : : Reference < css : : drawing : : XShape > & xShape ) ;
2014-03-27 18:12:18 +01:00
virtual double getLeft ( ) const SAL_OVERRIDE ;
virtual void setLeft ( double nLeft ) SAL_OVERRIDE ;
virtual double getTop ( ) const SAL_OVERRIDE ;
virtual void setTop ( double nTop ) SAL_OVERRIDE ;
virtual double getHeight ( ) const SAL_OVERRIDE ;
virtual void setHeight ( double nHeight ) SAL_OVERRIDE ;
virtual double getWidth ( ) const SAL_OVERRIDE ;
virtual void setWidth ( double nWidth ) SAL_OVERRIDE ;
2011-01-25 16:17:23 +01:00
virtual ~ ConcreteXShapeGeometryAttributes ( ) ;
2009-09-18 15:35:47 +00:00
} ;
2010-06-15 20:02:53 +02:00
2009-09-18 15:35:47 +00:00
# define VBA_LEFT "PositionX"
# define VBA_TOP "PositionY"
class VBAHELPER_DLLPUBLIC UserFormGeometryHelper : public AbstractGeometryAttributes
{
2011-03-25 10:40:25 +01:00
public :
UserFormGeometryHelper (
const css : : uno : : Reference < css : : uno : : XComponentContext > & xContext ,
const css : : uno : : Reference < css : : awt : : XControl > & xControl ,
double fOffsetX , double fOffsetY ) ;
2014-03-27 18:12:18 +01:00
virtual double getLeft ( ) const SAL_OVERRIDE ;
virtual void setLeft ( double fLeft ) SAL_OVERRIDE ;
virtual double getTop ( ) const SAL_OVERRIDE ;
virtual void setTop ( double fTop ) SAL_OVERRIDE ;
virtual double getWidth ( ) const SAL_OVERRIDE ;
virtual void setWidth ( double fWidth ) SAL_OVERRIDE ;
virtual double getHeight ( ) const SAL_OVERRIDE ;
virtual void setHeight ( double fHeight ) SAL_OVERRIDE ;
virtual double getInnerWidth ( ) const SAL_OVERRIDE ;
virtual void setInnerWidth ( double fWidth ) SAL_OVERRIDE ;
virtual double getInnerHeight ( ) const SAL_OVERRIDE ;
virtual void setInnerHeight ( double fHeight ) SAL_OVERRIDE ;
virtual double getOffsetX ( ) const SAL_OVERRIDE ;
virtual double getOffsetY ( ) const SAL_OVERRIDE ;
2011-03-25 10:40:25 +01:00
private :
double implGetPos ( bool bPosY ) const ;
void implSetPos ( double fPos , bool bPosY ) ;
double implGetSize ( bool bHeight , bool bOuter ) const ;
void implSetSize ( double fSize , bool bHeight , bool bOuter ) ;
private :
2010-08-26 19:24:07 +02:00
css : : uno : : Reference < css : : awt : : XWindow > mxWindow ;
2011-03-25 10:40:25 +01:00
css : : uno : : Reference < css : : beans : : XPropertySet > mxModelProps ;
css : : uno : : Reference < css : : awt : : XUnitConversion > mxUnitConv ;
double mfOffsetX ;
double mfOffsetY ;
2014-04-01 14:35:59 +02:00
bool mbDialog ;
2009-09-18 15:35:47 +00:00
} ;
class VBAHELPER_DLLPUBLIC ContainerUtilities
{
public :
2013-04-07 12:06:47 +02:00
static OUString getUniqueName ( const css : : uno : : Sequence < OUString > & _slist , const OUString & _sElementName , const OUString & _sSuffixSeparator ) ;
2014-03-13 15:04:48 +02:00
static OUString getUniqueName ( const css : : uno : : Sequence < OUString > & _slist , const OUString & _sElementName , const OUString & _sSuffixSeparator , sal_Int32 _nStartSuffix ) ;
2009-09-18 15:35:47 +00:00
2013-04-07 12:06:47 +02:00
static sal_Int32 FieldInList ( const css : : uno : : Sequence < OUString > & SearchList , const OUString & SearchString ) ;
2009-09-18 15:35:47 +00:00
} ;
2014-11-10 15:05:25 +01:00
// really just a place holder to ease the porting pain
2009-09-18 15:35:47 +00:00
class VBAHELPER_DLLPUBLIC DebugHelper
{
public :
2014-07-09 09:05:50 +01:00
static void basicexception ( const OUString & DetailedMessage , const css : : uno : : Exception & ex , int err , const OUString & /*additionalArgument*/ ) throw ( css : : script : : BasicErrorException ) ;
2009-09-18 15:35:47 +00:00
2014-07-09 09:05:50 +01:00
static void basicexception ( int err , const OUString & additionalArgument ) throw ( css : : script : : BasicErrorException ) ;
static void basicexception ( const css : : uno : : Exception & ex ) throw ( css : : script : : BasicErrorException ) ;
static void runtimeexception ( const OUString & DetailedMessage , const css : : uno : : Exception & ex , int err , const OUString & /*additionalArgument*/ ) throw ( css : : uno : : RuntimeException ) ;
static void runtimeexception ( int err , const OUString & additionalArgument ) throw ( css : : uno : : RuntimeException ) ;
2009-09-18 15:35:47 +00:00
} ;
2010-10-06 10:16:27 +01:00
2011-03-25 10:40:25 +01:00
} // vba
} // ooo
2009-09-18 15:35:47 +00:00
namespace ov = ooo : : vba ;
# endif
2010-10-27 13:11:31 +01:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */