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 "vbaselection.hxx"
29 : : #include <vbahelper/vbahelper.hxx>
30 : : #include <tools/diagnose_ex.h>
31 : : #include "vbarange.hxx"
32 : : #include "vbafind.hxx"
33 : : #include <com/sun/star/text/XTextRange.hpp>
34 : : #include <com/sun/star/text/XTextTable.hpp>
35 : : #include <com/sun/star/text/XTextTableCursor.hpp>
36 : : #include <com/sun/star/text/ControlCharacter.hpp>
37 : : #include <com/sun/star/table/XCell.hpp>
38 : : #include <comphelper/string.hxx>
39 : : #include <ooo/vba/word/WdUnits.hpp>
40 : : #include <ooo/vba/word/WdMovementType.hpp>
41 : : #include <ooo/vba/word/WdGoToItem.hpp>
42 : : #include <ooo/vba/word/WdGoToDirection.hpp>
43 : : #include <ooo/vba/word/XBookmark.hpp>
44 : : #include <ooo/vba/word/XApplication.hpp>
45 : : #include <ooo/vba/word/WdCollapseDirection.hpp>
46 : : #include <com/sun/star/text/XPageCursor.hpp>
47 : : #include "unotbl.hxx"
48 : : #include "unocoll.hxx"
49 : : #include "vbatable.hxx"
50 : : #include <com/sun/star/view/XSelectionSupplier.hpp>
51 : : #include <com/sun/star/view/XViewCursor.hpp>
52 : : #include <com/sun/star/view/XLineCursor.hpp>
53 : : #include <com/sun/star/text/XWordCursor.hpp>
54 : : #include <com/sun/star/text/XParagraphCursor.hpp>
55 : : #include <ooo/vba/word/WdInformation.hpp>
56 : : #include <ooo/vba/word/WdHeaderFooterIndex.hpp>
57 : : #include <ooo/vba/word/WdSeekView.hpp>
58 : : #include "vbainformationhelper.hxx"
59 : : #include "vbafield.hxx"
60 : : #include "vbaheaderfooter.hxx"
61 : : #include "vbaheaderfooterhelper.hxx"
62 : : #include <vbahelper/vbashaperange.hxx>
63 : : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
64 : : #include <com/sun/star/drawing/XDrawPage.hpp>
65 : : #include "vbarows.hxx"
66 : : #include "vbacolumns.hxx"
67 : : #include "vbatablehelper.hxx"
68 : : #include "vbacells.hxx"
69 : : #include "vbaview.hxx"
70 : : #include "vbaparagraph.hxx"
71 : : #include "vbastyle.hxx"
72 : : #include <docsh.hxx>
73 : : #include <tblenum.hxx>
74 : : #include <fesh.hxx>
75 : :
76 : : using namespace ::ooo::vba;
77 : : using namespace ::com::sun::star;
78 : :
79 : 0 : SwVbaSelection::SwVbaSelection( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< frame::XModel >& rModel ) throw ( uno::RuntimeException ) : SwVbaSelection_BASE( rParent, rContext ), mxModel( rModel )
80 : : {
81 [ # # ][ # # ]: 0 : mxTextViewCursor = word::getXTextViewCursor( mxModel );
82 : 0 : }
83 : :
84 : 0 : SwVbaSelection::~SwVbaSelection()
85 : : {
86 [ # # ]: 0 : }
87 : :
88 : 0 : uno::Reference< text::XTextRange > SwVbaSelection::GetSelectedRange() throw ( uno::RuntimeException )
89 : : {
90 : 0 : uno::Reference< text::XTextRange > xTextRange;
91 [ # # ][ # # ]: 0 : uno::Reference< lang::XServiceInfo > xServiceInfo( mxModel->getCurrentSelection(), uno::UNO_QUERY_THROW );
[ # # ]
92 [ # # ][ # # ]: 0 : if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextRanges") ) ) )
[ # # ][ # # ]
93 : : {
94 [ # # ]: 0 : uno::Reference< container::XIndexAccess > xTextRanges( xServiceInfo, uno::UNO_QUERY_THROW );
95 [ # # ][ # # ]: 0 : if( xTextRanges->getCount() > 0 )
[ # # ]
96 : : {
97 : : // if there are multipul selection, just return the last selected Range.
98 [ # # ][ # # ]: 0 : xTextRange.set( xTextRanges->getByIndex( xTextRanges->getCount()-1 ), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
[ # # ]
99 : 0 : }
100 : : }
101 : : else
102 : : {
103 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
104 : : }
105 : 0 : return xTextRange;
106 : : }
107 : :
108 : : uno::Reference< word::XRange > SAL_CALL
109 : 0 : SwVbaSelection::getRange() throw ( uno::RuntimeException )
110 : : {
111 [ # # ]: 0 : uno::Reference< text::XTextRange > xTextRange = GetSelectedRange();
112 [ # # ]: 0 : uno::Reference< text::XTextDocument > xDocument( mxModel, uno::UNO_QUERY_THROW );
113 [ # # ][ # # ]: 0 : return uno::Reference< word::XRange >( new SwVbaRange( this, mxContext, xDocument, xTextRange->getStart(), xTextRange->getEnd(), mxTextViewCursor->getText() ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
114 : : }
115 : :
116 : : rtl::OUString SAL_CALL
117 : 0 : SwVbaSelection::getText() throw ( uno::RuntimeException )
118 : : {
119 [ # # ][ # # ]: 0 : return getRange()->getText();
120 : : }
121 : :
122 : : void SAL_CALL
123 : 0 : SwVbaSelection::setText( const rtl::OUString& rText ) throw ( uno::RuntimeException )
124 : : {
125 [ # # ][ # # ]: 0 : getRange()->setText( rText );
126 : 0 : }
127 : :
128 : : void SAL_CALL
129 : 0 : SwVbaSelection::TypeText( const rtl::OUString& rText ) throw ( uno::RuntimeException )
130 : : {
131 : : // FIXME: handle the property Options.ReplaceSelection, the default value is sal_True
132 : 0 : setText( rText );
133 : 0 : }
134 : :
135 : : void SAL_CALL
136 : 0 : SwVbaSelection::HomeKey( const uno::Any& _unit, const uno::Any& _extend ) throw ( uno::RuntimeException )
137 : : {
138 : 0 : sal_Int32 nUnit = word::WdUnits::wdLine;
139 : 0 : sal_Int32 nExtend = word::WdMovementType::wdMove;
140 : 0 : _unit >>= nUnit;
141 : 0 : _extend >>= nExtend;
142 [ # # ]: 0 : sal_Bool bExtend = ( nExtend == word::WdMovementType::wdExtend ) ? sal_True : sal_False;
143 : :
144 [ # # # ]: 0 : switch( nUnit )
145 : : {
146 : : case word::WdUnits::wdStory:
147 : : {
148 : : // go to the valid text first so that the current view cursor is valid to call gotoRange.
149 [ # # ]: 0 : word::gotoSelectedObjectAnchor(mxModel);
150 : : // go to the begin of the document
151 [ # # ]: 0 : uno::Reference< text::XText > xCurrentText = word::getCurrentXText( mxModel );
152 [ # # ]: 0 : uno::Reference< text::XTextRange > xFirstRange = word::getFirstObjectPosition( xCurrentText );
153 [ # # ][ # # ]: 0 : mxTextViewCursor->gotoRange( xFirstRange, bExtend );
154 : 0 : break;
155 : : }
156 : : case word::WdUnits::wdLine:
157 : : {
158 : : // go to the begin of the Line
159 [ # # ]: 0 : uno::Reference< view::XLineCursor > xLineCursor( mxTextViewCursor, uno::UNO_QUERY_THROW );
160 [ # # ][ # # ]: 0 : xLineCursor->gotoStartOfLine( bExtend );
161 : 0 : break;
162 : : }
163 : : default:
164 : : {
165 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
166 : : }
167 : : }
168 : 0 : }
169 : :
170 : : void SAL_CALL
171 : 0 : SwVbaSelection::EndKey( const uno::Any& _unit, const uno::Any& _extend ) throw ( uno::RuntimeException )
172 : : {
173 : 0 : sal_Int32 nUnit = word::WdUnits::wdLine;
174 : 0 : sal_Int32 nExtend = word::WdMovementType::wdMove;
175 : 0 : _unit >>= nUnit;
176 : 0 : _extend >>= nExtend;
177 [ # # ]: 0 : sal_Bool bExtend = ( nExtend == word::WdMovementType::wdExtend ) ? sal_True : sal_False;
178 : :
179 [ # # # ]: 0 : switch( nUnit )
180 : : {
181 : : case word::WdUnits::wdStory:
182 : : {
183 : : // go to the valid text first so that the current view cursor is valid to call gotoRange.
184 [ # # ]: 0 : word::gotoSelectedObjectAnchor(mxModel);
185 : : // go to the end of the document
186 [ # # ]: 0 : uno::Reference< text::XText > xCurrentText = word::getCurrentXText( mxModel );
187 [ # # ][ # # ]: 0 : uno::Reference< text::XTextRange > xEnd = xCurrentText->getEnd();
188 [ # # ][ # # ]: 0 : mxTextViewCursor->gotoRange( xEnd, bExtend );
189 : 0 : break;
190 : : }
191 : : case word::WdUnits::wdLine:
192 : : {
193 : : // go to the end of the Line
194 [ # # ]: 0 : uno::Reference< view::XLineCursor > xLineCursor( mxTextViewCursor, uno::UNO_QUERY_THROW );
195 [ # # ][ # # ]: 0 : xLineCursor->gotoEndOfLine( bExtend );
196 : 0 : break;
197 : : }
198 : : default:
199 : : {
200 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
201 : : }
202 : : }
203 : 0 : }
204 : :
205 : : void SAL_CALL
206 : 0 : SwVbaSelection::Delete( const uno::Any& _unit, const uno::Any& _count ) throw ( uno::RuntimeException )
207 : : {
208 : 0 : sal_Int32 nUnit = word::WdUnits::wdLine;
209 : 0 : sal_Int32 nCount = 0;
210 [ # # ]: 0 : if( _count.hasValue() )
211 : 0 : _count >>= nCount;
212 [ # # ][ # # ]: 0 : if( _unit.hasValue() && ( nCount > 0 ) )
[ # # ]
213 : : {
214 : 0 : _unit >>= nUnit;
215 [ # # ]: 0 : switch( nUnit )
216 : : {
217 : : case word::WdUnits::wdCharacter:
218 : : {
219 [ # # ][ # # ]: 0 : if( HasSelection() )
220 : 0 : nCount--;
221 [ # # ][ # # ]: 0 : mxTextViewCursor->goRight( nCount, sal_True );
222 : 0 : break;
223 : : }
224 : : default:
225 : : {
226 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
227 : : }
228 : : }
229 : : }
230 [ # # ]: 0 : rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:Delete"));
231 [ # # ]: 0 : dispatchRequests( mxModel,url );
232 : 0 : }
233 : :
234 : : void
235 : 0 : SwVbaSelection::Move( const uno::Any& _unit, const uno::Any& _count, const uno::Any& _extend, word::E_DIRECTION eDirection ) throw ( uno::RuntimeException )
236 : : {
237 : 0 : sal_Int32 nUnit = word::WdUnits::wdCharacter;
238 : 0 : sal_Int32 nCount = 1;
239 : 0 : sal_Int32 nExtend = word::WdMovementType::wdMove;
240 : :
241 [ # # ]: 0 : if( _unit.hasValue() )
242 : 0 : _unit >>= nUnit;
243 [ # # ]: 0 : if( _count.hasValue() )
244 : 0 : _count >>= nCount;
245 [ # # ]: 0 : if( _extend.hasValue() )
246 : 0 : _extend >>= nExtend;
247 : :
248 [ # # ]: 0 : if( nCount == 0 )
249 : : return;
250 : :
251 : 0 : sal_Bool bExpand = ( nExtend == word::WdMovementType::wdMove ) ? sal_False : sal_True;
252 : :
253 [ # # # # : 0 : switch( nUnit )
# ]
254 : : {
255 : : case word::WdUnits::wdCell:
256 : : {
257 [ # # ]: 0 : if( nExtend == word::WdMovementType::wdExtend )
258 : : {
259 [ # # ]: 0 : DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString());
260 : : return;
261 : : }
262 [ # # ]: 0 : NextCell( nCount, eDirection );
263 : 0 : break;
264 : : }
265 : : case word::WdUnits::wdLine:
266 : : {
267 [ # # ][ # # ]: 0 : if( eDirection == word::MOVE_LEFT || eDirection == word::MOVE_RIGHT )
268 : : {
269 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
270 : : }
271 [ # # ]: 0 : uno::Reference< view::XViewCursor > xViewCursor( mxTextViewCursor, uno::UNO_QUERY_THROW );
272 [ # # ]: 0 : if( eDirection == word::MOVE_UP )
273 [ # # ][ # # ]: 0 : xViewCursor->goUp( nCount, bExpand );
274 [ # # ]: 0 : else if( eDirection == word::MOVE_DOWN )
275 [ # # ][ # # ]: 0 : xViewCursor->goDown( nCount, bExpand );
276 : 0 : break;
277 : : }
278 : : case word::WdUnits::wdCharacter:
279 : : {
280 [ # # ][ # # ]: 0 : if( eDirection == word::MOVE_UP || eDirection == word::MOVE_DOWN )
281 : : {
282 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
283 : : }
284 [ # # ][ # # ]: 0 : if( word::gotoSelectedObjectAnchor( mxModel ) )
285 : : {
286 : 0 : nCount--;
287 : : }
288 [ # # ]: 0 : uno::Reference< view::XViewCursor > xViewCursor( mxTextViewCursor, uno::UNO_QUERY_THROW );
289 [ # # ]: 0 : if( eDirection == word::MOVE_LEFT )
290 : : {
291 : : // if current select is a cellrange or table,
292 : : // the first count of move should move to the first selected cell.
293 [ # # ][ # # ]: 0 : uno::Reference< text::XTextTableCursor > xTextTableCursor( mxModel->getCurrentSelection(), uno::UNO_QUERY );
[ # # ]
294 [ # # ]: 0 : if ( xTextTableCursor.is() )
295 : : {
296 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW );
297 : 0 : uno::Reference< text::XTextTable > xTextTable;
298 [ # # ][ # # ]: 0 : xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextTable") ) ) >>= xTextTable;
[ # # ][ # # ]
299 [ # # ]: 0 : if( xTextTable.is() )
300 : : {
301 [ # # ][ # # ]: 0 : uno::Reference< text::XTextRange > xRange( xTextTable->getCellByName( xTextTableCursor->getRangeName()), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
[ # # ]
302 [ # # ][ # # ]: 0 : mxTextViewCursor->gotoRange( xRange->getStart(), bExpand );
[ # # ][ # # ]
303 : 0 : nCount--;
304 : 0 : }
305 : : }
306 [ # # ][ # # ]: 0 : xViewCursor->goLeft( nCount, bExpand );
307 : : }
308 [ # # ]: 0 : else if( eDirection == word::MOVE_RIGHT )
309 [ # # ][ # # ]: 0 : xViewCursor->goRight( nCount, bExpand );
310 : 0 : break;
311 : : }
312 : : case word::WdUnits::wdWord:
313 : : case word::WdUnits::wdParagraph:
314 : : {
315 [ # # ]: 0 : uno::Reference< text::XTextRange > xRange = GetSelectedRange();
316 [ # # ][ # # ]: 0 : uno::Reference< text::XText > xText = xRange->getText();
317 [ # # ][ # # ]: 0 : uno::Reference< text::XTextCursor > xTextCursor = xText->createTextCursorByRange( xRange );
318 [ # # ]: 0 : if( nUnit == word::WdUnits::wdParagraph )
319 : : {
320 [ # # ][ # # ]: 0 : if( eDirection == word::MOVE_LEFT || eDirection == word::MOVE_RIGHT )
321 : : {
322 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
323 : : }
324 [ # # ]: 0 : uno::Reference< text::XParagraphCursor > xParagraphCursor( xTextCursor, uno::UNO_QUERY_THROW );
325 [ # # ]: 0 : for( sal_Int32 i=0; i<nCount; i++ )
326 : : {
327 [ # # ][ # # ]: 0 : if( ( eDirection == word::MOVE_UP ) && ( xParagraphCursor->gotoPreviousParagraph( bExpand ) == sal_False ) )
[ # # ][ # # ]
[ # # ]
328 : 0 : break;
329 [ # # ][ # # ]: 0 : else if( ( eDirection == word::MOVE_DOWN ) && ( xParagraphCursor->gotoNextParagraph( bExpand ) == sal_False ) )
[ # # ][ # # ]
[ # # ]
330 : 0 : break;
331 : 0 : }
332 : : }
333 [ # # ]: 0 : else if( nUnit == word::WdUnits::wdWord )
334 : : {
335 [ # # ][ # # ]: 0 : if( eDirection == word::MOVE_UP || eDirection == word::MOVE_DOWN )
336 : : {
337 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
338 : : }
339 [ # # ]: 0 : uno::Reference< text::XWordCursor > xWordCursor( xTextCursor, uno::UNO_QUERY_THROW );
340 [ # # ]: 0 : for( sal_Int32 i=0; i<nCount; i++ )
341 : : {
342 [ # # ][ # # ]: 0 : if( (eDirection == word::MOVE_LEFT ) && ( xWordCursor->gotoPreviousWord( bExpand ) == sal_False ) )
[ # # ][ # # ]
[ # # ]
343 : 0 : break;
344 [ # # ][ # # ]: 0 : else if( ( eDirection == word::MOVE_RIGHT ) && ( xWordCursor->gotoNextWord( bExpand ) == sal_False ) )
[ # # ][ # # ]
[ # # ]
345 : 0 : break;
346 : 0 : }
347 : : }
348 [ # # ][ # # ]: 0 : mxTextViewCursor->gotoRange( xTextCursor->getStart(), sal_False );
[ # # ][ # # ]
349 [ # # ][ # # ]: 0 : mxTextViewCursor->gotoRange( xTextCursor->getEnd(), sal_True );
[ # # ][ # # ]
350 : 0 : break;
351 : : }
352 : : default:
353 : : {
354 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
355 : : break;
356 : : }
357 : : }
358 : : }
359 : :
360 : 0 : void SwVbaSelection::NextCell( sal_Int32 nCount, word::E_DIRECTION eDirection ) throw ( uno::RuntimeException )
361 : : {
362 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW );
363 : 0 : uno::Reference< text::XTextTable > xTextTable;
364 : 0 : uno::Reference< table::XCell > xCell;
365 [ # # ][ # # ]: 0 : xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextTable") ) ) >>= xTextTable;
[ # # ][ # # ]
366 [ # # ][ # # ]: 0 : xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Cell") ) ) >>= xCell;
[ # # ][ # # ]
367 [ # # ][ # # ]: 0 : if( !xTextTable.is() || !xCell.is() )
[ # # ]
368 : : {
369 [ # # ]: 0 : DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString());
370 : : return;
371 : : }
372 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xCellProps( xCell, uno::UNO_QUERY_THROW );
373 : 0 : rtl::OUString aCellName;
374 [ # # ][ # # ]: 0 : xCellProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CellName") ) ) >>= aCellName;
[ # # ]
375 [ # # ][ # # ]: 0 : uno::Reference< text::XTextTableCursor > xTextTableCursor = xTextTable->createCursorByCellName( aCellName );
376 : : // move the table cursor
377 [ # # # # : 0 : switch( eDirection )
# ]
378 : : {
379 : : case word::MOVE_LEFT:
380 : : {
381 [ # # ][ # # ]: 0 : xTextTableCursor->goLeft( nCount, sal_False );
382 : 0 : break;
383 : : }
384 : : case word::MOVE_RIGHT:
385 : : {
386 [ # # ][ # # ]: 0 : xTextTableCursor->goRight( nCount, sal_False );
387 : 0 : break;
388 : : }
389 : : case word::MOVE_UP:
390 : : {
391 [ # # ][ # # ]: 0 : xTextTableCursor->goUp( nCount, sal_False );
392 : 0 : break;
393 : : }
394 : : case word::MOVE_DOWN:
395 : : {
396 [ # # ][ # # ]: 0 : xTextTableCursor->goDown( nCount, sal_False );
397 : 0 : break;
398 : : }
399 : : default:
400 : : {
401 [ # # ]: 0 : DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString());
402 : : return;
403 : : }
404 : : }
405 : : // move the view cursor
406 [ # # ][ # # ]: 0 : xCell = xTextTable->getCellByName( xTextTableCursor->getRangeName() );
[ # # ][ # # ]
[ # # ]
407 [ # # ][ # # ]: 0 : mxTextViewCursor->gotoRange( uno::Reference< text::XTextRange >( xCell, uno::UNO_QUERY_THROW ), sal_False );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
408 : : }
409 : :
410 : : void SAL_CALL
411 : 0 : SwVbaSelection::MoveRight( const uno::Any& _unit, const uno::Any& _count, const uno::Any& _extend ) throw ( uno::RuntimeException )
412 : : {
413 : 0 : sal_Int32 nCount = 1;
414 : :
415 [ # # ]: 0 : if( _count.hasValue() )
416 : 0 : _count >>= nCount;
417 : :
418 [ # # ]: 0 : if( nCount == 0 )
419 : : return;
420 : :
421 [ # # ]: 0 : if( nCount < 0 )
422 : : {
423 [ # # ][ # # ]: 0 : MoveLeft( _unit, uno::makeAny( -nCount ), _extend );
424 : : return;
425 : : }
426 : :
427 [ # # ]: 0 : Move( _unit, _count, _extend, word::MOVE_RIGHT );
428 : : }
429 : :
430 : : void SAL_CALL
431 : 0 : SwVbaSelection::MoveLeft( const uno::Any& _unit, const uno::Any& _count, const uno::Any& _extend ) throw ( uno::RuntimeException )
432 : : {
433 : 0 : sal_Int32 nCount = 1;
434 [ # # ]: 0 : if( _count.hasValue() )
435 : 0 : _count >>= nCount;
436 : :
437 [ # # ]: 0 : if( nCount == 0 )
438 : : return;
439 : :
440 [ # # ]: 0 : if( nCount < 0 )
441 : : {
442 [ # # ][ # # ]: 0 : MoveRight( _unit, uno::makeAny( -nCount ), _extend );
443 : : return;
444 : : }
445 : :
446 [ # # ]: 0 : Move( _unit, _count, _extend, word::MOVE_LEFT );
447 : : }
448 : :
449 : : void SAL_CALL
450 : 0 : SwVbaSelection::MoveDown( const uno::Any& _unit, const uno::Any& _count, const uno::Any& _extend ) throw ( uno::RuntimeException )
451 : : {
452 : 0 : sal_Int32 nCount = 1;
453 : :
454 [ # # ]: 0 : if( _count.hasValue() )
455 : 0 : _count >>= nCount;
456 : :
457 [ # # ]: 0 : if( nCount == 0 )
458 : : return;
459 : :
460 [ # # ]: 0 : if( nCount < 0 )
461 : : {
462 [ # # ][ # # ]: 0 : MoveUp( _unit, uno::makeAny( -nCount ), _extend );
463 : : return;
464 : : }
465 : :
466 [ # # ]: 0 : Move( _unit, _count, _extend, word::MOVE_DOWN );
467 : : }
468 : :
469 : : void SAL_CALL
470 : 0 : SwVbaSelection::MoveUp( const uno::Any& _unit, const uno::Any& _count, const uno::Any& _extend ) throw ( uno::RuntimeException )
471 : : {
472 : 0 : sal_Int32 nCount = 1;
473 : :
474 [ # # ]: 0 : if( _count.hasValue() )
475 : 0 : _count >>= nCount;
476 : :
477 [ # # ]: 0 : if( nCount == 0 )
478 : : return;
479 : :
480 [ # # ]: 0 : if( nCount < 0 )
481 : : {
482 [ # # ][ # # ]: 0 : MoveDown( _unit, uno::makeAny( -nCount ), _extend );
483 : : return;
484 : : }
485 : :
486 [ # # ]: 0 : Move( _unit, _count, _extend, word::MOVE_UP );
487 : : }
488 : :
489 : : void SAL_CALL
490 : 0 : SwVbaSelection::TypeParagraph() throw ( uno::RuntimeException )
491 : : {
492 : : // #FIXME: if the selection is an entire paragraph, it's replaced
493 : : // by the new paragraph
494 : 0 : sal_Bool isCollapsed = mxTextViewCursor->isCollapsed();
495 : 0 : InsertParagraph();
496 [ # # ]: 0 : if( isCollapsed )
497 : 0 : mxTextViewCursor->collapseToStart();
498 : 0 : }
499 : :
500 : : void SAL_CALL
501 : 0 : SwVbaSelection::InsertParagraph() throw ( uno::RuntimeException )
502 : : {
503 : : // #FIME: the selection should include the new paragraph.
504 [ # # ][ # # ]: 0 : getRange()->InsertParagraph();
505 : 0 : }
506 : :
507 : : void SAL_CALL
508 : 0 : SwVbaSelection::InsertParagraphBefore() throw ( uno::RuntimeException )
509 : : {
510 [ # # ][ # # ]: 0 : getRange()->InsertParagraphBefore();
511 : 0 : }
512 : :
513 : : void SAL_CALL
514 : 0 : SwVbaSelection::InsertParagraphAfter() throw ( uno::RuntimeException )
515 : : {
516 [ # # ][ # # ]: 0 : getRange()->InsertParagraphAfter();
517 : 0 : }
518 : :
519 : : uno::Reference< word::XParagraphFormat > SAL_CALL
520 : 0 : SwVbaSelection::getParagraphFormat() throw ( uno::RuntimeException )
521 : : {
522 [ # # ][ # # ]: 0 : return getRange()->getParagraphFormat();
523 : : }
524 : :
525 : : void SAL_CALL
526 : 0 : SwVbaSelection::setParagraphFormat( const uno::Reference< word::XParagraphFormat >& rParagraphFormat ) throw ( uno::RuntimeException )
527 : : {
528 [ # # ][ # # ]: 0 : return getRange()->setParagraphFormat( rParagraphFormat );
529 : : }
530 : :
531 : : uno::Reference< word::XFind > SAL_CALL
532 : 0 : SwVbaSelection::getFind() throw ( uno::RuntimeException )
533 : : {
534 [ # # ]: 0 : uno::Reference< text::XTextRange > xTextRange = GetSelectedRange();
535 [ # # ][ # # ]: 0 : return uno::Reference< word::XFind >( new SwVbaFind( this, mxContext, mxModel, xTextRange ) );
[ # # ][ # # ]
536 : : }
537 : :
538 : : uno::Any SAL_CALL
539 : 0 : SwVbaSelection::getStyle() throw ( uno::RuntimeException )
540 : : {
541 [ # # ][ # # ]: 0 : return getRange()->getStyle();
542 : : }
543 : :
544 : : void SAL_CALL
545 : 0 : SwVbaSelection::setStyle( const uno::Any& rStyle ) throw ( uno::RuntimeException )
546 : : {
547 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xParaProps( mxTextViewCursor, uno::UNO_QUERY_THROW );
548 [ # # ]: 0 : return SwVbaStyle::setStyle( xParaProps, rStyle );
549 : : }
550 : :
551 : : uno::Reference< word::XFont > SAL_CALL
552 : 0 : SwVbaSelection::getFont() throw ( uno::RuntimeException )
553 : : {
554 [ # # ][ # # ]: 0 : return getRange()->getFont();
555 : : }
556 : :
557 : : void SAL_CALL
558 : 0 : SwVbaSelection::TypeBackspace() throw ( uno::RuntimeException )
559 : : {
560 [ # # ]: 0 : rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:SwBackspace"));
561 [ # # ]: 0 : dispatchRequests( mxModel,url );
562 : 0 : }
563 : :
564 : 0 : uno::Reference< word::XRange > SAL_CALL SwVbaSelection::GoTo( const uno::Any& _what, const uno::Any& _which, const uno::Any& _count, const uno::Any& _name ) throw (uno::RuntimeException)
565 : : {
566 : 0 : sal_Int32 nWhat = 0;
567 [ # # ]: 0 : if( ( _what >>= nWhat ) != sal_True )
568 [ # # ]: 0 : DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString());
569 [ # # # # ]: 0 : switch( nWhat )
570 : : {
571 : : case word::WdGoToItem::wdGoToBookmark:
572 : : {
573 : 0 : rtl::OUString sName;
574 [ # # ][ # # ]: 0 : uno::Reference< word::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
575 [ # # ][ # # ]: 0 : uno::Reference< word::XBookmark > xBookmark( xApplication->getActiveDocument()->Bookmarks(_name), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
[ # # ]
576 [ # # ][ # # ]: 0 : xBookmark->Select();
577 : 0 : break;
578 : : }
579 : : case word::WdGoToItem::wdGoToPage:
580 : : {
581 [ # # ]: 0 : uno::Reference< text::XPageCursor > xPageCursor( mxTextViewCursor, uno::UNO_QUERY_THROW );
582 [ # # ][ # # ]: 0 : sal_Int32 nCurrPage = xPageCursor->getPage();
583 [ # # ]: 0 : sal_Int32 nLastPage = word::getPageCount( mxModel );
584 : 0 : sal_Int32 nCount = 0;
585 [ # # ]: 0 : if( _count.hasValue() )
586 : 0 : _count >>= nCount;
587 : 0 : sal_Int32 nWhich = 0;
588 [ # # ]: 0 : if( _which.hasValue() )
589 : 0 : _which >>= nWhich;
590 : 0 : sal_Int32 nPage = 0;
591 [ # # # # ]: 0 : switch( nWhich )
592 : : {
593 : : case word::WdGoToDirection::wdGoToLast:
594 : : {
595 : 0 : nPage = nLastPage;
596 : 0 : break;
597 : : }
598 : : case word::WdGoToDirection::wdGoToNext:
599 : : {
600 [ # # ]: 0 : if( nCount !=0 )
601 : 0 : nPage = nCurrPage + nCount;
602 : : else
603 : 0 : nPage = nCurrPage + 1;
604 : 0 : break;
605 : : }
606 : : case word::WdGoToDirection::wdGoToPrevious:
607 : : {
608 [ # # ]: 0 : if( nCount !=0 )
609 : 0 : nPage = nCurrPage - nCount;
610 : : else
611 : 0 : nPage = nCurrPage - 1;
612 : 0 : break;
613 : : }
614 : : default:
615 : : {
616 : 0 : nPage = nCount;
617 : : }
618 : : }
619 [ # # ]: 0 : if( _name.hasValue() )
620 : : {
621 : 0 : rtl::OUString sName;
622 : 0 : _name >>= sName;
623 : 0 : sal_Int32 nName = sName.toInt32();
624 [ # # ]: 0 : if( nName !=0 )
625 : 0 : nPage = nName;
626 : : }
627 [ # # ]: 0 : if( nPage <= 0 )
628 : 0 : nPage = 1;
629 [ # # ]: 0 : if( nPage > nLastPage )
630 : 0 : nPage = nLastPage;
631 [ # # ][ # # ]: 0 : xPageCursor->jumpToPage( ( sal_Int16 )( nPage ) );
632 : 0 : break;
633 : : }
634 : : case word::WdGoToItem::wdGoToSection:
635 : : {
636 [ # # ]: 0 : uno::Reference< text::XPageCursor > xPageCursor( mxTextViewCursor, uno::UNO_QUERY_THROW );
637 : 0 : sal_Int32 nCount = 0;
638 [ # # ]: 0 : if( _count.hasValue() )
639 : 0 : _count >>= nCount;
640 : 0 : sal_Int32 nWhich = 0;
641 [ # # ]: 0 : if( _which.hasValue() )
642 : 0 : _which >>= nWhich;
643 : 0 : sal_Int32 nPage = 0;
644 [ # # ]: 0 : switch( nWhich )
645 : : {
646 : : case word::WdGoToDirection::wdGoToAbsolute:
647 : : {
648 : : // currently only support this type
649 [ # # ]: 0 : if( nCount == 1 )
650 : 0 : nPage = 1;
651 : 0 : break;
652 : : }
653 : : default:
654 : : {
655 : 0 : nPage = 0;
656 : : }
657 : : }
658 [ # # ]: 0 : if( nPage != 0 )
659 [ # # ][ # # ]: 0 : xPageCursor->jumpToPage( ( sal_Int16 )( nPage ) );
660 : : else
661 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
662 : 0 : break;
663 : : }
664 : : default:
665 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
666 : : }
667 [ # # ]: 0 : return getRange();
668 : : }
669 : :
670 : 0 : ::sal_Int32 SAL_CALL SwVbaSelection::getLanguageID() throw (uno::RuntimeException)
671 : : {
672 [ # # ][ # # ]: 0 : return getRange()->getLanguageID();
673 : : }
674 : :
675 : 0 : void SAL_CALL SwVbaSelection::setLanguageID( ::sal_Int32 _languageid ) throw (uno::RuntimeException)
676 : : {
677 [ # # ][ # # ]: 0 : getRange()->setLanguageID( _languageid );
678 : 0 : }
679 : :
680 : 0 : uno::Any SAL_CALL SwVbaSelection::Information( sal_Int32 _type ) throw (uno::RuntimeException)
681 : : {
682 : 0 : uno::Any result;
683 [ # # # # : 0 : switch( _type )
# # ]
684 : : {
685 : : case word::WdInformation::wdActiveEndPageNumber:
686 : : {
687 [ # # ][ # # ]: 0 : result = uno::makeAny( SwVbaInformationHelper::handleWdActiveEndPageNumber( mxTextViewCursor ) );
688 : 0 : break;
689 : : }
690 : : case word::WdInformation::wdNumberOfPagesInDocument:
691 : : {
692 [ # # ][ # # ]: 0 : result = uno::makeAny( SwVbaInformationHelper::handleWdNumberOfPagesInDocument( mxModel ) );
693 : 0 : break;
694 : : }
695 : : case word::WdInformation::wdVerticalPositionRelativeToPage:
696 : : {
697 [ # # ][ # # ]: 0 : result = uno::makeAny( SwVbaInformationHelper::handleWdVerticalPositionRelativeToPage( mxModel, mxTextViewCursor ) );
698 : 0 : break;
699 : : }
700 : : case word::WdInformation::wdWithInTable:
701 : : {
702 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW );
703 : 0 : uno::Reference< text::XTextTable > xTextTable;
704 [ # # ][ # # ]: 0 : xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextTable") ) ) >>= xTextTable;
[ # # ][ # # ]
705 [ # # ]: 0 : if( xTextTable.is() )
706 [ # # ]: 0 : result = uno::makeAny( sal_True );
707 : : else
708 [ # # ]: 0 : result = uno::makeAny( sal_False );
709 : 0 : break;
710 : : }
711 : : case word::WdInformation::wdHeaderFooterType:
712 : : {
713 [ # # ][ # # ]: 0 : uno::Reference< word::XView > xView( new SwVbaView( this, mxContext, mxModel ) );
[ # # ][ # # ]
714 [ # # ][ # # ]: 0 : sal_Int32 nView = xView->getSeekView();
715 : 0 : sal_Int32 nHeaderFooterType = 0;
716 [ # # # # : 0 : switch( nView )
# # # ]
717 : : {
718 : : case word::WdSeekView::wdSeekMainDocument:
719 : : {
720 : 0 : nHeaderFooterType = -1; // not in a header or footer
721 : 0 : break;
722 : : }
723 : : case word::WdSeekView::wdSeekEvenPagesHeader:
724 : : {
725 : 0 : nHeaderFooterType = 0; // even page header
726 : 0 : break;
727 : : }
728 : : case word::WdSeekView::wdSeekPrimaryHeader:
729 : : {
730 : 0 : nHeaderFooterType = 1; // odd page header
731 : 0 : break;
732 : : }
733 : : case word::WdSeekView::wdSeekEvenPagesFooter:
734 : : {
735 : 0 : nHeaderFooterType = 2; // even page footer
736 : 0 : break;
737 : : }
738 : : case word::WdSeekView::wdSeekPrimaryFooter:
739 : : {
740 : 0 : nHeaderFooterType = 3; // odd page footer
741 : 0 : break;
742 : : }
743 : : case word::WdSeekView::wdSeekFirstPageHeader:
744 : : case word::WdSeekView::wdSeekFirstPageFooter:
745 : : {
746 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW );
747 : 0 : rtl::OUString aPageStyleName;
748 [ # # ][ # # ]: 0 : xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageStyleName"))) >>= aPageStyleName;
[ # # ]
749 : 0 : sal_Bool bFirstPage = sal_False;
750 [ # # ]: 0 : if ( aPageStyleName == "First Page" )
751 : 0 : bFirstPage = sal_True;
752 [ # # ]: 0 : if( nView == word::WdSeekView::wdSeekFirstPageHeader )
753 : : {
754 [ # # ]: 0 : if( bFirstPage )
755 : 0 : nHeaderFooterType = 4;
756 : : else
757 : 0 : nHeaderFooterType = 1;
758 : : }
759 : : else
760 : : {
761 [ # # ]: 0 : if( bFirstPage )
762 : 0 : nHeaderFooterType = 5;
763 : : else
764 : 0 : nHeaderFooterType = 3;
765 : : }
766 : 0 : break;
767 : : }
768 : : default:
769 : : {
770 : 0 : nHeaderFooterType = -1;
771 : : }
772 : : }
773 [ # # ]: 0 : result = uno::makeAny( nHeaderFooterType );
774 : 0 : break;
775 : : }
776 : : default:
777 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
778 : : }
779 : 0 : return result;
780 : : }
781 : :
782 : 0 : void SAL_CALL SwVbaSelection::InsertBreak( const uno::Any& _breakType ) throw (uno::RuntimeException)
783 : : {
784 [ # # ][ # # ]: 0 : getRange()->InsertBreak( _breakType );
785 : 0 : }
786 : :
787 : : uno::Any SAL_CALL
788 : 0 : SwVbaSelection::Tables( const uno::Any& aIndex ) throw (uno::RuntimeException)
789 : : {
790 : : // Hacky implementation due to missing api ( and lack of knowledge )
791 : : // we can only support a selection that is a single table
792 [ # # ]: 0 : if ( !aIndex.hasValue() ) // currently we can't support multiple tables in a selection
793 [ # # ]: 0 : throw uno::RuntimeException();
794 : :
795 : 0 : sal_Int32 nIndex = 0;
796 : 0 : aIndex >>= nIndex;
797 : :
798 : 0 : uno::Any aRet;
799 : :
800 [ # # ]: 0 : if ( nIndex != 1 )
801 [ # # ]: 0 : throw uno::RuntimeException();
802 : :
803 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW );
804 : 0 : uno::Reference< text::XTextTable > xTextTable;
805 [ # # ][ # # ]: 0 : xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextTable") ) ) >>= xTextTable;
[ # # ][ # # ]
806 [ # # ]: 0 : if( xTextTable.is() )
807 : : {
808 [ # # ]: 0 : uno::Reference< css::text::XTextDocument > xTextDoc( mxModel, uno::UNO_QUERY_THROW );
809 [ # # ][ # # ]: 0 : uno::Reference< word::XTable > xVBATbl = new SwVbaTable( mxParent, mxContext, xTextDoc, xTextTable );
[ # # ][ # # ]
810 [ # # ]: 0 : aRet <<= xVBATbl;
811 : 0 : return aRet;
812 : : }
813 : :
814 : : // if the current selection is a XTextTableCursor and the index is 1 then we can service this request, otherwise we just have to throw
815 [ # # ][ # # ]: 0 : uno::Reference< text::XTextTableCursor > xTextTableCursor( mxModel->getCurrentSelection(), uno::UNO_QUERY );
[ # # ]
816 : :
817 [ # # ]: 0 : if ( !xTextTableCursor.is() )
818 [ # # ]: 0 : throw uno::RuntimeException();
819 : :
820 [ # # ][ # # ]: 0 : SwXTextTableCursor* pTTCursor = dynamic_cast< SwXTextTableCursor* >( xTextTableCursor.get() );
821 [ # # ]: 0 : if ( pTTCursor )
822 : : {
823 : 0 : SwFrmFmt* pFmt = pTTCursor->GetFrmFmt();
824 [ # # ]: 0 : if ( pFmt )
825 : : {
826 [ # # ][ # # ]: 0 : uno::Reference< text::XTextTable > xTbl = SwXTextTables::GetObject(*pFmt);
827 [ # # ]: 0 : uno::Reference< css::text::XTextDocument > xTextDoc( mxModel, uno::UNO_QUERY_THROW );
828 [ # # ][ # # ]: 0 : uno::Reference< word::XTable > xVBATbl = new SwVbaTable( mxParent, mxContext, xTextDoc, xTbl );
[ # # ][ # # ]
829 [ # # ]: 0 : aRet <<= xVBATbl;
830 : : }
831 : : }
832 : 0 : return aRet;
833 : :
834 : : }
835 : :
836 : : uno::Any SAL_CALL
837 : 0 : SwVbaSelection::Fields( const uno::Any& index ) throw (uno::RuntimeException)
838 : : {
839 [ # # ][ # # ]: 0 : uno::Reference< XCollection > xCol( new SwVbaFields( mxParent, mxContext, mxModel ) );
[ # # ][ # # ]
840 [ # # ]: 0 : if ( index.hasValue() )
841 [ # # ][ # # ]: 0 : return xCol->Item( index, uno::Any() );
842 [ # # ]: 0 : return uno::makeAny( xCol );
843 : : }
844 : :
845 : : uno::Reference< word::XHeaderFooter > SAL_CALL
846 : 0 : SwVbaSelection::getHeaderFooter() throw ( uno::RuntimeException )
847 : : {
848 [ # # ]: 0 : if( HeaderFooterHelper::isHeaderFooter( mxModel ) )
849 : : {
850 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xPageStyleProps( word::getCurrentPageStyle( mxModel ), uno::UNO_QUERY_THROW );
851 : 0 : sal_Int32 nIndex = word::WdHeaderFooterIndex::wdHeaderFooterPrimary;
852 [ # # ]: 0 : sal_Bool isHeader = HeaderFooterHelper::isHeader( mxModel );
853 [ # # ][ # # ]: 0 : if( HeaderFooterHelper::isEvenPagesHeader( mxModel ) || HeaderFooterHelper::isEvenPagesFooter( mxModel ) )
[ # # ][ # # ]
[ # # ]
854 : 0 : nIndex = word::WdHeaderFooterIndex::wdHeaderFooterEvenPages;
855 [ # # ][ # # ]: 0 : else if( HeaderFooterHelper::isFirstPageHeader( mxModel ) || HeaderFooterHelper::isFirstPageFooter( mxModel ) )
[ # # ][ # # ]
[ # # ]
856 : 0 : nIndex = word::WdHeaderFooterIndex::wdHeaderFooterFirstPage;
857 : :
858 [ # # ][ # # ]: 0 : return uno::Reference< word::XHeaderFooter >( new SwVbaHeaderFooter( this, mxContext, mxModel, xPageStyleProps, isHeader, nIndex ) );
[ # # ][ # # ]
859 : :
860 : : }
861 : 0 : return uno::Reference< word::XHeaderFooter >();
862 : : }
863 : :
864 : : uno::Any SAL_CALL
865 : 0 : SwVbaSelection::ShapeRange( ) throw (uno::RuntimeException)
866 : : {
867 [ # # ][ # # ]: 0 : uno::Reference< drawing::XShapes > xShapes( mxModel->getCurrentSelection(), uno::UNO_QUERY );
[ # # ]
868 [ # # ]: 0 : if ( !xShapes.is() )
869 : : {
870 [ # # ][ # # ]: 0 : uno::Reference< drawing::XShape > xShape( mxModel->getCurrentSelection(), uno::UNO_QUERY_THROW );
[ # # ]
871 [ # # ][ # # ]: 0 : uno::Reference< lang::XMultiServiceFactory > xMSF( mxContext->getServiceManager(), uno::UNO_QUERY_THROW );
[ # # ]
872 [ # # ][ # # ]: 0 : xShapes.set( xMSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.ShapeCollection")) ), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
873 [ # # ][ # # ]: 0 : xShapes->add( xShape );
874 : : }
875 : :
876 [ # # ]: 0 : uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxModel, uno::UNO_QUERY_THROW );
877 [ # # ][ # # ]: 0 : uno::Reference< drawing::XDrawPage > xDrawPage = xDrawPageSupplier->getDrawPage();
878 [ # # ]: 0 : uno::Reference< container::XIndexAccess > xShapesAccess( xShapes, uno::UNO_QUERY_THROW );
879 [ # # ][ # # ]: 0 : return uno::makeAny( uno::Reference< msforms::XShapeRange >( new ScVbaShapeRange( this, mxContext, xShapesAccess, xDrawPage, mxModel ) ) );
[ # # ][ # # ]
[ # # ]
880 : : }
881 : :
882 : 0 : ::sal_Int32 SAL_CALL SwVbaSelection::getStart() throw (uno::RuntimeException)
883 : : {
884 [ # # ][ # # ]: 0 : return getRange()->getStart();
885 : : }
886 : :
887 : 0 : void SAL_CALL SwVbaSelection::setStart( ::sal_Int32 _start ) throw (uno::RuntimeException)
888 : : {
889 [ # # ][ # # ]: 0 : getRange()->setStart( _start );
890 : 0 : }
891 : 0 : ::sal_Int32 SAL_CALL SwVbaSelection::getEnd() throw (uno::RuntimeException)
892 : : {
893 [ # # ][ # # ]: 0 : return getRange()->getEnd();
894 : : }
895 : :
896 : 0 : void SAL_CALL SwVbaSelection::setEnd( ::sal_Int32 _end ) throw (uno::RuntimeException)
897 : : {
898 [ # # ][ # # ]: 0 : getRange()->setEnd( _end );
899 : 0 : }
900 : :
901 : 0 : void SAL_CALL SwVbaSelection::SelectRow() throw (uno::RuntimeException)
902 : : {
903 [ # # ][ # # ]: 0 : uno::Reference< word::XRows > xRows( Rows( uno::Any() ), uno::UNO_QUERY_THROW );
904 [ # # ][ # # ]: 0 : xRows->Select();
905 : 0 : }
906 : :
907 : 0 : void SAL_CALL SwVbaSelection::SelectColumn() throw (uno::RuntimeException)
908 : : {
909 [ # # ][ # # ]: 0 : uno::Reference< word::XColumns > xColumns( Columns( uno::Any() ), uno::UNO_QUERY_THROW );
910 [ # # ][ # # ]: 0 : xColumns->Select();
911 : 0 : }
912 : :
913 : 0 : uno::Any SAL_CALL SwVbaSelection::Rows( const uno::Any& index ) throw (uno::RuntimeException)
914 : : {
915 : 0 : rtl::OUString sTLName;
916 : 0 : rtl::OUString sBRName;
917 [ # # ]: 0 : GetSelectedCellRange( sTLName, sBRName );
918 : :
919 : 0 : sal_Int32 nStartRow = 0;
920 : 0 : sal_Int32 nEndRow = 0;
921 [ # # ]: 0 : uno::Reference< text::XTextTable > xTextTable = GetXTextTable();
922 [ # # ]: 0 : SwVbaTableHelper aTableHelper( xTextTable );
923 [ # # ]: 0 : nStartRow = aTableHelper.getTabRowIndex( sTLName );
924 [ # # ]: 0 : if( !sBRName.isEmpty() )
925 : : {
926 [ # # ]: 0 : nEndRow = aTableHelper.getTabRowIndex( sBRName );
927 : : }
928 : : else
929 : : {
930 : 0 : nEndRow = nStartRow;
931 : : }
932 : :
933 [ # # ][ # # ]: 0 : uno::Reference< XCollection > xCol( new SwVbaRows( this, mxContext, xTextTable, xTextTable->getRows(), nStartRow, nEndRow ) );
[ # # ][ # # ]
[ # # ][ # # ]
934 [ # # ]: 0 : if ( index.hasValue() )
935 [ # # ][ # # ]: 0 : return xCol->Item( index, uno::Any() );
936 [ # # ][ # # ]: 0 : return uno::makeAny( xCol );
937 : : }
938 : :
939 : 0 : uno::Any SAL_CALL SwVbaSelection::Columns( const uno::Any& index ) throw (uno::RuntimeException)
940 : : {
941 : 0 : rtl::OUString sTLName;
942 : 0 : rtl::OUString sBRName;
943 [ # # ]: 0 : GetSelectedCellRange( sTLName, sBRName );
944 : 0 : sal_Int32 nStartColumn = 0;
945 : 0 : sal_Int32 nEndColumn = 0;
946 : :
947 [ # # ]: 0 : uno::Reference< text::XTextTable > xTextTable = GetXTextTable();
948 [ # # ]: 0 : SwVbaTableHelper aTableHelper( xTextTable );
949 [ # # ]: 0 : nStartColumn = aTableHelper.getTabColIndex( sTLName );
950 [ # # ]: 0 : if( !sBRName.isEmpty() )
951 : : {
952 [ # # ]: 0 : nEndColumn = aTableHelper.getTabColIndex( sBRName );
953 : : }
954 : : else
955 : : {
956 : 0 : nEndColumn = nStartColumn;
957 : : }
958 : :
959 [ # # ][ # # ]: 0 : uno::Reference< XCollection > xCol( new SwVbaColumns( this, mxContext, xTextTable, xTextTable->getColumns(), nStartColumn, nEndColumn ) );
[ # # ][ # # ]
[ # # ][ # # ]
960 [ # # ]: 0 : if ( index.hasValue() )
961 [ # # ][ # # ]: 0 : return xCol->Item( index, uno::Any() );
962 [ # # ][ # # ]: 0 : return uno::makeAny( xCol );
963 : : }
964 : :
965 : 0 : uno::Reference< text::XTextTable > SwVbaSelection::GetXTextTable() throw( uno::RuntimeException )
966 : : {
967 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW );
968 : 0 : uno::Reference< text::XTextTable > xTextTable;
969 [ # # ][ # # ]: 0 : xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextTable") ) ) >>= xTextTable;
[ # # ][ # # ]
970 : 0 : return xTextTable;
971 : : }
972 : :
973 : 0 : sal_Bool SwVbaSelection::IsInTable() throw( uno::RuntimeException )
974 : : {
975 [ # # ]: 0 : uno::Reference< text::XTextTable > xTextTable = GetXTextTable();
976 [ # # ]: 0 : if( xTextTable.is() )
977 : 0 : return sal_True;
978 : 0 : return sal_False;
979 : : }
980 : :
981 : 0 : sal_Bool SwVbaSelection::HasSelection() throw( uno::RuntimeException )
982 : : {
983 [ # # ][ # # ]: 0 : uno::Reference< text::XTextRange > xStart = mxTextViewCursor->getStart();
984 [ # # ][ # # ]: 0 : uno::Reference< text::XTextRange > xEnd = mxTextViewCursor->getEnd();
985 [ # # ][ # # ]: 0 : uno::Reference< text::XTextRangeCompare > xTRC( mxTextViewCursor->getText(), uno::UNO_QUERY_THROW );
[ # # ]
986 [ # # ][ # # ]: 0 : if( xTRC->compareRegionStarts( xStart, xEnd ) == 0 && xTRC->compareRegionEnds( xStart, xEnd ) == 0 )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
987 : 0 : return sal_False;
988 : 0 : return sal_True;
989 : : }
990 : :
991 : 0 : void SwVbaSelection::GetSelectedCellRange( rtl::OUString& sTLName, rtl::OUString& sBRName ) throw( uno::RuntimeException )
992 : : {
993 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW );
994 : 0 : uno::Reference< text::XTextTable > xTextTable;
995 [ # # ][ # # ]: 0 : xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextTable") ) ) >>= xTextTable;
[ # # ][ # # ]
996 [ # # ]: 0 : if( !xTextTable.is() )
997 [ # # ]: 0 : throw uno::RuntimeException( );
998 : :
999 [ # # ][ # # ]: 0 : uno::Reference< text::XTextTableCursor > xTextTableCursor( mxModel->getCurrentSelection(), uno::UNO_QUERY );
[ # # ]
1000 [ # # ]: 0 : if( xTextTableCursor.is() )
1001 : : {
1002 [ # # ][ # # ]: 0 : String sRange( xTextTableCursor->getRangeName() );
[ # # ]
1003 [ # # ][ # # ]: 0 : if( comphelper::string::getTokenCount(sRange, ':') > 0 )
[ # # ]
1004 : : {
1005 [ # # ][ # # ]: 0 : sTLName = sRange.GetToken(0, ':');
[ # # ]
1006 [ # # ][ # # ]: 0 : sBRName = sRange.GetToken(1, ':');
[ # # ]
1007 [ # # ]: 0 : }
1008 : : }
1009 [ # # ]: 0 : if( sTLName.isEmpty() )
1010 : : {
1011 : 0 : uno::Reference< table::XCell > xCell;
1012 [ # # ][ # # ]: 0 : xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Cell") ) ) >>= xCell;
[ # # ][ # # ]
1013 [ # # ]: 0 : if( !xCell.is() )
1014 : : {
1015 [ # # ]: 0 : throw uno::RuntimeException( );
1016 : : }
1017 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xCellProps( xCell, uno::UNO_QUERY_THROW );
1018 [ # # ][ # # ]: 0 : xCellProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CellName") ) ) >>= sTLName;
[ # # ]
1019 : 0 : }
1020 : 0 : }
1021 : :
1022 : 0 : uno::Any SAL_CALL SwVbaSelection::Cells( const uno::Any& index ) throw (uno::RuntimeException)
1023 : : {
1024 : 0 : rtl::OUString sTLName;
1025 : 0 : rtl::OUString sBRName;
1026 [ # # ]: 0 : GetSelectedCellRange( sTLName, sBRName );
1027 : 0 : sal_Int32 nLeft = 0;
1028 : 0 : sal_Int32 nTop = 0;
1029 : 0 : sal_Int32 nRight = 0;
1030 : 0 : sal_Int32 nBottom = 0;
1031 : :
1032 [ # # ]: 0 : uno::Reference< text::XTextTable > xTextTable = GetXTextTable();
1033 [ # # ]: 0 : SwVbaTableHelper aTableHelper( xTextTable );
1034 [ # # ]: 0 : nLeft = aTableHelper.getTabColIndex( sTLName );
1035 [ # # ]: 0 : nTop = aTableHelper.getTabRowIndex( sTLName );
1036 [ # # ]: 0 : if( !sBRName.isEmpty() )
1037 : : {
1038 [ # # ]: 0 : nRight = aTableHelper.getTabColIndex( sBRName );
1039 [ # # ]: 0 : nBottom = aTableHelper.getTabRowIndex( sBRName );
1040 : : }
1041 : : else
1042 : : {
1043 : 0 : nRight = nLeft;
1044 : 0 : nBottom = nTop;
1045 : : }
1046 : :
1047 [ # # ][ # # ]: 0 : uno::Reference< XCollection > xCol( new SwVbaCells( this, mxContext, xTextTable, nLeft, nTop, nRight, nBottom ) );
[ # # ][ # # ]
1048 [ # # ]: 0 : if ( index.hasValue() )
1049 [ # # ][ # # ]: 0 : return xCol->Item( index, uno::Any() );
1050 [ # # ][ # # ]: 0 : return uno::makeAny( xCol );
1051 : : }
1052 : :
1053 : 0 : void SAL_CALL SwVbaSelection::Copy( ) throw (uno::RuntimeException)
1054 : : {
1055 [ # # ]: 0 : rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:Copy"));
1056 [ # # ]: 0 : dispatchRequests( mxModel,url );
1057 : 0 : }
1058 : :
1059 : 0 : void SAL_CALL SwVbaSelection::CopyAsPicture( ) throw (uno::RuntimeException)
1060 : : {
1061 : : // seems not support in Writer
1062 : 0 : Copy();
1063 : 0 : }
1064 : :
1065 : 0 : void SAL_CALL SwVbaSelection::Paste( ) throw (uno::RuntimeException)
1066 : : {
1067 [ # # ]: 0 : rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:Paste"));
1068 [ # # ]: 0 : dispatchRequests( mxModel,url );
1069 : 0 : }
1070 : :
1071 : 0 : void SAL_CALL SwVbaSelection::Collapse( const uno::Any& Direction ) throw (uno::RuntimeException)
1072 : : {
1073 [ # # ][ # # ]: 0 : if( word::gotoSelectedObjectAnchor( mxModel ) )
1074 : 0 : return;
1075 : :
1076 : 0 : sal_Int32 nDirection = word::WdCollapseDirection::wdCollapseStart;
1077 [ # # ]: 0 : if( Direction.hasValue() )
1078 : 0 : Direction >>= nDirection;
1079 : :
1080 [ # # ]: 0 : uno::Reference< text::XTextViewCursor > xTextViewCursor = word::getXTextViewCursor( mxModel );
1081 [ # # ]: 0 : if( nDirection == word::WdCollapseDirection::wdCollapseStart )
1082 : : {
1083 : : // it is inaccurate if current seleciton is multipul cells, so it needs to go to start
1084 [ # # ][ # # ]: 0 : uno::Reference< text::XTextRange > xTextRange = mxTextViewCursor->getStart();
1085 [ # # ][ # # ]: 0 : xTextViewCursor->gotoRange( xTextRange, sal_False );
1086 [ # # ][ # # ]: 0 : xTextViewCursor->collapseToStart();
1087 : : }
1088 [ # # ]: 0 : else if( nDirection == word::WdCollapseDirection::wdCollapseEnd )
1089 : : {
1090 [ # # ][ # # ]: 0 : uno::Reference< text::XTextRange > xTextRange = mxTextViewCursor->getEnd();
1091 [ # # ][ # # ]: 0 : xTextViewCursor->gotoRange( xTextRange, sal_False );
1092 [ # # ][ # # ]: 0 : xTextViewCursor->collapseToEnd();
1093 : : }
1094 : : else
1095 : : {
1096 [ # # ]: 0 : throw uno::RuntimeException();
1097 : 0 : }
1098 : : }
1099 : :
1100 : 0 : void SAL_CALL SwVbaSelection::WholeStory( ) throw (uno::RuntimeException)
1101 : : {
1102 [ # # ]: 0 : uno::Reference< text::XText > xText = word::getCurrentXText( mxModel );
1103 : : // FIXME: for i#7747,if the first line is a table, it fails to select all the contents in the story.
1104 : : // Temporary solution, insert an empty line before the table so that it could select all the contents.
1105 [ # # ]: 0 : uno::Reference< container::XEnumerationAccess > xParaAccess( xText, uno::UNO_QUERY_THROW );
1106 [ # # ][ # # ]: 0 : uno::Reference< container::XEnumeration> xParaEnum = xParaAccess->createEnumeration();
1107 [ # # ][ # # ]: 0 : if( xParaEnum->hasMoreElements() )
[ # # ]
1108 : : {
1109 [ # # ][ # # ]: 0 : uno::Reference< text::XTextTable > xTextTable( xParaEnum->nextElement(), uno::UNO_QUERY );
[ # # ]
1110 [ # # ]: 0 : if( xTextTable.is() )
1111 : : {
1112 : : // insert an empty line
1113 [ # # ]: 0 : uno::Reference< text::XTextRange > xFirstCellRange = word::getFirstObjectPosition( xText );
1114 [ # # ][ # # ]: 0 : mxTextViewCursor->gotoRange( xFirstCellRange, sal_False );
1115 [ # # ]: 0 : rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:InsertPara"));
1116 [ # # ]: 0 : dispatchRequests( mxModel,url );
1117 : 0 : }
1118 : : }
1119 [ # # ][ # # ]: 0 : uno::Reference< text::XTextRange > xStart = xText->getStart();
1120 [ # # ][ # # ]: 0 : uno::Reference< text::XTextRange > xEnd = xText->getEnd();
1121 [ # # ][ # # ]: 0 : mxTextViewCursor->gotoRange( xStart, sal_False );
1122 [ # # ][ # # ]: 0 : mxTextViewCursor->gotoRange( xEnd, sal_True );
1123 : 0 : }
1124 : :
1125 : 0 : ::sal_Bool SAL_CALL SwVbaSelection::InRange( const uno::Reference< ::ooo::vba::word::XRange >& Range ) throw (uno::RuntimeException)
1126 : : {
1127 [ # # ][ # # ]: 0 : return getRange()->InRange( Range );
1128 : : }
1129 : :
1130 : 0 : void SAL_CALL SwVbaSelection::SplitTable( ) throw (uno::RuntimeException)
1131 : : {
1132 [ # # ]: 0 : if( !IsInTable() )
1133 [ # # ]: 0 : throw uno::RuntimeException();
1134 : :
1135 : 0 : SwDocShell* pDocShell = word::getDocShell( mxModel );
1136 [ # # ]: 0 : if( pDocShell )
1137 : : {
1138 : 0 : SwFEShell* pFEShell = pDocShell->GetFEShell();
1139 [ # # ]: 0 : if( pFEShell )
1140 : : {
1141 : 0 : pFEShell->SplitTable( HEADLINE_CNTNTCOPY );
1142 : : }
1143 : : }
1144 : 0 : }
1145 : :
1146 : : uno::Any SAL_CALL
1147 : 0 : SwVbaSelection::Paragraphs( const uno::Any& aIndex ) throw (uno::RuntimeException)
1148 : : {
1149 : : // Hacky implementation due to missing api ( and lack of knowledge )
1150 : : // we can only support a selection that is a single paragraph
1151 [ # # ]: 0 : if ( !aIndex.hasValue() ) // currently we can't support multiple paragraphs in a selection
1152 [ # # ]: 0 : throw uno::RuntimeException();
1153 : :
1154 : 0 : sal_Int32 nIndex = 0;
1155 : 0 : aIndex >>= nIndex;
1156 : :
1157 : 0 : uno::Any aRet;
1158 : :
1159 [ # # ]: 0 : if ( nIndex != 1 )
1160 [ # # ]: 0 : throw uno::RuntimeException();
1161 : :
1162 [ # # ][ # # ]: 0 : uno::Reference< text::XTextRange > xTextRange = mxTextViewCursor->getStart();
1163 [ # # ][ # # ]: 0 : uno::Reference< text::XText > xText = xTextRange->getText();
1164 [ # # ][ # # ]: 0 : uno::Reference< text::XParagraphCursor > xParaCursor( xText->createTextCursor(), uno::UNO_QUERY_THROW );
[ # # ]
1165 [ # # ][ # # ]: 0 : xParaCursor->gotoStartOfParagraph( sal_False );
1166 [ # # ][ # # ]: 0 : xParaCursor->gotoStartOfParagraph( sal_True );
1167 : :
1168 [ # # ]: 0 : uno::Reference< text::XTextDocument > xTextDoc( mxModel, uno::UNO_QUERY_THROW );
1169 [ # # ]: 0 : uno::Reference< text::XTextRange > xParaRange( xParaCursor, uno::UNO_QUERY_THROW );
1170 [ # # ][ # # ]: 0 : uno::Reference< word::XParagraph > xParagraph = new SwVbaParagraph( mxParent, mxContext, xTextDoc, xParaRange );
[ # # ][ # # ]
1171 : :
1172 [ # # ]: 0 : aRet <<= xParagraph;
1173 : 0 : return aRet;
1174 : : }
1175 : :
1176 : : rtl::OUString
1177 : 0 : SwVbaSelection::getServiceImplName()
1178 : : {
1179 : 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaSelection"));
1180 : : }
1181 : :
1182 : : uno::Sequence< rtl::OUString >
1183 : 0 : SwVbaSelection::getServiceNames()
1184 : : {
1185 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > aServiceNames;
[ # # ][ # # ]
1186 [ # # ]: 0 : if ( aServiceNames.getLength() == 0 )
1187 : : {
1188 : 0 : aServiceNames.realloc( 1 );
1189 [ # # ]: 0 : aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Selection" ) );
1190 : : }
1191 : 0 : return aServiceNames;
1192 : : }
1193 : :
1194 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|