diff options
-rw-r--r-- | compilerplugins/clang/badstatics.cxx | 3 | ||||
-rw-r--r-- | include/sfx2/viewsh.hxx | 1 | ||||
-rw-r--r-- | sfx2/source/view/lokhelper.cxx | 29 | ||||
-rw-r--r-- | sfx2/source/view/viewimp.hxx | 2 | ||||
-rw-r--r-- | sfx2/source/view/viewsh.cxx | 9 |
5 files changed, 18 insertions, 26 deletions
diff --git a/compilerplugins/clang/badstatics.cxx b/compilerplugins/clang/badstatics.cxx index 7f09dbc910a0..12e6b931b3c6 100644 --- a/compilerplugins/clang/badstatics.cxx +++ b/compilerplugins/clang/badstatics.cxx @@ -150,9 +150,6 @@ public: // ScAddInAsync* keys if that set is not empty at exit || name == "g_aWindowList" //vcl/unx/gtk/a11y/atkutil.cxx, asserted empty at exit - || name=="aViewMap" - // sfx2/source/view/lokhelper.cxx, not owning, leaked by - // (mis-)design ) // these variables appear unproblematic { return true; diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx index a6659137807d..f6e5777bee1d 100644 --- a/include/sfx2/viewsh.hxx +++ b/include/sfx2/viewsh.hxx @@ -334,6 +334,7 @@ public: /// See lok::Document::getPart(). virtual int getPart() const; virtual void dumpAsXml(struct _xmlTextWriter* pWriter) const; + sal_uInt32 GetViewShellId() const; }; diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index 09d78cf8601d..856a007a4206 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -17,42 +17,24 @@ #include <shellimpl.hxx> -namespace -{ - -/// Assigns a view ID to a view shell. -int shellToView(SfxViewShell* pViewShell) -{ - // Deleted view shells are not removed from this map, so view IDs are not - // reused when deleting, then creating a view. - static std::map<SfxViewShell*, int> aViewMap; - auto it = aViewMap.find(pViewShell); - if (it != aViewMap.end()) - return it->second; - - int nViewId = aViewMap.size(); - aViewMap[pViewShell] = nViewId; - return nViewId; -} -} - int SfxLokHelper::createView() { SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst(); SfxRequest aRequest(pViewFrame, SID_NEWWINDOW); pViewFrame->ExecView_Impl(aRequest); - return shellToView(SfxViewShell::Current()); + return SfxViewShell::Current()->GetViewShellId(); } void SfxLokHelper::destroyView(int nId) { + unsigned nViewShellId = nId; SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl(); for (std::size_t i = 0; i < rViewArr.size(); ++i) { SfxViewShell* pViewShell = rViewArr[i]; - if (shellToView(pViewShell) == nId) + if (pViewShell->GetViewShellId() == nViewShellId) { SfxViewFrame* pViewFrame = pViewShell->GetViewFrame(); SfxRequest aRequest(pViewFrame, SID_CLOSEWIN); @@ -64,12 +46,13 @@ void SfxLokHelper::destroyView(int nId) void SfxLokHelper::setView(int nId) { + unsigned nViewShellId = nId; SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl(); for (std::size_t i = 0; i < rViewArr.size(); ++i) { SfxViewShell* pViewShell = rViewArr[i]; - if (shellToView(pViewShell) == nId) + if (pViewShell->GetViewShellId() == nViewShellId) { if (pViewShell == SfxViewShell::Current()) return; @@ -86,7 +69,7 @@ int SfxLokHelper::getView(SfxViewShell* pViewShell) { if (!pViewShell) pViewShell = SfxViewShell::Current(); - return shellToView(pViewShell); + return pViewShell->GetViewShellId(); } std::size_t SfxLokHelper::getViews() diff --git a/sfx2/source/view/viewimp.hxx b/sfx2/source/view/viewimp.hxx index fa3e6800c016..95fdf8260df4 100644 --- a/sfx2/source/view/viewimp.hxx +++ b/sfx2/source/view/viewimp.hxx @@ -62,6 +62,8 @@ struct SfxViewShell_Impl void* m_pLibreOfficeKitViewData; /// Set if we are in the middle of a tiled search. bool m_bTiledSearching; + static sal_uInt32 m_nLastViewShellId; + const sal_uInt32 m_nViewShellId; explicit SfxViewShell_Impl(SfxViewShellFlags const nFlags); ~SfxViewShell_Impl(); diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx index 21086334dc78..6ffd25313749 100644 --- a/sfx2/source/view/viewsh.cxx +++ b/sfx2/source/view/viewsh.cxx @@ -238,6 +238,8 @@ public: size_t size() const { return maData.size(); } }; +sal_uInt32 SfxViewShell_Impl::m_nLastViewShellId = 0; + SfxViewShell_Impl::SfxViewShell_Impl(SfxViewShellFlags const nFlags) : aInterceptorContainer( aMutex ) , m_bControllerSet(false) @@ -252,6 +254,7 @@ SfxViewShell_Impl::SfxViewShell_Impl(SfxViewShellFlags const nFlags) , m_pLibreOfficeKitViewCallback(nullptr) , m_pLibreOfficeKitViewData(nullptr) , m_bTiledSearching(false) +, m_nViewShellId(SfxViewShell_Impl::m_nLastViewShellId++) {} SfxViewShell_Impl::~SfxViewShell_Impl() @@ -1502,10 +1505,16 @@ int SfxViewShell::getPart() const return 0; } +sal_uInt32 SfxViewShell::GetViewShellId() const +{ + return pImpl->m_nViewShellId; +} + void SfxViewShell::dumpAsXml(xmlTextWriterPtr pWriter) const { xmlTextWriterStartElement(pWriter, BAD_CAST("sfxViewShell")); xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this); + xmlTextWriterWriteAttribute(pWriter, BAD_CAST("id"), BAD_CAST(OString::number(GetViewShellId()).getStr())); xmlTextWriterEndElement(pWriter); } |