1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "vbabookmark.hxx"
31 #include <vbahelper/vbahelper.hxx>
32 #include <tools/diagnose_ex.h>
33 #include <com/sun/star/text/XTextDocument.hpp>
34 #include <com/sun/star/text/XTextContent.hpp>
35 #include <com/sun/star/text/XTextViewCursor.hpp>
36 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
37 #include "vbarange.hxx"
39 using namespace ::ooo::vba
;
40 using namespace ::com::sun::star
;
42 SwVbaBookmark::SwVbaBookmark( const uno::Reference
< ooo::vba::XHelperInterface
>& rParent
, const uno::Reference
< uno::XComponentContext
>& rContext
,
43 const css::uno::Reference
< frame::XModel
>& rModel
, const rtl::OUString
& rName
) throw ( css::uno::RuntimeException
) :
44 SwVbaBookmark_BASE( rParent
, rContext
), mxModel( rModel
), maName( rName
), mbValid( sal_True
)
46 uno::Reference
< text::XBookmarksSupplier
> xBookmarksSupplier( mxModel
, uno::UNO_QUERY_THROW
);
47 mxBookmark
.set( xBookmarksSupplier
->getBookmarks()->getByName( maName
), uno::UNO_QUERY_THROW
);
50 SwVbaBookmark::~SwVbaBookmark()
54 void SwVbaBookmark::checkVality() throw ( uno::RuntimeException
)
57 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("The bookmark is not valid" ) ), uno::Reference
< uno::XInterface
>() );
60 void SAL_CALL
SwVbaBookmark::Delete() throw ( uno::RuntimeException
)
63 uno::Reference
< text::XTextDocument
> xTextDocument( mxModel
, uno::UNO_QUERY_THROW
);
64 xTextDocument
->getText()->removeTextContent( mxBookmark
);
68 void SAL_CALL
SwVbaBookmark::Select() throw ( uno::RuntimeException
)
71 uno::Reference
< text::XTextViewCursorSupplier
> xViewCursorSupplier( mxModel
->getCurrentController(), uno::UNO_QUERY_THROW
);
72 xViewCursorSupplier
->getViewCursor()->gotoRange( mxBookmark
->getAnchor(),sal_False
);
75 rtl::OUString SAL_CALL
SwVbaBookmark::getName() throw ( uno::RuntimeException
)
80 void SAL_CALL
SwVbaBookmark::setName( const rtl::OUString
& _name
) throw ( uno::RuntimeException
)
82 uno::Reference
< container::XNamed
> xNamed( mxBookmark
, uno::UNO_QUERY_THROW
);
83 xNamed
->setName( _name
);
86 uno::Any SAL_CALL
SwVbaBookmark::Range() throw ( uno::RuntimeException
)
88 uno::Reference
< text::XTextContent
> xTextContent( mxBookmark
, uno::UNO_QUERY_THROW
);
89 uno::Reference
< text::XTextDocument
> xTextDocument( mxModel
, uno::UNO_QUERY_THROW
);
90 uno::Reference
< text::XTextRange
> xTextRange( xTextContent
->getAnchor(), uno::UNO_QUERY_THROW
);
91 return uno::makeAny( uno::Reference
< word::XRange
>( new SwVbaRange( this, mxContext
, xTextDocument
, xTextRange
->getStart(), xTextRange
->getEnd(), xTextRange
->getText() ) ) );
95 SwVbaBookmark::getServiceImplName()
97 static rtl::OUString
sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaBookmark") );
101 uno::Sequence
< rtl::OUString
>
102 SwVbaBookmark::getServiceNames()
104 static uno::Sequence
< rtl::OUString
> aServiceNames
;
105 if ( aServiceNames
.getLength() == 0 )
107 aServiceNames
.realloc( 1 );
108 aServiceNames
[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Bookmark" ) );
110 return aServiceNames
;