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