diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-06-17 16:38:04 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-06-17 16:00:44 +0000 |
commit | 45c2410041c48c22bd860efb42d4daadad7869b0 (patch) | |
tree | 7adf4d278976bcadd284c8d1cbd6a863f98c14d0 /sfx2 | |
parent | 9ec54e92407cd632c4e38317f914edd557835a86 (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.
Change-Id: If79ef8b99ba391011b5d82b219ad13447d44cd5a
Reviewed-on: https://gerrit.libreoffice.org/26423
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 | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index 97e17168d2c6..3a306cfbe362 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -14,54 +14,55 @@ #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(std::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(std::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); } -std::size_t SfxLokHelper::getView() +std::uintptr_t SfxLokHelper::getView() { - SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl(); - SfxViewFrame* pViewFrame = SfxViewFrame::Current(); - for (std::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()); } std::size_t SfxLokHelper::getViews() |