fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / vba / vbawindow.cxx
blob8f0168e93e663399840c3a68a896775c2f75138f
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 <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>
37 #include <docsh.hxx>
38 #include <tabvwsh.hxx>
39 #include <docuno.hxx>
40 #include <sc.hrc>
41 #include <sfx2/viewfrm.hxx>
42 #include <vcl/wrkwin.hxx>
43 #include "unonames.hxx"
44 #include "markdata.hxx"
45 #include <unordered_map>
47 using namespace ::com::sun::star;
48 using namespace ::ooo::vba;
49 using namespace ::ooo::vba::excel::XlWindowState;
51 typedef std::unordered_map< OUString,
52 SCTAB, OUStringHash,
53 ::std::equal_to< OUString > > NameIndexHash;
55 typedef std::vector< uno::Reference< sheet::XSpreadsheet > > Sheets;
57 typedef ::cppu::WeakImplHelper1< container::XEnumeration > Enumeration_BASE;
59 typedef ::cppu::WeakImplHelper3< container::XEnumerationAccess
60 , com::sun::star::container::XIndexAccess
61 , com::sun::star::container::XNameAccess
62 > SelectedSheets_BASE;
64 class SelectedSheetsEnum : public Enumeration_BASE
66 public:
67 uno::Reference< uno::XComponentContext > m_xContext;
68 Sheets m_sheets;
69 uno::Reference< frame::XModel > m_xModel;
70 Sheets::const_iterator m_it;
72 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 m_it = m_sheets.begin();
76 // XEnumeration
77 virtual sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
79 return m_it != m_sheets.end();
81 virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE
83 if ( !hasMoreElements() )
85 throw container::NoSuchElementException();
87 // #FIXME needs ThisWorkbook as parent
88 return uno::makeAny( uno::Reference< excel::XWorksheet > ( new ScVbaWorksheet( uno::Reference< XHelperInterface >(), m_xContext, *(m_it++), m_xModel ) ) );
93 class SelectedSheetsEnumAccess : public SelectedSheets_BASE
95 uno::Reference< uno::XComponentContext > m_xContext;
96 NameIndexHash namesToIndices;
97 Sheets sheets;
98 uno::Reference< frame::XModel > m_xModel;
99 public:
100 SelectedSheetsEnumAccess( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ):m_xContext( xContext ), m_xModel( xModel )
102 ScModelObj* pModel = static_cast< ScModelObj* >( m_xModel.get() );
103 if ( !pModel )
104 throw uno::RuntimeException("Cannot obtain current document" );
105 ScDocShell* pDocShell = static_cast<ScDocShell*>(pModel->GetEmbeddedObject());
106 if ( !pDocShell )
107 throw uno::RuntimeException("Cannot obtain docshell" );
108 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
109 if ( !pViewShell )
110 throw uno::RuntimeException("Cannot obtain view shell" );
112 SCTAB nTabCount = pDocShell->GetDocument().GetTableCount();
113 SCTAB nIndex = 0;
114 const ScMarkData& rMarkData = pViewShell->GetViewData().GetMarkData();
115 sheets.reserve( nTabCount );
116 uno::Reference <sheet::XSpreadsheetDocument> xSpreadSheet( m_xModel, uno::UNO_QUERY_THROW );
117 uno::Reference <container::XIndexAccess> xIndex( xSpreadSheet->getSheets(), uno::UNO_QUERY_THROW );
118 ScMarkData::const_iterator itr = rMarkData.begin(), itrEnd = rMarkData.end();
119 for (; itr != itrEnd && *itr < nTabCount; ++itr)
121 uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex( *itr ), uno::UNO_QUERY_THROW );
122 uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW );
123 sheets.push_back( xSheet );
124 namesToIndices[ xNamed->getName() ] = nIndex++;
129 //XEnumerationAccess
130 virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
132 return new SelectedSheetsEnum( m_xContext, sheets, m_xModel );
134 // XIndexAccess
135 virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
137 return sheets.size();
139 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw ( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE
141 if ( Index < 0
142 || static_cast< Sheets::size_type >( Index ) >= sheets.size() )
143 throw lang::IndexOutOfBoundsException();
145 return uno::makeAny( sheets[ Index ] );
148 //XElementAccess
149 virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
151 return cppu::UnoType<excel::XWorksheet>::get();
154 virtual sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
156 return ( !sheets.empty() );
159 //XNameAccess
160 virtual uno::Any SAL_CALL getByName( const OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE
162 NameIndexHash::const_iterator it = namesToIndices.find( aName );
163 if ( it == namesToIndices.end() )
164 throw container::NoSuchElementException();
165 return uno::makeAny( sheets[ it->second ] );
169 virtual uno::Sequence< OUString > SAL_CALL getElementNames( ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
171 uno::Sequence< OUString > names( namesToIndices.size() );
172 OUString* pString = names.getArray();
173 NameIndexHash::const_iterator it = namesToIndices.begin();
174 NameIndexHash::const_iterator it_end = namesToIndices.end();
175 for ( ; it != it_end; ++it, ++pString )
176 *pString = it->first;
177 return names;
180 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
182 NameIndexHash::const_iterator it = namesToIndices.find( aName );
183 return (it != namesToIndices.end());
188 ScVbaWindow::ScVbaWindow(
189 const uno::Reference< XHelperInterface >& xParent,
190 const uno::Reference< uno::XComponentContext >& xContext,
191 const uno::Reference< frame::XModel >& xModel,
192 const uno::Reference< frame::XController >& xController ) throw (uno::RuntimeException) :
193 WindowImpl_BASE( xParent, xContext, xModel, xController )
195 init();
198 ScVbaWindow::ScVbaWindow(
199 const uno::Sequence< uno::Any >& args,
200 const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException) :
201 WindowImpl_BASE( args, xContext )
203 init();
206 void
207 ScVbaWindow::init()
209 /* This method is called from the constructor, thus the own refcount is
210 still zero. The implementation of ActivePane() uses a UNO reference of
211 this (to set this window as parent of the pane object). This requires
212 the own refcount to be non-zero, otherwise this instance will be
213 desctructed immediately! Guard the call to ActivePane() in try/catch to
214 not miss the decrementation of the reference count on exception. */
215 osl_atomic_increment( &m_refCount );
218 m_xPane = ActivePane();
220 catch( uno::Exception& )
223 osl_atomic_decrement( &m_refCount );
226 uno::Reference< beans::XPropertySet >
227 ScVbaWindow::getControllerProps() throw (uno::RuntimeException)
229 return uno::Reference< beans::XPropertySet >( getController(), uno::UNO_QUERY_THROW );
232 uno::Reference< beans::XPropertySet >
233 ScVbaWindow::getFrameProps() throw (uno::RuntimeException)
235 return uno::Reference< beans::XPropertySet >( getController()->getFrame(), uno::UNO_QUERY_THROW );
238 uno::Reference< awt::XDevice >
239 ScVbaWindow::getDevice() throw (uno::RuntimeException)
241 return uno::Reference< awt::XDevice >( getWindow(), uno::UNO_QUERY_THROW );
244 void
245 ScVbaWindow::Scroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft, bool bLargeScroll ) throw (uno::RuntimeException)
247 if( !m_xPane.is() )
248 throw uno::RuntimeException();
249 if( bLargeScroll )
250 m_xPane->LargeScroll( Down, Up, ToRight, ToLeft );
251 else
252 m_xPane->SmallScroll( Down, Up, ToRight, ToLeft );
255 void SAL_CALL
256 ScVbaWindow::SmallScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException, std::exception)
258 Scroll( Down, Up, ToRight, ToLeft );
261 void SAL_CALL
262 ScVbaWindow::LargeScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException, std::exception)
264 Scroll( Down, Up, ToRight, ToLeft, true );
267 uno::Any SAL_CALL
268 ScVbaWindow::SelectedSheets( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
270 uno::Reference< container::XEnumerationAccess > xEnumAccess( new SelectedSheetsEnumAccess( mxContext, m_xModel ) );
271 // #FIXME needs a workbook as a parent
272 uno::Reference< excel::XWorksheets > xSheets( new ScVbaWorksheets( uno::Reference< XHelperInterface >(), mxContext, xEnumAccess, m_xModel ) );
273 if ( aIndex.hasValue() )
275 uno::Reference< XCollection > xColl( xSheets, uno::UNO_QUERY_THROW );
276 return xColl->Item( aIndex, uno::Any() );
278 return uno::makeAny( xSheets );
281 void SAL_CALL
282 ScVbaWindow::ScrollWorkbookTabs( const uno::Any& /*Sheets*/, const uno::Any& /*Position*/ ) throw (uno::RuntimeException, std::exception)
284 // #TODO #FIXME need some implementation to scroll through the tabs
285 // but where is this done?
287 sal_Int32 nSheets = 0;
288 sal_Int32 nPosition = 0;
289 throw uno::RuntimeException("No Implemented" );
290 sal_Bool bSheets = ( Sheets >>= nSheets );
291 sal_Bool bPosition = ( Position >>= nPosition );
292 if ( bSheets || bPosition ) // at least one param specified
293 if ( bSheets )
294 ;// use sheets
295 else if ( bPosition )
296 ; //use position
301 uno::Any SAL_CALL
302 ScVbaWindow::getCaption() throw (uno::RuntimeException, std::exception)
304 static const char sCrud[] = " - OpenOffice.org Calc";
305 static const sal_Int32 nCrudLen = strlen(sCrud);
307 OUString sTitle;
308 getFrameProps()->getPropertyValue( SC_UNONAME_TITLE ) >>= sTitle;
309 sal_Int32 nCrudIndex = sTitle.indexOf( sCrud );
310 // adjust title ( by removing crud )
311 // sCrud string present
312 if ( nCrudIndex != -1 )
314 // and ends with sCrud
315 if ( ( nCrudLen + nCrudIndex ) == sTitle.getLength() )
317 sTitle = sTitle.copy( 0, nCrudIndex );
318 ScVbaWorkbook workbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel );
319 OUString sName = workbook.getName();
320 // rather bizare hack to make sure the name behavior
321 // is like XL
322 // if the adjusted title == workbook name, use name
323 // if the adjusted title != workbook name but ...
324 // name == title + extension ( .csv, ,odt, .xls )
325 // etc. then also use the name
327 if ( !sTitle.equals( sName ) )
329 static const char sDot[] = ".";
330 // starts with title
331 if ( sName.startsWith( sTitle ) )
332 // extension starts immediately after
333 if ( sName.match( sDot, sTitle.getLength() ) )
334 sTitle = sName;
338 return uno::makeAny( sTitle );
341 void SAL_CALL
342 ScVbaWindow::setCaption( const uno::Any& _caption ) throw (uno::RuntimeException, std::exception)
344 getFrameProps()->setPropertyValue( OUString( SC_UNONAME_TITLE ), _caption );
347 uno::Any SAL_CALL
348 ScVbaWindow::getScrollRow() throw (uno::RuntimeException, std::exception)
350 sal_Int32 nValue = 0;
351 // !! TODO !! get view shell from controller
352 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
353 if ( pViewShell )
355 ScSplitPos eWhich = pViewShell->GetViewData().GetActivePart();
356 nValue = pViewShell->GetViewData().GetPosY(WhichV(eWhich));
359 return uno::makeAny( nValue + 1);
362 void SAL_CALL
363 ScVbaWindow::setScrollRow( const uno::Any& _scrollrow ) throw (uno::RuntimeException, std::exception)
365 // !! TODO !! get view shell from controller
366 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
367 if ( pViewShell )
369 sal_Int32 scrollRow = 0;
370 _scrollrow >>= scrollRow;
371 ScSplitPos eWhich = pViewShell->GetViewData().GetActivePart();
372 sal_Int32 nOldValue = pViewShell->GetViewData().GetPosY(WhichV(eWhich)) + 1;
373 pViewShell->ScrollLines(0, scrollRow - nOldValue);
377 uno::Any SAL_CALL
378 ScVbaWindow::getScrollColumn() throw (uno::RuntimeException, std::exception)
380 sal_Int32 nValue = 0;
381 // !! TODO !! get view shell from controller
382 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
383 if ( pViewShell )
385 ScSplitPos eWhich = pViewShell->GetViewData().GetActivePart();
386 nValue = pViewShell->GetViewData().GetPosX(WhichH(eWhich));
389 return uno::makeAny( nValue + 1);
392 void SAL_CALL
393 ScVbaWindow::setScrollColumn( const uno::Any& _scrollcolumn ) throw (uno::RuntimeException, std::exception)
395 // !! TODO !! get view shell from controller
396 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
397 if ( pViewShell )
399 sal_Int32 scrollColumn = 0;
400 _scrollcolumn >>= scrollColumn;
401 ScSplitPos eWhich = pViewShell->GetViewData().GetActivePart();
402 sal_Int32 nOldValue = pViewShell->GetViewData().GetPosX(WhichH(eWhich)) + 1;
403 pViewShell->ScrollLines(scrollColumn - nOldValue, 0);
407 uno::Any SAL_CALL
408 ScVbaWindow::getWindowState() throw (uno::RuntimeException, std::exception)
410 sal_Int32 nwindowState = xlNormal;
411 // !! TODO !! get view shell from controller
412 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
413 SfxViewFrame* pViewFrame = pViewShell -> GetViewFrame();
414 WorkWindow* pWork = static_cast<WorkWindow*>( pViewFrame->GetFrame().GetSystemWindow() );
415 if ( pWork )
417 if ( pWork -> IsMaximized())
418 nwindowState = xlMaximized;
419 else if (pWork -> IsMinimized())
420 nwindowState = xlMinimized;
422 return uno::makeAny( nwindowState );
425 void SAL_CALL
426 ScVbaWindow::setWindowState( const uno::Any& _windowstate ) throw (uno::RuntimeException, std::exception)
428 sal_Int32 nwindowState = xlMaximized;
429 _windowstate >>= nwindowState;
430 // !! TODO !! get view shell from controller
431 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
432 SfxViewFrame* pViewFrame = pViewShell -> GetViewFrame();
433 WorkWindow* pWork = static_cast<WorkWindow*>( pViewFrame->GetFrame().GetSystemWindow() );
434 if ( pWork )
436 if ( nwindowState == xlMaximized)
437 pWork -> Maximize();
438 else if (nwindowState == xlMinimized)
439 pWork -> Minimize();
440 else if (nwindowState == xlNormal)
441 pWork -> Restore();
442 else
443 throw uno::RuntimeException("Invalid Parameter" );
447 void
448 ScVbaWindow::Activate() throw (css::uno::RuntimeException, std::exception)
450 ScVbaWorkbook workbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel );
452 workbook.Activate();
455 void
456 ScVbaWindow::Close( const uno::Any& SaveChanges, const uno::Any& FileName, const uno::Any& RouteWorkBook ) throw (uno::RuntimeException, std::exception)
458 ScVbaWorkbook workbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel );
459 workbook.Close(SaveChanges, FileName, RouteWorkBook );
462 uno::Reference< excel::XPane > SAL_CALL
463 ScVbaWindow::ActivePane() throw (script::BasicErrorException, uno::RuntimeException, std::exception)
465 uno::Reference< sheet::XViewPane > xViewPane( getController(), uno::UNO_QUERY_THROW );
466 return new ScVbaPane( this, mxContext, m_xModel, xViewPane );
469 uno::Reference< excel::XRange > SAL_CALL
470 ScVbaWindow::ActiveCell( ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
472 uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
473 return xApplication->getActiveCell();
476 uno::Any SAL_CALL
477 ScVbaWindow::Selection( ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
479 uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
480 return xApplication->getSelection();
483 uno::Reference< excel::XRange > SAL_CALL
484 ScVbaWindow::RangeSelection() throw (script::BasicErrorException, uno::RuntimeException, std::exception)
486 /* TODO / FIXME: According to documentation, this method returns the range
487 selection even if shapes are selected. */
488 return uno::Reference< excel::XRange >( Selection(), uno::UNO_QUERY_THROW );
491 sal_Bool SAL_CALL
492 ScVbaWindow::getDisplayGridlines() throw (uno::RuntimeException, std::exception)
494 OUString sName( SC_UNO_SHOWGRID );
495 bool bGrid = true;
496 getControllerProps()->getPropertyValue( sName ) >>= bGrid;
497 return bGrid;
500 void SAL_CALL
501 ScVbaWindow::setDisplayGridlines( sal_Bool _displaygridlines ) throw (uno::RuntimeException, std::exception)
503 OUString sName( SC_UNO_SHOWGRID );
504 getControllerProps()->setPropertyValue( sName, uno::makeAny( _displaygridlines ));
507 sal_Bool SAL_CALL
508 ScVbaWindow::getDisplayHeadings() throw (uno::RuntimeException, std::exception)
510 OUString sName( SC_UNO_COLROWHDR );
511 bool bHeading = true;
512 getControllerProps()->getPropertyValue( sName ) >>= bHeading;
513 return bHeading;
516 void SAL_CALL
517 ScVbaWindow::setDisplayHeadings( sal_Bool _bDisplayHeadings ) throw (uno::RuntimeException, std::exception)
519 OUString sName( SC_UNO_COLROWHDR );
520 getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayHeadings ));
523 sal_Bool SAL_CALL
524 ScVbaWindow::getDisplayHorizontalScrollBar() throw (uno::RuntimeException, std::exception)
526 OUString sName( SC_UNO_HORSCROLL );
527 bool bHorizontalScrollBar = true;
528 getControllerProps()->getPropertyValue( sName ) >>= bHorizontalScrollBar;
529 return bHorizontalScrollBar;
532 void SAL_CALL
533 ScVbaWindow::setDisplayHorizontalScrollBar( sal_Bool _bDisplayHorizontalScrollBar ) throw (uno::RuntimeException, std::exception)
535 OUString sName( SC_UNO_HORSCROLL );
536 getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayHorizontalScrollBar ));
539 sal_Bool SAL_CALL
540 ScVbaWindow::getDisplayOutline() throw (uno::RuntimeException, std::exception)
542 OUString sName( SC_UNO_OUTLSYMB );
543 bool bOutline = true;
544 getControllerProps()->getPropertyValue( sName ) >>= bOutline;
545 return bOutline;
548 void SAL_CALL
549 ScVbaWindow::setDisplayOutline( sal_Bool _bDisplayOutline ) throw (uno::RuntimeException, std::exception)
551 OUString sName( SC_UNO_OUTLSYMB );
552 getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayOutline ));
555 sal_Bool SAL_CALL
556 ScVbaWindow::getDisplayVerticalScrollBar() throw (uno::RuntimeException, std::exception)
558 OUString sName( SC_UNO_VERTSCROLL );
559 bool bVerticalScrollBar = true;
560 getControllerProps()->getPropertyValue( sName ) >>= bVerticalScrollBar;
561 return bVerticalScrollBar;
564 void SAL_CALL
565 ScVbaWindow::setDisplayVerticalScrollBar( sal_Bool _bDisplayVerticalScrollBar ) throw (uno::RuntimeException, std::exception)
567 OUString sName( SC_UNO_VERTSCROLL );
568 getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayVerticalScrollBar ));
571 sal_Bool SAL_CALL
572 ScVbaWindow::getDisplayWorkbookTabs() throw (uno::RuntimeException, std::exception)
574 OUString sName( SC_UNO_SHEETTABS );
575 bool bWorkbookTabs = true;
576 getControllerProps()->getPropertyValue( sName ) >>= bWorkbookTabs;
577 return bWorkbookTabs;
580 void SAL_CALL
581 ScVbaWindow::setDisplayWorkbookTabs( sal_Bool _bDisplayWorkbookTabs ) throw (uno::RuntimeException, std::exception)
583 OUString sName( SC_UNO_SHEETTABS );
584 getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayWorkbookTabs ));
587 sal_Bool SAL_CALL
588 ScVbaWindow::getFreezePanes() throw (uno::RuntimeException, std::exception)
590 uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
591 return xViewFreezable->hasFrozenPanes();
594 void SAL_CALL
595 ScVbaWindow::setFreezePanes( sal_Bool _bFreezePanes ) throw (uno::RuntimeException, std::exception)
597 uno::Reference< sheet::XViewPane > xViewPane( getController(), uno::UNO_QUERY_THROW );
598 uno::Reference< sheet::XViewSplitable > xViewSplitable( xViewPane, uno::UNO_QUERY_THROW );
599 uno::Reference< sheet::XViewFreezable > xViewFreezable( xViewPane, uno::UNO_QUERY_THROW );
600 if( _bFreezePanes )
602 if( xViewSplitable->getIsWindowSplit() )
604 // if there is a split we freeze at the split
605 sal_Int32 nColumn = getSplitColumn();
606 sal_Int32 nRow = getSplitRow();
607 xViewFreezable->freezeAtPosition( nColumn, nRow );
609 else
611 // otherwise we freeze in the center of the visible sheet
612 table::CellRangeAddress aCellRangeAddress = xViewPane->getVisibleRange();
613 sal_Int32 nColumn = aCellRangeAddress.StartColumn + (( aCellRangeAddress.EndColumn - aCellRangeAddress.StartColumn )/2 );
614 sal_Int32 nRow = aCellRangeAddress.StartRow + (( aCellRangeAddress.EndRow - aCellRangeAddress.StartRow )/2 );
615 xViewFreezable->freezeAtPosition( nColumn, nRow );
618 else
620 //remove the freeze panes
621 xViewSplitable->splitAtPosition(0,0);
625 sal_Bool SAL_CALL
626 ScVbaWindow::getSplit() throw (uno::RuntimeException, std::exception)
628 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
629 return xViewSplitable->getIsWindowSplit();
632 void SAL_CALL
633 ScVbaWindow::setSplit( sal_Bool _bSplit ) throw (uno::RuntimeException, std::exception)
635 if( !_bSplit )
637 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
638 xViewSplitable->splitAtPosition(0,0);
640 else
642 uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
643 uno::Reference< excel::XRange > xRange = ActiveCell();
644 sal_Int32 nRow = xRange->getRow();
645 sal_Int32 nColumn = xRange->getColumn();
646 SplitAtDefinedPosition( nColumn-1, nRow-1 );
650 sal_Int32 SAL_CALL
651 ScVbaWindow::getSplitColumn() throw (uno::RuntimeException, std::exception)
653 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
654 return xViewSplitable->getSplitColumn();
657 void SAL_CALL
658 ScVbaWindow::setSplitColumn( sal_Int32 _splitcolumn ) throw (uno::RuntimeException, std::exception)
660 if( getSplitColumn() != _splitcolumn )
662 uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
663 sal_Int32 nRow = getSplitRow();
664 SplitAtDefinedPosition( _splitcolumn, nRow );
668 double SAL_CALL
669 ScVbaWindow::getSplitHorizontal() throw (uno::RuntimeException, std::exception)
671 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
672 return PixelsToPoints( getDevice(), xViewSplitable->getSplitHorizontal(), true );
675 void SAL_CALL
676 ScVbaWindow::setSplitHorizontal( double _splithorizontal ) throw (uno::RuntimeException, std::exception)
678 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
679 double fHoriPixels = PointsToPixels( getDevice(), _splithorizontal, true );
680 xViewSplitable->splitAtPosition( static_cast< sal_Int32 >( fHoriPixels ), 0 );
683 sal_Int32 SAL_CALL
684 ScVbaWindow::getSplitRow() throw (uno::RuntimeException, std::exception)
686 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
687 return xViewSplitable->getSplitRow();
690 void SAL_CALL
691 ScVbaWindow::setSplitRow( sal_Int32 _splitrow ) throw (uno::RuntimeException, std::exception)
693 if( getSplitRow() != _splitrow )
695 uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
696 sal_Int32 nColumn = getSplitColumn();
697 SplitAtDefinedPosition( nColumn, _splitrow );
701 double SAL_CALL
702 ScVbaWindow::getSplitVertical() throw (uno::RuntimeException, std::exception)
704 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
705 return PixelsToPoints( getDevice(), xViewSplitable->getSplitVertical(), false );
708 void SAL_CALL
709 ScVbaWindow::setSplitVertical(double _splitvertical ) throw (uno::RuntimeException, std::exception)
711 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
712 double fVertiPixels = PointsToPixels( getDevice(), _splitvertical, false );
713 xViewSplitable->splitAtPosition( 0, static_cast<sal_Int32>( fVertiPixels ) );
716 void ScVbaWindow::SplitAtDefinedPosition( sal_Int32 nColumns, sal_Int32 nRows )
718 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
719 uno::Reference< sheet::XViewFreezable > xViewFreezable( xViewSplitable, uno::UNO_QUERY_THROW );
720 // nColumns and nRows means split columns/rows
721 if( nColumns == 0 && nRows == 0 )
722 return;
724 sal_Int32 cellColumn = nColumns + 1;
725 sal_Int32 cellRow = nRows + 1;
727 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
728 if ( pViewShell )
730 //firstly remove the old splitter
731 xViewSplitable->splitAtPosition(0,0);
733 uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
734 uno::Reference< excel::XWorksheet > xSheet( xApplication->getActiveSheet(), uno::UNO_QUERY_THROW );
735 xSheet->Cells(uno::makeAny(cellRow), uno::makeAny(cellColumn))->Select();
737 //pViewShell->FreezeSplitters( FALSE );
738 dispatchExecute( pViewShell, SID_WINDOW_SPLIT );
742 uno::Any SAL_CALL
743 ScVbaWindow::getZoom() throw (uno::RuntimeException, std::exception)
745 uno::Reference< beans::XPropertySet > xProps = getControllerProps();
746 OUString sName( SC_UNO_ZOOMTYPE );
747 sal_Int16 nZoomType = view::DocumentZoomType::PAGE_WIDTH;
748 xProps->getPropertyValue( sName ) >>= nZoomType;
749 if( nZoomType == view::DocumentZoomType::PAGE_WIDTH )
751 return uno::makeAny( sal_True );
753 else if( nZoomType == view::DocumentZoomType::BY_VALUE )
755 sName = SC_UNO_ZOOMVALUE;
756 sal_Int16 nZoom = 100;
757 xProps->getPropertyValue( sName ) >>= nZoom;
758 return uno::makeAny( nZoom );
760 return uno::Any();
763 void SAL_CALL ScVbaWindow::setZoom(const uno::Any& _zoom)
764 throw (uno::RuntimeException, std::exception)
766 sal_Int16 nZoom = 100;
767 _zoom >>= nZoom;
768 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( m_xModel, uno::UNO_QUERY_THROW );
769 uno::Reference< excel::XWorksheet > xActiveSheet = ActiveSheet();
770 SCTAB nTab = 0;
771 if ( !ScVbaWorksheets::nameExists (xSpreadDoc, xActiveSheet->getName(), nTab) )
772 throw uno::RuntimeException();
773 std::vector< SCTAB > vTabs;
774 vTabs.push_back( nTab );
775 excel::implSetZoom( m_xModel, nZoom, vTabs );
778 uno::Reference< excel::XWorksheet > SAL_CALL
779 ScVbaWindow::ActiveSheet( ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
781 uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
782 return xApplication->getActiveSheet();
785 uno::Any SAL_CALL
786 ScVbaWindow::getView() throw (uno::RuntimeException, std::exception)
788 bool bPageBreak = false;
789 sal_Int32 nWindowView = excel::XlWindowView::xlNormalView;
791 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
792 if (pViewShell)
793 bPageBreak = pViewShell->GetViewData().IsPagebreakMode();
795 if( bPageBreak )
796 nWindowView = excel::XlWindowView::xlPageBreakPreview;
797 else
798 nWindowView = excel::XlWindowView::xlNormalView;
800 return uno::makeAny( nWindowView );
803 void SAL_CALL
804 ScVbaWindow::setView( const uno::Any& _view) throw (uno::RuntimeException, std::exception)
806 sal_Int32 nWindowView = excel::XlWindowView::xlNormalView;
807 _view >>= nWindowView;
808 sal_uInt16 nSlot = FID_NORMALVIEWMODE;
809 switch ( nWindowView )
811 case excel::XlWindowView::xlNormalView:
812 nSlot = FID_NORMALVIEWMODE;
813 break;
814 case excel::XlWindowView::xlPageBreakPreview:
815 nSlot = FID_PAGEBREAKMODE;
816 break;
817 default:
818 DebugHelper::runtimeexception(SbERR_BAD_PARAMETER, OUString() );
820 // !! TODO !! get view shell from controller
821 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
822 if ( pViewShell )
823 dispatchExecute( pViewShell, nSlot );
826 uno::Reference< excel::XRange > SAL_CALL
827 ScVbaWindow::getVisibleRange() throw (uno::RuntimeException, std::exception)
829 uno::Reference< container::XIndexAccess > xPanesIA( getController(), uno::UNO_QUERY_THROW );
830 uno::Reference< sheet::XViewPane > xTopLeftPane( xPanesIA->getByIndex( 0 ), uno::UNO_QUERY_THROW );
831 uno::Reference< excel::XPane > xPane( new ScVbaPane( this, mxContext, m_xModel, xTopLeftPane ) );
832 return xPane->getVisibleRange();
835 sal_Int32 SAL_CALL
836 ScVbaWindow::PointsToScreenPixelsX(sal_Int32 _points) throw (css::script::BasicErrorException, css::uno::RuntimeException, std::exception)
838 sal_Int32 nHundredthsofOneMillimeters = Millimeter::getInHundredthsOfOneMillimeter( _points );
839 double fConvertFactor = (getDevice()->getInfo().PixelPerMeterX/100000);
840 return static_cast<sal_Int32>(fConvertFactor * nHundredthsofOneMillimeters );
843 sal_Int32 SAL_CALL
844 ScVbaWindow::PointsToScreenPixelsY(sal_Int32 _points) throw (css::script::BasicErrorException, css::uno::RuntimeException, std::exception)
846 sal_Int32 nHundredthsofOneMillimeters = Millimeter::getInHundredthsOfOneMillimeter( _points );
847 double fConvertFactor = (getDevice()->getInfo().PixelPerMeterY/100000);
848 return static_cast<sal_Int32>(fConvertFactor * nHundredthsofOneMillimeters );
851 void SAL_CALL
852 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, std::exception)
854 // need test, print current active sheet
855 // !! TODO !! get view shell from controller
856 PrintOutHelper( excel::getBestViewShell( m_xModel ), From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, true );
859 void SAL_CALL
860 ScVbaWindow::PrintPreview( const css::uno::Any& EnableChanges ) throw (css::script::BasicErrorException, css::uno::RuntimeException, std::exception)
862 // need test, print preview current active sheet
863 // !! TODO !! get view shell from controller
864 PrintPreviewHelper( EnableChanges, excel::getBestViewShell( m_xModel ) );
867 double SAL_CALL ScVbaWindow::getTabRatio() throw (css::uno::RuntimeException, std::exception)
869 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
870 if ( pViewShell && pViewShell->GetViewData().GetView() )
872 double fRatio = pViewShell->GetViewData().GetView()->GetRelTabBarWidth();
873 if ( fRatio >= 0.0 && fRatio <= 1.0 )
874 return fRatio;
876 return 0.0;
879 void SAL_CALL ScVbaWindow::setTabRatio( double fRatio ) throw (css::uno::RuntimeException, std::exception)
881 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
882 if ( pViewShell && pViewShell->GetViewData().GetView() )
884 if ( fRatio >= 0.0 && fRatio <= 1.0 )
885 pViewShell->GetViewData().GetView()->SetRelTabBarWidth( fRatio );
889 OUString
890 ScVbaWindow::getServiceImplName()
892 return OUString("ScVbaWindow");
895 uno::Sequence< OUString >
896 ScVbaWindow::getServiceNames()
898 static uno::Sequence< OUString > aServiceNames;
899 if ( aServiceNames.getLength() == 0 )
901 aServiceNames.realloc( 1 );
902 aServiceNames[ 0 ] = "ooo.vba.excel.Window";
904 return aServiceNames;
906 namespace window
908 namespace sdecl = comphelper::service_decl;
909 sdecl::vba_service_class_<ScVbaWindow, sdecl::with_args<true> > serviceImpl;
910 extern sdecl::ServiceDecl const serviceDecl(
911 serviceImpl,
912 "ScVbaWindow",
913 "ooo.vba.excel.Window" );
916 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */