tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / vba / vbawindow.cxx
blob2c860eadcf865fcd14732a317acc20f98ae2dcbc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
40 #include <docsh.hxx>
41 #include <tabvwsh.hxx>
42 #include <docuno.hxx>
43 #include <sc.hrc>
44 #include <sfx2/viewfrm.hxx>
45 #include <utility>
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;
65 namespace {
67 class SelectedSheetsEnum : public ::cppu::WeakImplHelper< container::XEnumeration >
69 public:
70 uno::Reference< uno::XComponentContext > m_xContext;
71 Sheets m_sheets;
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();
81 // XEnumeration
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;
102 Sheets sheets;
103 rtl::Reference< ScModelObj > m_xModel;
104 public:
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() );
108 if ( !pModel )
109 throw uno::RuntimeException(u"Cannot obtain current document"_ustr );
110 m_xModel = pModel;
111 ScDocShell* pDocShell = static_cast<ScDocShell*>(pModel->GetEmbeddedObject());
112 if ( !pDocShell )
113 throw uno::RuntimeException(u"Cannot obtain docshell"_ustr );
114 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
115 if ( !pViewShell )
116 throw uno::RuntimeException(u"Cannot obtain view shell"_ustr );
118 SCTAB nTabCount = pDocShell->GetDocument().GetTableCount();
119 SCTAB nIndex = 0;
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)
126 break;
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++;
135 //XEnumerationAccess
136 virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) override
138 return new SelectedSheetsEnum( m_xContext, std::vector(sheets), m_xModel );
140 // XIndexAccess
141 virtual ::sal_Int32 SAL_CALL getCount( ) override
143 return sheets.size();
145 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) override
147 if ( Index < 0
148 || o3tl::make_unsigned( Index ) >= sheets.size() )
149 throw lang::IndexOutOfBoundsException();
151 return uno::Any( sheets[ Index ] );
154 //XElementAccess
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() );
165 //XNameAccess
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 )
197 init();
200 ScVbaWindow::ScVbaWindow(
201 const uno::Sequence< uno::Any >& args,
202 const uno::Reference< uno::XComponentContext >& xContext ) :
203 WindowImpl_BASE( args, xContext )
205 init();
208 void
209 ScVbaWindow::init()
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 );
246 void
247 ScVbaWindow::Scroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft, bool bLargeScroll )
249 if( !m_xPane.is() )
250 throw uno::RuntimeException();
251 if( bLargeScroll )
252 m_xPane->LargeScroll( Down, Up, ToRight, ToLeft );
253 else
254 m_xPane->SmallScroll( Down, Up, ToRight, ToLeft );
257 void SAL_CALL
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 );
263 void SAL_CALL
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 );
269 uno::Any SAL_CALL
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 );
283 void SAL_CALL
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
295 if ( bSheets )
296 ;// use sheets
297 else if ( bPosition )
298 ; //use position
303 uno::Any SAL_CALL
304 ScVbaWindow::getCaption()
306 // tdf#118129 - return only the caption property of the frame
307 OUString sTitle;
308 getFrameProps()->getPropertyValue(SC_UNONAME_TITLE) >>= sTitle;
309 return uno::Any( sTitle );
312 void SAL_CALL
313 ScVbaWindow::setCaption( const uno::Any& _caption )
315 getFrameProps()->setPropertyValue( SC_UNONAME_TITLE, _caption );
318 uno::Any SAL_CALL
319 ScVbaWindow::getScrollRow()
321 sal_Int32 nValue = 0;
322 // !! TODO !! get view shell from controller
323 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
324 if ( pViewShell )
326 ScSplitPos eWhich = pViewShell->GetViewData().GetActivePart();
327 nValue = pViewShell->GetViewData().GetPosY(WhichV(eWhich));
330 return uno::Any( nValue + 1);
333 void SAL_CALL
334 ScVbaWindow::setScrollRow( const uno::Any& _scrollrow )
336 // !! TODO !! get view shell from controller
337 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
338 if ( pViewShell )
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);
348 uno::Any SAL_CALL
349 ScVbaWindow::getScrollColumn()
351 sal_Int32 nValue = 0;
352 // !! TODO !! get view shell from controller
353 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
354 if ( pViewShell )
356 ScSplitPos eWhich = pViewShell->GetViewData().GetActivePart();
357 nValue = pViewShell->GetViewData().GetPosX(WhichH(eWhich));
360 return uno::Any( nValue + 1);
363 void SAL_CALL
364 ScVbaWindow::setScrollColumn( const uno::Any& _scrollcolumn )
366 // !! TODO !! get view shell from controller
367 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
368 if ( pViewShell )
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);
378 uno::Any SAL_CALL
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() );
387 if ( pWork )
389 if ( pWork -> IsMaximized())
390 nwindowState = xlMaximized;
391 else if (pWork -> IsMinimized())
392 nwindowState = xlMinimized;
395 return uno::Any( nwindowState );
398 void SAL_CALL
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() );
408 if ( pWork )
410 if ( nwindowState == xlMaximized)
411 pWork -> Maximize();
412 else if (nwindowState == xlMinimized)
413 pWork -> Minimize();
414 else if (nwindowState == xlNormal)
415 pWork -> Restore();
416 else
417 throw uno::RuntimeException(u"Invalid Parameter"_ustr );
422 void
423 ScVbaWindow::Activate()
425 rtl::Reference<ScVbaWorkbook> workbook( new ScVbaWorkbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel ) );
427 workbook->Activate();
430 void
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();
451 uno::Any SAL_CALL
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 );
466 sal_Bool SAL_CALL
467 ScVbaWindow::getDisplayGridlines()
469 bool bGrid = true;
470 getControllerProps()->getPropertyValue( SC_UNO_SHOWGRID ) >>= bGrid;
471 return bGrid;
474 void SAL_CALL
475 ScVbaWindow::setDisplayGridlines( sal_Bool _displaygridlines )
477 getControllerProps()->setPropertyValue( SC_UNO_SHOWGRID, uno::Any( _displaygridlines ));
480 sal_Bool SAL_CALL
481 ScVbaWindow::getDisplayHeadings()
483 bool bHeading = true;
484 getControllerProps()->getPropertyValue( SC_UNO_COLROWHDR ) >>= bHeading;
485 return bHeading;
488 void SAL_CALL
489 ScVbaWindow::setDisplayHeadings( sal_Bool _bDisplayHeadings )
491 getControllerProps()->setPropertyValue( SC_UNO_COLROWHDR, uno::Any( _bDisplayHeadings ));
494 sal_Bool SAL_CALL
495 ScVbaWindow::getDisplayHorizontalScrollBar()
497 bool bHorizontalScrollBar = true;
498 getControllerProps()->getPropertyValue( SC_UNO_HORSCROLL ) >>= bHorizontalScrollBar;
499 return bHorizontalScrollBar;
502 void SAL_CALL
503 ScVbaWindow::setDisplayHorizontalScrollBar( sal_Bool _bDisplayHorizontalScrollBar )
505 getControllerProps()->setPropertyValue( SC_UNO_HORSCROLL, uno::Any( _bDisplayHorizontalScrollBar ));
508 sal_Bool SAL_CALL
509 ScVbaWindow::getDisplayOutline()
511 bool bOutline = true;
512 getControllerProps()->getPropertyValue( SC_UNO_OUTLSYMB ) >>= bOutline;
513 return bOutline;
516 void SAL_CALL
517 ScVbaWindow::setDisplayOutline( sal_Bool _bDisplayOutline )
519 getControllerProps()->setPropertyValue( SC_UNO_OUTLSYMB, uno::Any( _bDisplayOutline ));
522 sal_Bool SAL_CALL
523 ScVbaWindow::getDisplayVerticalScrollBar()
525 bool bVerticalScrollBar = true;
526 getControllerProps()->getPropertyValue( SC_UNO_VERTSCROLL ) >>= bVerticalScrollBar;
527 return bVerticalScrollBar;
530 void SAL_CALL
531 ScVbaWindow::setDisplayVerticalScrollBar( sal_Bool _bDisplayVerticalScrollBar )
533 getControllerProps()->setPropertyValue( SC_UNO_VERTSCROLL, uno::Any( _bDisplayVerticalScrollBar ));
536 sal_Bool SAL_CALL
537 ScVbaWindow::getDisplayWorkbookTabs()
539 bool bWorkbookTabs = true;
540 getControllerProps()->getPropertyValue( SC_UNO_SHEETTABS ) >>= bWorkbookTabs;
541 return bWorkbookTabs;
544 void SAL_CALL
545 ScVbaWindow::setDisplayWorkbookTabs( sal_Bool _bDisplayWorkbookTabs )
547 getControllerProps()->setPropertyValue( SC_UNO_SHEETTABS, uno::Any( _bDisplayWorkbookTabs ));
550 sal_Bool SAL_CALL
551 ScVbaWindow::getFreezePanes()
553 uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
554 return xViewFreezable->hasFrozenPanes();
557 void SAL_CALL
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 );
563 if( _bFreezePanes )
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 );
572 else
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 );
581 else
583 //remove the freeze panes
584 xViewSplitable->splitAtPosition(0,0);
588 sal_Bool SAL_CALL
589 ScVbaWindow::getSplit()
591 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
592 return xViewSplitable->getIsWindowSplit();
595 void SAL_CALL
596 ScVbaWindow::setSplit( sal_Bool _bSplit )
598 if( !_bSplit )
600 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
601 xViewSplitable->splitAtPosition(0,0);
603 else
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 );
613 sal_Int32 SAL_CALL
614 ScVbaWindow::getSplitColumn()
616 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
617 return xViewSplitable->getSplitColumn();
620 void SAL_CALL
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 );
631 double SAL_CALL
632 ScVbaWindow::getSplitHorizontal()
634 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
635 return PixelsToPoints( getDevice(), xViewSplitable->getSplitHorizontal(), true );
638 void SAL_CALL
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 );
646 sal_Int32 SAL_CALL
647 ScVbaWindow::getSplitRow()
649 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
650 return xViewSplitable->getSplitRow();
653 void SAL_CALL
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 );
664 double SAL_CALL
665 ScVbaWindow::getSplitVertical()
667 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
668 return PixelsToPoints( getDevice(), xViewSplitable->getSplitVertical(), false );
671 void SAL_CALL
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 )
685 return;
687 sal_Int32 cellColumn = nColumns + 1;
688 sal_Int32 cellRow = nRows + 1;
690 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
691 if ( pViewShell )
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 );
705 uno::Any SAL_CALL
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 );
723 return uno::Any();
726 void SAL_CALL ScVbaWindow::setZoom(const uno::Any& _zoom)
728 sal_Int16 nZoom = 100;
729 _zoom >>= nZoom;
730 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( m_xModel, uno::UNO_QUERY_THROW );
731 uno::Reference< excel::XWorksheet > xActiveSheet = ActiveSheet();
732 SCTAB nTab = 0;
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();
746 uno::Any SAL_CALL
747 ScVbaWindow::getView()
749 bool bPageBreak = false;
750 sal_Int32 nWindowView = excel::XlWindowView::xlNormalView;
752 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
753 if (pViewShell)
754 bPageBreak = pViewShell->GetViewData().IsPagebreakMode();
756 if( bPageBreak )
757 nWindowView = excel::XlWindowView::xlPageBreakPreview;
758 else
759 nWindowView = excel::XlWindowView::xlNormalView;
761 return uno::Any( nWindowView );
764 void SAL_CALL
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;
774 break;
775 case excel::XlWindowView::xlPageBreakPreview:
776 nSlot = FID_PAGEBREAKMODE;
777 break;
778 default:
779 DebugHelper::runtimeexception(ERRCODE_BASIC_BAD_PARAMETER);
781 // !! TODO !! get view shell from controller
782 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
783 if ( pViewShell )
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();
796 sal_Int32 SAL_CALL
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 );
804 sal_Int32 SAL_CALL
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 );
812 void SAL_CALL
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 );
820 void SAL_CALL
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 )
835 return fRatio;
837 return 0.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 );
850 OUString
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: */