Kaydet (Commit) e1323281 authored tarafından Bjoern Michaelsen's avatar Bjoern Michaelsen

use UnoCursorPointer in ParagraphFrameEnumeration

Change-Id: I5fdf0bdd8609aa07c49b155cc75cade8bdb2c292
üst 4186d572
...@@ -22,42 +22,49 @@ ...@@ -22,42 +22,49 @@
#include <deque> #include <deque>
#include <boost/shared_ptr.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/container/XEnumeration.hpp> #include <com/sun/star/container/XEnumeration.hpp>
#include <com/sun/star/text/XTextContent.hpp> #include <com/sun/star/text/XTextContent.hpp>
#include <cppuhelper/implbase.hxx> #include <cppuhelper/implbase.hxx>
#include <calbck.hxx>
#include <unobaseclass.hxx> #include <unobaseclass.hxx>
class SwDepend; class SwDepend;
class SwNodeIndex; class SwNodeIndex;
class SwPaM; class SwPaM;
class SwFrameFormat; class SwFrameFormat;
struct FrameDependSortListEntry namespace sw
{
struct FrameClient : public SwClient
{
FrameClient(SwModify* pModify) : SwClient(pModify) {};
};
}
struct FrameClientSortListEntry
{ {
sal_Int32 nIndex; sal_Int32 nIndex;
sal_uInt32 nOrder; sal_uInt32 nOrder;
::boost::shared_ptr<SwDepend> pFrameDepend; std::shared_ptr<sw::FrameClient> pFrameClient;
FrameDependSortListEntry (sal_Int32 const i_nIndex, FrameClientSortListEntry (sal_Int32 const i_nIndex,
sal_uInt32 const i_nOrder, SwDepend * const i_pDepend) sal_uInt32 const i_nOrder, sw::FrameClient* const i_pClient)
: nIndex(i_nIndex), nOrder(i_nOrder), pFrameDepend(i_pDepend) { } : nIndex(i_nIndex), nOrder(i_nOrder), pFrameClient(i_pClient) { }
}; };
typedef ::std::deque< FrameDependSortListEntry > typedef ::std::deque< FrameClientSortListEntry >
FrameDependSortList_t; FrameClientSortList_t;
typedef ::std::deque< ::boost::shared_ptr<SwDepend> > typedef ::std::deque< std::shared_ptr<sw::FrameClient> >
FrameDependList_t; FrameClientList_t;
// #i28701# - adjust 4th parameter // #i28701# - adjust 4th parameter
void CollectFrameAtNode( SwClient& rClnt, const SwNodeIndex& rIdx, void CollectFrameAtNode( const SwNodeIndex& rIdx,
FrameDependSortList_t & rFrames, FrameClientSortList_t& rFrames,
const bool _bAtCharAnchoredObjs ); const bool bAtCharAnchoredObjs );
enum ParaFrameMode enum ParaFrameMode
{ {
......
...@@ -155,20 +155,19 @@ void DeepCopyPaM(SwPaM const & rSource, SwPaM & rTarget) ...@@ -155,20 +155,19 @@ void DeepCopyPaM(SwPaM const & rSource, SwPaM & rTarget)
} // namespace sw } // namespace sw
struct FrameDependSortListLess struct FrameClientSortListLess
{ {
bool operator() (FrameDependSortListEntry const& r1, bool operator() (FrameClientSortListEntry const& r1,
FrameDependSortListEntry const& r2) const FrameClientSortListEntry const& r2) const
{ {
return (r1.nIndex < r2.nIndex) return (r1.nIndex < r2.nIndex)
|| ((r1.nIndex == r2.nIndex) && (r1.nOrder < r2.nOrder)); || ((r1.nIndex == r2.nIndex) && (r1.nOrder < r2.nOrder));
} }
}; };
// OD 2004-05-07 #i28701# - adjust 4th parameter void CollectFrameAtNode( const SwNodeIndex& rIdx,
void CollectFrameAtNode( SwClient& rClnt, const SwNodeIndex& rIdx, FrameClientSortList_t& rFrames,
FrameDependSortList_t & rFrames, const bool bAtCharAnchoredObjs )
const bool _bAtCharAnchoredObjs )
{ {
// _bAtCharAnchoredObjs: // _bAtCharAnchoredObjs:
// <true>: at-character anchored objects are collected // <true>: at-character anchored objects are collected
...@@ -177,7 +176,7 @@ void CollectFrameAtNode( SwClient& rClnt, const SwNodeIndex& rIdx, ...@@ -177,7 +176,7 @@ void CollectFrameAtNode( SwClient& rClnt, const SwNodeIndex& rIdx,
// search all borders, images, and OLEs that are connected to the paragraph // search all borders, images, and OLEs that are connected to the paragraph
SwDoc* pDoc = rIdx.GetNode().GetDoc(); SwDoc* pDoc = rIdx.GetNode().GetDoc();
const sal_uInt16 nChkType = static_cast< sal_uInt16 >((_bAtCharAnchoredObjs) const sal_uInt16 nChkType = static_cast< sal_uInt16 >((bAtCharAnchoredObjs)
? FLY_AT_CHAR : FLY_AT_PARA); ? FLY_AT_CHAR : FLY_AT_PARA);
const SwContentFrm* pCFrm; const SwContentFrm* pCFrm;
const SwContentNode* pCNd; const SwContentNode* pCNd;
...@@ -201,14 +200,14 @@ void CollectFrameAtNode( SwClient& rClnt, const SwNodeIndex& rIdx, ...@@ -201,14 +200,14 @@ void CollectFrameAtNode( SwClient& rClnt, const SwNodeIndex& rIdx,
if ( rFormat.GetAnchor().GetAnchorId() == nChkType ) if ( rFormat.GetAnchor().GetAnchorId() == nChkType )
{ {
// create SwDepend and insert into array // create SwDepend and insert into array
SwDepend* pNewDepend = new SwDepend( &rClnt, &rFormat ); sw::FrameClient* pNewClient = new sw::FrameClient( &rFormat );
const sal_Int32 idx = const sal_Int32 idx =
rFormat.GetAnchor().GetContentAnchor()->nContent.GetIndex(); rFormat.GetAnchor().GetContentAnchor()->nContent.GetIndex();
sal_uInt32 nOrder = rFormat.GetAnchor().GetOrder(); sal_uInt32 nOrder = rFormat.GetAnchor().GetOrder();
// OD 2004-05-07 #i28701# - sorting no longer needed, // OD 2004-05-07 #i28701# - sorting no longer needed,
// because list <SwSortedObjs> is already sorted. // because list <SwSortedObjs> is already sorted.
FrameDependSortListEntry entry(idx, nOrder, pNewDepend); FrameClientSortListEntry entry(idx, nOrder, pNewClient);
rFrames.push_back(entry); rFrames.push_back(entry);
} }
} }
...@@ -227,18 +226,18 @@ void CollectFrameAtNode( SwClient& rClnt, const SwNodeIndex& rIdx, ...@@ -227,18 +226,18 @@ void CollectFrameAtNode( SwClient& rClnt, const SwNodeIndex& rIdx,
0 != (pAnchorPos = rAnchor.GetContentAnchor()) && 0 != (pAnchorPos = rAnchor.GetContentAnchor()) &&
pAnchorPos->nNode == rIdx ) pAnchorPos->nNode == rIdx )
{ {
SwDepend* pNewDepend = new SwDepend( &rClnt, const_cast<SwFrameFormat*>(pFormat)); sw::FrameClient* pNewClient = new sw::FrameClient(const_cast<SwFrameFormat*>(pFormat));
// OD 2004-05-07 #i28701# - determine insert position for // OD 2004-05-07 #i28701# - determine insert position for
// sorted <rFrameArr> // sorted <rFrameArr>
const sal_Int32 nIndex = pAnchorPos->nContent.GetIndex(); const sal_Int32 nIndex = pAnchorPos->nContent.GetIndex();
sal_uInt32 nOrder = rAnchor.GetOrder(); sal_uInt32 nOrder = rAnchor.GetOrder();
FrameDependSortListEntry entry(nIndex, nOrder, pNewDepend); FrameClientSortListEntry entry(nIndex, nOrder, pNewClient);
rFrames.push_back(entry); rFrames.push_back(entry);
} }
} }
::std::sort(rFrames.begin(), rFrames.end(), FrameDependSortListLess()); ::std::sort(rFrames.begin(), rFrames.end(), FrameClientSortListLess());
} }
} }
...@@ -1576,19 +1575,16 @@ void SwUnoCursorHelper::SetString(SwCursor & rCursor, const OUString& rString) ...@@ -1576,19 +1575,16 @@ void SwUnoCursorHelper::SetString(SwCursor & rCursor, const OUString& rString)
pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_INSERT, NULL); pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_INSERT, NULL);
} }
class SwXParaFrameEnumeration::Impl struct SwXParaFrameEnumeration::Impl
: public SwClient
{ {
public:
// created by hasMoreElements // created by hasMoreElements
uno::Reference< text::XTextContent > m_xNextObject; uno::Reference< text::XTextContent > m_xNextObject;
FrameDependList_t m_Frames; FrameClientList_t m_Frames;
::std::shared_ptr<SwUnoCrsr> m_pUnoCursor; ::sw::UnoCursorPointer m_pUnoCursor;
explicit Impl(SwPaM const & rPaM) explicit Impl(SwPaM const & rPaM)
: m_pUnoCursor(rPaM.GetDoc()->CreateUnoCrsr(*rPaM.GetPoint(), false)) : m_pUnoCursor(rPaM.GetDoc()->CreateUnoCrsr(*rPaM.GetPoint(), false))
{ {
m_pUnoCursor->Add(this);
if (rPaM.HasMark()) if (rPaM.HasMark())
{ {
GetCursor()->SetMark(); GetCursor()->SetMark();
...@@ -1596,60 +1592,29 @@ public: ...@@ -1596,60 +1592,29 @@ public:
} }
} }
virtual ~Impl() { SwUnoCrsr* GetCursor()
if(m_pUnoCursor) { return &(*m_pUnoCursor); }
m_pUnoCursor->Remove(this); void PurgeFrameClients()
// Impl owns the cursor; delete it here: SolarMutex is locked {
} if(!m_pUnoCursor)
SwUnoCrsr * GetCursor() {
return static_cast<SwUnoCrsr*>(
GetRegisteredIn());
}
protected:
// SwClient
virtual void Modify( const SfxPoolItem *pOld, const SfxPoolItem *pNew) SAL_OVERRIDE;
virtual void SwClientNotify(const SwModify& rModify, const SfxHint& rHint) SAL_OVERRIDE;
};
struct InvalidFrameDepend {
bool operator() (::boost::shared_ptr<SwDepend> const & rEntry)
{ return !rEntry->GetRegisteredIn(); }
};
void SwXParaFrameEnumeration::Impl::Modify( const SfxPoolItem *pOld, const SfxPoolItem *pNew)
{
ClientModify(this, pOld, pNew);
if(!GetRegisteredIn())
{ {
m_Frames.clear(); m_Frames.clear();
m_xNextObject = 0; m_xNextObject = nullptr;
} }
else else
{ {
// check if any frame went away... // removing orphaned SwDepends
FrameDependList_t::iterator const iter = const auto iter = std::remove_if(m_Frames.begin(), m_Frames.end(),
::std::remove_if(m_Frames.begin(), m_Frames.end(), [] (std::shared_ptr<sw::FrameClient>& rEntry) -> bool { return !rEntry->GetRegisteredIn(); });
InvalidFrameDepend());
m_Frames.erase(iter, m_Frames.end()); m_Frames.erase(iter, m_Frames.end());
} }
}
void SwXParaFrameEnumeration::Impl::SwClientNotify(const SwModify& rModify, const SfxHint& rHint)
{
SwClient::SwClientNotify(rModify, rHint);
if(m_pUnoCursor && typeid(rHint) == typeid(sw::DocDisposingHint))
{
m_pUnoCursor->Remove(this);
m_pUnoCursor.reset();
} }
} };
static bool static bool
lcl_CreateNextObject(SwUnoCrsr& i_rUnoCrsr, lcl_CreateNextObject(SwUnoCrsr& i_rUnoCrsr,
uno::Reference<text::XTextContent> & o_rNextObject, uno::Reference<text::XTextContent> & o_rNextObject,
FrameDependList_t & i_rFrames) FrameClientList_t & i_rFrames)
{ {
if (!i_rFrames.size()) if (!i_rFrames.size())
return false; return false;
...@@ -1700,8 +1665,7 @@ lcl_CreateNextObject(SwUnoCrsr& i_rUnoCrsr, ...@@ -1700,8 +1665,7 @@ lcl_CreateNextObject(SwUnoCrsr& i_rUnoCrsr,
// Search for a FLYCNT text attribute at the cursor point and fill the frame // Search for a FLYCNT text attribute at the cursor point and fill the frame
// into the array // into the array
static void static void
lcl_FillFrame(SwClient & rEnum, SwUnoCrsr& rUnoCrsr, lcl_FillFrame(SwUnoCrsr& rUnoCrsr, FrameClientList_t & rFrames)
FrameDependList_t & rFrames)
{ {
// search for objects at the cursor - anchored at/as char // search for objects at the cursor - anchored at/as char
SwTextAttr const*const pTextAttr = (rUnoCrsr.GetNode().IsTextNode()) SwTextAttr const*const pTextAttr = (rUnoCrsr.GetNode().IsTextNode())
...@@ -1712,8 +1676,8 @@ lcl_FillFrame(SwClient & rEnum, SwUnoCrsr& rUnoCrsr, ...@@ -1712,8 +1676,8 @@ lcl_FillFrame(SwClient & rEnum, SwUnoCrsr& rUnoCrsr,
{ {
const SwFormatFlyCnt& rFlyCnt = pTextAttr->GetFlyCnt(); const SwFormatFlyCnt& rFlyCnt = pTextAttr->GetFlyCnt();
SwFrameFormat * const pFrameFormat = rFlyCnt.GetFrameFormat(); SwFrameFormat * const pFrameFormat = rFlyCnt.GetFrameFormat();
SwDepend * const pNewDepend = new SwDepend(&rEnum, pFrameFormat); sw::FrameClient* const pNewClient = new sw::FrameClient(pFrameFormat);
rFrames.push_back( ::boost::shared_ptr<SwDepend>(pNewDepend) ); rFrames.push_back( std::shared_ptr<sw::FrameClient>(pNewClient) );
} }
} }
...@@ -1724,18 +1688,18 @@ SwXParaFrameEnumeration::SwXParaFrameEnumeration( ...@@ -1724,18 +1688,18 @@ SwXParaFrameEnumeration::SwXParaFrameEnumeration(
{ {
if (PARAFRAME_PORTION_PARAGRAPH == eParaFrameMode) if (PARAFRAME_PORTION_PARAGRAPH == eParaFrameMode)
{ {
FrameDependSortList_t frames; FrameClientSortList_t frames;
::CollectFrameAtNode(*m_pImpl.get(), rPaM.GetPoint()->nNode, ::CollectFrameAtNode(rPaM.GetPoint()->nNode,
frames, false); frames, false);
::std::transform(frames.begin(), frames.end(), ::std::transform(frames.begin(), frames.end(),
::std::back_inserter(m_pImpl->m_Frames), ::std::back_inserter(m_pImpl->m_Frames),
::boost::bind(&FrameDependSortListEntry::pFrameDepend, _1)); ::boost::bind(&FrameClientSortListEntry::pFrameClient, _1));
} }
else if (pFormat) else if (pFormat)
{ {
// create SwDepend for frame and insert into array // create SwDepend for frame and insert into array
SwDepend *const pNewDepend = new SwDepend(m_pImpl.get(), pFormat); sw::FrameClient* const pNewClient = new sw::FrameClient(pFormat);
m_pImpl->m_Frames.push_back(::boost::shared_ptr<SwDepend>(pNewDepend)); m_pImpl->m_Frames.push_back(std::shared_ptr<sw::FrameClient>(pNewClient));
} }
else if ((PARAFRAME_PORTION_CHAR == eParaFrameMode) || else if ((PARAFRAME_PORTION_CHAR == eParaFrameMode) ||
(PARAFRAME_PORTION_TEXTRANGE == eParaFrameMode)) (PARAFRAME_PORTION_TEXTRANGE == eParaFrameMode))
...@@ -1750,12 +1714,12 @@ SwXParaFrameEnumeration::SwXParaFrameEnumeration( ...@@ -1750,12 +1714,12 @@ SwXParaFrameEnumeration::SwXParaFrameEnumeration(
SwFrameFormat *const pFrameFormat = const_cast<SwFrameFormat*>(&((*aIter)->GetFormat())); SwFrameFormat *const pFrameFormat = const_cast<SwFrameFormat*>(&((*aIter)->GetFormat()));
// create SwDepend for frame and insert into array // create SwDepend for frame and insert into array
SwDepend *const pNewDepend = new SwDepend(m_pImpl.get(), pFrameFormat); sw::FrameClient* const pNewClient = new sw::FrameClient(pFrameFormat);
m_pImpl->m_Frames.push_back(::boost::shared_ptr<SwDepend>(pNewDepend)); m_pImpl->m_Frames.push_back(std::shared_ptr<sw::FrameClient>(pNewClient));
} }
} }
lcl_FillFrame(*m_pImpl.get(), *m_pImpl->GetCursor(), m_pImpl->m_Frames); lcl_FillFrame(*m_pImpl->GetCursor(), m_pImpl->m_Frames);
} }
} }
...@@ -1767,10 +1731,9 @@ sal_Bool SAL_CALL ...@@ -1767,10 +1731,9 @@ sal_Bool SAL_CALL
SwXParaFrameEnumeration::hasMoreElements() throw (uno::RuntimeException, std::exception) SwXParaFrameEnumeration::hasMoreElements() throw (uno::RuntimeException, std::exception)
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
if (!m_pImpl->GetCursor()) if (!m_pImpl->GetCursor())
throw uno::RuntimeException(); throw uno::RuntimeException();
m_pImpl->PurgeFrameClients();
return m_pImpl->m_xNextObject.is() || return m_pImpl->m_xNextObject.is() ||
lcl_CreateNextObject(*m_pImpl->GetCursor(),m_pImpl->m_xNextObject, m_pImpl->m_Frames); lcl_CreateNextObject(*m_pImpl->GetCursor(),m_pImpl->m_xNextObject, m_pImpl->m_Frames);
} }
...@@ -1780,12 +1743,9 @@ throw (container::NoSuchElementException, ...@@ -1780,12 +1743,9 @@ throw (container::NoSuchElementException,
lang::WrappedTargetException, uno::RuntimeException, std::exception) lang::WrappedTargetException, uno::RuntimeException, std::exception)
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
if (!m_pImpl->GetCursor()) if (!m_pImpl->GetCursor())
{
throw uno::RuntimeException(); throw uno::RuntimeException();
} m_pImpl->PurgeFrameClients();
if (!m_pImpl->m_xNextObject.is() && m_pImpl->m_Frames.size()) if (!m_pImpl->m_xNextObject.is() && m_pImpl->m_Frames.size())
{ {
lcl_CreateNextObject(*m_pImpl->GetCursor(), lcl_CreateNextObject(*m_pImpl->GetCursor(),
......
...@@ -80,7 +80,7 @@ static void lcl_CreatePortions( ...@@ -80,7 +80,7 @@ static void lcl_CreatePortions(
TextRangeList_t & i_rPortions, TextRangeList_t & i_rPortions,
uno::Reference< text::XText > const& i_xParentText, uno::Reference< text::XText > const& i_xParentText,
SwUnoCrsr* pUnoCrsr, SwUnoCrsr* pUnoCrsr,
FrameDependSortList_t & i_rFrames, FrameClientSortList_t & i_rFrames,
const sal_Int32 i_nStartPos, const sal_Int32 i_nEndPos ); const sal_Int32 i_nStartPos, const sal_Int32 i_nEndPos );
namespace namespace
...@@ -371,8 +371,8 @@ SwXTextPortionEnumeration::SwXTextPortionEnumeration( ...@@ -371,8 +371,8 @@ SwXTextPortionEnumeration::SwXTextPortionEnumeration(
"start or end value invalid!"); "start or end value invalid!");
// find all frames, graphics and OLEs that are bound AT character in para // find all frames, graphics and OLEs that are bound AT character in para
FrameDependSortList_t frames; FrameClientSortList_t frames;
::CollectFrameAtNode(*this, m_pUnoCrsr->GetPoint()->nNode, frames, true); ::CollectFrameAtNode(m_pUnoCrsr->GetPoint()->nNode, frames, true);
lcl_CreatePortions(m_Portions, xParentText, m_pUnoCrsr.get(), frames, nStart, nEnd); lcl_CreatePortions(m_Portions, xParentText, m_pUnoCrsr.get(), frames, nStart, nEnd);
} }
...@@ -1187,7 +1187,7 @@ static sal_Int32 lcl_ExportFrames( ...@@ -1187,7 +1187,7 @@ static sal_Int32 lcl_ExportFrames(
TextRangeList_t & rPortions, TextRangeList_t & rPortions,
Reference<XText> const & i_xParent, Reference<XText> const & i_xParent,
SwUnoCrsr * const i_pUnoCrsr, SwUnoCrsr * const i_pUnoCrsr,
FrameDependSortList_t & i_rFrames, FrameClientSortList_t & i_rFrames,
sal_Int32 const i_nCurrentIndex) sal_Int32 const i_nCurrentIndex)
{ {
// Ignore frames which are not exported, as we are exporting a selection // Ignore frames which are not exported, as we are exporting a selection
...@@ -1200,7 +1200,7 @@ static sal_Int32 lcl_ExportFrames( ...@@ -1200,7 +1200,7 @@ static sal_Int32 lcl_ExportFrames(
// do not check for i_nEnd here; this is done implicity by lcl_MoveCursor // do not check for i_nEnd here; this is done implicity by lcl_MoveCursor
{ {
const SwModify * const pFrame = const SwModify * const pFrame =
i_rFrames.front().pFrameDepend->GetRegisteredIn(); i_rFrames.front().pFrameClient->GetRegisteredIn();
if (pFrame) // Frame could be disposed if (pFrame) // Frame could be disposed
{ {
SwXTextPortion* pPortion = new SwXTextPortion(i_pUnoCrsr, i_xParent, SwXTextPortion* pPortion = new SwXTextPortion(i_pUnoCrsr, i_xParent,
...@@ -1243,7 +1243,7 @@ static void lcl_CreatePortions( ...@@ -1243,7 +1243,7 @@ static void lcl_CreatePortions(
TextRangeList_t & i_rPortions, TextRangeList_t & i_rPortions,
uno::Reference< text::XText > const & i_xParentText, uno::Reference< text::XText > const & i_xParentText,
SwUnoCrsr * const pUnoCrsr, SwUnoCrsr * const pUnoCrsr,
FrameDependSortList_t & i_rFrames, FrameClientSortList_t & i_rFrames,
const sal_Int32 i_nStartPos, const sal_Int32 i_nStartPos,
const sal_Int32 i_nEndPos ) const sal_Int32 i_nEndPos )
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment