merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / vba / vbawindow.cxx
blob4c6c89a8871916f984866d30b5d6e969ff150c56
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vbawindow.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include <vbahelper/helperdecl.hxx>
31 #include "vbawindow.hxx"
32 #include "vbaworksheets.hxx"
33 #include "vbaworksheet.hxx"
34 #include "vbaglobals.hxx"
35 #include "vbapane.hxx"
36 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
37 #include <com/sun/star/sheet/XSpreadsheet.hpp>
38 #include <com/sun/star/container/XNamed.hpp>
39 #include <com/sun/star/view/DocumentZoomType.hpp>
40 #include <com/sun/star/table/CellRangeAddress.hpp>
41 #include <ooo/vba/excel/XlWindowState.hpp>
42 #include <ooo/vba/excel/XlWindowView.hpp>
43 #include <ooo/vba/excel/Constants.hpp>
44 #include <com/sun/star/awt/XWindow.hpp>
45 #include <com/sun/star/awt/XWindow2.hpp>
46 #include <com/sun/star/awt/PosSize.hpp>
48 #include <docsh.hxx>
49 #include <tabvwsh.hxx>
50 #include <docuno.hxx>
51 #include <sc.hrc>
52 #include <hash_map>
53 #include <sfx2/viewfrm.hxx>
54 #include <sfx2/topfrm.hxx>
55 #include "unonames.hxx"
57 using namespace ::com::sun::star;
58 using namespace ::ooo::vba;
59 using namespace ::ooo::vba::excel::XlWindowState;
61 // nameExists defined in vbaworksheet.cxx
62 bool nameExists( uno::Reference <sheet::XSpreadsheetDocument>& xSpreadDoc, ::rtl::OUString & name, SCTAB& nTab ) throw ( lang::IllegalArgumentException );
64 typedef std::hash_map< rtl::OUString,
65 SCTAB, ::rtl::OUStringHash,
66 ::std::equal_to< ::rtl::OUString > > NameIndexHash;
68 typedef std::vector < uno::Reference< sheet::XSpreadsheet > > Sheets;
70 typedef ::cppu::WeakImplHelper1< container::XEnumeration
72 > Enumeration_BASE;
74 typedef ::cppu::WeakImplHelper3< container::XEnumerationAccess
75 , com::sun::star::container::XIndexAccess
76 , com::sun::star::container::XNameAccess
77 > SelectedSheets_BASE;
80 class SelectedSheetsEnum : public Enumeration_BASE
82 public:
83 uno::Reference< uno::XComponentContext > m_xContext;
84 Sheets m_sheets;
85 uno::Reference< frame::XModel > m_xModel;
86 Sheets::const_iterator m_it;
88 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 )
90 m_it = m_sheets.begin();
92 // XEnumeration
93 virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException)
95 return m_it != m_sheets.end();
97 virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
99 if ( !hasMoreElements() )
101 throw container::NoSuchElementException();
103 // #FIXME needs ThisWorkbook as parent
104 return uno::makeAny( uno::Reference< excel::XWorksheet > ( new ScVbaWorksheet( uno::Reference< XHelperInterface >(), m_xContext, *(m_it++), m_xModel ) ) );
110 class SelectedSheetsEnumAccess : public SelectedSheets_BASE
112 uno::Reference< uno::XComponentContext > m_xContext;
113 NameIndexHash namesToIndices;
114 Sheets sheets;
115 uno::Reference< frame::XModel > m_xModel;
116 public:
117 SelectedSheetsEnumAccess( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ):m_xContext( xContext ), m_xModel( xModel )
119 ScModelObj* pModel = static_cast< ScModelObj* >( m_xModel.get() );
120 if ( !pModel )
121 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot obtain current document" ) ), uno::Reference< uno::XInterface >() );
122 ScDocShell* pDocShell = (ScDocShell*)pModel->GetEmbeddedObject();
123 if ( !pDocShell )
124 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot obtain docshell" ) ), uno::Reference< uno::XInterface >() );
125 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
126 if ( !pViewShell )
127 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot obtain view shell" ) ), uno::Reference< uno::XInterface >() );
129 SCTAB nTabCount = pDocShell->GetDocument()->GetTableCount();
130 uno::Sequence<sal_Int32> aSheets( nTabCount );
131 SCTAB nIndex = 0;
132 const ScMarkData& rMarkData = pViewShell->GetViewData()->GetMarkData();
133 sheets.reserve( nTabCount );
134 uno::Reference <sheet::XSpreadsheetDocument> xSpreadSheet( m_xModel, uno::UNO_QUERY_THROW );
135 uno::Reference <container::XIndexAccess> xIndex( xSpreadSheet->getSheets(), uno::UNO_QUERY_THROW );
136 for ( SCTAB nTab=0; nTab<nTabCount; nTab++ )
138 if ( rMarkData.GetTableSelect(nTab) )
140 uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex( nTab ), uno::UNO_QUERY_THROW );
141 uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW );
142 sheets.push_back( xSheet );
143 namesToIndices[ xNamed->getName() ] = nIndex++;
149 //XEnumerationAccess
150 virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException)
152 return new SelectedSheetsEnum( m_xContext, sheets, m_xModel );
154 // XIndexAccess
155 virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException)
157 return sheets.size();
159 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw ( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
161 if ( Index < 0
162 || static_cast< Sheets::size_type >( Index ) >= sheets.size() )
163 throw lang::IndexOutOfBoundsException();
165 return uno::makeAny( sheets[ Index ] );
168 //XElementAccess
169 virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException)
171 return excel::XWorksheet::static_type(0);
174 virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException)
176 return (sheets.size() > 0);
179 //XNameAccess
180 virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
182 NameIndexHash::const_iterator it = namesToIndices.find( aName );
183 if ( it == namesToIndices.end() )
184 throw container::NoSuchElementException();
185 return uno::makeAny( sheets[ it->second ] );
189 virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (uno::RuntimeException)
191 uno::Sequence< ::rtl::OUString > names( namesToIndices.size() );
192 ::rtl::OUString* pString = names.getArray();
193 NameIndexHash::const_iterator it = namesToIndices.begin();
194 NameIndexHash::const_iterator it_end = namesToIndices.end();
195 for ( ; it != it_end; ++it, ++pString )
196 *pString = it->first;
197 return names;
200 virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (uno::RuntimeException)
202 NameIndexHash::const_iterator it = namesToIndices.find( aName );
203 return (it != namesToIndices.end());
209 ScVbaWindow::ScVbaWindow( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ) : WindowImpl_BASE( xParent, xContext, xModel )
211 init();
214 ScVbaWindow::ScVbaWindow( uno::Sequence< uno::Any > const & args, uno::Reference< uno::XComponentContext > const & xContext )
215 : WindowImpl_BASE( args, xContext )
217 init();
219 void
220 ScVbaWindow::init()
222 uno::Reference< frame::XController > xController( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
223 m_xViewPane.set( xController, uno::UNO_QUERY_THROW );
224 m_xViewFreezable.set( xController, uno::UNO_QUERY_THROW );
225 m_xViewSplitable.set( xController, uno::UNO_QUERY_THROW );
226 m_xPane.set( ActivePane(), uno::UNO_QUERY_THROW );
227 m_xDevice.set( xController->getFrame()->getComponentWindow(), uno::UNO_QUERY_THROW );
231 void
232 ScVbaWindow::Scroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft, bool bLargeScroll ) throw (uno::RuntimeException)
234 if( bLargeScroll )
235 m_xPane->LargeScroll( Down, Up, ToRight, ToLeft );
236 else
237 m_xPane->SmallScroll( Down, Up, ToRight, ToLeft );
239 void SAL_CALL
240 ScVbaWindow::SmallScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException)
242 Scroll( Down, Up, ToRight, ToLeft );
244 void SAL_CALL
245 ScVbaWindow::LargeScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException)
247 Scroll( Down, Up, ToRight, ToLeft, true );
250 uno::Any SAL_CALL
251 ScVbaWindow::SelectedSheets( const uno::Any& aIndex ) throw (uno::RuntimeException)
253 uno::Reference< container::XEnumerationAccess > xEnumAccess( new SelectedSheetsEnumAccess( mxContext, m_xModel ) );
254 // #FIXME needs a workbook as a parent
255 uno::Reference< excel::XWorksheets > xSheets( new ScVbaWorksheets( uno::Reference< XHelperInterface >(), mxContext, xEnumAccess, m_xModel ) );
256 if ( aIndex.hasValue() )
258 uno::Reference< XCollection > xColl( xSheets, uno::UNO_QUERY_THROW );
259 return xColl->Item( aIndex, uno::Any() );
261 return uno::makeAny( xSheets );
264 void SAL_CALL
265 ScVbaWindow::ScrollWorkbookTabs( const uno::Any& /*Sheets*/, const uno::Any& /*Position*/ ) throw (uno::RuntimeException)
267 // #TODO #FIXME need some implementation to scroll through the tabs
268 // but where is this done?
270 sal_Int32 nSheets = 0;
271 sal_Int32 nPosition = 0;
272 throw uno::RuntimeException( rtl::OUString::createFromAscii("No Implemented" ), uno::Reference< uno::XInterface >() );
273 sal_Bool bSheets = ( Sheets >>= nSheets );
274 sal_Bool bPosition = ( Position >>= nPosition );
275 if ( bSheets || bPosition ) // at least one param specified
276 if ( bSheets )
277 ;// use sheets
278 else if ( bPosition )
279 ; //use position
283 uno::Reference< beans::XPropertySet >
284 getPropsFromModel( const uno::Reference< frame::XModel >& xModel )
286 uno::Reference< frame::XController > xController = xModel->getCurrentController();
287 if ( !xController.is() )
288 throw uno::RuntimeException( rtl::OUString(
289 RTL_CONSTASCII_USTRINGPARAM ("No controller for model") ), uno::Reference< uno::XInterface >() );
290 return uno::Reference< beans::XPropertySet >( xController->getFrame(), uno::UNO_QUERY );
294 uno::Any SAL_CALL
295 ScVbaWindow::getCaption() throw (uno::RuntimeException)
297 static rtl::OUString sCrud(RTL_CONSTASCII_USTRINGPARAM(" - OpenOffice.org Calc" ) );
298 static sal_Int32 nCrudLen = sCrud.getLength();
300 uno::Reference< beans::XPropertySet > xProps = getPropsFromModel( m_xModel );
301 rtl::OUString sTitle;
302 xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SC_UNONAME_TITLE ) ) ) >>= sTitle;
303 sal_Int32 nCrudIndex = sTitle.indexOf( sCrud );
304 // adjust title ( by removing crud )
305 // sCrud string present
306 if ( nCrudIndex != -1 )
308 // and ends with sCrud
309 if ( ( nCrudLen + nCrudIndex ) == sTitle.getLength() )
311 sTitle = sTitle.copy( 0, nCrudIndex );
312 ScVbaWorkbook workbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel );
313 rtl::OUString sName = workbook.getName();
314 // rather bizare hack to make sure the name behavior
315 // is like XL
316 // if the adjusted title == workbook name, use name
317 // if the adjusted title != workbook name but ...
318 // name == title + extension ( .csv, ,odt, .xls )
319 // etc. then also use the name
321 if ( !sTitle.equals( sName ) )
323 static rtl::OUString sDot( RTL_CONSTASCII_USTRINGPARAM(".") );
324 // starts with title
325 if ( sName.indexOf( sTitle ) == 0 )
326 // extention starts immediately after
327 if ( sName.match( sDot, sTitle.getLength() ) )
328 sTitle = sName;
332 return uno::makeAny( sTitle );
335 void SAL_CALL
336 ScVbaWindow::setCaption( const uno::Any& _caption ) throw (uno::RuntimeException)
339 uno::Reference< beans::XPropertySet > xProps = getPropsFromModel( m_xModel );
340 xProps->setPropertyValue( rtl::OUString(
341 RTL_CONSTASCII_USTRINGPARAM ( SC_UNONAME_TITLE ) ) , _caption );
344 uno::Any SAL_CALL
345 ScVbaWindow::getScrollRow() throw (uno::RuntimeException)
347 sal_Int32 nValue = 0;
348 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
349 if ( pViewShell )
351 ScSplitPos eWhich = pViewShell->GetViewData()->GetActivePart();
352 nValue = pViewShell->GetViewData()->GetPosY(WhichV(eWhich));
355 return uno::makeAny( nValue + 1);
358 void SAL_CALL
359 ScVbaWindow::setScrollRow( const uno::Any& _scrollrow ) throw (uno::RuntimeException)
361 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
362 if ( pViewShell )
364 sal_Int32 scrollRow = 0;
365 _scrollrow >>= scrollRow;
366 ScSplitPos eWhich = pViewShell->GetViewData()->GetActivePart();
367 sal_Int32 nOldValue = pViewShell->GetViewData()->GetPosY(WhichV(eWhich)) + 1;
368 pViewShell->ScrollLines(0, scrollRow - nOldValue);
372 uno::Any SAL_CALL
373 ScVbaWindow::getScrollColumn() throw (uno::RuntimeException)
375 sal_Int32 nValue = 0;
376 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
377 if ( pViewShell )
379 ScSplitPos eWhich = pViewShell->GetViewData()->GetActivePart();
380 nValue = pViewShell->GetViewData()->GetPosX(WhichH(eWhich));
383 return uno::makeAny( nValue + 1);
386 void SAL_CALL
387 ScVbaWindow::setScrollColumn( const uno::Any& _scrollcolumn ) throw (uno::RuntimeException)
389 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
390 if ( pViewShell )
392 sal_Int32 scrollColumn = 0;
393 _scrollcolumn >>= scrollColumn;
394 ScSplitPos eWhich = pViewShell->GetViewData()->GetActivePart();
395 sal_Int32 nOldValue = pViewShell->GetViewData()->GetPosX(WhichH(eWhich)) + 1;
396 pViewShell->ScrollLines(scrollColumn - nOldValue, 0);
400 uno::Any SAL_CALL
401 ScVbaWindow::getWindowState() throw (uno::RuntimeException)
403 sal_Int32 nwindowState = xlNormal;
404 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
405 SfxViewFrame* pViewFrame = pViewShell -> GetViewFrame();
406 SfxTopViewFrame *pTop= PTR_CAST( SfxTopViewFrame, pViewFrame -> GetTopViewFrame() );
407 if ( pTop )
409 WorkWindow* pWork = (WorkWindow*) pTop->GetTopFrame_Impl()->GetSystemWindow();
410 if ( pWork )
412 if ( pWork -> IsMaximized())
413 nwindowState = xlMaximized;
414 else if (pWork -> IsMinimized())
415 nwindowState = xlMinimized;
418 return uno::makeAny( nwindowState );
421 void SAL_CALL
422 ScVbaWindow::setWindowState( const uno::Any& _windowstate ) throw (uno::RuntimeException)
424 sal_Int32 nwindowState = xlMaximized;
425 _windowstate >>= nwindowState;
426 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
427 SfxViewFrame* pViewFrame = pViewShell -> GetViewFrame();
428 SfxTopViewFrame *pTop= PTR_CAST( SfxTopViewFrame, pViewFrame -> GetTopViewFrame() );
429 if ( pTop )
431 WorkWindow* pWork = (WorkWindow*) pTop->GetTopFrame_Impl()->GetSystemWindow();
432 if ( pWork )
434 if ( nwindowState == xlMaximized)
435 pWork -> Maximize();
436 else if (nwindowState == xlMinimized)
437 pWork -> Minimize();
438 else if (nwindowState == xlNormal)
439 pWork -> Restore();
440 else
441 throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Invalid Parameter" ) ), uno::Reference< uno::XInterface >() );
446 void
447 ScVbaWindow::Activate() throw (css::uno::RuntimeException)
449 ScVbaWorkbook workbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel );
451 workbook.Activate();
454 void
455 ScVbaWindow::Close( const uno::Any& SaveChanges, const uno::Any& FileName, const uno::Any& RouteWorkBook ) throw (uno::RuntimeException)
457 ScVbaWorkbook workbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel );
458 workbook.Close(SaveChanges, FileName, RouteWorkBook );
461 uno::Reference< excel::XPane > SAL_CALL
462 ScVbaWindow::ActivePane() throw (script::BasicErrorException, uno::RuntimeException)
464 return new ScVbaPane( mxContext, m_xViewPane );
467 uno::Reference< excel::XRange > SAL_CALL
468 ScVbaWindow::ActiveCell( ) throw (script::BasicErrorException, uno::RuntimeException)
470 uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
471 return xApplication->getActiveCell();
474 uno::Any SAL_CALL
475 ScVbaWindow::Selection( ) throw (script::BasicErrorException, uno::RuntimeException)
477 uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
478 return xApplication->getSelection();
481 ::sal_Bool SAL_CALL
482 ScVbaWindow::getDisplayGridlines() throw (uno::RuntimeException)
484 uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
485 rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SHOWGRID ) );
486 sal_Bool bGrid = sal_True;
487 xProps->getPropertyValue( sName ) >>= bGrid;
488 return bGrid;
492 void SAL_CALL
493 ScVbaWindow::setDisplayGridlines( ::sal_Bool _displaygridlines ) throw (uno::RuntimeException)
495 uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
496 rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SHOWGRID ) );
497 xProps->setPropertyValue( sName, uno::makeAny( _displaygridlines ));
500 ::sal_Bool SAL_CALL
501 ScVbaWindow::getDisplayHeadings() throw (uno::RuntimeException)
503 uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
504 rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_COLROWHDR ) );
505 sal_Bool bHeading = sal_True;
506 xProps->getPropertyValue( sName ) >>= bHeading;
507 return bHeading;
510 void SAL_CALL
511 ScVbaWindow::setDisplayHeadings( ::sal_Bool _bDisplayHeadings ) throw (uno::RuntimeException)
513 uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
514 rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_COLROWHDR ) );
515 xProps->setPropertyValue( sName, uno::makeAny( _bDisplayHeadings ));
518 ::sal_Bool SAL_CALL
519 ScVbaWindow::getDisplayHorizontalScrollBar() throw (uno::RuntimeException)
521 uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
522 rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_HORSCROLL ) );
523 sal_Bool bHorizontalScrollBar = sal_True;
524 xProps->getPropertyValue( sName ) >>= bHorizontalScrollBar;
525 return bHorizontalScrollBar;
528 void SAL_CALL
529 ScVbaWindow::setDisplayHorizontalScrollBar( ::sal_Bool _bDisplayHorizontalScrollBar ) throw (uno::RuntimeException)
531 uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
532 rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_HORSCROLL ) );
533 xProps->setPropertyValue( sName, uno::makeAny( _bDisplayHorizontalScrollBar ));
536 ::sal_Bool SAL_CALL
537 ScVbaWindow::getDisplayOutline() throw (uno::RuntimeException)
539 uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
540 rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_OUTLSYMB ) );
541 sal_Bool bOutline = sal_True;
542 xProps->getPropertyValue( sName ) >>= bOutline;
543 return bOutline;
546 void SAL_CALL
547 ScVbaWindow::setDisplayOutline( ::sal_Bool _bDisplayOutline ) throw (uno::RuntimeException)
549 uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
550 rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_OUTLSYMB ) );
551 xProps->setPropertyValue( sName, uno::makeAny( _bDisplayOutline ));
554 ::sal_Bool SAL_CALL
555 ScVbaWindow::getDisplayVerticalScrollBar() throw (uno::RuntimeException)
557 uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
558 rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_VERTSCROLL ) );
559 sal_Bool bVerticalScrollBar = sal_True;
560 xProps->getPropertyValue( sName ) >>= bVerticalScrollBar;
561 return bVerticalScrollBar;
564 void SAL_CALL
565 ScVbaWindow::setDisplayVerticalScrollBar( ::sal_Bool _bDisplayVerticalScrollBar ) throw (uno::RuntimeException)
567 uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
568 rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_VERTSCROLL ) );
569 xProps->setPropertyValue( sName, uno::makeAny( _bDisplayVerticalScrollBar ));
572 ::sal_Bool SAL_CALL
573 ScVbaWindow::getDisplayWorkbookTabs() throw (uno::RuntimeException)
575 uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
576 rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SHEETTABS ) );
577 sal_Bool bWorkbookTabs = sal_True;
578 xProps->getPropertyValue( sName ) >>= bWorkbookTabs;
579 return bWorkbookTabs;
582 void SAL_CALL
583 ScVbaWindow::setDisplayWorkbookTabs( ::sal_Bool _bDisplayWorkbookTabs ) throw (uno::RuntimeException)
585 uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
586 rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SHEETTABS ) );
587 xProps->setPropertyValue( sName, uno::makeAny( _bDisplayWorkbookTabs ));
590 ::sal_Bool SAL_CALL
591 ScVbaWindow::getFreezePanes() throw (uno::RuntimeException)
593 return m_xViewFreezable->hasFrozenPanes();
596 void SAL_CALL
597 ScVbaWindow::setFreezePanes( ::sal_Bool /*_bFreezePanes*/ ) throw (uno::RuntimeException)
599 if( m_xViewSplitable->getIsWindowSplit() )
601 // if there is a split we freeze at the split
602 sal_Int32 nColumn = getSplitColumn();
603 sal_Int32 nRow = getSplitRow();
604 m_xViewFreezable->freezeAtPosition( nColumn, nRow );
606 else
608 // otherwise we freeze in the center of the visible sheet
609 table::CellRangeAddress aCellRangeAddress = m_xViewPane->getVisibleRange();
610 sal_Int32 nColumn = aCellRangeAddress.StartColumn + (( aCellRangeAddress.EndColumn - aCellRangeAddress.StartColumn )/2 );
611 sal_Int32 nRow = aCellRangeAddress.StartRow + (( aCellRangeAddress.EndRow - aCellRangeAddress.StartRow )/2 );
612 m_xViewFreezable->freezeAtPosition( nColumn, nRow );
616 ::sal_Bool SAL_CALL
617 ScVbaWindow::getSplit() throw (uno::RuntimeException)
619 return m_xViewSplitable->getIsWindowSplit();
622 void SAL_CALL
623 ScVbaWindow::setSplit( ::sal_Bool _bSplit ) throw (uno::RuntimeException)
625 if( !_bSplit )
627 m_xViewSplitable->splitAtPosition(0,0);
629 else
631 uno::Reference< excel::XRange > xRange = ActiveCell();
632 sal_Int32 nRow = xRange->getRow();
633 sal_Int32 nColumn = xRange->getColumn();
634 m_xViewFreezable->freezeAtPosition( nColumn-1, nRow-1 );
635 SplitAtDefinedPosition( sal_True );
639 sal_Int32 SAL_CALL
640 ScVbaWindow::getSplitColumn() throw (uno::RuntimeException)
642 return m_xViewSplitable->getSplitColumn();
645 void SAL_CALL
646 ScVbaWindow::setSplitColumn( sal_Int32 _splitcolumn ) throw (uno::RuntimeException)
648 if( getSplitColumn() != _splitcolumn )
650 sal_Bool bFrozen = getFreezePanes();
651 sal_Int32 nRow = getSplitRow();
652 m_xViewFreezable->freezeAtPosition( _splitcolumn, nRow );
653 SplitAtDefinedPosition( !bFrozen );
657 double SAL_CALL
658 ScVbaWindow::getSplitHorizontal() throw (uno::RuntimeException)
660 double fSplitHorizontal = m_xViewSplitable->getSplitHorizontal();
661 double fHoriPoints = PixelsToPoints( m_xDevice, fSplitHorizontal, sal_True );
662 return fHoriPoints;
665 void SAL_CALL
666 ScVbaWindow::setSplitHorizontal( double _splithorizontal ) throw (uno::RuntimeException)
668 double fHoriPixels = PointsToPixels( m_xDevice, _splithorizontal, sal_True );
669 m_xViewSplitable->splitAtPosition( static_cast<sal_Int32>( fHoriPixels ), 0 );
672 sal_Int32 SAL_CALL
673 ScVbaWindow::getSplitRow() throw (uno::RuntimeException)
675 sal_Int32 nValue = m_xViewSplitable->getSplitRow();
676 return nValue ? nValue - 1 : nValue;
679 void SAL_CALL
680 ScVbaWindow::setSplitRow( sal_Int32 _splitrow ) throw (uno::RuntimeException)
682 if( getSplitRow() != _splitrow )
684 sal_Bool bFrozen = getFreezePanes();
685 sal_Int32 nColumn = getSplitColumn();
686 m_xViewFreezable->freezeAtPosition( nColumn , _splitrow );
687 SplitAtDefinedPosition( !bFrozen );
691 double SAL_CALL
692 ScVbaWindow::getSplitVertical() throw (uno::RuntimeException)
694 double fSplitVertical = m_xViewSplitable->getSplitVertical();
695 double fVertiPoints = PixelsToPoints( m_xDevice, fSplitVertical, sal_False );
696 return fVertiPoints;
699 void SAL_CALL
700 ScVbaWindow::setSplitVertical(double _splitvertical ) throw (uno::RuntimeException)
702 double fVertiPixels = PointsToPixels( m_xDevice, _splitvertical, sal_False );
703 m_xViewSplitable->splitAtPosition( 0, static_cast<sal_Int32>( fVertiPixels ) );
706 void ScVbaWindow::SplitAtDefinedPosition(sal_Bool _bUnFreezePane)
708 sal_Int32 nVertSplit = m_xViewSplitable->getSplitVertical();
709 sal_Int32 nHoriSplit = m_xViewSplitable->getSplitHorizontal();
710 if( _bUnFreezePane )
712 m_xViewFreezable->freezeAtPosition(0,0);
714 m_xViewSplitable->splitAtPosition(nHoriSplit, nVertSplit);
717 uno::Any SAL_CALL
718 ScVbaWindow::getZoom() throw (uno::RuntimeException)
720 uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
721 rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_ZOOMTYPE ) );
722 sal_Int16 nZoomType = view::DocumentZoomType::PAGE_WIDTH;
723 xProps->getPropertyValue( sName ) >>= nZoomType;
724 if( nZoomType == view::DocumentZoomType::PAGE_WIDTH )
726 return uno::makeAny( sal_True );
728 else if( nZoomType == view::DocumentZoomType::BY_VALUE )
730 sName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(SC_UNO_ZOOMVALUE));
731 sal_Int16 nZoom = 100;
732 xProps->getPropertyValue( sName ) >>= nZoom;
733 return uno::makeAny( nZoom );
735 return uno::Any();
738 void SAL_CALL
739 ScVbaWindow::setZoom( const uno::Any& _zoom ) throw (uno::RuntimeException)
741 sal_Int16 nZoom = 100;
742 _zoom >>= nZoom;
743 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( m_xModel, uno::UNO_QUERY_THROW );
744 uno::Reference< excel::XWorksheet > xActiveSheet = ActiveSheet();
745 SCTAB nTab = 0;
746 rtl::OUString sName = xActiveSheet->getName();
747 bool bSheetExists = nameExists (xSpreadDoc, sName, nTab);
748 if ( !bSheetExists )
749 throw uno::RuntimeException();
750 std::vector< SCTAB > vTabs;
751 vTabs.push_back( nTab );
752 excel::implSetZoom( m_xModel, nZoom, vTabs );
755 uno::Reference< excel::XWorksheet > SAL_CALL
756 ScVbaWindow::ActiveSheet( ) throw (script::BasicErrorException, uno::RuntimeException)
758 uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
759 return xApplication->getActiveSheet();
762 uno::Any SAL_CALL
763 ScVbaWindow::getView() throw (uno::RuntimeException)
765 // not supported now
766 sal_Int32 nWindowView = excel::XlWindowView::xlNormalView;
767 return uno::makeAny( nWindowView );
770 void SAL_CALL
771 ScVbaWindow::setView( const uno::Any& _view) throw (uno::RuntimeException)
773 sal_Int32 nWindowView = excel::XlWindowView::xlNormalView;
774 _view >>= nWindowView;
775 USHORT nSlot = FID_NORMALVIEWMODE;
776 switch ( nWindowView )
778 case excel::XlWindowView::xlNormalView:
779 nSlot = FID_NORMALVIEWMODE;
780 break;
781 case excel::XlWindowView::xlPageBreakPreview:
782 nSlot = FID_PAGEBREAKMODE;
783 break;
784 default:
785 DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
787 ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
788 if ( pViewShell )
789 dispatchExecute( pViewShell, nSlot );
792 sal_Int32 SAL_CALL
793 ScVbaWindow::PointsToScreenPixelsX(sal_Int32 _points) throw (css::script::BasicErrorException, css::uno::RuntimeException)
795 sal_Int32 nHundredthsofOneMillimeters = Millimeter::getInHundredthsOfOneMillimeter( _points );
796 double fConvertFactor = (m_xDevice->getInfo().PixelPerMeterX/100000);
797 return static_cast<sal_Int32>(fConvertFactor * nHundredthsofOneMillimeters );
800 sal_Int32 SAL_CALL
801 ScVbaWindow::PointsToScreenPixelsY(sal_Int32 _points) throw (css::script::BasicErrorException, css::uno::RuntimeException)
803 sal_Int32 nHundredthsofOneMillimeters = Millimeter::getInHundredthsOfOneMillimeter( _points );
804 double fConvertFactor = (m_xDevice->getInfo().PixelPerMeterY/100000);
805 return static_cast<sal_Int32>(fConvertFactor * nHundredthsofOneMillimeters );
808 void SAL_CALL
809 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)
811 // need test, print current active sheet
812 PrintOutHelper( excel::getBestViewShell( m_xModel ), From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, sal_True );
815 void SAL_CALL
816 ScVbaWindow::PrintPreview( const css::uno::Any& EnableChanges ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
818 // need test, print preview current active sheet
819 PrintPreviewHelper( EnableChanges, excel::getBestViewShell( m_xModel ) );
822 rtl::OUString&
823 ScVbaWindow::getServiceImplName()
825 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaWindow") );
826 return sImplName;
829 uno::Sequence< rtl::OUString >
830 ScVbaWindow::getServiceNames()
832 static uno::Sequence< rtl::OUString > aServiceNames;
833 if ( aServiceNames.getLength() == 0 )
835 aServiceNames.realloc( 1 );
836 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Window" ) );
838 return aServiceNames;
840 namespace window
842 namespace sdecl = comphelper::service_decl;
843 sdecl::vba_service_class_<ScVbaWindow, sdecl::with_args<true> > serviceImpl;
844 extern sdecl::ServiceDecl const serviceDecl(
845 serviceImpl,
846 "ScVbaWindow",
847 "ooo.vba.excel.Window" );