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