Update ooo320-m1
[ooovba.git] / sc / source / ui / vba / vbacharacters.cxx
blob8f3c485b38f7c00838ba312c495b2a0ac148bfc3
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: vbacharacters.cxx,v $
10 * $Revision: 1.4 $
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 "vbacharacters.hxx"
32 #include "vbaglobals.hxx"
33 #include "vbafont.hxx"
36 using namespace ::ooo::vba;
37 using namespace ::com::sun::star;
39 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 )
41 Start >>= nStart;
42 if ( nStart < 1 )
43 nStart = 1; // silently correct user error ( as ms )
44 nStart--; // OOo is 0 based
45 Length >>=nLength;
46 uno::Reference< text::XTextCursor > xTextCursor( m_xSimpleText->createTextCursor(), uno::UNO_QUERY_THROW );
47 xTextCursor->collapseToStart();
48 if ( nStart )
50 if ( ( nStart + 1 ) > m_xSimpleText->getString().getLength() )
51 //nStart = m_xSimpleText->getString().getLength();
52 xTextCursor->gotoEnd( sal_False );
53 xTextCursor->goRight( nStart, sal_False );
55 if ( nLength < 0 ) // expand to end
56 xTextCursor->gotoEnd( sal_True );
57 else
58 xTextCursor->goRight( nLength, sal_True );
59 m_xTextRange.set( xTextCursor, uno::UNO_QUERY_THROW );
63 ::rtl::OUString SAL_CALL
64 ScVbaCharacters::getCaption() throw (css::uno::RuntimeException)
66 return m_xTextRange->getString();
68 void SAL_CALL
69 ScVbaCharacters::setCaption( const ::rtl::OUString& _caption ) throw (css::uno::RuntimeException)
71 m_xTextRange->setString( _caption );
75 ::sal_Int32 SAL_CALL
76 ScVbaCharacters::getCount() throw (css::uno::RuntimeException)
78 return getCaption().getLength();
81 ::rtl::OUString SAL_CALL
82 ScVbaCharacters::getText() throw (css::uno::RuntimeException)
84 return getCaption();
86 void SAL_CALL
87 ScVbaCharacters::setText( const ::rtl::OUString& _text ) throw (css::uno::RuntimeException)
89 setCaption( _text );
91 uno::Reference< excel::XFont > SAL_CALL
92 ScVbaCharacters::getFont() throw (css::uno::RuntimeException)
94 uno::Reference< beans::XPropertySet > xProps( m_xTextRange, uno::UNO_QUERY_THROW );
95 return uno::Reference< excel::XFont >( new ScVbaFont( this, mxContext, m_aPalette, xProps ) );
97 void SAL_CALL
98 ScVbaCharacters::setFont( const uno::Reference< excel::XFont >& /*_font*/ ) throw (css::uno::RuntimeException)
100 // #TODO #FIXME needs implementation, or can't be done?
101 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Not Implemented") ), uno::Reference< XInterface >() );
105 // Methods
106 void SAL_CALL
107 ScVbaCharacters::Insert( const ::rtl::OUString& String ) throw (css::uno::RuntimeException)
109 m_xSimpleText->insertString( m_xTextRange, String, bReplace );
112 void SAL_CALL
113 ScVbaCharacters::Delete( ) throw (css::uno::RuntimeException)
115 // #FIXME #TODO is this a bit suspect?, I wonder should the contents
116 // of the cell be deleted from the parent ( range )
117 m_xSimpleText->setString(rtl::OUString());
121 rtl::OUString&
122 ScVbaCharacters::getServiceImplName()
124 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaCharacters") );
125 return sImplName;
128 uno::Sequence< rtl::OUString >
129 ScVbaCharacters::getServiceNames()
131 static uno::Sequence< rtl::OUString > aServiceNames;
132 if ( aServiceNames.getLength() == 0 )
134 aServiceNames.realloc( 1 );
135 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Characters" ) );
137 return aServiceNames;