xref: /aoo42x/main/sc/source/ui/vba/vbacharacters.cxx (revision b3f79822)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #include "vbacharacters.hxx"
24 
25 #include "vbaglobals.hxx"
26 #include "vbafont.hxx"
27 
28 
29 using namespace ::ooo::vba;
30 using namespace ::com::sun::star;
31 
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)32 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 )
33 {
34 	Start >>= nStart;
35 	if ( nStart < 1 )
36 		nStart = 1; // silently correct user error ( as ms )
37 	nStart--; // OOo is 0 based
38 	Length >>=nLength;
39 	uno::Reference< text::XTextCursor > xTextCursor( m_xSimpleText->createTextCursor(), uno::UNO_QUERY_THROW );
40 	xTextCursor->collapseToStart();
41 	if ( nStart )
42 	{
43 		if ( ( nStart + 1 ) > m_xSimpleText->getString().getLength() )
44 			//nStart = m_xSimpleText->getString().getLength();
45 			xTextCursor->gotoEnd( sal_False );
46 		xTextCursor->goRight( nStart, sal_False );
47 	}
48 	if ( nLength < 0 ) // expand to end
49 		xTextCursor->gotoEnd( sal_True );
50 	else
51 		xTextCursor->goRight( nLength, sal_True );
52 	m_xTextRange.set( xTextCursor, uno::UNO_QUERY_THROW );
53 
54 }
55 
56 ::rtl::OUString SAL_CALL
getCaption()57 ScVbaCharacters::getCaption() throw (css::uno::RuntimeException)
58 {
59 	return m_xTextRange->getString();
60 }
61 void SAL_CALL
setCaption(const::rtl::OUString & _caption)62 ScVbaCharacters::setCaption( const ::rtl::OUString& _caption ) throw (css::uno::RuntimeException)
63 {
64 	m_xTextRange->setString( _caption );
65 
66 }
67 
68 ::sal_Int32 SAL_CALL
getCount()69 ScVbaCharacters::getCount() throw (css::uno::RuntimeException)
70 {
71 	return getCaption().getLength();
72 }
73 
74 ::rtl::OUString SAL_CALL
getText()75 ScVbaCharacters::getText() throw (css::uno::RuntimeException)
76 {
77 	return getCaption();
78 }
79 void SAL_CALL
setText(const::rtl::OUString & _text)80 ScVbaCharacters::setText( const ::rtl::OUString& _text ) throw (css::uno::RuntimeException)
81 {
82 	setCaption( _text );
83 }
84 uno::Reference< excel::XFont > SAL_CALL
getFont()85 ScVbaCharacters::getFont() throw (css::uno::RuntimeException)
86 {
87 	uno::Reference< beans::XPropertySet > xProps( m_xTextRange, uno::UNO_QUERY_THROW );
88 	return uno::Reference< excel::XFont >( new ScVbaFont( this, mxContext, m_aPalette, xProps ) );
89 }
90 void SAL_CALL
setFont(const uno::Reference<excel::XFont> &)91 ScVbaCharacters::setFont( const uno::Reference< excel::XFont >& /*_font*/ ) throw (css::uno::RuntimeException)
92 {
93 	// #TODO #FIXME needs implementation, or can't be done?
94 	throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Not Implemented") ), uno::Reference< XInterface >() );
95 }
96 
97 
98 // Methods
99 void SAL_CALL
Insert(const::rtl::OUString & String)100 ScVbaCharacters::Insert( const ::rtl::OUString& String ) throw (css::uno::RuntimeException)
101 {
102 	m_xSimpleText->insertString( m_xTextRange, String, bReplace );
103 }
104 
105 void SAL_CALL
Delete()106 ScVbaCharacters::Delete(  ) throw (css::uno::RuntimeException)
107 {
108 	// #FIXME #TODO is this a bit suspect?, I wonder should the contents
109 	// of the cell be deleted from the parent ( range )
110 	m_xSimpleText->setString(rtl::OUString());
111 }
112 
113 
114 rtl::OUString&
getServiceImplName()115 ScVbaCharacters::getServiceImplName()
116 {
117 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaCharacters") );
118 	return sImplName;
119 }
120 
121 uno::Sequence< rtl::OUString >
getServiceNames()122 ScVbaCharacters::getServiceNames()
123 {
124 	static uno::Sequence< rtl::OUString > aServiceNames;
125 	if ( aServiceNames.getLength() == 0 )
126 	{
127 		aServiceNames.realloc( 1 );
128 		aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Characters" ) );
129 	}
130 	return aServiceNames;
131 }
132 
133