summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2020-06-02 12:46:51 +0300
committerTor Lillqvist <tml@collabora.com>2020-06-24 13:28:33 +0200
commit3d9e60524fcb4d62fbf17af0ccd1f9613b1b8470 (patch)
tree45a34362940690ac0e050ce5a698fb2746bf4b6c /sfx2
parentdc13c656dc25ed35c31bec7b6c8ae7d0c6b258e3 (diff)
tdf#128502: Try to support multiple documents in LibreOfficeKit-using process
The LibreOfficeKit-specific code typically has assumed that all the "views" (SfxViewShell instances) are for the same document, because all LibreOfficeKit-based application processes (including the "kit" processes in Online and the iOS app) so far have only had one document open at a time. It is now possible to pass several document file names on the command line to gtktiledviewer and that is an easy way to demonstrate how badly it still works even with this patch. Introduce a unique numeric document id that is increased in the LibLODocument_Impl constructor. Add APIs to access that. When iterating over views, try to skip views that are not of the document visible in the "current" view, if we know what the "current" view is. Also add a couple of FIXMEs at places where it is a bit unclear (to me) whether it is correct to iterate over all views, or whether only views for the "current" document are what we would want. Change-Id: Id5ebb92a115723cdeb23907163d5b5f282016252 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95353 Tested-by: Jenkins Reviewed-by: Tor Lillqvist <tml@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96356 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/view/lokcharthelper.cxx4
-rw-r--r--sfx2/source/view/lokhelper.cxx75
-rw-r--r--sfx2/source/view/viewimp.hxx1
-rw-r--r--sfx2/source/view/viewsh.cxx19
4 files changed, 82 insertions, 17 deletions
diff --git a/sfx2/source/view/lokcharthelper.cxx b/sfx2/source/view/lokcharthelper.cxx
index 903e4727eb62..23d84851f5a5 100644
--- a/sfx2/source/view/lokcharthelper.cxx
+++ b/sfx2/source/view/lokcharthelper.cxx
@@ -180,7 +180,7 @@ bool LokChartHelper::HitAny(const Point& aPos)
SfxViewShell* pViewShell = SfxViewShell::GetFirst();
while (pViewShell)
{
- if (pViewShell->getPart() == nPartForCurView)
+ if (pViewShell->GetDocId() == pCurView->GetDocId() && pViewShell->getPart() == nPartForCurView)
{
LokChartHelper aChartHelper(pViewShell);
if (aChartHelper.Hit(aPos))
@@ -262,7 +262,7 @@ void LokChartHelper::PaintAllChartsOnTile(VirtualDevice& rDevice,
SfxViewShell* pViewShell = SfxViewShell::GetFirst();
while (pViewShell)
{
- if (pViewShell->getPart() == nPartForCurView)
+ if (pCurView && pViewShell->GetDocId() == pCurView->GetDocId() && pViewShell->getPart() == nPartForCurView)
{
LokChartHelper aChartHelper(pViewShell);
aChartHelper.PaintTile(rDevice, aTileRect);
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 4fb7761cec95..2f78bfc1eaa5 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -69,11 +69,17 @@ int SfxLokHelper::createView()
SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst();
if (!pViewFrame)
return -1;
+ SfxViewShell* pPrevViewShell = SfxViewShell::Current();
+ ViewShellDocId nId;
+ if (pPrevViewShell)
+ nId = pPrevViewShell->GetDocId();
SfxRequest aRequest(pViewFrame, SID_NEWWINDOW);
pViewFrame->ExecView_Impl(aRequest);
SfxViewShell* pViewShell = SfxViewShell::Current();
if (!pViewShell)
return -1;
+ if (pPrevViewShell)
+ pViewShell->SetDocId(nId);
return static_cast<sal_Int32>(pViewShell->GetViewShellId());
}
@@ -147,7 +153,20 @@ int SfxLokHelper::getView(SfxViewShell* pViewShell)
std::size_t SfxLokHelper::getViewsCount()
{
SfxApplication* pApp = SfxApplication::Get();
- return !pApp ? 0 : pApp->GetViewShells_Impl().size();
+ if (!pApp)
+ return 0;
+
+ const SfxViewShell* const pCurrentViewShell = SfxViewShell::Current();
+ const ViewShellDocId nCurrentDocId = pCurrentViewShell ? pCurrentViewShell->GetDocId() : ViewShellDocId(-1);
+ std::size_t n = 0;
+ SfxViewShell* pViewShell = SfxViewShell::GetFirst();
+ while (pViewShell)
+ {
+ if (pViewShell->GetDocId() == nCurrentDocId)
+ n++;
+ pViewShell = SfxViewShell::GetNext(*pViewShell);
+ }
+ return n;
}
bool SfxLokHelper::getViewIds(int* pArray, size_t nSize)
@@ -156,18 +175,45 @@ bool SfxLokHelper::getViewIds(int* pArray, size_t nSize)
if (!pApp)
return false;
- SfxViewShellArr_Impl& rViewArr = pApp->GetViewShells_Impl();
- if (rViewArr.size() > nSize)
- return false;
-
- for (std::size_t i = 0; i < rViewArr.size(); ++i)
+ const SfxViewShell* const pCurrentViewShell = SfxViewShell::Current();
+ const ViewShellDocId nCurrentDocId = pCurrentViewShell ? pCurrentViewShell->GetDocId() : ViewShellDocId(-1);
+ std::size_t n = 0;
+ SfxViewShell* pViewShell = SfxViewShell::GetFirst();
+ while (pViewShell)
{
- SfxViewShell* pViewShell = rViewArr[i];
- pArray[i] = static_cast<sal_Int32>(pViewShell->GetViewShellId());
+ if (n == nSize)
+ return false;
+ if (pViewShell->GetDocId() == nCurrentDocId)
+ {
+ pArray[n] = static_cast<sal_Int32>(pViewShell->GetViewShellId());
+ n++;
+ }
+ pViewShell = SfxViewShell::GetNext(*pViewShell);
}
return true;
}
+void SfxLokHelper::setDocumentIdOfView(int nId)
+{
+ SfxViewShell* pViewShell = SfxViewShell::Current();
+ assert(pViewShell);
+ if (!pViewShell)
+ return;
+ pViewShell->SetDocId(ViewShellDocId(nId));
+}
+
+int SfxLokHelper::getDocumentIdOfView(int nViewId)
+{
+ SfxViewShell* pViewShell = SfxViewShell::GetFirst();
+ while (pViewShell)
+ {
+ if (pViewShell->GetViewShellId() == ViewShellId(nViewId))
+ return static_cast<int>(pViewShell->GetDocId());
+ pViewShell = SfxViewShell::GetNext(*pViewShell);
+ }
+ return -1;
+}
+
LanguageTag SfxLokHelper::getDefaultLanguage()
{
return g_defaultLanguageTag;
@@ -252,13 +298,13 @@ void SfxLokHelper::notifyOtherView(SfxViewShell* pThisView, SfxViewShell const*
void SfxLokHelper::notifyOtherViews(SfxViewShell* pThisView, int nType, const OString& rKey, const OString& rPayload)
{
- if (SfxLokHelper::getViewsCount() <= 1 || DisableCallbacks::disabled())
+ if (DisableCallbacks::disabled())
return;
SfxViewShell* pViewShell = SfxViewShell::GetFirst();
while (pViewShell)
{
- if (pViewShell != pThisView)
+ if (pViewShell != pThisView && pViewShell->GetDocId() == pThisView-> GetDocId())
notifyOtherView(pThisView, pViewShell, nType, rKey, rPayload);
pViewShell = SfxViewShell::GetNext(*pViewShell);
@@ -371,10 +417,13 @@ void SfxLokHelper::notifyDocumentSizeChangedAllViews(vcl::ITiledRenderable* pDoc
if (!comphelper::LibreOfficeKit::isActive() || DisableCallbacks::disabled())
return;
+ // FIXME: Do we know whether it is the views for the document that is in the "current" view that has changed?
+ const SfxViewShell* const pCurrentViewShell = SfxViewShell::Current();
SfxViewShell* pViewShell = SfxViewShell::GetFirst();
while (pViewShell)
{
- SfxLokHelper::notifyDocumentSizeChanged(pViewShell, "", pDoc, bInvalidateAll);
+ if (pViewShell->GetDocId() == pCurrentViewShell-> GetDocId())
+ SfxLokHelper::notifyDocumentSizeChanged(pViewShell, "", pDoc, bInvalidateAll);
pViewShell = SfxViewShell::GetNext(*pViewShell);
}
}
@@ -406,10 +455,12 @@ void SfxLokHelper::notifyAllViews(int nType, const OString& rPayload)
return;
const auto payload = rPayload.getStr();
+ const SfxViewShell* const pCurrentViewShell = SfxViewShell::Current();
SfxViewShell* pViewShell = SfxViewShell::GetFirst();
while (pViewShell)
{
- pViewShell->libreOfficeKitViewCallback(nType, payload);
+ if (pViewShell->GetDocId() == pCurrentViewShell->GetDocId())
+ pViewShell->libreOfficeKitViewCallback(nType, payload);
pViewShell = SfxViewShell::GetNext(*pViewShell);
}
}
diff --git a/sfx2/source/view/viewimp.hxx b/sfx2/source/view/viewimp.hxx
index 00b7b51590fe..ef919a2fd89f 100644
--- a/sfx2/source/view/viewimp.hxx
+++ b/sfx2/source/view/viewimp.hxx
@@ -59,6 +59,7 @@ struct SfxViewShell_Impl
bool m_bTiledSearching;
static sal_uInt32 m_nLastViewShellId;
const ViewShellId m_nViewShellId;
+ ViewShellDocId m_nDocId;
explicit SfxViewShell_Impl(SfxViewShellFlags const nFlags);
~SfxViewShell_Impl();
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index dcbdc9ceef3a..ad46e704478f 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -228,7 +228,9 @@ SfxViewShell_Impl::SfxViewShell_Impl(SfxViewShellFlags const nFlags)
, m_pLibreOfficeKitViewData(nullptr)
, m_bTiledSearching(false)
, m_nViewShellId(SfxViewShell_Impl::m_nLastViewShellId++)
-{}
+, m_nDocId(-1)
+{
+}
SfxViewShell_Impl::~SfxViewShell_Impl()
{
@@ -1096,7 +1098,6 @@ SfxViewShell::SfxViewShell
SfxViewShell::~SfxViewShell()
{
-
// Remove from list
const SfxViewShell *pThis = this;
SfxViewShellArr_Impl &rViewArr = SfxGetpApp()->GetViewShells_Impl();
@@ -1478,7 +1479,8 @@ void SfxViewShell::registerLibreOfficeKitViewCallback(LibreOfficeKitCallback pCa
SfxViewShell* pViewShell = SfxViewShell::GetFirst();
while (pViewShell)
{
- pViewShell->NotifyCursor(this);
+ if (pViewShell->GetDocId() == GetDocId())
+ pViewShell->NotifyCursor(this);
pViewShell = SfxViewShell::GetNext(*pViewShell);
}
}
@@ -1573,6 +1575,17 @@ ViewShellId SfxViewShell::GetViewShellId() const
return pImpl->m_nViewShellId;
}
+void SfxViewShell::SetDocId(ViewShellDocId nId)
+{
+ assert(static_cast<int>(pImpl->m_nDocId) == -1);
+ pImpl->m_nDocId = nId;
+}
+
+ViewShellDocId SfxViewShell::GetDocId() const
+{
+ return pImpl->m_nDocId;
+}
+
void SfxViewShell::NotifyOtherViews(int nType, const OString& rKey, const OString& rPayload)
{
SfxLokHelper::notifyOtherViews(this, nType, rKey, rPayload);