1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir #include <vbahelper/helperdecl.hxx> 28*cdf0e10cSrcweir #include "vbawindow.hxx" 29*cdf0e10cSrcweir #include "vbaworksheets.hxx" 30*cdf0e10cSrcweir #include "vbaworksheet.hxx" 31*cdf0e10cSrcweir #include "vbaglobals.hxx" 32*cdf0e10cSrcweir #include "vbapane.hxx" 33*cdf0e10cSrcweir #include <com/sun/star/sheet/XSpreadsheetDocument.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/sheet/XSpreadsheet.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/view/DocumentZoomType.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/table/CellRangeAddress.hpp> 38*cdf0e10cSrcweir #include <ooo/vba/excel/XlWindowState.hpp> 39*cdf0e10cSrcweir #include <ooo/vba/excel/XlWindowView.hpp> 40*cdf0e10cSrcweir #include <ooo/vba/excel/Constants.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/awt/XWindow2.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp> 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir #include <docsh.hxx> 46*cdf0e10cSrcweir #include <tabvwsh.hxx> 47*cdf0e10cSrcweir #include <docuno.hxx> 48*cdf0e10cSrcweir #include <sc.hrc> 49*cdf0e10cSrcweir #include <hash_map> 50*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 51*cdf0e10cSrcweir #include <vcl/wrkwin.hxx> 52*cdf0e10cSrcweir #include "unonames.hxx" 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir using namespace ::com::sun::star; 55*cdf0e10cSrcweir using namespace ::ooo::vba; 56*cdf0e10cSrcweir using namespace ::ooo::vba::excel::XlWindowState; 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir typedef std::hash_map< rtl::OUString, 59*cdf0e10cSrcweir SCTAB, ::rtl::OUStringHash, 60*cdf0e10cSrcweir ::std::equal_to< ::rtl::OUString > > NameIndexHash; 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir typedef std::vector< uno::Reference< sheet::XSpreadsheet > > Sheets; 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir typedef ::cppu::WeakImplHelper1< container::XEnumeration > Enumeration_BASE; 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir typedef ::cppu::WeakImplHelper3< container::XEnumerationAccess 67*cdf0e10cSrcweir , com::sun::star::container::XIndexAccess 68*cdf0e10cSrcweir , com::sun::star::container::XNameAccess 69*cdf0e10cSrcweir > SelectedSheets_BASE; 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir class SelectedSheetsEnum : public Enumeration_BASE 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir public: 75*cdf0e10cSrcweir uno::Reference< uno::XComponentContext > m_xContext; 76*cdf0e10cSrcweir Sheets m_sheets; 77*cdf0e10cSrcweir uno::Reference< frame::XModel > m_xModel; 78*cdf0e10cSrcweir Sheets::const_iterator m_it; 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir 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 ) 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir m_it = m_sheets.begin(); 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir // XEnumeration 85*cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir return m_it != m_sheets.end(); 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir if ( !hasMoreElements() ) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir throw container::NoSuchElementException(); 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir // #FIXME needs ThisWorkbook as parent 96*cdf0e10cSrcweir return uno::makeAny( uno::Reference< excel::XWorksheet > ( new ScVbaWorksheet( uno::Reference< XHelperInterface >(), m_xContext, *(m_it++), m_xModel ) ) ); 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir }; 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir class SelectedSheetsEnumAccess : public SelectedSheets_BASE 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir uno::Reference< uno::XComponentContext > m_xContext; 105*cdf0e10cSrcweir NameIndexHash namesToIndices; 106*cdf0e10cSrcweir Sheets sheets; 107*cdf0e10cSrcweir uno::Reference< frame::XModel > m_xModel; 108*cdf0e10cSrcweir public: 109*cdf0e10cSrcweir SelectedSheetsEnumAccess( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ):m_xContext( xContext ), m_xModel( xModel ) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir ScModelObj* pModel = static_cast< ScModelObj* >( m_xModel.get() ); 112*cdf0e10cSrcweir if ( !pModel ) 113*cdf0e10cSrcweir throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot obtain current document" ) ), uno::Reference< uno::XInterface >() ); 114*cdf0e10cSrcweir ScDocShell* pDocShell = (ScDocShell*)pModel->GetEmbeddedObject(); 115*cdf0e10cSrcweir if ( !pDocShell ) 116*cdf0e10cSrcweir throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot obtain docshell" ) ), uno::Reference< uno::XInterface >() ); 117*cdf0e10cSrcweir ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel ); 118*cdf0e10cSrcweir if ( !pViewShell ) 119*cdf0e10cSrcweir throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot obtain view shell" ) ), uno::Reference< uno::XInterface >() ); 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir SCTAB nTabCount = pDocShell->GetDocument()->GetTableCount(); 122*cdf0e10cSrcweir uno::Sequence<sal_Int32> aSheets( nTabCount ); 123*cdf0e10cSrcweir SCTAB nIndex = 0; 124*cdf0e10cSrcweir const ScMarkData& rMarkData = pViewShell->GetViewData()->GetMarkData(); 125*cdf0e10cSrcweir sheets.reserve( nTabCount ); 126*cdf0e10cSrcweir uno::Reference <sheet::XSpreadsheetDocument> xSpreadSheet( m_xModel, uno::UNO_QUERY_THROW ); 127*cdf0e10cSrcweir uno::Reference <container::XIndexAccess> xIndex( xSpreadSheet->getSheets(), uno::UNO_QUERY_THROW ); 128*cdf0e10cSrcweir for ( SCTAB nTab=0; nTab<nTabCount; nTab++ ) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir if ( rMarkData.GetTableSelect(nTab) ) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex( nTab ), uno::UNO_QUERY_THROW ); 133*cdf0e10cSrcweir uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW ); 134*cdf0e10cSrcweir sheets.push_back( xSheet ); 135*cdf0e10cSrcweir namesToIndices[ xNamed->getName() ] = nIndex++; 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir //XEnumerationAccess 142*cdf0e10cSrcweir virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir return new SelectedSheetsEnum( m_xContext, sheets, m_xModel ); 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir // XIndexAccess 147*cdf0e10cSrcweir virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir return sheets.size(); 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw ( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir if ( Index < 0 154*cdf0e10cSrcweir || static_cast< Sheets::size_type >( Index ) >= sheets.size() ) 155*cdf0e10cSrcweir throw lang::IndexOutOfBoundsException(); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir return uno::makeAny( sheets[ Index ] ); 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir //XElementAccess 161*cdf0e10cSrcweir virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir return excel::XWorksheet::static_type(0); 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir return (sheets.size() > 0); 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir //XNameAccess 172*cdf0e10cSrcweir virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir NameIndexHash::const_iterator it = namesToIndices.find( aName ); 175*cdf0e10cSrcweir if ( it == namesToIndices.end() ) 176*cdf0e10cSrcweir throw container::NoSuchElementException(); 177*cdf0e10cSrcweir return uno::makeAny( sheets[ it->second ] ); 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (uno::RuntimeException) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > names( namesToIndices.size() ); 184*cdf0e10cSrcweir ::rtl::OUString* pString = names.getArray(); 185*cdf0e10cSrcweir NameIndexHash::const_iterator it = namesToIndices.begin(); 186*cdf0e10cSrcweir NameIndexHash::const_iterator it_end = namesToIndices.end(); 187*cdf0e10cSrcweir for ( ; it != it_end; ++it, ++pString ) 188*cdf0e10cSrcweir *pString = it->first; 189*cdf0e10cSrcweir return names; 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (uno::RuntimeException) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir NameIndexHash::const_iterator it = namesToIndices.find( aName ); 195*cdf0e10cSrcweir return (it != namesToIndices.end()); 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir }; 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir ScVbaWindow::ScVbaWindow( 202*cdf0e10cSrcweir const uno::Reference< XHelperInterface >& xParent, 203*cdf0e10cSrcweir const uno::Reference< uno::XComponentContext >& xContext, 204*cdf0e10cSrcweir const uno::Reference< frame::XModel >& xModel, 205*cdf0e10cSrcweir const uno::Reference< frame::XController >& xController ) throw (uno::RuntimeException) : 206*cdf0e10cSrcweir WindowImpl_BASE( xParent, xContext, xModel, xController ) 207*cdf0e10cSrcweir { 208*cdf0e10cSrcweir init(); 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir ScVbaWindow::ScVbaWindow( 212*cdf0e10cSrcweir const uno::Sequence< uno::Any >& args, 213*cdf0e10cSrcweir const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException) : 214*cdf0e10cSrcweir WindowImpl_BASE( args, xContext ) 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir init(); 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir void 220*cdf0e10cSrcweir ScVbaWindow::init() 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir /* This method is called from the constructor, thus the own refcount is 223*cdf0e10cSrcweir still zero. The implementation of ActivePane() uses a UNO reference of 224*cdf0e10cSrcweir this (to set this window as parent of the pane obejct). This requires 225*cdf0e10cSrcweir the own refcount to be non-zero, otherwise this instance will be 226*cdf0e10cSrcweir desctructed immediately! Guard the call to ActivePane() in try/catch to 227*cdf0e10cSrcweir not miss the decrementation of the reference count on exception. */ 228*cdf0e10cSrcweir osl_incrementInterlockedCount( &m_refCount ); 229*cdf0e10cSrcweir try 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir m_xPane = ActivePane(); 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir catch( uno::Exception& ) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir osl_decrementInterlockedCount( &m_refCount ); 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > 240*cdf0e10cSrcweir ScVbaWindow::getControllerProps() throw (uno::RuntimeException) 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir return uno::Reference< beans::XPropertySet >( getController(), uno::UNO_QUERY_THROW ); 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > 246*cdf0e10cSrcweir ScVbaWindow::getFrameProps() throw (uno::RuntimeException) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir return uno::Reference< beans::XPropertySet >( getController()->getFrame(), uno::UNO_QUERY_THROW ); 249*cdf0e10cSrcweir } 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir uno::Reference< awt::XDevice > 252*cdf0e10cSrcweir ScVbaWindow::getDevice() throw (uno::RuntimeException) 253*cdf0e10cSrcweir { 254*cdf0e10cSrcweir return uno::Reference< awt::XDevice >( getWindow(), uno::UNO_QUERY_THROW ); 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir void 258*cdf0e10cSrcweir ScVbaWindow::Scroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft, bool bLargeScroll ) throw (uno::RuntimeException) 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir if( !m_xPane.is() ) 261*cdf0e10cSrcweir throw uno::RuntimeException(); 262*cdf0e10cSrcweir if( bLargeScroll ) 263*cdf0e10cSrcweir m_xPane->LargeScroll( Down, Up, ToRight, ToLeft ); 264*cdf0e10cSrcweir else 265*cdf0e10cSrcweir m_xPane->SmallScroll( Down, Up, ToRight, ToLeft ); 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir void SAL_CALL 269*cdf0e10cSrcweir ScVbaWindow::SmallScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException) 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir Scroll( Down, Up, ToRight, ToLeft ); 272*cdf0e10cSrcweir } 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir void SAL_CALL 275*cdf0e10cSrcweir ScVbaWindow::LargeScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException) 276*cdf0e10cSrcweir { 277*cdf0e10cSrcweir Scroll( Down, Up, ToRight, ToLeft, true ); 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir uno::Any SAL_CALL 281*cdf0e10cSrcweir ScVbaWindow::SelectedSheets( const uno::Any& aIndex ) throw (uno::RuntimeException) 282*cdf0e10cSrcweir { 283*cdf0e10cSrcweir uno::Reference< container::XEnumerationAccess > xEnumAccess( new SelectedSheetsEnumAccess( mxContext, m_xModel ) ); 284*cdf0e10cSrcweir // #FIXME needs a workbook as a parent 285*cdf0e10cSrcweir uno::Reference< excel::XWorksheets > xSheets( new ScVbaWorksheets( uno::Reference< XHelperInterface >(), mxContext, xEnumAccess, m_xModel ) ); 286*cdf0e10cSrcweir if ( aIndex.hasValue() ) 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir uno::Reference< XCollection > xColl( xSheets, uno::UNO_QUERY_THROW ); 289*cdf0e10cSrcweir return xColl->Item( aIndex, uno::Any() ); 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir return uno::makeAny( xSheets ); 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir void SAL_CALL 295*cdf0e10cSrcweir ScVbaWindow::ScrollWorkbookTabs( const uno::Any& /*Sheets*/, const uno::Any& /*Position*/ ) throw (uno::RuntimeException) 296*cdf0e10cSrcweir { 297*cdf0e10cSrcweir // #TODO #FIXME need some implementation to scroll through the tabs 298*cdf0e10cSrcweir // but where is this done? 299*cdf0e10cSrcweir /* 300*cdf0e10cSrcweir sal_Int32 nSheets = 0; 301*cdf0e10cSrcweir sal_Int32 nPosition = 0; 302*cdf0e10cSrcweir throw uno::RuntimeException( rtl::OUString::createFromAscii("No Implemented" ), uno::Reference< uno::XInterface >() ); 303*cdf0e10cSrcweir sal_Bool bSheets = ( Sheets >>= nSheets ); 304*cdf0e10cSrcweir sal_Bool bPosition = ( Position >>= nPosition ); 305*cdf0e10cSrcweir if ( bSheets || bPosition ) // at least one param specified 306*cdf0e10cSrcweir if ( bSheets ) 307*cdf0e10cSrcweir ;// use sheets 308*cdf0e10cSrcweir else if ( bPosition ) 309*cdf0e10cSrcweir ; //use position 310*cdf0e10cSrcweir */ 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir uno::Any SAL_CALL 315*cdf0e10cSrcweir ScVbaWindow::getCaption() throw (uno::RuntimeException) 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir static rtl::OUString sCrud(RTL_CONSTASCII_USTRINGPARAM(" - OpenOffice.org Calc" ) ); 318*cdf0e10cSrcweir static sal_Int32 nCrudLen = sCrud.getLength(); 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir rtl::OUString sTitle; 321*cdf0e10cSrcweir getFrameProps()->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SC_UNONAME_TITLE ) ) ) >>= sTitle; 322*cdf0e10cSrcweir sal_Int32 nCrudIndex = sTitle.indexOf( sCrud ); 323*cdf0e10cSrcweir // adjust title ( by removing crud ) 324*cdf0e10cSrcweir // sCrud string present 325*cdf0e10cSrcweir if ( nCrudIndex != -1 ) 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir // and ends with sCrud 328*cdf0e10cSrcweir if ( ( nCrudLen + nCrudIndex ) == sTitle.getLength() ) 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir sTitle = sTitle.copy( 0, nCrudIndex ); 331*cdf0e10cSrcweir ScVbaWorkbook workbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel ); 332*cdf0e10cSrcweir rtl::OUString sName = workbook.getName(); 333*cdf0e10cSrcweir // rather bizare hack to make sure the name behavior 334*cdf0e10cSrcweir // is like XL 335*cdf0e10cSrcweir // if the adjusted title == workbook name, use name 336*cdf0e10cSrcweir // if the adjusted title != workbook name but ... 337*cdf0e10cSrcweir // name == title + extension ( .csv, ,odt, .xls ) 338*cdf0e10cSrcweir // etc. then also use the name 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir if ( !sTitle.equals( sName ) ) 341*cdf0e10cSrcweir { 342*cdf0e10cSrcweir static rtl::OUString sDot( RTL_CONSTASCII_USTRINGPARAM(".") ); 343*cdf0e10cSrcweir // starts with title 344*cdf0e10cSrcweir if ( sName.indexOf( sTitle ) == 0 ) 345*cdf0e10cSrcweir // extention starts immediately after 346*cdf0e10cSrcweir if ( sName.match( sDot, sTitle.getLength() ) ) 347*cdf0e10cSrcweir sTitle = sName; 348*cdf0e10cSrcweir } 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir return uno::makeAny( sTitle ); 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir void SAL_CALL 355*cdf0e10cSrcweir ScVbaWindow::setCaption( const uno::Any& _caption ) throw (uno::RuntimeException) 356*cdf0e10cSrcweir { 357*cdf0e10cSrcweir getFrameProps()->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_TITLE ) ), _caption ); 358*cdf0e10cSrcweir } 359*cdf0e10cSrcweir 360*cdf0e10cSrcweir uno::Any SAL_CALL 361*cdf0e10cSrcweir ScVbaWindow::getScrollRow() throw (uno::RuntimeException) 362*cdf0e10cSrcweir { 363*cdf0e10cSrcweir sal_Int32 nValue = 0; 364*cdf0e10cSrcweir // !! TODO !! get view shell from controller 365*cdf0e10cSrcweir ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel ); 366*cdf0e10cSrcweir if ( pViewShell ) 367*cdf0e10cSrcweir { 368*cdf0e10cSrcweir ScSplitPos eWhich = pViewShell->GetViewData()->GetActivePart(); 369*cdf0e10cSrcweir nValue = pViewShell->GetViewData()->GetPosY(WhichV(eWhich)); 370*cdf0e10cSrcweir } 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir return uno::makeAny( nValue + 1); 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir void SAL_CALL 376*cdf0e10cSrcweir ScVbaWindow::setScrollRow( const uno::Any& _scrollrow ) throw (uno::RuntimeException) 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir // !! TODO !! get view shell from controller 379*cdf0e10cSrcweir ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel ); 380*cdf0e10cSrcweir if ( pViewShell ) 381*cdf0e10cSrcweir { 382*cdf0e10cSrcweir sal_Int32 scrollRow = 0; 383*cdf0e10cSrcweir _scrollrow >>= scrollRow; 384*cdf0e10cSrcweir ScSplitPos eWhich = pViewShell->GetViewData()->GetActivePart(); 385*cdf0e10cSrcweir sal_Int32 nOldValue = pViewShell->GetViewData()->GetPosY(WhichV(eWhich)) + 1; 386*cdf0e10cSrcweir pViewShell->ScrollLines(0, scrollRow - nOldValue); 387*cdf0e10cSrcweir } 388*cdf0e10cSrcweir } 389*cdf0e10cSrcweir 390*cdf0e10cSrcweir uno::Any SAL_CALL 391*cdf0e10cSrcweir ScVbaWindow::getScrollColumn() throw (uno::RuntimeException) 392*cdf0e10cSrcweir { 393*cdf0e10cSrcweir sal_Int32 nValue = 0; 394*cdf0e10cSrcweir // !! TODO !! get view shell from controller 395*cdf0e10cSrcweir ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel ); 396*cdf0e10cSrcweir if ( pViewShell ) 397*cdf0e10cSrcweir { 398*cdf0e10cSrcweir ScSplitPos eWhich = pViewShell->GetViewData()->GetActivePart(); 399*cdf0e10cSrcweir nValue = pViewShell->GetViewData()->GetPosX(WhichH(eWhich)); 400*cdf0e10cSrcweir } 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir return uno::makeAny( nValue + 1); 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir void SAL_CALL 406*cdf0e10cSrcweir ScVbaWindow::setScrollColumn( const uno::Any& _scrollcolumn ) throw (uno::RuntimeException) 407*cdf0e10cSrcweir { 408*cdf0e10cSrcweir // !! TODO !! get view shell from controller 409*cdf0e10cSrcweir ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel ); 410*cdf0e10cSrcweir if ( pViewShell ) 411*cdf0e10cSrcweir { 412*cdf0e10cSrcweir sal_Int32 scrollColumn = 0; 413*cdf0e10cSrcweir _scrollcolumn >>= scrollColumn; 414*cdf0e10cSrcweir ScSplitPos eWhich = pViewShell->GetViewData()->GetActivePart(); 415*cdf0e10cSrcweir sal_Int32 nOldValue = pViewShell->GetViewData()->GetPosX(WhichH(eWhich)) + 1; 416*cdf0e10cSrcweir pViewShell->ScrollLines(scrollColumn - nOldValue, 0); 417*cdf0e10cSrcweir } 418*cdf0e10cSrcweir } 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir uno::Any SAL_CALL 421*cdf0e10cSrcweir ScVbaWindow::getWindowState() throw (uno::RuntimeException) 422*cdf0e10cSrcweir { 423*cdf0e10cSrcweir sal_Int32 nwindowState = xlNormal; 424*cdf0e10cSrcweir // !! TODO !! get view shell from controller 425*cdf0e10cSrcweir ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel ); 426*cdf0e10cSrcweir SfxViewFrame* pViewFrame = pViewShell -> GetViewFrame(); 427*cdf0e10cSrcweir WorkWindow* pWork = (WorkWindow*) pViewFrame->GetFrame().GetSystemWindow(); 428*cdf0e10cSrcweir if ( pWork ) 429*cdf0e10cSrcweir { 430*cdf0e10cSrcweir if ( pWork -> IsMaximized()) 431*cdf0e10cSrcweir nwindowState = xlMaximized; 432*cdf0e10cSrcweir else if (pWork -> IsMinimized()) 433*cdf0e10cSrcweir nwindowState = xlMinimized; 434*cdf0e10cSrcweir } 435*cdf0e10cSrcweir return uno::makeAny( nwindowState ); 436*cdf0e10cSrcweir } 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir void SAL_CALL 439*cdf0e10cSrcweir ScVbaWindow::setWindowState( const uno::Any& _windowstate ) throw (uno::RuntimeException) 440*cdf0e10cSrcweir { 441*cdf0e10cSrcweir sal_Int32 nwindowState = xlMaximized; 442*cdf0e10cSrcweir _windowstate >>= nwindowState; 443*cdf0e10cSrcweir // !! TODO !! get view shell from controller 444*cdf0e10cSrcweir ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel ); 445*cdf0e10cSrcweir SfxViewFrame* pViewFrame = pViewShell -> GetViewFrame(); 446*cdf0e10cSrcweir WorkWindow* pWork = (WorkWindow*) pViewFrame->GetFrame().GetSystemWindow(); 447*cdf0e10cSrcweir if ( pWork ) 448*cdf0e10cSrcweir { 449*cdf0e10cSrcweir if ( nwindowState == xlMaximized) 450*cdf0e10cSrcweir pWork -> Maximize(); 451*cdf0e10cSrcweir else if (nwindowState == xlMinimized) 452*cdf0e10cSrcweir pWork -> Minimize(); 453*cdf0e10cSrcweir else if (nwindowState == xlNormal) 454*cdf0e10cSrcweir pWork -> Restore(); 455*cdf0e10cSrcweir else 456*cdf0e10cSrcweir throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Invalid Parameter" ) ), uno::Reference< uno::XInterface >() ); 457*cdf0e10cSrcweir } 458*cdf0e10cSrcweir } 459*cdf0e10cSrcweir 460*cdf0e10cSrcweir void 461*cdf0e10cSrcweir ScVbaWindow::Activate() throw (css::uno::RuntimeException) 462*cdf0e10cSrcweir { 463*cdf0e10cSrcweir ScVbaWorkbook workbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel ); 464*cdf0e10cSrcweir 465*cdf0e10cSrcweir workbook.Activate(); 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir void 469*cdf0e10cSrcweir ScVbaWindow::Close( const uno::Any& SaveChanges, const uno::Any& FileName, const uno::Any& RouteWorkBook ) throw (uno::RuntimeException) 470*cdf0e10cSrcweir { 471*cdf0e10cSrcweir ScVbaWorkbook workbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel ); 472*cdf0e10cSrcweir workbook.Close(SaveChanges, FileName, RouteWorkBook ); 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir 475*cdf0e10cSrcweir uno::Reference< excel::XPane > SAL_CALL 476*cdf0e10cSrcweir ScVbaWindow::ActivePane() throw (script::BasicErrorException, uno::RuntimeException) 477*cdf0e10cSrcweir { 478*cdf0e10cSrcweir uno::Reference< sheet::XViewPane > xViewPane( getController(), uno::UNO_QUERY_THROW ); 479*cdf0e10cSrcweir return new ScVbaPane( this, mxContext, m_xModel, xViewPane ); 480*cdf0e10cSrcweir } 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir uno::Reference< excel::XRange > SAL_CALL 483*cdf0e10cSrcweir ScVbaWindow::ActiveCell( ) throw (script::BasicErrorException, uno::RuntimeException) 484*cdf0e10cSrcweir { 485*cdf0e10cSrcweir uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW ); 486*cdf0e10cSrcweir return xApplication->getActiveCell(); 487*cdf0e10cSrcweir } 488*cdf0e10cSrcweir 489*cdf0e10cSrcweir uno::Any SAL_CALL 490*cdf0e10cSrcweir ScVbaWindow::Selection( ) throw (script::BasicErrorException, uno::RuntimeException) 491*cdf0e10cSrcweir { 492*cdf0e10cSrcweir uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW ); 493*cdf0e10cSrcweir return xApplication->getSelection(); 494*cdf0e10cSrcweir } 495*cdf0e10cSrcweir 496*cdf0e10cSrcweir uno::Reference< excel::XRange > SAL_CALL 497*cdf0e10cSrcweir ScVbaWindow::RangeSelection() throw (script::BasicErrorException, uno::RuntimeException) 498*cdf0e10cSrcweir { 499*cdf0e10cSrcweir /* TODO / FIXME: According to documentation, this method returns the range 500*cdf0e10cSrcweir selection even if shapes are selected. */ 501*cdf0e10cSrcweir return uno::Reference< excel::XRange >( Selection(), uno::UNO_QUERY_THROW ); 502*cdf0e10cSrcweir } 503*cdf0e10cSrcweir 504*cdf0e10cSrcweir ::sal_Bool SAL_CALL 505*cdf0e10cSrcweir ScVbaWindow::getDisplayGridlines() throw (uno::RuntimeException) 506*cdf0e10cSrcweir { 507*cdf0e10cSrcweir rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SHOWGRID ) ); 508*cdf0e10cSrcweir sal_Bool bGrid = sal_True; 509*cdf0e10cSrcweir getControllerProps()->getPropertyValue( sName ) >>= bGrid; 510*cdf0e10cSrcweir return bGrid; 511*cdf0e10cSrcweir } 512*cdf0e10cSrcweir 513*cdf0e10cSrcweir 514*cdf0e10cSrcweir void SAL_CALL 515*cdf0e10cSrcweir ScVbaWindow::setDisplayGridlines( ::sal_Bool _displaygridlines ) throw (uno::RuntimeException) 516*cdf0e10cSrcweir { 517*cdf0e10cSrcweir rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SHOWGRID ) ); 518*cdf0e10cSrcweir getControllerProps()->setPropertyValue( sName, uno::makeAny( _displaygridlines )); 519*cdf0e10cSrcweir } 520*cdf0e10cSrcweir 521*cdf0e10cSrcweir ::sal_Bool SAL_CALL 522*cdf0e10cSrcweir ScVbaWindow::getDisplayHeadings() throw (uno::RuntimeException) 523*cdf0e10cSrcweir { 524*cdf0e10cSrcweir rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_COLROWHDR ) ); 525*cdf0e10cSrcweir sal_Bool bHeading = sal_True; 526*cdf0e10cSrcweir getControllerProps()->getPropertyValue( sName ) >>= bHeading; 527*cdf0e10cSrcweir return bHeading; 528*cdf0e10cSrcweir } 529*cdf0e10cSrcweir 530*cdf0e10cSrcweir void SAL_CALL 531*cdf0e10cSrcweir ScVbaWindow::setDisplayHeadings( ::sal_Bool _bDisplayHeadings ) throw (uno::RuntimeException) 532*cdf0e10cSrcweir { 533*cdf0e10cSrcweir rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_COLROWHDR ) ); 534*cdf0e10cSrcweir getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayHeadings )); 535*cdf0e10cSrcweir } 536*cdf0e10cSrcweir 537*cdf0e10cSrcweir ::sal_Bool SAL_CALL 538*cdf0e10cSrcweir ScVbaWindow::getDisplayHorizontalScrollBar() throw (uno::RuntimeException) 539*cdf0e10cSrcweir { 540*cdf0e10cSrcweir rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_HORSCROLL ) ); 541*cdf0e10cSrcweir sal_Bool bHorizontalScrollBar = sal_True; 542*cdf0e10cSrcweir getControllerProps()->getPropertyValue( sName ) >>= bHorizontalScrollBar; 543*cdf0e10cSrcweir return bHorizontalScrollBar; 544*cdf0e10cSrcweir } 545*cdf0e10cSrcweir 546*cdf0e10cSrcweir void SAL_CALL 547*cdf0e10cSrcweir ScVbaWindow::setDisplayHorizontalScrollBar( ::sal_Bool _bDisplayHorizontalScrollBar ) throw (uno::RuntimeException) 548*cdf0e10cSrcweir { 549*cdf0e10cSrcweir rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_HORSCROLL ) ); 550*cdf0e10cSrcweir getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayHorizontalScrollBar )); 551*cdf0e10cSrcweir } 552*cdf0e10cSrcweir 553*cdf0e10cSrcweir ::sal_Bool SAL_CALL 554*cdf0e10cSrcweir ScVbaWindow::getDisplayOutline() throw (uno::RuntimeException) 555*cdf0e10cSrcweir { 556*cdf0e10cSrcweir rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_OUTLSYMB ) ); 557*cdf0e10cSrcweir sal_Bool bOutline = sal_True; 558*cdf0e10cSrcweir getControllerProps()->getPropertyValue( sName ) >>= bOutline; 559*cdf0e10cSrcweir return bOutline; 560*cdf0e10cSrcweir } 561*cdf0e10cSrcweir 562*cdf0e10cSrcweir void SAL_CALL 563*cdf0e10cSrcweir ScVbaWindow::setDisplayOutline( ::sal_Bool _bDisplayOutline ) throw (uno::RuntimeException) 564*cdf0e10cSrcweir { 565*cdf0e10cSrcweir rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_OUTLSYMB ) ); 566*cdf0e10cSrcweir getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayOutline )); 567*cdf0e10cSrcweir } 568*cdf0e10cSrcweir 569*cdf0e10cSrcweir ::sal_Bool SAL_CALL 570*cdf0e10cSrcweir ScVbaWindow::getDisplayVerticalScrollBar() throw (uno::RuntimeException) 571*cdf0e10cSrcweir { 572*cdf0e10cSrcweir rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_VERTSCROLL ) ); 573*cdf0e10cSrcweir sal_Bool bVerticalScrollBar = sal_True; 574*cdf0e10cSrcweir getControllerProps()->getPropertyValue( sName ) >>= bVerticalScrollBar; 575*cdf0e10cSrcweir return bVerticalScrollBar; 576*cdf0e10cSrcweir } 577*cdf0e10cSrcweir 578*cdf0e10cSrcweir void SAL_CALL 579*cdf0e10cSrcweir ScVbaWindow::setDisplayVerticalScrollBar( ::sal_Bool _bDisplayVerticalScrollBar ) throw (uno::RuntimeException) 580*cdf0e10cSrcweir { 581*cdf0e10cSrcweir rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_VERTSCROLL ) ); 582*cdf0e10cSrcweir getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayVerticalScrollBar )); 583*cdf0e10cSrcweir } 584*cdf0e10cSrcweir 585*cdf0e10cSrcweir ::sal_Bool SAL_CALL 586*cdf0e10cSrcweir ScVbaWindow::getDisplayWorkbookTabs() throw (uno::RuntimeException) 587*cdf0e10cSrcweir { 588*cdf0e10cSrcweir rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SHEETTABS ) ); 589*cdf0e10cSrcweir sal_Bool bWorkbookTabs = sal_True; 590*cdf0e10cSrcweir getControllerProps()->getPropertyValue( sName ) >>= bWorkbookTabs; 591*cdf0e10cSrcweir return bWorkbookTabs; 592*cdf0e10cSrcweir } 593*cdf0e10cSrcweir 594*cdf0e10cSrcweir void SAL_CALL 595*cdf0e10cSrcweir ScVbaWindow::setDisplayWorkbookTabs( ::sal_Bool _bDisplayWorkbookTabs ) throw (uno::RuntimeException) 596*cdf0e10cSrcweir { 597*cdf0e10cSrcweir rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SHEETTABS ) ); 598*cdf0e10cSrcweir getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayWorkbookTabs )); 599*cdf0e10cSrcweir } 600*cdf0e10cSrcweir 601*cdf0e10cSrcweir ::sal_Bool SAL_CALL 602*cdf0e10cSrcweir ScVbaWindow::getFreezePanes() throw (uno::RuntimeException) 603*cdf0e10cSrcweir { 604*cdf0e10cSrcweir uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW ); 605*cdf0e10cSrcweir return xViewFreezable->hasFrozenPanes(); 606*cdf0e10cSrcweir } 607*cdf0e10cSrcweir 608*cdf0e10cSrcweir void SAL_CALL 609*cdf0e10cSrcweir ScVbaWindow::setFreezePanes( ::sal_Bool /*_bFreezePanes*/ ) throw (uno::RuntimeException) 610*cdf0e10cSrcweir { 611*cdf0e10cSrcweir uno::Reference< sheet::XViewPane > xViewPane( getController(), uno::UNO_QUERY_THROW ); 612*cdf0e10cSrcweir uno::Reference< sheet::XViewSplitable > xViewSplitable( xViewPane, uno::UNO_QUERY_THROW ); 613*cdf0e10cSrcweir uno::Reference< sheet::XViewFreezable > xViewFreezable( xViewPane, uno::UNO_QUERY_THROW ); 614*cdf0e10cSrcweir if( xViewSplitable->getIsWindowSplit() ) 615*cdf0e10cSrcweir { 616*cdf0e10cSrcweir // if there is a split we freeze at the split 617*cdf0e10cSrcweir sal_Int32 nColumn = getSplitColumn(); 618*cdf0e10cSrcweir sal_Int32 nRow = getSplitRow(); 619*cdf0e10cSrcweir xViewFreezable->freezeAtPosition( nColumn, nRow ); 620*cdf0e10cSrcweir } 621*cdf0e10cSrcweir else 622*cdf0e10cSrcweir { 623*cdf0e10cSrcweir // otherwise we freeze in the center of the visible sheet 624*cdf0e10cSrcweir table::CellRangeAddress aCellRangeAddress = xViewPane->getVisibleRange(); 625*cdf0e10cSrcweir sal_Int32 nColumn = aCellRangeAddress.StartColumn + (( aCellRangeAddress.EndColumn - aCellRangeAddress.StartColumn )/2 ); 626*cdf0e10cSrcweir sal_Int32 nRow = aCellRangeAddress.StartRow + (( aCellRangeAddress.EndRow - aCellRangeAddress.StartRow )/2 ); 627*cdf0e10cSrcweir xViewFreezable->freezeAtPosition( nColumn, nRow ); 628*cdf0e10cSrcweir } 629*cdf0e10cSrcweir } 630*cdf0e10cSrcweir 631*cdf0e10cSrcweir ::sal_Bool SAL_CALL 632*cdf0e10cSrcweir ScVbaWindow::getSplit() throw (uno::RuntimeException) 633*cdf0e10cSrcweir { 634*cdf0e10cSrcweir uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW ); 635*cdf0e10cSrcweir return xViewSplitable->getIsWindowSplit(); 636*cdf0e10cSrcweir } 637*cdf0e10cSrcweir 638*cdf0e10cSrcweir void SAL_CALL 639*cdf0e10cSrcweir ScVbaWindow::setSplit( ::sal_Bool _bSplit ) throw (uno::RuntimeException) 640*cdf0e10cSrcweir { 641*cdf0e10cSrcweir if( !_bSplit ) 642*cdf0e10cSrcweir { 643*cdf0e10cSrcweir uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW ); 644*cdf0e10cSrcweir xViewSplitable->splitAtPosition(0,0); 645*cdf0e10cSrcweir } 646*cdf0e10cSrcweir else 647*cdf0e10cSrcweir { 648*cdf0e10cSrcweir uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW ); 649*cdf0e10cSrcweir uno::Reference< excel::XRange > xRange = ActiveCell(); 650*cdf0e10cSrcweir sal_Int32 nRow = xRange->getRow(); 651*cdf0e10cSrcweir sal_Int32 nColumn = xRange->getColumn(); 652*cdf0e10cSrcweir xViewFreezable->freezeAtPosition( nColumn-1, nRow-1 ); 653*cdf0e10cSrcweir SplitAtDefinedPosition( sal_True ); 654*cdf0e10cSrcweir } 655*cdf0e10cSrcweir } 656*cdf0e10cSrcweir 657*cdf0e10cSrcweir sal_Int32 SAL_CALL 658*cdf0e10cSrcweir ScVbaWindow::getSplitColumn() throw (uno::RuntimeException) 659*cdf0e10cSrcweir { 660*cdf0e10cSrcweir uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW ); 661*cdf0e10cSrcweir return xViewSplitable->getSplitColumn(); 662*cdf0e10cSrcweir } 663*cdf0e10cSrcweir 664*cdf0e10cSrcweir void SAL_CALL 665*cdf0e10cSrcweir ScVbaWindow::setSplitColumn( sal_Int32 _splitcolumn ) throw (uno::RuntimeException) 666*cdf0e10cSrcweir { 667*cdf0e10cSrcweir if( getSplitColumn() != _splitcolumn ) 668*cdf0e10cSrcweir { 669*cdf0e10cSrcweir uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW ); 670*cdf0e10cSrcweir sal_Bool bFrozen = getFreezePanes(); 671*cdf0e10cSrcweir sal_Int32 nRow = getSplitRow(); 672*cdf0e10cSrcweir xViewFreezable->freezeAtPosition( _splitcolumn, nRow ); 673*cdf0e10cSrcweir SplitAtDefinedPosition( !bFrozen ); 674*cdf0e10cSrcweir } 675*cdf0e10cSrcweir } 676*cdf0e10cSrcweir 677*cdf0e10cSrcweir double SAL_CALL 678*cdf0e10cSrcweir ScVbaWindow::getSplitHorizontal() throw (uno::RuntimeException) 679*cdf0e10cSrcweir { 680*cdf0e10cSrcweir uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW ); 681*cdf0e10cSrcweir return PixelsToPoints( getDevice(), xViewSplitable->getSplitHorizontal(), sal_True ); 682*cdf0e10cSrcweir } 683*cdf0e10cSrcweir 684*cdf0e10cSrcweir void SAL_CALL 685*cdf0e10cSrcweir ScVbaWindow::setSplitHorizontal( double _splithorizontal ) throw (uno::RuntimeException) 686*cdf0e10cSrcweir { 687*cdf0e10cSrcweir uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW ); 688*cdf0e10cSrcweir double fHoriPixels = PointsToPixels( getDevice(), _splithorizontal, sal_True ); 689*cdf0e10cSrcweir xViewSplitable->splitAtPosition( static_cast< sal_Int32 >( fHoriPixels ), 0 ); 690*cdf0e10cSrcweir } 691*cdf0e10cSrcweir 692*cdf0e10cSrcweir sal_Int32 SAL_CALL 693*cdf0e10cSrcweir ScVbaWindow::getSplitRow() throw (uno::RuntimeException) 694*cdf0e10cSrcweir { 695*cdf0e10cSrcweir uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW ); 696*cdf0e10cSrcweir sal_Int32 nValue = xViewSplitable->getSplitRow(); 697*cdf0e10cSrcweir return nValue ? nValue - 1 : nValue; 698*cdf0e10cSrcweir } 699*cdf0e10cSrcweir 700*cdf0e10cSrcweir void SAL_CALL 701*cdf0e10cSrcweir ScVbaWindow::setSplitRow( sal_Int32 _splitrow ) throw (uno::RuntimeException) 702*cdf0e10cSrcweir { 703*cdf0e10cSrcweir if( getSplitRow() != _splitrow ) 704*cdf0e10cSrcweir { 705*cdf0e10cSrcweir uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW ); 706*cdf0e10cSrcweir sal_Bool bFrozen = getFreezePanes(); 707*cdf0e10cSrcweir sal_Int32 nColumn = getSplitColumn(); 708*cdf0e10cSrcweir xViewFreezable->freezeAtPosition( nColumn , _splitrow ); 709*cdf0e10cSrcweir SplitAtDefinedPosition( !bFrozen ); 710*cdf0e10cSrcweir } 711*cdf0e10cSrcweir } 712*cdf0e10cSrcweir 713*cdf0e10cSrcweir double SAL_CALL 714*cdf0e10cSrcweir ScVbaWindow::getSplitVertical() throw (uno::RuntimeException) 715*cdf0e10cSrcweir { 716*cdf0e10cSrcweir uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW ); 717*cdf0e10cSrcweir return PixelsToPoints( getDevice(), xViewSplitable->getSplitVertical(), sal_False ); 718*cdf0e10cSrcweir } 719*cdf0e10cSrcweir 720*cdf0e10cSrcweir void SAL_CALL 721*cdf0e10cSrcweir ScVbaWindow::setSplitVertical(double _splitvertical ) throw (uno::RuntimeException) 722*cdf0e10cSrcweir { 723*cdf0e10cSrcweir uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW ); 724*cdf0e10cSrcweir double fVertiPixels = PointsToPixels( getDevice(), _splitvertical, sal_False ); 725*cdf0e10cSrcweir xViewSplitable->splitAtPosition( 0, static_cast<sal_Int32>( fVertiPixels ) ); 726*cdf0e10cSrcweir } 727*cdf0e10cSrcweir 728*cdf0e10cSrcweir void ScVbaWindow::SplitAtDefinedPosition(sal_Bool _bUnFreezePane) 729*cdf0e10cSrcweir { 730*cdf0e10cSrcweir uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW ); 731*cdf0e10cSrcweir uno::Reference< sheet::XViewFreezable > xViewFreezable( xViewSplitable, uno::UNO_QUERY_THROW ); 732*cdf0e10cSrcweir sal_Int32 nVertSplit = xViewSplitable->getSplitVertical(); 733*cdf0e10cSrcweir sal_Int32 nHoriSplit = xViewSplitable->getSplitHorizontal(); 734*cdf0e10cSrcweir if( _bUnFreezePane ) 735*cdf0e10cSrcweir xViewFreezable->freezeAtPosition(0,0); 736*cdf0e10cSrcweir xViewSplitable->splitAtPosition(nHoriSplit, nVertSplit); 737*cdf0e10cSrcweir } 738*cdf0e10cSrcweir 739*cdf0e10cSrcweir uno::Any SAL_CALL 740*cdf0e10cSrcweir ScVbaWindow::getZoom() throw (uno::RuntimeException) 741*cdf0e10cSrcweir { 742*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProps = getControllerProps(); 743*cdf0e10cSrcweir rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_ZOOMTYPE ) ); 744*cdf0e10cSrcweir sal_Int16 nZoomType = view::DocumentZoomType::PAGE_WIDTH; 745*cdf0e10cSrcweir xProps->getPropertyValue( sName ) >>= nZoomType; 746*cdf0e10cSrcweir if( nZoomType == view::DocumentZoomType::PAGE_WIDTH ) 747*cdf0e10cSrcweir { 748*cdf0e10cSrcweir return uno::makeAny( sal_True ); 749*cdf0e10cSrcweir } 750*cdf0e10cSrcweir else if( nZoomType == view::DocumentZoomType::BY_VALUE ) 751*cdf0e10cSrcweir { 752*cdf0e10cSrcweir sName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(SC_UNO_ZOOMVALUE)); 753*cdf0e10cSrcweir sal_Int16 nZoom = 100; 754*cdf0e10cSrcweir xProps->getPropertyValue( sName ) >>= nZoom; 755*cdf0e10cSrcweir return uno::makeAny( nZoom ); 756*cdf0e10cSrcweir } 757*cdf0e10cSrcweir return uno::Any(); 758*cdf0e10cSrcweir } 759*cdf0e10cSrcweir 760*cdf0e10cSrcweir void SAL_CALL 761*cdf0e10cSrcweir ScVbaWindow::setZoom( const uno::Any& _zoom ) throw (uno::RuntimeException) 762*cdf0e10cSrcweir { 763*cdf0e10cSrcweir sal_Int16 nZoom = 100; 764*cdf0e10cSrcweir _zoom >>= nZoom; 765*cdf0e10cSrcweir uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( m_xModel, uno::UNO_QUERY_THROW ); 766*cdf0e10cSrcweir uno::Reference< excel::XWorksheet > xActiveSheet = ActiveSheet(); 767*cdf0e10cSrcweir SCTAB nTab = 0; 768*cdf0e10cSrcweir if ( !ScVbaWorksheets::nameExists (xSpreadDoc, xActiveSheet->getName(), nTab) ) 769*cdf0e10cSrcweir throw uno::RuntimeException(); 770*cdf0e10cSrcweir std::vector< SCTAB > vTabs; 771*cdf0e10cSrcweir vTabs.push_back( nTab ); 772*cdf0e10cSrcweir excel::implSetZoom( m_xModel, nZoom, vTabs ); 773*cdf0e10cSrcweir } 774*cdf0e10cSrcweir 775*cdf0e10cSrcweir uno::Reference< excel::XWorksheet > SAL_CALL 776*cdf0e10cSrcweir ScVbaWindow::ActiveSheet( ) throw (script::BasicErrorException, uno::RuntimeException) 777*cdf0e10cSrcweir { 778*cdf0e10cSrcweir uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW ); 779*cdf0e10cSrcweir return xApplication->getActiveSheet(); 780*cdf0e10cSrcweir } 781*cdf0e10cSrcweir 782*cdf0e10cSrcweir uno::Any SAL_CALL 783*cdf0e10cSrcweir ScVbaWindow::getView() throw (uno::RuntimeException) 784*cdf0e10cSrcweir { 785*cdf0e10cSrcweir // not supported now 786*cdf0e10cSrcweir sal_Int32 nWindowView = excel::XlWindowView::xlNormalView; 787*cdf0e10cSrcweir return uno::makeAny( nWindowView ); 788*cdf0e10cSrcweir } 789*cdf0e10cSrcweir 790*cdf0e10cSrcweir void SAL_CALL 791*cdf0e10cSrcweir ScVbaWindow::setView( const uno::Any& _view) throw (uno::RuntimeException) 792*cdf0e10cSrcweir { 793*cdf0e10cSrcweir sal_Int32 nWindowView = excel::XlWindowView::xlNormalView; 794*cdf0e10cSrcweir _view >>= nWindowView; 795*cdf0e10cSrcweir sal_uInt16 nSlot = FID_NORMALVIEWMODE; 796*cdf0e10cSrcweir switch ( nWindowView ) 797*cdf0e10cSrcweir { 798*cdf0e10cSrcweir case excel::XlWindowView::xlNormalView: 799*cdf0e10cSrcweir nSlot = FID_NORMALVIEWMODE; 800*cdf0e10cSrcweir break; 801*cdf0e10cSrcweir case excel::XlWindowView::xlPageBreakPreview: 802*cdf0e10cSrcweir nSlot = FID_PAGEBREAKMODE; 803*cdf0e10cSrcweir break; 804*cdf0e10cSrcweir default: 805*cdf0e10cSrcweir DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() ); 806*cdf0e10cSrcweir } 807*cdf0e10cSrcweir // !! TODO !! get view shell from controller 808*cdf0e10cSrcweir ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel ); 809*cdf0e10cSrcweir if ( pViewShell ) 810*cdf0e10cSrcweir dispatchExecute( pViewShell, nSlot ); 811*cdf0e10cSrcweir } 812*cdf0e10cSrcweir 813*cdf0e10cSrcweir uno::Reference< excel::XRange > SAL_CALL 814*cdf0e10cSrcweir ScVbaWindow::getVisibleRange() throw (uno::RuntimeException) 815*cdf0e10cSrcweir { 816*cdf0e10cSrcweir uno::Reference< container::XIndexAccess > xPanesIA( getController(), uno::UNO_QUERY_THROW ); 817*cdf0e10cSrcweir uno::Reference< sheet::XViewPane > xTopLeftPane( xPanesIA->getByIndex( 0 ), uno::UNO_QUERY_THROW ); 818*cdf0e10cSrcweir uno::Reference< excel::XPane > xPane( new ScVbaPane( this, mxContext, m_xModel, xTopLeftPane ) ); 819*cdf0e10cSrcweir return xPane->getVisibleRange(); 820*cdf0e10cSrcweir } 821*cdf0e10cSrcweir 822*cdf0e10cSrcweir sal_Int32 SAL_CALL 823*cdf0e10cSrcweir ScVbaWindow::PointsToScreenPixelsX(sal_Int32 _points) throw (css::script::BasicErrorException, css::uno::RuntimeException) 824*cdf0e10cSrcweir { 825*cdf0e10cSrcweir sal_Int32 nHundredthsofOneMillimeters = Millimeter::getInHundredthsOfOneMillimeter( _points ); 826*cdf0e10cSrcweir double fConvertFactor = (getDevice()->getInfo().PixelPerMeterX/100000); 827*cdf0e10cSrcweir return static_cast<sal_Int32>(fConvertFactor * nHundredthsofOneMillimeters ); 828*cdf0e10cSrcweir } 829*cdf0e10cSrcweir 830*cdf0e10cSrcweir sal_Int32 SAL_CALL 831*cdf0e10cSrcweir ScVbaWindow::PointsToScreenPixelsY(sal_Int32 _points) throw (css::script::BasicErrorException, css::uno::RuntimeException) 832*cdf0e10cSrcweir { 833*cdf0e10cSrcweir sal_Int32 nHundredthsofOneMillimeters = Millimeter::getInHundredthsOfOneMillimeter( _points ); 834*cdf0e10cSrcweir double fConvertFactor = (getDevice()->getInfo().PixelPerMeterY/100000); 835*cdf0e10cSrcweir return static_cast<sal_Int32>(fConvertFactor * nHundredthsofOneMillimeters ); 836*cdf0e10cSrcweir } 837*cdf0e10cSrcweir 838*cdf0e10cSrcweir void SAL_CALL 839*cdf0e10cSrcweir 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) 840*cdf0e10cSrcweir { 841*cdf0e10cSrcweir // need test, print current active sheet 842*cdf0e10cSrcweir // !! TODO !! get view shell from controller 843*cdf0e10cSrcweir PrintOutHelper( excel::getBestViewShell( m_xModel ), From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, sal_True ); 844*cdf0e10cSrcweir } 845*cdf0e10cSrcweir 846*cdf0e10cSrcweir void SAL_CALL 847*cdf0e10cSrcweir ScVbaWindow::PrintPreview( const css::uno::Any& EnableChanges ) throw (css::script::BasicErrorException, css::uno::RuntimeException) 848*cdf0e10cSrcweir { 849*cdf0e10cSrcweir // need test, print preview current active sheet 850*cdf0e10cSrcweir // !! TODO !! get view shell from controller 851*cdf0e10cSrcweir PrintPreviewHelper( EnableChanges, excel::getBestViewShell( m_xModel ) ); 852*cdf0e10cSrcweir } 853*cdf0e10cSrcweir 854*cdf0e10cSrcweir rtl::OUString& 855*cdf0e10cSrcweir ScVbaWindow::getServiceImplName() 856*cdf0e10cSrcweir { 857*cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaWindow") ); 858*cdf0e10cSrcweir return sImplName; 859*cdf0e10cSrcweir } 860*cdf0e10cSrcweir 861*cdf0e10cSrcweir uno::Sequence< rtl::OUString > 862*cdf0e10cSrcweir ScVbaWindow::getServiceNames() 863*cdf0e10cSrcweir { 864*cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames; 865*cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 ) 866*cdf0e10cSrcweir { 867*cdf0e10cSrcweir aServiceNames.realloc( 1 ); 868*cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Window" ) ); 869*cdf0e10cSrcweir } 870*cdf0e10cSrcweir return aServiceNames; 871*cdf0e10cSrcweir } 872*cdf0e10cSrcweir namespace window 873*cdf0e10cSrcweir { 874*cdf0e10cSrcweir namespace sdecl = comphelper::service_decl; 875*cdf0e10cSrcweir sdecl::vba_service_class_<ScVbaWindow, sdecl::with_args<true> > serviceImpl; 876*cdf0e10cSrcweir extern sdecl::ServiceDecl const serviceDecl( 877*cdf0e10cSrcweir serviceImpl, 878*cdf0e10cSrcweir "ScVbaWindow", 879*cdf0e10cSrcweir "ooo.vba.excel.Window" ); 880*cdf0e10cSrcweir } 881