From aac15b638410f181133dc15343136b4e9a1675ba Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Mon, 7 May 2012 15:22:54 -0400 Subject: Set anchor to XTextContent using UNO API. Change-Id: Id1ccae62037369917a46d620c0c46ac2447a0910 --- editeng/inc/editeng/unonames.hxx | 33 +++++++++++++++++++++++++++++++++ editeng/source/uno/unofield.cxx | 11 +++++++++++ editeng/source/uno/unotext.cxx | 8 ++++++-- 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 editeng/inc/editeng/unonames.hxx diff --git a/editeng/inc/editeng/unonames.hxx b/editeng/inc/editeng/unonames.hxx new file mode 100644 index 000000000000..e7241151aac0 --- /dev/null +++ b/editeng/inc/editeng/unonames.hxx @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Major Contributor(s): + * Copyright (C) 2012 Kohei Yoshida + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ + +#define UNO_TC_PROP_ANCHOR "Anchor" + +#define UNO_TR_PROP_SELECTION "Selection" + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/editeng/source/uno/unofield.cxx b/editeng/source/uno/unofield.cxx index 7b97684275cb..50c578f567ee 100644 --- a/editeng/source/uno/unofield.cxx +++ b/editeng/source/uno/unofield.cxx @@ -41,6 +41,8 @@ #include #include +#include "editeng/unonames.hxx" + using namespace ::rtl; using namespace ::cppu; using namespace ::com::sun::star; @@ -671,6 +673,12 @@ void SAL_CALL SvxUnoTextField::setPropertyValue( const OUString& aPropertyName, if( mpImpl == NULL ) throw uno::RuntimeException(); + if (aPropertyName == UNO_TC_PROP_ANCHOR) + { + aValue >>= mxAnchor; + return; + } + const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap().getByName( aPropertyName ); if ( !pMap ) throw beans::UnknownPropertyException(); @@ -838,6 +846,9 @@ uno::Any SAL_CALL SvxUnoTextField::getPropertyValue( const OUString& PropertyNam { SolarMutexGuard aGuard; + if (PropertyName == UNO_TC_PROP_ANCHOR) + return uno::makeAny(mxAnchor); + uno::Any aValue; const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap().getByName( PropertyName ); diff --git a/editeng/source/uno/unotext.cxx b/editeng/source/uno/unotext.cxx index a13bb0ca768f..52d31bb56aae 100644 --- a/editeng/source/uno/unotext.cxx +++ b/editeng/source/uno/unotext.cxx @@ -55,7 +55,7 @@ #include #include -#define UNO_TR_PROP_SELECTION "Selection" +#include "editeng/unonames.hxx" using namespace ::rtl; using namespace ::cppu; @@ -1821,7 +1821,11 @@ void SAL_CALL SvxUnoTextBase::insertTextContent( const uno::Reference< text::XTe pForwarder->QuickInsertField(aField, toESelection(aSel)); GetEditSource()->UpdateData(); - pField->SetAnchor( uno::Reference< text::XTextRange >::query( (cppu::OWeakObject*)this ) ); + uno::Reference xPropSetContent(xContent, uno::UNO_QUERY); + if (!xContent.is()) + throw lang::IllegalArgumentException(); + + xPropSetContent->setPropertyValue(UNO_TC_PROP_ANCHOR, uno::makeAny(xRange)); aSel.End.PositionInParagraph += 1; aSel.Start.PositionInParagraph = aSel.End.PositionInParagraph; -- cgit