22#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
23#include <com/sun/star/frame/Desktop.hpp>
32#include <unordered_map>
35#include <osl/file.hxx>
36#include <ooo/vba/excel/XApplication.hpp>
41typedef std::unordered_map< OUString,
44static uno::Reference< XHelperInterface >
lcl_createWorkbookHIParent(
const uno::Reference< frame::XModel >& xModel,
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Any& aApplication )
46 return new ScVbaWorkbook( uno::Reference< XHelperInterface >( aApplication, uno::UNO_QUERY_THROW ), xContext,
xModel );
51 uno::Reference< frame::XModel >
xModel( aSource, uno::UNO_QUERY_THROW );
53 uno::Reference< frame::XController >
xController(
xModel->getCurrentController(), uno::UNO_SET_THROW );
58typedef std::vector < uno::Reference< sheet::XSpreadsheetDocument > >
Components;
66 uno::Reference< uno::XComponentContext >
m_xContext;
68 Components::const_iterator m_it;
72 WindowComponentEnumImpl( uno::Reference< uno::XComponentContext > xContext,
Components&& components )
79 explicit WindowComponentEnumImpl( uno::Reference< uno::XComponentContext > xContext ) :
m_xContext(std::move( xContext ))
81 uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create(
m_xContext);
82 uno::Reference< container::XEnumeration > xComponents = xDesktop->getComponents()->createEnumeration();
83 while( xComponents->hasMoreElements() )
85 uno::Reference< sheet::XSpreadsheetDocument > xNext( xComponents->nextElement(), uno::UNO_QUERY );
92 virtual sal_Bool SAL_CALL hasMoreElements( )
override
97 virtual uno::Any SAL_CALL nextElement( )
override
99 if ( !hasMoreElements() )
101 throw container::NoSuchElementException();
103 return css::uno::Any( *(m_it++) );
107class WindowEnumImpl :
public WindowComponentEnumImpl
111 WindowEnumImpl(
const uno::Reference< uno::XComponentContext >& xContext,
uno::Any aApplication ): WindowComponentEnumImpl( xContext ), m_aApplication(std::move( aApplication )) {}
112 virtual uno::Any SAL_CALL nextElement( )
override
120typedef ::cppu::WeakImplHelper< container::XEnumerationAccess
121 , css::container::XIndexAccess
122 , css::container::XNameAccess
129 uno::Reference< uno::XComponentContext >
m_xContext;
133 explicit WindowsAccessImpl( uno::Reference< uno::XComponentContext > xContext ):
m_xContext(std::move( xContext ))
135 css::uno::Reference<css::container::XNameAccess> xNameAccess(
m_xContext,
136 css::uno::UNO_QUERY_THROW);
137 const auto aAppplication = xNameAccess->getByName(
"Application");
139 uno::Reference< container::XEnumeration > xEnum =
new WindowComponentEnumImpl(
m_xContext );
141 while( xEnum->hasMoreElements() )
143 uno::Reference< sheet::XSpreadsheetDocument > xNext( xEnum->nextElement(), uno::UNO_QUERY );
146 m_windows.push_back( xNext );
147 uno::Reference< frame::XModel >
xModel( xNext, uno::UNO_QUERY_THROW );
151 uno::Reference<XHelperInterface>(aAppplication, uno::UNO_QUERY_THROW),
153 const OUString aWorkBookName(workbook->getName());
154 if (!hasByName(aWorkBookName))
155 namesToIndices[aWorkBookName] =
nIndex;
159 ::osl::File::getSystemPathFromFileURL(
xModel->getURL(),
sName);
160 if (!hasByName(
sName))
164 uno::Reference< frame::XController >
xController(
xModel->getCurrentController(), uno::UNO_SET_THROW );
165 uno::Reference< XHelperInterface > xTemp;
168 window->getCaption() >>= sCaption;
169 namesToIndices[ sCaption ] =
nIndex++;
176 virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( )
override
178 return new WindowComponentEnumImpl(
m_xContext, std::vector(m_windows) );
181 virtual ::sal_Int32 SAL_CALL getCount( )
override
183 return m_windows.size();
185 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32
Index )
override
189 throw lang::IndexOutOfBoundsException();
190 return css::uno::Any( m_windows[
Index ] );
194 virtual uno::Type SAL_CALL getElementType( )
override
199 virtual sal_Bool SAL_CALL hasElements( )
override
201 return ( !m_windows.empty() );
205 virtual uno::Any SAL_CALL getByName(
const OUString&
aName )
override
207 NameIndexHash::const_iterator it = namesToIndices.find(
aName );
208 if ( it == namesToIndices.end() )
209 throw container::NoSuchElementException();
210 return css::uno::Any( m_windows[ it->second ] );
214 virtual uno::Sequence< OUString > SAL_CALL getElementNames( )
override
219 virtual sal_Bool SAL_CALL hasByName(
const OUString&
aName )
override
221 NameIndexHash::const_iterator it = namesToIndices.find(
aName );
222 return (it != namesToIndices.end());
232uno::Reference< container::XEnumeration >
259 return "ScVbaWindows";
262css::uno::Sequence<OUString>
265 static uno::Sequence< OUString >
const sNames
267 "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