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 <tools/diagnose_ex.h>
23 #include "wordvbahelper.hxx"
24 #include "vbarange.hxx"
25 
26 using namespace ::ooo::vba;
27 using namespace ::com::sun::star;
28 
29 SwVbaAutoTextEntry::SwVbaAutoTextEntry( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< text::XAutoTextEntry >& xEntry ) :
30  SwVbaAutoTextEntry_BASE( rParent, rContext ), mxEntry( xEntry )
31 {
32 }
33 
35 {
36 }
37 
38 uno::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  OUString url = ".uno:Delete";
67  dispatchRequests( xModel,url );
68  xTVCursor->gotoRange( xEndMarker->getEnd(), false );
69  }
70  }
71  xEndMarker->setString( "" ); // remove marker
72  xTC = xText->createTextCursorByRange( xEndMarker->getEnd() );
73  pWhere->setXTextCursor( xTC );
74  }
75  return uno::Reference< word::XRange >( pWhere );
76 }
77 
78 OUString
80 {
81  return "SwVbaAutoTextEntry";
82 }
83 
84 uno::Sequence< OUString >
86 {
87  static uno::Sequence< OUString > const aServiceNames
88  {
89  "ooo.vba.word.AutoTextEntry"
90  };
91  return aServiceNames;
92 }
93 
94 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 )
95 {
96 }
97 
98 // XEnumerationAccess
101 {
103 }
104 uno::Reference< container::XEnumeration >
106 {
107  throw uno::RuntimeException("Not implemented" );
108 }
109 
110 uno::Any
111 SwVbaAutoTextEntries::createCollectionObject( const css::uno::Any& aSource )
112 {
113  uno::Reference< text::XAutoTextEntry > xEntry( aSource, uno::UNO_QUERY_THROW );
114  return uno::makeAny( uno::Reference< word::XAutoTextEntry >( new SwVbaAutoTextEntry( this, mxContext, xEntry ) ) );
115 }
116 
117 OUString
119 {
120  return "SwVbaAutoTextEntries";
121 }
122 
123 css::uno::Sequence<OUString>
125 {
126  static uno::Sequence< OUString > const sNames
127  {
128  "ooo.vba.word.AutoTextEntries"
129  };
130  return sNames;
131 }
132 
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual OUString getServiceImplName() override
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:89
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)