summaryrefslogtreecommitdiff
path: root/sw/source/core/unocore/unorefmk.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sw/source/core/unocore/unorefmk.cxx')
-rw-r--r--sw/source/core/unocore/unorefmk.cxx86
1 files changed, 74 insertions, 12 deletions
diff --git a/sw/source/core/unocore/unorefmk.cxx b/sw/source/core/unocore/unorefmk.cxx
index 1450e1bd806a..622a995df0ac 100644
--- a/sw/source/core/unocore/unorefmk.cxx
+++ b/sw/source/core/unocore/unorefmk.cxx
@@ -38,6 +38,7 @@
#include <unomap.hxx>
#include <unocrsr.hxx>
#include <unoevtlstnr.hxx>
+#include <unocrsrhelper.hxx>
#include <doc.hxx>
#include <ndtxt.hxx>
#include <fmtrfmrk.hxx>
@@ -235,6 +236,17 @@ throw (uno::RuntimeException)
/* -----------------03.11.99 14:14-------------------
--------------------------------------------------*/
+template<typename T> struct NotContainedIn
+{
+ ::std::vector<T> const& m_rVector;
+ explicit NotContainedIn(::std::vector<T> const& rVector)
+ : m_rVector(rVector) { }
+ bool operator() (T const& rT) {
+ return ::std::find(m_rVector.begin(), m_rVector.end(), rT)
+ == m_rVector.end();
+ }
+};
+
void SwXReferenceMark::Impl::InsertRefMark(SwPaM& rPam,
SwXTextCursor const*const pCursor)
{
@@ -254,6 +266,13 @@ void SwXReferenceMark::Impl::InsertRefMark(SwPaM& rPam,
| nsSetAttrMode::SETATTR_DONTEXPAND)
: nsSetAttrMode::SETATTR_DONTEXPAND;
+ ::std::vector<SwTxtAttr *> oldMarks;
+ if (bMark)
+ {
+ oldMarks = rPam.GetNode()->GetTxtNode()->GetTxtAttrsAt(
+ rPam.GetPoint()->nContent.GetIndex(), RES_TXTATR_REFMARK);
+ }
+
pDoc2->InsertPoolItem( rPam, aRefMark, nInsertFlags );
if( bMark && *rPam.GetPoint() > *rPam.GetMark())
@@ -261,17 +280,38 @@ void SwXReferenceMark::Impl::InsertRefMark(SwPaM& rPam,
rPam.Exchange();
}
- SwTxtAttr *const pTxtAttr = (bMark)
- ? rPam.GetNode()->GetTxtNode()->GetTxtAttr(
- rPam.GetPoint()->nContent, RES_TXTATR_REFMARK)
- : rPam.GetNode()->GetTxtNode()->GetTxtAttrForCharAt(
+ // aRefMark was copied into the document pool; now retrieve real format...
+ SwTxtAttr * pTxtAttr(0);
+ if (bMark)
+ {
+ // #i107672#
+ // ensure that we do not retrieve a different mark at the same position
+ ::std::vector<SwTxtAttr *> const newMarks(
+ rPam.GetNode()->GetTxtNode()->GetTxtAttrsAt(
+ rPam.GetPoint()->nContent.GetIndex(), RES_TXTATR_REFMARK));
+ ::std::vector<SwTxtAttr *>::const_iterator const iter(
+ ::std::find_if(newMarks.begin(), newMarks.end(),
+ NotContainedIn<SwTxtAttr *>(oldMarks)));
+ OSL_ASSERT(newMarks.end() != iter);
+ if (newMarks.end() != iter)
+ {
+ pTxtAttr = *iter;
+ }
+ }
+ else
+ {
+ pTxtAttr = rPam.GetNode()->GetTxtNode()->GetTxtAttrForCharAt(
rPam.GetPoint()->nContent.GetIndex() - 1, RES_TXTATR_REFMARK);
+ }
- if(pTxtAttr)
+ if (!pTxtAttr)
{
- m_pMarkFmt = &pTxtAttr->GetRefMark();
+ throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
+ "SwXReferenceMark::InsertRefMark(): cannot insert attribute")), 0);
}
+ m_pMarkFmt = &pTxtAttr->GetRefMark();
+
pDoc2->GetUnoCallBack()->Add(this);
}
@@ -310,7 +350,6 @@ throw (lang::IllegalArgumentException, uno::RuntimeException)
m_pImpl->InsertRefMark(aPam, dynamic_cast<SwXTextCursor*>(pCursor));
m_pImpl->m_bIsDescriptor = sal_False;
m_pImpl->m_pDoc = pDocument;
- m_pImpl->m_pDoc->GetUnoCallBack()->Add(m_pImpl.get());
}
/*-- 11.12.98 10:28:34---------------------------------------------------
@@ -1159,11 +1198,7 @@ uno::Reference< text::XText > SAL_CALL
SwXMeta::getText() throw (uno::RuntimeException)
{
vos::OGuard g(Application::GetSolarMutex());
- //TODO probably this should return outer meta in case there is nesting,
- // but currently that is not done; would need to change at least
- // SwXTextPortionEnumeration and SwXMeta::attach and other places where
- // SwXMeta is constructed
- return GetParentText();
+ return this;
}
uno::Reference< text::XTextRange > SAL_CALL
@@ -1249,6 +1284,33 @@ SwXMeta::removeTextContent(
return m_pImpl->m_Text.removeTextContent(xContent);
}
+// XChild
+uno::Reference< uno::XInterface > SAL_CALL
+SwXMeta::getParent() throw (uno::RuntimeException)
+{
+ vos::OGuard g(Application::GetSolarMutex());
+ SwTxtNode * pTxtNode;
+ xub_StrLen nMetaStart;
+ xub_StrLen nMetaEnd;
+ bool const bSuccess( SetContentRange(pTxtNode, nMetaStart, nMetaEnd) );
+ OSL_ENSURE(bSuccess, "no pam?");
+ if (!bSuccess) { throw lang::DisposedException(); }
+ // in order to prevent getting this meta, subtract 1 from nMetaStart;
+ // so we get the index of the dummy character, and we exclude it
+ // by calling GetTxtAttrAt(_, _, PARENT) in GetNestedTextContent
+ uno::Reference<text::XTextContent> const xRet(
+ SwUnoCursorHelper::GetNestedTextContent(*pTxtNode, nMetaStart - 1,
+ true) );
+ return xRet;
+}
+
+void SAL_CALL
+SwXMeta::setParent(uno::Reference< uno::XInterface > const& /*xParent*/)
+ throw (uno::RuntimeException, lang::NoSupportException)
+{
+ throw lang::NoSupportException(C2S("setting parent not supported"), *this);
+}
+
// XElementAccess
uno::Type SAL_CALL
SwXMeta::getElementType() throw (uno::RuntimeException)