summaryrefslogtreecommitdiff
path: root/sw/inc/unocrsr.hxx
diff options
context:
space:
mode:
authorBjoern Michaelsen <bjoern.michaelsen@canonical.com>2015-05-30 23:35:17 +0200
committerBjoern Michaelsen <bjoern.michaelsen@canonical.com>2015-06-09 12:53:24 +0200
commit3e01e7d5720c9b0bee321add8b987ac807f91573 (patch)
tree6b35f806d54218f48d8ebf03406137dcda417d0c /sw/inc/unocrsr.hxx
parent623359af236ab8497d4fac34e112a8b9b7b291f2 (diff)
add smart pointer for managing SwUnoCrsrs
Change-Id: I9db71fb4be78b5d6fda64217287efea6abd7d771
Diffstat (limited to 'sw/inc/unocrsr.hxx')
-rw-r--r--sw/inc/unocrsr.hxx41
1 files changed, 41 insertions, 0 deletions
diff --git a/sw/inc/unocrsr.hxx b/sw/inc/unocrsr.hxx
index bfc8ebc5cfc4..4d2c38010f26 100644
--- a/sw/inc/unocrsr.hxx
+++ b/sw/inc/unocrsr.hxx
@@ -102,6 +102,47 @@ public:
const SwCursor& GetSelRing() const { return m_aTableSel; }
};
+namespace sw
+{
+ class UnoCursorPointer : public SwClient
+ {
+ public:
+ UnoCursorPointer(std::shared_ptr<SwUnoCrsr> pCursor)
+ : m_pCursor(pCursor)
+ {
+ m_pCursor->Add(this);
+ }
+ virtual ~UnoCursorPointer() SAL_OVERRIDE
+ {
+ if(m_pCursor)
+ m_pCursor->Remove(this);
+ }
+ virtual void SwClientNotify(const SwModify& rModify, const SfxHint& rHint) SAL_OVERRIDE
+ {
+ SwClient::SwClientNotify(rModify, rHint);
+ if(m_pCursor && typeid(rHint) == typeid(sw::DocDisposingHint))
+ m_pCursor->Remove(this);
+ if(!GetRegisteredIn())
+ m_pCursor.reset();
+ };
+ SwUnoCrsr& operator*() const
+ { return *m_pCursor.get(); }
+ SwUnoCrsr* operator->() const
+ { return m_pCursor.get(); }
+ explicit operator bool() const
+ { return static_cast<bool>(m_pCursor); }
+ void reset(std::shared_ptr<SwUnoCrsr> pNew)
+ {
+ if(pNew)
+ pNew->Add(this);
+ else if(m_pCursor)
+ m_pCursor->Remove(this);
+ m_pCursor = pNew;
+ }
+ private:
+ std::shared_ptr<SwUnoCrsr> m_pCursor;
+ };
+}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */