diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-06-29 17:27:04 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-06-30 06:16:28 +0000 |
commit | 615c37503cffa92a663245d7cb140f316ace0506 (patch) | |
tree | 9d1adcf7385f705e38fbbb925c1488962954a39c /sfx2 | |
parent | 76c2125ee3eeb64a95501c26c2fa660cd0f8818c (diff) |
LOK: change back type of view ids to int
Commit 45c2410041c48c22bd860efb42d4daadad7869b0 (LOK: change type of
view ids to uintptr_t, 2016-06-17) fixed the problem of view IDs being
reused for the price of random IDs, which makes debugging harder.
Implement a simple shellToView() function that makes sure view IDs are
not reused, and stop exposing view shell pointer addresses, which allows
reverting the LOK API change.
Change-Id: I63089e6de08ee7e1c7706757d43a11f6cf4d6e06
Reviewed-on: https://gerrit.libreoffice.org/26773
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/view/lokhelper.cxx | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index b44392c9dfef..653dd7f58e17 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -17,23 +17,42 @@ #include <shellimpl.hxx> -std::uintptr_t SfxLokHelper::createView() +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::Current(); SfxRequest aRequest(pViewFrame, SID_NEWWINDOW); pViewFrame->ExecView_Impl(aRequest); - return reinterpret_cast<std::uintptr_t>(SfxViewShell::Current()); + return shellToView(SfxViewShell::Current()); } -void SfxLokHelper::destroyView(std::uintptr_t nId) +void SfxLokHelper::destroyView(int nId) { SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl(); for (std::size_t i = 0; i < rViewArr.size(); ++i) { SfxViewShell* pViewShell = rViewArr[i]; - if (reinterpret_cast<std::uintptr_t>(pViewShell) == nId) + if (shellToView(pViewShell) == nId) { SfxViewFrame* pViewFrame = pViewShell->GetViewFrame(); SfxRequest aRequest(pViewFrame, SID_CLOSEWIN); @@ -43,14 +62,14 @@ void SfxLokHelper::destroyView(std::uintptr_t nId) } } -void SfxLokHelper::setView(std::uintptr_t nId) +void SfxLokHelper::setView(int nId) { SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl(); for (std::size_t i = 0; i < rViewArr.size(); ++i) { SfxViewShell* pViewShell = rViewArr[i]; - if (reinterpret_cast<std::uintptr_t>(pViewShell) == nId) + if (shellToView(pViewShell) == nId) { if (pViewShell == SfxViewShell::Current()) return; @@ -63,11 +82,11 @@ void SfxLokHelper::setView(std::uintptr_t nId) } -std::uintptr_t SfxLokHelper::getView(SfxViewShell* pViewShell) +int SfxLokHelper::getView(SfxViewShell* pViewShell) { if (!pViewShell) pViewShell = SfxViewShell::Current(); - return reinterpret_cast<std::uintptr_t>(pViewShell); + return shellToView(pViewShell); } std::size_t SfxLokHelper::getViews() |