Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #include <docsh.hxx>
29 : : #include "wordvbahelper.hxx"
30 : : #include <comphelper/processfactory.hxx>
31 : : #include <com/sun/star/frame/XController.hpp>
32 : : #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
33 : : #include <com/sun/star/text/XTextTable.hpp>
34 : : #include <com/sun/star/table/XCellRange.hpp>
35 : : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
36 : : #include <com/sun/star/container/XNameAccess.hpp>
37 : : #include <com/sun/star/container/XIndexAccess.hpp>
38 : : #include <com/sun/star/lang/XUnoTunnel.hpp>
39 : : #include <com/sun/star/view/XSelectionSupplier.hpp>
40 : : #include <unotxdoc.hxx>
41 : : #include <doc.hxx>
42 : : #include <view.hxx>
43 : : #include <viewsh.hxx>
44 : :
45 : : using namespace ::com::sun::star;
46 : : using namespace ::ooo::vba;
47 : :
48 : : #define FIRST_PAGE 1;
49 : :
50 : : namespace ooo
51 : : {
52 : : namespace vba
53 : : {
54 : : namespace word
55 : : {
56 : :
57 : 0 : SwDocShell* getDocShell( const uno::Reference< frame::XModel>& xModel )
58 : : {
59 [ # # ]: 0 : uno::Reference< lang::XUnoTunnel > xTunnel( xModel, uno::UNO_QUERY_THROW );
60 [ # # ][ # # ]: 0 : SwXTextDocument* pXDoc = reinterpret_cast< SwXTextDocument * >( sal::static_int_cast< sal_IntPtr >(xTunnel->getSomething(SwXTextDocument::getUnoTunnelId())));
[ # # ]
61 [ # # ]: 0 : return pXDoc ? pXDoc->GetDocShell() : 0;
62 : : }
63 : :
64 : 0 : SwView* getView( const uno::Reference< frame::XModel>& xModel )
65 : : {
66 : 0 : SwDocShell* pDocShell = getDocShell( xModel );
67 [ # # ]: 0 : return pDocShell? pDocShell->GetView() : 0;
68 : : }
69 : :
70 : 0 : uno::Reference< text::XTextViewCursor > getXTextViewCursor( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
71 : : {
72 [ # # ][ # # ]: 0 : uno::Reference< frame::XController > xController = xModel->getCurrentController();
73 [ # # ]: 0 : uno::Reference< text::XTextViewCursorSupplier > xTextViewCursorSupp( xController, uno::UNO_QUERY_THROW );
74 [ # # ][ # # ]: 0 : uno::Reference< text::XTextViewCursor > xTextViewCursor = xTextViewCursorSupp->getViewCursor();
75 : 0 : return xTextViewCursor;
76 : : }
77 : :
78 : 0 : uno::Reference< style::XStyle > getCurrentPageStyle( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
79 : : {
80 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xCursorProps( getXTextViewCursor( xModel ), uno::UNO_QUERY_THROW );
81 [ # # ]: 0 : return getCurrentPageStyle( xModel, xCursorProps );
82 : : }
83 : :
84 : 0 : uno::Reference< style::XStyle > getCurrentPageStyle( const uno::Reference< frame::XModel >& xModel, const uno::Reference< beans::XPropertySet >& xProps ) throw (uno::RuntimeException)
85 : : {
86 : 0 : rtl::OUString aPageStyleName;
87 [ # # ][ # # ]: 0 : xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageStyleName"))) >>= aPageStyleName;
[ # # ]
88 [ # # ]: 0 : uno::Reference< style::XStyleFamiliesSupplier > xSytleFamSupp( xModel, uno::UNO_QUERY_THROW );
89 [ # # ][ # # ]: 0 : uno::Reference< container::XNameAccess > xSytleFamNames( xSytleFamSupp->getStyleFamilies(), uno::UNO_QUERY_THROW );
[ # # ]
90 [ # # ][ # # ]: 0 : uno::Reference< container::XNameAccess > xPageStyles( xSytleFamNames->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageStyles") ) ), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
91 [ # # ][ # # ]: 0 : uno::Reference< style::XStyle > xStyle( xPageStyles->getByName( aPageStyleName ), uno::UNO_QUERY_THROW );
[ # # ]
92 : :
93 : 0 : return xStyle;
94 : : }
95 : :
96 : 0 : sal_Int32 getPageCount( const uno::Reference< frame::XModel>& xModel ) throw (uno::RuntimeException)
97 : : {
98 : 0 : SwDocShell* pDocShell = getDocShell( xModel );
99 [ # # ]: 0 : ViewShell* pViewSh = pDocShell ? pDocShell->GetDoc()->GetCurrentViewShell() : 0;
100 [ # # ]: 0 : return pViewSh ? pViewSh->GetPageCount() : 0;
101 : : }
102 : :
103 : 0 : uno::Reference< style::XStyle > getDefaultParagraphStyle( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
104 : : {
105 [ # # ]: 0 : uno::Reference< style::XStyleFamiliesSupplier > xSytleFamSupp( xModel, uno::UNO_QUERY_THROW );
106 [ # # ][ # # ]: 0 : uno::Reference< container::XNameAccess > xSytleFamNames( xSytleFamSupp->getStyleFamilies(), uno::UNO_QUERY_THROW );
[ # # ]
107 [ # # ][ # # ]: 0 : uno::Reference< container::XNameAccess > xParaStyles( xSytleFamNames->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParagraphStyles") ) ), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
108 [ # # ][ # # ]: 0 : uno::Reference< style::XStyle > xStyle( xParaStyles->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Standard") ) ), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
109 : :
110 : 0 : return xStyle;
111 : : }
112 : :
113 : 0 : uno::Reference< text::XTextRange > getFirstObjectPosition( const uno::Reference< text::XText >& xText ) throw (uno::RuntimeException)
114 : : {
115 : : // if the first object is table, get the position of first cell
116 : 0 : uno::Reference< text::XTextRange > xTextRange;
117 [ # # ]: 0 : uno::Reference< container::XEnumerationAccess > xParaAccess( xText, uno::UNO_QUERY_THROW );
118 [ # # ][ # # ]: 0 : uno::Reference< container::XEnumeration> xParaEnum = xParaAccess->createEnumeration();
119 [ # # ][ # # ]: 0 : if( xParaEnum->hasMoreElements() )
[ # # ]
120 : : {
121 [ # # ][ # # ]: 0 : uno::Reference< lang::XServiceInfo > xServiceInfo( xParaEnum->nextElement(), uno::UNO_QUERY_THROW );
[ # # ]
122 [ # # ][ # # ]: 0 : if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextTable") ) ) )
[ # # ][ # # ]
123 : : {
124 [ # # ]: 0 : uno::Reference< table::XCellRange > xCellRange( xServiceInfo, uno::UNO_QUERY_THROW );
125 [ # # ][ # # ]: 0 : uno::Reference< text::XText> xFirstCellText( xCellRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW );
[ # # ]
126 [ # # ][ # # ]: 0 : xTextRange = xFirstCellText->getStart();
[ # # ]
127 : 0 : }
128 : : }
129 [ # # ]: 0 : if( !xTextRange.is() )
130 [ # # ][ # # ]: 0 : xTextRange = xText->getStart();
[ # # ]
131 : 0 : return xTextRange;
132 : : }
133 : :
134 : 0 : uno::Reference< text::XText > getCurrentXText( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
135 : : {
136 : 0 : uno::Reference< text::XTextRange > xTextRange;
137 [ # # ][ # # ]: 0 : uno::Reference< text::XTextContent > xTextContent( xModel->getCurrentSelection(), uno::UNO_QUERY );
[ # # ]
138 [ # # ]: 0 : if( !xTextContent.is() )
139 : : {
140 [ # # ][ # # ]: 0 : uno::Reference< container::XIndexAccess > xIndexAccess( xModel->getCurrentSelection(), uno::UNO_QUERY );
[ # # ]
141 [ # # ]: 0 : if( xIndexAccess.is() )
142 : : {
143 [ # # ][ # # ]: 0 : xTextContent.set( xIndexAccess->getByIndex(0), uno::UNO_QUERY );
[ # # ]
144 : 0 : }
145 : : }
146 : :
147 [ # # ]: 0 : if( xTextContent.is() )
148 [ # # ][ # # ]: 0 : xTextRange.set( xTextContent->getAnchor(), uno::UNO_QUERY );
[ # # ]
149 : :
150 [ # # ]: 0 : if( !xTextRange.is() )
151 [ # # ][ # # ]: 0 : xTextRange.set( getXTextViewCursor( xModel ), uno::UNO_QUERY_THROW );
152 : :
153 : 0 : uno::Reference< text::XText > xText;
154 : : try
155 : : {
156 [ # # ][ # # ]: 0 : xText.set( xTextRange->getText(), uno::UNO_QUERY );
[ # # ][ # # ]
157 : : }
158 [ # # ]: 0 : catch (const uno::RuntimeException&)
159 : : {
160 : : //catch exception "no text selection"
161 : : }
162 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xVCProps( xTextRange, uno::UNO_QUERY_THROW );
163 [ # # ][ # # ]: 0 : while( xVCProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextTable") ) ) >>= xTextContent )
[ # # ][ # # ]
[ # # ]
164 : : {
165 [ # # ][ # # ]: 0 : xText = xTextContent->getAnchor()->getText();
[ # # ][ # # ]
[ # # ]
166 [ # # ][ # # ]: 0 : xVCProps.set( xText->createTextCursor(), uno::UNO_QUERY_THROW );
[ # # ]
167 : : }
168 : :
169 [ # # ]: 0 : if( !xText.is() )
170 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( "no text selection" ) ), uno::Reference< uno::XInterface >() );
171 : :
172 : 0 : return xText;
173 : : }
174 : :
175 : 0 : sal_Bool gotoSelectedObjectAnchor( const uno::Reference< frame::XModel>& xModel ) throw (uno::RuntimeException)
176 : : {
177 : 0 : sal_Bool isObjectSelected = sal_False;
178 [ # # ][ # # ]: 0 : uno::Reference< text::XTextContent > xTextContent( xModel->getCurrentSelection(), uno::UNO_QUERY );
[ # # ]
179 [ # # ]: 0 : if( xTextContent.is() )
180 : : {
181 [ # # ][ # # ]: 0 : uno::Reference< text::XTextRange > xTextRange( xTextContent->getAnchor(), uno::UNO_QUERY_THROW );
[ # # ]
182 [ # # ][ # # ]: 0 : uno::Reference< view::XSelectionSupplier > xSelectSupp( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
[ # # ]
183 [ # # ][ # # ]: 0 : xSelectSupp->select( uno::makeAny( xTextRange ) );
[ # # ]
184 : 0 : isObjectSelected = sal_True;
185 : : }
186 : 0 : return isObjectSelected;
187 : : }
188 : :
189 : : } // word
190 : : } //
191 : : } //
192 : :
193 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|