20#include <com/sun/star/util/URLTransformer.hpp>
21#include <com/sun/star/util/XURLTransformer.hpp>
22#include <com/sun/star/frame/XDispatchProvider.hpp>
23#include <com/sun/star/frame/XModel.hpp>
24#include <com/sun/star/frame/XFrame.hpp>
25#include <com/sun/star/frame/XController.hpp>
26#include <com/sun/star/frame/XModel2.hpp>
27#include <com/sun/star/script/BasicErrorException.hpp>
28#include <com/sun/star/script/XDefaultProperty.hpp>
29#include <com/sun/star/script/XInvocation.hpp>
30#include <com/sun/star/script/Converter.hpp>
31#include <com/sun/star/uno/XComponentContext.hpp>
32#include <com/sun/star/lang/XUnoTunnel.hpp>
33#include <com/sun/star/beans/XPropertySet.hpp>
34#include <com/sun/star/beans/theIntrospection.hpp>
35#include <com/sun/star/util/MeasureUnit.hpp>
36#include <com/sun/star/awt/XControl.hpp>
37#include <com/sun/star/awt/XWindow.hpp>
38#include <com/sun/star/awt/XDialog.hpp>
39#include <com/sun/star/awt/XUnitConversion.hpp>
40#include <com/sun/star/drawing/XShape.hpp>
41#include <ooo/vba/XHelperInterface.hpp>
52#include <sfx2/sfxsids.hrc>
66#include <rtl/ustrbuf.hxx>
88 sal_uInt16 nViewNo = SID_VIEWSHELL1 - SID_VIEWSHELL0;
100uno::Reference< beans::XIntrospectionAccess >
107uno::Reference< script::XTypeConverter >
const &
110 static uno::Reference< script::XTypeConverter > xTypeConv( script::Converter::create(xContext) );
116 static uno::Any aNULLL{ uno::Reference< uno::XInterface >() };
130 pDispatcher->
Execute( nSlot , SfxCallMode::SYNCHRON );
136dispatchRequests (
const uno::Reference< frame::XModel>& xModel,
const OUString & aUrl,
const uno::Sequence< beans::PropertyValue >& sProps )
142 uno::Reference<frame::XDispatchProvider> xDispatchProvider (
xFrame,uno::UNO_QUERY_THROW);
145 uno::Reference<uno::XComponentContext > xContext(
147 uno::Reference<util::XURLTransformer> xParser( util::URLTransformer::create(xContext) );
148 xParser->parseStrict (url);
150 catch (
const uno::Exception&)
155 uno::Reference<frame::XDispatch> xDispatcher = xDispatchProvider->queryDispatch(url,
"",0);
157 sal_Int32 nProps = sProps.getLength();
158 uno::Sequence<beans::PropertyValue> dispatchProps(nProps + 1);
162 std::copy(sProps.begin(), sProps.end(), dispatchProps.getArray());
165 if ( xDispatcher.is() )
167 xDispatcher->dispatch( url, dispatchProps );
174 uno::Sequence<beans::PropertyValue> dispatchProps;
178uno::Reference< frame::XModel >
181 uno::Reference< frame::XModel >
xModel;
183 if (pBasic ==
nullptr)
185 SAL_INFO(
"vbahelper",
"getModelFromBasic() StarBASIC* is NULL" );
194 basicChosen = pParentParent;
198 basicChosen = pParent;
203 SbxVariable *pCompVar = basicChosen->
Find( sKey, SbxClassType::Object );
210 throw uno::RuntimeException(
211 "Can't extract model from basic ( it's obviously not set yet therefore don't know the current document context)" );
213 SAL_INFO(
"vbahelper",
"Have model points to url " <<
xModel->getURL());
217 SAL_INFO(
"vbahelper",
"Failed to get " << sKey);
218 throw uno::RuntimeException(
"Can't determine the currently selected document" );
224static uno::Reference< frame::XModel >
225getCurrentDocCtx(
const OUString& ctxName,
const uno::Reference< uno::XComponentContext >& xContext )
227 uno::Reference< frame::XModel >
xModel;
229 css::uno::Reference< css::container::XNameAccess > xNameAccess( xContext, css::uno::UNO_QUERY_THROW );
230 xModel.set( xNameAccess->getByName( ctxName ), uno::UNO_QUERY_THROW );
234uno::Reference< frame::XModel >
240uno::Reference< frame::XModel >
246 uno::Reference< frame::XModel >
249 uno::Reference< frame::XModel >
xModel;
254 catch (
const uno::Exception&)
260 catch (
const uno::Exception&)
267 uno::Reference< frame::XModel >
270 uno::Reference< frame::XModel >
xModel;
275 catch (
const uno::Exception&)
281 catch (
const uno::Exception&)
291 sal_Int32 nAutoBits = nCol;
292 nAutoBits &= 0xFF000000;
293 sal_Int32 nRed = nCol;
296 sal_Int32 nGreen = nCol;
297 nGreen &= 0x0000FF00;
299 sal_Int32 nBlue = nCol;
301 sal_Int32 nRGB = ( nAutoBits | (nBlue << 16) | (nGreen << 8) | nRed );
308 sal_Int32 nAutoBits = nCol;
309 nAutoBits &= 0xFF000000;
311 sal_Int32 nBlue = nCol;
314 sal_Int32 nGreen = nCol;
315 nGreen &= 0x0000FF00;
317 sal_Int32 nRed = nCol;
319 sal_Int32 nRGB = ( nAutoBits | (nRed << 16) | (nGreen << 8) | nBlue );
343 sal_Int16 nCopies = 1;
344 bool bPreview =
false;
345 bool bCollate =
false;
346 bool bSelection = bUseSelection;
352 Collate >>= bCollate;
354 OUString sRange(
"-" );
360 sRange = OUString::number( nFrom ) + sRange;
362 sRange += OUString::number( nTo );
365 PrToFileName >>= sFileName;
374 SfxBoolItem sfxCollate( SID_PRINT_COLLATE, bCollate );
375 aArgs.
Put( sfxCollate, sfxCollate.
Which() );
377 aArgs.
Put( sfxCopies, sfxCopies.
Which() );
378 if ( !sFileName.isEmpty() )
381 aArgs.
Put( sfxFileName, sfxFileName.
Which() );
384 if ( !sRange.isEmpty() )
387 aArgs.
Put( sfxRange, sfxRange.
Which() );
389 SfxBoolItem sfxSelection( SID_SELECTION, bSelection );
390 aArgs.
Put( sfxSelection, sfxSelection.
Which() );
392 aArgs.
Put( sfxAsync, sfxAsync.
Which() );
409 pDispatcher->
Execute( sal_uInt16(SID_PRINTDOC), SfxCallMode::SYNCHRON, aArgs );
446 switch( rAny.getValueType().getTypeClass() )
448 case uno::TypeClass_BOOLEAN:
449 return rAny.get<
bool >();
450 case uno::TypeClass_FLOAT:
451 return rAny.get<
float >() != 0.0;
452 case uno::TypeClass_DOUBLE:
453 return rAny.get<
double >() != 0.0;
454 case uno::TypeClass_BYTE:
455 case uno::TypeClass_SHORT:
456 case uno::TypeClass_LONG:
457 return rAny.get< sal_Int32 >() != 0;
458 case uno::TypeClass_HYPER:
459 return rAny.get< sal_Int64 >() != 0;
462 throw uno::RuntimeException(
"Invalid type, cannot convert to boolean." ,
nullptr );
467 switch( rAny.getValueType().getTypeClass() )
469 case uno::TypeClass_STRING:
470 return rAny.get< OUString >();
471 case uno::TypeClass_BOOLEAN:
472 return bUppercaseBool ?
473 (rAny.get<
bool >() ? OUString(
"TRUE" ) : OUString(
"FALSE" )) :
474 OUString::boolean( rAny.get<
bool >() );
475 case uno::TypeClass_FLOAT:
476 return OUString::number( rAny.get<
float >() );
477 case uno::TypeClass_DOUBLE:
478 return OUString::number( rAny.get<
double >() );
479 case uno::TypeClass_BYTE:
480 case uno::TypeClass_SHORT:
481 case uno::TypeClass_LONG:
482 return OUString::number( rAny.get< sal_Int32 >() );
483 case uno::TypeClass_HYPER:
484 return OUString::number( rAny.get< sal_Int64 >() );
487 throw uno::RuntimeException(
"Invalid type, cannot convert to string." ,
nullptr );
504 return getUniqueName(_slist, _sElementName, _sSuffixSeparator, sal_Int32(2));
508ContainerUtilities::getUniqueName(
const uno::Sequence< OUString >& _slist,
const OUString& _sElementName, std::u16string_view _sSuffixSeparator, sal_Int32 _nStartSuffix)
510 if ( !_slist.hasElements() )
511 return _sElementName;
513 OUString scompname = _sElementName;
514 sal_Int32
a = _nStartSuffix;
521 scompname = _sElementName + _sSuffixSeparator + OUString::number( a++ );
535 return OUString(
".^$+\\|{}()").indexOf(cCode) != -1;
540 OUStringBuffer sResult;
555 sResult.append(
".*");
559 sResult.append(
"[0-9]");
563 sResult.append(
'\\');
564 sResult.append(*(++
start));
569 sResult.append(
'\\');
570 sResult.append(*
start++);
573 sResult.append(*
start++);
582 sResult.append(
'\\');
583 sResult.append(*
start);
586 sResult.append(*
start);
594 sResult.append(
'\\');
595 sResult.append(*
start);
603 sResult.append(
'\\');
604 sResult.append(*
start++);
608 return sResult.makeStringAndClear( );
613 return bVertical ? xDevice->getInfo().PixelPerMeterY : xDevice->getInfo().PixelPerMeterX;
616double PointsToPixels(
const css::uno::Reference< css::awt::XDevice >& xDevice,
double fPoints,
bool bVertical)
621double PixelsToPoints(
const css::uno::Reference< css::awt::XDevice >& xDevice,
double fPixels,
bool bVertical)
628 : m_aShapeHelper( xShape )
641 const uno::Reference< frame::XController >
xController(
xModel->getCurrentController(), uno::UNO_SET_THROW );
642 const uno::Reference< frame::XFrame >
xFrame (
xController->getFrame(), uno::UNO_SET_THROW );
643 const uno::Reference< awt::XWindow > xWindow (
xFrame->getContainerWindow(), uno::UNO_SET_THROW );
649 catch (
const uno::Exception&)
653 return nPointerStyle;
661 ::std::vector< uno::Reference< frame::XController > > aControllers;
663 uno::Reference< frame::XModel2 > xModel2(
xModel, uno::UNO_QUERY );
666 const uno::Reference< container::XEnumeration > xEnumControllers( xModel2->getControllers(), uno::UNO_SET_THROW );
667 while ( xEnumControllers->hasMoreElements() )
669 const uno::Reference< frame::XController >
xController( xEnumControllers->nextElement(), uno::UNO_QUERY_THROW );
677 const uno::Reference< frame::XController >
xController(
xModel->getCurrentController(), uno::UNO_SET_THROW );
682 for (
const auto& rController : aControllers )
684 const uno::Reference< frame::XFrame >
xFrame ( rController->getFrame(), uno::UNO_SET_THROW );
685 const uno::Reference< awt::XWindow > xWindow (
xFrame->getContainerWindow(), uno::UNO_SET_THROW );
688 SAL_WARN_IF( !pWindow,
"vbahelper",
"ScVbaApplication::setCursor: no window!" );
692 pWindow->GetSystemWindow()->SetPointer( nPointer );
693 pWindow->GetSystemWindow()->EnableChildPointerOverwrite( bOverWrite );
702 uno::Reference< script::XDefaultProperty > xDflt( aObj, uno::UNO_QUERY_THROW );
703 uno::Reference< beans::XPropertySet > xPropSet;
705 if ( xUnoAccess.is() )
708 if ( !xPropSet.is() )
709 throw uno::RuntimeException();
711 xPropSet->setPropertyValue( xDflt->getDefaultPropertyName(), aValue );
716 auto pProp = std::find_if(aProp.begin(), aProp.end(),
717 [&
aName](
const beans::PropertyValue& rProp) { return rProp.Name == aName; });
718 if (pProp != aProp.end())
725 auto [
begin,
end] = asNonConstRange(aProp);
726 auto pProp = std::find_if(
begin,
end,
727 [&
aName](
const beans::PropertyValue& rProp) {
return rProp.Name ==
aName; });
730 pProp->Value = aValue;
742 sal_Int32
nLength = aProp.getLength();
744 auto pProp = aProp.getArray();
746 pProp[
nLength ].Value = aValue;
756 if (!pRunTimeLibrary)
759 SbxVariable* pFound = pRunTimeLibrary->
Find(OUString(rSbRtl_command), SbxClassType::Method);
766 pMethod->
Broadcast(SfxHintId::BasicDataWanted);
773 const uno::Reference< awt::XControl >& xControl,
774 double fOffsetX,
double fOffsetY ) :
775 mfOffsetX( fOffsetX ),
776 mfOffsetY( fOffsetY ),
777 mbDialog(
uno::
Reference< awt::XDialog >( xControl,
uno::UNO_QUERY ).is() )
779 if ( !xControl.is() )
780 throw uno::RuntimeException(
"No control is provided!" );
782 mxWindow.set( xControl->getPeer(), uno::UNO_QUERY_THROW );
783 mxModelProps.set( xControl->getModel(), uno::UNO_QUERY_THROW );
866 awt::Point aPosPixel =
mxUnitConv->convertPointToPixel( awt::Point( nPosAppFont, nPosAppFont ), util::MeasureUnit::APPFONT );
868 awt::Point aPosPoint =
mxUnitConv->convertPointToLogic( aPosPixel, util::MeasureUnit::POINT );
875 sal_Int32 nPosPixel =
static_cast< sal_Int32
>( fPos + (bPosY ?
mfOffsetY :
mfOffsetX) );
876 awt::Point aPosPixel =
mxUnitConv->convertPointToPixel( awt::Point( nPosPixel, nPosPixel ), util::MeasureUnit::POINT );
878 awt::Point aPosAppFont =
mxUnitConv->convertPointToLogic( aPosPixel, util::MeasureUnit::APPFONT );
886 awt::Size aSizePixel =
mxUnitConv->convertSizeToPixel( awt::Size( nSizeAppFont, nSizeAppFont ), util::MeasureUnit::APPFONT );
901 awt::Size aSizePoint =
mxUnitConv->convertSizeToLogic( aSizePixel, util::MeasureUnit::POINT );
902 return bHeight ? aSizePoint.Height : aSizePoint.Width;
908 sal_Int32 nSize =
static_cast< sal_Int32
>( fSize );
909 awt::Size aSizePixel =
mxUnitConv->convertSizeToPixel( awt::Size( nSize, nSize ), util::MeasureUnit::POINT );
922 awt::Rectangle aInnerRect =
mxWindow->getPosSize();
923 sal_Int32 nDecorWidth = aOuterRect.
getOpenWidth() - aInnerRect.Width;
924 sal_Int32 nDecorHeight = aOuterRect.
getOpenHeight() - aInnerRect.Height;
925 aSizePixel.Width = ::std::max< sal_Int32 >( aSizePixel.Width - nDecorWidth, 1 );
926 aSizePixel.Height = ::std::max< sal_Int32 >( aSizePixel.Height - nDecorHeight, 1 );
931 awt::Size aSizeAppFont =
mxUnitConv->convertSizeToLogic( aSizePixel, util::MeasureUnit::APPFONT );
972 : xShape(
std::move( _xShape ))
975 throw css::uno::RuntimeException(
"No valid shape for helper" );
985 css::awt::Size aSize =
xShape->getSize();
997 css::awt::Size aSize =
xShape->getSize();
1009 css::awt::Point aPoint =
xShape->getPosition();
1011 xShape->setPosition(aPoint);
1021 css::awt::Point aPoint =
xShape->getPosition();
1023 xShape->setPosition(aPoint);
1029 throw css::script::BasicErrorException(
ex.Message, css::uno::Reference< css::uno::XInterface >(), sal_uInt32(
err), OUString() );
1045 throw css::uno::RuntimeException( css::uno::Exception().Message +
" " + OUString::number(sal_uInt32(
err)),
1046 css::uno::Reference< css::uno::XInterface >() );
1071 double points = convertMm100ToPoint<double>(_hmm);
1075uno::Reference< XHelperInterface >
getVBADocument(
const uno::Reference< frame::XModel >& xModel )
1077 uno::Reference< XHelperInterface > xIf;
1080 uno::Reference< beans::XPropertySet > xDocProps(
xModel, uno::UNO_QUERY_THROW );
1082 xDocProps->getPropertyValue(
"CodeName" ) >>= aCodeName;
1085 catch (
const uno::Exception&)
1093 uno::Reference< XHelperInterface > xIf;
1096 OUString sProj(
"Standard" );
1104 if ( pBasMgr && !pBasMgr->
GetName().isEmpty() )
1107 if(
SbModule* pMod = pBasic->FindModule( aModName ) )
1108 xIf.set( pMod->GetUnoModule(), uno::UNO_QUERY );
1117 throw uno::RuntimeException();
constexpr auto convertPointToMm100(N n)
SfxApplication * SfxGetpApp()
StarBASIC * GetLib(sal_uInt16 nLib) const
const OUString & GetName() const
virtual SbxVariable * Find(const OUString &, SbxClassType)
const SbxObject * GetParent() const
virtual void Broadcast(SfxHintId nHintId) override
void SetParameters(SbxArray *p)
static StarBASIC * GetBasic()
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SfxViewFactory & GetViewFactory(sal_uInt16 i=0) const
sal_uInt16 GetViewFactoryCount() const
BasicManager * GetBasicManager() const
virtual SfxObjectFactory & GetFactory() const=0
bool IsInPlaceActive() const
SfxInterfaceId GetOrdinal() const
SfxInterfaceId GetCurViewId() const
SfxDispatcher * GetDispatcher()
SfxFrame & GetFrame() const
virtual SfxObjectShell * GetObjectShell() override
SfxViewFrame & GetViewFrame() const
static SbModule * GetActiveModule()
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
virtual double getLeft() const override
virtual double getWidth() const override
virtual void setTop(double nTop) override
virtual ~ConcreteXShapeGeometryAttributes() override
virtual double getTop() const override
ConcreteXShapeGeometryAttributes(const css::uno::Reference< css::drawing::XShape > &xShape)
virtual void setWidth(double nWidth) override
virtual double getHeight() const override
ShapeHelper m_aShapeHelper
virtual void setHeight(double nHeight) override
virtual void setLeft(double nLeft) override
static OUString getUniqueName(const css::uno::Sequence< OUString > &_slist, const OUString &_sElementName, std::u16string_view _sSuffixSeparator)
static sal_Int32 FieldInList(const css::uno::Sequence< OUString > &SearchList, const OUString &SearchString)
static void basicexception(const css::uno::Exception &ex, ErrCode err, std::u16string_view)
static void runtimeexception(ErrCode err)
double getInHundredthsOfOneMillimeter() const
void setInPoints(double points)
static double getInPoints(int _hmm)
css::uno::Reference< css::drawing::XShape > xShape
void setWidth(double _fWidth)
void setTop(double _fTop)
ShapeHelper(css::uno::Reference< css::drawing::XShape > _xShape)
void setHeight(double _fheight)
void setLeft(double _fLeft)
SystemWindow * GetSystemWindow() const
PointerStyle GetPointer() const
#define DBG_UNHANDLED_EXCEPTION(...)
Reference< XIntrospection > xIntrospection
#define SAL_WARN_IF(condition, area, stream)
#define SAL_INFO(area, stream)
sal_Int32 findValue(const css::uno::Sequence< T1 > &_rList, const T2 &_rValue)
Reference< XComponentContext > getProcessComponentContext()
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
enumrange< T >::Iterator begin(enumrange< T >)
double PixelsToPoints(const css::uno::Reference< css::awt::XDevice > &xDevice, double fPixels, bool bVertical)
bool extractBoolFromAny(const uno::Any &rAny)
static uno::Reference< frame::XModel > getCurrentDocCtx(const OUString &ctxName, const uno::Reference< uno::XComponentContext > &xContext)
sal_Int32 XLRGBToOORGB(sal_Int32 nCol)
void PrintOutHelper(SfxViewShell const *pViewShell, const uno::Any &From, const uno::Any &To, const uno::Any &Copies, const uno::Any &Preview, const uno::Any &, const uno::Any &, const uno::Any &Collate, const uno::Any &PrToFileName, bool bUseSelection)
uno::Reference< script::XTypeConverter > const & getTypeConverter(const uno::Reference< uno::XComponentContext > &xContext)
void PrintPreviewHelper(const css::uno::Any &, SfxViewShell const *pViewShell)
uno::Any getPropertyValue(const uno::Sequence< beans::PropertyValue > &aProp, const OUString &aName)
constexpr OUStringLiteral saPosYName
void WaitUntilPreviewIsClosed(SfxViewFrame *pViewFrame)
constexpr OUStringLiteral saWidthName
void setCursorHelper(const uno::Reference< frame::XModel > &xModel, PointerStyle nPointer, bool bOverWrite)
uno::Reference< frame::XModel > getCurrentDoc(const OUString &sKey)
uno::Reference< frame::XModel > getCurrentExcelDoc(const uno::Reference< uno::XComponentContext > &xContext)
OUString VBAToRegexp(const OUString &rIn)
constexpr OUStringLiteral saHeightName
uno::Reference< XHelperInterface > getUnoDocModule(std::u16string_view aModName, SfxObjectShell const *pShell)
uno::Reference< frame::XModel > getThisWordDoc(const uno::Reference< uno::XComponentContext > &xContext)
static bool NeedEsc(sal_Unicode cCode)
uno::Reference< beans::XIntrospectionAccess > getIntrospectionAccess(const uno::Any &aObject)
static bool isInPrintPreview(SfxViewFrame *pView)
void setOrAppendPropertyValue(uno::Sequence< beans::PropertyValue > &aProp, const OUString &aName, const uno::Any &aValue)
OUString extractStringFromAny(const uno::Any &rAny, bool bUppercaseBool)
void dispatchExecute(SfxViewShell const *pViewShell, sal_uInt16 nSlot)
SfxObjectShell * getSfxObjShell(const uno::Reference< frame::XModel > &xModel)
double PointsToPixels(const css::uno::Reference< css::awt::XDevice > &xDevice, double fPoints, bool bVertical)
uno::Reference< XHelperInterface > getVBADocument(const uno::Reference< frame::XModel > &xModel)
PointerStyle getPointerStyle(const uno::Reference< frame::XModel > &xModel)
bool setPropertyValue(uno::Sequence< beans::PropertyValue > &aProp, const OUString &aName, const uno::Any &aValue)
OUString getAnyAsString(const uno::Any &pvargItem)
void setDefaultPropByIntrospection(const uno::Any &aObj, const uno::Any &aValue)
uno::Reference< frame::XModel > getCurrentWordDoc(const uno::Reference< uno::XComponentContext > &xContext)
constexpr OUStringLiteral saPosXName
void dispatchRequests(const uno::Reference< frame::XModel > &xModel, const OUString &aUrl, const uno::Sequence< beans::PropertyValue > &sProps)
sal_Int32 OORGBToXLRGB(sal_Int32 nCol)
bool executeRunTimeLibrary(const std::u16string_view &rSbRtl_command, SbxArray *pParameters)
uno::Reference< frame::XModel > getThisExcelDoc(const uno::Reference< uno::XComponentContext > &xContext)
static double getPixelToMeterConversionFactor(const css::uno::Reference< css::awt::XDevice > &xDevice, bool bVertical)
#define ERRCODE_BASIC_INTERNAL_ERROR
Any sbxToUnoValue(const SbxValue *pVar)
Reference< XController > xController
Reference< XFrame > xFrame
Reference< XModel > xModel