Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #include "vbawindows.hxx"
29 : :
30 : : #include <boost/unordered_map.hpp>
31 : :
32 : : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
33 : : #include <com/sun/star/frame/XDesktop.hpp>
34 : : #include <cppuhelper/implbase3.hxx>
35 : :
36 : : #include "vbawindow.hxx"
37 : : #include "vbaglobals.hxx"
38 : :
39 : : using namespace ::com::sun::star;
40 : : using namespace ::ooo::vba;
41 : :
42 : : typedef boost::unordered_map< rtl::OUString,
43 : : sal_Int32, ::rtl::OUStringHash,
44 : : ::std::equal_to< ::rtl::OUString > > NameIndexHash;
45 : :
46 : :
47 : 0 : uno::Reference< XHelperInterface > lcl_createWorkbookHIParent( const uno::Reference< frame::XModel >& xModel, const uno::Reference< uno::XComponentContext >& xContext, const uno::Any& aApplication )
48 : : {
49 [ # # ][ # # ]: 0 : return new ScVbaWorkbook( uno::Reference< XHelperInterface >( aApplication, uno::UNO_QUERY_THROW ), xContext, xModel );
[ # # ]
50 : : }
51 : :
52 : 0 : uno::Any ComponentToWindow( const uno::Any& aSource, uno::Reference< uno::XComponentContext > & xContext, const uno::Any& aApplication )
53 : : {
54 [ # # ]: 0 : uno::Reference< frame::XModel > xModel( aSource, uno::UNO_QUERY_THROW );
55 : : // !! TODO !! iterate over all controllers
56 [ # # ][ # # ]: 0 : uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW );
[ # # ]
57 [ # # ][ # # ]: 0 : uno::Reference< excel::XWindow > xWin( new ScVbaWindow( lcl_createWorkbookHIParent( xModel, xContext, aApplication ), xContext, xModel, xController ) );
[ # # ][ # # ]
58 [ # # ]: 0 : return uno::makeAny( xWin );
59 : : }
60 : :
61 : : typedef std::vector < uno::Reference< sheet::XSpreadsheetDocument > > Components;
62 : : // #TODO more or less the same as class in workwindows ( code sharing needed )
63 [ # # ]: 0 : class WindowComponentEnumImpl : public EnumerationHelper_BASE
64 : : {
65 : : protected:
66 : : uno::Reference< uno::XComponentContext > m_xContext;
67 : : Components m_components;
68 : : Components::const_iterator m_it;
69 : :
70 : : public:
71 [ # # ]: 0 : WindowComponentEnumImpl( const uno::Reference< uno::XComponentContext >& xContext, const Components& components ) throw ( uno::RuntimeException ) : m_xContext( xContext ), m_components( components )
72 : : {
73 [ # # ]: 0 : m_it = m_components.begin();
74 : 0 : }
75 : :
76 [ # # ]: 0 : WindowComponentEnumImpl( const uno::Reference< uno::XComponentContext >& xContext ) throw ( uno::RuntimeException ) : m_xContext( xContext )
77 : : {
78 : : uno::Reference< lang::XMultiComponentFactory > xSMgr(
79 [ # # ][ # # ]: 0 : m_xContext->getServiceManager(), uno::UNO_QUERY_THROW );
[ # # ]
80 : :
81 : : uno::Reference< frame::XDesktop > xDesktop
82 [ # # ][ # # ]: 0 : (xSMgr->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop")), m_xContext), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
83 [ # # ][ # # ]: 0 : uno::Reference< container::XEnumeration > mxComponents = xDesktop->getComponents()->createEnumeration();
[ # # ][ # # ]
84 [ # # ][ # # ]: 0 : while( mxComponents->hasMoreElements() )
[ # # ]
85 : : {
86 [ # # ][ # # ]: 0 : uno::Reference< sheet::XSpreadsheetDocument > xNext( mxComponents->nextElement(), uno::UNO_QUERY );
[ # # ]
87 [ # # ]: 0 : if ( xNext.is() )
88 [ # # ]: 0 : m_components.push_back( xNext );
89 : 0 : }
90 [ # # ]: 0 : m_it = m_components.begin();
91 : 0 : }
92 : : // XEnumeration
93 : 0 : virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException)
94 : : {
95 [ # # ]: 0 : return m_it != m_components.end();
96 : : }
97 : :
98 : 0 : virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
99 : : {
100 [ # # ]: 0 : if ( !hasMoreElements() )
101 : : {
102 [ # # ]: 0 : throw container::NoSuchElementException();
103 : : }
104 [ # # ]: 0 : return makeAny( *(m_it++) );
105 : : }
106 : : };
107 : :
108 [ # # ]: 0 : class WindowEnumImpl : public WindowComponentEnumImpl
109 : : {
110 : : uno::Any m_aApplication;
111 : : public:
112 : : WindowEnumImpl(const uno::Reference< uno::XComponentContext >& xContext, const Components& components, const uno::Any& aApplication ):WindowComponentEnumImpl( xContext, components ), m_aApplication( aApplication ){}
113 : 0 : WindowEnumImpl( const uno::Reference< uno::XComponentContext >& xContext, const uno::Any& aApplication ): WindowComponentEnumImpl( xContext ), m_aApplication( aApplication ) {}
114 : 0 : virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
115 : : {
116 [ # # ]: 0 : return ComponentToWindow( WindowComponentEnumImpl::nextElement(), m_xContext, m_aApplication );
117 : : }
118 : : };
119 : :
120 : : typedef ::cppu::WeakImplHelper3< container::XEnumerationAccess
121 : : , com::sun::star::container::XIndexAccess
122 : : , com::sun::star::container::XNameAccess
123 : : > WindowsAccessImpl_BASE;
124 : :
125 [ # # ][ # # ]: 0 : class WindowsAccessImpl : public WindowsAccessImpl_BASE
126 : : {
127 : : uno::Reference< uno::XComponentContext > m_xContext;
128 : : Components m_windows;
129 : : NameIndexHash namesToIndices;
130 : : public:
131 [ # # ][ # # ]: 0 : WindowsAccessImpl( const uno::Reference< uno::XComponentContext >& xContext ):m_xContext( xContext )
132 : : {
133 [ # # ][ # # ]: 0 : uno::Reference< container::XEnumeration > xEnum = new WindowComponentEnumImpl( m_xContext );
[ # # ]
134 : 0 : sal_Int32 nIndex=0;
135 [ # # ][ # # ]: 0 : while( xEnum->hasMoreElements() )
[ # # ]
136 : : {
137 [ # # ][ # # ]: 0 : uno::Reference< sheet::XSpreadsheetDocument > xNext( xEnum->nextElement(), uno::UNO_QUERY );
[ # # ]
138 [ # # ]: 0 : if ( xNext.is() )
139 : : {
140 [ # # ]: 0 : m_windows.push_back( xNext );
141 [ # # ]: 0 : uno::Reference< frame::XModel > xModel( xNext, uno::UNO_QUERY_THROW ); // that the spreadsheetdocument is a xmodel is a given
142 : : // !! TODO !! iterate over all controllers
143 [ # # ][ # # ]: 0 : uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW );
[ # # ]
144 : 0 : uno::Reference< XHelperInterface > xTemp; // temporary needed for g++ 3.3.5
145 [ # # ]: 0 : ScVbaWindow window( xTemp, m_xContext, xModel, xController );
146 : 0 : rtl::OUString sCaption;
147 [ # # ]: 0 : window.getCaption() >>= sCaption;
148 [ # # ][ # # ]: 0 : namesToIndices[ sCaption ] = nIndex++;
149 : : }
150 : 0 : }
151 : :
152 : 0 : }
153 : :
154 : : //XEnumerationAccess
155 : 0 : virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException)
156 : : {
157 [ # # ][ # # ]: 0 : return new WindowComponentEnumImpl( m_xContext, m_windows );
158 : : }
159 : : // XIndexAccess
160 : 0 : virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException)
161 : : {
162 : 0 : return m_windows.size();
163 : : }
164 : 0 : virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw ( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
165 : : {
166 [ # # # # ]: 0 : if ( Index < 0
[ # # ]
167 : 0 : || static_cast< Components::size_type >( Index ) >= m_windows.size() )
168 [ # # ]: 0 : throw lang::IndexOutOfBoundsException();
169 : 0 : return makeAny( m_windows[ Index ] ); // returns xspreadsheetdoc
170 : : }
171 : :
172 : : //XElementAccess
173 : 0 : virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException)
174 : : {
175 : 0 : return sheet::XSpreadsheetDocument::static_type(0);
176 : : }
177 : :
178 : 0 : virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException)
179 : : {
180 : 0 : return ( !m_windows.empty() );
181 : : }
182 : :
183 : : //XNameAccess
184 : 0 : virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
185 : : {
186 [ # # ]: 0 : NameIndexHash::const_iterator it = namesToIndices.find( aName );
187 [ # # ][ # # ]: 0 : if ( it == namesToIndices.end() )
188 [ # # ]: 0 : throw container::NoSuchElementException();
189 [ # # ][ # # ]: 0 : return makeAny( m_windows[ it->second ] );
190 : :
191 : : }
192 : :
193 : 0 : virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (uno::RuntimeException)
194 : : {
195 [ # # ]: 0 : uno::Sequence< ::rtl::OUString > names( namesToIndices.size() );
196 [ # # ]: 0 : ::rtl::OUString* pString = names.getArray();
197 [ # # ]: 0 : NameIndexHash::const_iterator it = namesToIndices.begin();
198 [ # # ]: 0 : NameIndexHash::const_iterator it_end = namesToIndices.end();
199 [ # # ]: 0 : for ( ; it != it_end; ++it, ++pString )
200 [ # # ]: 0 : *pString = it->first;
201 : 0 : return names;
202 : : }
203 : :
204 : 0 : virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (uno::RuntimeException)
205 : : {
206 [ # # ]: 0 : NameIndexHash::const_iterator it = namesToIndices.find( aName );
207 [ # # ]: 0 : return (it != namesToIndices.end());
208 : : }
209 : :
210 : : };
211 : :
212 [ # # ][ # # ]: 0 : ScVbaWindows::ScVbaWindows( const uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : ScVbaWindows_BASE( xParent, xContext, uno::Reference< container::XIndexAccess > ( new WindowsAccessImpl( xContext ) ) )
[ # # ]
213 : : {
214 : 0 : }
215 : : uno::Reference< container::XEnumeration >
216 : 0 : ScVbaWindows::createEnumeration() throw (uno::RuntimeException)
217 : : {
218 [ # # ][ # # ]: 0 : return new WindowEnumImpl( mxContext, Application() );
[ # # ]
219 : : }
220 : :
221 : : uno::Any
222 : 0 : ScVbaWindows::createCollectionObject( const css::uno::Any& aSource )
223 : : {
224 [ # # ]: 0 : return ComponentToWindow( aSource, mxContext, Application() );
225 : : }
226 : :
227 : : uno::Type
228 : 0 : ScVbaWindows::getElementType() throw (uno::RuntimeException)
229 : : {
230 : 0 : return excel::XWindows::static_type(0);
231 : : }
232 : :
233 : :
234 : : void SAL_CALL
235 : 0 : ScVbaWindows::Arrange( ::sal_Int32 /*ArrangeStyle*/, const uno::Any& /*ActiveWorkbook*/, const uno::Any& /*SyncHorizontal*/, const uno::Any& /*SyncVertical*/ ) throw (uno::RuntimeException)
236 : : {
237 : : //#TODO #FIXME see what can be done for an implementation here
238 : 0 : }
239 : :
240 : :
241 : : rtl::OUString
242 : 0 : ScVbaWindows::getServiceImplName()
243 : : {
244 : 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScVbaWindows"));
245 : : }
246 : :
247 : : css::uno::Sequence<rtl::OUString>
248 : 0 : ScVbaWindows::getServiceNames()
249 : : {
250 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > sNames;
[ # # ][ # # ]
251 [ # # ]: 0 : if ( sNames.getLength() == 0 )
252 : : {
253 : 0 : sNames.realloc( 1 );
254 [ # # ]: 0 : sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Windows") );
255 : : }
256 : 0 : return sNames;
257 : : }
258 : :
259 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|