LibreOffice Module sc (master) 1
vbacharacters.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#include "vbacharacters.hxx"
20
21#include "vbafont.hxx"
22
23#include <com/sun/star/beans/XPropertySet.hpp>
24#include <utility>
25
26using namespace ::ooo::vba;
27using namespace ::com::sun::star;
28
29ScVbaCharacters::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,
35 bool Replace )
36 : ScVbaCharacters_BASE( xParent, xContext ),
37 m_xSimpleText(std::move(xRange)), m_aPalette( dPalette), bReplace( Replace )
38{
39 sal_Int16 nLength(-1);
40 sal_Int16 nStart(1);
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_SET_THROW );
47 xTextCursor->collapseToStart();
48 if ( nStart )
49 {
50 if ( ( nStart + 1 ) > m_xSimpleText->getString().getLength() )
51 //nStart = m_xSimpleText->getString().getLength();
52 xTextCursor->gotoEnd( false );
53 xTextCursor->goRight( nStart, false );
54 }
55 if ( nLength < 0 ) // expand to end
56 xTextCursor->gotoEnd( true );
57 else
58 xTextCursor->goRight( nLength, true );
59 m_xTextRange.set( xTextCursor, uno::UNO_QUERY_THROW );
60
61}
62
63OUString SAL_CALL
65{
66 return m_xTextRange->getString();
67}
68void SAL_CALL
69ScVbaCharacters::setCaption( const OUString& _caption )
70{
71 m_xTextRange->setString( _caption );
72
73}
74
75::sal_Int32 SAL_CALL
77{
78 return getCaption().getLength();
79}
80
81OUString SAL_CALL
83{
84 return getCaption();
85}
86void SAL_CALL
87ScVbaCharacters::setText( const OUString& _text )
88{
89 setCaption( _text );
90}
91uno::Reference< excel::XFont > SAL_CALL
93{
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 ) );
96}
97void SAL_CALL
98ScVbaCharacters::setFont( const uno::Reference< excel::XFont >& /*_font*/ )
99{
100 // #TODO #FIXME needs implementation, or can't be done?
101 throw uno::RuntimeException("Not Implemented" );
102}
103
104// Methods
105void SAL_CALL
106ScVbaCharacters::Insert( const OUString& rString )
107{
108 m_xSimpleText->insertString( m_xTextRange, rString, bReplace );
109}
110
111void SAL_CALL
113{
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());
117}
118
119OUString
121{
122 return "ScVbaCharacters";
123}
124
125uno::Sequence< OUString >
127{
128 static uno::Sequence< OUString > const aServiceNames
129 {
130 "ooo.vba.excel.Characters"
131 };
132 return aServiceNames;
133}
134
135/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual void SAL_CALL Delete() override
virtual void SAL_CALL Insert(const OUString &String) override
ScVbaCharacters(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const ScVbaPalette &dPalette, css::uno::Reference< css::text::XSimpleText > xRange, const css::uno::Any &Start, const css::uno::Any &Length, bool bReplace=false)
virtual OUString SAL_CALL getCaption() override
virtual OUString SAL_CALL getText() override
virtual OUString getServiceImplName() override
virtual void SAL_CALL setCaption(const OUString &_caption) override
virtual void SAL_CALL setText(const OUString &_text) override
virtual void SAL_CALL setFont(const css::uno::Reference< ov::excel::XFont > &_font) override
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual ::sal_Int32 SAL_CALL getCount() override
virtual css::uno::Reference< ov::excel::XFont > SAL_CALL getFont() override
css::uno::Reference< css::text::XTextRange > m_xTextRange
ScVbaPalette m_aPalette
css::uno::Reference< css::text::XSimpleText > m_xSimpleText
Sequence< OUString > aServiceNames
Length
sal_Int32 nLength