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