summaryrefslogtreecommitdiff
path: root/sc/inc/postit.hxx
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2021-05-27 10:27:46 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-08-29 13:44:02 +0200
commit8611f6e259b807b4f19c8dc0eab86ca648891ce3 (patch)
treefa2b0e463aafb51df754768f916ca9104969a557 /sc/inc/postit.hxx
parent25a997c15d39fb30676a375df8ea4ce1ed2e1acd (diff)
ref-count SdrObject
Which means we can get rid of the majestic hack of ScCaptionPtr Previously, SdrObject was manually managed, and the ownership passed around in very complicated fashion. Notes: (*) SvxShape has a strong reference to SdrObject, where previously it had a weak reference. It is now strong since otherwise the SdrObject will go away very eagerly. (*) SdrObject still has a weak reference to SvxShape (*) In the existing places that an SdrObject is being deleted, we now just clear the reference (*) instead of SwVirtFlyDrawObj removing itself from the page that contains inside it's destructor, make the call site do the removing from the page. (*) Needed to take the SolarMutex in UndoManagerHelper_Impl::impl_clear because this can be called from UNO (e.g. sfx2_complex JUnit test) and the SdrObjects need the SolarMutex when destructing. (*) handle a tricky situation with SwDrawVirtObj in the SwDrawModel destructor because the existing code wants mpDrawObj in SwAnchoredObject to be sometimes owning, sometimes not, which results in a cycle with the new code. Change-Id: I4d79df1660e386388e5d51030653755bca02a163 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138837 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc/inc/postit.hxx')
-rw-r--r--sc/inc/postit.hxx109
1 files changed, 3 insertions, 106 deletions
diff --git a/sc/inc/postit.hxx b/sc/inc/postit.hxx
index 8a94402b88ad..36473542e1df 100644
--- a/sc/inc/postit.hxx
+++ b/sc/inc/postit.hxx
@@ -21,6 +21,7 @@
#include <rtl/ustring.hxx>
#include <svl/itemset.hxx>
+#include <rtl/ref.hxx>
#include "address.hxx"
#include "scdllapi.h"
@@ -36,110 +37,6 @@ class ScDocument;
namespace tools { class Rectangle; }
struct ScCaptionInitData;
-/** Some desperate attempt to fight against the caption object ownership mess,
- to which none of shared/weak/plain pointer is a cure.
- */
-class ScCaptionPtr
-{
-public:
- ScCaptionPtr();
- explicit ScCaptionPtr( SdrCaptionObj* p );
- ScCaptionPtr( const ScCaptionPtr& r );
- ScCaptionPtr(ScCaptionPtr&& r) noexcept;
- ~ScCaptionPtr();
-
- ScCaptionPtr& operator=( const ScCaptionPtr& r );
- ScCaptionPtr& operator=(ScCaptionPtr&& r) noexcept;
- explicit operator bool() const { return mpCaption != nullptr; }
- const SdrCaptionObj* get() const { return mpCaption; }
- SdrCaptionObj* get() { return mpCaption; }
- const SdrCaptionObj* operator->() const { return mpCaption; }
- SdrCaptionObj* operator->() { return mpCaption; }
- const SdrCaptionObj& operator*() const { return *mpCaption; }
- SdrCaptionObj& operator*() { return *mpCaption; }
-
- // Does not default to nullptr to make it visually obvious where such is used.
- void reset( SdrCaptionObj* p );
-
- /** Insert to draw page. The caption object is owned by the draw page then.
- */
- void insertToDrawPage( SdrPage& rDrawPage );
-
- /** Remove from draw page. The caption object is not owned anymore by the
- draw page then.
- */
- void removeFromDrawPage( SdrPage& rDrawPage );
-
- /** Remove from draw page and free caption object if no Undo recording.
- */
- void removeFromDrawPageAndFree( bool bIgnoreUndo = false );
-
- /** Release all management of the SdrCaptionObj* in all instances of this
- list and dissolve. The SdrCaptionObj pointer returned is ready to be
- managed elsewhere.
- */
- SdrCaptionObj* release();
-
- /** Forget the SdrCaptionObj pointer in this one instance.
- Decrements a use count but does not destroy the object, it's up to the
- caller to manage this mess...
- */
- void forget();
-
- /** Flag that this instance is in Undo, so drawing layer owns it. */
- void setNotOwner();
-
- oslInterlockedCount getRefs() const;
-
-private:
-
- struct Head
- {
- ScCaptionPtr* mpFirst; ///< first in list
- oslInterlockedCount mnRefs; ///< use count
-
- Head() = delete;
- explicit Head( ScCaptionPtr* );
- };
-
- Head* mpHead; ///< points to the "master" entry
- mutable ScCaptionPtr* mpNext; ///< next in list
- SdrCaptionObj* mpCaption; ///< the caption object, managed by head master
- bool mbNotOwner; ///< whether this caption object is owned by something else, e.g. held in Undo
- /* TODO: can that be moved to Head?
- * It's unclear when to reset, so
- * each instance has its own flag.
- * The last reference count
- * decrement automatically has the
- * then current state available.
- * */
-
- void newHead(); //< Allocate a new Head and init.
- void incRef() const;
- bool decRef() const; //< @returns <TRUE/> if the last reference was decremented.
- void decRefAndDestroy(); //< Destroys caption object if the last reference was decremented.
-
- /** Remove from current list and close gap.
-
- Usually there are only very few instances, so maintaining a doubly
- linked list isn't worth memory/performance wise and a simple walk does
- it.
- */
- void removeFromList();
-
- /** Replace this instance with pNew in a list, if any.
-
- Used by move-ctor and move assignment operator.
- */
- void replaceInList(ScCaptionPtr* pNew) noexcept;
-
- /** Dissolve list when the caption object is released or gone. */
- void dissolve();
-
- /** Just clear everything, while dissolving the list. */
- void clear();
-};
-
/** Internal data for a cell annotation. */
struct ScNoteData
{
@@ -148,7 +45,7 @@ struct ScNoteData
OUString maDate; /// Creation date of the note.
OUString maAuthor; /// Author of the note.
ScCaptionInitDataRef mxInitData; /// Initial data for invisible notes without SdrObject.
- ScCaptionPtr mxCaption; /// Drawing object representing the cell note.
+ rtl::Reference<SdrCaptionObj> mxCaption; /// Drawing object representing the cell note.
bool mbShown; /// True = note is visible.
explicit ScNoteData( bool bShown = false );
@@ -282,7 +179,7 @@ class SC_DLLPUBLIC ScNoteUtil
public:
/** Creates and returns a caption object for a temporary caption. */
- static ScCaptionPtr CreateTempCaption( ScDocument& rDoc, const ScAddress& rPos,
+ static rtl::Reference<SdrCaptionObj> CreateTempCaption( ScDocument& rDoc, const ScAddress& rPos,
SdrPage& rDrawPage, std::u16string_view rUserText,
const tools::Rectangle& rVisRect, bool bTailFront );