1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #include <docsh.hxx> 24 #include "wordvbahelper.hxx" 25 #include <comphelper/processfactory.hxx> 26 #include <com/sun/star/frame/XController.hpp> 27 #include <com/sun/star/text/XTextViewCursorSupplier.hpp> 28 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> 29 #include <com/sun/star/container/XNameAccess.hpp> 30 #include <com/sun/star/lang/XUnoTunnel.hpp> 31 #include <unotxdoc.hxx> 32 #include <doc.hxx> 33 #include <viewsh.hxx> 34 35 using namespace ::com::sun::star; 36 using namespace ::ooo::vba; 37 38 #define FIRST_PAGE 1; 39 40 namespace ooo 41 { 42 namespace vba 43 { 44 namespace word 45 { 46 47 SwDocShell* getDocShell( const uno::Reference< frame::XModel>& xModel ) 48 { 49 uno::Reference< lang::XUnoTunnel > xTunnel( xModel, uno::UNO_QUERY_THROW ); 50 SwXTextDocument* pXDoc = reinterpret_cast< SwXTextDocument * >( sal::static_int_cast< sal_IntPtr >(xTunnel->getSomething(SwXTextDocument::getUnoTunnelId()))); 51 return pXDoc ? pXDoc->GetDocShell() : 0; 52 } 53 54 SwView* getView( const uno::Reference< frame::XModel>& xModel ) 55 { 56 SwDocShell* pDocShell = getDocShell( xModel ); 57 return pDocShell? pDocShell->GetView() : 0; 58 } 59 60 uno::Reference< text::XTextViewCursor > getXTextViewCursor( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) 61 { 62 uno::Reference< frame::XController > xController = xModel->getCurrentController(); 63 uno::Reference< text::XTextViewCursorSupplier > xTextViewCursorSupp( xController, uno::UNO_QUERY_THROW ); 64 uno::Reference< text::XTextViewCursor > xTextViewCursor = xTextViewCursorSupp->getViewCursor(); 65 return xTextViewCursor; 66 } 67 68 uno::Reference< style::XStyle > getCurrentPageStyle( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) 69 { 70 uno::Reference< beans::XPropertySet > xCursorProps( getXTextViewCursor( xModel ), uno::UNO_QUERY_THROW ); 71 rtl::OUString aPageStyleName; 72 xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageStyleName"))) >>= aPageStyleName; 73 uno::Reference< style::XStyleFamiliesSupplier > xSytleFamSupp( xModel, uno::UNO_QUERY_THROW ); 74 uno::Reference< container::XNameAccess > xSytleFamNames( xSytleFamSupp->getStyleFamilies(), uno::UNO_QUERY_THROW ); 75 uno::Reference< container::XNameAccess > xPageStyles( xSytleFamNames->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageStyles") ) ), uno::UNO_QUERY_THROW ); 76 uno::Reference< style::XStyle > xStyle( xPageStyles->getByName( aPageStyleName ), uno::UNO_QUERY_THROW ); 77 78 return xStyle; 79 } 80 81 sal_Int32 getPageCount( const uno::Reference< frame::XModel>& xModel ) throw (uno::RuntimeException) 82 { 83 SwDocShell* pDocShell = getDocShell( xModel ); 84 ViewShell* pViewSh = pDocShell ? pDocShell->GetDoc()->GetCurrentViewShell() : 0; 85 return pViewSh ? pViewSh->GetPageCount() : 0; 86 } 87 88 } // word 89 } // 90 } // 91