include/svl/hint.hxx                 |    5 +
 svx/source/form/fmshell.cxx          |    2 
 sw/inc/fmtfld.hxx                    |    3 
 sw/source/uibase/docvw/PostItMgr.cxx |    7 -
 sw/source/uibase/uiview/view.cxx     |  164 +++++++++++++++++------------------
 5 files changed, 93 insertions(+), 88 deletions(-)

New commits:
commit 25caf7dfd01534f9cdb044676c05c798fac96917
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Mon May 27 21:13:53 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue May 28 09:58:48 2024 +0200

    avoid dynamic_cast in PostItMgr
    
    Change-Id: Ieb571b8f39de1ffbc5cf1ce257204dca9bdb649e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168121
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/include/svl/hint.hxx b/include/svl/hint.hxx
index f93c9196c9a2..98c37e4b7baa 100644
--- a/include/svl/hint.hxx
+++ b/include/svl/hint.hxx
@@ -157,6 +157,7 @@ enum class SfxHintId {
     SwTableHeadingChange,
     SwVirtPageNumHint,
     SwAutoFormatUsedHint,
+    SwFormatField,
 
     ThisIsAnSdrHint,
     ThisIsAnSfxEventHint
@@ -246,6 +247,7 @@ inline std::basic_ostream<charT, traits> & operator <<(
         return stream << "SwNavigatorSelectOutlinesWithSelections";
     case SfxHintId::SwCollectTextMarks: return stream << "SwCollectTextMarks";
     case SfxHintId::SwCollectTextTOXMarksForLayout: return stream << 
"SwCollectTextTOXMarksForLayout";
+    case SfxHintId::SwFormatField: return stream << "SwFormatField";
     case SfxHintId::ThisIsAnSdrHint: return stream << "SdrHint";
     default: return stream << "unk(" << std::to_string(int(id)) << ")";
     }
diff --git a/sw/inc/fmtfld.hxx b/sw/inc/fmtfld.hxx
index c9f7d756c0b9..5df4f0beaf57 100644
--- a/sw/inc/fmtfld.hxx
+++ b/sw/inc/fmtfld.hxx
@@ -196,7 +196,8 @@ class SW_DLLPUBLIC SwFormatFieldHint final : public SfxHint
 
 public:
     SwFormatFieldHint( const SwFormatField* pField, SwFormatFieldHintWhich 
nWhich, const SwView* pView = nullptr)
-        : m_pField(pField)
+        : SfxHint(SfxHintId::SwFormatField)
+        , m_pField(pField)
         , m_nWhich(nWhich)
         , m_pView(pView)
     {}
diff --git a/sw/source/uibase/docvw/PostItMgr.cxx 
b/sw/source/uibase/docvw/PostItMgr.cxx
index 95eaea2a5557..8a2ab40317ed 100644
--- a/sw/source/uibase/docvw/PostItMgr.cxx
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
@@ -355,8 +355,9 @@ void SwPostItMgr::Notify( SfxBroadcaster& rBC, const 
SfxHint& rHint )
             }
         }
     }
