compilerplugins/clang/unusedmethods.results  |    2 --
 svl/source/items/poolitem.cxx                |    1 -
 sw/inc/IDocumentFieldsAccess.hxx             |    2 +-
 sw/inc/SwUndoField.hxx                       |    4 ++--
 sw/inc/hintids.hxx                           |    3 +--
 sw/inc/hints.hxx                             |   15 ---------------
 sw/source/core/attr/hints.cxx                |    7 -------
 sw/source/core/doc/DocumentFieldsManager.cxx |    2 +-
 sw/source/core/edit/edfld.cxx                |   25 ++++++++++++++++---------
 sw/source/core/inc/DocumentFieldsManager.hxx |    2 +-
 sw/source/core/undo/SwUndoField.cxx          |    2 +-
 11 files changed, 23 insertions(+), 42 deletions(-)

New commits:
commit 4f4f2f0502881fc1a26c600e84c94c62808169eb
Author:     Bjoern Michaelsen <bjoern.michael...@libreoffice.org>
AuthorDate: Tue Feb 14 23:38:29 2023 +0100
Commit:     Bjoern Michaelsen <bjoern.michael...@libreoffice.org>
CommitDate: Wed Feb 15 18:56:41 2023 +0000

    clean up SwRefMarkFieldUpdate a bit
    
    - remove SwRefMarkFieldUpdate:
      * it has only one unused field
      * replace with a plain SwPtrMsgPoolItem
    - hint constness:
      * SwUndoFieldFromDoc: make ctor arg hint const
      * DocumentFieldsManager: make UpdateField arg hint const
      * however, seeing this hint is:
        a/ constructed on the stack, but
        b/ stored as pointer in undo
        likely it would be best to remove it altogether. For now, make it at
        least static, so that there is no use after free.
    
    Change-Id: Ica51a2a2ce19e1938c3a367e9b4a9e01bbb75374
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147030
    Tested-by: Jenkins
    Reviewed-by: Bjoern Michaelsen <bjoern.michael...@libreoffice.org>

diff --git a/compilerplugins/clang/unusedmethods.results 
b/compilerplugins/clang/unusedmethods.results
index 1c4f2a4119dd..bdac66f71d72 100644
--- a/compilerplugins/clang/unusedmethods.results
+++ b/compilerplugins/clang/unusedmethods.results
@@ -1762,8 +1762,6 @@ include/svl/typedwhich.hxx:31
      TypedWhichId::TypedWhichId(TypedWhichId<type-parameter-?-?>,typename 
enable_if<std::is_base_of_v<SwPtrItem, derived_type>, int>::type)
 include/svl/typedwhich.hxx:31
      TypedWhichId::TypedWhichId(TypedWhichId<type-parameter-?-?>,typename 
enable_if<std::is_base_of_v<SwPtrMsgPoolItem, derived_type>, int>::type)
-include/svl/typedwhich.hxx:31
-     TypedWhichId::TypedWhichId(TypedWhichId<type-parameter-?-?>,typename 
enable_if<std::is_base_of_v<SwRefMarkFieldUpdate, derived_type>, int>::type)
 include/svl/typedwhich.hxx:31
      TypedWhichId::TypedWhichId(TypedWhichId<type-parameter-?-?>,typename 
enable_if<std::is_base_of_v<SwRegisterItem, derived_type>, int>::type)
 include/svl/typedwhich.hxx:31
diff --git a/svl/source/items/poolitem.cxx b/svl/source/items/poolitem.cxx
index 225678340a1c..cac0e80a3a6f 100644
--- a/svl/source/items/poolitem.cxx
+++ b/svl/source/items/poolitem.cxx
@@ -435,7 +435,6 @@
 //     class SwPtrMsgPoolItem : public SwMsgPoolItem
 //     class SwFormatChg: public SwMsgPoolItem
 //     class SwUpdateAttr : public SwMsgPoolItem
-//     class SwRefMarkFieldUpdate : public SwMsgPoolItem
 //     class SwDocPosUpdate : public SwMsgPoolItem
 //     class SwTableFormulaUpdate : public SwMsgPoolItem
 //     class SwAutoFormatGetDocNode: public SwMsgPoolItem
diff --git a/sw/inc/IDocumentFieldsAccess.hxx b/sw/inc/IDocumentFieldsAccess.hxx
index 237af065ae7c..ee3e2536b921 100644
--- a/sw/inc/IDocumentFieldsAccess.hxx
+++ b/sw/inc/IDocumentFieldsAccess.hxx
@@ -90,7 +90,7 @@ namespace com::sun::star::uno { class Any; }
         @retval true             update was successful
         @retval false            else
     */
-    virtual bool UpdateField(SwTextField * rDstFormatField, SwField & 
rSrcField, SwMsgPoolItem * pMsgHint, bool bUpdateTableFields) = 0;
+    virtual bool UpdateField(SwTextField * rDstFormatField, SwField & 
rSrcField, const SwMsgPoolItem * pMsgHint, bool bUpdateTableFields) = 0;
 
     virtual void UpdateRefFields() = 0;
 
