diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2023-11-04 12:05:16 +0100 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2023-11-06 10:04:31 +0100 |
commit | 6bf428d354349995f7a20e6ce38a47c238911abe (patch) | |
tree | eedc0818a882e4b49e146b0d4417ef421d1aff75 /sfx2 | |
parent | e0334e1a77ec080b38952ea64b394c8652af851c (diff) |
lok: notebookbar: handle multiple sessions
This fixes regression from commit db5a78c8ab1eae30e442151f07b0dc4dcd017550
lok: notebookbar: don't recreate toolbars too often
When we had 2 sessions with notebookbar and one of them switched
to compact mode - other session's notebookbar didn't work.
Before previous change we recreated notebookbar and its welded wrapper
on every StateMethod call for LOK case. So when it become destroyed
we made it working again. But now we need to introduce better management
and not rely on single instence we get from SystemWindow.
Also it's bad idea to rely 100% on SfxNotebookBar::IsActive in LOK
case as when other view will turn notebookbar off, but QueryState
will be trigerred in our session - we will think that it should be
destroyed (it reads config state which is shared between views).
So trust only "true" value (it happens after calling SID_TOOLBAR_MODE),
but destroy notebookbar only after explicit call of
SfxNotebookBar::CloseMethod. It seems to have good result when tested
with multiple views in Online. Maybe we can track Notebookbar state
per view later to make things simpler in LOK case.
Change-Id: Ie739c6441ca05884b0ef20bff23751467706b562
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158936
Tested-by: Jenkins
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/notebookbar/SfxNotebookBar.cxx | 89 |
1 files changed, 60 insertions, 29 deletions
diff --git a/sfx2/source/notebookbar/SfxNotebookBar.cxx b/sfx2/source/notebookbar/SfxNotebookBar.cxx index e9e85de271bd..8e9c2c9ca494 100644 --- a/sfx2/source/notebookbar/SfxNotebookBar.cxx +++ b/sfx2/source/notebookbar/SfxNotebookBar.cxx @@ -11,7 +11,6 @@ #include <sfx2/viewsh.hxx> #include <sfx2/dispatch.hxx> #include <sfx2/notebookbar/SfxNotebookBar.hxx> -#include <vcl/notebookbar/notebookbar.hxx> #include <vcl/syswin.hxx> #include <sfx2/viewfrm.hxx> #include <sfx2/sfxsids.hrc> @@ -43,6 +42,7 @@ const char MERGE_NOTEBOOKBAR_URL[] = "URL"; bool SfxNotebookBar::m_bLock = false; bool SfxNotebookBar::m_bHide = false; std::map<const SfxViewShell*, std::shared_ptr<WeldedTabbedNotebookbar>> SfxNotebookBar::m_pNotebookBarWeldedWrapper; +std::map<const SfxViewShell*, VclPtr<NotebookBar>> SfxNotebookBar::m_pNotebookBarInstance; static void NotebookbarAddonValues( std::vector<Image>& aImageValues, @@ -195,6 +195,19 @@ static utl::OConfigurationNode lcl_getCurrentImplConfigNode(const Reference<css: return utl::OConfigurationNode(); } +void SfxNotebookBar::RemoveCurrentLOKWrapper() +{ + const SfxViewShell* pViewShell = SfxViewShell::Current(); + auto aFound = m_pNotebookBarInstance.find(pViewShell); + if (aFound != m_pNotebookBarInstance.end()) + { + // Calls STATIC_LINK SfxNotebookBar -> VclDisposeHdl + // which clears also m_pNotebookBarWeldedWrapper + aFound->second.disposeAndClear(); + m_pNotebookBarInstance.erase(aFound); + } +} + void SfxNotebookBar::CloseMethod(SfxBindings& rBindings) { SfxFrame& rFrame = rBindings.GetDispatcher_Impl()->GetFrame()->GetFrame(); @@ -203,6 +216,12 @@ void SfxNotebookBar::CloseMethod(SfxBindings& rBindings) void SfxNotebookBar::CloseMethod(SystemWindow* pSysWindow) { + if (comphelper::LibreOfficeKit::isActive()) + { + RemoveCurrentLOKWrapper(); + return; + } + if (pSysWindow) { if(pSysWindow->GetNotebookBar()) @@ -356,15 +375,19 @@ bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow, return false; } + const SfxViewShell* pViewShell = SfxViewShell::Current(); + bool hasWeldedWrapper = m_pNotebookBarWeldedWrapper.find(pViewShell) != m_pNotebookBarWeldedWrapper.end(); + if (IsActive()) { css::uno::Reference<css::uno::XComponentContext> xContext = comphelper::getProcessComponentContext(); const Reference<frame::XModuleManager> xModuleManager = frame::ModuleManager::create( xContext ); OUString aModuleName = xModuleManager->identify( xFrame ); vcl::EnumContext::Application eApp = vcl::EnumContext::GetApplicationEnum( aModuleName ); + bool bIsLOK = comphelper::LibreOfficeKit::isActive(); OUString sFile; - if (comphelper::LibreOfficeKit::isActive()) + if (bIsLOK) sFile = "notebookbar_online.ui"; else sFile = lcl_getNotebookbarFileName( eApp ); @@ -377,26 +400,12 @@ bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow, bool bChangedFile = sNewFile != sCurrentFile; - const SfxViewShell* pViewShell = SfxViewShell::Current(); - bool hasWeldedWrapper = m_pNotebookBarWeldedWrapper.find(pViewShell) != m_pNotebookBarWeldedWrapper.end(); - - if ((!sFile.isEmpty() && bChangedFile) || !pNotebookBar || !pNotebookBar->IsVisible() - || bReloadNotebookbar || (comphelper::LibreOfficeKit::isActive() && !hasWeldedWrapper)) + if ((!bIsLOK && ( + (!sFile.isEmpty() && bChangedFile) || + (!pNotebookBar || !pNotebookBar->IsVisible()) || + bReloadNotebookbar) + ) || (bIsLOK && !hasWeldedWrapper)) { - // Notebookbar was loaded too early what caused: - // * in LOK: Paste Special feature was incorrectly initialized - // Skip first request so Notebookbar will be initialized after document was loaded - static std::map<const void*, bool> bSkippedFirstInit; - if (comphelper::LibreOfficeKit::isActive() && eApp == vcl::EnumContext::Application::Writer - && bSkippedFirstInit.find(pViewShell) == bSkippedFirstInit.end()) - { - bSkippedFirstInit[pViewShell] = true; - ResetActiveToolbarModeToDefault(eApp); - return false; - } - - RemoveListeners(pSysWindow); - OUString aBuf = rUIFile + sFile; //Addons For Notebookbar @@ -407,20 +416,29 @@ bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow, aNotebookBarAddonsItem.aAddonValues = aExtensionValues; aNotebookBarAddonsItem.aImageValues = aImageValues; - // setup if necessary - if (comphelper::LibreOfficeKit::isActive()) + if (bIsLOK) { + // Notebookbar was loaded too early what caused: + // * in LOK: Paste Special feature was incorrectly initialized + // Skip first request so Notebookbar will be initialized after document was loaded + static std::map<const void*, bool> bSkippedFirstInit; + if (eApp == vcl::EnumContext::Application::Writer + && bSkippedFirstInit.find(pViewShell) == bSkippedFirstInit.end()) + { + bSkippedFirstInit[pViewShell] = true; + ResetActiveToolbarModeToDefault(eApp); + return false; + } + // update the current LOK language and locale for the dialog tunneling comphelper::LibreOfficeKit::setLanguageTag(pViewShell->GetLOKLanguageTag()); comphelper::LibreOfficeKit::setLocale(pViewShell->GetLOKLocale()); - } - pSysWindow->SetNotebookBar(aBuf, xFrame, aNotebookBarAddonsItem , bReloadNotebookbar); - pNotebookBar = pSysWindow->GetNotebookBar(); - pNotebookBar->Show(); + pNotebookBar = VclPtr<NotebookBar>::Create(pSysWindow, "NotebookBar", aBuf, xFrame, aNotebookBarAddonsItem); + m_pNotebookBarInstance.emplace(std::make_pair(pViewShell, pNotebookBar)); + + assert(pNotebookBar->IsWelded()); - if ((!hasWeldedWrapper || bReloadNotebookbar) && pNotebookBar->IsWelded()) - { sal_uInt64 nWindowId = reinterpret_cast<sal_uInt64>(pViewShell); m_pNotebookBarWeldedWrapper.emplace(std::make_pair(pViewShell, new WeldedTabbedNotebookbar(pNotebookBar->GetMainContainer(), @@ -428,8 +446,16 @@ bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow, xFrame, nWindowId))); pNotebookBar->SetDisposeCallback(LINK(nullptr, SfxNotebookBar, VclDisposeHdl), pViewShell); + + return true; } + RemoveListeners(pSysWindow); + + pSysWindow->SetNotebookBar(aBuf, xFrame, aNotebookBarAddonsItem , bReloadNotebookbar); + pNotebookBar = pSysWindow->GetNotebookBar(); + pNotebookBar->Show(); + pNotebookBar->GetParent()->Resize(); utl::OConfigurationTreeRoot aRoot(lcl_getCurrentImplConfigRoot()); @@ -446,6 +472,11 @@ bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow, return true; } + else if (comphelper::LibreOfficeKit::isActive()) + { + // don't do anything to not close notebookbar of other session + return hasWeldedWrapper; + } else if (auto pNotebookBar = pSysWindow->GetNotebookBar()) { vcl::Window* pParent = pNotebookBar->GetParent(); |