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