22#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
23#include <com/sun/star/frame/Desktop.hpp>
32#include <unordered_map>
38typedef std::unordered_map< OUString,
41static uno::Reference< XHelperInterface >
lcl_createWorkbookHIParent(
const uno::Reference< frame::XModel >& xModel,
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Any& aApplication )
43 return new ScVbaWorkbook( uno::Reference< XHelperInterface >( aApplication, uno::UNO_QUERY_THROW ), xContext,
xModel );
48 uno::Reference< frame::XModel >
xModel( aSource, uno::UNO_QUERY_THROW );
50 uno::Reference< frame::XController >
xController(
xModel->getCurrentController(), uno::UNO_SET_THROW );
55typedef std::vector < uno::Reference< sheet::XSpreadsheetDocument > >
Components;
63 uno::Reference< uno::XComponentContext >
m_xContext;
65 Components::const_iterator m_it;
69 WindowComponentEnumImpl( uno::Reference< uno::XComponentContext > xContext,
Components&& components )
76 explicit WindowComponentEnumImpl( uno::Reference< uno::XComponentContext > xContext ) :
m_xContext(std::move( xContext ))
78 uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create(
m_xContext);
79 uno::Reference< container::XEnumeration > xComponents = xDesktop->getComponents()->createEnumeration();
80 while( xComponents->hasMoreElements() )
82 uno::Reference< sheet::XSpreadsheetDocument > xNext( xComponents->nextElement(), uno::UNO_QUERY );
89 virtual sal_Bool SAL_CALL hasMoreElements( )
override
94 virtual uno::Any SAL_CALL nextElement( )
override
96 if ( !hasMoreElements() )
98 throw container::NoSuchElementException();
100 return css::uno::Any( *(m_it++) );
104class WindowEnumImpl :
public WindowComponentEnumImpl
108 WindowEnumImpl(
const uno::Reference< uno::XComponentContext >& xContext,
uno::Any aApplication ): WindowComponentEnumImpl( xContext ), m_aApplication(std::move( aApplication )) {}
109 virtual uno::Any SAL_CALL nextElement( )
override
117typedef ::cppu::WeakImplHelper< container::XEnumerationAccess
118 , css::container::XIndexAccess
119 , css::container::XNameAccess
126 uno::Reference< uno::XComponentContext >
m_xContext;
130 explicit WindowsAccessImpl( uno::Reference< uno::XComponentContext > xContext ):
m_xContext(std::move( xContext ))
132 uno::Reference< container::XEnumeration > xEnum =
new WindowComponentEnumImpl(
m_xContext );
134 while( xEnum->hasMoreElements() )
136 uno::Reference< sheet::XSpreadsheetDocument > xNext( xEnum->nextElement(), uno::UNO_QUERY );
139 m_windows.push_back( xNext );
140 uno::Reference< frame::XModel >
xModel( xNext, uno::UNO_QUERY_THROW );
142 uno::Reference< frame::XController >
xController(
xModel->getCurrentController(), uno::UNO_SET_THROW );
143 uno::Reference< XHelperInterface > xTemp;
146 window->getCaption() >>= sCaption;
147 namesToIndices[ sCaption ] =
nIndex++;
154 virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( )
override
156 return new WindowComponentEnumImpl(
m_xContext, std::vector(m_windows) );
159 virtual ::sal_Int32 SAL_CALL getCount( )
override
161 return m_windows.size();
163 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32
Index )
override
167 throw lang::IndexOutOfBoundsException();
168 return css::uno::Any( m_windows[
Index ] );
172 virtual uno::Type SAL_CALL getElementType( )
override
177 virtual sal_Bool SAL_CALL hasElements( )
override
179 return ( !m_windows.empty() );
183 virtual uno::Any SAL_CALL getByName(
const OUString&
aName )
override
185 NameIndexHash::const_iterator it = namesToIndices.find(
aName );
186 if ( it == namesToIndices.end() )
187 throw container::NoSuchElementException();
188 return css::uno::Any( m_windows[ it->second ] );
192 virtual uno::Sequence< OUString > SAL_CALL getElementNames( )
override
197 virtual sal_Bool SAL_CALL hasByName(
const OUString&
aName )
override
199 NameIndexHash::const_iterator it = namesToIndices.find(
aName );
200 return (it != namesToIndices.end());
210uno::Reference< container::XEnumeration >
237 return "ScVbaWindows";
240css::uno::Sequence<OUString>
243 static uno::Sequence< OUString >
const sNames
245 "ooo.vba.excel.Windows"
Reference< XComponentContext > m_xContext
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Any SAL_CALL Application() override
virtual void SAL_CALL Arrange(::sal_Int32 ArrangeStyle, const css::uno::Any &ActiveWorkbook, const css::uno::Any &SyncHorizontal, const css::uno::Any &SyncVertical) override
ScVbaWindows(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext)
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual css::uno::Type SAL_CALL getElementType() override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
virtual OUString getServiceImplName() override
css::uno::Type const & get()
std::deque< OUString > m_components
css::uno::Sequence< typename M::key_type > mapKeysToSequence(M const &map)
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
Reference< XController > xController
Reference< XModel > xModel
::cppu::WeakImplHelper< css::container::XEnumeration > EnumerationHelper_BASE
std::unordered_map< OUString, sal_Int32 > NameIndexHash
static uno::Reference< XHelperInterface > lcl_createWorkbookHIParent(const uno::Reference< frame::XModel > &xModel, const uno::Reference< uno::XComponentContext > &xContext, const uno::Any &aApplication)
std::vector< uno::Reference< sheet::XSpreadsheetDocument > > Components
static uno::Any ComponentToWindow(const uno::Any &aSource, const uno::Reference< uno::XComponentContext > &xContext, const uno::Any &aApplication)
::cppu::WeakImplHelper< container::XEnumerationAccess, css::container::XIndexAccess, css::container::XNameAccess > WindowsAccessImpl_BASE
std::unordered_map< OUString, sal_Int32 > NameIndexHash