/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ #include"vbarange.hxx" #include <utility> #include <vbahelper/vbahelper.hxx> #include <basic/sberrors.hxx> #include"vbarangehelper.hxx" #include <ooo/vba/word/WdBreakType.hpp> #include <com/sun/star/style/BreakType.hpp> #include <com/sun/star/text/ControlCharacter.hpp> #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> #include <com/sun/star/text/XTextRangeCompare.hpp> #include <com/sun/star/text/XTextViewCursor.hpp> #include"vbaparagraphformat.hxx" #include"vbastyle.hxx" #include"vbafont.hxx" #include"vbafind.hxx" #include"vbapalette.hxx" #include"vbapagesetup.hxx" #include"vbalistformat.hxx" #include"vbarevisions.hxx" #include"vbabookmarks.hxx" #include"vbasections.hxx" #include"vbafield.hxx" #include"wordvbahelper.hxx" #include <unotxdoc.hxx> #include <unostyle.hxx>
/** * The complexity in this method is because we need to workaround * an issue that the last paragraph in a document does not have a trailing CRLF. * @return
*/
OUString SAL_CALL
SwVbaRange::getText()
{
OUString aText = mxTextCursor->getString();
sal_Int32 nLen = aText.getLength();
// FIXME: should add a line separator if the range includes the last paragraph if( nLen == 0 )
{ if( mxTextCursor->isCollapsed() )
{
mxTextCursor->goRight( 1, true );
aText = mxTextCursor->getString();
mxTextCursor->collapseToStart();
} else
{
uno::Reference< text::XTextRange > xStart = mxTextCursor->getStart();
uno::Reference< text::XTextRange > xEnd = mxTextCursor->getEnd();
mxTextCursor->collapseToEnd();
mxTextCursor->goRight( 1, true );
mxTextCursor->gotoRange( xStart, false );
mxTextCursor->gotoRange( xEnd, true );
}
}
return aText;
}
void SAL_CALL
SwVbaRange::setText( const OUString& rText )
{ // Emulate the MSWord behavior, Don't delete the bookmark // which contains no text string in current inserting position,
OUString sName;
uno::Reference< text::XTextRange > xRange( mxTextCursor, uno::UNO_QUERY_THROW ); try
{
uno::Reference< text::XTextContent > xBookmark = SwVbaRangeHelper::findBookmarkByPosition( mxTextDocument, xRange->getStart() ); if( xBookmark.is() )
{
uno::Reference< container::XNamed > xNamed( xBookmark, uno::UNO_QUERY ); if (xNamed)
sName = xNamed->getName();
}
} catch (const uno::Exception&)
{ // do nothing
}
// insert the bookmark if the bookmark is deleted during setting text string if( !sName.isEmpty() )
{
uno::Reference< container::XNameAccess > xNameAccess( mxTextDocument->getBookmarks(), uno::UNO_SET_THROW ); if( !xNameAccess->hasByName( sName ) )
{
SwVbaBookmarks::addBookmarkByName( mxTextDocument, sName, xRange->getStart() );
}
}
}
// FIXME: test is not pass void SAL_CALL SwVbaRange::InsertBreak(const uno::Any& _breakType)
{ // default type is wdPageBreak;
sal_Int32 nBreakType = word::WdBreakType::wdPageBreak; if( _breakType.hasValue() )
_breakType >>= nBreakType;
style::BreakType eBreakType = style::BreakType_NONE; switch( nBreakType )
{ case word::WdBreakType::wdPageBreak:
eBreakType = style::BreakType_PAGE_BEFORE; break; case word::WdBreakType::wdColumnBreak:
eBreakType = style::BreakType_COLUMN_AFTER; break; case word::WdBreakType::wdLineBreak: case word::WdBreakType::wdLineBreakClearLeft: case word::WdBreakType::wdLineBreakClearRight: case word::WdBreakType::wdSectionBreakContinuous: case word::WdBreakType::wdSectionBreakEvenPage: case word::WdBreakType::wdSectionBreakNextPage: case word::WdBreakType::wdSectionBreakOddPage: case word::WdBreakType::wdTextWrappingBreak:
DebugHelper::basicexception( ERRCODE_BASIC_NOT_IMPLEMENTED, {} ); break; default:
DebugHelper::basicexception( ERRCODE_BASIC_BAD_PARAMETER, {} );
}
uno::Any SAL_CALL
SwVbaRange::Fields( const uno::Any& index )
{ //FIXME: should be get the field in current range
uno::Reference< XCollection > xCol( new SwVbaFields( mxParent, mxContext, mxTextDocument ) ); if ( index.hasValue() ) return xCol->Item( index, uno::Any() ); return uno::Any( xCol );
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.