diff options
24 files changed, 431 insertions, 83 deletions
diff --git a/extras/source/glade/libreoffice-catalog.xml.in b/extras/source/glade/libreoffice-catalog.xml.in index 017945162449..ec767c48f696 100644 --- a/extras/source/glade/libreoffice-catalog.xml.in +++ b/extras/source/glade/libreoffice-catalog.xml.in @@ -825,7 +825,7 @@ <glade-widget-class title="Show Text" name="cuilo-SvxShowText" generic-name="ShowText" parent="GtkDrawingArea" icon-name="widget-gtk-drawingarea"/> - <glade-widget-class title="Notebook switching tabs depending on context" name="vcllo-NotebookbarTabControl" + <glade-widget-class title="Notebook switching tabs depending on context" name="sfxlo-NotebookbarTabControl" generic-name="NotebookbarTabControl" parent="GtkNotebook" icon-name="widget-gtk-notebook"/> <glade-widget-class title="Slide Transition Pane" name="sdlo-SlideTransitionBox" diff --git a/include/sfx2/notebookbar/NotebookbarContextControl.hxx b/include/sfx2/notebookbar/NotebookbarContextControl.hxx index 348b52101df1..172b25756d8f 100644 --- a/include/sfx2/notebookbar/NotebookbarContextControl.hxx +++ b/include/sfx2/notebookbar/NotebookbarContextControl.hxx @@ -19,7 +19,6 @@ class NotebookbarContextControl public: virtual ~NotebookbarContextControl() {} virtual void SetContext( vcl::EnumContext::Context eContext ) = 0; - virtual void SetIconClickHdl( Link<NotebookBar*, void> aHdl ) = 0; }; #endif // INCLUDED_SFX2_NOTEBOOKBAR_NOTEBOOKBARCONTEXTCONTROL_HXX diff --git a/include/sfx2/notebookbar/NotebookbarTabControl.hxx b/include/sfx2/notebookbar/NotebookbarTabControl.hxx new file mode 100644 index 000000000000..062fe9631f48 --- /dev/null +++ b/include/sfx2/notebookbar/NotebookbarTabControl.hxx @@ -0,0 +1,46 @@ +/* -*- 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/. + */ + +#ifndef INCLUDED_SFX2_NOTEBOOKBAR_NOTEBOOKBARTABCONTROL_HXX +#define INCLUDED_SFX2_NOTEBOOKBAR_NOTEBOOKBARTABCONTROL_HXX + +#include <vcl/toolbox.hxx> +#include <sfx2/dllapi.h> +#include <com/sun/star/frame/XLayoutManager.hpp> +#include <vcl/tabctrl.hxx> + +class ChangedUIEventListener; + +class SFX2_DLLPUBLIC NotebookbarTabControl : public NotebookbarTabControlBase +{ +friend class ChangedUIEventListener; + +public: + NotebookbarTabControl( Window* pParent ); + + virtual void StateChanged(StateChangedType nStateChange) override; + +private: + static void FillShortcutsToolBox(css::uno::Reference<css::uno::XComponentContext>& xContext, + const css::uno::Reference<css::frame::XFrame>& xFrame, + const OUString& aModuleName, + ToolBox* pShortcuts + ); + DECL_STATIC_LINK(NotebookbarTabControl, OpenNotebookbarPopupMenu, NotebookBar*, void); + + ChangedUIEventListener* m_pListener; + +protected: + bool m_bInitialized; + bool m_bInvalidate; +}; + +#endif // INCLUDED_SFX2_NOTEBOOKBAR_NOTEBOOKBARTABCONTROL_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sfx2/notebookbar/SfxNotebookBar.hxx b/include/sfx2/notebookbar/SfxNotebookBar.hxx index 8792eecf3a4f..e87e7d928c45 100644 --- a/include/sfx2/notebookbar/SfxNotebookBar.hxx +++ b/include/sfx2/notebookbar/SfxNotebookBar.hxx @@ -50,8 +50,6 @@ public: private: static bool m_bLock; static bool m_bHide; - - DECL_STATIC_LINK(SfxNotebookBar, OpenNotebookbarPopupMenu, NotebookBar*, void); }; } // namespace sfx2 diff --git a/include/vcl/notebookbar.hxx b/include/vcl/notebookbar.hxx index 9a41152ab505..f16b3ed38976 100644 --- a/include/vcl/notebookbar.hxx +++ b/include/vcl/notebookbar.hxx @@ -32,8 +32,6 @@ public: virtual void setPosSizePixel(long nX, long nY, long nWidth, long nHeight, PosSizeFlags nFlags = PosSizeFlags::All) SAL_OVERRIDE; virtual void Resize() override; - void SetIconClickHdl(Link<NotebookBar*, void> aHdl); - void SetSystemWindow(SystemWindow* pSystemWindow); const css::uno::Reference<css::ui::XContextChangeEventListener>& getContextChangeEventListener() const { return m_pEventListener; } diff --git a/include/vcl/tabctrl.hxx b/include/vcl/tabctrl.hxx index fc7d1a8a9064..bdc1d3289a58 100644 --- a/include/vcl/tabctrl.hxx +++ b/include/vcl/tabctrl.hxx @@ -22,6 +22,7 @@ #include <vcl/dllapi.h> #include <vcl/ctrl.hxx> +#include <vcl/toolbox.hxx> #include <vcl/EnumContext.hxx> #include <sfx2/notebookbar/NotebookbarContextControl.hxx> @@ -190,14 +191,18 @@ public: class NotebookBar; -class VCL_DLLPUBLIC NotebookbarTabControl : public TabControl, +class VCL_DLLPUBLIC NotebookbarTabControlBase : public TabControl, public NotebookbarContextControl { public: - NotebookbarTabControl( vcl::Window* pParent ); + NotebookbarTabControlBase( vcl::Window* pParent ); + ~NotebookbarTabControlBase() override; + void dispose() override; void SetContext( vcl::EnumContext::Context eContext ) override; - void SetIconClickHdl( Link<NotebookBar*, void> aHdl ) override; + void SetIconClickHdl( Link<NotebookBar*, void> aHdl ); + void SetToolBox( ToolBox* pToolBox ); + ToolBox* GetToolBox() { return m_pShortcuts; } virtual sal_uInt16 GetPageId( const Point& rPos ) const override; virtual void SelectTabPage( sal_uInt16 nPageId ) override; @@ -215,6 +220,7 @@ private: vcl::EnumContext::Context eLastContext; Link<NotebookBar*,void> m_aIconClickHdl; static sal_uInt16 m_nHeaderHeight; + VclPtr<ToolBox> m_pShortcuts; }; #endif // INCLUDED_VCL_TABCTRL_HXX diff --git a/officecfg/registry/data/org/openoffice/Office/UI/CalcWindowState.xcu b/officecfg/registry/data/org/openoffice/Office/UI/CalcWindowState.xcu index 0bbaab8d50d5..7614ea3827c0 100644 --- a/officecfg/registry/data/org/openoffice/Office/UI/CalcWindowState.xcu +++ b/officecfg/registry/data/org/openoffice/Office/UI/CalcWindowState.xcu @@ -733,6 +733,17 @@ <value>false</value> </prop> </node> + <node oor:name="private:resource/toolbar/notebookbarshortcuts" oor:op="replace"> + <prop oor:name="UIName" oor:type="xs:string"> + <value xml:lang="en-US">Notebookbar shortcuts</value> + </prop> + <prop oor:name="Visible" oor:type="xs:boolean"> + <value>false</value> + </prop> + <prop oor:name="HideFromToolbarMenu" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> </node> </node> </oor:component-data> diff --git a/officecfg/registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu b/officecfg/registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu index 2f81b1143f78..9cef881c7c83 100644 --- a/officecfg/registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu +++ b/officecfg/registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu @@ -1028,6 +1028,17 @@ <value>false</value> </prop> </node> + <node oor:name="private:resource/toolbar/notebookbarshortcuts" oor:op="replace"> + <prop oor:name="UIName" oor:type="xs:string"> + <value xml:lang="en-US">Notebookbar shortcuts</value> + </prop> + <prop oor:name="Visible" oor:type="xs:boolean"> + <value>false</value> + </prop> + <prop oor:name="HideFromToolbarMenu" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> </node> </node> </oor:component-data> diff --git a/officecfg/registry/data/org/openoffice/Office/UI/WriterWindowState.xcu b/officecfg/registry/data/org/openoffice/Office/UI/WriterWindowState.xcu index 740462ad46c7..ac0b4c2a750c 100644 --- a/officecfg/registry/data/org/openoffice/Office/UI/WriterWindowState.xcu +++ b/officecfg/registry/data/org/openoffice/Office/UI/WriterWindowState.xcu @@ -108,6 +108,17 @@ <value>true</value> </prop> </node> + <node oor:name="private:resource/toolbar/notebookbarshortcuts" oor:op="replace"> + <prop oor:name="UIName" oor:type="xs:string"> + <value xml:lang="en-US">Notebookbar shortcuts</value> + </prop> + <prop oor:name="Visible" oor:type="xs:boolean"> + <value>false</value> + </prop> + <prop oor:name="HideFromToolbarMenu" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> <node oor:name="private:resource/toolbar/findbar" oor:op="replace"> <prop oor:name="DockPos" oor:type="xs:string"> <value>0,1</value> diff --git a/sc/UIConfig_scalc.mk b/sc/UIConfig_scalc.mk index 89527f367a4f..a5e1d6de324e 100644 --- a/sc/UIConfig_scalc.mk +++ b/sc/UIConfig_scalc.mk @@ -79,6 +79,7 @@ $(eval $(call gb_UIConfig_add_toolbarfiles,modules/scalc,\ sc/uiconfig/scalc/toolbar/linesbar \ sc/uiconfig/scalc/toolbar/mediaobjectbar \ sc/uiconfig/scalc/toolbar/moreformcontrols \ + sc/uiconfig/scalc/toolbar/notebookbarshortcuts \ sc/uiconfig/scalc/toolbar/previewbar \ sc/uiconfig/scalc/toolbar/singlemode \ sc/uiconfig/scalc/toolbar/standardbar \ diff --git a/sc/uiconfig/scalc/toolbar/notebookbarshortcuts.xml b/sc/uiconfig/scalc/toolbar/notebookbarshortcuts.xml new file mode 100644 index 000000000000..6bf1a4e8a4b3 --- /dev/null +++ b/sc/uiconfig/scalc/toolbar/notebookbarshortcuts.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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/. + * +--> +<toolbar:toolbar xmlns:toolbar="http://openoffice.org/2001/toolbar" xmlns:xlink="http://www.w3.org/1999/xlink"> + <toolbar:toolbaritem xlink:href=".uno:Open"/> + <toolbar:toolbaritem xlink:href=".uno:Save"/> + <toolbar:toolbaritem xlink:href=".uno:Undo"/> + <toolbar:toolbaritem xlink:href=".uno:Redo"/> +</toolbar:toolbar> diff --git a/sc/uiconfig/scalc/ui/notebookbar.ui b/sc/uiconfig/scalc/ui/notebookbar.ui index f922d4ba7a2a..9ac3e0480b0c 100644 --- a/sc/uiconfig/scalc/ui/notebookbar.ui +++ b/sc/uiconfig/scalc/ui/notebookbar.ui @@ -197,7 +197,7 @@ <property name="can_focus">False</property> <property name="orientation">vertical</property> <child> - <object class="vcllo-NotebookbarTabControl" id="ContextContainer"> + <object class="sfxlo-NotebookbarTabControl" id="ContextContainer"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="hexpand">True</property> diff --git a/sd/UIConfig_simpress.mk b/sd/UIConfig_simpress.mk index f268c0074d62..6bf23ea2f9ae 100644 --- a/sd/UIConfig_simpress.mk +++ b/sd/UIConfig_simpress.mk @@ -85,6 +85,7 @@ $(eval $(call gb_UIConfig_add_toolbarfiles,modules/simpress,\ sd/uiconfig/simpress/toolbar/masterviewtoolbar \ sd/uiconfig/simpress/toolbar/mediaobjectbar \ sd/uiconfig/simpress/toolbar/moreformcontrols \ + sd/uiconfig/simpress/toolbar/notebookbarshortcuts \ sd/uiconfig/simpress/toolbar/optimizetablebar \ sd/uiconfig/simpress/toolbar/optionsbar \ sd/uiconfig/simpress/toolbar/outlinetoolbar \ diff --git a/sd/uiconfig/simpress/toolbar/notebookbarshortcuts.xml b/sd/uiconfig/simpress/toolbar/notebookbarshortcuts.xml new file mode 100644 index 000000000000..6bf1a4e8a4b3 --- /dev/null +++ b/sd/uiconfig/simpress/toolbar/notebookbarshortcuts.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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/. + * +--> +<toolbar:toolbar xmlns:toolbar="http://openoffice.org/2001/toolbar" xmlns:xlink="http://www.w3.org/1999/xlink"> + <toolbar:toolbaritem xlink:href=".uno:Open"/> + <toolbar:toolbaritem xlink:href=".uno:Save"/> + <toolbar:toolbaritem xlink:href=".uno:Undo"/> + <toolbar:toolbaritem xlink:href=".uno:Redo"/> +</toolbar:toolbar> diff --git a/sd/uiconfig/simpress/ui/notebookbar.ui b/sd/uiconfig/simpress/ui/notebookbar.ui index 0dd20814afee..f6c0dccbd7c6 100644 --- a/sd/uiconfig/simpress/ui/notebookbar.ui +++ b/sd/uiconfig/simpress/ui/notebookbar.ui @@ -187,7 +187,7 @@ <property name="can_focus">False</property> <property name="orientation">vertical</property> <child> - <object class="vcllo-NotebookbarTabControl" id="ContextContainer"> + <object class="sfxlo-NotebookbarTabControl" id="ContextContainer"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="hexpand">True</property> 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) diff --git a/sw/UIConfig_swriter.mk b/sw/UIConfig_swriter.mk index 8d51e8c4bc55..41fed854c5d4 100644 --- a/sw/UIConfig_swriter.mk +++ b/sw/UIConfig_swriter.mk @@ -68,6 +68,7 @@ $(eval $(call gb_UIConfig_add_toolbarfiles,modules/swriter,\ sw/uiconfig/swriter/toolbar/mediaobjectbar \ sw/uiconfig/swriter/toolbar/moreformcontrols \ sw/uiconfig/swriter/toolbar/navigationobjectbar \ + sw/uiconfig/swriter/toolbar/notebookbarshortcuts \ sw/uiconfig/swriter/toolbar/numobjectbar \ sw/uiconfig/swriter/toolbar/oleobjectbar \ sw/uiconfig/swriter/toolbar/optimizetablebar \ diff --git a/sw/uiconfig/swriter/toolbar/notebookbarshortcuts.xml b/sw/uiconfig/swriter/toolbar/notebookbarshortcuts.xml new file mode 100644 index 000000000000..6a067ef567fd --- /dev/null +++ b/sw/uiconfig/swriter/toolbar/notebookbarshortcuts.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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/. + * +--> +<toolbar:toolbar xmlns:toolbar="http://openoffice.org/2001/toolbar" xmlns:xlink="http://www.w3.org/1999/xlink"> + <toolbar:toolbaritem xlink:href=".uno:OpenFromWriter"/> + <toolbar:toolbaritem xlink:href=".uno:Save"/> + <toolbar:toolbaritem xlink:href=".uno:Undo"/> + <toolbar:toolbaritem xlink:href=".uno:Redo"/> +</toolbar:toolbar> diff --git a/sw/uiconfig/swriter/ui/notebookbar.ui b/sw/uiconfig/swriter/ui/notebookbar.ui index 21dbfbee0973..9313942dc3b7 100644 --- a/sw/uiconfig/swriter/ui/notebookbar.ui +++ b/sw/uiconfig/swriter/ui/notebookbar.ui @@ -208,7 +208,7 @@ <property name="can_focus">False</property> <property name="orientation">vertical</property> <child> - <object class="vcllo-NotebookbarTabControl" id="ContextContainer"> + <object class="sfxlo-NotebookbarTabControl" id="ContextContainer"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="hexpand">True</property> diff --git a/vcl/source/control/notebookbar.cxx b/vcl/source/control/notebookbar.cxx index 453236012c21..f23e2d57d21a 100644 --- a/vcl/source/control/notebookbar.cxx +++ b/vcl/source/control/notebookbar.cxx @@ -120,12 +120,6 @@ void NotebookBar::Resize() Control::Resize(); } -void NotebookBar::SetIconClickHdl(Link<NotebookBar*, void> aHdl) -{ - if (m_pContextContainer) - m_pContextContainer->SetIconClickHdl(aHdl); -} - void NotebookBar::SetSystemWindow(SystemWindow* pSystemWindow) { m_pSystemWindow = pSystemWindow; diff --git a/vcl/source/control/tabctrl.cxx b/vcl/source/control/tabctrl.cxx index 34dc980808bf..753aa8996a2d 100644 --- a/vcl/source/control/tabctrl.cxx +++ b/vcl/source/control/tabctrl.cxx @@ -2202,11 +2202,9 @@ FactoryFunction TabControl::GetUITestFactory() const return TabControlUIObject::create; } -VCL_BUILDER_FACTORY(NotebookbarTabControl); +sal_uInt16 NotebookbarTabControlBase::m_nHeaderHeight = 0; -sal_uInt16 NotebookbarTabControl::m_nHeaderHeight = 0; - -NotebookbarTabControl::NotebookbarTabControl(vcl::Window* pParent) +NotebookbarTabControlBase::NotebookbarTabControlBase(vcl::Window* pParent) : TabControl(pParent, WB_STDTABCONTROL) , bLastContextWasSupported(true) , eLastContext(vcl::EnumContext::Context::Any) @@ -2216,7 +2214,12 @@ NotebookbarTabControl::NotebookbarTabControl(vcl::Window* pParent) SetPageImage(1, Image(aBitmap)); } -void NotebookbarTabControl::SetContext( vcl::EnumContext::Context eContext ) +NotebookbarTabControlBase::~NotebookbarTabControlBase() +{ + disposeOnce(); +} + +void NotebookbarTabControlBase::SetContext( vcl::EnumContext::Context eContext ) { if (eLastContext != eContext) { @@ -2225,21 +2228,22 @@ void NotebookbarTabControl::SetContext( vcl::EnumContext::Context eContext ) for (int nChild = 0; nChild < GetChildCount(); ++nChild) { TabPage* pPage = static_cast<TabPage*>(GetChild(nChild)); + sal_uInt16 nPageId = TabControl::GetPageId(*pPage); if (pPage->HasContext(eContext) || pPage->HasContext(vcl::EnumContext::Context::Any)) - EnablePage(nChild + 2); + EnablePage(nPageId); else - EnablePage(nChild + 2, false); + EnablePage(nPageId, false); if (!bHandled && bLastContextWasSupported && pPage->HasContext(vcl::EnumContext::Context::Default)) { - SetCurPageId(nChild + 2); + SetCurPageId(nPageId); } if (pPage->HasContext(eContext) && eContext != vcl::EnumContext::Context::Any) { - SetCurPageId(nChild + 2); + SetCurPageId(nPageId); bHandled = true; bLastContextWasSupported = true; } @@ -2251,16 +2255,27 @@ void NotebookbarTabControl::SetContext( vcl::EnumContext::Context eContext ) } } -void NotebookbarTabControl::SetIconClickHdl( Link<NotebookBar*, void> aHdl ) +void NotebookbarTabControlBase::dispose() +{ + m_pShortcuts.disposeAndClear(); + TabControl::dispose(); +} + +void NotebookbarTabControlBase::SetToolBox( ToolBox* pToolBox ) +{ + m_pShortcuts.set( pToolBox ); +} + +void NotebookbarTabControlBase::SetIconClickHdl( Link<NotebookBar*, void> aHdl ) { m_aIconClickHdl = aHdl; } -sal_uInt16 NotebookbarTabControl::GetPageId( const Point& rPos ) const +sal_uInt16 NotebookbarTabControlBase::GetPageId( const Point& rPos ) const { for( size_t i = 0; i < mpTabCtrlData->maItemList.size(); ++i ) { - if ( const_cast<NotebookbarTabControl*>(this)->ImplGetTabRect( static_cast<sal_uInt16>(i) ).IsInside( rPos ) ) + if ( const_cast<NotebookbarTabControlBase*>(this)->ImplGetTabRect( static_cast<sal_uInt16>(i) ).IsInside( rPos ) ) if ( mpTabCtrlData->maItemList[ i ].mbEnabled ) return mpTabCtrlData->maItemList[ i ].mnId; } @@ -2268,10 +2283,10 @@ sal_uInt16 NotebookbarTabControl::GetPageId( const Point& rPos ) const return 0; } -void NotebookbarTabControl::SelectTabPage( sal_uInt16 nPageId ) +void NotebookbarTabControlBase::SelectTabPage( sal_uInt16 nPageId ) { if ( nPageId == 1 ) - m_aIconClickHdl.Call( static_cast<NotebookBar*>(GetParent()) ); + m_aIconClickHdl.Call( static_cast<NotebookBar*>(GetParent()->GetParent()) ); else { TabControl::SelectTabPage( nPageId ); @@ -2279,7 +2294,7 @@ void NotebookbarTabControl::SelectTabPage( sal_uInt16 nPageId ) } } -void NotebookbarTabControl::SetCurPageId( sal_uInt16 nPageId ) +void NotebookbarTabControlBase::SetCurPageId( sal_uInt16 nPageId ) { if ( nPageId != 1 ) { @@ -2290,7 +2305,7 @@ void NotebookbarTabControl::SetCurPageId( sal_uInt16 nPageId ) ImplActivateTabPage( true ); } -void NotebookbarTabControl::ImplActivateTabPage( bool bNext ) +void NotebookbarTabControlBase::ImplActivateTabPage( bool bNext ) { sal_uInt16 nCurPos = GetPagePos( GetCurPageId() ); @@ -2323,12 +2338,12 @@ void NotebookbarTabControl::ImplActivateTabPage( bool bNext ) SelectTabPage( TabControl::GetPageId( nCurPos ) ); } -sal_uInt16 NotebookbarTabControl::GetHeaderHeight() +sal_uInt16 NotebookbarTabControlBase::GetHeaderHeight() { return m_nHeaderHeight; } -bool NotebookbarTabControl::ImplPlaceTabs( long nWidth ) +bool NotebookbarTabControlBase::ImplPlaceTabs( long nWidth ) { if ( nWidth <= 0 ) return false; @@ -2358,6 +2373,7 @@ bool NotebookbarTabControl::ImplPlaceTabs( long nWidth ) nMaxWidth = mnMaxPageWidth; nMaxWidth -= GetItemsOffset().X(); + long nShortcutsWidth = m_pShortcuts != nullptr ? m_pShortcuts->GetSizePixel().getWidth() : 0; long nX = nOffsetX; long nY = nOffsetY; @@ -2376,6 +2392,9 @@ bool NotebookbarTabControl::ImplPlaceTabs( long nWidth ) for( std::vector<ImplTabItem>::iterator it = mpTabCtrlData->maItemList.begin(); it != mpTabCtrlData->maItemList.end(); ++it, ++nIndex ) { + if( it == mpTabCtrlData->maItemList.begin() + 1 ) + nX += nShortcutsWidth; + Size aSize = ImplGetItemSize( &(*it), nMaxWidth ); bool bNewLine = false; @@ -2506,7 +2525,7 @@ bool NotebookbarTabControl::ImplPlaceTabs( long nWidth ) return true; } -void NotebookbarTabControl::ImplPaint(vcl::RenderContext& rRenderContext, const Rectangle& rRect) +void NotebookbarTabControlBase::ImplPaint(vcl::RenderContext& rRenderContext, const Rectangle& rRect) { HideFocus(); @@ -2697,9 +2716,11 @@ void NotebookbarTabControl::ImplPaint(vcl::RenderContext& rRenderContext, const ImplShowFocus(); mbSmallInvalidate = true; + + Control::Paint(rRenderContext, rRect); } -Size NotebookbarTabControl::calculateRequisition() const +Size NotebookbarTabControlBase::calculateRequisition() const { Size aOptimalPageSize(0, 0); @@ -2712,7 +2733,7 @@ Size NotebookbarTabControl::calculateRequisition() const //We need to force all tabs to exist to get overall optimal size for dialog if (!pPage) { - NotebookbarTabControl *pThis = const_cast<NotebookbarTabControl*>(this); + NotebookbarTabControlBase *pThis = const_cast<NotebookbarTabControlBase*>(this); pThis->SetCurPageId(it->mnId); pThis->ActivatePage(); pPage = it->mpTabPage; @@ -2734,7 +2755,7 @@ Size NotebookbarTabControl::calculateRequisition() const //page and re-activate it if (nOrigPageId != GetCurPageId()) { - NotebookbarTabControl *pThis = const_cast<NotebookbarTabControl*>(this); + NotebookbarTabControlBase *pThis = const_cast<NotebookbarTabControlBase*>(this); pThis->SetCurPageId(nOrigPageId); pThis->ActivatePage(); } @@ -2743,7 +2764,7 @@ Size NotebookbarTabControl::calculateRequisition() const for( std::vector< ImplTabItem >::const_iterator it = mpTabCtrlData->maItemList.begin(); it != mpTabCtrlData->maItemList.end(); ++it ) { - NotebookbarTabControl* pThis = const_cast<NotebookbarTabControl*>(this); + NotebookbarTabControlBase* pThis = const_cast<NotebookbarTabControlBase*>(this); sal_uInt16 nPos = it - mpTabCtrlData->maItemList.begin(); Rectangle aTabRect = pThis->ImplGetTabRect(nPos, aOptimalPageSize.Width(), LONG_MAX); |