1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #include "vbaautotextentry.hxx" 28 #include <vbahelper/vbahelper.hxx> 29 #include <tools/diagnose_ex.h> 30 #include "vbarange.hxx" 31 32 using namespace ::ooo::vba; 33 using namespace ::com::sun::star; 34 35 SwVbaAutoTextEntry::SwVbaAutoTextEntry( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< text::XAutoTextEntry >& xEntry ) throw ( uno::RuntimeException ) : 36 SwVbaAutoTextEntry_BASE( rParent, rContext ), mxEntry( xEntry ) 37 { 38 } 39 40 SwVbaAutoTextEntry::~SwVbaAutoTextEntry() 41 { 42 } 43 44 uno::Reference< word::XRange > SAL_CALL SwVbaAutoTextEntry::Insert( const uno::Reference< word::XRange >& _where, const uno::Any& /*_richtext*/ ) throw ( uno::RuntimeException ) 45 { 46 SwVbaRange* pWhere = dynamic_cast<SwVbaRange*>( _where.get() ); 47 if( pWhere ) 48 { 49 uno::Reference< text::XTextRange > xTextRange = pWhere->getXTextRange(); 50 xTextRange->setString( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("x") ) ); // set marker 51 uno::Reference< text::XTextRange > xEndMarker = xTextRange->getEnd(); 52 xEndMarker->setString( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("x") ) ); // set marker 53 uno::Reference< text::XText > xText = pWhere->getXText(); 54 mxEntry->applyTo( xEndMarker->getStart() ); 55 uno::Reference< text::XTextCursor > xTC = xText->createTextCursorByRange( xTextRange->getStart() ); 56 xTC->goRight( 1, sal_True ); 57 xTC->setString( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("") ) ); // remove marker 58 xEndMarker->setString( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("") ) ); // remove marker 59 xTC->gotoRange( xEndMarker, sal_True ); 60 pWhere->setXTextCursor( xTC ); 61 } 62 return uno::Reference< word::XRange >( pWhere ); 63 } 64 65 rtl::OUString& 66 SwVbaAutoTextEntry::getServiceImplName() 67 { 68 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaAutoTextEntry") ); 69 return sImplName; 70 } 71 72 uno::Sequence< rtl::OUString > 73 SwVbaAutoTextEntry::getServiceNames() 74 { 75 static uno::Sequence< rtl::OUString > aServiceNames; 76 if ( aServiceNames.getLength() == 0 ) 77 { 78 aServiceNames.realloc( 1 ); 79 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.AutoTextEntry" ) ); 80 } 81 return aServiceNames; 82 } 83 84 85 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 ) 86 { 87 } 88 89 // XEnumerationAccess 90 uno::Type 91 SwVbaAutoTextEntries::getElementType() throw (uno::RuntimeException) 92 { 93 return word::XAutoTextEntry::static_type(0); 94 } 95 uno::Reference< container::XEnumeration > 96 SwVbaAutoTextEntries::createEnumeration() throw (uno::RuntimeException) 97 { 98 uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW ); 99 return xEnumerationAccess->createEnumeration(); 100 } 101 102 uno::Any 103 SwVbaAutoTextEntries::createCollectionObject( const css::uno::Any& aSource ) 104 { 105 uno::Reference< text::XAutoTextEntry > xEntry( aSource, uno::UNO_QUERY_THROW ); 106 return uno::makeAny( uno::Reference< word::XAutoTextEntry >( new SwVbaAutoTextEntry( this, mxContext, xEntry ) ) ); 107 } 108 109 rtl::OUString& 110 SwVbaAutoTextEntries::getServiceImplName() 111 { 112 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaAutoTextEntries") ); 113 return sImplName; 114 } 115 116 css::uno::Sequence<rtl::OUString> 117 SwVbaAutoTextEntries::getServiceNames() 118 { 119 static uno::Sequence< rtl::OUString > sNames; 120 if ( sNames.getLength() == 0 ) 121 { 122 sNames.realloc( 1 ); 123 sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.AutoTextEntries") ); 124 } 125 return sNames; 126 } 127