26#include <com/sun/star/frame/ModuleManager.hpp>
27#include <com/sun/star/frame/XModuleManager2.hpp>
28#include <com/sun/star/frame/XFrame.hpp>
29#include <com/sun/star/lang/XServiceInfo.hpp>
30#include <com/sun/star/ui/XUIElementFactory.hpp>
47class AddonsToolBarFactory :
public ::cppu::WeakImplHelper< css::lang::XServiceInfo ,
48 css::ui::XUIElementFactory >
51 explicit AddonsToolBarFactory(
const css::uno::Reference< css::uno::XComponentContext >& xContext );
55 return "com.sun.star.comp.framework.AddonsToolBarFactory";
65 return {
"com.sun.star.ui.ToolBarFactory"};
69 virtual css::uno::Reference< css::ui::XUIElement > SAL_CALL createUIElement(
const OUString& ResourceURL,
const css::uno::Sequence< css::beans::PropertyValue >& Args )
override;
71 bool hasButtonsInContext(
const css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > >& rPropSeq,
72 const css::uno::Reference< css::frame::XFrame >& rFrame );
75 css::uno::Reference< css::uno::XComponentContext >
m_xContext;
76 css::uno::Reference< css::frame::XModuleManager2 > m_xModuleManager;
79AddonsToolBarFactory::AddonsToolBarFactory(
80 const css::uno::Reference< css::uno::XComponentContext >& xContext ) :
82 , m_xModuleManager( ModuleManager::
create( xContext ) )
86bool IsCorrectContext( std::u16string_view rModuleIdentifier, std::u16string_view aContextList )
88 if ( aContextList.empty() )
91 if ( !rModuleIdentifier.empty() )
93 return aContextList.find( rModuleIdentifier ) != std::u16string_view::npos;
99bool AddonsToolBarFactory::hasButtonsInContext(
103 OUString aModuleIdentifier;
106 aModuleIdentifier = m_xModuleManager->identify( rFrame );
112 catch (
const Exception& )
120 bool bIsButton(
true );
121 bool bIsCorrectContext(
false );
122 sal_uInt32 nPropChecked( 0 );
124 for ( PropertyValue
const & prop : props )
126 if ( prop.Name ==
"Context" )
128 OUString aContextList;
129 if ( prop.Value >>= aContextList )
133 else if ( prop.Name ==
"URL" )
137 bIsButton =
aURL !=
"private:separator";
141 if ( nPropChecked == 2 )
145 if ( bIsButton && bIsCorrectContext )
154 const OUString& ResourceURL,
161 OUString aResourceURL( ResourceURL );
163 for ( PropertyValue
const & arg : Args )
165 if ( arg.Name ==
"ConfigurationData" )
166 arg.Value >>= aConfigData;
167 else if ( arg.Name ==
"Frame" )
169 else if ( arg.Name ==
"ResourceURL" )
170 arg.Value >>= aResourceURL;
173 if ( !aResourceURL.startsWith(
"private:resource/toolbar/addon_") )
174 throw IllegalArgumentException();
179 aConfigData.hasElements() &&
180 hasButtonsInContext( aConfigData, xFrame ))
189 xToolBar = pToolBarWrapper;
190 pToolBarWrapper->initialize( aPropSeq );
198extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
200 css::uno::XComponentContext *context,
201 css::uno::Sequence<css::uno::Any>
const &)
203 return cppu::acquire(
new AddonsToolBarFactory(context));
css::uno::Reference< css::uno::XComponentContext > m_xContext
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
css::uno::Reference< css::deployment::XPackageRegistry > create(css::uno::Reference< css::deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)
Reference< XFrame > xFrame