diff --git a/sw/inc/SwUndoField.hxx b/sw/inc/SwUndoField.hxx
index 5c12c50356ce..95cb676c5de2 100644
--- a/sw/inc/SwUndoField.hxx
+++ b/sw/inc/SwUndoField.hxx
@@ -44,7 +44,7 @@ public:
 class SwUndoFieldFromDoc final : public SwUndoField
 {
     std::unique_ptr<SwField> m_pOldField, m_pNewField;
-    SwMsgPoolItem * m_pHint;
+    const SwMsgPoolItem * m_pHint;
     bool m_bUpdate;
 
     void DoImpl();
@@ -52,7 +52,7 @@ class SwUndoFieldFromDoc final : public SwUndoField
 public:
     SwUndoFieldFromDoc(const SwPosition & rPos, const SwField & aOldField,
                        const SwField & aNewField,
-                       SwMsgPoolItem * pHint, bool bUpdate);
+                       const SwMsgPoolItem * pHint, bool bUpdate);
 
     virtual ~SwUndoFieldFromDoc() override;
 
diff --git a/sw/inc/hintids.hxx b/sw/inc/hintids.hxx
index 891815c3cd1a..4766d0799375 100644
--- a/sw/inc/hintids.hxx
+++ b/sw/inc/hintids.hxx
@@ -134,7 +134,6 @@ class SwTableBoxNumFormat;
 class SwTextGridItem;
 class SwTransparencyGrf;
 class SwFormatRuby;
-class SwRefMarkFieldUpdate;
 class SwTableFormulaUpdate;
 class SwAutoFormatGetDocNode;
 class SwVirtPageNumInfo;
@@ -423,7 +422,7 @@ constexpr TypedWhichId<SwPtrMsgPoolItem> 
RES_OBJECTDYING(RES_MSG_BEGIN); // 161
 constexpr TypedWhichId<SwFormatChg> RES_FMT_CHG(162);
 constexpr TypedWhichId<SwAttrSetChg> RES_ATTRSET_CHG(163);
 constexpr TypedWhichId<SwUpdateAttr> RES_UPDATE_ATTR(167);
-constexpr TypedWhichId<SwRefMarkFieldUpdate> RES_REFMARKFLD_UPDATE(168);
+constexpr TypedWhichId<SwPtrMsgPoolItem> RES_REFMARKFLD_UPDATE(168);
 constexpr TypedWhichId<SwDocPosUpdate> RES_DOCPOS_UPDATE(169);
 constexpr TypedWhichId<SwTableFormulaUpdate> RES_TABLEFML_UPDATE(170);
 constexpr TypedWhichId<SwMsgPoolItem> RES_UPDATEDDETBL(171);
diff --git a/sw/inc/hints.hxx b/sw/inc/hints.hxx
index 7c37af060f68..ea856ae5cbaf 100644
--- a/sw/inc/hints.hxx
+++ b/sw/inc/hints.hxx
@@ -255,21 +255,6 @@ public:
     }
 };
 
-/** SwRefMarkFieldUpdate is sent when the referencemarks should be updated.
-     To determine Page- / chapternumbers the current frame has to be asked.
-      For this we need the current outputdevice */
-class SwRefMarkFieldUpdate final : public SwMsgPoolItem
-{
-    VclPtr<OutputDevice> pOut; ///< pointer to the current output device
-public:
-    /** Is sent if reference marks should be updated.
-
-        To get the page/chapter number, the frame has to be asked. For that we 
need
-        the current OutputDevice.
-    */
-    SwRefMarkFieldUpdate( OutputDevice* );
-};
-
 /** SwDocPosUpdate is sent to signal that only the frames from or to a 
specified document-global position
    have to be updated. At the moment this is only needed when updating 
pagenumber fields. */
 class SwDocPosUpdate final : public SwMsgPoolItem
