xref: /trunk/main/sw/source/ui/vba/vbaselection.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #include "vbaselection.hxx"
28 #include <vbahelper/vbahelper.hxx>
29 #include <tools/diagnose_ex.h>
30 #include "vbarange.hxx"
31 #include "vbafind.hxx"
32 #include "wordvbahelper.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 <ooo/vba/word/WdUnits.hpp>
39 #include <ooo/vba/word/WdMovementType.hpp>
40 #include <ooo/vba/word/WdGoToItem.hpp>
41 #include <ooo/vba/word/WdGoToDirection.hpp>
42 #include <ooo/vba/word/XBookmark.hpp>
43 #include <ooo/vba/word/XApplication.hpp>
44 #include <com/sun/star/text/XPageCursor.hpp>
45 #include "unotbl.hxx"
46 #include "unocoll.hxx"
47 #include "vbatable.hxx"
48 #include <com/sun/star/view/XSelectionSupplier.hpp>
49 #include <com/sun/star/view/XViewCursor.hpp>
50 #include <ooo/vba/word/WdInformation.hpp>
51 #include <ooo/vba/word/WdHeaderFooterIndex.hpp>
52 #include "vbainformationhelper.hxx"
53 #include "vbafield.hxx"
54 #include "vbaheaderfooter.hxx"
55 #include "vbaheaderfooterhelper.hxx"
56 #include <vbahelper/vbashaperange.hxx>
57 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
58 #include <com/sun/star/drawing/XDrawPage.hpp>
59 
60 using namespace ::ooo::vba;
61 using namespace ::com::sun::star;
62 
63 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 )
64 {
65     mxTextViewCursor = word::getXTextViewCursor( mxModel );
66 }
67 
68 SwVbaSelection::~SwVbaSelection()
69 {
70 }
71 
72 uno::Reference< text::XTextRange > SwVbaSelection::GetSelectedRange() throw ( uno::RuntimeException )
73 {
74     uno::Reference< text::XTextRange > xTextRange;
75     uno::Reference< lang::XServiceInfo > xServiceInfo( mxModel->getCurrentSelection(), uno::UNO_QUERY_THROW );
76     if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextRanges") ) ) )
77     {
78         uno::Reference< container::XIndexAccess > xTextRanges( xServiceInfo, uno::UNO_QUERY_THROW );
79         if( xTextRanges->getCount() > 0 )
80         {
81             // if there are multipul selection, just return the last selected Range.
82             xTextRange.set( xTextRanges->getByIndex( xTextRanges->getCount()-1 ), uno::UNO_QUERY_THROW );
83         }
84     }
85     else
86     {
87         throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
88     }
89     return xTextRange;
90 }
91 
92 uno::Reference< word::XRange > SAL_CALL
93 SwVbaSelection::getRange() throw ( uno::RuntimeException )
94 {
95     uno::Reference< text::XTextRange > xTextRange = GetSelectedRange();
96     uno::Reference< text::XTextDocument > xDocument( mxModel, uno::UNO_QUERY_THROW );
97     return uno::Reference< word::XRange >( new SwVbaRange( this, mxContext, xDocument, xTextRange->getStart(), xTextRange->getEnd(), mxTextViewCursor->getText() ) );
98 }
99 
100 rtl::OUString SAL_CALL
101 SwVbaSelection::getText() throw ( uno::RuntimeException )
102 {
103     return getRange()->getText();
104 }
105 
106 void SAL_CALL
107 SwVbaSelection::setText( const rtl::OUString& rText ) throw ( uno::RuntimeException )
108 {
109     getRange()->setText( rText );
110 }
111 
112 void SAL_CALL
113 SwVbaSelection::TypeText( const rtl::OUString& rText ) throw ( uno::RuntimeException )
114 {
115     // FIXME: handle the property Options.ReplaceSelection, the default value is sal_True
116     setText( rText );
117 }
118 
119 void SAL_CALL
120 SwVbaSelection::HomeKey( const uno::Any& _unit, const uno::Any& _extend ) throw ( uno::RuntimeException )
121 {
122     sal_Int32 nUnit = word::WdUnits::wdLine;
123     sal_Int32 nExtend = word::WdMovementType::wdMove;
124     _unit >>= nUnit;
125     _extend >>= nExtend;
126 
127     switch( nUnit )
128     {
129         case word::WdUnits::wdStory:
130         {
131             // go to the begin of the document
132             rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GoToStartOfDoc"));
133             dispatchRequests( mxModel,url );
134             // If something is selected, it needs to go twice
135             dispatchRequests( mxModel,url );
136             break;
137         }
138         case word::WdUnits::wdLine:
139         {
140             // go to the begin of the Line
141             rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GoToStartOfLine"));
142             dispatchRequests( mxModel,url );
143             break;
144         }
145         default:
146         {
147             throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
148             break;
149         }
150     }
151 }
152 
153 void SAL_CALL
154 SwVbaSelection::EndKey( const uno::Any& _unit, const uno::Any& _extend ) throw ( uno::RuntimeException )
155 {
156     sal_Int32 nUnit = word::WdUnits::wdLine;
157     sal_Int32 nExtend = word::WdMovementType::wdMove;
158     _unit >>= nUnit;
159     _extend >>= nExtend;
160 
161     switch( nUnit )
162     {
163         case word::WdUnits::wdStory:
164         {
165             // go to the end of the document
166             rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GoToEndOfDoc"));
167             dispatchRequests( mxModel,url );
168             // If something is selected, it needs to go twice
169             dispatchRequests( mxModel,url );
170             break;
171         }
172         case word::WdUnits::wdLine:
173         {
174             // go to the end of the Line
175             rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GoToEndOfLine"));
176             dispatchRequests( mxModel,url );
177             break;
178         }
179         default:
180         {
181             throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
182             break;
183         }
184     }
185 }
186 
187 void SAL_CALL
188 SwVbaSelection::Delete( const uno::Any& /*_unit*/, const uno::Any& /*_count*/ ) throw ( uno::RuntimeException )
189 {
190     // FIXME: handle the arguments: _unit and _count
191     rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:Delete"));
192     dispatchRequests( mxModel,url );
193 }
194 
195 void SwVbaSelection::NextCell( sal_Int32 nCount, E_DIRECTION eDirection ) throw ( uno::RuntimeException )
196 {
197     uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW );
198     uno::Reference< text::XTextTable > xTextTable;
199     uno::Reference< table::XCell > xCell;
200     xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextTable") ) ) >>= xTextTable;
201     xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Cell") ) ) >>= xCell;
202     if( !xTextTable.is() || !xCell.is() )
203     {
204         DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString());
205         return;
206     }
207     uno::Reference< beans::XPropertySet > xCellProps( xCell, uno::UNO_QUERY_THROW );
208     rtl::OUString aCellName;
209     xCellProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CellName") ) ) >>= aCellName;
210     uno::Reference< text::XTextTableCursor > xTextTableCursor = xTextTable->createCursorByCellName( aCellName );
211     // move the table cursor
212     switch( eDirection )
213     {
214         case MOVE_LEFT:
215         {
216             xTextTableCursor->goLeft( nCount, sal_False );
217             break;
218         }
219         case MOVE_RIGHT:
220         {
221             xTextTableCursor->goRight( nCount, sal_False );
222             break;
223         }
224         case MOVE_UP:
225         {
226             xTextTableCursor->goUp( nCount, sal_False );
227             break;
228         }
229         case MOVE_DOWN:
230         {
231             xTextTableCursor->goDown( nCount, sal_False );
232             break;
233         }
234         default:
235         {
236             DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString());
237             return;
238         }
239     }
240     // move the view cursor
241     xCell = xTextTable->getCellByName( xTextTableCursor->getRangeName() );
242     mxTextViewCursor->gotoRange( uno::Reference< text::XTextRange >( xCell, uno::UNO_QUERY_THROW ), sal_False );
243 }
244 
245 void SAL_CALL
246 SwVbaSelection::MoveRight( const uno::Any& _unit, const uno::Any& _count, const uno::Any& _extend ) throw ( uno::RuntimeException )
247 {
248     sal_Int32 nUnit = word::WdUnits::wdCharacter;
249     sal_Int32 nCount = 1;
250     sal_Int32 nExtend = word::WdMovementType::wdMove;
251 
252     if( _unit.hasValue() )
253         _unit >>= nUnit;
254     if( _count.hasValue() )
255         _count >>= nCount;
256     if( _extend.hasValue() )
257         _extend >>= nExtend;
258 
259     if( nCount == 0 )
260         return;
261 
262     if( nCount < 0 )
263     {
264         // TODO: call MoveLeft;
265         MoveLeft( _unit, uno::makeAny( -nCount ), _extend );
266         return;
267     }
268 
269     switch( nUnit )
270     {
271         case word::WdUnits::wdCell:
272         {
273             if(  nExtend == word::WdMovementType::wdExtend )
274             {
275                 DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString());
276                 return;
277             }
278             NextCell( nCount, MOVE_RIGHT );
279             break;
280         }
281         default:
282         {
283             throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
284             break;
285         }
286     }
287 
288 }
289 
290 void SAL_CALL
291 SwVbaSelection::MoveLeft( const uno::Any& _unit, const uno::Any& _count, const uno::Any& _extend ) throw ( uno::RuntimeException )
292 {
293     sal_Int32 nUnit = word::WdUnits::wdCharacter;
294     sal_Int32 nCount = 1;
295     sal_Int32 nExtend = word::WdMovementType::wdMove;
296 
297     if( _unit.hasValue() )
298         _unit >>= nUnit;
299     if( _count.hasValue() )
300         _count >>= nCount;
301     if( _extend.hasValue() )
302         _extend >>= nExtend;
303 
304     if( nCount == 0 )
305         return;
306 
307     if( nCount < 0 )
308     {
309         MoveRight( _unit, uno::makeAny( -nCount ), _extend );
310         return;
311     }
312 
313     switch( nUnit )
314     {
315         case word::WdUnits::wdCell:
316         {
317             if(  nExtend == word::WdMovementType::wdExtend )
318             {
319                 DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString());
320                 return;
321             }
322             NextCell( nCount, MOVE_LEFT );
323             break;
324         }
325         default:
326         {
327             throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
328             break;
329         }
330     }
331 
332 }
333 
334 void SAL_CALL
335 SwVbaSelection::MoveDown( const uno::Any& _unit, const uno::Any& _count, const uno::Any& _extend ) throw ( uno::RuntimeException )
336 {
337     sal_Int32 nUnit = word::WdUnits::wdCharacter;
338     sal_Int32 nCount = 1;
339     sal_Int32 nExtend = word::WdMovementType::wdMove;
340 
341     if( _unit.hasValue() )
342         _unit >>= nUnit;
343     if( _count.hasValue() )
344         _count >>= nCount;
345     if( _extend.hasValue() )
346         _extend >>= nExtend;
347 
348     if( nCount == 0 )
349         return;
350 
351     if( nCount < 0 )
352     {
353         // TODO: call MoveLeft;
354         //MoveUp( _unit, uno::makeAny( -nCount ), _extend );
355         return;
356     }
357 
358     switch( nUnit )
359     {
360         case word::WdUnits::wdLine:
361         {
362             uno::Reference< view::XViewCursor > xViewCursor( mxTextViewCursor, uno::UNO_QUERY_THROW );
363             sal_Bool bExpand = ( nExtend == word::WdMovementType::wdMove ) ? sal_False : sal_True;
364             xViewCursor->goDown( nCount, bExpand );
365             break;
366         }
367         default:
368         {
369             throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
370             break;
371         }
372     }
373 
374 }
375 
376 void SAL_CALL
377 SwVbaSelection::TypeParagraph() throw ( uno::RuntimeException )
378 {
379     // #FIXME: if the selection is an entire paragraph, it's replaced
380     // by the new paragraph
381     sal_Bool isCollapsed = mxTextViewCursor->isCollapsed();
382     InsertParagraph();
383     if( isCollapsed )
384         mxTextViewCursor->collapseToStart();
385 }
386 
387 void SAL_CALL
388 SwVbaSelection::InsertParagraph() throw ( uno::RuntimeException )
389 {
390     // #FIME: the selection should include the new paragraph.
391     getRange()->InsertParagraph();
392 }
393 
394 void SAL_CALL
395 SwVbaSelection::InsertParagraphBefore() throw ( uno::RuntimeException )
396 {
397     getRange()->InsertParagraphBefore();
398 }
399 
400 void SAL_CALL
401 SwVbaSelection::InsertParagraphAfter() throw ( uno::RuntimeException )
402 {
403     getRange()->InsertParagraphAfter();
404 }
405 
406 uno::Reference< word::XParagraphFormat > SAL_CALL
407 SwVbaSelection::getParagraphFormat() throw ( uno::RuntimeException )
408 {
409     return getRange()->getParagraphFormat();
410 }
411 
412 void SAL_CALL
413 SwVbaSelection::setParagraphFormat( const uno::Reference< word::XParagraphFormat >& rParagraphFormat ) throw ( uno::RuntimeException )
414 {
415     return getRange()->setParagraphFormat( rParagraphFormat );
416 }
417 
418 uno::Reference< word::XFind > SAL_CALL
419 SwVbaSelection::getFind() throw ( uno::RuntimeException )
420 {
421     uno::Reference< text::XTextRange > xTextRange = GetSelectedRange();
422     return uno::Reference< word::XFind >( new SwVbaFind( this, mxContext, mxModel, xTextRange ) );
423 }
424 
425 uno::Reference< word::XStyle > SAL_CALL
426 SwVbaSelection::getStyle() throw ( uno::RuntimeException )
427 {
428     return getRange()->getStyle();
429 }
430 
431 void SAL_CALL
432 SwVbaSelection::setStyle( const uno::Reference< word::XStyle >& rStyle ) throw ( uno::RuntimeException )
433 {
434     return getRange()->setStyle( rStyle );
435 }
436 
437 uno::Reference< word::XFont > SAL_CALL
438 SwVbaSelection::getFont() throw ( uno::RuntimeException )
439 {
440     return getRange()->getFont();
441 }
442 
443 void SAL_CALL
444 SwVbaSelection::TypeBackspace() throw ( uno::RuntimeException )
445 {
446     rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:SwBackspace"));
447     dispatchRequests( mxModel,url );
448 }
449 
450 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)
451 {
452     sal_Int32 nWhat = 0;
453     if( ( _what >>= nWhat ) != sal_True )
454          DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString());
455     switch( nWhat )
456     {
457         case word::WdGoToItem::wdGoToBookmark:
458         {
459             rtl::OUString sName;
460             uno::Reference< word::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
461             uno::Reference< word::XBookmark > xBookmark( xApplication->getActiveDocument()->Bookmarks(_name), uno::UNO_QUERY_THROW );
462             xBookmark->Select();
463             //return uno::Reference< word::XRange >( xBookmark->Range(), uno::UNO_QUERY_THROW );
464             break;
465         }
466         case word::WdGoToItem::wdGoToPage:
467         {
468             uno::Reference< text::XPageCursor > xPageCursor( mxTextViewCursor, uno::UNO_QUERY_THROW );
469             sal_Int32 nCurrPage = xPageCursor->getPage();
470             sal_Int32 nLastPage = word::getPageCount( mxModel );
471             sal_Int32 nCount = 0;
472             if( _count.hasValue() )
473                 _count >>= nCount;
474             sal_Int32 nWhich = 0;
475             if( _which.hasValue() )
476                 _which >>= nWhich;
477              sal_Int32 nPage = 0;
478              switch( nWhich )
479              {
480                 case word::WdGoToDirection::wdGoToLast:
481                 {
482                     nPage = nLastPage;
483                     break;
484                 }
485                 case word::WdGoToDirection::wdGoToNext:
486                 {
487                     nPage = nCurrPage + 1;
488                     break;
489                 }
490                 case word::WdGoToDirection::wdGoToPrevious:
491                 {
492                     nPage = nCurrPage - 1;
493                     break;
494                 }
495                 default:
496                 {
497                     nPage = nCount;
498                 }
499              }
500              if( nPage <= 0 )
501                 nPage = 1;
502              if( nPage > nLastPage )
503                 nPage = nLastPage;
504              xPageCursor->jumpToPage( ( sal_Int16 )( nPage ) );
505              break;
506         }
507         case word::WdGoToItem::wdGoToSection:
508         {
509             // TODO: implement Section object
510         }
511         default:
512             throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
513     }
514     return getRange();
515 }
516 
517 ::sal_Int32 SAL_CALL SwVbaSelection::getLanguageID() throw (uno::RuntimeException)
518 {
519     return getRange()->getLanguageID();
520 }
521 
522 void SAL_CALL SwVbaSelection::setLanguageID( ::sal_Int32 _languageid ) throw (uno::RuntimeException)
523 {
524     getRange()->setLanguageID( _languageid );
525 }
526 
527 uno::Any SAL_CALL SwVbaSelection::Information( sal_Int32 _type ) throw (uno::RuntimeException)
528 {
529     uno::Any result;
530     //uno::Reference< view::XSelectionSupplier > xSel( mxModel->getCurrentController(), uno::UNO_QUERY_THROW );
531     //uno::Any aSelectedObject = xSel->getSelection();
532     switch( _type )
533     {
534         case word::WdInformation::wdActiveEndPageNumber:
535         {
536             result = uno::makeAny( SwVbaInformationHelper::handleWdActiveEndPageNumber( mxTextViewCursor ) );
537             break;
538         }
539         case word::WdInformation::wdNumberOfPagesInDocument:
540         {
541             result = uno::makeAny( SwVbaInformationHelper::handleWdNumberOfPagesInDocument( mxModel ) );
542             break;
543         }
544         case word::WdInformation::wdVerticalPositionRelativeToPage:
545         {
546             result = uno::makeAny( SwVbaInformationHelper::handleWdVerticalPositionRelativeToPage( mxModel, mxTextViewCursor ) );
547             break;
548         }
549         default:
550             throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
551     }
552     // This method fails to restore the previouse selection
553     //xSel->select( aSelectedObject );
554     return result;
555 }
556 
557 void SAL_CALL SwVbaSelection::InsertBreak( const uno::Any& _breakType ) throw (uno::RuntimeException)
558 {
559     getRange()->InsertBreak( _breakType );
560 }
561 
562 uno::Any SAL_CALL
563 SwVbaSelection::Tables( const uno::Any& aIndex ) throw (uno::RuntimeException)
564 {
565     // Hacky implementation due to missing api ( and lack of knowledge )
566     // we can only support a selection that is a single table
567     if ( !aIndex.hasValue() ) // currently we can't support multiple tables in a selection
568        throw uno::RuntimeException();
569     // if the current selection is a XTextTableCursor and the index is 1 then we can service this request, otherwise we just have to throw
570     uno::Reference< text::XTextTableCursor > xTextTableCursor( mxModel->getCurrentSelection(), uno::UNO_QUERY );
571 
572     if ( !xTextTableCursor.is() )
573        throw uno::RuntimeException();
574 
575     sal_Int32 nIndex = 0;
576     aIndex >>= nIndex;
577 
578     uno::Any aRet;
579 
580     if ( nIndex != 1 )
581        throw uno::RuntimeException();
582     SwXTextTableCursor* pTTCursor = dynamic_cast< SwXTextTableCursor* >( xTextTableCursor.get() );
583     if ( pTTCursor )
584     {
585         SwFrmFmt* pFmt = pTTCursor->GetFrmFmt();
586         rtl::OUString sTableName;
587         if ( pFmt )
588         {
589             uno::Reference< text::XTextTable > xTbl = SwXTextTables::GetObject(*pFmt);
590             uno::Reference< css::text::XTextDocument > xTextDoc( mxModel, uno::UNO_QUERY_THROW );
591             uno::Reference< word::XTable > xVBATbl = new SwVbaTable( mxParent, mxContext, xTextDoc, xTbl );
592             aRet <<= xVBATbl;
593         }
594     }
595     return aRet;
596 
597 }
598 
599 uno::Any SAL_CALL
600 SwVbaSelection::Fields( const uno::Any& index ) throw (uno::RuntimeException)
601 {
602     uno::Reference< XCollection > xCol( new SwVbaFields( mxParent, mxContext, mxModel ) );
603     if ( index.hasValue() )
604         return xCol->Item( index, uno::Any() );
605     return uno::makeAny( xCol );
606 }
607 
608 uno::Reference< word::XHeaderFooter > SAL_CALL
609 SwVbaSelection::getHeaderFooter() throw ( uno::RuntimeException )
610 {
611     uno::Reference< text::XText > xCurrentText = word::getXTextViewCursor( mxModel )->getText();
612     if( HeaderFooterHelper::isHeader( mxModel, xCurrentText ) || HeaderFooterHelper::isFooter( mxModel, xCurrentText ) )
613     {
614         uno::Reference< beans::XPropertySet > xPageStyleProps( word::getCurrentPageStyle( mxModel ), uno::UNO_QUERY_THROW );
615         sal_Int32 nIndex = word::WdHeaderFooterIndex::wdHeaderFooterPrimary;
616         sal_Bool isHeader = HeaderFooterHelper::isHeader( mxModel, xCurrentText );
617         if( HeaderFooterHelper::isEvenPagesHeader( mxModel, xCurrentText ) || HeaderFooterHelper::isEvenPagesFooter( mxModel, xCurrentText ) )
618             nIndex = word::WdHeaderFooterIndex::wdHeaderFooterEvenPages;
619         else if( HeaderFooterHelper::isFirstPageHeader( mxModel, xCurrentText ) || HeaderFooterHelper::isFirstPageFooter( mxModel, xCurrentText ) )
620             nIndex = word::WdHeaderFooterIndex::wdHeaderFooterFirstPage;
621 
622         return uno::Reference< word::XHeaderFooter >( new SwVbaHeaderFooter( this, mxContext, mxModel, xPageStyleProps, isHeader, nIndex ) );
623 
624     }
625     return uno::Reference< word::XHeaderFooter >();
626 }
627 
628 uno::Any SAL_CALL
629 SwVbaSelection::ShapeRange( ) throw (uno::RuntimeException)
630 {
631     uno::Reference< drawing::XShapes > xShapes( mxModel->getCurrentSelection(), uno::UNO_QUERY );
632 
633     if ( !xShapes.is() )
634        throw uno::RuntimeException();
635 
636     uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxModel, uno::UNO_QUERY_THROW );
637     uno::Reference< drawing::XDrawPage > xDrawPage = xDrawPageSupplier->getDrawPage();
638     uno::Reference< container::XIndexAccess > xShapesAccess( xShapes, uno::UNO_QUERY_THROW );
639     return uno::makeAny( uno::Reference< msforms::XShapeRange >( new ScVbaShapeRange( this, mxContext, xShapesAccess, xDrawPage, mxModel ) ) );
640 }
641 
642 ::sal_Int32 SAL_CALL SwVbaSelection::getStart() throw (uno::RuntimeException)
643 {
644     return getRange()->getStart();
645 }
646 
647 void SAL_CALL SwVbaSelection::setStart( ::sal_Int32 _start ) throw (uno::RuntimeException)
648 {
649     getRange()->setStart( _start );
650 }
651 ::sal_Int32 SAL_CALL SwVbaSelection::getEnd() throw (uno::RuntimeException)
652 {
653     return getRange()->getEnd();
654 }
655 
656 void SAL_CALL SwVbaSelection::setEnd( ::sal_Int32 _end ) throw (uno::RuntimeException)
657 {
658     getRange()->setEnd( _end );
659 }
660 
661 rtl::OUString&
662 SwVbaSelection::getServiceImplName()
663 {
664 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaSelection") );
665 	return sImplName;
666 }
667 
668 uno::Sequence< rtl::OUString >
669 SwVbaSelection::getServiceNames()
670 {
671 	static uno::Sequence< rtl::OUString > aServiceNames;
672 	if ( aServiceNames.getLength() == 0 )
673 	{
674 		aServiceNames.realloc( 1 );
675 		aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Selection" ) );
676 	}
677 	return aServiceNames;
678 }
679 
680