diff options
author | Tor Lillqvist <tml@collabora.com> | 2018-03-07 13:12:01 +0200 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2018-05-30 19:26:24 +0200 |
commit | 857a33404626f8df04882478d026969691624cbb (patch) | |
tree | b78a1e0ad023c9c0d0f7b819949df334ae2852aa | |
parent | e02b3b095e472646c58eecd36d5a27b056dcb99e (diff) |
Add Caption property to ooo::vba::XApplicationBase
Implementation is just a dummy, though. At first I thought that it
would work to get the XModel of the "current" document (as returned by
getCurrentDocument()), and then get the XFrame of that, and then use
the XFrame's getName() and setName(). But, it seems that
getCurrentDocument() and what it calls is tightly coupled to
StarBasic, and it doesn't do anything sane in the case of Automation
clients.
Change-Id: I74ded5114ecce06e72862f69d0c06d963e55fd75
Reviewed-on: https://gerrit.libreoffice.org/55064
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
-rw-r--r-- | include/vbahelper/vbaapplicationbase.hxx | 2 | ||||
-rw-r--r-- | oovbaapi/ooo/vba/XApplicationBase.idl | 1 | ||||
-rw-r--r-- | vbahelper/source/vbahelper/vbaapplicationbase.cxx | 34 |
3 files changed, 37 insertions, 0 deletions
diff --git a/include/vbahelper/vbaapplicationbase.hxx b/include/vbahelper/vbaapplicationbase.hxx index 4f392a5d332c..be2f6765e951 100644 --- a/include/vbahelper/vbaapplicationbase.hxx +++ b/include/vbahelper/vbaapplicationbase.hxx @@ -64,6 +64,8 @@ public: virtual void SAL_CALL setInteractive( sal_Bool bInteractive ) override; virtual sal_Bool SAL_CALL getVisible() override; virtual void SAL_CALL setVisible( sal_Bool bVisible ) override; + virtual OUString SAL_CALL getCaption() override; + virtual void SAL_CALL setCaption( const OUString& sCaption ) override; virtual void SAL_CALL OnKey( const OUString& Key, const css::uno::Any& Procedure ) override; virtual css::uno::Any SAL_CALL CommandBars( const css::uno::Any& aIndex ) override; virtual OUString SAL_CALL getVersion() override; diff --git a/oovbaapi/ooo/vba/XApplicationBase.idl b/oovbaapi/ooo/vba/XApplicationBase.idl index 90ba919407d4..4df45daad53e 100644 --- a/oovbaapi/ooo/vba/XApplicationBase.idl +++ b/oovbaapi/ooo/vba/XApplicationBase.idl @@ -32,6 +32,7 @@ interface XApplicationBase [attribute] boolean DisplayStatusBar; [attribute] boolean Interactive; [attribute] boolean Visible; + [attribute] string Caption; [attribute, readonly] string Version; [attribute, readonly] any VBE; diff --git a/vbahelper/source/vbahelper/vbaapplicationbase.cxx b/vbahelper/source/vbahelper/vbaapplicationbase.cxx index a0268237efe6..d550731cc89f 100644 --- a/vbahelper/source/vbahelper/vbaapplicationbase.cxx +++ b/vbahelper/source/vbahelper/vbaapplicationbase.cxx @@ -151,6 +151,7 @@ struct VbaApplicationBase_Impl final { VbaTimerHashMap m_aTimerHash; bool mbVisible; + OUString msCaption; VbaApplicationBase_Impl() : mbVisible( true ) {} @@ -262,6 +263,39 @@ void SAL_CALL VbaApplicationBase::setVisible( sal_Bool bVisible ) m_pImpl->mbVisible = bVisible; // dummy implementation } +OUString SAL_CALL VbaApplicationBase::getCaption() +{ + SbMethod* pMeth = StarBASIC::GetActiveMethod(); + if (!pMeth) + { + // When called from Automation clients, we don't even try, as there doesn't seem to be any + // good way to get at the actual "caption" (title) of the application's window (any of them, + // if there are several). We just keep a copy of a fake caption in the VbaApplicationBase_Impl. + return m_pImpl->msCaption; + } + + // No idea if this code, which uses APIs that apparently are related to StarBasic (check + // getCurrentDoc() in vbahelper.cxx), actually works any better. + uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); + uno::Reference< frame::XFrame > xFrame( xModel->getCurrentController()->getFrame(), uno::UNO_QUERY_THROW ); + return xFrame->getName(); +} + +void SAL_CALL VbaApplicationBase::setCaption( const OUString& sCaption ) +{ + // See comments in getCaption(). + + SbMethod* pMeth = StarBASIC::GetActiveMethod(); + if (!pMeth) + { + m_pImpl->msCaption = sCaption; + return; + } + + uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); + uno::Reference< frame::XFrame > xFrame( xModel->getCurrentController()->getFrame(), uno::UNO_QUERY_THROW ); + xFrame->setName( sCaption ); +} void SAL_CALL VbaApplicationBase::OnKey( const OUString& Key, const uno::Any& Procedure ) |