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 "vbacharacters.hxx" 28 29 #include "vbaglobals.hxx" 30 #include "vbafont.hxx" 31 32 33 using namespace ::ooo::vba; 34 using namespace ::com::sun::star; 35 36 ScVbaCharacters::ScVbaCharacters( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const ScVbaPalette& dPalette, const uno::Reference< text::XSimpleText>& xRange,const css::uno::Any& Start, const css::uno::Any& Length, sal_Bool Replace ) throw ( css::lang::IllegalArgumentException ) : ScVbaCharacters_BASE( xParent, xContext ), m_xSimpleText(xRange), m_aPalette( dPalette), nLength(-1), nStart(1), bReplace( Replace ) 37 { 38 Start >>= nStart; 39 if ( nStart < 1 ) 40 nStart = 1; // silently correct user error ( as ms ) 41 nStart--; // OOo is 0 based 42 Length >>=nLength; 43 uno::Reference< text::XTextCursor > xTextCursor( m_xSimpleText->createTextCursor(), uno::UNO_QUERY_THROW ); 44 xTextCursor->collapseToStart(); 45 if ( nStart ) 46 { 47 if ( ( nStart + 1 ) > m_xSimpleText->getString().getLength() ) 48 //nStart = m_xSimpleText->getString().getLength(); 49 xTextCursor->gotoEnd( sal_False ); 50 xTextCursor->goRight( nStart, sal_False ); 51 } 52 if ( nLength < 0 ) // expand to end 53 xTextCursor->gotoEnd( sal_True ); 54 else 55 xTextCursor->goRight( nLength, sal_True ); 56 m_xTextRange.set( xTextCursor, uno::UNO_QUERY_THROW ); 57 58 } 59 60 ::rtl::OUString SAL_CALL 61 ScVbaCharacters::getCaption() throw (css::uno::RuntimeException) 62 { 63 return m_xTextRange->getString(); 64 } 65 void SAL_CALL 66 ScVbaCharacters::setCaption( const ::rtl::OUString& _caption ) throw (css::uno::RuntimeException) 67 { 68 m_xTextRange->setString( _caption ); 69 70 } 71 72 ::sal_Int32 SAL_CALL 73 ScVbaCharacters::getCount() throw (css::uno::RuntimeException) 74 { 75 return getCaption().getLength(); 76 } 77 78 ::rtl::OUString SAL_CALL 79 ScVbaCharacters::getText() throw (css::uno::RuntimeException) 80 { 81 return getCaption(); 82 } 83 void SAL_CALL 84 ScVbaCharacters::setText( const ::rtl::OUString& _text ) throw (css::uno::RuntimeException) 85 { 86 setCaption( _text ); 87 } 88 uno::Reference< excel::XFont > SAL_CALL 89 ScVbaCharacters::getFont() throw (css::uno::RuntimeException) 90 { 91 uno::Reference< beans::XPropertySet > xProps( m_xTextRange, uno::UNO_QUERY_THROW ); 92 return uno::Reference< excel::XFont >( new ScVbaFont( this, mxContext, m_aPalette, xProps ) ); 93 } 94 void SAL_CALL 95 ScVbaCharacters::setFont( const uno::Reference< excel::XFont >& /*_font*/ ) throw (css::uno::RuntimeException) 96 { 97 // #TODO #FIXME needs implementation, or can't be done? 98 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Not Implemented") ), uno::Reference< XInterface >() ); 99 } 100 101 102 // Methods 103 void SAL_CALL 104 ScVbaCharacters::Insert( const ::rtl::OUString& String ) throw (css::uno::RuntimeException) 105 { 106 m_xSimpleText->insertString( m_xTextRange, String, bReplace ); 107 } 108 109 void SAL_CALL 110 ScVbaCharacters::Delete( ) throw (css::uno::RuntimeException) 111 { 112 // #FIXME #TODO is this a bit suspect?, I wonder should the contents 113 // of the cell be deleted from the parent ( range ) 114 m_xSimpleText->setString(rtl::OUString()); 115 } 116 117 118 rtl::OUString& 119 ScVbaCharacters::getServiceImplName() 120 { 121 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaCharacters") ); 122 return sImplName; 123 } 124 125 uno::Sequence< rtl::OUString > 126 ScVbaCharacters::getServiceNames() 127 { 128 static uno::Sequence< rtl::OUString > aServiceNames; 129 if ( aServiceNames.getLength() == 0 ) 130 { 131 aServiceNames.realloc( 1 ); 132 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Characters" ) ); 133 } 134 return aServiceNames; 135 } 136 137