diff options
author | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2016-04-15 13:38:17 +0200 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2016-04-15 13:01:15 +0000 |
commit | 7ae232623a423b078dd54d06e5fe52e89994b391 (patch) | |
tree | b5f9ded5554be23b46f15c751a52ca07b6a67bb2 | |
parent | 9a081c5cb56c834e7b63ee1ad5b88f11119891ff (diff) |
tdf#95845 Use CommandInfoProvider in forms
Change-Id: I697f8c442cc4db7b38601c32fb71e0201f145354
Reviewed-on: https://gerrit.libreoffice.org/24106
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
-rw-r--r-- | forms/Library_frm.mk | 1 | ||||
-rw-r--r-- | forms/source/helper/commanddescriptionprovider.cxx | 123 | ||||
-rw-r--r-- | forms/source/inc/commanddescriptionprovider.hxx | 60 | ||||
-rw-r--r-- | forms/source/solar/component/navbarcontrol.cxx | 7 | ||||
-rw-r--r-- | forms/source/solar/control/navtoolbar.cxx | 13 | ||||
-rw-r--r-- | forms/source/solar/inc/navtoolbar.hxx | 5 | ||||
-rw-r--r-- | include/vcl/commandinfoprovider.hxx | 2 | ||||
-rw-r--r-- | vcl/source/helper/commandinfoprovider.cxx | 7 |
8 files changed, 18 insertions, 200 deletions
diff --git a/forms/Library_frm.mk b/forms/Library_frm.mk index 0199d38a30ae..494ca4b86689 100644 --- a/forms/Library_frm.mk +++ b/forms/Library_frm.mk @@ -95,7 +95,6 @@ $(eval $(call gb_Library_add_exception_objects,frm,\ forms/source/component/scrollbar \ forms/source/component/spinbutton \ forms/source/component/Time \ - forms/source/helper/commanddescriptionprovider \ forms/source/helper/commandimageprovider \ forms/source/helper/controlfeatureinterception \ forms/source/helper/formnavigation \ diff --git a/forms/source/helper/commanddescriptionprovider.cxx b/forms/source/helper/commanddescriptionprovider.cxx deleted file mode 100644 index 07b56c355d50..000000000000 --- a/forms/source/helper/commanddescriptionprovider.cxx +++ /dev/null @@ -1,123 +0,0 @@ -/* -*- 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 "commanddescriptionprovider.hxx" - -#include <com/sun/star/container/XNameAccess.hpp> -#include <com/sun/star/frame/ModuleManager.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/frame/theUICommandDescription.hpp> - -#include <comphelper/namedvaluecollection.hxx> -#include <tools/diagnose_ex.h> - - -namespace frm -{ - - - using ::com::sun::star::uno::Reference; - using ::com::sun::star::uno::XInterface; - using ::com::sun::star::uno::UNO_QUERY_THROW; - using ::com::sun::star::uno::Exception; - using ::com::sun::star::uno::RuntimeException; - using ::com::sun::star::uno::XComponentContext; - using ::com::sun::star::frame::XModel; - using ::com::sun::star::container::XNameAccess; - using ::com::sun::star::frame::ModuleManager; - using ::com::sun::star::frame::XModuleManager2; - using ::com::sun::star::beans::PropertyValue; - using ::com::sun::star::frame::theUICommandDescription; - - class DefaultCommandDescriptionProvider : public ICommandDescriptionProvider - { - public: - DefaultCommandDescriptionProvider( const Reference<XComponentContext>& _rxContext, const Reference< XModel >& _rxDocument ) - { - impl_init_nothrow( _rxContext, _rxDocument ); - } - - virtual ~DefaultCommandDescriptionProvider() - { - } - - // ICommandDescriptionProvider - virtual OUString getCommandDescription( const OUString& _rCommandURL ) const override; - - private: - void impl_init_nothrow( const Reference<XComponentContext>& _rxContext, const Reference< XModel >& _rxDocument ); - - private: - Reference< XNameAccess > m_xCommandAccess; - }; - - - void DefaultCommandDescriptionProvider::impl_init_nothrow( const Reference<XComponentContext>& _rxContext, const Reference< XModel >& _rxDocument ) - { - OSL_ENSURE( _rxDocument.is(), "DefaultCommandDescriptionProvider::impl_init_nothrow: no document => no command descriptions!" ); - if ( !_rxDocument.is() ) - return; - - try - { - Reference< XModuleManager2 > xModuleManager( ModuleManager::create(_rxContext) ); - OUString sModuleID = xModuleManager->identify( _rxDocument ); - - Reference< XNameAccess > xUICommandDescriptions( theUICommandDescription::get(_rxContext) ); - m_xCommandAccess.set( xUICommandDescriptions->getByName( sModuleID ), UNO_QUERY_THROW ); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - } - - - OUString DefaultCommandDescriptionProvider::getCommandDescription( const OUString& _rCommandURL ) const - { - if ( !m_xCommandAccess.is() ) - return OUString(); - - try - { - ::comphelper::NamedValueCollection aCommandProperties( m_xCommandAccess->getByName( _rCommandURL ) ); - return aCommandProperties.getOrDefault( "Name", OUString() ); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - - return OUString(); - } - - - PCommandDescriptionProvider createDocumentCommandDescriptionProvider( - const Reference<XComponentContext>& _rxContext, const Reference< XModel >& _rxDocument ) - { - PCommandDescriptionProvider pDescriptionProvider( new DefaultCommandDescriptionProvider( _rxContext, _rxDocument ) ); - return pDescriptionProvider; - } - - -} // namespace frm - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/forms/source/inc/commanddescriptionprovider.hxx b/forms/source/inc/commanddescriptionprovider.hxx deleted file mode 100644 index cff411e3dcc0..000000000000 --- a/forms/source/inc/commanddescriptionprovider.hxx +++ /dev/null @@ -1,60 +0,0 @@ -/* -*- 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 . - */ - -#ifndef INCLUDED_FORMS_SOURCE_INC_COMMANDDESCRIPTIONPROVIDER_HXX -#define INCLUDED_FORMS_SOURCE_INC_COMMANDDESCRIPTIONPROVIDER_HXX - -#include <com/sun/star/frame/XModel.hpp> -#include <com/sun/star/uno/XComponentContext.hpp> - -#include <memory> - - -namespace frm -{ - - - //= ICommandDescriptionProvider - - class SAL_NO_VTABLE ICommandDescriptionProvider - { - public: - virtual OUString getCommandDescription( const OUString& _rCommandURL ) const = 0; - - virtual ~ICommandDescriptionProvider() { } - }; - - typedef std::shared_ptr< const ICommandDescriptionProvider > PCommandDescriptionProvider; - - - //= factory - - PCommandDescriptionProvider - createDocumentCommandDescriptionProvider( - const css::uno::Reference< css::uno::XComponentContext >& _rxContext, - const css::uno::Reference< css::frame::XModel >& _rxDocument - ); - - -} // namespace frm - - -#endif // INCLUDED_FORMS_SOURCE_INC_COMMANDDESCRIPTIONPROVIDER_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/forms/source/solar/component/navbarcontrol.cxx b/forms/source/solar/component/navbarcontrol.cxx index cc7be7a83ecb..91f6a8a82f1c 100644 --- a/forms/source/solar/component/navbarcontrol.cxx +++ b/forms/source/solar/component/navbarcontrol.cxx @@ -24,13 +24,13 @@ #include "componenttools.hxx" #include "navtoolbar.hxx" #include "commandimageprovider.hxx" -#include "commanddescriptionprovider.hxx" #include <com/sun/star/awt/XView.hpp> #include <com/sun/star/awt/PosSize.hpp> #include <com/sun/star/form/runtime/FormFeature.hpp> #include <com/sun/star/awt/XControlModel.hpp> #include <com/sun/star/graphic/XGraphic.hpp> +#include <com/sun/star/frame/ModuleManager.hpp> #include <comphelper/processfactory.hxx> #include <tools/debug.hxx> @@ -223,11 +223,14 @@ namespace frm // the VCL control for the peer Reference< XModel > xContextDocument( getXModel( _rxModel ) ); + Reference< XModuleManager2 > xModuleManager( ModuleManager::create(_rxORB) ); + OUString sModuleID = xModuleManager->identify( xContextDocument ); + VclPtrInstance<NavigationToolBar> pNavBar( _pParentWindow, lcl_getWinBits_nothrow( _rxModel ), createDocumentCommandImageProvider( _rxORB, xContextDocument ), - createDocumentCommandDescriptionProvider( _rxORB, xContextDocument ) + sModuleID ); // some knittings diff --git a/forms/source/solar/control/navtoolbar.cxx b/forms/source/solar/control/navtoolbar.cxx index 79b75cab1e04..6fda36fed5ee 100644 --- a/forms/source/solar/control/navtoolbar.cxx +++ b/forms/source/solar/control/navtoolbar.cxx @@ -23,13 +23,13 @@ #include "featuredispatcher.hxx" #include "frm_resource.hrc" #include "commandimageprovider.hxx" -#include "commanddescriptionprovider.hxx" #include <com/sun/star/uno/Any.hxx> #include <com/sun/star/form/runtime/FormFeature.hpp> #include <sfx2/imgmgr.hxx> #include <vcl/fixed.hxx> +#include <vcl/commandinfoprovider.hxx> #include <sal/macros.h> @@ -131,14 +131,15 @@ namespace frm } } - NavigationToolBar::NavigationToolBar( vcl::Window* _pParent, WinBits _nStyle, const PCommandImageProvider& _pImageProvider, - const PCommandDescriptionProvider& _pDescriptionProvider ) + NavigationToolBar::NavigationToolBar( vcl::Window* _pParent, WinBits _nStyle, + const PCommandImageProvider& _pImageProvider, + const OUString sModuleId ) :Window( _pParent, _nStyle ) ,m_pDispatcher( nullptr ) ,m_pImageProvider( _pImageProvider ) - ,m_pDescriptionProvider( _pDescriptionProvider ) ,m_eImageSize( eSmall ) ,m_pToolbar( nullptr ) + ,m_sModuleId( sModuleId ) { implInit( ); } @@ -291,8 +292,8 @@ namespace frm { OUString sCommandURL( lcl_getCommandURL( pSupportedFeatures->nId ) ); m_pToolbar->SetItemCommand( pSupportedFeatures->nId, sCommandURL ); - if ( m_pDescriptionProvider ) - m_pToolbar->SetQuickHelpText( pSupportedFeatures->nId, m_pDescriptionProvider->getCommandDescription( sCommandURL ) ); + m_pToolbar->SetQuickHelpText( pSupportedFeatures->nId, + vcl::CommandInfoProvider::Instance().GetCommandPropertyFromModule(sCommandURL, m_sModuleId) ); } if ( pSupportedFeatures->bItemWindow ) diff --git a/forms/source/solar/inc/navtoolbar.hxx b/forms/source/solar/inc/navtoolbar.hxx index 3d2a191eac28..9112fac4e927 100644 --- a/forms/source/solar/inc/navtoolbar.hxx +++ b/forms/source/solar/inc/navtoolbar.hxx @@ -57,18 +57,17 @@ namespace frm const IFeatureDispatcher* m_pDispatcher; const std::shared_ptr< const ICommandImageProvider > m_pImageProvider; - const std::shared_ptr< const ICommandDescriptionProvider > - m_pDescriptionProvider; ImageSize m_eImageSize; VclPtr<ImplNavToolBar> m_pToolbar; ::std::vector< VclPtr<vcl::Window> > m_aChildWins; + const OUString m_sModuleId; public: NavigationToolBar( vcl::Window* _pParent, WinBits _nStyle, const std::shared_ptr< const ICommandImageProvider >& _pImageProvider, - const std::shared_ptr< const ICommandDescriptionProvider >& _pDescriptionProvider + const OUString sModuleId ); virtual ~NavigationToolBar( ); virtual void dispose() override; diff --git a/include/vcl/commandinfoprovider.hxx b/include/vcl/commandinfoprovider.hxx index 67a7ab3f5e22..2560745c9d58 100644 --- a/include/vcl/commandinfoprovider.hxx +++ b/include/vcl/commandinfoprovider.hxx @@ -87,7 +87,7 @@ public: OUString GetRealCommandForCommand( const OUString& rCommandName, const css::uno::Reference<css::frame::XFrame>& rxFrame ); - OUString GetCommandPropertyFromModule( const sal_Char* pCommandURL, const OUString& rModuleName ); + OUString GetCommandPropertyFromModule( const OUString& rCommandName, const OUString& rModuleName ); Image GetImageForCommand( const OUString& rsCommandName, diff --git a/vcl/source/helper/commandinfoprovider.cxx b/vcl/source/helper/commandinfoprovider.cxx index 77d5ba6903de..7a03c80afa7b 100644 --- a/vcl/source/helper/commandinfoprovider.cxx +++ b/vcl/source/helper/commandinfoprovider.cxx @@ -480,14 +480,13 @@ OUString CommandInfoProvider::GetCommandProperty(const OUString& rsProperty, con return OUString(); } -OUString CommandInfoProvider::GetCommandPropertyFromModule( const sal_Char* pCommandURL, const OUString& rModuleName ) +OUString CommandInfoProvider::GetCommandPropertyFromModule( const OUString& rCommandName, const OUString& rModuleName ) { OUString sLabel; - if ( !pCommandURL || !*pCommandURL ) + if ( rCommandName.isEmpty() ) return sLabel; Sequence<beans::PropertyValue> aProperties; - OUString sCommandURL = OUString::createFromAscii( pCommandURL ); try { if( rModuleName.getLength() > 0) @@ -495,7 +494,7 @@ OUString CommandInfoProvider::GetCommandPropertyFromModule( const sal_Char* pCom Reference<container::XNameAccess> xNameAccess = frame::theUICommandDescription::get(mxContext); Reference<container::XNameAccess> xUICommandLabels; if (xNameAccess->getByName( rModuleName ) >>= xUICommandLabels ) - xUICommandLabels->getByName(sCommandURL) >>= aProperties; + xUICommandLabels->getByName(rCommandName) >>= aProperties; for (sal_Int32 nIndex=0; nIndex<aProperties.getLength(); ++nIndex) { |