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 <vbahelper/vbahelper.hxx>
21 #include <com/sun/star/text/XParagraphCursor.hpp>
22 #include "wordvbahelper.hxx"
23 #include "vbarange.hxx"
24 
25 using namespace ::ooo::vba;
26 using namespace ::com::sun::star;
27 
28 SwVbaAutoTextEntry::SwVbaAutoTextEntry( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< text::XAutoTextEntry >& xEntry ) :
29  SwVbaAutoTextEntry_BASE( rParent, rContext ), mxEntry( xEntry )
30 {
31 }
32 
34 {
35 }
36 
37 uno::Reference< word::XRange > SAL_CALL SwVbaAutoTextEntry::Insert( const uno::Reference< word::XRange >& _where, const uno::Any& _richtext )
38 {
39  SwVbaRange* pWhere = dynamic_cast<SwVbaRange*>( _where.get() );
40  if( pWhere )
41  {
42  uno::Reference< text::XTextRange > xTextRange = pWhere->getXTextRange();
43  xTextRange->setString( "x" ); // set marker
44  uno::Reference< text::XTextRange > xEndMarker = xTextRange->getEnd();
45  xEndMarker->setString( "x" ); // set marker
46  uno::Reference< text::XText > xText = pWhere->getXText();
47  mxEntry->applyTo( xEndMarker->getStart() );
48  uno::Reference< text::XTextCursor > xTC = xText->createTextCursorByRange( xTextRange->getStart() );
49  xTC->goRight( 1, true );
50  xTC->setString( "" ); // remove marker
51  // remove the blank paragraph if it is a rich text
52  bool bRich = false;
53  _richtext >>= bRich;
54  if( bRich )
55  {
56  // check if it is a blank paragraph
57  uno::Reference< text::XParagraphCursor > xParaCursor( xTC, uno::UNO_QUERY_THROW );
58  if( xParaCursor->isStartOfParagraph() && xParaCursor->isEndOfParagraph() )
59  {
60  //remove the blank paragraph
61  uno::Reference< frame::XModel > xModel( getCurrentWordDoc( mxContext ), uno::UNO_SET_THROW );
62  uno::Reference< text::XTextViewCursor > xTVCursor = word::getXTextViewCursor( xModel );
63  uno::Reference< text::XTextRange > xCurrentRange( xTC->getEnd(), uno::UNO_SET_THROW );
64  xTVCursor->gotoRange( xCurrentRange, false );
65  dispatchRequests( xModel,".uno:Delete" );
66  xTVCursor->gotoRange( xEndMarker->getEnd(), false );
67  }
68  }
69  xEndMarker->setString( "" ); // remove marker
70  xTC = xText->createTextCursorByRange( xEndMarker->getEnd() );
71  pWhere->setXTextCursor( xTC );
72  }
73  return uno::Reference< word::XRange >( pWhere );
74 }
75 
76 OUString
78 {
79  return "SwVbaAutoTextEntry";
80 }
81 
82 uno::Sequence< OUString >
84 {
85  static uno::Sequence< OUString > const aServiceNames
86  {
87  "ooo.vba.word.AutoTextEntry"
88  };
89  return aServiceNames;
90 }
91 
92 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 )
93 {
94 }
95 
96 // XEnumerationAccess
99 {
101 }
102 uno::Reference< container::XEnumeration >
104 {
105  throw uno::RuntimeException("Not implemented" );
106 }
107 
108 uno::Any
109 SwVbaAutoTextEntries::createCollectionObject( const css::uno::Any& aSource )
110 {
111  uno::Reference< text::XAutoTextEntry > xEntry( aSource, uno::UNO_QUERY_THROW );
112  return uno::makeAny( uno::Reference< word::XAutoTextEntry >( new SwVbaAutoTextEntry( this, mxContext, xEntry ) ) );
113 }
114 
115 OUString
117 {
118  return "SwVbaAutoTextEntries";
119 }
120 
121 css::uno::Sequence<OUString>
123 {
124  static uno::Sequence< OUString > const sNames
125  {
126  "ooo.vba.word.AutoTextEntries"
127  };
128  return sNames;
129 }
130 
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual OUString getServiceImplName() override
Sequence< OUString > aServiceNames
const css::uno::Reference< css::text::XText > & getXText() const
Definition: vbarange.hxx:59
virtual OUString getServiceImplName() override
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getXTextRange() override
Definition: vbarange.cxx:83
uno::Reference< text::XTextViewCursor > getXTextViewCursor(const uno::Reference< frame::XModel > &xModel)
virtual ~SwVbaAutoTextEntry() override
void setXTextCursor(const css::uno::Reference< css::text::XTextCursor > &xTextCursor)
Definition: vbarange.hxx:60
uno::Reference< frame::XModel > getCurrentWordDoc(const uno::Reference< uno::XComponentContext > &xContext)
css::uno::Reference< css::text::XAutoTextEntry > mxEntry
css::uno::Type const & get()
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Type SAL_CALL getElementType() 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)
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
Reference< XModel > xModel
SwVbaAutoTextEntry(const css::uno::Reference< ooo::vba::XHelperInterface > &rParent, const css::uno::Reference< css::uno::XComponentContext > &rContext, const css::uno::Reference< css::text::XAutoTextEntry > &xEntry)
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
void dispatchRequests(const uno::Reference< frame::XModel > &xModel, const OUString &aUrl, const uno::Sequence< beans::PropertyValue > &sProps)