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