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("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("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, std::exception )
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 : OUString SAL_CALL
109 0 : SwVbaSelection::getText() throw ( uno::RuntimeException, std::exception )
110 : {
111 0 : return getRange()->getText();
112 : }
113 :
114 : void SAL_CALL
115 0 : SwVbaSelection::setText( const OUString& rText ) throw ( uno::RuntimeException, std::exception )
116 : {
117 0 : getRange()->setText( rText );
118 0 : }
119 :
120 : void SAL_CALL
121 0 : SwVbaSelection::TypeText( const OUString& rText ) throw ( uno::RuntimeException, std::exception )
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, std::exception )
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("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, std::exception )
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("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, std::exception )
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("Not implemented", uno::Reference< uno::XInterface >() );
219 : }
220 : }
221 : }
222 0 : OUString url = ".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 0 : 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, OUString());
252 0 : 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("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("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("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("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("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("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("TextTable") >>= xTextTable;
357 0 : xCursorProps->getPropertyValue("Cell") >>= xCell;
358 0 : if( !xTextTable.is() || !xCell.is() )
359 : {
360 0 : DebugHelper::exception(SbERR_BAD_ARGUMENT, OUString());
361 0 : return;
362 : }
363 0 : uno::Reference< beans::XPropertySet > xCellProps( xCell, uno::UNO_QUERY_THROW );
364 0 : OUString aCellName;
365 0 : xCellProps->getPropertyValue("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, OUString());
393 0 : 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, std::exception )
403 : {
404 0 : sal_Int32 nCount = 1;
405 :
406 0 : if( _count.hasValue() )
407 0 : _count >>= nCount;
408 :
409 0 : if( nCount == 0 )
410 0 : return;
411 :
412 0 : if( nCount < 0 )
413 : {
414 0 : MoveLeft( _unit, uno::makeAny( -nCount ), _extend );
415 0 : 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, std::exception )
423 : {
424 0 : sal_Int32 nCount = 1;
425 0 : if( _count.hasValue() )
426 0 : _count >>= nCount;
427 :
428 0 : if( nCount == 0 )
429 0 : return;
430 :
431 0 : if( nCount < 0 )
432 : {
433 0 : MoveRight( _unit, uno::makeAny( -nCount ), _extend );
434 0 : 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, std::exception )
442 : {
443 0 : sal_Int32 nCount = 1;
444 :
445 0 : if( _count.hasValue() )
446 0 : _count >>= nCount;
447 :
448 0 : if( nCount == 0 )
449 0 : return;
450 :
451 0 : if( nCount < 0 )
452 : {
453 0 : MoveUp( _unit, uno::makeAny( -nCount ), _extend );
454 0 : 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, std::exception )
462 : {
463 0 : sal_Int32 nCount = 1;
464 :
465 0 : if( _count.hasValue() )
466 0 : _count >>= nCount;
467 :
468 0 : if( nCount == 0 )
469 0 : return;
470 :
471 0 : if( nCount < 0 )
472 : {
473 0 : MoveDown( _unit, uno::makeAny( -nCount ), _extend );
474 0 : 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, std::exception )
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, std::exception )
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, std::exception )
500 : {
501 0 : getRange()->InsertParagraphBefore();
502 0 : }
503 :
504 : void SAL_CALL
505 0 : SwVbaSelection::InsertParagraphAfter() throw ( uno::RuntimeException, std::exception )
506 : {
507 0 : getRange()->InsertParagraphAfter();
508 0 : }
509 :
510 : uno::Reference< word::XParagraphFormat > SAL_CALL
511 0 : SwVbaSelection::getParagraphFormat() throw ( uno::RuntimeException, std::exception )
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, std::exception )
518 : {
519 0 : return getRange()->setParagraphFormat( rParagraphFormat );
520 : }
521 :
522 : uno::Reference< word::XFind > SAL_CALL
523 0 : SwVbaSelection::getFind() throw ( uno::RuntimeException, std::exception )
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, std::exception )
531 : {
532 0 : return getRange()->getStyle();
533 : }
534 :
535 : void SAL_CALL
536 0 : SwVbaSelection::setStyle( const uno::Any& rStyle ) throw ( uno::RuntimeException, std::exception )
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, std::exception )
544 : {
545 0 : return getRange()->getFont();
546 : }
547 :
548 : void SAL_CALL
549 0 : SwVbaSelection::TypeBackspace() throw ( uno::RuntimeException, std::exception )
550 : {
551 0 : OUString url = ".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 )
556 : throw (script::BasicErrorException, uno::RuntimeException, std::exception)
557 : {
558 0 : sal_Int32 nWhat = 0;
559 0 : if( !( _what >>= nWhat ) )
560 0 : DebugHelper::exception(SbERR_BAD_ARGUMENT, OUString());
561 0 : switch( nWhat )
562 : {
563 : case word::WdGoToItem::wdGoToBookmark:
564 : {
565 0 : uno::Reference< word::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
566 0 : uno::Reference< word::XBookmark > xBookmark( xApplication->getActiveDocument()->Bookmarks(_name), uno::UNO_QUERY_THROW );
567 0 : xBookmark->Select();
568 0 : break;
569 : }
570 : case word::WdGoToItem::wdGoToPage:
571 : {
572 0 : uno::Reference< text::XPageCursor > xPageCursor( mxTextViewCursor, uno::UNO_QUERY_THROW );
573 0 : sal_Int32 nCurrPage = xPageCursor->getPage();
574 0 : sal_Int32 nLastPage = word::getPageCount( mxModel );
575 0 : sal_Int32 nCount = 0;
576 0 : if( _count.hasValue() )
577 0 : _count >>= nCount;
578 0 : sal_Int32 nWhich = 0;
579 0 : if( _which.hasValue() )
580 0 : _which >>= nWhich;
581 0 : sal_Int32 nPage = 0;
582 0 : switch( nWhich )
583 : {
584 : case word::WdGoToDirection::wdGoToLast:
585 : {
586 0 : nPage = nLastPage;
587 0 : break;
588 : }
589 : case word::WdGoToDirection::wdGoToNext:
590 : {
591 0 : if( nCount !=0 )
592 0 : nPage = nCurrPage + nCount;
593 : else
594 0 : nPage = nCurrPage + 1;
595 0 : break;
596 : }
597 : case word::WdGoToDirection::wdGoToPrevious:
598 : {
599 0 : if( nCount !=0 )
600 0 : nPage = nCurrPage - nCount;
601 : else
602 0 : nPage = nCurrPage - 1;
603 0 : break;
604 : }
605 : default:
606 : {
607 0 : nPage = nCount;
608 : }
609 : }
610 0 : if( _name.hasValue() )
611 : {
612 0 : OUString sName;
613 0 : _name >>= sName;
614 0 : sal_Int32 nName = sName.toInt32();
615 0 : if( nName !=0 )
616 0 : nPage = nName;
617 : }
618 0 : if( nPage <= 0 )
619 0 : nPage = 1;
620 0 : if( nPage > nLastPage )
621 0 : nPage = nLastPage;
622 0 : xPageCursor->jumpToPage( ( sal_Int16 )( nPage ) );
623 0 : break;
624 : }
625 : case word::WdGoToItem::wdGoToSection:
626 : {
627 0 : uno::Reference< text::XPageCursor > xPageCursor( mxTextViewCursor, uno::UNO_QUERY_THROW );
628 0 : sal_Int32 nCount = 0;
629 0 : if( _count.hasValue() )
630 0 : _count >>= nCount;
631 0 : sal_Int32 nWhich = 0;
632 0 : if( _which.hasValue() )
633 0 : _which >>= nWhich;
634 0 : sal_Int32 nPage = 0;
635 0 : switch( nWhich )
636 : {
637 : case word::WdGoToDirection::wdGoToAbsolute:
638 : {
639 : // currently only support this type
640 0 : if( nCount == 1 )
641 0 : nPage = 1;
642 0 : break;
643 : }
644 : default:
645 : {
646 0 : nPage = 0;
647 : }
648 : }
649 0 : if( nPage != 0 )
650 0 : xPageCursor->jumpToPage( ( sal_Int16 )( nPage ) );
651 : else
652 0 : throw uno::RuntimeException("Not implemented", uno::Reference< uno::XInterface >() );
653 0 : break;
654 : }
655 : default:
656 0 : throw uno::RuntimeException("Not implemented", uno::Reference< uno::XInterface >() );
657 : }
658 0 : return getRange();
659 : }
660 :
661 0 : ::sal_Int32 SAL_CALL SwVbaSelection::getLanguageID() throw (uno::RuntimeException, std::exception)
662 : {
663 0 : return getRange()->getLanguageID();
664 : }
665 :
666 0 : void SAL_CALL SwVbaSelection::setLanguageID( ::sal_Int32 _languageid ) throw (uno::RuntimeException, std::exception)
667 : {
668 0 : getRange()->setLanguageID( _languageid );
669 0 : }
670 :
671 0 : uno::Any SAL_CALL SwVbaSelection::Information( sal_Int32 _type ) throw (uno::RuntimeException, std::exception)
672 : {
673 0 : uno::Any result;
674 0 : switch( _type )
675 : {
676 : case word::WdInformation::wdActiveEndPageNumber:
677 : {
678 0 : result = uno::makeAny( SwVbaInformationHelper::handleWdActiveEndPageNumber( mxTextViewCursor ) );
679 0 : break;
680 : }
681 : case word::WdInformation::wdNumberOfPagesInDocument:
682 : {
683 0 : result = uno::makeAny( SwVbaInformationHelper::handleWdNumberOfPagesInDocument( mxModel ) );
684 0 : break;
685 : }
686 : case word::WdInformation::wdVerticalPositionRelativeToPage:
687 : {
688 0 : result = uno::makeAny( SwVbaInformationHelper::handleWdVerticalPositionRelativeToPage( mxModel, mxTextViewCursor ) );
689 0 : break;
690 : }
691 : case word::WdInformation::wdWithInTable:
692 : {
693 0 : uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW );
694 0 : uno::Reference< text::XTextTable > xTextTable;
695 0 : xCursorProps->getPropertyValue("TextTable") >>= xTextTable;
696 0 : if( xTextTable.is() )
697 0 : result = uno::makeAny( sal_True );
698 : else
699 0 : result = uno::makeAny( sal_False );
700 0 : break;
701 : }
702 : case word::WdInformation::wdHeaderFooterType:
703 : {
704 0 : uno::Reference< word::XView > xView( new SwVbaView( this, mxContext, mxModel ) );
705 0 : sal_Int32 nView = xView->getSeekView();
706 0 : sal_Int32 nHeaderFooterType = 0;
707 0 : switch( nView )
708 : {
709 : case word::WdSeekView::wdSeekMainDocument:
710 : {
711 0 : nHeaderFooterType = -1; // not in a header or footer
712 0 : break;
713 : }
714 : case word::WdSeekView::wdSeekEvenPagesHeader:
715 : {
716 0 : nHeaderFooterType = 0; // even page header
717 0 : break;
718 : }
719 : case word::WdSeekView::wdSeekPrimaryHeader:
720 : {
721 0 : nHeaderFooterType = 1; // odd page header
722 0 : break;
723 : }
724 : case word::WdSeekView::wdSeekEvenPagesFooter:
725 : {
726 0 : nHeaderFooterType = 2; // even page footer
727 0 : break;
728 : }
729 : case word::WdSeekView::wdSeekPrimaryFooter:
730 : {
731 0 : nHeaderFooterType = 3; // odd page footer
732 0 : break;
733 : }
734 : case word::WdSeekView::wdSeekFirstPageHeader:
735 : case word::WdSeekView::wdSeekFirstPageFooter:
736 : {
737 0 : uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW );
738 0 : OUString aPageStyleName;
739 0 : xCursorProps->getPropertyValue("PageStyleName") >>= aPageStyleName;
740 0 : bool bFirstPage = false;
741 0 : if ( aPageStyleName == "First Page" )
742 0 : bFirstPage = true;
743 0 : if( nView == word::WdSeekView::wdSeekFirstPageHeader )
744 : {
745 0 : if( bFirstPage )
746 0 : nHeaderFooterType = 4;
747 : else
748 0 : nHeaderFooterType = 1;
749 : }
750 : else
751 : {
752 0 : if( bFirstPage )
753 0 : nHeaderFooterType = 5;
754 : else
755 0 : nHeaderFooterType = 3;
756 : }
757 0 : break;
758 : }
759 : default:
760 : {
761 0 : nHeaderFooterType = -1;
762 : }
763 : }
764 0 : result = uno::makeAny( nHeaderFooterType );
765 0 : break;
766 : }
767 : default:
768 0 : throw uno::RuntimeException("Not implemented", uno::Reference< uno::XInterface >() );
769 : }
770 0 : return result;
771 : }
772 :
773 0 : void SAL_CALL SwVbaSelection::InsertBreak( const uno::Any& _breakType ) throw (uno::RuntimeException, std::exception)
774 : {
775 0 : getRange()->InsertBreak( _breakType );
776 0 : }
777 :
778 : uno::Any SAL_CALL
779 0 : SwVbaSelection::Tables( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
780 : {
781 : // Hacky implementation due to missing api ( and lack of knowledge )
782 : // we can only support a selection that is a single table
783 0 : if ( !aIndex.hasValue() ) // currently we can't support multiple tables in a selection
784 0 : throw uno::RuntimeException();
785 :
786 0 : sal_Int32 nIndex = 0;
787 0 : aIndex >>= nIndex;
788 :
789 0 : uno::Any aRet;
790 :
791 0 : if ( nIndex != 1 )
792 0 : throw uno::RuntimeException();
793 :
794 0 : uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW );
795 0 : uno::Reference< text::XTextTable > xTextTable;
796 0 : xCursorProps->getPropertyValue("TextTable") >>= xTextTable;
797 0 : if( xTextTable.is() )
798 : {
799 0 : uno::Reference< css::text::XTextDocument > xTextDoc( mxModel, uno::UNO_QUERY_THROW );
800 0 : uno::Reference< word::XTable > xVBATbl = new SwVbaTable( mxParent, mxContext, xTextDoc, xTextTable );
801 0 : aRet <<= xVBATbl;
802 0 : return aRet;
803 : }
804 :
805 : // if the current selection is a XTextTableCursor and the index is 1 then we can service this request, otherwise we just have to throw
806 0 : uno::Reference< text::XTextTableCursor > xTextTableCursor( mxModel->getCurrentSelection(), uno::UNO_QUERY );
807 :
808 0 : if ( !xTextTableCursor.is() )
809 0 : throw uno::RuntimeException();
810 :
811 0 : SwXTextTableCursor* pTTCursor = dynamic_cast< SwXTextTableCursor* >( xTextTableCursor.get() );
812 0 : if ( pTTCursor )
813 : {
814 0 : SwFrmFmt* pFmt = pTTCursor->GetFrmFmt();
815 0 : if ( pFmt )
816 : {
817 0 : uno::Reference< text::XTextTable > xTbl = SwXTextTables::GetObject(*pFmt);
818 0 : uno::Reference< css::text::XTextDocument > xTextDoc( mxModel, uno::UNO_QUERY_THROW );
819 0 : uno::Reference< word::XTable > xVBATbl = new SwVbaTable( mxParent, mxContext, xTextDoc, xTbl );
820 0 : aRet <<= xVBATbl;
821 : }
822 : }
823 0 : return aRet;
824 :
825 : }
826 :
827 : uno::Any SAL_CALL
828 0 : SwVbaSelection::Fields( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
829 : {
830 0 : uno::Reference< XCollection > xCol( new SwVbaFields( mxParent, mxContext, mxModel ) );
831 0 : if ( index.hasValue() )
832 0 : return xCol->Item( index, uno::Any() );
833 0 : return uno::makeAny( xCol );
834 : }
835 :
836 : uno::Reference< word::XHeaderFooter > SAL_CALL
837 0 : SwVbaSelection::getHeaderFooter() throw ( uno::RuntimeException, std::exception )
838 : {
839 0 : if( HeaderFooterHelper::isHeaderFooter( mxModel ) )
840 : {
841 0 : uno::Reference< beans::XPropertySet > xPageStyleProps( word::getCurrentPageStyle( mxModel ), uno::UNO_QUERY_THROW );
842 0 : sal_Int32 nIndex = word::WdHeaderFooterIndex::wdHeaderFooterPrimary;
843 0 : sal_Bool isHeader = HeaderFooterHelper::isHeader( mxModel );
844 0 : if( HeaderFooterHelper::isEvenPagesHeader( mxModel ) || HeaderFooterHelper::isEvenPagesFooter( mxModel ) )
845 0 : nIndex = word::WdHeaderFooterIndex::wdHeaderFooterEvenPages;
846 0 : else if( HeaderFooterHelper::isFirstPageHeader( mxModel ) || HeaderFooterHelper::isFirstPageFooter( mxModel ) )
847 0 : nIndex = word::WdHeaderFooterIndex::wdHeaderFooterFirstPage;
848 :
849 0 : return uno::Reference< word::XHeaderFooter >( new SwVbaHeaderFooter( this, mxContext, mxModel, xPageStyleProps, isHeader, nIndex ) );
850 :
851 : }
852 0 : return uno::Reference< word::XHeaderFooter >();
853 : }
854 :
855 : uno::Any SAL_CALL
856 0 : SwVbaSelection::ShapeRange( ) throw (uno::RuntimeException, std::exception)
857 : {
858 0 : uno::Reference< drawing::XShapes > xShapes( mxModel->getCurrentSelection(), uno::UNO_QUERY );
859 0 : if ( !xShapes.is() )
860 : {
861 0 : uno::Reference< drawing::XShape > xShape( mxModel->getCurrentSelection(), uno::UNO_QUERY_THROW );
862 0 : xShapes.set( drawing::ShapeCollection::create(mxContext) );
863 0 : xShapes->add( xShape );
864 : }
865 :
866 0 : uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxModel, uno::UNO_QUERY_THROW );
867 0 : uno::Reference< drawing::XDrawPage > xDrawPage = xDrawPageSupplier->getDrawPage();
868 0 : uno::Reference< container::XIndexAccess > xShapesAccess( xShapes, uno::UNO_QUERY_THROW );
869 0 : return uno::makeAny( uno::Reference< msforms::XShapeRange >( new ScVbaShapeRange( this, mxContext, xShapesAccess, xDrawPage, mxModel ) ) );
870 : }
871 :
872 0 : ::sal_Int32 SAL_CALL SwVbaSelection::getStart() throw (uno::RuntimeException, std::exception)
873 : {
874 0 : return getRange()->getStart();
875 : }
876 :
877 0 : void SAL_CALL SwVbaSelection::setStart( ::sal_Int32 _start ) throw (uno::RuntimeException, std::exception)
878 : {
879 0 : getRange()->setStart( _start );
880 0 : }
881 0 : ::sal_Int32 SAL_CALL SwVbaSelection::getEnd() throw (uno::RuntimeException, std::exception)
882 : {
883 0 : return getRange()->getEnd();
884 : }
885 :
886 0 : void SAL_CALL SwVbaSelection::setEnd( ::sal_Int32 _end ) throw (uno::RuntimeException, std::exception)
887 : {
888 0 : getRange()->setEnd( _end );
889 0 : }
890 :
891 0 : void SAL_CALL SwVbaSelection::SelectRow() throw (uno::RuntimeException, std::exception)
892 : {
893 0 : uno::Reference< word::XRows > xRows( Rows( uno::Any() ), uno::UNO_QUERY_THROW );
894 0 : xRows->Select();
895 0 : }
896 :
897 0 : void SAL_CALL SwVbaSelection::SelectColumn() throw (uno::RuntimeException, std::exception)
898 : {
899 0 : uno::Reference< word::XColumns > xColumns( Columns( uno::Any() ), uno::UNO_QUERY_THROW );
900 0 : xColumns->Select();
901 0 : }
902 :
903 0 : uno::Any SAL_CALL SwVbaSelection::Rows( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
904 : {
905 0 : OUString sTLName;
906 0 : OUString sBRName;
907 0 : GetSelectedCellRange( sTLName, sBRName );
908 :
909 0 : sal_Int32 nStartRow = 0;
910 0 : sal_Int32 nEndRow = 0;
911 0 : uno::Reference< text::XTextTable > xTextTable = GetXTextTable();
912 0 : SwVbaTableHelper aTableHelper( xTextTable );
913 0 : nStartRow = aTableHelper.getTabRowIndex( sTLName );
914 0 : if( !sBRName.isEmpty() )
915 : {
916 0 : nEndRow = aTableHelper.getTabRowIndex( sBRName );
917 : }
918 : else
919 : {
920 0 : nEndRow = nStartRow;
921 : }
922 :
923 0 : uno::Reference< XCollection > xCol( new SwVbaRows( this, mxContext, xTextTable, xTextTable->getRows(), nStartRow, nEndRow ) );
924 0 : if ( index.hasValue() )
925 0 : return xCol->Item( index, uno::Any() );
926 0 : return uno::makeAny( xCol );
927 : }
928 :
929 0 : uno::Any SAL_CALL SwVbaSelection::Columns( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
930 : {
931 0 : OUString sTLName;
932 0 : OUString sBRName;
933 0 : GetSelectedCellRange( sTLName, sBRName );
934 0 : sal_Int32 nStartColumn = 0;
935 0 : sal_Int32 nEndColumn = 0;
936 :
937 0 : uno::Reference< text::XTextTable > xTextTable = GetXTextTable();
938 0 : SwVbaTableHelper aTableHelper( xTextTable );
939 0 : nStartColumn = aTableHelper.getTabColIndex( sTLName );
940 0 : if( !sBRName.isEmpty() )
941 : {
942 0 : nEndColumn = aTableHelper.getTabColIndex( sBRName );
943 : }
944 : else
945 : {
946 0 : nEndColumn = nStartColumn;
947 : }
948 :
949 0 : uno::Reference< XCollection > xCol( new SwVbaColumns( this, mxContext, xTextTable, xTextTable->getColumns(), nStartColumn, nEndColumn ) );
950 0 : if ( index.hasValue() )
951 0 : return xCol->Item( index, uno::Any() );
952 0 : return uno::makeAny( xCol );
953 : }
954 :
955 0 : uno::Reference< text::XTextTable > SwVbaSelection::GetXTextTable() throw( uno::RuntimeException )
956 : {
957 0 : uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW );
958 0 : uno::Reference< text::XTextTable > xTextTable;
959 0 : xCursorProps->getPropertyValue("TextTable") >>= xTextTable;
960 0 : return xTextTable;
961 : }
962 :
963 0 : bool SwVbaSelection::IsInTable() throw( uno::RuntimeException )
964 : {
965 0 : uno::Reference< text::XTextTable > xTextTable = GetXTextTable();
966 0 : if( xTextTable.is() )
967 0 : return true;
968 0 : return false;
969 : }
970 :
971 0 : bool SwVbaSelection::HasSelection() throw( uno::RuntimeException )
972 : {
973 0 : uno::Reference< text::XTextRange > xStart = mxTextViewCursor->getStart();
974 0 : uno::Reference< text::XTextRange > xEnd = mxTextViewCursor->getEnd();
975 0 : uno::Reference< text::XTextRangeCompare > xTRC( mxTextViewCursor->getText(), uno::UNO_QUERY_THROW );
976 0 : if( xTRC->compareRegionStarts( xStart, xEnd ) == 0 && xTRC->compareRegionEnds( xStart, xEnd ) == 0 )
977 0 : return false;
978 0 : return true;
979 : }
980 :
981 0 : void SwVbaSelection::GetSelectedCellRange( OUString& sTLName, OUString& sBRName ) throw( uno::RuntimeException )
982 : {
983 0 : uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW );
984 0 : uno::Reference< text::XTextTable > xTextTable;
985 0 : xCursorProps->getPropertyValue("TextTable") >>= xTextTable;
986 0 : if( !xTextTable.is() )
987 0 : throw uno::RuntimeException( );
988 :
989 0 : uno::Reference< text::XTextTableCursor > xTextTableCursor( mxModel->getCurrentSelection(), uno::UNO_QUERY );
990 0 : if( xTextTableCursor.is() )
991 : {
992 0 : OUString sRange( xTextTableCursor->getRangeName() );
993 0 : if( comphelper::string::getTokenCount(sRange, ':') > 0 )
994 : {
995 0 : sTLName = sRange.getToken(0, ':');
996 0 : sBRName = sRange.getToken(1, ':');
997 0 : }
998 : }
999 0 : if( sTLName.isEmpty() )
1000 : {
1001 0 : uno::Reference< table::XCell > xCell;
1002 0 : xCursorProps->getPropertyValue("Cell") >>= xCell;
1003 0 : if( !xCell.is() )
1004 : {
1005 0 : throw uno::RuntimeException( );
1006 : }
1007 0 : uno::Reference< beans::XPropertySet > xCellProps( xCell, uno::UNO_QUERY_THROW );
1008 0 : xCellProps->getPropertyValue("CellName") >>= sTLName;
1009 0 : }
1010 0 : }
1011 :
1012 0 : uno::Any SAL_CALL SwVbaSelection::Cells( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
1013 : {
1014 0 : OUString sTLName;
1015 0 : OUString sBRName;
1016 0 : GetSelectedCellRange( sTLName, sBRName );
1017 0 : sal_Int32 nLeft = 0;
1018 0 : sal_Int32 nTop = 0;
1019 0 : sal_Int32 nRight = 0;
1020 0 : sal_Int32 nBottom = 0;
1021 :
1022 0 : uno::Reference< text::XTextTable > xTextTable = GetXTextTable();
1023 0 : SwVbaTableHelper aTableHelper( xTextTable );
1024 0 : nLeft = aTableHelper.getTabColIndex( sTLName );
1025 0 : nTop = aTableHelper.getTabRowIndex( sTLName );
1026 0 : if( !sBRName.isEmpty() )
1027 : {
1028 0 : nRight = aTableHelper.getTabColIndex( sBRName );
1029 0 : nBottom = aTableHelper.getTabRowIndex( sBRName );
1030 : }
1031 : else
1032 : {
1033 0 : nRight = nLeft;
1034 0 : nBottom = nTop;
1035 : }
1036 :
1037 0 : uno::Reference< XCollection > xCol( new SwVbaCells( this, mxContext, xTextTable, nLeft, nTop, nRight, nBottom ) );
1038 0 : if ( index.hasValue() )
1039 0 : return xCol->Item( index, uno::Any() );
1040 0 : return uno::makeAny( xCol );
1041 : }
1042 :
1043 0 : void SAL_CALL SwVbaSelection::Copy( ) throw (uno::RuntimeException, std::exception)
1044 : {
1045 0 : OUString url = ".uno:Copy";
1046 0 : dispatchRequests( mxModel,url );
1047 0 : }
1048 :
1049 0 : void SAL_CALL SwVbaSelection::CopyAsPicture( ) throw (uno::RuntimeException, std::exception)
1050 : {
1051 : // seems not support in Writer
1052 0 : Copy();
1053 0 : }
1054 :
1055 0 : void SAL_CALL SwVbaSelection::Paste( ) throw (uno::RuntimeException, std::exception)
1056 : {
1057 0 : OUString url = ".uno:Paste";
1058 0 : dispatchRequests( mxModel,url );
1059 0 : }
1060 :
1061 0 : void SAL_CALL SwVbaSelection::Collapse( const uno::Any& Direction ) throw (uno::RuntimeException, std::exception)
1062 : {
1063 0 : if( word::gotoSelectedObjectAnchor( mxModel ) )
1064 0 : return;
1065 :
1066 0 : sal_Int32 nDirection = word::WdCollapseDirection::wdCollapseStart;
1067 0 : if( Direction.hasValue() )
1068 0 : Direction >>= nDirection;
1069 :
1070 0 : uno::Reference< text::XTextViewCursor > xTextViewCursor = word::getXTextViewCursor( mxModel );
1071 0 : if( nDirection == word::WdCollapseDirection::wdCollapseStart )
1072 : {
1073 : // it is inaccurate if current seleciton is multipul cells, so it needs to go to start
1074 0 : uno::Reference< text::XTextRange > xTextRange = mxTextViewCursor->getStart();
1075 0 : xTextViewCursor->gotoRange( xTextRange, sal_False );
1076 0 : xTextViewCursor->collapseToStart();
1077 : }
1078 0 : else if( nDirection == word::WdCollapseDirection::wdCollapseEnd )
1079 : {
1080 0 : uno::Reference< text::XTextRange > xTextRange = mxTextViewCursor->getEnd();
1081 0 : xTextViewCursor->gotoRange( xTextRange, sal_False );
1082 0 : xTextViewCursor->collapseToEnd();
1083 : }
1084 : else
1085 : {
1086 0 : throw uno::RuntimeException();
1087 0 : }
1088 : }
1089 :
1090 0 : void SAL_CALL SwVbaSelection::WholeStory( ) throw (uno::RuntimeException, std::exception)
1091 : {
1092 0 : uno::Reference< text::XText > xText = word::getCurrentXText( mxModel );
1093 : // FIXME: for i#7747,if the first line is a table, it fails to select all the contents in the story.
1094 : // Temporary solution, insert an empty line before the table so that it could select all the contents.
1095 0 : uno::Reference< container::XEnumerationAccess > xParaAccess( xText, uno::UNO_QUERY_THROW );
1096 0 : uno::Reference< container::XEnumeration> xParaEnum = xParaAccess->createEnumeration();
1097 0 : if( xParaEnum->hasMoreElements() )
1098 : {
1099 0 : uno::Reference< text::XTextTable > xTextTable( xParaEnum->nextElement(), uno::UNO_QUERY );
1100 0 : if( xTextTable.is() )
1101 : {
1102 : // insert an empty line
1103 0 : uno::Reference< text::XTextRange > xFirstCellRange = word::getFirstObjectPosition( xText );
1104 0 : mxTextViewCursor->gotoRange( xFirstCellRange, sal_False );
1105 0 : OUString url = ".uno:InsertPara";
1106 0 : dispatchRequests( mxModel,url );
1107 0 : }
1108 : }
1109 0 : uno::Reference< text::XTextRange > xStart = xText->getStart();
1110 0 : uno::Reference< text::XTextRange > xEnd = xText->getEnd();
1111 0 : mxTextViewCursor->gotoRange( xStart, sal_False );
1112 0 : mxTextViewCursor->gotoRange( xEnd, sal_True );
1113 0 : }
1114 :
1115 0 : sal_Bool SAL_CALL SwVbaSelection::InRange( const uno::Reference< ::ooo::vba::word::XRange >& Range ) throw (uno::RuntimeException, std::exception)
1116 : {
1117 0 : return getRange()->InRange( Range );
1118 : }
1119 :
1120 0 : void SAL_CALL SwVbaSelection::SplitTable()
1121 : throw (uno::RuntimeException, std::exception)
1122 : {
1123 0 : if( !IsInTable() )
1124 0 : throw uno::RuntimeException();
1125 :
1126 0 : SwDocShell* pDocShell = word::getDocShell( mxModel );
1127 0 : if( pDocShell )
1128 : {
1129 0 : SwFEShell* pFEShell = pDocShell->GetFEShell();
1130 0 : if( pFEShell )
1131 : {
1132 0 : pFEShell->SplitTable( HEADLINE_CNTNTCOPY );
1133 : }
1134 : }
1135 0 : }
1136 :
1137 : uno::Any SAL_CALL
1138 0 : SwVbaSelection::Paragraphs( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
1139 : {
1140 : // Hacky implementation due to missing api ( and lack of knowledge )
1141 : // we can only support a selection that is a single paragraph
1142 0 : if ( !aIndex.hasValue() ) // currently we can't support multiple paragraphs in a selection
1143 0 : throw uno::RuntimeException();
1144 :
1145 0 : sal_Int32 nIndex = 0;
1146 0 : aIndex >>= nIndex;
1147 :
1148 0 : uno::Any aRet;
1149 :
1150 0 : if ( nIndex != 1 )
1151 0 : throw uno::RuntimeException();
1152 :
1153 0 : uno::Reference< text::XTextRange > xTextRange = mxTextViewCursor->getStart();
1154 0 : uno::Reference< text::XText > xText = xTextRange->getText();
1155 0 : uno::Reference< text::XParagraphCursor > xParaCursor( xText->createTextCursor(), uno::UNO_QUERY_THROW );
1156 0 : xParaCursor->gotoStartOfParagraph( sal_False );
1157 0 : xParaCursor->gotoStartOfParagraph( sal_True );
1158 :
1159 0 : uno::Reference< text::XTextDocument > xTextDoc( mxModel, uno::UNO_QUERY_THROW );
1160 0 : uno::Reference< text::XTextRange > xParaRange( xParaCursor, uno::UNO_QUERY_THROW );
1161 0 : uno::Reference< word::XParagraph > xParagraph = new SwVbaParagraph( mxParent, mxContext, xTextDoc, xParaRange );
1162 :
1163 0 : aRet <<= xParagraph;
1164 0 : return aRet;
1165 : }
1166 :
1167 : OUString
1168 0 : SwVbaSelection::getServiceImplName()
1169 : {
1170 0 : return OUString("SwVbaSelection");
1171 : }
1172 :
1173 : uno::Sequence< OUString >
1174 0 : SwVbaSelection::getServiceNames()
1175 : {
1176 0 : static uno::Sequence< OUString > aServiceNames;
1177 0 : if ( aServiceNames.getLength() == 0 )
1178 : {
1179 0 : aServiceNames.realloc( 1 );
1180 0 : aServiceNames[ 0 ] = "ooo.vba.word.Selection";
1181 : }
1182 0 : return aServiceNames;
1183 : }
1184 :
1185 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|