merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / vba / vbaautotextentry.cxx
blob30bdc2a5a334a9b6abf82dd595a1af700c24b0ae
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile:
10 * $Revision:
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "vbaautotextentry.hxx"
31 #include <vbahelper/vbahelper.hxx>
32 #include <tools/diagnose_ex.h>
33 #include "vbarange.hxx"
35 using namespace ::ooo::vba;
36 using namespace ::com::sun::star;
38 SwVbaAutoTextEntry::SwVbaAutoTextEntry( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< text::XAutoTextEntry >& xEntry ) throw ( uno::RuntimeException ) :
39 SwVbaAutoTextEntry_BASE( rParent, rContext ), mxEntry( xEntry )
43 SwVbaAutoTextEntry::~SwVbaAutoTextEntry()
47 uno::Reference< word::XRange > SAL_CALL SwVbaAutoTextEntry::Insert( const uno::Reference< word::XRange >& _where, const uno::Any& /*_richtext*/ ) throw ( uno::RuntimeException )
49 SwVbaRange* pWhere = dynamic_cast<SwVbaRange*>( _where.get() );
50 if( pWhere )
52 uno::Reference< text::XTextRange > xTextRange = pWhere->getXTextRange();
53 xTextRange->setString( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("x") ) ); // set marker
54 uno::Reference< text::XTextRange > xEndMarker = xTextRange->getEnd();
55 xEndMarker->setString( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("x") ) ); // set marker
56 uno::Reference< text::XText > xText = pWhere->getXText();
57 mxEntry->applyTo( xEndMarker->getStart() );
58 uno::Reference< text::XTextCursor > xTC = xText->createTextCursorByRange( xTextRange->getStart() );
59 xTC->goRight( 1, sal_True );
60 xTC->setString( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("") ) ); // remove marker
61 xEndMarker->setString( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("") ) ); // remove marker
62 xTC->gotoRange( xEndMarker, sal_True );
63 pWhere->setXTextCursor( xTC );
65 return uno::Reference< word::XRange >( pWhere );
68 rtl::OUString&
69 SwVbaAutoTextEntry::getServiceImplName()
71 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaAutoTextEntry") );
72 return sImplName;
75 uno::Sequence< rtl::OUString >
76 SwVbaAutoTextEntry::getServiceNames()
78 static uno::Sequence< rtl::OUString > aServiceNames;
79 if ( aServiceNames.getLength() == 0 )
81 aServiceNames.realloc( 1 );
82 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.AutoTextEntry" ) );
84 return aServiceNames;
88 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 )
92 // XEnumerationAccess
93 uno::Type
94 SwVbaAutoTextEntries::getElementType() throw (uno::RuntimeException)
96 return word::XAutoTextEntry::static_type(0);
98 uno::Reference< container::XEnumeration >
99 SwVbaAutoTextEntries::createEnumeration() throw (uno::RuntimeException)
101 uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
102 return xEnumerationAccess->createEnumeration();
105 uno::Any
106 SwVbaAutoTextEntries::createCollectionObject( const css::uno::Any& aSource )
108 uno::Reference< text::XAutoTextEntry > xEntry( aSource, uno::UNO_QUERY_THROW );
109 return uno::makeAny( uno::Reference< word::XAutoTextEntry >( new SwVbaAutoTextEntry( this, mxContext, xEntry ) ) );
112 rtl::OUString&
113 SwVbaAutoTextEntries::getServiceImplName()
115 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaAutoTextEntries") );
116 return sImplName;
119 css::uno::Sequence<rtl::OUString>
120 SwVbaAutoTextEntries::getServiceNames()
122 static uno::Sequence< rtl::OUString > sNames;
123 if ( sNames.getLength() == 0 )
125 sNames.realloc( 1 );
126 sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.AutoTextEntries") );
128 return sNames;