include/sfx2/notebookbar/SfxNotebookBar.hxx                          |    1 
 include/sfx2/sfxsids.hrc                                             |    1 
 officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu |    5 
 officecfg/registry/data/org/openoffice/Office/UI/Notebookbar.xcu     |    6 
 officecfg/registry/schema/org/openoffice/Office/UI/Notebookbar.xcs   |    5 
 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 
+++++++---
 12 files changed, 183 insertions(+), 30 deletions(-)

New commits:
commit 3b01af931470c82375b4f962beb9f71243001230
Author: Szymon Kłos <eszka...@gmail.com>
Date:   Thu Aug 11 12:07:36 2016 +0200

    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 <c...@libreoffice.org>
    Reviewed-by: Szymon Kłos <eszka...@gmail.com>

diff --git a/include/sfx2/notebookbar/SfxNotebookBar.hxx 
b/include/sfx2/notebookbar/SfxNotebookBar.hxx
index e3735658..12373d1 100644
--- a/include/sfx2/notebookbar/SfxNotebookBar.hxx
+++ b/include/sfx2/notebookbar/SfxNotebookBar.hxx
@@ -40,6 +40,7 @@ public:
     static void RemoveListeners(SystemWindow* pSysWindow);
 
     static void ShowMenubar(bool bShow);
+    static void ToggleMenubar();
 
 private:
     static bool m_bLock;
diff --git a/include/sfx2/sfxsids.hrc b/include/sfx2/sfxsids.hrc
index 2498942..f5561fe 100644
--- a/include/sfx2/sfxsids.hrc
+++ b/include/sfx2/sfxsids.hrc
@@ -545,6 +545,7 @@
 #define SID_SEARCH_ITEM                     (SID_SVX_START + 291)
 #define SID_SIDEBAR                         (SID_SVX_START + 336)
 #define SID_NOTEBOOKBAR                     (SID_SVX_START + 338)
+#define SID_MENUBAR                         (SID_SVX_START + 339)
 #define SID_HYPERLINK_GETLINK               (SID_SVX_START + 361)
 #define SID_HYPERLINK_SETLINK               (SID_SVX_START + 362)
 #define SID_INFOBAR                         (SID_SVX_START + 365)
diff --git 
a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu 
b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
index 0247b17..9f476a5 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
@@ -6130,6 +6130,11 @@
           <value xml:lang="en-US">Paste Special</value>
         </prop>
       </node>
+      <node oor:name=".uno:Menubar" oor:op="replace">
+        <prop oor:name="Label" oor:type="xs:string">
+          <value xml:lang="en-US">Menubar</value>
+        </prop>
+      </node>
     </node>
   </node>
 </oor:component-data>
diff --git a/officecfg/registry/data/org/openoffice/Office/UI/Notebookbar.xcu 
b/officecfg/registry/data/org/openoffice/Office/UI/Notebookbar.xcu
index 3814b3e..2b67a6d 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/Notebookbar.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/Notebookbar.xcu
@@ -12,6 +12,9 @@
       <prop oor:name="File">
         <value>notebookbar.ui</value>
       </prop>
+      <prop oor:name="HasMenubar">
+        <value>false</value>
+      </prop>
     </node>
     <node oor:name="Groups" oor:op="replace">
       <prop oor:name="Label">
@@ -20,6 +23,9 @@
       <prop oor:name="File">
         <value>notebookbar_groups.ui</value>
       </prop>
+      <prop oor:name="HasMenubar">
+        <value>true</value>
+      </prop>
     </node>
   </node>
 </oor:component-data>
diff --git a/officecfg/registry/schema/org/openoffice/Office/UI/Notebookbar.xcs 
b/officecfg/registry/schema/org/openoffice/Office/UI/Notebookbar.xcs
index 51dbeed..ace1d50 100644
--- a/officecfg/registry/schema/org/openoffice/Office/UI/Notebookbar.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/UI/Notebookbar.xcs
@@ -36,6 +36,11 @@
         <desc>The .ui file name.</desc>
       </info>
     </prop>
+    <prop oor:name="HasMenubar" oor:type="xs:boolean" oor:nillable="false">
+      <info>
+        <desc>Determines if menubar is visible.</desc>
+      </info>
+    </prop>
     </group>
   </templates>
   <component>
diff --git a/sfx2/sdi/appslots.sdi b/sfx2/sdi/appslots.sdi
index d103b96..4921f27 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 3afeb51..7c24c75 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 0014f05..1afe604 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 732a716..1c77c86 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 9644b35..35c2495 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 b8ea6c6..8051411 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 41dac9c..e12bead 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: */
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to