20#include <config_features.h>
24#include <com/sun/star/frame/DispatchResultState.hpp>
48 Reference < XFrame >
xFrame;
58 return "com.sun.star.comp.sfx2.SfxMacroLoader";
68 return {
"com.sun.star.frame.ProtocolHandler" };
98 const util::URL& aURL ,
102 uno::Reference<frame::XDispatch> xDispatcher;
103 if(
aURL.Complete.startsWith(
"macro:"))
109uno::Sequence< uno::Reference<frame::XDispatch> > SAL_CALL
112 sal_Int32
nCount = seqDescriptor.getLength();
113 uno::Sequence< uno::Reference<frame::XDispatch> > lDispatcher(
nCount);
114 std::transform(seqDescriptor.begin(), seqDescriptor.end(), lDispatcher.getArray(),
115 [
this](
const frame::DispatchDescriptor& rDescr) -> uno::Reference<frame::XDispatch> {
116 return queryDispatch(rDescr.FeatureURL, rDescr.FrameName, rDescr.SearchFlags); });
122 const util::URL& aURL,
const uno::Sequence<beans::PropertyValue>& ,
123 const uno::Reference<frame::XDispatchResultListener>& xListener )
129 if( !xListener.is() )
134 frame::DispatchResultEvent
aEvent;
136 aEvent.Source = getXWeak();
138 aEvent.State = frame::DispatchResultState::SUCCESS;
140 aEvent.State = frame::DispatchResultState::FAILURE;
142 xListener->dispatchFinished(
aEvent ) ;
146 const util::URL& aURL,
const uno::Sequence<beans::PropertyValue>& )
158 beans::PropertyValue aErrorCode;
160 aErrorCode.Name =
"ErrorCode";
161 aErrorCode.Value <<= sal_uInt32(nErr);
170 const util::URL& aURL,
const uno::Sequence<beans::PropertyValue>& )
179 const uno::Reference< frame::XStatusListener >& ,
190 const uno::Reference< frame::XStatusListener >&,
197#if !HAVE_FEATURE_SCRIPTING
211 const OUString& aMacro( rURL );
212 sal_Int32 nThirdSlashPos = aMacro.indexOf(
'/', 8 );
213 sal_Int32 nArgsPos = aMacro.indexOf(
'(' );
219 if ( -1 != nThirdSlashPos && ( -1 == nArgsPos || nThirdSlashPos < nArgsPos ) )
224 if ( aBasMgrName.isEmpty() )
226 else if ( aBasMgrName ==
"." )
248 const bool bIsAppBasic = ( pBasMgr == pAppMgr );
249 const bool bIsDocBasic = ( pBasMgr != pAppMgr );
262 if ( -1 != nArgsPos )
265 aArgs = aQualifiedMethod.copy( nArgsPos - nThirdSlashPos - 1 );
266 aQualifiedMethod = aQualifiedMethod.copy( 0, nArgsPos - nThirdSlashPos - 1 );
269 if ( pBasMgr->
HasMacro( aQualifiedMethod ) )
271 Any aOldThisComponent;
272 const bool bSetDocMacroMode = ( pDoc != nullptr ) && bIsDocBasic;
273 const bool bSetGlobalThisComponent = ( pDoc != nullptr ) && bIsAppBasic;
274 if ( bSetDocMacroMode )
280 if ( bSetGlobalThisComponent )
291 std::optional< ::framework::DocumentUndoGuard > pUndoGuard;
293 pUndoGuard.emplace( pDoc->
GetModel() );
297 nErr = pBasMgr->
ExecuteMacro( aQualifiedMethod, aArgs, retValRef.
get() );
302 if ( bSetGlobalThisComponent )
307 if ( bSetDocMacroMode )
336extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
338 css::uno::XComponentContext *,
339 css::uno::Sequence<css::uno::Any>
const &arguments)
StarBASIC * GetLib(sal_uInt16 nLib) const
bool HasMacro(OUString const &i_fullyQualifiedName) const
ErrCode ExecuteMacro(OUString const &i_fullyQualifiedName, SbxArray *i_arguments, SbxValue *i_retValue)
void SetGlobalUNOConstant(const OUString &rName, const css::uno::Any &_rValue, css::uno::Any *pOldValue=nullptr)
static OUString decode(std::u16string_view rText, DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
static ErrCode const & GetError()
SbxVariable * Execute(const OUString &)
static BasicManager * GetBasicManager()
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
SAL_WARN_UNUSED_RESULT SfxObjectShell * GetCurrentDocument() const
static SAL_WARN_UNUSED_RESULT SfxFrame * GetNext(SfxFrame &)
static SAL_WARN_UNUSED_RESULT SfxFrame * GetFirst()
css::uno::WeakReference< css::frame::XFrame > m_xFrame
virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xControl, const css::util::URL &aURL) override
static SfxObjectShell * GetObjectShell(const css::uno::Reference< css::frame::XFrame > &xFrame)
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Bool SAL_CALL supportsService(OUString const &ServiceName) override
virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches(const css::uno::Sequence< css::frame::DispatchDescriptor > &seqDescriptor) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
SfxObjectShell * GetObjectShell_Impl()
virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(const css::util::URL &aURL, const OUString &sTargetFrameName, sal_Int32 eSearchFlags) override
virtual void SAL_CALL dispatch(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &lArgs) override
virtual void SAL_CALL dispatchWithNotification(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &lArgs, const css::uno::Reference< css::frame::XDispatchResultListener > &Listener) override
SfxMacroLoader(const css::uno::Sequence< css::uno::Any > &aArguments)
virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xControl, const css::util::URL &aURL) override
static ErrCode loadMacro(const OUString &aURL, css::uno::Any &rRetval, SfxObjectShell *pDoc)
virtual css::uno::Any SAL_CALL dispatchWithReturnValue(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &lArgs) override
BasicManager * GetBasicManager() const
static SAL_WARN_UNUSED_RESULT SfxObjectShell * GetNext(const SfxObjectShell &rPrev, const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
SAL_DLLPRIVATE void SetMacroMode_Impl(bool bModal=true)
css::uno::Reference< css::frame::XModel3 > GetModel() const
bool AdjustMacroMode()
adjusts the internal macro mode, according to the current security settings
static SAL_WARN_UNUSED_RESULT SfxObjectShell * GetFirst(const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
static SAL_WARN_UNUSED_RESULT SfxObjectShell * Current()
#define ERRCODE_IO_ACCESSDENIED
#define ERRCODE_IO_NOTEXISTS
Sequence< PropertyValue > aArguments
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_sfx2_SfxMacroLoader_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &arguments)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
#define SFX_TITLE_APINAME
#define ERRCODE_BASIC_PROC_UNDEFINED
Any sbxToUnoValue(const SbxValue *pVar)
Reference< XFrame > xFrame