22 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
23 #include <com/sun/star/frame/Desktop.hpp>
27 #include <rtl/ref.hxx>
32 #include <unordered_map>
37 typedef std::unordered_map< OUString,
40 static uno::Reference< XHelperInterface >
lcl_createWorkbookHIParent(
const uno::Reference< frame::XModel >& xModel,
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Any& aApplication )
42 return new ScVbaWorkbook( uno::Reference< XHelperInterface >( aApplication, uno::UNO_QUERY_THROW ), xContext, xModel );
47 uno::Reference< frame::XModel >
xModel( aSource, uno::UNO_QUERY_THROW );
49 uno::Reference< frame::XController >
xController( xModel->getCurrentController(), uno::UNO_SET_THROW );
51 return uno::makeAny( xWin );
54 typedef std::vector < uno::Reference< sheet::XSpreadsheetDocument > >
Components;
62 uno::Reference< uno::XComponentContext >
m_xContext;
64 Components::const_iterator m_it;
68 WindowComponentEnumImpl(
const uno::Reference< uno::XComponentContext >& xContext,
const Components& components ) : m_xContext( xContext ), m_components( components )
70 m_it = m_components.begin();
74 explicit WindowComponentEnumImpl(
const uno::Reference< uno::XComponentContext >& xContext ) : m_xContext( xContext )
76 uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create(m_xContext);
77 uno::Reference< container::XEnumeration > xComponents = xDesktop->getComponents()->createEnumeration();
78 while( xComponents->hasMoreElements() )
80 uno::Reference< sheet::XSpreadsheetDocument > xNext( xComponents->nextElement(), uno::UNO_QUERY );
82 m_components.push_back( xNext );
84 m_it = m_components.begin();
87 virtual sal_Bool SAL_CALL hasMoreElements( )
override
89 return m_it != m_components.end();
92 virtual uno::Any SAL_CALL nextElement( )
override
94 if ( !hasMoreElements() )
96 throw container::NoSuchElementException();
102 class WindowEnumImpl :
public WindowComponentEnumImpl
106 WindowEnumImpl(
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Any& aApplication ): WindowComponentEnumImpl( xContext ), m_aApplication( aApplication ) {}
107 virtual uno::Any SAL_CALL nextElement( )
override
115 typedef ::cppu::WeakImplHelper< container::XEnumerationAccess
116 , css::container::XIndexAccess
117 , css::container::XNameAccess
124 uno::Reference< uno::XComponentContext >
m_xContext;
128 explicit WindowsAccessImpl(
const uno::Reference< uno::XComponentContext >& xContext ):m_xContext( xContext )
130 uno::Reference< container::XEnumeration > xEnum =
new WindowComponentEnumImpl( m_xContext );
132 while( xEnum->hasMoreElements() )
134 uno::Reference< sheet::XSpreadsheetDocument > xNext( xEnum->nextElement(), uno::UNO_QUERY );
137 m_windows.push_back( xNext );
138 uno::Reference< frame::XModel >
xModel( xNext, uno::UNO_QUERY_THROW );
140 uno::Reference< frame::XController >
xController( xModel->getCurrentController(), uno::UNO_SET_THROW );
141 uno::Reference< XHelperInterface > xTemp;
144 window->getCaption() >>= sCaption;
145 namesToIndices[ sCaption ] = nIndex++;
152 virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( )
override
154 return new WindowComponentEnumImpl( m_xContext, m_windows );
157 virtual ::sal_Int32 SAL_CALL getCount( )
override
159 return m_windows.size();
161 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32
Index )
override
165 throw lang::IndexOutOfBoundsException();
166 return makeAny( m_windows[ Index ] );
170 virtual uno::Type SAL_CALL getElementType( )
override
175 virtual sal_Bool SAL_CALL hasElements( )
override
177 return ( !m_windows.empty() );
181 virtual uno::Any SAL_CALL getByName(
const OUString&
aName )
override
183 NameIndexHash::const_iterator it = namesToIndices.find( aName );
184 if ( it == namesToIndices.end() )
185 throw container::NoSuchElementException();
186 return makeAny( m_windows[ it->second ] );
190 virtual uno::Sequence< OUString > SAL_CALL getElementNames( )
override
195 virtual sal_Bool SAL_CALL hasByName(
const OUString& aName )
override
197 NameIndexHash::const_iterator it = namesToIndices.find( aName );
198 return (it != namesToIndices.end());
208 uno::Reference< container::XEnumeration >
235 return "ScVbaWindows";
238 css::uno::Sequence<OUString>
241 static uno::Sequence< OUString >
const sNames
243 "ooo.vba.excel.Windows"
virtual css::uno::Any SAL_CALL Application() override
virtual OUString getServiceImplName() override
static uno::Any ComponentToWindow(const uno::Any &aSource, const uno::Reference< uno::XComponentContext > &xContext, const uno::Any &aApplication)
std::deque< OUString > m_components
virtual css::uno::Type SAL_CALL getElementType() override
::cppu::WeakImplHelper< css::container::XEnumeration > EnumerationHelper_BASE
exports com.sun.star. container
Reference< XController > xController
virtual css::uno::Sequence< OUString > getServiceNames() 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
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
ScVbaWindows(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext)
css::uno::Type const & get()
std::unordered_map< OUString, sal_Int32 > NameIndexHash
::cppu::WeakImplHelper< container::XEnumerationAccess, css::container::XIndexAccess, css::container::XNameAccess > WindowsAccessImpl_BASE
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
std::vector< uno::Reference< sheet::XSpreadsheetDocument > > Components
css::uno::Reference< css::uno::XComponentContext > mxContext
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)
Reference< XModel > xModel
Reference< XComponentContext > m_xContext
css::uno::Sequence< typename M::key_type > mapKeysToSequence(M const &map)
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)