From 3b01af931470c82375b4f962beb9f71243001230 Mon Sep 17 00:00:00 2001 From: Szymon Kłos Date: Thu, 11 Aug 2016 12:07:36 +0200 Subject: GSoC notebookbar: hiding menubar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + node in the Notebookbar.xcu determines if menubar is visible for each implementation + new .uno:Menubar command (toggles menubar's visibility) Change-Id: I8ee4ec5bdb78556a8561cc328cba8ecd9bbef60d Reviewed-on: https://gerrit.libreoffice.org/28044 Tested-by: Jenkins Reviewed-by: Szymon Kłos --- sfx2/sdi/appslots.sdi | 5 + sfx2/sdi/sfx.sdi | 16 ++++ sfx2/source/appl/appserv.cxx | 46 +++++++++ sfx2/source/dialog/dialog.src | 6 ++ sfx2/source/notebookbar/NotebookBarPopupMenu.cxx | 5 +- sfx2/source/notebookbar/NotebookBarPopupMenu.hxx | 2 +- sfx2/source/notebookbar/SfxNotebookBar.cxx | 115 +++++++++++++++++------ 7 files changed, 165 insertions(+), 30 deletions(-) (limited to 'sfx2') diff --git a/sfx2/sdi/appslots.sdi b/sfx2/sdi/appslots.sdi index d103b962669a..4921f27e0d3e 100644 --- a/sfx2/sdi/appslots.sdi +++ b/sfx2/sdi/appslots.sdi @@ -220,6 +220,11 @@ interface Application [ ExecMethod = MiscExec_Impl ; ] + SID_MENUBAR + [ + ExecMethod = MiscExec_Impl ; + StateMethod = MiscState_Impl ; + ] } diff --git a/sfx2/sdi/sfx.sdi b/sfx2/sdi/sfx.sdi index 3afeb51b32d2..7c24c75f65d7 100644 --- a/sfx2/sdi/sfx.sdi +++ b/sfx2/sdi/sfx.sdi @@ -2623,6 +2623,22 @@ SfxBoolItem Sidebar SID_SIDEBAR GroupId = GID_VIEW; ] +SfxBoolItem Menubar SID_MENUBAR +[ + AutoUpdate = TRUE, + FastCall = FALSE, + ReadOnlyDoc = TRUE, + Toggle = FALSE, + Container = FALSE, + RecordAbsolute = FALSE, + RecordPerSet; + Asynchron; + + AccelConfig = FALSE, + MenuConfig = TRUE, + ToolBoxConfig = TRUE, + GroupId = GID_VIEW; +] SfxBoolItem Notebookbar SID_NOTEBOOKBAR (SfxStringItem File SID_NOTEBOOKBAR) diff --git a/sfx2/source/appl/appserv.cxx b/sfx2/source/appl/appserv.cxx index 0014f059c469..1afe604918c8 100644 --- a/sfx2/source/appl/appserv.cxx +++ b/sfx2/source/appl/appserv.cxx @@ -944,6 +944,12 @@ void SfxApplication::MiscExec_Impl( SfxRequest& rReq ) bDone = true; break; } + case SID_MENUBAR: + { + sfx2::SfxNotebookBar::ToggleMenubar(); + bDone = true; + break; + } default: break; @@ -1080,6 +1086,46 @@ void SfxApplication::MiscState_Impl(SfxItemSet &rSet) } break; + case SID_MENUBAR: + { + Reference < XDesktop2 > xDesktop = Desktop::create ( ::comphelper::getProcessComponentContext() ); + Reference< XFrame > xFrame = xDesktop->getActiveFrame(); + + Reference< css::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY ); + Reference< css::frame::XLayoutManager > xLayoutManager; + if ( xPropSet.is() ) + { + try + { + Any aValue = xPropSet->getPropertyValue("LayoutManager"); + aValue >>= xLayoutManager; + } + catch ( const css::uno::RuntimeException& ) + { + throw; + } + catch ( css::uno::Exception& ) + { + } + } + + if ( xLayoutManager.is() ) + { + bool bState = true; + if ( xLayoutManager->getElement( "private:resource/menubar/menubar" ).is() + && xLayoutManager->isElementVisible( "private:resource/menubar/menubar" ) ) + bState = true; + else + bState = false; + + SfxBoolItem aItem( SID_MENUBAR, bState ); + rSet.Put( aItem ); + } + if ( Application::GetToolkitName().compareTo( "gtk3" ) == 0 ) + rSet.DisableItem( SID_MENUBAR ); + break; + } + default: break; } diff --git a/sfx2/source/dialog/dialog.src b/sfx2/source/dialog/dialog.src index 732a716b1ecd..1c77c86e6ec6 100644 --- a/sfx2/source/dialog/dialog.src +++ b/sfx2/source/dialog/dialog.src @@ -161,6 +161,12 @@ Menu RID_MENU_NOTEBOOKBAR Text [ en-US ] = "Print" ; }; MenuItem + { + Identifier = SID_MENUBAR; + Command = ".uno:Menubar"; + Text [ en-US ] = "Menubar" ; + }; + MenuItem { Identifier = SID_OPTIONS; Command = ".uno:OptionsTreeDialog"; diff --git a/sfx2/source/notebookbar/NotebookBarPopupMenu.cxx b/sfx2/source/notebookbar/NotebookBarPopupMenu.cxx index 9644b35a9462..35c2495387d0 100644 --- a/sfx2/source/notebookbar/NotebookBarPopupMenu.cxx +++ b/sfx2/source/notebookbar/NotebookBarPopupMenu.cxx @@ -16,13 +16,14 @@ #include #include "NotebookBarPopupMenu.hxx" #include +#include using namespace sfx2; using namespace css::uno; using namespace css::ui; -NotebookBarPopupMenu::NotebookBarPopupMenu(ResId aRes) - : PopupMenu(aRes) +NotebookBarPopupMenu::NotebookBarPopupMenu() + : PopupMenu(SfxResId(RID_MENU_NOTEBOOKBAR)) { if (SfxViewFrame::Current()) { diff --git a/sfx2/source/notebookbar/NotebookBarPopupMenu.hxx b/sfx2/source/notebookbar/NotebookBarPopupMenu.hxx index b8ea6c6aec88..80514113a075 100644 --- a/sfx2/source/notebookbar/NotebookBarPopupMenu.hxx +++ b/sfx2/source/notebookbar/NotebookBarPopupMenu.hxx @@ -15,7 +15,7 @@ class NotebookBarPopupMenu : public PopupMenu { public: - explicit NotebookBarPopupMenu(ResId aRes); + explicit NotebookBarPopupMenu(); void Execute(NotebookBar* pNotebookbar, css::uno::Reference& xFrame); }; diff --git a/sfx2/source/notebookbar/SfxNotebookBar.cxx b/sfx2/source/notebookbar/SfxNotebookBar.cxx index 41dac9c5c900..e12beadc2886 100644 --- a/sfx2/source/notebookbar/SfxNotebookBar.cxx +++ b/sfx2/source/notebookbar/SfxNotebookBar.cxx @@ -38,6 +38,64 @@ bool SfxNotebookBar::m_bLock = false; Reference SfxNotebookBar::m_xLayoutManager; css::uno::Reference SfxNotebookBar::m_xFrame; +static OUString lcl_getAppName( vcl::EnumContext::Application eApp ) +{ + switch ( eApp ) + { + case vcl::EnumContext::Application::Application_Writer: + return OUString( "Writer" ); + break; + case vcl::EnumContext::Application::Application_Calc: + return OUString( "Calc" ); + break; + case vcl::EnumContext::Application::Application_Impress: + return OUString( "Impress" ); + break; + case vcl::EnumContext::Application::Application_Draw: + return OUString( "Draw" ); + break; + default: + return OUString( "" ); + break; + } +} + +static const utl::OConfigurationNode lcl_getCurrentImplConfigNode() +{ + const Reference xModuleManager = frame::ModuleManager::create( ::comphelper::getProcessComponentContext() ); + + OUStringBuffer aPath("org.openoffice.Office.UI.Notebookbar/"); + + const utl::OConfigurationTreeRoot aNotebookbarNode( + ::comphelper::getProcessComponentContext(), + aPath.makeStringAndClear(), + false); + if ( !aNotebookbarNode.isValid() ) + return utl::OConfigurationNode(); + + OUString aActive = comphelper::getString( aNotebookbarNode.getNodeValue( "Active" ) ); + + const utl::OConfigurationNode aImplsNode = aNotebookbarNode.openNode("Implementations"); + const Sequence aModeNodeNames( aImplsNode.getNodeNames() ); + const sal_Int32 nCount( aModeNodeNames.getLength() ); + + for ( sal_Int32 nReadIndex = 0; nReadIndex < nCount; ++nReadIndex ) + { + const utl::OConfigurationNode aImplNode( aImplsNode.openNode( aModeNodeNames[nReadIndex] ) ); + if ( !aImplNode.isValid() ) + continue; + + OUString aCommandArg = comphelper::getString( aImplNode.getNodeValue( "File" ) ); + + if ( aCommandArg.compareTo( aActive ) == 0 ) + { + return aImplNode; + } + } + + return utl::OConfigurationNode(); +} + void SfxNotebookBar::CloseMethod(SfxBindings& rBindings) { SfxFrame& rFrame = rBindings.GetDispatcher_Impl()->GetFrame()->GetFrame(); @@ -52,6 +110,8 @@ void SfxNotebookBar::CloseMethod(SystemWindow* pSysWindow) if(pSysWindow->GetNotebookBar()) pSysWindow->CloseNotebookBar(); } + SfxNotebookBar::ShowMenubar(true); + m_xLayoutManager.clear(); m_xFrame.clear(); } @@ -62,23 +122,7 @@ bool SfxNotebookBar::IsActive() vcl::EnumContext::Application eApp = vcl::EnumContext::GetApplicationEnum(xModuleManager->identify(m_xFrame)); OUStringBuffer aPath("org.openoffice.Office.UI.ToolbarMode/Applications/"); - switch ( eApp ) - { - case vcl::EnumContext::Application::Application_Writer: - aPath.append("Writer"); - break; - case vcl::EnumContext::Application::Application_Calc: - aPath.append("Calc"); - break; - case vcl::EnumContext::Application::Application_Impress: - aPath.append("Impress"); - break; - case vcl::EnumContext::Application::Application_Draw: - aPath.append("Draw"); - break; - default: - break; - } + aPath.append( lcl_getAppName( eApp ) ); const utl::OConfigurationTreeRoot aAppNode( ::comphelper::getProcessComponentContext(), @@ -92,7 +136,6 @@ bool SfxNotebookBar::IsActive() const utl::OConfigurationNode aModesNode = aAppNode.openNode("Modes"); const Sequence aModeNodeNames( aModesNode.getNodeNames() ); const sal_Int32 nCount( aModeNodeNames.getLength() ); - bool bNotebookbarVisible = false; for ( sal_Int32 nReadIndex = 0; nReadIndex < nCount; ++nReadIndex ) { @@ -104,11 +147,10 @@ bool SfxNotebookBar::IsActive() if ( aCommandArg.compareTo( aActive ) == 0 ) { - bNotebookbarVisible = comphelper::getBOOL( aModeNode.getNodeValue( "HasNotebookbar" ) ); - break; + return comphelper::getBOOL( aModeNode.getNodeValue( "HasNotebookbar" ) ); } } - return bNotebookbarVisible; + return false; } void SfxNotebookBar::ExecMethod(SfxBindings& rBindings, const OUString& rUIName) @@ -164,10 +206,12 @@ bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow, // setup if necessary pSysWindow->SetNotebookBar(aBuf.makeStringAndClear(), xFrame); - pSysWindow->GetNotebookBar()->Show(); pSysWindow->GetNotebookBar()->SetIconClickHdl(LINK(nullptr, SfxNotebookBar, OpenNotebookbarPopupMenu)); + const utl::OConfigurationNode aModeNode( lcl_getCurrentImplConfigNode() ); + SfxNotebookBar::ShowMenubar( comphelper::getBOOL( aModeNode.getNodeValue( "HasMenubar" ) ) ); + SfxViewFrame* pView = SfxViewFrame::Current(); if(pView) @@ -188,7 +232,10 @@ bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow, return true; } else if (auto pNotebookBar = pSysWindow->GetNotebookBar()) + { pNotebookBar->Hide(); + SfxNotebookBar::ShowMenubar(true); + } return false; } @@ -210,7 +257,7 @@ IMPL_STATIC_LINK_TYPED(SfxNotebookBar, OpenNotebookbarPopupMenu, NotebookBar*, p { if (pNotebookbar) { - ScopedVclPtrInstance pMenu(SfxResId(RID_MENU_NOTEBOOKBAR)); + ScopedVclPtrInstance pMenu; pMenu->Execute(pNotebookbar, m_xFrame); } } @@ -222,14 +269,28 @@ void SfxNotebookBar::ShowMenubar(bool bShow) m_bLock = true; m_xLayoutManager->lock(); - if (m_xLayoutManager->getElement(MENUBAR_STR).is() && !bShow) - m_xLayoutManager->destroyElement(MENUBAR_STR); - else if(!m_xLayoutManager->getElement(MENUBAR_STR).is() && bShow) - m_xLayoutManager->createElement(MENUBAR_STR); + if (m_xLayoutManager->getElement(MENUBAR_STR).is()) + { + 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); + } m_xLayoutManager->unlock(); m_bLock = false; } } +void SfxNotebookBar::ToggleMenubar() +{ + if (m_xLayoutManager.is() && m_xLayoutManager->getElement(MENUBAR_STR).is()) + { + if (m_xLayoutManager->isElementVisible(MENUBAR_STR)) + SfxNotebookBar::ShowMenubar(false); + else + SfxNotebookBar::ShowMenubar(true); + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit