diff --git a/comphelper/source/misc/lok.cxx b/comphelper/source/misc/lok.cxx index 5c64c2cc4ab0..c8330f992c3a 100644 --- a/comphelper/source/misc/lok.cxx +++ b/comphelper/source/misc/lok.cxx @@ -44,6 +44,9 @@ static bool g_bSlideshowRendering(false); static Compat g_eCompatFlags(Compat::none); +/// Used to set the DocId at ViewShell construction time. +static ViewShellDocId g_nCurrentDocId; + static std::function g_pAnyInputCallback; static void* g_pAnyInputCallbackData; static std::function g_pMostUrgentPriorityGetter; @@ -394,6 +397,16 @@ int getView() return g_pViewGetter(); } +ViewShellDocId getDocId() +{ + return g_nCurrentDocId; +} + +void setDocId(ViewShellDocId nDocId) +{ + g_nCurrentDocId = nDocId; +} + void setInitialClientVisibleArea(const awt::Rectangle& rClientVisibleArea) { g_aInitialClientVisibleArea = rClientVisibleArea; diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index aa39be86eddb..b353f1594692 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -374,7 +374,7 @@ DesktopLOKTest::loadDocUrlImpl(const OUString& rFileURL, LibreOfficeKitDocumentT } static int nDocumentIdCounter = 0; - SfxViewShell::SetCurrentDocId(ViewShellDocId(nDocumentIdCounter)); + comphelper::LibreOfficeKit::setDocId(ViewShellDocId(nDocumentIdCounter)); mxComponent = loadFromDesktop(rFileURL, aService); std::unique_ptr pDocument(new LibLODocument_Impl(mxComponent, nDocumentIdCounter)); diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 83a1a55cf619..a999e02beff7 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -2993,7 +2993,7 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis, HostFilter::setExemptVerifyHost(OUString(pExemptVerifyHost, strlen(pExemptVerifyHost), RTL_TEXTENCODING_UTF8)); const int nThisDocumentId = nDocumentIdCounter++; - SfxViewShell::SetCurrentDocId(ViewShellDocId(nThisDocumentId)); + comphelper::LibreOfficeKit::setDocId(ViewShellDocId(nThisDocumentId)); uno::Reference xComponent = xComponentLoader->loadComponentFromURL( aURL, u"_blank"_ustr, 0, aFilterOptions); @@ -3007,6 +3007,8 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis, return nullptr; } + assert(comphelper::LibreOfficeKit::getDocId() == ViewShellDocId(nThisDocumentId) && "incorrect docid set on document"); + LibLODocument_Impl* pDocument = new LibLODocument_Impl(xComponent, nThisDocumentId); // After loading the document, its initial view is the "current" view. diff --git a/include/comphelper/lok.hxx b/include/comphelper/lok.hxx index fb8f8417c4d1..9d28f839c9c0 100644 --- a/include/comphelper/lok.hxx +++ b/include/comphelper/lok.hxx @@ -13,8 +13,11 @@ #include #include +#include #include +typedef o3tl::strong_int ViewShellDocId; + class LanguageTag; namespace com::sun::star::awt { @@ -154,6 +157,16 @@ COMPHELPER_DLLPUBLIC void setView(int nView); COMPHELPER_DLLPUBLIC void setViewGetter(const std::function& pViewGetter); COMPHELPER_DLLPUBLIC int getView(); +/// Set the current DocId, which is used by Mobile LOKit to +/// load multiple documents and yet identify the views of each. +/// There are events that are fired while creating a new view, +/// and if we don't have a DocId, we can't know which other views +/// within the same document (if any) should get those events. +/// By setting this static value, we are able to set the DocId +/// of each SfxViewShell at construction time. +COMPHELPER_DLLPUBLIC void setDocId(ViewShellDocId nDocId); +COMPHELPER_DLLPUBLIC ViewShellDocId getDocId(); + COMPHELPER_DLLPUBLIC void setInitialClientVisibleArea(const css::awt::Rectangle& rClientVisibleArea); COMPHELPER_DLLPUBLIC css::awt::Rectangle getInitialClientVisibleArea(); diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx index 1748644dff75..fd4a7fe28f13 100644 --- a/include/sfx2/viewsh.hxx +++ b/include/sfx2/viewsh.hxx @@ -180,9 +180,6 @@ friend class SfxPrinterController; bool maLOKIsTimezoneSet; bool mbLOKColorPreviewEnabled; - /// Used to set the DocId at construction time. See SetCurrentDocId. - static ViewShellDocId mnCurrentDocId; - /// Used for async export std::shared_ptr m_xHelper; @@ -421,14 +418,6 @@ public: /// See OutlinerViewShell::GetViewShellId(). ViewShellId GetViewShellId() const override; - /// Set the current DocId, which is used by Mobile LOKit to - /// load multiple documents and yet identify the views of each. - /// There are events that are fired while creating a new view, - /// and if we don't have a DocId, we can't know which other views - /// within the same document (if any) should get those events. - /// By setting this static value, we are able to set the DocId - /// of each SfxViewShell at construction time. - static void SetCurrentDocId(ViewShellDocId nId); /// Get the DocId used by Mobile LOKit to load multiple documents. ViewShellDocId GetDocId() const override; diff --git a/include/svl/undo.hxx b/include/svl/undo.hxx index fc4485bde602..5a0340d99f05 100644 --- a/include/svl/undo.hxx +++ b/include/svl/undo.hxx @@ -20,6 +20,7 @@ #define INCLUDED_SVL_UNDO_HXX #include +#include #include #include #include @@ -29,7 +30,6 @@ #include typedef o3tl::strong_int ViewShellId; -typedef o3tl::strong_int ViewShellDocId; typedef struct _xmlTextWriter* xmlTextWriterPtr; diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index d6b103715d09..43c027585d8f 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -125,7 +125,7 @@ int SfxLokHelper::createView(SfxViewFrame& rViewFrame, ViewShellDocId docId) // something has likely cleared the original SID_INTERACTIONHANDLER assert(!isSfxMediumMissingInteractionHandled(rViewFrame) && "original XInteractionHandler missing"); - SfxViewShell::SetCurrentDocId(docId); + comphelper::LibreOfficeKit::setDocId(docId); SfxRequest aRequest(rViewFrame, SID_NEWWINDOW); rViewFrame.ExecView_Impl(aRequest); SfxViewShell* pViewShell = SfxViewShell::Current(); diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx index a8e1e6237579..8b1b86e2ed53 100644 --- a/sfx2/source/view/viewsh.cxx +++ b/sfx2/source/view/viewsh.cxx @@ -2726,8 +2726,6 @@ void SfxViewShell::SetWindow //SfxGetpApp()->GrabFocus( pWindow ); } -ViewShellDocId SfxViewShell::mnCurrentDocId(0); - SfxViewShell::SfxViewShell ( SfxViewFrame& rViewFrame, /* , which will be @@ -2736,7 +2734,7 @@ SfxViewShell::SfxViewShell ) : SfxShell(this) -, pImpl( new SfxViewShell_Impl(nFlags, SfxViewShell::mnCurrentDocId) ) +, pImpl( new SfxViewShell_Impl(nFlags, comphelper::LibreOfficeKit::getDocId()) ) , rFrame(rViewFrame) , pWindow(nullptr) , bNoNewWindow( nFlags & SfxViewShellFlags::NO_NEWWINDOW ) @@ -3549,11 +3547,6 @@ ViewShellId SfxViewShell::GetViewShellId() const return pImpl->m_nViewShellId; } -void SfxViewShell::SetCurrentDocId(ViewShellDocId nId) -{ - mnCurrentDocId = nId; -} - ViewShellDocId SfxViewShell::GetDocId() const { assert(pImpl->m_nDocId >= ViewShellDocId(0) && "m_nDocId should have been initialized, but it is invalid."); diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx index d60d5fa59aea..ddd4c237fbe2 100644 --- a/vcl/source/app/svapp.cxx +++ b/vcl/source/app/svapp.cxx @@ -406,13 +406,23 @@ bool Application::Reschedule( bool i_bAllEvents ) return false; } int nOldView = -1; + ViewShellDocId nOldDocId(-1); if (comphelper::LibreOfficeKit::isActive()) { nOldView = comphelper::LibreOfficeKit::getView(); + nOldDocId = comphelper::LibreOfficeKit::getDocId(); } bool bRet = ImplYield(false, i_bAllEvents); if (comphelper::LibreOfficeKit::isActive()) { + // Yield may have changed the current docId, restore the old value, + // (which is cheap). If there is a view to restore this doesn't matter + // much, but if there isn't yet, as in the case of loading a new + // document, then this ensures that the next view to be created is + // created with the expected document id. + assert(nOldDocId.get() != -1 && "won't be unset"); + comphelper::LibreOfficeKit::setDocId(nOldDocId); + int nNewView = comphelper::LibreOfficeKit::getView(); if (nOldView != -1 && nNewView != -1 && nOldView != nNewView) {