20#include <bitmaps.hlst>
38#include <com/sun/star/awt/PopupMenuDirection.hpp>
39#include <com/sun/star/awt/XPopupMenu.hpp>
40#include <com/sun/star/frame/thePopupMenuControllerFactory.hpp>
41#include <com/sun/star/frame/XPopupMenuController.hpp>
42#include <com/sun/star/frame/XStorable.hpp>
43#include <com/sun/star/frame/XSubToolbarController.hpp>
44#include <com/sun/star/frame/XUIControllerFactory.hpp>
45#include <com/sun/star/frame/XController.hpp>
46#include <com/sun/star/lang/XServiceInfo.hpp>
47#include <com/sun/star/ucb/CommandFailedException.hpp>
48#include <com/sun/star/ucb/ContentCreationException.hpp>
49#include <com/sun/star/util/XModifiable.hpp>
57 css::lang::XServiceInfo >
60class PopupMenuToolbarController :
public ToolBarBase
64 virtual void SAL_CALL
dispose()
override;
66 virtual void SAL_CALL initialize(
const css::uno::Sequence< css::uno::Any >& aArguments )
override;
68 virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createPopupWindow()
override;
70 virtual void SAL_CALL statusChanged(
const css::frame::FeatureStateEvent& rEvent )
override;
73 PopupMenuToolbarController(
const css::uno::Reference< css::uno::XComponentContext >& rxContext,
74 OUString aPopupCommand = OUString() );
75 virtual void functionExecuted(
const OUString &rCommand );
77 void createPopupMenuController();
79 bool m_bHasController;
81 OUString m_aPopupCommand;
85 css::uno::Reference< css::frame::XUIControllerFactory > m_xPopupMenuFactory;
86 css::uno::Reference< css::frame::XPopupMenuController > m_xPopupMenuController;
89PopupMenuToolbarController::PopupMenuToolbarController(
90 const css::uno::Reference< css::uno::XComponentContext >& xContext,
91 OUString aPopupCommand )
93 , m_bHasController( false )
94 , m_bResourceURL( false )
95 , m_aPopupCommand(
std::move( aPopupCommand ))
99void SAL_CALL PopupMenuToolbarController::dispose()
104 if( m_xPopupMenuController.is() )
106 css::uno::Reference< css::lang::XComponent > xComponent(
107 m_xPopupMenuController, css::uno::UNO_QUERY );
108 if( xComponent.is() )
112 xComponent->dispose();
117 m_xPopupMenuController.clear();
121 m_xPopupMenuFactory.clear();
122 m_xPopupMenu.clear();
125void SAL_CALL PopupMenuToolbarController::initialize(
126 const css::uno::Sequence< css::uno::Any >& aArguments )
128 ToolboxController::initialize( aArguments );
131 if ( !m_aPopupCommand.getLength() )
132 m_aPopupCommand = m_aCommandURL;
136 m_xPopupMenuFactory.set(
137 css::frame::thePopupMenuControllerFactory::get(
m_xContext ) );
138 m_bHasController = m_xPopupMenuFactory->hasController(
139 m_aPopupCommand, getModuleName() );
141 catch (
const css::uno::Exception&)
146 if ( !m_bHasController && m_aPopupCommand.startsWith(
"private:resource/" ) )
148 m_bResourceURL =
true;
149 m_bHasController =
true;
155 if ( getToolboxId( nItemId, &pToolBox ) )
161 nCurStyle | nSetStyle :
162 nCurStyle & ~nSetStyle );
167void SAL_CALL PopupMenuToolbarController::statusChanged(
const css::frame::FeatureStateEvent& rEvent )
169 if ( m_bResourceURL )
174 if ( getToolboxId( nItemId, &pToolBox ) )
177 pToolBox->
EnableItem( nItemId, rEvent.IsEnabled );
179 if ( rEvent.State >>= bValue )
184css::uno::Reference< css::awt::XWindow > SAL_CALL
185PopupMenuToolbarController::createPopupWindow()
187 css::uno::Reference< css::awt::XWindow > xRet;
190 if ( !m_bHasController )
193 createPopupMenuController();
200 pToolBox->SetItemDown( m_nToolBoxId,
true );
207 css::uno::Reference< css::awt::XPopupMenu > xPopupMenu ( m_xPopupMenu );
208 sal_uInt16
nId = xPopupMenu->execute(
209 css::uno::Reference< css::awt::XWindowPeer >( getParent(), css::uno::UNO_QUERY ),
211 ( eAlign == WindowAlign::Top || eAlign == WindowAlign::Bottom ) ?
212 css::awt::PopupMenuDirection::EXECUTE_DOWN :
213 css::awt::PopupMenuDirection::EXECUTE_RIGHT );
214 pToolBox->SetItemDown( m_nToolBoxId,
false );
217 functionExecuted( xPopupMenu->getCommand( nId ) );
222void PopupMenuToolbarController::functionExecuted(
const OUString &)
228 return ToolBoxItemBits::DROPDOWN;
231void PopupMenuToolbarController::createPopupMenuController()
233 if( !m_bHasController )
236 if ( m_xPopupMenuController.is() )
238 m_xPopupMenuController->updatePopupMenu();
242 css::uno::Sequence<css::uno::Any> aArgs {
254 sal_Int32 nAppendIndex = aArgs.getLength();
255 aArgs.realloc(nAppendIndex + 1);
258 m_xPopupMenuController.set(
m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
259 "com.sun.star.comp.framework.ResourceMenuController", aArgs,
m_xContext), css::uno::UNO_QUERY_THROW );
263 m_xPopupMenuController.set( m_xPopupMenuFactory->createInstanceWithArgumentsAndContext(
264 m_aPopupCommand, aArgs,
m_xContext), css::uno::UNO_QUERY_THROW );
267 m_xPopupMenuController->setPopupMenu( m_xPopupMenu );
269 catch (
const css::uno::Exception & )
272 m_xPopupMenu.clear();
277class GenericPopupToolbarController :
public PopupMenuToolbarController
280 GenericPopupToolbarController(
const css::uno::Reference< css::uno::XComponentContext >& rxContext,
281 const css::uno::Sequence< css::uno::Any >& rxArgs );
284 virtual void SAL_CALL initialize(
const css::uno::Sequence< css::uno::Any >& rxArgs )
override;
287 virtual void SAL_CALL statusChanged(
const css::frame::FeatureStateEvent& rEvent )
override;
297 bool m_bSplitButton, m_bReplaceWithLast;
298 void functionExecuted(
const OUString &rCommand)
override;
302GenericPopupToolbarController::GenericPopupToolbarController(
303 const css::uno::Reference< css::uno::XComponentContext >& xContext,
304 const css::uno::Sequence< css::uno::Any >& rxArgs )
305 : PopupMenuToolbarController( xContext )
306 , m_bReplaceWithLast( false )
308 css::beans::PropertyValue aPropValue;
309 for (
const auto& arg: rxArgs )
311 if ( ( arg >>= aPropValue ) && aPropValue.Name ==
"Value" )
315 aPropValue.Value >>= aValue;
316 m_aPopupCommand = aValue.getToken(0,
';', nIdx);
317 m_bReplaceWithLast = aValue.getToken(0,
';', nIdx).toBoolean();
321 m_bSplitButton = m_bReplaceWithLast || !m_aPopupCommand.isEmpty();
324OUString GenericPopupToolbarController::getImplementationName()
326 return "com.sun.star.comp.framework.GenericPopupToolbarController";
329sal_Bool GenericPopupToolbarController::supportsService(OUString
const & rServiceName)
334css::uno::Sequence<OUString> GenericPopupToolbarController::getSupportedServiceNames()
336 return {
"com.sun.star.frame.ToolbarController"};
339void GenericPopupToolbarController::initialize(
const css::uno::Sequence< css::uno::Any >& rxArgs )
341 PopupMenuToolbarController::initialize( rxArgs );
342 if ( m_bReplaceWithLast )
344 createPopupMenuController();
347void GenericPopupToolbarController::statusChanged(
const css::frame::FeatureStateEvent& rEvent )
351 if ( m_bReplaceWithLast && !rEvent.IsEnabled && m_xPopupMenu.is() )
355 if ( getToolboxId( nId, &pToolBox ) && pToolBox->
IsItemEnabled( nId ) )
357 Menu* pVclMenu = m_xPopupMenu->GetMenu();
362 for (sal_uInt16 i = 0, nCount = m_xPopupMenu->getItemCount(); i < nCount; ++i )
364 sal_uInt16 nItemId = m_xPopupMenu->getItemId(i);
365 if (nItemId && m_xPopupMenu->isItemEnabled(nItemId) && !m_xPopupMenu->getPopupMenu(nItemId).is())
367 functionExecuted(m_xPopupMenu->getCommand(nItemId));
373 PopupMenuToolbarController::statusChanged( rEvent );
376void GenericPopupToolbarController::functionExecuted(
const OUString& rCommand )
378 if ( !m_bReplaceWithLast )
381 removeStatusListener( m_aCommandURL );
385 m_aCommandURL = aRealCommand.isEmpty() ? rCommand : aRealCommand;
386 addStatusListener( m_aCommandURL );
390 if ( getToolboxId( nId, &pToolBox ) )
405 return m_bSplitButton ? ToolBoxItemBits::DROPDOWN : ToolBoxItemBits::DROPDOWNONLY;
408class SaveToolbarController :
public cppu::ImplInheritanceHelper< PopupMenuToolbarController,
409 css::frame::XSubToolbarController,
410 css::util::XModifyListener >
413 explicit SaveToolbarController(
const css::uno::Reference< css::uno::XComponentContext >& rxContext );
416 virtual void SAL_CALL initialize(
const css::uno::Sequence< css::uno::Any >& aArguments )
override;
420 virtual sal_Bool SAL_CALL opensSubToolbar()
override;
421 virtual OUString SAL_CALL getSubToolbarName()
override;
422 virtual void SAL_CALL functionSelected(
const OUString&
aCommand )
override;
423 virtual void SAL_CALL updateImage()
override;
426 virtual void SAL_CALL statusChanged(
const css::frame::FeatureStateEvent& rEvent )
override;
429 virtual void SAL_CALL modified(
const css::lang::EventObject& rEvent )
override;
432 virtual void SAL_CALL disposing(
const css::lang::EventObject& rEvent )
override;
435 virtual void SAL_CALL
dispose()
override;
445 css::uno::Reference< css::frame::XStorable > m_xStorable;
449SaveToolbarController::SaveToolbarController(
const css::uno::Reference< css::uno::XComponentContext >& rxContext )
450 : ImplInheritanceHelper( rxContext,
".uno:SaveAsMenu" )
452 , m_bModified( false )
456void SaveToolbarController::initialize(
const css::uno::Sequence< css::uno::Any >& aArguments )
458 PopupMenuToolbarController::initialize( aArguments );
462 if ( !getToolboxId( nId, &pToolBox ) )
471 m_xStorable.set( m_xModifiable, css::uno::UNO_QUERY );
482 modified( css::lang::EventObject() );
486sal_Bool SaveToolbarController::opensSubToolbar()
491OUString SaveToolbarController::getSubToolbarName()
496void SaveToolbarController::functionSelected(
const OUString& )
500void SaveToolbarController::updateImage()
505 if ( !getToolboxId( nId, &pToolBox ) )
516 else if ( m_bModified )
519 aImage =
Image(StockImage::Yes, BMP_SAVEMODIFIED_LARGE);
521 aImage =
Image(StockImage::Yes, BMP_SAVEMODIFIED_EXTRALARGE);
523 aImage =
Image(StockImage::Yes, BMP_SAVEMODIFIED_SMALL);
533void SaveToolbarController::statusChanged(
const css::frame::FeatureStateEvent& rEvent )
537 if ( !getToolboxId( nId, &pToolBox ) )
541 m_bReadOnly = m_xStorable.is() && m_xStorable->isReadonly();
542 if ( bLastReadOnly != m_bReadOnly )
544 OUString sCommand =
m_bReadOnly ? OUString(
".uno:SaveAs" ) : m_aCommandURL;
549 pToolBox->
SetItemBits( nId, pToolBox->
GetItemBits( nId ) & ~( m_bReadOnly ? ToolBoxItemBits::DROPDOWN : ToolBoxItemBits::DROPDOWNONLY ) );
550 pToolBox->
SetItemBits( nId, pToolBox->
GetItemBits( nId ) | ( m_bReadOnly ? ToolBoxItemBits::DROPDOWNONLY : ToolBoxItemBits::DROPDOWN ) );
555 pToolBox->
EnableItem( nId, rEvent.IsEnabled );
558void SaveToolbarController::modified(
const css::lang::EventObject& )
560 bool bLastModified = m_bModified;
562 if ( bLastModified != m_bModified )
566void SaveToolbarController::disposing(
const css::lang::EventObject& rEvent )
568 if ( rEvent.Source == m_xModifiable )
574 PopupMenuToolbarController::disposing( rEvent );
577void SaveToolbarController::dispose()
579 PopupMenuToolbarController::dispose();
588OUString SaveToolbarController::getImplementationName()
590 return "com.sun.star.comp.framework.SaveToolbarController";
593sal_Bool SaveToolbarController::supportsService( OUString
const & rServiceName )
598css::uno::Sequence< OUString > SaveToolbarController::getSupportedServiceNames()
600 return {
"com.sun.star.frame.ToolbarController"};
603class NewToolbarController :
public cppu::ImplInheritanceHelper<PopupMenuToolbarController, css::frame::XSubToolbarController>
606 explicit NewToolbarController(
const css::uno::Reference< css::uno::XComponentContext >& rxContext );
615 void SAL_CALL initialize(
const css::uno::Sequence< css::uno::Any >& aArguments )
override;
619 sal_Bool SAL_CALL opensSubToolbar()
override {
return true; }
620 OUString SAL_CALL getSubToolbarName()
override {
return OUString(); }
621 void SAL_CALL functionSelected(
const OUString& )
override {}
622 void SAL_CALL updateImage()
override;
625 void functionExecuted(
const OUString &rCommand )
override;
626 void SAL_CALL statusChanged(
const css::frame::FeatureStateEvent& rEvent )
override;
627 void SAL_CALL execute( sal_Int16 KeyModifier )
override;
628 sal_uInt16 getMenuIdForCommand( std::u16string_view rCommand );
630 sal_uInt16 m_nMenuId;
633NewToolbarController::NewToolbarController(
634 const css::uno::Reference< css::uno::XComponentContext >& xContext )
635 : ImplInheritanceHelper( xContext )
640OUString NewToolbarController::getImplementationName()
642 return "org.apache.openoffice.comp.framework.NewToolbarController";
645sal_Bool NewToolbarController::supportsService(OUString
const & rServiceName)
650css::uno::Sequence<OUString> NewToolbarController::getSupportedServiceNames()
652 return {
"com.sun.star.frame.ToolbarController"};
655void SAL_CALL NewToolbarController::initialize(
const css::uno::Sequence< css::uno::Any >& aArguments )
657 PopupMenuToolbarController::initialize( aArguments );
660 createPopupMenuController();
663void SAL_CALL NewToolbarController::statusChanged(
const css::frame::FeatureStateEvent& rEvent )
665 if ( rEvent.IsEnabled )
668 rEvent.State >>= aState;
673 functionExecuted( aState );
675 catch (
const css::ucb::CommandFailedException&)
678 catch (
const css::ucb::ContentCreationException&)
683 enable( rEvent.IsEnabled );
686void SAL_CALL NewToolbarController::execute( sal_Int16 )
690 OUString
aURL, aTarget;
691 if ( m_xPopupMenu.is() && m_nMenuId )
694 aURL = m_xPopupMenu->getCommand(m_nMenuId);
698 if ( pMenuAttributes )
699 aTarget = pMenuAttributes->aTargetFrame;
701 aTarget =
"_default";
704 aURL = m_aCommandURL;
707 "Referer", OUString(
"private:user" )) };
712void NewToolbarController::functionExecuted(
const OUString &rCommand )
714 m_nMenuId = getMenuIdForCommand( rCommand );
718sal_uInt16 NewToolbarController::getMenuIdForCommand( std::u16string_view rCommand )
720 if ( m_xPopupMenu.is() && !rCommand.empty() )
722 sal_uInt16
nCount = m_xPopupMenu->getItemCount();
723 for ( sal_uInt16 n = 0;
n <
nCount; ++
n )
725 sal_uInt16
nId = m_xPopupMenu->getItemId(n);
726 OUString aCmd(m_xPopupMenu->getCommand(nId));
730 if ( aCmd.match( rCommand ) )
738void SAL_CALL NewToolbarController::updateImage()
745 OUString
aURL, aImageId;
746 if ( m_xPopupMenu.is() && m_nMenuId )
748 aURL = m_xPopupMenu->getCommand(m_nMenuId);
750 if ( pMenuAttributes )
751 aImageId = pMenuAttributes->aImageId;
754 aURL = m_aCommandURL;
756 INetURLObject aURLObj( aImageId.isEmpty() ? aURL : aImageId );
765 pToolBox->SetItemImage( m_nToolBoxId, aImage );
770extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
772 css::uno::XComponentContext *context,
773 css::uno::Sequence<css::uno::Any>
const &args)
775 return cppu::acquire(
new GenericPopupToolbarController(context,
args));
778extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
780 css::uno::XComponentContext *context,
781 css::uno::Sequence<css::uno::Any>
const &)
783 return cppu::acquire(
new SaveToolbarController(context));
786extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
788 css::uno::XComponentContext *context,
789 css::uno::Sequence<css::uno::Any>
const &)
791 return cppu::acquire(
new NewToolbarController(context));
PropertiesInfo aProperties
css::uno::Reference< css::lang::XComponent > m_xFrame
static css::awt::Rectangle ConvertToAWTRect(::tools::Rectangle const &_rRect)
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
#define TOOLS_INFO_EXCEPTION(area, stream)
Reference< XModifiable2 > m_xModifiable
css::uno::Reference< css::uno::XComponentContext > m_xContext
bool dispatchCommand(const OUString &rCommand, const uno::Reference< css::frame::XFrame > &rFrame, const css::uno::Sequence< css::beans::PropertyValue > &rArguments, const uno::Reference< css::frame::XDispatchResultListener > &rListener)
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)
Sequence< beans::PropertyValue > GetCommandProperties(const OUString &rsCommandName, const OUString &rsModuleName)
OUString GetTooltipForCommand(const OUString &rsCommandName, const css::uno::Sequence< css::beans::PropertyValue > &rProperties, const Reference< frame::XFrame > &rxFrame)
OUString GetRealCommandForCommand(const css::uno::Sequence< css::beans::PropertyValue > &rProperties)
OUString GetModuleIdentifier(const Reference< frame::XFrame > &rxFrame)
Image GetImageForCommand(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame, vcl::ImageType eImageType)
OUString GetLabelForCommand(const css::uno::Sequence< css::beans::PropertyValue > &rProperties)
Reference< XController > xController