Kaydet (Commit) 7ae23262 authored tarafından Samuel Mehrbrodt's avatar Samuel Mehrbrodt

tdf#95845 Use CommandInfoProvider in forms

Change-Id: I697f8c442cc4db7b38601c32fb71e0201f145354
Reviewed-on: https://gerrit.libreoffice.org/24106Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
üst 9a081c5c
......@@ -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 \
......
/* -*- 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: */
/* -*- 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: */
......@@ -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
......
......@@ -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 )
......
......@@ -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;
......
......@@ -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,
......
......@@ -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)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment