1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #include <docsh.hxx> 28 #include "wordvbahelper.hxx" 29 #include <comphelper/processfactory.hxx> 30 #include <com/sun/star/frame/XController.hpp> 31 #include <com/sun/star/text/XTextViewCursorSupplier.hpp> 32 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> 33 #include <com/sun/star/container/XNameAccess.hpp> 34 #include <com/sun/star/lang/XUnoTunnel.hpp> 35 #include <unotxdoc.hxx> 36 #include <doc.hxx> 37 #include <viewsh.hxx> 38 39 using namespace ::com::sun::star; 40 using namespace ::ooo::vba; 41 42 #define FIRST_PAGE 1; 43 44 namespace ooo 45 { 46 namespace vba 47 { 48 namespace word 49 { 50 51 SwDocShell* getDocShell( const uno::Reference< frame::XModel>& xModel ) 52 { 53 uno::Reference< lang::XUnoTunnel > xTunnel( xModel, uno::UNO_QUERY_THROW ); 54 SwXTextDocument* pXDoc = reinterpret_cast< SwXTextDocument * >( sal::static_int_cast< sal_IntPtr >(xTunnel->getSomething(SwXTextDocument::getUnoTunnelId()))); 55 return pXDoc ? pXDoc->GetDocShell() : 0; 56 } 57 58 SwView* getView( const uno::Reference< frame::XModel>& xModel ) 59 { 60 SwDocShell* pDocShell = getDocShell( xModel ); 61 return pDocShell? pDocShell->GetView() : 0; 62 } 63 64 uno::Reference< text::XTextViewCursor > getXTextViewCursor( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) 65 { 66 uno::Reference< frame::XController > xController = xModel->getCurrentController(); 67 uno::Reference< text::XTextViewCursorSupplier > xTextViewCursorSupp( xController, uno::UNO_QUERY_THROW ); 68 uno::Reference< text::XTextViewCursor > xTextViewCursor = xTextViewCursorSupp->getViewCursor(); 69 return xTextViewCursor; 70 } 71 72 uno::Reference< style::XStyle > getCurrentPageStyle( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) 73 { 74 uno::Reference< beans::XPropertySet > xCursorProps( getXTextViewCursor( xModel ), uno::UNO_QUERY_THROW ); 75 rtl::OUString aPageStyleName; 76 xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageStyleName"))) >>= aPageStyleName; 77 uno::Reference< style::XStyleFamiliesSupplier > xSytleFamSupp( xModel, uno::UNO_QUERY_THROW ); 78 uno::Reference< container::XNameAccess > xSytleFamNames( xSytleFamSupp->getStyleFamilies(), uno::UNO_QUERY_THROW ); 79 uno::Reference< container::XNameAccess > xPageStyles( xSytleFamNames->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageStyles") ) ), uno::UNO_QUERY_THROW ); 80 uno::Reference< style::XStyle > xStyle( xPageStyles->getByName( aPageStyleName ), uno::UNO_QUERY_THROW ); 81 82 return xStyle; 83 } 84 85 sal_Int32 getPageCount( const uno::Reference< frame::XModel>& xModel ) throw (uno::RuntimeException) 86 { 87 SwDocShell* pDocShell = getDocShell( xModel ); 88 ViewShell* pViewSh = pDocShell ? pDocShell->GetDoc()->GetCurrentViewShell() : 0; 89 return pViewSh ? pViewSh->GetPageCount() : 0; 90 } 91 92 } // word 93 } // 94 } // 95