1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include "excelvbahelper.hxx"
20 #include "vbawindow.hxx"
21 #include "vbaworksheets.hxx"
22 #include "vbaworksheet.hxx"
23 #include "vbaworkbook.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/sheet/XViewSplitable.hpp>
28 #include <com/sun/star/sheet/XViewFreezable.hpp>
29 #include <com/sun/star/container/XNamed.hpp>
30 #include <com/sun/star/view/DocumentZoomType.hpp>
31 #include <com/sun/star/table/CellRangeAddress.hpp>
32 #include <o3tl/safeint.hxx>
33 #include <ooo/vba/excel/XApplication.hpp>
34 #include <ooo/vba/excel/XlWindowState.hpp>
35 #include <ooo/vba/excel/XlWindowView.hpp>
36 #include <basic/sberrors.hxx>
37 #include <comphelper/sequence.hxx>
38 #include <cppuhelper/implbase.hxx>
41 #include <tabvwsh.hxx>
44 #include <sfx2/viewfrm.hxx>
46 #include <vcl/wrkwin.hxx>
47 #include <unonames.hxx>
48 #include <markdata.hxx>
49 #include <unordered_map>
51 using namespace ::com::sun::star
;
52 using namespace ::ooo::vba
;
53 using namespace ::ooo::vba::excel::XlWindowState
;
55 typedef std::unordered_map
< OUString
,
56 SCTAB
> NameIndexHash
;
58 typedef std::vector
< uno::Reference
< sheet::XSpreadsheet
> > Sheets
;
60 typedef ::cppu::WeakImplHelper
< container::XEnumerationAccess
61 , css::container::XIndexAccess
62 , css::container::XNameAccess
63 > SelectedSheets_BASE
;
67 class SelectedSheetsEnum
: public ::cppu::WeakImplHelper
< container::XEnumeration
>
70 uno::Reference
< uno::XComponentContext
> m_xContext
;
72 uno::Reference
< frame::XModel
> m_xModel
;
73 Sheets::const_iterator m_it
;
75 /// @throws uno::RuntimeException
76 SelectedSheetsEnum( uno::Reference
< uno::XComponentContext
> xContext
, Sheets
&& sheets
, uno::Reference
< frame::XModel
> xModel
)
77 : m_xContext(std::move( xContext
)), m_sheets( std::move(sheets
) ), m_xModel(std::move( xModel
))
79 m_it
= m_sheets
.begin();
82 virtual sal_Bool SAL_CALL
hasMoreElements( ) override
84 return m_it
!= m_sheets
.end();
86 virtual uno::Any SAL_CALL
nextElement( ) override
88 if ( !hasMoreElements() )
90 throw container::NoSuchElementException();
92 // #FIXME needs ThisWorkbook as parent
93 return uno::Any( uno::Reference
< excel::XWorksheet
> ( new ScVbaWorksheet( uno::Reference
< XHelperInterface
>(), m_xContext
, *(m_it
++), m_xModel
) ) );
98 class SelectedSheetsEnumAccess
: public SelectedSheets_BASE
100 uno::Reference
< uno::XComponentContext
> m_xContext
;
101 NameIndexHash namesToIndices
;
103 rtl::Reference
< ScModelObj
> m_xModel
;
105 SelectedSheetsEnumAccess( uno::Reference
< uno::XComponentContext
> xContext
, const uno::Reference
< frame::XModel
> & xModel
):m_xContext(std::move( xContext
))
107 ScModelObj
* pModel
= static_cast< ScModelObj
* >( xModel
.get() );
109 throw uno::RuntimeException(u
"Cannot obtain current document"_ustr
);
111 ScDocShell
* pDocShell
= static_cast<ScDocShell
*>(pModel
->GetEmbeddedObject());
113 throw uno::RuntimeException(u
"Cannot obtain docshell"_ustr
);
114 ScTabViewShell
* pViewShell
= excel::getBestViewShell( m_xModel
);
116 throw uno::RuntimeException(u
"Cannot obtain view shell"_ustr
);
118 SCTAB nTabCount
= pDocShell
->GetDocument().GetTableCount();
120 const ScMarkData
& rMarkData
= pViewShell
->GetViewData().GetMarkData();
121 sheets
.reserve( nTabCount
);
122 uno::Reference
<container::XIndexAccess
> xIndex( m_xModel
->getSheets(), uno::UNO_QUERY_THROW
);
123 for (const auto& rTab
: rMarkData
)
125 if (rTab
>= nTabCount
)
127 uno::Reference
< sheet::XSpreadsheet
> xSheet( xIndex
->getByIndex( rTab
), uno::UNO_QUERY_THROW
);
128 uno::Reference
< container::XNamed
> xNamed( xSheet
, uno::UNO_QUERY_THROW
);
129 sheets
.push_back( xSheet
);
130 namesToIndices
[ xNamed
->getName() ] = nIndex
++;
136 virtual uno::Reference
< container::XEnumeration
> SAL_CALL
createEnumeration( ) override
138 return new SelectedSheetsEnum( m_xContext
, std::vector(sheets
), m_xModel
);
141 virtual ::sal_Int32 SAL_CALL
getCount( ) override
143 return sheets
.size();
145 virtual uno::Any SAL_CALL
getByIndex( ::sal_Int32 Index
) override
148 || o3tl::make_unsigned( Index
) >= sheets
.size() )
149 throw lang::IndexOutOfBoundsException();
151 return uno::Any( sheets
[ Index
] );
155 virtual uno::Type SAL_CALL
getElementType( ) override
157 return cppu::UnoType
<excel::XWorksheet
>::get();
160 virtual sal_Bool SAL_CALL
hasElements( ) override
162 return ( !sheets
.empty() );
166 virtual uno::Any SAL_CALL
getByName( const OUString
& aName
) override
168 NameIndexHash::const_iterator it
= namesToIndices
.find( aName
);
169 if ( it
== namesToIndices
.end() )
170 throw container::NoSuchElementException();
171 return uno::Any( sheets
[ it
->second
] );
175 virtual uno::Sequence
< OUString
> SAL_CALL
getElementNames( ) override
177 return comphelper::mapKeysToSequence( namesToIndices
);
180 virtual sal_Bool SAL_CALL
hasByName( const OUString
& aName
) override
182 NameIndexHash::const_iterator it
= namesToIndices
.find( aName
);
183 return (it
!= namesToIndices
.end());
190 ScVbaWindow::ScVbaWindow(
191 const uno::Reference
< XHelperInterface
>& xParent
,
192 const uno::Reference
< uno::XComponentContext
>& xContext
,
193 const uno::Reference
< frame::XModel
>& xModel
,
194 const uno::Reference
< frame::XController
>& xController
) :
195 WindowImpl_BASE( xParent
, xContext
, xModel
, xController
)
200 ScVbaWindow::ScVbaWindow(
201 const uno::Sequence
< uno::Any
>& args
,
202 const uno::Reference
< uno::XComponentContext
>& xContext
) :
203 WindowImpl_BASE( args
, xContext
)
211 /* This method is called from the constructor, thus the own refcount is
212 still zero. The implementation of ActivePane() uses a UNO reference of
213 this (to set this window as parent of the pane object). This requires
214 the own refcount to be non-zero, otherwise this instance will be
215 destructed immediately! Guard the call to ActivePane() in try/catch to
216 not miss the decrementation of the reference count on exception. */
217 osl_atomic_increment( &m_refCount
);
220 m_xPane
= ActivePane();
222 catch( uno::Exception
& )
225 osl_atomic_decrement( &m_refCount
);
228 uno::Reference
< beans::XPropertySet
>
229 ScVbaWindow::getControllerProps() const
231 return uno::Reference
< beans::XPropertySet
>( getController(), uno::UNO_QUERY_THROW
);
234 uno::Reference
< beans::XPropertySet
>
235 ScVbaWindow::getFrameProps() const
237 return uno::Reference
< beans::XPropertySet
>( getController()->getFrame(), uno::UNO_QUERY_THROW
);
240 uno::Reference
< awt::XDevice
>
241 ScVbaWindow::getDevice() const
243 return uno::Reference
< awt::XDevice
>( getWindow(), uno::UNO_QUERY_THROW
);
247 ScVbaWindow::Scroll( const uno::Any
& Down
, const uno::Any
& Up
, const uno::Any
& ToRight
, const uno::Any
& ToLeft
, bool bLargeScroll
)
250 throw uno::RuntimeException();
252 m_xPane
->LargeScroll( Down
, Up
, ToRight
, ToLeft
);
254 m_xPane
->SmallScroll( Down
, Up
, ToRight
, ToLeft
);
258 ScVbaWindow::SmallScroll( const uno::Any
& Down
, const uno::Any
& Up
, const uno::Any
& ToRight
, const uno::Any
& ToLeft
)
260 Scroll( Down
, Up
, ToRight
, ToLeft
, false );
264 ScVbaWindow::LargeScroll( const uno::Any
& Down
, const uno::Any
& Up
, const uno::Any
& ToRight
, const uno::Any
& ToLeft
)
266 Scroll( Down
, Up
, ToRight
, ToLeft
, true );
270 ScVbaWindow::SelectedSheets( const uno::Any
& aIndex
)
272 uno::Reference
< container::XEnumerationAccess
> xEnumAccess( new SelectedSheetsEnumAccess( mxContext
, m_xModel
) );
273 // #FIXME needs a workbook as a parent
274 uno::Reference
< excel::XWorksheets
> xSheets( new ScVbaWorksheets( uno::Reference
< XHelperInterface
>(), mxContext
, xEnumAccess
, m_xModel
) );
275 if ( aIndex
.hasValue() )
277 uno::Reference
< XCollection
> xColl( xSheets
, uno::UNO_QUERY_THROW
);
278 return xColl
->Item( aIndex
, uno::Any() );
280 return uno::Any( xSheets
);
284 ScVbaWindow::ScrollWorkbookTabs( const uno::Any
& /*Sheets*/, const uno::Any
& /*Position*/ )
286 // #TODO #FIXME need some implementation to scroll through the tabs
287 // but where is this done?
289 sal_Int32 nSheets = 0;
290 sal_Int32 nPosition = 0;
291 throw uno::RuntimeException("No Implemented" );
292 sal_Bool bSheets = ( Sheets >>= nSheets );
293 sal_Bool bPosition = ( Position >>= nPosition );
294 if ( bSheets || bPosition ) // at least one param specified
297 else if ( bPosition )
304 ScVbaWindow::getCaption()
306 // tdf#118129 - return only the caption property of the frame
308 getFrameProps()->getPropertyValue(SC_UNONAME_TITLE
) >>= sTitle
;
309 return uno::Any( sTitle
);
313 ScVbaWindow::setCaption( const uno::Any
& _caption
)
315 getFrameProps()->setPropertyValue( SC_UNONAME_TITLE
, _caption
);
319 ScVbaWindow::getScrollRow()
321 sal_Int32 nValue
= 0;
322 // !! TODO !! get view shell from controller
323 ScTabViewShell
* pViewShell
= excel::getBestViewShell( m_xModel
);
326 ScSplitPos eWhich
= pViewShell
->GetViewData().GetActivePart();
327 nValue
= pViewShell
->GetViewData().GetPosY(WhichV(eWhich
));
330 return uno::Any( nValue
+ 1);
334 ScVbaWindow::setScrollRow( const uno::Any
& _scrollrow
)
336 // !! TODO !! get view shell from controller
337 ScTabViewShell
* pViewShell
= excel::getBestViewShell( m_xModel
);
340 sal_Int32 scrollRow
= 0;
341 _scrollrow
>>= scrollRow
;
342 ScSplitPos eWhich
= pViewShell
->GetViewData().GetActivePart();
343 sal_Int32 nOldValue
= pViewShell
->GetViewData().GetPosY(WhichV(eWhich
)) + 1;
344 pViewShell
->ScrollLines(0, scrollRow
- nOldValue
);
349 ScVbaWindow::getScrollColumn()
351 sal_Int32 nValue
= 0;
352 // !! TODO !! get view shell from controller
353 ScTabViewShell
* pViewShell
= excel::getBestViewShell( m_xModel
);
356 ScSplitPos eWhich
= pViewShell
->GetViewData().GetActivePart();
357 nValue
= pViewShell
->GetViewData().GetPosX(WhichH(eWhich
));
360 return uno::Any( nValue
+ 1);
364 ScVbaWindow::setScrollColumn( const uno::Any
& _scrollcolumn
)
366 // !! TODO !! get view shell from controller
367 ScTabViewShell
* pViewShell
= excel::getBestViewShell( m_xModel
);
370 sal_Int32 scrollColumn
= 0;
371 _scrollcolumn
>>= scrollColumn
;
372 ScSplitPos eWhich
= pViewShell
->GetViewData().GetActivePart();
373 sal_Int32 nOldValue
= pViewShell
->GetViewData().GetPosX(WhichH(eWhich
)) + 1;
374 pViewShell
->ScrollLines(scrollColumn
- nOldValue
, 0);
379 ScVbaWindow::getWindowState()
381 sal_Int32 nwindowState
= xlNormal
;
382 // !! TODO !! get view shell from controller
383 if (ScTabViewShell
* pViewShell
= excel::getBestViewShell( m_xModel
))
385 SfxViewFrame
& rViewFrame
= pViewShell
->GetViewFrame();
386 WorkWindow
* pWork
= static_cast<WorkWindow
*>( rViewFrame
.GetFrame().GetSystemWindow() );
389 if ( pWork
-> IsMaximized())
390 nwindowState
= xlMaximized
;
391 else if (pWork
-> IsMinimized())
392 nwindowState
= xlMinimized
;
395 return uno::Any( nwindowState
);
399 ScVbaWindow::setWindowState( const uno::Any
& _windowstate
)
401 sal_Int32 nwindowState
= xlMaximized
;
402 _windowstate
>>= nwindowState
;
403 // !! TODO !! get view shell from controller
404 if (ScTabViewShell
* pViewShell
= excel::getBestViewShell( m_xModel
))
406 SfxViewFrame
& rViewFrame
= pViewShell
->GetViewFrame();
407 WorkWindow
* pWork
= static_cast<WorkWindow
*>( rViewFrame
.GetFrame().GetSystemWindow() );
410 if ( nwindowState
== xlMaximized
)
412 else if (nwindowState
== xlMinimized
)
414 else if (nwindowState
== xlNormal
)
417 throw uno::RuntimeException(u
"Invalid Parameter"_ustr
);
423 ScVbaWindow::Activate()
425 rtl::Reference
<ScVbaWorkbook
> workbook( new ScVbaWorkbook( uno::Reference
< XHelperInterface
>( Application(), uno::UNO_QUERY_THROW
), mxContext
, m_xModel
) );
427 workbook
->Activate();
431 ScVbaWindow::Close( const uno::Any
& SaveChanges
, const uno::Any
& FileName
, const uno::Any
& RouteWorkBook
)
433 rtl::Reference
< ScVbaWorkbook
> workbook( new ScVbaWorkbook( uno::Reference
< XHelperInterface
>( Application(), uno::UNO_QUERY_THROW
), mxContext
, m_xModel
) );
434 workbook
->Close(SaveChanges
, FileName
, RouteWorkBook
);
437 uno::Reference
< excel::XPane
> SAL_CALL
438 ScVbaWindow::ActivePane()
440 uno::Reference
< sheet::XViewPane
> xViewPane( getController(), uno::UNO_QUERY_THROW
);
441 return new ScVbaPane( this, mxContext
, m_xModel
, xViewPane
);
444 uno::Reference
< excel::XRange
> SAL_CALL
445 ScVbaWindow::ActiveCell( )
447 uno::Reference
< excel::XApplication
> xApplication( Application(), uno::UNO_QUERY_THROW
);
448 return xApplication
->getActiveCell();
452 ScVbaWindow::Selection( )
454 uno::Reference
< excel::XApplication
> xApplication( Application(), uno::UNO_QUERY_THROW
);
455 return xApplication
->getSelection();
458 uno::Reference
< excel::XRange
> SAL_CALL
459 ScVbaWindow::RangeSelection()
461 /* TODO / FIXME: According to documentation, this method returns the range
462 selection even if shapes are selected. */
463 return uno::Reference
< excel::XRange
>( Selection(), uno::UNO_QUERY_THROW
);
467 ScVbaWindow::getDisplayGridlines()
470 getControllerProps()->getPropertyValue( SC_UNO_SHOWGRID
) >>= bGrid
;
475 ScVbaWindow::setDisplayGridlines( sal_Bool _displaygridlines
)
477 getControllerProps()->setPropertyValue( SC_UNO_SHOWGRID
, uno::Any( _displaygridlines
));
481 ScVbaWindow::getDisplayHeadings()
483 bool bHeading
= true;
484 getControllerProps()->getPropertyValue( SC_UNO_COLROWHDR
) >>= bHeading
;
489 ScVbaWindow::setDisplayHeadings( sal_Bool _bDisplayHeadings
)
491 getControllerProps()->setPropertyValue( SC_UNO_COLROWHDR
, uno::Any( _bDisplayHeadings
));
495 ScVbaWindow::getDisplayHorizontalScrollBar()
497 bool bHorizontalScrollBar
= true;
498 getControllerProps()->getPropertyValue( SC_UNO_HORSCROLL
) >>= bHorizontalScrollBar
;
499 return bHorizontalScrollBar
;
503 ScVbaWindow::setDisplayHorizontalScrollBar( sal_Bool _bDisplayHorizontalScrollBar
)
505 getControllerProps()->setPropertyValue( SC_UNO_HORSCROLL
, uno::Any( _bDisplayHorizontalScrollBar
));
509 ScVbaWindow::getDisplayOutline()
511 bool bOutline
= true;
512 getControllerProps()->getPropertyValue( SC_UNO_OUTLSYMB
) >>= bOutline
;
517 ScVbaWindow::setDisplayOutline( sal_Bool _bDisplayOutline
)
519 getControllerProps()->setPropertyValue( SC_UNO_OUTLSYMB
, uno::Any( _bDisplayOutline
));
523 ScVbaWindow::getDisplayVerticalScrollBar()
525 bool bVerticalScrollBar
= true;
526 getControllerProps()->getPropertyValue( SC_UNO_VERTSCROLL
) >>= bVerticalScrollBar
;
527 return bVerticalScrollBar
;
531 ScVbaWindow::setDisplayVerticalScrollBar( sal_Bool _bDisplayVerticalScrollBar
)
533 getControllerProps()->setPropertyValue( SC_UNO_VERTSCROLL
, uno::Any( _bDisplayVerticalScrollBar
));
537 ScVbaWindow::getDisplayWorkbookTabs()
539 bool bWorkbookTabs
= true;
540 getControllerProps()->getPropertyValue( SC_UNO_SHEETTABS
) >>= bWorkbookTabs
;
541 return bWorkbookTabs
;
545 ScVbaWindow::setDisplayWorkbookTabs( sal_Bool _bDisplayWorkbookTabs
)
547 getControllerProps()->setPropertyValue( SC_UNO_SHEETTABS
, uno::Any( _bDisplayWorkbookTabs
));
551 ScVbaWindow::getFreezePanes()
553 uno::Reference
< sheet::XViewFreezable
> xViewFreezable( getController(), uno::UNO_QUERY_THROW
);
554 return xViewFreezable
->hasFrozenPanes();
558 ScVbaWindow::setFreezePanes( sal_Bool _bFreezePanes
)
560 uno::Reference
< sheet::XViewPane
> xViewPane( getController(), uno::UNO_QUERY_THROW
);
561 uno::Reference
< sheet::XViewSplitable
> xViewSplitable( xViewPane
, uno::UNO_QUERY_THROW
);
562 uno::Reference
< sheet::XViewFreezable
> xViewFreezable( xViewPane
, uno::UNO_QUERY_THROW
);
565 if( xViewSplitable
->getIsWindowSplit() )
567 // if there is a split we freeze at the split
568 sal_Int32 nColumn
= getSplitColumn();
569 sal_Int32 nRow
= getSplitRow();
570 xViewFreezable
->freezeAtPosition( nColumn
, nRow
);
574 // otherwise we freeze in the center of the visible sheet
575 table::CellRangeAddress aCellRangeAddress
= xViewPane
->getVisibleRange();
576 sal_Int32 nColumn
= aCellRangeAddress
.StartColumn
+ (( aCellRangeAddress
.EndColumn
- aCellRangeAddress
.StartColumn
)/2 );
577 sal_Int32 nRow
= aCellRangeAddress
.StartRow
+ (( aCellRangeAddress
.EndRow
- aCellRangeAddress
.StartRow
)/2 );
578 xViewFreezable
->freezeAtPosition( nColumn
, nRow
);
583 //remove the freeze panes
584 xViewSplitable
->splitAtPosition(0,0);
589 ScVbaWindow::getSplit()
591 uno::Reference
< sheet::XViewSplitable
> xViewSplitable( getController(), uno::UNO_QUERY_THROW
);
592 return xViewSplitable
->getIsWindowSplit();
596 ScVbaWindow::setSplit( sal_Bool _bSplit
)
600 uno::Reference
< sheet::XViewSplitable
> xViewSplitable( getController(), uno::UNO_QUERY_THROW
);
601 xViewSplitable
->splitAtPosition(0,0);
605 uno::Reference
< sheet::XViewFreezable
> xViewFreezable( getController(), uno::UNO_QUERY_THROW
);
606 uno::Reference
< excel::XRange
> xRange
= ActiveCell();
607 sal_Int32 nRow
= xRange
->getRow();
608 sal_Int32 nColumn
= xRange
->getColumn();
609 SplitAtDefinedPosition( nColumn
-1, nRow
-1 );
614 ScVbaWindow::getSplitColumn()
616 uno::Reference
< sheet::XViewSplitable
> xViewSplitable( getController(), uno::UNO_QUERY_THROW
);
617 return xViewSplitable
->getSplitColumn();
621 ScVbaWindow::setSplitColumn( sal_Int32 _splitcolumn
)
623 if( getSplitColumn() != _splitcolumn
)
625 uno::Reference
< sheet::XViewFreezable
> xViewFreezable( getController(), uno::UNO_QUERY_THROW
);
626 sal_Int32 nRow
= getSplitRow();
627 SplitAtDefinedPosition( _splitcolumn
, nRow
);
632 ScVbaWindow::getSplitHorizontal()
634 uno::Reference
< sheet::XViewSplitable
> xViewSplitable( getController(), uno::UNO_QUERY_THROW
);
635 return PixelsToPoints( getDevice(), xViewSplitable
->getSplitHorizontal(), true );
639 ScVbaWindow::setSplitHorizontal( double _splithorizontal
)
641 uno::Reference
< sheet::XViewSplitable
> xViewSplitable( getController(), uno::UNO_QUERY_THROW
);
642 double fHoriPixels
= PointsToPixels( getDevice(), _splithorizontal
, true );
643 xViewSplitable
->splitAtPosition( static_cast< sal_Int32
>( fHoriPixels
), 0 );
647 ScVbaWindow::getSplitRow()
649 uno::Reference
< sheet::XViewSplitable
> xViewSplitable( getController(), uno::UNO_QUERY_THROW
);
650 return xViewSplitable
->getSplitRow();
654 ScVbaWindow::setSplitRow( sal_Int32 _splitrow
)
656 if( getSplitRow() != _splitrow
)
658 uno::Reference
< sheet::XViewFreezable
> xViewFreezable( getController(), uno::UNO_QUERY_THROW
);
659 sal_Int32 nColumn
= getSplitColumn();
660 SplitAtDefinedPosition( nColumn
, _splitrow
);
665 ScVbaWindow::getSplitVertical()
667 uno::Reference
< sheet::XViewSplitable
> xViewSplitable( getController(), uno::UNO_QUERY_THROW
);
668 return PixelsToPoints( getDevice(), xViewSplitable
->getSplitVertical(), false );
672 ScVbaWindow::setSplitVertical(double _splitvertical
)
674 uno::Reference
< sheet::XViewSplitable
> xViewSplitable( getController(), uno::UNO_QUERY_THROW
);
675 double fVertiPixels
= PointsToPixels( getDevice(), _splitvertical
, false );
676 xViewSplitable
->splitAtPosition( 0, static_cast<sal_Int32
>( fVertiPixels
) );
679 void ScVbaWindow::SplitAtDefinedPosition( sal_Int32 nColumns
, sal_Int32 nRows
)
681 uno::Reference
< sheet::XViewSplitable
> xViewSplitable( getController(), uno::UNO_QUERY_THROW
);
682 uno::Reference
< sheet::XViewFreezable
> xViewFreezable( xViewSplitable
, uno::UNO_QUERY_THROW
);
683 // nColumns and nRows means split columns/rows
684 if( nColumns
== 0 && nRows
== 0 )
687 sal_Int32 cellColumn
= nColumns
+ 1;
688 sal_Int32 cellRow
= nRows
+ 1;
690 ScTabViewShell
* pViewShell
= excel::getBestViewShell( m_xModel
);
693 //firstly remove the old splitter
694 xViewSplitable
->splitAtPosition(0,0);
696 uno::Reference
< excel::XApplication
> xApplication( Application(), uno::UNO_QUERY_THROW
);
697 uno::Reference
< excel::XWorksheet
> xSheet( xApplication
->getActiveSheet(), uno::UNO_SET_THROW
);
698 xSheet
->Cells(uno::Any(cellRow
), uno::Any(cellColumn
))->Select();
700 //pViewShell->FreezeSplitters( FALSE );
701 dispatchExecute( pViewShell
, SID_WINDOW_SPLIT
);
706 ScVbaWindow::getZoom()
708 uno::Reference
< beans::XPropertySet
> xProps
= getControllerProps();
709 OUString
sName( SC_UNO_ZOOMTYPE
);
710 sal_Int16 nZoomType
= view::DocumentZoomType::PAGE_WIDTH
;
711 xProps
->getPropertyValue( sName
) >>= nZoomType
;
712 if( nZoomType
== view::DocumentZoomType::PAGE_WIDTH
)
714 return uno::Any( true );
716 else if( nZoomType
== view::DocumentZoomType::BY_VALUE
)
718 sName
= SC_UNO_ZOOMVALUE
;
719 sal_Int16 nZoom
= 100;
720 xProps
->getPropertyValue( sName
) >>= nZoom
;
721 return uno::Any( nZoom
);
726 void SAL_CALL
ScVbaWindow::setZoom(const uno::Any
& _zoom
)
728 sal_Int16 nZoom
= 100;
730 uno::Reference
<sheet::XSpreadsheetDocument
> xSpreadDoc( m_xModel
, uno::UNO_QUERY_THROW
);
731 uno::Reference
< excel::XWorksheet
> xActiveSheet
= ActiveSheet();
733 if ( !ScVbaWorksheets::nameExists (xSpreadDoc
, xActiveSheet
->getName(), nTab
) )
734 throw uno::RuntimeException();
735 std::vector
< SCTAB
> vTabs
{ nTab
};
736 excel::implSetZoom( m_xModel
, nZoom
, vTabs
);
739 uno::Reference
< excel::XWorksheet
> SAL_CALL
740 ScVbaWindow::ActiveSheet( )
742 uno::Reference
< excel::XApplication
> xApplication( Application(), uno::UNO_QUERY_THROW
);
743 return xApplication
->getActiveSheet();
747 ScVbaWindow::getView()
749 bool bPageBreak
= false;
750 sal_Int32 nWindowView
= excel::XlWindowView::xlNormalView
;
752 ScTabViewShell
* pViewShell
= excel::getBestViewShell( m_xModel
);
754 bPageBreak
= pViewShell
->GetViewData().IsPagebreakMode();
757 nWindowView
= excel::XlWindowView::xlPageBreakPreview
;
759 nWindowView
= excel::XlWindowView::xlNormalView
;
761 return uno::Any( nWindowView
);
765 ScVbaWindow::setView( const uno::Any
& _view
)
767 sal_Int32 nWindowView
= excel::XlWindowView::xlNormalView
;
768 _view
>>= nWindowView
;
769 sal_uInt16 nSlot
= FID_NORMALVIEWMODE
;
770 switch ( nWindowView
)
772 case excel::XlWindowView::xlNormalView
:
773 nSlot
= FID_NORMALVIEWMODE
;
775 case excel::XlWindowView::xlPageBreakPreview
:
776 nSlot
= FID_PAGEBREAKMODE
;
779 DebugHelper::runtimeexception(ERRCODE_BASIC_BAD_PARAMETER
);
781 // !! TODO !! get view shell from controller
782 ScTabViewShell
* pViewShell
= excel::getBestViewShell( m_xModel
);
784 dispatchExecute( pViewShell
, nSlot
);
787 uno::Reference
< excel::XRange
> SAL_CALL
788 ScVbaWindow::getVisibleRange()
790 uno::Reference
< container::XIndexAccess
> xPanesIA( getController(), uno::UNO_QUERY_THROW
);
791 uno::Reference
< sheet::XViewPane
> xTopLeftPane( xPanesIA
->getByIndex( 0 ), uno::UNO_QUERY_THROW
);
792 uno::Reference
< excel::XPane
> xPane( new ScVbaPane( this, mxContext
, m_xModel
, xTopLeftPane
) );
793 return xPane
->getVisibleRange();
797 ScVbaWindow::PointsToScreenPixelsX(sal_Int32 _points
)
799 sal_Int32 nHundredthsofOneMillimeters
= Millimeter::getInHundredthsOfOneMillimeter( _points
);
800 double fConvertFactor
= getDevice()->getInfo().PixelPerMeterX
/100000;
801 return static_cast<sal_Int32
>(fConvertFactor
* nHundredthsofOneMillimeters
);
805 ScVbaWindow::PointsToScreenPixelsY(sal_Int32 _points
)
807 sal_Int32 nHundredthsofOneMillimeters
= Millimeter::getInHundredthsOfOneMillimeter( _points
);
808 double fConvertFactor
= getDevice()->getInfo().PixelPerMeterY
/100000;
809 return static_cast<sal_Int32
>(fConvertFactor
* nHundredthsofOneMillimeters
);
813 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
)
815 // need test, print current active sheet
816 // !! TODO !! get view shell from controller
817 PrintOutHelper( excel::getBestViewShell( m_xModel
), From
, To
, Copies
, Preview
, ActivePrinter
, PrintToFile
, Collate
, PrToFileName
, true );
821 ScVbaWindow::PrintPreview( const css::uno::Any
& EnableChanges
)
823 // need test, print preview current active sheet
824 // !! TODO !! get view shell from controller
825 PrintPreviewHelper( EnableChanges
, excel::getBestViewShell( m_xModel
) );
828 double SAL_CALL
ScVbaWindow::getTabRatio()
830 ScTabViewShell
* pViewShell
= excel::getBestViewShell( m_xModel
);
831 if ( pViewShell
&& pViewShell
->GetViewData().GetView() )
833 double fRatio
= ScTabView::GetRelTabBarWidth();
834 if ( fRatio
>= 0.0 && fRatio
<= 1.0 )
840 void SAL_CALL
ScVbaWindow::setTabRatio( double fRatio
)
842 ScTabViewShell
* pViewShell
= excel::getBestViewShell( m_xModel
);
843 if ( pViewShell
&& pViewShell
->GetViewData().GetView() )
845 if ( fRatio
>= 0.0 && fRatio
<= 1.0 )
846 pViewShell
->GetViewData().GetView()->SetRelTabBarWidth( fRatio
);
851 ScVbaWindow::getServiceImplName()
853 return u
"ScVbaWindow"_ustr
;
856 uno::Sequence
< OUString
>
857 ScVbaWindow::getServiceNames()
859 static uno::Sequence
< OUString
> const aServiceNames
861 u
"ooo.vba.excel.Window"_ustr
863 return aServiceNames
;
866 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
867 Calc_ScVbaWindow_get_implementation(
868 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const& args
)
870 return cppu::acquire(new ScVbaWindow(args
, context
));
873 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */