Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #include "vbarange.hxx"
29 : : #include <vbahelper/vbahelper.hxx>
30 : : #include <tools/diagnose_ex.h>
31 : : #include "vbarangehelper.hxx"
32 : : #include <ooo/vba/word/WdBreakType.hpp>
33 : : #include <com/sun/star/style/BreakType.hpp>
34 : : #include <com/sun/star/text/ControlCharacter.hpp>
35 : : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
36 : : #include <com/sun/star/text/XTextRangeCompare.hpp>
37 : : #include <com/sun/star/text/XWordCursor.hpp>
38 : : #include <com/sun/star/text/XParagraphCursor.hpp>
39 : : #include <ooo/vba/word/WdUnits.hpp>
40 : : #include <ooo/vba/word/WdMovementType.hpp>
41 : : #include "vbaparagraphformat.hxx"
42 : : #include "vbastyle.hxx"
43 : : #include "vbafont.hxx"
44 : : #include "vbapalette.hxx"
45 : : #include "vbapagesetup.hxx"
46 : : #include "vbalistformat.hxx"
47 : : #include "vbarevisions.hxx"
48 : : #include "vbabookmarks.hxx"
49 : : #include "vbasections.hxx"
50 : : #include "vbafield.hxx"
51 : :
52 : : using namespace ::ooo::vba;
53 : : using namespace ::com::sun::star;
54 : :
55 : 0 : SwVbaRange::SwVbaRange( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< text::XTextDocument >& rTextDocument, const uno::Reference< text::XTextRange >& rStart, sal_Bool _bMaySpanEndOfDocument ) throw (uno::RuntimeException) : SwVbaRange_BASE( rParent, rContext ), mxTextDocument( rTextDocument ), mbMaySpanEndOfDocument( _bMaySpanEndOfDocument )
56 : : {
57 : 0 : uno::Reference< text::XTextRange > xEnd;
58 [ # # ]: 0 : initialize( rStart, xEnd );
59 : 0 : }
60 : :
61 : 0 : SwVbaRange::SwVbaRange( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< text::XTextDocument >& rTextDocument, const uno::Reference< text::XTextRange >& rStart, const uno::Reference< text::XTextRange >& rEnd, sal_Bool _bMaySpanEndOfDocument ) throw (uno::RuntimeException) : SwVbaRange_BASE( rParent, rContext ), mxTextDocument( rTextDocument ), mbMaySpanEndOfDocument( _bMaySpanEndOfDocument )
62 : : {
63 [ # # ]: 0 : initialize( rStart, rEnd );
64 : 0 : }
65 : :
66 : 0 : SwVbaRange::SwVbaRange( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< text::XTextDocument >& rTextDocument, const uno::Reference< text::XTextRange >& rStart, const uno::Reference< text::XTextRange >& rEnd, const uno::Reference< text::XText >& rText, sal_Bool _bMaySpanEndOfDocument ) throw (uno::RuntimeException) : SwVbaRange_BASE( rParent, rContext ),mxTextDocument( rTextDocument ), mxText( rText ), mbMaySpanEndOfDocument( _bMaySpanEndOfDocument )
67 : : {
68 [ # # ]: 0 : initialize( rStart, rEnd );
69 : 0 : }
70 : :
71 : 0 : SwVbaRange::~SwVbaRange()
72 : : {
73 [ # # ]: 0 : }
74 : :
75 : 0 : void SwVbaRange::initialize( const uno::Reference< text::XTextRange >& rStart, const uno::Reference< text::XTextRange >& rEnd ) throw (uno::RuntimeException)
76 : : {
77 [ # # ]: 0 : if( !mxText.is() )
78 : : {
79 [ # # ]: 0 : mxText = mxTextDocument->getText();
80 : : }
81 : :
82 [ # # ]: 0 : mxTextCursor = SwVbaRangeHelper::initCursor( rStart, mxText );
83 [ # # ]: 0 : if( !mxTextCursor.is() )
84 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Fails to create text cursor") ), uno::Reference< uno::XInterface >() );
85 : 0 : mxTextCursor->collapseToStart();
86 : :
87 [ # # ]: 0 : if( rEnd.is() )
88 : 0 : mxTextCursor->gotoRange( rEnd, sal_True );
89 : : else
90 : 0 : mxTextCursor->gotoEnd( sal_True );
91 : 0 : }
92 : :
93 : : uno::Reference< text::XTextRange > SAL_CALL
94 : 0 : SwVbaRange::getXTextRange() throw (uno::RuntimeException)
95 : : {
96 : 0 : uno::Reference< text::XTextRange > xTextRange( mxTextCursor, uno::UNO_QUERY_THROW );
97 : 0 : return xTextRange;
98 : : }
99 : :
100 : : /**
101 : : * The complexity in this method is because we need to workaround
102 : : * an issue that the last paragraph in a document does not have a trailing CRLF.
103 : : * @return
104 : : */
105 : : rtl::OUString SAL_CALL
106 : 0 : SwVbaRange::getText() throw ( uno::RuntimeException )
107 : : {
108 : 0 : rtl::OUString aText = mxTextCursor->getString();
109 : 0 : sal_Int32 nLen = aText.getLength();
110 : :
111 : : // FIXME: should add a line separator if the range includes the last paragraph
112 [ # # ]: 0 : if( nLen == 0 )
113 : : {
114 [ # # ][ # # ]: 0 : if( mxTextCursor->isCollapsed() )
[ # # ]
115 : : {
116 [ # # ][ # # ]: 0 : mxTextCursor->goRight( 1, sal_True );
117 [ # # ][ # # ]: 0 : aText = mxTextCursor->getString();
118 [ # # ][ # # ]: 0 : mxTextCursor->collapseToStart();
119 : : }
120 : : else
121 : : {
122 [ # # ][ # # ]: 0 : uno::Reference< text::XTextRange > xStart = mxTextCursor->getStart();
123 [ # # ][ # # ]: 0 : uno::Reference< text::XTextRange > xEnd = mxTextCursor->getEnd();
124 [ # # ][ # # ]: 0 : mxTextCursor->collapseToEnd();
125 [ # # ][ # # ]: 0 : mxTextCursor->goRight( 1, sal_True );
126 [ # # ][ # # ]: 0 : mxTextCursor->gotoRange( xStart, sal_False );
127 [ # # ][ # # ]: 0 : mxTextCursor->gotoRange( xEnd, sal_True );
128 : : }
129 : : }
130 : :
131 : 0 : return aText;
132 : : }
133 : :
134 : : void SAL_CALL
135 : 0 : SwVbaRange::setText( const rtl::OUString& rText ) throw ( uno::RuntimeException )
136 : : {
137 : : // Emulate the MSWord behavior, Don't delete the bookmark
138 : : // which contains no text string in current inserting position,
139 : 0 : rtl::OUString sName;
140 [ # # ]: 0 : uno::Reference< text::XTextRange > xRange( mxTextCursor, uno::UNO_QUERY_THROW );
141 : : try
142 : : {
143 [ # # ][ # # ]: 0 : uno::Reference< text::XTextContent > xBookmark = SwVbaRangeHelper::findBookmarkByPosition( mxTextDocument, xRange->getStart() );
[ # # ]
144 [ # # ]: 0 : if( xBookmark.is() )
145 : : {
146 [ # # ]: 0 : uno::Reference< container::XNamed > xNamed( xBookmark, uno::UNO_QUERY_THROW );
147 [ # # ][ # # ]: 0 : sName = xNamed->getName();
148 [ # # ]: 0 : }
149 : : }
150 [ # # ]: 0 : catch (const uno::Exception&)
151 : : {
152 : : // do nothing
153 : : }
154 : :
155 [ # # ]: 0 : if( rText.indexOf( '\n' ) != -1 )
156 : : {
157 [ # # ][ # # ]: 0 : mxTextCursor->setString( rtl::OUString() );
158 : : // process CR in strings
159 [ # # ]: 0 : SwVbaRangeHelper::insertString( xRange, mxText, rText, sal_True );
160 : : }
161 : : else
162 : : {
163 [ # # ][ # # ]: 0 : mxTextCursor->setString( rText );
164 : : }
165 : :
166 : : // insert the bookmark if the bookmark is deleted during setting text string
167 [ # # ]: 0 : if( !sName.isEmpty() )
168 : : {
169 [ # # ]: 0 : uno::Reference< text::XBookmarksSupplier > xBookmarksSupplier( mxTextDocument, uno::UNO_QUERY_THROW );
170 [ # # ][ # # ]: 0 : uno::Reference< container::XNameAccess > xNameAccess( xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY_THROW );
[ # # ]
171 [ # # ][ # # ]: 0 : if( !xNameAccess->hasByName( sName ) )
[ # # ]
172 : : {
173 [ # # ]: 0 : uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
174 [ # # ][ # # ]: 0 : SwVbaBookmarks::addBookmarkByName( xModel, sName, xRange->getStart() );
[ # # ]
175 : 0 : }
176 : 0 : }
177 : 0 : }
178 : :
179 : : // FIXME: test is not pass
180 : 0 : void SAL_CALL SwVbaRange::InsertBreak( const uno::Any& _breakType ) throw (uno::RuntimeException)
181 : : {
182 : : // default type is wdPageBreak;
183 : 0 : sal_Int32 nBreakType = word::WdBreakType::wdPageBreak;
184 [ # # ]: 0 : if( _breakType.hasValue() )
185 : 0 : _breakType >>= nBreakType;
186 : :
187 : 0 : style::BreakType eBreakType = style::BreakType_NONE;
188 [ # # # # ]: 0 : switch( nBreakType )
189 : : {
190 : : case word::WdBreakType::wdPageBreak:
191 : 0 : eBreakType = style::BreakType_PAGE_BEFORE;
192 : 0 : break;
193 : : case word::WdBreakType::wdColumnBreak:
194 : 0 : eBreakType = style::BreakType_COLUMN_AFTER;
195 : 0 : break;
196 : : case word::WdBreakType::wdLineBreak:
197 : : case word::WdBreakType::wdLineBreakClearLeft:
198 : : case word::WdBreakType::wdLineBreakClearRight:
199 : : case word::WdBreakType::wdSectionBreakContinuous:
200 : : case word::WdBreakType::wdSectionBreakEvenPage:
201 : : case word::WdBreakType::wdSectionBreakNextPage:
202 : : case word::WdBreakType::wdSectionBreakOddPage:
203 : : case word::WdBreakType::wdTextWrappingBreak:
204 [ # # ]: 0 : DebugHelper::exception( SbERR_NOT_IMPLEMENTED, rtl::OUString() );
205 : 0 : break;
206 : : default:
207 [ # # ]: 0 : DebugHelper::exception( SbERR_BAD_PARAMETER, rtl::OUString() );
208 : : }
209 : :
210 [ # # ]: 0 : if( eBreakType != style::BreakType_NONE )
211 : : {
212 [ # # ][ # # ]: 0 : if( !mxTextCursor->isCollapsed() )
[ # # ]
213 : : {
214 [ # # ][ # # ]: 0 : mxTextCursor->setString( rtl::OUString() );
215 [ # # ][ # # ]: 0 : mxTextCursor->collapseToStart();
216 : : }
217 : :
218 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xProp( mxTextCursor, uno::UNO_QUERY_THROW );
219 [ # # ][ # # ]: 0 : xProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BreakType") ), uno::makeAny( eBreakType ) );
[ # # ][ # # ]
220 : : }
221 : 0 : }
222 : :
223 : : void SAL_CALL
224 : 0 : SwVbaRange::Select() throw ( uno::RuntimeException )
225 : : {
226 [ # # ]: 0 : uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
227 [ # # ]: 0 : uno::Reference< text::XTextViewCursor > xTextViewCursor = word::getXTextViewCursor( xModel );
228 [ # # ][ # # ]: 0 : xTextViewCursor->gotoRange( mxTextCursor->getStart(), sal_False );
[ # # ][ # # ]
229 [ # # ][ # # ]: 0 : xTextViewCursor->gotoRange( mxTextCursor->getEnd(), sal_True );
[ # # ][ # # ]
230 : 0 : }
231 : :
232 : : void SAL_CALL
233 : 0 : SwVbaRange::InsertParagraph() throw ( uno::RuntimeException )
234 : : {
235 [ # # ]: 0 : mxTextCursor->setString( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("") ) );
236 : 0 : InsertParagraphBefore();
237 : 0 : }
238 : :
239 : : void SAL_CALL
240 : 0 : SwVbaRange::InsertParagraphBefore() throw ( uno::RuntimeException )
241 : : {
242 [ # # ][ # # ]: 0 : uno::Reference< text::XTextRange > xTextRange = mxTextCursor->getStart();
243 [ # # ][ # # ]: 0 : mxText->insertControlCharacter( xTextRange, text::ControlCharacter::PARAGRAPH_BREAK, sal_True );
244 [ # # ][ # # ]: 0 : mxTextCursor->gotoRange( xTextRange, sal_True );
245 : 0 : }
246 : :
247 : : void SAL_CALL
248 : 0 : SwVbaRange::InsertParagraphAfter() throw ( uno::RuntimeException )
249 : : {
250 [ # # ][ # # ]: 0 : uno::Reference< text::XTextRange > xTextRange = mxTextCursor->getEnd();
251 [ # # ][ # # ]: 0 : mxText->insertControlCharacter( xTextRange, text::ControlCharacter::PARAGRAPH_BREAK, sal_True );
252 : 0 : }
253 : :
254 : : uno::Reference< word::XParagraphFormat > SAL_CALL
255 : 0 : SwVbaRange::getParagraphFormat() throw ( uno::RuntimeException )
256 : : {
257 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xParaProps( mxTextCursor, uno::UNO_QUERY_THROW );
258 [ # # ][ # # ]: 0 : return uno::Reference< word::XParagraphFormat >( new SwVbaParagraphFormat( this, mxContext, mxTextDocument, xParaProps ) );
[ # # ][ # # ]
259 : : }
260 : :
261 : : void SAL_CALL
262 : 0 : SwVbaRange::setParagraphFormat( const uno::Reference< word::XParagraphFormat >& /*rParagraphFormat*/ ) throw ( uno::RuntimeException )
263 : : {
264 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
265 : : }
266 : :
267 : 0 : void SwVbaRange::GetStyleInfo(rtl::OUString& aStyleName, rtl::OUString& aStyleType ) throw ( uno::RuntimeException )
268 : : {
269 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xProp( mxTextCursor, uno::UNO_QUERY_THROW );
270 [ # # ][ # # ]: 0 : if( ( xProp->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CharStyleName") ) ) >>= aStyleName ) && !aStyleName.isEmpty() )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # #
# # # # ]
271 : : {
272 [ # # ]: 0 : aStyleType = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CharacterStyles") );
273 : : }
274 [ # # ][ # # ]: 0 : else if( ( xProp->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaStyleName") ) ) >>= aStyleName ) && !aStyleName.isEmpty() )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # #
# # # # ]
275 : : {
276 [ # # ]: 0 : aStyleType = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParagraphStyles") );
277 : : }
278 [ # # ]: 0 : if( aStyleType.isEmpty() )
279 : : {
280 [ # # ]: 0 : DebugHelper::exception( SbERR_INTERNAL_ERROR, rtl::OUString() );
281 : 0 : }
282 : 0 : }
283 : :
284 : : uno::Any SAL_CALL
285 : 0 : SwVbaRange::getStyle() throw ( uno::RuntimeException )
286 : : {
287 : 0 : rtl::OUString aStyleName;
288 : 0 : rtl::OUString aStyleType;
289 [ # # ]: 0 : GetStyleInfo( aStyleName, aStyleType );
290 [ # # ]: 0 : uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( mxTextDocument, uno::UNO_QUERY_THROW);
291 [ # # ][ # # ]: 0 : uno::Reference< container::XNameAccess > xStylesAccess( xStyleSupplier->getStyleFamilies()->getByName( aStyleType ), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
[ # # ]
292 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xStyleProps( xStylesAccess->getByName( aStyleName ), uno::UNO_QUERY_THROW );
[ # # ]
293 [ # # ]: 0 : uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
294 [ # # ][ # # ]: 0 : return uno::makeAny( uno::Reference< word::XStyle >( new SwVbaStyle( this, mxContext, xModel, xStyleProps ) ) );
[ # # ][ # # ]
[ # # ]
295 : : }
296 : :
297 : : void SAL_CALL
298 : 0 : SwVbaRange::setStyle( const uno::Any& rStyle ) throw ( uno::RuntimeException )
299 : : {
300 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xParaProps( mxTextCursor, uno::UNO_QUERY_THROW );
301 [ # # ]: 0 : SwVbaStyle::setStyle( xParaProps, rStyle );
302 : 0 : }
303 : :
304 : : uno::Reference< word::XFont > SAL_CALL
305 : 0 : SwVbaRange::getFont() throw ( uno::RuntimeException )
306 : : {
307 [ # # ]: 0 : VbaPalette aColors;
308 [ # # ][ # # ]: 0 : return new SwVbaFont( mxParent, mxContext, aColors.getPalette(), uno::Reference< beans::XPropertySet >( getXTextRange(), uno::UNO_QUERY_THROW ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
309 : : }
310 : :
311 : : uno::Reference< word::XListFormat > SAL_CALL
312 : 0 : SwVbaRange::getListFormat() throw ( uno::RuntimeException )
313 : : {
314 [ # # ][ # # ]: 0 : return uno::Reference< word::XListFormat >( new SwVbaListFormat( this, mxContext, getXTextRange() ) );
[ # # ][ # # ]
315 : : }
316 : :
317 : 0 : ::sal_Int32 SAL_CALL SwVbaRange::getLanguageID() throw (uno::RuntimeException)
318 : : {
319 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xParaProps( mxTextCursor, uno::UNO_QUERY_THROW );
320 [ # # ]: 0 : return SwVbaStyle::getLanguageID( xParaProps );
321 : : }
322 : :
323 : 0 : void SAL_CALL SwVbaRange::setLanguageID( ::sal_Int32 _languageid ) throw (uno::RuntimeException)
324 : : {
325 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xParaProps( mxTextCursor, uno::UNO_QUERY_THROW );
326 [ # # ]: 0 : SwVbaStyle::setLanguageID( xParaProps, _languageid );
327 : 0 : }
328 : :
329 : : uno::Any SAL_CALL
330 : 0 : SwVbaRange::PageSetup( ) throw (uno::RuntimeException)
331 : : {
332 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xParaProps( mxTextCursor, uno::UNO_QUERY_THROW );
333 [ # # ]: 0 : uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
334 : 0 : rtl::OUString aPageStyleName;
335 [ # # ][ # # ]: 0 : xParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageStyleName"))) >>= aPageStyleName;
[ # # ]
336 [ # # ]: 0 : uno::Reference< style::XStyleFamiliesSupplier > xSytleFamSupp( xModel, uno::UNO_QUERY_THROW );
337 [ # # ][ # # ]: 0 : uno::Reference< container::XNameAccess > xSytleFamNames( xSytleFamSupp->getStyleFamilies(), uno::UNO_QUERY_THROW );
[ # # ]
338 [ # # ][ # # ]: 0 : uno::Reference< container::XNameAccess > xPageStyles( xSytleFamNames->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageStyles") ) ), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
339 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xPageProps( xPageStyles->getByName( aPageStyleName ), uno::UNO_QUERY_THROW );
[ # # ]
340 [ # # ][ # # ]: 0 : return uno::makeAny( uno::Reference< word::XPageSetup >( new SwVbaPageSetup( this, mxContext, xModel, xPageProps ) ) );
[ # # ][ # # ]
[ # # ]
341 : : }
342 : :
343 : 0 : ::sal_Int32 SAL_CALL SwVbaRange::getStart() throw (uno::RuntimeException)
344 : : {
345 [ # # ][ # # ]: 0 : uno::Reference< text::XText > xText = mxTextDocument->getText();
346 [ # # ][ # # ]: 0 : return SwVbaRangeHelper::getPosition( xText, mxTextCursor->getStart() );
[ # # ]
347 : : }
348 : :
349 : 0 : void SAL_CALL SwVbaRange::setStart( ::sal_Int32 _start ) throw (uno::RuntimeException)
350 : : {
351 [ # # ][ # # ]: 0 : uno::Reference< text::XText > xText = mxTextDocument->getText();
352 [ # # ]: 0 : uno::Reference< text::XTextRange > xStart = SwVbaRangeHelper::getRangeByPosition( xText, _start );
353 [ # # ][ # # ]: 0 : uno::Reference< text::XTextRange > xEnd = mxTextCursor->getEnd();
354 : :
355 [ # # ][ # # ]: 0 : mxTextCursor->gotoRange( xStart, sal_False );
356 [ # # ][ # # ]: 0 : mxTextCursor->gotoRange( xEnd, sal_True );
357 : 0 : }
358 : :
359 : 0 : ::sal_Int32 SAL_CALL SwVbaRange::getEnd() throw (uno::RuntimeException)
360 : : {
361 [ # # ][ # # ]: 0 : uno::Reference< text::XText > xText = mxTextDocument->getText();
362 [ # # ][ # # ]: 0 : return SwVbaRangeHelper::getPosition( xText, mxTextCursor->getEnd() );
[ # # ]
363 : : }
364 : :
365 : 0 : void SAL_CALL SwVbaRange::setEnd( ::sal_Int32 _end ) throw (uno::RuntimeException)
366 : : {
367 [ # # ][ # # ]: 0 : uno::Reference< text::XText > xText = mxTextDocument->getText();
368 [ # # ]: 0 : uno::Reference< text::XTextRange > xEnd = SwVbaRangeHelper::getRangeByPosition( xText, _end );
369 : :
370 [ # # ][ # # ]: 0 : mxTextCursor->collapseToStart();
371 [ # # ][ # # ]: 0 : mxTextCursor->gotoRange( xEnd, sal_True );
372 : 0 : }
373 : :
374 : 0 : ::sal_Bool SAL_CALL SwVbaRange::InRange( const uno::Reference< ::ooo::vba::word::XRange >& Range ) throw (uno::RuntimeException)
375 : : {
376 [ # # ][ # # ]: 0 : SwVbaRange* pRange = dynamic_cast< SwVbaRange* >( Range.get() );
377 [ # # ]: 0 : if( !pRange )
378 [ # # ]: 0 : throw uno::RuntimeException();
379 [ # # ]: 0 : uno::Reference< text::XTextRange > xTextRange = pRange->getXTextRange();
380 [ # # ][ # # ]: 0 : uno::Reference< text::XTextRangeCompare > xTRC( mxTextCursor->getText(), uno::UNO_QUERY_THROW );
[ # # ]
381 [ # # ][ # # ]: 0 : if( xTRC->compareRegionStarts( xTextRange, getXTextRange() ) >= 0 && xTRC->compareRegionEnds( xTextRange, getXTextRange() ) <= 0 )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # #
# # # # ]
[ # # ]
382 : 0 : return sal_True;
383 : 0 : return sal_False;
384 : : }
385 : :
386 : : uno::Any SAL_CALL
387 : 0 : SwVbaRange::Revisions( const uno::Any& index ) throw (uno::RuntimeException)
388 : : {
389 [ # # ]: 0 : uno::Reference< text::XTextRange > xTextRange = getXTextRange();
390 [ # # ]: 0 : uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
391 [ # # ][ # # ]: 0 : uno::Reference< XCollection > xCol( new SwVbaRevisions( mxParent, mxContext, xModel, xTextRange ) );
[ # # ][ # # ]
392 [ # # ]: 0 : if ( index.hasValue() )
393 [ # # ][ # # ]: 0 : return xCol->Item( index, uno::Any() );
394 [ # # ]: 0 : return uno::makeAny( xCol );
395 : : }
396 : :
397 : : uno::Any SAL_CALL
398 : 0 : SwVbaRange::Sections( const uno::Any& index ) throw (uno::RuntimeException)
399 : : {
400 [ # # ]: 0 : uno::Reference< text::XTextRange > xTextRange = getXTextRange();
401 [ # # ]: 0 : uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
402 [ # # ][ # # ]: 0 : uno::Reference< XCollection > xCol( new SwVbaSections( mxParent, mxContext, xModel, xTextRange ) );
[ # # ][ # # ]
403 [ # # ]: 0 : if ( index.hasValue() )
404 [ # # ][ # # ]: 0 : return xCol->Item( index, uno::Any() );
405 [ # # ]: 0 : return uno::makeAny( xCol );
406 : : }
407 : :
408 : : uno::Any SAL_CALL
409 : 0 : SwVbaRange::Fields( const uno::Any& index ) throw (uno::RuntimeException)
410 : : {
411 : : //FIXME: should be get the field in current range
412 [ # # ]: 0 : uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
413 [ # # ][ # # ]: 0 : uno::Reference< XCollection > xCol( new SwVbaFields( mxParent, mxContext, xModel ) );
[ # # ][ # # ]
414 [ # # ]: 0 : if ( index.hasValue() )
415 [ # # ][ # # ]: 0 : return xCol->Item( index, uno::Any() );
416 [ # # ]: 0 : return uno::makeAny( xCol );
417 : : }
418 : :
419 : : rtl::OUString
420 : 0 : SwVbaRange::getServiceImplName()
421 : : {
422 : 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaRange"));
423 : : }
424 : :
425 : : uno::Sequence< rtl::OUString >
426 : 0 : SwVbaRange::getServiceNames()
427 : : {
428 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > aServiceNames;
[ # # ][ # # ]
429 [ # # ]: 0 : if ( aServiceNames.getLength() == 0 )
430 : : {
431 : 0 : aServiceNames.realloc( 1 );
432 [ # # ]: 0 : aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Range" ) );
433 : : }
434 : 0 : return aServiceNames;
435 : : }
436 : :
437 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|