summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorSzymon Kłos <eszkadev@gmail.com>2017-02-21 11:31:18 +0100
committerSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2017-03-15 15:54:19 +0000
commite681749ffa5a18c8a6ff874787d4ab8411a46125 (patch)
treeafa5c4095f4d1ef35f007cc64178e71b92c78cd2 /sfx2
parent5411d99c0a7345e9c68ad55debcb20eecdc0b36a (diff)
tdf#105040 Notebookbar: added shortcuts toolbox
In the tabbed notebookbar the shortcuts toolbox is introduced. It is placed before tab labels, after the menu button. Customization is possible, buttons are loaded from the newly created toolbar "Notebookbar shortcuts". NotebookbarTabControl was moved to the sfx module. Change-Id: Ifa4a1688c6e92c2f03bd386608e3e9d1c28069d4 Reviewed-on: https://gerrit.libreoffice.org/35194 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/Library_sfx.mk1
-rw-r--r--sfx2/source/notebookbar/ContextVBox.cxx5
-rw-r--r--sfx2/source/notebookbar/NotebookbarTabControl.cxx241
-rw-r--r--sfx2/source/notebookbar/SfxNotebookBar.cxx42
4 files changed, 247 insertions, 42 deletions
diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk
index 148a9b0d45b9..f0a5a52c0cc2 100644
--- a/sfx2/Library_sfx.mk
+++ b/sfx2/Library_sfx.mk
@@ -242,6 +242,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\
sfx2/source/notebookbar/DropdownBox \
sfx2/source/notebookbar/PriorityHBox \
sfx2/source/notebookbar/SfxNotebookBar \
+ sfx2/source/notebookbar/NotebookbarTabControl \
sfx2/source/notify/eventsupplier \
sfx2/source/notify/globalevents \
sfx2/source/notify/hintpost \
diff --git a/sfx2/source/notebookbar/ContextVBox.cxx b/sfx2/source/notebookbar/ContextVBox.cxx
index a02cc51051ee..a89c9c2938ce 100644
--- a/sfx2/source/notebookbar/ContextVBox.cxx
+++ b/sfx2/source/notebookbar/ContextVBox.cxx
@@ -68,11 +68,6 @@ public:
aSize.Width() += 6;
SetSizePixel( aSize );
}
-
- void SetIconClickHdl( Link<NotebookBar*, void> ) override
- {
- // Menu not supported
- }
};
VCL_BUILDER_FACTORY(ContextVBox)
diff --git a/sfx2/source/notebookbar/NotebookbarTabControl.cxx b/sfx2/source/notebookbar/NotebookbarTabControl.cxx
new file mode 100644
index 000000000000..b4a946502222
--- /dev/null
+++ b/sfx2/source/notebookbar/NotebookbarTabControl.cxx
@@ -0,0 +1,241 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <vcl/builderfactory.hxx>
+#include <vcl/layout.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/notebookbar/NotebookbarTabControl.hxx>
+#include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
+#include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
+#include <com/sun/star/ui/ItemType.hpp>
+#include <com/sun/star/frame/XModuleManager.hpp>
+#include <com/sun/star/frame/ModuleManager.hpp>
+#include <sfx2/notebookbar/SfxNotebookBar.hxx>
+#include <com/sun/star/uno/Reference.h>
+#include <toolkit/awt/vclxmenu.hxx>
+#include <com/sun/star/frame/XPopupMenuController.hpp>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/propertyvalue.hxx>
+#include <sfx2/sidebar/SidebarToolBox.hxx>
+#include <cppuhelper/queryinterface.hxx>
+#include <cppuhelper/implbase.hxx>
+
+#define ICON_SIZE 25
+#define TOOLBAR_STR "private:resource/toolbar/notebookbarshortcuts"
+
+using namespace css::uno;
+using namespace css::ui;
+using namespace css::frame;
+
+class ChangedUIEventListener : public ::cppu::WeakImplHelper<XUIConfigurationListener>
+{
+ VclPtr<NotebookbarTabControl> m_pParent;
+
+public:
+ explicit ChangedUIEventListener(NotebookbarTabControl *p)
+ : m_pParent(p)
+ {
+ try
+ {
+ Reference<XComponentContext> xContext = comphelper::getProcessComponentContext();
+ const Reference<XModuleManager> xModuleManager = ModuleManager::create( xContext );
+ Reference<XFrame> xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface();
+ OUString aModuleName = xModuleManager->identify( xFrame );
+
+ Reference<XUIConfigurationManager> m_xConfigManager;
+ Reference<XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier(
+ theModuleUIConfigurationManagerSupplier::get( xContext ) );
+ m_xConfigManager.set( xModuleCfgMgrSupplier->getUIConfigurationManager( aModuleName ) );
+ css::uno::Reference< css::ui::XUIConfiguration > xConfig( m_xConfigManager, css::uno::UNO_QUERY_THROW );
+ xConfig->addConfigurationListener( this );
+ }
+ catch( const css::uno::RuntimeException& ) {}
+ }
+
+ // XUIConfigurationListener
+ virtual void SAL_CALL elementInserted( const ConfigurationEvent& rEvent ) override
+ {
+ if( rEvent.ResourceURL == TOOLBAR_STR )
+ {
+ m_pParent->m_bInvalidate = true;
+ m_pParent->StateChanged(StateChangedType::UpdateMode);
+ }
+ }
+
+ virtual void SAL_CALL elementRemoved( const ConfigurationEvent& rEvent ) override
+ {
+ elementInserted( rEvent );
+ }
+
+ virtual void SAL_CALL elementReplaced( const ConfigurationEvent& rEvent ) override
+ {
+ elementInserted( rEvent );
+ }
+
+ virtual void SAL_CALL disposing(const ::css::lang::EventObject&) override
+ {
+ m_pParent.clear();
+ }
+};
+
+class ShortcutsToolBox : public sfx2::sidebar::SidebarToolBox
+{
+public:
+ ShortcutsToolBox( Window* pParent )
+ : sfx2::sidebar::SidebarToolBox( pParent )
+ {
+ mbUseDefaultButtonSize = false;
+ SetToolboxButtonSize(ToolBoxButtonSize::Small);
+ }
+};
+
+NotebookbarTabControl::NotebookbarTabControl( Window* pParent )
+: NotebookbarTabControlBase( pParent )
+, m_pListener( nullptr )
+, m_bInitialized( false )
+, m_bInvalidate( true )
+{
+}
+
+void NotebookbarTabControl::StateChanged(StateChangedType nStateChange)
+{
+ if( !m_bInitialized && SfxViewFrame::Current() )
+ {
+ VclPtr<ShortcutsToolBox> pShortcuts = VclPtr<ShortcutsToolBox>::Create( this );
+ pShortcuts->Show();
+
+ SetToolBox( static_cast<ToolBox*>( pShortcuts.get() ) );
+ SetIconClickHdl( LINK( nullptr, NotebookbarTabControl, OpenNotebookbarPopupMenu ) );
+
+ m_pListener = new ChangedUIEventListener( this );
+
+ m_bInitialized = true;
+ }
+ if( m_bInitialized && m_bInvalidate && SfxViewFrame::Current() )
+ {
+ ToolBox* pToolBox = GetToolBox();
+ pToolBox->Clear();
+
+ Reference<XComponentContext> xContext = comphelper::getProcessComponentContext();
+ const Reference<XModuleManager> xModuleManager = ModuleManager::create( xContext );
+ Reference<XFrame> xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface();
+ OUString aModuleName = xModuleManager->identify( xFrame );
+
+ FillShortcutsToolBox( xContext, xFrame, aModuleName, pToolBox );
+
+ Size aSize( pToolBox->GetOptimalSize() );
+ Point aPos( ICON_SIZE + 10, 0 );
+ pToolBox->SetPosSizePixel( aPos, aSize );
+ ImplPlaceTabs( GetSizePixel().getWidth() );
+
+ m_bInvalidate = false;
+ }
+ NotebookbarTabControlBase::StateChanged( nStateChange );
+}
+
+void NotebookbarTabControl::FillShortcutsToolBox(Reference<XComponentContext>& xContext,
+ const Reference<XFrame>& xFrame,
+ const OUString& aModuleName,
+ ToolBox* pShortcuts
+)
+{
+ Reference<::com::sun::star::container::XIndexAccess> xIndex;
+
+ try
+ {
+ Reference<XUIConfigurationManager> m_xConfigManager;
+ Reference<XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier(
+ theModuleUIConfigurationManagerSupplier::get( xContext ) );
+ m_xConfigManager.set( xModuleCfgMgrSupplier->getUIConfigurationManager( aModuleName ) );
+ xIndex = m_xConfigManager->getSettings( TOOLBAR_STR, false );
+ }
+ catch( const Exception& ) {}
+
+ if ( !xIndex.is() )
+ return;
+
+ Sequence< css::beans::PropertyValue > aPropSequence;
+ for ( sal_Int32 i = 0; i < xIndex->getCount(); ++i )
+ {
+ try
+ {
+ if ( xIndex->getByIndex( i ) >>= aPropSequence )
+ {
+ OUString aCommandURL;
+ OUString aLabel;
+ sal_uInt16 nType = ItemType::DEFAULT;
+ bool bVisible = true;
+
+ for ( const auto& aProp: aPropSequence )
+ {
+ if ( aProp.Name == "CommandURL" )
+ aProp.Value >>= aCommandURL;
+ else if ( aProp.Name == "Label" )
+ aProp.Value >>= aLabel;
+ else if ( aProp.Name == "Type" )
+ aProp.Value >>= nType;
+ else if ( aProp.Name == "IsVisible" )
+ aProp.Value >>= bVisible;
+ }
+ if ( bVisible && ( nType == ItemType::DEFAULT ) )
+ pShortcuts->InsertItem( aCommandURL, xFrame, ToolBoxItemBits::ICON_ONLY, Size( ICON_SIZE, ICON_SIZE ) );
+ }
+ }
+ catch ( const Exception& )
+ {
+ break;
+ }
+ }
+}
+
+IMPL_STATIC_LINK(NotebookbarTabControl, OpenNotebookbarPopupMenu, NotebookBar*, pNotebookbar, void)
+{
+ SfxViewFrame* pViewFrame = SfxViewFrame::Current();
+ if (pNotebookbar && pViewFrame)
+ {
+ Sequence<Any> aArgs {
+ makeAny(comphelper::makePropertyValue("Value", OUString("notebookbar"))),
+ makeAny(comphelper::makePropertyValue("Frame", pViewFrame->GetFrame().GetFrameInterface())) };
+
+ Reference<XComponentContext> xContext = comphelper::getProcessComponentContext();
+ Reference<XPopupMenuController> xPopupController(
+ xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+ "com.sun.star.comp.framework.ResourceMenuController", aArgs, xContext), UNO_QUERY);
+
+ Reference<css::awt::XPopupMenu> xPopupMenu(xContext->getServiceManager()->createInstanceWithContext(
+ "com.sun.star.awt.PopupMenu", xContext), UNO_QUERY);
+
+ if (!xPopupController.is() || !xPopupMenu.is())
+ return;
+
+ xPopupController->setPopupMenu(xPopupMenu);
+ VCLXMenu* pAwtMenu = VCLXMenu::GetImplementation(xPopupMenu);
+ PopupMenu* pVCLMenu = static_cast<PopupMenu*>(pAwtMenu->GetMenu());
+ Point aPos(0, NotebookbarTabControl::GetHeaderHeight());
+ pVCLMenu->Execute(pNotebookbar, Rectangle(aPos, aPos),PopupMenuFlags::ExecuteDown|PopupMenuFlags::NoMouseUpClose);
+
+ Reference<css::lang::XComponent> xComponent(xPopupController, UNO_QUERY);
+ if (xComponent.is())
+ xComponent->dispose();
+ }
+}
+
+VCL_BUILDER_FACTORY( NotebookbarTabControl )
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/notebookbar/SfxNotebookBar.cxx b/sfx2/source/notebookbar/SfxNotebookBar.cxx
index 2976f43a6524..15d89bce4205 100644
--- a/sfx2/source/notebookbar/SfxNotebookBar.cxx
+++ b/sfx2/source/notebookbar/SfxNotebookBar.cxx
@@ -270,8 +270,10 @@ bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow,
if (IsActive())
{
- const Reference<frame::XModuleManager> xModuleManager = frame::ModuleManager::create( ::comphelper::getProcessComponentContext() );
- vcl::EnumContext::Application eApp = vcl::EnumContext::GetApplicationEnum(xModuleManager->identify(xFrame));
+ css::uno::Reference<css::uno::XComponentContext> xContext = comphelper::getProcessComponentContext();
+ const Reference<frame::XModuleManager> xModuleManager = frame::ModuleManager::create( xContext );
+ OUString aModuleName = xModuleManager->identify( xFrame );
+ vcl::EnumContext::Application eApp = vcl::EnumContext::GetApplicationEnum( aModuleName );
OUString sFile = lcl_getNotebookbarFileName( eApp );
OUString sNewFile = rUIFile + sFile;
OUString sCurrentFile;
@@ -302,7 +304,6 @@ bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow,
pNotebookBar = pSysWindow->GetNotebookBar();
pNotebookBar->Show();
pNotebookBar->GetParent()->Resize();
- pNotebookBar->SetIconClickHdl( LINK( nullptr, SfxNotebookBar, OpenNotebookbarPopupMenu ) );
utl::OConfigurationTreeRoot aRoot(lcl_getCurrentImplConfigRoot());
const utl::OConfigurationNode aModeNode(lcl_getCurrentImplConfigNode(xFrame, aRoot));
@@ -313,8 +314,7 @@ bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow,
if(pView)
{
Reference<XContextChangeEventMultiplexer> xMultiplexer
- = ContextChangeEventMultiplexer::get(
- ::comphelper::getProcessComponentContext());
+ = ContextChangeEventMultiplexer::get( xContext );
if(xFrame.is())
{
@@ -350,38 +350,6 @@ void SfxNotebookBar::RemoveListeners(SystemWindow* pSysWindow)
}
}
-IMPL_STATIC_LINK(SfxNotebookBar, OpenNotebookbarPopupMenu, NotebookBar*, pNotebookbar, void)
-{
- SfxViewFrame* pViewFrame = SfxViewFrame::Current();
- if (pNotebookbar && pViewFrame)
- {
- css::uno::Sequence<css::uno::Any> aArgs {
- css::uno::makeAny(comphelper::makePropertyValue("Value", OUString("notebookbar"))),
- css::uno::makeAny(comphelper::makePropertyValue("Frame", pViewFrame->GetFrame().GetFrameInterface())) };
-
- css::uno::Reference<css::uno::XComponentContext> xContext = comphelper::getProcessComponentContext();
- css::uno::Reference<css::frame::XPopupMenuController> xPopupController(
- xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
- "com.sun.star.comp.framework.ResourceMenuController", aArgs, xContext), css::uno::UNO_QUERY);
-
- css::uno::Reference<css::awt::XPopupMenu> xPopupMenu(xContext->getServiceManager()->createInstanceWithContext(
- "com.sun.star.awt.PopupMenu", xContext), css::uno::UNO_QUERY);
-
- if (!xPopupController.is() || !xPopupMenu.is())
- return;
-
- xPopupController->setPopupMenu(xPopupMenu);
- VCLXMenu* pAwtMenu = VCLXMenu::GetImplementation(xPopupMenu);
- PopupMenu* pVCLMenu = static_cast<PopupMenu*>(pAwtMenu->GetMenu());
- Point aPos(0, NotebookbarTabControl::GetHeaderHeight());
- pVCLMenu->Execute(pNotebookbar, Rectangle(aPos, aPos),PopupMenuFlags::ExecuteDown|PopupMenuFlags::NoMouseUpClose);
-
- css::uno::Reference<css::lang::XComponent> xComponent(xPopupController, css::uno::UNO_QUERY);
- if (xComponent.is())
- xComponent->dispose();
- }
-}
-
void SfxNotebookBar::ShowMenubar(bool bShow)
{
if (!m_bLock)