summaryrefslogtreecommitdiff
path: root/sfx2/source
diff options
context:
space:
mode:
authorSzymon Kłos <eszkadev@gmail.com>2016-09-12 16:26:41 +0200
committerChristian Lohmaier <lohmaier+LibreOffice@googlemail.com>2016-09-26 11:02:56 +0000
commit5bd2931b57a6cb4ac1f39d7ddae874ac693cfab0 (patch)
treee44a33988a1a800f424cc6cadcc0623100a63106 /sfx2/source
parent808ba5ac050fb5c9b3e1c77cb71feff1cf1a664e (diff)
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 <ci@libreoffice.org> Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'sfx2/source')
-rw-r--r--sfx2/source/control/dispatch.cxx6
-rw-r--r--sfx2/source/notebookbar/NotebookBarPopupMenu.cxx2
-rw-r--r--sfx2/source/notebookbar/NotebookBarPopupMenu.hxx2
-rw-r--r--sfx2/source/notebookbar/SfxNotebookBar.cxx122
4 files changed, 90 insertions, 42 deletions
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<css::frame::XFrame>& xFrame)
+ const Reference<css::frame::XFrame>& 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<css::frame::XFrame>& xFrame);
+ const css::uno::Reference<css::frame::XFrame>& 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<css::frame::XLayoutManager> SfxNotebookBar::m_xLayoutManager;
-css::uno::Reference<css::frame::XFrame> SfxNotebookBar::m_xFrame;
+
+static Reference<frame::XLayoutManager> lcl_getLayoutManager( const Reference<frame::XFrame>& xFrame )
+{
+ css::uno::Reference<css::frame::XLayoutManager> xLayoutManager;
+
+ if (xFrame.is())
+ {
+ Reference<css::beans::XPropertySet> 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<frame::XModuleManager> 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<frame::XFrame>& xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface();
+ if (!xFrame.is())
+ return false;
+
+ const Reference<frame::XModuleManager> 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<frame::XModuleManager> xModuleManager = frame::ModuleManager::create( ::comphelper::getProcessComponentContext() );
- vcl::EnumContext::Application eApp = vcl::EnumContext::GetApplicationEnum(xModuleManager->identify(m_xFrame));
- lcl_setNotebookbarFileName( eApp, rUIName );
+ const Reference<frame::XFrame>& xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface();
+ if (xFrame.is())
+ {
+ const Reference<frame::XModuleManager> 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<css::beans::XPropertySet> xPropSet(xFrame, UNO_QUERY);
-
- if (xPropSet.is())
- {
- Any aValue = xPropSet->getPropertyValue("LayoutManager");
- aValue >>= m_xLayoutManager;
- }
- }
-
if (IsActive())
{
RemoveListeners(pSysWindow);
const Reference<frame::XModuleManager> 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<NotebookBarPopupMenu> pMenu;
- pMenu->Execute(pNotebookbar, m_xFrame);
+ if (SfxViewFrame::Current())
+ {
+ const Reference<frame::XFrame>& 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<frame::XFrame>& xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface();
+ if (xFrame.is())
+ {
+ const Reference<frame::XLayoutManager>& 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<frame::XFrame>& xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface();
+ if (xFrame.is())
+ {
+ const Reference<frame::XLayoutManager>& xLayoutManager =
+ lcl_getLayoutManager(xFrame);
+
+ if (xLayoutManager.is() && xLayoutManager->getElement(MENUBAR_STR).is())
+ {
+ if (xLayoutManager->isElementVisible(MENUBAR_STR))
+ SfxNotebookBar::ShowMenubar(false);
+ else
+ SfxNotebookBar::ShowMenubar(true);
+ }
+ }
}
}