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