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 "vbaview.hxx"
29 : : #include <vbahelper/vbahelper.hxx>
30 : : #include <tools/diagnose_ex.h>
31 : : #include <com/sun/star/beans/XPropertySet.hpp>
32 : : #include <com/sun/star/view/XViewSettingsSupplier.hpp>
33 : : #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
34 : : #include <com/sun/star/text/XText.hpp>
35 : : #include <com/sun/star/text/XTextTable.hpp>
36 : : #include <com/sun/star/table/XCellRange.hpp>
37 : : #include <com/sun/star/text/XTextDocument.hpp>
38 : : #include <com/sun/star/text/XFootnotesSupplier.hpp>
39 : : #include <com/sun/star/text/XEndnotesSupplier.hpp>
40 : : #include <com/sun/star/container/XIndexAccess.hpp>
41 : : #include <com/sun/star/container/XEnumerationAccess.hpp>
42 : : #include <com/sun/star/container/XEnumeration.hpp>
43 : : #include <com/sun/star/frame/XController.hpp>
44 : : #include <com/sun/star/lang/XServiceInfo.hpp>
45 : : #include <ooo/vba/word/WdSpecialPane.hpp>
46 : : #include <ooo/vba/word/WdViewType.hpp>
47 : : #include <ooo/vba/word/WdSeekView.hpp>
48 : :
49 : : #include "wordvbahelper.hxx"
50 : : #include "vbaheaderfooterhelper.hxx"
51 : : #include <view.hxx>
52 : :
53 : : using namespace ::ooo::vba;
54 : : using namespace ::com::sun::star;
55 : :
56 : : static const sal_Int32 DEFAULT_BODY_DISTANCE = 500;
57 : :
58 : 0 : SwVbaView::SwVbaView( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext,
59 : : const uno::Reference< frame::XModel >& rModel ) throw ( uno::RuntimeException ) :
60 : 0 : SwVbaView_BASE( rParent, rContext ), mxModel( rModel )
61 : : {
62 [ # # ][ # # ]: 0 : uno::Reference< frame::XController > xController = mxModel->getCurrentController();
63 : :
64 [ # # ]: 0 : uno::Reference< text::XTextViewCursorSupplier > xTextViewCursorSupp( xController, uno::UNO_QUERY_THROW );
65 [ # # ][ # # ]: 0 : mxViewCursor = xTextViewCursorSupp->getViewCursor();
[ # # ]
66 : :
67 [ # # ]: 0 : uno::Reference< view::XViewSettingsSupplier > xViewSettingSupp( xController, uno::UNO_QUERY_THROW );
68 [ # # ][ # # ]: 0 : mxViewSettings.set( xViewSettingSupp->getViewSettings(), uno::UNO_QUERY_THROW );
[ # # ]
69 : 0 : }
70 : :
71 : 0 : SwVbaView::~SwVbaView()
72 : : {
73 [ # # ]: 0 : }
74 : :
75 : : ::sal_Int32 SAL_CALL
76 : 0 : SwVbaView::getSeekView() throw (css::uno::RuntimeException)
77 : : {
78 : : // FIXME: if the view cursor is in table, field, section and frame
79 : : // handle if the cursor is in table
80 [ # # ][ # # ]: 0 : uno::Reference< text::XText > xCurrentText = mxViewCursor->getText();
81 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xCursorProps( mxViewCursor, uno::UNO_QUERY_THROW );
82 : 0 : uno::Reference< text::XTextContent > xTextContent;
83 [ # # ][ # # ]: 0 : while( xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextTable") ) ) >>= xTextContent )
[ # # ][ # # ]
[ # # ]
84 : : {
85 [ # # ][ # # ]: 0 : xCurrentText = xTextContent->getAnchor()->getText();
[ # # ][ # # ]
[ # # ]
86 [ # # ][ # # ]: 0 : xCursorProps.set( xCurrentText->createTextCursor(), uno::UNO_QUERY_THROW );
[ # # ]
87 : : }
88 [ # # ]: 0 : uno::Reference< lang::XServiceInfo > xServiceInfo( xCurrentText, uno::UNO_QUERY_THROW );
89 [ # # ][ # # ]: 0 : rtl::OUString aImplName = xServiceInfo->getImplementationName();
90 [ # # ]: 0 : if ( aImplName == "SwXBodyText" )
91 : : {
92 : 0 : return word::WdSeekView::wdSeekMainDocument;
93 : : }
94 [ # # ]: 0 : else if ( aImplName == "SwXHeadFootText" )
95 : : {
96 [ # # ][ # # ]: 0 : if( HeaderFooterHelper::isHeader( mxModel ) )
97 : : {
98 [ # # ][ # # ]: 0 : if( HeaderFooterHelper::isFirstPageHeader( mxModel ) )
99 : 0 : return word::WdSeekView::wdSeekFirstPageHeader;
100 [ # # ][ # # ]: 0 : else if( HeaderFooterHelper::isEvenPagesHeader( mxModel ) )
101 : 0 : return word::WdSeekView::wdSeekEvenPagesHeader;
102 : : else
103 : 0 : return word::WdSeekView::wdSeekPrimaryHeader;
104 : : }
105 : : else
106 : : {
107 [ # # ][ # # ]: 0 : if( HeaderFooterHelper::isFirstPageFooter( mxModel ) )
108 : 0 : return word::WdSeekView::wdSeekFirstPageFooter;
109 [ # # ][ # # ]: 0 : else if( HeaderFooterHelper::isEvenPagesFooter( mxModel ) )
110 : 0 : return word::WdSeekView::wdSeekEvenPagesFooter;
111 : : else
112 : 0 : return word::WdSeekView::wdSeekPrimaryFooter;
113 : : }
114 : : }
115 [ # # ]: 0 : else if ( aImplName == "SwXFootnote" )
116 : : {
117 [ # # ][ # # ]: 0 : if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Endnote") ) ) )
[ # # ][ # # ]
118 : 0 : return word::WdSeekView::wdSeekEndnotes;
119 : : else
120 : 0 : return word::WdSeekView::wdSeekFootnotes;
121 : : }
122 : :
123 : 0 : return word::WdSeekView::wdSeekMainDocument;
124 : : }
125 : :
126 : : void SAL_CALL
127 : 0 : SwVbaView::setSeekView( ::sal_Int32 _seekview ) throw (css::uno::RuntimeException)
128 : : {
129 : : // FIXME: save the current cursor position, if the cursor is in the main
130 : : // document, so we can jump back to this position, if the macro sets
131 : : // the ViewMode back to wdSeekMainDocument
132 : :
133 : 0 : word::gotoSelectedObjectAnchor( mxModel );
134 [ # # # # : 0 : switch( _seekview )
# ]
135 : : {
136 : : case word::WdSeekView::wdSeekFirstPageFooter:
137 : : case word::WdSeekView::wdSeekFirstPageHeader:
138 : : case word::WdSeekView::wdSeekCurrentPageFooter:
139 : : case word::WdSeekView::wdSeekCurrentPageHeader:
140 : : case word::WdSeekView::wdSeekPrimaryFooter:
141 : : case word::WdSeekView::wdSeekPrimaryHeader:
142 : : case word::WdSeekView::wdSeekEvenPagesFooter:
143 : : case word::WdSeekView::wdSeekEvenPagesHeader:
144 : : {
145 : : // need to test
146 [ # # ]: 0 : mxViewCursor->gotoRange( getHFTextRange( _seekview ), sal_False );
147 : 0 : break;
148 : : }
149 : : case word::WdSeekView::wdSeekFootnotes:
150 : : {
151 [ # # ]: 0 : uno::Reference< text::XFootnotesSupplier > xFootnotesSupp( mxModel, uno::UNO_QUERY_THROW );
152 [ # # ][ # # ]: 0 : uno::Reference< container::XIndexAccess > xFootnotes( xFootnotesSupp->getFootnotes(), uno::UNO_QUERY_THROW );
[ # # ]
153 [ # # ][ # # ]: 0 : if( xFootnotes->getCount() > 0 )
[ # # ]
154 : : {
155 [ # # ][ # # ]: 0 : uno::Reference< text::XText > xText( xFootnotes->getByIndex(0), uno::UNO_QUERY_THROW );
[ # # ]
156 [ # # ][ # # ]: 0 : mxViewCursor->gotoRange( xText->getStart(), sal_False );
[ # # ][ # # ]
157 : : }
158 : : else
159 : : {
160 [ # # ]: 0 : DebugHelper::exception( SbERR_NO_ACTIVE_OBJECT, rtl::OUString() );
161 : : }
162 : 0 : break;
163 : : }
164 : : case word::WdSeekView::wdSeekEndnotes:
165 : : {
166 [ # # ]: 0 : uno::Reference< text::XEndnotesSupplier > xEndnotesSupp( mxModel, uno::UNO_QUERY_THROW );
167 [ # # ][ # # ]: 0 : uno::Reference< container::XIndexAccess > xEndnotes( xEndnotesSupp->getEndnotes(), uno::UNO_QUERY_THROW );
[ # # ]
168 [ # # ][ # # ]: 0 : if( xEndnotes->getCount() > 0 )
[ # # ]
169 : : {
170 [ # # ][ # # ]: 0 : uno::Reference< text::XText > xText( xEndnotes->getByIndex(0), uno::UNO_QUERY_THROW );
[ # # ]
171 [ # # ][ # # ]: 0 : mxViewCursor->gotoRange( xText->getStart(), sal_False );
[ # # ][ # # ]
172 : : }
173 : : else
174 : : {
175 [ # # ]: 0 : DebugHelper::exception( SbERR_NO_ACTIVE_OBJECT, rtl::OUString() );
176 : : }
177 : 0 : break;
178 : : }
179 : : case word::WdSeekView::wdSeekMainDocument:
180 : : {
181 [ # # ]: 0 : uno::Reference< text::XTextDocument > xTextDocument( mxModel, uno::UNO_QUERY_THROW );
182 [ # # ][ # # ]: 0 : uno::Reference< text::XText > xText = xTextDocument->getText();
183 [ # # ][ # # ]: 0 : mxViewCursor->gotoRange( word::getFirstObjectPosition( xText ), sal_False );
[ # # ]
184 : 0 : break;
185 : : }
186 : : }
187 : 0 : }
188 : :
189 : : ::sal_Int32 SAL_CALL
190 : 0 : SwVbaView::getSplitSpecial() throw (css::uno::RuntimeException)
191 : : {
192 : 0 : return word::WdSpecialPane::wdPaneNone;
193 : : }
194 : :
195 : : void SAL_CALL
196 : 0 : SwVbaView::setSplitSpecial( ::sal_Int32/* _splitspecial */) throw (css::uno::RuntimeException)
197 : : {
198 : : // not support in Writer
199 : 0 : }
200 : :
201 : : ::sal_Bool SAL_CALL
202 : 0 : SwVbaView::getTableGridLines() throw (css::uno::RuntimeException)
203 : : {
204 : 0 : sal_Bool bShowTableGridLine = sal_False;
205 [ # # ][ # # ]: 0 : mxViewSettings->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ShowTableBoundaries"))) >>= bShowTableGridLine;
[ # # ]
206 : 0 : return bShowTableGridLine;
207 : : }
208 : :
209 : : void SAL_CALL
210 : 0 : SwVbaView::setTableGridLines( ::sal_Bool _tablegridlines ) throw (css::uno::RuntimeException)
211 : : {
212 [ # # ][ # # ]: 0 : mxViewSettings->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ShowTableBoundaries")), uno::makeAny( _tablegridlines ) );
213 : 0 : }
214 : :
215 : : ::sal_Int32 SAL_CALL
216 : 0 : SwVbaView::getType() throw (css::uno::RuntimeException)
217 : : {
218 : : // FIXME: handle wdPrintPreview type
219 : 0 : sal_Bool bOnlineLayout = sal_False;
220 [ # # ][ # # ]: 0 : mxViewSettings->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ShowOnlineLayout"))) >>= bOnlineLayout;
[ # # ]
221 [ # # ]: 0 : return bOnlineLayout ? word::WdViewType::wdWebView : word::WdViewType::wdPrintView;
222 : : }
223 : :
224 : : void SAL_CALL
225 : 0 : SwVbaView::setType( ::sal_Int32 _type ) throw (css::uno::RuntimeException)
226 : : {
227 : : // FIXME: handle wdPrintPreview type
228 [ # # # # ]: 0 : switch( _type )
229 : : {
230 : : case word::WdViewType::wdPrintView:
231 : : case word::WdViewType::wdNormalView:
232 : : {
233 [ # # ][ # # ]: 0 : mxViewSettings->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ShowOnlineLayout")), uno::makeAny( sal_False ) );
[ # # ]
234 : 0 : break;
235 : : }
236 : : case word::WdViewType::wdWebView:
237 : : {
238 [ # # ][ # # ]: 0 : mxViewSettings->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ShowOnlineLayout")), uno::makeAny( sal_True ) );
[ # # ]
239 : 0 : break;
240 : : }
241 : : case word::WdViewType::wdPrintPreview:
242 : : {
243 [ # # ]: 0 : PrintPreviewHelper( uno::Any(),word::getView( mxModel ) );
244 : 0 : break;
245 : : }
246 : : default:
247 [ # # ]: 0 : DebugHelper::exception( SbERR_NOT_IMPLEMENTED, rtl::OUString() );
248 : :
249 : : }
250 : 0 : }
251 : :
252 : 0 : uno::Reference< text::XTextRange > SwVbaView::getHFTextRange( sal_Int32 nType ) throw (uno::RuntimeException)
253 : : {
254 [ # # ][ # # ]: 0 : mxModel->lockControllers();
255 : :
256 : 0 : rtl::OUString aPropIsOn;
257 : 0 : rtl::OUString aPropIsShared;
258 : 0 : rtl::OUString aPropBodyDistance;
259 : 0 : rtl::OUString aPropText;
260 : :
261 [ # # # ]: 0 : switch( nType )
262 : : {
263 : : case word::WdSeekView::wdSeekCurrentPageFooter:
264 : : case word::WdSeekView::wdSeekFirstPageFooter:
265 : : case word::WdSeekView::wdSeekPrimaryFooter:
266 : : case word::WdSeekView::wdSeekEvenPagesFooter:
267 : : {
268 [ # # ]: 0 : aPropIsOn = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterIsOn") );
269 [ # # ]: 0 : aPropIsShared = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterIsShared") );
270 [ # # ]: 0 : aPropBodyDistance = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterBodyDistance") );
271 [ # # ]: 0 : aPropText = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterText") );
272 : 0 : break;
273 : : }
274 : : case word::WdSeekView::wdSeekCurrentPageHeader:
275 : : case word::WdSeekView::wdSeekFirstPageHeader:
276 : : case word::WdSeekView::wdSeekPrimaryHeader:
277 : : case word::WdSeekView::wdSeekEvenPagesHeader:
278 : : {
279 [ # # ]: 0 : aPropIsOn = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsOn") );
280 [ # # ]: 0 : aPropIsShared = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsShared") );
281 [ # # ]: 0 : aPropBodyDistance = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderBodyDistance") );
282 [ # # ]: 0 : aPropText = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderText") );
283 : 0 : break;
284 : : }
285 : : }
286 : :
287 [ # # ]: 0 : uno::Reference< text::XPageCursor > xPageCursor( mxViewCursor, uno::UNO_QUERY_THROW );
288 : :
289 [ # # ][ # # ]: 0 : if( nType == word::WdSeekView::wdSeekFirstPageFooter
290 : : || nType == word::WdSeekView::wdSeekFirstPageHeader )
291 : : {
292 [ # # ][ # # ]: 0 : xPageCursor->jumpToFirstPage();
293 : : }
294 : :
295 : 0 : uno::Reference< style::XStyle > xStyle;
296 : 0 : uno::Reference< text::XText > xText;
297 [ # # ]: 0 : switch( nType )
298 : : {
299 : : case word::WdSeekView::wdSeekPrimaryFooter:
300 : : case word::WdSeekView::wdSeekPrimaryHeader:
301 : : case word::WdSeekView::wdSeekEvenPagesFooter:
302 : : case word::WdSeekView::wdSeekEvenPagesHeader:
303 : : {
304 : : // The primary header is the first header of the section.
305 : : // If the header is not shared between odd and even pages
306 : : // the odd page's header is the primary header. If the
307 : : // first page's header is different from the rest of the
308 : : // document, it is NOT the primary header ( the next primary
309 : : // header would be on page 3 )
310 : : // The even pages' header is only available if the header is
311 : : // not shared and the current style is applied to a page with
312 : : // an even page number
313 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xCursorProps( mxViewCursor, uno::UNO_QUERY_THROW );
314 : 0 : rtl::OUString aPageStyleName;
315 [ # # ][ # # ]: 0 : xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageStyleName"))) >>= aPageStyleName;
[ # # ]
316 [ # # ]: 0 : if ( aPageStyleName == "First Page" )
317 : : {
318 : : // go to the beginning of where the next style is used
319 : 0 : sal_Bool hasNextPage = sal_False;
320 [ # # ][ # # ]: 0 : xStyle = word::getCurrentPageStyle( mxModel );
321 [ # # ][ # # ]: 0 : do
[ # # ]
322 : : {
323 [ # # ][ # # ]: 0 : hasNextPage = xPageCursor->jumpToNextPage();
324 : : }
325 [ # # ][ # # ]: 0 : while( hasNextPage && ( xStyle == word::getCurrentPageStyle( mxModel ) ) );
[ # # ][ # # ]
326 : :
327 [ # # ]: 0 : if( !hasNextPage )
328 [ # # ]: 0 : DebugHelper::exception( SbERR_BAD_ACTION, rtl::OUString() );
329 : : }
330 : 0 : break;
331 : : }
332 : : default:
333 : : {
334 : 0 : break;
335 : : }
336 : : }
337 : :
338 [ # # ][ # # ]: 0 : xStyle = word::getCurrentPageStyle( mxModel );
339 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xPageProps( xStyle, uno::UNO_QUERY_THROW );
340 : 0 : sal_Bool isOn = sal_False;
341 [ # # ][ # # ]: 0 : xPageProps->getPropertyValue( aPropIsOn ) >>= isOn;
342 : 0 : sal_Bool isShared = sal_False;
343 [ # # ][ # # ]: 0 : xPageProps->getPropertyValue( aPropIsShared ) >>= isShared;
344 [ # # ]: 0 : if( !isOn )
345 : : {
346 [ # # ][ # # ]: 0 : xPageProps->setPropertyValue( aPropIsOn, uno::makeAny( sal_True ) );
[ # # ]
347 [ # # ][ # # ]: 0 : xPageProps->setPropertyValue( aPropBodyDistance, uno::makeAny( DEFAULT_BODY_DISTANCE ) );
[ # # ]
348 : : }
349 [ # # ]: 0 : if( !isShared )
350 : : {
351 : 0 : rtl::OUString aTempPropText = aPropText;
352 [ # # ][ # # ]: 0 : if( nType == word::WdSeekView::wdSeekEvenPagesFooter
353 : : || nType == word::WdSeekView::wdSeekEvenPagesHeader )
354 : : {
355 [ # # ]: 0 : aTempPropText += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Left") );
356 : : }
357 : : else
358 : : {
359 [ # # ]: 0 : aTempPropText += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Right") );
360 : : }
361 [ # # ][ # # ]: 0 : xText.set( xPageProps->getPropertyValue( aTempPropText), uno::UNO_QUERY_THROW );
[ # # ]
362 : : }
363 : : else
364 : : {
365 [ # # ][ # # ]: 0 : if( nType == word::WdSeekView::wdSeekEvenPagesFooter
366 : : || nType == word::WdSeekView::wdSeekEvenPagesHeader )
367 : : {
368 [ # # ]: 0 : DebugHelper::exception( SbERR_BAD_ACTION, rtl::OUString() );
369 : : }
370 [ # # ][ # # ]: 0 : xText.set( xPageProps->getPropertyValue( aPropText ), uno::UNO_QUERY_THROW );
[ # # ]
371 : : }
372 : :
373 [ # # ][ # # ]: 0 : mxModel->unlockControllers();
374 [ # # ]: 0 : if( !xText.is() )
375 : : {
376 [ # # ]: 0 : DebugHelper::exception( SbERR_INTERNAL_ERROR, rtl::OUString() );
377 : : }
378 [ # # ]: 0 : uno::Reference< text::XTextRange > xTextRange = word::getFirstObjectPosition( xText );
379 : 0 : return xTextRange;
380 : : }
381 : :
382 : : rtl::OUString
383 : 0 : SwVbaView::getServiceImplName()
384 : : {
385 : 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaView"));
386 : : }
387 : :
388 : : uno::Sequence< rtl::OUString >
389 : 0 : SwVbaView::getServiceNames()
390 : : {
391 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > aServiceNames;
[ # # ][ # # ]
392 [ # # ]: 0 : if ( aServiceNames.getLength() == 0 )
393 : : {
394 : 0 : aServiceNames.realloc( 1 );
395 [ # # ]: 0 : aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.View" ) );
396 : : }
397 : 0 : return aServiceNames;
398 : : }
399 : :
400 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|