1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vbahelper.cxx,v $
10 * $Revision: 1.5.32.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "wordvbahelper.hxx"
32 #include <comphelper/processfactory.hxx>
33 #include <com/sun/star/frame/XController.hpp>
34 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
35 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
36 #include <com/sun/star/container/XNameAccess.hpp>
37 #include <com/sun/star/lang/XUnoTunnel.hpp>
38 #include <unotxdoc.hxx>
41 using namespace ::com::sun::star
;
42 using namespace ::ooo::vba
;
53 SwDocShell
* getDocShell( const uno::Reference
< frame::XModel
>& xModel
)
55 uno::Reference
< lang::XUnoTunnel
> xTunnel( xModel
, uno::UNO_QUERY_THROW
);
56 SwXTextDocument
* pXDoc
= reinterpret_cast< SwXTextDocument
* >( sal::static_int_cast
< sal_IntPtr
>(xTunnel
->getSomething(SwXTextDocument::getUnoTunnelId())));
57 return pXDoc
? pXDoc
->GetDocShell() : 0;
60 SwView
* getView( const uno::Reference
< frame::XModel
>& xModel
)
62 SwDocShell
* pDocShell
= getDocShell( xModel
);
63 return pDocShell
? pDocShell
->GetView() : 0;
66 uno::Reference
< text::XTextViewCursor
> getXTextViewCursor( const uno::Reference
< frame::XModel
>& xModel
) throw (uno::RuntimeException
)
68 uno::Reference
< frame::XController
> xController
= xModel
->getCurrentController();
69 uno::Reference
< text::XTextViewCursorSupplier
> xTextViewCursorSupp( xController
, uno::UNO_QUERY_THROW
);
70 uno::Reference
< text::XTextViewCursor
> xTextViewCursor
= xTextViewCursorSupp
->getViewCursor();
71 return xTextViewCursor
;
74 uno::Reference
< style::XStyle
> getCurrentPageStyle( const uno::Reference
< frame::XModel
>& xModel
) throw (uno::RuntimeException
)
76 uno::Reference
< beans::XPropertySet
> xCursorProps( getXTextViewCursor( xModel
), uno::UNO_QUERY_THROW
);
77 rtl::OUString aPageStyleName
;
78 xCursorProps
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageStyleName"))) >>= aPageStyleName
;
79 uno::Reference
< style::XStyleFamiliesSupplier
> xSytleFamSupp( xModel
, uno::UNO_QUERY_THROW
);
80 uno::Reference
< container::XNameAccess
> xSytleFamNames( xSytleFamSupp
->getStyleFamilies(), uno::UNO_QUERY_THROW
);
81 uno::Reference
< container::XNameAccess
> xPageStyles( xSytleFamNames
->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageStyles") ) ), uno::UNO_QUERY_THROW
);
82 uno::Reference
< style::XStyle
> xStyle( xPageStyles
->getByName( aPageStyleName
), uno::UNO_QUERY_THROW
);
87 sal_Int32
getPageCount( const uno::Reference
< frame::XModel
>& xModel
) throw (uno::RuntimeException
)
89 SwDocShell
* pDocShell
= getDocShell( xModel
);
90 return pDocShell
? pDocShell
->GetDoc()->GetPageCount() : 0;