-    else if ( const SwFormatFieldHint * pFormatHint = dynamic_cast<const 
SwFormatFieldHint*>(&rHint) )
+    else if ( rHint.GetId() == SfxHintId::SwFormatField )
     {
+        const SwFormatFieldHint * pFormatHint = static_cast<const 
SwFormatFieldHint*>(&rHint);
         SwFormatField* pField = const_cast <SwFormatField*>( 
pFormatHint->GetField() );
         switch ( pFormatHint->Which() )
         {
@@ -1470,9 +1471,9 @@ class FieldDocWatchingStack : public SfxListener
 
     virtual void Notify(SfxBroadcaster&, const SfxHint& rHint) override
     {
-        const SwFormatFieldHint* pHint = dynamic_cast<const 
SwFormatFieldHint*>(&rHint);
-        if (!pHint)
+        if ( rHint.GetId() != SfxHintId::SwFormatField )
             return;
+        const SwFormatFieldHint* pHint = static_cast<const 
SwFormatFieldHint*>(&rHint);
 
         bool bAllInvalidated = false;
         if (pHint->Which() == SwFormatFieldHintWhich::REMOVED)
commit e7fcca88ce9acc78a402c5929d063e3cfc573be4
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Mon May 27 19:03:28 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue May 28 09:58:41 2024 +0200

    avoid dynamic_cast in SwView::Notify
    
    Change-Id: Id2b8f0f85165d442a5e3a54ee2e3b433f53b3613
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168120
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Tested-by: Jenkins

diff --git a/include/svl/hint.hxx b/include/svl/hint.hxx
index e8971934c7d4..f93c9196c9a2 100644
--- a/include/svl/hint.hxx
+++ b/include/svl/hint.hxx
@@ -61,6 +61,8 @@ enum class SfxHintId {
     BasicStart,
     BasicStop,
 
+// SVX
+    FmDesignModeChanged,
 // SVX edit source
     EditSourceParasMoved,
     EditSourceSelectionChanged,
@@ -195,6 +197,7 @@ inline std::basic_ostream<charT, traits> & operator <<(
     case SfxHintId::BasicInfoWanted: return stream << "BasicInfoWanted";
     case SfxHintId::BasicStart: return stream << "BasicStart";
     case SfxHintId::BasicStop: return stream << "BasicStop";
+    case SfxHintId::FmDesignModeChanged: return stream << 
"FmDesignModeChanged";
     case SfxHintId::EditSourceParasMoved: return stream << 
"EditSourceParasMoved";
     case SfxHintId::EditSourceSelectionChanged: return stream << 
"EditSourceSelectionChanged";
     case SfxHintId::ScDataChanged: return stream << "ScDataChanged";
diff --git a/svx/source/form/fmshell.cxx b/svx/source/form/fmshell.cxx
index 10616b67d3d0..2cedf38ba9b1 100644
--- a/svx/source/form/fmshell.cxx
+++ b/svx/source/form/fmshell.cxx
@@ -119,7 +119,7 @@ using namespace ::com::sun::star::form::runtime;
 using namespace ::svxform;
 
 FmDesignModeChangedHint::FmDesignModeChangedHint( bool bDesMode )
-    :m_bDesignMode( bDesMode )
+    :SfxHint(SfxHintId::FmDesignModeChanged), m_bDesignMode( bDesMode )
 {
 }
 
diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx
index fdc9c0891b81..6578944aa4a8 100644
--- a/sw/source/uibase/uiview/view.cxx
+++ b/sw/source/uibase/uiview/view.cxx
@@ -1731,103 +1731,101 @@ SwGlossaryHdl* SwView::GetGlosHdl()
 void SwView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
 {
     bool bCallBase = true;
-    if(auto pChangedHint = dynamic_cast<const 
FmDesignModeChangedHint*>(&rHint))
+    SfxHintId nId = rHint.GetId();
+    switch ( nId )
     {
-        bool bDesignMode = pChangedHint->GetDesignMode();
-        if (!bDesignMode && GetDrawFuncPtr())
+        case SfxHintId::FmDesignModeChanged:
         {
-            GetDrawFuncPtr()->Deactivate();
-            SetDrawFuncPtr(nullptr);
-            LeaveDrawCreate();
-            AttrChangedNotify(nullptr);
+            auto pChangedHint = static_cast<const 
FmDesignModeChangedHint*>(&rHint);
+            bool bDesignMode = pChangedHint->GetDesignMode();
+            if (!bDesignMode && GetDrawFuncPtr())
+            {
+                GetDrawFuncPtr()->Deactivate();
+                SetDrawFuncPtr(nullptr);
+                LeaveDrawCreate();
+                AttrChangedNotify(nullptr);
+            }
+            break;
         }
-    }
-    else
-    {
-        SfxHintId nId = rHint.GetId();
-
-        switch ( nId )
-        {
-            // sub shells will be destroyed by the
-            // dispatcher, if the view frame is dying. Thus, reset member 
<pShell>.
-            case SfxHintId::Dying:
-                {
-                    if ( &rBC == &GetViewFrame() )
-                    {
-                        ResetSubShell();
-                    }
-                }
-                break;
-            case SfxHintId::ModeChanged:
+        // sub shells will be destroyed by the
+        // dispatcher, if the view frame is dying. Thus, reset member <pShell>.
+        case SfxHintId::Dying:
+            {
+                if ( &rBC == &GetViewFrame() )
                 {
-                    // Modal mode change-over?
-                    bool bModal = GetDocShell()->IsInModalMode();
-                    m_pHRuler->SetActive( !bModal );
-                    m_pVRuler->SetActive( !bModal );
+                    ResetSubShell();
                 }
+            }
+            break;
+        case SfxHintId::ModeChanged:
+            {
+                // Modal mode change-over?
+                bool bModal = GetDocShell()->IsInModalMode();
+                m_pHRuler->SetActive( !bModal );
+                m_pVRuler->SetActive( !bModal );
+            }
 
-                [[fallthrough]];
+            [[fallthrough]];
 
-            case SfxHintId::TitleChanged:
-                if ( GetDocShell()->IsReadOnly() != 
GetWrtShell().GetViewOptions()->IsReadonly() )
-                {
-                    SwWrtShell &rSh = GetWrtShell();
-                    rSh.SetReadonlyOption( GetDocShell()->IsReadOnly() );
-
-                    if ( rSh.GetViewOptions()->IsViewVRuler() )
-                        CreateVRuler();
-                    else
-                        KillVRuler();
-                    if ( rSh.GetViewOptions()->IsViewHRuler() )
-                        CreateTab();
-                    else
-                        KillTab();
-                    bool bReadonly = GetDocShell()->IsReadOnly();
-                    // if document is to be opened in alive-mode then this has 
to be
-                    // regarded while switching from readonly-mode to edit-mode
-                    if( !bReadonly )
-                    {
-                        SwDrawModel * pDrawDoc = 
GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel();
-                        if (pDrawDoc)
-                        {
-                            if( !pDrawDoc->GetOpenInDesignMode() )
-                                break;// don't touch the design mode
-                        }
-                    }
-                    SfxBoolItem aItem( SID_FM_DESIGN_MODE, !bReadonly);
-                    GetDispatcher().ExecuteList(SID_FM_DESIGN_MODE,
-                            SfxCallMode::ASYNCHRON, { &aItem });
-                }
-                break;
+        case SfxHintId::TitleChanged:
+            if ( GetDocShell()->IsReadOnly() != 
GetWrtShell().GetViewOptions()->IsReadonly() )
+            {
+                SwWrtShell &rSh = GetWrtShell();
+                rSh.SetReadonlyOption( GetDocShell()->IsReadOnly() );
 
-            case SfxHintId::SwDrawViewsCreated:
+                if ( rSh.GetViewOptions()->IsViewVRuler() )
+                    CreateVRuler();
+                else
+                    KillVRuler();
+                if ( rSh.GetViewOptions()->IsViewHRuler() )
+                    CreateTab();
+                else
+                    KillTab();
+                bool bReadonly = GetDocShell()->IsReadOnly();
+                // if document is to be opened in alive-mode then this has to 
be
+                // regarded while switching from readonly-mode to edit-mode
+                if( !bReadonly )
                 {
-                    bCallBase = false;
-                    if ( GetFormShell() )
+                    SwDrawModel * pDrawDoc = 
GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel();
+                    if (pDrawDoc)
                     {
-                        
GetFormShell()->SetView(dynamic_cast<FmFormView*>(GetWrtShell().GetDrawView()));
-                        SfxBoolItem aItem( SID_FM_DESIGN_MODE, 
!GetDocShell()->IsReadOnly());
-                        GetDispatcher().ExecuteList(SID_FM_DESIGN_MODE,
-                                SfxCallMode::SYNCHRON, { &aItem });
+                        if( !pDrawDoc->GetOpenInDesignMode() )
+                            break;// don't touch the design mode
                     }
                 }
-                break;
-            case SfxHintId::RedlineChanged:
+                SfxBoolItem aItem( SID_FM_DESIGN_MODE, !bReadonly);
+                GetDispatcher().ExecuteList(SID_FM_DESIGN_MODE,
+                        SfxCallMode::ASYNCHRON, { &aItem });
+            }
+            break;
+
+        case SfxHintId::SwDrawViewsCreated:
+            {
+                bCallBase = false;
+                if ( GetFormShell() )
                 {
-                    static sal_uInt16 const aSlotRedLine[] = {
-                        FN_REDLINE_ACCEPT_DIRECT,
-                        FN_REDLINE_REJECT_DIRECT,
-                        FN_REDLINE_NEXT_CHANGE,
-                        FN_REDLINE_PREV_CHANGE,
-                        FN_REDLINE_ACCEPT_ALL,
-                        FN_REDLINE_REJECT_ALL,
-                        0
-                    };
-                    GetViewFrame().GetBindings().Invalidate(aSlotRedLine);
+                    
GetFormShell()->SetView(dynamic_cast<FmFormView*>(GetWrtShell().GetDrawView()));
+                    SfxBoolItem aItem( SID_FM_DESIGN_MODE, 
!GetDocShell()->IsReadOnly());
+                    GetDispatcher().ExecuteList(SID_FM_DESIGN_MODE,
+                            SfxCallMode::SYNCHRON, { &aItem });
                 }
-                break;
-            default: break;
-        }
+            }
+            break;
+        case SfxHintId::RedlineChanged:
+            {
+                static sal_uInt16 const aSlotRedLine[] = {
+                    FN_REDLINE_ACCEPT_DIRECT,
+                    FN_REDLINE_REJECT_DIRECT,
+                    FN_REDLINE_NEXT_CHANGE,
+                    FN_REDLINE_PREV_CHANGE,
+                    FN_REDLINE_ACCEPT_ALL,
+                    FN_REDLINE_REJECT_ALL,
+                    0
+                };
+                GetViewFrame().GetBindings().Invalidate(aSlotRedLine);
+            }
+            break;
+        default: break;
     }
 
     if ( bCallBase )

Reply via email to