summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-06-29 17:27:04 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-07-20 18:02:06 +0200
commit87251b0c5d769020a8469064a7e4be9c36a5f1ee (patch)
tree093bf869d7891cc7b656e0bd9661566ab1fdc60a /sfx2
parent43ebf466fef79b055e4a905ab4abf18da190180a (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> (cherry picked from commit 615c37503cffa92a663245d7cb140f316ace0506)
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/view/lokhelper.cxx35
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()