summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-06-17 16:38:04 +0200
committerAshod Nakashian <ashod.nakashian@collabora.co.uk>2016-07-20 01:33:09 -0400
commit665eb58b9e460c969de1f49af5c1a7fae37c34cc (patch)
treef64a9ac9b59036a9e9575cfe782058311e6a10d9 /sfx2
parent2a03b0e6fe09ba8ce02977d50814800e720b8d46 (diff)
LOK: change type of view ids to uintptr_t
This fixes the following problem: - createView() = 1 - createView() = 2 - destroyView(1) and then view #2 was renumbered to 1. Instead expose the pointer address of the SfxViewShell as the ID, which is not changing in such a situation. Note that the SfxViewShell <-> ID mapping is an implementation detail of SfxLokHelper, and only pointers are converted to IDs, user-supplied IDs are never converted back to pointers. Reviewed-on: https://gerrit.libreoffice.org/26423 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Jenkins <ci@libreoffice.org> (cherry picked from commit 45c2410041c48c22bd860efb42d4daadad7869b0) Change-Id: If79ef8b99ba391011b5d82b219ad13447d44cd5a
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/view/lokhelper.cxx68
1 files changed, 34 insertions, 34 deletions
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index f3731e799ec3..3a306cfbe362 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -10,70 +10,70 @@
#include <sfx2/lokhelper.hxx>
#include <sfx2/viewsh.hxx>
#include <sfx2/request.hxx>
-#include <sfx2/sfxsids.hrc>
#include <sfx2/viewfrm.hxx>
#include <shellimpl.hxx>
-int SfxLokHelper::createView()
+std::uintptr_t SfxLokHelper::createView()
{
SfxViewFrame* pViewFrame = SfxViewFrame::Current();
SfxRequest aRequest(pViewFrame, SID_NEWWINDOW);
pViewFrame->ExecView_Impl(aRequest);
- // The SfxViewShell ctor always puts the view shell to the end of the vector.
- SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
- return rViewArr.size() - 1;
+ return reinterpret_cast<std::uintptr_t>(SfxViewShell::Current());
}
-void SfxLokHelper::destroyView(size_t nId)
+void SfxLokHelper::destroyView(std::uintptr_t nId)
{
SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
- if (nId > rViewArr.size() - 1)
- return;
- SfxViewShell* pViewShell = rViewArr[nId];
- SfxViewFrame* pViewFrame = pViewShell->GetViewFrame();
- SfxRequest aRequest(pViewFrame, SID_CLOSEWIN);
- pViewFrame->Exec_Impl(aRequest);
+ for (std::size_t i = 0; i < rViewArr.size(); ++i)
+ {
+ SfxViewShell* pViewShell = rViewArr[i];
+ if (reinterpret_cast<std::uintptr_t>(pViewShell) == nId)
+ {
+ SfxViewFrame* pViewFrame = pViewShell->GetViewFrame();
+ SfxRequest aRequest(pViewFrame, SID_CLOSEWIN);
+ pViewFrame->Exec_Impl(aRequest);
+ break;
+ }
+ }
}
-void SfxLokHelper::setView(size_t nId)
+void SfxLokHelper::setView(std::uintptr_t nId)
{
SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
- if (nId > rViewArr.size() - 1)
- return;
- SfxViewShell* pViewShell = rViewArr[nId];
- if (pViewShell->GetViewFrame() == SfxViewFrame::Current())
- return;
+ for (std::size_t i = 0; i < rViewArr.size(); ++i)
+ {
+ SfxViewShell* pViewShell = rViewArr[i];
+ if (reinterpret_cast<std::uintptr_t>(pViewShell) == nId)
+ {
+ if (pViewShell == SfxViewShell::Current())
+ return;
+
+ SfxViewFrame* pViewFrame = pViewShell->GetViewFrame();
+ pViewFrame->MakeActive_Impl(false);
+ return;
+ }
+ }
- if (SfxViewFrame* pViewFrame = pViewShell->GetViewFrame())
- pViewFrame->MakeActive_Impl(false);
}
-size_t SfxLokHelper::getView()
+std::uintptr_t SfxLokHelper::getView()
{
- SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
- SfxViewFrame* pViewFrame = SfxViewFrame::Current();
- for (size_t i = 0; i < rViewArr.size(); ++i)
- {
- if (rViewArr[i]->GetViewFrame() == pViewFrame)
- return i;
- }
- assert(false);
- return 0;
+ return reinterpret_cast<std::uintptr_t>(SfxViewShell::Current());
}
-size_t SfxLokHelper::getViews()
+std::size_t SfxLokHelper::getViews()
{
- size_t nRet = 0;
+ std::size_t nRet = 0;
SfxObjectShell* pObjectShell = SfxViewFrame::Current()->GetObjectShell();
SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
- for (size_t i = 0; i < rViewArr.size(); ++i)
+ for (SfxViewShell* i : rViewArr)
{
- if (rViewArr[i]->GetObjectShell() == pObjectShell)
+ if (i->GetObjectShell() == pObjectShell)
++nRet;
}