1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include "vbacharacters.hxx"
21 #include "vbafont.hxx"
23 #include <com/sun/star/beans/XPropertySet.hpp>
26 using namespace ::ooo::vba
;
27 using namespace ::com::sun::star
;
29 ScVbaCharacters::ScVbaCharacters( const uno::Reference
< XHelperInterface
>& xParent
,
30 const uno::Reference
< uno::XComponentContext
>& xContext
,
31 const ScVbaPalette
& dPalette
,
32 uno::Reference
< text::XSimpleText
> xRange
,
33 const css::uno::Any
& Start
,
34 const css::uno::Any
& Length
,
36 : ScVbaCharacters_BASE( xParent
, xContext
),
37 m_xSimpleText(std::move(xRange
)), m_aPalette( dPalette
), bReplace( Replace
)
39 sal_Int16
nLength(-1);
43 nStart
= 1; // silently correct user error ( as ms )
44 nStart
--; // OOo is 0 based
46 uno::Reference
< text::XTextCursor
> xTextCursor( m_xSimpleText
->createTextCursor(), uno::UNO_SET_THROW
);
47 xTextCursor
->collapseToStart();
50 if ( ( nStart
+ 1 ) > m_xSimpleText
->getString().getLength() )
51 //nStart = m_xSimpleText->getString().getLength();
52 xTextCursor
->gotoEnd( false );
53 xTextCursor
->goRight( nStart
, false );
55 if ( nLength
< 0 ) // expand to end
56 xTextCursor
->gotoEnd( true );
58 xTextCursor
->goRight( nLength
, true );
59 m_xTextRange
.set( xTextCursor
, uno::UNO_QUERY_THROW
);
64 ScVbaCharacters::getCaption()
66 return m_xTextRange
->getString();
69 ScVbaCharacters::setCaption( const OUString
& _caption
)
71 m_xTextRange
->setString( _caption
);
76 ScVbaCharacters::getCount()
78 return getCaption().getLength();
82 ScVbaCharacters::getText()
87 ScVbaCharacters::setText( const OUString
& _text
)
91 uno::Reference
< excel::XFont
> SAL_CALL
92 ScVbaCharacters::getFont()
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
) );
98 ScVbaCharacters::setFont( const uno::Reference
< excel::XFont
>& /*_font*/ )
100 // #TODO #FIXME needs implementation, or can't be done?
101 throw uno::RuntimeException(u
"Not Implemented"_ustr
);
106 ScVbaCharacters::Insert( const OUString
& rString
)
108 m_xSimpleText
->insertString( m_xTextRange
, rString
, bReplace
);
112 ScVbaCharacters::Delete( )
114 // #FIXME #TODO is this a bit suspect? I wonder should the contents
115 // of the cell be deleted from the parent ( range )
116 m_xSimpleText
->setString(OUString());
120 ScVbaCharacters::getServiceImplName()
122 return u
"ScVbaCharacters"_ustr
;
125 uno::Sequence
< OUString
>
126 ScVbaCharacters::getServiceNames()
128 static uno::Sequence
< OUString
> const aServiceNames
130 u
"ooo.vba.excel.Characters"_ustr
132 return aServiceNames
;
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */