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 "vbabookmark.hxx"
20 : #include <vbahelper/vbahelper.hxx>
21 : #include <tools/diagnose_ex.h>
22 : #include <com/sun/star/text/XTextDocument.hpp>
23 : #include <com/sun/star/text/XTextContent.hpp>
24 : #include <com/sun/star/text/XTextRange.hpp>
25 : #include <com/sun/star/text/XTextViewCursor.hpp>
26 : #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
27 : #include <com/sun/star/view/XSelectionSupplier.hpp>
28 : #include "vbarange.hxx"
29 : #include "wordvbahelper.hxx"
30 :
31 : using namespace ::ooo::vba;
32 : using namespace ::com::sun::star;
33 :
34 0 : SwVbaBookmark::SwVbaBookmark( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext,
35 : const css::uno::Reference< frame::XModel >& rModel, const rtl::OUString& rName ) throw ( css::uno::RuntimeException ) :
36 0 : SwVbaBookmark_BASE( rParent, rContext ), mxModel( rModel ), maName( rName ), mbValid( sal_True )
37 : {
38 0 : uno::Reference< text::XBookmarksSupplier > xBookmarksSupplier( mxModel, uno::UNO_QUERY_THROW );
39 0 : mxBookmark.set( xBookmarksSupplier->getBookmarks()->getByName( maName ), uno::UNO_QUERY_THROW );
40 0 : }
41 :
42 0 : SwVbaBookmark::~SwVbaBookmark()
43 : {
44 0 : }
45 :
46 0 : void SwVbaBookmark::checkVality() throw ( uno::RuntimeException )
47 : {
48 0 : if( !mbValid )
49 0 : throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("The bookmark is not valid" ) ), uno::Reference< uno::XInterface >() );
50 0 : }
51 :
52 0 : void SAL_CALL SwVbaBookmark::Delete() throw ( uno::RuntimeException )
53 : {
54 0 : checkVality();
55 0 : uno::Reference< text::XTextDocument > xTextDocument( mxModel, uno::UNO_QUERY_THROW );
56 0 : xTextDocument->getText()->removeTextContent( mxBookmark );
57 0 : mbValid = sal_False;
58 0 : }
59 :
60 0 : void SAL_CALL SwVbaBookmark::Select() throw ( uno::RuntimeException )
61 : {
62 0 : checkVality();
63 0 : uno::Reference< view::XSelectionSupplier > xSelectSupp( mxModel->getCurrentController(), uno::UNO_QUERY_THROW );
64 0 : xSelectSupp->select( uno::makeAny( mxBookmark ) );
65 0 : }
66 :
67 0 : rtl::OUString SAL_CALL SwVbaBookmark::getName() throw ( uno::RuntimeException )
68 : {
69 0 : return maName;
70 : }
71 :
72 0 : void SAL_CALL SwVbaBookmark::setName( const rtl::OUString& _name ) throw ( uno::RuntimeException )
73 : {
74 0 : uno::Reference< container::XNamed > xNamed( mxBookmark, uno::UNO_QUERY_THROW );
75 0 : xNamed->setName( _name );
76 0 : }
77 :
78 0 : uno::Any SAL_CALL SwVbaBookmark::Range() throw ( uno::RuntimeException )
79 : {
80 0 : uno::Reference< text::XTextContent > xTextContent( mxBookmark, uno::UNO_QUERY_THROW );
81 0 : uno::Reference< text::XTextDocument > xTextDocument( mxModel, uno::UNO_QUERY_THROW );
82 0 : uno::Reference< text::XTextRange > xTextRange( xTextContent->getAnchor(), uno::UNO_QUERY_THROW );
83 0 : return uno::makeAny( uno::Reference< word::XRange>( new SwVbaRange( this, mxContext, xTextDocument, xTextRange->getStart(), xTextRange->getEnd(), xTextRange->getText() ) ) );
84 : }
85 :
86 : rtl::OUString
87 0 : SwVbaBookmark::getServiceImplName()
88 : {
89 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaBookmark"));
90 : }
91 :
92 : uno::Sequence< rtl::OUString >
93 0 : SwVbaBookmark::getServiceNames()
94 : {
95 0 : static uno::Sequence< rtl::OUString > aServiceNames;
96 0 : if ( aServiceNames.getLength() == 0 )
97 : {
98 0 : aServiceNames.realloc( 1 );
99 0 : aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Bookmark" ) );
100 : }
101 0 : return aServiceNames;
102 : }
103 :
104 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|