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  OUString url = ".uno:Delete";
66  dispatchRequests( xModel,url );
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 
77 OUString
79 {
80  return "SwVbaAutoTextEntry";
81 }
82 
83 uno::Sequence< OUString >
85 {
86  static uno::Sequence< OUString > const aServiceNames
87  {
88  "ooo.vba.word.AutoTextEntry"
89  };
90  return aServiceNames;
91 }
92 
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 )
94 {
95 }
96 
97 // XEnumerationAccess
100 {
102 }
103 uno::Reference< container::XEnumeration >
105 {
106  throw uno::RuntimeException("Not implemented" );
107 }
108 
109 uno::Any
110 SwVbaAutoTextEntries::createCollectionObject( const css::uno::Any& aSource )
111 {
112  uno::Reference< text::XAutoTextEntry > xEntry( aSource, uno::UNO_QUERY_THROW );
113  return uno::makeAny( uno::Reference< word::XAutoTextEntry >( new SwVbaAutoTextEntry( this, mxContext, xEntry ) ) );
114 }
115 
116 OUString
118 {
119  return "SwVbaAutoTextEntries";
120 }
121 
122 css::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: */
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)