From 5bd2931b57a6cb4ac1f39d7ddae874ac693cfab0 Mon Sep 17 00:00:00 2001 From: Szymon Kłos Date: Mon, 12 Sep 2016 16:26:41 +0200 Subject: tdf#102063 Notebookbar wont appear on launch * removed static members from SfxNotebookBar to avoid crashes * Updating Notebookbar state after module load Change-Id: Ia4e3dcb0b6e2c5aa7c5205992dbf3575e72fa354 Reviewed-on: https://gerrit.libreoffice.org/28841 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt --- sfx2/source/control/dispatch.cxx | 6 ++ sfx2/source/notebookbar/NotebookBarPopupMenu.cxx | 2 +- sfx2/source/notebookbar/NotebookBarPopupMenu.hxx | 2 +- sfx2/source/notebookbar/SfxNotebookBar.cxx | 122 +++++++++++++++-------- 4 files changed, 90 insertions(+), 42 deletions(-) (limited to 'sfx2/source') diff --git a/sfx2/source/control/dispatch.cxx b/sfx2/source/control/dispatch.cxx index 0df9c0e893d2..4b57f14956fe 100644 --- a/sfx2/source/control/dispatch.cxx +++ b/sfx2/source/control/dispatch.cxx @@ -1344,6 +1344,12 @@ void SfxDispatcher::Update_Impl( bool bForce ) if ( xLayoutManager.is() ) xLayoutManager->unlock(); + if ( SfxViewShell::Current() && SfxViewShell::Current()->GetDispatcher() ) + { + const SfxPoolItem *pItem; + SfxViewShell::Current()->GetDispatcher()->QueryState(SID_NOTEBOOKBAR, pItem); + } + return; } diff --git a/sfx2/source/notebookbar/NotebookBarPopupMenu.cxx b/sfx2/source/notebookbar/NotebookBarPopupMenu.cxx index 35c2495387d0..9d36d015fe18 100644 --- a/sfx2/source/notebookbar/NotebookBarPopupMenu.cxx +++ b/sfx2/source/notebookbar/NotebookBarPopupMenu.cxx @@ -52,7 +52,7 @@ NotebookBarPopupMenu::NotebookBarPopupMenu() } void NotebookBarPopupMenu::Execute(NotebookBar* pNotebookbar, - css::uno::Reference& xFrame) + const Reference& xFrame) { if (pNotebookbar) { diff --git a/sfx2/source/notebookbar/NotebookBarPopupMenu.hxx b/sfx2/source/notebookbar/NotebookBarPopupMenu.hxx index 80514113a075..0d06a6e788d6 100644 --- a/sfx2/source/notebookbar/NotebookBarPopupMenu.hxx +++ b/sfx2/source/notebookbar/NotebookBarPopupMenu.hxx @@ -17,7 +17,7 @@ class NotebookBarPopupMenu : public PopupMenu public: explicit NotebookBarPopupMenu(); void Execute(NotebookBar* pNotebookbar, - css::uno::Reference& xFrame); + const css::uno::Reference& xFrame); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/notebookbar/SfxNotebookBar.cxx b/sfx2/source/notebookbar/SfxNotebookBar.cxx index 49956d5ada4d..f3c343902834 100644 --- a/sfx2/source/notebookbar/SfxNotebookBar.cxx +++ b/sfx2/source/notebookbar/SfxNotebookBar.cxx @@ -35,8 +35,24 @@ using namespace css; #define MENUBAR_STR "private:resource/menubar/menubar" bool SfxNotebookBar::m_bLock = false; -Reference SfxNotebookBar::m_xLayoutManager; -css::uno::Reference SfxNotebookBar::m_xFrame; + +static Reference lcl_getLayoutManager( const Reference& xFrame ) +{ + css::uno::Reference xLayoutManager; + + if (xFrame.is()) + { + Reference xPropSet(xFrame, UNO_QUERY); + + if (xPropSet.is()) + { + Any aValue = xPropSet->getPropertyValue("LayoutManager"); + aValue >>= xLayoutManager; + } + } + + return xLayoutManager; +} static OUString lcl_getAppName( vcl::EnumContext::Application eApp ) { @@ -149,15 +165,21 @@ void SfxNotebookBar::CloseMethod(SystemWindow* pSysWindow) pSysWindow->CloseNotebookBar(); } SfxNotebookBar::ShowMenubar(true); - - m_xLayoutManager.clear(); - m_xFrame.clear(); } bool SfxNotebookBar::IsActive() { - const Reference xModuleManager = frame::ModuleManager::create( ::comphelper::getProcessComponentContext() ); - vcl::EnumContext::Application eApp = vcl::EnumContext::GetApplicationEnum(xModuleManager->identify(m_xFrame)); + vcl::EnumContext::Application eApp = vcl::EnumContext::Application::Application_Any; + + if (SfxViewFrame::Current()) + { + const Reference& xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface(); + if (!xFrame.is()) + return false; + + const Reference xModuleManager = frame::ModuleManager::create( ::comphelper::getProcessComponentContext() ); + eApp = vcl::EnumContext::GetApplicationEnum(xModuleManager->identify(xFrame)); + } OUStringBuffer aPath("org.openoffice.Office.UI.ToolbarMode/Applications/"); aPath.append( lcl_getAppName( eApp ) ); @@ -194,11 +216,15 @@ bool SfxNotebookBar::IsActive() void SfxNotebookBar::ExecMethod(SfxBindings& rBindings, const OUString& rUIName) { // Save active UI file name - if ( !rUIName.isEmpty() ) + if ( !rUIName.isEmpty() && SfxViewFrame::Current() ) { - const Reference xModuleManager = frame::ModuleManager::create( ::comphelper::getProcessComponentContext() ); - vcl::EnumContext::Application eApp = vcl::EnumContext::GetApplicationEnum(xModuleManager->identify(m_xFrame)); - lcl_setNotebookbarFileName( eApp, rUIName ); + const Reference& xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface(); + if (xFrame.is()) + { + const Reference xModuleManager = frame::ModuleManager::create( ::comphelper::getProcessComponentContext() ); + vcl::EnumContext::Application eApp = vcl::EnumContext::GetApplicationEnum(xModuleManager->identify(xFrame)); + lcl_setNotebookbarFileName( eApp, rUIName ); + } } // trigger the StateMethod @@ -218,25 +244,12 @@ bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow, { assert(pSysWindow); - m_xFrame = xFrame; - - if (!m_xLayoutManager.is()) - { - Reference xPropSet(xFrame, UNO_QUERY); - - if (xPropSet.is()) - { - Any aValue = xPropSet->getPropertyValue("LayoutManager"); - aValue >>= m_xLayoutManager; - } - } - if (IsActive()) { RemoveListeners(pSysWindow); const Reference xModuleManager = frame::ModuleManager::create( ::comphelper::getProcessComponentContext() ); - vcl::EnumContext::Application eApp = vcl::EnumContext::GetApplicationEnum(xModuleManager->identify(m_xFrame)); + vcl::EnumContext::Application eApp = vcl::EnumContext::GetApplicationEnum(xModuleManager->identify(xFrame)); OUString sFile = lcl_getNotebookbarFileName( eApp ); OUString sNewFile = rUIFile + sFile; OUString sCurrentFile; @@ -313,38 +326,67 @@ IMPL_STATIC_LINK_TYPED(SfxNotebookBar, OpenNotebookbarPopupMenu, NotebookBar*, p if (pNotebookbar) { ScopedVclPtrInstance pMenu; - pMenu->Execute(pNotebookbar, m_xFrame); + if (SfxViewFrame::Current()) + { + const Reference& xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface(); + if (xFrame.is()) + pMenu->Execute(pNotebookbar, xFrame); + } } } void SfxNotebookBar::ShowMenubar(bool bShow) { - if (!m_bLock && m_xLayoutManager.is()) + if (!m_bLock) { m_bLock = true; - m_xLayoutManager->lock(); - if (m_xLayoutManager->getElement(MENUBAR_STR).is()) + if (SfxViewFrame::Current()) { - if (m_xLayoutManager->isElementVisible(MENUBAR_STR) && !bShow) - m_xLayoutManager->hideElement(MENUBAR_STR); - else if(!m_xLayoutManager->isElementVisible(MENUBAR_STR) && bShow) - m_xLayoutManager->showElement(MENUBAR_STR); - } + const Reference& xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface(); + if (xFrame.is()) + { + const Reference& xLayoutManager = + lcl_getLayoutManager(xFrame); + + if (xLayoutManager.is()) + { + xLayoutManager->lock(); - m_xLayoutManager->unlock(); + if (xLayoutManager->getElement(MENUBAR_STR).is()) + { + if (xLayoutManager->isElementVisible(MENUBAR_STR) && !bShow) + xLayoutManager->hideElement(MENUBAR_STR); + else if(!xLayoutManager->isElementVisible(MENUBAR_STR) && bShow) + xLayoutManager->showElement(MENUBAR_STR); + } + + xLayoutManager->unlock(); + } + } + } m_bLock = false; } } void SfxNotebookBar::ToggleMenubar() { - if (m_xLayoutManager.is() && m_xLayoutManager->getElement(MENUBAR_STR).is()) + if (SfxViewFrame::Current()) { - if (m_xLayoutManager->isElementVisible(MENUBAR_STR)) - SfxNotebookBar::ShowMenubar(false); - else - SfxNotebookBar::ShowMenubar(true); + const Reference& xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface(); + if (xFrame.is()) + { + const Reference& xLayoutManager = + lcl_getLayoutManager(xFrame); + + if (xLayoutManager.is() && xLayoutManager->getElement(MENUBAR_STR).is()) + { + if (xLayoutManager->isElementVisible(MENUBAR_STR)) + SfxNotebookBar::ShowMenubar(false); + else + SfxNotebookBar::ShowMenubar(true); + } + } } } -- cgit