LibreOffice Module sw (master) 1
vbaautotextentry.cxx
Go to the documentation of this file.
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 "vbaautotextentry.hxx"
20#include <utility>
22#include <com/sun/star/text/XParagraphCursor.hpp>
23#include "wordvbahelper.hxx"
24#include "vbarange.hxx"
25
26using namespace ::ooo::vba;
27using namespace ::com::sun::star;
28
29SwVbaAutoTextEntry::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 ))
31{
32}
33
35{
36}
37
38uno::Reference< word::XRange > SAL_CALL SwVbaAutoTextEntry::Insert( const uno::Reference< word::XRange >& _where, const uno::Any& _richtext )
39{
40 SwVbaRange* pWhere = dynamic_cast<SwVbaRange*>( _where.get() );
41 if( pWhere )
42 {
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
53 bool bRich = false;
54 _richtext >>= bRich;
55 if( bRich )
56 {
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() )
60 {
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 );
68 }
69 }
70 xEndMarker->setString( "" ); // remove marker
71 xTC = xText->createTextCursorByRange( xEndMarker->getEnd() );
72 pWhere->setXTextCursor( xTC );
73 }
74 return uno::Reference< word::XRange >( pWhere );
75}
76
77OUString
79{
80 return "SwVbaAutoTextEntry";
81}
82
83uno::Sequence< OUString >
85{
86 static uno::Sequence< OUString > const aServiceNames
87 {
88 "ooo.vba.word.AutoTextEntry"
89 };
90 return aServiceNames;
91}
92
93SwVbaAutoTextEntries::SwVbaAutoTextEntries( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< css::uno::XComponentContext > & xContext, const uno::Reference< container::XIndexAccess >& xIndexAccess ) : SwVbaAutoTextEntries_BASE( xParent, xContext, xIndexAccess )
94{
95}
96
97// XEnumerationAccess
100{
102}
103uno::Reference< container::XEnumeration >
105{
106 throw uno::RuntimeException("Not implemented" );
107}
108
110SwVbaAutoTextEntries::createCollectionObject( const css::uno::Any& aSource )
111{
112 uno::Reference< text::XAutoTextEntry > xEntry( aSource, uno::UNO_QUERY_THROW );
113 return uno::Any( uno::Reference< word::XAutoTextEntry >( new SwVbaAutoTextEntry( this, mxContext, xEntry ) ) );
114}
115
116OUString
118{
119 return "SwVbaAutoTextEntries";
120}
121
122css::uno::Sequence<OUString>
124{
125 static uno::Sequence< OUString > const sNames
126 {
127 "ooo.vba.word.AutoTextEntries"
128 };
129 return sNames;
130}
131
132/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Type SAL_CALL getElementType() override
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual OUString getServiceImplName() override
virtual css::uno::Sequence< OUString > getServiceNames() override
SwVbaAutoTextEntries(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::container::XIndexAccess > &xIndexAccess)
css::uno::Reference< css::text::XAutoTextEntry > mxEntry
virtual css::uno::Reference< ooo::vba::word::XRange > SAL_CALL Insert(const css::uno::Reference< ooo::vba::word::XRange > &_where, const css::uno::Any &_richtext) override
SwVbaAutoTextEntry(const css::uno::Reference< ooo::vba::XHelperInterface > &rParent, const css::uno::Reference< css::uno::XComponentContext > &rContext, css::uno::Reference< css::text::XAutoTextEntry > xEntry)
virtual OUString getServiceImplName() override
virtual ~SwVbaAutoTextEntry() override
virtual css::uno::Sequence< OUString > getServiceNames() override
void setXTextCursor(const css::uno::Reference< css::text::XTextCursor > &xTextCursor)
Definition: vbarange.hxx:61
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getXTextRange() override
Definition: vbarange.cxx:85
const css::uno::Reference< css::text::XText > & getXText() const
Definition: vbarange.hxx:60
css::uno::Type const & get()
Sequence< OUString > aServiceNames
uno::Reference< text::XTextViewCursor > getXTextViewCursor(const uno::Reference< frame::XModel > &xModel)
VBAHELPER_DLLPUBLIC void dispatchRequests(const css::uno::Reference< css::frame::XModel > &xModel, const OUString &aUrl)
VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentWordDoc(const css::uno::Reference< css::uno::XComponentContext > &xContext)
Reference< XModel > xModel