1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include "vbaautotextentry.hxx"
21 #include <vbahelper/vbahelper.hxx>
22 #include <com/sun/star/text/XParagraphCursor.hpp>
23 #include "wordvbahelper.hxx"
24 #include "vbarange.hxx"
26 using namespace ::ooo::vba
;
27 using namespace ::com::sun::star
;
29 SwVbaAutoTextEntry::SwVbaAutoTextEntry( const uno::Reference
< ooo::vba::XHelperInterface
>& rParent
, const uno::Reference
< uno::XComponentContext
>& rContext
, uno::Reference
< text::XAutoTextEntry
> xEntry
) :
30 SwVbaAutoTextEntry_BASE( rParent
, rContext
), mxEntry(std::move( xEntry
))
34 SwVbaAutoTextEntry::~SwVbaAutoTextEntry()
38 uno::Reference
< word::XRange
> SAL_CALL
SwVbaAutoTextEntry::Insert( const uno::Reference
< word::XRange
>& _where
, const uno::Any
& _richtext
)
40 SwVbaRange
* pWhere
= dynamic_cast<SwVbaRange
*>( _where
.get() );
43 uno::Reference
< text::XTextRange
> xTextRange
= pWhere
->getXTextRange();
44 xTextRange
->setString( "x" ); // set marker
45 uno::Reference
< text::XTextRange
> xEndMarker
= xTextRange
->getEnd();
46 xEndMarker
->setString( "x" ); // set marker
47 uno::Reference
< text::XText
> xText
= pWhere
->getXText();
48 mxEntry
->applyTo( xEndMarker
->getStart() );
49 uno::Reference
< text::XTextCursor
> xTC
= xText
->createTextCursorByRange( xTextRange
->getStart() );
50 xTC
->goRight( 1, true );
51 xTC
->setString( "" ); // remove marker
52 // remove the blank paragraph if it is a rich text
57 // check if it is a blank paragraph
58 uno::Reference
< text::XParagraphCursor
> xParaCursor( xTC
, uno::UNO_QUERY_THROW
);
59 if( xParaCursor
->isStartOfParagraph() && xParaCursor
->isEndOfParagraph() )
61 //remove the blank paragraph
62 uno::Reference
< frame::XModel
> xModel( getCurrentWordDoc( mxContext
), uno::UNO_SET_THROW
);
63 uno::Reference
< text::XTextViewCursor
> xTVCursor
= word::getXTextViewCursor( xModel
);
64 uno::Reference
< text::XTextRange
> xCurrentRange( xTC
->getEnd(), uno::UNO_SET_THROW
);
65 xTVCursor
->gotoRange( xCurrentRange
, false );
66 dispatchRequests( xModel
,".uno:Delete" );
67 xTVCursor
->gotoRange( xEndMarker
->getEnd(), false );
70 xEndMarker
->setString( "" ); // remove marker
71 xTC
= xText
->createTextCursorByRange( xEndMarker
->getEnd() );
72 pWhere
->setXTextCursor( xTC
);
74 return uno::Reference
< word::XRange
>( pWhere
);
78 SwVbaAutoTextEntry::getServiceImplName()
80 return "SwVbaAutoTextEntry";
83 uno::Sequence
< OUString
>
84 SwVbaAutoTextEntry::getServiceNames()
86 static uno::Sequence
< OUString
> const aServiceNames
88 "ooo.vba.word.AutoTextEntry"
93 SwVbaAutoTextEntries::SwVbaAutoTextEntries( const uno::Reference
< XHelperInterface
>& xParent
, const uno::Reference
< css::uno::XComponentContext
> & xContext
, const uno::Reference
< container::XIndexAccess
>& xIndexAccess
) : SwVbaAutoTextEntries_BASE( xParent
, xContext
, xIndexAccess
)
99 SwVbaAutoTextEntries::getElementType()
101 return cppu::UnoType
<word::XAutoTextEntry
>::get();
103 uno::Reference
< container::XEnumeration
>
104 SwVbaAutoTextEntries::createEnumeration()
106 throw uno::RuntimeException("Not implemented" );
110 SwVbaAutoTextEntries::createCollectionObject( const css::uno::Any
& aSource
)
112 uno::Reference
< text::XAutoTextEntry
> xEntry( aSource
, uno::UNO_QUERY_THROW
);
113 return uno::Any( uno::Reference
< word::XAutoTextEntry
>( new SwVbaAutoTextEntry( this, mxContext
, xEntry
) ) );
117 SwVbaAutoTextEntries::getServiceImplName()
119 return "SwVbaAutoTextEntries";
122 css::uno::Sequence
<OUString
>
123 SwVbaAutoTextEntries::getServiceNames()
125 static uno::Sequence
< OUString
> const sNames
127 "ooo.vba.word.AutoTextEntries"
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */