1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #include "vbaautotextentry.hxx"
24 #include <vbahelper/vbahelper.hxx>
25 #include <tools/diagnose_ex.h>
26 #include "vbarange.hxx"
27 
28 using namespace ::ooo::vba;
29 using namespace ::com::sun::star;
30 
SwVbaAutoTextEntry(const uno::Reference<ooo::vba::XHelperInterface> & rParent,const uno::Reference<uno::XComponentContext> & rContext,const uno::Reference<text::XAutoTextEntry> & xEntry)31 SwVbaAutoTextEntry::SwVbaAutoTextEntry( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< text::XAutoTextEntry >& xEntry ) throw ( uno::RuntimeException ) :
32     SwVbaAutoTextEntry_BASE( rParent, rContext ), mxEntry( xEntry )
33 {
34 }
35 
~SwVbaAutoTextEntry()36 SwVbaAutoTextEntry::~SwVbaAutoTextEntry()
37 {
38 }
39 
Insert(const uno::Reference<word::XRange> & _where,const uno::Any &)40 uno::Reference< word::XRange > SAL_CALL SwVbaAutoTextEntry::Insert( const uno::Reference< word::XRange >& _where, const uno::Any& /*_richtext*/ ) throw ( uno::RuntimeException )
41 {
42     SwVbaRange* pWhere = dynamic_cast<SwVbaRange*>( _where.get() );
43     if( pWhere )
44     {
45         uno::Reference< text::XTextRange > xTextRange = pWhere->getXTextRange();
46         xTextRange->setString( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("x") ) ); // set marker
47         uno::Reference< text::XTextRange > xEndMarker = xTextRange->getEnd();
48         xEndMarker->setString( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("x") ) ); // set marker
49         uno::Reference< text::XText > xText = pWhere->getXText();
50         mxEntry->applyTo( xEndMarker->getStart() );
51         uno::Reference< text::XTextCursor > xTC = xText->createTextCursorByRange( xTextRange->getStart() );
52         xTC->goRight( 1, sal_True );
53         xTC->setString( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("") ) ); // remove marker
54         xEndMarker->setString( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("") ) ); // remove marker
55         xTC->gotoRange( xEndMarker, sal_True );
56         pWhere->setXTextCursor( xTC );
57     }
58     return uno::Reference< word::XRange >( pWhere );
59 }
60 
61 rtl::OUString&
getServiceImplName()62 SwVbaAutoTextEntry::getServiceImplName()
63 {
64 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaAutoTextEntry") );
65 	return sImplName;
66 }
67 
68 uno::Sequence< rtl::OUString >
getServiceNames()69 SwVbaAutoTextEntry::getServiceNames()
70 {
71 	static uno::Sequence< rtl::OUString > aServiceNames;
72 	if ( aServiceNames.getLength() == 0 )
73 	{
74 		aServiceNames.realloc( 1 );
75 		aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.AutoTextEntry" ) );
76 	}
77 	return aServiceNames;
78 }
79 
80 
SwVbaAutoTextEntries(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<::com::sun::star::uno::XComponentContext> & xContext,const uno::Reference<container::XIndexAccess> & xIndexAccess)81 SwVbaAutoTextEntries::SwVbaAutoTextEntries( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< ::com::sun::star::uno::XComponentContext > & xContext, const uno::Reference< container::XIndexAccess >& xIndexAccess ) throw (uno::RuntimeException) : SwVbaAutoTextEntries_BASE( xParent, xContext, xIndexAccess ), mxAutoTextEntryAccess( xIndexAccess )
82 {
83 }
84 
85 // XEnumerationAccess
86 uno::Type
getElementType()87 SwVbaAutoTextEntries::getElementType() throw (uno::RuntimeException)
88 {
89 	return word::XAutoTextEntry::static_type(0);
90 }
91 uno::Reference< container::XEnumeration >
createEnumeration()92 SwVbaAutoTextEntries::createEnumeration() throw (uno::RuntimeException)
93 {
94     uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
95     return xEnumerationAccess->createEnumeration();
96 }
97 
98 uno::Any
createCollectionObject(const css::uno::Any & aSource)99 SwVbaAutoTextEntries::createCollectionObject( const css::uno::Any& aSource )
100 {
101     uno::Reference< text::XAutoTextEntry > xEntry( aSource, uno::UNO_QUERY_THROW );
102     return uno::makeAny( uno::Reference< word::XAutoTextEntry >( new SwVbaAutoTextEntry( this, mxContext, xEntry ) ) );
103 }
104 
105 rtl::OUString&
getServiceImplName()106 SwVbaAutoTextEntries::getServiceImplName()
107 {
108 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaAutoTextEntries") );
109 	return sImplName;
110 }
111 
112 css::uno::Sequence<rtl::OUString>
getServiceNames()113 SwVbaAutoTextEntries::getServiceNames()
114 {
115 	static uno::Sequence< rtl::OUString > sNames;
116 	if ( sNames.getLength() == 0 )
117 	{
118 		sNames.realloc( 1 );
119 		sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.AutoTextEntries") );
120 	}
121 	return sNames;
122 }
123