Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #include <vbahelper/helperdecl.hxx>
20 : #include "vbawindow.hxx"
21 : #include "vbaworksheets.hxx"
22 : #include "vbaworksheet.hxx"
23 : #include "vbaglobals.hxx"
24 : #include "vbapane.hxx"
25 : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
26 : #include <com/sun/star/sheet/XSpreadsheet.hpp>
27 : #include <com/sun/star/container/XNamed.hpp>
28 : #include <com/sun/star/view/DocumentZoomType.hpp>
29 : #include <com/sun/star/table/CellRangeAddress.hpp>
30 : #include <ooo/vba/excel/XlWindowState.hpp>
31 : #include <ooo/vba/excel/XlWindowView.hpp>
32 : #include <ooo/vba/excel/Constants.hpp>
33 : #include <com/sun/star/awt/XWindow.hpp>
34 : #include <com/sun/star/awt/XWindow2.hpp>
35 : #include <com/sun/star/awt/PosSize.hpp>
36 :
37 : #include <docsh.hxx>
38 : #include <tabvwsh.hxx>
39 : #include <docuno.hxx>
40 : #include <sc.hrc>
41 : #include <boost/unordered_map.hpp>
42 : #include <sfx2/viewfrm.hxx>
43 : #include <vcl/wrkwin.hxx>
44 : #include "unonames.hxx"
45 : #include "markdata.hxx"
46 :
47 : using namespace ::com::sun::star;
48 : using namespace ::ooo::vba;
49 : using namespace ::ooo::vba::excel::XlWindowState;
50 :
51 : typedef boost::unordered_map< rtl::OUString,
52 : SCTAB, ::rtl::OUStringHash,
53 : ::std::equal_to< ::rtl::OUString > > NameIndexHash;
54 :
55 : typedef std::vector< uno::Reference< sheet::XSpreadsheet > > Sheets;
56 :
57 : typedef ::cppu::WeakImplHelper1< container::XEnumeration > Enumeration_BASE;
58 :
59 : typedef ::cppu::WeakImplHelper3< container::XEnumerationAccess
60 : , com::sun::star::container::XIndexAccess
61 : , com::sun::star::container::XNameAccess
62 : > SelectedSheets_BASE;
63 :
64 :
65 0 : class SelectedSheetsEnum : public Enumeration_BASE
66 : {
67 : public:
68 : uno::Reference< uno::XComponentContext > m_xContext;
69 : Sheets m_sheets;
70 : uno::Reference< frame::XModel > m_xModel;
71 : Sheets::const_iterator m_it;
72 :
73 0 : SelectedSheetsEnum( const uno::Reference< uno::XComponentContext >& xContext, const Sheets& sheets, const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException ) : m_xContext( xContext ), m_sheets( sheets ), m_xModel( xModel )
74 : {
75 0 : m_it = m_sheets.begin();
76 0 : }
77 : // XEnumeration
78 0 : virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException)
79 : {
80 0 : return m_it != m_sheets.end();
81 : }
82 0 : virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
83 : {
84 0 : if ( !hasMoreElements() )
85 : {
86 0 : throw container::NoSuchElementException();
87 : }
88 : // #FIXME needs ThisWorkbook as parent
89 0 : return uno::makeAny( uno::Reference< excel::XWorksheet > ( new ScVbaWorksheet( uno::Reference< XHelperInterface >(), m_xContext, *(m_it++), m_xModel ) ) );
90 : }
91 :
92 :
93 : };
94 :
95 0 : class SelectedSheetsEnumAccess : public SelectedSheets_BASE
96 : {
97 : uno::Reference< uno::XComponentContext > m_xContext;
98 : NameIndexHash namesToIndices;
99 : Sheets sheets;
100 : uno::Reference< frame::XModel > m_xModel;
101 : public:
102 0 : SelectedSheetsEnumAccess( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ):m_xContext( xContext ), m_xModel( xModel )
103 : {
104 0 : ScModelObj* pModel = static_cast< ScModelObj* >( m_xModel.get() );
105 0 : if ( !pModel )
106 0 : throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot obtain current document" ) ), uno::Reference< uno::XInterface >() );
107 0 : ScDocShell* pDocShell = (ScDocShell*)pModel->GetEmbeddedObject();
108 0 : if ( !pDocShell )
109 0 : throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot obtain docshell" ) ), uno::Reference< uno::XInterface >() );
110 0 : ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
111 0 : if ( !pViewShell )
112 0 : throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot obtain view shell" ) ), uno::Reference< uno::XInterface >() );
113 :
114 0 : SCTAB nTabCount = pDocShell->GetDocument()->GetTableCount();
115 0 : uno::Sequence<sal_Int32> aSheets( nTabCount );
116 0 : SCTAB nIndex = 0;
117 0 : const ScMarkData& rMarkData = pViewShell->GetViewData()->GetMarkData();
118 0 : sheets.reserve( nTabCount );
119 0 : uno::Reference <sheet::XSpreadsheetDocument> xSpreadSheet( m_xModel, uno::UNO_QUERY_THROW );
120 0 : uno::Reference <container::XIndexAccess> xIndex( xSpreadSheet->getSheets(), uno::UNO_QUERY_THROW );
121 0 : ScMarkData::const_iterator itr = rMarkData.begin(), itrEnd = rMarkData.end();
122 0 : for (; itr != itrEnd && *itr < nTabCount; ++itr)
123 : {
124 0 : uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex( *itr ), uno::UNO_QUERY_THROW );
125 0 : uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW );
126 0 : sheets.push_back( xSheet );
127 0 : namesToIndices[ xNamed->getName() ] = nIndex++;
128 0 : }
129 :
130 0 : }
131 :
132 : //XEnumerationAccess
133 0 : virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException)
134 : {
135 0 : return new SelectedSheetsEnum( m_xContext, sheets, m_xModel );
136 : }
137 : // XIndexAccess
138 0 : virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException)
139 : {
140 0 : return sheets.size();
141 : }
142 0 : virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw ( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
143 : {
144 0 : if ( Index < 0
145 0 : || static_cast< Sheets::size_type >( Index ) >= sheets.size() )
146 0 : throw lang::IndexOutOfBoundsException();
147 :
148 0 : return uno::makeAny( sheets[ Index ] );
149 : }
150 :
151 : //XElementAccess
152 0 : virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException)
153 : {
154 0 : return excel::XWorksheet::static_type(0);
155 : }
156 :
157 0 : virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException)
158 : {
159 0 : return ( !sheets.empty() );
160 : }
161 :
162 : //XNameAccess
163 0 : virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
164 : {
165 0 : NameIndexHash::const_iterator it = namesToIndices.find( aName );
166 0 : if ( it == namesToIndices.end() )
167 0 : throw container::NoSuchElementException();
168 0 : return uno::makeAny( sheets[ it->second ] );
169 :
170 : }
171 :
172 0 : virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (uno::RuntimeException)
173 : {
174 0 : uno::Sequence< ::rtl::OUString > names( namesToIndices.size() );
175 0 : ::rtl::OUString* pString = names.getArray();
176 0 : NameIndexHash::const_iterator it = namesToIndices.begin();
177 0 : NameIndexHash::const_iterator it_end = namesToIndices.end();
178 0 : for ( ; it != it_end; ++it, ++pString )
179 0 : *pString = it->first;
180 0 : return names;
181 : }
182 :
183 0 : virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (uno::RuntimeException)
184 : {
185 0 : NameIndexHash::const_iterator it = namesToIndices.find( aName );
186 0 : return (it != namesToIndices.end());
187 : }
188 :
189 :
190 : };
191 :
192 0 : ScVbaWindow::ScVbaWindow(
193 : const uno::Reference< XHelperInterface >& xParent,
194 : const uno::Reference< uno::XComponentContext >& xContext,
195 : const uno::Reference< frame::XModel >& xModel,
196 : const uno::Reference< frame::XController >& xController ) throw (uno::RuntimeException) :
197 0 : WindowImpl_BASE( xParent, xContext, xModel, xController )
198 : {
199 0 : init();
200 0 : }
201 :
202 0 : ScVbaWindow::ScVbaWindow(
203 : const uno::Sequence< uno::Any >& args,
204 : const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException) :
205 0 : WindowImpl_BASE( args, xContext )
206 : {
207 0 : init();
208 0 : }
209 :
210 : void
211 0 : ScVbaWindow::init()
212 : {
213 : /* This method is called from the constructor, thus the own refcount is
214 : still zero. The implementation of ActivePane() uses a UNO reference of
215 : this (to set this window as parent of the pane obejct). This requires
216 : the own refcount to be non-zero, otherwise this instance will be
217 : desctructed immediately! Guard the call to ActivePane() in try/catch to
218 : not miss the decrementation of the reference count on exception. */
219 0 : osl_atomic_increment( &m_refCount );
220 : try
221 : {
222 0 : m_xPane = ActivePane();
223 : }
224 0 : catch( uno::Exception& )
225 : {
226 : }
227 0 : osl_atomic_decrement( &m_refCount );
228 0 : }
229 :
230 : uno::Reference< beans::XPropertySet >
231 0 : ScVbaWindow::getControllerProps() throw (uno::RuntimeException)
232 : {
233 0 : return uno::Reference< beans::XPropertySet >( getController(), uno::UNO_QUERY_THROW );
234 : }
235 :
236 : uno::Reference< beans::XPropertySet >
237 0 : ScVbaWindow::getFrameProps() throw (uno::RuntimeException)
238 : {
239 0 : return uno::Reference< beans::XPropertySet >( getController()->getFrame(), uno::UNO_QUERY_THROW );
240 : }
241 :
242 : uno::Reference< awt::XDevice >
243 0 : ScVbaWindow::getDevice() throw (uno::RuntimeException)
244 : {
245 0 : return uno::Reference< awt::XDevice >( getWindow(), uno::UNO_QUERY_THROW );
246 : }
247 :
248 : void
249 0 : ScVbaWindow::Scroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft, bool bLargeScroll ) throw (uno::RuntimeException)
250 : {
251 0 : if( !m_xPane.is() )
252 0 : throw uno::RuntimeException();
253 0 : if( bLargeScroll )
254 0 : m_xPane->LargeScroll( Down, Up, ToRight, ToLeft );
255 : else
256 0 : m_xPane->SmallScroll( Down, Up, ToRight, ToLeft );
257 0 : }
258 :
259 : void SAL_CALL
260 0 : ScVbaWindow::SmallScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException)
261 : {
262 0 : Scroll( Down, Up, ToRight, ToLeft );
263 0 : }
264 :
265 : void SAL_CALL
266 0 : ScVbaWindow::LargeScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException)
267 : {
268 0 : Scroll( Down, Up, ToRight, ToLeft, true );
269 0 : }
270 :
271 : uno::Any SAL_CALL
272 0 : ScVbaWindow::SelectedSheets( const uno::Any& aIndex ) throw (uno::RuntimeException)
273 : {
274 0 : uno::Reference< container::XEnumerationAccess > xEnumAccess( new SelectedSheetsEnumAccess( mxContext, m_xModel ) );
275 : // #FIXME needs a workbook as a parent
276 0 : uno::Reference< excel::XWorksheets > xSheets( new ScVbaWorksheets( uno::Reference< XHelperInterface >(), mxContext, xEnumAccess, m_xModel ) );
277 0 : if ( aIndex.hasValue() )
278 : {
279 0 : uno::Reference< XCollection > xColl( xSheets, uno::UNO_QUERY_THROW );
280 0 : return xColl->Item( aIndex, uno::Any() );
281 : }
282 0 : return uno::makeAny( xSheets );
283 : }
284 :
285 : void SAL_CALL
286 0 : ScVbaWindow::ScrollWorkbookTabs( const uno::Any& /*Sheets*/, const uno::Any& /*Position*/ ) throw (uno::RuntimeException)
287 : {
288 : // #TODO #FIXME need some implementation to scroll through the tabs
289 : // but where is this done?
290 : /*
291 : sal_Int32 nSheets = 0;
292 : sal_Int32 nPosition = 0;
293 : throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("No Implemented")), uno::Reference< uno::XInterface >() );
294 : sal_Bool bSheets = ( Sheets >>= nSheets );
295 : sal_Bool bPosition = ( Position >>= nPosition );
296 : if ( bSheets || bPosition ) // at least one param specified
297 : if ( bSheets )
298 : ;// use sheets
299 : else if ( bPosition )
300 : ; //use position
301 : */
302 :
303 0 : }
304 :
305 : uno::Any SAL_CALL
306 0 : ScVbaWindow::getCaption() throw (uno::RuntimeException)
307 : {
308 0 : static rtl::OUString sCrud(RTL_CONSTASCII_USTRINGPARAM(" - OpenOffice.org Calc" ) );
309 0 : static sal_Int32 nCrudLen = sCrud.getLength();
310 :
311 0 : rtl::OUString sTitle;
312 0 : getFrameProps()->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SC_UNONAME_TITLE ) ) ) >>= sTitle;
313 0 : sal_Int32 nCrudIndex = sTitle.indexOf( sCrud );
314 : // adjust title ( by removing crud )
315 : // sCrud string present
316 0 : if ( nCrudIndex != -1 )
317 : {
318 : // and ends with sCrud
319 0 : if ( ( nCrudLen + nCrudIndex ) == sTitle.getLength() )
320 : {
321 0 : sTitle = sTitle.copy( 0, nCrudIndex );
322 0 : ScVbaWorkbook workbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel );
323 0 : rtl::OUString sName = workbook.getName();
324 : // rather bizare hack to make sure the name behavior
325 : // is like XL
326 : // if the adjusted title == workbook name, use name
327 : // if the adjusted title != workbook name but ...
328 : // name == title + extension ( .csv, ,odt, .xls )
329 : // etc. then also use the name
330 :
331 0 : if ( !sTitle.equals( sName ) )
332 : {
333 0 : static rtl::OUString sDot( RTL_CONSTASCII_USTRINGPARAM(".") );
334 : // starts with title
335 0 : if ( sName.indexOf( sTitle ) == 0 )
336 : // extention starts immediately after
337 0 : if ( sName.match( sDot, sTitle.getLength() ) )
338 0 : sTitle = sName;
339 0 : }
340 : }
341 : }
342 0 : return uno::makeAny( sTitle );
343 : }
344 :
345 : void SAL_CALL
346 0 : ScVbaWindow::setCaption( const uno::Any& _caption ) throw (uno::RuntimeException)
347 : {
348 0 : getFrameProps()->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_TITLE ) ), _caption );
349 0 : }
350 :
351 : uno::Any SAL_CALL
352 0 : ScVbaWindow::getScrollRow() throw (uno::RuntimeException)
353 : {
354 0 : sal_Int32 nValue = 0;
355 : // !! TODO !! get view shell from controller
356 0 : ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
357 0 : if ( pViewShell )
358 : {
359 0 : ScSplitPos eWhich = pViewShell->GetViewData()->GetActivePart();
360 0 : nValue = pViewShell->GetViewData()->GetPosY(WhichV(eWhich));
361 : }
362 :
363 0 : return uno::makeAny( nValue + 1);
364 : }
365 :
366 : void SAL_CALL
367 0 : ScVbaWindow::setScrollRow( const uno::Any& _scrollrow ) throw (uno::RuntimeException)
368 : {
369 : // !! TODO !! get view shell from controller
370 0 : ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
371 0 : if ( pViewShell )
372 : {
373 0 : sal_Int32 scrollRow = 0;
374 0 : _scrollrow >>= scrollRow;
375 0 : ScSplitPos eWhich = pViewShell->GetViewData()->GetActivePart();
376 0 : sal_Int32 nOldValue = pViewShell->GetViewData()->GetPosY(WhichV(eWhich)) + 1;
377 0 : pViewShell->ScrollLines(0, scrollRow - nOldValue);
378 : }
379 0 : }
380 :
381 : uno::Any SAL_CALL
382 0 : ScVbaWindow::getScrollColumn() throw (uno::RuntimeException)
383 : {
384 0 : sal_Int32 nValue = 0;
385 : // !! TODO !! get view shell from controller
386 0 : ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
387 0 : if ( pViewShell )
388 : {
389 0 : ScSplitPos eWhich = pViewShell->GetViewData()->GetActivePart();
390 0 : nValue = pViewShell->GetViewData()->GetPosX(WhichH(eWhich));
391 : }
392 :
393 0 : return uno::makeAny( nValue + 1);
394 : }
395 :
396 : void SAL_CALL
397 0 : ScVbaWindow::setScrollColumn( const uno::Any& _scrollcolumn ) throw (uno::RuntimeException)
398 : {
399 : // !! TODO !! get view shell from controller
400 0 : ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
401 0 : if ( pViewShell )
402 : {
403 0 : sal_Int32 scrollColumn = 0;
404 0 : _scrollcolumn >>= scrollColumn;
405 0 : ScSplitPos eWhich = pViewShell->GetViewData()->GetActivePart();
406 0 : sal_Int32 nOldValue = pViewShell->GetViewData()->GetPosX(WhichH(eWhich)) + 1;
407 0 : pViewShell->ScrollLines(scrollColumn - nOldValue, 0);
408 : }
409 0 : }
410 :
411 : uno::Any SAL_CALL
412 0 : ScVbaWindow::getWindowState() throw (uno::RuntimeException)
413 : {
414 0 : sal_Int32 nwindowState = xlNormal;
415 : // !! TODO !! get view shell from controller
416 0 : ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
417 0 : SfxViewFrame* pViewFrame = pViewShell -> GetViewFrame();
418 0 : WorkWindow* pWork = (WorkWindow*) pViewFrame->GetFrame().GetSystemWindow();
419 0 : if ( pWork )
420 : {
421 0 : if ( pWork -> IsMaximized())
422 0 : nwindowState = xlMaximized;
423 0 : else if (pWork -> IsMinimized())
424 0 : nwindowState = xlMinimized;
425 : }
426 0 : return uno::makeAny( nwindowState );
427 : }
428 :
429 : void SAL_CALL
430 0 : ScVbaWindow::setWindowState( const uno::Any& _windowstate ) throw (uno::RuntimeException)
431 : {
432 0 : sal_Int32 nwindowState = xlMaximized;
433 0 : _windowstate >>= nwindowState;
434 : // !! TODO !! get view shell from controller
435 0 : ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
436 0 : SfxViewFrame* pViewFrame = pViewShell -> GetViewFrame();
437 0 : WorkWindow* pWork = (WorkWindow*) pViewFrame->GetFrame().GetSystemWindow();
438 0 : if ( pWork )
439 : {
440 0 : if ( nwindowState == xlMaximized)
441 0 : pWork -> Maximize();
442 0 : else if (nwindowState == xlMinimized)
443 0 : pWork -> Minimize();
444 0 : else if (nwindowState == xlNormal)
445 0 : pWork -> Restore();
446 : else
447 0 : throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Invalid Parameter" ) ), uno::Reference< uno::XInterface >() );
448 : }
449 0 : }
450 :
451 : void
452 0 : ScVbaWindow::Activate() throw (css::uno::RuntimeException)
453 : {
454 0 : ScVbaWorkbook workbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel );
455 :
456 0 : workbook.Activate();
457 0 : }
458 :
459 : void
460 0 : ScVbaWindow::Close( const uno::Any& SaveChanges, const uno::Any& FileName, const uno::Any& RouteWorkBook ) throw (uno::RuntimeException)
461 : {
462 0 : ScVbaWorkbook workbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel );
463 0 : workbook.Close(SaveChanges, FileName, RouteWorkBook );
464 0 : }
465 :
466 : uno::Reference< excel::XPane > SAL_CALL
467 0 : ScVbaWindow::ActivePane() throw (script::BasicErrorException, uno::RuntimeException)
468 : {
469 0 : uno::Reference< sheet::XViewPane > xViewPane( getController(), uno::UNO_QUERY_THROW );
470 0 : return new ScVbaPane( this, mxContext, m_xModel, xViewPane );
471 : }
472 :
473 : uno::Reference< excel::XRange > SAL_CALL
474 0 : ScVbaWindow::ActiveCell( ) throw (script::BasicErrorException, uno::RuntimeException)
475 : {
476 0 : uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
477 0 : return xApplication->getActiveCell();
478 : }
479 :
480 : uno::Any SAL_CALL
481 0 : ScVbaWindow::Selection( ) throw (script::BasicErrorException, uno::RuntimeException)
482 : {
483 0 : uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
484 0 : return xApplication->getSelection();
485 : }
486 :
487 : uno::Reference< excel::XRange > SAL_CALL
488 0 : ScVbaWindow::RangeSelection() throw (script::BasicErrorException, uno::RuntimeException)
489 : {
490 : /* TODO / FIXME: According to documentation, this method returns the range
491 : selection even if shapes are selected. */
492 0 : return uno::Reference< excel::XRange >( Selection(), uno::UNO_QUERY_THROW );
493 : }
494 :
495 : ::sal_Bool SAL_CALL
496 0 : ScVbaWindow::getDisplayGridlines() throw (uno::RuntimeException)
497 : {
498 0 : rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SHOWGRID ) );
499 0 : sal_Bool bGrid = sal_True;
500 0 : getControllerProps()->getPropertyValue( sName ) >>= bGrid;
501 0 : return bGrid;
502 : }
503 :
504 :
505 : void SAL_CALL
506 0 : ScVbaWindow::setDisplayGridlines( ::sal_Bool _displaygridlines ) throw (uno::RuntimeException)
507 : {
508 0 : rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SHOWGRID ) );
509 0 : getControllerProps()->setPropertyValue( sName, uno::makeAny( _displaygridlines ));
510 0 : }
511 :
512 : ::sal_Bool SAL_CALL
513 0 : ScVbaWindow::getDisplayHeadings() throw (uno::RuntimeException)
514 : {
515 0 : rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_COLROWHDR ) );
516 0 : sal_Bool bHeading = sal_True;
517 0 : getControllerProps()->getPropertyValue( sName ) >>= bHeading;
518 0 : return bHeading;
519 : }
520 :
521 : void SAL_CALL
522 0 : ScVbaWindow::setDisplayHeadings( ::sal_Bool _bDisplayHeadings ) throw (uno::RuntimeException)
523 : {
524 0 : rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_COLROWHDR ) );
525 0 : getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayHeadings ));
526 0 : }
527 :
528 : ::sal_Bool SAL_CALL
529 0 : ScVbaWindow::getDisplayHorizontalScrollBar() throw (uno::RuntimeException)
530 : {
531 0 : rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_HORSCROLL ) );
532 0 : sal_Bool bHorizontalScrollBar = sal_True;
533 0 : getControllerProps()->getPropertyValue( sName ) >>= bHorizontalScrollBar;
534 0 : return bHorizontalScrollBar;
535 : }
536 :
537 : void SAL_CALL
538 0 : ScVbaWindow::setDisplayHorizontalScrollBar( ::sal_Bool _bDisplayHorizontalScrollBar ) throw (uno::RuntimeException)
539 : {
540 0 : rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_HORSCROLL ) );
541 0 : getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayHorizontalScrollBar ));
542 0 : }
543 :
544 : ::sal_Bool SAL_CALL
545 0 : ScVbaWindow::getDisplayOutline() throw (uno::RuntimeException)
546 : {
547 0 : rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_OUTLSYMB ) );
548 0 : sal_Bool bOutline = sal_True;
549 0 : getControllerProps()->getPropertyValue( sName ) >>= bOutline;
550 0 : return bOutline;
551 : }
552 :
553 : void SAL_CALL
554 0 : ScVbaWindow::setDisplayOutline( ::sal_Bool _bDisplayOutline ) throw (uno::RuntimeException)
555 : {
556 0 : rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_OUTLSYMB ) );
557 0 : getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayOutline ));
558 0 : }
559 :
560 : ::sal_Bool SAL_CALL
561 0 : ScVbaWindow::getDisplayVerticalScrollBar() throw (uno::RuntimeException)
562 : {
563 0 : rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_VERTSCROLL ) );
564 0 : sal_Bool bVerticalScrollBar = sal_True;
565 0 : getControllerProps()->getPropertyValue( sName ) >>= bVerticalScrollBar;
566 0 : return bVerticalScrollBar;
567 : }
568 :
569 : void SAL_CALL
570 0 : ScVbaWindow::setDisplayVerticalScrollBar( ::sal_Bool _bDisplayVerticalScrollBar ) throw (uno::RuntimeException)
571 : {
572 0 : rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_VERTSCROLL ) );
573 0 : getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayVerticalScrollBar ));
574 0 : }
575 :
576 : ::sal_Bool SAL_CALL
577 0 : ScVbaWindow::getDisplayWorkbookTabs() throw (uno::RuntimeException)
578 : {
579 0 : rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SHEETTABS ) );
580 0 : sal_Bool bWorkbookTabs = sal_True;
581 0 : getControllerProps()->getPropertyValue( sName ) >>= bWorkbookTabs;
582 0 : return bWorkbookTabs;
583 : }
584 :
585 : void SAL_CALL
586 0 : ScVbaWindow::setDisplayWorkbookTabs( ::sal_Bool _bDisplayWorkbookTabs ) throw (uno::RuntimeException)
587 : {
588 0 : rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SHEETTABS ) );
589 0 : getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayWorkbookTabs ));
590 0 : }
591 :
592 : ::sal_Bool SAL_CALL
593 0 : ScVbaWindow::getFreezePanes() throw (uno::RuntimeException)
594 : {
595 0 : uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
596 0 : return xViewFreezable->hasFrozenPanes();
597 : }
598 :
599 : void SAL_CALL
600 0 : ScVbaWindow::setFreezePanes( ::sal_Bool /*_bFreezePanes*/ ) throw (uno::RuntimeException)
601 : {
602 0 : uno::Reference< sheet::XViewPane > xViewPane( getController(), uno::UNO_QUERY_THROW );
603 0 : uno::Reference< sheet::XViewSplitable > xViewSplitable( xViewPane, uno::UNO_QUERY_THROW );
604 0 : uno::Reference< sheet::XViewFreezable > xViewFreezable( xViewPane, uno::UNO_QUERY_THROW );
605 0 : if( xViewSplitable->getIsWindowSplit() )
606 : {
607 : // if there is a split we freeze at the split
608 0 : sal_Int32 nColumn = getSplitColumn();
609 0 : sal_Int32 nRow = getSplitRow();
610 0 : xViewFreezable->freezeAtPosition( nColumn, nRow );
611 : }
612 : else
613 : {
614 : // otherwise we freeze in the center of the visible sheet
615 0 : table::CellRangeAddress aCellRangeAddress = xViewPane->getVisibleRange();
616 0 : sal_Int32 nColumn = aCellRangeAddress.StartColumn + (( aCellRangeAddress.EndColumn - aCellRangeAddress.StartColumn )/2 );
617 0 : sal_Int32 nRow = aCellRangeAddress.StartRow + (( aCellRangeAddress.EndRow - aCellRangeAddress.StartRow )/2 );
618 0 : xViewFreezable->freezeAtPosition( nColumn, nRow );
619 0 : }
620 0 : }
621 :
622 : ::sal_Bool SAL_CALL
623 0 : ScVbaWindow::getSplit() throw (uno::RuntimeException)
624 : {
625 0 : uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
626 0 : return xViewSplitable->getIsWindowSplit();
627 : }
628 :
629 : void SAL_CALL
630 0 : ScVbaWindow::setSplit( ::sal_Bool _bSplit ) throw (uno::RuntimeException)
631 : {
632 0 : if( !_bSplit )
633 : {
634 0 : uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
635 0 : xViewSplitable->splitAtPosition(0,0);
636 : }
637 : else
638 : {
639 0 : uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
640 0 : uno::Reference< excel::XRange > xRange = ActiveCell();
641 0 : sal_Int32 nRow = xRange->getRow();
642 0 : sal_Int32 nColumn = xRange->getColumn();
643 0 : xViewFreezable->freezeAtPosition( nColumn-1, nRow-1 );
644 0 : SplitAtDefinedPosition( sal_True );
645 : }
646 0 : }
647 :
648 : sal_Int32 SAL_CALL
649 0 : ScVbaWindow::getSplitColumn() throw (uno::RuntimeException)
650 : {
651 0 : uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
652 0 : return xViewSplitable->getSplitColumn();
653 : }
654 :
655 : void SAL_CALL
656 0 : ScVbaWindow::setSplitColumn( sal_Int32 _splitcolumn ) throw (uno::RuntimeException)
657 : {
658 0 : if( getSplitColumn() != _splitcolumn )
659 : {
660 0 : uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
661 0 : sal_Bool bFrozen = getFreezePanes();
662 0 : sal_Int32 nRow = getSplitRow();
663 0 : xViewFreezable->freezeAtPosition( _splitcolumn, nRow );
664 0 : SplitAtDefinedPosition( !bFrozen );
665 : }
666 0 : }
667 :
668 : double SAL_CALL
669 0 : ScVbaWindow::getSplitHorizontal() throw (uno::RuntimeException)
670 : {
671 0 : uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
672 0 : return PixelsToPoints( getDevice(), xViewSplitable->getSplitHorizontal(), sal_True );
673 : }
674 :
675 : void SAL_CALL
676 0 : ScVbaWindow::setSplitHorizontal( double _splithorizontal ) throw (uno::RuntimeException)
677 : {
678 0 : uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
679 0 : double fHoriPixels = PointsToPixels( getDevice(), _splithorizontal, sal_True );
680 0 : xViewSplitable->splitAtPosition( static_cast< sal_Int32 >( fHoriPixels ), 0 );
681 0 : }
682 :
683 : sal_Int32 SAL_CALL
684 0 : ScVbaWindow::getSplitRow() throw (uno::RuntimeException)
685 : {
686 0 : uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
687 0 : sal_Int32 nValue = xViewSplitable->getSplitRow();
688 0 : return nValue ? nValue - 1 : nValue;
689 : }
690 :
691 : void SAL_CALL
692 0 : ScVbaWindow::setSplitRow( sal_Int32 _splitrow ) throw (uno::RuntimeException)
693 : {
694 0 : if( getSplitRow() != _splitrow )
695 : {
696 0 : uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
697 0 : sal_Bool bFrozen = getFreezePanes();
698 0 : sal_Int32 nColumn = getSplitColumn();
699 0 : xViewFreezable->freezeAtPosition( nColumn , _splitrow );
700 0 : SplitAtDefinedPosition( !bFrozen );
701 : }
702 0 : }
703 :
704 : double SAL_CALL
705 0 : ScVbaWindow::getSplitVertical() throw (uno::RuntimeException)
706 : {
707 0 : uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
708 0 : return PixelsToPoints( getDevice(), xViewSplitable->getSplitVertical(), sal_False );
709 : }
710 :
711 : void SAL_CALL
712 0 : ScVbaWindow::setSplitVertical(double _splitvertical ) throw (uno::RuntimeException)
713 : {
714 0 : uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
715 0 : double fVertiPixels = PointsToPixels( getDevice(), _splitvertical, sal_False );
716 0 : xViewSplitable->splitAtPosition( 0, static_cast<sal_Int32>( fVertiPixels ) );
717 0 : }
718 :
719 0 : void ScVbaWindow::SplitAtDefinedPosition(sal_Bool _bUnFreezePane)
720 : {
721 0 : uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
722 0 : uno::Reference< sheet::XViewFreezable > xViewFreezable( xViewSplitable, uno::UNO_QUERY_THROW );
723 0 : sal_Int32 nVertSplit = xViewSplitable->getSplitVertical();
724 0 : sal_Int32 nHoriSplit = xViewSplitable->getSplitHorizontal();
725 0 : if( _bUnFreezePane )
726 0 : xViewFreezable->freezeAtPosition(0,0);
727 0 : xViewSplitable->splitAtPosition(nHoriSplit, nVertSplit);
728 0 : }
729 :
730 : uno::Any SAL_CALL
731 0 : ScVbaWindow::getZoom() throw (uno::RuntimeException)
732 : {
733 0 : uno::Reference< beans::XPropertySet > xProps = getControllerProps();
734 0 : rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_ZOOMTYPE ) );
735 0 : sal_Int16 nZoomType = view::DocumentZoomType::PAGE_WIDTH;
736 0 : xProps->getPropertyValue( sName ) >>= nZoomType;
737 0 : if( nZoomType == view::DocumentZoomType::PAGE_WIDTH )
738 : {
739 0 : return uno::makeAny( sal_True );
740 : }
741 0 : else if( nZoomType == view::DocumentZoomType::BY_VALUE )
742 : {
743 0 : sName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(SC_UNO_ZOOMVALUE));
744 0 : sal_Int16 nZoom = 100;
745 0 : xProps->getPropertyValue( sName ) >>= nZoom;
746 0 : return uno::makeAny( nZoom );
747 : }
748 0 : return uno::Any();
749 : }
750 :
751 : void SAL_CALL
752 0 : ScVbaWindow::setZoom( const uno::Any& _zoom ) throw (uno::RuntimeException)
753 : {
754 0 : sal_Int16 nZoom = 100;
755 0 : _zoom >>= nZoom;
756 0 : uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( m_xModel, uno::UNO_QUERY_THROW );
757 0 : uno::Reference< excel::XWorksheet > xActiveSheet = ActiveSheet();
758 0 : SCTAB nTab = 0;
759 0 : if ( !ScVbaWorksheets::nameExists (xSpreadDoc, xActiveSheet->getName(), nTab) )
760 0 : throw uno::RuntimeException();
761 0 : std::vector< SCTAB > vTabs;
762 0 : vTabs.push_back( nTab );
763 0 : excel::implSetZoom( m_xModel, nZoom, vTabs );
764 0 : }
765 :
766 : uno::Reference< excel::XWorksheet > SAL_CALL
767 0 : ScVbaWindow::ActiveSheet( ) throw (script::BasicErrorException, uno::RuntimeException)
768 : {
769 0 : uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
770 0 : return xApplication->getActiveSheet();
771 : }
772 :
773 : uno::Any SAL_CALL
774 0 : ScVbaWindow::getView() throw (uno::RuntimeException)
775 : {
776 : // not supported now
777 0 : sal_Int32 nWindowView = excel::XlWindowView::xlNormalView;
778 0 : return uno::makeAny( nWindowView );
779 : }
780 :
781 : void SAL_CALL
782 0 : ScVbaWindow::setView( const uno::Any& _view) throw (uno::RuntimeException)
783 : {
784 0 : sal_Int32 nWindowView = excel::XlWindowView::xlNormalView;
785 0 : _view >>= nWindowView;
786 0 : sal_uInt16 nSlot = FID_NORMALVIEWMODE;
787 0 : switch ( nWindowView )
788 : {
789 : case excel::XlWindowView::xlNormalView:
790 0 : nSlot = FID_NORMALVIEWMODE;
791 0 : break;
792 : case excel::XlWindowView::xlPageBreakPreview:
793 0 : nSlot = FID_PAGEBREAKMODE;
794 0 : break;
795 : default:
796 0 : DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
797 : }
798 : // !! TODO !! get view shell from controller
799 0 : ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
800 0 : if ( pViewShell )
801 0 : dispatchExecute( pViewShell, nSlot );
802 0 : }
803 :
804 : uno::Reference< excel::XRange > SAL_CALL
805 0 : ScVbaWindow::getVisibleRange() throw (uno::RuntimeException)
806 : {
807 0 : uno::Reference< container::XIndexAccess > xPanesIA( getController(), uno::UNO_QUERY_THROW );
808 0 : uno::Reference< sheet::XViewPane > xTopLeftPane( xPanesIA->getByIndex( 0 ), uno::UNO_QUERY_THROW );
809 0 : uno::Reference< excel::XPane > xPane( new ScVbaPane( this, mxContext, m_xModel, xTopLeftPane ) );
810 0 : return xPane->getVisibleRange();
811 : }
812 :
813 : sal_Int32 SAL_CALL
814 0 : ScVbaWindow::PointsToScreenPixelsX(sal_Int32 _points) throw (css::script::BasicErrorException, css::uno::RuntimeException)
815 : {
816 0 : sal_Int32 nHundredthsofOneMillimeters = Millimeter::getInHundredthsOfOneMillimeter( _points );
817 0 : double fConvertFactor = (getDevice()->getInfo().PixelPerMeterX/100000);
818 0 : return static_cast<sal_Int32>(fConvertFactor * nHundredthsofOneMillimeters );
819 : }
820 :
821 : sal_Int32 SAL_CALL
822 0 : ScVbaWindow::PointsToScreenPixelsY(sal_Int32 _points) throw (css::script::BasicErrorException, css::uno::RuntimeException)
823 : {
824 0 : sal_Int32 nHundredthsofOneMillimeters = Millimeter::getInHundredthsOfOneMillimeter( _points );
825 0 : double fConvertFactor = (getDevice()->getInfo().PixelPerMeterY/100000);
826 0 : return static_cast<sal_Int32>(fConvertFactor * nHundredthsofOneMillimeters );
827 : }
828 :
829 : void SAL_CALL
830 0 : ScVbaWindow::PrintOut( const css::uno::Any& From, const css::uno::Any&To, const css::uno::Any& Copies, const css::uno::Any& Preview, const css::uno::Any& ActivePrinter, const css::uno::Any& PrintToFile, const css::uno::Any& Collate, const css::uno::Any& PrToFileName ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
831 : {
832 : // need test, print current active sheet
833 : // !! TODO !! get view shell from controller
834 0 : PrintOutHelper( excel::getBestViewShell( m_xModel ), From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, sal_True );
835 0 : }
836 :
837 : void SAL_CALL
838 0 : ScVbaWindow::PrintPreview( const css::uno::Any& EnableChanges ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
839 : {
840 : // need test, print preview current active sheet
841 : // !! TODO !! get view shell from controller
842 0 : PrintPreviewHelper( EnableChanges, excel::getBestViewShell( m_xModel ) );
843 0 : }
844 :
845 0 : double SAL_CALL ScVbaWindow::getTabRatio() throw (css::uno::RuntimeException)
846 : {
847 0 : ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
848 0 : if ( pViewShell && pViewShell->GetViewData() && pViewShell->GetViewData()->GetView() )
849 : {
850 0 : double fRatio = pViewShell->GetViewData()->GetView()->GetRelTabBarWidth();
851 0 : if ( fRatio >= 0.0 && fRatio <= 1.0 )
852 0 : return fRatio;
853 : }
854 0 : return 0.0;
855 : }
856 :
857 0 : void SAL_CALL ScVbaWindow::setTabRatio( double fRatio ) throw (css::uno::RuntimeException)
858 : {
859 0 : ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
860 0 : if ( pViewShell && pViewShell->GetViewData() && pViewShell->GetViewData()->GetView() )
861 : {
862 0 : if ( fRatio >= 0.0 && fRatio <= 1.0 )
863 0 : pViewShell->GetViewData()->GetView()->SetRelTabBarWidth( fRatio );
864 : }
865 0 : }
866 :
867 : rtl::OUString
868 0 : ScVbaWindow::getServiceImplName()
869 : {
870 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScVbaWindow"));
871 : }
872 :
873 : uno::Sequence< rtl::OUString >
874 0 : ScVbaWindow::getServiceNames()
875 : {
876 0 : static uno::Sequence< rtl::OUString > aServiceNames;
877 0 : if ( aServiceNames.getLength() == 0 )
878 : {
879 0 : aServiceNames.realloc( 1 );
880 0 : aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Window" ) );
881 : }
882 0 : return aServiceNames;
883 : }
884 : namespace window
885 : {
886 : namespace sdecl = comphelper::service_decl;
887 0 : sdecl::vba_service_class_<ScVbaWindow, sdecl::with_args<true> > serviceImpl;
888 0 : extern sdecl::ServiceDecl const serviceDecl(
889 : serviceImpl,
890 : "ScVbaWindow",
891 : "ooo.vba.excel.Window" );
892 0 : }
893 :
894 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|