1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vbawindow.cxx,v $
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>
49 #include <tabvwsh.hxx>
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
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
83 uno::Reference
< uno::XComponentContext
> m_xContext
;
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();
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
;
115 uno::Reference
< frame::XModel
> m_xModel
;
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() );
121 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot obtain current document" ) ), uno::Reference
< uno::XInterface
>() );
122 ScDocShell
* pDocShell
= (ScDocShell
*)pModel
->GetEmbeddedObject();
124 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot obtain docshell" ) ), uno::Reference
< uno::XInterface
>() );
125 ScTabViewShell
* pViewShell
= excel::getBestViewShell( m_xModel
);
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
);
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
++;
150 virtual uno::Reference
< container::XEnumeration
> SAL_CALL
createEnumeration( ) throw (uno::RuntimeException
)
152 return new SelectedSheetsEnum( m_xContext
, sheets
, m_xModel
);
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
)
162 || static_cast< Sheets::size_type
>( Index
) >= sheets
.size() )
163 throw lang::IndexOutOfBoundsException();
165 return uno::makeAny( sheets
[ Index
] );
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);
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
;
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
)
214 ScVbaWindow::ScVbaWindow( uno::Sequence
< uno::Any
> const & args
, uno::Reference
< uno::XComponentContext
> const & xContext
)
215 : WindowImpl_BASE( args
, xContext
)
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
);
232 ScVbaWindow::Scroll( const uno::Any
& Down
, const uno::Any
& Up
, const uno::Any
& ToRight
, const uno::Any
& ToLeft
, bool bLargeScroll
) throw (uno::RuntimeException
)
235 m_xPane
->LargeScroll( Down
, Up
, ToRight
, ToLeft
);
237 m_xPane
->SmallScroll( Down
, Up
, ToRight
, ToLeft
);
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
);
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 );
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
);
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
278 else if ( bPosition )
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
);
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
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(".") );
325 if ( sName
.indexOf( sTitle
) == 0 )
326 // extention starts immediately after
327 if ( sName
.match( sDot
, sTitle
.getLength() ) )
332 return uno::makeAny( sTitle
);
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
);
345 ScVbaWindow::getScrollRow() throw (uno::RuntimeException
)
347 sal_Int32 nValue
= 0;
348 ScTabViewShell
* pViewShell
= excel::getBestViewShell( m_xModel
);
351 ScSplitPos eWhich
= pViewShell
->GetViewData()->GetActivePart();
352 nValue
= pViewShell
->GetViewData()->GetPosY(WhichV(eWhich
));
355 return uno::makeAny( nValue
+ 1);
359 ScVbaWindow::setScrollRow( const uno::Any
& _scrollrow
) throw (uno::RuntimeException
)
361 ScTabViewShell
* pViewShell
= excel::getBestViewShell( m_xModel
);
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
);
373 ScVbaWindow::getScrollColumn() throw (uno::RuntimeException
)
375 sal_Int32 nValue
= 0;
376 ScTabViewShell
* pViewShell
= excel::getBestViewShell( m_xModel
);
379 ScSplitPos eWhich
= pViewShell
->GetViewData()->GetActivePart();
380 nValue
= pViewShell
->GetViewData()->GetPosX(WhichH(eWhich
));
383 return uno::makeAny( nValue
+ 1);
387 ScVbaWindow::setScrollColumn( const uno::Any
& _scrollcolumn
) throw (uno::RuntimeException
)
389 ScTabViewShell
* pViewShell
= excel::getBestViewShell( m_xModel
);
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);
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() );
409 WorkWindow
* pWork
= (WorkWindow
*) pTop
->GetTopFrame_Impl()->GetSystemWindow();
412 if ( pWork
-> IsMaximized())
413 nwindowState
= xlMaximized
;
414 else if (pWork
-> IsMinimized())
415 nwindowState
= xlMinimized
;
418 return uno::makeAny( nwindowState
);
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() );
431 WorkWindow
* pWork
= (WorkWindow
*) pTop
->GetTopFrame_Impl()->GetSystemWindow();
434 if ( nwindowState
== xlMaximized
)
436 else if (nwindowState
== xlMinimized
)
438 else if (nwindowState
== xlNormal
)
441 throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Invalid Parameter" ) ), uno::Reference
< uno::XInterface
>() );
447 ScVbaWindow::Activate() throw (css::uno::RuntimeException
)
449 ScVbaWorkbook
workbook( uno::Reference
< XHelperInterface
>( Application(), uno::UNO_QUERY_THROW
), mxContext
, m_xModel
);
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();
475 ScVbaWindow::Selection( ) throw (script::BasicErrorException
, uno::RuntimeException
)
477 uno::Reference
< excel::XApplication
> xApplication( Application(), uno::UNO_QUERY_THROW
);
478 return xApplication
->getSelection();
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
;
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
));
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
;
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
));
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
;
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
));
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
;
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
));
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
;
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
));
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
;
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
));
591 ScVbaWindow::getFreezePanes() throw (uno::RuntimeException
)
593 return m_xViewFreezable
->hasFrozenPanes();
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
);
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
);
617 ScVbaWindow::getSplit() throw (uno::RuntimeException
)
619 return m_xViewSplitable
->getIsWindowSplit();
623 ScVbaWindow::setSplit( ::sal_Bool _bSplit
) throw (uno::RuntimeException
)
627 m_xViewSplitable
->splitAtPosition(0,0);
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
);
640 ScVbaWindow::getSplitColumn() throw (uno::RuntimeException
)
642 return m_xViewSplitable
->getSplitColumn();
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
);
658 ScVbaWindow::getSplitHorizontal() throw (uno::RuntimeException
)
660 double fSplitHorizontal
= m_xViewSplitable
->getSplitHorizontal();
661 double fHoriPoints
= PixelsToPoints( m_xDevice
, fSplitHorizontal
, sal_True
);
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 );
673 ScVbaWindow::getSplitRow() throw (uno::RuntimeException
)
675 sal_Int32 nValue
= m_xViewSplitable
->getSplitRow();
676 return nValue
? nValue
- 1 : nValue
;
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
);
692 ScVbaWindow::getSplitVertical() throw (uno::RuntimeException
)
694 double fSplitVertical
= m_xViewSplitable
->getSplitVertical();
695 double fVertiPoints
= PixelsToPoints( m_xDevice
, fSplitVertical
, sal_False
);
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();
712 m_xViewFreezable
->freezeAtPosition(0,0);
714 m_xViewSplitable
->splitAtPosition(nHoriSplit
, nVertSplit
);
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
);
739 ScVbaWindow::setZoom( const uno::Any
& _zoom
) throw (uno::RuntimeException
)
741 sal_Int16 nZoom
= 100;
743 uno::Reference
<sheet::XSpreadsheetDocument
> xSpreadDoc( m_xModel
, uno::UNO_QUERY_THROW
);
744 uno::Reference
< excel::XWorksheet
> xActiveSheet
= ActiveSheet();
746 rtl::OUString sName
= xActiveSheet
->getName();
747 bool bSheetExists
= nameExists (xSpreadDoc
, sName
, nTab
);
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();
763 ScVbaWindow::getView() throw (uno::RuntimeException
)
766 sal_Int32 nWindowView
= excel::XlWindowView::xlNormalView
;
767 return uno::makeAny( nWindowView
);
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
;
781 case excel::XlWindowView::xlPageBreakPreview
:
782 nSlot
= FID_PAGEBREAKMODE
;
785 DebugHelper::exception(SbERR_BAD_PARAMETER
, rtl::OUString() );
787 ScTabViewShell
* pViewShell
= excel::getBestViewShell( m_xModel
);
789 dispatchExecute( pViewShell
, nSlot
);
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
);
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
);
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
);
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
) );
823 ScVbaWindow::getServiceImplName()
825 static rtl::OUString
sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaWindow") );
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
;
842 namespace sdecl
= comphelper::service_decl
;
843 sdecl::vba_service_class_
<ScVbaWindow
, sdecl::with_args
<true> > serviceImpl
;
844 extern sdecl::ServiceDecl
const serviceDecl(
847 "ooo.vba.excel.Window" );