summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorSzymon Kłos <eszkadev@gmail.com>2016-08-11 12:07:36 +0200
committerSzymon Kłos <eszkadev@gmail.com>2016-08-25 16:55:05 +0000
commit3b01af931470c82375b4f962beb9f71243001230 (patch)
tree79c7ec0bc2582bb8d99c4d62e81d5a361d3dc642 /sfx2
parent1594fd83c303139692c5dd6a7f2e236dbf99638e (diff)
GSoC notebookbar: hiding menubar
+ 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 <ci@libreoffice.org> Reviewed-by: Szymon Kłos <eszkadev@gmail.com>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/sdi/appslots.sdi5
-rw-r--r--sfx2/sdi/sfx.sdi16
-rw-r--r--sfx2/source/appl/appserv.cxx46
-rw-r--r--sfx2/source/dialog/dialog.src6
-rw-r--r--sfx2/source/notebookbar/NotebookBarPopupMenu.cxx5
-rw-r--r--sfx2/source/notebookbar/NotebookBarPopupMenu.hxx2
-rw-r--r--sfx2/source/notebookbar/SfxNotebookBar.cxx115
7 files changed, 165 insertions, 30 deletions
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
@@ -162,6 +162,12 @@ Menu RID_MENU_NOTEBOOKBAR
};
MenuItem
{
+ Identifier = SID_MENUBAR;
+ Command = ".uno:Menubar";
+ Text [ en-US ] = "Menubar" ;
+ };
+ MenuItem
+ {
Identifier = SID_OPTIONS;
Command = ".uno:OptionsTreeDialog";
Text [ en-US ] = "Options" ;
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 <sfx2/sfxresid.hxx>
#include "NotebookBarPopupMenu.hxx"
#include <vcl/tabctrl.hxx>
+#include <sfx2/notebookbar/SfxNotebookBar.hxx>
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<css::frame::XFrame>& 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<css::frame::XLayoutManager> SfxNotebookBar::m_xLayoutManager;
css::uno::Reference<css::frame::XFrame> 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<frame::XModuleManager> 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<OUString> 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<OUString> 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<NotebookBarPopupMenu> pMenu(SfxResId(RID_MENU_NOTEBOOKBAR));
+ ScopedVclPtrInstance<NotebookBarPopupMenu> 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: */