diff --git a/sw/source/core/attr/hints.cxx b/sw/source/core/attr/hints.cxx
index 3257d5736900..a755cc47b7e2 100644
--- a/sw/source/core/attr/hints.cxx
+++ b/sw/source/core/attr/hints.cxx
@@ -81,13 +81,6 @@ SwUpdateAttr::SwUpdateAttr( sal_Int32 nS, sal_Int32 nE, 
sal_uInt16 nW, std::vect
 {
 }
 
-SwRefMarkFieldUpdate::SwRefMarkFieldUpdate( OutputDevice* pOutput )
-    : SwMsgPoolItem( RES_REFMARKFLD_UPDATE ),
-    pOut( pOutput )
-{
-    OSL_ENSURE( pOut, "No OutputDevice pointer" );
-}
-
 SwDocPosUpdate::SwDocPosUpdate( const SwTwips nDcPos )
     : SwMsgPoolItem( RES_DOCPOS_UPDATE ), nDocPos(nDcPos)
 {
diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx 
b/sw/source/core/doc/DocumentFieldsManager.cxx
index fc604900a139..0c5bcfb375d6 100644
--- a/sw/source/core/doc/DocumentFieldsManager.cxx
+++ b/sw/source/core/doc/DocumentFieldsManager.cxx
@@ -492,7 +492,7 @@ void DocumentFieldsManager::PutValueToField(const 
SwPosition & rPos,
 }
 
 bool DocumentFieldsManager::UpdateField(SwTextField * pDstTextField, SwField & 
rSrcField,
-                      SwMsgPoolItem * pMsgHint,
+                      const SwMsgPoolItem * pMsgHint,
                       bool bUpdateFields)
 {
     OSL_ENSURE(pDstTextField, "no field to update!");
diff --git a/sw/source/core/edit/edfld.cxx b/sw/source/core/edit/edfld.cxx
index 79d9aedfc0a8..1273309b5a8e 100644
--- a/sw/source/core/edit/edfld.cxx
+++ b/sw/source/core/edit/edfld.cxx
@@ -203,15 +203,13 @@ void SwEditShell::UpdateOneField(SwField &rField)
     StartAllAction();
     {
         // If there are no selections so take the value of the current cursor 
position.
-        SwMsgPoolItem* pMsgHint = nullptr;
-        SwRefMarkFieldUpdate aRefMkHt( GetOut() );
-        SwFieldIds nFieldWhich = rField.GetTyp()->Which();
-        if( SwFieldIds::GetRef == nFieldWhich )
-            pMsgHint = &aRefMkHt;
-
         SwPaM* pCursor = GetCursor();
         SwTextField *pTextField;
         SwFormatField *pFormatField;
+        static const SwMsgPoolItem aRefMarkHint(RES_REFMARKFLD_UPDATE);
+        const SwMsgPoolItem* pRefMarkHint = SwFieldIds::GetRef == 
rField.GetTyp()->Which() // is this conditional even needed?
+            ? &aRefMarkHint
+            : nullptr;
 
         if ( !pCursor->IsMultiSelection() && !pCursor->HasMark())
         {
@@ -221,7 +219,13 @@ void SwEditShell::UpdateOneField(SwField &rField)
                 pTextField = lcl_FindInputField( GetDoc(), rField);
 
             if (pTextField != nullptr)
-                GetDoc()->getIDocumentFieldsAccess().UpdateField(pTextField, 
rField, pMsgHint, true);
+            {
+                GetDoc()->getIDocumentFieldsAccess().UpdateField(
+                    pTextField,
+                    rField,
+                    pRefMarkHint,
+                    true);
+            }
         }
 
         // bOkay (instead of return because of EndAllAction) becomes false,
@@ -271,8 +275,11 @@ void SwEditShell::UpdateOneField(SwField &rField)
                             rField.GetTyp()->Which() )
                             bOkay = false;
 
-                        bTableSelBreak = 
GetDoc()->getIDocumentFieldsAccess().UpdateField(pTextField, rField,
-                                                           pMsgHint, false);
+                        bTableSelBreak = 
GetDoc()->getIDocumentFieldsAccess().UpdateField(
+                            pTextField,
+                            rField,
+                            pRefMarkHint,
+                            false);
                     }
                     // The search area is reduced by the found area:
                     pCurStt->AdjustContent(+1);
diff --git a/sw/source/core/inc/DocumentFieldsManager.hxx 
b/sw/source/core/inc/DocumentFieldsManager.hxx
index 43b15e31feff..2b661604b8de 100644
--- a/sw/source/core/inc/DocumentFieldsManager.hxx
+++ b/sw/source/core/inc/DocumentFieldsManager.hxx
@@ -43,7 +43,7 @@ public:
     virtual void UpdateFields(bool bCloseDB) override;
     virtual void InsDeletedFieldType(SwFieldType &) override;
     virtual void PutValueToField(const SwPosition & rPos, const css::uno::Any& 
rVal, sal_uInt16 nWhich) override;
-    virtual bool UpdateField(SwTextField * rDstFormatField, SwField & 
rSrcField, SwMsgPoolItem * pMsgHint, bool bUpdateTableFields) override;
+    virtual bool UpdateField(SwTextField * rDstFormatField, SwField & 
rSrcField, const SwMsgPoolItem * pMsgHint, bool bUpdateTableFields) override;
     virtual void UpdateRefFields() override;
     virtual void UpdateTableFields(SfxPoolItem* pHt) override;
     virtual void UpdateExpFields(SwTextField* pField, bool bUpdateRefFields) 
override;
diff --git a/sw/source/core/undo/SwUndoField.cxx 
b/sw/source/core/undo/SwUndoField.cxx
index f7c23e3cbe30..e4dfcf7bd8f1 100644
--- a/sw/source/core/undo/SwUndoField.cxx
+++ b/sw/source/core/undo/SwUndoField.cxx
@@ -57,7 +57,7 @@ SwPosition SwUndoField::GetPosition()
 SwUndoFieldFromDoc::SwUndoFieldFromDoc(const SwPosition & rPos,
                          const SwField & rOldField,
                          const SwField & rNewField,
-                         SwMsgPoolItem * _pHint, bool _bUpdate)
+                         const SwMsgPoolItem * _pHint, bool _bUpdate)
     : SwUndoField(rPos)
     , m_pOldField(rOldField.CopyField())
     , m_pNewField(rNewField.CopyField())

Reply via email to